added paste multiple links

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@2516 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2010-03-10 23:09:35 +00:00
parent ff0b797248
commit 0705d9dfc7
7 changed files with 74 additions and 75 deletions

View File

@ -1636,7 +1636,7 @@ void PeersDialog::anchorClicked (const QUrl& link )
if (link.scheme() == "retroshare")
{
RetroShareLink rslnk(link.toString()) ;
RetroShareLink rslnk(link) ;
if (rslnk.valid())
{

View File

@ -25,20 +25,17 @@
const QString RetroShareLink::HEADER_NAME("retroshare://file");
RetroShareLink::RetroShareLink(const QString & url)
RetroShareLink::RetroShareLink(const QUrl& url)
{
// parse
#ifdef DEBUG_RSLINK
std::cerr << "got new RS link \"" << url.toStdString() << "\"" << std::endl ;
std::cerr << "got new RS link \"" << url.toString().toStdString() << "\"" << std::endl ;
#endif
QStringList urlList = url.split ("\n");
QStringList list = url.toString().split ("|");
if(urlList.isEmpty ())
if(list.size() < 4)
goto bad_link ;
{
QStringList list = urlList[0].split ("|");
bool ok ;
_name = list[1] ;
@ -53,7 +50,6 @@ RetroShareLink::RetroShareLink(const QString & url)
std::cerr << " hash = \"" << _hash.toStdString() << "\"" << std::endl ;
std::cerr << " size = " << _size << std::endl ;
#endif
}
check() ;
@ -122,6 +118,11 @@ bool RetroShareLink::checkName(const QString& name)
return true ;
}
QUrl RetroShareLink::toUrl() const
{
return QUrl(toString()) ;
}
bool RetroShareLink::checkHash(const QString& hash)
{
if(hash.length() != 40)
@ -140,4 +141,3 @@ bool RetroShareLink::checkHash(const QString& hash)
return true ;
}

View File

@ -27,11 +27,12 @@
#include <stdint.h>
#include <QString>
#include <QVector>
#include <QUrl>
class RetroShareLink
{
public:
RetroShareLink(const QString& url);
RetroShareLink(const QUrl& url);
RetroShareLink(const QString& name, uint64_t size, const QString& hash);
uint64_t size() const { return _size ; }
@ -39,10 +40,9 @@ class RetroShareLink
const QString& hash() const { return _hash ; }
QString toString() const ;
QUrl toUrl() 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) ;

View File

@ -254,12 +254,9 @@ void SearchDialog::searchtableWidgetCostumPopupMenu( QPoint point )
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);
contextMnu->exec( mevent->globalPos() );
@ -1195,6 +1192,8 @@ void SearchDialog::copysearchLink()
int numdls = itemsForCopy.size();
QTreeWidgetItem * item;
QList<QUrl> urls ;
for (int i = 0; i < numdls; ++i)
{
item = itemsForCopy.at(i);
@ -1211,10 +1210,13 @@ void SearchDialog::copysearchLink()
RetroShareLink link(fname, fsize, fhash);
QApplication::clipboard()->setText(link.toString());
break ;
if(link.valid())
urls.push_back(link.toUrl()) ;
}
}
QMimeData *dt = new QMimeData;
dt->setUrls(urls) ;
QApplication::clipboard()->setMimeData(dt) ;
}
void SearchDialog::sendLinkTo( )

View File

@ -251,43 +251,43 @@ void SharedFilesDialog::copyLink (const QModelIndexList& lst, bool remote)
else
localModel->getDirDetailsFromSelect(lst, dirVec);
QList<QUrl> urls ;
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();
cit != details.children.end(); ++cit)
for (std::list<DirStub>::const_iterator cit = details.children.begin();cit != details.children.end(); ++cit)
{
const DirStub& dirStub = *cit;
DirDetails details;
uint32_t flags = DIR_FLAGS_DETAILS;
if (remote)
{
flags |= DIR_FLAGS_REMOTE;
}
else
{
flags |= DIR_FLAGS_LOCAL;
}
// do not recursive copy sub dirs.
if (!rsFiles->RequestDirDetails(dirStub.ref, details, flags) || details.type != DIR_TYPE_FILE)
continue;
analyzer.setRetroShareLink (details.name.c_str(), QString::number(details.count), details.hash.c_str());
RetroShareLink link(details.name.c_str(), details.count, details.hash.c_str());
urls.push_back(link.toUrl()) ;
}
}
else
analyzer.setRetroShareLink (details.name.c_str(), QString::number(details.count), details.hash.c_str());
#endif
{
RetroShareLink link(details.name.c_str(), details.count, details.hash.c_str());
urls.push_back(link.toUrl()) ;
}
}
QMimeData *dt = new QMimeData ;
dt->setUrls(urls) ;
QApplication::clipboard()->setMimeData(dt) ;
}
void SharedFilesDialog::copyLinkRemote()

View File

@ -1072,12 +1072,15 @@ void TransfersDialog::showDetailsDialog()
void TransfersDialog::pasteLink()
{
RetroShareLink link(QApplication::clipboard()->text());
QList<QUrl> urllist = QApplication::clipboard()->mimeData()->urls() ;
if (!link.valid())
return;
for(QList<QUrl>::const_iterator it(urllist.begin());it!=urllist.end();++it)
{
RetroShareLink link(*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)

View File

@ -23,6 +23,7 @@
#include <gui/settings/rsharesettings.h>
#include <gui/RetroShareLink.h>
#include <QtGui>
#include <QFileDialog>
#include <QString>
@ -414,21 +415,14 @@ void CreateForumMsg::fileHashingFinished(AttachFileItem* file) {
void CreateForumMsg::pasteLink()
{
QList<QUrl> list = QApplication::clipboard()->mimeData()->urls();
QString link = QApplication::clipboard()->text();
if (link.startsWith("retroshare://", Qt::CaseInsensitive))
for(QList<QUrl>::const_iterator it(list.begin());it!=list.end();++it)
{
ui.forumMessage->setHtml("<a href='" + link + "'> " + link + "</a>");
RetroShareLink link(*it) ;
if(link.valid())
ui.forumMessage->insertHtml("<a href='" + link.toString() + "'> " + link.toString() + "</a> <br>") ;
}
else
{
QMessageBox::warning(this, tr("RetroShare"),tr("Clipboard does not contains RetroShare link('s)"),
QMessageBox::Ok, QMessageBox::Ok);
return;
}
}