...
[jenirok] / src / gui / searchdialog.cpp
index 58dd94f..ea412a9 100644 (file)
@@ -23,6 +23,7 @@
 #include <QtGui/QDialogButtonBox>
 #include <QMaemo5ValueButton>
 #include "searchdialog.h"
+#include "settings.h"
 
 SearchDialog::SearchDialog(QWidget* parent): QDialog(parent),
 numberInput_(0), locationInput_(0), selector_(0)
@@ -42,8 +43,7 @@ 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);
@@ -75,7 +75,16 @@ void SearchDialog::searchPressed()
     }
 
     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();
 }
@@ -89,3 +98,45 @@ void SearchDialog::setVisible(bool visible)
         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();
+    }
+}