mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
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:
parent
a208efdaf9
commit
a657def956
@ -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 \
|
||||
|
@ -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<RetroShareLinkData> linkList;
|
||||
analyzer.getFileInformation(linkList);
|
||||
RetroShareLink link(url);
|
||||
|
||||
if (!linkList.isEmpty())
|
||||
{ /* set title as first name from list */
|
||||
RetroShareLinkData item = linkList.first();
|
||||
ui.titleLineEdit->setText(item.getName());
|
||||
}
|
||||
if(link.valid())
|
||||
ui.titleLineEdit->setText(link.name());
|
||||
else
|
||||
{
|
||||
ui.titleLineEdit->setText("New File");
|
||||
}
|
||||
|
||||
load();
|
||||
|
||||
|
@ -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<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);
|
||||
mb.setButtonText( QMessageBox::Ok, "OK" );
|
||||
|
@ -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<RsRankComment>::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<RetroShareLinkData> 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();
|
||||
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(item.getHash().toStdString(), 0, 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(item.getName().toStdString(), item.getHash().toStdString(), item.getSize().toULong(), "", 0, srcIds);
|
||||
}
|
||||
rsFiles->FileRequest(rslink.name().toStdString(), rslink.hash().toStdString(), rslink.size(), "", 0, srcIds);
|
||||
}
|
||||
|
||||
void LinksDialog::anchorClicked (const QUrl& link )
|
||||
|
@ -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"
|
||||
@ -1017,21 +1018,17 @@ void MessagesDialog::anchorClicked (const QUrl& link )
|
||||
|
||||
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<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);
|
||||
mb.setButtonText( QMessageBox::Ok, "OK" );
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include <QFileInfo>
|
||||
#include "common/vmessagebox.h"
|
||||
#include <gui/mainpagestack.h>
|
||||
#include <gui/RetroShareLink.h>
|
||||
|
||||
#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<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);
|
||||
mb.setButtonText( QMessageBox::Ok, "OK" );
|
||||
|
143
retroshare-gui/src/gui/RetroShareLink.cpp
Normal file
143
retroshare-gui/src/gui/RetroShareLink.cpp
Normal 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 ;
|
||||
}
|
||||
|
||||
|
59
retroshare-gui/src/gui/RetroShareLink.h
Normal file
59
retroshare-gui/src/gui/RetroShareLink.h
Normal 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
|
||||
|
@ -19,10 +19,11 @@
|
||||
* Boston, MA 02110-1301, USA.
|
||||
****************************************************************/
|
||||
|
||||
#include <set>
|
||||
|
||||
#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();
|
||||
|
||||
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<QTreeWidgetItem*> itemsForCopy = ui.searchResultWidget->selectedItems();
|
||||
int numdls = itemsForCopy.size();
|
||||
@ -1202,21 +1204,17 @@ void SearchDialog::copysearchLink()
|
||||
{
|
||||
std::cerr << "SearchDialog::copysearchLink() Calling set retroshare link";
|
||||
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 fsize = item->text(SR_REALSIZE_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( )
|
||||
|
@ -34,9 +34,7 @@
|
||||
#include "AddLinksDialog.h"
|
||||
#include "SendLinkDialog.h"
|
||||
|
||||
#ifndef RETROSHARE_LINK_ANALYZER
|
||||
#include "RetroShareLinkAnalyzer.h"
|
||||
#endif
|
||||
#include "RetroShareLink.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
@ -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<DirStub>::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()
|
||||
|
@ -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,6 +411,7 @@ void TransfersDialog::downloadListCostumPopupMenu( QPoint point )
|
||||
contextMnu.addAction( clearcompletedAct);
|
||||
contextMnu.addSeparator();
|
||||
#ifndef RS_RELEASE_VERSION
|
||||
if(single)
|
||||
contextMnu.addAction( copylinkAct);
|
||||
#endif
|
||||
contextMnu.addAction( pastelinkAct);
|
||||
@ -958,47 +959,47 @@ void TransfersDialog::cancel()
|
||||
}
|
||||
}
|
||||
|
||||
void TransfersDialog::handleDownloadRequest(const QString& url){
|
||||
|
||||
RetroShareLinkAnalyzer analyzer (url);
|
||||
|
||||
if (!analyzer.isValid ())
|
||||
return;
|
||||
|
||||
QVector<RetroShareLinkData> linkList;
|
||||
analyzer.getFileInformation (linkList);
|
||||
|
||||
std::list<std::string> 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<RetroShareLinkData> linkList;
|
||||
// analyzer.getFileInformation (linkList);
|
||||
//
|
||||
// std::list<std::string> 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;
|
||||
|
||||
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() ;
|
||||
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<RetroShareLinkData> linkList;
|
||||
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);
|
||||
}
|
||||
rsFiles->FileRequest(link.name().toStdString(), link.hash().toStdString(),link.size(), "", RS_FILE_HINTS_NETWORK_WIDE, std::list<std::string>());
|
||||
}
|
||||
|
||||
void TransfersDialog::getIdOfSelectedItems(std::set<QStandardItem *>& items)
|
||||
|
@ -60,7 +60,7 @@ public:
|
||||
public slots:
|
||||
void insertTransfers();
|
||||
|
||||
void handleDownloadRequest(const QString& url);
|
||||
// void handleDownloadRequest(const QString& url);
|
||||
|
||||
private slots:
|
||||
|
||||
|
@ -830,7 +830,7 @@ void PopupChatDialog::anchorClicked (const QUrl& link ) {
|
||||
std::list<std::string> 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" );
|
||||
|
Loading…
Reference in New Issue
Block a user