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), aboutDialog_(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()));
79 menuBar()->addAction(tr("About"), this, SLOT(showAbout()));
82 MainWindow::~MainWindow()
87 void MainWindow::showSettings()
91 settingsDialog_ = new SettingsDialog(this);
94 settingsDialog_->show();
97 void MainWindow::toggleDaemon()
106 readyText = tr("Daemon was successfully stopped.");
107 failText = tr("Unable to stop daemon.");
108 buttonText = tr("Start daemon");
109 ret = Daemon::stop();
113 readyText = tr("Daemon was successfully started.");
114 failText = tr("Unable to start daemon.");
115 buttonText = tr("Stop daemon");
116 ret = Daemon::start();
121 QMessageBox::critical(this, tr("Error"), failText);
125 QMaemo5InformationBox::information(this, readyText);
126 toggleButton_->setText(buttonText);
127 toggleButton_->setIcon(QIcon(running_ ? START_ICON : CLOSE_ICON));
128 running_ = !running_;
133 void MainWindow::openSearch()
137 QString username = Settings::instance()->get("eniro_username");
138 QString password = Settings::instance()->get("eniro_password");
142 if(username.isEmpty() || password.isEmpty())
144 QMessageBox::information(this, tr("Info"), tr("You need to set Eniro login details in settings before using this feature."));
150 searchDialog_ = new SearchDialog(this);
151 connect(searchDialog_, SIGNAL(search(SearchDialog::SearchDetails&)), this, SLOT(handleSearch(SearchDialog::SearchDetails&)));
154 searchDialog_->show();
157 QToolButton* MainWindow::createButton(QString const& text)
159 QToolButton* button = new QToolButton();
160 button->setText(text);
161 button->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
165 void MainWindow::handleSearch(SearchDialog::SearchDetails& details)
167 emit search(details);
170 void MainWindow::showAbout()
174 aboutDialog_ = new AboutDialog(this);
177 aboutDialog_->show();