diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6709fbf37..349f967cd 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -61,9 +61,7 @@ add_subdirectory(base) if (GUI) find_package(Qt5 ${minQtVersion} REQUIRED COMPONENTS Widgets Svg) - if (CMAKE_SYSTEM_NAME STREQUAL "Darwin") - find_package(Qt5 ${minQtVersion} REQUIRED COMPONENTS MacExtras) - elseif (CMAKE_SYSTEM_NAME STREQUAL "Windows") + if (CMAKE_SYSTEM_NAME STREQUAL "Windows") find_package(Qt5 ${minQtVersion} REQUIRED COMPONENTS WinExtras) endif() add_subdirectory(gui) diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index 507e0acd7..d8af86fdc 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -228,7 +228,6 @@ if (CMAKE_SYSTEM_NAME STREQUAL "Darwin") macutilities.mm ) target_link_libraries(qbt_gui PRIVATE - Qt5::MacExtras objc ) endif() diff --git a/src/gui/macutilities.h b/src/gui/macutilities.h index 5250a22fb..e6ea8c20e 100644 --- a/src/gui/macutilities.h +++ b/src/gui/macutilities.h @@ -42,4 +42,7 @@ namespace MacUtils void overrideDockClickHandler(bool (*dockClickHandler)(id, SEL, ...)); void displayNotification(const QString &title, const QString &message); void openFiles(const QSet &pathsList); + + QString badgeLabelText(); + void setBadgeLabelText(const QString &text); } diff --git a/src/gui/macutilities.mm b/src/gui/macutilities.mm index f1072058a..910d77368 100644 --- a/src/gui/macutilities.mm +++ b/src/gui/macutilities.mm @@ -35,18 +35,21 @@ #include #include #include -#include + +QImage qt_mac_toQImage(CGImageRef image); namespace MacUtils { QPixmap pixmapForExtension(const QString &ext, const QSize &size) { - @autoreleasepool { + @autoreleasepool + { NSImage *image = [[NSWorkspace sharedWorkspace] iconForFileType:ext.toNSString()]; - if (image) { + if (image) + { NSRect rect = NSMakeRect(0, 0, size.width(), size.height()); CGImageRef cgImage = [image CGImageForProposedRect:&rect context:nil hints:nil]; - return QtMac::fromCGImageRef(cgImage); + return QPixmap::fromImage(qt_mac_toQImage(cgImage)); } return QPixmap(); @@ -63,13 +66,15 @@ namespace MacUtils Class delClass = [[appInst delegate] class]; SEL shouldHandle = sel_registerName("applicationShouldHandleReopen:hasVisibleWindows:"); - if (class_getInstanceMethod(delClass, shouldHandle)) { + if (class_getInstanceMethod(delClass, shouldHandle)) + { if (class_replaceMethod(delClass, shouldHandle, (IMP)dockClickHandler, "B@:")) qDebug("Registered dock click handler (replaced original method)"); else qWarning("Failed to replace method for dock click handler"); } - else { + else + { if (class_addMethod(delClass, shouldHandle, (IMP)dockClickHandler, "B@:")) qDebug("Registered dock click handler"); else @@ -79,7 +84,8 @@ namespace MacUtils void displayNotification(const QString &title, const QString &message) { - @autoreleasepool { + @autoreleasepool + { NSUserNotification *notification = [[NSUserNotification alloc] init]; notification.title = title.toNSString(); notification.informativeText = message.toNSString(); @@ -91,7 +97,8 @@ namespace MacUtils void openFiles(const QSet &pathsList) { - @autoreleasepool { + @autoreleasepool + { NSMutableArray *pathURLs = [NSMutableArray arrayWithCapacity:pathsList.size()]; for (const auto &path : pathsList) @@ -100,4 +107,14 @@ namespace MacUtils [[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs:pathURLs]; } } + + QString badgeLabelText() + { + return QString::fromNSString(NSApp.dockTile.badgeLabel); + } + + void setBadgeLabelText(const QString &text) + { + NSApp.dockTile.badgeLabel = text.toNSString(); + } } diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index ae9b913c3..23135e964 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -48,10 +48,6 @@ #include #include -#ifdef Q_OS_MACOS -#include -#include -#endif #if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) && defined(QT_DBUS_LIB) #include #include "qtnotify/notifications.h" @@ -1627,12 +1623,12 @@ void MainWindow::reloadSessionStats() #ifdef Q_OS_MACOS if (status.payloadDownloadRate > 0) { - QtMac::setBadgeLabelText(tr("%1/s", "s is a shorthand for seconds") + MacUtils::setBadgeLabelText(tr("%1/s", "s is a shorthand for seconds") .arg(Utils::Misc::friendlyUnit(status.payloadDownloadRate))); } - else if (!QtMac::badgeLabelText().isEmpty()) + else if (!MacUtils::badgeLabelText().isEmpty()) { - QtMac::setBadgeLabelText(""); + MacUtils::setBadgeLabelText(""); } #else if (m_systrayIcon) diff --git a/src/src.pro b/src/src.pro index 0e265e615..0ae7e2f64 100644 --- a/src/src.pro +++ b/src/src.pro @@ -27,7 +27,6 @@ nogui { QT += winextras } macx { - QT += macextras LIBS += -lobjc } }