2 * @file purple-search.c
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
35 #if PURPLE_VERSION_CHECK(3,0,0)
37 #include "conversations.h"
40 #include "sipe-common.h"
41 #include "sipe-backend.h"
42 #include "sipe-core.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
,
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();
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
,
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
,
98 static void searchresults_im_buddy(PurpleConnection
*gc
,
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
,
110 conv
= purple_im_conversation_new(acct
, id
);
112 PurpleConversation
*conv
= purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM
,
116 conv
= purple_conversation_new(PURPLE_CONV_TYPE_IM
, acct
, id
);
120 purple_conversation_present((PurpleConversation
*) conv
);
123 static void searchresults_add_buddy(PurpleConnection
*gc
,
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),
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
,
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
;
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) {
179 } else if (strcmp(id
, "surname") == 0) {
181 } else if (strcmp(id
, "email") == 0) {
183 } else if (strcmp(id
, "sipid") == 0) {
185 } else if (strcmp(id
, "company") == 0) {
187 } else if (strcmp(id
, "country") == 0) {
192 entries
= g_list_next(entries
);
195 sipe_core_buddy_search(PURPLE_GC_TO_SIPE_CORE_PUBLIC
,
205 #if PURPLE_VERSION_CHECK(3,0,0)
206 void sipe_purple_show_find_contact(PurpleProtocolAction
*action
)
208 PurpleConnection
*gc
= action
->connection
;
210 void sipe_purple_show_find_contact(PurplePluginAction
*action
)
212 PurpleConnection
*gc
= (PurpleConnection
*) action
->context
;
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
,
237 _("Search for a contact"),
238 _("Enter the information for the person you wish to find. Empty fields will be ignored."),
240 _("_Search"), G_CALLBACK(sipe_purple_find_contact_cb
),
242 #if PURPLE_VERSION_CHECK(3,0,0)
243 purple_request_cpar_from_connection(gc
),
245 purple_connection_get_account(gc
), NULL
, NULL
,