2 * @file purple-search.c
6 * Copyright (C) 2011 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 struct sipe_backend_search_results
*sipe_backend_search_results_start(SIPE_UNUSED_PARAMETER
struct sipe_core_public
*sipe_public
)
40 PurpleNotifySearchResults
*results
= purple_notify_searchresults_new();
43 PurpleNotifySearchColumn
*column
;
44 column
= purple_notify_searchresults_column_new(_("User name"));
45 purple_notify_searchresults_column_add(results
, column
);
47 column
= purple_notify_searchresults_column_new(_("Name"));
48 purple_notify_searchresults_column_add(results
, column
);
50 column
= purple_notify_searchresults_column_new(_("Company"));
51 purple_notify_searchresults_column_add(results
, column
);
53 column
= purple_notify_searchresults_column_new(_("Country"));
54 purple_notify_searchresults_column_add(results
, column
);
56 column
= purple_notify_searchresults_column_new(_("Email"));
57 purple_notify_searchresults_column_add(results
, column
);
60 return((struct sipe_backend_search_results
*)results
);
63 void sipe_backend_search_results_add(SIPE_UNUSED_PARAMETER
struct sipe_core_public
*sipe_public
,
64 struct sipe_backend_search_results
*results
,
72 row
= g_list_append(row
, g_strdup(uri
));
73 row
= g_list_append(row
, g_strdup(name
));
74 row
= g_list_append(row
, g_strdup(company
));
75 row
= g_list_append(row
, g_strdup(country
));
76 row
= g_list_append(row
, g_strdup(email
));
77 purple_notify_searchresults_row_add((PurpleNotifySearchResults
*) results
,
81 static void searchresults_im_buddy(PurpleConnection
*gc
,
83 SIPE_UNUSED_PARAMETER
void *user_data
)
85 PurpleAccount
*acct
= purple_connection_get_account(gc
);
86 gchar
*id
= sip_uri_from_name(g_list_nth_data(row
, 0));
87 PurpleConversation
*conv
= purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM
,
91 conv
= purple_conversation_new(PURPLE_CONV_TYPE_IM
, acct
, id
);
93 purple_conversation_present(conv
);
96 static void searchresults_add_buddy(PurpleConnection
*gc
,
98 SIPE_UNUSED_PARAMETER
void *user_data
)
100 purple_blist_request_add_buddy(purple_connection_get_account(gc
),
101 g_list_nth_data(row
, 0),
103 g_list_nth_data(row
, 1));
107 void sipe_backend_search_results_finalize(struct sipe_core_public
*sipe_public
,
108 struct sipe_backend_search_results
*results
,
109 const gchar
*description
,
110 SIPE_UNUSED_PARAMETER gboolean more
)
112 struct sipe_backend_private
*purple_private
= sipe_public
->backend_private
;
113 PurpleNotifySearchResults
*r
= (PurpleNotifySearchResults
*) results
;
115 purple_notify_searchresults_button_add(r
,
116 PURPLE_NOTIFY_BUTTON_IM
,
117 searchresults_im_buddy
);
118 purple_notify_searchresults_button_add(r
,
119 PURPLE_NOTIFY_BUTTON_ADD
,
120 searchresults_add_buddy
);
121 purple_notify_searchresults(purple_private
->gc
,