Fixed some logic bugs in settingsdlg
[irwi] / src / settingsdlg.cpp
index 8755529..e596a66 100644 (file)
 #include <QLabel>
 #include <QDebug>
 #include <QNetworkConfiguration>
+#include <QShowEvent>
 
 SettingsDlg::SettingsDlg(QWidget *parent)
     : QDialog(parent)
+    , m_busy(true)
+    , m_netConfMan(NULL)
 {
     QSettings settings(this);
     m_layout = new QVBoxLayout(this);
@@ -65,18 +68,19 @@ SettingsDlg::SettingsDlg(QWidget *parent)
     QString selectedRemote = settings.value("remoteName", "").toString();
     if (selectedRemote == "") {
         m_remoteNameLabel->setText(tr("No remote selected"));
-        enableRateBtns(false);
     } else {
         // Create remote by name and update it's info if online
         m_remote = Remote(selectedRemote);
+        connect(&m_remote, SIGNAL(infoUpdated()),
+                this, SLOT(updateRemoteInfo()));
         m_remoteNameLabel->setText(selectedRemote);
-        m_netConfMan = new QTM_PREPEND_NAMESPACE(
-                QNetworkConfigurationManager)(this);
-        connect(m_netConfMan, SIGNAL(updateCompleted()),
-                this, SLOT(onNetworkStatusUpdate()));
-        m_netConfMan->updateConfigurations();
-        enableRateBtns(false);
     }
+    m_netConfMan = new QTM_PREPEND_NAMESPACE(
+            QNetworkConfigurationManager)(this);
+    connect(m_netConfMan, SIGNAL(updateCompleted()),
+            this, SLOT(onNetworkStatusUpdate()));
+    m_netConfMan->updateConfigurations();
+    enableRateBtns(false);
 }
 
 SettingsDlg::~SettingsDlg()
@@ -97,7 +101,7 @@ SettingsDlg::~SettingsDlg()
 void SettingsDlg::setBusy(bool busy)
 {
     setAttribute(Qt::WA_Maemo5ShowProgressIndicator, busy);
-    setEnabled(!busy);
+    m_busy = busy;
 }
 
 void SettingsDlg::showAdvSettingsDlg()
@@ -112,7 +116,6 @@ void SettingsDlg::showSelectRemoteDlg()
     connect(&dlg, SIGNAL(remoteChanged(Remote)),
             this, SLOT(setRemote(Remote)));
     dlg.exec();
-    onNetworkStatusUpdate();
 }
 
 void SettingsDlg::showAboutDlg()
@@ -124,20 +127,24 @@ void SettingsDlg::showAboutDlg()
 void SettingsDlg::setRemote(Remote r)
 {
     m_remote = r;
+    connect(&m_remote, SIGNAL(infoUpdated()),
+            this, SLOT(updateRemoteInfo()));
     updateRemoteInfo();
     enableRateBtns();
 }
 
 void SettingsDlg::onNetworkStatusUpdate()
 {
-    if (m_netConfMan->isOnline()) {
+    if (m_netConfMan->isOnline() &&
+        QSettings(this).value("remoteName", "").toString() != "") {
         setBusy();
-        connect(&m_remote, SIGNAL(infoUpdated()),
-                this, SLOT(updateRemoteInfo()));
         m_remote.updateInfo();
         enableRateBtns();
-    } else {
+    } else if (!m_netConfMan->isOnline()) {
         m_ratingLabel->setText(tr("Offline"));
+        setBusy(false);
+    } else {
+        setBusy(false);
     }
 }
 
@@ -151,20 +158,20 @@ void SettingsDlg::updateRemoteInfo()
 
 void SettingsDlg::rateUpClicked()
 {
-    m_remote.sendRating(Rating::Up);
     processRatingSent();
+    m_remote.sendRating(Rating::Up);
 }
 
 void SettingsDlg::rateDownClicked()
 {
-    m_remote.sendRating(Rating::Down);
     processRatingSent();
+    m_remote.sendRating(Rating::Down);
 }
 
 void SettingsDlg::processRatingSent()
 {
+    setBusy();
     enableRateBtns(false);
-    m_remote.updateInfo();
 }
 
 void SettingsDlg::enableRateBtns(bool enable)
@@ -173,4 +180,11 @@ void SettingsDlg::enableRateBtns(bool enable)
     m_rateDownBtn->setEnabled(enable);
 }
 
+void SettingsDlg::showEvent(QShowEvent *event)
+{
+    setBusy(m_busy);
+    QDialog::showEvent(event);
+}
+
+