org.guifications.plugins: 3e52de5a8b56711393f126806c660aad6ba74895

grim at guifications.org grim at guifications.org
Thu Jul 3 02:40:05 CDT 2008


-----------------------------------------------------------------
Revision: 3e52de5a8b56711393f126806c660aad6ba74895
Ancestor: 960dfa1c946a9a527972a1707652df71b541023c
Author: grim at guifications.org
Date: 2008-07-03T07:39:46
Branch: org.guifications.plugins

Modified files:
        configure.ac splitter/Makefile.am splitter/plugins.cfg
        splitter/splitter.c

ChangeLog: 

Fixed up the message splitter plugin to work and not depend on gdk...

Theres some hackery here though.  On !win32, we depend on cairo, which should be alright anyways, however this needs to be tested on windows.

Also, this still needs a lot of cleanup, but it does work.


-----------------------------------------------------------------
This revision's diffstat output:
 configure.ac         |   33 ++++++++++
 splitter/Makefile.am |    4 +
 splitter/plugins.cfg |    4 -
 splitter/splitter.c  |  160 ++++++++++++++++++++++++++++++---------------------
 4 files changed, 133 insertions(+), 68 deletions(-)
-------------- next part --------------
============================================================
--- configure.ac	d17712f29cbe874f076605a88cec0965be961148
+++ configure.ac	5158b9bd6fd8f45e7b6ce2991994a3fb41c7bd9c
@@ -192,7 +192,7 @@ dnl ####################################
 AC_SUBST(FINCH_PIXMAPSDIR)
 
 dnl #######################################################################
-dnl # check for gtk and other dependencies
+dnl # check for gtk
 dnl #######################################################################
 HAVE_GLIB="no"
 PKG_CHECK_MODULES(GLIB, [glib-2.0], HAVE_GLIB="yes", HAVE_GLIB="no")
@@ -212,6 +212,9 @@ AC_SUBST(GTK_LIBS)
 AC_SUBST(GTK_CFLAGS)
 AC_SUBST(GTK_LIBS)
 
+dnl #######################################################################
+dnl # check for gnt
+dnl #######################################################################
 HAVE_GNT="no"
 GNT_CFLAGS=""
 GNT_LIBS=""
@@ -220,6 +223,34 @@ dnl ####################################
 AC_SUBST(GNT_CFLAGS)
 
 dnl #######################################################################
+dnl # check for pango
+dnl #######################################################################
+HAVE_PANGO="no"
+PANGO_CFLAGS=""
+PANGO_LIBS=""
+PKG_CHECK_MODULES(PANGO, [pango], HAVE_PANGO="yes", HAVE_PANGO="no")
+AC_SUBST(PANGO_CFLAGS)
+AC_SUBST(PANGO_CFLAGS)
+
+if test x"$HAVE_PANGO" = x"yes" ; then
+	DEPENDENCIES="$DEPENDENCIES,pango"
+fi
+
+dnl #######################################################################
+dnl # check for cairo
+dnl #######################################################################
+HAVE_CAIRO="no"
+CAIRO_CFLAGS=""
+CAIRO_LIBS=""
+PKG_CHECK_MODULES(CAIRO, [cairo], HAVE_CAIRO="yes", HAVE_CAIRO="no")
+AC_SUBST(CAIRO_CFLAGS)
+AC_SUBST(CAIRO_CFLAGS)
+
+if test x"$HAVE_CAIRO" = x"yes" ; then
+	DEPENDENCIES="$DEPENDENCIES,cairo"
+fi
+
+dnl #######################################################################
 dnl # Check for talkfilters
 dnl #######################################################################
 AC_CHECK_HEADER(talkfilters.h, HAVE_TALKFILTERS=yes, AC_MSG_WARN([
============================================================
--- splitter/Makefile.am	3408696cf7538f4b164497e28341025d22b80d91
+++ splitter/Makefile.am	42409c5aa3e66b87ba38326978c37c6292147299
@@ -14,7 +14,9 @@ splitter_la_LIBADD = \
 	splitter.c
 
 splitter_la_LIBADD = \
+	$(CAIRO_LIBS) \
 	$(GLIB_LIBS) \
+	$(PANGO_LIBS) \
 	$(PURPLE_LIBS)
 
 endif
@@ -23,6 +25,8 @@ AM_CPPFLAGS = \
 	-DLIBDIR=\"$(PURPLE_LIBDIR)\" \
 	-DDATADIR=\"$(PURPLE_DATADIR)\" \
 	-DPIXMAPSDIR=\"$(PURPLE_PIXMAPSDIR)\" \
+	$(CAIRO_CFLAGS) \
 	$(DEBUG_CFLAGS) \
+	$(PANGO_CFLAGS) \
 	$(PURPLE_CFLAGS)
 
============================================================
--- splitter/plugins.cfg	a00f727af2d520a33910c0ccfa6212b3e757557b
+++ splitter/plugins.cfg	8a184deb090439b6fce374a4b55633c04e71fedd
@@ -1,6 +1,6 @@
 [Message Splitter]
-type=incomplete
-depends=purple pango
+type=default
+depends=purple pango cairo
 provides=splitter
 summary=Splits sent messages into smaller ones of a specified size
 description=%(summary)s
============================================================
--- splitter/splitter.c	d152b0f1056dd7c274f3869c19c1878b170869b5
+++ splitter/splitter.c	b58eea24a0263e60273b814c788ec11694728b42
@@ -21,24 +21,22 @@
  * 02111-1307, USA.
  */
 
-#define GETTEXT_PACKAGE "gtk20"
-#include <glib/gi18n-lib.h>
+#include "../common/pp_internal.h"
 
-#include <gtk/gtk.h>
+#include <pango/pango.h>
 
+#ifndef _WIN32
+# include <pango/pangocairo.h>
+#endif
+
 #include <string.h>
 #include <errno.h>
 
-#ifndef PURPLE_PLUGINS
-#define PURPLE_PLUGINS
-#endif
-
 #include <debug.h>
 #include <notify.h>
 #include <version.h>
 #include <util.h>
 
-#define WEBSITE   "http://ikebo.hypermart.net/"
 #define PLUGIN_ID "core-ike-splitter"
 
 /* grr */
@@ -64,21 +62,21 @@ typedef struct
 	PurpleConversationType type;
 	union {
 		char *receiver; /* IM username */
-		int  id;        /* chat ID */
+		gint id;        /* chat ID */
 	};
 } message_to_conv;
 
 typedef struct {
-	int start, end;
+	gint start;
+	gint end;
 } message_slice;
 
 /* plugin preference variables */
 static gint current_split_size;
 
-
 /* initialize preferences dialog */
-static PurplePluginPrefFrame *get_plugin_pref_frame(PurplePlugin *plugin)
-{
+static PurplePluginPrefFrame *
+get_plugin_pref_frame(PurplePlugin *plugin) {
 	PurplePluginPrefFrame *frame;
 	PurplePluginPref      *ppref;
 
@@ -113,13 +111,15 @@ static PurplePluginPrefFrame *get_plugin
  *
  * taken from conversation.c with signal emission removed.
  */
-static void splitter_common_send(PurpleConversation *conv, const char *message, PurpleMessageFlags msgflags)
+static void
+splitter_common_send(PurpleConversation *conv, const char *message,
+                     PurpleMessageFlags msgflags)
 {
 	PurpleConversationType type;
 	PurpleAccount *account;
 	PurpleConnection *gc;
 	char *displayed = NULL, *sent = NULL;
-	int err = 0;
+	gint err = 0;
 
 	if (strlen(message) == 0)
 		return;
@@ -206,8 +206,8 @@ static void splitter_common_send(PurpleC
 }
 
 /* a timer based callback function that sends the next message in the queue */
-static gboolean send_message_timer_cb( message_to_conv *msg_to_conv )
-{
+static gboolean
+send_message_timer_cb( message_to_conv *msg_to_conv ) {
 	PurpleAccount *account;
 	PurpleConversation *conv;
 	gchar *msg;
@@ -258,9 +258,31 @@ static gboolean send_message_timer_cb( m
 	}
 }
 
+/* Create/get a pango context
+ *
+ * On windows we use the win32 context creator, on everything else we
+ * use the cairo one.
+ */
+PangoContext *
+splitter_create_pango_context(void) {
+#ifdef _WIN32
+	return pango_win32_get_context();
+#else
+	PangoContext *context = NULL;
+	PangoFontMap *fontmap = pango_cairo_font_map_get_default();
+
+	context =
+		pango_cairo_font_map_create_context(PANGO_CAIRO_FONT_MAP(fontmap));
+
+	g_object_unref(G_OBJECT(fontmap));
+
+	return context;
+#endif
+}
+
 /* finds the first line-breakable character backwards starting from a[last]  */
-static int find_last_break(PangoLogAttr *a, int last)
-{
+static gint
+find_last_break(PangoLogAttr *a, int last) {
 	for(; last > 0; last-- )
 		if( a[last].is_line_break == 1)
 			break;
@@ -271,12 +293,12 @@ static int find_last_break(PangoLogAttr 
 /* uses Pango to find all possible line break locations in a message and returns
    a PangoLogAttr array which maps to each byte of the message of length
    one larger than the message.  This must be g_free()'d */
-static PangoLogAttr* find_all_breaks(const char *message)
-{
+static PangoLogAttr *
+find_all_breaks(const char *message) {
 	PangoContext *context;
 	PangoLogAttr *a;
 	GList *list;
-	int len, n_attr;
+	gint len, n_attr;
 
 	g_return_val_if_fail(message != NULL, NULL);
 
@@ -285,7 +307,8 @@ static PangoLogAttr* find_all_breaks(con
 	a = g_new0(PangoLogAttr, n_attr);
 
 	/* init Pango */
-	context = gdk_pango_context_get();
+	context = splitter_create_pango_context();
+
 	g_return_val_if_fail(context != NULL, NULL);
 
 	list = pango_itemize(context, message, 0, len, NULL, NULL);
@@ -298,9 +321,9 @@ static PangoLogAttr* find_all_breaks(con
 
 /* return a queue of message slices from a plain text message based on current_split_size using
    Pango to determine possible line break locations */
-static GQueue* get_message_slices(const char *message)
-{
-	int current_break_start, last_break_start, break_pos, len;
+static GQueue *
+get_message_slices(const char *message) {
+	gint current_break_start, last_break_start, break_pos, len;
 	message_slice *slice;
 	PangoLogAttr *a;
 	GQueue *q;
@@ -348,12 +371,12 @@ static GQueue* get_message_slices(const 
 /* takes a message, splits it up based on whitespace (ignoring HTML formatting),
    requests HTMLized slices of the splits, and returns a queue of them.  The
    messages and the queue must be freed */
-static GQueue* create_message_queue(const char *message)
-{
+static GQueue *
+create_message_queue(const char *message) {
 	GQueue *slices, *messages;
 	message_slice *slice;
 	char *stripped_message, *msg;
-	int stripped_len;
+	gint stripped_len;
 
 	stripped_message = purple_markup_strip_html(message);
 	stripped_len = strlen(stripped_message);
@@ -381,8 +404,8 @@ static GQueue* create_message_queue(cons
 }
 
 /* create message queue and prepare timer callbacks */
-static void split_and_send(message_to_conv *msg_to_conv, const char **message)
-{
+static void
+split_and_send(message_to_conv *msg_to_conv, const char **message) {
 	gint message_delay_ms;
 
 	g_return_if_fail( msg_to_conv != NULL );
@@ -413,8 +436,8 @@ static void split_and_send(message_to_co
 }
 
 /* initialize a chat message to potentially be split */
-static void sending_chat_msg_cb(PurpleAccount *account, const char **message, int id)
-{
+static void
+sending_chat_msg_cb(PurpleAccount *account, const char **message, int id) {
 	message_to_conv *msg_to_conv;
 
 	purple_debug(PURPLE_DEBUG_MISC, "purple-splitter", "splitter plugin invoked\n");
@@ -435,8 +458,9 @@ static void sending_chat_msg_cb(PurpleAc
 }
 
 /* initialize an IM message to potentially be split */
-static void sending_im_msg_cb(PurpleAccount *account, const char *receiver,
-						    const char **message)
+static void
+sending_im_msg_cb(PurpleAccount *account, const char *receiver,
+                  const char **message)
 {
 	message_to_conv *msg_to_conv;
 
@@ -459,8 +483,8 @@ static void sending_im_msg_cb(PurpleAcco
 }
 
 /* register "sending" message signal callback */
-static gboolean plugin_load(PurplePlugin *plugin)
-{
+static gboolean
+plugin_load(PurplePlugin *plugin) {
 	purple_signal_connect(purple_conversations_get_handle(),
 			    "sending-im-msg",
 			    plugin,
@@ -476,8 +500,8 @@ static gboolean plugin_load(PurplePlugin
 }
 
 
-static gboolean plugin_unload(PurplePlugin *plugin)
-{
+static gboolean
+plugin_unload(PurplePlugin *plugin) {
 	return TRUE;
 }
 
@@ -485,46 +509,52 @@ static PurplePluginUiInfo prefs_info = {
 	get_plugin_pref_frame, 0, NULL, NULL, NULL, NULL, NULL
 };
 
-static PurplePluginInfo info =
-{
+static PurplePluginInfo info = {
 	PURPLE_PLUGIN_MAGIC,
 	PURPLE_MAJOR_VERSION,
 	PURPLE_MINOR_VERSION,
-	PURPLE_PLUGIN_STANDARD,                             /**< type           */
-	NULL,                                             /**< ui_requirement */
-	0,                                                /**< flags          */
-	NULL,                                             /**< dependencies   */
-	PURPLE_PRIORITY_DEFAULT,                            /**< priority       */
+	PURPLE_PLUGIN_STANDARD,
+	NULL,
+	0,
+	NULL,
+	PURPLE_PRIORITY_DEFAULT,
 
-	PLUGIN_ID,                                        /**< id             */
-	N_("Message Splitter"),                           /**< name           */
-	VERSION,                                          /**< version        */
-							  /**  summary        */
-	N_("Splits a large outgoing message into smaller "
-	   "messages of a specified size."),
-							  /**  description    */
-	N_("Splits a large outgoing message into smaller "
-	   "messages of a specified size."),
-	"Ike Gingerich <ike_ at users.sourceforge.net>",     /**< author         */
-	WEBSITE,                                          /**< homepage       */
+	PLUGIN_ID,
+	NULL,
+	PP_VERSION,
 
-	plugin_load,                                      /**< load           */
-	plugin_unload,                                    /**< unload         */
-	NULL,                                             /**< destroy        */
+	NULL,
+	NULL,
+	"Ike Gingerich <ike_ at users.sourceforge.net>",
+	PP_WEBSITE,
 
-	NULL,                                             /**< ui_info        */
-	NULL,                                             /**< extra_info     */
-	&prefs_info,                                      /**< prefs_info     */
+	plugin_load,
+	plugin_unload,
 	NULL,
+
 	NULL,
 	NULL,
+	&prefs_info,
 	NULL,
+	NULL,
+	NULL,
+	NULL,
 	NULL
 };
 
 /* store initial preference values */
-static void init_plugin(PurplePlugin *plugin)
-{
+static void
+init_plugin(PurplePlugin *plugin) {
+#ifdef ENABLE_NLS
+	bindtextdomain(GETTEXT_PACKAGE, PP_LOCALEDIR);
+	bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
+#endif /* ENABLE_NLS */
+
+	info.name = _("Message Splitter");
+	info.summary = _("Splits a large outgoing message into smaller messages of "
+	                 "a specified size.");
+	info.description = info.summary;
+
 	purple_prefs_add_none("/plugins/core/splitter");
 	purple_prefs_add_int ("/plugins/core/splitter/split_size", DEFAULT_SPLIT_SIZE);
 	purple_prefs_add_int ("/plugins/core/splitter/delay_ms",   DEFAULT_DELAY_MS);


More information about the Plugins-commits mailing list