From 6a9dfed408446dc0e76fb7bf4c0202a4bf2e0275 Mon Sep 17 00:00:00 2001 From: thunder2 Date: Tue, 24 Sep 2013 20:19:21 +0000 Subject: [PATCH] Added new action "Load images always for this message" to image blocking. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6760 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/retroshare/rsforums.h | 7 +- libretroshare/src/retroshare/rsmsgs.h | 2 + libretroshare/src/rsserver/p3msgs.cc | 5 + libretroshare/src/rsserver/p3msgs.h | 1 + libretroshare/src/serialiser/rsmsgitems.h | 1 + libretroshare/src/services/p3forums.cc | 2 +- libretroshare/src/services/p3msgservice.cc | 11 ++ retroshare-gui/src/gui/ForumsDialog.cpp | 25 +++- retroshare-gui/src/gui/ForumsDialog.h | 2 + retroshare-gui/src/gui/ForumsDialog.ui | 111 +++++++++--------- .../src/gui/common/RSImageBlockWidget.cpp | 50 ++++++++ .../src/gui/common/RSImageBlockWidget.h | 23 ++++ .../src/gui/common/RSImageBlockWidget.ui | 6 +- retroshare-gui/src/gui/msgs/MessageWidget.cpp | 12 +- retroshare-gui/src/gui/msgs/MessageWidget.h | 2 + retroshare-gui/src/lang/retroshare_en.ts | 92 ++++++++++----- 16 files changed, 255 insertions(+), 97 deletions(-) diff --git a/libretroshare/src/retroshare/rsforums.h b/libretroshare/src/retroshare/rsforums.h index 74065805e..06c835ba4 100644 --- a/libretroshare/src/retroshare/rsforums.h +++ b/libretroshare/src/retroshare/rsforums.h @@ -34,9 +34,10 @@ #include "rstypes.h" #include "rsdistrib.h" /* For FLAGS */ -#define FORUM_MSG_STATUS_MASK 0x000f -#define FORUM_MSG_STATUS_READ 0x0001 -#define FORUM_MSG_STATUS_UNREAD_BY_USER 0x0002 +#define FORUM_MSG_STATUS_MASK 0x000f +#define FORUM_MSG_STATUS_READ 0x0001 +#define FORUM_MSG_STATUS_UNREAD_BY_USER 0x0002 +#define FORUM_MSG_STATUS_LOAD_EMBEDDED_IMAGES 0x0004 class ForumInfo { diff --git a/libretroshare/src/retroshare/rsmsgs.h b/libretroshare/src/retroshare/rsmsgs.h index e2c195984..a7193cdb9 100644 --- a/libretroshare/src/retroshare/rsmsgs.h +++ b/libretroshare/src/retroshare/rsmsgs.h @@ -61,6 +61,7 @@ #define RS_MSG_ENCRYPTED 0x1000 /* message is encrypted */ #define RS_MSG_SIGNATURE_CHECKS 0x2000 /* message was signed, and signature checked */ #define RS_MSG_SIGNED 0x4000 /* message was signed and signature didn't check */ +#define RS_MSG_LOAD_EMBEDDED_IMAGES 0x8000 /* load embedded images */ #define RS_CHAT_LOBBY_EVENT_PEER_LEFT 0x01 #define RS_CHAT_LOBBY_EVENT_PEER_STATUS 0x02 @@ -264,6 +265,7 @@ virtual bool MessageRead(const std::string &mid, bool unreadByUser) = 0; virtual bool MessageReplied(const std::string &mid, bool replied) = 0; virtual bool MessageForwarded(const std::string &mid, bool forwarded) = 0; virtual bool MessageStar(const std::string &mid, bool mark) = 0; +virtual bool MessageLoadEmbeddedImages(const std::string &mid, bool load) = 0; /* message tagging */ diff --git a/libretroshare/src/rsserver/p3msgs.cc b/libretroshare/src/rsserver/p3msgs.cc index 58613ac26..c6aad41be 100644 --- a/libretroshare/src/rsserver/p3msgs.cc +++ b/libretroshare/src/rsserver/p3msgs.cc @@ -169,6 +169,11 @@ bool p3Msgs::MessageForwarded(const std::string &mid, bool forwarded) return mMsgSrv->setMsgFlag(mid, forwarded ? RS_MSG_FLAGS_FORWARDED : 0, RS_MSG_FLAGS_FORWARDED); } +bool p3Msgs::MessageLoadEmbeddedImages(const std::string &mid, bool load) +{ + return mMsgSrv->setMsgFlag(mid, load ? RS_MSG_FLAGS_LOAD_EMBEDDED_IMAGES : 0, RS_MSG_FLAGS_LOAD_EMBEDDED_IMAGES); +} + bool p3Msgs::getMessageTagTypes(MsgTagType& tags) { return mMsgSrv->getMessageTagTypes(tags); diff --git a/libretroshare/src/rsserver/p3msgs.h b/libretroshare/src/rsserver/p3msgs.h index c42888a4e..6ccd80a1d 100644 --- a/libretroshare/src/rsserver/p3msgs.h +++ b/libretroshare/src/rsserver/p3msgs.h @@ -67,6 +67,7 @@ class p3Msgs: public RsMsgs virtual bool MessageReplied(const std::string &mid, bool replied); virtual bool MessageForwarded(const std::string &mid, bool forwarded); virtual bool MessageStar(const std::string &mid, bool star); + virtual bool MessageLoadEmbeddedImages(const std::string &mid, bool load); virtual bool getMsgParentId(const std::string &msgId, std::string &msgParentId); virtual bool getMessageTagTypes(MsgTagType& tags); diff --git a/libretroshare/src/serialiser/rsmsgitems.h b/libretroshare/src/serialiser/rsmsgitems.h index 7c9704c1f..d0616b393 100644 --- a/libretroshare/src/serialiser/rsmsgitems.h +++ b/libretroshare/src/serialiser/rsmsgitems.h @@ -431,6 +431,7 @@ const uint32_t RS_MSG_FLAGS_ENCRYPTED = 0x00004000; const uint32_t RS_MSG_FLAGS_DISTANT = 0x00008000; const uint32_t RS_MSG_FLAGS_SIGNATURE_CHECKS = 0x00010000; const uint32_t RS_MSG_FLAGS_SIGNED = 0x00020000; +const uint32_t RS_MSG_FLAGS_LOAD_EMBEDDED_IMAGES = 0x00040000; class RsMessageItem: public RsItem { diff --git a/libretroshare/src/services/p3forums.cc b/libretroshare/src/services/p3forums.cc index 12dcee700..d83e498bb 100644 --- a/libretroshare/src/services/p3forums.cc +++ b/libretroshare/src/services/p3forums.cc @@ -362,7 +362,7 @@ bool p3Forums::ForumMessageSend(ForumMsgInfo &info) // return id info.msgId = mId; - return setMessageStatus(info.forumId, mId, FORUM_MSG_STATUS_READ, FORUM_MSG_STATUS_MASK); + return setMessageStatus(info.forumId, mId, FORUM_MSG_STATUS_READ | FORUM_MSG_STATUS_LOAD_EMBEDDED_IMAGES, FORUM_MSG_STATUS_MASK); } bool p3Forums::setMessageStatus(const std::string& fId,const std::string& mId,const uint32_t status, const uint32_t statusMask) diff --git a/libretroshare/src/services/p3msgservice.cc b/libretroshare/src/services/p3msgservice.cc index 9f9fac2ef..73be85bb9 100644 --- a/libretroshare/src/services/p3msgservice.cc +++ b/libretroshare/src/services/p3msgservice.cc @@ -1539,6 +1539,10 @@ void p3MsgService::initRsMI(RsMsgItem *msg, MessageInfo &mi) { mi.msgflags |= RS_MSG_FRIEND_RECOMMENDATION; } + if (msg->msgFlags & RS_MSG_FLAGS_LOAD_EMBEDDED_IMAGES) + { + mi.msgflags |= RS_MSG_LOAD_EMBEDDED_IMAGES; + } mi.ts = msg->sendTime; mi.srcId = msg->PeerId(); @@ -1652,6 +1656,10 @@ void p3MsgService::initRsMIS(RsMsgItem *msg, MsgInfoSummary &mis) { mis.msgflags |= RS_MSG_FRIEND_RECOMMENDATION; } + if (msg->msgFlags & RS_MSG_FLAGS_LOAD_EMBEDDED_IMAGES) + { + mis.msgflags |= RS_MSG_LOAD_EMBEDDED_IMAGES; + } mis.srcId = msg->PeerId(); { @@ -1726,6 +1734,9 @@ RsMsgItem *p3MsgService::initMIRsMsg(MessageInfo &info, const std::string &to) if (info.msgflags & RS_MSG_SIGNED) msg->msgFlags |= RS_MSG_FLAGS_SIGNED; + /* load embedded images from own messages */ + msg->msgFlags |= RS_MSG_FLAGS_LOAD_EMBEDDED_IMAGES; + // See if we need to encrypt this message. If so, we replace the msg text // by the whole message serialized and binary encrypted, so as to obfuscate // all its content. diff --git a/retroshare-gui/src/gui/ForumsDialog.cpp b/retroshare-gui/src/gui/ForumsDialog.cpp index 8ff18ffd8..c8f9f16a8 100644 --- a/retroshare-gui/src/gui/ForumsDialog.cpp +++ b/retroshare-gui/src/gui/ForumsDialog.cpp @@ -139,6 +139,7 @@ ForumsDialog::ForumsDialog(QWidget *parent) connect(NotifyQt::getInstance(), SIGNAL(forumMsgReadSatusChanged(QString,QString,int)), this, SLOT(forumMsgReadSatusChanged(QString,QString,int))); + ui.imageBlockWidget->addButtonAction(tr("Load images always for this message"), this, SLOT(loadImagesAlways()), true); ui.postText->setImageBlockWidget(ui.imageBlockWidget); /* Set initial size the splitter */ @@ -481,11 +482,11 @@ void ForumsDialog::togglethreadview() void ForumsDialog::togglethreadview_internal() { if (ui.expandButton->isChecked()) { - ui.postText->setVisible(true); + ui.postFrame->setVisible(true); ui.expandButton->setIcon(QIcon(QString(":/images/edit_remove24.png"))); ui.expandButton->setToolTip(tr("Hide")); } else { - ui.postText->setVisible(false); + ui.postFrame->setVisible(false); ui.expandButton->setIcon(QIcon(QString(":/images/edit_add24.png"))); ui.expandButton->setToolTip(tr("Expand")); } @@ -1210,7 +1211,16 @@ void ForumsDialog::insertPost() QString extraTxt = RsHtml().formatText(ui.postText->document(), messageFromInfo(msg), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS); - ui.postText->resetImagesStatus(Settings->getForumLoadEmbeddedImages()); + bool loadEmbeddedImages = Settings->getForumLoadEmbeddedImages(); + if (!loadEmbeddedImages) { + uint32_t status = 0; + rsForums->getMessageStatus(mCurrForumId, mCurrThreadId, status); + if (status & FORUM_MSG_STATUS_LOAD_EMBEDDED_IMAGES) { + loadEmbeddedImages = true; + } + } + + ui.postText->resetImagesStatus(loadEmbeddedImages); ui.postText->setHtml(extraTxt); ui.threadTitle->setText(titleFromInfo(msg)); } @@ -2119,3 +2129,12 @@ void ForumsFillThread::run() std::cerr << "ForumsFillThread::run() stopped: " << (wasStopped() ? "yes" : "no") << std::endl; #endif } + +void ForumsDialog::loadImagesAlways() +{ + if (mCurrForumId.empty() || mCurrThreadId.empty()) { + return; + } + + rsForums->setMessageStatus(mCurrForumId, mCurrThreadId, FORUM_MSG_STATUS_LOAD_EMBEDDED_IMAGES, FORUM_MSG_STATUS_LOAD_EMBEDDED_IMAGES); +} diff --git a/retroshare-gui/src/gui/ForumsDialog.h b/retroshare-gui/src/gui/ForumsDialog.h index ed3c21f98..eb4ab043d 100644 --- a/retroshare-gui/src/gui/ForumsDialog.h +++ b/retroshare-gui/src/gui/ForumsDialog.h @@ -128,6 +128,8 @@ private slots: void shareKey(); + void loadImagesAlways(); + private: void insertForums(); void insertThreads(); diff --git a/retroshare-gui/src/gui/ForumsDialog.ui b/retroshare-gui/src/gui/ForumsDialog.ui index 1b5b86617..ed4772355 100644 --- a/retroshare-gui/src/gui/ForumsDialog.ui +++ b/retroshare-gui/src/gui/ForumsDialog.ui @@ -113,8 +113,8 @@ Qt::Vertical - - + + @@ -200,7 +200,7 @@ - + @@ -278,7 +278,54 @@ - + + + + + 9 + + + + Qt::CustomContextMenu + + + true + + + true + + + + Title + + + + + + + + + :/images/message-state-header.png:/images/message-state-header.png + + + + + Date + + + + + Author + + + + + Signed + + + + + @@ -311,7 +358,7 @@ - + @@ -487,60 +534,16 @@ - - - - - 9 - - - - Qt::CustomContextMenu - - - true - - - true - - - - Title - - - - - - - - - :/images/message-state-header.png:/images/message-state-header.png - - - - - Date - - - - - Author - - - - - Signed - - - - - - + + 2 + + 0 + diff --git a/retroshare-gui/src/gui/common/RSImageBlockWidget.cpp b/retroshare-gui/src/gui/common/RSImageBlockWidget.cpp index 8a3c728ee..98f6193c3 100644 --- a/retroshare-gui/src/gui/common/RSImageBlockWidget.cpp +++ b/retroshare-gui/src/gui/common/RSImageBlockWidget.cpp @@ -1,3 +1,26 @@ +/**************************************************************** + * RetroShare is distributed under the following license: + * + * Copyright (C) 2013 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 "RSImageBlockWidget.h" #include "ui_RSImageBlockWidget.h" @@ -14,3 +37,30 @@ RSImageBlockWidget::~RSImageBlockWidget() { delete ui; } + +void RSImageBlockWidget::addButtonAction(const QString &text, const QObject *receiver, const char *member, bool standardAction) +{ + QMenu *menu = ui->loadImagesButton->menu(); + if (!menu) { + /* Set popup mode */ + ui->loadImagesButton->setPopupMode(QToolButton::MenuButtonPopup); + ui->loadImagesButton->setIcon(ui->loadImagesButton->icon()); // Sometimes Qt doesn't recalculate sizeHint + + /* Create popup menu */ + menu = new QMenu; + ui->loadImagesButton->setMenu(menu); + + /* Add 'click' action as action */ + QAction *action = menu->addAction(ui->loadImagesButton->text(), this, SIGNAL(showImages())); + menu->setDefaultAction(action); + } + + /* Add new action */ + QAction *action = menu->addAction(text, receiver, member); + ui->loadImagesButton->addAction(action); + + if (standardAction) { + /* Connect standard action */ + connect(action, SIGNAL(triggered()), this, SIGNAL(showImages())); + } +} diff --git a/retroshare-gui/src/gui/common/RSImageBlockWidget.h b/retroshare-gui/src/gui/common/RSImageBlockWidget.h index 4455e7e74..f4dfffbfc 100644 --- a/retroshare-gui/src/gui/common/RSImageBlockWidget.h +++ b/retroshare-gui/src/gui/common/RSImageBlockWidget.h @@ -1,3 +1,24 @@ +/**************************************************************** + * RetroShare is distributed under the following license: + * + * Copyright (C) 2013 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 RSIMAGEBLOCKWIDGET_H #define RSIMAGEBLOCKWIDGET_H @@ -15,6 +36,8 @@ public: explicit RSImageBlockWidget(QWidget *parent = 0); ~RSImageBlockWidget(); + void addButtonAction(const QString &text, const QObject *receiver, const char *member, bool standardAction); + signals: void showImages(); diff --git a/retroshare-gui/src/gui/common/RSImageBlockWidget.ui b/retroshare-gui/src/gui/common/RSImageBlockWidget.ui index f33a346d3..ed8dd2430 100644 --- a/retroshare-gui/src/gui/common/RSImageBlockWidget.ui +++ b/retroshare-gui/src/gui/common/RSImageBlockWidget.ui @@ -7,7 +7,7 @@ 0 0 476 - 37 + 34 @@ -110,14 +110,14 @@ - 162 + 40 20 - + Load images diff --git a/retroshare-gui/src/gui/msgs/MessageWidget.cpp b/retroshare-gui/src/gui/msgs/MessageWidget.cpp index 84361342e..5a07dd075 100644 --- a/retroshare-gui/src/gui/msgs/MessageWidget.cpp +++ b/retroshare-gui/src/gui/msgs/MessageWidget.cpp @@ -135,6 +135,7 @@ MessageWidget::MessageWidget(bool controlled, QWidget *parent, Qt::WFlags flags) connect(NotifyQt::getInstance(), SIGNAL(messagesTagsChanged()), this, SLOT(messagesTagsChanged())); connect(NotifyQt::getInstance(), SIGNAL(messagesChanged()), this, SLOT(messagesChanged())); + ui.imageBlockWidget->addButtonAction(tr("Load images always for this message"), this, SLOT(loadImagesAlways()), true); ui.msgText->setImageBlockWidget(ui.imageBlockWidget); /* hide the Tree +/- */ @@ -560,7 +561,7 @@ void MessageWidget::fill(const std::string &msgId) ui.subjectText->setText(QString::fromStdWString(msgInfo.title)); text = RsHtmlMsg(msgInfo.msgflags).formatText(ui.msgText->document(), QString::fromStdWString(msgInfo.msg), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS | RSHTML_FORMATTEXT_REPLACE_LINKS); - ui.msgText->resetImagesStatus(Settings->getMsgLoadEmbeddedImages()); + ui.msgText->resetImagesStatus(Settings->getMsgLoadEmbeddedImages() || (msgInfo.msgflags & RS_MSG_LOAD_EMBEDDED_IMAGES)); ui.msgText->setHtml(text); ui.filesText->setText(QString("(%1 %2)").arg(msgInfo.count).arg(msgInfo.count == 1 ? tr("File") : tr("Files"))); @@ -713,3 +714,12 @@ void MessageWidget::anchorClicked(const QUrl &url) links.append(link); RetroShareLink::process(links); } + +void MessageWidget::loadImagesAlways() +{ + if (currMsgId.empty()) { + return; + } + + rsMsgs->MessageLoadEmbeddedImages(currMsgId, true); +} diff --git a/retroshare-gui/src/gui/msgs/MessageWidget.h b/retroshare-gui/src/gui/msgs/MessageWidget.h index 39b87ed1c..c36d1e9b3 100644 --- a/retroshare-gui/src/gui/msgs/MessageWidget.h +++ b/retroshare-gui/src/gui/msgs/MessageWidget.h @@ -78,6 +78,8 @@ private slots: void anchorClicked(const QUrl &url); + void loadImagesAlways(); + private: void clearTagLabels(); void showTagLabels(); diff --git a/retroshare-gui/src/lang/retroshare_en.ts b/retroshare-gui/src/lang/retroshare_en.ts index 5e893a828..36dcde342 100644 --- a/retroshare-gui/src/lang/retroshare_en.ts +++ b/retroshare-gui/src/lang/retroshare_en.ts @@ -1343,22 +1343,6 @@ Please choose one of it to chat with. Selected lobby info - - Lobby name: - - - - Lobby Id: - - - - Topic: - - - - Type: - - Private @@ -1367,22 +1351,10 @@ Please choose one of it to chat with. Public - - Peers: - - You're not subscribed to this lobby; Double click-it to enter and chat. - - No lobby selected. - -Select lobbies at left to show details. - -Double click lobbies to enter and chat. - - Invitation to chat lobby @@ -1435,6 +1407,36 @@ Double click lobbies to enter and chat. No + + Lobby Name: + + + + Lobby Id: + + + + Topic: + + + + Type: + + + + Peers: + + + + TextLabel + + + + No lobby selected. +Select lobbies at left to show details. +Double click lobbies to enter and chat. + + ChatMsgItem @@ -5671,6 +5673,10 @@ p, li { white-space: pre-wrap; } <h1><img width="32" src=":/images/64px_help.png">&nbsp;&nbsp;Forums</h1> <p>Retroshare Forums look like internet forums, but they work in a decentralized way: You see forums your friends are subscribed to, and you forward subscribed forums to your friends. This automatically promotes interesting forums in the network.</p> <p>Forums are either Authenticated (<img src=":/images/konv_message2.png" width="12"/>) in which case you need to cryptographically sign your posts, or anonymous (<img src=":/images/konversation.png" width="12"/>). The former class is more resistant to spamming.</p> <p>Forum posts propagate from friend to friend using small cache file exchanges. When you first connect to a new friend, it's likely you will receive many such cache files, and new forums will appear. </p> + + Load images always for this message + + ForumsFillThread @@ -6269,10 +6275,6 @@ anonymous, you can use a fake email. Location - - Put a meaningful location. ex : home, laptop, etc. This field will be used to differentiate different installations with the same identity (PGP key). - - Create new identity @@ -6423,6 +6425,28 @@ Fill in your PGP password when asked, to sign your new key. Failed to Generate your new Certificate, maybe PGP password is wrong! + + Password (check) + + + + <html><head/><body><p align="justify">Before proceeding, move your mouse around to help Retroshare collect as much randomness as possible. Filling the progressbar to 20% is needed, 100% is advised.</p></body></html> + + + + [Required] Type the same password again here. + + + + Put a meaningful location. ex : home, laptop, etc. +This field will be used to differentiate different installations with +the same identity (PGP key). + + + + Passwords to not match + + GeneralPage @@ -9075,6 +9099,10 @@ Do you want to save message ? HTML-Files (*.htm *.html);;All Files (*) + + Load images always for this message + + MessageWindow