Merge pull request #1829 from G10h4ck/rsfiles_links

RsFiles links support in libretroshare + a bunch of fixes
This commit is contained in:
G10h4ck 2020-04-20 17:12:04 +02:00 committed by GitHub
commit 2b44492cb6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
77 changed files with 2949 additions and 1667 deletions

View file

@ -623,10 +623,7 @@ void SharedFilesDialog::copyLinks(const QModelIndexList& lst, bool remote,QList<
if (details.type == DIR_TYPE_DIR)
{
FileTree *ft = FileTree::create(details,remote) ;
std::cerr << "Created collection file tree:" << std::endl;
ft->print();
auto ft = RsFileTree::fromDirDetails(details,remote);
QString dir_name = QDir(QString::fromUtf8(details.name.c_str())).dirName();
@ -634,8 +631,6 @@ void SharedFilesDialog::copyLinks(const QModelIndexList& lst, bool remote,QList<
if(link.valid())
urls.push_back(link) ;
delete ft ;
}
else
{

View file

@ -1076,30 +1076,36 @@ TransfersDialog::TransfersDialog(QWidget *parent)
// load settings
processSettings(true);
int S = QFontMetricsF(font()).height();
QString help_str = tr(
" <h1><img width=\"%1\" src=\":/icons/help_64.png\">&nbsp;&nbsp;File Transfer</h1> \
<p>Retroshare brings two ways of transferring files: direct transfers from your friends, and \
distant anonymous tunnelled transfers. In addition, file transfer is multi-source and allows swarming \
(you can be a source while downloading)</p> \
<p>You can share files using the <img src=\":/images/directoryadd_24x24_shadow.png\" width=%2 /> icon from the left side bar. \
These files will be listed in the My Files tab. You can decide for each friend group whether they can or not see these files \
in their Friends Files tab</p>\
<p>The search tab reports files from your friends' file lists, and distant files that can be reached \
anonymously using the multi-hop tunnelling system.</p> \
").arg(QString::number(2*S)).arg(QString::number(S)) ;
int S = static_cast<int>(QFontMetricsF(font()).height());
QString help_str = tr(
"<h1><img width=\"%1\" src=\":/icons/help_64.png\">&nbsp;&nbsp;"
"File Transfer</h1>"
"<p>Retroshare brings two ways of transferring files: direct "
"transfers from your friends, and distant anonymous tunnelled "
"transfers. In addition, file transfer is multi-source and "
"allows swarming (you can be a source while downloading)</p>"
"<p>You can share files using the "
"<img src=\":/images/directoryadd_24x24_shadow.png\" width=%2 />"
" icon from the left side bar. These files will be listed in "
"the My Files tab. You can decide for each friend group whether"
" they can or not see these files in their Friends Files tab</p>"
"<p>The search tab reports files from your friends' file lists,"
" and distant files that can be reached anonymously using the "
"multi-hop tunnelling system.</p>")
.arg(QString::number(2*S)).arg(QString::number(S)) ;
registerHelpButton(ui.helpButton,help_str,"TransfersDialog") ;
registerHelpButton(ui.helpButton,help_str,"TransfersDialog") ;
mEventHandlerId=0;
rsEvents->registerEventsHandler(RsEventType::FILE_TRANSFER, [this](std::shared_ptr<const RsEvent> event) { handleEvent(event); }, mEventHandlerId );
mEventHandlerId=0;
rsEvents->registerEventsHandler(
[this](std::shared_ptr<const RsEvent> event) { handleEvent(event); },
mEventHandlerId, RsEventType::FILE_TRANSFER );
}
void TransfersDialog::handleEvent(std::shared_ptr<const RsEvent> event)
{
if(event->mType != RsEventType::FILE_TRANSFER)
return;
if(event->mType != RsEventType::FILE_TRANSFER) return;
const RsFileTransferEvent *fe = dynamic_cast<const RsFileTransferEvent*>(event.get());
if(!fe)
@ -2225,9 +2231,8 @@ void TransfersDialog::pasteLink()
for(QList<RetroShareLink>::const_iterator it(links.begin());it!=links.end();++it)
{
FileTree *ft = FileTree::create((*it).radix().toStdString()) ;
col.merge_in(*ft) ;
auto ft = RsFileTree::fromRadix64((*it).radix().toStdString());
col.merge_in(*ft);
}
links.clear();
RSLinkClipboard::pasteLinks(links,RetroShareLink::TYPE_FILE);

View file

@ -149,11 +149,17 @@ IdDialog::IdDialog(QWidget *parent) : MainPage(parent), ui(new Ui::IdDialog)
{
ui->setupUi(this);
mEventHandlerId_identity = 0;
rsEvents->registerEventsHandler(RsEventType::GXS_IDENTITY, [this](std::shared_ptr<const RsEvent> event) { RsQThreadUtils::postToObject( [=]() { handleEvent_main_thread(event); }, this ); }, mEventHandlerId_identity );
mEventHandlerId_identity = 0;
rsEvents->registerEventsHandler(
[this](std::shared_ptr<const RsEvent> event)
{ RsQThreadUtils::postToObject([=](){ handleEvent_main_thread(event); }, this); },
mEventHandlerId_identity, RsEventType::GXS_IDENTITY );
mEventHandlerId_circles = 0;
rsEvents->registerEventsHandler(RsEventType::GXS_CIRCLES, [this](std::shared_ptr<const RsEvent> event) { RsQThreadUtils::postToObject( [=]() { handleEvent_main_thread(event); }, this ); }, mEventHandlerId_circles );
mEventHandlerId_circles = 0;
rsEvents->registerEventsHandler(
[this](std::shared_ptr<const RsEvent> event)
{ RsQThreadUtils::postToObject([=](){ handleEvent_main_thread(event); }, this); },
mEventHandlerId_circles, RsEventType::GXS_CIRCLES );
// This is used to grab the broadcast of changes from p3GxsCircles, which is discarded by the current dialog, since it expects data for p3Identity only.
//mCirclesBroadcastBase = new RsGxsUpdateBroadcastBase(rsGxsCircles, this);

View file

@ -67,12 +67,11 @@
* #define NEWS_DEBUG 1
****/
static NewsFeed *instance = NULL;
static NewsFeed* instance = nullptr;
/** Constructor */
NewsFeed::NewsFeed(QWidget *parent) : MainPage(parent), ui(new Ui::NewsFeed)
{
mEventTypes = {
NewsFeed::NewsFeed(QWidget *parent) : MainPage(parent), ui(new Ui::NewsFeed),
mEventTypes({
RsEventType::AUTHSSL_CONNECTION_AUTENTICATION,
RsEventType::PEER_CONNECTION ,
RsEventType::GXS_CIRCLES ,
@ -80,12 +79,14 @@ NewsFeed::NewsFeed(QWidget *parent) : MainPage(parent), ui(new Ui::NewsFeed)
RsEventType::GXS_FORUMS ,
RsEventType::GXS_POSTED ,
RsEventType::MAIL_STATUS
};
for(uint32_t i=0;i<mEventTypes.size();++i)
})
{
for(uint32_t i=0;i<mEventTypes.size();++i)
{
mEventHandlerIds.push_back(0); // needed to force intialization by registerEventsHandler()
rsEvents->registerEventsHandler(mEventTypes[i], [this](std::shared_ptr<const RsEvent> event) { handleEvent(event); }, mEventHandlerIds.back() );
rsEvents->registerEventsHandler(
[this](std::shared_ptr<const RsEvent> event) { handleEvent(event); },
mEventHandlerIds.back(), mEventTypes[i] );
}
/* Invoke the Qt Designer generated object setup routine */

View file

@ -41,13 +41,14 @@ public:
};
/** Constructor */
PostedDialog::PostedDialog(QWidget *parent)
: GxsGroupFrameDialog(rsPosted, parent)
PostedDialog::PostedDialog(QWidget *parent):
GxsGroupFrameDialog(rsPosted, parent), mEventHandlerId(0)
{
mEventHandlerId = 0;
// Needs to be asynced because this function is likely to be called by another thread!
rsEvents->registerEventsHandler(RsEventType::GXS_POSTED, [this](std::shared_ptr<const RsEvent> event) { RsQThreadUtils::postToObject( [=]() { handleEvent_main_thread(event); }, this ); }, mEventHandlerId );
// Needs to be asynced because this function is likely to be called by another thread!
rsEvents->registerEventsHandler(
[this](std::shared_ptr<const RsEvent> event)
{ RsQThreadUtils::postToObject( [=]() { handleEvent_main_thread(event); }, this ); },
mEventHandlerId, RsEventType::GXS_POSTED );
}
void PostedDialog::handleEvent_main_thread(std::shared_ptr<const RsEvent> event)

View file

@ -107,9 +107,11 @@ PostedListWidget::PostedListWidget(const RsGxsGroupId &postedId, QWidget *parent
processSettings(true);
mEventHandlerId = 0;
// Needs to be asynced because this function is likely to be called by another thread!
rsEvents->registerEventsHandler(RsEventType::GXS_POSTED, [this](std::shared_ptr<const RsEvent> event) { RsQThreadUtils::postToObject( [=]() { handleEvent_main_thread(event); }, this ); }, mEventHandlerId );
// Needs to be asynced because this function is called by another thread!
rsEvents->registerEventsHandler(
[this](std::shared_ptr<const RsEvent> event)
{ RsQThreadUtils::postToObject( [=]() { handleEvent_main_thread(event); }, this ); },
mEventHandlerId, RsEventType::GXS_POSTED );
/* Initialize GUI */
setGroupId(postedId);

View file

@ -1706,15 +1706,13 @@ static void processList(const QStringList &list, const QString &textSingular, co
}
break;
case TYPE_FILE_TREE:
{
FileTree *ft = FileTree::create(link.radix().toStdString()) ;
RsCollection(*ft).downloadFiles() ;
delete ft;
}
case TYPE_FILE_TREE:
{
auto ft = RsFileTree::fromRadix64(
link.radix().toStdString() );
RsCollection(*ft).downloadFiles();
break;
}
case TYPE_CHAT_ROOM:
{

View file

@ -177,8 +177,10 @@ NewFriendList::NewFriendList(QWidget *parent) : /* RsAutoUpdatePage(5000,parent)
ui->filterLineEdit->setPlaceholderText(tr("Search")) ;
ui->filterLineEdit->showFilterIcon();
mEventHandlerId=0; // forces initialization
rsEvents->registerEventsHandler( RsEventType::PEER_CONNECTION, [this](std::shared_ptr<const RsEvent> e) { handleEvent(e); }, mEventHandlerId );
mEventHandlerId=0; // forces initialization
rsEvents->registerEventsHandler(
[this](std::shared_ptr<const RsEvent> e) { handleEvent(e); },
mEventHandlerId, RsEventType::PEER_CONNECTION );
mModel = new RsFriendListModel();
mProxyModel = new FriendListSortFilterProxyModel(ui->peerTreeWidget->header(),this);

View file

@ -44,7 +44,7 @@ RsCollection::RsCollection(QObject *parent)
_xml_doc.appendChild(_root);
}
RsCollection::RsCollection(const FileTree& fr)
RsCollection::RsCollection(const RsFileTree& fr)
: _xml_doc("RsCollection")
{
_root = _xml_doc.createElement("RsCollection");
@ -153,7 +153,7 @@ void RsCollection::merge_in(const QString& fname,uint64_t size,const RsFileHash&
recursAddElements(_xml_doc,info,_root) ;
}
void RsCollection::merge_in(const FileTree& tree)
void RsCollection::merge_in(const RsFileTree& tree)
{
recursAddElements(_xml_doc,tree,0,_root) ;
}
@ -273,14 +273,14 @@ void RsCollection::recursAddElements(QDomDocument& doc,const ColFileInfo& colFil
}
}
void RsCollection::recursAddElements(QDomDocument& doc,const FileTree& ft,uint32_t index,QDomElement& e) const
void RsCollection::recursAddElements(
QDomDocument& doc, const RsFileTree& ft, uint32_t index,
QDomElement& e ) const
{
std::vector<uint32_t> subdirs ;
std::vector<FileTree::FileData> subfiles ;
std::vector<uint64_t> subdirs;
std::vector<RsFileTree::FileData> subfiles ;
std::string name;
if(!ft.getDirectoryContent(index,name,subdirs,subfiles))
return ;
if(!ft.getDirectoryContent(name, subdirs, subfiles, index)) return;
QDomElement d = doc.createElement("Directory") ;
d.setAttribute(QString("name"),QString::fromUtf8(name.c_str())) ;

View file

@ -62,11 +62,11 @@ public:
RsCollection(QObject *parent = 0) ;
// create from list of files and directories
RsCollection(const std::vector<DirDetails>& file_entries, FileSearchFlags flags, QObject *parent = 0) ;
RsCollection(const FileTree& fr);
RsCollection(const RsFileTree& fr);
virtual ~RsCollection() ;
void merge_in(const QString& fname,uint64_t size,const RsFileHash& hash) ;
void merge_in(const FileTree& tree) ;
void merge_in(const RsFileTree& tree) ;
static const QString ExtensionString ;
@ -99,7 +99,9 @@ private:
void recursAddElements(QDomDocument&, const DirDetails&, QDomElement&, FileSearchFlags flags) const ;
void recursAddElements(QDomDocument&,const ColFileInfo&,QDomElement&) const;
void recursAddElements(QDomDocument& doc,const FileTree& ft,uint32_t index,QDomElement& e) const;
void recursAddElements(
QDomDocument& doc, const RsFileTree& ft, uint32_t index,
QDomElement& e ) const;
void recursCollectColFileInfos(const QDomElement&,std::vector<ColFileInfo>& 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

View file

@ -47,12 +47,14 @@
// };
/** Constructor */
GxsChannelDialog::GxsChannelDialog(QWidget *parent)
: GxsGroupFrameDialog(rsGxsChannels, parent,true)
GxsChannelDialog::GxsChannelDialog(QWidget *parent):
GxsGroupFrameDialog(rsGxsChannels, parent, true), mEventHandlerId(0)
{
mEventHandlerId = 0;
// Needs to be asynced because this function is likely to be called by another thread!
rsEvents->registerEventsHandler(RsEventType::GXS_CHANNELS, [this](std::shared_ptr<const RsEvent> event) { RsQThreadUtils::postToObject( [=]() { handleEvent_main_thread(event); }, this ); }, mEventHandlerId );
// Needs to be asynced because this function is called by another thread!
rsEvents->registerEventsHandler(
[this](std::shared_ptr<const RsEvent> event)
{ RsQThreadUtils::postToObject([=]() { handleEvent_main_thread(event); }, this ); },
mEventHandlerId, RsEventType::GXS_CHANNELS );
}
void GxsChannelDialog::handleEvent_main_thread(std::shared_ptr<const RsEvent> event)

View file

@ -130,9 +130,11 @@ GxsChannelPostsWidget::GxsChannelPostsWidget(const RsGxsGroupId &channelId, QWid
setGroupId(channelId);
mEventHandlerId = 0;
// Needs to be asynced because this function is likely to be called by another thread!
rsEvents->registerEventsHandler(RsEventType::GXS_CHANNELS, [this](std::shared_ptr<const RsEvent> event) { RsQThreadUtils::postToObject( [=]() { handleEvent_main_thread(event); }, this ); }, mEventHandlerId );
// Needs to be asynced because this function is called by another thread!
rsEvents->registerEventsHandler(
[this](std::shared_ptr<const RsEvent> event)
{ RsQThreadUtils::postToObject([=](){ handleEvent_main_thread(event); }, this ); },
mEventHandlerId, RsEventType::GXS_CHANNELS );
}
void GxsChannelPostsWidget::handleEvent_main_thread(std::shared_ptr<const RsEvent> event)

View file

@ -345,10 +345,12 @@ GxsForumThreadWidget::GxsForumThreadWidget(const RsGxsGroupId &forumId, QWidget
ui->threadTreeWidget->enableColumnCustomize(true);
#endif
mEventHandlerId = 0;
// Needs to be asynced because this function is likely to be called by another thread!
rsEvents->registerEventsHandler(RsEventType::GXS_FORUMS, [this](std::shared_ptr<const RsEvent> event) { RsQThreadUtils::postToObject( [=]() { handleEvent_main_thread(event); }, this ); }, mEventHandlerId );
mEventHandlerId = 0;
// Needs to be asynced because this function is called by another thread!
rsEvents->registerEventsHandler(
[this](std::shared_ptr<const RsEvent> event)
{ RsQThreadUtils::postToObject([=](){ handleEvent_main_thread(event); }, this ); },
mEventHandlerId, RsEventType::GXS_FORUMS );
}
void GxsForumThreadWidget::handleEvent_main_thread(std::shared_ptr<const RsEvent> event)

View file

@ -38,14 +38,15 @@ public:
};
/** Constructor */
GxsForumsDialog::GxsForumsDialog(QWidget *parent)
: GxsGroupFrameDialog(rsGxsForums, parent)
GxsForumsDialog::GxsForumsDialog(QWidget *parent) :
GxsGroupFrameDialog(rsGxsForums, parent), mEventHandlerId(0)
{
mCountChildMsgs = true;
mEventHandlerId = 0;
// Needs to be asynced because this function is likely to be called by another thread!
rsEvents->registerEventsHandler(RsEventType::GXS_FORUMS, [this](std::shared_ptr<const RsEvent> event) { RsQThreadUtils::postToObject( [=]() { handleEvent_main_thread(event); }, this ); }, mEventHandlerId );
rsEvents->registerEventsHandler(
[this](std::shared_ptr<const RsEvent> event)
{ RsQThreadUtils::postToObject( [=]() { handleEvent_main_thread(event); }, this ); },
mEventHandlerId, RsEventType::GXS_FORUMS );
}
void GxsForumsDialog::handleEvent_main_thread(std::shared_ptr<const RsEvent> event)

View file

@ -52,8 +52,10 @@ HashingStatus::HashingStatus(QWidget *parent)
hashloader->hide();
statusHashing->hide();
mEventHandlerId=0;
rsEvents->registerEventsHandler(RsEventType::SHARED_DIRECTORIES, [this](std::shared_ptr<const RsEvent> event) { handleEvent(event); }, mEventHandlerId );
mEventHandlerId=0;
rsEvents->registerEventsHandler(
[this](std::shared_ptr<const RsEvent> event) { handleEvent(event); },
mEventHandlerId, RsEventType::SHARED_DIRECTORIES );
}
void HashingStatus::handleEvent(std::shared_ptr<const RsEvent> event)

View file

@ -1,7 +1,7 @@
/*******************************************************************************
* util/RsGxsUpdateBroadcast.cpp *
* *
* Copyright (c) 2014 Retroshare Team <retroshare.project@gmail.com> *
* Copyright (C) 2014-2020 Retroshare Team <contact@retroshare.cc> *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Affero General Public License as *
@ -22,6 +22,7 @@
#include "RsGxsUpdateBroadcast.h"
#include "gui/notifyqt.h"
#include "util/qtthreadsutils.h"
#include <retroshare/rsgxsifacehelper.h>
@ -32,17 +33,20 @@
// now the update notify works through rsnotify and notifyqt
// so the single instance per service is not really needed anymore
QMap<RsGxsIfaceHelper*, RsGxsUpdateBroadcast*> updateBroadcastMap;
static QMap<RsGxsIfaceHelper*, RsGxsUpdateBroadcast*> updateBroadcastMap;
RsGxsUpdateBroadcast::RsGxsUpdateBroadcast(RsGxsIfaceHelper *ifaceImpl) :
QObject(NULL), mIfaceImpl(ifaceImpl)
QObject(nullptr), mIfaceImpl(ifaceImpl), mEventHandlerId(0)
{
mEventHandlerId = 0; // forces initialization in registerEventsHandler()
rsEvents->registerEventsHandler(RsEventType::GXS_CHANGES, [this](std::shared_ptr<const RsEvent> event)
{
onChangesReceived(*dynamic_cast<const RsGxsChanges*>(event.get()));
}, mEventHandlerId );
rsEvents->registerEventsHandler(
[this](std::shared_ptr<const RsEvent> event)
{
RsQThreadUtils::postToObject(
[=]()
{ onChangesReceived(*dynamic_cast<const RsGxsChanges*>(event.get())); },
this );
},
mEventHandlerId, RsEventType::GXS_CHANGES );
}
RsGxsUpdateBroadcast::~RsGxsUpdateBroadcast()

View file

@ -31,7 +31,7 @@ struct RsGxsChanges;
typedef uint32_t TurtleRequestId ;
class RsGxsUpdateBroadcast : public QObject
class RS_DEPRECATED RsGxsUpdateBroadcast : public QObject
{
Q_OBJECT