2 * @file miranda-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 "miranda-version.h"
32 #include "newpluginapi.h"
33 #include "m_protosvc.h"
34 #include "m_protoint.h"
38 #include "sipe-common.h"
39 #include "sipe-backend.h"
40 #include "sipe-core.h"
43 #include "miranda-private.h"
44 #include "miranda-resource.h"
46 struct sipe_backend_search_results
{
50 void sipe_backend_search_failed(struct sipe_core_public
*sipe_public
,
51 SIPE_UNUSED_PARAMETER
struct sipe_backend_search_token
*token
,
54 sipe_backend_notify_error(sipe_public
, msg
, NULL
);
57 struct sipe_backend_search_results
*sipe_backend_search_results_start(SIPE_UNUSED_PARAMETER
struct sipe_core_public
*sipe_public
,
58 SIPE_UNUSED_PARAMETER
struct sipe_backend_search_token
*token
)
60 return g_new0(struct sipe_backend_search_results
, 1);
63 void sipe_backend_search_results_add(SIPE_UNUSED_PARAMETER
struct sipe_core_public
*sipe_public
,
64 struct sipe_backend_search_results
*results
,
71 SIPPROTO
*pr
= sipe_public
->backend_private
;
72 PROTOSEARCHRESULT psr
= { 0 };
73 HANDLE hProcess
= (HANDLE
)1; /* g_hash_table_lookup(opts, "searchid"); */
76 psr
.cbSize
= sizeof(psr
);
77 psr
.id
= (PROTOCHAR
*)uri
;
78 nameparts
= g_strsplit_set(name
, ",", 2);
79 psr
.nick
= (FNAMECHAR
*)name
;
80 psr
.firstName
= (PROTOCHAR
*)(nameparts
[1] ? nameparts
[1] : NULL
);
81 psr
.lastName
= (PROTOCHAR
*)nameparts
[0];
82 psr
.email
= (PROTOCHAR
*)email
;
84 sipe_miranda_SendBroadcast(pr
, NULL
, ACKTYPE_SEARCH
, ACKRESULT_DATA
, hProcess
, (LPARAM
) & psr
);
85 g_strfreev(nameparts
);
88 void sipe_backend_search_results_finalize(struct sipe_core_public
*sipe_public
,
89 struct sipe_backend_search_results
*results
,
90 const gchar
*description
,
93 SIPPROTO
*pr
= sipe_public
->backend_private
;
94 HANDLE hProcess
= (HANDLE
)1; /* g_hash_table_lookup(opts, "searchid"); */
96 sipe_miranda_SendBroadcast(pr
, NULL
, ACKTYPE_SEARCH
, ACKRESULT_SUCCESS
, hProcess
, 0);
101 HANDLE
sipe_miranda_SearchByEmail( SIPPROTO
*pr
, const PROTOCHAR
* email
)
105 SIPE_DEBUG_INFO("SearchByEmail: email <%S>", email
);
106 if (!pr
->sip
) return NULL
;
108 mail
= mir_t2a(email
);
111 sipe_core_buddy_search(pr
->sip
, NULL
, NULL
, NULL
, NULL
, NULL
, mail
);
119 HANDLE
sipe_miranda_SearchByName( SIPPROTO
*pr
, const PROTOCHAR
* nick
, const PROTOCHAR
* firstName
, const PROTOCHAR
* lastName
)
123 SIPE_DEBUG_INFO("SearchByName: nick <%S> firstname <%S> lastname <%S>", nick
, firstName
, lastName
);
124 if (!pr
->sip
) return NULL
;
126 given_name
= mir_t2a(firstName
);
127 surname
= mir_t2a(lastName
);
130 sipe_core_buddy_search(pr
->sip
, NULL
, given_name
, surname
, NULL
, NULL
, NULL
);
133 mir_free(given_name
);
139 HWND
sipe_miranda_SearchAdvanced( SIPPROTO
*pr
, HWND owner
)
142 GHashTable
*query
= g_hash_table_new_full(NULL
,NULL
,NULL
,g_free
);
145 if (!pr
->sip
) return NULL
;
146 msg
= g_string_new("SearchAdvanced: ");
148 GetDlgItemTextA(owner
, IDC_SEARCH_FN
, buf
, sizeof(buf
));
151 g_string_append_printf(msg
, "firstname <%s> ", buf
);
152 g_hash_table_insert(query
, "givenName", g_strdup(buf
));
155 GetDlgItemTextA(owner
, IDC_SEARCH_LN
, buf
, sizeof(buf
));
158 g_string_append_printf(msg
, "lastname <%s> ", buf
);
159 g_hash_table_insert(query
, "sn", g_strdup(buf
));
162 GetDlgItemTextA(owner
, IDC_SEARCH_COMPANY
, buf
, sizeof(buf
));
165 g_string_append_printf(msg
, "company <%s> ", buf
);
166 g_hash_table_insert(query
, "company", g_strdup(buf
));
169 GetDlgItemTextA(owner
, IDC_SEARCH_COUNTRY
, buf
, sizeof(buf
));
172 g_string_append_printf(msg
, "country <%s> ", buf
);
173 g_hash_table_insert(query
, "c", g_strdup(buf
));
176 SIPE_DEBUG_INFO_NOFORMAT(msg
->str
);
177 g_string_free(msg
, TRUE
);
180 /* ret = (HANDLE)sipe_core_buddy_search( pr->sip, NULL, query, sipsimple_search_contact_cb, pr); */