From db225bdcb7100cfca951f231e49909139d77fc19 Mon Sep 17 00:00:00 2001 From: joss17 Date: Sun, 7 Feb 2010 12:36:37 +0000 Subject: [PATCH] re implement chat parsing for urls. External web browser call might not work on some systems git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@2224 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- retroshare-gui/src/gui/PeersDialog.cpp | 108 +++--- retroshare-gui/src/gui/PeersDialog.ui | 6 + .../src/gui/chat/PopupChatDialog.cpp | 18 +- .../src/gui/chat/PopupChatDialog.ui | 356 +++++++++--------- 4 files changed, 255 insertions(+), 233 deletions(-) diff --git a/retroshare-gui/src/gui/PeersDialog.cpp b/retroshare-gui/src/gui/PeersDialog.cpp index 46613b9bf..782e4636a 100644 --- a/retroshare-gui/src/gui/PeersDialog.cpp +++ b/retroshare-gui/src/gui/PeersDialog.cpp @@ -193,8 +193,8 @@ PeersDialog::PeersDialog(QWidget *parent) ui.menupushButton->setMenu(menu); - ui.msgText->setOpenExternalLinks ( false ); - ui.msgText->setOpenLinks ( false ); + //ui.msgText->setOpenExternalLinks ( false ); + //ui.msgText->setOpenLinks ( false ); setAcceptDrops(true); ui.lineEdit->setAcceptDrops(false); @@ -890,7 +890,7 @@ void PeersDialog::insertChat() /* add in lines at the bottom */ for(it = newchat.begin(); it != newchat.end(); it++) { - std::string msg(it->msg.begin(), it->msg.end()); + std::string msg(it->msg.begin(), it->msg.end()); #ifdef PEERS_DEBUG std::cerr << "PeersDialog::insertChat(): " << msg << std::endl; #endif @@ -907,50 +907,64 @@ void PeersDialog::insertChat() std::ostringstream out; QString extraTxt; - QString timestamp = QDateTime::currentDateTime().toString("hh:mm:ss"); - QString name = QString::fromStdString(it->name); - QString line = "" + timestamp + "" + - "" + " " + name + ""; + QString timestamp = QDateTime::currentDateTime().toString("hh:mm:ss"); + QString name = QString::fromStdString(it->name); + QString line = "" + timestamp + "" + + "" + " " + name + ""; - //std::cerr << "PeersDialog::insertChat(): 1.11\n"; - historyKeeper.addMessage(name, "THIS", QString::fromStdWString(it->msg)); - //std::cerr << "PeersDialog::insertChat(): 1.12\n"; - extraTxt += line; + //std::cerr << "PeersDialog::insertChat(): 1.11\n"; + historyKeeper.addMessage(name, "THIS", QString::fromStdWString(it->msg)); + //std::cerr << "PeersDialog::insertChat(): 1.12\n"; + extraTxt += line; - extraTxt += QString::fromStdWString(it->msg); + extraTxt += QString::fromStdWString(it->msg); - // notify with a systray icon msg - if(it->rsid != rsPeers->getOwnId()) - { - // This is a trick to translate HTML into text. - QTextEdit editor ; - editor.setHtml(QString::fromStdWString(it->msg)); - QString notifyMsg(QString::fromStdString(it->name)+": "+editor.toPlainText()) ; + // notify with a systray icon msg + if(it->rsid != rsPeers->getOwnId()) + { + // This is a trick to translate HTML into text. + QTextEdit editor ; + editor.setHtml(QString::fromStdWString(it->msg)); + QString notifyMsg(QString::fromStdString(it->name)+": "+editor.toPlainText()) ; - if(notifyMsg.length() > 30) - emit notifyGroupChat(QString("New group chat"), notifyMsg.left(30)+QString("...")); - else - emit notifyGroupChat(QString("New group chat"), notifyMsg); - } + if(notifyMsg.length() > 30) + emit notifyGroupChat(QString("New group chat"), notifyMsg.left(30)+QString("...")); + else + emit notifyGroupChat(QString("New group chat"), notifyMsg); + } - QHashIterator i(smileys); - while(i.hasNext()) - { - i.next(); - foreach(QString code, i.key().split("|")) - extraTxt.replace(code, ""); - } + //replace http://, https:// and www. with links + QRegExp rx("(https?://[^ <>]*)|(www\\.[^ <>]*)"); + int count = 0; + int pos = 200; //ignore the first 200 char because of the standard DTD ref + while ( (pos = rx.indexIn(extraTxt, pos)) != -1 ) { + //we need to look ahead to see if it's already a well formed link + if (extraTxt.mid(pos - 6, 6) != "href=\"" && extraTxt.mid(pos - 6, 6) != "href='" && extraTxt.mid(pos - 6, 6) != "ttp://" ) { + QString tempMessg = extraTxt.left(pos) + "" + rx.cap(count) + "" + extraTxt.mid(pos + rx.matchedLength(), -1); + extraTxt = tempMessg; + } + pos += rx.matchedLength() + 15; + count ++; + } - if ((msgWidget->verticalScrollBar()->maximum() - 30) < msgWidget->verticalScrollBar()->value() ) { - msgWidget->append(extraTxt); - } else { - //the vertical scroll is not at the bottom, so just update the text, the scroll will stay at the current position - int scroll = msgWidget->verticalScrollBar()->value(); - msgWidget->setHtml(msgWidget->toHtml() + extraTxt); - msgWidget->verticalScrollBar()->setValue(scroll); - msgWidget->update(); - } - } + QHashIterator i(smileys); + while(i.hasNext()) + { + i.next(); + foreach(QString code, i.key().split("|")) + extraTxt.replace(code, ""); + } + + if ((msgWidget->verticalScrollBar()->maximum() - 30) < msgWidget->verticalScrollBar()->value() ) { + msgWidget->append(extraTxt); + } else { + //the vertical scroll is not at the bottom, so just update the text, the scroll will stay at the current position + int scroll = msgWidget->verticalScrollBar()->value(); + msgWidget->setHtml(msgWidget->toHtml() + extraTxt); + msgWidget->verticalScrollBar()->setValue(scroll); + msgWidget->update(); + } + } } void PeersDialog::checkChat() @@ -1522,7 +1536,7 @@ void PeersDialog::addAttachment(std::string filePath) { } void PeersDialog::fileHashingFinished(AttachFileItem* file) { - std::cerr << "PopupChatDialog::fileHashingFinished() started."; + std::cerr << "PeersDialog::fileHashingFinished() started."; std::cerr << std::endl; //check that the file is ok tos end @@ -1553,8 +1567,8 @@ void PeersDialog::fileHashingFinished(AttachFileItem* file) { std::string mesgString = "" + "retroshare://file|" + (file->FileName()) + "|" + fileSize + "|" + (file->FileHash()) + ""; -#ifdef CHAT_DEBUG - std::cerr << "CreateForumMsg::anchorClicked mesgString : " << mesgString << std::endl; +#ifdef PEERS_DEBUG + std::cerr << "PeersDialog::fileHashingFinished mesgString : " << mesgString << std::endl; #endif const char * messageString = mesgString.c_str (); @@ -1581,8 +1595,8 @@ void PeersDialog::fileHashingFinished(AttachFileItem* file) { void PeersDialog::anchorClicked (const QUrl& link ) { - #ifdef FORUM_DEBUG - std::cerr << "ForumsDialog::anchorClicked link.scheme() : " << link.scheme().toStdString() << std::endl; + #ifdef PEERS_DEBUG + std::cerr << "PeersDialog::anchorClicked link.scheme() : " << link.scheme().toStdString() << std::endl; #endif if (link.scheme() == "retroshare") @@ -1593,7 +1607,7 @@ void PeersDialog::anchorClicked (const QUrl& link ) uint64_t fileSize = L.at(2).toULongLong(); std::string fileHash = L.at(3).toStdString() ; -#ifdef FORUM_DEBUG +#ifdef PEERS_DEBUG std::cerr << "PeersDialog::anchorClicked FileRequest : fileName : " << fileName << ". fileHash : " << fileHash << ". fileSize : " << fileSize << std::endl; #endif diff --git a/retroshare-gui/src/gui/PeersDialog.ui b/retroshare-gui/src/gui/PeersDialog.ui index d1792b50a..401a35ae9 100644 --- a/retroshare-gui/src/gui/PeersDialog.ui +++ b/retroshare-gui/src/gui/PeersDialog.ui @@ -861,6 +861,12 @@ background: white;} true + + true + + + false + diff --git a/retroshare-gui/src/gui/chat/PopupChatDialog.cpp b/retroshare-gui/src/gui/chat/PopupChatDialog.cpp index fcec99c45..9cc8cefe7 100644 --- a/retroshare-gui/src/gui/chat/PopupChatDialog.cpp +++ b/retroshare-gui/src/gui/chat/PopupChatDialog.cpp @@ -99,8 +99,8 @@ PopupChatDialog::PopupChatDialog(std::string id, std::string name, // Create the status bar resetStatusBar() ; - ui.textBrowser->setOpenExternalLinks ( false ); - ui.textBrowser->setOpenLinks ( false ); + //ui.textBrowser->setOpenExternalLinks ( false ); + //ui.textBrowser->setOpenLinks ( false ); QString title = QString::fromStdString(name) + " :" + tr(" RetroShare - Encrypted Chat") ; setWindowTitle(title); @@ -252,29 +252,21 @@ void PopupChatDialog::addChatMsg(ChatInfo *ci) //replace http://, https:// and www. with links QRegExp rx("(https?://[^ <>]*)|(www\\.[^ <>]*)"); int count = 0; - int pos = 100; //ignor the first 100 charater because of the standard DTD ref + int pos = 100; //ignore the first 100 char because of the standard DTD ref while ( (pos = rx.indexIn(message, pos)) != -1 ) { - count ++; //we need to look ahead to see if it's already a well formed link if (message.mid(pos - 6, 6) != "href=\"" && message.mid(pos - 6, 6) != "href='" && message.mid(pos - 6, 6) != "ttp://" ) { QString tempMessg = message.left(pos) + "" + rx.cap(count) + "" + message.mid(pos + rx.matchedLength(), -1); message = tempMessg; } pos += rx.matchedLength() + 15; - } + count ++; + } #ifdef CHAT_DEBUG std::cout << "PopupChatDialog:addChatMsg message : " << message.toStdString() << std::endl; #endif - - /*QHashIterator i(smileys); - while(i.hasNext()) - { - i.next(); - message.replace(i.key(), ""); - }*/ - QHashIterator i(smileys); while(i.hasNext()) { diff --git a/retroshare-gui/src/gui/chat/PopupChatDialog.ui b/retroshare-gui/src/gui/chat/PopupChatDialog.ui index 2abd56d5e..77386ff61 100644 --- a/retroshare-gui/src/gui/chat/PopupChatDialog.ui +++ b/retroshare-gui/src/gui/chat/PopupChatDialog.ui @@ -1,7 +1,8 @@ - + + PopupChatDialog - - + + 0 0 @@ -9,100 +10,103 @@ 439 - + MainWindow - - - + + + 0 - + 0 - + 0 - - 0 - - - - - + + + + 0 0 - + 0 0 - + 0 0 + + true + + + false + - - - + + + QFrame::StyledPanel - + QFrame::Raised - - + + 0 - + 9 - + 0 - + 9 - - - + + + 116 116 - + 116 116 - + QLabel{ border-image: url(:/images/mystatus_bg.png); } - + - + Qt::AlignCenter - + - + Qt::Vertical - + 61 141 @@ -110,43 +114,43 @@ border-image: url(:/images/mystatus_bg.png); - - - + + + 116 116 - + 116 116 - + QLabel{ border-image: url(:/images/mystatus_bg.png); } - + - + Qt::AlignCenter - + - + Qt::Vertical - + QSizePolicy::Fixed - + 61 30 @@ -157,42 +161,42 @@ border-image: url(:/images/mystatus_bg.png); - - - - - + + + + + 14 31 - + 14 31 - + - + 16 31 - + true - + - + Qt::Vertical - + 14 321 @@ -202,33 +206,33 @@ border-image: url(:/images/mystatus_bg.png); - - - + + + 16 46 - + QFrame::StyledPanel - + QFrame::Raised - - + + 9 - + 6 - + - + Qt::Horizontal - + 190 25 @@ -236,30 +240,30 @@ border-image: url(:/images/mystatus_bg.png); - - - - + + + + 0 0 - + 28 28 - + 28 28 - + - + 24 24 @@ -267,30 +271,30 @@ border-image: url(:/images/mystatus_bg.png); - - - + + + 28 28 - + 28 28 - - <html><head><meta name="qrichtext" content="1" /><style type="text/css"> + + <html><head><meta name="qrichtext" content="1" /><style type="text/css"> p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Set Chat Window Style</p></body></html> +</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Set Chat Window Style</p></body></html> - + - + 24 24 @@ -298,136 +302,140 @@ p, li { white-space: pre-wrap; } - - - + + + 28 28 - + 28 28 - + Bold - + - - C:/Dokumente und Einstellungen/Linux/.designer/backup + + + C:/Dokumente und Einstellungen/Linux/.designer/backupC:/Dokumente und Einstellungen/Linux/.designer/backup - + false - - - + + + 28 28 - + 28 28 - + Underline - + - - C:/Dokumente und Einstellungen/Linux/.designer/backup + + + C:/Dokumente und Einstellungen/Linux/.designer/backupC:/Dokumente und Einstellungen/Linux/.designer/backup - + false - - - + + + 28 28 - + 28 28 - + Italic - + - - C:/Dokumente und Einstellungen/Linux/.designer/backup + + + C:/Dokumente und Einstellungen/Linux/.designer/backupC:/Dokumente und Einstellungen/Linux/.designer/backup - + false - - - + + + 28 28 - + 28 28 - + Set Font - + - - C:/Dokumente und Einstellungen/Linux/.designer/backup + + + C:/Dokumente und Einstellungen/Linux/.designer/backupC:/Dokumente und Einstellungen/Linux/.designer/backup - + false - - - + + + 28 28 - + 28 28 - + Text Color - + @@ -435,39 +443,40 @@ p, li { white-space: pre-wrap; } - - - - + + + + 0 0 - - - + + + 0 - + 2 - + 2 - - + + Add a File for your Friend - + - - :/images/add-share24.png + + + :/images/add-share24.png:/images/add-share24.png - + 24 24 @@ -477,10 +486,10 @@ p, li { white-space: pre-wrap; } - + Qt::Horizontal - + 331 20 @@ -489,72 +498,73 @@ p, li { white-space: pre-wrap; } - - + + Send - - + + - - - + + + toolBar - + 24 24 - + TopToolBarArea - + false - + - - + + Bold - - + + Italic - - + + Underline - - + + Strike - - - :/images/add_image24.png + + + + :/images/add_image24.png:/images/add_image24.png - + Avatar - + Set your Avatar Picture - +