libpurple/purpleaccountmanager.c

Fri, 20 Oct 2023 01:09:45 -0500

author
Gary Kramlich <grim@reaperworld.com>
date
Fri, 20 Oct 2023 01:09:45 -0500
changeset 42375
8e61249e9b10
parent 42344
c51d37734155
child 42576
ab1ca778ddb2
permissions
-rw-r--r--

Implement ProtocolFileTransfer

Testing Done:
Ran the unit tests under valgrind.

Bugs closed: PIDGIN-17833

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

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 "accounts.h"
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
23 #include "core.h"
42344
c51d37734155 Rename account.[ch] to purpleaccount.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 42291
diff changeset
24 #include "purpleaccount.h"
41181
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,
42234
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
31 SIG_ACCOUNT_CONNECTED,
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
32 SIG_ACCOUNT_DISCONNECTED,
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
33 N_SIGNALS,
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 static guint signals[N_SIGNALS] = {0, };
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
36
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
37 struct _PurpleAccountManager {
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
38 GObject parent;
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
39
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
40 GPtrArray *accounts;
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
41 };
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
42
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
43 static PurpleAccountManager *default_manager = NULL;
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
44
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
45 /******************************************************************************
41891
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
46 * Callbacks
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
47 *****************************************************************************/
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
48 /* 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
49 * 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
50 * 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
51 * 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
52 * 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
53 */
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
54 static void
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
55 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
56 gpointer data)
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
57 {
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
58 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
59 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
60 source, pspec);
0fb3b0e7122f Add a setting-changed signal to PurpleAccount and propagate it from PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41934
diff changeset
61 }
0fb3b0e7122f Add a setting-changed signal to PurpleAccount and propagate it from PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41934
diff changeset
62
0fb3b0e7122f Add a setting-changed signal to PurpleAccount and propagate it from PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41934
diff changeset
63 static void
0fb3b0e7122f Add a setting-changed signal to PurpleAccount and propagate it from PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41934
diff changeset
64 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
65 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
66 gpointer data)
0fb3b0e7122f Add a setting-changed signal to PurpleAccount and propagate it from PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41934
diff changeset
67 {
0fb3b0e7122f Add a setting-changed signal to PurpleAccount and propagate it from PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41934
diff changeset
68 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
69 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
70 }
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
71
42234
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
72 static void
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
73 purple_account_manager_account_connected_cb(PurpleAccount *account,
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
74 gpointer data)
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
75 {
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
76 g_signal_emit(data, signals[SIG_ACCOUNT_CONNECTED], 0, account);
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
77 }
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
78
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
79 static void
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
80 purple_account_manager_account_disconnected_cb(PurpleAccount *account,
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
81 gpointer data)
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
82 {
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
83 g_signal_emit(data, signals[SIG_ACCOUNT_DISCONNECTED], 0, account);
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
84 }
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
85
41891
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
86 /******************************************************************************
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
87 * GListModel Implementation
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
88 *****************************************************************************/
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
89 static GType
41934
2bf330d7a6db A few tweaks to PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41891
diff changeset
90 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
91 return PURPLE_TYPE_ACCOUNT;
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
92 }
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 static guint
41934
2bf330d7a6db A few tweaks to PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41891
diff changeset
95 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
96 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
97
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
98 return manager->accounts->len;
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
99 }
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
100
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
101 static gpointer
41934
2bf330d7a6db A few tweaks to PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41891
diff changeset
102 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
103 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
104 PurpleAccount *account = NULL;
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
105
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
106 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
107 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
108 g_object_ref(account);
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
109 }
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
110
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
111 return account;
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
112 }
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
113
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
114 static void
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
115 purple_account_manager_list_model_init(GListModelInterface *iface) {
41934
2bf330d7a6db A few tweaks to PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41891
diff changeset
116 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
117 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
118 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
119 }
41181
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 /******************************************************************************
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
122 * GObject Implementation
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
123 *****************************************************************************/
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
124 G_DEFINE_TYPE_EXTENDED(PurpleAccountManager, purple_account_manager,
41934
2bf330d7a6db A few tweaks to PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41891
diff changeset
125 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
126 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
127 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
128
41181
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_finalize(GObject *obj) {
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
131 PurpleAccountManager *manager = PURPLE_ACCOUNT_MANAGER(obj);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
132
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
133 if(manager->accounts != NULL) {
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
134 g_ptr_array_free(manager->accounts, TRUE);
41181
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
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
137 G_OBJECT_CLASS(purple_account_manager_parent_class)->finalize(obj);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
138 }
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 static void
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
141 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
142 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
143 }
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
144
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
145 static void
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
146 purple_account_manager_class_init(PurpleAccountManagerClass *klass) {
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
147 GObjectClass *obj_class = G_OBJECT_CLASS(klass);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
148
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
149 obj_class->finalize = purple_account_manager_finalize;
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
150
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
151 /**
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
152 * PurpleAccountManager::added:
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
153 * @manager: The account manager instance.
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
154 * @account: The account that was added.
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 * Emitted after @account was added to @manager.
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
157 *
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
158 * Since: 3.0.0
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
159 */
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
160 signals[SIG_ADDED] = g_signal_new_class_handler(
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
161 "added",
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
162 G_OBJECT_CLASS_TYPE(klass),
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
163 G_SIGNAL_RUN_LAST,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
164 NULL,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
165 NULL,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
166 NULL,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
167 NULL,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
168 G_TYPE_NONE,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
169 1,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
170 PURPLE_TYPE_ACCOUNT);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
171
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
172 /**
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
173 * PurpleAccountManager::removed:
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
174 * @manager: The account manager instance.
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
175 * @account: The account that was removed.
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
176 *
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
177 * Emitted after @account was removed from @manager.
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
178 *
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
179 * Since: 3.0.0
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
180 */
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
181 signals[SIG_REMOVED] = g_signal_new_class_handler(
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
182 "removed",
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
183 G_OBJECT_CLASS_TYPE(klass),
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
184 G_SIGNAL_RUN_LAST,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
185 NULL,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
186 NULL,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
187 NULL,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
188 NULL,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
189 G_TYPE_NONE,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
190 1,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
191 PURPLE_TYPE_ACCOUNT);
41891
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 /**
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
194 * PurpleAccountManager::account-changed:
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
195 * @manager: The account manager instance.
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
196 * @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
197 * @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
198 *
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
199 * 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
200 * 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
201 * about.
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
202 *
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
203 * 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
204 * 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
205 * 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
206 *
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
207 * Since: 3.0.0
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
208 */
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
209 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
210 "account-changed",
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
211 G_OBJECT_CLASS_TYPE(klass),
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
212 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
213 NULL,
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
214 NULL,
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
215 NULL,
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
216 NULL,
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
217 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
218 2,
0fb3b0e7122f Add a setting-changed signal to PurpleAccount and propagate it from PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41934
diff changeset
219 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
220 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
221
0fb3b0e7122f Add a setting-changed signal to PurpleAccount and propagate it from PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41934
diff changeset
222 /**
0fb3b0e7122f Add a setting-changed signal to PurpleAccount and propagate it from PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41934
diff changeset
223 * 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
224 * @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
225 * @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
226 * @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
227 *
0fb3b0e7122f Add a setting-changed signal to PurpleAccount and propagate it from PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41934
diff changeset
228 * 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
229 * 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
230 * 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
231 *
0fb3b0e7122f Add a setting-changed signal to PurpleAccount and propagate it from PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41934
diff changeset
232 * 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
233 * 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
234 * 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
235 *
0fb3b0e7122f Add a setting-changed signal to PurpleAccount and propagate it from PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41934
diff changeset
236 * 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
237 */
0fb3b0e7122f Add a setting-changed signal to PurpleAccount and propagate it from PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41934
diff changeset
238 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
239 "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
240 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
241 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
242 NULL,
0fb3b0e7122f Add a setting-changed signal to PurpleAccount and propagate it from PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41934
diff changeset
243 NULL,
0fb3b0e7122f Add a setting-changed signal to PurpleAccount and propagate it from PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41934
diff changeset
244 NULL,
0fb3b0e7122f Add a setting-changed signal to PurpleAccount and propagate it from PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41934
diff changeset
245 NULL,
0fb3b0e7122f Add a setting-changed signal to PurpleAccount and propagate it from PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41934
diff changeset
246 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
247 2,
0fb3b0e7122f Add a setting-changed signal to PurpleAccount and propagate it from PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41934
diff changeset
248 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
249 G_TYPE_STRING);
42234
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
250
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
251 /**
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
252 * PurpleAccountManager::account-connected:
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
253 * @manager: The account manager instance.
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
254 * @account: The account that was connected.
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
255 *
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
256 * This is a propagation of [signal@Purple.Account::connected] signal. This
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
257 * means that your callback will be called for any account that @manager
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
258 * knows about.
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
259 *
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
260 * Since: 3.0.0
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
261 */
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
262 signals[SIG_ACCOUNT_CONNECTED] = g_signal_new_class_handler(
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
263 "account-connected",
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
264 G_OBJECT_CLASS_TYPE(klass),
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
265 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
266 NULL,
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
267 NULL,
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
268 NULL,
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
269 NULL,
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
270 G_TYPE_NONE,
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
271 1,
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
272 PURPLE_TYPE_ACCOUNT);
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
273
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
274 /**
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
275 * PurpleAccountManager::account-disconnected:
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
276 * @manager: The account manager instance.
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
277 * @account: The account that was disconnected.
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
278 *
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
279 * This is a propagation of [signal@Purple.Account::disconnected] signal.
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
280 * This means that your callback will be called for any account that
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
281 * @manager knows about.
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
282 *
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
283 * Since: 3.0.0
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
284 */
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
285 signals[SIG_ACCOUNT_DISCONNECTED] = g_signal_new_class_handler(
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
286 "account-disconnected",
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
287 G_OBJECT_CLASS_TYPE(klass),
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
288 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
289 NULL,
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
290 NULL,
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
291 NULL,
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
292 NULL,
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
293 G_TYPE_NONE,
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
294 1,
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
295 PURPLE_TYPE_ACCOUNT);
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
296 }
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
297
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 * Private API
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
300 *****************************************************************************/
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
301 void
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
302 purple_account_manager_startup(void) {
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
303 if(!PURPLE_IS_ACCOUNT_MANAGER(default_manager)) {
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
304 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
305 g_object_add_weak_pointer(G_OBJECT(default_manager),
2bf330d7a6db A few tweaks to PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41891
diff changeset
306 (gpointer *)&default_manager);
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
307 }
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
308 }
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
309
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
310 void
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
311 purple_account_manager_shutdown(void) {
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
312 g_clear_object(&default_manager);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
313 }
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
314
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
315 /******************************************************************************
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
316 * Public API
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
317 *****************************************************************************/
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
318 PurpleAccountManager *
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
319 purple_account_manager_get_default(void) {
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
320 return default_manager;
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
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
323 GListModel *
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
324 purple_account_manager_get_default_as_model(void) {
41934
2bf330d7a6db A few tweaks to PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41891
diff changeset
325 if(PURPLE_IS_ACCOUNT_MANAGER(default_manager)) {
2bf330d7a6db A few tweaks to PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41891
diff changeset
326 return G_LIST_MODEL(default_manager);
2bf330d7a6db A few tweaks to PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41891
diff changeset
327 }
2bf330d7a6db A few tweaks to PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41891
diff changeset
328
2bf330d7a6db A few tweaks to PurpleAccountManager
Gary Kramlich <grim@reaperworld.com>
parents: 41891
diff changeset
329 return NULL;
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
330 }
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
331
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
332 void
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
333 purple_account_manager_add(PurpleAccountManager *manager,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
334 PurpleAccount *account)
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
335 {
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
336 g_return_if_fail(PURPLE_IS_ACCOUNT_MANAGER(manager));
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
337 g_return_if_fail(PURPLE_IS_ACCOUNT(account));
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 /* 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
340 if(g_ptr_array_find(manager->accounts, account, NULL)) {
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
341 return;
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
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
344 /* 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
345 * 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
346 * 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
347 * new account.
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
348 */
42234
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
349 g_ptr_array_insert(manager->accounts, 0, g_object_ref(account));
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
350
41891
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
351 /* 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
352 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
353 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
354 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
355 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
356 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
357 manager, 0);
42234
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
358 g_signal_connect_object(account, "connected",
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
359 G_CALLBACK(purple_account_manager_account_connected_cb),
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
360 manager, 0);
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
361 g_signal_connect_object(account, "disconnected",
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
362 G_CALLBACK(purple_account_manager_account_disconnected_cb),
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
363 manager, 0);
41891
a45d6db4f857 Propagate the PurpleAccount::notify signal via PurpleAccountManager::account-changed
Gary Kramlich <grim@reaperworld.com>
parents: 41890
diff changeset
364
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
365 purple_accounts_schedule_save();
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
366
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
367 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
368 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
369 }
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
370
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
371 void
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
372 purple_account_manager_remove(PurpleAccountManager *manager,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
373 PurpleAccount *account)
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
374 {
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
375 guint index = 0;
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
376
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
377 g_return_if_fail(PURPLE_IS_ACCOUNT_MANAGER(manager));
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
378 g_return_if_fail(PURPLE_IS_ACCOUNT(account));
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
379
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
380 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
381 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
382 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
383 }
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
384
42234
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
385 /* Disconnect all the signals we added for the account. */
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
386 g_signal_handlers_disconnect_by_func(account,
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
387 purple_account_manager_account_notify_cb,
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
388 manager);
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
389 g_signal_handlers_disconnect_by_func(account,
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
390 purple_account_manager_account_setting_changed_cb,
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
391 manager);
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
392 g_signal_handlers_disconnect_by_func(account,
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
393 purple_account_manager_account_connected_cb,
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
394 manager);
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
395 g_signal_handlers_disconnect_by_func(account,
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
396 purple_account_manager_account_disconnected_cb,
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
397 manager);
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
398
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
399 /* Save the list. */
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
400 purple_accounts_schedule_save();
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
401
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
402 /* Clearing the error ensures that account-error-changed is emitted,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
403 * 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
404 */
42049
16d2e16bd24f Export Account::error
Gary Kramlich <grim@reaperworld.com>
parents: 41976
diff changeset
405 purple_account_set_error(account, NULL);
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
406
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
407 g_signal_emit(manager, signals[SIG_REMOVED], 0, account);
42234
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
408
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
409 /* Since we stole the index from the GPtrArray, we need to unref it
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
410 * ourselves.
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
411 */
95aec1611d01 A few account manager changes
Gary Kramlich <grim@reaperworld.com>
parents: 42049
diff changeset
412 g_object_unref(account);
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
413 }
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
414
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
415 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
416 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
417 GList *enabled = NULL;
41181
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 g_return_val_if_fail(PURPLE_IS_ACCOUNT_MANAGER(manager), NULL);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
420
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
421 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
422 PurpleAccount *account = g_ptr_array_index(manager->accounts, index);
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
423
41392
b5c84f55d5d2 Remove the ui parameter from purple_account_[gs]et_enabled
Gary Kramlich <grim@reaperworld.com>
parents: 41315
diff changeset
424 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
425 enabled = g_list_append(enabled, account);
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
426 }
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
427 }
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
428
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
429 return enabled;
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
430 }
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
431
41315
1c9f47bbc031 Replace PidginAccountsDisabledMenu with PidginInactiveAccountsMenu which is a GMenuModel subclass.
Gary Kramlich <grim@reaperworld.com>
parents: 41298
diff changeset
432 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
433 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
434 GList *disabled = NULL;
41315
1c9f47bbc031 Replace PidginAccountsDisabledMenu with PidginInactiveAccountsMenu which is a GMenuModel subclass.
Gary Kramlich <grim@reaperworld.com>
parents: 41298
diff changeset
435
1c9f47bbc031 Replace PidginAccountsDisabledMenu with PidginInactiveAccountsMenu which is a GMenuModel subclass.
Gary Kramlich <grim@reaperworld.com>
parents: 41298
diff changeset
436 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
437
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
438 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
439 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
440
41392
b5c84f55d5d2 Remove the ui parameter from purple_account_[gs]et_enabled
Gary Kramlich <grim@reaperworld.com>
parents: 41315
diff changeset
441 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
442 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
443 }
1c9f47bbc031 Replace PidginAccountsDisabledMenu with PidginInactiveAccountsMenu which is a GMenuModel subclass.
Gary Kramlich <grim@reaperworld.com>
parents: 41298
diff changeset
444 }
1c9f47bbc031 Replace PidginAccountsDisabledMenu with PidginInactiveAccountsMenu which is a GMenuModel subclass.
Gary Kramlich <grim@reaperworld.com>
parents: 41298
diff changeset
445
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
446 return disabled;
41315
1c9f47bbc031 Replace PidginAccountsDisabledMenu with PidginInactiveAccountsMenu which is a GMenuModel subclass.
Gary Kramlich <grim@reaperworld.com>
parents: 41298
diff changeset
447 }
1c9f47bbc031 Replace PidginAccountsDisabledMenu with PidginInactiveAccountsMenu which is a GMenuModel subclass.
Gary Kramlich <grim@reaperworld.com>
parents: 41298
diff changeset
448
41890
2c15f6e30f20 Add purple_account_manager_get_connected and port libpurple to it
Gary Kramlich <grim@reaperworld.com>
parents: 41851
diff changeset
449 GList *
2c15f6e30f20 Add purple_account_manager_get_connected and port libpurple to it
Gary Kramlich <grim@reaperworld.com>
parents: 41851
diff changeset
450 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
451 GList *connected = NULL;
2c15f6e30f20 Add purple_account_manager_get_connected and port libpurple to it
Gary Kramlich <grim@reaperworld.com>
parents: 41851
diff changeset
452
2c15f6e30f20 Add purple_account_manager_get_connected and port libpurple to it
Gary Kramlich <grim@reaperworld.com>
parents: 41851
diff changeset
453 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
454
2c15f6e30f20 Add purple_account_manager_get_connected and port libpurple to it
Gary Kramlich <grim@reaperworld.com>
parents: 41851
diff changeset
455 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
456 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
457 PurpleConnection *connection = NULL;
2c15f6e30f20 Add purple_account_manager_get_connected and port libpurple to it
Gary Kramlich <grim@reaperworld.com>
parents: 41851
diff changeset
458
2c15f6e30f20 Add purple_account_manager_get_connected and port libpurple to it
Gary Kramlich <grim@reaperworld.com>
parents: 41851
diff changeset
459 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
460 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
461 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
462 {
2c15f6e30f20 Add purple_account_manager_get_connected and port libpurple to it
Gary Kramlich <grim@reaperworld.com>
parents: 41851
diff changeset
463 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
464 }
2c15f6e30f20 Add purple_account_manager_get_connected and port libpurple to it
Gary Kramlich <grim@reaperworld.com>
parents: 41851
diff changeset
465 }
2c15f6e30f20 Add purple_account_manager_get_connected and port libpurple to it
Gary Kramlich <grim@reaperworld.com>
parents: 41851
diff changeset
466
2c15f6e30f20 Add purple_account_manager_get_connected and port libpurple to it
Gary Kramlich <grim@reaperworld.com>
parents: 41851
diff changeset
467 return connected;
2c15f6e30f20 Add purple_account_manager_get_connected and port libpurple to it
Gary Kramlich <grim@reaperworld.com>
parents: 41851
diff changeset
468 }
2c15f6e30f20 Add purple_account_manager_get_connected and port libpurple to it
Gary Kramlich <grim@reaperworld.com>
parents: 41851
diff changeset
469
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
470 void
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
471 purple_account_manager_reorder(PurpleAccountManager *manager,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
472 PurpleAccount *account,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
473 guint new_index)
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 guint index = 0;
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
476
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
477 g_return_if_fail(PURPLE_IS_ACCOUNT_MANAGER(manager));
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
478 g_return_if_fail(PURPLE_IS_ACCOUNT(account));
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
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 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
481 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
482 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
483
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
484 /* 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
485 * 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
486 * 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
487 */
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
488 if(new_index > index) {
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
489 new_index--;
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
490 }
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
491 } else {
41976
49969fa9a664 Update libpurple for the deprecations in the account api
Gary Kramlich <grim@reaperworld.com>
parents: 41946
diff changeset
492 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
493
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
494 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
495 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
496
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
497 return;
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
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
500 /* 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
501 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
502 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
503
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
504 purple_accounts_schedule_save();
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
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
507 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
508 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
509 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
510 {
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
511 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
512 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
513
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
514 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
515 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
516 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
517
41976
49969fa9a664 Update libpurple for the deprecations in the account api
Gary Kramlich <grim@reaperworld.com>
parents: 41946
diff changeset
518 if(purple_strequal(purple_contact_info_get_id(info), id)) {
42291
a86b7bcbb471 Make the purple_account_manager_find functions return transfer full.
Gary Kramlich <grim@reaperworld.com>
parents: 42234
diff changeset
519 return g_object_ref(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
520 }
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
521 }
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
522
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
523 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
524 }
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
525
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
526 PurpleAccount *
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
527 purple_account_manager_find(PurpleAccountManager *manager,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
528 const gchar *username, const gchar *protocol_id)
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
529 {
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
530 g_return_val_if_fail(PURPLE_IS_ACCOUNT_MANAGER(manager), NULL);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
531 g_return_val_if_fail(username != NULL, NULL);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
532 g_return_val_if_fail(protocol_id != NULL, NULL);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
533
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
534 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
535 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
536 PurpleContactInfo *info = PURPLE_CONTACT_INFO(account);
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
537 gchar *normalized = NULL;
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
538 const gchar *existing_protocol_id = NULL;
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
539 const gchar *existing_username = NULL;
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
540 const gchar *existing_normalized = NULL;
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
541
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
542 /* Check if the protocol id matches what the user asked for. */
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
543 existing_protocol_id = purple_account_get_protocol_id(account);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
544 if(!purple_strequal(existing_protocol_id, protocol_id)) {
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
545 continue;
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
546 }
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
547
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
548 /* Finally verify the username. */
41976
49969fa9a664 Update libpurple for the deprecations in the account api
Gary Kramlich <grim@reaperworld.com>
parents: 41946
diff changeset
549 existing_username = purple_contact_info_get_username(info);
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
550 normalized = g_strdup(purple_normalize(account, username));
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
551 existing_normalized = purple_normalize(account, existing_username);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
552
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
553 if(purple_strequal(existing_normalized, normalized)) {
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
554 g_free(normalized);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
555
42291
a86b7bcbb471 Make the purple_account_manager_find functions return transfer full.
Gary Kramlich <grim@reaperworld.com>
parents: 42234
diff changeset
556 return g_object_ref(account);
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
557 }
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
558 g_free(normalized);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
559 }
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
560
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
561 return NULL;
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
562 }
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
563
41641
ff6dff2228e1 Add a custom find to account manager
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41456
diff changeset
564 PurpleAccount *
ff6dff2228e1 Add a custom find to account manager
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41456
diff changeset
565 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
566 GEqualFunc func, gconstpointer data)
ff6dff2228e1 Add a custom find to account manager
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41456
diff changeset
567 {
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
568 guint index = 0;
41641
ff6dff2228e1 Add a custom find to account manager
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41456
diff changeset
569
ff6dff2228e1 Add a custom find to account manager
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41456
diff changeset
570 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
571 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
572
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
573 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
574 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
575
42291
a86b7bcbb471 Make the purple_account_manager_find functions return transfer full.
Gary Kramlich <grim@reaperworld.com>
parents: 42234
diff changeset
576 return g_object_ref(account);
41641
ff6dff2228e1 Add a custom find to account manager
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41456
diff changeset
577 }
ff6dff2228e1 Add a custom find to account manager
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41456
diff changeset
578
ff6dff2228e1 Add a custom find to account manager
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41456
diff changeset
579 return NULL;
ff6dff2228e1 Add a custom find to account manager
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41456
diff changeset
580 }
ff6dff2228e1 Add a custom find to account manager
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41456
diff changeset
581
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
582 void
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
583 purple_account_manager_foreach(PurpleAccountManager *manager,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
584 PurpleAccountManagerForeachFunc callback,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
585 gpointer data)
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
586 {
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
587 g_return_if_fail(PURPLE_IS_ACCOUNT_MANAGER(manager));
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
588 g_return_if_fail(callback != NULL);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
589
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
590 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
591 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
592 callback(account, data);
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
593 }
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
594 }

mercurial