2011-06-17 15:59:01 -04:00
/****************************************************************
* RetroShare is distributed under the following license :
*
* Copyright ( C ) 2006 , crypton
*
* 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 .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2011-07-05 16:29:07 -04:00
# include <iostream>
2012-09-04 17:59:49 -04:00
# include <QDialog>
2011-06-17 15:59:01 -04:00
# include "PluginsPage.h"
2011-07-05 16:29:07 -04:00
# include "PluginItem.h"
2011-06-17 15:59:01 -04:00
# include "rshare.h"
# include "rsharesettings.h"
# include <retroshare/rsplugin.h>
# include "../MainWindow.h"
2013-10-18 17:10:33 -04:00
PluginsPage : : PluginsPage ( QWidget * parent , Qt : : WindowFlags flags )
2011-06-17 15:59:01 -04:00
: ConfigPage ( parent , flags )
{
ui . setupUi ( this ) ;
setAttribute ( Qt : : WA_QuitOnClose , false ) ;
QString text ;
2011-07-05 16:29:07 -04:00
std : : cerr < < " PluginsPage: adding plugins " < < std : : endl ;
2011-06-17 15:59:01 -04:00
if ( rsPlugins - > nbPlugins ( ) > 0 )
for ( int i = 0 ; i < rsPlugins - > nbPlugins ( ) ; + + i )
{
2011-07-05 16:29:07 -04:00
std : : cerr < < " Adding new page. " < < std : : endl ;
2014-03-17 16:56:06 -04:00
std : : string file_name , error_string ;
RsFileHash file_hash ;
2011-07-05 16:29:07 -04:00
uint32_t status ;
2012-09-04 17:59:49 -04:00
uint32_t svn_revision ;
2011-07-05 16:29:07 -04:00
2012-09-04 17:59:49 -04:00
rsPlugins - > getPluginStatus ( i , status , file_name , file_hash , svn_revision , error_string ) ;
2011-07-05 16:29:07 -04:00
QString status_string ;
switch ( status )
{
2012-09-09 09:59:21 -04:00
case PLUGIN_STATUS_REJECTED_HASH : status_string = tr ( " Hash rejected. Enable it manually and restart, if you need. " ) ;
break ;
case PLUGIN_STATUS_MISSING_API : status_string = tr ( " No API number supplied. Please read plugin development manual. " ) ;
break ;
case PLUGIN_STATUS_MISSING_SVN : status_string = tr ( " No SVN number supplied. Please read plugin development manual. " ) ;
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 ;
2011-07-05 16:29:07 -04:00
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 " ) ;
2012-08-15 08:33:46 -04:00
QString pluginVersion = tr ( " Unknown version " ) ;
2011-07-05 16:29:07 -04:00
if ( plugin ! = NULL )
{
2012-08-15 08:33:46 -04:00
if ( plugin - > qt_icon ( ) ! = NULL )
plugin_icon = * plugin - > qt_icon ( ) ;
2011-07-05 16:29:07 -04:00
2012-08-15 08:33:46 -04:00
pluginTitle = QString : : fromUtf8 ( plugin - > getPluginName ( ) . c_str ( ) ) ;
pluginDescription = QString : : fromUtf8 ( plugin - > getShortPluginDescription ( ) . c_str ( ) ) ;
int major = 0 ;
int minor = 0 ;
int svn_rev = 0 ;
plugin - > getPluginVersion ( major , minor , svn_rev ) ;
pluginVersion = QString ( " %1.%2.%3 " ) . arg ( major ) . arg ( minor ) . arg ( svn_rev ) ;
}
2011-07-05 16:29:07 -04:00
2012-08-15 08:33:46 -04:00
PluginItem * item = new PluginItem ( pluginVersion , i , pluginTitle , pluginDescription , status_string ,
2011-07-05 16:29:07 -04:00
QString : : fromStdString ( file_name ) ,
2014-03-17 16:56:06 -04:00
QString : : fromStdString ( file_hash . toStdString ( ) ) , QString : : fromStdString ( error_string ) ,
2011-07-05 16:29:07 -04:00
plugin_icon ) ;
2011-06-17 15:59:01 -04:00
2011-07-05 16:29:07 -04:00
ui . _pluginsLayout - > insertWidget ( 0 , item ) ;
2012-09-19 11:41:31 -04:00
2011-07-05 16:29:07 -04:00
if ( plugin = = NULL | | plugin - > qt_config_panel ( ) = = NULL )
item - > _configure_PB - > setEnabled ( false ) ;
2012-09-19 11:41:31 -04:00
if ( plugin ! = NULL ) {
item - > enableButton - > hide ( ) ;
item - > disableButton - > show ( ) ;
} else {
item - > enableButton - > show ( ) ;
item - > disableButton - > hide ( ) ;
}
2011-07-05 16:29:07 -04:00
2012-09-19 11:41:31 -04:00
//if(rsPlugins->getAllowAllPlugins())
2011-07-05 16:29:07 -04:00
2012-09-19 11:41:31 -04:00
QObject : : connect ( item , SIGNAL ( pluginEnabled ( const QString & ) ) , this , SLOT ( enablePlugin ( const QString & ) ) ) ;
QObject : : connect ( item , SIGNAL ( pluginDisabled ( const QString & ) ) , this , SLOT ( disablePlugin ( const QString & ) ) ) ;
2012-02-18 09:55:50 -05:00
2011-07-05 16:29:07 -04:00
QObject : : connect ( item , SIGNAL ( pluginConfigure ( int ) ) , this , SLOT ( configurePlugin ( int ) ) ) ;
2012-09-04 17:59:49 -04:00
QObject : : connect ( item , SIGNAL ( pluginAbout ( int ) ) , this , SLOT ( aboutPlugin ( int ) ) ) ;
2011-07-05 16:29:07 -04:00
}
ui . _pluginsLayout - > update ( ) ;
2011-06-17 15:59:01 -04:00
const std : : vector < std : : string > & dirs ( rsPlugins - > getPluginDirectories ( ) ) ;
text = " " ;
2011-08-14 17:25:41 -04:00
for ( uint i = 0 ; i < dirs . size ( ) ; + + i )
2011-10-05 12:57:33 -04:00
text + = " <b> " + QString : : fromStdString ( dirs [ i ] ) + " </b><br> " ;
2011-06-17 15:59:01 -04:00
ui . _lookupDirectories_TB - > setHtml ( text ) ;
2011-11-17 16:17:24 -05:00
// todo
2012-02-18 09:55:50 -05:00
ui . enableAll - > setChecked ( rsPlugins - > getAllowAllPlugins ( ) ) ;
ui . enableAll - > setToolTip ( tr ( " Check this for developing plugins. They will not \n be checked for the hash. However, in normal \n times, checking the hash protects you from \n malicious behavior of crafted plugins. " ) ) ;
2011-11-17 16:17:24 -05:00
ui . enableAll - > setEnabled ( false ) ;
2012-02-18 09:55:50 -05:00
QObject : : connect ( ui . enableAll , SIGNAL ( toggled ( bool ) ) , this , SLOT ( toggleEnableAll ( bool ) ) ) ;
}
2013-10-13 07:43:15 -04:00
QString PluginsPage : : helpText ( ) const
{
return tr ( " <h1><img width= \" 24 \" src= \" :/images/64px_help.png \" > Plugins</h1> \
< p > Plugins are loaded from the directories listed in the bottom list . < / p > \
< p > For security reasons , accepted plugins load automatically until \
the main Retroshare executable or the plugin library changes . In \
such a case , the user needs to confirm them again . \
After the program is started , you can enable a plugin manually by clicking on the \
\ " Enable \" button and then restart Retroshare.</p> \
< p > If you want to develop your own plugins , contact the developpers team \
they will be happy to help you out ! < / p > " ) ;
}
2012-02-18 09:55:50 -05:00
void PluginsPage : : toggleEnableAll ( bool b )
{
rsPlugins - > allowAllPlugins ( b ) ;
2011-06-17 15:59:01 -04:00
}
2012-09-04 17:59:49 -04:00
void PluginsPage : : aboutPlugin ( int i )
{
std : : cerr < < " Launching about window for plugin " < < i < < std : : endl ;
if ( rsPlugins - > plugin ( i ) ! = NULL & & rsPlugins - > plugin ( i ) - > qt_about_page ( ) ! = NULL )
rsPlugins - > plugin ( i ) - > qt_about_page ( ) - > exec ( ) ;
}
2011-07-05 16:29:07 -04:00
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 ( ) ;
}
2012-09-19 11:41:31 -04:00
void PluginsPage : : enablePlugin ( const QString & hash )
2014-03-17 16:56:06 -04:00
{
std : : cerr < < " Switching status of plugin " < < hash . toStdString ( ) < < " to enable " < < std : : endl ;
2012-09-19 11:41:31 -04:00
2014-03-17 16:56:06 -04:00
rsPlugins - > enablePlugin ( RsFileHash ( hash . toStdString ( ) ) ) ;
2012-09-19 11:41:31 -04:00
}
void PluginsPage : : disablePlugin ( const QString & hash )
2014-03-17 16:56:06 -04:00
{
std : : cerr < < " Switching status of plugin " < < hash . toStdString ( ) < < " to disable " < < std : : endl ;
2012-09-19 11:41:31 -04:00
2014-03-17 16:56:06 -04:00
rsPlugins - > disablePlugin ( RsFileHash ( hash . toStdString ( ) ) ) ;
2011-07-05 16:29:07 -04:00
}
2011-06-17 15:59:01 -04:00
2012-09-19 11:41:31 -04:00
2011-06-17 15:59:01 -04:00
PluginsPage : : ~ PluginsPage ( )
{
}
/** Saves the changes on this page */
2011-08-12 10:06:29 -04:00
bool PluginsPage : : save ( QString & /*errmsg*/ )
2011-06-17 15:59:01 -04:00
{
// nothing to save for now.
return true ;
}
/** Loads the settings for this page */
void PluginsPage : : load ( )
{
}