1 /***************************************************************************
2 * Copyright (C) 2007 by David Cuadrado *
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. *
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. *
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>
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
;
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()));
74 NewProjectDialog::~NewProjectDialog()
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
98 for(int i
= 0; i
< ui
->sceneList
->count(); i
++)
100 scenes
<< ui
->sceneList
->item(i
)->text();
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()
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();
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();
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
);
189 if( ui
->author
->text().isEmpty() )
191 DGui::Osd::self()->display(tr("Please fill the author field"), DGui::Osd::Error
);
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
);
203 if( uiNetwork
->server
->text().isEmpty() )
205 DGui::Osd::self()->display(tr("Please fill the server field"), DGui::Osd::Error
);
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());
229 config
->remove("password");
232 config
->setValue("server", server());
233 config
->setValue("port", port());
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());