libpurple/purpleaccountmanager.c

Wed, 14 Dec 2022 01:29:28 -0600

author
Gary Kramlich <grim@reaperworld.com>
date
Wed, 14 Dec 2022 01:29:28 -0600
changeset 41976
49969fa9a664
parent 41946
0fb3b0e7122f
child 42049
16d2e16bd24f
permissions
-rw-r--r--

Update libpurple for the deprecations in the account api

Testing Done:
Compiled and ran the unit tests.

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

41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1 /*
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
2 * Purple - Internet Messaging Library
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
3 * Copyright (C) Pidgin Developers <devel@pidgin.im>
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
4 *
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
5 * This program is free software; you can redistribute it and/or modify
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
7 * the Free Software Foundation; either version 2 of the License, or
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
8 * (at your option) any later version.
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
9 *
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
13 * GNU General Public License for more details.
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
14 *
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
16 * along with this program; if not, see <https://www.gnu.org/licenses/>.
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
17 */
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
18
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
19 #include "purpleaccountmanager.h"
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
20 #include "purpleprivate.h"
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
21
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
22 #include "account.h"
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
23 #include "accounts.h"
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
24 #include "core.h"
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
25
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
26 enum {
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
27 SIG_ADDED,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
28 SIG_REMOVED,
41891
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
29 SIG_ACCOUNT_CHANGED,
41946
0fb3b0e7122f Add a setting-changed signal to PurpleAccount and propagate it from PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41934
diff changeset
30 SIG_ACCOUNT_SETTING_CHANGED,
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
31 N_SIGNALS,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
32 };
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
33 static guint signals[N_SIGNALS] = {0, };
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
34
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
35 struct _PurpleAccountManager {
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
36 GObject parent;
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
37
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
38 GPtrArray *accounts;
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
39 };
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
40
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
41 static PurpleAccountManager *default_manager = NULL;
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
42
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
43 /******************************************************************************
41891
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
44 * Callbacks
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
45 *****************************************************************************/
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
46 /* This is the callback for the notify signal on accounts. It re-emits the
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
47 * signal as coming from the manager and passes the account as a parameter to
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
48 * the callback. It supports details as well so you can use
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
49 * g_signal_connect(manager, "account-changed::enabled", ...) to just get
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
50 * called when an account's enabled property changes.
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
51 */
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
52 static void
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
53 purple_account_manager_account_notify_cb(GObject *source, GParamSpec *pspec,
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
54 gpointer data)
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
55 {
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
56 g_signal_emit(data, signals[SIG_ACCOUNT_CHANGED],
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
57 g_param_spec_get_name_quark(pspec),
41946
0fb3b0e7122f Add a setting-changed signal to PurpleAccount and propagate it from PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41934
diff changeset
58 source, pspec);
0fb3b0e7122f Add a setting-changed signal to PurpleAccount and propagate it from PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41934
diff changeset
59 }
0fb3b0e7122f Add a setting-changed signal to PurpleAccount and propagate it from PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41934
diff changeset
60
0fb3b0e7122f Add a setting-changed signal to PurpleAccount and propagate it from PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41934
diff changeset
61 static void
0fb3b0e7122f Add a setting-changed signal to PurpleAccount and propagate it from PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41934
diff changeset
62 purple_account_manager_account_setting_changed_cb(PurpleAccount *account,
0fb3b0e7122f Add a setting-changed signal to PurpleAccount and propagate it from PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41934
diff changeset
63 const char *name,
0fb3b0e7122f Add a setting-changed signal to PurpleAccount and propagate it from PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41934
diff changeset
64 gpointer data)
0fb3b0e7122f Add a setting-changed signal to PurpleAccount and propagate it from PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41934
diff changeset
65 {
0fb3b0e7122f Add a setting-changed signal to PurpleAccount and propagate it from PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41934
diff changeset
66 g_signal_emit(data, signals[SIG_ACCOUNT_SETTING_CHANGED],
0fb3b0e7122f Add a setting-changed signal to PurpleAccount and propagate it from PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41934
diff changeset
67 g_quark_from_string(name), account, name);
41891
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
68 }
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
69
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
70 /******************************************************************************
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
71 * GListModel Implementation
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
72 *****************************************************************************/
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
73 static GType
41934
2bf330d7a6db A few tweaks to PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41891
diff changeset
74 purple_account_manager_get_item_type(G_GNUC_UNUSED GListModel *list) {
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
75 return PURPLE_TYPE_ACCOUNT;
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
76 }
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
77
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
78 static guint
41934
2bf330d7a6db A few tweaks to PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41891
diff changeset
79 purple_account_manager_get_n_items(GListModel *list) {
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
80 PurpleAccountManager *manager = PURPLE_ACCOUNT_MANAGER(list);
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
81
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
82 return manager->accounts->len;
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
83 }
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
84
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
85 static gpointer
41934
2bf330d7a6db A few tweaks to PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41891
diff changeset
86 purple_account_manager_get_item(GListModel *list, guint position) {
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
87 PurpleAccountManager *manager = PURPLE_ACCOUNT_MANAGER(list);
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
88 PurpleAccount *account = NULL;
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
89
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
90 if(position < manager->accounts->len) {
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
91 account = g_ptr_array_index(manager->accounts, position);
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
92 g_object_ref(account);
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
93 }
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
94
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
95 return account;
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
96 }
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
97
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
98 static void
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
99 purple_account_manager_list_model_init(GListModelInterface *iface) {
41934
2bf330d7a6db A few tweaks to PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41891
diff changeset
100 iface->get_item_type = purple_account_manager_get_item_type;
2bf330d7a6db A few tweaks to PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41891
diff changeset
101 iface->get_n_items = purple_account_manager_get_n_items;
2bf330d7a6db A few tweaks to PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41891
diff changeset
102 iface->get_item = purple_account_manager_get_item;
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
103 }
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
104
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
105 /******************************************************************************
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
106 * GObject Implementation
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
107 *****************************************************************************/
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
108 G_DEFINE_TYPE_EXTENDED(PurpleAccountManager, purple_account_manager,
41934
2bf330d7a6db A few tweaks to PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41891
diff changeset
109 G_TYPE_OBJECT, G_TYPE_FLAG_FINAL,
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
110 G_IMPLEMENT_INTERFACE(G_TYPE_LIST_MODEL,
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
111 purple_account_manager_list_model_init))
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
112
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
113 static void
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
114 purple_account_manager_finalize(GObject *obj) {
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
115 PurpleAccountManager *manager = PURPLE_ACCOUNT_MANAGER(obj);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
116
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
117 if(manager->accounts != NULL) {
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
118 g_ptr_array_free(manager->accounts, TRUE);
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
119 }
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
120
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
121 G_OBJECT_CLASS(purple_account_manager_parent_class)->finalize(obj);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
122 }
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
123
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
124 static void
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
125 purple_account_manager_init(PurpleAccountManager *manager) {
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
126 manager->accounts = g_ptr_array_new_full(0, (GDestroyNotify)g_object_unref);
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
127 }
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
128
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
129 static void
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
130 purple_account_manager_class_init(PurpleAccountManagerClass *klass) {
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
131 GObjectClass *obj_class = G_OBJECT_CLASS(klass);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
132
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
133 obj_class->finalize = purple_account_manager_finalize;
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
134
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
135 /**
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
136 * PurpleAccountManager::added:
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
137 * @manager: The account manager instance.
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
138 * @account: The account that was added.
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
139 *
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
140 * Emitted after @account was added to @manager.
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
141 *
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
142 * Since: 3.0.0
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
143 */
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
144 signals[SIG_ADDED] = g_signal_new_class_handler(
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
145 "added",
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
146 G_OBJECT_CLASS_TYPE(klass),
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
147 G_SIGNAL_RUN_LAST,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
148 NULL,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
149 NULL,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
150 NULL,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
151 NULL,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
152 G_TYPE_NONE,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
153 1,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
154 PURPLE_TYPE_ACCOUNT);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
155
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
156 /**
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
157 * PurpleAccountManager::removed:
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
158 * @manager: The account manager instance.
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
159 * @account: The account that was removed.
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
160 *
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
161 * Emitted after @account was removed from @manager.
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
162 *
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
163 * Since: 3.0.0
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
164 */
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
165 signals[SIG_REMOVED] = g_signal_new_class_handler(
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
166 "removed",
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
167 G_OBJECT_CLASS_TYPE(klass),
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
168 G_SIGNAL_RUN_LAST,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
169 NULL,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
170 NULL,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
171 NULL,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
172 NULL,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
173 G_TYPE_NONE,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
174 1,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
175 PURPLE_TYPE_ACCOUNT);
41891
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
176
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
177 /**
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
178 * PurpleAccountManager::account-changed:
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
179 * @manager: The account manager instance.
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
180 * @account: The account that was changed.
41946
0fb3b0e7122f Add a setting-changed signal to PurpleAccount and propagate it from PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41934
diff changeset
181 * @pspec: The [class@GObject.ParamSpec] for the property that changed.
41891
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
182 *
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
183 * This is a propagation of the notify signal from @account. This means
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
184 * that your callback will be called for any account that @manager knows
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
185 * about.
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
186 *
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
187 * This also supports details, so you can specify the signal name as
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
188 * something like `account-changed::enabled` and your callback will only
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
189 * be called when the enabled property of @account has been changed.
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
190 *
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
191 * Since: 3.0.0
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
192 */
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
193 signals[SIG_ACCOUNT_CHANGED] = g_signal_new_class_handler(
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
194 "account-changed",
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
195 G_OBJECT_CLASS_TYPE(klass),
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
196 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
197 NULL,
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
198 NULL,
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
199 NULL,
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
200 NULL,
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
201 G_TYPE_NONE,
41946
0fb3b0e7122f Add a setting-changed signal to PurpleAccount and propagate it from PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41934
diff changeset
202 2,
0fb3b0e7122f Add a setting-changed signal to PurpleAccount and propagate it from PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41934
diff changeset
203 PURPLE_TYPE_ACCOUNT,
0fb3b0e7122f Add a setting-changed signal to PurpleAccount and propagate it from PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41934
diff changeset
204 G_TYPE_PARAM);
0fb3b0e7122f Add a setting-changed signal to PurpleAccount and propagate it from PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41934
diff changeset
205
0fb3b0e7122f Add a setting-changed signal to PurpleAccount and propagate it from PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41934
diff changeset
206 /**
0fb3b0e7122f Add a setting-changed signal to PurpleAccount and propagate it from PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41934
diff changeset
207 * PurpleAccountManager::account-setting-changed:
0fb3b0e7122f Add a setting-changed signal to PurpleAccount and propagate it from PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41934
diff changeset
208 * @manager: The account manager instance.
0fb3b0e7122f Add a setting-changed signal to PurpleAccount and propagate it from PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41934
diff changeset
209 * @account: The account that was changed.
0fb3b0e7122f Add a setting-changed signal to PurpleAccount and propagate it from PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41934
diff changeset
210 * @name: The name of the setting that was changed.
0fb3b0e7122f Add a setting-changed signal to PurpleAccount and propagate it from PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41934
diff changeset
211 *
0fb3b0e7122f Add a setting-changed signal to PurpleAccount and propagate it from PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41934
diff changeset
212 * This is a propagation of [signal@Purple.Account::setting-changed]
0fb3b0e7122f Add a setting-changed signal to PurpleAccount and propagate it from PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41934
diff changeset
213 * signal. This means that your callback will be called for any account
0fb3b0e7122f Add a setting-changed signal to PurpleAccount and propagate it from PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41934
diff changeset
214 * that @manager knows about.
0fb3b0e7122f Add a setting-changed signal to PurpleAccount and propagate it from PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41934
diff changeset
215 *
0fb3b0e7122f Add a setting-changed signal to PurpleAccount and propagate it from PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41934
diff changeset
216 * This also supports details, so you can specify the signal name as
0fb3b0e7122f Add a setting-changed signal to PurpleAccount and propagate it from PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41934
diff changeset
217 * something like `account-setting-changed::use-tls` and your callback will
0fb3b0e7122f Add a setting-changed signal to PurpleAccount and propagate it from PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41934
diff changeset
218 * only be called when the `use-tls` setting of @account has been changed.
0fb3b0e7122f Add a setting-changed signal to PurpleAccount and propagate it from PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41934
diff changeset
219 *
0fb3b0e7122f Add a setting-changed signal to PurpleAccount and propagate it from PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41934
diff changeset
220 * Since: 3.0.0
0fb3b0e7122f Add a setting-changed signal to PurpleAccount and propagate it from PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41934
diff changeset
221 */
0fb3b0e7122f Add a setting-changed signal to PurpleAccount and propagate it from PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41934
diff changeset
222 signals[SIG_ACCOUNT_SETTING_CHANGED] = g_signal_new_class_handler(
0fb3b0e7122f Add a setting-changed signal to PurpleAccount and propagate it from PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41934
diff changeset
223 "account-setting-changed",
0fb3b0e7122f Add a setting-changed signal to PurpleAccount and propagate it from PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41934
diff changeset
224 G_OBJECT_CLASS_TYPE(klass),
0fb3b0e7122f Add a setting-changed signal to PurpleAccount and propagate it from PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41934
diff changeset
225 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
0fb3b0e7122f Add a setting-changed signal to PurpleAccount and propagate it from PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41934
diff changeset
226 NULL,
0fb3b0e7122f Add a setting-changed signal to PurpleAccount and propagate it from PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41934
diff changeset
227 NULL,
0fb3b0e7122f Add a setting-changed signal to PurpleAccount and propagate it from PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41934
diff changeset
228 NULL,
0fb3b0e7122f Add a setting-changed signal to PurpleAccount and propagate it from PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41934
diff changeset
229 NULL,
0fb3b0e7122f Add a setting-changed signal to PurpleAccount and propagate it from PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41934
diff changeset
230 G_TYPE_NONE,
0fb3b0e7122f Add a setting-changed signal to PurpleAccount and propagate it from PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41934
diff changeset
231 2,
0fb3b0e7122f Add a setting-changed signal to PurpleAccount and propagate it from PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41934
diff changeset
232 PURPLE_TYPE_ACCOUNT,
0fb3b0e7122f Add a setting-changed signal to PurpleAccount and propagate it from PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41934
diff changeset
233 G_TYPE_STRING);
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
234 }
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
235
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
236 /******************************************************************************
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
237 * Private API
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
238 *****************************************************************************/
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
239 void
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
240 purple_account_manager_startup(void) {
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
241 if(!PURPLE_IS_ACCOUNT_MANAGER(default_manager)) {
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
242 default_manager = g_object_new(PURPLE_TYPE_ACCOUNT_MANAGER, NULL);
41934
2bf330d7a6db A few tweaks to PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41891
diff changeset
243 g_object_add_weak_pointer(G_OBJECT(default_manager),
2bf330d7a6db A few tweaks to PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41891
diff changeset
244 (gpointer *)&default_manager);
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
245 }
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
246 }
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
247
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
248 void
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
249 purple_account_manager_shutdown(void) {
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
250 g_clear_object(&default_manager);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
251 }
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
252
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
253 /******************************************************************************
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
254 * Public API
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
255 *****************************************************************************/
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
256 PurpleAccountManager *
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
257 purple_account_manager_get_default(void) {
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
258 return default_manager;
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
259 }
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
260
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
261 GListModel *
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
262 purple_account_manager_get_default_as_model(void) {
41934
2bf330d7a6db A few tweaks to PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41891
diff changeset
263 if(PURPLE_IS_ACCOUNT_MANAGER(default_manager)) {
2bf330d7a6db A few tweaks to PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41891
diff changeset
264 return G_LIST_MODEL(default_manager);
2bf330d7a6db A few tweaks to PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41891
diff changeset
265 }
2bf330d7a6db A few tweaks to PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41891
diff changeset
266
2bf330d7a6db A few tweaks to PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41891
diff changeset
267 return NULL;
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
268 }
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
269
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
270 void
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
271 purple_account_manager_add(PurpleAccountManager *manager,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
272 PurpleAccount *account)
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
273 {
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
274 g_return_if_fail(PURPLE_IS_ACCOUNT_MANAGER(manager));
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
275 g_return_if_fail(PURPLE_IS_ACCOUNT(account));
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
276
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
277 /* If the manager already knows about the account, we do nothing. */
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
278 if(g_ptr_array_find(manager->accounts, account, NULL)) {
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
279 return;
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
280 }
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
281
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
282 /* Since the manager doesn't know about the account, put the new account
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
283 * at the start of the list as that's likely to be the first one in user
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
284 * interfaces and the most likely to have configuration issues as it's a
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
285 * new account.
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
286 */
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
287 g_ptr_array_insert(manager->accounts, 0, account);
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
288
41891
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
289 /* Connect to the signals of the account that we want to propagate. */
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
290 g_signal_connect_object(account, "notify",
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
291 G_CALLBACK(purple_account_manager_account_notify_cb),
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
292 manager, 0);
41946
0fb3b0e7122f Add a setting-changed signal to PurpleAccount and propagate it from PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41934
diff changeset
293 g_signal_connect_object(account, "setting-changed",
0fb3b0e7122f Add a setting-changed signal to PurpleAccount and propagate it from PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41934
diff changeset
294 G_CALLBACK(purple_account_manager_account_setting_changed_cb),
0fb3b0e7122f Add a setting-changed signal to PurpleAccount and propagate it from PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41934
diff changeset
295 manager, 0);
41891
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
296
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
297 purple_accounts_schedule_save();
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
298
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
299 g_signal_emit(manager, signals[SIG_ADDED], 0, account);
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
300 g_list_model_items_changed(G_LIST_MODEL(manager), 0, 0, 1);
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
301 }
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
302
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
303 void
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
304 purple_account_manager_remove(PurpleAccountManager *manager,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
305 PurpleAccount *account)
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
306 {
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
307 guint index = 0;
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
308
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
309 g_return_if_fail(PURPLE_IS_ACCOUNT_MANAGER(manager));
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
310 g_return_if_fail(PURPLE_IS_ACCOUNT(account));
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
311
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
312 if(g_ptr_array_find(manager->accounts, account, &index)) {
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
313 g_ptr_array_steal_index(manager->accounts, index);
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
314 g_list_model_items_changed(G_LIST_MODEL(manager), index, 1, 0);
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
315 }
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
316
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
317 purple_accounts_schedule_save();
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
318
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
319 /* Clearing the error ensures that account-error-changed is emitted,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
320 * which is the end of the guarantee that the error's pointer is valid.
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
321 */
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
322 purple_account_clear_current_error(account);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
323
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
324 g_signal_emit(manager, signals[SIG_REMOVED], 0, account);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
325 }
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
326
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
327 GList *
41451
e587ef39e02e Update the account manager to use enabled/disabled for accounts rather than active/inactive.
Gary Kramlich <grim@reaperworld.com>
parents: 41392
diff changeset
328 purple_account_manager_get_enabled(PurpleAccountManager *manager) {
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
329 GList *enabled = NULL;
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
330
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
331 g_return_val_if_fail(PURPLE_IS_ACCOUNT_MANAGER(manager), NULL);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
332
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
333 for(guint index = 0; index < manager->accounts->len; index++) {
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
334 PurpleAccount *account = g_ptr_array_index(manager->accounts, index);
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
335
41392
b5c84f55d5d2 Remove the ui parameter from purple_account_[gs]et_enabled
Gary Kramlich <grim@reaperworld.com>
parents: 41315
diff changeset
336 if(purple_account_get_enabled(account)) {
41451
e587ef39e02e Update the account manager to use enabled/disabled for accounts rather than active/inactive.
Gary Kramlich <grim@reaperworld.com>
parents: 41392
diff changeset
337 enabled = g_list_append(enabled, account);
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
338 }
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
339 }
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
340
41451
e587ef39e02e Update the account manager to use enabled/disabled for accounts rather than active/inactive.
Gary Kramlich <grim@reaperworld.com>
parents: 41392
diff changeset
341 return enabled;
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
342 }
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
343
41315
1c9f47bbc031 Replace PidginAccountsDisabledMenu with PidginInactiveAccountsMenu which is a GMenuModel subclass.
Gary Kramlich <grim@reaperworld.com>
parents: 41298
diff changeset
344 GList *
41451
e587ef39e02e Update the account manager to use enabled/disabled for accounts rather than active/inactive.
Gary Kramlich <grim@reaperworld.com>
parents: 41392
diff changeset
345 purple_account_manager_get_disabled(PurpleAccountManager *manager) {
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
346 GList *disabled = NULL;
41315
1c9f47bbc031 Replace PidginAccountsDisabledMenu with PidginInactiveAccountsMenu which is a GMenuModel subclass.
Gary Kramlich <grim@reaperworld.com>
parents: 41298
diff changeset
347
1c9f47bbc031 Replace PidginAccountsDisabledMenu with PidginInactiveAccountsMenu which is a GMenuModel subclass.
Gary Kramlich <grim@reaperworld.com>
parents: 41298
diff changeset
348 g_return_val_if_fail(PURPLE_IS_ACCOUNT_MANAGER(manager), NULL);
1c9f47bbc031 Replace PidginAccountsDisabledMenu with PidginInactiveAccountsMenu which is a GMenuModel subclass.
Gary Kramlich <grim@reaperworld.com>
parents: 41298
diff changeset
349
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
350 for(guint index = 0; index < manager->accounts->len; index++) {
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
351 PurpleAccount *account = g_ptr_array_index(manager->accounts, index);
41315
1c9f47bbc031 Replace PidginAccountsDisabledMenu with PidginInactiveAccountsMenu which is a GMenuModel subclass.
Gary Kramlich <grim@reaperworld.com>
parents: 41298
diff changeset
352
41392
b5c84f55d5d2 Remove the ui parameter from purple_account_[gs]et_enabled
Gary Kramlich <grim@reaperworld.com>
parents: 41315
diff changeset
353 if(!purple_account_get_enabled(account)) {
41451
e587ef39e02e Update the account manager to use enabled/disabled for accounts rather than active/inactive.
Gary Kramlich <grim@reaperworld.com>
parents: 41392
diff changeset
354 disabled = g_list_append(disabled, account);
41315
1c9f47bbc031 Replace PidginAccountsDisabledMenu with PidginInactiveAccountsMenu which is a GMenuModel subclass.
Gary Kramlich <grim@reaperworld.com>
parents: 41298
diff changeset
355 }
1c9f47bbc031 Replace PidginAccountsDisabledMenu with PidginInactiveAccountsMenu which is a GMenuModel subclass.
Gary Kramlich <grim@reaperworld.com>
parents: 41298
diff changeset
356 }
1c9f47bbc031 Replace PidginAccountsDisabledMenu with PidginInactiveAccountsMenu which is a GMenuModel subclass.
Gary Kramlich <grim@reaperworld.com>
parents: 41298
diff changeset
357
41451
e587ef39e02e Update the account manager to use enabled/disabled for accounts rather than active/inactive.
Gary Kramlich <grim@reaperworld.com>
parents: 41392
diff changeset
358 return disabled;
41315
1c9f47bbc031 Replace PidginAccountsDisabledMenu with PidginInactiveAccountsMenu which is a GMenuModel subclass.
Gary Kramlich <grim@reaperworld.com>
parents: 41298
diff changeset
359 }
1c9f47bbc031 Replace PidginAccountsDisabledMenu with PidginInactiveAccountsMenu which is a GMenuModel subclass.
Gary Kramlich <grim@reaperworld.com>
parents: 41298
diff changeset
360
41890
2c15f6e30f20 Add purple_account_manager_get_connected and port libpurple to it
Gary Kramlich <grim@reaperworld.com>
parents: 41851
diff changeset
361 GList *
2c15f6e30f20 Add purple_account_manager_get_connected and port libpurple to it
Gary Kramlich <grim@reaperworld.com>
parents: 41851
diff changeset
362 purple_account_manager_get_connected(PurpleAccountManager *manager) {
2c15f6e30f20 Add purple_account_manager_get_connected and port libpurple to it
Gary Kramlich <grim@reaperworld.com>
parents: 41851
diff changeset
363 GList *connected = NULL;
2c15f6e30f20 Add purple_account_manager_get_connected and port libpurple to it
Gary Kramlich <grim@reaperworld.com>
parents: 41851
diff changeset
364
2c15f6e30f20 Add purple_account_manager_get_connected and port libpurple to it
Gary Kramlich <grim@reaperworld.com>
parents: 41851
diff changeset
365 g_return_val_if_fail(PURPLE_IS_ACCOUNT_MANAGER(manager), NULL);
2c15f6e30f20 Add purple_account_manager_get_connected and port libpurple to it
Gary Kramlich <grim@reaperworld.com>
parents: 41851
diff changeset
366
2c15f6e30f20 Add purple_account_manager_get_connected and port libpurple to it
Gary Kramlich <grim@reaperworld.com>
parents: 41851
diff changeset
367 for(guint index = 0; index < manager->accounts->len; index++) {
2c15f6e30f20 Add purple_account_manager_get_connected and port libpurple to it
Gary Kramlich <grim@reaperworld.com>
parents: 41851
diff changeset
368 PurpleAccount *account = g_ptr_array_index(manager->accounts, index);
2c15f6e30f20 Add purple_account_manager_get_connected and port libpurple to it
Gary Kramlich <grim@reaperworld.com>
parents: 41851
diff changeset
369 PurpleConnection *connection = NULL;
2c15f6e30f20 Add purple_account_manager_get_connected and port libpurple to it
Gary Kramlich <grim@reaperworld.com>
parents: 41851
diff changeset
370
2c15f6e30f20 Add purple_account_manager_get_connected and port libpurple to it
Gary Kramlich <grim@reaperworld.com>
parents: 41851
diff changeset
371 connection = purple_account_get_connection(account);
2c15f6e30f20 Add purple_account_manager_get_connected and port libpurple to it
Gary Kramlich <grim@reaperworld.com>
parents: 41851
diff changeset
372 if(PURPLE_IS_CONNECTION(connection) &&
2c15f6e30f20 Add purple_account_manager_get_connected and port libpurple to it
Gary Kramlich <grim@reaperworld.com>
parents: 41851
diff changeset
373 PURPLE_CONNECTION_IS_CONNECTED(connection))
2c15f6e30f20 Add purple_account_manager_get_connected and port libpurple to it
Gary Kramlich <grim@reaperworld.com>
parents: 41851
diff changeset
374 {
2c15f6e30f20 Add purple_account_manager_get_connected and port libpurple to it
Gary Kramlich <grim@reaperworld.com>
parents: 41851
diff changeset
375 connected = g_list_append(connected, account);
2c15f6e30f20 Add purple_account_manager_get_connected and port libpurple to it
Gary Kramlich <grim@reaperworld.com>
parents: 41851
diff changeset
376 }
2c15f6e30f20 Add purple_account_manager_get_connected and port libpurple to it
Gary Kramlich <grim@reaperworld.com>
parents: 41851
diff changeset
377 }
2c15f6e30f20 Add purple_account_manager_get_connected and port libpurple to it
Gary Kramlich <grim@reaperworld.com>
parents: 41851
diff changeset
378
2c15f6e30f20 Add purple_account_manager_get_connected and port libpurple to it
Gary Kramlich <grim@reaperworld.com>
parents: 41851
diff changeset
379 return connected;
2c15f6e30f20 Add purple_account_manager_get_connected and port libpurple to it
Gary Kramlich <grim@reaperworld.com>
parents: 41851
diff changeset
380 }
2c15f6e30f20 Add purple_account_manager_get_connected and port libpurple to it
Gary Kramlich <grim@reaperworld.com>
parents: 41851
diff changeset
381
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
382 void
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
383 purple_account_manager_reorder(PurpleAccountManager *manager,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
384 PurpleAccount *account,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
385 guint new_index)
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
386 {
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
387 guint index = 0;
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
388
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
389 g_return_if_fail(PURPLE_IS_ACCOUNT_MANAGER(manager));
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
390 g_return_if_fail(PURPLE_IS_ACCOUNT(account));
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
391
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
392 if(g_ptr_array_find(manager->accounts, account, &index)) {
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
393 g_ptr_array_steal_index(manager->accounts, index);
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
394 g_list_model_items_changed(G_LIST_MODEL(manager), index, 1, 0);
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
395
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
396 /* If new_index is greater than the current index, we need to
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
397 * decrement new_index by 1 to account for the move as we'll be
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
398 * inserting into a list with one less item.
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
399 */
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
400 if(new_index > index) {
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
401 new_index--;
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
402 }
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
403 } else {
41976
49969fa9a664 Update libpurple for the deprecations in the account api
Gary Kramlich <grim@reaperworld.com>
parents: 41946
diff changeset
404 PurpleContactInfo *info = PURPLE_CONTACT_INFO(account);
49969fa9a664 Update libpurple for the deprecations in the account api
Gary Kramlich <grim@reaperworld.com>
parents: 41946
diff changeset
405
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
406 g_critical("Unregistered account (%s) found during reorder!",
41976
49969fa9a664 Update libpurple for the deprecations in the account api
Gary Kramlich <grim@reaperworld.com>
parents: 41946
diff changeset
407 purple_contact_info_get_username(info));
49969fa9a664 Update libpurple for the deprecations in the account api
Gary Kramlich <grim@reaperworld.com>
parents: 41946
diff changeset
408
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
409 return;
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
410 }
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
411
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
412 /* Insert the account into its new position. */
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
413 g_ptr_array_insert(manager->accounts, new_index, account);
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
414 g_list_model_items_changed(G_LIST_MODEL(manager), new_index, 0, 1);
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
415
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
416 purple_accounts_schedule_save();
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
417 }
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
418
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
419 PurpleAccount *
41298
6d816e02fd76 Create a menu controller that will keep a GMenu in sync with the disabled accounts in libpurple
Gary Kramlich <grim@reaperworld.com>
parents: 41181
diff changeset
420 purple_account_manager_find_by_id(PurpleAccountManager *manager,
6d816e02fd76 Create a menu controller that will keep a GMenu in sync with the disabled accounts in libpurple
Gary Kramlich <grim@reaperworld.com>
parents: 41181
diff changeset
421 const gchar *id)
6d816e02fd76 Create a menu controller that will keep a GMenu in sync with the disabled accounts in libpurple
Gary Kramlich <grim@reaperworld.com>
parents: 41181
diff changeset
422 {
6d816e02fd76 Create a menu controller that will keep a GMenu in sync with the disabled accounts in libpurple
Gary Kramlich <grim@reaperworld.com>
parents: 41181
diff changeset
423 g_return_val_if_fail(PURPLE_IS_ACCOUNT_MANAGER(manager), NULL);
6d816e02fd76 Create a menu controller that will keep a GMenu in sync with the disabled accounts in libpurple
Gary Kramlich <grim@reaperworld.com>
parents: 41181
diff changeset
424 g_return_val_if_fail(id != NULL, NULL);
6d816e02fd76 Create a menu controller that will keep a GMenu in sync with the disabled accounts in libpurple
Gary Kramlich <grim@reaperworld.com>
parents: 41181
diff changeset
425
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
426 for(guint index = 0; index < manager->accounts->len; index++) {
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
427 PurpleAccount *account = g_ptr_array_index(manager->accounts, index);
41976
49969fa9a664 Update libpurple for the deprecations in the account api
Gary Kramlich <grim@reaperworld.com>
parents: 41946
diff changeset
428 PurpleContactInfo *info = PURPLE_CONTACT_INFO(account);
41298
6d816e02fd76 Create a menu controller that will keep a GMenu in sync with the disabled accounts in libpurple
Gary Kramlich <grim@reaperworld.com>
parents: 41181
diff changeset
429
41976
49969fa9a664 Update libpurple for the deprecations in the account api
Gary Kramlich <grim@reaperworld.com>
parents: 41946
diff changeset
430 if(purple_strequal(purple_contact_info_get_id(info), id)) {
41298
6d816e02fd76 Create a menu controller that will keep a GMenu in sync with the disabled accounts in libpurple
Gary Kramlich <grim@reaperworld.com>
parents: 41181
diff changeset
431 return account;
6d816e02fd76 Create a menu controller that will keep a GMenu in sync with the disabled accounts in libpurple
Gary Kramlich <grim@reaperworld.com>
parents: 41181
diff changeset
432 }
6d816e02fd76 Create a menu controller that will keep a GMenu in sync with the disabled accounts in libpurple
Gary Kramlich <grim@reaperworld.com>
parents: 41181
diff changeset
433 }
6d816e02fd76 Create a menu controller that will keep a GMenu in sync with the disabled accounts in libpurple
Gary Kramlich <grim@reaperworld.com>
parents: 41181
diff changeset
434
6d816e02fd76 Create a menu controller that will keep a GMenu in sync with the disabled accounts in libpurple
Gary Kramlich <grim@reaperworld.com>
parents: 41181
diff changeset
435 return NULL;
6d816e02fd76 Create a menu controller that will keep a GMenu in sync with the disabled accounts in libpurple
Gary Kramlich <grim@reaperworld.com>
parents: 41181
diff changeset
436 }
6d816e02fd76 Create a menu controller that will keep a GMenu in sync with the disabled accounts in libpurple
Gary Kramlich <grim@reaperworld.com>
parents: 41181
diff changeset
437
6d816e02fd76 Create a menu controller that will keep a GMenu in sync with the disabled accounts in libpurple
Gary Kramlich <grim@reaperworld.com>
parents: 41181
diff changeset
438 PurpleAccount *
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
439 purple_account_manager_find(PurpleAccountManager *manager,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
440 const gchar *username, const gchar *protocol_id)
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
441 {
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
442 g_return_val_if_fail(PURPLE_IS_ACCOUNT_MANAGER(manager), NULL);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
443 g_return_val_if_fail(username != NULL, NULL);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
444 g_return_val_if_fail(protocol_id != NULL, NULL);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
445
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
446 for(guint index = 0; index < manager->accounts->len; index++) {
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
447 PurpleAccount *account = g_ptr_array_index(manager->accounts, index);
41976
49969fa9a664 Update libpurple for the deprecations in the account api
Gary Kramlich <grim@reaperworld.com>
parents: 41946
diff changeset
448 PurpleContactInfo *info = PURPLE_CONTACT_INFO(account);
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
449 gchar *normalized = NULL;
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
450 const gchar *existing_protocol_id = NULL;
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
451 const gchar *existing_username = NULL;
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
452 const gchar *existing_normalized = NULL;
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
453
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
454 /* Check if the protocol id matches what the user asked for. */
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
455 existing_protocol_id = purple_account_get_protocol_id(account);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
456 if(!purple_strequal(existing_protocol_id, protocol_id)) {
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
457 continue;
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
458 }
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
459
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
460 /* Finally verify the username. */
41976
49969fa9a664 Update libpurple for the deprecations in the account api
Gary Kramlich <grim@reaperworld.com>
parents: 41946
diff changeset
461 existing_username = purple_contact_info_get_username(info);
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
462 normalized = g_strdup(purple_normalize(account, username));
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
463 existing_normalized = purple_normalize(account, existing_username);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
464
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
465 if(purple_strequal(existing_normalized, normalized)) {
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
466 g_free(normalized);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
467
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
468 return account;
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
469 }
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
470 g_free(normalized);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
471 }
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
472
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
473 return NULL;
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
474 }
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
475
41641
ff6dff2228e1 Add a custom find to account manager
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41456
diff changeset
476 PurpleAccount *
ff6dff2228e1 Add a custom find to account manager
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41456
diff changeset
477 purple_account_manager_find_custom(PurpleAccountManager *manager,
ff6dff2228e1 Add a custom find to account manager
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41456
diff changeset
478 GEqualFunc func, gconstpointer data)
ff6dff2228e1 Add a custom find to account manager
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41456
diff changeset
479 {
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
480 guint index = 0;
41641
ff6dff2228e1 Add a custom find to account manager
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41456
diff changeset
481
ff6dff2228e1 Add a custom find to account manager
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41456
diff changeset
482 g_return_val_if_fail(PURPLE_IS_ACCOUNT_MANAGER(manager), NULL);
ff6dff2228e1 Add a custom find to account manager
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41456
diff changeset
483 g_return_val_if_fail(func != NULL, NULL);
ff6dff2228e1 Add a custom find to account manager
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41456
diff changeset
484
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
485 if(g_ptr_array_find_with_equal_func(manager->accounts, data, func, &index)) {
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
486 PurpleAccount *account = g_ptr_array_index(manager->accounts, index);
41641
ff6dff2228e1 Add a custom find to account manager
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41456
diff changeset
487
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
488 return account;
41641
ff6dff2228e1 Add a custom find to account manager
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41456
diff changeset
489 }
ff6dff2228e1 Add a custom find to account manager
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41456
diff changeset
490
ff6dff2228e1 Add a custom find to account manager
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41456
diff changeset
491 return NULL;
ff6dff2228e1 Add a custom find to account manager
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41456
diff changeset
492 }
ff6dff2228e1 Add a custom find to account manager
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41456
diff changeset
493
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
494 void
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
495 purple_account_manager_foreach(PurpleAccountManager *manager,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
496 PurpleAccountManagerForeachFunc callback,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
497 gpointer data)
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
498 {
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
499 g_return_if_fail(PURPLE_IS_ACCOUNT_MANAGER(manager));
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
500 g_return_if_fail(callback != NULL);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
501
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
502 for(guint index = 0; index < manager->accounts->len; index++) {
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
503 PurpleAccount *account = g_ptr_array_index(manager->accounts, index);
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
504 callback(account, data);
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
505 }
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
506 }

mercurial