summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Bieber <robby@bieberphoto.com>2010-06-15 20:31:28 +0000
committerRobert Bieber <robby@bieberphoto.com>2010-06-15 20:31:28 +0000
commit0c26a790ee2a5702a8c87a9cd1af666d17afcc05 (patch)
treea1c612163c1d2b9c34806ea40e1c6a5bc17ce4e5
parent738d83c59b2adc480751e0e70ccd75adc3d5903d (diff)
downloadrockbox-0c26a790ee2a5702a8c87a9cd1af666d17afcc05.tar.gz
rockbox-0c26a790ee2a5702a8c87a9cd1af666d17afcc05.zip
Theme Editor: Added copyright headers to ConfigDocument files, continued work on configuration editing
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26862 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--utils/themeeditor/configdocument.cpp98
-rw-r--r--utils/themeeditor/configdocument.h21
2 files changed, 118 insertions, 1 deletions
diff --git a/utils/themeeditor/configdocument.cpp b/utils/themeeditor/configdocument.cpp
index 95daec0b60..c212cc52ce 100644
--- a/utils/themeeditor/configdocument.cpp
+++ b/utils/themeeditor/configdocument.cpp
@@ -1,6 +1,33 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2010 Robert Bieber
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include "projectmodel.h"
1#include "configdocument.h" 23#include "configdocument.h"
2#include "ui_configdocument.h" 24#include "ui_configdocument.h"
3 25
26#include <QMessageBox>
27#include <QFile>
28#include <QSettings>
29#include <QFileDialog>
30
4ConfigDocument::ConfigDocument(QMap<QString, QString>& settings, QString file, 31ConfigDocument::ConfigDocument(QMap<QString, QString>& settings, QString file,
5 QWidget *parent) 32 QWidget *parent)
6 : TabContent(parent), 33 : TabContent(parent),
@@ -44,17 +71,86 @@ QString ConfigDocument::title() const
44 71
45void ConfigDocument::save() 72void ConfigDocument::save()
46{ 73{
74 QFile fout(filePath);
75
76 if(!fout.exists())
77 {
78 saveAs();
79 return;
80 }
81
82 fout.open(QFile::WriteOnly);
83 fout.write(toPlainText().toAscii());
84 fout.close();
85
86 saved = toPlainText();
87 emit titleChanged(title());
47 88
48} 89}
49 90
50void ConfigDocument::saveAs() 91void ConfigDocument::saveAs()
51{ 92{
93 /* Determining the directory to open */
94 QString directory = filePath;
95
96 QSettings settings;
97 settings.beginGroup("ProjectModel");
98 if(directory == "")
99 directory = settings.value("defaultDirectory", "").toString();
100
101 filePath = QFileDialog::getSaveFileName(this, tr("Save Document"),
102 directory,
103 ProjectModel::fileFilter());
104 directory = filePath;
105 if(filePath == "")
106 return;
107
108 directory.chop(filePath.length() - filePath.lastIndexOf('/') - 1);
109 settings.setValue("defaultDirectory", directory);
110 settings.endGroup();
111
112 QFile fout(filePath);
113 fout.open(QFile::WriteOnly);
114 fout.write(toPlainText().toAscii());
115 fout.close();
116
117 saved = toPlainText();
118 emit titleChanged(title());
52 119
53} 120}
54 121
55bool ConfigDocument::requestClose() 122bool ConfigDocument::requestClose()
56{ 123{
57 124 if(toPlainText() != saved)
125 {
126 /* Spawning the "Are you sure?" dialog */
127 QMessageBox confirm(this);
128 confirm.setWindowTitle(tr("Confirm Close"));
129 confirm.setText(title() + tr(" has been modified."));
130 confirm.setInformativeText(tr("Do you want to save your changes?"));
131 confirm.setStandardButtons(QMessageBox::Save | QMessageBox::Discard
132 | QMessageBox::Cancel);
133 confirm.setDefaultButton(QMessageBox::Save);
134 int confirmation = confirm.exec();
135
136 switch(confirmation)
137 {
138 case QMessageBox::Save:
139 save();
140 /* After calling save, make sure the user actually went through */
141 if(toPlainText() != saved)
142 return false;
143 else
144 return true;
145
146 case QMessageBox::Discard:
147 return true;
148
149 case QMessageBox::Cancel:
150 return false;
151 }
152 }
153 return false;
58} 154}
59 155
60QString ConfigDocument::toPlainText() const 156QString ConfigDocument::toPlainText() const
diff --git a/utils/themeeditor/configdocument.h b/utils/themeeditor/configdocument.h
index 2f4c2501a1..9aa1a63da5 100644
--- a/utils/themeeditor/configdocument.h
+++ b/utils/themeeditor/configdocument.h
@@ -1,3 +1,24 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2010 Robert Bieber
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
1#ifndef CONFIGDOCUMENT_H 22#ifndef CONFIGDOCUMENT_H
2#define CONFIGDOCUMENT_H 23#define CONFIGDOCUMENT_H
3 24