diff options
| author | 2011-03-16 21:58:18 +0000 | |
|---|---|---|
| committer | 2011-03-16 21:58:18 +0000 | |
| commit | b9d79d0d368cccd31e0c00062b3fb3a26da3b1b8 (patch) | |
| tree | 7ec35a1438f8441ec6076e475992a4fa79651701 /src/modules | |
| parent | upd8 spanish translation (diff) | |
| download | KVIrc-b9d79d0d368cccd31e0c00062b3fb3a26da3b1b8.tar.gz KVIrc-b9d79d0d368cccd31e0c00062b3fb3a26da3b1b8.tar.bz2 KVIrc-b9d79d0d368cccd31e0c00062b3fb3a26da3b1b8.zip | |
Code improvements in the theme manager(wip)
git-svn-id: https://svn.kvirc.de/svn/trunk/kvirc@5610 17fca916-40b9-46aa-a4ea-0a15b648b75c
Diffstat (limited to 'src/modules')
| -rw-r--r-- | src/modules/objects/KvsObject_label.cpp | 2 | ||||
| -rw-r--r-- | src/modules/objects/KvsObject_webView.cpp | 43 | ||||
| -rw-r--r-- | src/modules/objects/KvsObject_webView.h | 4 | ||||
| -rw-r--r-- | src/modules/objects/KvsObject_widget.cpp | 1 | ||||
| -rw-r--r-- | src/modules/setup/libkvisetup.cpp | 7 | ||||
| -rw-r--r-- | src/modules/theme/CMakeLists.txt | 4 | ||||
| -rw-r--r-- | src/modules/theme/PackThemeDialog.cpp | 5 | ||||
| -rw-r--r-- | src/modules/theme/SaveThemeDialog.cpp | 20 | ||||
| -rw-r--r-- | src/modules/theme/ThemeFunctions.cpp | 17 | ||||
| -rw-r--r-- | src/modules/theme/ThemeManagementDialog.cpp | 63 | ||||
| -rw-r--r-- | src/modules/theme/ThemeManagementDialog.h | 16 | ||||
| -rw-r--r-- | src/modules/theme/WebThemeInterfaceDialog.cpp | 253 | ||||
| -rw-r--r-- | src/modules/theme/WebThemeInterfaceDialog.h | 73 | ||||
| -rw-r--r-- | src/modules/theme/libkvitheme.cpp | 7 |
14 files changed, 460 insertions, 55 deletions
diff --git a/src/modules/objects/KvsObject_label.cpp b/src/modules/objects/KvsObject_label.cpp index 08cb4ffa1..c5fa7fdd7 100644 --- a/src/modules/objects/KvsObject_label.cpp +++ b/src/modules/objects/KvsObject_label.cpp @@ -6,7 +6,7 @@ // This file is part of the KVIrc irc client distribution // Copyright (C) 2000 Krzysztof Godlewski // Copyright (C) 2000-2010 Szymon Stefanek (pragma at kvirc dot net) -// +//LinkDelegationPolicy // 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 diff --git a/src/modules/objects/KvsObject_webView.cpp b/src/modules/objects/KvsObject_webView.cpp index 0736b2c84..c8c850c6b 100644 --- a/src/modules/objects/KvsObject_webView.cpp +++ b/src/modules/objects/KvsObject_webView.cpp @@ -79,16 +79,16 @@ KviKvsDownloadHandler::~KviKvsDownloadHandler() } void KviKvsDownloadHandler::slotReadyRead() { - qDebug("Slot ready read"); QVariant vSize=m_pReply->header(QNetworkRequest::ContentLengthHeader); + int iSize=0; if(!vSize.isNull()){ bool ok; - int isize; - isize=vSize.toInt(&ok); - qDebug("contents %d",isize); + iSize=vSize.toInt(&ok); } + QByteArray bytes=m_pReply->readAll(); - KviKvsVariantList params(new KviKvsVariant((kvs_int_t)bytes.count()),new KviKvsVariant((kvs_int_t)m_Id)); + KviKvsVariantList params(new KviKvsVariant((kvs_int_t)bytes.count()),\ + new KviKvsVariant((kvs_int_t)m_Id),new KviKvsVariant((kvs_int_t)iSize)); m_pParentScript->callFunction(m_pParentScript,"downloadProgressEvent",¶ms); m_pFile->write(bytes); } @@ -116,6 +116,7 @@ const QWebSettings::WebAttribute webattributes_cod[] = { QWebSettings::ZoomTextOnly #if (QT_VERSION >= 0x040700) , +#if (QT_VERSION >= 0x040700) QWebSettings::LocalContentCanAccessFileUrls #endif }; @@ -166,10 +167,12 @@ KVSO_BEGIN_REGISTERCLASS(KvsObject_webView,"webview","widget") KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_webView,removeFromDocument) KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_webView,removeClass) KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_webView,classes) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_webView,setLinkDelegationPolicy) + + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_webView,linkClickedEvent) KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_webView,loadFinishedEvent) KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_webView,loadProgressEvent) KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_webView,loadStartedEvent) - KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_webView,downloadCompletedEvent) KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_webView,downloadRequestEvent) KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_webView,downloadProgressEvent) @@ -196,6 +199,7 @@ bool KvsObject_webView::init(KviKvsRunTimeContext *c ,KviKvsVariantList *) connect(((QWebView *)widget()),SIGNAL(loadStarted()),this,SLOT(slotLoadStarted())); connect(((QWebView *)widget()),SIGNAL(loadFinished(bool)),this,SLOT(slotLoadFinished(bool))); connect(((QWebView *)widget()),SIGNAL(loadProgress(int)),this,SLOT(slotLoadProgress(int))); + connect(pPage,SIGNAL(linkClicked(const QUrl &)),this,SLOT(slotLinkClicked(const QUrl &))); connect(pPage,SIGNAL(downloadRequested(const QNetworkRequest &)),this,SLOT(slotDownloadRequest(const QNetworkRequest &))); return true; } @@ -217,6 +221,22 @@ void KvsObject_webView::getFrames(QWebFrame *pFrame,KviKvsArray *pArray, kvs_uin } } +KVSO_CLASS_FUNCTION(webView,setLinkDelegationPolicy) +{ + CHECK_INTERNAL_POINTER(widget()) + QString szPolicy; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("policy",KVS_PT_STRING,0,szPolicy) + KVSO_PARAMETERS_END(c) + QWebPage::LinkDelegationPolicy policy = QWebPage::DontDelegateLinks; + if(KviQString::equalCI(szPolicy,"DontDelegateLinks")) policy=QWebPage::DontDelegateLinks; + else if(KviQString::equalCI(szPolicy,"DelegateExternalLinks")) policy=QWebPage::DelegateExternalLinks; + else if(KviQString::equalCI(szPolicy,"DelegateAllLinks")) policy=QWebPage::DelegateAllLinks; + else c->warning(__tr2qs_ctx("Unknown delegation policy '%Q'- Switch do default dontDeleGateLinks","objects"),&szPolicy); + ((QWebView *)widget())->page()->setLinkDelegationPolicy(policy); + return true; +} + KVSO_CLASS_FUNCTION(webView,load) { CHECK_INTERNAL_POINTER(widget()) @@ -557,6 +577,11 @@ KVSO_CLASS_FUNCTION(webView,downloadProgressEvent) emitSignal("downloadProgress",c,c->params()); return true; } +KVSO_CLASS_FUNCTION(webView,linkClickedEvent) +{ + emitSignal("linkClicked",c,c->params()); + return true; +} KVSO_CLASS_FUNCTION(webView,downloadRequestEvent) { emitSignal("downloadRequest",c,c->params()); @@ -583,6 +608,12 @@ void KvsObject_webView::slotLoadProgress(int iProgress) KviKvsVariantList params(new KviKvsVariant((kvs_int_t) iProgress)); callFunction(this,"loadProgressEvent" ,¶ms); } +void KvsObject_webView::slotLinkClicked(const QUrl &url) +{ + QString szUrl=url.toString(); + qDebug("Link clicked %s",szUrl.toUtf8().data()); + +} void KvsObject_webView::slotDownloadRequest(const QNetworkRequest &r) { QNetworkReply *pReply=m_pNetworkManager->get(r); diff --git a/src/modules/objects/KvsObject_webView.h b/src/modules/objects/KvsObject_webView.h index 7cb0dadec..221fb3aea 100644 --- a/src/modules/objects/KvsObject_webView.h +++ b/src/modules/objects/KvsObject_webView.h @@ -80,12 +80,14 @@ protected: bool queryResultsCount(KviKvsObjectFunctionCall *c); bool attributeNames(KviKvsObjectFunctionCall *c); + bool setLinkDelegationPolicy(KviKvsObjectFunctionCall *c); bool setAttribute(KviKvsObjectFunctionCall *c); bool setWebSetting(KviKvsObjectFunctionCall *c); bool attribute(KviKvsObjectFunctionCall *c); bool frames(KviKvsObjectFunctionCall *c); bool loadStartedEvent(KviKvsObjectFunctionCall *c); + bool linkClickedEvent(KviKvsObjectFunctionCall *c); bool loadFinishedEvent(KviKvsObjectFunctionCall *c); bool loadProgressEvent(KviKvsObjectFunctionCall *c); bool downloadCompletedEvent(KviKvsObjectFunctionCall *c); @@ -96,6 +98,8 @@ protected slots: void slotLoadProgress(int); void slotLoadStarted(); void slotDownloadRequest(const QNetworkRequest &); + void slotLinkClicked(const QUrl &); + }; class KviKvsDownloadHandler : public QObject { diff --git a/src/modules/objects/KvsObject_widget.cpp b/src/modules/objects/KvsObject_widget.cpp index 73babf97a..0d1550e9e 100644 --- a/src/modules/objects/KvsObject_widget.cpp +++ b/src/modules/objects/KvsObject_widget.cpp @@ -478,6 +478,7 @@ const char * const widgettypes_tbl[] = { - . [br] - ^ [br] + [/pre] !fn: $mapFromGlobal(<x>,<y>) Translates the global screen coordinate pos to widget coordinates. diff --git a/src/modules/setup/libkvisetup.cpp b/src/modules/setup/libkvisetup.cpp index b176f0b83..20394857d 100644 --- a/src/modules/setup/libkvisetup.cpp +++ b/src/modules/setup/libkvisetup.cpp @@ -86,17 +86,14 @@ KVIMODULEEXPORTFUNC void setup_finish() // #define KVI_DEFAULT_AWAY_MESSAGE "I'm off to see the wizard." // Apply the chosen default theme - QString szDir; KviThemeInfo out; switch(g_iThemeToApply) { case THEME_APPLY_HIRES: - g_pApp->getGlobalKvircDirectory(szDir,KviApplication::Themes,"YellowIRC-1.0.0"); - KviTheme::load(szDir,out); + KviTheme::load("YellowIRC-1.0.0",out,BUILTIN); break; case THEME_APPLY_LORES: - g_pApp->getGlobalKvircDirectory(szDir,KviApplication::Themes,"MinimalDark-1.0.0"); - KviTheme::load(szDir,out); + KviTheme::load("MinimalDark-1.0.0",out,BUILTIN); break; // default: no theme } diff --git a/src/modules/theme/CMakeLists.txt b/src/modules/theme/CMakeLists.txt index 9605b5abe..b68843bc5 100644 --- a/src/modules/theme/CMakeLists.txt +++ b/src/modules/theme/CMakeLists.txt @@ -1,13 +1,15 @@ # CMakeLists for src/modules/theme SET(kvitheme_MOC_HDRS - ThemeManagementDialog.h + WebThemeInterfaceDialog.h + ThemeManagementDialog.h PackThemeDialog.h SaveThemeDialog.h ) SET(kvitheme_SRCS libkvitheme.cpp + WebThemeInterfaceDialog.cpp ThemeManagementDialog.cpp PackThemeDialog.cpp SaveThemeDialog.cpp diff --git a/src/modules/theme/PackThemeDialog.cpp b/src/modules/theme/PackThemeDialog.cpp index 991f1c6ea..dc92c62a7 100644 --- a/src/modules/theme/PackThemeDialog.cpp +++ b/src/modules/theme/PackThemeDialog.cpp @@ -533,8 +533,9 @@ bool PackThemeDialog::packTheme() bufferz.close(); f.addInfoField(szTmp,pba); } - - if(!f.addDirectory(pInfo->absoluteDirectory(),pInfo->subdirectory())) + QString szThemePath; + pInfo->getCompleteDirPath(szThemePath); + if(!f.addDirectory(szThemePath,pInfo->subdirectory())) { szTmp = __tr2qs_ctx("Packaging failed","theme"); szTmp += ": "; diff --git a/src/modules/theme/SaveThemeDialog.cpp b/src/modules/theme/SaveThemeDialog.cpp index 6c4e0e9d7..090b97cd0 100644 --- a/src/modules/theme/SaveThemeDialog.cpp +++ b/src/modules/theme/SaveThemeDialog.cpp @@ -64,6 +64,9 @@ SaveThemeDialog::SaveThemeDialog(QWidget * pParent) setWindowTitle(__tr2qs_ctx("Save Current Theme - KVIrc","theme")); setMinimumSize(400,350); + KviThemeInfo info; + info.load(KVI_OPTION_STRING(KviOption_stringIconThemeSubdir)); + // welcome page ================================================================================== QWidget * pPage = new QWidget(this); QGridLayout * pLayout = new QGridLayout(pPage); @@ -104,7 +107,7 @@ SaveThemeDialog::SaveThemeDialog(QWidget * pParent) pLayout->addWidget(pLabel,1,0); m_pThemeNameEdit = new QLineEdit(pPage); - //m_pThemeNameEdit->setText(szThemeName); + m_pThemeNameEdit->setText(info.name()); pLayout->addWidget(m_pThemeNameEdit,1,1); pLabel = new QLabel(pPage); @@ -112,7 +115,11 @@ SaveThemeDialog::SaveThemeDialog(QWidget * pParent) pLayout->addWidget(pLabel,2,0); m_pThemeVersionEdit = new QLineEdit(pPage); - //m_pThemeVersionEdit->setText(szThemeVersion); + m_pThemeVersionEdit->setText(info.version()); + QRegExp rx("(.[0-9]{1,2}){3,3}"); + QValidator *validator = new QRegExpValidator(rx, this); +m_pThemeVersionEdit->setValidator(validator); + pLayout->addWidget(m_pThemeVersionEdit,2,1); pLabel = new QLabel(pPage); @@ -120,7 +127,7 @@ SaveThemeDialog::SaveThemeDialog(QWidget * pParent) pLayout->addWidget(pLabel,3,0); m_pThemeDescriptionEdit = new QTextEdit(pPage); - //m_pThemeDescriptionEdit->setText(szThemeDescription); + m_pThemeDescriptionEdit->setText(info.description()); pLayout->addWidget(m_pThemeDescriptionEdit,3,1); pLabel = new QLabel(pPage); @@ -128,7 +135,7 @@ SaveThemeDialog::SaveThemeDialog(QWidget * pParent) pLayout->addWidget(pLabel,4,0); m_pAuthorNameEdit = new QLineEdit(pPage); - //m_pAuthorNameEdit->setText(szThemeAuthor); + m_pAuthorNameEdit->setText(info.author()); pLayout->addWidget(m_pAuthorNameEdit,4,1); @@ -272,7 +279,6 @@ bool SaveThemeDialog::saveTheme() return false; } - sto.setAbsoluteDirectory(szAbsDir); if(!KviTheme::save(sto)) { @@ -296,7 +302,9 @@ bool SaveThemeDialog::saveTheme() } QString szMsg = __tr2qs_ctx("Theme saved successfully to ","theme"); - szMsg += sto.absoluteDirectory(); + QString szThemePath; + sto.getCompleteDirPath(szThemePath); + szMsg += szThemePath; QMessageBox::information(this,__tr2qs_ctx("Save Theme - KVIrc","theme"),szMsg,QMessageBox::Ok, QMessageBox::NoButton,QMessageBox::NoButton); diff --git a/src/modules/theme/ThemeFunctions.cpp b/src/modules/theme/ThemeFunctions.cpp index a24684c7b..271fef739 100644 --- a/src/modules/theme/ThemeFunctions.cpp +++ b/src/modules/theme/ThemeFunctions.cpp @@ -64,6 +64,7 @@ namespace ThemeFunctions if(!r.readHeader(szThemePackageFileName)) { + qDebug("The selected file does not seem to be a valid KVIrc package"); QString szErr = r.lastError(); szError = QString(__tr2qs_ctx("The selected file does not seem to be a valid KVIrc package: %1","theme")).arg(szErr); return false; @@ -72,8 +73,10 @@ namespace ThemeFunctions pInfoFields = r.stringInfoFields(); pValue = pInfoFields->find("PackageType"); - if(!pValue) + if(!pValue){ + qDebug("no package type"); return notAValidThemePackage(szError); + } if(!KviQString::equalCI(*pValue,"ThemePack")) return notAValidThemePackage(szError); @@ -91,16 +94,22 @@ namespace ThemeFunctions } pValue = pInfoFields->find("ThemeCount"); - if(!pValue) + if(!pValue){ + qDebug("no theme count"); return notAValidThemePackage(szError); + } bool bOk; int iThemeCount = pValue->toInt(&bOk); - if(!bOk) + if(!bOk){ + qDebug("no theme count 2"); return notAValidThemePackage(szError); + } + if(iThemeCount < 1){ - if(iThemeCount < 1) + qDebug("no theme count 2"); return notAValidThemePackage(szError); + } // ok.. it should be really valid at this point diff --git a/src/modules/theme/ThemeManagementDialog.cpp b/src/modules/theme/ThemeManagementDialog.cpp index 182dd64d8..ead7de0e7 100644 --- a/src/modules/theme/ThemeManagementDialog.cpp +++ b/src/modules/theme/ThemeManagementDialog.cpp @@ -21,6 +21,11 @@ // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // //============================================================================= +#include "kvi_settings.h" +#if defined(COMPILE_WEBKIT_SUPPORT) && (QT_VERSION >= 0x040600) +#include "WebThemeInterfaceDialog.h" +#endif + #include "ThemeManagementDialog.h" #include "PackThemeDialog.h" @@ -67,6 +72,9 @@ extern QRect g_rectManagementDialogGeometry; +#define BUILTIN_THEMES 1 + +#define USER_DEFINED_THEMES 0 ThemeListWidgetItem::ThemeListWidgetItem(KviTalListWidget * box,KviThemeInfo * inf) : KviTalListWidgetItem(box) @@ -111,6 +119,9 @@ ThemeManagementDialog::ThemeManagementDialog(QWidget * parent) : QWidget(parent) { m_pItemDelegate=0; + #if defined(COMPILE_WEBKIT_SUPPORT) && (QT_VERSION >= 0x040600) + m_pWebThemeInterfaceDialog = 0; + #endif setObjectName("theme_options_widget"); setWindowTitle(__tr2qs_ctx("Manage Themes - KVIrc","theme")); setWindowIcon(*(g_pIconManager->getSmallIcon(KviIconManager::Theme))); @@ -218,6 +229,13 @@ ThemeManagementDialog::~ThemeManagementDialog() if (m_pItemDelegate) delete m_pItemDelegate; g_rectManagementDialogGeometry = QRect(pos().x(),pos().y(),size().width(),size().height()); m_pInstance = 0; + #if defined(COMPILE_WEBKIT_SUPPORT) && (QT_VERSION >= 0x040600) + if(m_pWebThemeInterfaceDialog) + { + delete m_pWebThemeInterfaceDialog; + m_pWebThemeInterfaceDialog = 0; + } + #endif } void ThemeManagementDialog::closeClicked() @@ -303,11 +321,11 @@ void ThemeManagementDialog::applyCurrentTheme() __tr2qs_ctx("Do you wish to apply theme \"%Q\" (version %Q)?","theme"), &(it->themeInfo()->name()),&(it->themeInfo()->version()))) { - QString szPath = it->themeInfo()->absoluteDirectory(); + QString szPath = it->themeInfo()->dirName(); if(szPath.isEmpty())return; KviThemeInfo out; - if(!KviTheme::load(szPath,out)) + if(!KviTheme::load(szPath,out,it->themeInfo()->isBuiltin())) { QString szErr = out.lastError(); QString szMsg = QString(__tr2qs_ctx("Failed to apply the specified theme: %1","theme")).arg(szErr); @@ -327,7 +345,9 @@ void ThemeManagementDialog::deleteTheme() if(!KviMessageBox::yesNo(__tr2qs_ctx("Delete Theme - KVIrc","theme"), __tr2qs_ctx("Do you really wish to delete theme \"%Q\" (version %Q)?","theme"), &(((ThemeListWidgetItem *)itemsSelected.at(i))->themeInfo()->name()),&(((ThemeListWidgetItem *)itemsSelected.at(i))->themeInfo()->version())))goto jump_out; - KviFileUtils::deleteDir(((ThemeListWidgetItem *)itemsSelected.at(i))->themeInfo()->absoluteDirectory()); + QString szThemePath; + ((ThemeListWidgetItem *)itemsSelected.at(i))->themeInfo()->getCompleteDirPath(szThemePath); + KviFileUtils::deleteDir(szThemePath); } jump_out: fillThemeBox(); @@ -350,10 +370,20 @@ void ThemeManagementDialog::installFromFile() void ThemeManagementDialog::getMoreThemes() { + #if defined(COMPILE_WEBKIT_SUPPORT) && (QT_VERSION >= 0x040600) + if (m_pWebThemeInterfaceDialog) m_pWebThemeInterfaceDialog->show(); + else{ + m_pWebThemeInterfaceDialog = new WebThemeInterfaceDialog(); + m_pWebThemeInterfaceDialog->show(); + } + return; + #else if(!g_pMainWindow)return; g_pMainWindow->executeInternalCommand(KVI_INTERNALCOMMAND_OPENURL_KVIRC_THEMES); + #endif } + void ThemeManagementDialog::saveCurrentTheme() { SaveThemeDialog * pSaveThemeDialog = new SaveThemeDialog(this); @@ -362,25 +392,17 @@ void ThemeManagementDialog::saveCurrentTheme() fillThemeBox(); } -void ThemeManagementDialog::fillThemeBox(const QString &szDir) +void ThemeManagementDialog::fillThemeBox(bool bBuiltin) { - QDir d(szDir); - - QStringList sl = d.entryList(QDir::Dirs); + QStringList slThemes; + KviTheme::installedThemes(slThemes,bBuiltin); - for(QStringList::Iterator it = sl.begin();it != sl.end();++it) + for(int i=0;i<slThemes.count();i++) { - if(*it == ".")continue; - if(*it == "..")continue; - - QString szTest = szDir; - szTest += KVI_PATH_SEPARATOR_CHAR; - szTest += *it; - KviThemeInfo * inf = new KviThemeInfo(); - if(inf->loadFromDirectory(szTest)) + if(inf->load(slThemes.at(i),bBuiltin)) { - inf->setSubdirectory(*it); + inf->setSubdirectory(slThemes.at(i)); new ThemeListWidgetItem(m_pListWidget,inf); } else { delete inf; @@ -392,11 +414,8 @@ void ThemeManagementDialog::fillThemeBox() { m_pListWidget->clear(); - QString szDir; - g_pApp->getGlobalKvircDirectory(szDir,KviApplication::Themes); - fillThemeBox(szDir); - g_pApp->getLocalKvircDirectory(szDir,KviApplication::Themes); - fillThemeBox(szDir); + fillThemeBox(BUILTIN_THEMES); + fillThemeBox(USER_DEFINED_THEMES); enableDisableButtons(); } diff --git a/src/modules/theme/ThemeManagementDialog.h b/src/modules/theme/ThemeManagementDialog.h index 5c6d46de8..d4f7fa61d 100644 --- a/src/modules/theme/ThemeManagementDialog.h +++ b/src/modules/theme/ThemeManagementDialog.h @@ -38,13 +38,15 @@ #include <QListWidget> #include <QItemDelegate> #include <QToolButton> - +#include "kvi_settings.h" +#if defined(COMPILE_WEBKIT_SUPPORT) || defined(Q_MOC_RUN) +#include "WebThemeInterfaceDialog.h" +#endif class QLineEdit; class QPushButton; class QLabel; class KviDynamicToolTip; - class ThemeListWidgetItem : public KviTalListWidgetItem { public: @@ -53,7 +55,7 @@ public: public: KviThemeInfo * m_pThemeInfo; public: - KviThemeInfo * themeInfo(){ return m_pThemeInfo; }; + KviThemeInfo * themeInfo(){ return m_pThemeInfo; } }; @@ -70,15 +72,19 @@ protected: KviTalPopupMenu * m_pContextPopup; QToolButton * m_pDeleteThemeButton; QToolButton * m_pPackThemeButton; +#if defined(COMPILE_WEBKIT_SUPPORT) || defined(Q_MOC_RUN) + WebThemeInterfaceDialog *m_pWebThemeInterfaceDialog; +#endif public: - static ThemeManagementDialog * instance(){ return m_pInstance; }; + static ThemeManagementDialog * instance(){ return m_pInstance; } static void display(bool bTopLevel); static void cleanup(); protected: - void fillThemeBox(const QString &szDir); + void fillThemeBox(bool bBuiltin); bool hasSelectedItems(); virtual void closeEvent(QCloseEvent * e); protected slots: + void saveCurrentTheme(); void getMoreThemes(); void installFromFile(); diff --git a/src/modules/theme/WebThemeInterfaceDialog.cpp b/src/modules/theme/WebThemeInterfaceDialog.cpp new file mode 100644 index 000000000..98b683d67 --- /dev/null +++ b/src/modules/theme/WebThemeInterfaceDialog.cpp @@ -0,0 +1,253 @@ +//============================================================================= +// +// File : WebThemeInterfaceDialog.cpp +// Creation date : Mon Mar 14 2011 15:10:20 by Alessandro Carbone +// +// This file is part of the KVIrc irc client distribution +// Copyright (C) 2011 Alessandro Carbone(elfonol at gmail dot com) +// +// 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" +#define KVI_URL_THEMES "http://www.kvirc.de/app/themes.php" +#if defined(COMPILE_WEBKIT_SUPPORT) && (QT_VERSION >= 0x040600) +#include "WebThemeInterfaceDialog.h" +#include "ThemeFunctions.h" + +#include "KviLocale.h" +#include "KviApplication.h" +#include "KviMessageBox.h" +#include "KviModule.h" +#include "KviFileUtils.h" +#include "KviIconManager.h" + +#include <QDesktopWidget> +#include <QToolButton> +#include <QLineEdit> +#include <QToolTip> +#include <QTimer> +#include <QClipboard> +#include <QHBoxLayout> +#include <QDir> + +WebThemeInterfaceDialog::WebThemeInterfaceDialog(QWidget * par) +: QWidget (par) +{ + m_pLayout = new QVBoxLayout(this); + setWindowTitle(__tr2qs_ctx("KVIrc Web Theme Interface","theme")); + setWindowIcon(*(g_pIconManager->getBigIcon(KVI_BIGICON_WWW))); + m_pFile = 0; + m_bBusy = false; + QWidget *pStatus = new QWidget(this); + m_pLayout->addWidget(pStatus); + QHBoxLayout *hbox= new QHBoxLayout(pStatus); + // m_pLayout = new QVBoxLayout(this); + m_pFtp = 0; + m_pLayout->setMargin(3); + m_pLayout->setSpacing(2); + setLayout(m_pLayout); + m_pToolBar= new QToolBar(pStatus); + m_pProgressBar = new QProgressBar(pStatus); + m_pProgressBar->setMaximumWidth(220); + m_pProgressBar->setMinimumWidth(220); + hbox->addWidget(m_pToolBar); + hbox->addWidget(m_pProgressBar); + hbox->setAlignment(m_pProgressBar,Qt::AlignRight); + + m_pWebView = new QWebView(this); + m_pLayout->addWidget(m_pWebView); + // disable context menu + m_pWebView->setContextMenuPolicy(Qt::NoContextMenu); + m_pToolBar->addAction(m_pWebView->pageAction(QWebPage::Back)); + m_pToolBar->addAction(m_pWebView->pageAction(QWebPage::Forward)); + + //connect(pWebView,SIGNAL(loadStarted()),this,SLOT(slotLoadStarted())); + connect(m_pWebView,SIGNAL(loadFinished(bool)),this,SLOT(slotLoadFinished(bool))); + connect(m_pWebView,SIGNAL(loadProgress(int)),this,SLOT(slotLoadProgress(int))); + connect(m_pWebView->page(),SIGNAL(linkClicked(const QUrl &)),this,SLOT(slotLinkClicked(const QUrl &))); + + // we managing the links + m_pWebView->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks); + m_pWebView->load(QUrl(KVI_URL_THEMES)); + + +} +WebThemeInterfaceDialog::~WebThemeInterfaceDialog() +{ + if (m_pFile) delete m_pFile; + if (m_pFtp) delete m_pFtp; +} + +void WebThemeInterfaceDialog::slotLoadFinished(bool bOk) +{ + if (bOk){ + m_pProgressBar->hide(); + m_pProgressBar->setValue(0); + if(!isVisible()) show(); + // main frame + QWebFrame *pFrame=m_pWebView->page()->mainFrame(); + /*QWebElement style=pFrame->documentElement().findFirst("style"); + QString szCss=style.toPlainText(); + szCss.append("div.item_entry:hover {background-color: rgba(0,0,0,0.9)}"); + style.setPlainText(szCss);*/ + // search for all item_entry div + QWebElementCollection elementscollection=pFrame->documentElement().findAll("div.item_entry"); + + // local dir for user defined themes + QString szLocalThemesPath; + g_pApp->getLocalKvircDirectory(szLocalThemesPath,KviApplication::Themes); + szLocalThemesPath += KVI_PATH_SEPARATOR_CHAR; + + // global dir for builtin themes + QString szGlobalThemesPath; + g_pApp->getGlobalKvircDirectory(szGlobalThemesPath,KviApplication::Themes); + szGlobalThemesPath += KVI_PATH_SEPARATOR_CHAR; + + // if this is null something is wrong + if(elementscollection.count()) + { + foreach(QWebElement element,elementscollection) + { + // web element 'title' + QWebElement eTitle=element.findFirst("span.item_name"); + // string title + QString szTitle=eTitle.toPlainText(); + // number version + QString szVersion=element.findFirst("span.item_version").toPlainText(); + //QString t=szLocalThemesPath+szTitle+"-"+szVersion; + // is the theme installed? + if(KviFileUtils::fileExists(szGlobalThemesPath+szTitle+"-"+szVersion)|| KviFileUtils::fileExists(szLocalThemesPath+szTitle+"-"+szVersion)) + { + // yeah: change the background color for highlight the item + element.findFirst("div.item_id").setStyleProperty("background","none repeat scroll 0 0 #3cd543"); + // then change the 'install' text into 'uninstall' + QWebElement eDownload=element.findFirst("a.item_download_link"); + eDownload.setPlainText("Uninstall"); + // why use a c++ var when we can use the web page for store it? :-D + eDownload.setAttribute("Installed",QString("1")); + } + } + } + } + else qDebug("Error loading page");// fixme: add warning dialog +} +void WebThemeInterfaceDialog::slotLinkClicked(const QUrl &url) +{ + // check if one download is running + if(m_bBusy) return; + QString szScheme=url.scheme(); + // it's an ftp link? + if (KviQString::equalCI(szScheme,"ftp")) + { + // let's search for the 'a' tag + QWebElementCollection elementscollection=m_pWebView->page()->mainFrame()->findAllElements("a.item_download_link"); + if(elementscollection.count()) + { + + foreach(QWebElement element,elementscollection) + { + // check the href to find the item + if (KviQString::equalCI(element.attribute("href"),url.toString())) + { + // check the hidden attribute for installed item + if (element.attribute("Installed").isEmpty()) + { + // one download at once + m_bBusy = true; + if(!m_pFtp) + { + m_pFtp = new QFtp(); + connect(m_pFtp,SIGNAL(commandFinished(int,bool)),this,SLOT(slotCommandFinished(int,bool))); + connect(m_pFtp,SIGNAL(dataTransferProgress(qint64,qint64)),this,SLOT(slotDataTransferProgress(qint64,qint64))); + } + m_pProgressBar->show(); + QString szUrl = url.toString(); + int iIdx=szUrl.lastIndexOf("/"); + QString szFile = szUrl.right(szUrl.length()-iIdx-1); + m_pFile = new QFile(m_pFtp); + g_pApp->getLocalKvircDirectory(m_szLocalTmpThemeCompletePath,KviApplication::Tmp,szFile); + m_pFile->setFileName(m_szLocalTmpThemeCompletePath); + m_pFile->open(QIODevice::ReadWrite); + m_pFtp->connectToHost(url.host()); + m_pFtp->login("anonymous","anonymous"); + m_pFtp->get(url.path(),m_pFile); + } + else qDebug("uninstall theme");//to be continued + } + } + } + } + else { + m_pProgressBar->show(); + m_pWebView->load(url); + } +} + +void WebThemeInterfaceDialog::slotDataTransferProgress(qint64 iDone,qint64 iTotal) +{ + m_pProgressBar->setMaximum(iTotal); + m_pProgressBar->setValue(iDone); + m_pProgressBar->setFormat(__tr2qs_ctx("Downloading ","theme")+"%p"); +} + +void WebThemeInterfaceDialog::slotLoadProgress(int iProgress) +{ + m_pProgressBar->setMaximum(100); + m_pProgressBar->setValue(iProgress); + m_pProgressBar->setFormat(__tr2qs_ctx("Loading ","theme")+"%p"); +} + +void WebThemeInterfaceDialog::slotCommandFinished(int id,bool error) +{ + if(m_pFtp->currentCommand()==QFtp::Get) + { + m_pProgressBar->hide(); + m_pProgressBar->setValue(0); + if(!error) + { + QString szError; + m_pFile->close(); + if(!ThemeFunctions::installThemePackage(m_szLocalTmpThemeCompletePath,szError,this)) + { + KviMessageBox::information(szError); + } + else{ + m_pWebView->load(QUrl(KVI_URL_THEMES)); + } + QFileInfo info(m_szLocalTmpThemeCompletePath); + + delete m_pFile; + m_pFile = 0; + if (info.exists()) KviFileUtils::removeFile(m_szLocalTmpThemeCompletePath); + m_bBusy = false; + m_pFtp->close(); + } + } + id=0; //to be continued +} +void WebThemeInterfaceDialog::showEvent(QShowEvent *) +{ + m_pProgressBar->hide(); + QRect rect = g_pApp->desktop()->screenGeometry(g_pApp->desktop()->primaryScreen()); + move((rect.width() - width())/2,(rect.height() - height())/2); + +} + +#endif +#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES +#include "WebThemeInterfaceDialog.moc" +#endif //!COMPILE_USE_STANDALONE_MOC_SOURCES diff --git a/src/modules/theme/WebThemeInterfaceDialog.h b/src/modules/theme/WebThemeInterfaceDialog.h new file mode 100644 index 000000000..ed65cae97 --- /dev/null +++ b/src/modules/theme/WebThemeInterfaceDialog.h @@ -0,0 +1,73 @@ +#ifndef _WEBTHEMEINTERFACEDIALOG_H_ +#define _WEBTHEMEINTERFACEDIALOG_H_ +//============================================================================= +// +// File : WebThemeInterfaceDialog.h +// Creation date : Mon Mar 14 2011 15:10:20 by Alessandro Carbone +// +// This file is part of the KVIrc irc client distribution +// Copyright (C) 2011 Alessandro Carbone(elfonol at gmail dot com) +// +// 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" +#if defined(COMPILE_WEBKIT_SUPPORT) +#include <QDialog> +#include <QtWebKit/QWebView> +#include <QtWebKit/QWebFrame> +#include <QWebElement> +#include <QToolBar> +#include <QFtp> +#include <QUrl> +#include <QFile> +#include <QVBoxLayout> +#include <QProgressBar> +#include <QShowEvent> + + +class WebThemeInterfaceDialog : public QWidget +{ + Q_OBJECT +public: + WebThemeInterfaceDialog(QWidget *par=0); + ~WebThemeInterfaceDialog(); +private: + QToolBar * m_pToolBar; + QString m_szLocalTmpThemeCompletePath; + QVBoxLayout *m_pLayout; + QWebView * m_pWebView; + QFile *m_pFile; + QFtp *m_pFtp; + bool m_bBusy; + QProgressBar *m_pProgressBar; +protected: + virtual void showEvent(QShowEvent *e); +protected slots: + + void slotLoadFinished(bool ok); + void slotLoadProgress(int iProgress); + void slotDataTransferProgress(qint64 iDone,qint64 iTotal); + void slotCommandFinished(int id,bool error); + void slotLinkClicked(const QUrl &url); +}; + +#endif + + +#endif //_WEBTHEMEINTERFACEDIALOG_H_ + diff --git a/src/modules/theme/libkvitheme.cpp b/src/modules/theme/libkvitheme.cpp index 86425b9a7..3422291cc 100644 --- a/src/modules/theme/libkvitheme.cpp +++ b/src/modules/theme/libkvitheme.cpp @@ -101,14 +101,15 @@ static bool theme_kvs_cmd_apply(KviKvsModuleCommandCall * c) szDir += KVI_PATH_SEPARATOR_CHAR; szDir += szThemePackFile; KviThemeInfo * themeInfo = new KviThemeInfo(); - if(themeInfo->loadFromDirectory(szDir)) + if(themeInfo->load(szDir)) { themeInfo->setSubdirectory(szThemePackFile); if(KviMessageBox::yesNo(__tr2qs_ctx("Apply theme - KVIrc","theme"), __tr2qs_ctx("Do you wish to apply theme \"%Q\" (version %Q)?","theme"), &(themeInfo->name()),&(themeInfo->version()))) { - QString szPath = themeInfo->absoluteDirectory(); + QString szPath; + themeInfo->getCompleteDirPath(szPath); if(szPath.isEmpty())return true; KviThemeInfo out; @@ -151,7 +152,7 @@ static bool theme_kvs_fnc_info(KviKvsModuleFunctionCall * c) szDir += KVI_PATH_SEPARATOR_CHAR; szDir += szThemePackFile; KviThemeInfo * themeInfo = new KviThemeInfo(); - if(themeInfo->loadFromDirectory(szDir)) + if(themeInfo->load(szDir)) { KviKvsHash *pHash=new KviKvsHash(); KviKvsVariant *name=new KviKvsVariant(themeInfo->name()); |
