mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-02 14:16:16 -04:00
PeersDialog/MessengerWindow:
- send recommended friend as message - paste recommended friends as "retroshare://person|..." from clipboard reworked retroshare link handling - added new type -> retroshare://person|<name>|<hash> - added processing of links to RetroShareLink and RSLinkClipboard and removed all processing in anchorClicked of QTextBrowser - fixed parseClipboard to handle all found links in clipboard - disabled the processing of the clickable links (RetroShareLink::processUrl), because QUrl can't handle the RetroShare links properly removed memory leaks of the QAction in some context menus git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3292 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
3291e61291
commit
daf0ea50ee
21 changed files with 712 additions and 525 deletions
|
@ -23,235 +23,487 @@
|
|||
#include <QApplication>
|
||||
#include <QMimeData>
|
||||
#include <QClipboard>
|
||||
#include <QDesktopServices>
|
||||
#include <QMessageBox>
|
||||
#include <QIcon>
|
||||
#include <QObject>
|
||||
|
||||
#include "RetroShareLink.h"
|
||||
|
||||
#include "rsiface/rsfiles.h"
|
||||
#include "rsiface/rspeers.h"
|
||||
|
||||
#define DEBUG_RSLINK 1
|
||||
|
||||
const QString RetroShareLink::HEADER_NAME("retroshare://file");
|
||||
#define HEADER_FILE "retroshare://file"
|
||||
#define HEADER_PERSON "retroshare://person"
|
||||
|
||||
RetroShareLink::RetroShareLink(const QUrl& url)
|
||||
{
|
||||
// parse
|
||||
const QString stringurl = url.toString();
|
||||
fromString(stringurl);
|
||||
}
|
||||
|
||||
RetroShareLink::RetroShareLink(const QString& url)
|
||||
{
|
||||
fromString(url);
|
||||
}
|
||||
|
||||
void RetroShareLink::fromString(const QString& url)
|
||||
{
|
||||
_valid = false;
|
||||
|
||||
// parse
|
||||
#ifdef DEBUG_RSLINK
|
||||
std::cerr << "got new RS link \"" << url.toString().toStdString() << "\"" << std::endl ;
|
||||
std::cerr << "got new RS link \"" << url.toStdString() << "\"" << std::endl ;
|
||||
#endif
|
||||
QStringList list = url.toString().split ("|");
|
||||
QStringList list = url.split ("|");
|
||||
|
||||
if(list.size() < 4)
|
||||
goto bad_link ;
|
||||
if (list.size() >= 1) {
|
||||
if (list.size() == 4 && list[0] == HEADER_FILE) {
|
||||
bool ok ;
|
||||
|
||||
bool ok ;
|
||||
_type = TYPE_FILE;
|
||||
_name = list[1] ;
|
||||
_size = list[2].toULongLong(&ok) ;
|
||||
_hash = list[3].left(40) ; // normally not necessary, but it's a security.
|
||||
|
||||
_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 ;
|
||||
if (ok) {
|
||||
#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 ;
|
||||
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;
|
||||
}
|
||||
} else if (list.size() == 3 && list[0] == HEADER_PERSON) {
|
||||
_type = TYPE_PERSON;
|
||||
_name = list[1] ;
|
||||
_hash = list[2].left(40) ; // normally not necessary, but it's a security.
|
||||
_size = 0;
|
||||
check();
|
||||
return;
|
||||
}
|
||||
|
||||
check() ;
|
||||
// bad link
|
||||
}
|
||||
|
||||
return ;
|
||||
bad_link:
|
||||
#ifdef DEBUG_RSLINK
|
||||
std::cerr << "Wrongly formed RS link. Can't process." << std::endl ;
|
||||
std::cerr << "Wrongly formed RS link. Can't process." << std::endl ;
|
||||
#endif
|
||||
_hash = "" ;
|
||||
_size = 0 ;
|
||||
_name = "" ;
|
||||
_type = TYPE_UNKNOWN;
|
||||
_hash = "" ;
|
||||
_size = 0 ;
|
||||
_name = "" ;
|
||||
}
|
||||
|
||||
RetroShareLink::RetroShareLink(const QString & name, uint64_t size, const QString & hash)
|
||||
: _name(name),_size(size),_hash(hash)
|
||||
: _name(name),_size(size),_hash(hash)
|
||||
{
|
||||
check() ;
|
||||
_valid = false;
|
||||
_type = TYPE_FILE;
|
||||
check() ;
|
||||
}
|
||||
|
||||
RetroShareLink::RetroShareLink(const QString & name, const QString & hash)
|
||||
: _name(name),_size(0),_hash(hash)
|
||||
{
|
||||
_valid = false;
|
||||
_type = TYPE_PERSON;
|
||||
check() ;
|
||||
}
|
||||
|
||||
void RetroShareLink::check()
|
||||
{
|
||||
bool valid = true ;
|
||||
_valid = true;
|
||||
|
||||
if(_size > (((uint64_t)1)<<40)) // 1TB. Who has such large files?
|
||||
valid = false ;
|
||||
switch (_type) {
|
||||
case TYPE_UNKNOWN:
|
||||
_valid = false;
|
||||
break;
|
||||
case TYPE_FILE:
|
||||
if(_size > (((uint64_t)1)<<40)) // 1TB. Who has such large files?
|
||||
_valid = false;
|
||||
|
||||
if(!checkName(_name))
|
||||
valid = false ;
|
||||
if(!checkName(_name))
|
||||
_valid = false;
|
||||
|
||||
if(!checkHash(_hash))
|
||||
valid = false ;
|
||||
if(!checkHash(_hash))
|
||||
_valid = false;
|
||||
break;
|
||||
case TYPE_PERSON:
|
||||
if(_size != 0)
|
||||
_valid = false;
|
||||
|
||||
if(!valid) // we should throw an exception instead of this crap, but drbob doesn't like exceptions. Why ???
|
||||
{
|
||||
_hash = "" ;
|
||||
_name = "" ;
|
||||
_size = 0 ;
|
||||
}
|
||||
if(_name.isEmpty())
|
||||
_valid = false;
|
||||
|
||||
if(_hash.isEmpty())
|
||||
_valid = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if(!_valid) // we should throw an exception instead of this crap, but drbob doesn't like exceptions. Why ???
|
||||
{
|
||||
_type = TYPE_UNKNOWN;
|
||||
_hash = "" ;
|
||||
_name = "" ;
|
||||
_size = 0 ;
|
||||
}
|
||||
}
|
||||
|
||||
QString RetroShareLink::toString() const
|
||||
{
|
||||
return HEADER_NAME + "|" + _name + "|" + QString::number(_size) + "|" + _hash ;
|
||||
switch (_type) {
|
||||
case TYPE_UNKNOWN:
|
||||
break;
|
||||
case TYPE_FILE:
|
||||
return QString(HEADER_FILE) + "|" + _name + "|" + QString::number(_size) + "|" + _hash;
|
||||
case TYPE_PERSON:
|
||||
return QString(HEADER_PERSON) + "|" + _name + "|" + _hash;
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
QString RetroShareLink::niceName() const
|
||||
{
|
||||
if (type() == TYPE_PERSON) {
|
||||
return name() + "@" + hash();
|
||||
}
|
||||
|
||||
return name();
|
||||
}
|
||||
|
||||
QString RetroShareLink::toHtml() const
|
||||
{
|
||||
return QString("<a href='") + toString() + "'>" + name() + "</a>" ;
|
||||
return QString("<a href='") + toString() + "'>" + niceName() + "</a>" ;
|
||||
}
|
||||
|
||||
QString RetroShareLink::toHtmlFull() const
|
||||
{
|
||||
return QString("<a href='") + toString() + "'>" + toString() + "</a>" ;
|
||||
return QString("<a href='") + toString() + "'>" + toString() + "</a>" ;
|
||||
}
|
||||
|
||||
bool RetroShareLink::checkName(const QString& name)
|
||||
{
|
||||
if(name == "")
|
||||
return false ;
|
||||
if(name == "")
|
||||
return false ;
|
||||
|
||||
for(int i=0;i<name.length();++i)
|
||||
{
|
||||
QChar::Category cat( name[i].category() ) ;
|
||||
for(int i=0;i<name.length();++i)
|
||||
{
|
||||
QChar::Category cat( name[i].category() ) ;
|
||||
|
||||
if( cat == QChar::Separator_Line
|
||||
|| cat == QChar::Other_NotAssigned
|
||||
)
|
||||
{
|
||||
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 ;
|
||||
std::cerr <<"Unwanted category " << cat << " at place " << i << " in string \"" << name.toStdString() << "\"" << std::endl ;
|
||||
#endif
|
||||
return false ;
|
||||
}
|
||||
}
|
||||
return false ;
|
||||
}
|
||||
}
|
||||
|
||||
return true ;
|
||||
return true ;
|
||||
}
|
||||
|
||||
QUrl RetroShareLink::toUrl() const
|
||||
{
|
||||
return QUrl(toString()) ;
|
||||
return QUrl(toString()) ;
|
||||
}
|
||||
|
||||
bool RetroShareLink::checkHash(const QString& hash)
|
||||
{
|
||||
if(hash.length() != 40)
|
||||
return false ;
|
||||
if(hash.length() != 40)
|
||||
return false ;
|
||||
|
||||
QByteArray qb(hash.toAscii()) ;
|
||||
QByteArray qb(hash.toAscii()) ;
|
||||
|
||||
for(int i=0;i<qb.length();++i)
|
||||
{
|
||||
unsigned char b(qb[i]) ;
|
||||
for(int i=0;i<qb.length();++i)
|
||||
{
|
||||
unsigned char b(qb[i]) ;
|
||||
|
||||
if(!((b>47 && b<58) || (b>96 && b<103)))
|
||||
return false ;
|
||||
}
|
||||
if(!((b>47 && b<58) || (b>96 && b<103)))
|
||||
return false ;
|
||||
}
|
||||
|
||||
return true ;
|
||||
return true ;
|
||||
}
|
||||
|
||||
bool RetroShareLink::process(std::list<std::string> *psrcIds, int flag)
|
||||
{
|
||||
if (valid() == false) {
|
||||
std::cerr << " RetroShareLink::process invalid request" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (type()) {
|
||||
case TYPE_UNKNOWN:
|
||||
break;
|
||||
|
||||
case TYPE_FILE:
|
||||
{
|
||||
std::cerr << " RetroShareLink::process FileRequest : fileName : " << name().toStdString() << ". fileHash : " << hash().toStdString() << ". fileSize : " << size() << std::endl;
|
||||
|
||||
std::list<std::string> srcIds;
|
||||
if (psrcIds) {
|
||||
srcIds = *psrcIds;
|
||||
}
|
||||
|
||||
// I removed the NETWORK WIDE flag. Indeed, somebody can capture the turtle tunnel requests and ask for downloading the file while
|
||||
// it's being downloaded (as partial files are always sources).
|
||||
//
|
||||
if (rsFiles->FileRequest(name().toStdString(), hash().toStdString(), size(), "", 0 /*RS_FILE_HINTS_NETWORK_WIDE*/, srcIds)) {
|
||||
if (flag & RSLINK_PROCESS_NOTIFY_SUCCESS) {
|
||||
QMessageBox mb(QObject::tr("File Request Confirmation"), QObject::tr("The file has been added to your download list."),QMessageBox::Information,QMessageBox::Ok,0,0);
|
||||
mb.setButtonText( QMessageBox::Ok, "OK" );
|
||||
mb.setWindowIcon(QIcon(QString::fromUtf8(":/images/rstray3.png")));
|
||||
mb.exec();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (flag & RSLINK_PROCESS_NOTIFY_ERROR) {
|
||||
QMessageBox mb(QObject::tr("File Request canceled"), QObject::tr("The file has not been added to your download list, because you already have it."),QMessageBox::Critical,QMessageBox::Ok,0,0);
|
||||
mb.setButtonText( QMessageBox::Ok, "OK" );
|
||||
mb.setWindowIcon(QIcon(QString::fromUtf8(":/images/rstray3.png")));
|
||||
mb.exec();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
case TYPE_PERSON:
|
||||
{
|
||||
std::cerr << " RetroShareLink::process FriendRequest : name : " << name().toStdString() << ". id : " << hash().toStdString() << std::endl;
|
||||
|
||||
RsPeerDetails detail;
|
||||
if (rsPeers->getPeerDetails(hash().toStdString(), detail)) {
|
||||
if (detail.gpg_id == rsPeers->getGPGOwnId()) {
|
||||
// it's me, do nothing
|
||||
return true;
|
||||
}
|
||||
|
||||
if (detail.accept_connection) {
|
||||
// peer connection is already accepted
|
||||
if (flag & RSLINK_PROCESS_NOTIFY_SUCCESS) {
|
||||
QMessageBox mb(QObject::tr("Friend Request Confirmation"), QObject::tr("The friend is already in your list."),QMessageBox::Information,QMessageBox::Ok,0,0);
|
||||
mb.setButtonText( QMessageBox::Ok, "OK" );
|
||||
mb.setWindowIcon(QIcon(QString::fromUtf8(":/images/rstray3.png")));
|
||||
mb.exec();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (rsPeers->setAcceptToConnectGPGCertificate(hash().toStdString(), true)) {
|
||||
if (flag & RSLINK_PROCESS_NOTIFY_SUCCESS) {
|
||||
QMessageBox mb(QObject::tr("Friend Request Confirmation"), QObject::tr("The friend has been added to your list."),QMessageBox::Information,QMessageBox::Ok,0,0);
|
||||
mb.setButtonText( QMessageBox::Ok, "OK" );
|
||||
mb.setWindowIcon(QIcon(QString::fromUtf8(":/images/rstray3.png")));
|
||||
mb.exec();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (flag & RSLINK_PROCESS_NOTIFY_ERROR) {
|
||||
QMessageBox mb(QObject::tr("Friend Request canceled"), QObject::tr("The friend could not be added to your list."),QMessageBox::Critical,QMessageBox::Ok,0,0);
|
||||
mb.setButtonText( QMessageBox::Ok, "OK" );
|
||||
mb.setWindowIcon(QIcon(QString::fromUtf8(":/images/rstray3.png")));
|
||||
mb.exec();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (flag & RSLINK_PROCESS_NOTIFY_ERROR) {
|
||||
QMessageBox mb(QObject::tr("Friend Request canceled"), QObject::tr("The friend could not be found."),QMessageBox::Critical,QMessageBox::Ok,0,0);
|
||||
mb.setButtonText( QMessageBox::Ok, "OK" );
|
||||
mb.setWindowIcon(QIcon(QString::fromUtf8(":/images/rstray3.png")));
|
||||
mb.exec();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
std::cerr << " RetroShareLink::process unknown type: " << type() << std::endl;
|
||||
|
||||
if (flag & RSLINK_PROCESS_NOTIFY_ERROR) {
|
||||
QMessageBox mb(QObject::tr("File Request Error"), QObject::tr("The file link is malformed."),QMessageBox::Critical,QMessageBox::Ok,0,0);
|
||||
mb.setButtonText( QMessageBox::Ok, "OK" );
|
||||
mb.setWindowIcon(QIcon(QString::fromUtf8(":/images/rstray3.png")));
|
||||
mb.exec();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*static*/ bool RetroShareLink::processUrl(const QUrl &url, std::list<std::string> *psrcIds, int flag)
|
||||
{
|
||||
if (url.scheme() == "http") {
|
||||
QDesktopServices::openUrl(url);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (url.scheme() == "retroshare") {
|
||||
// QUrl can't handle the RetroShare link format properly
|
||||
if (flag & RSLINK_PROCESS_NOTIFY_ERROR) {
|
||||
QMessageBox mb(QObject::tr("File Request"), QObject::tr("Process of RetroShare links is not implemented. Please use copy instead."),QMessageBox::Critical,QMessageBox::Ok,0,0);
|
||||
mb.setButtonText( QMessageBox::Ok, "OK" );
|
||||
mb.setWindowIcon(QIcon(QString::fromUtf8(":/images/rstray3.png")));
|
||||
mb.exec();
|
||||
}
|
||||
|
||||
// RetroShareLink link(url);
|
||||
//
|
||||
// if (link.valid()) {
|
||||
// return link.process(psrcId, flag);
|
||||
// }
|
||||
//
|
||||
// if (flag & RSLINK_PROCESS_NOTIFY_ERROR) {
|
||||
// QMessageBox mb(QObject::tr("File Request Error"), QObject::tr("The file link is malformed."),QMessageBox::Information,QMessageBox::Ok,0,0);
|
||||
//second version: QMessageBox mb(QObject::tr("Badly formed RS link"), QObject::tr("This RetroShare link is malformed. This is bug. Please contact the developers.\n\nNote: this possibly comes from a bug in Qt4.6. Try to right-click + copy link location, and paste in Transfer Tab."),QMessageBox::Critical,QMessageBox::Ok,0,0);
|
||||
// mb.setButtonText( QMessageBox::Ok, "OK" );
|
||||
// mb.setWindowIcon(QIcon(QString::fromUtf8(":/images/rstray3.png")));
|
||||
// mb.exec();
|
||||
// }
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (url.scheme().isEmpty()) {
|
||||
//it's probably a web adress, let's add http:// at the beginning of the link
|
||||
QString newAddress = "http://" + url.toString();
|
||||
QDesktopServices::openUrl(QUrl(newAddress));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void RSLinkClipboard::copyLinks(const std::vector<RetroShareLink>& links)
|
||||
{
|
||||
QString res ;
|
||||
for(uint32_t i=0;i<links.size();++i)
|
||||
res += links[i].toString() + "\n" ;
|
||||
QString res ;
|
||||
for(uint32_t i=0;i<links.size();++i)
|
||||
res += links[i].toString() + "\n" ;
|
||||
|
||||
QApplication::clipboard()->setText(res) ;
|
||||
QApplication::clipboard()->setText(res) ;
|
||||
}
|
||||
|
||||
std::vector<RetroShareLink> RSLinkClipboard::pasteLinks()
|
||||
void RSLinkClipboard::pasteLinks(std::vector<RetroShareLink> &links)
|
||||
{
|
||||
return parseClipboard() ;
|
||||
return parseClipboard(links);
|
||||
}
|
||||
|
||||
std::vector<RetroShareLink> RSLinkClipboard::parseClipboard()
|
||||
void RSLinkClipboard::parseClipboard(std::vector<RetroShareLink> &links)
|
||||
{
|
||||
// parse clipboard for links.
|
||||
//
|
||||
std::vector<RetroShareLink> links ;
|
||||
QString text = QApplication::clipboard()->text() ;
|
||||
// parse clipboard for links.
|
||||
//
|
||||
links.clear();
|
||||
QString text = QApplication::clipboard()->text() ;
|
||||
|
||||
std::cerr << "Parsing clipboard:" << text.toStdString() << std::endl ;
|
||||
std::cerr << "Parsing clipboard:" << text.toStdString() << std::endl ;
|
||||
|
||||
QRegExp rx("retroshare://file") ;
|
||||
rx.setPatternSyntax(QRegExp::Wildcard) ;
|
||||
QRegExp rx("retroshare://(file|person)[^\r\n]+") ;
|
||||
|
||||
int pos = 0;
|
||||
int pos = 0;
|
||||
|
||||
while((pos = rx.indexIn(text, pos)) != -1)
|
||||
{
|
||||
QString txt = text.right(text.length()-pos) ;
|
||||
QStringList lst = txt.split('|') ;
|
||||
while((pos = rx.indexIn(text, pos)) != -1)
|
||||
{
|
||||
QString url(text.mid(pos, rx.matchedLength()));
|
||||
RetroShareLink link(url);
|
||||
|
||||
if(lst.size() < 4)
|
||||
break ;
|
||||
if(link.valid())
|
||||
{
|
||||
// check that the link is not already in the list:
|
||||
bool already = false ;
|
||||
for(uint32_t i=0;i<links.size();++i)
|
||||
if(links[i] == link)
|
||||
{
|
||||
already = true ;
|
||||
break ;
|
||||
}
|
||||
|
||||
bool ok = false ;
|
||||
RetroShareLink link(lst[1],lst[2].toULongLong(&ok),lst[3].left(40)) ;
|
||||
if(!already)
|
||||
{
|
||||
links.push_back(link) ;
|
||||
std::cerr << "captured link: " << link.toString().toStdString() << std::endl ;
|
||||
}
|
||||
}
|
||||
else
|
||||
std::cerr << "invalid link" << std::endl ;
|
||||
|
||||
if(link.valid())
|
||||
{
|
||||
// check that the link is not already in the list:
|
||||
bool already = false ;
|
||||
for(uint32_t i=0;i<links.size();++i)
|
||||
if(links[i] == link)
|
||||
{
|
||||
already = true ;
|
||||
break ;
|
||||
}
|
||||
|
||||
if(!already)
|
||||
{
|
||||
links.push_back(link) ;
|
||||
std::cerr << "captured link: " << link.toString().toStdString() << std::endl ;
|
||||
}
|
||||
}
|
||||
else
|
||||
std::cerr << "invalid link" << std::endl ;
|
||||
|
||||
pos += rx.matchedLength();
|
||||
}
|
||||
|
||||
return links ;
|
||||
pos += rx.matchedLength();
|
||||
}
|
||||
}
|
||||
|
||||
QString RSLinkClipboard::toString()
|
||||
{
|
||||
std::vector<RetroShareLink> links(parseClipboard()) ;
|
||||
std::vector<RetroShareLink> links;
|
||||
parseClipboard(links);
|
||||
|
||||
QString res ;
|
||||
for(uint32_t i=0;i<links.size();++i)
|
||||
res += links[i].toString() + "\n" ;
|
||||
QString res ;
|
||||
for(uint32_t i=0;i<links.size();++i)
|
||||
res += links[i].toString() + "\n" ;
|
||||
|
||||
return res ;
|
||||
return res ;
|
||||
}
|
||||
|
||||
QString RSLinkClipboard::toHtml()
|
||||
{
|
||||
std::vector<RetroShareLink> links(parseClipboard()) ;
|
||||
std::vector<RetroShareLink> links;
|
||||
parseClipboard(links);
|
||||
|
||||
QString res ;
|
||||
for(uint32_t i=0;i<links.size();++i)
|
||||
res += links[i].toHtml() + "<br/>" ;
|
||||
QString res ;
|
||||
for(uint32_t i=0;i<links.size();++i)
|
||||
res += links[i].toHtml() + "<br/>" ;
|
||||
|
||||
return res ;
|
||||
return res ;
|
||||
}
|
||||
|
||||
QString RSLinkClipboard::toHtmlFull()
|
||||
{
|
||||
std::vector<RetroShareLink> links(parseClipboard()) ;
|
||||
std::vector<RetroShareLink> links;
|
||||
parseClipboard(links);
|
||||
|
||||
QString res ;
|
||||
for(uint32_t i=0;i<links.size();++i)
|
||||
res += links[i].toHtmlFull() + "<br/>" ;
|
||||
QString res ;
|
||||
for(uint32_t i=0;i<links.size();++i)
|
||||
res += links[i].toHtmlFull() + "<br/>" ;
|
||||
|
||||
return res ;
|
||||
return res ;
|
||||
}
|
||||
bool RSLinkClipboard::empty()
|
||||
|
||||
bool RSLinkClipboard::empty(RetroShareLink::enumType type /*= RetroShareLink::TYPE_UNKNOWN*/)
|
||||
{
|
||||
return parseClipboard().empty() ;
|
||||
std::vector<RetroShareLink> links;
|
||||
parseClipboard(links);
|
||||
|
||||
if (type == RetroShareLink::TYPE_UNKNOWN) {
|
||||
return links.empty();
|
||||
}
|
||||
|
||||
for (std::vector<RetroShareLink>::iterator link = links.begin(); link != links.end(); link++) {
|
||||
if (link->type() == type) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*static*/ int RSLinkClipboard::process(RetroShareLink::enumType type /*= RetroShareLink::TYPE_UNKNOWN*/, int flag /*= RSLINK_PROCESS_NOTIFY_ALL*/)
|
||||
{
|
||||
std::vector<RetroShareLink> links;
|
||||
pasteLinks(links);
|
||||
|
||||
int count = 0;
|
||||
|
||||
for (uint32_t i = 0; i < links.size(); i++) {
|
||||
if (links[i].valid() && (type == RetroShareLink::TYPE_UNKNOWN || links[i].type() == type)) {
|
||||
if (links[i].process(NULL, flag)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue