org.guifications.plugins.buddytools: 1c9d4b6e6a8f30d949e8128ee29807d2b201fa02

rlaager at guifications.org rlaager at guifications.org
Mon Oct 22 00:20:14 CDT 2007


-----------------------------------------------------------------
Revision: 1c9d4b6e6a8f30d949e8128ee29807d2b201fa02
Ancestor: 8afe303ac7111f529055302aedc98a4d69d75b7d
Author: rlaager at guifications.org
Date: 2006-05-16T03:35:26
Branch: org.guifications.plugins.buddytools
Tag: v0.4pre1-orig

Modified files:
        Changelog Makefile buddyedit.c buddytimezone.c

ChangeLog: 

[buddytools @ 8]
Importing Martijn's changes, which resulted in version 0.4pre1...

NOTE: This is the first version I received from him named 0.4pre1, not the
NOTE: version 0.4pre1 from the website.

version 0.4pre1 (7 Apr 2006)
        * Various cleanups (rlaager)
        * Fix so time only displays when different from system time
        * Attach copyright notices and clarify GPLv2+
        * Makefile cleanups (rlaager)


-----------------------------------------------------------------
This revision's diffstat output:
 Changelog       |   10 ++++-
 Makefile        |   26 ++++++++-------
 buddyedit.c     |    2 -
 buddytimezone.c |   96 ++++++++++++++++++++++++++++++++++++++++++++------------
 4 files changed, 100 insertions(+), 34 deletions(-)
-------------- next part --------------
============================================================
--- Changelog	3017b5bfdfebffb5a1c7fbff217ad9d55bacf716
+++ Changelog	97674e88933a96a6878a1b24cc30f2501bda70f6
@@ -1,7 +1,13 @@
-version 0.3
+version 0.4pre1 (7 Apr 2006)
+	* Various cleanups (rlaager)
+	* Fix so time only displays when different from system time
+	* Attach copyright notices and clarify GPLv2+
+	* Makefile cleanups (rlaager)
+
+version 0.3 (6 Apr 2006)
 	* Now have editing for all node types, but Chat is a bit lame so far
 	* Have made gtkwidget to will be successor to huge list box for
-	  timezone, now just need to add it somehow.
+	  timezones, now just need to add it somehow.
 	* Groups can now have default timezones and languages.
 	* You can now select Disabled as well as Default, if you don't want
 	  to display and spellcheck anything ever.
============================================================
--- Makefile	37237d7cdca5294b73ecce004eee3f63d0a3654e
+++ Makefile	6e1ab8409dd1b663c367ead01e59972bce43ea8b
@@ -1,12 +1,12 @@
 #*************************************************************************
 #* Buddy Edit Makefile
 #* by Martijn van Oosterhout <kleptog at svana.org> (C) April 2006
 #* Licenced under the GNU General Public Licence version 2.
 #*************************************************************************/
 
-VERSION=0.3
+VERSION=0.4pre1
 # yes or no
-PRIVATE_TZLIB=yes
+PRIVATE_TZLIB ?= yes
 
 CFLAGS=-O2 -g -Wall `pkg-config --cflags glib-2.0 gaim` -DPLUGIN_VERSION=$(VERSION)
 LDFLAGS=`pkg-config --libs glib-2.0 gaim`
@@ -17,35 +17,37 @@ endif
 PRIVATE_TZLIB_OBJS=localtime.o
 endif
 
-all: buddyedit.so buddytimezone.so buddynotes.so buddylang.so timetest recursetest gtktimezonetest
+LIB_TARGETS=buddyedit.so buddytimezone.so buddynotes.so buddylang.so
+EXE_TARGETS=timetest recursetest gtktimezonetest
 
+all: $(LIB_TARGETS) $(EXE_TARGETS)
+
 recursetest: recurse.o recursetest.o
 
 timetest: timetest.o localtime.o
 
 gtktimezonetest.o: gtktimezonetest.c
-	gcc -c $(CFLAGS) `pkg-config --cflags gtk+-2.0` -o $@ $<
+	$(CC) -c $(CFLAGS) `pkg-config --cflags gtk+-2.0` -o $@ $<
 
 gtktimezonetest: gtktimezonetest.o recurse.o
-	gcc $(LDFLAGS) -lgtk-x11-2.0 -lgdk-x11-2.0 -o $@ $^
+	$(CC) $(LDFLAGS) -lgtk-x11-2.0 -lgdk-x11-2.0 -o $@ $^
 
-
 buddytimezone.so: buddytimezone.o $(PRIVATE_TZLIB_OBJS) recurse.o
-	gcc -shared $(LDFLAGS) -o $@ $^
+	$(CC) -shared $(LDFLAGS) -o $@ $^
 
 buddyedit.so: buddyedit.o
-	gcc -shared $(LDFLAGS) -o $@ $^
+	$(CC) -shared $(LDFLAGS) -o $@ $^
 
 buddynotes.so: buddynotes.o
-	gcc -shared $(LDFLAGS) -o $@ $^
+	$(CC) -shared $(LDFLAGS) -o $@ $^
 
 buddylang.o: buddylang.c
-	gcc -c $(CFLAGS) `pkg-config --cflags gtkspell-2.0` -o $@ $<
+	$(CC) -c $(CFLAGS) `pkg-config --cflags gtkspell-2.0` -o $@ $<
 buddylang.so: buddylang.o
-	gcc -shared $(LDFLAGS) -lgtkspell -laspell -o $@ $^
+	$(CC) -shared $(LDFLAGS) -lgtkspell -laspell -o $@ $^
 
 clean:
-	rm -f *.o *.so
+	rm -f *.o $(LIB_TARGETS) $(EXE_TARGETS)
 
 install: all
 	install -m 755 -d $(HOME)/.gaim/plugins
============================================================
--- buddyedit.c	965519f1590863759cc359410786aca7f55d48f6
+++ buddyedit.c	fa052431556981044cb6ae64745eb0c3193652a0
@@ -198,7 +198,7 @@ buddy_menu_cb(GaimBlistNode * node, GLis
 #if GAIM_MAJOR_VERSION < 2
     action = gaim_blist_node_action_new("Edit...", buddy_edit_cb, NULL);
 #else
-    action = gaim_menu_action_new("Edit...", buddy_edit_cb, NULL, NULL);
+    action = gaim_menu_action_new("Edit...", GAIM_CALLBACK(buddy_edit_cb), NULL, NULL);
 #endif
     *menu = g_list_append(*menu, action);
 }
============================================================
--- buddytimezone.c	954fa97d481ecf78ffa2a54f0df11568355ab282
+++ buddytimezone.c	7e7ab785f7047720dfdc93c9c359146ba582182f
@@ -18,6 +18,7 @@
 #include <errno.h>
 #include <ctype.h>
 #include <string.h>
+#include <math.h>
 
 #include "notify.h"
 #include "plugin.h"
@@ -38,6 +39,10 @@ void *gaim_gtk_blist_get_handle();
 #define TIMEZONE_FLAG  ((void*)1)
 #define DISABLED_FLAG ((void*)2)
 
+#define TIME_FORMAT "%X"
+/* Another possible format (hides seconds) */
+//#define TIME_FORMAT  "%H:%M"
+
 static GaimPlugin *plugin_self;
 
 /* Resolve specifies what the return value should mean:
@@ -94,41 +99,80 @@ buddy_get_timezone(GaimBlistNode * node,
     return timezone;
 }
 
+/* Calcuates the difference between two struct tm's. */
+static float timezone_calc_difference( struct tm *remote_tm, struct tm *local_tm )
+{
+    int datediff = 0, diff;
+    
+    /* 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);
+    
+    return (float)diff / 60.0;
+}
+
 #ifdef PRIVATE_TZLIB
 static int
-timezone_get_time(const char *timezone, struct tm *tm)
+timezone_get_time(const char *timezone, struct tm *tm, float *diff)
 {
     struct state *tzinfo = timezone_load(timezone);
+    struct tm *local_tm;
+    time_t now;
+    
     if(!tzinfo)
         return -1;
-    else
-    {
-        time_t now = time(NULL);
-        localsub(&now, 0, tm, tzinfo);
-        free(tzinfo);
-    }
+
+    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_in)
+timezone_get_time(const char *timezone, struct tm *tm, float *diff)
 {
     time_t now;
-    struct tm *tm;
+    struct tm *tm_tmp;
     const gchar *old_tz;
 
     /* Store the current TZ value. */
     old_tz = g_getenv("TZ");
+
     g_setenv("TZ", timezone, TRUE);
-    now = time(NULL);
-    tm = localtime(&now);
-    memcpy(tm_in, tm, sizeof(*tm));
 
+    time(&now);
+    tm_tmp = localtime(&now);
+    *tm = *tm_tmp;         /* Must copy, localtime uses local buffer */
+
     /* Reset the old TZ value. */
     if(old_tz == NULL)
         g_unsetenv("TZ");
     else
         g_setenv("TZ", old_tz, TRUE);
+        
+    /* 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 )
+        return 1;
+
+    *diff = timezone_calc_difference( tm, tm_tmp );
     return 0;
 }
 #endif
@@ -140,6 +184,7 @@ timezone_createconv_cb(GaimConversation 
     GaimBuddy *buddy;
     struct tm tm;
     const char *timezone;
+    float diff;
     int ret;
 
 #if GAIM_MAJOR_VERSION < 2
@@ -160,18 +205,18 @@ timezone_createconv_cb(GaimConversation 
     if(!timezone)
         return;
 
-    ret = timezone_get_time(timezone, &tm);
+    ret = timezone_get_time(timezone, &tm, &diff);
 
     if(ret == 0)
     {
 #if GAIM_MAJOR_VERSION > 1
-        char *text = gaim_date_format_short(tm);
+        const char *text = gaim_time_format(&tm);
 #else
         char text[64];
-        strftime(text, sizeof(text), "%X", &tm);
+        strftime(text, sizeof(text), TIME_FORMAT, &tm);
 #endif
 
-        char *str = g_strdup_printf("Remote Local Time: %s", text);
+        char *str = g_strdup_printf("Remote Local Time: %s (%g hours %s)", text, fabs(diff), (diff<0)?"behind":"ahead");
 
         gaim_conversation_write(conv, PLUGIN, str, GAIM_MESSAGE_SYSTEM, time(NULL));
 
@@ -180,7 +225,8 @@ timezone_createconv_cb(GaimConversation 
 }
 
 #if GAIM_MAJOR_VERSION > 1
-static void buddytimezone_tooltip_cb(GaimBlistNode * node, char **text, gboolean full, void *data);
+static void
+buddytimezone_tooltip_cb(GaimBlistNode * node, char **text, gboolean full, void *data)
 #else
 static void
 buddytimezone_tooltip_cb(GaimBlistNode * node, char **text, void *data)
@@ -189,6 +235,7 @@ buddytimezone_tooltip_cb(GaimBlistNode *
     char *newtext;
     const char *timezone;
     struct tm tm;
+    float diff;
     int ret;
 
 #if GAIM_MAJOR_VERSION > 1
@@ -201,11 +248,22 @@ buddytimezone_tooltip_cb(GaimBlistNode *
     if(!timezone)
         return;
 
-    ret = timezone_get_time(timezone, &tm);
+    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 )
+    {
+#if GAIM_MAJOR_VERSION > 1
+        char *timetext = gaim_date_format_short(tm);
+#else
+        char timetext[64];
+        strftime(timetext, sizeof(timetext), TIME_FORMAT, &tm);
+#endif
+
+        newtext = g_strdup_printf("%s\n<b>Local Time:</b> %s (%g hours %s)", *text, timetext, fabs(diff), (diff<0)?"behind":"ahead");
+    }
     else
-        newtext = g_strdup_printf("%s\n<b>Local Time:</b> %d:%02d", *text, tm.tm_hour, tm.tm_min);
+    	return;
 
     g_free(*text);
     *text = newtext;


More information about the Plugins-commits mailing list