diff options
| author | 2011-03-17 14:55:29 +0000 | |
|---|---|---|
| committer | 2011-03-17 14:55:29 +0000 | |
| commit | 51d1524d760f0b9946d2e41b66250faa96a23da4 (patch) | |
| tree | c5eac07090d9cc431cd1da1e542c6d3a4e327c9c /src | |
| parent | Change spaces to tabs, reindent, simplify (diff) | |
| download | KVIrc-51d1524d760f0b9946d2e41b66250faa96a23da4.tar.gz KVIrc-51d1524d760f0b9946d2e41b66250faa96a23da4.tar.bz2 KVIrc-51d1524d760f0b9946d2e41b66250faa96a23da4.zip | |
Start generalizing the web package management interface
git-svn-id: https://svn.kvirc.de/svn/trunk/kvirc@5618 17fca916-40b9-46aa-a4ea-0a15b648b75c
Diffstat (limited to 'src')
| -rw-r--r-- | src/kvirc/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/kvirc/ui/KviWebPackageManagementDialog.cpp | 277 | ||||
| -rw-r--r-- | src/kvirc/ui/KviWebPackageManagementDialog.h | 98 | ||||
| -rw-r--r-- | src/modules/theme/ThemeManagementDialog.cpp | 24 | ||||
| -rw-r--r-- | src/modules/theme/WebThemeInterfaceDialog.cpp | 226 | ||||
| -rw-r--r-- | src/modules/theme/WebThemeInterfaceDialog.h | 41 |
6 files changed, 422 insertions, 246 deletions
diff --git a/src/kvirc/CMakeLists.txt b/src/kvirc/CMakeLists.txt index f60ad39d0..e30ae9e3f 100644 --- a/src/kvirc/CMakeLists.txt +++ b/src/kvirc/CMakeLists.txt @@ -64,6 +64,7 @@ SET(kvirc_MOC_HDRS ui/KviWindowToolWidget.h ui/KviTopicWidget.h ui/KviUserListView.h + ui/KviWebPackageManagementDialog.h ui/KviWindow.h ui/KviWindowListBase.h ui/KviTreeWindowList.h @@ -149,6 +150,7 @@ SET(kvirc_SRCS ui/KviThemedLineEdit.cpp ui/KviThemedTreeWidget.cpp ui/KviToolBar.cpp + ui/KviWebPackageManagementDialog.cpp ui/KviWindowToolWidget.cpp ui/KviTopicWidget.cpp ui/KviUserListView.cpp diff --git a/src/kvirc/ui/KviWebPackageManagementDialog.cpp b/src/kvirc/ui/KviWebPackageManagementDialog.cpp new file mode 100644 index 000000000..673a3a7a1 --- /dev/null +++ b/src/kvirc/ui/KviWebPackageManagementDialog.cpp @@ -0,0 +1,277 @@ +//============================================================================= +// +// File : KviWebPackageManagementDialog.cpp +// Creation date : Thu 17 Mar 2011 15:21:06 +// +// This file is part of the KVIrc IRC Client distribution +// Copyright (C) 2011 Alessandro Carbone <elfonol at gmail dot com> +// Copyright (C) 2011 Szymon Stefanek <pragma at kvirc dot net> +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// + +//============================================================================= + +#include "KviWebPackageManagementDialog.h" + +#ifdef COMPILE_WEBKIT_SUPPORT + +#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 <QWebView> +#include <QVBoxLayout> +#include <QToolBar> +#include <QFile> +#include <QFtp> +#include <QProgressBar> +#include <QDir> +#include <QtWebKit/QWebView> +#include <QtWebKit/QWebFrame> +#include <QWebElement> +#include <QUrl> +#include <QShowEvent> + +KviWebPackageManagementDialog::KviWebPackageManagementDialog( + const QString &szPackagePageUrl, + QWidget * pParent + ) + : QWidget(pParent), + m_szPackagePageUrl(szPackagePageUrl) +{ + setWindowIcon(QIcon(*(g_pIconManager->getBigIcon(KVI_BIGICON_WWW)))); + + m_pLayout = new QVBoxLayout(this); + + 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(m_szPackagePageUrl)); + +} + +KviWebPackageManagementDialog::~KviWebPackageManagementDialog() +{ + if(m_pFile) + delete m_pFile; + if(m_pFtp) + delete m_pFtp; +} + + + +void KviWebPackageManagementDialog::slotLoadFinished(bool bOk) +{ + if(!bOk) + { + qDebug("Error loading page");// fixme: add warning dialog return; + return; + } + + 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"); + + + // 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(packageIsInstalled(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")); + } + } + } +} +void KviWebPackageManagementDialog::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")) + { + m_pProgressBar->show(); + m_pWebView->load(url); + return; + } + + // let's search for the 'a' tag + QWebElementCollection elementscollection=m_pWebView->page()->mainFrame()->findAllElements("a.item_download_link"); + if(elementscollection.count() == 0) + return; + + foreach(QWebElement element,elementscollection) + { + // check the href to find the item + if(!KviQString::equalCI(element.attribute("href"),url.toString())) + continue; + + // 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_szLocalTemporaryPath,KviApplication::Tmp,szFile); + m_pFile->setFileName(m_szLocalTemporaryPath); + 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 + } + } +} + +void KviWebPackageManagementDialog::slotDataTransferProgress(qint64 iDone,qint64 iTotal) +{ + m_pProgressBar->setMaximum(iTotal); + m_pProgressBar->setValue(iDone); + m_pProgressBar->setFormat(__tr2qs_ctx("Downloading ","theme")+"%p"); +} + +void KviWebPackageManagementDialog::slotLoadProgress(int iProgress) +{ + m_pProgressBar->setMaximum(100); + m_pProgressBar->setValue(iProgress); + m_pProgressBar->setFormat(__tr2qs_ctx("Loading ","theme")+"%p"); +} + +void KviWebPackageManagementDialog::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(!installPackage(m_szLocalTemporaryPath,szError)) + { + KviMessageBox::information(szError); + } else { + m_pWebView->load(QUrl(m_szPackagePageUrl)); + } + QFileInfo info(m_szLocalTemporaryPath); + + delete m_pFile; + m_pFile = 0; + if (info.exists()) + KviFileUtils::removeFile(m_szLocalTemporaryPath); + m_bBusy = false; + m_pFtp->close(); + } + } + id=0; //to be continued +} + +void KviWebPackageManagementDialog::showEvent(QShowEvent *) +{ + m_pProgressBar->hide(); + QRect rect = g_pApp->desktop()->screenGeometry(g_pApp->desktop()->primaryScreen()); + move((rect.width() - width())/2,(rect.height() - height())/2); +} + + +#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES + #include "KviWebPackageManagementDialog.moc" +#endif //!COMPILE_USE_STANDALONE_MOC_SOURCES + +#endif //COMPILE_WEBKIT_SUPPORT + diff --git a/src/kvirc/ui/KviWebPackageManagementDialog.h b/src/kvirc/ui/KviWebPackageManagementDialog.h new file mode 100644 index 000000000..ee1303075 --- /dev/null +++ b/src/kvirc/ui/KviWebPackageManagementDialog.h @@ -0,0 +1,98 @@ +#ifndef _KviWebPackageManagementDialog_h_ +#define _KviWebPackageManagementDialog_h_ +//============================================================================= +// +// File : KviWebPackageManagementDialog.h +// Creation date : Thu 17 Mar 2011 15:21:06 +// +// This file is part of the KVIrc IRC Client distribution +// Copyright (C) 2011 Alessandro Carbone <elfonol at gmail dot com> +// Copyright (C) 2011 Szymon Stefanek <pragma at kvirc dot net> +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +//============================================================================= + + +#include "kvi_settings.h" + +#ifdef COMPILE_WEBKIT_SUPPORT + +#include <QWidget> + +class QToolBar; +class QVBoxLayout; +class QWebView; +class QFile; +class QFtp; +class QProgressBar; +class QUrl; + +/// +/// \class KviWebPackageManagementDialog +/// \brief The KviWebPackageManagementDialog class +/// +/// This class... +/// +class KVIRC_API KviWebPackageManagementDialog : public QWidget +{ + Q_OBJECT + +public: + + /// + /// Creates an instance of KviWebPackageManagementDialog + /// + KviWebPackageManagementDialog( + const QString &szPackagePageUrl, + QWidget * pParent = NULL + ); + + /// + /// Destroys the instance of KviWebPackageManagementDialog + /// and frees all the relevant resources + /// + virtual ~KviWebPackageManagementDialog(); + +private: + + QToolBar * m_pToolBar; + QVBoxLayout *m_pLayout; + QWebView * m_pWebView; + QFile *m_pFile; + QFtp *m_pFtp; + bool m_bBusy; + QProgressBar *m_pProgressBar; + QString m_szPackagePageUrl; + QString m_szLocalTemporaryPath; +protected: + virtual void showEvent(QShowEvent *e); + + virtual bool packageIsInstalled(const QString &szName,const QString &szVersion) = 0; + virtual bool installPackage(const QString &szPath,QString &szError) = 0; + +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); + +}; // class KviWebPackageManagementDialog + +#endif //COMPILE_WEBKIT_SUPPORT + +#endif //!_KviWebPackageManagementDialog_h_ diff --git a/src/modules/theme/ThemeManagementDialog.cpp b/src/modules/theme/ThemeManagementDialog.cpp index 045609a84..e79cfc02a 100644 --- a/src/modules/theme/ThemeManagementDialog.cpp +++ b/src/modules/theme/ThemeManagementDialog.cpp @@ -230,13 +230,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) +#ifdef COMPILE_WEBKIT_SUPPORT if(m_pWebThemeInterfaceDialog) { delete m_pWebThemeInterfaceDialog; m_pWebThemeInterfaceDialog = 0; } - #endif +#endif //COMPILE_WEBKIT_SUPPORT } void ThemeManagementDialog::closeClicked() @@ -371,17 +371,19 @@ 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(); +#ifdef COMPILE_WEBKIT_SUPPORT + if(m_pWebThemeInterfaceDialog) + { + m_pWebThemeInterfaceDialog->show(); + } else { + m_pWebThemeInterfaceDialog = new WebThemeInterfaceDialog(); + m_pWebThemeInterfaceDialog->show(); } - return; - #else - if(!g_pMainWindow)return; +#else + if(!g_pMainWindow) + return; g_pMainWindow->executeInternalCommand(KVI_INTERNALCOMMAND_OPENURL_KVIRC_THEMES); - #endif +#endif } diff --git a/src/modules/theme/WebThemeInterfaceDialog.cpp b/src/modules/theme/WebThemeInterfaceDialog.cpp index 0dab74e0a..8be3a2dbf 100644 --- a/src/modules/theme/WebThemeInterfaceDialog.cpp +++ b/src/modules/theme/WebThemeInterfaceDialog.cpp @@ -24,241 +24,55 @@ #include "kvi_settings.h" -#define KVI_URL_THEMES "http://www.kvirc.de/app/themes.php" - -#if defined(COMPILE_WEBKIT_SUPPORT) && (QT_VERSION >= 0x040600) +#ifdef COMPILE_WEBKIT_SUPPORT #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 "KviLocale.h" -#include <QDesktopWidget> -#include <QToolButton> -#include <QLineEdit> -#include <QToolTip> -#include <QTimer> -#include <QClipboard> -#include <QHBoxLayout> -#include <QDir> WebThemeInterfaceDialog::WebThemeInterfaceDialog(QWidget * par) -: QWidget (par) +: KviWebPackageManagementDialog( + QString::fromAscii("http://www.kvirc.de/app/themes.php"), + 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) - { - qDebug("Error loading page");// fixme: add warning dialog return; - return; - } - - 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; + g_pApp->getLocalKvircDirectory(m_szLocalThemesPath,KviApplication::Themes); + m_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")); - } - } - } -} -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")) - { - m_pProgressBar->show(); - m_pWebView->load(url); - return; - } - - // let's search for the 'a' tag - QWebElementCollection elementscollection=m_pWebView->page()->mainFrame()->findAllElements("a.item_download_link"); - if(elementscollection.count() == 0) - return; - - foreach(QWebElement element,elementscollection) - { - // check the href to find the item - if(!KviQString::equalCI(element.attribute("href"),url.toString())) - continue; + g_pApp->getGlobalKvircDirectory(m_szGlobalThemesPath,KviApplication::Themes); + m_szGlobalThemesPath += KVI_PATH_SEPARATOR_CHAR; - // 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 - } - } } - -void WebThemeInterfaceDialog::slotDataTransferProgress(qint64 iDone,qint64 iTotal) +WebThemeInterfaceDialog::~WebThemeInterfaceDialog() { - m_pProgressBar->setMaximum(iTotal); - m_pProgressBar->setValue(iDone); - m_pProgressBar->setFormat(__tr2qs_ctx("Downloading ","theme")+"%p"); } -void WebThemeInterfaceDialog::slotLoadProgress(int iProgress) +bool WebThemeInterfaceDialog::installPackage(const QString &szPath,QString &szError) { - m_pProgressBar->setMaximum(100); - m_pProgressBar->setValue(iProgress); - m_pProgressBar->setFormat(__tr2qs_ctx("Loading ","theme")+"%p"); + return ThemeFunctions::installThemePackage(szPath,szError,this); } -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 *) +bool WebThemeInterfaceDialog::packageIsInstalled(const QString &szName,const QString &szVersion) { - m_pProgressBar->hide(); - QRect rect = g_pApp->desktop()->screenGeometry(g_pApp->desktop()->primaryScreen()); - move((rect.width() - width())/2,(rect.height() - height())/2); + return \ + KviFileUtils::fileExists(m_szGlobalThemesPath+szName+"-"+szVersion) || \ + KviFileUtils::fileExists(m_szLocalThemesPath+szName+"-"+szVersion); } -#endif - #ifndef COMPILE_USE_STANDALONE_MOC_SOURCES -#include "WebThemeInterfaceDialog.moc" + #include "WebThemeInterfaceDialog.moc" #endif //!COMPILE_USE_STANDALONE_MOC_SOURCES +#endif //COMPILE_WEBKIT_SUPPORT + diff --git a/src/modules/theme/WebThemeInterfaceDialog.h b/src/modules/theme/WebThemeInterfaceDialog.h index ed65cae97..d3d930e40 100644 --- a/src/modules/theme/WebThemeInterfaceDialog.h +++ b/src/modules/theme/WebThemeInterfaceDialog.h @@ -26,47 +26,30 @@ #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> +#ifdef COMPILE_WEBKIT_SUPPORT -class WebThemeInterfaceDialog : public QWidget +#include "KviWebPackageManagementDialog.h" + + +class WebThemeInterfaceDialog : public KviWebPackageManagementDialog { 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; + QString m_szLocalThemesPath; + QString m_szGlobalThemesPath; + protected: - virtual void showEvent(QShowEvent *e); -protected slots: + virtual bool packageIsInstalled(const QString &szName,const QString &szVersion); + virtual bool installPackage(const QString &szPath,QString &szError); - 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 //COMPILE_WEBKIT_SUPPORT #endif //_WEBTHEMEINTERFACEDIALOG_H_ |
