Mercurial > pidgin.yaz
comparison pidgin/gtkconv.c @ 15519:b15cc37605c4
In Pidgin, display a full date on the timestamp of the first message to
cross the boundary into a new day. Sean and various users want this. I
think I'm finally going to admit it's a decent idea.
I've also refactored plenty of code related to the conversation-timestamp
and log-timestamp signals. This breaks API compatibility, but I'm pretty
sure the only plugin that uses those signals is the Message Timestamps
plugin that we ship. The changes eliminate duplicated code between the
core/UI and the plugin.
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Sat, 03 Feb 2007 20:28:41 +0000 |
parents | 75ffc646647f |
children | 9c32176ac555 |
comparison
equal
deleted
inserted
replaced
15515:75ffc646647f | 15519:b15cc37605c4 |
---|---|
4808 g_free(str); | 4808 g_free(str); |
4809 | 4809 |
4810 return buddytag; | 4810 return buddytag; |
4811 } | 4811 } |
4812 | 4812 |
4813 static void pidgin_conv_calculate_newday(PidginConversation *gtkconv, time_t mtime) | |
4814 { | |
4815 struct tm *tm = localtime(&mtime); | |
4816 | |
4817 tm->tm_hour = tm->tm_min = tm->tm_sec = 0; | |
4818 tm->tm_mday++; | |
4819 | |
4820 gtkconv->newday = mktime(tm); | |
4821 } | |
4822 | |
4813 static void | 4823 static void |
4814 pidgin_conv_write_conv(GaimConversation *conv, const char *name, const char *alias, | 4824 pidgin_conv_write_conv(GaimConversation *conv, const char *name, const char *alias, |
4815 const char *message, GaimMessageFlags flags, | 4825 const char *message, GaimMessageFlags flags, |
4816 time_t mtime) | 4826 time_t mtime) |
4817 { | 4827 { |
4823 int gtk_font_options = 0; | 4833 int gtk_font_options = 0; |
4824 int gtk_font_options_all = 0; | 4834 int gtk_font_options_all = 0; |
4825 int max_scrollback_lines; | 4835 int max_scrollback_lines; |
4826 int line_count; | 4836 int line_count; |
4827 char buf2[BUF_LONG]; | 4837 char buf2[BUF_LONG]; |
4838 gboolean show_date; | |
4828 char *mdate; | 4839 char *mdate; |
4829 char color[10]; | 4840 char color[10]; |
4830 char *str; | 4841 char *str; |
4831 char *with_font_tag; | 4842 char *with_font_tag; |
4832 char *sml_attrib = NULL; | 4843 char *sml_attrib = NULL; |
4930 gtk_font_options_all |= GTK_IMHTML_USE_SMOOTHSCROLLING; | 4941 gtk_font_options_all |= GTK_IMHTML_USE_SMOOTHSCROLLING; |
4931 | 4942 |
4932 if (gtk_text_buffer_get_char_count(gtk_text_view_get_buffer(GTK_TEXT_VIEW(gtkconv->imhtml)))) | 4943 if (gtk_text_buffer_get_char_count(gtk_text_view_get_buffer(GTK_TEXT_VIEW(gtkconv->imhtml)))) |
4933 gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), "<BR>", gtk_font_options_all); | 4944 gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), "<BR>", gtk_font_options_all); |
4934 | 4945 |
4946 /* First message in a conversation. */ | |
4947 if (gtkconv->newday == 0) | |
4948 pidgin_conv_calculate_newday(gtkconv, mtime); | |
4949 | |
4950 /* Show the date on the first message in a new day, or if the message is | |
4951 * older than 20 minutes. */ | |
4952 show_date = (mtime >= gtkconv->newday) || (time(NULL) > mtime + 20*60); | |
4953 | |
4935 mdate = gaim_signal_emit_return_1(pidgin_conversations_get_handle(), | 4954 mdate = gaim_signal_emit_return_1(pidgin_conversations_get_handle(), |
4936 "conversation-timestamp", | 4955 "conversation-timestamp", |
4937 conv, mtime); | 4956 conv, mtime, show_date); |
4957 | |
4938 if (mdate == NULL) | 4958 if (mdate == NULL) |
4939 { | 4959 { |
4940 struct tm *tm = localtime(&mtime); | 4960 struct tm *tm = localtime(&mtime); |
4941 if (time(NULL) > mtime + 20*60) /* show date if older than 20 minutes */ | 4961 if (show_date) |
4942 mdate = g_strdup(gaim_date_format_long(tm)); | 4962 mdate = g_strdup(gaim_date_format_long(tm)); |
4943 else | 4963 else |
4944 mdate = g_strdup(gaim_time_format(tm)); | 4964 mdate = g_strdup(gaim_time_format(tm)); |
4945 } | 4965 } |
4966 | |
4967 if (mtime >= gtkconv->newday) | |
4968 pidgin_conv_calculate_newday(gtkconv, mtime); | |
4946 | 4969 |
4947 sml_attrib = g_strdup_printf("sml=\"%s\"", gaim_account_get_protocol_name(account)); | 4970 sml_attrib = g_strdup_printf("sml=\"%s\"", gaim_account_get_protocol_name(account)); |
4948 | 4971 |
4949 gtk_font_options |= GTK_IMHTML_NO_COMMENTS; | 4972 gtk_font_options |= GTK_IMHTML_NO_COMMENTS; |
4950 | 4973 |
6776 gaim_value_new(GAIM_TYPE_BOXED, | 6799 gaim_value_new(GAIM_TYPE_BOXED, |
6777 "PidginWindow *")); | 6800 "PidginWindow *")); |
6778 | 6801 |
6779 gaim_signal_register(handle, "conversation-timestamp", | 6802 gaim_signal_register(handle, "conversation-timestamp", |
6780 #if SIZEOF_TIME_T == 4 | 6803 #if SIZEOF_TIME_T == 4 |
6781 gaim_marshal_POINTER__POINTER_INT, | 6804 gaim_marshal_POINTER__POINTER_INT_BOOLEAN, |
6782 #elif SIZEOF_TIME_T == 8 | 6805 #elif SIZEOF_TIME_T == 8 |
6783 gaim_marshal_POINTER__POINTER_INT64, | 6806 gaim_marshal_POINTER__POINTER_INT64_BOOLEAN, |
6784 #else | 6807 #else |
6785 #error Unkown size of time_t | 6808 #error Unkown size of time_t |
6786 #endif | 6809 #endif |
6787 gaim_value_new(GAIM_TYPE_POINTER), 2, | 6810 gaim_value_new(GAIM_TYPE_POINTER), 3, |
6788 gaim_value_new(GAIM_TYPE_SUBTYPE, | 6811 gaim_value_new(GAIM_TYPE_SUBTYPE, |
6789 GAIM_SUBTYPE_CONVERSATION), | 6812 GAIM_SUBTYPE_CONVERSATION), |
6790 #if SIZEOF_TIME_T == 4 | 6813 #if SIZEOF_TIME_T == 4 |
6791 gaim_value_new(GAIM_TYPE_INT)); | 6814 gaim_value_new(GAIM_TYPE_INT), |
6792 #elif SIZEOF_TIME_T == 8 | 6815 #elif SIZEOF_TIME_T == 8 |
6793 gaim_value_new(GAIM_TYPE_INT64)); | 6816 gaim_value_new(GAIM_TYPE_INT64), |
6794 #else | 6817 #else |
6795 # error Unknown size of time_t | 6818 # error Unknown size of time_t |
6796 #endif | 6819 #endif |
6820 gaim_value_new(GAIM_TYPE_BOOLEAN)); | |
6797 | 6821 |
6798 gaim_signal_register(handle, "displaying-im-msg", | 6822 gaim_signal_register(handle, "displaying-im-msg", |
6799 gaim_marshal_BOOLEAN__POINTER_POINTER_POINTER_POINTER_POINTER, | 6823 gaim_marshal_BOOLEAN__POINTER_POINTER_POINTER_POINTER_POINTER, |
6800 gaim_value_new(GAIM_TYPE_BOOLEAN), 5, | 6824 gaim_value_new(GAIM_TYPE_BOOLEAN), 5, |
6801 gaim_value_new(GAIM_TYPE_SUBTYPE, | 6825 gaim_value_new(GAIM_TYPE_SUBTYPE, |