diff options
author | Robert Bieber <robby@bieberphoto.com> | 2010-07-24 08:10:44 +0000 |
---|---|---|
committer | Robert Bieber <robby@bieberphoto.com> | 2010-07-24 08:10:44 +0000 |
commit | 8556ad81bd65cfbf431634e4cee7a59d1d9abe1d (patch) | |
tree | c7a1975bdd9e5f24dc045581eadaa83e4191358a /utils/themeeditor | |
parent | 97b9a4bad8169541d77cb4d5daf69a3290602d42 (diff) |
Theme Editor: Implemented zip file project export
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27537 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'utils/themeeditor')
-rw-r--r-- | utils/themeeditor/gui/projectexporter.cpp | 62 | ||||
-rw-r--r-- | utils/themeeditor/gui/projectexporter.h | 2 |
2 files changed, 58 insertions, 6 deletions
diff --git a/utils/themeeditor/gui/projectexporter.cpp b/utils/themeeditor/gui/projectexporter.cpp index b9718d11c5..dec1b13d3e 100644 --- a/utils/themeeditor/gui/projectexporter.cpp +++ b/utils/themeeditor/gui/projectexporter.cpp @@ -22,6 +22,11 @@ #include "projectexporter.h" #include "ui_projectexporter.h" +#include "quazipfile.h" + +#include <QTextStream> +#include <QDir> + ProjectExporter::ProjectExporter(QString path, ProjectModel* project, QWidget *parent) :QDialog(parent), @@ -34,11 +39,20 @@ ProjectExporter::ProjectExporter(QString path, ProjectModel* project, if(zipFile.open(QuaZip::mdCreate)) { - writeZip(project); + html += tr("<span style=\"color:orange\">Resource Check: " + "Not implemented yet</span><br>"); + ui->statusBox->document()->setHtml(html); + writeZip(project->getSetting("themebase", "")); + zipFile.close(); + + html += tr("<span style=\"color:green\">Project exported " + "successfully</span><br>"); + ui->statusBox->document()->setHtml(html); } else { - html += tr("<span style = \"color:red\">Error opening zip file</span><br>"); + html += tr("<span style = \"color:red\">" + "Error opening zip file</span><br>"); ui->statusBox->document()->setHtml(html); } } @@ -72,8 +86,46 @@ void ProjectExporter::close() hide(); } -void ProjectExporter::writeZip(ProjectModel *project) +void ProjectExporter::writeZip(QString path, QString base) { - (void)project; - zipFile.close(); + if(base == "") + base = path; + if(path == "") + { + html += tr("<span style = \"color:red\">" + "Error: Couldn't locate project directory</span><br>"); + ui->statusBox->document()->setHtml(html); + return; + } + + QDir dir(path); + + /* First adding any files in the directory */ + QFileInfoList files = dir.entryInfoList(QDir::Files); + for(int i = 0; i < files.count(); i++) + { + QFileInfo current = files[i]; + + QString newPath = current.absoluteFilePath().replace(base, "/.rockbox"); + + QuaZipFile fout(&zipFile); + QFile fin(current.absoluteFilePath()); + + fin.open(QFile::ReadOnly | QFile::Text); + fout.open(QIODevice::WriteOnly, + QuaZipNewInfo(newPath, current.absoluteFilePath())); + + fout.write(fin.readAll()); + + fin.close(); + fout.close(); + } + + /* Then recursively adding any directories */ + QFileInfoList dirs = dir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot); + for(int i = 0; i < dirs.count(); i++) + { + QFileInfo current = dirs[i]; + writeZip(current.absoluteFilePath(), base); + } } diff --git a/utils/themeeditor/gui/projectexporter.h b/utils/themeeditor/gui/projectexporter.h index 4012d384ac..d743172dd9 100644 --- a/utils/themeeditor/gui/projectexporter.h +++ b/utils/themeeditor/gui/projectexporter.h @@ -48,7 +48,7 @@ private slots: void close(); private: - void writeZip(ProjectModel* project); + void writeZip(QString path, QString base = ""); Ui::ProjectExporter *ui; QuaZip zipFile; |