Removed unimplemented GUI actions.
[tagua/yd.git] / src / themeinfo.cpp
blob04b6b71148a48265f4b26230a6e8b87c11ad2a68
1 /*
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.
9 */
11 #include "themeinfo.h"
13 #include <QHash>
14 #include <QDir>
15 #include <QFileInfo>
16 #include <KDesktopFile>
18 #include "foreach.h"
19 #include "settings.h"
21 ThemeInfo::operator bool() const {
22 return !file_name.isEmpty();
25 void ThemeInfo::save(Settings& s) {
26 s["file-name"] = file_name;
27 s["name"] = name;
28 s["description"] = description;
30 SettingArray s_variants = s.group("variants").newArray("variant");
31 foreach (QString v, variants) {
32 Settings s_var = s_variants.append();
33 s_var["name"] = v;
36 s["last-modified"] = last_modified.toString();
37 s["desktop-file"] = desktopFile;
40 ThemeInfo ThemeInfo::fromSettings(const Settings& s) {
41 ThemeInfo res;
43 s["file-name"] >> res.file_name;
44 s["name"] >> res.name;
45 s["description"] >> res.description;
46 s["desktop-file"] >> res.desktopFile;
47 res.last_modified = QDateTime::fromString(s["last-modified"].value<QString>());
49 SettingArray variants = s.group("variants").array("variant");
50 foreach (Settings var, variants) {
51 res.variants.append(var["name"].value<QString>());
54 return res;
57 ThemeInfo ThemeInfo::fromDesktopFile(const QString& desktop_file) {
58 ThemeInfo res;
60 QFileInfo desktop_file_info(desktop_file);
61 res.desktopFile = desktop_file;
62 if (!KDesktopFile::isDesktopFile(desktop_file)) {
63 return res;
66 KDesktopFile theme(desktop_file);
67 KConfigGroup themeData = theme.desktopGroup();
69 res.name = theme.readName();
70 res.description = theme.readComment();
71 res.description.replace("|", "\n");
72 res.variants = themeData.readEntry("X-Tagua-Variants").split(QRegExp("\\s*,\\s*"));
73 res.file_name = themeData.readEntry("X-Tagua-Script");
74 if (res.file_name.isEmpty()) {
75 // use a file with the same name as the .desktop, but with .lua extension
76 res.file_name = desktop_file;
77 res.file_name.replace(QRegExp("\\.desktop$"), ".lua");
79 else {
80 if (!QDir::isAbsolutePath(res.file_name)) {
81 // the file is relative to the .desktop directory
82 res.file_name = QDir(desktop_file_info.path()).filePath(res.file_name);
85 res.last_modified = desktop_file_info.lastModified();
87 return res;
90 uint qHash(const ThemeInfo& info) {
91 return qHash(info.file_name);
94 bool ThemeInfo::operator==(const ThemeInfo& info) const {
95 return desktopFile == info.desktopFile;