From 1600831e16b53a32a5c2e2b9aa9828e4b5606feb Mon Sep 17 00:00:00 2001 From: defnax Date: Sun, 31 Jan 2010 22:29:30 +0000 Subject: [PATCH] Added attaching files to Public Chat via Button/Drag and Drop git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@2168 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- retroshare-gui/src/gui/PeersDialog.cpp | 248 ++++++++- retroshare-gui/src/gui/PeersDialog.h | 24 +- retroshare-gui/src/gui/PeersDialog.ui | 534 ++++++++++++------- retroshare-gui/src/gui/SharedFilesDialog.cpp | 7 - 4 files changed, 593 insertions(+), 220 deletions(-) diff --git a/retroshare-gui/src/gui/PeersDialog.cpp b/retroshare-gui/src/gui/PeersDialog.cpp index 5272fc39b..2a3244140 100644 --- a/retroshare-gui/src/gui/PeersDialog.cpp +++ b/retroshare-gui/src/gui/PeersDialog.cpp @@ -45,6 +45,7 @@ #include #include +#include #include #include @@ -62,7 +63,8 @@ #include #include #include - +#include +#include /* Images for context menu icons */ #define IMAGE_REMOVEFRIEND ":/images/removefriend16.png" @@ -106,10 +108,12 @@ PeersDialog::PeersDialog(QWidget *parent) connect( ui.mypersonalstatuslabel, SIGNAL(clicked()), SLOT(statusmessage())); connect( ui.actionSet_your_Avatar, SIGNAL(triggered()), this, SLOT(getAvatar())); connect( ui.actionSet_your_Personal_Message, SIGNAL(triggered()), this, SLOT(statusmessage())); + connect( ui.addfileButton, SIGNAL(clicked() ), this , SLOT(addExtraFile())); + connect( ui.msgText, SIGNAL(anchorClicked(const QUrl &)), SLOT(anchorClicked(const QUrl &))); connect(ui.hide_unconnected, SIGNAL(clicked()), this, SLOT(insertPeers())); - ui.peertabWidget->setTabPosition(QTabWidget::East); + ui.peertabWidget->setTabPosition(QTabWidget::North); ui.peertabWidget->addTab(new ProfileWidget(),QString(tr("Profile"))); ui.peertreeWidget->setColumnCount(4); @@ -133,8 +137,6 @@ PeersDialog::PeersDialog(QWidget *parent) headerItem->setTextAlignment(1, Qt::AlignLeft | Qt::AlignVCenter); headerItem->setTextAlignment(2, Qt::AlignHCenter | Qt::AlignVCenter); - loadEmoticonsgroupchat(); - connect(ui.lineEdit, SIGNAL(textChanged ( ) ), this, SLOT(checkChat( ) )); connect(ui.Sendbtn, SIGNAL(clicked()), this, SLOT(sendMsg())); connect(ui.emoticonBtn, SIGNAL(clicked()), this, SLOT(smileyWidgetgroupchat())); @@ -189,8 +191,15 @@ PeersDialog::PeersDialog(QWidget *parent) ui.menupushButton->setMenu(menu); + ui.msgText->setOpenExternalLinks ( false ); + ui.msgText->setOpenLinks ( false ); + + setAcceptDrops(true); + ui.lineEdit->setAcceptDrops(false); + updateAvatar(); loadmypersonalstatus(); + loadEmoticonsgroupchat(); /* Hide platform specific features */ #ifdef Q_WS_WIN @@ -1481,3 +1490,234 @@ void PeersDialog::statusmessage() static StatusMessage *statusmsgdialog = new StatusMessage(); statusmsgdialog->show(); } + +void PeersDialog::addExtraFile() +{ + // select a file + QString qfile = QFileDialog::getOpenFileName(this, tr("Add Extra File"), "", "", 0, + QFileDialog::DontResolveSymlinks); + std::string filePath = qfile.toStdString(); + if (filePath != "") + { + PeersDialog::addAttachment(filePath); + } +} + +void PeersDialog::addAttachment(std::string filePath) { + /* add a AttachFileItem to the attachment section */ + std::cerr << "PopupChatDialog::addExtraFile() hashing file."; + std::cerr << std::endl; + + /* add widget in for new destination */ + AttachFileItem *file = new AttachFileItem(filePath); + //file-> + + ui.verticalLayout->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() == AFI_STATE_LOCAL) { + fileHashingFinished(file); + } else { + QObject::connect(file,SIGNAL(fileFinished(AttachFileItem *)), SLOT(fileHashingFinished(AttachFileItem *))) ; + } +} + +void PeersDialog::fileHashingFinished(AttachFileItem* file) { + std::cerr << "PopupChatDialog::fileHashingFinished() started."; + std::cerr << std::endl; + + //check that the file is ok tos end + if (file->getState() == AFI_STATE_ERROR) { + #ifdef CHAT_DEBUG + std::cerr << "PopupChatDialog::fileHashingFinished error file is not hashed."; + #endif + return; + } + + 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 = "" + + "retroshare://file|" + (file->FileName()) + "|" + fileSize + "|" + (file->FileHash()) + ""; +#ifdef CHAT_DEBUG + std::cerr << "CreateForumMsg::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_PUBLIC; + + rsMsgs -> ChatSend(ci); + setFont(); +} + +void PeersDialog::anchorClicked (const QUrl& link ) +{ + #ifdef FORUM_DEBUG + std::cerr << "ForumsDialog::anchorClicked link.scheme() : " << link.scheme().toStdString() << std::endl; + #endif + + if (link.scheme() == "retroshare") + { + QStringList L = link.toString().split("|") ; + + std::string fileName = L.at(1).toStdString() ; + uint64_t fileSize = L.at(2).toULongLong(); + std::string fileHash = L.at(3).toStdString() ; + +#ifdef FORUM_DEBUG + std::cerr << "ForumsDialog::anchorClicked FileRequest : fileName : " << fileName << ". fileHash : " << fileHash << ". fileSize : " << fileSize << std::endl; +#endif + + if (fileName != "" && fileHash != "") + { + std::list srcIds; + + if(rsFiles->FileRequest(fileName, fileHash, fileSize, "", RS_FILE_HINTS_NETWORK_WIDE, srcIds)) + { + QMessageBox mb(tr("File Request Confirmation"), tr("The file has been added to your download list."),QMessageBox::Information,QMessageBox::Ok,0,0); + mb.setButtonText( QMessageBox::Ok, "OK" ); + mb.exec(); + } + else + { + QMessageBox mb(tr("File Request canceled"), tr("The file has not been added to your download list, because you already have it."),QMessageBox::Information,QMessageBox::Ok,0,0); + mb.setButtonText( QMessageBox::Ok, "OK" ); + mb.exec(); + } + } + else + { + QMessageBox mb(tr("File Request Error"), tr("The file link is malformed."),QMessageBox::Information,QMessageBox::Ok,0,0); + mb.setButtonText( QMessageBox::Ok, "OK" ); + mb.exec(); + } + } + else if (link.scheme() == "http") + { + QDesktopServices::openUrl(link); + } + else if (link.scheme() == "") + { + //it's probably a web adress, let's add http:// at the beginning of the link + QString newAddress = link.toString(); + newAddress.prepend("http://"); + QDesktopServices::openUrl(QUrl(newAddress)); + } +} + +void PeersDialog::dropEvent(QDropEvent *event) +{ + if (!(Qt::CopyAction & event->possibleActions())) + { + std::cerr << "PeersDialog::dropEvent() Rejecting uncopyable DropAction"; + std::cerr << std::endl; + + /* can't do it */ + return; + } + + std::cerr << "PeersDialog::dropEvent() Formats"; + std::cerr << std::endl; + QStringList formats = event->mimeData()->formats(); + QStringList::iterator it; + for(it = formats.begin(); it != formats.end(); it++) + { + std::cerr << "Format: " << (*it).toStdString(); + std::cerr << std::endl; + } + + if (event->mimeData()->hasUrls()) + { + std::cerr << "PeersDialog::dropEvent() Urls:"; + std::cerr << std::endl; + + QList urls = event->mimeData()->urls(); + QList::iterator uit; + for(uit = urls.begin(); uit != urls.end(); uit++) + { + std::string localpath = uit->toLocalFile().toStdString(); + std::cerr << "Whole URL: " << uit->toString().toStdString(); + std::cerr << std::endl; + std::cerr << "or As Local File: " << localpath; + std::cerr << std::endl; + + if (localpath.size() > 0) + { + struct stat buf; + //Check that the file does exist and is not a directory + if ((-1 == stat(localpath.c_str(), &buf))) { + std::cerr << "PeersDialog::dropEvent() file does not exists."<< std::endl; + QMessageBox mb(tr("Drop file error."), tr("File not found or file name not accepted."),QMessageBox::Information,QMessageBox::Ok,0,0); + mb.setButtonText( QMessageBox::Ok, "OK" ); + mb.exec(); + } else if (S_ISDIR(buf.st_mode)) { + std::cerr << "PeersDialog::dropEvent() directory not accepted."<< std::endl; + QMessageBox mb(tr("Drop file error."), tr("Directory can't be dropped, only files are accepted."),QMessageBox::Information,QMessageBox::Ok,0,0); + mb.setButtonText( QMessageBox::Ok, "OK" ); + mb.exec(); + } else { + PeersDialog::addAttachment(localpath); + } + } + } + } + + event->setDropAction(Qt::CopyAction); + event->accept(); +} + +void PeersDialog::dragEnterEvent(QDragEnterEvent *event) +{ + /* print out mimeType */ + std::cerr << "PeersDialog::dragEnterEvent() Formats"; + std::cerr << std::endl; + QStringList formats = event->mimeData()->formats(); + QStringList::iterator it; + for(it = formats.begin(); it != formats.end(); it++) + { + std::cerr << "Format: " << (*it).toStdString(); + std::cerr << std::endl; + } + + if (event->mimeData()->hasUrls()) + { + std::cerr << "PeersDialog::dragEnterEvent() Accepting Urls"; + std::cerr << std::endl; + event->acceptProposedAction(); + } + else + { + std::cerr << "PeersDialog::dragEnterEvent() No Urls"; + std::cerr << std::endl; + } +} diff --git a/retroshare-gui/src/gui/PeersDialog.h b/retroshare-gui/src/gui/PeersDialog.h index 7d497cc14..4cf507a8c 100644 --- a/retroshare-gui/src/gui/PeersDialog.h +++ b/retroshare-gui/src/gui/PeersDialog.h @@ -42,7 +42,7 @@ class PeersDialog : public RsAutoUpdatePage { Q_OBJECT - public: +public: /** Default Constructor */ PeersDialog(QWidget *parent = 0); /** Default Destructor */ @@ -57,7 +57,7 @@ class PeersDialog : public RsAutoUpdatePage virtual void updateDisplay() ; // overloaded from RsAutoUpdatePage virtual void keyPressEvent(QKeyEvent *) ; - public slots: +public slots: void insertPeers(); void toggleSendItem( QTreeWidgetItem *item, int col ); @@ -66,6 +66,7 @@ class PeersDialog : public RsAutoUpdatePage void setChatInfo(QString info, QColor color=QApplication::palette().color(QPalette::WindowText)); void resetStatusBar() ; + void fileHashingFinished(AttachFileItem* file); void smileyWidgetgroupchat(); void addSmileys(); @@ -79,11 +80,15 @@ class PeersDialog : public RsAutoUpdatePage void updatePeersCustomStateString(const QString& peer_id) ; void updatePeersAvatar(const QString& peer_id); void updateAvatar(); // called by notifyQt to update the avatar when it gets changed by another component + +protected: + virtual void dragEnterEvent(QDragEnterEvent *event); + virtual void dropEvent(QDropEvent *event); - private slots: +private slots: - /** Create the context popup menu and it's submenus */ - void peertreeWidgetCostumPopupMenu( QPoint point ); + /** Create the context popup menu and it's submenus */ + void peertreeWidgetCostumPopupMenu( QPoint point ); void updateStatusString(const QString& statusString) ; // called when a peer is typing in group chat void updateStatusTyping() ; // called each time a key is hit @@ -114,8 +119,6 @@ class PeersDialog : public RsAutoUpdatePage void statusmessage(); - //void privchat(); - void setFont(); void getFont(); void underline(); @@ -128,12 +131,17 @@ class PeersDialog : public RsAutoUpdatePage void on_actionCreate_New_Channel_activated(); void loadmypersonalstatus(); + + void addExtraFile(); + void anchorClicked (const QUrl &); + void addAttachment(std::string); + signals: void friendsUpdated() ; void notifyGroupChat(const QString&,const QString&) ; - private: +private: class QLabel *iconLabel, *textLabel; class QWidget *widget; class QWidgetAction *widgetAction; diff --git a/retroshare-gui/src/gui/PeersDialog.ui b/retroshare-gui/src/gui/PeersDialog.ui index d6203e519..d1792b50a 100644 --- a/retroshare-gui/src/gui/PeersDialog.ui +++ b/retroshare-gui/src/gui/PeersDialog.ui @@ -864,207 +864,336 @@ background: white;} - - - - - - - - - - - - Qt::Horizontal - - - - 88 - 21 - - - - - - - - - 24 - 24 - - - - - 24 - 24 - - - - - - - - :/images/emoticons/kopete/kopete020.png:/images/emoticons/kopete/kopete020.png - - - - 24 - 24 - - - - - - - - - 24 - 24 - - - - - 24 - 24 - - - - Bold - - - - - - - :/images/edit-bold.png:/images/edit-bold.png - - - true - - - - - - - - 24 - 24 - - - - - 24 - 24 - - - - Underline - - - - - - - :/images/edit-underline.png:/images/edit-underline.png - - - true - - - - - - - - 24 - 24 - - - - - 24 - 24 - - - - Italic - - - - - - - :/images/edit-italic.png:/images/edit-italic.png - - - true - - - - - - - - 24 - 24 - - - - - 24 - 24 - - - - Font - - - - - - - - - - - 24 - 24 - - - - - 24 - 24 - - - - Text Color - - - - - - - - - - - 24 - 24 - - - - - 24 - 24 - - - - - - - - + + + + 16777215 + 38 + + + + QFrame#buttonframe{ +background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1, + stop:0 #FEFEFE, stop:1 #E8E8E8); + +border: 1px solid #CCCCCC;} + + + + 6 + + + + + + + + + + + + Qt::Horizontal + + + + 88 + 21 + + + + + + + + + 0 + 0 + + + + + 24 + 24 + + + + + 24 + 24 + + + + + + + + :/images/emoticons/kopete/kopete020.png:/images/emoticons/kopete/kopete020.png + + + + 24 + 24 + + + + true + + + + + + + + 0 + 0 + + + + + 24 + 24 + + + + + 24 + 24 + + + + Bold + + + + + + + :/images/edit-bold.png:/images/edit-bold.png + + + true + + + true + + + + + + + + 0 + 0 + + + + + 24 + 24 + + + + + 24 + 24 + + + + Underline + + + + + + + :/images/edit-underline.png:/images/edit-underline.png + + + true + + + true + + + + + + + + 0 + 0 + + + + + 24 + 24 + + + + + 24 + 24 + + + + Italic + + + + + + + :/images/edit-italic.png:/images/edit-italic.png + + + true + + + true + + + + + + + + 0 + 0 + + + + + 24 + 24 + + + + + 24 + 24 + + + + Font + + + + + + true + + + + + + + + 0 + 0 + + + + + 24 + 24 + + + + + 24 + 24 + + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<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;"><span style=" font-size:8pt;">set Text Color</span></p></body></html> + + + + + + true + + + + + + + + 0 + 0 + + + + + 24 + 24 + + + + + 24 + 24 + + + + + + + QToolButton::MenuButtonPopup + + + false + + + + + + + + 0 + 0 + + + + + 26 + 26 + + + + + 26 + 26 + + + + Attach File + + + + + + + :/images/add-share24.png:/images/add-share24.png + + + + 24 + 24 + + + + true + + + + + @@ -1122,6 +1251,9 @@ background: white;} + + + diff --git a/retroshare-gui/src/gui/SharedFilesDialog.cpp b/retroshare-gui/src/gui/SharedFilesDialog.cpp index 5523d702c..be11c14a4 100644 --- a/retroshare-gui/src/gui/SharedFilesDialog.cpp +++ b/retroshare-gui/src/gui/SharedFilesDialog.cpp @@ -662,18 +662,11 @@ void SharedFilesDialog::sharedDirTreeWidgetContextMenu( QPoint point ) if(localModel->isDir( midx ) ) - { contextMnu2.addAction( openfolderAct); - contextMnu2.addSeparator(); - contextMnu2.addAction( copylinklocalAct); - contextMnu2.addAction( sendlinkAct); - contextMnu2.addAction( sendhtmllinkAct); - } else { contextMnu2.addAction( menuAction ); contextMnu2.addAction( openfileAct); - contextMnu2.addAction( openfolderAct); } contextMnu2.addSeparator();