From 633300c5cc778a153f8819bc07cbf669325e6f2d Mon Sep 17 00:00:00 2001 From: defnax Date: Thu, 21 Jan 2010 22:34:10 +0000 Subject: [PATCH] Added Copy and Send retroshare links for Search git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@2109 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- retroshare-gui/src/gui/SearchDialog.cpp | 66 +++++++++++++++++++++++-- retroshare-gui/src/gui/SearchDialog.h | 9 +++- 2 files changed, 70 insertions(+), 5 deletions(-) diff --git a/retroshare-gui/src/gui/SearchDialog.cpp b/retroshare-gui/src/gui/SearchDialog.cpp index 4ea5a7c68..4baed5c28 100644 --- a/retroshare-gui/src/gui/SearchDialog.cpp +++ b/retroshare-gui/src/gui/SearchDialog.cpp @@ -22,6 +22,9 @@ #include "rshare.h" #include "SearchDialog.h" +#include "RetroShareLinkAnalyzer.h" +#include "msgs/ChanMsgDialog.h" + #include "rsiface/rsiface.h" #include "rsiface/rsexpr.h" #include "rsiface/rsfiles.h" @@ -69,6 +72,8 @@ #define SS_COUNT_COL 1 #define SS_SEARCH_ID_COL 2 +#define IMAGE_COPYLINK ":/images/copyrslink.png" + /* static members */ /* These indices MUST be identical to their equivalent indices in the combobox */ const int SearchDialog::FILETYPE_IDX_ANY = 0; @@ -211,6 +216,12 @@ void SearchDialog::searchtableWidgetCostumPopupMenu( QPoint point ) downloadAct = new QAction(QIcon(IMAGE_START), tr( "Download" ), this ); connect( downloadAct , SIGNAL( triggered() ), this, SLOT( download() ) ); + copysearchlinkAct = new QAction(QIcon(IMAGE_COPYLINK), tr( "Copy retroshare Link" ), this ); + connect( copysearchlinkAct , SIGNAL( triggered() ), this, SLOT( copysearchLink() ) ); + + sendrslinkAct = new QAction(QIcon(IMAGE_COPYLINK), tr( "Send retroshare Link" ), this ); + connect( sendrslinkAct , SIGNAL( triggered() ), this, SLOT( sendLinkTo( ) ) ); + broadcastonchannelAct = new QAction( tr( "Broadcast on Channel" ), this ); connect( broadcastonchannelAct , SIGNAL( triggered() ), this, SLOT( broadcastonchannel() ) ); @@ -220,9 +231,9 @@ void SearchDialog::searchtableWidgetCostumPopupMenu( QPoint point ) contextMnu->clear(); contextMnu->addAction( downloadAct); - //contextMnu->addSeparator(); - //contextMnu->addAction( broadcastonchannelAct); - //contextMnu->addAction( recommendtofriendsAct); + contextMnu->addSeparator(); + contextMnu->addAction( copysearchlinkAct); + contextMnu->addAction( sendrslinkAct); } QMouseEvent *mevent = new QMouseEvent( QEvent::MouseButtonPress, point, @@ -936,3 +947,52 @@ void SearchDialog::setIconAndType(QTreeWidgetItem *item, QString &ext) item->setIcon(SR_ICON_COL, QIcon(":/images/FileTypeAny.png")); } } + +void SearchDialog::copysearchLink() +{ + RetroShareLinkAnalyzer analyzer; + + /* should also be able to handle multi-selection */ + QList itemsForCopy = ui.searchResultWidget->selectedItems(); + int numdls = itemsForCopy.size(); + QTreeWidgetItem * item; + + for (int i = 0; i < numdls; ++i) + { + item = itemsForCopy.at(i); + // call copy + + if (!item->childCount()) + { + std::cerr << "SearchDialog::copysearchLink() Calling set retroshare link"; + std::cerr << std::endl; + std::list srcIds; + srcIds.push_back(item->text(SR_UID_COL).toStdString()) ; + + QString fhash = item->text(SR_HASH_COL); + QString fsize = item->text(SR_REALSIZE_COL); + QString fname = item->text(SR_NAME_COL); + + analyzer.setRetroShareLink (fname, fsize, fhash); + + } + } + + QClipboard *clipboard = QApplication::clipboard(); + clipboard->setText(analyzer.getRetroShareLink ()); + +} + +void SearchDialog::sendLinkTo( ) +{ + copysearchLink(); + + /* create a message */ + ChanMsgDialog *nMsgDialog = new ChanMsgDialog(true); + + nMsgDialog->newMsg(); + nMsgDialog->insertTitleText("New RetroShare Link(s)"); + nMsgDialog->insertHtmlText(QApplication::clipboard()->text().toStdString()); + + nMsgDialog->show(); +} diff --git a/retroshare-gui/src/gui/SearchDialog.h b/retroshare-gui/src/gui/SearchDialog.h index 3727140b1..3045d99c4 100644 --- a/retroshare-gui/src/gui/SearchDialog.h +++ b/retroshare-gui/src/gui/SearchDialog.h @@ -60,7 +60,8 @@ private slots: void broadcastonchannel(); void recommendtofriends(); - + + void copysearchLink(); void searchRemove(); @@ -82,12 +83,14 @@ private slots: void selectSearchResults(); void clearKeyword(); + + void sendLinkTo(); private: /** render the results to the tree widget display */ void initSearchResult(const std::string& txt,qulonglong searchId) ; - void resultsToTree(std::string,qulonglong searchId, const std::list&); + void resultsToTree(std::string,qulonglong searchId, const std::list&); void insertFile(const std::string& txt,qulonglong searchId, const FileDetail& file) ; void insertDirectory(const std::string &txt, qulonglong searchId, const DirDetails &dir, QTreeWidgetItem *item); void setIconAndType(QTreeWidgetItem *item, QString &ext); @@ -104,6 +107,8 @@ private: /** Defines the actions for the context menu */ QAction* downloadAct; + QAction* copysearchlinkAct; + QAction* sendrslinkAct; QAction* broadcastonchannelAct; QAction* recommendtofriendsAct;