Fix #222: SIPE crashes when groupchat session expires (VI)
[siplcs.git] / src / purple / purple-search.c
blobaeeaae41d5b2314f1d2f576dc69fde202d7040a3
1 /**
2 * @file purple-search.c
4 * pidgin-sipe
6 * Copyright (C) 2011-12 SIPE Project <http://sipe.sourceforge.net/>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
27 #include <glib.h>
29 #include "notify.h"
31 #include "sipe-common.h"
32 #include "sipe-backend.h"
33 #include "sipe-core.h"
34 #include "sipe-nls.h"
36 #include "purple-private.h"
38 void sipe_backend_search_failed(struct sipe_core_public *sipe_public,
39 SIPE_UNUSED_PARAMETER struct sipe_backend_search_token *token,
40 const gchar *msg)
42 sipe_backend_notify_error(sipe_public, msg, NULL);
45 struct sipe_backend_search_results *sipe_backend_search_results_start(SIPE_UNUSED_PARAMETER struct sipe_core_public *sipe_public,
46 SIPE_UNUSED_PARAMETER struct sipe_backend_search_token *token)
48 PurpleNotifySearchResults *results = purple_notify_searchresults_new();
50 if (results) {
51 PurpleNotifySearchColumn *column;
52 column = purple_notify_searchresults_column_new(_("User name"));
53 purple_notify_searchresults_column_add(results, column);
55 column = purple_notify_searchresults_column_new(_("Name"));
56 purple_notify_searchresults_column_add(results, column);
58 column = purple_notify_searchresults_column_new(_("Company"));
59 purple_notify_searchresults_column_add(results, column);
61 column = purple_notify_searchresults_column_new(_("Country"));
62 purple_notify_searchresults_column_add(results, column);
64 column = purple_notify_searchresults_column_new(_("Email"));
65 purple_notify_searchresults_column_add(results, column);
68 return((struct sipe_backend_search_results *)results);
71 void sipe_backend_search_results_add(SIPE_UNUSED_PARAMETER struct sipe_core_public *sipe_public,
72 struct sipe_backend_search_results *results,
73 const gchar *uri,
74 const gchar *name,
75 const gchar *company,
76 const gchar *country,
77 const gchar *email)
79 GList *row = NULL;
80 row = g_list_append(row, g_strdup(uri));
81 row = g_list_append(row, g_strdup(name));
82 row = g_list_append(row, g_strdup(company));
83 row = g_list_append(row, g_strdup(country));
84 row = g_list_append(row, g_strdup(email));
85 purple_notify_searchresults_row_add((PurpleNotifySearchResults *) results,
86 row);
89 static void searchresults_im_buddy(PurpleConnection *gc,
90 GList *row,
91 SIPE_UNUSED_PARAMETER void *user_data)
93 PurpleAccount *acct = purple_connection_get_account(gc);
94 gchar *id = sip_uri_from_name(g_list_nth_data(row, 0));
95 PurpleConversation *conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM,
96 id,
97 acct);
98 if (conv == NULL)
99 conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, acct, id);
100 g_free(id);
101 purple_conversation_present(conv);
104 static void searchresults_add_buddy(PurpleConnection *gc,
105 GList *row,
106 SIPE_UNUSED_PARAMETER void *user_data)
108 purple_blist_request_add_buddy(purple_connection_get_account(gc),
109 g_list_nth_data(row, 0),
110 _("Other Contacts"),
111 g_list_nth_data(row, 1));
115 void sipe_backend_search_results_finalize(struct sipe_core_public *sipe_public,
116 struct sipe_backend_search_results *results,
117 const gchar *description,
118 SIPE_UNUSED_PARAMETER gboolean more)
120 struct sipe_backend_private *purple_private = sipe_public->backend_private;
121 PurpleNotifySearchResults *r = (PurpleNotifySearchResults *) results;
123 purple_notify_searchresults_button_add(r,
124 PURPLE_NOTIFY_BUTTON_IM,
125 searchresults_im_buddy);
126 purple_notify_searchresults_button_add(r,
127 PURPLE_NOTIFY_BUTTON_ADD,
128 searchresults_add_buddy);
129 purple_notify_searchresults(purple_private->gc,
130 NULL,
131 NULL,
132 description,
134 NULL,
135 NULL);
140 Local Variables:
141 mode: c
142 c-file-style: "bsd"
143 indent-tabs-mode: t
144 tab-width: 8
145 End: