purple: add support for latest appstreamcli
[siplcs.git] / src / miranda / miranda-search.c
blob9eec8a1aa8d33ba14d2dcbe1bb72b431d4ce3d30
1 /**
2 * @file miranda-search.c
4 * pidgin-sipe
6 * Copyright (C) 2011-2018 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 #include <windows.h>
24 #include <glib.h>
25 #include <stdio.h>
27 #include "miranda-version.h"
28 #include "newpluginapi.h"
29 #include "m_protosvc.h"
30 #include "m_protoint.h"
31 #include "m_system.h"
32 #include "m_utils.h"
34 #include "sipe-common.h"
35 #include "sipe-backend.h"
36 #include "sipe-core.h"
38 #include "miranda-private.h"
39 #include "miranda-resource.h"
41 struct sipe_backend_search_results {
42 int dummy;
45 void sipe_backend_search_failed(struct sipe_core_public *sipe_public,
46 SIPE_UNUSED_PARAMETER struct sipe_backend_search_token *token,
47 const gchar *msg)
49 sipe_miranda_SendBroadcast(sipe_public->backend_private, NULL, ACKTYPE_SEARCH, ACKRESULT_FAILED, (HANDLE)1, 0);
50 sipe_backend_notify_error(sipe_public, msg, NULL);
53 struct sipe_backend_search_results *sipe_backend_search_results_start(SIPE_UNUSED_PARAMETER struct sipe_core_public *sipe_public,
54 SIPE_UNUSED_PARAMETER struct sipe_backend_search_token *token)
56 return g_new0(struct sipe_backend_search_results, 1);
59 void sipe_backend_search_results_add(SIPE_UNUSED_PARAMETER struct sipe_core_public *sipe_public,
60 struct sipe_backend_search_results *results,
61 const gchar *uri,
62 const gchar *name,
63 const gchar *company,
64 const gchar *country,
65 const gchar *email)
67 SIPPROTO *pr = sipe_public->backend_private;
68 PROTOSEARCHRESULT psr = { 0 };
69 HANDLE hProcess = (HANDLE)1; /* g_hash_table_lookup(opts, "searchid"); */
70 gchar **nameparts;
72 psr.cbSize = sizeof(psr);
73 psr.id = (PROTOCHAR*)uri;
74 nameparts = g_strsplit_set(name, ",", 2);
75 psr.nick = (FNAMECHAR*)name;
76 psr.firstName = (PROTOCHAR*)(nameparts[1] ? nameparts[1] : NULL);
77 psr.lastName = (PROTOCHAR*)nameparts[0];
78 psr.email = (PROTOCHAR*)email;
80 sipe_miranda_SendBroadcast(pr, NULL, ACKTYPE_SEARCH, ACKRESULT_DATA, hProcess, (LPARAM) & psr);
81 g_strfreev(nameparts);
84 void sipe_backend_search_results_finalize(struct sipe_core_public *sipe_public,
85 struct sipe_backend_search_results *results,
86 const gchar *description,
87 gboolean more)
89 SIPPROTO *pr = sipe_public->backend_private;
90 HANDLE hProcess = (HANDLE)1; /* g_hash_table_lookup(opts, "searchid"); */
92 sipe_miranda_SendBroadcast(pr, NULL, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, hProcess, 0);
94 g_free(results);
97 HANDLE sipe_miranda_SearchByEmail( SIPPROTO *pr, const PROTOCHAR* email )
99 char *mail;
101 SIPE_DEBUG_INFO("SearchByEmail: email <%S>", email);
102 if (!pr->sip) return NULL;
104 mail = mir_t2a(email);
106 LOCK;
107 sipe_core_buddy_search(pr->sip, NULL, NULL, NULL, mail, NULL, NULL, NULL);
108 UNLOCK;
110 mir_free(mail);
112 return (HANDLE)1;
115 HANDLE sipe_miranda_SearchByName( SIPPROTO *pr, const PROTOCHAR* nick, const PROTOCHAR* firstName, const PROTOCHAR* lastName)
117 char *given_name;
118 char *surname;
119 SIPE_DEBUG_INFO("SearchByName: nick <%S> firstname <%S> lastname <%S>", nick, firstName, lastName);
120 if (!pr->sip) return NULL;
122 given_name = mir_t2a(firstName);
123 surname = mir_t2a(lastName);
125 LOCK;
126 sipe_core_buddy_search(pr->sip, NULL, given_name, surname, NULL, NULL, NULL, NULL);
127 UNLOCK;
129 mir_free(given_name);
130 mir_free(surname);
132 return (HANDLE)1;
135 HWND sipe_miranda_SearchAdvanced( SIPPROTO *pr, HWND owner )
137 char buf[512];
138 GHashTable *query = g_hash_table_new_full(NULL,NULL,NULL,g_free);
139 GString *msg;
141 if (!pr->sip) return NULL;
142 msg = g_string_new("SearchAdvanced: ");
144 GetDlgItemTextA(owner, IDC_SEARCH_FN, buf, sizeof(buf));
145 if (strlen(buf))
147 g_string_append_printf(msg, "firstname <%s> ", buf);
148 g_hash_table_insert(query, "givenName", g_strdup(buf));
151 GetDlgItemTextA(owner, IDC_SEARCH_LN, buf, sizeof(buf));
152 if (strlen(buf))
154 g_string_append_printf(msg, "lastname <%s> ", buf);
155 g_hash_table_insert(query, "sn", g_strdup(buf));
158 GetDlgItemTextA(owner, IDC_SEARCH_COMPANY, buf, sizeof(buf));
159 if (strlen(buf))
161 g_string_append_printf(msg, "company <%s> ", buf);
162 g_hash_table_insert(query, "company", g_strdup(buf));
165 GetDlgItemTextA(owner, IDC_SEARCH_COUNTRY, buf, sizeof(buf));
166 if (strlen(buf))
168 g_string_append_printf(msg, "country <%s> ", buf);
169 g_hash_table_insert(query, "c", g_strdup(buf));
172 SIPE_DEBUG_INFO_NOFORMAT(msg->str);
173 g_string_free(msg, TRUE);
175 LOCK;
176 sipe_backend_search_failed(pr->sip, NULL, "Not implemented");
178 /* ret = (HANDLE)sipe_core_buddy_search( pr->sip, NULL, query, sipsimple_search_contact_cb, pr); */
179 UNLOCK;
181 return (HANDLE)1;
186 Local Variables:
187 mode: c
188 c-file-style: "bsd"
189 indent-tabs-mode: t
190 tab-width: 8
191 End: