ported trunk commit 2889 and 2888

git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5.0@2889 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2010-05-12 18:47:34 +00:00
parent ac693595c9
commit acbcf57bd8
4 changed files with 49 additions and 56 deletions

View File

@ -11,7 +11,7 @@ MOC_DIR = temp/moc
#CONFIG += debug #CONFIG += debug
debug { debug {
QMAKE_CXXFLAGS *= -g QMAKE_CFLAGS += -g
} }
################################# Linux ########################################## ################################# Linux ##########################################
@ -19,8 +19,15 @@ debug {
linux-* { linux-* {
CONFIG += version_detail_bash_script CONFIG += version_detail_bash_script
QMAKE_CXXFLAGS *= -D_FILE_OFFSET_BITS=64 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 += ../../libretroshare/src/lib/libretroshare.a
LIBS += -lssl -lgpgme -lupnp LIBS += -lssl -lgpgme -lupnp
} }
linux-g++ { linux-g++ {
@ -205,6 +212,7 @@ HEADERS += rshare.h \
gui/profile/ProfileWidget.h \ gui/profile/ProfileWidget.h \
gui/profile/StatusMessage.h \ gui/profile/StatusMessage.h \
gui/chat/PopupChatDialog.h \ gui/chat/PopupChatDialog.h \
gui/chat/HandleRichText.h \
gui/channels/ChannelDetails.h \ gui/channels/ChannelDetails.h \
gui/channels/CreateChannelMsg.h \ gui/channels/CreateChannelMsg.h \
gui/connect/ConnectDialog.h \ gui/connect/ConnectDialog.h \
@ -386,6 +394,7 @@ SOURCES += main.cpp \
gui/channels/CreateChannelMsg.cpp \ gui/channels/CreateChannelMsg.cpp \
gui/channels/ChannelDetails.cpp \ gui/channels/ChannelDetails.cpp \
gui/chat/PopupChatDialog.cpp \ gui/chat/PopupChatDialog.cpp \
gui/chat/HandleRichText.cpp \
gui/connect/ConnectDialog.cpp \ gui/connect/ConnectDialog.cpp \
gui/connect/ConfCertDialog.cpp \ gui/connect/ConfCertDialog.cpp \
gui/msgs/ChanMsgDialog.cpp \ gui/msgs/ChanMsgDialog.cpp \

View File

@ -952,14 +952,13 @@ void PeersDialog::insertChat()
QString name = QString::fromStdString(it->name); QString name = QString::fromStdString(it->name);
QString line = "<span style=\"color:#C00000\">" + timestamp + "</span>" + QString line = "<span style=\"color:#C00000\">" + timestamp + "</span>" +
"<span style=\"color:#2D84C9\"><strong>" + " " + name + "</strong></span>"; "<span style=\"color:#2D84C9\"><strong>" + " " + name + "</strong></span>";
QString msgContents = QString::fromStdWString(it->msg);
//std::cerr << "PeersDialog::insertChat(): 1.11\n"; //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"; //std::cerr << "PeersDialog::insertChat(): 1.12\n";
extraTxt += line; extraTxt += line;
extraTxt += QString::fromStdWString(it->msg);
// notify with a systray icon msg // notify with a systray icon msg
if(it->rsid != rsPeers->getOwnId()) if(it->rsid != rsPeers->getOwnId())
{ {
@ -974,30 +973,19 @@ void PeersDialog::insertChat()
emit notifyGroupChat(QString("New group chat"), notifyMsg); emit notifyGroupChat(QString("New group chat"), notifyMsg);
} }
//replace http://, https:// and www. with <a href> links // create a DOM tree object from the message and embed contents with HTML tags
QRegExp rx("(retroshare://[^ <>]*)|(https?://[^ <>]*)|(www\\.[^ <>]*)"); QDomDocument doc;
int count = 0; doc.setContent(msgContents);
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 ++;
}
if(!ui.actionDisable_Emoticons->isChecked()) // embed links
{ QDomElement body = doc.documentElement();
QHashIterator<QString, QString> i(smileys); RsChat::embedHtml(doc, body, defEmbedAhref);
while(i.hasNext())
{ if(!ui.actionDisable_Emoticons->isChecked())
i.next(); RsChat::embedHtml(doc, body, defEmbedImg);
foreach(QString code, i.key().split("|"))
extraTxt.replace(code, "<img src=\"" + i.value() + "\" />"); msgContents = doc.toString(-1); // -1 removes any annoying carriage return misinterpreted by QTextEdit
} extraTxt += msgContents;
}
if ((msgWidget->verticalScrollBar()->maximum() - 30) < msgWidget->verticalScrollBar()->value() ) { if ((msgWidget->verticalScrollBar()->maximum() - 30) < msgWidget->verticalScrollBar()->value() ) {
msgWidget->append(extraTxt); msgWidget->append(extraTxt);
@ -1310,7 +1298,7 @@ void PeersDialog::loadEmoticonsgroupchat()
#endif #endif
if(!sm_file.open(QIODevice::ReadOnly)) 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 ; return ;
} }
sm_codes = sm_file.readAll(); sm_codes = sm_file.readAll();
@ -1360,6 +1348,9 @@ void PeersDialog::loadEmoticonsgroupchat()
smileys.insert(smcode, ":/"+smfile); smileys.insert(smcode, ":/"+smfile);
#endif #endif
} }
// init <img> embedder
defEmbedImg.InitFromAwkwardHash(smileys);
} }
void PeersDialog::smileyWidgetgroupchat() void PeersDialog::smileyWidgetgroupchat()
@ -1615,13 +1606,13 @@ void PeersDialog::fileHashingFinished(AttachFileItem* file) {
} }
//convert fileSize from uint_64 to string for html link //convert fileSize from uint_64 to string for html link
char fileSizeChar [100]; // char fileSizeChar [100];
sprintf(fileSizeChar, "%lld", file->FileSize()); // sprintf(fileSizeChar, "%lld", file->FileSize());
std::string fileSize = *(&fileSizeChar); // std::string fileSize = *(&fileSizeChar);
std::string mesgString = RetroShareLink(QString::fromStdString(file->FileName()), std::string mesgString = RetroShareLink(QString::fromStdString(file->FileName()),
file->FileSize(), file->FileSize(),
QString::fromStdString(file->FileHash())).toHtml().toStdString() ; QString::fromStdString(file->FileHash())).toHtml().toStdString() ;
// std::string mesgString = "<a href='retroshare://file|" + (file->FileName()) + "|" + fileSize + "|" + (file->FileHash()) + "'>" // std::string mesgString = "<a href='retroshare://file|" + (file->FileName()) + "|" + fileSize + "|" + (file->FileHash()) + "'>"
// + "retroshare://file|" + (file->FileName()) + "|" + fileSize + "|" + (file->FileHash()) + "</a>"; // + "retroshare://file|" + (file->FileName()) + "|" + fileSize + "|" + (file->FileHash()) + "</a>";
@ -1633,13 +1624,13 @@ void PeersDialog::fileHashingFinished(AttachFileItem* file) {
//convert char massageString to w_char //convert char massageString to w_char
wchar_t* message; 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 */ /* Add one to leave room for the NULL terminator */
message = (wchar_t *)malloc( (requiredSize + 1) * sizeof( wchar_t )); message = (wchar_t *)malloc( (requiredSize + 1) * sizeof( wchar_t ));
if (! message) { if (! message) {
std::cerr << ("Memory allocation failure.\n"); 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)) { if (size == (size_t) (-1)) {
printf("Couldn't convert string--invalid multibyte character.\n"); printf("Couldn't convert string--invalid multibyte character.\n");
} }

View File

@ -25,6 +25,7 @@
#include <QFileDialog> #include <QFileDialog>
#include "chat/PopupChatDialog.h" #include "chat/PopupChatDialog.h"
#include "chat/HandleRichText.h"
#include "RsAutoUpdatePage.h" #include "RsAutoUpdatePage.h"
#include "mainpage.h" #include "mainpage.h"
@ -149,6 +150,15 @@ private:
class QWidgetAction *widgetAction; class QWidgetAction *widgetAction;
class QSpacerItem *spacerItem; 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 */ /* Worker Functions */
/* (1) Update Display */ /* (1) Update Display */
@ -174,7 +184,7 @@ private:
QColor _currentColor; QColor _currentColor;
bool _underline; bool _underline;
time_t last_status_send_time ; time_t last_status_send_time ;
QHash<QString, QString> smileys; QHash<QString, QString> smileys;
std::map<std::string, PopupChatDialog *> chatDialogs; std::map<std::string, PopupChatDialog *> chatDialogs;
@ -188,5 +198,5 @@ private:
Ui::PeersDialog ui; Ui::PeersDialog ui;
}; };
#endif
#endif

View File

@ -1242,25 +1242,8 @@ void ChanMsgDialog::fileHashingFinished(AttachFileItem* file) {
std::cerr << "ChanMsgDialog::anchorClicked mesgString : " << mesgString << std::endl; std::cerr << "ChanMsgDialog::anchorClicked mesgString : " << mesgString << std::endl;
#endif #endif
const char * messageString = mesgString.c_str (); ui.msgText->textCursor().insertHtml(QString::fromStdString(mesgString));
//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->setFocus( Qt::OtherFocusReason ); ui.msgText->setFocus( Qt::OtherFocusReason );
} }
void ChanMsgDialog::checkAttachmentReady() void ChanMsgDialog::checkAttachmentReady()