Browse Source

Merge pull request #8032 from vit9696/fopen

Fix torrent file selection in Finder on mac
adaptive-webui-19844
sledgehammer999 7 years ago committed by GitHub
parent
commit
ea44923cce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      src/gui/macutilities.h
  2. 16
      src/gui/macutilities.mm
  3. 4
      src/gui/mainwindow.cpp
  4. 8
      src/gui/properties/propertieswidget.cpp
  5. 2
      src/gui/torrentcontentmodel.cpp
  6. 18
      src/gui/transferlistwidget.cpp

4
src/gui/macutilities.h

@ -33,8 +33,12 @@ @@ -33,8 +33,12 @@
#include <QSize>
#include <objc/objc.h>
namespace MacUtils
{
QPixmap pixmapForExtension(const QString &ext, const QSize &size);
void overrideDockClickHandler(bool (*dockClickHandler)(id, SEL, ...));
void displayNotification(const QString &title, const QString &message);
void openFiles(const QSet<QString> &pathsList);
}
#endif // MACUTILITIES_H

16
src/gui/macutilities.mm

@ -28,10 +28,13 @@ @@ -28,10 +28,13 @@
#include "macutilities.h"
#include <QSet>
#include <QtMac>
#include <objc/message.h>
#import <Cocoa/Cocoa.h>
namespace MacUtils
{
QPixmap pixmapForExtension(const QString &ext, const QSize &size)
{
@autoreleasepool {
@ -81,3 +84,16 @@ void displayNotification(const QString &title, const QString &message) @@ -81,3 +84,16 @@ void displayNotification(const QString &title, const QString &message)
[[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];
}
}
}

4
src/gui/mainwindow.cpp

@ -1298,7 +1298,7 @@ static bool dockClickHandler(id self, SEL cmd, ...) @@ -1298,7 +1298,7 @@ static bool dockClickHandler(id self, SEL cmd, ...)
void MainWindow::setupDockClickHandler()
{
dockMainWindowHandle = this;
overrideDockClickHandler(dockClickHandler);
MacUtils::overrideDockClickHandler(dockClickHandler);
}
#endif
@ -1557,7 +1557,7 @@ void MainWindow::showNotificationBaloon(QString title, QString msg) const @@ -1557,7 +1557,7 @@ void MainWindow::showNotificationBaloon(QString title, QString msg) const
if (!reply.isError())
return;
#elif defined(Q_OS_MAC)
displayNotification(title, msg);
MacUtils::displayNotification(title, msg);
#else
if (m_systrayIcon && QSystemTrayIcon::supportsMessages())
m_systrayIcon->showMessage(title, msg, QSystemTrayIcon::Information, TIME_TRAY_BALLOON);

8
src/gui/properties/propertieswidget.cpp

@ -65,6 +65,10 @@ @@ -65,6 +65,10 @@
#include "ui_propertieswidget.h"
#ifdef Q_OS_MAC
#include "macutilities.h"
#endif
PropertiesWidget::PropertiesWidget(QWidget *parent, MainWindow *mainWindow, TransferListWidget *transferList)
: QWidget(parent)
, m_ui(new Ui::PropertiesWidget())
@ -574,10 +578,14 @@ void PropertiesWidget::openFolder(const QModelIndex &index, bool containingFolde @@ -574,10 +578,14 @@ void PropertiesWidget::openFolder(const QModelIndex &index, bool containingFolde
// Flush data
m_torrent->flushCache();
#ifdef Q_OS_MAC
MacUtils::openFiles(QSet<QString>{absolutePath});
#else
if (containingFolder)
Utils::Misc::openFolderSelect(absolutePath);
else
Utils::Misc::openPath(absolutePath);
#endif
}
void PropertiesWidget::displayFilesListMenu(const QPoint &)

2
src/gui/torrentcontentmodel.cpp

@ -150,7 +150,7 @@ namespace @@ -150,7 +150,7 @@ namespace
{
QPixmap pixmapForExtension(const QString &ext) const override
{
return ::pixmapForExtension(ext, QSize(32, 32));
return MacUtils::pixmapForExtension(ext, QSize(32, 32));
}
};
#else

18
src/gui/transferlistwidget.cpp

@ -62,6 +62,10 @@ @@ -62,6 +62,10 @@
#include "transferlistsortmodel.h"
#include "updownratiodlg.h"
#ifdef Q_OS_MAC
#include "macutilities.h"
#endif
namespace
{
using ToggleFn = std::function<void (Qt::CheckState)>;
@ -358,10 +362,14 @@ void TransferListWidget::torrentDoubleClicked() @@ -358,10 +362,14 @@ void TransferListWidget::torrentDoubleClicked()
torrent->pause();
break;
case OPEN_DEST:
#ifdef Q_OS_MAC
MacUtils::openFiles(QSet<QString>{torrent->contentPath(true)});
#else
if (torrent->filesCount() == 1)
Utils::Misc::openFolderSelect(torrent->contentPath(true));
else
Utils::Misc::openPath(torrent->contentPath(true));
#endif
break;
}
}
@ -548,6 +556,15 @@ void TransferListWidget::hidePriorityColumn(bool hide) @@ -548,6 +556,15 @@ void TransferListWidget::hidePriorityColumn(bool hide)
void TransferListWidget::openSelectedTorrentsFolder() const
{
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);
}
MacUtils::openFiles(pathsList);
#else
foreach (BitTorrent::TorrentHandle *const torrent, getSelectedTorrents()) {
QString path = torrent->contentPath(true);
if (!pathsList.contains(path)) {
@ -558,6 +575,7 @@ void TransferListWidget::openSelectedTorrentsFolder() const @@ -558,6 +575,7 @@ void TransferListWidget::openSelectedTorrentsFolder() const
}
pathsList.insert(path);
}
#endif
}
void TransferListWidget::previewSelectedTorrents()

Loading…
Cancel
Save