From c84f34e916468b6d7e919fb1babcf0ed3706db11 Mon Sep 17 00:00:00 2001 From: defnax Date: Fri, 15 Aug 2008 00:23:27 +0000 Subject: [PATCH] -added new Preferences Dialog for Appearance -moved some Settings from General to Appearance ( Language, Style, stylesheet -added checkbox for Start RetroShare with System start in GeneralDialog -moved Rsharesettings to Preferences folder to find bether -added new RSettings source -clean uped some old code stuff in MainWindow which is not more needed -replaced in MainWindow PreferencesWindows open function with new one. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@684 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- retroshare-gui/src/RetroShare.pro | 12 +- retroshare-gui/src/config/rsharesettings.cpp | 127 ++-- retroshare-gui/src/config/rsharesettings.h | 7 +- retroshare-gui/src/gui/MainWindow.cpp | 66 +- retroshare-gui/src/gui/MainWindow.h | 5 +- retroshare-gui/src/gui/MainWindow.ui | 83 +- .../src/gui/Preferences/AppearanceDialog.cpp | 135 ++++ .../src/gui/Preferences/AppearanceDialog.h | 65 ++ .../src/gui/Preferences/AppearanceDialog.ui | 717 ++++++++++++++++++ .../src/gui/Preferences/DirectoriesDialog.h | 2 +- .../src/gui/Preferences/GeneralDialog.cpp | 87 +-- .../src/gui/Preferences/GeneralDialog.h | 8 +- .../src/gui/Preferences/GeneralDialog.ui | 247 +----- .../src/gui/Preferences/PreferencesWindow.cpp | 37 +- .../src/gui/Preferences/PreferencesWindow.h | 19 +- .../src/gui/Preferences/ServerDialog.h | 2 +- .../src/gui/Preferences/rsettings.cpp | 95 +++ .../src/gui/Preferences/rsettings.h | 68 ++ .../src/gui/Preferences/rsharesettings.cpp | 271 +++++++ .../src/gui/Preferences/rsharesettings.h | 120 +++ retroshare-gui/src/gui/common/rwindow.cpp | 6 +- retroshare-gui/src/gui/common/rwindow.h | 2 +- retroshare-gui/src/gui/images.qrc | 1 + retroshare-gui/src/gui/images/kcmsystem24.png | Bin 0 -> 1535 bytes retroshare-gui/src/rshare.cpp | 2 +- retroshare-gui/src/rshare.h | 2 + retroshare-gui/src/util/win32.cpp | 71 ++ retroshare-gui/src/util/win32.h | 12 + 28 files changed, 1779 insertions(+), 490 deletions(-) create mode 100644 retroshare-gui/src/gui/Preferences/AppearanceDialog.cpp create mode 100644 retroshare-gui/src/gui/Preferences/AppearanceDialog.h create mode 100644 retroshare-gui/src/gui/Preferences/AppearanceDialog.ui create mode 100644 retroshare-gui/src/gui/Preferences/rsettings.cpp create mode 100644 retroshare-gui/src/gui/Preferences/rsettings.h create mode 100644 retroshare-gui/src/gui/Preferences/rsharesettings.cpp create mode 100644 retroshare-gui/src/gui/Preferences/rsharesettings.h create mode 100644 retroshare-gui/src/gui/images/kcmsystem24.png diff --git a/retroshare-gui/src/RetroShare.pro b/retroshare-gui/src/RetroShare.pro index b522a051f..ad023d5fa 100644 --- a/retroshare-gui/src/RetroShare.pro +++ b/retroshare-gui/src/RetroShare.pro @@ -44,7 +44,6 @@ HEADERS += rshare.h \ rsiface/rstypes.h \ rsiface/notifyqt.h \ rsiface/RemoteDirModel.h \ - config/rshareSettings.h \ control/bandwidthevent.h \ control/eventtype.h \ gui/DLListDelegate.h \ @@ -118,11 +117,13 @@ HEADERS += rshare.h \ gui/Preferences/configpagestack.h \ gui/Preferences/CryptographyDialog.h \ gui/Preferences/DirectoriesDialog.h \ - gui/Preferences/LogDialog.h \ + gui/Preferences/AppearanceDialog.h \ gui/Preferences/GeneralDialog.h \ gui/Preferences/PreferencesWindow.h \ gui/Preferences/ServerDialog.h \ gui/Preferences/ConfirmQuitDialog.h \ + gui/Preferences/rsharesettings.h \ + gui/Preferences/rsettings.h \ gui/toaster/MessageToaster.h \ gui/toaster/OnlineToaster.h \ gui/toaster/ChatToaster.h \ @@ -219,7 +220,7 @@ FORMS += gui/ChatDialog.ui \ gui/moreinfo/moreinfo.ui \ gui/Preferences/CryptographyDialog.ui \ gui/Preferences/DirectoriesDialog.ui \ - gui/Preferences/LogDialog.ui \ + gui/Preferences/AppearanceDialog.ui \ gui/Preferences/GeneralDialog.ui \ gui/Preferences/PreferencesWindow.ui \ gui/Preferences/ServerDialog.ui \ @@ -263,7 +264,6 @@ SOURCES += main.cpp \ rshare.cpp \ rsiface/notifyqt.cpp \ rsiface/RemoteDirModel.cpp \ - config/rshareSettings.cpp \ gui/DLListDelegate.cpp \ gui/ULListDelegate.cpp \ gui/StartDialog.cpp \ @@ -329,11 +329,13 @@ SOURCES += main.cpp \ gui/Preferences/configpagestack.cpp \ gui/Preferences/CryptographyDialog.cpp \ gui/Preferences/DirectoriesDialog.cpp \ - gui/Preferences/LogDialog.cpp \ + gui/Preferences/AppearanceDialog.cpp \ gui/Preferences/GeneralDialog.cpp \ gui/Preferences/PreferencesWindow.cpp \ gui/Preferences/ServerDialog.cpp \ gui/Preferences/ConfirmQuitDialog.cpp \ + gui/Preferences/rsharesettings.cpp \ + gui/Preferences/rsettings.cpp \ gui/common/vmessagebox.cpp \ gui/common/rwindow.cpp \ gui/common/html.cpp \ diff --git a/retroshare-gui/src/config/rsharesettings.cpp b/retroshare-gui/src/config/rsharesettings.cpp index eec7a3d7b..b2debe992 100644 --- a/retroshare-gui/src/config/rsharesettings.cpp +++ b/retroshare-gui/src/config/rsharesettings.cpp @@ -24,6 +24,7 @@ #include #include +#include #include #include @@ -50,95 +51,51 @@ #define SETTING_BWGRAPH_ALWAYS_ON_TOP "StatisticDialog/AlwaysOnTop" /* Default Retroshare Settings */ -#if defined(Q_WS_MAC) -#define DEFAULT_STYLE "macintosh (aqua)" -#else -#define DEFAULT_STYLE "plastique" -#endif - -#define DEFAULT_SHEETNAME "Default" - -#define DEFAULT_LANGUAGE LanguageSupport::defaultLanguageCode() - #define DEFAULT_OPACITY 100 #if defined(Q_OS_WIN32) - #define STARTUP_REG_KEY "Software\\Microsoft\\Windows\\CurrentVersion\\Run" -#define Rshare_REG_KEY "RetroShare" -#else - +#define Rshare_REG_KEY "RetroShare" #endif /* Default bandwidth graph settings */ #define DEFAULT_BWGRAPH_FILTER (BWGRAPH_SEND|BWGRAPH_REC) #define DEFAULT_BWGRAPH_ALWAYS_ON_TOP false -/** The location of RetroShare's settings and configuration file. */ -#define SETTINGS_FILE (Rshare::dataDirectory() + "/RetroShare.conf") /** Default Constructor */ RshareSettings::RshareSettings() : QSettings(SETTINGS_FILE, QSettings::IniFormat) { - setDefault(SETTING_STYLE, DEFAULT_STYLE); +#if defined(Q_WS_MAC) + setDefault(SETTING_STYLE, "macintosh (aqua)"); +#else + static QStringList styles = QStyleFactory::keys(); +#if defined(Q_WS_WIN) + if (styles.contains("windowsvista", Qt::CaseInsensitive)) + setDefault(SETTING_STYLE, "windowsvista"); + else +#endif + { + if (styles.contains("cleanlooks", Qt::CaseInsensitive)) + setDefault(SETTING_STYLE, "cleanlooks"); + else + setDefault(SETTING_STYLE, "plastique"); + } +#endif + + setDefault(SETTING_LANGUAGE, LanguageSupport::defaultLanguageCode()); + setDefault(SETTING_SHEETNAME, true); setDefault(SETTING_SHOW_MAINWINDOW_AT_START, true); } -/** Sets the default value of key to be val. */ -void RshareSettings::setDefault(QString key, QVariant val) -{ - _defaults.insert(key, val); -} - -/** Returns the default value for key. */ -QVariant RshareSettings::defaultValue(QString key) -{ - if (_defaults.contains(key)) { - return _defaults.value(key); - } - return QVariant(); -} - - - -/** Save val to the configuration file for the setting key, if - * val is different than key's current value. */ -void RshareSettings::setValue(QString key, QVariant val) -{ - if (value(key) != val) { - QSettings::setValue(key, val); - } -} - -/** Returns the value for key. If no value is currently saved, then the - * default value for key will be returned. */ -QVariant RshareSettings::value(QString key) -{ - return value(key, defaultValue(key)); -} - -/** Returns the value for key. If no value is currently saved, then - * defaultValue will be returned. */ -QVariant RshareSettings::value(QString key, QVariant defaultValue) -{ - return QSettings::value(key, defaultValue); -} - - -/** Resets all of RetroShare's settings. */ -void RshareSettings::reset() -{ - QSettings settings(SETTINGS_FILE, QSettings::IniFormat); - settings.clear(); -} /** Gets the currently preferred language code for Rshare. */ QString RshareSettings::getLanguageCode() { - return value(SETTING_LANGUAGE, DEFAULT_LANGUAGE).toString(); + return value(SETTING_LANGUAGE).toString(); } /** Sets the preferred language code. */ @@ -150,7 +107,7 @@ void RshareSettings::setLanguageCode(QString languageCode) /** Gets the interface style key (e.g., "windows", "motif", etc.) */ QString RshareSettings::getInterfaceStyle() { - return value(SETTING_STYLE, DEFAULT_STYLE).toString(); + return value(SETTING_STYLE).toString(); } /** Sets the interface style key. */ @@ -162,7 +119,7 @@ void RshareSettings::setInterfaceStyle(QString styleKey) /** Gets the sheetname.*/ QString RshareSettings::getSheetName() { - return value(SETTING_SHEETNAME, DEFAULT_SHEETNAME).toString(); + return value(SETTING_SHEETNAME).toString(); } /** Sets the sheetname.*/ void RshareSettings::setSheetName(QString sheet) @@ -224,6 +181,42 @@ RshareSettings::setShowMainWindowAtStart(bool show) setValue(SETTING_SHOW_MAINWINDOW_AT_START, show); } +/** Returns true if Vidalia is set to run on system boot. */ +bool +RshareSettings::runRetroshareOnBoot() +{ +#if defined(Q_WS_WIN) + if (!win32_registry_get_key_value(STARTUP_REG_KEY, Rshare_REG_KEY).isEmpty()) { + return true; + } else { + return false; + } +#else + /* Platforms other than windows aren't supported yet */ + return false; +#endif +} + +/** If run is set to true, then Vidalia will run on system boot. */ +void +RshareSettings::setRunRetroshareOnBoot(bool run) +{ +#if defined(Q_WS_WIN) + if (run) { + win32_registry_set_key_value(STARTUP_REG_KEY, Rshare_REG_KEY, + QString("\"" + + QDir::convertSeparators(QCoreApplication::applicationFilePath())) + + "\""); + } else { + win32_registry_remove_key(STARTUP_REG_KEY, Rshare_REG_KEY); + } +#else + /* Platforms othe rthan windows aren't supported yet */ + Q_UNUSED(run); + return; +#endif +} + /** Saving Generic Widget Size / Location */ void RshareSettings::saveWidgetInformation(QWidget *widget) diff --git a/retroshare-gui/src/config/rsharesettings.h b/retroshare-gui/src/config/rsharesettings.h index 48ba7c2a5..efe59c202 100644 --- a/retroshare-gui/src/config/rsharesettings.h +++ b/retroshare-gui/src/config/rsharesettings.h @@ -87,7 +87,12 @@ public: * application starts. */ bool showMainWindowAtStart(); /** Sets whether to show Vidalia's main window when the application starts. */ - void setShowMainWindowAtStart(bool show); + void setShowMainWindowAtStart(bool show); + + /** Returns true if RetroShare should start on system boot. */ + bool runRetroshareOnBoot(); + /** Set whether to run RetroShare on system boot. */ + void setRunRetroshareOnBoot(bool run); /* Get the destination log file. */ diff --git a/retroshare-gui/src/gui/MainWindow.cpp b/retroshare-gui/src/gui/MainWindow.cpp index 9a41ec2c8..3a921b1a6 100644 --- a/retroshare-gui/src/gui/MainWindow.cpp +++ b/retroshare-gui/src/gui/MainWindow.cpp @@ -65,7 +65,7 @@ #define IMAGE_LINKS ":/images/knewsticker24.png" #define IMAGE_FILES ":/images/fileshare24.png" #define IMAGE_CHANNELS ":/images/channels.png" -#define IMAGE_PREFERENCES ":/images/settings16.png" +#define IMAGE_PREFERENCES ":/images/kcmsystem24.png" #define IMAGE_CHAT ":/images/groupchat.png" #define IMAGE_RETROSHARE ":/images/rstray3.png" #define IMAGE_ABOUT ":/images/informations_24x24.png" @@ -111,10 +111,6 @@ MainWindow::MainWindow(QWidget* parent, Qt::WFlags flags) mSMPlayer = NULL; - /* Hide Console frame */ - //showConsoleFrame(false); - //connect(ui.btnToggleConsole, SIGNAL(toggled(bool)), this, SLOT(showConsoleFrame(bool))); - ui.toolBarservice->hide(); // Setting icons @@ -123,6 +119,7 @@ MainWindow::MainWindow(QWidget* parent, Qt::WFlags flags) /* Create all the dialogs of which we only want one instance */ _bandwidthGraph = new BandwidthGraph(); messengerWindow = new MessengerWindow(); + _preferencesWindow = new PreferencesWindow(); messengerWindow->hide(); //messengerWindow->show(); applicationWindow = new ApplicationWindow(); @@ -137,13 +134,8 @@ MainWindow::MainWindow(QWidget* parent, Qt::WFlags flags) connect(ui.actionSMPlayer, SIGNAL(triggered()), this, SLOT( showsmplayer()) ); connect(ui.actionAbout, SIGNAL(triggered()), this, SLOT( showabout()) ); connect(ui.actionColor, SIGNAL(triggered()), this, SLOT( setStyle()) ); - - - /** Games ToolBox*/ - //connect(ui.qbackgammonButton, SIGNAL(clicked( bool )), this, SLOT( startgammon()) ); - //connect(ui.qcheckersButton, SIGNAL(clicked( bool )), this, SLOT( startqcheckers()) ); - - + + /** adjusted quit behaviour: trigger a warning that can be switched off in the saved config file RetroShare.conf */ connect(ui.actionQuit, SIGNAL(triggered()), this, SLOT(doQuit())); @@ -465,11 +457,11 @@ void MainWindow::addSharedDirectory() } /** Shows Preferences */ -void MainWindow::showPreferencesWindow() +/*void MainWindow::showPreferencesWindow() { static PreferencesWindow* preferencesWindow = new PreferencesWindow(this); preferencesWindow->show(); -} +}*/ /** Shows Options */ void MainWindow::showSettings() @@ -497,10 +489,10 @@ void MainWindow::showApplWindow() /** Destructor. */ MainWindow::~MainWindow() { - delete _prefsAct; delete _bandwidthGraph; delete _messengerwindowAct; delete _smplayerAct; + delete _preferencesWindow; } /** Create and bind actions to events. Setup for initial @@ -614,43 +606,6 @@ void MainWindow::toggleVisibilitycontextmenu() show(); } - -/** -Toggles the Console pane on and off, changes toggle button text - */ -/*void MainWindow::showConsoleFrame(bool show) -{ - if (show) { - ui.frmConsole->setVisible(true); - ui.btnToggleConsole->setChecked(true); - ui.btnToggleConsole->setToolTip(tr("Hide Console")); - } else { - ui.frmConsole->setVisible(false); - ui.btnToggleConsole->setChecked(false); - ui.btnToggleConsole->setToolTip(tr("Show Console")); - } -}*/ - -/** - Toggles the ToolBox on and off, changes toggle button text - */ -/*void MainWindow::showToolboxFrame(bool show) -{ - if (show) { - ui.toolboxframe->setVisible(true); - ui.btntoggletoolbox->setChecked(true); - ui.btntoggletoolbox->setToolTip(tr("Hide ToolBox")); - ui.btntoggletoolbox->setIcon(QIcon(tr(":images/hide_toolbox_frame.png"))); - } else { - ui.toolboxframe->setVisible(false); - ui.btntoggletoolbox->setChecked(false); - ui.btntoggletoolbox->setToolTip(tr("Show ToolBox")); - ui.btntoggletoolbox->setIcon(QIcon(tr(":images/show_toolbox_frame.png"))); - } -}*/ - - - void MainWindow::loadStyleSheet(const QString &sheetName) { /** internal Stylesheets **/ @@ -744,5 +699,12 @@ void MainWindow::setStyle() } +/** Creates and displays the Configuration dialog with the current page set to + * page. */ +void +MainWindow::showPreferencesWindow(PreferencesWindow::Page page) +{ + _preferencesWindow->showWindow(page); +} diff --git a/retroshare-gui/src/gui/MainWindow.h b/retroshare-gui/src/gui/MainWindow.h index eaf7106bb..dbd8fceb4 100644 --- a/retroshare-gui/src/gui/MainWindow.h +++ b/retroshare-gui/src/gui/MainWindow.h @@ -128,7 +128,7 @@ private slots: void addFriend(); void inviteFriend(); void addSharedDirectory(); - void showPreferencesWindow(); + //void showPreferencesWindow(); void showMessengerWindow(); void showApplWindow(); void showsmplayer(); @@ -140,6 +140,9 @@ private slots: /** Called when a child window requests the given help topic. */ void showHelpDialog(const QString &topic); + /** Creates and displays the Configuration dialog with the current page set + * to page. */ + void showPreferencesWindow(PreferencesWindow::Page page = PreferencesWindow::General); void showSettings(); void setStyle(); diff --git a/retroshare-gui/src/gui/MainWindow.ui b/retroshare-gui/src/gui/MainWindow.ui index 095b0a51a..4c4507932 100644 --- a/retroshare-gui/src/gui/MainWindow.ui +++ b/retroshare-gui/src/gui/MainWindow.ui @@ -505,17 +505,16 @@ Qt::ToolButtonIconOnly + + + 35 + 12 + 753 + 567 + + - - 0 - - - 0 - - - 0 - - + 0 @@ -1014,8 +1013,25 @@ - + + + + 0 + 579 + 800 + 21 + + + + + + 0 + 0 + 800 + 12 + + Qt::NoContextMenu @@ -1045,11 +1061,19 @@ + + + 788 + 12 + 12 + 567 + + - Qt::BottomToolBarArea|Qt::LeftToolBarArea|Qt::NoToolBarArea|Qt::RightToolBarArea + Qt::BottomToolBarArea|Qt::LeftToolBarArea|Qt::RightToolBarArea @@ -1068,6 +1092,14 @@ true + + + 0 + 12 + 35 + 567 + + toolBar_2 @@ -1098,7 +1130,8 @@ - :/images/add-friend24.png + + :/images/add-friend24.png:/images/add-friend24.png Add Friend @@ -1106,7 +1139,8 @@ - :/images/invite-friend24.png + + :/images/invite-friend24.png:/images/invite-friend24.png Invite Friend @@ -1114,7 +1148,8 @@ - :/images/add-share24.png + + :/images/add-share24.png:/images/add-share24.png Add Share @@ -1122,7 +1157,8 @@ - :/images/settings.png + + :/images/kcmsystem24.png:/images/kcmsystem24.png Options @@ -1130,7 +1166,8 @@ - :/images/exit_24x24.png + + :/images/exit_24x24.png:/images/exit_24x24.png Quit @@ -1141,7 +1178,8 @@ false - :/images/highlight.png + + :/images/highlight.png:/images/highlight.png Color @@ -1152,7 +1190,8 @@ - :/images/smplayer_icon32.png + + :/images/smplayer_icon32.png:/images/smplayer_icon32.png SMPlayer @@ -1160,7 +1199,8 @@ - :/images/kdmconfig.png + + :/images/kdmconfig.png:/images/kdmconfig.png Messenger @@ -1168,7 +1208,8 @@ - :/images/informations_24x24.png + + :/images/informations_24x24.png:/images/informations_24x24.png About diff --git a/retroshare-gui/src/gui/Preferences/AppearanceDialog.cpp b/retroshare-gui/src/gui/Preferences/AppearanceDialog.cpp new file mode 100644 index 000000000..e9b5a42ae --- /dev/null +++ b/retroshare-gui/src/gui/Preferences/AppearanceDialog.cpp @@ -0,0 +1,135 @@ +/**************************************************************** + * RShare is distributed under the following license: + * + * Copyright (C) 2006, crypton + * + * 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. + ****************************************************************/ + + +#include +#include "AppearanceDialog.h" + + +/** Constructor */ +AppearanceDialog::AppearanceDialog(QWidget *parent) +: ConfigPage(parent) +{ + /* 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 */ + foreach (QString code, LanguageSupport::languageCodes()) { + ui.cmboLanguage->addItem(QIcon(":/images/flags/" + code + ".png"), + LanguageSupport::languageName(code), + code); + } + foreach (QString style, QStyleFactory::keys()) { + ui.cmboStyle->addItem(style, style.toLower()); + } + + ui.styleSheetCombo->setCurrentIndex(ui.styleSheetCombo->findText("Default")); + //loadStyleSheet("Default"); + loadqss(); + + + /* Hide platform specific features */ +#ifdef Q_WS_WIN + +#endif +} + +/** Saves the changes on this page */ +bool +AppearanceDialog::save(QString &errmsg) +{ + Q_UNUSED(errmsg); + QString languageCode = + LanguageSupport::languageCode(ui.cmboLanguage->currentText()); + + _settings->setLanguageCode(languageCode); + _settings->setInterfaceStyle(ui.cmboStyle->currentText()); + _settings->setSheetName(ui.styleSheetCombo->currentText()); + + /* Set to new style */ + Rshare::setStyle(ui.cmboStyle->currentText()); + return true; +} + + + +/** Loads the settings for this page */ +void +AppearanceDialog::load() +{ + + 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())); + + /** load saved internal styleSheet **/ + //QFile file(":/qss/" + (_settings->getSheetName().toLower()) + ".qss"); + + /** load saved extern Stylesheets **/ + QFile file(QApplication::applicationDirPath() + "/qss/" + (_settings->getSheetName().toLower()) + ".qss"); + + file.open(QFile::ReadOnly); + QString styleSheet = QLatin1String(file.readAll()); + qApp->setStyleSheet(styleSheet); + +} + +void AppearanceDialog::on_styleSheetCombo_activated(const QString &sheetName) +{ + loadStyleSheet(sheetName); +} + +void AppearanceDialog::loadStyleSheet(const QString &sheetName) +{ + /** internal Stylesheets **/ + //QFile file(":/qss/" + sheetName.toLower() + ".qss"); + + /** extern Stylesheets **/ + QFile file(QApplication::applicationDirPath() + "/qss/" + sheetName.toLower() + ".qss"); + + file.open(QFile::ReadOnly); + QString styleSheet = QLatin1String(file.readAll()); + + + qApp->setStyleSheet(styleSheet); + +} + +void AppearanceDialog::loadqss() +{ + + QFileInfoList slist = QDir(QApplication::applicationDirPath() + "/qss/").entryInfoList(); + foreach(QFileInfo st, slist) + { + if(st.fileName() != "." && st.fileName() != ".." && st.isFile()) + ui.styleSheetCombo->addItem(st.fileName().remove(".qss")); + } + +} \ No newline at end of file diff --git a/retroshare-gui/src/gui/Preferences/AppearanceDialog.h b/retroshare-gui/src/gui/Preferences/AppearanceDialog.h new file mode 100644 index 000000000..88655ae14 --- /dev/null +++ b/retroshare-gui/src/gui/Preferences/AppearanceDialog.h @@ -0,0 +1,65 @@ +/**************************************************************** + * RShare is distributed under the following license: + * + * Copyright (C) 2006, crypton + * + * 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 _LOGDIALOG_H +#define _LOGDIALOG_H + +#include +#include + +#include "rsharesettings.h" +#include + +#include "configpage.h" +#include "ui_AppearanceDialog.h" + +class AppearanceDialog : public ConfigPage +{ + Q_OBJECT + +public: + /** Default Constructor */ + AppearanceDialog(QWidget *parent = 0); + /** Default Destructor */ + + /** Saves the changes on this page */ + bool save(QString &errmsg); + /** Loads the settings for this page */ + void load(); + +private slots: + + void on_styleSheetCombo_activated(const QString &styleSheetName); + + +private: + /** A RshareSettings object used for saving/loading settings */ + RshareSettings* _settings; + + void loadStyleSheet(const QString &sheetName); + void loadqss(); + + /** Qt Designer generated object */ + Ui::AppearanceDialog ui; +}; + +#endif + diff --git a/retroshare-gui/src/gui/Preferences/AppearanceDialog.ui b/retroshare-gui/src/gui/Preferences/AppearanceDialog.ui new file mode 100644 index 000000000..9f775ec3e --- /dev/null +++ b/retroshare-gui/src/gui/Preferences/AppearanceDialog.ui @@ -0,0 +1,717 @@ + + AppearanceDialog + + + + 0 + 0 + 440 + 311 + + + + + + + + + 0 + 0 + 0 + + + + + + + 208 + 208 + 208 + + + + + + + 255 + 255 + 255 + + + + + + + 247 + 247 + 247 + + + + + + + 104 + 104 + 104 + + + + + + + 139 + 139 + 139 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 240 + 240 + 240 + + + + + + + 0 + 0 + 0 + + + + + + + 0 + 0 + 128 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 0 + 255 + + + + + + + 255 + 0 + 255 + + + + + + + 231 + 231 + 231 + + + + + + + + + 0 + 0 + 0 + + + + + + + 208 + 208 + 208 + + + + + + + 255 + 255 + 255 + + + + + + + 247 + 247 + 247 + + + + + + + 104 + 104 + 104 + + + + + + + 139 + 139 + 139 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 240 + 240 + 240 + + + + + + + 0 + 0 + 0 + + + + + + + 192 + 192 + 192 + + + + + + + 0 + 0 + 0 + + + + + + + 0 + 0 + 255 + + + + + + + 255 + 0 + 255 + + + + + + + 231 + 231 + 231 + + + + + + + + + 104 + 104 + 104 + + + + + + + 208 + 208 + 208 + + + + + + + 255 + 255 + 255 + + + + + + + 247 + 247 + 247 + + + + + + + 104 + 104 + 104 + + + + + + + 139 + 139 + 139 + + + + + + + 104 + 104 + 104 + + + + + + + 255 + 255 + 255 + + + + + + + 104 + 104 + 104 + + + + + + + 240 + 240 + 240 + + + + + + + 240 + 240 + 240 + + + + + + + 0 + 0 + 0 + + + + + + + 0 + 0 + 128 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 0 + 255 + + + + + + + 255 + 0 + 255 + + + + + + + 231 + 231 + 231 + + + + + + + + + Arial + 8 + 50 + false + false + false + false + + + + Qt::NoContextMenu + + + + + 0 + 0 + 441 + 75 + + + + Qt::NoContextMenu + + + Language + + + + + 10 + 44 + 341 + 26 + + + + + 0 + + + 6 + + + + + Qt::Horizontal + + + + 300 + 16 + + + + + + + + + 150 + 0 + + + + Qt::NoContextMenu + + + <html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'Arial'; font-size:10pt; font-weight:400; font-style:normal; text-decoration:none;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Choose the language used in RetroShare</p></body></html> + + + false + + + + 24 + 16 + + + + + + + + + + 10 + 27 + 591 + 17 + + + + Qt::NoContextMenu + + + <html><head><meta name="qrichtext" content="1" /></head><body style=" white-space: pre-wrap; font-family:Arial; font-size:8pt; font-weight:400; font-style:normal; text-decoration:none;"><p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Changes to language will only take effect after restarting RetroShare!</p></body></html> + + + + + + + 0 + 80 + 441 + 55 + + + + Qt::NoContextMenu + + + + + + Style + + + + + 10 + 24 + 341 + 26 + + + + + 0 + + + 6 + + + + + + 150 + 0 + + + + Qt::NoContextMenu + + + <html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'Arial'; font-size:10pt; font-weight:400; font-style:normal; text-decoration:none;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Choose RetroShare's interface style</p></body></html> + + + false + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + 0 + 140 + 441 + 61 + + + + Style Sheet + + + + + 11 + 20 + 341 + 25 + + + + + 0 + + + 6 + + + + + Qt::Horizontal + + + + 181 + 20 + + + + + + + + + 150 + 0 + + + + + + + + + + + + + diff --git a/retroshare-gui/src/gui/Preferences/DirectoriesDialog.h b/retroshare-gui/src/gui/Preferences/DirectoriesDialog.h index 14e380edf..b3fca1536 100644 --- a/retroshare-gui/src/gui/Preferences/DirectoriesDialog.h +++ b/retroshare-gui/src/gui/Preferences/DirectoriesDialog.h @@ -24,7 +24,7 @@ #include -#include +#include "rsharesettings.h" #include "configpage.h" #include "ui_DirectoriesDialog.h" diff --git a/retroshare-gui/src/gui/Preferences/GeneralDialog.cpp b/retroshare-gui/src/gui/Preferences/GeneralDialog.cpp index 2802018f7..afb7293eb 100644 --- a/retroshare-gui/src/gui/Preferences/GeneralDialog.cpp +++ b/retroshare-gui/src/gui/Preferences/GeneralDialog.cpp @@ -34,22 +34,6 @@ GeneralDialog::GeneralDialog(QWidget *parent) /* Create RshareSettings object */ _settings = new RshareSettings(); - connect(ui.styleSheetCombo, SIGNAL(clicked()), this, SLOT(loadStyleSheet())); - - /* Populate combo boxes */ - foreach (QString code, LanguageSupport::languageCodes()) { - ui.cmboLanguage->addItem(QIcon(":/images/flags/" + code + ".png"), - LanguageSupport::languageName(code), - code); - } - foreach (QString style, QStyleFactory::keys()) { - ui.cmboStyle->addItem(style, style.toLower()); - } - - ui.styleSheetCombo->setCurrentIndex(ui.styleSheetCombo->findText("Default")); - //loadStyleSheet("Default"); - loadqss(); - if (QSystemTrayIcon::isSystemTrayAvailable()){ /* Check if we are supposed to show our main window on startup */ @@ -61,7 +45,10 @@ GeneralDialog::GeneralDialog(QWidget *parent) ui.chkShowOnStartup->hide(); //show(); } - + /* Hide platform specific features */ +#ifndef Q_WS_WIN + ui.chkRunRetroshareAtSystemStartup->setVisible(false); +#endif } /** Destructor */ @@ -75,18 +62,9 @@ bool GeneralDialog::save(QString &errmsg) { Q_UNUSED(errmsg); - QString languageCode = - LanguageSupport::languageCode(ui.cmboLanguage->currentText()); - - _settings->setLanguageCode(languageCode); - _settings->setInterfaceStyle(ui.cmboStyle->currentText()); - _settings->setSheetName(ui.styleSheetCombo->currentText()); _settings->setValue(QString::fromUtf8("StartMinimized"), startMinimized()); - - /* Set to new style */ - Rshare::setStyle(ui.cmboStyle->currentText()); return true; } @@ -94,61 +72,16 @@ GeneralDialog::save(QString &errmsg) void GeneralDialog::load() { - int index = ui.cmboLanguage->findData(_settings->getLanguageCode()); - ui.cmboLanguage->setCurrentIndex(index); - index = ui.cmboStyle->findData(Rshare::style().toLower()); - ui.cmboStyle->setCurrentIndex(index); - - ui.checkStartMinimized->setChecked(_settings->value(QString::fromUtf8("StartMinimized"), false).toBool()); + ui.chkRunRetroshareAtSystemStartup->setChecked( + _settings->runRetroshareOnBoot()); - - ui.styleSheetCombo->setCurrentIndex(ui.styleSheetCombo->findText(_settings->getSheetName())); - - /** load saved internal styleSheet **/ - //QFile file(":/qss/" + (_settings->getSheetName().toLower()) + ".qss"); - - /** load saved extern Stylesheets **/ - QFile file(QApplication::applicationDirPath() + "/qss/" + (_settings->getSheetName().toLower()) + ".qss"); - - file.open(QFile::ReadOnly); - QString styleSheet = QLatin1String(file.readAll()); - qApp->setStyleSheet(styleSheet); - -} - -void GeneralDialog::on_styleSheetCombo_activated(const QString &sheetName) -{ - loadStyleSheet(sheetName); -} - -void GeneralDialog::loadStyleSheet(const QString &sheetName) -{ - /** internal Stylesheets **/ - //QFile file(":/qss/" + sheetName.toLower() + ".qss"); - - /** extern Stylesheets **/ - QFile file(QApplication::applicationDirPath() + "/qss/" + sheetName.toLower() + ".qss"); - - file.open(QFile::ReadOnly); - QString styleSheet = QLatin1String(file.readAll()); - - - qApp->setStyleSheet(styleSheet); - -} - -void GeneralDialog::loadqss() -{ - - QFileInfoList slist = QDir(QApplication::applicationDirPath() + "/qss/").entryInfoList(); - foreach(QFileInfo st, slist) - { - if(st.fileName() != "." && st.fileName() != ".." && st.isFile()) - ui.styleSheetCombo->addItem(st.fileName().remove(".qss")); - } + ui.checkStartMinimized->setChecked(_settings->value(QString::fromUtf8("StartMinimized"), false).toBool()); + } + + bool GeneralDialog::startMinimized() const { if(ui.checkStartMinimized->isChecked()) return true; diff --git a/retroshare-gui/src/gui/Preferences/GeneralDialog.h b/retroshare-gui/src/gui/Preferences/GeneralDialog.h index 3a68cc1c1..08042a3c0 100644 --- a/retroshare-gui/src/gui/Preferences/GeneralDialog.h +++ b/retroshare-gui/src/gui/Preferences/GeneralDialog.h @@ -24,11 +24,9 @@ #define _GENERALDIALOG_H #include #include -#include #include -#include -#include +#include "rsharesettings.h" #include "configpage.h" #include "ui_GeneralDialog.h" @@ -51,15 +49,13 @@ public: private slots: - void on_styleSheetCombo_activated(const QString &styleSheetName); private: /** A VidaliaSettings object used for saving/loading settings */ RshareSettings* _settings; - void loadStyleSheet(const QString &sheetName); - void loadqss(); + /** Qt Designer generated object */ Ui::GeneralDialog ui; diff --git a/retroshare-gui/src/gui/Preferences/GeneralDialog.ui b/retroshare-gui/src/gui/Preferences/GeneralDialog.ui index 493d1a597..7ad9b1563 100644 --- a/retroshare-gui/src/gui/Preferences/GeneralDialog.ui +++ b/retroshare-gui/src/gui/Preferences/GeneralDialog.ui @@ -492,228 +492,11 @@ Qt::NoContextMenu - - - - 0 - 80 - 441 - 55 - - - - Qt::NoContextMenu - - - - - - Style - - - - - 10 - 24 - 341 - 26 - - - - - 0 - - - 6 - - - - - - 150 - 0 - - - - Qt::NoContextMenu - - - <html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'Arial'; font-size:10pt; font-weight:400; font-style:normal; text-decoration:none;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Choose RetroShare's interface style</p></body></html> - - - false - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - 0 - 0 - 441 - 75 - - - - Qt::NoContextMenu - - - Language - - - - - 10 - 44 - 341 - 26 - - - - - 0 - - - 6 - - - - - Qt::Horizontal - - - - 300 - 16 - - - - - - - - - 150 - 0 - - - - Qt::NoContextMenu - - - <html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'Arial'; font-size:10pt; font-weight:400; font-style:normal; text-decoration:none;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Choose the language used in RetroShare</p></body></html> - - - false - - - - 24 - 16 - - - - - - - - - - 10 - 27 - 591 - 17 - - - - Qt::NoContextMenu - - - <html><head><meta name="qrichtext" content="1" /></head><body style=" white-space: pre-wrap; font-family:Arial; font-size:8pt; font-weight:400; font-style:normal; text-decoration:none;"><p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Changes to language will only take effect after restarting RetroShare!</p></body></html> - - - - - - - 0 - 140 - 441 - 61 - - - - Style Sheet - - - - - 11 - 20 - 341 - 25 - - - - - 0 - - - 6 - - - - - Qt::Horizontal - - - - 181 - 20 - - - - - - - - - 150 - 0 - - - - - - - 0 - 210 + 0 441 61 @@ -739,19 +522,19 @@ p, li { white-space: pre-wrap; } 0 - 280 + 60 441 - 80 + 111 - System tray + Misc 10 - 20 + 40 401 20 @@ -767,7 +550,7 @@ p, li { white-space: pre-wrap; } 10 - 50 + 60 401 20 @@ -779,13 +562,21 @@ p, li { white-space: pre-wrap; } true + + + + 10 + 20 + 411 + 18 + + + + Start RetroShare when my system starts + + - - cmboLanguage - cmboStyle - styleSheetCombo - diff --git a/retroshare-gui/src/gui/Preferences/PreferencesWindow.cpp b/retroshare-gui/src/gui/Preferences/PreferencesWindow.cpp index 8aace05a3..e26c18acd 100644 --- a/retroshare-gui/src/gui/Preferences/PreferencesWindow.cpp +++ b/retroshare-gui/src/gui/Preferences/PreferencesWindow.cpp @@ -31,7 +31,7 @@ #define FONT QFont(tr("Arial"), 8) /* Images for toolbar icons */ -#define IMAGE_PREFERENCES ":/images/locale.png" +#define IMAGE_PREFERENCES ":/images/kcmsystem24.png" #define IMAGE_SERVER ":/images/server_24x24.png" #define IMAGE_DIRECTORIES ":/images/folder_doments.png" #define IMAGE_CRYPTOGRAPHY ":/images/cryptography_24x24.png" @@ -42,7 +42,7 @@ /** Constructor */ PreferencesWindow::PreferencesWindow(QWidget *parent, Qt::WFlags flags) -: QMainWindow(parent, flags) +: RWindow("PreferencesWindow", parent, flags) { /* Invoke the Qt Designer generated QObject setup routine */ ui.setupUi(this); @@ -56,7 +56,15 @@ PreferencesWindow::PreferencesWindow(QWidget *parent, Qt::WFlags flags) createPageAction(QIcon(IMAGE_SERVER), tr("Server"), grp)); ui.stackPages->add(new DirectoriesDialog(ui.stackPages), - createPageAction(QIcon(IMAGE_DIRECTORIES), tr("Directories"), grp)); + createPageAction(QIcon(IMAGE_DIRECTORIES), tr("Directories"), grp)); + + ui.stackPages->add(new AppearanceDialog(ui.stackPages), + createPageAction(QIcon(IMAGE_DIRECTORIES), tr("AppearanceDialog"), grp)); + + /*foreach (ConfigPage *page, ui.stackPages->pages()) { + connect(page, SIGNAL(helpRequested(QString)), + this, SLOT(help(QString))); + } */ /* Create the toolbar */ ui.toolBar->addActions(grp->actions()); @@ -103,11 +111,11 @@ PreferencesWindow::addAction(QAction *action, const char *slot) } /** Overloads the default show so we can load settings */ -void +/*void PreferencesWindow::show() -{ +{*/ /* Load saved settings */ - loadSettings(); + /*loadSettings(); if (!this->isVisible()) { QMainWindow::show(); @@ -116,15 +124,16 @@ PreferencesWindow::show() setWindowState(windowState() & ~Qt::WindowMinimized | Qt::WindowActive); QMainWindow::raise(); } -} +}*/ -/** Shows the config dialog with focus set to the given page. */ +/** Shows the Preferences dialog with focus set to the given page. */ void -PreferencesWindow::show(Page page) +PreferencesWindow::showWindow(Page page) { - /* Show the dialog. */ - show(); - + /* Load saved settings */ + loadSettings(); + /* Show the dialog. */ + RWindow::showWindow(); /* Set the focus to the specified page. */ ui.stackPages->setCurrentIndex((int)page); } @@ -215,9 +224,9 @@ PreferencesWindow::help() case General: help("config.general"); break; case Server: - help("server"); break; - case Directories: help("config.server"); break; + case Directories: + help("config.directories"); break; default: help("config.general"); break; } diff --git a/retroshare-gui/src/gui/Preferences/PreferencesWindow.h b/retroshare-gui/src/gui/Preferences/PreferencesWindow.h index cc8f74fad..6947de910 100644 --- a/retroshare-gui/src/gui/Preferences/PreferencesWindow.h +++ b/retroshare-gui/src/gui/Preferences/PreferencesWindow.h @@ -29,14 +29,14 @@ #include "DirectoriesDialog.h" #include "ServerDialog.h" #include "CryptographyDialog.h" -#include "LogDialog.h" +#include "AppearanceDialog.h" #include "gui/help/browser/helpbrowser.h" - +#include #include "ui_PreferencesWindow.h" -class PreferencesWindow : public QMainWindow +class PreferencesWindow : public RWindow { Q_OBJECT @@ -44,10 +44,9 @@ public: /** Preferences dialog pages. */ enum Page { General = 0, /** Preferences page. */ - Directories = 1, /** Directories page. */ - Server = 2, /** Server page. */ - Cryptography = 3, /** Cryptography page. */ - About = 4 /** About page. */ + Server, /** Server page. */ + Directories, /** Directories page. */ + Appearance /** Appearance page. */ }; @@ -61,9 +60,9 @@ protected: public slots: /** Called when this dialog is to be displayed */ - void show(); - /** Shows the config dialog with focus set to the given page. */ - void show(Page page); + //void show(); + /** Shows the Preferences dialog with focus set to the given page. */ + void showWindow(Page page); private slots: diff --git a/retroshare-gui/src/gui/Preferences/ServerDialog.h b/retroshare-gui/src/gui/Preferences/ServerDialog.h index 4daa5f0a0..21ed8e2da 100644 --- a/retroshare-gui/src/gui/Preferences/ServerDialog.h +++ b/retroshare-gui/src/gui/Preferences/ServerDialog.h @@ -24,7 +24,7 @@ #include -#include +#include "rsharesettings.h" #include "configpage.h" #include "ui_ServerDialog.h" diff --git a/retroshare-gui/src/gui/Preferences/rsettings.cpp b/retroshare-gui/src/gui/Preferences/rsettings.cpp new file mode 100644 index 000000000..ce17420c7 --- /dev/null +++ b/retroshare-gui/src/gui/Preferences/rsettings.cpp @@ -0,0 +1,95 @@ +/**************************************************************** + * This file is distributed under the following license: + * + * Copyright (c) 2008, crypton + * Copyright (c) 2008, 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. + ****************************************************************/ + +#include + +#include "rsettings.h" + +/** The file in which all settings will read and written. */ +#define SETTINGS_FILE (Rshare::dataDirectory() + "/RetroShare.conf") + +/** Constructor */ +RSettings::RSettings(const QString settingsGroup) +: QSettings(SETTINGS_FILE, QSettings::IniFormat) +{ + if (!settingsGroup.isEmpty()) + beginGroup(settingsGroup); +} + +/** Returns the saved value associated with key. If no value has been + * set, the default value is returned. + * \sa setDefault + */ +QVariant +RSettings::value(const QString &key, const QVariant &defaultVal) const +{ + return QSettings::value(key, defaultVal.isNull() ? defaultValue(key) + : defaultVal); +} + +/** Sets the value associated with key to val. */ +void +RSettings::setValue(const QString &key, const QVariant &val) +{ + if (val == defaultValue(key)) + QSettings::remove(key); + else if (val != value(key)) + QSettings::setValue(key, val); +} + +/** Sets the default setting for key to val. */ +void +RSettings::setDefault(const QString &key, const QVariant &val) +{ + _defaults.insert(key, val); +} + +/** Returns the default setting value associated with key. If + * key has no default value, then an empty QVariant is returned. */ +QVariant +RSettings::defaultValue(const QString &key) const +{ + if (_defaults.contains(key)) + return _defaults.value(key); + return QVariant(); +} + +/** Resets all of Vidalia's settings. */ +void +RSettings::reset() +{ + /* Static method, so we have to create a QSettings object. */ + QSettings settings(SETTINGS_FILE, QSettings::IniFormat); + settings.clear(); +} + +/** Returns a map of all currently saved settings at the last appyl() point. */ +/*QMap +RSettings::allSettings() const +{ + QMap settings; + foreach (QString key, allKeys()) { + settings.insert(key, value(key)); + } + return settings; +}*/ + diff --git a/retroshare-gui/src/gui/Preferences/rsettings.h b/retroshare-gui/src/gui/Preferences/rsettings.h new file mode 100644 index 000000000..c598cb513 --- /dev/null +++ b/retroshare-gui/src/gui/Preferences/rsettings.h @@ -0,0 +1,68 @@ +/**************************************************************** + * This file is distributed under the following license: + * + * Copyright (c) 2008, crypton + * Copyright (c) 2008, 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 _RSETTINGS_H +#define _RSETTINGS_H + +#include +#include + + +class RSettings : public QSettings +{ + Q_OBJECT + +public: + /** Default constructor. The optional parameter group can be used to + * set a prefix that will be prepended to keys specified to VSettings in + * value() and setValue(). */ + RSettings(const QString group = QString()); + + /** Resets all of Vidalia's settings. */ + static void reset(); + + /** Returns the saved value associated with key. If no value has been + * set, the default value is returned. + * \sa setDefault + */ + virtual QVariant value(const QString &key, + const QVariant &defaultVal = QVariant()) const; + /** Sets the value associated with key to val. */ + virtual void setValue(const QString &key, const QVariant &val); + +protected: + /** Sets the default setting for key to val. */ + void setDefault(const QString &key, const QVariant &val); + /** Returns the default setting value associated with key. If + * key has no default value, then an empty QVariant is returned. */ + QVariant defaultValue(const QString &key) const; + /** Returns a map of all currently saved settings at the last apply() + * point. */ + //QMap allSettings() const; + +private: + /** Association of setting key names to default setting values. */ + QHash _defaults; +}; + +#endif + diff --git a/retroshare-gui/src/gui/Preferences/rsharesettings.cpp b/retroshare-gui/src/gui/Preferences/rsharesettings.cpp new file mode 100644 index 000000000..a858c0d23 --- /dev/null +++ b/retroshare-gui/src/gui/Preferences/rsharesettings.cpp @@ -0,0 +1,271 @@ +/**************************************************************** + * 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. + ****************************************************************/ + + + +#include +#include +#include +#include +#include + +#include "rsharesettings.h" + +#include +#include + +#if defined(Q_WS_WIN) +#include +#include +#endif + + +/* Retroshare's Settings */ +#define SETTING_LANGUAGE "LanguageCode" +#define SETTING_STYLE "InterfaceStyle" +#define SETTING_SHEETNAME "SheetName" + +#define SETTING_DATA_DIRECTORY "DataDirectory" +#define SETTING_SHOW_MAINWINDOW_AT_START "ShowMainWindowAtStart" +#define SETTING_BWGRAPH_FILTER "StatisticDialog/BWLineFilter" +#define SETTING_BWGRAPH_OPACITY "StatisticDialog/Opacity" +#define SETTING_BWGRAPH_ALWAYS_ON_TOP "StatisticDialog/AlwaysOnTop" + +/* Default Retroshare Settings */ +#define DEFAULT_OPACITY 100 + + +#if defined(Q_OS_WIN32) +#define STARTUP_REG_KEY "Software\\Microsoft\\Windows\\CurrentVersion\\Run" +#define RETROSHARE_REG_KEY "RetroShare" +#endif + +/* Default bandwidth graph settings */ +#define DEFAULT_BWGRAPH_FILTER (BWGRAPH_SEND|BWGRAPH_REC) +#define DEFAULT_BWGRAPH_ALWAYS_ON_TOP false + + + +/** Default Constructor */ +RshareSettings::RshareSettings() +{ +#if defined(Q_WS_MAC) + setDefault(SETTING_STYLE, "macintosh (aqua)"); +#else + static QStringList styles = QStyleFactory::keys(); +#if defined(Q_WS_WIN) + if (styles.contains("windowsvista", Qt::CaseInsensitive)) + setDefault(SETTING_STYLE, "windowsvista"); + else +#endif + { + if (styles.contains("cleanlooks", Qt::CaseInsensitive)) + setDefault(SETTING_STYLE, "cleanlooks"); + else + setDefault(SETTING_STYLE, "plastique"); + } +#endif + + setDefault(SETTING_LANGUAGE, LanguageSupport::defaultLanguageCode()); + setDefault(SETTING_SHEETNAME, true); + setDefault(SETTING_SHOW_MAINWINDOW_AT_START, true); +} + + +/** Gets the currently preferred language code for Rshare. */ +QString RshareSettings::getLanguageCode() +{ + return value(SETTING_LANGUAGE).toString(); +} + +/** Sets the preferred language code. */ +void RshareSettings::setLanguageCode(QString languageCode) +{ + setValue(SETTING_LANGUAGE, languageCode); +} + +/** Gets the interface style key (e.g., "windows", "motif", etc.) */ +QString RshareSettings::getInterfaceStyle() +{ + return value(SETTING_STYLE).toString(); +} + +/** Sets the interface style key. */ +void RshareSettings::setInterfaceStyle(QString styleKey) +{ + setValue(SETTING_STYLE, styleKey); +} + +/** Gets the sheetname.*/ +QString RshareSettings::getSheetName() +{ + return value(SETTING_SHEETNAME).toString(); +} +/** Sets the sheetname.*/ +void RshareSettings::setSheetName(QString sheet) +{ + setValue(SETTING_SHEETNAME, sheet); +} + +/** Returns the bandwidth line filter. */ +uint RshareSettings::getBWGraphFilter() +{ + return value(SETTING_BWGRAPH_FILTER, DEFAULT_BWGRAPH_FILTER).toUInt(); +} + +/** Saves the setting for whether or not the given line will be graphed */ +void RshareSettings::setBWGraphFilter(uint line, bool status) +{ + uint filter = getBWGraphFilter(); + filter = (status ? (filter | line) : (filter & ~(line))); + setValue(SETTING_BWGRAPH_FILTER, filter); +} + +/** Get the level of opacity for the BandwidthGraph window. */ +int RshareSettings::getBWGraphOpacity() +{ + return value(SETTING_BWGRAPH_OPACITY, DEFAULT_OPACITY).toInt(); +} + +/** Set the level of opacity for the BandwidthGraph window. */ +void RshareSettings::setBWGraphOpacity(int value) +{ + setValue(SETTING_BWGRAPH_OPACITY, value); +} + +/** Gets whether the bandwidth graph is always on top when displayed. */ +bool RshareSettings::getBWGraphAlwaysOnTop() +{ + return value(SETTING_BWGRAPH_ALWAYS_ON_TOP, + DEFAULT_BWGRAPH_ALWAYS_ON_TOP).toBool(); +} + +/** Sets whether the bandwidth graph is always on top when displayed. */ +void RshareSettings::setBWGraphAlwaysOnTop(bool alwaysOnTop) +{ + setValue(SETTING_BWGRAPH_ALWAYS_ON_TOP, alwaysOnTop); +} + +/** Returns true if RetroShare's main window should be visible when the + * application starts. */ +bool +RshareSettings::showMainWindowAtStart() +{ + return value(SETTING_SHOW_MAINWINDOW_AT_START).toBool(); +} + +/** Sets whether to show RetroShare's main window when the application starts. */ +void +RshareSettings::setShowMainWindowAtStart(bool show) +{ + setValue(SETTING_SHOW_MAINWINDOW_AT_START, show); +} + +/** Returns true if Vidalia is set to run on system boot. */ +bool +RshareSettings::runRetroshareOnBoot() +{ +#if defined(Q_WS_WIN) + if (!win32_registry_get_key_value(STARTUP_REG_KEY, RETROSHARE_REG_KEY).isEmpty()) { + return true; + } else { + return false; + } +#else + /* Platforms other than windows aren't supported yet */ + return false; +#endif +} + +/** If run is set to true, then Vidalia will run on system boot. */ +void +RshareSettings::setRunRetroshareOnBoot(bool run) +{ +#if defined(Q_WS_WIN) + if (run) { + win32_registry_set_key_value(STARTUP_REG_KEY, RETROSHARE_REG_KEY, + QString("\"" + + QDir::convertSeparators(QCoreApplication::applicationFilePath())) + + "\""); + } else { + win32_registry_remove_key(STARTUP_REG_KEY, RETROSHARE_REG_KEY); + } +#else + /* Platforms othe rthan windows aren't supported yet */ + Q_UNUSED(run); + return; +#endif +} + +/** Saving Generic Widget Size / Location */ + +void RshareSettings::saveWidgetInformation(QWidget *widget) +{ + beginGroup("widgetInformation"); + beginGroup(widget->objectName()); + + setValue("size", widget->size()); + setValue("pos", widget->pos()); + + endGroup(); + endGroup(); +} + +void RshareSettings::saveWidgetInformation(QMainWindow *widget, QToolBar *toolBar) +{ + beginGroup("widgetInformation"); + beginGroup(widget->objectName()); + + setValue("toolBarArea", widget->toolBarArea(toolBar)); + + endGroup(); + endGroup(); + + saveWidgetInformation(widget); +} + +void RshareSettings::loadWidgetInformation(QWidget *widget) +{ + beginGroup("widgetInformation"); + beginGroup(widget->objectName()); + + widget->resize(value("size", widget->size()).toSize()); + widget->move(value("pos", QPoint(200, 200)).toPoint()); + + endGroup(); + endGroup(); +} + +void RshareSettings::loadWidgetInformation(QMainWindow *widget, QToolBar *toolBar) +{ + beginGroup("widgetInformation"); + beginGroup(widget->objectName()); + + widget->addToolBar((Qt::ToolBarArea) value("toolBarArea", Qt::TopToolBarArea).toInt(), + toolBar); + + endGroup(); + endGroup(); + + loadWidgetInformation(widget); +} + diff --git a/retroshare-gui/src/gui/Preferences/rsharesettings.h b/retroshare-gui/src/gui/Preferences/rsharesettings.h new file mode 100644 index 000000000..f88182c11 --- /dev/null +++ b/retroshare-gui/src/gui/Preferences/rsharesettings.h @@ -0,0 +1,120 @@ +/**************************************************************** + * 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 _RSHARESETTINGS_H +#define _RSHARESETTINGS_H + +#include +#include + +#include +#include "rsettings.h" + + +//Forward declaration. +class QWidget; +class QTableWidget; +class QToolBar; +class QMainWindow; + +/** Handles saving and restoring RShares's settings, such as the + * location of Tor, the control port, etc. + * + * NOTE: Qt 4.1 documentation states that constructing a QSettings object is + * "very fast", so we shouldn't need to create a global instance of this + * class. + */ +class RshareSettings : public RSettings +{ + +public: + /** Default constructor. */ + RshareSettings(); + + /** Gets the currently preferred language code for RShare. */ + QString getLanguageCode(); + /** Saves the preferred language code. */ + void setLanguageCode(QString languageCode); + + /** Gets the interface style key (e.g., "windows", "motif", etc.) */ + QString getInterfaceStyle(); + /** Sets the interface style key. */ + void setInterfaceStyle(QString styleKey); + + /** Sets the stylesheet */ + void setSheetName(QString sheet); + /** Gets the stylesheet */ + QString getSheetName(); + + /** Returns true if RetroShare's main window should be visible when the + * application starts. */ + bool showMainWindowAtStart(); + /** Sets whether to show Vidalia's main window when the application starts. */ + void setShowMainWindowAtStart(bool show); + + /** Returns true if RetroShare should start on system boot. */ + bool runRetroshareOnBoot(); + /** Set whether to run RetroShare on system boot. */ + void setRunRetroshareOnBoot(bool run); + + + /* Get the destination log file. */ + QString getLogFile(); + /** Set the destination log file. */ + void setLogFile(QString file); + + /* Get the bandwidth graph line filter. */ + uint getBWGraphFilter(); + /** Set the bandwidth graph line filter. */ + void setBWGraphFilter(uint line, bool status); + + /** Set the bandwidth graph opacity setting. */ + int getBWGraphOpacity(); + /** Set the bandwidth graph opacity settings. */ + void setBWGraphOpacity(int value); + + /** Gets whether the bandwidth graph is always on top. */ + bool getBWGraphAlwaysOnTop(); + /** Sets whether the bandwidth graph is always on top. */ + void setBWGraphAlwaysOnTop(bool alwaysOnTop); + + + //! Save placement, state and size information of a window. + void saveWidgetInformation(QWidget *widget); + + //! Load placement, state and size information of a window. + void loadWidgetInformation(QWidget *widget); + + //! Method overload. Save window and toolbar information. + void saveWidgetInformation(QMainWindow *widget, QToolBar *toolBar); + + //! Method overload. Restore window and toolbar information. + void loadWidgetInformation(QMainWindow *widget, QToolBar *toolBar); + + + +}; + +#endif + diff --git a/retroshare-gui/src/gui/common/rwindow.cpp b/retroshare-gui/src/gui/common/rwindow.cpp index 697d92a10..be298f1e1 100644 --- a/retroshare-gui/src/gui/common/rwindow.cpp +++ b/retroshare-gui/src/gui/common/rwindow.cpp @@ -97,16 +97,14 @@ RWindow::restoreWindowState() QVariant RWindow::getSetting(QString setting, QVariant defaultValue) { - QString key = _name + "/" + setting; - return _settings->value(key, defaultValue); + return _settings->value(setting, defaultValue); } /** Saves a value associated with a property name for this window object. */ void RWindow::saveSetting(QString prop, QVariant value) { - QString key = _name + "/" + prop; - _settings->setValue(key, value); + _settings->setValue(prop, value); } /** Overloaded QWidget::setVisible(). If this window is already visible and diff --git a/retroshare-gui/src/gui/common/rwindow.h b/retroshare-gui/src/gui/common/rwindow.h index 41e4c42c7..1d470b66e 100644 --- a/retroshare-gui/src/gui/common/rwindow.h +++ b/retroshare-gui/src/gui/common/rwindow.h @@ -28,7 +28,7 @@ #include #include #include -#include +#include class RWindow : public QMainWindow diff --git a/retroshare-gui/src/gui/images.qrc b/retroshare-gui/src/gui/images.qrc index 1f81f9dac..763e8dccc 100644 --- a/retroshare-gui/src/gui/images.qrc +++ b/retroshare-gui/src/gui/images.qrc @@ -161,6 +161,7 @@ images/invitefriendlabel.png images/kbackgammon.png images/kblogger.png + images/kcmsystem24.png images/kdmconfig.png images/konsole.png images/konqsidebar_news16.png diff --git a/retroshare-gui/src/gui/images/kcmsystem24.png b/retroshare-gui/src/gui/images/kcmsystem24.png new file mode 100644 index 0000000000000000000000000000000000000000..cedcf7f0f27b29b2ef3bde13660632cee29ee8e0 GIT binary patch literal 1535 zcmVrckVpyZA(Xo=|ft11lrOBD@ zegnV@{|C! zy>qW#z52(pWy`{?t*uKtIyw&b_4OU8sj0Ct`AFu7cJKa@5khaSYk0dT6by#XpFfu> zE`GV-)tVZbP8(p1!{Oj?I2`bJJm~K3wjt%O{+To9l$DkF+Vp*skUj9~chyBHW4gkc!4EDMHVz%)%r3D}km z%QRht5cbp#R8?Jn>h$RYvxVl$Msl{b`T9Wy_YltgNiVmSyFvd24Nn$Kzp^ zHL+Qv zU#4k}o;-PSBMAfo^`}mE9SH>TXzW1@wr#_*Ec|o-KKy<^yk0MU=;{hJHhxedrTk}d zA*$Ni_MUrVq?90pZ~*vX*RFx4rl!JZG>T+01;77A5JF&C7J7PmV5AIi&cGPQ z!t!!B6$OTwMl>1&V+^{kRyb;;}BB7Oj{TqA4f8o#P5B5u%!ec03`&A7B2>+Qg!kMKcQqo2=D6ZN&o=k3~rYjnx?_)^?)&k#g&z)dgT=?SyF|{$|YcwK~+`gx(1ia z1;!X4CC;4bPCT;%Ldb&6n>Tmu+qbW%rKKeji9{aM)zuZwpTEG7Hci-*`rwl`-P_x1 zT)KE+C@(M1_wIWeXMD2tqg#g#9a+7YJrAJralWViqX1ZD?sPiKE?m51218*P z8jZ-aXMai&LJA+l@TYN2v+Inm?9ALSjL`98N3REiK@NZf0)d2-GV&N^+F$(CH~6n0 lgv #include #include -#include "config/rsharesettings.h" +#include "gui/Preferences/rsharesettings.h" #include "rshare.h" diff --git a/retroshare-gui/src/rshare.h b/retroshare-gui/src/rshare.h index 59b0dbc85..71a877347 100644 --- a/retroshare-gui/src/rshare.h +++ b/retroshare-gui/src/rshare.h @@ -34,6 +34,8 @@ #include #include +#include "gui/Preferences/rsharesettings.h" + /** Rshare's version string */ #define RSHARE_VERSION "0.7" diff --git a/retroshare-gui/src/util/win32.cpp b/retroshare-gui/src/util/win32.cpp index f1a3e770d..55af41b1b 100644 --- a/retroshare-gui/src/util/win32.cpp +++ b/retroshare-gui/src/util/win32.cpp @@ -58,6 +58,77 @@ win32_get_folder_location(int folder, QString defaultPath) return defaultPath; } +/** Returns the value in keyName at keyLocation. + * Returns an empty QString if the keyName doesn't exist */ +QString +win32_registry_get_key_value(QString keyLocation, QString keyName) +{ + HKEY key; + char data[255] = {0}; + DWORD size = sizeof(data); + + /* Open the key for reading (opens new key if it doesn't exist) */ + if (RegOpenKeyExA(HKEY_CURRENT_USER, + qPrintable(keyLocation), + 0L, KEY_READ, &key) == ERROR_SUCCESS) { + + /* Key exists, so read the value into data */ + RegQueryValueExA(key, qPrintable(keyName), + NULL, NULL, (LPBYTE)data, &size); + } + + /* Close anything that was opened */ + RegCloseKey(key); + + return QString(data); +} + +/** Creates and/or sets the key to the specified value */ +void +win32_registry_set_key_value(QString keyLocation, QString keyName, QString keyValue) +{ + HKEY key; + + /* Open the key for writing (opens new key if it doesn't exist */ + if (RegOpenKeyExA(HKEY_CURRENT_USER, + qPrintable(keyLocation), + 0, KEY_WRITE, &key) != ERROR_SUCCESS) { + + /* Key didn't exist, so write the newly opened key */ + RegCreateKeyExA(HKEY_CURRENT_USER, + qPrintable(keyLocation), + 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, + &key, NULL); + } + + /* Save the value in the key */ + RegSetValueExA(key, qPrintable(keyName), 0, REG_SZ, + (BYTE *)qPrintable(keyValue), + (DWORD)keyValue.length() + 1); // include null terminator + + /* Close the key */ + RegCloseKey(key); +} + +/** Removes the key from the registry if it exists */ +void +win32_registry_remove_key(QString keyLocation, QString keyName) +{ + HKEY key; + + /* Open the key for writing (opens new key if it doesn't exist */ + if (RegOpenKeyExA(HKEY_CURRENT_USER, + qPrintable(keyLocation), + 0, KEY_SET_VALUE, &key) == ERROR_SUCCESS) { + + /* Key exists so delete it */ + RegDeleteValueA(key, qPrintable(keyName)); + } + + /* Close anything that was opened */ + RegCloseKey(key); +} + /** Gets the location of the user's %PROGRAMFILES% folder. */ QString win32_program_files_folder() diff --git a/retroshare-gui/src/util/win32.h b/retroshare-gui/src/util/win32.h index d03061b06..4196de8ea 100644 --- a/retroshare-gui/src/util/win32.h +++ b/retroshare-gui/src/util/win32.h @@ -24,6 +24,9 @@ #ifndef _WIN32_H #define _WIN32_H +#define WIN32_LEAN_AND_MEAN +#include +#include #include /** Retrieves the location of the user's %PROGRAMFILES% folder. */ @@ -32,5 +35,14 @@ QString win32_program_files_folder(); /** Retrieves the location of the user's %APPDATA% folder. */ QString win32_app_data_folder(); +/** Returns value of keyName or empty QString if keyName doesn't exist */ +QString win32_registry_get_key_value(QString keyLocation, QString keyName); + +/** Creates and/or sets the key to the specified value */ +void win32_registry_set_key_value(QString keyLocation, QString keyName, QString keyValue); + +/** Removes the key from the registry if it exists */ +void win32_registry_remove_key(QString keyLocation, QString keyName); + #endif