2 * This file is part of Jenirok.
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.
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.
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/>.
19 #include <QtCore/QDebug>
20 #include <QtGui/QHBoxLayout>
21 #include <QtGui/QVBoxLayout>
22 #include <QtGui/QLabel>
23 #include <QtGui/QDialogButtonBox>
24 #include <QMaemo5ValueButton>
25 #include "searchdialog.h"
29 SearchDialog::SearchDialog(QWidget* parent): QDialog(parent),
30 numberInput_(0), locationInput_(0), selector_(0)
32 setWindowTitle(tr("Search"));
34 QHBoxLayout* numberLayout = new QHBoxLayout;
35 QLabel* numberLabel = new QLabel(tr("Name/number"));
36 numberInput_ = new QLineEdit;
37 numberLayout->addWidget(numberLabel);
38 numberLayout->addWidget(numberInput_);
40 QHBoxLayout* locationLayout = new QHBoxLayout;
41 QLabel* locationLabel = new QLabel(tr("Location"));
42 locationInput_ = new QLineEdit;
43 locationLayout->addWidget(locationLabel);
44 locationLayout->addWidget(locationInput_);
46 selector_ = new ButtonSelector(tr("Type"), this);
49 QVBoxLayout* leftLayout = new QVBoxLayout;
50 leftLayout->addLayout(numberLayout);
51 leftLayout->addLayout(locationLayout);
52 leftLayout->addWidget(selector_);
54 QDialogButtonBox* buttons = new QDialogButtonBox;
55 buttons->setCenterButtons(false);
56 QPushButton* submitButton = new QPushButton(tr("Search"));
57 buttons->addButton(submitButton, QDialogButtonBox::AcceptRole);
58 connect(submitButton, SIGNAL(pressed()), this, SLOT(searchPressed()));
60 QHBoxLayout* mainLayout = new QHBoxLayout;
61 mainLayout->addLayout(leftLayout, Qt::AlignLeft);
62 mainLayout->addWidget(buttons);
64 setLayout(mainLayout);
67 void SearchDialog::searchPressed()
69 SearchDetails details;
70 details.name = numberInput_->text();
72 if(details.name.isEmpty())
74 numberInput_->setFocus();
78 details.location = locationInput_->text();
79 details.type = selector_->value().toInt();
84 void SearchDialog::setVisible(bool visible)
86 QDialog::setVisible(visible);
90 numberInput_->setFocus();
94 void SearchDialog::loadSearchTypes()
98 Source* source = Source::getSource(Source::stringToId(Settings::instance()->get("source")));
100 QList<Source::SearchType> types;
101 source->getSearchTypes(types);
105 for(int i = 0; i < types.size(); i++)
109 case Source::PERSONS:
110 selector_->addItem(tr("Persons"), static_cast<int>(Source::PERSONS));
112 case Source::YELLOW_PAGES:
113 selector_->addItem(tr("Companies"), static_cast<int>(Source::YELLOW_PAGES));
120 if(!selector_->isVisible())