Browse Source

Put macOS specific functions to MacUtils namespace

adaptive-webui-19844
vit9696 7 years ago
parent
commit
d7fa5b6b6b
  1. 11
      src/gui/macutilities.h
  2. 23
      src/gui/macutilities.mm
  3. 4
      src/gui/mainwindow.cpp
  4. 2
      src/gui/torrentcontentmodel.cpp
  5. 2
      src/gui/transferlistwidget.cpp

11
src/gui/macutilities.h

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

23
src/gui/macutilities.mm

@ -33,8 +33,10 @@
#include <objc/message.h> #include <objc/message.h>
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
QPixmap pixmapForExtension(const QString &ext, const QSize &size) namespace MacUtils
{ {
QPixmap pixmapForExtension(const QString &ext, const QSize &size)
{
@autoreleasepool { @autoreleasepool {
NSImage *image = [[NSWorkspace sharedWorkspace] iconForFileType:ext.toNSString()]; NSImage *image = [[NSWorkspace sharedWorkspace] iconForFileType:ext.toNSString()];
if (image) { if (image) {
@ -45,10 +47,10 @@ QPixmap pixmapForExtension(const QString &ext, const QSize &size)
return QPixmap(); return QPixmap();
} }
} }
void overrideDockClickHandler(bool (*dockClickHandler)(id, SEL, ...)) void overrideDockClickHandler(bool (*dockClickHandler)(id, SEL, ...))
{ {
NSApplication *appInst = [NSApplication sharedApplication]; NSApplication *appInst = [NSApplication sharedApplication];
if (!appInst) if (!appInst)
@ -69,10 +71,10 @@ void overrideDockClickHandler(bool (*dockClickHandler)(id, SEL, ...))
else else
qWarning("Failed to register dock click handler"); qWarning("Failed to register dock click handler");
} }
} }
void displayNotification(const QString &title, const QString &message) void displayNotification(const QString &title, const QString &message)
{ {
@autoreleasepool { @autoreleasepool {
NSUserNotification *notification = [[NSUserNotification alloc] init]; NSUserNotification *notification = [[NSUserNotification alloc] init];
notification.title = title.toNSString(); notification.title = title.toNSString();
@ -81,10 +83,10 @@ void displayNotification(const QString &title, const QString &message)
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification]; [[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification];
} }
} }
void openFiles(const QSet<QString> &pathsList) void openFiles(const QSet<QString> &pathsList)
{ {
@autoreleasepool { @autoreleasepool {
NSMutableArray *pathURLs = [NSMutableArray arrayWithCapacity:pathsList.size()]; NSMutableArray *pathURLs = [NSMutableArray arrayWithCapacity:pathsList.size()];
@ -93,4 +95,5 @@ void openFiles(const QSet<QString> &pathsList)
[[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs:pathURLs]; [[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs:pathURLs];
} }
}
} }

4
src/gui/mainwindow.cpp

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

2
src/gui/torrentcontentmodel.cpp

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

2
src/gui/transferlistwidget.cpp

@ -559,7 +559,7 @@ void TransferListWidget::openSelectedTorrentsFolder() const
QString path = torrent->contentPath(true); QString path = torrent->contentPath(true);
pathsList.insert(path); pathsList.insert(path);
} }
openFiles(pathsList); MacUtils::openFiles(pathsList);
#else #else
foreach (BitTorrent::TorrentHandle *const torrent, getSelectedTorrents()) { foreach (BitTorrent::TorrentHandle *const torrent, getSelectedTorrents()) {
QString path = torrent->contentPath(true); QString path = torrent->contentPath(true);

Loading…
Cancel
Save