Start to add an asynchronious function to test each IP. (not working yet)
authorschutz <schutz@schutz.(none)>
Sun, 15 Aug 2010 19:37:06 +0000 (21:37 +0200)
committerschutz <schutz@schutz.(none)>
Sun, 15 Aug 2010 19:37:06 +0000 (21:37 +0200)
accountdialog.cpp
accountdialog.h

index 4256d06..009e220 100644 (file)
@@ -5,7 +5,8 @@
 #include <QInputDialog>
 #include <QSettings>
 #include <QTcpSocket>
-
+#include <QFuture>
+#include <QtConcurrentRun>
 AccountDialog::AccountDialog(QWidget *parent) :
         QDialog(parent),
         ui(new Ui::AccountDialog)
@@ -52,16 +53,6 @@ void AccountDialog::load()
     {
         QListWidgetItem * item = new QListWidgetItem;
 
-        // ========> NEED TO USE QFUTUR
-        //        QString hostIp = settings.value(key).toString();
-        //        QTcpSocket * socket = new QTcpSocket(this);
-        //        socket->connectToHost(hostIp, 80);
-        //        if (socket->waitForConnected(1000))
-        //            item->setBackgroundColor(Qt::green);
-        //        else
-        //            item->setBackgroundColor(Qt::red);
-
-
         item->setText(key);
         item->setData(Qt::UserRole, settings.value(key));
         if (useKey == key) {
@@ -72,8 +63,40 @@ void AccountDialog::load()
         ui->listWidget->addItem(item);
     }
     settings.endGroup();    
+
+
+
 }
 
+
+void AccountDialog::asyncTestConnection()
+{
+    QSettings settings;
+    settings.beginGroup("account");
+
+    for ( int i=0; i<ui->listWidget->count(); ++i)
+    {
+
+        QListWidgetItem * item = ui->listWidget->item(i);
+        QString key = item->text();
+        QString hostIp = settings.value(key).toString();
+        qDebug()<<hostIp;
+        QTcpSocket * socket = new QTcpSocket(this);
+        socket->connectToHost(hostIp, 80);
+
+        if (socket->waitForConnected(1000))
+            item->setBackgroundColor(Qt::green);
+        else
+            item->setBackgroundColor(Qt::red);
+
+
+    }
+
+    settings.endGroup();
+
+}
+
+
 void AccountDialog::edit()
 {
     QString currentIp = ui->listWidget->currentItem()->data(Qt::UserRole).toString();
index 11cdda1..75d64a3 100644 (file)
@@ -14,6 +14,9 @@ class AccountDialog : public QDialog
 public:
     explicit AccountDialog(QWidget *parent = 0);
     ~AccountDialog();
+    void asyncTestConnection();
+
+
 
 public slots:
     void add();