From 8988bde2c41f314acbe7c8409ce8e9c1465fdee8 Mon Sep 17 00:00:00 2001 From: Szymon Tomasz Stefanek Date: Sat, 5 Mar 2011 03:27:15 +0000 Subject: More file renaming git-svn-id: https://svn.kvirc.de/svn/trunk/kvirc@5537 17fca916-40b9-46aa-a4ea-0a15b648b75c --- src/modules/addon/AddonManagementDialog.cpp | 373 +++++++++ src/modules/addon/AddonManagementDialog.h | 90 +++ src/modules/addon/CMakeLists.txt | 4 +- src/modules/addon/libkviaddon.cpp | 2 +- src/modules/addon/managementdialog.cpp | 373 --------- src/modules/addon/managementdialog.h | 90 --- src/modules/reguser/CMakeLists.txt | 4 +- src/modules/reguser/RegisteredUserEntryDialog.cpp | 2 +- src/modules/reguser/RegisteredUsersDialog.cpp | 933 ++++++++++++++++++++++ src/modules/reguser/RegisteredUsersDialog.h | 159 ++++ src/modules/reguser/dialog.cpp | 933 ---------------------- src/modules/reguser/dialog.h | 159 ---- src/modules/reguser/libkvireguser.cpp | 2 +- src/modules/theme/CMakeLists.txt | 4 +- src/modules/theme/ThemeManagementDialog.cpp | 457 +++++++++++ src/modules/theme/ThemeManagementDialog.h | 97 +++ src/modules/theme/libkvitheme.cpp | 2 +- src/modules/theme/managementdialog.cpp | 457 ----------- src/modules/theme/managementdialog.h | 97 --- 19 files changed, 2119 insertions(+), 2119 deletions(-) create mode 100644 src/modules/addon/AddonManagementDialog.cpp create mode 100644 src/modules/addon/AddonManagementDialog.h delete mode 100644 src/modules/addon/managementdialog.cpp delete mode 100644 src/modules/addon/managementdialog.h create mode 100644 src/modules/reguser/RegisteredUsersDialog.cpp create mode 100644 src/modules/reguser/RegisteredUsersDialog.h delete mode 100644 src/modules/reguser/dialog.cpp delete mode 100644 src/modules/reguser/dialog.h create mode 100644 src/modules/theme/ThemeManagementDialog.cpp create mode 100644 src/modules/theme/ThemeManagementDialog.h delete mode 100644 src/modules/theme/managementdialog.cpp delete mode 100644 src/modules/theme/managementdialog.h (limited to 'src') diff --git a/src/modules/addon/AddonManagementDialog.cpp b/src/modules/addon/AddonManagementDialog.cpp new file mode 100644 index 000000000..efa91d2b4 --- /dev/null +++ b/src/modules/addon/AddonManagementDialog.cpp @@ -0,0 +1,373 @@ +//============================================================================= +// +// File : AddonManagementDialog.cpp +// Creation date : Fri 08 Apr 2005 14:54:56 by Szymon Stefanek +// +// This file is part of the KVIrc IRC Client distribution +// Copyright (C) 2005-2010 Szymon Stefanek +// +// 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 "AddonManagementDialog.h" +#include "PackAddonDialog.h" +#include "AddonFunctions.h" + +#include "KviApplication.h" +#include "KviLocale.h" +#include "KviMainWindow.h" +#include "KviIconManager.h" +#include "KviKvsScriptAddonManager.h" +#include "KviWindow.h" +#include "KviFileDialog.h" +#include "KviFileUtils.h" +#include "kvi_fileextensions.h" +#include "KviKvsScript.h" +#include "kvi_sourcesdate.h" +#include "KviTalListWidget.h" +#include "KviTalToolTip.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +AddonManagementDialog * AddonManagementDialog::m_pInstance = 0; +extern QRect g_rectManagementDialogGeometry; + +AddonListViewItem::AddonListViewItem(KviTalListWidget *v,KviKvsScriptAddon * a) +: KviTalListWidgetItem(v) +{ + m_pAddon = new KviKvsScriptAddon(*a); + m_pListWidget = v; + QString t = ""; + t += a->visibleName(); + t += " ["; + t += a->version(); + t += "]"; + t += " ["; + t += a->name(); + t += "]"; + t += "
"; + t += a->description(); + t += ""; + + setText(t); + QPixmap * p = a->icon(); + if (p) setIcon(*p); +} + +AddonListViewItem::~AddonListViewItem() +{ + delete m_pAddon; +} + +AddonManagementDialog::AddonManagementDialog(QWidget * p) +: QWidget(p) +{ + setWindowTitle(__tr2qs_ctx("Manage Script-Based Addons","addon")); + setObjectName("Addon manager"); + setWindowIcon(*(g_pIconManager->getSmallIcon(KviIconManager::Addons))); + + m_pInstance = this; + QGridLayout * g = new QGridLayout(this); + + KviTalHBox *hb = new KviTalHBox(this); + hb->setMargin(1); + hb->setSpacing(1); + g->addWidget(hb,0,0); + + QToolButton * tb; + QFrame * sep; + + m_pConfigureButton = new QToolButton(hb); + m_pConfigureButton->setIcon(*(g_pIconManager->getBigIcon(KVI_BIGICON_ADDONS))); + m_pConfigureButton->setIconSize(QSize(32,32)); + KviTalToolTip::add(m_pConfigureButton,__tr2qs_ctx("Configure Addon...","addon")); + connect(m_pConfigureButton,SIGNAL(clicked()),this,SLOT(configureScript())); + + m_pHelpButton = new QToolButton(hb); + m_pHelpButton->setIcon(*(g_pIconManager->getBigIcon(KVI_BIGICON_HELP))); + m_pHelpButton->setIconSize(QSize(32,32)); + KviTalToolTip::add(m_pHelpButton,__tr2qs_ctx("Show Help","addon")); + connect(m_pHelpButton,SIGNAL(clicked()),this,SLOT(showScriptHelp())); + + m_pUninstallButton = new QToolButton(hb); + m_pUninstallButton->setIcon(*(g_pIconManager->getBigIcon(KVI_BIGICON_REMOVE))); + m_pUninstallButton->setIconSize(QSize(32,32)); + KviTalToolTip::add(m_pUninstallButton,__tr2qs_ctx("Delete Selected Addons","addon")); + connect(m_pUninstallButton,SIGNAL(clicked()),this,SLOT(uninstallScript())); + + sep = new QFrame(hb); + sep->setFrameStyle(QFrame::VLine | QFrame::Sunken); + sep->setMinimumWidth(12); + + m_pPackButton = new QToolButton(hb); + m_pPackButton->setIcon(*(g_pIconManager->getBigIcon(KVI_BIGICON_PACK))); + m_pPackButton->setIconSize(QSize(32,32)); + KviTalToolTip::add(m_pPackButton,__tr2qs_ctx("Create an Addon as a Distributable Package","addon")); + connect(m_pPackButton,SIGNAL(clicked()),this,SLOT(packScript())); + + sep = new QFrame(hb); + sep->setFrameStyle(QFrame::VLine | QFrame::Sunken); + sep->setMinimumWidth(12); + + tb = new QToolButton(hb); + tb->setIcon(*(g_pIconManager->getBigIcon(KVI_BIGICON_OPEN))); + tb->setIconSize(QSize(32,32)); + KviTalToolTip::add(tb,__tr2qs_ctx("Install Addon Package From Disk","addon")); + connect(tb,SIGNAL(clicked()),this,SLOT(installScript())); + + tb = new QToolButton(hb); + tb->setIcon(*(g_pIconManager->getBigIcon(KVI_BIGICON_WWW))); + tb->setIconSize(QSize(32,32)); + KviTalToolTip::add(tb,__tr2qs_ctx("Get More Addons...","addon")); + connect(tb,SIGNAL(clicked()),this,SLOT(getMoreScripts())); + + QWidget *w= new QWidget(hb); + w->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Minimum); + + m_pListWidget = new KviTalListWidget(this); + KviTalIconAndRichTextItemDelegate *itemDelegate=new KviTalIconAndRichTextItemDelegate(m_pListWidget); + + m_pListWidget->setItemDelegate(itemDelegate); + m_pListWidget->setSelectionMode(QAbstractItemView::SingleSelection); + m_pListWidget->setSortingEnabled(true); + m_pListWidget->setMinimumHeight(400); + m_pListWidget->setMinimumWidth(380); + g->addWidget(m_pListWidget,1,0); + + fillListView(); + + currentChanged(0,0); + connect(m_pListWidget,SIGNAL(currentItemChanged(QListWidgetItem *,QListWidgetItem *)),this,SLOT(currentChanged(QListWidgetItem *,QListWidgetItem *))); + m_pListWidget->setCurrentItem(m_pListWidget->item(0)); + + QPushButton * pCloseBtn = new QPushButton(__tr2qs_ctx("Close","addon"),this); + pCloseBtn->setMaximumSize(pCloseBtn->sizeHint().width(),pCloseBtn->sizeHint().height()); + connect(pCloseBtn,SIGNAL(clicked()),this,SLOT(closeClicked())); + g->addWidget(pCloseBtn,2,0); + + g->setMargin(5); + g->setSpacing(5); + g->setAlignment(pCloseBtn,Qt::AlignRight); + + if(g_rectManagementDialogGeometry.y() < 5) + { + g_rectManagementDialogGeometry.setY(5); + } + resize(g_rectManagementDialogGeometry.width(), + g_rectManagementDialogGeometry.height()); + + QRect rect = g_pApp->desktop()->screenGeometry(g_pMainWindow); + move(rect.x() + ((rect.width() - g_rectManagementDialogGeometry.width())/2),rect.y() + ((rect.height() - g_rectManagementDialogGeometry.height())/2)); +} + +AddonManagementDialog::~AddonManagementDialog() +{ + g_rectManagementDialogGeometry = QRect(pos().x(),pos().y(),size().width(),size().height()); + m_pInstance = 0; +} + +void AddonManagementDialog::fillListView() +{ + m_pListWidget->clear(); + KviPointerHashTable * d = KviKvsScriptAddonManager::instance()->addonDict(); + if(!d)return; + KviPointerHashTableIterator it(*d); + + while(KviKvsScriptAddon * a = it.current()) + { + new AddonListViewItem(m_pListWidget,a); + ++it; + } +} + +void AddonManagementDialog::currentChanged(QListWidgetItem *item,QListWidgetItem *) +{ + AddonListViewItem * it = (AddonListViewItem *)item; + if(!it) + { + m_pConfigureButton->setEnabled(false); + m_pUninstallButton->setEnabled(false); + m_pHelpButton->setEnabled(false); + } else { + m_pConfigureButton->setEnabled(!(it->addon()->configureCallbackCode().isEmpty())); + m_pHelpButton->setEnabled(!(it->addon()->helpCallbackCode().isEmpty())); + m_pUninstallButton->setEnabled(true); + } +} + +void AddonManagementDialog::showScriptHelp() +{ + AddonListViewItem * it = (AddonListViewItem *)m_pListWidget->currentItem(); + if(!it)return; + if(it->addon()->helpCallbackCode().isEmpty())return; + it->addon()->executeHelpCallback(g_pActiveWindow); +} + +void AddonManagementDialog::configureScript() +{ + AddonListViewItem * it = (AddonListViewItem *)m_pListWidget->currentItem(); + if(!it)return; + if(it->addon()->configureCallbackCode().isEmpty())return; + it->addon()->executeConfigureCallback(g_pActiveWindow); +} + +void AddonManagementDialog::packScript() +{ + PackAddonDialog * pDialog = new PackAddonDialog(this); + pDialog->exec(); + delete pDialog; +} + +void AddonManagementDialog::uninstallScript() +{ + AddonListViewItem * it = (AddonListViewItem *)m_pListWidget->currentItem(); + if(!it)return; + + QString txt = "

"; + txt += __tr2qs_ctx("Do you really want to uninstall the addon \"%1\" ?","addon").arg(it->addon()->visibleName()); + txt += "

"; + + if(QMessageBox::question( + this, + __tr2qs_ctx("Confirm addon uninstallation","addon"), + txt, __tr2qs_ctx("Yes","addon"), __tr2qs_ctx("No","addon"),0,1 + ) != 0) return; + + KviKvsScriptAddonManager::instance()->unregisterAddon(it->addon()->name(),g_pActiveWindow); + + fillListView(); + currentChanged(0,0); +} + +void AddonManagementDialog::getMoreScripts() +{ + // If change this introducing not-fixed text, remember to escape this using KviQString::escapeKvs()! + KviKvsScript::run("openurl http://www.kvirc.net/?id=addons&version=" KVI_VERSION "." KVI_SOURCES_DATE,g_pActiveWindow); +} + +void AddonManagementDialog::installScript() +{ + QString szFileName, szError; + + if(!KviFileDialog::askForOpenFileName( + szFileName, + __tr2qs_ctx("Please select the addon installation file","addon"), + QString(),KVI_FILTER_ADDON,false,true + )) return; + + szFileName.replace("\\","\\\\"); + + // Sanity check + if(szFileName.endsWith(".kva")) + { + if(!AddonFunctions::installAddonPackage(szFileName,szError,this)) + { + QMessageBox::critical( + this, + __tr2qs_ctx("Install Addon - KVIrc","addon"), + szError, + QMessageBox::Ok, + QMessageBox::NoButton, + QMessageBox::NoButton + ); + return; + } + } else { + // Just for sanity check. We should NEVER enter here + qDebug("Entered sanity check"); + AddonFunctions::notAValidAddonPackage(szError); + QMessageBox::critical( + this, + __tr2qs_ctx("Install Addon - KVIrc","addon"), + szError, + QMessageBox::Ok, + QMessageBox::NoButton, + QMessageBox::NoButton + ); + } + + fillListView(); + currentChanged(0,0); + + //m_pListWidget->publicUpdateContents(); + //m_pListWidget->triggerUpdate(); +} + +void AddonManagementDialog::closeClicked() +{ + delete this; +} + +void AddonManagementDialog::cleanup() +{ + if(!m_pInstance)return; + delete m_pInstance; + m_pInstance = 0; +} + +void AddonManagementDialog::display(bool bTopLevel) +{ + if(m_pInstance) + { + if(bTopLevel) + { + if(m_pInstance->parent()) + { + m_pInstance->setParent(0); + } + } else { + if(m_pInstance->parent() != g_pMainWindow->splitter()) + { + m_pInstance->setParent(g_pMainWindow->splitter()); + } + } + } else { + if(bTopLevel) + { + m_pInstance = new AddonManagementDialog(0); + } else { + m_pInstance = new AddonManagementDialog(g_pMainWindow->splitter()); + } + } + m_pInstance->show(); + m_pInstance->raise(); + m_pInstance->setFocus(); +} + +void AddonManagementDialog::closeEvent(QCloseEvent * e) +{ + e->ignore(); + delete this; +} + +void AddonManagementDialog::reject() +{ + cleanup(); +} diff --git a/src/modules/addon/AddonManagementDialog.h b/src/modules/addon/AddonManagementDialog.h new file mode 100644 index 000000000..392ad6257 --- /dev/null +++ b/src/modules/addon/AddonManagementDialog.h @@ -0,0 +1,90 @@ +#ifndef _MANAGEMENTDIALOG_H_ +#define _MANAGEMENTDIALOG_H_ +//============================================================================= +// +// File : AddonManagementDialog.h +// Creation date : Fri 08 Apr 2005 14:54:56 by Szymon Stefanek +// +// This file is part of the KVIrc IRC Client distribution +// Copyright (C) 2005-2010 Szymon Stefanek +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +//============================================================================= + +#include "kvi_settings.h" +#include "KviTalListWidget.h" + +#include +#include +#include +#include +#include +#include +#include + +class QPixmap; +class KviKvsScriptAddon; + +class AddonListViewItem : public KviTalListWidgetItem +{ +public: + AddonListViewItem(KviTalListWidget * v,KviKvsScriptAddon * a); + ~AddonListViewItem(); +protected: + KviKvsScriptAddon * m_pAddon; + QTextDocument * m_pText; + QPixmap * m_pIcon; + QListWidget * m_pListWidget; + QString m_szKey; +public: + KviKvsScriptAddon * addon(){ return m_pAddon; }; +}; + + +class AddonManagementDialog : public QWidget +{ + Q_OBJECT +protected: + AddonManagementDialog(QWidget * p); +public: + ~AddonManagementDialog(); +protected: + KviTalListWidget * m_pListWidget; + static AddonManagementDialog * m_pInstance; + QToolButton * m_pConfigureButton; + QToolButton * m_pHelpButton; + QToolButton * m_pPackButton; + QToolButton * m_pUninstallButton; +public: + static AddonManagementDialog * instance(){ return m_pInstance; }; + static void display(bool bTopLevel); + static void cleanup(); +protected: + void fillListView(); + virtual void closeEvent(QCloseEvent * e); +protected slots: + void currentChanged(QListWidgetItem * i, QListWidgetItem *); + void closeClicked(); + void configureScript(); + void showScriptHelp(); + void packScript(); + void uninstallScript(); + void getMoreScripts(); + void installScript(); + virtual void reject(); +}; + +#endif //!_MANAGEMENTDIALOG_H_ diff --git a/src/modules/addon/CMakeLists.txt b/src/modules/addon/CMakeLists.txt index 53ee2e847..df508e37e 100644 --- a/src/modules/addon/CMakeLists.txt +++ b/src/modules/addon/CMakeLists.txt @@ -1,13 +1,13 @@ # CMakeLists for src/modules/addon SET(kviaddon_MOC_HDRS - managementdialog.h + AddonManagementDialog.h PackAddonDialog.h ) SET(kviaddon_SRCS libkviaddon.cpp - managementdialog.cpp + AddonManagementDialog.cpp PackAddonDialog.cpp AddonFunctions.cpp ) diff --git a/src/modules/addon/libkviaddon.cpp b/src/modules/addon/libkviaddon.cpp index 51451108b..1de0166f1 100644 --- a/src/modules/addon/libkviaddon.cpp +++ b/src/modules/addon/libkviaddon.cpp @@ -22,7 +22,7 @@ // //============================================================================= -#include "managementdialog.h" +#include "AddonManagementDialog.h" #include "AddonFunctions.h" #include "KviModule.h" diff --git a/src/modules/addon/managementdialog.cpp b/src/modules/addon/managementdialog.cpp deleted file mode 100644 index d2a70110b..000000000 --- a/src/modules/addon/managementdialog.cpp +++ /dev/null @@ -1,373 +0,0 @@ -//============================================================================= -// -// File : managementdialog.cpp -// Creation date : Fri 08 Apr 2005 14:54:56 by Szymon Stefanek -// -// This file is part of the KVIrc IRC Client distribution -// Copyright (C) 2005-2010 Szymon Stefanek -// -// 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 "managementdialog.h" -#include "PackAddonDialog.h" -#include "AddonFunctions.h" - -#include "KviApplication.h" -#include "KviLocale.h" -#include "KviMainWindow.h" -#include "KviIconManager.h" -#include "KviKvsScriptAddonManager.h" -#include "KviWindow.h" -#include "KviFileDialog.h" -#include "KviFileUtils.h" -#include "kvi_fileextensions.h" -#include "KviKvsScript.h" -#include "kvi_sourcesdate.h" -#include "KviTalListWidget.h" -#include "KviTalToolTip.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -AddonManagementDialog * AddonManagementDialog::m_pInstance = 0; -extern QRect g_rectManagementDialogGeometry; - -AddonListViewItem::AddonListViewItem(KviTalListWidget *v,KviKvsScriptAddon * a) -: KviTalListWidgetItem(v) -{ - m_pAddon = new KviKvsScriptAddon(*a); - m_pListWidget = v; - QString t = ""; - t += a->visibleName(); - t += " ["; - t += a->version(); - t += "]"; - t += " ["; - t += a->name(); - t += "]"; - t += "
"; - t += a->description(); - t += ""; - - setText(t); - QPixmap * p = a->icon(); - if (p) setIcon(*p); -} - -AddonListViewItem::~AddonListViewItem() -{ - delete m_pAddon; -} - -AddonManagementDialog::AddonManagementDialog(QWidget * p) -: QWidget(p) -{ - setWindowTitle(__tr2qs_ctx("Manage Script-Based Addons","addon")); - setObjectName("Addon manager"); - setWindowIcon(*(g_pIconManager->getSmallIcon(KviIconManager::Addons))); - - m_pInstance = this; - QGridLayout * g = new QGridLayout(this); - - KviTalHBox *hb = new KviTalHBox(this); - hb->setMargin(1); - hb->setSpacing(1); - g->addWidget(hb,0,0); - - QToolButton * tb; - QFrame * sep; - - m_pConfigureButton = new QToolButton(hb); - m_pConfigureButton->setIcon(*(g_pIconManager->getBigIcon(KVI_BIGICON_ADDONS))); - m_pConfigureButton->setIconSize(QSize(32,32)); - KviTalToolTip::add(m_pConfigureButton,__tr2qs_ctx("Configure Addon...","addon")); - connect(m_pConfigureButton,SIGNAL(clicked()),this,SLOT(configureScript())); - - m_pHelpButton = new QToolButton(hb); - m_pHelpButton->setIcon(*(g_pIconManager->getBigIcon(KVI_BIGICON_HELP))); - m_pHelpButton->setIconSize(QSize(32,32)); - KviTalToolTip::add(m_pHelpButton,__tr2qs_ctx("Show Help","addon")); - connect(m_pHelpButton,SIGNAL(clicked()),this,SLOT(showScriptHelp())); - - m_pUninstallButton = new QToolButton(hb); - m_pUninstallButton->setIcon(*(g_pIconManager->getBigIcon(KVI_BIGICON_REMOVE))); - m_pUninstallButton->setIconSize(QSize(32,32)); - KviTalToolTip::add(m_pUninstallButton,__tr2qs_ctx("Delete Selected Addons","addon")); - connect(m_pUninstallButton,SIGNAL(clicked()),this,SLOT(uninstallScript())); - - sep = new QFrame(hb); - sep->setFrameStyle(QFrame::VLine | QFrame::Sunken); - sep->setMinimumWidth(12); - - m_pPackButton = new QToolButton(hb); - m_pPackButton->setIcon(*(g_pIconManager->getBigIcon(KVI_BIGICON_PACK))); - m_pPackButton->setIconSize(QSize(32,32)); - KviTalToolTip::add(m_pPackButton,__tr2qs_ctx("Create an Addon as a Distributable Package","addon")); - connect(m_pPackButton,SIGNAL(clicked()),this,SLOT(packScript())); - - sep = new QFrame(hb); - sep->setFrameStyle(QFrame::VLine | QFrame::Sunken); - sep->setMinimumWidth(12); - - tb = new QToolButton(hb); - tb->setIcon(*(g_pIconManager->getBigIcon(KVI_BIGICON_OPEN))); - tb->setIconSize(QSize(32,32)); - KviTalToolTip::add(tb,__tr2qs_ctx("Install Addon Package From Disk","addon")); - connect(tb,SIGNAL(clicked()),this,SLOT(installScript())); - - tb = new QToolButton(hb); - tb->setIcon(*(g_pIconManager->getBigIcon(KVI_BIGICON_WWW))); - tb->setIconSize(QSize(32,32)); - KviTalToolTip::add(tb,__tr2qs_ctx("Get More Addons...","addon")); - connect(tb,SIGNAL(clicked()),this,SLOT(getMoreScripts())); - - QWidget *w= new QWidget(hb); - w->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Minimum); - - m_pListWidget = new KviTalListWidget(this); - KviTalIconAndRichTextItemDelegate *itemDelegate=new KviTalIconAndRichTextItemDelegate(m_pListWidget); - - m_pListWidget->setItemDelegate(itemDelegate); - m_pListWidget->setSelectionMode(QAbstractItemView::SingleSelection); - m_pListWidget->setSortingEnabled(true); - m_pListWidget->setMinimumHeight(400); - m_pListWidget->setMinimumWidth(380); - g->addWidget(m_pListWidget,1,0); - - fillListView(); - - currentChanged(0,0); - connect(m_pListWidget,SIGNAL(currentItemChanged(QListWidgetItem *,QListWidgetItem *)),this,SLOT(currentChanged(QListWidgetItem *,QListWidgetItem *))); - m_pListWidget->setCurrentItem(m_pListWidget->item(0)); - - QPushButton * pCloseBtn = new QPushButton(__tr2qs_ctx("Close","addon"),this); - pCloseBtn->setMaximumSize(pCloseBtn->sizeHint().width(),pCloseBtn->sizeHint().height()); - connect(pCloseBtn,SIGNAL(clicked()),this,SLOT(closeClicked())); - g->addWidget(pCloseBtn,2,0); - - g->setMargin(5); - g->setSpacing(5); - g->setAlignment(pCloseBtn,Qt::AlignRight); - - if(g_rectManagementDialogGeometry.y() < 5) - { - g_rectManagementDialogGeometry.setY(5); - } - resize(g_rectManagementDialogGeometry.width(), - g_rectManagementDialogGeometry.height()); - - QRect rect = g_pApp->desktop()->screenGeometry(g_pMainWindow); - move(rect.x() + ((rect.width() - g_rectManagementDialogGeometry.width())/2),rect.y() + ((rect.height() - g_rectManagementDialogGeometry.height())/2)); -} - -AddonManagementDialog::~AddonManagementDialog() -{ - g_rectManagementDialogGeometry = QRect(pos().x(),pos().y(),size().width(),size().height()); - m_pInstance = 0; -} - -void AddonManagementDialog::fillListView() -{ - m_pListWidget->clear(); - KviPointerHashTable * d = KviKvsScriptAddonManager::instance()->addonDict(); - if(!d)return; - KviPointerHashTableIterator it(*d); - - while(KviKvsScriptAddon * a = it.current()) - { - new AddonListViewItem(m_pListWidget,a); - ++it; - } -} - -void AddonManagementDialog::currentChanged(QListWidgetItem *item,QListWidgetItem *) -{ - AddonListViewItem * it = (AddonListViewItem *)item; - if(!it) - { - m_pConfigureButton->setEnabled(false); - m_pUninstallButton->setEnabled(false); - m_pHelpButton->setEnabled(false); - } else { - m_pConfigureButton->setEnabled(!(it->addon()->configureCallbackCode().isEmpty())); - m_pHelpButton->setEnabled(!(it->addon()->helpCallbackCode().isEmpty())); - m_pUninstallButton->setEnabled(true); - } -} - -void AddonManagementDialog::showScriptHelp() -{ - AddonListViewItem * it = (AddonListViewItem *)m_pListWidget->currentItem(); - if(!it)return; - if(it->addon()->helpCallbackCode().isEmpty())return; - it->addon()->executeHelpCallback(g_pActiveWindow); -} - -void AddonManagementDialog::configureScript() -{ - AddonListViewItem * it = (AddonListViewItem *)m_pListWidget->currentItem(); - if(!it)return; - if(it->addon()->configureCallbackCode().isEmpty())return; - it->addon()->executeConfigureCallback(g_pActiveWindow); -} - -void AddonManagementDialog::packScript() -{ - PackAddonDialog * pDialog = new PackAddonDialog(this); - pDialog->exec(); - delete pDialog; -} - -void AddonManagementDialog::uninstallScript() -{ - AddonListViewItem * it = (AddonListViewItem *)m_pListWidget->currentItem(); - if(!it)return; - - QString txt = "

"; - txt += __tr2qs_ctx("Do you really want to uninstall the addon \"%1\" ?","addon").arg(it->addon()->visibleName()); - txt += "

"; - - if(QMessageBox::question( - this, - __tr2qs_ctx("Confirm addon uninstallation","addon"), - txt, __tr2qs_ctx("Yes","addon"), __tr2qs_ctx("No","addon"),0,1 - ) != 0) return; - - KviKvsScriptAddonManager::instance()->unregisterAddon(it->addon()->name(),g_pActiveWindow); - - fillListView(); - currentChanged(0,0); -} - -void AddonManagementDialog::getMoreScripts() -{ - // If change this introducing not-fixed text, remember to escape this using KviQString::escapeKvs()! - KviKvsScript::run("openurl http://www.kvirc.net/?id=addons&version=" KVI_VERSION "." KVI_SOURCES_DATE,g_pActiveWindow); -} - -void AddonManagementDialog::installScript() -{ - QString szFileName, szError; - - if(!KviFileDialog::askForOpenFileName( - szFileName, - __tr2qs_ctx("Please select the addon installation file","addon"), - QString(),KVI_FILTER_ADDON,false,true - )) return; - - szFileName.replace("\\","\\\\"); - - // Sanity check - if(szFileName.endsWith(".kva")) - { - if(!AddonFunctions::installAddonPackage(szFileName,szError,this)) - { - QMessageBox::critical( - this, - __tr2qs_ctx("Install Addon - KVIrc","addon"), - szError, - QMessageBox::Ok, - QMessageBox::NoButton, - QMessageBox::NoButton - ); - return; - } - } else { - // Just for sanity check. We should NEVER enter here - qDebug("Entered sanity check"); - AddonFunctions::notAValidAddonPackage(szError); - QMessageBox::critical( - this, - __tr2qs_ctx("Install Addon - KVIrc","addon"), - szError, - QMessageBox::Ok, - QMessageBox::NoButton, - QMessageBox::NoButton - ); - } - - fillListView(); - currentChanged(0,0); - - //m_pListWidget->publicUpdateContents(); - //m_pListWidget->triggerUpdate(); -} - -void AddonManagementDialog::closeClicked() -{ - delete this; -} - -void AddonManagementDialog::cleanup() -{ - if(!m_pInstance)return; - delete m_pInstance; - m_pInstance = 0; -} - -void AddonManagementDialog::display(bool bTopLevel) -{ - if(m_pInstance) - { - if(bTopLevel) - { - if(m_pInstance->parent()) - { - m_pInstance->setParent(0); - } - } else { - if(m_pInstance->parent() != g_pMainWindow->splitter()) - { - m_pInstance->setParent(g_pMainWindow->splitter()); - } - } - } else { - if(bTopLevel) - { - m_pInstance = new AddonManagementDialog(0); - } else { - m_pInstance = new AddonManagementDialog(g_pMainWindow->splitter()); - } - } - m_pInstance->show(); - m_pInstance->raise(); - m_pInstance->setFocus(); -} - -void AddonManagementDialog::closeEvent(QCloseEvent * e) -{ - e->ignore(); - delete this; -} - -void AddonManagementDialog::reject() -{ - cleanup(); -} diff --git a/src/modules/addon/managementdialog.h b/src/modules/addon/managementdialog.h deleted file mode 100644 index 78190df28..000000000 --- a/src/modules/addon/managementdialog.h +++ /dev/null @@ -1,90 +0,0 @@ -#ifndef _MANAGEMENTDIALOG_H_ -#define _MANAGEMENTDIALOG_H_ -//============================================================================= -// -// File : managementdialog.h -// Creation date : Fri 08 Apr 2005 14:54:56 by Szymon Stefanek -// -// This file is part of the KVIrc IRC Client distribution -// Copyright (C) 2005-2010 Szymon Stefanek -// -// This program is FREE software. You can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your opinion) any later version. -// -// This program is distributed in the HOPE that it will be USEFUL, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -// See the GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, write to the Free Software Foundation, -// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -//============================================================================= - -#include "kvi_settings.h" -#include "KviTalListWidget.h" - -#include -#include -#include -#include -#include -#include -#include - -class QPixmap; -class KviKvsScriptAddon; - -class AddonListViewItem : public KviTalListWidgetItem -{ -public: - AddonListViewItem(KviTalListWidget * v,KviKvsScriptAddon * a); - ~AddonListViewItem(); -protected: - KviKvsScriptAddon * m_pAddon; - QTextDocument * m_pText; - QPixmap * m_pIcon; - QListWidget * m_pListWidget; - QString m_szKey; -public: - KviKvsScriptAddon * addon(){ return m_pAddon; }; -}; - - -class AddonManagementDialog : public QWidget -{ - Q_OBJECT -protected: - AddonManagementDialog(QWidget * p); -public: - ~AddonManagementDialog(); -protected: - KviTalListWidget * m_pListWidget; - static AddonManagementDialog * m_pInstance; - QToolButton * m_pConfigureButton; - QToolButton * m_pHelpButton; - QToolButton * m_pPackButton; - QToolButton * m_pUninstallButton; -public: - static AddonManagementDialog * instance(){ return m_pInstance; }; - static void display(bool bTopLevel); - static void cleanup(); -protected: - void fillListView(); - virtual void closeEvent(QCloseEvent * e); -protected slots: - void currentChanged(QListWidgetItem * i, QListWidgetItem *); - void closeClicked(); - void configureScript(); - void showScriptHelp(); - void packScript(); - void uninstallScript(); - void getMoreScripts(); - void installScript(); - virtual void reject(); -}; - -#endif //!_MANAGEMENTDIALOG_H_ diff --git a/src/modules/reguser/CMakeLists.txt b/src/modules/reguser/CMakeLists.txt index aed8d44ba..66d672c06 100644 --- a/src/modules/reguser/CMakeLists.txt +++ b/src/modules/reguser/CMakeLists.txt @@ -3,14 +3,14 @@ SET(kvireguser_MOC_HDRS RegisteredUserEntryDialog.h RegistrationWizard.h - dialog.h + RegisteredUsersDialog.h ) SET(kvireguser_SRCS libkvireguser.cpp RegisteredUserEntryDialog.cpp RegistrationWizard.cpp - dialog.cpp + RegisteredUsersDialog.cpp ) # After this call, files will be moc'ed to moc_kvi_*.cpp diff --git a/src/modules/reguser/RegisteredUserEntryDialog.cpp b/src/modules/reguser/RegisteredUserEntryDialog.cpp index c3aae0fd7..05ba20eef 100644 --- a/src/modules/reguser/RegisteredUserEntryDialog.cpp +++ b/src/modules/reguser/RegisteredUserEntryDialog.cpp @@ -26,7 +26,7 @@ #include "RegisteredUserEntryDialog.h" #include "RegistrationWizard.h" -#include "dialog.h" +#include "RegisteredUsersDialog.h" #include "KviRegisteredUserDataBase.h" #include "KviLocale.h" diff --git a/src/modules/reguser/RegisteredUsersDialog.cpp b/src/modules/reguser/RegisteredUsersDialog.cpp new file mode 100644 index 000000000..b19e0fcc4 --- /dev/null +++ b/src/modules/reguser/RegisteredUsersDialog.cpp @@ -0,0 +1,933 @@ +//============================================================================= +// +// File : RegisteredUserEntryDialog.cpp +// Creation date : Tue Dec 26 2000 12:24:12 CEST by Szymon Stefanek +// +// This file is part of the KVIrc irc client distribution +// Copyright (C) 2000-2010 Szymon Stefanek (pragma at kvirc dot net) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +//============================================================================= + +#define _WANT_OPTION_FLAGS_ + +#include "RegisteredUserEntryDialog.h" +#include "RegistrationWizard.h" +#include "RegisteredUsersDialog.h" + +#include "KviRegisteredUserDataBase.h" +#include "KviLocale.h" +#include "KviIrcMask.h" +#include "kvi_debug.h" +#include "KviMainWindow.h" +#include "KviIconManager.h" +#include "KviApplication.h" +#include "KviOptions.h" +#include "KviFile.h" +#include "KviFileDialog.h" +#include "KviMessageBox.h" +#include "KviFileUtils.h" +#include "kvi_settings.h" +#include "KviStringConversion.h" +#include "KviOptions.h" +#include "KviPointerHashTable.h" +#include "KviTalHBox.h" +#include "KviTalVBox.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#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) + + +extern RegisteredUsersDialog * g_pRegisteredUsersDialog; + +KviRegisteredUsersListView::KviRegisteredUsersListView(QWidget * par) +: QTreeWidget(par) +{ + setColumnCount(2); + + QStringList labels; + labels << __tr2qs_ctx("Name","register") << __tr2qs_ctx("Flags","register"); + setHeaderLabels(labels); + setColumnWidth(0,360); + setColumnWidth(1,20); + + setAllColumnsShowFocus(true); + + setSelectionBehavior(QAbstractItemView::SelectRows); + setSelectionMode(QAbstractItemView::ExtendedSelection); + setRootIsDecorated(TRUE); + setSortingEnabled(true); + + setToolTip(__tr2qs_ctx("
This is the list of registered users. " \ + "KVIrc can automatically recognize and associate properties to them.
" \ + "Use the buttons on the right to add, edit and remove entries. " \ + "The \"notify\" column allows you to quickly add users to the notify list. " \ + "Notify list fine-tuning can be performed by editing the entry properties.
","register")); +} + +void KviRegisteredUsersListView::mousePressEvent (QMouseEvent *e) +{ + if (e->button() == Qt::RightButton) + { + QTreeWidgetItem *i= itemAt(e->pos()); + if (i) emit rightButtonPressed(i,QCursor::pos()); + } + QTreeWidget::mousePressEvent(e); +} + +RegisteredUsersDialogItem::RegisteredUsersDialogItem(QTreeWidgetItem * par,KviRegisteredUser * u) +: RegisteredUsersDialogItemBase(User,par), m_pUser(u) +{ + QString szTmp; + QString t = ""; + t += u->name(); + t += " ["; + szTmp = m_pUser->getProperty("notify"); + if(szTmp.isEmpty()) + { + t += __tr2qs_ctx("Notify disabled","register"); + } else { + t += __tr2qs_ctx("Notify as:","register"); + t += " "; + t += szTmp; + + } + t += "]"; + t += "
"; + szTmp = m_pUser->getProperty("comment"); + if(szTmp.isEmpty()) + { + t += __tr2qs_ctx("No comment set","register"); + } else { + t += __tr2qs_ctx("Comment:","register"); + t += " "; + t += m_pUser->getProperty("comment"); + } + t += ""; + m_pText.setHtml(t); + m_pText.setTextWidth(-1); +// setText(0,t); +} + +RegisteredUsersDialogItem::~RegisteredUsersDialogItem() +{ +} + +QString RegisteredUsersDialogItem::key(int,bool) const +{ + return m_pUser->name(); +} + +void RegisteredUsersDialogItemDelegate::paint( QPainter * p, const QStyleOptionViewItem & option, const QModelIndex & index ) const +{ + + RegisteredUsersDialogItemBase *item=static_cast(index.internalPointer()); + + if(item->type()==RegisteredUsersDialogItemBase::Group) + { + //groups + QStyledItemDelegate::paint(p, option, index); + } else { + QStyleOptionViewItemV4 opt = option; + initStyleOption(&opt, index); + + if (opt.state & QStyle::State_Selected) + QApplication::style()->drawPrimitive(QStyle::PE_PanelItemViewItem,&opt, p); + + RegisteredUsersDialogItem *it=(RegisteredUsersDialogItem*)item; + + if(index.column()==0) + { + QPoint pt=opt.rect.topLeft(); + pt.setX(pt.x()+LVI_BORDER); + pt.setY(pt.y()+LVI_BORDER); + + p->drawPixmap(pt, *(g_pIconManager->getBigIcon(KVI_BIGICON_REGUSERS))); + QRect cliprect=QRect(QPoint(0,0),QSize(opt.rect.width()-(LVI_ICON_SIZE+LVI_SPACING+LVI_BORDER),opt.rect.height())); + p->save(); + + p->translate(opt.rect.x()+LVI_ICON_SIZE+LVI_SPACING, opt.rect.y()); + it->m_pText.drawContents(p, cliprect); + p->restore(); + } else { + if(it->user()) + { + if(!it->user()->getProperty("notify").isEmpty()) + p->drawPixmap(opt.rect.topLeft().x()+LVI_BORDER,opt.rect.topLeft().y()+LVI_BORDER,*(g_pIconManager->getSmallIcon(KviIconManager::NotifyOnLine))); + else + p->drawPixmap(opt.rect.topLeft().x()+LVI_BORDER,opt.rect.topLeft().y()+LVI_BORDER,*(g_pIconManager->getSmallIcon(KviIconManager::NotifyOffLine))); + if(it->user()->ignoreEnagled()) + p->drawPixmap(opt.rect.topLeft().x()+LVI_BORDER,opt.rect.topLeft().y()+2*LVI_BORDER+16,*(g_pIconManager->getSmallIcon(KviIconManager::Ignore))); + } + } + } +} + +QSize RegisteredUsersDialogItemDelegate::sizeHint( const QStyleOptionViewItem & option, const QModelIndex & index ) const +{ + RegisteredUsersDialogItemBase *item=static_cast(index.internalPointer()); + + if(item->type()==RegisteredUsersDialogItemBase::Group) + { + //groups + return QStyledItemDelegate::sizeHint(option, index); + } else { + //users +// RegisteredUsersDialogItem *it=(RegisteredUsersDialogItem*)item; + + return QSize(300, LVI_ICON_SIZE+2*LVI_BORDER); + } +} + +RegisteredUsersDialog::RegisteredUsersDialog(QWidget * par) +: QWidget(par) +{ + g_pRegisteredUsersDialog = this; + + g_pLocalRegisteredUserDataBase = new KviRegisteredUserDataBase(); + g_pLocalRegisteredUserDataBase->copyFrom(g_pRegisteredUserDataBase); + + setWindowIcon(*(g_pIconManager->getSmallIcon(KviIconManager::RegUsers))); + setWindowTitle(__tr2qs_ctx("Registered Users - KVIrc","register")); + + QGridLayout * g = new QGridLayout(this); + + + m_pListView = new KviRegisteredUsersListView(this); + m_pListView->setItemDelegate(new RegisteredUsersDialogItemDelegate()); + + connect(m_pListView,SIGNAL(itemPressed(QTreeWidgetItem *,int)),this,SLOT(itemPressed(QTreeWidgetItem *,int))); + connect(m_pListView,SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)),this,SLOT(itemDoubleClicked(QTreeWidgetItem *, int))); + + g->addWidget(m_pListView,0,0,2,2); + + KviTalVBox * vbox = new KviTalVBox(this); + vbox->setSpacing(4); + g->addWidget(vbox,0,2); + + m_pWizardAddButton = new QPushButton(__tr2qs_ctx("Add (Wizard)...","register"),vbox); + connect(m_pWizardAddButton,SIGNAL(clicked()),this,SLOT(addWizardClicked())); + m_pWizardAddButton->setToolTip(__tr2qs_ctx("Add a registered user by means of a user-friendly wizard.","register")); + m_pWizardAddButton->setIcon(*(g_pIconManager->getSmallIcon(KviIconManager::NewItemByWizard))); + + + m_pAddButton = new QPushButton(__tr2qs_ctx("&Add...","register"),vbox); + connect(m_pAddButton,SIGNAL(clicked()),this,SLOT(addClicked())); + m_pAddButton->setToolTip(__tr2qs_ctx("Open the edit dialog to create a new user entry.","register")); + m_pAddButton->setIcon(*(g_pIconManager->getSmallIcon(KviIconManager::NewItem))); + + m_pAddGroupButton = new QPushButton(__tr2qs_ctx("&Add Group...","register"),vbox); + connect(m_pAddGroupButton,SIGNAL(clicked()),this,SLOT(addGroupClicked())); + m_pAddGroupButton->setToolTip(__tr2qs_ctx("Adds a new group","register")); + m_pAddGroupButton->setIcon(*(g_pIconManager->getSmallIcon(KviIconManager::NewItem))); + + m_pRemoveButton = new QPushButton(__tr2qs_ctx("Re&move","register"),vbox); + connect(m_pRemoveButton,SIGNAL(clicked()),this,SLOT(removeClicked())); + m_pRemoveButton->setEnabled(false); + m_pRemoveButton->setToolTip(__tr2qs_ctx("Remove the currently selected entries.","register")); + m_pRemoveButton->setIcon(*(g_pIconManager->getSmallIcon(KviIconManager::DeleteItem))); + + + m_pEditButton = new QPushButton(__tr2qs_ctx("&Edit...","register"),vbox); + connect(m_pEditButton,SIGNAL(clicked()),this,SLOT(editClicked())); + m_pEditButton->setEnabled(false); + m_pEditButton->setToolTip(__tr2qs_ctx("Edit the first selected entry.","register")); + m_pEditButton->setIcon(*(g_pIconManager->getSmallIcon(KviIconManager::EditItem))); + + QFrame * f = new QFrame(vbox); + f->setFrameStyle(QFrame::HLine | QFrame::Sunken); + + m_pSelectAllButton = new QPushButton(__tr2qs_ctx("Select all","register"),vbox); + connect(m_pSelectAllButton,SIGNAL(clicked()),this,SLOT(selectAllClicked())); + m_pSelectAllButton->setToolTip(__tr2qs_ctx("Select all the entries","register")); + m_pSelectAllButton->setIcon(*(g_pIconManager->getSmallIcon(KviIconManager::Plus))); + + m_pExportButton = new QPushButton(__tr2qs_ctx("Export To...","register"),vbox); + m_pExportButton->setEnabled(false); + connect(m_pExportButton,SIGNAL(clicked()),this,SLOT(exportClicked())); + m_pExportButton->setToolTip(__tr2qs_ctx("Export the selected entries to a file.
All the data associated with the selected registered users will be exported.
You (or anyone else) can later import the entries by using the \"Import\" button.","register")); + m_pExportButton->setIcon(*(g_pIconManager->getSmallIcon(KviIconManager::Floppy))); + + + m_pImportButton = new QPushButton(__tr2qs_ctx("Import From...","register"),vbox); + connect(m_pImportButton,SIGNAL(clicked()),this,SLOT(importClicked())); + m_pImportButton->setToolTip(__tr2qs_ctx("Import entries from a file exported earlier by the \"export\" function of this dialog.","register")); + m_pImportButton->setIcon(*(g_pIconManager->getSmallIcon(KviIconManager::Folder))); + + + KviTalHBox * hbox = new KviTalHBox(this); + hbox->setSpacing(4); + g->addWidget(hbox,3,1,1,2); + + QPushButton * b; + + + b = new QPushButton(__tr2qs_ctx("&OK","register"),hbox); + connect(b,SIGNAL(clicked()),this,SLOT(okClicked())); + b->setIcon(*(g_pIconManager->getSmallIcon(KviIconManager::Accept))); + //b->setMinimumWidth(120); + + b = new QPushButton(__tr2qs_ctx("Cancel","register"),hbox); + connect(b,SIGNAL(clicked()),this,SLOT(cancelClicked())); + b->setIcon(*(g_pIconManager->getSmallIcon(KviIconManager::Discard))); + //b->setMinimumWidth(120); + + g->addItem(new QSpacerItem(0, 15), 2, 0); + g->setColumnStretch(0,1); + g->setRowStretch(1,1); + + connect(m_pListView,SIGNAL(itemSelectionChanged()),this,SLOT(selectionChanged())); + connect(m_pListView,SIGNAL(rightButtonPressed(QTreeWidgetItem *, QPoint)),this,SLOT(rightButtonPressed(QTreeWidgetItem *, QPoint))); + + fillList(); + + if(!parent()) + { + if(KVI_OPTION_RECT(KviOption_rectRegisteredUsersDialogGeometry).y() < 5) + KVI_OPTION_RECT(KviOption_rectRegisteredUsersDialogGeometry).setY(5); + + //setGeometry(KVI_OPTION_RECT(KviOption_rectRegisteredUsersDialogGeometry)); + resize(KVI_OPTION_RECT(KviOption_rectRegisteredUsersDialogGeometry).width(), + KVI_OPTION_RECT(KviOption_rectRegisteredUsersDialogGeometry).height()); + + QRect rect = g_pApp->desktop()->screenGeometry(g_pMainWindow); + move(rect.x() + ((rect.width() - KVI_OPTION_RECT(KviOption_rectRegisteredUsersDialogGeometry).width())/2),rect.y() + ((rect.height() - KVI_OPTION_RECT(KviOption_rectRegisteredUsersDialogGeometry).height())/2)); + + } +} + +RegisteredUsersDialog::~RegisteredUsersDialog() +{ +#ifndef COMPILE_ON_MAC + if(!parent())KVI_OPTION_RECT(KviOption_rectRegisteredUsersDialogGeometry) = QRect(pos().x(),pos().y(),size().width(),size().height()); +#else + if(!parent())KVI_OPTION_RECT(KviOption_rectRegisteredUsersDialogGeometry) = geometry(); +#endif + + g_pRegisteredUsersDialog = 0; + + delete g_pLocalRegisteredUserDataBase; + g_pLocalRegisteredUserDataBase = 0; +} + +void RegisteredUsersDialog::itemPressed(QTreeWidgetItem *it,int c) +{ + if(!it)return; + RegisteredUsersDialogItemBase* b=(RegisteredUsersDialogItemBase*)it; + if(b->type()==RegisteredUsersDialogItemBase::User) + { + RegisteredUsersDialogItem *i = (RegisteredUsersDialogItem *)it; + + QRect r = m_pListView->visualItemRect(i); + int daw = m_pListView->columnWidth(0); + + QPoint ppp = m_pListView->mapFromGlobal(QCursor::pos()); + + if((c == 1) && (ppp.x() < (r.height() + 5 + daw))) + { + // notify list toggle + if(i->user()->getProperty("notify").isEmpty()) + { + // try to find the nicknames to be notified + QString szMask; + + for(KviIrcMask * m = i->user()->maskList()->first();m;m = i->user()->maskList()->next()) + { + QString tmp = m->nick(); + if((tmp.indexOf('*') == -1) && (tmp.indexOf('?') == -1) && (!tmp.isEmpty())) + { + if(!szMask.isEmpty())szMask.append(' '); + szMask.append(tmp); + } + } + // if the nickname list is still empty, build a dummy nick to notify + if(szMask.isEmpty()) + { + szMask = i->user()->name(); + szMask.replace(" ",""); + szMask.replace("'",""); + szMask.replace("&",""); + szMask.replace(",",""); + } + + i->user()->setProperty("notify",szMask); + } else { + i->user()->setProperty("notify",QString("")); // kill that + } + + m_pListView->repaint(r); + } + } +} + +void RegisteredUsersDialog::itemDoubleClicked(QTreeWidgetItem *it, int) +{ + if(!it)return; + RegisteredUsersDialogItemBase* b=(RegisteredUsersDialogItemBase*)it; + if(b->type()==RegisteredUsersDialogItemBase::User) + { + editItem((RegisteredUsersDialogItem *)it); + } else { + RegisteredUsersGroupItem *i = (RegisteredUsersGroupItem *)b; + editGroup(i->group()); + } +} + +void RegisteredUsersDialog::addGroupClicked() +{ + bool ok; + QString text = QInputDialog::getText( this, + "KVIrc", __tr2qs_ctx("Group name:","register"), QLineEdit::Normal, + QString(), &ok ); + if ( ok && !text.isEmpty() ) { + g_pLocalRegisteredUserDataBase->addGroup(text); + fillList(); + } +} + +void RegisteredUsersDialog::editGroup(KviRegisteredUserGroup* group) +{ + bool ok; + + QString text = QInputDialog::getText( this, + "KVIrc", __tr2qs_ctx("Group name:","register"), QLineEdit::Normal, + group->name(), &ok ); + if ( ok && !text.isEmpty() ) { + QString szOldGroup=group->name(); + g_pLocalRegisteredUserDataBase->groupDict()->setAutoDelete(0); + g_pLocalRegisteredUserDataBase->groupDict()->remove(szOldGroup); + g_pLocalRegisteredUserDataBase->groupDict()->setAutoDelete(1); + group->setName(text); + g_pLocalRegisteredUserDataBase->groupDict()->insert(text,group); + + KviPointerHashTable * d = g_pLocalRegisteredUserDataBase->userDict(); + + for(KviRegisteredUser * u = d->first();u;u = d->next()) + { + if(u->group()==szOldGroup) + u->setGroup(text); + } + + fillList(); + + // select the last edited item + for(int c=0;ctopLevelItemCount();c++) + { + QTreeWidgetItem * pGroup = m_pListView->topLevelItem(c); + if(KviQString::equalCI(pGroup->text(0),text)) + { + pGroup->setSelected(true); + m_pListView->setCurrentItem(pGroup); + break; + } + } + } +} + + +void RegisteredUsersDialog::rightButtonPressed ( QTreeWidgetItem * pItem, QPoint pnt) +{ + if(pItem) + { + RegisteredUsersDialogItemBase* b=(RegisteredUsersDialogItemBase*)pItem; + if(b->type()==RegisteredUsersDialogItemBase::User) + { + KviTalPopupMenu *groups = new KviTalPopupMenu; + + KviPointerHashTable * pGroups = g_pLocalRegisteredUserDataBase->groupDict(); + m_TmpDict.clear(); + for(KviPointerHashTableEntry * g = pGroups->firstEntry();g;g = pGroups->nextEntry()) + { + int id=groups->insertItem(g->key()); + m_TmpDict.replace(id,g->data()); + } + + connect(groups,SIGNAL(activated ( int )),this,SLOT(moveToGroupMenuClicked(int))); + + KviTalPopupMenu *mainPopup = new KviTalPopupMenu; + mainPopup->insertItem(__tr2qs_ctx("Move to group","register"),groups); + mainPopup->exec(pnt); + } + } +} + +void RegisteredUsersDialog::moveToGroupMenuClicked(int id) +{ + QString szGroup=(*(m_TmpDict.find(id)))->name(); + QList list = m_pListView->selectedItems(); + for(int i=0; itype()==RegisteredUsersDialogItemBase::User) + { + ((RegisteredUsersDialogItem *)list.at(i))->user()->setGroup(szGroup); + } + } + fillList(); +} + +void RegisteredUsersDialog::fillList() +{ + m_pListView->clear(); + KviPointerHashTable groupItems(5,false); + groupItems.setAutoDelete(false); + + KviPointerHashTable * pGroups = g_pLocalRegisteredUserDataBase->groupDict(); + for(KviRegisteredUserGroup * g = pGroups->first();g;g = pGroups->next()) + { + RegisteredUsersGroupItem* pCur = new RegisteredUsersGroupItem(m_pListView,g); + groupItems.insert(g->name(),pCur); + pCur->setExpanded(TRUE); + } + + KviPointerHashTable * d = g_pLocalRegisteredUserDataBase->userDict(); + RegisteredUsersDialogItem * item; + + for(KviRegisteredUser * u = d->first();u;u = d->next()) + { + if(u->group().isEmpty()) + u->setGroup(__tr2qs_ctx("Default","register")); + if(groupItems.find(u->group())) + item = new RegisteredUsersDialogItem(groupItems.find(u->group()),u); + else if(groupItems.find(__tr2qs_ctx("Default","register"))) + item = new RegisteredUsersDialogItem(groupItems.find(__tr2qs_ctx("Default","register")),u); + else { //should never be called + KviRegisteredUserGroup* pGroup = g_pLocalRegisteredUserDataBase->addGroup(__tr2qs_ctx("Default","register")); + RegisteredUsersGroupItem* pCur = new RegisteredUsersGroupItem(m_pListView,pGroup); + groupItems.insert(__tr2qs_ctx("Default","register"),pCur); + item = new RegisteredUsersDialogItem(pCur,u); + } + } + if(m_pListView->topLevelItem(0)) + { + m_pListView->topLevelItem(0)->setSelected(true); + m_pListView->setCurrentItem(m_pListView->topLevelItem(0)); + } +} + +void RegisteredUsersDialog::closeEvent(QCloseEvent *e) +{ + m_pListView->clear(); + e->accept(); + okClicked(); + //delete this; +} + +void RegisteredUsersDialog::okClicked() +{ + m_pListView->clear(); + g_pRegisteredUserDataBase->copyFrom(g_pLocalRegisteredUserDataBase); + g_pApp->restartNotifyLists(); + delete this; +} + +void RegisteredUsersDialog::cancelClicked() +{ + m_pListView->clear(); + delete this; +} + +void RegisteredUsersDialog::addClicked() +{ + RegisteredUserEntryDialog * dlg = new RegisteredUserEntryDialog(this,0); + int ret = dlg->exec(); + delete dlg; + + if(!g_pRegisteredUsersDialog)return; // we have been deleted! + + if(ret == QDialog::Accepted) + { + fillList(); + } +} + +void RegisteredUsersDialog::addWizardClicked() +{ + RegistrationWizard * w = new RegistrationWizard("",g_pLocalRegisteredUserDataBase,this,true); + int ret = w->exec(); + delete w; + if(!g_pRegisteredUsersDialog)return; // we have been deleted! + if(ret == QDialog::Accepted) + { + fillList(); + } +} + +void RegisteredUsersDialog::removeClicked() +{ + QList list = m_pListView->selectedItems(); + for(int i=0; itype()==RegisteredUsersDialogItemBase::User) + { + g_pLocalRegisteredUserDataBase->removeUser(((RegisteredUsersDialogItem *)list.at(i))->user()->name()); + } else { + g_pLocalRegisteredUserDataBase->removeGroup(((RegisteredUsersGroupItem *)list.at(i))->group()->name()); + } + } + fillList(); +// RegisteredUsersDialogItem *it = (RegisteredUsersDialogItem *)m_pListView->firstChild(); +// RegisteredUsersDialogItemBase* b=(RegisteredUsersDialogItemBase*)it; +// if(b->type()==RegisteredUsersDialogItemBase::User) +// { +// KviPointerList l; +// l.setAutoDelete(false); +// while(it) +// { +// if(it->isSelected())l.append(it); +// it = (RegisteredUsersDialogItem *)it->nextSibling(); +// } +// +// for(RegisteredUsersDialogItem * i = l.first();i;i = l.next()) +// { +// //g_pLocalRegisteredUserDataBase->removeUser(i->user()->name()); +// delete i; +// } +// } else { +// +// } +} + +void RegisteredUsersDialog::editClicked() +{ + RegisteredUsersDialogItemBase* b=(RegisteredUsersDialogItemBase*)(m_pListView->currentItem()); + if(!b)return; + if(b->type()==RegisteredUsersDialogItemBase::User) + { + RegisteredUsersDialogItem *i = (RegisteredUsersDialogItem *)b; + editItem(i); + } else { + RegisteredUsersGroupItem *i = (RegisteredUsersGroupItem *)b; + editGroup(i->group()); + } +} + +void RegisteredUsersDialog::editItem(RegisteredUsersDialogItem * i) +{ + KviRegisteredUser * u = i->user(); + + i->setUser(0); + + QString szName = u->name(); + + RegisteredUserEntryDialog * dlg = new RegisteredUserEntryDialog(this,u); + int res = dlg->exec(); + delete dlg; + + if(!g_pRegisteredUsersDialog)return; // we have been deleted! + + if(res == QDialog::Accepted) + { + fillList(); + + // select the last edited item + for(int c=0;ctopLevelItemCount();c++) + { + QTreeWidgetItem * pGroup = m_pListView->topLevelItem(c); + for(int d=0;dchildCount();d++) + { + RegisteredUsersDialogItem * pUser = (RegisteredUsersDialogItem*) pGroup->child(d); + if(KviQString::equalCI(pUser->user()->name(),szName)) + { + pUser->setSelected(true); + m_pListView->setCurrentItem(pUser); + break; + } + } + } + + return; + } + + i->setUser(u); + m_pListView->update(); +} + +void RegisteredUsersDialog::selectionChanged() +{ + bool bHaveSelected = !m_pListView->selectedItems().empty(); + + m_pEditButton->setEnabled(bHaveSelected); + m_pRemoveButton->setEnabled(bHaveSelected); + m_pExportButton->setEnabled(bHaveSelected); +} + + +#define KVI_REGUSER_DB_FILE_MAGIC 0x5334DBDB +#define KVI_REGUSER_DB_FILE_VERSION 1 + +typedef struct _KviReguserDbFileHeader +{ + kvi_u32_t magic; + kvi_u32_t version; + kvi_u32_t nentries; +} KviReguserDbFileHeader; + +void RegisteredUsersDialog::exportClicked() +{ + unsigned int nEntries = 0; + + QList list = m_pListView->selectedItems(); + + //only "user" entries matters, discard groups from count + for(int i=0; itype() == RegisteredUsersDialogItemBase::User) + nEntries++; + } + + if(nEntries < 1) + { + KviMessageBox::warning(__tr2qs_ctx("No entries selected.","register")); + return; + } + + QString buffer; + + if(!KviFileDialog::askForSaveFileName(buffer,__tr2qs_ctx("Choose a Filename - KVIrc","register"),0,0,true,true))return; + + if(!g_pRegisteredUsersDialog)return; // we have been deleted! + + KviFile f(buffer); + if(!f.open(QIODevice::WriteOnly | QIODevice::Truncate)) + { + KviMessageBox::warning(__tr2qs_ctx("Can't open file %Q for writing.","register"),&buffer); + return; + } + + KviReguserDbFileHeader hf; + hf.magic = KVI_REGUSER_DB_FILE_MAGIC; + hf.version = KVI_REGUSER_DB_FILE_VERSION; + hf.nentries = nEntries; + + if(f.write((const char *)&hf,sizeof(KviReguserDbFileHeader)) != sizeof(KviReguserDbFileHeader))goto write_error; + + for(int i=0; itype()!=RegisteredUsersDialogItemBase::User) + continue; + + KviRegisteredUser * u = ((RegisteredUsersDialogItem *)list.at(i))->user(); + if(u) + { + if(!f.save(u->name()))goto write_error; + KviPointerHashTable * pd = u->propertyDict(); + if(pd) + { + if(!f.save(pd->count()))goto write_error; + for(KviPointerHashTableEntry * pCur = pd->firstEntry();pCur;pCur = pd->nextEntry()) + { + QString key = pCur->key(); + if(!f.save(key))goto write_error; + if(!f.save(*(pCur->data())))goto write_error; + } + } else { + if(!f.save(0))goto write_error; + } + + KviPointerList * ml = u->maskList(); + if(ml) + { + if(!f.save(ml->count()))goto write_error; + for(KviIrcMask * m = ml->first();m;m = ml->next()) + { + QString fullMask; + m->mask(fullMask,KviIrcMask::NickUserHost); + if(!f.save(fullMask))goto write_error; + } + } else { + if(!f.save(0))goto write_error; + } + + QString avatar; + if(u->getProperty("avatar",avatar)) + { + KviAvatar * av = g_pIconManager->getAvatar(QString(),avatar); + if(av) + { + if(!av->pixmap()->isNull()) + { + if(!f.save(1))goto write_error; + QImageWriter io; + io.setDevice(&f); + io.setFormat("PNG"); + if(!io.write(av->pixmap()->toImage()))goto write_error; + } else { + if(!f.save(0))goto write_error; + } + } else { + if(!f.save(0))goto write_error; + } + } else { + if(!f.save(0))goto write_error; + } + } + } + + goto succesfull_export; + + +write_error: + KviMessageBox::warning(__tr2qs_ctx("Can't export the registered users database: Write error.","register")); + f.close(); + return; + +succesfull_export: + + f.close(); +} + +void RegisteredUsersDialog::selectAllClicked() +{ + m_pListView->selectAll(); +} + +void RegisteredUsersDialog::importClicked() +{ + //KviCString buffer; + QString buffer; + + if(!KviFileDialog::askForOpenFileName(buffer,__tr2qs_ctx("Choose a Filename - KVIrc","register")))return; + + if(!g_pRegisteredUsersDialog)return; // we have been deleted! + + KviFile f(buffer); + if(!f.open(QIODevice::ReadOnly)) + { + KviMessageBox::warning(__tr2qs_ctx("Can't open file %s for reading.","register"),&buffer); + return; + } + + KviReguserDbFileHeader hf; + unsigned int idx; + + if(f.read((char *)&hf,sizeof(KviReguserDbFileHeader)) != sizeof(KviReguserDbFileHeader))goto read_error; + + if(hf.magic != KVI_REGUSER_DB_FILE_MAGIC) + { + KviMessageBox::warning(__tr2qs_ctx("The file %s doesn't appear to be a valid registered users database.","register"),&buffer); + f.close(); + return; + } + + if(hf.version != KVI_REGUSER_DB_FILE_VERSION) + { + KviMessageBox::warning(__tr2qs_ctx("The file %s contains an invalid registered users database version.","register"),&buffer); + f.close(); + return; + } + + for(idx = 0;idx < hf.nentries;idx++) + { + QString szName; + if(!f.load(szName))goto read_error; + KviRegisteredUser * u = g_pLocalRegisteredUserDataBase->getUser(szName); + if(!u) goto read_error; + unsigned int count = 0; + if(!f.load(count))goto read_error; + for(unsigned int up = 0;up < count;up++) + { + QString szKey,szValue; + if(!f.load(szKey))goto read_error; + if(!f.load(szValue))goto read_error; + u->setProperty(szKey,szValue); + } + if(!f.load(count))goto read_error; + for(unsigned int um = 0;um < count;um++) + { + QString szMask; + if(!f.load(szMask))goto read_error; + if(!szMask.isEmpty()) + { + KviIrcMask * m = new KviIrcMask(szMask); + g_pLocalRegisteredUserDataBase->addMask(u,m); + } + } + if(!f.load(count))goto read_error; + if(count) + { + // there is an avatar + QImage img; + QImageReader io; + io.setDevice(&f); + io.setFormat("PNG"); + img=io.read(); +// if(io.read())goto read_error; + + if(img.isNull())qDebug("Ops.. readed a null image ?"); + + QString fName = u->name(); + KviFileUtils::adjustFilePath(fName); + + QString fPath; + int rnm = 0 ; + do + { + g_pApp->getLocalKvircDirectory(fPath,KviApplication::Avatars,fName); + fPath.append(QString("%1.png").arg(rnm)); + rnm++; + } while(KviFileUtils::fileExists(fPath)); + + if(!img.save(fPath,"PNG")) + { + qDebug("Can't save image %s",fPath.toUtf8().data()); + } else { + u->setProperty("avatar",fPath); + } + } + } + + goto succesfull_import; + + +read_error: + KviMessageBox::warning(__tr2qs_ctx("Can't import the registered users database: Read error.","register")); + f.close(); + return; + +succesfull_import: + + f.close(); + fillList(); +} + + +#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES +#include "dialog.moc" +#endif //!COMPILE_USE_STANDALONE_MOC_SOURCES diff --git a/src/modules/reguser/RegisteredUsersDialog.h b/src/modules/reguser/RegisteredUsersDialog.h new file mode 100644 index 000000000..d511560dd --- /dev/null +++ b/src/modules/reguser/RegisteredUsersDialog.h @@ -0,0 +1,159 @@ +#ifndef _DIALOG_H_ +#define _DIALOG_H_ +//============================================================================= +// +// File : RegisteredUserEntryDialog.h +// Creation date : Sun Dec 24 2000 15:16:17 CEST by Szymon Stefanek +// +// This file is part of the KVIrc irc client distribution +// Copyright (C) 2000-2010 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 "KviCString.h" +#include "KviRegisteredUserDataBase.h" +#include "KviSelectors.h" +#include "KviPointerHashTable.h" +#include +#include "KviTalListWidget.h" +#include "KviTalPopupMenu.h" + +#include +#include +#include +#include +#include +#include + +class KviRegisteredUsersListView : public QTreeWidget +{ + Q_OBJECT +public: + KviRegisteredUsersListView(QWidget*); + ~KviRegisteredUsersListView(){}; +protected: + void mousePressEvent (QMouseEvent *e); +signals: + void rightButtonPressed(QTreeWidgetItem *,QPoint); +}; + +class RegisteredUsersDialogItemDelegate : public QStyledItemDelegate +{ +public: + RegisteredUsersDialogItemDelegate(KviRegisteredUsersListView * pWidget=0) + : QStyledItemDelegate(pWidget) {}; + ~RegisteredUsersDialogItemDelegate(){}; + QSize sizeHint(const QStyleOptionViewItem &option,const QModelIndex &index) const; + void paint( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const; + +}; + +class RegisteredUsersDialogItemBase : public QTreeWidgetItem +{ +public: + enum Types { User,Group }; +protected: + RegisteredUsersDialogItemBase(Types type,KviRegisteredUsersListView * par) + :QTreeWidgetItem(par),m_iType(type) + { + }; + RegisteredUsersDialogItemBase(Types type,QTreeWidgetItem * par) + :QTreeWidgetItem(par),m_iType(type) + { + }; + ~RegisteredUsersDialogItemBase() + { + }; + +private: + RegisteredUsersDialogItemBase::Types m_iType; +public: + RegisteredUsersDialogItemBase::Types type() { return m_iType; }; +}; + +class RegisteredUsersGroupItem : public RegisteredUsersDialogItemBase +{ +protected: + KviRegisteredUserGroup * m_pGroup; +public: + RegisteredUsersGroupItem(KviRegisteredUsersListView * par,KviRegisteredUserGroup * g) + :RegisteredUsersDialogItemBase(Group,par), m_pGroup(g) + { + setText(0,m_pGroup->name()); + } + ~RegisteredUsersGroupItem() + { + } + KviRegisteredUserGroup * group() { return m_pGroup; }; +}; + +class RegisteredUsersDialogItem : public RegisteredUsersDialogItemBase +{ + friend class RegisteredUsersDialogItemDelegate; +protected: + KviRegisteredUser * m_pUser; + QTextDocument m_pText; +public: + RegisteredUsersDialogItem(QTreeWidgetItem * par,KviRegisteredUser * u); + ~RegisteredUsersDialogItem(); +public: + KviRegisteredUser * user(){ return m_pUser; }; + void setUser(KviRegisteredUser * u){ m_pUser = u; }; + virtual QString key(int,bool) const; +}; + +class RegisteredUsersDialog : public QWidget +{ + Q_OBJECT +public: + RegisteredUsersDialog(QWidget * par = 0); + ~RegisteredUsersDialog(); +public: + KviRegisteredUsersListView * m_pListView; + QPushButton * m_pAddButton; + QPushButton * m_pWizardAddButton; + QPushButton * m_pRemoveButton; + QPushButton * m_pEditButton; + QPushButton * m_pImportButton; + QPushButton * m_pExportButton; + QPushButton * m_pAddGroupButton; + QPushButton * m_pSelectAllButton; + QMultiHash m_TmpDict; +protected: + void fillList(); + void editItem(RegisteredUsersDialogItem * i); + void editGroup(KviRegisteredUserGroup* group); + virtual void closeEvent(QCloseEvent *); +protected slots: + void cancelClicked(); + void okClicked(); + void addClicked(); + void removeClicked(); + void editClicked(); + void selectionChanged(); + void importClicked(); + void exportClicked(); + void addWizardClicked(); + void addGroupClicked(); + void selectAllClicked(); + void itemPressed(QTreeWidgetItem *it,int c); + void itemDoubleClicked(QTreeWidgetItem *it, int); + void rightButtonPressed ( QTreeWidgetItem *, QPoint); + void moveToGroupMenuClicked(int); +}; + +#endif diff --git a/src/modules/reguser/dialog.cpp b/src/modules/reguser/dialog.cpp deleted file mode 100644 index 0cf185aea..000000000 --- a/src/modules/reguser/dialog.cpp +++ /dev/null @@ -1,933 +0,0 @@ -//============================================================================= -// -// File : RegisteredUserEntryDialog.cpp -// Creation date : Tue Dec 26 2000 12:24:12 CEST by Szymon Stefanek -// -// This file is part of the KVIrc irc client distribution -// Copyright (C) 2000-2010 Szymon Stefanek (pragma at kvirc dot net) -// -// This program is FREE software. You can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your opinion) any later version. -// -// This program is distributed in the HOPE that it will be USEFUL, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -// See the GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, write to the Free Software Foundation, -// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -//============================================================================= - -#define _WANT_OPTION_FLAGS_ - -#include "RegisteredUserEntryDialog.h" -#include "RegistrationWizard.h" -#include "dialog.h" - -#include "KviRegisteredUserDataBase.h" -#include "KviLocale.h" -#include "KviIrcMask.h" -#include "kvi_debug.h" -#include "KviMainWindow.h" -#include "KviIconManager.h" -#include "KviApplication.h" -#include "KviOptions.h" -#include "KviFile.h" -#include "KviFileDialog.h" -#include "KviMessageBox.h" -#include "KviFileUtils.h" -#include "kvi_settings.h" -#include "KviStringConversion.h" -#include "KviOptions.h" -#include "KviPointerHashTable.h" -#include "KviTalHBox.h" -#include "KviTalVBox.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#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) - - -extern RegisteredUsersDialog * g_pRegisteredUsersDialog; - -KviRegisteredUsersListView::KviRegisteredUsersListView(QWidget * par) -: QTreeWidget(par) -{ - setColumnCount(2); - - QStringList labels; - labels << __tr2qs_ctx("Name","register") << __tr2qs_ctx("Flags","register"); - setHeaderLabels(labels); - setColumnWidth(0,360); - setColumnWidth(1,20); - - setAllColumnsShowFocus(true); - - setSelectionBehavior(QAbstractItemView::SelectRows); - setSelectionMode(QAbstractItemView::ExtendedSelection); - setRootIsDecorated(TRUE); - setSortingEnabled(true); - - setToolTip(__tr2qs_ctx("
This is the list of registered users. " \ - "KVIrc can automatically recognize and associate properties to them.
" \ - "Use the buttons on the right to add, edit and remove entries. " \ - "The \"notify\" column allows you to quickly add users to the notify list. " \ - "Notify list fine-tuning can be performed by editing the entry properties.
","register")); -} - -void KviRegisteredUsersListView::mousePressEvent (QMouseEvent *e) -{ - if (e->button() == Qt::RightButton) - { - QTreeWidgetItem *i= itemAt(e->pos()); - if (i) emit rightButtonPressed(i,QCursor::pos()); - } - QTreeWidget::mousePressEvent(e); -} - -RegisteredUsersDialogItem::RegisteredUsersDialogItem(QTreeWidgetItem * par,KviRegisteredUser * u) -: RegisteredUsersDialogItemBase(User,par), m_pUser(u) -{ - QString szTmp; - QString t = ""; - t += u->name(); - t += " ["; - szTmp = m_pUser->getProperty("notify"); - if(szTmp.isEmpty()) - { - t += __tr2qs_ctx("Notify disabled","register"); - } else { - t += __tr2qs_ctx("Notify as:","register"); - t += " "; - t += szTmp; - - } - t += "]"; - t += "
"; - szTmp = m_pUser->getProperty("comment"); - if(szTmp.isEmpty()) - { - t += __tr2qs_ctx("No comment set","register"); - } else { - t += __tr2qs_ctx("Comment:","register"); - t += " "; - t += m_pUser->getProperty("comment"); - } - t += ""; - m_pText.setHtml(t); - m_pText.setTextWidth(-1); -// setText(0,t); -} - -RegisteredUsersDialogItem::~RegisteredUsersDialogItem() -{ -} - -QString RegisteredUsersDialogItem::key(int,bool) const -{ - return m_pUser->name(); -} - -void RegisteredUsersDialogItemDelegate::paint( QPainter * p, const QStyleOptionViewItem & option, const QModelIndex & index ) const -{ - - RegisteredUsersDialogItemBase *item=static_cast(index.internalPointer()); - - if(item->type()==RegisteredUsersDialogItemBase::Group) - { - //groups - QStyledItemDelegate::paint(p, option, index); - } else { - QStyleOptionViewItemV4 opt = option; - initStyleOption(&opt, index); - - if (opt.state & QStyle::State_Selected) - QApplication::style()->drawPrimitive(QStyle::PE_PanelItemViewItem,&opt, p); - - RegisteredUsersDialogItem *it=(RegisteredUsersDialogItem*)item; - - if(index.column()==0) - { - QPoint pt=opt.rect.topLeft(); - pt.setX(pt.x()+LVI_BORDER); - pt.setY(pt.y()+LVI_BORDER); - - p->drawPixmap(pt, *(g_pIconManager->getBigIcon(KVI_BIGICON_REGUSERS))); - QRect cliprect=QRect(QPoint(0,0),QSize(opt.rect.width()-(LVI_ICON_SIZE+LVI_SPACING+LVI_BORDER),opt.rect.height())); - p->save(); - - p->translate(opt.rect.x()+LVI_ICON_SIZE+LVI_SPACING, opt.rect.y()); - it->m_pText.drawContents(p, cliprect); - p->restore(); - } else { - if(it->user()) - { - if(!it->user()->getProperty("notify").isEmpty()) - p->drawPixmap(opt.rect.topLeft().x()+LVI_BORDER,opt.rect.topLeft().y()+LVI_BORDER,*(g_pIconManager->getSmallIcon(KviIconManager::NotifyOnLine))); - else - p->drawPixmap(opt.rect.topLeft().x()+LVI_BORDER,opt.rect.topLeft().y()+LVI_BORDER,*(g_pIconManager->getSmallIcon(KviIconManager::NotifyOffLine))); - if(it->user()->ignoreEnagled()) - p->drawPixmap(opt.rect.topLeft().x()+LVI_BORDER,opt.rect.topLeft().y()+2*LVI_BORDER+16,*(g_pIconManager->getSmallIcon(KviIconManager::Ignore))); - } - } - } -} - -QSize RegisteredUsersDialogItemDelegate::sizeHint( const QStyleOptionViewItem & option, const QModelIndex & index ) const -{ - RegisteredUsersDialogItemBase *item=static_cast(index.internalPointer()); - - if(item->type()==RegisteredUsersDialogItemBase::Group) - { - //groups - return QStyledItemDelegate::sizeHint(option, index); - } else { - //users -// RegisteredUsersDialogItem *it=(RegisteredUsersDialogItem*)item; - - return QSize(300, LVI_ICON_SIZE+2*LVI_BORDER); - } -} - -RegisteredUsersDialog::RegisteredUsersDialog(QWidget * par) -: QWidget(par) -{ - g_pRegisteredUsersDialog = this; - - g_pLocalRegisteredUserDataBase = new KviRegisteredUserDataBase(); - g_pLocalRegisteredUserDataBase->copyFrom(g_pRegisteredUserDataBase); - - setWindowIcon(*(g_pIconManager->getSmallIcon(KviIconManager::RegUsers))); - setWindowTitle(__tr2qs_ctx("Registered Users - KVIrc","register")); - - QGridLayout * g = new QGridLayout(this); - - - m_pListView = new KviRegisteredUsersListView(this); - m_pListView->setItemDelegate(new RegisteredUsersDialogItemDelegate()); - - connect(m_pListView,SIGNAL(itemPressed(QTreeWidgetItem *,int)),this,SLOT(itemPressed(QTreeWidgetItem *,int))); - connect(m_pListView,SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)),this,SLOT(itemDoubleClicked(QTreeWidgetItem *, int))); - - g->addWidget(m_pListView,0,0,2,2); - - KviTalVBox * vbox = new KviTalVBox(this); - vbox->setSpacing(4); - g->addWidget(vbox,0,2); - - m_pWizardAddButton = new QPushButton(__tr2qs_ctx("Add (Wizard)...","register"),vbox); - connect(m_pWizardAddButton,SIGNAL(clicked()),this,SLOT(addWizardClicked())); - m_pWizardAddButton->setToolTip(__tr2qs_ctx("Add a registered user by means of a user-friendly wizard.","register")); - m_pWizardAddButton->setIcon(*(g_pIconManager->getSmallIcon(KviIconManager::NewItemByWizard))); - - - m_pAddButton = new QPushButton(__tr2qs_ctx("&Add...","register"),vbox); - connect(m_pAddButton,SIGNAL(clicked()),this,SLOT(addClicked())); - m_pAddButton->setToolTip(__tr2qs_ctx("Open the edit dialog to create a new user entry.","register")); - m_pAddButton->setIcon(*(g_pIconManager->getSmallIcon(KviIconManager::NewItem))); - - m_pAddGroupButton = new QPushButton(__tr2qs_ctx("&Add Group...","register"),vbox); - connect(m_pAddGroupButton,SIGNAL(clicked()),this,SLOT(addGroupClicked())); - m_pAddGroupButton->setToolTip(__tr2qs_ctx("Adds a new group","register")); - m_pAddGroupButton->setIcon(*(g_pIconManager->getSmallIcon(KviIconManager::NewItem))); - - m_pRemoveButton = new QPushButton(__tr2qs_ctx("Re&move","register"),vbox); - connect(m_pRemoveButton,SIGNAL(clicked()),this,SLOT(removeClicked())); - m_pRemoveButton->setEnabled(false); - m_pRemoveButton->setToolTip(__tr2qs_ctx("Remove the currently selected entries.","register")); - m_pRemoveButton->setIcon(*(g_pIconManager->getSmallIcon(KviIconManager::DeleteItem))); - - - m_pEditButton = new QPushButton(__tr2qs_ctx("&Edit...","register"),vbox); - connect(m_pEditButton,SIGNAL(clicked()),this,SLOT(editClicked())); - m_pEditButton->setEnabled(false); - m_pEditButton->setToolTip(__tr2qs_ctx("Edit the first selected entry.","register")); - m_pEditButton->setIcon(*(g_pIconManager->getSmallIcon(KviIconManager::EditItem))); - - QFrame * f = new QFrame(vbox); - f->setFrameStyle(QFrame::HLine | QFrame::Sunken); - - m_pSelectAllButton = new QPushButton(__tr2qs_ctx("Select all","register"),vbox); - connect(m_pSelectAllButton,SIGNAL(clicked()),this,SLOT(selectAllClicked())); - m_pSelectAllButton->setToolTip(__tr2qs_ctx("Select all the entries","register")); - m_pSelectAllButton->setIcon(*(g_pIconManager->getSmallIcon(KviIconManager::Plus))); - - m_pExportButton = new QPushButton(__tr2qs_ctx("Export To...","register"),vbox); - m_pExportButton->setEnabled(false); - connect(m_pExportButton,SIGNAL(clicked()),this,SLOT(exportClicked())); - m_pExportButton->setToolTip(__tr2qs_ctx("Export the selected entries to a file.
All the data associated with the selected registered users will be exported.
You (or anyone else) can later import the entries by using the \"Import\" button.","register")); - m_pExportButton->setIcon(*(g_pIconManager->getSmallIcon(KviIconManager::Floppy))); - - - m_pImportButton = new QPushButton(__tr2qs_ctx("Import From...","register"),vbox); - connect(m_pImportButton,SIGNAL(clicked()),this,SLOT(importClicked())); - m_pImportButton->setToolTip(__tr2qs_ctx("Import entries from a file exported earlier by the \"export\" function of this dialog.","register")); - m_pImportButton->setIcon(*(g_pIconManager->getSmallIcon(KviIconManager::Folder))); - - - KviTalHBox * hbox = new KviTalHBox(this); - hbox->setSpacing(4); - g->addWidget(hbox,3,1,1,2); - - QPushButton * b; - - - b = new QPushButton(__tr2qs_ctx("&OK","register"),hbox); - connect(b,SIGNAL(clicked()),this,SLOT(okClicked())); - b->setIcon(*(g_pIconManager->getSmallIcon(KviIconManager::Accept))); - //b->setMinimumWidth(120); - - b = new QPushButton(__tr2qs_ctx("Cancel","register"),hbox); - connect(b,SIGNAL(clicked()),this,SLOT(cancelClicked())); - b->setIcon(*(g_pIconManager->getSmallIcon(KviIconManager::Discard))); - //b->setMinimumWidth(120); - - g->addItem(new QSpacerItem(0, 15), 2, 0); - g->setColumnStretch(0,1); - g->setRowStretch(1,1); - - connect(m_pListView,SIGNAL(itemSelectionChanged()),this,SLOT(selectionChanged())); - connect(m_pListView,SIGNAL(rightButtonPressed(QTreeWidgetItem *, QPoint)),this,SLOT(rightButtonPressed(QTreeWidgetItem *, QPoint))); - - fillList(); - - if(!parent()) - { - if(KVI_OPTION_RECT(KviOption_rectRegisteredUsersDialogGeometry).y() < 5) - KVI_OPTION_RECT(KviOption_rectRegisteredUsersDialogGeometry).setY(5); - - //setGeometry(KVI_OPTION_RECT(KviOption_rectRegisteredUsersDialogGeometry)); - resize(KVI_OPTION_RECT(KviOption_rectRegisteredUsersDialogGeometry).width(), - KVI_OPTION_RECT(KviOption_rectRegisteredUsersDialogGeometry).height()); - - QRect rect = g_pApp->desktop()->screenGeometry(g_pMainWindow); - move(rect.x() + ((rect.width() - KVI_OPTION_RECT(KviOption_rectRegisteredUsersDialogGeometry).width())/2),rect.y() + ((rect.height() - KVI_OPTION_RECT(KviOption_rectRegisteredUsersDialogGeometry).height())/2)); - - } -} - -RegisteredUsersDialog::~RegisteredUsersDialog() -{ -#ifndef COMPILE_ON_MAC - if(!parent())KVI_OPTION_RECT(KviOption_rectRegisteredUsersDialogGeometry) = QRect(pos().x(),pos().y(),size().width(),size().height()); -#else - if(!parent())KVI_OPTION_RECT(KviOption_rectRegisteredUsersDialogGeometry) = geometry(); -#endif - - g_pRegisteredUsersDialog = 0; - - delete g_pLocalRegisteredUserDataBase; - g_pLocalRegisteredUserDataBase = 0; -} - -void RegisteredUsersDialog::itemPressed(QTreeWidgetItem *it,int c) -{ - if(!it)return; - RegisteredUsersDialogItemBase* b=(RegisteredUsersDialogItemBase*)it; - if(b->type()==RegisteredUsersDialogItemBase::User) - { - RegisteredUsersDialogItem *i = (RegisteredUsersDialogItem *)it; - - QRect r = m_pListView->visualItemRect(i); - int daw = m_pListView->columnWidth(0); - - QPoint ppp = m_pListView->mapFromGlobal(QCursor::pos()); - - if((c == 1) && (ppp.x() < (r.height() + 5 + daw))) - { - // notify list toggle - if(i->user()->getProperty("notify").isEmpty()) - { - // try to find the nicknames to be notified - QString szMask; - - for(KviIrcMask * m = i->user()->maskList()->first();m;m = i->user()->maskList()->next()) - { - QString tmp = m->nick(); - if((tmp.indexOf('*') == -1) && (tmp.indexOf('?') == -1) && (!tmp.isEmpty())) - { - if(!szMask.isEmpty())szMask.append(' '); - szMask.append(tmp); - } - } - // if the nickname list is still empty, build a dummy nick to notify - if(szMask.isEmpty()) - { - szMask = i->user()->name(); - szMask.replace(" ",""); - szMask.replace("'",""); - szMask.replace("&",""); - szMask.replace(",",""); - } - - i->user()->setProperty("notify",szMask); - } else { - i->user()->setProperty("notify",QString("")); // kill that - } - - m_pListView->repaint(r); - } - } -} - -void RegisteredUsersDialog::itemDoubleClicked(QTreeWidgetItem *it, int) -{ - if(!it)return; - RegisteredUsersDialogItemBase* b=(RegisteredUsersDialogItemBase*)it; - if(b->type()==RegisteredUsersDialogItemBase::User) - { - editItem((RegisteredUsersDialogItem *)it); - } else { - RegisteredUsersGroupItem *i = (RegisteredUsersGroupItem *)b; - editGroup(i->group()); - } -} - -void RegisteredUsersDialog::addGroupClicked() -{ - bool ok; - QString text = QInputDialog::getText( this, - "KVIrc", __tr2qs_ctx("Group name:","register"), QLineEdit::Normal, - QString(), &ok ); - if ( ok && !text.isEmpty() ) { - g_pLocalRegisteredUserDataBase->addGroup(text); - fillList(); - } -} - -void RegisteredUsersDialog::editGroup(KviRegisteredUserGroup* group) -{ - bool ok; - - QString text = QInputDialog::getText( this, - "KVIrc", __tr2qs_ctx("Group name:","register"), QLineEdit::Normal, - group->name(), &ok ); - if ( ok && !text.isEmpty() ) { - QString szOldGroup=group->name(); - g_pLocalRegisteredUserDataBase->groupDict()->setAutoDelete(0); - g_pLocalRegisteredUserDataBase->groupDict()->remove(szOldGroup); - g_pLocalRegisteredUserDataBase->groupDict()->setAutoDelete(1); - group->setName(text); - g_pLocalRegisteredUserDataBase->groupDict()->insert(text,group); - - KviPointerHashTable * d = g_pLocalRegisteredUserDataBase->userDict(); - - for(KviRegisteredUser * u = d->first();u;u = d->next()) - { - if(u->group()==szOldGroup) - u->setGroup(text); - } - - fillList(); - - // select the last edited item - for(int c=0;ctopLevelItemCount();c++) - { - QTreeWidgetItem * pGroup = m_pListView->topLevelItem(c); - if(KviQString::equalCI(pGroup->text(0),text)) - { - pGroup->setSelected(true); - m_pListView->setCurrentItem(pGroup); - break; - } - } - } -} - - -void RegisteredUsersDialog::rightButtonPressed ( QTreeWidgetItem * pItem, QPoint pnt) -{ - if(pItem) - { - RegisteredUsersDialogItemBase* b=(RegisteredUsersDialogItemBase*)pItem; - if(b->type()==RegisteredUsersDialogItemBase::User) - { - KviTalPopupMenu *groups = new KviTalPopupMenu; - - KviPointerHashTable * pGroups = g_pLocalRegisteredUserDataBase->groupDict(); - m_TmpDict.clear(); - for(KviPointerHashTableEntry * g = pGroups->firstEntry();g;g = pGroups->nextEntry()) - { - int id=groups->insertItem(g->key()); - m_TmpDict.replace(id,g->data()); - } - - connect(groups,SIGNAL(activated ( int )),this,SLOT(moveToGroupMenuClicked(int))); - - KviTalPopupMenu *mainPopup = new KviTalPopupMenu; - mainPopup->insertItem(__tr2qs_ctx("Move to group","register"),groups); - mainPopup->exec(pnt); - } - } -} - -void RegisteredUsersDialog::moveToGroupMenuClicked(int id) -{ - QString szGroup=(*(m_TmpDict.find(id)))->name(); - QList list = m_pListView->selectedItems(); - for(int i=0; itype()==RegisteredUsersDialogItemBase::User) - { - ((RegisteredUsersDialogItem *)list.at(i))->user()->setGroup(szGroup); - } - } - fillList(); -} - -void RegisteredUsersDialog::fillList() -{ - m_pListView->clear(); - KviPointerHashTable groupItems(5,false); - groupItems.setAutoDelete(false); - - KviPointerHashTable * pGroups = g_pLocalRegisteredUserDataBase->groupDict(); - for(KviRegisteredUserGroup * g = pGroups->first();g;g = pGroups->next()) - { - RegisteredUsersGroupItem* pCur = new RegisteredUsersGroupItem(m_pListView,g); - groupItems.insert(g->name(),pCur); - pCur->setExpanded(TRUE); - } - - KviPointerHashTable * d = g_pLocalRegisteredUserDataBase->userDict(); - RegisteredUsersDialogItem * item; - - for(KviRegisteredUser * u = d->first();u;u = d->next()) - { - if(u->group().isEmpty()) - u->setGroup(__tr2qs_ctx("Default","register")); - if(groupItems.find(u->group())) - item = new RegisteredUsersDialogItem(groupItems.find(u->group()),u); - else if(groupItems.find(__tr2qs_ctx("Default","register"))) - item = new RegisteredUsersDialogItem(groupItems.find(__tr2qs_ctx("Default","register")),u); - else { //should never be called - KviRegisteredUserGroup* pGroup = g_pLocalRegisteredUserDataBase->addGroup(__tr2qs_ctx("Default","register")); - RegisteredUsersGroupItem* pCur = new RegisteredUsersGroupItem(m_pListView,pGroup); - groupItems.insert(__tr2qs_ctx("Default","register"),pCur); - item = new RegisteredUsersDialogItem(pCur,u); - } - } - if(m_pListView->topLevelItem(0)) - { - m_pListView->topLevelItem(0)->setSelected(true); - m_pListView->setCurrentItem(m_pListView->topLevelItem(0)); - } -} - -void RegisteredUsersDialog::closeEvent(QCloseEvent *e) -{ - m_pListView->clear(); - e->accept(); - okClicked(); - //delete this; -} - -void RegisteredUsersDialog::okClicked() -{ - m_pListView->clear(); - g_pRegisteredUserDataBase->copyFrom(g_pLocalRegisteredUserDataBase); - g_pApp->restartNotifyLists(); - delete this; -} - -void RegisteredUsersDialog::cancelClicked() -{ - m_pListView->clear(); - delete this; -} - -void RegisteredUsersDialog::addClicked() -{ - RegisteredUserEntryDialog * dlg = new RegisteredUserEntryDialog(this,0); - int ret = dlg->exec(); - delete dlg; - - if(!g_pRegisteredUsersDialog)return; // we have been deleted! - - if(ret == QDialog::Accepted) - { - fillList(); - } -} - -void RegisteredUsersDialog::addWizardClicked() -{ - RegistrationWizard * w = new RegistrationWizard("",g_pLocalRegisteredUserDataBase,this,true); - int ret = w->exec(); - delete w; - if(!g_pRegisteredUsersDialog)return; // we have been deleted! - if(ret == QDialog::Accepted) - { - fillList(); - } -} - -void RegisteredUsersDialog::removeClicked() -{ - QList list = m_pListView->selectedItems(); - for(int i=0; itype()==RegisteredUsersDialogItemBase::User) - { - g_pLocalRegisteredUserDataBase->removeUser(((RegisteredUsersDialogItem *)list.at(i))->user()->name()); - } else { - g_pLocalRegisteredUserDataBase->removeGroup(((RegisteredUsersGroupItem *)list.at(i))->group()->name()); - } - } - fillList(); -// RegisteredUsersDialogItem *it = (RegisteredUsersDialogItem *)m_pListView->firstChild(); -// RegisteredUsersDialogItemBase* b=(RegisteredUsersDialogItemBase*)it; -// if(b->type()==RegisteredUsersDialogItemBase::User) -// { -// KviPointerList l; -// l.setAutoDelete(false); -// while(it) -// { -// if(it->isSelected())l.append(it); -// it = (RegisteredUsersDialogItem *)it->nextSibling(); -// } -// -// for(RegisteredUsersDialogItem * i = l.first();i;i = l.next()) -// { -// //g_pLocalRegisteredUserDataBase->removeUser(i->user()->name()); -// delete i; -// } -// } else { -// -// } -} - -void RegisteredUsersDialog::editClicked() -{ - RegisteredUsersDialogItemBase* b=(RegisteredUsersDialogItemBase*)(m_pListView->currentItem()); - if(!b)return; - if(b->type()==RegisteredUsersDialogItemBase::User) - { - RegisteredUsersDialogItem *i = (RegisteredUsersDialogItem *)b; - editItem(i); - } else { - RegisteredUsersGroupItem *i = (RegisteredUsersGroupItem *)b; - editGroup(i->group()); - } -} - -void RegisteredUsersDialog::editItem(RegisteredUsersDialogItem * i) -{ - KviRegisteredUser * u = i->user(); - - i->setUser(0); - - QString szName = u->name(); - - RegisteredUserEntryDialog * dlg = new RegisteredUserEntryDialog(this,u); - int res = dlg->exec(); - delete dlg; - - if(!g_pRegisteredUsersDialog)return; // we have been deleted! - - if(res == QDialog::Accepted) - { - fillList(); - - // select the last edited item - for(int c=0;ctopLevelItemCount();c++) - { - QTreeWidgetItem * pGroup = m_pListView->topLevelItem(c); - for(int d=0;dchildCount();d++) - { - RegisteredUsersDialogItem * pUser = (RegisteredUsersDialogItem*) pGroup->child(d); - if(KviQString::equalCI(pUser->user()->name(),szName)) - { - pUser->setSelected(true); - m_pListView->setCurrentItem(pUser); - break; - } - } - } - - return; - } - - i->setUser(u); - m_pListView->update(); -} - -void RegisteredUsersDialog::selectionChanged() -{ - bool bHaveSelected = !m_pListView->selectedItems().empty(); - - m_pEditButton->setEnabled(bHaveSelected); - m_pRemoveButton->setEnabled(bHaveSelected); - m_pExportButton->setEnabled(bHaveSelected); -} - - -#define KVI_REGUSER_DB_FILE_MAGIC 0x5334DBDB -#define KVI_REGUSER_DB_FILE_VERSION 1 - -typedef struct _KviReguserDbFileHeader -{ - kvi_u32_t magic; - kvi_u32_t version; - kvi_u32_t nentries; -} KviReguserDbFileHeader; - -void RegisteredUsersDialog::exportClicked() -{ - unsigned int nEntries = 0; - - QList list = m_pListView->selectedItems(); - - //only "user" entries matters, discard groups from count - for(int i=0; itype() == RegisteredUsersDialogItemBase::User) - nEntries++; - } - - if(nEntries < 1) - { - KviMessageBox::warning(__tr2qs_ctx("No entries selected.","register")); - return; - } - - QString buffer; - - if(!KviFileDialog::askForSaveFileName(buffer,__tr2qs_ctx("Choose a Filename - KVIrc","register"),0,0,true,true))return; - - if(!g_pRegisteredUsersDialog)return; // we have been deleted! - - KviFile f(buffer); - if(!f.open(QIODevice::WriteOnly | QIODevice::Truncate)) - { - KviMessageBox::warning(__tr2qs_ctx("Can't open file %Q for writing.","register"),&buffer); - return; - } - - KviReguserDbFileHeader hf; - hf.magic = KVI_REGUSER_DB_FILE_MAGIC; - hf.version = KVI_REGUSER_DB_FILE_VERSION; - hf.nentries = nEntries; - - if(f.write((const char *)&hf,sizeof(KviReguserDbFileHeader)) != sizeof(KviReguserDbFileHeader))goto write_error; - - for(int i=0; itype()!=RegisteredUsersDialogItemBase::User) - continue; - - KviRegisteredUser * u = ((RegisteredUsersDialogItem *)list.at(i))->user(); - if(u) - { - if(!f.save(u->name()))goto write_error; - KviPointerHashTable * pd = u->propertyDict(); - if(pd) - { - if(!f.save(pd->count()))goto write_error; - for(KviPointerHashTableEntry * pCur = pd->firstEntry();pCur;pCur = pd->nextEntry()) - { - QString key = pCur->key(); - if(!f.save(key))goto write_error; - if(!f.save(*(pCur->data())))goto write_error; - } - } else { - if(!f.save(0))goto write_error; - } - - KviPointerList * ml = u->maskList(); - if(ml) - { - if(!f.save(ml->count()))goto write_error; - for(KviIrcMask * m = ml->first();m;m = ml->next()) - { - QString fullMask; - m->mask(fullMask,KviIrcMask::NickUserHost); - if(!f.save(fullMask))goto write_error; - } - } else { - if(!f.save(0))goto write_error; - } - - QString avatar; - if(u->getProperty("avatar",avatar)) - { - KviAvatar * av = g_pIconManager->getAvatar(QString(),avatar); - if(av) - { - if(!av->pixmap()->isNull()) - { - if(!f.save(1))goto write_error; - QImageWriter io; - io.setDevice(&f); - io.setFormat("PNG"); - if(!io.write(av->pixmap()->toImage()))goto write_error; - } else { - if(!f.save(0))goto write_error; - } - } else { - if(!f.save(0))goto write_error; - } - } else { - if(!f.save(0))goto write_error; - } - } - } - - goto succesfull_export; - - -write_error: - KviMessageBox::warning(__tr2qs_ctx("Can't export the registered users database: Write error.","register")); - f.close(); - return; - -succesfull_export: - - f.close(); -} - -void RegisteredUsersDialog::selectAllClicked() -{ - m_pListView->selectAll(); -} - -void RegisteredUsersDialog::importClicked() -{ - //KviCString buffer; - QString buffer; - - if(!KviFileDialog::askForOpenFileName(buffer,__tr2qs_ctx("Choose a Filename - KVIrc","register")))return; - - if(!g_pRegisteredUsersDialog)return; // we have been deleted! - - KviFile f(buffer); - if(!f.open(QIODevice::ReadOnly)) - { - KviMessageBox::warning(__tr2qs_ctx("Can't open file %s for reading.","register"),&buffer); - return; - } - - KviReguserDbFileHeader hf; - unsigned int idx; - - if(f.read((char *)&hf,sizeof(KviReguserDbFileHeader)) != sizeof(KviReguserDbFileHeader))goto read_error; - - if(hf.magic != KVI_REGUSER_DB_FILE_MAGIC) - { - KviMessageBox::warning(__tr2qs_ctx("The file %s doesn't appear to be a valid registered users database.","register"),&buffer); - f.close(); - return; - } - - if(hf.version != KVI_REGUSER_DB_FILE_VERSION) - { - KviMessageBox::warning(__tr2qs_ctx("The file %s contains an invalid registered users database version.","register"),&buffer); - f.close(); - return; - } - - for(idx = 0;idx < hf.nentries;idx++) - { - QString szName; - if(!f.load(szName))goto read_error; - KviRegisteredUser * u = g_pLocalRegisteredUserDataBase->getUser(szName); - if(!u) goto read_error; - unsigned int count = 0; - if(!f.load(count))goto read_error; - for(unsigned int up = 0;up < count;up++) - { - QString szKey,szValue; - if(!f.load(szKey))goto read_error; - if(!f.load(szValue))goto read_error; - u->setProperty(szKey,szValue); - } - if(!f.load(count))goto read_error; - for(unsigned int um = 0;um < count;um++) - { - QString szMask; - if(!f.load(szMask))goto read_error; - if(!szMask.isEmpty()) - { - KviIrcMask * m = new KviIrcMask(szMask); - g_pLocalRegisteredUserDataBase->addMask(u,m); - } - } - if(!f.load(count))goto read_error; - if(count) - { - // there is an avatar - QImage img; - QImageReader io; - io.setDevice(&f); - io.setFormat("PNG"); - img=io.read(); -// if(io.read())goto read_error; - - if(img.isNull())qDebug("Ops.. readed a null image ?"); - - QString fName = u->name(); - KviFileUtils::adjustFilePath(fName); - - QString fPath; - int rnm = 0 ; - do - { - g_pApp->getLocalKvircDirectory(fPath,KviApplication::Avatars,fName); - fPath.append(QString("%1.png").arg(rnm)); - rnm++; - } while(KviFileUtils::fileExists(fPath)); - - if(!img.save(fPath,"PNG")) - { - qDebug("Can't save image %s",fPath.toUtf8().data()); - } else { - u->setProperty("avatar",fPath); - } - } - } - - goto succesfull_import; - - -read_error: - KviMessageBox::warning(__tr2qs_ctx("Can't import the registered users database: Read error.","register")); - f.close(); - return; - -succesfull_import: - - f.close(); - fillList(); -} - - -#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES -#include "dialog.moc" -#endif //!COMPILE_USE_STANDALONE_MOC_SOURCES diff --git a/src/modules/reguser/dialog.h b/src/modules/reguser/dialog.h deleted file mode 100644 index d511560dd..000000000 --- a/src/modules/reguser/dialog.h +++ /dev/null @@ -1,159 +0,0 @@ -#ifndef _DIALOG_H_ -#define _DIALOG_H_ -//============================================================================= -// -// File : RegisteredUserEntryDialog.h -// Creation date : Sun Dec 24 2000 15:16:17 CEST by Szymon Stefanek -// -// This file is part of the KVIrc irc client distribution -// Copyright (C) 2000-2010 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 "KviCString.h" -#include "KviRegisteredUserDataBase.h" -#include "KviSelectors.h" -#include "KviPointerHashTable.h" -#include -#include "KviTalListWidget.h" -#include "KviTalPopupMenu.h" - -#include -#include -#include -#include -#include -#include - -class KviRegisteredUsersListView : public QTreeWidget -{ - Q_OBJECT -public: - KviRegisteredUsersListView(QWidget*); - ~KviRegisteredUsersListView(){}; -protected: - void mousePressEvent (QMouseEvent *e); -signals: - void rightButtonPressed(QTreeWidgetItem *,QPoint); -}; - -class RegisteredUsersDialogItemDelegate : public QStyledItemDelegate -{ -public: - RegisteredUsersDialogItemDelegate(KviRegisteredUsersListView * pWidget=0) - : QStyledItemDelegate(pWidget) {}; - ~RegisteredUsersDialogItemDelegate(){}; - QSize sizeHint(const QStyleOptionViewItem &option,const QModelIndex &index) const; - void paint( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const; - -}; - -class RegisteredUsersDialogItemBase : public QTreeWidgetItem -{ -public: - enum Types { User,Group }; -protected: - RegisteredUsersDialogItemBase(Types type,KviRegisteredUsersListView * par) - :QTreeWidgetItem(par),m_iType(type) - { - }; - RegisteredUsersDialogItemBase(Types type,QTreeWidgetItem * par) - :QTreeWidgetItem(par),m_iType(type) - { - }; - ~RegisteredUsersDialogItemBase() - { - }; - -private: - RegisteredUsersDialogItemBase::Types m_iType; -public: - RegisteredUsersDialogItemBase::Types type() { return m_iType; }; -}; - -class RegisteredUsersGroupItem : public RegisteredUsersDialogItemBase -{ -protected: - KviRegisteredUserGroup * m_pGroup; -public: - RegisteredUsersGroupItem(KviRegisteredUsersListView * par,KviRegisteredUserGroup * g) - :RegisteredUsersDialogItemBase(Group,par), m_pGroup(g) - { - setText(0,m_pGroup->name()); - } - ~RegisteredUsersGroupItem() - { - } - KviRegisteredUserGroup * group() { return m_pGroup; }; -}; - -class RegisteredUsersDialogItem : public RegisteredUsersDialogItemBase -{ - friend class RegisteredUsersDialogItemDelegate; -protected: - KviRegisteredUser * m_pUser; - QTextDocument m_pText; -public: - RegisteredUsersDialogItem(QTreeWidgetItem * par,KviRegisteredUser * u); - ~RegisteredUsersDialogItem(); -public: - KviRegisteredUser * user(){ return m_pUser; }; - void setUser(KviRegisteredUser * u){ m_pUser = u; }; - virtual QString key(int,bool) const; -}; - -class RegisteredUsersDialog : public QWidget -{ - Q_OBJECT -public: - RegisteredUsersDialog(QWidget * par = 0); - ~RegisteredUsersDialog(); -public: - KviRegisteredUsersListView * m_pListView; - QPushButton * m_pAddButton; - QPushButton * m_pWizardAddButton; - QPushButton * m_pRemoveButton; - QPushButton * m_pEditButton; - QPushButton * m_pImportButton; - QPushButton * m_pExportButton; - QPushButton * m_pAddGroupButton; - QPushButton * m_pSelectAllButton; - QMultiHash m_TmpDict; -protected: - void fillList(); - void editItem(RegisteredUsersDialogItem * i); - void editGroup(KviRegisteredUserGroup* group); - virtual void closeEvent(QCloseEvent *); -protected slots: - void cancelClicked(); - void okClicked(); - void addClicked(); - void removeClicked(); - void editClicked(); - void selectionChanged(); - void importClicked(); - void exportClicked(); - void addWizardClicked(); - void addGroupClicked(); - void selectAllClicked(); - void itemPressed(QTreeWidgetItem *it,int c); - void itemDoubleClicked(QTreeWidgetItem *it, int); - void rightButtonPressed ( QTreeWidgetItem *, QPoint); - void moveToGroupMenuClicked(int); -}; - -#endif diff --git a/src/modules/reguser/libkvireguser.cpp b/src/modules/reguser/libkvireguser.cpp index 3986417b0..1263b0471 100644 --- a/src/modules/reguser/libkvireguser.cpp +++ b/src/modules/reguser/libkvireguser.cpp @@ -25,7 +25,7 @@ #include "RegisteredUserEntryDialog.h" #include "RegistrationWizard.h" #include "KviIrcConnection.h" -#include "dialog.h" +#include "RegisteredUsersDialog.h" #include "KviModule.h" #include "KviRegisteredUserDataBase.h" diff --git a/src/modules/theme/CMakeLists.txt b/src/modules/theme/CMakeLists.txt index 600ec61cf..9605b5abe 100644 --- a/src/modules/theme/CMakeLists.txt +++ b/src/modules/theme/CMakeLists.txt @@ -1,14 +1,14 @@ # CMakeLists for src/modules/theme SET(kvitheme_MOC_HDRS - managementdialog.h + ThemeManagementDialog.h PackThemeDialog.h SaveThemeDialog.h ) SET(kvitheme_SRCS libkvitheme.cpp - managementdialog.cpp + ThemeManagementDialog.cpp PackThemeDialog.cpp SaveThemeDialog.cpp ThemeFunctions.cpp diff --git a/src/modules/theme/ThemeManagementDialog.cpp b/src/modules/theme/ThemeManagementDialog.cpp new file mode 100644 index 000000000..182dd64d8 --- /dev/null +++ b/src/modules/theme/ThemeManagementDialog.cpp @@ -0,0 +1,457 @@ +//============================================================================= +// +// File : ThemeManagementDialog.cpp +// Creation date : Sat 30 Dec 2006 14:54:56 by Szymon Stefanek +// +// This file is part of the KVIrc IRC Client distribution +// Copyright (C) 2006-2010 Szymon Stefanek +// +// 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 "ThemeManagementDialog.h" +#include "PackThemeDialog.h" +#include "SaveThemeDialog.h" +#include "ThemeFunctions.h" + +#include "KviOptions.h" +#include "KviLocale.h" +#include "KviConfigurationFile.h" +#include "KviFileUtils.h" +#include "KviApplication.h" +#include "KviMainWindow.h" +#include "KviIconManager.h" +#include "KviInternalCommand.h" +#include "KviPackageReader.h" +#include "kvi_fileextensions.h" +#include "KviFileDialog.h" +#include "KviDynamicToolTip.h" +#include "KviIconManager.h" +#include "KviMessageBox.h" +#include "KviTalPopupMenu.h" +#include "KviTalListWidget.h" + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern QRect g_rectManagementDialogGeometry; + + +ThemeListWidgetItem::ThemeListWidgetItem(KviTalListWidget * box,KviThemeInfo * inf) +: KviTalListWidgetItem(box) +{ + m_pThemeInfo = inf; + QString t; + t = ""; + t += inf->name(); + t += ""; + + if(!inf->version().isEmpty()) { + t += "["; + t += inf->version(); + t += "]"; + } + + if(!inf->author().isEmpty()) { + t += " "; + t += __tr2qs_ctx("by","theme"); + t += " "; + t += inf->author(); + t += ""; + } + + t += ""; + t += "
"; + t += inf->description(); + t += ""; + setText(t); +} + +ThemeListWidgetItem::~ThemeListWidgetItem() +{ + delete m_pThemeInfo; + +} + +ThemeManagementDialog * ThemeManagementDialog::m_pInstance = 0; + + +ThemeManagementDialog::ThemeManagementDialog(QWidget * parent) +: QWidget(parent) +{ + m_pItemDelegate=0; + setObjectName("theme_options_widget"); + setWindowTitle(__tr2qs_ctx("Manage Themes - KVIrc","theme")); + setWindowIcon(*(g_pIconManager->getSmallIcon(KviIconManager::Theme))); + + m_pInstance = this; + + QGridLayout * g = new QGridLayout(this); + + KviTalHBox *hb = new KviTalHBox(this); + hb->setMargin(1); + hb->setSpacing(1); + g->addWidget(hb,0,0); + + QToolButton * tb; + QFrame * sep; + + tb = new QToolButton(hb); + tb->setIcon(*(g_pIconManager->getBigIcon(KVI_BIGICON_SAVE))); + tb->setIconSize(QSize(32,32)); + tb->setToolTip(__tr2qs_ctx("Save Current Theme...","theme")); + connect(tb,SIGNAL(clicked()),this,SLOT(saveCurrentTheme())); + + sep = new QFrame(hb); + sep->setFrameStyle(QFrame::VLine | QFrame::Sunken); + sep->setMinimumWidth(12); + + m_pPackThemeButton = new QToolButton(hb); + m_pPackThemeButton->setIcon(*(g_pIconManager->getBigIcon(KVI_BIGICON_PACK))); + + m_pPackThemeButton->setIconSize(QSize(32,32)); + m_pPackThemeButton->setToolTip(__tr2qs_ctx("Export Selected Themes to a Distributable Package","theme")); + connect(m_pPackThemeButton,SIGNAL(clicked()),this,SLOT(packTheme())); + + m_pDeleteThemeButton = new QToolButton(hb); + m_pDeleteThemeButton->setIcon(*(g_pIconManager->getBigIcon(KVI_BIGICON_REMOVE))); + m_pDeleteThemeButton->setIconSize(QSize(32,32)); + m_pDeleteThemeButton->setToolTip(__tr2qs_ctx("Delete Selected Themes","theme")); + connect(m_pDeleteThemeButton,SIGNAL(clicked()),this,SLOT(deleteTheme())); + + sep = new QFrame(hb); + sep->setFrameStyle(QFrame::VLine | QFrame::Sunken); + sep->setMinimumWidth(12); + + tb = new QToolButton(hb); + tb->setIcon(*(g_pIconManager->getBigIcon(KVI_BIGICON_OPEN))); + tb->setIconSize(QSize(32,32)); + tb->setToolTip(__tr2qs_ctx("Install Theme Package From Disk","theme")); + connect(tb,SIGNAL(clicked()),this,SLOT(installFromFile())); + + tb = new QToolButton(hb); + tb->setIcon(*(g_pIconManager->getBigIcon(KVI_BIGICON_WWW))); + tb->setIconSize(QSize(32,32)); + tb->setToolTip(__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_pListWidget = new KviTalListWidget(this); + m_pListWidget->setContextMenuPolicy(Qt::CustomContextMenu); + m_pItemDelegate = new KviTalIconAndRichTextItemDelegate(m_pListWidget); + m_pItemDelegate->setDefaultIcon(g_pIconManager->getBigIcon(QString(KVI_BIGICON_THEME))); + m_pListWidget->setItemDelegate(m_pItemDelegate); + m_pListWidget->setMinimumHeight(400); + m_pListWidget->setMinimumWidth(400); + + m_pListWidget->setSelectionMode(QAbstractItemView::ExtendedSelection); + m_pListWidget->setSortingEnabled(true); + connect(m_pListWidget,SIGNAL(itemDoubleClicked(QListWidgetItem *)),this,SLOT(applyTheme(QListWidgetItem *))); + + //FIXME tooltip + //connect(m_pListWidget,SIGNAL(tipRequest(QListWidgetItem *,const QPoint &)),this,SLOT(tipRequest(QListWidgetItem *,const QPoint &))); + connect(m_pListWidget,SIGNAL(customContextMenuRequested(const QPoint &)), + this,SLOT(contextMenuRequested(const QPoint &))); + connect(m_pListWidget,SIGNAL(itemSelectionChanged()),this,SLOT(enableDisableButtons())); + g->addWidget(m_pListWidget,1,0); + +// KviDynamicToolTip * tip = new KviDynamicToolTip(m_pListWidget); +// connect(tip,SIGNAL(tipRequest(KviDynamicToolTip *,const QPoint &)),this,SLOT(tipRequest(KviDynamicToolTip *,const QPoint &))); + + QPushButton * b = new QPushButton(__tr2qs("Close"),this); + b->setMaximumSize(b->sizeHint().width(),b->sizeHint().height()); + connect(b,SIGNAL(clicked()),this,SLOT(closeClicked())); + g->addWidget(b,2,0); + + g->setMargin(1); + g->setSpacing(1); + g->setAlignment(b,Qt::AlignRight); + fillThemeBox(); + m_pContextPopup = new KviTalPopupMenu(this); + + if(g_rectManagementDialogGeometry.y() < 5) + { + g_rectManagementDialogGeometry.setY(5); + } + resize(g_rectManagementDialogGeometry.width(), + g_rectManagementDialogGeometry.height()); + + QRect rect = g_pApp->desktop()->screenGeometry(g_pMainWindow); + move(rect.x() + ((rect.width() - g_rectManagementDialogGeometry.width())/2),rect.y() + ((rect.height() - g_rectManagementDialogGeometry.height())/2)); +} + +ThemeManagementDialog::~ThemeManagementDialog() +{ + if (m_pItemDelegate) delete m_pItemDelegate; + g_rectManagementDialogGeometry = QRect(pos().x(),pos().y(),size().width(),size().height()); + m_pInstance = 0; +} + +void ThemeManagementDialog::closeClicked() +{ + delete this; + m_pInstance = 0; +} + +void ThemeManagementDialog::display(bool bTopLevel) +{ + if(m_pInstance) + { + if(bTopLevel) + { + if(m_pInstance->parent()) + { + m_pInstance->setParent(0); + } + } else { + if(m_pInstance->parent() != g_pMainWindow->splitter()) + { + m_pInstance->setParent(g_pMainWindow->splitter()); + } + } + } else { + if(bTopLevel) + { + m_pInstance = new ThemeManagementDialog(0); + } else { + m_pInstance = new ThemeManagementDialog(g_pMainWindow->splitter()); + } + } + m_pInstance->show(); + m_pInstance->raise(); + m_pInstance->setFocus(); +} + +void ThemeManagementDialog::cleanup() +{ + if(!m_pInstance)return; + delete m_pInstance; + m_pInstance = 0; +} + +void ThemeManagementDialog::packTheme() +{ + KviPointerList dl; + dl.setAutoDelete(false); + QList itemsSelected = m_pListWidget->selectedItems (); + for(int i=0;ithemeInfo()); + if(dl.isEmpty())return; + + PackThemeDialog * pDialog = new PackThemeDialog(this,&dl); + pDialog->exec(); + delete pDialog; +} + +void ThemeManagementDialog::contextMenuRequested(const QPoint & pos) +{ + if(m_pListWidget->itemAt(pos)!=0) + { + m_pListWidget->setCurrentItem(m_pListWidget->itemAt(pos)); + m_pContextPopup->clear(); + m_pContextPopup->insertItem(*(g_pIconManager->getSmallIcon(KviIconManager::Minus)),__tr2qs_ctx("&Remove Theme","theme"),this,SLOT(deleteTheme())); + m_pContextPopup->insertItem(*(g_pIconManager->getSmallIcon(KviIconManager::Accept)),__tr2qs_ctx("&Apply Theme","theme"),this,SLOT(applyCurrentTheme())); + m_pContextPopup->popup(m_pListWidget->viewport()->mapToGlobal(pos)); + } +} + +void ThemeManagementDialog::applyTheme ( QListWidgetItem * it) +{ + if(it)m_pListWidget->setCurrentItem(it); + applyCurrentTheme(); +} + +void ThemeManagementDialog::applyCurrentTheme() +{ + ThemeListWidgetItem * it = (ThemeListWidgetItem *)m_pListWidget->currentItem(); + if(!it)return; + + if(KviMessageBox::yesNo(__tr2qs_ctx("Apply theme - KVIrc","theme"), + __tr2qs_ctx("Do you wish to apply theme \"%Q\" (version %Q)?","theme"), + &(it->themeInfo()->name()),&(it->themeInfo()->version()))) + { + QString szPath = it->themeInfo()->absoluteDirectory(); + if(szPath.isEmpty())return; + + KviThemeInfo out; + if(!KviTheme::load(szPath,out)) + { + QString szErr = out.lastError(); + QString szMsg = QString(__tr2qs_ctx("Failed to apply the specified theme: %1","theme")).arg(szErr); + QMessageBox::critical(this,__tr2qs_ctx("Apply theme - KVIrc","theme"),szMsg, + QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton); + + } + m_pItemDelegate->setDefaultIcon(g_pIconManager->getBigIcon(QString(KVI_BIGICON_THEME))); + } +} + +void ThemeManagementDialog::deleteTheme() +{ + QList itemsSelected = m_pListWidget->selectedItems (); + for(int i=0;ithemeInfo()->name()),&(((ThemeListWidgetItem *)itemsSelected.at(i))->themeInfo()->version())))goto jump_out; + KviFileUtils::deleteDir(((ThemeListWidgetItem *)itemsSelected.at(i))->themeInfo()->absoluteDirectory()); + } +jump_out: + fillThemeBox(); +} + +void ThemeManagementDialog::installFromFile() +{ + QString szFileName; + QString szError; + + if(!KviFileDialog::askForOpenFileName(szFileName,__tr2qs_ctx("Open Theme - KVIrc","theme"),QString(),KVI_FILTER_THEME)) + return; + if(!ThemeFunctions::installThemePackage(szFileName,szError,this)) + { + KviMessageBox::information(szError); + return; + } + fillThemeBox(); +} + +void ThemeManagementDialog::getMoreThemes() +{ + if(!g_pMainWindow)return; + g_pMainWindow->executeInternalCommand(KVI_INTERNALCOMMAND_OPENURL_KVIRC_THEMES); +} + +void ThemeManagementDialog::saveCurrentTheme() +{ + SaveThemeDialog * pSaveThemeDialog = new SaveThemeDialog(this); + pSaveThemeDialog->exec(); + delete pSaveThemeDialog; + fillThemeBox(); +} + +void ThemeManagementDialog::fillThemeBox(const QString &szDir) +{ + QDir d(szDir); + + QStringList sl = d.entryList(QDir::Dirs); + + for(QStringList::Iterator it = sl.begin();it != sl.end();++it) + { + if(*it == ".")continue; + if(*it == "..")continue; + + QString szTest = szDir; + szTest += KVI_PATH_SEPARATOR_CHAR; + szTest += *it; + + KviThemeInfo * inf = new KviThemeInfo(); + if(inf->loadFromDirectory(szTest)) + { + inf->setSubdirectory(*it); + new ThemeListWidgetItem(m_pListWidget,inf); + } else { + delete inf; + } + } +} + +void ThemeManagementDialog::fillThemeBox() +{ + m_pListWidget->clear(); + + QString szDir; + g_pApp->getGlobalKvircDirectory(szDir,KviApplication::Themes); + fillThemeBox(szDir); + g_pApp->getLocalKvircDirectory(szDir,KviApplication::Themes); + fillThemeBox(szDir); + + enableDisableButtons(); +} + +bool ThemeManagementDialog::hasSelectedItems() +{ + QList itemsSelected = m_pListWidget->selectedItems (); + return itemsSelected.count()?true:false; + +} + +void ThemeManagementDialog::enableDisableButtons() +{ + bool b = hasSelectedItems(); + m_pPackThemeButton->setEnabled(b); + m_pDeleteThemeButton->setEnabled(b); +} + +void ThemeManagementDialog::closeEvent(QCloseEvent * e) +{ + e->ignore(); + delete this; +} + +void ThemeManagementDialog::tipRequest(QListWidgetItem *,const QPoint &) +{ + // FIXME + /* + //ThemeListWidgetItem * it = (ThemeListWidgetItem *)(m_pListWidget->itemAt(pnt)); + + //if(!it)return; + + KviThemeInfo * pThemeInfo = ((ThemeListWidgetItem *)it)->themeInfo(); + + QString szThemeDescription; + + ThemeFunctions::getThemeHtmlDescription( + szThemeDescription, + pThemeInfo->name(), + pThemeInfo->version(), + pThemeInfo->description(), + pThemeInfo->subdirectory(), + pThemeInfo->application(), + pThemeInfo->author(), + pThemeInfo->date(), + pThemeInfo->themeEngineVersion(), + pThemeInfo->mediumScreenshot(), + 0 + ); + QLabel *wid=new QLabel(0); + wid->setWindowFlags(Qt::Popup); + wid->setText("Prova del tooltip"); + wid->move(pnt); + wid->show(); +// pTip->tip(m_pListWidget->visualItemRect(it),szThemeDescription); +*/ +} + diff --git a/src/modules/theme/ThemeManagementDialog.h b/src/modules/theme/ThemeManagementDialog.h new file mode 100644 index 000000000..5c6d46de8 --- /dev/null +++ b/src/modules/theme/ThemeManagementDialog.h @@ -0,0 +1,97 @@ +#ifndef _MANAGEMENTDIALOG_H_ +#define _MANAGEMENTDIALOG_H_ +//============================================================================= +// +// File : ThemeManagementDialog.h +// Creation date : Sat 30 Dec 2006 14:54:56 by Szymon Stefanek +// +// This file is part of the KVIrc IRC Client distribution +// Copyright (C) 2006-2010 Szymon Stefanek +// +// 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 "KviOptionsWidget.h" +#include "KviPointerList.h" +#include "KviTheme.h" +#include "KviTalPopupMenu.h" +#include "KviTalWizard.h" +#include "KviTalListWidget.h" + +#include +#include +#include +#include +#include +#include +#include + +class QLineEdit; +class QPushButton; +class QLabel; +class KviDynamicToolTip; + + +class ThemeListWidgetItem : public KviTalListWidgetItem +{ +public: + ThemeListWidgetItem(KviTalListWidget * box,KviThemeInfo * inf); + virtual ~ThemeListWidgetItem(); +public: + KviThemeInfo * m_pThemeInfo; +public: + KviThemeInfo * themeInfo(){ return m_pThemeInfo; }; +}; + + +class ThemeManagementDialog : public QWidget +{ + Q_OBJECT +public: + ThemeManagementDialog(QWidget * parent); + virtual ~ThemeManagementDialog(); +protected: + static ThemeManagementDialog * m_pInstance; + KviTalIconAndRichTextItemDelegate * m_pItemDelegate; + KviTalListWidget * m_pListWidget; + KviTalPopupMenu * m_pContextPopup; + QToolButton * m_pDeleteThemeButton; + QToolButton * m_pPackThemeButton; +public: + static ThemeManagementDialog * instance(){ return m_pInstance; }; + static void display(bool bTopLevel); + static void cleanup(); +protected: + void fillThemeBox(const QString &szDir); + bool hasSelectedItems(); + virtual void closeEvent(QCloseEvent * e); +protected slots: + void saveCurrentTheme(); + void getMoreThemes(); + void installFromFile(); + void fillThemeBox(); + void deleteTheme(); + void closeClicked(); + void packTheme(); + void applyTheme(QListWidgetItem *); + void applyCurrentTheme(); + void enableDisableButtons(); + void contextMenuRequested(const QPoint & pos); + //void tipRequest(KviDynamicToolTip *pTip,const QPoint &pnt); + void tipRequest(QListWidgetItem *item,const QPoint &pnt); +}; + +#endif //!_MANAGEMENTDIALOG_H_ diff --git a/src/modules/theme/libkvitheme.cpp b/src/modules/theme/libkvitheme.cpp index 3019deb37..86425b9a7 100644 --- a/src/modules/theme/libkvitheme.cpp +++ b/src/modules/theme/libkvitheme.cpp @@ -22,7 +22,7 @@ // //============================================================================= -#include "managementdialog.h" +#include "ThemeManagementDialog.h" #include "ThemeFunctions.h" #include "KviMessageBox.h" diff --git a/src/modules/theme/managementdialog.cpp b/src/modules/theme/managementdialog.cpp deleted file mode 100644 index 0aa1a4d15..000000000 --- a/src/modules/theme/managementdialog.cpp +++ /dev/null @@ -1,457 +0,0 @@ -//============================================================================= -// -// File : managementdialog.cpp -// Creation date : Sat 30 Dec 2006 14:54:56 by Szymon Stefanek -// -// This file is part of the KVIrc IRC Client distribution -// Copyright (C) 2006-2010 Szymon Stefanek -// -// 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 "managementdialog.h" -#include "PackThemeDialog.h" -#include "SaveThemeDialog.h" -#include "ThemeFunctions.h" - -#include "KviOptions.h" -#include "KviLocale.h" -#include "KviConfigurationFile.h" -#include "KviFileUtils.h" -#include "KviApplication.h" -#include "KviMainWindow.h" -#include "KviIconManager.h" -#include "KviInternalCommand.h" -#include "KviPackageReader.h" -#include "kvi_fileextensions.h" -#include "KviFileDialog.h" -#include "KviDynamicToolTip.h" -#include "KviIconManager.h" -#include "KviMessageBox.h" -#include "KviTalPopupMenu.h" -#include "KviTalListWidget.h" - - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -extern QRect g_rectManagementDialogGeometry; - - -ThemeListWidgetItem::ThemeListWidgetItem(KviTalListWidget * box,KviThemeInfo * inf) -: KviTalListWidgetItem(box) -{ - m_pThemeInfo = inf; - QString t; - t = ""; - t += inf->name(); - t += ""; - - if(!inf->version().isEmpty()) { - t += "["; - t += inf->version(); - t += "]"; - } - - if(!inf->author().isEmpty()) { - t += " "; - t += __tr2qs_ctx("by","theme"); - t += " "; - t += inf->author(); - t += ""; - } - - t += ""; - t += "
"; - t += inf->description(); - t += ""; - setText(t); -} - -ThemeListWidgetItem::~ThemeListWidgetItem() -{ - delete m_pThemeInfo; - -} - -ThemeManagementDialog * ThemeManagementDialog::m_pInstance = 0; - - -ThemeManagementDialog::ThemeManagementDialog(QWidget * parent) -: QWidget(parent) -{ - m_pItemDelegate=0; - setObjectName("theme_options_widget"); - setWindowTitle(__tr2qs_ctx("Manage Themes - KVIrc","theme")); - setWindowIcon(*(g_pIconManager->getSmallIcon(KviIconManager::Theme))); - - m_pInstance = this; - - QGridLayout * g = new QGridLayout(this); - - KviTalHBox *hb = new KviTalHBox(this); - hb->setMargin(1); - hb->setSpacing(1); - g->addWidget(hb,0,0); - - QToolButton * tb; - QFrame * sep; - - tb = new QToolButton(hb); - tb->setIcon(*(g_pIconManager->getBigIcon(KVI_BIGICON_SAVE))); - tb->setIconSize(QSize(32,32)); - tb->setToolTip(__tr2qs_ctx("Save Current Theme...","theme")); - connect(tb,SIGNAL(clicked()),this,SLOT(saveCurrentTheme())); - - sep = new QFrame(hb); - sep->setFrameStyle(QFrame::VLine | QFrame::Sunken); - sep->setMinimumWidth(12); - - m_pPackThemeButton = new QToolButton(hb); - m_pPackThemeButton->setIcon(*(g_pIconManager->getBigIcon(KVI_BIGICON_PACK))); - - m_pPackThemeButton->setIconSize(QSize(32,32)); - m_pPackThemeButton->setToolTip(__tr2qs_ctx("Export Selected Themes to a Distributable Package","theme")); - connect(m_pPackThemeButton,SIGNAL(clicked()),this,SLOT(packTheme())); - - m_pDeleteThemeButton = new QToolButton(hb); - m_pDeleteThemeButton->setIcon(*(g_pIconManager->getBigIcon(KVI_BIGICON_REMOVE))); - m_pDeleteThemeButton->setIconSize(QSize(32,32)); - m_pDeleteThemeButton->setToolTip(__tr2qs_ctx("Delete Selected Themes","theme")); - connect(m_pDeleteThemeButton,SIGNAL(clicked()),this,SLOT(deleteTheme())); - - sep = new QFrame(hb); - sep->setFrameStyle(QFrame::VLine | QFrame::Sunken); - sep->setMinimumWidth(12); - - tb = new QToolButton(hb); - tb->setIcon(*(g_pIconManager->getBigIcon(KVI_BIGICON_OPEN))); - tb->setIconSize(QSize(32,32)); - tb->setToolTip(__tr2qs_ctx("Install Theme Package From Disk","theme")); - connect(tb,SIGNAL(clicked()),this,SLOT(installFromFile())); - - tb = new QToolButton(hb); - tb->setIcon(*(g_pIconManager->getBigIcon(KVI_BIGICON_WWW))); - tb->setIconSize(QSize(32,32)); - tb->setToolTip(__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_pListWidget = new KviTalListWidget(this); - m_pListWidget->setContextMenuPolicy(Qt::CustomContextMenu); - m_pItemDelegate = new KviTalIconAndRichTextItemDelegate(m_pListWidget); - m_pItemDelegate->setDefaultIcon(g_pIconManager->getBigIcon(QString(KVI_BIGICON_THEME))); - m_pListWidget->setItemDelegate(m_pItemDelegate); - m_pListWidget->setMinimumHeight(400); - m_pListWidget->setMinimumWidth(400); - - m_pListWidget->setSelectionMode(QAbstractItemView::ExtendedSelection); - m_pListWidget->setSortingEnabled(true); - connect(m_pListWidget,SIGNAL(itemDoubleClicked(QListWidgetItem *)),this,SLOT(applyTheme(QListWidgetItem *))); - - //FIXME tooltip - //connect(m_pListWidget,SIGNAL(tipRequest(QListWidgetItem *,const QPoint &)),this,SLOT(tipRequest(QListWidgetItem *,const QPoint &))); - connect(m_pListWidget,SIGNAL(customContextMenuRequested(const QPoint &)), - this,SLOT(contextMenuRequested(const QPoint &))); - connect(m_pListWidget,SIGNAL(itemSelectionChanged()),this,SLOT(enableDisableButtons())); - g->addWidget(m_pListWidget,1,0); - -// KviDynamicToolTip * tip = new KviDynamicToolTip(m_pListWidget); -// connect(tip,SIGNAL(tipRequest(KviDynamicToolTip *,const QPoint &)),this,SLOT(tipRequest(KviDynamicToolTip *,const QPoint &))); - - QPushButton * b = new QPushButton(__tr2qs("Close"),this); - b->setMaximumSize(b->sizeHint().width(),b->sizeHint().height()); - connect(b,SIGNAL(clicked()),this,SLOT(closeClicked())); - g->addWidget(b,2,0); - - g->setMargin(1); - g->setSpacing(1); - g->setAlignment(b,Qt::AlignRight); - fillThemeBox(); - m_pContextPopup = new KviTalPopupMenu(this); - - if(g_rectManagementDialogGeometry.y() < 5) - { - g_rectManagementDialogGeometry.setY(5); - } - resize(g_rectManagementDialogGeometry.width(), - g_rectManagementDialogGeometry.height()); - - QRect rect = g_pApp->desktop()->screenGeometry(g_pMainWindow); - move(rect.x() + ((rect.width() - g_rectManagementDialogGeometry.width())/2),rect.y() + ((rect.height() - g_rectManagementDialogGeometry.height())/2)); -} - -ThemeManagementDialog::~ThemeManagementDialog() -{ - if (m_pItemDelegate) delete m_pItemDelegate; - g_rectManagementDialogGeometry = QRect(pos().x(),pos().y(),size().width(),size().height()); - m_pInstance = 0; -} - -void ThemeManagementDialog::closeClicked() -{ - delete this; - m_pInstance = 0; -} - -void ThemeManagementDialog::display(bool bTopLevel) -{ - if(m_pInstance) - { - if(bTopLevel) - { - if(m_pInstance->parent()) - { - m_pInstance->setParent(0); - } - } else { - if(m_pInstance->parent() != g_pMainWindow->splitter()) - { - m_pInstance->setParent(g_pMainWindow->splitter()); - } - } - } else { - if(bTopLevel) - { - m_pInstance = new ThemeManagementDialog(0); - } else { - m_pInstance = new ThemeManagementDialog(g_pMainWindow->splitter()); - } - } - m_pInstance->show(); - m_pInstance->raise(); - m_pInstance->setFocus(); -} - -void ThemeManagementDialog::cleanup() -{ - if(!m_pInstance)return; - delete m_pInstance; - m_pInstance = 0; -} - -void ThemeManagementDialog::packTheme() -{ - KviPointerList dl; - dl.setAutoDelete(false); - QList itemsSelected = m_pListWidget->selectedItems (); - for(int i=0;ithemeInfo()); - if(dl.isEmpty())return; - - PackThemeDialog * pDialog = new PackThemeDialog(this,&dl); - pDialog->exec(); - delete pDialog; -} - -void ThemeManagementDialog::contextMenuRequested(const QPoint & pos) -{ - if(m_pListWidget->itemAt(pos)!=0) - { - m_pListWidget->setCurrentItem(m_pListWidget->itemAt(pos)); - m_pContextPopup->clear(); - m_pContextPopup->insertItem(*(g_pIconManager->getSmallIcon(KviIconManager::Minus)),__tr2qs_ctx("&Remove Theme","theme"),this,SLOT(deleteTheme())); - m_pContextPopup->insertItem(*(g_pIconManager->getSmallIcon(KviIconManager::Accept)),__tr2qs_ctx("&Apply Theme","theme"),this,SLOT(applyCurrentTheme())); - m_pContextPopup->popup(m_pListWidget->viewport()->mapToGlobal(pos)); - } -} - -void ThemeManagementDialog::applyTheme ( QListWidgetItem * it) -{ - if(it)m_pListWidget->setCurrentItem(it); - applyCurrentTheme(); -} - -void ThemeManagementDialog::applyCurrentTheme() -{ - ThemeListWidgetItem * it = (ThemeListWidgetItem *)m_pListWidget->currentItem(); - if(!it)return; - - if(KviMessageBox::yesNo(__tr2qs_ctx("Apply theme - KVIrc","theme"), - __tr2qs_ctx("Do you wish to apply theme \"%Q\" (version %Q)?","theme"), - &(it->themeInfo()->name()),&(it->themeInfo()->version()))) - { - QString szPath = it->themeInfo()->absoluteDirectory(); - if(szPath.isEmpty())return; - - KviThemeInfo out; - if(!KviTheme::load(szPath,out)) - { - QString szErr = out.lastError(); - QString szMsg = QString(__tr2qs_ctx("Failed to apply the specified theme: %1","theme")).arg(szErr); - QMessageBox::critical(this,__tr2qs_ctx("Apply theme - KVIrc","theme"),szMsg, - QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton); - - } - m_pItemDelegate->setDefaultIcon(g_pIconManager->getBigIcon(QString(KVI_BIGICON_THEME))); - } -} - -void ThemeManagementDialog::deleteTheme() -{ - QList itemsSelected = m_pListWidget->selectedItems (); - for(int i=0;ithemeInfo()->name()),&(((ThemeListWidgetItem *)itemsSelected.at(i))->themeInfo()->version())))goto jump_out; - KviFileUtils::deleteDir(((ThemeListWidgetItem *)itemsSelected.at(i))->themeInfo()->absoluteDirectory()); - } -jump_out: - fillThemeBox(); -} - -void ThemeManagementDialog::installFromFile() -{ - QString szFileName; - QString szError; - - if(!KviFileDialog::askForOpenFileName(szFileName,__tr2qs_ctx("Open Theme - KVIrc","theme"),QString(),KVI_FILTER_THEME)) - return; - if(!ThemeFunctions::installThemePackage(szFileName,szError,this)) - { - KviMessageBox::information(szError); - return; - } - fillThemeBox(); -} - -void ThemeManagementDialog::getMoreThemes() -{ - if(!g_pMainWindow)return; - g_pMainWindow->executeInternalCommand(KVI_INTERNALCOMMAND_OPENURL_KVIRC_THEMES); -} - -void ThemeManagementDialog::saveCurrentTheme() -{ - SaveThemeDialog * pSaveThemeDialog = new SaveThemeDialog(this); - pSaveThemeDialog->exec(); - delete pSaveThemeDialog; - fillThemeBox(); -} - -void ThemeManagementDialog::fillThemeBox(const QString &szDir) -{ - QDir d(szDir); - - QStringList sl = d.entryList(QDir::Dirs); - - for(QStringList::Iterator it = sl.begin();it != sl.end();++it) - { - if(*it == ".")continue; - if(*it == "..")continue; - - QString szTest = szDir; - szTest += KVI_PATH_SEPARATOR_CHAR; - szTest += *it; - - KviThemeInfo * inf = new KviThemeInfo(); - if(inf->loadFromDirectory(szTest)) - { - inf->setSubdirectory(*it); - new ThemeListWidgetItem(m_pListWidget,inf); - } else { - delete inf; - } - } -} - -void ThemeManagementDialog::fillThemeBox() -{ - m_pListWidget->clear(); - - QString szDir; - g_pApp->getGlobalKvircDirectory(szDir,KviApplication::Themes); - fillThemeBox(szDir); - g_pApp->getLocalKvircDirectory(szDir,KviApplication::Themes); - fillThemeBox(szDir); - - enableDisableButtons(); -} - -bool ThemeManagementDialog::hasSelectedItems() -{ - QList itemsSelected = m_pListWidget->selectedItems (); - return itemsSelected.count()?true:false; - -} - -void ThemeManagementDialog::enableDisableButtons() -{ - bool b = hasSelectedItems(); - m_pPackThemeButton->setEnabled(b); - m_pDeleteThemeButton->setEnabled(b); -} - -void ThemeManagementDialog::closeEvent(QCloseEvent * e) -{ - e->ignore(); - delete this; -} - -void ThemeManagementDialog::tipRequest(QListWidgetItem *,const QPoint &) -{ - // FIXME - /* - //ThemeListWidgetItem * it = (ThemeListWidgetItem *)(m_pListWidget->itemAt(pnt)); - - //if(!it)return; - - KviThemeInfo * pThemeInfo = ((ThemeListWidgetItem *)it)->themeInfo(); - - QString szThemeDescription; - - ThemeFunctions::getThemeHtmlDescription( - szThemeDescription, - pThemeInfo->name(), - pThemeInfo->version(), - pThemeInfo->description(), - pThemeInfo->subdirectory(), - pThemeInfo->application(), - pThemeInfo->author(), - pThemeInfo->date(), - pThemeInfo->themeEngineVersion(), - pThemeInfo->mediumScreenshot(), - 0 - ); - QLabel *wid=new QLabel(0); - wid->setWindowFlags(Qt::Popup); - wid->setText("Prova del tooltip"); - wid->move(pnt); - wid->show(); -// pTip->tip(m_pListWidget->visualItemRect(it),szThemeDescription); -*/ -} - diff --git a/src/modules/theme/managementdialog.h b/src/modules/theme/managementdialog.h deleted file mode 100644 index beed4ade9..000000000 --- a/src/modules/theme/managementdialog.h +++ /dev/null @@ -1,97 +0,0 @@ -#ifndef _MANAGEMENTDIALOG_H_ -#define _MANAGEMENTDIALOG_H_ -//============================================================================= -// -// File : managementdialog.h -// Creation date : Sat 30 Dec 2006 14:54:56 by Szymon Stefanek -// -// This file is part of the KVIrc IRC Client distribution -// Copyright (C) 2006-2010 Szymon Stefanek -// -// 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 "KviOptionsWidget.h" -#include "KviPointerList.h" -#include "KviTheme.h" -#include "KviTalPopupMenu.h" -#include "KviTalWizard.h" -#include "KviTalListWidget.h" - -#include -#include -#include -#include -#include -#include -#include - -class QLineEdit; -class QPushButton; -class QLabel; -class KviDynamicToolTip; - - -class ThemeListWidgetItem : public KviTalListWidgetItem -{ -public: - ThemeListWidgetItem(KviTalListWidget * box,KviThemeInfo * inf); - virtual ~ThemeListWidgetItem(); -public: - KviThemeInfo * m_pThemeInfo; -public: - KviThemeInfo * themeInfo(){ return m_pThemeInfo; }; -}; - - -class ThemeManagementDialog : public QWidget -{ - Q_OBJECT -public: - ThemeManagementDialog(QWidget * parent); - virtual ~ThemeManagementDialog(); -protected: - static ThemeManagementDialog * m_pInstance; - KviTalIconAndRichTextItemDelegate * m_pItemDelegate; - KviTalListWidget * m_pListWidget; - KviTalPopupMenu * m_pContextPopup; - QToolButton * m_pDeleteThemeButton; - QToolButton * m_pPackThemeButton; -public: - static ThemeManagementDialog * instance(){ return m_pInstance; }; - static void display(bool bTopLevel); - static void cleanup(); -protected: - void fillThemeBox(const QString &szDir); - bool hasSelectedItems(); - virtual void closeEvent(QCloseEvent * e); -protected slots: - void saveCurrentTheme(); - void getMoreThemes(); - void installFromFile(); - void fillThemeBox(); - void deleteTheme(); - void closeClicked(); - void packTheme(); - void applyTheme(QListWidgetItem *); - void applyCurrentTheme(); - void enableDisableButtons(); - void contextMenuRequested(const QPoint & pos); - //void tipRequest(KviDynamicToolTip *pTip,const QPoint &pnt); - void tipRequest(QListWidgetItem *item,const QPoint &pnt); -}; - -#endif //!_MANAGEMENTDIALOG_H_ -- cgit v1.3.1-10-gc9f91