core cleanup: core/backend API changes after review
[siplcs.git] / src / purple / purple-search.c
blob84b44819fa9c4ccca321acb316e29f1350fdfb87
1 /**
2 * @file purple-search.c
4 * pidgin-sipe
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
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
27 #include <glib.h>
29 #include "notify.h"
31 #include "sipe-common.h"
32 #include "sipe-backend.h"
33 #include "sipe-core.h"
34 #include "sipe-nls.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();
42 if (results) {
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,
65 const gchar *uri,
66 const gchar *name,
67 const gchar *company,
68 const gchar *country,
69 const gchar *email)
71 GList *row = NULL;
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,
78 row);
81 static void searchresults_im_buddy(PurpleConnection *gc,
82 GList *row,
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,
88 id,
89 acct);
90 if (conv == NULL)
91 conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, acct, id);
92 g_free(id);
93 purple_conversation_present(conv);
96 static void searchresults_add_buddy(PurpleConnection *gc,
97 GList *row,
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),
102 _("Other Contacts"),
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,
122 NULL,
123 NULL,
124 description,
126 NULL,
127 NULL);
132 Local Variables:
133 mode: c
134 c-file-style: "bsd"
135 indent-tabs-mode: t
136 tab-width: 8
137 End: