mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-07 05:38:09 -05:00
fixed RS link copy/paste from shared/search to transfers/forums/Pmessages
git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5.0@2544 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
814c06eb7a
commit
2f242db979
@ -25,6 +25,8 @@
|
|||||||
|
|
||||||
const QString RetroShareLink::HEADER_NAME("retroshare://file");
|
const QString RetroShareLink::HEADER_NAME("retroshare://file");
|
||||||
|
|
||||||
|
std::vector<RetroShareLink> RSLinkClipboard::_links ;
|
||||||
|
|
||||||
RetroShareLink::RetroShareLink(const QUrl& url)
|
RetroShareLink::RetroShareLink(const QUrl& url)
|
||||||
{
|
{
|
||||||
// parse
|
// parse
|
||||||
@ -94,6 +96,10 @@ QString RetroShareLink::toString() const
|
|||||||
{
|
{
|
||||||
return HEADER_NAME + "|" + _name + "|" + QString::number(_size) + "|" + _hash ;
|
return HEADER_NAME + "|" + _name + "|" + QString::number(_size) + "|" + _hash ;
|
||||||
}
|
}
|
||||||
|
QString RetroShareLink::toHtml() const
|
||||||
|
{
|
||||||
|
return QString("<a href='") + toString() + "'>" + toString() + "</a>" ;
|
||||||
|
}
|
||||||
|
|
||||||
bool RetroShareLink::checkName(const QString& name)
|
bool RetroShareLink::checkName(const QString& name)
|
||||||
{
|
{
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (C) 2009 *
|
* Copyright (C) 2009 Cyril Soler *
|
||||||
* *
|
* *
|
||||||
* This program is free software; you can redistribute it and/or modify *
|
* 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 *
|
* it under the terms of the GNU General Public License as published by *
|
||||||
@ -24,6 +24,14 @@
|
|||||||
//
|
//
|
||||||
// The link is done in a way that if valid()==true, then the link can be used.
|
// The link is done in a way that if valid()==true, then the link can be used.
|
||||||
//
|
//
|
||||||
|
// The following combinations have been tested:
|
||||||
|
// copy paste-> Transfers (DL) | Message compose (forums) | Private msg | Public chat | private Chat
|
||||||
|
// -------------+----------------+--------------------------+------------------+-------------+-------------
|
||||||
|
// search | Y | Y | Y (send RS link) | Paste menu? | Paste menu?
|
||||||
|
// -------------+----------------+--------------------------+------------------+-------------+-------------
|
||||||
|
// shared | Y | Y | Y (send RS link) | Paste menu? | Paste menu?
|
||||||
|
// -------------+----------------+--------------------------+------------------+-------------+-------------
|
||||||
|
//
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
@ -39,7 +47,10 @@ class RetroShareLink
|
|||||||
const QString& name() const { return _name ; }
|
const QString& name() const { return _name ; }
|
||||||
const QString& hash() const { return _hash ; }
|
const QString& hash() const { return _hash ; }
|
||||||
|
|
||||||
|
/// returns the string retroshare://file|name|size|hash
|
||||||
QString toString() const ;
|
QString toString() const ;
|
||||||
|
/// returns the string <a href="retroshare://file|name|size|hash">retroshare://file|name|size|hash</a>
|
||||||
|
QString toHtml() const ;
|
||||||
QUrl toUrl() const ;
|
QUrl toUrl() const ;
|
||||||
|
|
||||||
bool valid() const { return _size > 0 ; }
|
bool valid() const { return _size > 0 ; }
|
||||||
@ -55,5 +66,37 @@ class RetroShareLink
|
|||||||
QString _hash;
|
QString _hash;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// This class handles the copy/paste of links. Every member is static to ensure unicity.
|
||||||
|
/// I put no mutex, because all calls supposely com from the GUI thread.
|
||||||
|
//
|
||||||
|
class RSLinkClipboard
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static void copyLinks(const std::vector<RetroShareLink>& links)
|
||||||
|
{
|
||||||
|
_links = links ;
|
||||||
|
}
|
||||||
|
static const std::vector<RetroShareLink>& pasteLinks()
|
||||||
|
{
|
||||||
|
return _links ;
|
||||||
|
}
|
||||||
|
static QString toHtml()
|
||||||
|
{
|
||||||
|
QString res ;
|
||||||
|
for(uint32_t i=0;i<_links.size();++i)
|
||||||
|
res += _links[i].toHtml() + "<br/>" ;
|
||||||
|
|
||||||
|
return res ;
|
||||||
|
}
|
||||||
|
static bool empty()
|
||||||
|
{
|
||||||
|
return _links.empty();
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
static std::vector<RetroShareLink> _links ;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1192,7 +1192,7 @@ void SearchDialog::copysearchLink()
|
|||||||
int numdls = itemsForCopy.size();
|
int numdls = itemsForCopy.size();
|
||||||
QTreeWidgetItem * item;
|
QTreeWidgetItem * item;
|
||||||
|
|
||||||
QList<QUrl> urls ;
|
std::vector<RetroShareLink> urls ;
|
||||||
|
|
||||||
for (int i = 0; i < numdls; ++i)
|
for (int i = 0; i < numdls; ++i)
|
||||||
{
|
{
|
||||||
@ -1212,12 +1212,10 @@ void SearchDialog::copysearchLink()
|
|||||||
|
|
||||||
std::cerr << "new link added to clipboard: " << link.toString().toStdString() << std::endl ;
|
std::cerr << "new link added to clipboard: " << link.toString().toStdString() << std::endl ;
|
||||||
if(link.valid())
|
if(link.valid())
|
||||||
urls.push_back(link.toUrl()) ;
|
urls.push_back(link) ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
QMimeData *dt = new QMimeData;
|
RSLinkClipboard::copyLinks(urls) ;
|
||||||
dt->setUrls(urls) ;
|
|
||||||
QApplication::clipboard()->setMimeData(dt) ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SearchDialog::sendLinkTo( )
|
void SearchDialog::sendLinkTo( )
|
||||||
@ -1229,8 +1227,8 @@ void SearchDialog::sendLinkTo( )
|
|||||||
|
|
||||||
nMsgDialog->newMsg();
|
nMsgDialog->newMsg();
|
||||||
nMsgDialog->insertTitleText("New RetroShare Link(s)");
|
nMsgDialog->insertTitleText("New RetroShare Link(s)");
|
||||||
nMsgDialog->insertHtmlText(QApplication::clipboard()->text().toStdString());
|
|
||||||
|
|
||||||
|
nMsgDialog->insertMsgText(RSLinkClipboard::toHtml().toStdString()) ;
|
||||||
nMsgDialog->show();
|
nMsgDialog->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -251,7 +251,7 @@ void SharedFilesDialog::copyLink (const QModelIndexList& lst, bool remote)
|
|||||||
else
|
else
|
||||||
localModel->getDirDetailsFromSelect(lst, dirVec);
|
localModel->getDirDetailsFromSelect(lst, dirVec);
|
||||||
|
|
||||||
QList<QUrl> urls ;
|
std::vector<RetroShareLink> urls ;
|
||||||
|
|
||||||
for (int i = 0, n = dirVec.size(); i < n; ++i)
|
for (int i = 0, n = dirVec.size(); i < n; ++i)
|
||||||
{
|
{
|
||||||
@ -275,19 +275,20 @@ void SharedFilesDialog::copyLink (const QModelIndexList& lst, bool remote)
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
RetroShareLink link(details.name.c_str(), details.count, details.hash.c_str());
|
RetroShareLink link(details.name.c_str(), details.count, details.hash.c_str());
|
||||||
urls.push_back(link.toUrl()) ;
|
|
||||||
|
if(link.valid())
|
||||||
|
urls.push_back(link) ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
RetroShareLink link(details.name.c_str(), details.count, details.hash.c_str());
|
RetroShareLink link(details.name.c_str(), details.count, details.hash.c_str());
|
||||||
|
|
||||||
urls.push_back(link.toUrl()) ;
|
if(link.valid())
|
||||||
|
urls.push_back(link) ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
QMimeData *dt = new QMimeData ;
|
RSLinkClipboard::copyLinks(urls) ;
|
||||||
dt->setUrls(urls) ;
|
|
||||||
QApplication::clipboard()->setMimeData(dt) ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SharedFilesDialog::copyLinkRemote()
|
void SharedFilesDialog::copyLinkRemote()
|
||||||
@ -327,7 +328,7 @@ void SharedFilesDialog::sendremoteLinkTo()
|
|||||||
std::cerr << "SharedFilesDialog::sendremoteLinkTo()" << std::endl;
|
std::cerr << "SharedFilesDialog::sendremoteLinkTo()" << std::endl;
|
||||||
nMsgDialog->newMsg();
|
nMsgDialog->newMsg();
|
||||||
nMsgDialog->insertTitleText("RetroShare Link");
|
nMsgDialog->insertTitleText("RetroShare Link");
|
||||||
nMsgDialog->insertMsgText(QApplication::clipboard()->text().toStdString());
|
nMsgDialog->insertMsgText(RSLinkClipboard::toHtml().toStdString());
|
||||||
|
|
||||||
nMsgDialog->show();
|
nMsgDialog->show();
|
||||||
}
|
}
|
||||||
@ -347,7 +348,8 @@ void SharedFilesDialog::sendLinkTo()
|
|||||||
std::cerr << "SharedFilesDialog::sendLinkTo()" << std::endl;
|
std::cerr << "SharedFilesDialog::sendLinkTo()" << std::endl;
|
||||||
nMsgDialog->newMsg();
|
nMsgDialog->newMsg();
|
||||||
nMsgDialog->insertTitleText("RetroShare Link");
|
nMsgDialog->insertTitleText("RetroShare Link");
|
||||||
nMsgDialog->insertMsgText(QApplication::clipboard()->text().toStdString());
|
|
||||||
|
nMsgDialog->insertMsgText(RSLinkClipboard::toHtml().toStdString());
|
||||||
|
|
||||||
nMsgDialog->show();
|
nMsgDialog->show();
|
||||||
}
|
}
|
||||||
@ -359,7 +361,6 @@ void SharedFilesDialog::sendHtmlLinkTo( )
|
|||||||
/* create a message */
|
/* create a message */
|
||||||
ChanMsgDialog *nMsgDialog = new ChanMsgDialog(true);
|
ChanMsgDialog *nMsgDialog = new ChanMsgDialog(true);
|
||||||
|
|
||||||
|
|
||||||
/* fill it in
|
/* fill it in
|
||||||
* files are receommended already
|
* files are receommended already
|
||||||
* just need to set peers
|
* just need to set peers
|
||||||
@ -367,22 +368,22 @@ void SharedFilesDialog::sendHtmlLinkTo( )
|
|||||||
std::cerr << "SharedFilesDialog::sendLinkTo()" << std::endl;
|
std::cerr << "SharedFilesDialog::sendLinkTo()" << std::endl;
|
||||||
nMsgDialog->newMsg();
|
nMsgDialog->newMsg();
|
||||||
nMsgDialog->insertTitleText("RetroShare Link");
|
nMsgDialog->insertTitleText("RetroShare Link");
|
||||||
nMsgDialog->insertHtmlText(QApplication::clipboard()->text().toStdString());
|
// nMsgDialog->insertHtmlText(QApplication::clipboard()->text().toStdString());// not compatible with multiple links
|
||||||
|
nMsgDialog->insertMsgText(RSLinkClipboard::toHtml().toStdString());
|
||||||
|
|
||||||
nMsgDialog->show();
|
nMsgDialog->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SharedFilesDialog::sendLinktoChat()
|
//void SharedFilesDialog::sendLinktoChat()
|
||||||
{
|
//{
|
||||||
copyLinkLocal ();
|
// copyLinkLocal ();
|
||||||
|
//
|
||||||
static SendLinkDialog *slinkDialog = new SendLinkDialog(this);
|
// static SendLinkDialog *slinkDialog = new SendLinkDialog(this);
|
||||||
|
//
|
||||||
slinkDialog->insertHtmlText(QApplication::clipboard()->text().toStdString());
|
// slinkDialog->insertMsgText(RSLinkClipboard::toHtml().toStdString());
|
||||||
|
// slinkDialog->show();
|
||||||
slinkDialog->show();
|
//
|
||||||
|
//}
|
||||||
}
|
|
||||||
|
|
||||||
void SharedFilesDialog::sendLinkToCloud()
|
void SharedFilesDialog::sendLinkToCloud()
|
||||||
{
|
{
|
||||||
@ -673,8 +674,8 @@ void SharedFilesDialog::sharedDirTreeWidgetContextMenu( QPoint point )
|
|||||||
sendhtmllinkAct = new QAction(QIcon(IMAGE_COPYLINK), tr( "Send retroshare Links (HTML)" ), this );
|
sendhtmllinkAct = new QAction(QIcon(IMAGE_COPYLINK), tr( "Send retroshare Links (HTML)" ), this );
|
||||||
connect( sendhtmllinkAct , SIGNAL( triggered() ), this, SLOT( sendHtmlLinkTo( ) ) );
|
connect( sendhtmllinkAct , SIGNAL( triggered() ), this, SLOT( sendHtmlLinkTo( ) ) );
|
||||||
|
|
||||||
sendchatlinkAct = new QAction(QIcon(IMAGE_COPYLINK), tr( "Send retroshare Links to Chat" ), this );
|
// sendchatlinkAct = new QAction(QIcon(IMAGE_COPYLINK), tr( "Send retroshare Links to Chat" ), this );
|
||||||
connect( sendchatlinkAct , SIGNAL( triggered() ), this, SLOT( sendLinktoChat( ) ) );
|
// connect( sendchatlinkAct , SIGNAL( triggered() ), this, SLOT( sendLinktoChat( ) ) );
|
||||||
|
|
||||||
sendlinkCloudAct = new QAction(QIcon(IMAGE_COPYLINK), tr( "Send retroshare Links to Cloud" ), this );
|
sendlinkCloudAct = new QAction(QIcon(IMAGE_COPYLINK), tr( "Send retroshare Links to Cloud" ), this );
|
||||||
connect( sendlinkCloudAct , SIGNAL( triggered() ), this, SLOT( sendLinkToCloud( ) ) );
|
connect( sendlinkCloudAct , SIGNAL( triggered() ), this, SLOT( sendLinkToCloud( ) ) );
|
||||||
@ -702,10 +703,10 @@ void SharedFilesDialog::sharedDirTreeWidgetContextMenu( QPoint point )
|
|||||||
if(!localModel->isDir( midx ) )
|
if(!localModel->isDir( midx ) )
|
||||||
{
|
{
|
||||||
contextMnu2.addAction( copylinklocalAct);
|
contextMnu2.addAction( copylinklocalAct);
|
||||||
contextMnu2.addAction( copylinklocalhtmlAct);
|
// contextMnu2.addAction( copylinklocalhtmlAct);
|
||||||
contextMnu2.addAction( sendlinkAct);
|
contextMnu2.addAction( sendlinkAct);
|
||||||
contextMnu2.addAction( sendhtmllinkAct);
|
// contextMnu2.addAction( sendhtmllinkAct);
|
||||||
contextMnu2.addAction( sendchatlinkAct);
|
// contextMnu2.addAction( sendchatlinkAct);
|
||||||
contextMnu2.addSeparator();
|
contextMnu2.addSeparator();
|
||||||
#ifndef RS_RELEASE_VERSION
|
#ifndef RS_RELEASE_VERSION
|
||||||
contextMnu2.addAction( sendlinkCloudAct);
|
contextMnu2.addAction( sendlinkCloudAct);
|
||||||
|
@ -70,7 +70,7 @@ private slots:
|
|||||||
void sendHtmlLinkTo();
|
void sendHtmlLinkTo();
|
||||||
void sendLinkToCloud();
|
void sendLinkToCloud();
|
||||||
void addLinkToCloud();
|
void addLinkToCloud();
|
||||||
void sendLinktoChat();
|
// void sendLinktoChat();
|
||||||
|
|
||||||
void showFrame(bool show);
|
void showFrame(bool show);
|
||||||
void showFrameRemote(bool show);
|
void showFrameRemote(bool show);
|
||||||
|
@ -414,7 +414,9 @@ void TransfersDialog::downloadListCostumPopupMenu( QPoint point )
|
|||||||
if(single)
|
if(single)
|
||||||
contextMnu.addAction( copylinkAct);
|
contextMnu.addAction( copylinkAct);
|
||||||
#endif
|
#endif
|
||||||
contextMnu.addAction( pastelinkAct);
|
if(!RSLinkClipboard::empty())
|
||||||
|
contextMnu.addAction( pastelinkAct);
|
||||||
|
|
||||||
contextMnu.addSeparator();
|
contextMnu.addSeparator();
|
||||||
// contextMnu.addAction( clearQueueAct);
|
// contextMnu.addAction( clearQueueAct);
|
||||||
contextMnu.addSeparator();
|
contextMnu.addSeparator();
|
||||||
@ -1072,15 +1074,12 @@ void TransfersDialog::showDetailsDialog()
|
|||||||
|
|
||||||
void TransfersDialog::pasteLink()
|
void TransfersDialog::pasteLink()
|
||||||
{
|
{
|
||||||
QList<QUrl> urllist = QApplication::clipboard()->mimeData()->urls() ;
|
const std::vector<RetroShareLink>& links(RSLinkClipboard::pasteLinks()) ;
|
||||||
|
|
||||||
for(QList<QUrl>::const_iterator it(urllist.begin());it!=urllist.end();++it)
|
for(uint32_t i=0;i<links.size();++i)
|
||||||
{
|
if (links[i].valid())
|
||||||
RetroShareLink link(*it) ;
|
if(!rsFiles->FileRequest(links[i].name().toStdString(), links[i].hash().toStdString(),links[i].size(), "", RS_FILE_HINTS_NETWORK_WIDE, std::list<std::string>()))
|
||||||
|
QMessageBox::critical(NULL,"Download refused","The file "+links[i].name()+" could not be downloaded. Do you already have it ?") ;
|
||||||
if (link.valid())
|
|
||||||
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)
|
void TransfersDialog::getIdOfSelectedItems(std::set<QStandardItem *>& items)
|
||||||
|
@ -84,6 +84,9 @@ CreateForumMsg::CreateForumMsg(std::string fId, std::string pId)
|
|||||||
void CreateForumMsg::forumMessageCostumPopupMenu( QPoint point )
|
void CreateForumMsg::forumMessageCostumPopupMenu( QPoint point )
|
||||||
{
|
{
|
||||||
|
|
||||||
|
if(RSLinkClipboard::empty())
|
||||||
|
return ;
|
||||||
|
|
||||||
contextMnu = new QMenu( this );
|
contextMnu = new QMenu( this );
|
||||||
|
|
||||||
pasteLinkAct = new QAction(QIcon(":/images/pasterslink.png"), tr( "Paste retroshare Link" ), this );
|
pasteLinkAct = new QAction(QIcon(":/images/pasterslink.png"), tr( "Paste retroshare Link" ), this );
|
||||||
@ -415,14 +418,6 @@ void CreateForumMsg::fileHashingFinished(AttachFileItem* file) {
|
|||||||
|
|
||||||
void CreateForumMsg::pasteLink()
|
void CreateForumMsg::pasteLink()
|
||||||
{
|
{
|
||||||
QList<QUrl> list = QApplication::clipboard()->mimeData()->urls();
|
ui.forumMessage->insertHtml(RSLinkClipboard::toHtml()) ;
|
||||||
|
|
||||||
for(QList<QUrl>::const_iterator it(list.begin());it!=list.end();++it)
|
|
||||||
{
|
|
||||||
RetroShareLink link(*it) ;
|
|
||||||
|
|
||||||
if(link.valid())
|
|
||||||
ui.forumMessage->insertHtml("<a href='" + link.toString() + "'> " + link.toString() + "</a> <br>") ;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user