diff options
| author | 2008-05-08 17:05:26 +0000 | |
|---|---|---|
| committer | 2008-05-08 17:05:26 +0000 | |
| commit | 26f44e553bc848d91bd237986beea068cd55b320 (patch) | |
| tree | 8cb2f3a70354025afe5b13b3d78b3917fe14aad4 /src/modules | |
| parent | removed useless include (diff) | |
| download | KVIrc-26f44e553bc848d91bd237986beea068cd55b320.tar.gz KVIrc-26f44e553bc848d91bd237986beea068cd55b320.tar.bz2 KVIrc-26f44e553bc848d91bd237986beea068cd55b320.zip | |
new addon packaging system (wip)
git-svn-id: https://svn.kvirc.de/svn/trunk/kvirc@1711 17fca916-40b9-46aa-a4ea-0a15b648b75c
Diffstat (limited to 'src/modules')
| -rw-r--r-- | src/modules/addon/CMakeLists.txt | 6 | ||||
| -rw-r--r-- | src/modules/addon/addonfunctions.cpp | 346 | ||||
| -rw-r--r-- | src/modules/addon/addonfunctions.h | 52 | ||||
| -rw-r--r-- | src/modules/addon/libkviaddon.cpp | 42 | ||||
| -rw-r--r-- | src/modules/addon/managementdialog.cpp | 15 | ||||
| -rw-r--r-- | src/modules/addon/packaddondialog.cpp | 289 | ||||
| -rw-r--r-- | src/modules/addon/packaddondialog.h | 54 |
7 files changed, 791 insertions, 13 deletions
diff --git a/src/modules/addon/CMakeLists.txt b/src/modules/addon/CMakeLists.txt index 47aa70145..d1594008e 100644 --- a/src/modules/addon/CMakeLists.txt +++ b/src/modules/addon/CMakeLists.txt @@ -2,11 +2,15 @@ SET(kviaddon_MOC_HDRS managementdialog.h + packaddondialog.h + addonfunctions.h ) SET(kviaddon_SRCS - managementdialog.cpp libkviaddon.cpp + managementdialog.cpp + packaddondialog.cpp + addonfunctions.cpp ) # After this call, files will be moc'ed to moc_kvi_*.cpp diff --git a/src/modules/addon/addonfunctions.cpp b/src/modules/addon/addonfunctions.cpp new file mode 100644 index 000000000..3af9c34d8 --- /dev/null +++ b/src/modules/addon/addonfunctions.cpp @@ -0,0 +1,346 @@ +//============================================================================= +// +// File : addonfunctions.cpp +// Created on Fri 02 May 2008 17:36:07 by Elvio Basello +// +// This file is part of the KVIrc IRC Client distribution +// Copyright (C) 2008 Elvio Basello <hellvis69 at netsons dot org> +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc. ,59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +//============================================================================= + +#include "addonfunctions.h" + +#include "kvi_packagefile.h" +#include "kvi_locale.h" +#include "kvi_msgbox.h" +#include "kvi_app.h" +#include "kvi_htmldialog.h" +#include "kvi_iconmanager.h" +#include "kvi_miscutils.h" +#include "kvi_sourcesdate.h" +#include "kvi_theme.h" +#include "kvi_frame.h" + +//#include <qmime.h> +#include <q3mimefactory.h> +#define KviTalMimeSourceFactory Q3MimeSourceFactory + +#define KVI_CURRENT_ADDONS_ENGINE_VERSION "1.0.0" + +namespace KviAddonFunctions +{ + static bool notAValidAddonPackage(QString &szError) + { + KviQString::sprintf(szError,__tr2qs_ctx("The selected file does not seem to be a valid KVIrc addon package","addon")); + return false; + } + + bool installAddonPackage(const QString &szAddonPackageFileName,QString &szError,QWidget * pDialogParent) + { + KviPointerHashTable<QString,QString> * pInfoFields; + QString * pValue; + bool bInstall; + QPixmap pix; + QByteArray * pByteArray; + KviHtmlDialogData hd; + + const char * check_fields[] = { "Name", "Version", "Author", "Description", "Date", "Application" }; + + // check if it is a valid addon file + KviPackageReader r; + if(!r.readHeader(szAddonPackageFileName)) + { + QString szErr = r.lastError(); + KviQString::sprintf(szError,__tr2qs_ctx("The selected file does not seem to be a valid KVIrc package: %Q","addon"),&szErr); + return false; + } + + pInfoFields = r.stringInfoFields(); + + pValue = pInfoFields->find("PackageType"); + if(!pValue)return notAValidAddonPackage(szError); + if(!KviQString::equalCI(*pValue,"AddonPack"))return notAValidAddonPackage(szError); + pValue = pInfoFields->find("AddonPackVersion"); + if(!pValue)return notAValidAddonPackage(szError); + if(!KviQString::equalCI(*pValue,"1"))return notAValidAddonPackage(szError); + + // make sure the default fields exist + for(int i=0;i<6;i++) + { + pValue = pInfoFields->find(check_fields[i]); + if(!pValue)return notAValidAddonPackage(szError); + } + + pValue = pInfoFields->find("AddonCount"); + if(!pValue)return notAValidAddonPackage(szError); + bool bOk; + int iAddonCount = pValue->toInt(&bOk); + if(!bOk)return notAValidAddonPackage(szError); + if(iAddonCount < 1)return notAValidAddonPackage(szError); + + // ok.. it should be really valid at this point + + // load its picture + pByteArray = r.binaryInfoFields()->find("Image"); + if(pByteArray) + pix.loadFromData(*pByteArray,0,0); + + if(pix.isNull()) + { + // load the default icon + pix = *(g_pIconManager->getBigIcon(KVI_BIGICON_ADDONS)); + } + + QString szPackageName; + QString szPackageVersion; + QString szPackageAuthor; + QString szPackageDescription; + QString szPackageDate; + QString szPackageAddonEngineVersion; + QString szPackageApplication; + + QString szAuthor = __tr2qs_ctx("Author","addon"); + QString szCreatedAt = __tr2qs_ctx("Created at","addon"); + QString szCreatedOn = __tr2qs_ctx("Created with","Addon"); + + r.getStringInfoField("Name",szPackageName); + r.getStringInfoField("Version",szPackageVersion); + r.getStringInfoField("Author",szPackageAuthor); + r.getStringInfoField("Description",szPackageDescription); + r.getStringInfoField("Application",szPackageApplication); + r.getStringInfoField("Date",szPackageDate); + + QString szWarnings; + QString szDetails = "<html><body bgcolor=\"#ffffff\">"; + QString szTmp; + + int iIdx = 0; + int iValidAddonCount = iAddonCount; + + while(iIdx < iAddonCount) + { + bool bValid = true; + + QString szAddonName; + QString szAddonVersion; + QString szAddonDescription; + QString szAddonDate; + QString szAddonSubdirectory; + QString szAddonAuthor; + QString szAddonEngineVersion; + QString szAddonApplication; + + KviQString::sprintf(szTmp,"Addon%dName",iIdx); + r.getStringInfoField(szTmp,szAddonName); + KviQString::sprintf(szTmp,"Addon%dVersion",iIdx); + r.getStringInfoField(szTmp,szAddonVersion); + KviQString::sprintf(szTmp,"Addon%dApplication",iIdx); + r.getStringInfoField(szTmp,szAddonApplication); + KviQString::sprintf(szTmp,"Addon%dDescription",iIdx); + r.getStringInfoField(szTmp,szAddonDescription); + KviQString::sprintf(szTmp,"Addon%dDate",iIdx); + r.getStringInfoField(szTmp,szAddonDate); + KviQString::sprintf(szTmp,"Addon%dSubdirectory",iIdx); + r.getStringInfoField(szTmp,szAddonSubdirectory); + KviQString::sprintf(szTmp,"Addon%dAuthor",iIdx); + r.getStringInfoField(szTmp,szAddonAuthor); + KviQString::sprintf(szTmp,"Addon%dAddonEngineVersion",iIdx); + r.getStringInfoField(szTmp,szAddonEngineVersion); + + if(szAddonName.isEmpty() || szAddonVersion.isEmpty() || szAddonSubdirectory.isEmpty() || szAddonEngineVersion.isEmpty()) + bValid = false; + if(KviMiscUtils::compareVersions(szAddonEngineVersion,KVI_CURRENT_ADDONS_ENGINE_VERSION) < 0) + bValid = false; + + QString szDetailsBuffer; + + getAddonHtmlDescription( + szDetailsBuffer, + szAddonName, + szAddonVersion, + szAddonDescription, + szAddonSubdirectory, + szAddonApplication, + szAddonAuthor, + szAddonDate, + szAddonEngineVersion, + iIdx + ); + + if(iIdx > 0) szDetails += "<hr>"; + + szDetails += szDetailsBuffer; + + if(!bValid) + { + szDetails += "<p><center><font color=\"#ff0000\"><b>"; + szDetails += __tr2qs_ctx("Warning: The addon might be incompatible with this version of KVIrc","addon"); + szDetails += "</b></font></center></p>"; + iValidAddonCount--; + } + + iIdx++; + } + + szDetails += "<br><p><center><a href=\"Addon_dialog_main\">"; + szDetails += __tr2qs_ctx("Go Back to Package Data","addon"); + szDetails += "</a></center></p>"; + szDetails += "</body></html>"; + + if(iValidAddonCount < iAddonCount) + { + szWarnings += "<p><center><font color=\"#ff0000\"><b>"; + szWarnings += __tr2qs_ctx("Warning: Some of the Addons contained in this package might be either corrupted or incompatible with this version of KVIrc","addon"); + szWarnings += "</b></font></center></p>"; + } + + QString szShowDetails = __tr2qs_ctx("Show Details","addon"); + + KviQString::sprintf(hd.szHtmlText, + "<html bgcolor=\"#ffffff\">" \ + "<body bgcolor=\"#ffffff\">" \ + "<p><center>" \ + "<h2>%Q %Q</h2>" \ + "</center></p>" \ + "<p><center>" \ + "<img src=\"addon_dialog_pack_image\">" \ + "</center></p>" \ + "<p><center>" \ + "<i>%Q</i>" \ + "</center></p>" \ + "<p><center>" \ + "%Q: <b>%Q</b><br>" \ + "%Q: <b>%Q</b><br>" \ + "</center></p>" \ + "<p><center>" \ + "<font color=\"#808080\">" \ + "%Q: %Q<br>" \ + "</font>" \ + "</center></p>" \ + "%Q" \ + "<br>" \ + "<p><center>" \ + "<a href=\"addon_dialog_details\">%Q</a>" \ + "</center></p>" \ + "</body>" \ + "</html>", + &szPackageName, + &szPackageVersion, + &szPackageDescription, + &szAuthor, + &szPackageAuthor, + &szCreatedAt, + &szPackageDate, + &szCreatedOn, + &szPackageApplication, + &szWarnings, + &szShowDetails + ); + + + + KviTalMimeSourceFactory::defaultFactory()->setPixmap("Addon_dialog_pack_image",pix); + KviTalMimeSourceFactory::defaultFactory()->setText("addon_dialog_details",szDetails); + KviTalMimeSourceFactory::defaultFactory()->setText("addon_dialog_main",hd.szHtmlText); + + QString beginCenter = "<center>"; + QString endCenter = "</center>"; + + hd.szCaption = __tr2qs_ctx("Install Addon Pack - KVIrc","addon"); + hd.szUpperLabelText = beginCenter + __tr2qs_ctx("You're about to install the following addon package","addon") + endCenter; + hd.szLowerLabelText = beginCenter + __tr2qs_ctx("Do you want to proceed with the installation ?","addon") + endCenter; + hd.szButton1Text = __tr2qs_ctx("Do Not Install","addon"); + hd.szButton2Text = __tr2qs_ctx("Yes, Proceed","addon"); + hd.iDefaultButton = 2; + hd.iCancelButton = 1; + hd.pixIcon = *(g_pIconManager->getSmallIcon(KVI_SMALLICON_ADDONS)); + hd.iMinimumWidth = 350; + hd.iMinimumHeight = 420; + hd.iFlags = KviHtmlDialogData::ForceMinimumSize; + + bInstall = KviHtmlDialog::display(pDialogParent,&hd) == 2; + + if(bInstall) + { + QString szUnpackPath; + g_pApp->getLocalKvircDirectory(szUnpackPath,KviApp::Themes); + if(!r.unpack(szAddonPackageFileName,szUnpackPath)) + { + QString szErr2 = r.lastError(); + KviQString::sprintf(szError,__tr2qs_ctx("Failed to unpack the selected file: %Q","addon"),&szErr2); + return true; + } + } + + return true; + } + + + void getAddonHtmlDescription( + QString &szBuffer, + const QString &szAddonName, + const QString &szAddonVersion, + const QString &szAddonDescription, + const QString &szAddonSubdirectory, + const QString &szAddonApplication, + const QString &szAddonAuthor, + const QString &szAddonDate, + const QString &szAddonAddonEngineVersion, + int iUniqueIndexInDocument + ) + { + QString szAuthor = __tr2qs_ctx("Author","Addon"); + QString szCreatedAt = __tr2qs_ctx("Created at","addon"); + QString szCreatedOn = __tr2qs_ctx("Created with","addon"); + QString szAddonEngineVersion = __tr2qs_ctx("Addon Engine Version","addon"); + QString szSubdirectory = __tr2qs_ctx("Subdirectory","addon"); + + KviQString::sprintf( + szBuffer, + "<p><center>" \ + "<h2>%Q %Q</h2>" \ + "</center></p>" \ + "<p><center>" \ + "<i>%Q</i>" \ + "</center></p>" \ + "<p><center>" \ + "%Q: <b>%Q</b><br>" \ + "%Q: <b>%Q</b><br>" \ + "</center></p>" \ + "<p><center>" \ + "<font color=\"#808080\">" \ + "%Q: %Q<br>" \ + "%Q: %Q<br>" \ + "%Q: %Q<br>" \ + "</font>" \ + "</center></p>", + &szAddonName, + &szAddonVersion, + &szAddonDescription, + &szAuthor, + &szAddonAuthor, + &szCreatedAt, + &szAddonDate, + &szCreatedOn, + &szAddonApplication, + &szAddonAddonEngineVersion, + &szAddonAddonEngineVersion, + &szSubdirectory, + &szAddonSubdirectory + ); + } +}; diff --git a/src/modules/addon/addonfunctions.h b/src/modules/addon/addonfunctions.h new file mode 100644 index 000000000..ae26351b4 --- /dev/null +++ b/src/modules/addon/addonfunctions.h @@ -0,0 +1,52 @@ +#ifndef _ADDONFUNCTIONS_H_ +#define _ADDONFUNCTIONS_H_ +//============================================================================= +// +// File : addonfunctions.h +// Created on Fri 02 May 2008 17:36:07 by Elvio Basello +// +// This file is part of the KVIrc IRC Client distribution +// Copyright (C) 2008 Elvio Basello <hellvis69 at netsons dot org> +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc. ,59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +//============================================================================= + +#include "kvi_settings.h" +#include "kvi_qstring.h" + +#include <QWidget> +#include <QPixmap> + +namespace KviAddonFunctions +{ + static bool notAValidAddonPackage(QString &szError); + bool installAddonPackage(const QString &szAddonPackageFileName,QString &szError,QWidget * pDialogParent = 0); + void getAddonHtmlDescription( + QString &szBuffer, + const QString &szAddonName, + const QString &szAddonVersion, + const QString &szAddonDescription, + const QString &szAddonSubdirectory, + const QString &szAddonApplication, + const QString &szAddonAuthor, + const QString &szAddonDate, + const QString &szAddonAddonEngineVersion, + int iUniqueIndexInDocument = 0 + ); +}; + + +#endif //!_ADDONFUNCTIONS_H_ diff --git a/src/modules/addon/libkviaddon.cpp b/src/modules/addon/libkviaddon.cpp index c96e06793..6c69b3675 100644 --- a/src/modules/addon/libkviaddon.cpp +++ b/src/modules/addon/libkviaddon.cpp @@ -23,6 +23,7 @@ /////////////////////////////////////////////////////////////////////////////// #include "managementdialog.h" +#include "addonfunctions.h" #include "kvi_module.h" #include "kvi_kvs_scriptaddonmanager.h" @@ -30,7 +31,6 @@ #include "kvi_qstring.h" #include "kvi_parameterlist.h" #include "kvi_cmdformatter.h" -#include "kvi_qstring.h" #include "kvi_error.h" #include "kvi_out.h" #include "kvi_iconmanager.h" @@ -38,6 +38,10 @@ #include "kvi_config.h" #include "kvi_sourcesdate.h" #include "kvi_miscutils.h" +#include "kvi_fileutils.h" +#include "kvi_filedialog.h" + +#include <QFileInfo> QRect g_rectManagementDialogGeometry(0,0,0,0); @@ -604,6 +608,38 @@ static bool addon_kvs_cmd_dialog(KviKvsModuleCommandCall * c) return true; } +/* + @doc: addon.install + @type: + command + @title: + addon.install + @short: + Shows the addon management editor + @syntax: + addon.install <package_path:string> + @description: + Attempts to install the addons in the package specified by <package_path>. +*/ + +static bool addon_kvs_cmd_install(KviKvsModuleCommandCall * c) +{ + QString szAddonPackFile; + + KVSM_PARAMETERS_BEGIN(c) + KVSM_PARAMETER("package_path",KVS_PT_STRING,0,szAddonPackFile) + KVSM_PARAMETERS_END(c) + + QString szError; + if(!KviAddonFunctions::installAddonPackage(szAddonPackFile,szError)) + { + c->error(__tr2qs_ctx("Error installing addon package: %Q","addon"),&szError); + return false; + } + + return true; +} + static bool addon_module_init(KviModule *m) { KVSM_REGISTER_FUNCTION(m,"exists",addon_kvs_fnc_exists); @@ -611,6 +647,7 @@ static bool addon_module_init(KviModule *m) KVSM_REGISTER_SIMPLE_COMMAND(m,"dialog",addon_kvs_cmd_dialog); KVSM_REGISTER_SIMPLE_COMMAND(m,"list",addon_kvs_cmd_list); + KVSM_REGISTER_SIMPLE_COMMAND(m,"install",addon_kvs_cmd_install); KVSM_REGISTER_SIMPLE_COMMAND(m,"uninstall",addon_kvs_cmd_uninstall); KVSM_REGISTER_SIMPLE_COMMAND(m,"configure",addon_kvs_cmd_configure); KVSM_REGISTER_SIMPLE_COMMAND(m,"help",addon_kvs_cmd_help); @@ -648,7 +685,8 @@ static bool addon_module_can_unload(KviModule * m) KVIRC_MODULE( "Addon", // module name "4.0.0", // module version - "Copyright (C) 2005 Szymon Stefanek (pragma at kvirc dot net)", // author & (C) + "Copyright (C) 2005 Szymon Stefanek (pragma at kvirc dot net)\n" \ + " 2008 Elvio Basello (hellvis69 at netsons dot org)", // author & (C) "Script management functions for the KVS engine", addon_module_init, addon_module_can_unload, diff --git a/src/modules/addon/managementdialog.cpp b/src/modules/addon/managementdialog.cpp index f72bd24b6..789c826e2 100644 --- a/src/modules/addon/managementdialog.cpp +++ b/src/modules/addon/managementdialog.cpp @@ -23,6 +23,7 @@ //=============================================================================
#include "managementdialog.h"
+#include "packaddondialog.h"
#include "kvi_app.h"
#include "kvi_locale.h"
@@ -54,8 +55,6 @@ #include <QAbstractTextDocumentLayout>
-
-
KviScriptManagementDialog * KviScriptManagementDialog::m_pInstance = 0;
extern QRect g_rectManagementDialogGeometry;
@@ -86,7 +85,6 @@ KviScriptAddonListViewItem::~KviScriptAddonListViewItem() delete m_pAddon;
}
-
KviScriptManagementDialog::KviScriptManagementDialog(QWidget * p)
: QDialog(p/*,WType_TopLevel | WStyle_Customize | WStyle_Title | WStyle_StaysOnTop | WStyle_DialogBorder*/)
{
@@ -124,7 +122,7 @@ KviScriptManagementDialog::KviScriptManagementDialog(QWidget * p) m_pPackButton = new QToolButton(hb);
m_pPackButton->setIcon(*(g_pIconManager->getBigIcon(KVI_BIGICON_PACK)));
m_pPackButton->setIconSize(QSize(32,32));
- QToolTip::add(m_pPackButton,__tr2qs_ctx("Export Selected Addons to a Distributable Package","addon"));
+ QToolTip::add(m_pPackButton,__tr2qs_ctx("Create an Addon as a Distributable Package","addon"));
connect(m_pPackButton,SIGNAL(clicked()),this,SLOT(packScript()));
m_pUninstallButton = new QToolButton(hb);
@@ -163,12 +161,11 @@ KviScriptManagementDialog::KviScriptManagementDialog(QWidget * p) QString szPic;
g_pApp->getGlobalKvircDirectory(szPic,KviApp::Pics);
- // we need mandatory unix like path separator
+ // we need mandatory unix like path separator
szPic.replace('\\',"/");
szPic += "/kvi_dialog_addons.png";
QString szStyle("QListWidget {background-image: url(" + szPic + ");background-repeat: no-repeat;background-position: bottom right;}");
- debug("path %s",szPic.toUtf8().data());
m_pListWidget->setStyleSheet(szStyle);
g->addWidget(m_pListWidget,1,0);
@@ -225,7 +222,6 @@ void KviScriptManagementDialog::currentChanged(QListWidgetItem *item,QListWidget m_pConfigureButton->setEnabled(false);
m_pUninstallButton->setEnabled(false);
m_pHelpButton->setEnabled(false);
- m_pPackButton->setEnabled(false);
} else {
m_pConfigureButton->setEnabled(!(it->addon()->configureCallbackCode().isEmpty()));
m_pHelpButton->setEnabled(!(it->addon()->helpCallbackCode().isEmpty()));
@@ -258,11 +254,10 @@ void KviScriptManagementDialog::packScript() for(int i=0;i<itemsSelected.count();i++)
dl.append(((KviThemeListBoxItem *)itemsSelected.at(i))->themeInfo());
if(dl.isEmpty())return;
-
- KviPackAddonDialog * pDialog = new KviPackAddonDialog(this,&dl);
+ */
+ KviPackAddonDialog * pDialog = new KviPackAddonDialog(this);
pDialog->exec();
delete pDialog;
- */
}
void KviScriptManagementDialog::uninstallScript()
diff --git a/src/modules/addon/packaddondialog.cpp b/src/modules/addon/packaddondialog.cpp new file mode 100644 index 000000000..9477c1850 --- /dev/null +++ b/src/modules/addon/packaddondialog.cpp @@ -0,0 +1,289 @@ +//============================================================================ +// +// File : packaddondialog.cpp +// Created on Sat 03 May 2008 01:40:44 by Elvio Basello +// +// This file is part of the KVIrc IRC Client distribution +// Copyright (C) 2008 Elvio Basello <hellvis69 at netsons dot org> +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc. ,59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +//============================================================================ + +#include "packaddondialog.h" +#include "addonfunctions.h" + +#include "kvi_options.h" +#include "kvi_locale.h" +#include "kvi_config.h" +#include "kvi_fileutils.h" +#include "kvi_app.h" +#include "kvi_frame.h" +#include "kvi_iconmanager.h" +#include "kvi_styled_controls.h" +#include "kvi_packagefile.h" +#include "kvi_fileextensions.h" +#include "kvi_filedialog.h" +#include "kvi_msgbox.h" +#include "kvi_selectors.h" +#include "kvi_miscutils.h" +#include "kvi_sourcesdate.h" +#include "kvi_tal_textedit.h" + +#include <QLayout> +#include <QPushButton> +#include <QLineEdit> +#include <QRegExp> +#include <QMessageBox> +#include <QDir> +#include <QComboBox> +#include <QPainter> +#include <QToolTip> +#include <QImage> +#include <QDateTime> +#include <QBuffer> +#include <QLabel> +#include <QString> + + +KviPackAddonDialog::KviPackAddonDialog(QWidget * pParent) +: KviTalWizard(pParent) +{ + QString szPackageName = "MyAddon"; + QString szPackageAuthor = __tr2qs_ctx("Your name here","addon"); + QString szPackageDescription = __tr2qs_ctx("Put a package description here...","addon"); + QString szPackageVersion = "1.0.0"; + + m_szPackagePath = QDir::homeDirPath(); + KviQString::ensureLastCharIs(m_szPackagePath,QChar(KVI_PATH_SEPARATOR_CHAR)); + /* + m_szPackagePath += szPackageName; + m_szPackagePath += "-"; + m_szPackagePath += szPackageVersion; + m_szPackagePath += "."; + m_szPackagePath += KVI_FILEEXTENSION_ADDONPACKAGE; + */ + + setWindowTitle(__tr2qs_ctx("Export Addon - KVIrc","addon")); + setMinimumSize(400,350); + + // welcome page + QWidget * pPage = new QWidget(this); + QGridLayout * pLayout = new QGridLayout(pPage); + + QLabel * pLabel = new QLabel(pPage); + QString szText = "<p>"; + szText += __tr2qs_ctx("This procedure allows you to export the selected addon to a single package. It is useful when you want to distribute your addon to the public.","addon"); + szText += "</p><p>"; + szText += __tr2qs_ctx("You will be asked to provide a package name, a version and a description.","addon"); + szText += "</p><p>"; + szText += __tr2qs_ctx("Hit the \"Next\" button to begin.","addon"); + szText += "<p>"; + + pLabel->setText(szText); + pLayout->addWidget(pLabel,0,0); + pLayout->setRowStretch(1,1); + + addPage(pPage,__tr2qs_ctx("Welcome","addon")); + setBackEnabled(pPage,false); + setNextEnabled(pPage,true); + setHelpEnabled(pPage,false); + setFinishEnabled(pPage,false); + + // packager informations + pPage = new QWidget(this); + pLayout = new QGridLayout(pPage); + + pLabel = new QLabel(pPage); + pLabel->setText(__tr2qs_ctx("Here you need to provide informations about you (the packager) and a short description of the package you're creating.","addon")); + pLabel->setTextFormat(Qt::RichText); + pLayout->addWidget(pLabel,0,0,1,2); + + pLabel = new QLabel(pPage); + pLabel->setText(__tr2qs_ctx("Package Author:","addon")); + pLayout->addWidget(pLabel,1,0); + + m_pPackagerNameEdit = new QLineEdit(pPage); + m_pPackagerNameEdit->setText(szPackageAuthor); + pLayout->addWidget(m_pPackagerNameEdit,1,1); + + pLabel = new QLabel(pPage); + pLabel->setText(__tr2qs_ctx("Package Name:","addon")); + pLayout->addWidget(pLabel,2,0); + + m_pPackageNameEdit = new QLineEdit(pPage); + m_pPackageNameEdit->setText(szPackageName); + pLayout->addWidget(m_pPackageNameEdit,2,1); + + pLabel = new QLabel(pPage); + pLabel->setText(__tr2qs_ctx("Package Version:","addon")); + pLayout->addWidget(pLabel,3,0); + + m_pPackageVersionEdit = new QLineEdit(pPage); + m_pPackageVersionEdit->setText(szPackageVersion); + pLayout->addWidget(m_pPackageVersionEdit,3,1); + + pLabel = new QLabel(pPage); + pLabel->setText(__tr2qs_ctx("Package Description:","addon")); + pLayout->addWidget(pLabel,4,0); + + m_pPackageDescriptionEdit = new KviTalTextEdit(pPage); + m_pPackageDescriptionEdit->setBackgroundRole(QPalette::Window); + m_pPackageDescriptionEdit->setText(szPackageDescription); + pLayout->addWidget(m_pPackageDescriptionEdit,4,1,1,2); + pLayout->setRowStretch(1,1); + + addPage(pPage,__tr2qs_ctx("Package Informations","addon")); + setBackEnabled(pPage,true); + setHelpEnabled(pPage,false); + setNextEnabled(pPage,true); + setFinishEnabled(pPage,false); + + // select script files + + // select image dir + + // select help dir + + // select sound dir + + + + // final results + pPage = new QWidget(this); + pLayout = new QGridLayout(pPage); + + pLabel = new QLabel(pPage); + pLabel->setText(__tr2qs_ctx("Here there are the informations you provided. If they are correct, hit the \"Finish\" button to complete the packaging operations.","addon")); + pLayout->addWidget(pLabel,0,0,1,2); + + pLabel = new QLabel(pPage); + pLabel->setText(__tr2qs_ctx("Package Author:","addon")); + pLayout->addWidget(pLabel,1,0); + + pLabel = new QLabel(pPage); + pLabel->setText(m_pPackagerNameEdit->text()); + pLayout->addWidget(pLabel,1,1); + + pLabel = new QLabel(pPage); + pLabel->setText(__tr2qs_ctx("Package Name:","addon")); + pLayout->addWidget(pLabel,2,0); + + pLabel = new QLabel(pPage); + pLabel->setText(m_pPackageNameEdit->text()); + pLayout->addWidget(pLabel,2,1); + + pLabel = new QLabel(pPage); + pLabel->setText(__tr2qs_ctx("Package Version:","addon")); + pLayout->addWidget(pLabel,3,0); + + pLabel = new QLabel(pPage); + pLabel->setText(m_pPackageVersionEdit->text()); + pLayout->addWidget(pLabel,3,1); + + pLabel = new QLabel(pPage); + pLabel->setText(__tr2qs_ctx("Package Description:","addon")); + pLayout->addWidget(pLabel,4,0); + + pLabel = new QLabel(pPage); + pLabel->setText(m_pPackageDescriptionEdit->text()); + pLayout->addWidget(pLabel,4,1,1,2); + pLayout->setRowStretch(1,1); + + addPage(pPage,__tr2qs_ctx("Package Path","addon")); + setBackEnabled(pPage,true); + setHelpEnabled(pPage,false); + setNextEnabled(pPage,false); + setFinishEnabled(pPage,true); +} + +KviPackAddonDialog::~KviPackAddonDialog() +{ +} + +void KviPackAddonDialog::accept() +{ + if(!packAddon())return; + KviTalWizard::accept(); +} + +bool KviPackAddonDialog::packAddon() +{ + //m_pPathSelector->commit(); + + QString szPackageAuthor = m_pPackagerNameEdit->text(); + QString szPackageName = m_pPackageNameEdit->text(); + QString szPackageDescription = m_pPackageDescriptionEdit->text(); + QString szPackageVersion = m_pPackageVersionEdit->text(); + + QString szTmp = QDateTime::currentDateTime().toString(); + KviPackageWriter f; + f.addInfoField("PackageType","AddonPack"); + f.addInfoField("AddonPackVersion","1"); + f.addInfoField("Name",szPackageName); + f.addInfoField("Version",szPackageVersion); + f.addInfoField("Author",szPackageAuthor); + f.addInfoField("Description",szPackageDescription); + f.addInfoField("Date",szTmp); + f.addInfoField("Application","KVIrc " KVI_VERSION "." KVI_SOURCES_DATE); +/* + szTmp.setNum(m_pThemeInfoList->count()); + f.addInfoField("AddonCount",szTmp); + + int iIdx = 0; + for(KviThemeInfo * pInfo = m_pThemeInfoList->first();pInfo;pInfo = m_pThemeInfoList->next()) + { + KviQString::sprintf(szTmp,"Theme%dName",iIdx); + f.addInfoField(szTmp,pInfo->name()); + KviQString::sprintf(szTmp,"Theme%dVersion",iIdx); + f.addInfoField(szTmp,pInfo->version()); + KviQString::sprintf(szTmp,"Theme%dDescription",iIdx); + f.addInfoField(szTmp,pInfo->description()); + KviQString::sprintf(szTmp,"Theme%dDate",iIdx); + f.addInfoField(szTmp,pInfo->date()); + KviQString::sprintf(szTmp,"Theme%dSubdirectory",iIdx); + f.addInfoField(szTmp,pInfo->subdirectory()); + KviQString::sprintf(szTmp,"Theme%dAuthor",iIdx); + f.addInfoField(szTmp,pInfo->author()); + KviQString::sprintf(szTmp,"Theme%dApplication",iIdx); + f.addInfoField(szTmp,pInfo->application()); + KviQString::sprintf(szTmp,"Theme%dThemeEngineVersion",iIdx); + f.addInfoField(szTmp,pInfo->themeEngineVersion()); + + if(!f.addDirectory(pInfo->absoluteDirectory(),pInfo->subdirectory())) + { + szTmp = __tr2qs_ctx("Packaging failed","addon"); + szTmp += ": "; + szTmp += f.lastError(); + QMessageBox::critical(this,__tr2qs_ctx("Export Addon - KVIrc","addon"),szTmp,QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton); + } + + iIdx++; + } + + if(!f.pack(m_szPackagePath)) + { + szTmp = __tr2qs_ctx("Packaging failed","addon"); + szTmp += ": "; + szTmp += f.lastError(); + QMessageBox::critical(this,__tr2qs_ctx("Export Addon - KVIrc","addon"),szTmp,QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton); + return false; + } + */ + + QMessageBox::information(this,__tr2qs_ctx("Export Addon - KVIrc","addon"),__tr2qs("Package saved succesfully"),QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton); + + return true; +} diff --git a/src/modules/addon/packaddondialog.h b/src/modules/addon/packaddondialog.h new file mode 100644 index 000000000..f60ad01df --- /dev/null +++ b/src/modules/addon/packaddondialog.h @@ -0,0 +1,54 @@ +#ifndef _PACKADDONDIALOG_H_ +#define _PACKADDONDIALOG_H_ +//============================================================================= +// +// File : packaddondialog.h +// Created on Sat 03 May 2008 01:40:44 by Elvio Basello +// +// This file is part of the KVIrc IRC Client distribution +// Copyright (C) 2008 Elvio Basello <hellvis69 at netsons dot org> +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc. ,59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +//============================================================================= + +#include "kvi_settings.h" +#include "kvi_pointerlist.h" +#include "kvi_tal_wizard.h" + +class QString; +class QLineEdit; +class KviTalTextEdit; +class KviFileSelector; + +class KviPackAddonDialog : public KviTalWizard +{ + Q_OBJECT +public: + KviPackAddonDialog(QWidget * pParent); + virtual ~KviPackAddonDialog(); +protected: + QString m_szPackagePath; + KviFileSelector * m_pPathSelector; + QLineEdit * m_pPackagerNameEdit; + QLineEdit * m_pPackageNameEdit; + QLineEdit * m_pPackageVersionEdit; + KviTalTextEdit * m_pPackageDescriptionEdit; +protected: + virtual void accept(); + bool packAddon(); +}; + +#endif //!_PACKADDONDIALOG_H_ |
