Connection handling improved again. Added ability to bybass general Maemo connectivit...
[jenirok] / src / gui / mainwindow.cpp
index 1e4de14..f16e852 100644 (file)
@@ -22,6 +22,8 @@
 #include <QtGui/QWidget>
 #include <QtGui/QHBoxLayout>
 #include <QtGui/QMessageBox>
+#include <QtGui/QDialogButtonBox>
+#include <QtGui/QTextEdit>
 #include <QMaemo5InformationBox>
 #include <QDebug>
 #include "mainwindow.h"
@@ -39,7 +41,7 @@ namespace
 
 MainWindow::MainWindow(QWidget* parent): QMainWindow(parent),
 searchResults_(0), settingsDialog_(0), running_(false),
-toggleButton_(0), searchDialog_(0), aboutDialog_(0)
+toggleButton_(0), searchDialog_(0), aboutDialog_(0), warning_(0)
 {
     setWindowTitle(tr("Jenirok"));
     setAttribute(Qt::WA_Maemo5StackedWindow);
@@ -86,6 +88,11 @@ MainWindow::~MainWindow()
 
 void MainWindow::showSettings()
 {
+    if(warning_ && warning_->isVisible())
+    {
+        warning_->hide();
+    }
+
     if(!settingsDialog_)
     {
         settingsDialog_ = new SettingsDialog(this);
@@ -110,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");