code refactoring and other small changes

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1558 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
alexandrut 2009-08-19 22:15:16 +00:00
parent 39882161b1
commit 19920e95bc
22 changed files with 204 additions and 186 deletions

View File

@ -26,7 +26,7 @@
/** Constructor */
AppearancePage::AppearancePage(QWidget * parent, Qt::WFlags flags)
: QWidget(parent, flags)
: ConfigPage(parent, flags)
{
/* Invoke the Qt Designer generated object setup routine */
ui.setupUi(this);

View File

@ -29,9 +29,10 @@
#include "gui/Preferences/rsharesettings.h"
#include <lang/languagesupport.h>
#include "configpage.h"
#include "ui_AppearancePage.h"
class AppearancePage : public QWidget
class AppearancePage : public ConfigPage
{
Q_OBJECT

View File

@ -34,7 +34,7 @@
/** Constructor */
CryptoPage::CryptoPage(QWidget * parent, Qt::WFlags flags)
: QWidget(parent, flags)
: ConfigPage(parent, flags)
{
/* Invoke the Qt Designer generated object setup routine */
ui.setupUi(this);

View File

@ -28,9 +28,10 @@
#include <gui/Preferences/rsharesettings.h>
#include "gui/connect/ConnectFriendWizard.h"
#include "configpage.h"
#include "ui_CryptoPage.h"
class CryptoPage : public QWidget
class CryptoPage : public ConfigPage
{
Q_OBJECT

View File

@ -27,9 +27,8 @@
#include <algorithm>
DirectoriesPage::DirectoriesPage(QWidget * parent, Qt::WFlags flags)
: QWidget(parent, flags)
: ConfigPage(parent, flags)
{
ui.setupUi(this);
setAttribute(Qt::WA_QuitOnClose, false);

View File

@ -26,10 +26,10 @@
#include <QWidget>
#include <QtGui>
#include "configpage.h"
#include "ui_DirectoriesPage.h"
# include "ui_DirectoriesPage.h"
class DirectoriesPage: public QWidget
class DirectoriesPage: public ConfigPage
{
Q_OBJECT

View File

@ -54,7 +54,7 @@
//============================================================================
FileAssociationsPage::FileAssociationsPage(QWidget * parent, Qt::WFlags flags)
: QWidget(parent, flags)
: ConfigPage(parent, flags)
//:QFrame()
{
QVBoxLayout* pageLay = new QVBoxLayout(this);

View File

@ -22,7 +22,7 @@
#ifndef __FileAssociationsPage__
#define __FileAssociationsPage__
//#include "configpage.h"
#include "configpage.h"
#include <QString>
#include <QWidget>
@ -52,7 +52,7 @@ class RshareSettings;
//! With this config page user can specify, what programs should be executed
//! to open some types of files. Here 'type' means 'file extension'(and
//! 'file extension' means 'some symbols after last dot in filename').
class FileAssociationsPage : public QWidget
class FileAssociationsPage : public ConfigPage
{
Q_OBJECT

View File

@ -26,7 +26,7 @@
/** Constructor */
GeneralPage::GeneralPage(QWidget * parent, Qt::WFlags flags)
: QWidget(parent, flags)
: ConfigPage(parent, flags)
{
/* Invoke the Qt Designer generated object setup routine */
ui.setupUi(this);

View File

@ -29,10 +29,11 @@
#include "gui/Preferences/rsharesettings.h"
#include "configpage.h"
#include "ui_GeneralPage.h"
class GeneralPage : public QWidget
class GeneralPage : public ConfigPage
{
Q_OBJECT

View File

@ -23,7 +23,7 @@
#include "rshare.h"
NetworkPage::NetworkPage(QWidget * parent, Qt::WFlags flags)
: QWidget(parent, flags)
: ConfigPage(parent, flags)
{
ui.setupUi(this);
setAttribute(Qt::WA_QuitOnClose, false);
@ -41,7 +41,7 @@ NetworkPage::closeEvent (QCloseEvent * event)
bool
NetworkPage::save(QString &errmsg)
{
return true;
}
/** Loads the settings for this page */

View File

@ -23,9 +23,11 @@
#define NETWORKPAGE_H
#include <QtGui/QWidget>
#include "configpage.h"
#include "ui_NetworkPage.h"
class NetworkPage: public QWidget
class NetworkPage : public ConfigPage
{
public:
NetworkPage(QWidget * parent = 0, Qt::WFlags flags = 0);

View File

@ -32,7 +32,7 @@
/** Constructor */
NotifyPage::NotifyPage(QWidget * parent, Qt::WFlags flags)
: QWidget(parent, flags)
: ConfigPage(parent, flags)
{
/* Invoke the Qt Designer generated object setup routine */
ui.setupUi(this);

View File

@ -27,10 +27,10 @@
#include "gui/Preferences/rsharesettings.h"
#include "configpage.h"
#include "ui_NotifyPage.h"
class NotifyPage : public QWidget
class NotifyPage : public ConfigPage
{
Q_OBJECT

View File

@ -33,7 +33,7 @@
#include <QTimer>
ServerPage::ServerPage(QWidget * parent, Qt::WFlags flags)
: QWidget(parent, flags)
: ConfigPage(parent, flags)
{
/* Invoke the Qt Designer generated object setup routine */
ui.setupUi(this);

View File

@ -23,9 +23,11 @@
# define SERVERPAGE_H
# include <QtGui/QWidget>
# include "ui_ServerPage.h"
class ServerPage: public QWidget
#include "configpage.h"
#include "ui_ServerPage.h"
class ServerPage: public ConfigPage
{
Q_OBJECT

View File

@ -26,7 +26,7 @@
/** Constructor */
SoundPage::SoundPage(QWidget * parent, Qt::WFlags flags)
: QWidget(parent, flags)
: ConfigPage(parent, flags)
{
/* Invoke the Qt Designer generated object setup routine */
ui.setupUi(this);

View File

@ -26,9 +26,10 @@
#include <gui/Preferences/rsharesettings.h>
#include "configpage.h"
#include "ui_SoundPage.h"
class SoundPage : public QWidget
class SoundPage : public ConfigPage
{
Q_OBJECT

View File

@ -0,0 +1,43 @@
/****************************************************************
* This file is distributed under the following license:
*
* Copyright (c) 2006-2007, crypton
* Copyright (c) 2006, Matt Edman, Justin Hipple
*
* 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
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#ifndef _CONFIGPAGE_H
#define _CONFIGPAGE_H
#include <QWidget>
class ConfigPage : public QWidget
{
public:
/** Default Constructor */
ConfigPage(QWidget *parent = 0, Qt::WFlags flags = 0) : QWidget(parent, flags) {}
/** Pure virtual method. Subclassed pages load their config settings here. */
virtual void load() = 0;
/** Pure virtual method. Subclassed pages save their config settings here
* and return true if everything was saved successfully. */
virtual bool save(QString &errmsg) = 0;
};
#endif

View File

@ -43,18 +43,20 @@ RSettingsWin::RSettingsWin(QWidget * parent, Qt::WFlags flags)
initStackedWidget();
connect(listWidget, SIGNAL(currentRowChanged(int)),
this, SLOT(setNewPage(int)));
connect(listWidget, SIGNAL(currentRowChanged(int)), this, SLOT(setNewPage(int)));
connect(okButton, SIGNAL(clicked( bool )), this, SLOT( saveChanges()) );
}
void
RSettingsWin::showWindow(int page)
{
setNewPage(page);
QDialog::show();
}
void
RSettingsWin::closeEvent (QCloseEvent * event)
{
QWidget::closeEvent(event);
}
@ -65,7 +67,6 @@ RSettingsWin::initStackedWidget()
stackedWidget->removeWidget(stackedWidget->widget(0));
stackedWidget->addWidget(new GeneralPage(false));
stackedWidget->addWidget(new NetworkPage());
stackedWidget->addWidget(new ServerPage());
stackedWidget->addWidget(new DirectoriesPage());
stackedWidget->addWidget(new NotifyPage());
@ -75,7 +76,6 @@ RSettingsWin::initStackedWidget()
stackedWidget->addWidget(new SoundPage() );
setNewPage(General);
}
void
@ -89,10 +89,6 @@ RSettingsWin::setNewPage(int page)
text = tr("General");
pageicon->setPixmap(QPixmap(":/images/kcmsystem24.png"));
break;
case Network:
text = tr("Network");
pageicon->setPixmap(QPixmap(":/images/network32.png"));
break;
case Directories:
text = tr("Directories");
pageicon->setPixmap(QPixmap(":/images/folder_doments.png"));
@ -125,7 +121,7 @@ RSettingsWin::setNewPage(int page)
text = tr("UnknownPage");// impossible case
}
pageName->setText(text); //tr("%1").arg(
pageName->setText(text);
stackedWidget->setCurrentIndex(page);
listWidget->setCurrentRow(page);
}
@ -134,53 +130,31 @@ RSettingsWin::setNewPage(int page)
void
RSettingsWin::saveChanges()
{
bool saveOk;
QString errmsg;
bool saveOk;
QString errmsg;
GeneralPage *gp;
NetworkPage *np;
CryptoPage *cp;
ServerPage *sp;
NotifyPage *nfp;
AppearancePage *ap;
/* Call each config page's save() method to save its data */
int i, count = stackedWidget->count();
for (i = 0; i < count; i++) {
ConfigPage *page = (ConfigPage *) stackedWidget->widget(i);
saveOk = page->save(errmsg);
/* Call each config page's save() method to save its data */
int i, count = stackedWidget->count();
for (i = 0; i < count; i++) {
QWidget *page = stackedWidget->widget(i);
if (NULL != (gp = dynamic_cast<GeneralPage *>(page))) {saveOk = gp->save(errmsg);}
else
if (NULL !=(np = dynamic_cast<NetworkPage *>(page))) {saveOk = np->save(errmsg);}
else
if (NULL !=(sp = dynamic_cast<ServerPage *>(page))) {saveOk = sp->save(errmsg);}
else
if (NULL !=(cp = dynamic_cast<CryptoPage *>(page))) {saveOk = cp->save(errmsg);}
else
if (NULL !=(nfp = dynamic_cast<NotifyPage *>(page))) {saveOk = nfp->save(errmsg);}
else if (NULL !=(ap = dynamic_cast<AppearancePage *>(page))) {saveOk = ap->save(errmsg);}
if (!saveOk) {
/* Display the offending page */
stackedWidget->setCurrentWidget(page);
/* Show the user what went wrong */
QMessageBox::warning(this,
tr("Error Saving Configuration"), errmsg,
QMessageBox::Ok, QMessageBox::NoButton);
if (!saveOk) {
/* Display the offending page */
stackedWidget->setCurrentWidget(page);
/* Don't process the rest of the pages */
return;
}
}
/* Show the user what went wrong */
QMessageBox::warning(this,
tr("Error Saving Configuration"), errmsg,
QMessageBox::Ok, QMessageBox::NoButton);
/* call to RsIface save function.... */
//rsicontrol -> ConfigSave();
/* Don't process the rest of the pages */
return;
}
}
/* call to RsIface save function.... */
//rsicontrol -> ConfigSave();
QDialog::close();
QDialog::close();
}

View File

@ -31,22 +31,25 @@ class RSettingsWin: public QDialog, private Ui::Settings
Q_OBJECT
public:
enum PageType { General = 0, Network, Server,
Directories, Notify, Security, Appearance, Fileassociations, Sound };
enum PageType { General = 0, Server,
Directories, Notify, Security, Appearance, Fileassociations, Sound };
RSettingsWin(QWidget * parent = 0, Qt::WFlags flags = 0);
~RSettingsWin() {}
void showWindow(int page);
public slots:
//! Go to a specific part of the control panel.
void setNewPage(int page);
private slots:
/** Called when user clicks "Save Settings" */
void saveChanges();
private:
void closeEvent (QCloseEvent * event);
void initStackedWidget();
/** Called when user clicks "Save Settings" */
void saveChanges();
};
#endif // !RSETTINGSWIN_HPP_

View File

@ -87,15 +87,6 @@
<normaloff>:/images/kcmsystem24.png</normaloff>:/images/kcmsystem24.png</iconset>
</property>
</item>
<item>
<property name="text">
<string>Network</string>
</property>
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/network.png</normaloff>:/images/network.png</iconset>
</property>
</item>
<item>
<property name="text">
<string>Server</string>