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,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<std::string> 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<std::string> 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));
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user