2016-09-21 21:09:12 +02:00
|
|
|
#include "./downloadview.h"
|
|
|
|
#include "./downloaditemdelegate.h"
|
2020-01-23 20:07:11 +01:00
|
|
|
#include "./helper.h"
|
2016-09-21 21:09:12 +02:00
|
|
|
|
2020-10-07 21:34:37 +02:00
|
|
|
#include "../../connector/syncthingdir.h"
|
2016-09-30 23:55:25 +02:00
|
|
|
#include "../../model/syncthingdownloadmodel.h"
|
2016-09-21 21:09:12 +02:00
|
|
|
|
2017-05-01 03:34:43 +02:00
|
|
|
#include <QClipboard>
|
2016-09-21 21:09:12 +02:00
|
|
|
#include <QGuiApplication>
|
2017-05-01 03:34:43 +02:00
|
|
|
#include <QHeaderView>
|
|
|
|
#include <QMenu>
|
|
|
|
#include <QMouseEvent>
|
2016-09-21 21:09:12 +02:00
|
|
|
|
|
|
|
using namespace Data;
|
|
|
|
|
|
|
|
namespace QtGui {
|
|
|
|
|
2017-05-01 03:34:43 +02:00
|
|
|
DownloadView::DownloadView(QWidget *parent)
|
|
|
|
: QTreeView(parent)
|
2016-09-21 21:09:12 +02:00
|
|
|
{
|
|
|
|
header()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
|
|
|
header()->hide();
|
2016-09-28 00:06:21 +02:00
|
|
|
setItemDelegateForColumn(0, new DownloadItemDelegate(this));
|
2016-09-21 21:09:12 +02:00
|
|
|
setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
|
connect(this, &DownloadView::customContextMenuRequested, this, &DownloadView::showContextMenu);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DownloadView::mouseReleaseEvent(QMouseEvent *event)
|
|
|
|
{
|
|
|
|
QTreeView::mouseReleaseEvent(event);
|
2019-07-27 11:11:36 +02:00
|
|
|
const auto *const dlModel = qobject_cast<const SyncthingDownloadModel *>(model());
|
|
|
|
if (!dlModel) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const QPoint pos(event->pos());
|
|
|
|
const QModelIndex clickedIndex(indexAt(event->pos()));
|
|
|
|
if (!clickedIndex.isValid() || clickedIndex.column() != 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const QRect itemRect(visualRect(clickedIndex));
|
|
|
|
if (pos.x() <= itemRect.right() - 17) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (clickedIndex.parent().isValid()) {
|
|
|
|
if (pos.y() < itemRect.y() + itemRect.height() / 2) {
|
|
|
|
if (const SyncthingItemDownloadProgress *const progress = dlModel->progressInfo(clickedIndex)) {
|
|
|
|
emit openItemDir(*progress);
|
2016-09-21 21:09:12 +02:00
|
|
|
}
|
|
|
|
}
|
2019-07-27 11:11:36 +02:00
|
|
|
} else if (const SyncthingDir *const dir = dlModel->dirInfo(clickedIndex)) {
|
|
|
|
emit openDir(*dir);
|
2016-09-21 21:09:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-20 18:56:20 +02:00
|
|
|
void DownloadView::showContextMenu(const QPoint &position)
|
2016-09-21 21:09:12 +02:00
|
|
|
{
|
2020-10-07 21:34:37 +02:00
|
|
|
const auto selectedRow = SelectedRow(this);
|
|
|
|
const auto &selectedIndex = selectedRow.index;
|
|
|
|
if (!selectedRow) {
|
2019-07-27 11:11:36 +02:00
|
|
|
return;
|
|
|
|
}
|
2019-07-31 22:21:44 +02:00
|
|
|
QMenu menu(this);
|
2020-10-07 21:34:37 +02:00
|
|
|
if (selectedIndex.parent().isValid()) {
|
2019-07-27 11:11:36 +02:00
|
|
|
connect(menu.addAction(QIcon::fromTheme(QStringLiteral("edit-copy"), QIcon(QStringLiteral(":/icons/hicolor/scalable/actions/edit-copy.svg"))),
|
2017-05-01 03:34:43 +02:00
|
|
|
tr("Copy value")),
|
2020-10-07 21:34:37 +02:00
|
|
|
&QAction::triggered, copyToClipboard(model()->data(model()->index(selectedIndex.row(), 1, selectedIndex.parent())).toString()));
|
2019-07-27 11:11:36 +02:00
|
|
|
} else {
|
2020-10-07 21:34:37 +02:00
|
|
|
const auto [dir, progress] = selectedRow.data;
|
2019-07-27 11:11:36 +02:00
|
|
|
connect(menu.addAction(QIcon::fromTheme(QStringLiteral("edit-copy"), QIcon(QStringLiteral(":/icons/hicolor/scalable/actions/edit-copy.svg"))),
|
2017-05-01 03:34:43 +02:00
|
|
|
tr("Copy label/ID")),
|
2020-10-07 21:34:37 +02:00
|
|
|
&QAction::triggered, copyToClipboard(dir->displayName()));
|
|
|
|
menu.addSeparator();
|
|
|
|
connect(menu.addAction(QIcon::fromTheme(QStringLiteral("folder"), QIcon(QStringLiteral(":/icons/hicolor/scalable/places/folder-open.svg"))),
|
|
|
|
tr("Open in file browser")),
|
|
|
|
&QAction::triggered, triggerActionForSelectedRow(this, &DownloadView::emitOpenDir));
|
2016-09-21 21:09:12 +02:00
|
|
|
}
|
2020-01-23 20:07:11 +01:00
|
|
|
showViewMenu(position, *this, menu);
|
2016-09-21 21:09:12 +02:00
|
|
|
}
|
|
|
|
|
2020-10-07 21:34:37 +02:00
|
|
|
void DownloadView::emitOpenDir(QPair<const SyncthingDir *, const SyncthingItemDownloadProgress *> info)
|
2016-09-21 21:09:12 +02:00
|
|
|
{
|
2020-10-07 21:34:37 +02:00
|
|
|
if (info.second) {
|
|
|
|
emit openItemDir(*info.second);
|
2019-07-27 11:11:36 +02:00
|
|
|
} else {
|
2020-10-07 21:34:37 +02:00
|
|
|
emit openDir(*info.first);
|
2016-09-21 21:09:12 +02:00
|
|
|
}
|
|
|
|
}
|
2020-10-07 21:34:37 +02:00
|
|
|
|
2017-09-17 21:48:15 +02:00
|
|
|
} // namespace QtGui
|