X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;f=accountdialog.cpp;h=4c8a5fa09b9ba5012b3a8b0cb61949d7beded453;hb=3606d69e42b19947969814e44eb4426e2ca8ac21;hp=009e2201439e06caaa834f4485ef603ffc057d73;hpb=b376c5a6db43dbeca79e41e62de10ec0c87c0099;p=vlc-remote diff --git a/accountdialog.cpp b/accountdialog.cpp index 009e220..4c8a5fa 100644 --- a/accountdialog.cpp +++ b/accountdialog.cpp @@ -1,3 +1,20 @@ +/* VLC-REMOTE for MAEMO 5 +* Copyright (C) 2010 Schutz Sacha , Dru Moore +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2, +* or (at your option) any later version, as published by the Free +* Software Foundation +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details +* +* You should have received a copy of the GNU General Public +* License along with this program; if not, write to the +* Free Software Foundation, Inc., +* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ #include "accountdialog.h" #include "ui_accountdialog.h" #include "newaccountdialog.h" @@ -6,13 +23,32 @@ #include #include #include -#include +#include + + + +QListWidgetItem asyncTestItem(const QListWidgetItem &item) +{ + + QListWidgetItem item2= item; + item2.setText("boby"); + + return item; + +} + + + + AccountDialog::AccountDialog(QWidget *parent) : QDialog(parent), ui(new Ui::AccountDialog) { ui->setupUi(this); + mFuturWatcher = new QFutureWatcher(this); + connect(mFuturWatcher,SIGNAL(resultReadyAt(int)),this,SLOT(setAsyncItem(int))); + connect(ui->addButton,SIGNAL(clicked()),this,SLOT(add())); connect(ui->editButton,SIGNAL(clicked()),this,SLOT(edit())); connect(ui->remButton,SIGNAL(clicked()),this,SLOT(rem())); @@ -35,6 +71,19 @@ void AccountDialog::add() dialog->exec(); load(); } +QString AccountDialog::currentIp() +{ + + QSettings settings; + QString useKey = settings.value("config/currentKey").toString(); + QString useIp ; + if ( !useKey.isEmpty()) + useIp = settings.value("account/"+useKey).toString(); + + else return QString(); + + return useIp; +} void AccountDialog::load() { @@ -44,9 +93,10 @@ void AccountDialog::load() ui->listWidget->clear(); // tjr effacer , sinon on rajoute QSettings settings; - settings.beginGroup("config"); - QString useKey = settings.value("currentKey").toString(); - settings.endGroup(); + + QString useKey = settings.value("config/currentKey").toString(); + + QList asycItems; settings.beginGroup("account"); foreach ( QString key, settings.allKeys()) @@ -61,42 +111,64 @@ void AccountDialog::load() item->setFont(font); } ui->listWidget->addItem(item); + asycItems.append(*item); } settings.endGroup(); + // ... create and add in the list widget + + // QFuture itemFutur = QtConcurrent::mapped(asycItems, asyncTestItem); -} + mFuturWatcher->setFuture(QtConcurrent::mapped(asycItems, asyncTestItem)); +} -void AccountDialog::asyncTestConnection() +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; - settings.beginGroup("account"); + QString host = settings.value("account/"+item.text()).toString(); - for ( int i=0; ilistWidget->count(); ++i) + if(host.contains(":")) { + QStringList hostSplit = host.split(":"); + QString ip = hostSplit.at(0); + QString port = hostSplit.at(1); + socket->connectToHost(ip,port.toInt()); + } - QListWidgetItem * item = ui->listWidget->item(i); - QString key = item->text(); - QString hostIp = settings.value(key).toString(); - qDebug()<connectToHost(hostIp, 80); + else + socket->connectToHost(host,8080); - if (socket->waitForConnected(1000)) - item->setBackgroundColor(Qt::green); - else - item->setBackgroundColor(Qt::red); + if (socket->waitForConnected(1000)) + newItem.setIcon(QIcon::fromTheme("widgets_tickmark_list")); + else + newItem.setIcon(QIcon::fromTheme("statusarea_presence_busy_error")); + return newItem; + + +} + + + +void AccountDialog::setAsyncItem(int row) // EDIT THE ROW AFTER ASYNC FUNCTION FINISHED +{ + QListWidgetItem newItem = mFuturWatcher->resultAt(row); + QListWidgetItem * item = ui->listWidget->item(row); + + item->setIcon(newItem.icon()); - } - settings.endGroup(); } + void AccountDialog::edit() { QString currentIp = ui->listWidget->currentItem()->data(Qt::UserRole).toString(); @@ -124,13 +196,10 @@ void AccountDialog::rem() void AccountDialog::use() { QString currentKey = ui->listWidget->currentItem()->text(); - QSettings settings; - settings.beginGroup("config"); - settings.setValue("currentKey", currentKey); - settings.endGroup(); - + settings.setValue("config/currentKey", currentKey); load(); + emit accept(); } void AccountDialog::enableUi()