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.
|
|
|
|
****************************************************************/
|
|
|
|
|
|
|
|
#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"
|
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)));
|
2009-07-23 13:11:51 -04:00
|
|
|
connect(okButton, 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;
|
|
|
|
}
|
|
|
|
|
2009-07-23 13:11:51 -04:00
|
|
|
void
|
|
|
|
RSettingsWin::closeEvent (QCloseEvent * event)
|
|
|
|
{
|
|
|
|
QWidget::closeEvent(event);
|
|
|
|
}
|
|
|
|
|
2010-04-24 18:09:47 -04:00
|
|
|
/*static*/ void RSettingsWin::showYourself(QWidget *parent)
|
|
|
|
{
|
|
|
|
if(_instance == NULL) {
|
|
|
|
_instance = new RSettingsWin(parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_instance->isHidden()) {
|
|
|
|
_instance->setNewPage(lastPage);
|
|
|
|
}
|
|
|
|
_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) {
|
|
|
|
ConfigPage *Page = (ConfigPage*) _instance->stackedWidget->currentWidget();
|
|
|
|
if (Page) {
|
|
|
|
Page->load();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-23 13:11:51 -04:00
|
|
|
void
|
|
|
|
RSettingsWin::initStackedWidget()
|
|
|
|
{
|
|
|
|
stackedWidget->setCurrentIndex(-1);
|
|
|
|
stackedWidget->removeWidget(stackedWidget->widget(0));
|
|
|
|
|
2009-08-19 18:15:16 -04:00
|
|
|
stackedWidget->addWidget(new GeneralPage(false));
|
2009-07-23 13:11:51 -04:00
|
|
|
stackedWidget->addWidget(new ServerPage());
|
2010-01-27 15:24:49 -05:00
|
|
|
stackedWidget->addWidget(new TransferPage());
|
2009-07-23 13:11:51 -04:00
|
|
|
stackedWidget->addWidget(new DirectoriesPage());
|
|
|
|
stackedWidget->addWidget(new NotifyPage());
|
|
|
|
stackedWidget->addWidget(new CryptoPage());
|
|
|
|
stackedWidget->addWidget(new AppearancePage());
|
2010-02-06 16:56:10 -05:00
|
|
|
#ifndef RS_RELEASE_VERSION
|
2009-07-23 13:11:51 -04:00
|
|
|
stackedWidget->addWidget(new FileAssociationsPage() );
|
|
|
|
stackedWidget->addWidget(new SoundPage() );
|
2010-02-06 16:56:10 -05:00
|
|
|
#endif
|
2009-08-19 18:15:16 -04:00
|
|
|
|
2009-07-23 13:11:51 -04:00
|
|
|
setNewPage(General);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
RSettingsWin::setNewPage(int page)
|
|
|
|
{
|
|
|
|
QString text;
|
|
|
|
|
|
|
|
switch (page)
|
|
|
|
{
|
|
|
|
case General:
|
|
|
|
text = tr("General");
|
|
|
|
pageicon->setPixmap(QPixmap(":/images/kcmsystem24.png"));
|
|
|
|
break;
|
|
|
|
case Directories:
|
|
|
|
text = tr("Directories");
|
|
|
|
pageicon->setPixmap(QPixmap(":/images/folder_doments.png"));
|
|
|
|
break;
|
|
|
|
case Server:
|
|
|
|
text = tr("Server");
|
|
|
|
pageicon->setPixmap(QPixmap(":/images/server_24x24.png"));
|
|
|
|
break;
|
2010-01-27 15:24:49 -05:00
|
|
|
case Transfer:
|
|
|
|
text = tr("Transfer");
|
|
|
|
pageicon->setPixmap(QPixmap(":/images/ktorrent32.png"));
|
|
|
|
break;
|
2009-07-23 13:11:51 -04:00
|
|
|
case Notify:
|
|
|
|
text = tr("Notify");
|
|
|
|
pageicon->setPixmap(QPixmap(":/images/status_unknown.png"));
|
|
|
|
break;
|
|
|
|
case Security:
|
|
|
|
text = tr("Security");
|
|
|
|
pageicon->setPixmap(QPixmap(":/images/encrypted32.png"));
|
|
|
|
break;
|
|
|
|
case Appearance:
|
|
|
|
text = tr("Appearance");
|
|
|
|
pageicon->setPixmap(QPixmap(":/images/looknfeel.png"));
|
|
|
|
break;
|
2010-02-06 16:56:26 -05:00
|
|
|
#ifndef RS_RELEASE_VERSION
|
2009-07-23 13:11:51 -04:00
|
|
|
case Fileassociations:
|
|
|
|
text = tr("File Associations");
|
|
|
|
pageicon->setPixmap(QPixmap(":/images/filetype-association.png"));
|
|
|
|
break;
|
|
|
|
case Sound:
|
|
|
|
text = tr("Sound");
|
|
|
|
pageicon->setPixmap(QPixmap(":/images/sound.png"));
|
|
|
|
break;
|
2010-02-06 16:56:26 -05:00
|
|
|
#endif
|
2009-07-23 13:11:51 -04:00
|
|
|
default:
|
|
|
|
text = tr("UnknownPage");// impossible case
|
|
|
|
}
|
2009-08-19 18:15:16 -04:00
|
|
|
|
|
|
|
pageName->setText(text);
|
2009-08-21 13:58:55 -04:00
|
|
|
loadSettings(); /* load saved settings */
|
2009-07-23 13:11:51 -04:00
|
|
|
stackedWidget->setCurrentIndex(page);
|
|
|
|
listWidget->setCurrentRow(page);
|
|
|
|
}
|
|
|
|
|
2009-08-19 18:47:10 -04:00
|
|
|
void
|
|
|
|
RSettingsWin::loadSettings()
|
|
|
|
{
|
|
|
|
/* Call each config page's load() method to load its data */
|
|
|
|
int i, count = stackedWidget->count();
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
ConfigPage *page = (ConfigPage *) stackedWidget->widget(i);
|
|
|
|
page->load();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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));
|
2009-07-23 13:11:51 -04:00
|
|
|
|
2010-04-10 10:56:34 -04:00
|
|
|
if(!page->save(errmsg))
|
|
|
|
{
|
2009-08-19 18:15:16 -04:00
|
|
|
/* Display the offending page */
|
|
|
|
stackedWidget->setCurrentWidget(page);
|
2009-07-23 13:11:51 -04:00
|
|
|
|
2009-08-19 18:15:16 -04:00
|
|
|
/* Show the user what went wrong */
|
|
|
|
QMessageBox::warning(this,
|
2010-04-10 10:56:34 -04:00
|
|
|
tr("Error Saving Configuration on page ")+QString::number(i), errmsg,
|
2009-08-19 18:15:16 -04:00
|
|
|
QMessageBox::Ok, QMessageBox::NoButton);
|
2009-07-23 13:11:51 -04:00
|
|
|
|
2009-08-19 18:15:16 -04:00
|
|
|
/* Don't process the rest of the pages */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
2009-08-19 18:15:16 -04:00
|
|
|
QDialog::close();
|
|
|
|
}
|
2010-04-10 10:56:34 -04:00
|
|
|
|