diff --git a/libretroshare/src/ft/ftcontroller.cc b/libretroshare/src/ft/ftcontroller.cc index 9b82888b3..eaca0383b 100644 --- a/libretroshare/src/ft/ftcontroller.cc +++ b/libretroshare/src/ft/ftcontroller.cc @@ -930,6 +930,11 @@ bool ftController::FileRequest(std::string fname, std::string hash, uint64_t size, std::string dest, uint32_t flags, std::list &srcIds) { + /* check if we have the file */ + + if(alreadyHaveFile(hash)) + return false ; + if(size == 0) // we treat this special case because { /* if no destpath - send to download directory */ @@ -968,11 +973,6 @@ bool ftController::FileRequest(std::string fname, std::string hash, } } - /* check if we have the file */ - - if(alreadyHaveFile(hash)) - return true ; - FileInfo info; std::list::iterator it; std::list::iterator pit; diff --git a/retroshare-gui/src/gui/PeersDialog.cpp b/retroshare-gui/src/gui/PeersDialog.cpp index 07e433c9e..6cc33bd54 100644 --- a/retroshare-gui/src/gui/PeersDialog.cpp +++ b/retroshare-gui/src/gui/PeersDialog.cpp @@ -142,8 +142,12 @@ PeersDialog::PeersDialog(QWidget *parent) connect(ui.Sendbtn, SIGNAL(clicked()), this, SLOT(sendMsg())); connect(ui.emoticonBtn, SIGNAL(clicked()), this, SLOT(smileyWidgetgroupchat())); + ui.lineEdit->setContextMenuPolicy(Qt::CustomContextMenu) ; + connect(ui.lineEdit,SIGNAL(customContextMenuRequested(QPoint)),this,SLOT(contextMenu(QPoint))); + + pasteLinkAct = new QAction(QIcon(":/images/pasterslink.png"), tr( "Paste retroshare Link" ), this ); + connect( pasteLinkAct , SIGNAL( triggered() ), this, SLOT( pasteLink() ) ); - //connect( ui.msgSendList, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( msgSendListCostumPopupMenu( QPoint ) ) ); connect( ui.msgText, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayInfoChatMenu(const QPoint&))); connect(ui.textboldChatButton, SIGNAL(clicked()), this, SLOT(setFont())); @@ -211,6 +215,23 @@ PeersDialog::PeersDialog(QWidget *parent) #endif } +void PeersDialog::pasteLink() +{ + ui.lineEdit->insertHtml(RSLinkClipboard::toHtml()) ; +} + +void PeersDialog::contextMenu( QPoint point ) +{ + if(RSLinkClipboard::empty()) + return ; + + QMenu contextMnu(this); + contextMnu.addAction( pasteLinkAct); + + QMouseEvent mevent(QEvent::MouseButtonPress, point, Qt::RightButton, Qt::RightButton, Qt::NoModifier); + contextMnu.exec( mevent.globalPos() ); +} + void PeersDialog::peertreeWidgetCostumPopupMenu( QPoint point ) { QTreeWidgetItem *c = getCurrentPeer(); @@ -300,8 +321,6 @@ void PeersDialog::peertreeWidgetCostumPopupMenu( QPoint point ) contextMnu.addAction( expandAll); contextMnu.addAction( collapseAll); contextMnu.exec( mevent->globalPos() ); - - } void PeersDialog::keyPressEvent(QKeyEvent *e) @@ -1600,11 +1619,15 @@ void PeersDialog::fileHashingFinished(AttachFileItem* file) { sprintf(fileSizeChar, "%lld", file->FileSize()); std::string fileSize = *(&fileSizeChar); - std::string mesgString = "" - + "retroshare://file|" + (file->FileName()) + "|" + fileSize + "|" + (file->FileHash()) + ""; - #ifdef PEERS_DEBUG - std::cerr << "PeersDialog::fileHashingFinished mesgString : " << mesgString << std::endl; - #endif + std::string mesgString = RetroShareLink(QString::fromStdString(file->FileName()), + file->FileSize(), + QString::fromStdString(file->FileHash())).toHtml().toStdString() ; + +// std::string mesgString = "" +// + "retroshare://file|" + (file->FileName()) + "|" + fileSize + "|" + (file->FileHash()) + ""; +#ifdef PEERS_DEBUG + std::cerr << "PeersDialog::fileHashingFinished mesgString : " << mesgString << std::endl; +#endif const char * messageString = mesgString.c_str (); diff --git a/retroshare-gui/src/gui/PeersDialog.h b/retroshare-gui/src/gui/PeersDialog.h index 4cf507a8c..606f78099 100644 --- a/retroshare-gui/src/gui/PeersDialog.h +++ b/retroshare-gui/src/gui/PeersDialog.h @@ -86,6 +86,8 @@ protected: virtual void dropEvent(QDropEvent *event); private slots: + void pasteLink() ; + void contextMenu(QPoint) ; /** Create the context popup menu and it's submenus */ void peertreeWidgetCostumPopupMenu( QPoint point ); @@ -157,6 +159,7 @@ private: QMenu* contextMnu; /** Defines the actions for the context menu */ QAction* chatAct; + QAction* pasteLinkAct; QAction* msgAct; QAction* connectfriendAct; QAction* profileviewAct; diff --git a/retroshare-gui/src/gui/RetroShareLink.cpp b/retroshare-gui/src/gui/RetroShareLink.cpp index fc1ea2ec5..c0716d804 100644 --- a/retroshare-gui/src/gui/RetroShareLink.cpp +++ b/retroshare-gui/src/gui/RetroShareLink.cpp @@ -98,7 +98,7 @@ QString RetroShareLink::toString() const } QString RetroShareLink::toHtml() const { - return QString("" + toString() + "" ; + return QString("" + name() + "" ; } bool RetroShareLink::checkName(const QString& name) diff --git a/retroshare-gui/src/gui/TransfersDialog.cpp b/retroshare-gui/src/gui/TransfersDialog.cpp index df864def5..a82987734 100644 --- a/retroshare-gui/src/gui/TransfersDialog.cpp +++ b/retroshare-gui/src/gui/TransfersDialog.cpp @@ -739,48 +739,49 @@ void TransfersDialog::insertTransfers() std::set used_rows ; - for (pit = info.peers.begin(); pit != info.peers.end(); pit++) - { - QString peerName = getPeerName(pit->peerId); - //unique combination: fileHash + peerId, variant: hash + peerName (too long) - QString hashFileAndPeerId = fileHash + QString::fromStdString(pit->peerId); - QString version; - if (retv && versions.end() != (vit = versions.find(pit->peerId))) { - version = tr("version: ") + QString::fromStdString(vit->second); + if(info.downloadStatus != FT_STATE_COMPLETE) + for (pit = info.peers.begin(); pit != info.peers.end(); pit++) + { + QString peerName = getPeerName(pit->peerId); + //unique combination: fileHash + peerId, variant: hash + peerName (too long) + QString hashFileAndPeerId = fileHash + QString::fromStdString(pit->peerId); + QString version; + if (retv && versions.end() != (vit = versions.find(pit->peerId))) { + version = tr("version: ") + QString::fromStdString(vit->second); + } + + QString status; + switch (pit->status) { + case FT_STATE_FAILED: status = tr("Failed"); break; + case FT_STATE_OKAY: status = tr("Okay"); break; + case FT_STATE_WAITING: status = tr(""); break; + case FT_STATE_DOWNLOADING: status = tr("Downloading"); break; + case FT_STATE_COMPLETE: status = tr("Complete"); break; + default: status = tr(""); break; + } + double peerDlspeed = 0; + if ((uint32_t)pit->status == FT_STATE_DOWNLOADING && info.downloadStatus != FT_STATE_PAUSED && info.downloadStatus != FT_STATE_COMPLETE) + peerDlspeed = pit->tfRate * 1024.0; + + FileProgressInfo peerpinfo ; + peerpinfo.cmap = fcinfo.compressed_peer_availability_maps[pit->peerId]; + peerpinfo.type = FileProgressInfo::DOWNLOAD_SOURCE ; + peerpinfo.progress = 0.0 ; // we don't display completion for sources. + peerpinfo.nb_chunks = peerpinfo.cmap._map.empty()?0:fcinfo.chunks.size(); + + // std::cerr << std::endl ; + // std::cerr << "Source " << pit->peerId << " as map " << peerpinfo.cmap._map.size() << " compressed chunks" << std::endl ; + // for(uint j=0;jstatus == FT_STATE_DOWNLOADING && info.downloadStatus != FT_STATE_PAUSED) - peerDlspeed = pit->tfRate * 1024.0; - - FileProgressInfo peerpinfo ; - peerpinfo.cmap = fcinfo.compressed_peer_availability_maps[pit->peerId]; - peerpinfo.type = FileProgressInfo::DOWNLOAD_SOURCE ; - peerpinfo.progress = 0.0 ; // we don't display completion for sources. - peerpinfo.nb_chunks = peerpinfo.cmap._map.empty()?0:fcinfo.chunks.size(); - - // std::cerr << std::endl ; - // std::cerr << "Source " << pit->peerId << " as map " << peerpinfo.cmap._map.size() << " compressed chunks" << std::endl ; - // for(uint j=0;j #include #include @@ -53,6 +54,7 @@ /***** * #define CHAT_DEBUG 1 *****/ +#define CHAT_DEBUG 1 /** Default constructor */ PopupChatDialog::PopupChatDialog(std::string id, std::string name, @@ -96,6 +98,10 @@ PopupChatDialog::PopupChatDialog(std::string id, std::string name, connect(ui.textBrowser, SIGNAL(anchorClicked(const QUrl &)), SLOT(anchorClicked(const QUrl &))); + std::cerr << "Connecting custom context menu" << std::endl; + ui.chattextEdit->setContextMenuPolicy(Qt::CustomContextMenu) ; + connect(ui.chattextEdit,SIGNAL(customContextMenuRequested(QPoint)),this,SLOT(contextMenu(QPoint))); + // Create the status bar resetStatusBar() ; @@ -136,10 +142,32 @@ PopupChatDialog::PopupChatDialog(std::string id, std::string name, colorChanged(mCurrentColor); setFont(); + pasteLinkAct = new QAction(QIcon(":/images/pasterslink.png"), tr( "Paste retroshare Link" ), this ); + connect( pasteLinkAct , SIGNAL( triggered() ), this, SLOT( pasteLink() ) ); + updateAvatar() ; updatePeerAvatar(id) ; } +void PopupChatDialog::pasteLink() +{ + std::cerr << "In paste link" << std::endl ; + ui.chattextEdit->insertHtml(RSLinkClipboard::toHtml()) ; +} + +void PopupChatDialog::contextMenu( QPoint point ) +{ + std::cerr << "In context menu" << std::endl ; + if(RSLinkClipboard::empty()) + return ; + + QMenu contextMnu(this); + contextMnu.addAction( pasteLinkAct); + + QMouseEvent mevent(QEvent::MouseButtonPress, point, Qt::RightButton, Qt::RightButton, Qt::NoModifier); + contextMnu.exec( mevent.globalPos() ); +} + void PopupChatDialog::resetStatusBar() { statusBar()->showMessage(tr("Chatting with ") + QString::fromStdString(dialogName)) ; @@ -732,7 +760,8 @@ void PopupChatDialog::addExtraFile() } } -void PopupChatDialog::addAttachment(std::string filePath) { +void PopupChatDialog::addAttachment(std::string filePath) +{ /* add a AttachFileItem to the attachment section */ std::cerr << "PopupChatDialog::addExtraFile() hashing file."; std::cerr << std::endl; @@ -751,7 +780,8 @@ void PopupChatDialog::addAttachment(std::string filePath) { } } -void PopupChatDialog::fileHashingFinished(AttachFileItem* file) { +void PopupChatDialog::fileHashingFinished(AttachFileItem* file) +{ std::cerr << "PopupChatDialog::fileHashingFinished() started."; std::cerr << std::endl; @@ -781,7 +811,10 @@ void PopupChatDialog::fileHashingFinished(AttachFileItem* file) { sprintf(fileSizeChar, "%lld", file->FileSize()); std::string fileSize = *(&fileSizeChar); - std::string mesgString = "" + (file->FileName()) + ""; +// std::string mesgString = "" + (file->FileName()) + ""; + + std::string mesgString = RetroShareLink(QString::fromStdString(file->FileName()),file->FileSize(),QString::fromStdString(file->FileHash())).toHtml().toStdString() ; + #ifdef CHAT_DEBUG std::cerr << "PopupChatDialog::anchorClicked mesgString : " << mesgString << std::endl; #endif @@ -813,44 +846,38 @@ void PopupChatDialog::fileHashingFinished(AttachFileItem* file) { rsMsgs -> ChatSend(ci); } -void PopupChatDialog::anchorClicked (const QUrl& link ) { +void PopupChatDialog::anchorClicked (const QUrl& link ) +{ #ifdef CHAT_DEBUG std::cerr << "PopupChatDialog::anchorClicked link.scheme() : " << link.scheme().toStdString() << std::endl; #endif - if (link.scheme() == "file") { - 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 - if (fileName != "" && - fileHash != "") { - std::list srcIds; - srcIds.push_front(dialogId); - 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, or you're already downloading it."),QMessageBox::Information,QMessageBox::Ok,0,0); - mb.setButtonText( QMessageBox::Ok, "OK" ); - mb.exec(); - } - } - else + if(link.scheme() == "retroshare") + { + RetroShareLink rslink(link) ; + + if(!rslink.valid()) { - QMessageBox mb(tr("File Request Error"), tr("The file link is malformed."),QMessageBox::Information,QMessageBox::Ok,0,0); + QMessageBox mb(tr("Badly formed RS link"), tr("This RetroShare link is malformed. This is bug. Please contact the developers."),QMessageBox::Information,QMessageBox::Ok,0,0); + mb.setButtonText( QMessageBox::Ok, "OK" ); + mb.exec(); + return ; + } + + if(rsFiles->FileRequest(rslink.name().toStdString(), rslink.hash().toStdString(), rslink.size(), "", RS_FILE_HINTS_NETWORK_WIDE, std::list())) + { + 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, or you're already downloading it."),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() == "") @@ -860,7 +887,6 @@ void PopupChatDialog::anchorClicked (const QUrl& link ) { newAddress.prepend("http://"); QDesktopServices::openUrl(QUrl(newAddress)); } - } void PopupChatDialog::dropEvent(QDropEvent *event) diff --git a/retroshare-gui/src/gui/chat/PopupChatDialog.h b/retroshare-gui/src/gui/chat/PopupChatDialog.h index 4281c8bcd..959e6acdb 100644 --- a/retroshare-gui/src/gui/chat/PopupChatDialog.h +++ b/retroshare-gui/src/gui/chat/PopupChatDialog.h @@ -72,6 +72,8 @@ public slots: void getfocus(); void flash(); + void pasteLink() ; + void contextMenu(QPoint) ; void smileyWidget(); void addSmiley(); @@ -115,6 +117,7 @@ private: QAction *actionTextBold; QAction *actionTextUnderline; QAction *actionTextItalic; + QAction *pasteLinkAct ; std::string dialogId, dialogName; unsigned int lastChatTime;