enabled custom notifies in os x 10.7, added content image in os x native notifiers

This commit is contained in:
John Preston 2015-01-28 16:14:43 +03:00
parent 75a47e98c3
commit 61da0ff829
6 changed files with 23 additions and 13 deletions

View File

@ -1038,6 +1038,7 @@ notifyBorder: #f1f1f1;
notifyBorderWidth: 1px;
notifySlowHide: 4000;
notifyPhotoSize: 62px;
notifyMacPhotoSize: 64px;
notifyPhotoPos: point(9px, 9px);
notifyClosePos: point(1px, 2px);
notifyClose: iconedButton(btnDefIconed) {

View File

@ -2448,7 +2448,6 @@ void MainWidget::updateOnline(bool gotOtherOffline) {
int updateIn = cOnlineUpdatePeriod();
if (isOnline) {
uint64 idle = psIdleTime();
LOG(("Idle: %1").arg(idle));
if (idle >= uint64(cOfflineIdleTimeout())) {
isOnline = false;
if (!_isIdle) {
@ -2478,7 +2477,6 @@ void MainWidget::updateOnline(bool gotOtherOffline) {
} else if (isOnline) {
updateIn = qMin(updateIn, int(_lastSetOnline + cOnlineUpdatePeriod() - ms));
}
LOG(("UPDATE IN: %1").arg(updateIn));
_onlineTimer.start(updateIn);
}

View File

@ -480,8 +480,10 @@ void PsMainWindow::psNotifyShown(NotifyWindow *w) {
void PsMainWindow::psPlatformNotify(HistoryItem *item) {
QString title = (cNotifyView() <= dbinvShowName) ? item->history()->peer->name : qsl("Telegram Desktop");
QString subtitle = (cNotifyView() <= dbinvShowName) ? item->notificationHeader() : QString();
QPixmap pix = (cNotifyView() <= dbinvShowName) ? item->history()->peer->photo->pix(st::notifyMacPhotoSize) : QPixmap();
QString msg = (cNotifyView() <= dbinvShowPreview) ? item->notificationText() : lang(lng_notification_preview);
_private.showNotify(item->history()->peer->id, title, subtitle, msg, (cNotifyView() <= dbinvShowPreview));
_private.showNotify(item->history()->peer->id, pix, title, subtitle, msg, (cNotifyView() <= dbinvShowPreview));
}
bool PsMainWindow::eventFilter(QObject *obj, QEvent *evt) {

View File

@ -29,7 +29,7 @@ public:
void updateDelegate();
void showNotify(uint64 peer, const QString &title, const QString &subtitle, const QString &msg, bool withReply);
void showNotify(uint64 peer, const QPixmap &pix, const QString &title, const QString &subtitle, const QString &msg, bool withReply);
void clearNotifies(uint64 peer = 0);
void enableShadow(WId winId);

View File

@ -148,13 +148,15 @@ public:
void onNotifyClick(NSUserNotification *notification) {
NSNumber *peerObj = [[notification userInfo] objectForKey:@"peer"];
unsigned long long peerLong = [peerObj unsignedLongLongValue];
unsigned long long peerLong = peerObj ? [peerObj unsignedLongLongValue] : 0;
LOG(("Received notification click with peer %1").arg(peerLong));
wnd->notifyClicked(peerLong);
}
void onNotifyReply(NSUserNotification *notification) {
NSNumber *peerObj = [[notification userInfo] objectForKey:@"peer"];
unsigned long long peerLong = [peerObj unsignedLongLongValue];
unsigned long long peerLong = peerObj ? [peerObj unsignedLongLongValue] : 0;
LOG(("Received notification reply with peer %1").arg(peerLong));
wnd->notifyReplied(peerLong, [[[notification response] string] UTF8String]);
}
@ -202,11 +204,12 @@ public:
- (void) userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification:(NSUserNotification *)notification {
NSNumber *instObj = [[notification userInfo] objectForKey:@"inst"];
unsigned long long instLong = [instObj unsignedLongLongValue];
unsigned long long instLong = instObj ? [instObj unsignedLongLongValue] : 0;
DEBUG_LOG(("Received notification with instance %1").arg(instLong));
if (instLong != cInstance()) { // other app instance notification
return;
}
if (notification.activationType == NSUserNotificationActivationTypeReplied){
if (notification.activationType == NSUserNotificationActivationTypeReplied) {
wnd->data->onNotifyReply(notification);
} else if (notification.activationType == NSUserNotificationActivationTypeContentsClicked) {
wnd->data->onNotifyClick(notification);
@ -255,7 +258,7 @@ void objc_showOverAll(WId winId, bool canFocus) {
[wnd setLevel:NSPopUpMenuWindowLevel];
if (!canFocus) {
[wnd setStyleMask:NSUtilityWindowMask | NSNonactivatingPanelMask];
[wnd setCollectionBehavior:NSWindowCollectionBehaviorCanJoinAllSpaces|NSWindowCollectionBehaviorFullScreenAuxiliary|NSWindowCollectionBehaviorIgnoresCycle];
[wnd setCollectionBehavior:NSWindowCollectionBehaviorMoveToActiveSpace|NSWindowCollectionBehaviorStationary|NSWindowCollectionBehaviorFullScreenAuxiliary|NSWindowCollectionBehaviorIgnoresCycle];
}
}
@ -269,14 +272,19 @@ void objc_activateWnd(WId winId) {
[wnd orderFront:wnd];
}
void PsMacWindowPrivate::showNotify(uint64 peer, const QString &title, const QString &subtitle, const QString &msg, bool withReply) {
NSImage *qt_mac_create_nsimage(const QPixmap &pm);
void PsMacWindowPrivate::showNotify(uint64 peer, const QPixmap &pix, const QString &title, const QString &subtitle, const QString &msg, bool withReply) {
NSUserNotification *notification = [[NSUserNotification alloc] init];
NSImage *img = qt_mac_create_nsimage(pix);
DEBUG_LOG(("Sending notification with userinfo: peer %1 and instance %2").arg(peer).arg(cInstance()));
[notification setUserInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithUnsignedLongLong:peer],@"peer",[NSNumber numberWithUnsignedLongLong:cInstance()],@"inst",nil]];
[notification setTitle:QNSString(title).s()];
[notification setSubtitle:QNSString(subtitle).s()];
[notification setInformativeText:QNSString(msg).s()];
[notification setContentImage:img];
if (withReply) [notification setHasReplyButton:YES];
@ -284,7 +292,8 @@ void PsMacWindowPrivate::showNotify(uint64 peer, const QString &title, const QSt
NSUserNotificationCenter *center = [NSUserNotificationCenter defaultUserNotificationCenter];
[center deliverNotification:notification];
if (img) [img release];
[notification release];
}

View File

@ -129,7 +129,7 @@ int gOtherOnline = 0;
void settingsParseArgs(int argc, char *argv[]) {
if (cPlatform() == dbipMac) {
gCustomNotifies = false;
gCustomNotifies = (QSysInfo::macVersion() < QSysInfo::MV_10_8);
} else {
gCustomNotifies = true;
}