QSystemTrayIcon on macOS: support the timeout hint in showMessage

If set, schedule a call to remove the notification (NSTimeInterval is
specified in seconds). The system might hide the notification balloon
earlier, but the notification will still be removed from the message
center after the specified interval.

Task-number: QTBUG-77150
Change-Id: I510e412beb16e9de271290798f3e66310f44df4f
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
bb10
Volker Hilsheimer 2019-08-30 12:05:01 +02:00
parent c66732b979
commit 64ed4081ca
2 changed files with 6 additions and 2 deletions

View File

@ -65,7 +65,7 @@ public:
void updateMenu(QPlatformMenu *menu) override;
QRect geometry() const override;
void showMessage(const QString &title, const QString &msg,
const QIcon& icon, MessageIcon iconType, int secs) override;
const QIcon& icon, MessageIcon iconType, int msecs) override;
bool isSystemTrayAvailable() const override;
bool supportsMessages() const override;

View File

@ -264,7 +264,7 @@ bool QCocoaSystemTrayIcon::supportsMessages() const
}
void QCocoaSystemTrayIcon::showMessage(const QString &title, const QString &message,
const QIcon& icon, MessageIcon, int)
const QIcon& icon, MessageIcon, int msecs)
{
if (!m_sys)
return;
@ -282,6 +282,10 @@ void QCocoaSystemTrayIcon::showMessage(const QString &title, const QString &mess
NSUserNotificationCenter *center = NSUserNotificationCenter.defaultUserNotificationCenter;
center.delegate = m_sys->item;
[center deliverNotification:notification];
if (msecs) {
NSTimeInterval timeout = msecs / 1000.0;
[center performSelector:@selector(removeDeliveredNotification:) withObject:notification afterDelay:timeout];
}
[notification release];
}
QT_END_NAMESPACE