summaryrefslogtreecommitdiffstats
path: root/src/modules/theme
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/theme')
-rw-r--r--src/modules/theme/Makefile.am36
-rw-r--r--src/modules/theme/libkvitheme.cpp193
-rw-r--r--src/modules/theme/managementdialog.cpp459
-rw-r--r--src/modules/theme/managementdialog.h109
-rw-r--r--src/modules/theme/packthemedialog.cpp489
-rw-r--r--src/modules/theme/packthemedialog.h66
-rw-r--r--src/modules/theme/savethemedialog.cpp301
-rw-r--r--src/modules/theme/savethemedialog.h71
-rw-r--r--src/modules/theme/themefunctions.cpp396
-rw-r--r--src/modules/theme/themefunctions.h54
10 files changed, 2174 insertions, 0 deletions
diff --git a/src/modules/theme/Makefile.am b/src/modules/theme/Makefile.am
new file mode 100644
index 00000000..5417e9e5
--- /dev/null
+++ b/src/modules/theme/Makefile.am
@@ -0,0 +1,36 @@
+###############################################################################
+# KVirc IRC client Makefile - 30.12.2006 Szymon Stefanek <pragma at kvirc dot net>
+###############################################################################
+
+AM_CPPFLAGS = -I$(SS_TOPSRCDIR)/src/kvilib/include/ -I$(SS_TOPSRCDIR)/src/kvirc/include/ \
+$(SS_INCDIRS) $(SS_CPPFLAGS) -DGLOBAL_KVIRC_DIR=\"$(globalkvircdir)\"
+
+pluglib_LTLIBRARIES = libkvitheme.la
+
+libkvitheme_la_LDFLAGS = -module -avoid-version $(SS_LDFLAGS) $(SS_LIBDIRS)
+
+libkvitheme_la_SOURCES = libkvitheme.cpp \
+ managementdialog.cpp \
+ packthemedialog.cpp \
+ savethemedialog.cpp \
+ themefunctions.cpp
+
+nodist_libkvitheme_la_SOURCES = moc_managementdialog.cpp \
+ moc_packthemedialog.cpp \
+ moc_savethemedialog.cpp
+
+libkvitheme_la_LIBADD = $(SS_LIBLINK) ../../kvilib/build/libkvilib.la
+
+noinst_HEADERS= managementdialog.h \
+ packthemedialog.h \
+ savethemedialog.h \
+ themefunctions.h
+
+moc_managementdialog.cpp: managementdialog.h
+ $(SS_QT_MOC) $< -o $@
+
+moc_packthemedialog.cpp: packthemedialog.h
+ $(SS_QT_MOC) $< -o $@
+
+moc_savethemedialog.cpp: savethemedialog.h
+ $(SS_QT_MOC) $< -o $@
diff --git a/src/modules/theme/libkvitheme.cpp b/src/modules/theme/libkvitheme.cpp
new file mode 100644
index 00000000..cba1b4e8
--- /dev/null
+++ b/src/modules/theme/libkvitheme.cpp
@@ -0,0 +1,193 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+// File : libkvitheme.cpp
+// Created on Sat 30 Dec 2006 14:54:56 by Szymon Stefanek
+//
+// This toolbar is part of the KVirc irc client distribution
+// Copyright (C) 2006 Szymon Stefanek (pragma at kvirc dot net)
+//
+// 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. ,51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "kvi_module.h"
+#include "kvi_locale.h"
+#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"
+#include "kvi_mirccntrl.h"
+#include "kvi_config.h"
+#include "kvi_sourcesdate.h"
+#include "kvi_fileutils.h"
+#include "kvi_filedialog.h"
+
+#include "managementdialog.h"
+#include "themefunctions.h"
+
+#include <qfileinfo.h>
+
+QRect g_rectManagementDialogGeometry(0,0,0,0);
+
+
+/*
+ @doc: theme.install
+ @type:
+ command
+ @title:
+ theme.install
+ @short:
+ Shows the theme theme management editor
+ @syntax:
+ theme.install <package_path:string>
+ @description:
+ Attempts to install the themes in the package specified by <package_path>.
+*/
+
+static bool theme_kvs_cmd_install(KviKvsModuleCommandCall * c)
+{
+ QString szThemePackFile;
+
+ KVSM_PARAMETERS_BEGIN(c)
+ KVSM_PARAMETER("package_path",KVS_PT_STRING,0,szThemePackFile)
+ KVSM_PARAMETERS_END(c)
+
+ QString szError;
+ if(!KviThemeFunctions::installThemePackage(szThemePackFile,szError))
+ {
+ c->error(__tr2qs_ctx("Error installing theme package: %Q","theme"),&szError);
+ return false;
+ }
+
+ return true;
+}
+
+/*
+ @doc: theme.screenshot
+ @type:
+ command
+ @title:
+ theme.screenshot
+ @short:
+ Makes a screenshot of the KVIrc window
+ @syntax:
+ theme.screenshot [file_name_path:string]
+ @description:
+ Makes a screenshot of the KVIrc main window
+ and saves it in the specified file. If [file_name_path]
+ is not specified then a save file dialog is shown.
+*/
+
+static bool theme_kvs_cmd_screenshot(KviKvsModuleCommandCall * c)
+{
+ QString szFileName;
+
+ KVSM_PARAMETERS_BEGIN(c)
+ KVSM_PARAMETER("file_name_path",KVS_PT_STRING,KVS_PF_OPTIONAL,szFileName)
+ KVSM_PARAMETERS_END(c)
+
+
+ KviFileUtils::adjustFilePath(szFileName);
+
+ QString szTmp;
+ c->enterBlockingSection();
+
+ bool bResult = KviFileDialog::askForSaveFileName(szTmp,__tr2qs_ctx("Choose a file to save the screenshot to","theme"),szFileName,"*.png");
+
+ if(!c->leaveBlockingSection())return false; // need to stop immediately
+ if(!bResult)return true;
+
+ szFileName = szTmp;
+
+ if(szFileName.isEmpty())return true; // done
+ KviFileUtils::adjustFilePath(szFileName);
+ if(QFileInfo(szFileName).extension(false)!="png")
+ szFileName+=".png";
+
+ QString szError;
+ if(!KviThemeFunctions::makeKVIrcScreenshot(szFileName))
+ {
+ c->error(__tr2qs_ctx("Error making screenshot","theme")); // FIXME: a nicer error ?
+ return false;
+ }
+
+ return true;
+}
+
+/*
+ @doc: theme.dialog
+ @type:
+ command
+ @title:
+ theme.dialog
+ @short:
+ Shows the theme theme management editor
+ @syntax:
+ theme.dialog
+ @description:
+ Shows the theme theme management editor
+*/
+
+static bool theme_kvs_cmd_dialog(KviKvsModuleCommandCall * c)
+{
+ KviThemeManagementDialog::display();
+ return true;
+}
+
+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,"screenshot",theme_kvs_cmd_screenshot);
+
+ QString szBuf;
+ m->getDefaultConfigFileName(szBuf);
+ KviConfig cfg(szBuf,KviConfig::Read);
+ g_rectManagementDialogGeometry = cfg.readRectEntry("EditorGeometry",QRect(10,10,390,440));
+
+ return true;
+}
+
+static bool theme_module_cleanup(KviModule *m)
+{
+ KviThemeManagementDialog::cleanup();
+
+ QString szBuf;
+ m->getDefaultConfigFileName(szBuf);
+ KviConfig cfg(szBuf,KviConfig::Write);
+ cfg.writeEntry("EditorGeometry",g_rectManagementDialogGeometry);
+
+ return true;
+}
+
+static bool theme_module_can_unload(KviModule * m)
+{
+ return (!KviThemeManagementDialog::instance());
+}
+
+
+KVIRC_MODULE(
+ "theme", // module name
+ "1.0.0", // module version
+ "Copyright (C) 2006 Szymon Stefanek (pragma at kvirc dot net)", // author & (C)
+ "Theme management functions",
+ theme_module_init,
+ theme_module_can_unload,
+ 0,
+ theme_module_cleanup
+)
diff --git a/src/modules/theme/managementdialog.cpp b/src/modules/theme/managementdialog.cpp
new file mode 100644
index 00000000..bfd75283
--- /dev/null
+++ b/src/modules/theme/managementdialog.cpp
@@ -0,0 +1,459 @@
+//=============================================================================
+//
+// File : managementdialog.cpp
+// Created on Sat 30 Dec 2006 14:54:56 by Szymon Stefanek
+//
+// This file is part of the KVIrc IRC Client distribution
+// Copyright (C) 2006 Szymon Stefanek <pragma at kvirc dot net>
+//
+// 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. ,51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+//=============================================================================
+
+#define LVI_ICON_SIZE 32
+#define LVI_BORDER 4
+#define LVI_SPACING 8
+#define LVI_MINIMUM_TEXT_WIDTH 300
+#define LVI_MINIMUM_CELL_WIDTH (LVI_MINIMUM_TEXT_WIDTH + LVI_BORDER + LVI_ICON_SIZE + LVI_SPACING + LVI_BORDER)
+
+#include "managementdialog.h"
+#include "packthemedialog.h"
+#include "savethemedialog.h"
+#include "themefunctions.h"
+
+#include "kvi_iconmanager.h"
+#include "kvi_msgbox.h"
+
+
+#include <qlayout.h>
+#include <qpushbutton.h>
+#include "kvi_tal_listbox.h"
+#include <qlineedit.h>
+#include <kvi_tal_textedit.h>
+#include <qregexp.h>
+#include <qmessagebox.h>
+#include <qdir.h>
+#include <qstringlist.h>
+#include <qdatetime.h>
+#include <qfiledialog.h>
+#include "kvi_tal_popupmenu.h"
+#include <qcombobox.h>
+#include <qpainter.h>
+#include <qtooltip.h>
+#include <qimage.h>
+#include <kvi_tal_textedit.h>
+//#include <qmultilineedit.h>
+#ifdef COMPILE_USE_QT4
+#include <QCloseEvent>
+#endif
+#include <qbuffer.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_internalcmd.h"
+#include "kvi_styled_controls.h"
+#include "kvi_doublebuffer.h"
+#include "kvi_packagefile.h"
+#include "kvi_fileextensions.h"
+#include "kvi_filedialog.h"
+#include "kvi_dynamictooltip.h"
+
+#include <stdlib.h> // rand & srand
+
+extern QRect g_rectManagementDialogGeometry;
+
+
+
+KviThemeListBoxItem::KviThemeListBoxItem(KviTalListBox * box,KviThemeInfo * inf)
+: KviTalListBoxText(box)
+{
+ m_pThemeInfo = inf;
+ QString t;
+ t = "<nobr><b>";
+ t += inf->name();
+ t += "</b>";
+
+ if(!inf->version().isEmpty()) {
+ t += "[";
+ t += inf->version();
+ t += "]";
+ }
+
+ if(!inf->author().isEmpty()) {
+ t += " <font color=\"#a0a0a0\"> ";
+ t += __tr2qs_ctx("by","theme");
+ t += " ";
+ t += inf->author();
+ t += "</font>";
+ }
+
+ t += "</nobr>";
+ t += "<br><nobr><font size=\"-1\">";
+ t += inf->description();
+ t += "</font></nobr>";
+ m_pText = new KviTalSimpleRichText(t,box->font());
+ int iWidth = box->visibleWidth();
+ if(iWidth < LVI_MINIMUM_CELL_WIDTH)iWidth = LVI_MINIMUM_CELL_WIDTH;
+ iWidth -= LVI_BORDER + LVI_ICON_SIZE + LVI_SPACING + LVI_BORDER;
+ m_pText->setWidth(iWidth);
+}
+
+KviThemeListBoxItem::~KviThemeListBoxItem()
+{
+ delete m_pThemeInfo;
+ delete m_pText;
+}
+
+void KviThemeListBoxItem::paint(QPainter * p)
+{
+ KviTalListBoxText::paint(p);
+ p->drawPixmap(LVI_BORDER,LVI_BORDER, *(g_pIconManager->getBigIcon(QString(KVI_BIGICON_THEME))) );
+ int afterIcon = LVI_BORDER + LVI_ICON_SIZE + LVI_SPACING;
+ int www = p->window().width() - (afterIcon + LVI_BORDER);
+ m_pText->setWidth(www);
+ m_pText->draw(p,afterIcon,LVI_BORDER,QRect(afterIcon,LVI_BORDER,www,p->window().height() - (LVI_BORDER * 2)),listBox()->viewport()->colorGroup());
+}
+
+int KviThemeListBoxItem::height(const KviTalListBox * lb) const
+{
+ int iHeight = m_pText->height() + (2 * LVI_BORDER);
+ if(iHeight < (LVI_ICON_SIZE + (2 * LVI_BORDER)))iHeight = LVI_ICON_SIZE + (2 * LVI_BORDER);
+ return iHeight;
+}
+
+KviThemeManagementDialog * KviThemeManagementDialog::m_pInstance = 0;
+
+
+KviThemeManagementDialog::KviThemeManagementDialog(QWidget * parent)
+: QDialog(parent,"theme_options_widget")
+{
+ setCaption(__tr2qs_ctx("Manage Themes - KVIrc","theme"));
+ setIcon(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_THEME)));
+
+ setModal(true);
+
+ m_pInstance = this;
+
+ QGridLayout * g = new QGridLayout(this,3,2,4,4);
+
+ KviTalHBox *hb = new KviTalHBox(this);
+ g->addMultiCellWidget(hb,0,0,0,1);
+
+ KviStyledToolButton * tb;
+ QFrame * sep;
+
+ tb = new KviStyledToolButton(hb);
+ tb->setIconSet(*(g_pIconManager->getBigIcon(KVI_BIGICON_SAVE)));
+ tb->setUsesBigPixmap(true);
+ QToolTip::add(tb,__tr2qs_ctx("Save Current Theme...","theme"));
+ connect(tb,SIGNAL(clicked()),this,SLOT(saveCurrentTheme()));
+
+ sep = new QFrame(hb);
+ sep->setFrameStyle(QFrame::VLine | QFrame::Sunken);
+ sep->setMinimumWidth(12);
+
+ m_pPackThemeButton = new KviStyledToolButton(hb);
+ m_pPackThemeButton->setIconSet(*(g_pIconManager->getBigIcon(KVI_BIGICON_PACK)));
+ m_pPackThemeButton->setUsesBigPixmap(true);
+ QToolTip::add(m_pPackThemeButton,__tr2qs_ctx("Export Selected Themes to a Distributable Package","theme"));
+ connect(m_pPackThemeButton,SIGNAL(clicked()),this,SLOT(packTheme()));
+
+ m_pDeleteThemeButton = new KviStyledToolButton(hb);
+ m_pDeleteThemeButton->setIconSet(*(g_pIconManager->getBigIcon(KVI_BIGICON_REMOVE)));
+ m_pDeleteThemeButton->setUsesBigPixmap(true);
+ QToolTip::add(m_pDeleteThemeButton,__tr2qs_ctx("Delete Selected Themes","theme"));
+ connect(m_pDeleteThemeButton,SIGNAL(clicked()),this,SLOT(deleteTheme()));
+
+ sep = new QFrame(hb);
+ sep->setFrameStyle(QFrame::VLine | QFrame::Sunken);
+ sep->setMinimumWidth(12);
+
+ tb = new KviStyledToolButton(hb);
+ tb->setIconSet(*(g_pIconManager->getBigIcon(KVI_BIGICON_OPEN)));
+ tb->setUsesBigPixmap(true);
+ QToolTip::add(tb,__tr2qs_ctx("Install Theme Package From Disk","theme"));
+ connect(tb,SIGNAL(clicked()),this,SLOT(installFromFile()));
+
+ tb = new KviStyledToolButton(hb);
+ tb->setIconSet(*(g_pIconManager->getBigIcon(KVI_BIGICON_WWW)));
+ tb->setUsesBigPixmap(true);
+ QToolTip::add(tb,__tr2qs_ctx("Get More Themes...","theme"));
+ connect(tb,SIGNAL(clicked()),this,SLOT(getMoreThemes()));
+
+ QWidget *w= new QWidget(hb);
+ w->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Minimum);
+
+ m_pListBox = new KviTalListBox(this);
+ m_pListBox->setMinimumHeight(400);
+ m_pListBox->setMinimumWidth(400);
+ m_pListBox->setSelectionMode(KviTalListBox::Extended);
+ connect(m_pListBox,SIGNAL(doubleClicked(KviTalListBoxItem *)),this,SLOT(applyTheme(KviTalListBoxItem *)));
+ connect(m_pListBox,SIGNAL(contextMenuRequested(KviTalListBoxItem *,const QPoint &)),
+ this,SLOT(contextMenuRequested(KviTalListBoxItem *,const QPoint &)));
+ connect(m_pListBox,SIGNAL(selectionChanged()),this,SLOT(enableDisableButtons()));
+ g->addMultiCellWidget(m_pListBox,1,1,0,1);
+
+ KviDynamicToolTip * tip = new KviDynamicToolTip(m_pListBox);
+ connect(tip,SIGNAL(tipRequest(KviDynamicToolTip *,const QPoint &)),this,SLOT(tipRequest(KviDynamicToolTip *,const QPoint &)));
+
+ QPushButton * b = new QPushButton(__tr2qs("Close"),this);
+ connect(b,SIGNAL(clicked()),this,SLOT(closeClicked()));
+ g->addWidget(b,2,1);
+
+ g->setRowStretch(1,0);
+ g->setColStretch(0,1);
+
+ fillThemeBox();
+ m_pContextPopup = new KviTalPopupMenu(this);
+
+ if(g_rectManagementDialogGeometry.y() < 5)
+ {
+ g_rectManagementDialogGeometry.setY(5);
+ }
+ resize(g_rectManagementDialogGeometry.width(),
+ g_rectManagementDialogGeometry.height());
+ move(g_rectManagementDialogGeometry.x(),
+ g_rectManagementDialogGeometry.y());
+}
+
+KviThemeManagementDialog::~KviThemeManagementDialog()
+{
+ g_rectManagementDialogGeometry = QRect(pos().x(),pos().y(),size().width(),size().height());
+ m_pInstance = 0;
+}
+
+void KviThemeManagementDialog::closeClicked()
+{
+ delete this;
+ m_pInstance = 0;
+}
+
+
+void KviThemeManagementDialog::display()
+{
+ if(!m_pInstance)
+ m_pInstance = new KviThemeManagementDialog(g_pFrame);
+ m_pInstance->show();
+}
+
+void KviThemeManagementDialog::cleanup()
+{
+ if(!m_pInstance)return;
+ delete m_pInstance;
+ m_pInstance = 0;
+}
+
+void KviThemeManagementDialog::packTheme()
+{
+ KviPointerList<KviThemeInfo> dl;
+ dl.setAutoDelete(false);
+ for(KviThemeListBoxItem * it = (KviThemeListBoxItem *)m_pListBox->firstItem();it;it = (KviThemeListBoxItem *)it->next())
+ {
+ if(it->isSelected())
+ dl.append(it->themeInfo());
+ }
+ if(dl.isEmpty())return;
+
+ KviPackThemeDialog * pDialog = new KviPackThemeDialog(this,&dl);
+ pDialog->exec();
+ delete pDialog;
+
+}
+
+void KviThemeManagementDialog::contextMenuRequested(KviTalListBoxItem * it,const QPoint & pos)
+{
+ if(it)
+ {
+ m_pListBox->setCurrentItem(it);
+ m_pContextPopup->clear();
+ m_pContextPopup->insertItem(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_MINUS)),__tr2qs_ctx("&Remove Theme","theme"),this,SLOT(deleteTheme()));
+ m_pContextPopup->insertItem(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_ACCEPT)),__tr2qs_ctx("&Apply Theme","theme"),this,SLOT(applyCurrentTheme()));
+ m_pContextPopup->popup(pos);
+ }
+}
+
+void KviThemeManagementDialog::applyTheme ( KviTalListBoxItem * it)
+{
+ if(it)m_pListBox->setCurrentItem(it);
+ applyCurrentTheme();
+}
+
+void KviThemeManagementDialog::applyCurrentTheme()
+{
+ KviThemeListBoxItem * it = (KviThemeListBoxItem *)m_pListBox->item(m_pListBox->currentItem());
+ if(!it)return;
+
+ 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()->absoluteDirectory();
+ if(szPath.isEmpty())return;
+
+ KviThemeInfo out;
+ if(!KviTheme::load(szPath,out))
+ {
+ QString szErr = out.lastError();
+ QString szMsg;
+ KviQString::sprintf(szMsg,__tr2qs_ctx("Failed to apply the specified theme: %Q","theme"),&szErr);
+ QMessageBox::critical(this,__tr2qs_ctx("Apply theme - KVIrc","theme"),szMsg,
+ QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton);
+
+ }
+ }
+}
+
+void KviThemeManagementDialog::deleteTheme()
+{
+ for(KviThemeListBoxItem * pItem = (KviThemeListBoxItem *)m_pListBox->firstItem();pItem;pItem = (KviThemeListBoxItem *)pItem->next())
+ {
+ if(pItem->isSelected())
+ {
+ if(!KviMessageBox::yesNo(__tr2qs_ctx("Delete Theme - KVIrc","theme"),
+ __tr2qs_ctx("Do you really wish to delete theme \"%Q\" (version %Q)?","theme"),
+ &(pItem->themeInfo()->name()),&(pItem->themeInfo()->version())))goto jump_out;
+
+ KviFileUtils::deleteDir(pItem->themeInfo()->absoluteDirectory());
+ }
+ }
+jump_out:
+ fillThemeBox();
+}
+
+void KviThemeManagementDialog::installFromFile()
+{
+ int iThemeCount=0;
+ QString szFileName;
+ QString szError;
+
+ if(!KviFileDialog::askForOpenFileName(szFileName,__tr2qs_ctx("Open Theme - KVIrc","theme"),QString::null,"*.kvt"))
+ return;
+
+ if(!KviThemeFunctions::installThemePackage(szFileName,szError,this))
+ {
+ KviMessageBox::information(szError);
+ return;
+ }
+ fillThemeBox();
+}
+
+void KviThemeManagementDialog::getMoreThemes()
+{
+ if(!g_pFrame)return;
+ g_pFrame->executeInternalCommand(KVI_INTERNALCOMMAND_OPENURL_KVIRC_THEMES);
+}
+
+void KviThemeManagementDialog::saveCurrentTheme()
+{
+ KviSaveThemeDialog * pSaveThemeDialog = new KviSaveThemeDialog(this);
+ pSaveThemeDialog->exec();
+ delete pSaveThemeDialog;
+ fillThemeBox();
+}
+
+void KviThemeManagementDialog::fillThemeBox(const QString &szDir)
+{
+ QDir d(szDir);
+
+ QStringList sl = d.entryList(QDir::Dirs);
+
+ for(QStringList::Iterator it = sl.begin();it != sl.end();++it)
+ {
+ if(*it == ".")continue;
+ if(*it == "..")continue;
+
+ QString szTest = szDir;
+ szTest += KVI_PATH_SEPARATOR_CHAR;
+ szTest += *it;
+
+ KviThemeInfo * inf = new KviThemeInfo();
+ if(inf->loadFromDirectory(szTest))
+ {
+ inf->setSubdirectory(*it);
+ KviThemeListBoxItem * item = 0;
+ item = new KviThemeListBoxItem(m_pListBox,inf);
+ } else {
+ delete inf;
+ }
+ }
+}
+
+void KviThemeManagementDialog::fillThemeBox()
+{
+ m_pListBox->clear();
+
+ QString szDir;
+ g_pApp->getGlobalKvircDirectory(szDir,KviApp::Themes);
+ fillThemeBox(szDir);
+ g_pApp->getLocalKvircDirectory(szDir,KviApp::Themes);
+ fillThemeBox(szDir);
+
+ enableDisableButtons();
+}
+
+bool KviThemeManagementDialog::hasSelectedItems()
+{
+ for(KviTalListBoxItem * it = m_pListBox->firstItem();it;it = it->next())
+ {
+ if(it->isSelected())return true;
+ }
+ return false;
+}
+
+
+void KviThemeManagementDialog::enableDisableButtons()
+{
+ bool b = hasSelectedItems();
+ m_pPackThemeButton->setEnabled(b);
+ m_pDeleteThemeButton->setEnabled(b);
+}
+
+void KviThemeManagementDialog::closeEvent(QCloseEvent * e)
+{
+ e->ignore();
+ delete this;
+}
+
+void KviThemeManagementDialog::tipRequest(KviDynamicToolTip *pTip,const QPoint &pnt)
+{
+ KviThemeListBoxItem * it = (KviThemeListBoxItem *)(m_pListBox->itemAt(pnt));
+
+ if(!it)return;
+
+ KviThemeInfo * pThemeInfo = it->themeInfo();
+
+ QString szThemeDescription;
+
+ KviThemeFunctions::getThemeHtmlDescription(
+ szThemeDescription,
+ pThemeInfo->name(),
+ pThemeInfo->version(),
+ pThemeInfo->description(),
+ pThemeInfo->subdirectory(),
+ pThemeInfo->application(),
+ pThemeInfo->author(),
+ pThemeInfo->date(),
+ pThemeInfo->themeEngineVersion(),
+ pThemeInfo->mediumScreenshot(),
+ 0
+ );
+
+ pTip->tip(m_pListBox->itemRect(it),szThemeDescription);
+}
diff --git a/src/modules/theme/managementdialog.h b/src/modules/theme/managementdialog.h
new file mode 100644
index 00000000..52ae0f86
--- /dev/null
+++ b/src/modules/theme/managementdialog.h
@@ -0,0 +1,109 @@
+#ifndef _MANAGEMENTDIALOG_H_
+#define _MANAGEMENTDIALOG_H_
+//=============================================================================
+//
+// File : managementdialog.h
+// Created on Sat 30 Dec 2006 14:54:56 by Szymon Stefanek
+//
+// This file is part of the KVIrc IRC Client distribution
+// Copyright (C) 2006 Szymon Stefanek <pragma at kvirc dot net>
+//
+// 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. ,51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+//=============================================================================
+
+#include "kvi_optionswidget.h"
+#include "kvi_pointerlist.h"
+#include "kvi_theme.h"
+
+#include <qdialog.h>
+#ifdef COMPILE_USE_QT4
+#include <q3simplerichtext.h>
+#define KviTalSimpleRichText Q3SimpleRichText
+#else
+#include <qsimplerichtext.h>
+#define KviTalSimpleRichText QSimpleRichText
+#endif
+#include "kvi_tal_listbox.h"
+#include <qcombobox.h>
+#include "kvi_tal_popupmenu.h"
+#include <qcursor.h>
+#include <kvi_tal_wizard.h>
+
+
+class QLineEdit;
+class KviTalTextEdit;
+class QPushButton;
+class QLabel;
+class QCheckBox;
+
+//class QMultiLineEdit;
+
+class KviDynamicToolTip;
+class KviStyledToolButton;
+
+
+class KviThemeListBoxItem : public KviTalListBoxText
+{
+public:
+ KviThemeListBoxItem(KviTalListBox * box,KviThemeInfo * inf);
+ virtual ~KviThemeListBoxItem();
+public:
+ KviThemeInfo * m_pThemeInfo;
+ KviTalSimpleRichText * m_pText;
+public:
+ KviThemeInfo * themeInfo(){ return m_pThemeInfo; };
+ virtual int height ( const KviTalListBox * lb ) const ;
+protected:
+ virtual void paint ( QPainter * painter );
+};
+
+
+class KviThemeManagementDialog : public QDialog
+{
+ Q_OBJECT
+public:
+ KviThemeManagementDialog(QWidget * parent);
+ virtual ~KviThemeManagementDialog();
+protected:
+ static KviThemeManagementDialog * m_pInstance;
+ KviTalListBox * m_pListBox;
+ KviTalPopupMenu * m_pContextPopup;
+ KviStyledToolButton * m_pDeleteThemeButton;
+ KviStyledToolButton * m_pPackThemeButton;
+public:
+ static KviThemeManagementDialog * instance(){ return m_pInstance; };
+ static void display();
+ static void cleanup();
+protected:
+ void fillThemeBox(const QString &szDir);
+ bool hasSelectedItems();
+ virtual void closeEvent(QCloseEvent * e);
+protected slots:
+ void saveCurrentTheme();
+ void getMoreThemes();
+ void installFromFile();
+ void fillThemeBox();
+ void deleteTheme();
+ void closeClicked();
+ void packTheme();
+ void applyTheme(KviTalListBoxItem *);
+ void applyCurrentTheme();
+ void enableDisableButtons();
+ void contextMenuRequested(KviTalListBoxItem * item, const QPoint & pos);
+ void tipRequest(KviDynamicToolTip *pTip,const QPoint &pnt);
+};
+
+#endif //!_MANAGEMENTDIALOG_H_
diff --git a/src/modules/theme/packthemedialog.cpp b/src/modules/theme/packthemedialog.cpp
new file mode 100644
index 00000000..88b248a8
--- /dev/null
+++ b/src/modules/theme/packthemedialog.cpp
@@ -0,0 +1,489 @@
+//=============================================================================
+//
+// File : packthemedialog.cpp
+// Created on Wed 03 Jan 2007 01:11:44 by Szymon Stefanek
+//
+// This file is part of the KVIrc IRC Client distribution
+// Copyright (C) 2007 Szymon Stefanek <pragma at kvirc dot net>
+//
+// 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. ,51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+//=============================================================================
+
+#include "packthemedialog.h"
+#include "themefunctions.h"
+
+#include <qlayout.h>
+#include <qpushbutton.h>
+#include <qlineedit.h>
+#include <qregexp.h>
+#include <qmessagebox.h>
+#include <qdir.h>
+#include <qcombobox.h>
+#include <qpainter.h>
+#include <qtooltip.h>
+#include <qimage.h>
+#include <kvi_tal_textedit.h>
+#ifdef COMPILE_USE_QT4
+#include <q3multilineedit.h>
+#include <QDateTime>
+#else
+#include <qmultilineedit.h>
+#endif
+#include <qbuffer.h>
+#include <qlabel.h>
+#include <qregexp.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"
+
+
+
+KviPackThemeDialog::KviPackThemeDialog(QWidget * pParent,KviPointerList<KviThemeInfo> * pThemeInfoList)
+: KviTalWizard(pParent)
+{
+ m_pThemeInfoList = pThemeInfoList;
+
+ KviThemeInfo * pThemeInfo;
+ QString szPackageName;
+ QString szPackageAuthor;
+ QString szPackageDescription;
+ QString szPackageVersion;
+
+ m_szPackagePath = QDir::homeDirPath();
+ KviQString::ensureLastCharIs(m_szPackagePath,QChar(KVI_PATH_SEPARATOR_CHAR));
+
+ bool bPackagePathSet = false;
+
+ if(m_pThemeInfoList->count() > 1)
+ {
+ szPackageName = "MyThemes";
+ szPackageAuthor = __tr2qs_ctx("Your name here","theme");
+ szPackageVersion = "1.0.0";
+ szPackageDescription = __tr2qs_ctx("Put a package description here...","theme");
+ } else {
+ if(m_pThemeInfoList->count() > 0)
+ {
+ pThemeInfo = m_pThemeInfoList->first();
+ szPackageName = pThemeInfo->subdirectory();
+ szPackageAuthor = pThemeInfo->author();
+ szPackageDescription = pThemeInfo->description();
+ szPackageVersion = pThemeInfo->version();
+
+ m_szPackagePath += pThemeInfo->subdirectory();
+ if(m_szPackagePath.find(QRegExp("[0-9]\\.[0-9]")) == -1)
+ {
+ m_szPackagePath += "-";
+ m_szPackagePath += szPackageVersion;
+ }
+ m_szPackagePath += ".";
+ m_szPackagePath += KVI_FILEEXTENSION_THEMEPACKAGE;
+
+ bPackagePathSet = true;
+ }
+ }
+
+ if(!bPackagePathSet)
+ {
+ m_szPackagePath += szPackageName;
+ m_szPackagePath += "-";
+ m_szPackagePath += szPackageVersion;
+ m_szPackagePath += ".";
+ m_szPackagePath += KVI_FILEEXTENSION_THEMEPACKAGE;
+ }
+
+ setCaption(__tr2qs_ctx("Export Theme - KVIrc","theme"));
+ setMinimumSize(400,350);
+
+ // welcome page ==================================================================================
+ QWidget * pPage = new QWidget(this);
+ QGridLayout * pLayout = new QGridLayout(pPage,2,1,4,4);
+
+ QLabel * pLabel = new QLabel(pPage);
+ QString szText = "<p>";
+ szText += __tr2qs_ctx("This procedure allows you to export the selected themes to a single package. It is useful when you want to distribute your themes to the public.","theme");
+ szText += "</p><p>";
+ szText += __tr2qs_ctx("You will be asked to provide a package name, a description and, if you want, an icon/screenshot.","theme");
+ szText += "</p><p>";
+ szText += __tr2qs_ctx("Hit the \"Next\" button to begin.","theme");
+ szText += "<p>";
+
+ pLabel->setText(szText);
+ pLayout->addWidget(pLabel,0,0);
+ pLayout->setRowStretch(1,1);
+
+ addPage(pPage,__tr2qs_ctx("Welcome","theme"));
+ setBackEnabled(pPage,false);
+ setNextEnabled(pPage,true);
+ setHelpEnabled(pPage,false);
+ setFinishEnabled(pPage,false);
+
+ // theme data name ================================================================================
+
+ pPage = new QWidget(this);
+ pLayout = new QGridLayout(pPage,2,1,4,4);
+
+ pLabel = new QLabel(pPage);
+ pLabel->setText(__tr2qs_ctx("This is the information list for the themes you're packaging. If it looks OK press \"Next\" to continue, otherwise press \"Cancel\" and rewiew your themes first.","theme"));
+ pLabel->setTextFormat(Qt::RichText);
+ pLayout->addWidget(pLabel,0,0);
+
+ QString szThemesDescription = "<html><body bgcolor=\"#ffffff\">";
+
+ int iIdx = 0;
+ QPixmap pixScreenshot;
+ QString szScreenshotPath;
+
+ for(pThemeInfo = m_pThemeInfoList->first();pThemeInfo;pThemeInfo = m_pThemeInfoList->next())
+ {
+ QString szThemeDescription;
+
+ if(pixScreenshot.isNull())
+ {
+ pixScreenshot = pThemeInfo->smallScreenshot();
+ if(!pixScreenshot.isNull())
+ szScreenshotPath = pThemeInfo->smallScreenshotPath();
+ }
+
+ KviThemeFunctions::getThemeHtmlDescription(
+ szThemeDescription,
+ pThemeInfo->name(),
+ pThemeInfo->version(),
+ pThemeInfo->description(),
+ pThemeInfo->subdirectory(),
+ pThemeInfo->application(),
+ pThemeInfo->author(),
+ pThemeInfo->date(),
+ pThemeInfo->themeEngineVersion(),
+ pThemeInfo->smallScreenshot(),
+ iIdx
+ );
+
+ if(iIdx > 0)
+ szThemesDescription += "<hr>";
+ szThemesDescription += szThemeDescription;
+ iIdx++;
+ }
+
+ szThemesDescription += "</body></html>";
+
+ KviTalTextEdit * pTextEdit = new KviTalTextEdit(pPage);
+ pTextEdit->setPaper(QBrush(QColor(255,255,255)));
+ pTextEdit->setReadOnly(true);
+ pTextEdit->setText(szThemesDescription);
+ pLayout->addWidget(pTextEdit,1,0);
+ pLayout->setRowStretch(1,1);
+
+ addPage(pPage,__tr2qs_ctx("Theme Data","theme"));
+ setBackEnabled(pPage,true);
+ setHelpEnabled(pPage,false);
+ setNextEnabled(pPage,true);
+ setFinishEnabled(pPage,false);
+
+ // packager informations ================================================================================
+
+ pPage = new QWidget(this);
+ pLayout = new QGridLayout(pPage,5,2,4,4);
+
+ 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.","theme"));
+ pLabel->setTextFormat(Qt::RichText);
+ pLayout->addMultiCellWidget(pLabel,0,0,0,1);
+
+ pLabel = new QLabel(pPage);
+ pLabel->setText(__tr2qs_ctx("Package Name:","theme"));
+ pLayout->addWidget(pLabel,1,0);
+
+ m_pPackageNameEdit = new QLineEdit(pPage);
+ m_pPackageNameEdit->setText(szPackageName);
+ pLayout->addWidget(m_pPackageNameEdit,1,1);
+
+ pLabel = new QLabel(pPage);
+ pLabel->setText(__tr2qs_ctx("Version:","theme"));
+ pLayout->addWidget(pLabel,2,0);
+
+ m_pPackageVersionEdit = new QLineEdit(pPage);
+ m_pPackageVersionEdit->setText(szPackageVersion);
+ pLayout->addWidget(m_pPackageVersionEdit,2,1);
+
+ pLabel = new QLabel(pPage);
+ pLabel->setText(__tr2qs_ctx("Description:","theme"));
+ pLayout->addWidget(pLabel,3,0);
+
+ m_pPackageDescriptionEdit = new KviTalTextEdit(pPage);
+ m_pPackageDescriptionEdit->setText(szPackageDescription);
+ pLayout->addWidget(m_pPackageDescriptionEdit,3,1);
+
+ pLabel = new QLabel(pPage);
+ pLabel->setText(__tr2qs_ctx("Package Author:","theme"));
+ pLayout->addWidget(pLabel,4,0);
+
+ m_pPackagerNameEdit = new QLineEdit(pPage);
+ m_pPackagerNameEdit->setText(szPackageAuthor);
+ pLayout->addWidget(m_pPackagerNameEdit,4,1);
+
+
+ pLayout->setRowStretch(3,1);
+ pLayout->setColStretch(1,1);
+
+ addPage(pPage,__tr2qs_ctx("Package Informations","theme"));
+ setBackEnabled(pPage,true);
+ setHelpEnabled(pPage,false);
+ setNextEnabled(pPage,true);
+ setFinishEnabled(pPage,false);
+
+ // screenshot/logo/icon ================================================================================
+
+ pPage = new QWidget(this);
+ pLayout = new QGridLayout(pPage,3,1,4,4);
+
+ pLabel = new QLabel(pPage);
+ pLabel->setText(__tr2qs_ctx("Here you can choose the image that will appear in the installation dialog for your theme package. It can be an icon, a logo or a screenshot and it should be not larger than 300x225. If you don't provide an image a simple default icon will be used at installation stage.","theme"));
+ pLabel->setTextFormat(Qt::RichText);
+ pLayout->addWidget(pLabel,0,0);
+
+ m_pImageLabel = new QLabel(pPage);
+ m_pImageLabel->setFrameStyle(QFrame::Sunken | QFrame::Panel);
+ m_pImageLabel->setMinimumSize(300,225);
+ m_pImageLabel->setAlignment(Qt::AlignCenter | Qt::AlignVCenter);
+ pLayout->addWidget(m_pImageLabel,1,0);
+
+ QString szFilter = "*.png *.jpg *.xpm";
+ m_pImageSelector = new KviFileSelector(pPage,"",&m_szImagePath,true,0,szFilter);
+ connect(m_pImageSelector,SIGNAL(selectionChanged(const QString &)),this,SLOT(imageSelectionChanged(const QString &)));
+ pLayout->addWidget(m_pImageSelector,2,0);
+ pLayout->setRowStretch(1,1);
+
+ m_pImageSelectionPage = pPage;
+ addPage(pPage,__tr2qs_ctx("Icon/Screenshot","theme"));
+ setBackEnabled(pPage,true);
+ setHelpEnabled(pPage,false);
+ setNextEnabled(pPage,true);
+ setFinishEnabled(pPage,false);
+
+ // save file name ================================================================================
+
+ pPage = new QWidget(this);
+ pLayout = new QGridLayout(pPage,4,1,4,4);
+
+ pLabel = new QLabel(pPage);
+ pLabel->setText(__tr2qs_ctx("Here you must choose the file name for the theme package. It should have a *.%1 extension.","theme").arg(KVI_FILEEXTENSION_THEMEPACKAGE));
+ pLabel->setTextFormat(Qt::RichText);
+ pLayout->addWidget(pLabel,0,0);
+
+ szFilter = "*.";
+ szFilter += KVI_FILEEXTENSION_THEMEPACKAGE;
+ m_pPathSelector = new KviFileSelector(pPage,"",&m_szPackagePath,true,KviFileSelector::ChooseSaveFileName,szFilter);
+ pLayout->addWidget(m_pPathSelector,1,0);
+
+ pLabel = new QLabel(pPage);
+ pLabel->setText(__tr2qs_ctx("Finally hit the \"Finish\" button to complete the packaging operation.","theme"));
+ pLabel->setTextFormat(Qt::RichText);
+ pLayout->addWidget(pLabel,3,0);
+
+ pLayout->setRowStretch(2,1);
+
+ addPage(pPage,__tr2qs_ctx("Package Path","theme"));
+ setBackEnabled(pPage,true);
+ setHelpEnabled(pPage,false);
+ setNextEnabled(pPage,false);
+ setFinishEnabled(pPage,true);
+
+ if(!szScreenshotPath.isEmpty())
+ {
+ m_pImageSelector->setSelection(szScreenshotPath);
+ imageSelectionChanged(szScreenshotPath);
+ }
+}
+
+KviPackThemeDialog::~KviPackThemeDialog()
+{
+}
+
+void KviPackThemeDialog::imageSelectionChanged(const QString &szImagePath)
+{
+ QImage pix(szImagePath);
+ if(!pix.isNull())
+ {
+ QPixmap out;
+ if(pix.width() > 300 || pix.height() > 225)
+#ifdef COMPILE_USE_QT4
+ out.convertFromImage(pix.scaled(300,225,Qt::KeepAspectRatio,Qt::SmoothTransformation));
+#else
+ out.convertFromImage(pix.smoothScale(300,225,QImage::ScaleMin));
+#endif
+ else
+ out.convertFromImage(pix);
+ m_pImageLabel->setPixmap(out);
+ return;
+ }
+
+ QMessageBox::critical(this,__tr2qs_ctx("Export Theme - KVIrc","theme"),__tr2qs_ctx("Failed to load the selected image","theme"),
+ QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton);
+
+ m_pImageSelector->setSelection("");
+ m_pImageLabel->setPixmap(QPixmap());
+}
+
+
+void KviPackThemeDialog::accept()
+{
+ if(!packTheme())return;
+ KviTalWizard::accept();
+}
+
+
+bool KviPackThemeDialog::packTheme()
+{
+ m_pImageSelector->commit();
+ m_pPathSelector->commit();
+
+ QString szPackageAuthor = m_pPackagerNameEdit->text();
+ QString szPackageName = m_pPackageNameEdit->text();
+ QString szPackageDescription = m_pPackageDescriptionEdit->text();
+ QString szPackageVersion = m_pPackageVersionEdit->text();
+
+ QImage pix(m_szImagePath);
+ QPixmap out;
+ if(!pix.isNull())
+ {
+ if(pix.width() > 300 || pix.height() > 225)
+ #ifdef COMPILE_USE_QT4
+ out.convertFromImage(pix.scaled(300,225,Qt::KeepAspectRatio));
+ #else
+ out.convertFromImage(pix.smoothScale(300,225,QImage::ScaleMin));
+#endif
+ else
+ out.convertFromImage(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::currentDateTime().toString();
+
+ f.addInfoField("PackageType","ThemePack");
+ f.addInfoField("ThemePackVersion","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);
+
+ if(!out.isNull())
+ {
+ QByteArray * pba = new QByteArray();
+#ifdef COMPILE_USE_QT4
+ QBuffer buffer(pba,0);
+#else
+ QBuffer buffer(*pba);
+#endif
+ buffer.open(IO_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())
+ {
+ 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());
+ QPixmap pixScreenshot = pInfo->smallScreenshot();
+ if(!pixScreenshot.isNull())
+ {
+ KviQString::sprintf(szTmp,"Theme%dScreenshot",iIdx);
+ QByteArray * pba = new QByteArray();
+#ifdef COMPILE_USE_QT4
+ QBuffer bufferz(pba,0);
+#else
+ QBuffer bufferz(*pba);
+#endif
+ bufferz.open(IO_WriteOnly);
+ pixScreenshot.save(&bufferz,"PNG");
+ bufferz.close();
+ f.addInfoField(szTmp,pba);
+ }
+
+ if(!f.addDirectory(pInfo->absoluteDirectory(),pInfo->subdirectory()))
+ {
+ 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);
+ }
+
+ 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 succesfully"),
+ QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton);
+
+ return true;
+}
+
diff --git a/src/modules/theme/packthemedialog.h b/src/modules/theme/packthemedialog.h
new file mode 100644
index 00000000..7731cc30
--- /dev/null
+++ b/src/modules/theme/packthemedialog.h
@@ -0,0 +1,66 @@
+#ifndef _PACKTHEMEDIALOG_H_
+#define _PACKTHEMEDIALOG_H_
+//=============================================================================
+//
+// File : packthemedialog.h
+// Created on Wed 03 Jan 2007 01:11:44 by Szymon Stefanek
+//
+// This file is part of the KVIrc IRC Client distribution
+// Copyright (C) 2007 Szymon Stefanek <pragma at kvirc dot net>
+//
+// 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. ,51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+//=============================================================================
+
+#include "kvi_settings.h"
+#include "kvi_pointerlist.h"
+#include "kvi_theme.h"
+
+#include <qdialog.h>
+#include <kvi_tal_wizard.h>
+
+class QLineEdit;
+class KviTalTextEdit;
+class QLabel;
+class QMultiLineEdit;
+class KviFileSelector;
+
+
+class KviPackThemeDialog : public KviTalWizard
+{
+ Q_OBJECT
+public:
+ KviPackThemeDialog(QWidget * pParent,KviPointerList<KviThemeInfo> * pThemeInfoList);
+ virtual ~KviPackThemeDialog();
+protected:
+ QString m_szImagePath;
+ KviFileSelector * m_pImageSelector;
+ QString m_szPackagePath;
+ KviFileSelector * m_pPathSelector;
+ QLabel * m_pImageLabel;
+ KviPointerList<KviThemeInfo> * m_pThemeInfoList;
+ QLineEdit * m_pPackageNameEdit;
+ KviTalTextEdit * m_pPackageDescriptionEdit;
+ QLineEdit * m_pPackageVersionEdit;
+ QLineEdit * m_pPackagerNameEdit;
+ QWidget * m_pImageSelectionPage;
+protected:
+ virtual void accept();
+ bool packTheme();
+protected slots:
+ void imageSelectionChanged(const QString &szImagePath);
+};
+
+#endif //!_PACKTHEMEDIALOG_H_
diff --git a/src/modules/theme/savethemedialog.cpp b/src/modules/theme/savethemedialog.cpp
new file mode 100644
index 00000000..79319e60
--- /dev/null
+++ b/src/modules/theme/savethemedialog.cpp
@@ -0,0 +1,301 @@
+//=============================================================================
+//
+// File : savethemedialog.cpp
+// Created on Wed 03 Jan 2007 03:01:34 by Szymon Stefanek
+//
+// This file is part of the KVIrc IRC Client distribution
+// Copyright (C) 2007 Szymon Stefanek <pragma at kvirc dot net>
+//
+// 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. ,51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+//=============================================================================
+
+#include "savethemedialog.h"
+#include "themefunctions.h"
+
+#include <qlayout.h>
+#include <qpushbutton.h>
+#include <qlineedit.h>
+#include <qregexp.h>
+#include <qmessagebox.h>
+#include <qdir.h>
+#include <qcombobox.h>
+#include <qpainter.h>
+#include <qtooltip.h>
+#include <qimage.h>
+#include <kvi_tal_textedit.h>
+#ifdef COMPILE_USE_QT4
+#include <q3multilineedit.h>
+#include <QDateTime>
+#else
+#include <qmultilineedit.h>
+#endif
+#include <qbuffer.h>
+#include <qlabel.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"
+
+
+
+KviSaveThemeDialog::KviSaveThemeDialog(QWidget * pParent)
+: KviTalWizard(pParent)
+{
+ setCaption(__tr2qs_ctx("Save Current Theme - KVIrc","theme"));
+ setMinimumSize(400,350);
+
+ // welcome page ==================================================================================
+ QWidget * pPage = new QWidget(this);
+ QGridLayout * pLayout = new QGridLayout(pPage,2,1,4,4);
+
+ QLabel * pLabel = new QLabel(pPage);
+ QString szText = "<p>";
+ szText += __tr2qs_ctx("This procedure allows you to save the current theme settings to a single directory. It is useful if you want to apply other themes or play with the theme settings and later come back to this theme with a single click. It will also allow you to manually modify the theme settings and later export them to a distributable package.","theme");
+ szText += "</p><p>";
+ szText += __tr2qs_ctx("You will be asked to provide a theme name, a description and, if you want, a screenshot.","theme");
+ szText += "</p><p>";
+ szText += __tr2qs_ctx("Hit the \"Next\" button to begin.","theme");
+ szText += "<p>";
+
+ pLabel->setText(szText);
+ pLayout->addWidget(pLabel,0,0);
+ pLayout->setRowStretch(1,1);
+
+ addPage(pPage,__tr2qs_ctx("Welcome","theme"));
+ setBackEnabled(pPage,false);
+ setNextEnabled(pPage,true);
+ setHelpEnabled(pPage,false);
+ setFinishEnabled(pPage,false);
+
+ // packager informations ================================================================================
+
+ pPage = new QWidget(this);
+ pLayout = new QGridLayout(pPage,5,2,4,4);
+
+ pLabel = new QLabel(pPage);
+ pLabel->setText(__tr2qs_ctx("Here you need to provide informations about you (the author) and a short description of the theme you're creating.","theme"));
+ pLabel->setTextFormat(Qt::RichText);
+ pLayout->addMultiCellWidget(pLabel,0,0,0,1);
+
+ pLabel = new QLabel(pPage);
+ pLabel->setText(__tr2qs_ctx("Theme Name:","theme"));
+ pLayout->addWidget(pLabel,1,0);
+
+ m_pThemeNameEdit = new QLineEdit(pPage);
+ //m_pThemeNameEdit->setText(szThemeName);
+ pLayout->addWidget(m_pThemeNameEdit,1,1);
+
+ pLabel = new QLabel(pPage);
+ pLabel->setText(__tr2qs_ctx("Version:","theme"));
+ pLayout->addWidget(pLabel,2,0);
+
+ m_pThemeVersionEdit = new QLineEdit(pPage);
+ //m_pThemeVersionEdit->setText(szThemeVersion);
+ pLayout->addWidget(m_pThemeVersionEdit,2,1);
+
+ pLabel = new QLabel(pPage);
+ pLabel->setText(__tr2qs_ctx("Description:","theme"));
+ pLayout->addWidget(pLabel,3,0);
+
+ m_pThemeDescriptionEdit = new KviTalTextEdit(pPage);
+ //m_pThemeDescriptionEdit->setText(szThemeDescription);
+ pLayout->addWidget(m_pThemeDescriptionEdit,3,1);
+
+ pLabel = new QLabel(pPage);
+ pLabel->setText(__tr2qs_ctx("Theme Author:","theme"));
+ pLayout->addWidget(pLabel,4,0);
+
+ m_pAuthorNameEdit = new QLineEdit(pPage);
+ //m_pAuthorNameEdit->setText(szThemeAuthor);
+ pLayout->addWidget(m_pAuthorNameEdit,4,1);
+
+
+ pLayout->setRowStretch(3,1);
+ pLayout->setColStretch(1,1);
+
+ addPage(pPage,__tr2qs_ctx("Theme Informations","theme"));
+ setBackEnabled(pPage,true);
+ setHelpEnabled(pPage,false);
+ setNextEnabled(pPage,true);
+ setFinishEnabled(pPage,false);
+
+ // screenshot/logo/icon ================================================================================
+
+ pPage = new QWidget(this);
+ pLayout = new QGridLayout(pPage,4,1,4,4);
+
+ pLabel = new QLabel(pPage);
+ pLabel->setText(__tr2qs_ctx("Here you can either choose a screenshot image from disk or make one now. The screenshot will be displayed in the tooltips of the theme management dialog and will be also visible in the package installation dialog if you will export the theme to a distributable package.","theme"));
+ pLabel->setTextFormat(Qt::RichText);
+ pLayout->addWidget(pLabel,0,0);
+
+ m_pImageLabel = new QLabel(pPage);
+ m_pImageLabel->setFrameStyle(QFrame::Sunken | QFrame::Panel);
+ m_pImageLabel->setMinimumSize(300,225);
+ m_pImageLabel->setAlignment(Qt::AlignCenter | Qt::AlignVCenter);
+ pLayout->addWidget(m_pImageLabel,1,0);
+
+ QString szFilter = "*.png *.jpg *.xpm";
+ m_pImageSelector = new KviFileSelector(pPage,"",&m_szScreenshotPath,true,0,szFilter);
+ connect(m_pImageSelector,SIGNAL(selectionChanged(const QString &)),this,SLOT(imageSelectionChanged(const QString &)));
+ pLayout->addWidget(m_pImageSelector,2,0);
+
+ QPushButton * pButton = new QPushButton(pPage);
+ pButton->setText(__tr2qs_ctx("Make Screenshot Now","theme"));
+ connect(pButton,SIGNAL(clicked()),this,SLOT(makeScreenshot()));
+ pLayout->addWidget(pButton,3,0);
+
+ pLayout->setRowStretch(1,1);
+
+ m_pImageSelectionPage = pPage;
+ addPage(pPage,__tr2qs_ctx("Screenshot","theme"));
+ setBackEnabled(pPage,true);
+ setHelpEnabled(pPage,false);
+ setNextEnabled(pPage,true);
+ setFinishEnabled(pPage,true);
+}
+
+KviSaveThemeDialog::~KviSaveThemeDialog()
+{
+}
+
+void KviSaveThemeDialog::imageSelectionChanged(const QString &szImagePath)
+{
+ QImage pix(szImagePath);
+ if(!pix.isNull())
+ {
+ QPixmap out;
+ if(pix.width() > 300 || pix.height() > 225)
+ #ifdef COMPILE_USE_QT4
+ out.convertFromImage(pix.scaled(300,225,Qt::KeepAspectRatio));
+ #else
+ out.convertFromImage(pix.smoothScale(300,225,QImage::ScaleMin));
+#endif
+ else
+ out.convertFromImage(pix);
+ m_pImageLabel->setPixmap(out);
+ return;
+ }
+
+ QMessageBox::critical(this,__tr2qs_ctx("Save Current Theme - KVIrc","theme"),__tr2qs_ctx("Failed to load the selected image","theme"),
+ QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton);
+
+ m_pImageSelector->setSelection("");
+ m_pImageLabel->setPixmap(QPixmap());
+}
+
+
+void KviSaveThemeDialog::accept()
+{
+ if(!saveTheme())return;
+ KviTalWizard::accept();
+}
+
+
+void KviSaveThemeDialog::makeScreenshot()
+{
+ QString szFileName;
+ g_pApp->getTmpFileName(szFileName,"screenshot.png");
+ if(!KviThemeFunctions::makeKVIrcScreenshot(szFileName))
+ {
+ QMessageBox::critical(this,__tr2qs_ctx("Acquire Screenshot - KVIrc","theme"),__tr2qs_ctx("Failed to make screenshot","theme"),
+ QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton);
+ return;
+ }
+ m_pImageSelector->setSelection(szFileName);
+ imageSelectionChanged(szFileName);
+}
+
+bool KviSaveThemeDialog::saveTheme()
+{
+ m_pImageSelector->commit();
+
+ KviThemeInfo sto;
+ sto.setName(m_pThemeNameEdit->text());
+ if(sto.name().isEmpty())
+ {
+ QMessageBox::critical(this,__tr2qs_ctx("Save Current Theme - KVIrc","theme"),__tr2qs_ctx("You must choose a theme name!","theme"),QMessageBox::Ok,
+ QMessageBox::NoButton,QMessageBox::NoButton);
+ return false;
+ }
+
+ sto.setAuthor(m_pAuthorNameEdit->text());
+ sto.setDescription(m_pThemeDescriptionEdit->text());
+ sto.setDate(QDateTime::currentDateTime().toString());
+ sto.setVersion(m_pThemeVersionEdit->text());
+ sto.setApplication("KVIrc " KVI_VERSION "." KVI_SOURCES_DATE);
+
+ if(sto.version().isEmpty())sto.setVersion("1.0.0");
+
+ QString szSubdir = sto.name() + QString("-") + sto.version();
+ szSubdir.replace(QRegExp("[ \\\\/:][ \\\\/:]*"),"_");
+ sto.setSubdirectory(szSubdir);
+
+ QString szAbsDir;
+ g_pApp->getLocalKvircDirectory(szAbsDir,KviApp::Themes,sto.subdirectory(),true);
+ if(!KviFileUtils::makeDir(szAbsDir))
+ {
+ QMessageBox::critical(this,__tr2qs_ctx("Save Current Theme - KVIrc","theme"),__tr2qs_ctx("Unable to create theme directory.","theme"),
+ QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton);
+ return false;
+ }
+
+ sto.setAbsoluteDirectory(szAbsDir);
+
+ if(!KviTheme::save(sto))
+ {
+ QString szMsg2;
+ QString szErr = sto.lastError();
+ KviQString::sprintf(szMsg2,__tr2qs_ctx("Unable to save theme: %Q","theme"),&szErr);
+ QMessageBox::critical(this,__tr2qs_ctx("Save Current Theme - KVIrc","theme"),szMsg2,
+ QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton);
+ return false;
+ }
+ // write down the screenshot, if needed
+
+ if(!m_szScreenshotPath.isEmpty())
+ {
+ if(!KviTheme::saveScreenshots(sto,m_szScreenshotPath))
+ {
+ QMessageBox::critical(this,__tr2qs_ctx("Save Current Theme - KVIrc","theme"),__tr2qs_ctx("Failed to load the selected screenshot image: please fix it","theme"),
+ QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton);
+ setCurrentPage(m_pImageSelectionPage);
+ return false;
+ }
+ }
+
+ QString szMsg = __tr2qs_ctx("Theme saved successfully to ","theme");
+ szMsg += sto.absoluteDirectory();
+
+ QMessageBox::information(this,__tr2qs_ctx("Save Theme - KVIrc","theme"),szMsg,QMessageBox::Ok,
+ QMessageBox::NoButton,QMessageBox::NoButton);
+
+ return true;
+}
+
diff --git a/src/modules/theme/savethemedialog.h b/src/modules/theme/savethemedialog.h
new file mode 100644
index 00000000..df55ee92
--- /dev/null
+++ b/src/modules/theme/savethemedialog.h
@@ -0,0 +1,71 @@
+#ifndef _SAVETHEMEDIALOG_H_
+#define _SAVETHEMEDIALOG_H_
+//=============================================================================
+//
+// File : savethemedialog.h
+// Created on Wed 03 Jan 2007 03:01:34 by Szymon Stefanek
+//
+// This file is part of the KVIrc IRC Client distribution
+// Copyright (C) 2007 Szymon Stefanek <pragma at kvirc dot net>
+//
+// 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. ,51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+//=============================================================================
+
+#include "kvi_settings.h"
+#include "kvi_pointerlist.h"
+#include "kvi_theme.h"
+
+#include <qdialog.h>
+#include <kvi_tal_wizard.h>
+
+
+class QLineEdit;
+class KviTalTextEdit;
+class QPushButton;
+class QCheckBox;
+class QLabel;
+class QMultiLineEdit;
+class KviFileSelector;
+
+
+class KviSaveThemeDialog : public KviTalWizard
+{
+ Q_OBJECT
+public:
+ KviSaveThemeDialog(QWidget * pParent);
+ virtual ~KviSaveThemeDialog();
+protected:
+ QString m_szScreenshotPath;
+ KviFileSelector * m_pImageSelector;
+ QLabel * m_pImageLabel;
+ QLineEdit * m_pThemeNameEdit;
+ KviTalTextEdit * m_pThemeDescriptionEdit;
+ QLineEdit * m_pThemeVersionEdit;
+ QLineEdit * m_pAuthorNameEdit;
+ QWidget * m_pImageSelectionPage;
+ QPushButton * m_pOkButton;
+protected:
+ virtual void accept();
+ bool saveTheme();
+protected slots:
+ void makeScreenshot();
+ void imageSelectionChanged(const QString &szImagePath);
+ //void themeNameChanged(const QString &txt);
+};
+
+
+
+#endif //!_SAVETHEMEDIALOG_H_
diff --git a/src/modules/theme/themefunctions.cpp b/src/modules/theme/themefunctions.cpp
new file mode 100644
index 00000000..0a011956
--- /dev/null
+++ b/src/modules/theme/themefunctions.cpp
@@ -0,0 +1,396 @@
+//=============================================================================
+//
+// File : themefunctions.cpp
+// Created on Wed 03 Jan 2007 03:14:07 by Szymon Stefanek
+//
+// This file is part of the KVIrc IRC Client distribution
+// Copyright (C) 2007 Szymon Stefanek <pragma at kvirc dot net>
+//
+// 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. ,51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+//=============================================================================
+
+#include "themefunctions.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"
+#ifdef COMPILE_USE_QT4
+#define KviTalMimeSourceFactory Q3MimeSourceFactory
+#include <q3mimefactory.h>
+#else
+#define KviTalMimeSourceFactory QMimeSourceFactory
+#endif
+#include <qmime.h>
+
+namespace KviThemeFunctions
+{
+
+ static bool notAValidThemePackage(QString &szError)
+ {
+ KviQString::sprintf(szError,__tr2qs_ctx("The selected file does not seem to be a valid KVIrc theme package","theme"));
+ return false;
+ }
+
+ bool installThemePackage(const QString &szThemePackageFileName,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 theme file
+ KviPackageReader r;
+ if(!r.readHeader(szThemePackageFileName))
+ {
+ QString szErr = r.lastError();
+ KviQString::sprintf(szError,__tr2qs_ctx("The selected file does not seem to be a valid KVIrc package: %Q","theme"),&szErr);
+ return false;
+ }
+
+ pInfoFields = r.stringInfoFields();
+
+ pValue = pInfoFields->find("PackageType");
+ if(!pValue)return notAValidThemePackage(szError);
+ if(!KviQString::equalCI(*pValue,"ThemePack"))return notAValidThemePackage(szError);
+ pValue = pInfoFields->find("ThemePackVersion");
+ if(!pValue)return notAValidThemePackage(szError);
+ if(!KviQString::equalCI(*pValue,"1"))return notAValidThemePackage(szError);
+
+ // make sure the default fields exist
+ for(int i=0;i<6;i++)
+ {
+ pValue = pInfoFields->find(check_fields[i]);
+ if(!pValue)return notAValidThemePackage(szError);
+ }
+
+ pValue = pInfoFields->find("ThemeCount");
+ if(!pValue)return notAValidThemePackage(szError);
+ bool bOk;
+ int iThemeCount = pValue->toInt(&bOk);
+ if(!bOk)return notAValidThemePackage(szError);
+ if(iThemeCount < 1)return notAValidThemePackage(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_THEME));
+ }
+
+ QString szPackageName;
+ QString szPackageVersion;
+ QString szPackageAuthor;
+ QString szPackageDescription;
+ QString szPackageDate;
+ QString szPackageThemeEngineVersion;
+ QString szPackageApplication;
+
+ QString szAuthor = __tr2qs_ctx("Author","theme");
+ QString szCreatedAt = __tr2qs_ctx("Created at","theme");
+ QString szCreatedOn = __tr2qs_ctx("Created with","theme");
+
+ 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 iValidThemeCount = iThemeCount;
+
+ while(iIdx < iThemeCount)
+ {
+ bool bValid = true;
+
+ QString szThemeName;
+ QString szThemeVersion;
+ QString szThemeDescription;
+ QString szThemeDate;
+ QString szThemeSubdirectory;
+ QString szThemeAuthor;
+ QString szThemeThemeEngineVersion;
+ QString szThemeApplication;
+
+ KviQString::sprintf(szTmp,"Theme%dName",iIdx);
+ r.getStringInfoField(szTmp,szThemeName);
+ KviQString::sprintf(szTmp,"Theme%dVersion",iIdx);
+ r.getStringInfoField(szTmp,szThemeVersion);
+ KviQString::sprintf(szTmp,"Theme%dApplication",iIdx);
+ r.getStringInfoField(szTmp,szThemeApplication);
+ KviQString::sprintf(szTmp,"Theme%dDescription",iIdx);
+ r.getStringInfoField(szTmp,szThemeDescription);
+ KviQString::sprintf(szTmp,"Theme%dDate",iIdx);
+ r.getStringInfoField(szTmp,szThemeDate);
+ KviQString::sprintf(szTmp,"Theme%dSubdirectory",iIdx);
+ r.getStringInfoField(szTmp,szThemeSubdirectory);
+ KviQString::sprintf(szTmp,"Theme%dAuthor",iIdx);
+ r.getStringInfoField(szTmp,szThemeAuthor);
+ KviQString::sprintf(szTmp,"Theme%dThemeEngineVersion",iIdx);
+ r.getStringInfoField(szTmp,szThemeThemeEngineVersion);
+ KviQString::sprintf(szTmp,"Theme%dScreenshot",iIdx);
+ QPixmap pixScreenshot;
+ pByteArray = r.binaryInfoFields()->find(szTmp);
+ if(pByteArray)
+ pixScreenshot.loadFromData(*pByteArray,0,0);
+
+ if(szThemeName.isEmpty() || szThemeVersion.isEmpty() || szThemeSubdirectory.isEmpty() || szThemeThemeEngineVersion.isEmpty())
+ bValid = false;
+ if(KviMiscUtils::compareVersions(szThemeThemeEngineVersion,KVI_CURRENT_THEME_ENGINE_VERSION) < 0)
+ bValid = false;
+
+ QString szDetailsBuffer;
+
+ getThemeHtmlDescription(
+ szDetailsBuffer,
+ szThemeName,
+ szThemeVersion,
+ szThemeDescription,
+ szThemeSubdirectory,
+ szThemeApplication,
+ szThemeAuthor,
+ szThemeDate,
+ szThemeThemeEngineVersion,
+ pixScreenshot,
+ iIdx
+ );
+
+ if(iIdx > 0)
+ szDetails += "<hr>";
+
+ szDetails += szDetailsBuffer;
+
+ if(!bValid)
+ {
+ szDetails += "<p><center><font color=\"#ff0000\"><b>";
+ szDetails += __tr2qs_ctx("Warning: The theme might be incompatible with this version of KVIrc","theme");
+ szDetails += "</b></font></center></p>";
+ iValidThemeCount--;
+ }
+
+ iIdx++;
+ }
+
+ szDetails += "<br><p><center><a href=\"theme_dialog_main\">";
+ szDetails += __tr2qs_ctx("Go Back to Package Data","theme");
+ szDetails += "</a></center></p>";
+ szDetails += "</body></html>";
+
+ if(iValidThemeCount < iThemeCount)
+ {
+ szWarnings += "<p><center><font color=\"#ff0000\"><b>";
+ szWarnings += __tr2qs_ctx("Warning: Some of the theme contained in this package might be either corrupted or incompatible with this version of KVIrc","theme");
+ szWarnings += "</b></font></center></p>";
+ }
+
+ QString szShowDetails = __tr2qs_ctx("Show Details","theme");
+
+ KviQString::sprintf(hd.szHtmlText,
+ "<html bgcolor=\"#ffffff\">" \
+ "<body bgcolor=\"#ffffff\">" \
+ "<p><center>" \
+ "<h2>%Q %Q</h2>" \
+ "</center></p>" \
+ "<p><center>" \
+ "<img src=\"theme_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=\"theme_dialog_details\">%Q</a>" \
+ "</center></p>" \
+ "</body>" \
+ "</html>",
+ &szPackageName,
+ &szPackageVersion,
+ &szPackageDescription,
+ &szAuthor,
+ &szPackageAuthor,
+ &szCreatedAt,
+ &szPackageDate,
+ &szCreatedOn,
+ &szPackageApplication,
+ &szWarnings,
+ &szShowDetails
+ );
+
+
+
+ KviTalMimeSourceFactory::defaultFactory()->setPixmap("theme_dialog_pack_image",pix);
+ KviTalMimeSourceFactory::defaultFactory()->setText("theme_dialog_details",szDetails);
+ KviTalMimeSourceFactory::defaultFactory()->setText("theme_dialog_main",hd.szHtmlText);
+
+ QString beginCenter = "<center>";
+ QString endCenter = "</center>";
+
+ hd.szCaption = __tr2qs_ctx("Install Theme Pack - KVIrc","theme");
+ hd.szUpperLabelText = beginCenter + __tr2qs_ctx("You're about to install the following theme package","theme") + endCenter;
+ hd.szLowerLabelText = beginCenter + __tr2qs_ctx("Do you want to proceed with the installation ?","theme") + endCenter;
+ hd.szButton1Text = __tr2qs_ctx("Do Not Install","theme");
+ hd.szButton2Text = __tr2qs_ctx("Yes, Proceed","theme");
+ hd.iDefaultButton = 2;
+ hd.iCancelButton = 1;
+ hd.pixIcon = *(g_pIconManager->getSmallIcon(KVI_SMALLICON_THEME));
+ 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(szThemePackageFileName,szUnpackPath))
+ {
+ QString szErr2 = r.lastError();
+ KviQString::sprintf(szError,__tr2qs_ctx("Failed to unpack the selected file: %Q","theme"),&szErr2);
+ return true;
+ }
+ }
+
+ return true;
+ }
+
+
+ void getThemeHtmlDescription(
+ QString &szBuffer,
+ const QString &szThemeName,
+ const QString &szThemeVersion,
+ const QString &szThemeDescription,
+ const QString &szThemeSubdirectory,
+ const QString &szThemeApplication,
+ const QString &szThemeAuthor,
+ const QString &szThemeDate,
+ const QString &szThemeThemeEngineVersion,
+ const QPixmap &pixScreenshot,
+ int iUniqueIndexInDocument
+ )
+ {
+ QString szAuthor = __tr2qs_ctx("Author","theme");
+ QString szCreatedAt = __tr2qs_ctx("Created at","theme");
+ QString szCreatedOn = __tr2qs_ctx("Created with","theme");
+ QString szThemeEngineVersion = __tr2qs_ctx("Theme Engine Version","theme");
+ QString szSubdirectory = __tr2qs_ctx("Subdirectory","theme");
+
+ QString szScreenshot;
+ if(!pixScreenshot.isNull())
+ {
+ KviQString::sprintf(szScreenshot,"<p><center><img src=\"theme_shot%d\"></center></p>",iUniqueIndexInDocument);
+ QString szTmp;
+ KviQString::sprintf(szTmp,"theme_shot%d",iUniqueIndexInDocument);
+ KviTalMimeSourceFactory::defaultFactory()->setPixmap(szTmp,pixScreenshot);
+ } else {
+ szScreenshot = "";
+ }
+
+ KviQString::sprintf(
+ szBuffer,
+ "<p><center>" \
+ "<h2>%Q %Q</h2>" \
+ "</center></p>" \
+ "%Q" \
+ "<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>",
+ &szThemeName,
+ &szThemeVersion,
+ &szScreenshot,
+ &szThemeDescription,
+ &szAuthor,
+ &szThemeAuthor,
+ &szCreatedAt,
+ &szThemeDate,
+ &szCreatedOn,
+ &szThemeApplication,
+ &szThemeEngineVersion,
+ &szThemeThemeEngineVersion,
+ &szSubdirectory,
+ &szThemeSubdirectory
+ );
+ }
+
+ bool makeKVIrcScreenshot(const QString &szSavePngFilePath,bool bMaximizeFrame)
+ {
+ if(bMaximizeFrame)
+ {
+ if(g_pFrame->isMaximized())
+ bMaximizeFrame = false;
+ }
+
+ if(bMaximizeFrame)
+ g_pFrame->showMaximized();
+
+ QPixmap pix = QPixmap::grabWidget(g_pFrame);
+ bool bResult = true;
+
+ if(pix.isNull())
+ bResult = false;
+ else {
+ if(!pix.save(szSavePngFilePath,"PNG",100))
+ bResult = false;
+ }
+
+ if(bMaximizeFrame)
+ g_pFrame->showNormal();
+ return bResult;
+ }
+};
+
diff --git a/src/modules/theme/themefunctions.h b/src/modules/theme/themefunctions.h
new file mode 100644
index 00000000..124a65f6
--- /dev/null
+++ b/src/modules/theme/themefunctions.h
@@ -0,0 +1,54 @@
+#ifndef _THEMEFUNCTIONS_H_
+#define _THEMEFUNCTIONS_H_
+//=============================================================================
+//
+// File : themefunctions.h
+// Created on Wed 03 Jan 2007 03:14:07 by Szymon Stefanek
+//
+// This file is part of the KVIrc IRC Client distribution
+// Copyright (C) 2007 Szymon Stefanek <pragma at kvirc dot net>
+//
+// 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. ,51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+//=============================================================================
+
+#include "kvi_settings.h"
+#include "kvi_qstring.h"
+
+#include <qwidget.h>
+#include <qpixmap.h>
+
+namespace KviThemeFunctions
+{
+ bool installThemePackage(const QString &szThemePackageFileName,QString &szError,QWidget * pDialogParent = 0);
+ void getThemeHtmlDescription(
+ QString &szBuffer,
+ const QString &szThemeName,
+ const QString &szThemeVersion,
+ const QString &szThemeDescription,
+ const QString &szThemeSubdirectory,
+ const QString &szThemeApplication,
+ const QString &szThemeAuthor,
+ const QString &szThemeDate,
+ const QString &szThemeThemeEngineVersion,
+ const QPixmap &pixScreenshot,
+ int iUniqueIndexInDocument = 0
+ );
+ bool makeKVIrcScreenshot(const QString &szSavePngFilePath,bool bMaximizeFrame = false);
+};
+
+
+
+#endif //!_THEMEFUNCTIONS_H_