mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
Some work on the link of the chat dialog
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1185 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
f2a2681c2e
commit
46f7dd0047
@ -33,6 +33,7 @@
|
||||
#include <QIcon>
|
||||
#include <QPixmap>
|
||||
#include <QHashIterator>
|
||||
#include <QDesktopServices>
|
||||
|
||||
#include "rsiface/rspeers.h"
|
||||
#include "rsiface/rsmsgs.h"
|
||||
@ -94,7 +95,7 @@ PopupChatDialog::PopupChatDialog(std::string id, std::string name,
|
||||
// Create the status bar
|
||||
resetStatusBar() ;
|
||||
|
||||
ui.textBrowser->setOpenExternalLinks ( true );
|
||||
ui.textBrowser->setOpenExternalLinks ( false );
|
||||
ui.textBrowser->setOpenLinks ( false );
|
||||
|
||||
QString title = QString::fromStdString(name) + " :" + tr(" RetroShare - Encrypted Chat") ;
|
||||
@ -250,6 +251,19 @@ void PopupChatDialog::addChatMsg(ChatInfo *ci)
|
||||
QString name = QString::fromStdString(ci ->name);
|
||||
QString message = QString::fromStdWString(ci -> msg);
|
||||
|
||||
//replace url by a link
|
||||
//first, avoid DTD link taht stands at the beginning of the string
|
||||
QString messageSubString = message.mid(110, -1);
|
||||
//replace http:// and www. with <a href> links
|
||||
messageSubString.replace(QRegExp("(http://[^ <]*)|(www\\.[^ <]*)"), "<a href=\"\\1\\2\">\\1\\2</a>");
|
||||
//rebuild the full message
|
||||
message = message.left(109) + messageSubString;
|
||||
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cout << "PopupChatDialog:addChatMsg message : " << message.toStdString() << std::endl;
|
||||
#endif
|
||||
|
||||
|
||||
/*QHashIterator<QString, QString> i(smileys);
|
||||
while(i.hasNext())
|
||||
{
|
||||
@ -770,6 +784,10 @@ void PopupChatDialog::fileHashingFinished(SubFileItem* file) {
|
||||
}
|
||||
|
||||
void PopupChatDialog::anchorClicked (const QUrl& link ) {
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "PopupChatDialog::anchorClicked link.scheme() : " << link.scheme().toStdString() << std::endl;
|
||||
#endif
|
||||
if (link.scheme() == "file") {
|
||||
std::string fileName = link.queryItemValue(QString("fileName")).toStdString();
|
||||
std::string fileHash = link.queryItemValue(QString("fileHash")).toStdString();
|
||||
uint32_t fileSize = link.queryItemValue(QString("fileSize")).toInt();
|
||||
@ -791,5 +809,13 @@ void PopupChatDialog::anchorClicked (const QUrl& link ) {
|
||||
mb.setButtonText( QMessageBox::Ok, "OK" );
|
||||
mb.exec();
|
||||
}
|
||||
} else if (link.scheme() == "http") {
|
||||
QDesktopServices::openUrl(link);
|
||||
} else if (link.scheme() == "") {
|
||||
//it's probably a web adress, let's add http:// at the beginning of the link
|
||||
QString newAddress = link.toString();
|
||||
newAddress.prepend("http://");
|
||||
QDesktopServices::openUrl(QUrl(newAddress));
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user