pidgin/pidginaccountsmenu.c

Thu, 06 Aug 2020 22:22:03 -0500

author
Gary Kramlich <grim@reaperworld.com>
date
Thu, 06 Aug 2020 22:22:03 -0500
changeset 40502
875489636847
parent 40498
b119cf7a05b9
child 40504
413ef6af21ab
permissions
-rw-r--r--

pidgin.h phase3: create pidgin.h and force its usage

fix the section id of pidgincore.h

Generate our pidgin.h file

Add include guard to all pidgin/*.h files and deal with the fallout from that.

Also had to namespace PIDGIN_BLIST_COLUMN_NAME, will come back and get the rest at a later time.

Testing Done:
Compile test, including some plugins that don't build by default. Also ran everything seems fine.

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

40379
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1 /*
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
2 * pidgin
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
3 *
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
4 * 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
5 * 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
6 * source distribution.
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
7 *
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
8 * 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
9 * 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
10 * 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
11 * (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
12 *
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
13 * 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
14 * 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
15 * 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
16 * 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
17 *
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
19 * along with this program; if not, write to the Free Software
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
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 "gtkaccount.h"
6941fece679b phase2 of pidgin.h: move existing file to pidgincore.h
Gary Kramlich <grim@reaperworld.com>
parents: 40444
diff changeset
30 #include "pidgincore.h"
40379
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
31
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
32 struct _PidginAccountsMenu {
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
33 GtkMenu parent;
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
34
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_open_manager_cb(GtkMenuItem *item, gpointer data) {
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
47 pidgin_accounts_window_show();
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
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
50 static void
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
51 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
52 PurpleAccount *account = PURPLE_ACCOUNT(data);
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
53
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
54 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
55 }
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
56
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
57 /******************************************************************************
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
58 * Helpers
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
59 *****************************************************************************/
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
60 static GtkWidget *
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
61 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
62 PurpleAccount *account)
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 GtkWidget *item = NULL;
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
65 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
66 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
67 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
68
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
69 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
70 g_free(label);
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
71 gtk_widget_show(item);
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
72
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
73 return item;
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
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
76 static void
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
77 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
78 PurpleAccount *account)
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
79 {
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
80 GtkWidget *item = NULL, *submenu = NULL;
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
81
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
82 /* if the account is in the disabled list, delete its widget */
40498
b119cf7a05b9 Fix memory issues at shutdown
Elliott S <quantum.analyst@gmail.com>
parents: 40496
diff changeset
83 if (g_hash_table_lookup_extended(menu->disabled_items, account, NULL, &item)) {
b119cf7a05b9 Fix memory issues at shutdown
Elliott S <quantum.analyst@gmail.com>
parents: 40496
diff changeset
84 g_clear_pointer(&item, gtk_widget_destroy);
b119cf7a05b9 Fix memory issues at shutdown
Elliott S <quantum.analyst@gmail.com>
parents: 40496
diff changeset
85 g_hash_table_remove(menu->disabled_items, account);
b119cf7a05b9 Fix memory issues at shutdown
Elliott S <quantum.analyst@gmail.com>
parents: 40496
diff changeset
86 }
40379
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
87
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
88 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
89 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
90 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
91 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
92 item);
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
93
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
94 /* 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
95 * 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
96 */
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
97 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
98 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
99 }
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
100
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
101 static void
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
102 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
103 PurpleAccount *account)
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
104 {
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
105 GtkWidget *item = NULL;
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
106
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
107 /* if the account is in the enabled list, delete its widget */
40498
b119cf7a05b9 Fix memory issues at shutdown
Elliott S <quantum.analyst@gmail.com>
parents: 40496
diff changeset
108 if (g_hash_table_lookup_extended(menu->account_items, account, NULL, &item)) {
b119cf7a05b9 Fix memory issues at shutdown
Elliott S <quantum.analyst@gmail.com>
parents: 40496
diff changeset
109 g_clear_pointer(&item, gtk_widget_destroy);
b119cf7a05b9 Fix memory issues at shutdown
Elliott S <quantum.analyst@gmail.com>
parents: 40496
diff changeset
110 g_hash_table_remove(menu->account_items, account);
b119cf7a05b9 Fix memory issues at shutdown
Elliott S <quantum.analyst@gmail.com>
parents: 40496
diff changeset
111 }
40379
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
112
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
113 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
114 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
115 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
116 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
117
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
118 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
119 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
120 item);
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
121 }
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
122
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
123 static void
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
124 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
125 GList *accounts = NULL, *l = NULL;
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
126
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
127 accounts = purple_accounts_get_all();
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
128 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
129 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
130
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
131 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
132 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
133 } else {
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
134 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
135 }
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
136 }
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
137 }
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 /******************************************************************************
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
140 * Purple Signal Callbacks
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
141 *****************************************************************************/
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
142 static void
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
143 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
144 gpointer d)
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
145 {
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
146 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
147 gpointer data = NULL;
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 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
150 if(GTK_IS_WIDGET(data)) {
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
151 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
152 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
153 }
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
154 }
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
155
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
156 static void
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
157 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
158 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
159 account);
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
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
162 static void
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
163 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
164 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
165 account);
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 /******************************************************************************
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
169 * GObject Implementation
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
170 *****************************************************************************/
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
171 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
172
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
173 static void
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
174 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
175 gpointer handle;
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
176
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
177 /* initialize our template */
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
178 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
179
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
180 /* 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
181 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
182 g_object_unref, NULL);
40379
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
183 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
184 g_object_unref, NULL);
40379
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
185
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
186 /* 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
187 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
188
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
189 /* 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
190 handle = purple_accounts_get_handle();
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
191 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
192 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
193 menu);
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
194 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
195 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
196 menu);
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
197 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
198 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
199 menu);
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
200 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
201 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
202 menu);
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-disabled", 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_disabled),
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 };
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
207
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
208 static void
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
209 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
210 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
211
40379
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
212 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
213
40388
3f2e9e346f6f Fix a bunch of stuff that was found in review.
Gary Kramlich <grim@reaperworld.com>
parents: 40387
diff changeset
214 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
215 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
216
40379
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
217 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
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_class_init(PidginAccountsMenuClass *klass) {
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
222 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
223 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
224
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
225 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
226
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
227 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
228 widget_class,
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
229 "/im/pidgin/Pidgin/Accounts/menu.ui"
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
230 );
40379
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
231
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
232 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
233 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
234 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
235 separator);
40379
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
236
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
237 gtk_widget_class_bind_template_callback(widget_class,
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
238 pidgin_accounts_menu_open_manager_cb);
40379
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
239 }
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
240
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
241 /******************************************************************************
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
242 * Public API
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
243 *****************************************************************************/
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
244 GtkWidget *
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
245 pidgin_accounts_menu_new(void) {
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
246 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
247 }
c50c509dd028 Migrate the accounts menu to its own set of widgets
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
248

mercurial