2009-07-23 13:11:51 -04:00
|
|
|
/****************************************************************
|
|
|
|
* This file is distributed under the following license:
|
|
|
|
*
|
2009-08-17 17:19:50 -04:00
|
|
|
* Copyright (c) 2009 RetroShare Team
|
2009-07-23 13:11:51 -04:00
|
|
|
*
|
|
|
|
* 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
|
2009-08-19 18:15:16 -04:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
2009-07-23 13:11:51 -04:00
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
****************************************************************/
|
|
|
|
|
2011-08-16 20:06:44 -04:00
|
|
|
#include <QMessageBox>
|
2010-04-08 07:55:10 -04:00
|
|
|
#include <iostream>
|
|
|
|
#include <rshare.h>
|
2011-07-30 13:13:08 -04:00
|
|
|
#include "retroshare/rsinit.h"
|
|
|
|
#include "retroshare/rsconfig.h"
|
|
|
|
|
2009-08-17 17:19:50 -04:00
|
|
|
#include "GeneralPage.h"
|
2009-07-23 13:11:51 -04:00
|
|
|
#include <util/stringutil.h>
|
2017-02-27 17:13:45 -05:00
|
|
|
#include <util/misc.h>
|
2009-07-23 13:11:51 -04:00
|
|
|
#include <QSystemTrayIcon>
|
2010-05-11 16:02:52 -04:00
|
|
|
#include "rsharesettings.h"
|
2009-07-23 13:11:51 -04:00
|
|
|
|
2009-08-17 17:19:50 -04:00
|
|
|
/** Constructor */
|
2016-12-15 05:20:13 -05:00
|
|
|
GeneralPage::GeneralPage(QWidget * parent, Qt::WindowFlags flags) :
|
|
|
|
ConfigPage(parent, flags)
|
2009-07-23 13:11:51 -04:00
|
|
|
{
|
2011-08-16 20:06:44 -04:00
|
|
|
/* Invoke the Qt Designer generated object setup routine */
|
|
|
|
ui.setupUi(this);
|
2009-07-23 13:11:51 -04:00
|
|
|
|
2011-08-16 20:06:44 -04:00
|
|
|
/* Hide platform specific features */
|
2015-08-29 15:31:01 -04:00
|
|
|
#ifdef Q_OS_WIN
|
2013-08-08 08:46:32 -04:00
|
|
|
|
|
|
|
#ifdef QT_DEBUG
|
|
|
|
ui.chkRunRetroshareAtSystemStartup->setEnabled(false);
|
|
|
|
ui.chkRunRetroshareAtSystemStartupMinimized->setEnabled(false);
|
|
|
|
#endif
|
2016-06-14 09:10:15 -04:00
|
|
|
ui.desktopFileMissingLabel->setVisible(false);
|
2013-08-08 08:46:32 -04:00
|
|
|
|
2011-08-16 20:06:44 -04:00
|
|
|
#else
|
|
|
|
ui.chkRunRetroshareAtSystemStartup->setVisible(false);
|
|
|
|
ui.chkRunRetroshareAtSystemStartupMinimized->setVisible(false);
|
2016-03-01 07:08:33 -05:00
|
|
|
ui.registerRetroShareProtocol->setVisible(false);
|
2011-08-16 20:06:44 -04:00
|
|
|
ui.adminLabel->setVisible(false);
|
2009-08-19 18:15:16 -04:00
|
|
|
#endif
|
2016-03-01 07:08:33 -05:00
|
|
|
|
|
|
|
if (Settings->canSetRetroShareProtocol()) {
|
|
|
|
ui.registerRetroShareProtocol->setEnabled(true);
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
ui.adminLabel->setEnabled(true);
|
|
|
|
ui.adminLabel->setToolTip(tr("You have enough right."));
|
|
|
|
#else
|
|
|
|
ui.desktopFileMissingLabel->setVisible(false);
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
ui.registerRetroShareProtocol->setEnabled(false);
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
ui.adminLabel->setEnabled(false);
|
|
|
|
ui.adminLabel->setToolTip(tr("You don't have enough right. Run RetroShare as Admin to change this setting."));
|
|
|
|
#else
|
|
|
|
ui.desktopFileMissingLabel->setVisible(true);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
ui.useLocalServer->setEnabled(true);
|
2016-12-15 05:20:13 -05:00
|
|
|
|
|
|
|
#ifdef RS_AUTOLOGIN
|
|
|
|
ui.autoLogin->setToolTip(tr("For security reasons the usage of auto-login is discouraged, you can enable it but you are on your own!"));
|
|
|
|
#else // RS_AUTOLOGIN
|
|
|
|
ui.autoLogin->setEnabled(false);
|
|
|
|
ui.autoLogin->setToolTip(tr("Your RetroShare build has auto-login disabled."));
|
|
|
|
#endif // RS_AUTOLOGIN
|
2017-01-28 12:13:38 -05:00
|
|
|
|
|
|
|
/* Connect signals */
|
2017-01-31 15:51:16 -05:00
|
|
|
connect(ui.useLocalServer, SIGNAL(toggled(bool)), this,SLOT(updateUseLocalServer())) ;
|
|
|
|
connect(ui.idleSpinBox, SIGNAL(valueChanged(int)), this,SLOT(updateMaxTimeBeforeIdle())) ;
|
|
|
|
connect(ui.checkStartMinimized, SIGNAL(toggled(bool)), this,SLOT(updateStartMinimized())) ;
|
|
|
|
connect(ui.checkQuit, SIGNAL(toggled(bool)), this,SLOT(updateDoQuit())) ;
|
|
|
|
connect(ui.checkCloseToTray, SIGNAL(toggled(bool)), this,SLOT(updateCloseToTray())) ;
|
|
|
|
connect(ui.autoLogin, SIGNAL(toggled(bool)), this,SLOT(updateAutoLogin())) ;
|
|
|
|
connect(ui.chkRunRetroshareAtSystemStartup, SIGNAL(toggled(bool)), this,SLOT(updateRunRSOnBoot())) ;
|
|
|
|
connect(ui.chkRunRetroshareAtSystemStartupMinimized, SIGNAL(toggled(bool)), this,SLOT(updateRunRSOnBoot())) ;
|
2017-03-01 14:36:36 -05:00
|
|
|
//connect(ui.runStartWizard_PB, SIGNAL(clicked()), this,SLOT(runStartWizard())) ;
|
2017-01-31 15:51:16 -05:00
|
|
|
connect(ui.checkAdvanced, SIGNAL(toggled(bool)), this,SLOT(updateAdvancedMode())) ;
|
|
|
|
connect(ui.registerRetroShareProtocol, SIGNAL(toggled(bool)), this,SLOT(updateRegisterRSProtocol())) ;
|
2009-07-23 13:11:51 -04:00
|
|
|
}
|
|
|
|
|
2009-08-17 17:19:50 -04:00
|
|
|
/** Destructor */
|
2010-05-07 19:58:17 -04:00
|
|
|
GeneralPage::~GeneralPage()
|
2009-07-23 13:11:51 -04:00
|
|
|
{
|
2010-05-07 19:58:17 -04:00
|
|
|
}
|
2009-07-23 13:11:51 -04:00
|
|
|
|
2017-01-28 12:13:38 -05:00
|
|
|
void GeneralPage::updateAdvancedMode()
|
|
|
|
{
|
|
|
|
if (ui.checkAdvanced->isChecked())
|
|
|
|
{
|
|
|
|
std::string opt("YES");
|
|
|
|
rsConfig->setConfigurationOption(RS_CONFIG_ADVANCED, opt);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::string opt("NO");
|
|
|
|
rsConfig->setConfigurationOption(RS_CONFIG_ADVANCED, opt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GeneralPage::updateUseLocalServer() { Settings->setUseLocalServer(ui.useLocalServer->isChecked()); }
|
|
|
|
void GeneralPage::updateMaxTimeBeforeIdle(){ Settings->setMaxTimeBeforeIdle(ui.idleSpinBox->value()); }
|
|
|
|
void GeneralPage::updateStartMinimized() { Settings->setStartMinimized(ui.checkStartMinimized->isChecked()); }
|
|
|
|
void GeneralPage::updateDoQuit() { Settings->setValue("doQuit", ui.checkQuit->isChecked()); }
|
|
|
|
void GeneralPage::updateCloseToTray() { Settings->setCloseToTray(ui.checkCloseToTray->isChecked()); }
|
|
|
|
void GeneralPage::updateAutoLogin() { RsInit::setAutoLogin(ui.autoLogin->isChecked());}
|
|
|
|
void GeneralPage::updateRunRSOnBoot()
|
2009-08-19 18:15:16 -04:00
|
|
|
{
|
2015-08-29 15:31:01 -04:00
|
|
|
#ifdef Q_OS_WIN
|
2013-08-08 08:46:32 -04:00
|
|
|
#ifndef QT_DEBUG
|
2010-12-11 17:46:14 -05:00
|
|
|
Settings->setRunRetroshareOnBoot(ui.chkRunRetroshareAtSystemStartup->isChecked(), ui.chkRunRetroshareAtSystemStartupMinimized->isChecked());
|
2013-08-08 08:46:32 -04:00
|
|
|
#endif
|
2010-12-13 15:34:07 -05:00
|
|
|
#endif
|
2017-01-28 12:13:38 -05:00
|
|
|
}
|
2010-12-13 15:34:07 -05:00
|
|
|
|
2017-01-28 12:13:38 -05:00
|
|
|
void GeneralPage::updateRegisterRSProtocol()
|
|
|
|
{
|
|
|
|
if (ui.registerRetroShareProtocol->isChecked() != Settings->getRetroShareProtocol())
|
|
|
|
{
|
|
|
|
QString error ="";
|
|
|
|
if (Settings->setRetroShareProtocol(ui.registerRetroShareProtocol->isChecked(), error) == false) {
|
|
|
|
if (ui.registerRetroShareProtocol->isChecked()) {
|
|
|
|
QMessageBox::critical(this, tr("Error"), tr("Could not add retroshare:// as protocol.").append("\n").append(error));
|
|
|
|
} else {
|
|
|
|
QMessageBox::critical(this, tr("Error"), tr("Could not remove retroshare:// protocol.").append("\n").append(error));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-07-23 13:11:51 -04:00
|
|
|
}
|
2009-08-19 18:15:16 -04:00
|
|
|
|
2009-07-23 13:11:51 -04:00
|
|
|
/** Loads the settings for this page */
|
2010-12-13 15:34:07 -05:00
|
|
|
void GeneralPage::load()
|
2009-08-19 18:15:16 -04:00
|
|
|
{
|
2015-08-29 15:31:01 -04:00
|
|
|
#ifdef Q_OS_WIN
|
2010-12-11 17:46:14 -05:00
|
|
|
bool minimized;
|
|
|
|
ui.chkRunRetroshareAtSystemStartup->setChecked(Settings->runRetroshareOnBoot(minimized));
|
|
|
|
ui.chkRunRetroshareAtSystemStartupMinimized->setChecked(minimized);
|
2010-12-13 15:34:07 -05:00
|
|
|
#endif
|
2009-08-19 18:15:16 -04:00
|
|
|
|
2017-02-27 17:13:45 -05:00
|
|
|
whileBlocking(ui.checkStartMinimized)->setChecked(Settings->getStartMinimized());
|
2011-07-30 13:13:08 -04:00
|
|
|
|
|
|
|
bool advancedmode = false;
|
|
|
|
std::string advsetting;
|
|
|
|
if (rsConfig->getConfigurationOption(RS_CONFIG_ADVANCED, advsetting) && (advsetting == "YES"))
|
|
|
|
{
|
2016-03-01 07:08:33 -05:00
|
|
|
advancedmode = true;
|
2011-07-30 13:13:08 -04:00
|
|
|
}
|
2017-02-27 17:13:45 -05:00
|
|
|
whileBlocking(ui.checkAdvanced)->setChecked(advancedmode);
|
2011-07-30 13:13:08 -04:00
|
|
|
|
2017-02-27 17:13:45 -05:00
|
|
|
whileBlocking(ui.checkQuit)->setChecked(Settings->value("doQuit", false).toBool());
|
|
|
|
whileBlocking(ui.checkCloseToTray)->setChecked(Settings->getCloseToTray());
|
|
|
|
whileBlocking(ui.autoLogin)->setChecked(RsInit::getAutoLogin());
|
|
|
|
whileBlocking(ui.registerRetroShareProtocol)->setChecked(Settings->getRetroShareProtocol());
|
|
|
|
whileBlocking(ui.useLocalServer)->setChecked(Settings->getUseLocalServer());
|
2016-03-01 07:08:33 -05:00
|
|
|
|
2017-02-27 17:13:45 -05:00
|
|
|
whileBlocking(ui.idleSpinBox)->setValue(Settings->getMaxTimeBeforeIdle());
|
2010-04-08 07:55:10 -04:00
|
|
|
}
|