grim/purple-spasm

port *back* to purple2

2020-04-19, Gary Kramlich
78292b8a66a6
Parents 42059653e981
Children a1e6bcaf27c3
port *back* to purple2
--- a/meson.build Sun Apr 19 05:11:17 2020 -0500
+++ b/meson.build Sun Apr 19 06:50:19 2020 -0500
@@ -5,16 +5,17 @@
)
add_project_arguments(
- '-DPREFIX="@0@"'.format(get_option('prefix')),
+ '-DGETTEXT_PACKAGE="spasm"',
'-DLIBDIR="@0@"'.format(get_option('libdir')),
- '-DPLUGIN_VERSION="@0@"'.format(meson.project_version()),
+ '-DPREFIX="@0@"'.format(get_option('prefix')),
+ '-DSPASM_VERSION="@0@"'.format(meson.project_version()),
language : 'c'
)
JSON_GLIB = dependency('json-glib-1.0')
SOUP = dependency('libsoup-2.4')
-PURPLE3 = dependency('purple-3', version: '>=3.0.0')
+PURPLE = dependency('purple', version: '>=2.13.0')
subdir('icons')
subdir('src')
--- a/src/meson.build Sun Apr 19 05:11:17 2020 -0500
+++ b/src/meson.build Sun Apr 19 06:50:19 2020 -0500
@@ -1,18 +1,23 @@
SOURCES = [
- 'spasm.c',
'spasm-account.c',
+ 'spasm-account.h',
'spasm-chat.c',
- 'spasm-protocol.c',
+ 'spasm-chat.h',
+ 'spasm-const.h',
+ 'spasm-plugin.c',
'spasm-rest.c',
+ 'spasm-rest.h',
'spasm-user.c',
+ 'spasm-user.h',
+ 'spasm.h',
]
shared_library(
- meson.project_name() + '3',
+ meson.project_name(),
SOURCES,
name_prefix: '',
- dependencies: [PURPLE3, JSON_GLIB, SOUP],
+ dependencies: [PURPLE, JSON_GLIB, SOUP],
install: true,
- install_dir: join_paths(get_option('libdir'), 'purple3'),
+ install_dir: join_paths(get_option('libdir'), 'purple'),
)
--- a/src/spasm-account.c Sun Apr 19 05:11:17 2020 -0500
+++ b/src/spasm-account.c Sun Apr 19 06:50:19 2020 -0500
@@ -173,12 +173,7 @@
g_error_free(error);
- purple_connection_error(
- connection,
- PURPLE_CONNECTION_ERROR_OTHER_ERROR,
- err_msg
- );
-
+ purple_connection_error(connection, err_msg);
g_free(err_msg);
return;
@@ -191,17 +186,13 @@
static void
spasm_access_token_input_cb(gpointer data, const gchar *access_token) {
PurpleAccount *account = NULL;
- PurpleConnection *connection = NULL;
SpasmAccount *sa = SPASM_ACCOUNT(data);
account = spasm_account_get_account(sa);
purple_account_set_remember_password(account, TRUE);
spasm_account_set_access_token(sa, access_token);
- purple_account_set_password(account, access_token, NULL, NULL);
-
- connection = spasm_account_get_connection(sa);
- purple_connection_update_progress(connection, "Verifying", 2, 3);
+ purple_account_set_password(account, access_token);
spasm_get_user(sa, spasm_login_test_cb, NULL);
}
@@ -212,7 +203,6 @@
purple_connection_error(
spasm_account_get_connection(sa),
- PURPLE_CONNECTION_ERROR_OTHER_ERROR,
"User cancelled authorization"
);
@@ -223,19 +213,12 @@
spasm_oauth_login(SpasmAccount *sa) {
PurpleAccount *account = NULL;
PurpleConnection *connection = NULL;
- PurpleRequestCommonParameters *cpar = NULL;
gchar *state = NULL, *uri = NULL;
const gchar *username = NULL;
account = spasm_account_get_account(sa);
connection = purple_account_get_connection(account);
- purple_connection_update_progress(
- connection,
- "Authenticating",
- 0,
- 1
- );
username = purple_account_get_username(account);
state = g_strdup_printf("%s,%s", SPASM_PLUGIN_ID, username);
@@ -253,8 +236,6 @@
purple_notify_uri(connection, uri);
g_free(uri);
- cpar = purple_request_cpar_from_account(account);
-
purple_request_input(
connection,
"Access Token",
@@ -266,7 +247,9 @@
NULL,
"OK", G_CALLBACK(spasm_access_token_input_cb),
"Cancel", G_CALLBACK(spasm_access_token_cancel_cb),
- cpar,
+ account,
+ NULL,
+ NULL,
sa
);
}
@@ -383,12 +366,21 @@
return sa->twitter_connected;
}
-static void
-spasm_account_login_got_password(PurpleAccount *account, const gchar *password,
- GError *error, gpointer data)
-{
- SpasmAccount *sa = SPASM_ACCOUNT(data);
+void
+spasm_account_login(PurpleAccount *account) {
+ PurpleConnection *pc = NULL;
+ SpasmAccount *sa = NULL;
+ const gchar *password = NULL;
+
+ pc = purple_account_get_connection(account);
+ sa = spasm_account_new(account, pc);
+ purple_connection_set_protocol_data(pc, sa);
+
+ purple_connection_set_state(pc, PURPLE_CONNECTING);
+
+ /* try to load the password */
+ password = purple_account_get_password(account);
if(password != NULL) {
spasm_account_set_access_token(sa, password);
spasm_get_user(sa, spasm_login_test_cb, NULL);
@@ -397,19 +389,3 @@
}
}
-void
-spasm_account_login(PurpleAccount *account) {
- PurpleConnection *pc = NULL;
- SpasmAccount *sa = NULL;
-
- pc = purple_account_get_connection(account);
-
- sa = spasm_account_new(account, pc);
- purple_connection_set_protocol_data(pc, sa);
-
- purple_connection_set_state(pc, PURPLE_CONNECTION_CONNECTING);
-
- /* try to load the password */
- purple_account_get_password(account, spasm_account_login_got_password, sa);
-}
-
--- a/src/spasm-chat.c Sun Apr 19 05:11:17 2020 -0500
+++ b/src/spasm-chat.c Sun Apr 19 06:50:19 2020 -0500
@@ -20,6 +20,8 @@
#include "spasm-chat.h"
#include "spasm-const.h"
+#include <glib/gi18n-lib.h>
+
#include <stdarg.h>
#include <purple.h>
@@ -69,19 +71,11 @@
PurpleConnection *purple_connection = spasm_account_get_connection(chat->sa);
if(error) {
- purple_connection_error(
- purple_connection,
- PURPLE_CONNECTION_ERROR_OTHER_ERROR,
- error->message
- );
+ purple_connection_error(purple_connection, error->message);
g_error_free(error);
} else {
- purple_connection_error(
- purple_connection,
- PURPLE_CONNECTION_ERROR_OTHER_ERROR,
- "unknown error"
- );
+ purple_connection_error(purple_connection, _("unknown error"));
}
return;
@@ -137,12 +131,7 @@
error_msg = g_strdup_printf("spasm server closed connection");
}
- purple_connection_error(
- spasm_account_get_connection(chat->sa),
- PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
- error_msg
- );
-
+ purple_connection_error(spasm_account_get_connection(chat->sa), error_msg);
g_free(error_msg);
return;
@@ -189,19 +178,10 @@
if(error) {
g_prefix_error(&error, "failed to connect: ");
- purple_connection_error(
- purple_connection,
- PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
- error->message
- );
-
+ purple_connection_error(purple_connection, error->message);
g_error_free(error);
} else {
- purple_connection_error(
- purple_connection,
- PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
- "unknown error"
- );
+ purple_connection_error(purple_connection, _("unknown error"));
}
return;
@@ -223,7 +203,7 @@
spasm_account_get_name(chat->sa)
);
- purple_connection_set_state(purple_connection, PURPLE_CONNECTION_CONNECTED);
+ purple_connection_set_state(purple_connection, PURPLE_CONNECTED);
chat->input_stream = g_data_input_stream_new(
g_io_stream_get_input_stream(G_IO_STREAM(chat->socket_connection))
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/spasm-plugin.c Sun Apr 19 06:50:19 2020 -0500
@@ -0,0 +1,108 @@
+/*
+ * Spasm - A Twitch Protocol Plugin
+ * Copyright (C) 2017-2020 Gary Kramlich <grim@reaperworld.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include <glib.h>
+#include <glib/gi18n-lib.h>
+
+#include <purple.h>
+
+#include "spasm-account.h"
+#include "spasm-const.h"
+
+/******************************************************************************
+ * Simple Protocol Functions
+ *****************************************************************************/
+static GList *
+spasm_status_types(PurpleAccount *account) {
+ PurpleStatusType *type = NULL;
+ GList *types = NULL;
+
+ type = purple_status_type_new(PURPLE_STATUS_AVAILABLE, NULL, NULL, TRUE);
+ types = g_list_append(types, type);
+
+ type = purple_status_type_new(PURPLE_STATUS_OFFLINE, NULL, NULL, TRUE);
+ types = g_list_append(types, type);
+
+ return types;
+}
+
+static const gchar *
+spasm_list_icon(PurpleAccount *account, PurpleBuddy *buddy) {
+ return "spasm";
+}
+
+static void
+spasm_close(PurpleConnection *connection) {
+}
+
+/******************************************************************************
+ * Purple2 Plugin Interface
+ *****************************************************************************/
+static gboolean
+spasm_plugin_load(PurplePlugin *plugin) {
+ return TRUE;
+}
+
+static gboolean
+spasm_plugin_unload(PurplePlugin *plugin) {
+ return TRUE;
+}
+
+static void
+spasm_plugin_init(PurplePlugin *plugin) {
+}
+
+static PurplePluginProtocolInfo spasm_protocol_info = {
+ .options = OPT_PROTO_NO_PASSWORD,
+
+ .login = spasm_account_login,
+ .close = spasm_close,
+ .list_icon = spasm_list_icon,
+
+ .status_types = spasm_status_types,
+
+ // chat stuff
+#if 0
+ .chat_info = spasm_chat_service_info,
+ .chat_info_defaults = spasm_chat_service_info_default,
+ .join_chat = spasm_chat_service_join,
+ .get_chat_name = spasm_chat_service_name,
+ .chat_leave = spasm_chat_service_leave,
+ .chat_send = spasm_chat_service_send,
+ .set_chat_topic = spasm_chat_service_set_topic,
+#endif
+};
+
+static PurplePluginInfo info = {
+ .magic = PURPLE_PLUGIN_MAGIC,
+ .major_version = PURPLE_MAJOR_VERSION,
+ .minor_version = PURPLE_MINOR_VERSION,
+ .type = PURPLE_PLUGIN_PROTOCOL,
+ .id = SPASM_PLUGIN_ID,
+ .name = N_("Twitch.tv"),
+ .version = SPASM_VERSION,
+ .author = "Gary Kramlich <grim@reaperworld.com>",
+ .homepage = "https://keep.imfreedom.org/grim/purple-spasm",
+ .load = spasm_plugin_load,
+ .unload = spasm_plugin_unload,
+ .extra_info = &spasm_protocol_info,
+};
+
+PURPLE_INIT_PLUGIN(spasm, spasm_plugin_init, info);
+
--- a/src/spasm.c Sun Apr 19 05:11:17 2020 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,105 +0,0 @@
-/*
- * Spasm - A Twitch Protocol Plugin
- * Copyright (C) 2017-2019 Gary Kramlich <grim@reaperworld.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-#include <glib.h>
-
-#include <purple.h>
-
-#include "spasm-account.h"
-#include "spasm-const.h"
-#include "spasm-protocol.h"
-
-/******************************************************************************
- * Globals
- *****************************************************************************/
-static PurpleProtocol *spasm = NULL;
-
-/******************************************************************************
- * Implementations
- *****************************************************************************/
-
-/******************************************************************************
- * Plugin Stuff
- *****************************************************************************/
-#if 0
-static PurplePluginProtocolInfo prpl_info = {
- .struct_size = sizeof(PurplePluginProtocolInfo),
-
- .options = OPT_PROTO_NO_PASSWORD,
-
- .login = purple_spasm_account_login,
- .close = _purple_spasm_close,
- .list_icon = _purple_spasm_list_icon,
-
- .status_types = _purple_spasm_get_status_types,
- .set_status = _purple_spasm_set_status,
-
- // chat stuff
- .chat_info = purple_spasm_chat_service_info,
- .chat_info_defaults = purple_spasm_chat_service_info_default,
- .join_chat = purple_spasm_chat_service_join,
- .get_chat_name = purple_spasm_chat_service_name,
- .chat_leave = purple_spasm_chat_service_leave,
- .chat_send = purple_spasm_chat_service_send,
- .set_chat_topic = purple_spasm_chat_service_set_topic,
-};
-#endif
-
-/******************************************************************************
- * GPlugin Interface
- *****************************************************************************/
-G_MODULE_EXPORT GPluginPluginInfo *
-gplugin_query(GError **error) {
- const gchar * const authors [] = { "Gary Kramlich <grim@reaperworld.com>", NULL };
-
- return GPLUGIN_PLUGIN_INFO(purple_plugin_info_new(
- "id", SPASM_PLUGIN_ID,
- "name", "Twitch",
- "version", PLUGIN_VERSION,
- "abi-version", PURPLE_ABI_VERSION,
- "flags", PURPLE_PLUGIN_INFO_FLAGS_INTERNAL | PURPLE_PLUGIN_INFO_FLAGS_AUTO_LOAD,
-
- "summary", "Twitch.tv Protocol Plugin",
- "description", "Implements the Twitch.tv chat protocol",
- "authors", authors,
- "website", "https://bitbucket.org/rw_grim/purple-spasm",
-
- NULL
- ));
-}
-
-G_MODULE_EXPORT gboolean
-gplugin_load(GPluginPlugin *plugin, GError **error) {
- spasm_protocol_register(G_TYPE_MODULE(plugin));
-
- spasm = purple_protocols_add(SPASM_TYPE_PROTOCOL, error);
- if(spasm == NULL) {
- g_warning("instance was null");
- return FALSE;
- }
-
- return TRUE;
-}
-
-G_MODULE_EXPORT gboolean
-gplugin_unload(GPluginPlugin *plugin, GError **error) {
- spasm = NULL;
-
- return TRUE;
-}