From 46f7dd0047d71778212c984e9ec085ca1b62a276 Mon Sep 17 00:00:00 2001 From: joss17 Date: Thu, 7 May 2009 19:40:02 +0000 Subject: [PATCH] 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 --- .../src/gui/chat/PopupChatDialog.cpp | 66 +++++++++++++------ 1 file changed, 46 insertions(+), 20 deletions(-) diff --git a/retroshare-gui/src/gui/chat/PopupChatDialog.cpp b/retroshare-gui/src/gui/chat/PopupChatDialog.cpp index 23234661f..d1f540399 100644 --- a/retroshare-gui/src/gui/chat/PopupChatDialog.cpp +++ b/retroshare-gui/src/gui/chat/PopupChatDialog.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #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 links + messageSubString.replace(QRegExp("(http://[^ <]*)|(www\\.[^ <]*)"), "\\1\\2"); + //rebuild the full message + message = message.left(109) + messageSubString; + +#ifdef CHAT_DEBUG +std::cout << "PopupChatDialog:addChatMsg message : " << message.toStdString() << std::endl; +#endif + + /*QHashIterator i(smileys); while(i.hasNext()) { @@ -770,26 +784,38 @@ void PopupChatDialog::fileHashingFinished(SubFileItem* file) { } void PopupChatDialog::anchorClicked (const QUrl& link ) { - std::string fileName = link.queryItemValue(QString("fileName")).toStdString(); - std::string fileHash = link.queryItemValue(QString("fileHash")).toStdString(); - uint32_t fileSize = link.queryItemValue(QString("fileSize")).toInt(); -#ifdef CHAT_DEBUG - std::cerr << "PopupChatDialog::anchorClicked FileRequest : fileName : " << fileName << ". fileHash : " << fileHash << ". fileSize : " << fileSize; - std::cerr << ". source id : " << dialogId << std::endl; -#endif - if (fileName != "" && - fileHash != "") { - std::list srcIds; - srcIds.push_front(dialogId); - rsFiles->FileRequest(fileName, fileHash, fileSize, "", 0, srcIds); + #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(); + #ifdef CHAT_DEBUG + std::cerr << "PopupChatDialog::anchorClicked FileRequest : fileName : " << fileName << ". fileHash : " << fileHash << ". fileSize : " << fileSize; + std::cerr << ". source id : " << dialogId << std::endl; + #endif + if (fileName != "" && + fileHash != "") { + std::list srcIds; + srcIds.push_front(dialogId); + rsFiles->FileRequest(fileName, fileHash, fileSize, "", 0, srcIds); - QMessageBox mb(tr("File Request Confirmation"), tr("The file has been added to your download list."),QMessageBox::Information,QMessageBox::Ok,0,0); - mb.setButtonText( QMessageBox::Ok, "OK" ); - mb.exec(); - } else { - QMessageBox mb(tr("File Request Error"), tr("The file link is malformed."),QMessageBox::Information,QMessageBox::Ok,0,0); - mb.setButtonText( QMessageBox::Ok, "OK" ); - mb.exec(); + QMessageBox mb(tr("File Request Confirmation"), tr("The file has been added to your download list."),QMessageBox::Information,QMessageBox::Ok,0,0); + mb.setButtonText( QMessageBox::Ok, "OK" ); + mb.exec(); + } else { + QMessageBox mb(tr("File Request Error"), tr("The file link is malformed."),QMessageBox::Information,QMessageBox::Ok,0,0); + 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)); } }