#include <QtGui/QDialogButtonBox>
#include <QMaemo5ValueButton>
#include "searchdialog.h"
+#include "settings.h"
SearchDialog::SearchDialog(QWidget* parent): QDialog(parent),
numberInput_(0), locationInput_(0), selector_(0)
locationLayout->addWidget(locationInput_);
selector_ = new ButtonSelector(tr("Type"), this);
- selector_->addItem(tr("Persons"));
- selector_->addItem(tr("Companies"));
+ loadSearchTypes();
QVBoxLayout* leftLayout = new QVBoxLayout;
leftLayout->addLayout(numberLayout);
}
details.location = locationInput_->text();
- details.type = selector_->currentIndex();
+
+ int type = 0;
+
+ if(selector_->isVisible())
+ {
+ type = selector_->value().toInt();
+ }
+
+ details.type = static_cast<Source::SearchType>(type);
+
emit search(details);
hide();
}
numberInput_->setFocus();
}
}
+
+void SearchDialog::setSearchString(QString const& string)
+{
+ numberInput_->setText(string);
+}
+
+void SearchDialog::loadSearchTypes()
+{
+ selector_->clear();
+
+ Source* source = Source::getSource(Source::stringToId(Settings::instance()->get("source")));
+
+ QList<Source::SearchType> types;
+ source->getSearchTypes(types);
+
+ if(types.size() > 1)
+ {
+ for(int i = 0; i < types.size(); i++)
+ {
+ switch(types.at(i))
+ {
+ case Source::PERSONS:
+ selector_->addItem(tr("Persons"), static_cast<int>(Source::PERSONS));
+ break;
+ case Source::YELLOW_PAGES:
+ selector_->addItem(tr("Companies"), static_cast<int>(Source::YELLOW_PAGES));
+ break;
+ case Source::BOTH:
+ break;
+ }
+ }
+
+ if(!selector_->isVisible())
+ {
+ selector_->show();
+ }
+ }
+ else
+ {
+ selector_->hide();
+ }
+}