Reformat all Objective-C++ files with clang-format.
clang-format -style=Google -i src/*/*.mm
This commit is contained in:
parent
0a778e2901
commit
b96ec7555a
|
@ -62,16 +62,17 @@
|
|||
|
||||
#include <QtDebug>
|
||||
|
||||
QDebug operator <<(QDebug dbg, NSObject* object) {
|
||||
QString ns_format = [[NSString stringWithFormat: @"%@", object] UTF8String];
|
||||
QDebug operator<<(QDebug dbg, NSObject* object) {
|
||||
QString ns_format = [[NSString stringWithFormat:@"%@", object] UTF8String];
|
||||
dbg.nospace() << ns_format;
|
||||
return dbg.space();
|
||||
}
|
||||
|
||||
// Capture global media keys on Mac (Cocoa only!)
|
||||
// See: http://www.rogueamoeba.com/utm/2007/09/29/apple-keyboard-media-key-event-handling/
|
||||
// See:
|
||||
// http://www.rogueamoeba.com/utm/2007/09/29/apple-keyboard-media-key-event-handling/
|
||||
|
||||
@interface MacApplication :NSApplication {
|
||||
@interface MacApplication : NSApplication {
|
||||
PlatformInterface* application_handler_;
|
||||
AppDelegate* delegate_;
|
||||
// shortcut_handler_ only used to temporarily save it
|
||||
|
@ -79,18 +80,16 @@ QDebug operator <<(QDebug dbg, NSObject* object) {
|
|||
MacGlobalShortcutBackend* shortcut_handler_;
|
||||
}
|
||||
|
||||
- (MacGlobalShortcutBackend*) shortcut_handler;
|
||||
- (void) SetShortcutHandler: (MacGlobalShortcutBackend*)handler;
|
||||
- (MacGlobalShortcutBackend*)shortcut_handler;
|
||||
- (void)SetShortcutHandler:(MacGlobalShortcutBackend*)handler;
|
||||
|
||||
- (PlatformInterface*) application_handler;
|
||||
- (void) SetApplicationHandler: (PlatformInterface*)handler;
|
||||
- (PlatformInterface*)application_handler;
|
||||
- (void)SetApplicationHandler:(PlatformInterface*)handler;
|
||||
|
||||
@end
|
||||
|
||||
#ifdef HAVE_BREAKPAD
|
||||
static bool BreakpadCallback(int, int, mach_port_t, void*) {
|
||||
return true;
|
||||
}
|
||||
static bool BreakpadCallback(int, int, mach_port_t, void*) { return true; }
|
||||
|
||||
static BreakpadRef InitBreakpad() {
|
||||
ScopedNSAutoreleasePool pool;
|
||||
|
@ -103,11 +102,11 @@ static BreakpadRef InitBreakpad() {
|
|||
[pool release];
|
||||
return breakpad;
|
||||
}
|
||||
#endif // HAVE_BREAKPAD
|
||||
#endif // HAVE_BREAKPAD
|
||||
|
||||
@implementation AppDelegate
|
||||
|
||||
- (id) init {
|
||||
- (id)init {
|
||||
if ((self = [super init])) {
|
||||
application_handler_ = nil;
|
||||
shortcut_handler_ = nil;
|
||||
|
@ -116,7 +115,7 @@ static BreakpadRef InitBreakpad() {
|
|||
return self;
|
||||
}
|
||||
|
||||
- (id) initWithHandler: (PlatformInterface*)handler {
|
||||
- (id)initWithHandler:(PlatformInterface*)handler {
|
||||
application_handler_ = handler;
|
||||
|
||||
#ifdef HAVE_BREAKPAD
|
||||
|
@ -124,45 +123,48 @@ static BreakpadRef InitBreakpad() {
|
|||
#endif
|
||||
|
||||
// Register defaults for the whitelist of apps that want to use media keys
|
||||
[[NSUserDefaults standardUserDefaults] registerDefaults:[NSDictionary dictionaryWithObjectsAndKeys:
|
||||
[SPMediaKeyTap defaultMediaKeyUserBundleIdentifiers], kMediaKeyUsingBundleIdentifiersDefaultsKey,
|
||||
nil]];
|
||||
[[NSUserDefaults standardUserDefaults]
|
||||
registerDefaults:
|
||||
[NSDictionary
|
||||
dictionaryWithObjectsAndKeys:
|
||||
[SPMediaKeyTap defaultMediaKeyUserBundleIdentifiers],
|
||||
kMediaKeyUsingBundleIdentifiersDefaultsKey, nil]];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL) applicationShouldHandleReopen: (NSApplication*)app hasVisibleWindows:(BOOL)flag {
|
||||
- (BOOL)applicationShouldHandleReopen:(NSApplication*)app
|
||||
hasVisibleWindows:(BOOL)flag {
|
||||
if (application_handler_) {
|
||||
application_handler_->Activate();
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void) setDockMenu: (NSMenu*)menu {
|
||||
- (void)setDockMenu:(NSMenu*)menu {
|
||||
dock_menu_ = menu;
|
||||
}
|
||||
|
||||
- (NSMenu*) applicationDockMenu: (NSApplication*)sender {
|
||||
- (NSMenu*)applicationDockMenu:(NSApplication*)sender {
|
||||
return dock_menu_;
|
||||
}
|
||||
|
||||
- (void) setShortcutHandler: (MacGlobalShortcutBackend*)backend {
|
||||
- (void)setShortcutHandler:(MacGlobalShortcutBackend*)backend {
|
||||
shortcut_handler_ = backend;
|
||||
}
|
||||
|
||||
- (MacGlobalShortcutBackend*) shortcut_handler {
|
||||
- (MacGlobalShortcutBackend*)shortcut_handler {
|
||||
return shortcut_handler_;
|
||||
}
|
||||
|
||||
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
|
||||
- (void)applicationDidFinishLaunching:(NSNotification*)aNotification {
|
||||
key_tap_ = [[SPMediaKeyTap alloc] initWithDelegate:self];
|
||||
if([SPMediaKeyTap usesGlobalMediaKeyTap])
|
||||
if ([SPMediaKeyTap usesGlobalMediaKeyTap])
|
||||
[key_tap_ startWatchingMediaKeys];
|
||||
else
|
||||
qLog(Warning)<<"Media key monitoring disabled";
|
||||
|
||||
qLog(Warning) << "Media key monitoring disabled";
|
||||
}
|
||||
|
||||
- (BOOL) application: (NSApplication*)app openFile:(NSString*)filename {
|
||||
- (BOOL)application:(NSApplication*)app openFile:(NSString*)filename {
|
||||
qLog(Debug) << "Wants to open:" << [filename UTF8String];
|
||||
|
||||
if (application_handler_->LoadUrl(QString::fromUtf8([filename UTF8String]))) {
|
||||
|
@ -172,15 +174,19 @@ static BreakpadRef InitBreakpad() {
|
|||
return NO;
|
||||
}
|
||||
|
||||
- (void) application: (NSApplication*)app openFiles:(NSArray*)filenames {
|
||||
- (void)application:(NSApplication*)app openFiles:(NSArray*)filenames {
|
||||
qLog(Debug) << "Wants to open:" << filenames;
|
||||
[filenames enumerateObjectsUsingBlock:^(id object, NSUInteger idx, BOOL* stop) {
|
||||
[self application:app openFile:(NSString*)object];
|
||||
}];
|
||||
[filenames
|
||||
enumerateObjectsUsingBlock:^(id object, NSUInteger idx, BOOL* stop) {
|
||||
[self application:app openFile:(NSString*)object];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void) mediaKeyTap: (SPMediaKeyTap*)keyTap receivedMediaKeyEvent:(NSEvent*)event {
|
||||
NSAssert([event type] == NSSystemDefined && [event subtype] == SPSystemDefinedEventMediaKeys, @"Unexpected NSEvent in mediaKeyTap:receivedMediaKeyEvent:");
|
||||
- (void)mediaKeyTap:(SPMediaKeyTap*)keyTap
|
||||
receivedMediaKeyEvent:(NSEvent*)event {
|
||||
NSAssert([event type] == NSSystemDefined &&
|
||||
[event subtype] == SPSystemDefinedEventMediaKeys,
|
||||
@"Unexpected NSEvent in mediaKeyTap:receivedMediaKeyEvent:");
|
||||
|
||||
int key_code = (([event data1] & 0xFFFF0000) >> 16);
|
||||
int key_flags = ([event data1] & 0x0000FFFF);
|
||||
|
@ -196,14 +202,16 @@ static BreakpadRef InitBreakpad() {
|
|||
}
|
||||
}
|
||||
|
||||
- (NSApplicationTerminateReply) applicationShouldTerminate:(NSApplication*) sender {
|
||||
- (NSApplicationTerminateReply)applicationShouldTerminate:
|
||||
(NSApplication*)sender {
|
||||
#ifdef HAVE_BREAKPAD
|
||||
BreakpadRelease(breakpad_);
|
||||
#endif
|
||||
return NSTerminateNow;
|
||||
}
|
||||
|
||||
- (BOOL) userNotificationCenter: (id)center shouldPresentNotification: (id)notification {
|
||||
- (BOOL)userNotificationCenter:(id)center
|
||||
shouldPresentNotification:(id)notification {
|
||||
// Always show notifications, even if Clementine is in the foreground.
|
||||
return YES;
|
||||
}
|
||||
|
@ -212,51 +220,54 @@ static BreakpadRef InitBreakpad() {
|
|||
|
||||
@implementation MacApplication
|
||||
|
||||
- (id) init {
|
||||
- (id)init {
|
||||
if ((self = [super init])) {
|
||||
[self SetShortcutHandler:nil];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (MacGlobalShortcutBackend*) shortcut_handler {
|
||||
- (MacGlobalShortcutBackend*)shortcut_handler {
|
||||
// should be the same as delegate_'s shortcut handler
|
||||
return shortcut_handler_;
|
||||
}
|
||||
|
||||
- (void) SetShortcutHandler: (MacGlobalShortcutBackend*)handler {
|
||||
- (void)SetShortcutHandler:(MacGlobalShortcutBackend*)handler {
|
||||
shortcut_handler_ = handler;
|
||||
if(delegate_)
|
||||
[delegate_ setShortcutHandler:handler];
|
||||
if (delegate_) [delegate_ setShortcutHandler:handler];
|
||||
}
|
||||
|
||||
- (PlatformInterface*) application_handler {
|
||||
- (PlatformInterface*)application_handler {
|
||||
return application_handler_;
|
||||
}
|
||||
|
||||
- (void) SetApplicationHandler: (PlatformInterface*)handler {
|
||||
- (void)SetApplicationHandler:(PlatformInterface*)handler {
|
||||
delegate_ = [[AppDelegate alloc] initWithHandler:handler];
|
||||
// App-shortcut-handler set before delegate is set.
|
||||
// this makes sure the delegate's shortcut_handler is set
|
||||
[delegate_ setShortcutHandler:shortcut_handler_];
|
||||
[self setDelegate:delegate_];
|
||||
|
||||
Class notification_center_class = NSClassFromString(@"NSUserNotificationCenter");
|
||||
Class notification_center_class =
|
||||
NSClassFromString(@"NSUserNotificationCenter");
|
||||
if (notification_center_class) {
|
||||
id notification_center = [notification_center_class defaultUserNotificationCenter];
|
||||
[notification_center setDelegate: delegate_];
|
||||
id notification_center =
|
||||
[notification_center_class defaultUserNotificationCenter];
|
||||
[notification_center setDelegate:delegate_];
|
||||
}
|
||||
}
|
||||
|
||||
-(void) sendEvent: (NSEvent*)event {
|
||||
- (void)sendEvent:(NSEvent*)event {
|
||||
// If event tap is not installed, handle events that reach the app instead
|
||||
BOOL shouldHandleMediaKeyEventLocally = ![SPMediaKeyTap usesGlobalMediaKeyTap];
|
||||
BOOL shouldHandleMediaKeyEventLocally =
|
||||
![SPMediaKeyTap usesGlobalMediaKeyTap];
|
||||
|
||||
if(shouldHandleMediaKeyEventLocally && [event type] == NSSystemDefined && [event subtype] == SPSystemDefinedEventMediaKeys) {
|
||||
[(id)[self delegate] mediaKeyTap: nil receivedMediaKeyEvent: event];
|
||||
if (shouldHandleMediaKeyEventLocally && [event type] == NSSystemDefined &&
|
||||
[event subtype] == SPSystemDefinedEventMediaKeys) {
|
||||
[(id)[self delegate] mediaKeyTap:nil receivedMediaKeyEvent:event];
|
||||
}
|
||||
|
||||
[super sendEvent: event];
|
||||
[super sendEvent:event];
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -267,30 +278,33 @@ void MacMain() {
|
|||
ScopedNSAutoreleasePool pool;
|
||||
// Creates and sets the magic global variable so QApplication will find it.
|
||||
[MacApplication sharedApplication];
|
||||
#ifdef HAVE_SPARKLE
|
||||
// Creates and sets the magic global variable for Sparkle.
|
||||
[[SUUpdater sharedUpdater] setDelegate: NSApp];
|
||||
#endif
|
||||
#ifdef HAVE_SPARKLE
|
||||
// Creates and sets the magic global variable for Sparkle.
|
||||
[[SUUpdater sharedUpdater] setDelegate:NSApp];
|
||||
#endif
|
||||
}
|
||||
|
||||
void SetShortcutHandler(MacGlobalShortcutBackend* handler) {
|
||||
[NSApp SetShortcutHandler: handler];
|
||||
[NSApp SetShortcutHandler:handler];
|
||||
}
|
||||
|
||||
void SetApplicationHandler(PlatformInterface* handler) {
|
||||
[NSApp SetApplicationHandler: handler];
|
||||
[NSApp SetApplicationHandler:handler];
|
||||
}
|
||||
|
||||
void CheckForUpdates() {
|
||||
#ifdef HAVE_SPARKLE
|
||||
[[SUUpdater sharedUpdater] checkForUpdates: NSApp];
|
||||
#endif
|
||||
#ifdef HAVE_SPARKLE
|
||||
[[SUUpdater sharedUpdater] checkForUpdates:NSApp];
|
||||
#endif
|
||||
}
|
||||
|
||||
QString GetBundlePath() {
|
||||
ScopedCFTypeRef<CFURLRef> app_url(CFBundleCopyBundleURL(CFBundleGetMainBundle()));
|
||||
ScopedCFTypeRef<CFStringRef> mac_path(CFURLCopyFileSystemPath(app_url.get(), kCFURLPOSIXPathStyle));
|
||||
const char* path = CFStringGetCStringPtr(mac_path.get(), CFStringGetSystemEncoding());
|
||||
ScopedCFTypeRef<CFURLRef> app_url(
|
||||
CFBundleCopyBundleURL(CFBundleGetMainBundle()));
|
||||
ScopedCFTypeRef<CFStringRef> mac_path(
|
||||
CFURLCopyFileSystemPath(app_url.get(), kCFURLPOSIXPathStyle));
|
||||
const char* path =
|
||||
CFStringGetCStringPtr(mac_path.get(), CFStringGetSystemEncoding());
|
||||
QString bundle_path = QString::fromUtf8(path);
|
||||
return bundle_path;
|
||||
}
|
||||
|
@ -303,9 +317,7 @@ QString GetResourcesPath() {
|
|||
QString GetApplicationSupportPath() {
|
||||
ScopedNSAutoreleasePool pool;
|
||||
NSArray* paths = NSSearchPathForDirectoriesInDomains(
|
||||
NSApplicationSupportDirectory,
|
||||
NSUserDomainMask,
|
||||
YES);
|
||||
NSApplicationSupportDirectory, NSUserDomainMask, YES);
|
||||
QString ret;
|
||||
if ([paths count] > 0) {
|
||||
NSString* user_path = [paths objectAtIndex:0];
|
||||
|
@ -318,10 +330,8 @@ QString GetApplicationSupportPath() {
|
|||
|
||||
QString GetMusicDirectory() {
|
||||
ScopedNSAutoreleasePool pool;
|
||||
NSArray* paths = NSSearchPathForDirectoriesInDomains(
|
||||
NSMusicDirectory,
|
||||
NSUserDomainMask,
|
||||
YES);
|
||||
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSMusicDirectory,
|
||||
NSUserDomainMask, YES);
|
||||
QString ret;
|
||||
if ([paths count] > 0) {
|
||||
NSString* user_path = [paths objectAtIndex:0];
|
||||
|
@ -335,57 +345,108 @@ QString GetMusicDirectory() {
|
|||
static int MapFunctionKey(int keycode) {
|
||||
switch (keycode) {
|
||||
// Function keys
|
||||
case NSInsertFunctionKey: return Qt::Key_Insert;
|
||||
case NSDeleteFunctionKey: return Qt::Key_Delete;
|
||||
case NSPauseFunctionKey: return Qt::Key_Pause;
|
||||
case NSPrintFunctionKey: return Qt::Key_Print;
|
||||
case NSSysReqFunctionKey: return Qt::Key_SysReq;
|
||||
case NSHomeFunctionKey: return Qt::Key_Home;
|
||||
case NSEndFunctionKey: return Qt::Key_End;
|
||||
case NSLeftArrowFunctionKey: return Qt::Key_Left;
|
||||
case NSUpArrowFunctionKey: return Qt::Key_Up;
|
||||
case NSRightArrowFunctionKey: return Qt::Key_Right;
|
||||
case NSDownArrowFunctionKey: return Qt::Key_Down;
|
||||
case NSPageUpFunctionKey: return Qt::Key_PageUp;
|
||||
case NSPageDownFunctionKey: return Qt::Key_PageDown;
|
||||
case NSScrollLockFunctionKey: return Qt::Key_ScrollLock;
|
||||
case NSF1FunctionKey: return Qt::Key_F1;
|
||||
case NSF2FunctionKey: return Qt::Key_F2;
|
||||
case NSF3FunctionKey: return Qt::Key_F3;
|
||||
case NSF4FunctionKey: return Qt::Key_F4;
|
||||
case NSF5FunctionKey: return Qt::Key_F5;
|
||||
case NSF6FunctionKey: return Qt::Key_F6;
|
||||
case NSF7FunctionKey: return Qt::Key_F7;
|
||||
case NSF8FunctionKey: return Qt::Key_F8;
|
||||
case NSF9FunctionKey: return Qt::Key_F9;
|
||||
case NSF10FunctionKey: return Qt::Key_F10;
|
||||
case NSF11FunctionKey: return Qt::Key_F11;
|
||||
case NSF12FunctionKey: return Qt::Key_F12;
|
||||
case NSF13FunctionKey: return Qt::Key_F13;
|
||||
case NSF14FunctionKey: return Qt::Key_F14;
|
||||
case NSF15FunctionKey: return Qt::Key_F15;
|
||||
case NSF16FunctionKey: return Qt::Key_F16;
|
||||
case NSF17FunctionKey: return Qt::Key_F17;
|
||||
case NSF18FunctionKey: return Qt::Key_F18;
|
||||
case NSF19FunctionKey: return Qt::Key_F19;
|
||||
case NSF20FunctionKey: return Qt::Key_F20;
|
||||
case NSF21FunctionKey: return Qt::Key_F21;
|
||||
case NSF22FunctionKey: return Qt::Key_F22;
|
||||
case NSF23FunctionKey: return Qt::Key_F23;
|
||||
case NSF24FunctionKey: return Qt::Key_F24;
|
||||
case NSF25FunctionKey: return Qt::Key_F25;
|
||||
case NSF26FunctionKey: return Qt::Key_F26;
|
||||
case NSF27FunctionKey: return Qt::Key_F27;
|
||||
case NSF28FunctionKey: return Qt::Key_F28;
|
||||
case NSF29FunctionKey: return Qt::Key_F29;
|
||||
case NSF30FunctionKey: return Qt::Key_F30;
|
||||
case NSF31FunctionKey: return Qt::Key_F31;
|
||||
case NSF32FunctionKey: return Qt::Key_F32;
|
||||
case NSF33FunctionKey: return Qt::Key_F33;
|
||||
case NSF34FunctionKey: return Qt::Key_F34;
|
||||
case NSF35FunctionKey: return Qt::Key_F35;
|
||||
case NSMenuFunctionKey: return Qt::Key_Menu;
|
||||
case NSHelpFunctionKey: return Qt::Key_Help;
|
||||
case NSInsertFunctionKey:
|
||||
return Qt::Key_Insert;
|
||||
case NSDeleteFunctionKey:
|
||||
return Qt::Key_Delete;
|
||||
case NSPauseFunctionKey:
|
||||
return Qt::Key_Pause;
|
||||
case NSPrintFunctionKey:
|
||||
return Qt::Key_Print;
|
||||
case NSSysReqFunctionKey:
|
||||
return Qt::Key_SysReq;
|
||||
case NSHomeFunctionKey:
|
||||
return Qt::Key_Home;
|
||||
case NSEndFunctionKey:
|
||||
return Qt::Key_End;
|
||||
case NSLeftArrowFunctionKey:
|
||||
return Qt::Key_Left;
|
||||
case NSUpArrowFunctionKey:
|
||||
return Qt::Key_Up;
|
||||
case NSRightArrowFunctionKey:
|
||||
return Qt::Key_Right;
|
||||
case NSDownArrowFunctionKey:
|
||||
return Qt::Key_Down;
|
||||
case NSPageUpFunctionKey:
|
||||
return Qt::Key_PageUp;
|
||||
case NSPageDownFunctionKey:
|
||||
return Qt::Key_PageDown;
|
||||
case NSScrollLockFunctionKey:
|
||||
return Qt::Key_ScrollLock;
|
||||
case NSF1FunctionKey:
|
||||
return Qt::Key_F1;
|
||||
case NSF2FunctionKey:
|
||||
return Qt::Key_F2;
|
||||
case NSF3FunctionKey:
|
||||
return Qt::Key_F3;
|
||||
case NSF4FunctionKey:
|
||||
return Qt::Key_F4;
|
||||
case NSF5FunctionKey:
|
||||
return Qt::Key_F5;
|
||||
case NSF6FunctionKey:
|
||||
return Qt::Key_F6;
|
||||
case NSF7FunctionKey:
|
||||
return Qt::Key_F7;
|
||||
case NSF8FunctionKey:
|
||||
return Qt::Key_F8;
|
||||
case NSF9FunctionKey:
|
||||
return Qt::Key_F9;
|
||||
case NSF10FunctionKey:
|
||||
return Qt::Key_F10;
|
||||
case NSF11FunctionKey:
|
||||
return Qt::Key_F11;
|
||||
case NSF12FunctionKey:
|
||||
return Qt::Key_F12;
|
||||
case NSF13FunctionKey:
|
||||
return Qt::Key_F13;
|
||||
case NSF14FunctionKey:
|
||||
return Qt::Key_F14;
|
||||
case NSF15FunctionKey:
|
||||
return Qt::Key_F15;
|
||||
case NSF16FunctionKey:
|
||||
return Qt::Key_F16;
|
||||
case NSF17FunctionKey:
|
||||
return Qt::Key_F17;
|
||||
case NSF18FunctionKey:
|
||||
return Qt::Key_F18;
|
||||
case NSF19FunctionKey:
|
||||
return Qt::Key_F19;
|
||||
case NSF20FunctionKey:
|
||||
return Qt::Key_F20;
|
||||
case NSF21FunctionKey:
|
||||
return Qt::Key_F21;
|
||||
case NSF22FunctionKey:
|
||||
return Qt::Key_F22;
|
||||
case NSF23FunctionKey:
|
||||
return Qt::Key_F23;
|
||||
case NSF24FunctionKey:
|
||||
return Qt::Key_F24;
|
||||
case NSF25FunctionKey:
|
||||
return Qt::Key_F25;
|
||||
case NSF26FunctionKey:
|
||||
return Qt::Key_F26;
|
||||
case NSF27FunctionKey:
|
||||
return Qt::Key_F27;
|
||||
case NSF28FunctionKey:
|
||||
return Qt::Key_F28;
|
||||
case NSF29FunctionKey:
|
||||
return Qt::Key_F29;
|
||||
case NSF30FunctionKey:
|
||||
return Qt::Key_F30;
|
||||
case NSF31FunctionKey:
|
||||
return Qt::Key_F31;
|
||||
case NSF32FunctionKey:
|
||||
return Qt::Key_F32;
|
||||
case NSF33FunctionKey:
|
||||
return Qt::Key_F33;
|
||||
case NSF34FunctionKey:
|
||||
return Qt::Key_F34;
|
||||
case NSF35FunctionKey:
|
||||
return Qt::Key_F35;
|
||||
case NSMenuFunctionKey:
|
||||
return Qt::Key_Menu;
|
||||
case NSHelpFunctionKey:
|
||||
return Qt::Key_Help;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -399,11 +460,21 @@ QKeySequence KeySequenceFromNSEvent(NSEvent* event) {
|
|||
int key = 0;
|
||||
unsigned char c = chars[0];
|
||||
switch (c) {
|
||||
case 0x1b: key = Qt::Key_Escape; break;
|
||||
case 0x09: key = Qt::Key_Tab; break;
|
||||
case 0x0d: key = Qt::Key_Return; break;
|
||||
case 0x08: key = Qt::Key_Backspace; break;
|
||||
case 0x03: key = Qt::Key_Enter; break;
|
||||
case 0x1b:
|
||||
key = Qt::Key_Escape;
|
||||
break;
|
||||
case 0x09:
|
||||
key = Qt::Key_Tab;
|
||||
break;
|
||||
case 0x0d:
|
||||
key = Qt::Key_Return;
|
||||
break;
|
||||
case 0x08:
|
||||
key = Qt::Key_Backspace;
|
||||
break;
|
||||
case 0x03:
|
||||
key = Qt::Key_Enter;
|
||||
break;
|
||||
}
|
||||
|
||||
if (key == 0) {
|
||||
|
@ -448,12 +519,12 @@ void EnableFullScreen(const QWidget& main_window) {
|
|||
|
||||
NSView* view = reinterpret_cast<NSView*>(main_window.winId());
|
||||
NSWindow* window = [view window];
|
||||
[window setCollectionBehavior: kFullScreenPrimary];
|
||||
[window setCollectionBehavior:kFullScreenPrimary];
|
||||
}
|
||||
|
||||
float GetDevicePixelRatio(QWidget* widget) {
|
||||
NSView* view = reinterpret_cast<NSView*>(widget->winId());
|
||||
if ([[view window] respondsToSelector: @selector(backingScaleFactor)]) {
|
||||
if ([[view window] respondsToSelector:@selector(backingScaleFactor)]) {
|
||||
return [[view window] backingScaleFactor];
|
||||
}
|
||||
return 1.0f;
|
||||
|
|
|
@ -25,24 +25,17 @@
|
|||
#include "core/scoped_nsobject.h"
|
||||
|
||||
MacFSListener::MacFSListener(QObject* parent)
|
||||
: FileSystemWatcherInterface(parent),
|
||||
run_loop_(NULL),
|
||||
stream_(NULL) {
|
||||
: FileSystemWatcherInterface(parent), run_loop_(NULL), stream_(NULL) {
|
||||
update_timer_.setSingleShot(true);
|
||||
update_timer_.setInterval(2000);
|
||||
connect(&update_timer_, SIGNAL(timeout()), SLOT(UpdateStream()));
|
||||
}
|
||||
|
||||
void MacFSListener::Init() {
|
||||
run_loop_ = CFRunLoopGetCurrent();
|
||||
}
|
||||
void MacFSListener::Init() { run_loop_ = CFRunLoopGetCurrent(); }
|
||||
|
||||
void MacFSListener::EventStreamCallback(
|
||||
ConstFSEventStreamRef stream,
|
||||
void* user_data,
|
||||
size_t num_events,
|
||||
void* event_paths,
|
||||
const FSEventStreamEventFlags event_flags[],
|
||||
ConstFSEventStreamRef stream, void* user_data, size_t num_events,
|
||||
void* event_paths, const FSEventStreamEventFlags event_flags[],
|
||||
const FSEventStreamEventId event_ids[]) {
|
||||
MacFSListener* me = reinterpret_cast<MacFSListener*>(user_data);
|
||||
char** paths = reinterpret_cast<char**>(event_paths);
|
||||
|
@ -73,9 +66,7 @@ void MacFSListener::Clear() {
|
|||
UpdateStreamAsync();
|
||||
}
|
||||
|
||||
void MacFSListener::UpdateStreamAsync() {
|
||||
update_timer_.start();
|
||||
}
|
||||
void MacFSListener::UpdateStreamAsync() { update_timer_.start(); }
|
||||
|
||||
void MacFSListener::UpdateStream() {
|
||||
if (stream_) {
|
||||
|
@ -91,10 +82,10 @@ void MacFSListener::UpdateStream() {
|
|||
|
||||
scoped_nsobject<NSMutableArray> array([[NSMutableArray alloc] init]);
|
||||
|
||||
foreach (const QString& path, paths_) {
|
||||
for (const QString& path : paths_) {
|
||||
scoped_nsobject<NSString> string(
|
||||
[[NSString alloc] initWithUTF8String: path.toUtf8().constData()]);
|
||||
[array addObject: string.get()];
|
||||
[[NSString alloc] initWithUTF8String:path.toUtf8().constData()]);
|
||||
[array addObject:string.get()];
|
||||
}
|
||||
|
||||
FSEventStreamContext context;
|
||||
|
@ -102,14 +93,10 @@ void MacFSListener::UpdateStream() {
|
|||
context.info = this;
|
||||
CFAbsoluteTime latency = 1.0;
|
||||
|
||||
stream_ = FSEventStreamCreate(
|
||||
NULL,
|
||||
&EventStreamCallback,
|
||||
&context, // Copied
|
||||
reinterpret_cast<CFArrayRef>(array.get()),
|
||||
kFSEventStreamEventIdSinceNow,
|
||||
latency,
|
||||
kFSEventStreamCreateFlagNone);
|
||||
stream_ = FSEventStreamCreate(NULL, &EventStreamCallback, &context, // Copied
|
||||
reinterpret_cast<CFArrayRef>(array.get()),
|
||||
kFSEventStreamEventIdSinceNow, latency,
|
||||
kFSEventStreamCreateFlagNone);
|
||||
|
||||
FSEventStreamScheduleWithRunLoop(stream_, run_loop_, kCFRunLoopDefaultMode);
|
||||
FSEventStreamStart(stream_);
|
||||
|
|
|
@ -38,21 +38,23 @@
|
|||
class MacGlobalShortcutBackendPrivate : boost::noncopyable {
|
||||
public:
|
||||
explicit MacGlobalShortcutBackendPrivate(MacGlobalShortcutBackend* backend)
|
||||
: global_monitor_(nil),
|
||||
local_monitor_(nil),
|
||||
backend_(backend) {
|
||||
}
|
||||
: global_monitor_(nil), local_monitor_(nil), backend_(backend) {}
|
||||
|
||||
bool Register() {
|
||||
global_monitor_ = [NSEvent addGlobalMonitorForEventsMatchingMask:NSKeyDownMask
|
||||
handler:^(NSEvent* event) {
|
||||
HandleKeyEvent(event);
|
||||
}];
|
||||
local_monitor_ = [NSEvent addLocalMonitorForEventsMatchingMask:NSKeyDownMask
|
||||
handler:^(NSEvent* event) {
|
||||
// Filter event if we handle it as a global shortcut.
|
||||
return HandleKeyEvent(event) ? nil : event;
|
||||
}];
|
||||
global_monitor_ =
|
||||
[NSEvent addGlobalMonitorForEventsMatchingMask:NSKeyDownMask
|
||||
handler:^(NSEvent* event) {
|
||||
HandleKeyEvent(event);
|
||||
}];
|
||||
local_monitor_ =
|
||||
[NSEvent addLocalMonitorForEventsMatchingMask:NSKeyDownMask
|
||||
handler:^(NSEvent* event) {
|
||||
// Filter event if we handle
|
||||
// it as a global shortcut.
|
||||
return HandleKeyEvent(event)
|
||||
? nil
|
||||
: event;
|
||||
}];
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -67,26 +69,24 @@ class MacGlobalShortcutBackendPrivate : boost::noncopyable {
|
|||
return backend_->KeyPressed(sequence);
|
||||
}
|
||||
|
||||
|
||||
id global_monitor_;
|
||||
id local_monitor_;
|
||||
MacGlobalShortcutBackend* backend_;
|
||||
};
|
||||
|
||||
MacGlobalShortcutBackend::MacGlobalShortcutBackend(GlobalShortcuts* parent)
|
||||
: GlobalShortcutBackend(parent),
|
||||
p_(new MacGlobalShortcutBackendPrivate(this)) {
|
||||
}
|
||||
: GlobalShortcutBackend(parent),
|
||||
p_(new MacGlobalShortcutBackendPrivate(this)) {}
|
||||
|
||||
MacGlobalShortcutBackend::~MacGlobalShortcutBackend() {
|
||||
}
|
||||
MacGlobalShortcutBackend::~MacGlobalShortcutBackend() {}
|
||||
|
||||
bool MacGlobalShortcutBackend::DoRegister() {
|
||||
// Always enable media keys.
|
||||
mac::SetShortcutHandler(this);
|
||||
|
||||
if (AXAPIEnabled()) {
|
||||
foreach (const GlobalShortcuts::Shortcut& shortcut, manager_->shortcuts().values()) {
|
||||
for (const GlobalShortcuts::Shortcut& shortcut :
|
||||
manager_->shortcuts().values()) {
|
||||
shortcuts_[shortcut.action->shortcut()] = shortcut.action;
|
||||
}
|
||||
return p_->Register();
|
||||
|
@ -134,8 +134,10 @@ void MacGlobalShortcutBackend::ShowAccessibilityDialog() {
|
|||
NSArray* paths = NSSearchPathForDirectoriesInDomains(
|
||||
NSPreferencePanesDirectory, NSSystemDomainMask, YES);
|
||||
if ([paths count] == 1) {
|
||||
NSURL* prefpane_url = [NSURL fileURLWithPath:
|
||||
[[paths objectAtIndex:0] stringByAppendingPathComponent:@"UniversalAccessPref.prefPane"]];
|
||||
NSURL* prefpane_url =
|
||||
[NSURL fileURLWithPath:[[paths objectAtIndex:0]
|
||||
stringByAppendingPathComponent:
|
||||
@"UniversalAccessPref.prefPane"]];
|
||||
[[NSWorkspace sharedWorkspace] openURL:prefpane_url];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,22 +60,18 @@
|
|||
#define kUSBProductString "USB Product Name"
|
||||
#endif
|
||||
|
||||
// io_object_t, io_service_t, io_iterator_t etc. are all typedef'd to unsigned int,
|
||||
// io_object_t, io_service_t, io_iterator_t etc. are all typedef'd to unsigned
|
||||
// int,
|
||||
// hence the lack of templating here.
|
||||
class ScopedIOObject {
|
||||
public:
|
||||
explicit ScopedIOObject(io_object_t object = 0)
|
||||
: object_(object) {
|
||||
}
|
||||
explicit ScopedIOObject(io_object_t object = 0) : object_(object) {}
|
||||
|
||||
~ScopedIOObject() {
|
||||
if (object_)
|
||||
IOObjectRelease(object_);
|
||||
if (object_) IOObjectRelease(object_);
|
||||
}
|
||||
|
||||
io_object_t get() const {
|
||||
return object_;
|
||||
}
|
||||
io_object_t get() const { return object_; }
|
||||
|
||||
private:
|
||||
io_object_t object_;
|
||||
|
@ -105,12 +101,9 @@ uint qHash(const MacDeviceLister::MTPDevice& d) {
|
|||
return qHash(d.vendor_id) ^ qHash(d.product_id);
|
||||
}
|
||||
|
||||
MacDeviceLister::MacDeviceLister() {
|
||||
}
|
||||
MacDeviceLister::MacDeviceLister() {}
|
||||
|
||||
MacDeviceLister::~MacDeviceLister() {
|
||||
CFRelease(loop_session_);
|
||||
}
|
||||
MacDeviceLister::~MacDeviceLister() { CFRelease(loop_session_); }
|
||||
|
||||
void MacDeviceLister::Init() {
|
||||
ScopedNSAutoreleasePool pool;
|
||||
|
@ -149,24 +142,23 @@ void MacDeviceLister::Init() {
|
|||
// Register for disk mounts/unmounts.
|
||||
loop_session_ = DASessionCreate(kCFAllocatorDefault);
|
||||
DARegisterDiskAppearedCallback(
|
||||
loop_session_, kDADiskDescriptionMatchVolumeMountable, &DiskAddedCallback, reinterpret_cast<void*>(this));
|
||||
DARegisterDiskDisappearedCallback(
|
||||
loop_session_, NULL, &DiskRemovedCallback, reinterpret_cast<void*>(this));
|
||||
loop_session_, kDADiskDescriptionMatchVolumeMountable, &DiskAddedCallback,
|
||||
reinterpret_cast<void*>(this));
|
||||
DARegisterDiskDisappearedCallback(loop_session_, NULL, &DiskRemovedCallback,
|
||||
reinterpret_cast<void*>(this));
|
||||
DASessionScheduleWithRunLoop(loop_session_, run_loop_, kCFRunLoopDefaultMode);
|
||||
|
||||
// Register for USB device connection/disconnection.
|
||||
IONotificationPortRef notification_port = IONotificationPortCreate(kIOMasterPortDefault);
|
||||
CFMutableDictionaryRef matching_dict = IOServiceMatching(kIOUSBDeviceClassName);
|
||||
IONotificationPortRef notification_port =
|
||||
IONotificationPortCreate(kIOMasterPortDefault);
|
||||
CFMutableDictionaryRef matching_dict =
|
||||
IOServiceMatching(kIOUSBDeviceClassName);
|
||||
// IOServiceAddMatchingNotification decreases reference count.
|
||||
CFRetain(matching_dict);
|
||||
io_iterator_t it;
|
||||
kern_return_t err = IOServiceAddMatchingNotification(
|
||||
notification_port,
|
||||
kIOFirstMatchNotification,
|
||||
matching_dict,
|
||||
&USBDeviceAddedCallback,
|
||||
reinterpret_cast<void*>(this),
|
||||
&it);
|
||||
notification_port, kIOFirstMatchNotification, matching_dict,
|
||||
&USBDeviceAddedCallback, reinterpret_cast<void*>(this), &it);
|
||||
if (err == KERN_SUCCESS) {
|
||||
USBDeviceAddedCallback(this, it);
|
||||
} else {
|
||||
|
@ -174,28 +166,22 @@ void MacDeviceLister::Init() {
|
|||
}
|
||||
|
||||
err = IOServiceAddMatchingNotification(
|
||||
notification_port,
|
||||
kIOTerminatedNotification,
|
||||
matching_dict,
|
||||
&USBDeviceRemovedCallback,
|
||||
reinterpret_cast<void*>(this),
|
||||
&it);
|
||||
notification_port, kIOTerminatedNotification, matching_dict,
|
||||
&USBDeviceRemovedCallback, reinterpret_cast<void*>(this), &it);
|
||||
if (err == KERN_SUCCESS) {
|
||||
USBDeviceRemovedCallback(this, it);
|
||||
} else {
|
||||
qLog(Warning) << "Could not add notification USB device removal";
|
||||
}
|
||||
|
||||
CFRunLoopSourceRef io_source = IONotificationPortGetRunLoopSource(notification_port);
|
||||
CFRunLoopSourceRef io_source =
|
||||
IONotificationPortGetRunLoopSource(notification_port);
|
||||
CFRunLoopAddSource(run_loop_, io_source, kCFRunLoopDefaultMode);
|
||||
|
||||
CFRunLoopRun();
|
||||
}
|
||||
|
||||
void MacDeviceLister::ShutDown() {
|
||||
CFRunLoopStop(run_loop_);
|
||||
}
|
||||
|
||||
void MacDeviceLister::ShutDown() { CFRunLoopStop(run_loop_); }
|
||||
|
||||
// IOKit helpers.
|
||||
namespace {
|
||||
|
@ -203,7 +189,8 @@ namespace {
|
|||
// Caller is responsible for calling CFRelease().
|
||||
CFTypeRef GetUSBRegistryEntry(io_object_t device, CFStringRef key) {
|
||||
io_iterator_t it;
|
||||
if (IORegistryEntryGetParentIterator(device, kIOServicePlane, &it) == KERN_SUCCESS) {
|
||||
if (IORegistryEntryGetParentIterator(device, kIOServicePlane, &it) ==
|
||||
KERN_SUCCESS) {
|
||||
io_object_t next;
|
||||
while ((next = IOIteratorNext(it))) {
|
||||
CFTypeRef registry_entry = (CFStringRef)IORegistryEntryCreateCFProperty(
|
||||
|
@ -230,7 +217,8 @@ CFTypeRef GetUSBRegistryEntry(io_object_t device, CFStringRef key) {
|
|||
}
|
||||
|
||||
QString GetUSBRegistryEntryString(io_object_t device, CFStringRef key) {
|
||||
ScopedCFTypeRef<CFStringRef> registry_string((CFStringRef)GetUSBRegistryEntry(device, key));
|
||||
ScopedCFTypeRef<CFStringRef> registry_string(
|
||||
(CFStringRef)GetUSBRegistryEntry(device, key));
|
||||
if (registry_string) {
|
||||
return QString::fromUtf8([(NSString*)registry_string.get() UTF8String]);
|
||||
}
|
||||
|
@ -240,14 +228,15 @@ QString GetUSBRegistryEntryString(io_object_t device, CFStringRef key) {
|
|||
|
||||
NSObject* GetPropertyForDevice(io_object_t device, CFStringRef key) {
|
||||
CFMutableDictionaryRef properties;
|
||||
kern_return_t ret = IORegistryEntryCreateCFProperties(
|
||||
device, &properties, kCFAllocatorDefault, 0);
|
||||
kern_return_t ret = IORegistryEntryCreateCFProperties(device, &properties,
|
||||
kCFAllocatorDefault, 0);
|
||||
|
||||
if (ret != KERN_SUCCESS) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
scoped_nsobject<NSDictionary> dict((NSDictionary*)properties); // Takes ownership.
|
||||
scoped_nsobject<NSDictionary> dict(
|
||||
(NSDictionary*)properties); // Takes ownership.
|
||||
NSObject* prop = [dict objectForKey:(NSString*)key];
|
||||
if (prop) {
|
||||
// The dictionary goes out of scope so we should retain this object.
|
||||
|
@ -266,10 +255,7 @@ NSObject* GetPropertyForDevice(io_object_t device, CFStringRef key) {
|
|||
|
||||
int GetUSBDeviceClass(io_object_t device) {
|
||||
ScopedCFTypeRef<CFTypeRef> interface_class(IORegistryEntrySearchCFProperty(
|
||||
device,
|
||||
kIOServicePlane,
|
||||
CFSTR(kUSBInterfaceClass),
|
||||
kCFAllocatorDefault,
|
||||
device, kIOServicePlane, CFSTR(kUSBInterfaceClass), kCFAllocatorDefault,
|
||||
kIORegistryIterateRecursively));
|
||||
NSNumber* number = (NSNumber*)interface_class.get();
|
||||
if (number) {
|
||||
|
@ -280,13 +266,17 @@ int GetUSBDeviceClass(io_object_t device) {
|
|||
}
|
||||
|
||||
QString GetIconForDevice(io_object_t device) {
|
||||
scoped_nsobject<NSDictionary> media_icon((NSDictionary*)GetPropertyForDevice(device, CFSTR("IOMediaIcon")));
|
||||
scoped_nsobject<NSDictionary> media_icon(
|
||||
(NSDictionary*)GetPropertyForDevice(device, CFSTR("IOMediaIcon")));
|
||||
if (media_icon) {
|
||||
NSString* bundle = (NSString*)[media_icon objectForKey:@"CFBundleIdentifier"];
|
||||
NSString* file = (NSString*)[media_icon objectForKey:@"IOBundleResourceFile"];
|
||||
NSString* bundle =
|
||||
(NSString*)[media_icon objectForKey:@"CFBundleIdentifier"];
|
||||
NSString* file =
|
||||
(NSString*)[media_icon objectForKey:@"IOBundleResourceFile"];
|
||||
|
||||
scoped_nsobject<NSURL> bundle_url((NSURL*)KextManagerCreateURLForBundleIdentifier(
|
||||
kCFAllocatorDefault, (CFStringRef)bundle));
|
||||
scoped_nsobject<NSURL> bundle_url(
|
||||
(NSURL*)KextManagerCreateURLForBundleIdentifier(kCFAllocatorDefault,
|
||||
(CFStringRef)bundle));
|
||||
|
||||
QString path = QString::fromUtf8([[bundle_url path] UTF8String]);
|
||||
path += "/Contents/Resources/";
|
||||
|
@ -298,7 +288,8 @@ QString GetIconForDevice(io_object_t device) {
|
|||
}
|
||||
|
||||
QString GetSerialForDevice(io_object_t device) {
|
||||
QString serial = GetUSBRegistryEntryString(device, CFSTR(kUSBSerialNumberString));
|
||||
QString serial =
|
||||
GetUSBRegistryEntryString(device, CFSTR(kUSBSerialNumberString));
|
||||
if (!serial.isEmpty()) {
|
||||
return "USB/" + serial;
|
||||
}
|
||||
|
@ -306,8 +297,8 @@ QString GetSerialForDevice(io_object_t device) {
|
|||
}
|
||||
|
||||
QString GetSerialForMTPDevice(io_object_t device) {
|
||||
scoped_nsobject<NSString> serial((NSString*)
|
||||
GetPropertyForDevice(device, CFSTR(kUSBSerialNumberString)));
|
||||
scoped_nsobject<NSString> serial(
|
||||
(NSString*)GetPropertyForDevice(device, CFSTR(kUSBSerialNumberString)));
|
||||
return QString(QString("MTP/") + QString::fromUtf8([serial UTF8String]));
|
||||
}
|
||||
|
||||
|
@ -320,14 +311,14 @@ QString FindDeviceProperty(const QString& bsd_name, CFStringRef property) {
|
|||
QString ret = GetUSBRegistryEntryString(device.get(), property);
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
quint64 MacDeviceLister::GetFreeSpace(const QUrl& url) {
|
||||
QMutexLocker l(&libmtp_mutex_);
|
||||
MtpConnection connection(url);
|
||||
if (!connection.is_valid()) {
|
||||
qLog(Warning) << "Error connecting to MTP device, couldn't get device free space";
|
||||
qLog(Warning)
|
||||
<< "Error connecting to MTP device, couldn't get device free space";
|
||||
return -1;
|
||||
}
|
||||
LIBMTP_devicestorage_t* storage = connection.device()->storage;
|
||||
|
@ -343,7 +334,8 @@ quint64 MacDeviceLister::GetCapacity(const QUrl& url) {
|
|||
QMutexLocker l(&libmtp_mutex_);
|
||||
MtpConnection connection(url);
|
||||
if (!connection.is_valid()) {
|
||||
qLog(Warning) << "Error connecting to MTP device, couldn't get device capacity";
|
||||
qLog(Warning)
|
||||
<< "Error connecting to MTP device, couldn't get device capacity";
|
||||
return -1;
|
||||
}
|
||||
LIBMTP_devicestorage_t* storage = connection.device()->storage;
|
||||
|
@ -358,9 +350,11 @@ quint64 MacDeviceLister::GetCapacity(const QUrl& url) {
|
|||
void MacDeviceLister::DiskAddedCallback(DADiskRef disk, void* context) {
|
||||
MacDeviceLister* me = reinterpret_cast<MacDeviceLister*>(context);
|
||||
|
||||
scoped_nsobject<NSDictionary> properties((NSDictionary*)DADiskCopyDescription(disk));
|
||||
scoped_nsobject<NSDictionary> properties(
|
||||
(NSDictionary*)DADiskCopyDescription(disk));
|
||||
|
||||
NSString* kind = [properties objectForKey:(NSString*)kDADiskDescriptionMediaKindKey];
|
||||
NSString* kind =
|
||||
[properties objectForKey:(NSString*)kDADiskDescriptionMediaKindKey];
|
||||
#ifdef HAVE_AUDIOCD
|
||||
if (kind && strcmp([kind UTF8String], kIOCDMediaClass) == 0) {
|
||||
// CD inserted.
|
||||
|
@ -371,22 +365,26 @@ void MacDeviceLister::DiskAddedCallback(DADiskRef disk, void* context) {
|
|||
}
|
||||
#endif
|
||||
|
||||
NSURL* volume_path =
|
||||
[[properties objectForKey:(NSString*)kDADiskDescriptionVolumePathKey] copy];
|
||||
NSURL* volume_path = [[properties
|
||||
objectForKey:(NSString*)kDADiskDescriptionVolumePathKey] copy];
|
||||
|
||||
if (volume_path) {
|
||||
ScopedIOObject device(DADiskCopyIOMedia(disk));
|
||||
ScopedCFTypeRef<CFStringRef> class_name(IOObjectCopyClass(device.get()));
|
||||
if (class_name && CFStringCompare(class_name.get(), CFSTR(kIOMediaClass), 0) == kCFCompareEqualTo) {
|
||||
QString vendor = GetUSBRegistryEntryString(device.get(), CFSTR(kUSBVendorString));
|
||||
QString product = GetUSBRegistryEntryString(device.get(), CFSTR(kUSBProductString));
|
||||
if (class_name && CFStringCompare(class_name.get(), CFSTR(kIOMediaClass),
|
||||
0) == kCFCompareEqualTo) {
|
||||
QString vendor =
|
||||
GetUSBRegistryEntryString(device.get(), CFSTR(kUSBVendorString));
|
||||
QString product =
|
||||
GetUSBRegistryEntryString(device.get(), CFSTR(kUSBProductString));
|
||||
|
||||
CFMutableDictionaryRef cf_properties;
|
||||
kern_return_t ret = IORegistryEntryCreateCFProperties(
|
||||
device.get(), &cf_properties, kCFAllocatorDefault, 0);
|
||||
|
||||
if (ret == KERN_SUCCESS) {
|
||||
scoped_nsobject<NSDictionary> dict((NSDictionary*)cf_properties); // Takes ownership.
|
||||
scoped_nsobject<NSDictionary> dict(
|
||||
(NSDictionary*)cf_properties); // Takes ownership.
|
||||
if ([[dict objectForKey:@"Removable"] intValue] == 1) {
|
||||
QString serial = GetSerialForDevice(device.get());
|
||||
if (!serial.isEmpty()) {
|
||||
|
@ -420,15 +418,9 @@ void MacDeviceLister::DiskRemovedCallback(DADiskRef disk, void* context) {
|
|||
}
|
||||
}
|
||||
|
||||
bool DeviceRequest(IOUSBDeviceInterface** dev,
|
||||
quint8 direction,
|
||||
quint8 type,
|
||||
quint8 recipient,
|
||||
quint8 request_code,
|
||||
quint16 value,
|
||||
quint16 index,
|
||||
quint16 length,
|
||||
QByteArray* data) {
|
||||
bool DeviceRequest(IOUSBDeviceInterface** dev, quint8 direction, quint8 type,
|
||||
quint8 recipient, quint8 request_code, quint16 value,
|
||||
quint16 index, quint16 length, QByteArray* data) {
|
||||
IOUSBDevRequest req;
|
||||
req.bmRequestType = USBmakebmRequestType(direction, type, recipient);
|
||||
req.bRequest = request_code;
|
||||
|
@ -468,15 +460,19 @@ void MacDeviceLister::USBDeviceAddedCallback(void* refcon, io_iterator_t it) {
|
|||
io_object_t object;
|
||||
while ((object = IOIteratorNext(it))) {
|
||||
ScopedCFTypeRef<CFStringRef> class_name(IOObjectCopyClass(object));
|
||||
BOOST_SCOPE_EXIT((object)) {
|
||||
IOObjectRelease(object);
|
||||
} BOOST_SCOPE_EXIT_END
|
||||
BOOST_SCOPE_EXIT((object)) { IOObjectRelease(object); }
|
||||
BOOST_SCOPE_EXIT_END
|
||||
|
||||
if (CFStringCompare(class_name.get(), CFSTR(kIOUSBDeviceClassName), 0) == kCFCompareEqualTo) {
|
||||
NSString* vendor = (NSString*)GetPropertyForDevice(object, CFSTR(kUSBVendorString));
|
||||
NSString* product = (NSString*)GetPropertyForDevice(object, CFSTR(kUSBProductString));
|
||||
NSNumber* vendor_id = (NSNumber*)GetPropertyForDevice(object, CFSTR(kUSBVendorID));
|
||||
NSNumber* product_id = (NSNumber*)GetPropertyForDevice(object, CFSTR(kUSBProductID));
|
||||
if (CFStringCompare(class_name.get(), CFSTR(kIOUSBDeviceClassName), 0) ==
|
||||
kCFCompareEqualTo) {
|
||||
NSString* vendor =
|
||||
(NSString*)GetPropertyForDevice(object, CFSTR(kUSBVendorString));
|
||||
NSString* product =
|
||||
(NSString*)GetPropertyForDevice(object, CFSTR(kUSBProductString));
|
||||
NSNumber* vendor_id =
|
||||
(NSNumber*)GetPropertyForDevice(object, CFSTR(kUSBVendorID));
|
||||
NSNumber* product_id =
|
||||
(NSNumber*)GetPropertyForDevice(object, CFSTR(kUSBProductID));
|
||||
int interface_class = GetUSBDeviceClass(object);
|
||||
qLog(Debug) << "Interface class:" << interface_class;
|
||||
|
||||
|
@ -492,7 +488,8 @@ void MacDeviceLister::USBDeviceAddedCallback(void* refcon, io_iterator_t it) {
|
|||
device.bus = -1;
|
||||
device.address = -1;
|
||||
|
||||
if (device.vendor_id == kAppleVendorID || // I think we can safely skip Apple products.
|
||||
if (device.vendor_id ==
|
||||
kAppleVendorID || // I think we can safely skip Apple products.
|
||||
// Blacklist ilok2 as this probe may be breaking it.
|
||||
(device.vendor_id == 0x088e && device.product_id == 0x5036) ||
|
||||
// Blacklist eLicenser
|
||||
|
@ -504,7 +501,8 @@ void MacDeviceLister::USBDeviceAddedCallback(void* refcon, io_iterator_t it) {
|
|||
continue;
|
||||
}
|
||||
|
||||
NSNumber* addr = (NSNumber*)GetPropertyForDevice(object, CFSTR("USB Address"));
|
||||
NSNumber* addr =
|
||||
(NSNumber*)GetPropertyForDevice(object, CFSTR("USB Address"));
|
||||
int bus = GetBusNumber(object);
|
||||
if (!addr || bus == -1) {
|
||||
// Failed to get bus or address number.
|
||||
|
@ -525,19 +523,15 @@ void MacDeviceLister::USBDeviceAddedCallback(void* refcon, io_iterator_t it) {
|
|||
IOCFPlugInInterface** plugin_interface = NULL;
|
||||
SInt32 score;
|
||||
kern_return_t err = IOCreatePlugInInterfaceForService(
|
||||
object,
|
||||
kIOUSBDeviceUserClientTypeID,
|
||||
kIOCFPlugInInterfaceID,
|
||||
&plugin_interface,
|
||||
&score);
|
||||
object, kIOUSBDeviceUserClientTypeID, kIOCFPlugInInterfaceID,
|
||||
&plugin_interface, &score);
|
||||
if (err != KERN_SUCCESS) {
|
||||
continue;
|
||||
}
|
||||
|
||||
IOUSBDeviceInterface** dev = NULL;
|
||||
HRESULT result = (*plugin_interface)->QueryInterface(
|
||||
plugin_interface,
|
||||
CFUUIDGetUUIDBytes(kIOUSBDeviceInterfaceID),
|
||||
plugin_interface, CFUUIDGetUUIDBytes(kIOUSBDeviceInterfaceID),
|
||||
(LPVOID*)&dev);
|
||||
|
||||
(*plugin_interface)->Release(plugin_interface);
|
||||
|
@ -555,44 +549,43 @@ void MacDeviceLister::USBDeviceAddedCallback(void* refcon, io_iterator_t it) {
|
|||
BOOST_SCOPE_EXIT((dev)) {
|
||||
(*dev)->USBDeviceClose(dev);
|
||||
(*dev)->Release(dev);
|
||||
} BOOST_SCOPE_EXIT_END
|
||||
}
|
||||
BOOST_SCOPE_EXIT_END
|
||||
|
||||
// Request the string descriptor at 0xee.
|
||||
// This is a magic string that indicates whether this device supports MTP.
|
||||
QByteArray data;
|
||||
bool ret = DeviceRequest(
|
||||
dev, kUSBIn, kUSBStandard, kUSBDevice, kUSBRqGetDescriptor,
|
||||
(kUSBStringDesc << 8) | 0xee, 0x0409, 2, &data);
|
||||
if (!ret)
|
||||
continue;
|
||||
bool ret = DeviceRequest(dev, kUSBIn, kUSBStandard, kUSBDevice,
|
||||
kUSBRqGetDescriptor,
|
||||
(kUSBStringDesc << 8) | 0xee, 0x0409, 2, &data);
|
||||
if (!ret) continue;
|
||||
|
||||
UInt8 string_len = data[0];
|
||||
|
||||
ret = DeviceRequest(
|
||||
dev, kUSBIn, kUSBStandard, kUSBDevice, kUSBRqGetDescriptor,
|
||||
(kUSBStringDesc << 8) | 0xee, 0x0409, string_len, &data);
|
||||
if (!ret)
|
||||
continue;
|
||||
ret = DeviceRequest(dev, kUSBIn, kUSBStandard, kUSBDevice,
|
||||
kUSBRqGetDescriptor, (kUSBStringDesc << 8) | 0xee,
|
||||
0x0409, string_len, &data);
|
||||
if (!ret) continue;
|
||||
|
||||
// The device actually returned something. That's a good sign.
|
||||
// Because this was designed by MS, the characters are in UTF-16 (LE?).
|
||||
QString str = QString::fromUtf16(reinterpret_cast<ushort*>(data.data() + 2), (data.size() / 2) - 2);
|
||||
QString str = QString::fromUtf16(
|
||||
reinterpret_cast<ushort*>(data.data() + 2), (data.size() / 2) - 2);
|
||||
|
||||
if (str.startsWith("MSFT100")) {
|
||||
// We got the OS descriptor!
|
||||
char vendor_code = data[16];
|
||||
ret = DeviceRequest(
|
||||
dev, kUSBIn, kUSBVendor, kUSBDevice, vendor_code, 0, 4, 256, &data);
|
||||
if (!ret || data.at(0) != 0x28)
|
||||
continue;
|
||||
ret = DeviceRequest(dev, kUSBIn, kUSBVendor, kUSBDevice, vendor_code, 0,
|
||||
4, 256, &data);
|
||||
if (!ret || data.at(0) != 0x28) continue;
|
||||
|
||||
if (QString::fromAscii(data.data() + 0x12, 3) != "MTP") {
|
||||
// Not quite.
|
||||
continue;
|
||||
}
|
||||
|
||||
ret = DeviceRequest(
|
||||
dev, kUSBIn, kUSBVendor, kUSBDevice, vendor_code, 0, 5, 256, &data);
|
||||
ret = DeviceRequest(dev, kUSBIn, kUSBVendor, kUSBDevice, vendor_code, 0,
|
||||
5, 256, &data);
|
||||
if (!ret || data.at(0) != 0x28) {
|
||||
continue;
|
||||
}
|
||||
|
@ -613,15 +606,19 @@ void MacDeviceLister::USBDeviceRemovedCallback(void* refcon, io_iterator_t it) {
|
|||
io_object_t object;
|
||||
while ((object = IOIteratorNext(it))) {
|
||||
ScopedCFTypeRef<CFStringRef> class_name(IOObjectCopyClass(object));
|
||||
BOOST_SCOPE_EXIT((object)) {
|
||||
IOObjectRelease(object);
|
||||
} BOOST_SCOPE_EXIT_END
|
||||
BOOST_SCOPE_EXIT((object)) { IOObjectRelease(object); }
|
||||
BOOST_SCOPE_EXIT_END
|
||||
|
||||
if (CFStringCompare(class_name.get(), CFSTR(kIOUSBDeviceClassName), 0) == kCFCompareEqualTo) {
|
||||
NSString* vendor = (NSString*)GetPropertyForDevice(object, CFSTR(kUSBVendorString));
|
||||
NSString* product = (NSString*)GetPropertyForDevice(object, CFSTR(kUSBProductString));
|
||||
NSNumber* vendor_id = (NSNumber*)GetPropertyForDevice(object, CFSTR(kUSBVendorID));
|
||||
NSNumber* product_id = (NSNumber*)GetPropertyForDevice(object, CFSTR(kUSBProductID));
|
||||
if (CFStringCompare(class_name.get(), CFSTR(kIOUSBDeviceClassName), 0) ==
|
||||
kCFCompareEqualTo) {
|
||||
NSString* vendor =
|
||||
(NSString*)GetPropertyForDevice(object, CFSTR(kUSBVendorString));
|
||||
NSString* product =
|
||||
(NSString*)GetPropertyForDevice(object, CFSTR(kUSBProductString));
|
||||
NSNumber* vendor_id =
|
||||
(NSNumber*)GetPropertyForDevice(object, CFSTR(kUSBVendorID));
|
||||
NSNumber* product_id =
|
||||
(NSNumber*)GetPropertyForDevice(object, CFSTR(kUSBProductID));
|
||||
QString serial = GetSerialForMTPDevice(object);
|
||||
|
||||
MTPDevice device;
|
||||
|
@ -643,7 +640,8 @@ void MacDeviceLister::RemovedMTPDevice(const QString& serial) {
|
|||
}
|
||||
}
|
||||
|
||||
void MacDeviceLister::FoundMTPDevice(const MTPDevice& device, const QString& serial) {
|
||||
void MacDeviceLister::FoundMTPDevice(const MTPDevice& device,
|
||||
const QString& serial) {
|
||||
qLog(Debug) << "New MTP device detected!" << device.bus << device.address;
|
||||
mtp_devices_[serial] = device;
|
||||
QList<QUrl> urls = MakeDeviceUrls(serial);
|
||||
|
@ -653,9 +651,7 @@ void MacDeviceLister::FoundMTPDevice(const MTPDevice& device, const QString& ser
|
|||
emit DeviceAdded(serial);
|
||||
}
|
||||
|
||||
bool IsMTPSerial(const QString& serial) {
|
||||
return serial.startsWith("MTP");
|
||||
}
|
||||
bool IsMTPSerial(const QString& serial) { return serial.startsWith("MTP"); }
|
||||
|
||||
bool MacDeviceLister::IsCDDevice(const QString& serial) const {
|
||||
return cd_devices_.contains(serial);
|
||||
|
@ -671,23 +667,27 @@ QString MacDeviceLister::MakeFriendlyName(const QString& serial) {
|
|||
}
|
||||
}
|
||||
|
||||
QString bsd_name = IsCDDevice(serial) ? *cd_devices_.find(serial) : current_devices_[serial];
|
||||
QString bsd_name =
|
||||
IsCDDevice(serial) ? *cd_devices_.find(serial) : current_devices_[serial];
|
||||
ScopedCFTypeRef<DASessionRef> session(DASessionCreate(kCFAllocatorDefault));
|
||||
ScopedCFTypeRef<DADiskRef> disk(DADiskCreateFromBSDName(
|
||||
kCFAllocatorDefault, session.get(), bsd_name.toAscii().constData()));
|
||||
|
||||
if (IsCDDevice(serial)) {
|
||||
scoped_nsobject<NSDictionary> properties((NSDictionary*)DADiskCopyDescription(disk.get()));
|
||||
NSString* device_name = (NSString*)[properties.get() objectForKey:
|
||||
(NSString*)kDADiskDescriptionMediaNameKey];
|
||||
scoped_nsobject<NSDictionary> properties(
|
||||
(NSDictionary*)DADiskCopyDescription(disk.get()));
|
||||
NSString* device_name = (NSString*)[properties.get()
|
||||
objectForKey:(NSString*)kDADiskDescriptionMediaNameKey];
|
||||
|
||||
return QString::fromUtf8([device_name UTF8String]);
|
||||
}
|
||||
|
||||
ScopedIOObject device(DADiskCopyIOMedia(disk));
|
||||
|
||||
QString vendor = GetUSBRegistryEntryString(device.get(), CFSTR(kUSBVendorString));
|
||||
QString product = GetUSBRegistryEntryString(device.get(), CFSTR(kUSBProductString));
|
||||
QString vendor =
|
||||
GetUSBRegistryEntryString(device.get(), CFSTR(kUSBVendorString));
|
||||
QString product =
|
||||
GetUSBRegistryEntryString(device.get(), CFSTR(kUSBProductString));
|
||||
|
||||
if (vendor.isEmpty()) {
|
||||
return product;
|
||||
|
@ -718,9 +718,10 @@ QList<QUrl> MacDeviceLister::MakeDeviceUrls(const QString& serial) {
|
|||
ScopedCFTypeRef<DADiskRef> disk(DADiskCreateFromBSDName(
|
||||
kCFAllocatorDefault, session.get(), bsd_name.toAscii().constData()));
|
||||
|
||||
scoped_nsobject<NSDictionary> properties((NSDictionary*)DADiskCopyDescription(disk.get()));
|
||||
scoped_nsobject<NSURL> volume_path(
|
||||
[[properties objectForKey:(NSString*)kDADiskDescriptionVolumePathKey] copy]);
|
||||
scoped_nsobject<NSDictionary> properties(
|
||||
(NSDictionary*)DADiskCopyDescription(disk.get()));
|
||||
scoped_nsobject<NSURL> volume_path([[properties
|
||||
objectForKey:(NSString*)kDADiskDescriptionVolumePathKey] copy]);
|
||||
|
||||
QString path = QString::fromUtf8([[volume_path path] UTF8String]);
|
||||
QUrl ret = MakeUrlFromLocalPath(path);
|
||||
|
@ -749,9 +750,10 @@ QVariantList MacDeviceLister::DeviceIcons(const QString& serial) {
|
|||
ScopedIOObject device(DADiskCopyIOMedia(disk.get()));
|
||||
QString icon = GetIconForDevice(device.get());
|
||||
|
||||
scoped_nsobject<NSDictionary> properties((NSDictionary*)DADiskCopyDescription(disk));
|
||||
scoped_nsobject<NSURL> volume_path(
|
||||
[[properties objectForKey:(NSString*)kDADiskDescriptionVolumePathKey] copy]);
|
||||
scoped_nsobject<NSDictionary> properties(
|
||||
(NSDictionary*)DADiskCopyDescription(disk));
|
||||
scoped_nsobject<NSURL> volume_path([[properties
|
||||
objectForKey:(NSString*)kDADiskDescriptionVolumePathKey] copy]);
|
||||
|
||||
QString path = QString::fromUtf8([[volume_path path] UTF8String]);
|
||||
|
||||
|
@ -764,21 +766,21 @@ QVariantList MacDeviceLister::DeviceIcons(const QString& serial) {
|
|||
return ret;
|
||||
}
|
||||
|
||||
QString MacDeviceLister::DeviceManufacturer(const QString& serial){
|
||||
QString MacDeviceLister::DeviceManufacturer(const QString& serial) {
|
||||
if (IsMTPSerial(serial)) {
|
||||
return mtp_devices_[serial].vendor;
|
||||
}
|
||||
return FindDeviceProperty(current_devices_[serial], CFSTR(kUSBVendorString));
|
||||
}
|
||||
|
||||
QString MacDeviceLister::DeviceModel(const QString& serial){
|
||||
QString MacDeviceLister::DeviceModel(const QString& serial) {
|
||||
if (IsMTPSerial(serial)) {
|
||||
return mtp_devices_[serial].product;
|
||||
}
|
||||
return FindDeviceProperty(current_devices_[serial], CFSTR(kUSBProductString));
|
||||
}
|
||||
|
||||
quint64 MacDeviceLister::DeviceCapacity(const QString& serial){
|
||||
quint64 MacDeviceLister::DeviceCapacity(const QString& serial) {
|
||||
if (IsMTPSerial(serial)) {
|
||||
QList<QUrl> urls = MakeDeviceUrls(serial);
|
||||
return mtp_devices_[serial].capacity;
|
||||
|
@ -799,7 +801,7 @@ quint64 MacDeviceLister::DeviceCapacity(const QString& serial){
|
|||
return ret;
|
||||
}
|
||||
|
||||
quint64 MacDeviceLister::DeviceFreeSpace(const QString& serial){
|
||||
quint64 MacDeviceLister::DeviceFreeSpace(const QString& serial) {
|
||||
if (IsMTPSerial(serial)) {
|
||||
QList<QUrl> urls = MakeDeviceUrls(serial);
|
||||
return mtp_devices_[serial].free_space;
|
||||
|
@ -809,20 +811,25 @@ quint64 MacDeviceLister::DeviceFreeSpace(const QString& serial){
|
|||
ScopedCFTypeRef<DADiskRef> disk(DADiskCreateFromBSDName(
|
||||
kCFAllocatorDefault, session.get(), bsd_name.toAscii().constData()));
|
||||
|
||||
scoped_nsobject<NSDictionary> properties((NSDictionary*)DADiskCopyDescription(disk));
|
||||
scoped_nsobject<NSURL> volume_path(
|
||||
[[properties objectForKey:(NSString*)kDADiskDescriptionVolumePathKey] copy]);
|
||||
scoped_nsobject<NSDictionary> properties(
|
||||
(NSDictionary*)DADiskCopyDescription(disk));
|
||||
scoped_nsobject<NSURL> volume_path([[properties
|
||||
objectForKey:(NSString*)kDADiskDescriptionVolumePathKey] copy]);
|
||||
|
||||
NSNumber* value = nil;
|
||||
NSError* error = nil;
|
||||
if ([volume_path getResourceValue: &value
|
||||
forKey: NSURLVolumeAvailableCapacityKey error: &error] && value) {
|
||||
if ([volume_path getResourceValue:&value
|
||||
forKey:NSURLVolumeAvailableCapacityKey
|
||||
error:&error] &&
|
||||
value) {
|
||||
return [value unsignedLongLongValue];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
QVariantMap MacDeviceLister::DeviceHardwareInfo(const QString& serial){return QVariantMap();}
|
||||
QVariantMap MacDeviceLister::DeviceHardwareInfo(const QString& serial) {
|
||||
return QVariantMap();
|
||||
}
|
||||
|
||||
bool MacDeviceLister::AskForScan(const QString& serial) const {
|
||||
return !IsCDDevice(serial);
|
||||
|
@ -838,8 +845,9 @@ void MacDeviceLister::UnmountDevice(const QString& serial) {
|
|||
DADiskUnmount(disk, kDADiskUnmountOptionDefault, &DiskUnmountCallback, this);
|
||||
}
|
||||
|
||||
void MacDeviceLister::DiskUnmountCallback(
|
||||
DADiskRef disk, DADissenterRef dissenter, void* context) {
|
||||
void MacDeviceLister::DiskUnmountCallback(DADiskRef disk,
|
||||
DADissenterRef dissenter,
|
||||
void* context) {
|
||||
if (dissenter) {
|
||||
qLog(Warning) << "Another app blocked the unmount";
|
||||
} else {
|
||||
|
|
|
@ -11,23 +11,24 @@
|
|||
|
||||
- (void)netServiceWillPublish:(NSNetService*)netService;
|
||||
- (void)netService:(NSNetService*)netService
|
||||
didNotPublish:(NSDictionary*)errorDict;
|
||||
didNotPublish:(NSDictionary*)errorDict;
|
||||
- (void)netServiceDidStop:(NSNetService*)netService;
|
||||
|
||||
@end
|
||||
|
||||
@implementation NetServicePublicationDelegate
|
||||
|
||||
- (void)netServiceWillPublish: (NSNetService*)netService {
|
||||
- (void)netServiceWillPublish:(NSNetService*)netService {
|
||||
qLog(Debug) << "Publishing:" << [[netService name] UTF8String];
|
||||
}
|
||||
|
||||
- (void)netService: (NSNetService*)netServie didNotPublish: (NSDictionary*)errorDict {
|
||||
- (void)netService:(NSNetService*)netServie
|
||||
didNotPublish:(NSDictionary*)errorDict {
|
||||
qLog(Debug) << "Failed to publish remote service with Bonjour";
|
||||
NSLog(@"%@", errorDict);
|
||||
}
|
||||
|
||||
- (void)netServiceDidStop: (NSNetService*)netService {
|
||||
- (void)netServiceDidStop:(NSNetService*)netService {
|
||||
qLog(Debug) << "Unpublished:" << [[netService name] UTF8String];
|
||||
}
|
||||
|
||||
|
@ -36,32 +37,24 @@
|
|||
namespace {
|
||||
|
||||
NSString* NSStringFromQString(const QString& s) {
|
||||
return [[NSString alloc] initWithUTF8String: s.toUtf8().constData()];
|
||||
return [[NSString alloc] initWithUTF8String:s.toUtf8().constData()];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Bonjour::Bonjour() : delegate_([[NetServicePublicationDelegate alloc] init]) {}
|
||||
|
||||
Bonjour::Bonjour()
|
||||
: delegate_([[NetServicePublicationDelegate alloc] init]) {
|
||||
}
|
||||
Bonjour::~Bonjour() { [delegate_ release]; }
|
||||
|
||||
Bonjour::~Bonjour() {
|
||||
[delegate_ release];
|
||||
}
|
||||
|
||||
void Bonjour::PublishInternal(
|
||||
const QString& domain,
|
||||
const QString& type,
|
||||
const QByteArray& name,
|
||||
quint16 port) {
|
||||
void Bonjour::PublishInternal(const QString& domain, const QString& type,
|
||||
const QByteArray& name, quint16 port) {
|
||||
ScopedNSAutoreleasePool pool;
|
||||
NSNetService* service = [[NSNetService alloc]
|
||||
initWithDomain: NSStringFromQString(domain)
|
||||
type: NSStringFromQString(type)
|
||||
name: [NSString stringWithUTF8String: name.constData()]
|
||||
port: port];
|
||||
initWithDomain:NSStringFromQString(domain)
|
||||
type:NSStringFromQString(type)
|
||||
name:[NSString stringWithUTF8String:name.constData()]
|
||||
port:port];
|
||||
if (service) {
|
||||
[service setDelegate: delegate_];
|
||||
[service setDelegate:delegate_];
|
||||
[service publish];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,13 +30,9 @@
|
|||
|
||||
class MacMonitorWrapper : boost::noncopyable {
|
||||
public:
|
||||
explicit MacMonitorWrapper(id monitor)
|
||||
: local_monitor_(monitor) {
|
||||
}
|
||||
explicit MacMonitorWrapper(id monitor) : local_monitor_(monitor) {}
|
||||
|
||||
~MacMonitorWrapper() {
|
||||
[NSEvent removeMonitor: local_monitor_];
|
||||
}
|
||||
~MacMonitorWrapper() { [NSEvent removeMonitor:local_monitor_]; }
|
||||
|
||||
private:
|
||||
id local_monitor_;
|
||||
|
@ -53,13 +49,14 @@ bool GlobalShortcutGrabber::HandleMacEvent(NSEvent* event) {
|
|||
}
|
||||
|
||||
void GlobalShortcutGrabber::SetupMacEventHandler() {
|
||||
id monitor = [NSEvent addLocalMonitorForEventsMatchingMask: NSKeyDownMask
|
||||
handler:^(NSEvent* event) {
|
||||
return HandleMacEvent(event) ? event : nil;
|
||||
}];
|
||||
id monitor =
|
||||
[NSEvent addLocalMonitorForEventsMatchingMask:NSKeyDownMask
|
||||
handler:^(NSEvent* event) {
|
||||
return HandleMacEvent(event)
|
||||
? event
|
||||
: nil;
|
||||
}];
|
||||
wrapper_ = new MacMonitorWrapper(monitor);
|
||||
}
|
||||
|
||||
void GlobalShortcutGrabber::TeardownMacEventHandler() {
|
||||
delete wrapper_;
|
||||
}
|
||||
void GlobalShortcutGrabber::TeardownMacEventHandler() { delete wrapper_; }
|
||||
|
|
|
@ -29,29 +29,29 @@
|
|||
#include <AppKit/NSMenu.h>
|
||||
#include <AppKit/NSMenuItem.h>
|
||||
|
||||
@interface Target :NSObject {
|
||||
@interface Target : NSObject {
|
||||
QAction* action_;
|
||||
}
|
||||
- (id) initWithQAction: (QAction*)action;
|
||||
- (void) clicked;
|
||||
- (id)initWithQAction:(QAction*)action;
|
||||
- (void)clicked;
|
||||
@end
|
||||
|
||||
@implementation Target // <NSMenuValidation>
|
||||
- (id) init {
|
||||
- (id)init {
|
||||
return [super init];
|
||||
}
|
||||
|
||||
- (id) initWithQAction: (QAction*)action {
|
||||
- (id)initWithQAction:(QAction*)action {
|
||||
action_ = action;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL) validateMenuItem: (NSMenuItem*)menuItem {
|
||||
- (BOOL)validateMenuItem:(NSMenuItem*)menuItem {
|
||||
// This is called when the menu is shown.
|
||||
return action_->isEnabled();
|
||||
}
|
||||
|
||||
- (void) clicked {
|
||||
- (void)clicked {
|
||||
action_->trigger();
|
||||
}
|
||||
@end
|
||||
|
@ -62,21 +62,20 @@ class MacSystemTrayIconPrivate : boost::noncopyable {
|
|||
dock_menu_ = [[NSMenu alloc] initWithTitle:@"DockMenu"];
|
||||
|
||||
QString title = QT_TR_NOOP("Now Playing");
|
||||
NSString* t = [[NSString alloc] initWithUTF8String:title.toUtf8().constData()];
|
||||
now_playing_ = [[NSMenuItem alloc]
|
||||
initWithTitle:t
|
||||
action:NULL
|
||||
keyEquivalent:@""];
|
||||
NSString* t =
|
||||
[[NSString alloc] initWithUTF8String:title.toUtf8().constData()];
|
||||
now_playing_ =
|
||||
[[NSMenuItem alloc] initWithTitle:t action:NULL keyEquivalent:@""];
|
||||
|
||||
now_playing_artist_ = [[NSMenuItem alloc]
|
||||
initWithTitle:@"Nothing to see here"
|
||||
action:NULL
|
||||
keyEquivalent:@""];
|
||||
now_playing_artist_ =
|
||||
[[NSMenuItem alloc] initWithTitle:@"Nothing to see here"
|
||||
action:NULL
|
||||
keyEquivalent:@""];
|
||||
|
||||
now_playing_title_ = [[NSMenuItem alloc]
|
||||
initWithTitle:@"Nothing to see here"
|
||||
action:NULL
|
||||
keyEquivalent:@""];
|
||||
now_playing_title_ =
|
||||
[[NSMenuItem alloc] initWithTitle:@"Nothing to see here"
|
||||
action:NULL
|
||||
keyEquivalent:@""];
|
||||
|
||||
[dock_menu_ insertItem:now_playing_title_ atIndex:0];
|
||||
[dock_menu_ insertItem:now_playing_artist_ atIndex:0];
|
||||
|
@ -84,7 +83,7 @@ class MacSystemTrayIconPrivate : boost::noncopyable {
|
|||
|
||||
// Don't look now.
|
||||
// This must be called after our custom NSApplicationDelegate has been set.
|
||||
[(AppDelegate*)([NSApp delegate]) setDockMenu:dock_menu_];
|
||||
[(AppDelegate*)([NSApp delegate])setDockMenu:dock_menu_];
|
||||
|
||||
ClearNowPlaying();
|
||||
}
|
||||
|
@ -92,13 +91,14 @@ class MacSystemTrayIconPrivate : boost::noncopyable {
|
|||
void AddMenuItem(QAction* action) {
|
||||
// Strip accelarators from name.
|
||||
QString text = action->text().remove("&");
|
||||
NSString* title = [[NSString alloc] initWithUTF8String: text.toUtf8().constData()];
|
||||
// Create an object that can receive user clicks and pass them on to the QAction.
|
||||
NSString* title =
|
||||
[[NSString alloc] initWithUTF8String:text.toUtf8().constData()];
|
||||
// Create an object that can receive user clicks and pass them on to the
|
||||
// QAction.
|
||||
Target* target = [[Target alloc] initWithQAction:action];
|
||||
NSMenuItem* item = [[[NSMenuItem alloc]
|
||||
initWithTitle:title
|
||||
action:@selector(clicked)
|
||||
keyEquivalent:@""] autorelease];
|
||||
NSMenuItem* item = [[[NSMenuItem alloc] initWithTitle:title
|
||||
action:@selector(clicked)
|
||||
keyEquivalent:@""] autorelease];
|
||||
[item setEnabled:action->isEnabled()];
|
||||
[item setTarget:target];
|
||||
[dock_menu_ addItem:item];
|
||||
|
@ -107,7 +107,8 @@ class MacSystemTrayIconPrivate : boost::noncopyable {
|
|||
|
||||
void ActionChanged(QAction* action) {
|
||||
NSMenuItem* item = actions_[action];
|
||||
NSString* title = [[NSString alloc] initWithUTF8String: action->text().toUtf8().constData()];
|
||||
NSString* title = [[NSString alloc]
|
||||
initWithUTF8String:action->text().toUtf8().constData()];
|
||||
[item setTitle:title];
|
||||
}
|
||||
|
||||
|
@ -118,13 +119,18 @@ class MacSystemTrayIconPrivate : boost::noncopyable {
|
|||
|
||||
void ShowNowPlaying(const QString& artist, const QString& title) {
|
||||
ClearNowPlaying(); // Makes sure the order is consistent.
|
||||
[now_playing_artist_ setTitle:
|
||||
[[NSString alloc] initWithUTF8String: artist.toUtf8().constData()]];
|
||||
[now_playing_title_ setTitle:
|
||||
[[NSString alloc] initWithUTF8String: title.toUtf8().constData()]];
|
||||
title.isEmpty() ? HideItem(now_playing_title_) : ShowItem(now_playing_title_);
|
||||
artist.isEmpty() ? HideItem(now_playing_artist_) : ShowItem(now_playing_artist_);
|
||||
artist.isEmpty() && title.isEmpty() ? HideItem(now_playing_) : ShowItem(now_playing_);
|
||||
[now_playing_artist_
|
||||
setTitle:[[NSString alloc]
|
||||
initWithUTF8String:artist.toUtf8().constData()]];
|
||||
[now_playing_title_
|
||||
setTitle:[[NSString alloc]
|
||||
initWithUTF8String:title.toUtf8().constData()]];
|
||||
title.isEmpty() ? HideItem(now_playing_title_)
|
||||
: ShowItem(now_playing_title_);
|
||||
artist.isEmpty() ? HideItem(now_playing_artist_)
|
||||
: ShowItem(now_playing_artist_);
|
||||
artist.isEmpty() && title.isEmpty() ? HideItem(now_playing_)
|
||||
: ShowItem(now_playing_);
|
||||
}
|
||||
|
||||
void ClearNowPlaying() {
|
||||
|
@ -156,20 +162,20 @@ class MacSystemTrayIconPrivate : boost::noncopyable {
|
|||
};
|
||||
|
||||
MacSystemTrayIcon::MacSystemTrayIcon(QObject* parent)
|
||||
: SystemTrayIcon(parent),
|
||||
orange_icon_(QPixmap(":icon_large.png").scaled(
|
||||
128, 128, Qt::KeepAspectRatio, Qt::SmoothTransformation)),
|
||||
grey_icon_(QPixmap(":icon_large_grey.png").scaled(
|
||||
128, 128, Qt::KeepAspectRatio, Qt::SmoothTransformation)) {
|
||||
: SystemTrayIcon(parent),
|
||||
orange_icon_(QPixmap(":icon_large.png").scaled(
|
||||
128, 128, Qt::KeepAspectRatio, Qt::SmoothTransformation)),
|
||||
grey_icon_(QPixmap(":icon_large_grey.png").scaled(
|
||||
128, 128, Qt::KeepAspectRatio, Qt::SmoothTransformation)) {
|
||||
QApplication::setWindowIcon(orange_icon_);
|
||||
}
|
||||
|
||||
MacSystemTrayIcon::~MacSystemTrayIcon() {
|
||||
}
|
||||
MacSystemTrayIcon::~MacSystemTrayIcon() {}
|
||||
|
||||
void MacSystemTrayIcon::SetupMenu(
|
||||
QAction* previous, QAction* play, QAction* stop, QAction* stop_after,
|
||||
QAction* next, QAction* mute, QAction* love, QAction* ban, QAction* quit) {
|
||||
void MacSystemTrayIcon::SetupMenu(QAction* previous, QAction* play,
|
||||
QAction* stop, QAction* stop_after,
|
||||
QAction* next, QAction* mute, QAction* love,
|
||||
QAction* ban, QAction* quit) {
|
||||
p_.reset(new MacSystemTrayIconPrivate());
|
||||
SetupMenuItem(previous);
|
||||
SetupMenuItem(play);
|
||||
|
@ -198,10 +204,9 @@ void MacSystemTrayIcon::ActionChanged() {
|
|||
p_->ActionChanged(action);
|
||||
}
|
||||
|
||||
void MacSystemTrayIcon::ClearNowPlaying() {
|
||||
p_->ClearNowPlaying();
|
||||
}
|
||||
void MacSystemTrayIcon::ClearNowPlaying() { p_->ClearNowPlaying(); }
|
||||
|
||||
void MacSystemTrayIcon::SetNowPlaying(const Song& song, const QString& image_path) {
|
||||
void MacSystemTrayIcon::SetNowPlaying(const Song& song,
|
||||
const QString& image_path) {
|
||||
p_->ShowNowPlaying(song.artist(), song.PrettyTitle());
|
||||
}
|
||||
|
|
|
@ -27,59 +27,60 @@
|
|||
#include "core/scoped_nsautorelease_pool.h"
|
||||
#include "core/scoped_nsobject.h"
|
||||
|
||||
@interface GrowlInterface :NSObject <GrowlApplicationBridgeDelegate> {
|
||||
@interface GrowlInterface : NSObject<GrowlApplicationBridgeDelegate> {
|
||||
}
|
||||
-(void) SendGrowlAlert:(NSString*)message title:(NSString*)title image:(NSData*)image;
|
||||
-(void) ClickCallback; // Called when user clicks on notification.
|
||||
- (void)SendGrowlAlert:(NSString*)message
|
||||
title:(NSString*)title
|
||||
image:(NSData*)image;
|
||||
- (void)ClickCallback; // Called when user clicks on notification.
|
||||
@end
|
||||
|
||||
|
||||
@implementation GrowlInterface
|
||||
|
||||
-(id) init {
|
||||
- (id)init {
|
||||
if ((self = [super init])) {
|
||||
[GrowlApplicationBridge setGrowlDelegate:self];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void) dealloc {
|
||||
- (void)dealloc {
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
-(NSDictionary*) registrationDictionaryForGrowl {
|
||||
NSArray* array = [NSArray arrayWithObjects:@"next_track", nil]; // Valid notification names.
|
||||
NSDictionary* dict = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
[NSNumber numberWithInt:1],
|
||||
@"TicketVersion",
|
||||
array,
|
||||
@"AllNotifications",
|
||||
array,
|
||||
@"DefaultNotifications",
|
||||
@"com.davidsansome.clementine",
|
||||
@"ApplicationId",
|
||||
nil];
|
||||
- (NSDictionary*)registrationDictionaryForGrowl {
|
||||
NSArray* array = [NSArray
|
||||
arrayWithObjects:@"next_track", nil]; // Valid notification names.
|
||||
NSDictionary* dict = [NSDictionary
|
||||
dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:1], @"TicketVersion",
|
||||
array, @"AllNotifications", array,
|
||||
@"DefaultNotifications",
|
||||
@"com.davidsansome.clementine",
|
||||
@"ApplicationId", nil];
|
||||
return dict;
|
||||
}
|
||||
|
||||
-(void) growlNotificationWasClicked:(id)clickContext {
|
||||
- (void)growlNotificationWasClicked:(id)clickContext {
|
||||
if (clickContext) {
|
||||
[self ClickCallback];
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
-(void) SendGrowlAlert:(NSString*)message title:(NSString*)title image:(NSData*)image {
|
||||
[GrowlApplicationBridge notifyWithTitle:title
|
||||
description:message
|
||||
notificationName:@"next_track"
|
||||
iconData:image
|
||||
priority:0
|
||||
isSticky:NO
|
||||
clickContext:@"click_callback"]; // String sent to our callback.
|
||||
- (void)SendGrowlAlert:(NSString*)message
|
||||
title:(NSString*)title
|
||||
image:(NSData*)image {
|
||||
[GrowlApplicationBridge
|
||||
notifyWithTitle:title
|
||||
description:message
|
||||
notificationName:@"next_track"
|
||||
iconData:image
|
||||
priority:0
|
||||
isSticky:NO
|
||||
clickContext:@"click_callback"]; // String sent to our callback.
|
||||
}
|
||||
|
||||
-(void) ClickCallback {
|
||||
- (void)ClickCallback {
|
||||
qDebug() << "Growl notification clicked!";
|
||||
return;
|
||||
}
|
||||
|
@ -92,16 +93,15 @@ class OSD::GrowlNotificationWrapper {
|
|||
growl_interface_ = [[GrowlInterface alloc] init];
|
||||
}
|
||||
|
||||
~GrowlNotificationWrapper() {
|
||||
[growl_interface_ release];
|
||||
}
|
||||
~GrowlNotificationWrapper() { [growl_interface_ release]; }
|
||||
|
||||
void ShowMessage(const QString& summary,
|
||||
const QString& message,
|
||||
void ShowMessage(const QString& summary, const QString& message,
|
||||
const QImage& image) {
|
||||
|
||||
NSString* mac_message = [[NSString alloc] initWithUTF8String:message.toUtf8().constData()];
|
||||
NSString* mac_summary = [[NSString alloc] initWithUTF8String:summary.toUtf8().constData()];
|
||||
NSString* mac_message =
|
||||
[[NSString alloc] initWithUTF8String:message.toUtf8().constData()];
|
||||
NSString* mac_summary =
|
||||
[[NSString alloc] initWithUTF8String:summary.toUtf8().constData()];
|
||||
|
||||
NSData* image_data = nil;
|
||||
// Growl expects raw TIFF data.
|
||||
|
@ -110,12 +110,13 @@ class OSD::GrowlNotificationWrapper {
|
|||
QByteArray tiff_data;
|
||||
QBuffer tiff(&tiff_data);
|
||||
image.save(&tiff, "TIFF");
|
||||
image_data = [NSData dataWithBytes:tiff_data.constData() length:tiff_data.size()];
|
||||
image_data =
|
||||
[NSData dataWithBytes:tiff_data.constData() length:tiff_data.size()];
|
||||
}
|
||||
|
||||
[growl_interface_ SendGrowlAlert:mac_message
|
||||
title:mac_summary
|
||||
image:image_data];
|
||||
title:mac_summary
|
||||
image:image_data];
|
||||
|
||||
[mac_message release];
|
||||
[mac_summary release];
|
||||
|
@ -126,17 +127,11 @@ class OSD::GrowlNotificationWrapper {
|
|||
ScopedNSAutoreleasePool pool_;
|
||||
};
|
||||
|
||||
void OSD::Init() {
|
||||
wrapper_ = new GrowlNotificationWrapper;
|
||||
}
|
||||
void OSD::Init() { wrapper_ = new GrowlNotificationWrapper; }
|
||||
|
||||
bool OSD::SupportsNativeNotifications() {
|
||||
return true;
|
||||
}
|
||||
bool OSD::SupportsNativeNotifications() { return true; }
|
||||
|
||||
bool OSD::SupportsTrayPopups() {
|
||||
return false;
|
||||
}
|
||||
bool OSD::SupportsTrayPopups() { return false; }
|
||||
|
||||
namespace {
|
||||
|
||||
|
@ -150,12 +145,11 @@ void SendNotificationCenterMessage(NSString* title, NSString* subtitle) {
|
|||
|
||||
Class user_notification_class = NSClassFromString(@"NSUserNotification");
|
||||
id notification = [[user_notification_class alloc] init];
|
||||
[notification setTitle: title];
|
||||
[notification setSubtitle: subtitle];
|
||||
[notification setTitle:title];
|
||||
[notification setSubtitle:subtitle];
|
||||
|
||||
[notification_center deliverNotification: notification];
|
||||
[notification_center deliverNotification:notification];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void OSD::ShowMessageNative(const QString& summary, const QString& message,
|
||||
|
|
Loading…
Reference in New Issue