added Copy/Paste/Send retroshare//: file urls/links

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1257 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
defnax 2009-05-18 14:23:55 +00:00
parent b7290c67ed
commit 30e4d8d078
12 changed files with 438 additions and 35 deletions

View File

@ -135,6 +135,7 @@ HEADERS += rshare.h \
gui/TrustView.h \
gui/MessengerWindow.h \
gui/PeersDialog.h \
gui/RetroShareLinkAnalyzer.h \
gui/SearchTreeWidget.h \
gui/SearchDialog.h \
gui/SharedFilesDialog.h \
@ -349,6 +350,7 @@ SOURCES += main.cpp \
gui/TrustView.cpp \
gui/MessengerWindow.cpp \
gui/PeersDialog.cpp \
gui/RetroShareLinkAnalyzer.cpp \
gui/SearchTreeWidget.cpp \
gui/SearchDialog.cpp \
gui/SharedFilesDialog.cpp \

View File

@ -0,0 +1,71 @@
/***************************************************************************
* 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 <QStringList>
#include "RetroShareLinkAnalyzer.h"
const QString RetroShareLinkAnalyzer::HEADER_NAME = "retroshare://file|";
RetroShareLinkAnalyzer::RetroShareLinkAnalyzer (const QString & url)
{
this->url = url;
}
void RetroShareLinkAnalyzer::setRetroShareLink (const QString & name, const QString & size, const QString & hash)
{
url.append(HEADER_NAME);
url.append(name);
url.append("|");
url.append(size);
url.append("|");
url.append(hash);
url.append("\n");
}
bool RetroShareLinkAnalyzer::getFileInformation(QVector<RetroShareLinkData>& linkList)
{
if (!isValid ())
return false;
QStringList urlList = url.split ("\n");
for (int i = 0, n = urlList.size(); i < n; ++i)
{
if (urlList[i].isEmpty ())
continue;
QStringList list = urlList[i].split ("|");
linkList.push_back (RetroShareLinkData (list.at (NAME_), list.at (SIZE_), list.at (HASH_)));
}
return true;
}
// easy check for now.
bool RetroShareLinkAnalyzer::isValid () const
{
QStringList urlList = url.split ("\n");
if (urlList.isEmpty ())
return false;
QStringList list = urlList[0].split ("|");
return (list.size() % NUMBER_OF_PARTITIONS == 0);
}

View File

@ -0,0 +1,76 @@
/***************************************************************************
* 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
#include <QString>
#include <QVector>
struct RetroShareLinkData
{
public:
RetroShareLinkData () {}
RetroShareLinkData (const QString& n, const QString& s, const QString& h)
: name (n)
, size (s)
, hash (h)
{}
const QString& getName () const {return name;}
const QString& getSize () const {return size;}
const QString& getHash () const {return hash;}
private:
QString name;
QString size;
QString hash;
};
class RetroShareLinkAnalyzer
{
public:
RetroShareLinkAnalyzer(const QString& url = "");
void setRetroShareLink(const QString& name, const QString& size, const QString& hash);
void setRetroShareLink(const QString& url) {this->url = url;}
const QString& getRetroShareLink() const {return url;}
bool isValid() const;
// Get file name, size, hash from kommute link list.
// Return true if kommute link is valid, otherwise return false.
bool getFileInformation(QVector<RetroShareLinkData>& linkList);
private:
enum PARTITION
{
HEADER_,
NAME_,
SIZE_,
HASH_,
NUMBER_OF_PARTITIONS
};
static const QString HEADER_NAME;
QString url;
};
#endif

View File

@ -32,9 +32,14 @@
#include "msgs/ChanMsgDialog.h"
#include "Preferences/rsharesettings.h"
#ifndef RETROSHARE_LINK_ANALYZER
#include "RetroShareLinkAnalyzer.h"
#endif
#include <iostream>
#include <sstream>
#include <QClipboard>
#include <QDesktopServices>
#include <QContextMenuEvent>
#include <QMenu>
@ -59,6 +64,8 @@
#define IMAGE_ATTACHMENT ":/images/attachment.png"
#define IMAGE_FRIEND ":/images/peers_16x16.png"
#define IMAGE_PROGRESS ":/images/browse-looking.gif"
#define IMAGE_COPYLINK ":/images/copyrslink.png"
const QString Image_AddNewAssotiationForFile = ":/images/kcmsystem24.png";
@ -193,12 +200,21 @@ void SharedFilesDialog::shareddirtreeviewCostumPopupMenu( QPoint point )
downloadAct = new QAction(QIcon(IMAGE_DOWNLOAD), tr( "Download" ), this );
connect( downloadAct , SIGNAL( triggered() ), this, SLOT( downloadRemoteSelected() ) );
copyremotelinkAct = new QAction(QIcon(IMAGE_COPYLINK), tr( "Copy retroshare Link" ), this );
connect( copyremotelinkAct , SIGNAL( triggered() ), this, SLOT( copyLinkRemote() ) );
sendremotelinkAct = new QAction(QIcon(IMAGE_COPYLINK), tr( "Send retroshare Link" ), this );
connect( sendremotelinkAct , SIGNAL( triggered() ), this, SLOT( sendremoteLinkTo( ) ) );
// addMsgAct = new QAction( tr( "Add to Message" ), this );
// connect( addMsgAct , SIGNAL( triggered() ), this, SLOT( addMsgRemoteSelected() ) );
contextMnu.clear();
contextMnu.addAction( downloadAct);
contextMnu.addSeparator();
contextMnu.addAction( copyremotelinkAct);
contextMnu.addAction( sendremotelinkAct);
// contextMnu.addAction( addMsgAct);
contextMnu.exec( mevent->globalPos() );
}
@ -217,6 +233,106 @@ void SharedFilesDialog::downloadRemoteSelected()
}
void SharedFilesDialog::copyLink (const QModelIndexList& lst, bool remote)
{
std::vector<DirDetails> dirVec;
if (remote)
model->getDirDetailsFromSelect(lst, dirVec);
else
localModel->getDirDetailsFromSelect(lst, dirVec);
RetroShareLinkAnalyzer analyzer;
for (int i = 0, n = dirVec.size(); i < n; ++i)
{
const DirDetails& details = dirVec[i];
if (details.type == DIR_TYPE_DIR)
{
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());
}
}
else
analyzer.setRetroShareLink (details.name.c_str(), QString::number(details.count), details.hash.c_str());
}
QClipboard *clipboard = QApplication::clipboard();
clipboard->setText(analyzer.getRetroShareLink ());
//QMessageBox::warning(this, tr("RetroShare"), analyzer.getKommuteLink (), QMessageBox::Ok);
}
void SharedFilesDialog::copyLinkRemote()
{
QModelIndexList lst = ui.remoteDirTreeView->selectionModel ()->selectedIndexes ();
copyLink (lst, true);
}
void SharedFilesDialog::copyLinkLocal()
{
QModelIndexList lst = ui.localDirTreeView->selectionModel ()->selectedIndexes ();
copyLink (lst, false);
}
void SharedFilesDialog::sendremoteLinkTo()
{
copyLinkRemote ();
/* create a message */
ChanMsgDialog *nMsgDialog = new ChanMsgDialog(true);
/* fill it in
* files are receommended already
* just need to set peers
*/
std::cerr << "SharedFilesDialog::sendremoteLinkTo()" << std::endl;
nMsgDialog->newMsg();
nMsgDialog->insertTitleText("RetroShare Link");
nMsgDialog->insertMsgText(QApplication::clipboard()->text().toStdString());
nMsgDialog->show();
}
void SharedFilesDialog::sendLinkTo( /*std::string rsid*/ )
{
copyLinkLocal ();
/* create a message */
ChanMsgDialog *nMsgDialog = new ChanMsgDialog(true);
/* fill it in
* files are receommended already
* just need to set peers
*/
std::cerr << "SharedFilesDialog::sendLinkTo()" << std::endl;
nMsgDialog->newMsg();
nMsgDialog->insertTitleText("RetroShare Link");
nMsgDialog->insertMsgText(QApplication::clipboard()->text().toStdString());
nMsgDialog->show();
}
void SharedFilesDialog::playselectedfiles()
@ -393,8 +509,8 @@ void SharedFilesDialog::sharedDirTreeWidgetContextMenu( QPoint point )
{
//=== at this moment we'll show menu only for files, not for folders
QModelIndex midx = ui.localDirTreeView->indexAt(point);
if (localModel->isDir( midx ) )
return;
//if (localModel->isDir( midx ) )
// return;
currentFile = localModel->data(midx,
RemoteDirModel::FileNameRole).toString();
@ -461,10 +577,18 @@ void SharedFilesDialog::sharedDirTreeWidgetContextMenu( QPoint point )
}
//#endif
copylinklocalAct = new QAction(QIcon(IMAGE_COPYLINK), tr( "Copy retroshare Link" ), this );
connect( copylinklocalAct , SIGNAL( triggered() ), this, SLOT( copyLinkLocal() ) );
sendlinkAct = new QAction(QIcon(IMAGE_COPYLINK), tr( "Send retroshare Link" ), this );
connect( sendlinkAct , SIGNAL( triggered() ), this, SLOT( sendLinkTo( /*std::string rsid*/ ) ) );
contextMnu2.addAction( menuAction );
//contextMnu2.addAction( openfileAct);
contextMnu2.addAction( copylinklocalAct);
contextMnu2.addAction( sendlinkAct);
contextMnu2.addSeparator();
contextMnu2.addMenu( recMenu);
contextMnu2.addMenu( msgMenu);

View File

@ -61,6 +61,11 @@ private slots:
void downloadRemoteSelected();
// void addMsgRemoteSelected();
void copyLinkRemote();
void copyLinkLocal();
void sendLinkTo();
void sendremoteLinkTo();
//void showFrame(bool show);
@ -86,6 +91,8 @@ private:
//QMenu* contextMnu2;
void copyLink (const QModelIndexList& lst, bool remote);
/** Defines the actions for the context menu for QTreeView */
QAction* downloadAct;
QAction* addMsgAct;
@ -93,6 +100,10 @@ private:
/** Defines the actions for the context menu for QTreeWidget */
QAction* openfileAct;
QAction* openfolderAct;
QAction* copyremotelinkAct;
QAction* copylinklocalAct;
QAction* sendremotelinkAct;
QAction* sendlinkAct;
QTreeView *shareddirtreeview;

View File

@ -22,6 +22,7 @@
#include "rshare.h"
#include "TransfersDialog.h"
#include "RetroShareLinkAnalyzer.h"
#include "DLListDelegate.h"
#include "ULListDelegate.h"
@ -43,7 +44,9 @@
#define IMAGE_INFO ":/images/fileinfo.png"
#define IMAGE_CANCEL ":/images/delete.png"
#define IMAGE_CLEARCOMPLETED ":/images/deleteall.png"
#define IMAGE_PLAY ":/images/player_play.png"
#define IMAGE_PLAY ":/images/player_play.png"
#define IMAGE_COPYLINK ":/images/copyrslink.png"
#define IMAGE_PASTELINK ":/images/pasterslink.png"
/** Constructor */
TransfersDialog::TransfersDialog(QWidget *parent)
@ -188,9 +191,15 @@ void TransfersDialog::downloadListCostumPopupMenu( QPoint point )
connect( playAct , SIGNAL( triggered() ), this, SLOT( playSelectedTransfer() ) );
}
cancelAct = new QAction(QIcon(IMAGE_CANCEL), tr( "Cancel" ), this );
cancelAct = new QAction(QIcon(IMAGE_CANCEL), tr( "Cancel" ), this );
connect( cancelAct , SIGNAL( triggered() ), this, SLOT( cancel() ) );
copylinkAct = new QAction(QIcon(IMAGE_COPYLINK), tr( "Copy retroshare Link" ), this );
connect( copylinkAct , SIGNAL( triggered() ), this, SLOT( copyLink() ) );
pastelinkAct = new QAction(QIcon(IMAGE_PASTELINK), tr( "Paste retroshare Link" ), this );
connect( pastelinkAct , SIGNAL( triggered() ), this, SLOT( pasteLink() ) );
clearcompletedAct = new QAction(QIcon(IMAGE_CLEARCOMPLETED), tr( "Clear Completed" ), this );
connect( clearcompletedAct , SIGNAL( triggered() ), this, SLOT( clearcompleted() ) );
@ -203,6 +212,9 @@ void TransfersDialog::downloadListCostumPopupMenu( QPoint point )
contextMnu.addAction( cancelAct);
contextMnu.addSeparator();
contextMnu.addAction( copylinkAct);
contextMnu.addAction( pastelinkAct);
contextMnu.addSeparator();
contextMnu.addAction( clearcompletedAct);
contextMnu.exec( mevent->globalPos() );
}
@ -627,6 +639,72 @@ void TransfersDialog::cancel()
return;
}
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::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() ;
QString fname= ind.model ()->data (ind.model ()->index (ind.row (), NAME)).toString() ;
analyzer.setRetroShareLink (fname, fsize, fhash);
}
}
QClipboard *clipboard = QApplication::clipboard();
clipboard->setText(analyzer.getRetroShareLink ());
}
void TransfersDialog::pasteLink()
{
QClipboard *clipboard = QApplication::clipboard();
RetroShareLinkAnalyzer analyzer (clipboard->text ());
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];
//downloadFileRequested(linkData.getName (), linkData.getSize ().toInt (),
// linkData.getHash (), "", -1, -1, -1, -1);
rsFiles->FileRequest (linkData.getName ().toStdString (), linkData.getHash ().toStdString (),
linkData.getSize ().toInt (), "", 0, srcIds);
}
}
void TransfersDialog::clearcompleted()
{
std::cerr << "TransfersDialog::clearcompleted()" << std::endl;

View File

@ -51,6 +51,8 @@ class TransfersDialog : public MainPage
public slots:
void insertTransfers();
void handleDownloadRequest(const QString& url);
private slots:
@ -61,6 +63,9 @@ class TransfersDialog : public MainPage
/** removes finished Downloads**/
void clearcompleted();
void playSelectedTransfer();
void copyLink();
void pasteLink();
signals:
void playFiles(QStringList files);
@ -87,6 +92,8 @@ class TransfersDialog : public MainPage
QAction* showdowninfoAct;
QAction* cancelAct;
QAction* clearcompletedAct;
QAction* copylinkAct;
QAction* pastelinkAct;
QTreeView *downloadList;

View File

@ -21,6 +21,7 @@
<file>images/channels16.png</file>
<file>images/channels24.png</file>
<file>images/channels32.png</file>
<file>images/copyrslink.png</file>
<file>images/contacts24.png</file>
<file>images/connection.png</file>
<file>images/Client0.png</file>
@ -237,6 +238,7 @@
<file>images/new-mail-alert.png</file>
<file>images/new_forum16.png</file>
<file>images/nopic.png</file>
<file>images/pasterslink.png</file>
<file>images/package_games1.png</file>
<file>images/peerdetails_16x16.png</file>
<file>images/peers_16x16.png</file>

Binary file not shown.

After

Width:  |  Height:  |  Size: 637 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@ -730,40 +730,69 @@ void RemoteDirModel::downloadSelected(QModelIndexList list)
* make it into something the RsControl can understand
*/
std::vector <DirDetails> dirVec;
getDirDetailsFromSelect(list, dirVec);
/* Fire off requests */
QModelIndexList::iterator it;
for(it = list.begin(); it != list.end(); it++)
if(it->column()==1)
{
void *ref = it -> internalPointer();
for (int i = 0, n = dirVec.size(); i < n; ++i)
{
if (!RemoteMode)
{
continue; /* don't try to download local stuff */
}
DirDetails details;
uint32_t flags = DIR_FLAGS_DETAILS;
if (RemoteMode)
{
flags |= DIR_FLAGS_REMOTE;
}
else
{
flags |= DIR_FLAGS_LOCAL;
continue; /* don't try to download local stuff */
}
const DirDetails& details = dirVec[i];
if (!rsFiles->RequestDirDetails(ref, details, flags))
{
continue;
}
/* only request if it is a file */
if (details.type == DIR_TYPE_FILE)
{
std::cerr << "RemoteDirModel::downloadSelected() Calling File Request";
std::cerr << std::endl;
std::list<std::string> srcIds;
srcIds.push_back(details.id);
rsFiles -> FileRequest(details.name, details.hash,
details.count, "", 0, srcIds);
}
}
/* if it is a file */
if (details.type == DIR_TYPE_FILE)
{
std::cerr << "RemoteDirModel::downloadSelected() Calling File Request";
std::cerr << std::endl;
std::list<std::string> srcIds;
srcIds.push_back(details.id);
rsFiles -> FileRequest(details.name, details.hash,
details.count, "", 0, srcIds);
}
/* if it is a dir, copy all files included*/
else if (details.type == DIR_TYPE_DIR)
{
}
}
}
void RemoteDirModel::getDirDetailsFromSelect (QModelIndexList list, std::vector <DirDetails>& dirVec)
{
dirVec.clear();
/* Fire off requests */
QModelIndexList::iterator it;
for(it = list.begin(); it != list.end(); it++)
{
if(it->column()==1)
{
void *ref = it -> internalPointer();
DirDetails details;
uint32_t flags = DIR_FLAGS_DETAILS;
if (RemoteMode)
{
flags |= DIR_FLAGS_REMOTE;
}
else
{
flags |= DIR_FLAGS_LOCAL;
}
if (!rsFiles->RequestDirDetails(ref, details, flags))
{
continue;
}
dirVec.push_back(details);
}
}
}
/****************************************************************************

View File

@ -7,6 +7,7 @@
#include <string>
#include <rsiface/rsfiles.h>
#include "util/misc.h"
#include "rsiface/rstypes.h"
class RemoteDirModel : public QAbstractItemModel
{
@ -38,6 +39,8 @@ public:
/* Callback from GUI */
void downloadSelected(QModelIndexList list);
void getDirDetailsFromSelect (QModelIndexList list, std::vector <DirDetails>& dirVec);
bool isDir ( const QModelIndex & index ) const ;
//void openFile(QModelIndex fileIndex, const QString command);