protocols/demo/purpledemoconnection.c

Sun, 10 Aug 2025 23:44:08 +0800

author
Gong Zhile <gongzl@stu.hebust.edu.cn>
date
Sun, 10 Aug 2025 23:44:08 +0800
branch
purple_conversation_find_message_by_id
changeset 43309
099e1dfb856b
parent 43042
8135b5752cec
permissions
-rw-r--r--

Add Purple.Conversation.find_message_by_id

The method was added so that a protocol or plugin could easily lookup
for the reference for a message. This will be especially useful when a
protocol received a quoted message but only with an id.

41999
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1 /*
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
2 * Purple - Internet Messaging Library
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
3 * Copyright (C) Pidgin Developers <devel@pidgin.im>
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
4 *
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
5 * This program is free software; you can redistribute it and/or modify
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
7 * the Free Software Foundation; either version 2 of the License, or
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
8 * (at your option) any later version.
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
9 *
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
13 * GNU General Public License for more details.
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
14 *
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
16 * along with this program; if not, see <https://www.gnu.org/licenses/>.
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
17 */
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
18
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
19 #include <glib/gi18n-lib.h>
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
20
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
21 #include "purpledemoconnection.h"
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
22
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
23 #include "purpledemocontacts.h"
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
24
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
25 struct _PurpleDemoConnection {
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
26 PurpleConnection parent;
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
27 };
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
28
42570
a980db2607fd Make sure all of the final types in the protocols are defined as such
Gary Kramlich <grim@reaperworld.com>
parents: 41999
diff changeset
29 G_DEFINE_DYNAMIC_TYPE_EXTENDED(PurpleDemoConnection, purple_demo_connection,
a980db2607fd Make sure all of the final types in the protocols are defined as such
Gary Kramlich <grim@reaperworld.com>
parents: 41999
diff changeset
30 PURPLE_TYPE_CONNECTION, G_TYPE_FLAG_FINAL, {})
41999
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
31
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
32 /******************************************************************************
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
33 * PurpleConnection Implementation
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
34 *****************************************************************************/
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
35 static gboolean
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
36 purple_demo_connection_connect(PurpleConnection *connection,
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
37 G_GNUC_UNUSED GError **error)
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
38 {
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
39 PurpleAccount *account = purple_connection_get_account(connection);
42906
e0d5b79e7431 Fix some issues with Purple.Message in the Demo protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42652
diff changeset
40 PurpleContactInfo *info = purple_account_get_contact_info(account);
e0d5b79e7431 Fix some issues with Purple.Message in the Demo protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42652
diff changeset
41 const char *username = NULL;
e0d5b79e7431 Fix some issues with Purple.Message in the Demo protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42652
diff changeset
42
e0d5b79e7431 Fix some issues with Purple.Message in the Demo protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42652
diff changeset
43 username = purple_account_get_username(account);
e0d5b79e7431 Fix some issues with Purple.Message in the Demo protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42652
diff changeset
44 purple_contact_info_set_id(info, username);
e0d5b79e7431 Fix some issues with Purple.Message in the Demo protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42652
diff changeset
45 purple_contact_info_set_username(info, username);
41999
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
46
43042
8135b5752cec Update the protocols to the new connection state api
Gary Kramlich <grim@reaperworld.com>
parents: 42906
diff changeset
47 purple_account_connected(account);
41999
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
48
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
49 purple_demo_contacts_load(account);
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
50
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
51 return TRUE;
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
52 }
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
53
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
54 static gboolean
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
55 purple_demo_connection_disconnect(G_GNUC_UNUSED PurpleConnection *connection,
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
56 G_GNUC_UNUSED GError **error)
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
57 {
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
58 return TRUE;
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
59 }
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
60
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
61 /******************************************************************************
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
62 * GObject Implementation
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
63 *****************************************************************************/
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
64 static void
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
65 purple_demo_connection_init(G_GNUC_UNUSED PurpleDemoConnection *connection) {
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
66 }
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
67
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
68 static void
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
69 purple_demo_connection_class_finalize(G_GNUC_UNUSED PurpleDemoConnectionClass *klass) {
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
70 }
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
71
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
72 static void
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
73 purple_demo_connection_class_init(PurpleDemoConnectionClass *klass) {
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
74 PurpleConnectionClass *connection_class = PURPLE_CONNECTION_CLASS(klass);
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
75
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
76 connection_class->connect = purple_demo_connection_connect;
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
77 connection_class->disconnect = purple_demo_connection_disconnect;
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
78 }
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
79
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
80 /******************************************************************************
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
81 * Internal API
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
82 *****************************************************************************/
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
83 void
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
84 purple_demo_connection_register(GPluginNativePlugin *plugin) {
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
85 purple_demo_connection_register_type(G_TYPE_MODULE(plugin));
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
86 }

mercurial