2009-07-23 13:11:51 -04:00
|
|
|
/****************************************************************
|
|
|
|
* RetroShare is distributed under the following license:
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 -2009 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
|
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.
|
|
|
|
****************************************************************/
|
|
|
|
|
2010-07-23 14:52:58 -04:00
|
|
|
#include <QMessageBox>
|
|
|
|
|
2012-02-18 09:55:50 -05:00
|
|
|
#include <retroshare/rsplugin.h>
|
2009-07-23 13:11:51 -04:00
|
|
|
#include "GeneralPage.h"
|
|
|
|
#include "DirectoriesPage.h"
|
|
|
|
#include "ServerPage.h"
|
|
|
|
#include "NetworkPage.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"
|
2011-12-19 21:09:27 -05:00
|
|
|
#include "RelayPage.h"
|
2010-05-03 17:17:36 -04:00
|
|
|
#include "ChatPage.h"
|
2010-05-21 09:54:40 -04:00
|
|
|
#include "MessagePage.h"
|
2010-08-08 18:58:10 -04:00
|
|
|
#include "ForumPage.h"
|
2011-06-17 15:59:01 -04:00
|
|
|
#include "PluginsPage.h"
|
2009-07-23 13:11:51 -04:00
|
|
|
|
|
|
|
#define IMAGE_GENERAL ":/images/kcmsystem24.png"
|
|
|
|
|
|
|
|
|
|
|
|
#include "rsettingswin.h"
|
|
|
|
|
2010-04-24 18:09:47 -04:00
|
|
|
RSettingsWin *RSettingsWin::_instance = NULL;
|
|
|
|
int RSettingsWin::lastPage = 0;
|
|
|
|
|
2009-07-23 13:11:51 -04:00
|
|
|
RSettingsWin::RSettingsWin(QWidget * parent, Qt::WFlags flags)
|
|
|
|
: QDialog(parent, flags)
|
|
|
|
{
|
|
|
|
setupUi(this);
|
2010-04-24 18:09:47 -04:00
|
|
|
setAttribute(Qt::WA_DeleteOnClose, true);
|
2009-07-23 13:11:51 -04:00
|
|
|
setModal(false);
|
|
|
|
|
|
|
|
initStackedWidget();
|
|
|
|
|
2009-08-19 18:15:16 -04:00
|
|
|
connect(listWidget, SIGNAL(currentRowChanged(int)), this, SLOT(setNewPage(int)));
|
2010-05-16 05:54:21 -04:00
|
|
|
connect(applyButton, SIGNAL(clicked( bool )), this, SLOT( saveChanges()) );
|
2009-08-19 18:15:16 -04:00
|
|
|
}
|
2009-07-23 13:11:51 -04:00
|
|
|
|
2010-04-24 18:09:47 -04:00
|
|
|
RSettingsWin::~RSettingsWin()
|
|
|
|
{
|
|
|
|
lastPage = stackedWidget->currentIndex ();
|
|
|
|
_instance = NULL;
|
|
|
|
}
|
|
|
|
|
2012-02-08 07:11:15 -05:00
|
|
|
/*static*/ void RSettingsWin::showYourself(QWidget *parent, PageType page /* = LastPage*/)
|
2010-04-24 18:09:47 -04:00
|
|
|
{
|
|
|
|
if(_instance == NULL) {
|
|
|
|
_instance = new RSettingsWin(parent);
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*static*/ void RSettingsWin::postModDirectories(bool update_local)
|
|
|
|
{
|
|
|
|
if (_instance == NULL || _instance->isHidden() || _instance->stackedWidget == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (update_local) {
|
|
|
|
if (_instance->stackedWidget->currentIndex() == Directories) {
|
2010-04-25 19:28:10 -04:00
|
|
|
ConfigPage *Page = dynamic_cast<ConfigPage *> (_instance->stackedWidget->currentWidget());
|
2010-04-24 18:09:47 -04:00
|
|
|
if (Page) {
|
|
|
|
Page->load();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-23 13:11:51 -04:00
|
|
|
void
|
|
|
|
RSettingsWin::initStackedWidget()
|
|
|
|
{
|
|
|
|
stackedWidget->setCurrentIndex(-1);
|
|
|
|
stackedWidget->removeWidget(stackedWidget->widget(0));
|
|
|
|
|
2012-02-18 09:55:50 -05:00
|
|
|
addPage(new GeneralPage(0));
|
|
|
|
addPage(new ServerPage());
|
|
|
|
addPage(new TransferPage());
|
|
|
|
addPage(new RelayPage() );
|
|
|
|
addPage(new DirectoriesPage());
|
|
|
|
addPage(new PluginsPage() );
|
|
|
|
addPage(new NotifyPage());
|
|
|
|
addPage(new CryptoPage());
|
|
|
|
addPage(new MessagePage());
|
|
|
|
addPage(new ForumPage());
|
|
|
|
addPage(new ChatPage());
|
|
|
|
addPage(new AppearancePage());
|
|
|
|
addPage(new SoundPage() );
|
|
|
|
|
|
|
|
// add widgets from plugins
|
|
|
|
|
|
|
|
for(int i=0;i<rsPlugins->nbPlugins();++i)
|
|
|
|
{
|
|
|
|
RsPlugin *pl = rsPlugins->plugin(i) ;
|
|
|
|
|
|
|
|
if(pl->qt_config_page() != NULL)
|
2012-02-18 15:29:03 -05:00
|
|
|
addPage(pl->qt_config_page()) ;
|
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);
|
|
|
|
}
|
|
|
|
|
2012-02-18 09:55:50 -05:00
|
|
|
void RSettingsWin::addPage(ConfigPage *page)
|
|
|
|
{
|
|
|
|
stackedWidget->addWidget(page) ;
|
|
|
|
|
|
|
|
QListWidgetItem *item = new QListWidgetItem(QIcon(page->iconPixmap()),page->pageName()) ;
|
|
|
|
listWidget->addItem(item) ;
|
|
|
|
}
|
|
|
|
|
2009-07-23 13:11:51 -04:00
|
|
|
void
|
|
|
|
RSettingsWin::setNewPage(int page)
|
|
|
|
{
|
2012-02-18 09:55:50 -05:00
|
|
|
ConfigPage *pagew = dynamic_cast<ConfigPage*>(stackedWidget->widget(page)) ;
|
|
|
|
|
|
|
|
if(pagew == NULL)
|
|
|
|
{
|
|
|
|
std::cerr << "Error in RSettingsWin::setNewPage(): widget is not a ConfigPage!" << std::endl;
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
pageName->setText(pagew->pageName());
|
|
|
|
pageicon->setPixmap(pagew->iconPixmap()) ;
|
2009-08-19 18:15:16 -04:00
|
|
|
|
2012-02-18 09:55:50 -05:00
|
|
|
stackedWidget->setCurrentIndex(page);
|
|
|
|
listWidget->setCurrentRow(page);
|
2009-07-23 13:11:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Saves changes made to settings. */
|
|
|
|
void
|
|
|
|
RSettingsWin::saveChanges()
|
|
|
|
{
|
2009-08-19 18:15:16 -04:00
|
|
|
QString errmsg;
|
2009-07-23 13:11:51 -04:00
|
|
|
|
2009-08-19 18:15:16 -04:00
|
|
|
/* Call each config page's save() method to save its data */
|
|
|
|
int i, count = stackedWidget->count();
|
2010-04-10 10:56:34 -04:00
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
ConfigPage *page = dynamic_cast<ConfigPage *>(stackedWidget->widget(i));
|
2011-06-14 20:40:07 -04:00
|
|
|
if (page && page->wasLoaded()) {
|
|
|
|
if (!page->save(errmsg))
|
|
|
|
{
|
|
|
|
/* Display the offending page */
|
|
|
|
stackedWidget->setCurrentWidget(page);
|
|
|
|
|
|
|
|
/* Show the user what went wrong */
|
|
|
|
QMessageBox::warning(this,
|
|
|
|
tr("Error Saving Configuration on page ")+QString::number(i), errmsg,
|
|
|
|
QMessageBox::Ok, QMessageBox::NoButton);
|
|
|
|
|
|
|
|
/* Don't process the rest of the pages */
|
|
|
|
return;
|
|
|
|
}
|
2009-08-19 18:15:16 -04:00
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
2011-06-14 20:40:07 -04:00
|
|
|
close();
|
2009-08-19 18:15:16 -04:00
|
|
|
}
|