diff options
author | Robert Bieber <robby@bieberphoto.com> | 2010-06-09 20:28:51 +0000 |
---|---|---|
committer | Robert Bieber <robby@bieberphoto.com> | 2010-06-09 20:28:51 +0000 |
commit | 1cc95c541bd7bafe5d33ef0145887cb7ddd8a6d7 (patch) | |
tree | f1e3080c0a876e95b4ba76b855e54a338bd55300 | |
parent | 70b9ab484f5cddea5cb9a94c93dfbbdf6eea472a (diff) |
Theme Editor: Got project viewer displaying WPS files
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26731 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | utils/themeeditor/projectfiles.cpp | 52 | ||||
-rw-r--r-- | utils/themeeditor/projectfiles.h | 25 | ||||
-rw-r--r-- | utils/themeeditor/projectmodel.cpp | 44 | ||||
-rw-r--r-- | utils/themeeditor/projectmodel.h | 4 |
4 files changed, 121 insertions, 4 deletions
diff --git a/utils/themeeditor/projectfiles.cpp b/utils/themeeditor/projectfiles.cpp index 441ff1169e..b7168ac47d 100644 --- a/utils/themeeditor/projectfiles.cpp +++ b/utils/themeeditor/projectfiles.cpp @@ -21,8 +21,26 @@ #include "projectfiles.h" -ProjectFiles::ProjectFiles(ProjectNode* parent): parentLink(parent) +ProjectFiles::ProjectFiles(QHash<QString, QString>& settings, + ProjectNode* parent): parentLink(parent) { + QList<QString> keys; + keys.append("wps"); + keys.append("rwps"); + keys.append("sbs"); + keys.append("rsbs"); + keys.append("fms"); + keys.append("rfms"); + + for(int i = 0; i < keys.count(); i++) + { + QString file = settings.value(keys[i], ""); + if(file != "" && file != "-") + { + file.replace("/.rockbox/", ""); + children.append(new ProjectFile(file, this)); + } + } } ProjectFiles::~ProjectFiles() @@ -75,3 +93,35 @@ void ProjectFiles::activated() } +/* Project File functions */ +ProjectFile::ProjectFile(QString file, ProjectNode* parent) : + parentLink(parent), file(file) +{ + +} + +ProjectFile::~ProjectFile() +{ + +} + +QVariant ProjectFile::data(int column) const +{ + if(column == 0) + return file; + else + return QVariant(); +} + +Qt::ItemFlags ProjectFile::flags(int column) const +{ + if(column == 0) + return Qt::ItemIsEnabled | Qt::ItemIsSelectable; + else + return 0; +} + +void ProjectFile::activated() +{ +} + diff --git a/utils/themeeditor/projectfiles.h b/utils/themeeditor/projectfiles.h index 5fcbff73b2..96212c8bc6 100644 --- a/utils/themeeditor/projectfiles.h +++ b/utils/themeeditor/projectfiles.h @@ -23,11 +23,12 @@ #define PROJECTFILES_H #include "projectmodel.h" +#include <QHash> class ProjectFiles : public ProjectNode { public: - ProjectFiles(ProjectNode* parent); + ProjectFiles(QHash<QString, QString>& settings, ProjectNode* parent); virtual ~ProjectFiles(); virtual ProjectNode* parent() const; @@ -43,4 +44,26 @@ private: }; +/* A class to enumerate a single file */ +class ProjectFile: public ProjectNode +{ +public: + ProjectFile(QString file, ProjectNode* parent); + virtual ~ProjectFile(); + + virtual ProjectNode* parent() const{ return parentLink; } + virtual ProjectNode* child(int row) const{ return 0; } + virtual int numChildren() const{ return 0; } + virtual int row() const{ + return parentLink->indexOf(const_cast<ProjectFile*>(this)); + } + virtual QVariant data(int column) const; + virtual Qt::ItemFlags flags(int column) const; + virtual void activated(); + +private: + ProjectNode* parentLink; + QString file; +}; + #endif // PROJECTFILES_H diff --git a/utils/themeeditor/projectmodel.cpp b/utils/themeeditor/projectmodel.cpp index aeca1c76a7..d3a338ea4f 100644 --- a/utils/themeeditor/projectmodel.cpp +++ b/utils/themeeditor/projectmodel.cpp @@ -23,6 +23,11 @@ #include "projectmodel.h" #include "projectfiles.h" +#include <QFile> +#include <QTextStream> +#include <QHash> +#include <QDir> + ProjectModel::ProjectModel(QString config, QObject *parent) : QAbstractItemModel(parent) { @@ -60,7 +65,7 @@ QModelIndex ProjectModel::parent(const QModelIndex &child) const ProjectNode* foundParent = static_cast<ProjectNode*> (child.internalPointer())->parent(); - if(foundParent == 0) + if(foundParent == root) return QModelIndex(); return createIndex(foundParent->row(), 0, foundParent); @@ -118,7 +123,42 @@ bool ProjectModel::setData(const QModelIndex &index, const QVariant &value, /* Constructor and destructor for the root class */ ProjectRoot::ProjectRoot(QString config) { - children.append(new ProjectFiles(this)); + /* Reading the config file */ + QFile cfg(config); + cfg.open(QFile::ReadOnly | QFile::Text); + if(!cfg.isReadable()) + return; + + QTextStream fin(&cfg); + + /* Storing the base directory */ + QString confDir = config; + confDir.chop(confDir.length() - confDir.lastIndexOf('/') - 1); + QDir base(confDir); + base.cdUp(); + settings.insert("themebase", base.canonicalPath()); + + while(!fin.atEnd()) + { + QString current = fin.readLine(); + QList<QString> parts = current.split(':'); + + /* A valid setting has at least one : */ + if(parts.count() < 2) + continue; + + QString setting; + for(int i = 1; i < parts.count(); i++) + setting.append(parts[i].trimmed()); + + settings.insert(parts[0].trimmed(), setting); + } + + cfg.close(); + + /* Showing the files */ + children.append(new ProjectFiles(settings, this)); + } ProjectRoot::~ProjectRoot() diff --git a/utils/themeeditor/projectmodel.h b/utils/themeeditor/projectmodel.h index 62cf00818c..083865a669 100644 --- a/utils/themeeditor/projectmodel.h +++ b/utils/themeeditor/projectmodel.h @@ -23,6 +23,7 @@ #define PROJECTMODEL_H #include <QAbstractItemModel> +#include <QHash> class ProjectNode; @@ -98,6 +99,9 @@ public: virtual Qt::ItemFlags flags(int column) const{ return 0; } virtual void activated(){ } +private: + QHash<QString, QString> settings; + }; |