1 // vim: set tabstop=4 shiftwidth=4 noexpandtab:
3 Gwenview: an image viewer
4 Copyright 2008 Aurélien Gâteau <aurelien.gateau@free.fr>
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.
22 #include "fullscreentheme.h"
30 #include <kcomponentdata.h>
31 #include <kmacroexpander.h>
32 #include <kstandarddirs.h>
33 #include <kstringhandler.h>
36 #include <lib/gwenviewconfig.h>
41 static const char* THEME_BASE_DIR
= "fullscreenthemes/";
44 struct FullScreenThemePrivate
{
50 FullScreenTheme::FullScreenTheme(const QString
& themeName
)
51 : d(new FullScreenThemePrivate
) {
53 d
->mThemeDir
= KStandardDirs::locate("appdata", THEME_BASE_DIR
+ themeName
+ '/');
54 if (d
->mThemeDir
.isEmpty()) {
55 kWarning() << "Couldn't find fullscreen theme" << themeName
;
60 QString styleSheetPath
= d
->mThemeDir
+ "/style.css";
61 QFile
file(styleSheetPath
);
62 if (!file
.open(QIODevice::ReadOnly
| QIODevice::Text
)) {
63 kWarning() << "Couldn't open" << styleSheetPath
;
66 QString styleSheet
= QString::fromUtf8(file
.readAll());
68 d
->mStyleSheet
= replaceThemeVars(styleSheet
);
72 FullScreenTheme::~FullScreenTheme() {
77 QString
FullScreenTheme::styleSheet() const {
78 return d
->mStyleSheet
;
82 QString
FullScreenTheme::replaceThemeVars(const QString
& styleSheet
) {
83 QHash
<QString
, QString
> macros
;
84 macros
["themeDir"] = d
->mThemeDir
;
85 return KMacroExpander::expandMacros(styleSheet
, macros
, QLatin1Char('$'));
89 QString
FullScreenTheme::currentThemeName() {
90 return GwenviewConfig::fullScreenTheme();
94 void FullScreenTheme::setCurrentThemeName(const QString
& name
) {
95 GwenviewConfig::setFullScreenTheme(name
);
99 static bool themeNameLessThan(const QString
& s1
, const QString
& s2
) {
100 return KStringHandler::naturalCompare(s1
.toLower(), s2
.toLower()) < 0;
104 QStringList
FullScreenTheme::themeNameList() {
106 QStringList themeBaseDirs
=
107 KGlobal::mainComponent().dirs()
108 ->findDirs("appdata", THEME_BASE_DIR
);
109 Q_FOREACH(const QString
& themeBaseDir
, themeBaseDirs
) {
110 QDir
dir(themeBaseDir
);
111 list
+= dir
.entryList(QDir::Dirs
| QDir::NoDotAndDotDot
);
113 qSort(list
.begin(), list
.end(), themeNameLessThan
);