2 * This file is part of jSpeed.
4 * jSpeed is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * jSpeed is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with jSpeed. If not, see <http://www.gnu.org/licenses/>.
19 #include <QtCore/QString>
20 #include <QtCore/QDebug>
21 #include <QtCore/QDir>
22 #include "themepicker.h"
23 #include "themescheduler.h"
24 #include "themeloader.h"
27 ThemePicker::ThemePicker(QString const& text, QWidget* parent):
28 FileSelector(text, parent)
32 void ThemePicker::setVisible(bool visible)
39 FileSelector::setVisible(visible);
42 void ThemePicker::loadThemes()
44 QString current = Settings::instance().value("theme", ThemeScheduler::getDefaultTheme()).toString();
46 addItem(tr("Default"), ThemeScheduler::getDefaultTheme());
48 QDir themeDir(ThemeLoader::getThemeDir());
50 if(!themeDir.exists() || !themeDir.isReadable())
52 qDebug() << "Warning: theme dir (" + ThemeLoader::getThemeDir() + ") doesn't exist or is read protected";
57 filters << "*" + ThemeLoader::getThemeSuffix();
58 themeDir.setNameFilters(filters);
59 themeDir.setFilter(QDir::Files);
60 QStringList files = themeDir.entryList();
62 for(int i = 0; i < files.size(); i++)
66 getThemeDetails(files.at(i), name, id);
71 setCurrentIndex(i + 1);
76 bool ThemePicker::selectTheme(QString const& filename)
80 getThemeDetails(filename, name, id);
81 return selectByValue(id);
84 void ThemePicker::getThemeDetails(QString filename,
88 static QRegExp cleaner(QRegExp::escape(ThemeLoader::getThemeSuffix()) + "$");
89 filename = filename.replace(cleaner, "");
92 name = filename.at(0).toUpper() + filename.mid(1);