2 * @file purple-search.c
6 * Copyright (C) 2011-12 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
31 #include "sipe-common.h"
32 #include "sipe-backend.h"
33 #include "sipe-core.h"
36 #include "purple-private.h"
38 void sipe_backend_search_failed(struct sipe_core_public
*sipe_public
,
39 SIPE_UNUSED_PARAMETER
struct sipe_backend_search_token
*token
,
42 sipe_backend_notify_error(sipe_public
, msg
, NULL
);
45 struct sipe_backend_search_results
*sipe_backend_search_results_start(SIPE_UNUSED_PARAMETER
struct sipe_core_public
*sipe_public
,
46 SIPE_UNUSED_PARAMETER
struct sipe_backend_search_token
*token
)
48 PurpleNotifySearchResults
*results
= purple_notify_searchresults_new();
51 PurpleNotifySearchColumn
*column
;
52 column
= purple_notify_searchresults_column_new(_("User name"));
53 purple_notify_searchresults_column_add(results
, column
);
55 column
= purple_notify_searchresults_column_new(_("Name"));
56 purple_notify_searchresults_column_add(results
, column
);
58 column
= purple_notify_searchresults_column_new(_("Company"));
59 purple_notify_searchresults_column_add(results
, column
);
61 column
= purple_notify_searchresults_column_new(_("Country"));
62 purple_notify_searchresults_column_add(results
, column
);
64 column
= purple_notify_searchresults_column_new(_("Email"));
65 purple_notify_searchresults_column_add(results
, column
);
68 return((struct sipe_backend_search_results
*)results
);
71 void sipe_backend_search_results_add(SIPE_UNUSED_PARAMETER
struct sipe_core_public
*sipe_public
,
72 struct sipe_backend_search_results
*results
,
80 row
= g_list_append(row
, g_strdup(uri
));
81 row
= g_list_append(row
, g_strdup(name
));
82 row
= g_list_append(row
, g_strdup(company
));
83 row
= g_list_append(row
, g_strdup(country
));
84 row
= g_list_append(row
, g_strdup(email
));
85 purple_notify_searchresults_row_add((PurpleNotifySearchResults
*) results
,
89 static void searchresults_im_buddy(PurpleConnection
*gc
,
91 SIPE_UNUSED_PARAMETER
void *user_data
)
93 PurpleAccount
*acct
= purple_connection_get_account(gc
);
94 gchar
*id
= sip_uri_from_name(g_list_nth_data(row
, 0));
95 PurpleConversation
*conv
= purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM
,
99 conv
= purple_conversation_new(PURPLE_CONV_TYPE_IM
, acct
, id
);
101 purple_conversation_present(conv
);
104 static void searchresults_add_buddy(PurpleConnection
*gc
,
106 SIPE_UNUSED_PARAMETER
void *user_data
)
108 purple_blist_request_add_buddy(purple_connection_get_account(gc
),
109 g_list_nth_data(row
, 0),
111 g_list_nth_data(row
, 1));
115 void sipe_backend_search_results_finalize(struct sipe_core_public
*sipe_public
,
116 struct sipe_backend_search_results
*results
,
117 const gchar
*description
,
118 SIPE_UNUSED_PARAMETER gboolean more
)
120 struct sipe_backend_private
*purple_private
= sipe_public
->backend_private
;
121 PurpleNotifySearchResults
*r
= (PurpleNotifySearchResults
*) results
;
123 purple_notify_searchresults_button_add(r
,
124 PURPLE_NOTIFY_BUTTON_IM
,
125 searchresults_im_buddy
);
126 purple_notify_searchresults_button_add(r
,
127 PURPLE_NOTIFY_BUTTON_ADD
,
128 searchresults_add_buddy
);
129 purple_notify_searchresults(purple_private
->gc
,