forked from len0rd/rockbox
Theme Editor: Got project viewer displaying WPS files
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26731 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
70b9ab484f
commit
1cc95c541b
4 changed files with 121 additions and 4 deletions
|
@ -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()
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue