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
This commit is contained in:
joss17 2010-02-07 12:36:37 +00:00
parent 37e9bf527c
commit db225bdcb7
4 changed files with 255 additions and 233 deletions

View File

@ -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);
@ -933,6 +933,20 @@ void PeersDialog::insertChat()
emit notifyGroupChat(QString("New group chat"), notifyMsg);
}
//replace http://, https:// and www. with <a href> 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) + "<a href=\"" + rx.cap(count) + "\">" + rx.cap(count) + "</a>" + extraTxt.mid(pos + rx.matchedLength(), -1);
extraTxt = tempMessg;
}
pos += rx.matchedLength() + 15;
count ++;
}
QHashIterator<QString, QString> i(smileys);
while(i.hasNext())
{
@ -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 = "<a href='retroshare://file|" + (file->FileName()) + "|" + fileSize + "|" + (file->FileHash()) + "'>"
+ "retroshare://file|" + (file->FileName()) + "|" + fileSize + "|" + (file->FileHash()) + "</a>";
#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

View File

@ -861,6 +861,12 @@ background: white;}</string>
<property name="readOnly">
<bool>true</bool>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
<property name="openLinks">
<bool>false</bool>
</property>
</widget>
</item>
<item>

View File

@ -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 <a href> 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) + "<a href=\"" + rx.cap(count) + "\">" + rx.cap(count) + "</a>" + 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<QString, QString> i(smileys);
while(i.hasNext())
{
i.next();
message.replace(i.key(), "<img src=\"" + i.value() + "\">");
}*/
QHashIterator<QString, QString> i(smileys);
while(i.hasNext())
{

View File

@ -1,3 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>PopupChatDialog</class>
<widget class="QMainWindow" name="PopupChatDialog">
@ -20,16 +21,13 @@
<property name="bottomMargin">
<number>0</number>
</property>
<property name="horizontalSpacing" >
<number>0</number>
</property>
<property name="verticalSpacing" >
<property name="spacing">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QTextBrowser" name="textBrowser">
<property name="sizePolicy">
<sizepolicy vsizetype="MinimumExpanding" hsizetype="Expanding" >
<sizepolicy hsizetype="Expanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -46,9 +44,15 @@
<height>0</height>
</size>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
<property name="openLinks">
<bool>false</bool>
</property>
</widget>
</item>
<item rowspan="4" row="0" column="1" >
<item row="0" column="1" rowspan="4">
<widget class="QFrame" name="avatarframe">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
@ -102,7 +106,7 @@ border-image: url(:/images/mystatus_bg.png);
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" >
<property name="sizeHint" stdset="0">
<size>
<width>61</width>
<height>141</height>
@ -146,7 +150,7 @@ border-image: url(:/images/mystatus_bg.png);
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" >
<property name="sizeHint" stdset="0">
<size>
<width>61</width>
<height>30</height>
@ -157,7 +161,7 @@ border-image: url(:/images/mystatus_bg.png);
</layout>
</widget>
</item>
<item rowspan="4" row="0" column="2" >
<item row="0" column="2" rowspan="4">
<layout class="QGridLayout">
<item row="0" column="0">
<widget class="QPushButton" name="avatarFrameButton">
@ -192,7 +196,7 @@ border-image: url(:/images/mystatus_bg.png);
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" >
<property name="sizeHint" stdset="0">
<size>
<width>14</width>
<height>321</height>
@ -228,7 +232,7 @@ border-image: url(:/images/mystatus_bg.png);
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<property name="sizeHint" stdset="0">
<size>
<width>190</width>
<height>25</height>
@ -239,7 +243,7 @@ border-image: url(:/images/mystatus_bg.png);
<item row="0" column="1">
<widget class="QPushButton" name="emoteiconButton">
<property name="sizePolicy">
<sizepolicy vsizetype="Fixed" hsizetype="Fixed" >
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -282,10 +286,10 @@ border-image: url(:/images/mystatus_bg.png);
</size>
</property>
<property name="toolTip">
<string>&lt;html>&lt;head>&lt;meta name="qrichtext" content="1" />&lt;style type="text/css">
<string>&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style>&lt;/head>&lt;body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;">
&lt;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&lt;/p>&lt;/body>&lt;/html></string>
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Set Chat Window Style&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string/>
@ -319,7 +323,8 @@ p, li { white-space: pre-wrap; }
<string/>
</property>
<property name="icon">
<iconset>C:/Dokumente und Einstellungen/Linux/.designer/backup</iconset>
<iconset>
<normaloff>C:/Dokumente und Einstellungen/Linux/.designer/backup</normaloff>C:/Dokumente und Einstellungen/Linux/.designer/backup</iconset>
</property>
<property name="checkable">
<bool>false</bool>
@ -347,7 +352,8 @@ p, li { white-space: pre-wrap; }
<string/>
</property>
<property name="icon">
<iconset>C:/Dokumente und Einstellungen/Linux/.designer/backup</iconset>
<iconset>
<normaloff>C:/Dokumente und Einstellungen/Linux/.designer/backup</normaloff>C:/Dokumente und Einstellungen/Linux/.designer/backup</iconset>
</property>
<property name="checkable">
<bool>false</bool>
@ -375,7 +381,8 @@ p, li { white-space: pre-wrap; }
<string/>
</property>
<property name="icon">
<iconset>C:/Dokumente und Einstellungen/Linux/.designer/backup</iconset>
<iconset>
<normaloff>C:/Dokumente und Einstellungen/Linux/.designer/backup</normaloff>C:/Dokumente und Einstellungen/Linux/.designer/backup</iconset>
</property>
<property name="checkable">
<bool>false</bool>
@ -403,7 +410,8 @@ p, li { white-space: pre-wrap; }
<string/>
</property>
<property name="icon">
<iconset>C:/Dokumente und Einstellungen/Linux/.designer/backup</iconset>
<iconset>
<normaloff>C:/Dokumente und Einstellungen/Linux/.designer/backup</normaloff>C:/Dokumente und Einstellungen/Linux/.designer/backup</iconset>
</property>
<property name="checkable">
<bool>false</bool>
@ -438,7 +446,7 @@ p, li { white-space: pre-wrap; }
<item row="2" column="0">
<widget class="QTextEdit" name="chattextEdit">
<property name="sizePolicy">
<sizepolicy vsizetype="Maximum" hsizetype="Expanding" >
<sizepolicy hsizetype="Expanding" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -465,7 +473,8 @@ p, li { white-space: pre-wrap; }
<string/>
</property>
<property name="icon">
<iconset resource="../images.qrc" >:/images/add-share24.png</iconset>
<iconset resource="../images.qrc">
<normaloff>:/images/add-share24.png</normaloff>:/images/add-share24.png</iconset>
</property>
<property name="iconSize">
<size>
@ -480,7 +489,7 @@ p, li { white-space: pre-wrap; }
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<property name="sizeHint" stdset="0">
<size>
<width>331</width>
<height>20</height>
@ -543,7 +552,8 @@ p, li { white-space: pre-wrap; }
</action>
<action name="actionAvatar">
<property name="icon">
<iconset resource="../images.qrc" >:/images/add_image24.png</iconset>
<iconset resource="../images.qrc">
<normaloff>:/images/add_image24.png</normaloff>:/images/add_image24.png</iconset>
</property>
<property name="text">
<string>Avatar</string>