Mercurial > pidgin
diff src/gtkconv.c @ 12116:e75ef7aa913e
[gaim-migrate @ 14416]
" This patch implements a replacement for the queuing
system from 1.x. It also obsoletes a previous patch
[#1338873] I submitted to prioritize the unseen states
in gtk conversations.
The attached envelope.png is ripped from the
msgunread.png already included in gaim. It should be
dropped in the pixmaps directory (Makefile.am is
updated accordingly in this patch).
The two separate queuing preferences from 1.x, queuing
messages while away and queuing all new messages (from
docklet), are replaced with a single 3-way preference
for conversations. The new preference is "Hide new IM
conversations". This preference can be set to never,
away and always.
When a gtk conversation is created, it may be placed in
a hidden conversation window instead of being placed
normally. This decision is based upon the preference
and possibly the away state of the account the
conversation is being created for. This *will* effect
conversations the user explicitly requests to be
created, so in these cases the caller must be sure to
present the conversation to the user, using
gaim_gtkconv_present_conversation(). This is done
already in gtkdialogs.c which handles creating
conversations requested by the user from gaim proper
(menus, double-clicking on budy in blist, etc.).
The main advantage to not queuing messages is that the
conversations exist, the message is written to the
conversation (and logged if appropriate) and the unseen
state is set on the conversation. This means no
additional features are needed to track whether there
are queued messages or not, just use the unseen state
on conversations.
Since conversations may not be visible (messages
"queued"), gaim proper needs some notification that
there are messages waiting. I opted for a menutray icon
that shows up when an im conversation has an unseen
message. Clicking this icon will focus (and show if
hidden) the first conversation with an unseen message.
This is essentially the same behavior of the docklet in
cvs right now, except that the icon is only visible
when there is a conversation with an unread message.
The api that is added is flexible enough to allow
either the docklet or the new blist menutray icon to be
visible for conversations of any/all types and for
unseen messages >= any state. Currently they are set to
only IM conversations and only unseen states >= TEXT
(system messages and no log messages will not trigger
blinking the docklet or showing the blist tray icon),
but these could be made preferences relatively easily
in the future. Other plugins could probably benefit as
well: gaim_gtk_conversations_get_first_unseen().
There is probably some limit to comment size, so I'll
stop rambling now. If anyone has more
questions/comments, catch me in #gaim, here or on
gaim-devel."
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Wed, 16 Nov 2005 18:17:01 +0000 |
parents | 8c6ea55c84a4 |
children | cb7ccb5048cf |
line wrap: on
line diff
--- a/src/gtkconv.c Wed Nov 16 17:55:26 2005 +0000 +++ b/src/gtkconv.c Wed Nov 16 18:17:01 2005 +0000 @@ -113,6 +113,10 @@ static GtkWidget *invite_dialog = NULL; static GtkWidget *warn_close_dialog = NULL; +static GaimGtkWindow *hidden_convwin = NULL; +static GList *window_list = NULL; + + static gboolean update_send_to_selection(GaimGtkWindow *win); static void generate_send_to_items(GaimGtkWindow *win); @@ -128,6 +132,8 @@ static void update_typing_icon(GaimGtkConversation *gtkconv); static char *item_factory_translate_func (const char *path, gpointer func_data); gboolean gaim_gtkconv_has_focus(GaimConversation *conv); +static void private_remove_gtkconv(GaimGtkWindow *win, GaimGtkConversation *gtkconv, + gboolean destroy_empty); static GdkColor *get_nick_color(GaimGtkConversation *gtkconv, const char *name) { static GdkColor col; @@ -2096,7 +2102,7 @@ if (status != NULL) g_object_unref(status); - if (gaim_gtk_conv_window_get_active_conversation(win) == conv && + if (gaim_gtk_conv_window_is_active_conversation(conv) && (gaim_conversation_get_type(conv) != GAIM_CONV_TYPE_IM || gtkconv->u.im->anim == NULL)) { @@ -2354,6 +2360,22 @@ /************************************************************************** * End of the bunch of buddy icon functions **************************************************************************/ +void +gaim_gtkconv_present_conversation(GaimConversation *conv) +{ + GaimGtkConversation *gtkconv = GAIM_GTK_CONVERSATION(conv); + + if(gtkconv->win==hidden_convwin) { + private_remove_gtkconv(hidden_convwin, gtkconv, FALSE); + gaim_gtkconv_placement_place(gtkconv); + } + + gaim_gtkconv_set_active_conversation(conv); + gaim_gtk_conv_window_switch_gtkconv(gtkconv->win, gtkconv); + gaim_gtk_conv_window_raise(gtkconv->win); + gtk_window_present(GTK_WINDOW(gtkconv->win->window)); +} + GaimConversation * gaim_gtk_conversations_get_first_unseen(GaimConversationType type, GaimUnseenState min_state) @@ -3958,6 +3980,23 @@ G_CALLBACK(gtk_widget_grab_focus), gtkconv->entry); + if (conv_type == GAIM_CONV_TYPE_IM) { + /* put conv in hidden_convwin if hide_new pref is always */ + if(strcmp(gaim_prefs_get_string("/gaim/gtk/conversations/im/hide_new"), "always")==0) { + gaim_gtk_conv_window_add_gtkconv(hidden_convwin, gtkconv); + return; + } + + /* put conv in hidden_convwin if hide_new pref is away and account is away */ + if(strcmp(gaim_prefs_get_string("/gaim/gtk/conversations/im/hide_new"), "away")==0 + && gaim_status_type_get_primitive( + gaim_status_get_type(gaim_account_get_active_status( + gaim_conversation_get_account(conv)))) == GAIM_STATUS_AWAY) { + gaim_gtk_conv_window_add_gtkconv(hidden_convwin, gtkconv); + return; + } + } + gaim_gtkconv_placement_place(gtkconv); } @@ -4622,12 +4661,9 @@ g_object_get(G_OBJECT(win->window), "has-toplevel-focus", &has_focus, NULL); - if (has_focus) - { - GaimConversation *c = gaim_gtk_conv_window_get_active_conversation(win); - if (GAIM_GTK_CONVERSATION(c) == gtkconv) - return TRUE; - } + if (has_focus && gaim_gtk_conv_window_is_active_conversation(conv)) + return TRUE; + return FALSE; } @@ -5078,12 +5114,12 @@ else gtk_label_set_text(GTK_LABEL(gtkconv->tab_label), title); - if (conv == gaim_gtk_conv_window_get_active_conversation(win)) + if (gaim_gtk_conv_window_is_active_conversation(conv)) update_typing_icon(gtkconv); if (type == GAIM_CONV_UPDATE_TITLE) { gtk_label_set_text(GTK_LABEL(gtkconv->menu_label), title); - if (conv == gaim_gtk_conv_window_get_active_conversation(win)) + if (gaim_gtk_conv_window_is_active_conversation(conv)) gtk_window_set_title(GTK_WINDOW(win->window), title); } @@ -5308,7 +5344,7 @@ /* The buddy icon code needs badly to be fixed. */ buf = gdk_pixbuf_animation_get_static_image(gtkconv->u.im->anim); - if(conv == gaim_gtk_conv_window_get_active_conversation(gtkconv->win)) + if(gaim_gtk_conv_window_is_active_conversation(conv)) gtk_window_set_icon(GTK_WINDOW(win->window), buf); } @@ -5534,6 +5570,72 @@ } static void +account_status_changed_cb(GaimAccount *account, GaimStatus *oldstatus, + GaimStatus *newstatus) +{ + GList *l; + GaimConversation *conv = NULL; + GaimGtkConversation *gtkconv; + + if(strcmp(gaim_prefs_get_string("/gaim/gtk/conversations/im/hide_new"), "away")!=0) + return; + + if(gaim_status_type_get_primitive(gaim_status_get_type(oldstatus))!=GAIM_STATUS_AWAY) + return; + + if(gaim_status_type_get_primitive(gaim_status_get_type(newstatus))==GAIM_STATUS_AWAY) + return; + + for (l = hidden_convwin->gtkconvs; l != NULL; l = l->next) { + gtkconv = l->data; + + conv = gtkconv->active_conv; + + if(gaim_status_type_get_primitive( + gaim_status_get_type(gaim_account_get_active_status( + gaim_conversation_get_account(conv)))) == GAIM_STATUS_AWAY) + continue; + + private_remove_gtkconv(hidden_convwin, gtkconv, FALSE); + gaim_gtkconv_placement_place(gtkconv); + } +} + +static void +hide_new_pref_cb(const char *name, GaimPrefType type, gpointer value, + gpointer data) +{ + GList *l; + GaimConversation *conv = NULL; + GaimGtkConversation *gtkconv; + gboolean when_away = FALSE; + + if(!hidden_convwin) + return; + + if(strcmp(gaim_prefs_get_string("/gaim/gtk/conversations/im/hide_new"), "always")==0) + return; + + if(strcmp(gaim_prefs_get_string("/gaim/gtk/conversations/im/hide_new"), "away")==0) + when_away = TRUE; + + for (l = hidden_convwin->gtkconvs; l != NULL; l = l->next) { + gtkconv = l->data; + + conv = gtkconv->active_conv; + + if(when_away && gaim_status_type_get_primitive( + gaim_status_get_type(gaim_account_get_active_status( + gaim_conversation_get_account(conv)))) == GAIM_STATUS_AWAY) + continue; + + private_remove_gtkconv(hidden_convwin, gtkconv, FALSE); + gaim_gtkconv_placement_place(gtkconv); + } +} + + +static void conv_placement_pref_cb(const char *name, GaimPrefType type, gpointer value, gpointer data) { @@ -5602,6 +5704,19 @@ gaim_prefs_add_int("/gaim/gtk/conversations/im/entry_height", 50); gaim_prefs_add_bool("/gaim/gtk/conversations/im/show_buddy_icons", TRUE); + /* convert old queuing prefs to hide_new 3-way pref */ + if(gaim_prefs_exists("/plugins/gtk/docklet/queue_messages") && + gaim_prefs_get_bool("/plugins/gtk/docklet/queue_messages")) { + gaim_prefs_add_string("/gaim/gtk/conversations/im/hide_new", "always"); + } + else if(gaim_prefs_exists("/gaim/gtk/away/queue_messages") && + gaim_prefs_get_bool("/gaim/gtk/away/queue_messages")) { + gaim_prefs_add_string("/gaim/gtk/conversations/im/hide_new", "away"); + } + else { + gaim_prefs_add_string("/gaim/gtk/conversations/im/hide_new", "never"); + } + /* Connect callbacks. */ gaim_prefs_connect_callback(handle, "/gaim/gtk/conversations/close_on_tabs", close_on_tabs_pref_cb, NULL); @@ -5624,6 +5739,9 @@ animate_buddy_icons_pref_cb, NULL); gaim_prefs_connect_callback(handle, "/gaim/gtk/conversations/im/show_buddy_icons", show_buddy_icons_pref_cb, NULL); + gaim_prefs_connect_callback(handle, "/gaim/gtk/conversations/im/hide_new", + hide_new_pref_cb, NULL); + /********************************************************************** @@ -5665,6 +5783,12 @@ G_CALLBACK(buddy_update_cb), NULL); gaim_conversations_set_ui_ops(&conversation_ui_ops); + + hidden_convwin = gaim_gtk_conv_window_new(); + window_list = g_list_remove(window_list, hidden_convwin); + + gaim_signal_connect(gaim_accounts_get_handle(), "account-status-changed", + handle, GAIM_CALLBACK(account_status_changed_cb), NULL); } void @@ -5673,6 +5797,8 @@ gaim_prefs_disconnect_by_handle(gaim_gtk_conversations_get_handle()); gaim_signals_disconnect_by_handle(gaim_gtk_conversations_get_handle()); gaim_signals_unregister_by_instance(gaim_gtk_conversations_get_handle()); + gaim_gtk_conv_window_destroy(hidden_convwin); + hidden_convwin=NULL; } @@ -6399,8 +6525,6 @@ * GTK+ window ops **************************************************************************/ -static GList *window_list = NULL; - GList * gaim_gtk_conv_windows_get_list() { @@ -6681,8 +6805,8 @@ update_send_to_selection(win); } -void -gaim_gtk_conv_window_remove_gtkconv(GaimGtkWindow *win, GaimGtkConversation *gtkconv) +static void +private_remove_gtkconv(GaimGtkWindow *win, GaimGtkConversation *gtkconv, gboolean destroy_empty) { unsigned int index; GaimConversationType conv_type; @@ -6703,9 +6827,14 @@ win->gtkconvs = g_list_remove(win->gtkconvs, gtkconv); - if (!win->gtkconvs) + if (destroy_empty && !win->gtkconvs) gaim_gtk_conv_window_destroy(win); } +void +gaim_gtk_conv_window_remove_gtkconv(GaimGtkWindow *win, GaimGtkConversation *gtkconv) +{ + private_remove_gtkconv(win, gtkconv, TRUE); +} GaimGtkConversation * gaim_gtk_conv_window_get_gtkconv_at_index(const GaimGtkWindow *win, int index)