2 Copyright (c) 2006-2007 Paolo Capriotti <p.capriotti@gmail.com>
3 (c) 2006-2007 Maurizio Monge <maurizio.monge@kdemail.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
11 #include "themeinfo.h"
16 #include <KDesktopFile>
17 #include <KConfigGroup>
22 ThemeInfo::operator bool() const {
23 return !file_name
.isEmpty();
26 void ThemeInfo::save(Settings
& s
) {
27 s
["file-name"] = file_name
;
29 s
["description"] = description
;
31 SettingArray s_variants
= s
.group("variants").newArray("variant");
32 foreach (QString v
, variants
) {
33 Settings s_var
= s_variants
.append();
37 s
["last-modified"] = last_modified
.toString();
38 s
["desktop-file"] = desktopFile
;
41 ThemeInfo
ThemeInfo::fromSettings(const Settings
& s
) {
44 s
["file-name"] >> res
.file_name
;
45 s
["name"] >> res
.name
;
46 s
["description"] >> res
.description
;
47 s
["desktop-file"] >> res
.desktopFile
;
48 res
.last_modified
= QDateTime::fromString(s
["last-modified"].value
<QString
>());
50 SettingArray variants
= s
.group("variants").array("variant");
51 foreach (Settings var
, variants
) {
52 res
.variants
.append(var
["name"].value
<QString
>());
58 ThemeInfo
ThemeInfo::fromDesktopFile(const QString
& desktop_file
) {
61 QFileInfo
desktop_file_info(desktop_file
);
62 res
.desktopFile
= desktop_file
;
63 if (!KDesktopFile::isDesktopFile(desktop_file
)) {
67 KDesktopFile
theme(desktop_file
);
68 KConfigGroup themeData
= theme
.desktopGroup();
70 res
.name
= theme
.readName();
71 res
.description
= theme
.readComment();
72 res
.description
.replace("|", "\n");
73 res
.variants
= themeData
.readEntry("X-Tagua-Variants").split(QRegExp("\\s*,\\s*"));
74 res
.file_name
= themeData
.readEntry("X-Tagua-Script");
75 if (res
.file_name
.isEmpty()) {
76 // use a file with the same name as the .desktop, but with .lua extension
77 res
.file_name
= desktop_file
;
78 res
.file_name
.replace(QRegExp("\\.desktop$"), ".lua");
81 if (!QDir::isAbsolutePath(res
.file_name
)) {
82 // the file is relative to the .desktop directory
83 res
.file_name
= QDir(desktop_file_info
.path()).filePath(res
.file_name
);
86 res
.last_modified
= desktop_file_info
.lastModified();
91 uint
qHash(const ThemeInfo
& info
) {
92 return qHash(info
.file_name
);
95 bool ThemeInfo::operator==(const ThemeInfo
& info
) const {
96 return desktopFile
== info
.desktopFile
;