Add support for opening files via Finder in OS X.

Update issue #405
Status: Started
Opening from Finder works but Clementine still isn't a "recommended" application.
This commit is contained in:
John Maguire 2010-06-14 13:22:45 +00:00
parent e46d93b599
commit 5a97697702
3 changed files with 44 additions and 17 deletions

View File

@ -4,11 +4,20 @@
class GlobalShortcuts;
class QObject;
class PlatformInterface {
public:
// Called when the application should show itself.
virtual void Activate() = 0;
virtual bool LoadUrl(const QString& url) = 0;
virtual ~PlatformInterface() {}
};
namespace mac {
void MacMain();
void SetShortcutHandler(GlobalShortcuts* handler);
void SetApplicationHandler(QObject* handler);
void SetApplicationHandler(PlatformInterface* handler);
void CheckForUpdates();
QString GetBundlePath();

View File

@ -15,30 +15,31 @@
#include <QCoreApplication>
#include <QEvent>
#include <QObject>
#include <QtDebug>
// Capture global media keys on Mac (Cocoa only!)
// See: http://www.rogueamoeba.com/utm/2007/09/29/apple-keyboard-media-key-event-handling/
@interface MacApplication :NSApplication {
GlobalShortcuts* shortcut_handler_;
QObject* application_handler_;
PlatformInterface* application_handler_;
}
- (GlobalShortcuts*) shortcut_handler;
- (void) SetShortcutHandler: (GlobalShortcuts*)handler;
- (QObject*) application_handler;
- (void) SetApplicationHandler: (QObject*)handler;
- (PlatformInterface*) application_handler;
- (void) SetApplicationHandler: (PlatformInterface*)handler;
- (void) mediaKeyEvent: (int)key state: (BOOL)state repeat: (BOOL)repeat;
@end
@interface AppDelegate :NSObject { //<NSApplicationDelegate> {
QObject* application_handler_;
PlatformInterface* application_handler_;
}
- (id) initWithHandler: (QObject*)handler;
- (id) initWithHandler: (PlatformInterface*)handler;
// NSApplicationDelegate
- (BOOL) applicationShouldHandleReopen: (NSApplication*)app hasVisibleWindows:(BOOL)flag;
@end
@ -52,17 +53,27 @@
return self;
}
- (id) initWithHandler: (QObject*)handler {
- (id) initWithHandler: (PlatformInterface*)handler {
application_handler_ = handler;
return self;
}
- (BOOL) applicationShouldHandleReopen: (NSApplication*)app hasVisibleWindows:(BOOL)flag {
if (application_handler_) {
qApp->postEvent(application_handler_, new QEvent(QEvent::ApplicationActivate));
application_handler_->Activate();
}
return YES;
}
- (BOOL) application: (NSApplication*)app openFile:(NSString*)filename {
qDebug() << "Wants to open:" << [filename UTF8String];
if (application_handler_->LoadUrl(QString::fromUtf8([filename UTF8String]))) {
return YES;
}
return NO;
}
@end
@implementation MacApplication
@ -83,11 +94,11 @@
shortcut_handler_ = handler;
}
- (QObject*) application_handler {
- (PlatformInterface*) application_handler {
return application_handler_;
}
- (void) SetApplicationHandler: (QObject*)handler {
- (void) SetApplicationHandler: (PlatformInterface*)handler {
AppDelegate* delegate = [[AppDelegate alloc] initWithHandler:handler];
[self setDelegate:delegate];
}
@ -144,7 +155,7 @@ void SetShortcutHandler(GlobalShortcuts* handler) {
[NSApp SetShortcutHandler: handler];
}
void SetApplicationHandler(QObject* handler) {
void SetApplicationHandler(PlatformInterface* handler) {
[NSApp SetApplicationHandler: handler];
}

View File

@ -1169,13 +1169,20 @@ void MainWindow::ForceShowOSD(const Song &song) {
osd_->SongChanged(song);
}
bool MainWindow::event(QEvent* event) {
// ApplicationActivate is received when the dock is clicked on OS X.
if (event->type() == QEvent::ApplicationActivate) {
show();
void MainWindow::Activate() {
show();
}
bool MainWindow::LoadUrl(const QString& path) {
// Currently this is only local files.
QFileInfo info(path);
if (info.exists()) {
QList<QUrl> urls;
urls << QUrl::fromLocalFile(path);
AddFilesToPlaylist(urls);
return true;
}
return QMainWindow::event(event);
return false;
}
void MainWindow::CheckForUpdates() {