From 6bd6c505026854d4e405f47c6f2479421a34b984 Mon Sep 17 00:00:00 2001 From: thunder2 Date: Tue, 7 Sep 2010 15:49:31 +0000 Subject: [PATCH] Styles for public chat, private chat and history. RetroShare has a standard style for each type, but the user can define their own styles. The external directories "style/public", "style/private" and "style/history" are scanned for subdirs with user defined style informations. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3453 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- retroshare-gui/src/gui/PeersDialog.cpp | 2 +- retroshare-gui/src/gui/chat/ChatStyle.cpp | 230 ++- retroshare-gui/src/gui/chat/ChatStyle.h | 38 +- .../src/gui/chat/PopupChatDialog.cpp | 2 +- .../src/gui/im_history/ImHistoryBrowser.cpp | 2 +- retroshare-gui/src/gui/images.qrc | 5 + retroshare-gui/src/gui/notifyqt.cpp | 7 +- retroshare-gui/src/gui/notifyqt.h | 8 +- .../src/gui/qss/chat/history/hincoming.htm | 15 + .../src/gui/qss/chat/history/incoming.htm | 3 +- .../src/gui/qss/chat/history/info.xml | 12 + .../src/gui/qss/chat/history/main.css | 12 +- .../src/gui/qss/chat/history/outgoing.htm | 3 +- .../src/gui/qss/chat/private/hincoming.htm | 2 +- .../src/gui/qss/chat/private/houtgoing.htm | 2 +- .../src/gui/qss/chat/private/incoming.htm | 2 +- .../src/gui/qss/chat/private/info.xml | 12 + .../src/gui/qss/chat/private/outgoing.htm | 2 +- .../src/gui/qss/chat/public/info.xml | 12 + retroshare-gui/src/gui/settings/ChatPage.cpp | 170 +- retroshare-gui/src/gui/settings/ChatPage.h | 8 + retroshare-gui/src/gui/settings/ChatPage.ui | 1629 ++++++++++------- .../src/gui/settings/rsharesettings.cpp | 30 + .../src/gui/settings/rsharesettings.h | 13 +- 24 files changed, 1537 insertions(+), 684 deletions(-) create mode 100644 retroshare-gui/src/gui/qss/chat/history/hincoming.htm create mode 100644 retroshare-gui/src/gui/qss/chat/history/info.xml create mode 100644 retroshare-gui/src/gui/qss/chat/private/info.xml create mode 100644 retroshare-gui/src/gui/qss/chat/public/info.xml diff --git a/retroshare-gui/src/gui/PeersDialog.cpp b/retroshare-gui/src/gui/PeersDialog.cpp index a270d402d..e0c1069ce 100644 --- a/retroshare-gui/src/gui/PeersDialog.cpp +++ b/retroshare-gui/src/gui/PeersDialog.cpp @@ -202,7 +202,7 @@ PeersDialog::PeersDialog(QWidget *parent) mCurrentFont.fromString(Settings->valueFromGroup("Chat", QString::fromUtf8("ChatScreenFont")).toString()); ui.lineEdit->setFont(mCurrentFont); - style.setStylePath(":/qss/chat/public"); + style.setStyleFromSettings(ChatStyle::TYPE_PUBLIC); style.loadEmoticons(); setChatInfo(tr("Welcome to RetroShare's group chat."), QString::fromUtf8("blue")); diff --git a/retroshare-gui/src/gui/chat/ChatStyle.cpp b/retroshare-gui/src/gui/chat/ChatStyle.cpp index e9d75dd93..eaf8ade0a 100644 --- a/retroshare-gui/src/gui/chat/ChatStyle.cpp +++ b/retroshare-gui/src/gui/chat/ChatStyle.cpp @@ -26,9 +26,13 @@ #include #include #include +#include + #include #include "ChatStyle.h" +#include "gui/settings/rsharesettings.h" +#include "gui/notifyqt.h" enum enumGetStyle { @@ -39,8 +43,11 @@ enum enumGetStyle }; /* Default constructor */ -ChatStyle::ChatStyle() +ChatStyle::ChatStyle() : QObject() { + m_styleType = TYPE_UNKNOWN; + + connect(NotifyQt::getInstance(), SIGNAL(chatStyleChanged(int)), SLOT(styleChanged(int))); } /* Destructor. */ @@ -48,14 +55,51 @@ ChatStyle::~ChatStyle() { } -void ChatStyle::setStylePath(QString path) +void ChatStyle::styleChanged(int styleType) { - stylePath = path; - if (stylePath.right(1) != "/" && stylePath.right(1) != "\\") { - stylePath += "/"; + if (m_styleType == styleType) { + setStyleFromSettings(m_styleType); } } +bool ChatStyle::setStylePath(QString stylePath) +{ + m_styleType = TYPE_UNKNOWN; + + m_styleDir.setPath(QApplication::applicationDirPath()); + if (m_styleDir.cd(stylePath) == false) { + m_styleDir = QDir(""); + return false; + } + + return true; +} + +bool ChatStyle::setStyleFromSettings(enumStyleType styleType) +{ + QString stylePath; + + switch (styleType) { + case TYPE_PUBLIC: + Settings->getPublicChatStyle(stylePath); + break; + case TYPE_PRIVATE: + Settings->getPrivateChatStyle(stylePath); + break; + case TYPE_HISTORY: + Settings->getHistoryChatStyle(stylePath); + break; + case TYPE_UNKNOWN: + return false; + } + + bool result = setStylePath(stylePath); + + m_styleType = styleType; + + return result; +} + void ChatStyle::loadEmoticons() { QString sm_codes; @@ -204,27 +248,27 @@ void ChatStyle::showSmileyWidget(QWidget *parent, QWidget *button, const char *s smWidget->show(); } -static QString getStyle(QString &stylePath, enumGetStyle type) +static QString getStyle(QDir &styleDir, enumGetStyle type) { QString style; - if (stylePath.isEmpty()) { + if (styleDir == QDir("")) { return ""; } QFile fileHtml; switch (type) { case GETSTYLE_INCOMING: - fileHtml.setFileName(stylePath + "incoming.htm"); + fileHtml.setFileName(QFileInfo(styleDir, "incoming.htm").absoluteFilePath()); break; case GETSTYLE_OUTGOING: - fileHtml.setFileName(stylePath + "outgoing.htm"); + fileHtml.setFileName(QFileInfo(styleDir, "outgoing.htm").absoluteFilePath()); break; case GETSTYLE_HINCOMING: - fileHtml.setFileName(stylePath + "hincoming.htm"); + fileHtml.setFileName(QFileInfo(styleDir, "hincoming.htm").absoluteFilePath()); break; case GETSTYLE_HOUTGOING: - fileHtml.setFileName(stylePath + "houtgoing.htm"); + fileHtml.setFileName(QFileInfo(styleDir, "houtgoing.htm").absoluteFilePath()); break; default: return ""; @@ -234,7 +278,7 @@ static QString getStyle(QString &stylePath, enumGetStyle type) style = fileHtml.readAll(); fileHtml.close(); - QFile fileCss(stylePath + "main.css"); + QFile fileCss(QFileInfo(styleDir, "main.css").absoluteFilePath()); QString css; if (fileCss.open(QIODevice::ReadOnly)) { css = fileCss.readAll(); @@ -273,22 +317,22 @@ QString ChatStyle::formatMessage(enumFormatMessage type, QString &name, QDateTim switch (type) { case FORMATMSG_INCOMING: - style = getStyle(stylePath, GETSTYLE_INCOMING); + style = getStyle(m_styleDir, GETSTYLE_INCOMING); break; case FORMATMSG_OUTGOING: - style = getStyle(stylePath, GETSTYLE_OUTGOING); + style = getStyle(m_styleDir, GETSTYLE_OUTGOING); break; case FORMATMSG_HINCOMING: - style = getStyle(stylePath, GETSTYLE_HINCOMING); + style = getStyle(m_styleDir, GETSTYLE_HINCOMING); break; case FORMATMSG_HOUTGOING: - style = getStyle(stylePath, GETSTYLE_HOUTGOING); + style = getStyle(m_styleDir, GETSTYLE_HOUTGOING); break; } if (style.isEmpty()) { // default style - style = "%timestamp% %name% \n %message% "; + style = "
%name%%timestamp%
%message%
"; } unsigned int formatFlag = 0; @@ -339,3 +383,155 @@ QString ChatStyle::formatMessage(enumFormatMessage type, QString &name, QDateTim return formatMsg; } + +static bool getStyleInfo(QString stylePath, QString stylePathRelative, ChatStyleInfo &info) +{ + // Initialize info + info = ChatStyleInfo(); + + QFileInfo file(stylePath, "info.xml"); + + QFile xmlFile(file.filePath()); + if (xmlFile.open(QIODevice::ReadOnly) == false) { + // No info file found + return false; + } + + QDir dir(QApplication::applicationDirPath()); + + QXmlStreamReader reader; + reader.setDevice(&xmlFile); + + while (reader.atEnd() == false) { + reader.readNext(); + if (reader.isStartElement()) { + if (reader.name() == "RetroShare_Style") { + if (reader.attributes().value("version") == "1.0") { + info.stylePath = stylePathRelative; + continue; + } + // Not the right format of the xml file; + return false ; + } + + if (info.stylePath.isEmpty()) { + continue; + } + + if (reader.name() == "style") { + // read style information + while (reader.atEnd() == false) { + reader.readNext(); + if (reader.isEndElement()) { + if (reader.name() == "style") { + break; + } + continue; + } + if (reader.isStartElement()) { + if (reader.name() == "name") { + info.styleName = reader.readElementText(); + continue; + } + if (reader.name() == "description") { + info.styleDescription = reader.readElementText(); + continue; + } + // ingore all other entries + } + } + continue; + } + + if (reader.name() == "author") { + // read author information + while (reader.atEnd() == false) { + reader.readNext(); + if (reader.isEndElement()) { + if (reader.name() == "author") { + break; + } + continue; + } + if (reader.isStartElement()) { + if (reader.name() == "name") { + info.authorName = reader.readElementText(); + continue; + } + if (reader.name() == "email") { + info.authorEmail = reader.readElementText(); + continue; + } + // ingore all other entries + } + } + continue; + } + // ingore all other entries + } + } + + if (reader.hasError()) { + return false; + } + + if (info.stylePath.isEmpty()) { + return false; + } + return true; +} + +/*static*/ bool ChatStyle::getAvailableStyles(enumStyleType styleType, QList &styles) +{ + styles.clear(); + + ChatStyleInfo standardInfo; + QString stylePath; + + switch (styleType) { + case TYPE_PUBLIC: + if (getStyleInfo(":/qss/chat/public", ":/qss/chat/public", standardInfo)) { + standardInfo.styleDescription = tr("Standard style for public chat"); + styles.append(standardInfo); + } + stylePath = "style/public"; + break; + case TYPE_PRIVATE: + if (getStyleInfo(":/qss/chat/private", ":/qss/chat/private", standardInfo)) { + standardInfo.styleDescription = tr("Standard style for private chat"); + styles.append(standardInfo); + } + stylePath = "style/private"; + break; + case TYPE_HISTORY: + if (getStyleInfo(":/qss/chat/history", ":/qss/chat/history", standardInfo)) { + standardInfo.styleDescription = tr("Standard style for history"); + styles.append(standardInfo); + } + stylePath = "style/history"; + break; + case TYPE_UNKNOWN: + default: + return false; + } + + // application path + QDir applicationDir(QApplication::applicationDirPath()); + QDir dir(QApplication::applicationDirPath()); + if (dir.cd(stylePath) == false) { + return true; + } + + // get all style directories + QFileInfoList dirList = dir.entryInfoList(QDir::AllDirs | QDir::NoDotAndDotDot, QDir::Name); + + // iterate style directories and get info + for (QFileInfoList::iterator dir = dirList.begin(); dir != dirList.end(); dir++) { + ChatStyleInfo info; + if (getStyleInfo(dir->absoluteFilePath(), applicationDir.relativeFilePath(dir->absoluteFilePath()), info)) { + styles.append(info); + } + } + + return true; +} diff --git a/retroshare-gui/src/gui/chat/ChatStyle.h b/retroshare-gui/src/gui/chat/ChatStyle.h index 492180d8e..a0fdca148 100644 --- a/retroshare-gui/src/gui/chat/ChatStyle.h +++ b/retroshare-gui/src/gui/chat/ChatStyle.h @@ -26,6 +26,7 @@ #include #include #include +#include #include "HandleRichText.h" @@ -37,8 +38,25 @@ #define CHAT_FORMATTEXT_EMBED_SMILEYS 1 #define CHAT_FORMATTEXT_EMBED_LINKS 2 -class ChatStyle +class ChatStyleInfo { +public: + ChatStyleInfo() {} + +public: + QString stylePath; + QString styleName; + QString styleDescription; + QString authorName; + QString authorEmail; +}; + +Q_DECLARE_METATYPE(ChatStyleInfo) + +class ChatStyle : public QObject +{ + Q_OBJECT + public: enum enumFormatMessage { @@ -48,6 +66,14 @@ public: FORMATMSG_HOUTGOING }; + enum enumStyleType + { + TYPE_UNKNOWN, + TYPE_PUBLIC, + TYPE_PRIVATE, + TYPE_HISTORY + }; + QHash smileys; public: @@ -56,16 +82,22 @@ public: /* Default destructor */ ~ChatStyle(); - void setStylePath(QString path); + bool setStylePath(QString stylePath); + bool setStyleFromSettings(enumStyleType styleType); void loadEmoticons(); QString formatMessage(enumFormatMessage type, QString &name, QDateTime ×tamp, QString &message, unsigned int flag); QString formatText(QString &message, unsigned int flag); void showSmileyWidget(QWidget *parent, QWidget *button, const char *slotAddMethod); + static bool getAvailableStyles(enumStyleType styleType, QList &styles); + +private slots: + void styleChanged(int styleType); private: - QString stylePath; + enumStyleType m_styleType; + QDir m_styleDir; /** store default information for embedding HTML */ RsChat::EmbedInHtmlAhref defEmbedAhref; diff --git a/retroshare-gui/src/gui/chat/PopupChatDialog.cpp b/retroshare-gui/src/gui/chat/PopupChatDialog.cpp index cca7dc6b2..a6cf04862 100644 --- a/retroshare-gui/src/gui/chat/PopupChatDialog.cpp +++ b/retroshare-gui/src/gui/chat/PopupChatDialog.cpp @@ -99,7 +99,7 @@ PopupChatDialog::PopupChatDialog(std::string id, std::string name, m_bInsertOnVisible = true; last_status_send_time = 0 ; - style.setStylePath(":/qss/chat/private"); + style.setStyleFromSettings(ChatStyle::TYPE_PRIVATE); style.loadEmoticons(); /* Hide or show the frames */ diff --git a/retroshare-gui/src/gui/im_history/ImHistoryBrowser.cpp b/retroshare-gui/src/gui/im_history/ImHistoryBrowser.cpp index 5080e2527..3b89d5fb2 100644 --- a/retroshare-gui/src/gui/im_history/ImHistoryBrowser.cpp +++ b/retroshare-gui/src/gui/im_history/ImHistoryBrowser.cpp @@ -70,7 +70,7 @@ ImHistoryBrowser::ImHistoryBrowser(bool isPrivateChatIn, IMHistoryKeeper &histKe embedSmileys = Settings->valueFromGroup(QString("Chat"), QString::fromUtf8("Emoteicons_GroupChat"), true).toBool(); } - style.setStylePath(":/qss/chat/history"); + style.setStyleFromSettings(ChatStyle::TYPE_HISTORY); style.loadEmoticons(); ui.listWidget->setItemDelegate(new IMHistoryItemDelegate); diff --git a/retroshare-gui/src/gui/images.qrc b/retroshare-gui/src/gui/images.qrc index 80c76e480..6a1cf9e65 100644 --- a/retroshare-gui/src/gui/images.qrc +++ b/retroshare-gui/src/gui/images.qrc @@ -451,18 +451,23 @@ images/window_fullscreen.png images/window_nofullscreen.png layouts/default.ui + qss/chat/private/info.xml qss/chat/private/incoming.htm qss/chat/private/outgoing.htm qss/chat/private/hincoming.htm qss/chat/private/houtgoing.htm qss/chat/private/main.css + qss/chat/public/info.xml qss/chat/public/incoming.htm qss/chat/public/outgoing.htm qss/chat/public/hincoming.htm qss/chat/public/houtgoing.htm qss/chat/public/main.css + qss/chat/history/info.xml qss/chat/history/incoming.htm qss/chat/history/outgoing.htm + qss/chat/history/hincoming.htm + qss/chat/history/houtgoing.htm qss/chat/history/main.css smileys/angry.png smileys/beer.png diff --git a/retroshare-gui/src/gui/notifyqt.cpp b/retroshare-gui/src/gui/notifyqt.cpp index f81566b02..c2d482189 100644 --- a/retroshare-gui/src/gui/notifyqt.cpp +++ b/retroshare-gui/src/gui/notifyqt.cpp @@ -399,7 +399,12 @@ void NotifyQt::UpdateGUI() } #endif // MINIMAL_RSGUI } - + +void NotifyQt::notifyChatStyleChanged(int /*ChatStyle::enumStyleType*/ styleType) +{ + emit chatStyleChanged(styleType); +} + //void NotifyQt::displaySearch() //{ // iface->lockData(); /* Lock Interface */ diff --git a/retroshare-gui/src/gui/notifyqt.h b/retroshare-gui/src/gui/notifyqt.h index 1b84c5211..975e1a735 100644 --- a/retroshare-gui/src/gui/notifyqt.h +++ b/retroshare-gui/src/gui/notifyqt.h @@ -15,7 +15,7 @@ class ChatDialog; class MessagesDialog; class ChannelsDialog; class MessengerWindow; -struct TurtleFileInfo ; +struct TurtleFileInfo; //class NotifyQt: public NotifyBase, public QObject class NotifyQt: public QObject, public NotifyBase @@ -47,6 +47,9 @@ class NotifyQt: public QObject, public NotifyBase virtual std::string askForPassword(const std::string& key_details,bool prev_is_bad) ; + /* Notify from GUI */ + void notifyChatStyleChanged(int /*ChatStyle::enumStyleType*/ styleType); + signals: // It's beneficial to send info to the GUI using signals, because signals are thread-safe // as they get queued by Qt. @@ -75,6 +78,9 @@ class NotifyQt: public QObject, public NotifyBase void publicChatChanged(int type) const ; void privateChatChanged(int type) const ; + /* Notify from GUI */ + void chatStyleChanged(int /*ChatStyle::enumStyleType*/ styleType); + public slots: void UpdateGUI(); /* called by timer */ diff --git a/retroshare-gui/src/gui/qss/chat/history/hincoming.htm b/retroshare-gui/src/gui/qss/chat/history/hincoming.htm new file mode 100644 index 000000000..fce27c7b7 --- /dev/null +++ b/retroshare-gui/src/gui/qss/chat/history/hincoming.htm @@ -0,0 +1,15 @@ + + + + + + +
%name%[%timestamp%]
+ + + + +
%message%
+ \ No newline at end of file diff --git a/retroshare-gui/src/gui/qss/chat/history/incoming.htm b/retroshare-gui/src/gui/qss/chat/history/incoming.htm index 814d06e7b..71c308421 100644 --- a/retroshare-gui/src/gui/qss/chat/history/incoming.htm +++ b/retroshare-gui/src/gui/qss/chat/history/incoming.htm @@ -5,10 +5,9 @@ %name% [%timestamp%] - - +
diff --git a/retroshare-gui/src/gui/qss/chat/history/info.xml b/retroshare-gui/src/gui/qss/chat/history/info.xml new file mode 100644 index 000000000..7f0445b03 --- /dev/null +++ b/retroshare-gui/src/gui/qss/chat/history/info.xml @@ -0,0 +1,12 @@ + + + + + + RetroShare Team + + + \ No newline at end of file diff --git a/retroshare-gui/src/gui/qss/chat/history/main.css b/retroshare-gui/src/gui/qss/chat/history/main.css index d4330ac67..2321bfe04 100644 --- a/retroshare-gui/src/gui/qss/chat/history/main.css +++ b/retroshare-gui/src/gui/qss/chat/history/main.css @@ -31,25 +31,29 @@ color: #244578; } -.hincomingHeader { +.hincomingTable{ background-color:#dfedff; +} + +.hincomingHeader { border-color:#fafafa #d1dfef #d1dfef #fafafa; color: #295b07; } .hincomingTime { - background-color:#dfedff; color: #295b07; } -.houtgoingHeader { +.houtgoingTable{ background-color:#f5f5f5; +} + +.houtgoingHeader { border-color:#fafafa #e3e3e3 #e3e3e3 #fafafa; color: #244578; } .houtgoingTime { - background-color:#f5f5f5; color: #244578; } diff --git a/retroshare-gui/src/gui/qss/chat/history/outgoing.htm b/retroshare-gui/src/gui/qss/chat/history/outgoing.htm index 2d5a39661..99425b5dc 100644 --- a/retroshare-gui/src/gui/qss/chat/history/outgoing.htm +++ b/retroshare-gui/src/gui/qss/chat/history/outgoing.htm @@ -5,10 +5,9 @@ -
%message%
%name% [%timestamp%]
- +
diff --git a/retroshare-gui/src/gui/qss/chat/private/hincoming.htm b/retroshare-gui/src/gui/qss/chat/private/hincoming.htm index 094b29f7e..10e6fb431 100644 --- a/retroshare-gui/src/gui/qss/chat/private/hincoming.htm +++ b/retroshare-gui/src/gui/qss/chat/private/hincoming.htm @@ -7,7 +7,7 @@
%message%
%timestamp%
- +
diff --git a/retroshare-gui/src/gui/qss/chat/private/houtgoing.htm b/retroshare-gui/src/gui/qss/chat/private/houtgoing.htm index 6c13e37e9..70e7a9d8d 100644 --- a/retroshare-gui/src/gui/qss/chat/private/houtgoing.htm +++ b/retroshare-gui/src/gui/qss/chat/private/houtgoing.htm @@ -7,7 +7,7 @@
%message%
%timestamp%
- +
diff --git a/retroshare-gui/src/gui/qss/chat/private/incoming.htm b/retroshare-gui/src/gui/qss/chat/private/incoming.htm index dce79d1e8..8c9aeb130 100644 --- a/retroshare-gui/src/gui/qss/chat/private/incoming.htm +++ b/retroshare-gui/src/gui/qss/chat/private/incoming.htm @@ -7,7 +7,7 @@
%message%
%timestamp%
- +
diff --git a/retroshare-gui/src/gui/qss/chat/private/info.xml b/retroshare-gui/src/gui/qss/chat/private/info.xml new file mode 100644 index 000000000..7f0445b03 --- /dev/null +++ b/retroshare-gui/src/gui/qss/chat/private/info.xml @@ -0,0 +1,12 @@ + + + + + + RetroShare Team + + + \ No newline at end of file diff --git a/retroshare-gui/src/gui/qss/chat/private/outgoing.htm b/retroshare-gui/src/gui/qss/chat/private/outgoing.htm index 0942f7401..b2b3abe48 100644 --- a/retroshare-gui/src/gui/qss/chat/private/outgoing.htm +++ b/retroshare-gui/src/gui/qss/chat/private/outgoing.htm @@ -7,7 +7,7 @@
%message%
%timestamp%
- +
diff --git a/retroshare-gui/src/gui/qss/chat/public/info.xml b/retroshare-gui/src/gui/qss/chat/public/info.xml new file mode 100644 index 000000000..7f0445b03 --- /dev/null +++ b/retroshare-gui/src/gui/qss/chat/public/info.xml @@ -0,0 +1,12 @@ + + + + + + RetroShare Team + + + \ No newline at end of file diff --git a/retroshare-gui/src/gui/settings/ChatPage.cpp b/retroshare-gui/src/gui/settings/ChatPage.cpp index d75284816..72ef9eb1d 100644 --- a/retroshare-gui/src/gui/settings/ChatPage.cpp +++ b/retroshare-gui/src/gui/settings/ChatPage.cpp @@ -20,19 +20,60 @@ ****************************************************************/ #include +#include #include "ChatPage.h" - +#include "gui/chat/ChatStyle.h" +#include "gui/notifyqt.h" #include "rsharesettings.h" +static QString loadStyleInfo(ChatStyle::enumStyleType type, QListWidget *listWidget) +{ + QList styles; + QList::iterator style; + QListWidgetItem *item; + QListWidgetItem *activeItem = NULL; + + QString stylePath; + + switch (type) { + case ChatStyle::TYPE_PUBLIC: + Settings->getPublicChatStyle(stylePath); + break; + case ChatStyle::TYPE_PRIVATE: + Settings->getPrivateChatStyle(stylePath); + break; + case ChatStyle::TYPE_HISTORY: + Settings->getHistoryChatStyle(stylePath); + break; + case ChatStyle::TYPE_UNKNOWN: + return ""; + } + + ChatStyle::getAvailableStyles(type, styles); + for (style = styles.begin(); style != styles.end(); style++) { + item = new QListWidgetItem(style->styleName); + item->setData(Qt::UserRole, qVariantFromValue(*style)); + listWidget->addItem(item); + + if (style->stylePath == stylePath) { + activeItem = item; + } + } + + listWidget->setCurrentItem(activeItem); + + return stylePath; +} + /** Constructor */ ChatPage::ChatPage(QWidget * parent, Qt::WFlags flags) : ConfigPage(parent, flags) { - /* Invoke the Qt Designer generated object setup routine */ - ui.setupUi(this); + /* Invoke the Qt Designer generated object setup routine */ + ui.setupUi(this); - /* Hide platform specific features */ + /* Hide platform specific features */ #ifdef Q_WS_WIN #endif @@ -59,6 +100,34 @@ ChatPage::save(QString &errmsg) Settings->setChatSendMessageWithCtrlReturn(ui.sendMessageWithCtrlReturn->isChecked()); + ChatStyleInfo info; + QListWidgetItem *item = ui.publicList->currentItem(); + if (item) { + info = qVariantValue(item->data(Qt::UserRole)); + if (publicStylePath != info.stylePath) { + Settings->setPublicChatStyle(info.stylePath); + NotifyQt::getInstance()->notifyChatStyleChanged(ChatStyle::TYPE_PUBLIC); + } + } + + item = ui.privateList->currentItem(); + if (item) { + info = qVariantValue(item->data(Qt::UserRole)); + if (privateStylePath != info.stylePath) { + Settings->setPrivateChatStyle(info.stylePath); + NotifyQt::getInstance()->notifyChatStyleChanged(ChatStyle::TYPE_PRIVATE); + } + } + + item = ui.historyList->currentItem(); + if (item) { + info = qVariantValue(item->data(Qt::UserRole)); + if (historyStylePath != info.stylePath) { + Settings->setHistoryChatStyle(info.stylePath); + NotifyQt::getInstance()->notifyChatStyleChanged(ChatStyle::TYPE_HISTORY); + } + } + return true; } @@ -80,6 +149,11 @@ ChatPage::load() ui.labelChatFontPreview->setText(fontTempChat.rawName()); ui.labelChatFontPreview->setFont(fontTempChat); + + /* Load styles */ + publicStylePath = loadStyleInfo(ChatStyle::TYPE_PUBLIC, ui.publicList); + privateStylePath = loadStyleInfo(ChatStyle::TYPE_PRIVATE, ui.privateList); + historyStylePath = loadStyleInfo(ChatStyle::TYPE_HISTORY, ui.historyList); } bool ChatPage::emotePrivatChat() const { @@ -107,3 +181,91 @@ void ChatPage::on_pushButtonChangeChatFont_clicked() ui.labelChatFontPreview->setFont(fontTempChat); } } + +void ChatPage::setPreviewMessages(QString &stylePath, QTextBrowser *textBrowser) +{ + ChatStyle style; + style.setStylePath(stylePath); + style.loadEmoticons(); + + textBrowser->clear(); + + QString nameIncoming = "Incoming"; + QString nameOutgoing = "Outgoing"; + QDateTime timestmp = QDateTime::fromTime_t(time(NULL)); + QTextEdit textEdit; + QString message; + + textEdit.setText(tr("Incoming message in history")); + message = textEdit.toHtml(); + textBrowser->append(style.formatMessage(ChatStyle::FORMATMSG_HINCOMING, nameIncoming, timestmp, message, CHAT_FORMATTEXT_EMBED_SMILEYS)); + textEdit.setText(tr("Outgoing message in history")); + message = textEdit.toHtml(); + textBrowser->append(style.formatMessage(ChatStyle::FORMATMSG_HOUTGOING, nameOutgoing, timestmp, message, CHAT_FORMATTEXT_EMBED_SMILEYS)); + textEdit.setText(tr("Incoming message")); + message = textEdit.toHtml(); + textBrowser->append(style.formatMessage(ChatStyle::FORMATMSG_INCOMING, nameIncoming, timestmp, message, CHAT_FORMATTEXT_EMBED_SMILEYS)); + textEdit.setText(tr("Outgoing message")); + message = textEdit.toHtml(); + textBrowser->append(style.formatMessage(ChatStyle::FORMATMSG_OUTGOING, nameOutgoing, timestmp, message, CHAT_FORMATTEXT_EMBED_SMILEYS)); +} + +void ChatPage::on_publicList_currentRowChanged(int currentRow) +{ + if (currentRow != -1) { + QListWidgetItem *item = ui.publicList->item(currentRow); + ChatStyleInfo info = qVariantValue(item->data(Qt::UserRole)); + setPreviewMessages(info.stylePath, ui.publicPreview); + + QString author = info.authorName; + if (info.authorEmail.isEmpty() == false) { + author += " (" + info.authorEmail + ")"; + } + ui.publicAuthor->setText(author); + ui.publicDescription->setText(info.styleDescription); + } else { + ui.publicPreview->clear(); + ui.publicAuthor->clear(); + ui.publicDescription->clear(); + } +} + +void ChatPage::on_privateList_currentRowChanged(int currentRow) +{ + if (currentRow != -1) { + QListWidgetItem *item = ui.privateList->item(currentRow); + ChatStyleInfo info = qVariantValue(item->data(Qt::UserRole)); + setPreviewMessages(info.stylePath, ui.privatePreview); + + QString author = info.authorName; + if (info.authorEmail.isEmpty() == false) { + author += " (" + info.authorEmail + ")"; + } + ui.privateAuthor->setText(author); + ui.privateDescription->setText(info.styleDescription); + } else { + ui.privatePreview->clear(); + ui.privateAuthor->clear(); + ui.privateDescription->clear(); + } +} + +void ChatPage::on_historyList_currentRowChanged(int currentRow) +{ + if (currentRow != -1) { + QListWidgetItem *item = ui.historyList->item(currentRow); + ChatStyleInfo info = qVariantValue(item->data(Qt::UserRole)); + setPreviewMessages(info.stylePath, ui.historyPreview); + + QString author = info.authorName; + if (info.authorEmail.isEmpty() == false) { + author += " (" + info.authorEmail + ")"; + } + ui.historyAuthor->setText(author); + ui.historyDescription->setText(info.styleDescription); + } else { + ui.historyPreview->clear(); + ui.historyAuthor->clear(); + ui.historyDescription->clear(); + } +} diff --git a/retroshare-gui/src/gui/settings/ChatPage.h b/retroshare-gui/src/gui/settings/ChatPage.h index 7bdf6a21a..ba253a879 100644 --- a/retroshare-gui/src/gui/settings/ChatPage.h +++ b/retroshare-gui/src/gui/settings/ChatPage.h @@ -48,9 +48,17 @@ class ChatPage : public ConfigPage private slots: void on_pushButtonChangeChatFont_clicked(); + void on_publicList_currentRowChanged(int currentRow); + void on_privateList_currentRowChanged(int currentRow); + void on_historyList_currentRowChanged(int currentRow); private: void closeEvent (QCloseEvent * event); + void setPreviewMessages(QString &stylePath, QTextBrowser *textBrowser); + + QString publicStylePath; + QString privateStylePath; + QString historyStylePath; /** Qt Designer generated object */ Ui::ChatPage ui; diff --git a/retroshare-gui/src/gui/settings/ChatPage.ui b/retroshare-gui/src/gui/settings/ChatPage.ui index c2b2bf7b8..257cc3e59 100644 --- a/retroshare-gui/src/gui/settings/ChatPage.ui +++ b/retroshare-gui/src/gui/settings/ChatPage.ui @@ -1,641 +1,988 @@ - - - ChatPage - - - - 0 - 0 - 426 - 256 - - - - - 0 - 0 - - - - - - - - - 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 - - - - - - Chat Settings - - - - - - Enable Emoticons Privat Chat - - - true - - - - - - - - 16777215 - 16777215 - - - - - - - Chat Font - - - - 2 - - - 0 - - - 0 - - - 0 - - - 2 - - - - - Change Chat Font - - - - - - - - 0 - 0 - - - - Chat Font: - - - - - - - Font Preview - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - Enable Emoticons Group Chat - - - true - - - - - - - Enable GroupChat History - - - true - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - Send message with Ctrl+Return - - - - - - - - - - - - - + + + ChatPage + + + + 0 + 0 + 426 + 256 + + + + + 0 + 0 + + + + + + + + + 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 + + + + General + + + + + + + 0 + 0 + + + + Chat Settings + + + + + + Enable Emoticons Privat Chat + + + true + + + + + + + + 16777215 + 16777215 + + + + + + + Chat Font + + + + 2 + + + 0 + + + 0 + + + 0 + + + 2 + + + + + Change Chat Font + + + + + + + + 0 + 0 + + + + Chat Font: + + + + + + + Font Preview + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + Enable Emoticons Group Chat + + + true + + + + + + + Enable GroupChat History + + + true + + + + + + + Send message with Ctrl+Return + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + Style + + + + + + QTabWidget::North + + + 0 + + + + Public + + + + + + + + + 0 + 0 + + + + + 150 + 16777215 + + + + + + + + + 0 + 0 + + + + + + + + + + + + QLayout::SetFixedSize + + + + + + 0 + 0 + + + + Author: + + + + + + + + 0 + 0 + + + + Description: + + + + + + + + + + + + 0 + 0 + + + + Author + + + + + + + + 0 + 0 + + + + Description + + + + + + + + + + + + Private + + + + + + + + + 0 + 0 + + + + + 150 + 16777215 + + + + + + + + + 0 + 0 + + + + + + + + + + + + QLayout::SetFixedSize + + + + + + 0 + 0 + + + + Author: + + + + + + + + 0 + 0 + + + + Description: + + + + + + + + + + + + 0 + 0 + + + + Author + + + + + + + + 0 + 0 + + + + Description + + + + + + + + + + + + History + + + + + + + + + 0 + 0 + + + + + 150 + 16777215 + + + + + + + + + 0 + 0 + + + + + + + + + + + + QLayout::SetFixedSize + + + + + + 0 + 0 + + + + Author: + + + + + + + + 0 + 0 + + + + Description: + + + + + + + + + + + + 0 + 0 + + + + Author + + + + + + + + 0 + 0 + + + + Description + + + + + + + + + + + + + + + + + + + + diff --git a/retroshare-gui/src/gui/settings/rsharesettings.cpp b/retroshare-gui/src/gui/settings/rsharesettings.cpp index 994b665ab..5f033d2cc 100644 --- a/retroshare-gui/src/gui/settings/rsharesettings.cpp +++ b/retroshare-gui/src/gui/settings/rsharesettings.cpp @@ -299,6 +299,36 @@ void RshareSettings::setChatSendMessageWithCtrlReturn(bool bValue) setValueToGroup("Chat", "SendMessageWithCtrlReturn", bValue); } +void RshareSettings::getPublicChatStyle(QString &stylePath) +{ + stylePath = valueFromGroup("Chat", "StylePublic", ":/qss/chat/public").toString(); +} + +void RshareSettings::setPublicChatStyle(QString stylePath) +{ + setValueToGroup("Chat", "StylePublic", stylePath); +} + +void RshareSettings::getPrivateChatStyle(QString &stylePath) +{ + stylePath = valueFromGroup("Chat", "StylePrivate", ":/qss/chat/private").toString(); +} + +void RshareSettings::setPrivateChatStyle(QString stylePath) +{ + setValueToGroup("Chat", "StylePrivate", stylePath); +} + +void RshareSettings::getHistoryChatStyle(QString &stylePath) +{ + stylePath = valueFromGroup("Chat", "StyleHistory", ":/qss/chat/history").toString(); +} + +void RshareSettings::setHistoryChatStyle(QString stylePath) +{ + setValueToGroup("Chat", "StyleHistory", stylePath); +} + /** Returns true if RetroShare is set to run on system boot. */ bool RshareSettings::runRetroshareOnBoot() diff --git a/retroshare-gui/src/gui/settings/rsharesettings.h b/retroshare-gui/src/gui/settings/rsharesettings.h index 029846a83..a1e1328bc 100644 --- a/retroshare-gui/src/gui/settings/rsharesettings.h +++ b/retroshare-gui/src/gui/settings/rsharesettings.h @@ -83,7 +83,6 @@ public: /** set the chat avatar. Returns a null image if no avatar is saved. */ void setChatAvatar(const QImage&) ; - /* Get the destination log file. */ QString getLogFile(); @@ -122,7 +121,17 @@ public: bool getChatSendMessageWithCtrlReturn(); void setChatSendMessageWithCtrlReturn(bool bValue); - + + /* chat styles */ + void getPublicChatStyle(QString &stylePath); + void setPublicChatStyle(QString stylePath); + + void getPrivateChatStyle(QString &stylePath); + void setPrivateChatStyle(QString stylePath); + + void getHistoryChatStyle(QString &stylePath); + void setHistoryChatStyle(QString stylePath); + //! Save placement, state and size information of a window. void saveWidgetInformation(QWidget *widget);
%message%