diff options
Diffstat (limited to 'utils/themeeditor/projectmodel.cpp')
-rw-r--r-- | utils/themeeditor/projectmodel.cpp | 161 |
1 files changed, 47 insertions, 114 deletions
diff --git a/utils/themeeditor/projectmodel.cpp b/utils/themeeditor/projectmodel.cpp index da810d4906..925be81950 100644 --- a/utils/themeeditor/projectmodel.cpp +++ b/utils/themeeditor/projectmodel.cpp | |||
@@ -21,124 +21,18 @@ | |||
21 | 21 | ||
22 | 22 | ||
23 | #include "projectmodel.h" | 23 | #include "projectmodel.h" |
24 | #include "projectfiles.h" | ||
25 | #include "projectsettings.h" | ||
26 | #include "editorwindow.h" | 24 | #include "editorwindow.h" |
27 | 25 | ||
28 | #include <QFile> | 26 | #include <QFile> |
29 | #include <QTextStream> | 27 | #include <QTextStream> |
30 | #include <QHash> | 28 | #include <QMap> |
31 | #include <QDir> | 29 | #include <QDir> |
32 | 30 | ||
33 | ProjectModel::ProjectModel(QString config, EditorWindow* mainWindow, | 31 | ProjectModel::ProjectModel(QString config, EditorWindow* mainWindow, |
34 | QObject *parent) | 32 | QObject *parent) |
35 | : QAbstractItemModel(parent), | 33 | : QAbstractListModel(parent), |
36 | mainWindow(mainWindow) | 34 | mainWindow(mainWindow) |
37 | { | 35 | { |
38 | root = new ProjectRoot(config, this); | ||
39 | } | ||
40 | |||
41 | ProjectModel::~ProjectModel() | ||
42 | { | ||
43 | if(root) | ||
44 | delete root; | ||
45 | } | ||
46 | |||
47 | QModelIndex ProjectModel::index(int row, int column, | ||
48 | const QModelIndex& parent) const | ||
49 | { | ||
50 | |||
51 | if(!hasIndex(row, column, parent)) | ||
52 | return QModelIndex(); | ||
53 | |||
54 | ProjectNode* foundParent = root; | ||
55 | if(parent.isValid()) | ||
56 | foundParent = static_cast<ProjectNode*>(parent.internalPointer()); | ||
57 | |||
58 | if(row < foundParent->numChildren() && row >= 0) | ||
59 | return createIndex(row, column, foundParent->child(row)); | ||
60 | else | ||
61 | return QModelIndex(); | ||
62 | } | ||
63 | |||
64 | QModelIndex ProjectModel::parent(const QModelIndex &child) const | ||
65 | { | ||
66 | if(!child.isValid()) | ||
67 | return QModelIndex(); | ||
68 | |||
69 | ProjectNode* foundParent = static_cast<ProjectNode*> | ||
70 | (child.internalPointer())->parent(); | ||
71 | |||
72 | if(foundParent == root) | ||
73 | return QModelIndex(); | ||
74 | |||
75 | return createIndex(foundParent->row(), 0, foundParent); | ||
76 | } | ||
77 | |||
78 | int ProjectModel::rowCount(const QModelIndex &parent) const | ||
79 | { | ||
80 | if(!root) | ||
81 | return 0; | ||
82 | |||
83 | if(!parent.isValid()) | ||
84 | return root->numChildren(); | ||
85 | |||
86 | if(parent.column() != 0) | ||
87 | return 0; | ||
88 | |||
89 | return static_cast<ProjectNode*>(parent.internalPointer())->numChildren(); | ||
90 | } | ||
91 | |||
92 | int ProjectModel::columnCount(const QModelIndex &parent) const | ||
93 | { | ||
94 | return numColumns; | ||
95 | } | ||
96 | |||
97 | QVariant ProjectModel::data(const QModelIndex &index, int role) const | ||
98 | { | ||
99 | if(!index.isValid()) | ||
100 | return QVariant(); | ||
101 | |||
102 | if(role != Qt::DisplayRole) | ||
103 | return QVariant(); | ||
104 | |||
105 | return static_cast<ProjectNode*> | ||
106 | (index.internalPointer())->data(index.column()); | ||
107 | } | ||
108 | |||
109 | QVariant ProjectModel::headerData(int col, Qt::Orientation orientation, | ||
110 | int role) const | ||
111 | { | ||
112 | return QVariant(); | ||
113 | } | ||
114 | |||
115 | Qt::ItemFlags ProjectModel::flags(const QModelIndex &index) const | ||
116 | { | ||
117 | return static_cast<ProjectNode*> | ||
118 | (index.internalPointer())->flags(index.column()); | ||
119 | } | ||
120 | |||
121 | bool ProjectModel::setData(const QModelIndex &index, const QVariant &value, | ||
122 | int role) | ||
123 | { | ||
124 | return true; | ||
125 | } | ||
126 | |||
127 | void ProjectModel::loadFile(QString file) | ||
128 | { | ||
129 | mainWindow->loadTabFromFile(file); | ||
130 | } | ||
131 | |||
132 | void ProjectModel::activated(const QModelIndex &index) | ||
133 | { | ||
134 | static_cast<ProjectNode*>(index.internalPointer())->activated(); | ||
135 | } | ||
136 | |||
137 | /* Constructor and destructor for the root class */ | ||
138 | ProjectRoot::ProjectRoot(QString config, ProjectModel* model) | ||
139 | { | ||
140 | this->model = model; | ||
141 | |||
142 | /* Reading the config file */ | 36 | /* Reading the config file */ |
143 | QFile cfg(config); | 37 | QFile cfg(config); |
144 | cfg.open(QFile::ReadOnly | QFile::Text); | 38 | cfg.open(QFile::ReadOnly | QFile::Text); |
@@ -172,14 +66,53 @@ ProjectRoot::ProjectRoot(QString config, ProjectModel* model) | |||
172 | 66 | ||
173 | cfg.close(); | 67 | cfg.close(); |
174 | 68 | ||
175 | /* Showing the files */ | 69 | /* Adding the files, starting with the .cfg */ |
176 | children.append(new ProjectFiles(settings, model, this)); | 70 | config.replace(base.canonicalPath() + "/", ""); |
177 | children.append(new ProjectSettings(settings, model, this)); | 71 | files.append(config); |
72 | |||
73 | QList<QString> keys; | ||
74 | keys.append("wps"); | ||
75 | keys.append("rwps"); | ||
76 | keys.append("sbs"); | ||
77 | keys.append("rsbs"); | ||
78 | keys.append("fms"); | ||
79 | keys.append("rfms"); | ||
80 | |||
81 | for(int i = 0; i < keys.count(); i++) | ||
82 | { | ||
83 | QString file = settings.value(keys[i], ""); | ||
84 | if(file != "" && file != "-") | ||
85 | { | ||
86 | file.replace("/.rockbox/", ""); | ||
87 | files.append(file); | ||
88 | } | ||
89 | } | ||
178 | 90 | ||
91 | |||
92 | } | ||
93 | |||
94 | ProjectModel::~ProjectModel() | ||
95 | { | ||
179 | } | 96 | } |
180 | 97 | ||
181 | ProjectRoot::~ProjectRoot() | 98 | int ProjectModel::rowCount(const QModelIndex& parent) const |
99 | { | ||
100 | return files.count(); | ||
101 | } | ||
102 | |||
103 | QVariant ProjectModel::data(const QModelIndex &index, int role) const | ||
104 | { | ||
105 | if(!index.isValid()) | ||
106 | return QVariant(); | ||
107 | |||
108 | if(role != Qt::DisplayRole) | ||
109 | return QVariant(); | ||
110 | |||
111 | return files[index.row()]; | ||
112 | } | ||
113 | |||
114 | void ProjectModel::activated(const QModelIndex &index) | ||
182 | { | 115 | { |
183 | for(int i = 0; i < children.count(); i++) | 116 | mainWindow->loadTabFromFile(settings.value("themebase", "") |
184 | delete children[i]; | 117 | + "/" + files[index.row()]); |
185 | } | 118 | } |