Improvement to plugin system:

- made config page system more automatic, to allow addign config pages from plugins
- added (disabled) checkbox and function to allow all plugins for development
- added config page methods to RsPlugin class



git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4957 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2012-02-18 14:55:50 +00:00
parent 13283b40ee
commit 5679a30e67
25 changed files with 220 additions and 300 deletions

View file

@ -36,6 +36,7 @@ RsPluginHandler *rsPlugins ;
RsPluginManager::RsPluginManager() : p3Config(CONFIG_TYPE_PLUGINS) RsPluginManager::RsPluginManager() : p3Config(CONFIG_TYPE_PLUGINS)
{ {
_allow_all_plugins = false ;
} }
void RsPluginManager::loadConfiguration() 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 ; 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 *RsPluginManager::setupSerialiser()
{ {
RsSerialiser *rss = new RsSerialiser ; RsSerialiser *rss = new RsSerialiser ;
rss->addSerialType(new RsPluginSerialiser()) ; rss->addSerialType(new RsPluginSerialiser()) ;
rss->addSerialType(new RsGeneralConfigSerialiser()) ;
return rss ; return rss ;
} }
@ -203,7 +214,7 @@ bool RsPluginManager::loadPlugin(const std::string& plugin_name)
std::cerr << " -> hash = " << pinfo.file_hash << std::endl; 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; 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 ; pinfo.status = PLUGIN_STATUS_UNKNOWN_HASH ;
@ -343,6 +354,18 @@ bool RsPluginManager::loadList(std::list<RsItem*>& list)
std::cerr << " loaded hash " << *it << std::endl; std::cerr << " loaded hash " << *it << std::endl;
} }
RsConfigKeyValueSet *witem = dynamic_cast<RsConfigKeyValueSet *>(*it) ;
if(witem)
{
for(std::list<RsTlvKeyValue>::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); delete (*it);
} }
return true; return true;
@ -359,6 +382,14 @@ bool RsPluginManager::saveList(bool& cleanup, std::list<RsItem*>& list)
list.push_back(vitem) ; 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; return true;
} }

View file

@ -40,6 +40,9 @@ class RsPluginManager: public RsPluginHandler, public p3Config
virtual ftServer *getFileServer() const ; virtual ftServer *getFileServer() const ;
virtual p3LinkMgr *getLinkMgr() const ; virtual p3LinkMgr *getLinkMgr() const ;
virtual void allowAllPlugins(bool b) ;
virtual bool getAllowAllPlugins() const ;
// ---------------- Derived from p3Config -------------------// // ---------------- Derived from p3Config -------------------//
// //
bool saveList(bool& cleanup, std::list<RsItem*>& list) ; bool saveList(bool& cleanup, std::list<RsItem*>& list) ;
@ -84,6 +87,7 @@ class RsPluginManager: public RsPluginHandler, public p3Config
std::vector<PluginInfo> _plugins ; std::vector<PluginInfo> _plugins ;
std::set<std::string> _accepted_hashes ; std::set<std::string> _accepted_hashes ;
bool _allow_all_plugins ;
static std::string _plugin_entry_symbol ; static std::string _plugin_entry_symbol ;
static std::string _remote_cache_dir ; static std::string _remote_cache_dir ;

View file

@ -45,6 +45,7 @@ class QTranslator;
class QApplication; class QApplication;
class RsCacheService ; class RsCacheService ;
class ftServer ; class ftServer ;
class ConfigPage ;
class pqiService ; class pqiService ;
// Used for the status of plugins. // Used for the status of plugins.
@ -83,6 +84,8 @@ class RsPlugin
virtual MainPage *qt_page() const { return NULL ; } virtual MainPage *qt_page() const { return NULL ; }
virtual QWidget *qt_config_panel() const { return NULL ; } virtual QWidget *qt_config_panel() const { return NULL ; }
virtual QIcon *qt_icon() 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 QTranslator *qt_translator(QApplication * /* app */, const QString& /* languageCode */ ) const { return NULL ; }
virtual std::string configurationFileName() const { return std::string() ; } virtual std::string configurationFileName() const { return std::string() ; }
@ -105,6 +108,9 @@ class RsPluginHandler
virtual void enablePlugin(const std::string& hash) = 0; virtual void enablePlugin(const std::string& hash) = 0;
virtual void disablePlugin(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 void slowTickPlugins(time_t sec) = 0 ;
virtual const std::string& getLocalCacheDir() const =0; virtual const std::string& getLocalCacheDir() const =0;

View file

@ -202,6 +202,7 @@ INCLUDEPATH += ../../libretroshare/src/
# Input # Input
HEADERS += rshare.h \ HEADERS += rshare.h \
retroshare-gui/configpage.h \
gui/notifyqt.h \ gui/notifyqt.h \
control/bandwidthevent.h \ control/bandwidthevent.h \
control/eventtype.h \ control/eventtype.h \
@ -302,7 +303,6 @@ HEADERS += rshare.h \
gui/settings/RsharePeerSettings.h \ gui/settings/RsharePeerSettings.h \
gui/settings/rsettings.h \ gui/settings/rsettings.h \
gui/settings/rsettingswin.h \ gui/settings/rsettingswin.h \
gui/settings/configpage.h \
gui/settings/GeneralPage.h \ gui/settings/GeneralPage.h \
gui/settings/DirectoriesPage.h \ gui/settings/DirectoriesPage.h \
gui/settings/ServerPage.h \ gui/settings/ServerPage.h \
@ -596,7 +596,6 @@ SOURCES += main.cpp \
gui/common/LinkTextBrowser.cpp \ gui/common/LinkTextBrowser.cpp \
gui/style/RSStyle.cpp \ gui/style/RSStyle.cpp \
gui/style/StyleDialog.cpp \ gui/style/StyleDialog.cpp \
gui/settings/configpage.cpp \
gui/settings/rsharesettings.cpp \ gui/settings/rsharesettings.cpp \
gui/settings/RsharePeerSettings.cpp \ gui/settings/RsharePeerSettings.cpp \
gui/settings/rsettings.cpp \ gui/settings/rsettings.cpp \

View file

@ -22,7 +22,7 @@
#ifndef _APPERARANCEPAGE_H #ifndef _APPERARANCEPAGE_H
#define _APPERARANCEPAGE_H #define _APPERARANCEPAGE_H
#include "configpage.h" #include <retroshare-gui/configpage.h>
#include "ui_AppearancePage.h" #include "ui_AppearancePage.h"
class AppearancePage : public ConfigPage class AppearancePage : public ConfigPage
@ -36,9 +36,13 @@ class AppearancePage : public ConfigPage
~AppearancePage(); ~AppearancePage();
/** Saves the changes on this page */ /** Saves the changes on this page */
bool save(QString &errmsg); virtual bool save(QString &errmsg);
/** Loads the settings for this page */ /** 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: private slots:

View file

@ -22,7 +22,7 @@
#ifndef _CHATPAGE_H #ifndef _CHATPAGE_H
#define _CHATPAGE_H #define _CHATPAGE_H
#include "configpage.h" #include <retroshare-gui/configpage.h>
#include "ui_ChatPage.h" #include "ui_ChatPage.h"
class ChatPage : public ConfigPage class ChatPage : public ConfigPage
@ -36,9 +36,12 @@ class ChatPage : public ConfigPage
~ChatPage() {} ~ChatPage() {}
/** Saves the changes on this page */ /** Saves the changes on this page */
bool save(QString &errmsg); virtual bool save(QString &errmsg);
/** Loads the settings for this page */ /** 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: private slots:
void on_historyComboBoxVariant_currentIndexChanged(int index); void on_historyComboBoxVariant_currentIndexChanged(int index);

View file

@ -22,7 +22,7 @@
#ifndef _CRYPTOPAGE_H #ifndef _CRYPTOPAGE_H
#define _CRYPTOPAGE_H #define _CRYPTOPAGE_H
#include "configpage.h" #include <retroshare-gui/configpage.h>
#include "ui_CryptoPage.h" #include "ui_CryptoPage.h"
class CryptoPage : public ConfigPage class CryptoPage : public ConfigPage
@ -36,11 +36,14 @@ class CryptoPage : public ConfigPage
~CryptoPage(); ~CryptoPage();
/** Saves the changes on this page */ /** Saves the changes on this page */
bool save(QString &errmsg); virtual bool save(QString &errmsg);
/** Loads the settings for this page */ /** Loads the settings for this page */
virtual QPixmap iconPixmap() const { return QPixmap(":/images/encrypted32.png") ; }
virtual QString pageName() const { return tr("Security") ; }
private slots: private slots:
void load(); virtual void load();
void copyPublicKey(); void copyPublicKey();
void copyRSLink() ; void copyRSLink() ;

View file

@ -22,7 +22,7 @@
#ifndef DIRECTORIESPAGE_H #ifndef DIRECTORIESPAGE_H
#define DIRECTORIESPAGE_H #define DIRECTORIESPAGE_H
#include "configpage.h" #include <retroshare-gui/configpage.h>
#include "ui_DirectoriesPage.h" #include "ui_DirectoriesPage.h"
class DirectoriesPage: public ConfigPage class DirectoriesPage: public ConfigPage
@ -33,9 +33,12 @@ public:
DirectoriesPage(QWidget * parent = 0, Qt::WFlags flags = 0); DirectoriesPage(QWidget * parent = 0, Qt::WFlags flags = 0);
/** Saves the changes on this page */ /** Saves the changes on this page */
bool save(QString &errmsg); virtual bool save(QString &errmsg);
/** Loads the settings for this page */ /** 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: private slots:
void editDirectories() ; void editDirectories() ;

View file

@ -22,7 +22,7 @@
#ifndef __FileAssociationsPage__ #ifndef __FileAssociationsPage__
#define __FileAssociationsPage__ #define __FileAssociationsPage__
#include "configpage.h" #include <retroshare-gui/configpage.h>
class QToolBar; class QToolBar;
class QAction; class QAction;
@ -51,8 +51,10 @@ public:
FileAssociationsPage(QWidget * parent = 0, Qt::WFlags flags = 0); FileAssociationsPage(QWidget * parent = 0, Qt::WFlags flags = 0);
virtual ~FileAssociationsPage(); virtual ~FileAssociationsPage();
void load(); virtual void load();
bool save (QString &errmsg); virtual bool save (QString &errmsg);
virtual QPixmap iconPixmap() const { return QPixmap(":/images/filetype-association.png") ; }
virtual QString pageName() const { return tr("Associations") ; }
protected: protected:
QToolBar* toolBar; QToolBar* toolBar;

View file

@ -22,7 +22,7 @@
#ifndef FORUMPAGE_H #ifndef FORUMPAGE_H
#define FORUMPAGE_H #define FORUMPAGE_H
#include "configpage.h" #include <retroshare-gui/configpage.h>
#include "ui_ForumPage.h" #include "ui_ForumPage.h"
class ForumPage : public ConfigPage class ForumPage : public ConfigPage
@ -34,9 +34,12 @@ public:
~ForumPage(); ~ForumPage();
/** Saves the changes on this page */ /** Saves the changes on this page */
bool save(QString &errmsg); virtual bool save(QString &errmsg);
/** Loads the settings for this page */ /** 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: private:
Ui::ForumPage ui; Ui::ForumPage ui;

View file

@ -23,7 +23,7 @@
#ifndef _GENERALPAGE_H #ifndef _GENERALPAGE_H
#define _GENERALPAGE_H #define _GENERALPAGE_H
#include "configpage.h" #include <retroshare-gui/configpage.h>
#include "ui_GeneralPage.h" #include "ui_GeneralPage.h"
class GeneralPage : public ConfigPage class GeneralPage : public ConfigPage
@ -37,9 +37,12 @@ public:
~GeneralPage(); ~GeneralPage();
/** Saves the changes on this page */ /** Saves the changes on this page */
bool save(QString &errmsg); virtual bool save(QString &errmsg);
/** Loads the settings for this page */ /** 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: private:
/** Qt Designer generated object */ /** Qt Designer generated object */

View file

@ -24,7 +24,7 @@
#include <stdint.h> #include <stdint.h>
#include "configpage.h" #include <retroshare-gui/configpage.h>
#include "ui_MessagePage.h" #include "ui_MessagePage.h"
class MsgTagType; class MsgTagType;
@ -38,9 +38,13 @@ public:
~MessagePage(); ~MessagePage();
/** Saves the changes on this page */ /** Saves the changes on this page */
bool save(QString &errmsg); virtual bool save(QString &errmsg);
/** Loads the settings for this page */ /** 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: private slots:
void addTag(); void addTag();

View file

@ -22,7 +22,7 @@
#ifndef NETWORKPAGE_H #ifndef NETWORKPAGE_H
#define NETWORKPAGE_H #define NETWORKPAGE_H
#include "configpage.h" #include <retroshare-gui/configpage.h>
#include "ui_NetworkPage.h" #include "ui_NetworkPage.h"
class NetworkPage : public ConfigPage class NetworkPage : public ConfigPage
@ -32,9 +32,12 @@ public:
~NetworkPage() {} ~NetworkPage() {}
/** Saves the changes on this page */ /** Saves the changes on this page */
bool save(QString &errmsg); virtual bool save(QString &errmsg);
/** Loads the settings for this page */ /** 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: private:
Ui::NetworkPage ui; Ui::NetworkPage ui;

View file

@ -22,7 +22,7 @@
#ifndef NOTIFYPAGE_H #ifndef NOTIFYPAGE_H
#define NOTIFYPAGE_H #define NOTIFYPAGE_H
#include "configpage.h" #include <retroshare-gui/configpage.h>
#include "ui_NotifyPage.h" #include "ui_NotifyPage.h"
class NotifyPage : public ConfigPage class NotifyPage : public ConfigPage
@ -36,9 +36,12 @@ public:
~NotifyPage(); ~NotifyPage();
/** Saves the changes on this page */ /** Saves the changes on this page */
bool save(QString &errmsg); virtual bool save(QString &errmsg);
/** Loads the settings for this page */ /** 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: private slots:
void privatChatToggled(); void privatChatToggled();

View file

@ -95,6 +95,9 @@ PluginsPage::PluginsPage(QWidget * parent, Qt::WFlags flags)
if(plugin != NULL) if(plugin != NULL)
item->_enabled_CB->setChecked(true) ; 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(pluginEnabled(bool,const QString&)),this,SLOT(togglePlugin(bool,const QString&))) ;
QObject::connect(item,SIGNAL(pluginConfigure(int)),this,SLOT(configurePlugin(int))) ; 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) ; ui._lookupDirectories_TB->setHtml(text) ;
// todo // 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); 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) void PluginsPage::configurePlugin(int i)
{ {

View file

@ -21,7 +21,7 @@
#pragma once #pragma once
#include "configpage.h" #include <retroshare-gui/configpage.h>
#include "ui_PluginsPage.h" #include "ui_PluginsPage.h"
class PluginsPage : public ConfigPage class PluginsPage : public ConfigPage
@ -33,13 +33,18 @@ class PluginsPage : public ConfigPage
~PluginsPage(); ~PluginsPage();
/** Saves the changes on this page */ /** Saves the changes on this page */
bool save(QString &errmsg); virtual bool save(QString &errmsg);
/** Loads the settings for this page */ /** 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: public slots:
void togglePlugin(bool b,const QString&) ; void togglePlugin(bool b,const QString&) ;
void configurePlugin(int i) ; void configurePlugin(int i) ;
void toggleEnableAll(bool) ;
private: private:
Ui::PluginsPage ui; Ui::PluginsPage ui;

View file

@ -24,7 +24,7 @@
# include <QtGui/QWidget> # include <QtGui/QWidget>
#include "configpage.h" #include <retroshare-gui/configpage.h>
#include "ui_RelayPage.h" #include "ui_RelayPage.h"
class RelayPage: public ConfigPage class RelayPage: public ConfigPage
@ -40,6 +40,9 @@ class RelayPage: public ConfigPage
/** Loads the settings for this page */ /** Loads the settings for this page */
virtual void load(); virtual void load();
virtual QPixmap iconPixmap() const { return QPixmap(":/images/server_24x24.png") ; }
virtual QString pageName() const { return tr("Relay") ; }
public slots: public slots:
void updateRelayOptions(); void updateRelayOptions();
void updateEnabled(); void updateEnabled();

View file

@ -22,7 +22,7 @@
#ifndef SERVERPAGE_H #ifndef SERVERPAGE_H
#define SERVERPAGE_H #define SERVERPAGE_H
#include "configpage.h" #include <retroshare-gui/configpage.h>
#include "ui_ServerPage.h" #include "ui_ServerPage.h"
class ServerPage: public ConfigPage class ServerPage: public ConfigPage
@ -34,9 +34,12 @@ public:
~ServerPage() {} ~ServerPage() {}
/** Saves the changes on this page */ /** Saves the changes on this page */
bool save(QString &errmsg); virtual bool save(QString &errmsg);
/** Loads the settings for this page */ /** 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: public slots:
void updateStatus(); void updateStatus();

View file

@ -24,7 +24,7 @@
#include <QFileDialog> #include <QFileDialog>
#include "configpage.h" #include <retroshare-gui/configpage.h>
#include "ui_SoundPage.h" #include "ui_SoundPage.h"
#include "gui/SoundManager.h" #include "gui/SoundManager.h"
@ -39,9 +39,12 @@ public:
~SoundPage(); ~SoundPage();
/** Saves the changes on this page */ /** Saves the changes on this page */
bool save(QString &errmsg); virtual bool save(QString &errmsg);
/** Loads the settings for this page */ /** 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: private slots:
void eventChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous); void eventChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous);

View file

@ -24,7 +24,7 @@
# include <QtGui/QWidget> # include <QtGui/QWidget>
#include "configpage.h" #include <retroshare-gui/configpage.h>
#include "ui_TransferPage.h" #include "ui_TransferPage.h"
class TransferPage: public ConfigPage class TransferPage: public ConfigPage
@ -40,6 +40,9 @@ class TransferPage: public ConfigPage
/** Loads the settings for this page */ /** Loads the settings for this page */
virtual void load() {} virtual void load() {}
virtual QPixmap iconPixmap() const { return QPixmap(":/images/ktorrent32.png") ; }
virtual QString pageName() const { return tr("Transfer") ; }
public slots: public slots:
void updateQueueSize(int) ; void updateQueueSize(int) ;
void updateMinPrioritized(int) ; void updateMinPrioritized(int) ;

View file

@ -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;
}

View file

@ -21,6 +21,7 @@
#include <QMessageBox> #include <QMessageBox>
#include <retroshare/rsplugin.h>
#include "GeneralPage.h" #include "GeneralPage.h"
#include "DirectoriesPage.h" #include "DirectoriesPage.h"
#include "ServerPage.h" #include "ServerPage.h"
@ -105,95 +106,58 @@ RSettingsWin::initStackedWidget()
stackedWidget->setCurrentIndex(-1); stackedWidget->setCurrentIndex(-1);
stackedWidget->removeWidget(stackedWidget->widget(0)); stackedWidget->removeWidget(stackedWidget->widget(0));
stackedWidget->addWidget(new GeneralPage(0)); addPage(new GeneralPage(0));
stackedWidget->addWidget(new ServerPage()); addPage(new ServerPage());
stackedWidget->addWidget(new TransferPage()); addPage(new TransferPage());
stackedWidget->addWidget(new RelayPage() ); addPage(new RelayPage() );
stackedWidget->addWidget(new DirectoriesPage()); addPage(new DirectoriesPage());
stackedWidget->addWidget(new PluginsPage() ); addPage(new PluginsPage() );
stackedWidget->addWidget(new NotifyPage()); addPage(new NotifyPage());
stackedWidget->addWidget(new CryptoPage()); addPage(new CryptoPage());
stackedWidget->addWidget(new MessagePage()); addPage(new MessagePage());
stackedWidget->addWidget(new ForumPage()); addPage(new ForumPage());
stackedWidget->addWidget(new ChatPage()); addPage(new ChatPage());
stackedWidget->addWidget(new AppearancePage()); addPage(new AppearancePage());
stackedWidget->addWidget(new SoundPage() ); addPage(new SoundPage() );
// add widgets from plugins
for(int i=0;i<rsPlugins->nbPlugins();++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); setNewPage(General);
} }
void RSettingsWin::addPage(ConfigPage *page)
{
stackedWidget->addWidget(page) ;
QListWidgetItem *item = new QListWidgetItem(QIcon(page->iconPixmap()),page->pageName()) ;
listWidget->addItem(item) ;
}
void void
RSettingsWin::setNewPage(int page) RSettingsWin::setNewPage(int page)
{ {
QString text; ConfigPage *pagew = dynamic_cast<ConfigPage*>(stackedWidget->widget(page)) ;
switch (page) if(pagew == NULL)
{ {
case General: std::cerr << "Error in RSettingsWin::setNewPage(): widget is not a ConfigPage!" << std::endl;
text = tr("General"); return ;
pageicon->setPixmap(QPixmap(":/images/kcmsystem24.png")); }
break; pageName->setText(pagew->pageName());
case Directories: pageicon->setPixmap(pagew->iconPixmap()) ;
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
}
pageName->setText(text); stackedWidget->setCurrentIndex(page);
stackedWidget->setCurrentIndex(page); listWidget->setCurrentRow(page);
listWidget->setCurrentRow(page);
} }
/** Saves changes made to settings. */ /** Saves changes made to settings. */

View file

@ -23,6 +23,7 @@
# define RSETTINGSWIN_HPP_ # define RSETTINGSWIN_HPP_
# include <QtGui/QDialog> # include <QtGui/QDialog>
# include <retroshare-gui/configpage.h>
# include "ui_settings.h" # include "ui_settings.h"
@ -41,6 +42,7 @@ class RSettingsWin: public QDialog, private Ui::Settings
RSettingsWin(QWidget * parent = 0, Qt::WFlags flags = 0); RSettingsWin(QWidget * parent = 0, Qt::WFlags flags = 0);
~RSettingsWin(); ~RSettingsWin();
void addPage(ConfigPage*) ;
public slots: public slots:
//! Go to a specific part of the control panel. //! Go to a specific part of the control panel.
void setNewPage(int page); void setNewPage(int page);

View file

@ -80,123 +80,6 @@
<property name="currentRow"> <property name="currentRow">
<number>-1</number> <number>-1</number>
</property> </property>
<item>
<property name="text">
<string>General</string>
</property>
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/kcmsystem24.png</normaloff>:/images/kcmsystem24.png</iconset>
</property>
</item>
<item>
<property name="text">
<string>Server</string>
</property>
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/server_24x24.png</normaloff>:/images/server_24x24.png</iconset>
</property>
</item>
<item>
<property name="text">
<string>Transfer</string>
</property>
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/ktorrent32.png</normaloff>:/images/ktorrent32.png</iconset>
</property>
</item>
<item>
<property name="text">
<string>Relays</string>
</property>
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/server_24x24.png</normaloff>:/images/server_24x24.png</iconset>
</property>
</item>
<item>
<property name="text">
<string>Directories</string>
</property>
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/folder_doments.png</normaloff>:/images/folder_doments.png</iconset>
</property>
</item>
<item>
<property name="text">
<string>Plugins</string>
</property>
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/extension_32.png</normaloff>:/images/extension_32.png</iconset>
</property>
</item>
<item>
<property name="text">
<string>Notify</string>
</property>
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/status_unknown.png</normaloff>:/images/status_unknown.png</iconset>
</property>
</item>
<item>
<property name="text">
<string>Security</string>
</property>
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/encrypted32.png</normaloff>:/images/encrypted32.png</iconset>
</property>
</item>
<item>
<property name="text">
<string>Message</string>
</property>
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/evolution.png</normaloff>:/images/evolution.png</iconset>
</property>
</item>
<item>
<property name="text">
<string>Forum</string>
</property>
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/konversation.png</normaloff>:/images/konversation.png</iconset>
</property>
</item>
<item>
<property name="text">
<string>Chat</string>
</property>
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/chat_24.png</normaloff>:/images/chat_24.png</iconset>
</property>
</item>
<item>
<property name="text">
<string>Appearance</string>
</property>
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/looknfeel.png</normaloff>:/images/looknfeel.png</iconset>
</property>
</item>
<item>
<property name="text">
<string>Sound</string>
</property>
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/sound.png</normaloff>:/images/sound.png</iconset>
</property>
</item>
</widget> </widget>
</item> </item>
<item row="0" column="1"> <item row="0" column="1">

View file

@ -25,25 +25,41 @@
#include <QWidget> #include <QWidget>
class ConfigPage : public QWidget class ConfigPage : public QWidget
{ {
public: public:
/** Default Constructor */ /** Default Constructor */
ConfigPage(QWidget *parent = 0, Qt::WFlags flags = 0); ConfigPage(QWidget *parent = 0, Qt::WFlags flags = 0) : loaded(false) {}
/** Pure virtual method. Subclassed pages load their config settings here. */ /** Pure virtual method. Subclassed pages load their config settings here. */
virtual void load() = 0; 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;
bool wasLoaded(); /** Pure virtual method. Subclassed pages save their config settings here
* and return true if everything was saved successfully. */
protected: virtual bool save(QString &errmsg) = 0;
void showEvent(QShowEvent * event);
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 #endif