From 31cdf5d658a89f1e4810d64098d0642f81eb90e3 Mon Sep 17 00:00:00 2001 From: Noldor Date: Fri, 23 Apr 2010 15:20:42 +0000 Subject: KVS improvements in theme module git-svn-id: https://svn.kvirc.de/svn/trunk/kvirc@4287 17fca916-40b9-46aa-a4ea-0a15b648b75c --- src/modules/theme/libkvitheme.cpp | 84 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) (limited to 'src/modules/theme/libkvitheme.cpp') diff --git a/src/modules/theme/libkvitheme.cpp b/src/modules/theme/libkvitheme.cpp index 1e288548f..4d63bcc68 100644 --- a/src/modules/theme/libkvitheme.cpp +++ b/src/modules/theme/libkvitheme.cpp @@ -25,6 +25,7 @@ #include "managementdialog.h" #include "themefunctions.h" +#include "kvi_msgbox.h" #include "kvi_module.h" #include "kvi_locale.h" #include "kvi_qstring.h" @@ -38,8 +39,10 @@ #include "kvi_sourcesdate.h" #include "kvi_fileutils.h" #include "kvi_filedialog.h" +#include "kvi_theme.h" #include +#include QRect g_rectManagementDialogGeometry(0,0,0,0); @@ -75,6 +78,85 @@ static bool theme_kvs_cmd_install(KviKvsModuleCommandCall * c) return true; } +/* + @doc: theme.apply + @type: + command + @title: + theme.apply + @short: + Apply a theme. + @syntax: + theme.apply + @description: + Attempts to apply the theme specified by . +*/ +static bool theme_kvs_cmd_apply(KviKvsModuleCommandCall * c) +{ + QString szThemePackFile; + + KVSM_PARAMETERS_BEGIN(c) + KVSM_PARAMETER("package_name",KVS_PT_STRING,0,szThemePackFile) + KVSM_PARAMETERS_END(c) + QString szDir; + g_pApp->getLocalKvircDirectory(szDir,KviApp::Themes); + szDir += KVI_PATH_SEPARATOR_CHAR; + szDir += szThemePackFile; + KviThemeInfo * themeInfo = new KviThemeInfo(); + if(themeInfo->loadFromDirectory(szDir)) + { + themeInfo->setSubdirectory(szThemePackFile); + if(KviMessageBox::yesNo(__tr2qs_ctx("Apply theme - KVIrc","theme"), + __tr2qs_ctx("Do you wish to apply theme \"%Q\" (version %Q)?","theme"), + &(themeInfo->name()),&(themeInfo->version()))) + { + QString szPath = themeInfo->absoluteDirectory(); + if(szPath.isEmpty())return true; + + KviThemeInfo out; + + if(!KviTheme::load(szPath,out)) + { + QString szErr = out.lastError(); + QString szMsg; + KviQString::sprintf(szMsg,__tr2qs_ctx("Failed to apply the specified theme: %Q","theme"),&szErr); + QMessageBox::critical(0,__tr2qs_ctx("Apply theme - KVIrc","theme"),szMsg, + QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton); + } + } + } + c->warning(__tr2qs_ctx("The theme package %Q does not exists","theme"),&szThemePackFile); + return true; +} +/* + @doc: theme.list + @type: + function + @title: + theme.list + @short: + Return a list of the installed themes. + @syntax: + $theme.list + @description: + Returns a comma separated string list of the KVIrc installed themes. +*/ +static bool theme_kvs_fnc_list(KviKvsModuleFunctionCall * c) +{ + QString szDir; + g_pApp->getLocalKvircDirectory(szDir,KviApp::Themes); + QDir d(szDir); + QStringList sl = d.entryList(QDir::Dirs); + QStringList szThemes; + for(QStringList::Iterator it = sl.begin();it != sl.end();++it) + { + if(*it == ".")continue; + if(*it == "..")continue; + szThemes.append(*it); + } + c->returnValue()->setString(szThemes.join(",")); + return true; +} /* @doc: theme.screenshot @@ -152,8 +234,10 @@ static bool theme_module_init(KviModule *m) { KVSM_REGISTER_SIMPLE_COMMAND(m,"dialog",theme_kvs_cmd_dialog); KVSM_REGISTER_SIMPLE_COMMAND(m,"install",theme_kvs_cmd_install); + KVSM_REGISTER_SIMPLE_COMMAND(m,"apply",theme_kvs_cmd_apply); KVSM_REGISTER_SIMPLE_COMMAND(m,"screenshot",theme_kvs_cmd_screenshot); + KVSM_REGISTER_FUNCTION(m,"list",theme_kvs_fnc_list); QString szBuf; m->getDefaultConfigFileName(szBuf); KviConfig cfg(szBuf,KviConfig::Read); -- cgit v1.3.1-10-gc9f91