mirror of
https://github.com/clementine-player/Clementine
synced 2024-12-16 11:19:18 +01:00
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:
parent
e46d93b599
commit
5a97697702
@ -4,11 +4,20 @@
|
|||||||
class GlobalShortcuts;
|
class GlobalShortcuts;
|
||||||
class QObject;
|
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 {
|
namespace mac {
|
||||||
|
|
||||||
void MacMain();
|
void MacMain();
|
||||||
void SetShortcutHandler(GlobalShortcuts* handler);
|
void SetShortcutHandler(GlobalShortcuts* handler);
|
||||||
void SetApplicationHandler(QObject* handler);
|
void SetApplicationHandler(PlatformInterface* handler);
|
||||||
void CheckForUpdates();
|
void CheckForUpdates();
|
||||||
|
|
||||||
QString GetBundlePath();
|
QString GetBundlePath();
|
||||||
|
@ -15,30 +15,31 @@
|
|||||||
|
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QEvent>
|
#include <QEvent>
|
||||||
#include <QObject>
|
|
||||||
|
#include <QtDebug>
|
||||||
|
|
||||||
// Capture global media keys on Mac (Cocoa only!)
|
// 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 {
|
||||||
GlobalShortcuts* shortcut_handler_;
|
GlobalShortcuts* shortcut_handler_;
|
||||||
QObject* application_handler_;
|
PlatformInterface* application_handler_;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (GlobalShortcuts*) shortcut_handler;
|
- (GlobalShortcuts*) shortcut_handler;
|
||||||
- (void) SetShortcutHandler: (GlobalShortcuts*)handler;
|
- (void) SetShortcutHandler: (GlobalShortcuts*)handler;
|
||||||
|
|
||||||
- (QObject*) application_handler;
|
- (PlatformInterface*) application_handler;
|
||||||
- (void) SetApplicationHandler: (QObject*)handler;
|
- (void) SetApplicationHandler: (PlatformInterface*)handler;
|
||||||
|
|
||||||
- (void) mediaKeyEvent: (int)key state: (BOOL)state repeat: (BOOL)repeat;
|
- (void) mediaKeyEvent: (int)key state: (BOOL)state repeat: (BOOL)repeat;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface AppDelegate :NSObject { //<NSApplicationDelegate> {
|
@interface AppDelegate :NSObject { //<NSApplicationDelegate> {
|
||||||
QObject* application_handler_;
|
PlatformInterface* application_handler_;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id) initWithHandler: (QObject*)handler;
|
- (id) initWithHandler: (PlatformInterface*)handler;
|
||||||
// NSApplicationDelegate
|
// NSApplicationDelegate
|
||||||
- (BOOL) applicationShouldHandleReopen: (NSApplication*)app hasVisibleWindows:(BOOL)flag;
|
- (BOOL) applicationShouldHandleReopen: (NSApplication*)app hasVisibleWindows:(BOOL)flag;
|
||||||
@end
|
@end
|
||||||
@ -52,17 +53,27 @@
|
|||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id) initWithHandler: (QObject*)handler {
|
- (id) initWithHandler: (PlatformInterface*)handler {
|
||||||
application_handler_ = handler;
|
application_handler_ = handler;
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL) applicationShouldHandleReopen: (NSApplication*)app hasVisibleWindows:(BOOL)flag {
|
- (BOOL) applicationShouldHandleReopen: (NSApplication*)app hasVisibleWindows:(BOOL)flag {
|
||||||
if (application_handler_) {
|
if (application_handler_) {
|
||||||
qApp->postEvent(application_handler_, new QEvent(QEvent::ApplicationActivate));
|
application_handler_->Activate();
|
||||||
}
|
}
|
||||||
return YES;
|
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
|
@end
|
||||||
|
|
||||||
@implementation MacApplication
|
@implementation MacApplication
|
||||||
@ -83,11 +94,11 @@
|
|||||||
shortcut_handler_ = handler;
|
shortcut_handler_ = handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (QObject*) application_handler {
|
- (PlatformInterface*) application_handler {
|
||||||
return application_handler_;
|
return application_handler_;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) SetApplicationHandler: (QObject*)handler {
|
- (void) SetApplicationHandler: (PlatformInterface*)handler {
|
||||||
AppDelegate* delegate = [[AppDelegate alloc] initWithHandler:handler];
|
AppDelegate* delegate = [[AppDelegate alloc] initWithHandler:handler];
|
||||||
[self setDelegate:delegate];
|
[self setDelegate:delegate];
|
||||||
}
|
}
|
||||||
@ -144,7 +155,7 @@ void SetShortcutHandler(GlobalShortcuts* handler) {
|
|||||||
[NSApp SetShortcutHandler: handler];
|
[NSApp SetShortcutHandler: handler];
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetApplicationHandler(QObject* handler) {
|
void SetApplicationHandler(PlatformInterface* handler) {
|
||||||
[NSApp SetApplicationHandler: handler];
|
[NSApp SetApplicationHandler: handler];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1169,13 +1169,20 @@ void MainWindow::ForceShowOSD(const Song &song) {
|
|||||||
osd_->SongChanged(song);
|
osd_->SongChanged(song);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MainWindow::event(QEvent* event) {
|
void MainWindow::Activate() {
|
||||||
// ApplicationActivate is received when the dock is clicked on OS X.
|
|
||||||
if (event->type() == QEvent::ApplicationActivate) {
|
|
||||||
show();
|
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 true;
|
||||||
}
|
}
|
||||||
return QMainWindow::event(event);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::CheckForUpdates() {
|
void MainWindow::CheckForUpdates() {
|
||||||
|
Loading…
Reference in New Issue
Block a user