cleaned the RS link code, factorized the parsing into a single class. Still missing: copy/paste of multiple links

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@2514 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2010-03-10 21:38:26 +00:00
parent a208efdaf9
commit a657def956
13 changed files with 316 additions and 170 deletions

View File

@ -159,7 +159,7 @@ HEADERS += rshare.h \
gui/MessengerWindow.h \ gui/MessengerWindow.h \
gui/PeersDialog.h \ gui/PeersDialog.h \
gui/RemoteDirModel.h \ gui/RemoteDirModel.h \
gui/RetroShareLinkAnalyzer.h \ gui/RetroShareLink.h \
gui/SearchTreeWidget.h \ gui/SearchTreeWidget.h \
gui/SendLinkDialog.h \ gui/SendLinkDialog.h \
gui/SearchDialog.h \ gui/SearchDialog.h \
@ -341,7 +341,7 @@ SOURCES += main.cpp \
gui/PeersDialog.cpp \ gui/PeersDialog.cpp \
gui/RemoteDirModel.cpp \ gui/RemoteDirModel.cpp \
gui/RsAutoUpdatePage.cpp \ gui/RsAutoUpdatePage.cpp \
gui/RetroShareLinkAnalyzer.cpp \ gui/RetroShareLink.cpp \
gui/SearchTreeWidget.cpp \ gui/SearchTreeWidget.cpp \
gui/SearchDialog.cpp \ gui/SearchDialog.cpp \
gui/SendLinkDialog.cpp \ gui/SendLinkDialog.cpp \

View File

@ -22,7 +22,7 @@
#include "common/vmessagebox.h" #include "common/vmessagebox.h"
#include "AddLinksDialog.h" #include "AddLinksDialog.h"
#include "RetroShareLinkAnalyzer.h" #include "RetroShareLink.h"
#include "rsiface/rsrank.h" #include "rsiface/rsrank.h"
/* Images for context menu icons */ /* Images for context menu icons */
@ -49,19 +49,12 @@ AddLinksDialog::AddLinksDialog(QString url, QWidget *parent)
ui.linkLineEdit->setReadOnly(true); ui.linkLineEdit->setReadOnly(true);
ui.linkLineEdit->setText(url); ui.linkLineEdit->setText(url);
RetroShareLinkAnalyzer analyzer(url); RetroShareLink link(url);
QVector<RetroShareLinkData> linkList;
analyzer.getFileInformation(linkList); if(link.valid())
ui.titleLineEdit->setText(link.name());
if (!linkList.isEmpty())
{ /* set title as first name from list */
RetroShareLinkData item = linkList.first();
ui.titleLineEdit->setText(item.getName());
}
else else
{
ui.titleLineEdit->setText("New File"); ui.titleLineEdit->setText("New File");
}
load(); load();
@ -130,4 +123,4 @@ void AddLinksDialog::load()
ui.scoreBox->setEnabled(true); ui.scoreBox->setEnabled(true);
ui.linkTextEdit->setEnabled(true); ui.linkTextEdit->setEnabled(true);
} }
} }

View File

@ -20,6 +20,7 @@
****************************************************************/ ****************************************************************/
#include "ForumsDialog.h" #include "ForumsDialog.h"
#include "gui/RetroShareLink.h"
#include "gui/forums/CreateForum.h" #include "gui/forums/CreateForum.h"
#include "gui/forums/CreateForumMsg.h" #include "gui/forums/CreateForumMsg.h"
#include "gui/forums/ForumDetails.h" #include "gui/forums/ForumDetails.h"
@ -1088,21 +1089,13 @@ void ForumsDialog::anchorClicked (const QUrl& link )
if (link.scheme() == "retroshare") if (link.scheme() == "retroshare")
{ {
QStringList L = link.toString().split("|") ; RetroShareLink rslnk(link.toString()) ;
std::string fileName = L.at(1).toStdString() ; if(rslnk.valid())
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<std::string> srcIds; std::list<std::string> 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); 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.setButtonText( QMessageBox::Ok, "OK" );

View File

@ -30,7 +30,7 @@
//#include "rshare.h" //#include "rshare.h"
#include "LinksDialog.h" #include "LinksDialog.h"
#include "RetroShareLinkAnalyzer.h" #include "RetroShareLink.h"
#include "rsiface/rspeers.h" #include "rsiface/rspeers.h"
#include "rsiface/rsrank.h" #include "rsiface/rsrank.h"
#include "rsiface/rsfiles.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 #ifdef LINKS_DEBUG
std::cerr << "LinksDialog::openLink()" << std::endl; std::cerr << "LinksDialog::openLink()" << std::endl;
@ -555,7 +555,7 @@ void LinksDialog::openLink ( QTreeWidgetItem * item, int column )
item->setExpanded(!state); item->setExpanded(!state);
} }
void LinksDialog::changedItem(QTreeWidgetItem *curr, QTreeWidgetItem *prev) void LinksDialog::changedItem(QTreeWidgetItem *curr, QTreeWidgetItem *)
{ {
/* work out the ids */ /* work out the ids */
if (!curr) if (!curr)
@ -617,7 +617,7 @@ int ScoreToIndex(int score)
/* get the list of Links from the RsRanks. */ /* 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<RsRankComment>::iterator cit; std::list<RsRankComment>::iterator cit;
@ -711,10 +711,7 @@ void LinksDialog::addLinkComment( void )
{ {
if ((link == "") || (title == "")) if ((link == "") || (title == ""))
{ {
QMessageBox::StandardButton sb = QMessageBox::warning ( NULL, QMessageBox::warning ( NULL, "Add Link Failure", "Missing Link and/or Title", QMessageBox::Ok);
"Add Link Failure",
"Missing Link and/or Title",
QMessageBox::Ok);
/* can't do anything */ /* can't do anything */
return; return;
} }
@ -742,10 +739,7 @@ void LinksDialog::addLinkComment( void )
if (!rsRanks->getRankDetails(mLinkId, detail)) if (!rsRanks->getRankDetails(mLinkId, detail))
{ {
/* strange error! */ /* strange error! */
QMessageBox::StandardButton sb = QMessageBox::warning ( NULL, QMessageBox::warning ( NULL, "Add Link Failure", "Missing Link Data", QMessageBox::Ok);
"Add Link Failure",
"Missing Link Data",
QMessageBox::Ok);
return; return;
} }
@ -753,10 +747,7 @@ void LinksDialog::addLinkComment( void )
{ {
if (comment == "") /* no comment! */ if (comment == "") /* no comment! */
{ {
QMessageBox::StandardButton sb = QMessageBox::warning ( NULL, QMessageBox::warning ( NULL, "Add Link Failure", "Missing Comment", QMessageBox::Ok);
"Add Link Failure",
"Missing Comment",
QMessageBox::Ok);
return; return;
} }
@ -986,27 +977,24 @@ void LinksDialog::downloadSelected()
std::cerr << "LinksDialog::downloadSelected() : " << link.toStdString() << std::endl; std::cerr << "LinksDialog::downloadSelected() : " << link.toStdString() << std::endl;
#endif #endif
RetroShareLinkAnalyzer analyzer(QString::fromStdWString(detail.link)); RetroShareLink rslink(QString::fromStdWString(detail.link));
QVector<RetroShareLinkData> linkList;
analyzer.getFileInformation(linkList); if(!rslink.valid())
if (!linkList.isEmpty())
{ {
/* regularly one link and choose it */ QMessageBox::critical(NULL,"Badly formed link","This link is badly formed. Can't parse/use it. This is a bug. Please contact the developers.") ;
RetroShareLinkData item = linkList.first(); return ;
/* retrieve all peers id for this file */
FileInfo info;
rsFiles->FileDetails(item.getHash().toStdString(), 0, info);
std::list<std::string> srcIds;
std::list<TransferInfo>::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);
} }
/* retrieve all peers id for this file */
FileInfo info;
rsFiles->FileDetails(rslink.hash().toStdString(), 0, info);
std::list<std::string> srcIds;
std::list<TransferInfo>::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 ) void LinksDialog::anchorClicked (const QUrl& link )

View File

@ -22,6 +22,7 @@
#include "MessagesDialog.h" #include "MessagesDialog.h"
#include "msgs/ChanMsgDialog.h" #include "msgs/ChanMsgDialog.h"
#include "gui/RetroShareLink.h"
#include "gui/toaster/MessageToaster.h" #include "gui/toaster/MessageToaster.h"
#include "util/printpreview.h" #include "util/printpreview.h"
#include "util/misc.h" #include "util/misc.h"
@ -1011,27 +1012,23 @@ void MessagesDialog::printpreview()
void MessagesDialog::anchorClicked (const QUrl& link ) void MessagesDialog::anchorClicked (const QUrl& link )
{ {
#ifdef FORUM_DEBUG #ifdef FORUM_DEBUG
std::cerr << "MessagesDialog::anchorClicked link.scheme() : " << link.scheme().toStdString() << std::endl; std::cerr << "MessagesDialog::anchorClicked link.scheme() : " << link.scheme().toStdString() << std::endl;
#endif #endif
if (link.scheme() == "retroshare") 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 #ifdef FORUM_DEBUG
std::cerr << "MessagesDialog::anchorClicked FileRequest : fileName : " << fileName << ". fileHash : " << fileHash << ". fileSize : " << fileSize << std::endl; std::cerr << "MessagesDialog::anchorClicked FileRequest : fileName : " << fileName << ". fileHash : " << fileHash << ". fileSize : " << fileSize << std::endl;
#endif #endif
if (fileName != "" && fileHash != "") if(rslnk.valid())
{ {
std::list<std::string> srcIds; std::list<std::string> 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); 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.setButtonText( QMessageBox::Ok, "OK" );

View File

@ -23,6 +23,7 @@
#include <QFileInfo> #include <QFileInfo>
#include "common/vmessagebox.h" #include "common/vmessagebox.h"
#include <gui/mainpagestack.h> #include <gui/mainpagestack.h>
#include <gui/RetroShareLink.h>
#include "rshare.h" #include "rshare.h"
#include "PeersDialog.h" #include "PeersDialog.h"
@ -1635,24 +1636,13 @@ void PeersDialog::anchorClicked (const QUrl& link )
if (link.scheme() == "retroshare") if (link.scheme() == "retroshare")
{ {
QStringList L = link.toString().split("|") ; RetroShareLink rslnk(link.toString()) ;
std::string fileName = L.at(1).toStdString() ; if (rslnk.valid())
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 != "")
{ {
std::list<std::string> srcIds; std::list<std::string> 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); 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.setButtonText( QMessageBox::Ok, "OK" );

View File

@ -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 <iostream>
#include <QStringList>
#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;i<name.length();++i)
{
QChar::Category cat( name[i].category() ) ;
if( cat == QChar::Separator_Line
|| cat == QChar::Other_NotAssigned
)
{
#ifdef DEBUG_RSLINK
std::cerr <<"Unwanted category " << cat << " at place " << i << " in string \"" << name.toStdString() << "\"" << std::endl ;
#endif
return false ;
}
}
return true ;
}
bool RetroShareLink::checkHash(const QString& hash)
{
if(hash.length() != 40)
return false ;
QByteArray qb(hash.toAscii()) ;
for(int i=0;i<qb.length();++i)
{
unsigned char b(qb[i]) ;
if(!((b>47 && b<58) || (b>96 && b<103)))
return false ;
}
return true ;
}

View File

@ -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 <stdint.h>
#include <QString>
#include <QVector>
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<RetroShareLink>& 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

View File

@ -19,10 +19,11 @@
* Boston, MA 02110-1301, USA. * Boston, MA 02110-1301, USA.
****************************************************************/ ****************************************************************/
#include <set>
#include "rshare.h" #include "rshare.h"
#include "SearchDialog.h" #include "SearchDialog.h"
#include "RetroShareLinkAnalyzer.h" #include "RetroShareLink.h"
#include "msgs/ChanMsgDialog.h" #include "msgs/ChanMsgDialog.h"
#include "rsiface/rsiface.h" #include "rsiface/rsiface.h"
@ -252,12 +253,15 @@ void SearchDialog::searchtableWidgetCostumPopupMenu( QPoint point )
contextMnu->clear(); contextMnu->clear();
contextMnu->addAction( downloadAct); contextMnu->addAction( downloadAct);
contextMnu->addSeparator(); 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, QMouseEvent *mevent = new QMouseEvent(QEvent::MouseButtonPress,point,Qt::RightButton, Qt::RightButton,Qt::NoModifier);
Qt::RightButton, Qt::RightButton, Qt::NoModifier );
contextMnu->exec( mevent->globalPos() ); contextMnu->exec( mevent->globalPos() );
} }
@ -1186,8 +1190,6 @@ void SearchDialog::setIconAndType(QTreeWidgetItem *item, QString &ext)
void SearchDialog::copysearchLink() void SearchDialog::copysearchLink()
{ {
RetroShareLinkAnalyzer analyzer;
/* should also be able to handle multi-selection */ /* should also be able to handle multi-selection */
QList<QTreeWidgetItem*> itemsForCopy = ui.searchResultWidget->selectedItems(); QList<QTreeWidgetItem*> itemsForCopy = ui.searchResultWidget->selectedItems();
int numdls = itemsForCopy.size(); int numdls = itemsForCopy.size();
@ -1199,24 +1201,20 @@ void SearchDialog::copysearchLink()
// call copy // call copy
if (!item->childCount()) if (!item->childCount())
{ {
std::cerr << "SearchDialog::copysearchLink() Calling set retroshare link"; std::cerr << "SearchDialog::copysearchLink() Calling set retroshare link";
std::cerr << std::endl; std::cerr << std::endl;
std::list<std::string> srcIds;
srcIds.push_back(item->text(SR_UID_COL).toStdString()) ;
QString fhash = item->text(SR_HASH_COL); QString fhash = item->text(SR_HASH_COL);
QString fsize = item->text(SR_REALSIZE_COL); qulonglong fsize = item->text(SR_REALSIZE_COL).toULongLong();
QString fname = item->text(SR_NAME_COL); 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( ) void SearchDialog::sendLinkTo( )

View File

@ -34,9 +34,7 @@
#include "AddLinksDialog.h" #include "AddLinksDialog.h"
#include "SendLinkDialog.h" #include "SendLinkDialog.h"
#ifndef RETROSHARE_LINK_ANALYZER #include "RetroShareLink.h"
#include "RetroShareLinkAnalyzer.h"
#endif
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
@ -253,12 +251,14 @@ void SharedFilesDialog::copyLink (const QModelIndexList& lst, bool remote)
else else
localModel->getDirDetailsFromSelect(lst, dirVec); localModel->getDirDetailsFromSelect(lst, dirVec);
RetroShareLinkAnalyzer analyzer;
for (int i = 0, n = dirVec.size(); i < n; ++i) for (int i = 0, n = dirVec.size(); i < n; ++i)
{ {
const DirDetails& details = dirVec[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) if (details.type == DIR_TYPE_DIR)
{ {
for (std::list<DirStub>::const_iterator cit = details.children.begin(); for (std::list<DirStub>::const_iterator cit = details.children.begin();
@ -286,10 +286,8 @@ void SharedFilesDialog::copyLink (const QModelIndexList& lst, bool remote)
} }
else else
analyzer.setRetroShareLink (details.name.c_str(), QString::number(details.count), details.hash.c_str()); 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() void SharedFilesDialog::copyLinkRemote()

View File

@ -27,7 +27,7 @@
#include "rshare.h" #include "rshare.h"
#include "TransfersDialog.h" #include "TransfersDialog.h"
#include "RetroShareLinkAnalyzer.h" #include "RetroShareLink.h"
#include "DetailsDialog.h" #include "DetailsDialog.h"
#include "DLListDelegate.h" #include "DLListDelegate.h"
#include "ULListDelegate.h" #include "ULListDelegate.h"
@ -411,7 +411,8 @@ void TransfersDialog::downloadListCostumPopupMenu( QPoint point )
contextMnu.addAction( clearcompletedAct); contextMnu.addAction( clearcompletedAct);
contextMnu.addSeparator(); contextMnu.addSeparator();
#ifndef RS_RELEASE_VERSION #ifndef RS_RELEASE_VERSION
contextMnu.addAction( copylinkAct); if(single)
contextMnu.addAction( copylinkAct);
#endif #endif
contextMnu.addAction( pastelinkAct); contextMnu.addAction( pastelinkAct);
contextMnu.addSeparator(); contextMnu.addSeparator();
@ -958,47 +959,47 @@ void TransfersDialog::cancel()
} }
} }
void TransfersDialog::handleDownloadRequest(const QString& url){ //void TransfersDialog::handleDownloadRequest(const QString& url)
//{
RetroShareLinkAnalyzer analyzer (url); // RetroShareLink link(url);
//
if (!analyzer.isValid ()) // if (!link.valid ())
return; // {
// QMessageBox::critical(NULL,"Link error","This link could not be parsed. This is a bug. Please contact the developers.") ;
QVector<RetroShareLinkData> linkList; // return;
analyzer.getFileInformation (linkList); // }
//
std::list<std::string> srcIds; // QVector<RetroShareLinkData> linkList;
// analyzer.getFileInformation (linkList);
for (int i = 0, n = linkList.size (); i < n; ++i) //
{ // std::list<std::string> srcIds;
const RetroShareLinkData& linkData = linkList[i]; //
// for (int i = 0, n = linkList.size (); i < n; ++i)
rsFiles->FileRequest (linkData.getName ().toStdString (), linkData.getHash ().toStdString (), // {
linkData.getSize ().toInt (), "", 0, srcIds); // const RetroShareLinkData& linkData = linkList[i];
} //
} // rsFiles->FileRequest (linkData.getName ().toStdString (), linkData.getHash ().toStdString (),
// linkData.getSize ().toInt (), "", 0, srcIds);
// }
//}
void TransfersDialog::copyLink () void TransfersDialog::copyLink ()
{ {
QModelIndexList lst = ui.downloadList->selectionModel ()->selectedIndexes (); QModelIndexList lst = ui.downloadList->selectionModel ()->selectedIndexes ();
RetroShareLinkAnalyzer analyzer;
for (int i = 0; i < lst.count (); i++) for (int i = 0; i < lst.count (); i++)
{ if ( lst[i].column() == 0 )
if ( lst[i].column() == 0 ) {
{ QModelIndex & ind = lst[i];
QModelIndex & ind = lst[i]; QString fhash= ind.model ()->data (ind.model ()->index (ind.row (), ID )).toString() ;
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 fsize= ind.model ()->data (ind.model ()->index (ind.row (), SIZE)).toString() ; QString fname= ind.model ()->data (ind.model ()->index (ind.row (), NAME)).toString() ;
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(); QApplication::clipboard()->setText(link.toString());
clipboard->setText(analyzer.getRetroShareLink ()); break ;
}
} }
void TransfersDialog::showDetailsDialog() void TransfersDialog::showDetailsDialog()
@ -1006,7 +1007,6 @@ void TransfersDialog::showDetailsDialog()
static DetailsDialog *detailsdlg = new DetailsDialog(); static DetailsDialog *detailsdlg = new DetailsDialog();
QModelIndexList lst = ui.downloadList->selectionModel ()->selectedIndexes (); QModelIndexList lst = ui.downloadList->selectionModel ()->selectedIndexes ();
RetroShareLinkAnalyzer analyzer;
std::string file_hash ; std::string file_hash ;
@ -1061,8 +1061,8 @@ void TransfersDialog::showDetailsDialog()
detailsdlg->setDownloadtime(fdownloadtime); detailsdlg->setDownloadtime(fdownloadtime);
// retroshare link(s) Tab // retroshare link(s) Tab
analyzer.setRetroShareLink (fname, fsize, fhash); RetroShareLink link(fname, filesize, fhash);
detailsdlg->setLink(analyzer.getRetroShareLink ()); detailsdlg->setLink(link.toString());
detailsdlg->show(); detailsdlg->show();
break; break;
@ -1072,25 +1072,12 @@ void TransfersDialog::showDetailsDialog()
void TransfersDialog::pasteLink() void TransfersDialog::pasteLink()
{ {
QClipboard *clipboard = QApplication::clipboard(); RetroShareLink link(QApplication::clipboard()->text());
RetroShareLinkAnalyzer analyzer (clipboard->text ());
if (!analyzer.isValid ()) if (!link.valid())
return; return;
QVector<RetroShareLinkData> linkList; rsFiles->FileRequest(link.name().toStdString(), link.hash().toStdString(),link.size(), "", RS_FILE_HINTS_NETWORK_WIDE, std::list<std::string>());
analyzer.getFileInformation (linkList);
std::list<std::string> 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);
}
} }
void TransfersDialog::getIdOfSelectedItems(std::set<QStandardItem *>& items) void TransfersDialog::getIdOfSelectedItems(std::set<QStandardItem *>& items)

View File

@ -60,7 +60,7 @@ public:
public slots: public slots:
void insertTransfers(); void insertTransfers();
void handleDownloadRequest(const QString& url); // void handleDownloadRequest(const QString& url);
private slots: private slots:

View File

@ -830,7 +830,7 @@ void PopupChatDialog::anchorClicked (const QUrl& link ) {
std::list<std::string> srcIds; std::list<std::string> srcIds;
srcIds.push_front(dialogId); 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); 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.setButtonText( QMessageBox::Ok, "OK" );