Mercurial > pidgin
comparison pidgin/gtkblist.c @ 32715:4ae0c82b158d
Go back to the old way of creating the accounts menu.
There doesn't seem to be a way to set the pixbuf through an
action, so we've had to go back to this way. Also, using actions
would always attempt to set a mnemonic which would mess up
usernames with underscores.
author | Elliott Sales de Andrade <qulogic@pidgin.im> |
---|---|
date | Sat, 21 Jan 2012 12:02:41 +0000 |
parents | d86fa4e61631 |
children | 0a184aea3efd |
comparison
equal
deleted
inserted
replaced
32714:d86fa4e61631 | 32715:4ae0c82b158d |
---|---|
127 #if !GTK_CHECK_VERSION(2,18,0) | 127 #if !GTK_CHECK_VERSION(2,18,0) |
128 #define gtk_widget_get_visible(x) GTK_WIDGET_VISIBLE(x) | 128 #define gtk_widget_get_visible(x) GTK_WIDGET_VISIBLE(x) |
129 #define gtk_widget_has_focus(x) GTK_WIDGET_HAS_FOCUS(x) | 129 #define gtk_widget_has_focus(x) GTK_WIDGET_HAS_FOCUS(x) |
130 #endif | 130 #endif |
131 | 131 |
132 static guint accounts_merge_id; | 132 static GtkWidget *accountmenu = NULL; |
133 static GtkActionGroup *accounts_action_group = NULL; | |
134 | 133 |
135 static guint visibility_manager_count = 0; | 134 static guint visibility_manager_count = 0; |
136 static GdkVisibilityState gtk_blist_visibility = GDK_VISIBILITY_UNOBSCURED; | 135 static GdkVisibilityState gtk_blist_visibility = GDK_VISIBILITY_UNOBSCURED; |
137 static gboolean gtk_blist_focused = FALSE; | 136 static gboolean gtk_blist_focused = FALSE; |
138 static gboolean editing_blist = FALSE; | 137 static gboolean editing_blist = FALSE; |
3638 { "Quit", GTK_STOCK_QUIT, N_("_Quit"), "<control>Q", NULL, purple_core_quit }, | 3637 { "Quit", GTK_STOCK_QUIT, N_("_Quit"), "<control>Q", NULL, purple_core_quit }, |
3639 | 3638 |
3640 /* Accounts menu */ | 3639 /* Accounts menu */ |
3641 { "AccountsMenu", NULL, N_("_Accounts"), NULL, NULL, NULL }, | 3640 { "AccountsMenu", NULL, N_("_Accounts"), NULL, NULL, NULL }, |
3642 { "ManageAccounts", NULL, N_("Manage Accounts"), "<control>A", NULL, pidgin_accounts_window_show }, | 3641 { "ManageAccounts", NULL, N_("Manage Accounts"), "<control>A", NULL, pidgin_accounts_window_show }, |
3643 { "EnableAccountMenu", NULL, N_("Enable Account"), NULL, NULL, NULL }, | |
3644 | 3642 |
3645 /* Tools */ | 3643 /* Tools */ |
3646 { "ToolsMenu", NULL, N_("_Tools"), NULL, NULL, NULL }, | 3644 { "ToolsMenu", NULL, N_("_Tools"), NULL, NULL, NULL }, |
3647 { "BuddyPounces", NULL, N_("Buddy _Pounces"), NULL, NULL, pidgin_pounces_manager_show }, | 3645 { "BuddyPounces", NULL, N_("Buddy _Pounces"), NULL, NULL, pidgin_pounces_manager_show }, |
3648 { "Certificates", NULL, N_("_Certificates"), NULL, NULL, pidgin_certmgr_show }, | 3646 { "Certificates", NULL, N_("_Certificates"), NULL, NULL, pidgin_certmgr_show }, |
3703 "<separator/>" | 3701 "<separator/>" |
3704 "<menuitem action='Quit'/>" | 3702 "<menuitem action='Quit'/>" |
3705 "</menu>" | 3703 "</menu>" |
3706 "<menu action='AccountsMenu'>" | 3704 "<menu action='AccountsMenu'>" |
3707 "<menuitem action='ManageAccounts'/>" | 3705 "<menuitem action='ManageAccounts'/>" |
3708 "<menu action='EnableAccountMenu'/>" | |
3709 "<separator/>" | |
3710 "<placeholder name='Accounts'/>" | |
3711 "</menu>" | 3706 "</menu>" |
3712 "<menu action='ToolsMenu'>" | 3707 "<menu action='ToolsMenu'>" |
3713 "<menuitem action='BuddyPounces'/>" | 3708 "<menuitem action='BuddyPounces'/>" |
3714 "<menuitem action='Certificates'/>" | 3709 "<menuitem action='Certificates'/>" |
3715 "<menuitem action='CustomSmileys'/>" | 3710 "<menuitem action='CustomSmileys'/>" |
5892 gtk_menu_shell_append(GTK_MENU_SHELL(menu), gtkblist->menutray); | 5887 gtk_menu_shell_append(GTK_MENU_SHELL(menu), gtkblist->menutray); |
5893 gtk_widget_show(gtkblist->menutray); | 5888 gtk_widget_show(gtkblist->menutray); |
5894 gtk_widget_show(menu); | 5889 gtk_widget_show(menu); |
5895 gtk_box_pack_start(GTK_BOX(gtkblist->main_vbox), menu, FALSE, FALSE, 0); | 5890 gtk_box_pack_start(GTK_BOX(gtkblist->main_vbox), menu, FALSE, FALSE, 0); |
5896 | 5891 |
5892 menu = gtk_ui_manager_get_widget(gtkblist->ui, "/BList/AccountsMenu"); | |
5893 accountmenu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(menu)); | |
5894 | |
5897 /****************************** Notebook *************************************/ | 5895 /****************************** Notebook *************************************/ |
5898 gtkblist->notebook = gtk_notebook_new(); | 5896 gtkblist->notebook = gtk_notebook_new(); |
5899 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(gtkblist->notebook), FALSE); | 5897 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(gtkblist->notebook), FALSE); |
5900 gtk_notebook_set_show_border(GTK_NOTEBOOK(gtkblist->notebook), FALSE); | 5898 gtk_notebook_set_show_border(GTK_NOTEBOOK(gtkblist->notebook), FALSE); |
5901 gtk_box_pack_start(GTK_BOX(gtkblist->main_vbox), gtkblist->notebook, TRUE, TRUE, 0); | 5899 gtk_box_pack_start(GTK_BOX(gtkblist->main_vbox), gtkblist->notebook, TRUE, TRUE, 0); |
6987 if (priv->current_theme) | 6985 if (priv->current_theme) |
6988 g_object_unref(priv->current_theme); | 6986 g_object_unref(priv->current_theme); |
6989 g_free(priv); | 6987 g_free(priv); |
6990 | 6988 |
6991 g_free(gtkblist); | 6989 g_free(gtkblist); |
6990 accountmenu = NULL; | |
6992 gtkblist = NULL; | 6991 gtkblist = NULL; |
6993 purple_prefs_disconnect_by_handle(pidgin_blist_get_handle()); | 6992 purple_prefs_disconnect_by_handle(pidgin_blist_get_handle()); |
6994 } | 6993 } |
6995 | 6994 |
6996 static void pidgin_blist_set_visible(PurpleBuddyList *list, gboolean show) | 6995 static void pidgin_blist_set_visible(PurpleBuddyList *list, gboolean show) |
8075 PurpleAccount *account = data; | 8074 PurpleAccount *account = data; |
8076 | 8075 |
8077 purple_account_set_enabled(account, PIDGIN_UI, FALSE); | 8076 purple_account_set_enabled(account, PIDGIN_UI, FALSE); |
8078 } | 8077 } |
8079 | 8078 |
8080 | |
8081 | |
8082 void | 8079 void |
8083 pidgin_blist_update_accounts_menu(void) | 8080 pidgin_blist_update_accounts_menu(void) |
8084 { | 8081 { |
8085 GList *accounts = NULL; | 8082 GtkWidget *menuitem, *submenu; |
8086 | 8083 GtkAccelGroup *accel_group; |
8087 GtkAction *action; | 8084 GList *l, *accounts; |
8088 GString *accounts_ui; | 8085 gboolean disabled_accounts = FALSE; |
8089 GString *enable_ui; | 8086 gboolean enabled_accounts = FALSE; |
8090 gchar *ui_string; | 8087 |
8091 int count = 0; | 8088 if (accountmenu == NULL) |
8092 | |
8093 if ((gtkblist == NULL) || (gtkblist->ui == NULL)) | |
8094 return; | 8089 return; |
8095 | 8090 |
8096 /* Clear the old menu */ | 8091 /* Clear the old Accounts menu */ |
8097 if (accounts_action_group) { | 8092 for (l = gtk_container_get_children(GTK_CONTAINER(accountmenu)); l; l = g_list_delete_link(l, l)) { |
8098 gtk_ui_manager_remove_ui(gtkblist->ui, accounts_merge_id); | 8093 menuitem = l->data; |
8099 gtk_ui_manager_remove_action_group(gtkblist->ui, accounts_action_group); | 8094 |
8100 g_object_unref(G_OBJECT(accounts_action_group)); | 8095 if (menuitem != gtk_ui_manager_get_widget(gtkblist->ui, "/BList/AccountsMenu/ManageAccounts")) |
8101 } | 8096 gtk_widget_destroy(menuitem); |
8102 | 8097 } |
8103 accounts_action_group = gtk_action_group_new("Accounts"); | 8098 |
8104 #ifdef ENABLE_NLS | 8099 accel_group = gtk_menu_get_accel_group(GTK_MENU(accountmenu)); |
8105 gtk_action_group_set_translation_domain(accounts_action_group, PACKAGE); | |
8106 #endif | |
8107 accounts_ui = g_string_new(NULL); | |
8108 enable_ui = g_string_new(NULL); | |
8109 | |
8110 action = gtk_action_new("none-available", N_("No actions available"), NULL, NULL); | |
8111 gtk_action_group_add_action(accounts_action_group, action); | |
8112 gtk_action_set_sensitive(action, FALSE); | |
8113 | 8100 |
8114 for (accounts = purple_accounts_get_all(); accounts; accounts = accounts->next) { | 8101 for (accounts = purple_accounts_get_all(); accounts; accounts = accounts->next) { |
8115 char *label; | 8102 char *buf = NULL; |
8116 char *base; | 8103 GtkWidget *image = NULL; |
8117 char *name; | |
8118 PurpleAccount *account = NULL; | 8104 PurpleAccount *account = NULL; |
8105 GdkPixbuf *pixbuf = NULL; | |
8119 | 8106 |
8120 account = accounts->data; | 8107 account = accounts->data; |
8121 | 8108 |
8122 base = name = g_strdup_printf("account%d", count); | 8109 if (!purple_account_get_enabled(account, PIDGIN_UI)) { |
8123 label = g_strconcat(purple_account_get_username(account), " (", | 8110 if (!disabled_accounts) { |
8111 menuitem = gtk_menu_item_new_with_label(_("Enable Account")); | |
8112 gtk_menu_shell_append(GTK_MENU_SHELL(accountmenu), menuitem); | |
8113 | |
8114 submenu = gtk_menu_new(); | |
8115 gtk_menu_set_accel_group(GTK_MENU(submenu), accel_group); | |
8116 gtk_menu_set_accel_path(GTK_MENU(submenu), N_("<main>/AccountsMenu/EnableAccount")); | |
8117 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), submenu); | |
8118 | |
8119 disabled_accounts = TRUE; | |
8120 } | |
8121 | |
8122 buf = g_strconcat(purple_account_get_username(account), " (", | |
8124 purple_account_get_protocol_name(account), ")", NULL); | 8123 purple_account_get_protocol_name(account), ")", NULL); |
8125 action = gtk_action_new(name, label, NULL, NULL); | 8124 menuitem = gtk_image_menu_item_new_with_label(buf); |
8126 g_free(label); | 8125 g_free(buf); |
8127 gtk_action_group_add_action(accounts_action_group, action); | 8126 |
8128 | 8127 pixbuf = pidgin_create_prpl_icon(account, PIDGIN_PRPL_ICON_SMALL); |
8129 if (!purple_account_get_enabled(account, PIDGIN_UI)) { | 8128 if (pixbuf != NULL) { |
8130 g_string_append_printf(enable_ui, "<menuitem action='%s'/>", name); | 8129 if (!purple_account_is_connected(account)) |
8131 g_signal_connect(G_OBJECT(action), "activate", | 8130 gdk_pixbuf_saturate_and_pixelate(pixbuf, pixbuf, 0.0, FALSE); |
8132 G_CALLBACK(enable_account_cb), account); | 8131 image = gtk_image_new_from_pixbuf(pixbuf); |
8132 g_object_unref(G_OBJECT(pixbuf)); | |
8133 gtk_widget_show(image); | |
8134 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem), image); | |
8135 } | |
8136 | |
8137 g_signal_connect(G_OBJECT(menuitem), "activate", | |
8138 G_CALLBACK(enable_account_cb), account); | |
8139 gtk_menu_shell_append(GTK_MENU_SHELL(submenu), menuitem); | |
8133 | 8140 |
8134 } else { | 8141 } else { |
8135 PurpleConnection *gc = NULL; | 8142 enabled_accounts = TRUE; |
8136 PurplePlugin *plugin = NULL; | 8143 } |
8137 | 8144 } |
8138 g_string_append_printf(accounts_ui, "<menu action='%s'>", name); | 8145 |
8139 | 8146 if (!enabled_accounts) { |
8140 name = g_strconcat(base, "-edit", NULL); | 8147 gtk_widget_show_all(accountmenu); |
8141 action = gtk_action_new(name, N_("_Edit Account"), NULL, NULL); | 8148 return; |
8142 gtk_action_group_add_action(accounts_action_group, action); | 8149 } |
8143 g_signal_connect(G_OBJECT(action), "activate", | 8150 |
8144 G_CALLBACK(modify_account_cb), account); | 8151 pidgin_separator(accountmenu); |
8145 g_string_append_printf(accounts_ui, "<menuitem action='%s'/>", name); | 8152 |
8146 g_free(name); | 8153 for (accounts = purple_accounts_get_all(); accounts; accounts = accounts->next) { |
8147 | 8154 char *buf = NULL; |
8148 g_string_append(accounts_ui, "<separator/>"); | 8155 char *accel_path_buf = NULL; |
8149 | 8156 GtkWidget *image = NULL; |
8150 gc = purple_account_get_connection(account); | 8157 PurpleConnection *gc = NULL; |
8151 plugin = gc && PURPLE_CONNECTION_IS_CONNECTED(gc) ? purple_connection_get_prpl(gc) : NULL; | 8158 PurpleAccount *account = NULL; |
8152 if (plugin && PURPLE_PLUGIN_HAS_ACTIONS(plugin)) { | 8159 GdkPixbuf *pixbuf = NULL; |
8153 build_plugin_actions(accounts_action_group, accounts_ui, base, plugin, gc); | 8160 PurplePlugin *plugin = NULL; |
8154 } else { | 8161 PurplePluginProtocolInfo *prpl_info; |
8155 g_string_append(accounts_ui, "<menuitem action='none-available'/>"); | 8162 |
8163 account = accounts->data; | |
8164 | |
8165 if (!purple_account_get_enabled(account, PIDGIN_UI)) | |
8166 continue; | |
8167 | |
8168 buf = g_strconcat(purple_account_get_username(account), " (", | |
8169 purple_account_get_protocol_name(account), ")", NULL); | |
8170 menuitem = gtk_image_menu_item_new_with_label(buf); | |
8171 accel_path_buf = g_strconcat(N_("<main>/AccountsMenu/"), buf, NULL); | |
8172 g_free(buf); | |
8173 | |
8174 pixbuf = pidgin_create_prpl_icon(account, PIDGIN_PRPL_ICON_SMALL); | |
8175 if (pixbuf != NULL) { | |
8176 if (!purple_account_is_connected(account)) | |
8177 gdk_pixbuf_saturate_and_pixelate(pixbuf, pixbuf, | |
8178 0.0, FALSE); | |
8179 image = gtk_image_new_from_pixbuf(pixbuf); | |
8180 g_object_unref(G_OBJECT(pixbuf)); | |
8181 gtk_widget_show(image); | |
8182 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem), image); | |
8183 } | |
8184 | |
8185 gtk_menu_shell_append(GTK_MENU_SHELL(accountmenu), menuitem); | |
8186 | |
8187 submenu = gtk_menu_new(); | |
8188 gtk_menu_set_accel_group(GTK_MENU(submenu), accel_group); | |
8189 gtk_menu_set_accel_path(GTK_MENU(submenu), accel_path_buf); | |
8190 g_free(accel_path_buf); | |
8191 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), submenu); | |
8192 | |
8193 menuitem = gtk_menu_item_new_with_mnemonic(_("_Edit Account")); | |
8194 g_signal_connect(G_OBJECT(menuitem), "activate", | |
8195 G_CALLBACK(modify_account_cb), account); | |
8196 gtk_menu_shell_append(GTK_MENU_SHELL(submenu), menuitem); | |
8197 | |
8198 pidgin_separator(submenu); | |
8199 | |
8200 gc = purple_account_get_connection(account); | |
8201 plugin = gc && PURPLE_CONNECTION_IS_CONNECTED(gc) ? purple_connection_get_prpl(gc) : NULL; | |
8202 prpl_info = plugin ? PURPLE_PLUGIN_PROTOCOL_INFO(plugin) : NULL; | |
8203 | |
8204 if (prpl_info && | |
8205 (PURPLE_PROTOCOL_PLUGIN_HAS_FUNC(prpl_info, get_moods) || | |
8206 PURPLE_PLUGIN_HAS_ACTIONS(plugin))) { | |
8207 if (PURPLE_PROTOCOL_PLUGIN_HAS_FUNC(prpl_info, get_moods) && | |
8208 (purple_connection_get_flags(gc) & PURPLE_CONNECTION_SUPPORT_MOODS)) { | |
8209 | |
8210 if (purple_account_get_status(account, "mood")) { | |
8211 menuitem = gtk_menu_item_new_with_mnemonic(_("Set _Mood...")); | |
8212 g_signal_connect(G_OBJECT(menuitem), "activate", | |
8213 G_CALLBACK(set_mood_cb), account); | |
8214 gtk_menu_shell_append(GTK_MENU_SHELL(submenu), menuitem); | |
8215 } | |
8156 } | 8216 } |
8157 | 8217 |
8158 g_string_append(accounts_ui, "<separator/>"); | 8218 if (PURPLE_PLUGIN_HAS_ACTIONS(plugin)) { |
8159 | 8219 GtkWidget *menuitem; |
8160 name = g_strconcat(base, "-disable", NULL); | 8220 PurplePluginAction *action = NULL; |
8161 action = gtk_action_new(name, N_("_Disable"), NULL, NULL); | 8221 GList *actions, *l; |
8162 gtk_action_group_add_action(accounts_action_group, action); | 8222 |
8163 g_signal_connect(G_OBJECT(action), "activate", | 8223 actions = PURPLE_PLUGIN_ACTIONS(plugin, gc); |
8164 G_CALLBACK(disable_account_cb), account); | 8224 |
8165 g_string_append_printf(accounts_ui, "<menuitem action='%s'/>", name); | 8225 for (l = actions; l != NULL; l = l->next) |
8166 g_free(name); | 8226 { |
8167 | 8227 if (l->data) |
8168 g_string_append(accounts_ui, "</menu>"); | 8228 { |
8169 } | 8229 action = (PurplePluginAction *) l->data; |
8170 | 8230 action->plugin = plugin; |
8171 g_free(base); | 8231 action->context = gc; |
8172 count++; | 8232 |
8173 } | 8233 menuitem = gtk_menu_item_new_with_label(action->label); |
8174 | 8234 gtk_menu_shell_append(GTK_MENU_SHELL(submenu), menuitem); |
8175 ui_string = g_strconcat("<ui><menubar action='BList'><menu action='AccountsMenu'><menu action='EnableAccountMenu'>", | 8235 |
8176 enable_ui->str, | 8236 g_signal_connect(G_OBJECT(menuitem), "activate", |
8177 "</menu><placeholder name='Accounts'>", | 8237 G_CALLBACK(plugin_act), action); |
8178 accounts_ui->str, | 8238 g_object_set_data_full(G_OBJECT(menuitem), "plugin_action", |
8179 "</placeholder></menu></menubar></ui>", | 8239 action, |
8180 NULL); | 8240 (GDestroyNotify)purple_plugin_action_free); |
8181 gtk_ui_manager_insert_action_group(gtkblist->ui, accounts_action_group, 1); | 8241 gtk_widget_show(menuitem); |
8182 accounts_merge_id = gtk_ui_manager_add_ui_from_string(gtkblist->ui, ui_string, -1, NULL); | 8242 } |
8183 purple_debug_info("blist", "The account menu is {%s}\n", ui_string); | 8243 else |
8184 | 8244 pidgin_separator(submenu); |
8185 g_string_free(enable_ui, TRUE); | 8245 } |
8186 g_string_free(accounts_ui, TRUE); | 8246 |
8187 g_free(ui_string); | 8247 g_list_free(actions); |
8248 } | |
8249 } else { | |
8250 menuitem = gtk_menu_item_new_with_label(_("No actions available")); | |
8251 gtk_menu_shell_append(GTK_MENU_SHELL(submenu), menuitem); | |
8252 gtk_widget_set_sensitive(menuitem, FALSE); | |
8253 } | |
8254 | |
8255 pidgin_separator(submenu); | |
8256 | |
8257 menuitem = gtk_menu_item_new_with_mnemonic(_("_Disable")); | |
8258 g_signal_connect(G_OBJECT(menuitem), "activate", | |
8259 G_CALLBACK(disable_account_cb), account); | |
8260 gtk_menu_shell_append(GTK_MENU_SHELL(submenu), menuitem); | |
8261 } | |
8262 | |
8263 gtk_widget_show_all(accountmenu); | |
8188 } | 8264 } |
8189 | 8265 |
8190 static guint plugins_merge_id; | 8266 static guint plugins_merge_id; |
8191 static GtkActionGroup *plugins_action_group = NULL; | 8267 static GtkActionGroup *plugins_action_group = NULL; |
8192 | 8268 |