From a7f143e0dc9ebcdc90242c6ca900b5fa87459b8d Mon Sep 17 00:00:00 2001 From: defnax Date: Mon, 4 Jan 2010 14:29:49 +0000 Subject: [PATCH] Added Display smiley icon in Forum Posts git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1972 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- retroshare-gui/src/gui/ForumsDialog.cpp | 90 +++++++++++++++++++++++-- retroshare-gui/src/gui/ForumsDialog.h | 8 ++- 2 files changed, 89 insertions(+), 9 deletions(-) diff --git a/retroshare-gui/src/gui/ForumsDialog.cpp b/retroshare-gui/src/gui/ForumsDialog.cpp index 552b73e64..b6487f95f 100644 --- a/retroshare-gui/src/gui/ForumsDialog.cpp +++ b/retroshare-gui/src/gui/ForumsDialog.cpp @@ -19,7 +19,6 @@ * Boston, MA 02110-1301, USA. ****************************************************************/ - #include "ForumsDialog.h" #include "gui/forums/CreateForum.h" #include "gui/forums/CreateForumMsg.h" @@ -29,21 +28,25 @@ #include "rsiface/rspeers.h" #include "rsiface/rsmsgs.h" #include "rsiface/rsforums.h" + #include #include #include -#include #include -#include +#include +#include +#include +#include #include #include +#include #include #include -#include #include #include #include +#include /* Images for context menu icons */ #define IMAGE_MESSAGE ":/images/folder-draft.png" @@ -96,8 +99,6 @@ ForumsDialog::ForumsDialog(QWidget *parent) timer->connect(timer, SIGNAL(timeout()), this, SLOT(checkUpdate())); timer->start(1000); - - /* Set header resize modes and initial section sizes */ QHeaderView * ftheader = ui.forumTreeWidget->header () ; ftheader->setResizeMode (0, QHeaderView::Interactive); @@ -115,6 +116,8 @@ ForumsDialog::ForumsDialog(QWidget *parent) mForumNameFont = QFont("Times", 12, QFont::Bold); ui.forumName->setFont(mForumNameFont); ui.threadTitle->setFont(mForumNameFont); + + loadForumEmoticons(); /* Hide platform specific features */ @@ -799,8 +802,19 @@ void ForumsDialog::insertPost() ui.threadTitle->setText(""); return; } + + QString extraTxt; + extraTxt += QString::fromStdWString(msg.msg); + + QHashIterator i(smileys); + while(i.hasNext()) + { + i.next(); + foreach(QString code, i.key().split("|")) + extraTxt.replace(code, ""); + } - ui.postText->setHtml(QString::fromStdWString(msg.msg)); + ui.postText->setHtml(extraTxt); ui.threadTitle->setText(QString::fromStdWString(title.title)); } @@ -924,4 +938,66 @@ void ForumsDialog::showForumDetails() } +void ForumsDialog::loadForumEmoticons() +{ + QString sm_codes; + #if defined(Q_OS_WIN32) + QFile sm_file(QApplication::applicationDirPath() + "/emoticons/emotes.acs"); + #else + QFile sm_file(QString(":/smileys/emotes.acs")); + #endif + if(!sm_file.open(QIODevice::ReadOnly)) + { + std::cerr << "Could not open resouce file :/emoticons/emotes.acs" << std::endl ; + return ; + } + sm_codes = sm_file.readAll(); + sm_file.close(); + sm_codes.remove("\n"); + sm_codes.remove("\r"); + int i = 0; + QString smcode; + QString smfile; + while(sm_codes[i] != '{') + { + i++; + + } + while (i < sm_codes.length()-2) + { + smcode = ""; + smfile = ""; + while(sm_codes[i] != '\"') + { + i++; + } + i++; + while (sm_codes[i] != '\"') + { + smcode += sm_codes[i]; + i++; + + } + i++; + + while(sm_codes[i] != '\"') + { + i++; + } + i++; + while(sm_codes[i] != '\"' && sm_codes[i+1] != ';') + { + smfile += sm_codes[i]; + i++; + } + i++; + if(!smcode.isEmpty() && !smfile.isEmpty()) + #if defined(Q_OS_WIN32) + smileys.insert(smcode, smfile); + #else + smileys.insert(smcode, ":/"+smfile); + #endif + } +} + diff --git a/retroshare-gui/src/gui/ForumsDialog.h b/retroshare-gui/src/gui/ForumsDialog.h index 04a3ae204..5c5b3c5a6 100644 --- a/retroshare-gui/src/gui/ForumsDialog.h +++ b/retroshare-gui/src/gui/ForumsDialog.h @@ -34,10 +34,12 @@ public: void insertForums(); void insertPost(); + + void loadForumEmoticons(); private slots: - void insertThreads(); + void insertThreads(); /** Create the context popup menu and it's submenus */ void forumListCustomPopupMenu( QPoint point ); void threadListCustomPopupMenu( QPoint point ); @@ -72,7 +74,7 @@ private slots: void unsubscribeToForum(); void showForumDetails(); - + private: void forumSubscribe(bool subscribe); @@ -84,6 +86,8 @@ private: QFont mForumNameFont; QFont itemFont; + + QHash smileys; /** Qt Designer generated object */ Ui::ForumsDialog ui;