Statistics
| Branch: | Tag: | Revision:

root / kadu-core / gui / windows / search-window.cpp @ 9469ed1a

History | View | Annotate | Download (22.5 kB)

1
/***************************************************************************
2
 *                                                                         *
3
 *   This program is free software; you can redistribute it and/or modify  *
4
 *   it under the terms of the GNU General Public License as published by  *
5
 *   the Free Software Foundation; either version 2 of the License, or     *
6
 *   (at your option) any later version.                                   *
7
 *                                                                         *
8
 ***************************************************************************/
9
10
#include <QtGui/QAction>
11
#include <QtGui/QButtonGroup>
12
#include <QtGui/QCheckBox>
13
#include <QtGui/QComboBox>
14
#include <QtGui/QGroupBox>
15
#include <QtGui/QGridLayout>
16
#include <QtGui/QKeyEvent>
17
#include <QtGui/QLabel>
18
#include <QtGui/QLineEdit>
19
#include <QtGui/QRadioButton>
20
#include <QtGui/QTreeWidget>
21
#include <QtGui/QTreeWidgetItem>
22
23
#include "accounts/account-manager.h"
24
#include "chat/chat-manager.h"
25
#include "configuration/configuration-file.h"
26
#include "contacts/contact.h"
27
#include "buddies/buddy-manager.h"
28
#include "debug.h"
29
#include "core/core.h"
30
#include "gui/widgets/chat-widget-manager.h"
31
#include "gui/windows/add-buddy-window.h"
32
#include "gui/windows/message-dialog.h"
33
#include "misc/misc.h"
34
#include "gui/widgets/toolbar.h"
35
#include "protocols/protocol.h"
36
#include "protocols/services/search-service.h"
37
38
#include "search-window.h"
39
#include <protocols/protocol-factory.h>
40
41
SearchActionsSlots *SearchWindow::searchActionsSlot;
42
43
ActionDescription *SearchWindow::firstSearchAction;
44
ActionDescription *SearchWindow::nextResultsAction;
45
ActionDescription *SearchWindow::stopSearchAction;
46
ActionDescription *SearchWindow::clearResultsAction;
47
ActionDescription *SearchWindow::addFoundAction;
48
ActionDescription *SearchWindow::chatFoundAction;
49
50
SearchWindow::SearchWindow(QWidget *parent, Buddy buddy)
51
        : MainWindow(parent),
52
        only_active(0), e_uin(0), e_name(0), e_nick(0), e_byrFrom(0), e_byrTo(0), e_surname(0),
53
        c_gender(0), e_city(0), results(0), progress(0), r_uin(0), r_pers(0), CurrentSearchCriteria(BuddySearchCriteria()),
54
        seq(0), selectedUsers(BuddySet()), searchhidden(false), searching(false), workaround(false)
55
{
56
        kdebugf();
57
58
        setAttribute(Qt::WA_DeleteOnClose);
59
        setWindowTitle(tr("Search user in directory"));
60
61
        initModule();
62
63
        QWidget *centralWidget = new QWidget(this);
64
65
        QLabel *l_name;
66
        QLabel *l_nick;
67
        QLabel *l_byr;
68
        QLabel *l_byrFrom;
69
        QLabel *l_byrTo;
70
        QLabel *l_surname;
71
        QLabel *l_gender;
72
        QLabel *l_city;
73
        QLabel *l_uin;
74
75
        l_nick = new QLabel(tr("Nickname"), centralWidget);
76
        e_nick = new QLineEdit(centralWidget);
77
        connect(e_nick, SIGNAL(textChanged(const QString &)), this, SLOT(personalDataTyped()));
78
        connect(e_nick, SIGNAL(returnPressed()), this, SLOT(firstSearch()));
79
80
        l_gender = new QLabel(tr("Gender"), centralWidget);
81
        c_gender = new QComboBox(centralWidget);
82
        c_gender->insertItem(0, " ");
83
        c_gender->insertItem(1, tr("Male"));
84
        c_gender->insertItem(2, tr("Female"));
85
        connect(c_gender, SIGNAL(activated(const QString &)), this, SLOT(personalDataTyped()));
86
87
        l_name = new QLabel(tr("Name"), centralWidget);
88
        e_name = new QLineEdit(centralWidget);
89
        connect(e_name, SIGNAL(textChanged(const QString &)), this, SLOT(personalDataTyped()));
90
        connect(e_name, SIGNAL(returnPressed()), this, SLOT(firstSearch()));
91
92
        l_surname = new QLabel(tr("Surname"), centralWidget);
93
        e_surname = new QLineEdit(centralWidget);
94
        connect(e_surname, SIGNAL(textChanged(const QString &)), this, SLOT(personalDataTyped()));
95
        connect(e_surname, SIGNAL(returnPressed()), this, SLOT(firstSearch()));
96
97
        l_byr = new QLabel(tr("Birthyear"), centralWidget);
98
        l_byrFrom = new QLabel(tr("from"), centralWidget);
99
        e_byrFrom = new QLineEdit(centralWidget);
100
        e_byrFrom->setMaxLength(4);
101
        e_byrFrom->setValidator(new QIntValidator(1, 2100, this));
102
        connect(e_byrFrom, SIGNAL(textChanged(const QString &)), this, SLOT(personalDataTyped()));
103
        connect(e_byrFrom, SIGNAL(textChanged(const QString &)), this, SLOT(byrFromDataTyped()));
104
        connect(e_byrFrom, SIGNAL(returnPressed()), this, SLOT(firstSearch()));
105
        l_byrTo = new QLabel(tr("to"), centralWidget);
106
        e_byrTo = new QLineEdit(centralWidget);
107
        e_byrTo->setEnabled(false);
108
        e_byrTo->setMaxLength(4);
109
        e_byrTo->setValidator(new QIntValidator(1, 2100, centralWidget));
110
        connect(e_byrTo, SIGNAL(textChanged(const QString &)), this, SLOT(personalDataTyped()));
111
        connect(e_byrTo, SIGNAL(returnPressed()), this, SLOT(firstSearch()));
112
113
        l_city = new QLabel(tr("City"), centralWidget);
114
        e_city = new QLineEdit(centralWidget);
115
        connect(e_city, SIGNAL(textChanged(const QString &)), this, SLOT(personalDataTyped()));
116
        connect(e_city, SIGNAL(returnPressed()), this, SLOT(firstSearch()));
117
118
        only_active = new QCheckBox(tr("Only active users"), centralWidget);
119
        connect(only_active, SIGNAL(clicked()), this, SLOT(personalDataTyped()));
120
121
        QGroupBox *qgrp1 = new QGroupBox(tr("Uin"), centralWidget);
122
        QHBoxLayout *uinLayout = new QHBoxLayout(qgrp1);
123
        l_uin = new QLabel(tr("Uin"),qgrp1);
124
        e_uin = new QLineEdit(qgrp1);
125
        e_uin->setMaxLength(9);
126
        e_uin->setValidator(new QIntValidator(1, 999999999, centralWidget));
127
        connect(e_uin, SIGNAL(textChanged(const QString &)), this, SLOT(uinTyped()));
128
        connect(e_uin, SIGNAL(returnPressed()), this, SLOT(firstSearch()));
129
        uinLayout->addWidget(l_uin);
130
        uinLayout->addWidget(e_uin);
131
132
        progress = new QLabel(centralWidget);
133
134
        results = new QTreeWidget(centralWidget);
135
        connect(results, SIGNAL(itemSelectionChanged()), this, SLOT(selectionChanged()));
136
137
        QGroupBox * btngrp = new QGroupBox(tr("Search criteria"), centralWidget);
138
        QButtonGroup *buttonGroup = new QButtonGroup(btngrp);
139
        QHBoxLayout *btngrpLayout = new QHBoxLayout(btngrp);
140
        r_pers = new QRadioButton(tr("&Personal data"), btngrp);
141
        r_pers->setChecked(true);
142
        connect(r_pers, SIGNAL(toggled(bool)), this, SLOT(persClicked()));
143
        r_pers->setToolTip(tr("Search using the personal data typed above (name, nickname)..."));
144
145
        r_uin = new QRadioButton(tr("&Uin number"), btngrp);
146
        connect(r_uin, SIGNAL(toggled(bool)), this, SLOT(uinClicked()));
147
        r_uin->setToolTip(tr("Search for this UIN exclusively"));
148
149
        buttonGroup->addButton(r_pers);
150
        buttonGroup->addButton(r_uin);
151
152
        btngrpLayout->addWidget(r_pers);
153
        btngrpLayout->addWidget(r_uin);
154
155
        QGridLayout * grid = new QGridLayout(centralWidget);
156
157
        grid->addWidget(l_nick, 1, 0, Qt::AlignRight); 
158
        grid->addWidget(e_nick, 1, 1);
159
        grid->addWidget(l_name, 1, 3, Qt::AlignRight); 
160
        grid->addWidget(e_name, 1, 4);
161
        grid->addWidget(l_byr, 1, 6, Qt::AlignRight);
162
        grid->addWidget(l_byrFrom, 1, 7, Qt::AlignRight); 
163
        grid->addWidget(e_byrFrom, 1, 8);
164
        grid->addWidget(l_city, 1, 10, Qt::AlignRight);
165
        grid->addWidget(e_city, 1, 11);
166
167
        grid->addWidget(l_gender, 2, 0, Qt::AlignRight); 
168
        grid->addWidget(c_gender, 2, 1);
169
        grid->addWidget(l_surname, 2, 3, Qt::AlignRight); 
170
        grid->addWidget(e_surname, 2, 4);
171
        grid->addWidget(l_byrTo, 2, 7, Qt::AlignRight); 
172
        grid->addWidget(e_byrTo, 2, 8);
173
        grid->addWidget(only_active, 2, 10, 1, 2);
174
175
        grid->addWidget(qgrp1, 3, 0, 1, 4);
176
        grid->addWidget(btngrp, 3, 4, 1, 8);
177
        grid->addWidget(results, 5, 0, 1, 12);
178
        grid->addWidget(progress, 6, 0, 1, 2);
179
        
180
        QStringList headers;
181
        headers << tr("Status") << tr("Uin") << tr("Name") << tr("City") << tr("Nickname") << tr("Birth year");
182
        results->setHeaderLabels(headers);
183
        results->setSortingEnabled(true);
184
        results->setAllColumnsShowFocus(true);
185
        results->setSelectionMode(QAbstractItemView::SingleSelection);
186
        results->setIndentation(false);
187
188
        setCentralWidget(centralWidget);
189
190
        if (loadToolBarsFromConfig("searchDockArea", Qt::BottomToolBarArea, true))
191
                writeToolBarsToConfig("search"); // port old config
192
        else
193
                loadToolBarsFromConfig("search"); // load new config
194
195
         setActionState(stopSearchAction, false);
196
         setActionState(firstSearchAction, false);
197
         setActionState(nextResultsAction,false);
198
         setActionState(clearResultsAction, false);
199
         setActionState(addFoundAction, false);
200
         setActionState(chatFoundAction, false);
201
202
        loadWindowGeometry(this, "General", "SearchWindowGeometry", 0, 50, 800, 350);
203
204
        if (Buddy::null != buddy)
205
        {
206
                CurrentAccount = buddy.prefferedAccount();
207
        }
208
        else
209
        {
210
                foreach (Account a, AccountManager::instance()->accounts())
211
                {
212
                        // TODO 0.6.6: !!!
213
                        if (a.protocolHandler()->isConnected() && a.protocolHandler()->protocolFactory()->name() == "gadu")
214
                        {
215
                                CurrentAccount = a;
216
                                break;
217
                        }
218
                }
219
                if (CurrentAccount.isNull())
220
                        CurrentAccount = AccountManager::instance()->accounts().at(0);
221
        }
222
223
        if (CurrentAccount.protocolHandler())
224
                CurrentSearchService = CurrentAccount.protocolHandler()->searchService();
225
226
        if (CurrentSearchService)
227
                connect(CurrentSearchService, SIGNAL(newResults(BuddyList)), this, SLOT(newSearchResults(BuddyList)));
228
229
        if (!buddy.isNull())
230
        {
231
                CurrentSearchCriteria.SearchBuddy = buddy;
232
                e_uin->insert(buddy.contact(CurrentAccount).id());
233
        }
234
235
        kdebugf2();
236
}
237
238
SearchWindow::~SearchWindow()
239
{
240
        kdebugf();
241
        writeToolBarsToConfig("search");
242
         saveWindowGeometry(this, "General", "SearchWindowGeometry");
243
        closeModule();
244
        kdebugf2();
245
}
246
247
void SearchWindow::initModule()
248
{
249
        kdebugf();
250
251
        searchActionsSlot = new SearchActionsSlots();
252
253
        firstSearchAction = new ActionDescription(searchActionsSlot,
254
                ActionDescription::TypeSearch, "firstSearchAction",
255
                searchActionsSlot, SLOT(firstSearchActionActivated(QAction *, bool)),
256
                "LookupUserInfo", tr("&Search")
257
        );
258
        QObject::connect(firstSearchAction, SIGNAL(actionCreated(Action *)), searchActionsSlot, SLOT(firstSearchActionCreated(Action *)));
259
260
        nextResultsAction = new ActionDescription(searchActionsSlot,
261
                ActionDescription::TypeSearch, "nextResultsAction",
262
                searchActionsSlot, SLOT(nextResultsActionActivated(QAction *, bool)),
263
                "NextSearchResults", tr("&Next results")
264
        );
265
        QObject::connect(nextResultsAction, SIGNAL(actionCreated(Action *)), searchActionsSlot, SLOT(nextResultsActionCreated(Action *)));
266
267
        stopSearchAction = new ActionDescription(searchActionsSlot,
268
                ActionDescription::TypeSearch, "stopSearchAction",
269
                searchActionsSlot, SLOT(stopSearchActionActivated(QAction *, bool)),
270
                "CloseWindow", tr("Stop")
271
        );
272
        QObject::connect(stopSearchAction, SIGNAL(actionCreated(Action *)), searchActionsSlot, SLOT(stopSearchActionCreated(Action *)));
273
274
        clearResultsAction = new ActionDescription(searchActionsSlot,
275
                ActionDescription::TypeSearch, "clearSearchAction",
276
                searchActionsSlot, SLOT(clearResultsActionActivated(QAction *, bool)),
277
                "ClearSearchResults", tr("Clear results")
278
        );
279
        QObject::connect(clearResultsAction, SIGNAL(actionCreated(Action *)), searchActionsSlot, SLOT(clearResultsActionCreated(Action *)));
280
281
        addFoundAction = new ActionDescription(searchActionsSlot,
282
                ActionDescription::TypeSearch, "addSearchedAction",
283
                searchActionsSlot, SLOT(addFoundActionActivated(QAction *, bool)),
284
                "AddUser", tr("Add selected user")
285
        );
286
        QObject::connect(addFoundAction, SIGNAL(actionCreated(Action *)), searchActionsSlot, SLOT(actionsFoundActionCreated(Action *)));
287
288
        chatFoundAction = new ActionDescription(searchActionsSlot,
289
                ActionDescription::TypeSearch, "chatSearchedAction",
290
                searchActionsSlot, SLOT(chatFoundActionActivated(QAction *, bool)),
291
                "OpenChat", tr("&Chat")
292
        );
293
        QObject::connect(chatFoundAction, SIGNAL(actionCreated(Action *)), searchActionsSlot, SLOT(actionsFoundActionCreated(Action *)));
294
295
        kdebugf2();
296
}
297
298
void SearchWindow::closeModule()
299
{
300
        delete searchActionsSlot;
301
}
302
303
QTreeWidgetItem * SearchWindow::selectedItem()
304
{
305
        if (results->selectedItems().count())
306
                return results->selectedItems()[0];
307
        else if (results->children().count() == 1)
308
                return dynamic_cast<QTreeWidgetItem *>(results->children()[0]);
309
        else 
310
                return NULL;
311
}
312
313
void SearchWindow::addFound()
314
{
315
        BuddyList found = selected().toBuddyList();
316
317
        foreach (Buddy buddy, found)
318
        {
319
                AddBuddyWindow *a = new AddBuddyWindow(this);
320
                a->setContact(CurrentSearchCriteria.SearchBuddy);
321
                a->show();
322
        }
323
}
324
325
void SearchWindow::chatFound()
326
{
327
        BuddySet contacts = selected();
328
        if (contacts.count() > 0)
329
        {
330
                Chat chat = (*contacts.begin()).prefferedAccount().protocolHandler()->findChat(contacts);
331
                if (chat)
332
                        ChatWidgetManager::instance()->openChatWidget(chat, true);
333
        }
334
335
}
336
337
// TODO: return real list
338
BuddySet SearchWindow::selected()
339
{
340
        BuddySet result;
341
342
        QTreeWidgetItem *selected = selectedItem();
343
344
        if (!selected)
345
                return result;
346
347
        QString uin = selected->text(1);
348
        QString firstname = selected->text(2);
349
        QString nickname = selected->text(4);
350
351
        QString altnick;
352
        if (!nickname.isEmpty()) // Build altnick. Trying user nick first.
353
                altnick = nickname;
354
        else if (!firstname.isEmpty()) // If nick is empty, try firstname.
355
                altnick = firstname;
356
        else
357
                altnick = uin; // If above are empty, use uin.
358
359
        Buddy e = BuddyManager::instance()->byId(CurrentAccount, uin);
360
361
        if (e.isAnonymous())
362
        {
363
                e.setFirstName(firstname);
364
                e.setNickName(nickname);
365
                e.setDisplay(altnick);
366
        }
367
368
        result.insert(e);
369
        return result;
370
}
371
372
void SearchWindow::clearResults()
373
{
374
        results->clear();
375
376
         setActionState(addFoundAction, false);
377
         setActionState(clearResultsAction, false);
378
         setActionState(chatFoundAction, false);
379
}
380
381
void SearchWindow::stopSearch()
382
{
383
        kdebugf();
384
385
        CurrentSearchService->stop();
386
387
        setActionState(stopSearchAction, false);
388
389
        if ((r_pers->isChecked() && !isPersonalDataEmpty()) || (r_uin->isChecked() && !e_uin->text().isEmpty()))
390
                setActionState(firstSearchAction, true);
391
        if (!results->selectedItems().isEmpty())
392
        {
393
                if (r_pers->isChecked() && !isPersonalDataEmpty())
394
                        setActionState(nextResultsAction, true);
395
396
                setActionState(addFoundAction, true);
397
                setActionState(chatFoundAction, true);
398
        }
399
        if (results->topLevelItemCount() > 0)
400
                setActionState(clearResultsAction, true);
401
402
        kdebugf2();
403
}
404
405
void SearchWindow::firstSearch()
406
{
407
        kdebugf();
408
409
        if (r_pers->isChecked() && isPersonalDataEmpty())
410
                return;
411
412
        if (!CurrentSearchService)
413
        {
414
                MessageDialog::msg(tr("For this network we dont offer contacts search feature yet"), false, "Critical", this);
415
                kdebugf2();
416
                return;
417
        }
418
419
        if (!CurrentAccount.protocolHandler()->isConnected())
420
        {
421
                MessageDialog::msg(tr("Cannot search contacts in offline mode"), false, "Critical", this);
422
                kdebugf2();
423
                return;
424
        }
425
426
        if (!results->children().isEmpty())
427
                clearResults();
428
429
        if (searching)
430
                CurrentSearchService->stop();
431
432
        CurrentSearchCriteria.clearData();
433
434
        if (r_pers->isChecked())
435
        {
436
                CurrentSearchCriteria.reqFirstName(e_name->text());
437
                CurrentSearchCriteria.reqLastName(e_surname->text());
438
                CurrentSearchCriteria.reqNickName(e_nick->text());
439
                CurrentSearchCriteria.reqCity(e_city->text());
440
                if (((e_byrTo->text().isEmpty()) && (!e_byrFrom->text().isEmpty()))
441
                    || ((e_byrTo->text().toUShort()) < (e_byrFrom->text().toUShort())))
442
                        e_byrTo->setText(e_byrFrom->text());
443
                CurrentSearchCriteria.reqBirthYear(e_byrFrom->text(), e_byrTo->text());
444
445
                switch (c_gender->currentIndex())
446
                {
447
                        case 1:
448
                                CurrentSearchCriteria.reqGender(false);
449
                                break;
450
                        case 2:
451
                                CurrentSearchCriteria.reqGender(true);
452
                                break;
453
                }
454
455
                if (only_active->isChecked())
456
                        CurrentSearchCriteria.reqActive();
457
        }
458
        else if (r_uin->isChecked())
459
                CurrentSearchCriteria.reqUin(CurrentAccount, e_uin->text());
460
461
        searching = true;
462
463
         setActionState(stopSearchAction, true);
464
         setActionState(firstSearchAction, false);
465
         setActionState(nextResultsAction, false);
466
         setActionState(addFoundAction, false);
467
         setActionState(chatFoundAction, false);
468
469
        CurrentSearchService->searchFirst(CurrentSearchCriteria);
470
471
        progress->setText(tr("Searching..."));
472
473
        kdebugf2();
474
}
475
476
void SearchWindow::nextSearch()
477
{
478
        kdebugf();
479
480
        if (!CurrentAccount.protocolHandler()->isConnected())
481
                return;
482
483
        searching = true;
484
485
         setActionState(stopSearchAction, true);
486
         setActionState(firstSearchAction, false);
487
         setActionState(nextResultsAction, false);
488
         setActionState(addFoundAction, false);
489
        setActionState(chatFoundAction, false);
490
491
        CurrentSearchService->searchNext();
492
493
        progress->setText(tr("Searching..."));
494
495
        kdebugf2();
496
}
497
498
void SearchWindow::newSearchResults(BuddyList buddies)
499
{
500
        kdebugf();
501
502
        QTreeWidgetItem *qlv = 0;
503
        QPixmap pix;
504
505
        int items = results->topLevelItemCount(); // number of items already in results
506
507
        foreach(Buddy buddy, buddies)
508
        {
509
                Contact contact = buddy.contact(CurrentAccount);
510
                QList <QTreeWidgetItem *> items = results->findItems(contact.id(), Qt::MatchExactly, 1);
511
                if (items.count())
512
                        qlv = items[0];                
513
                pix = contact.contactAccount().statusContainer()->statusPixmap(contact.currentStatus());
514
515
                if (qlv)
516
                {
517
                        qlv->setText(1, contact.id());
518
                        qlv->setText(2, buddy.firstName());
519
                        qlv->setText(3, buddy.city());
520
                        qlv->setText(4, buddy.nickName());
521
                        qlv->setText(5, buddy.familyCity());
522
                }
523
                else
524
                {
525
                        QStringList strings;
526
                        strings << QString::null << contact.id() << buddy.firstName() << buddy.city() << buddy.nickName() << QString::number(buddy.birthYear());
527
                        qlv = new QTreeWidgetItem(results, strings);
528
                        qlv->setIcon(0, QIcon(pix));
529
                        qlv = 0;
530
                }
531
        }
532
533
        progress->setText(tr("Done searching"));
534
535
        if ((r_pers->isChecked() && !isPersonalDataEmpty()) || (r_uin->isChecked() && !e_uin->text().isEmpty()))
536
                setActionState(firstSearchAction, true);
537
        setActionState(stopSearchAction, false);
538
539
        if (buddies.isEmpty()  || (buddies.count() == items))
540
        {
541
                kdebugmf(KDEBUG_INFO, "No results. Exit.\n");
542
                MessageDialog::msg(tr("There were no results of your search"), false, "Information", this);
543
        }
544
        else
545
        {
546
                if (r_pers->isChecked() && !isPersonalDataEmpty())
547
                        setActionState(nextResultsAction, true);
548
549
                if (results->topLevelItemCount() > 0)
550
                        setActionState(clearResultsAction, true);
551
        }
552
553
        if (!results->selectedItems().isEmpty())
554
        {
555
                setActionState(addFoundAction, true);
556
                setActionState(chatFoundAction, true);
557
        }
558
559
        searching = false;
560
561
        kdebugf2();
562
}
563
564
void SearchWindow::closeEvent(QCloseEvent * e)
565
{
566
        QWidget::closeEvent(e);
567
}
568
569
void SearchWindow::resizeEvent(QResizeEvent *e)
570
{
571
        QWidget::resizeEvent(e);
572
//        results->triggerUpdate();//workaround for bug in Qt, which do not refresh results properly
573
}
574
575
void SearchWindow::keyPressEvent(QKeyEvent *e)
576
{
577
        if (e->key() == Qt::Key_Escape)
578
        {
579
                e->accept();
580
                close();
581
        }
582
        else
583
                QWidget::keyPressEvent(e);
584
}
585
586
void SearchWindow::uinTyped(void)
587
{
588
        r_uin->setChecked(true);
589
590
         setActionState(firstSearchAction, !e_uin->text().isEmpty());
591
}
592
593
void SearchWindow::personalDataTyped(void)
594
{
595
        workaround = true;
596
        r_pers->setChecked(true);
597
        workaround = false;
598
599
         setActionState(firstSearchAction, !isPersonalDataEmpty());
600
         setActionState(nextResultsAction, false);
601
}
602
603
void SearchWindow::byrFromDataTyped(void)
604
{
605
        bool b = e_byrFrom->text().isEmpty();
606
        e_byrTo->setEnabled(!b);
607
        if (b)
608
                e_byrTo->setText(QString::null);
609
}
610
611
void SearchWindow::persClicked()
612
{
613
         only_active->setEnabled(true);
614
         only_active->setChecked(false);
615
        if (!workaround)
616
                e_nick->setFocus();
617
618
         setActionState(firstSearchAction, !isPersonalDataEmpty());
619
}
620
621
void SearchWindow::uinClicked()
622
{
623
         only_active->setEnabled(false);
624
        if (!workaround)
625
                e_uin->setFocus();
626
627
         setActionState(firstSearchAction, !e_uin->text().isEmpty());
628
         setActionState(nextResultsAction, false);
629
}
630
631
bool SearchWindow::isPersonalDataEmpty() const
632
{
633
        return
634
                e_name->text().isEmpty() &&
635
                e_nick->text().isEmpty() &&
636
                e_byrFrom->text().isEmpty() &&
637
                e_surname->text().isEmpty() &&
638
                c_gender->currentIndex() == 0 &&
639
                e_city->text().isEmpty();
640
}
641
642
void SearchWindow::selectionChanged()
643
{
644
        //kdebugmf(KDEBUG_FUNCTION_START, "%p\n", );
645
         bool enableActions = results->selectedItems().count() > 0;
646
         setActionState(addFoundAction, enableActions);
647
         setActionState(chatFoundAction, enableActions);
648
}
649
650
void SearchActionsSlots::firstSearchActionActivated(QAction *sender, bool toggled)
651
{
652
        SearchWindow *search = dynamic_cast<SearchWindow *>(sender->parent());
653
        if (search)
654
                search->firstSearch();
655
}
656
657
void SearchWindow::createDefaultToolbars(QDomElement toolbarsConfig)
658
{
659
        QDomElement dockAreaConfig = getDockAreaConfigElement(toolbarsConfig, "search_bottomDockArea");
660
        QDomElement toolbarConfig = xml_config_file->createElement(dockAreaConfig, "ToolBar");
661
 
662
        addToolButton(toolbarConfig, "firstSearchAction", Qt::ToolButtonTextUnderIcon);
663
        addToolButton(toolbarConfig, "nextResultsAction", Qt::ToolButtonTextUnderIcon);
664
        addToolButton(toolbarConfig, "stopSearchAction", Qt::ToolButtonTextUnderIcon);
665
        addToolButton(toolbarConfig, "clearSearchAction", Qt::ToolButtonTextUnderIcon);
666
        addToolButton(toolbarConfig, "addSearchedAction", Qt::ToolButtonTextUnderIcon);
667
        addToolButton(toolbarConfig, "chatSearchedAction", Qt::ToolButtonTextUnderIcon);
668
}
669
670
void SearchWindow::setActionState(ActionDescription *actionDescription, bool toogle)
671
{
672
        Action *action = actionDescription->action(this);
673
        if (action)
674
                action->setEnabled(toogle);
675
}
676
677
void SearchActionsSlots::firstSearchActionCreated(Action *action)
678
{
679
        SearchWindow *search = dynamic_cast<SearchWindow *>(action->parent());
680
        if (!search)
681
                return;
682
683
        if (search->searching || (search->r_pers->isChecked() && search->isPersonalDataEmpty()) || (search->r_uin->isChecked() && search->e_uin->text().isEmpty()))
684
                action->setEnabled(false);
685
}
686
687
void SearchActionsSlots::nextResultsActionCreated(Action *action)
688
{
689
        SearchWindow *search = dynamic_cast<SearchWindow *>(action->parent());
690
        if (!search)
691
                return;
692
        if (search->searching || search->r_uin->isChecked() || search->isPersonalDataEmpty())
693
                action->setEnabled(false);
694
695
}
696
697
void SearchActionsSlots::stopSearchActionCreated(Action *action)
698
{
699
        SearchWindow *search = dynamic_cast<SearchWindow *>(action->parent());
700
        if (!search)
701
                return;
702
        if (!search->searching)
703
                action->setEnabled(false);
704
}
705
706
void SearchActionsSlots::clearResultsActionCreated(Action *action)
707
{
708
        SearchWindow *search = dynamic_cast<SearchWindow *>(action->parent());
709
        if (!search)
710
                return;
711
        if (!search->results->topLevelItemCount())
712
                action->setEnabled(false);
713
}
714
715
void SearchActionsSlots::actionsFoundActionCreated(Action *action)
716
{
717
        SearchWindow *search = dynamic_cast<SearchWindow *>(action->parent());
718
        if (!search)
719
                return;
720
        if (search->results->selectedItems().count() == 0)
721
                action->setEnabled(false);
722
}
723
724
void SearchActionsSlots::nextResultsActionActivated(QAction *sender, bool toggled)
725
{
726
        SearchWindow *search = dynamic_cast<SearchWindow *>(sender->parent());
727
        if (search)
728
                search->nextSearch();
729
}
730
731
void SearchActionsSlots::stopSearchActionActivated(QAction *sender, bool toggled)
732
{
733
        SearchWindow *search = dynamic_cast<SearchWindow *>(sender->parent());
734
        if (search)
735
                search->stopSearch();
736
}
737
738
void SearchActionsSlots::clearResultsActionActivated(QAction *sender, bool toggled)
739
{
740
        SearchWindow *search = dynamic_cast<SearchWindow *>(sender->parent());
741
        if (search)
742
                search->clearResults();
743
}
744
745
void SearchActionsSlots::addFoundActionActivated(QAction *sender, bool toggled)
746
{
747
        SearchWindow *search = dynamic_cast<SearchWindow *>(sender->parent());
748
        if (search)
749
                search->addFound();
750
}
751
752
void SearchActionsSlots::chatFoundActionActivated(QAction *sender, bool toggled)
753
{
754
        SearchWindow *search = dynamic_cast<SearchWindow *>(sender->parent());
755
        if (search)
756
                search->chatFound();
757
}
758