build: replace deprecated glib2 functions
[siplcs.git] / src / miranda / miranda-search.c
blob291e87205a78a07e15d64eaac2925e184d8f41d3
1 /**
2 * @file miranda-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 <windows.h>
28 #include <glib.h>
29 #include <stdio.h>
31 #include "miranda-version.h"
32 #include "newpluginapi.h"
33 #include "m_protosvc.h"
34 #include "m_protoint.h"
35 #include "m_system.h"
36 #include "m_utils.h"
38 #include "sipe-common.h"
39 #include "sipe-backend.h"
40 #include "sipe-core.h"
41 #include "sipe-nls.h"
43 #include "miranda-private.h"
44 #include "miranda-resource.h"
46 struct sipe_backend_search_results {
47 int dummy;
50 struct sipe_backend_search_results *sipe_backend_search_results_start(SIPE_UNUSED_PARAMETER struct sipe_core_public *sipe_public)
52 return g_new0(struct sipe_backend_search_results, 1);
55 void sipe_backend_search_results_add(SIPE_UNUSED_PARAMETER struct sipe_core_public *sipe_public,
56 struct sipe_backend_search_results *results,
57 const gchar *uri,
58 const gchar *name,
59 const gchar *company,
60 const gchar *country,
61 const gchar *email)
63 SIPPROTO *pr = sipe_public->backend_private;
64 PROTOSEARCHRESULT psr = { 0 };
65 HANDLE hProcess = (HANDLE)1; /* g_hash_table_lookup(opts, "searchid"); */
66 gchar **nameparts;
68 psr.cbSize = sizeof(psr);
69 psr.id = (PROTOCHAR*)uri;
70 nameparts = g_strsplit_set(name, ",", 2);
71 psr.nick = (FNAMECHAR*)name;
72 psr.firstName = (PROTOCHAR*)(nameparts[1] ? nameparts[1] : NULL);
73 psr.lastName = (PROTOCHAR*)nameparts[0];
74 psr.email = (PROTOCHAR*)email;
76 sipe_miranda_SendBroadcast(pr, NULL, ACKTYPE_SEARCH, ACKRESULT_DATA, hProcess, (LPARAM) & psr);
77 g_strfreev(nameparts);
80 void sipe_backend_search_results_finalize(struct sipe_core_public *sipe_public,
81 struct sipe_backend_search_results *results,
82 const gchar *description,
83 gboolean more)
85 SIPPROTO *pr = sipe_public->backend_private;
86 HANDLE hProcess = (HANDLE)1; /* g_hash_table_lookup(opts, "searchid"); */
88 sipe_miranda_SendBroadcast(pr, NULL, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, hProcess, 0);
90 g_free(results);
93 HANDLE sipe_miranda_SearchByEmail( SIPPROTO *pr, const PROTOCHAR* email )
95 char *mail;
97 SIPE_DEBUG_INFO("SearchByEmail: email <%S>", email);
98 if (!pr->sip) return NULL;
100 mail = mir_t2a(email);
102 LOCK;
103 sipe_core_buddy_search(pr->sip, NULL, NULL, NULL, NULL, mail);
104 UNLOCK;
106 mir_free(mail);
108 return (HANDLE)1;
111 HANDLE sipe_miranda_SearchByName( SIPPROTO *pr, const PROTOCHAR* nick, const PROTOCHAR* firstName, const PROTOCHAR* lastName)
113 char *given_name;
114 char *surname;
115 SIPE_DEBUG_INFO("SearchByName: nick <%S> firstname <%S> lastname <%S>", nick, firstName, lastName);
116 if (!pr->sip) return NULL;
118 given_name = mir_t2a(firstName);
119 surname = mir_t2a(lastName);
121 LOCK;
122 sipe_core_buddy_search(pr->sip, given_name, surname, NULL, NULL, NULL);
123 UNLOCK;
125 mir_free(given_name);
126 mir_free(surname);
128 return (HANDLE)1;
131 HWND sipe_miranda_SearchAdvanced( SIPPROTO *pr, HWND owner )
133 char buf[512];
134 GHashTable *query = g_hash_table_new_full(NULL,NULL,NULL,g_free);
135 GString *msg;
137 if (!pr->sip) return NULL;
138 msg = g_string_new("SearchAdvanced: ");
140 GetDlgItemTextA(owner, IDC_SEARCH_FN, buf, sizeof(buf));
141 if (strlen(buf))
143 g_string_append_printf(msg, "firstname <%s> ", buf);
144 g_hash_table_insert(query, "givenName", g_strdup(buf));
147 GetDlgItemTextA(owner, IDC_SEARCH_LN, buf, sizeof(buf));
148 if (strlen(buf))
150 g_string_append_printf(msg, "lastname <%s> ", buf);
151 g_hash_table_insert(query, "sn", g_strdup(buf));
154 GetDlgItemTextA(owner, IDC_SEARCH_COMPANY, buf, sizeof(buf));
155 if (strlen(buf))
157 g_string_append_printf(msg, "company <%s> ", buf);
158 g_hash_table_insert(query, "company", g_strdup(buf));
161 GetDlgItemTextA(owner, IDC_SEARCH_COUNTRY, buf, sizeof(buf));
162 if (strlen(buf))
164 g_string_append_printf(msg, "country <%s> ", buf);
165 g_hash_table_insert(query, "c", g_strdup(buf));
168 SIPE_DEBUG_INFO_NOFORMAT(msg->str);
169 g_string_free(msg, TRUE);
171 LOCK;
172 /* ret = (HANDLE)sipe_core_buddy_search( pr->sip, query, sipsimple_search_contact_cb, pr); */
173 UNLOCK;
175 return (HANDLE)1;
180 Local Variables:
181 mode: c
182 c-file-style: "bsd"
183 indent-tabs-mode: t
184 tab-width: 8
185 End: