diff options
author | Robert Bieber <robby@bieberphoto.com> | 2010-07-24 22:41:45 +0000 |
---|---|---|
committer | Robert Bieber <robby@bieberphoto.com> | 2010-07-24 22:41:45 +0000 |
commit | 7a1a72a5273bd8179d61a51335c3d4d19c6bd5e5 (patch) | |
tree | d849fec17287d7a2a13e1a83946287037220f1f3 | |
parent | 1035fa95a307283177f1fb7829a9861fe44fea29 (diff) | |
download | rockbox-7a1a72a5273bd8179d61a51335c3d4d19c6bd5e5.tar.gz rockbox-7a1a72a5273bd8179d61a51335c3d4d19c6bd5e5.zip |
Theme Editor: Added resource check to project export
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27543 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | utils/themeeditor/gui/projectexporter.cpp | 193 | ||||
-rw-r--r-- | utils/themeeditor/gui/projectexporter.h | 6 |
2 files changed, 187 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 @@ | |||
22 | #include "projectexporter.h" | 22 | #include "projectexporter.h" |
23 | #include "ui_projectexporter.h" | 23 | #include "ui_projectexporter.h" |
24 | 24 | ||
25 | #include "tag_table.h" | ||
26 | #include "skin_parser.h" | ||
27 | |||
25 | #include "quazipfile.h" | 28 | #include "quazipfile.h" |
26 | 29 | ||
27 | #include <QTextStream> | 30 | #include <QTextStream> |
28 | #include <QDir> | 31 | #include <QDir> |
32 | #include <QSettings> | ||
33 | #include <QDebug> | ||
29 | 34 | ||
30 | ProjectExporter::ProjectExporter(QString path, ProjectModel* project, | 35 | ProjectExporter::ProjectExporter(QString path, ProjectModel* project, |
31 | QWidget *parent) | 36 | QWidget *parent) |
@@ -39,21 +44,16 @@ ProjectExporter::ProjectExporter(QString path, ProjectModel* project, | |||
39 | 44 | ||
40 | if(zipFile.open(QuaZip::mdCreate)) | 45 | if(zipFile.open(QuaZip::mdCreate)) |
41 | { | 46 | { |
42 | html += tr("<span style=\"color:orange\">Resource Check: " | 47 | |
43 | "Not implemented yet</span><br>"); | 48 | checkRes(project); |
44 | ui->statusBox->document()->setHtml(html); | ||
45 | writeZip(project->getSetting("themebase", "")); | 49 | writeZip(project->getSetting("themebase", "")); |
46 | zipFile.close(); | 50 | zipFile.close(); |
47 | 51 | ||
48 | html += tr("<span style=\"color:green\">Project exported " | 52 | addSuccess(tr("Project exported successfully")); |
49 | "successfully</span><br>"); | ||
50 | ui->statusBox->document()->setHtml(html); | ||
51 | } | 53 | } |
52 | else | 54 | else |
53 | { | 55 | { |
54 | html += tr("<span style = \"color:red\">" | 56 | addError(tr("Couldn't open zip file")); |
55 | "Error opening zip file</span><br>"); | ||
56 | ui->statusBox->document()->setHtml(html); | ||
57 | } | 57 | } |
58 | } | 58 | } |
59 | 59 | ||
@@ -92,9 +92,7 @@ void ProjectExporter::writeZip(QString path, QString base) | |||
92 | base = path; | 92 | base = path; |
93 | if(path == "") | 93 | if(path == "") |
94 | { | 94 | { |
95 | html += tr("<span style = \"color:red\">" | 95 | addError(tr("Couldn't locate project directory")); |
96 | "Error: Couldn't locate project directory</span><br>"); | ||
97 | ui->statusBox->document()->setHtml(html); | ||
98 | return; | 96 | return; |
99 | } | 97 | } |
100 | 98 | ||
@@ -129,3 +127,174 @@ void ProjectExporter::writeZip(QString path, QString base) | |||
129 | writeZip(current.absoluteFilePath(), base); | 127 | writeZip(current.absoluteFilePath(), base); |
130 | } | 128 | } |
131 | } | 129 | } |
130 | |||
131 | void ProjectExporter::checkRes(ProjectModel *project) | ||
132 | { | ||
133 | QMap<QString, QString> settings = project->getSettings(); | ||
134 | QMap<QString, QString>::iterator i; | ||
135 | |||
136 | for(i = settings.begin(); i != settings.end(); i++) | ||
137 | { | ||
138 | if(i.key() == "wps" || i.key() == "rwps" || i.key() == "sbs" | ||
139 | || i.key() == "rsbs" || i.key() == "fms" || i.key() == "rfms") | ||
140 | { | ||
141 | checkWPS(project, i.value()); | ||
142 | } | ||
143 | else if(i.value().contains("/.rockbox")) | ||
144 | { | ||
145 | QString absPath = i.value().replace("/.rockbox", | ||
146 | settings.value("themebase")); | ||
147 | if(QFile::exists(absPath)) | ||
148 | { | ||
149 | addSuccess(i.key() + tr(" found")); | ||
150 | } | ||
151 | else | ||
152 | { | ||
153 | if(i.key() == "font") | ||
154 | { | ||
155 | QSettings qset; | ||
156 | qset.beginGroup("RBFont"); | ||
157 | QString fontDir = qset.value("fontDir", "").toString(); | ||
158 | qset.endGroup(); | ||
159 | |||
160 | QString newDir = fontDir + "/" + absPath.split("/").last(); | ||
161 | |||
162 | if(QFile::exists(newDir)) | ||
163 | { | ||
164 | addSuccess(tr("font found in font pack")); | ||
165 | } | ||
166 | else | ||
167 | { | ||
168 | addWarning(tr("font not found")); | ||
169 | } | ||
170 | |||
171 | } | ||
172 | else | ||
173 | { | ||
174 | addWarning(i.key() + tr(" not found")); | ||
175 | } | ||
176 | } | ||
177 | } | ||
178 | } | ||
179 | } | ||
180 | |||
181 | void ProjectExporter::checkWPS(ProjectModel* project, QString file) | ||
182 | { | ||
183 | /* Set this to false if any resource checks fail */ | ||
184 | bool check = true; | ||
185 | |||
186 | QSettings settings; | ||
187 | settings.beginGroup("RBFont"); | ||
188 | QString fontPack = settings.value("fontDir", "").toString() + "/"; | ||
189 | settings.endGroup(); | ||
190 | |||
191 | QString fontDir = project->getSetting("themebase", "") + "/fonts/"; | ||
192 | QString wpsName = file.split("/").last().split(".").first(); | ||
193 | QString imDir = project->getSetting("themebase", "") + "/wps/" + wpsName + | ||
194 | "/"; | ||
195 | |||
196 | QFile fin(file.replace("/.rockbox", project->getSetting("themebase", ""))); | ||
197 | if(!fin.open(QFile::ReadOnly | QFile::Text)) | ||
198 | { | ||
199 | addWarning(tr("Couldn't open ") + file.split("/").last()); | ||
200 | } | ||
201 | |||
202 | QString contents(fin.readAll()); | ||
203 | fin.close(); | ||
204 | |||
205 | skin_element* root; | ||
206 | root = skin_parse(contents.toAscii()); | ||
207 | if(!root) | ||
208 | { | ||
209 | addWarning(tr("Couldn't parse ") + file.split("/").last()); | ||
210 | return; | ||
211 | } | ||
212 | |||
213 | /* Now we scan through the tree to check all the resources */ | ||
214 | /* Outer loop scans through all viewports */ | ||
215 | while(root) | ||
216 | { | ||
217 | skin_element* line; | ||
218 | if(root->children_count == 0) | ||
219 | line = 0; | ||
220 | else | ||
221 | line = root->children[0]; | ||
222 | |||
223 | /* Next loop scans through logical lines */ | ||
224 | while(line) | ||
225 | { | ||
226 | |||
227 | /* Innermost loop gives top-level tags */ | ||
228 | skin_element* current; | ||
229 | if(line->children_count == 0) | ||
230 | current = 0; | ||
231 | else | ||
232 | current = line->children[0]; | ||
233 | while(current) | ||
234 | { | ||
235 | if(current->type == TAG) | ||
236 | { | ||
237 | if(QString(current->tag->name) == "Fl") | ||
238 | { | ||
239 | QString font = current->params[1].data.text; | ||
240 | if(!QFile::exists(fontDir + font) | ||
241 | && !QFile::exists(fontPack + font)) | ||
242 | { | ||
243 | check = false; | ||
244 | addWarning(font + tr(" not found")); | ||
245 | } | ||
246 | } | ||
247 | else if(QString(current->tag->name) == "X") | ||
248 | { | ||
249 | QString backdrop = current->params[0].data.text; | ||
250 | if(!QFile::exists(imDir + backdrop)) | ||
251 | { | ||
252 | check = false; | ||
253 | addWarning(backdrop + tr(" not found")); | ||
254 | } | ||
255 | } | ||
256 | else if(QString(current->tag->name) == "xl") | ||
257 | { | ||
258 | QString image = current->params[1].data.text; | ||
259 | if(!QFile::exists(imDir + image)) | ||
260 | { | ||
261 | check = false; | ||
262 | addWarning(image + tr(" not found")); | ||
263 | } | ||
264 | } | ||
265 | } | ||
266 | current = current->next; | ||
267 | } | ||
268 | |||
269 | line = line->next; | ||
270 | } | ||
271 | |||
272 | root = root->next; | ||
273 | } | ||
274 | |||
275 | if(check) | ||
276 | addSuccess(file.split("/").last() + tr(" passed resource check")); | ||
277 | else | ||
278 | addWarning(file.split("/").last() + tr(" failed resource check")); | ||
279 | |||
280 | } | ||
281 | |||
282 | void ProjectExporter::addSuccess(QString text) | ||
283 | { | ||
284 | html += tr("<span style =\"color:green\">") + text + tr("</span><br>"); | ||
285 | ui->statusBox->document()->setHtml(html); | ||
286 | } | ||
287 | |||
288 | void ProjectExporter::addWarning(QString text) | ||
289 | { | ||
290 | html += tr("<span style =\"color:orange\">Warning: ") + text + | ||
291 | tr("</span><br>"); | ||
292 | ui->statusBox->document()->setHtml(html); | ||
293 | } | ||
294 | |||
295 | void ProjectExporter::addError(QString text) | ||
296 | { | ||
297 | html += tr("<span style =\"color:red\">Error: ") + text + | ||
298 | tr("</span><br>"); | ||
299 | ui->statusBox->document()->setHtml(html); | ||
300 | } | ||
diff --git a/utils/themeeditor/gui/projectexporter.h b/utils/themeeditor/gui/projectexporter.h index d743172dd9..353aadda1c 100644 --- a/utils/themeeditor/gui/projectexporter.h +++ b/utils/themeeditor/gui/projectexporter.h | |||
@@ -49,6 +49,12 @@ private slots: | |||
49 | 49 | ||
50 | private: | 50 | private: |
51 | void writeZip(QString path, QString base = ""); | 51 | void writeZip(QString path, QString base = ""); |
52 | void checkRes(ProjectModel* project); | ||
53 | void checkWPS(ProjectModel* project, QString file); | ||
54 | |||
55 | void addSuccess(QString text); | ||
56 | void addWarning(QString text); | ||
57 | void addError(QString text); | ||
52 | 58 | ||
53 | Ui::ProjectExporter *ui; | 59 | Ui::ProjectExporter *ui; |
54 | QuaZip zipFile; | 60 | QuaZip zipFile; |