From c272144867f94dc7e99f8333bec5dd052878ecd8 Mon Sep 17 00:00:00 2001 From: Robert Bieber Date: Thu, 15 Jul 2010 21:39:09 +0000 Subject: Theme Editor: Added New Project feature git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27439 a1c6a512-1295-4272-9138-f99709370657 --- utils/themeeditor/gui/editorwindow.cpp | 192 ++++++++++++++++++++------ utils/themeeditor/gui/editorwindow.h | 5 + utils/themeeditor/gui/editorwindow.ui | 9 ++ utils/themeeditor/gui/newprojectdialog.cpp | 105 +++++++++++++++ utils/themeeditor/gui/newprojectdialog.h | 95 +++++++++++++ utils/themeeditor/gui/newprojectdialog.ui | 209 +++++++++++++++++++++++++++++ utils/themeeditor/themeeditor.pro | 9 +- 7 files changed, 581 insertions(+), 43 deletions(-) create mode 100644 utils/themeeditor/gui/newprojectdialog.cpp create mode 100644 utils/themeeditor/gui/newprojectdialog.h create mode 100644 utils/themeeditor/gui/newprojectdialog.ui (limited to 'utils/themeeditor') diff --git a/utils/themeeditor/gui/editorwindow.cpp b/utils/themeeditor/gui/editorwindow.cpp index 247109cc19..043c08badd 100644 --- a/utils/themeeditor/gui/editorwindow.cpp +++ b/utils/themeeditor/gui/editorwindow.cpp @@ -24,12 +24,16 @@ #include "ui_editorwindow.h" #include "rbfontcache.h" #include "rbtextcache.h" +#include "newprojectdialog.h" #include #include #include #include +#include #include +#include +#include EditorWindow::EditorWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::EditorWindow), parseTreeSelection(0) @@ -200,6 +204,8 @@ void EditorWindow::setupMenus() /* Connecting the document management actions */ QObject::connect(ui->actionNew_Document, SIGNAL(triggered()), this, SLOT(newTab())); + QObject::connect(ui->actionNew_Project, SIGNAL(triggered()), + this, SLOT(newProject())); QObject::connect(ui->actionToolbarNew, SIGNAL(triggered()), this, SLOT(newTab())); @@ -261,6 +267,93 @@ void EditorWindow::newTab() ui->editorTabs->setCurrentWidget(doc); } +void EditorWindow::newProject() +{ + NewProjectDialog dialog(this); + if(dialog.exec() == QDialog::Rejected) + return; + + /* Assembling the new project if the dialog was accepted */ + NewProjectDialog::NewProjectInfo info = dialog.results(); + + QDir path(info.path); + if(!path.exists()) + { + QMessageBox::warning(this, tr("Error Creating Project"), tr("Error:" + " Project directory does not exist")); + return; + } + + if(path.exists(info.name)) + { + QMessageBox::warning(this, tr("Error Creating Project"), tr("Error:" + " Project directory already exists")); + return; + } + + if(!path.mkdir(info.name)) + { + QMessageBox::warning(this, tr("Error Creating Project"), tr("Error:" + " Project directory not writeable")); + return; + } + + path.cd(info.name); + + /* Making standard directories */ + path.mkdir("fonts"); + path.mkdir("icons"); + path.mkdir("backdrops"); + + /* Adding the desired wps documents */ + path.mkdir("wps"); + path.cd("wps"); + + if(info.sbs) + createFile(path.filePath(info.name + ".sbs"), tr("# SBS Document\n")); + if(info.wps) + createFile(path.filePath(info.name + ".wps"), tr("# WPS Document\n")); + if(info.fms) + createFile(path.filePath(info.name + ".fms"), tr("# FMS Document\n")); + if(info.rsbs) + createFile(path.filePath(info.name + ".rsbs"), tr("# RSBS Document\n")); + if(info.rwps) + createFile(path.filePath(info.name + ".rwps"), tr("# RWPS Document\n")); + if(info.rfms) + createFile(path.filePath(info.name + ".rfms"), tr("# RFMS Document\n")); + + path.mkdir(info.name); + + path.cdUp(); + + /* Adding the config file */ + path.mkdir("themes"); + path.cd("themes"); + + /* Generating the config file */ + QString config = tr("# Config file for ") + info.name + "\n"; + QString wpsBase = "/.rockbox/wps/"; + if(info.sbs) + config.append("sbs: " + wpsBase + info.name + ".sbs\n"); + if(info.wps) + config.append("wps: " + wpsBase + info.name + ".wps\n"); + if(info.fms) + config.append("fms: " + wpsBase + info.name + ".fms\n"); + if(info.rsbs) + config.append("rsbs: " + wpsBase + info.name + ".rsbs\n"); + if(info.rwps) + config.append("rwps: " + wpsBase + info.name + ".rwps\n"); + if(info.rfms) + config.append("rfms: " + wpsBase + info.name + ".rfms\n"); + + + createFile(path.filePath(info.name + ".cfg"), + config); + + /* Opening the new project */ + loadProjectFile(path.filePath(info.name + ".cfg")); +} + void EditorWindow::shiftTab(int index) { TabContent* widget = dynamic_cast @@ -424,47 +517,8 @@ void EditorWindow::openProject() fileName = QFileDialog::getOpenFileName(this, tr("Open Project"), directory, ProjectModel::fileFilter()); - if(QFile::exists(fileName)) - { - - if(project) - project->deleteLater(); - - ui->actionClose_Project->setEnabled(true); - - project = new ProjectModel(fileName, this); - ui->projectTree->setModel(project); - - if(project->getSetting("#screenwidth") != "") - deviceConfig->setData("screenwidth", - project->getSetting("#screenwidth")); - if(project->getSetting("#screenheight") != "") - deviceConfig->setData("screenheight", - project->getSetting("#screenheight")); - - QObject::connect(ui->projectTree, SIGNAL(activated(QModelIndex)), - project, SLOT(activated(QModelIndex))); - - fileName.chop(fileName.length() - fileName.lastIndexOf('/') - 1); - settings.setValue("defaultDirectory", fileName); - - for(int i = 0; i < ui->editorTabs->count(); i++) - { - TabContent* doc = dynamic_cast - (ui->editorTabs->widget(i)); - if(doc->type() == TabContent::Skin) - { - dynamic_cast(doc)->setProject(project); - if(i == ui->editorTabs->currentIndex()) - { - viewer->setScene(dynamic_cast(doc)->scene()); - } - } - } - - } - settings.endGroup(); + loadProjectFile(fileName); } @@ -657,3 +711,61 @@ void EditorWindow::sizeColumns() ui->parseTree->resizeColumnToContents(ParseTreeModel::typeColumn); ui->parseTree->resizeColumnToContents(ParseTreeModel::valueColumn); } + +void EditorWindow::loadProjectFile(QString fileName) +{ + QSettings settings; + settings.beginGroup("ProjectModel"); + + if(QFile::exists(fileName)) + { + if(project) + project->deleteLater(); + + ui->actionClose_Project->setEnabled(true); + + project = new ProjectModel(fileName, this); + ui->projectTree->setModel(project); + + if(project->getSetting("#screenwidth") != "") + deviceConfig->setData("screenwidth", + project->getSetting("#screenwidth")); + if(project->getSetting("#screenheight") != "") + deviceConfig->setData("screenheight", + project->getSetting("#screenheight")); + + QObject::connect(ui->projectTree, SIGNAL(activated(QModelIndex)), + project, SLOT(activated(QModelIndex))); + + fileName.chop(fileName.length() - fileName.lastIndexOf('/') - 1); + settings.setValue("defaultDirectory", fileName); + + for(int i = 0; i < ui->editorTabs->count(); i++) + { + TabContent* doc = dynamic_cast + (ui->editorTabs->widget(i)); + if(doc->type() == TabContent::Skin) + { + dynamic_cast(doc)->setProject(project); + if(i == ui->editorTabs->currentIndex()) + { + viewer->setScene(dynamic_cast(doc)->scene()); + } + } + } + + } + + settings.endGroup(); + +} + +void EditorWindow::createFile(QString filename, QString contents) +{ + QFile fout(filename); + fout.open(QFile::WriteOnly); + + fout.write(contents.toAscii()); + + fout.close(); +} diff --git a/utils/themeeditor/gui/editorwindow.h b/utils/themeeditor/gui/editorwindow.h index 0178f602b2..5bfa795714 100644 --- a/utils/themeeditor/gui/editorwindow.h +++ b/utils/themeeditor/gui/editorwindow.h @@ -64,6 +64,7 @@ public slots: private slots: void showPanel(); void newTab(); + void newProject(); void shiftTab(int index); bool closeTab(int index); void closeCurrent(); @@ -88,11 +89,15 @@ private: void saveSettings(); void setupUI(); void setupMenus(); + void addTab(TabContent* doc); void expandLine(ParseTreeModel* model, QModelIndex parent, int line, bool highlight); void sizeColumns(); + void loadProjectFile(QString fileName); + static void createFile(QString filename, QString contents); + Ui::EditorWindow *ui; PreferencesDialog* prefs; QLabel* parseStatus; diff --git a/utils/themeeditor/gui/editorwindow.ui b/utils/themeeditor/gui/editorwindow.ui index ab8dc61896..a7246b9def 100644 --- a/utils/themeeditor/gui/editorwindow.ui +++ b/utils/themeeditor/gui/editorwindow.ui @@ -48,6 +48,7 @@ &File + @@ -386,6 +387,14 @@ Ctrl+Shift+W + + + N&ew Project + + + Ctrl+Shift+N + + projectTree diff --git a/utils/themeeditor/gui/newprojectdialog.cpp b/utils/themeeditor/gui/newprojectdialog.cpp new file mode 100644 index 0000000000..50a8bc4631 --- /dev/null +++ b/utils/themeeditor/gui/newprojectdialog.cpp @@ -0,0 +1,105 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2010 Robert Bieber + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include "newprojectdialog.h" +#include "ui_newprojectdialog.h" + +#include +#include +#include + +NewProjectDialog::NewProjectDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::NewProjectDialog) +{ + ui->setupUi(this); + + /* Getting the default directory from the application settings */ + QSettings settings; + settings.beginGroup("NewProjectDialog"); + + ui->locationBox->setText(settings.value("defaultDir", + QDir::home().absolutePath()) + .toString()); + + settings.endGroup(); + + /* Connecting the browse button */ + QObject::connect(ui->browseButton, SIGNAL(clicked()), + this, SLOT(browse())); +} + +NewProjectDialog::~NewProjectDialog() +{ + delete ui; +} + +void NewProjectDialog::accept() +{ + status.name = ui->nameBox->text(); + status.path = ui->locationBox->text(); + status.sbs = ui->sbsBox->isChecked(); + status.wps = ui->wpsBox->isChecked(); + status.fms = ui->fmsBox->isChecked(); + status.rsbs = ui->rsbsBox->isChecked(); + status.rwps = ui->rwpsBox->isChecked(); + status.rfms = ui->rfmsBox->isChecked(); + + QSettings settings; + settings.beginGroup("NewProjectDialog"); + + settings.setValue("defaultDir", ui->locationBox->text()); + + settings.endGroup(); + + QDialog::accept(); +} + +void NewProjectDialog::reject() +{ + ui->nameBox->setText(status.name); + ui->locationBox->setText(status.path); + ui->sbsBox->setChecked(status.sbs); + ui->wpsBox->setChecked(status.wps); + ui->fmsBox->setChecked(status.fms); + ui->rsbsBox->setChecked(status.rsbs); + ui->rwpsBox->setChecked(status.rwps); + ui->rfmsBox->setChecked(status.rfms); + + QSettings settings; + settings.beginGroup("NewProjectDialog"); + + ui->locationBox->setText(settings.value("defaultDir", + QDir::home().absolutePath()) + .toString()); + + settings.endGroup(); + + QDialog::reject(); +} + +void NewProjectDialog::browse() +{ + QString path; + path = QFileDialog::getExistingDirectory(this, "New Project Location", + ui->locationBox->text()); + ui->locationBox->setText(path); +} diff --git a/utils/themeeditor/gui/newprojectdialog.h b/utils/themeeditor/gui/newprojectdialog.h new file mode 100644 index 0000000000..c59607c53f --- /dev/null +++ b/utils/themeeditor/gui/newprojectdialog.h @@ -0,0 +1,95 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2010 Robert Bieber + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#ifndef NEWPROJECTDIALOG_H +#define NEWPROJECTDIALOG_H + +#include + +namespace Ui { + class NewProjectDialog; +} + +class NewProjectDialog : public QDialog { + Q_OBJECT +public: + struct NewProjectInfo + { + QString name; + QString path; + bool sbs; + bool wps; + bool fms; + bool rsbs; + bool rwps; + bool rfms; + + NewProjectInfo() + { + name = ""; + path = ""; + sbs = true; + wps = true; + fms = false; + rsbs = false; + rwps = false; + rfms = false; + } + + NewProjectInfo(const NewProjectInfo& other) + { + operator=(other); + } + + const NewProjectInfo& operator=(const NewProjectInfo& other) + { + name = other.name; + path = other.path; + sbs = other.sbs; + wps = other.wps; + fms = other.fms; + rsbs = other.rsbs; + rwps = other.rwps; + rfms = other.rfms; + + return *this; + } + }; + + NewProjectDialog(QWidget *parent = 0); + virtual ~NewProjectDialog(); + + NewProjectInfo results(){ return status; } + +public slots: + void accept(); + void reject(); + +private slots: + void browse(); + +private: + Ui::NewProjectDialog *ui; + + NewProjectInfo status; +}; + +#endif // NEWPROJECTDIALOG_H diff --git a/utils/themeeditor/gui/newprojectdialog.ui b/utils/themeeditor/gui/newprojectdialog.ui new file mode 100644 index 0000000000..f6e2dcc139 --- /dev/null +++ b/utils/themeeditor/gui/newprojectdialog.ui @@ -0,0 +1,209 @@ + + + NewProjectDialog + + + + 0 + 0 + 400 + 275 + + + + New Project + + + + :/resources/windowicon.png:/resources/windowicon.png + + + + + + + + Name: + + + nameBox + + + + + + + + + + Create In: + + + locationBox + + + + + + + + + + + + Browse... + + + + + + + + + Target: + + + comboBox + + + + + + + + Not Yet Available + + + + + + + + Add Documents + + + false + + + false + + + + QFormLayout::AllNonFixedFieldsGrow + + + + + SBS + + + true + + + + + + + RSBS + + + + + + + WPS + + + true + + + + + + + RWPS + + + + + + + FMS + + + + + + + RFMS + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + + + buttonBox + accepted() + NewProjectDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + NewProjectDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/utils/themeeditor/themeeditor.pro b/utils/themeeditor/themeeditor.pro index 5d77d562a6..75bad8373b 100644 --- a/utils/themeeditor/themeeditor.pro +++ b/utils/themeeditor/themeeditor.pro @@ -54,7 +54,8 @@ HEADERS += models/parsetreemodel.h \ graphics/rbfontcache.h \ graphics/rbtextcache.h \ gui/skintimer.h \ - graphics/rbtoucharea.h + graphics/rbtoucharea.h \ + gui/newprojectdialog.h SOURCES += main.cpp \ models/parsetreemodel.cpp \ models/parsetreenode.cpp \ @@ -79,7 +80,8 @@ SOURCES += main.cpp \ graphics/rbfontcache.cpp \ graphics/rbtextcache.cpp \ gui/skintimer.cpp \ - graphics/rbtoucharea.cpp + graphics/rbtoucharea.cpp \ + gui/newprojectdialog.cpp OTHER_FILES += README \ resources/windowicon.png \ resources/appicon.xcf \ @@ -106,7 +108,8 @@ FORMS += gui/editorwindow.ui \ gui/configdocument.ui \ gui/skinviewer.ui \ gui/findreplacedialog.ui \ - gui/skintimer.ui + gui/skintimer.ui \ + gui/newprojectdialog.ui RESOURCES += resources.qrc win32:RC_FILE = themeeditor.rc macx { -- cgit v1.2.3