Browse Source

Merge pull request #14783 from glassez/macutils

Don't use "Qt Mac Extras" module
adaptive-webui-19844
Vladimir Golovnev 4 years ago committed by GitHub
parent
commit
e0d17e496a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      src/CMakeLists.txt
  2. 1
      src/gui/CMakeLists.txt
  3. 3
      src/gui/macutilities.h
  4. 33
      src/gui/macutilities.mm
  5. 10
      src/gui/mainwindow.cpp
  6. 1
      src/src.pro

4
src/CMakeLists.txt

@ -61,9 +61,7 @@ add_subdirectory(base)
if (GUI) if (GUI)
find_package(Qt5 ${minQtVersion} REQUIRED COMPONENTS Widgets Svg) find_package(Qt5 ${minQtVersion} REQUIRED COMPONENTS Widgets Svg)
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin") if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
find_package(Qt5 ${minQtVersion} REQUIRED COMPONENTS MacExtras)
elseif (CMAKE_SYSTEM_NAME STREQUAL "Windows")
find_package(Qt5 ${minQtVersion} REQUIRED COMPONENTS WinExtras) find_package(Qt5 ${minQtVersion} REQUIRED COMPONENTS WinExtras)
endif() endif()
add_subdirectory(gui) add_subdirectory(gui)

1
src/gui/CMakeLists.txt

@ -228,7 +228,6 @@ if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
macutilities.mm macutilities.mm
) )
target_link_libraries(qbt_gui PRIVATE target_link_libraries(qbt_gui PRIVATE
Qt5::MacExtras
objc objc
) )
endif() endif()

3
src/gui/macutilities.h

@ -42,4 +42,7 @@ namespace MacUtils
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); void openFiles(const QSet<QString> &pathsList);
QString badgeLabelText();
void setBadgeLabelText(const QString &text);
} }

33
src/gui/macutilities.mm

@ -35,18 +35,21 @@
#include <QSet> #include <QSet>
#include <QSize> #include <QSize>
#include <QString> #include <QString>
#include <QtMac>
QImage qt_mac_toQImage(CGImageRef image);
namespace MacUtils namespace MacUtils
{ {
QPixmap pixmapForExtension(const QString &ext, const QSize &size) 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)
{
NSRect rect = NSMakeRect(0, 0, size.width(), size.height()); NSRect rect = NSMakeRect(0, 0, size.width(), size.height());
CGImageRef cgImage = [image CGImageForProposedRect:&rect context:nil hints:nil]; CGImageRef cgImage = [image CGImageForProposedRect:&rect context:nil hints:nil];
return QtMac::fromCGImageRef(cgImage); return QPixmap::fromImage(qt_mac_toQImage(cgImage));
} }
return QPixmap(); return QPixmap();
@ -63,13 +66,15 @@ namespace MacUtils
Class delClass = [[appInst delegate] class]; Class delClass = [[appInst delegate] class];
SEL shouldHandle = sel_registerName("applicationShouldHandleReopen:hasVisibleWindows:"); SEL shouldHandle = sel_registerName("applicationShouldHandleReopen:hasVisibleWindows:");
if (class_getInstanceMethod(delClass, shouldHandle)) { if (class_getInstanceMethod(delClass, shouldHandle))
{
if (class_replaceMethod(delClass, shouldHandle, (IMP)dockClickHandler, "B@:")) if (class_replaceMethod(delClass, shouldHandle, (IMP)dockClickHandler, "B@:"))
qDebug("Registered dock click handler (replaced original method)"); qDebug("Registered dock click handler (replaced original method)");
else else
qWarning("Failed to replace method for dock click handler"); qWarning("Failed to replace method for dock click handler");
} }
else { else
{
if (class_addMethod(delClass, shouldHandle, (IMP)dockClickHandler, "B@:")) if (class_addMethod(delClass, shouldHandle, (IMP)dockClickHandler, "B@:"))
qDebug("Registered dock click handler"); qDebug("Registered dock click handler");
else else
@ -79,7 +84,8 @@ namespace MacUtils
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();
notification.informativeText = message.toNSString(); notification.informativeText = message.toNSString();
@ -91,7 +97,8 @@ namespace MacUtils
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()];
for (const auto &path : pathsList) for (const auto &path : pathsList)
@ -100,4 +107,14 @@ namespace MacUtils
[[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs:pathURLs]; [[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs:pathURLs];
} }
} }
QString badgeLabelText()
{
return QString::fromNSString(NSApp.dockTile.badgeLabel);
}
void setBadgeLabelText(const QString &text)
{
NSApp.dockTile.badgeLabel = text.toNSString();
}
} }

10
src/gui/mainwindow.cpp

@ -48,10 +48,6 @@
#include <QtGlobal> #include <QtGlobal>
#include <QTimer> #include <QTimer>
#ifdef Q_OS_MACOS
#include <QtMac>
#include <QtMacExtras>
#endif
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) && defined(QT_DBUS_LIB) #if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) && defined(QT_DBUS_LIB)
#include <QDBusConnection> #include <QDBusConnection>
#include "qtnotify/notifications.h" #include "qtnotify/notifications.h"
@ -1627,12 +1623,12 @@ void MainWindow::reloadSessionStats()
#ifdef Q_OS_MACOS #ifdef Q_OS_MACOS
if (status.payloadDownloadRate > 0) 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))); .arg(Utils::Misc::friendlyUnit(status.payloadDownloadRate)));
} }
else if (!QtMac::badgeLabelText().isEmpty()) else if (!MacUtils::badgeLabelText().isEmpty())
{ {
QtMac::setBadgeLabelText(""); MacUtils::setBadgeLabelText("");
} }
#else #else
if (m_systrayIcon) if (m_systrayIcon)

1
src/src.pro

@ -27,7 +27,6 @@ nogui {
QT += winextras QT += winextras
} }
macx { macx {
QT += macextras
LIBS += -lobjc LIBS += -lobjc
} }
} }

Loading…
Cancel
Save