2 * @file purple-search.c
6 * Copyright (C) 2011-2014 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
33 #if PURPLE_VERSION_CHECK(3,0,0)
34 #include "conversations.h"
37 #include "sipe-common.h"
38 #include "sipe-backend.h"
39 #include "sipe-core.h"
42 #include "purple-private.h"
44 void sipe_backend_search_failed(struct sipe_core_public
*sipe_public
,
45 SIPE_UNUSED_PARAMETER
struct sipe_backend_search_token
*token
,
48 sipe_backend_notify_error(sipe_public
, msg
, NULL
);
51 struct sipe_backend_search_results
*sipe_backend_search_results_start(SIPE_UNUSED_PARAMETER
struct sipe_core_public
*sipe_public
,
52 SIPE_UNUSED_PARAMETER
struct sipe_backend_search_token
*token
)
54 PurpleNotifySearchResults
*results
= purple_notify_searchresults_new();
57 PurpleNotifySearchColumn
*column
;
58 column
= purple_notify_searchresults_column_new(_("User name"));
59 purple_notify_searchresults_column_add(results
, column
);
61 column
= purple_notify_searchresults_column_new(_("Name"));
62 purple_notify_searchresults_column_add(results
, column
);
64 column
= purple_notify_searchresults_column_new(_("Company"));
65 purple_notify_searchresults_column_add(results
, column
);
67 column
= purple_notify_searchresults_column_new(_("Country"));
68 purple_notify_searchresults_column_add(results
, column
);
70 column
= purple_notify_searchresults_column_new(_("Email"));
71 purple_notify_searchresults_column_add(results
, column
);
74 return((struct sipe_backend_search_results
*)results
);
77 void sipe_backend_search_results_add(SIPE_UNUSED_PARAMETER
struct sipe_core_public
*sipe_public
,
78 struct sipe_backend_search_results
*results
,
86 row
= g_list_append(row
, g_strdup(uri
));
87 row
= g_list_append(row
, g_strdup(name
));
88 row
= g_list_append(row
, g_strdup(company
));
89 row
= g_list_append(row
, g_strdup(country
));
90 row
= g_list_append(row
, g_strdup(email
));
91 purple_notify_searchresults_row_add((PurpleNotifySearchResults
*) results
,
95 static void searchresults_im_buddy(PurpleConnection
*gc
,
97 SIPE_UNUSED_PARAMETER
void *user_data
)
99 PurpleAccount
*acct
= purple_connection_get_account(gc
);
100 gchar
*id
= sip_uri_from_name(g_list_nth_data(row
, 0));
102 #if PURPLE_VERSION_CHECK(3,0,0)
103 PurpleIMConversation
*conv
= purple_conversations_find_im_with_account(id
,
107 conv
= purple_im_conversation_new(acct
, id
);
109 PurpleConversation
*conv
= purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM
,
113 conv
= purple_conversation_new(PURPLE_CONV_TYPE_IM
, acct
, id
);
117 purple_conversation_present((PurpleConversation
*) conv
);
120 static void searchresults_add_buddy(PurpleConnection
*gc
,
122 SIPE_UNUSED_PARAMETER
void *user_data
)
124 purple_blist_request_add_buddy(purple_connection_get_account(gc
),
125 g_list_nth_data(row
, 0),
127 g_list_nth_data(row
, 1));
131 void sipe_backend_search_results_finalize(struct sipe_core_public
*sipe_public
,
132 struct sipe_backend_search_results
*results
,
133 const gchar
*description
,
134 SIPE_UNUSED_PARAMETER gboolean more
)
136 struct sipe_backend_private
*purple_private
= sipe_public
->backend_private
;
137 PurpleNotifySearchResults
*r
= (PurpleNotifySearchResults
*) results
;
139 purple_notify_searchresults_button_add(r
,
140 PURPLE_NOTIFY_BUTTON_IM
,
141 searchresults_im_buddy
);
142 purple_notify_searchresults_button_add(r
,
143 PURPLE_NOTIFY_BUTTON_ADD
,
144 searchresults_add_buddy
);
145 purple_notify_searchresults(purple_private
->gc
,
155 static void sipe_purple_find_contact_cb(PurpleConnection
*gc
,
156 PurpleRequestFields
*fields
)
158 GList
*entries
= purple_request_field_group_get_fields(purple_request_fields_get_groups(fields
)->data
);
159 const gchar
*given_name
= NULL
;
160 const gchar
*surname
= NULL
;
161 const gchar
*email
= NULL
;
162 const gchar
*company
= NULL
;
163 const gchar
*country
= NULL
;
166 PurpleRequestField
*field
= entries
->data
;
167 const char *id
= purple_request_field_get_id(field
);
168 const char *value
= purple_request_field_string_get_value(field
);
170 SIPE_DEBUG_INFO("sipe_purple_find_contact_cb: %s = '%s'", id
, value
? value
: "");
172 if (value
&& strlen(value
)) {
173 if (strcmp(id
, "given") == 0) {
175 } else if (strcmp(id
, "surname") == 0) {
177 } else if (strcmp(id
, "email") == 0) {
179 } else if (strcmp(id
, "sipid") == 0) {
181 } else if (strcmp(id
, "company") == 0) {
183 } else if (strcmp(id
, "country") == 0) {
188 entries
= g_list_next(entries
);
191 sipe_core_buddy_search(PURPLE_GC_TO_SIPE_CORE_PUBLIC
,
200 void sipe_purple_show_find_contact(PurplePluginAction
*action
)
202 PurpleConnection
*gc
= (PurpleConnection
*) action
->context
;
203 PurpleRequestFields
*fields
;
204 PurpleRequestFieldGroup
*group
;
205 PurpleRequestField
*field
;
207 fields
= purple_request_fields_new();
208 group
= purple_request_field_group_new(NULL
);
209 purple_request_fields_add_group(fields
, group
);
211 field
= purple_request_field_string_new("given", _("First name"), NULL
, FALSE
);
212 purple_request_field_group_add_field(group
, field
);
213 field
= purple_request_field_string_new("surname", _("Last name"), NULL
, FALSE
);
214 purple_request_field_group_add_field(group
, field
);
215 field
= purple_request_field_string_new("email", _("Email"), NULL
, FALSE
);
216 purple_request_field_group_add_field(group
, field
);
217 field
= purple_request_field_string_new("sipid", _("SIP ID"), NULL
, FALSE
);
218 purple_request_field_group_add_field(group
, field
);
219 field
= purple_request_field_string_new("company", _("Company"), NULL
, FALSE
);
220 purple_request_field_group_add_field(group
, field
);
221 field
= purple_request_field_string_new("country", _("Country"), NULL
, FALSE
);
222 purple_request_field_group_add_field(group
, field
);
224 purple_request_fields(gc
,
226 _("Search for a contact"),
227 _("Enter the information for the person you wish to find. Empty fields will be ignored."),
229 _("_Search"), G_CALLBACK(sipe_purple_find_contact_cb
),
231 #if PURPLE_VERSION_CHECK(3,0,0)
232 purple_request_cpar_from_connection(gc
),
234 purple_connection_get_account(gc
), NULL
, NULL
,