Revert "Working on network-undo"
[dashstudio.git] / src / shell / newprojectdialog.cpp
blob4d617f0706060136a93716476f373aa8ffe1d71a
1 /***************************************************************************
2 * Copyright (C) 2007 by David Cuadrado *
3 * krawek@gmail.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #include "newprojectdialog.h"
23 #include <dgui/iconloader.h>
24 #include <dgui/osd.h>
26 #include <dcore/config.h>
28 #include "ui_newproject.h"
29 #include "ui_connect.h"
31 NewProjectDialog::NewProjectDialog(QWidget *parent)
32 : QDialog(parent), m_sceneCounter(1)
34 ui = new Ui::NewProject;
35 ui->setupUi(this);
37 ui->author->setText(tr("Anonymous"));
38 ui->sceneList->item(0)->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled);
40 ui->image->setPixmap(DGui::IconLoader::self()->load("applications-multimedia.svg").pixmap(100, 200));
43 uiNetwork = new Ui::Connect;
44 QWidget *networkPage = new QWidget;
45 uiNetwork->setupUi(networkPage);
47 uiNetwork->imageNetwork->setPixmap(DGui::IconLoader::self()->load("applications-internet.svg").pixmap(100, 100));
48 uiNetwork->port->setValue(6821);
50 ui->tabWidget->addTab(networkPage, tr("Network"));
53 ui->addScene->setIcon(DGui::IconLoader::self()->load("list-add.svg"));
54 ui->removeScene->setIcon(DGui::IconLoader::self()->load("list-remove.svg"));
55 ui->moveUpScene->setIcon(DGui::IconLoader::self()->load("go-up.svg"));
56 ui->moveDownScene->setIcon(DGui::IconLoader::self()->load("go-down.svg"));
58 connect(ui->addScene, SIGNAL(clicked()), this, SLOT(addScene()));
59 connect(ui->removeScene, SIGNAL(clicked()), this, SLOT(removeScene()));
60 connect(ui->moveUpScene, SIGNAL(clicked()), this, SLOT(moveUpScene()));
61 connect(ui->moveDownScene, SIGNAL(clicked()), this, SLOT(moveDownScene()));
63 connect(ui->useNetwork, SIGNAL(toggled(bool)), this, SLOT(enableNetwork(bool)));
66 enableNetwork(ui->useNetwork->isChecked());
68 connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(onAccepted()));
70 restoreSettings();
74 NewProjectDialog::~NewProjectDialog()
76 delete uiNetwork;
77 delete ui;
80 QString NewProjectDialog::projectName() const
82 return ui->projectName->text();
85 QString NewProjectDialog::author() const
87 return ui->author->text();
90 QString NewProjectDialog::description() const
92 return ui->description->toPlainText();
95 QStringList NewProjectDialog::scenes() const
97 QStringList scenes;
98 for(int i = 0; i < ui->sceneList->count(); i++)
100 scenes << ui->sceneList->item(i)->text();
103 return scenes;
106 int NewProjectDialog::framesPerScene() const
108 return ui->framesPerScene->value();
112 bool NewProjectDialog::useNetwork() const
114 return ui->useNetwork->isChecked();
117 QString NewProjectDialog::login() const
119 return uiNetwork->user->text();
122 QString NewProjectDialog::password() const
124 return uiNetwork->password->text();
127 QString NewProjectDialog::server() const
129 return uiNetwork->server->text();
132 int NewProjectDialog::port() const
134 return uiNetwork->port->value();
138 void NewProjectDialog::enableNetwork(bool e)
140 ui->tabWidget->setTabEnabled(2, e);
143 void NewProjectDialog::addScene()
145 m_sceneCounter++;
146 QListWidgetItem *item = new QListWidgetItem(ui->sceneList);
147 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled);
148 item->setText(tr("Scene %1").arg(m_sceneCounter));
151 void NewProjectDialog::removeScene()
153 delete ui->sceneList->takeItem(ui->sceneList->currentRow());
156 void NewProjectDialog::moveUpScene()
158 int row = ui->sceneList->currentRow();
159 if( row >= 0 )
161 QListWidgetItem *item = ui->sceneList->takeItem(row);
163 ui->sceneList->insertItem(row-1,item);
165 ui->sceneList->setCurrentItem(item);
169 void NewProjectDialog::moveDownScene()
171 int row = ui->sceneList->currentRow();
172 if( row >= 0 )
174 QListWidgetItem *item = ui->sceneList->takeItem(row);
176 ui->sceneList->insertItem(row+1,item);
177 ui->sceneList->setCurrentItem(item);
181 void NewProjectDialog::onAccepted()
183 if( ui->projectName->text().isEmpty() )
185 DGui::Osd::self()->display(tr("Please fill the project name field"), DGui::Osd::Error);
186 return;
189 if( ui->author->text().isEmpty() )
191 DGui::Osd::self()->display(tr("Please fill the author field"), DGui::Osd::Error);
192 return;
195 if( ui->useNetwork->isChecked() )
197 if( uiNetwork->user->text().isEmpty() )
199 DGui::Osd::self()->display(tr("Please fill the user field"), DGui::Osd::Error);
200 return;
203 if( uiNetwork->server->text().isEmpty() )
205 DGui::Osd::self()->display(tr("Please fill the server field"), DGui::Osd::Error);
206 return;
210 saveSettings();
212 QDialog::accept();
216 void NewProjectDialog::saveSettings()
218 DCore::Config *config = DCore::Config::self();
219 config->beginGroup("Network");
221 config->setValue("login", login());
223 if( uiNetwork->storePassword->isChecked() )
225 config->setValue("password", password());
227 else
229 config->remove("password");
232 config->setValue("server", server());
233 config->setValue("port", port());
235 config->endGroup();
238 void NewProjectDialog::restoreSettings()
240 DCore::Config *config = DCore::Config::self();
241 config->beginGroup("Network");
243 uiNetwork->user->setText(config->value("login").toString());
245 if( config->contains("password") )
247 uiNetwork->password->setText(config->value("password").toString());
248 uiNetwork->storePassword->setChecked(true);
251 uiNetwork->server->setText(config->value("server").toString());
252 uiNetwork->port->setValue(config->value("port").toInt());
254 config->endGroup();