diff --git a/libretroshare/src/plugins/pluginmanager.cc b/libretroshare/src/plugins/pluginmanager.cc index 157f3c599..8c0366693 100644 --- a/libretroshare/src/plugins/pluginmanager.cc +++ b/libretroshare/src/plugins/pluginmanager.cc @@ -36,6 +36,7 @@ RsPluginHandler *rsPlugins ; RsPluginManager::RsPluginManager() : p3Config(CONFIG_TYPE_PLUGINS) { + _allow_all_plugins = false ; } void RsPluginManager::loadConfiguration() @@ -145,10 +146,20 @@ void RsPluginManager::getPluginStatus(int i,uint32_t& status,std::string& file_n file_name = _plugins[i].file_name ; } +bool RsPluginManager::getAllowAllPlugins() const +{ + return _allow_all_plugins ; +} +void RsPluginManager::allowAllPlugins(bool b) +{ + _allow_all_plugins = b ; + IndicateConfigChanged() ; +} RsSerialiser *RsPluginManager::setupSerialiser() { RsSerialiser *rss = new RsSerialiser ; - rss->addSerialType(new RsPluginSerialiser()) ; + rss->addSerialType(new RsPluginSerialiser()) ; + rss->addSerialType(new RsGeneralConfigSerialiser()) ; return rss ; } @@ -203,7 +214,7 @@ bool RsPluginManager::loadPlugin(const std::string& plugin_name) std::cerr << " -> hash = " << pinfo.file_hash << std::endl; - if(_accepted_hashes.find(pinfo.file_hash) == _accepted_hashes.end()) + if((!_allow_all_plugins) && _accepted_hashes.find(pinfo.file_hash) == _accepted_hashes.end()) { std::cerr << " -> hash is not in white list. Plugin is rejected. Go to config->plugins to authorise this plugin." << std::endl; pinfo.status = PLUGIN_STATUS_UNKNOWN_HASH ; @@ -342,7 +353,19 @@ bool RsPluginManager::loadList(std::list& list) _accepted_hashes.insert(*it) ; std::cerr << " loaded hash " << *it << std::endl; } - + + RsConfigKeyValueSet *witem = dynamic_cast(*it) ; + + if(witem) + { + for(std::list::const_iterator kit = witem->tlvkvs.pairs.begin(); kit != witem->tlvkvs.pairs.end(); ++kit) + if((*kit).key == "ALLOW_ALL_PLUGINS") + { + std::cerr << "WARNING: Allowing all plugins. No hash will be checked. Be careful! " << std::endl ; + _allow_all_plugins = (kit->value == "YES"); + } + } + delete (*it); } return true; @@ -359,6 +382,14 @@ bool RsPluginManager::saveList(bool& cleanup, std::list& list) list.push_back(vitem) ; + RsConfigKeyValueSet *witem = new RsConfigKeyValueSet ; + RsTlvKeyValue kv; + kv.key = "ALLOW_ALL_PLUGINS" ; + kv.value = _allow_all_plugins?"YES":"NO" ; + witem->tlvkvs.pairs.push_back(kv) ; + + list.push_back(witem) ; + return true; } diff --git a/libretroshare/src/plugins/pluginmanager.h b/libretroshare/src/plugins/pluginmanager.h index b3da878cb..8d9cf922a 100644 --- a/libretroshare/src/plugins/pluginmanager.h +++ b/libretroshare/src/plugins/pluginmanager.h @@ -40,6 +40,9 @@ class RsPluginManager: public RsPluginHandler, public p3Config virtual ftServer *getFileServer() const ; virtual p3LinkMgr *getLinkMgr() const ; + virtual void allowAllPlugins(bool b) ; + virtual bool getAllowAllPlugins() const ; + // ---------------- Derived from p3Config -------------------// // bool saveList(bool& cleanup, std::list& list) ; @@ -84,6 +87,7 @@ class RsPluginManager: public RsPluginHandler, public p3Config std::vector _plugins ; std::set _accepted_hashes ; + bool _allow_all_plugins ; static std::string _plugin_entry_symbol ; static std::string _remote_cache_dir ; diff --git a/libretroshare/src/retroshare/rsplugin.h b/libretroshare/src/retroshare/rsplugin.h index 331a946ce..59fc115e7 100644 --- a/libretroshare/src/retroshare/rsplugin.h +++ b/libretroshare/src/retroshare/rsplugin.h @@ -45,6 +45,7 @@ class QTranslator; class QApplication; class RsCacheService ; class ftServer ; +class ConfigPage ; class pqiService ; // Used for the status of plugins. @@ -83,6 +84,8 @@ class RsPlugin virtual MainPage *qt_page() const { return NULL ; } virtual QWidget *qt_config_panel() const { return NULL ; } virtual QIcon *qt_icon() const { return NULL ; } + virtual ConfigPage *qt_config_page() const { return NULL ; } + virtual QTranslator *qt_translator(QApplication * /* app */, const QString& /* languageCode */ ) const { return NULL ; } virtual std::string configurationFileName() const { return std::string() ; } @@ -105,6 +108,9 @@ class RsPluginHandler virtual void enablePlugin(const std::string& hash) = 0; virtual void disablePlugin(const std::string& hash) = 0; + virtual void allowAllPlugins(bool b) = 0 ; + virtual bool getAllowAllPlugins() const = 0 ; + virtual void slowTickPlugins(time_t sec) = 0 ; virtual const std::string& getLocalCacheDir() const =0; diff --git a/retroshare-gui/src/RetroShare.pro b/retroshare-gui/src/RetroShare.pro index b69502e70..168420e3b 100644 --- a/retroshare-gui/src/RetroShare.pro +++ b/retroshare-gui/src/RetroShare.pro @@ -202,6 +202,7 @@ INCLUDEPATH += ../../libretroshare/src/ # Input HEADERS += rshare.h \ + retroshare-gui/configpage.h \ gui/notifyqt.h \ control/bandwidthevent.h \ control/eventtype.h \ @@ -302,7 +303,6 @@ HEADERS += rshare.h \ gui/settings/RsharePeerSettings.h \ gui/settings/rsettings.h \ gui/settings/rsettingswin.h \ - gui/settings/configpage.h \ gui/settings/GeneralPage.h \ gui/settings/DirectoriesPage.h \ gui/settings/ServerPage.h \ @@ -596,7 +596,6 @@ SOURCES += main.cpp \ gui/common/LinkTextBrowser.cpp \ gui/style/RSStyle.cpp \ gui/style/StyleDialog.cpp \ - gui/settings/configpage.cpp \ gui/settings/rsharesettings.cpp \ gui/settings/RsharePeerSettings.cpp \ gui/settings/rsettings.cpp \ diff --git a/retroshare-gui/src/gui/settings/AppearancePage.h b/retroshare-gui/src/gui/settings/AppearancePage.h index 195750922..7e6115e01 100755 --- a/retroshare-gui/src/gui/settings/AppearancePage.h +++ b/retroshare-gui/src/gui/settings/AppearancePage.h @@ -22,7 +22,7 @@ #ifndef _APPERARANCEPAGE_H #define _APPERARANCEPAGE_H -#include "configpage.h" +#include #include "ui_AppearancePage.h" class AppearancePage : public ConfigPage @@ -36,9 +36,13 @@ class AppearancePage : public ConfigPage ~AppearancePage(); /** Saves the changes on this page */ - bool save(QString &errmsg); + virtual bool save(QString &errmsg); /** Loads the settings for this page */ - void load(); + virtual void load(); + + virtual QPixmap iconPixmap() const { return QPixmap(":/images/looknfeel.png") ; } + virtual QString pageName() const { return tr("Appearance") ; } + private slots: diff --git a/retroshare-gui/src/gui/settings/ChatPage.h b/retroshare-gui/src/gui/settings/ChatPage.h index 3704ed389..6b76ba716 100644 --- a/retroshare-gui/src/gui/settings/ChatPage.h +++ b/retroshare-gui/src/gui/settings/ChatPage.h @@ -22,7 +22,7 @@ #ifndef _CHATPAGE_H #define _CHATPAGE_H -#include "configpage.h" +#include #include "ui_ChatPage.h" class ChatPage : public ConfigPage @@ -36,9 +36,12 @@ class ChatPage : public ConfigPage ~ChatPage() {} /** Saves the changes on this page */ - bool save(QString &errmsg); + virtual bool save(QString &errmsg); /** Loads the settings for this page */ - void load(); + virtual void load(); + + virtual QPixmap iconPixmap() const { return QPixmap(":/images/chat_24.png") ; } + virtual QString pageName() const { return tr("Chat") ; } private slots: void on_historyComboBoxVariant_currentIndexChanged(int index); diff --git a/retroshare-gui/src/gui/settings/CryptoPage.h b/retroshare-gui/src/gui/settings/CryptoPage.h index d146466c2..0f1994269 100755 --- a/retroshare-gui/src/gui/settings/CryptoPage.h +++ b/retroshare-gui/src/gui/settings/CryptoPage.h @@ -22,7 +22,7 @@ #ifndef _CRYPTOPAGE_H #define _CRYPTOPAGE_H -#include "configpage.h" +#include #include "ui_CryptoPage.h" class CryptoPage : public ConfigPage @@ -36,11 +36,14 @@ class CryptoPage : public ConfigPage ~CryptoPage(); /** Saves the changes on this page */ - bool save(QString &errmsg); + virtual bool save(QString &errmsg); /** Loads the settings for this page */ + virtual QPixmap iconPixmap() const { return QPixmap(":/images/encrypted32.png") ; } + virtual QString pageName() const { return tr("Security") ; } + private slots: - void load(); + virtual void load(); void copyPublicKey(); void copyRSLink() ; diff --git a/retroshare-gui/src/gui/settings/DirectoriesPage.h b/retroshare-gui/src/gui/settings/DirectoriesPage.h index 3f035c836..e59213c6c 100755 --- a/retroshare-gui/src/gui/settings/DirectoriesPage.h +++ b/retroshare-gui/src/gui/settings/DirectoriesPage.h @@ -22,7 +22,7 @@ #ifndef DIRECTORIESPAGE_H #define DIRECTORIESPAGE_H -#include "configpage.h" +#include #include "ui_DirectoriesPage.h" class DirectoriesPage: public ConfigPage @@ -33,9 +33,12 @@ public: DirectoriesPage(QWidget * parent = 0, Qt::WFlags flags = 0); /** Saves the changes on this page */ - bool save(QString &errmsg); + virtual bool save(QString &errmsg); /** Loads the settings for this page */ - void load(); + virtual void load(); + + virtual QPixmap iconPixmap() const { return QPixmap(":/images/folder_doments.png") ; } + virtual QString pageName() const { return tr("Directories") ; } private slots: void editDirectories() ; diff --git a/retroshare-gui/src/gui/settings/FileAssociationsPage.h b/retroshare-gui/src/gui/settings/FileAssociationsPage.h index bc51cd13c..168a0acb5 100755 --- a/retroshare-gui/src/gui/settings/FileAssociationsPage.h +++ b/retroshare-gui/src/gui/settings/FileAssociationsPage.h @@ -22,7 +22,7 @@ #ifndef __FileAssociationsPage__ #define __FileAssociationsPage__ -#include "configpage.h" +#include class QToolBar; class QAction; @@ -51,8 +51,10 @@ public: FileAssociationsPage(QWidget * parent = 0, Qt::WFlags flags = 0); virtual ~FileAssociationsPage(); - void load(); - bool save (QString &errmsg); + virtual void load(); + virtual bool save (QString &errmsg); + virtual QPixmap iconPixmap() const { return QPixmap(":/images/filetype-association.png") ; } + virtual QString pageName() const { return tr("Associations") ; } protected: QToolBar* toolBar; diff --git a/retroshare-gui/src/gui/settings/ForumPage.h b/retroshare-gui/src/gui/settings/ForumPage.h index c381e5601..50b4d7102 100644 --- a/retroshare-gui/src/gui/settings/ForumPage.h +++ b/retroshare-gui/src/gui/settings/ForumPage.h @@ -22,7 +22,7 @@ #ifndef FORUMPAGE_H #define FORUMPAGE_H -#include "configpage.h" +#include #include "ui_ForumPage.h" class ForumPage : public ConfigPage @@ -34,9 +34,12 @@ public: ~ForumPage(); /** Saves the changes on this page */ - bool save(QString &errmsg); + virtual bool save(QString &errmsg); /** Loads the settings for this page */ - void load(); + virtual void load(); + + virtual QPixmap iconPixmap() const { return QPixmap(":/images/konversation.png") ; } + virtual QString pageName() const { return tr("Forum") ; } private: Ui::ForumPage ui; diff --git a/retroshare-gui/src/gui/settings/GeneralPage.h b/retroshare-gui/src/gui/settings/GeneralPage.h index dc4bc2f21..28826abad 100755 --- a/retroshare-gui/src/gui/settings/GeneralPage.h +++ b/retroshare-gui/src/gui/settings/GeneralPage.h @@ -23,7 +23,7 @@ #ifndef _GENERALPAGE_H #define _GENERALPAGE_H -#include "configpage.h" +#include #include "ui_GeneralPage.h" class GeneralPage : public ConfigPage @@ -37,9 +37,12 @@ public: ~GeneralPage(); /** Saves the changes on this page */ - bool save(QString &errmsg); + virtual bool save(QString &errmsg); /** Loads the settings for this page */ - void load(); + virtual void load(); + + virtual QPixmap iconPixmap() const { return QPixmap(":/images/kcmsystem24.png") ; } + virtual QString pageName() const { return tr("General") ; } private: /** Qt Designer generated object */ diff --git a/retroshare-gui/src/gui/settings/MessagePage.h b/retroshare-gui/src/gui/settings/MessagePage.h index 662cb4660..57996c990 100644 --- a/retroshare-gui/src/gui/settings/MessagePage.h +++ b/retroshare-gui/src/gui/settings/MessagePage.h @@ -24,7 +24,7 @@ #include -#include "configpage.h" +#include #include "ui_MessagePage.h" class MsgTagType; @@ -38,9 +38,13 @@ public: ~MessagePage(); /** Saves the changes on this page */ - bool save(QString &errmsg); + virtual bool save(QString &errmsg); /** Loads the settings for this page */ - void load(); + virtual void load(); + + virtual QPixmap iconPixmap() const { return QPixmap(":/images/evolution.png") ; } + virtual QString pageName() const { return tr("Message") ; } + private slots: void addTag(); diff --git a/retroshare-gui/src/gui/settings/NetworkPage.h b/retroshare-gui/src/gui/settings/NetworkPage.h index 2702ddbc3..36b08af29 100755 --- a/retroshare-gui/src/gui/settings/NetworkPage.h +++ b/retroshare-gui/src/gui/settings/NetworkPage.h @@ -22,7 +22,7 @@ #ifndef NETWORKPAGE_H #define NETWORKPAGE_H -#include "configpage.h" +#include #include "ui_NetworkPage.h" class NetworkPage : public ConfigPage @@ -32,9 +32,12 @@ public: ~NetworkPage() {} /** Saves the changes on this page */ - bool save(QString &errmsg); + virtual bool save(QString &errmsg); /** Loads the settings for this page */ - void load(); + virtual void load(); + + virtual QPixmap iconPixmap() const { return QPixmap(":/images/server_24x24.png") ; } + virtual QString pageName() const { return tr("Network") ; } private: Ui::NetworkPage ui; diff --git a/retroshare-gui/src/gui/settings/NotifyPage.h b/retroshare-gui/src/gui/settings/NotifyPage.h index b7e3f78ca..4081b8c3d 100755 --- a/retroshare-gui/src/gui/settings/NotifyPage.h +++ b/retroshare-gui/src/gui/settings/NotifyPage.h @@ -22,7 +22,7 @@ #ifndef NOTIFYPAGE_H #define NOTIFYPAGE_H -#include "configpage.h" +#include #include "ui_NotifyPage.h" class NotifyPage : public ConfigPage @@ -36,9 +36,12 @@ public: ~NotifyPage(); /** Saves the changes on this page */ - bool save(QString &errmsg); + virtual bool save(QString &errmsg); /** Loads the settings for this page */ - void load(); + virtual void load(); + + virtual QPixmap iconPixmap() const { return QPixmap(":/images/status_unknown.png") ; } + virtual QString pageName() const { return tr("Notify") ; } private slots: void privatChatToggled(); diff --git a/retroshare-gui/src/gui/settings/PluginsPage.cpp b/retroshare-gui/src/gui/settings/PluginsPage.cpp index 8794f1b5c..80b5306d4 100644 --- a/retroshare-gui/src/gui/settings/PluginsPage.cpp +++ b/retroshare-gui/src/gui/settings/PluginsPage.cpp @@ -95,6 +95,9 @@ PluginsPage::PluginsPage(QWidget * parent, Qt::WFlags flags) if(plugin != NULL) item->_enabled_CB->setChecked(true) ; + if(rsPlugins->getAllowAllPlugins()) + item->_enabled_CB->setEnabled(false) ; + QObject::connect(item,SIGNAL(pluginEnabled(bool,const QString&)),this,SLOT(togglePlugin(bool,const QString&))) ; QObject::connect(item,SIGNAL(pluginConfigure(int)),this,SLOT(configurePlugin(int))) ; } @@ -109,7 +112,15 @@ PluginsPage::PluginsPage(QWidget * parent, Qt::WFlags flags) ui._lookupDirectories_TB->setHtml(text) ; // todo + ui.enableAll->setChecked(rsPlugins->getAllowAllPlugins()); + ui.enableAll->setToolTip(tr("Check this for developing plugins. They will not\nbe checked for the hash. However, in normal\ntimes, checking the hash protects you from\nmalicious behavior of crafted plugins.")); ui.enableAll->setEnabled(false); + + QObject::connect(ui.enableAll,SIGNAL(toggled(bool)),this,SLOT(toggleEnableAll(bool))) ; +} +void PluginsPage::toggleEnableAll(bool b) +{ + rsPlugins->allowAllPlugins(b) ; } void PluginsPage::configurePlugin(int i) { diff --git a/retroshare-gui/src/gui/settings/PluginsPage.h b/retroshare-gui/src/gui/settings/PluginsPage.h index faee8f0d7..da50ead21 100644 --- a/retroshare-gui/src/gui/settings/PluginsPage.h +++ b/retroshare-gui/src/gui/settings/PluginsPage.h @@ -21,7 +21,7 @@ #pragma once -#include "configpage.h" +#include #include "ui_PluginsPage.h" class PluginsPage : public ConfigPage @@ -33,13 +33,18 @@ class PluginsPage : public ConfigPage ~PluginsPage(); /** Saves the changes on this page */ - bool save(QString &errmsg); + virtual bool save(QString &errmsg); /** Loads the settings for this page */ - void load(); + virtual void load(); + + virtual QPixmap iconPixmap() const { return QPixmap(":/images/extension_32.png") ; } + virtual QString pageName() const { return tr("Plugins") ; } + public slots: void togglePlugin(bool b,const QString&) ; void configurePlugin(int i) ; + void toggleEnableAll(bool) ; private: Ui::PluginsPage ui; diff --git a/retroshare-gui/src/gui/settings/RelayPage.h b/retroshare-gui/src/gui/settings/RelayPage.h index 9bce561b3..09a9b7855 100644 --- a/retroshare-gui/src/gui/settings/RelayPage.h +++ b/retroshare-gui/src/gui/settings/RelayPage.h @@ -24,7 +24,7 @@ # include -#include "configpage.h" +#include #include "ui_RelayPage.h" class RelayPage: public ConfigPage @@ -40,6 +40,9 @@ class RelayPage: public ConfigPage /** Loads the settings for this page */ virtual void load(); + virtual QPixmap iconPixmap() const { return QPixmap(":/images/server_24x24.png") ; } + virtual QString pageName() const { return tr("Relay") ; } + public slots: void updateRelayOptions(); void updateEnabled(); diff --git a/retroshare-gui/src/gui/settings/ServerPage.h b/retroshare-gui/src/gui/settings/ServerPage.h index 47fa33614..ba49b5eec 100755 --- a/retroshare-gui/src/gui/settings/ServerPage.h +++ b/retroshare-gui/src/gui/settings/ServerPage.h @@ -22,7 +22,7 @@ #ifndef SERVERPAGE_H #define SERVERPAGE_H -#include "configpage.h" +#include #include "ui_ServerPage.h" class ServerPage: public ConfigPage @@ -34,9 +34,12 @@ public: ~ServerPage() {} /** Saves the changes on this page */ - bool save(QString &errmsg); + virtual bool save(QString &errmsg); /** Loads the settings for this page */ - void load(); + virtual void load(); + + virtual QPixmap iconPixmap() const { return QPixmap(":/images/server_24x24.png") ; } + virtual QString pageName() const { return tr("Server") ; } public slots: void updateStatus(); diff --git a/retroshare-gui/src/gui/settings/SoundPage.h b/retroshare-gui/src/gui/settings/SoundPage.h index 557870139..1278a1467 100644 --- a/retroshare-gui/src/gui/settings/SoundPage.h +++ b/retroshare-gui/src/gui/settings/SoundPage.h @@ -24,7 +24,7 @@ #include -#include "configpage.h" +#include #include "ui_SoundPage.h" #include "gui/SoundManager.h" @@ -39,9 +39,12 @@ public: ~SoundPage(); /** Saves the changes on this page */ - bool save(QString &errmsg); + virtual bool save(QString &errmsg); /** Loads the settings for this page */ - void load(); + virtual void load(); + + virtual QPixmap iconPixmap() const { return QPixmap(":/images/sound.png") ; } + virtual QString pageName() const { return tr("Sound") ; } private slots: void eventChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous); diff --git a/retroshare-gui/src/gui/settings/TransferPage.h b/retroshare-gui/src/gui/settings/TransferPage.h index 49aa2de95..69f410774 100644 --- a/retroshare-gui/src/gui/settings/TransferPage.h +++ b/retroshare-gui/src/gui/settings/TransferPage.h @@ -24,7 +24,7 @@ # include -#include "configpage.h" +#include #include "ui_TransferPage.h" class TransferPage: public ConfigPage @@ -40,6 +40,9 @@ class TransferPage: public ConfigPage /** Loads the settings for this page */ virtual void load() {} + virtual QPixmap iconPixmap() const { return QPixmap(":/images/ktorrent32.png") ; } + virtual QString pageName() const { return tr("Transfer") ; } + public slots: void updateQueueSize(int) ; void updateMinPrioritized(int) ; diff --git a/retroshare-gui/src/gui/settings/configpage.cpp b/retroshare-gui/src/gui/settings/configpage.cpp deleted file mode 100644 index 5f69ed525..000000000 --- a/retroshare-gui/src/gui/settings/configpage.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/**************************************************************** - * RetroShare is distributed under the following license: - * - * Copyright (C) 2006 - 2010 RetroShare Team - * - * 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 option) 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 "configpage.h" - -ConfigPage::ConfigPage(QWidget *parent, Qt::WFlags flags) : QWidget(parent, flags) -{ - loaded = false; -} - -void ConfigPage::showEvent(QShowEvent */*event*/) -{ - if (loaded) { - return; - } - - loaded = true; - - /* Load the settings */ - load(); -} - -bool ConfigPage::wasLoaded() -{ - return loaded; -} diff --git a/retroshare-gui/src/gui/settings/rsettingswin.cpp b/retroshare-gui/src/gui/settings/rsettingswin.cpp index 049b367da..43e8dc848 100644 --- a/retroshare-gui/src/gui/settings/rsettingswin.cpp +++ b/retroshare-gui/src/gui/settings/rsettingswin.cpp @@ -21,6 +21,7 @@ #include +#include #include "GeneralPage.h" #include "DirectoriesPage.h" #include "ServerPage.h" @@ -105,95 +106,58 @@ RSettingsWin::initStackedWidget() stackedWidget->setCurrentIndex(-1); stackedWidget->removeWidget(stackedWidget->widget(0)); - stackedWidget->addWidget(new GeneralPage(0)); - stackedWidget->addWidget(new ServerPage()); - stackedWidget->addWidget(new TransferPage()); - stackedWidget->addWidget(new RelayPage() ); - stackedWidget->addWidget(new DirectoriesPage()); - stackedWidget->addWidget(new PluginsPage() ); - stackedWidget->addWidget(new NotifyPage()); - stackedWidget->addWidget(new CryptoPage()); - stackedWidget->addWidget(new MessagePage()); - stackedWidget->addWidget(new ForumPage()); - stackedWidget->addWidget(new ChatPage()); - stackedWidget->addWidget(new AppearancePage()); - stackedWidget->addWidget(new SoundPage() ); + addPage(new GeneralPage(0)); + addPage(new ServerPage()); + addPage(new TransferPage()); + addPage(new RelayPage() ); + addPage(new DirectoriesPage()); + addPage(new PluginsPage() ); + addPage(new NotifyPage()); + addPage(new CryptoPage()); + addPage(new MessagePage()); + addPage(new ForumPage()); + addPage(new ChatPage()); + addPage(new AppearancePage()); + addPage(new SoundPage() ); + + // add widgets from plugins + + for(int i=0;inbPlugins();++i) + { + RsPlugin *pl = rsPlugins->plugin(i) ; + + if(pl->qt_config_page() != NULL) + stackedWidget->addWidget(pl->qt_config_page()) ; + } + + // make the first page the default. setNewPage(General); } +void RSettingsWin::addPage(ConfigPage *page) +{ + stackedWidget->addWidget(page) ; + + QListWidgetItem *item = new QListWidgetItem(QIcon(page->iconPixmap()),page->pageName()) ; + listWidget->addItem(item) ; +} + void RSettingsWin::setNewPage(int page) { - QString text; + ConfigPage *pagew = dynamic_cast(stackedWidget->widget(page)) ; - switch (page) - { - case General: - text = tr("General"); - pageicon->setPixmap(QPixmap(":/images/kcmsystem24.png")); - break; - case Directories: - text = tr("Directories"); - pageicon->setPixmap(QPixmap(":/images/folder_doments.png")); - break; - case Server: - text = tr("Server"); - pageicon->setPixmap(QPixmap(":/images/server_24x24.png")); - break; - case Transfer: - text = tr("Transfer"); - pageicon->setPixmap(QPixmap(":/images/ktorrent32.png")); - break; - case Relay: - text = tr("Relay"); - pageicon->setPixmap(QPixmap(":/images/server_24x24.png")); - break; - case Notify: - text = tr("Notify"); - pageicon->setPixmap(QPixmap(":/images/status_unknown.png")); - break; - case Security: - text = tr("Security"); - pageicon->setPixmap(QPixmap(":/images/encrypted32.png")); - break; - case Message: - text = tr("Message"); - pageicon->setPixmap(QPixmap(":/images/evolution.png")); - break; - case Forum: - text = tr("Forum"); - pageicon->setPixmap(QPixmap(":/images/konversation.png")); - break; - case Plugins: - text = tr("Plugins"); - pageicon->setPixmap(QPixmap(":/images/extension_32.png")); - break; - case Chat: - text = tr("Chat"); - pageicon->setPixmap(QPixmap(":/images/chat_24.png")); - break; - case Appearance: - text = tr("Appearance"); - pageicon->setPixmap(QPixmap(":/images/looknfeel.png")); - break; - /*// #ifndef RS_RELEASE_VERSION - case Fileassociations: - text = tr("File Associations"); - pageicon->setPixmap(QPixmap(":/images/filetype-association.png")); - break;*/ - case Sound: - text = tr("Sound"); - pageicon->setPixmap(QPixmap(":/images/sound.png")); - break; - // #endif - default: - text = tr("UnknownPage");// impossible case - } + if(pagew == NULL) + { + std::cerr << "Error in RSettingsWin::setNewPage(): widget is not a ConfigPage!" << std::endl; + return ; + } + pageName->setText(pagew->pageName()); + pageicon->setPixmap(pagew->iconPixmap()) ; - pageName->setText(text); - stackedWidget->setCurrentIndex(page); - listWidget->setCurrentRow(page); + stackedWidget->setCurrentIndex(page); + listWidget->setCurrentRow(page); } /** Saves changes made to settings. */ diff --git a/retroshare-gui/src/gui/settings/rsettingswin.h b/retroshare-gui/src/gui/settings/rsettingswin.h index 4d8dd28d9..15640f459 100755 --- a/retroshare-gui/src/gui/settings/rsettingswin.h +++ b/retroshare-gui/src/gui/settings/rsettingswin.h @@ -23,6 +23,7 @@ # define RSETTINGSWIN_HPP_ # include +# include # include "ui_settings.h" @@ -41,6 +42,7 @@ class RSettingsWin: public QDialog, private Ui::Settings RSettingsWin(QWidget * parent = 0, Qt::WFlags flags = 0); ~RSettingsWin(); + void addPage(ConfigPage*) ; public slots: //! Go to a specific part of the control panel. void setNewPage(int page); diff --git a/retroshare-gui/src/gui/settings/settings.ui b/retroshare-gui/src/gui/settings/settings.ui index 84bfa4219..1e5569fed 100755 --- a/retroshare-gui/src/gui/settings/settings.ui +++ b/retroshare-gui/src/gui/settings/settings.ui @@ -80,123 +80,6 @@ -1 - - - General - - - - :/images/kcmsystem24.png:/images/kcmsystem24.png - - - - - Server - - - - :/images/server_24x24.png:/images/server_24x24.png - - - - - Transfer - - - - :/images/ktorrent32.png:/images/ktorrent32.png - - - - - Relays - - - - :/images/server_24x24.png:/images/server_24x24.png - - - - - Directories - - - - :/images/folder_doments.png:/images/folder_doments.png - - - - - Plugins - - - - :/images/extension_32.png:/images/extension_32.png - - - - - Notify - - - - :/images/status_unknown.png:/images/status_unknown.png - - - - - Security - - - - :/images/encrypted32.png:/images/encrypted32.png - - - - - Message - - - - :/images/evolution.png:/images/evolution.png - - - - - Forum - - - - :/images/konversation.png:/images/konversation.png - - - - - Chat - - - - :/images/chat_24.png:/images/chat_24.png - - - - - Appearance - - - - :/images/looknfeel.png:/images/looknfeel.png - - - - - Sound - - - - :/images/sound.png:/images/sound.png - - diff --git a/retroshare-gui/src/gui/settings/configpage.h b/retroshare-gui/src/retroshare-gui/configpage.h similarity index 60% rename from retroshare-gui/src/gui/settings/configpage.h rename to retroshare-gui/src/retroshare-gui/configpage.h index d1091a036..a6245e1d3 100644 --- a/retroshare-gui/src/gui/settings/configpage.h +++ b/retroshare-gui/src/retroshare-gui/configpage.h @@ -25,25 +25,41 @@ #include - class ConfigPage : public QWidget { -public: - /** Default Constructor */ - ConfigPage(QWidget *parent = 0, Qt::WFlags flags = 0); + public: + /** Default Constructor */ + ConfigPage(QWidget *parent = 0, Qt::WFlags flags = 0) : loaded(false) {} - /** Pure virtual method. Subclassed pages load their config settings here. */ - virtual void load() = 0; - /** Pure virtual method. Subclassed pages save their config settings here - * and return true if everything was saved successfully. */ - virtual bool save(QString &errmsg) = 0; + /** Pure virtual method. Subclassed pages load their config settings here. */ + virtual void load() = 0; - bool wasLoaded(); + /** Pure virtual method. Subclassed pages save their config settings here + * and return true if everything was saved successfully. */ -protected: - void showEvent(QShowEvent * event); + virtual bool save(QString &errmsg) = 0; - bool loaded; + bool wasLoaded() { return loaded ; } + + // Icon to be used to display the config page. + // + virtual QPixmap iconPixmap() const = 0 ; + + // Name of the page, to put in the leftside list + // + virtual QString pageName() const = 0 ; + + protected: + virtual void showEvent(QShowEvent * event) + { + if(!loaded) + { + load() ; + loaded = true ; + } + } + + bool loaded; }; #endif