/dev/twasilczyk/imgupload: 501ed6c0631e: Imgupload: initial impl...

Tomasz Wasilczyk <[email protected]>
Newsgroups gmane.comp.gnome.gaim.cvs
Message-ID <[email protected]>
Changeset: 501ed6c0631eb8a0c7f047423f5d5d5883d538f0
Author:	 Tomasz Wasilczyk <[email protected]>
Date:	 2014-05-19 10:01 +0200
Branch:	 default
URL: https://hg.pidgin.im/dev/twasilczyk/imgupload/rev/501ed6c0631e

Description:

Imgupload: initial implementation and basic hooks

diffstat:

 libpurple/plugin.c         |   21 ++++++
 libpurple/plugin.h         |   24 +++++++
 pidgin/plugins/Makefile.am |    4 +
 pidgin/plugins/imgupload.c |  140 +++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 189 insertions(+), 0 deletions(-)

diffs (265 lines):

diff --git a/libpurple/plugin.c b/libpurple/plugin.c
--- a/libpurple/plugin.c
+++ b/libpurple/plugin.c
@@ -184,12 +184,32 @@ purple_plugin_new(gboolean native, const
 
 	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 @@ purple_plugin_destroy(PurplePlugin *plug
 
 	g_free(plugin->path);
 	g_free(plugin->error);
+	g_hash_table_destroy(plugin->extra_data);
 
 	PURPLE_DBUS_UNREGISTER_POINTER(plugin);
 
diff --git a/libpurple/plugin.h b/libpurple/plugin.h
--- a/libpurple/plugin.h
+++ b/libpurple/plugin.h
@@ -187,6 +187,7 @@ struct _PurplePlugin
 	gboolean unloadable;
 	GList *dependent_plugins;
 	gpointer ui_data;
+	GHashTable *extra_data;
 
 	/*< private >*/
 	void (*_purple_reserved1)(void);
@@ -297,6 +298,29 @@ GType purple_plugin_get_type(void);
 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.
  *
diff --git a/pidgin/plugins/Makefile.am b/pidgin/plugins/Makefile.am
--- a/pidgin/plugins/Makefile.am
+++ b/pidgin/plugins/Makefile.am
@@ -43,6 +43,7 @@ gtk_signals_test_la_LDFLAGS = -module @P
 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 @@ plugin_LTLIBRARIES = \
 	gtkbuddynote.la     \
 	history.la          \
 	iconaway.la         \
+	imgupload.la        \
 	markerline.la       \
 	notify.la           \
 	relnot.la           \
@@ -85,6 +87,7 @@ gtk_signals_test_la_SOURCES = gtk-signal
 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 @@ gtk_signals_test_la_LIBADD  = @PIDGIN_LI
 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@
diff --git a/pidgin/plugins/imgupload.c b/pidgin/plugins/imgupload.c
new file mode 100644
--- /dev/null
+++ b/pidgin/plugins/imgupload.c
@@ -0,0 +1,140 @@
+/*
+ * Image Upload - an inline images implementation for protocols without
+ * support for such feature.
+ *
+ * Copyright (C) 2014, Tomasz Wasilczyk <[email protected]>
+ *
+ * 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 <[email protected]>",
+	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)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.