org.guifications.plugins: 232732c662117f3311e7e111493f92ceeddbfd85
rlaager at guifications.org
rlaager at guifications.org
Mon Oct 22 00:20:16 CDT 2007
-----------------------------------------------------------------
Revision: 232732c662117f3311e7e111493f92ceeddbfd85
Ancestor: 281dbdcebcad586dc7c7074588209d58392e8018
Author: rlaager at guifications.org
Date: 2007-10-22T04:27:28
Branch: org.guifications.plugins
Deleted entries:
buddytools buddytools/COPYING buddytools/Changelog
buddytools/Makefile buddytools/README buddytools/buddylang.c
buddytools/buddynotes.c
Renamed entries:
buddytime/buddytime.c to buddytime/buddytime.c.old
buddytools/buddyedit.c to buddytime/buddyedit.c
buddytools/buddytimezone.c to buddytime/buddytime.c
buddytools/gtktimezone.c to buddytime/gtktimezone.c
buddytools/gtktimezonetest.c to buddytime/gtktimezonetest.c
buddytools/localtime.c to buddytime/localtime.c
buddytools/localtime.h to buddytime/localtime.h
buddytools/private.h to buddytime/private.h
buddytools/recurse.c to buddytime/recurse.c
buddytools/recurse.h to buddytime/recurse.h
buddytools/recursetest.c to buddytime/recursetest.c
buddytools/timetest.c to buddytime/timetest.c
buddytools/tzfile.h to buddytime/tzfile.h
Added files:
buddytime/.purple-plugin buddytime/buddytime.h
buddytime/gtkbuddytime.c
Modified files:
.mtn-ignore AUTHORS ChangeLog buddytime/Makefile.am
buddytime/buddytime.c
ChangeLog:
I've merged the buddytimezone plugin and core/ui split it. This works as
far as display goes. The old behaviors of showing the timezone in the
tooltip and in new conversations remains. The editing interface, which
depends on the buddyedit plugin, is currently #if 0'ed out.
-----------------------------------------------------------------
This revision's diffstat output:
.mtn-ignore | 2
AUTHORS | 1
ChangeLog | 2
buddytime/Makefile.am | 36 +++
buddytime/buddytime.c | 447 ++++++++++++++++++++++++-----------------------
buddytime/buddytime.h | 52 +++++
buddytime/gtkbuddytime.c | 148 +++++++++++++++
7 files changed, 471 insertions(+), 217 deletions(-)
-------------- next part --------------
============================================================
--- buddytime/.purple-plugin da39a3ee5e6b4b0d3255bfef95601890afd80709
+++ buddytime/.purple-plugin da39a3ee5e6b4b0d3255bfef95601890afd80709
============================================================
--- buddytime/buddytime.h 6e9a20dd9ca648cb539322ffc382efe5a2ef0856
+++ buddytime/buddytime.h 6e9a20dd9ca648cb539322ffc382efe5a2ef0856
@@ -0,0 +1,52 @@
+/*
+ * Buddy Time - Displays a buddy's local time
+ *
+ * A libpurple plugin that allows you to configure a timezone on a per-contact
+ * basis so it can display the localtime of your contact when a conversation
+ * starts. Convenient if you deal with contacts from many parts of the
+ * world.
+ *
+ * Copyright (C) 2006-2007, Richard Laager <rlaager at users.sf.net>
+ * Copyright (C) 2006, Martijn van Oosterhout <kleptog at svana.org>
+ *
+ * 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., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+#ifndef _BUDDYTIME_H_
+#define _BUDDYTIME_H_
+
+#define CORE_PLUGIN_STATIC_NAME "buddytime"
+#define CORE_PLUGIN_ID "core-kleptog-" CORE_PLUGIN_STATIC_NAME
+
+#define PLUGIN_AUTHOR "Martijn van Oosterhout <kleptog at svana.org>" \
+ "\n\t\t\tRichard Laager <rlaager at pidgin.im>"
+
+#define BUDDYTIME_BUDDY_GET_TIMEZONE "buddy_get_timezone"
+#define BUDDYTIME_TIMEZONE_GET_TIME "timezone_get_time"
+
+typedef struct _BuddyTimeUiOps BuddyTimeUiOps;
+
+struct _BuddyTimeUiOps
+{
+ void *(*create_menu)(const char *selected); /**< Creates a timezone menu. */
+ const char * (*get_timezone_menu_selection)(void *ui_data); /**< Retrieves the menu setting. */
+
+ void (*_buddytime_reserved1)(void);
+ void (*_buddytime_reserved2)(void);
+ void (*_buddytime_reserved3)(void);
+ void (*_buddytime_reserved4)(void);
+};
+
+#endif /* _BUDDYTIME_H_ */
============================================================
--- buddytime/gtkbuddytime.c 4bd3b7ec09f838bb8285f5349949841c1d10b49d
+++ buddytime/gtkbuddytime.c 4bd3b7ec09f838bb8285f5349949841c1d10b49d
@@ -0,0 +1,148 @@
+/*
+ * Buddy Time - Displays a buddy's local time
+ *
+ * A libpurple plugin that allows you to configure a timezone on a per-contact
+ * basis so it can display the localtime of your contact when a conversation
+ * starts. Convenient if you deal with contacts from many parts of the
+ * world.
+ *
+ * Copyright (C) 2006-2007, Richard Laager <rlaager at pidgin.im>
+ * Copyright (C) 2006, Martijn van Oosterhout <kleptog at svana.org>
+ *
+ * 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., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+#include "../common/pp_internal.h"
+
+#define PLUGIN_STATIC_NAME "gtkbuddytime"
+#define PLUGIN_ID PIDGIN_UI "-buddytime"
+
+#include "buddytime.h"
+
+#include <glib.h>
+
+#include "plugin.h"
+#include "version.h"
+
+#include "gtkblist.h"
+#include "gtkplugin.h"
+
+PurplePlugin *core_plugin = NULL;
+
+static void
+buddytimezone_tooltip_cb(PurpleBlistNode * node, char **text, gboolean full, void *data)
+{
+ char *newtext;
+ const char *timezone;
+ struct tm tm;
+ double diff;
+ int ret;
+
+ if (!full)
+ return;
+
+ timezone = purple_plugin_ipc_call(core_plugin, BUDDYTIME_BUDDY_GET_TIMEZONE,
+ NULL, node, TRUE);
+
+ if (!timezone)
+ return;
+
+ ret = GPOINTER_TO_INT(purple_plugin_ipc_call(core_plugin, BUDDYTIME_TIMEZONE_GET_TIME,
+ NULL, timezone, &tm, &diff));
+ if (ret < 0)
+ newtext = g_strdup_printf("%s\n<b>Timezone:</b> %s (error)", *text, timezone);
+ else if (ret == 0)
+ {
+ const char *timetext = purple_time_format(&tm);
+
+ if (diff < 0)
+ {
+ diff = 0 - diff;
+ newtext = g_strdup_printf(dngettext(GETTEXT_PACKAGE,
+ "%s\n<b>Local Time:</b> %s (%.4g hour behind)",
+ "%s\n<b>Local Time:</b> %s (%.4g hours behind)", diff),
+ *text, timetext, diff);
+ }
+ else
+ {
+ newtext = g_strdup_printf(dngettext(GETTEXT_PACKAGE,
+ "%s\n<b>Local Time:</b> %s (%.4g hour ahead)",
+ "%s\n<b>Local Time:</b> %s (%.4g hours ahead)", diff),
+ *text, timetext, diff); }
+ }
+ else
+ return;
+
+ g_free(*text);
+ *text = newtext;
+}
+
+static gboolean
+plugin_load(PurplePlugin * plugin)
+{
+ purple_signal_connect(pidgin_blist_get_handle(), "drawing-tooltip", plugin,
+ PURPLE_CALLBACK(buddytimezone_tooltip_cb), NULL);
+
+ core_plugin = purple_plugins_find_with_id(CORE_PLUGIN_ID);
+
+ return (core_plugin != NULL);
+}
+
+static PurplePluginInfo info =
+{
+ PURPLE_PLUGIN_MAGIC,
+ PURPLE_MAJOR_VERSION,
+ 0,
+ PURPLE_PLUGIN_STANDARD, /**< type */
+ PIDGIN_PLUGIN_TYPE, /**< ui_requirement */
+ PURPLE_PLUGIN_FLAG_INVISIBLE, /**< flags */
+ NULL, /**< dependencies */
+ PURPLE_PRIORITY_DEFAULT, /**< priority */
+ PLUGIN_ID, /**< id */
+ NULL, /**< name */
+ PP_VERSION, /**< version */
+ NULL, /**< summary */
+ NULL, /**< description */
+ PLUGIN_AUTHOR, /**< author */
+ PP_WEBSITE, /**< homepage */
+ plugin_load, /**< load */
+ NULL, /**< unload */
+ NULL, /**< destroy */
+ NULL, /**< ui_info */
+ NULL, /**< extra_info */
+ NULL, /**< prefs_info */
+ NULL, /**< actions */
+ NULL, /**< reserved 1 */
+ NULL, /**< reserved 2 */
+ NULL, /**< reserved 3 */
+ NULL /**< reserved 4 */
+};
+
+static void
+init_plugin(PurplePlugin * plugin)
+{
+ info.dependencies = g_list_append(info.dependencies, CORE_PLUGIN_ID);
+
+#ifdef ENABLE_NLS
+ bindtextdomain(GETTEXT_PACKAGE, PP_LOCALEDIR);
+ bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
+#endif /* ENABLE_NLS */
+
+ info.name = _("Buddy Time (Pidgin UI)");
+ info.summary = _("Pidgin user interface for the Buddy Time plugin.");
+ info.description = _("Pidgin user interface for the Buddy Time plugin.");
+}
+
+PURPLE_INIT_PLUGIN(PLUGIN_STATIC_NAME, init_plugin, info);
============================================================
--- .mtn-ignore d57be520eb4fc621712a786a88ea9cd7781a6dd2
+++ .mtn-ignore e80e91d8e90a7a2c35448ed0550db104e976752c
@@ -1,9 +1,11 @@ aclocal.m4
.*/?Makefile(\.in)?$
.*/?.+\.loT
(pre|pp)_config.h(\.in)?$
.+\.spec
.*\.dll
aclocal.m4
+buddytime/gtktimezonetest
+buddytime/recursetest
config.(cache|guess|log|status|sub)
configure
depcomp
============================================================
--- AUTHORS 58a72f03a3f76f3a6ac57ce43619e50fa8577154
+++ AUTHORS fdfb6ecc22ea52889c423f2fccc2536b3e1b1cb6
@@ -9,6 +9,7 @@ Richard Laager <rlaager at guifications.org
Daniel Atallah <datallah at users.sourceforge.net>
Sadrul H Chowdhury <sadrul at users.sourceforge.net>
Richard Laager <rlaager at guifications.org>
+Martijn van Oosterhout <kleptog at svana.org>
Translators
===========
============================================================
--- ChangeLog a1dcab4b202a0504337b3054498674326a33e503
+++ ChangeLog dd17fc5793e69f9a54e99fb409389eeb8eb27038
@@ -25,6 +25,8 @@ Version 2.2.0mtn:
* Removed the .build file from hideconv to remove it from default
builds. Pidgin will have persistent conversations soon.
* Added dewysiwygification plugin
+ * Merged buddytimezone from the buddytools package into the existing
+ (incomplete) buddytime plugin
Version 2.1.1: 8/19/07
* Fixed lack of .build, .pidgin-plugin, and Makefile.mingw for convbadger
============================================================
--- buddytime/Makefile.am 56ea6469b497eb1b586ce5166ab60224c4b113bf
+++ buddytime/Makefile.am 4bd391a3ba69349128fb127325f683d2e0a47e16
@@ -1,23 +1,45 @@
-EXTRA_DIST = .incomplete .pidgin-plugin
+EXTRA_DIST = .incomplete .purple-plugin .pidgin-plugin
-buddytimedir = $(PIDGIN_LIBDIR)
+noinst_PROGRAMS = recursetest
-buddytime_la_LDFLAGS = -module -avoid-version
+recursetest_SOURCES = \
+ recurse.c \
+ recursetest.c
if HAVE_PIDGIN
-buddytime_LTLIBRARIES = buddytime.la
+noinst_PROGRAMS += gtktimezonetest
-buddytime_la_SOURCES = \
- buddytime.c
+gtktimezonetest_SOURCES = \
+ gtktimezone.c \
+ gtktimezonetest.c \
+ recurse.c
-buddytime_la_LIBADD = \
+gtktimezonetest_LDADD = \
+ $(GTK_LIBS)
+
+gtkbuddytimedir = $(PIDGIN_LIBDIR)
+gtkbuddytime_la_LDFLAGS = -module -avoid-version
+gtkbuddytime_LTLIBRARIES = gtkbuddytime.la
+gtkbuddytime_la_SOURCES = \
+ gtkbuddytime.c
+gtkbuddytime_la_LIBADD = \
$(PIDGIN_LIBS) \
$(GLIB_LIBS) \
$(GTK_LIBS)
endif
+buddytimedir = $(PURPLE_LIBDIR)
+buddytime_la_LDFLAGS = -module -avoid-version
+buddytime_LTLIBRARIES = buddytime.la
+buddytime_la_SOURCES = \
+ buddytime.c
+buddytime_la_LIBADD = \
+ $(PURPLE_LIBS) \
+ $(GLIB_LIBS)
+
+
AM_CPPFLAGS = \
-DLIBDIR=\"$(PIDGIN_LIBDIR)\" \
-DDATADIR=\"$(PIDGIN_DATADIR)\" \
============================================================
--- buddytools/buddytimezone.c 973cb36eff88c30fe679f4e0fdc7885158d04338
+++ buddytime/buddytime.c 064892480640d2dee03b4fd3156f42408be73000
@@ -1,13 +1,13 @@
-/*************************************************************************
- * Buddy Timezone Module
+/*
+ * Buddy Time - Displays a buddy's local time
*
- * A Purple plugin that allows you to configure a timezone on a per-contact
+ * A libpurple plugin that allows you to configure a timezone on a per-contact
* basis so it can display the localtime of your contact when a conversation
* starts. Convenient if you deal with contacts from many parts of the
* world.
*
- * by Martijn van Oosterhout <kleptog at svana.org> (C) April 2006
- * Some code copyright (C) 2006, Richard Laager <rlaager at users.sf.net>
+ * Copyright (C) 2006-2007, Richard Laager <rlaager at pidgin.im>
+ * Copyright (C) 2006, Martijn van Oosterhout <kleptog at svana.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@@ -23,49 +23,41 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
- *************************************************************************/
+ */
+#include "../common/pp_internal.h"
-#define PURPLE_PLUGINS
+#include "buddytime.h"
+#define PLUGIN_STATIC_NAME CORE_PLUGIN_STATIC_NAME
+#define PLUGIN_ID CORE_PLUGIN_ID
-#ifdef CUSTOM_GTK
-#define PLUGIN "gtk-kleptog-buddytimezone"
-#else
-#define PLUGIN "core-kleptog-buddytimezone"
-#endif
-
#define SETTING_NAME "timezone"
-#define CONTROL_NAME PLUGIN "-" SETTING_NAME
+#define CONTROL_NAME PLUGIN_ID "-" SETTING_NAME
#include <glib.h>
#include <errno.h>
#include <ctype.h>
#include <string.h>
-#include <math.h>
+#include "conversation.h"
+#include "core.h"
+#include "debug.h"
#include "notify.h"
#include "plugin.h"
+#include "request.h"
+#include "util.h"
+#include "value.h"
#include "version.h"
-#include "debug.h" /* Debug output functions */
-#include "util.h" /* Menu functions */
-#include "request.h" /* Requests stuff */
-#include "conversation.h" /* Conversation stuff */
+#include "gtkblist.h"
-#include "localtime.h"
#include "recurse.h"
-#include "gtkblist.h"
-
-#define TIMEZONE_FLAG ((void*)1)
+#define TIMEZONE_FLAG ((void*)1)
#define DISABLED_FLAG ((void*)2)
-#define TIME_FORMAT "%X"
-/* Another possible format (hides seconds) */
-//#define TIME_FORMAT "%H:%M"
+BuddyTimeUiOps *ui_ops = NULL;
static PurplePlugin *plugin_self;
-void *make_timezone_menu(const char *selected);
-const char *get_timezone_menu_selection(void *widget);
/* Resolve specifies what the return value should mean:
*
@@ -74,9 +66,11 @@ const char *get_timezone_menu_selection(
*
* If false, we only want what the user enter, thus the string "none" if
* that's what it is
+ *
+ * data is here so we can use this as a callback for IPC
*/
static const char *
-buddy_get_timezone(PurpleBlistNode * node, gboolean resolve)
+buddy_get_timezone(PurpleBlistNode * node, gboolean resolve, void *data)
{
PurpleBlistNode *datanode = NULL;
const char *timezone;
@@ -98,59 +92,55 @@ buddy_get_timezone(PurpleBlistNode * nod
timezone = purple_blist_node_get_string(datanode, SETTING_NAME);
- if(!resolve)
+ if (!resolve)
return timezone;
/* The effect of "none" is to stop recursion */
- if(timezone && strcmp(timezone, "none") == 0)
+ if (timezone && strcmp(timezone, "none") == 0)
return NULL;
- if(timezone)
+ if (timezone)
return timezone;
- if(datanode->type == PURPLE_BLIST_CONTACT_NODE)
+ if (datanode->type == PURPLE_BLIST_CONTACT_NODE)
{
/* There is no purple_blist_contact_get_group(), though there probably should be */
datanode = datanode->parent;
timezone = purple_blist_node_get_string(datanode, SETTING_NAME);
}
- if(timezone && strcmp(timezone, "none") == 0)
+ if (timezone && strcmp(timezone, "none") == 0)
return NULL;
return timezone;
}
/* Calcuates the difference between two struct tm's. */
-static float
-timezone_calc_difference(struct tm *remote_tm, struct tm *local_tm)
+static double
+timezone_calc_difference(struct tm *remote_tm, struct tm *tmp_tm)
{
- int datediff = 0, diff;
+ int hours_diff = 0;
+ int minutes_diff = 0;
- /* Tries to calculate the difference. Note this only works because the
- * times are with 24 hours of eachother! */
- if(remote_tm->tm_mday != local_tm->tm_mday)
- {
- datediff = remote_tm->tm_year - local_tm->tm_year;
- if(datediff == 0)
- datediff = remote_tm->tm_mon - local_tm->tm_mon;
- if(datediff == 0)
- datediff = remote_tm->tm_mday - local_tm->tm_mday;
- }
- diff =
- datediff * 24 * 60 + (remote_tm->tm_hour - local_tm->tm_hour) * 60 + (remote_tm->tm_min -
- local_tm->tm_min);
+ /* Note this only works because the times are
+ * known to be within 24 hours of each other! */
+ if (remote_tm->tm_mday != tmp_tm->tm_mday)
+ hours_diff = 24;
- return (float)diff / 60.0;
+ hours_diff += (remote_tm->tm_hour - tmp_tm->tm_hour);
+ minutes_diff = (remote_tm->tm_min - tmp_tm->tm_min);
+
+ return (double)minutes_diff / 60.0 + hours_diff;
}
-#ifdef PRIVATE_TZLIB
+/* data is here so we can use this as a callback for IPC */
static int
-timezone_get_time(const char *timezone, struct tm *tm, float *diff)
+timezone_get_time(const char *timezone, struct tm *tm, double *diff, void *data)
{
- struct state *tzinfo = timezone_load(timezone);
- struct tm *local_tm;
time_t now;
+ struct tm *tm_tmp;
+#ifdef PRIVATE_TZLIB
+ struct state *tzinfo = timezone_load(timezone);
if(!tzinfo)
return -1;
@@ -158,22 +148,7 @@ timezone_get_time(const char *timezone,
time(&now);
localsub(&now, 0, tm, tzinfo);
free(tzinfo);
-
- /* Calculate user's localtime, and compare. If same, no output */
- local_tm = localtime(&now);
-
- if(local_tm->tm_hour == tm->tm_hour && local_tm->tm_min == tm->tm_min)
- return 1;
-
- *diff = timezone_calc_difference(tm, local_tm);
- return 0;
-}
#else
-static int
-timezone_get_time(const char *timezone, struct tm *tm, float *diff)
-{
- time_t now;
- struct tm *tm_tmp;
const gchar *old_tz;
/* Store the current TZ value. */
@@ -186,21 +161,21 @@ timezone_get_time(const char *timezone,
*tm = *tm_tmp; /* Must copy, localtime uses local buffer */
/* Reset the old TZ value. */
- if(old_tz == NULL)
+ if (old_tz == NULL)
g_unsetenv("TZ");
else
g_setenv("TZ", old_tz, TRUE);
+#endif
/* Calculate user's localtime, and compare. If same, no output */
tm_tmp = localtime(&now);
- if(tm_tmp->tm_hour == tm->tm_hour && tm_tmp->tm_min == tm->tm_min)
+ if (tm_tmp->tm_hour == tm->tm_hour && tm_tmp->tm_min == tm->tm_min)
return 1;
*diff = timezone_calc_difference(tm, tm_tmp);
return 0;
}
-#endif
static void
timezone_createconv_cb(PurpleConversation * conv, void *data)
@@ -209,80 +184,60 @@ timezone_createconv_cb(PurpleConversatio
PurpleBuddy *buddy;
struct tm tm;
const char *timezone;
- float diff;
+ double diff;
int ret;
- if(purple_conversation_get_type(conv) != PURPLE_CONV_TYPE_IM)
+ if (purple_conversation_get_type(conv) != PURPLE_CONV_TYPE_IM)
return;
name = purple_conversation_get_name(conv);
buddy = purple_find_buddy(purple_conversation_get_account(conv), name);
- if(!buddy)
+ if (!buddy)
return;
- timezone = buddy_get_timezone((PurpleBlistNode *) buddy, TRUE);
+ timezone = buddy_get_timezone((PurpleBlistNode *) buddy, TRUE, NULL);
- if(!timezone)
+ if (!timezone)
return;
- ret = timezone_get_time(timezone, &tm, &diff);
+ ret = timezone_get_time(timezone, &tm, &diff, NULL);
- if(ret == 0)
+ if (ret == 0)
{
const char *text = purple_time_format(&tm);
- char *str = g_strdup_printf("Remote Local Time: %s (%g hours %s)", text, fabs(diff),
- (diff < 0) ? "behind" : "ahead");
+ char *str;
+ if (diff < 0)
+ {
+ diff = 0 - diff;
+ str = g_strdup_printf(dngettext(GETTEXT_PACKAGE,
+ "Remote Local Time: %s (%.4g hour behind)",
+ "Remote Local Time: %s (%.4g hours behind)", diff),
+ text, diff);
+ }
+ else
+ {
+ str = g_strdup_printf(dngettext(GETTEXT_PACKAGE,
+ "Remote Local Time: %s (%.4g hour ahead)",
+ "Remote Local Time: %s (%.4g hours ahead)", diff),
+ text, diff);
+ }
- purple_conversation_write(conv, PLUGIN, str, PURPLE_MESSAGE_SYSTEM, time(NULL));
+ purple_conversation_write(conv, PLUGIN_STATIC_NAME, str, PURPLE_MESSAGE_SYSTEM, time(NULL));
g_free(str);
}
}
+#if 0
static void
-buddytimezone_tooltip_cb(PurpleBlistNode * node, char **text, gboolean full, void *data)
-{
- char *newtext;
- const char *timezone;
- struct tm tm;
- float diff;
- int ret;
-
- if(!full)
- return;
-
- purple_debug(PURPLE_DEBUG_INFO, PLUGIN, "type %d\n", node->type);
- timezone = buddy_get_timezone(node, TRUE);
- if(!timezone)
- return;
-
- ret = timezone_get_time(timezone, &tm, &diff);
- if(ret < 0)
- newtext = g_strdup_printf("%s\n<b>Timezone:</b> %s (error)", *text, timezone);
- else if(ret == 0)
- {
- const char *timetext = purple_time_format(&tm);
-
- newtext =
- g_strdup_printf("%s\n<b>Local Time:</b> %s (%g hours %s)", *text, timetext, fabs(diff),
- (diff < 0) ? "behind" : "ahead");
- }
- else
- return;
-
- g_free(*text);
- *text = newtext;
-}
-
-static void
buddytimezone_submitfields_cb(PurpleRequestFields * fields, PurpleBlistNode * data)
{
PurpleBlistNode *node;
PurpleRequestField *list;
/* timezone stuff */
- purple_debug(PURPLE_DEBUG_INFO, PLUGIN, "buddytimezone_submitfields_cb(%p,%p)\n", fields, data);
+ purple_debug(PURPLE_DEBUG_INFO, PLUGIN_STATIC_NAME, "buddytimezone_submitfields_cb(%p,%p)\n", fields, data);
switch (data->type)
{
@@ -302,44 +257,45 @@ buddytimezone_submitfields_cb(PurpleRequ
}
list = purple_request_fields_get_field(fields, CONTROL_NAME);
-#ifdef CUSTOM_GTK
- const char *seldata = get_timezone_menu_selection(list->ui_data);
- if(seldata == NULL)
- purple_blist_node_remove_setting(node, SETTING_NAME);
+ if (ui_ops != NULL && ui_ops->get_timezone_menu_selection != NULL)
+ {
+ const char *seldata = ui_ops->get_timezone_menu_selection(list->ui_data);
+ if (seldata == NULL)
+ purple_blist_node_remove_setting(node, SETTING_NAME);
+ else
+ purple_blist_node_set_string(node, SETTING_NAME, seldata);
+ }
else
- purple_blist_node_set_string(node, SETTING_NAME, seldata);
-#else
- const GList *sellist;
- void *seldata = NULL;
- sellist = purple_request_field_list_get_selected(list);
- if(sellist)
- seldata = purple_request_field_list_get_data(list, sellist->data);
+ {
+ const GList *sellist;
+ void *seldata = NULL;
+ sellist = purple_request_field_list_get_selected(list);
+ if (sellist)
+ seldata = purple_request_field_list_get_data(list, sellist->data);
- /* Otherwise, it's fixed value and this means deletion */
- if(seldata == TIMEZONE_FLAG)
- purple_blist_node_set_string(node, SETTING_NAME, sellist->data);
- else if(seldata == DISABLED_FLAG)
- purple_blist_node_set_string(node, SETTING_NAME, "none");
- else
- purple_blist_node_remove_setting(node, SETTING_NAME);
-#endif
+ /* Otherwise, it's fixed value and this means deletion */
+ if (seldata == TIMEZONE_FLAG)
+ purple_blist_node_set_string(node, SETTING_NAME, sellist->data);
+ else if (seldata == DISABLED_FLAG)
+ purple_blist_node_set_string(node, SETTING_NAME, "none");
+ else
+ purple_blist_node_remove_setting(node, SETTING_NAME);
+ }
}
-#ifndef CUSTOM_GTK
static int
buddy_add_timezone_cb(char *filename, void *data)
{
PurpleRequestField *field = (PurpleRequestField *) data;
- if(isupper(filename[0]))
+ if (isupper(filename[0]))
purple_request_field_list_add(field, filename, TIMEZONE_FLAG);
return 0;
}
-#endif
static void
buddytimezone_createfields_cb(PurpleRequestFields * fields, PurpleBlistNode * data)
{
- purple_debug(PURPLE_DEBUG_INFO, PLUGIN, "buddytimezone_createfields_cb(%p,%p)\n", fields, data);
+ purple_debug(PURPLE_DEBUG_INFO, PLUGIN_STATIC_NAME, "buddytimezone_createfields_cb(%p,%p)\n", fields, data);
PurpleRequestField *field;
PurpleRequestFieldGroup *group;
const char *timezone;
@@ -364,98 +320,169 @@ buddytimezone_createfields_cb(PurpleRequ
group = purple_request_field_group_new(NULL);
purple_request_fields_add_group(fields, group);
- timezone = buddy_get_timezone(data, FALSE);
+ timezone = buddy_get_timezone(data, FALSE, NULL);
-#ifdef CUSTOM_GTK
- field =
- purple_request_field_new(CONTROL_NAME,
- is_default ? "Default timezone for group" : "Timezone of contact",
- PURPLE_REQUEST_FIELD_LIST);
- field->ui_data = make_timezone_menu(timezone);
-#else
- field =
- purple_request_field_list_new(CONTROL_NAME,
- is_default ? "Default timezone for group" :
- "Timezone of contact (type to select)");
- purple_request_field_list_set_multi_select(field, FALSE);
- purple_request_field_list_add(field, "<Default>", "");
- purple_request_field_list_add(field, "<Disabled>", DISABLED_FLAG);
+ if (ui_ops != NULL && ui_ops->create_menu)
+ {
+ field =
+ purple_request_field_new(CONTROL_NAME,
+ is_default ? "Default timezone for group" : "Timezone of contact",
+ PURPLE_REQUEST_FIELD_LIST);
+ field->ui_data = ui_ops->create_menu(timezone);
+ }
+ else
+ {
+ field =
+ purple_request_field_list_new(CONTROL_NAME,
+ is_default ? "Default timezone for group" :
+ "Timezone of contact (type to select)");
+ purple_request_field_list_set_multi_select(field, FALSE);
+ purple_request_field_list_add(field, "<Default>", "");
+ purple_request_field_list_add(field, "<Disabled>", DISABLED_FLAG);
- recurse_directory("/usr/share/zoneinfo/", buddy_add_timezone_cb, field);
+ recurse_directory("/usr/share/zoneinfo/", buddy_add_timezone_cb, field);
- if(timezone)
- {
- if(strcmp(timezone, "none") == 0)
- purple_request_field_list_add_selected(field, "<Disabled>");
+ if (timezone)
+ {
+ if (strcmp(timezone, "none") == 0)
+ purple_request_field_list_add_selected(field, "<Disabled>");
+ else
+ purple_request_field_list_add_selected(field, timezone);
+ }
else
- purple_request_field_list_add_selected(field, timezone);
+ purple_request_field_list_add_selected(field, "<Default>");
}
- else
- purple_request_field_list_add_selected(field, "<Default>");
+
+ purple_request_field_group_add_field(group, field);
+}
#endif
- purple_request_field_group_add_field(group, field);
+static void
+marshal_POINTER__POINTER_BOOL(PurpleCallback cb, va_list args, void *data,
+ void **return_val)
+{
+ gpointer ret_val;
+ void *arg1 = va_arg(args, void *);
+ gboolean arg2 = va_arg(args, gboolean);
+
+ ret_val = ((gpointer (*)(void *, gboolean, void *))cb)(arg1, arg2, data);
+
+ if (return_val != NULL)
+ *return_val = ret_val;
}
+static void
+marshal_POINTER__POINTER_POINTER_POINTER(PurpleCallback cb, va_list args, void *data,
+ void **return_val)
+{
+ gpointer ret_val;
+ void *arg1 = va_arg(args, void *);
+ void *arg2 = va_arg(args, void *);
+ void *arg3 = va_arg(args, void *);
+
+ ret_val = ((gpointer (*)(void *, void *, void *, void *))cb)(arg1, arg2, arg3, data);
+
+ if (return_val != NULL)
+ *return_val = ret_val;
+}
+
static gboolean
-plugin_load(PurplePlugin * plugin)
+load_ui_plugin(gpointer data)
{
- plugin_self = plugin;
+ char *ui_plugin_id;
+ PurplePlugin *ui_plugin;
- purple_signal_connect(purple_blist_get_handle(), "core-kleptog-buddyedit-create-fields", plugin,
- PURPLE_CALLBACK(buddytimezone_createfields_cb), NULL);
- purple_signal_connect(purple_blist_get_handle(), "core-kleptog-buddyedit-submit-fields", plugin,
- PURPLE_CALLBACK(buddytimezone_submitfields_cb), NULL);
- purple_signal_connect(pidgin_blist_get_handle(), "drawing-tooltip", plugin,
- PURPLE_CALLBACK(buddytimezone_tooltip_cb), NULL);
- purple_signal_connect(purple_conversations_get_handle(), "conversation-created", plugin,
- PURPLE_CALLBACK(timezone_createconv_cb), NULL);
+ ui_plugin_id = g_strconcat(purple_core_get_ui(), "-", PLUGIN_STATIC_NAME, NULL);
+ ui_plugin = purple_plugins_find_with_id(ui_plugin_id);
-#ifdef PRIVATE_TZLIB
- const char *zoneinfo_dir = purple_prefs_get_string("/plugins/timezone/zoneinfo_dir");
- if(tz_init(zoneinfo_dir) < 0)
- purple_debug_error(PLUGIN, "Problem opening zoneinfo dir (%s): %s\n", zoneinfo_dir,
- strerror(errno));
-#endif
+ if (ui_plugin != NULL)
+ {
+ if (!purple_plugin_load(ui_plugin))
+ {
+ purple_notify_error(ui_plugin, NULL, _("Failed to load the Buddy Timezone UI."),
+ ui_plugin->error ? ui_plugin->error : "");
+ }
+ }
- return TRUE;
+ g_free(ui_plugin_id);
+
+ return FALSE;
}
-static PurplePluginInfo info = {
- PURPLE_PLUGIN_MAGIC,
- PURPLE_MAJOR_VERSION,
- 0,
- PURPLE_PLUGIN_STANDARD,
- NULL,
- 0,
- NULL,
- PURPLE_PRIORITY_DEFAULT,
+static gboolean
+plugin_load(PurplePlugin * plugin)
+{
+ plugin_self = plugin;
- PLUGIN,
- "Buddy Timezone Module",
- G_STRINGIFY(PLUGIN_VERSION),
+ purple_signal_connect(purple_conversations_get_handle(), "conversation-created", plugin,
+ PURPLE_CALLBACK(timezone_createconv_cb), NULL);
- "Quickly see the local time of a buddy",
- "A Purple plugin that allows you to configure a timezone on a per-contact "
- "basis so it can display the localtime of your contact when a conversation "
- "starts. Convenient if you deal with contacts from many parts of the " "world.",
- "Martijn van Oosterhout <kleptog at svana.org>",
- "http://svana.org/kleptog/purple/",
+ purple_plugin_ipc_register(plugin, BUDDYTIME_BUDDY_GET_TIMEZONE,
+ PURPLE_CALLBACK(buddy_get_timezone),
+ marshal_POINTER__POINTER_BOOL,
+ purple_value_new(PURPLE_TYPE_STRING),
+ 2,
+ purple_value_new(PURPLE_TYPE_SUBTYPE,
+ PURPLE_SUBTYPE_BLIST_NODE),
+ purple_value_new(PURPLE_TYPE_BOOLEAN));
- plugin_load,
- NULL,
- NULL,
+ purple_plugin_ipc_register(plugin, BUDDYTIME_TIMEZONE_GET_TIME,
+ PURPLE_CALLBACK(timezone_get_time),
+ marshal_POINTER__POINTER_POINTER_POINTER,
+ purple_value_new(PURPLE_TYPE_INT),
+ 2,
+ purple_value_new(PURPLE_TYPE_POINTER),
+ purple_value_new(PURPLE_TYPE_POINTER));
- NULL,
- NULL,
- NULL,
- NULL
+ /* This is done as an idle callback to avoid an infinite loop
+ * when we try to load the UI plugin which depends on this plugin
+ * which isn't officially loaded yet. */
+ purple_timeout_add(0, load_ui_plugin, NULL);
+
+ return TRUE;
+}
+
+static PurplePluginInfo info =
+{
+ PURPLE_PLUGIN_MAGIC,
+ PURPLE_MAJOR_VERSION,
+ 0,
+ PURPLE_PLUGIN_STANDARD, /**< type */
+ NULL, /**< ui_requirement */
+ 0, /**< flags */
+ NULL, /**< dependencies */
+ PURPLE_PRIORITY_DEFAULT, /**< priority */
+ PLUGIN_ID, /**< id */
+ NULL, /**< name */
+ PP_VERSION, /**< version */
+ NULL, /**< summary */
+ NULL, /**< description */
+ PLUGIN_AUTHOR, /**< author */
+ PP_WEBSITE, /**< homepage */
+ plugin_load, /**< load */
+ NULL, /**< unload */
+ NULL, /**< destroy */
+ NULL, /**< ui_info */
+ NULL, /**< extra_info */
+ NULL, /**< prefs_info */
+ NULL, /**< actions */
+ NULL, /**< reserved 1 */
+ NULL, /**< reserved 2 */
+ NULL, /**< reserved 3 */
+ NULL /**< reserved 4 */
};
static void
init_plugin(PurplePlugin * plugin)
{
- info.dependencies = g_list_append(info.dependencies, "core-kleptog-buddyedit");
+#ifdef ENABLE_NLS
+ bindtextdomain(GETTEXT_PACKAGE, PP_LOCALEDIR);
+ bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
+#endif /* ENABLE_NLS */
+
+ info.name = _("Buddy Time");
+ info.summary = _("Quickly see the local time of a buddy");
+ info.description = _("Quickly see the local time of a buddy");
}
+PURPLE_INIT_PLUGIN(PLUGIN_STATIC_NAME, init_plugin, info);
-PURPLE_INIT_PLUGIN(buddytimezone, init_plugin, info);
More information about the Plugins-commits
mailing list