summaryrefslogtreecommitdiff
path: root/icqj_s7_sss_mod/icq_advsearch.c
blob: 40f49ae86dbb0326a0116b864403f0c605e73238 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
// ---------------------------------------------------------------------------80
//                ICQ plugin for Miranda Instant Messenger
//                ________________________________________
// 
// Copyright  2000,2001 Richard Hughes, Roland Rabien, Tristan Van de Vreede
// Copyright  2001,2002 Jon Keating, Richard Hughes
// Copyright  2002,2003,2004 Martin berg, Sam Kothari, Robert Rainwater
// Copyright  2004,2005,2006,2007 Joe Kucera
// Copyright  2006,2007 [sss], chaos.persei, [sin], Faith Healer, Theif, nullbie
// 
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
//
// -----------------------------------------------------------------------------
//
// File name      : $Source$
// Revision       : $Revision: 36 $
// Last change on : $Date: 2007-08-05 03:45:10 +0300 (Вс, 05 авг 2007) $
// Last change by : $Author: sss123next $
//
// DESCRIPTION:
//
//  Describe me here please...
//
// -----------------------------------------------------------------------------

#include "icqoscar.h"



static void InitComboBox(HWND hwndCombo,struct fieldnames_t *names)
{
  int iItem;
  int i;

  iItem = ComboBoxAddStringUtf(hwndCombo, "", 0);
  SendMessage(hwndCombo, CB_SETCURSEL, iItem, 0);

  for (i = 0; ; i++)
  {
    if (names[i].text == NULL)
      break;
    
    iItem = ComboBoxAddStringUtf(hwndCombo, names[i].text, names[i].code);
  }
}



BOOL CALLBACK AdvancedSearchDlgProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
  switch(message)
  {
    case WM_INITDIALOG:
      ICQTranslateDialog(hwndDlg);
      InitComboBox(GetDlgItem(hwndDlg, IDC_GENDER), genderField);
      InitComboBox(GetDlgItem(hwndDlg, IDC_AGERANGE), agesField);
      InitComboBox(GetDlgItem(hwndDlg, IDC_MARITALSTATUS), maritalField);
      InitComboBox(GetDlgItem(hwndDlg, IDC_WORKFIELD), workField);
      InitComboBox(GetDlgItem(hwndDlg, IDC_ORGANISATION), affiliationField);
      InitComboBox(GetDlgItem(hwndDlg, IDC_LANGUAGE), languageField);

      {
        struct CountryListEntry *countries;
        int countryCount;
        int i;
        int iItem;
        HWND hCombo;

        CallService(MS_UTILS_GETCOUNTRYLIST, (WPARAM)&countryCount, (LPARAM)&countries);

        hCombo = GetDlgItem(hwndDlg, IDC_COUNTRY);
        iItem = ComboBoxAddStringUtf(hCombo, "", 0);
        SendMessage(hCombo, CB_SETCURSEL, iItem, 0);
        for (i = 0; i < countryCount; i++)
        {
          if (countries[i].id == 0 || countries[i].id == 0xFFFF)
            continue;
          iItem = ComboBoxAddStringUtf(hCombo, countries[i].szName, countries[i].id);
        }
      }

      InitComboBox(GetDlgItem(hwndDlg, IDC_INTERESTSCAT), interestsField);
      InitComboBox(GetDlgItem(hwndDlg, IDC_PASTCAT), pastField);

      return TRUE;
      
    case WM_COMMAND:
      {
        switch(LOWORD(wParam))
        {
          
        case IDOK:
          SendMessage(GetParent(hwndDlg), WM_COMMAND, MAKEWPARAM(IDOK, BN_CLICKED), (LPARAM)GetDlgItem(GetParent(hwndDlg), IDOK));
          break;
          
        case IDCANCEL:
          //          CheckDlgButton(GetParent(hwndDlg),IDC_ADVANCED,BST_UNCHECKED);
          //          SendMessage(GetParent(hwndDlg),WM_COMMAND,MAKEWPARAM(IDC_ADVANCED,BN_CLICKED),(LPARAM)GetDlgItem(GetParent(hwndDlg),IDC_ADVANCED));
          break;
          
        default:
          break;
          
        }
        break;
      }

    default:
      break;
  }

  return FALSE;
}



static DWORD getCurItemData(HWND hwndDlg, UINT iCtrl)
{
  return SendDlgItemMessage(hwndDlg, iCtrl, CB_GETITEMDATA, SendDlgItemMessage(hwndDlg, iCtrl, CB_GETCURSEL, 0, 0), 0);
}



static void searchPackTLVLNTS(PBYTE *buf, int *buflen, HWND hwndDlg, UINT idControl, WORD wType)
{
  char str[512];

  GetDlgItemText(hwndDlg, idControl, str, sizeof(str));

  ppackTLVLNTS(buf, buflen, str, wType, 0);
}



static void searchPackTLVWordLNTS(PBYTE *buf, int *buflen, HWND hwndDlg, UINT idControl, WORD w, WORD wType)
{
  char str[512];

  GetDlgItemText(hwndDlg, idControl, str, sizeof(str));

  ppackTLVWordLNTS(buf, buflen, w, str, wType, 0);
}



static PBYTE createAdvancedSearchStructureTLV(HWND hwndDlg, int *length)
{
  PBYTE buf = NULL;
  int buflen = 0;
  WORD w;

  ppackLEWord(&buf, &buflen, META_SEARCH_GENERIC);       /* subtype: full search */

  searchPackTLVLNTS(&buf, &buflen, hwndDlg, IDC_FIRSTNAME, TLV_FIRSTNAME);
  searchPackTLVLNTS(&buf, &buflen, hwndDlg, IDC_LASTNAME, TLV_LASTNAME);
  searchPackTLVLNTS(&buf, &buflen, hwndDlg, IDC_NICK, TLV_NICKNAME);
  searchPackTLVLNTS(&buf, &buflen, hwndDlg, IDC_EMAIL, TLV_EMAIL);
  searchPackTLVLNTS(&buf, &buflen, hwndDlg, IDC_CITY, TLV_CITY);
  searchPackTLVLNTS(&buf, &buflen, hwndDlg, IDC_STATE, TLV_STATE);
  searchPackTLVLNTS(&buf, &buflen, hwndDlg, IDC_COMPANY, TLV_COMPANY);
  searchPackTLVLNTS(&buf, &buflen, hwndDlg, IDC_DEPARTMENT, TLV_DEPARTMENT);
  searchPackTLVLNTS(&buf, &buflen, hwndDlg, IDC_POSITION, TLV_POSITION);
  searchPackTLVLNTS(&buf, &buflen, hwndDlg, IDC_KEYWORDS, TLV_KEYWORDS);

  ppackTLVDWord(&buf, &buflen, (DWORD)getCurItemData(hwndDlg, IDC_AGERANGE),      TLV_AGERANGE,  0);
  ppackTLVByte(&buf,  &buflen, (BYTE)getCurItemData(hwndDlg,  IDC_GENDER),        TLV_GENDER,    0);
  ppackTLVByte(&buf,  &buflen, (BYTE)getCurItemData(hwndDlg,  IDC_MARITALSTATUS), TLV_MARITAL,   0);
  ppackTLVWord(&buf,  &buflen, (WORD)getCurItemData(hwndDlg,  IDC_LANGUAGE),      TLV_LANGUAGE,  0);
  ppackTLVWord(&buf,  &buflen, (WORD)getCurItemData(hwndDlg,  IDC_COUNTRY),       TLV_COUNTRY,   0);
  ppackTLVWord(&buf,  &buflen, (WORD)getCurItemData(hwndDlg,  IDC_WORKFIELD),     TLV_OCUPATION, 0);

  w = (WORD)getCurItemData(hwndDlg, IDC_PASTCAT);
  searchPackTLVWordLNTS(&buf, &buflen, hwndDlg, IDC_PASTKEY, w, TLV_PASTINFO);

  w = (WORD)getCurItemData(hwndDlg, IDC_INTERESTSCAT);
  searchPackTLVWordLNTS(&buf, &buflen, hwndDlg, IDC_INTERESTSKEY, w, TLV_INTERESTS);

  w = (WORD)getCurItemData(hwndDlg, IDC_ORGANISATION);
  searchPackTLVWordLNTS(&buf, &buflen, hwndDlg, IDC_ORGKEYWORDS, w, TLV_AFFILATIONS);

  w = (WORD)getCurItemData(hwndDlg, IDC_HOMEPAGECAT);;
  searchPackTLVWordLNTS(&buf, &buflen, hwndDlg, IDC_HOMEPAGEKEY, w, TLV_HOMEPAGE);

  ppackTLVByte(&buf, &buflen, (BYTE)IsDlgButtonChecked(hwndDlg, IDC_ONLINEONLY), TLV_ONLINEONLY, 1);

  if (length)
    *length = buflen;

  return buf;
}



PBYTE createAdvancedSearchStructure(HWND hwndDlg, int *length)
{
  if (!hwndDlg)
    return NULL;

  return createAdvancedSearchStructureTLV(hwndDlg, length);
}