libpurple/purpleaccountmanager.c

Fri, 04 Nov 2022 23:55:30 -0500

author
Gary Kramlich <grim@reaperworld.com>
date
Fri, 04 Nov 2022 23:55:30 -0500
changeset 41890
2c15f6e30f20
parent 41851
64d7e69bff25
child 41891
a45d6db4f857
permissions
-rw-r--r--

Add purple_account_manager_get_connected and port libpurple to it

Generally speaking, purple_connections_get_all is used to get a list of accounts
that are currently connected and then act upon those accounts.

Instead of having a connections API for that, we can just put it into the
account manager which can query the accounts it knows about and check if they
are connected or not making the account the source of truth for whether it is
connected or not.

This also has the benefit of treating the connection as just a data object that
belongs to the account which feels a lot more natural than the existing API.

Testing Done:
Ran and let a bonjour account go idle and verified via another instance of pidgin.

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

41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1 /*
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
2 * Purple - Internet Messaging Library
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
3 * Copyright (C) Pidgin Developers <devel@pidgin.im>
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
4 *
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
5 * This program is free software; you can redistribute it and/or modify
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
7 * the Free Software Foundation; either version 2 of the License, or
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
8 * (at your option) any later version.
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
9 *
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
13 * GNU General Public License for more details.
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
14 *
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
16 * along with this program; if not, see <https://www.gnu.org/licenses/>.
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
17 */
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
18
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
19 #include "purpleaccountmanager.h"
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
20 #include "purpleprivate.h"
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
21
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
22 #include "account.h"
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
23 #include "accounts.h"
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
24 #include "core.h"
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
25
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
26 enum {
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
27 SIG_ADDED,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
28 SIG_REMOVED,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
29 N_SIGNALS,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
30 };
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
31 static guint signals[N_SIGNALS] = {0, };
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
32
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
33 struct _PurpleAccountManager {
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
34 GObject parent;
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
35
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
36 GPtrArray *accounts;
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
37 };
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
38
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
39 static PurpleAccountManager *default_manager = NULL;
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
40
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
41 /******************************************************************************
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
42 * GListModel Implementation
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
43 *****************************************************************************/
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
44 static GType
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
45 purple_account_get_item_type(G_GNUC_UNUSED GListModel *list) {
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
46 return PURPLE_TYPE_ACCOUNT;
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
47 }
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
48
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
49 static guint
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
50 purple_account_get_n_items(GListModel *list) {
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
51 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
52
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
53 return manager->accounts->len;
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
54 }
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
55
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
56 static gpointer
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
57 purple_account_get_item(GListModel *list, guint position) {
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
58 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
59 PurpleAccount *account = NULL;
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
60
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
61 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
62 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
63 g_object_ref(account);
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
64 }
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
65
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
66 return account;
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
67 }
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
68
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
69 static void
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
70 purple_account_manager_list_model_init(GListModelInterface *iface) {
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
71 iface->get_item_type = purple_account_get_item_type;
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
72 iface->get_n_items = purple_account_get_n_items;
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
73 iface->get_item = purple_account_get_item;
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
74 }
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
75
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
76 /******************************************************************************
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
77 * GObject Implementation
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
78 *****************************************************************************/
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
79 G_DEFINE_TYPE_EXTENDED(PurpleAccountManager, purple_account_manager,
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
80 G_TYPE_OBJECT, 0,
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
81 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
82 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
83
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
84 static void
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
85 purple_account_manager_finalize(GObject *obj) {
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
86 PurpleAccountManager *manager = PURPLE_ACCOUNT_MANAGER(obj);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
87
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
88 if(manager->accounts != NULL) {
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
89 g_ptr_array_free(manager->accounts, TRUE);
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
90 }
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
91
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
92 G_OBJECT_CLASS(purple_account_manager_parent_class)->finalize(obj);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
93 }
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
94
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
95 static void
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
96 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
97 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
98 }
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
99
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
100 static void
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
101 purple_account_manager_class_init(PurpleAccountManagerClass *klass) {
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
102 GObjectClass *obj_class = G_OBJECT_CLASS(klass);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
103
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
104 obj_class->finalize = purple_account_manager_finalize;
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
105
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
106 /**
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
107 * PurpleAccountManager::added:
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
108 * @manager: The account manager instance.
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
109 * @account: The account that was added.
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
110 *
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
111 * Emitted after @account was added to @manager.
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
112 *
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
113 * Since: 3.0.0
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
114 */
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
115 signals[SIG_ADDED] = g_signal_new_class_handler(
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
116 "added",
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
117 G_OBJECT_CLASS_TYPE(klass),
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
118 G_SIGNAL_RUN_LAST,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
119 NULL,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
120 NULL,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
121 NULL,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
122 NULL,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
123 G_TYPE_NONE,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
124 1,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
125 PURPLE_TYPE_ACCOUNT);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
126
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
127 /**
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
128 * PurpleAccountManager::removed:
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
129 * @manager: The account manager instance.
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
130 * @account: The account that was removed.
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
131 *
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
132 * Emitted after @account was removed from @manager.
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
133 *
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
134 * Since: 3.0.0
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 signals[SIG_REMOVED] = g_signal_new_class_handler(
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
137 "removed",
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
138 G_OBJECT_CLASS_TYPE(klass),
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
139 G_SIGNAL_RUN_LAST,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
140 NULL,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
141 NULL,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
142 NULL,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
143 NULL,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
144 G_TYPE_NONE,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
145 1,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
146 PURPLE_TYPE_ACCOUNT);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
147 }
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 /******************************************************************************
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
150 * Private API
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 void
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
153 purple_account_manager_startup(void) {
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
154 if(!PURPLE_IS_ACCOUNT_MANAGER(default_manager)) {
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
155 default_manager = g_object_new(PURPLE_TYPE_ACCOUNT_MANAGER, NULL);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
156 }
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
157 }
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
158
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
159 void
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
160 purple_account_manager_shutdown(void) {
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
161 g_clear_object(&default_manager);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
162 }
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
163
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
164 /******************************************************************************
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
165 * Public API
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
166 *****************************************************************************/
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
167 PurpleAccountManager *
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
168 purple_account_manager_get_default(void) {
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
169 return default_manager;
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
170 }
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
171
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
172 GListModel *
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
173 purple_account_manager_get_default_as_model(void) {
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
174 return G_LIST_MODEL(default_manager);
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
175 }
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
176
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
177 void
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
178 purple_account_manager_add(PurpleAccountManager *manager,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
179 PurpleAccount *account)
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 g_return_if_fail(PURPLE_IS_ACCOUNT_MANAGER(manager));
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
182 g_return_if_fail(PURPLE_IS_ACCOUNT(account));
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
183
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
184 /* 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
185 if(g_ptr_array_find(manager->accounts, account, NULL)) {
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
186 return;
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
187 }
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
188
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
189 /* 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
190 * 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
191 * 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
192 * new account.
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
193 */
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
194 g_ptr_array_insert(manager->accounts, 0, account);
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
195
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
196 purple_accounts_schedule_save();
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
197
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
198 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
199 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
200 }
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
201
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
202 void
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
203 purple_account_manager_remove(PurpleAccountManager *manager,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
204 PurpleAccount *account)
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
205 {
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
206 guint index = 0;
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
207
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
208 g_return_if_fail(PURPLE_IS_ACCOUNT_MANAGER(manager));
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
209 g_return_if_fail(PURPLE_IS_ACCOUNT(account));
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
210
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
211 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
212 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
213 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
214 }
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
215
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
216 purple_accounts_schedule_save();
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
217
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
218 /* Clearing the error ensures that account-error-changed is emitted,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
219 * 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
220 */
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
221 purple_account_clear_current_error(account);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
222
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
223 g_signal_emit(manager, signals[SIG_REMOVED], 0, account);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
224 }
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
225
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
226 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
227 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
228 GList *enabled = NULL;
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
229
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
230 g_return_val_if_fail(PURPLE_IS_ACCOUNT_MANAGER(manager), NULL);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
231
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
232 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
233 PurpleAccount *account = g_ptr_array_index(manager->accounts, index);
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
234
41392
b5c84f55d5d2 Remove the ui parameter from purple_account_[gs]et_enabled
Gary Kramlich <grim@reaperworld.com>
parents: 41315
diff changeset
235 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
236 enabled = g_list_append(enabled, account);
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
237 }
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
238 }
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
239
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
240 return enabled;
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
241 }
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
242
41315
1c9f47bbc031 Replace PidginAccountsDisabledMenu with PidginInactiveAccountsMenu which is a GMenuModel subclass.
Gary Kramlich <grim@reaperworld.com>
parents: 41298
diff changeset
243 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
244 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
245 GList *disabled = NULL;
41315
1c9f47bbc031 Replace PidginAccountsDisabledMenu with PidginInactiveAccountsMenu which is a GMenuModel subclass.
Gary Kramlich <grim@reaperworld.com>
parents: 41298
diff changeset
246
1c9f47bbc031 Replace PidginAccountsDisabledMenu with PidginInactiveAccountsMenu which is a GMenuModel subclass.
Gary Kramlich <grim@reaperworld.com>
parents: 41298
diff changeset
247 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
248
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
249 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
250 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
251
41392
b5c84f55d5d2 Remove the ui parameter from purple_account_[gs]et_enabled
Gary Kramlich <grim@reaperworld.com>
parents: 41315
diff changeset
252 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
253 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
254 }
1c9f47bbc031 Replace PidginAccountsDisabledMenu with PidginInactiveAccountsMenu which is a GMenuModel subclass.
Gary Kramlich <grim@reaperworld.com>
parents: 41298
diff changeset
255 }
1c9f47bbc031 Replace PidginAccountsDisabledMenu with PidginInactiveAccountsMenu which is a GMenuModel subclass.
Gary Kramlich <grim@reaperworld.com>
parents: 41298
diff changeset
256
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
257 return disabled;
41315
1c9f47bbc031 Replace PidginAccountsDisabledMenu with PidginInactiveAccountsMenu which is a GMenuModel subclass.
Gary Kramlich <grim@reaperworld.com>
parents: 41298
diff changeset
258 }
1c9f47bbc031 Replace PidginAccountsDisabledMenu with PidginInactiveAccountsMenu which is a GMenuModel subclass.
Gary Kramlich <grim@reaperworld.com>
parents: 41298
diff changeset
259
41890
2c15f6e30f20 Add purple_account_manager_get_connected and port libpurple to it
Gary Kramlich <grim@reaperworld.com>
parents: 41851
diff changeset
260 GList *
2c15f6e30f20 Add purple_account_manager_get_connected and port libpurple to it
Gary Kramlich <grim@reaperworld.com>
parents: 41851
diff changeset
261 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
262 GList *connected = NULL;
2c15f6e30f20 Add purple_account_manager_get_connected and port libpurple to it
Gary Kramlich <grim@reaperworld.com>
parents: 41851
diff changeset
263
2c15f6e30f20 Add purple_account_manager_get_connected and port libpurple to it
Gary Kramlich <grim@reaperworld.com>
parents: 41851
diff changeset
264 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
265
2c15f6e30f20 Add purple_account_manager_get_connected and port libpurple to it
Gary Kramlich <grim@reaperworld.com>
parents: 41851
diff changeset
266 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
267 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
268 PurpleConnection *connection = NULL;
2c15f6e30f20 Add purple_account_manager_get_connected and port libpurple to it
Gary Kramlich <grim@reaperworld.com>
parents: 41851
diff changeset
269
2c15f6e30f20 Add purple_account_manager_get_connected and port libpurple to it
Gary Kramlich <grim@reaperworld.com>
parents: 41851
diff changeset
270 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
271 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
272 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
273 {
2c15f6e30f20 Add purple_account_manager_get_connected and port libpurple to it
Gary Kramlich <grim@reaperworld.com>
parents: 41851
diff changeset
274 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
275 }
2c15f6e30f20 Add purple_account_manager_get_connected and port libpurple to it
Gary Kramlich <grim@reaperworld.com>
parents: 41851
diff changeset
276 }
2c15f6e30f20 Add purple_account_manager_get_connected and port libpurple to it
Gary Kramlich <grim@reaperworld.com>
parents: 41851
diff changeset
277
2c15f6e30f20 Add purple_account_manager_get_connected and port libpurple to it
Gary Kramlich <grim@reaperworld.com>
parents: 41851
diff changeset
278 return connected;
2c15f6e30f20 Add purple_account_manager_get_connected and port libpurple to it
Gary Kramlich <grim@reaperworld.com>
parents: 41851
diff changeset
279 }
2c15f6e30f20 Add purple_account_manager_get_connected and port libpurple to it
Gary Kramlich <grim@reaperworld.com>
parents: 41851
diff changeset
280
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
281 void
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
282 purple_account_manager_reorder(PurpleAccountManager *manager,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
283 PurpleAccount *account,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
284 guint new_index)
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
285 {
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
286 guint index = 0;
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
287
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
288 g_return_if_fail(PURPLE_IS_ACCOUNT_MANAGER(manager));
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
289 g_return_if_fail(PURPLE_IS_ACCOUNT(account));
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
290
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
291 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
292 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
293 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
294
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
295 /* 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
296 * 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
297 * 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
298 */
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
299 if(new_index > index) {
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
300 new_index--;
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
301 }
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
302 } else {
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
303 g_critical("Unregistered account (%s) found during reorder!",
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
304 purple_account_get_username(account));
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
305 return;
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
306 }
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 /* 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
309 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
310 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
311
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
312 purple_accounts_schedule_save();
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 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
316 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
317 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
318 {
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
319 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
320 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
321
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
322 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
323 PurpleAccount *account = g_ptr_array_index(manager->accounts, index);
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
324
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
325 if(purple_strequal(purple_account_get_id(account), 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
326 return account;
6d816e02fd76 Create a menu controller that will keep a GMenu in sync with the disabled accounts in libpurple
Gary Kramlich <grim@reaperworld.com>
parents: 41181
diff changeset
327 }
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
328 }
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
329
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
330 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
331 }
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
332
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
333 PurpleAccount *
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
334 purple_account_manager_find(PurpleAccountManager *manager,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
335 const gchar *username, const gchar *protocol_id)
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
336 {
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
337 g_return_val_if_fail(PURPLE_IS_ACCOUNT_MANAGER(manager), NULL);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
338 g_return_val_if_fail(username != NULL, NULL);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
339 g_return_val_if_fail(protocol_id != NULL, NULL);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
340
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
341 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
342 PurpleAccount *account = g_ptr_array_index(manager->accounts, index);
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
343 gchar *normalized = NULL;
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
344 const gchar *existing_protocol_id = NULL;
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
345 const gchar *existing_username = NULL;
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
346 const gchar *existing_normalized = NULL;
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
347
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
348 /* Check if the protocol id matches what the user asked for. */
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
349 existing_protocol_id = purple_account_get_protocol_id(account);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
350 if(!purple_strequal(existing_protocol_id, protocol_id)) {
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
351 continue;
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
352 }
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
353
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
354 /* Finally verify the username. */
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
355 existing_username = purple_account_get_username(account);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
356 normalized = g_strdup(purple_normalize(account, username));
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
357 existing_normalized = purple_normalize(account, existing_username);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
358
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
359 if(purple_strequal(existing_normalized, normalized)) {
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
360 g_free(normalized);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
361
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
362 return account;
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
363 }
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
364 g_free(normalized);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
365 }
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 return NULL;
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
368 }
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
369
41641
ff6dff2228e1 Add a custom find to account manager
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41456
diff changeset
370 PurpleAccount *
ff6dff2228e1 Add a custom find to account manager
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41456
diff changeset
371 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
372 GEqualFunc func, gconstpointer data)
ff6dff2228e1 Add a custom find to account manager
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41456
diff changeset
373 {
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
374 guint index = 0;
41641
ff6dff2228e1 Add a custom find to account manager
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41456
diff changeset
375
ff6dff2228e1 Add a custom find to account manager
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41456
diff changeset
376 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
377 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
378
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
379 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
380 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
381
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
382 return account;
41641
ff6dff2228e1 Add a custom find to account manager
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41456
diff changeset
383 }
ff6dff2228e1 Add a custom find to account manager
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41456
diff changeset
384
ff6dff2228e1 Add a custom find to account manager
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41456
diff changeset
385 return NULL;
ff6dff2228e1 Add a custom find to account manager
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41456
diff changeset
386 }
ff6dff2228e1 Add a custom find to account manager
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41456
diff changeset
387
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
388 void
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
389 purple_account_manager_foreach(PurpleAccountManager *manager,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
390 PurpleAccountManagerForeachFunc callback,
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
391 gpointer data)
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
392 {
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
393 g_return_if_fail(PURPLE_IS_ACCOUNT_MANAGER(manager));
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
394 g_return_if_fail(callback != NULL);
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
395
41851
64d7e69bff25 Move PurpleAccountManager to GPtrArray and implement GListModel
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41798
diff changeset
396 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
397 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
398 callback(account, data);
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
399 }
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
400 }

mercurial