Refactored PlayList handling to recursive function.
[vlc-remote] / newaccountdialog.cpp
index 4f9c39e..8be1fbc 100644 (file)
@@ -1,3 +1,20 @@
+/*   VLC-REMOTE for MAEMO 5
+*   Copyright (C) 2010 Schutz Sacha <istdasklar@gmail.com>, Dru Moore <usr@dru-id.co.uk>, Yann Nave <yannux@onbebop.net>
+*   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 "newaccountdialog.h"
 #include <QFormLayout>
 #include <QDebug>
@@ -8,8 +25,11 @@ NewAccountDialog::NewAccountDialog(QWidget *parent)
 {
     this->setWindowTitle(tr("Add account"));
 
-    mMyKeyLineEdit = new QLineEdit;
-    mMyIpLineEdit = new QLineEdit;
+    mKeyLineEdit = new QLineEdit;
+    mIpLineEdit = new QLineEdit;
+    mPortLineEdit = new QLineEdit;
+    mPortLineEdit->setText("8080");
+    mPortLineEdit->setReadOnly(false);
 
     mButtonBox = new QDialogButtonBox;
     mButtonBox->addButton(QDialogButtonBox::Save);
@@ -20,8 +40,9 @@ NewAccountDialog::NewAccountDialog(QWidget *parent)
 
     QFormLayout *layout = new QFormLayout;
     layout->expandingDirections();
-    layout->addRow(tr("Name:"), mMyKeyLineEdit);
-    layout->addRow(tr("Ip:"), mMyIpLineEdit);
+    layout->addRow(tr("Name:"), mKeyLineEdit);
+    layout->addRow(tr("Ip:"), mIpLineEdit);
+    layout->addRow(tr("Port:"), mPortLineEdit);
     layout->addWidget(mButtonBox);
 
     setLayout(layout);
@@ -29,8 +50,9 @@ NewAccountDialog::NewAccountDialog(QWidget *parent)
 
 void NewAccountDialog::save()
 {
-    QString myKey = mMyKeyLineEdit->text();
-    QString myIp = mMyIpLineEdit->text();
+    QString myKey = mKeyLineEdit->text();
+    QString myIp = mIpLineEdit->text();
+    QString myPort = mPortLineEdit->text();
 
     QSettings settings;
     settings.beginGroup("account");
@@ -39,7 +61,10 @@ void NewAccountDialog::save()
     }
 
     if (!myIp.isEmpty() && !myKey.isEmpty()) {
-        settings.setValue(myKey, myIp);
+        if (myPort.isEmpty()) {
+            myPort = "8080";
+        }
+        settings.setValue(myKey, myIp+":"+myPort);
         // Rajouter des tests pour vĂ©rifier qu'on est sur Maemo
         //QMaemo5InformationBox::information(this, tr("Account saved"), QMaemo5InformationBox::DefaultTimeout);
     }
@@ -52,11 +77,20 @@ void NewAccountDialog::edit(QString &key, QString &ip)
 {
     this->setWindowTitle(tr("Edit account"));
 
+    QSettings settings;
+    settings.beginGroup("account");
+    QString value = settings.value(key).toString();
+    settings.endGroup();
+
+    QStringList values = value.split(":");
+
     mEditKey = key;
-    mEditIp = ip;
+    mEditIp = values.first();
+    mEditPort = values.last();
 
-    mMyKeyLineEdit->setText(key);
-    mMyKeyLineEdit->setDisabled(true);
-    mMyIpLineEdit->setText(ip);
+    mKeyLineEdit->setText(mEditKey);
+    mKeyLineEdit->setDisabled(true);
+    mIpLineEdit->setText(mEditIp);
+    mPortLineEdit->setText(mEditPort);
 }