From 340a313fea36868846c9a5cbc5efaa1aed6be232 Mon Sep 17 00:00:00 2001 From: thunder2 Date: Sat, 11 Feb 2012 13:42:42 +0000 Subject: [PATCH] Fixed bug when the user clicks on a link without http:// in a QTextBrowser. This link was opened directly in RetroShare. Show clickable links in the channel feed message. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4923 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- retroshare-gui/src/RetroShare.pro | 2 ++ retroshare-gui/src/gui/ForumsDialog.ui | 13 ++++++------- retroshare-gui/src/gui/FriendsDialog.ui | 13 ++++++------- retroshare-gui/src/gui/chat/ChatWidget.ui | 13 ++++++------- retroshare-gui/src/gui/chat/HandleRichText.h | 2 +- .../src/gui/common/LinkTextBrowser.cpp | 19 +++++++++++++++++++ .../src/gui/common/LinkTextBrowser.h | 17 +++++++++++++++++ .../src/gui/connect/ConfCertDialog.ui | 16 +++++++--------- retroshare-gui/src/gui/feeds/ChanMsgItem.cpp | 5 +++-- retroshare-gui/src/gui/feeds/ChanMsgItem.ui | 3 +++ retroshare-gui/src/gui/msgs/MessageWidget.ui | 15 ++++++++------- 11 files changed, 78 insertions(+), 40 deletions(-) create mode 100644 retroshare-gui/src/gui/common/LinkTextBrowser.cpp create mode 100644 retroshare-gui/src/gui/common/LinkTextBrowser.h diff --git a/retroshare-gui/src/RetroShare.pro b/retroshare-gui/src/RetroShare.pro index a3d265950..3f1edc905 100644 --- a/retroshare-gui/src/RetroShare.pro +++ b/retroshare-gui/src/RetroShare.pro @@ -339,6 +339,7 @@ HEADERS += rshare.h \ gui/common/FriendList.h \ gui/common/FriendSelectionWidget.h \ gui/common/HashBox.h \ + gui/common/LinkTextBrowser.h \ gui/style/RSStyle.h \ gui/style/StyleDialog.h \ gui/MessagesDialog.h \ @@ -584,6 +585,7 @@ SOURCES += main.cpp \ gui/common/FriendList.cpp \ gui/common/FriendSelectionWidget.cpp \ gui/common/HashBox.cpp \ + gui/common/LinkTextBrowser.cpp \ gui/style/RSStyle.cpp \ gui/style/StyleDialog.cpp \ gui/settings/configpage.cpp \ diff --git a/retroshare-gui/src/gui/ForumsDialog.ui b/retroshare-gui/src/gui/ForumsDialog.ui index 14dc4ab0c..3409be113 100644 --- a/retroshare-gui/src/gui/ForumsDialog.ui +++ b/retroshare-gui/src/gui/ForumsDialog.ui @@ -1250,7 +1250,7 @@ border-image: url(:/images/closepressed.png) - + 0 @@ -1262,12 +1262,6 @@ border-image: url(:/images/closepressed.png) 9 - - true - - - true - @@ -1285,6 +1279,11 @@ border-image: url(:/images/closepressed.png) + + LinkTextBrowser + QTextBrowser +
gui/common/LinkTextBrowser.h
+
GroupTreeWidget QWidget diff --git a/retroshare-gui/src/gui/FriendsDialog.ui b/retroshare-gui/src/gui/FriendsDialog.ui index 9ba49dc8a..aba71b9fd 100644 --- a/retroshare-gui/src/gui/FriendsDialog.ui +++ b/retroshare-gui/src/gui/FriendsDialog.ui @@ -1218,7 +1218,7 @@ border: 1px solid #CCCCCC;} false - + 0 @@ -1238,12 +1238,6 @@ background: white;} true - - true - - - true - @@ -1477,6 +1471,11 @@ background: white;}
gui/common/FriendList.h
1
+ + LinkTextBrowser + QTextBrowser +
gui/common/LinkTextBrowser.h
+
diff --git a/retroshare-gui/src/gui/chat/ChatWidget.ui b/retroshare-gui/src/gui/chat/ChatWidget.ui index 2a8cdac17..e19a9ce68 100644 --- a/retroshare-gui/src/gui/chat/ChatWidget.ui +++ b/retroshare-gui/src/gui/chat/ChatWidget.ui @@ -173,7 +173,7 @@ border-image: url(:/images/closepressed.png) - + 0 @@ -191,12 +191,6 @@ border-image: url(:/images/closepressed.png) border-radius: 6px; background: white;} - - true - - - true - @@ -665,6 +659,11 @@ border: 1px solid #CCCCCC;
gui/common/HashBox.h
1 + + LinkTextBrowser + QTextBrowser +
gui/common/LinkTextBrowser.h
+
diff --git a/retroshare-gui/src/gui/chat/HandleRichText.h b/retroshare-gui/src/gui/chat/HandleRichText.h index 13e6b1f2f..906fb3b77 100644 --- a/retroshare-gui/src/gui/chat/HandleRichText.h +++ b/retroshare-gui/src/gui/chat/HandleRichText.h @@ -80,7 +80,7 @@ public: EmbedInHtmlAhref() : EmbedInHtml(Ahref) { - myRE.setPattern("(\\bretroshare://[^\\s]*)|(\\bhttps?://[^\\s]*)|(\\bwww\\.[^\\s]*)"); + myRE.setPattern("(\\bretroshare://[^\\s]*)|(\\bhttps?://[^\\s]*)|(\\bfile://[^\\s]*)|(\\bwww\\.[^\\s]*)"); } }; diff --git a/retroshare-gui/src/gui/common/LinkTextBrowser.cpp b/retroshare-gui/src/gui/common/LinkTextBrowser.cpp new file mode 100644 index 000000000..dddc6124b --- /dev/null +++ b/retroshare-gui/src/gui/common/LinkTextBrowser.cpp @@ -0,0 +1,19 @@ +#include + +#include "LinkTextBrowser.h" + +LinkTextBrowser::LinkTextBrowser(QWidget *parent) : + QTextBrowser(parent) +{ + setOpenExternalLinks(true); + setOpenLinks(false); + + connect(this, SIGNAL(anchorClicked(QUrl)), this, SLOT(linkClicked(QUrl))); +} + +void LinkTextBrowser::linkClicked(const QUrl &url) +{ + // some links are opened directly in the QTextBrowser with open external links set to true, + // so we handle links by our own + QDesktopServices::openUrl(url); +} diff --git a/retroshare-gui/src/gui/common/LinkTextBrowser.h b/retroshare-gui/src/gui/common/LinkTextBrowser.h new file mode 100644 index 000000000..f5c29165a --- /dev/null +++ b/retroshare-gui/src/gui/common/LinkTextBrowser.h @@ -0,0 +1,17 @@ +#ifndef LINKTEXTBROWSER_H +#define LINKTEXTBROWSER_H + +#include + +class LinkTextBrowser : public QTextBrowser +{ + Q_OBJECT + +public: + explicit LinkTextBrowser(QWidget *parent = 0); + +private slots: + void linkClicked(const QUrl &url); +}; + +#endif // LINKTEXTBROWSER_H diff --git a/retroshare-gui/src/gui/connect/ConfCertDialog.ui b/retroshare-gui/src/gui/connect/ConfCertDialog.ui index 5f3607578..f372b10d9 100644 --- a/retroshare-gui/src/gui/connect/ConfCertDialog.ui +++ b/retroshare-gui/src/gui/connect/ConfCertDialog.ui @@ -116,7 +116,7 @@
- + true @@ -141,9 +141,6 @@ true - - true - @@ -549,11 +546,7 @@ - - - true - - + @@ -765,6 +758,11 @@ p, li { white-space: pre-wrap; }
gui/common/AvatarWidget.h
1 + + LinkTextBrowser + QTextBrowser +
gui/common/LinkTextBrowser.h
+
diff --git a/retroshare-gui/src/gui/feeds/ChanMsgItem.cpp b/retroshare-gui/src/gui/feeds/ChanMsgItem.cpp index d4bd629a9..fdc4bd52e 100644 --- a/retroshare-gui/src/gui/feeds/ChanMsgItem.cpp +++ b/retroshare-gui/src/gui/feeds/ChanMsgItem.cpp @@ -29,6 +29,7 @@ #include "gui/notifyqt.h" #include "util/misc.h" #include "gui/RetroShareLink.h" +#include "gui/chat/HandleRichText.h" #include @@ -125,7 +126,7 @@ void ChanMsgItem::updateItemStatic() { /* subject */ titleLabel->setText(QString::fromStdWString(cmi.subject)); - subjectLabel->setText(QString::fromStdWString(cmi.msg)); + subjectLabel->setText(RsHtml::formatText(QString::fromStdWString(cmi.msg), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS)); /* disable buttons: deletion facility not enabled with cache services yet */ clearButton->setEnabled(false); @@ -162,7 +163,7 @@ void ChanMsgItem::updateItemStatic() } } - msgLabel->setText(QString::fromStdWString(cmi.msg)); + msgLabel->setText(RsHtml::formatText(QString::fromStdWString(cmi.msg), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS)); msgWidget->setVisible(!cmi.msg.empty()); QDateTime qtime; diff --git a/retroshare-gui/src/gui/feeds/ChanMsgItem.ui b/retroshare-gui/src/gui/feeds/ChanMsgItem.ui index 4744d6ccc..0708cbad6 100644 --- a/retroshare-gui/src/gui/feeds/ChanMsgItem.ui +++ b/retroshare-gui/src/gui/feeds/ChanMsgItem.ui @@ -466,6 +466,9 @@ border-radius: 10px;} true + + true + Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse diff --git a/retroshare-gui/src/gui/msgs/MessageWidget.ui b/retroshare-gui/src/gui/msgs/MessageWidget.ui index 75432a2c6..46c3d51d4 100644 --- a/retroshare-gui/src/gui/msgs/MessageWidget.ui +++ b/retroshare-gui/src/gui/msgs/MessageWidget.ui @@ -39,19 +39,13 @@ - + 0 0 - - true - - - true - @@ -481,6 +475,13 @@ p, li { white-space: pre-wrap; } + + + LinkTextBrowser + QTextBrowser +
gui/common/LinkTextBrowser.h
+
+