2012-11-25 22:50:38 +00:00
/****************************************************************
* RetroShare is distributed under the following license :
*
* Copyright ( C ) 2008 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
2016-02-07 11:45:55 +01:00
* Foundation , Inc . , 51 Franklin Street , Fifth Floor ,
2012-11-25 22:50:38 +00:00
* Boston , MA 02110 - 1301 , USA .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# include <QHBoxLayout>
2017-05-10 21:37:06 +02:00
# include <QMessageBox>
2012-11-25 22:50:38 +00:00
# include <QLabel>
# include "gui/statusbar/OpModeStatus.h"
2016-02-07 11:45:55 +01:00
# include "gui/settings/rsharesettings.h"
2012-11-25 22:50:38 +00:00
# include <retroshare/rsconfig.h>
2016-02-07 11:45:55 +01:00
2012-11-25 22:50:38 +00:00
# include <iostream>
OpModeStatus : : OpModeStatus ( QWidget * parent )
2016-02-07 11:45:55 +01:00
: QComboBox ( parent )
2012-11-25 22:50:38 +00:00
{
2016-02-07 11:45:55 +01:00
onUpdate = false ;
opMode_Full_Color = QColor ( " #CCFFCC " ) ;
opMode_NoTurtle_Color = QColor ( " #CCCCFF " ) ;
opMode_Gaming_Color = QColor ( " #FFFFCC " ) ;
opMode_Minimal_Color = QColor ( " #FFCCCC " ) ;
2012-11-25 22:50:38 +00:00
/* add the options */
addItem ( tr ( " Normal Mode " ) , RS_OPMODE_FULL ) ;
2016-02-07 11:45:55 +01:00
setItemData ( 0 , opMode_Full_Color , Qt : : BackgroundRole ) ;
2012-11-25 22:50:38 +00:00
addItem ( tr ( " No Anon D/L " ) , RS_OPMODE_NOTURTLE ) ;
2016-02-07 11:45:55 +01:00
setItemData ( 1 , opMode_NoTurtle_Color , Qt : : BackgroundRole ) ;
2012-11-25 22:50:38 +00:00
addItem ( tr ( " Gaming Mode " ) , RS_OPMODE_GAMING ) ;
2016-02-07 11:45:55 +01:00
setItemData ( 2 , opMode_Gaming_Color , Qt : : BackgroundRole ) ;
2012-11-25 22:50:38 +00:00
addItem ( tr ( " Low Traffic " ) , RS_OPMODE_MINIMAL ) ;
2016-02-07 11:45:55 +01:00
setItemData ( 3 , opMode_Minimal_Color , Qt : : BackgroundRole ) ;
2012-11-25 22:50:38 +00:00
connect ( this , SIGNAL ( activated ( int ) ) , this , SLOT ( setOpMode ( ) ) ) ;
2012-12-09 22:27:34 +00:00
2016-02-07 11:45:55 +01:00
setCurrentIndex ( Settings - > valueFromGroup ( " StatusBar " , " OpMode " , QVariant ( 0 ) ) . toInt ( ) ) ;
setOpMode ( ) ;
2012-12-09 22:27:34 +00:00
setToolTip ( tr ( " Use this DropList to quickly change Retroshare's behaviour \n No Anon D/L: switches off file forwarding \n Gaming Mode: 25% standard traffic and TODO: reduced popups \n Low Traffic: 10% standard traffic and TODO: pauses all file-transfers " ) ) ;
2013-01-03 14:08:39 +00:00
setFocusPolicy ( Qt : : ClickFocus ) ;
2012-11-25 22:50:38 +00:00
}
void OpModeStatus : : getOpMode ( )
{
int opMode = rsConfig - > getOperatingMode ( ) ;
switch ( opMode )
{
default :
case RS_OPMODE_FULL :
setCurrentIndex ( 0 ) ;
2016-02-07 11:45:55 +01:00
setProperty ( " opMode " , " Full " ) ;
break ;
2012-11-25 22:50:38 +00:00
case RS_OPMODE_NOTURTLE :
setCurrentIndex ( 1 ) ;
2016-02-07 11:45:55 +01:00
setProperty ( " opMode " , " NoTurtle " ) ;
break ;
2012-11-25 22:50:38 +00:00
case RS_OPMODE_GAMING :
setCurrentIndex ( 2 ) ;
2016-02-07 11:45:55 +01:00
setProperty ( " opMode " , " Gaming " ) ;
break ;
2012-11-25 22:50:38 +00:00
case RS_OPMODE_MINIMAL :
setCurrentIndex ( 3 ) ;
2016-02-07 11:45:55 +01:00
setProperty ( " opMode " , " Minimal " ) ;
break ;
2012-11-25 22:50:38 +00:00
}
2016-02-07 11:45:55 +01:00
onUpdate = true ;
style ( ) - > unpolish ( this ) ;
style ( ) - > polish ( this ) ;
update ( ) ;
onUpdate = false ;
2012-11-25 22:50:38 +00:00
}
void OpModeStatus : : setOpMode ( )
{
std : : cerr < < " OpModeStatus::setOpMode() " ;
std : : cerr < < std : : endl ;
2016-02-07 11:45:55 +01:00
int idx = currentIndex ( ) ;
QVariant var = itemData ( idx ) ;
uint32_t opMode = var . toUInt ( ) ;
2012-11-25 22:50:38 +00:00
2017-05-10 21:37:06 +02:00
QString message = tr ( " <p>Warning: This Operating mode disables the tunneling service. This means you can use distant chat not anonymously download files and the mail service will be slower.</p><p>This state will be saved after restart, so do not forget that you changed it!</p> " ) ;
if ( opMode = = RS_OPMODE_NOTURTLE & & ! Settings - > getPageAlreadyDisplayed ( QString ( " RS_OPMODE_NO_TURTLE " ) ) )
{
QMessageBox : : warning ( NULL , tr ( " Turtle routing disabled! " ) , message ) ;
Settings - > setPageAlreadyDisplayed ( QString ( " RS_OPMODE_NO_TURTLE " ) , true ) ;
}
if ( ( opMode = = RS_OPMODE_MINIMAL & & ! Settings - > getPageAlreadyDisplayed ( QString ( " RS_OPMODE_MINIMAL " ) ) ) )
{
QMessageBox : : warning ( NULL , tr ( " Turtle routing disabled! " ) , message ) ;
Settings - > setPageAlreadyDisplayed ( QString ( " RS_OPMODE_MINIMAL " ) , true ) ;
}
2012-11-25 22:50:38 +00:00
rsConfig - > setOperatingMode ( opMode ) ;
// reload to be safe.
getOpMode ( ) ;
2016-02-07 11:45:55 +01:00
Settings - > setValueToGroup ( " StatusBar " , " OpMode " , idx ) ;
}
QColor OpModeStatus : : getOpMode_Full_Color ( ) const
{
return opMode_Full_Color ;
}
void OpModeStatus : : setOpMode_Full_Color ( QColor c )
{
opMode_Full_Color = c ;
setItemData ( 0 , opMode_Full_Color , Qt : : BackgroundRole ) ;
if ( ! onUpdate )
getOpMode ( ) ;
}
QColor OpModeStatus : : getOpMode_NoTurtle_Color ( ) const
{
return opMode_NoTurtle_Color ;
2012-11-25 22:50:38 +00:00
}
2016-02-07 11:45:55 +01:00
void OpModeStatus : : setOpMode_NoTurtle_Color ( QColor c )
{
opMode_NoTurtle_Color = c ;
setItemData ( 1 , opMode_NoTurtle_Color , Qt : : BackgroundRole ) ;
if ( ! onUpdate )
getOpMode ( ) ;
}
2016-02-03 14:02:19 +01:00
2016-02-07 11:45:55 +01:00
QColor OpModeStatus : : getOpMode_Gaming_Color ( ) const
{
return opMode_Gaming_Color ;
}
void OpModeStatus : : setOpMode_Gaming_Color ( QColor c )
{
opMode_Gaming_Color = c ;
setItemData ( 2 , opMode_Gaming_Color , Qt : : BackgroundRole ) ;
if ( ! onUpdate )
getOpMode ( ) ;
}
QColor OpModeStatus : : getOpMode_Minimal_Color ( ) const
{
return opMode_Minimal_Color ;
}
void OpModeStatus : : setOpMode_Minimal_Color ( QColor c )
{
opMode_Minimal_Color = c ;
setItemData ( 3 , opMode_Minimal_Color , Qt : : BackgroundRole ) ;
if ( ! onUpdate )
getOpMode ( ) ;
}