pidgin/pidgin

501ed6c0631e
Parents 4eeb75c4ed61
Children 33978dc8ef6f
Imgupload: initial implementation and basic hooks
--- a/libpurple/plugin.c Mon May 19 09:31:48 2014 +0200
+++ b/libpurple/plugin.c Mon May 19 10:01:26 2014 +0200
@@ -184,12 +184,32 @@
plugin->native_plugin = native;
plugin->path = g_strdup(path);
+ plugin->extra_data = g_hash_table_new_full(g_str_hash, g_str_equal,
+ g_free, NULL);
PURPLE_DBUS_REGISTER_POINTER(plugin, PurplePlugin);
return plugin;
}
+void
+purple_plugin_set_data(PurplePlugin *plugin, const gchar *key, gpointer value)
+{
+ g_return_if_fail(plugin != NULL);
+ g_return_if_fail(plugin->extra_data != NULL);
+
+ g_hash_table_insert(plugin->extra_data, g_strdup(key), value);
+}
+
+gpointer
+purple_plugin_get_data(PurplePlugin *plugin, const gchar *key)
+{
+ g_return_val_if_fail(plugin != NULL, NULL);
+ g_return_val_if_fail(plugin->extra_data != NULL, NULL);
+
+ return g_hash_table_lookup(plugin->extra_data, key);
+}
+
PurplePlugin *
purple_plugin_probe(const char *filename)
{
@@ -876,6 +896,7 @@
g_free(plugin->path);
g_free(plugin->error);
+ g_hash_table_destroy(plugin->extra_data);
PURPLE_DBUS_UNREGISTER_POINTER(plugin);
--- a/libpurple/plugin.h Mon May 19 09:31:48 2014 +0200
+++ b/libpurple/plugin.h Mon May 19 10:01:26 2014 +0200
@@ -187,6 +187,7 @@
gboolean unloadable;
GList *dependent_plugins;
gpointer ui_data;
+ GHashTable *extra_data;
/*< private >*/
void (*_purple_reserved1)(void);
@@ -297,6 +298,29 @@
PurplePlugin *purple_plugin_new(gboolean native, const char *path);
/**
+ * purple_plugin_set_data:
+ * @plugin: The plugin.
+ * @key: The data key.
+ * @value: The data to set.
+ *
+ * Sets extra data for particular plugin.
+ */
+void
+purple_plugin_set_data(PurplePlugin *plugin, const gchar *key, gpointer value);
+
+/**
+ * purple_plugin_get_data:
+ * @plugin: The plugin.
+ * @key: The data key.
+ *
+ * Gets extra data for particular plugin.
+ *
+ * Returns: data set previously with #purple_plugin_set_data.
+ */
+gpointer
+purple_plugin_get_data(PurplePlugin *plugin, const gchar *key);
+
+/**
* purple_plugin_probe:
* @filename: The plugin's filename.
*
--- a/pidgin/plugins/Makefile.am Mon May 19 09:31:48 2014 +0200
+++ b/pidgin/plugins/Makefile.am Mon May 19 10:01:26 2014 +0200
@@ -43,6 +43,7 @@
gtkbuddynote_la_LDFLAGS = -module @PLUGIN_LDFLAGS@
history_la_LDFLAGS = -module @PLUGIN_LDFLAGS@
iconaway_la_LDFLAGS = -module @PLUGIN_LDFLAGS@
+imgupload_la_LDFLAGS = -module @PLUGIN_LDFLAGS@
markerline_la_LDFLAGS = -module @PLUGIN_LDFLAGS@
notify_la_LDFLAGS = -module @PLUGIN_LDFLAGS@
relnot_la_LDFLAGS = -module @PLUGIN_LDFLAGS@
@@ -61,6 +62,7 @@
gtkbuddynote.la \
history.la \
iconaway.la \
+ imgupload.la \
markerline.la \
notify.la \
relnot.la \
@@ -85,6 +87,7 @@
gtkbuddynote_la_SOURCES = gtkbuddynote.c
history_la_SOURCES = history.c
iconaway_la_SOURCES = iconaway.c
+imgupload_la_SOURCES = imgupload.c
markerline_la_SOURCES = markerline.c
notify_la_SOURCES = notify.c
relnot_la_SOURCES = relnot.c
@@ -102,6 +105,7 @@
gtkbuddynote_la_LIBADD = @PIDGIN_LIBS@
history_la_LIBADD = @PIDGIN_LIBS@
iconaway_la_LIBADD = @PIDGIN_LIBS@
+imgupload_la_LIBADD = @PIDGIN_LIBS@
markerline_la_LIBADD = @PIDGIN_LIBS@ $(WEBKIT_LIBS)
notify_la_LIBADD = @PIDGIN_LIBS@
relnot_la_LIBADD = @PIDGIN_LIBS@
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/pidgin/plugins/imgupload.c Mon May 19 10:01:26 2014 +0200
@@ -0,0 +1,140 @@
+/*
+ * Image Upload - an inline images implementation for protocols without
+ * support for such feature.
+ *
+ * Copyright (C) 2014, Tomasz Wasilczyk <twasilczyk@pidgin.im>
+ *
+ * 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 02111-1301 USA
+ */
+
+#include "internal.h"
+
+#include "debug.h"
+#include "glibcompat.h"
+#include "version.h"
+
+#include "gtk3compat.h"
+#include "gtkconv.h"
+#include "gtkplugin.h"
+#include "gtkutils.h"
+#include "gtkwebviewtoolbar.h"
+#include "pidginstock.h"
+
+/******************************************************************************
+ *
+ ******************************************************************************/
+
+
+/******************************************************************************
+ * Plugin setup
+ ******************************************************************************/
+
+static void
+imgup_prpl_init(PurplePlugin *prpl)
+{
+ PurplePluginProtocolInfo *prpl_info;
+
+ prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl);
+
+ if (prpl_info->options & OPT_PROTO_IM_IMAGE)
+ return;
+
+ purple_plugin_set_data(prpl, "imgupload-set", GINT_TO_POINTER(TRUE));
+ prpl_info->options |= OPT_PROTO_IM_IMAGE;
+}
+
+static void
+imgup_prpl_uninit(PurplePlugin *prpl)
+{
+ PurplePluginProtocolInfo *prpl_info;
+
+ if (!purple_plugin_get_data(prpl, "imgupload-set"))
+ return;
+
+ prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl);
+ prpl_info->options &= ~OPT_PROTO_IM_IMAGE;
+
+ purple_plugin_set_data(prpl, "imgupload-set", NULL);
+}
+
+static gboolean
+imgup_plugin_load(PurplePlugin *plugin)
+{
+ GList *it;
+
+ it = purple_plugins_get_protocols();
+ for (; it; it = g_list_next(it)) {
+ PurplePlugin *prpl = it->data;
+ imgup_prpl_init(prpl);
+ }
+
+ return TRUE;
+}
+
+static gboolean
+imgup_plugin_unload(PurplePlugin *plugin)
+{
+ GList *it;
+
+ it = purple_plugins_get_protocols();
+ for (; it; it = g_list_next(it)) {
+ PurplePlugin *prpl = it->data;
+ imgup_prpl_uninit(prpl);
+ }
+
+ return TRUE;
+}
+
+static PurplePluginInfo imgup_info =
+{
+ PURPLE_PLUGIN_MAGIC,
+ PURPLE_MAJOR_VERSION,
+ PURPLE_MINOR_VERSION,
+ PURPLE_PLUGIN_STANDARD,
+ PIDGIN_PLUGIN_TYPE,
+ 0,
+ NULL,
+ PURPLE_PRIORITY_DEFAULT,
+ "gtk-imgupload",
+ N_("Image Upload"),
+ DISPLAY_VERSION,
+ N_("Inline images implementation for protocols without such feature."),
+ N_("Adds inline images support for protocols lacking this feature by "
+ "uploading them to the external service."),
+ "Tomasz Wasilczyk <twasilczyk@pidgin.im>",
+ PURPLE_WEBSITE,
+ imgup_plugin_load,
+ imgup_plugin_unload,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+
+ /* padding */
+ NULL, NULL, NULL, NULL
+};
+
+static void
+imgup_init_plugin(PurplePlugin *plugin)
+{
+#if 0
+ purple_prefs_add_none("/plugins");
+ purple_prefs_add_none("/plugins/gtk");
+ purple_prefs_add_none("/plugins/gtk/imgupload");
+#endif
+}
+
+PURPLE_INIT_PLUGIN(imgupload, imgup_init_plugin, imgup_info)