diff --git a/retroshare-gui/src/RetroShare.pro b/retroshare-gui/src/RetroShare.pro index d19fa7a5b..4dd2c9df7 100644 --- a/retroshare-gui/src/RetroShare.pro +++ b/retroshare-gui/src/RetroShare.pro @@ -159,7 +159,7 @@ HEADERS += rshare.h \ gui/MessengerWindow.h \ gui/PeersDialog.h \ gui/RemoteDirModel.h \ - gui/RetroShareLinkAnalyzer.h \ + gui/RetroShareLink.h \ gui/SearchTreeWidget.h \ gui/SendLinkDialog.h \ gui/SearchDialog.h \ @@ -341,7 +341,7 @@ SOURCES += main.cpp \ gui/PeersDialog.cpp \ gui/RemoteDirModel.cpp \ gui/RsAutoUpdatePage.cpp \ - gui/RetroShareLinkAnalyzer.cpp \ + gui/RetroShareLink.cpp \ gui/SearchTreeWidget.cpp \ gui/SearchDialog.cpp \ gui/SendLinkDialog.cpp \ diff --git a/retroshare-gui/src/gui/AddLinksDialog.cpp b/retroshare-gui/src/gui/AddLinksDialog.cpp index 3e4dca483..46d675f2f 100644 --- a/retroshare-gui/src/gui/AddLinksDialog.cpp +++ b/retroshare-gui/src/gui/AddLinksDialog.cpp @@ -22,7 +22,7 @@ #include "common/vmessagebox.h" #include "AddLinksDialog.h" -#include "RetroShareLinkAnalyzer.h" +#include "RetroShareLink.h" #include "rsiface/rsrank.h" /* Images for context menu icons */ @@ -49,19 +49,12 @@ AddLinksDialog::AddLinksDialog(QString url, QWidget *parent) ui.linkLineEdit->setReadOnly(true); ui.linkLineEdit->setText(url); - RetroShareLinkAnalyzer analyzer(url); - QVector linkList; - analyzer.getFileInformation(linkList); - - if (!linkList.isEmpty()) - { /* set title as first name from list */ - RetroShareLinkData item = linkList.first(); - ui.titleLineEdit->setText(item.getName()); - } + RetroShareLink link(url); + + if(link.valid()) + ui.titleLineEdit->setText(link.name()); else - { ui.titleLineEdit->setText("New File"); - } load(); @@ -130,4 +123,4 @@ void AddLinksDialog::load() ui.scoreBox->setEnabled(true); ui.linkTextEdit->setEnabled(true); } -} \ No newline at end of file +} diff --git a/retroshare-gui/src/gui/ForumsDialog.cpp b/retroshare-gui/src/gui/ForumsDialog.cpp index 0632df01c..db51cf79a 100644 --- a/retroshare-gui/src/gui/ForumsDialog.cpp +++ b/retroshare-gui/src/gui/ForumsDialog.cpp @@ -20,6 +20,7 @@ ****************************************************************/ #include "ForumsDialog.h" +#include "gui/RetroShareLink.h" #include "gui/forums/CreateForum.h" #include "gui/forums/CreateForumMsg.h" #include "gui/forums/ForumDetails.h" @@ -1088,21 +1089,13 @@ void ForumsDialog::anchorClicked (const QUrl& link ) if (link.scheme() == "retroshare") { - QStringList L = link.toString().split("|") ; + RetroShareLink rslnk(link.toString()) ; - 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 != "") + if(rslnk.valid()) { std::list srcIds; - if(rsFiles->FileRequest(fileName, fileHash, fileSize, "", RS_FILE_HINTS_NETWORK_WIDE, srcIds)) + if(rsFiles->FileRequest(rslnk.name().toStdString(), rslnk.hash().toStdString(), rslnk.size(), "", 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" ); diff --git a/retroshare-gui/src/gui/LinksDialog.cpp b/retroshare-gui/src/gui/LinksDialog.cpp index 75168ec07..1a978ea1b 100644 --- a/retroshare-gui/src/gui/LinksDialog.cpp +++ b/retroshare-gui/src/gui/LinksDialog.cpp @@ -30,7 +30,7 @@ //#include "rshare.h" #include "LinksDialog.h" -#include "RetroShareLinkAnalyzer.h" +#include "RetroShareLink.h" #include "rsiface/rspeers.h" #include "rsiface/rsrank.h" #include "rsiface/rsfiles.h" @@ -514,7 +514,7 @@ void LinksDialog::updateLinks() } -void LinksDialog::openLink ( QTreeWidgetItem * item, int column ) +void LinksDialog::openLink ( QTreeWidgetItem * item, int ) { #ifdef LINKS_DEBUG std::cerr << "LinksDialog::openLink()" << std::endl; @@ -555,7 +555,7 @@ void LinksDialog::openLink ( QTreeWidgetItem * item, int column ) item->setExpanded(!state); } -void LinksDialog::changedItem(QTreeWidgetItem *curr, QTreeWidgetItem *prev) +void LinksDialog::changedItem(QTreeWidgetItem *curr, QTreeWidgetItem *) { /* work out the ids */ if (!curr) @@ -617,7 +617,7 @@ int ScoreToIndex(int score) /* get the list of Links from the RsRanks. */ -void LinksDialog::updateComments(std::string rid, std::string pid) +void LinksDialog::updateComments(std::string rid, std::string ) { std::list::iterator cit; @@ -711,10 +711,7 @@ void LinksDialog::addLinkComment( void ) { if ((link == "") || (title == "")) { - QMessageBox::StandardButton sb = QMessageBox::warning ( NULL, - "Add Link Failure", - "Missing Link and/or Title", - QMessageBox::Ok); + QMessageBox::warning ( NULL, "Add Link Failure", "Missing Link and/or Title", QMessageBox::Ok); /* can't do anything */ return; } @@ -742,10 +739,7 @@ void LinksDialog::addLinkComment( void ) if (!rsRanks->getRankDetails(mLinkId, detail)) { /* strange error! */ - QMessageBox::StandardButton sb = QMessageBox::warning ( NULL, - "Add Link Failure", - "Missing Link Data", - QMessageBox::Ok); + QMessageBox::warning ( NULL, "Add Link Failure", "Missing Link Data", QMessageBox::Ok); return; } @@ -753,10 +747,7 @@ void LinksDialog::addLinkComment( void ) { if (comment == "") /* no comment! */ { - QMessageBox::StandardButton sb = QMessageBox::warning ( NULL, - "Add Link Failure", - "Missing Comment", - QMessageBox::Ok); + QMessageBox::warning ( NULL, "Add Link Failure", "Missing Comment", QMessageBox::Ok); return; } @@ -986,27 +977,24 @@ void LinksDialog::downloadSelected() std::cerr << "LinksDialog::downloadSelected() : " << link.toStdString() << std::endl; #endif - RetroShareLinkAnalyzer analyzer(QString::fromStdWString(detail.link)); - QVector linkList; - analyzer.getFileInformation(linkList); - if (!linkList.isEmpty()) + RetroShareLink rslink(QString::fromStdWString(detail.link)); + + if(!rslink.valid()) { - /* regularly one link and choose it */ - RetroShareLinkData item = linkList.first(); - - /* retrieve all peers id for this file */ - FileInfo info; - rsFiles->FileDetails(item.getHash().toStdString(), 0, info); - - std::list srcIds; - std::list::iterator pit; - for (pit = info.peers.begin(); pit != info.peers.end(); pit ++) - { - srcIds.push_back(pit->peerId); - } - - rsFiles->FileRequest(item.getName().toStdString(), item.getHash().toStdString(), item.getSize().toULong(), "", 0, srcIds); + QMessageBox::critical(NULL,"Badly formed link","This link is badly formed. Can't parse/use it. This is a bug. Please contact the developers.") ; + return ; } + + /* retrieve all peers id for this file */ + FileInfo info; + rsFiles->FileDetails(rslink.hash().toStdString(), 0, info); + + std::list srcIds; + std::list::iterator pit; + for (pit = info.peers.begin(); pit != info.peers.end(); pit ++) + srcIds.push_back(pit->peerId); + + rsFiles->FileRequest(rslink.name().toStdString(), rslink.hash().toStdString(), rslink.size(), "", 0, srcIds); } void LinksDialog::anchorClicked (const QUrl& link ) diff --git a/retroshare-gui/src/gui/MessagesDialog.cpp b/retroshare-gui/src/gui/MessagesDialog.cpp index aa9c0ba87..2040033df 100644 --- a/retroshare-gui/src/gui/MessagesDialog.cpp +++ b/retroshare-gui/src/gui/MessagesDialog.cpp @@ -22,6 +22,7 @@ #include "MessagesDialog.h" #include "msgs/ChanMsgDialog.h" +#include "gui/RetroShareLink.h" #include "gui/toaster/MessageToaster.h" #include "util/printpreview.h" #include "util/misc.h" @@ -1011,27 +1012,23 @@ void MessagesDialog::printpreview() void MessagesDialog::anchorClicked (const QUrl& link ) { - #ifdef FORUM_DEBUG - std::cerr << "MessagesDialog::anchorClicked link.scheme() : " << link.scheme().toStdString() << std::endl; - #endif +#ifdef FORUM_DEBUG + std::cerr << "MessagesDialog::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() ; + RetroShareLink rslnk(link.toString()) ; #ifdef FORUM_DEBUG std::cerr << "MessagesDialog::anchorClicked FileRequest : fileName : " << fileName << ". fileHash : " << fileHash << ". fileSize : " << fileSize << std::endl; #endif - if (fileName != "" && fileHash != "") + if(rslnk.valid()) { std::list srcIds; - if(rsFiles->FileRequest(fileName, fileHash, fileSize, "", RS_FILE_HINTS_NETWORK_WIDE, srcIds)) + if(rsFiles->FileRequest(rslnk.name().toStdString(), rslnk.hash().toStdString(), rslnk.size(), "", 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" ); diff --git a/retroshare-gui/src/gui/PeersDialog.cpp b/retroshare-gui/src/gui/PeersDialog.cpp index e312a5840..b5032a1e0 100644 --- a/retroshare-gui/src/gui/PeersDialog.cpp +++ b/retroshare-gui/src/gui/PeersDialog.cpp @@ -23,6 +23,7 @@ #include #include "common/vmessagebox.h" #include +#include #include "rshare.h" #include "PeersDialog.h" @@ -1635,24 +1636,13 @@ void PeersDialog::anchorClicked (const QUrl& link ) if (link.scheme() == "retroshare") { - QStringList L = link.toString().split("|") ; + RetroShareLink rslnk(link.toString()) ; - std::string fileName = L.at(1).toStdString() ; - uint64_t fileSize = L.at(2).toULongLong(); - std::string fileHash = L.at(3).toStdString() ; - - if(fileHash.length() > 40) - fileHash.resize(40) ; - - #ifdef PEERS_DEBUG - std::cerr << "PeersDialog::anchorClicked FileRequest : fileName : " << fileName << ". fileHash : " << fileHash << ". fileSize : " << fileSize << std::endl; - #endif - - if (fileName != "" && fileHash != "") + if (rslnk.valid()) { std::list srcIds; - if(rsFiles->FileRequest(fileName, fileHash, fileSize, "", RS_FILE_HINTS_NETWORK_WIDE, srcIds)) + if(rsFiles->FileRequest(rslnk.name().toStdString(), rslnk.hash().toStdString(), rslnk.size(), "", 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" ); diff --git a/retroshare-gui/src/gui/RetroShareLink.cpp b/retroshare-gui/src/gui/RetroShareLink.cpp new file mode 100644 index 000000000..eccccf7ec --- /dev/null +++ b/retroshare-gui/src/gui/RetroShareLink.cpp @@ -0,0 +1,143 @@ +/*************************************************************************** + * Copyright (C) 2009 * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include +#include +#include "RetroShareLink.h" + +#define DEBUG_RSLINK 1 + +const QString RetroShareLink::HEADER_NAME("retroshare://file"); + +RetroShareLink::RetroShareLink(const QString & url) +{ + // parse +#ifdef DEBUG_RSLINK + std::cerr << "got new RS link \"" << url.toStdString() << "\"" << std::endl ; +#endif + QStringList urlList = url.split ("\n"); + + if(urlList.isEmpty ()) + goto bad_link ; + + { + QStringList list = urlList[0].split ("|"); + + bool ok ; + + _name = list[1] ; + _size = list[2].toULongLong(&ok) ; + _hash = list[3].left(40) ; // normally not necessary, but it's a security. + + if(!ok) + goto bad_link ; +#ifdef DEBUG_RSLINK + std::cerr << "New RetroShareLink forged:" << std::endl ; + std::cerr << " name = \"" << _name.toStdString() << "\"" << std::endl ; + std::cerr << " hash = \"" << _hash.toStdString() << "\"" << std::endl ; + std::cerr << " size = " << _size << std::endl ; +#endif + } + + check() ; + + return ; +bad_link: +#ifdef DEBUG_RSLINK + std::cerr << "Wrongly formed RS link. Can't process." << std::endl ; +#endif + _hash = "" ; + _size = 0 ; + _name = "" ; +} + +RetroShareLink::RetroShareLink(const QString & name, uint64_t size, const QString & hash) + : _name(name),_size(size),_hash(hash) +{ + check() ; +} + +void RetroShareLink::check() +{ + bool valid = true ; + + if(_size > (((uint64_t)1)<<40)) // 1TB. Who has such large files? + valid = false ; + + if(!checkName(_name)) + valid = false ; + + if(!checkHash(_hash)) + valid = false ; + + if(!valid) // we should throw an exception instead of this crap, but drbob doesn't like exceptions. Why ??? + { + _hash = "" ; + _name = "" ; + _size = 0 ; + } +} + +QString RetroShareLink::toString() const +{ + return HEADER_NAME + "|" + _name + "|" + QString::number(_size) + "|" + _hash ; +} + +bool RetroShareLink::checkName(const QString& name) +{ + if(name == "") + return false ; + + for(int i=0;i47 && b<58) || (b>96 && b<103))) + return false ; + } + + return true ; +} + + diff --git a/retroshare-gui/src/gui/RetroShareLink.h b/retroshare-gui/src/gui/RetroShareLink.h new file mode 100644 index 000000000..5b57c8ea7 --- /dev/null +++ b/retroshare-gui/src/gui/RetroShareLink.h @@ -0,0 +1,59 @@ +/*************************************************************************** + * Copyright (C) 2009 * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef RETROSHARE_LINK_ANALYZER +#define RETROSHARE_LINK_ANALYZER + +// This class implements a RS link. +// +// The link is done in a way that if valid()==true, then the link can be used. +// +#include +#include +#include + +class RetroShareLink +{ + public: + RetroShareLink(const QString& url); + RetroShareLink(const QString& name, uint64_t size, const QString& hash); + + uint64_t size() const { return _size ; } + const QString& name() const { return _name ; } + const QString& hash() const { return _hash ; } + + QString toString() const ; + + bool valid() const { return _size > 0 ; } + + static void parseForLinks(const QString& text,QList& link_list) ; + private: + void check() ; + static bool checkHash(const QString& hash) ; + static bool checkName(const QString& hash) ; + + static const QString HEADER_NAME; + + QString _name; + uint64_t _size; + QString _hash; +}; + +#endif + diff --git a/retroshare-gui/src/gui/SearchDialog.cpp b/retroshare-gui/src/gui/SearchDialog.cpp index 15263285d..5fab5405d 100644 --- a/retroshare-gui/src/gui/SearchDialog.cpp +++ b/retroshare-gui/src/gui/SearchDialog.cpp @@ -19,10 +19,11 @@ * Boston, MA 02110-1301, USA. ****************************************************************/ +#include #include "rshare.h" #include "SearchDialog.h" -#include "RetroShareLinkAnalyzer.h" +#include "RetroShareLink.h" #include "msgs/ChanMsgDialog.h" #include "rsiface/rsiface.h" @@ -252,12 +253,15 @@ void SearchDialog::searchtableWidgetCostumPopupMenu( QPoint point ) contextMnu->clear(); contextMnu->addAction( downloadAct); contextMnu->addSeparator(); - contextMnu->addAction( copysearchlinkAct); - contextMnu->addAction( sendrslinkAct); + + if ((ui.searchResultWidget->selectedItems()).size() == 1) + { + contextMnu->addAction( copysearchlinkAct); + contextMnu->addAction( sendrslinkAct); + } } - QMouseEvent *mevent = new QMouseEvent( QEvent::MouseButtonPress, point, - Qt::RightButton, Qt::RightButton, Qt::NoModifier ); + QMouseEvent *mevent = new QMouseEvent(QEvent::MouseButtonPress,point,Qt::RightButton, Qt::RightButton,Qt::NoModifier); contextMnu->exec( mevent->globalPos() ); } @@ -1186,8 +1190,6 @@ void SearchDialog::setIconAndType(QTreeWidgetItem *item, QString &ext) void SearchDialog::copysearchLink() { - RetroShareLinkAnalyzer analyzer; - /* should also be able to handle multi-selection */ QList itemsForCopy = ui.searchResultWidget->selectedItems(); int numdls = itemsForCopy.size(); @@ -1199,24 +1201,20 @@ void SearchDialog::copysearchLink() // 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); + qulonglong fsize = item->text(SR_REALSIZE_COL).toULongLong(); + QString fname = item->text(SR_NAME_COL); - analyzer.setRetroShareLink (fname, fsize, fhash); + RetroShareLink link(fname, fsize, fhash); - } + QApplication::clipboard()->setText(link.toString()); + break ; + } } - - QClipboard *clipboard = QApplication::clipboard(); - clipboard->setText(analyzer.getRetroShareLink ()); - } void SearchDialog::sendLinkTo( ) diff --git a/retroshare-gui/src/gui/SharedFilesDialog.cpp b/retroshare-gui/src/gui/SharedFilesDialog.cpp index 482608051..21e5f905e 100644 --- a/retroshare-gui/src/gui/SharedFilesDialog.cpp +++ b/retroshare-gui/src/gui/SharedFilesDialog.cpp @@ -34,9 +34,7 @@ #include "AddLinksDialog.h" #include "SendLinkDialog.h" -#ifndef RETROSHARE_LINK_ANALYZER -#include "RetroShareLinkAnalyzer.h" -#endif +#include "RetroShareLink.h" #include #include @@ -253,12 +251,14 @@ void SharedFilesDialog::copyLink (const QModelIndexList& lst, bool remote) else localModel->getDirDetailsFromSelect(lst, dirVec); - RetroShareLinkAnalyzer analyzer; - for (int i = 0, n = dirVec.size(); i < n; ++i) { const DirDetails& details = dirVec[i]; + RetroShareLink link(details.name.c_str(), details.count, details.hash.c_str()); + + QApplication::clipboard()->setText(link.toString()); +#ifdef TO_DO_LATER if (details.type == DIR_TYPE_DIR) { for (std::list::const_iterator cit = details.children.begin(); @@ -286,10 +286,8 @@ void SharedFilesDialog::copyLink (const QModelIndexList& lst, bool remote) } else analyzer.setRetroShareLink (details.name.c_str(), QString::number(details.count), details.hash.c_str()); +#endif } - - QClipboard *clipboard = QApplication::clipboard(); - clipboard->setText(analyzer.getRetroShareLink ()); } void SharedFilesDialog::copyLinkRemote() diff --git a/retroshare-gui/src/gui/TransfersDialog.cpp b/retroshare-gui/src/gui/TransfersDialog.cpp index 470f952a5..651588128 100644 --- a/retroshare-gui/src/gui/TransfersDialog.cpp +++ b/retroshare-gui/src/gui/TransfersDialog.cpp @@ -27,7 +27,7 @@ #include "rshare.h" #include "TransfersDialog.h" -#include "RetroShareLinkAnalyzer.h" +#include "RetroShareLink.h" #include "DetailsDialog.h" #include "DLListDelegate.h" #include "ULListDelegate.h" @@ -411,7 +411,8 @@ void TransfersDialog::downloadListCostumPopupMenu( QPoint point ) contextMnu.addAction( clearcompletedAct); contextMnu.addSeparator(); #ifndef RS_RELEASE_VERSION - contextMnu.addAction( copylinkAct); + if(single) + contextMnu.addAction( copylinkAct); #endif contextMnu.addAction( pastelinkAct); contextMnu.addSeparator(); @@ -958,47 +959,47 @@ void TransfersDialog::cancel() } } -void TransfersDialog::handleDownloadRequest(const QString& url){ - - RetroShareLinkAnalyzer analyzer (url); - - if (!analyzer.isValid ()) - return; - - QVector linkList; - analyzer.getFileInformation (linkList); - - std::list srcIds; - - for (int i = 0, n = linkList.size (); i < n; ++i) - { - const RetroShareLinkData& linkData = linkList[i]; - - rsFiles->FileRequest (linkData.getName ().toStdString (), linkData.getHash ().toStdString (), - linkData.getSize ().toInt (), "", 0, srcIds); - } -} +//void TransfersDialog::handleDownloadRequest(const QString& url) +//{ +// RetroShareLink link(url); +// +// if (!link.valid ()) +// { +// QMessageBox::critical(NULL,"Link error","This link could not be parsed. This is a bug. Please contact the developers.") ; +// return; +// } +// +// QVector linkList; +// analyzer.getFileInformation (linkList); +// +// std::list srcIds; +// +// for (int i = 0, n = linkList.size (); i < n; ++i) +// { +// const RetroShareLinkData& linkData = linkList[i]; +// +// rsFiles->FileRequest (linkData.getName ().toStdString (), linkData.getHash ().toStdString (), +// linkData.getSize ().toInt (), "", 0, srcIds); +// } +//} void TransfersDialog::copyLink () { - QModelIndexList lst = ui.downloadList->selectionModel ()->selectedIndexes (); - RetroShareLinkAnalyzer analyzer; + QModelIndexList lst = ui.downloadList->selectionModel ()->selectedIndexes (); - for (int i = 0; i < lst.count (); i++) - { - if ( lst[i].column() == 0 ) - { - QModelIndex & ind = lst[i]; - QString fhash= ind.model ()->data (ind.model ()->index (ind.row (), ID )).toString() ; - QString fsize= ind.model ()->data (ind.model ()->index (ind.row (), SIZE)).toString() ; - QString fname= ind.model ()->data (ind.model ()->index (ind.row (), NAME)).toString() ; + for (int i = 0; i < lst.count (); i++) + if ( lst[i].column() == 0 ) + { + QModelIndex & ind = lst[i]; + QString fhash= ind.model ()->data (ind.model ()->index (ind.row (), ID )).toString() ; + qulonglong fsize= ind.model ()->data (ind.model ()->index (ind.row (), SIZE)).toULongLong() ; + QString fname= ind.model ()->data (ind.model ()->index (ind.row (), NAME)).toString() ; - analyzer.setRetroShareLink (fname, fsize, fhash); - } - } + RetroShareLink link(fname, fsize, fhash); - QClipboard *clipboard = QApplication::clipboard(); - clipboard->setText(analyzer.getRetroShareLink ()); + QApplication::clipboard()->setText(link.toString()); + break ; + } } void TransfersDialog::showDetailsDialog() @@ -1006,7 +1007,6 @@ void TransfersDialog::showDetailsDialog() static DetailsDialog *detailsdlg = new DetailsDialog(); QModelIndexList lst = ui.downloadList->selectionModel ()->selectedIndexes (); - RetroShareLinkAnalyzer analyzer; std::string file_hash ; @@ -1061,8 +1061,8 @@ void TransfersDialog::showDetailsDialog() detailsdlg->setDownloadtime(fdownloadtime); // retroshare link(s) Tab - analyzer.setRetroShareLink (fname, fsize, fhash); - detailsdlg->setLink(analyzer.getRetroShareLink ()); + RetroShareLink link(fname, filesize, fhash); + detailsdlg->setLink(link.toString()); detailsdlg->show(); break; @@ -1072,25 +1072,12 @@ void TransfersDialog::showDetailsDialog() void TransfersDialog::pasteLink() { - QClipboard *clipboard = QApplication::clipboard(); - RetroShareLinkAnalyzer analyzer (clipboard->text ()); + RetroShareLink link(QApplication::clipboard()->text()); - if (!analyzer.isValid ()) + if (!link.valid()) return; - QVector linkList; - analyzer.getFileInformation (linkList); - - std::list srcIds; - - for (int i = 0, n = linkList.size (); i < n; ++i) - { - const RetroShareLinkData& linkData = linkList[i]; - //downloadFileRequested(linkData.getName (), linkData.getSize ().toInt (), - // linkData.getHash (), "", -1, -1, -1, -1); - rsFiles->FileRequest (linkData.getName ().toStdString (), linkData.getHash ().toStdString (), - linkData.getSize().toULongLong(), "", RS_FILE_HINTS_NETWORK_WIDE, srcIds); - } + rsFiles->FileRequest(link.name().toStdString(), link.hash().toStdString(),link.size(), "", RS_FILE_HINTS_NETWORK_WIDE, std::list()); } void TransfersDialog::getIdOfSelectedItems(std::set& items) diff --git a/retroshare-gui/src/gui/TransfersDialog.h b/retroshare-gui/src/gui/TransfersDialog.h index 35bda37f1..f9fb6b4d8 100644 --- a/retroshare-gui/src/gui/TransfersDialog.h +++ b/retroshare-gui/src/gui/TransfersDialog.h @@ -60,7 +60,7 @@ public: public slots: void insertTransfers(); - void handleDownloadRequest(const QString& url); +// void handleDownloadRequest(const QString& url); private slots: diff --git a/retroshare-gui/src/gui/chat/PopupChatDialog.cpp b/retroshare-gui/src/gui/chat/PopupChatDialog.cpp index d6e608fb6..0e8c3724a 100644 --- a/retroshare-gui/src/gui/chat/PopupChatDialog.cpp +++ b/retroshare-gui/src/gui/chat/PopupChatDialog.cpp @@ -830,7 +830,7 @@ void PopupChatDialog::anchorClicked (const QUrl& link ) { std::list srcIds; srcIds.push_front(dialogId); - if(rsFiles->FileRequest(fileName, fileHash, fileSize, "", RS_FILE_HINTS_ASSUME_AVAILABILITY, 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" );