diff --git a/retroshare-gui/src/RetroShare.pro b/retroshare-gui/src/RetroShare.pro index 1618cb4bc..cbedc5bc1 100644 --- a/retroshare-gui/src/RetroShare.pro +++ b/retroshare-gui/src/RetroShare.pro @@ -11,7 +11,7 @@ MOC_DIR = temp/moc #CONFIG += debug debug { - QMAKE_CXXFLAGS *= -g + QMAKE_CFLAGS += -g } ################################# Linux ########################################## @@ -19,8 +19,15 @@ debug { linux-* { CONFIG += version_detail_bash_script QMAKE_CXXFLAGS *= -D_FILE_OFFSET_BITS=64 + + system(which gpgme-config >/dev/null 2>&1) { + INCLUDEPATH += $$system(gpgme-config --cflags | sed -e "s/-I//g") + } else { + message(Could not find gpgme-config on your system, assuming gpgme.h is in /usr/include) + } + LIBS += ../../libretroshare/src/lib/libretroshare.a - LIBS += -lssl -lgpgme -lupnp + LIBS += -lssl -lgpgme -lupnp } linux-g++ { @@ -205,6 +212,7 @@ HEADERS += rshare.h \ gui/profile/ProfileWidget.h \ gui/profile/StatusMessage.h \ gui/chat/PopupChatDialog.h \ + gui/chat/HandleRichText.h \ gui/channels/ChannelDetails.h \ gui/channels/CreateChannelMsg.h \ gui/connect/ConnectDialog.h \ @@ -386,6 +394,7 @@ SOURCES += main.cpp \ gui/channels/CreateChannelMsg.cpp \ gui/channels/ChannelDetails.cpp \ gui/chat/PopupChatDialog.cpp \ + gui/chat/HandleRichText.cpp \ gui/connect/ConnectDialog.cpp \ gui/connect/ConfCertDialog.cpp \ gui/msgs/ChanMsgDialog.cpp \ diff --git a/retroshare-gui/src/gui/PeersDialog.cpp b/retroshare-gui/src/gui/PeersDialog.cpp index 6cc33bd54..bccb1bc2a 100644 --- a/retroshare-gui/src/gui/PeersDialog.cpp +++ b/retroshare-gui/src/gui/PeersDialog.cpp @@ -952,14 +952,13 @@ void PeersDialog::insertChat() QString name = QString::fromStdString(it->name); QString line = "" + timestamp + "" + "" + " " + name + ""; + QString msgContents = QString::fromStdWString(it->msg); //std::cerr << "PeersDialog::insertChat(): 1.11\n"; - historyKeeper.addMessage(name, "THIS", QString::fromStdWString(it->msg)); + historyKeeper.addMessage(name, "THIS", msgContents); //std::cerr << "PeersDialog::insertChat(): 1.12\n"; extraTxt += line; - extraTxt += QString::fromStdWString(it->msg); - // notify with a systray icon msg if(it->rsid != rsPeers->getOwnId()) { @@ -974,30 +973,19 @@ void PeersDialog::insertChat() emit notifyGroupChat(QString("New group chat"), notifyMsg); } - //replace http://, https:// and www. with links - QRegExp rx("(retroshare://[^ <>]*)|(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 ++; - } + // create a DOM tree object from the message and embed contents with HTML tags + QDomDocument doc; + doc.setContent(msgContents); - if(!ui.actionDisable_Emoticons->isChecked()) - { - QHashIterator i(smileys); - while(i.hasNext()) - { - i.next(); - foreach(QString code, i.key().split("|")) - extraTxt.replace(code, ""); - } - } + // embed links + QDomElement body = doc.documentElement(); + RsChat::embedHtml(doc, body, defEmbedAhref); + + if(!ui.actionDisable_Emoticons->isChecked()) + RsChat::embedHtml(doc, body, defEmbedImg); + + msgContents = doc.toString(-1); // -1 removes any annoying carriage return misinterpreted by QTextEdit + extraTxt += msgContents; if ((msgWidget->verticalScrollBar()->maximum() - 30) < msgWidget->verticalScrollBar()->value() ) { msgWidget->append(extraTxt); @@ -1310,7 +1298,7 @@ void PeersDialog::loadEmoticonsgroupchat() #endif if(!sm_file.open(QIODevice::ReadOnly)) { - std::cerr << "Could not open resouce file :/emoticons/emotes.acs" << endl ; + std::cerr << "Could not open resouce file :/emoticons/emotes.acs" << std::endl ; return ; } sm_codes = sm_file.readAll(); @@ -1360,6 +1348,9 @@ void PeersDialog::loadEmoticonsgroupchat() smileys.insert(smcode, ":/"+smfile); #endif } + + // init embedder + defEmbedImg.InitFromAwkwardHash(smileys); } void PeersDialog::smileyWidgetgroupchat() @@ -1615,13 +1606,13 @@ void PeersDialog::fileHashingFinished(AttachFileItem* file) { } //convert fileSize from uint_64 to string for html link - char fileSizeChar [100]; - sprintf(fileSizeChar, "%lld", file->FileSize()); - std::string fileSize = *(&fileSizeChar); +// char fileSizeChar [100]; +// sprintf(fileSizeChar, "%lld", file->FileSize()); +// std::string fileSize = *(&fileSizeChar); std::string mesgString = RetroShareLink(QString::fromStdString(file->FileName()), - file->FileSize(), - QString::fromStdString(file->FileHash())).toHtml().toStdString() ; + file->FileSize(), + QString::fromStdString(file->FileHash())).toHtml().toStdString() ; // std::string mesgString = "" // + "retroshare://file|" + (file->FileName()) + "|" + fileSize + "|" + (file->FileHash()) + ""; @@ -1633,13 +1624,13 @@ void PeersDialog::fileHashingFinished(AttachFileItem* file) { //convert char massageString to w_char wchar_t* message; - int requiredSize = mbstowcs(NULL, messageString, 0); // C4996 + size_t requiredSize = mbstowcs(NULL, messageString, 0); // C4996 /* Add one to leave room for the NULL terminator */ message = (wchar_t *)malloc( (requiredSize + 1) * sizeof( wchar_t )); if (! message) { std::cerr << ("Memory allocation failure.\n"); } - int size = mbstowcs( message, messageString, requiredSize + 1); // C4996 + size_t size = mbstowcs( message, messageString, requiredSize + 1); // C4996 if (size == (size_t) (-1)) { printf("Couldn't convert string--invalid multibyte character.\n"); } diff --git a/retroshare-gui/src/gui/PeersDialog.h b/retroshare-gui/src/gui/PeersDialog.h index 606f78099..8d40a39b2 100644 --- a/retroshare-gui/src/gui/PeersDialog.h +++ b/retroshare-gui/src/gui/PeersDialog.h @@ -25,6 +25,7 @@ #include #include "chat/PopupChatDialog.h" +#include "chat/HandleRichText.h" #include "RsAutoUpdatePage.h" #include "mainpage.h" @@ -149,6 +150,15 @@ private: class QWidgetAction *widgetAction; class QSpacerItem *spacerItem; + ///play the sound when recv a message + void playsound(); + + QString fileName; + + /** store default information for embedding HTML */ + RsChat::EmbedInHtmlAhref defEmbedAhref; + RsChat::EmbedInHtmlImg defEmbedImg; + /* Worker Functions */ /* (1) Update Display */ @@ -174,7 +184,7 @@ private: QColor _currentColor; bool _underline; time_t last_status_send_time ; - + QHash smileys; std::map chatDialogs; @@ -188,5 +198,5 @@ private: Ui::PeersDialog ui; }; -#endif +#endif diff --git a/retroshare-gui/src/gui/msgs/ChanMsgDialog.cpp b/retroshare-gui/src/gui/msgs/ChanMsgDialog.cpp index 3acac56f4..77c25dd68 100644 --- a/retroshare-gui/src/gui/msgs/ChanMsgDialog.cpp +++ b/retroshare-gui/src/gui/msgs/ChanMsgDialog.cpp @@ -1242,25 +1242,8 @@ void ChanMsgDialog::fileHashingFinished(AttachFileItem* file) { std::cerr << "ChanMsgDialog::anchorClicked mesgString : " << mesgString << std::endl; #endif - const char * messageString = mesgString.c_str (); - - //convert char massageString to w_char - wchar_t* message; - size_t requiredSize = mbstowcs(NULL, messageString, 0); // C4996 - /* Add one to leave room for the NULL terminator */ - message = (wchar_t *)malloc( (requiredSize + 1) * sizeof( wchar_t )); - if (! message) { - std::cerr << ("Memory allocation failure.\n"); - } - size_t size = mbstowcs( message, messageString, requiredSize + 1); // C4996 - if (size == (size_t) (-1)) { - printf("Couldn't convert string--invalid multibyte character.\n"); - } - - ui.msgText->setHtml(QString::fromStdWString(message)); + ui.msgText->textCursor().insertHtml(QString::fromStdString(mesgString)); ui.msgText->setFocus( Qt::OtherFocusReason ); - - } void ChanMsgDialog::checkAttachmentReady()