added context menu with copy link in channel posts files

This commit is contained in:
csoler 2021-01-09 15:40:15 +01:00
parent 453c656570
commit 5a1e6b8b60
4 changed files with 42 additions and 2 deletions

View File

@ -98,6 +98,7 @@ public:
// Helper functions
void clear() ;
bool getFileData(const QModelIndex& i, ChannelPostFileInfo &fmpe) const;
// AbstractItemModel functions.
@ -156,7 +157,6 @@ private:
quintptr getParentRow(quintptr ref,int& row) const;
quintptr getChildRef(quintptr ref, int index) const;
int getChildrenCount(quintptr ref) const;
bool getFileData(const QModelIndex& i, ChannelPostFileInfo &fmpe) const;
static bool convertTabEntryToRefPointer(uint32_t entry, quintptr& ref);
static bool convertRefPointerToTabEntry(quintptr ref,uint32_t& entry);

View File

@ -406,6 +406,9 @@ GxsChannelPostsWidgetWithModel::GxsChannelPostsWidgetWithModel(const RsGxsGroupI
connect(ui->channelPostFiles_TV->header(),SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)), this, SLOT(sortColumnPostFiles(int,Qt::SortOrder)));
connect(ui->channelFiles_TV->header(),SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)), this, SLOT(sortColumnFiles(int,Qt::SortOrder)));
connect(ui->channelPostFiles_TV,SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showChannelFilesContextMenu(QPoint)));
connect(ui->channelFiles_TV,SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showChannelFilesContextMenu(QPoint)));
ui->channelFiles_TV->setModel(mChannelFilesModel = new RsGxsChannelPostFilesModel());
ui->channelFiles_TV->setItemDelegate(mFilesDelegate = new ChannelPostFilesDelegate(this));
ui->channelFiles_TV->setPlaceholderText(tr("No files in the channel, or no channel selected"));
@ -1243,6 +1246,35 @@ void GxsChannelPostsWidgetWithModel::insertChannelDetails(const RsGxsChannelGrou
showPostDetails();
}
void GxsChannelPostsWidgetWithModel::showChannelFilesContextMenu(QPoint p)
{
QMenu contextMnu(this) ;
QAction *action = contextMnu.addAction(QIcon(), tr("Copy Retroshare link"), this, SLOT(copyChannelFilesLink()));
action->setData(QVariant::fromValue(sender()));
contextMnu.exec(QCursor::pos());
}
void GxsChannelPostsWidgetWithModel::copyChannelFilesLink()
{
// Block the popup if no results available
QAction *action = dynamic_cast<QAction*>(sender());
RSTreeView *tree = dynamic_cast<RSTreeView*>(action->data().value<QWidget*>());
QModelIndexList sel = tree->selectionModel()->selection().indexes();
if(sel.empty())
return;
ChannelPostFileInfo file;
if(!static_cast<RsGxsChannelPostFilesModel*>(tree->model())->getFileData(sel.front(),file))
return;
RetroShareLink link = RetroShareLink::createFile(QString::fromUtf8(file.mName.c_str()), file.mSize, QString::fromStdString(file.mHash.toStdString()));
RSLinkClipboard::copyLinks(QList<RetroShareLink>{ link });
}
void GxsChannelPostsWidgetWithModel::setSubscribeButtonText(const RsGxsGroupId& group_id,uint32_t flags, uint32_t mPop)
{
if(IS_GROUP_SUBSCRIBED(flags))

View File

@ -163,6 +163,8 @@ public slots:
void sortColumnFiles(int col,Qt::SortOrder so);
void sortColumnPostFiles(int col,Qt::SortOrder so);
void updateCommentsCount(int n);
void showChannelFilesContextMenu(QPoint p);
void copyChannelFilesLink();
private:
void processSettings(bool load);

View File

@ -181,7 +181,7 @@
<item>
<widget class="QTabWidget" name="channel_TW">
<property name="currentIndex">
<number>0</number>
<number>1</number>
</property>
<widget class="QWidget" name="tab_3">
<attribute name="title">
@ -552,6 +552,9 @@ p, li { white-space: pre-wrap; }
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="RSTreeView" name="channelPostFiles_TV">
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
<property name="editTriggers">
<set>QAbstractItemView::CurrentChanged|QAbstractItemView::SelectedClicked</set>
</property>
@ -602,6 +605,9 @@ p, li { white-space: pre-wrap; }
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<widget class="RSTreeView" name="channelFiles_TV">
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
<property name="editTriggers">
<set>QAbstractItemView::CurrentChanged|QAbstractItemView::SelectedClicked</set>
</property>