#include "daemon.h"
#include "settings.h"
#include "db.h"
+#include "source.h"
+#include "sourcecoreconfig.h"
namespace
{
MainWindow::MainWindow(QWidget* parent): QMainWindow(parent),
searchResults_(0), settingsDialog_(0), running_(false),
-toggleButton_(0), searchDialog_(0), aboutDialog_(0), warning_(0)
+toggleButton_(0), searchDialog_(0), aboutDialog_(0), warning_(0),
+logWindow_(0)
{
setWindowTitle(tr("Jenirok"));
setAttribute(Qt::WA_Maemo5StackedWindow);
running_ = false;
}
+ QSizePolicy policy;
+
+ policy.setHorizontalPolicy(QSizePolicy::Preferred);
+
+ toggleButton_->setSizePolicy(policy);
+
QToolButton* searchButton = createButton(tr("Search"));
searchButton->setIcon(QIcon::fromTheme("general_search"));
+ searchButton->setSizePolicy(policy);
+
+ QToolButton* logButton = createButton(tr("Log"));
+ logButton->setIcon(QIcon::fromTheme("general_call"));
+ logButton->setSizePolicy(policy);
QSize size(64, 64);
searchButton->setIconSize(size);
toggleButton_->setIconSize(size);
+ logButton->setIconSize(size);
QHBoxLayout *buttonLayout = new QHBoxLayout;
- buttonLayout->addWidget(toggleButton_, Qt::AlignLeft);
- buttonLayout->addWidget(searchButton, Qt::AlignRight);
+ buttonLayout->addWidget(toggleButton_, Qt::AlignHCenter);
+ buttonLayout->addWidget(searchButton, Qt::AlignHCenter);
+ buttonLayout->addWidget(logButton, Qt::AlignHCenter);
mainWidget->setLayout(buttonLayout);
connect(toggleButton_, SIGNAL(pressed()), this, SLOT(toggleDaemon()));
connect(searchButton, SIGNAL(pressed()), this, SLOT(openSearch()));
+ connect(logButton, SIGNAL(pressed()), this, SLOT(openLog()));
setCentralWidget(mainWidget);
menuBar()->addAction(tr("Settings"), this, SLOT(showSettings()));
if(!settingsDialog_)
{
settingsDialog_ = new SettingsDialog(this);
+
+ if(searchDialog_)
+ {
+ connect(settingsDialog_, SIGNAL(saved()), searchDialog_, SLOT(loadSearchTypes()));
+ }
}
settingsDialog_->show();
}
else
{
- QMaemo5InformationBox::information(this, readyText);
+ QMaemo5InformationBox::information(this, readyText, 800);
toggleButton_->setText(buttonText);
toggleButton_->setIcon(QIcon(running_ ? START_ICON : CLOSE_ICON));
running_ = !running_;
}
-void MainWindow::openSearch()
+void MainWindow::openSearch(QString const& str)
{
- DB::connect();
+ Source::SourceId sourceId = Source::stringToId(Settings::instance()->get("source"));
+ SourceCoreConfig* config = SourceCoreConfig::getCoreConfig(sourceId);
- QString username = Settings::instance()->get("eniro_username");
- QString password = Settings::instance()->get("eniro_password");
+ Q_ASSERT(config != 0);
- DB::disconnect();
+ bool readyToSearch = config->readyToSearch();
+ delete config;
- if(username.isEmpty() || password.isEmpty())
+ if(!readyToSearch)
{
- QMessageBox::information(this, tr("Info"), tr("You need to set Eniro login details in settings before using this feature."));
+ QMessageBox::information(this, tr("Info"), tr("You need to set login details or other options in settings before using this feature."));
return;
}
{
searchDialog_ = new SearchDialog(this);
connect(searchDialog_, SIGNAL(search(SearchDialog::SearchDetails&)),
- this, SLOT(handleSearch(SearchDialog::SearchDetails&)));
+ this, SIGNAL(search(SearchDialog::SearchDetails&)));
+
+ if(settingsDialog_)
+ {
+ connect(settingsDialog_, SIGNAL(saved()), searchDialog_, SLOT(loadSearchTypes()));
+ }
+ }
+
+ if(!str.isEmpty())
+ {
+ searchDialog_->setSearchString(str);
}
searchDialog_->show();
}
+void MainWindow::openLog()
+{
+ if(!logWindow_)
+ {
+ 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();
+}
+
QToolButton* MainWindow::createButton(QString const& text)
{
QToolButton* button = new QToolButton();
return button;
}
-void MainWindow::handleSearch(SearchDialog::SearchDetails& details)
-{
- emit search(details);
-}
-
void MainWindow::showAbout()
{
if(!aboutDialog_)