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>
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"
PluginsPage : : PluginsPage ( QWidget * parent , Qt : : WFlags flags )
: 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 ;
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 " ) ;
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 ) ,
QString : : fromStdString ( file_hash ) , QString : : fromStdString ( error_string ) ,
plugin_icon ) ;
2011-06-17 15:59:01 -04:00
2011-07-05 16:29:07 -04:00
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 ) ;
2012-02-18 09:55:50 -05:00
if ( rsPlugins - > getAllowAllPlugins ( ) )
item - > _enabled_CB - > setEnabled ( false ) ;
2011-07-05 16:29:07 -04:00
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 ( ) ;
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 ) ) ) ;
}
void PluginsPage : : toggleEnableAll ( bool b )
{
rsPlugins - > allowAllPlugins ( b ) ;
2011-06-17 15:59:01 -04:00
}
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 ( ) ;
}
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 ( ) ) ;
}
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 ( )
{
}