Skip to content

Commit

Permalink
Add option to open torrent's file or download directory on double cli…
Browse files Browse the repository at this point in the history
…ck (#128)
  • Loading branch information
equeim committed Nov 27, 2023
1 parent 04fa479 commit 30e798c
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 10 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

## [Unreleased]
### Added
- Add support of xdg-activation protocol on Wayland with Qt < 6.3
- Support of xdg-activation protocol on Wayland with Qt < 6.3
- Option to open torrent's file or download directory on double click

### Changed
- "Open" and "Show in file manager" actions now show error dialog if file/directory does not exist,
Expand Down
11 changes: 10 additions & 1 deletion src/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@

#include "log/log.h"
#include "target_os.h"
#include "ui/systemcolorsprovider.h"

SPECIALIZE_FORMATTER_FOR_Q_ENUM(Qt::ToolButtonStyle)
SPECIALIZE_FORMATTER_FOR_Q_ENUM(tremotesf::TorrentsProxyModel::StatusFilter)
SPECIALIZE_FORMATTER_FOR_Q_ENUM(tremotesf::Settings::DarkThemeMode)
SPECIALIZE_FORMATTER_FOR_Q_ENUM(tremotesf::Settings::TorrentDoubleClickAction)

#define SETTINGS_PROPERTY_DEF_IMPL(type, getter, setterType, setter, key, defaultValue) \
type Settings::getter() const { return getValue<type>(mSettings, key, defaultValue); } \
Expand Down Expand Up @@ -196,6 +196,13 @@ namespace tremotesf {
Settings::DarkThemeMode, darkThemeMode, setDarkThemeMode, "darkThemeMode", Settings::DarkThemeMode::FollowSystem
)
SETTINGS_PROPERTY_DEF_TRIVIAL(bool, useSystemAccentColor, setUseSystemAccentColor, "useSystemAccentColor", true)
SETTINGS_PROPERTY_DEF_TRIVIAL(
Settings::TorrentDoubleClickAction,
torrentDoubleClickAction,
setTorrentDoubleClickAction,
"torrentDoubleClickAction",
Settings::TorrentDoubleClickAction::OpenPropertiesDialog
)

Settings::Settings(QObject* parent) : QObject(parent) {
if constexpr (isTargetOsWindows) {
Expand All @@ -214,11 +221,13 @@ namespace tremotesf {
qRegisterMetaType<TorrentData::Priority>();
qRegisterMetaType<TorrentsProxyModel::StatusFilter>();
qRegisterMetaType<Settings::DarkThemeMode>();
qRegisterMetaType<Settings::TorrentDoubleClickAction>();
#if QT_VERSION_MAJOR < 6
qRegisterMetaTypeStreamOperators<Qt::ToolButtonStyle>();
qRegisterMetaTypeStreamOperators<TorrentData::Priority>();
qRegisterMetaTypeStreamOperators<TorrentsProxyModel::StatusFilter>();
qRegisterMetaTypeStreamOperators<Settings::DarkThemeMode>();
qRegisterMetaTypeStreamOperators<Settings::TorrentDoubleClickAction>();
#endif
}

Expand Down
8 changes: 8 additions & 0 deletions src/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,16 @@ namespace tremotesf {
enum class DarkThemeMode { FollowSystem, On, Off };
Q_ENUM(DarkThemeMode)

enum class TorrentDoubleClickAction {
OpenPropertiesDialog,
OpenTorrentFile,
OpenDownloadDirectory
};
Q_ENUM(TorrentDoubleClickAction)

SETTINGS_PROPERTY_TRIVIAL(Settings::DarkThemeMode, darkThemeMode, setDarkThemeMode)
SETTINGS_PROPERTY_TRIVIAL(bool, useSystemAccentColor, setUseSystemAccentColor)
SETTINGS_PROPERTY_TRIVIAL(Settings::TorrentDoubleClickAction, torrentDoubleClickAction, setTorrentDoubleClickAction)

public:
static Settings* instance();
Expand Down
21 changes: 19 additions & 2 deletions src/ui/screens/mainwindow/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ namespace tremotesf {
&mTorrentsView,
&TorrentsView::activated,
this,
&MainWindow::Impl::showTorrentsPropertiesDialogs
&MainWindow::Impl::performTorrentDoubleClickAction
);

setupTorrentsPlaceholder(torrentsViewLayout);
Expand Down Expand Up @@ -328,7 +328,8 @@ namespace tremotesf {
QAction mAddTorrentFileAction{
QIcon::fromTheme("list-add"_l1),
//: Menu item
qApp->translate("tremotesf", "&Add Torrent File...")};
qApp->translate("tremotesf", "&Add Torrent File...")
};
QAction mAddTorrentLinkAction{
QIcon::fromTheme("insert-link"_l1),
//: Menu item
Expand Down Expand Up @@ -801,6 +802,22 @@ namespace tremotesf {
mOpenTorrentDownloadDirectoryAction->setEnabled(localOrMounted);
}

void performTorrentDoubleClickAction() {
switch (Settings::instance()->torrentDoubleClickAction()) {
case Settings::TorrentDoubleClickAction::OpenPropertiesDialog:
showTorrentsPropertiesDialogs();
break;
case Settings::TorrentDoubleClickAction::OpenTorrentFile:
openTorrentsFiles();
break;
case Settings::TorrentDoubleClickAction::OpenDownloadDirectory:
showTorrentsInFileManager();
break;
default:
break;
}
}

void showTorrentsPropertiesDialogs() {
const QModelIndexList selectedRows(mTorrentsView.selectionModel()->selectedRows());

Expand Down
63 changes: 57 additions & 6 deletions src/ui/screens/settingsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "settingsdialog.h"

#include <array>
#include <QCheckBox>
#include <QComboBox>
#include <QCoreApplication>
Expand All @@ -22,6 +23,21 @@
#include "ui/systemcolorsprovider.h"

namespace tremotesf {
namespace {
constexpr std::array torrentDoubleClickActionComboBoxValues{
Settings::TorrentDoubleClickAction::OpenPropertiesDialog,
Settings::TorrentDoubleClickAction::OpenTorrentFile,
Settings::TorrentDoubleClickAction::OpenDownloadDirectory
};

Settings::TorrentDoubleClickAction torrentDoubleClickActionFromComboBoxIndex(int index) {
if (index == -1) {
return Settings::TorrentDoubleClickAction::OpenPropertiesDialog;
}
return torrentDoubleClickActionComboBoxValues.at(static_cast<size_t>(index));
}
}

SettingsDialog::SettingsDialog(QWidget* parent) : QDialog(parent) {
//: Dialog title
setWindowTitle(qApp->translate("tremotesf", "Options"));
Expand All @@ -36,6 +52,7 @@ namespace tremotesf {
//: Options section
auto appearanceGroupBox = new QGroupBox(qApp->translate("tremotesf", "Appearance"), this);
auto appearanceGroupBoxLayout = new QFormLayout(appearanceGroupBox);
appearanceGroupBoxLayout->setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow);

darkThemeComboBox = new QComboBox(this);
//: Dark theme mode
Expand Down Expand Up @@ -102,6 +119,33 @@ namespace tremotesf {

layout->addWidget(addTorrentsGroupBox);

//: Options section
auto otherBehaviourGroupBox = new QGroupBox(qApp->translate("tremotesf", "Other behaviour"), this);
layout->addWidget(otherBehaviourGroupBox);
auto otherBehaviourGroupBoxLayout = new QFormLayout(otherBehaviourGroupBox);
otherBehaviourGroupBoxLayout->setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow);

auto torrentDoubleClickActionComboBox = new QComboBox(this);
for (const auto action : torrentDoubleClickActionComboBoxValues) {
switch (action) {
case Settings::TorrentDoubleClickAction::OpenPropertiesDialog:
torrentDoubleClickActionComboBox->addItem(qApp->translate("tremotesf", "Open properties dialog"));
break;
case Settings::TorrentDoubleClickAction::OpenTorrentFile:
torrentDoubleClickActionComboBox->addItem(qApp->translate("tremotesf", "Open torrent's file"));
break;
case Settings::TorrentDoubleClickAction::OpenDownloadDirectory:
torrentDoubleClickActionComboBox->addItem(qApp->translate("tremotesf", "Open download directory"));
break;
default:
break;
}
}
otherBehaviourGroupBoxLayout->addRow(
qApp->translate("tremotesf", "What to do when torrent in the list is double clicked:"),
torrentDoubleClickActionComboBox
);

//: Options section
auto notificationsGroupBox = new QGroupBox(qApp->translate("tremotesf", "Notifications"), this);
auto notificationsGroupBoxLayout = new QVBoxLayout(notificationsGroupBox);
Expand Down Expand Up @@ -167,12 +211,16 @@ namespace tremotesf {

auto settings = Settings::instance();
connectOnStartupCheckBox->setChecked(settings->connectOnStartup());
notificationOnDisconnectingCheckBox->setChecked(settings->notificationOnDisconnecting());
notificationOnAddingTorrentCheckBox->setChecked(settings->notificationOnAddingTorrent());
notificationOfFinishedTorrentsCheckBox->setChecked(settings->notificationOfFinishedTorrents());
rememberOpenTorrentDirCheckbox->setChecked(settings->rememberOpenTorrentDir());
rememberAddTorrentParameters->setChecked(settings->rememberAddTorrentParameters());
torrentDoubleClickActionComboBox->setCurrentIndex(
// NOLINTNEXTLINE(bugprone-unchecked-optional-access)
indexOfCasted<int>(torrentDoubleClickActionComboBoxValues, settings->torrentDoubleClickAction()).value()
);
fillTorrentLinkFromKeyboardCheckBox->setChecked(settings->fillTorrentLinkFromClipboard());
notificationOnDisconnectingCheckBox->setChecked(settings->notificationOnDisconnecting());
notificationOnAddingTorrentCheckBox->setChecked(settings->notificationOnAddingTorrent());
notificationOfFinishedTorrentsCheckBox->setChecked(settings->notificationOfFinishedTorrents());
trayIconCheckBox->setChecked(settings->showTrayIcon());
addedSinceLastConnectionCheckBox->setChecked(settings->notificationsOnAddedTorrentsSinceLastConnection());
finishedSinceLastConnectionCheckBox->setChecked(settings->notificationsOnFinishedTorrentsSinceLastConnection());
Expand All @@ -190,6 +238,12 @@ namespace tremotesf {
QObject::connect(this, &SettingsDialog::accepted, this, [=] {
auto settings = Settings::instance();
settings->setConnectOnStartup(connectOnStartupCheckBox->isChecked());
settings->setRememberOpenTorrentDir(rememberOpenTorrentDirCheckbox->isChecked());
settings->setRememberTorrentAddParameters(rememberAddTorrentParameters->isChecked());
settings->setFillTorrentLinkFromClipboard(fillTorrentLinkFromKeyboardCheckBox->isChecked());
settings->setTorrentDoubleClickAction(
torrentDoubleClickActionFromComboBoxIndex(torrentDoubleClickActionComboBox->currentIndex())
);
settings->setNotificationOnDisconnecting(notificationOnDisconnectingCheckBox->isChecked());
settings->setNotificationOnAddingTorrent(notificationOnAddingTorrentCheckBox->isChecked());
settings->setNotificationOfFinishedTorrents(notificationOfFinishedTorrentsCheckBox->isChecked());
Expand All @@ -198,9 +252,6 @@ namespace tremotesf {
settings->setNotificationsOnFinishedTorrentsSinceLastConnection(
finishedSinceLastConnectionCheckBox->isChecked()
);
settings->setRememberOpenTorrentDir(rememberOpenTorrentDirCheckbox->isChecked());
settings->setRememberTorrentAddParameters(rememberAddTorrentParameters->isChecked());
settings->setFillTorrentLinkFromClipboard(fillTorrentLinkFromKeyboardCheckBox->isChecked());
if constexpr (isTargetOsWindows) {
if (const int index = darkThemeComboBox->currentIndex(); index != -1) {
settings->setDarkThemeMode(darkThemeComboBoxValues[static_cast<size_t>(index)]);
Expand Down

0 comments on commit 30e798c

Please sign in to comment.