Changed settings to local variable, no more as pointer on all classes.

RshareSettings settings;
settings.value(...);

It should lower memory usage and removes memory leaks.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@2886 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2010-05-11 20:02:52 +00:00
parent 2f8d21ab76
commit 0c46da0dd2
52 changed files with 310 additions and 428 deletions

View file

@ -22,6 +22,7 @@
#include <rshare.h>
#include "AppearancePage.h"
#include "rsharesettings.h"
/** Constructor */
@ -31,9 +32,6 @@ AppearancePage::AppearancePage(QWidget * parent, Qt::WFlags flags)
/* Invoke the Qt Designer generated object setup routine */
ui.setupUi(this);
/* Create RshareSettings object */
_settings = new RshareSettings();
connect(ui.styleSheetCombo, SIGNAL(clicked()), this, SLOT(loadStyleSheet()));
/* Populate combo boxes */
@ -61,7 +59,6 @@ AppearancePage::AppearancePage(QWidget * parent, Qt::WFlags flags)
AppearancePage::~AppearancePage()
{
delete _settings;
}
/** Saves the changes on this page */
@ -72,9 +69,10 @@ AppearancePage::save(QString &errmsg)
QString languageCode =
LanguageSupport::languageCode(ui.cmboLanguage->currentText());
_settings->setLanguageCode(languageCode);
_settings->setInterfaceStyle(ui.cmboStyle->currentText());
_settings->setSheetName(ui.styleSheetCombo->currentText());
RshareSettings settings;
settings.setLanguageCode(languageCode);
settings.setInterfaceStyle(ui.cmboStyle->currentText());
settings.setSheetName(ui.styleSheetCombo->currentText());
/* Set to new style */
Rshare::setStyle(ui.cmboStyle->currentText());
@ -87,20 +85,21 @@ AppearancePage::save(QString &errmsg)
void
AppearancePage::load()
{
RshareSettings settings;
int index = ui.cmboLanguage->findData(_settings->getLanguageCode());
int index = ui.cmboLanguage->findData(settings.getLanguageCode());
ui.cmboLanguage->setCurrentIndex(index);
index = ui.cmboStyle->findData(Rshare::style().toLower());
ui.cmboStyle->setCurrentIndex(index);
ui.styleSheetCombo->setCurrentIndex(ui.styleSheetCombo->findText(_settings->getSheetName()));
ui.styleSheetCombo->setCurrentIndex(ui.styleSheetCombo->findText(settings.getSheetName()));
/** load saved internal styleSheet **/
//QFile file(":/qss/" + (_settings->getSheetName().toLower()) + ".qss");
//QFile file(":/qss/" + (settings.getSheetName().toLower()) + ".qss");
/** load saved extern Stylesheets **/
QFile file(QApplication::applicationDirPath() + "/qss/" + (_settings->getSheetName().toLower()) + ".qss");
QFile file(QApplication::applicationDirPath() + "/qss/" + (settings.getSheetName().toLower()) + ".qss");
file.open(QFile::ReadOnly);
QString styleSheet = QLatin1String(file.readAll());

View file

@ -26,7 +26,6 @@
#include <QStyleFactory>
#include <QtGui>
#include "rsharesettings.h"
#include <lang/languagesupport.h>
#include "configpage.h"
@ -53,9 +52,6 @@ class AppearancePage : public ConfigPage
private:
/** A RshareSettings object used for saving/loading settings */
RshareSettings* _settings;
void loadStyleSheet(const QString &sheetName);
void loadqss();

View file

@ -21,6 +21,7 @@
#include "rsiface/rspeers.h" //for rsPeers variable
#include "rsiface/rsiface.h"
#include "rsharesettings.h"
#include <QtGui>
#include <QClipboard>
@ -39,9 +40,6 @@ ChatPage::ChatPage(QWidget * parent, Qt::WFlags flags)
/* Invoke the Qt Designer generated object setup routine */
ui.setupUi(this);
/* Create RshareSettings object */
_settings = new RshareSettings();
//connect(ui.copykeyButton, SIGNAL(clicked()), this, SLOT(copyPublicKey()));
//connect(ui.saveButton, SIGNAL(clicked()), this, SLOT(fileSaveAs()));
@ -66,11 +64,12 @@ ChatPage::closeEvent (QCloseEvent * event)
bool
ChatPage::save(QString &errmsg)
{
_settings->setValue(QString::fromUtf8("Emoteicons_PrivatChat"), emotePrivatChat());
RshareSettings settings;
settings.setValue(QString::fromUtf8("Emoteicons_PrivatChat"), emotePrivatChat());
_settings->setValue(QString::fromUtf8("Emoteicons_GroupChat"), emoteGroupChat());
settings.setValue(QString::fromUtf8("Emoteicons_GroupChat"), emoteGroupChat());
_settings->setValue(QString::fromUtf8("GroupChat_History"), groupchatHistory());
settings.setValue(QString::fromUtf8("GroupChat_History"), groupchatHistory());
return true;
}
@ -79,12 +78,13 @@ ChatPage::save(QString &errmsg)
void
ChatPage::load()
{
RshareSettings settings;
ui.checkBox_emoteprivchat->setChecked(_settings->value(QString::fromUtf8("Emoteicons_PrivatChat"), true).toBool());
ui.checkBox_emoteprivchat->setChecked(settings.value(QString::fromUtf8("Emoteicons_PrivatChat"), true).toBool());
ui.checkBox_emotegroupchat->setChecked(_settings->value(QString::fromUtf8("Emoteicons_GroupChat"), true).toBool());
ui.checkBox_emotegroupchat->setChecked(settings.value(QString::fromUtf8("Emoteicons_GroupChat"), true).toBool());
ui.checkBox_groupchathistory->setChecked(_settings->value(QString::fromUtf8("GroupChat_History"), true).toBool());
ui.checkBox_groupchathistory->setChecked(settings.value(QString::fromUtf8("GroupChat_History"), true).toBool());
}

View file

@ -25,8 +25,6 @@
#include <QFileDialog>
#include <QtGui/QWidget>
#include "rsharesettings.h"
#include "configpage.h"
#include "ui_ChatPage.h"
@ -53,9 +51,6 @@ class ChatPage : public ConfigPage
private:
/** A RshareSettings object used for saving/loading settings */
RshareSettings* _settings;
void closeEvent (QCloseEvent * event);

View file

@ -39,9 +39,6 @@ CryptoPage::CryptoPage(QWidget * parent, Qt::WFlags flags)
/* Invoke the Qt Designer generated object setup routine */
ui.setupUi(this);
/* Create RshareSettings object */
_settings = new RshareSettings();
connect(ui.copykeyButton, SIGNAL(clicked()), this, SLOT(copyPublicKey()));
connect(ui.saveButton, SIGNAL(clicked()), this, SLOT(fileSaveAs()));
@ -57,7 +54,6 @@ CryptoPage::CryptoPage(QWidget * parent, Qt::WFlags flags)
CryptoPage::~CryptoPage()
{
delete _settings;
}
void

View file

@ -25,7 +25,6 @@
#include <QFileDialog>
#include <QtGui/QWidget>
#include "rsharesettings.h"
#include "gui/connect/ConnectFriendWizard.h"
#include "configpage.h"
@ -58,9 +57,6 @@ class CryptoPage : public ConfigPage
private:
/** A RshareSettings object used for saving/loading settings */
RshareSettings* _settings;
void closeEvent (QCloseEvent * event);
void setCurrentFileName(const QString &fileName);

View file

@ -116,10 +116,10 @@ FileAssociationsPage::FileAssociationsPage(QWidget * parent, Qt::WFlags flags)
// connect( addNewAssotiationButton, SIGNAL( clicked() ),
// this, SLOT( testButtonClicked() ) );
settings = new RshareSettings();
// RshareSettings settings;
//new QSettings( qApp->applicationDirPath()+"/sett.ini",
// QSettings::IniFormat);
settings->beginGroup("FileAssociations");
// settings.beginGroup("FileAssociations");
@ -129,7 +129,6 @@ FileAssociationsPage::FileAssociationsPage(QWidget * parent, Qt::WFlags flags)
FileAssociationsPage::~FileAssociationsPage()
{
delete settings ;
}
//============================================================================
@ -137,25 +136,25 @@ FileAssociationsPage::~FileAssociationsPage()
bool
FileAssociationsPage::save (QString &errmsg)
{
//RshareSettings* settings = new RshareSettings();
// RshareSettings settings;
// settings->beginGroup("FileAssotiations");
// settings->setValue(".s01", "s01 test");
// settings->setValue(".s02", "s02 test");
// settings->setValue(".s03", "s03 test");
// settings->setValue(".s04", "s04 test");
// settings.beginGroup("FileAssotiations");
// settings.setValue(".s01", "s01 test");
// settings.setValue(".s02", "s02 test");
// settings.setValue(".s03", "s03 test");
// settings.setValue(".s04", "s04 test");
// QMap<QString, QString>::const_iterator ati = ations.constBegin();
// while (ati != ations.constEnd())
// {
// settings->setValue( ati.key(), ati.value() );
// settings.setValue( ati.key(), ati.value() );
// qDebug() << " - " << ati.key() << ati.value() << "\n" ;
// ati++;
// }
//
// settings->endGroup();
// settings.endGroup();
settings->sync();
// settings.sync();
// delete settings;
/* */
@ -167,12 +166,12 @@ FileAssociationsPage::save (QString &errmsg)
void
FileAssociationsPage::load()
{
//RshareSettings* settings = new RshareSettings();
RshareSettings settings;
// QSettings* settings = new QSettings( qApp->applicationDirPath()+"/sett.ini",
// QSettings::IniFormat);
//
// settings->beginGroup("FileAssotiations");
QStringList keys = settings->allKeys();
// settings.beginGroup("FileAssotiations");
QStringList keys = settings.allKeys();
table->setRowCount( keys.count() );
@ -180,7 +179,7 @@ FileAssociationsPage::load()
QStringList::const_iterator ki;
for(ki=keys.constBegin(); ki!=keys.constEnd(); ki++)
{
QString val = (settings->value(*ki, "")).toString();
QString val = (settings.value(*ki, "")).toString();
addNewItemToTable( rowi, 0, *ki );
addNewItemToTable( rowi, 1, val );
@ -207,7 +206,8 @@ FileAssociationsPage::remove()
QTableWidgetItem const * titem = table->item( currentRow,0);
QString key = (titem->data(QTableWidgetItem::Type)).toString();
settings->remove(key);
RshareSettings settings;
settings.remove(key);
table->removeRow( currentRow );
if ( table->rowCount()==0 )
@ -235,7 +235,8 @@ FileAssociationsPage::addnew()
QString currCmd = afad.resultCommand() ;
if ( !settings->contains(currType) )//new item should be added only if
RshareSettings settings;
if ( !settings.contains(currType) )//new item should be added only if
{ // it wasn't entered before.
int nridx = table->rowCount();//new row index
table->setRowCount(nridx+1);
@ -256,7 +257,7 @@ FileAssociationsPage::addnew()
}
}
settings->setValue(currType, currCmd);
settings.setValue(currType, currCmd);
removeAction->setEnabled(true);
editAction->setEnabled(true);
@ -289,7 +290,8 @@ FileAssociationsPage::edit()
titem->setData(QTableWidgetItem::Type, currCmd);
settings->setValue(currType, currCmd);
RshareSettings settings;
settings.setValue(currType, currCmd);
}
}

View file

@ -44,7 +44,6 @@ class QLabel;
class QLineEdit;
//class QSettings;
class RshareSettings;
//=============================================================================
//! Dialog for setting file assotiations for RS
@ -74,9 +73,6 @@ protected:
QPushButton* addNewAssotiationButton;
QString settingsFileName;
RshareSettings* settings;
// QSettings* settings;
void addNewItemToTable(int row, int column, QString itemText);
protected slots:

View file

@ -25,6 +25,7 @@
#include "GeneralPage.h"
#include <util/stringutil.h>
#include <QSystemTrayIcon>
#include "rsharesettings.h"
/** Constructor */
GeneralPage::GeneralPage(QWidget * parent, Qt::WFlags flags)
@ -33,9 +34,6 @@ GeneralPage::GeneralPage(QWidget * parent, Qt::WFlags flags)
/* Invoke the Qt Designer generated object setup routine */
ui.setupUi(this);
/* Create RshareSettings object */
_settings = new RshareSettings();
connect(ui.autoLogin, SIGNAL(clicked()), this, SLOT(setAutoLogin()));
/* Hide platform specific features */
@ -51,20 +49,20 @@ GeneralPage::GeneralPage(QWidget * parent, Qt::WFlags flags)
/** Destructor */
GeneralPage::~GeneralPage()
{
delete _settings;
}
/** Saves the changes on this page */
bool
GeneralPage::save(QString &errmsg)
{
_settings->setValue(QString::fromUtf8("StartMinimized"), startMinimized());
RshareSettings settings;
settings.setValue(QString::fromUtf8("StartMinimized"), startMinimized());
_settings->setValue(QString::fromUtf8("doQuit"), quit());
settings.setValue(QString::fromUtf8("doQuit"), quit());
_settings->setValue(QString::fromUtf8("ClosetoTray"), closetoTray());
settings.setValue(QString::fromUtf8("ClosetoTray"), closetoTray());
_settings->setRunRetroshareOnBoot(
settings.setRunRetroshareOnBoot(
ui.chkRunRetroshareAtSystemStartup->isChecked());
return true;
@ -74,14 +72,14 @@ GeneralPage::save(QString &errmsg)
void
GeneralPage::load()
{
ui.chkRunRetroshareAtSystemStartup->setChecked(
_settings->runRetroshareOnBoot());
RshareSettings settings;
ui.chkRunRetroshareAtSystemStartup->setChecked(settings.runRetroshareOnBoot());
ui.checkStartMinimized->setChecked(_settings->value(QString::fromUtf8("StartMinimized"), false).toBool());
ui.checkStartMinimized->setChecked(settings.value(QString::fromUtf8("StartMinimized"), false).toBool());
ui.checkQuit->setChecked(_settings->value(QString::fromUtf8("doQuit"), false).toBool());
ui.checkQuit->setChecked(settings.value(QString::fromUtf8("doQuit"), false).toBool());
ui.checkClosetoTray->setChecked(_settings->value(QString::fromUtf8("ClosetoTray"), false).toBool());
ui.checkClosetoTray->setChecked(settings.value(QString::fromUtf8("ClosetoTray"), false).toBool());
}
@ -106,8 +104,8 @@ bool GeneralPage::closetoTray() const {
void
GeneralPage::toggleShowOnStartup(bool checked)
{
//RshareSettings _settings;
_settings->setShowMainWindowAtStart(checked);
RshareSettings settings;
settings.setShowMainWindowAtStart(checked);
}
void GeneralPage::setAutoLogin(){

View file

@ -27,7 +27,6 @@
#include <QFileDialog>
#include <QLineEdit>
#include "rsharesettings.h"
#include "rsiface/rsiface.h"
#include "configpage.h"
@ -64,11 +63,6 @@ private slots:
void setAutoLogin();
private:
/** A RetroShare Settings object used for saving/loading settings */
RshareSettings *_settings;
/** Qt Designer generated object */
Ui::GeneralPage ui;
};

View file

@ -26,6 +26,7 @@
#include <sstream>
#include "rsiface/rsnotify.h"
#include "rsharesettings.h"
#include <QTimer>
@ -39,9 +40,6 @@ NotifyPage::NotifyPage(QWidget * parent, Qt::WFlags flags)
setAttribute(Qt::WA_QuitOnClose, false);
setWindowTitle(windowTitle() + QLatin1String(" - Notify"));
/* Create RshareSettings object */
_settings = new RshareSettings();
//load();
//QTimer *timer = new QTimer(this);
@ -57,7 +55,6 @@ NotifyPage::NotifyPage(QWidget * parent, Qt::WFlags flags)
NotifyPage::~NotifyPage()
{
delete _settings;
}
void
@ -111,9 +108,10 @@ NotifyPage::save(QString &errmsg)
if (ui.chat_Focus->isChecked())
chatflags |= RS_CHAT_FOCUS;
_settings->setNotifyFlags(notifyflags);
_settings->setNewsFeedFlags(newsflags);
_settings->setChatFlags(chatflags);
RshareSettings settings;
settings.setNotifyFlags(notifyflags);
settings.setNewsFeedFlags(newsflags);
settings.setChatFlags(chatflags);
load();
return true;
@ -124,10 +122,11 @@ NotifyPage::save(QString &errmsg)
void NotifyPage::load()
{
/* extract from rsNotify the flags */
RshareSettings settings;
uint notifyflags = _settings->getNotifyFlags();
uint newsflags = _settings->getNewsFeedFlags();
uint chatflags = _settings->getChatFlags();
uint notifyflags = settings.getNotifyFlags();
uint newsflags = settings.getNewsFeedFlags();
uint chatflags = settings.getChatFlags();
ui.popup_Connect->setChecked(notifyflags & RS_POPUP_CONNECT);
ui.popup_NewMsg->setChecked(notifyflags & RS_POPUP_MSG);

View file

@ -25,8 +25,6 @@
#include <QFileDialog>
#include <QtGui/QWidget>
#include "rsharesettings.h"
#include "configpage.h"
#include "ui_NotifyPage.h"
@ -54,9 +52,6 @@ class NotifyPage : public ConfigPage
void closeEvent (QCloseEvent * event);
/** A RshareSettings object used for saving/loading settings */
RshareSettings* _settings;
/** Qt Designer generated object */
Ui::NotifyPage ui;
};

View file

@ -22,6 +22,7 @@
#include <rshare.h>
#include "SoundPage.h"
#include "rsharesettings.h"
/** Constructor */
@ -31,9 +32,6 @@ SoundPage::SoundPage(QWidget * parent, Qt::WFlags flags)
/* Invoke the Qt Designer generated object setup routine */
ui.setupUi(this);
/* Create RshareSettings object */
_settings = new RshareSettings();
connect(ui.cmd_openFile, SIGNAL(clicked(bool) ),this,SLOT(on_cmd_openFile()));
//connect(ui.cmd_openFile_2,SIGNAL(clicked(bool) ),this,SLOT(on_cmd_openFile2()));
connect(ui.cmd_openFile_3,SIGNAL(clicked(bool) ),this,SLOT(on_cmd_openFile3()));
@ -52,31 +50,31 @@ SoundPage::SoundPage(QWidget * parent, Qt::WFlags flags)
SoundPage::~SoundPage()
{
delete _settings;
}
/** Saves the changes on this page */
bool
SoundPage::save(QString &errmsg)
{
_settings->beginGroup("Sound");
_settings->beginGroup("Enable");
_settings->setValue("User_go_Online",ui.checkBoxSound->isChecked());
//_settings->setValue("User_go_Offline",ui.checkBoxSound_2->isChecked());
_settings->setValue("FileSend_Finished",ui.checkBoxSound_3->isChecked());
_settings->setValue("FileRecive_Incoming",ui.checkBoxSound_4->isChecked());
_settings->setValue("FileRecive_Finished",ui.checkBoxSound_5->isChecked());
_settings->setValue("NewChatMessage",ui.checkBoxSound_6->isChecked());
_settings->endGroup();
_settings->beginGroup("SoundFilePath");
_settings->setValue("User_go_Online",ui.txt_SoundFile->text());
//_settings->setValue("User_go_Offline",ui.txt_SoundFile2->text());
_settings->setValue("FileSend_Finished",ui.txt_SoundFile3->text());
_settings->setValue("FileRecive_Incoming",ui.txt_SoundFile4->text());
_settings->setValue("FileRecive_Finished",ui.txt_SoundFile5->text());
_settings->setValue("NewChatMessage",ui.txt_SoundFile6->text());
_settings->endGroup();
_settings->endGroup();
RshareSettings settings;
settings.beginGroup("Sound");
settings.beginGroup("Enable");
settings.setValue("User_go_Online",ui.checkBoxSound->isChecked());
//settings.setValue("User_go_Offline",ui.checkBoxSound_2->isChecked());
settings.setValue("FileSend_Finished",ui.checkBoxSound_3->isChecked());
settings.setValue("FileRecive_Incoming",ui.checkBoxSound_4->isChecked());
settings.setValue("FileRecive_Finished",ui.checkBoxSound_5->isChecked());
settings.setValue("NewChatMessage",ui.checkBoxSound_6->isChecked());
settings.endGroup();
settings.beginGroup("SoundFilePath");
settings.setValue("User_go_Online",ui.txt_SoundFile->text());
//settings.setValue("User_go_Offline",ui.txt_SoundFile2->text());
settings.setValue("FileSend_Finished",ui.txt_SoundFile3->text());
settings.setValue("FileRecive_Incoming",ui.txt_SoundFile4->text());
settings.setValue("FileRecive_Finished",ui.txt_SoundFile5->text());
settings.setValue("NewChatMessage",ui.txt_SoundFile6->text());
settings.endGroup();
settings.endGroup();
return true;
}
@ -87,14 +85,15 @@ SoundPage::save(QString &errmsg)
void
SoundPage::load()
{
_settings->beginGroup("Sound");
_settings->beginGroup("SoundFilePath");
ui.txt_SoundFile->setText(_settings->value("User_go_Online","").toString());
//ui.txt_SoundFile2->setText(_settings->value("User_go_Offline","").toString());
ui.txt_SoundFile3->setText(_settings->value("FileSend_Finished","").toString());
ui.txt_SoundFile4->setText(_settings->value("FileRecive_Incoming","").toString());
ui.txt_SoundFile5->setText(_settings->value("FileRecive_Finished","").toString());
ui.txt_SoundFile6->setText(_settings->value("NewChatMessage","").toString());
RshareSettings settings;
settings.beginGroup("Sound");
settings.beginGroup("SoundFilePath");
ui.txt_SoundFile->setText(settings.value("User_go_Online","").toString());
//ui.txt_SoundFile2->setText(settings.value("User_go_Offline","").toString());
ui.txt_SoundFile3->setText(settings.value("FileSend_Finished","").toString());
ui.txt_SoundFile4->setText(settings.value("FileRecive_Incoming","").toString());
ui.txt_SoundFile5->setText(settings.value("FileRecive_Finished","").toString());
ui.txt_SoundFile6->setText(settings.value("NewChatMessage","").toString());
if(!ui.txt_SoundFile->text().isEmpty())ui.checkBoxSound->setEnabled(true);
//if(!ui.txt_SoundFile2->text().isEmpty())ui.checkBoxSound_2->setEnabled(true);
@ -103,17 +102,17 @@ SoundPage::load()
if(!ui.txt_SoundFile5->text().isEmpty())ui.checkBoxSound_5->setEnabled(true);
if(!ui.txt_SoundFile6->text().isEmpty())ui.checkBoxSound_6->setEnabled(true);
_settings->endGroup();
settings.endGroup();
_settings->beginGroup("Enable");
ui.checkBoxSound->setChecked(_settings->value("User_go_Online",false).toBool());
//ui.checkBoxSound_2->setChecked(_settings->value("User_go_Offline",false).toBool());
ui.checkBoxSound_3->setChecked(_settings->value("FileSend_Finished",false).toBool());
ui.checkBoxSound_4->setChecked(_settings->value("FileRecive_Incoming",false).toBool());
ui.checkBoxSound_5->setChecked(_settings->value("FileRecive_Finished",false).toBool());
ui.checkBoxSound_6->setChecked(_settings->value("NewChatMessage",false).toBool());
_settings->endGroup();
_settings->endGroup();
settings.beginGroup("Enable");
ui.checkBoxSound->setChecked(settings.value("User_go_Online",false).toBool());
//ui.checkBoxSound_2->setChecked(settings.value("User_go_Offline",false).toBool());
ui.checkBoxSound_3->setChecked(settings.value("FileSend_Finished",false).toBool());
ui.checkBoxSound_4->setChecked(settings.value("FileRecive_Incoming",false).toBool());
ui.checkBoxSound_5->setChecked(settings.value("FileRecive_Finished",false).toBool());
ui.checkBoxSound_6->setChecked(settings.value("NewChatMessage",false).toBool());
settings.endGroup();
settings.endGroup();
}
void SoundPage::on_cmd_openFile()

View file

@ -24,8 +24,6 @@
#include <QFileDialog>
#include "rsharesettings.h"
#include "configpage.h"
#include "ui_SoundPage.h"
@ -54,9 +52,6 @@ private slots:
void on_cmd_openFile6();
private:
/** A RshareSettings object used for saving/loading settings */
RshareSettings* _settings;
/** Qt Designer generated object */
Ui::SoundPage ui;
};