2008-08-14 20:23:27 -04:00
|
|
|
/****************************************************************
|
2010-01-27 17:31:25 -05:00
|
|
|
* This file is distributed under the following license:
|
|
|
|
*
|
|
|
|
* Copyright (c) 2006-2007, crypton
|
2008-08-14 20:23:27 -04:00
|
|
|
* 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 <QDir>
|
|
|
|
#include <QCoreApplication>
|
|
|
|
#include <QStyleFactory>
|
2010-11-04 09:09:08 -04:00
|
|
|
#include <QWidget>
|
2008-08-14 20:23:27 -04:00
|
|
|
#include <lang/languagesupport.h>
|
|
|
|
#include <rshare.h>
|
|
|
|
|
|
|
|
#include "rsharesettings.h"
|
2011-02-22 09:51:03 -05:00
|
|
|
#ifdef MINIMAL_RSGUI
|
|
|
|
#include <QMainWindow>
|
|
|
|
#else
|
2010-11-04 09:09:08 -04:00
|
|
|
#include "gui/MainWindow.h"
|
2011-02-22 09:51:03 -05:00
|
|
|
#endif // MINIMAL_RSGUI
|
2008-08-14 20:23:27 -04:00
|
|
|
|
2010-08-06 05:40:23 -04:00
|
|
|
#include <retroshare/rsnotify.h>
|
2011-04-14 17:59:51 -04:00
|
|
|
#include <retroshare/rspeers.h>
|
2008-12-07 09:19:13 -05:00
|
|
|
|
2008-08-14 20:23:27 -04:00
|
|
|
#if defined(Q_WS_WIN)
|
|
|
|
#include <util/win32.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/* Retroshare's Settings */
|
|
|
|
#define SETTING_LANGUAGE "LanguageCode"
|
|
|
|
#define SETTING_STYLE "InterfaceStyle"
|
|
|
|
#define SETTING_SHEETNAME "SheetName"
|
|
|
|
|
|
|
|
#define SETTING_DATA_DIRECTORY "DataDirectory"
|
|
|
|
#define SETTING_BWGRAPH_FILTER "StatisticDialog/BWLineFilter"
|
|
|
|
#define SETTING_BWGRAPH_OPACITY "StatisticDialog/Opacity"
|
|
|
|
#define SETTING_BWGRAPH_ALWAYS_ON_TOP "StatisticDialog/AlwaysOnTop"
|
|
|
|
|
2008-12-07 09:19:13 -05:00
|
|
|
#define SETTING_NEWSFEED_FLAGS "NewsFeedFlags"
|
|
|
|
#define SETTING_CHAT_FLAGS "ChatFlags"
|
|
|
|
#define SETTING_NOTIFY_FLAGS "NotifyFlags"
|
2010-10-07 17:50:15 -04:00
|
|
|
#define SETTING_TRAYNOTIFY_FLAGS "TrayNotifyFlags"
|
2009-03-01 10:18:34 -05:00
|
|
|
#define SETTING_CHAT_AVATAR "ChatAvatar"
|
2008-12-07 09:19:13 -05:00
|
|
|
|
2008-08-14 20:23:27 -04:00
|
|
|
/* 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
|
|
|
|
|
2010-05-20 17:53:27 -04:00
|
|
|
// the one and only global settings object
|
|
|
|
RshareSettings *Settings = NULL;
|
|
|
|
|
|
|
|
/*static*/ void RshareSettings::Create ()
|
|
|
|
{
|
2010-06-14 09:32:13 -04:00
|
|
|
if (Settings && Settings->m_bValid == false) {
|
|
|
|
// recreate with correct path
|
|
|
|
delete (Settings);
|
|
|
|
Settings = NULL;
|
|
|
|
}
|
2010-05-20 17:53:27 -04:00
|
|
|
if (Settings == NULL) {
|
|
|
|
Settings = new RshareSettings ();
|
|
|
|
}
|
2010-01-27 17:31:25 -05:00
|
|
|
}
|
2008-08-14 20:23:27 -04:00
|
|
|
|
|
|
|
/** Default Constructor */
|
2010-06-14 09:32:13 -04:00
|
|
|
RshareSettings::RshareSettings()
|
|
|
|
{
|
2010-07-21 03:39:14 -04:00
|
|
|
m_maxTimeBeforeIdle = -1;
|
|
|
|
|
2010-01-27 17:31:25 -05:00
|
|
|
initSettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RshareSettings::initSettings()
|
2008-08-14 20:23:27 -04:00
|
|
|
{
|
|
|
|
#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");
|
2010-05-29 19:44:23 -04:00
|
|
|
else if (styles.contains("windowsxp", Qt::CaseInsensitive))
|
|
|
|
setDefault(SETTING_STYLE, "windowsxp");
|
2008-08-14 20:23:27 -04:00
|
|
|
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);
|
2008-12-07 09:19:13 -05:00
|
|
|
|
|
|
|
/* defaults here are not ideal.... but dusent matter */
|
|
|
|
|
2010-11-13 16:53:06 -05:00
|
|
|
uint defChat = RS_CHAT_OPEN;
|
2008-12-07 09:19:13 -05:00
|
|
|
// This is not default... RS_CHAT_FOCUS.
|
|
|
|
|
2010-12-07 19:14:12 -05:00
|
|
|
uint defNotify = (RS_POPUP_CONNECT | RS_POPUP_MSG);
|
2008-12-07 09:19:13 -05:00
|
|
|
|
|
|
|
uint defNewsFeed = (RS_FEED_TYPE_PEER | RS_FEED_TYPE_CHAN |
|
|
|
|
RS_FEED_TYPE_FORUM | RS_FEED_TYPE_BLOG |
|
|
|
|
RS_FEED_TYPE_CHAT | RS_FEED_TYPE_MSG |
|
|
|
|
RS_FEED_TYPE_FILES);
|
|
|
|
|
|
|
|
setDefault(SETTING_NEWSFEED_FLAGS, defNewsFeed);
|
|
|
|
setDefault(SETTING_CHAT_FLAGS, defChat);
|
|
|
|
setDefault(SETTING_NOTIFY_FLAGS, defNotify);
|
2010-06-15 12:51:48 -04:00
|
|
|
|
|
|
|
setDefault("DisplayTrayGroupChat", true);
|
2010-09-01 16:54:24 -04:00
|
|
|
setDefault("AddFeedsAtEnd", false);
|
2008-08-14 20:23:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/** 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);
|
|
|
|
}
|
|
|
|
|
2010-12-02 19:54:40 -05:00
|
|
|
static QString getKeyForLastDir(RshareSettings::enumLastDir type)
|
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case RshareSettings::LASTDIR_EXTRAFILE:
|
|
|
|
return "ExtraFile";
|
|
|
|
case RshareSettings::LASTDIR_CERT:
|
|
|
|
return "Certificate";
|
|
|
|
case RshareSettings::LASTDIR_HISTORY:
|
|
|
|
return "History";
|
|
|
|
case RshareSettings::LASTDIR_IMAGES:
|
|
|
|
return "Images";
|
|
|
|
case RshareSettings::LASTDIR_MESSAGES:
|
|
|
|
return "Messages";
|
|
|
|
case RshareSettings::LASTDIR_BLOGS:
|
|
|
|
return "Messages";
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
QString RshareSettings::getLastDir(enumLastDir type)
|
|
|
|
{
|
|
|
|
QString key = getKeyForLastDir(type);
|
|
|
|
if (key.isEmpty()) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
return valueFromGroup("LastDir", key).toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RshareSettings::setLastDir(enumLastDir type, const QString &lastDir)
|
|
|
|
{
|
|
|
|
QString key = getKeyForLastDir(type);
|
|
|
|
if (key.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
setValueToGroup("LastDir", key, lastDir);
|
|
|
|
}
|
|
|
|
|
2008-08-14 20:23:27 -04:00
|
|
|
/** 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. */
|
2010-12-13 15:34:07 -05:00
|
|
|
bool RshareSettings::getStartMinimized()
|
2008-08-14 20:23:27 -04:00
|
|
|
{
|
2010-12-13 15:34:07 -05:00
|
|
|
return value("StartMinimized", false).toBool();
|
2008-08-14 20:23:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Sets whether to show RetroShare's main window when the application starts. */
|
2010-12-13 15:34:07 -05:00
|
|
|
void RshareSettings::setStartMinimized(bool startMinimized)
|
2008-08-14 20:23:27 -04:00
|
|
|
{
|
2010-12-13 15:34:07 -05:00
|
|
|
setValue("StartMinimized", startMinimized);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RshareSettings::getCloseToTray()
|
|
|
|
{
|
|
|
|
return value("ClosetoTray", false).toBool();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RshareSettings::setCloseToTray(bool closeToTray)
|
|
|
|
{
|
|
|
|
setValue("ClosetoTray", closeToTray);
|
2008-08-14 20:23:27 -04:00
|
|
|
}
|
|
|
|
|
2008-12-07 09:19:13 -05:00
|
|
|
/** Setting for Notify / Chat and NewsFeeds **/
|
|
|
|
uint RshareSettings::getNewsFeedFlags()
|
|
|
|
{
|
|
|
|
return value(SETTING_NEWSFEED_FLAGS).toUInt();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RshareSettings::setNewsFeedFlags(uint flags)
|
|
|
|
{
|
|
|
|
setValue(SETTING_NEWSFEED_FLAGS, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint RshareSettings::getChatFlags()
|
|
|
|
{
|
|
|
|
return value(SETTING_CHAT_FLAGS).toUInt();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RshareSettings::setChatFlags(uint flags)
|
|
|
|
{
|
|
|
|
setValue(SETTING_CHAT_FLAGS, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint RshareSettings::getNotifyFlags()
|
|
|
|
{
|
|
|
|
return value(SETTING_NOTIFY_FLAGS).toUInt();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RshareSettings::setNotifyFlags(uint flags)
|
|
|
|
{
|
|
|
|
setValue(SETTING_NOTIFY_FLAGS, flags);
|
|
|
|
}
|
|
|
|
|
2010-10-07 17:50:15 -04:00
|
|
|
uint RshareSettings::getTrayNotifyFlags()
|
|
|
|
{
|
2011-07-13 15:24:33 -04:00
|
|
|
return value(SETTING_TRAYNOTIFY_FLAGS, TRAYNOTIFY_PRIVATECHAT | TRAYNOTIFY_MESSAGES | TRAYNOTIFY_CHANNELS | TRAYNOTIFY_FORUMS | TRAYNOTIFY_TRANSFERS).toUInt();
|
2010-10-07 17:50:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void RshareSettings::setTrayNotifyFlags(uint flags)
|
|
|
|
{
|
|
|
|
setValue(SETTING_TRAYNOTIFY_FLAGS, flags);
|
|
|
|
}
|
|
|
|
|
2010-06-15 12:51:48 -04:00
|
|
|
bool RshareSettings::getDisplayTrayGroupChat()
|
|
|
|
{
|
|
|
|
return value("DisplayTrayGroupChat").toBool();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RshareSettings::setDisplayTrayGroupChat(bool bValue)
|
|
|
|
{
|
|
|
|
setValue("DisplayTrayGroupChat", bValue);
|
|
|
|
}
|
|
|
|
|
2010-09-01 16:54:24 -04:00
|
|
|
bool RshareSettings::getAddFeedsAtEnd()
|
|
|
|
{
|
|
|
|
return value("AddFeedsAtEnd").toBool();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RshareSettings::setAddFeedsAtEnd(bool bValue)
|
|
|
|
{
|
|
|
|
setValue("AddFeedsAtEnd", bValue);
|
|
|
|
}
|
|
|
|
|
2010-09-04 10:23:30 -04:00
|
|
|
bool RshareSettings::getChatSendMessageWithCtrlReturn()
|
|
|
|
{
|
|
|
|
return valueFromGroup("Chat", "SendMessageWithCtrlReturn", false).toBool();
|
|
|
|
}
|
|
|
|
|
2010-12-10 16:49:38 -05:00
|
|
|
RshareSettings::enumToasterPosition RshareSettings::getToasterPosition()
|
|
|
|
{
|
|
|
|
return (enumToasterPosition) value("ToasterPosition", TOASTERPOS_BOTTOMRIGHT).toInt();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RshareSettings::setToasterPosition(enumToasterPosition position)
|
|
|
|
{
|
|
|
|
setValue("ToasterPosition", position);
|
|
|
|
}
|
|
|
|
|
|
|
|
QPoint RshareSettings::getToasterMargin()
|
|
|
|
{
|
|
|
|
return value("ToasterMargin", QPoint(10, 10)).toPoint();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RshareSettings::setToasterMargin(QPoint margin)
|
|
|
|
{
|
|
|
|
setValue("ToasterMargin", margin);
|
|
|
|
}
|
|
|
|
|
2010-09-04 10:23:30 -04:00
|
|
|
void RshareSettings::setChatSendMessageWithCtrlReturn(bool bValue)
|
|
|
|
{
|
|
|
|
setValueToGroup("Chat", "SendMessageWithCtrlReturn", bValue);
|
|
|
|
}
|
|
|
|
|
2010-09-10 14:38:46 -04:00
|
|
|
QString RshareSettings::getChatScreenFont()
|
|
|
|
{
|
|
|
|
return valueFromGroup("Chat", "ChatScreenFont").toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RshareSettings::setChatScreenFont(const QString &font)
|
|
|
|
{
|
|
|
|
setValueToGroup("Chat", "ChatScreenFont", font);
|
|
|
|
}
|
|
|
|
|
2010-09-07 19:19:27 -04:00
|
|
|
void RshareSettings::getPublicChatStyle(QString &stylePath, QString &styleVariant)
|
2010-09-07 11:49:31 -04:00
|
|
|
{
|
|
|
|
stylePath = valueFromGroup("Chat", "StylePublic", ":/qss/chat/public").toString();
|
2010-09-07 19:19:27 -04:00
|
|
|
styleVariant = valueFromGroup("Chat", "StylePublicVariant", "").toString();
|
2010-09-07 11:49:31 -04:00
|
|
|
}
|
|
|
|
|
2010-09-10 14:38:46 -04:00
|
|
|
void RshareSettings::setPublicChatStyle(const QString &stylePath, const QString &styleVariant)
|
2010-09-07 11:49:31 -04:00
|
|
|
{
|
|
|
|
setValueToGroup("Chat", "StylePublic", stylePath);
|
2010-09-07 19:19:27 -04:00
|
|
|
setValueToGroup("Chat", "StylePublicVariant", styleVariant);
|
2010-09-07 11:49:31 -04:00
|
|
|
}
|
|
|
|
|
2010-09-07 19:19:27 -04:00
|
|
|
void RshareSettings::getPrivateChatStyle(QString &stylePath, QString &styleVariant)
|
2010-09-07 11:49:31 -04:00
|
|
|
{
|
|
|
|
stylePath = valueFromGroup("Chat", "StylePrivate", ":/qss/chat/private").toString();
|
2010-09-07 19:19:27 -04:00
|
|
|
styleVariant = valueFromGroup("Chat", "StylePrivateVariant", "").toString();
|
2010-09-07 11:49:31 -04:00
|
|
|
}
|
|
|
|
|
2010-09-10 14:38:46 -04:00
|
|
|
void RshareSettings::setPrivateChatStyle(const QString &stylePath, const QString &styleVariant)
|
2010-09-07 11:49:31 -04:00
|
|
|
{
|
|
|
|
setValueToGroup("Chat", "StylePrivate", stylePath);
|
2010-09-07 19:19:27 -04:00
|
|
|
setValueToGroup("Chat", "StylePrivateVariant", styleVariant);
|
2010-09-07 11:49:31 -04:00
|
|
|
}
|
|
|
|
|
2010-09-07 19:19:27 -04:00
|
|
|
void RshareSettings::getHistoryChatStyle(QString &stylePath, QString &styleVariant)
|
2010-09-07 11:49:31 -04:00
|
|
|
{
|
|
|
|
stylePath = valueFromGroup("Chat", "StyleHistory", ":/qss/chat/history").toString();
|
2010-09-07 19:19:27 -04:00
|
|
|
styleVariant = valueFromGroup("Chat", "StylePrivateVariant", "").toString();
|
2010-09-07 11:49:31 -04:00
|
|
|
}
|
|
|
|
|
2010-09-10 14:38:46 -04:00
|
|
|
void RshareSettings::setHistoryChatStyle(const QString &stylePath, const QString &styleVariant)
|
2010-09-07 11:49:31 -04:00
|
|
|
{
|
|
|
|
setValueToGroup("Chat", "StyleHistory", stylePath);
|
2010-09-07 19:19:27 -04:00
|
|
|
setValueToGroup("Chat", "StylePrivateVariant", styleVariant);
|
2010-09-07 11:49:31 -04:00
|
|
|
}
|
|
|
|
|
2010-11-04 07:14:47 -04:00
|
|
|
int RshareSettings::getPublicChatHistoryCount()
|
|
|
|
{
|
|
|
|
return valueFromGroup("Chat", "PublicChatHistoryCount", 0).toInt();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RshareSettings::setPublicChatHistoryCount(int value)
|
|
|
|
{
|
|
|
|
setValueToGroup("Chat", "PublicChatHistoryCount", value);
|
|
|
|
}
|
|
|
|
|
|
|
|
int RshareSettings::getPrivateChatHistoryCount()
|
|
|
|
{
|
|
|
|
return valueFromGroup("Chat", "PrivateChatHistoryCount", 20).toInt();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RshareSettings::setPrivateChatHistoryCount(int value)
|
|
|
|
{
|
|
|
|
setValueToGroup("Chat", "PrivateChatHistoryCount", value);
|
|
|
|
}
|
|
|
|
|
2010-05-18 14:02:51 -04:00
|
|
|
/** Returns true if RetroShare is set to run on system boot. */
|
2008-08-14 20:23:27 -04:00
|
|
|
bool
|
2010-12-11 17:46:14 -05:00
|
|
|
RshareSettings::runRetroshareOnBoot(bool &minimized)
|
2008-08-14 20:23:27 -04:00
|
|
|
{
|
2010-12-11 17:46:14 -05:00
|
|
|
minimized = false;
|
|
|
|
|
2008-08-14 20:23:27 -04:00
|
|
|
#if defined(Q_WS_WIN)
|
2010-12-11 17:46:14 -05:00
|
|
|
QString value = win32_registry_get_key_value(STARTUP_REG_KEY, RETROSHARE_REG_KEY);
|
|
|
|
|
|
|
|
if (!value.isEmpty()) {
|
|
|
|
/* Simple check for "-m" */
|
|
|
|
minimized = value.contains(" -m");
|
2008-08-14 20:23:27 -04:00
|
|
|
return true;
|
|
|
|
}
|
2010-12-11 17:46:14 -05:00
|
|
|
return false;
|
2008-08-14 20:23:27 -04:00
|
|
|
#else
|
|
|
|
/* Platforms other than windows aren't supported yet */
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-05-18 14:02:51 -04:00
|
|
|
/** If <b>run</b> is set to true, then RetroShare will run on system boot. */
|
2008-08-14 20:23:27 -04:00
|
|
|
void
|
2010-12-11 17:46:14 -05:00
|
|
|
RshareSettings::setRunRetroshareOnBoot(bool run, bool minimized)
|
2008-08-14 20:23:27 -04:00
|
|
|
{
|
|
|
|
#if defined(Q_WS_WIN)
|
|
|
|
if (run) {
|
2010-12-11 17:46:14 -05:00
|
|
|
QString value = "\"" + QDir::convertSeparators(QCoreApplication::applicationFilePath()) + "\"";
|
|
|
|
|
|
|
|
if (minimized) {
|
|
|
|
value += " -m";
|
|
|
|
}
|
|
|
|
|
|
|
|
win32_registry_set_key_value(STARTUP_REG_KEY, RETROSHARE_REG_KEY, value);
|
2008-08-14 20:23:27 -04:00
|
|
|
} else {
|
|
|
|
win32_registry_remove_key(STARTUP_REG_KEY, RETROSHARE_REG_KEY);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
/* Platforms othe rthan windows aren't supported yet */
|
|
|
|
Q_UNUSED(run);
|
2011-04-14 17:59:51 -04:00
|
|
|
Q_UNUSED(minimized);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static QString getAppPathForProtocol()
|
|
|
|
{
|
|
|
|
return "\"" + QDir::convertSeparators(QCoreApplication::applicationFilePath()) + "\" -r \"%1\"";
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Returns true if retroshare:// is registered as protocol */
|
|
|
|
bool RshareSettings::getRetroShareProtocol()
|
|
|
|
{
|
|
|
|
#if defined(Q_WS_WIN)
|
|
|
|
/* Check key */
|
|
|
|
QSettings retroshare("HKEY_CLASSES_ROOT\\retroshare", QSettings::NativeFormat);
|
|
|
|
if (retroshare.contains("Default")) {
|
|
|
|
/* Check profile */
|
|
|
|
if (retroshare.value("Profile").toString().toStdString() == rsPeers->getOwnId()) {
|
|
|
|
/* Check app path */
|
|
|
|
QSettings command("HKEY_CLASSES_ROOT\\retroshare\\shell\\open\\command", QSettings::NativeFormat);
|
|
|
|
if (command.value("Default").toString() == getAppPathForProtocol()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
/* Platforms other than windows aren't supported yet */
|
|
|
|
#endif
|
2011-04-14 19:58:30 -04:00
|
|
|
return false;
|
2011-04-14 17:59:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Register retroshare:// as protocl */
|
|
|
|
void RshareSettings::setRetroShareProtocol(bool value)
|
|
|
|
{
|
|
|
|
#if defined(Q_WS_WIN)
|
|
|
|
if (value) {
|
|
|
|
QSettings retroshare("HKEY_CLASSES_ROOT\\retroshare", QSettings::NativeFormat);
|
|
|
|
retroshare.setValue("Default", "URL: RetroShare protocol");
|
|
|
|
retroshare.setValue("URL Protocol", "");
|
|
|
|
retroshare.setValue("Profile", QString::fromStdString(rsPeers->getOwnId()));
|
|
|
|
|
|
|
|
QSettings command("HKEY_CLASSES_ROOT\\retroshare\\shell\\open\\command", QSettings::NativeFormat);
|
|
|
|
command.setValue("Default", getAppPathForProtocol());
|
|
|
|
} else {
|
|
|
|
QSettings retroshare("HKEY_CLASSES_ROOT", QSettings::NativeFormat);
|
|
|
|
retroshare.remove("retroshare");
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
/* Platforms othe rthan windows aren't supported yet */
|
|
|
|
Q_UNUSED(value);
|
2008-08-14 20:23:27 -04:00
|
|
|
#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);
|
|
|
|
}
|
|
|
|
|
2011-02-22 09:51:03 -05:00
|
|
|
#ifndef MINIMAL_RSGUI
|
2010-11-04 07:14:47 -04:00
|
|
|
/* MainWindow */
|
|
|
|
int RshareSettings::getLastPageInMainWindow ()
|
|
|
|
{
|
2010-11-04 09:09:08 -04:00
|
|
|
return valueFromGroup("MainWindow", "LastPage", MainWindow::Network).toInt();
|
2010-11-04 07:14:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void RshareSettings::setLastPageInMainWindow (int value)
|
|
|
|
{
|
|
|
|
setValueToGroup("MainWindow", "LastPage", value);
|
|
|
|
}
|
|
|
|
|
2011-01-07 11:56:57 -05:00
|
|
|
uint RshareSettings::getStatusBarFlags()
|
|
|
|
{
|
|
|
|
/* Default = All but disc status */
|
|
|
|
return valueFromGroup("MainWindow", "StatusBarFlags", 0xFFFFFFFF ^ STATUSBAR_DISC).toUInt();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RshareSettings::setStatusBarFlags(uint flags)
|
|
|
|
{
|
|
|
|
setValueToGroup("MainWindow", "StatusBarFlags", flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RshareSettings::setStatusBarFlag(uint flag, bool enable)
|
|
|
|
{
|
|
|
|
uint flags = getStatusBarFlags();
|
|
|
|
|
|
|
|
if (enable) {
|
|
|
|
flags |= flag;
|
|
|
|
} else {
|
|
|
|
flags &= ~flag;
|
|
|
|
}
|
|
|
|
|
|
|
|
setStatusBarFlags(flags);
|
|
|
|
}
|
2011-02-22 09:51:03 -05:00
|
|
|
#endif // MINIMAL_RSGUI
|
2011-01-07 11:56:57 -05:00
|
|
|
|
2010-05-23 13:21:30 -04:00
|
|
|
/* Messages */
|
|
|
|
bool RshareSettings::getMsgSetToReadOnActivate ()
|
|
|
|
{
|
|
|
|
return valueFromGroup("MessageDialog", "SetMsgToReadOnActivate", true).toBool();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RshareSettings::setMsgSetToReadOnActivate (bool bValue)
|
|
|
|
{
|
|
|
|
setValueToGroup("MessageDialog", "SetMsgToReadOnActivate", bValue);
|
|
|
|
}
|
2010-07-21 03:39:14 -04:00
|
|
|
|
2011-06-03 20:46:02 -04:00
|
|
|
RshareSettings::enumMsgOpen RshareSettings::getMsgOpen()
|
|
|
|
{
|
|
|
|
enumMsgOpen value = (enumMsgOpen) valueFromGroup("MessageDialog", "msgOpen", MSG_OPEN_TAB).toInt();
|
|
|
|
|
|
|
|
switch (value) {
|
|
|
|
case MSG_OPEN_TAB:
|
|
|
|
case MSG_OPEN_WINDOW:
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
return MSG_OPEN_TAB;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RshareSettings::setMsgOpen(enumMsgOpen value)
|
|
|
|
{
|
|
|
|
switch (value) {
|
|
|
|
case MSG_OPEN_TAB:
|
|
|
|
case MSG_OPEN_WINDOW:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
value = MSG_OPEN_TAB;
|
|
|
|
}
|
|
|
|
|
|
|
|
setValueToGroup("MessageDialog", "msgOpen", value);
|
|
|
|
}
|
|
|
|
|
2010-08-08 18:58:10 -04:00
|
|
|
/* Forums */
|
|
|
|
bool RshareSettings::getForumMsgSetToReadOnActivate ()
|
|
|
|
{
|
|
|
|
return valueFromGroup("ForumDialog", "SetMsgToReadOnActivate", true).toBool();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RshareSettings::setForumMsgSetToReadOnActivate (bool bValue)
|
|
|
|
{
|
|
|
|
setValueToGroup("ForumDialog", "SetMsgToReadOnActivate", bValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RshareSettings::getExpandNewMessages()
|
|
|
|
{
|
|
|
|
return valueFromGroup("ForumDialog", "ExpandNewMessages", true).toBool();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RshareSettings::setExpandNewMessages (bool bValue)
|
|
|
|
{
|
|
|
|
setValueToGroup("ForumDialog", "ExpandNewMessages", bValue);
|
|
|
|
}
|
|
|
|
|
2010-07-21 03:39:14 -04:00
|
|
|
/* time before idle */
|
|
|
|
uint RshareSettings::getMaxTimeBeforeIdle()
|
|
|
|
{
|
|
|
|
if (m_maxTimeBeforeIdle == -1) {
|
|
|
|
m_maxTimeBeforeIdle = valueFromGroup("General", "maxTimeBeforeIdle", 30).toUInt();
|
|
|
|
}
|
|
|
|
|
|
|
|
return m_maxTimeBeforeIdle;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RshareSettings::setMaxTimeBeforeIdle(uint nValue)
|
|
|
|
{
|
|
|
|
m_maxTimeBeforeIdle = nValue;
|
|
|
|
setValueToGroup("General", "maxTimeBeforeIdle", nValue);
|
|
|
|
}
|