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 */ /** Constructor */
AppearancePage::AppearancePage(QWidget * parent, Qt::WFlags flags) AppearancePage::AppearancePage(QWidget * parent, Qt::WFlags flags)
: QWidget(parent, flags) : ConfigPage(parent, flags)
{ {
/* Invoke the Qt Designer generated object setup routine */ /* Invoke the Qt Designer generated object setup routine */
ui.setupUi(this); ui.setupUi(this);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -26,9 +26,10 @@
#include <gui/Preferences/rsharesettings.h> #include <gui/Preferences/rsharesettings.h>
#include "configpage.h"
#include "ui_SoundPage.h" #include "ui_SoundPage.h"
class SoundPage : public QWidget class SoundPage : public ConfigPage
{ {
Q_OBJECT 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(); initStackedWidget();
connect(listWidget, SIGNAL(currentRowChanged(int)), connect(listWidget, SIGNAL(currentRowChanged(int)), this, SLOT(setNewPage(int)));
this, SLOT(setNewPage(int)));
connect(okButton, SIGNAL(clicked( bool )), this, SLOT( saveChanges()) ); connect(okButton, SIGNAL(clicked( bool )), this, SLOT( saveChanges()) );
}
void
RSettingsWin::showWindow(int page)
{
setNewPage(page);
QDialog::show();
} }
void void
RSettingsWin::closeEvent (QCloseEvent * event) RSettingsWin::closeEvent (QCloseEvent * event)
{ {
QWidget::closeEvent(event); QWidget::closeEvent(event);
} }
@ -65,7 +67,6 @@ RSettingsWin::initStackedWidget()
stackedWidget->removeWidget(stackedWidget->widget(0)); stackedWidget->removeWidget(stackedWidget->widget(0));
stackedWidget->addWidget(new GeneralPage(false)); stackedWidget->addWidget(new GeneralPage(false));
stackedWidget->addWidget(new NetworkPage());
stackedWidget->addWidget(new ServerPage()); stackedWidget->addWidget(new ServerPage());
stackedWidget->addWidget(new DirectoriesPage()); stackedWidget->addWidget(new DirectoriesPage());
stackedWidget->addWidget(new NotifyPage()); stackedWidget->addWidget(new NotifyPage());
@ -75,7 +76,6 @@ RSettingsWin::initStackedWidget()
stackedWidget->addWidget(new SoundPage() ); stackedWidget->addWidget(new SoundPage() );
setNewPage(General); setNewPage(General);
} }
void void
@ -89,10 +89,6 @@ RSettingsWin::setNewPage(int page)
text = tr("General"); text = tr("General");
pageicon->setPixmap(QPixmap(":/images/kcmsystem24.png")); pageicon->setPixmap(QPixmap(":/images/kcmsystem24.png"));
break; break;
case Network:
text = tr("Network");
pageicon->setPixmap(QPixmap(":/images/network32.png"));
break;
case Directories: case Directories:
text = tr("Directories"); text = tr("Directories");
pageicon->setPixmap(QPixmap(":/images/folder_doments.png")); pageicon->setPixmap(QPixmap(":/images/folder_doments.png"));
@ -125,7 +121,7 @@ RSettingsWin::setNewPage(int page)
text = tr("UnknownPage");// impossible case text = tr("UnknownPage");// impossible case
} }
pageName->setText(text); //tr("%1").arg( pageName->setText(text);
stackedWidget->setCurrentIndex(page); stackedWidget->setCurrentIndex(page);
listWidget->setCurrentRow(page); listWidget->setCurrentRow(page);
} }
@ -137,28 +133,11 @@ RSettingsWin::saveChanges()
bool saveOk; bool saveOk;
QString errmsg; 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 */ /* Call each config page's save() method to save its data */
int i, count = stackedWidget->count(); int i, count = stackedWidget->count();
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
QWidget *page = stackedWidget->widget(i); ConfigPage *page = (ConfigPage *) stackedWidget->widget(i);
if (NULL != (gp = dynamic_cast<GeneralPage *>(page))) {saveOk = gp->save(errmsg);} saveOk = page->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) { if (!saveOk) {
/* Display the offending page */ /* Display the offending page */
@ -174,13 +153,8 @@ RSettingsWin::saveChanges()
} }
} }
/* call to RsIface save function.... */ /* call to RsIface save function.... */
//rsicontrol -> ConfigSave(); //rsicontrol -> ConfigSave();
QDialog::close(); QDialog::close();
} }

View File

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

View File

@ -87,15 +87,6 @@
<normaloff>:/images/kcmsystem24.png</normaloff>:/images/kcmsystem24.png</iconset> <normaloff>:/images/kcmsystem24.png</normaloff>:/images/kcmsystem24.png</iconset>
</property> </property>
</item> </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> <item>
<property name="text"> <property name="text">
<string>Server</string> <string>Server</string>