Updated the licenses to include my details
[vlc-remote] / newaccountdialog.cpp
1 /*   VLC-REMOTE for MAEMO 5
2 *   Copyright (C) 2010 Schutz Sacha <istdasklar@gmail.com>, Dru Moore <usr@dru-id.co.uk>, Yann Nave <yannux@onbebop.net>
3 *   This program is free software; you can redistribute it and/or modify
4 *   it under the terms of the GNU General Public License version 2,
5 *   or (at your option) any later version, as published by the Free
6 *   Software Foundation
7 *
8 *   This program is distributed in the hope that it will be useful,
9 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
10 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 *   GNU General Public License for more details
12 *
13 *   You should have received a copy of the GNU General Public
14 *   License along with this program; if not, write to the
15 *   Free Software Foundation, Inc.,
16 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17 */
18 #include "newaccountdialog.h"
19 #include <QFormLayout>
20 #include <QDebug>
21 #include <QSettings>
22 //#include <QMaemo5InformationBox>
23
24 NewAccountDialog::NewAccountDialog(QWidget *parent)
25 {
26     this->setWindowTitle(tr("Add account"));
27
28     mKeyLineEdit = new QLineEdit;
29     mIpLineEdit = new QLineEdit;
30     mPortLineEdit = new QLineEdit;
31     mPortLineEdit->setText("8080");
32     mPortLineEdit->setReadOnly(false);
33
34     mButtonBox = new QDialogButtonBox;
35     mButtonBox->addButton(QDialogButtonBox::Save);
36     mButtonBox->addButton(QDialogButtonBox::Cancel);
37
38     connect(mButtonBox, SIGNAL(accepted()), this, SLOT(save()));
39     connect(mButtonBox, SIGNAL(rejected()), this, SLOT(reject()));
40
41     QFormLayout *layout = new QFormLayout;
42     layout->expandingDirections();
43     layout->addRow(tr("Name:"), mKeyLineEdit);
44     layout->addRow(tr("Ip:"), mIpLineEdit);
45     layout->addRow(tr("Port:"), mPortLineEdit);
46     layout->addWidget(mButtonBox);
47
48     setLayout(layout);
49 }
50
51 void NewAccountDialog::save()
52 {
53     QString myKey = mKeyLineEdit->text();
54     QString myIp = mIpLineEdit->text();
55     QString myPort = mPortLineEdit->text();
56
57     QSettings settings;
58     settings.beginGroup("account");
59     if (!mEditKey.isEmpty()) {
60         settings.remove(mEditKey);
61     }
62
63     if (!myIp.isEmpty() && !myKey.isEmpty()) {
64         if (myPort.isEmpty()) {
65             myPort = "8080";
66         }
67         settings.setValue(myKey, myIp+":"+myPort);
68         // Rajouter des tests pour vĂ©rifier qu'on est sur Maemo
69         //QMaemo5InformationBox::information(this, tr("Account saved"), QMaemo5InformationBox::DefaultTimeout);
70     }
71     settings.endGroup();
72
73     emit accept();
74 }
75
76 void NewAccountDialog::edit(QString &key, QString &ip)
77 {
78     this->setWindowTitle(tr("Edit account"));
79
80     QSettings settings;
81     settings.beginGroup("account");
82     QString value = settings.value(key).toString();
83     settings.endGroup();
84
85     QStringList values = value.split(":");
86
87     mEditKey = key;
88     mEditIp = values.first();
89     mEditPort = values.last();
90
91     mKeyLineEdit->setText(mEditKey);
92     mKeyLineEdit->setDisabled(true);
93     mIpLineEdit->setText(mEditIp);
94     mPortLineEdit->setText(mEditPort);
95 }
96