# HG changeset patch # User Christopher O'Brien # Date 1135281292 0 # Node ID 97ec28aaae479250a1ba9c4dba9e99818c5a1b74 # Parent fee6a32644a4e409187e6cbedf5086ed3e3d38f3 [gaim-migrate @ 14966] added user search action to sametime committer: Tailor Script diff -r fee6a32644a4 -r 97ec28aaae47 src/protocols/sametime/sametime.c --- a/src/protocols/sametime/sametime.c Thu Dec 22 19:39:23 2005 +0000 +++ b/src/protocols/sametime/sametime.c Thu Dec 22 19:54:52 2005 +0000 @@ -4266,6 +4266,8 @@ gaim_notify_searchresults(gc, _("Select User"), msgA, msgB, sres, notify_close, NULL); + + g_free(msgB); } @@ -5358,6 +5360,123 @@ } +static void search_notify(struct mwResolveResult *result, + GaimConnection *gc) { + GList *l; + char *msgA, *msgB; + + GaimNotifySearchResults *sres; + GaimNotifySearchColumn *scol; + + sres = gaim_notify_searchresults_new(); + + scol = gaim_notify_searchresults_column_new(_("User Name")); + gaim_notify_searchresults_column_add(sres, scol); + + scol = gaim_notify_searchresults_column_new(_("Sametime ID")); + gaim_notify_searchresults_column_add(sres, scol); + + gaim_notify_searchresults_button_add(sres, GAIM_NOTIFY_BUTTON_IM, + notify_im); + + gaim_notify_searchresults_button_add(sres, GAIM_NOTIFY_BUTTON_ADD, + notify_add); + + for(l = result->matches; l; l = l->next) { + struct mwResolveMatch *match = l->data; + GList *row = NULL; + + if(!match->id || !match->name) + continue; + + row = g_list_append(row, g_strdup(match->name)); + row = g_list_append(row, g_strdup(match->id)); + gaim_notify_searchresults_row_add(sres, row); + } + + msgA = _("Search results for '%s'"); + msgB = _("The identifier '%s' may possibly refer to any of the following" + " users. You may add these users to your buddy list or send them" + " messages with the action buttons below."); + + msgA = g_strdup_printf(msgA, result->name); + msgB = g_strdup_printf(msgB, result->name); + + gaim_notify_searchresults(gc, _("Search Results"), + msgA, msgB, sres, notify_close, NULL); + + g_free(msgA); + g_free(msgB); +} + + +static void search_resolved(struct mwServiceResolve *srvc, + guint32 id, guint32 code, GList *results, + gpointer b) { + + GaimConnection *gc = b; + struct mwResolveResult *res = NULL; + + if(results) res = results->data; + + if(!code && res && res->matches) { + search_notify(res, gc); + + } else { + char *msgA, *msgB; + msgA = _("No matches"); + msgB = _("The identifier '%s' did not match and users in your" + " Sametime community."); + msgB = g_strdup_printf(msgB, NSTR(res->name)); + + gaim_notify_error(gc, _("No Matches"), msgA, msgB); + + g_free(msgB); + } +} + + +static void search_action_cb(GaimConnection *gc, const char *name) { + struct mwGaimPluginData *pd; + struct mwServiceResolve *srvc; + GList *query; + enum mwResolveFlag flags; + guint32 req; + + pd = gc->proto_data; + srvc = pd->srvc_resolve; + + query = g_list_prepend(NULL, (char *) name); + flags = mwResolveFlag_FIRST | mwResolveFlag_USERS; + + req = mwServiceResolve_resolve(srvc, query, flags, search_resolved, + gc, NULL); + g_list_free(query); + + if(req == SEARCH_ERROR) { + /** @todo display error */ + } +} + + +static void search_action(GaimPluginAction *act) { + GaimConnection *gc; + const char *msgA, *msgB; + + gc = act->context; + + msgA = _("Search for a user"); + msgB = _("Enter a name or partial ID in the field below to search" + " for matching users in your Sametime community."); + + gaim_request_input(gc, _("User Search"), msgA, msgB, NULL, + FALSE, FALSE, NULL, + _("Search"), G_CALLBACK(search_action_cb), + _("Cancel"), NULL, + gc); +} + + static GList *mw_plugin_actions(GaimPlugin *plugin, gpointer context) { GaimPluginAction *act; GList *l = NULL; @@ -5374,6 +5493,10 @@ remote_group_action); l = g_list_append(l, act); + act = gaim_plugin_action_new(_("User Search..."), + search_action); + l = g_list_append(l, act); + return l; }