2018-12-23 12:03:08 -05:00
|
|
|
/*******************************************************************************
|
|
|
|
* gui/settings/rsettingswin.cpp *
|
|
|
|
* *
|
|
|
|
* Copyright (c) 2008, Retroshare Team <retroshare.project@gmail.com> *
|
|
|
|
* *
|
|
|
|
* This program is free software: you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU Affero General Public License as *
|
|
|
|
* published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU Affero General Public License *
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
|
|
|
* *
|
|
|
|
*******************************************************************************/
|
2009-07-23 13:11:51 -04:00
|
|
|
|
2010-07-23 14:52:58 -04:00
|
|
|
#include <QMessageBox>
|
|
|
|
|
2012-02-18 09:55:50 -05:00
|
|
|
#include <retroshare/rsplugin.h>
|
2012-09-25 19:51:13 -04:00
|
|
|
#include <rshare.h>
|
2009-07-23 13:11:51 -04:00
|
|
|
#include "GeneralPage.h"
|
|
|
|
#include "ServerPage.h"
|
|
|
|
#include "NotifyPage.h"
|
|
|
|
#include "CryptoPage.h"
|
|
|
|
#include "AppearancePage.h"
|
|
|
|
#include "FileAssociationsPage.h"
|
|
|
|
#include "SoundPage.h"
|
2010-01-27 15:24:49 -05:00
|
|
|
#include "TransferPage.h"
|
2010-05-03 17:17:36 -04:00
|
|
|
#include "ChatPage.h"
|
2014-05-08 13:17:48 -04:00
|
|
|
#include "ChannelPage.h"
|
2016-04-02 16:14:08 -04:00
|
|
|
#include "PeoplePage.h"
|
2010-05-21 09:54:40 -04:00
|
|
|
#include "MessagePage.h"
|
2014-04-14 18:36:10 -04:00
|
|
|
#include "ForumPage.h"
|
2017-01-24 16:39:28 -05:00
|
|
|
#include "AboutPage.h"
|
2014-07-24 10:54:23 -04:00
|
|
|
#include "PostedPage.h"
|
2011-06-17 15:59:01 -04:00
|
|
|
#include "PluginsPage.h"
|
2014-03-07 08:48:33 -05:00
|
|
|
#include "ServicePermissionsPage.h"
|
2012-09-25 19:51:13 -04:00
|
|
|
#include "rsharesettings.h"
|
2013-01-05 21:30:10 -05:00
|
|
|
#include "gui/notifyqt.h"
|
2013-10-09 05:31:40 -04:00
|
|
|
#include "gui/common/FloatingHelpBrowser.h"
|
2017-03-05 07:22:30 -05:00
|
|
|
#include "gui/common/RSElidedItemDelegate.h"
|
2009-07-23 13:11:51 -04:00
|
|
|
|
2019-11-10 11:38:16 -05:00
|
|
|
#ifdef RS_WEBUI
|
2018-04-15 06:41:54 -04:00
|
|
|
# include "WebuiPage.h"
|
|
|
|
#endif
|
|
|
|
|
2018-09-20 19:58:38 -04:00
|
|
|
#ifdef RS_JSONAPI
|
|
|
|
# include "JsonApiPage.h"
|
|
|
|
#endif
|
|
|
|
|
2009-07-23 13:11:51 -04:00
|
|
|
#define IMAGE_GENERAL ":/images/kcmsystem24.png"
|
|
|
|
|
2017-03-05 07:22:30 -05:00
|
|
|
#define ITEM_SPACING 2
|
|
|
|
|
2009-07-23 13:11:51 -04:00
|
|
|
#include "rsettingswin.h"
|
|
|
|
|
2017-01-26 16:35:33 -05:00
|
|
|
//RSettingsWin *RSettingsWin::_instance = NULL;
|
|
|
|
int SettingsPage::lastPage = 0;
|
2010-04-24 18:09:47 -04:00
|
|
|
|
2017-01-26 16:35:33 -05:00
|
|
|
SettingsPage::SettingsPage(QWidget *parent)
|
|
|
|
: MainPage(parent, Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint)
|
2009-07-23 13:11:51 -04:00
|
|
|
{
|
2014-05-10 14:05:18 -04:00
|
|
|
ui.setupUi(this);
|
2010-04-24 18:09:47 -04:00
|
|
|
setAttribute(Qt::WA_DeleteOnClose, true);
|
2009-07-23 13:11:51 -04:00
|
|
|
|
2013-10-09 05:31:40 -04:00
|
|
|
/* Initialize help browser */
|
2014-05-10 14:05:18 -04:00
|
|
|
mHelpBrowser = new FloatingHelpBrowser(this, ui.helpButton);
|
2013-10-09 05:31:40 -04:00
|
|
|
|
2017-03-05 07:22:30 -05:00
|
|
|
/* Add own item delegate to get item width*/
|
|
|
|
RSElidedItemDelegate *itemDelegate = new RSElidedItemDelegate(this);
|
|
|
|
itemDelegate->setSpacing(QSize(0, ITEM_SPACING));
|
|
|
|
ui.listWidget->setItemDelegate(itemDelegate);
|
|
|
|
|
2009-07-23 13:11:51 -04:00
|
|
|
initStackedWidget();
|
|
|
|
|
2014-05-10 14:05:18 -04:00
|
|
|
/* Load window position */
|
|
|
|
QByteArray geometry = Settings->valueFromGroup("SettingDialog", "Geometry", QByteArray()).toByteArray();
|
|
|
|
if (geometry.isEmpty() == false) {
|
|
|
|
restoreGeometry(geometry);
|
|
|
|
}
|
|
|
|
|
|
|
|
connect(ui.listWidget, SIGNAL(currentRowChanged(int)), this, SLOT(setNewPage(int)));
|
2012-09-25 19:51:13 -04:00
|
|
|
connect(this, SIGNAL(finished(int)), this, SLOT(dialogFinished(int)));
|
2009-08-19 18:15:16 -04:00
|
|
|
}
|
2009-07-23 13:11:51 -04:00
|
|
|
|
2017-01-26 16:35:33 -05:00
|
|
|
SettingsPage::~SettingsPage()
|
2010-04-24 18:09:47 -04:00
|
|
|
{
|
2014-05-10 14:05:18 -04:00
|
|
|
/* Save window position */
|
|
|
|
Settings->setValueToGroup("SettingDialog", "Geometry", saveGeometry());
|
|
|
|
lastPage = ui.stackedWidget->currentIndex ();
|
2017-01-26 16:35:33 -05:00
|
|
|
//_instance = NULL;
|
2010-04-24 18:09:47 -04:00
|
|
|
}
|
|
|
|
|
2017-01-26 16:35:33 -05:00
|
|
|
//void RSettingsPage::dialogFinished(int result)
|
|
|
|
//{
|
|
|
|
// if (result == Rejected) {
|
|
|
|
// /* reaload style sheet */
|
|
|
|
// Rshare::loadStyleSheet(::Settings->getSheetName());
|
|
|
|
// }
|
|
|
|
//}
|
2012-09-25 19:51:13 -04:00
|
|
|
|
2017-02-27 16:12:48 -05:00
|
|
|
/*static*/ void SettingsPage::showYourself(QWidget */*parent*/, PageType /*page = LastPage*/)
|
2010-04-24 18:09:47 -04:00
|
|
|
{
|
2017-01-26 16:35:33 -05:00
|
|
|
#ifdef TODO
|
2010-04-24 18:09:47 -04:00
|
|
|
if(_instance == NULL) {
|
2017-01-26 16:35:33 -05:00
|
|
|
_instance = new RSettingsPage(parent);
|
2010-04-24 18:09:47 -04:00
|
|
|
}
|
|
|
|
|
2011-03-26 18:17:15 -04:00
|
|
|
if (page != LastPage) {
|
|
|
|
/* show given page */
|
|
|
|
_instance->setNewPage(page);
|
|
|
|
} else {
|
|
|
|
if (_instance->isHidden()) {
|
|
|
|
_instance->setNewPage(lastPage);
|
|
|
|
}
|
2010-04-24 18:09:47 -04:00
|
|
|
}
|
2011-03-26 18:17:15 -04:00
|
|
|
|
2010-04-24 18:09:47 -04:00
|
|
|
_instance->show();
|
|
|
|
_instance->activateWindow();
|
2017-01-26 16:35:33 -05:00
|
|
|
#else
|
|
|
|
std::cerr << "(EE) unimplemented call to RSettingsPage::showYourself" << std::endl;
|
|
|
|
#endif
|
2010-04-24 18:09:47 -04:00
|
|
|
}
|
|
|
|
|
2017-01-26 16:35:33 -05:00
|
|
|
/*static*/ void SettingsPage::postModDirectories(bool update_local)
|
2010-04-24 18:09:47 -04:00
|
|
|
{
|
2017-01-26 16:35:33 -05:00
|
|
|
//if (_instance == NULL || _instance->isHidden() || _instance->ui.stackedWidget == NULL) {
|
|
|
|
if (ui.stackedWidget == NULL) {
|
2010-04-24 18:09:47 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (update_local) {
|
2017-01-26 16:35:33 -05:00
|
|
|
if (ui.stackedWidget->currentIndex() == Directories) {
|
|
|
|
ConfigPage *Page = dynamic_cast<ConfigPage *> (ui.stackedWidget->currentWidget());
|
2010-04-24 18:09:47 -04:00
|
|
|
if (Page) {
|
|
|
|
Page->load();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-23 13:11:51 -04:00
|
|
|
void
|
2017-01-26 16:35:33 -05:00
|
|
|
SettingsPage::initStackedWidget()
|
2009-07-23 13:11:51 -04:00
|
|
|
{
|
2014-05-10 14:05:18 -04:00
|
|
|
ui.stackedWidget->setCurrentIndex(-1);
|
|
|
|
ui.stackedWidget->removeWidget(ui.stackedWidget->widget(0));
|
2009-07-23 13:11:51 -04:00
|
|
|
|
2017-03-03 08:23:50 -05:00
|
|
|
addPage(new GeneralPage()); // GENERAL
|
|
|
|
addPage(new CryptoPage()); // NODE
|
|
|
|
addPage(new ServerPage()); // NETWORK
|
|
|
|
addPage(new PeoplePage()); // PEOLPE
|
|
|
|
addPage(new ChatPage()); // CHAT
|
|
|
|
addPage(new MessagePage()); //MESSGE RENAME TO MAIL
|
|
|
|
addPage(new TransferPage()); //FILE TRANSFER
|
|
|
|
addPage(new ChannelPage()); // CHANNELS
|
|
|
|
addPage(new ForumPage()); // FORUMS
|
|
|
|
addPage(new PostedPage()); // POSTED RENAME TO LINKS
|
|
|
|
addPage(new NotifyPage()); // NOTIFY
|
2018-07-06 10:55:12 -04:00
|
|
|
addPage(new settings::PluginsPage() ); // PLUGINS
|
2017-03-03 08:23:50 -05:00
|
|
|
addPage(new AppearancePage()); // APPEARENCE
|
|
|
|
addPage(new SoundPage() ); // SOUND
|
|
|
|
addPage(new ServicePermissionsPage() ); // PERMISSIONS
|
2019-11-16 12:19:07 -05:00
|
|
|
#ifdef RS_JSONAPI
|
|
|
|
JsonApiPage *jsonapi_p = new JsonApiPage() ;
|
|
|
|
addPage(new JsonApiPage());
|
2019-11-10 11:38:16 -05:00
|
|
|
#ifdef RS_WEBUI
|
2019-11-16 12:19:07 -05:00
|
|
|
WebuiPage *webui_p = new WebuiPage() ;
|
2015-04-24 10:31:13 -04:00
|
|
|
addPage(new WebuiPage() );
|
2012-02-18 09:55:50 -05:00
|
|
|
|
2019-11-16 12:19:07 -05:00
|
|
|
QObject::connect(webui_p,SIGNAL(passwordChanged()),jsonapi_p,SLOT(load()));
|
|
|
|
#endif
|
2018-09-20 19:58:38 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// add widgets from plugins
|
2015-07-30 05:11:16 -04:00
|
|
|
for(int i=0;i<rsPlugins->nbPlugins();++i)
|
|
|
|
{
|
|
|
|
RsPlugin *pl = rsPlugins->plugin(i) ;
|
|
|
|
if(pl != NULL)
|
|
|
|
{
|
|
|
|
ConfigPage* cp = pl->qt_config_page();
|
|
|
|
if(cp != NULL)
|
|
|
|
addPage(cp) ;
|
|
|
|
}
|
|
|
|
}
|
2017-01-24 16:39:28 -05:00
|
|
|
addPage(new AboutPage() );
|
2012-02-18 09:55:50 -05:00
|
|
|
|
|
|
|
// make the first page the default.
|
2009-08-19 18:15:16 -04:00
|
|
|
|
2009-07-23 13:11:51 -04:00
|
|
|
setNewPage(General);
|
|
|
|
}
|
|
|
|
|
2017-01-26 16:35:33 -05:00
|
|
|
void SettingsPage::addPage(ConfigPage *page)
|
2012-02-18 09:55:50 -05:00
|
|
|
{
|
2014-05-10 14:05:18 -04:00
|
|
|
ui.stackedWidget->addWidget(page) ;
|
2012-02-18 09:55:50 -05:00
|
|
|
|
2017-03-05 07:22:30 -05:00
|
|
|
QListWidgetItem *item = new QListWidgetItem(QIcon(page->iconPixmap()),page->pageName(),ui.listWidget) ;
|
|
|
|
QFontMetrics fontMetrics = ui.listWidget->fontMetrics();
|
|
|
|
int w = ITEM_SPACING*8;
|
|
|
|
w += ui.listWidget->iconSize().width();
|
|
|
|
w += fontMetrics.width(item->text());
|
|
|
|
if (w > ui.listWidget->maximumWidth())
|
|
|
|
ui.listWidget->setMaximumWidth(w);
|
2012-02-18 09:55:50 -05:00
|
|
|
}
|
|
|
|
|
2009-07-23 13:11:51 -04:00
|
|
|
void
|
2017-01-26 16:35:33 -05:00
|
|
|
SettingsPage::setNewPage(int page)
|
2009-07-23 13:11:51 -04:00
|
|
|
{
|
2014-05-10 14:05:18 -04:00
|
|
|
ConfigPage *pagew = dynamic_cast<ConfigPage*>(ui.stackedWidget->widget(page)) ;
|
2012-02-18 09:55:50 -05:00
|
|
|
|
2013-10-09 05:31:40 -04:00
|
|
|
mHelpBrowser->hide();
|
|
|
|
|
2012-02-18 09:55:50 -05:00
|
|
|
if(pagew == NULL)
|
|
|
|
{
|
2017-01-26 16:35:33 -05:00
|
|
|
std::cerr << "Error in RSettingsPage::setNewPage(): widget is not a ConfigPage!" << std::endl;
|
2013-10-09 05:31:40 -04:00
|
|
|
mHelpBrowser->clear();
|
2012-02-18 09:55:50 -05:00
|
|
|
return ;
|
|
|
|
}
|
2014-05-10 14:05:18 -04:00
|
|
|
ui.pageName->setText(pagew->pageName());
|
|
|
|
ui.pageicon->setPixmap(pagew->iconPixmap()) ;
|
2009-08-19 18:15:16 -04:00
|
|
|
|
2014-05-10 14:05:18 -04:00
|
|
|
ui.stackedWidget->setCurrentIndex(page);
|
|
|
|
ui.listWidget->setCurrentRow(page);
|
2013-10-09 05:31:40 -04:00
|
|
|
|
|
|
|
mHelpBrowser->setHelpText(pagew->helpText());
|
2009-07-23 13:11:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Saves changes made to settings. */
|
2017-01-28 12:13:38 -05:00
|
|
|
void SettingsPage::notifySettingsChanged()
|
2009-07-23 13:11:51 -04:00
|
|
|
{
|
2009-08-19 18:15:16 -04:00
|
|
|
/* call to RsIface save function.... */
|
|
|
|
//rsicontrol -> ConfigSave();
|
2009-07-23 13:11:51 -04:00
|
|
|
|
2017-01-28 12:13:38 -05:00
|
|
|
if (NotifyQt::getInstance())
|
2013-01-05 21:30:10 -05:00
|
|
|
NotifyQt::getInstance()->notifySettingsChanged();
|
2009-08-19 18:15:16 -04:00
|
|
|
}
|