summaryrefslogtreecommitdiff
path: root/utils/themeeditor/models/targetdata.cpp
diff options
context:
space:
mode:
authorRobert Bieber <robby@bieberphoto.com>2010-07-16 20:47:23 +0000
committerRobert Bieber <robby@bieberphoto.com>2010-07-16 20:47:23 +0000
commit025147effbee00db8bae931b3ef3df25052e0d96 (patch)
treedb2df79d33b48f115fa35ffd9ae24f97c2bdc28b /utils/themeeditor/models/targetdata.cpp
parent1c1d10b9fdfc2b78c5aeba4c352cd7dbc0717edc (diff)
downloadrockbox-025147effbee00db8bae931b3ef3df25052e0d96.zip
rockbox-025147effbee00db8bae931b3ef3df25052e0d96.tar.gz
rockbox-025147effbee00db8bae931b3ef3df25052e0d96.tar.bz2
rockbox-025147effbee00db8bae931b3ef3df25052e0d96.tar.xz
Theme Editor: Added target database, now populates combo box in new project dialog but otherwise not used yet
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27450 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'utils/themeeditor/models/targetdata.cpp')
-rw-r--r--utils/themeeditor/models/targetdata.cpp245
1 files changed, 245 insertions, 0 deletions
diff --git a/utils/themeeditor/models/targetdata.cpp b/utils/themeeditor/models/targetdata.cpp
new file mode 100644
index 0000000..a20a4cf
--- /dev/null
+++ b/utils/themeeditor/models/targetdata.cpp
@@ -0,0 +1,245 @@
+/***************************************************************************
+ * __________ __ ___.
+ * 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 "targetdata.h"
+
+#include <QStringList>
+
+const QString TargetData::reserved = "{}:#\n";
+
+TargetData::TargetData(QString file)
+{
+ if(!QFile::exists(file))
+ file = ":/targets/targetdb";
+
+ QFile fin(file);
+ fin.open(QFile::ReadOnly | QFile::Text);
+
+ /* Reading the database */
+ QString data = QString(fin.readAll());
+
+ fin.close();
+
+ int cursor = 0;
+ int index = 0;
+ while(cursor < data.count())
+ {
+ QString id = scanString(data, cursor);
+ QString name = "";
+ QRect size(0, 0, 0, 0);
+ ScreenDepth depth = None;
+ QRect rSize(0, 0, 0, 0);
+ ScreenDepth rDepth = None;
+ bool fm = false;
+
+ if(id == "")
+ break;
+
+ if(!require('{', data, cursor))
+ break;
+
+ /* Now we have to parse each of the arguments */
+ while(cursor < data.count())
+ {
+ QString key = scanString(data, cursor);
+ if(key == "")
+ {
+ break;
+ }
+ else
+ {
+ if(!require(':', data, cursor))
+ break;
+
+ if(key.toLower() == "name")
+ {
+ name = scanString(data, cursor);
+ }
+ else if(key.toLower() == "screen")
+ {
+ QString s = scanString(data, cursor);
+ if(s[0].toLower() != 'n')
+ {
+ int subCursor = 0;
+ int width = scanInt(s, subCursor);
+
+ if(!require('x', s, subCursor))
+ break;
+
+ int height = scanInt(s, subCursor);
+
+ if(!require('@', s, subCursor))
+ break;
+
+ size = QRect(0, 0, width, height);
+ depth = scanDepth(s, subCursor);
+ }
+ }
+ else if(key.toLower() == "remote")
+ {
+ QString s = scanString(data, cursor);
+ if(s[0].toLower() != 'n')
+ {
+ int subCursor = 0;
+ int width = scanInt(s, subCursor);
+
+ if(!require('x', s, subCursor))
+ break;
+
+ int height = scanInt(s, subCursor);
+
+ if(!require('@', s, subCursor))
+ break;
+
+ rSize = QRect(0, 0, width, height);
+ rDepth = scanDepth(s, subCursor);
+ }
+ }
+ else if(key.toLower() == "fm")
+ {
+ QString s = scanString(data, cursor);
+ if(s.toLower() == "yes")
+ fm = true;
+ }
+ }
+ }
+
+ /* Checking for the closing '}' and adding the entry */
+ if(require('}', data, cursor))
+ {
+ entries.append(Entry(name, size, depth, rSize, rDepth, fm));
+ indices.insert(id, index);
+ index++;
+ }
+ else
+ {
+ break;
+ }
+ }
+}
+
+TargetData::~TargetData()
+{
+}
+
+QString TargetData::scanString(QString data, int &index)
+{
+ QString retval;
+
+ /* Skipping whitespace and comments */
+ while(index < data.count() && (data[index].isSpace() || data[index] == '#'))
+ {
+ if(data[index] == '#')
+ skipComment(data, index);
+ else
+ index++;
+ }
+
+ while(index < data.count() && !reserved.contains(data[index]))
+ {
+ if(data[index] == '%')
+ {
+ retval.append(data[index + 1]);
+ index += 2;
+ }
+ else
+ {
+ retval.append(data[index]);
+ index++;
+ }
+ }
+
+ return retval.trimmed();
+}
+
+int TargetData::scanInt(QString data, int &index)
+{
+ /* Skipping whitespace and comments */
+ while(index < data.count() && (data[index].isSpace() || data[index] == '#'))
+ {
+ if(data[index] == '#')
+ skipComment(data, index);
+ else
+ index++;
+ }
+
+ QString number;
+ while(index < data.count() && data[index].isDigit())
+ number.append(data[index++]);
+
+ return number.toInt();
+}
+
+TargetData::ScreenDepth TargetData::scanDepth(QString data, int &index)
+{
+ QString depth = scanString(data, index);
+
+ if(depth.toLower() == "grey")
+ return Grey;
+ else if(depth.toLower() == "rgb")
+ return RGB;
+ else if(depth.toLower() == "mono")
+ return Mono;
+ else
+ return None;
+}
+
+void TargetData::skipComment(QString data, int &index)
+{
+ if(data[index] != '#')
+ return;
+
+ while(index < data.count() && data[index] != '\n')
+ index++;
+
+ if(index < data.count())
+ index++;
+}
+
+bool TargetData::require(QChar required, QString data, int &index)
+{
+ /* Skipping whitespace and comments */
+ while(index < data.count() && (data[index].isSpace() || data[index] == '#'))
+ {
+ if(data[index] == '#')
+ skipComment(data, index);
+ else
+ index++;
+ }
+
+ if(index == data.count())
+ {
+ return false;
+ }
+ else
+ {
+ if(data[index] == required)
+ {
+ index++;
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+}