From 06177a0cecb29906e9bbe823a3d247c9e936f00e Mon Sep 17 00:00:00 2001 From: Paolo Capriotti Date: Fri, 20 Jul 2007 18:30:18 +0200 Subject: [PATCH] Themes are now searched by desktop files. This means that all themes should now have an associated desktop files. Some themes (but not all) have been ported. --- data/themes/controls/Cool/theme.desktop | 8 ++ data/themes/controls/Google/theme_google.desktop | 8 ++ data/themes/figurines/AlphaTTF/theme.desktop | 8 ++ data/themes/figurines/FantasyTTF/theme.desktop | 8 ++ .../pieces/AlphaTTF/theme_babaschess.desktop | 7 ++ data/themes/pieces/AlphaTTF/theme_eboard.desktop | 7 ++ data/themes/pieces/AlphaTTF/theme_jose.desktop | 7 ++ data/themes/pieces/FantasySVG/theme.desktop | 2 + data/themes/squares/Default/theme.desktop | 8 ++ src/loader/theme.cpp | 3 +- src/luaapi/loader.h | 6 +- src/pref_theme.cpp | 98 +++++++++++++--------- src/pref_theme.h | 2 +- 13 files changed, 129 insertions(+), 43 deletions(-) create mode 100644 data/themes/controls/Cool/theme.desktop create mode 100644 data/themes/controls/Google/theme_google.desktop create mode 100644 data/themes/figurines/AlphaTTF/theme.desktop create mode 100644 data/themes/figurines/FantasyTTF/theme.desktop create mode 100644 data/themes/pieces/AlphaTTF/theme_babaschess.desktop create mode 100644 data/themes/pieces/AlphaTTF/theme_eboard.desktop create mode 100644 data/themes/pieces/AlphaTTF/theme_jose.desktop create mode 100644 data/themes/squares/Default/theme.desktop diff --git a/data/themes/controls/Cool/theme.desktop b/data/themes/controls/Cool/theme.desktop new file mode 100644 index 0000000..4ad865d --- /dev/null +++ b/data/themes/controls/Cool/theme.desktop @@ -0,0 +1,8 @@ +[Desktop Entry] +Encoding=UTF-8 +Name=Cool +Type=Application +Comment=Cool controls +X-Tagua-ThemeType=Figurines +X-Tagua-Variants=any[default] +X-Tagua-Script=theme.lua diff --git a/data/themes/controls/Google/theme_google.desktop b/data/themes/controls/Google/theme_google.desktop new file mode 100644 index 0000000..eb227ba --- /dev/null +++ b/data/themes/controls/Google/theme_google.desktop @@ -0,0 +1,8 @@ +[Desktop Entry] +Encoding=UTF-8 +Name=Google +Type=Application +Comment=Google-like controls +X-Tagua-ThemeType=Controls +X-Tagua-Variants=any +X-Tagua-Script=theme_google.lua diff --git a/data/themes/figurines/AlphaTTF/theme.desktop b/data/themes/figurines/AlphaTTF/theme.desktop new file mode 100644 index 0000000..d55b83b --- /dev/null +++ b/data/themes/figurines/AlphaTTF/theme.desktop @@ -0,0 +1,8 @@ +[Desktop Entry] +Encoding=UTF-8 +Name=Alpha +Type=Application +Comment=Alpha TTF figurines.| by Eric Bentzen +X-Tagua-ThemeType=Figurines +X-Tagua-Variants=Chess +X-Tagua-Script=theme.lua diff --git a/data/themes/figurines/FantasyTTF/theme.desktop b/data/themes/figurines/FantasyTTF/theme.desktop new file mode 100644 index 0000000..f5607aa --- /dev/null +++ b/data/themes/figurines/FantasyTTF/theme.desktop @@ -0,0 +1,8 @@ +[Desktop Entry] +Encoding=UTF-8 +Name=Fantasy +Type=Application +Comment=Google-like controls +X-Tagua-ThemeType=Figurines +X-Tagua-Variants=Chess[default] +X-Tagua-Script=theme.lua diff --git a/data/themes/pieces/AlphaTTF/theme_babaschess.desktop b/data/themes/pieces/AlphaTTF/theme_babaschess.desktop new file mode 100644 index 0000000..70b0fd6 --- /dev/null +++ b/data/themes/pieces/AlphaTTF/theme_babaschess.desktop @@ -0,0 +1,7 @@ +[Desktop Entry] +Encoding=UTF-8 +Name=Alpha (BabasChess style) +Type=Application +Comment=Alpha TTF theme,|as BabasChess's default.| by Eric Bentzen +X-Tagua-ThemeType=Pieces +X-Tagua-Variants=Chess diff --git a/data/themes/pieces/AlphaTTF/theme_eboard.desktop b/data/themes/pieces/AlphaTTF/theme_eboard.desktop new file mode 100644 index 0000000..1c0b5c1 --- /dev/null +++ b/data/themes/pieces/AlphaTTF/theme_eboard.desktop @@ -0,0 +1,7 @@ +[Desktop Entry] +Encoding=UTF-8 +Name=Alpha (Eboard style) +Type=Application +Comment=Alpha TTF theme.| by Eric Bentzen +X-Tagua-ThemeType=Pieces +X-Tagua-Variants=Chess diff --git a/data/themes/pieces/AlphaTTF/theme_jose.desktop b/data/themes/pieces/AlphaTTF/theme_jose.desktop new file mode 100644 index 0000000..be6a077 --- /dev/null +++ b/data/themes/pieces/AlphaTTF/theme_jose.desktop @@ -0,0 +1,7 @@ +[Desktop Entry] +Encoding=UTF-8 +Name=Alpha (Jose style) +Type=Application +Comment=Alpha TTF theme.| by Eric Bentzen +X-Tagua-ThemeType=Pieces +X-Tagua-Variants=Chess diff --git a/data/themes/pieces/FantasySVG/theme.desktop b/data/themes/pieces/FantasySVG/theme.desktop index fb79e22..3ddc19c 100644 --- a/data/themes/pieces/FantasySVG/theme.desktop +++ b/data/themes/pieces/FantasySVG/theme.desktop @@ -3,4 +3,6 @@ Encoding=UTF-8 Name=FantasySVG Type=Application Comment=Fantasy SVG theme,| by Maurizio Monge +X-Tagua-ThemeType=Pieces X-Tagua-Variants=Chess[default], Shogi +X-Tagua-Script=theme.lua diff --git a/data/themes/squares/Default/theme.desktop b/data/themes/squares/Default/theme.desktop new file mode 100644 index 0000000..9405236 --- /dev/null +++ b/data/themes/squares/Default/theme.desktop @@ -0,0 +1,8 @@ +[Desktop Entry] +Encoding=UTF-8 +Name=Default +Type=Application +Comment=Default squares +X-Tagua-ThemeType=Squares +X-Tagua-Variants=Chess[default], Shogi, XiangQi +X-Tagua-Script=theme.lua diff --git a/src/loader/theme.cpp b/src/loader/theme.cpp index 9ee8ad5..e0e244f 100644 --- a/src/loader/theme.cpp +++ b/src/loader/theme.cpp @@ -37,7 +37,8 @@ Theme::Theme(const QString& lua_file) , m_context() , m_lua_loader(&m_context) { - m_lua_loader.runFile(m_file.toAscii().constData()); + std::cout << "******** LOADING " << m_file << " ***********" << std::endl; + m_lua_loader.runFile(qPrintable(m_file)); if(m_lua_loader.error()) ERROR("Script load error: " << std::endl << m_lua_loader.errorString()); diff --git a/src/luaapi/loader.h b/src/luaapi/loader.h index da5bdbd..a98697d 100644 --- a/src/luaapi/loader.h +++ b/src/luaapi/loader.h @@ -67,9 +67,9 @@ public: template T getValue(const QString& key, int size = 0, const LuaValueMap* args = NULL, bool allow_nil = false); - bool error(){ return m_error; } - void clearError(){ m_error = false; } - QString errorString(){ return m_error_string; } + bool error() { return m_error; } + void clearError() { m_error = false; } + QString errorString() { return m_error_string; } QDir currDir() { return m_curr_dir; } }; diff --git a/src/pref_theme.cpp b/src/pref_theme.cpp index 6869ff4..7912950 100644 --- a/src/pref_theme.cpp +++ b/src/pref_theme.cpp @@ -12,17 +12,53 @@ #include #include #include -#include + +#include +#include + #include "mastersettings.h" #include "luaapi/loader.h" #include "variants/variants.h" #include "tagua.h" #include "pref_theme.h" +class InvalidTheme { }; + +void PrefTheme::read_theme_info(PrefTheme::ThemeInfo& info, const QString& desktopFile) { + std::cout << "reading desktop file " << desktopFile << std::endl; + if (!KDesktopFile::isDesktopFile(desktopFile)) { + return; + } + + KDesktopFile theme(desktopFile); + KConfigGroup themeData = theme.desktopGroup(); + + info.name = theme.readName(); + info.description = theme.readComment(); + info.description.replace("|", "\n"); + info.variants = themeData.readEntry("X-Tagua-Variants").split(QRegExp("\\s*,\\s*")); + info.file_name = themeData.readEntry("X-Tagua-Script"); + if (info.file_name.isEmpty()) { + // use a file with the same name as the .desktop, but with as .lua extension + info.file_name = desktopFile; + info.file_name.replace(QRegExp("\\.desktop$"), ".lua"); + } + else { + QFileInfo filePath(info.file_name); + QFileInfo desktopPath(desktopFile); + if (!filePath.isAbsolute()) { + // the file is relative to the .desktop directory + info.file_name = QDir(desktopPath.path()).filePath(info.file_name); + } + } + + std::cout << "THEME FOUND: variants = " << info.variants.join("\n") << std::endl; +} PrefTheme::ThemeInfoList PrefTheme::to_theme_info_list(const QStringList& files, const Settings& s) { + std::cout << "about to examine " << files.size() << " desktop files" << std::endl; std::map cache; - + SettingArray themes = s.group("themes").array("theme"); foreach (Settings s_theme, themes) { QStringList variants; @@ -41,44 +77,28 @@ PrefTheme::ThemeInfoList PrefTheme::to_theme_info_list(const QStringList& files, ThemeInfoList allluafiles; ThemeInfoList retv; bool updated = false; - for(int i=0;i::iterator it = cache.find(files[i]); - if(it != cache.end() && it->second.last_modified == lm) { - if(!it->second.name.isEmpty()) + if (it != cache.end() && it->second.last_modified == lm) { + std::cout << "found " << it->second.name << " in the cache" << std::endl; + if (!it->second.name.isEmpty()) retv << it->second; } else { updated = true; - LuaApi::Loader l(NULL); - l.runFile(files[i]); - - { - if(l.error()) - goto fail; - - QString name = l.getValue("name"); - if(name.isEmpty() || l.error()) - goto fail; - - QString description = l.getValue("description"); - if(l.error()) - goto fail; - - QStringList variants = l.getValue("variants"); - if(l.error()) - goto fail; - - ThemeInfo t(files[i], name, description, variants, lm); - retv << t; - allluafiles << t; - continue; + + ThemeInfo info; + info.last_modified = lm; + read_theme_info(info, files[i]); + retv << info; + allluafiles << info; + + if (info.name.isEmpty()) { + ERROR("No name property in " << files[i]); } - fail: - allluafiles << ThemeInfo(files[i], QString(), QString(), QStringList(), lm ); - ERROR("Loading " << files[i] << std::endl - << l.errorString()); } } @@ -100,7 +120,7 @@ PrefTheme::ThemeInfoList PrefTheme::to_theme_info_list(const QStringList& files, s_theme["last-modified"] = allluafiles[i].last_modified.toString(); } } - + return retv; } @@ -159,7 +179,7 @@ PrefTheme::PrefTheme(QWidget *parent) c->m_opt_layout->setMargin(0); c->m_themes = to_theme_info_list( - KGlobal::dirs()->findAllResources("appdata", "themes/"+cit->first+"/*.lua", KStandardDirs::Recursive), + KGlobal::dirs()->findAllResources("appdata", "themes/"+cit->first+"/*.desktop", KStandardDirs::Recursive), s.group(cit->first) ); } @@ -291,8 +311,9 @@ QString PrefTheme::getBestTheme(VariantInfo* vi, const QString& category) { MasterSettings s(".tagua_config_cache.xml"); KStandardDirs* dirs = KGlobal::dirs(); - ThemeInfoList themes = to_theme_info_list(dirs->findAllResources("appdata", "themes/"+category+"/*.lua", + ThemeInfoList themes = to_theme_info_list(dirs->findAllResources("appdata", "themes/"+category+"/*.desktop", KStandardDirs::Recursive), s.group(category)); + std::cout << "found " << themes.size() << " themes" << std::endl; int best = 0; QString retv; @@ -302,15 +323,16 @@ QString PrefTheme::getBestTheme(VariantInfo* vi, const QString& category) { ok = themes[i].variants.contains("any[default]", Qt::CaseInsensitive) ? 2 : ok; ok = themes[i].variants.contains(v, Qt::CaseInsensitive) ? 3 : ok; ok = themes[i].variants.contains(v+"[default]", Qt::CaseInsensitive) ? 4 : ok; - if(!ok) + if (!ok) continue; - if(ok > best) { + if (ok > best) { retv = themes[i].file_name; best = ok; } } - + + std::cout << "best theme " << retv << std::endl; if (!retv.isEmpty()) var[tag] = retv; return retv; diff --git a/src/pref_theme.h b/src/pref_theme.h index f6831eb..02da674 100644 --- a/src/pref_theme.h +++ b/src/pref_theme.h @@ -58,7 +58,7 @@ Q_OBJECT static ThemeInfoList to_theme_info_list(const QStringList& files, const Settings& s); static void update_list_view(QListWidget* list, const ThemeInfoList& themes, QString variant, QString settings); - + static void read_theme_info(PrefTheme::ThemeInfo& info, const QString& desktopFile); private slots: void variantChanged(); -- 2.11.4.GIT