a56838e970eb6ef1b33797f848ff2d8b8cea2223
[jenirok] / src / gui / searchdialog.cpp
1 /*
2  * This file is part of Jenirok.
3  *
4  * Jenirok is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * Jenirok is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with Jenirok.  If not, see <http://www.gnu.org/licenses/>.
16  *
17  */
18
19 #include <QtGui/QHBoxLayout>
20 #include <QtGui/QVBoxLayout>
21 #include <QtGui/QLabel>
22 #include <QtGui/QDialogButtonBox>
23 #include <QMaemo5ValueButton>
24 #include <QDebug>
25 #include "searchdialog.h"
26
27 SearchDialog::SearchDialog(QWidget* parent): QDialog(parent),
28 numberInput_(0), locationInput_(0), selector_(0)
29 {
30     setWindowTitle(tr("Search"));
31
32     QHBoxLayout* numberLayout = new QHBoxLayout;
33     QLabel* numberLabel = new QLabel(tr("Name/number"));
34     numberInput_ = new QLineEdit;
35     numberLayout->addWidget(numberLabel);
36     numberLayout->addWidget(numberInput_);
37
38     QHBoxLayout* locationLayout = new QHBoxLayout;
39     QLabel* locationLabel = new QLabel(tr("Location"));
40     locationInput_ = new QLineEdit;
41     locationLayout->addWidget(locationLabel);
42     locationLayout->addWidget(locationInput_);
43
44     selector_ = new ButtonSelector(tr("Type"), this);
45     selector_->addItem(tr("Persons"));
46     selector_->addItem(tr("Yellow pages"));
47
48     QVBoxLayout* leftLayout = new QVBoxLayout;
49     leftLayout->addLayout(numberLayout);
50     leftLayout->addLayout(locationLayout);
51     leftLayout->addWidget(selector_);
52
53     QDialogButtonBox* buttons = new QDialogButtonBox;
54     QPushButton* submitButton = new QPushButton(tr("Search"));
55     buttons->addButton(submitButton, QDialogButtonBox::AcceptRole);
56     connect(submitButton, SIGNAL(pressed()), this, SLOT(searchPressed()));
57
58     QHBoxLayout* mainLayout = new QHBoxLayout;
59     mainLayout->addLayout(leftLayout, Qt::AlignLeft);
60     mainLayout->addWidget(buttons);
61
62     setLayout(mainLayout);
63 }
64
65 void SearchDialog::searchPressed()
66 {
67     SearchDetails details;
68     details.name = numberInput_->text();
69
70     if(details.name.isEmpty())
71     {
72         numberInput_->setFocus();
73         return;
74     }
75
76     details.location = locationInput_->text();
77     details.type = selector_->currentIndex();
78     emit search(details);
79     hide();
80 }