From 770add8b8ac5a0eb192d72a934bf77c013838d18 Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 21 Oct 2017 21:23:40 +0200 Subject: [PATCH] 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; }