mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-04-14 04:23:10 -04:00
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:
parent
13283b40ee
commit
5679a30e67
@ -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<RsItem*>& list)
|
||||
_accepted_hashes.insert(*it) ;
|
||||
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);
|
||||
}
|
||||
return true;
|
||||
@ -359,6 +382,14 @@ bool RsPluginManager::saveList(bool& cleanup, std::list<RsItem*>& 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;
|
||||
}
|
||||
|
||||
|
@ -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<RsItem*>& list) ;
|
||||
@ -84,6 +87,7 @@ class RsPluginManager: public RsPluginHandler, public p3Config
|
||||
|
||||
std::vector<PluginInfo> _plugins ;
|
||||
std::set<std::string> _accepted_hashes ;
|
||||
bool _allow_all_plugins ;
|
||||
|
||||
static std::string _plugin_entry_symbol ;
|
||||
static std::string _remote_cache_dir ;
|
||||
|
@ -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;
|
||||
|
@ -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 \
|
||||
|
@ -22,7 +22,7 @@
|
||||
#ifndef _APPERARANCEPAGE_H
|
||||
#define _APPERARANCEPAGE_H
|
||||
|
||||
#include "configpage.h"
|
||||
#include <retroshare-gui/configpage.h>
|
||||
#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:
|
||||
|
||||
|
@ -22,7 +22,7 @@
|
||||
#ifndef _CHATPAGE_H
|
||||
#define _CHATPAGE_H
|
||||
|
||||
#include "configpage.h"
|
||||
#include <retroshare-gui/configpage.h>
|
||||
#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);
|
||||
|
@ -22,7 +22,7 @@
|
||||
#ifndef _CRYPTOPAGE_H
|
||||
#define _CRYPTOPAGE_H
|
||||
|
||||
#include "configpage.h"
|
||||
#include <retroshare-gui/configpage.h>
|
||||
#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() ;
|
||||
|
||||
|
@ -22,7 +22,7 @@
|
||||
#ifndef DIRECTORIESPAGE_H
|
||||
#define DIRECTORIESPAGE_H
|
||||
|
||||
#include "configpage.h"
|
||||
#include <retroshare-gui/configpage.h>
|
||||
#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() ;
|
||||
|
@ -22,7 +22,7 @@
|
||||
#ifndef __FileAssociationsPage__
|
||||
#define __FileAssociationsPage__
|
||||
|
||||
#include "configpage.h"
|
||||
#include <retroshare-gui/configpage.h>
|
||||
|
||||
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;
|
||||
|
@ -22,7 +22,7 @@
|
||||
#ifndef FORUMPAGE_H
|
||||
#define FORUMPAGE_H
|
||||
|
||||
#include "configpage.h"
|
||||
#include <retroshare-gui/configpage.h>
|
||||
#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;
|
||||
|
@ -23,7 +23,7 @@
|
||||
#ifndef _GENERALPAGE_H
|
||||
#define _GENERALPAGE_H
|
||||
|
||||
#include "configpage.h"
|
||||
#include <retroshare-gui/configpage.h>
|
||||
#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 */
|
||||
|
@ -24,7 +24,7 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "configpage.h"
|
||||
#include <retroshare-gui/configpage.h>
|
||||
#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();
|
||||
|
@ -22,7 +22,7 @@
|
||||
#ifndef NETWORKPAGE_H
|
||||
#define NETWORKPAGE_H
|
||||
|
||||
#include "configpage.h"
|
||||
#include <retroshare-gui/configpage.h>
|
||||
#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;
|
||||
|
@ -22,7 +22,7 @@
|
||||
#ifndef NOTIFYPAGE_H
|
||||
#define NOTIFYPAGE_H
|
||||
|
||||
#include "configpage.h"
|
||||
#include <retroshare-gui/configpage.h>
|
||||
#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();
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -21,7 +21,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "configpage.h"
|
||||
#include <retroshare-gui/configpage.h>
|
||||
#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;
|
||||
|
@ -24,7 +24,7 @@
|
||||
|
||||
# include <QtGui/QWidget>
|
||||
|
||||
#include "configpage.h"
|
||||
#include <retroshare-gui/configpage.h>
|
||||
#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();
|
||||
|
@ -22,7 +22,7 @@
|
||||
#ifndef SERVERPAGE_H
|
||||
#define SERVERPAGE_H
|
||||
|
||||
#include "configpage.h"
|
||||
#include <retroshare-gui/configpage.h>
|
||||
#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();
|
||||
|
@ -24,7 +24,7 @@
|
||||
|
||||
#include <QFileDialog>
|
||||
|
||||
#include "configpage.h"
|
||||
#include <retroshare-gui/configpage.h>
|
||||
#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);
|
||||
|
@ -24,7 +24,7 @@
|
||||
|
||||
# include <QtGui/QWidget>
|
||||
|
||||
#include "configpage.h"
|
||||
#include <retroshare-gui/configpage.h>
|
||||
#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) ;
|
||||
|
@ -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;
|
||||
}
|
@ -21,6 +21,7 @@
|
||||
|
||||
#include <QMessageBox>
|
||||
|
||||
#include <retroshare/rsplugin.h>
|
||||
#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;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);
|
||||
}
|
||||
|
||||
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<ConfigPage*>(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. */
|
||||
|
@ -23,6 +23,7 @@
|
||||
# define RSETTINGSWIN_HPP_
|
||||
|
||||
# include <QtGui/QDialog>
|
||||
# include <retroshare-gui/configpage.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();
|
||||
|
||||
void addPage(ConfigPage*) ;
|
||||
public slots:
|
||||
//! Go to a specific part of the control panel.
|
||||
void setNewPage(int page);
|
||||
|
@ -80,123 +80,6 @@
|
||||
<property name="currentRow">
|
||||
<number>-1</number>
|
||||
</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>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
|
@ -25,25 +25,41 @@
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
|
||||
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
|
Loading…
x
Reference in New Issue
Block a user