mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-17 00:04:02 -04:00
add notifications on mac (#7673)
This commit is contained in:
parent
05fb0f4350
commit
66dd6768ef
@ -332,6 +332,9 @@ IF(WITH_CORE)
|
||||
FIND_PACKAGE(Qt53DExtras REQUIRED)
|
||||
SET(HAVE_3D TRUE) # used in qgsconfig.h
|
||||
ENDIF (WITH_3D)
|
||||
IF (APPLE)
|
||||
FIND_PACKAGE(Qt5MacExtras REQUIRED)
|
||||
ENDIF (APPLE)
|
||||
INCLUDE("cmake/modules/ECMQt4To5Porting.cmake")
|
||||
MESSAGE(STATUS "Found Qt version: ${Qt5Core_VERSION_STRING}")
|
||||
IF (WITH_QUICK)
|
||||
|
@ -152,6 +152,12 @@ IF (UNIX AND NOT APPLE AND NOT ANDROID)
|
||||
TARGET_LINK_LIBRARIES(qgis_native Qt5::DBus)
|
||||
ENDIF (UNIX AND NOT APPLE AND NOT ANDROID)
|
||||
|
||||
IF (APPLE)
|
||||
FIND_PACKAGE(Qt5MacExtras)
|
||||
|
||||
TARGET_LINK_LIBRARIES(qgis_native Qt5::MacExtras)
|
||||
ENDIF (APPLE)
|
||||
|
||||
IF (WIN32)
|
||||
FIND_PACKAGE(Qt5WinExtras)
|
||||
|
||||
|
@ -26,11 +26,20 @@ class QString;
|
||||
class NATIVE_EXPORT QgsMacNative : public QgsNative
|
||||
{
|
||||
public:
|
||||
virtual ~QgsMacNative();
|
||||
explicit QgsMacNative();
|
||||
~QgsMacNative() override;
|
||||
|
||||
virtual const char *currentAppLocalizedName();
|
||||
void currentAppActivateIgnoringOtherApps() override;
|
||||
void openFileExplorerAndSelectFile( const QString &path ) override;
|
||||
QgsNative::Capabilities capabilities() const override;
|
||||
QgsNative::NotificationResult showDesktopNotification( const QString &summary, const QString &body, const NotificationSettings &settings ) override;
|
||||
|
||||
private:
|
||||
class QgsUserNotificationCenter;
|
||||
QgsUserNotificationCenter *mQgsUserNotificationCenter = nullptr;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif // QGSMACNATIVE_H
|
||||
|
@ -18,10 +18,43 @@
|
||||
#include "qgsmacnative.h"
|
||||
|
||||
#include <Cocoa/Cocoa.h>
|
||||
#include <QtMacExtras/QtMac>
|
||||
|
||||
#include <QString>
|
||||
#include <QPixmap>
|
||||
|
||||
|
||||
@interface QgsUserNotificationCenterDelegate : NSObject <NSUserNotificationCenterDelegate>
|
||||
@end
|
||||
|
||||
@implementation QgsUserNotificationCenterDelegate
|
||||
|
||||
- ( BOOL )userNotificationCenter:( NSUserNotificationCenter * )center shouldPresentNotification:( NSUserNotification * )notification
|
||||
{
|
||||
#pragma unused (notification)
|
||||
#pragma unused (center)
|
||||
return YES;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
class QgsMacNative::QgsUserNotificationCenter
|
||||
{
|
||||
public:
|
||||
QgsUserNotificationCenterDelegate *_qgsUserNotificationCenter;
|
||||
};
|
||||
|
||||
QgsMacNative::QgsMacNative()
|
||||
: mQgsUserNotificationCenter( new QgsMacNative::QgsUserNotificationCenter() )
|
||||
{
|
||||
mQgsUserNotificationCenter->_qgsUserNotificationCenter = [[QgsUserNotificationCenterDelegate alloc] init];
|
||||
[[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate: mQgsUserNotificationCenter->_qgsUserNotificationCenter];
|
||||
}
|
||||
|
||||
QgsMacNative::~QgsMacNative()
|
||||
{
|
||||
[mQgsUserNotificationCenter->_qgsUserNotificationCenter dealloc];
|
||||
delete mQgsUserNotificationCenter;
|
||||
}
|
||||
|
||||
const char *QgsMacNative::currentAppLocalizedName()
|
||||
@ -41,3 +74,38 @@ void QgsMacNative::openFileExplorerAndSelectFile( const QString &path )
|
||||
NSArray *fileURLs = [NSArray arrayWithObjects:[NSURL fileURLWithPath:pathStr], nil];
|
||||
[[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs:fileURLs];
|
||||
}
|
||||
|
||||
QgsNative::Capabilities QgsMacNative::capabilities() const
|
||||
{
|
||||
return NativeDesktopNotifications;
|
||||
}
|
||||
|
||||
QgsNative::NotificationResult QgsMacNative::showDesktopNotification( const QString &summary,
|
||||
const QString &body,
|
||||
const QgsNative::NotificationSettings &settings )
|
||||
{
|
||||
NSUserNotification *notification = [[NSUserNotification alloc] init];
|
||||
notification.title = summary.toNSString();
|
||||
notification.informativeText = body.toNSString();
|
||||
notification.soundName = NSUserNotificationDefaultSoundName; //Will play a default sound
|
||||
const QPixmap px = QPixmap::fromImage( settings.image );
|
||||
NSImage *image = nil;
|
||||
if ( settings.image.isNull() )
|
||||
{
|
||||
image = [[NSImage imageNamed:@"NSApplicationIcon"] retain];
|
||||
}
|
||||
else
|
||||
{
|
||||
image = QtMac::toNSImage( px );
|
||||
}
|
||||
notification.contentImage = image;
|
||||
|
||||
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification: notification];
|
||||
[notification autorelease];
|
||||
|
||||
//[userCenterDelegate dealloc];
|
||||
|
||||
NotificationResult result;
|
||||
result.successful = true;
|
||||
return result;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user