Add mce-dev into control build templates for dbus support
[vlc-remote] / src / 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 "appsettings.h"
23 //#include <QMaemo5InformationBox>
24
25 NewAccountDialog::NewAccountDialog(QWidget *parent)
26 {
27     Q_UNUSED(parent);
28     this->setWindowTitle(tr("Add account"));
29
30     mKeyLineEdit = new QLineEdit;
31     mIpLineEdit = new QLineEdit;
32     mPortLineEdit = new QLineEdit;
33     mPortLineEdit->setText("8080");
34     mPortLineEdit->setReadOnly(false);
35
36     mButtonBox = new QDialogButtonBox;
37     mButtonBox->addButton(QDialogButtonBox::Save);
38     mButtonBox->addButton(QDialogButtonBox::Cancel);
39
40     connect(mButtonBox, SIGNAL(accepted()), this, SLOT(save()));
41     connect(mButtonBox, SIGNAL(rejected()), this, SLOT(reject()));
42
43     QFormLayout *layout = new QFormLayout;
44     layout->expandingDirections();
45     layout->addRow(tr("Name:"), mKeyLineEdit);
46     layout->addRow(tr("Ip:"), mIpLineEdit);
47     layout->addRow(tr("Port:"), mPortLineEdit);
48     layout->addWidget(mButtonBox);
49
50     setLayout(layout);
51 }
52
53 void NewAccountDialog::save()
54 {
55     QString myKey = mKeyLineEdit->text();
56     QString myIp = mIpLineEdit->text();
57     QString myPort = mPortLineEdit->text();
58
59     /// TODO create account through appsettings
60     QSettings settings;
61     settings.beginGroup("account");
62     if (!mEditKey.isEmpty()) {
63         settings.remove(mEditKey);
64     }
65
66     if (!myIp.isEmpty() && !myKey.isEmpty()) {
67         if (myPort.isEmpty()) {
68             myPort = "8080";
69         }
70         settings.setValue(myKey, myIp+":"+myPort);
71         // Rajouter des tests pour vĂ©rifier qu'on est sur Maemo
72         //QMaemo5InformationBox::information(this, tr("Account saved"), QMaemo5InformationBox::DefaultTimeout);
73     }
74     settings.endGroup();
75
76     emit accept();
77 }
78
79 void NewAccountDialog::edit(QString &key, QString &ip)
80 {
81     Q_UNUSED(ip);
82     this->setWindowTitle(tr("Edit account"));
83
84     QSettings settings;
85     settings.beginGroup("account");
86     QString value = settings.value(key).toString();
87     settings.endGroup();
88
89     QStringList values = value.split(":");
90
91     mEditKey = key;
92     mEditIp = values.first();
93     mEditPort = values.last();
94
95     mKeyLineEdit->setText(mEditKey);
96     mKeyLineEdit->setDisabled(true);
97     mIpLineEdit->setText(mEditIp);
98     mPortLineEdit->setText(mEditPort);
99 }
100