diff options
| author | 2015-08-27 02:45:18 +0200 | |
|---|---|---|
| committer | 2015-08-27 02:45:18 +0200 | |
| commit | 238e4dfe754ea003cacca06a94d443e381b9c857 (patch) | |
| tree | 722eca44f0e99d252db06ef87288ce84ef2bda3f | |
| parent | Use the 'bug' icon for bug reporting menu entry (diff) | |
| download | KVIrc-238e4dfe754ea003cacca06a94d443e381b9c857.tar.gz KVIrc-238e4dfe754ea003cacca06a94d443e381b9c857.tar.bz2 KVIrc-238e4dfe754ea003cacca06a94d443e381b9c857.zip | |
Rework the theme management a bit
| -rw-r--r-- | src/kvirc/kernel/KviOptions.cpp | 14 | ||||
| -rw-r--r-- | src/kvirc/kernel/KviTheme.cpp | 118 | ||||
| -rw-r--r-- | src/kvirc/kernel/KviTheme.h | 84 | ||||
| -rw-r--r-- | src/kvirc/ui/KviWebPackageManagementDialog.cpp | 6 | ||||
| -rw-r--r-- | src/modules/setup/libkvisetup.cpp | 4 | ||||
| -rw-r--r-- | src/modules/theme/PackThemeDialog.cpp | 147 | ||||
| -rw-r--r-- | src/modules/theme/SaveThemeDialog.cpp | 30 | ||||
| -rw-r--r-- | src/modules/theme/ThemeFunctions.cpp | 131 | ||||
| -rw-r--r-- | src/modules/theme/ThemeFunctions.h | 16 | ||||
| -rw-r--r-- | src/modules/theme/ThemeManagementDialog.cpp | 56 | ||||
| -rw-r--r-- | src/modules/theme/libkvitheme.cpp | 208 |
11 files changed, 498 insertions, 316 deletions
diff --git a/src/kvirc/kernel/KviOptions.cpp b/src/kvirc/kernel/KviOptions.cpp index e48d3730b..8b0070adb 100644 --- a/src/kvirc/kernel/KviOptions.cpp +++ b/src/kvirc/kernel/KviOptions.cpp @@ -1032,8 +1032,7 @@ namespace KviTheme // that are implemented here for convenience (in saving the options) bool save(KviThemeInfo &options) { - QString szThemeDirPath; - options.getCompleteDirPath(szThemeDirPath); + QString szThemeDirPath = options.directory(); if(szThemeDirPath.isEmpty()) { @@ -1050,7 +1049,6 @@ namespace KviTheme } } - if(!options.save(szThemeDirPath+KVI_THEMEINFO_FILE_NAME)) { return false; @@ -1157,17 +1155,17 @@ namespace KviTheme return true; } - bool load(const QString &szThemeDir,KviThemeInfo &buffer,bool bBuiltin) + bool apply(const QString &szThemeDir,KviThemeInfo::Location eLocation,KviThemeInfo &buffer) { //qDebug("Loading and apply theme"); - if(!buffer.load(szThemeDir,bBuiltin)) + if(!buffer.load(szThemeDir,eLocation)) { - qDebug("data does not exist in theme dir %s",szThemeDir.toUtf8().data()); + qDebug("data does not exist in theme dir %s at location %d",szThemeDir.toUtf8().data(),eLocation); return false; // makes sure that themedata exists too } - QString szThemeDirPath; - buffer.getCompleteDirPath(szThemeDirPath); + QString szThemeDirPath = buffer.directory(); + //qDebug("Ok loading from %s",szThemeDirPath.toUtf8().data()); // reset the current theme subdir KVI_OPTION_STRING(KviOption_stringIconThemeSubdir) = ""; diff --git a/src/kvirc/kernel/KviTheme.cpp b/src/kvirc/kernel/KviTheme.cpp index c228e9108..4bee98a03 100644 --- a/src/kvirc/kernel/KviTheme.cpp +++ b/src/kvirc/kernel/KviTheme.cpp @@ -45,25 +45,68 @@ KviThemeInfo::KviThemeInfo() : KviHeapObject() { - m_bBuiltin = false; } KviThemeInfo::~KviThemeInfo() { } +void KviThemeInfo::setDirectoryAndLocation(const QString &szDirectory,Location eLocation) +{ + switch(eLocation) + { + case Auto: + g_pApp->getLocalKvircDirectory(m_szDirectory,KviApplication::Themes,szDirectory); + if(KviFileUtils::directoryExists(m_szDirectory)) + { + m_eLocation = User; + } else { + g_pApp->getGlobalKvircDirectory(m_szDirectory,KviApplication::Themes,szDirectory); + if(KviFileUtils::directoryExists(m_szDirectory)) + { + m_eLocation = Builtin; + } else { + m_eLocation = External; + m_szDirectory = szDirectory; + m_szSubdirectory = KviFileUtils::extractFileName(szDirectory); + } + } + break; + case Builtin: + m_eLocation = eLocation; + m_szSubdirectory = szDirectory; + g_pApp->getGlobalKvircDirectory(m_szDirectory,KviApplication::Themes,m_szSubdirectory); + break; + case User: + m_eLocation = eLocation; + m_szSubdirectory = szDirectory; + g_pApp->getLocalKvircDirectory(m_szDirectory,KviApplication::Themes,m_szSubdirectory); + break; + default: // assume external + { + m_eLocation = External; + m_szDirectory = szDirectory; + m_szSubdirectory = KviFileUtils::extractFileName(szDirectory); + } + break; + } + KviQString::ensureLastCharIs(m_szDirectory,QChar(KVI_PATH_SEPARATOR_CHAR)); -bool KviThemeInfo::load(const QString &szThemeFileName,bool bBuiltin) -{ - m_bBuiltin = bBuiltin; - m_szSubdirectory = szThemeFileName; + //qDebug( + // "[KviTheme::setDirectoryAndLocation] Directory(%s), Subdirectory(%s), Location(%d)", + // m_szDirectory.toUtf8().data(), + // m_szSubdirectory.toUtf8().data(), + // m_eLocation + // ); +} - QString szThemePath; - getCompleteDirPath(szThemePath); +bool KviThemeInfo::load(const QString &szDirectory,Location eLocation) +{ + setDirectoryAndLocation(szDirectory,eLocation); - QString szThemeInfoFileName = szThemePath + KVI_THEMEINFO_FILE_NAME; - QString szThemeDataFileName = szThemePath + KVI_THEMEDATA_FILE_NAME; + QString szThemeInfoFileName = m_szDirectory + KVI_THEMEINFO_FILE_NAME; + QString szThemeDataFileName = m_szDirectory + KVI_THEMEDATA_FILE_NAME; if(!KviFileUtils::fileExists(szThemeInfoFileName)) { @@ -77,7 +120,6 @@ bool KviThemeInfo::load(const QString &szThemeFileName,bool bBuiltin) return false; } - KviConfigurationFile cfg(szThemeInfoFileName,KviConfigurationFile::Read); cfg.setGroup(KVI_THEMEINFO_CONFIG_GROUP); @@ -114,11 +156,14 @@ bool KviThemeInfo::load(const QString &szThemeFileName,bool bBuiltin) if(m_szApplication.isEmpty()) m_szApplication = szUnknown; - m_szDirName = szThemeFileName; + //qDebug( + // "[KviTheme::load] Directory(%s), Subdirectory(%s), Location(%d)", + // m_szDirectory.toUtf8().data(), + // m_szSubdirectory.toUtf8().data(), + // m_eLocation + // ); return true; - - } bool KviThemeInfo::save(const QString &szThemeFileName) @@ -143,18 +188,17 @@ bool KviThemeInfo::save(const QString &szThemeFileName) QString KviThemeInfo::smallScreenshotPath() { - QString szRet; - getCompleteDirPath(szRet); + QString szRet = m_szDirectory; szRet.append(KVI_THEME_SMALL_SCREENSHOT_NAME); return szRet; } const QPixmap & KviThemeInfo::smallScreenshot() { - if(!m_pixScreenshotSmall.isNull())return m_pixScreenshotSmall; + if(!m_pixScreenshotSmall.isNull()) + return m_pixScreenshotSmall; - QString szFileName; - getCompleteDirPath(szFileName); + QString szFileName = m_szDirectory; szFileName.append(KVI_THEME_SMALL_SCREENSHOT_NAME); QPixmap pix(szFileName); if(!pix.isNull()) @@ -179,10 +223,10 @@ const QPixmap & KviThemeInfo::smallScreenshot() const QPixmap & KviThemeInfo::mediumScreenshot() { - if(!m_pixScreenshotMedium.isNull())return m_pixScreenshotMedium; + if(!m_pixScreenshotMedium.isNull()) + return m_pixScreenshotMedium; - QString szFileName; - getCompleteDirPath(szFileName); + QString szFileName = m_szDirectory; szFileName.append(KVI_THEME_MEDIUM_SCREENSHOT_NAME); QPixmap pix(szFileName); if(!pix.isNull()) @@ -206,10 +250,10 @@ const QPixmap & KviThemeInfo::mediumScreenshot() const QPixmap & KviThemeInfo::largeScreenshot() { - if(!m_pixScreenshotLarge.isNull())return m_pixScreenshotLarge; + if(!m_pixScreenshotLarge.isNull()) + return m_pixScreenshotLarge; - QString szFileName; - getCompleteDirPath(szFileName); + QString szFileName = m_szDirectory; szFileName.append(KVI_THEME_LARGE_SCREENSHOT_NAME); QPixmap pix(szFileName); if(pix.isNull())return m_pixScreenshotLarge; @@ -231,8 +275,8 @@ namespace KviTheme QImage out; - QString szScreenshotPath; - options.getCompleteDirPath(szScreenshotPath); + QString szScreenshotPath = options.directory(); + if(szScreenshotPath.isEmpty()) { options.setLastError(__tr2qs("Invalid option")); @@ -270,18 +314,26 @@ namespace KviTheme return true; } - void installedThemes(QStringList &slThemes,bool bBuiltin) + void installedThemeDirectories(QStringList &slThemes,KviThemeInfo::Location eLocation) { QString szThemePath; - if(bBuiltin) - g_pApp->getGlobalKvircDirectory(szThemePath,KviApplication::Themes); - else - g_pApp->getLocalKvircDirectory(szThemePath,KviApplication::Themes); + switch(eLocation) + { + case KviThemeInfo::Builtin: + g_pApp->getGlobalKvircDirectory(szThemePath,KviApplication::Themes); + break; + case KviThemeInfo::User: + g_pApp->getLocalKvircDirectory(szThemePath,KviApplication::Themes); + break; + default: + return; + break; + } + QDir d(szThemePath); QStringList sl = d.entryList(QDir::Dirs | QDir::NoDotAndDotDot); + for(QStringList::Iterator it = sl.begin();it != sl.end();++it) - { slThemes.append(*it); - } } }; diff --git a/src/kvirc/kernel/KviTheme.h b/src/kvirc/kernel/KviTheme.h index bb4972ddc..c93d58512 100644 --- a/src/kvirc/kernel/KviTheme.h +++ b/src/kvirc/kernel/KviTheme.h @@ -33,7 +33,7 @@ #include "KviFileUtils.h" #include <QPixmap> -#define BUILTIN 1 + #define KVI_THEMEINFO_FILE_NAME "themeinfo" KVI_FILEEXTENSION_CONFIG #define KVI_THEMEDATA_FILE_NAME "themedata" KVI_FILEEXTENSION_CONFIG #define KVI_THEMEINFO_CONFIG_GROUP "ThemeInfo" @@ -60,11 +60,34 @@ class KVIRC_API KviThemeInfo : public KviHeapObject public: KviThemeInfo(); ~KviThemeInfo(); +public: + enum Location + { + /// + /// Theme is a builtin theme. The subdirectory is inside the kvirc global theme directory. + /// + Builtin = 0, + /// + /// Theme is an user theme. The subdirectory is inside the kvirc local theme directory. + /// + User = 1, + /// + /// Theme is an external theme. The subdirectory is somewhere on the filesystem. + /// + External = 3, + /// + /// Automatically determine location + /// + Auto = 4 + }; protected: QString m_szName; //< name of the theme QString m_szVersion; //< version of the theme - QString m_szSubdirectory; //< subdirectory of $LOCALKVIRCDIR/themes where the theme is saved to (not always used) - QString m_szDirName; //< directory where the theme should be saved to (or is loaded from) + + QString m_szDirectory; //< the absolute directory of the theme + QString m_szSubdirectory; //< the last component of m_szDirectory (this is needed when the theme is installed) + Location m_eLocation; //< the location of the theme + QString m_szAuthor; //< author of the theme QString m_szDescription; //< description of the theme QString m_szDate; //< theme creation date @@ -77,32 +100,49 @@ protected: QPixmap m_pixScreenshotMedium; //< the medium screenshot pixmap QPixmap m_pixScreenshotSmall; //< the small screenshot pixmap - bool m_bBuiltin; //< bool is a builtin theme public: /// - /// load data from a specified theme config file + /// Load theme data from the specified location. + /// If eLocation is Builtin then szThemeDirectory is assumed to be a subdirectory of the kvirc global theme directory. + /// If eLocation is User then szThemeDirectory is assumed to be a subdirectory of the kvirc local theme directory. + /// If eLocation is External the szThemeDirectory is assumed to be a full path to a theme directory. /// - bool load(const QString &szThemeFileName,bool bBuiltin=false); + bool load(const QString &szDirectory,Location eLocation); + /// /// save the currently defined theme configuration in the specified file /// bool save(const QString &szThemeFileName); - bool isBuiltin(){return m_bBuiltin;} + const QString & lastError(){ return m_szLastError; } void setLastError(const QString &szLastError){ m_szLastError = szLastError; } const QString & name(){ return m_szName; } void setName(const QString &szName){ m_szName = szName; } const QString & version(){ return m_szVersion; } void setVersion(const QString &szVersion){ m_szVersion = szVersion; } - const QString & subdirectory(){ return m_szSubdirectory; } - void setSubdirectory(const QString &szSubdirectory){ m_szSubdirectory = szSubdirectory; } - void getCompleteDirPath(QString &szBuffer) + + const QString & directory() const + { + return m_szDirectory; + } + + const QString & subdirectory() const { - if(m_bBuiltin) g_pApp->getGlobalKvircDirectory(szBuffer,KviApplication::Themes,m_szSubdirectory); - else g_pApp->getLocalKvircDirectory(szBuffer,KviApplication::Themes,m_szSubdirectory); - KviQString::ensureLastCharIs(szBuffer,QChar(KVI_PATH_SEPARATOR_CHAR)); + return m_szSubdirectory; } - const QString & dirName(){ return m_szDirName; } + + Location location() const + { + return m_eLocation; + } + + void setDirectoryAndLocation(const QString &szDirectory,Location eLocation); + + bool isBuiltin() + { + return m_eLocation == KviThemeInfo::Builtin; + } + const QString & author(){ return m_szAuthor; } void setAuthor(const QString &szAuthor){ m_szAuthor = szAuthor; } const QString & description(){ return m_szDescription; } @@ -139,18 +179,24 @@ public: /// has been set, otherwise the returned pixmap will be null. /// QString smallScreenshotPath(); + + }; namespace KviTheme { /// - /// Attempt to load (apply) a theme from globaldir::theme (bBuiltin=true) or from localdir::theme. + /// Attempt to load and apply a theme. + /// If eLocation is Builtin then szThemeDirectory is assumed to be a subdirectory of the kvirc global theme directory. + /// If eLocation is User then szThemeDirectory is assumed to be a subdirectory of the kvirc local theme directory. + /// If eLocation is External the szThemeDirectory is assumed to be a full path to a theme directory. /// Will return true on success and false on failure. /// On success this function will return the theme information in the buffer. /// On failure this function will also set buffer.lastError() to a meaningful value /// Note that for convenience this function is implemented in KviOptions.cpp /// - bool KVIRC_API load(const QString &szThemeName,KviThemeInfo &buffer,bool bBuiltin=false); + bool KVIRC_API apply(const QString &szThemeDirectory,KviThemeInfo::Location eLocation,KviThemeInfo &buffer); + /// /// Save a theme given the specified options. /// Will return true on success and false on failure. @@ -162,13 +208,17 @@ namespace KviTheme /// Note that for convenience this function is implemented in KviOptions.cpp /// bool KVIRC_API save(KviThemeInfo &options); + /// /// Save the theme screenshots in the given EXISTING directory and given /// an existing screenshot on disk (usually in the tmp directory). /// bool KVIRC_API saveScreenshots(KviThemeInfo &options,const QString &szOriginalScreenshotPath); - void KVIRC_API installedThemes(QStringList &slThemes,bool bBuiltin); + /// + /// List directory names of installed themes. + /// + void KVIRC_API installedThemeDirectories(QStringList &slThemes,KviThemeInfo::Location eLocation); } diff --git a/src/kvirc/ui/KviWebPackageManagementDialog.cpp b/src/kvirc/ui/KviWebPackageManagementDialog.cpp index fd911b191..a1e6fdfa5 100644 --- a/src/kvirc/ui/KviWebPackageManagementDialog.cpp +++ b/src/kvirc/ui/KviWebPackageManagementDialog.cpp @@ -207,14 +207,14 @@ void KviWebPackageManagementDialog::slotDataTransferProgress(qint64 iDone,qint64 { m_pProgressBar->setMaximum(iTotal); m_pProgressBar->setValue(iDone); - m_pProgressBar->setFormat(__tr2qs_ctx("Downloading: %p%","theme")); + m_pProgressBar->setFormat(__tr2qs("Downloading: %p%")); } void KviWebPackageManagementDialog::slotLoadProgress(int iProgress) { m_pProgressBar->setMaximum(100); m_pProgressBar->setValue(iProgress); - m_pProgressBar->setFormat(__tr2qs_ctx("Loading: %p%","theme")); + m_pProgressBar->setFormat(__tr2qs("Loading: %p%")); } void KviWebPackageManagementDialog::slotCommandFinished() @@ -254,7 +254,7 @@ void KviWebPackageManagementDialog::slotCommandFinished() } else { //get http status code int httpStatus = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); - KviMessageBox::information(QString("Download failed:%1").arg(reply->errorString())); + KviMessageBox::information(__tr2qs("Download failed: %1").arg(reply->errorString())); } reply->deleteLater(); } diff --git a/src/modules/setup/libkvisetup.cpp b/src/modules/setup/libkvisetup.cpp index 51d5b6ab1..f45bb05a7 100644 --- a/src/modules/setup/libkvisetup.cpp +++ b/src/modules/setup/libkvisetup.cpp @@ -89,10 +89,10 @@ KVIMODULEEXPORTFUNC void setup_finish() switch(g_iThemeToApply) { case THEME_APPLY_HIRES: - KviTheme::load("Aria-1.0.0",out,BUILTIN); + KviTheme::apply("Aria-1.0.0",KviThemeInfo::Builtin,out); break; case THEME_APPLY_LORES: - KviTheme::load("MinimalDark-1.0.0",out,BUILTIN); + KviTheme::apply("MinimalDark-1.0.0",KviThemeInfo::Builtin,out); break; // default: no theme } diff --git a/src/modules/theme/PackThemeDialog.cpp b/src/modules/theme/PackThemeDialog.cpp index f113b8ed8..32691a4d1 100644 --- a/src/modules/theme/PackThemeDialog.cpp +++ b/src/modules/theme/PackThemeDialog.cpp @@ -433,145 +433,36 @@ bool PackThemeDialog::packTheme() m_szDescription = field("packageDescription").toString(); m_szImagePath = field("packageImagePath").toString(); m_szPackagePath = field("packageSavePath").toString(); - //m_szSavePath = field("packageSavePath").toString(); - //return false; + QString szError; - QImage pix(m_szImagePath); - QPixmap out; - if(!pix.isNull()) - { - if((pix.width() > 300) || (pix.height() > 225)) - { - out=out.fromImage(pix.scaled(300,225,Qt::KeepAspectRatio)); - } else { - out=out.fromImage(pix); - } - } else { - if(!m_szImagePath.isEmpty()) - { - QMessageBox::critical(this, - __tr2qs_ctx("Export Theme - KVIrc","theme"), - __tr2qs_ctx("Failed to load the selected image: please fix it","theme"), - QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton - ); - //setCurrentPage(m_pImageSelectionPage); - return false; - } - } - - KviPackageWriter f; - - QString szTmp; - QDateTime date = QDateTime::currentDateTime(); - - switch(KVI_OPTION_UINT(KviOption_uintOutputDatetimeFormat)) + if(! + ThemeFunctions::packageThemes( + m_szPackagePath, + m_szName, + m_szVersion, + m_szDescription, + m_szAuthor, + m_szImagePath, + *m_pThemeInfoList, + szError + ) + ) { - case 0: - // this is the equivalent to an empty date.toString() call, but it's needed - // to ensure qt4 will use the default() locale and not the system() one - szTmp = QLocale().toString(date, "ddd MMM d hh:mm:ss yyyy"); - break; - case 1: - szTmp = date.toString(Qt::ISODate); - break; - case 2: - szTmp = date.toString(Qt::SystemLocaleShortDate); - break; - } - - f.addInfoField("PackageType","ThemePack"); - f.addInfoField("ThemePackVersion",KVI_CURRENT_THEME_ENGINE_VERSION); - f.addInfoField("Name",m_szName); - f.addInfoField("Version",m_szVersion); - f.addInfoField("Author",m_szAuthor); - f.addInfoField("Description",m_szDescription); - f.addInfoField("Date",szTmp); - f.addInfoField("Application","KVIrc " KVI_VERSION "." KVI_SOURCES_DATE); - - if(!out.isNull()) - { - QByteArray * pba = new QByteArray(); - QBuffer buffer(pba,0); - buffer.open(QIODevice::WriteOnly); - out.save(&buffer,"PNG"); - buffer.close(); - f.addInfoField("Image",pba); // cool :) [no disk access needed] - } - - szTmp.setNum(m_pThemeInfoList->count()); - f.addInfoField("ThemeCount",szTmp); - - int iIdx = 0; - for(KviThemeInfo * pInfo = m_pThemeInfoList->first(); pInfo; pInfo = m_pThemeInfoList->next()) - { - szTmp = QString("Theme%1Name").arg(iIdx); - f.addInfoField(szTmp,pInfo->name()); - szTmp = QString("Theme%1Version").arg(iIdx); - f.addInfoField(szTmp,pInfo->version()); - szTmp = QString("Theme%1Description").arg(iIdx); - f.addInfoField(szTmp,pInfo->description()); - szTmp = QString("Theme%1Date").arg(iIdx); - f.addInfoField(szTmp,pInfo->date()); - szTmp = QString("Theme%1Subdirectory").arg(iIdx); - f.addInfoField(szTmp,pInfo->subdirectory()); - szTmp = QString("Theme%1Author").arg(iIdx); - f.addInfoField(szTmp,pInfo->author()); - szTmp = QString("Theme%1Application").arg(iIdx); - f.addInfoField(szTmp,pInfo->application()); - szTmp = QString("Theme%1ThemeEngineVersion").arg(iIdx); - f.addInfoField(szTmp,pInfo->themeEngineVersion()); - QPixmap pixScreenshot = pInfo->smallScreenshot(); - if(!pixScreenshot.isNull()) - { - szTmp = QString("Theme%1Screenshot").arg(iIdx); - QByteArray * pba = new QByteArray(); - - QBuffer bufferz(pba,0); - bufferz.open(QIODevice::WriteOnly); - pixScreenshot.save(&bufferz,"PNG"); - bufferz.close(); - f.addInfoField(szTmp,pba); - } - QString szThemePath; - pInfo->getCompleteDirPath(szThemePath); - if(!f.addDirectory(szThemePath,pInfo->subdirectory())) - { - szTmp = __tr2qs_ctx("Packaging failed","theme"); - szTmp += ": "; - szTmp += f.lastError(); - QMessageBox::critical(this, + QMessageBox::critical(this, __tr2qs_ctx("Export Theme - KVIrc","theme"), - szTmp, + szError, QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton - ); - } - - iIdx++; - } - - if(!f.pack(m_szPackagePath)) - { - szTmp = __tr2qs_ctx("Packaging failed","theme"); - szTmp += ": "; - szTmp += f.lastError(); - QMessageBox::critical(this, - __tr2qs_ctx("Export Theme - KVIrc","theme"), - szTmp, - QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton ); - return false; } - //KviPackageReader r; - //r.unpack("/root/test.kvt","/root/unpacked_test_kvt"); - QMessageBox::information(this, - __tr2qs_ctx("Export Theme - KVIrc","theme"), - __tr2qs("Package saved successfully"), - QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton + __tr2qs_ctx("Export Theme - KVIrc","theme"), + __tr2qs("Package saved successfully"), + QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton ); return true; } + diff --git a/src/modules/theme/SaveThemeDialog.cpp b/src/modules/theme/SaveThemeDialog.cpp index adf6fbbd4..df3d38a49 100644 --- a/src/modules/theme/SaveThemeDialog.cpp +++ b/src/modules/theme/SaveThemeDialog.cpp @@ -56,7 +56,6 @@ - SaveThemeDialog::SaveThemeDialog(QWidget * pParent) : KviTalWizard(pParent) { @@ -64,7 +63,7 @@ SaveThemeDialog::SaveThemeDialog(QWidget * pParent) setMinimumSize(400,350); KviThemeInfo info; - info.load(KVI_OPTION_STRING(KviOption_stringIconThemeSubdir)); + info.load(KVI_OPTION_STRING(KviOption_stringIconThemeSubdir),KviThemeInfo::Auto); // welcome page ================================================================================== QWidget * pPage = new QWidget(this); @@ -244,24 +243,9 @@ bool SaveThemeDialog::saveTheme() sto.setAuthor(m_pAuthorNameEdit->text()); sto.setDescription(m_pThemeDescriptionEdit->toPlainText()); - QString szTmp; - QDateTime date = QDateTime::currentDateTime(); - switch(KVI_OPTION_UINT(KviOption_uintOutputDatetimeFormat)) - { - case 0: - // this is the equivalent to an empty date.toString() call, but it's needed - // to ensure qt4 will use the default() locale and not the system() one - szTmp = QLocale().toString(date, "ddd MMM d hh:mm:ss yyyy"); - break; - case 1: - szTmp = date.toString(Qt::ISODate); - break; - case 2: - szTmp = date.toString(Qt::SystemLocaleShortDate); - break; - } - - sto.setDate(szTmp); + // this is the equivalent to an empty date.toString() call, but it's needed + // to ensure qt4 will use the default() locale and not the system() one + sto.setDate(QLocale().toString(QDateTime::currentDateTime(), "ddd MMM d hh:mm:ss yyyy")); sto.setVersion(m_pThemeVersionEdit->text()); sto.setApplication("KVIrc " KVI_VERSION "." KVI_SOURCES_DATE); @@ -269,10 +253,9 @@ bool SaveThemeDialog::saveTheme() QString szSubdir = sto.name() + QString("-") + sto.version(); szSubdir.replace(QRegExp("[ \\\\/:][ \\\\/:]*"),"_"); - sto.setSubdirectory(szSubdir); + sto.setDirectoryAndLocation(szSubdir,KviThemeInfo::User); - QString szAbsDir; - g_pApp->getLocalKvircDirectory(szAbsDir,KviApplication::Themes,sto.subdirectory(),true); + QString szAbsDir = sto.directory(); if(!KviFileUtils::makeDir(szAbsDir)) { QMessageBox::critical(this,__tr2qs_ctx("Save Current Theme - KVIrc","theme"),__tr2qs_ctx("Unable to create theme directory.","theme"), @@ -280,7 +263,6 @@ bool SaveThemeDialog::saveTheme() return false; } - if(!KviTheme::save(sto)) { QString szErr = sto.lastError(); diff --git a/src/modules/theme/ThemeFunctions.cpp b/src/modules/theme/ThemeFunctions.cpp index 271fef739..d4b349be4 100644 --- a/src/modules/theme/ThemeFunctions.cpp +++ b/src/modules/theme/ThemeFunctions.cpp @@ -25,6 +25,7 @@ #include "ThemeFunctions.h" #include "KviPackageReader.h" +#include "KviPackageWriter.h" #include "KviLocale.h" #include "KviMessageBox.h" #include "KviApplication.h" @@ -35,6 +36,12 @@ #include "KviTheme.h" #include "KviMainWindow.h" +#include <QImage> +#include <QPixmap> +#include <QByteArray> +#include <QBuffer> +#include <QDateTime> + //#include <qmime.h> @@ -382,5 +389,129 @@ namespace ThemeFunctions g_pMainWindow->showNormal(); return bResult; } + + + bool packageThemes( + const QString &szPackagePath, + const QString &szPackageName, + const QString &szPackageVersion, + const QString &szPackageDescription, + const QString &szPackageAuthor, + const QString &szPackageImagePath, + KviPointerList<KviThemeInfo> &lThemeInfoList, + QString &szError + ) + { + + if(szPackagePath.isEmpty()) + { + szError = __tr2qs_ctx("Invalid empty package path","theme"); + return false; + } + + if(szPackageName.isEmpty()) + { + szError = __tr2qs_ctx("Invalid empty package name","theme"); + return false; + } + + QPixmap out; + + if(!szPackageImagePath.isEmpty()) + { + QImage pix(szPackageImagePath); + if(pix.isNull()) + { + szError = __tr2qs_ctx("Failed to load the selected image: please fix it","theme"); + return false; + } + + if((pix.width() > 300) || (pix.height() > 225)) + out = out.fromImage(pix.scaled(300,225,Qt::KeepAspectRatio)); + else + out=out.fromImage(pix); + } + + KviPackageWriter f; + + f.addInfoField("PackageType","ThemePack"); + f.addInfoField("ThemePackVersion",KVI_CURRENT_THEME_ENGINE_VERSION); + f.addInfoField("Name",szPackageName); + f.addInfoField("Version",szPackageVersion.isEmpty() ? "1.0.0" : szPackageVersion); + f.addInfoField("Author",szPackageAuthor); + f.addInfoField("Description",szPackageDescription); + // this is the equivalent to an empty date.toString() call, but it's needed + // to ensure qt4 will use the default() locale and not the system() one + f.addInfoField("Date",QLocale().toString(QDateTime::currentDateTime(),"ddd MMM d hh:mm:ss yyyy")); + f.addInfoField("Application","KVIrc " KVI_VERSION "." KVI_SOURCES_DATE); + + if(!out.isNull()) + { + QByteArray * pba = new QByteArray(); + QBuffer buffer(pba,0); + buffer.open(QIODevice::WriteOnly); + out.save(&buffer,"PNG"); + buffer.close(); + f.addInfoField("Image",pba); // cool :) [no disk access needed] + } + + QString szTmp; + + szTmp.setNum(lThemeInfoList.count()); + f.addInfoField("ThemeCount",szTmp); + + int iIdx = 0; + for(KviThemeInfo * pInfo = lThemeInfoList.first();pInfo;pInfo = lThemeInfoList.next()) + { + szTmp = QString("Theme%1Name").arg(iIdx); + f.addInfoField(szTmp,pInfo->name()); + szTmp = QString("Theme%1Version").arg(iIdx); + f.addInfoField(szTmp,pInfo->version()); + szTmp = QString("Theme%1Description").arg(iIdx); + f.addInfoField(szTmp,pInfo->description()); + szTmp = QString("Theme%1Date").arg(iIdx); + f.addInfoField(szTmp,pInfo->date()); + szTmp = QString("Theme%1Subdirectory").arg(iIdx); + f.addInfoField(szTmp,pInfo->subdirectory()); + szTmp = QString("Theme%1Author").arg(iIdx); + f.addInfoField(szTmp,pInfo->author()); + szTmp = QString("Theme%1Application").arg(iIdx); + f.addInfoField(szTmp,pInfo->application()); + szTmp = QString("Theme%1ThemeEngineVersion").arg(iIdx); + f.addInfoField(szTmp,pInfo->themeEngineVersion()); + QPixmap pixScreenshot = pInfo->smallScreenshot(); + if(!pixScreenshot.isNull()) + { + szTmp = QString("Theme%1Screenshot").arg(iIdx); + QByteArray * pba = new QByteArray(); + + QBuffer bufferz(pba,0); + bufferz.open(QIODevice::WriteOnly); + pixScreenshot.save(&bufferz,"PNG"); + bufferz.close(); + f.addInfoField(szTmp,pba); + } + + if(!f.addDirectory(pInfo->directory(),pInfo->subdirectory())) + { + szError = __tr2qs_ctx("Packaging failed","theme"); + szError += ": "; + szError += f.lastError(); + return false; + } + + iIdx++; + } + + if(!f.pack(szPackagePath)) + { + szError = __tr2qs_ctx("Packaging failed","theme"); + szError += ": "; + szError += f.lastError(); + return false; + } + + return true; + } } diff --git a/src/modules/theme/ThemeFunctions.h b/src/modules/theme/ThemeFunctions.h index 08cf1b4b9..630fefda7 100644 --- a/src/modules/theme/ThemeFunctions.h +++ b/src/modules/theme/ThemeFunctions.h @@ -27,6 +27,8 @@ #include "kvi_settings.h" #include "KviQString.h" #include "KviHtmlDialog.h" +#include "KviPointerList.h" +#include "KviTheme.h" #include <QWidget> #include <QPixmap> @@ -34,6 +36,7 @@ namespace ThemeFunctions { bool installThemePackage(const QString &szThemePackageFileName,QString &szError,QWidget * pDialogParent = 0); + void getThemeHtmlDescription( QString &szBuffer, const QString &szThemeName, @@ -47,9 +50,20 @@ namespace ThemeFunctions const QPixmap &pixScreenshot, int iUniqueIndexInDocument = 0, KviHtmlDialogData *hd=0 - ); + bool makeKVIrcScreenshot(const QString &szSavePngFilePath,bool bMaximizeFrame = false); + + bool packageThemes( + const QString &szPackagePath, + const QString &szPackageName, + const QString &szPackageVersion, + const QString &szPackageDescription, + const QString &szPackageAuthor, + const QString &szPackageImagePath, + KviPointerList<KviThemeInfo> &lThemeInfo, + QString &szError + ); } diff --git a/src/modules/theme/ThemeManagementDialog.cpp b/src/modules/theme/ThemeManagementDialog.cpp index a5eb66db8..9e7d3861f 100644 --- a/src/modules/theme/ThemeManagementDialog.cpp +++ b/src/modules/theme/ThemeManagementDialog.cpp @@ -72,10 +72,6 @@ extern QRect g_rectManagementDialogGeometry; -#define BUILTIN_THEMES 1 - -#define USER_DEFINED_THEMES 0 - ThemeListWidgetItem::ThemeListWidgetItem(KviTalListWidget * pBox, KviThemeInfo * pInfo) : KviTalListWidgetItem(pBox) { @@ -333,7 +329,6 @@ void ThemeManagementDialog::contextMenuRequested(const QPoint & pos) KviThemeInfo * pInfo = pItem->themeInfo(); if(!pInfo) return; - QString szDir = pInfo->dirName(); if(!pInfo->isBuiltin()) m_pContextPopup->addAction(*(g_pIconManager->getSmallIcon(KviIconManager::Minus)),__tr2qs_ctx("&Remove Theme","theme"),this,SLOT(deleteTheme())); @@ -353,27 +348,29 @@ void ThemeManagementDialog::applyTheme(QListWidgetItem * it) void ThemeManagementDialog::applyCurrentTheme() { ThemeListWidgetItem * it = (ThemeListWidgetItem *)m_pListWidget->currentItem(); - if(!it)return; + if(!it) + return; - if(KviMessageBox::yesNo(__tr2qs_ctx("Apply theme - KVIrc","theme"), + if(!KviMessageBox::yesNo(__tr2qs_ctx("Apply theme - KVIrc","theme"), __tr2qs_ctx("Do you wish to apply theme \"%Q\" (version %Q)?","theme"), &(it->themeInfo()->name()),&(it->themeInfo()->version()))) - { - QString szPath = it->themeInfo()->dirName(); - if(szPath.isEmpty())return; + return; - KviThemeInfo out; - if(!KviTheme::load(szPath,out,it->themeInfo()->isBuiltin())) - { - QString szErr = out.lastError(); - QString szMsg = QString(__tr2qs_ctx("Failed to apply the specified theme: %1","theme")).arg(szErr); - QMessageBox::critical(this,__tr2qs_ctx("Apply theme - KVIrc","theme"),szMsg, - QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton); + KviThemeInfo out; - } - else m_pCurrentInstalledThemeLabel->setText(__tr2qs_ctx("<b><u>Current Installed Theme:</u> ","theme")+KVI_OPTION_STRING(KviOption_stringIconThemeSubdir)+"</b>"); - m_pItemDelegate->setDefaultIcon(g_pIconManager->getBigIcon(QString(KVI_BIGICON_THEME))); + //qDebug("Apply theme item %x, info %x, %s : %s at location %d",(long)it,(long)it->themeInfo(),it->themeInfo()->directory().toUtf8().data(),it->themeInfo()->subdirectory().toUtf8().data(),it->themeInfo()->location()); + + if(!KviTheme::apply(it->themeInfo()->subdirectory(),it->themeInfo()->location(),out)) + { + QString szErr = out.lastError(); + QString szMsg = QString(__tr2qs_ctx("Failed to apply the specified theme: %1","theme")).arg(szErr); + QMessageBox::critical(this,__tr2qs_ctx("Apply theme - KVIrc","theme"),szMsg, + QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton); + return; } + + m_pCurrentInstalledThemeLabel->setText(__tr2qs_ctx("<b><u>Current Installed Theme:</u> ","theme")+KVI_OPTION_STRING(KviOption_stringIconThemeSubdir)+"</b>"); + m_pItemDelegate->setDefaultIcon(g_pIconManager->getBigIcon(QString(KVI_BIGICON_THEME))); } void ThemeManagementDialog::deleteTheme() @@ -395,8 +392,7 @@ void ThemeManagementDialog::deleteTheme() ) goto jump_out; - QString szThemePath; - ((ThemeListWidgetItem *)itemsSelected.at(i))->themeInfo()->getCompleteDirPath(szThemePath); + QString szThemePath = ((ThemeListWidgetItem *)itemsSelected.at(i))->themeInfo()->directory(); KviFileUtils::deleteDir(szThemePath); } jump_out: @@ -418,11 +414,13 @@ void ThemeManagementDialog::installFromFile() this) ) return; + if(!ThemeFunctions::installThemePackage(szFileName,szError,this)) { KviMessageBox::information(szError); return; } + fillThemeBox(); } @@ -463,15 +461,19 @@ void ThemeManagementDialog::saveCurrentTheme() void ThemeManagementDialog::fillThemeBox(bool bBuiltin) { QStringList slThemes; - KviTheme::installedThemes(slThemes,bBuiltin); + KviTheme::installedThemeDirectories(slThemes,bBuiltin ? KviThemeInfo::Builtin : KviThemeInfo::User); for(int i=0;i<slThemes.count();i++) { + //qDebug("Installed theme %s builtin %d",slThemes.at(i).toUtf8().data(),bBuiltin); + KviThemeInfo * inf = new KviThemeInfo(); - if(inf->load(slThemes.at(i),bBuiltin)) + if(inf->load(slThemes.at(i),bBuiltin ? KviThemeInfo::Builtin : KviThemeInfo::User)) { - inf->setSubdirectory(slThemes.at(i)); ThemeListWidgetItem *it=new ThemeListWidgetItem(m_pListWidget,inf); + + //qDebug("Item %x, info %x, info2 %x, %s : %s at location %d",(long)it,(long)inf,(long)it->themeInfo(),it->themeInfo()->directory().toUtf8().data(),it->themeInfo()->subdirectory().toUtf8().data(),it->themeInfo()->location()); + QPixmap pixmap=inf->smallScreenshot(); if(!pixmap.isNull()) it->setIcon(pixmap.scaled(32,32)); @@ -485,8 +487,8 @@ void ThemeManagementDialog::fillThemeBox() { m_pListWidget->clear(); - fillThemeBox(BUILTIN_THEMES); - fillThemeBox(USER_DEFINED_THEMES); + fillThemeBox(true); + fillThemeBox(false); enableDisableButtons(); } diff --git a/src/modules/theme/libkvitheme.cpp b/src/modules/theme/libkvitheme.cpp index ea9b24cf0..206846dbc 100644 --- a/src/modules/theme/libkvitheme.cpp +++ b/src/modules/theme/libkvitheme.cpp @@ -39,6 +39,7 @@ #include "KviFileUtils.h" #include "KviFileDialog.h" #include "KviTheme.h" +#include "ThemeFunctions.h" #include <QFileInfo> #include <QMessageBox> @@ -77,6 +78,7 @@ static bool theme_kvs_cmd_install(KviKvsModuleCommandCall * c) return true; } + /* @doc: theme.apply @type: @@ -86,39 +88,53 @@ static bool theme_kvs_cmd_install(KviKvsModuleCommandCall * c) @short: Apply a theme. @syntax: - theme.apply <package_name:string> + theme.apply [-b] [-e] [-u] <theme:string> + @switches: + !sw: -e | --external + <theme> is an absolute directory containing a theme + !sw: -b | --builtin + <theme> is the name of a builtin theme (a subdirectory of the kvirc global themes directory) + !sw: -u | --user + <theme> is the name of an user theme (a subdirectory of the kvirc local themes directory) @description: - Attempts to apply the theme specified by <package_name>. + Attempts to apply the global theme specified by <theme>. + If the -b switch is present then <theme> is assumed to be a name of + a builtin installed theme (a subdirectory of the kvirc global themes directory). + If the -l switch is present then <theme> is assumed to be a name of + an user installed theme (a subdirectory of the kvirc local themes directory). + If the -e switch is present then <theme> is assumed to be an absolute + directory containing the theme data. + If no switch is present then kvirc tries to determine automatically the + type of theme (user, builtin or external). */ static bool theme_kvs_cmd_apply(KviKvsModuleCommandCall * c) { - QString szThemePackFile; + QString szTheme; KVSM_PARAMETERS_BEGIN(c) - KVSM_PARAMETER("package_name",KVS_PT_STRING,0,szThemePackFile) + KVSM_PARAMETER("theme",KVS_PT_STRING,0,szTheme) KVSM_PARAMETERS_END(c) - KviThemeInfo * themeInfo = new KviThemeInfo(); - if(themeInfo->load(szThemePackFile)) + + KviThemeInfo out; + KviThemeInfo::Location eLocation = KviThemeInfo::Auto; + + if(c->switches()->find('b',"builtin")) + eLocation = KviThemeInfo::Builtin; + else if(c->switches()->find('e',"external")) + eLocation = KviThemeInfo::External; + else if(c->switches()->find('u',"user")) + eLocation = KviThemeInfo::User; + + if(!KviTheme::apply(szTheme,eLocation,out)) { - 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()))) - { - KviThemeInfo out; - if(!KviTheme::load(szThemePackFile,out)) - { - QString szErr = out.lastError(); - QString szMsg = QString(__tr2qs_ctx("Failed to apply the specified theme: %1","theme")).arg(szErr); - QMessageBox::critical(0,__tr2qs_ctx("Apply theme - KVIrc","theme"),szMsg, - QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton); - } - return true; - } + QString szErr = out.lastError(); + c->error(__tr2qs_ctx("Failed to apply theme: %Q","theme"),&szErr); + return false; } - c->warning(__tr2qs_ctx("The theme package '%Q' does not exist","theme"),&szThemePackFile); + return true; } + /* @doc: theme.info @type: @@ -127,65 +143,31 @@ static bool theme_kvs_cmd_apply(KviKvsModuleCommandCall * c) $theme.info @short: Return info about an user defined theme. - @syntax: - <themes_list:string> $theme.info(<theme_name:string>) @description: - Returns as hash the info about an user definded theme. - Hash keys are: name, version, author, description. + Returns a hash with information about the global theme specified by <theme>. */ static bool theme_kvs_fnc_info(KviKvsModuleFunctionCall * c) { - QString szThemePackFile; + QString szTheme; KVSM_PARAMETERS_BEGIN(c) - KVSM_PARAMETER("package_name",KVS_PT_STRING,0,szThemePackFile) + KVSM_PARAMETER("theme",KVS_PT_STRING,0,szTheme) KVSM_PARAMETERS_END(c) - KviThemeInfo * themeInfo = new KviThemeInfo(); - if(themeInfo->load(szThemePackFile)) + + KviKvsHash *pHash = new KviKvsHash(); + c->returnValue()->setHash(pHash); + + KviThemeInfo theme; + if(!theme.load(szTheme,KviThemeInfo::Auto)) { - KviKvsHash *pHash=new KviKvsHash(); - KviKvsVariant *name=new KviKvsVariant(themeInfo->name()); - pHash->set("name",name); - KviKvsVariant *version=new KviKvsVariant(themeInfo->version()); - pHash->set("version",version); - KviKvsVariant *author=new KviKvsVariant(themeInfo->author()); - pHash->set("author",author); - KviKvsVariant *description=new KviKvsVariant(themeInfo->description()); - pHash->set("description",description); - c->returnValue()->setHash(pHash); + c->warning(__tr2qs_ctx("The theme package '%Q' does not exist","theme"),&szTheme); return true; } - c->warning(__tr2qs_ctx("The theme package '%Q' does not exist","theme"),&szThemePackFile); - return true; -} -/* - @doc: theme.list - @type: - function - @title: - $theme.list - @short: - Return a list of the installed themes. - @syntax: - <themes_list:string> $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,KviApplication::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(",")); + pHash->set("name",new KviKvsVariant(theme.name())); + pHash->set("version",new KviKvsVariant(theme.version())); + pHash->set("author",new KviKvsVariant(theme.author())); + pHash->set("description",new KviKvsVariant(theme.description())); return true; } @@ -213,7 +195,6 @@ static bool theme_kvs_cmd_screenshot(KviKvsModuleCommandCall * c) KVSM_PARAMETER("file_name_path",KVS_PT_STRING,KVS_PF_OPTIONAL,szFileName) KVSM_PARAMETERS_END(c) - KviFileUtils::adjustFilePath(szFileName); QString szTmp; @@ -273,19 +254,100 @@ static bool theme_kvs_cmd_screenshot(KviKvsModuleCommandCall * c) static bool theme_kvs_cmd_dialog(KviKvsModuleCommandCall *c) { - ThemeManagementDialog::display(c->hasSwitch('t',"toplevel")); return true; } +/* + @doc: theme.pack + @type: + command + @title: + theme.pack + @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>... ]] + @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] + <package_name> is the visible name of the package (something like "My Theme Set").[br] + <package_version> is the version of the package in the form X.Y.Z.[br] + <package_description> is a textual description of the package. + <package_author> is the name of the person that is creating the package (NOT necessairly the themes contained within). + <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. +*/ +static bool theme_kvs_cmd_pack(KviKvsModuleCommandCall * c) +{ + QString szPath,szName,szVersion,szDescription,szAuthor,szImage; + QStringList lThemeList; + + KVSM_PARAMETERS_BEGIN(c) + KVSM_PARAMETER("package_path",KVS_PT_NONEMPTYSTRING,0,szPath) + KVSM_PARAMETER("package_name",KVS_PT_NONEMPTYSTRING,0,szName) + KVSM_PARAMETER("package_version",KVS_PT_NONEMPTYSTRING,0,szVersion) + 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_PARAMETERS_END(c) + + KviPointerList<KviThemeInfo> lThemeInfoList; + lThemeInfoList.setAutoDelete(true); + + + Q_FOREACH(QString szTheme,lThemeList) + { + KviThemeInfo * pInfo = new KviThemeInfo(); + if(!pInfo->load(szTheme,KviThemeInfo::External)) + { + QString szErr = pInfo->lastError(); + c->error(__tr2qs_ctx("Failed to load theme from directory %Q: %Q","theme"),&szTheme,&szErr); + delete pInfo; + return false; + } + + lThemeInfoList.append(pInfo); + } + + if(lThemeInfoList.isEmpty()) + { + c->error(__tr2qs_ctx("No themes specified: refusing to create an empty theme package","theme")); + return false; + } + + QString szError; + + if( + ThemeFunctions::packageThemes( + szPath, + szName, + szVersion, + szDescription, + szAuthor, + szImage, + lThemeInfoList, + szError + ) + ) + return true; + + c->error(szError); + return false; +} + 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_SIMPLE_COMMAND(m,"pack",theme_kvs_cmd_pack); - KVSM_REGISTER_FUNCTION(m,"list",theme_kvs_fnc_list); KVSM_REGISTER_FUNCTION(m,"info",theme_kvs_fnc_info); QString szBuf; |
