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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
|
/*
Kopete Oscar Protocol
icqsearchdialog.cpp - search for people
Copyright (c) 2005 Matt Rogers <mattr@kde.org>
Kopete (c) 2002-2005 by the Kopete developers <kopete-devel@kde.org>
*************************************************************************
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
*************************************************************************
*/
#include "icqsearchdialog.h"
#include <tqlineedit.h>
#include <tqcheckbox.h>
#include <tqcombobox.h>
#include <tqlayout.h>
#include <tqtextcodec.h>
#include <tqtabwidget.h>
#include <kdebug.h>
#include <kiconloader.h>
#include <klistview.h>
#include <klocale.h>
#include <kpushbutton.h>
#include <kmessagebox.h>
#include "kopeteuiglobal.h"
#include "icqaccount.h"
#include "icqaddcontactpage.h"
#include "icqprotocol.h"
#include "icqsearchbase.h"
#include "oscartypes.h"
#include "icqcontact.h"
#include "icquserinfowidget.h"
ICQSearchDialog::ICQSearchDialog( ICQAccount* account, TQWidget* tqparent, const char* name )
: KDialogBase( tqparent, name, true, i18n( "ICQ User Search" ), 0, NoDefault )
{
m_account = account;
m_searchUI = new ICQSearchBase( this, name );
setMainWidget( m_searchUI );
connect( m_searchUI->searchButton, TQT_SIGNAL( clicked() ), this, TQT_SLOT( startSearch() ) );
connect( m_searchUI->searchResults, TQT_SIGNAL( selectionChanged() ), this, TQT_SLOT( resultSelectionChanged() ) );
connect( m_searchUI->addButton, TQT_SIGNAL( clicked() ), this, TQT_SLOT( addContact() ) );
connect( m_searchUI->clearButton, TQT_SIGNAL( clicked() ), this, TQT_SLOT( clearResults() ) );
connect( m_searchUI->stopButton, TQT_SIGNAL( clicked() ), this, TQT_SLOT( stopSearch() ) );
connect( m_searchUI->closeButton, TQT_SIGNAL( clicked() ), this, TQT_SLOT( closeDialog() ) );
connect( m_searchUI->userInfoButton, TQT_SIGNAL( clicked() ), this, TQT_SLOT( userInfo() ) );
connect( m_searchUI->newSearchButton, TQT_SIGNAL( clicked() ), this, TQT_SLOT( newSearch() ) );
ICQProtocol *p = ICQProtocol::protocol();
p->fillComboFromTable( m_searchUI->gender, p->genders() );
p->fillComboFromTable( m_searchUI->country, p->countries() );
p->fillComboFromTable( m_searchUI->language, p->languages() );
m_contact = NULL;
m_infoWidget = NULL;
m_contact = NULL;
m_infoWidget = NULL;
}
ICQSearchDialog::~ICQSearchDialog()
{
}
void ICQSearchDialog::startSearch()
{
// Doing the search only if the account is online, otherwise warn the user
if(!m_account->isConnected())
{
// Account currently offline
m_searchUI->searchButton->setEnabled( false );
KMessageBox::sorry( this, i18n("You must be online to search the ICQ Whitepages."), i18n("ICQ Plugin") );
}
else
{
// Account is online
clearResults();
m_searchUI->stopButton->setEnabled( true );
m_searchUI->searchButton->setEnabled( false );
m_searchUI->newSearchButton->setEnabled( false );
connect( m_account->engine(), TQT_SIGNAL( gotSearchResults( const ICQSearchResult& ) ),
this, TQT_SLOT( newResult( const ICQSearchResult& ) ) );
connect( m_account->engine(), TQT_SIGNAL( endOfSearch( int ) ),
this, TQT_SLOT( searchFinished( int ) ) );
const TQWidget* currentPage = m_searchUI->tabWidget3->currentPage();
if ( currentPage == m_searchUI->tab )
{
if( m_searchUI->uin->text().isEmpty() || m_searchUI->uin->text().toULong() == 0 )
{
// Invalid UIN
stopSearch();
clearResults();
KMessageBox::sorry( this, i18n("You must enter a valid UIN."), i18n("ICQ Plugin") );
kdDebug(OSCAR_RAW_DEBUG) << k_funcinfo << "Search aborted: invalid UIN " << m_searchUI->uin->text() << endl;
}
else
{
//doing a uin search
m_account->engine()->uinSearch( m_searchUI->uin->text() );
}
}
else if ( currentPage == m_searchUI->tab_2 )
{
//create a ICQWPSearchInfo struct and send it
ICQProtocol* p = ICQProtocol::protocol();
ICQWPSearchInfo info;
TQTextCodec* codec = m_account->defaultCodec();
info.firstName = codec->fromUnicode( m_searchUI->firstName->text() );
info.lastName = codec->fromUnicode( m_searchUI->lastName->text() );
info.nickName = codec->fromUnicode( m_searchUI->nickName->text() );
info.email = codec->fromUnicode( m_searchUI->email->text() );
info.city = codec->fromUnicode( m_searchUI->city->text() ); // City
info.gender = p->getCodeForCombo(m_searchUI->gender, p->genders()); // Gender
info.language = p->getCodeForCombo(m_searchUI->language, p->languages()); // Lang
info.country =p->getCodeForCombo(m_searchUI->country, p->countries()); // country code
info.onlineOnly = m_searchUI->onlyOnline->isChecked();
// Check if the user has actually entered things to search
if( info.firstName.isEmpty() &&
info.lastName.isEmpty() &&
info.nickName.isEmpty() &&
info.email.isEmpty() &&
info.city.isEmpty() &&
(info.gender == 0) &&
(info.language == 0) &&
(info.country == 0)
)
{
// All fields were blank
stopSearch();
clearResults();
KMessageBox::information(this, i18n("You must enter search criteria."), i18n("ICQ Plugin") );
kdDebug(OSCAR_ICQ_DEBUG) << k_funcinfo << "Search aborted: all fields were blank" << endl;
}
else
{
// Start the search
m_account->engine()->whitePagesSearch( info );
kdDebug(OSCAR_RAW_DEBUG) << k_funcinfo << "Starting whitepage search" << endl;
}
}
}
}
void ICQSearchDialog::stopSearch()
{
disconnect( m_account->engine(), TQT_SIGNAL( gotSearchResults( const ICQSearchResult& ) ),
this, TQT_SLOT( newResult( const ICQSearchResult& ) ) );
disconnect( m_account->engine(), TQT_SIGNAL( endOfSearch( int ) ),
this, TQT_SLOT( searchFinished( int ) ) );
m_searchUI->stopButton->setEnabled( false );
m_searchUI->searchButton->setEnabled( true );
m_searchUI->newSearchButton->setEnabled( true );
}
void ICQSearchDialog::addContact()
{
ICQAddContactPage* iacp = dynamic_cast<ICQAddContactPage*>( tqparent() );
if ( !iacp )
{
kdDebug(OSCAR_ICQ_DEBUG) << k_funcinfo << "The ICQ ACP is not our tqparent!!" << endl;
}
else
{
TQString uin = m_searchUI->searchResults->selectedItem()->text( 0 );
kdDebug(OSCAR_ICQ_DEBUG) << k_funcinfo << "Passing " << uin << " back to the ACP" << endl;
iacp->setUINFromSearch( uin );
// Closing the dialog
closeDialog();
}
}
void ICQSearchDialog::userInfo()
{
// Lookup user info only if the account is online, otherwise warn the user
if(!m_account->isConnected())
{
// Account currently offline
KMessageBox::sorry( this, i18n("You must be online to display user info."), i18n("ICQ Plugin") );
}
else
{
// Account currently online
m_contact = new ICQContact( m_account,
m_searchUI->searchResults->selectedItem()->text( 0 ),
NULL);
m_infoWidget = new ICQUserInfoWidget( Kopete::UI::Global::mainWidget(), "icq info" );
TQObject::connect( m_infoWidget, TQT_SIGNAL( finished() ), this, TQT_SLOT( closeUserInfo() ) );
m_infoWidget->setContact( m_contact );
m_infoWidget->setModal(true);
m_infoWidget->show();
if ( m_contact->account()->isConnected() )
m_account->engine()->requestFullInfo( m_contact->contactId() );
kdDebug(OSCAR_ICQ_DEBUG) << k_funcinfo << "Displaying user info" << endl;
}
}
void ICQSearchDialog::closeUserInfo()
{
// Free the ICQUserInfoWidget
TQObject::disconnect( this, 0, m_infoWidget, 0 );
m_infoWidget->delayedDestruct();
m_infoWidget = NULL;
// Free the ICQContact
delete m_contact;
m_contact = NULL;
}
void ICQSearchDialog::clearResults()
{
stopSearch();
m_searchUI->searchResults->clear();
m_searchUI->addButton->setEnabled( false );
m_searchUI->userInfoButton->setEnabled( false );
m_searchUI->searchButton->setEnabled( true );
}
void ICQSearchDialog::closeDialog()
{
stopSearch();
clearResults();
clearFields();
slotClose();
}
void ICQSearchDialog::resultSelectionChanged()
{
if ( !m_searchUI->searchResults->selectedItem() )
{
m_searchUI->addButton->setEnabled( false );
m_searchUI->userInfoButton->setEnabled( false );
}
else
{
m_searchUI->addButton->setEnabled( true );
m_searchUI->userInfoButton->setEnabled( true );
}
}
void ICQSearchDialog::newResult( const ICQSearchResult& info )
{
if ( info.uin == 1 )
{
//TODO update progress
return;
}
TQTextCodec* codec = m_account->defaultCodec();
TQListViewItem *item = new TQListViewItem( m_searchUI->searchResults, TQString::number( info.uin ),
codec->toUnicode( info.nickName ),
codec->toUnicode( info.firstName ),
codec->toUnicode( info.lastName ),
codec->toUnicode( info.email ),
info.auth ? i18n( "Yes" ) : i18n( "No" ) );
if ( !item )
return;
if ( info.online )
item->setPixmap( 0, SmallIcon( "icq_online" ) );
else
item->setPixmap( 0, SmallIcon( "icq_offline" ) );
}
void ICQSearchDialog::searchFinished( int numLeft )
{
kdWarning(OSCAR_ICQ_DEBUG) << k_funcinfo << "There are " << numLeft << "contact left out of this search" << endl;
m_searchUI->stopButton->setEnabled( false );
m_searchUI->clearButton->setEnabled( true );
m_searchUI->searchButton->setEnabled( true );
m_searchUI->newSearchButton->setEnabled( true );
}
void ICQSearchDialog::clearFields()
{
m_searchUI->uin->setText( TQString() );
m_searchUI->firstName->setText( TQString() );
m_searchUI->lastName->setText( TQString() );
m_searchUI->nickName->setText( TQString() );
m_searchUI->email->setText( TQString() );
m_searchUI->city->setText( TQString() );
m_searchUI->gender->setCurrentItem( 0 ); // Unspecified
m_searchUI->country->setCurrentItem( 0 );
m_searchUI->language->setCurrentItem( 0 );
m_searchUI->onlyOnline->setChecked( false );
}
void ICQSearchDialog::newSearch()
{
clearResults();
clearFields();
}
//kate: indent-mode csands; space-indent off; tqreplace-tabs off; tab-width 4;
#include "icqsearchdialog.moc"
|