aboutsummaryrefslogtreecommitdiffstats
path: root/src/modules
diff options
context:
space:
mode:
authorGravatar Szymon Tomasz Stefanek2015-08-27 04:16:03 +0200
committerGravatar Szymon Tomasz Stefanek2015-08-27 04:16:03 +0200
commitb59a43f57ecc290d6798a29402256c169f5b1bd2 (patch)
tree33a115a647c2a8acdf38181026b141407dc12ffd /src/modules
parentMerge branch 'master' of https://github.com/kvirc/KVIrc (diff)
downloadKVIrc-b59a43f57ecc290d6798a29402256c169f5b1bd2.tar.gz
KVIrc-b59a43f57ecc290d6798a29402256c169f5b1bd2.tar.bz2
KVIrc-b59a43f57ecc290d6798a29402256c169f5b1bd2.zip
More work on theme packing
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/theme/SaveThemeDialog.cpp6
-rw-r--r--src/modules/theme/ThemeFunctions.cpp19
-rw-r--r--src/modules/theme/WebThemeInterfaceDialog.cpp7
-rw-r--r--src/modules/theme/libkvitheme.cpp34
4 files changed, 54 insertions, 12 deletions
diff --git a/src/modules/theme/SaveThemeDialog.cpp b/src/modules/theme/SaveThemeDialog.cpp
index df3d38a49..01d29d15e 100644
--- a/src/modules/theme/SaveThemeDialog.cpp
+++ b/src/modules/theme/SaveThemeDialog.cpp
@@ -249,10 +249,11 @@ bool SaveThemeDialog::saveTheme()
sto.setVersion(m_pThemeVersionEdit->text());
sto.setApplication("KVIrc " KVI_VERSION "." KVI_SOURCES_DATE);
- if(sto.version().isEmpty())sto.setVersion("1.0.0");
+ if(sto.version().isEmpty())
+ sto.setVersion("1.0.0");
QString szSubdir = sto.name() + QString("-") + sto.version();
- szSubdir.replace(QRegExp("[ \\\\/:][ \\\\/:]*"),"_");
+ szSubdir.replace(QRegExp("[^a-zA-Z0-9_\\-.][^a-zA-Z0-9_\\-.]*"),"_");
sto.setDirectoryAndLocation(szSubdir,KviThemeInfo::User);
QString szAbsDir = sto.directory();
@@ -291,3 +292,4 @@ bool SaveThemeDialog::saveTheme()
return true;
}
+
diff --git a/src/modules/theme/ThemeFunctions.cpp b/src/modules/theme/ThemeFunctions.cpp
index d4b349be4..ecd2c880a 100644
--- a/src/modules/theme/ThemeFunctions.cpp
+++ b/src/modules/theme/ThemeFunctions.cpp
@@ -402,7 +402,6 @@ namespace ThemeFunctions
QString &szError
)
{
-
if(szPackagePath.isEmpty())
{
szError = __tr2qs_ctx("Invalid empty package path","theme");
@@ -463,6 +462,20 @@ namespace ThemeFunctions
int iIdx = 0;
for(KviThemeInfo * pInfo = lThemeInfoList.first();pInfo;pInfo = lThemeInfoList.next())
{
+ if(pInfo->name().isEmpty())
+ {
+ szError = __tr2qs_ctx("Invalid theme name","theme");
+ return false;
+ }
+ if(pInfo->version().isEmpty())
+ {
+ szError = __tr2qs_ctx("Invalid theme version","theme");
+ return false;
+ }
+
+ QString szSubdir = pInfo->name() + QString("-") + pInfo->version();
+ szSubdir.replace(QRegExp("[^a-zA-Z0-9_\\-.][^a-zA-Z0-9_\\-.]*"),"_");
+
szTmp = QString("Theme%1Name").arg(iIdx);
f.addInfoField(szTmp,pInfo->name());
szTmp = QString("Theme%1Version").arg(iIdx);
@@ -472,7 +485,7 @@ namespace ThemeFunctions
szTmp = QString("Theme%1Date").arg(iIdx);
f.addInfoField(szTmp,pInfo->date());
szTmp = QString("Theme%1Subdirectory").arg(iIdx);
- f.addInfoField(szTmp,pInfo->subdirectory());
+ f.addInfoField(szTmp,szSubdir);
szTmp = QString("Theme%1Author").arg(iIdx);
f.addInfoField(szTmp,pInfo->author());
szTmp = QString("Theme%1Application").arg(iIdx);
@@ -492,7 +505,7 @@ namespace ThemeFunctions
f.addInfoField(szTmp,pba);
}
- if(!f.addDirectory(pInfo->directory(),pInfo->subdirectory()))
+ if(!f.addDirectory(pInfo->directory(),szSubdir))
{
szError = __tr2qs_ctx("Packaging failed","theme");
szError += ": ";
diff --git a/src/modules/theme/WebThemeInterfaceDialog.cpp b/src/modules/theme/WebThemeInterfaceDialog.cpp
index 4c0345793..ceb4e9ca0 100644
--- a/src/modules/theme/WebThemeInterfaceDialog.cpp
+++ b/src/modules/theme/WebThemeInterfaceDialog.cpp
@@ -65,9 +65,12 @@ bool WebThemeInterfaceDialog::installPackage(const QString &szPath,QString &szEr
bool WebThemeInterfaceDialog::packageIsInstalled(const QString &szId,const QString &szVersion)
{
+ QString szSubdir = szId + QString("-") + szVersion;
+ szSubdir.replace(QRegExp("[^a-zA-Z0-9_\\-.][^a-zA-Z0-9_\\-.]*"),"_");
+
return \
- KviFileUtils::fileExists(m_szGlobalThemesPath+szId+"-"+szVersion) || \
- KviFileUtils::fileExists(m_szLocalThemesPath+szId+"-"+szVersion);
+ KviFileUtils::fileExists(m_szGlobalThemesPath+szSubdir) || \
+ KviFileUtils::fileExists(m_szLocalThemesPath+szSubdir);
}
diff --git a/src/modules/theme/libkvitheme.cpp b/src/modules/theme/libkvitheme.cpp
index 206846dbc..46b8d671c 100644
--- a/src/modules/theme/libkvitheme.cpp
+++ b/src/modules/theme/libkvitheme.cpp
@@ -25,6 +25,7 @@
#include "ThemeManagementDialog.h"
#include "ThemeFunctions.h"
+#include "KviKvsArrayCast.h"
#include "KviMessageBox.h"
#include "KviModule.h"
#include "KviLocale.h"
@@ -267,7 +268,7 @@ static bool theme_kvs_cmd_dialog(KviKvsModuleCommandCall *c)
@short:
Creates a kvt package containing a set of themes
@syntax:
- theme.pack <package_path> <package_name> <package_version> <package_description> <package_author> <package_image> <theme_path> [<theme_path> [<theme_path>... ]]
+ theme.pack <package_path> <package_name> <package_version> <package_description> <package_author> <package_image> <themes>
@description:
Creates a *.kvt package containing a set of KVIrc themes.[br]
<package_path> is the absolute path and file name of the package that should be saved.[br]
@@ -278,13 +279,14 @@ static bool theme_kvs_cmd_dialog(KviKvsModuleCommandCall *c)
<package_image> is the path of an image to be used as package rappresentative image. If the package is going
to contain a single theme you may specify the theme's screenshot here. Pass an empty string if you
don't want an image to be stored in the package.
- <theme_path> is a path to a directory containing a theme as it's exported by kvirc,
- may be repeated more than once to pack multiple themes within a single package.
+ <theme> is a either a single path to a directory containing a theme as it's exported by kvirc,
+ or an array of such paths.
*/
static bool theme_kvs_cmd_pack(KviKvsModuleCommandCall * c)
{
QString szPath,szName,szVersion,szDescription,szAuthor,szImage;
- QStringList lThemeList;
+
+ KviKvsArrayCast aCast;
KVSM_PARAMETERS_BEGIN(c)
KVSM_PARAMETER("package_path",KVS_PT_NONEMPTYSTRING,0,szPath)
@@ -293,9 +295,31 @@ static bool theme_kvs_cmd_pack(KviKvsModuleCommandCall * c)
KVSM_PARAMETER("package_description",KVS_PT_STRING,0,szDescription)
KVSM_PARAMETER("package_author",KVS_PT_NONEMPTYSTRING,0,szAuthor)
KVSM_PARAMETER("package_image",KVS_PT_STRING,0,szImage)
- KVSM_PARAMETER("theme",KVS_PT_STRINGLIST,0,lThemeList)
+ KVSM_PARAMETER("theme",KVS_PT_ARRAYCAST,0,aCast)
KVSM_PARAMETERS_END(c)
+ KviKvsArray * pArray = aCast.array();
+ if((!pArray) || (pArray->size() < 1))
+ {
+ c->error(__tr2qs_ctx("No themes specified","theme"));
+ return false;
+ }
+
+ kvs_uint_t s = pArray->size();
+ QStringList lThemeList;
+
+ for(kvs_uint_t i=0;i<s;i++)
+ {
+ KviKvsVariant * v = pArray->at(i);
+ if(!v)
+ continue; // ?
+ QString szVal;
+ v->asString(szVal);
+ if(szVal.isEmpty())
+ continue;
+ lThemeList.append(szVal);
+ }
+
KviPointerList<KviThemeInfo> lThemeInfoList;
lThemeInfoList.setAutoDelete(true);