libpurple/protocols/gg/servconn.c

Tue, 07 Mar 2023 01:04:42 -0600

author
Elliott Sales de Andrade <quantum.analyst@gmail.com>
date
Tue, 07 Mar 2023 01:04:42 -0600
changeset 42128
118067ca0367
parent 40813
71305a7d7423
child 42172
7c2d151b410d
permissions
-rw-r--r--

Convert PurpleRequestPage into a GObject

And rename it from `PurpleRequestFields`.

Also, implements `GListModel` for the groups, but nothing uses it that way get.

Testing Done:
Compiled, and opened Request Fields from Demo protocol.

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

33348
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33339
diff changeset
1 /* purple
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33339
diff changeset
2 *
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33339
diff changeset
3 * Purple is the legal property of its developers, whose names are too numerous
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33339
diff changeset
4 * to list here. Please refer to the COPYRIGHT file distributed with this
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33339
diff changeset
5 * source distribution.
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33339
diff changeset
6 *
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33339
diff changeset
7 * Rewritten from scratch during Google Summer of Code 2012
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33339
diff changeset
8 * by Tomek Wasilczyk (http://www.wasilczyk.pl).
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33339
diff changeset
9 *
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33339
diff changeset
10 * Previously implemented by:
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33339
diff changeset
11 * - Arkadiusz Miskiewicz <misiek@pld.org.pl> - first implementation (2001);
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33339
diff changeset
12 * - Bartosz Oler <bartosz@bzimage.us> - reimplemented during GSoC 2005;
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33339
diff changeset
13 * - Krzysztof Klinikowski <grommasher@gmail.com> - some parts (2009-2011).
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33339
diff changeset
14 *
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33339
diff changeset
15 * This program is free software; you can redistribute it and/or modify
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33339
diff changeset
16 * it under the terms of the GNU General Public License as published by
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33339
diff changeset
17 * the Free Software Foundation; either version 2 of the License, or
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33339
diff changeset
18 * (at your option) any later version.
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33339
diff changeset
19 *
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33339
diff changeset
20 * This program is distributed in the hope that it will be useful,
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33339
diff changeset
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33339
diff changeset
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33339
diff changeset
23 * GNU General Public License for more details.
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33339
diff changeset
24 *
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33339
diff changeset
25 * You should have received a copy of the GNU General Public License
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33339
diff changeset
26 * along with this program; if not, write to the Free Software
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33339
diff changeset
27 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33339
diff changeset
28 */
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33339
diff changeset
29
33339
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
30 #include "servconn.h"
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
31
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
32 #include "utils.h"
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
33
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
34 #define GGP_SERVCONN_HISTORY_PREF "/plugins/prpl/gg/server_history"
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
35 #define GGP_SERVCONN_HISTORY_MAXLEN 15
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
36
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
37 typedef struct
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
38 {
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
39 GList *server_history;
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
40 PurpleAccountOption *server_option;
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
41 } ggp_servconn_global_data;
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
42
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
43 static ggp_servconn_global_data global_data;
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
44
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
45 void ggp_servconn_setup(PurpleAccountOption *server_option)
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
46 {
40538
222423055d93 Cleanup some GG utility functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40358
diff changeset
47 GList *extra;
222423055d93 Cleanup some GG utility functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40358
diff changeset
48 purple_prefs_add_string_list(GGP_SERVCONN_HISTORY_PREF, NULL);
35357
389e413e3414 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35145
diff changeset
49
33339
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
50 global_data.server_option = server_option;
40538
222423055d93 Cleanup some GG utility functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40358
diff changeset
51 global_data.server_history =
222423055d93 Cleanup some GG utility functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40358
diff changeset
52 purple_prefs_get_string_list(GGP_SERVCONN_HISTORY_PREF);
222423055d93 Cleanup some GG utility functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40358
diff changeset
53 extra = g_list_nth(global_data.server_history, GGP_SERVCONN_HISTORY_MAXLEN);
222423055d93 Cleanup some GG utility functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40358
diff changeset
54 if (extra != NULL) {
222423055d93 Cleanup some GG utility functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40358
diff changeset
55 /* Truncate the list to the maximum. */
222423055d93 Cleanup some GG utility functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40358
diff changeset
56 extra->prev->next = NULL;
222423055d93 Cleanup some GG utility functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40358
diff changeset
57 g_list_free_full(extra, g_free);
222423055d93 Cleanup some GG utility functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40358
diff changeset
58 }
35357
389e413e3414 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35145
diff changeset
59
40813
71305a7d7423 Modernize PurpleProtocol
Gary Kramlich <grim@reaperworld.com>
parents: 40538
diff changeset
60 if(server_option != NULL) {
71305a7d7423 Modernize PurpleProtocol
Gary Kramlich <grim@reaperworld.com>
parents: 40538
diff changeset
61 purple_account_option_string_set_hints(global_data.server_option,
71305a7d7423 Modernize PurpleProtocol
Gary Kramlich <grim@reaperworld.com>
parents: 40538
diff changeset
62 ggp_servconn_get_servers());
71305a7d7423 Modernize PurpleProtocol
Gary Kramlich <grim@reaperworld.com>
parents: 40538
diff changeset
63 }
33339
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
64 }
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
65
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
66 void ggp_servconn_cleanup(void)
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
67 {
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
68 g_list_free_full(global_data.server_history, &g_free);
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
69 }
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
70
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
71 void ggp_servconn_add_server(const gchar *server)
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
72 {
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
73 GList *old_entry;
35357
389e413e3414 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35145
diff changeset
74
33339
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
75 old_entry = g_list_find_custom(global_data.server_history, server,
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
76 (GCompareFunc)g_strcmp0);
35361
efdbd45604f1 Style: fix gg braces (part 2)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35357
diff changeset
77 if (old_entry) {
33339
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
78 g_free(old_entry->data);
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
79 global_data.server_history = g_list_delete_link(
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
80 global_data.server_history, old_entry);
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
81 }
35357
389e413e3414 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35145
diff changeset
82
33339
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
83 global_data.server_history = g_list_prepend(global_data.server_history,
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
84 g_strdup(server));
40538
222423055d93 Cleanup some GG utility functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40358
diff changeset
85 old_entry =
222423055d93 Cleanup some GG utility functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40358
diff changeset
86 g_list_nth(global_data.server_history, GGP_SERVCONN_HISTORY_MAXLEN);
222423055d93 Cleanup some GG utility functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40358
diff changeset
87 if (old_entry != NULL) {
222423055d93 Cleanup some GG utility functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40358
diff changeset
88 /* Truncate the list to the maximum. */
222423055d93 Cleanup some GG utility functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40358
diff changeset
89 old_entry->prev->next = NULL;
222423055d93 Cleanup some GG utility functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40358
diff changeset
90 g_list_free_full(old_entry, g_free);
222423055d93 Cleanup some GG utility functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40358
diff changeset
91 }
33339
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
92
40538
222423055d93 Cleanup some GG utility functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40358
diff changeset
93 purple_prefs_set_string_list(GGP_SERVCONN_HISTORY_PREF,
222423055d93 Cleanup some GG utility functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40358
diff changeset
94 global_data.server_history);
33339
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
95 purple_account_option_string_set_hints(global_data.server_option,
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
96 ggp_servconn_get_servers());
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
97 }
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
98
40538
222423055d93 Cleanup some GG utility functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40358
diff changeset
99 GSList *
222423055d93 Cleanup some GG utility functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40358
diff changeset
100 ggp_servconn_get_servers(void)
33339
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
101 {
40538
222423055d93 Cleanup some GG utility functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40358
diff changeset
102 GSList *new_list = NULL;
222423055d93 Cleanup some GG utility functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40358
diff changeset
103 GList *it;
222423055d93 Cleanup some GG utility functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40358
diff changeset
104
222423055d93 Cleanup some GG utility functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40358
diff changeset
105 it = g_list_first(global_data.server_history);
222423055d93 Cleanup some GG utility functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40358
diff changeset
106 while (it) {
222423055d93 Cleanup some GG utility functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40358
diff changeset
107 new_list = g_slist_append(new_list, g_strdup(it->data));
222423055d93 Cleanup some GG utility functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40358
diff changeset
108 it = g_list_next(it);
222423055d93 Cleanup some GG utility functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40358
diff changeset
109 }
222423055d93 Cleanup some GG utility functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40358
diff changeset
110 return new_list;
33339
02ee2834030c Gadu-Gadu: servers history feature
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
111 }
35145
01ef7274b440 Gadu-Gadu: handle apropriate event when getting remotely disconnected from other session
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34350
diff changeset
112
01ef7274b440 Gadu-Gadu: handle apropriate event when getting remotely disconnected from other session
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34350
diff changeset
113 void
01ef7274b440 Gadu-Gadu: handle apropriate event when getting remotely disconnected from other session
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34350
diff changeset
114 ggp_servconn_remote_disconnect(PurpleConnection *gc)
01ef7274b440 Gadu-Gadu: handle apropriate event when getting remotely disconnected from other session
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34350
diff changeset
115 {
01ef7274b440 Gadu-Gadu: handle apropriate event when getting remotely disconnected from other session
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34350
diff changeset
116 purple_debug_info("gg", "Server remotely closes connection");
01ef7274b440 Gadu-Gadu: handle apropriate event when getting remotely disconnected from other session
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34350
diff changeset
117 purple_account_disconnect(purple_connection_get_account(gc));
01ef7274b440 Gadu-Gadu: handle apropriate event when getting remotely disconnected from other session
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34350
diff changeset
118 }

mercurial