From 8e6f082025fb8c271a51498063b1cdf6a155f959 Mon Sep 17 00:00:00 2001 From: joss17 Date: Wed, 6 May 2009 21:15:12 +0000 Subject: [PATCH] add file button to general message; add extra file sending from chat dialog; Add a link when sending a file; Add a link for downloading in the reciever chat dialog; Little gui improvement Merge branch 'extraFile' git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1181 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- retroshare-gui/src/gui/GeneralMsgDialog.cpp | 21 +- retroshare-gui/src/gui/GeneralMsgDialog.h | 1 + retroshare-gui/src/gui/GeneralMsgDialog.ui | 175 ++++---- .../src/gui/chat/PopupChatDialog.cpp | 107 ++++- retroshare-gui/src/gui/chat/PopupChatDialog.h | 11 +- .../src/gui/chat/PopupChatDialog.ui | 384 ++++++++++-------- retroshare-gui/src/gui/feeds/SubFileItem.cpp | 6 +- retroshare-gui/src/gui/feeds/SubFileItem.h | 5 + 8 files changed, 441 insertions(+), 269 deletions(-) diff --git a/retroshare-gui/src/gui/GeneralMsgDialog.cpp b/retroshare-gui/src/gui/GeneralMsgDialog.cpp index eab7b2472..401de8ad0 100644 --- a/retroshare-gui/src/gui/GeneralMsgDialog.cpp +++ b/retroshare-gui/src/gui/GeneralMsgDialog.cpp @@ -45,9 +45,11 @@ GeneralMsgDialog::GeneralMsgDialog(QWidget *parent, uint32_t type) connect(addButton, SIGNAL(clicked()), this, SLOT(newDestination())); connect(typeComboBox, SIGNAL(currentIndexChanged( int )), this, SLOT(updateGroupId())); - connect(buttonBox, SIGNAL(accepted()), this, SLOT(sendMsg())); + connect(buttonBox, SIGNAL(accepted()), this, SLOT(sendMsg())); connect(buttonBox, SIGNAL(rejected()), this, SLOT(cancelMsg())); + connect(addFileButton, SIGNAL(clicked() ), this , SLOT(addExtraFile())); + /* set the type to ... * const uint32_t GMD_TYPE_MESSAGE_IDX = 0; * const uint32_t GMD_TYPE_FORUM_IDX = 1; @@ -289,6 +291,23 @@ void GeneralMsgDialog::addAttachment(std::string hash, std::string fname, uint64 } +void GeneralMsgDialog::addExtraFile() +{ + /* add a SubFileItem to the attachment section */ + std::cerr << "GeneralMsgDialog::addExtraFile() opening file dialog"; + std::cerr << std::endl; + + // select a file + QString qfile = QFileDialog::getOpenFileName(this, tr("Add Extra File"), "", "", 0, + QFileDialog::DontResolveSymlinks); + std::string filePath = qfile.toStdString(); + if (filePath != "") + { + addAttachment(filePath); + } +} + + void GeneralMsgDialog::addAttachment(std::string path) { /* add a SubFileItem to the attachment section */ diff --git a/retroshare-gui/src/gui/GeneralMsgDialog.h b/retroshare-gui/src/gui/GeneralMsgDialog.h index 8a345c6bc..cf7464471 100644 --- a/retroshare-gui/src/gui/GeneralMsgDialog.h +++ b/retroshare-gui/src/gui/GeneralMsgDialog.h @@ -54,6 +54,7 @@ virtual void dragEnterEvent(QDragEnterEvent *event); virtual void dropEvent(QDropEvent *event); private slots: + void addExtraFile(); void checkAttachmentReady(); void updateGroupId(); void newDestination(); diff --git a/retroshare-gui/src/gui/GeneralMsgDialog.ui b/retroshare-gui/src/gui/GeneralMsgDialog.ui index 73f889d35..76ec356e6 100644 --- a/retroshare-gui/src/gui/GeneralMsgDialog.ui +++ b/retroshare-gui/src/gui/GeneralMsgDialog.ui @@ -1,7 +1,8 @@ - + + GeneralMsgDialog - - + + 0 0 @@ -9,37 +10,37 @@ 516 - + true - + Dialog - + - + - - + + true - + Friend - + Channel - + Forum - + Blog @@ -47,13 +48,13 @@ - + Qt::Horizontal - + QSizePolicy::Preferred - + 20 20 @@ -62,14 +63,14 @@ - + - + Qt::Horizontal - + 40 20 @@ -78,59 +79,60 @@ - - - + + + 0 0 - + Add Message Destination - + - - :/images/loadcert16.png + + + :/images/loadcert16.png:/images/loadcert16.png - - + + true - + QFrame::StyledPanel - + QFrame::Raised - + - + - - + + - - :/images/contacts24.png + + :/images/contacts24.png - + Qt::Horizontal - + QSizePolicy::Fixed - + 10 20 @@ -139,24 +141,24 @@ - - + + 75 true - + Message Destination - + Qt::Horizontal - + 271 20 @@ -170,122 +172,133 @@ - - + + 16 60 - + true - + Drag and Drop Files from Search Results - + QFrame::StyledPanel - + QFrame::Raised - + - + - - + + - - :/images/attachment.png + + :/images/attachment.png - + Qt::Horizontal - + QSizePolicy::Fixed - + - 10 + 13 20 - - + + 75 true - + Attachments - + Qt::Horizontal - + - 271 + 218 20 + + + + + + + + :/images/add-share24.png:/images/add-share24.png + + + - + - - + + 75 true - + Subject : - + - + - - + + Qt::Horizontal - - QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok - + @@ -294,11 +307,11 @@ GeneralMsgDialog accept() - + 248 254 - + 157 274 @@ -310,11 +323,11 @@ GeneralMsgDialog reject() - + 316 260 - + 286 274 diff --git a/retroshare-gui/src/gui/chat/PopupChatDialog.cpp b/retroshare-gui/src/gui/chat/PopupChatDialog.cpp index 3cb0d71b4..ffb462010 100644 --- a/retroshare-gui/src/gui/chat/PopupChatDialog.cpp +++ b/retroshare-gui/src/gui/chat/PopupChatDialog.cpp @@ -36,6 +36,9 @@ #include "rsiface/rspeers.h" #include "rsiface/rsmsgs.h" +#include "rsiface/rsfiles.h" + +#include "gui/feeds/SubFileItem.h" #define appDir QApplication::applicationDirPath() @@ -76,7 +79,8 @@ PopupChatDialog::PopupChatDialog(std::string id, std::string name, connect(ui.chattextEdit, SIGNAL(textChanged ( ) ), this, SLOT(checkChat( ) )); connect(ui.sendButton, SIGNAL(clicked( ) ), this, SLOT(sendChat( ) )); - + connect(ui.addFileButton, SIGNAL(clicked() ), this , SLOT(addExtraFile())); + connect(ui.textboldButton, SIGNAL(clicked()), this, SLOT(setFont())); connect(ui.textunderlineButton, SIGNAL(clicked()), this, SLOT(setFont())); connect(ui.textitalicButton, SIGNAL(clicked()), this, SLOT(setFont())); @@ -85,10 +89,13 @@ PopupChatDialog::PopupChatDialog(std::string id, std::string name, connect(ui.emoteiconButton, SIGNAL(clicked()), this, SLOT(smileyWidget())); connect(ui.styleButton, SIGNAL(clicked()), SLOT(changeStyle())); + connect(ui.textBrowser, SIGNAL(anchorClicked(const QUrl &)), SLOT(anchorClicked(const QUrl &))); + // Create the status bar resetStatusBar() ; ui.textBrowser->setOpenExternalLinks ( false ); + ui.textBrowser->setOpenLinks ( false ); QString title = QString::fromStdString(name) + " :" + tr(" RetroShare - Encrypted Chat") ; setWindowTitle(title); @@ -294,7 +301,7 @@ void PopupChatDialog::checkChat() void PopupChatDialog::sendChat() { - QTextEdit *chatWidget = ui.chattextEdit; + QTextEdit *chatWidget = ui.chattextEdit; ChatInfo ci; @@ -678,3 +685,99 @@ void PopupChatDialog::getAvatar() } } +void PopupChatDialog::addExtraFile() +{ + // select a file + QString qfile = QFileDialog::getOpenFileName(this, tr("Add Extra File"), "", "", 0, + QFileDialog::DontResolveSymlinks); + std::string filePath = qfile.toStdString(); + if (filePath != "") + { + /* add a SubFileItem to the attachment section */ + std::cerr << "PopupChatDialog::addExtraFile() hashing file."; + std::cerr << std::endl; + + /* add widget in for new destination */ + SubFileItem *file = new SubFileItem(filePath); + //file-> + + ui.SendLayout->addWidget(file, 1, 0); + + //when the file is local or is finished hashing, call the fileHashingFinished method to send a chat message + if (file->getState() == SFI_STATE_LOCAL) { + fileHashingFinished(file); + } else { + QObject::connect(file,SIGNAL(fileFinished(SubFileItem *)), SLOT(fileHashingFinished(SubFileItem *))) ; + } + + } +} + +void PopupChatDialog::fileHashingFinished(SubFileItem* file) { + std::cerr << "PopupChatDialog::fileHashingFinished() started."; + std::cerr << std::endl; + + ChatInfo ci; + + + { + rsiface->lockData(); /* Lock Interface */ + const RsConfig &conf = rsiface->getConfig(); + + ci.rsid = conf.ownId; + ci.name = conf.ownName; + + rsiface->unlockData(); /* Unlock Interface */ + } + + //convert fileSize from uint_64 to string for html link + char fileSizeChar [100]; + sprintf(fileSizeChar, "%lld", file->FileSize()); + std::string fileSize = *(&fileSizeChar); + + std::string mesgString = "" + (file->FileName()) + ""; +#ifdef CHAT_DEBUG + std::cerr << "PopupChatDialog::anchorClicked mesgString : " << mesgString << std::endl; +#endif + + const char * messageString = mesgString.c_str (); + + //convert char massageString to w_char + wchar_t* message; + int 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 + if (size == (size_t) (-1)) + { + printf("Couldn't convert string--invalid multibyte character.\n"); + } + + ci.msg = message; + ci.chatflags = RS_CHAT_PRIVATE; + + addChatMsg(&ci); + + /* put proper destination */ + ci.rsid = dialogId; + ci.name = dialogName; + + rsMsgs -> ChatSend(ci); +} + +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 + std::list srcIds; + srcIds.push_front(dialogId); + rsFiles->FileRequest(fileName, fileHash, fileSize, "", 0, srcIds); +} diff --git a/retroshare-gui/src/gui/chat/PopupChatDialog.h b/retroshare-gui/src/gui/chat/PopupChatDialog.h index 9e34c9e57..f23cfd343 100644 --- a/retroshare-gui/src/gui/chat/PopupChatDialog.h +++ b/retroshare-gui/src/gui/chat/PopupChatDialog.h @@ -30,6 +30,7 @@ #include #include "rsiface/rsiface.h" +#include "gui/feeds/SubFileItem.h" @@ -74,15 +75,19 @@ public slots: void addSmiley(); void changeStyle(); + void fileHashingFinished(SubFileItem* file); void resetStatusBar() ; void updateStatusTyping() ; void updateStatusString(const QString&) ; + void anchorClicked (const QUrl &); + + protected: void closeEvent (QCloseEvent * event); private slots: - + void addExtraFile(); void showAvatarFrame(bool show); void setColor(); @@ -95,7 +100,6 @@ private slots: void getAvatar(); - private: void colorChanged(const QColor &c); @@ -120,10 +124,9 @@ private: QStringList history; QString wholeChat; - - /** Qt Designer generated object */ Ui::PopupChatDialog ui; + }; #endif diff --git a/retroshare-gui/src/gui/chat/PopupChatDialog.ui b/retroshare-gui/src/gui/chat/PopupChatDialog.ui index 72ccb32ef..6cdcdfcc1 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,38 +10,35 @@ 437 - + MainWindow - - - + + + 0 - + 0 - + 0 - - 0 - - - - - + + + + 0 0 - + 0 0 - + 0 0 @@ -48,61 +46,61 @@ - - - + + + 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 +108,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 +155,42 @@ border-image: url(:/images/mystatus_bg.png); - - - - - + + + + + 14 31 - + 14 31 - + - + 16 31 - + true - + - + Qt::Vertical - + 14 321 @@ -202,33 +200,33 @@ border-image: url(:/images/mystatus_bg.png); - - - + + + 16 46 - + QFrame::StyledPanel - + QFrame::Raised - - + + 9 - + 6 - + - + Qt::Horizontal - + 190 25 @@ -236,30 +234,30 @@ border-image: url(:/images/mystatus_bg.png); - - - - + + + + 0 0 - + 28 28 - + 28 28 - + - + 24 24 @@ -267,30 +265,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 +296,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,107 +437,129 @@ p, li { white-space: pre-wrap; } - - - - + + + + 0 0 - - - + + + 0 - + 2 - + 2 - - 6 - - - - - Qt::Horizontal + + + + 0 - - - 351 - 20 - + + 2 - - - - - - Send + + 2 - + + + + + + + + :/images/add-share24.png:/images/add-share24.png + + + + + + + Qt::Horizontal + + + + 331 + 20 + + + + + + + + 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 - + diff --git a/retroshare-gui/src/gui/feeds/SubFileItem.cpp b/retroshare-gui/src/gui/feeds/SubFileItem.cpp index ffc3d02ac..70e4f0e1b 100644 --- a/retroshare-gui/src/gui/feeds/SubFileItem.cpp +++ b/retroshare-gui/src/gui/feeds/SubFileItem.cpp @@ -482,6 +482,7 @@ void SubFileItem::updateItem() } uint32_t repeat = 0; + switch (mMode) { case SFI_STATE_ERROR: @@ -505,6 +506,7 @@ void SubFileItem::updateItem() case SFI_STATE_LOCAL: repeat = 0; + emit fileFinished(this); break; case SFI_STATE_UPLOAD: @@ -644,4 +646,6 @@ void SubFileItem::save() } } - +uint32_t SubFileItem::getState() { + return mMode; +} diff --git a/retroshare-gui/src/gui/feeds/SubFileItem.h b/retroshare-gui/src/gui/feeds/SubFileItem.h index 7e75467b3..70a709304 100644 --- a/retroshare-gui/src/gui/feeds/SubFileItem.h +++ b/retroshare-gui/src/gui/feeds/SubFileItem.h @@ -63,6 +63,7 @@ public: bool done(); bool ready(); + uint32_t getState(); public slots: void download(); @@ -93,6 +94,10 @@ private: /* for display purposes */ float amountDone; + +signals: + void fileFinished(SubFileItem * subFileItem) const ; + };