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"
28 SearchDialog::SearchDialog(QWidget* parent): QDialog(parent),
29 numberInput_(0), locationInput_(0), selector_(0)
31 setWindowTitle(tr("Search"));
33 QHBoxLayout* numberLayout = new QHBoxLayout;
34 QLabel* numberLabel = new QLabel(tr("Name/number"));
35 numberInput_ = new QLineEdit;
36 numberLayout->addWidget(numberLabel);
37 numberLayout->addWidget(numberInput_);
39 QHBoxLayout* locationLayout = new QHBoxLayout;
40 QLabel* locationLabel = new QLabel(tr("Location"));
41 locationInput_ = new QLineEdit;
42 locationLayout->addWidget(locationLabel);
43 locationLayout->addWidget(locationInput_);
45 selector_ = new ButtonSelector(tr("Type"), this);
48 QVBoxLayout* leftLayout = new QVBoxLayout;
49 leftLayout->addLayout(numberLayout);
50 leftLayout->addLayout(locationLayout);
51 leftLayout->addWidget(selector_);
53 QDialogButtonBox* buttons = new QDialogButtonBox;
54 buttons->setCenterButtons(false);
55 QPushButton* submitButton = new QPushButton(tr("Search"));
56 buttons->addButton(submitButton, QDialogButtonBox::AcceptRole);
57 connect(submitButton, SIGNAL(pressed()), this, SLOT(searchPressed()));
59 QHBoxLayout* mainLayout = new QHBoxLayout;
60 mainLayout->addLayout(leftLayout, Qt::AlignLeft);
61 mainLayout->addWidget(buttons);
63 setLayout(mainLayout);
66 void SearchDialog::searchPressed()
68 SearchDetails details;
69 details.name = numberInput_->text();
71 if(details.name.isEmpty())
73 numberInput_->setFocus();
77 details.location = locationInput_->text();
81 if(selector_->isVisible())
83 type = selector_->value().toInt();
86 details.type = static_cast<Source::SearchType>(type);
92 void SearchDialog::setVisible(bool visible)
94 QDialog::setVisible(visible);
98 numberInput_->setFocus();
102 void SearchDialog::loadSearchTypes()
106 Source* source = Source::getSource(Source::stringToId(Settings::instance()->get("source")));
108 QList<Source::SearchType> types;
109 source->getSearchTypes(types);
113 for(int i = 0; i < types.size(); i++)
117 case Source::PERSONS:
118 selector_->addItem(tr("Persons"), static_cast<int>(Source::PERSONS));
120 case Source::YELLOW_PAGES:
121 selector_->addItem(tr("Companies"), static_cast<int>(Source::YELLOW_PAGES));
128 if(!selector_->isVisible())