From 68763f58d16e7e532f1bf89af860c486fa153505 Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 15 Oct 2017 20:52:21 +0200 Subject: [PATCH 01/19] added links machinery to handle file hierarchies --- retroshare-gui/src/gui/RetroShareLink.cpp | 86 ++++++++++++++-------- retroshare-gui/src/gui/RetroShareLink.h | 4 +- retroshare-gui/src/util/HandleRichText.cpp | 2 + 3 files changed, 62 insertions(+), 30 deletions(-) diff --git a/retroshare-gui/src/gui/RetroShareLink.cpp b/retroshare-gui/src/gui/RetroShareLink.cpp index b58e7186b..d1cb574c9 100644 --- a/retroshare-gui/src/gui/RetroShareLink.cpp +++ b/retroshare-gui/src/gui/RetroShareLink.cpp @@ -58,6 +58,7 @@ //#define DEBUG_RSLINK 1 #define HOST_FILE "file" +#define HOST_COLLECTION "collection" #define HOST_EXTRAFILE "extra" #define HOST_PERSON "person" #define HOST_FORUM "forum" @@ -75,6 +76,10 @@ #define FILE_HASH "hash" #define FILE_SOURCE "src" +#define COLLECTION_NAME "name" +#define COLLECTION_SIZE "size" +#define COLLECTION_DATA "radix" + #define PERSON_NAME "name" #define PERSON_HASH "hash" @@ -328,6 +333,19 @@ void RetroShareLink::fromUrl(const QUrl& url) return; } + if (url.host() == HOST_COLLECTION) { + bool ok; + _type = TYPE_COLLECTION; + _radix = decodedQueryItemValue(urlQuery, COLLECTION_DATA); + _size = urlQuery.queryItemValue(COLLECTION_SIZE).toULongLong(&ok); + _name = urlQuery.queryItemValue(COLLECTION_NAME).toULongLong(&ok); + +#ifdef DEBUG_RSLINK + std::cerr << "Got a certificate link!!" << std::endl; +#endif + check() ; + return; + } if (url.host() == HOST_CERTIFICATE) { _type = TYPE_CERTIFICATE; _radix = decodedQueryItemValue(urlQuery, CERTIFICATE_RADIX); @@ -400,6 +418,20 @@ RetroShareLink RetroShareLink::createFile(const QString& name, uint64_t size, co return link; } +RetroShareLink RetroShareLink::createCollection(const QString& name, const uint64_t size,const QString& radix_data) +{ + RetroShareLink link; + link.clear(); + + link._name = name; + link._size = size; + link._radix = radix_data ; + link._type = TYPE_COLLECTION; + + link.check(); + + return link; +} RetroShareLink RetroShareLink::createPublicMsgInvite(time_t time_stamp,const QString& issuer_pgp_id,const QString& hash) { RetroShareLink link; @@ -608,6 +640,8 @@ void RetroShareLink::check() if(!checkSSLId(_SSLid)) _valid = false; // no break! We also test file stuff below. /* fallthrough */ + case TYPE_COLLECTION: + case TYPE_FILE: if(_size > (((uint64_t)1)<<40)) // 1TB. Who has such large files? _valid = false; @@ -615,7 +649,7 @@ void RetroShareLink::check() if(!checkName(_name)) _valid = false; - if(!checkHash(_hash)) + if(!checkRadix64(_radix)) _valid = false; break; @@ -717,6 +751,8 @@ QString RetroShareLink::title() const rsPeers->getGPGDetails(RsPgpId(_GPGid.toStdString()), detail) ; return QObject::tr("Click to send a private message to %1 (%2).").arg(QString::fromUtf8(detail.name.c_str())).arg(_GPGid) ; } + case TYPE_COLLECTION: + return QObject::tr("Click to browse/download this file collection"); case TYPE_EXTRAFILE: return QObject::tr("%1 (%2, Extra - Source included)").arg(hash()).arg(misc::friendlyUnit(size())); case TYPE_FILE: @@ -860,6 +896,13 @@ QString RetroShareLink::toString() const break; + case TYPE_COLLECTION: + url.setScheme(RSLINK_SCHEME); + url.setHost(HOST_COLLECTION) ; + urlQuery.addQueryItem(CERTIFICATE_RADIX, encodeItem(_radix)); + urlQuery.addQueryItem(CERTIFICATE_NAME, encodeItem(_name)); + break; + case TYPE_CERTIFICATE: url.setScheme(RSLINK_SCHEME); url.setHost(HOST_CERTIFICATE) ; @@ -885,6 +928,9 @@ QString RetroShareLink::niceName() const if(type() == TYPE_IDENTITY) return QObject::tr("Identity link (name=%1, ID=%2)").arg(_name).arg(_hash) ; + if(type() == TYPE_COLLECTION) + return QObject::tr("Click to browse/download this file collection"); + if(type() == TYPE_PUBLIC_MSG) { RsPeerDetails detail; rsPeers->getGPGDetails(RsPgpId(_GPGid.toStdString()), detail) ; @@ -1095,6 +1141,7 @@ static void processList(const QStringList &list, const QString &textSingular, co case TYPE_SEARCH: case TYPE_MESSAGE: case TYPE_IDENTITY: + case TYPE_COLLECTION: case TYPE_CERTIFICATE: case TYPE_PUBLIC_MSG: case TYPE_PRIVATE_CHAT: @@ -1336,6 +1383,15 @@ static void processList(const QStringList &list, const QString &textSingular, co } break; + case TYPE_COLLECTION: + { + //FileHierarchy fh ; + //fh.initFromRadix(_radix); + + QMessageBox::information(NULL,"Unimplemented code","File collection links not handled yet.") ; + } + break; + case TYPE_PERSON: { #ifdef DEBUG_RSLINK @@ -1347,34 +1403,6 @@ static void processList(const QStringList &list, const QString &textSingular, co PGPKeyDialog::showIt(detail.gpg_id,PGPKeyDialog::PageDetails) ; else personNotFound.append(PeerDefs::rsid(link.name().toUtf8().constData(), RsPgpId(link.hash().toStdString()))); - -// needNotifySuccess = true; - -// RsPeerDetails detail; -// if (rsPeers->getGPGDetails(RsPgpId(link.hash().toStdString()), detail)) -// { -// if (RsPgpId(detail.gpg_id) == rsPeers->getGPGOwnId()) { -// // it's me, do nothing -// break; -// } -// -// if (detail.accept_connection) { -// // peer connection is already accepted -// personExist.append(PeerDefs::rsid(detail)); -// break; -// } -// -// if (rsPeers->addFriend(RsPeerId(), RsPgpId(link.hash().toStdString()))) { -// ConfCertDialog::loadAll(); -// personAdded.append(PeerDefs::rsid(detail)); -// break; -// } -// -// personFailed.append(PeerDefs::rsid(link.name().toUtf8().constData(), RsPgpId(link.hash().toStdString()))); -// break; -// } -// -// personNotFound.append(PeerDefs::rsid(link.name().toUtf8().constData(), RsPgpId(link.hash().toStdString()))); } break; diff --git a/retroshare-gui/src/gui/RetroShareLink.h b/retroshare-gui/src/gui/RetroShareLink.h index 131970887..a2e54798d 100644 --- a/retroshare-gui/src/gui/RetroShareLink.h +++ b/retroshare-gui/src/gui/RetroShareLink.h @@ -69,7 +69,8 @@ class RetroShareLink TYPE_PRIVATE_CHAT = 0x09, TYPE_PUBLIC_MSG = 0x0a, TYPE_POSTED = 0x0b, - TYPE_IDENTITY = 0x0c + TYPE_IDENTITY = 0x0c, + TYPE_COLLECTION = 0x0d }; public: @@ -80,6 +81,7 @@ class RetroShareLink static RetroShareLink createIdentity(const RsGxsId& gxs_id,const QString& name,const QString& radix_data) ; static RetroShareLink createExtraFile(const QString& name, uint64_t size, const QString& hash, const QString& ssl_id); static RetroShareLink createFile(const QString& name, uint64_t size, const QString& hash); + static RetroShareLink createCollection(const QString& name, const uint64_t size,const QString& radix_data); static RetroShareLink createPublicMsgInvite(time_t time_stamp,const QString& pgp_id,const QString& hash) ; static RetroShareLink createPerson(const RsPgpId &id); static RetroShareLink createCertificate(const RsPeerId &ssl_id) ; diff --git a/retroshare-gui/src/util/HandleRichText.cpp b/retroshare-gui/src/util/HandleRichText.cpp index 96fd36d73..91f3e13ab 100644 --- a/retroshare-gui/src/util/HandleRichText.cpp +++ b/retroshare-gui/src/util/HandleRichText.cpp @@ -227,6 +227,7 @@ bool RsHtml::canReplaceAnchor(QDomDocument &/*doc*/, QDomElement &/*element*/, c switch (link.type()) { case RetroShareLink::TYPE_UNKNOWN: case RetroShareLink::TYPE_FILE: + case RetroShareLink::TYPE_COLLECTION: case RetroShareLink::TYPE_PERSON: case RetroShareLink::TYPE_FORUM: case RetroShareLink::TYPE_CHANNEL: @@ -257,6 +258,7 @@ void RsHtml::anchorStylesheetForImg(QDomDocument &/*doc*/, QDomElement &/*elemen switch (link.type()) { case RetroShareLink::TYPE_UNKNOWN: case RetroShareLink::TYPE_FILE: + case RetroShareLink::TYPE_COLLECTION: case RetroShareLink::TYPE_PERSON: case RetroShareLink::TYPE_FORUM: case RetroShareLink::TYPE_CHANNEL: From 847c1b2bce93699b924ea219ff6e29a1480e336a Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 15 Oct 2017 21:10:29 +0200 Subject: [PATCH 02/19] renamed RsCollectionFile into RsCollectionEditor --- .../src/gui/FileTransfer/SearchDialog.cpp | 20 +++---- .../gui/FileTransfer/SharedFilesDialog.cpp | 33 ++++-------- .../src/gui/FileTransfer/TransfersDialog.cpp | 22 ++++---- retroshare-gui/src/gui/MainWindow.cpp | 8 +-- retroshare-gui/src/gui/RemoteDirModel.cpp | 4 +- retroshare-gui/src/gui/RetroShareLink.cpp | 6 +-- retroshare-gui/src/gui/common/FilesDefs.cpp | 4 +- .../src/gui/common/RsCollectionDialog.cpp | 10 ++-- .../src/gui/common/RsCollectionDialog.h | 2 +- ...lectionFile.cpp => RsCollectionEditor.cpp} | 54 +++++++++---------- ...sCollectionFile.h => RsCollectionEditor.h} | 8 +-- .../src/gui/common/RsUrlHandler.cpp | 6 +-- retroshare-gui/src/retroshare-gui.pro | 8 +-- 13 files changed, 87 insertions(+), 98 deletions(-) rename retroshare-gui/src/gui/common/{RsCollectionFile.cpp => RsCollectionEditor.cpp} (86%) rename retroshare-gui/src/gui/common/{RsCollectionFile.h => RsCollectionEditor.h} (93%) diff --git a/retroshare-gui/src/gui/FileTransfer/SearchDialog.cpp b/retroshare-gui/src/gui/FileTransfer/SearchDialog.cpp index 4607a2541..e55493a0c 100644 --- a/retroshare-gui/src/gui/FileTransfer/SearchDialog.cpp +++ b/retroshare-gui/src/gui/FileTransfer/SearchDialog.cpp @@ -30,7 +30,7 @@ #include "gui/RetroShareLink.h" #include "retroshare-gui/RsAutoUpdatePage.h" #include "gui/msgs/MessageComposer.h" -#include "gui/common/RsCollectionFile.h" +#include "gui/common/RsCollectionEditor.h" #include "gui/common/FilesDefs.h" #include "gui/common/RsUrlHandler.h" #include "gui/settings/rsharesettings.h" @@ -345,7 +345,7 @@ void SearchDialog::searchResultWidgetCustomPopupMenu( QPoint /*point*/ ) QList item =ui.searchResultWidget->selectedItems() ; if (item.at(0)->data(SR_DATA_COL, SR_ROLE_LOCAL).toBool()) { contextMnu.addAction(QIcon(IMAGE_OPENFOLDER), tr("Open Folder"), this, SLOT(openFolderSearch())) ; - if (item.at(0)->text(SR_NAME_COL).endsWith(RsCollectionFile::ExtensionString)) { + if (item.at(0)->text(SR_NAME_COL).endsWith(RsCollectionEditor::ExtensionString)) { add_CollActions = true ; }//if (item.at(0)->text(SR_NAME_COL).endsWith(RsCollectionFile::ExtensionString)) }//if (item.at(0)->data(SR_DATA_COL, SR_ROLE_LOCAL).toBool()) @@ -448,7 +448,7 @@ void SearchDialog::collCreate() }//if (!item->text(SR_HASH_COL).isEmpty()) }//for (int i = 0; i < numdls; ++i) - RsCollectionFile(dirVec).openNewColl(this); + RsCollectionEditor(dirVec).openNewColl(this); } void SearchDialog::collModif() @@ -476,8 +476,8 @@ void SearchDialog::collModif() QFileInfo qinfo; qinfo.setFile(QString::fromUtf8(path.c_str())); if (qinfo.exists()) { - if (qinfo.absoluteFilePath().endsWith(RsCollectionFile::ExtensionString)) { - RsCollectionFile collection; + if (qinfo.absoluteFilePath().endsWith(RsCollectionEditor::ExtensionString)) { + RsCollectionEditor collection; collection.openColl(qinfo.absoluteFilePath()); }//if (qinfo.absoluteFilePath().endsWith(RsCollectionFile::ExtensionString)) }//if (qinfo.exists()) @@ -508,8 +508,8 @@ void SearchDialog::collView() QFileInfo qinfo; qinfo.setFile(QString::fromUtf8(path.c_str())); if (qinfo.exists()) { - if (qinfo.absoluteFilePath().endsWith(RsCollectionFile::ExtensionString)) { - RsCollectionFile collection; + if (qinfo.absoluteFilePath().endsWith(RsCollectionEditor::ExtensionString)) { + RsCollectionEditor collection; collection.openColl(qinfo.absoluteFilePath(), true); }//if (qinfo.absoluteFilePath().endsWith(RsCollectionFile::ExtensionString)) }//if (qinfo.exists()) @@ -540,8 +540,8 @@ void SearchDialog::collOpen() QFileInfo qinfo; qinfo.setFile(QString::fromUtf8(path.c_str())); if (qinfo.exists()) { - if (qinfo.absoluteFilePath().endsWith(RsCollectionFile::ExtensionString)) { - RsCollectionFile collection; + if (qinfo.absoluteFilePath().endsWith(RsCollectionEditor::ExtensionString)) { + RsCollectionEditor collection; if (collection.load(qinfo.absoluteFilePath())) { collection.downloadFiles(); return; @@ -552,7 +552,7 @@ void SearchDialog::collOpen() } } - RsCollectionFile collection; + RsCollectionEditor collection; if (collection.load(this)) { collection.downloadFiles(); }//if (collection.load(this)) diff --git a/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp b/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp index 9b1dac00d..9279642c3 100644 --- a/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp +++ b/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp @@ -37,7 +37,7 @@ #include "gui/RetroShareLink.h" #include "gui/ShareManager.h" #include "gui/common/PeerDefs.h" -#include "gui/common/RsCollectionFile.h" +#include "gui/common/RsCollectionEditor.h" #include "gui/msgs/MessageComposer.h" #include "gui/settings/AddFileAssociationDialog.h" #include "gui/settings/rsharesettings.h" @@ -499,17 +499,12 @@ void RemoteSharedFilesDialog::spawnCustomPopupMenu( QPoint point ) QMenu contextMnu( this ) ; - //bool bIsRsColl = currentFile.endsWith(RsCollectionFile::ExtensionString); collCreateAct->setEnabled(true); - //collModifAct->setEnabled(bIsRsColl); - //collViewAct->setEnabled(bIsRsColl); collOpenAct->setEnabled(true); QMenu collectionMenu(tr("Collection"), this); collectionMenu.setIcon(QIcon(IMAGE_LIBRARY)); collectionMenu.addAction(collCreateAct); - //collectionMenu.addAction(collModifAct); - //collectionMenu.addAction(collViewAct); collectionMenu.addAction(collOpenAct); QAction *downloadAct = new QAction(QIcon(IMAGE_DOWNLOAD), tr( "Download" ), &contextMnu ) ; @@ -517,18 +512,12 @@ void RemoteSharedFilesDialog::spawnCustomPopupMenu( QPoint point ) contextMnu.addAction( downloadAct) ; if ( type == DIR_TYPE_FILE ) { - //QAction *copyremotelinkAct = new QAction(QIcon(IMAGE_COPYLINK), tr( "Copy retroshare Link" ), &contextMnu ) ; - //connect( copyremotelinkAct , SIGNAL( triggered() ), this, SLOT( copyLink() ) ) ; - - //QAction *sendremotelinkAct = new QAction(QIcon(IMAGE_COPYLINK), tr( "Send retroshare Link" ), &contextMnu ) ; - //connect( sendremotelinkAct , SIGNAL( triggered() ), this, SLOT( sendremoteLinkTo( ) ) ) ; - contextMnu.addSeparator() ;//------------------------------------ contextMnu.addAction( copylinkAct) ; contextMnu.addAction( sendlinkAct) ; contextMnu.addSeparator() ;//------------------------------------ contextMnu.addAction(QIcon(IMAGE_MSG), tr("Recommend in a message to"), this, SLOT(recommendFilesToMsg())) ; - }//if (type == DIR_TYPE_FILE) + } contextMnu.addSeparator() ;//------------------------------------ contextMnu.addMenu(&collectionMenu) ; @@ -542,7 +531,7 @@ QModelIndexList SharedFilesDialog::getSelected() QModelIndexList proxyList ; for (QModelIndexList::iterator index = list.begin(); index != list.end(); ++index ) { proxyList.append(proxyModel->mapToSource(*index)) ; - }//for (QModelIndexList::iterator index + } return proxyList ; } @@ -692,8 +681,8 @@ void SharedFilesDialog::collModif() QFileInfo qinfo; qinfo.setFile(QString::fromUtf8(path.c_str())); if (qinfo.exists()) { - if (qinfo.absoluteFilePath().endsWith(RsCollectionFile::ExtensionString)) { - RsCollectionFile collection; + if (qinfo.absoluteFilePath().endsWith(RsCollectionEditor::ExtensionString)) { + RsCollectionEditor collection; collection.openColl(qinfo.absoluteFilePath()); }//if (qinfo.absoluteFilePath().endsWith(RsCollectionFile::ExtensionString)) }//if (qinfo.exists()) @@ -722,8 +711,8 @@ void SharedFilesDialog::collView() QFileInfo qinfo; qinfo.setFile(QString::fromUtf8(path.c_str())); if (qinfo.exists()) { - if (qinfo.absoluteFilePath().endsWith(RsCollectionFile::ExtensionString)) { - RsCollectionFile collection; + if (qinfo.absoluteFilePath().endsWith(RsCollectionEditor::ExtensionString)) { + RsCollectionEditor collection; collection.openColl(qinfo.absoluteFilePath(), true); }//if (qinfo.absoluteFilePath().endsWith(RsCollectionFile::ExtensionString)) }//if (qinfo.exists()) @@ -752,8 +741,8 @@ void SharedFilesDialog::collOpen() QFileInfo qinfo; qinfo.setFile(QString::fromUtf8(path.c_str())); if (qinfo.exists()) { - if (qinfo.absoluteFilePath().endsWith(RsCollectionFile::ExtensionString)) { - RsCollectionFile collection; + if (qinfo.absoluteFilePath().endsWith(RsCollectionEditor::ExtensionString)) { + RsCollectionEditor collection; if (collection.load(qinfo.absoluteFilePath())) { collection.downloadFiles(); return; @@ -763,7 +752,7 @@ void SharedFilesDialog::collOpen() } } - RsCollectionFile collection; + RsCollectionEditor collection; if (collection.load(this)) { collection.downloadFiles(); }//if (collection.load(this)) @@ -995,7 +984,7 @@ void LocalSharedFilesDialog::spawnCustomPopupMenu( QPoint point ) QMenu contextMnu(this) ; - bool bIsRsColl = currentFile.endsWith(RsCollectionFile::ExtensionString); + bool bIsRsColl = currentFile.endsWith(RsCollectionEditor::ExtensionString); collCreateAct->setEnabled(true); collModifAct->setEnabled(bIsRsColl); collViewAct->setEnabled(bIsRsColl); diff --git a/retroshare-gui/src/gui/FileTransfer/TransfersDialog.cpp b/retroshare-gui/src/gui/FileTransfer/TransfersDialog.cpp index aecc53bef..98bc7f3cb 100644 --- a/retroshare-gui/src/gui/FileTransfer/TransfersDialog.cpp +++ b/retroshare-gui/src/gui/FileTransfer/TransfersDialog.cpp @@ -31,7 +31,7 @@ #include #include -#include +#include #include #include @@ -50,7 +50,7 @@ #include "xprogressbar.h" #include #include "util/misc.h" -#include +#include #include "TransferUserNotify.h" #include "util/QtVersion.h" #include "util/RsFile.h" @@ -702,7 +702,7 @@ void TransfersDialog::downloadListCustomPopupMenu( QPoint /*point*/ ) add_PlayOption = !add_PreviewOption ; }// if (misc::isPreviewable(info.fname.substr(pos + 1).c_str())) // Check if the file is a collection - if (RsCollectionFile::ExtensionString == info.fname.substr(pos + 1).c_str()) { + if (RsCollectionEditor::ExtensionString == info.fname.substr(pos + 1).c_str()) { add_CollActions = (info.downloadStatus == FT_STATE_COMPLETE); }//if (RsCollectionFile::ExtensionString == info }// if(pos != std::string::npos) @@ -2155,7 +2155,7 @@ void TransfersDialog::collCreate() dirVec.push_back(details); }//for (it = items.begin(); - RsCollectionFile(dirVec).openNewColl(this); + RsCollectionEditor(dirVec).openNewColl(this); } void TransfersDialog::collModif() @@ -2180,8 +2180,8 @@ void TransfersDialog::collModif() QFileInfo qinfo; qinfo.setFile(QString::fromUtf8(path.c_str())); if (qinfo.exists()) { - if (qinfo.absoluteFilePath().endsWith(RsCollectionFile::ExtensionString)) { - RsCollectionFile collection; + if (qinfo.absoluteFilePath().endsWith(RsCollectionEditor::ExtensionString)) { + RsCollectionEditor collection; collection.openColl(qinfo.absoluteFilePath()); }//if (qinfo.absoluteFilePath().endsWith(RsCollectionFile::ExtensionString)) }//if (qinfo.exists()) @@ -2210,8 +2210,8 @@ void TransfersDialog::collView() QFileInfo qinfo; qinfo.setFile(QString::fromUtf8(path.c_str())); if (qinfo.exists()) { - if (qinfo.absoluteFilePath().endsWith(RsCollectionFile::ExtensionString)) { - RsCollectionFile collection; + if (qinfo.absoluteFilePath().endsWith(RsCollectionEditor::ExtensionString)) { + RsCollectionEditor collection; collection.openColl(qinfo.absoluteFilePath(), true); }//if (qinfo.absoluteFilePath().endsWith(RsCollectionFile::ExtensionString)) }//if (qinfo.exists()) @@ -2240,8 +2240,8 @@ void TransfersDialog::collOpen() QFileInfo qinfo; qinfo.setFile(QString::fromUtf8(path.c_str())); if (qinfo.exists()) { - if (qinfo.absoluteFilePath().endsWith(RsCollectionFile::ExtensionString)) { - RsCollectionFile collection; + if (qinfo.absoluteFilePath().endsWith(RsCollectionEditor::ExtensionString)) { + RsCollectionEditor collection; if (collection.load(qinfo.absoluteFilePath())) { collection.downloadFiles(); return; @@ -2252,7 +2252,7 @@ void TransfersDialog::collOpen() } } - RsCollectionFile collection; + RsCollectionEditor collection; if (collection.load(this)) { collection.downloadFiles(); }//if (collection.load(this)) diff --git a/retroshare-gui/src/gui/MainWindow.cpp b/retroshare-gui/src/gui/MainWindow.cpp index 0933f8e7b..d3bb3200f 100644 --- a/retroshare-gui/src/gui/MainWindow.cpp +++ b/retroshare-gui/src/gui/MainWindow.cpp @@ -103,7 +103,7 @@ #include "gui/statistics/StatisticsWindow.h" #include "gui/connect/ConnectFriendWizard.h" -#include "gui/common/RsCollectionFile.h" +#include "gui/common/RsCollectionEditor.h" #include "settings/rsettingswin.h" #include "settings/rsharesettings.h" #include "settings/WebuiPage.h" @@ -1020,7 +1020,7 @@ void MainWindow::newRsCollection() { std::vector dirVec; - RsCollectionFile(dirVec).openNewColl(this); + RsCollectionEditor(dirVec).openNewColl(this); } /** Shows Share Manager */ @@ -1448,8 +1448,8 @@ void MainWindow::openRsCollection(const QString &filename) { QFileInfo qinfo(filename); if (qinfo.exists()) { - if (qinfo.absoluteFilePath().endsWith(RsCollectionFile::ExtensionString)) { - RsCollectionFile collection; + if (qinfo.absoluteFilePath().endsWith(RsCollectionEditor::ExtensionString)) { + RsCollectionEditor collection; collection.openColl(qinfo.absoluteFilePath()); } } diff --git a/retroshare-gui/src/gui/RemoteDirModel.cpp b/retroshare-gui/src/gui/RemoteDirModel.cpp index 15ac3168e..29f08b6a5 100644 --- a/retroshare-gui/src/gui/RemoteDirModel.cpp +++ b/retroshare-gui/src/gui/RemoteDirModel.cpp @@ -26,7 +26,7 @@ #include #include -#include +#include #include #include #include @@ -1065,7 +1065,7 @@ void RetroshareDirModel::createCollectionFile(QWidget *parent, const QModelIndex std::vector dirVec; getDirDetailsFromSelect(list, dirVec); - RsCollectionFile(dirVec).openNewColl(parent); + RsCollectionEditor(dirVec).openNewColl(parent); } void RetroshareDirModel::downloadSelected(const QModelIndexList &list) diff --git a/retroshare-gui/src/gui/RetroShareLink.cpp b/retroshare-gui/src/gui/RetroShareLink.cpp index d1cb574c9..27ec2c1a9 100644 --- a/retroshare-gui/src/gui/RetroShareLink.cpp +++ b/retroshare-gui/src/gui/RetroShareLink.cpp @@ -43,7 +43,7 @@ #include "msgs/MessageComposer.h" #include "util/misc.h" #include "common/PeerDefs.h" -#include "common/RsCollectionFile.h" +#include "common/RsCollectionEditor.h" #include #include "gui/connect/ConnectFriendWizard.h" #include "gui/connect/ConfCertDialog.h" @@ -972,10 +972,10 @@ QString RetroShareLink::toHtmlSize() const { QString size = QString("(%1)").arg(misc::friendlyUnit(_size)); - if (type() == TYPE_FILE && RsCollectionFile::isCollectionFile(name())) { + if (type() == TYPE_FILE && RsCollectionEditor::isCollectionFile(name())) { FileInfo finfo; if (rsFiles->FileDetails(RsFileHash(hash().toStdString()), RS_FILE_HINTS_EXTRA | RS_FILE_HINTS_LOCAL, finfo)) { - RsCollectionFile collection; + RsCollectionEditor collection; if (collection.load(QString::fromUtf8(finfo.path.c_str()), false)) { size += QString(" [%1]").arg(misc::friendlyUnit(collection.size())); } diff --git a/retroshare-gui/src/gui/common/FilesDefs.cpp b/retroshare-gui/src/gui/common/FilesDefs.cpp index 7c4fc9140..063c85e3b 100644 --- a/retroshare-gui/src/gui/common/FilesDefs.cpp +++ b/retroshare-gui/src/gui/common/FilesDefs.cpp @@ -23,7 +23,7 @@ #include #include "FilesDefs.h" -#include "RsCollectionFile.h" +#include "RsCollectionEditor.h" static QString getInfoFromFilename(const QString& filename, bool anyForUnknown, bool image) { @@ -54,7 +54,7 @@ static QString getInfoFromFilename(const QString& filename, bool anyForUnknown, return image ? ":/images/FileTypeDocument.png" : QApplication::translate("FilesDefs", "Document"); } else if (ext == "pdf") { return image ? ":/images/mimetypes/pdf.png" : QApplication::translate("FilesDefs", "Document"); - } else if (ext == RsCollectionFile::ExtensionString) { + } else if (ext == RsCollectionEditor::ExtensionString) { return image ? ":/images/mimetypes/rscollection-16.png" : QApplication::translate("FilesDefs", "RetroShare collection file"); } else if (ext == "sub" || ext == "srt") { return image ? ":/images/FileTypeAny.png" : QApplication::translate("FilesDefs", "Subtitles"); diff --git a/retroshare-gui/src/gui/common/RsCollectionDialog.cpp b/retroshare-gui/src/gui/common/RsCollectionDialog.cpp index eb920f219..ee0aeec39 100644 --- a/retroshare-gui/src/gui/common/RsCollectionDialog.cpp +++ b/retroshare-gui/src/gui/common/RsCollectionDialog.cpp @@ -29,7 +29,7 @@ #include #include #include "RsCollectionDialog.h" -#include "RsCollectionFile.h" +#include "RsCollectionEditor.h" #include "util/misc.h" #define COLUMN_FILE 0 #define COLUMN_FILEPATH 1 @@ -591,12 +591,12 @@ void RsCollectionDialog::changeFileName() QString fileName; if(!misc::getSaveFileName(this, RshareSettings::LASTDIR_EXTRAFILE , QApplication::translate("RsCollectionFile", "Create collection file") - , QApplication::translate("RsCollectionFile", "Collection files") + " (*." + RsCollectionFile::ExtensionString + ")" + , QApplication::translate("RsCollectionFile", "Collection files") + " (*." + RsCollectionEditor::ExtensionString + ")" , fileName,0, QFileDialog::DontConfirmOverwrite)) return; - if (!fileName.endsWith("." + RsCollectionFile::ExtensionString)) - fileName += "." + RsCollectionFile::ExtensionString ; + if (!fileName.endsWith("." + RsCollectionEditor::ExtensionString)) + fileName += "." + RsCollectionEditor::ExtensionString ; std::cerr << "Got file name: " << fileName.toStdString() << std::endl; @@ -604,7 +604,7 @@ void RsCollectionDialog::changeFileName() if(file.exists()) { - RsCollectionFile collFile; + RsCollectionEditor collFile; if (!collFile.checkFile(fileName,true)) return; QMessageBox mb; diff --git a/retroshare-gui/src/gui/common/RsCollectionDialog.h b/retroshare-gui/src/gui/common/RsCollectionDialog.h index 2c5721d8b..e5e5df86d 100644 --- a/retroshare-gui/src/gui/common/RsCollectionDialog.h +++ b/retroshare-gui/src/gui/common/RsCollectionDialog.h @@ -22,7 +22,7 @@ ****************************************************************/ #include "ui_RsCollectionDialog.h" -#include "RsCollectionFile.h" +#include "RsCollectionEditor.h" #include #include diff --git a/retroshare-gui/src/gui/common/RsCollectionFile.cpp b/retroshare-gui/src/gui/common/RsCollectionEditor.cpp similarity index 86% rename from retroshare-gui/src/gui/common/RsCollectionFile.cpp rename to retroshare-gui/src/gui/common/RsCollectionEditor.cpp index 3e4792063..7abfe3f92 100644 --- a/retroshare-gui/src/gui/common/RsCollectionFile.cpp +++ b/retroshare-gui/src/gui/common/RsCollectionEditor.cpp @@ -24,7 +24,7 @@ #include #include -#include "RsCollectionFile.h" +#include "RsCollectionEditor.h" #include "RsCollectionDialog.h" #include "util/misc.h" @@ -36,14 +36,14 @@ #include #include -const QString RsCollectionFile::ExtensionString = QString("rscollection") ; +const QString RsCollectionEditor::ExtensionString = QString("rscollection") ; -RsCollectionFile::RsCollectionFile(QObject *parent) +RsCollectionEditor::RsCollectionEditor(QObject *parent) : QObject(parent), _xml_doc("RsCollection") { } -RsCollectionFile::RsCollectionFile(const std::vector& file_infos, QObject *parent) +RsCollectionEditor::RsCollectionEditor(const std::vector& file_infos, QObject *parent) : QObject(parent), _xml_doc("RsCollection") { QDomElement root = _xml_doc.createElement("RsCollection"); @@ -53,11 +53,11 @@ RsCollectionFile::RsCollectionFile(const std::vector& file_infos, QO recursAddElements(_xml_doc,file_infos[i],root) ; } -RsCollectionFile::~RsCollectionFile() +RsCollectionEditor::~RsCollectionEditor() { } -void RsCollectionFile::downloadFiles() const +void RsCollectionEditor::downloadFiles() const { // print out the element names of all elements that are direct children // of the outermost element. @@ -87,7 +87,7 @@ static QString purifyFileName(const QString& input,bool& bad) return output ; } -void RsCollectionFile::recursCollectColFileInfos(const QDomElement& e,std::vector& colFileInfos,const QString& current_path, bool bad_chars_in_parent) const +void RsCollectionEditor::recursCollectColFileInfos(const QDomElement& e,std::vector& colFileInfos,const QString& current_path, bool bad_chars_in_parent) const { QDomNode n = e.firstChild() ; @@ -139,7 +139,7 @@ void RsCollectionFile::recursCollectColFileInfos(const QDomElement& e,std::vecto } -void RsCollectionFile::recursAddElements(QDomDocument& doc,const DirDetails& details,QDomElement& e) const +void RsCollectionEditor::recursAddElements(QDomDocument& doc,const DirDetails& details,QDomElement& e) const { if (details.type == DIR_TYPE_FILE) { @@ -175,7 +175,7 @@ void RsCollectionFile::recursAddElements(QDomDocument& doc,const DirDetails& det } } -void RsCollectionFile::recursAddElements(QDomDocument& doc,const ColFileInfo& colFileInfo,QDomElement& e) const +void RsCollectionEditor::recursAddElements(QDomDocument& doc,const ColFileInfo& colFileInfo,QDomElement& e) const { if (colFileInfo.type == DIR_TYPE_FILE) { @@ -208,7 +208,7 @@ static void showErrorBox(const QString& fileName, const QString& error) mb.exec(); } -bool RsCollectionFile::load(const QString& fileName, bool showError /* = true*/) +bool RsCollectionEditor::load(const QString& fileName, bool showError /* = true*/) { if (!checkFile(fileName,showError)) return false; @@ -238,7 +238,7 @@ bool RsCollectionFile::load(const QString& fileName, bool showError /* = true*/) } // check that the file is a valid rscollection file, and not a lol bomb or some shit like this -bool RsCollectionFile::checkFile(const QString& fileName, bool showError) +bool RsCollectionEditor::checkFile(const QString& fileName, bool showError) { QFile file(fileName); @@ -306,10 +306,10 @@ bool RsCollectionFile::checkFile(const QString& fileName, bool showError) return false; } -bool RsCollectionFile::load(QWidget *parent) +bool RsCollectionEditor::load(QWidget *parent) { QString fileName; - if (!misc::getOpenFileName(parent, RshareSettings::LASTDIR_EXTRAFILE, QApplication::translate("RsCollectionFile", "Open collection file"), QApplication::translate("RsCollectionFile", "Collection files") + " (*." + RsCollectionFile::ExtensionString + ")", fileName)) + if (!misc::getOpenFileName(parent, RshareSettings::LASTDIR_EXTRAFILE, QApplication::translate("RsCollectionFile", "Open collection file"), QApplication::translate("RsCollectionFile", "Collection files") + " (*." + RsCollectionEditor::ExtensionString + ")", fileName)) return false; std::cerr << "Got file name: " << fileName.toStdString() << std::endl; @@ -317,7 +317,7 @@ bool RsCollectionFile::load(QWidget *parent) return load(fileName, true); } -bool RsCollectionFile::save(const QString& fileName) const +bool RsCollectionEditor::save(const QString& fileName) const { QFile file(fileName); @@ -337,14 +337,14 @@ bool RsCollectionFile::save(const QString& fileName) const return true; } -bool RsCollectionFile::save(QWidget *parent) const +bool RsCollectionEditor::save(QWidget *parent) const { QString fileName; - if(!misc::getSaveFileName(parent, RshareSettings::LASTDIR_EXTRAFILE, QApplication::translate("RsCollectionFile", "Create collection file"), QApplication::translate("RsCollectionFile", "Collection files") + " (*." + RsCollectionFile::ExtensionString + ")", fileName)) + if(!misc::getSaveFileName(parent, RshareSettings::LASTDIR_EXTRAFILE, QApplication::translate("RsCollectionFile", "Create collection file"), QApplication::translate("RsCollectionFile", "Collection files") + " (*." + RsCollectionEditor::ExtensionString + ")", fileName)) return false; - if (!fileName.endsWith("." + RsCollectionFile::ExtensionString)) - fileName += "." + RsCollectionFile::ExtensionString ; + if (!fileName.endsWith("." + RsCollectionEditor::ExtensionString)) + fileName += "." + RsCollectionEditor::ExtensionString ; std::cerr << "Got file name: " << fileName.toStdString() << std::endl; @@ -352,17 +352,17 @@ bool RsCollectionFile::save(QWidget *parent) const } -bool RsCollectionFile::openNewColl(QWidget *parent) +bool RsCollectionEditor::openNewColl(QWidget *parent) { QString fileName; if(!misc::getSaveFileName(parent, RshareSettings::LASTDIR_EXTRAFILE , QApplication::translate("RsCollectionFile", "Create collection file") - , QApplication::translate("RsCollectionFile", "Collection files") + " (*." + RsCollectionFile::ExtensionString + ")" + , QApplication::translate("RsCollectionFile", "Collection files") + " (*." + RsCollectionEditor::ExtensionString + ")" , fileName,0, QFileDialog::DontConfirmOverwrite)) return false; - if (!fileName.endsWith("." + RsCollectionFile::ExtensionString)) - fileName += "." + RsCollectionFile::ExtensionString ; + if (!fileName.endsWith("." + RsCollectionEditor::ExtensionString)) + fileName += "." + RsCollectionEditor::ExtensionString ; std::cerr << "Got file name: " << fileName.toStdString() << std::endl; @@ -419,7 +419,7 @@ bool RsCollectionFile::openNewColl(QWidget *parent) return _saved; } -bool RsCollectionFile::openColl(const QString& fileName, bool readOnly /* = false */, bool showError /* = true*/) +bool RsCollectionEditor::openColl(const QString& fileName, bool readOnly /* = false */, bool showError /* = true*/) { if (load(fileName, showError)) { std::vector colFileInfos ; @@ -437,7 +437,7 @@ bool RsCollectionFile::openColl(const QString& fileName, bool readOnly /* = fals return false; } -qulonglong RsCollectionFile::size() +qulonglong RsCollectionEditor::size() { QDomElement docElem = _xml_doc.documentElement(); @@ -453,14 +453,14 @@ qulonglong RsCollectionFile::size() return size; } -bool RsCollectionFile::isCollectionFile(const QString &fileName) +bool RsCollectionEditor::isCollectionFile(const QString &fileName) { QString ext = QFileInfo(fileName).suffix().toLower(); - return (ext == RsCollectionFile::ExtensionString); + return (ext == RsCollectionEditor::ExtensionString); } -void RsCollectionFile::saveColl(std::vector colFileInfos, const QString &fileName) +void RsCollectionEditor::saveColl(std::vector colFileInfos, const QString &fileName) { QDomElement root = _xml_doc.elementsByTagName("RsCollection").at(0).toElement(); diff --git a/retroshare-gui/src/gui/common/RsCollectionFile.h b/retroshare-gui/src/gui/common/RsCollectionEditor.h similarity index 93% rename from retroshare-gui/src/gui/common/RsCollectionFile.h rename to retroshare-gui/src/gui/common/RsCollectionEditor.h index d2a86eba9..62c33bfd5 100644 --- a/retroshare-gui/src/gui/common/RsCollectionFile.h +++ b/retroshare-gui/src/gui/common/RsCollectionEditor.h @@ -56,16 +56,16 @@ public: }; Q_DECLARE_METATYPE(ColFileInfo) -class RsCollectionFile : public QObject +class RsCollectionEditor : public QObject { Q_OBJECT public: - RsCollectionFile(QObject *parent = 0) ; + RsCollectionEditor(QObject *parent = 0) ; // create from list of files and directories - RsCollectionFile(const std::vector& file_entries, QObject *parent = 0) ; - virtual ~RsCollectionFile() ; + RsCollectionEditor(const std::vector& file_entries, QObject *parent = 0) ; + virtual ~RsCollectionEditor() ; static const QString ExtensionString ; diff --git a/retroshare-gui/src/gui/common/RsUrlHandler.cpp b/retroshare-gui/src/gui/common/RsUrlHandler.cpp index e2c3cd092..2e16b23c4 100644 --- a/retroshare-gui/src/gui/common/RsUrlHandler.cpp +++ b/retroshare-gui/src/gui/common/RsUrlHandler.cpp @@ -22,14 +22,14 @@ #include #include #include -#include "RsCollectionFile.h" +#include "RsCollectionEditor.h" #include "RsUrlHandler.h" bool RsUrlHandler::openUrl(const QUrl& url) { - if(url.scheme() == QString("file") && url.toLocalFile().endsWith("."+RsCollectionFile::ExtensionString)) + if(url.scheme() == QString("file") && url.toLocalFile().endsWith("."+RsCollectionEditor::ExtensionString)) { - RsCollectionFile collection ; + RsCollectionEditor collection ; if(collection.load(url.toLocalFile())) { collection.downloadFiles() ; diff --git a/retroshare-gui/src/retroshare-gui.pro b/retroshare-gui/src/retroshare-gui.pro index b7bc361ce..b762dc4ed 100644 --- a/retroshare-gui/src/retroshare-gui.pro +++ b/retroshare-gui/src/retroshare-gui.pro @@ -476,7 +476,6 @@ HEADERS += rshare.h \ gui/common/ElidedLabel.h \ gui/common/vmessagebox.h \ gui/common/RsUrlHandler.h \ - gui/common/RsCollectionFile.h \ gui/common/RsCollectionDialog.h \ gui/common/rwindow.h \ gui/common/html.h \ @@ -565,7 +564,8 @@ HEADERS += rshare.h \ gui/GetStartedDialog.h \ gui/statistics/BWGraph.h \ util/RsSyntaxHighlighter.h \ - util/imageutil.h + util/imageutil.h \ + gui/common/RsCollectionEditor.h # gui/ForumsDialog.h \ # gui/forums/ForumDetails.h \ @@ -791,7 +791,6 @@ SOURCES += main.cpp \ gui/common/RSGraphWidget.cpp \ gui/common/ElidedLabel.cpp \ gui/common/vmessagebox.cpp \ - gui/common/RsCollectionFile.cpp \ gui/common/RsCollectionDialog.cpp \ gui/common/RsUrlHandler.cpp \ gui/common/rwindow.cpp \ @@ -925,7 +924,8 @@ SOURCES += main.cpp \ gui/statistics/RttStatistics.cpp \ gui/statistics/BWGraph.cpp \ util/RsSyntaxHighlighter.cpp \ - util/imageutil.cpp + util/imageutil.cpp \ + gui/common/RsCollectionEditor.cpp # gui/ForumsDialog.cpp \ # gui/forums/ForumDetails.cpp \ From f98edd400e9c3092bcb04f785c2683cc5da4488b Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 18 Oct 2017 00:04:04 +0200 Subject: [PATCH 03/19] added FileTree class to implement a compact representation of file hierarchies --- .../src/file_sharing/dir_hierarchy.cc | 18 +- libretroshare/src/file_sharing/file_tree.cc | 244 ++++++++++++++++++ libretroshare/src/file_sharing/file_tree.h | 25 ++ libretroshare/src/file_sharing/filelist_io.cc | 10 + libretroshare/src/file_sharing/filelist_io.h | 16 +- libretroshare/src/libretroshare.pro | 2 + libretroshare/src/retroshare/rsfiles.h | 30 +++ 7 files changed, 328 insertions(+), 17 deletions(-) create mode 100644 libretroshare/src/file_sharing/file_tree.cc create mode 100644 libretroshare/src/file_sharing/file_tree.h diff --git a/libretroshare/src/file_sharing/dir_hierarchy.cc b/libretroshare/src/file_sharing/dir_hierarchy.cc index bc8faf0e9..9ec6d2088 100644 --- a/libretroshare/src/file_sharing/dir_hierarchy.cc +++ b/libretroshare/src/file_sharing/dir_hierarchy.cc @@ -35,6 +35,8 @@ //#define DEBUG_DIRECTORY_STORAGE 1 +typedef FileListIO::read_error read_error; + /******************************************************************************************************************/ /* Internal File Hierarchy Storage */ /******************************************************************************************************************/ @@ -1041,22 +1043,6 @@ bool InternalFileHierarchyStorage::save(const std::string& fname) } } -class read_error -{ -public: - read_error(unsigned char *sec,uint32_t size,uint32_t offset,uint8_t expected_tag) - { - std::ostringstream s ; - s << "At offset " << offset << "/" << size << ": expected section tag " << std::hex << (int)expected_tag << std::dec << " but got " << RsUtil::BinToHex(&sec[offset],std::min((int)size-(int)offset, 15)) << "..." << std::endl; - err_string = s.str(); - } - read_error(const std::string& s) : err_string(s) {} - - const std::string& what() const { return err_string ; } -private: - std::string err_string ; -}; - bool InternalFileHierarchyStorage::load(const std::string& fname) { unsigned char *buffer = NULL ; diff --git a/libretroshare/src/file_sharing/file_tree.cc b/libretroshare/src/file_sharing/file_tree.cc new file mode 100644 index 000000000..59987553c --- /dev/null +++ b/libretroshare/src/file_sharing/file_tree.cc @@ -0,0 +1,244 @@ +#include +#include + +#include "file_sharing_defaults.h" +#include "filelist_io.h" +#include "file_tree.h" + +std::string FileTreeImpl::toRadix64() const +{ + unsigned char *buff = NULL ; + uint32_t size = 0 ; + + serialise(buff,size) ; + + std::string res ; + + Radix64::encode(buff,size,res) ; + + free(buff) ; + return res ; +} + +FileTree *FileTree::create(const std::string& radix64_string) +{ + FileTreeImpl *ft = new FileTreeImpl ; + + std::vector mem = Radix64::decode(radix64_string); + ft->deserialise(mem.data(),mem.size()) ; + + return ft ; +} + +static void recurs_buildFileTree(FileTreeImpl& ft,uint32_t index,void *ref) +{ +} + +FileTree *FileTree::create(void *ref) +{ + FileTreeImpl *ft = new FileTreeImpl ; + + recurs_buildFileTree(*ft,0,ref) ; + + return ft ; +} + +typedef FileListIO::read_error read_error ; + +bool FileTreeImpl::deserialise(unsigned char *buffer,uint32_t buffer_size) +{ + uint32_t buffer_offset = 0 ; + + mTotalFiles = 0; + mTotalSize = 0; + + try + { + // Read some header + + uint32_t version,n_dirs,n_files ; + + if(!FileListIO::readField(buffer,buffer_size,buffer_offset,FILE_LIST_IO_TAG_LOCAL_DIRECTORY_VERSION,version)) throw read_error(buffer,buffer_size,buffer_offset,FILE_LIST_IO_TAG_LOCAL_DIRECTORY_VERSION) ; + if(version != (uint32_t) FILE_LIST_IO_LOCAL_DIRECTORY_TREE_VERSION_0001) throw std::runtime_error("Wrong version number") ; + + if(!FileListIO::readField(buffer,buffer_size,buffer_offset,FILE_LIST_IO_TAG_RAW_NUMBER,n_files)) throw read_error(buffer,buffer_size,buffer_offset,FILE_LIST_IO_TAG_RAW_NUMBER) ; + if(!FileListIO::readField(buffer,buffer_size,buffer_offset,FILE_LIST_IO_TAG_RAW_NUMBER,n_dirs)) throw read_error(buffer,buffer_size,buffer_offset,FILE_LIST_IO_TAG_RAW_NUMBER) ; + + // Write all file/dir entries + + mFiles.resize(n_files) ; + mDirs.resize(n_dirs) ; + + unsigned char *node_section_data = NULL ; + uint32_t node_section_size = 0 ; + + for(uint32_t i=0;i= mDirs.size()) + { + std::cerr << "(EE) inconsistent FileTree structure" << std::endl; + return; + } + std::cerr << indent << mDirs[index].name << std::endl; + + for(uint32_t i=0;i& subdirs,std::vector& subfiles) const ; + virtual void print() const ; + + bool serialise(unsigned char *& data,uint32_t& data_size) const ; + bool deserialise(unsigned char* data, uint32_t data_size) ; + +protected: + void recurs_print(uint32_t index,const std::string& indent) const; + + struct DirData { + std::string name; + std::vector subdirs ; + std::vector subfiles ; + }; + std::vector mFiles ; + std::vector mDirs ; +}; diff --git a/libretroshare/src/file_sharing/filelist_io.cc b/libretroshare/src/file_sharing/filelist_io.cc index 618d6c6bb..15d4d1b53 100644 --- a/libretroshare/src/file_sharing/filelist_io.cc +++ b/libretroshare/src/file_sharing/filelist_io.cc @@ -22,12 +22,22 @@ * Please report all bugs and problems to "retroshare.project@gmail.com". * */ + +#include #include "retroshare/rsids.h" #include "pqi/authssl.h" #include "util/rsdir.h" +#include "util/rsprint.h" #include "serialiser/rsbaseserial.h" #include "filelist_io.h" +FileListIO::read_error::read_error(unsigned char *sec,uint32_t size,uint32_t offset,uint8_t expected_tag) +{ + std::ostringstream s ; + s << "At offset " << offset << "/" << size << ": expected section tag " << std::hex << (int)expected_tag << std::dec << " but got " << RsUtil::BinToHex(&sec[offset],std::min((int)size-(int)offset, 15)) << "..." << std::endl; + err_string = s.str(); +} + template<> bool FileListIO::serialise(unsigned char *buff,uint32_t size,uint32_t& offset,const uint32_t & val) { return setRawUInt32(buff,size,&offset,val) ; } template<> bool FileListIO::serialise(unsigned char *buff,uint32_t size,uint32_t& offset,const uint64_t & val) { return setRawUInt64(buff,size,&offset,val) ; } template<> bool FileListIO::serialise(unsigned char *buff,uint32_t size,uint32_t& offset,const std::string & val) { return setRawString(buff,size,&offset,val) ; } diff --git a/libretroshare/src/file_sharing/filelist_io.h b/libretroshare/src/file_sharing/filelist_io.h index 0fcdb00fb..8eccd6b27 100644 --- a/libretroshare/src/file_sharing/filelist_io.h +++ b/libretroshare/src/file_sharing/filelist_io.h @@ -36,6 +36,7 @@ // WARNING: the encoding is system-dependent, so this should *not* be used to exchange data between computers. static const uint32_t FILE_LIST_IO_LOCAL_DIRECTORY_STORAGE_VERSION_0001 = 0x00000001 ; +static const uint32_t FILE_LIST_IO_LOCAL_DIRECTORY_TREE_VERSION_0001 = 0x00010001 ; static const uint8_t FILE_LIST_IO_TAG_UNKNOWN = 0x00 ; static const uint8_t FILE_LIST_IO_TAG_LOCAL_DIRECTORY_VERSION = 0x01 ; @@ -65,6 +66,7 @@ static const uint8_t FILE_LIST_IO_TAG_RAW_NUMBER = 0x62 ; static const uint32_t SECTION_HEADER_MAX_SIZE = 6 ; // section tag (1 byte) + size (max = 5 bytes) + class FileListIO { public: @@ -93,7 +95,19 @@ public: return deserialise(buff,buff_size,offset,val); } - static bool writeField( unsigned char*&buff,uint32_t& buff_size,uint32_t& offset,uint8_t section_tag,const unsigned char * val,uint32_t size) ; + class read_error + { + public: + read_error(unsigned char *sec,uint32_t size,uint32_t offset,uint8_t expected_tag); + read_error(const std::string& s) : err_string(s) {} + + const std::string& what() const { return err_string ; } + private: + std::string err_string ; + }; + + + static bool writeField( unsigned char*&buff,uint32_t& buff_size,uint32_t& offset,uint8_t section_tag,const unsigned char * val,uint32_t size) ; static bool readField (const unsigned char *buff,uint32_t buff_size,uint32_t& offset,uint8_t check_section_tag, unsigned char *& val,uint32_t& size) ; template static bool serialise(unsigned char *buff,uint32_t size,uint32_t& offset,const T& val) ; diff --git a/libretroshare/src/libretroshare.pro b/libretroshare/src/libretroshare.pro index d96e7dc7f..0cb982ee6 100644 --- a/libretroshare/src/libretroshare.pro +++ b/libretroshare/src/libretroshare.pro @@ -47,6 +47,7 @@ file_lists { file_sharing/directory_updater.h \ file_sharing/rsfilelistitems.h \ file_sharing/dir_hierarchy.h \ + file_sharing/file_tree.h \ file_sharing/file_sharing_defaults.h SOURCES *= file_sharing/p3filelists.cc \ @@ -55,6 +56,7 @@ file_lists { file_sharing/directory_storage.cc \ file_sharing/directory_updater.cc \ file_sharing/dir_hierarchy.cc \ + file_sharing/file_tree.cc \ file_sharing/rsfilelistitems.cc } diff --git a/libretroshare/src/retroshare/rsfiles.h b/libretroshare/src/retroshare/rsfiles.h index 313ca26eb..22a7dd8bf 100644 --- a/libretroshare/src/retroshare/rsfiles.h +++ b/libretroshare/src/retroshare/rsfiles.h @@ -134,6 +134,36 @@ struct SharedDirStats uint64_t total_shared_size ; }; +// This class represents a tree of directories and files, only with their names size and hash. It is used to create collection links in the GUI +// and to transmit directory information between services. This class is independent from the existing FileHierarchy classes used in storage because +// we need a very copact serialization and storage size since we create links with it. Besides, we cannot afford to risk the leak of other local information +// by using the orignal classes. + +class FileTree +{ +public: + virtual ~FileTree() {} + + static FileTree *create(void *ref) ; + static FileTree *create(const std::string& radix64_string) ; + + virtual std::string toRadix64() const =0 ; + + // These methods allow the user to browse the hierarchy + + struct FileData { + std::string name ; + uint64_t size ; + RsFileHash hash ; + }; + + virtual uint32_t root() const { return 0;} + virtual bool getDirectoryContent(uint32_t index,std::vector& subdirs,std::vector& subfiles) const = 0; + + uint32_t mTotalFiles ; + uint64_t mTotalSize ; +}; + class RsFiles { public: From e1d501428837d8a417dbb25b7c8527bddc9be5a1 Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 18 Oct 2017 22:32:15 +0200 Subject: [PATCH 04/19] added copy links from file hierarchy --- libretroshare/src/file_sharing/file_tree.cc | 60 ++++++++++++++++--- libretroshare/src/file_sharing/file_tree.h | 4 ++ libretroshare/src/retroshare/rsfiles.h | 4 +- .../gui/FileTransfer/SharedFilesDialog.cpp | 16 ++++- 4 files changed, 74 insertions(+), 10 deletions(-) diff --git a/libretroshare/src/file_sharing/file_tree.cc b/libretroshare/src/file_sharing/file_tree.cc index 59987553c..75736ddc8 100644 --- a/libretroshare/src/file_sharing/file_tree.cc +++ b/libretroshare/src/file_sharing/file_tree.cc @@ -30,15 +30,63 @@ FileTree *FileTree::create(const std::string& radix64_string) return ft ; } -static void recurs_buildFileTree(FileTreeImpl& ft,uint32_t index,void *ref) +void FileTreeImpl::recurs_buildFileTree(FileTreeImpl& ft,uint32_t index,const DirDetails& dd,bool remote) { + if(ft.mDirs.size() <= index) + ft.mDirs.resize(index+1) ; + + ft.mDirs[index].name = dd.name ; + ft.mDirs[index].subfiles.clear(); + ft.mDirs[index].subdirs.clear(); + + DirDetails dd2 ; + + FileSearchFlags flags = remote?RS_FILE_HINTS_REMOTE:RS_FILE_HINTS_LOCAL ; + + for(uint32_t i=0;iRequestDirDetails(dd.children[i].ref,dd2,flags)) + { + if(dd.children[i].type == DIR_TYPE_FILE) + { + FileTree::FileData f ; + f.name = dd2.name ; + f.size = dd2.count ; + f.hash = dd2.hash ; + + ft.mDirs[index].subfiles.push_back(ft.mFiles.size()) ; + ft.mFiles.push_back(f) ; + } + else if(dd.children[i].type == DIR_TYPE_DIR) + { + ft.mDirs[index].subdirs.push_back(ft.mDirs.size()); + recurs_buildFileTree(ft,ft.mDirs.size(),dd2,remote) ; + } + else + std::cerr << "(EE) Unsupported DirDetails type." << std::endl; + } + else + std::cerr << "(EE) Cannot request dir details for pointer " << dd.children[i].ref << std::endl; } -FileTree *FileTree::create(void *ref) +bool FileTreeImpl::getDirectoryContent(uint32_t index,std::vector& subdirs,std::vector& subfiles) const +{ + if(index >= mDirs.size()) + return false ; + + subdirs = mDirs[index].subdirs ; + + subfiles.clear() ; + for(uint32_t i=0;i subdirs ; @@ -22,4 +24,6 @@ protected: }; std::vector mFiles ; std::vector mDirs ; + + friend class FileTree ; }; diff --git a/libretroshare/src/retroshare/rsfiles.h b/libretroshare/src/retroshare/rsfiles.h index 22a7dd8bf..422b1e9fd 100644 --- a/libretroshare/src/retroshare/rsfiles.h +++ b/libretroshare/src/retroshare/rsfiles.h @@ -144,7 +144,7 @@ class FileTree public: virtual ~FileTree() {} - static FileTree *create(void *ref) ; + static FileTree *create(const DirDetails& dd, bool remote) ; static FileTree *create(const std::string& radix64_string) ; virtual std::string toRadix64() const =0 ; @@ -160,6 +160,8 @@ public: virtual uint32_t root() const { return 0;} virtual bool getDirectoryContent(uint32_t index,std::vector& subdirs,std::vector& subfiles) const = 0; + virtual void print() const=0; + uint32_t mTotalFiles ; uint64_t mTotalSize ; }; diff --git a/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp b/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp index 9279642c3..a43e3cc5f 100644 --- a/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp +++ b/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp @@ -511,7 +511,8 @@ void RemoteSharedFilesDialog::spawnCustomPopupMenu( QPoint point ) connect( downloadAct , SIGNAL( triggered() ), this, SLOT( downloadRemoteSelected() ) ) ; contextMnu.addAction( downloadAct) ; - if ( type == DIR_TYPE_FILE ) { + //if ( type == DIR_TYPE_FILE ) + { contextMnu.addSeparator() ;//------------------------------------ contextMnu.addAction( copylinkAct) ; contextMnu.addAction( sendlinkAct) ; @@ -572,6 +573,18 @@ void SharedFilesDialog::copyLink (const QModelIndexList& lst, bool remote) if (details.type == DIR_TYPE_DIR) { + FileTree *ft = FileTree::create(details,remote) ; + + std::cerr << "Created collection file tree:" << std::endl; + ft->print(); + + RetroShareLink link = RetroShareLink::createCollection(QString::fromUtf8(details.name.c_str()), details.count,QString::fromStdString(ft->toRadix64())) ; + + if(link.valid()) + urls.push_back(link) ; + + delete ft ; +#ifdef TO_REMOVE for(uint32_t j=0;j Date: Wed, 18 Oct 2017 23:20:19 +0200 Subject: [PATCH 05/19] fixed up collection link display --- libretroshare/src/file_sharing/file_tree.cc | 6 +++++- libretroshare/src/file_sharing/file_tree.h | 6 +++++- .../gui/FileTransfer/SharedFilesDialog.cpp | 2 +- retroshare-gui/src/gui/RetroShareLink.cpp | 20 +++++++++++++------ retroshare-gui/src/gui/RetroShareLink.h | 3 ++- 5 files changed, 27 insertions(+), 10 deletions(-) diff --git a/libretroshare/src/file_sharing/file_tree.cc b/libretroshare/src/file_sharing/file_tree.cc index 75736ddc8..65eacbcef 100644 --- a/libretroshare/src/file_sharing/file_tree.cc +++ b/libretroshare/src/file_sharing/file_tree.cc @@ -55,6 +55,9 @@ void FileTreeImpl::recurs_buildFileTree(FileTreeImpl& ft,uint32_t index,const Di ft.mDirs[index].subfiles.push_back(ft.mFiles.size()) ; ft.mFiles.push_back(f) ; + + ft.mTotalFiles++ ; + ft.mTotalSize += f.size ; } else if(dd.children[i].type == DIR_TYPE_DIR) { @@ -264,7 +267,8 @@ bool FileTreeImpl::serialise(unsigned char *& buffer,uint32_t& buffer_size) cons void FileTreeImpl::print() const { - recurs_print(0,"") ; + std::cerr << "File hierarchy: name=" << mDirs[0].name << " size=" << mTotalSize << std::endl; + recurs_print(0," ") ; } void FileTreeImpl::recurs_print(uint32_t index,const std::string& indent) const diff --git a/libretroshare/src/file_sharing/file_tree.h b/libretroshare/src/file_sharing/file_tree.h index f4f951361..942414e67 100644 --- a/libretroshare/src/file_sharing/file_tree.h +++ b/libretroshare/src/file_sharing/file_tree.h @@ -3,7 +3,11 @@ class FileTreeImpl: public FileTree { public: - FileTreeImpl() {} + FileTreeImpl() + { + mTotalFiles = 0 ; + mTotalSize = 0 ; + } virtual std::string toRadix64() const ; virtual bool getDirectoryContent(uint32_t index,std::vector& subdirs,std::vector& subfiles) const ; diff --git a/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp b/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp index a43e3cc5f..3a437c9cf 100644 --- a/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp +++ b/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp @@ -578,7 +578,7 @@ void SharedFilesDialog::copyLink (const QModelIndexList& lst, bool remote) std::cerr << "Created collection file tree:" << std::endl; ft->print(); - RetroShareLink link = RetroShareLink::createCollection(QString::fromUtf8(details.name.c_str()), details.count,QString::fromStdString(ft->toRadix64())) ; + RetroShareLink link = RetroShareLink::createCollection(QString::fromUtf8(details.name.c_str()),ft->mTotalSize,ft->mTotalFiles,QString::fromStdString(ft->toRadix64())) ; if(link.valid()) urls.push_back(link) ; diff --git a/retroshare-gui/src/gui/RetroShareLink.cpp b/retroshare-gui/src/gui/RetroShareLink.cpp index 27ec2c1a9..d141422f1 100644 --- a/retroshare-gui/src/gui/RetroShareLink.cpp +++ b/retroshare-gui/src/gui/RetroShareLink.cpp @@ -69,7 +69,7 @@ #define HOST_CERTIFICATE "certificate" #define HOST_PUBLIC_MSG "public_msg" #define HOST_IDENTITY "identity" -#define HOST_REGEXP "file|extra|person|forum|channel|posted|search|message|certificate|private_chat|public_msg|identity" +#define HOST_REGEXP "file|collection|extra|person|forum|channel|posted|search|message|certificate|private_chat|public_msg|identity" #define FILE_NAME "name" #define FILE_SIZE "size" @@ -79,6 +79,7 @@ #define COLLECTION_NAME "name" #define COLLECTION_SIZE "size" #define COLLECTION_DATA "radix" +#define COLLECTION_COUNT "files" #define PERSON_NAME "name" #define PERSON_HASH "hash" @@ -337,8 +338,9 @@ void RetroShareLink::fromUrl(const QUrl& url) bool ok; _type = TYPE_COLLECTION; _radix = decodedQueryItemValue(urlQuery, COLLECTION_DATA); + _name = decodedQueryItemValue(urlQuery, COLLECTION_NAME); _size = urlQuery.queryItemValue(COLLECTION_SIZE).toULongLong(&ok); - _name = urlQuery.queryItemValue(COLLECTION_NAME).toULongLong(&ok); + _count = urlQuery.queryItemValue(COLLECTION_COUNT).toULongLong(&ok); #ifdef DEBUG_RSLINK std::cerr << "Got a certificate link!!" << std::endl; @@ -418,12 +420,13 @@ RetroShareLink RetroShareLink::createFile(const QString& name, uint64_t size, co return link; } -RetroShareLink RetroShareLink::createCollection(const QString& name, const uint64_t size,const QString& radix_data) +RetroShareLink RetroShareLink::createCollection(const QString& name, uint64_t size, uint32_t count, const QString& radix_data) { RetroShareLink link; link.clear(); link._name = name; + link._count = count; link._size = size; link._radix = radix_data ; link._type = TYPE_COLLECTION; @@ -899,8 +902,10 @@ QString RetroShareLink::toString() const case TYPE_COLLECTION: url.setScheme(RSLINK_SCHEME); url.setHost(HOST_COLLECTION) ; - urlQuery.addQueryItem(CERTIFICATE_RADIX, encodeItem(_radix)); - urlQuery.addQueryItem(CERTIFICATE_NAME, encodeItem(_name)); + urlQuery.addQueryItem(COLLECTION_NAME, encodeItem(_name)); + urlQuery.addQueryItem(COLLECTION_SIZE, QString::number(_size)); + urlQuery.addQueryItem(COLLECTION_DATA, encodeItem(_radix)); + urlQuery.addQueryItem(COLLECTION_COUNT, QString::number(_count)); break; case TYPE_CERTIFICATE: @@ -925,11 +930,14 @@ QString RetroShareLink::niceName() const if (type() == TYPE_PERSON) return PeerDefs::rsid(name().toUtf8().constData(), RsPgpId(hash().toStdString())); + if(type() == TYPE_COLLECTION) + return QObject::tr("%1 (%2 files, %3)").arg(_name).arg(_count).arg(misc::friendlyUnit(_size)); + if(type() == TYPE_IDENTITY) return QObject::tr("Identity link (name=%1, ID=%2)").arg(_name).arg(_hash) ; if(type() == TYPE_COLLECTION) - return QObject::tr("Click to browse/download this file collection"); + return QObject::tr("File directory (Total %s) Click to browse/download this file collection").arg(misc::friendlyUnit(_size)); if(type() == TYPE_PUBLIC_MSG) { RsPeerDetails detail; diff --git a/retroshare-gui/src/gui/RetroShareLink.h b/retroshare-gui/src/gui/RetroShareLink.h index a2e54798d..2576b880c 100644 --- a/retroshare-gui/src/gui/RetroShareLink.h +++ b/retroshare-gui/src/gui/RetroShareLink.h @@ -81,7 +81,7 @@ class RetroShareLink static RetroShareLink createIdentity(const RsGxsId& gxs_id,const QString& name,const QString& radix_data) ; static RetroShareLink createExtraFile(const QString& name, uint64_t size, const QString& hash, const QString& ssl_id); static RetroShareLink createFile(const QString& name, uint64_t size, const QString& hash); - static RetroShareLink createCollection(const QString& name, const uint64_t size,const QString& radix_data); + static RetroShareLink createCollection(const QString& name, uint64_t size,uint32_t count,const QString& radix_data); static RetroShareLink createPublicMsgInvite(time_t time_stamp,const QString& pgp_id,const QString& hash) ; static RetroShareLink createPerson(const RsPgpId &id); static RetroShareLink createCertificate(const RsPeerId &ssl_id) ; @@ -169,6 +169,7 @@ class RetroShareLink QString _encrypted_chat_info ; // encrypted data string for the recipient of a chat invite time_t _time_stamp ; // time stamp at which the link will expire. QString _radix_group_data; + uint32_t _count ; unsigned int _subType; // for general use as sub type for _type (RSLINK_SUBTYPE_...) }; From 32be00614d8251249965f87f021243ce8d444f3a Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 19 Oct 2017 10:19:56 +0200 Subject: [PATCH 06/19] various improvements to collection links --- libretroshare/src/file_sharing/file_tree.cc | 3 +- libretroshare/src/file_sharing/file_tree.h | 2 +- libretroshare/src/retroshare/rsfiles.h | 2 +- .../gui/FileTransfer/SharedFilesDialog.cpp | 1 + retroshare-gui/src/gui/RetroShareLink.cpp | 8 ++-- .../src/gui/common/RsCollectionEditor.cpp | 45 ++++++++++++++++++- .../src/gui/common/RsCollectionEditor.h | 28 +++++++----- 7 files changed, 69 insertions(+), 20 deletions(-) diff --git a/libretroshare/src/file_sharing/file_tree.cc b/libretroshare/src/file_sharing/file_tree.cc index 65eacbcef..8a1f11fc5 100644 --- a/libretroshare/src/file_sharing/file_tree.cc +++ b/libretroshare/src/file_sharing/file_tree.cc @@ -71,11 +71,12 @@ void FileTreeImpl::recurs_buildFileTree(FileTreeImpl& ft,uint32_t index,const Di std::cerr << "(EE) Cannot request dir details for pointer " << dd.children[i].ref << std::endl; } -bool FileTreeImpl::getDirectoryContent(uint32_t index,std::vector& subdirs,std::vector& subfiles) const +bool FileTreeImpl::getDirectoryContent(uint32_t index,std::string& name,std::vector& subdirs,std::vector& subfiles) const { if(index >= mDirs.size()) return false ; + name = mDirs[index].name; subdirs = mDirs[index].subdirs ; subfiles.clear() ; diff --git a/libretroshare/src/file_sharing/file_tree.h b/libretroshare/src/file_sharing/file_tree.h index 942414e67..5f94bdf48 100644 --- a/libretroshare/src/file_sharing/file_tree.h +++ b/libretroshare/src/file_sharing/file_tree.h @@ -10,7 +10,7 @@ public: } virtual std::string toRadix64() const ; - virtual bool getDirectoryContent(uint32_t index,std::vector& subdirs,std::vector& subfiles) const ; + virtual bool getDirectoryContent(uint32_t index,std::string& name,std::vector& subdirs,std::vector& subfiles) const ; virtual void print() const ; bool serialise(unsigned char *& data,uint32_t& data_size) const ; diff --git a/libretroshare/src/retroshare/rsfiles.h b/libretroshare/src/retroshare/rsfiles.h index 422b1e9fd..64af23885 100644 --- a/libretroshare/src/retroshare/rsfiles.h +++ b/libretroshare/src/retroshare/rsfiles.h @@ -158,7 +158,7 @@ public: }; virtual uint32_t root() const { return 0;} - virtual bool getDirectoryContent(uint32_t index,std::vector& subdirs,std::vector& subfiles) const = 0; + virtual bool getDirectoryContent(uint32_t index,std::string& name,std::vector& subdirs,std::vector& subfiles) const = 0; virtual void print() const=0; diff --git a/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp b/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp index 3a437c9cf..0f0244818 100644 --- a/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp +++ b/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp @@ -1014,6 +1014,7 @@ void LocalSharedFilesDialog::spawnCustomPopupMenu( QPoint point ) switch (type) { case DIR_TYPE_DIR : contextMnu.addAction(openfolderAct) ; + contextMnu.addAction(copylinkAct) ; contextMnu.addSeparator() ;//------------------------------------ contextMnu.addMenu(&collectionMenu) ; break ; diff --git a/retroshare-gui/src/gui/RetroShareLink.cpp b/retroshare-gui/src/gui/RetroShareLink.cpp index d141422f1..5a417cc37 100644 --- a/retroshare-gui/src/gui/RetroShareLink.cpp +++ b/retroshare-gui/src/gui/RetroShareLink.cpp @@ -1393,10 +1393,12 @@ static void processList(const QStringList &list, const QString &textSingular, co case TYPE_COLLECTION: { - //FileHierarchy fh ; - //fh.initFromRadix(_radix); + FileTree *ft = FileTree::create(_radix.toStdString()) ; - QMessageBox::information(NULL,"Unimplemented code","File collection links not handled yet.") ; + RsCollectionEditor colled(*ft,NULL) ; + colled.exec(); + + delete ft; } break; diff --git a/retroshare-gui/src/gui/common/RsCollectionEditor.cpp b/retroshare-gui/src/gui/common/RsCollectionEditor.cpp index 7abfe3f92..ea76231bd 100644 --- a/retroshare-gui/src/gui/common/RsCollectionEditor.cpp +++ b/retroshare-gui/src/gui/common/RsCollectionEditor.cpp @@ -43,6 +43,15 @@ RsCollectionEditor::RsCollectionEditor(QObject *parent) { } +RsCollectionEditor::RsCollectionEditor(const FileTree& fr, QObject *parent) + : QObject(parent), _xml_doc("RsCollection") +{ + QDomElement root = _xml_doc.createElement("RsCollection"); + _xml_doc.appendChild(root); + + recursAddElements(_xml_doc,fr,0,root) ; +} + RsCollectionEditor::RsCollectionEditor(const std::vector& file_infos, QObject *parent) : QObject(parent), _xml_doc("RsCollection") { @@ -186,7 +195,7 @@ void RsCollectionEditor::recursAddElements(QDomDocument& doc,const ColFileInfo& f.setAttribute(QString("size"),QString::number(colFileInfo.size)) ; e.appendChild(f) ; -} + } else if (colFileInfo.type == DIR_TYPE_DIR) { QDomElement d = doc.createElement("Directory") ; @@ -194,7 +203,7 @@ void RsCollectionEditor::recursAddElements(QDomDocument& doc,const ColFileInfo& d.setAttribute(QString("name"),colFileInfo.name) ; for (std::vector::const_iterator it = colFileInfo.children.begin(); it != colFileInfo.children.end(); ++it) -{ + { recursAddElements(doc,(*it),d) ; } @@ -202,6 +211,34 @@ void RsCollectionEditor::recursAddElements(QDomDocument& doc,const ColFileInfo& } } +void RsCollectionEditor::recursAddElements(QDomDocument& doc,const FileTree& ft,uint32_t index,QDomElement& e) const +{ + std::vector subdirs ; + std::vector subfiles ; + std::string name; + + if(!ft.getDirectoryContent(index,name,subdirs,subfiles)) + return ; + + QDomElement d = doc.createElement("Directory") ; + d.setAttribute(QString::fromUtf8()("name"),QString::fromUtf8(name.c_str())) ; + e.appendChild(d) ; + + for (uint32_t i=0;i& file_entries, QObject *parent = 0) ; + RsCollectionEditor(const FileTree& fr, QObject *parent); virtual ~RsCollectionEditor() ; static const QString ExtensionString ; - // Loads file from disk. - bool load(QWidget *parent); + // Loads file from disk. + bool load(QWidget *parent); bool load(const QString& fileName, bool showError = true); - // Save to disk - bool save(QWidget *parent) const ; + // Loads from FileTree + bool load(const FileTree& f); + + // Save to disk + bool save(QWidget *parent) const ; bool save(const QString& fileName) const ; // Open new collection @@ -84,28 +88,28 @@ public: // Open existing collection bool openColl(const QString& fileName, bool readOnly = false, bool showError = true); - // Download the content. - void downloadFiles() const ; + // Download the content. + void downloadFiles() const ; - qulonglong size(); + qulonglong size(); static bool isCollectionFile(const QString& fileName); private slots: void saveColl(std::vector colFileInfos, const QString& fileName); - private: +private: - void recursAddElements(QDomDocument&,const DirDetails&,QDomElement&) const ; + void recursAddElements(QDomDocument&,const DirDetails&,QDomElement&) const ; void recursAddElements(QDomDocument&,const ColFileInfo&,QDomElement&) const; void recursCollectColFileInfos(const QDomElement&,std::vector& colFileInfos,const QString& current_dir,bool bad_chars_in_parent) const ; // check that the file is a valid rscollection file, and not a lol bomb or some shit like this static bool checkFile(const QString &fileName, bool showError); - QDomDocument _xml_doc ; + QDomDocument _xml_doc ; QString _fileName ; bool _saved; - friend class RsCollectionDialog ; + friend class RsCollectionDialog ; }; From 74d5069225d9658ffbe441743034307cf6aa6f91 Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 19 Oct 2017 22:14:04 +0200 Subject: [PATCH 07/19] renamed RsCollectionEditor into RsCollection. Added download of FileTree links --- .../src/gui/FileTransfer/SearchDialog.cpp | 20 ++--- .../gui/FileTransfer/SharedFilesDialog.cpp | 28 +++--- .../src/gui/FileTransfer/TransfersDialog.cpp | 86 +++++++++---------- retroshare-gui/src/gui/MainWindow.cpp | 8 +- retroshare-gui/src/gui/RemoteDirModel.cpp | 4 +- retroshare-gui/src/gui/RetroShareLink.cpp | 11 ++- retroshare-gui/src/gui/common/FilesDefs.cpp | 4 +- ...sCollectionEditor.cpp => RsCollection.cpp} | 73 ++++++++-------- .../{RsCollectionEditor.h => RsCollection.h} | 15 ++-- .../src/gui/common/RsCollectionDialog.cpp | 10 +-- .../src/gui/common/RsCollectionDialog.h | 2 +- .../src/gui/common/RsUrlHandler.cpp | 6 +- retroshare-gui/src/retroshare-gui.pro | 4 +- 13 files changed, 132 insertions(+), 139 deletions(-) rename retroshare-gui/src/gui/common/{RsCollectionEditor.cpp => RsCollection.cpp} (84%) rename retroshare-gui/src/gui/common/{RsCollectionEditor.h => RsCollection.h} (90%) diff --git a/retroshare-gui/src/gui/FileTransfer/SearchDialog.cpp b/retroshare-gui/src/gui/FileTransfer/SearchDialog.cpp index e55493a0c..facb8b60d 100644 --- a/retroshare-gui/src/gui/FileTransfer/SearchDialog.cpp +++ b/retroshare-gui/src/gui/FileTransfer/SearchDialog.cpp @@ -30,7 +30,7 @@ #include "gui/RetroShareLink.h" #include "retroshare-gui/RsAutoUpdatePage.h" #include "gui/msgs/MessageComposer.h" -#include "gui/common/RsCollectionEditor.h" +#include "gui/common/RsCollection.h" #include "gui/common/FilesDefs.h" #include "gui/common/RsUrlHandler.h" #include "gui/settings/rsharesettings.h" @@ -345,7 +345,7 @@ void SearchDialog::searchResultWidgetCustomPopupMenu( QPoint /*point*/ ) QList item =ui.searchResultWidget->selectedItems() ; if (item.at(0)->data(SR_DATA_COL, SR_ROLE_LOCAL).toBool()) { contextMnu.addAction(QIcon(IMAGE_OPENFOLDER), tr("Open Folder"), this, SLOT(openFolderSearch())) ; - if (item.at(0)->text(SR_NAME_COL).endsWith(RsCollectionEditor::ExtensionString)) { + if (item.at(0)->text(SR_NAME_COL).endsWith(RsCollection::ExtensionString)) { add_CollActions = true ; }//if (item.at(0)->text(SR_NAME_COL).endsWith(RsCollectionFile::ExtensionString)) }//if (item.at(0)->data(SR_DATA_COL, SR_ROLE_LOCAL).toBool()) @@ -448,7 +448,7 @@ void SearchDialog::collCreate() }//if (!item->text(SR_HASH_COL).isEmpty()) }//for (int i = 0; i < numdls; ++i) - RsCollectionEditor(dirVec).openNewColl(this); + RsCollection(dirVec).openNewColl(this); } void SearchDialog::collModif() @@ -476,8 +476,8 @@ void SearchDialog::collModif() QFileInfo qinfo; qinfo.setFile(QString::fromUtf8(path.c_str())); if (qinfo.exists()) { - if (qinfo.absoluteFilePath().endsWith(RsCollectionEditor::ExtensionString)) { - RsCollectionEditor collection; + if (qinfo.absoluteFilePath().endsWith(RsCollection::ExtensionString)) { + RsCollection collection; collection.openColl(qinfo.absoluteFilePath()); }//if (qinfo.absoluteFilePath().endsWith(RsCollectionFile::ExtensionString)) }//if (qinfo.exists()) @@ -508,8 +508,8 @@ void SearchDialog::collView() QFileInfo qinfo; qinfo.setFile(QString::fromUtf8(path.c_str())); if (qinfo.exists()) { - if (qinfo.absoluteFilePath().endsWith(RsCollectionEditor::ExtensionString)) { - RsCollectionEditor collection; + if (qinfo.absoluteFilePath().endsWith(RsCollection::ExtensionString)) { + RsCollection collection; collection.openColl(qinfo.absoluteFilePath(), true); }//if (qinfo.absoluteFilePath().endsWith(RsCollectionFile::ExtensionString)) }//if (qinfo.exists()) @@ -540,8 +540,8 @@ void SearchDialog::collOpen() QFileInfo qinfo; qinfo.setFile(QString::fromUtf8(path.c_str())); if (qinfo.exists()) { - if (qinfo.absoluteFilePath().endsWith(RsCollectionEditor::ExtensionString)) { - RsCollectionEditor collection; + if (qinfo.absoluteFilePath().endsWith(RsCollection::ExtensionString)) { + RsCollection collection; if (collection.load(qinfo.absoluteFilePath())) { collection.downloadFiles(); return; @@ -552,7 +552,7 @@ void SearchDialog::collOpen() } } - RsCollectionEditor collection; + RsCollection collection; if (collection.load(this)) { collection.downloadFiles(); }//if (collection.load(this)) diff --git a/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp b/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp index 0f0244818..f071c3a66 100644 --- a/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp +++ b/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp @@ -37,7 +37,7 @@ #include "gui/RetroShareLink.h" #include "gui/ShareManager.h" #include "gui/common/PeerDefs.h" -#include "gui/common/RsCollectionEditor.h" +#include "gui/common/RsCollection.h" #include "gui/msgs/MessageComposer.h" #include "gui/settings/AddFileAssociationDialog.h" #include "gui/settings/rsharesettings.h" @@ -695,11 +695,11 @@ void SharedFilesDialog::collModif() QFileInfo qinfo; qinfo.setFile(QString::fromUtf8(path.c_str())); if (qinfo.exists()) { - if (qinfo.absoluteFilePath().endsWith(RsCollectionEditor::ExtensionString)) { - RsCollectionEditor collection; + if (qinfo.absoluteFilePath().endsWith(RsCollection::ExtensionString)) { + RsCollection collection; collection.openColl(qinfo.absoluteFilePath()); - }//if (qinfo.absoluteFilePath().endsWith(RsCollectionFile::ExtensionString)) - }//if (qinfo.exists()) + } + } } void SharedFilesDialog::collView() @@ -725,11 +725,11 @@ void SharedFilesDialog::collView() QFileInfo qinfo; qinfo.setFile(QString::fromUtf8(path.c_str())); if (qinfo.exists()) { - if (qinfo.absoluteFilePath().endsWith(RsCollectionEditor::ExtensionString)) { - RsCollectionEditor collection; + if (qinfo.absoluteFilePath().endsWith(RsCollection::ExtensionString)) { + RsCollection collection; collection.openColl(qinfo.absoluteFilePath(), true); - }//if (qinfo.absoluteFilePath().endsWith(RsCollectionFile::ExtensionString)) - }//if (qinfo.exists()) + } + } } void SharedFilesDialog::collOpen() @@ -755,8 +755,8 @@ void SharedFilesDialog::collOpen() QFileInfo qinfo; qinfo.setFile(QString::fromUtf8(path.c_str())); if (qinfo.exists()) { - if (qinfo.absoluteFilePath().endsWith(RsCollectionEditor::ExtensionString)) { - RsCollectionEditor collection; + if (qinfo.absoluteFilePath().endsWith(RsCollection::ExtensionString)) { + RsCollection collection; if (collection.load(qinfo.absoluteFilePath())) { collection.downloadFiles(); return; @@ -766,10 +766,10 @@ void SharedFilesDialog::collOpen() } } - RsCollectionEditor collection; + RsCollection collection; if (collection.load(this)) { collection.downloadFiles(); - }//if (collection.load(this)) + } } void LocalSharedFilesDialog::playselectedfiles() @@ -998,7 +998,7 @@ void LocalSharedFilesDialog::spawnCustomPopupMenu( QPoint point ) QMenu contextMnu(this) ; - bool bIsRsColl = currentFile.endsWith(RsCollectionEditor::ExtensionString); + bool bIsRsColl = currentFile.endsWith(RsCollection::ExtensionString); collCreateAct->setEnabled(true); collModifAct->setEnabled(bIsRsColl); collViewAct->setEnabled(bIsRsColl); diff --git a/retroshare-gui/src/gui/FileTransfer/TransfersDialog.cpp b/retroshare-gui/src/gui/FileTransfer/TransfersDialog.cpp index 98bc7f3cb..b6c3376a5 100644 --- a/retroshare-gui/src/gui/FileTransfer/TransfersDialog.cpp +++ b/retroshare-gui/src/gui/FileTransfer/TransfersDialog.cpp @@ -31,7 +31,7 @@ #include #include -#include +#include #include #include @@ -50,7 +50,7 @@ #include "xprogressbar.h" #include #include "util/misc.h" -#include +#include #include "TransferUserNotify.h" #include "util/QtVersion.h" #include "util/RsFile.h" @@ -679,20 +679,20 @@ void TransfersDialog::downloadListCustomPopupMenu( QPoint /*point*/ ) */ if (info.downloadStatus == FT_STATE_WAITING) { atLeastOne_Waiting = true ; - }//if (info.downloadStatus == FT_STATE_WAITING) + } if (info.downloadStatus == FT_STATE_DOWNLOADING) { atLeastOne_Downloading=true ; - }//if (info.downloadStatus == FT_STATE_DOWNLOADING) + } if (info.downloadStatus == FT_STATE_COMPLETE) { atLeastOne_Complete = true ; add_OpenFileOption = single ; - }//if (info.downloadStatus == FT_STATE_COMPLETE) + } if (info.downloadStatus == FT_STATE_QUEUED) { atLeastOne_Queued = true ; - }//if(info.downloadStatus == FT_STATE_QUEUED) + } if (info.downloadStatus == FT_STATE_PAUSED) { atLeastOne_Paused = true ; - }//if (info.downloadStatus == FT_STATE_PAUSED) + } size_t pos = info.fname.find_last_of('.') ; if (pos != std::string::npos) { @@ -700,23 +700,23 @@ void TransfersDialog::downloadListCustomPopupMenu( QPoint /*point*/ ) if (misc::isPreviewable(info.fname.substr(pos + 1).c_str())) { add_PreviewOption = (info.downloadStatus != FT_STATE_COMPLETE) ; add_PlayOption = !add_PreviewOption ; - }// if (misc::isPreviewable(info.fname.substr(pos + 1).c_str())) + } // Check if the file is a collection - if (RsCollectionEditor::ExtensionString == info.fname.substr(pos + 1).c_str()) { + if (RsCollection::ExtensionString == info.fname.substr(pos + 1).c_str()) { add_CollActions = (info.downloadStatus == FT_STATE_COMPLETE); - }//if (RsCollectionFile::ExtensionString == info - }// if(pos != std::string::npos) + } + } - }// if FileDetails - }// for items iterate - }// if (!items.empty()) + } + } + } if (atLeastOne_Waiting || atLeastOne_Downloading || atLeastOne_Queued || atLeastOne_Paused) { contextMnu.addMenu( &prioritySpeedMenu) ; } if (atLeastOne_Queued) { contextMnu.addMenu( &priorityQueueMenu) ; - }//if (atLeastOne_Queued) + } if ( (!items.empty()) && (atLeastOne_Downloading || atLeastOne_Queued || atLeastOne_Waiting || atLeastOne_Paused)) { @@ -724,7 +724,7 @@ void TransfersDialog::downloadListCustomPopupMenu( QPoint /*point*/ ) if (single) { contextMnu.addAction( renameFileAct) ; - }//if (single) + } QMenu *directoryMenu = contextMnu.addMenu(QIcon(IMAGE_OPENFOLDER), tr("Set destination directory")) ; directoryMenu->addAction(specifyDestinationDirectoryAct) ; @@ -745,27 +745,27 @@ void TransfersDialog::downloadListCustomPopupMenu( QPoint /*point*/ ) act->setData(QString::fromUtf8( (*it).filename.c_str() ) ) ; connect(act, SIGNAL(triggered()), this, SLOT(setDestinationDirectory())) ; directoryMenu->addAction( act) ; - }//for (std::list::const_iterator it - }//if ( (!items.empty()) && + } + } if (atLeastOne_Paused) { contextMnu.addAction(resumeAct) ; - }//if (atLeastOne_Paused) + } if (atLeastOne_Downloading || atLeastOne_Queued || atLeastOne_Waiting) { contextMnu.addAction(pauseAct) ; - }//if (atLeastOne_Downloading || atLeastOne_Queued || atLeastOne_Waiting) + } if (!atLeastOne_Complete && !items.empty()) { contextMnu.addAction(forceCheckAct) ; contextMnu.addAction(cancelAct) ; - }//if (!atLeastOne_Complete && !items.empty()) + } if (add_PlayOption) { contextMnu.addAction(playAct) ; - }//if (add_PlayOption) + } if (atLeastOne_Paused || atLeastOne_Downloading || atLeastOne_Complete || add_PlayOption) { contextMnu.addSeparator() ;//------------------------------------------------ - }//if (atLeastOne_Paused || + } if (single) { if (add_OpenFileOption) contextMnu.addAction( openFileAct) ; @@ -773,20 +773,20 @@ void TransfersDialog::downloadListCustomPopupMenu( QPoint /*point*/ ) contextMnu.addAction( openFolderAct) ; contextMnu.addAction( detailsFileAct) ; contextMnu.addSeparator() ;//-------------------------------------------- - }//if (single) + } contextMnu.addAction( clearCompletedAct) ; contextMnu.addSeparator() ;//------------------------------------------------ if (add_CopyLink) { contextMnu.addAction( copyLinkAct) ; - }//if (add_CopyLink) + } if (add_PasteLink) { contextMnu.addAction( pasteLinkAct) ; - }//if (add_PasteLink) + } if (add_CopyLink || add_PasteLink) { contextMnu.addSeparator() ;//-------------------------------------------- - }//if (add_CopyLink || add_PasteLink) + } if (DLLFilterModel->rowCount()>0 ) { contextMnu.addAction( expandAllDLAct ) ; @@ -2153,9 +2153,9 @@ void TransfersDialog::collCreate() details.type = DIR_TYPE_FILE; dirVec.push_back(details); - }//for (it = items.begin(); + } - RsCollectionEditor(dirVec).openNewColl(this); + RsCollection(dirVec).openNewColl(this); } void TransfersDialog::collModif() @@ -2180,12 +2180,12 @@ void TransfersDialog::collModif() QFileInfo qinfo; qinfo.setFile(QString::fromUtf8(path.c_str())); if (qinfo.exists()) { - if (qinfo.absoluteFilePath().endsWith(RsCollectionEditor::ExtensionString)) { - RsCollectionEditor collection; + if (qinfo.absoluteFilePath().endsWith(RsCollection::ExtensionString)) { + RsCollection collection; collection.openColl(qinfo.absoluteFilePath()); - }//if (qinfo.absoluteFilePath().endsWith(RsCollectionFile::ExtensionString)) - }//if (qinfo.exists()) - }//if (info.downloadStatus == FT_STATE_COMPLETE) + } + } + } } void TransfersDialog::collView() @@ -2210,12 +2210,12 @@ void TransfersDialog::collView() QFileInfo qinfo; qinfo.setFile(QString::fromUtf8(path.c_str())); if (qinfo.exists()) { - if (qinfo.absoluteFilePath().endsWith(RsCollectionEditor::ExtensionString)) { - RsCollectionEditor collection; + if (qinfo.absoluteFilePath().endsWith(RsCollection::ExtensionString)) { + RsCollection collection; collection.openColl(qinfo.absoluteFilePath(), true); - }//if (qinfo.absoluteFilePath().endsWith(RsCollectionFile::ExtensionString)) - }//if (qinfo.exists()) - }//if (info.downloadStatus == FT_STATE_COMPLETE) + } + } + } } void TransfersDialog::collOpen() @@ -2240,8 +2240,8 @@ void TransfersDialog::collOpen() QFileInfo qinfo; qinfo.setFile(QString::fromUtf8(path.c_str())); if (qinfo.exists()) { - if (qinfo.absoluteFilePath().endsWith(RsCollectionEditor::ExtensionString)) { - RsCollectionEditor collection; + if (qinfo.absoluteFilePath().endsWith(RsCollection::ExtensionString)) { + RsCollection collection; if (collection.load(qinfo.absoluteFilePath())) { collection.downloadFiles(); return; @@ -2252,10 +2252,10 @@ void TransfersDialog::collOpen() } } - RsCollectionEditor collection; + RsCollection collection; if (collection.load(this)) { collection.downloadFiles(); - }//if (collection.load(this)) + } } void TransfersDialog::setShowDLSizeColumn(bool show) diff --git a/retroshare-gui/src/gui/MainWindow.cpp b/retroshare-gui/src/gui/MainWindow.cpp index d3bb3200f..ea57a93b6 100644 --- a/retroshare-gui/src/gui/MainWindow.cpp +++ b/retroshare-gui/src/gui/MainWindow.cpp @@ -103,7 +103,7 @@ #include "gui/statistics/StatisticsWindow.h" #include "gui/connect/ConnectFriendWizard.h" -#include "gui/common/RsCollectionEditor.h" +#include "gui/common/RsCollection.h" #include "settings/rsettingswin.h" #include "settings/rsharesettings.h" #include "settings/WebuiPage.h" @@ -1020,7 +1020,7 @@ void MainWindow::newRsCollection() { std::vector dirVec; - RsCollectionEditor(dirVec).openNewColl(this); + RsCollection(dirVec).openNewColl(this); } /** Shows Share Manager */ @@ -1448,8 +1448,8 @@ void MainWindow::openRsCollection(const QString &filename) { QFileInfo qinfo(filename); if (qinfo.exists()) { - if (qinfo.absoluteFilePath().endsWith(RsCollectionEditor::ExtensionString)) { - RsCollectionEditor collection; + if (qinfo.absoluteFilePath().endsWith(RsCollection::ExtensionString)) { + RsCollection collection; collection.openColl(qinfo.absoluteFilePath()); } } diff --git a/retroshare-gui/src/gui/RemoteDirModel.cpp b/retroshare-gui/src/gui/RemoteDirModel.cpp index 29f08b6a5..7ffbcf5bd 100644 --- a/retroshare-gui/src/gui/RemoteDirModel.cpp +++ b/retroshare-gui/src/gui/RemoteDirModel.cpp @@ -26,7 +26,7 @@ #include #include -#include +#include #include #include #include @@ -1065,7 +1065,7 @@ void RetroshareDirModel::createCollectionFile(QWidget *parent, const QModelIndex std::vector dirVec; getDirDetailsFromSelect(list, dirVec); - RsCollectionEditor(dirVec).openNewColl(parent); + RsCollection(dirVec).openNewColl(parent); } void RetroshareDirModel::downloadSelected(const QModelIndexList &list) diff --git a/retroshare-gui/src/gui/RetroShareLink.cpp b/retroshare-gui/src/gui/RetroShareLink.cpp index 5a417cc37..7a1e32aae 100644 --- a/retroshare-gui/src/gui/RetroShareLink.cpp +++ b/retroshare-gui/src/gui/RetroShareLink.cpp @@ -43,7 +43,7 @@ #include "msgs/MessageComposer.h" #include "util/misc.h" #include "common/PeerDefs.h" -#include "common/RsCollectionEditor.h" +#include "common/RsCollection.h" #include #include "gui/connect/ConnectFriendWizard.h" #include "gui/connect/ConfCertDialog.h" @@ -980,10 +980,10 @@ QString RetroShareLink::toHtmlSize() const { QString size = QString("(%1)").arg(misc::friendlyUnit(_size)); - if (type() == TYPE_FILE && RsCollectionEditor::isCollectionFile(name())) { + if (type() == TYPE_FILE && RsCollection::isCollectionFile(name())) { FileInfo finfo; if (rsFiles->FileDetails(RsFileHash(hash().toStdString()), RS_FILE_HINTS_EXTRA | RS_FILE_HINTS_LOCAL, finfo)) { - RsCollectionEditor collection; + RsCollection collection; if (collection.load(QString::fromUtf8(finfo.path.c_str()), false)) { size += QString(" [%1]").arg(misc::friendlyUnit(collection.size())); } @@ -1393,10 +1393,9 @@ static void processList(const QStringList &list, const QString &textSingular, co case TYPE_COLLECTION: { - FileTree *ft = FileTree::create(_radix.toStdString()) ; + FileTree *ft = FileTree::create(link.radix().toStdString()) ; - RsCollectionEditor colled(*ft,NULL) ; - colled.exec(); + RsCollection(*ft).downloadFiles() ; delete ft; } diff --git a/retroshare-gui/src/gui/common/FilesDefs.cpp b/retroshare-gui/src/gui/common/FilesDefs.cpp index 063c85e3b..b20660b20 100644 --- a/retroshare-gui/src/gui/common/FilesDefs.cpp +++ b/retroshare-gui/src/gui/common/FilesDefs.cpp @@ -23,7 +23,7 @@ #include #include "FilesDefs.h" -#include "RsCollectionEditor.h" +#include "RsCollection.h" static QString getInfoFromFilename(const QString& filename, bool anyForUnknown, bool image) { @@ -54,7 +54,7 @@ static QString getInfoFromFilename(const QString& filename, bool anyForUnknown, return image ? ":/images/FileTypeDocument.png" : QApplication::translate("FilesDefs", "Document"); } else if (ext == "pdf") { return image ? ":/images/mimetypes/pdf.png" : QApplication::translate("FilesDefs", "Document"); - } else if (ext == RsCollectionEditor::ExtensionString) { + } else if (ext == RsCollection::ExtensionString) { return image ? ":/images/mimetypes/rscollection-16.png" : QApplication::translate("FilesDefs", "RetroShare collection file"); } else if (ext == "sub" || ext == "srt") { return image ? ":/images/FileTypeAny.png" : QApplication::translate("FilesDefs", "Subtitles"); diff --git a/retroshare-gui/src/gui/common/RsCollectionEditor.cpp b/retroshare-gui/src/gui/common/RsCollection.cpp similarity index 84% rename from retroshare-gui/src/gui/common/RsCollectionEditor.cpp rename to retroshare-gui/src/gui/common/RsCollection.cpp index ea76231bd..a7ba9637a 100644 --- a/retroshare-gui/src/gui/common/RsCollectionEditor.cpp +++ b/retroshare-gui/src/gui/common/RsCollection.cpp @@ -24,7 +24,7 @@ #include #include -#include "RsCollectionEditor.h" +#include "RsCollection.h" #include "RsCollectionDialog.h" #include "util/misc.h" @@ -36,15 +36,15 @@ #include #include -const QString RsCollectionEditor::ExtensionString = QString("rscollection") ; +const QString RsCollection::ExtensionString = QString("rscollection") ; -RsCollectionEditor::RsCollectionEditor(QObject *parent) +RsCollection::RsCollection(QObject *parent) : QObject(parent), _xml_doc("RsCollection") { } -RsCollectionEditor::RsCollectionEditor(const FileTree& fr, QObject *parent) - : QObject(parent), _xml_doc("RsCollection") +RsCollection::RsCollection(const FileTree& fr) + : _xml_doc("RsCollection") { QDomElement root = _xml_doc.createElement("RsCollection"); _xml_doc.appendChild(root); @@ -52,7 +52,7 @@ RsCollectionEditor::RsCollectionEditor(const FileTree& fr, QObject *parent) recursAddElements(_xml_doc,fr,0,root) ; } -RsCollectionEditor::RsCollectionEditor(const std::vector& file_infos, QObject *parent) +RsCollection::RsCollection(const std::vector& file_infos, QObject *parent) : QObject(parent), _xml_doc("RsCollection") { QDomElement root = _xml_doc.createElement("RsCollection"); @@ -62,11 +62,11 @@ RsCollectionEditor::RsCollectionEditor(const std::vector& file_infos recursAddElements(_xml_doc,file_infos[i],root) ; } -RsCollectionEditor::~RsCollectionEditor() +RsCollection::~RsCollection() { } -void RsCollectionEditor::downloadFiles() const +void RsCollection::downloadFiles() const { // print out the element names of all elements that are direct children // of the outermost element. @@ -96,7 +96,7 @@ static QString purifyFileName(const QString& input,bool& bad) return output ; } -void RsCollectionEditor::recursCollectColFileInfos(const QDomElement& e,std::vector& colFileInfos,const QString& current_path, bool bad_chars_in_parent) const +void RsCollection::recursCollectColFileInfos(const QDomElement& e,std::vector& colFileInfos,const QString& current_path, bool bad_chars_in_parent) const { QDomNode n = e.firstChild() ; @@ -148,7 +148,7 @@ void RsCollectionEditor::recursCollectColFileInfos(const QDomElement& e,std::vec } -void RsCollectionEditor::recursAddElements(QDomDocument& doc,const DirDetails& details,QDomElement& e) const +void RsCollection::recursAddElements(QDomDocument& doc,const DirDetails& details,QDomElement& e) const { if (details.type == DIR_TYPE_FILE) { @@ -184,7 +184,7 @@ void RsCollectionEditor::recursAddElements(QDomDocument& doc,const DirDetails& d } } -void RsCollectionEditor::recursAddElements(QDomDocument& doc,const ColFileInfo& colFileInfo,QDomElement& e) const +void RsCollection::recursAddElements(QDomDocument& doc,const ColFileInfo& colFileInfo,QDomElement& e) const { if (colFileInfo.type == DIR_TYPE_FILE) { @@ -211,7 +211,7 @@ void RsCollectionEditor::recursAddElements(QDomDocument& doc,const ColFileInfo& } } -void RsCollectionEditor::recursAddElements(QDomDocument& doc,const FileTree& ft,uint32_t index,QDomElement& e) const +void RsCollection::recursAddElements(QDomDocument& doc,const FileTree& ft,uint32_t index,QDomElement& e) const { std::vector subdirs ; std::vector subfiles ; @@ -221,7 +221,7 @@ void RsCollectionEditor::recursAddElements(QDomDocument& doc,const FileTree& ft, return ; QDomElement d = doc.createElement("Directory") ; - d.setAttribute(QString::fromUtf8()("name"),QString::fromUtf8(name.c_str())) ; + d.setAttribute(QString("name"),QString::fromUtf8(name.c_str())) ; e.appendChild(d) ; for (uint32_t i=0;i colFileInfos ; @@ -474,11 +469,11 @@ bool RsCollectionEditor::openColl(const QString& fileName, bool readOnly /* = fa delete rcd; return _saved; - }//if (load(fileName, showError)) + } return false; } -qulonglong RsCollectionEditor::size() +qulonglong RsCollection::size() { QDomElement docElem = _xml_doc.documentElement(); @@ -494,14 +489,14 @@ qulonglong RsCollectionEditor::size() return size; } -bool RsCollectionEditor::isCollectionFile(const QString &fileName) +bool RsCollection::isCollectionFile(const QString &fileName) { QString ext = QFileInfo(fileName).suffix().toLower(); - return (ext == RsCollectionEditor::ExtensionString); + return (ext == RsCollection::ExtensionString); } -void RsCollectionEditor::saveColl(std::vector colFileInfos, const QString &fileName) +void RsCollection::saveColl(std::vector colFileInfos, const QString &fileName) { QDomElement root = _xml_doc.elementsByTagName("RsCollection").at(0).toElement(); diff --git a/retroshare-gui/src/gui/common/RsCollectionEditor.h b/retroshare-gui/src/gui/common/RsCollection.h similarity index 90% rename from retroshare-gui/src/gui/common/RsCollectionEditor.h rename to retroshare-gui/src/gui/common/RsCollection.h index 0f291401e..f42b81db0 100644 --- a/retroshare-gui/src/gui/common/RsCollectionEditor.h +++ b/retroshare-gui/src/gui/common/RsCollection.h @@ -56,17 +56,17 @@ public: }; Q_DECLARE_METATYPE(ColFileInfo) -class RsCollectionEditor : public QObject +class RsCollection : public QObject { Q_OBJECT public: - RsCollectionEditor(QObject *parent = 0) ; + RsCollection(QObject *parent = 0) ; // create from list of files and directories - RsCollectionEditor(const std::vector& file_entries, QObject *parent = 0) ; - RsCollectionEditor(const FileTree& fr, QObject *parent); - virtual ~RsCollectionEditor() ; + RsCollection(const std::vector& file_entries, QObject *parent = 0) ; + RsCollection(const FileTree& fr); + virtual ~RsCollection() ; static const QString ExtensionString ; @@ -76,9 +76,6 @@ public: bool load(QWidget *parent); bool load(const QString& fileName, bool showError = true); - // Loads from FileTree - bool load(const FileTree& f); - // Save to disk bool save(QWidget *parent) const ; bool save(const QString& fileName) const ; @@ -102,6 +99,8 @@ private: void recursAddElements(QDomDocument&,const DirDetails&,QDomElement&) const ; void recursAddElements(QDomDocument&,const ColFileInfo&,QDomElement&) const; + void recursAddElements(QDomDocument& doc,const FileTree& ft,uint32_t index,QDomElement& e) const; + void recursCollectColFileInfos(const QDomElement&,std::vector& colFileInfos,const QString& current_dir,bool bad_chars_in_parent) const ; // check that the file is a valid rscollection file, and not a lol bomb or some shit like this static bool checkFile(const QString &fileName, bool showError); diff --git a/retroshare-gui/src/gui/common/RsCollectionDialog.cpp b/retroshare-gui/src/gui/common/RsCollectionDialog.cpp index ee0aeec39..68599eeeb 100644 --- a/retroshare-gui/src/gui/common/RsCollectionDialog.cpp +++ b/retroshare-gui/src/gui/common/RsCollectionDialog.cpp @@ -29,7 +29,7 @@ #include #include #include "RsCollectionDialog.h" -#include "RsCollectionEditor.h" +#include "RsCollection.h" #include "util/misc.h" #define COLUMN_FILE 0 #define COLUMN_FILEPATH 1 @@ -591,12 +591,12 @@ void RsCollectionDialog::changeFileName() QString fileName; if(!misc::getSaveFileName(this, RshareSettings::LASTDIR_EXTRAFILE , QApplication::translate("RsCollectionFile", "Create collection file") - , QApplication::translate("RsCollectionFile", "Collection files") + " (*." + RsCollectionEditor::ExtensionString + ")" + , QApplication::translate("RsCollectionFile", "Collection files") + " (*." + RsCollection::ExtensionString + ")" , fileName,0, QFileDialog::DontConfirmOverwrite)) return; - if (!fileName.endsWith("." + RsCollectionEditor::ExtensionString)) - fileName += "." + RsCollectionEditor::ExtensionString ; + if (!fileName.endsWith("." + RsCollection::ExtensionString)) + fileName += "." + RsCollection::ExtensionString ; std::cerr << "Got file name: " << fileName.toStdString() << std::endl; @@ -604,7 +604,7 @@ void RsCollectionDialog::changeFileName() if(file.exists()) { - RsCollectionEditor collFile; + RsCollection collFile; if (!collFile.checkFile(fileName,true)) return; QMessageBox mb; diff --git a/retroshare-gui/src/gui/common/RsCollectionDialog.h b/retroshare-gui/src/gui/common/RsCollectionDialog.h index e5e5df86d..bac5289b4 100644 --- a/retroshare-gui/src/gui/common/RsCollectionDialog.h +++ b/retroshare-gui/src/gui/common/RsCollectionDialog.h @@ -22,7 +22,7 @@ ****************************************************************/ #include "ui_RsCollectionDialog.h" -#include "RsCollectionEditor.h" +#include "RsCollection.h" #include #include diff --git a/retroshare-gui/src/gui/common/RsUrlHandler.cpp b/retroshare-gui/src/gui/common/RsUrlHandler.cpp index 2e16b23c4..d307d7db1 100644 --- a/retroshare-gui/src/gui/common/RsUrlHandler.cpp +++ b/retroshare-gui/src/gui/common/RsUrlHandler.cpp @@ -22,14 +22,14 @@ #include #include #include -#include "RsCollectionEditor.h" +#include "RsCollection.h" #include "RsUrlHandler.h" bool RsUrlHandler::openUrl(const QUrl& url) { - if(url.scheme() == QString("file") && url.toLocalFile().endsWith("."+RsCollectionEditor::ExtensionString)) + if(url.scheme() == QString("file") && url.toLocalFile().endsWith("."+RsCollection::ExtensionString)) { - RsCollectionEditor collection ; + RsCollection collection ; if(collection.load(url.toLocalFile())) { collection.downloadFiles() ; diff --git a/retroshare-gui/src/retroshare-gui.pro b/retroshare-gui/src/retroshare-gui.pro index b762dc4ed..6b3211392 100644 --- a/retroshare-gui/src/retroshare-gui.pro +++ b/retroshare-gui/src/retroshare-gui.pro @@ -565,7 +565,7 @@ HEADERS += rshare.h \ gui/statistics/BWGraph.h \ util/RsSyntaxHighlighter.h \ util/imageutil.h \ - gui/common/RsCollectionEditor.h + gui/common/RsCollection.h # gui/ForumsDialog.h \ # gui/forums/ForumDetails.h \ @@ -925,7 +925,7 @@ SOURCES += main.cpp \ gui/statistics/BWGraph.cpp \ util/RsSyntaxHighlighter.cpp \ util/imageutil.cpp \ - gui/common/RsCollectionEditor.cpp + gui/common/RsCollection.cpp # gui/ForumsDialog.cpp \ # gui/forums/ForumDetails.cpp \ From 0fbcf0148c1e765d7654008ca257577ace9478ec Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 19 Oct 2017 22:20:23 +0200 Subject: [PATCH 08/19] code cleaning. Removed comments at end of conditional --- .../src/gui/common/RsCollectionDialog.cpp | 98 +++++++++---------- 1 file changed, 49 insertions(+), 49 deletions(-) diff --git a/retroshare-gui/src/gui/common/RsCollectionDialog.cpp b/retroshare-gui/src/gui/common/RsCollectionDialog.cpp index 68599eeeb..68c2a70b7 100644 --- a/retroshare-gui/src/gui/common/RsCollectionDialog.cpp +++ b/retroshare-gui/src/gui/common/RsCollectionDialog.cpp @@ -243,26 +243,26 @@ bool RsCollectionDialog::eventFilter(QObject *obj, QEvent *event) for (it = selectedItems.begin(); it != selectedItems.end(); ++it) { if ((*it)->checkState(COLUMN_FILE) != checkState) (*it)->setCheckState(COLUMN_FILE, checkState); - }//for (it - }//if (item) + } + } return true; // eat event - }//if (keyEvent && keyEvent->key() == Qt::Key_Space) + } if (keyEvent && (keyEvent->key() == Qt::Key_Delete)) { // Delete pressed remove(); return true; // eat event - }//if (keyEvent && keyEvent->key() == Qt::Key_Delete) + } if (keyEvent && (keyEvent->key() == Qt::Key_Plus)) { // Plus pressed makeDir(); return true; // eat event - }//if (keyEvent && keyEvent->key() == Qt::Key_Plus) + } - }//if (event->type() == QEvent::KeyPress) - }//if (obj == ui._fileEntriesTW) + } + } if (obj == ui._systemFileTW) { if (event->type() == QEvent::KeyPress) { @@ -277,9 +277,9 @@ bool RsCollectionDialog::eventFilter(QObject *obj, QEvent *event) } return true; // eat event - }//if (keyEvent && keyEvent->key() == Qt::Key_Enter... - }//if (event->type() == QEvent::KeyPress) - }//if (obj == ui._systemFileTW) + } + } + } // pass the event on to the parent class return QDialog::eventFilter(obj, event); @@ -452,7 +452,7 @@ bool RsCollectionDialog::addChild(QTreeWidgetItem* parent, const std::vectorsetToolTip(COLUMN_FILEC, tr("Real File Count=%1").arg(1)); item->setData(COLUMN_FILEC, ROLE_FILEC, 1); item->setData(COLUMN_FILEC, ROLE_SELFILEC, 1); - }//if (colFileInfo.type==DIR_TYPE_DIR + } item->setFont(COLUMN_FILE, font); if (colFileInfo.filename_has_wrong_characters) @@ -487,12 +487,12 @@ bool RsCollectionDialog::addChild(QTreeWidgetItem* parent, const std::vectorsetText(COLUMN_FILEC, QString("%1").arg(parentSelFileCount)); itemParent = itemParent->parent(); - }//while (itemParent) - }//if (itemParent) - }//if (colFileInfo.type==DIR_TYPE_FILE) + } + } + } founds.push_back(item); - }//(founds.empty()) + } if (!founds.empty()) { @@ -624,7 +624,7 @@ void RsCollectionDialog::changeFileName() if (qddOldFile.setContent(&file)) { QDomElement docOldElem = qddOldFile.elementsByTagName("RsCollection").at(0).toElement(); collFile.recursCollectColFileInfos(docOldElem,_newColFileInfos,QString(),false); - }//(qddOldFile.setContent(&file)) + } } else if (mb.clickedButton()==btnCancel) { return; @@ -636,7 +636,7 @@ void RsCollectionDialog::changeFileName() //create a new empty file to check if name if good. if (!file.open(QFile::WriteOnly)) return; file.remove(); - }//if(file.exists()) + } _fileName = fileName; @@ -686,7 +686,7 @@ void RsCollectionDialog::addRecursive(bool recursive) } else { continue; } - }//if (fileInfo.isDir()) + } if (fileInfo.isFile()){ fileToHash.append(fileInfo.absoluteFilePath()); ++count; @@ -694,9 +694,9 @@ void RsCollectionDialog::addRecursive(bool recursive) _listOfFilesAddedInDir.insert(fileInfo.absoluteFilePath(),fileInfo.absolutePath()); else _listOfFilesAddedInDir.insert(fileInfo.absoluteFilePath(),""); - }//if (fileInfo.isFile()) - }//if (index.column()==0) - }//foreach (QModelIndex index, milSelectionList) + } + } + } // Process Dirs QTreeWidgetItem *item = NULL; @@ -705,8 +705,8 @@ void RsCollectionDialog::addRecursive(bool recursive) if (item) { while (item->data(COLUMN_HASH, ROLE_TYPE).toUInt() != DIR_TYPE_DIR) { item = item->parent();//Only Dir as Parent - }//while - }//if (item) + } + } int index = 0; while (index < dirToAdd.count()) @@ -722,7 +722,7 @@ void RsCollectionDialog::addRecursive(bool recursive) //QMap is ordered, so we get parent before child //Iterator is moved inside this function processItem(dirToAdd, index, root); - }//while (index < dirToAdd.count()) + } //Update liste before attach files to be sure when file is hashed, parent directory exists. updateList(); @@ -736,9 +736,9 @@ void RsCollectionDialog::addRecursive(bool recursive) } else if(item) { if (item->data(COLUMN_HASH, ROLE_NAME) != "") { it.value() = item->text(COLUMN_FILEPATH); - }//if (item->data(COLUMN_HASH, ROLE_NAME) != "") - }//if (dirToAdd.contains(path)) - }//for (QHash::Iterator it + } + } + } // Process Files once all done ui._hashBox->addAttachments(fileToHash,RS_FILE_REQ_ANONYMOUS_ROUTING /*, 0*/); @@ -781,13 +781,13 @@ bool RsCollectionDialog::addAllChild(QFileInfo &fileInfoParent default: // should never be reached break; - }//switch (ret) + } } if (fileInfo.isDir()) { dirToAdd.insert(fileInfo.absoluteFilePath(),fileInfo.absolutePath()); ++count; if (!addAllChild(fileInfo, dirToAdd, fileToHash, count)) return false; - }//if (fileInfo.isDir()) + } if (fileInfo.isFile()){ fileToHash.append(fileInfo.absoluteFilePath()); ++count; @@ -795,8 +795,8 @@ bool RsCollectionDialog::addAllChild(QFileInfo &fileInfoParent _listOfFilesAddedInDir.insert(fileInfo.absoluteFilePath(),fileInfo.absolutePath()); else _listOfFilesAddedInDir.insert(fileInfo.absoluteFilePath(),""); - }//if (fileInfo.isFile()) - }//foreach (QFileInfo fileInfo, dirParent.entryInfoList()) + } + } return true; } @@ -821,10 +821,10 @@ void RsCollectionDialog::remove() item->setSelected(false); } else { listDir += item->data(COLUMN_HASH, ROLE_NAME).toString() +"
"; - }//if (listDir.contains(item->data(COLUMN_HASH, ROLE_PATH).toString())) - }//if (item->data(COLUMN_HASH, ROLE_TYPE).toUInt() == DIR_TYPE_DIR) - }//if (item != getRootItem()) - }//for (int curs = 0; curs < count; ++curs) + } + } + } + } //If directories, ask to remove them or not if (!listDir.isEmpty()){ @@ -870,14 +870,14 @@ void RsCollectionDialog::remove() case QMessageBox::Cancel: { delete msgBox; return; - }//case QMessageBox::Cancel: + } break; default: // should never be reached break; - }//switch (ret) + } delete msgBox; - }//if (!listDir.isEmpty()) + } //Remove wanted items int leftItem = 0; @@ -966,7 +966,7 @@ void RsCollectionDialog::processItem(QMap &dirToAdd } else { _newColFileInfos.push_back(newChild); } - }//(index < count) + } } /** @@ -1006,13 +1006,13 @@ void RsCollectionDialog::makeDir() default: // should never be reached break; - }//switch (ret) - }//if (badChar) + } + } } else {//if (ok && !childName.isEmpty()) return; - }//if (ok && !childName.isEmpty()) + } - }//while (!nameOK) + } // Process all selected items int count = ui._fileEntriesTW->selectedItems().count(); @@ -1040,8 +1040,8 @@ void RsCollectionDialog::makeDir() if (item == getRootItem()) newChild.path = ""; _newColFileInfos.push_back(newChild); - }//if (item) - }//for (; curs < count; ++curs) + } + } updateList(); @@ -1074,7 +1074,7 @@ void RsCollectionDialog::fileHashingFinished(QList hashedFiles) //File Added in directory, find its parent colFileInfo.path = _listOfFilesAddedInDir.value(hashedFile.filepath,""); _listOfFilesAddedInDir.remove(hashedFile.filepath); - }//if (_listOfFilesAddedInDir.value(hashedFile.filepath,"")!="") + } _newColFileInfos.push_back(colFileInfo); @@ -1112,7 +1112,7 @@ void RsCollectionDialog::itemChanged(QTreeWidgetItem *item, int col) itemParent->setText(COLUMN_FILEC, QString("%1").arg(parentFileCount)); itemParent = itemParent->parent(); - }//while (itemParent) + } updateSizes() ; @@ -1258,8 +1258,8 @@ void RsCollectionDialog::download() std::list()); } else {//if (item->checkState(COLUMN_FILE) == Qt::Checked) std::cerr<<"Skipping file : " << item->data(COLUMN_HASH,ROLE_NAME).toString().toStdString() << std::endl; - }//if (item->checkState(COLUMN_FILE) == Qt::Checked) - }//while ((item = *itemIterator) != NULL) + } + } close(); } From 6581fa0429e9ba09f3b50c591738c613f9b8bb54 Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 21 Oct 2017 15:44:45 +0200 Subject: [PATCH 09/19] code cleaning --- .../src/gui/FileTransfer/TransfersDialog.cpp | 134 ++++-------------- 1 file changed, 29 insertions(+), 105 deletions(-) diff --git a/retroshare-gui/src/gui/FileTransfer/TransfersDialog.cpp b/retroshare-gui/src/gui/FileTransfer/TransfersDialog.cpp index b6c3376a5..d2194ebec 100644 --- a/retroshare-gui/src/gui/FileTransfer/TransfersDialog.cpp +++ b/retroshare-gui/src/gui/FileTransfer/TransfersDialog.cpp @@ -666,8 +666,7 @@ void TransfersDialog::downloadListCustomPopupMenu( QPoint /*point*/ ) //Look only for first column == File List //Get Info for current item - if (rsFiles->FileDetails(fileHash - , RS_FILE_HINTS_DOWNLOAD, info)) { + if (rsFiles->FileDetails(fileHash, RS_FILE_HINTS_DOWNLOAD, info)) { /*const uint32_t FT_STATE_FAILED = 0x0000; *const uint32_t FT_STATE_OKAY = 0x0001; *const uint32_t FT_STATE_WAITING = 0x0002; @@ -677,22 +676,21 @@ void TransfersDialog::downloadListCustomPopupMenu( QPoint /*point*/ ) *const uint32_t FT_STATE_PAUSED = 0x0006; *const uint32_t FT_STATE_CHECKING_HASH = 0x0007; */ - if (info.downloadStatus == FT_STATE_WAITING) { + if (info.downloadStatus == FT_STATE_WAITING) atLeastOne_Waiting = true ; - } - if (info.downloadStatus == FT_STATE_DOWNLOADING) { + + if (info.downloadStatus == FT_STATE_DOWNLOADING) atLeastOne_Downloading=true ; - } + if (info.downloadStatus == FT_STATE_COMPLETE) { atLeastOne_Complete = true ; add_OpenFileOption = single ; } - if (info.downloadStatus == FT_STATE_QUEUED) { + if (info.downloadStatus == FT_STATE_QUEUED) atLeastOne_Queued = true ; - } - if (info.downloadStatus == FT_STATE_PAUSED) { + + if (info.downloadStatus == FT_STATE_PAUSED) atLeastOne_Paused = true ; - } size_t pos = info.fname.find_last_of('.') ; if (pos != std::string::npos) { @@ -748,24 +746,21 @@ void TransfersDialog::downloadListCustomPopupMenu( QPoint /*point*/ ) } } - if (atLeastOne_Paused) { + if (atLeastOne_Paused) contextMnu.addAction(resumeAct) ; - } - if (atLeastOne_Downloading || atLeastOne_Queued || atLeastOne_Waiting) { + + if (atLeastOne_Downloading || atLeastOne_Queued || atLeastOne_Waiting) contextMnu.addAction(pauseAct) ; - } if (!atLeastOne_Complete && !items.empty()) { contextMnu.addAction(forceCheckAct) ; contextMnu.addAction(cancelAct) ; } - if (add_PlayOption) { + if (add_PlayOption) contextMnu.addAction(playAct) ; - } - if (atLeastOne_Paused || atLeastOne_Downloading || atLeastOne_Complete || add_PlayOption) { - contextMnu.addSeparator() ;//------------------------------------------------ - } + if (atLeastOne_Paused || atLeastOne_Downloading || atLeastOne_Complete || add_PlayOption) + contextMnu.addSeparator() ; if (single) { if (add_OpenFileOption) contextMnu.addAction( openFileAct) ; @@ -776,7 +771,7 @@ void TransfersDialog::downloadListCustomPopupMenu( QPoint /*point*/ ) } contextMnu.addAction( clearCompletedAct) ; - contextMnu.addSeparator() ;//------------------------------------------------ + contextMnu.addSeparator() ; if (add_CopyLink) { contextMnu.addAction( copyLinkAct) ; @@ -785,7 +780,7 @@ void TransfersDialog::downloadListCustomPopupMenu( QPoint /*point*/ ) contextMnu.addAction( pasteLinkAct) ; } if (add_CopyLink || add_PasteLink) { - contextMnu.addSeparator() ;//-------------------------------------------- + contextMnu.addSeparator() ; } if (DLLFilterModel->rowCount()>0 ) { @@ -2153,7 +2148,7 @@ void TransfersDialog::collCreate() details.type = DIR_TYPE_FILE; dirVec.push_back(details); - } + }//for (it = items.begin(); RsCollection(dirVec).openNewColl(this); } @@ -2258,89 +2253,18 @@ void TransfersDialog::collOpen() } } -void TransfersDialog::setShowDLSizeColumn(bool show) -{ - if ( (!ui.downloadList->isColumnHidden(COLUMN_SIZE)) != show) { - ui.downloadList->setColumnHidden(COLUMN_SIZE, !show); - } -} - -void TransfersDialog::setShowDLCompleteColumn(bool show) -{ - if ( (!ui.downloadList->isColumnHidden(COLUMN_COMPLETED)) != show) { - ui.downloadList->setColumnHidden(COLUMN_COMPLETED, !show); - } -} - -void TransfersDialog::setShowDLDLSpeedColumn(bool show) -{ - if ( (!ui.downloadList->isColumnHidden(COLUMN_DLSPEED)) != show) { - ui.downloadList->setColumnHidden(COLUMN_DLSPEED, !show); - } -} - -void TransfersDialog::setShowDLProgressColumn(bool show) -{ - if ( (!ui.downloadList->isColumnHidden(COLUMN_PROGRESS)) != show) { - ui.downloadList->setColumnHidden(COLUMN_PROGRESS, !show); - } -} - -void TransfersDialog::setShowDLSourcesColumn(bool show) -{ - if ( (!ui.downloadList->isColumnHidden(COLUMN_SOURCES)) != show) { - ui.downloadList->setColumnHidden(COLUMN_SOURCES, !show); - } -} - -void TransfersDialog::setShowDLStatusColumn(bool show) -{ - if ( (!ui.downloadList->isColumnHidden(COLUMN_STATUS)) != show) { - ui.downloadList->setColumnHidden(COLUMN_STATUS, !show); - } -} - -void TransfersDialog::setShowDLPriorityColumn(bool show) -{ - if ( (!ui.downloadList->isColumnHidden(COLUMN_PRIORITY)) != show) { - ui.downloadList->setColumnHidden(COLUMN_PRIORITY, !show); - } -} - -void TransfersDialog::setShowDLRemainingColumn(bool show) -{ - if ( (!ui.downloadList->isColumnHidden(COLUMN_REMAINING)) != show) { - ui.downloadList->setColumnHidden(COLUMN_REMAINING, !show); - } -} - -void TransfersDialog::setShowDLDownloadTimeColumn(bool show) -{ - if ( (!ui.downloadList->isColumnHidden(COLUMN_DOWNLOADTIME)) != show) { - ui.downloadList->setColumnHidden(COLUMN_DOWNLOADTIME, !show); - } -} - -void TransfersDialog::setShowDLIDColumn(bool show) -{ - if ( (!ui.downloadList->isColumnHidden(COLUMN_ID)) != show) { - ui.downloadList->setColumnHidden(COLUMN_ID, !show); - } -} - -void TransfersDialog::setShowDLLastDLColumn(bool show) -{ - if ( (!ui.downloadList->isColumnHidden(COLUMN_LASTDL)) != show) { - ui.downloadList->setColumnHidden(COLUMN_LASTDL, !show); - } -} - -void TransfersDialog::setShowDLPath(bool show) -{ - if ( (!ui.downloadList->isColumnHidden(COLUMN_PATH)) != show) { - ui.downloadList->setColumnHidden(COLUMN_PATH, !show); - } -} +void TransfersDialog::setShowDLSizeColumn (bool show) { ui.downloadList->setColumnHidden(COLUMN_SIZE, !show); } +void TransfersDialog::setShowDLCompleteColumn (bool show) { ui.downloadList->setColumnHidden(COLUMN_COMPLETED, !show); } +void TransfersDialog::setShowDLDLSpeedColumn (bool show) { ui.downloadList->setColumnHidden(COLUMN_DLSPEED, !show); } +void TransfersDialog::setShowDLProgressColumn (bool show) { ui.downloadList->setColumnHidden(COLUMN_PROGRESS, !show); } +void TransfersDialog::setShowDLSourcesColumn (bool show) { ui.downloadList->setColumnHidden(COLUMN_SOURCES, !show); } +void TransfersDialog::setShowDLStatusColumn (bool show) { ui.downloadList->setColumnHidden(COLUMN_STATUS, !show); } +void TransfersDialog::setShowDLPriorityColumn (bool show) { ui.downloadList->setColumnHidden(COLUMN_PRIORITY, !show); } +void TransfersDialog::setShowDLRemainingColumn (bool show) { ui.downloadList->setColumnHidden(COLUMN_REMAINING, !show); } +void TransfersDialog::setShowDLDownloadTimeColumn(bool show) { ui.downloadList->setColumnHidden(COLUMN_DOWNLOADTIME, !show); } +void TransfersDialog::setShowDLIDColumn (bool show) { ui.downloadList->setColumnHidden(COLUMN_ID, !show); } +void TransfersDialog::setShowDLLastDLColumn (bool show) { ui.downloadList->setColumnHidden(COLUMN_LASTDL, !show); } +void TransfersDialog::setShowDLPath (bool show) { ui.downloadList->setColumnHidden(COLUMN_PATH, !show); } void TransfersDialog::expandAllDL() { From fe516c6b7a2563efdb0aae5f3f812f35dcc8356f Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 21 Oct 2017 16:16:23 +0200 Subject: [PATCH 10/19] fixed pasting of FileTree links in download queue --- .../src/gui/FileTransfer/SharedFilesDialog.cpp | 10 ++++++---- .../src/gui/FileTransfer/TransfersDialog.cpp | 4 +++- retroshare-gui/src/gui/RetroShareLink.cpp | 18 +++++++++--------- retroshare-gui/src/gui/RetroShareLink.h | 2 +- retroshare-gui/src/util/HandleRichText.cpp | 4 ++-- 5 files changed, 21 insertions(+), 17 deletions(-) diff --git a/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp b/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp index f071c3a66..b5d82ad4f 100644 --- a/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp +++ b/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp @@ -517,7 +517,7 @@ void RemoteSharedFilesDialog::spawnCustomPopupMenu( QPoint point ) contextMnu.addAction( copylinkAct) ; contextMnu.addAction( sendlinkAct) ; contextMnu.addSeparator() ;//------------------------------------ - contextMnu.addAction(QIcon(IMAGE_MSG), tr("Recommend in a message to"), this, SLOT(recommendFilesToMsg())) ; + contextMnu.addAction(QIcon(IMAGE_MSG), tr("Recommend in a message to..."), this, SLOT(recommendFilesToMsg())) ; } contextMnu.addSeparator() ;//------------------------------------ @@ -578,7 +578,9 @@ void SharedFilesDialog::copyLink (const QModelIndexList& lst, bool remote) std::cerr << "Created collection file tree:" << std::endl; ft->print(); - RetroShareLink link = RetroShareLink::createCollection(QString::fromUtf8(details.name.c_str()),ft->mTotalSize,ft->mTotalFiles,QString::fromStdString(ft->toRadix64())) ; + QString dir_name = QDir(QString::fromUtf8(details.name.c_str())).dirName(); + + RetroShareLink link = RetroShareLink::createCollection(dir_name,ft->mTotalSize,ft->mTotalFiles,QString::fromStdString(ft->toRadix64())) ; if(link.valid()) urls.push_back(link) ; @@ -1027,12 +1029,12 @@ void LocalSharedFilesDialog::spawnCustomPopupMenu( QPoint point ) contextMnu.addSeparator() ;//------------------------------------ contextMnu.addMenu(&collectionMenu) ; contextMnu.addSeparator() ;//------------------------------------ - contextMnu.addAction(QIcon(IMAGE_MSG), tr("Recommend in a message to"), this, SLOT(recommendFilesToMsg())) ; + contextMnu.addAction(QIcon(IMAGE_MSG), tr("Recommend in a message to..."), this, SLOT(recommendFilesToMsg())) ; break ; default : return ; - }//switch (type) + } contextMnu.exec(QCursor::pos()) ; } diff --git a/retroshare-gui/src/gui/FileTransfer/TransfersDialog.cpp b/retroshare-gui/src/gui/FileTransfer/TransfersDialog.cpp index d2194ebec..ca4cf5cfa 100644 --- a/retroshare-gui/src/gui/FileTransfer/TransfersDialog.cpp +++ b/retroshare-gui/src/gui/FileTransfer/TransfersDialog.cpp @@ -652,7 +652,8 @@ void TransfersDialog::downloadListCustomPopupMenu( QPoint /*point*/ ) QMenu contextMnu( this ); - if(!RSLinkClipboard::empty(RetroShareLink::TYPE_FILE)) add_PasteLink=true; + if(!RSLinkClipboard::empty(RetroShareLink::TYPE_FILE)) add_PasteLink=true; + if(!RSLinkClipboard::empty(RetroShareLink::TYPE_FILE_TREE)) add_PasteLink=true; if(!items.empty()) { @@ -1640,6 +1641,7 @@ void TransfersDialog::updateDetailsDialog() void TransfersDialog::pasteLink() { RSLinkClipboard::process(RetroShareLink::TYPE_FILE); + RSLinkClipboard::process(RetroShareLink::TYPE_FILE_TREE); } void TransfersDialog::getDLSelectedItems(std::set *ids, std::set *rows) diff --git a/retroshare-gui/src/gui/RetroShareLink.cpp b/retroshare-gui/src/gui/RetroShareLink.cpp index 7a1e32aae..769a6321f 100644 --- a/retroshare-gui/src/gui/RetroShareLink.cpp +++ b/retroshare-gui/src/gui/RetroShareLink.cpp @@ -336,7 +336,7 @@ void RetroShareLink::fromUrl(const QUrl& url) if (url.host() == HOST_COLLECTION) { bool ok; - _type = TYPE_COLLECTION; + _type = TYPE_FILE_TREE; _radix = decodedQueryItemValue(urlQuery, COLLECTION_DATA); _name = decodedQueryItemValue(urlQuery, COLLECTION_NAME); _size = urlQuery.queryItemValue(COLLECTION_SIZE).toULongLong(&ok); @@ -429,7 +429,7 @@ RetroShareLink RetroShareLink::createCollection(const QString& name, uint64_t si link._count = count; link._size = size; link._radix = radix_data ; - link._type = TYPE_COLLECTION; + link._type = TYPE_FILE_TREE; link.check(); @@ -643,7 +643,7 @@ void RetroShareLink::check() if(!checkSSLId(_SSLid)) _valid = false; // no break! We also test file stuff below. /* fallthrough */ - case TYPE_COLLECTION: + case TYPE_FILE_TREE: case TYPE_FILE: if(_size > (((uint64_t)1)<<40)) // 1TB. Who has such large files? @@ -754,7 +754,7 @@ QString RetroShareLink::title() const rsPeers->getGPGDetails(RsPgpId(_GPGid.toStdString()), detail) ; return QObject::tr("Click to send a private message to %1 (%2).").arg(QString::fromUtf8(detail.name.c_str())).arg(_GPGid) ; } - case TYPE_COLLECTION: + case TYPE_FILE_TREE: return QObject::tr("Click to browse/download this file collection"); case TYPE_EXTRAFILE: return QObject::tr("%1 (%2, Extra - Source included)").arg(hash()).arg(misc::friendlyUnit(size())); @@ -899,7 +899,7 @@ QString RetroShareLink::toString() const break; - case TYPE_COLLECTION: + case TYPE_FILE_TREE: url.setScheme(RSLINK_SCHEME); url.setHost(HOST_COLLECTION) ; urlQuery.addQueryItem(COLLECTION_NAME, encodeItem(_name)); @@ -930,13 +930,13 @@ QString RetroShareLink::niceName() const if (type() == TYPE_PERSON) return PeerDefs::rsid(name().toUtf8().constData(), RsPgpId(hash().toStdString())); - if(type() == TYPE_COLLECTION) + if(type() == TYPE_FILE_TREE) return QObject::tr("%1 (%2 files, %3)").arg(_name).arg(_count).arg(misc::friendlyUnit(_size)); if(type() == TYPE_IDENTITY) return QObject::tr("Identity link (name=%1, ID=%2)").arg(_name).arg(_hash) ; - if(type() == TYPE_COLLECTION) + if(type() == TYPE_FILE_TREE) return QObject::tr("File directory (Total %s) Click to browse/download this file collection").arg(misc::friendlyUnit(_size)); if(type() == TYPE_PUBLIC_MSG) { @@ -1149,7 +1149,7 @@ static void processList(const QStringList &list, const QString &textSingular, co case TYPE_SEARCH: case TYPE_MESSAGE: case TYPE_IDENTITY: - case TYPE_COLLECTION: + case TYPE_FILE_TREE: case TYPE_CERTIFICATE: case TYPE_PUBLIC_MSG: case TYPE_PRIVATE_CHAT: @@ -1391,7 +1391,7 @@ static void processList(const QStringList &list, const QString &textSingular, co } break; - case TYPE_COLLECTION: + case TYPE_FILE_TREE: { FileTree *ft = FileTree::create(link.radix().toStdString()) ; diff --git a/retroshare-gui/src/gui/RetroShareLink.h b/retroshare-gui/src/gui/RetroShareLink.h index 2576b880c..11b25b419 100644 --- a/retroshare-gui/src/gui/RetroShareLink.h +++ b/retroshare-gui/src/gui/RetroShareLink.h @@ -70,7 +70,7 @@ class RetroShareLink TYPE_PUBLIC_MSG = 0x0a, TYPE_POSTED = 0x0b, TYPE_IDENTITY = 0x0c, - TYPE_COLLECTION = 0x0d + TYPE_FILE_TREE = 0x0d }; public: diff --git a/retroshare-gui/src/util/HandleRichText.cpp b/retroshare-gui/src/util/HandleRichText.cpp index 91f3e13ab..743a2fcc1 100644 --- a/retroshare-gui/src/util/HandleRichText.cpp +++ b/retroshare-gui/src/util/HandleRichText.cpp @@ -227,7 +227,7 @@ bool RsHtml::canReplaceAnchor(QDomDocument &/*doc*/, QDomElement &/*element*/, c switch (link.type()) { case RetroShareLink::TYPE_UNKNOWN: case RetroShareLink::TYPE_FILE: - case RetroShareLink::TYPE_COLLECTION: + case RetroShareLink::TYPE_FILE_TREE: case RetroShareLink::TYPE_PERSON: case RetroShareLink::TYPE_FORUM: case RetroShareLink::TYPE_CHANNEL: @@ -258,7 +258,7 @@ void RsHtml::anchorStylesheetForImg(QDomDocument &/*doc*/, QDomElement &/*elemen switch (link.type()) { case RetroShareLink::TYPE_UNKNOWN: case RetroShareLink::TYPE_FILE: - case RetroShareLink::TYPE_COLLECTION: + case RetroShareLink::TYPE_FILE_TREE: case RetroShareLink::TYPE_PERSON: case RetroShareLink::TYPE_FORUM: case RetroShareLink::TYPE_CHANNEL: From 2cfa86620cf778e76c32f2da8cd536fa96a64311 Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 21 Oct 2017 17:35:06 +0200 Subject: [PATCH 11/19] merge of trees and single files before paste in DL queue so that all use the CollectionEditor --- .../src/gui/FileTransfer/TransfersDialog.cpp | 23 +++++++++++++-- retroshare-gui/src/gui/RetroShareLink.cpp | 28 +++++++----------- retroshare-gui/src/gui/RetroShareLink.h | 6 ++-- .../src/gui/common/RsCollection.cpp | 29 +++++++++++++------ retroshare-gui/src/gui/common/RsCollection.h | 6 ++-- 5 files changed, 58 insertions(+), 34 deletions(-) diff --git a/retroshare-gui/src/gui/FileTransfer/TransfersDialog.cpp b/retroshare-gui/src/gui/FileTransfer/TransfersDialog.cpp index ca4cf5cfa..b9e961457 100644 --- a/retroshare-gui/src/gui/FileTransfer/TransfersDialog.cpp +++ b/retroshare-gui/src/gui/FileTransfer/TransfersDialog.cpp @@ -1640,8 +1640,27 @@ void TransfersDialog::updateDetailsDialog() void TransfersDialog::pasteLink() { - RSLinkClipboard::process(RetroShareLink::TYPE_FILE); - RSLinkClipboard::process(RetroShareLink::TYPE_FILE_TREE); + QList links ; + + // We want to capture and process all links at once here, because we're possibly pasting a large collection of files. So we first + // merge all links into a single RsCollection and then process it. + + RsCollection col ; + RSLinkClipboard::pasteLinks(links,RetroShareLink::TYPE_FILE_TREE); + + for(QList::const_iterator it(links.begin());it!=links.end();++it) + { + FileTree *ft = FileTree::create((*it).radix().toStdString()) ; + + col.merge_in(*ft) ; + } + links.clear(); + RSLinkClipboard::pasteLinks(links,RetroShareLink::TYPE_FILE); + + for(QList::const_iterator it(links.begin());it!=links.end();++it) + col.merge_in((*it).name(),(*it).size(),RsFileHash((*it).hash().toStdString())) ; + + col.downloadFiles(); } void TransfersDialog::getDLSelectedItems(std::set *ids, std::set *rows) diff --git a/retroshare-gui/src/gui/RetroShareLink.cpp b/retroshare-gui/src/gui/RetroShareLink.cpp index 769a6321f..a42d9c104 100644 --- a/retroshare-gui/src/gui/RetroShareLink.cpp +++ b/retroshare-gui/src/gui/RetroShareLink.cpp @@ -1716,17 +1716,17 @@ void RSLinkClipboard::copyLinks(const QList& links) QApplication::clipboard()->setText(res) ; } -void RSLinkClipboard::pasteLinks(QList &links) +void RSLinkClipboard::pasteLinks(QList &links,RetroShareLink::enumType type) { - return parseClipboard(links); + return parseClipboard(links,type); } -void RSLinkClipboard::parseClipboard(QList &links) +void RSLinkClipboard::parseClipboard(QList &links,RetroShareLink::enumType type) { // parse clipboard for links. // QString text = QApplication::clipboard()->text() ; - parseText(text, links); + parseText(text, links,type); } QString RSLinkClipboard::toString() @@ -1771,26 +1771,18 @@ bool RSLinkClipboard::empty(RetroShareLink::enumType type /* = RetroShareLink::T return true; } -/*static*/ int RSLinkClipboard::process(RetroShareLink::enumType type /* = RetroShareLink::TYPE_UNKNOWN*/, uint flag /* = RSLINK_PROCESS_NOTIFY_ALL*/) +int RSLinkClipboard::process(RetroShareLink::enumType type /* = RetroShareLink::TYPE_UNKNOWN*/, uint flag /* = RSLINK_PROCESS_NOTIFY_ALL*/) { QList links; - pasteLinks(links); + pasteLinks(links,type); - QList linksToProcess; - for (int i = 0; i < links.size(); ++i) { - if (links[i].valid() && (type == RetroShareLink::TYPE_UNKNOWN || links[i].type() == type)) { - linksToProcess.append(links[i]); - } - } - - if (linksToProcess.isEmpty()) { + if (links.isEmpty()) return 0; - } - return RetroShareLink::process(linksToProcess, flag); + return RetroShareLink::process(links, flag); } -void RSLinkClipboard::parseText(QString text, QList &links) +void RSLinkClipboard::parseText(QString text, QList &links,RetroShareLink::enumType type ) { links.clear(); @@ -1805,7 +1797,7 @@ void RSLinkClipboard::parseText(QString text, QList &links) QString url(text.mid(pos, rx.matchedLength())); RetroShareLink link(url); - if(link.valid()) + if(link.valid() && (type == RetroShareLink::TYPE_UNKNOWN || type == link.type())) { // check that the link is not already in the list: bool already = false ; diff --git a/retroshare-gui/src/gui/RetroShareLink.h b/retroshare-gui/src/gui/RetroShareLink.h index 11b25b419..43ca67ab0 100644 --- a/retroshare-gui/src/gui/RetroShareLink.h +++ b/retroshare-gui/src/gui/RetroShareLink.h @@ -192,7 +192,7 @@ class RSLinkClipboard // Get the liste of pasted links, either from the internal RS links, or by default // from the clipboard. // - static void pasteLinks(QList &links) ; + static void pasteLinks(QList &links,RetroShareLink::enumType type = RetroShareLink::TYPE_UNKNOWN) ; // Produces a list of links with no html structure. static QString toString() ; @@ -215,10 +215,10 @@ class RSLinkClipboard // static int process(RetroShareLink::enumType type = RetroShareLink::TYPE_UNKNOWN, uint flag = RSLINK_PROCESS_NOTIFY_ALL); - static void parseText(QString text, QList &links) ; + static void parseText(QString text, QList &links, RetroShareLink::enumType type = RetroShareLink::TYPE_UNKNOWN) ; private: - static void parseClipboard(QList &links) ; + static void parseClipboard(QList &links, RetroShareLink::enumType type = RetroShareLink::TYPE_UNKNOWN) ; }; #endif diff --git a/retroshare-gui/src/gui/common/RsCollection.cpp b/retroshare-gui/src/gui/common/RsCollection.cpp index a7ba9637a..a42d34340 100644 --- a/retroshare-gui/src/gui/common/RsCollection.cpp +++ b/retroshare-gui/src/gui/common/RsCollection.cpp @@ -41,25 +41,21 @@ const QString RsCollection::ExtensionString = QString("rscollection") ; RsCollection::RsCollection(QObject *parent) : QObject(parent), _xml_doc("RsCollection") { + _root = _xml_doc.createElement("RsCollection"); + _xml_doc.appendChild(_root); } RsCollection::RsCollection(const FileTree& fr) : _xml_doc("RsCollection") { - QDomElement root = _xml_doc.createElement("RsCollection"); - _xml_doc.appendChild(root); - - recursAddElements(_xml_doc,fr,0,root) ; + recursAddElements(_xml_doc,fr,0,_root) ; } RsCollection::RsCollection(const std::vector& file_infos, QObject *parent) : QObject(parent), _xml_doc("RsCollection") { - QDomElement root = _xml_doc.createElement("RsCollection"); - _xml_doc.appendChild(root); - for(uint32_t i = 0;i& colFileInfos,const QString& current_path, bool bad_chars_in_parent) const { QDomNode n = e.firstChild() ; @@ -235,7 +246,7 @@ void RsCollection::recursAddElements(QDomDocument& doc,const FileTree& ft,uint32 f.setAttribute(QString("sha1"),QString::fromStdString(subfiles[i].hash.toStdString())) ; f.setAttribute(QString("size"),QString::number(subfiles[i].size)) ; - e.appendChild(f) ; + d.appendChild(f) ; } } diff --git a/retroshare-gui/src/gui/common/RsCollection.h b/retroshare-gui/src/gui/common/RsCollection.h index f42b81db0..0a6e1e65f 100644 --- a/retroshare-gui/src/gui/common/RsCollection.h +++ b/retroshare-gui/src/gui/common/RsCollection.h @@ -68,10 +68,11 @@ public: RsCollection(const FileTree& fr); virtual ~RsCollection() ; + void merge_in(const QString& fname,uint64_t size,const RsFileHash& hash) ; + void merge_in(const FileTree& tree) ; + static const QString ExtensionString ; - - // Loads file from disk. bool load(QWidget *parent); bool load(const QString& fileName, bool showError = true); @@ -108,6 +109,7 @@ private: QDomDocument _xml_doc ; QString _fileName ; bool _saved; + QDomElement _root ; friend class RsCollectionDialog ; }; From cbcf402e0bded6413f6419a1f4b0ea7259bc908f Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 21 Oct 2017 17:42:17 +0200 Subject: [PATCH 12/19] setup proper title in RsCollectionEditor when in download mode --- retroshare-gui/src/gui/common/RsCollection.cpp | 2 -- retroshare-gui/src/gui/common/RsCollectionDialog.cpp | 6 +++++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/retroshare-gui/src/gui/common/RsCollection.cpp b/retroshare-gui/src/gui/common/RsCollection.cpp index a42d34340..8fdbd4e0f 100644 --- a/retroshare-gui/src/gui/common/RsCollection.cpp +++ b/retroshare-gui/src/gui/common/RsCollection.cpp @@ -214,9 +214,7 @@ void RsCollection::recursAddElements(QDomDocument& doc,const ColFileInfo& colFil d.setAttribute(QString("name"),colFileInfo.name) ; for (std::vector::const_iterator it = colFileInfo.children.begin(); it != colFileInfo.children.end(); ++it) - { recursAddElements(doc,(*it),d) ; - } e.appendChild(d) ; } diff --git a/retroshare-gui/src/gui/common/RsCollectionDialog.cpp b/retroshare-gui/src/gui/common/RsCollectionDialog.cpp index 68c2a70b7..b73191fec 100644 --- a/retroshare-gui/src/gui/common/RsCollectionDialog.cpp +++ b/retroshare-gui/src/gui/common/RsCollectionDialog.cpp @@ -138,7 +138,11 @@ RsCollectionDialog::RsCollectionDialog(const QString& collectionFileName ui.headerFrame->setHeaderImage(QPixmap(":/images/library64.png")); - ui.headerFrame->setHeaderText(tr("Collection Editor")); + + if(creation) + ui.headerFrame->setHeaderText(tr("Collection Editor")); + else + ui.headerFrame->setHeaderText(tr("Download files")); // 1 - add all elements to the list. From edffbc3670b61a3f8bd239105824d475f9c5b92d Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 21 Oct 2017 18:09:26 +0200 Subject: [PATCH 13/19] fixed bug in removing top dirs when creating file hierarhies --- libretroshare/src/file_sharing/file_tree.cc | 15 ++++++++++----- libretroshare/src/file_sharing/file_tree.h | 2 +- libretroshare/src/retroshare/rsfiles.h | 2 +- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/libretroshare/src/file_sharing/file_tree.cc b/libretroshare/src/file_sharing/file_tree.cc index 8a1f11fc5..92ee6a362 100644 --- a/libretroshare/src/file_sharing/file_tree.cc +++ b/libretroshare/src/file_sharing/file_tree.cc @@ -1,5 +1,6 @@ #include #include +#include #include "file_sharing_defaults.h" #include "filelist_io.h" @@ -30,12 +31,16 @@ FileTree *FileTree::create(const std::string& radix64_string) return ft ; } -void FileTreeImpl::recurs_buildFileTree(FileTreeImpl& ft,uint32_t index,const DirDetails& dd,bool remote) +void FileTreeImpl::recurs_buildFileTree(FileTreeImpl& ft,uint32_t index,const DirDetails& dd,bool remote,bool remove_top_dirs) { if(ft.mDirs.size() <= index) ft.mDirs.resize(index+1) ; - ft.mDirs[index].name = dd.name ; + if(remove_top_dirs) + ft.mDirs[index].name = RsDirUtil::getTopDir(dd.name) ; + else + ft.mDirs[index].name = dd.name ; + ft.mDirs[index].subfiles.clear(); ft.mDirs[index].subdirs.clear(); @@ -62,7 +67,7 @@ void FileTreeImpl::recurs_buildFileTree(FileTreeImpl& ft,uint32_t index,const Di else if(dd.children[i].type == DIR_TYPE_DIR) { ft.mDirs[index].subdirs.push_back(ft.mDirs.size()); - recurs_buildFileTree(ft,ft.mDirs.size(),dd2,remote) ; + recurs_buildFileTree(ft,ft.mDirs.size(),dd2,remote,remove_top_dirs) ; } else std::cerr << "(EE) Unsupported DirDetails type." << std::endl; @@ -86,11 +91,11 @@ bool FileTreeImpl::getDirectoryContent(uint32_t index,std::string& name,std::vec return true ; } -FileTree *FileTree::create(const DirDetails& dd, bool remote) +FileTree *FileTree::create(const DirDetails& dd, bool remote,bool remove_top_dirs) { FileTreeImpl *ft = new FileTreeImpl ; - FileTreeImpl::recurs_buildFileTree(*ft,0,dd,remote) ; + FileTreeImpl::recurs_buildFileTree(*ft,0,dd,remote,remove_top_dirs) ; return ft ; } diff --git a/libretroshare/src/file_sharing/file_tree.h b/libretroshare/src/file_sharing/file_tree.h index 5f94bdf48..8aaa9dff6 100644 --- a/libretroshare/src/file_sharing/file_tree.h +++ b/libretroshare/src/file_sharing/file_tree.h @@ -19,7 +19,7 @@ public: protected: void recurs_print(uint32_t index,const std::string& indent) const; - static void recurs_buildFileTree(FileTreeImpl& ft,uint32_t index,const DirDetails& dd,bool remote); + static void recurs_buildFileTree(FileTreeImpl& ft, uint32_t index, const DirDetails& dd, bool remote, bool remove_top_dirs); struct DirData { std::string name; diff --git a/libretroshare/src/retroshare/rsfiles.h b/libretroshare/src/retroshare/rsfiles.h index 64af23885..d7efb2937 100644 --- a/libretroshare/src/retroshare/rsfiles.h +++ b/libretroshare/src/retroshare/rsfiles.h @@ -144,7 +144,7 @@ class FileTree public: virtual ~FileTree() {} - static FileTree *create(const DirDetails& dd, bool remote) ; + static FileTree *create(const DirDetails& dd, bool remote, bool remove_top_dirs = true) ; static FileTree *create(const std::string& radix64_string) ; virtual std::string toRadix64() const =0 ; From 770add8b8ac5a0eb192d72a934bf77c013838d18 Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 21 Oct 2017 21:23:40 +0200 Subject: [PATCH 14/19] added code to share a file/dir on channel --- .../gui/FileTransfer/SharedFilesDialog.cpp | 133 ++++++++++-------- .../src/gui/FileTransfer/SharedFilesDialog.h | 7 +- .../src/gui/gxs/GxsGroupFrameDialog.cpp | 9 ++ .../src/gui/gxs/GxsGroupFrameDialog.h | 4 + .../src/gui/gxschannels/GxsChannelDialog.cpp | 5 + .../src/gui/gxschannels/GxsChannelDialog.h | 2 + 6 files changed, 98 insertions(+), 62 deletions(-) diff --git a/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp b/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp index b5d82ad4f..afba50f7b 100644 --- a/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp +++ b/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp @@ -33,6 +33,7 @@ #include "SharedFilesDialog.h" #include "gui/notifyqt.h" +#include "gui/MainWindow.h" #include "gui/RemoteDirModel.h" #include "gui/RetroShareLink.h" #include "gui/ShareManager.h" @@ -40,6 +41,7 @@ #include "gui/common/RsCollection.h" #include "gui/msgs/MessageComposer.h" #include "gui/settings/AddFileAssociationDialog.h" +#include "gui/gxschannels/GxsChannelDialog.h" #include "gui/settings/rsharesettings.h" #include "util/QtVersion.h" #include "util/RsAction.h" @@ -61,6 +63,7 @@ #define IMAGE_OPENFOLDER ":/images/folderopen.png" #define IMAGE_OPENFILE ":/images/fileopen.png" #define IMAGE_LIBRARY ":/images/library.png" +#define IMAGE_CHANNEL ":/images/channels32.png" #define IMAGE_COLLCREATE ":/images/library_add.png" #define IMAGE_COLLMODIF ":/images/library_edit.png" #define IMAGE_COLLVIEW ":/images/library_view.png" @@ -154,9 +157,6 @@ SharedFilesDialog::SharedFilesDialog(RetroshareDirModel *_tree_model,RetroshareD connect(notify, SIGNAL(filesPreModChanged(bool)), this, SLOT(preModDirectories(bool))); connect(notify, SIGNAL(filesPostModChanged(bool)), this, SLOT(postModDirectories(bool))); -//== connect(ui.localButton, SIGNAL(toggled(bool)), this, SLOT(showFrame(bool))); -//== connect(ui.remoteButton, SIGNAL(toggled(bool)), this, SLOT(showFrameRemote(bool))); -//== connect(ui.splittedButton, SIGNAL(toggled(bool)), this, SLOT(showFrameSplitted(bool))); connect(ui.viewType_CB, SIGNAL(currentIndexChanged(int)), this, SLOT(changeCurrentViewModel(int))); connect( ui.dirTreeView, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( spawnCustomPopupMenu( QPoint ) ) ); @@ -511,14 +511,12 @@ void RemoteSharedFilesDialog::spawnCustomPopupMenu( QPoint point ) connect( downloadAct , SIGNAL( triggered() ), this, SLOT( downloadRemoteSelected() ) ) ; contextMnu.addAction( downloadAct) ; - //if ( type == DIR_TYPE_FILE ) - { - contextMnu.addSeparator() ;//------------------------------------ - contextMnu.addAction( copylinkAct) ; - contextMnu.addAction( sendlinkAct) ; - contextMnu.addSeparator() ;//------------------------------------ - contextMnu.addAction(QIcon(IMAGE_MSG), tr("Recommend in a message to..."), this, SLOT(recommendFilesToMsg())) ; - } + contextMnu.addSeparator() ;//------------------------------------ + contextMnu.addAction( copylinkAct) ; + contextMnu.addAction( sendlinkAct) ; + contextMnu.addSeparator() ;//------------------------------------ + contextMnu.addAction(QIcon(IMAGE_MSG), tr("Recommend in a message to..."), this, SLOT(recommendFilesToMsg())) ; + contextMnu.addSeparator() ;//------------------------------------ contextMnu.addMenu(&collectionMenu) ; @@ -557,22 +555,20 @@ void RemoteSharedFilesDialog::downloadRemoteSelected() model -> downloadSelected(lst) ; } -void SharedFilesDialog::copyLink (const QModelIndexList& lst, bool remote) +void SharedFilesDialog::copyLinks(const QModelIndexList& lst, bool remote,QList& urls,bool& has_unhashed_files) { - std::vector dirVec; + std::vector dirVec; - model->getDirDetailsFromSelect(lst, dirVec); + model->getDirDetailsFromSelect(lst, dirVec); - QList urls ; + has_unhashed_files = false; - bool has_unhashed_files = false; + for (int i = 0, n = dirVec.size(); i < n; ++i) + { + const DirDetails& details = dirVec[i]; - for (int i = 0, n = dirVec.size(); i < n; ++i) - { - const DirDetails& details = dirVec[i]; - - if (details.type == DIR_TYPE_DIR) - { + if (details.type == DIR_TYPE_DIR) + { FileTree *ft = FileTree::create(details,remote) ; std::cerr << "Created collection file tree:" << std::endl; @@ -586,48 +582,32 @@ void SharedFilesDialog::copyLink (const QModelIndexList& lst, bool remote) urls.push_back(link) ; delete ft ; -#ifdef TO_REMOVE - for(uint32_t j=0;jRequestDirDetails(dirStub.ref, details, flags) || details.type != DIR_TYPE_FILE) - continue; - - if(details.hash.isNull()) - { - has_unhashed_files = true; - continue; - } - - RetroShareLink link = RetroShareLink::createFile(QString::fromUtf8(details.name.c_str()), details.count, details.hash.toStdString().c_str()); - if (link.valid()) { - urls.push_back(link) ; - } - } -#endif - } - else - { - if(details.hash.isNull()) + } + else + { + if(details.hash.isNull()) { has_unhashed_files = true; continue; } - RetroShareLink link = RetroShareLink::createFile(QString::fromUtf8(details.name.c_str()), details.count, details.hash.toStdString().c_str()); - if (link.valid()) { - urls.push_back(link) ; - } - } - } + RetroShareLink link = RetroShareLink::createFile(QString::fromUtf8(details.name.c_str()), details.count, details.hash.toStdString().c_str()); + if (link.valid()) { + urls.push_back(link) ; + } + } + } +} + +void SharedFilesDialog::copyLink (const QModelIndexList& lst, bool remote) +{ + QList urls ; + bool has_unhashed_files = false; + + copyLinks(lst,remote,urls,has_unhashed_files) ; RSLinkClipboard::copyLinks(urls) ; if(has_unhashed_files) - QMessageBox::warning(NULL,tr("Some files have been omitted"),tr("Some files have been omitted because their hash is not available yet.")) ; + QMessageBox::warning(NULL,tr("Some files have been omitted"),tr("Some files have been omitted because they have not been indexed yet.")) ; } void SharedFilesDialog::copyLink() @@ -1036,7 +1016,44 @@ void LocalSharedFilesDialog::spawnCustomPopupMenu( QPoint point ) return ; } - contextMnu.exec(QCursor::pos()) ; + GxsChannelDialog *channelDialog = dynamic_cast(MainWindow::getPage(MainWindow::Channels)); + + if(channelDialog != NULL) + { + QMenu shareChannelMenu(tr("Share on channel...")) ; + shareChannelMenu.setIcon(QIcon(IMAGE_CHANNEL)); + + std::list grp_metas ; + channelDialog->getGroupList(grp_metas) ; + + for(auto it(grp_metas.begin());it!=grp_metas.end();++it) + if(IS_GROUP_PUBLISHER((*it).mSubscribeFlags)) + shareChannelMenu.addAction(QString::fromUtf8((*it).mGroupName.c_str()), this, SLOT(shareOnChannel()))->setData(QString::fromStdString((*it).mGroupId.toStdString())) ; + + contextMnu.addMenu(&shareChannelMenu) ; + contextMnu.exec(QCursor::pos()) ; // added here because the shareChannelMenu QMenu object is deleted afterwards + } + else + contextMnu.exec(QCursor::pos()) ; +} + +void LocalSharedFilesDialog::shareOnChannel() +{ + RsGxsGroupId groupId(qobject_cast(sender())->data().toString().toStdString()); + + GxsChannelDialog *channelDialog = dynamic_cast(MainWindow::getPage(MainWindow::Channels)); + + if(channelDialog == NULL) + return ; + + std::list files_info ; + + QList file_links_list ; + bool has_unhashed_files ; + + copyLinks(getSelected(),false,file_links_list,has_unhashed_files) ; + + channelDialog->shareOnChannel(groupId,file_links_list) ; } //============================================================================ diff --git a/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.h b/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.h index e7ec1e2b0..885bab91a 100644 --- a/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.h +++ b/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.h @@ -24,6 +24,7 @@ #include #include "RsAutoUpdatePage.h" +#include "gui/RetroShareLink.h" #include "ui_SharedFilesDialog.h" class RetroshareDirModel; @@ -68,10 +69,6 @@ private slots: void collView(); void collOpen(); -//== void showFrame(bool show); -//== void showFrameRemote(bool show); -//== void showFrameSplitted(bool show); - void recommendFilesToMsg(); void indicatorChanged(int index); @@ -103,6 +100,7 @@ protected: //QMenu* contextMnu2; + void copyLinks(const QModelIndexList& lst, bool remote, QList& urls, bool& has_unhashed_files); void copyLink (const QModelIndexList& lst, bool remote); void FilterItems(); @@ -161,6 +159,7 @@ class LocalSharedFilesDialog : public SharedFilesDialog void runCommandForFile(); void tryToAddNewAssotiation(); void forceCheck(); + void shareOnChannel(); QAction* fileAssotiationAction(const QString fileName); diff --git a/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.cpp b/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.cpp index 998f01a6e..25f6bf2b6 100644 --- a/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.cpp +++ b/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.cpp @@ -121,6 +121,13 @@ GxsGroupFrameDialog::~GxsGroupFrameDialog() delete(ui); } +void GxsGroupFrameDialog::getGroupList(std::list& group_list) +{ + group_list = mCachedGroupMetas ; + + if(group_list.empty()) + requestGroupSummary(); +} void GxsGroupFrameDialog::initUi() { registerHelpButton(ui->helpButton, getHelpString(),pageName()) ; @@ -927,6 +934,8 @@ void GxsGroupFrameDialog::loadGroupSummary(const uint32_t &token) RsUserdata *userdata = NULL; loadGroupSummaryToken(token, groupInfo, userdata); + mCachedGroupMetas = groupInfo ; + insertGroupsData(groupInfo, userdata); mStateHelper->setLoading(TOKEN_TYPE_GROUP_SUMMARY, false); diff --git a/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.h b/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.h index 8138cc1e1..2c0dca594 100644 --- a/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.h +++ b/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.h @@ -81,6 +81,8 @@ public: virtual QString getHelpString() const =0; + virtual void getGroupList(std::list& groups) ; + protected: virtual void showEvent(QShowEvent *event); virtual void updateDisplay(bool complete); @@ -197,6 +199,8 @@ private: /** Qt Designer generated object */ Ui::GxsGroupFrameDialog *ui; + + std::list mCachedGroupMetas; }; #endif diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelDialog.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelDialog.cpp index 1bd22504e..a3fa824f6 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelDialog.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelDialog.cpp @@ -76,6 +76,11 @@ UserNotify *GxsChannelDialog::getUserNotify(QObject *parent) return new GxsChannelUserNotify(rsGxsChannels, parent); } +void GxsChannelDialog::shareOnChannel(const RsGxsGroupId& channel_id,const QList& file_link) +{ + std::cerr << "Sharing file link on channel " << channel_id << ": Not yet implemented!" << std::endl; +} + QString GxsChannelDialog::text(TextType type) { switch (type) { diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelDialog.h b/retroshare-gui/src/gui/gxschannels/GxsChannelDialog.h index 9915ec362..e1f3c75d0 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelDialog.h +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelDialog.h @@ -42,6 +42,8 @@ public: virtual UserNotify *getUserNotify(QObject *parent); + void shareOnChannel(const RsGxsGroupId& channel_id, const QList& file_link) ; + protected: /* GxsGroupFrameDialog */ virtual RetroShareLink::enumType getLinkType() { return RetroShareLink::TYPE_CHANNEL; } From b6aeacbed4ac50c723a395de47498c00d7e42f43 Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 21 Oct 2017 23:48:27 +0200 Subject: [PATCH 15/19] fixed share on channel code --- .../src/gui/gxschannels/CreateGxsChannelMsg.cpp | 5 +++++ .../src/gui/gxschannels/CreateGxsChannelMsg.h | 1 + .../src/gui/gxschannels/GxsChannelDialog.cpp | 12 +++++++++++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/retroshare-gui/src/gui/gxschannels/CreateGxsChannelMsg.cpp b/retroshare-gui/src/gui/gxschannels/CreateGxsChannelMsg.cpp index f21fd8660..89c1a3a4e 100644 --- a/retroshare-gui/src/gui/gxschannels/CreateGxsChannelMsg.cpp +++ b/retroshare-gui/src/gui/gxschannels/CreateGxsChannelMsg.cpp @@ -411,6 +411,11 @@ void CreateGxsChannelMsg::addExtraFile() } } +void CreateGxsChannelMsg::addHtmlText(const QString& text) +{ + msgEdit->setHtml(text) ; +} + void CreateGxsChannelMsg::addAttachment(const std::string &path) { /* add a SubFileItem to the attachment section */ diff --git a/retroshare-gui/src/gui/gxschannels/CreateGxsChannelMsg.h b/retroshare-gui/src/gui/gxschannels/CreateGxsChannelMsg.h index 4a99ad9aa..5168c6226 100644 --- a/retroshare-gui/src/gui/gxschannels/CreateGxsChannelMsg.h +++ b/retroshare-gui/src/gui/gxschannels/CreateGxsChannelMsg.h @@ -43,6 +43,7 @@ public: /** Default Destructor */ ~CreateGxsChannelMsg(); + void addHtmlText(const QString& text) ; void addAttachment(const std::string &path); void addAttachment(const RsFileHash &hash, const std::string &fname, uint64_t size, bool local, const RsPeerId &srcId,bool assume_file_ready = false); diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelDialog.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelDialog.cpp index a3fa824f6..c011621a8 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelDialog.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelDialog.cpp @@ -27,6 +27,7 @@ #include "GxsChannelDialog.h" #include "GxsChannelGroupDialog.h" #include "GxsChannelPostsWidget.h" +#include "CreateGxsChannelMsg.h" #include "GxsChannelUserNotify.h" #include "gui/gxs/GxsGroupShareKey.h" #include "gui/feeds/GxsChannelPostItem.h" @@ -76,9 +77,18 @@ UserNotify *GxsChannelDialog::getUserNotify(QObject *parent) return new GxsChannelUserNotify(rsGxsChannels, parent); } -void GxsChannelDialog::shareOnChannel(const RsGxsGroupId& channel_id,const QList& file_link) +void GxsChannelDialog::shareOnChannel(const RsGxsGroupId& channel_id,const QList& file_links) { std::cerr << "Sharing file link on channel " << channel_id << ": Not yet implemented!" << std::endl; + + CreateGxsChannelMsg *msgDialog = new CreateGxsChannelMsg(channel_id) ; + + QString txt ; + for(QList::const_iterator it(file_links.begin());it!=file_links.end();++it) + txt += (*it).toHtml() + "\n" ; + + msgDialog->addHtmlText(txt); + msgDialog->show(); } QString GxsChannelDialog::text(TextType type) From ee2120a5bce5dcf1b2f9a512a9c38f8545215c02 Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 22 Oct 2017 17:36:19 +0200 Subject: [PATCH 16/19] fixed bug causing FileTree links to open empty --- retroshare-gui/src/gui/common/RsCollection.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/retroshare-gui/src/gui/common/RsCollection.cpp b/retroshare-gui/src/gui/common/RsCollection.cpp index 8fdbd4e0f..14f522531 100644 --- a/retroshare-gui/src/gui/common/RsCollection.cpp +++ b/retroshare-gui/src/gui/common/RsCollection.cpp @@ -48,12 +48,18 @@ RsCollection::RsCollection(QObject *parent) RsCollection::RsCollection(const FileTree& fr) : _xml_doc("RsCollection") { + _root = _xml_doc.createElement("RsCollection"); + _xml_doc.appendChild(_root); + recursAddElements(_xml_doc,fr,0,_root) ; } RsCollection::RsCollection(const std::vector& file_infos, QObject *parent) : QObject(parent), _xml_doc("RsCollection") { + _root = _xml_doc.createElement("RsCollection"); + _xml_doc.appendChild(_root); + for(uint32_t i = 0;i Date: Sun, 22 Oct 2017 18:28:36 +0200 Subject: [PATCH 17/19] added means to select download directory in RsCollectionDialog --- .../src/gui/common/RsCollectionDialog.cpp | 56 ++++++++++++++++++- .../src/gui/common/RsCollectionDialog.h | 3 + .../src/gui/common/RsCollectionDialog.ui | 40 +++++++------ 3 files changed, 82 insertions(+), 17 deletions(-) diff --git a/retroshare-gui/src/gui/common/RsCollectionDialog.cpp b/retroshare-gui/src/gui/common/RsCollectionDialog.cpp index b73191fec..e78fbdf08 100644 --- a/retroshare-gui/src/gui/common/RsCollectionDialog.cpp +++ b/retroshare-gui/src/gui/common/RsCollectionDialog.cpp @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -50,6 +51,7 @@ #define MAX_FILE_ADDED_BEFORE_ASK 500 //Number of file added in Recursive mode before asking to continue +#define IMAGE_SEARCH ":/icons/svg/magnifying-glass.svg" /** * @brief The FSMSortFilterProxyModel class sort directory before file. @@ -140,9 +142,21 @@ RsCollectionDialog::RsCollectionDialog(const QString& collectionFileName ui.headerFrame->setHeaderImage(QPixmap(":/images/library64.png")); if(creation) + { ui.headerFrame->setHeaderText(tr("Collection Editor")); + ui.downloadFolder_LE->hide(); + ui.downloadFolder_LB->hide(); + } else + { ui.headerFrame->setHeaderText(tr("Download files")); + ui.downloadFolder_LE->show(); + ui.downloadFolder_LB->show(); + + ui.downloadFolder_LE->setText(QString::fromUtf8(rsFiles->getDownloadDirectory().c_str())) ; + + QObject::connect(ui.downloadFolder_LE,SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(openDestinationDirectoryMenu(QPoint))); + } // 1 - add all elements to the list. @@ -213,6 +227,46 @@ RsCollectionDialog::RsCollectionDialog(const QString& collectionFileName QMessageBox::warning(NULL,tr("Bad filenames have been cleaned"),tr("Some filenames or directory names contained forbidden characters.\nCharacters \",|,/,\\,<,>,*,? will be replaced by '_'.\n Concerned files are listed in red.")) ; } +void RsCollectionDialog::openDestinationDirectoryMenu(QPoint) +{ + QMenu contextMnu( this ); + + // pop a menu with existing entries and also a custom entry + // Now get the list of existing directories. + + std::list< SharedDirInfo> dirs ; + rsFiles->getSharedDirectories( dirs) ; + + for (std::list::const_iterator it(dirs.begin());it!=dirs.end();++it){ + // Check for existence of directory name + QFile directory( QString::fromUtf8((*it).filename.c_str())) ; + + if (!directory.exists()) continue ; + if (!(directory.permissions() & QFile::WriteOwner)) continue ; + + contextMnu.addAction(QString::fromUtf8((*it).filename.c_str()), this, SLOT(setDestinationDirectory()))->setData(QString::fromUtf8( (*it).filename.c_str() ) ) ; + } + + contextMnu.addAction( QIcon(IMAGE_SEARCH),tr("Specify..."),this,SLOT(chooseDestinationDirectory())); + + contextMnu.exec(QCursor::pos()) ; +} + +void RsCollectionDialog::setDestinationDirectory() +{ + QString dest_dir(qobject_cast(sender())->data().toString()) ; + ui.downloadFolder_LE->setText(dest_dir) ; +} + +void RsCollectionDialog::chooseDestinationDirectory() +{ + QString dest_dir = QFileDialog::getExistingDirectory(this,tr("Choose directory")) ; + + if(dest_dir.isNull()) + return ; + + ui.downloadFolder_LE->setText(dest_dir) ; +} /** * @brief RsCollectionDialog::~RsCollectionDialog */ @@ -1226,7 +1280,7 @@ void RsCollectionDialog::download() { std::cerr << "Downloading!" << std::endl; - QString dldir = QString::fromUtf8(rsFiles->getDownloadDirectory().c_str()) ; + QString dldir = ui.downloadFolder_LE->text(); std::cerr << "downloading all these files:" << std::endl; diff --git a/retroshare-gui/src/gui/common/RsCollectionDialog.h b/retroshare-gui/src/gui/common/RsCollectionDialog.h index bac5289b4..7ecf9b6da 100644 --- a/retroshare-gui/src/gui/common/RsCollectionDialog.h +++ b/retroshare-gui/src/gui/common/RsCollectionDialog.h @@ -49,6 +49,9 @@ private slots: void add() ; void addRecursive() ; void remove() ; + void chooseDestinationDirectory(); + void setDestinationDirectory(); + void openDestinationDirectoryMenu(QPoint pt); void processItem(QMap &dirToAdd , int &index , ColFileInfo &parent diff --git a/retroshare-gui/src/gui/common/RsCollectionDialog.ui b/retroshare-gui/src/gui/common/RsCollectionDialog.ui index 78e736c24..a1b2fd275 100644 --- a/retroshare-gui/src/gui/common/RsCollectionDialog.ui +++ b/retroshare-gui/src/gui/common/RsCollectionDialog.ui @@ -6,8 +6,8 @@ 0 0 - 693 - 525 + 969 + 778 @@ -67,19 +67,7 @@ QFrame::Plain - - - 0 - - - 0 - - - 0 - - - 0 - + @@ -403,7 +391,7 @@ - + @@ -424,6 +412,26 @@ + + + + Destination: + + + + + + + Qt::PreventContextMenu + + + Right click to change download directory + + + true + + + From 0359795caeb16e8937d11ac5b608f1772252a0fd Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 22 Oct 2017 20:08:22 +0200 Subject: [PATCH 18/19] fixed regression preventing context menu to open in destination directory for RsCollection --- retroshare-gui/src/gui/common/RsCollectionDialog.ui | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/retroshare-gui/src/gui/common/RsCollectionDialog.ui b/retroshare-gui/src/gui/common/RsCollectionDialog.ui index a1b2fd275..1e867eb2a 100644 --- a/retroshare-gui/src/gui/common/RsCollectionDialog.ui +++ b/retroshare-gui/src/gui/common/RsCollectionDialog.ui @@ -10,6 +10,9 @@ 778 + + Qt::CustomContextMenu + Collection @@ -422,7 +425,7 @@ - Qt::PreventContextMenu + Qt::CustomContextMenu Right click to change download directory From 603ea7e96eed7582221db4bdc27bf0abe94bb06f Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 23 Oct 2017 22:12:52 +0200 Subject: [PATCH 19/19] removed debug info from RsCollection --- retroshare-gui/src/gui/common/RsCollection.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/retroshare-gui/src/gui/common/RsCollection.cpp b/retroshare-gui/src/gui/common/RsCollection.cpp index 14f522531..f92598137 100644 --- a/retroshare-gui/src/gui/common/RsCollection.cpp +++ b/retroshare-gui/src/gui/common/RsCollection.cpp @@ -36,6 +36,8 @@ #include #include +// #define COLLECTION_DEBUG 1 + const QString RsCollection::ExtensionString = QString("rscollection") ; RsCollection::RsCollection(QObject *parent) @@ -116,14 +118,17 @@ void RsCollection::merge_in(const FileTree& tree) void RsCollection::recursCollectColFileInfos(const QDomElement& e,std::vector& colFileInfos,const QString& current_path, bool bad_chars_in_parent) const { QDomNode n = e.firstChild() ; - +#ifdef COLLECTION_DEBUG std::cerr << "Parsing element " << e.tagName().toStdString() << std::endl; +#endif while(!n.isNull()) { QDomElement ee = n.toElement(); // try to convert the node to an element. +#ifdef COLLECTION_DEBUG std::cerr << " Seeing child " << ee.tagName().toStdString() << std::endl; +#endif if(ee.tagName() == QString("File")) {