From cbdb717e51f90b7443824c297723944f1421b75f Mon Sep 17 00:00:00 2001 From: thunder2 Date: Fri, 10 Sep 2010 18:38:46 +0000 Subject: [PATCH] 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 --- retroshare-gui/src/RetroShare.pro | 2 + retroshare-gui/src/gui/PeersDialog.cpp | 7 +- retroshare-gui/src/gui/chat/ChatStyle.cpp | 4 +- retroshare-gui/src/gui/chat/ChatStyle.h | 4 +- .../src/gui/chat/PopupChatDialog.cpp | 44 +++-- retroshare-gui/src/gui/chat/PopupChatDialog.h | 1 + retroshare-gui/src/gui/settings/ChatPage.cpp | 8 +- .../src/gui/settings/RsharePeerSettings.cpp | 157 ++++++++++++++++++ .../src/gui/settings/RsharePeerSettings.h | 59 +++++++ .../src/gui/settings/rsharesettings.cpp | 16 +- .../src/gui/settings/rsharesettings.h | 10 +- retroshare-gui/src/main.cpp | 2 + 12 files changed, 279 insertions(+), 35 deletions(-) create mode 100644 retroshare-gui/src/gui/settings/RsharePeerSettings.cpp create mode 100644 retroshare-gui/src/gui/settings/RsharePeerSettings.h diff --git a/retroshare-gui/src/RetroShare.pro b/retroshare-gui/src/RetroShare.pro index 945d54e27..afe91381b 100644 --- a/retroshare-gui/src/RetroShare.pro +++ b/retroshare-gui/src/RetroShare.pro @@ -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 \ diff --git a/retroshare-gui/src/gui/PeersDialog.cpp b/retroshare-gui/src/gui/PeersDialog.cpp index 7aef2aaaa..2694738b6 100644 --- a/retroshare-gui/src/gui/PeersDialog.cpp +++ b/retroshare-gui/src/gui/PeersDialog.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(); diff --git a/retroshare-gui/src/gui/chat/ChatStyle.cpp b/retroshare-gui/src/gui/chat/ChatStyle.cpp index a0346dc48..917ac8a68 100644 --- a/retroshare-gui/src/gui/chat/ChatStyle.cpp +++ b/retroshare-gui/src/gui/chat/ChatStyle.cpp @@ -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(); diff --git a/retroshare-gui/src/gui/chat/ChatStyle.h b/retroshare-gui/src/gui/chat/ChatStyle.h index 592cae586..4afd48e89 100644 --- a/retroshare-gui/src/gui/chat/ChatStyle.h +++ b/retroshare-gui/src/gui/chat/ChatStyle.h @@ -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 &styles); - static bool getAvailableVariants(QString stylePath, QStringList &variants); + static bool getAvailableVariants(const QString &stylePath, QStringList &variants); private slots: void styleChanged(int styleType); diff --git a/retroshare-gui/src/gui/chat/PopupChatDialog.cpp b/retroshare-gui/src/gui/chat/PopupChatDialog.cpp index 8778c1bc9..5c1f12f33 100644 --- a/retroshare-gui/src/gui/chat/PopupChatDialog.cpp +++ b/retroshare-gui/src/gui/chat/PopupChatDialog.cpp @@ -45,6 +45,7 @@ #include #include #include "gui/settings/rsharesettings.h" +#include "gui/settings/RsharePeerSettings.h" #include "gui/notifyqt.h" #include "../RsAutoUpdatePage.h" @@ -145,7 +146,7 @@ PopupChatDialog::PopupChatDialog(std::string id, std::string name, //ui.textBrowser->setOpenExternalLinks ( false ); //ui.textBrowser->setOpenLinks ( false ); - QString title = tr("RetroShare - ") + QString::fromStdString(name) ; + QString title = tr("RetroShare - ") + QString::fromStdString(name); setWindowTitle(title); setWindowIcon(QIcon(IMAGE_WINDOW)); @@ -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() ) ); @@ -667,10 +668,11 @@ void PopupChatDialog::on_closeInfoFrameButton_clicked() void PopupChatDialog::setColor() { - bool ok; + bool ok; QRgb color = QColorDialog::getRgba(ui.chattextEdit->textColor().rgba(), &ok, this); if (ok) { mCurrentColor = QColor(color); + PeerSettings->setPrivateChatColor(dialogId, mCurrentColor.name()); colorChanged(mCurrentColor); } setFont(); @@ -686,25 +688,35 @@ 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()); + mCurrentFont.setUnderline(ui.textunderlineButton->isChecked()); + mCurrentFont.setItalic(ui.textitalicButton->isChecked()); -// mCurrentFont.setBold(ui.textboldButton->isChecked()); - bool flag; - flag=ui.textboldButton->isChecked(); - mCurrentFont.setBold(flag); - mCurrentFont.setUnderline(ui.textunderlineButton->isChecked()); - mCurrentFont.setItalic(ui.textitalicButton->isChecked()); + ui.chattextEdit->setFont(mCurrentFont); + ui.chattextEdit->setTextColor(mCurrentColor); - ui.chattextEdit->setFont(mCurrentFont); - ui.chattextEdit->setTextColor(mCurrentColor); - - ui.chattextEdit->setFocus(); + ui.chattextEdit->setFocus(); + PeerSettings->setPrivateChatFont(dialogId, mCurrentFont.toString()); } //============================================================================ diff --git a/retroshare-gui/src/gui/chat/PopupChatDialog.h b/retroshare-gui/src/gui/chat/PopupChatDialog.h index d80964ad4..2ec6e9a24 100644 --- a/retroshare-gui/src/gui/chat/PopupChatDialog.h +++ b/retroshare-gui/src/gui/chat/PopupChatDialog.h @@ -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); diff --git a/retroshare-gui/src/gui/settings/ChatPage.cpp b/retroshare-gui/src/gui/settings/ChatPage.cpp index 20cca3e8c..ae8a4dbbc 100644 --- a/retroshare-gui/src/gui/settings/ChatPage.cpp +++ b/retroshare-gui/src/gui/settings/ChatPage.cpp @@ -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()); diff --git a/retroshare-gui/src/gui/settings/RsharePeerSettings.cpp b/retroshare-gui/src/gui/settings/RsharePeerSettings.cpp new file mode 100644 index 000000000..6483a0046 --- /dev/null +++ b/retroshare-gui/src/gui/settings/RsharePeerSettings.cpp @@ -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 +#include +#include + +#include +#include + +#include +#include + +#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::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); +} diff --git a/retroshare-gui/src/gui/settings/RsharePeerSettings.h b/retroshare-gui/src/gui/settings/RsharePeerSettings.h new file mode 100644 index 000000000..42f7b9491 --- /dev/null +++ b/retroshare-gui/src/gui/settings/RsharePeerSettings.h @@ -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 + +/** 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 m_SslToGpg; +}; + +// the one and only global settings object +extern RsharePeerSettings *PeerSettings; + +#endif diff --git a/retroshare-gui/src/gui/settings/rsharesettings.cpp b/retroshare-gui/src/gui/settings/rsharesettings.cpp index cb3e2d98b..c3257eea1 100644 --- a/retroshare-gui/src/gui/settings/rsharesettings.cpp +++ b/retroshare-gui/src/gui/settings/rsharesettings.cpp @@ -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); diff --git a/retroshare-gui/src/gui/settings/rsharesettings.h b/retroshare-gui/src/gui/settings/rsharesettings.h index cad8cc826..b6183b233 100644 --- a/retroshare-gui/src/gui/settings/rsharesettings.h +++ b/retroshare-gui/src/gui/settings/rsharesettings.h @@ -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); diff --git a/retroshare-gui/src/main.cpp b/retroshare-gui/src/main.cpp index 35a6671fd..4e9479d33 100644 --- a/retroshare-gui/src/main.cpp +++ b/retroshare-gui/src/main.cpp @@ -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();