Improvement of the plugin system:

- Added configuration saving for plugin manager and serialization methods
	- added a list of accepted plugin hashes
	- added plugin widget for each plugin in settings, to allow enabling/disabling plugins
	- updated LinkCloud plugin to new rsPlugin class
	- put the addconfiguration for plugin manager in rsinit.cc a bit earlier to allow to load 
		the list of accepted hashes early enough
	- added icon for disabled plugins



git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4393 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2011-07-05 20:29:07 +00:00
parent de87a89437
commit ccfbfa9984
21 changed files with 965 additions and 103 deletions

View file

@ -291,6 +291,7 @@ HEADERS += rshare.h \
gui/settings/NewTag.h \
gui/settings/ForumPage.h \
gui/settings/PluginsPage.h \
gui/settings/PluginItem.h \
gui/settings/AppearancePage.h \
gui/settings/FileAssociationsPage.h \
gui/settings/SoundPage.h \
@ -407,6 +408,7 @@ FORMS += gui/StartDialog.ui \
gui/settings/TransferPage.ui \
gui/settings/SoundPage.ui \
gui/settings/ChatPage.ui \
gui/settings/PluginItem.ui \
gui/toaster/MessageToaster.ui \
gui/toaster/OnlineToaster.ui \
gui/toaster/DownloadToaster.ui \
@ -546,6 +548,7 @@ SOURCES += main.cpp \
gui/settings/NewTag.cpp \
gui/settings/ForumPage.cpp \
gui/settings/PluginsPage.cpp \
gui/settings/PluginItem.cpp \
gui/settings/AppearancePage.cpp \
gui/settings/FileAssociationsPage.cpp \
gui/settings/SoundPage.cpp \

View file

@ -250,12 +250,23 @@ MainWindow::MainWindow(QWidget* parent, Qt::WFlags flags)
std::cerr << "Looking for interfaces in existing plugins:" << std::endl;
for(uint32_t i = 0;i<rsPlugins->nbPlugins();++i)
{
if(rsPlugins->plugin(i)->qt_page() != NULL && rsPlugins->plugin(i)->qt_icon() != NULL)
QIcon icon ;
if(rsPlugins->plugin(i) != NULL && rsPlugins->plugin(i)->qt_page() != NULL)
{
if(rsPlugins->plugin(i)->qt_icon() != NULL)
icon = *rsPlugins->plugin(i)->qt_icon() ;
else
icon = QIcon(":images/extension_48.png") ;
std::cerr << " Addign widget page for plugin " << rsPlugins->plugin(i)->getPluginName() << std::endl;
ui.stackPages->add(rsPlugins->plugin(i)->qt_page(), createPageAction(*rsPlugins->plugin(i)->qt_icon(), QString::fromStdString(rsPlugins->plugin(i)->getPluginName()), grp));
ui.stackPages->add(rsPlugins->plugin(i)->qt_page(), createPageAction(icon, QString::fromStdString(rsPlugins->plugin(i)->getPluginName()), grp));
}
//ui.stackPages->add(linksDialog = new LinksDialog(ui.stackPages), createPageAction(QIcon(IMAGE_LINKS), tr("Links Cloud"), grp));
else if(rsPlugins->plugin(i) == NULL)
std::cerr << " No plugin object !" << std::endl;
else
std::cerr << " No plugin page !" << std::endl;
}
#ifndef RS_RELEASE_VERSION

View file

@ -136,6 +136,7 @@
<file>images/encrypted22.png</file>
<file>images/encrypted32.png</file>
<file>images/encrypted48.png</file>
<file>images/disabled_plugin_48.png</file>
<file>images/evolution.png</file>
<file>images/exit_24x24.png</file>
<file>images/expand_frame.png</file>

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

View file

@ -0,0 +1,52 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2011 Cyril Soler
*
* 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 "PluginItem.h"
PluginItem::PluginItem(int id, const QString& pluginTitle,const QString& pluginDescription,const QString& status, const QString& file_name, const QString& file_hash, const QString& error_string, const QIcon& icon)
:QWidget(NULL)
{
setupUi(this) ;
_id = id ;
_statusLabel->setText(status) ;
_hashLabel->setText(file_hash) ;
_name_LE->setText(file_name) ;
_pluginIcon->setIcon(icon) ;
_pluginIcon->setText(QString()) ;
msgLabel->setText(pluginDescription) ;
subjectLabel->setText(pluginTitle) ;
QObject::connect(_enabled_CB,SIGNAL(toggled(bool)),this,SLOT(togglePlugin(bool))) ;
QObject::connect(_configure_PB,SIGNAL(clicked()),this,SLOT(configurePlugin())) ;
}
void PluginItem::togglePlugin(bool b)
{
emit( pluginEnabled(b,_hashLabel->text()) ) ;
}
void PluginItem::configurePlugin()
{
emit( pluginConfigure(_id) ) ;
}

View file

@ -0,0 +1,45 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2011 Cyril Soler
*
* 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.
****************************************************************/
#pragma once
#include "ui_PluginItem.h"
class PluginItem: public QWidget, public Ui::PluginItem
{
Q_OBJECT
public:
PluginItem(int id,const QString& pluginTitle,const QString& pluginDescription,const QString& status, const QString& file_name, const QString& file_hash, const QString& error_string, const QIcon& icon) ;
protected slots:
void togglePlugin(bool) ;
void configurePlugin() ;
signals:
void pluginEnabled(bool,const QString&) ;
void pluginConfigure(int) ;
private:
int _id ;
};

View file

@ -0,0 +1,251 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>PluginItem</class>
<widget class="QWidget" name="PluginItem">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>519</width>
<height>186</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_7">
<item>
<widget class="QFrame" name="frame">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="styleSheet">
<string notr="true">QFrame#frame{border: 2px solid green;
background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #62E0B1, stop: 1 #8EFFD3);
border-radius: 0px}</string>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<layout class="QVBoxLayout" name="verticalLayout_4">
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<item>
<widget class="QPushButton" name="_pluginIcon">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>48</horstretch>
<verstretch>48</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>48</width>
<height>48</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>48</width>
<height>48</height>
</size>
</property>
<property name="text">
<string>PushButton</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="subjectLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string notr="true">subjectLabel</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Status: </string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>File hash:</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>File name: </string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="_statusLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="_hashLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="_name_LE">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QFrame" name="expandFrame">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="_2">
<item>
<widget class="QLabel" name="msgLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string notr="true">Long
message here</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QPushButton" name="_configure_PB">
<property name="toolTip">
<string>Launch configuration panel, if provided by the plugin</string>
</property>
<property name="text">
<string>Configure</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="_enabled_CB">
<property name="toolTip">
<string>Add the plugin into the white list of accepted plugins. This will be effective after you restart RetroShare, since plugins need to be loaded at startup.</string>
</property>
<property name="text">
<string>Enabled</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources>
<include location="../images.qrc"/>
</resources>
<connections/>
</ui>

View file

@ -19,7 +19,10 @@
* Boston, MA 02110-1301, USA.
****************************************************************/
#include <iostream>
#include "PluginsPage.h"
#include "PluginItem.h"
#include "rshare.h"
#include "rsharesettings.h"
@ -35,17 +38,67 @@ PluginsPage::PluginsPage(QWidget * parent, Qt::WFlags flags)
QString text ;
std::cerr << "PluginsPage: adding plugins" << std::endl;
if(rsPlugins->nbPlugins() > 0)
for(int i=0;i<rsPlugins->nbPlugins();++i)
{
text += "<b>"+tr("Plugin")+":</b> \t" + QString::fromStdString(rsPlugins->plugin(i)->getPluginName()) + "<BR/>" ;
text += "<b>"+tr("Description")+":</b> \t" + QString::fromStdString(rsPlugins->plugin(i)->getShortPluginDescription()) + "<BR/>" ;
text += "<br/>" ;
}
else
text = tr("<h3>No plugins loaded.</h3>") ;
std::cerr << " Adding new page." << std::endl;
ui._loadedPlugins_TB->setHtml(text) ;
std::string file_name, file_hash, error_string ;
uint32_t status ;
rsPlugins->getPluginStatus(i,status,file_name,file_hash,error_string) ;
QString status_string ;
switch(status)
{
case PLUGIN_STATUS_UNKNOWN_HASH: status_string = tr("Hash rejected. Add to white list.") ;
break ;
case PLUGIN_STATUS_DLOPEN_ERROR: status_string = tr("Loading error.") ;
break ;
case PLUGIN_STATUS_MISSING_SYMBOL: status_string = tr("Missing symbol. Wrong version?") ;
break ;
case PLUGIN_STATUS_NULL_PLUGIN: status_string = tr("No plugin object") ;
break ;
case PLUGIN_STATUS_LOADED: status_string = tr("Plugins is loaded.") ;
break ;
default:
status_string = tr("Unknown status.") ;
}
QIcon plugin_icon(":images/disabled_plugin_48.png") ;
RsPlugin *plugin = rsPlugins->plugin(i) ;
QString pluginTitle = tr("Title unavailable") ;
QString pluginDescription = tr("Description unavailable") ;
if(plugin!=NULL)
{
if(plugin->qt_icon() != NULL)
plugin_icon = *plugin->qt_icon() ;
pluginTitle = QString::fromStdString(plugin->getPluginName()) ;
pluginDescription = QString::fromStdString(plugin->getShortPluginDescription()) ;
}
PluginItem *item = new PluginItem(i,pluginTitle,pluginDescription,status_string,
QString::fromStdString(file_name),
QString::fromStdString(file_hash),QString::fromStdString(error_string),
plugin_icon) ;
ui._pluginsLayout->insertWidget(0,item) ;
if(plugin == NULL || plugin->qt_config_panel() == NULL)
item->_configure_PB->setEnabled(false) ;
if(plugin != NULL)
item->_enabled_CB->setChecked(true) ;
QObject::connect(item,SIGNAL(pluginEnabled(bool,const QString&)),this,SLOT(togglePlugin(bool,const QString&))) ;
QObject::connect(item,SIGNAL(pluginConfigure(int)),this,SLOT(configurePlugin(int))) ;
}
ui._pluginsLayout->update() ;
const std::vector<std::string>& dirs(rsPlugins->getPluginDirectories()) ;
text = "" ;
@ -55,6 +108,22 @@ PluginsPage::PluginsPage(QWidget * parent, Qt::WFlags flags)
ui._lookupDirectories_TB->setHtml(text) ;
}
void PluginsPage::configurePlugin(int i)
{
std::cerr << "Launching configuration window for plugin " << i << std::endl;
if(rsPlugins->plugin(i) != NULL && rsPlugins->plugin(i)->qt_config_panel() != NULL)
rsPlugins->plugin(i)->qt_config_panel()->show() ;
}
void PluginsPage::togglePlugin(bool b,const QString& hash)
{
std::cerr << "Switching status of plugin " << hash.toStdString() << " to " << b << std::endl;
if(b)
rsPlugins->enablePlugin(hash.toStdString()) ;
else
rsPlugins->disablePlugin(hash.toStdString()) ;
}
PluginsPage::~PluginsPage()
{

View file

@ -26,18 +26,22 @@
class PluginsPage : public ConfigPage
{
Q_OBJECT
Q_OBJECT
public:
PluginsPage(QWidget * parent = 0, Qt::WFlags flags = 0);
~PluginsPage();
public:
PluginsPage(QWidget * parent = 0, Qt::WFlags flags = 0);
~PluginsPage();
/** Saves the changes on this page */
bool save(QString &errmsg);
/** Loads the settings for this page */
void load();
/** Saves the changes on this page */
bool save(QString &errmsg);
/** Loads the settings for this page */
void load();
private:
Ui::PluginsPage ui;
public slots:
void togglePlugin(bool b,const QString&) ;
void configurePlugin(int i) ;
private:
Ui::PluginsPage ui;
};

View file

@ -500,19 +500,7 @@
<enum>Qt::NoContextMenu</enum>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Loaded plugins</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QTextBrowser" name="_loadedPlugins_TB"/>
</item>
</layout>
</widget>
</item>
<item row="2" column="0">
<item row="4" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
@ -525,14 +513,60 @@
</property>
</spacer>
</item>
<item row="2" column="0">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Loaded plugins</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<layout class="QVBoxLayout" name="_pluginsLayout">
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="checkBox">
<property name="text">
<string>Authorize all plugins</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Plugin look-up directories</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTextBrowser" name="_lookupDirectories_TB"/>
<widget class="QTextBrowser" name="_lookupDirectories_TB">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>50</height>
</size>
</property>
</widget>
</item>
</layout>
</widget>