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>
|
|
|
|
|
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"
|
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"
|
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;
|
|
|
|
}
|
|
|
|
|
2011-03-26 18:17:15 -04: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));
|
|
|
|
|
2010-07-08 21:10:27 -04:00
|
|
|
stackedWidget->addWidget(new GeneralPage(0));
|
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());
|
2010-05-21 09:54:40 -04:00
|
|
|
stackedWidget->addWidget(new MessagePage());
|
2010-08-08 18:58:10 -04:00
|
|
|
stackedWidget->addWidget(new ForumPage());
|
2010-05-03 17:17:36 -04:00
|
|
|
stackedWidget->addWidget(new ChatPage());
|
2009-07-23 13:11:51 -04:00
|
|
|
stackedWidget->addWidget(new AppearancePage());
|
|
|
|
stackedWidget->addWidget(new SoundPage() );
|
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");
|
2011-06-14 20:40:07 -04:00
|
|
|
pageicon->setPixmap(QPixmap(":/images/kcmsystem24.png"));
|
2009-07-23 13:11:51 -04:00
|
|
|
break;
|
|
|
|
case Directories:
|
|
|
|
text = tr("Directories");
|
2011-06-14 20:40:07 -04:00
|
|
|
pageicon->setPixmap(QPixmap(":/images/folder_doments.png"));
|
2009-07-23 13:11:51 -04:00
|
|
|
break;
|
|
|
|
case Server:
|
|
|
|
text = tr("Server");
|
2011-06-14 20:40:07 -04:00
|
|
|
pageicon->setPixmap(QPixmap(":/images/server_24x24.png"));
|
2009-07-23 13:11:51 -04:00
|
|
|
break;
|
2010-01-27 15:24:49 -05:00
|
|
|
case Transfer:
|
|
|
|
text = tr("Transfer");
|
2011-06-14 20:40:07 -04:00
|
|
|
pageicon->setPixmap(QPixmap(":/images/ktorrent32.png"));
|
2010-01-27 15:24:49 -05:00
|
|
|
break;
|
2009-07-23 13:11:51 -04:00
|
|
|
case Notify:
|
|
|
|
text = tr("Notify");
|
2011-06-14 20:40:07 -04:00
|
|
|
pageicon->setPixmap(QPixmap(":/images/status_unknown.png"));
|
2009-07-23 13:11:51 -04:00
|
|
|
break;
|
|
|
|
case Security:
|
|
|
|
text = tr("Security");
|
2011-06-14 20:40:07 -04:00
|
|
|
pageicon->setPixmap(QPixmap(":/images/encrypted32.png"));
|
2009-07-23 13:11:51 -04:00
|
|
|
break;
|
2010-05-21 09:54:40 -04:00
|
|
|
case Message:
|
|
|
|
text = tr("Message");
|
2011-06-14 20:40:07 -04:00
|
|
|
pageicon->setPixmap(QPixmap(":/images/evolution.png"));
|
2010-05-21 09:54:40 -04:00
|
|
|
break;
|
2010-08-08 18:58:10 -04:00
|
|
|
case Forum:
|
|
|
|
text = tr("Forum");
|
|
|
|
pageicon->setPixmap(QPixmap(":/images/konversation.png"));
|
|
|
|
break;
|
2010-05-03 17:17:36 -04:00
|
|
|
case Chat:
|
|
|
|
text = tr("Chat");
|
2011-06-14 20:40:07 -04:00
|
|
|
pageicon->setPixmap(QPixmap(":/images/chat_24.png"));
|
2010-05-03 17:17:36 -04:00
|
|
|
break;
|
2009-07-23 13:11:51 -04:00
|
|
|
case Appearance:
|
|
|
|
text = tr("Appearance");
|
2011-06-14 20:40:07 -04:00
|
|
|
pageicon->setPixmap(QPixmap(":/images/looknfeel.png"));
|
2009-07-23 13:11:51 -04:00
|
|
|
break;
|
2010-05-05 07:47:29 -04:00
|
|
|
/*// #ifndef RS_RELEASE_VERSION
|
2009-07-23 13:11:51 -04:00
|
|
|
case Fileassociations:
|
|
|
|
text = tr("File Associations");
|
2011-06-14 20:40:07 -04:00
|
|
|
pageicon->setPixmap(QPixmap(":/images/filetype-association.png"));
|
2010-05-05 07:47:29 -04:00
|
|
|
break;*/
|
2009-07-23 13:11:51 -04:00
|
|
|
case Sound:
|
|
|
|
text = tr("Sound");
|
2011-06-14 20:40:07 -04:00
|
|
|
pageicon->setPixmap(QPixmap(":/images/sound.png"));
|
2009-07-23 13:11:51 -04:00
|
|
|
break;
|
2010-05-05 07:47:29 -04: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-07-23 13:11:51 -04:00
|
|
|
stackedWidget->setCurrentIndex(page);
|
|
|
|
listWidget->setCurrentRow(page);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** 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
|
|
|
}
|