Browse Source

Fix torrent file selection in Finder on mac

adaptive-webui-19844
vit9696 7 years ago
parent
commit
d57bd62add
  1. 1
      src/gui/macutilities.h
  2. 13
      src/gui/macutilities.mm
  3. 14
      src/gui/transferlistwidget.cpp

1
src/gui/macutilities.h

@ -36,5 +36,6 @@
QPixmap pixmapForExtension(const QString &ext, const QSize &size); QPixmap pixmapForExtension(const QString &ext, const QSize &size);
void overrideDockClickHandler(bool (*dockClickHandler)(id, SEL, ...)); void overrideDockClickHandler(bool (*dockClickHandler)(id, SEL, ...));
void displayNotification(const QString &title, const QString &message); void displayNotification(const QString &title, const QString &message);
void openFiles(const QSet<QString> &pathsList);
#endif // MACUTILITIES_H #endif // MACUTILITIES_H

13
src/gui/macutilities.mm

@ -28,6 +28,7 @@
#include "macutilities.h" #include "macutilities.h"
#include <QSet>
#include <QtMac> #include <QtMac>
#include <objc/message.h> #include <objc/message.h>
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
@ -81,3 +82,15 @@ void displayNotification(const QString &title, const QString &message)
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification]; [[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification];
} }
} }
void openFiles(const QSet<QString> &pathsList)
{
@autoreleasepool {
NSMutableArray *pathURLs = [NSMutableArray arrayWithCapacity:pathsList.size()];
for (const auto &path : pathsList)
[pathURLs addObject:[NSURL fileURLWithPath:path.toNSString()]];
[[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs:pathURLs];
}
}

14
src/gui/transferlistwidget.cpp

@ -62,6 +62,10 @@
#include "transferlistsortmodel.h" #include "transferlistsortmodel.h"
#include "updownratiodlg.h" #include "updownratiodlg.h"
#ifdef Q_OS_MAC
#include "macutilities.h"
#endif
namespace namespace
{ {
using ToggleFn = std::function<void (Qt::CheckState)>; using ToggleFn = std::function<void (Qt::CheckState)>;
@ -548,6 +552,15 @@ void TransferListWidget::hidePriorityColumn(bool hide)
void TransferListWidget::openSelectedTorrentsFolder() const void TransferListWidget::openSelectedTorrentsFolder() const
{ {
QSet<QString> pathsList; QSet<QString> pathsList;
#ifdef Q_OS_MAC
// On macOS you expect both the files and folders to be opened in their parent
// folders prehilighted for opening, so we use a custom method.
foreach (BitTorrent::TorrentHandle *const torrent, getSelectedTorrents()) {
QString path = torrent->contentPath(true);
pathsList.insert(path);
}
openFiles(pathsList);
#else
foreach (BitTorrent::TorrentHandle *const torrent, getSelectedTorrents()) { foreach (BitTorrent::TorrentHandle *const torrent, getSelectedTorrents()) {
QString path = torrent->contentPath(true); QString path = torrent->contentPath(true);
if (!pathsList.contains(path)) { if (!pathsList.contains(path)) {
@ -558,6 +571,7 @@ void TransferListWidget::openSelectedTorrentsFolder() const
} }
pathsList.insert(path); pathsList.insert(path);
} }
#endif
} }
void TransferListWidget::previewSelectedTorrents() void TransferListWidget::previewSelectedTorrents()

Loading…
Cancel
Save