org.guifications.plugins.buddytools: 6bc5753f073b74266279b39e0c6d51933d3d997b
rlaager at guifications.org
rlaager at guifications.org
Mon Oct 22 00:20:21 CDT 2007
-----------------------------------------------------------------
Revision: 6bc5753f073b74266279b39e0c6d51933d3d997b
Ancestor: 80c48775896345bafbd7073503e7fe1c02c256f9
Author: rlaager at guifications.org
Date: 2006-05-16T03:41:26
Branch: org.guifications.plugins.buddytools
Tag: v0.5
Modified files:
Changelog Makefile buddyedit.c buddytimezone.c gtktimezone.c
gtktimezonetest.c
ChangeLog:
[buddytools @ 14]
Importing Martijn's changes, which resulted in version 0.5:
version 0.5 (9 Apr 2006)
* Add initial "Edit Chat" functionality. Works at least for IRC. (kleptog)
* The usual bug fixes
-----------------------------------------------------------------
This revision's diffstat output:
Changelog | 4 +
Makefile | 5 -
buddyedit.c | 153 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
buddytimezone.c | 61 ++++++++++++---------
gtktimezone.c | 27 ++++-----
gtktimezonetest.c | 2
6 files changed, 205 insertions(+), 47 deletions(-)
-------------- next part --------------
============================================================
--- Changelog c48ca2e2da6790f777b3eb31f18ce6a4829b9798
+++ Changelog 015ea1015c7b78ca2714dbeb5c8b9cdfa5a65f35
@@ -1,3 +1,7 @@
+version 0.5 (9 Apr 2006)
+ * Add initial "Edit Chat" functionality. Works at least for IRC. (kleptog)
+ * The usual bug fixes
+
version 0.4pre2 (9 Apr 2006)
* Fix compilation issues for Gaim 2 (kleptog)
* Update Makefile to allow compilation against multiple versions of
============================================================
--- Makefile 468ad88ebb98d73a89836d27b1144a8370af6d30
+++ Makefile 24cb8c2f5082c7bf75d00723a95797c314cd9307
@@ -1,10 +1,10 @@
#*************************************************************************
#* 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.4pre2
+VERSION=0.5
# Use internal timezone library rather than system one: yes or no
PRIVATE_TZLIB ?= yes
@@ -15,7 +15,7 @@ CUSTOM_GTK ?= yes
# For choosing which version to compile against
# This is name of the pkgconfig file to use
-GAIM_NAME ?= gaim
+GAIM_NAME ?= gaim2
# Where to install the modules
INSTALL_PATH=$(HOME)/.$(GAIM_NAME)/plugins/
@@ -86,7 +86,6 @@ compiletest:
# - Martijn
compiletest:
for i in gaim gaim2 ; do for j in yes no ; do for k in yes no ; do \
- if [ $$i = gaim -a $$j = yes ] ; then continue ; fi ; \
make clean ; \
make all GAIM_NAME=$$i CUSTOM_GTK=$$j PRIVATE_TZLIB=$$k ; \
done ; done ; done
============================================================
--- buddyedit.c ca02ca9dd1946c38cf294922453e68f79d79a2cb
+++ buddyedit.c e883e5621ebcf7d288b4cd2bd071db80fb24726e
@@ -43,8 +43,10 @@ buddyedit_editcomplete_cb(GaimBlistNode
static void
buddyedit_editcomplete_cb(GaimBlistNode * data, GaimRequestFields * fields)
{
- gboolean buddy_destroy = FALSE;
+ gboolean blist_destroy = FALSE;
+ GaimBlistNode *olddata = data; /* Keep pointer in case we need to destroy it */
+
/* Account detail stuff */
switch (data->type)
{
@@ -67,7 +69,7 @@ buddyedit_editcomplete_cb(GaimBlistNode
((GaimBlistNode *) buddy)->settings = ((GaimBlistNode *) newbuddy)->settings;
((GaimBlistNode *) newbuddy)->settings = tmp;
- buddy_destroy = TRUE;
+ blist_destroy = TRUE;
data = (GaimBlistNode *) newbuddy;
}
else
@@ -91,6 +93,101 @@ buddyedit_editcomplete_cb(GaimBlistNode
case GAIM_BLIST_CHAT_NODE:
{
GaimChat *chat = (GaimChat *) data;
+ gboolean new_chat = FALSE;
+
+ GaimConnection *gc;
+ GList *list = NULL, *tmp;
+ gc = gaim_account_get_connection(chat->account);
+ if(GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info != NULL)
+ list = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info(gc);
+
+ GaimAccount *newaccount = gaim_request_fields_get_account(fields, "account");
+
+ /* In Gaim2 each prot_chat_entry has a field "required". We use
+ * this to determine if a field is important enough to recreate
+ * the chat if it changes. Non-required fields we jsut change
+ * in-situ. In Gaim1.5 this field doesn't exist so we always
+ * recreate */
+#if GAIM_MAJOR_VERSION >= 2
+ if(newaccount != chat->account)
+ new_chat = TRUE;
+ else
+ {
+ const char *oldvalue, *newvalue;
+
+ for (tmp = g_list_first(list); tmp && !new_chat; tmp = g_list_next(tmp))
+ {
+ struct proto_chat_entry *pce = tmp->data;
+ if(!pce->required) /* Only checking required fields at this point */
+ continue;
+ if(pce->is_int)
+ continue; /* Not yet */
+ oldvalue = g_hash_table_lookup(chat->components, pce->identifier);
+ newvalue = gaim_request_fields_get_string(fields, pce->identifier);
+
+ if(oldvalue == NULL)
+ oldvalue = "";
+ if(newvalue == NULL)
+ newvalue = "";
+ if(strcmp(oldvalue, newvalue) != 0)
+ new_chat = TRUE;
+ }
+ }
+#else
+ new_chat = TRUE;
+#endif
+
+ if(new_chat)
+ {
+ const char *oldvalue, *newvalue;
+ GHashTable *components =
+ g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
+
+ for (tmp = g_list_first(list); tmp; tmp = g_list_next(tmp))
+ {
+ struct proto_chat_entry *pce = tmp->data;
+
+ if(pce->is_int)
+ {
+ oldvalue = g_hash_table_lookup(chat->components, pce->identifier);
+ g_hash_table_replace(components, g_strdup(pce->identifier),
+ g_strdup(oldvalue));
+ }
+ else
+ {
+ newvalue = gaim_request_fields_get_string(fields, pce->identifier);
+ g_hash_table_replace(components, g_strdup(pce->identifier),
+ g_strdup(newvalue));
+ }
+ }
+ GaimChat *newchat = gaim_chat_new(newaccount, NULL, components);
+ gaim_blist_add_chat(newchat, NULL, data); /* Copy it to correct location */
+ data = (GaimBlistNode *) newchat;
+ blist_destroy = TRUE;
+ }
+ else /* Just updating values in old chat */
+ {
+ const char *newvalue;
+ for (tmp = g_list_first(list); tmp; tmp = g_list_next(tmp))
+ {
+ struct proto_chat_entry *pce = tmp->data;
+#if GAIM_MAJOR_VERSION >= 2
+ if(pce->required)
+ continue;
+#endif
+ if(pce->is_int)
+ {
+ /* Do nothing, yet */
+ }
+ else
+ {
+ newvalue = gaim_request_fields_get_string(fields, pce->identifier);
+ g_hash_table_replace(chat->components, g_strdup(pce->identifier),
+ g_strdup(newvalue));
+ }
+ }
+ }
+
const char *alias = gaim_request_fields_get_string(fields, "alias");
gaim_blist_alias_chat(chat, alias);
break;
@@ -101,12 +198,32 @@ buddyedit_editcomplete_cb(GaimBlistNode
gaim_signal_emit(gaim_blist_get_handle(), PLUGIN "-submit-fields", fields, data);
- if(buddy_destroy)
- gaim_blist_remove_buddy((GaimBuddy *) data);
+ if(blist_destroy)
+ {
+ if(olddata->type == GAIM_BLIST_BUDDY_NODE)
+ gaim_blist_remove_buddy((GaimBuddy *) olddata);
+ else if(olddata->type == GAIM_BLIST_CHAT_NODE)
+ gaim_blist_remove_chat((GaimChat *) olddata);
+ }
+
/* Save any changes */
gaim_blist_schedule_save();
}
+static GaimAccount *buddyedit_account_filter_func_data;
+
+static gboolean
+buddyedit_account_filter_func(GaimAccount * account)
+{
+ GaimPluginProtocolInfo *gppi1 =
+ GAIM_PLUGIN_PROTOCOL_INFO(gaim_account_get_connection(account)->prpl);
+ GaimPluginProtocolInfo *gppi2 =
+ GAIM_PLUGIN_PROTOCOL_INFO(gaim_account_get_connection(buddyedit_account_filter_func_data)->
+ prpl);
+
+ return gppi1 == gppi2;
+}
+
/* Node is either a contact or a buddy */
static void
buddy_edit_cb(GaimBlistNode * node, gpointer data)
@@ -170,6 +287,34 @@ buddy_edit_cb(GaimBlistNode * node, gpoi
group = gaim_request_field_group_new("Chat Details");
gaim_request_fields_add_group(fields, group);
+ field = gaim_request_field_account_new("account", "Account", chat->account);
+ gaim_request_field_account_set_filter(field, buddyedit_account_filter_func);
+ buddyedit_account_filter_func_data = chat->account;
+ gaim_request_field_group_add_field(group, field);
+ GaimConnection *gc;
+ GList *list = NULL, *tmp;
+ gc = gaim_account_get_connection(chat->account);
+ if(GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info != NULL)
+ list = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info(gc);
+
+ for (tmp = g_list_first(list); tmp; tmp = g_list_next(tmp))
+ {
+ struct proto_chat_entry *pce = tmp->data;
+ const char *value;
+#if GAIM_MAJOR_VERSION >= 2
+ gaim_debug(GAIM_DEBUG_INFO, PLUGIN,
+ "identifier=%s, label=%s, is_int=%d, required=%d\n", pce->identifier,
+ pce->label, pce->is_int, pce->required);
+#endif
+ if(pce->is_int)
+ continue; /* Not yet */
+ value = g_hash_table_lookup(chat->components, pce->identifier);
+ field = gaim_request_field_string_new(pce->identifier, pce->label, value, FALSE);
+#if GAIM_MAJOR_VERSION >= 2
+ gaim_request_field_set_required(field, pce->required);
+#endif
+ gaim_request_field_group_add_field(group, field);
+ }
field = gaim_request_field_string_new("alias", "Alias", chat->alias, FALSE);
gaim_request_field_group_add_field(group, field);
============================================================
--- buddytimezone.c 3fd1166f48e589108105f656004deb1bf7a78efa
+++ buddytimezone.c b9cb3e6b2c66dd39cdbcf2b4373074b0f706876b
@@ -72,7 +72,7 @@ void *make_timezone_menu(const char *sel
static GaimPlugin *plugin_self;
void *make_timezone_menu(const char *selected);
-const char *get_timezone_menu_selection( void *widget );
+const char *get_timezone_menu_selection(void *widget);
/* Resolve specifies what the return value should mean:
*
@@ -129,22 +129,25 @@ buddy_get_timezone(GaimBlistNode * node,
}
/* Calcuates the difference between two struct tm's. */
-static float timezone_calc_difference( struct tm *remote_tm, struct tm *local_tm )
+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 )
+ if(remote_tm->tm_mday != local_tm->tm_mday)
{
datediff = remote_tm->tm_year - local_tm->tm_year;
- if( datediff == 0 )
+ if(datediff == 0)
datediff = remote_tm->tm_mon - local_tm->tm_mon;
- if( datediff == 0 )
+ 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);
-
+ }
+ 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;
}
@@ -155,7 +158,7 @@ timezone_get_time(const char *timezone,
struct state *tzinfo = timezone_load(timezone);
struct tm *local_tm;
time_t now;
-
+
if(!tzinfo)
return -1;
@@ -165,11 +168,11 @@ timezone_get_time(const char *timezone,
/* 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 )
+
+ if(local_tm->tm_hour == tm->tm_hour && local_tm->tm_min == tm->tm_min)
return 1;
-
- *diff = timezone_calc_difference( tm, local_tm );
+
+ *diff = timezone_calc_difference(tm, local_tm);
return 0;
}
#else
@@ -187,21 +190,21 @@ timezone_get_time(const char *timezone,
time(&now);
tm_tmp = localtime(&now);
- *tm = *tm_tmp; /* Must copy, localtime uses local buffer */
+ *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 )
+
+ if(tm_tmp->tm_hour == tm->tm_hour && tm_tmp->tm_min == tm->tm_min)
return 1;
- *diff = timezone_calc_difference( tm, tm_tmp );
+ *diff = timezone_calc_difference(tm, tm_tmp);
return 0;
}
#endif
@@ -245,7 +248,8 @@ timezone_createconv_cb(GaimConversation
strftime(text, sizeof(text), TIME_FORMAT, &tm);
#endif
- char *str = g_strdup_printf("Remote Local Time: %s (%g hours %s)", text, fabs(diff), (diff<0)?"behind":"ahead");
+ 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));
@@ -280,7 +284,7 @@ buddytimezone_tooltip_cb(GaimBlistNode *
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 )
+ else if(ret == 0)
{
#if GAIM_MAJOR_VERSION > 1
const char *timetext = gaim_time_format(&tm);
@@ -289,10 +293,12 @@ buddytimezone_tooltip_cb(GaimBlistNode *
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");
+ newtext =
+ g_strdup_printf("%s\n<b>Local Time:</b> %s (%g hours %s)", *text, timetext, fabs(diff),
+ (diff < 0) ? "behind" : "ahead");
}
else
- return;
+ return;
g_free(*text);
*text = newtext;
@@ -326,8 +332,8 @@ buddytimezone_submitfields_cb(GaimReques
list = gaim_request_fields_get_field(fields, CONTROL_NAME);
#ifdef CUSTOM_GTK
- const char *seldata = get_timezone_menu_selection( list->ui_data );
- if( seldata == NULL )
+ const char *seldata = get_timezone_menu_selection(list->ui_data);
+ if(seldata == NULL)
gaim_blist_node_remove_setting(node, SETTING_NAME);
else
gaim_blist_node_set_string(node, SETTING_NAME, seldata);
@@ -390,7 +396,10 @@ buddytimezone_createfields_cb(GaimReques
timezone = buddy_get_timezone(data, FALSE);
#ifdef CUSTOM_GTK
- field = gaim_request_field_new( CONTROL_NAME, "Timezone", GAIM_REQUEST_FIELD_LIST );
+ field =
+ gaim_request_field_new(CONTROL_NAME,
+ is_default ? "Default timezone for group" : "Timezone of contact",
+ GAIM_REQUEST_FIELD_LIST);
field->ui_data = make_timezone_menu(timezone);
#else
field =
============================================================
--- gtktimezone.c 27586df46582c96e2e0f7077f84474c3f49149bb
+++ gtktimezone.c 3e965caa2ee6c957469062a97956b141c9440fd6
@@ -48,7 +48,7 @@ menu_select_cb(GtkMenuItem * menuitem, G
static int
menu_select_cb(GtkMenuItem * menuitem, GtkWidget * menu)
{
- const char *label = menuitem_get_label( menuitem );
+ const char *label = menuitem_get_label(menuitem);
// printf( "menuitem = %s(%p), menu = %s(%p)\n", G_OBJECT_TYPE_NAME(menuitem), menuitem, G_OBJECT_TYPE_NAME(menu), menu );
@@ -105,8 +105,9 @@ menu_select_cb(GtkMenuItem * menuitem, G
gtk_label_set_text(label, str);
gtk_widget_show(GTK_WIDGET(selection));
gtk_option_menu_set_history(optionmenu, 0);
-
- printf("optionmenu=%p, menu=%p, menuitem=%p, label=%p\n", optionmenu, menu, selection, label );
+
+ printf("optionmenu=%p, menu=%p, menuitem=%p, label=%p\n", optionmenu, menu, selection,
+ label);
g_free(str);
}
}
@@ -174,9 +175,9 @@ make_timezone_menu(const char *selected)
GtkWidget *menu;
GtkWidget *optionmenu, *menuitem, *selection;
- if( selected == NULL )
+ if(selected == NULL)
selected = "";
-
+
menu = gtk_menu_new();
menuitem = gtk_menu_item_new_with_label(selected);
gtk_menu_append(menu, menuitem);
@@ -197,7 +198,7 @@ make_timezone_menu(const char *selected)
state.currdepth = 0;
- recurse_directory("/usr/share/zoneinfo", (DirRecurseMatch)make_menu_cb, &state);
+ recurse_directory("/usr/share/zoneinfo", (DirRecurseMatch) make_menu_cb, &state);
for (i = 0; i < state.currdepth; i++)
g_free(state.stack[i].string);
@@ -225,16 +226,16 @@ const char *
}
const char *
-get_timezone_menu_selection( void *widget )
+get_timezone_menu_selection(void *widget)
{
GtkOptionMenu *menu = GTK_OPTION_MENU(widget);
-
- int sel = gtk_option_menu_get_history( menu );
- if( sel == 2 ) /* Default */
- return NULL;
- if( sel == 1 ) /* Disabled */
- return "none";
+ int sel = gtk_option_menu_get_history(menu);
+ if(sel == 2) /* Default */
+ return NULL;
+ if(sel == 1) /* Disabled */
+ return "none";
+
// GtkMenu *m = GTK_MENU( gtk_option_menu_get_menu(menu) );
// GtkMenuItem *mi = GTK_MENU_ITEM( gtk_menu_get_active( m ));
GtkLabel *l = GTK_LABEL(gtk_bin_get_child(GTK_BIN(menu)));
============================================================
--- gtktimezonetest.c b4cd9377736de4250aa51fd3d8c443be0868bdea
+++ gtktimezonetest.c 5cd01b2b8ff8cda05ba65c2256f43cdd6d52919b
@@ -250,7 +250,7 @@ make_menu2(char *selected)
#endif
state.currdepth = 0;
- recurse_directory("/usr/share/zoneinfo", (DirRecurseMatch)make_menu_cb, &state);
+ recurse_directory("/usr/share/zoneinfo", (DirRecurseMatch) make_menu_cb, &state);
for (i = 0; i < state.currdepth; i++)
g_free(state.stack[i].string);
More information about the Plugins-commits
mailing list