added code to share a file/dir on channel

This commit is contained in:
csoler 2017-10-21 21:23:40 +02:00
parent edffbc3670
commit 770add8b8a
6 changed files with 98 additions and 62 deletions

View File

@ -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<RetroShareLink>& urls,bool& has_unhashed_files)
{
std::vector<DirDetails> dirVec;
std::vector<DirDetails> dirVec;
model->getDirDetailsFromSelect(lst, dirVec);
model->getDirDetailsFromSelect(lst, dirVec);
QList<RetroShareLink> 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;j<details.children.size();++j)
{
const DirStub& dirStub = details.children[j];
DirDetails details;
FileSearchFlags flags = remote?RS_FILE_HINTS_REMOTE:RS_FILE_HINTS_LOCAL ;
// do not recursive copy sub dirs.
if (!rsFiles->RequestDirDetails(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<RetroShareLink> 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<GxsChannelDialog*>(MainWindow::getPage(MainWindow::Channels));
if(channelDialog != NULL)
{
QMenu shareChannelMenu(tr("Share on channel...")) ;
shareChannelMenu.setIcon(QIcon(IMAGE_CHANNEL));
std::list<RsGroupMetaData> 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<QAction*>(sender())->data().toString().toStdString());
GxsChannelDialog *channelDialog = dynamic_cast<GxsChannelDialog*>(MainWindow::getPage(MainWindow::Channels));
if(channelDialog == NULL)
return ;
std::list<DirDetails> files_info ;
QList<RetroShareLink> file_links_list ;
bool has_unhashed_files ;
copyLinks(getSelected(),false,file_links_list,has_unhashed_files) ;
channelDialog->shareOnChannel(groupId,file_links_list) ;
}
//============================================================================

View File

@ -24,6 +24,7 @@
#include <set>
#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<RetroShareLink>& 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);

View File

@ -121,6 +121,13 @@ GxsGroupFrameDialog::~GxsGroupFrameDialog()
delete(ui);
}
void GxsGroupFrameDialog::getGroupList(std::list<RsGroupMetaData>& 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);

View File

@ -81,6 +81,8 @@ public:
virtual QString getHelpString() const =0;
virtual void getGroupList(std::list<RsGroupMetaData>& 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<RsGroupMetaData> mCachedGroupMetas;
};
#endif

View File

@ -76,6 +76,11 @@ UserNotify *GxsChannelDialog::getUserNotify(QObject *parent)
return new GxsChannelUserNotify(rsGxsChannels, parent);
}
void GxsChannelDialog::shareOnChannel(const RsGxsGroupId& channel_id,const QList<RetroShareLink>& file_link)
{
std::cerr << "Sharing file link on channel " << channel_id << ": Not yet implemented!" << std::endl;
}
QString GxsChannelDialog::text(TextType type)
{
switch (type) {

View File

@ -42,6 +42,8 @@ public:
virtual UserNotify *getUserNotify(QObject *parent);
void shareOnChannel(const RsGxsGroupId& channel_id, const QList<RetroShareLink>& file_link) ;
protected:
/* GxsGroupFrameDialog */
virtual RetroShareLink::enumType getLinkType() { return RetroShareLink::TYPE_CHANNEL; }