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:
joss17 2009-05-07 19:40:02 +00:00
parent f2a2681c2e
commit 46f7dd0047

View file

@ -33,6 +33,7 @@
#include <QIcon> #include <QIcon>
#include <QPixmap> #include <QPixmap>
#include <QHashIterator> #include <QHashIterator>
#include <QDesktopServices>
#include "rsiface/rspeers.h" #include "rsiface/rspeers.h"
#include "rsiface/rsmsgs.h" #include "rsiface/rsmsgs.h"
@ -94,7 +95,7 @@ PopupChatDialog::PopupChatDialog(std::string id, std::string name,
// Create the status bar // Create the status bar
resetStatusBar() ; resetStatusBar() ;
ui.textBrowser->setOpenExternalLinks ( true ); ui.textBrowser->setOpenExternalLinks ( false );
ui.textBrowser->setOpenLinks ( false ); ui.textBrowser->setOpenLinks ( false );
QString title = QString::fromStdString(name) + " :" + tr(" RetroShare - Encrypted Chat") ; 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 name = QString::fromStdString(ci ->name);
QString message = QString::fromStdWString(ci -> msg); 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); /*QHashIterator<QString, QString> i(smileys);
while(i.hasNext()) while(i.hasNext())
{ {
@ -770,13 +784,17 @@ void PopupChatDialog::fileHashingFinished(SubFileItem* file) {
} }
void PopupChatDialog::anchorClicked (const QUrl& link ) { 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 fileName = link.queryItemValue(QString("fileName")).toStdString();
std::string fileHash = link.queryItemValue(QString("fileHash")).toStdString(); std::string fileHash = link.queryItemValue(QString("fileHash")).toStdString();
uint32_t fileSize = link.queryItemValue(QString("fileSize")).toInt(); uint32_t fileSize = link.queryItemValue(QString("fileSize")).toInt();
#ifdef CHAT_DEBUG #ifdef CHAT_DEBUG
std::cerr << "PopupChatDialog::anchorClicked FileRequest : fileName : " << fileName << ". fileHash : " << fileHash << ". fileSize : " << fileSize; std::cerr << "PopupChatDialog::anchorClicked FileRequest : fileName : " << fileName << ". fileHash : " << fileHash << ". fileSize : " << fileSize;
std::cerr << ". source id : " << dialogId << std::endl; std::cerr << ". source id : " << dialogId << std::endl;
#endif #endif
if (fileName != "" && if (fileName != "" &&
fileHash != "") { fileHash != "") {
std::list<std::string> srcIds; std::list<std::string> srcIds;
@ -791,5 +809,13 @@ void PopupChatDialog::anchorClicked (const QUrl& link ) {
mb.setButtonText( QMessageBox::Ok, "OK" ); mb.setButtonText( QMessageBox::Ok, "OK" );
mb.exec(); 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));
}
} }