protocols/demo/purpledemoprotocol.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 43082
0248f784950d
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.

41224
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1 /*
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
2 * Purple - Internet Messaging Library
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
3 * Copyright (C) Pidgin Developers <devel@pidgin.im>
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
4 *
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
8 * version 2 of the License, or (at your option) any later version.
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
9 *
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
13 * Lesser General Public License for more details.
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
14 *
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
16 * License along with this library; if not, see <https://www.gnu.org/licenses/>.
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
17 */
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
18
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
19 #include <glib/gi18n-lib.h>
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
20
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
21 #include "purpledemoprotocol.h"
41999
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents: 41968
diff changeset
22
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents: 41968
diff changeset
23 #include "purpledemoconnection.h"
41459
53a9d24d5be2 Add some protocol actions to demo protocol
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41285
diff changeset
24 #include "purpledemoprotocolactions.h"
42304
51a419226147 A basic context menu for PurpleContactInfo
Gary Kramlich <grim@reaperworld.com>
parents: 42126
diff changeset
25 #include "purpledemoprotocolcontacts.h"
42323
119cc14f9c12 Port the Demo protocol plugin to PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42304
diff changeset
26 #include "purpledemoprotocolconversation.h"
41224
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
27
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
28 struct _PurpleDemoProtocol {
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
29 PurpleProtocol parent;
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
30 };
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
31
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
32 /******************************************************************************
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
33 * PurpleProtocol Implementation
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
34 *****************************************************************************/
41999
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents: 41968
diff changeset
35 static PurpleConnection *
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents: 41968
diff changeset
36 purple_demo_protocol_create_connection(PurpleProtocol *protocol,
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents: 41968
diff changeset
37 PurpleAccount *account,
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents: 41968
diff changeset
38 const char *password,
42009
fb172b78a9ee Replace the account-actions-changed signal with an actions-changed signal on PurpleProtocolActions
Gary Kramlich <grim@reaperworld.com>
parents: 41999
diff changeset
39 G_GNUC_UNUSED GError **error)
41775
82c861678f39 Pass the PurpleProtocol objects to all methods of the class
Gary Kramlich <grim@reaperworld.com>
parents: 41487
diff changeset
40 {
41999
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents: 41968
diff changeset
41 g_return_val_if_fail(PURPLE_IS_PROTOCOL(protocol), NULL);
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents: 41968
diff changeset
42 g_return_val_if_fail(PURPLE_IS_ACCOUNT(account), NULL);
41224
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
43
41999
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents: 41968
diff changeset
44 return g_object_new(
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents: 41968
diff changeset
45 PURPLE_DEMO_TYPE_CONNECTION,
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents: 41968
diff changeset
46 "protocol", protocol,
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents: 41968
diff changeset
47 "account", account,
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents: 41968
diff changeset
48 "password", password,
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents: 41968
diff changeset
49 NULL);
41224
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
50
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
51 }
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
52
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
53 /******************************************************************************
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
54 * GObject Implementation
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
55 *****************************************************************************/
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
56 G_DEFINE_DYNAMIC_TYPE_EXTENDED(
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
57 PurpleDemoProtocol,
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
58 purple_demo_protocol,
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
59 PURPLE_TYPE_PROTOCOL,
41911
201aae92d734 Clean up the G_DEFINE_DYNAMIC_TYPE definitions for protocols
Gary Kramlich <grim@reaperworld.com>
parents: 41845
diff changeset
60 G_TYPE_FLAG_FINAL,
42304
51a419226147 A basic context menu for PurpleContactInfo
Gary Kramlich <grim@reaperworld.com>
parents: 42126
diff changeset
61 G_IMPLEMENT_INTERFACE_DYNAMIC(PURPLE_TYPE_PROTOCOL_CONTACTS,
51a419226147 A basic context menu for PurpleContactInfo
Gary Kramlich <grim@reaperworld.com>
parents: 42126
diff changeset
62 purple_demo_protocol_contacts_init)
42323
119cc14f9c12 Port the Demo protocol plugin to PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42304
diff changeset
63 G_IMPLEMENT_INTERFACE_DYNAMIC(PURPLE_TYPE_PROTOCOL_CONVERSATION,
42763
e73dd56b68f1 Remove the media implementation from the Demo protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42697
diff changeset
64 purple_demo_protocol_conversation_init))
41224
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
65
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
66 static void
41968
2fc2db360044 Bump C standard to C99 for Demo protocol and fix warnings
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41911
diff changeset
67 purple_demo_protocol_init(G_GNUC_UNUSED PurpleDemoProtocol *protocol) {
41224
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
68 }
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
69
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
70 static void
41968
2fc2db360044 Bump C standard to C99 for Demo protocol and fix warnings
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41911
diff changeset
71 purple_demo_protocol_class_finalize(G_GNUC_UNUSED PurpleDemoProtocolClass *klass) {
41224
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
72 }
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
73
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
74 static void
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
75 purple_demo_protocol_class_init(PurpleDemoProtocolClass *klass) {
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
76 PurpleProtocolClass *protocol_class = PURPLE_PROTOCOL_CLASS(klass);
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
77
41999
91af085cf35b Update the demo protocol plugin to use the new create_connection virtual method
Gary Kramlich <grim@reaperworld.com>
parents: 41968
diff changeset
78 protocol_class->create_connection = purple_demo_protocol_create_connection;
42878
5183064bcc28 Implement Purple.Protocol.get_action_menu in the Demo protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42854
diff changeset
79 protocol_class->get_action_menu = purple_demo_protocol_get_action_menu;
41224
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
80 }
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
81
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
82 /******************************************************************************
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
83 * Local Exports
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
84 *****************************************************************************/
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
85 void
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
86 purple_demo_protocol_register(GPluginNativePlugin *plugin) {
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
87 purple_demo_protocol_register_type(G_TYPE_MODULE(plugin));
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
88 }
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
89
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
90 PurpleProtocol *
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
91 purple_demo_protocol_new(void) {
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
92 return g_object_new(
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
93 PURPLE_DEMO_TYPE_PROTOCOL,
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
94 "id", "prpl-demo",
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
95 "name", "Demo",
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
96 "description", "A protocol plugin with static data to be used in "
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
97 "screen shots.",
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
98 "icon-name", "im-purple-demo",
43082
0248f784950d Make protocol resource paths more consistent
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 42881
diff changeset
99 "icon-resource-path", "/im/pidgin/libpurple/protocols/demo/icons",
41224
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
100 "options", OPT_PROTO_NO_PASSWORD,
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
101 NULL);
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
102 }

mercurial