2010-09-10 14:38:46 -04:00
|
|
|
/****************************************************************
|
|
|
|
* This file is distributed under the following license:
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 - 2010, RetroShare Team
|
|
|
|
*
|
|
|
|
* 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 <QColor>
|
|
|
|
#include <QFont>
|
|
|
|
#include <QDateTime>
|
2010-11-15 15:49:24 -05:00
|
|
|
#include <QWidget>
|
2010-09-10 14:38:46 -04:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <list>
|
|
|
|
|
|
|
|
#include <retroshare/rsinit.h>
|
|
|
|
#include <retroshare/rspeers.h>
|
|
|
|
|
|
|
|
#include "RsharePeerSettings.h"
|
2012-02-11 16:41:41 -05:00
|
|
|
#include "rsharesettings.h"
|
2011-04-09 18:52:52 -04:00
|
|
|
#include "gui/style/RSStyle.h"
|
2010-09-10 14:38:46 -04:00
|
|
|
|
|
|
|
/** The file in which all settings of he peers will read and written. */
|
2014-01-17 21:35:06 -05:00
|
|
|
#define SETTINGS_FILE (QString::fromUtf8(RsAccounts::ConfigDirectory().c_str()) + "/RSPeers.conf")
|
2010-09-10 14:38:46 -04:00
|
|
|
|
2012-01-17 15:36:36 -05:00
|
|
|
/* clean dead id's after these days */
|
2010-09-10 14:38:46 -04:00
|
|
|
#define DAYS_TO_CLEAN 7
|
|
|
|
|
|
|
|
/* Group for general data */
|
|
|
|
#define GROUP_GENERAL "Default"
|
|
|
|
|
|
|
|
/* the one and only global settings object */
|
|
|
|
RsharePeerSettings *PeerSettings = NULL;
|
|
|
|
|
|
|
|
/*static*/ void RsharePeerSettings::Create ()
|
|
|
|
{
|
|
|
|
if (PeerSettings == NULL) {
|
|
|
|
PeerSettings = new RsharePeerSettings();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Default Constructor */
|
|
|
|
RsharePeerSettings::RsharePeerSettings()
|
2011-10-12 19:36:25 -04:00
|
|
|
: QSettings(SETTINGS_FILE, QSettings::IniFormat)
|
2010-09-10 14:38:46 -04:00
|
|
|
{
|
2012-01-17 15:36:36 -05:00
|
|
|
cleanDeadIds();
|
2010-09-10 14:38:46 -04:00
|
|
|
}
|
|
|
|
|
2012-01-17 15:36:36 -05:00
|
|
|
void RsharePeerSettings::cleanDeadIds()
|
2010-09-10 14:38:46 -04:00
|
|
|
{
|
|
|
|
beginGroup(GROUP_GENERAL);
|
|
|
|
QDateTime lastClean = value("lastClean").toDateTime();
|
|
|
|
endGroup();
|
|
|
|
|
|
|
|
QDateTime currentDate = QDateTime::currentDateTime();
|
|
|
|
|
|
|
|
if (lastClean.addDays(DAYS_TO_CLEAN) < currentDate) {
|
|
|
|
/* clean */
|
|
|
|
QStringList groups = childGroups();
|
2014-10-21 18:33:02 -04:00
|
|
|
for (QStringList::iterator group = groups.begin(); group != groups.end(); ++group) {
|
2010-09-10 14:38:46 -04:00
|
|
|
if (*group == GROUP_GENERAL) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-12-29 16:41:05 -05:00
|
|
|
// TODO: implement cleanup for chatlobbies and distant chat
|
|
|
|
|
|
|
|
ChatId chatId((*group).toStdString());
|
|
|
|
// remove if not a chat id and pgp id was removed from friendslist
|
|
|
|
if(chatId.isNotSet() && rsPeers->isGPGAccepted(RsPgpId((*group).toStdString())) == false) {
|
2010-09-10 14:38:46 -04:00
|
|
|
remove(*group);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
beginGroup(GROUP_GENERAL);
|
|
|
|
setValue("lastClean", currentDate);
|
|
|
|
endGroup();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-29 16:41:05 -05:00
|
|
|
bool RsharePeerSettings::getSettingsIdOfPeerId(const ChatId& chatId, std::string &settingsId)
|
2010-09-10 14:38:46 -04:00
|
|
|
{
|
2014-12-29 16:41:05 -05:00
|
|
|
if(chatId.isPeerId())
|
|
|
|
{
|
|
|
|
RsPeerId peerId = chatId.toPeerId();
|
|
|
|
// for ssl id, get pgp id
|
|
|
|
// check if pgp id is cached
|
|
|
|
std::map<RsPeerId, std::string>::iterator it = m_SslToGpg.find(peerId);
|
|
|
|
if (it != m_SslToGpg.end()) {
|
|
|
|
settingsId = it->second;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// if not fetch and store it
|
|
|
|
RsPeerDetails details;
|
|
|
|
if (rsPeers->getPeerDetails(peerId, details) == false) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
settingsId = details.gpg_id.toStdString();
|
|
|
|
m_SslToGpg[peerId] = settingsId ;
|
2012-01-17 15:36:36 -05:00
|
|
|
return true;
|
|
|
|
}
|
2014-12-29 16:41:05 -05:00
|
|
|
if(chatId.isGxsId() || chatId.isLobbyId() || chatId.isBroadcast())
|
|
|
|
{
|
|
|
|
settingsId = chatId.toStdString();
|
2010-09-10 14:38:46 -04:00
|
|
|
return true;
|
|
|
|
}
|
2014-12-29 16:41:05 -05:00
|
|
|
return false;
|
2010-09-10 14:38:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* get value of peer */
|
2014-12-29 16:41:05 -05:00
|
|
|
QVariant RsharePeerSettings::get(const ChatId& chatId, const QString &key, const QVariant &defaultValue)
|
2010-09-10 14:38:46 -04:00
|
|
|
{
|
|
|
|
QVariant result;
|
|
|
|
|
2012-01-17 15:36:36 -05:00
|
|
|
std::string settingsId;
|
2014-12-29 16:41:05 -05:00
|
|
|
if (getSettingsIdOfPeerId(chatId, settingsId) == false) {
|
2012-01-17 15:36:36 -05:00
|
|
|
/* settings id not found */
|
2010-09-10 14:38:46 -04:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2012-01-17 15:36:36 -05:00
|
|
|
beginGroup(QString::fromStdString(settingsId));
|
2010-09-10 14:38:46 -04:00
|
|
|
result = value(key, defaultValue);
|
|
|
|
endGroup();
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set value of peer */
|
2014-12-29 16:41:05 -05:00
|
|
|
void RsharePeerSettings::set(const ChatId& chatId, const QString &key, const QVariant &value)
|
2010-09-10 14:38:46 -04:00
|
|
|
{
|
2012-01-17 15:36:36 -05:00
|
|
|
std::string settingsId;
|
2014-12-29 16:41:05 -05:00
|
|
|
if (getSettingsIdOfPeerId(chatId, settingsId) == false) {
|
2012-01-17 15:36:36 -05:00
|
|
|
/* settings id not found */
|
2010-09-10 14:38:46 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-01-17 15:36:36 -05:00
|
|
|
beginGroup(QString::fromStdString(settingsId));
|
2012-02-11 16:41:41 -05:00
|
|
|
if (value.isNull()) {
|
|
|
|
remove(key);
|
|
|
|
} else {
|
|
|
|
setValue(key, value);
|
|
|
|
}
|
2010-09-10 14:38:46 -04:00
|
|
|
endGroup();
|
|
|
|
}
|
|
|
|
|
2014-12-29 16:41:05 -05:00
|
|
|
QString RsharePeerSettings::getPrivateChatColor(const ChatId& chatId)
|
2010-09-10 14:38:46 -04:00
|
|
|
{
|
2014-12-29 16:41:05 -05:00
|
|
|
return get(chatId, "PrivateChatColor", QColor(Qt::black).name()).toString();
|
2010-09-10 14:38:46 -04:00
|
|
|
}
|
|
|
|
|
2014-12-29 16:41:05 -05:00
|
|
|
void RsharePeerSettings::setPrivateChatColor(const ChatId& chatId, const QString &value)
|
2010-09-10 14:38:46 -04:00
|
|
|
{
|
2014-12-29 16:41:05 -05:00
|
|
|
set(chatId, "PrivateChatColor", value);
|
2010-09-10 14:38:46 -04:00
|
|
|
}
|
|
|
|
|
2014-12-29 16:41:05 -05:00
|
|
|
QString RsharePeerSettings::getPrivateChatFont(const ChatId& chatId)
|
2010-09-10 14:38:46 -04:00
|
|
|
{
|
2014-12-29 16:41:05 -05:00
|
|
|
return get(chatId, "PrivateChatFont", Settings->getChatScreenFont()).toString();
|
2010-09-10 14:38:46 -04:00
|
|
|
}
|
|
|
|
|
2014-12-29 16:41:05 -05:00
|
|
|
void RsharePeerSettings::setPrivateChatFont(const ChatId& chatId, const QString &value)
|
2010-09-10 14:38:46 -04:00
|
|
|
{
|
2012-02-11 16:41:41 -05:00
|
|
|
if (Settings->getChatScreenFont() == value) {
|
2014-12-29 16:41:05 -05:00
|
|
|
set(chatId, "PrivateChatFont", QVariant());
|
2012-02-11 16:41:41 -05:00
|
|
|
} else {
|
2014-12-29 16:41:05 -05:00
|
|
|
set(chatId, "PrivateChatFont", value);
|
2012-02-11 16:41:41 -05:00
|
|
|
}
|
2010-09-10 14:38:46 -04:00
|
|
|
}
|
2010-11-15 15:49:24 -05:00
|
|
|
|
2014-12-29 16:41:05 -05:00
|
|
|
bool RsharePeerSettings::getPrivateChatOnTop(const ChatId& chatId)
|
2011-07-08 18:33:26 -04:00
|
|
|
{
|
2014-12-29 16:41:05 -05:00
|
|
|
return get(chatId, "PrivateChatOnTop", false).toBool();
|
2011-07-08 18:33:26 -04:00
|
|
|
}
|
|
|
|
|
2014-12-29 16:41:05 -05:00
|
|
|
void RsharePeerSettings::setPrivateChatOnTop(const ChatId& chatId, bool value)
|
2011-07-08 18:33:26 -04:00
|
|
|
{
|
2014-12-29 16:41:05 -05:00
|
|
|
set(chatId, "PrivateChatOnTop", value);
|
2011-07-08 18:33:26 -04:00
|
|
|
}
|
|
|
|
|
2014-12-29 16:41:05 -05:00
|
|
|
void RsharePeerSettings::saveWidgetInformation(const ChatId& chatId, QWidget *widget)
|
2010-11-15 15:49:24 -05:00
|
|
|
{
|
2012-01-17 15:36:36 -05:00
|
|
|
std::string settingsId;
|
2014-12-29 16:41:05 -05:00
|
|
|
if (getSettingsIdOfPeerId(chatId, settingsId) == false) {
|
2012-01-17 15:36:36 -05:00
|
|
|
/* settings id not found */
|
2010-11-15 15:49:24 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-01-17 15:36:36 -05:00
|
|
|
beginGroup(QString::fromStdString(settingsId));
|
2010-11-15 15:49:24 -05:00
|
|
|
beginGroup("widgetInformation");
|
|
|
|
beginGroup(widget->objectName());
|
|
|
|
|
|
|
|
setValue("size", widget->size());
|
|
|
|
setValue("pos", widget->pos());
|
|
|
|
|
|
|
|
endGroup();
|
|
|
|
endGroup();
|
|
|
|
endGroup();
|
|
|
|
}
|
|
|
|
|
2014-12-29 16:41:05 -05:00
|
|
|
void RsharePeerSettings::loadWidgetInformation(const ChatId& chatId, QWidget *widget)
|
2010-11-15 15:49:24 -05:00
|
|
|
{
|
2012-01-17 15:36:36 -05:00
|
|
|
std::string settingsId;
|
2014-12-29 16:41:05 -05:00
|
|
|
if (getSettingsIdOfPeerId(chatId, settingsId) == false) {
|
2012-01-17 15:36:36 -05:00
|
|
|
/* settings id not found */
|
2010-11-15 15:49:24 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-01-17 15:36:36 -05:00
|
|
|
beginGroup(QString::fromStdString(settingsId));
|
2010-11-15 15:49:24 -05:00
|
|
|
beginGroup("widgetInformation");
|
|
|
|
beginGroup(widget->objectName());
|
|
|
|
|
|
|
|
widget->resize(value("size", widget->size()).toSize());
|
|
|
|
widget->move(value("pos", QPoint(200, 200)).toPoint());
|
|
|
|
|
|
|
|
endGroup();
|
|
|
|
endGroup();
|
|
|
|
endGroup();
|
|
|
|
}
|
2011-03-26 19:19:28 -04:00
|
|
|
|
2014-12-29 16:41:05 -05:00
|
|
|
bool RsharePeerSettings::getShowAvatarFrame(const ChatId& chatId)
|
2011-03-26 19:19:28 -04:00
|
|
|
{
|
2014-12-29 16:41:05 -05:00
|
|
|
return get(chatId, "ShowAvatarFrame", true).toBool();
|
2011-03-26 19:19:28 -04:00
|
|
|
}
|
|
|
|
|
2014-12-29 16:41:05 -05:00
|
|
|
void RsharePeerSettings::setShowAvatarFrame(const ChatId& chatId, bool value)
|
2011-03-26 19:19:28 -04:00
|
|
|
{
|
2014-12-29 16:41:05 -05:00
|
|
|
return set(chatId, "ShowAvatarFrame", value);
|
2011-03-26 19:19:28 -04:00
|
|
|
}
|
2011-04-09 18:52:52 -04:00
|
|
|
|
2014-12-29 16:41:05 -05:00
|
|
|
bool RsharePeerSettings::getShowParticipantsFrame(const ChatId& chatId)
|
2012-01-17 15:36:36 -05:00
|
|
|
{
|
2014-12-29 16:41:05 -05:00
|
|
|
return get(chatId, "ShowParticipantsFrame", true).toBool();
|
2012-01-17 15:36:36 -05:00
|
|
|
}
|
|
|
|
|
2014-12-29 16:41:05 -05:00
|
|
|
void RsharePeerSettings::setShowParticipantsFrame(const ChatId& chatId, bool value)
|
2012-01-17 15:36:36 -05:00
|
|
|
{
|
2014-12-29 16:41:05 -05:00
|
|
|
return set(chatId, "ShowParticipantsFrame", value);
|
2012-01-17 15:36:36 -05:00
|
|
|
}
|
|
|
|
|
2014-12-29 16:41:05 -05:00
|
|
|
void RsharePeerSettings::getStyle(const ChatId& chatId, const QString &name, RSStyle &style)
|
2011-04-09 18:52:52 -04:00
|
|
|
{
|
2012-01-17 15:36:36 -05:00
|
|
|
std::string settingsId;
|
2014-12-29 16:41:05 -05:00
|
|
|
if (getSettingsIdOfPeerId(chatId, settingsId) == false) {
|
2012-01-17 15:36:36 -05:00
|
|
|
/* settings id not found */
|
2011-04-09 18:52:52 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-01-17 15:36:36 -05:00
|
|
|
beginGroup(QString::fromStdString(settingsId));
|
2011-04-09 18:52:52 -04:00
|
|
|
beginGroup("style");
|
|
|
|
beginGroup(name);
|
|
|
|
|
|
|
|
style.readSetting(*this);
|
|
|
|
|
|
|
|
endGroup();
|
|
|
|
endGroup();
|
|
|
|
endGroup();
|
|
|
|
}
|
|
|
|
|
2014-12-29 16:41:05 -05:00
|
|
|
void RsharePeerSettings::setStyle(const ChatId& chatId, const QString &name, RSStyle &style)
|
2011-04-09 18:52:52 -04:00
|
|
|
{
|
2012-01-17 15:36:36 -05:00
|
|
|
std::string settingsId;
|
2014-12-29 16:41:05 -05:00
|
|
|
if (getSettingsIdOfPeerId(chatId, settingsId) == false) {
|
2012-01-17 15:36:36 -05:00
|
|
|
/* settings id not found */
|
2011-04-09 18:52:52 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-01-17 15:36:36 -05:00
|
|
|
beginGroup(QString::fromStdString(settingsId));
|
2011-04-09 18:52:52 -04:00
|
|
|
beginGroup("style");
|
|
|
|
beginGroup(name);
|
|
|
|
|
|
|
|
style.writeSetting(*this);
|
|
|
|
|
|
|
|
endGroup();
|
|
|
|
endGroup();
|
|
|
|
endGroup();
|
|
|
|
}
|