summaryrefslogtreecommitdiffstats
path: root/utils/themeeditor/gui/projectexporter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'utils/themeeditor/gui/projectexporter.cpp')
-rw-r--r--utils/themeeditor/gui/projectexporter.cpp193
1 files changed, 181 insertions, 12 deletions
diff --git a/utils/themeeditor/gui/projectexporter.cpp b/utils/themeeditor/gui/projectexporter.cpp
index dec1b13d3e..b73e4d312a 100644
--- a/utils/themeeditor/gui/projectexporter.cpp
+++ b/utils/themeeditor/gui/projectexporter.cpp
@@ -22,10 +22,15 @@
#include "projectexporter.h"
#include "ui_projectexporter.h"
+#include "tag_table.h"
+#include "skin_parser.h"
+
#include "quazipfile.h"
#include <QTextStream>
#include <QDir>
+#include <QSettings>
+#include <QDebug>
ProjectExporter::ProjectExporter(QString path, ProjectModel* project,
QWidget *parent)
@@ -39,21 +44,16 @@ ProjectExporter::ProjectExporter(QString path, ProjectModel* project,
if(zipFile.open(QuaZip::mdCreate))
{
- html += tr("<span style=\"color:orange\">Resource Check: "
- "Not implemented yet</span><br>");
- ui->statusBox->document()->setHtml(html);
+
+ checkRes(project);
writeZip(project->getSetting("themebase", ""));
zipFile.close();
- html += tr("<span style=\"color:green\">Project exported "
- "successfully</span><br>");
- ui->statusBox->document()->setHtml(html);
+ addSuccess(tr("Project exported successfully"));
}
else
{
- html += tr("<span style = \"color:red\">"
- "Error opening zip file</span><br>");
- ui->statusBox->document()->setHtml(html);
+ addError(tr("Couldn't open zip file"));
}
}
@@ -92,9 +92,7 @@ void ProjectExporter::writeZip(QString path, QString base)
base = path;
if(path == "")
{
- html += tr("<span style = \"color:red\">"
- "Error: Couldn't locate project directory</span><br>");
- ui->statusBox->document()->setHtml(html);
+ addError(tr("Couldn't locate project directory"));
return;
}
@@ -129,3 +127,174 @@ void ProjectExporter::writeZip(QString path, QString base)
writeZip(current.absoluteFilePath(), base);
}
}
+
+void ProjectExporter::checkRes(ProjectModel *project)
+{
+ QMap<QString, QString> settings = project->getSettings();
+ QMap<QString, QString>::iterator i;
+
+ for(i = settings.begin(); i != settings.end(); i++)
+ {
+ if(i.key() == "wps" || i.key() == "rwps" || i.key() == "sbs"
+ || i.key() == "rsbs" || i.key() == "fms" || i.key() == "rfms")
+ {
+ checkWPS(project, i.value());
+ }
+ else if(i.value().contains("/.rockbox"))
+ {
+ QString absPath = i.value().replace("/.rockbox",
+ settings.value("themebase"));
+ if(QFile::exists(absPath))
+ {
+ addSuccess(i.key() + tr(" found"));
+ }
+ else
+ {
+ if(i.key() == "font")
+ {
+ QSettings qset;
+ qset.beginGroup("RBFont");
+ QString fontDir = qset.value("fontDir", "").toString();
+ qset.endGroup();
+
+ QString newDir = fontDir + "/" + absPath.split("/").last();
+
+ if(QFile::exists(newDir))
+ {
+ addSuccess(tr("font found in font pack"));
+ }
+ else
+ {
+ addWarning(tr("font not found"));
+ }
+
+ }
+ else
+ {
+ addWarning(i.key() + tr(" not found"));
+ }
+ }
+ }
+ }
+}
+
+void ProjectExporter::checkWPS(ProjectModel* project, QString file)
+{
+ /* Set this to false if any resource checks fail */
+ bool check = true;
+
+ QSettings settings;
+ settings.beginGroup("RBFont");
+ QString fontPack = settings.value("fontDir", "").toString() + "/";
+ settings.endGroup();
+
+ QString fontDir = project->getSetting("themebase", "") + "/fonts/";
+ QString wpsName = file.split("/").last().split(".").first();
+ QString imDir = project->getSetting("themebase", "") + "/wps/" + wpsName +
+ "/";
+
+ QFile fin(file.replace("/.rockbox", project->getSetting("themebase", "")));
+ if(!fin.open(QFile::ReadOnly | QFile::Text))
+ {
+ addWarning(tr("Couldn't open ") + file.split("/").last());
+ }
+
+ QString contents(fin.readAll());
+ fin.close();
+
+ skin_element* root;
+ root = skin_parse(contents.toAscii());
+ if(!root)
+ {
+ addWarning(tr("Couldn't parse ") + file.split("/").last());
+ return;
+ }
+
+ /* Now we scan through the tree to check all the resources */
+ /* Outer loop scans through all viewports */
+ while(root)
+ {
+ skin_element* line;
+ if(root->children_count == 0)
+ line = 0;
+ else
+ line = root->children[0];
+
+ /* Next loop scans through logical lines */
+ while(line)
+ {
+
+ /* Innermost loop gives top-level tags */
+ skin_element* current;
+ if(line->children_count == 0)
+ current = 0;
+ else
+ current = line->children[0];
+ while(current)
+ {
+ if(current->type == TAG)
+ {
+ if(QString(current->tag->name) == "Fl")
+ {
+ QString font = current->params[1].data.text;
+ if(!QFile::exists(fontDir + font)
+ && !QFile::exists(fontPack + font))
+ {
+ check = false;
+ addWarning(font + tr(" not found"));
+ }
+ }
+ else if(QString(current->tag->name) == "X")
+ {
+ QString backdrop = current->params[0].data.text;
+ if(!QFile::exists(imDir + backdrop))
+ {
+ check = false;
+ addWarning(backdrop + tr(" not found"));
+ }
+ }
+ else if(QString(current->tag->name) == "xl")
+ {
+ QString image = current->params[1].data.text;
+ if(!QFile::exists(imDir + image))
+ {
+ check = false;
+ addWarning(image + tr(" not found"));
+ }
+ }
+ }
+ current = current->next;
+ }
+
+ line = line->next;
+ }
+
+ root = root->next;
+ }
+
+ if(check)
+ addSuccess(file.split("/").last() + tr(" passed resource check"));
+ else
+ addWarning(file.split("/").last() + tr(" failed resource check"));
+
+}
+
+void ProjectExporter::addSuccess(QString text)
+{
+ html += tr("<span style =\"color:green\">") + text + tr("</span><br>");
+ ui->statusBox->document()->setHtml(html);
+}
+
+void ProjectExporter::addWarning(QString text)
+{
+ html += tr("<span style =\"color:orange\">Warning: ") + text +
+ tr("</span><br>");
+ ui->statusBox->document()->setHtml(html);
+}
+
+void ProjectExporter::addError(QString text)
+{
+ html += tr("<span style =\"color:red\">Error: ") + text +
+ tr("</span><br>");
+ ui->statusBox->document()->setHtml(html);
+}