mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
Fixed choose of the font in PopupChatDialog with the font dialog.
New class RsharePeerSettings and a global variable PeerSettings for read and write settings of a peer (gpg id). Save font and color in PopupChatDialog. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3464 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
7c126f24ba
commit
cbdb717e51
@ -250,6 +250,7 @@ HEADERS += rshare.h \
|
||||
gui/msgs/textformat.h \
|
||||
gui/images/retroshare_win.rc.h \
|
||||
gui/settings/rsharesettings.h \
|
||||
gui/settings/RsharePeerSettings.h \
|
||||
gui/settings/rsettings.h \
|
||||
gui/settings/rsettingswin.h \
|
||||
gui/settings/GeneralPage.h \
|
||||
@ -467,6 +468,7 @@ SOURCES += main.cpp \
|
||||
gui/common/rwindow.cpp \
|
||||
gui/common/html.cpp \
|
||||
gui/settings/rsharesettings.cpp \
|
||||
gui/settings/RsharePeerSettings.cpp \
|
||||
gui/settings/rsettings.cpp \
|
||||
gui/settings/rsettingswin.cpp \
|
||||
gui/settings/GeneralPage.cpp \
|
||||
|
@ -199,7 +199,7 @@ PeersDialog::PeersDialog(QWidget *parent)
|
||||
pxm.fill(_currentColor);
|
||||
ui.colorChatButton->setIcon(pxm);
|
||||
|
||||
mCurrentFont.fromString(Settings->valueFromGroup("Chat", QString::fromUtf8("ChatScreenFont")).toString());
|
||||
mCurrentFont.fromString(Settings->getChatScreenFont());
|
||||
ui.lineEdit->setFont(mCurrentFont);
|
||||
|
||||
style.setStyleFromSettings(ChatStyle::TYPE_PUBLIC);
|
||||
@ -1389,10 +1389,7 @@ void PeersDialog::setFont()
|
||||
mCurrentFont.setItalic(ui.textitalicChatButton->isChecked());
|
||||
ui.lineEdit->setFont(mCurrentFont);
|
||||
ui.lineEdit->setTextColor(_currentColor);
|
||||
Settings->beginGroup("Chat");
|
||||
Settings->setValue(QString::fromUtf8("ChatScreenFont"), mCurrentFont.toString());
|
||||
Settings->endGroup();
|
||||
|
||||
Settings->setChatScreenFont(mCurrentFont.toString());
|
||||
|
||||
ui.lineEdit->setFocus();
|
||||
|
||||
|
@ -64,7 +64,7 @@ void ChatStyle::styleChanged(int styleType)
|
||||
}
|
||||
}
|
||||
|
||||
bool ChatStyle::setStylePath(QString stylePath, QString styleVariant)
|
||||
bool ChatStyle::setStylePath(const QString &stylePath, const QString &styleVariant)
|
||||
{
|
||||
m_styleType = TYPE_UNKNOWN;
|
||||
|
||||
@ -572,7 +572,7 @@ static QString getBaseDir()
|
||||
return true;
|
||||
}
|
||||
|
||||
/*static*/ bool ChatStyle::getAvailableVariants(QString stylePath, QStringList &variants)
|
||||
/*static*/ bool ChatStyle::getAvailableVariants(const QString &stylePath, QStringList &variants)
|
||||
{
|
||||
variants.clear();
|
||||
|
||||
|
@ -82,7 +82,7 @@ public:
|
||||
/* Default destructor */
|
||||
~ChatStyle();
|
||||
|
||||
bool setStylePath(QString stylePath, QString styleVariant);
|
||||
bool setStylePath(const QString &stylePath, const QString &styleVariant);
|
||||
bool setStyleFromSettings(enumStyleType styleType);
|
||||
void loadEmoticons();
|
||||
|
||||
@ -91,7 +91,7 @@ public:
|
||||
|
||||
void showSmileyWidget(QWidget *parent, QWidget *button, const char *slotAddMethod);
|
||||
static bool getAvailableStyles(enumStyleType styleType, QList<ChatStyleInfo> &styles);
|
||||
static bool getAvailableVariants(QString stylePath, QStringList &variants);
|
||||
static bool getAvailableVariants(const QString &stylePath, QStringList &variants);
|
||||
|
||||
private slots:
|
||||
void styleChanged(int styleType);
|
||||
|
@ -45,6 +45,7 @@
|
||||
#include <retroshare/rsstatus.h>
|
||||
#include <retroshare/rsiface.h>
|
||||
#include "gui/settings/rsharesettings.h"
|
||||
#include "gui/settings/RsharePeerSettings.h"
|
||||
#include "gui/notifyqt.h"
|
||||
#include "../RsAutoUpdatePage.h"
|
||||
|
||||
@ -173,11 +174,11 @@ PopupChatDialog::PopupChatDialog(std::string id, std::string name,
|
||||
//toolmenu->addAction(ui.action_Disable_Emoticons);
|
||||
ui.pushtoolsButton->setMenu(toolmenu);
|
||||
|
||||
mCurrentColor = Qt::black;
|
||||
mCurrentFont = QFont("Comic Sans MS", 10);
|
||||
mCurrentColor.setNamedColor(PeerSettings->getPrivateChatColor(dialogId));
|
||||
mCurrentFont.fromString(PeerSettings->getPrivateChatFont(dialogId));
|
||||
|
||||
colorChanged(mCurrentColor);
|
||||
setFont();
|
||||
fontChanged(mCurrentFont);
|
||||
|
||||
pasteLinkAct = new QAction(QIcon(":/images/pasterslink.png"), tr( "Paste retroshare Link" ), this );
|
||||
connect( pasteLinkAct , SIGNAL( triggered() ), this, SLOT( pasteLink() ) );
|
||||
@ -671,6 +672,7 @@ void PopupChatDialog::setColor()
|
||||
QRgb color = QColorDialog::getRgba(ui.chattextEdit->textColor().rgba(), &ok, this);
|
||||
if (ok) {
|
||||
mCurrentColor = QColor(color);
|
||||
PeerSettings->setPrivateChatColor(dialogId, mCurrentColor.name());
|
||||
colorChanged(mCurrentColor);
|
||||
}
|
||||
setFont();
|
||||
@ -686,17 +688,26 @@ void PopupChatDialog::colorChanged(const QColor &c)
|
||||
void PopupChatDialog::getFont()
|
||||
{
|
||||
bool ok;
|
||||
mCurrentFont = QFontDialog::getFont(&ok, mCurrentFont, this);
|
||||
QFont font = QFontDialog::getFont(&ok, mCurrentFont, this);
|
||||
if (ok) {
|
||||
fontChanged(font);
|
||||
}
|
||||
}
|
||||
|
||||
void PopupChatDialog::fontChanged(const QFont &font)
|
||||
{
|
||||
mCurrentFont = font;
|
||||
|
||||
ui.textboldButton->setChecked(mCurrentFont.bold());
|
||||
ui.textunderlineButton->setChecked(mCurrentFont.underline());
|
||||
ui.textitalicButton->setChecked(mCurrentFont.italic());
|
||||
|
||||
setFont();
|
||||
}
|
||||
|
||||
void PopupChatDialog::setFont()
|
||||
{
|
||||
|
||||
// mCurrentFont.setBold(ui.textboldButton->isChecked());
|
||||
bool flag;
|
||||
flag=ui.textboldButton->isChecked();
|
||||
mCurrentFont.setBold(flag);
|
||||
mCurrentFont.setBold(ui.textboldButton->isChecked());
|
||||
mCurrentFont.setUnderline(ui.textunderlineButton->isChecked());
|
||||
mCurrentFont.setItalic(ui.textitalicButton->isChecked());
|
||||
|
||||
@ -705,6 +716,7 @@ void PopupChatDialog::setFont()
|
||||
|
||||
ui.chattextEdit->setFocus();
|
||||
|
||||
PeerSettings->setPrivateChatFont(dialogId, mCurrentFont.toString());
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
|
@ -115,6 +115,7 @@ private slots:
|
||||
private:
|
||||
|
||||
void colorChanged(const QColor &c);
|
||||
void fontChanged(const QFont &font);
|
||||
void addAttachment(std::string,int flag);
|
||||
void processSettings(bool bLoad);
|
||||
|
||||
|
@ -106,10 +106,10 @@ ChatPage::save(QString &errmsg)
|
||||
Settings->setValue(QString::fromUtf8("Emoteicons_PrivatChat"), emotePrivatChat());
|
||||
Settings->setValue(QString::fromUtf8("Emoteicons_GroupChat"), emoteGroupChat());
|
||||
Settings->setValue(QString::fromUtf8("GroupChat_History"), groupchatHistory());
|
||||
Settings->setValue(QString::fromUtf8("ChatScreenFont"), fontTempChat.toString());
|
||||
|
||||
Settings->endGroup();
|
||||
|
||||
Settings->setChatScreenFont(fontTempChat.toString());
|
||||
|
||||
Settings->setChatSendMessageWithCtrlReturn(ui.sendMessageWithCtrlReturn->isChecked());
|
||||
|
||||
ChatStyleInfo info;
|
||||
@ -153,10 +153,10 @@ ChatPage::load()
|
||||
ui.checkBox_emotegroupchat->setChecked(Settings->value(QString::fromUtf8("Emoteicons_GroupChat"), true).toBool());
|
||||
ui.checkBox_groupchathistory->setChecked(Settings->value(QString::fromUtf8("GroupChat_History"), true).toBool());
|
||||
|
||||
fontTempChat.fromString(Settings->value(QString::fromUtf8("ChatScreenFont")).toString());
|
||||
|
||||
Settings->endGroup();
|
||||
|
||||
fontTempChat.fromString(Settings->getChatScreenFont());
|
||||
|
||||
ui.sendMessageWithCtrlReturn->setChecked(Settings->getChatSendMessageWithCtrlReturn());
|
||||
|
||||
ui.labelChatFontPreview->setText(fontTempChat.rawName());
|
||||
|
157
retroshare-gui/src/gui/settings/RsharePeerSettings.cpp
Normal file
157
retroshare-gui/src/gui/settings/RsharePeerSettings.cpp
Normal file
@ -0,0 +1,157 @@
|
||||
/****************************************************************
|
||||
* 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>
|
||||
|
||||
#include <string>
|
||||
#include <list>
|
||||
|
||||
#include <retroshare/rsinit.h>
|
||||
#include <retroshare/rspeers.h>
|
||||
|
||||
#include "RsharePeerSettings.h"
|
||||
|
||||
/** The file in which all settings of he peers will read and written. */
|
||||
#define SETTINGS_FILE (RsInit::RsProfileConfigDirectory() + "/RSPeers.conf")
|
||||
|
||||
/* clean dead gpg id's after these days */
|
||||
#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()
|
||||
: QSettings(QString::fromStdString(SETTINGS_FILE), QSettings::IniFormat)
|
||||
{
|
||||
cleanDeadGpgIds();
|
||||
}
|
||||
|
||||
void RsharePeerSettings::cleanDeadGpgIds()
|
||||
{
|
||||
beginGroup(GROUP_GENERAL);
|
||||
QDateTime lastClean = value("lastClean").toDateTime();
|
||||
endGroup();
|
||||
|
||||
QDateTime currentDate = QDateTime::currentDateTime();
|
||||
|
||||
if (lastClean.addDays(DAYS_TO_CLEAN) < currentDate) {
|
||||
/* clean */
|
||||
QStringList groups = childGroups();
|
||||
for (QStringList::iterator group = groups.begin(); group != groups.end(); group++) {
|
||||
if (*group == GROUP_GENERAL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (rsPeers->isGPGAccepted((*group).toStdString()) == false) {
|
||||
remove(*group);
|
||||
}
|
||||
}
|
||||
|
||||
beginGroup(GROUP_GENERAL);
|
||||
setValue("lastClean", currentDate);
|
||||
endGroup();
|
||||
}
|
||||
}
|
||||
|
||||
bool RsharePeerSettings::getGpgIdOfSslId(const std::string &sslId, std::string &gpgId)
|
||||
|
||||
{
|
||||
std::map<std::string, std::string>::iterator it = m_SslToGpg.find(sslId);
|
||||
if (it != m_SslToGpg.end()) {
|
||||
gpgId = it->second;
|
||||
return true;
|
||||
}
|
||||
|
||||
RsPeerDetails details;
|
||||
if (rsPeers->getPeerDetails(sslId, details) == false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
gpgId = details.gpg_id;
|
||||
m_SslToGpg[sslId] = gpgId;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/* get value of peer */
|
||||
QVariant RsharePeerSettings::get(const std::string &peerId, const QString &key, const QVariant &defaultValue)
|
||||
{
|
||||
QVariant result;
|
||||
|
||||
std::string gpgId;
|
||||
if (getGpgIdOfSslId(peerId, gpgId) == false) {
|
||||
/* gpg id not found */
|
||||
return result;
|
||||
}
|
||||
|
||||
beginGroup(QString::fromStdString(gpgId));
|
||||
result = value(key, defaultValue);
|
||||
endGroup();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/* set value of peer */
|
||||
void RsharePeerSettings::set(const std::string &peerId, const QString &key, const QVariant &value)
|
||||
{
|
||||
std::string gpgId;
|
||||
if (getGpgIdOfSslId(peerId, gpgId) == false) {
|
||||
/* gpg id not found */
|
||||
return;
|
||||
}
|
||||
|
||||
beginGroup(QString::fromStdString(gpgId));
|
||||
setValue(key, value);
|
||||
endGroup();
|
||||
}
|
||||
|
||||
QString RsharePeerSettings::getPrivateChatColor(const std::string &peerId)
|
||||
{
|
||||
return get(peerId, "PrivateChatColor", QColor(Qt::black).name()).toString();
|
||||
}
|
||||
|
||||
void RsharePeerSettings::setPrivateChatColor(const std::string &peerId, const QString &value)
|
||||
{
|
||||
set(peerId, "PrivateChatColor", value);
|
||||
}
|
||||
|
||||
QString RsharePeerSettings::getPrivateChatFont(const std::string &peerId)
|
||||
{
|
||||
return get(peerId, "PrivateChatFont", QFont("Comic Sans MS", 10).toString()).toString();
|
||||
}
|
||||
|
||||
void RsharePeerSettings::setPrivateChatFont(const std::string &peerId, const QString &value)
|
||||
{
|
||||
set(peerId, "PrivateChatFont", value);
|
||||
}
|
59
retroshare-gui/src/gui/settings/RsharePeerSettings.h
Normal file
59
retroshare-gui/src/gui/settings/RsharePeerSettings.h
Normal file
@ -0,0 +1,59 @@
|
||||
/****************************************************************
|
||||
* 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.
|
||||
****************************************************************/
|
||||
|
||||
#ifndef _RSHAREPEERSETTINGS_H
|
||||
#define _RSHAREPEERSETTINGS_H
|
||||
|
||||
#include <QSettings>
|
||||
|
||||
/** Handles saving and restoring RShares's settings for peers */
|
||||
class RsharePeerSettings : public QSettings
|
||||
{
|
||||
public:
|
||||
/* create settings object */
|
||||
static void Create ();
|
||||
|
||||
QString getPrivateChatColor(const std::string &peerId);
|
||||
void setPrivateChatColor(const std::string &peerId, const QString &value);
|
||||
|
||||
QString getPrivateChatFont(const std::string &peerId);
|
||||
void setPrivateChatFont(const std::string &peerId, const QString &value);
|
||||
|
||||
protected:
|
||||
/** Default constructor. */
|
||||
RsharePeerSettings();
|
||||
|
||||
bool getGpgIdOfSslId(const std::string &sslId, std::string &gpgId);
|
||||
void cleanDeadGpgIds();
|
||||
|
||||
/* get value of peer */
|
||||
QVariant get(const std::string &peerId, const QString &key, const QVariant &defaultValue = QVariant());
|
||||
/* set value of peer */
|
||||
void set(const std::string &peerId, const QString &key, const QVariant &value);
|
||||
|
||||
/* map for fast access of the gpg id to the ssl id */
|
||||
std::map<std::string, std::string> m_SslToGpg;
|
||||
};
|
||||
|
||||
// the one and only global settings object
|
||||
extern RsharePeerSettings *PeerSettings;
|
||||
|
||||
#endif
|
@ -299,13 +299,23 @@ void RshareSettings::setChatSendMessageWithCtrlReturn(bool bValue)
|
||||
setValueToGroup("Chat", "SendMessageWithCtrlReturn", bValue);
|
||||
}
|
||||
|
||||
QString RshareSettings::getChatScreenFont()
|
||||
{
|
||||
return valueFromGroup("Chat", "ChatScreenFont").toString();
|
||||
}
|
||||
|
||||
void RshareSettings::setChatScreenFont(const QString &font)
|
||||
{
|
||||
setValueToGroup("Chat", "ChatScreenFont", font);
|
||||
}
|
||||
|
||||
void RshareSettings::getPublicChatStyle(QString &stylePath, QString &styleVariant)
|
||||
{
|
||||
stylePath = valueFromGroup("Chat", "StylePublic", ":/qss/chat/public").toString();
|
||||
styleVariant = valueFromGroup("Chat", "StylePublicVariant", "").toString();
|
||||
}
|
||||
|
||||
void RshareSettings::setPublicChatStyle(QString stylePath, QString styleVariant)
|
||||
void RshareSettings::setPublicChatStyle(const QString &stylePath, const QString &styleVariant)
|
||||
{
|
||||
setValueToGroup("Chat", "StylePublic", stylePath);
|
||||
setValueToGroup("Chat", "StylePublicVariant", styleVariant);
|
||||
@ -317,7 +327,7 @@ void RshareSettings::getPrivateChatStyle(QString &stylePath, QString &styleVaria
|
||||
styleVariant = valueFromGroup("Chat", "StylePrivateVariant", "").toString();
|
||||
}
|
||||
|
||||
void RshareSettings::setPrivateChatStyle(QString stylePath, QString styleVariant)
|
||||
void RshareSettings::setPrivateChatStyle(const QString &stylePath, const QString &styleVariant)
|
||||
{
|
||||
setValueToGroup("Chat", "StylePrivate", stylePath);
|
||||
setValueToGroup("Chat", "StylePrivateVariant", styleVariant);
|
||||
@ -329,7 +339,7 @@ void RshareSettings::getHistoryChatStyle(QString &stylePath, QString &styleVaria
|
||||
styleVariant = valueFromGroup("Chat", "StylePrivateVariant", "").toString();
|
||||
}
|
||||
|
||||
void RshareSettings::setHistoryChatStyle(QString stylePath, QString styleVariant)
|
||||
void RshareSettings::setHistoryChatStyle(const QString &stylePath, const QString &styleVariant)
|
||||
{
|
||||
setValueToGroup("Chat", "StyleHistory", stylePath);
|
||||
setValueToGroup("Chat", "StylePrivateVariant", styleVariant);
|
||||
|
@ -122,15 +122,19 @@ public:
|
||||
bool getChatSendMessageWithCtrlReturn();
|
||||
void setChatSendMessageWithCtrlReturn(bool bValue);
|
||||
|
||||
/* chat font */
|
||||
QString getChatScreenFont();
|
||||
void setChatScreenFont(const QString &font);
|
||||
|
||||
/* chat styles */
|
||||
void getPublicChatStyle(QString &stylePath, QString &styleVariant);
|
||||
void setPublicChatStyle(QString stylePath, QString styleVariant);
|
||||
void setPublicChatStyle(const QString &stylePath, const QString &styleVariant);
|
||||
|
||||
void getPrivateChatStyle(QString &stylePath, QString &styleVariant);
|
||||
void setPrivateChatStyle(QString stylePath, QString styleVariant);
|
||||
void setPrivateChatStyle(const QString &stylePath, const QString &styleVariant);
|
||||
|
||||
void getHistoryChatStyle(QString &stylePath, QString &styleVariant);
|
||||
void setHistoryChatStyle(QString stylePath, QString styleVariant);
|
||||
void setHistoryChatStyle(const QString &stylePath, const QString &styleVariant);
|
||||
|
||||
//! Save placement, state and size information of a window.
|
||||
void saveWidgetInformation(QWidget *widget);
|
||||
|
@ -36,6 +36,7 @@
|
||||
#include "gui/StartDialog.h"
|
||||
#include "gui/GenCertDialog.h"
|
||||
#include "gui/settings/rsharesettings.h"
|
||||
#include "gui/settings/RsharePeerSettings.h"
|
||||
#include "gui/connect/ConfCertDialog.h"
|
||||
#include "idle/idle.h"
|
||||
|
||||
@ -160,6 +161,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
/* recreate global settings object, now with correct path */
|
||||
RshareSettings::Create ();
|
||||
RsharePeerSettings::Create();
|
||||
|
||||
#ifdef MINIMAL_RSGUI
|
||||
MessengerWindow::showYourself();
|
||||
|
Loading…
Reference in New Issue
Block a user