1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2010 Robert Bieber
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
23 #include "projectmodel.h"
24 #include "editorwindow.h"
27 #include <QTextStream>
31 ProjectModel::ProjectModel(QString config
, EditorWindow
* mainWindow
,
33 : QAbstractListModel(parent
),
34 mainWindow(mainWindow
)
36 /* Reading the config file */
38 cfg
.open(QFile::ReadOnly
| QFile::Text
);
42 settings
.insert("configfile", config
);
44 QTextStream
fin(&cfg
);
46 /* Storing the base directory */
47 QString confDir
= config
;
48 confDir
.chop(confDir
.length() - confDir
.lastIndexOf('/') - 1);
51 settings
.insert("themebase", base
.canonicalPath());
55 QString current
= fin
.readLine();
56 QList
<QString
> parts
= current
.split(':');
58 /* A valid setting has at least one : */
63 for(int i
= 1; i
< parts
.count(); i
++)
64 setting
.append(parts
[i
].trimmed());
66 settings
.insert(parts
[0].trimmed(), setting
);
71 /* Adding the files, starting with the .cfg */
72 config
.replace(base
.canonicalPath() + "/", "");
83 for(int i
= 0; i
< keys
.count(); i
++)
85 QString file
= settings
.value(keys
[i
], "");
86 if(file
!= "" && file
!= "-")
88 file
.replace("/.rockbox/", "");
96 ProjectModel::~ProjectModel()
100 int ProjectModel::rowCount(const QModelIndex
& parent
) const
102 return files
.count();
105 QVariant
ProjectModel::data(const QModelIndex
&index
, int role
) const
110 if(role
!= Qt::DisplayRole
)
113 return files
[index
.row()];
116 void ProjectModel::activated(const QModelIndex
&index
)
120 ConfigDocument
* doc
= new ConfigDocument(settings
,
121 settings
.value("themebase",
124 QObject::connect(doc
, SIGNAL(configFileChanged(QString
)),
125 mainWindow
, SLOT(configFileChanged(QString
)));
126 mainWindow
->loadConfigTab(doc
);
130 mainWindow
->loadTabFromSkinFile(settings
.value("themebase", "")
131 + "/" + files
[index
.row()]);