| 1 |
/**************************************************************************************** |
| 2 |
* Copyright (c) 2007 Benjamin Reed <ranger@befunk.com> * |
| 3 |
* * |
| 4 |
* This program is free software; you can redistribute it and/or modify it under * |
| 5 |
* the terms of the GNU General Public License as published by the Free Software * |
| 6 |
* Foundation; either version 2 of the License, or (at your option) any later * |
| 7 |
* version. * |
| 8 |
* * |
| 9 |
* This program is distributed in the hope that it will be useful, but WITHOUT ANY * |
| 10 |
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * |
| 11 |
* PARTICULAR PURPOSE. See the GNU General Public License for more details. * |
| 12 |
* * |
| 13 |
* You should have received a copy of the GNU General Public License along with * |
| 14 |
* this program. If not, see <http://www.gnu.org/licenses/>. * |
| 15 |
****************************************************************************************/ |
| 16 |
|
| 17 |
#include <Carbon/Carbon.h> |
| 18 |
|
| 19 |
#include "amarokurls/AmarokUrl.h" |
| 20 |
#include "core-impl/collections/support/CollectionManager.h" |
| 21 |
#include "core/support/Debug.h" |
| 22 |
#include "DirectoryLoader.h" |
| 23 |
#include "core/meta/Meta.h" |
| 24 |
#include "core/playlists/Playlist.h" |
| 25 |
#include "core-impl/playlists/types/file/PlaylistFileSupport.h" |
| 26 |
#include "playlist/PlaylistController.h" |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
#include <QByteArray> |
| 31 |
|
| 32 |
#include <KUrl> |
| 33 |
|
| 34 |
static AEEventHandlerUPP appleEventProcessorUPP = 0; |
| 35 |
static AEEventHandlerUPP macCallbackUrlHandlerUPP = 0; |
| 36 |
|
| 37 |
OSStatus |
| 38 |
appleEventProcessor(const AppleEvent *ae, AppleEvent *, long /*handlerRefCon*/) |
| 39 |
{ |
| 40 |
OSType aeID = typeWildCard; |
| 41 |
OSType aeClass = typeWildCard; |
| 42 |
AEGetAttributePtr(ae, keyEventClassAttr, typeType, 0, &aeClass, sizeof(aeClass), 0); |
| 43 |
AEGetAttributePtr(ae, keyEventIDAttr, typeType, 0, &aeID, sizeof(aeID), 0); |
| 44 |
|
| 45 |
if(aeClass == kCoreEventClass) |
| 46 |
{ |
| 47 |
if(aeID == kAEReopenApplication) |
| 48 |
{ |
| 49 |
#if 0 |
| 50 |
if( PlaylistWindow::self() ) |
| 51 |
PlaylistWindow::self()->show(); |
| 52 |
#endif |
| 53 |
} |
| 54 |
return noErr; |
| 55 |
} |
| 56 |
return eventNotHandledErr; |
| 57 |
} |
| 58 |
|
| 59 |
OSStatus |
| 60 |
macCallbackUrlHandler( const AppleEvent *ae, AppleEvent *, long /*handlerRefCon*/) |
| 61 |
{ |
| 62 |
DEBUG_BLOCK |
| 63 |
OSErr error = noErr; |
| 64 |
Size actualSize = 0; |
| 65 |
DescType descType = typeUTF8Text; |
| 66 |
if( ( error = AESizeOfParam( ae, keyDirectObject, &descType, &actualSize ) ) == noErr ) |
| 67 |
{ |
| 68 |
QByteArray ba; |
| 69 |
ba.resize( actualSize + 1 ); |
| 70 |
error = AEGetParamPtr( ae, keyDirectObject, typeUTF8Text, 0, ba.data(), actualSize, &actualSize ); |
| 71 |
if( error == noErr ) |
| 72 |
{ |
| 73 |
KUrl url( QString::fromUtf8( ba.data() ) ); |
| 74 |
if( url.protocol() == "amarok" ) |
| 75 |
{ |
| 76 |
AmarokUrl aUrl( url.url() ); |
| 77 |
aUrl.run(); |
| 78 |
} else |
| 79 |
{ |
| 80 |
DirectoryLoader* loader = new DirectoryLoader(); |
| 81 |
QList<KUrl> urls; |
| 82 |
urls << url; |
| 83 |
loader->init(urls); |
| 84 |
} |
| 85 |
} |
| 86 |
} |
| 87 |
return error; |
| 88 |
} |
| 89 |
|
| 90 |
void |
| 91 |
setupEventHandler_mac(long handlerRef) |
| 92 |
{ |
| 93 |
appleEventProcessorUPP = AEEventHandlerUPP(appleEventProcessor); |
| 94 |
AEInstallEventHandler(kCoreEventClass, kAEReopenApplication, appleEventProcessorUPP, handlerRef, true); |
| 95 |
macCallbackUrlHandlerUPP = AEEventHandlerUPP(macCallbackUrlHandler); |
| 96 |
AEInstallEventHandler(kInternetEventClass, kAEGetURL, macCallbackUrlHandlerUPP, handlerRef, false); |
| 97 |
} |