2016-08-25 00:45:32 +02:00
|
|
|
#include "./dirview.h"
|
|
|
|
#include "./dirbuttonsitemdelegate.h"
|
2020-01-23 20:07:11 +01:00
|
|
|
#include "./helper.h"
|
2016-08-25 00:45:32 +02:00
|
|
|
|
2021-01-25 19:48:11 +01:00
|
|
|
#include <syncthingconnector/syncthingconnection.h>
|
|
|
|
#include <syncthingmodel/syncthingdirectorymodel.h>
|
|
|
|
#include <syncthingmodel/syncthingsortfiltermodel.h>
|
|
|
|
#include <syncthingwidgets/misc/direrrorsdialog.h>
|
2016-09-21 21:09:12 +02:00
|
|
|
|
2017-05-01 03:34:43 +02:00
|
|
|
#include <QClipboard>
|
2016-08-25 00:45:32 +02:00
|
|
|
#include <QGuiApplication>
|
2017-05-01 03:34:43 +02:00
|
|
|
#include <QHeaderView>
|
|
|
|
#include <QMenu>
|
|
|
|
#include <QMouseEvent>
|
2016-08-25 00:45:32 +02:00
|
|
|
|
2016-09-21 21:09:12 +02:00
|
|
|
using namespace Data;
|
|
|
|
|
2016-08-25 00:45:32 +02:00
|
|
|
namespace QtGui {
|
|
|
|
|
2017-05-01 03:34:43 +02:00
|
|
|
DirView::DirView(QWidget *parent)
|
|
|
|
: QTreeView(parent)
|
2016-08-25 00:45:32 +02:00
|
|
|
{
|
|
|
|
header()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
|
|
|
header()->hide();
|
|
|
|
setItemDelegateForColumn(1, new DirButtonsItemDelegate(this));
|
|
|
|
setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
|
connect(this, &DirView::customContextMenuRequested, this, &DirView::showContextMenu);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DirView::mouseReleaseEvent(QMouseEvent *event)
|
|
|
|
{
|
|
|
|
QTreeView::mouseReleaseEvent(event);
|
2018-11-03 17:54:12 +01:00
|
|
|
|
2020-10-18 15:48:02 +02:00
|
|
|
const auto pos = event->pos();
|
2020-10-20 19:16:53 +02:00
|
|
|
const auto clickedRow = ClickedRow(this, pos);
|
|
|
|
if (!clickedRow) {
|
2018-11-03 17:54:12 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-20 19:16:53 +02:00
|
|
|
if (!clickedRow.index.parent().isValid()) {
|
2018-11-03 17:54:12 +01:00
|
|
|
// open/scan dir buttons
|
2020-10-20 19:16:53 +02:00
|
|
|
const QRect itemRect = visualRect(clickedRow.proxyIndex);
|
2018-11-03 17:54:12 +01:00
|
|
|
if (pos.x() <= itemRect.right() - 58) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (pos.x() < itemRect.right() - 34) {
|
2020-10-20 19:16:53 +02:00
|
|
|
if (!clickedRow.data->paused) {
|
|
|
|
emit scanDir(*clickedRow.data);
|
2016-08-25 00:45:32 +02:00
|
|
|
}
|
2018-11-03 17:54:12 +01:00
|
|
|
} else if (pos.x() < itemRect.right() - 17) {
|
2020-10-20 19:16:53 +02:00
|
|
|
emit pauseResumeDir(*clickedRow.data);
|
2018-11-03 17:54:12 +01:00
|
|
|
} else {
|
2020-10-20 19:16:53 +02:00
|
|
|
emit openDir(*clickedRow.data);
|
2016-08-25 00:45:32 +02:00
|
|
|
}
|
2020-10-20 19:16:53 +02:00
|
|
|
} else if (clickedRow.index.row() == 9 && clickedRow.data->pullErrorCount) {
|
|
|
|
auto &connection(*clickedRow.model->connection());
|
|
|
|
connection.requestDirPullErrors(clickedRow.data->id);
|
2018-11-03 21:30:17 +01:00
|
|
|
|
2020-10-20 19:16:53 +02:00
|
|
|
auto *const textViewDlg = new DirectoryErrorsDialog(connection, *clickedRow.data);
|
2018-11-03 17:54:12 +01:00
|
|
|
textViewDlg->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
textViewDlg->show();
|
2016-08-25 00:45:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-20 18:56:20 +02:00
|
|
|
void DirView::showContextMenu(const QPoint &position)
|
2016-08-25 00:45:32 +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(selectedRow.model->data(selectedRow.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 *const dir = 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()));
|
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 path")),
|
2020-10-07 21:34:37 +02:00
|
|
|
&QAction::triggered, copyToClipboard(dir->path));
|
|
|
|
menu.addSeparator();
|
|
|
|
connect(menu.addAction(
|
|
|
|
QIcon::fromTheme(QStringLiteral("view-refresh"), QIcon(QStringLiteral(":/icons/hicolor/scalable/actions/view-refresh.svg"))),
|
|
|
|
tr("Rescan")),
|
|
|
|
&QAction::triggered, triggerActionForSelectedRow(this, &DirView::scanDir));
|
|
|
|
if (dir->paused) {
|
|
|
|
connect(menu.addAction(QIcon::fromTheme(QStringLiteral("media-playback-start"),
|
|
|
|
QIcon(QStringLiteral(":/icons/hicolor/scalable/actions/media-playback-start.svg"))),
|
|
|
|
tr("Resume")),
|
|
|
|
&QAction::triggered, triggerActionForSelectedRow(this, &DirView::pauseResumeDir));
|
|
|
|
} else {
|
|
|
|
connect(menu.addAction(QIcon::fromTheme(QStringLiteral("media-playback-pause"),
|
|
|
|
QIcon(QStringLiteral(":/icons/hicolor/scalable/actions/media-playback-pause.svg"))),
|
|
|
|
tr("Pause")),
|
|
|
|
&QAction::triggered, triggerActionForSelectedRow(this, &DirView::pauseResumeDir));
|
|
|
|
}
|
|
|
|
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, &DirView::openDir));
|
2016-08-25 00:45:32 +02:00
|
|
|
}
|
2020-01-23 20:07:11 +01:00
|
|
|
showViewMenu(position, *this, menu);
|
2016-08-25 00:45:32 +02:00
|
|
|
}
|
|
|
|
|
2017-09-17 21:48:15 +02:00
|
|
|
} // namespace QtGui
|