Unnecessary includes removed.
[jenirok] / src / gui / mainwindow.cpp
index cec7517..7c0221a 100644 (file)
 #include <QtGui/QWidget>
 #include <QtGui/QHBoxLayout>
 #include <QtGui/QMessageBox>
+#include <QtGui/QDialogButtonBox>
+#include <QtGui/QTextEdit>
+#include <QtCore/QDebug>
 #include <QMaemo5InformationBox>
-#include <QDebug>
 #include "mainwindow.h"
 #include "settingsdialog.h"
 #include "searchdialog.h"
@@ -39,7 +41,7 @@ namespace
 
 MainWindow::MainWindow(QWidget* parent): QMainWindow(parent),
 searchResults_(0), settingsDialog_(0), running_(false),
-toggleButton_(0), searchDialog_(0)
+toggleButton_(0), searchDialog_(0), aboutDialog_(0), warning_(0)
 {
     setWindowTitle(tr("Jenirok"));
     setAttribute(Qt::WA_Maemo5StackedWindow);
@@ -76,6 +78,7 @@ toggleButton_(0), searchDialog_(0)
 
     setCentralWidget(mainWidget);
     menuBar()->addAction(tr("Settings"), this, SLOT(showSettings()));
+    menuBar()->addAction(tr("About"), this, SLOT(showAbout()));
 }
 
 MainWindow::~MainWindow()
@@ -85,6 +88,11 @@ MainWindow::~MainWindow()
 
 void MainWindow::showSettings()
 {
+    if(warning_ && warning_->isVisible())
+    {
+        warning_->hide();
+    }
+
     if(!settingsDialog_)
     {
         settingsDialog_ = new SettingsDialog(this);
@@ -109,6 +117,33 @@ void MainWindow::toggleDaemon()
     }
     else
     {
+        if(Settings::instance()->getConnectionType() == Settings::ALWAYS_ASK)
+        {
+            if(!warning_)
+            {
+                warning_ = new QDialog(this);
+                warning_->setWindowTitle(tr("Unable to start daemon"));
+                QHBoxLayout* warningLayout = new QHBoxLayout;
+                QTextEdit* text = new QTextEdit(tr("Daemon cannot be started because it's not allowed to connect to the Internet. You have to either allow automatic Internet connection in Jenirok settings or in global Maemo settings."));
+                text->setReadOnly(true);
+                QDialogButtonBox* buttons = new QDialogButtonBox;
+                buttons->setOrientation(Qt::Vertical);
+                QPushButton* settingsButton = new QPushButton(tr("Open settings"));
+                connect(settingsButton, SIGNAL(pressed()), this, SLOT(showSettings()));
+                QPushButton* okButton = new QPushButton(tr("Close"));
+                connect(okButton, SIGNAL(pressed()), warning_, SLOT(hide()));
+                buttons->addButton(settingsButton, QDialogButtonBox::YesRole);
+                buttons->addButton(okButton, QDialogButtonBox::AcceptRole);
+                warningLayout->addWidget(text);
+                warningLayout->addWidget(buttons);
+                warning_->setLayout(warningLayout);
+            }
+
+            warning_->show();
+
+            return;
+        }
+
         readyText = tr("Daemon was successfully started.");
         failText = tr("Unable to start daemon.");
         buttonText = tr("Stop daemon");
@@ -147,7 +182,8 @@ void MainWindow::openSearch()
     if(!searchDialog_)
     {
         searchDialog_ = new SearchDialog(this);
-        connect(searchDialog_, SIGNAL(search(SearchDialog::SearchDetails&)), this, SLOT(handleSearch(SearchDialog::SearchDetails&)));
+        connect(searchDialog_, SIGNAL(search(SearchDialog::SearchDetails&)),
+                this, SLOT(handleSearch(SearchDialog::SearchDetails&)));
     }
 
     searchDialog_->show();
@@ -165,3 +201,14 @@ void MainWindow::handleSearch(SearchDialog::SearchDetails& details)
 {
     emit search(details);
 }
+
+void MainWindow::showAbout()
+{
+    if(!aboutDialog_)
+    {
+        aboutDialog_ = new AboutDialog(this);
+    }
+
+    aboutDialog_->show();
+
+}