purple: add _PurpleProtocolAction fwd declaration
[siplcs.git] / src / purple / purple-search.c
blob7c8e1331f2ea190576187346df4d8fabe7edf795
1 /**
2 * @file purple-search.c
4 * pidgin-sipe
6 * Copyright (C) 2011-2019 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 "action.h"
37 #include "conversations.h"
38 #endif
40 #include "sipe-common.h"
41 #include "sipe-backend.h"
42 #include "sipe-core.h"
43 #include "sipe-nls.h"
45 #include "purple-private.h"
47 void sipe_backend_search_failed(struct sipe_core_public *sipe_public,
48 SIPE_UNUSED_PARAMETER struct sipe_backend_search_token *token,
49 const gchar *msg)
51 sipe_backend_notify_error(sipe_public, msg, NULL);
54 struct sipe_backend_search_results *sipe_backend_search_results_start(SIPE_UNUSED_PARAMETER struct sipe_core_public *sipe_public,
55 SIPE_UNUSED_PARAMETER struct sipe_backend_search_token *token)
57 PurpleNotifySearchResults *results = purple_notify_searchresults_new();
59 if (results) {
60 PurpleNotifySearchColumn *column;
61 column = purple_notify_searchresults_column_new(_("User name"));
62 purple_notify_searchresults_column_add(results, column);
64 column = purple_notify_searchresults_column_new(_("Name"));
65 purple_notify_searchresults_column_add(results, column);
67 column = purple_notify_searchresults_column_new(_("Company"));
68 purple_notify_searchresults_column_add(results, column);
70 column = purple_notify_searchresults_column_new(_("Country"));
71 purple_notify_searchresults_column_add(results, column);
73 column = purple_notify_searchresults_column_new(_("Email"));
74 purple_notify_searchresults_column_add(results, column);
77 return((struct sipe_backend_search_results *)results);
80 void sipe_backend_search_results_add(SIPE_UNUSED_PARAMETER struct sipe_core_public *sipe_public,
81 struct sipe_backend_search_results *results,
82 const gchar *uri,
83 const gchar *name,
84 const gchar *company,
85 const gchar *country,
86 const gchar *email)
88 GList *row = NULL;
89 row = g_list_append(row, g_strdup(uri));
90 row = g_list_append(row, g_strdup(name));
91 row = g_list_append(row, g_strdup(company));
92 row = g_list_append(row, g_strdup(country));
93 row = g_list_append(row, g_strdup(email));
94 purple_notify_searchresults_row_add((PurpleNotifySearchResults *) results,
95 row);
98 static void searchresults_im_buddy(PurpleConnection *gc,
99 GList *row,
100 SIPE_UNUSED_PARAMETER void *user_data)
102 PurpleAccount *acct = purple_connection_get_account(gc);
103 gchar *id = sip_uri_from_name(g_list_nth_data(row, 0));
105 #if PURPLE_VERSION_CHECK(3,0,0)
106 PurpleIMConversation *conv = purple_conversations_find_im_with_account(id,
107 acct);
109 if (conv == NULL)
110 conv = purple_im_conversation_new(acct, id);
111 #else
112 PurpleConversation *conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM,
114 acct);
115 if (conv == NULL)
116 conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, acct, id);
117 #endif
119 g_free(id);
120 purple_conversation_present((PurpleConversation *) conv);
123 static void searchresults_add_buddy(PurpleConnection *gc,
124 GList *row,
125 SIPE_UNUSED_PARAMETER void *user_data)
127 purple_blist_request_add_buddy(purple_connection_get_account(gc),
128 g_list_nth_data(row, 0),
129 _("Other Contacts"),
130 NULL);
134 void sipe_backend_search_results_finalize(struct sipe_core_public *sipe_public,
135 struct sipe_backend_search_results *results,
136 const gchar *description,
137 SIPE_UNUSED_PARAMETER gboolean more)
139 struct sipe_backend_private *purple_private = sipe_public->backend_private;
140 PurpleNotifySearchResults *r = (PurpleNotifySearchResults *) results;
142 purple_notify_searchresults_button_add(r,
143 PURPLE_NOTIFY_BUTTON_IM,
144 searchresults_im_buddy);
145 purple_notify_searchresults_button_add(r,
146 PURPLE_NOTIFY_BUTTON_ADD,
147 searchresults_add_buddy);
148 purple_notify_searchresults(purple_private->gc,
149 NULL,
150 NULL,
151 description,
153 NULL,
154 NULL);
158 static void sipe_purple_find_contact_cb(PurpleConnection *gc,
159 PurpleRequestFields *fields)
161 GList *entries = purple_request_field_group_get_fields(purple_request_fields_get_groups(fields)->data);
162 const gchar *given_name = NULL;
163 const gchar *surname = NULL;
164 const gchar *email = NULL;
165 const gchar *sipid = NULL;
166 const gchar *company = NULL;
167 const gchar *country = NULL;
169 while (entries) {
170 PurpleRequestField *field = entries->data;
171 const char *id = purple_request_field_get_id(field);
172 const char *value = purple_request_field_string_get_value(field);
174 SIPE_DEBUG_INFO("sipe_purple_find_contact_cb: %s = '%s'", id, value ? value : "");
176 if (value && strlen(value)) {
177 if (strcmp(id, "given") == 0) {
178 given_name = value;
179 } else if (strcmp(id, "surname") == 0) {
180 surname = value;
181 } else if (strcmp(id, "email") == 0) {
182 email = value;
183 } else if (strcmp(id, "sipid") == 0) {
184 sipid = value;
185 } else if (strcmp(id, "company") == 0) {
186 company = value;
187 } else if (strcmp(id, "country") == 0) {
188 country = value;
192 entries = g_list_next(entries);
195 sipe_core_buddy_search(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
196 NULL,
197 given_name,
198 surname,
199 email,
200 sipid,
201 company,
202 country);
205 #if PURPLE_VERSION_CHECK(3,0,0)
206 void sipe_purple_show_find_contact(PurpleProtocolAction *action)
208 PurpleConnection *gc = action->connection;
209 #else
210 void sipe_purple_show_find_contact(PurplePluginAction *action)
212 PurpleConnection *gc = (PurpleConnection *) action->context;
213 #endif
214 PurpleRequestFields *fields;
215 PurpleRequestFieldGroup *group;
216 PurpleRequestField *field;
218 fields = purple_request_fields_new();
219 group = purple_request_field_group_new(NULL);
220 purple_request_fields_add_group(fields, group);
222 field = purple_request_field_string_new("given", _("First name"), NULL, FALSE);
223 purple_request_field_group_add_field(group, field);
224 field = purple_request_field_string_new("surname", _("Last name"), NULL, FALSE);
225 purple_request_field_group_add_field(group, field);
226 field = purple_request_field_string_new("email", _("Email"), NULL, FALSE);
227 purple_request_field_group_add_field(group, field);
228 field = purple_request_field_string_new("sipid", _("SIP ID"), NULL, FALSE);
229 purple_request_field_group_add_field(group, field);
230 field = purple_request_field_string_new("company", _("Company"), NULL, FALSE);
231 purple_request_field_group_add_field(group, field);
232 field = purple_request_field_string_new("country", _("Country"), NULL, FALSE);
233 purple_request_field_group_add_field(group, field);
235 purple_request_fields(gc,
236 _("Search"),
237 _("Search for a contact"),
238 _("Enter the information for the person you wish to find. Empty fields will be ignored."),
239 fields,
240 _("_Search"), G_CALLBACK(sipe_purple_find_contact_cb),
241 _("_Cancel"), NULL,
242 #if PURPLE_VERSION_CHECK(3,0,0)
243 purple_request_cpar_from_connection(gc),
244 #else
245 purple_connection_get_account(gc), NULL, NULL,
246 #endif
247 gc);
251 Local Variables:
252 mode: c
253 c-file-style: "bsd"
254 indent-tabs-mode: t
255 tab-width: 8
256 End: