Asynchronous updating for remote info in SettingsDlg
authorJari Jarvi <t7jaja00@students.oamk.fi>
Tue, 6 Jul 2010 06:22:22 +0000 (09:22 +0300)
committerJari Jarvi <t7jaja00@students.oamk.fi>
Tue, 6 Jul 2010 06:22:22 +0000 (09:22 +0300)
src/settingsdlg.cpp
src/settingsdlg.h
src/src.pro

index c88da36..a5a0d16 100644 (file)
@@ -10,6 +10,7 @@
 #include <QPushButton>
 #include <QLabel>
 #include <QDebug>
+#include <QNetworkConfiguration>
 
 SettingsDlg::SettingsDlg(QWidget *parent)
     : QDialog(parent)
@@ -61,13 +62,20 @@ SettingsDlg::SettingsDlg(QWidget *parent)
     m_layout->addLayout(m_btnLayout);
     this->setLayout(m_layout);
 
-    QString selectedRemote = QSettings(this).value("remoteName", "").toString();
+    QString selectedRemote = settings.value("remoteName", "").toString();
     if (selectedRemote == "") {
         m_remoteNameLabel->setText("No remote selected");
         enableRateBtns(false);
     } else {
-        setRemote(selectedRemote);
-        setBusy();
+        // Create remote by name and update it's info if online
+        m_remote = Remote(selectedRemote);
+        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);
     }
 }
 
@@ -83,6 +91,7 @@ SettingsDlg::~SettingsDlg()
     delete m_btnLayout;
     delete m_remoteNameLayout;
     delete m_layout;
+    delete m_netConfMan;
 }
 
 void SettingsDlg::setBusy(bool busy)
@@ -114,23 +123,19 @@ void SettingsDlg::showAboutDlg()
 void SettingsDlg::setRemote(Remote r)
 {
     m_remote = r;
-    processRemoteChange();
     updateRemoteInfo();
+    enableRateBtns();
 }
 
-void SettingsDlg::setRemote(const QString &name)
-{
-    setBusy();
-    m_remote = Remote(name);
-    processRemoteChange();
-    m_remote.updateInfo();  // request update from server
-}
-
-void SettingsDlg::processRemoteChange()
+void SettingsDlg::onNetworkStatusUpdate()
 {
-    connect(&m_remote, SIGNAL(infoUpdated()),
-            this, SLOT(updateRemoteInfo()));
-    enableRateBtns();
+    if (m_netConfMan->isOnline()) {
+        setBusy();
+        connect(&m_remote, SIGNAL(infoUpdated()),
+                this, SLOT(updateRemoteInfo()));
+        m_remote.updateInfo();
+        enableRateBtns();
+    }
 }
 
 void SettingsDlg::updateRemoteInfo()
index cf530ab..78c72f6 100644 (file)
@@ -3,6 +3,7 @@
 
 #include <QDialog>
 #include <QSettings>
+#include <QNetworkConfigurationManager>
 
 #include "remote.h"
 
@@ -25,14 +26,13 @@ private slots:
     void showSelectRemoteDlg();
     void showAboutDlg();
     void setRemote(Remote);
-    void setRemote(const QString &name);
     void updateRemoteInfo();
     void rateUpClicked();
     void rateDownClicked();
+    void onNetworkStatusUpdate();
 
 private:
     void enableRateBtns(bool enable = true);
-    void processRemoteChange();
     void processRatingSent();
     void setBusy(bool busy = true);
 
@@ -49,6 +49,7 @@ private:
     QPushButton *m_aboutBtn;
     QLabel *m_remoteNameLabel;
     QLabel *m_ratingLabel;
+    QTM_PREPEND_NAMESPACE(QNetworkConfigurationManager) *m_netConfMan;
 };
 
 #endif
index d631d74..4399b6c 100644 (file)
@@ -36,6 +36,9 @@ MOC_DIR = moc
 QT += network
 QT += xml
 
+CONFIG += mobility
+MOBILITY += bearer
+
 unix {
 #VARIABLES
 isEmpty(PREFIX) {