2 * This file is part of Jenirok.
4 * Jenirok is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Jenirok is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Jenirok. If not, see <http://www.gnu.org/licenses/>.
19 #include <QtGui/QMenuBar>
20 #include <QtGui/QLabel>
21 #include <QtGui/QPushButton>
22 #include <QtGui/QWidget>
23 #include <QtGui/QHBoxLayout>
24 #include <QtGui/QMessageBox>
25 #include <QMaemo5InformationBox>
27 #include "mainwindow.h"
28 #include "settingsdialog.h"
29 #include "searchdialog.h"
36 const QString START_ICON = ":/icons/start.png";
37 const QString CLOSE_ICON = ":/icons/stop.png";
40 MainWindow::MainWindow(QWidget* parent): QMainWindow(parent),
41 searchResults_(0), settingsDialog_(0), running_(false),
42 toggleButton_(0), searchDialog_(0)
44 setWindowTitle(tr("Jenirok"));
45 setAttribute(Qt::WA_Maemo5StackedWindow);
46 QWidget* mainWidget = new QWidget(this);
48 if(Daemon::isRunning())
50 toggleButton_ = createButton(tr("Stop daemon"));
51 toggleButton_->setIcon(QIcon(CLOSE_ICON));
56 toggleButton_ = createButton(tr("Start daemon"));
57 toggleButton_->setIcon(QIcon(START_ICON));
61 QToolButton* searchButton = createButton(tr("Search"));
62 searchButton->setIcon(QIcon::fromTheme("general_search"));
65 searchButton->setIconSize(size);
66 toggleButton_->setIconSize(size);
68 QHBoxLayout *buttonLayout = new QHBoxLayout;
69 buttonLayout->addWidget(toggleButton_, Qt::AlignLeft);
70 buttonLayout->addWidget(searchButton, Qt::AlignRight);
72 mainWidget->setLayout(buttonLayout);
74 connect(toggleButton_, SIGNAL(pressed()), this, SLOT(toggleDaemon()));
75 connect(searchButton, SIGNAL(pressed()), this, SLOT(openSearch()));
77 setCentralWidget(mainWidget);
78 menuBar()->addAction(tr("Settings"), this, SLOT(showSettings()));
81 MainWindow::~MainWindow()
86 void MainWindow::showSettings()
90 settingsDialog_ = new SettingsDialog(this);
93 settingsDialog_->show();
96 void MainWindow::toggleDaemon()
105 readyText = tr("Daemon was successfully stopped.");
106 failText = tr("Unable to stop daemon.");
107 buttonText = tr("Start daemon");
108 ret = Daemon::stop();
112 readyText = tr("Daemon was successfully started.");
113 failText = tr("Unable to start daemon.");
114 buttonText = tr("Stop daemon");
115 ret = Daemon::start();
120 QMessageBox::critical(this, tr("Error"), failText);
124 QMaemo5InformationBox::information(this, readyText);
125 toggleButton_->setText(buttonText);
126 toggleButton_->setIcon(QIcon(running_ ? START_ICON : CLOSE_ICON));
127 running_ = !running_;
132 void MainWindow::openSearch()
136 QString username = Settings::instance()->get("eniro_username");
137 QString password = Settings::instance()->get("eniro_password");
141 if(username.isEmpty() || password.isEmpty())
143 QMessageBox::information(this, tr("Info"), tr("You need to set Eniro login details in settings before using this feature."));
149 searchDialog_ = new SearchDialog(this);
150 connect(searchDialog_, SIGNAL(search(SearchDialog::SearchDetails&)), this, SLOT(handleSearch(SearchDialog::SearchDetails&)));
153 searchDialog_->show();
156 QToolButton* MainWindow::createButton(QString const& text)
158 QToolButton* button = new QToolButton();
159 button->setText(text);
160 button->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
164 void MainWindow::handleSearch(SearchDialog::SearchDetails& details)
166 emit search(details);