diff options
| author | 2015-09-15 01:10:11 +0200 | |
|---|---|---|
| committer | 2015-09-15 01:10:11 +0200 | |
| commit | 7337ca5d7f5c35cec949319069f6a3aa6b079d81 (patch) | |
| tree | c86f5c669cac25135099be916120af69b2962413 /src/modules | |
| parent | Add the ability to not store the icons when saving a theme (diff) | |
| download | KVIrc-7337ca5d7f5c35cec949319069f6a3aa6b079d81.tar.gz KVIrc-7337ca5d7f5c35cec949319069f6a3aa6b079d81.tar.bz2 KVIrc-7337ca5d7f5c35cec949319069f6a3aa6b079d81.zip | |
Add addon.pack to package addons manually. Improve addon support.
Diffstat (limited to 'src/modules')
| -rw-r--r-- | src/modules/addon/AddonFunctions.cpp | 121 | ||||
| -rw-r--r-- | src/modules/addon/AddonFunctions.h | 15 | ||||
| -rw-r--r-- | src/modules/addon/PackAddonDialog.cpp | 150 | ||||
| -rw-r--r-- | src/modules/addon/PackAddonDialog.h | 2 | ||||
| -rw-r--r-- | src/modules/addon/libkviaddon.cpp | 51 | ||||
| -rw-r--r-- | src/modules/theme/ThemeFunctions.cpp | 4 |
6 files changed, 227 insertions, 116 deletions
diff --git a/src/modules/addon/AddonFunctions.cpp b/src/modules/addon/AddonFunctions.cpp index e0a762ac8..03f3613a9 100644 --- a/src/modules/addon/AddonFunctions.cpp +++ b/src/modules/addon/AddonFunctions.cpp @@ -25,6 +25,7 @@ #include "AddonFunctions.h" #include "KviPackageReader.h" +#include "KviPackageWriter.h" #include "KviLocale.h" #include "KviMessageBox.h" #include "KviApplication.h" @@ -37,8 +38,12 @@ #include "KviKvsScript.h" #include <QMessageBox> - +#include <QBuffer> #include <QDir> +#include <QDirIterator> +#include <QFile> +#include <QDateTime> + #include <stdlib.h> @@ -113,6 +118,7 @@ namespace AddonFunctions QString szPackageDate; QString szAddonPackVersion; QString szPackageApplication; + QString szMinKVIrcVersion; QString szAuthor = __tr2qs_ctx("Author","addon"); QString szCreatedAt = __tr2qs_ctx("Created at","addon"); @@ -125,6 +131,7 @@ namespace AddonFunctions r.getStringInfoField("Application",szPackageApplication); r.getStringInfoField("Date",szPackageDate); r.getStringInfoField("AddonPackVersion",szAddonPackVersion); + r.getStringInfoField("MinimumKVIrcVersion",szMinKVIrcVersion); QString szWarnings; QString szTmp; @@ -137,6 +144,11 @@ namespace AddonFunctions if(KviMiscUtils::compareVersions(szAddonPackVersion,KVI_CURRENT_ADDONS_ENGINE_VERSION) < 0) bValid = false; + if(!szMinKVIrcVersion.isEmpty()) + { + if(KviMiscUtils::compareVersions(szMinKVIrcVersion,KVI_VERSION) < 0) + bValid = false; + } if(!bValid) { @@ -145,6 +157,7 @@ namespace AddonFunctions szWarnings += "</b></font></center></p>"; } + hd.szHtmlText = QString( "<html bgcolor=\"#ffffff\">" \ "<body bgcolor=\"#ffffff\">" \ @@ -255,4 +268,110 @@ namespace AddonFunctions return szDirName; } + + bool checkDirTree(const QString &szDirPath,QString * pszError) + { + if(pszError) + *pszError = ""; + + QDir addon(szDirPath); + if(!addon.exists()) + { + *pszError = __tr2qs_ctx("The selected directory does not exist.","addon"); + return false; + } + + QFileInfo init(szDirPath + "/install.kvs"); + if(!init.exists()) + { + *pszError = __tr2qs_ctx("The initialization script (install.kvs) does not exist.","addon"); + return false; + } + + return true; + } + + bool pack(AddonInfo &info,QString &szError) + { + if(!checkDirTree(info.szDirPath,&szError)) + return false; + + if(info.szMinVersion.isEmpty()) + info.szMinVersion = KVI_VERSION; + + QString szTmp; + szTmp = QDateTime::currentDateTime().toString(); + + KviPackageWriter pw; + pw.addInfoField("PackageType","AddonPack"); + pw.addInfoField("AddonPackVersion",KVI_CURRENT_ADDONS_ENGINE_VERSION); + pw.addInfoField("Name",info.szName); + pw.addInfoField("Version",info.szVersion); + pw.addInfoField("Author",info.szAuthor); + pw.addInfoField("Description",info.szDescription); + pw.addInfoField("Date",szTmp); + pw.addInfoField("MinimumKVIrcVersion",info.szMinVersion); + pw.addInfoField("Application","KVIrc " KVI_VERSION "." KVI_SOURCES_DATE); + + QPixmap pix(info.szIcon); + if(!pix.isNull()) + { + QByteArray * pba = new QByteArray(); + QBuffer bufferz(pba,0); + + bufferz.open(QIODevice::WriteOnly); + pix.save(&bufferz,"PNG"); + bufferz.close(); + pw.addInfoField("Image",pba); + } + + QDir dir(info.szDirPath); + QFileInfoList ls = dir.entryInfoList(QDir::Dirs | QDir::Files | QDir::Readable | QDir::NoSymLinks | QDir::NoDotAndDotDot); + + if(ls.isEmpty()) + { + szError = __tr2qs_ctx("The package file list is empty","addon"); + return false; + } + + for(QFileInfoList::Iterator it = ls.begin();it != ls.end();++it) + { + const QFileInfo &inf = *it; + + if(inf.isDir()) + { + if(!pw.addDirectory(inf.absoluteFilePath(),QString("%1/").arg(inf.fileName()))) + { + szError = pw.lastError(); + return false; + } + + continue; + } + + // must be a file + if(!pw.addFile(inf.absoluteFilePath(),inf.fileName())) + { + szError = pw.lastError(); + return false; + } + } + + + // Create the addon package + if(info.szSavePath.isEmpty()) + { + szError = __tr2qs_ctx("Save path is empty","addon"); + return false; + } + + if(!pw.pack(info.szSavePath)) + { + szError = pw.lastError(); + return false; + } + + return true; + } + } diff --git a/src/modules/addon/AddonFunctions.h b/src/modules/addon/AddonFunctions.h index adcc455c2..b4de8b668 100644 --- a/src/modules/addon/AddonFunctions.h +++ b/src/modules/addon/AddonFunctions.h @@ -32,8 +32,23 @@ #define KVI_CURRENT_ADDONS_ENGINE_VERSION "2.0.0" +class AddonInfo +{ +public: + QString szAuthor; + QString szName; + QString szVersion; + QString szDescription; + QString szMinVersion; + QString szIcon; + QString szDirPath; + QString szSavePath; +}; + namespace AddonFunctions { + bool checkDirTree(const QString &szDirPath,QString * pszError); + bool pack(AddonInfo &info,QString &szError); bool notAValidAddonPackage(QString & szError); bool installAddonPackage(const QString & szAddonPackageFileName, QString & szError, QWidget * pDialogParent = 0); QString createRandomDir(); diff --git a/src/modules/addon/PackAddonDialog.cpp b/src/modules/addon/PackAddonDialog.cpp index f2c0bafcc..0abec8bc2 100644 --- a/src/modules/addon/PackAddonDialog.cpp +++ b/src/modules/addon/PackAddonDialog.cpp @@ -40,9 +40,6 @@ #include <QMessageBox> #include <QDir> #include <QDirIterator> -#include <QDateTime> -#include <QBuffer> -#include <QFile> PackAddonDialog::PackAddonDialog(QWidget * pParent) : QWizard(pParent) @@ -133,6 +130,8 @@ void PackAddonDialog::accept() QWizard::accept(); } + +#if 0 bool PackAddonDialog::checkDirTree(QString * pszError) { if(pszError) @@ -154,8 +153,6 @@ bool PackAddonDialog::checkDirTree(QString * pszError) return true; } - -#if 0 bool PackAddonDialog::createInstaller(QString * pszError) { if(pszError) @@ -259,134 +256,63 @@ bool PackAddonDialog::createInstaller(QString * pszError) #endif + + bool PackAddonDialog::packAddon() { // Get data from registered fields - m_szAuthor = field("packageAuthor").toString(); - m_szName = field("packageName").toString(); - m_szVersion = field("packageVersion").toString(); - m_szDescription = field("packageDescription").toString(); - m_szMinVersion = field("packageMinVersion").toString(); - m_szIcon = field("packageIcon").toString(); - m_szDirPath = field("packageDirPath").toString(); - m_szSavePath = field("packageSavePath").toString(); + AddonInfo info; + info.szAuthor = field("packageAuthor").toString(); + info.szName = field("packageName").toString(); + info.szVersion = field("packageVersion").toString(); + info.szDescription = field("packageDescription").toString(); + info.szMinVersion = field("packageMinVersion").toString(); + info.szIcon = field("packageIcon").toString(); + info.szDirPath = field("packageDirPath").toString(); + info.szSavePath = field("packageSavePath").toString(); - // Check the addon tree - QString szError; + if(info.szSavePath.isEmpty()) + { + info.szSavePath = QDir::homePath(); + KviQString::ensureLastCharIs(info.szSavePath,QChar(KVI_PATH_SEPARATOR_CHAR)); + info.szSavePath += m_szName; + info.szSavePath += "-"; + info.szSavePath += m_szVersion; + info.szSavePath += KVI_FILEEXTENSION_ADDONPACKAGE; + } - if(!checkDirTree(&szError)) + if(QFile::exists(info.szSavePath)) { - QMessageBox::critical(this, - __tr2qs_ctx("Addon Packaging Error","addon"), - szError,QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton - ); - return false; + if(QMessageBox::question( + this, + __tr2qs_ctx("Export Addon - KVIrc","addon"), + __tr2qs_ctx("File %1 already exists. Do you want to overwrite it?","addon").arg(info.szSavePath), + QMessageBox::Yes, + QMessageBox::No + ) == QMessageBox::No) + return false; } // Raise the files summary dialog m_pPackAddonSummaryFilesWidget = new PackAddonSummaryFilesWidget(this); - m_pPackAddonSummaryFilesWidget->setPath(m_szDirPath); + m_pPackAddonSummaryFilesWidget->setPath(info.szDirPath); if(m_pPackAddonSummaryFilesWidget->exec() == QDialog::Rejected) { delete m_pPackAddonSummaryFilesWidget; return false; } + QString szError; - QString szTmp; - szTmp = QDateTime::currentDateTime().toString(); - - KviPackageWriter pw; - pw.addInfoField("PackageType","AddonPack"); - pw.addInfoField("AddonPackVersion",KVI_CURRENT_ADDONS_ENGINE_VERSION); - pw.addInfoField("Name",m_szName); - pw.addInfoField("Version",m_szVersion); - pw.addInfoField("Author",m_szAuthor); - pw.addInfoField("Description",m_szDescription); - pw.addInfoField("Date",szTmp); - pw.addInfoField("Application","KVIrc " KVI_VERSION "." KVI_SOURCES_DATE); - - QPixmap pix(m_szIcon); - if(!pix.isNull()) - { - QByteArray * pba = new QByteArray(); - QBuffer bufferz(pba,0); - - bufferz.open(QIODevice::WriteOnly); - pix.save(&bufferz,"PNG"); - bufferz.close(); - pw.addInfoField("Image",pba); - } - - QDir dir(m_szDirPath); - QFileInfoList ls = dir.entryInfoList(QDir::Dirs | QDir::Files | QDir::Readable | QDir::NoSymLinks | QDir::NoDotAndDotDot); - - if(ls.isEmpty()) - { - szTmp = __tr2qs_ctx("Packaging failed","addon"); - szTmp += ": "; - szTmp += __tr2qs_ctx("The package file list is empty","addon"); - QMessageBox::critical(this,__tr2qs_ctx("Export Addon - KVIrc","addon"),szTmp,QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton); - return false; - } - - for(QFileInfoList::Iterator it = ls.begin();it != ls.end();++it) - { - const QFileInfo &inf = *it; - - if(inf.isDir()) - { - if(!pw.addDirectory(inf.absoluteFilePath(),QString("%1/").arg(inf.fileName()))) - { - QString szTmp = __tr2qs_ctx("Packaging failed","addon"); - szTmp += ": "; - szTmp += pw.lastError(); - QMessageBox::critical(this,__tr2qs_ctx("Export Addon - KVIrc","addon"),szTmp,QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton); - return false; - } - - continue; - } - - // must be a file - if(!pw.addFile(inf.absoluteFilePath(),inf.fileName())) - { - szTmp = __tr2qs_ctx("Packaging failed","addon"); - szTmp += ": "; - szTmp += pw.lastError(); - QMessageBox::critical(this,__tr2qs_ctx("Export Addon - KVIrc","addon"),szTmp,QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton); - return false; - } - } - - - // Create the addon package - if(m_szSavePath.isEmpty()) - { - m_szSavePath = QDir::homePath(); - KviQString::ensureLastCharIs(m_szSavePath,QChar(KVI_PATH_SEPARATOR_CHAR)); - m_szSavePath += m_szName; - m_szSavePath += "-"; - m_szSavePath += m_szVersion; - m_szSavePath += KVI_FILEEXTENSION_ADDONPACKAGE; - } - - if(QFile::exists(m_szSavePath)) - { - if(QMessageBox::question(this,__tr2qs_ctx("Export Addon - KVIrc","addon"),__tr2qs_ctx("File %1 already exists. Do you want to overwrite it?","addon").arg(m_szSavePath),QMessageBox::Yes,QMessageBox::No) == QMessageBox::No) - return false; - } - - if(!pw.pack(m_szSavePath)) + if(!AddonFunctions::pack(info,szError)) { - szTmp = __tr2qs_ctx("Packaging failed","addon"); - szTmp += ": "; - szTmp += pw.lastError(); - QMessageBox::critical(this,__tr2qs_ctx("Export Addon - KVIrc","addon"),szTmp,QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton); + QMessageBox::critical(this, + __tr2qs_ctx("Addon Packaging Error","addon"), + szError,QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton + ); return false; } - QMessageBox::information(this,__tr2qs_ctx("Export Addon - KVIrc","addon"),__tr2qs_ctx("Package saved successfully in %1","addon").arg(m_szSavePath),QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton); return true; diff --git a/src/modules/addon/PackAddonDialog.h b/src/modules/addon/PackAddonDialog.h index 0d70d6ca1..e3bcca402 100644 --- a/src/modules/addon/PackAddonDialog.h +++ b/src/modules/addon/PackAddonDialog.h @@ -98,6 +98,7 @@ protected: */ bool packAddon(); +#if 0 /** * \brief Ensures the sources directory is complete * \param pszError The buffer containing errors @@ -111,6 +112,7 @@ protected: * \return bool */ bool createInstaller(QString * pszError); +#endif }; /** diff --git a/src/modules/addon/libkviaddon.cpp b/src/modules/addon/libkviaddon.cpp index 4aefa59a0..74fb8a4ea 100644 --- a/src/modules/addon/libkviaddon.cpp +++ b/src/modules/addon/libkviaddon.cpp @@ -813,6 +813,56 @@ static bool addon_kvs_cmd_install(KviKvsModuleCommandCall * c) return true; } +/* + @doc: addon.pack + @type: + command + @title: + addon.pack + @short: + Creates a kva package containing an addon + @syntax: + addon.pack <package_path> <addon_name> <addon_version> <description> <author> <min_kvirc_version> <icon> <addon_path> + @description: + Creates a *.kva package containing a KVIrc addon.[br] + <package_path> is the absolute path and file name of the package that should be saved.[br] + <addon_name> is the visible name of the addon (something like "My Addon").[br] + <addon_version> is the version of the addon in the form X.Y.Z.[br] + <description> is a textual description of the addon. + <author> is the name of the person that is creating the addon. + <min_kvirc_version> is the minimum kvirc version that this addon supports. Pass an empty string if you want + this to become the current kvirc version. + <icon> is the path of an icon to be used as rappresentative image of the addon. Pass an empty string if you + don't want an icon to be stored in the package. + <addon_path> is a path to a directory containing an addon. It should contain an install.kvs file + that calls [cmd]addon.register[/cmd] and then installs all the addon aliases, events and files (via [cmd]addon.installfiles[/cmd]. +*/ +static bool addon_kvs_cmd_pack(KviKvsModuleCommandCall * c) +{ + AddonInfo info; + + KVSM_PARAMETERS_BEGIN(c) + KVSM_PARAMETER("package_path",KVS_PT_NONEMPTYSTRING,0,info.szSavePath) + KVSM_PARAMETER("addon_name",KVS_PT_NONEMPTYSTRING,0,info.szName) + KVSM_PARAMETER("addon_version",KVS_PT_NONEMPTYSTRING,0,info.szVersion) + KVSM_PARAMETER("description",KVS_PT_STRING,0,info.szDescription) + KVSM_PARAMETER("author",KVS_PT_NONEMPTYSTRING,0,info.szAuthor) + KVSM_PARAMETER("min_kvirc_version",KVS_PT_STRING,0,info.szMinVersion) + KVSM_PARAMETER("addon_icon",KVS_PT_STRING,0,info.szIcon) + KVSM_PARAMETER("addon_path",KVS_PT_NONEMPTYSTRING,0,info.szDirPath) + KVSM_PARAMETERS_END(c) + + QString szError; + + if(AddonFunctions::pack(info,szError)) + return true; + + c->error(szError); + return false; +} + + + static bool addon_module_init(KviModule *m) { KVSM_REGISTER_FUNCTION(m,"exists",addon_kvs_fnc_exists); @@ -825,6 +875,7 @@ static bool addon_module_init(KviModule *m) KVSM_REGISTER_SIMPLE_COMMAND(m,"configure",addon_kvs_cmd_configure); KVSM_REGISTER_SIMPLE_COMMAND(m,"help",addon_kvs_cmd_help); KVSM_REGISTER_SIMPLE_COMMAND(m,"installfiles",addon_kvs_cmd_installfiles); + KVSM_REGISTER_SIMPLE_COMMAND(m,"pack",addon_kvs_cmd_pack); KVSM_REGISTER_CALLBACK_COMMAND(m,"setconfigurecallback",addon_kvs_cmd_setconfigurecallback); KVSM_REGISTER_CALLBACK_COMMAND(m,"sethelpcallback",addon_kvs_cmd_sethelpcallback); diff --git a/src/modules/theme/ThemeFunctions.cpp b/src/modules/theme/ThemeFunctions.cpp index eec3e4bed..86a0aa8d8 100644 --- a/src/modules/theme/ThemeFunctions.cpp +++ b/src/modules/theme/ThemeFunctions.cpp @@ -80,10 +80,8 @@ namespace ThemeFunctions pInfoFields = r.stringInfoFields(); pValue = pInfoFields->find("PackageType"); - if(!pValue){ - qDebug("no package type"); + if(!pValue) return notAValidThemePackage(szError); - } if(!KviQString::equalCI(*pValue,"ThemePack")) return notAValidThemePackage(szError); |
