2 * @file purple-search.c
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
35 #if PURPLE_VERSION_CHECK(3,0,0)
36 #include "conversations.h"
39 #include "sipe-common.h"
40 #include "sipe-backend.h"
41 #include "sipe-core.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
,
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();
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
,
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
,
97 static void searchresults_im_buddy(PurpleConnection
*gc
,
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
,
109 conv
= purple_im_conversation_new(acct
, id
);
111 PurpleConversation
*conv
= purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM
,
115 conv
= purple_conversation_new(PURPLE_CONV_TYPE_IM
, acct
, id
);
119 purple_conversation_present((PurpleConversation
*) conv
);
122 static void searchresults_add_buddy(PurpleConnection
*gc
,
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),
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
,
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
;
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) {
178 } else if (strcmp(id
, "surname") == 0) {
180 } else if (strcmp(id
, "email") == 0) {
182 } else if (strcmp(id
, "sipid") == 0) {
184 } else if (strcmp(id
, "company") == 0) {
186 } else if (strcmp(id
, "country") == 0) {
191 entries
= g_list_next(entries
);
194 sipe_core_buddy_search(PURPLE_GC_TO_SIPE_CORE_PUBLIC
,
204 #if PURPLE_VERSION_CHECK(3,0,0)
205 void sipe_purple_show_find_contact(PurpleProtocolAction
*action
)
207 PurpleConnection
*gc
= action
->connection
;
209 void sipe_purple_show_find_contact(PurplePluginAction
*action
)
211 PurpleConnection
*gc
= (PurpleConnection
*) action
->context
;
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
,
236 _("Search for a contact"),
237 _("Enter the information for the person you wish to find. Empty fields will be ignored."),
239 _("_Search"), G_CALLBACK(sipe_purple_find_contact_cb
),
241 #if PURPLE_VERSION_CHECK(3,0,0)
242 purple_request_cpar_from_connection(gc
),
244 purple_connection_get_account(gc
), NULL
, NULL
,