From 07e0d59c6ec1c43f9c3aa2512cbe7774fa2c6753 Mon Sep 17 00:00:00 2001 From: eshe Date: Sun, 18 Jul 2010 21:27:58 +0100 Subject: [PATCH] Added Das Telefonbuch support. --- debian/postinst | 1 - src/common/source.cpp | 17 +++++++++++++-- src/common/source.h | 5 +++-- src/common/sourcecoreconfig.cpp | 1 + src/daemon/daemon.pro | 6 ++++-- src/gui/gui.pro | 6 ++++-- src/gui/mainwindow.cpp | 10 +++++++++ src/gui/searchdialog.cpp | 44 ++++++++++++++++++++++++++++++++++++--- src/gui/searchdialog.h | 3 +++ src/gui/settingsdialog.cpp | 2 ++ src/gui/settingsdialog.h | 3 +++ src/gui/sourceguiconfig.cpp | 1 + 12 files changed, 87 insertions(+), 12 deletions(-) diff --git a/debian/postinst b/debian/postinst index 9dbc6dc..1d89f14 100644 --- a/debian/postinst +++ b/debian/postinst @@ -1,6 +1,5 @@ #!/bin/sh -e -gtk-update-icon-cache -f /usr/share/icons/hicolor /etc/init.d/jenirokd start -boot exit 0 diff --git a/src/common/source.cpp b/src/common/source.cpp index 460f98e..21245b9 100644 --- a/src/common/source.cpp +++ b/src/common/source.cpp @@ -20,19 +20,22 @@ #include "source.h" #include "eniro.h" #include "mobil1881.h" +#include "dastelefonbuch.h" namespace { static const QString SOURCE_NAMES[Source::SOURCE_COUNT] = { "Eniro (FI, SE, DK)", - "1881 Mobil (NO)" + "1881 Mobil (NO)", + "Das Telefonbuch (DE)" }; static const QString SOURCE_IDS[Source::SOURCE_COUNT] = { "eniro", - "1881mobil" + "1881mobil", + "dastelefonbuch" }; } @@ -53,6 +56,9 @@ Source* Source::getSource(Source::SourceId id, QObject* parent) case MOBIL1881: return new Mobil1881(parent); break; + case DASTELEFONBUCH: + return new DasTelefonbuch(parent); + break; default: qDebug() << "Unknown source:" << id; } @@ -112,6 +118,13 @@ unsigned int Source::getMaxResults() const return maxResults_; } +void Source::getSearchTypes(QList& types) const +{ + types.clear(); + types.push_back(PERSONS); + types.push_back(YELLOW_PAGES); +} + void Source::setTimeout(unsigned int timeout) { timeout_ = timeout; diff --git a/src/common/source.h b/src/common/source.h index 3477380..6af26b2 100644 --- a/src/common/source.h +++ b/src/common/source.h @@ -55,8 +55,8 @@ public: enum Error {NO_ERROR, CONNECTION_FAILURE, INVALID_LOGIN, TIMEOUT}; - enum SourceId {ENIRO, MOBIL1881}; - static int const SOURCE_COUNT = 2; + enum SourceId {ENIRO, MOBIL1881, DASTELEFONBUCH}; + static int const SOURCE_COUNT = 3; struct SourceDetails { @@ -75,6 +75,7 @@ public: static Source* getSource(); virtual void abort(); virtual void search(SearchDetails const& details) = 0; + virtual void getSearchTypes(QList& types) const; void setMaxResults(unsigned int results); unsigned int getMaxResults() const; void setTimeout(unsigned int ms); diff --git a/src/common/sourcecoreconfig.cpp b/src/common/sourcecoreconfig.cpp index 79c88c6..09a66d5 100644 --- a/src/common/sourcecoreconfig.cpp +++ b/src/common/sourcecoreconfig.cpp @@ -37,6 +37,7 @@ SourceCoreConfig* SourceCoreConfig::getCoreConfig(Source::SourceId id) return new EniroCoreConfig(); break; case Source::MOBIL1881: + case Source::DASTELEFONBUCH: return new EmptyCoreConfig(); // No configuration break; default: diff --git a/src/daemon/daemon.pro b/src/daemon/daemon.pro index 26485e3..d9e3ccd 100644 --- a/src/daemon/daemon.pro +++ b/src/daemon/daemon.pro @@ -15,7 +15,8 @@ SOURCES += main.cpp \ ../common/db.cpp \ ../common/settings.cpp \ ../common/connectionmanager.cpp \ - ../common/cache.cpp + ../common/cache.cpp \ + ../common/dastelefonbuch.cpp HEADERS += calllistener.h \ informationbox.h \ ../common/source.h \ @@ -28,7 +29,8 @@ HEADERS += calllistener.h \ ../common/db.h \ ../common/settings.h \ ../common/connectionmanager.h \ - ../common/cache.h + ../common/cache.h \ + ../common/dastelefonbuch.h TRANSLATIONS = ../common/translations/fi_FI.ts RESOURCES = ../common/translations.grc INCLUDEPATH += ../common diff --git a/src/gui/gui.pro b/src/gui/gui.pro index d93bd09..3492c0a 100644 --- a/src/gui/gui.pro +++ b/src/gui/gui.pro @@ -24,7 +24,8 @@ SOURCES += main.cpp \ ../common/db.cpp \ ../common/settings.cpp \ ../common/connectionmanager.cpp \ - ../common/cache.cpp + ../common/cache.cpp \ + ../common/dastelefonbuch.cpp HEADERS += mainwindow.h \ searchdialog.h \ resultwindow.h \ @@ -47,7 +48,8 @@ HEADERS += mainwindow.h \ ../common/db.h \ ../common/settings.h \ ../common/connectionmanager.h \ - ../common/cache.h + ../common/cache.h \ + ../common/dastelefonbuch.h TRANSLATIONS = ../common/translations/fi_FI.ts RESOURCES = icons.grc ../common/translations.grc INCLUDEPATH += ../common diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 8a5c71d..2d4800d 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -98,6 +98,11 @@ void MainWindow::showSettings() if(!settingsDialog_) { settingsDialog_ = new SettingsDialog(this); + + if(searchDialog_) + { + connect(settingsDialog_, SIGNAL(saved()), searchDialog_, SLOT(loadSearchTypes())); + } } settingsDialog_->show(); @@ -187,6 +192,11 @@ void MainWindow::openSearch() searchDialog_ = new SearchDialog(this); connect(searchDialog_, SIGNAL(search(SearchDialog::SearchDetails&)), this, SLOT(handleSearch(SearchDialog::SearchDetails&))); + + if(settingsDialog_) + { + connect(settingsDialog_, SIGNAL(saved()), searchDialog_, SLOT(loadSearchTypes())); + } } searchDialog_->show(); diff --git a/src/gui/searchdialog.cpp b/src/gui/searchdialog.cpp index 58dd94f..5ee806c 100644 --- a/src/gui/searchdialog.cpp +++ b/src/gui/searchdialog.cpp @@ -23,6 +23,8 @@ #include #include #include "searchdialog.h" +#include "source.h" +#include "settings.h" SearchDialog::SearchDialog(QWidget* parent): QDialog(parent), numberInput_(0), locationInput_(0), selector_(0) @@ -42,8 +44,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 +76,7 @@ void SearchDialog::searchPressed() } details.location = locationInput_->text(); - details.type = selector_->currentIndex(); + details.type = selector_->value().toInt(); emit search(details); hide(); } @@ -89,3 +90,40 @@ void SearchDialog::setVisible(bool visible) numberInput_->setFocus(); } } + +void SearchDialog::loadSearchTypes() +{ + selector_->clear(); + + Source* source = Source::getSource(Source::stringToId(Settings::instance()->get("source"))); + + QList 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(Source::PERSONS)); + break; + case Source::YELLOW_PAGES: + selector_->addItem(tr("Companies"), static_cast(Source::YELLOW_PAGES)); + break; + case Source::BOTH: + break; + } + } + + if(!selector_->isVisible()) + { + selector_->show(); + } + } + else + { + selector_->hide(); + } +} diff --git a/src/gui/searchdialog.h b/src/gui/searchdialog.h index 193ee83..05c54c5 100644 --- a/src/gui/searchdialog.h +++ b/src/gui/searchdialog.h @@ -45,6 +45,9 @@ public: signals: void search(SearchDialog::SearchDetails& details); +public slots: + void loadSearchTypes(); + private slots: void searchPressed(); diff --git a/src/gui/settingsdialog.cpp b/src/gui/settingsdialog.cpp index 44207c6..2c3ee77 100644 --- a/src/gui/settingsdialog.cpp +++ b/src/gui/settingsdialog.cpp @@ -188,6 +188,8 @@ void SettingsDialog::saveSettings() Daemon::restart(); } + emit saved(); + } void SettingsDialog::resetCache() diff --git a/src/gui/settingsdialog.h b/src/gui/settingsdialog.h index 9686e37..b93b028 100644 --- a/src/gui/settingsdialog.h +++ b/src/gui/settingsdialog.h @@ -42,6 +42,9 @@ class SettingsDialog : public QDialog public: SettingsDialog(QWidget* parent = 0); +signals: + void saved(); + public slots: void saveSettings(); void resetCache(); diff --git a/src/gui/sourceguiconfig.cpp b/src/gui/sourceguiconfig.cpp index 70f214a..5d918bb 100644 --- a/src/gui/sourceguiconfig.cpp +++ b/src/gui/sourceguiconfig.cpp @@ -39,6 +39,7 @@ SourceGuiConfig* SourceGuiConfig::getGuiConfig(Source::SourceId id, QWidget* par return new EniroGuiConfig(parent); break; case Source::MOBIL1881: + case Source::DASTELEFONBUCH: return new EmptyGuiConfig(parent); // No configuration break; default: -- 1.7.9.5