2014-11-25 20:15:18 +00:00
|
|
|
/*
|
2014-06-14 19:32:11 +00:00
|
|
|
This file is part of Telegram Desktop,
|
2014-12-01 10:47:38 +00:00
|
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
2016-01-11 15:43:29 +00:00
|
|
|
|
2014-06-14 19:32:11 +00:00
|
|
|
Telegram Desktop is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
2016-01-11 15:43:29 +00:00
|
|
|
|
2014-06-14 19:32:11 +00:00
|
|
|
It is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2016-01-11 15:43:29 +00:00
|
|
|
|
2014-06-14 19:32:11 +00:00
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
2017-01-11 18:31:31 +00:00
|
|
|
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
2014-06-14 19:32:11 +00:00
|
|
|
*/
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "pspecific_mac_p.h"
|
|
|
|
|
2016-04-12 21:31:28 +00:00
|
|
|
#include "mainwindow.h"
|
2015-07-13 17:55:59 +00:00
|
|
|
#include "mainwidget.h"
|
2014-11-12 20:30:26 +00:00
|
|
|
#include "application.h"
|
2016-08-31 17:58:46 +00:00
|
|
|
#include "localstorage.h"
|
2016-09-23 16:04:26 +00:00
|
|
|
#include "media/player/media_player_instance.h"
|
2017-01-24 21:24:39 +00:00
|
|
|
#include "media/media_audio.h"
|
2016-10-02 15:44:54 +00:00
|
|
|
#include "platform/mac/mac_utilities.h"
|
2016-11-04 08:23:50 +00:00
|
|
|
#include "styles/style_window.h"
|
2014-06-18 18:37:44 +00:00
|
|
|
#include "lang.h"
|
|
|
|
|
2014-06-14 19:32:11 +00:00
|
|
|
#include <Cocoa/Cocoa.h>
|
2014-06-17 06:06:01 +00:00
|
|
|
#include <CoreFoundation/CFURL.h>
|
2016-11-08 14:07:25 +00:00
|
|
|
#include <IOKit/IOKitLib.h>
|
2015-07-13 17:55:59 +00:00
|
|
|
#include <IOKit/hidsystem/ev_keymap.h>
|
2016-10-17 14:57:14 +00:00
|
|
|
#include <SPMediaKeyTap.h>
|
|
|
|
|
2016-10-02 15:44:54 +00:00
|
|
|
using Platform::Q2NSString;
|
|
|
|
using Platform::NSlang;
|
|
|
|
using Platform::NS2QString;
|
|
|
|
|
2015-01-02 15:07:48 +00:00
|
|
|
@interface qVisualize : NSObject {
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (id)str:(const QString &)str;
|
|
|
|
- (id)initWithString:(const QString &)str;
|
|
|
|
|
|
|
|
+ (id)bytearr:(const QByteArray &)arr;
|
|
|
|
- (id)initWithByteArray:(const QByteArray &)arr;
|
|
|
|
|
|
|
|
- (id)debugQuickLookObject;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation qVisualize {
|
|
|
|
NSString *value;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (id)bytearr:(const QByteArray &)arr {
|
|
|
|
return [[qVisualize alloc] initWithByteArray:arr];
|
|
|
|
}
|
|
|
|
- (id)initWithByteArray:(const QByteArray &)arr {
|
|
|
|
if (self = [super init]) {
|
|
|
|
value = [NSString stringWithUTF8String:arr.constData()];
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (id)str:(const QString &)str {
|
|
|
|
return [[qVisualize alloc] initWithString:str];
|
|
|
|
}
|
|
|
|
- (id)initWithString:(const QString &)str {
|
|
|
|
if (self = [super init]) {
|
|
|
|
value = [NSString stringWithUTF8String:str.toUtf8().constData()];
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id)debugQuickLookObject {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2014-09-20 21:31:03 +00:00
|
|
|
@interface ApplicationDelegate : NSObject<NSApplicationDelegate> {
|
2016-10-17 14:57:14 +00:00
|
|
|
|
|
|
|
SPMediaKeyTap *keyTap;
|
2016-10-22 14:35:37 +00:00
|
|
|
BOOL watchingMediaKeys;
|
2016-10-17 14:57:14 +00:00
|
|
|
|
2014-09-20 21:31:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag;
|
2016-10-17 14:57:14 +00:00
|
|
|
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification;
|
2014-11-12 20:30:26 +00:00
|
|
|
- (void)applicationDidBecomeActive:(NSNotification *)aNotification;
|
|
|
|
- (void)receiveWakeNote:(NSNotification*)note;
|
2016-10-22 14:35:37 +00:00
|
|
|
- (void)setWatchingMediaKeys:(BOOL)watching;
|
|
|
|
- (BOOL)isWatchingMediaKeys;
|
2016-10-17 14:57:14 +00:00
|
|
|
- (void)mediaKeyTap:(SPMediaKeyTap*)keyTap receivedMediaKeyEvent:(NSEvent*)event;
|
2014-09-20 21:31:03 +00:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
2014-12-03 15:07:24 +00:00
|
|
|
ApplicationDelegate *_sharedDelegate = nil;
|
|
|
|
|
2014-09-20 21:31:03 +00:00
|
|
|
@implementation ApplicationDelegate {
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag {
|
|
|
|
if (App::wnd() && App::wnd()->isHidden()) App::wnd()->showFromTray();
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2016-10-17 14:57:14 +00:00
|
|
|
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
|
2016-10-22 14:35:37 +00:00
|
|
|
keyTap = nullptr;
|
|
|
|
watchingMediaKeys = false;
|
2016-10-19 22:02:21 +00:00
|
|
|
#ifndef OS_MAC_STORE
|
2016-10-17 14:57:14 +00:00
|
|
|
if ([SPMediaKeyTap usesGlobalMediaKeyTap]) {
|
2016-10-22 14:35:37 +00:00
|
|
|
keyTap = [[SPMediaKeyTap alloc] initWithDelegate:self];
|
2016-10-17 14:57:14 +00:00
|
|
|
} else {
|
|
|
|
LOG(("Media key monitoring disabled"));
|
|
|
|
}
|
2016-10-19 22:02:21 +00:00
|
|
|
#endif // else for !OS_MAC_STORE
|
2016-10-17 14:57:14 +00:00
|
|
|
}
|
|
|
|
|
2014-11-12 20:30:26 +00:00
|
|
|
- (void)applicationDidBecomeActive:(NSNotification *)aNotification {
|
|
|
|
if (App::app()) App::app()->checkLocalTime();
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)receiveWakeNote:(NSNotification*)aNotification {
|
|
|
|
if (App::app()) App::app()->checkLocalTime();
|
2017-01-24 21:24:39 +00:00
|
|
|
|
|
|
|
LOG(("Audio Info: -receiveWakeNote: received, scheduling detach from audio device"));
|
|
|
|
Media::Player::DetachFromDeviceByTimer();
|
2014-11-12 20:30:26 +00:00
|
|
|
}
|
|
|
|
|
2016-10-22 14:35:37 +00:00
|
|
|
- (void)setWatchingMediaKeys:(BOOL)watching {
|
|
|
|
if (watchingMediaKeys != watching) {
|
|
|
|
watchingMediaKeys = watching;
|
|
|
|
if (keyTap) {
|
|
|
|
#ifndef OS_MAC_STORE
|
|
|
|
if (watchingMediaKeys) {
|
|
|
|
[keyTap startWatchingMediaKeys];
|
|
|
|
} else {
|
|
|
|
[keyTap stopWatchingMediaKeys];
|
|
|
|
}
|
|
|
|
#endif // else for !OS_MAC_STORE
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)isWatchingMediaKeys {
|
|
|
|
return watchingMediaKeys;
|
|
|
|
}
|
|
|
|
|
2016-10-17 14:57:14 +00:00
|
|
|
- (void)mediaKeyTap:(SPMediaKeyTap*)keyTap receivedMediaKeyEvent:(NSEvent*)e {
|
|
|
|
if (e && [e type] == NSSystemDefined && [e subtype] == SPSystemDefinedEventMediaKeys) {
|
2016-11-08 14:07:25 +00:00
|
|
|
objc_handleMediaKeyEvent(e);
|
2016-10-17 14:57:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-20 21:31:03 +00:00
|
|
|
@end
|
|
|
|
|
2016-10-22 14:35:37 +00:00
|
|
|
namespace Platform {
|
|
|
|
|
|
|
|
void SetWatchingMediaKeys(bool watching) {
|
|
|
|
if (_sharedDelegate) {
|
|
|
|
[_sharedDelegate setWatchingMediaKeys:(watching ? YES : NO)];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Platform
|
|
|
|
|
2014-10-17 12:57:14 +00:00
|
|
|
void objc_holdOnTop(WId winId) {
|
2016-10-02 15:44:54 +00:00
|
|
|
NSWindow *wnd = [reinterpret_cast<NSView *>(winId) window];
|
|
|
|
[wnd setHidesOnDeactivate:NO];
|
2014-06-14 19:32:11 +00:00
|
|
|
}
|
|
|
|
|
2014-11-18 12:40:43 +00:00
|
|
|
bool objc_darkMode() {
|
2016-10-02 15:44:54 +00:00
|
|
|
bool result = false;
|
|
|
|
@autoreleasepool {
|
|
|
|
|
2014-11-18 12:40:43 +00:00
|
|
|
NSDictionary *dict = [[NSUserDefaults standardUserDefaults] persistentDomainForName:NSGlobalDomain];
|
2016-10-02 15:44:54 +00:00
|
|
|
id style = [dict objectForKey:Q2NSString(strStyleOfInterface())];
|
2016-06-16 15:17:39 +00:00
|
|
|
BOOL darkModeOn = (style && [style isKindOfClass:[NSString class]] && NSOrderedSame == [style caseInsensitiveCompare:@"dark"]);
|
2016-10-02 15:44:54 +00:00
|
|
|
result = darkModeOn ? true : false;
|
|
|
|
|
|
|
|
}
|
|
|
|
return result;
|
2014-11-18 12:40:43 +00:00
|
|
|
}
|
|
|
|
|
2014-10-17 12:57:14 +00:00
|
|
|
void objc_showOverAll(WId winId, bool canFocus) {
|
2016-10-02 15:44:54 +00:00
|
|
|
NSWindow *wnd = [reinterpret_cast<NSView *>(winId) window];
|
2014-10-17 12:57:14 +00:00
|
|
|
[wnd setLevel:NSPopUpMenuWindowLevel];
|
|
|
|
if (!canFocus) {
|
|
|
|
[wnd setStyleMask:NSUtilityWindowMask | NSNonactivatingPanelMask];
|
2015-01-28 13:14:43 +00:00
|
|
|
[wnd setCollectionBehavior:NSWindowCollectionBehaviorMoveToActiveSpace|NSWindowCollectionBehaviorStationary|NSWindowCollectionBehaviorFullScreenAuxiliary|NSWindowCollectionBehaviorIgnoresCycle];
|
2014-10-17 12:57:14 +00:00
|
|
|
}
|
2014-06-14 19:32:11 +00:00
|
|
|
}
|
|
|
|
|
2014-10-17 12:57:14 +00:00
|
|
|
void objc_bringToBack(WId winId) {
|
|
|
|
NSWindow *wnd = [reinterpret_cast<NSView *>(winId) window];
|
|
|
|
[wnd setLevel:NSModalPanelWindowLevel];
|
|
|
|
}
|
|
|
|
|
|
|
|
void objc_activateWnd(WId winId) {
|
2016-10-02 15:44:54 +00:00
|
|
|
NSWindow *wnd = [reinterpret_cast<NSView *>(winId) window];
|
|
|
|
[wnd orderFront:wnd];
|
2014-06-14 19:32:11 +00:00
|
|
|
}
|
|
|
|
|
2016-11-08 14:07:25 +00:00
|
|
|
bool objc_handleMediaKeyEvent(void *ev) {
|
|
|
|
auto e = reinterpret_cast<NSEvent*>(ev);
|
2016-11-28 15:45:07 +00:00
|
|
|
|
2016-10-17 14:57:14 +00:00
|
|
|
int keyCode = (([e data1] & 0xFFFF0000) >> 16);
|
|
|
|
int keyFlags = ([e data1] & 0x0000FFFF);
|
|
|
|
int keyState = (((keyFlags & 0xFF00) >> 8)) == 0xA;
|
|
|
|
int keyRepeat = (keyFlags & 0x1);
|
|
|
|
|
2016-10-22 14:35:37 +00:00
|
|
|
if (!_sharedDelegate || ![_sharedDelegate isWatchingMediaKeys]) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-10-17 14:57:14 +00:00
|
|
|
switch (keyCode) {
|
|
|
|
case NX_KEYTYPE_PLAY:
|
|
|
|
if (keyState == 0) { // Play pressed and released
|
2017-01-24 21:24:39 +00:00
|
|
|
Media::Player::instance()->playPause();
|
2016-10-17 14:57:14 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NX_KEYTYPE_FAST:
|
|
|
|
if (keyState == 0) { // Next pressed and released
|
2017-01-24 21:24:39 +00:00
|
|
|
Media::Player::instance()->next();
|
2016-10-17 14:57:14 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NX_KEYTYPE_REWIND:
|
|
|
|
if (keyState == 0) { // Previous pressed and released
|
2017-01-24 21:24:39 +00:00
|
|
|
Media::Player::instance()->previous();
|
2016-10-17 14:57:14 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-06-25 07:25:55 +00:00
|
|
|
void objc_debugShowAlert(const QString &str) {
|
2016-10-02 15:44:54 +00:00
|
|
|
@autoreleasepool {
|
2015-07-13 17:55:59 +00:00
|
|
|
|
2016-10-02 15:44:54 +00:00
|
|
|
[[NSAlert alertWithMessageText:@"Debug Message" defaultButton:@"OK" alternateButton:nil otherButton:nil informativeTextWithFormat:@"%@", Q2NSString(str)] runModal];
|
2014-06-14 19:32:11 +00:00
|
|
|
|
2016-10-02 15:44:54 +00:00
|
|
|
}
|
2014-06-14 19:32:11 +00:00
|
|
|
}
|
|
|
|
|
2014-06-25 07:25:55 +00:00
|
|
|
void objc_outputDebugString(const QString &str) {
|
2016-10-02 15:44:54 +00:00
|
|
|
@autoreleasepool {
|
|
|
|
|
|
|
|
NSLog(@"%@", Q2NSString(str));
|
|
|
|
|
|
|
|
}
|
2014-06-14 19:32:11 +00:00
|
|
|
}
|
|
|
|
|
2015-03-02 12:34:16 +00:00
|
|
|
bool objc_idleSupported() {
|
2016-12-01 19:20:33 +00:00
|
|
|
auto idleTime = 0LL;
|
2015-03-02 12:34:16 +00:00
|
|
|
return objc_idleTime(idleTime);
|
|
|
|
}
|
|
|
|
|
2016-12-01 19:20:33 +00:00
|
|
|
bool objc_idleTime(TimeMs &idleTime) { // taken from https://github.com/trueinteractions/tint/issues/53
|
2016-10-02 15:44:54 +00:00
|
|
|
CFMutableDictionaryRef properties = 0;
|
|
|
|
CFTypeRef obj;
|
|
|
|
mach_port_t masterPort;
|
|
|
|
io_iterator_t iter;
|
|
|
|
io_registry_entry_t curObj;
|
|
|
|
|
|
|
|
IOMasterPort(MACH_PORT_NULL, &masterPort);
|
|
|
|
|
|
|
|
/* Get IOHIDSystem */
|
|
|
|
IOServiceGetMatchingServices(masterPort, IOServiceMatching("IOHIDSystem"), &iter);
|
|
|
|
if (iter == 0) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
curObj = IOIteratorNext(iter);
|
|
|
|
}
|
|
|
|
if (IORegistryEntryCreateCFProperties(curObj, &properties, kCFAllocatorDefault, 0) == KERN_SUCCESS && properties != NULL) {
|
|
|
|
obj = CFDictionaryGetValue(properties, CFSTR("HIDIdleTime"));
|
|
|
|
CFRetain(obj);
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64 err = ~0L, result = err;
|
|
|
|
if (obj) {
|
|
|
|
CFTypeID type = CFGetTypeID(obj);
|
|
|
|
|
|
|
|
if (type == CFDataGetTypeID()) {
|
|
|
|
CFDataGetBytes((CFDataRef) obj, CFRangeMake(0, sizeof(result)), (UInt8*)&result);
|
|
|
|
} else if (type == CFNumberGetTypeID()) {
|
|
|
|
CFNumberGetValue((CFNumberRef)obj, kCFNumberSInt64Type, &result);
|
|
|
|
} else {
|
|
|
|
// error
|
|
|
|
}
|
|
|
|
|
|
|
|
CFRelease(obj);
|
|
|
|
|
|
|
|
if (result != err) {
|
|
|
|
result /= 1000000; // return as ms
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// error
|
|
|
|
}
|
|
|
|
|
|
|
|
CFRelease((CFTypeRef)properties);
|
|
|
|
IOObjectRelease(curObj);
|
|
|
|
IOObjectRelease(iter);
|
2015-01-26 13:04:41 +00:00
|
|
|
if (result == err) return false;
|
|
|
|
|
2016-12-01 19:20:33 +00:00
|
|
|
idleTime = static_cast<TimeMs>(result);
|
2015-01-26 13:04:41 +00:00
|
|
|
return true;
|
2014-06-14 19:32:11 +00:00
|
|
|
}
|
2014-06-17 06:06:01 +00:00
|
|
|
|
2015-01-21 10:20:23 +00:00
|
|
|
@interface OpenWithApp : NSObject {
|
|
|
|
NSString *fullname;
|
|
|
|
NSURL *app;
|
|
|
|
NSImage *icon;
|
|
|
|
}
|
|
|
|
@property (nonatomic, retain) NSString *fullname;
|
|
|
|
@property (nonatomic, retain) NSURL *app;
|
|
|
|
@property (nonatomic, retain) NSImage *icon;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation OpenWithApp
|
|
|
|
@synthesize fullname, app, icon;
|
|
|
|
|
|
|
|
- (void) dealloc {
|
|
|
|
[fullname release];
|
|
|
|
[app release];
|
|
|
|
[icon release];
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface OpenFileWithInterface : NSObject {
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) init:(NSString *)file;
|
|
|
|
- (BOOL) popupAtX:(int)x andY:(int)y;
|
|
|
|
- (void) itemChosen:(id)sender;
|
|
|
|
- (void) dealloc;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation OpenFileWithInterface {
|
|
|
|
NSString *toOpen;
|
|
|
|
|
|
|
|
NSURL *defUrl;
|
|
|
|
NSString *defBundle, *defName, *defVersion;
|
|
|
|
NSImage *defIcon;
|
|
|
|
|
|
|
|
NSMutableArray *apps;
|
|
|
|
|
|
|
|
NSMenu *menu;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) fillAppByUrl:(NSURL*)url bundle:(NSString**)bundle name:(NSString**)name version:(NSString**)version icon:(NSImage**)icon {
|
|
|
|
NSBundle *b = [NSBundle bundleWithURL:url];
|
|
|
|
if (b) {
|
|
|
|
NSString *path = [url path];
|
|
|
|
*name = [[NSFileManager defaultManager] displayNameAtPath: path];
|
|
|
|
if (!*name) *name = (NSString*)[b objectForInfoDictionaryKey:@"CFBundleDisplayName"];
|
|
|
|
if (!*name) *name = (NSString*)[b objectForInfoDictionaryKey:@"CFBundleName"];
|
|
|
|
if (*name) {
|
|
|
|
*bundle = [b bundleIdentifier];
|
|
|
|
if (bundle) {
|
|
|
|
*version = (NSString*)[b objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
|
|
|
|
*icon = [[NSWorkspace sharedWorkspace] iconForFile: path];
|
|
|
|
if (*icon && [*icon isValid]) [*icon setSize: CGSizeMake(16., 16.)];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*bundle = *name = *version = nil;
|
|
|
|
*icon = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) init:(NSString*)file {
|
2016-10-02 15:44:54 +00:00
|
|
|
toOpen = [file retain];
|
2015-01-21 10:20:23 +00:00
|
|
|
if (self = [super init]) {
|
|
|
|
NSURL *url = [NSURL fileURLWithPath:file];
|
|
|
|
defUrl = [[NSWorkspace sharedWorkspace] URLForApplicationToOpenURL:url];
|
|
|
|
if (defUrl) {
|
|
|
|
[self fillAppByUrl:defUrl bundle:&defBundle name:&defName version:&defVersion icon:&defIcon];
|
|
|
|
if (!defBundle || !defName) {
|
|
|
|
defUrl = nil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NSArray *appsList = (NSArray*)LSCopyApplicationURLsForURL(CFURLRef(url), kLSRolesAll);
|
|
|
|
NSMutableDictionary *data = [NSMutableDictionary dictionaryWithCapacity:16];
|
|
|
|
int fullcount = 0;
|
|
|
|
for (id app in appsList) {
|
|
|
|
if (fullcount > 15) break;
|
|
|
|
|
|
|
|
NSString *bundle = nil, *name = nil, *version = nil;
|
|
|
|
NSImage *icon = nil;
|
|
|
|
[self fillAppByUrl:(NSURL*)app bundle:&bundle name:&name version:&version icon:&icon];
|
|
|
|
if (bundle && name) {
|
|
|
|
if ([bundle isEqualToString:defBundle] && [version isEqualToString:defVersion]) continue;
|
|
|
|
NSString *key = [[NSArray arrayWithObjects:bundle, name, nil] componentsJoinedByString:@"|"];
|
|
|
|
if (!version) version = @"";
|
|
|
|
|
|
|
|
NSMutableDictionary *versions = (NSMutableDictionary*)[data objectForKey:key];
|
|
|
|
if (!versions) {
|
|
|
|
versions = [NSMutableDictionary dictionaryWithCapacity:2];
|
|
|
|
[data setValue:versions forKey:key];
|
|
|
|
}
|
|
|
|
if (![versions objectForKey:version]) {
|
|
|
|
[versions setValue:[NSArray arrayWithObjects:name, icon, app, nil] forKey:version];
|
|
|
|
++fullcount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (fullcount || defUrl) {
|
|
|
|
apps = [NSMutableArray arrayWithCapacity:fullcount];
|
|
|
|
for (id key in data) {
|
|
|
|
NSMutableDictionary *val = (NSMutableDictionary*)[data objectForKey:key];
|
|
|
|
for (id ver in val) {
|
|
|
|
NSArray *app = (NSArray*)[val objectForKey:ver];
|
|
|
|
OpenWithApp *a = [[OpenWithApp alloc] init];
|
|
|
|
NSString *fullname = (NSString*)[app objectAtIndex:0], *version = (NSString*)ver;
|
|
|
|
BOOL showVersion = ([val count] > 1);
|
|
|
|
if (!showVersion) {
|
|
|
|
NSError *error = NULL;
|
|
|
|
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"^\\d+\\.\\d+\\.\\d+(\\.\\d+)?$" options:NSRegularExpressionCaseInsensitive error:&error];
|
|
|
|
showVersion = ![regex numberOfMatchesInString:version options:NSMatchingWithoutAnchoringBounds range:{0,[version length]}];
|
|
|
|
}
|
|
|
|
if (showVersion) fullname = [[NSArray arrayWithObjects:fullname, @" (", version, @")", nil] componentsJoinedByString:@""];
|
|
|
|
[a setFullname:fullname];
|
|
|
|
[a setIcon:(NSImage*)[app objectAtIndex:1]];
|
|
|
|
[a setApp:(NSURL*)[app objectAtIndex:2]];
|
|
|
|
[apps addObject:a];
|
|
|
|
[a release];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
[apps sortUsingDescriptors:[NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"fullname" ascending:YES]]];
|
|
|
|
[appsList release];
|
|
|
|
menu = nil;
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) popupAtX:(int)x andY:(int)y {
|
|
|
|
if (![apps count] && !defName) return NO;
|
|
|
|
menu = [[NSMenu alloc] initWithTitle:@"Open With"];
|
|
|
|
|
|
|
|
int index = 0;
|
|
|
|
if (defName) {
|
|
|
|
NSMenuItem *item = [menu insertItemWithTitle:[[NSArray arrayWithObjects:defName, @" (default)", nil] componentsJoinedByString:@""] action:@selector(itemChosen:) keyEquivalent:@"" atIndex:index++];
|
|
|
|
if (defIcon) [item setImage:defIcon];
|
|
|
|
[item setTarget:self];
|
|
|
|
[menu insertItem:[NSMenuItem separatorItem] atIndex:index++];
|
|
|
|
}
|
|
|
|
if ([apps count]) {
|
|
|
|
for (id a in apps) {
|
|
|
|
OpenWithApp *app = (OpenWithApp*)a;
|
|
|
|
NSMenuItem *item = [menu insertItemWithTitle:[a fullname] action:@selector(itemChosen:) keyEquivalent:@"" atIndex:index++];
|
|
|
|
if ([app icon]) [item setImage:[app icon]];
|
|
|
|
[item setTarget:self];
|
|
|
|
}
|
|
|
|
[menu insertItem:[NSMenuItem separatorItem] atIndex:index++];
|
|
|
|
}
|
2016-10-02 15:44:54 +00:00
|
|
|
NSMenuItem *item = [menu insertItemWithTitle:NSlang(lng_mac_choose_program_menu) action:@selector(itemChosen:) keyEquivalent:@"" atIndex:index++];
|
2015-01-21 10:20:23 +00:00
|
|
|
[item setTarget:self];
|
|
|
|
|
|
|
|
[menu popUpMenuPositioningItem:nil atLocation:CGPointMake(x, y) inView:nil];
|
|
|
|
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) itemChosen:(id)sender {
|
|
|
|
NSArray *items = [menu itemArray];
|
|
|
|
NSURL *url = nil;
|
|
|
|
for (int i = 0, l = [items count]; i < l; ++i) {
|
|
|
|
if ([items objectAtIndex:i] == sender) {
|
|
|
|
if (defName) i -= 2;
|
|
|
|
if (i < 0) {
|
|
|
|
url = defUrl;
|
|
|
|
} else if (i < int([apps count])) {
|
|
|
|
url = [(OpenWithApp*)[apps objectAtIndex:i] app];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (url) {
|
|
|
|
[[NSWorkspace sharedWorkspace] openFile:toOpen withApplication:[url path]];
|
|
|
|
} else {
|
2016-10-02 15:44:54 +00:00
|
|
|
objc_openFile(NS2QString(toOpen), true);
|
2015-01-21 10:20:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc {
|
2016-10-02 15:44:54 +00:00
|
|
|
[toOpen release];
|
2015-01-21 10:20:23 +00:00
|
|
|
if (menu) [menu release];
|
2016-10-02 15:44:54 +00:00
|
|
|
[super dealloc];
|
2015-01-21 10:20:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
bool objc_showOpenWithMenu(int x, int y, const QString &f) {
|
2016-10-02 15:44:54 +00:00
|
|
|
@autoreleasepool {
|
|
|
|
|
|
|
|
NSString *file = Q2NSString(f);
|
2015-01-21 10:20:23 +00:00
|
|
|
@try {
|
2016-10-02 15:44:54 +00:00
|
|
|
OpenFileWithInterface *menu = [[[OpenFileWithInterface alloc] init:file] autorelease];
|
2015-01-21 10:20:23 +00:00
|
|
|
QRect r = QApplication::desktop()->screenGeometry(QPoint(x, y));
|
|
|
|
y = r.y() + r.height() - y;
|
|
|
|
return !![menu popupAtX:x andY:y];
|
|
|
|
}
|
|
|
|
@catch (NSException *exception) {
|
|
|
|
}
|
|
|
|
@finally {
|
2016-10-02 15:44:54 +00:00
|
|
|
}
|
|
|
|
|
2015-01-21 10:20:23 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-06-25 07:25:55 +00:00
|
|
|
void objc_showInFinder(const QString &file, const QString &path) {
|
2016-10-02 15:44:54 +00:00
|
|
|
@autoreleasepool {
|
|
|
|
|
|
|
|
[[NSWorkspace sharedWorkspace] selectFile:Q2NSString(file) inFileViewerRootedAtPath:Q2NSString(path)];
|
|
|
|
|
|
|
|
}
|
2014-06-17 06:06:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@interface NSURL(CompareUrls)
|
|
|
|
|
|
|
|
- (BOOL) isEquivalent:(NSURL *)aURL;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation NSURL(CompareUrls)
|
|
|
|
|
|
|
|
- (BOOL) isEquivalent:(NSURL *)aURL {
|
2016-10-02 15:44:54 +00:00
|
|
|
if ([self isEqual:aURL]) return YES;
|
|
|
|
if ([[self scheme] caseInsensitiveCompare:[aURL scheme]] != NSOrderedSame) return NO;
|
|
|
|
if ([[self host] caseInsensitiveCompare:[aURL host]] != NSOrderedSame) return NO;
|
|
|
|
if ([[self path] compare:[aURL path]] != NSOrderedSame) return NO;
|
|
|
|
if ([[self port] compare:[aURL port]] != NSOrderedSame) return NO;
|
|
|
|
if ([[self query] compare:[aURL query]] != NSOrderedSame) return NO;
|
|
|
|
return YES;
|
2014-06-17 06:06:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface ChooseApplicationDelegate : NSObject<NSOpenSavePanelDelegate> {
|
|
|
|
}
|
|
|
|
|
2014-06-18 18:37:44 +00:00
|
|
|
- (id) init:(NSArray *)recommendedApps withPanel:(NSOpenPanel *)creator withSelector:(NSPopUpButton *)menu withGood:(NSTextField *)goodLabel withBad:(NSTextField *)badLabel withIcon:(NSImageView *)badIcon withAccessory:(NSView *)acc;
|
2014-06-17 06:06:01 +00:00
|
|
|
- (BOOL) panel:(id)sender shouldEnableURL:(NSURL *)url;
|
2014-06-18 18:37:44 +00:00
|
|
|
- (void) panelSelectionDidChange:(id)sender;
|
|
|
|
- (void) menuDidClose;
|
2014-06-17 06:06:01 +00:00
|
|
|
- (void) dealloc;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation ChooseApplicationDelegate {
|
2016-10-02 15:44:54 +00:00
|
|
|
BOOL onlyRecommended;
|
|
|
|
NSArray *apps;
|
|
|
|
NSOpenPanel *panel;
|
|
|
|
NSPopUpButton *selector;
|
|
|
|
NSTextField *good, *bad;
|
|
|
|
NSImageView *icon;
|
|
|
|
NSString *recom;
|
|
|
|
NSView *accessory;
|
2014-06-17 06:06:01 +00:00
|
|
|
}
|
|
|
|
|
2014-06-18 18:37:44 +00:00
|
|
|
- (id) init:(NSArray *)recommendedApps withPanel:(NSOpenPanel *)creator withSelector:(NSPopUpButton *)menu withGood:(NSTextField *)goodLabel withBad:(NSTextField *)badLabel withIcon:(NSImageView *)badIcon withAccessory:(NSView *)acc {
|
2016-10-02 15:44:54 +00:00
|
|
|
if (self = [super init]) {
|
|
|
|
onlyRecommended = YES;
|
|
|
|
recom = [NSlang(lng_mac_recommended_apps) copy];
|
|
|
|
apps = recommendedApps;
|
|
|
|
panel = creator;
|
|
|
|
selector = menu;
|
|
|
|
good = goodLabel;
|
|
|
|
bad = badLabel;
|
|
|
|
icon = badIcon;
|
|
|
|
accessory = acc;
|
|
|
|
[selector setAction:@selector(menuDidClose)];
|
|
|
|
}
|
|
|
|
return self;
|
2014-06-17 06:06:01 +00:00
|
|
|
}
|
|
|
|
|
2014-06-18 18:37:44 +00:00
|
|
|
- (BOOL) isRecommended:(NSURL *)url {
|
2016-10-02 15:44:54 +00:00
|
|
|
if (apps) {
|
|
|
|
for (id app in apps) {
|
|
|
|
if ([(NSURL*)app isEquivalent:url]) {
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NO;
|
2014-06-18 18:37:44 +00:00
|
|
|
}
|
|
|
|
|
2014-06-17 06:06:01 +00:00
|
|
|
- (BOOL) panel:(id)sender shouldEnableURL:(NSURL *)url {
|
2016-10-02 15:44:54 +00:00
|
|
|
NSNumber *isDirectory;
|
|
|
|
if ([url getResourceValue:&isDirectory forKey:NSURLIsDirectoryKey error:nil] && isDirectory != nil && [isDirectory boolValue]) {
|
|
|
|
if (onlyRecommended) {
|
|
|
|
CFStringRef ext = CFURLCopyPathExtension((CFURLRef)url);
|
|
|
|
NSNumber *isPackage;
|
|
|
|
if ([url getResourceValue:&isPackage forKey:NSURLIsPackageKey error:nil] && isPackage != nil && [isPackage boolValue]) {
|
|
|
|
return [self isRecommended:url];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
return NO;
|
2014-06-17 06:06:01 +00:00
|
|
|
}
|
|
|
|
|
2014-06-18 18:37:44 +00:00
|
|
|
- (void) panelSelectionDidChange:(id)sender {
|
2016-10-02 15:44:54 +00:00
|
|
|
NSArray *urls = [panel URLs];
|
|
|
|
if ([urls count]) {
|
|
|
|
if ([self isRecommended:[urls firstObject]]) {
|
|
|
|
[bad removeFromSuperview];
|
|
|
|
[icon removeFromSuperview];
|
|
|
|
[accessory addSubview:good];
|
|
|
|
} else {
|
|
|
|
[good removeFromSuperview];
|
|
|
|
[accessory addSubview:bad];
|
|
|
|
[accessory addSubview:icon];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
[good removeFromSuperview];
|
|
|
|
[bad removeFromSuperview];
|
|
|
|
[icon removeFromSuperview];
|
|
|
|
}
|
2014-06-18 18:37:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) menuDidClose {
|
2016-10-02 15:44:54 +00:00
|
|
|
onlyRecommended = [[[selector selectedItem] title] isEqualToString:recom];
|
|
|
|
[self refreshPanelTable];
|
2014-06-18 18:37:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) refreshDataInViews: (NSArray*)subviews {
|
2016-10-02 15:44:54 +00:00
|
|
|
for (id view in subviews) {
|
|
|
|
NSString *cls = [view className];
|
|
|
|
if ([cls isEqualToString:Q2NSString(strNeedToReload())]) {
|
|
|
|
[view reloadData];
|
|
|
|
} else if ([cls isEqualToString:Q2NSString(strNeedToRefresh1())] || [cls isEqualToString:Q2NSString(strNeedToRefresh2())]) {
|
|
|
|
[view reloadData];
|
|
|
|
return YES;
|
|
|
|
} else {
|
|
|
|
NSArray *next = [view subviews];
|
|
|
|
if ([next count] && [self refreshDataInViews:next]) {
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NO;
|
2014-06-18 18:37:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void) refreshPanelTable {
|
2016-10-02 15:44:54 +00:00
|
|
|
@autoreleasepool {
|
|
|
|
|
|
|
|
[self refreshDataInViews:[[panel contentView] subviews]];
|
|
|
|
[panel validateVisibleColumns];
|
|
|
|
|
|
|
|
}
|
2014-06-18 18:37:44 +00:00
|
|
|
}
|
|
|
|
|
2014-06-17 06:06:01 +00:00
|
|
|
- (void) dealloc {
|
2016-10-02 15:44:54 +00:00
|
|
|
if (apps) {
|
|
|
|
[apps release];
|
|
|
|
[recom release];
|
|
|
|
}
|
|
|
|
[super dealloc];
|
2014-06-17 06:06:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2014-06-25 07:25:55 +00:00
|
|
|
void objc_openFile(const QString &f, bool openwith) {
|
2016-10-02 15:44:54 +00:00
|
|
|
@autoreleasepool {
|
2016-01-11 15:43:29 +00:00
|
|
|
|
2016-10-02 15:44:54 +00:00
|
|
|
NSString *file = Q2NSString(f);
|
|
|
|
if (openwith || [[NSWorkspace sharedWorkspace] openFile:file] == NO) {
|
|
|
|
@try {
|
|
|
|
NSURL *url = [NSURL fileURLWithPath:file];
|
|
|
|
NSString *ext = [url pathExtension];
|
|
|
|
NSArray *names = [url pathComponents];
|
|
|
|
NSString *name = [names count] ? [names lastObject] : @"";
|
|
|
|
NSArray *apps = (NSArray*)LSCopyApplicationURLsForURL(CFURLRef(url), kLSRolesAll);
|
2016-01-11 15:43:29 +00:00
|
|
|
|
2016-10-02 15:44:54 +00:00
|
|
|
NSOpenPanel *openPanel = [NSOpenPanel openPanel];
|
2014-12-08 09:45:13 +00:00
|
|
|
|
2016-04-17 17:52:17 +00:00
|
|
|
NSRect fullRect = { { 0., 0. }, { st::macAccessoryWidth, st::macAccessoryHeight } };
|
2014-12-08 09:45:13 +00:00
|
|
|
NSView *accessory = [[NSView alloc] initWithFrame:fullRect];
|
2016-01-11 15:43:29 +00:00
|
|
|
|
2016-10-02 15:44:54 +00:00
|
|
|
[accessory setAutoresizesSubviews:YES];
|
|
|
|
|
|
|
|
NSPopUpButton *selector = [[NSPopUpButton alloc] init];
|
|
|
|
[accessory addSubview:selector];
|
|
|
|
[selector addItemWithTitle:NSlang(lng_mac_recommended_apps)];
|
|
|
|
[selector addItemWithTitle:NSlang(lng_mac_all_apps)];
|
|
|
|
[selector sizeToFit];
|
|
|
|
|
|
|
|
NSTextField *enableLabel = [[NSTextField alloc] init];
|
|
|
|
[accessory addSubview:enableLabel];
|
|
|
|
[enableLabel setStringValue:NSlang(lng_mac_enable_filter)];
|
|
|
|
[enableLabel setFont:[selector font]];
|
|
|
|
[enableLabel setBezeled:NO];
|
|
|
|
[enableLabel setDrawsBackground:NO];
|
|
|
|
[enableLabel setEditable:NO];
|
|
|
|
[enableLabel setSelectable:NO];
|
|
|
|
[enableLabel sizeToFit];
|
|
|
|
|
|
|
|
NSRect selectorFrame = [selector frame], enableFrame = [enableLabel frame];
|
|
|
|
enableFrame.size.width += st::macEnableFilterAdd;
|
|
|
|
enableFrame.origin.x = (fullRect.size.width - selectorFrame.size.width - enableFrame.size.width) / 2.;
|
|
|
|
selectorFrame.origin.x = (fullRect.size.width - selectorFrame.size.width + enableFrame.size.width) / 2.;
|
|
|
|
enableFrame.origin.y = fullRect.size.height - selectorFrame.size.height - st::macEnableFilterTop + (selectorFrame.size.height - enableFrame.size.height) / 2.;
|
|
|
|
selectorFrame.origin.y = fullRect.size.height - selectorFrame.size.height - st::macSelectorTop;
|
|
|
|
[enableLabel setFrame:enableFrame];
|
|
|
|
[enableLabel setAutoresizingMask:NSViewMinXMargin|NSViewMaxXMargin];
|
|
|
|
[selector setFrame:selectorFrame];
|
|
|
|
[selector setAutoresizingMask:NSViewMinXMargin|NSViewMaxXMargin];
|
|
|
|
|
|
|
|
NSButton *button = [[NSButton alloc] init];
|
|
|
|
[accessory addSubview:button];
|
|
|
|
[button setButtonType:NSSwitchButton];
|
|
|
|
[button setFont:[selector font]];
|
|
|
|
[button setTitle:NSlang(lng_mac_always_open_with)];
|
|
|
|
[button sizeToFit];
|
|
|
|
NSRect alwaysRect = [button frame];
|
|
|
|
alwaysRect.origin.x = (fullRect.size.width - alwaysRect.size.width) / 2;
|
|
|
|
alwaysRect.origin.y = selectorFrame.origin.y - alwaysRect.size.height - st::macAlwaysThisAppTop;
|
|
|
|
[button setFrame:alwaysRect];
|
|
|
|
[button setAutoresizingMask:NSViewMinXMargin|NSViewMaxXMargin];
|
2016-08-31 17:58:46 +00:00
|
|
|
#ifdef OS_MAC_STORE
|
2016-10-02 15:44:54 +00:00
|
|
|
[button setHidden:YES];
|
2016-08-31 17:58:46 +00:00
|
|
|
#endif // OS_MAC_STORE
|
2016-10-02 15:44:54 +00:00
|
|
|
NSTextField *goodLabel = [[NSTextField alloc] init];
|
|
|
|
[goodLabel setStringValue:Q2NSString(lng_mac_this_app_can_open(lt_file, NS2QString(name)))];
|
|
|
|
[goodLabel setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
|
|
|
|
[goodLabel setBezeled:NO];
|
|
|
|
[goodLabel setDrawsBackground:NO];
|
|
|
|
[goodLabel setEditable:NO];
|
|
|
|
[goodLabel setSelectable:NO];
|
|
|
|
[goodLabel sizeToFit];
|
|
|
|
NSRect goodFrame = [goodLabel frame];
|
|
|
|
goodFrame.origin.x = (fullRect.size.width - goodFrame.size.width) / 2.;
|
|
|
|
goodFrame.origin.y = alwaysRect.origin.y - goodFrame.size.height - st::macAppHintTop;
|
|
|
|
[goodLabel setFrame:goodFrame];
|
|
|
|
|
|
|
|
NSTextField *badLabel = [[NSTextField alloc] init];
|
|
|
|
[badLabel setStringValue:Q2NSString(lng_mac_not_known_app(lt_file, NS2QString(name)))];
|
|
|
|
[badLabel setFont:[goodLabel font]];
|
|
|
|
[badLabel setBezeled:NO];
|
|
|
|
[badLabel setDrawsBackground:NO];
|
|
|
|
[badLabel setEditable:NO];
|
|
|
|
[badLabel setSelectable:NO];
|
|
|
|
[badLabel sizeToFit];
|
|
|
|
NSImageView *badIcon = [[NSImageView alloc] init];
|
|
|
|
NSImage *badImage = [NSImage imageNamed:NSImageNameCaution];
|
|
|
|
[badIcon setImage:badImage];
|
|
|
|
[badIcon setFrame:NSMakeRect(0, 0, st::macCautionIconSize, st::macCautionIconSize)];
|
|
|
|
|
|
|
|
NSRect badFrame = [badLabel frame], badIconFrame = [badIcon frame];
|
|
|
|
badFrame.origin.x = (fullRect.size.width - badFrame.size.width + badIconFrame.size.width) / 2.;
|
|
|
|
badIconFrame.origin.x = (fullRect.size.width - badFrame.size.width - badIconFrame.size.width) / 2.;
|
|
|
|
badFrame.origin.y = alwaysRect.origin.y - badFrame.size.height - st::macAppHintTop;
|
|
|
|
badIconFrame.origin.y = badFrame.origin.y;
|
|
|
|
[badLabel setFrame:badFrame];
|
|
|
|
[badIcon setFrame:badIconFrame];
|
2014-12-08 09:45:13 +00:00
|
|
|
|
|
|
|
[openPanel setAccessoryView:accessory];
|
|
|
|
|
2016-10-02 15:44:54 +00:00
|
|
|
ChooseApplicationDelegate *delegate = [[ChooseApplicationDelegate alloc] init:apps withPanel:openPanel withSelector:selector withGood:goodLabel withBad:badLabel withIcon:badIcon withAccessory:accessory];
|
|
|
|
[openPanel setDelegate:delegate];
|
|
|
|
|
|
|
|
[openPanel setCanChooseDirectories:NO];
|
|
|
|
[openPanel setCanChooseFiles:YES];
|
|
|
|
[openPanel setAllowsMultipleSelection:NO];
|
|
|
|
[openPanel setResolvesAliases:YES];
|
|
|
|
[openPanel setTitle:NSlang(lng_mac_choose_app)];
|
|
|
|
[openPanel setMessage:Q2NSString(lng_mac_choose_text(lt_file, NS2QString(name)))];
|
|
|
|
|
|
|
|
NSArray *appsPaths = [[NSFileManager defaultManager] URLsForDirectory:NSApplicationDirectory inDomains:NSLocalDomainMask];
|
|
|
|
if ([appsPaths count]) [openPanel setDirectoryURL:[appsPaths firstObject]];
|
|
|
|
[openPanel beginWithCompletionHandler:^(NSInteger result){
|
|
|
|
if (result == NSFileHandlingPanelOKButton) {
|
|
|
|
if ([[openPanel URLs] count] > 0) {
|
|
|
|
NSURL *app = [[openPanel URLs] objectAtIndex:0];
|
|
|
|
NSString *path = [app path];
|
|
|
|
if ([button state] == NSOnState) {
|
|
|
|
NSArray *UTIs = (NSArray *)UTTypeCreateAllIdentifiersForTag(kUTTagClassFilenameExtension,
|
|
|
|
(CFStringRef)ext,
|
|
|
|
nil);
|
|
|
|
for (NSString *UTI in UTIs) {
|
2014-12-08 09:45:13 +00:00
|
|
|
OSStatus result = LSSetDefaultRoleHandlerForContentType((CFStringRef)UTI,
|
|
|
|
kLSRolesAll,
|
|
|
|
(CFStringRef)[[NSBundle bundleWithPath:path] bundleIdentifier]);
|
2016-10-02 15:44:54 +00:00
|
|
|
DEBUG_LOG(("App Info: set default handler for '%1' UTI result: %2").arg(NS2QString(UTI)).arg(result));
|
|
|
|
}
|
|
|
|
|
|
|
|
[UTIs release];
|
|
|
|
}
|
|
|
|
[[NSWorkspace sharedWorkspace] openFile:file withApplication:[app path]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
[selector release];
|
|
|
|
[button release];
|
|
|
|
[enableLabel release];
|
|
|
|
[goodLabel release];
|
|
|
|
[badLabel release];
|
|
|
|
[badIcon release];
|
|
|
|
[accessory release];
|
|
|
|
[delegate release];
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
@catch (NSException *exception) {
|
|
|
|
[[NSWorkspace sharedWorkspace] openFile:file];
|
|
|
|
}
|
|
|
|
@finally {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2014-06-17 06:06:01 +00:00
|
|
|
}
|
2014-06-18 18:37:44 +00:00
|
|
|
|
2014-09-20 21:31:03 +00:00
|
|
|
void objc_start() {
|
|
|
|
_sharedDelegate = [[ApplicationDelegate alloc] init];
|
|
|
|
[[NSApplication sharedApplication] setDelegate:_sharedDelegate];
|
2014-11-12 20:30:26 +00:00
|
|
|
[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver: _sharedDelegate
|
|
|
|
selector: @selector(receiveWakeNote:)
|
|
|
|
name: NSWorkspaceDidWakeNotification object: NULL];
|
2014-09-20 21:31:03 +00:00
|
|
|
}
|
|
|
|
|
2015-11-26 17:34:52 +00:00
|
|
|
namespace {
|
|
|
|
NSURL *_downloadPathUrl = nil;
|
|
|
|
}
|
|
|
|
|
2014-06-18 18:37:44 +00:00
|
|
|
void objc_finish() {
|
2014-09-20 21:31:03 +00:00
|
|
|
[_sharedDelegate release];
|
2015-11-26 17:34:52 +00:00
|
|
|
if (_downloadPathUrl) {
|
|
|
|
[_downloadPathUrl stopAccessingSecurityScopedResource];
|
|
|
|
_downloadPathUrl = nil;
|
|
|
|
}
|
2014-06-18 18:37:44 +00:00
|
|
|
}
|
2014-06-25 07:25:55 +00:00
|
|
|
|
2014-12-03 13:10:32 +00:00
|
|
|
void objc_registerCustomScheme() {
|
2016-10-18 07:56:38 +00:00
|
|
|
#ifndef TDESKTOP_DISABLE_REGISTER_CUSTOM_SCHEME
|
2014-12-08 09:45:13 +00:00
|
|
|
OSStatus result = LSSetDefaultHandlerForURLScheme(CFSTR("tg"), (CFStringRef)[[NSBundle mainBundle] bundleIdentifier]);
|
|
|
|
DEBUG_LOG(("App Info: set default handler for 'tg' scheme result: %1").arg(result));
|
2016-10-18 07:56:38 +00:00
|
|
|
#endif // !TDESKTOP_DISABLE_REGISTER_CUSTOM_SCHEME
|
2014-12-03 13:10:32 +00:00
|
|
|
}
|
|
|
|
|
2016-01-30 18:24:18 +00:00
|
|
|
BOOL _execUpdater(BOOL update = YES, const QString &crashreport = QString()) {
|
2016-10-02 15:44:54 +00:00
|
|
|
@autoreleasepool {
|
|
|
|
|
2014-06-25 07:25:55 +00:00
|
|
|
NSString *path = @"", *args = @"";
|
|
|
|
@try {
|
|
|
|
path = [[NSBundle mainBundle] bundlePath];
|
|
|
|
if (!path) {
|
|
|
|
LOG(("Could not get bundle path!!"));
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
path = [path stringByAppendingString:@"/Contents/Frameworks/Updater"];
|
|
|
|
|
2016-10-02 15:44:54 +00:00
|
|
|
NSMutableArray *args = [[NSMutableArray alloc] initWithObjects:@"-workpath", Q2NSString(cWorkingDir()), @"-procid", nil];
|
2014-06-25 07:25:55 +00:00
|
|
|
[args addObject:[NSString stringWithFormat:@"%d", [[NSProcessInfo processInfo] processIdentifier]]];
|
2014-12-19 22:03:50 +00:00
|
|
|
if (cRestartingToSettings()) [args addObject:@"-tosettings"];
|
2014-06-25 07:25:55 +00:00
|
|
|
if (!update) [args addObject:@"-noupdate"];
|
2016-01-11 15:43:29 +00:00
|
|
|
if (cLaunchMode() == LaunchModeAutoStart) [args addObject:@"-autostart"];
|
2014-06-25 07:25:55 +00:00
|
|
|
if (cDebug()) [args addObject:@"-debug"];
|
2015-01-27 16:58:58 +00:00
|
|
|
if (cStartInTray()) [args addObject:@"-startintray"];
|
2015-04-02 10:33:19 +00:00
|
|
|
if (cTestMode()) [args addObject:@"-testmode"];
|
|
|
|
if (cDataFile() != qsl("data")) {
|
2014-06-25 07:25:55 +00:00
|
|
|
[args addObject:@"-key"];
|
2016-10-02 15:44:54 +00:00
|
|
|
[args addObject:Q2NSString(cDataFile())];
|
2014-06-25 07:25:55 +00:00
|
|
|
}
|
2016-01-30 18:24:18 +00:00
|
|
|
if (!crashreport.isEmpty()) {
|
|
|
|
[args addObject:@"-crashreport"];
|
2016-10-02 15:44:54 +00:00
|
|
|
[args addObject:Q2NSString(crashreport)];
|
2016-01-30 18:24:18 +00:00
|
|
|
}
|
2014-06-25 07:25:55 +00:00
|
|
|
|
2016-10-02 15:44:54 +00:00
|
|
|
DEBUG_LOG(("Application Info: executing %1 %2").arg(NS2QString(path)).arg(NS2QString([args componentsJoinedByString:@" "])));
|
2016-02-08 10:50:56 +00:00
|
|
|
Logs::closeMain();
|
|
|
|
SignalHandlers::finish();
|
2014-06-25 07:25:55 +00:00
|
|
|
if (![NSTask launchedTaskWithLaunchPath:path arguments:args]) {
|
2016-10-02 15:44:54 +00:00
|
|
|
DEBUG_LOG(("Task not launched while executing %1 %2").arg(NS2QString(path)).arg(NS2QString([args componentsJoinedByString:@" "])));
|
2014-06-25 07:25:55 +00:00
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@catch (NSException *exception) {
|
2016-10-02 15:44:54 +00:00
|
|
|
LOG(("Exception caught while executing %1 %2").arg(NS2QString(path)).arg(NS2QString(args)));
|
2014-06-25 07:25:55 +00:00
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
@finally {
|
2016-10-02 15:44:54 +00:00
|
|
|
}
|
|
|
|
|
2014-06-25 07:25:55 +00:00
|
|
|
}
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool objc_execUpdater() {
|
|
|
|
return !!_execUpdater();
|
|
|
|
}
|
|
|
|
|
2016-01-30 18:24:18 +00:00
|
|
|
void objc_execTelegram(const QString &crashreport) {
|
2016-08-31 17:58:46 +00:00
|
|
|
#ifndef OS_MAC_STORE
|
2016-01-30 18:24:18 +00:00
|
|
|
_execUpdater(NO, crashreport);
|
2016-08-31 17:58:46 +00:00
|
|
|
#else // OS_MAC_STORE
|
2016-10-02 15:44:54 +00:00
|
|
|
@autoreleasepool {
|
|
|
|
|
2016-08-31 17:58:46 +00:00
|
|
|
NSDictionary *conf = [NSDictionary dictionaryWithObject:[NSArray array] forKey:NSWorkspaceLaunchConfigurationArguments];
|
2016-10-02 15:44:54 +00:00
|
|
|
[[NSWorkspace sharedWorkspace] launchApplicationAtURL:[NSURL fileURLWithPath:Q2NSString(cExeDir() + cExeName())] options:NSWorkspaceLaunchAsync | NSWorkspaceLaunchNewInstance configuration:conf error:0];
|
|
|
|
|
|
|
|
}
|
2016-08-31 17:58:46 +00:00
|
|
|
#endif // OS_MAC_STORE
|
2014-06-25 07:25:55 +00:00
|
|
|
}
|
|
|
|
|
2015-08-12 18:02:20 +00:00
|
|
|
void objc_activateProgram(WId winId) {
|
2014-06-25 07:25:55 +00:00
|
|
|
[NSApp activateIgnoringOtherApps:YES];
|
2015-08-12 18:02:20 +00:00
|
|
|
if (winId) {
|
|
|
|
NSWindow *w = [reinterpret_cast<NSView*>(winId) window];
|
|
|
|
[w makeKeyAndOrderFront:NSApp];
|
|
|
|
}
|
2014-06-25 07:25:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool objc_moveFile(const QString &from, const QString &to) {
|
2016-10-02 15:44:54 +00:00
|
|
|
@autoreleasepool {
|
|
|
|
|
|
|
|
NSString *f = Q2NSString(from), *t = Q2NSString(to);
|
2014-06-25 07:25:55 +00:00
|
|
|
if ([[NSFileManager defaultManager] fileExistsAtPath:t]) {
|
|
|
|
NSData *data = [NSData dataWithContentsOfFile:f];
|
|
|
|
if (data) {
|
|
|
|
if ([data writeToFile:t atomically:YES]) {
|
|
|
|
if ([[NSFileManager defaultManager] removeItemAtPath:f error:nil]) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ([[NSFileManager defaultManager] moveItemAtPath:f toPath:t error:nil]) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2016-10-02 15:44:54 +00:00
|
|
|
|
|
|
|
}
|
2014-06-25 07:25:55 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void objc_deleteDir(const QString &dir) {
|
2016-10-02 15:44:54 +00:00
|
|
|
@autoreleasepool {
|
|
|
|
|
|
|
|
[[NSFileManager defaultManager] removeItemAtPath:Q2NSString(dir) error:nil];
|
|
|
|
|
|
|
|
}
|
2014-06-25 07:25:55 +00:00
|
|
|
}
|
|
|
|
|
2016-01-30 18:24:18 +00:00
|
|
|
double objc_appkitVersion() {
|
|
|
|
return NSAppKitVersionNumber;
|
|
|
|
}
|
|
|
|
|
2016-08-31 17:58:46 +00:00
|
|
|
QString objc_documentsPath() {
|
|
|
|
NSURL *url = [[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:YES error:nil];
|
|
|
|
if (url) {
|
|
|
|
return QString::fromUtf8([[url path] fileSystemRepresentation]) + '/';
|
|
|
|
}
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2014-06-25 07:25:55 +00:00
|
|
|
QString objc_appDataPath() {
|
|
|
|
NSURL *url = [[NSFileManager defaultManager] URLForDirectory:NSApplicationSupportDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:YES error:nil];
|
|
|
|
if (url) {
|
2016-05-04 10:41:41 +00:00
|
|
|
return QString::fromUtf8([[url path] fileSystemRepresentation]) + '/' + str_const_toString(AppName) + '/';
|
2014-06-25 07:25:55 +00:00
|
|
|
}
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2014-09-30 14:11:09 +00:00
|
|
|
QString objc_downloadPath() {
|
|
|
|
NSURL *url = [[NSFileManager defaultManager] URLForDirectory:NSDownloadsDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:YES error:nil];
|
|
|
|
if (url) {
|
2016-05-04 10:41:41 +00:00
|
|
|
return QString::fromUtf8([[url path] fileSystemRepresentation]) + '/' + str_const_toString(AppName) + '/';
|
2014-06-25 07:25:55 +00:00
|
|
|
}
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString objc_currentCountry() {
|
|
|
|
NSLocale *currentLocale = [NSLocale currentLocale]; // get the current locale.
|
|
|
|
NSString *countryCode = [currentLocale objectForKey:NSLocaleCountryCode];
|
2016-10-02 15:44:54 +00:00
|
|
|
return countryCode ? NS2QString(countryCode) : QString();
|
2014-06-25 07:25:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QString objc_currentLang() {
|
|
|
|
NSLocale *currentLocale = [NSLocale currentLocale]; // get the current locale.
|
|
|
|
NSString *currentLang = [currentLocale objectForKey:NSLocaleLanguageCode];
|
2016-10-02 15:44:54 +00:00
|
|
|
return currentLang ? NS2QString(currentLang) : QString();
|
2014-06-25 07:25:55 +00:00
|
|
|
}
|
2014-09-30 14:13:47 +00:00
|
|
|
|
2015-11-26 17:34:52 +00:00
|
|
|
QByteArray objc_downloadPathBookmark(const QString &path) {
|
2016-08-31 17:58:46 +00:00
|
|
|
#ifndef OS_MAC_STORE
|
2015-11-26 17:34:52 +00:00
|
|
|
return QByteArray();
|
2016-08-31 17:58:46 +00:00
|
|
|
#else // OS_MAC_STORE
|
|
|
|
NSURL *url = [NSURL fileURLWithPath:[NSString stringWithUTF8String:path.toUtf8().constData()] isDirectory:YES];
|
|
|
|
if (!url) return QByteArray();
|
|
|
|
|
|
|
|
NSError *error = nil;
|
|
|
|
NSData *data = [url bookmarkDataWithOptions:NSURLBookmarkCreationWithSecurityScope includingResourceValuesForKeys:nil relativeToURL:nil error:&error];
|
|
|
|
return data ? QByteArray::fromNSData(data) : QByteArray();
|
|
|
|
#endif // OS_MAC_STORE
|
2015-11-26 17:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QByteArray objc_pathBookmark(const QString &path) {
|
2016-08-31 17:58:46 +00:00
|
|
|
#ifndef OS_MAC_STORE
|
2015-11-26 17:34:52 +00:00
|
|
|
return QByteArray();
|
2016-08-31 17:58:46 +00:00
|
|
|
#else // OS_MAC_STORE
|
|
|
|
NSURL *url = [NSURL fileURLWithPath:[NSString stringWithUTF8String:path.toUtf8().constData()]];
|
|
|
|
if (!url) return QByteArray();
|
|
|
|
|
|
|
|
NSError *error = nil;
|
|
|
|
NSData *data = [url bookmarkDataWithOptions:(NSURLBookmarkCreationWithSecurityScope | NSURLBookmarkCreationSecurityScopeAllowOnlyReadAccess) includingResourceValuesForKeys:nil relativeToURL:nil error:&error];
|
|
|
|
return data ? QByteArray::fromNSData(data) : QByteArray();
|
|
|
|
#endif // OS_MAC_STORE
|
2015-11-26 17:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void objc_downloadPathEnableAccess(const QByteArray &bookmark) {
|
2016-08-31 17:58:46 +00:00
|
|
|
#ifdef OS_MAC_STORE
|
|
|
|
if (bookmark.isEmpty()) return;
|
|
|
|
|
|
|
|
BOOL isStale = NO;
|
|
|
|
NSError *error = nil;
|
|
|
|
NSURL *url = [NSURL URLByResolvingBookmarkData:bookmark.toNSData() options:NSURLBookmarkResolutionWithSecurityScope relativeToURL:nil bookmarkDataIsStale:&isStale error:&error];
|
|
|
|
if (!url) return;
|
|
|
|
|
|
|
|
if ([url startAccessingSecurityScopedResource]) {
|
|
|
|
if (_downloadPathUrl) {
|
|
|
|
[_downloadPathUrl stopAccessingSecurityScopedResource];
|
|
|
|
}
|
|
|
|
_downloadPathUrl = url;
|
|
|
|
|
2016-10-02 15:44:54 +00:00
|
|
|
Global::SetDownloadPath(NS2QString([_downloadPathUrl path]) + '/');
|
2016-08-31 17:58:46 +00:00
|
|
|
if (isStale) {
|
|
|
|
NSData *data = [_downloadPathUrl bookmarkDataWithOptions:NSURLBookmarkCreationWithSecurityScope includingResourceValuesForKeys:nil relativeToURL:nil error:&error];
|
|
|
|
if (data) {
|
2016-09-20 15:14:00 +00:00
|
|
|
Global::SetDownloadPathBookmark(QByteArray::fromNSData(data));
|
2016-08-31 17:58:46 +00:00
|
|
|
Local::writeUserSettings();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // OS_MAC_STORE
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef OS_MAC_STORE
|
|
|
|
namespace {
|
|
|
|
QMutex _bookmarksMutex;
|
2015-11-26 17:34:52 +00:00
|
|
|
}
|
|
|
|
|
2016-09-02 16:57:44 +00:00
|
|
|
class objc_FileBookmark::objc_FileBookmarkData {
|
2016-08-31 17:58:46 +00:00
|
|
|
public:
|
|
|
|
~objc_FileBookmarkData() {
|
|
|
|
if (url) [url release];
|
|
|
|
}
|
|
|
|
NSURL *url = nil;
|
|
|
|
QString name;
|
|
|
|
QByteArray bookmark;
|
|
|
|
int counter = 0;
|
|
|
|
};
|
|
|
|
#endif // OS_MAC_STORE
|
|
|
|
|
2015-11-26 17:34:52 +00:00
|
|
|
objc_FileBookmark::objc_FileBookmark(const QByteArray &bookmark) {
|
2016-08-31 17:58:46 +00:00
|
|
|
#ifdef OS_MAC_STORE
|
|
|
|
if (bookmark.isEmpty()) return;
|
|
|
|
|
|
|
|
BOOL isStale = NO;
|
|
|
|
NSError *error = nil;
|
|
|
|
NSURL *url = [NSURL URLByResolvingBookmarkData:bookmark.toNSData() options:NSURLBookmarkResolutionWithSecurityScope relativeToURL:nil bookmarkDataIsStale:&isStale error:&error];
|
|
|
|
if (!url) return;
|
|
|
|
|
|
|
|
if ([url startAccessingSecurityScopedResource]) {
|
|
|
|
data = new objc_FileBookmarkData();
|
|
|
|
data->url = [url retain];
|
2016-10-02 15:44:54 +00:00
|
|
|
data->name = NS2QString([url path]);
|
2016-08-31 17:58:46 +00:00
|
|
|
data->bookmark = bookmark;
|
|
|
|
[url stopAccessingSecurityScopedResource];
|
|
|
|
}
|
|
|
|
#endif // OS_MAC_STORE
|
2015-11-26 17:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool objc_FileBookmark::valid() const {
|
2016-08-31 17:58:46 +00:00
|
|
|
if (enable()) {
|
|
|
|
disable();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2015-11-26 17:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool objc_FileBookmark::enable() const {
|
2016-08-31 17:58:46 +00:00
|
|
|
#ifndef OS_MAC_STORE
|
2015-11-26 17:34:52 +00:00
|
|
|
return true;
|
2016-08-31 17:58:46 +00:00
|
|
|
#else // OS_MAC_STORE
|
|
|
|
if (!data) return false;
|
|
|
|
|
|
|
|
QMutexLocker lock(&_bookmarksMutex);
|
|
|
|
if (data->counter > 0 || [data->url startAccessingSecurityScopedResource] == YES) {
|
|
|
|
++data->counter;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
#endif // OS_MAC_STORE
|
2015-11-26 17:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void objc_FileBookmark::disable() const {
|
2016-08-31 17:58:46 +00:00
|
|
|
#ifdef OS_MAC_STORE
|
|
|
|
if (!data) return;
|
|
|
|
|
|
|
|
QMutexLocker lock(&_bookmarksMutex);
|
|
|
|
if (data->counter > 0) {
|
|
|
|
--data->counter;
|
|
|
|
if (!data->counter) {
|
|
|
|
[data->url stopAccessingSecurityScopedResource];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // OS_MAC_STORE
|
2015-11-26 17:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const QString &objc_FileBookmark::name(const QString &original) const {
|
2016-08-31 17:58:46 +00:00
|
|
|
#ifndef OS_MAC_STORE
|
2015-11-26 17:34:52 +00:00
|
|
|
return original;
|
2016-08-31 17:58:46 +00:00
|
|
|
#else // OS_MAC_STORE
|
|
|
|
return (data && !data->name.isEmpty()) ? data->name : original;
|
|
|
|
#endif // OS_MAC_STORE
|
2015-11-26 17:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QByteArray objc_FileBookmark::bookmark() const {
|
2016-08-31 17:58:46 +00:00
|
|
|
#ifndef OS_MAC_STORE
|
2015-11-26 17:34:52 +00:00
|
|
|
return QByteArray();
|
2016-08-31 17:58:46 +00:00
|
|
|
#else // OS_MAC_STORE
|
|
|
|
return data ? data->bookmark : QByteArray();
|
|
|
|
#endif // OS_MAC_STORE
|
2015-11-26 17:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
objc_FileBookmark::~objc_FileBookmark() {
|
2016-08-31 17:58:46 +00:00
|
|
|
#ifdef OS_MAC_STORE
|
|
|
|
if (data && data->counter > 0) {
|
|
|
|
LOG(("Did not disable() bookmark, counter: %1").arg(data->counter));
|
|
|
|
[data->url stopAccessingSecurityScopedResource];
|
|
|
|
}
|
|
|
|
#endif // OS_MAC_STORE
|
2015-11-26 17:34:52 +00:00
|
|
|
}
|