Sun, 10 Aug 2025 23:53:22 +0800
Various improvement, Support configuration from UI
| 0 | 1 | /* |
| 2 | * Purple Satori Plugin - Satori Protocol Plugin for Purple3 | |
| 3 | * Copyright (C) 2025 Gong Zhile | |
| 4 | * | |
| 5 | * This library is free software; you can redistribute it and/or | |
| 6 | * modify it under the terms of the GNU Lesser General Public | |
| 7 | * License as published by the Free Software Foundation; either | |
| 8 | * version 2 of the License, or (at your option) any later version. | |
| 9 | * | |
| 10 | * This library is distributed in the hope that it will be useful, | |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 13 | * Lesser General Public License for more details. | |
| 14 | * | |
| 15 | * You should have received a copy of the GNU Lesser General Public | |
| 16 | * License along with this library; if not, see <https://www.gnu.org/licenses/>. | |
| 17 | */ | |
| 18 | ||
| 19 | #include <glib/gi18n-lib.h> | |
| 20 | ||
| 21 | #include "purplesatoriprotocol.h" | |
| 22 | ||
|
3
33a7b189a2c6
Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents:
0
diff
changeset
|
23 | #include "glib.h" |
| 0 | 24 | #include "purplesatoriconnection.h" |
| 25 | #include "purplesatoriprotocolcontacts.h" | |
| 26 | #include "purplesatoriprotocolconversation.h" | |
| 27 | ||
| 28 | struct _PurpleSatoriProtocol { | |
| 29 | PurpleProtocol parent; | |
| 30 | }; | |
| 31 | ||
| 32 | /****************************************************************************** | |
| 33 | * PurpleProtocol Implementation | |
| 34 | *****************************************************************************/ | |
| 35 | static PurpleConnection * | |
| 36 | purple_satori_protocol_create_connection(PurpleProtocol *protocol, | |
| 37 | PurpleAccount *account, | |
| 38 | const char *password, | |
| 39 | G_GNUC_UNUSED GError **error) | |
| 40 | { | |
| 41 | g_return_val_if_fail(PURPLE_IS_PROTOCOL(protocol), NULL); | |
| 42 | g_return_val_if_fail(PURPLE_IS_ACCOUNT(account), NULL); | |
| 43 | ||
| 44 | return g_object_new(PURPLE_SATORI_TYPE_CONNECTION, | |
| 45 | "protocol", protocol, | |
| 46 | "account", account, | |
| 47 | "password", password, | |
| 48 | NULL); | |
| 49 | ||
| 50 | } | |
| 51 | ||
|
3
33a7b189a2c6
Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents:
0
diff
changeset
|
52 | static GList * |
|
33a7b189a2c6
Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents:
0
diff
changeset
|
53 | purple_satori_protocol_get_account_options(G_GNUC_UNUSED PurpleProtocol *protocol) |
|
33a7b189a2c6
Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents:
0
diff
changeset
|
54 | { |
|
33a7b189a2c6
Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents:
0
diff
changeset
|
55 | PurpleAccountOption *option = NULL; |
|
33a7b189a2c6
Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents:
0
diff
changeset
|
56 | GList *options = NULL; |
|
33a7b189a2c6
Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents:
0
diff
changeset
|
57 | |
|
33a7b189a2c6
Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents:
0
diff
changeset
|
58 | option = purple_account_option_string_new(_("Satori Platform"), "platform", |
|
33a7b189a2c6
Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents:
0
diff
changeset
|
59 | "QQ"); |
|
33a7b189a2c6
Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents:
0
diff
changeset
|
60 | options = g_list_append(options, option); |
|
33a7b189a2c6
Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents:
0
diff
changeset
|
61 | |
|
33a7b189a2c6
Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents:
0
diff
changeset
|
62 | option = purple_account_option_bool_new(_("Secure Connection (HTTPS)"), |
|
33a7b189a2c6
Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents:
0
diff
changeset
|
63 | "https", FALSE); |
|
33a7b189a2c6
Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents:
0
diff
changeset
|
64 | options = g_list_append(options, option); |
|
33a7b189a2c6
Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents:
0
diff
changeset
|
65 | |
|
33a7b189a2c6
Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents:
0
diff
changeset
|
66 | option = purple_account_option_string_new(_("API Host"), |
|
33a7b189a2c6
Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents:
0
diff
changeset
|
67 | "host", "127.0.0.1:5600"); |
|
33a7b189a2c6
Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents:
0
diff
changeset
|
68 | options = g_list_append(options, option); |
|
33a7b189a2c6
Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents:
0
diff
changeset
|
69 | |
|
33a7b189a2c6
Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents:
0
diff
changeset
|
70 | option = purple_account_option_string_new(_("API Path"), "path", "/v1"), |
|
33a7b189a2c6
Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents:
0
diff
changeset
|
71 | options = g_list_append(options, option); |
|
33a7b189a2c6
Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents:
0
diff
changeset
|
72 | |
|
33a7b189a2c6
Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents:
0
diff
changeset
|
73 | option = purple_account_option_string_new(_("API Token"), "token", NULL); |
|
33a7b189a2c6
Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents:
0
diff
changeset
|
74 | purple_account_option_string_set_masked(option, TRUE); |
|
33a7b189a2c6
Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents:
0
diff
changeset
|
75 | options = g_list_append(options, option); |
|
33a7b189a2c6
Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents:
0
diff
changeset
|
76 | |
|
33a7b189a2c6
Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents:
0
diff
changeset
|
77 | return options; |
|
33a7b189a2c6
Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents:
0
diff
changeset
|
78 | } |
|
33a7b189a2c6
Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents:
0
diff
changeset
|
79 | |
| 0 | 80 | /****************************************************************************** |
| 81 | * GObject Implementation | |
| 82 | *****************************************************************************/ | |
| 83 | G_DEFINE_DYNAMIC_TYPE_EXTENDED( | |
| 84 | PurpleSatoriProtocol, | |
| 85 | purple_satori_protocol, | |
| 86 | PURPLE_TYPE_PROTOCOL, | |
| 87 | G_TYPE_FLAG_FINAL, | |
| 88 | G_IMPLEMENT_INTERFACE_DYNAMIC(PURPLE_TYPE_PROTOCOL_CONTACTS, | |
| 89 | purple_satori_protocol_contacts_init) | |
| 90 | G_IMPLEMENT_INTERFACE_DYNAMIC(PURPLE_TYPE_PROTOCOL_CONVERSATION, | |
| 91 | purple_satori_protocol_conversation_init)) | |
| 92 | ||
| 93 | static void | |
| 94 | purple_satori_protocol_init(G_GNUC_UNUSED PurpleSatoriProtocol *protocol) { | |
| 95 | } | |
| 96 | ||
| 97 | static void | |
| 98 | purple_satori_protocol_class_finalize(G_GNUC_UNUSED PurpleSatoriProtocolClass *klass) { | |
| 99 | } | |
| 100 | ||
| 101 | static void | |
| 102 | purple_satori_protocol_class_init(PurpleSatoriProtocolClass *klass) { | |
| 103 | PurpleProtocolClass *protocol_class = PURPLE_PROTOCOL_CLASS(klass); | |
| 104 | ||
|
3
33a7b189a2c6
Various improvement, Support configuration from UI
Gong Zhile <gongzl@stu.hebust.edu.cn>
parents:
0
diff
changeset
|
105 | protocol_class->get_account_options = purple_satori_protocol_get_account_options; |
| 0 | 106 | protocol_class->create_connection = purple_satori_protocol_create_connection; |
| 107 | } | |
| 108 | ||
| 109 | /****************************************************************************** | |
| 110 | * Local Exports | |
| 111 | *****************************************************************************/ | |
| 112 | void | |
| 113 | purple_satori_protocol_register(GPluginNativePlugin *plugin) { | |
| 114 | purple_satori_protocol_register_type(G_TYPE_MODULE(plugin)); | |
| 115 | } | |
| 116 | ||
| 117 | PurpleProtocol * | |
| 118 | purple_satori_protocol_new(void) { | |
| 119 | return g_object_new( | |
| 120 | PURPLE_SATORI_TYPE_PROTOCOL, | |
| 121 | "id", "prpl-satori", | |
| 122 | "name", "Satori", | |
| 123 | "description", "Satori Protocol Plugin for Purple 3", | |
| 124 | "icon-name", "im-purple-satori", | |
| 125 | "icon-resource-path", "/im/pidgin/libpurple/protocols/satori/icons", | |
| 126 | "options", OPT_PROTO_NO_PASSWORD, | |
| 127 | NULL); | |
| 128 | } |