Add if ( host.contains(":")) to avoid crash
[vlc-remote] / accountdialog.cpp
index c87215a..5b19fb6 100644 (file)
@@ -109,22 +109,28 @@ void AccountDialog::load()
 
 QListWidgetItem AccountDialog::asyncTestItem(const QListWidgetItem& item)
 {
+    //==========> NEED TO USE POINTER TO AVOID setAsyncItem! But I don't know how;..
     QListWidgetItem newItem = item;
 
     QTcpSocket * socket = new QTcpSocket;
     QSettings settings;
     QString host = settings.value("account/"+item.text()).toString();
-    QStringList hostSplit = host.split(":");
-    QString ip   = hostSplit.at(0);
-    QString port = hostSplit.at(1);
 
+    if(host.contains(":"))
+    {
+        QStringList hostSplit = host.split(":");
+        QString ip   = hostSplit.at(0);
+        QString port = hostSplit.at(1);
+        socket->connectToHost(ip,port.toInt());
+    }
 
-    socket->connectToHost(ip,port.toInt());
+    else
+        socket->connectToHost(host,8080);
 
     if (socket->waitForConnected(1000))
-        newItem.setBackgroundColor(Qt::green);
+        newItem.setIcon(QIcon::fromTheme("widgets_tickmark_list"));
     else
-        newItem.setBackgroundColor(Qt::red);
+        newItem.setIcon(QIcon::fromTheme("statusarea_presence_busy_error"));
 
     return newItem;
 
@@ -138,7 +144,7 @@ void AccountDialog::setAsyncItem(int row)  // EDIT THE ROW AFTER ASYNC FUNCTION
     QListWidgetItem newItem = mFuturWatcher->resultAt(row);
     QListWidgetItem * item = ui->listWidget->item(row);
 
-    item->setBackgroundColor(newItem.backgroundColor());
+    item->setIcon(newItem.icon());
 
 
 
@@ -176,6 +182,7 @@ void AccountDialog::use()
     QSettings settings;
     settings.setValue("config/currentKey", currentKey);
     load();
+    emit accept();
 }
 
 void AccountDialog::enableUi()