From bf7fb8b9ca33a5f079f9a1797eac96eda84c9bb1 Mon Sep 17 00:00:00 2001 From: eshe Date: Tue, 17 Aug 2010 11:07:45 +0100 Subject: [PATCH] Some optimization to settings and searching. --- src/common/dastelefonbuch.cpp | 14 +++++++------- src/common/mobil1881.cpp | 19 ++++++++++++------- src/common/settings.cpp | 11 +++++++++++ src/common/settings.h | 2 ++ src/daemon/calllistener.cpp | 4 ---- src/daemon/calllistener.h | 2 +- src/gui/logwindow.cpp | 24 +++++++++++++----------- src/gui/logwindow.h | 1 + src/gui/mainwindow.cpp | 15 ++++++++------- src/gui/mainwindow.h | 3 +-- src/gui/searchdialog.cpp | 5 +++++ src/gui/searchdialog.h | 1 + 12 files changed, 62 insertions(+), 39 deletions(-) diff --git a/src/common/dastelefonbuch.cpp b/src/common/dastelefonbuch.cpp index 7ab3ed4..7cb36ad 100644 --- a/src/common/dastelefonbuch.cpp +++ b/src/common/dastelefonbuch.cpp @@ -113,10 +113,10 @@ void DasTelefonbuch::addNumbers(SearchData* searchData, } int pos = 0; - QRegExp rx(""); - QRegExp name("
(.*)"); - QRegExp number("(.*)"); - QRegExp address("(.*).*(.*)"); + static QRegExp rx(""); + static QRegExp name("
(.*)"); + static QRegExp number("(.*)"); + static QRegExp address("(.*).*(.*)"); rx.setMinimal(true); name.setMinimal(true); @@ -197,9 +197,9 @@ void DasTelefonbuch::addOnlyNumber(SearchData* searchData, QString const& data, int index) { - QRegExp name("
(.*) (.*)"); - QRegExp number("(.*)"); - QRegExp address("(.*).*(.*)"); + static QRegExp name("
(.*) (.*)"); + static QRegExp number("(.*)"); + static QRegExp address("(.*).*(.*)"); name.setMinimal(true); number.setMinimal(true); address.setMinimal(true); diff --git a/src/common/mobil1881.cpp b/src/common/mobil1881.cpp index 6bc9deb..6ded070 100644 --- a/src/common/mobil1881.cpp +++ b/src/common/mobil1881.cpp @@ -114,10 +114,10 @@ void Mobil1881::addNumbers(SearchData* searchData, } int pos = 0; - QRegExp rx("(.*)"); - QRegExp name("
(.*)
"); - QRegExp address("
(.*),
(.*)
"); - QRegExp number("
(.*)
"); + static QRegExp rx("(.*)"); + static QRegExp name("
(.*)
"); + static QRegExp address("
(.*),
(.*)
"); + static QRegExp number("
(.*)
"); rx.setMinimal(true); name.setMinimal(true); address.setMinimal(true); @@ -171,6 +171,11 @@ void Mobil1881::addNumbers(SearchData* searchData, if(searchData->results.size() >= maxResults) { emitRequestFinished(searchData, false, index); + + if(searchData->totalSearches > 1) + { + abort(); + } } else { @@ -192,9 +197,9 @@ void Mobil1881::addOnlyNumber(SearchData* searchData, QString const& data, int index) { - QRegExp name("
(.*)
"); - QRegExp number("class=\"srlttxt\">(.*)"); - QRegExp address("class=\"srlttxt\">(.*),
(.*)
"); + static QRegExp name("
(.*)
"); + static QRegExp number("class=\"srlttxt\">(.*)"); + static QRegExp address("class=\"srlttxt\">(.*),
(.*)
"); name.setMinimal(true); number.setMinimal(true); address.setMinimal(true); diff --git a/src/common/settings.cpp b/src/common/settings.cpp index 21962d9..6453bb3 100644 --- a/src/common/settings.cpp +++ b/src/common/settings.cpp @@ -129,11 +129,20 @@ bool Settings::set(QString const& name, QString const& value) endEdit(); } + settings_[name] = value; + return returnValue; } QString Settings::get(QString const& name) { + QMap::iterator it; + + if((it = settings_.find(name)) != settings_.end()) + { + return it.value(); + } + QString result = ""; bool close = !editing_; @@ -159,6 +168,8 @@ QString Settings::get(QString const& name) endEdit(); } + settings_[name] = result; + return result; } diff --git a/src/common/settings.h b/src/common/settings.h index c732299..c0d0a5f 100644 --- a/src/common/settings.h +++ b/src/common/settings.h @@ -21,6 +21,7 @@ #include #include +#include #include class Settings; @@ -55,6 +56,7 @@ public: private: Settings(); static Settings* instance_; + QMap settings_; bool editing_; }; diff --git a/src/daemon/calllistener.cpp b/src/daemon/calllistener.cpp index b4d80d4..79a6485 100644 --- a/src/daemon/calllistener.cpp +++ b/src/daemon/calllistener.cpp @@ -111,8 +111,6 @@ void CallListener::end() void CallListener::search(Source::SearchDetails const& details) { - qDebug() << "Search called"; - if(currentCall_) { delete currentCall_; @@ -150,8 +148,6 @@ void CallListener::search(Source::SearchDetails const& details) showDelayedResult(tr("Searching..."), BANNER_DELAY); - qDebug() << "Starting to search..."; - source_->search(details); } diff --git a/src/daemon/calllistener.h b/src/daemon/calllistener.h index 5e1d18b..23b97eb 100644 --- a/src/daemon/calllistener.h +++ b/src/daemon/calllistener.h @@ -40,7 +40,7 @@ public: static const int BANNER_DELAY = 350; static const int SEARCH_RETRIES = 2; static const int CONNECT_RETRIES = 2; - static const int CONNECTION_LOOKUP_RETRIES = 10; + static const int CONNECTION_LOOKUP_RETRIES = 8; static const int GPRS_SCANS = 2; static const int WLAN_SCANS = 5; static const int WAIT_BETWEEN_RETRIES = 500; diff --git a/src/gui/logwindow.cpp b/src/gui/logwindow.cpp index 4197111..bd57ce5 100644 --- a/src/gui/logwindow.cpp +++ b/src/gui/logwindow.cpp @@ -90,20 +90,22 @@ void LogWindow::itemClicked(int index) } QMap data = list_->getData(index).toMap(); - Source::Result details; - details.name = data["name"].toString(); - if(details.name.isEmpty()) + if(data["name"].toString().isEmpty()) { - return; + emit openSearch(data["number"].toString()); + } + else + { + Source::Result details; + details.name = data["name"].toString(); + details.street = data["street"].toString(); + details.city = data["city"].toString(); + details.number = data["number"].toString(); + details.country = data["country"].toString(); + + emit logItemSelected(details); } - - details.street = data["street"].toString(); - details.city = data["city"].toString(); - details.number = data["number"].toString(); - details.country = data["country"].toString(); - - emit logItemSelected(details); } QWidget* LogWindow::createWidget(Cache::LogDetails const& details) diff --git a/src/gui/logwindow.h b/src/gui/logwindow.h index 2afe7e7..a242a4f 100644 --- a/src/gui/logwindow.h +++ b/src/gui/logwindow.h @@ -35,6 +35,7 @@ public: signals: void logItemSelected(Source::Result const& result); + void openSearch(QString const& number); protected: void setVisible(bool visible); diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 3e62491..4388860 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -186,7 +186,7 @@ void MainWindow::toggleDaemon() } -void MainWindow::openSearch() +void MainWindow::openSearch(QString const& str) { Source::SourceId sourceId = Source::stringToId(Settings::instance()->get("source")); SourceCoreConfig* config = SourceCoreConfig::getCoreConfig(sourceId); @@ -206,7 +206,7 @@ void MainWindow::openSearch() { searchDialog_ = new SearchDialog(this); connect(searchDialog_, SIGNAL(search(SearchDialog::SearchDetails&)), - this, SLOT(handleSearch(SearchDialog::SearchDetails&))); + this, SIGNAL(search(SearchDialog::SearchDetails&))); if(settingsDialog_) { @@ -214,6 +214,11 @@ void MainWindow::openSearch() } } + if(!str.isEmpty()) + { + searchDialog_->setSearchString(str); + } + searchDialog_->show(); } @@ -223,6 +228,7 @@ void MainWindow::openLog() { logWindow_ = new LogWindow(this); connect(logWindow_, SIGNAL(logItemSelected(Source::Result const&)), this, SIGNAL(logItemSelected(Source::Result const&))); + connect(logWindow_, SIGNAL(openSearch(QString const&)), this, SLOT(openSearch(QString const&))); } logWindow_->show(); @@ -236,11 +242,6 @@ QToolButton* MainWindow::createButton(QString const& text) return button; } -void MainWindow::handleSearch(SearchDialog::SearchDetails& details) -{ - emit search(details); -} - void MainWindow::showAbout() { if(!aboutDialog_) diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h index 98ff0c6..b859be0 100644 --- a/src/gui/mainwindow.h +++ b/src/gui/mainwindow.h @@ -45,9 +45,8 @@ public slots: void showSettings(); void showAbout(); void toggleDaemon(); - void openSearch(); + void openSearch(QString const& str = QString()); void openLog(); - void handleSearch(SearchDialog::SearchDetails& details); private: QToolButton* createButton(QString const& text); diff --git a/src/gui/searchdialog.cpp b/src/gui/searchdialog.cpp index a6224cb..ea412a9 100644 --- a/src/gui/searchdialog.cpp +++ b/src/gui/searchdialog.cpp @@ -99,6 +99,11 @@ void SearchDialog::setVisible(bool visible) } } +void SearchDialog::setSearchString(QString const& string) +{ + numberInput_->setText(string); +} + void SearchDialog::loadSearchTypes() { selector_->clear(); diff --git a/src/gui/searchdialog.h b/src/gui/searchdialog.h index 2f57a9b..0a143e0 100644 --- a/src/gui/searchdialog.h +++ b/src/gui/searchdialog.h @@ -48,6 +48,7 @@ signals: public slots: void loadSearchTypes(); + void setSearchString(QString const& string); private slots: void searchPressed(); -- 1.7.9.5