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 QTextStream
fin(&cfg
);
44 /* Storing the base directory */
45 QString confDir
= config
;
46 confDir
.chop(confDir
.length() - confDir
.lastIndexOf('/') - 1);
49 settings
.insert("themebase", base
.canonicalPath());
53 QString current
= fin
.readLine();
54 QList
<QString
> parts
= current
.split(':');
56 /* A valid setting has at least one : */
61 for(int i
= 1; i
< parts
.count(); i
++)
62 setting
.append(parts
[i
].trimmed());
64 settings
.insert(parts
[0].trimmed(), setting
);
69 /* Adding the files, starting with the .cfg */
70 config
.replace(base
.canonicalPath() + "/", "");
81 for(int i
= 0; i
< keys
.count(); i
++)
83 QString file
= settings
.value(keys
[i
], "");
84 if(file
!= "" && file
!= "-")
86 file
.replace("/.rockbox/", "");
94 ProjectModel::~ProjectModel()
98 int ProjectModel::rowCount(const QModelIndex
& parent
) const
100 return files
.count();
103 QVariant
ProjectModel::data(const QModelIndex
&index
, int role
) const
108 if(role
!= Qt::DisplayRole
)
111 return files
[index
.row()];
114 void ProjectModel::activated(const QModelIndex
&index
)
116 mainWindow
->loadTabFromFile(settings
.value("themebase", "")
117 + "/" + files
[index
.row()]);