OBS: updates for Ubuntu 16.04
[siplcs.git] / src / purple / purple-search.c
blob1ca03b4c6d4895f38eb134a0b0582197f5d1816e
1 /**
2 * @file purple-search.c
4 * pidgin-sipe
6 * Copyright (C) 2011-2015 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 <string.h>
29 #include <glib.h>
31 #include "notify.h"
32 #include "request.h"
34 #include "version.h"
35 #if PURPLE_VERSION_CHECK(3,0,0)
36 #include "conversations.h"
37 #endif
39 #include "sipe-common.h"
40 #include "sipe-backend.h"
41 #include "sipe-core.h"
42 #include "sipe-nls.h"
44 #include "purple-private.h"
46 void sipe_backend_search_failed(struct sipe_core_public *sipe_public,
47 SIPE_UNUSED_PARAMETER struct sipe_backend_search_token *token,
48 const gchar *msg)
50 sipe_backend_notify_error(sipe_public, msg, NULL);
53 struct sipe_backend_search_results *sipe_backend_search_results_start(SIPE_UNUSED_PARAMETER struct sipe_core_public *sipe_public,
54 SIPE_UNUSED_PARAMETER struct sipe_backend_search_token *token)
56 PurpleNotifySearchResults *results = purple_notify_searchresults_new();
58 if (results) {
59 PurpleNotifySearchColumn *column;
60 column = purple_notify_searchresults_column_new(_("User name"));
61 purple_notify_searchresults_column_add(results, column);
63 column = purple_notify_searchresults_column_new(_("Name"));
64 purple_notify_searchresults_column_add(results, column);
66 column = purple_notify_searchresults_column_new(_("Company"));
67 purple_notify_searchresults_column_add(results, column);
69 column = purple_notify_searchresults_column_new(_("Country"));
70 purple_notify_searchresults_column_add(results, column);
72 column = purple_notify_searchresults_column_new(_("Email"));
73 purple_notify_searchresults_column_add(results, column);
76 return((struct sipe_backend_search_results *)results);
79 void sipe_backend_search_results_add(SIPE_UNUSED_PARAMETER struct sipe_core_public *sipe_public,
80 struct sipe_backend_search_results *results,
81 const gchar *uri,
82 const gchar *name,
83 const gchar *company,
84 const gchar *country,
85 const gchar *email)
87 GList *row = NULL;
88 row = g_list_append(row, g_strdup(uri));
89 row = g_list_append(row, g_strdup(name));
90 row = g_list_append(row, g_strdup(company));
91 row = g_list_append(row, g_strdup(country));
92 row = g_list_append(row, g_strdup(email));
93 purple_notify_searchresults_row_add((PurpleNotifySearchResults *) results,
94 row);
97 static void searchresults_im_buddy(PurpleConnection *gc,
98 GList *row,
99 SIPE_UNUSED_PARAMETER void *user_data)
101 PurpleAccount *acct = purple_connection_get_account(gc);
102 gchar *id = sip_uri_from_name(g_list_nth_data(row, 0));
104 #if PURPLE_VERSION_CHECK(3,0,0)
105 PurpleIMConversation *conv = purple_conversations_find_im_with_account(id,
106 acct);
108 if (conv == NULL)
109 conv = purple_im_conversation_new(acct, id);
110 #else
111 PurpleConversation *conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM,
113 acct);
114 if (conv == NULL)
115 conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, acct, id);
116 #endif
118 g_free(id);
119 purple_conversation_present((PurpleConversation *) conv);
122 static void searchresults_add_buddy(PurpleConnection *gc,
123 GList *row,
124 SIPE_UNUSED_PARAMETER void *user_data)
126 purple_blist_request_add_buddy(purple_connection_get_account(gc),
127 g_list_nth_data(row, 0),
128 _("Other Contacts"),
129 g_list_nth_data(row, 1));
133 void sipe_backend_search_results_finalize(struct sipe_core_public *sipe_public,
134 struct sipe_backend_search_results *results,
135 const gchar *description,
136 SIPE_UNUSED_PARAMETER gboolean more)
138 struct sipe_backend_private *purple_private = sipe_public->backend_private;
139 PurpleNotifySearchResults *r = (PurpleNotifySearchResults *) results;
141 purple_notify_searchresults_button_add(r,
142 PURPLE_NOTIFY_BUTTON_IM,
143 searchresults_im_buddy);
144 purple_notify_searchresults_button_add(r,
145 PURPLE_NOTIFY_BUTTON_ADD,
146 searchresults_add_buddy);
147 purple_notify_searchresults(purple_private->gc,
148 NULL,
149 NULL,
150 description,
152 NULL,
153 NULL);
157 static void sipe_purple_find_contact_cb(PurpleConnection *gc,
158 PurpleRequestFields *fields)
160 GList *entries = purple_request_field_group_get_fields(purple_request_fields_get_groups(fields)->data);
161 const gchar *given_name = NULL;
162 const gchar *surname = NULL;
163 const gchar *email = NULL;
164 const gchar *sipid = NULL;
165 const gchar *company = NULL;
166 const gchar *country = NULL;
168 while (entries) {
169 PurpleRequestField *field = entries->data;
170 const char *id = purple_request_field_get_id(field);
171 const char *value = purple_request_field_string_get_value(field);
173 SIPE_DEBUG_INFO("sipe_purple_find_contact_cb: %s = '%s'", id, value ? value : "");
175 if (value && strlen(value)) {
176 if (strcmp(id, "given") == 0) {
177 given_name = value;
178 } else if (strcmp(id, "surname") == 0) {
179 surname = value;
180 } else if (strcmp(id, "email") == 0) {
181 email = value;
182 } else if (strcmp(id, "sipid") == 0) {
183 sipid = value;
184 } else if (strcmp(id, "company") == 0) {
185 company = value;
186 } else if (strcmp(id, "country") == 0) {
187 country = value;
191 entries = g_list_next(entries);
194 sipe_core_buddy_search(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
195 NULL,
196 given_name,
197 surname,
198 email,
199 sipid,
200 company,
201 country);
204 #if PURPLE_VERSION_CHECK(3,0,0)
205 void sipe_purple_show_find_contact(PurpleProtocolAction *action)
207 PurpleConnection *gc = action->connection;
208 #else
209 void sipe_purple_show_find_contact(PurplePluginAction *action)
211 PurpleConnection *gc = (PurpleConnection *) action->context;
212 #endif
213 PurpleRequestFields *fields;
214 PurpleRequestFieldGroup *group;
215 PurpleRequestField *field;
217 fields = purple_request_fields_new();
218 group = purple_request_field_group_new(NULL);
219 purple_request_fields_add_group(fields, group);
221 field = purple_request_field_string_new("given", _("First name"), NULL, FALSE);
222 purple_request_field_group_add_field(group, field);
223 field = purple_request_field_string_new("surname", _("Last name"), NULL, FALSE);
224 purple_request_field_group_add_field(group, field);
225 field = purple_request_field_string_new("email", _("Email"), NULL, FALSE);
226 purple_request_field_group_add_field(group, field);
227 field = purple_request_field_string_new("sipid", _("SIP ID"), NULL, FALSE);
228 purple_request_field_group_add_field(group, field);
229 field = purple_request_field_string_new("company", _("Company"), NULL, FALSE);
230 purple_request_field_group_add_field(group, field);
231 field = purple_request_field_string_new("country", _("Country"), NULL, FALSE);
232 purple_request_field_group_add_field(group, field);
234 purple_request_fields(gc,
235 _("Search"),
236 _("Search for a contact"),
237 _("Enter the information for the person you wish to find. Empty fields will be ignored."),
238 fields,
239 _("_Search"), G_CALLBACK(sipe_purple_find_contact_cb),
240 _("_Cancel"), NULL,
241 #if PURPLE_VERSION_CHECK(3,0,0)
242 purple_request_cpar_from_connection(gc),
243 #else
244 purple_connection_get_account(gc), NULL, NULL,
245 #endif
246 gc);
250 Local Variables:
251 mode: c
252 c-file-style: "bsd"
253 indent-tabs-mode: t
254 tab-width: 8
255 End: