diff options
| author | 2006-12-30 14:47:50 +0000 | |
|---|---|---|
| committer | 2006-12-30 14:47:50 +0000 | |
| commit | 1655daf2249fa681bcf56f176b7a49c6332ff26f (patch) | |
| tree | 90184ad81e1f7b5a111be3c10c5638db7dd38c36 /src/modules | |
| parent | *AUTOMATICALLY* updated KVI_SOURCES_DATE variable (diff) | |
| download | KVIrc-1655daf2249fa681bcf56f176b7a49c6332ff26f.tar.gz KVIrc-1655daf2249fa681bcf56f176b7a49c6332ff26f.tar.bz2 KVIrc-1655daf2249fa681bcf56f176b7a49c6332ff26f.zip | |
Theme management stuff and other tricks
git-svn-id: https://svn.kvirc.de/svn/trunk/kvirc@75 17fca916-40b9-46aa-a4ea-0a15b648b75c
Diffstat (limited to 'src/modules')
| -rw-r--r-- | src/modules/Makefile.am | 1 | ||||
| -rw-r--r-- | src/modules/help/libkvihelp.cpp | 6 | ||||
| -rw-r--r-- | src/modules/options/instances.cpp | 41 | ||||
| -rw-r--r-- | src/modules/options/optw_theme.cpp | 583 | ||||
| -rw-r--r-- | src/modules/options/optw_theme.h | 87 | ||||
| -rw-r--r-- | src/modules/theme/.svnignore | 11 | ||||
| -rw-r--r-- | src/modules/theme/Makefile.am | 20 | ||||
| -rw-r--r-- | src/modules/theme/libkvitheme.cpp | 122 | ||||
| -rw-r--r-- | src/modules/theme/managementdialog.cpp | 1148 | ||||
| -rw-r--r-- | src/modules/theme/managementdialog.h | 164 |
10 files changed, 1471 insertions, 712 deletions
diff --git a/src/modules/Makefile.am b/src/modules/Makefile.am index f0290648e..388cb6daf 100644 --- a/src/modules/Makefile.am +++ b/src/modules/Makefile.am @@ -52,6 +52,7 @@ SUBDIRS = about \ system \ term \ texticons \ + theme \ tip \ tmphighlight \ toolbar \ diff --git a/src/modules/help/libkvihelp.cpp b/src/modules/help/libkvihelp.cpp index 46c8d8586..a9ea33eb3 100644 --- a/src/modules/help/libkvihelp.cpp +++ b/src/modules/help/libkvihelp.cpp @@ -135,7 +135,6 @@ static bool help_kvs_cmd_search(KviKvsModuleCommandCall * c) static bool help_kvs_cmd_open(KviKvsModuleCommandCall * c) { - QString doc; KVSM_PARAMETERS_BEGIN(c) KVSM_PARAMETER("document",KVS_PT_STRING,KVS_PF_OPTIONAL,doc) @@ -150,12 +149,11 @@ static bool help_kvs_cmd_open(KviKvsModuleCommandCall * c) if(!c->switches()->find('n',"new")) { - KviHelpWidget * w = (KviHelpWidget *)c->window()->frame()->child( - "help_widget","KviHelpWidget"); - + KviHelpWidget * w = (KviHelpWidget *)c->window()->frame()->child("help_widget","KviHelpWidget"); if(w) { w->textBrowser()->setSource(doc); + return true; } } if(c->switches()->find('m',"mdi")) diff --git a/src/modules/options/instances.cpp b/src/modules/options/instances.cpp index db11329f7..1e59137ae 100644 --- a/src/modules/options/instances.cpp +++ b/src/modules/options/instances.cpp @@ -426,11 +426,6 @@ KviOptionsWidget * classKviTextIconsOptionsWidget_createInstanceProc(QWidget * p return new KviTextIconsOptionsWidget(parent); } -KviOptionsWidget * classKviThemeOptionsWidget_createInstanceProc(QWidget * parent) -{ - return new KviThemeOptionsWidget(parent); -} - KviOptionsWidget * classKviToolsOptionsWidget_createInstanceProc(QWidget * parent) { return new KviToolsOptionsWidget(parent); @@ -618,8 +613,6 @@ static const char * g_szName_KviTextEncodingOptionsWidget = KVI_OPTIONS_WIDGET_N static const char * g_szClassName_KviTextEncodingOptionsWidget = "KviTextEncodingOptionsWidget"; static const char * g_szName_KviTextIconsOptionsWidget = KVI_OPTIONS_WIDGET_NAME_KviTextIconsOptionsWidget; static const char * g_szClassName_KviTextIconsOptionsWidget = "KviTextIconsOptionsWidget"; -static const char * g_szName_KviThemeOptionsWidget = KVI_OPTIONS_WIDGET_NAME_KviThemeOptionsWidget; -static const char * g_szClassName_KviThemeOptionsWidget = "KviThemeOptionsWidget"; static const char * g_szName_KviToolsOptionsWidget = KVI_OPTIONS_WIDGET_NAME_KviToolsOptionsWidget; static const char * g_szClassName_KviToolsOptionsWidget = "KviToolsOptionsWidget"; static const char * g_szName_KviTopicLabelLookOptionsWidget = KVI_OPTIONS_WIDGET_NAME_KviTopicLabelLookOptionsWidget; @@ -3204,40 +3197,6 @@ KviOptionsInstanceManager::KviOptionsInstanceManager() e1->pChildList = 0; e0 = new KviOptionsWidgetInstanceEntry; - e0->createProc = &classKviThemeOptionsWidget_createInstanceProc; - e0->pWidget = 0; - e0->szClassName = g_szClassName_KviThemeOptionsWidget; - e0->iIcon = KVI_OPTIONS_WIDGET_ICON_KviThemeOptionsWidget; - #ifdef KVI_OPTIONS_WIDGET_PRIORITY_KviThemeOptionsWidget - e0->iPriority = KVI_OPTIONS_WIDGET_PRIORITY_KviThemeOptionsWidget; - #else - e0->iPriority = 0; - #endif - #ifdef KVI_OPTIONS_WIDGET_KEYWORDS_KviThemeOptionsWidget - e0->szKeywordsNoLocale = KVI_OPTIONS_WIDGET_KEYWORDS_KviThemeOptionsWidget; - e0->szKeywords = __tr2qs_ctx_no_xgettext(e0->szKeywordsNoLocale,"options");; - #endif - #ifdef KVI_OPTIONS_WIDGET_GROUP_KviThemeOptionsWidget - e0->szGroup = KVI_OPTIONS_WIDGET_GROUP_KviThemeOptionsWidget; - #else - e0->szGroup = "general"; - #endif - #ifdef KVI_OPTIONS_WIDGET_CONTAINER_KviThemeOptionsWidget - e0->bIsContainer = KVI_OPTIONS_WIDGET_CONTAINER_KviThemeOptionsWidget; - #else - e0->bIsContainer = false; - #endif - #ifdef KVI_OPTIONS_WIDGET_NOTCONTAINED_KviThemeOptionsWidget - e0->bIsNotContained = KVI_OPTIONS_WIDGET_NOTCONTAINED_KviThemeOptionsWidget; - #else - e0->bIsNotContained = false; - #endif - e0->szNameNoLocale = g_szName_KviThemeOptionsWidget; - e0->szName = __tr2qs_ctx_no_xgettext(g_szName_KviThemeOptionsWidget,"options"); - m_pInstanceTree->append(e0); - e0->pChildList = 0; - - e0 = new KviOptionsWidgetInstanceEntry; e0->createProc = &classKviTopicLabelLookOptionsWidget_createInstanceProc; e0->pWidget = 0; e0->szClassName = g_szClassName_KviTopicLabelLookOptionsWidget; diff --git a/src/modules/options/optw_theme.cpp b/src/modules/options/optw_theme.cpp index a4eb1bb4c..9906b7ec1 100644 --- a/src/modules/options/optw_theme.cpp +++ b/src/modules/options/optw_theme.cpp @@ -22,588 +22,5 @@ // //============================================================================= -#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 "optw_theme.h" -#include "kvi_xmladdonloader.h" -#include "kvi_iconmanager.h" -#include "kvi_msgbox.h" - -#include <qlayout.h> -#include <qpushbutton.h> -#include <qlistbox.h> -#include <qlineedit.h> -#include <qtextedit.h> -#include <qregexp.h> -#include <qmessagebox.h> -#include <qdir.h> -#include <qstringlist.h> -#include <qdatetime.h> -#include <qfiledialog.h> -#include <qpopupmenu.h> -#include <qcombobox.h> -#include <qpainter.h> -#include <qtooltip.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 <stdlib.h> // rand & srand - - -KviSaveThemeDialog::KviSaveThemeDialog(QWidget * par) -: QDialog(par) -{ - setCaption(__tr2qs_ctx("Save Current Theme","options")); - - QGridLayout * g = new QGridLayout(this,8,2,4,4); - - QLabel * l; - - l = new QLabel(__tr2qs_ctx("Theme name:","options"),this); - g->addWidget(l,0,0); - - m_pThemeNameEdit = new QLineEdit(this); - g->addMultiCellWidget(m_pThemeNameEdit,0,0,1,2); - connect(m_pThemeNameEdit,SIGNAL(textChanged(const QString &)),this,SLOT(themeNameChanged(const QString &))); - - - l = new QLabel(__tr2qs_ctx("Version:","options"),this); - g->addWidget(l,1,0); - - m_pVersionEdit = new QLineEdit(this); - g->addMultiCellWidget(m_pVersionEdit,1,1,1,2); - - - l = new QLabel(__tr2qs_ctx("Author:","options"),this); - g->addWidget(l,2,0); - - m_pAuthorEdit = new QLineEdit(this); - g->addMultiCellWidget(m_pAuthorEdit,2,2,1,2); - - l = new QLabel(__tr2qs_ctx("Description:","options"),this); - g->addWidget(l,3,0); - - m_pDescriptionEdit = new QTextEdit(this); - g->addMultiCellWidget(m_pDescriptionEdit,3,4,1,2); - - m_pIncludeMsgcolors = new KviStyledCheckBox( __tr2qs_ctx("Include message colors information","options"), this ); - m_pIncludeMsgcolors->setChecked(TRUE); - g->addMultiCellWidget(m_pIncludeMsgcolors,5,5,0,1); - - l = new QLabel(__tr2qs_ctx("Package type:","options"),this); - g->addWidget(l,6,0); - - m_pFormatCombo = new QComboBox(this); - m_pFormatCombo->insertItem(__tr2qs_ctx("KVIrc Package","options"),0); -// m_pFormatCombo->insertItem(__tr2qs_ctx("New multi-file format","options"),1); - m_pFormatCombo->insertItem(__tr2qs_ctx("Dublicate Theme","options"),1); - g->addWidget(m_pFormatCombo,6,1); - - QHBox * h = new QHBox(this); - h->setSpacing(7); - g->addWidget(h,7,2); - m_pOkButton = new QPushButton(__tr2qs_ctx("OK","options"),h); - m_pOkButton->setEnabled(false); - connect(m_pOkButton,SIGNAL(clicked()),this,SLOT(saveTheme())); - m_pOkButton->setIconSet(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_ACCEPT))); - - QPushButton * pb = new QPushButton(__tr2qs_ctx("Cancel","options"),h); - connect(pb,SIGNAL(clicked()),this,SLOT(reject())); - pb->setIconSet(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_DISCARD))); - -} - -KviSaveThemeDialog::~KviSaveThemeDialog() -{ - -} - -void KviSaveThemeDialog::themeNameChanged(const QString &txt) -{ - m_pOkButton->setEnabled(!txt.isEmpty()); -} - -void KviSaveThemeDialog::saveThemeInOldFormat(KviThemeInfo& sto) -{ - if(!KviFileUtils::directoryExists(sto.szAbsoluteDirectory)) - { - g_pApp->getLocalKvircDirectory(sto.szAbsoluteDirectory,KviApp::Themes,sto.szSubdirectory,true); - if(!KviFileUtils::makeDir(sto.szAbsoluteDirectory)) - { - QMessageBox::critical(this,__tr2qs_ctx("Save Theme - KVIrc","options"),__tr2qs_ctx("Unable to create theme directory.","options"), - QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton); - return; - } - } - g_pApp->saveTheme(sto); - // write down the images - - QString szMsg = __tr2qs_ctx("Theme saved successfully to ","options"); - szMsg += sto.szAbsoluteDirectory; - - QMessageBox::information(this,__tr2qs_ctx("Save Theme - KVIrc","options"),szMsg,QMessageBox::Ok, - QMessageBox::NoButton,QMessageBox::NoButton); -} - -void KviSaveThemeDialog::saveThemeInNewFormat(KviThemeInfo& sto) -{ - QString szBaseDir; - QFileDialog * d = new QFileDialog(this); - d->setCaption(__tr2qs_ctx("Choose save directory","options")); - d->setMode(QFileDialog::DirectoryOnly); - if(d->exec() == QDialog::Accepted) - { - szBaseDir = d->selectedFile(); - KviFileUtils::adjustFilePath(szBaseDir); - delete d; - if(szBaseDir.isEmpty()) - { - QMessageBox::critical(this,__tr2qs_ctx("Save Theme - KVIrc","options"),__tr2qs_ctx("You must select save directory","options"), - QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton); - return; - } - } else { - delete d; - QMessageBox::critical(this,__tr2qs_ctx("Save Theme - KVIrc","options"),__tr2qs_ctx("You must select save directory","options"), - QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton); - return; - } - KviQString::ensureLastCharIs(szBaseDir,KVI_PATH_SEPARATOR_CHAR); - sto.szAbsoluteDirectory=szBaseDir+sto.szSubdirectory; - KviQString::ensureLastCharIs(sto.szAbsoluteDirectory,KVI_PATH_SEPARATOR_CHAR); - QString szThemeDir=sto.szAbsoluteDirectory; - sto.szAbsoluteDirectory+="files"; - - if(!KviFileUtils::makeDir(sto.szAbsoluteDirectory)) - { - QMessageBox::critical(this,__tr2qs_ctx("Save Theme - KVIrc","options"),__tr2qs_ctx("Unable to create theme files directory.","options"), - QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton); - return; - } - - g_pApp->saveTheme(sto); - - if(!KviFileUtils::makeDir(szThemeDir+"utils")) - { - QMessageBox::critical(this,__tr2qs_ctx("Save Theme - KVIrc","options"),__tr2qs_ctx("Unable to create theme utils directory.","options"), - QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton); - return; - } - - QString szInstallerScript; - g_pApp->getGlobalKvircDirectory(szInstallerScript,KviApp::DefScript,"installer.kvs"); - if(!KviFileUtils::fileExists(szInstallerScript)) - { - QMessageBox::critical(this,__tr2qs_ctx("Save Theme - KVIrc","options"),__tr2qs_ctx("Cannot find installer.kvs.","options"), - QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton); - return; - } - - if(!KviFileUtils::copyFile(szInstallerScript,szThemeDir+"utils/installer.kvs")) - { - QMessageBox::critical(this,__tr2qs_ctx("Save Theme - KVIrc","options"),__tr2qs_ctx("Cannot write installer.kvs.","options"), - QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton); - return; - } - - g_pApp->getGlobalKvircDirectory(szInstallerScript,KviApp::DefScript,"theme-install.kvs"); - QString szMainScript=szThemeDir+"install.kvs"; - if(!KviFileUtils::copyFile(szInstallerScript,szMainScript)) - { - QMessageBox::critical(this,__tr2qs_ctx("Save Theme - KVIrc","options"),__tr2qs_ctx("Cannot write install.kvs.","options"), - QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton); - return; - } - QFile installFile(szMainScript); - if(!installFile.open(IO_ReadOnly)) - { - QMessageBox::critical(this,__tr2qs_ctx("Save Theme - KVIrc","options"),__tr2qs_ctx("Cannot open install.kvs for reading.","options"), - QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton); - return; - } - - QCString szFileContents; - szFileContents=installFile.readAll(); - installFile.close(); - - sto.szName.replace("\"","\\\""); - - szFileContents.replace("@THEMENAME@",sto.szName.utf8().data()); -// szFileContents.replace("@THEMENAME@",sto.szName.utf8().data()); - sto.szDescription.replace("\"","\\\""); - if(sto.szDescription.isEmpty()) sto.szDescription="empty"; - szFileContents.replace("@THEMEDESCRIPTION@",sto.szDescription.utf8().data()); - sto.szVersion.replace("\"","\\\""); - szFileContents.replace("@THEMEVERSION@",sto.szVersion.utf8().data()); - szFileContents.replace("@SUBDIR@",sto.szSubdirectory.utf8().data()); - - QString szAliasName=""; - QString m_szId; - - struct timeval tv; - kvi_gettimeofday(&tv,0); - - KviQString::sprintf(m_szId,"theme_%d%d%d",tv.tv_usec,rand() % 1000,rand() % 1000); - szAliasName.prepend(m_szId); - szFileContents.replace("@ALIASNAME@",szAliasName.utf8().data()); - if(!installFile.open(IO_WriteOnly)) - { - QMessageBox::critical(this,__tr2qs_ctx("Save Theme - KVIrc","options"),__tr2qs_ctx("Cannot open install.kvs for writing.","options"), - QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton); - return; - } - installFile.writeBlock(szFileContents.data(),szFileContents.length()); - installFile.close(); - - QString szMsg = __tr2qs_ctx("Theme saved successfully to ","options"); - szMsg += szThemeDir; - - QMessageBox::information(this,__tr2qs_ctx("Save Theme - KVIrc","options"),szMsg,QMessageBox::Ok, - QMessageBox::NoButton,QMessageBox::NoButton); -} - -void KviSaveThemeDialog::saveThemeInXmlFormat(KviThemeInfo& sto) -{ - QString szFilename; - QFileDialog * d = new QFileDialog(this); - d->setCaption(__tr2qs_ctx("Choose filaname","options")); - d->setMode(QFileDialog::AnyFile); - d->setFilter( "KVIrc Packages (*.kvp)" ); - if(d->exec() == QDialog::Accepted) - { - szFilename = d->selectedFile(); - KviFileUtils::adjustFilePath(szFilename); - delete d; - if(szFilename.isEmpty()) - { - QMessageBox::critical(this,__tr2qs_ctx("Save Theme - KVIrc","options"),__tr2qs_ctx("You must select filename","options"), - QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton); - return; - } - } else { - delete d; - QMessageBox::critical(this,__tr2qs_ctx("Save Theme - KVIrc","options"),__tr2qs_ctx("You must select filename","options"), - QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton); - return; - } - if(QFileInfo(szFilename).extension()!="kvp") szFilename.append(".kvp"); - g_pApp->saveXmlTheme(sto,szFilename); -} - -void KviSaveThemeDialog::saveTheme() -{ - KviThemeInfo sto; - sto.szName = m_pThemeNameEdit->text(); - if(sto.szName.isEmpty()) - { - QMessageBox::critical(this,__tr2qs_ctx("Save Theme - KVIrc","options"),__tr2qs_ctx("You must choose a theme name!","options"),QMessageBox::Ok, - QMessageBox::NoButton,QMessageBox::NoButton); - return; - } - - sto.szAuthor = m_pAuthorEdit->text(); - sto.szDescription = m_pDescriptionEdit->text(); - sto.szDate = QDateTime::currentDateTime().toString(); - sto.szVersion = m_pVersionEdit->text(); - sto.szKvircVersion = KVI_VERSION; - sto.bIncludeMsgColors=m_pIncludeMsgcolors->isChecked(); - - if(sto.szVersion.isEmpty())sto.szVersion = "1.0.0"; - - sto.szSubdirectory = sto.szName + QString("-") + sto.szVersion; - sto.szSubdirectory.replace(QRegExp("[ \\\\/:][ \\\\/:]*"),"_"); - - switch(m_pFormatCombo->currentItem()) - { - case 0: - saveThemeInXmlFormat(sto); - break; - case 1: -/* saveThemeInNewFormat(sto); - break; - case 2:*/ - saveThemeInOldFormat(sto); - break; - } - - accept(); -} - - - - -KviThemeListBoxItem::KviThemeListBoxItem(QListBox * box,KviThemeInfo * inf) -: QListBoxText(box) -{ - m_pThemeInfo = inf; - QString t; - t = "<nobr><b>"; - t += inf->szName; - t += "</b>"; - - if(!inf->szVersion.isEmpty()) { - t += "["; - t += inf->szVersion; - t += "]"; - } - - if(!inf->szAuthor.isEmpty()) { - t += " <font color=\"#a0a0a0\"> "; - t += __tr2qs_ctx("by","options"); - t += " "; - t += inf->szAuthor; - t += "</font>"; - } - - t += "</nobr>"; - t += "<br><nobr><font size=\"-1\">"; - t += inf->szDescription; - t += "</font></nobr>"; - m_pText = new QSimpleRichText(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 ) -{ - QListBoxText::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 QListBox * 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; -} - -KviThemeOptionsWidget::KviThemeOptionsWidget(QWidget * parent) -: KviOptionsWidget(parent,"theme_options_widget") -{ - m_pSaveThemeDialog = 0; - - createLayout(2,1); - - QHBox *hb = new QHBox(this); - layout()->addWidget(hb,0,0); - - KviStyledToolButton * tb = new KviStyledToolButton(hb); - tb->setIconSet(*(g_pIconManager->getBigIcon(KVI_BIGICON_OPEN))); - QToolTip::add(tb,__tr2qs_ctx("Install Theme Package","options")); - connect(tb,SIGNAL(clicked()),this,SLOT(installFromXml())); - - tb = new KviStyledToolButton(hb); - tb->setIconSet(*(g_pIconManager->getBigIcon(KVI_BIGICON_SAVE))); - QToolTip::add(tb,__tr2qs_ctx("Save Current Theme...","options")); - connect(tb,SIGNAL(clicked()),this,SLOT(saveCurrentTheme())); - - tb = new KviStyledToolButton(hb); - tb->setIconSet(*(g_pIconManager->getBigIcon(KVI_BIGICON_REMOVE))); - QToolTip::add(tb,__tr2qs_ctx("Delete Selected Theme","options")); - connect(tb,SIGNAL(clicked()),this,SLOT(deleteTheme())); - - tb = new KviStyledToolButton(hb); - tb->setIconSet(*(g_pIconManager->getBigIcon(KVI_BIGICON_WWW))); - QToolTip::add(tb,__tr2qs_ctx("Get More Themes...","options")); - connect(tb,SIGNAL(clicked()),this,SLOT(getMoreThemes())); - - QWidget *w= new QWidget(hb); - w->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Minimum); - - m_pListBox = new QListBox(this); - m_pListBox->setMinimumHeight(400); - m_pListBox->setMinimumWidth(400); - connect(m_pListBox,SIGNAL(doubleClicked ( QListBoxItem * )),this,SLOT(applyTheme ( QListBoxItem * ))); - connect(m_pListBox,SIGNAL(contextMenuRequested(QListBoxItem *,const QPoint &)), - this,SLOT(contextMenuRequested(QListBoxItem *,const QPoint &))); - layout()->addWidget(m_pListBox,1,0); - - layout()->setRowStretch(1,0); - layout()->setColStretch(1,0); - - fillThemeBox(); - m_pContextPopup = new QPopupMenu(this); -} - -KviThemeOptionsWidget::~KviThemeOptionsWidget() -{ - if(m_pSaveThemeDialog) - { - delete m_pSaveThemeDialog; - m_pSaveThemeDialog = 0; - } -} - -void KviThemeOptionsWidget::contextMenuRequested ( QListBoxItem * 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","options"),this,SLOT(deleteTheme())); - m_pContextPopup->insertItem(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_ACCEPT)),__tr2qs_ctx("&Apply Theme","options"),this,SLOT(applyCurrentTheme())); - m_pContextPopup->popup(pos); - } -} - -void KviThemeOptionsWidget::applyTheme ( QListBoxItem * it) -{ - if(it) m_pListBox->setCurrentItem(it); - applyCurrentTheme(); -} - -void KviThemeOptionsWidget::applyCurrentTheme() -{ - KviThemeListBoxItem * it = (KviThemeListBoxItem *)m_pListBox->item(m_pListBox->currentItem()); - if(!it)return; - - if(KviMessageBox::yesNo(__tr2qs_ctx("Apply theme - KVIrc","options"), - __tr2qs_ctx("Do you wish to apply theme \"%Q\" (version %Q)?","options"), - &(it->themeInfo()->szName),&(it->themeInfo()->szVersion))) { - - QString szPath = it->themeInfo()->szAbsoluteDirectory; - if(szPath.isEmpty())return; - - g_pApp->loadTheme(szPath); - } -} - -void KviThemeOptionsWidget::deleteTheme() -{ - KviThemeListBoxItem* pItem=(KviThemeListBoxItem* )(m_pListBox->selectedItem()); - if(pItem) - { - KviThemeInfo * pInfo=pItem->themeInfo(); - QDir d(pInfo->szAbsoluteDirectory); - KviQString::ensureLastCharIs(pInfo->szAbsoluteDirectory,KVI_PATH_SEPARATOR_CHAR); - QStringList sl = d.entryList(QDir::Files); - for(QStringList::Iterator it=sl.begin();it != sl.end();it++) - { - KviFileUtils::removeFile(pInfo->szAbsoluteDirectory+*it); - } - KviFileUtils::removeDir(pInfo->szAbsoluteDirectory); - fillThemeBox(); - } -} - -void KviThemeOptionsWidget::installFromXml() -{ - QString szFilename; - QFileDialog * d = new QFileDialog(this); - d->setCaption(__tr2qs_ctx("Choose filaname","options")); - d->setMode(QFileDialog::ExistingFile); - d->setFilter( "KVIrc Packages (*.kvp, *.kvxml)" ); - if(d->exec() == QDialog::Accepted) - { - szFilename = d->selectedFile(); - KviFileUtils::adjustFilePath(szFilename); - delete d; - if(szFilename.isEmpty()) - { - QMessageBox::critical(this,__tr2qs_ctx("Open Theme - KVIrc","options"),__tr2qs_ctx("You must select file","options"), - QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton); - return; - } - } else { - delete d; - return; - } - KviXmlAddonLoader * pLoader = new KviXmlAddonLoader(szFilename,this); - pLoader->exec(); - fillThemeBox(); -} - -void KviThemeOptionsWidget::getMoreThemes() -{ - if(!g_pFrame)return; - g_pFrame->executeInternalCommand(KVI_INTERNALCOMMAND_OPENURL_KVIRC_THEMES); -} - -void KviThemeOptionsWidget::saveCurrentTheme() -{ - if(m_pSaveThemeDialog)return; - m_pSaveThemeDialog = new KviSaveThemeDialog(this); - m_pSaveThemeDialog->exec(); - if(m_pSaveThemeDialog) - { - delete m_pSaveThemeDialog; - m_pSaveThemeDialog = 0; - fillThemeBox(); - } -} - -void KviThemeOptionsWidget::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(g_pApp->loadThemeInfo(szTest,*inf)) - { - KviThemeListBoxItem * item = 0; - item = new KviThemeListBoxItem(m_pListBox,inf); - } else { - delete inf; - } - } -} - -void KviThemeOptionsWidget::fillThemeBox() -{ - m_pListBox->clear(); - - KviThemeInfo * ti = new KviThemeInfo; - ti->szName = __tr2qs_ctx("Current Theme","options"); - - KviThemeListBoxItem * itewrq = new KviThemeListBoxItem(m_pListBox,ti); - - QString szDir; - g_pApp->getGlobalKvircDirectory(szDir,KviApp::Themes); - fillThemeBox(szDir); - g_pApp->getLocalKvircDirectory(szDir,KviApp::Themes); - fillThemeBox(szDir); - - m_pListBox->setCurrentItem(itewrq); -} - -void KviThemeOptionsWidget::commit() -{ - KviOptionsWidget::commit(); -} #include "m_optw_theme.moc" diff --git a/src/modules/options/optw_theme.h b/src/modules/options/optw_theme.h index 076e45a02..729c72e2c 100644 --- a/src/modules/options/optw_theme.h +++ b/src/modules/options/optw_theme.h @@ -1,12 +1,13 @@ #ifndef _OPTW_THEME_H_ #define _OPTW_THEME_H_ +//============================================================================= // // File : optw_theme.h // Creation date : Sun May 25 2003 18:03:11 by Szymon Stefanek // // This file is part of the KVirc irc client distribution -// Copyright (C) 2003 Szymon Stefanek (pragma at kvirc dot net) +// Copyright (C) 2003-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 @@ -22,90 +23,8 @@ // 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_optionswidget.h" -#include <qdialog.h> -#include <qsimplerichtext.h> -#include <qlistbox.h> -#include <qcombobox.h> -#include <qpopupmenu.h> -#include <qcursor.h> -#define KVI_OPTIONS_WIDGET_ICON_KviThemeOptionsWidget KVI_SMALLICON_GUI -#define KVI_OPTIONS_WIDGET_NAME_KviThemeOptionsWidget __tr2qs_no_lookup("Load & Save") -#define KVI_OPTIONS_WIDGET_PRIORITY_KviThemeOptionsWidget 90000 -#define KVI_OPTIONS_WIDGET_KEYWORDS_KviThemeOptionsWidget __tr2qs_no_lookup("theme") -#define KVI_OPTIONS_WIDGET_GROUP_KviThemeOptionsWidget "themeLoader" - -class QLineEdit; -class QTextEdit; -class QPushButton; -class QLabel; -class QCheckBox; -typedef struct _KviThemeInfoTag KviThemeInfo; - -class KviSaveThemeDialog : public QDialog -{ - Q_OBJECT -public: - KviSaveThemeDialog(QWidget *par); - ~KviSaveThemeDialog(); -protected: - QLineEdit * m_pAuthorEdit; - QLineEdit * m_pThemeNameEdit; - QLineEdit * m_pVersionEdit; - QTextEdit * m_pDescriptionEdit; - QPushButton * m_pOkButton; - QComboBox * m_pFormatCombo; - QCheckBox * m_pIncludeMsgcolors; - -private: - void saveThemeInNewFormat(KviThemeInfo& info); - void saveThemeInOldFormat(KviThemeInfo& info); - void saveThemeInXmlFormat(KviThemeInfo& info); -protected slots: - void saveTheme(); - void themeNameChanged(const QString &txt); -}; - -class KviThemeListBoxItem : public QListBoxText -{ -public: - KviThemeListBoxItem(QListBox * box,KviThemeInfo * inf); - ~KviThemeListBoxItem(); -public: - KviThemeInfo * m_pThemeInfo; - QSimpleRichText * m_pText; -public: - KviThemeInfo * themeInfo(){ return m_pThemeInfo; }; - virtual int height ( const QListBox * lb ) const ; -protected: - virtual void paint ( QPainter * painter ); -}; - - -class KviThemeOptionsWidget : public KviOptionsWidget -{ - Q_OBJECT -public: - KviThemeOptionsWidget(QWidget * parent); - ~KviThemeOptionsWidget(); -protected: - QListBox * m_pListBox; - QPopupMenu * m_pContextPopup; - KviSaveThemeDialog * m_pSaveThemeDialog; -protected: - virtual void commit(); - void fillThemeBox(const QString &szDir); -protected slots: - void saveCurrentTheme(); - void getMoreThemes(); - void installFromXml(); - void fillThemeBox(); - void deleteTheme(); - void applyTheme ( QListBoxItem * ); - void applyCurrentTheme(); - void contextMenuRequested ( QListBoxItem * item, const QPoint & pos ); -}; #endif //!_OPTW_THEME_H_ diff --git a/src/modules/theme/.svnignore b/src/modules/theme/.svnignore new file mode 100644 index 000000000..087a502ca --- /dev/null +++ b/src/modules/theme/.svnignore @@ -0,0 +1,11 @@ +Makefile.in +Makefile +.deps +*.o +*.lo +*.la +*.moc +.libs +.mospics +moc_*.cpp +.pics
\ No newline at end of file diff --git a/src/modules/theme/Makefile.am b/src/modules/theme/Makefile.am new file mode 100644 index 000000000..fba495058 --- /dev/null +++ b/src/modules/theme/Makefile.am @@ -0,0 +1,20 @@ +############################################################################### +# 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 +nodist_libkvitheme_la_SOURCES = moc_managementdialog.cpp + +libkvitheme_la_LIBADD = $(SS_LIBLINK) ../../kvilib/build/libkvilib.la + +noinst_HEADERS= managementdialog.h + +moc_managementdialog.cpp: managementdialog.h + $(SS_QT_MOC) $< -o $@ diff --git a/src/modules/theme/libkvitheme.cpp b/src/modules/theme/libkvitheme.cpp new file mode 100644 index 000000000..72b6261a3 --- /dev/null +++ b/src/modules/theme/libkvitheme.cpp @@ -0,0 +1,122 @@ +/////////////////////////////////////////////////////////////////////////////// +// +// 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. ,59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 "managementdialog.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) +{ + 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); + + 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 000000000..566b2691c --- /dev/null +++ b/src/modules/theme/managementdialog.cpp @@ -0,0 +1,1148 @@ +//============================================================================= +// +// 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. ,59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 "kvi_xmladdonloader.h" +#include "kvi_iconmanager.h" +#include "kvi_msgbox.h" + +#include <qlayout.h> +#include <qpushbutton.h> +#include <qlistbox.h> +#include <qlineedit.h> +#include <qtextedit.h> +#include <qregexp.h> +#include <qmessagebox.h> +#include <qdir.h> +#include <qstringlist.h> +#include <qdatetime.h> +#include <qfiledialog.h> +#include <qpopupmenu.h> +#include <qcombobox.h> +#include <qpainter.h> +#include <qtooltip.h> +#include <qimage.h> +#include <qtextedit.h> +#include <qmultilineedit.h> +#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 <stdlib.h> // rand & srand + +extern QRect g_rectManagementDialogGeometry; + +KviSaveThemeDialog::KviSaveThemeDialog(QWidget * par) +: QDialog(par) +{ + setCaption(__tr2qs_ctx("Save Current Theme","theme")); + + QGridLayout * g = new QGridLayout(this,8,2,4,4); + + QLabel * l; + + l = new QLabel(__tr2qs_ctx("Theme name:","theme"),this); + g->addWidget(l,0,0); + + m_pThemeNameEdit = new QLineEdit(this); + g->addMultiCellWidget(m_pThemeNameEdit,0,0,1,2); + connect(m_pThemeNameEdit,SIGNAL(textChanged(const QString &)),this,SLOT(themeNameChanged(const QString &))); + + + l = new QLabel(__tr2qs_ctx("Version:","theme"),this); + g->addWidget(l,1,0); + + m_pVersionEdit = new QLineEdit(this); + g->addMultiCellWidget(m_pVersionEdit,1,1,1,2); + + + l = new QLabel(__tr2qs_ctx("Author:","theme"),this); + g->addWidget(l,2,0); + + m_pAuthorEdit = new QLineEdit(this); + g->addMultiCellWidget(m_pAuthorEdit,2,2,1,2); + + l = new QLabel(__tr2qs_ctx("Description:","theme"),this); + g->addWidget(l,3,0); + + m_pDescriptionEdit = new QTextEdit(this); + g->addMultiCellWidget(m_pDescriptionEdit,3,4,1,2); + + m_pIncludeMsgcolors = new KviStyledCheckBox( __tr2qs_ctx("Include message colors information","theme"), this ); + m_pIncludeMsgcolors->setChecked(TRUE); + g->addMultiCellWidget(m_pIncludeMsgcolors,5,5,0,1); + +// l = new QLabel(__tr2qs_ctx("Package type:","theme"),this); +// g->addWidget(l,6,0); + +// m_pFormatCombo = new QComboBox(this); +// m_pFormatCombo->insertItem(__tr2qs_ctx("KVIrc Package","theme"),0); +// m_pFormatCombo->insertItem(__tr2qs_ctx("New multi-file format","theme"),1); +// m_pFormatCombo->insertItem(__tr2qs_ctx("Dublicate Theme","theme"),1); +// g->addWidget(m_pFormatCombo,6,1); + + QHBox * h = new QHBox(this); + h->setSpacing(7); + g->addWidget(h,7,2); + m_pOkButton = new QPushButton(__tr2qs_ctx("OK","theme"),h); + m_pOkButton->setEnabled(false); + connect(m_pOkButton,SIGNAL(clicked()),this,SLOT(saveTheme())); + m_pOkButton->setIconSet(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_ACCEPT))); + + QPushButton * pb = new QPushButton(__tr2qs_ctx("Cancel","theme"),h); + connect(pb,SIGNAL(clicked()),this,SLOT(reject())); + pb->setIconSet(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_DISCARD))); + +} + +KviSaveThemeDialog::~KviSaveThemeDialog() +{ + +} + +void KviSaveThemeDialog::themeNameChanged(const QString &txt) +{ + m_pOkButton->setEnabled(!txt.isEmpty()); +} + +void KviSaveThemeDialog::saveThemeInOldFormat(KviThemeInfo& sto) +{ + if(!KviFileUtils::directoryExists(sto.szAbsoluteDirectory)) + { + g_pApp->getLocalKvircDirectory(sto.szAbsoluteDirectory,KviApp::Themes,sto.szSubdirectory,true); + if(!KviFileUtils::makeDir(sto.szAbsoluteDirectory)) + { + QMessageBox::critical(this,__tr2qs_ctx("Save Theme - KVIrc","theme"),__tr2qs_ctx("Unable to create theme directory.","theme"), + QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton); + return; + } + } + g_pApp->saveTheme(sto); + // write down the images + + QString szMsg = __tr2qs_ctx("Theme saved successfully to ","theme"); + szMsg += sto.szAbsoluteDirectory; + + QMessageBox::information(this,__tr2qs_ctx("Save Theme - KVIrc","theme"),szMsg,QMessageBox::Ok, + QMessageBox::NoButton,QMessageBox::NoButton); +} + +void KviSaveThemeDialog::saveThemeInNewFormat(KviThemeInfo& sto) +{ + QString szBaseDir; + QFileDialog * d = new QFileDialog(this); + d->setCaption(__tr2qs_ctx("Choose save directory","theme")); + d->setMode(QFileDialog::DirectoryOnly); + if(d->exec() == QDialog::Accepted) + { + szBaseDir = d->selectedFile(); + KviFileUtils::adjustFilePath(szBaseDir); + delete d; + if(szBaseDir.isEmpty()) + { + QMessageBox::critical(this,__tr2qs_ctx("Save Theme - KVIrc","theme"),__tr2qs_ctx("You must select save directory","theme"), + QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton); + return; + } + } else { + delete d; + QMessageBox::critical(this,__tr2qs_ctx("Save Theme - KVIrc","theme"),__tr2qs_ctx("You must select save directory","theme"), + QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton); + return; + } + KviQString::ensureLastCharIs(szBaseDir,KVI_PATH_SEPARATOR_CHAR); + sto.szAbsoluteDirectory=szBaseDir+sto.szSubdirectory; + KviQString::ensureLastCharIs(sto.szAbsoluteDirectory,KVI_PATH_SEPARATOR_CHAR); + QString szThemeDir=sto.szAbsoluteDirectory; + sto.szAbsoluteDirectory+="files"; + + if(!KviFileUtils::makeDir(sto.szAbsoluteDirectory)) + { + QMessageBox::critical(this,__tr2qs_ctx("Save Theme - KVIrc","theme"),__tr2qs_ctx("Unable to create theme files directory.","theme"), + QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton); + return; + } + + g_pApp->saveTheme(sto); + + if(!KviFileUtils::makeDir(szThemeDir+"utils")) + { + QMessageBox::critical(this,__tr2qs_ctx("Save Theme - KVIrc","theme"),__tr2qs_ctx("Unable to create theme utils directory.","theme"), + QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton); + return; + } + + QString szInstallerScript; + g_pApp->getGlobalKvircDirectory(szInstallerScript,KviApp::DefScript,"installer.kvs"); + if(!KviFileUtils::fileExists(szInstallerScript)) + { + QMessageBox::critical(this,__tr2qs_ctx("Save Theme - KVIrc","theme"),__tr2qs_ctx("Cannot find installer.kvs.","theme"), + QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton); + return; + } + + if(!KviFileUtils::copyFile(szInstallerScript,szThemeDir+"utils/installer.kvs")) + { + QMessageBox::critical(this,__tr2qs_ctx("Save Theme - KVIrc","theme"),__tr2qs_ctx("Cannot write installer.kvs.","theme"), + QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton); + return; + } + + g_pApp->getGlobalKvircDirectory(szInstallerScript,KviApp::DefScript,"theme-install.kvs"); + QString szMainScript=szThemeDir+"install.kvs"; + if(!KviFileUtils::copyFile(szInstallerScript,szMainScript)) + { + QMessageBox::critical(this,__tr2qs_ctx("Save Theme - KVIrc","theme"),__tr2qs_ctx("Cannot write install.kvs.","theme"), + QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton); + return; + } + QFile installFile(szMainScript); + if(!installFile.open(IO_ReadOnly)) + { + QMessageBox::critical(this,__tr2qs_ctx("Save Theme - KVIrc","theme"),__tr2qs_ctx("Cannot open install.kvs for reading.","theme"), + QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton); + return; + } + + QCString szFileContents; + szFileContents=installFile.readAll(); + installFile.close(); + + sto.szName.replace("\"","\\\""); + + szFileContents.replace("@THEMENAME@",sto.szName.utf8().data()); +// szFileContents.replace("@THEMENAME@",sto.szName.utf8().data()); + sto.szDescription.replace("\"","\\\""); + if(sto.szDescription.isEmpty()) sto.szDescription="empty"; + szFileContents.replace("@THEMEDESCRIPTION@",sto.szDescription.utf8().data()); + sto.szVersion.replace("\"","\\\""); + szFileContents.replace("@THEMEVERSION@",sto.szVersion.utf8().data()); + szFileContents.replace("@SUBDIR@",sto.szSubdirectory.utf8().data()); + + QString szAliasName=""; + QString m_szId; + + struct timeval tv; + kvi_gettimeofday(&tv,0); + + KviQString::sprintf(m_szId,"theme_%d%d%d",tv.tv_usec,rand() % 1000,rand() % 1000); + szAliasName.prepend(m_szId); + szFileContents.replace("@ALIASNAME@",szAliasName.utf8().data()); + if(!installFile.open(IO_WriteOnly)) + { + QMessageBox::critical(this,__tr2qs_ctx("Save Theme - KVIrc","theme"),__tr2qs_ctx("Cannot open install.kvs for writing.","theme"), + QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton); + return; + } + installFile.writeBlock(szFileContents.data(),szFileContents.length()); + installFile.close(); + + QString szMsg = __tr2qs_ctx("Theme saved successfully to ","theme"); + szMsg += szThemeDir; + + QMessageBox::information(this,__tr2qs_ctx("Save Theme - KVIrc","theme"),szMsg,QMessageBox::Ok, + QMessageBox::NoButton,QMessageBox::NoButton); +} + +void KviSaveThemeDialog::saveThemeInXmlFormat(KviThemeInfo& sto) +{ + QString szFilename; + QFileDialog * d = new QFileDialog(this); + d->setCaption(__tr2qs_ctx("Choose filaname","theme")); + d->setMode(QFileDialog::AnyFile); + d->setFilter( "KVIrc Packages (*.kvp)" ); + if(d->exec() == QDialog::Accepted) + { + szFilename = d->selectedFile(); + KviFileUtils::adjustFilePath(szFilename); + delete d; + if(szFilename.isEmpty()) + { + QMessageBox::critical(this,__tr2qs_ctx("Save Theme - KVIrc","theme"),__tr2qs_ctx("You must select filename","theme"), + QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton); + return; + } + } else { + delete d; + QMessageBox::critical(this,__tr2qs_ctx("Save Theme - KVIrc","theme"),__tr2qs_ctx("You must select filename","theme"), + QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton); + return; + } + if(QFileInfo(szFilename).extension()!="kvp") szFilename.append(".kvp"); + g_pApp->saveXmlTheme(sto,szFilename); +} + +void KviSaveThemeDialog::saveTheme() +{ + KviThemeInfo sto; + sto.szName = m_pThemeNameEdit->text(); + if(sto.szName.isEmpty()) + { + QMessageBox::critical(this,__tr2qs_ctx("Save Theme - KVIrc","theme"),__tr2qs_ctx("You must choose a theme name!","theme"),QMessageBox::Ok, + QMessageBox::NoButton,QMessageBox::NoButton); + return; + } + + sto.szAuthor = m_pAuthorEdit->text(); + sto.szDescription = m_pDescriptionEdit->text(); + sto.szDate = QDateTime::currentDateTime().toString(); + sto.szVersion = m_pVersionEdit->text(); + sto.szKvircVersion = KVI_VERSION; + sto.bIncludeMsgColors=m_pIncludeMsgcolors->isChecked(); + + if(sto.szVersion.isEmpty())sto.szVersion = "1.0.0"; + + sto.szSubdirectory = sto.szName + QString("-") + sto.szVersion; + sto.szSubdirectory.replace(QRegExp("[ \\\\/:][ \\\\/:]*"),"_"); + +/* + switch(m_pFormatCombo->currentItem()) + { + case 0: + saveThemeInXmlFormat(sto); + break; + case 1: + saveThemeInNewFormat(sto); + break; + case 2:*/ + saveThemeInOldFormat(sto); +/* break; + } +*/ + accept(); +} + +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + + +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + +KviPackThemeDialog::KviPackThemeDialog(QWidget * pParent,KviPtrList<KviThemeInfo> * pThemeInfoList) +: QWizard(pParent) +{ + m_pThemeInfoList = pThemeInfoList; + + KviThemeInfo * pThemeInfo; + QString szPackageName; + QString szPackageAuthor; + QString szPackageDescription; + QString szPackageVersion; + if(m_pThemeInfoList->count() > 1) + { + szPackageName = "MyThemes"; + szPackageAuthor = __tr2qs_ctx("Your name here","theme"); + szPackageVersion = "1.0"; + szPackageDescription = __tr2qs_ctx("Put a package description here...","theme"); + } else { + if(m_pThemeInfoList->count() > 0) + { + pThemeInfo = m_pThemeInfoList->first(); + szPackageName = pThemeInfo->szSubdirectory; + szPackageAuthor = pThemeInfo->szAuthor; + szPackageDescription = pThemeInfo->szDescription; + szPackageVersion = pThemeInfo->szVersion; + } + } + + + 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 szAuthor = __tr2qs_ctx("Author","theme"); + QString szCreatedAt = __tr2qs_ctx("Created at","theme"); + QString szCreatedOn = __tr2qs_ctx("Created on","theme"); + QString szSubdirectory = __tr2qs_ctx("Subdirectory","theme"); + + QString szThemesDescription = "<html><body bgcolor=\"#ffffff\">"; + + int iIdx = 0; + for(pThemeInfo = m_pThemeInfoList->first();pThemeInfo;pThemeInfo = m_pThemeInfoList->next()) + { + QString szThemeDescription; + KviQString::sprintf( + szThemeDescription, + "<p>" \ + "<h2>%Q %Q</h2>" \ + "</p>" \ + "<p>" \ + "<i>%Q</i>" \ + "</p>" \ + "<p>" \ + "%Q: <b>%Q</b><br>" \ + "%Q: <b>%Q</b><br>" \ + "</p>" \ + "<p>" \ + "<font color=\"#808080\">" \ + "%Q: KVIrc %Q<br>" \ + "%Q: %Q<br>" \ + "</font>" \ + "</p>", + &(pThemeInfo->szName), + &(pThemeInfo->szVersion), + &(pThemeInfo->szDescription), + &szAuthor, + &(pThemeInfo->szAuthor), + &szCreatedAt, + &(pThemeInfo->szDate), + &szCreatedOn, + &(pThemeInfo->szKvircVersion), + &szSubdirectory, + &(pThemeInfo->szSubdirectory) + ); + if(iIdx > 0) + szThemesDescription += "<hr>"; + szThemesDescription += szThemeDescription; + iIdx++; + } + + szThemesDescription += "</body></html>"; + + QTextEdit * pTextEdit = new QTextEdit(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 QMultiLineEdit(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); + + 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_THEMEPACKAGE; + + 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); + +} + +KviPackThemeDialog::~KviPackThemeDialog() +{ +} + +void KviPackThemeDialog::imageSelectionChanged(const QString &szImagePath) +{ + QImage pix(szImagePath); + if(!pix.isNull()) + { + QPixmap out; + if(pix.width() > 300 || pix.height() > 225) + out.convertFromImage(pix.smoothScale(300,225,QImage::ScaleMin)); + 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; + QWizard::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) + out.convertFromImage(pix.smoothScale(300,225,QImage::ScaleMin)); + 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); + showPage(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("KVIrcVersion",KVI_VERSION); + + if(!out.isNull()) + { + QByteArray * pba = new QByteArray(); + QBuffer buffer(*pba); + 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->szName); + KviQString::sprintf(szTmp,"Theme%dVersion",iIdx); + f.addInfoField(szTmp,pInfo->szVersion); + KviQString::sprintf(szTmp,"Theme%dDescription",iIdx); + f.addInfoField(szTmp,pInfo->szDescription); + KviQString::sprintf(szTmp,"Theme%dDate",iIdx); + f.addInfoField(szTmp,pInfo->szDate); + KviQString::sprintf(szTmp,"Theme%dSubdirectory",iIdx); + f.addInfoField(szTmp,pInfo->szSubdirectory); + KviQString::sprintf(szTmp,"Theme%dAuthor",iIdx); + f.addInfoField(szTmp,pInfo->szAuthor); + KviQString::sprintf(szTmp,"Theme%dKVIrcVersion",iIdx); + f.addInfoField(szTmp,pInfo->szKvircVersion); + if(!f.addDirectory(pInfo->szAbsoluteDirectory,pInfo->szSubdirectory)) + { + 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; +} + + +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + + +KviThemeListBoxItem::KviThemeListBoxItem(QListBox * box,KviThemeInfo * inf) +: QListBoxText(box) +{ + m_pThemeInfo = inf; + QString t; + t = "<nobr><b>"; + t += inf->szName; + t += "</b>"; + + if(!inf->szVersion.isEmpty()) { + t += "["; + t += inf->szVersion; + t += "]"; + } + + if(!inf->szAuthor.isEmpty()) { + t += " <font color=\"#a0a0a0\"> "; + t += __tr2qs_ctx("by","theme"); + t += " "; + t += inf->szAuthor; + t += "</font>"; + } + + t += "</nobr>"; + t += "<br><nobr><font size=\"-1\">"; + t += inf->szDescription; + t += "</font></nobr>"; + m_pText = new QSimpleRichText(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 ) +{ + QListBoxText::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 QListBox * 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_THEMES))); + + setModal(true); + + m_pInstance = this; + + m_pSaveThemeDialog = 0; + + QGridLayout * g = new QGridLayout(this,3,2,4,4); + + QHBox *hb = new QHBox(this); + g->addMultiCellWidget(hb,0,0,0,1); + + KviStyledToolButton * 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(installFromXml())); + + 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())); + + 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())); + + 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 QListBox(this); + m_pListBox->setMinimumHeight(400); + m_pListBox->setMinimumWidth(400); + m_pListBox->setSelectionMode(QListBox::Extended); + connect(m_pListBox,SIGNAL(doubleClicked(QListBoxItem *)),this,SLOT(applyTheme(QListBoxItem *))); + connect(m_pListBox,SIGNAL(contextMenuRequested(QListBoxItem *,const QPoint &)), + this,SLOT(contextMenuRequested(QListBoxItem *,const QPoint &))); + connect(m_pListBox,SIGNAL(selectionChanged()),this,SLOT(enableDisableButtons())); + g->addMultiCellWidget(m_pListBox,1,1,0,1); + + + 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,0); + + fillThemeBox(); + m_pContextPopup = new QPopupMenu(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()); + + if(m_pSaveThemeDialog) + { + delete m_pSaveThemeDialog; + m_pSaveThemeDialog = 0; + } + + m_pInstance = 0; +} + +void KviThemeManagementDialog::closeClicked() +{ + delete this; +} + + +void KviThemeManagementDialog::display() +{ + if(m_pInstance)return; + 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() +{ + KviPtrList<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 ( QListBoxItem * 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 ( QListBoxItem * 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()->szName),&(it->themeInfo()->szVersion))) { + + QString szPath = it->themeInfo()->szAbsoluteDirectory; + if(szPath.isEmpty())return; + + g_pApp->loadTheme(szPath); + } +} + +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()->szName),&(pItem->themeInfo()->szVersion)))goto jump_out; + + KviFileUtils::deleteDir(pItem->themeInfo()->szAbsoluteDirectory); + } + } +jump_out: + fillThemeBox(); +} + +void KviThemeManagementDialog::installFromXml() +{ + QString szFileName; + QDict<QString> * pInfoFields; + QString * pValue; + bool bInstall; + + const char * check_fields[] = { "Name", "Version", "Author", "Description", "Date", "KVIrcVersion" }; + + if(!KviFileDialog::askForOpenFileName(szFileName,__tr2qs_ctx("Open Theme - KVIrc","theme"),QString::null,"*.kvt")) + return; + + // check if it is a valid theme file + KviPackageReader r; + if(!r.readHeader(szFileName)) + { + QString szErr = r.lastError(); + KviMessageBox::information(__tr2qs_ctx("The selected file does not seem to be a valid KVIrc package: %Q","theme"),&szErr); + return; + } + + pInfoFields = r.stringInfoFields(); + + pValue = pInfoFields->find("PackageType"); + if(!pValue)goto not_a_valid_theme_package; + if(!KviQString::equalCI(*pValue,"ThemePack"))goto not_a_valid_theme_package; + pValue = pInfoFields->find("ThemePackVersion"); + if(!pValue)goto not_a_valid_theme_package; + if(!KviQString::equalCI(*pValue,"1"))goto not_a_valid_theme_package; + + // make sure the default fields exist + for(int i=0;i<6;i++) + { + pValue = pInfoFields->find(check_fields[i]); + if(!pValue)goto not_a_valid_theme_package; + } + + pValue = pInfoFields->find("ThemeCount"); + if(!pValue)goto not_a_valid_theme_package; + bool bOk; + int iThemeCount = pValue->toInt(&bOk); + if(!bOk)goto not_a_valid_theme_package; + if(iThemeCount < 1)goto not_a_valid_theme_package; + + // ok.. it should be really valid at this point + + // load it's picture + /* + KviUnpackThemeDialog * pDialog = new KviUnpackThemeDialog(this,szFileName); + bool bInstall = pDialog->exec() == QDialog::Accepted; + delete pDialog; + */ + + bInstall = true; + + if(bInstall) + { + QString szUnpackPath; + g_pApp->getLocalKvircDirectory(szUnpackPath,KviApp::Themes); + if(!r.unpack(szFileName,szUnpackPath)) + { + QString szErr2 = r.lastError(); + KviMessageBox::information(__tr2qs_ctx("Failed to unpack the selected file: %Q","theme"),&szErr2); + return; + } + } + + /* + KviXmlAddonLoader * pLoader = new KviXmlAddonLoader(szFilename,this); + pLoader->exec(); + */ + fillThemeBox(); + return; +not_a_valid_theme_package: + KviMessageBox::information(__tr2qs_ctx("The selected file does not seem to be a valid KVIrc theme package","theme")); + return; +} + +void KviThemeManagementDialog::getMoreThemes() +{ + if(!g_pFrame)return; + g_pFrame->executeInternalCommand(KVI_INTERNALCOMMAND_OPENURL_KVIRC_THEMES); +} + +void KviThemeManagementDialog::saveCurrentTheme() +{ + if(m_pSaveThemeDialog)return; + m_pSaveThemeDialog = new KviSaveThemeDialog(this); + m_pSaveThemeDialog->exec(); + if(m_pSaveThemeDialog) + { + delete m_pSaveThemeDialog; + m_pSaveThemeDialog = 0; + 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; + inf->szSubdirectory = *it; + if(g_pApp->loadThemeInfo(szTest,*inf)) + { + KviThemeListBoxItem * item = 0; + item = new KviThemeListBoxItem(m_pListBox,inf); + } else { + delete inf; + } + } +} + +void KviThemeManagementDialog::fillThemeBox() +{ + m_pListBox->clear(); + +// KviThemeInfo * ti = new KviThemeInfo; +// ti->szName = __tr2qs_ctx("Current Theme","theme"); + +// KviThemeListBoxItem * itewrq = new KviThemeListBoxItem(m_pListBox,ti); + + QString szDir; + g_pApp->getGlobalKvircDirectory(szDir,KviApp::Themes); + fillThemeBox(szDir); + g_pApp->getLocalKvircDirectory(szDir,KviApp::Themes); + fillThemeBox(szDir); + +// m_pListBox->setCurrentItem(itewrq); + enableDisableButtons(); +} + +bool KviThemeManagementDialog::hasSelectedItems() +{ + for(QListBoxItem * 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); +} + + diff --git a/src/modules/theme/managementdialog.h b/src/modules/theme/managementdialog.h new file mode 100644 index 000000000..d88be2ea0 --- /dev/null +++ b/src/modules/theme/managementdialog.h @@ -0,0 +1,164 @@ +#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. ,59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +//============================================================================= + +#include "kvi_optionswidget.h" +#include "kvi_list.h" + +#include <qdialog.h> +#include <qsimplerichtext.h> +#include <qlistbox.h> +#include <qcombobox.h> +#include <qpopupmenu.h> +#include <qcursor.h> +#include <qwizard.h> + +#define KVI_OPTIONS_WIDGET_ICON_KviThemeManagementDialog KVI_SMALLICON_GUI +#define KVI_OPTIONS_WIDGET_NAME_KviThemeManagementDialog __tr2qs_no_lookup("Load & Save") +#define KVI_OPTIONS_WIDGET_PRIORITY_KviThemeManagementDialog 90000 +#define KVI_OPTIONS_WIDGET_KEYWORDS_KviThemeManagementDialog __tr2qs_no_lookup("theme") +#define KVI_OPTIONS_WIDGET_GROUP_KviThemeManagementDialog "themeLoader" + +class QLineEdit; +class QTextEdit; +class QPushButton; +class QLabel; +class QCheckBox; +class QMultiLineEdit; + +typedef struct _KviThemeInfoTag KviThemeInfo; + +class KviSaveThemeDialog : public QDialog +{ + Q_OBJECT +public: + KviSaveThemeDialog(QWidget *par); + ~KviSaveThemeDialog(); +protected: + QLineEdit * m_pAuthorEdit; + QLineEdit * m_pThemeNameEdit; + QLineEdit * m_pVersionEdit; + QTextEdit * m_pDescriptionEdit; + QPushButton * m_pOkButton; +// QComboBox * m_pFormatCombo; + QCheckBox * m_pIncludeMsgcolors; + +private: + void saveThemeInNewFormat(KviThemeInfo& info); + void saveThemeInOldFormat(KviThemeInfo& info); + void saveThemeInXmlFormat(KviThemeInfo& info); +protected slots: + void saveTheme(); + void themeNameChanged(const QString &txt); +}; + +class KviPackThemeDialog : public QWizard +{ + Q_OBJECT +public: + KviPackThemeDialog(QWidget * pParent,KviPtrList<KviThemeInfo> * pThemeInfoList); + ~KviPackThemeDialog(); +protected: + QString m_szImagePath; + KviFileSelector * m_pImageSelector; + QString m_szPackagePath; + KviFileSelector * m_pPathSelector; + QLabel * m_pImageLabel; + KviPtrList<KviThemeInfo> * m_pThemeInfoList; + QLineEdit * m_pPackageNameEdit; + QMultiLineEdit * m_pPackageDescriptionEdit; + QLineEdit * m_pPackageVersionEdit; + QLineEdit * m_pPackagerNameEdit; + QWidget * m_pImageSelectionPage; +protected: + virtual void accept(); +protected slots: + bool packTheme(); + void imageSelectionChanged(const QString &szImagePath); +}; + +/* +class KviUnpackThemeDialog : public QDialog +{ + Q_OBJECT +public: + KviUnpackThemeDialog(QWidget * pParent); + ~KviUnpackThemeDialog(); +}; +*/ + +class KviThemeListBoxItem : public QListBoxText +{ +public: + KviThemeListBoxItem(QListBox * box,KviThemeInfo * inf); + ~KviThemeListBoxItem(); +public: + KviThemeInfo * m_pThemeInfo; + QSimpleRichText * m_pText; +public: + KviThemeInfo * themeInfo(){ return m_pThemeInfo; }; + virtual int height ( const QListBox * lb ) const ; +protected: + virtual void paint ( QPainter * painter ); +}; + + +class KviStyledToolButton; + +class KviThemeManagementDialog : public QDialog +{ + Q_OBJECT +public: + KviThemeManagementDialog(QWidget * parent); + ~KviThemeManagementDialog(); +protected: + static KviThemeManagementDialog * m_pInstance; + QListBox * m_pListBox; + QPopupMenu * m_pContextPopup; + KviSaveThemeDialog * m_pSaveThemeDialog; + 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(); +protected slots: + void saveCurrentTheme(); + void getMoreThemes(); + void installFromXml(); + void fillThemeBox(); + void deleteTheme(); + void closeClicked(); + void packTheme(); + void applyTheme(QListBoxItem *); + void applyCurrentTheme(); + void enableDisableButtons(); + void contextMenuRequested(QListBoxItem * item, const QPoint & pos); +}; + +#endif //!_MANAGEMENTDIALOG_H_ |
