pidgin/pidginaccountsmenu.c

Mon, 16 Aug 2021 03:10:08 -0500

author
Gary Kramlich <grim@reaperworld.com>
date
Mon, 16 Aug 2021 03:10:08 -0500
changeset 41030
ec8b76f3bf0a
parent 40600
46d10c72c137
child 41209
909561f42b1f
permissions
-rw-r--r--

Fix the resource path so we can use the automatic stuff that GtkApplication supports

Testing Done:
Opened a conversation, as well as the plugins and help dialogs.

Reviewed at https://reviews.imfreedom.org/r/898/

40379
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1 /*
40597
fa308dd62f4c Properly set the sensitive state of the "enable account" menu item based on whether or not any accounts are disabled.
Gary Kramlich <grim@reaperworld.com>
parents: 40504
diff changeset
2 * Pidgin - Internet Messenger
fa308dd62f4c Properly set the sensitive state of the "enable account" menu item based on whether or not any accounts are disabled.
Gary Kramlich <grim@reaperworld.com>
parents: 40504
diff changeset
3 * Copyright (C) Pidgin Developers <devel@pidgin.im>
40379
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
4 *
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
5 * Pidgin is the legal property of its developers, whose names are too numerous
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
6 * to list here. Please refer to the COPYRIGHT file distributed with this
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
7 * source distribution.
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
8 *
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
9 * This program is free software; you can redistribute it and/or modify
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
10 * it under the terms of the GNU General Public License as published by
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
11 * the Free Software Foundation; either version 2 of the License, or
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
12 * (at your option) any later version.
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
13 *
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
14 * This program is distributed in the hope that it will be useful,
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
17 * GNU General Public License for more details.
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
18 *
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
19 * You should have received a copy of the GNU General Public License
40597
fa308dd62f4c Properly set the sensitive state of the "enable account" menu item based on whether or not any accounts are disabled.
Gary Kramlich <grim@reaperworld.com>
parents: 40504
diff changeset
20 * along with this program; if not, see <https://www.gnu.org/licenses/>.
40379
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
21 */
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
22
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
23 #include "pidginaccountsmenu.h"
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
24
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
25 #include <purple.h>
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
26
40496
6941fece679b phase2 of pidgin.h: move existing file to pidgincore.h
Gary Kramlich <grim@reaperworld.com>
parents: 40444
diff changeset
27 #include "pidginaccountactionsmenu.h"
6941fece679b phase2 of pidgin.h: move existing file to pidgincore.h
Gary Kramlich <grim@reaperworld.com>
parents: 40444
diff changeset
28
6941fece679b phase2 of pidgin.h: move existing file to pidgincore.h
Gary Kramlich <grim@reaperworld.com>
parents: 40444
diff changeset
29 #include "pidgincore.h"
40379
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
30
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
31 struct _PidginAccountsMenu {
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
32 GtkMenu parent;
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
33
40597
fa308dd62f4c Properly set the sensitive state of the "enable account" menu item based on whether or not any accounts are disabled.
Gary Kramlich <grim@reaperworld.com>
parents: 40504
diff changeset
34 GtkWidget *enable_account;
40379
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
35 GtkWidget *disabled_menu;
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
36 GtkWidget *separator;
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
37
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
38 GHashTable *account_items;
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
39 GHashTable *disabled_items;
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
40 };
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
41
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
42 /******************************************************************************
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
43 * GSignal Handlers
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
44 *****************************************************************************/
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
45 static void
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
46 pidgin_accounts_menu_enable_account(GtkMenuItem *item, gpointer data) {
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
47 PurpleAccount *account = PURPLE_ACCOUNT(data);
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
48
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
49 purple_account_set_enabled(account, PIDGIN_UI, TRUE);
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
50 }
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
51
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
52 /******************************************************************************
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
53 * Helpers
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
54 *****************************************************************************/
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
55 static GtkWidget *
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
56 pidgin_accounts_menu_create_account_menu_item(PidginAccountsMenu *menu,
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
57 PurpleAccount *account)
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
58 {
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
59 GtkWidget *item = NULL;
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
60 const gchar *account_name = purple_account_get_username(account);
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
61 const gchar *protocol_name = purple_account_get_protocol_name(account);
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
62 gchar *label = g_strdup_printf("%s (%s)", account_name, protocol_name);
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
63
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
64 item = gtk_menu_item_new_with_label(label);
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
65 g_free(label);
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
66 gtk_widget_show(item);
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
67
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
68 return item;
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
69 }
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
70
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
71 static void
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
72 pidgin_accounts_menu_add_enabled_account(PidginAccountsMenu *menu,
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
73 PurpleAccount *account)
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
74 {
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
75 GtkWidget *item = NULL, *submenu = NULL;
40504
413ef6af21ab Fix a bunch of random warnings
Gary Kramlich <grim@reaperworld.com>
parents: 40498
diff changeset
76 gpointer data = NULL;
413ef6af21ab Fix a bunch of random warnings
Gary Kramlich <grim@reaperworld.com>
parents: 40498
diff changeset
77 gboolean found = FALSE;
40379
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
78
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
79 /* if the account is in the disabled list, delete its widget */
40504
413ef6af21ab Fix a bunch of random warnings
Gary Kramlich <grim@reaperworld.com>
parents: 40498
diff changeset
80 found = g_hash_table_lookup_extended(menu->disabled_items, account, NULL,
413ef6af21ab Fix a bunch of random warnings
Gary Kramlich <grim@reaperworld.com>
parents: 40498
diff changeset
81 &data);
413ef6af21ab Fix a bunch of random warnings
Gary Kramlich <grim@reaperworld.com>
parents: 40498
diff changeset
82 if(found) {
413ef6af21ab Fix a bunch of random warnings
Gary Kramlich <grim@reaperworld.com>
parents: 40498
diff changeset
83 g_clear_pointer(&data, gtk_widget_destroy);
40498
b119cf7a05b9 Fix memory issues at shutdown
Elliott S <quantum.analyst@gmail.com>
parents: 40496
diff changeset
84 g_hash_table_remove(menu->disabled_items, account);
40597
fa308dd62f4c Properly set the sensitive state of the "enable account" menu item based on whether or not any accounts are disabled.
Gary Kramlich <grim@reaperworld.com>
parents: 40504
diff changeset
85
fa308dd62f4c Properly set the sensitive state of the "enable account" menu item based on whether or not any accounts are disabled.
Gary Kramlich <grim@reaperworld.com>
parents: 40504
diff changeset
86 if(g_hash_table_size(menu->disabled_items) == 0) {
fa308dd62f4c Properly set the sensitive state of the "enable account" menu item based on whether or not any accounts are disabled.
Gary Kramlich <grim@reaperworld.com>
parents: 40504
diff changeset
87 gtk_widget_set_sensitive(menu->enable_account, FALSE);
fa308dd62f4c Properly set the sensitive state of the "enable account" menu item based on whether or not any accounts are disabled.
Gary Kramlich <grim@reaperworld.com>
parents: 40504
diff changeset
88 }
40498
b119cf7a05b9 Fix memory issues at shutdown
Elliott S <quantum.analyst@gmail.com>
parents: 40496
diff changeset
89 }
40379
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
90
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
91 item = pidgin_accounts_menu_create_account_menu_item(menu, account);
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
92 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
93 g_hash_table_insert(menu->account_items,
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
94 g_object_ref(G_OBJECT(account)),
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
95 item);
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
96
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
97 /* create the submenu and attach it to item right away, this allows us to
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
98 * reuse item for the submenu items.
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
99 */
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
100 submenu = pidgin_account_actions_menu_new(account);
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
101 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu);
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
102 }
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
103
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
104 static void
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
105 pidgin_accounts_menu_add_disabled_account(PidginAccountsMenu *menu,
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
106 PurpleAccount *account)
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
107 {
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
108 GtkWidget *item = NULL;
40504
413ef6af21ab Fix a bunch of random warnings
Gary Kramlich <grim@reaperworld.com>
parents: 40498
diff changeset
109 gpointer data = NULL;
413ef6af21ab Fix a bunch of random warnings
Gary Kramlich <grim@reaperworld.com>
parents: 40498
diff changeset
110 gboolean found = FALSE;
40379
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
111
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
112 /* if the account is in the enabled list, delete its widget */
40504
413ef6af21ab Fix a bunch of random warnings
Gary Kramlich <grim@reaperworld.com>
parents: 40498
diff changeset
113 found = g_hash_table_lookup_extended(menu->account_items, account, NULL,
413ef6af21ab Fix a bunch of random warnings
Gary Kramlich <grim@reaperworld.com>
parents: 40498
diff changeset
114 &data);
413ef6af21ab Fix a bunch of random warnings
Gary Kramlich <grim@reaperworld.com>
parents: 40498
diff changeset
115 if(found) {
413ef6af21ab Fix a bunch of random warnings
Gary Kramlich <grim@reaperworld.com>
parents: 40498
diff changeset
116 g_clear_pointer(&data, gtk_widget_destroy);
40498
b119cf7a05b9 Fix memory issues at shutdown
Elliott S <quantum.analyst@gmail.com>
parents: 40496
diff changeset
117 g_hash_table_remove(menu->account_items, account);
b119cf7a05b9 Fix memory issues at shutdown
Elliott S <quantum.analyst@gmail.com>
parents: 40496
diff changeset
118 }
40379
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
119
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
120 item = pidgin_accounts_menu_create_account_menu_item(menu, account);
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
121 g_signal_connect(G_OBJECT(item), "activate",
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
122 G_CALLBACK(pidgin_accounts_menu_enable_account), account);
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
123 gtk_menu_shell_append(GTK_MENU_SHELL(menu->disabled_menu), item);
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
124
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
125 g_hash_table_insert(menu->disabled_items,
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
126 g_object_ref(G_OBJECT(account)),
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
127 item);
40597
fa308dd62f4c Properly set the sensitive state of the "enable account" menu item based on whether or not any accounts are disabled.
Gary Kramlich <grim@reaperworld.com>
parents: 40504
diff changeset
128
fa308dd62f4c Properly set the sensitive state of the "enable account" menu item based on whether or not any accounts are disabled.
Gary Kramlich <grim@reaperworld.com>
parents: 40504
diff changeset
129 /* We know there's at least one item in the menu, so make sure it is
fa308dd62f4c Properly set the sensitive state of the "enable account" menu item based on whether or not any accounts are disabled.
Gary Kramlich <grim@reaperworld.com>
parents: 40504
diff changeset
130 * sensitive.
fa308dd62f4c Properly set the sensitive state of the "enable account" menu item based on whether or not any accounts are disabled.
Gary Kramlich <grim@reaperworld.com>
parents: 40504
diff changeset
131 */
fa308dd62f4c Properly set the sensitive state of the "enable account" menu item based on whether or not any accounts are disabled.
Gary Kramlich <grim@reaperworld.com>
parents: 40504
diff changeset
132 gtk_widget_set_sensitive(menu->enable_account, TRUE);
40379
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
133 }
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
134
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
135 static void
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
136 pidgin_accounts_menu_add_current(PidginAccountsMenu *menu) {
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
137 GList *accounts = NULL, *l = NULL;
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
138
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
139 accounts = purple_accounts_get_all();
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
140 for(l = accounts; l != NULL; l = l->next) {
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
141 PurpleAccount *account = PURPLE_ACCOUNT(l->data);
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
142
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
143 if(purple_account_get_enabled(account, PIDGIN_UI)) {
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
144 pidgin_accounts_menu_add_enabled_account(menu, account);
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
145 } else {
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
146 pidgin_accounts_menu_add_disabled_account(menu, account);
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
147 }
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
148 }
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
149 }
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
150
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
151 /******************************************************************************
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
152 * Purple Signal Callbacks
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
153 *****************************************************************************/
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
154 static void
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
155 pidgin_accounts_menu_account_status_changed(PurpleAccount *account,
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
156 gpointer d)
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
157 {
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
158 PidginAccountsMenu *menu = PIDGIN_ACCOUNTS_MENU(d);
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
159 gpointer data = NULL;
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
160
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
161 data = g_hash_table_lookup(menu->account_items, account);
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
162 if(GTK_IS_WIDGET(data)) {
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
163 gtk_menu_item_set_submenu(GTK_MENU_ITEM(data),
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
164 pidgin_account_actions_menu_new(account));
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
165 }
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
166 }
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
167
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
168 static void
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
169 pidgin_accounts_menu_account_enabled(PurpleAccount *account, gpointer data) {
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
170 pidgin_accounts_menu_add_enabled_account(PIDGIN_ACCOUNTS_MENU(data),
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
171 account);
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
172 }
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
173
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
174 static void
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
175 pidgin_accounts_menu_account_disabled(PurpleAccount *account, gpointer data) {
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
176 pidgin_accounts_menu_add_disabled_account(PIDGIN_ACCOUNTS_MENU(data),
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
177 account);
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
178 }
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
179
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
180 /******************************************************************************
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
181 * GObject Implementation
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
182 *****************************************************************************/
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
183 G_DEFINE_TYPE(PidginAccountsMenu, pidgin_accounts_menu, GTK_TYPE_MENU)
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
184
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
185 static void
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
186 pidgin_accounts_menu_init(PidginAccountsMenu *menu) {
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
187 gpointer handle;
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
188
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
189 /* initialize our template */
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
190 gtk_widget_init_template(GTK_WIDGET(menu));
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
191
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
192 /* create our storage for the items */
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
193 menu->account_items = g_hash_table_new_full(g_direct_hash, g_direct_equal,
40498
b119cf7a05b9 Fix memory issues at shutdown
Elliott S <quantum.analyst@gmail.com>
parents: 40496
diff changeset
194 g_object_unref, NULL);
40379
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
195 menu->disabled_items = g_hash_table_new_full(g_direct_hash, g_direct_equal,
40498
b119cf7a05b9 Fix memory issues at shutdown
Elliott S <quantum.analyst@gmail.com>
parents: 40496
diff changeset
196 g_object_unref, NULL);
40379
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
197
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
198 /* add all of the existing accounts */
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
199 pidgin_accounts_menu_add_current(menu);
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
200
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
201 /* finally connect to the purple signals to stay up to date */
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
202 handle = purple_accounts_get_handle();
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
203 purple_signal_connect(handle, "account-signed-on", menu,
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
204 G_CALLBACK(pidgin_accounts_menu_account_status_changed),
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
205 menu);
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
206 purple_signal_connect(handle, "account-signed-off", menu,
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
207 G_CALLBACK(pidgin_accounts_menu_account_status_changed),
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
208 menu);
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
209 purple_signal_connect(handle, "account-actions-changed", menu,
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
210 G_CALLBACK(pidgin_accounts_menu_account_status_changed),
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
211 menu);
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
212 purple_signal_connect(handle, "account-enabled", menu,
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
213 G_CALLBACK(pidgin_accounts_menu_account_enabled),
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
214 menu);
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
215 purple_signal_connect(handle, "account-disabled", menu,
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
216 G_CALLBACK(pidgin_accounts_menu_account_disabled),
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
217 menu);
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
218 };
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
219
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
220 static void
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
221 pidgin_accounts_menu_finalize(GObject *obj) {
40388
3f2e9e346f6f Fix a bunch of stuff that was found in review.
Gary Kramlich <grim@reaperworld.com>
parents: 40387
diff changeset
222 PidginAccountsMenu *menu = PIDGIN_ACCOUNTS_MENU(obj);
3f2e9e346f6f Fix a bunch of stuff that was found in review.
Gary Kramlich <grim@reaperworld.com>
parents: 40387
diff changeset
223
40379
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
224 purple_signals_disconnect_by_handle(obj);
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
225
40388
3f2e9e346f6f Fix a bunch of stuff that was found in review.
Gary Kramlich <grim@reaperworld.com>
parents: 40387
diff changeset
226 g_hash_table_destroy(menu->account_items);
3f2e9e346f6f Fix a bunch of stuff that was found in review.
Gary Kramlich <grim@reaperworld.com>
parents: 40387
diff changeset
227 g_hash_table_destroy(menu->disabled_items);
3f2e9e346f6f Fix a bunch of stuff that was found in review.
Gary Kramlich <grim@reaperworld.com>
parents: 40387
diff changeset
228
40379
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
229 G_OBJECT_CLASS(pidgin_accounts_menu_parent_class)->finalize(obj);
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
230 }
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
231
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
232 static void
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
233 pidgin_accounts_menu_class_init(PidginAccountsMenuClass *klass) {
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
234 GObjectClass *obj_class = G_OBJECT_CLASS(klass);
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
235 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass);
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
236
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
237 obj_class->finalize = pidgin_accounts_menu_finalize;
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
238
40387
4cdb2a681dc1 use g_list_index instead of manually searching a list and a bunch of whitespace fixes
Gary Kramlich <grim@reaperworld.com>
parents: 40379
diff changeset
239 gtk_widget_class_set_template_from_resource(
4cdb2a681dc1 use g_list_index instead of manually searching a list and a bunch of whitespace fixes
Gary Kramlich <grim@reaperworld.com>
parents: 40379
diff changeset
240 widget_class,
41030
ec8b76f3bf0a Fix the resource path so we can use the automatic stuff that GtkApplication supports
Gary Kramlich <grim@reaperworld.com>
parents: 40600
diff changeset
241 "/im/pidgin/Pidgin3/Accounts/menu.ui"
40387
4cdb2a681dc1 use g_list_index instead of manually searching a list and a bunch of whitespace fixes
Gary Kramlich <grim@reaperworld.com>
parents: 40379
diff changeset
242 );
40379
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
243
40387
4cdb2a681dc1 use g_list_index instead of manually searching a list and a bunch of whitespace fixes
Gary Kramlich <grim@reaperworld.com>
parents: 40379
diff changeset
244 gtk_widget_class_bind_template_child(widget_class, PidginAccountsMenu,
40597
fa308dd62f4c Properly set the sensitive state of the "enable account" menu item based on whether or not any accounts are disabled.
Gary Kramlich <grim@reaperworld.com>
parents: 40504
diff changeset
245 enable_account);
fa308dd62f4c Properly set the sensitive state of the "enable account" menu item based on whether or not any accounts are disabled.
Gary Kramlich <grim@reaperworld.com>
parents: 40504
diff changeset
246 gtk_widget_class_bind_template_child(widget_class, PidginAccountsMenu,
40387
4cdb2a681dc1 use g_list_index instead of manually searching a list and a bunch of whitespace fixes
Gary Kramlich <grim@reaperworld.com>
parents: 40379
diff changeset
247 disabled_menu);
4cdb2a681dc1 use g_list_index instead of manually searching a list and a bunch of whitespace fixes
Gary Kramlich <grim@reaperworld.com>
parents: 40379
diff changeset
248 gtk_widget_class_bind_template_child(widget_class, PidginAccountsMenu,
4cdb2a681dc1 use g_list_index instead of manually searching a list and a bunch of whitespace fixes
Gary Kramlich <grim@reaperworld.com>
parents: 40379
diff changeset
249 separator);
40379
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
250 }
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
251
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
252 /******************************************************************************
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
253 * Public API
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
254 *****************************************************************************/
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
255 GtkWidget *
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
256 pidgin_accounts_menu_new(void) {
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
257 return GTK_WIDGET(g_object_new(PIDGIN_TYPE_ACCOUNTS_MENU, NULL));
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
258 }
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
259

mercurial