1 #include <Carbon/Carbon.h>
2 #include <ApplicationServices/ApplicationServices.h>
3 #include "libmpdemux/url.h"
9 static play_tree_t
*files
=NULL
;
11 static inline void add_entry(play_tree_t
**last_parentp
, play_tree_t
**last_entryp
, play_tree_t
*entry
) {
13 if(*last_entryp
==NULL
)
14 play_tree_set_child(*last_parentp
, entry
);
16 play_tree_append_entry(*last_entryp
, entry
);
21 static pascal OSErr
AppleEventHandlerProc(const AppleEvent
*theAppleEvent
, AppleEvent
* reply
, SInt32 handlerRefcon
) {
22 OSErr err
=errAEEventNotHandled
, res
=noErr
;
26 AERemoveEventHandler(kCoreEventClass
, kAEOpenDocuments
, NULL
, FALSE
);
27 if((res
=AEGetParamDesc(theAppleEvent
, keyDirectObject
, typeAEList
, &docList
))==noErr
) {
28 if((res
=AECountItems(&docList
, &itemsInList
))==noErr
) {
32 play_tree_t
*last_entry
=NULL
;
34 files
=play_tree_new();
35 for(i
=1;i
<=itemsInList
;++i
) {
41 DescType returnedType
;
43 if((e
=AEGetNthPtr(&docList
, i
, typeFileURL
, &keywd
, &returnedType
, (Ptr
)parm
, currentSize
, &actualSize
))==noErr
) {
44 if(actualSize
>=currentSize
) {
45 currentSize
=actualSize
+1;
46 parm
=realloc(parm
, currentSize
);
61 URL_t
*url
=url_new(parm
);
63 if(url
&& !strcmp(url
->protocol
,"file") && !strcmp(url
->hostname
,"localhost")) {
64 play_tree_t
*entry
=play_tree_new();
66 url_unescape_string(url
->file
, url
->file
);
67 play_tree_add_file(entry
, url
->file
);
68 add_entry(&files
, &last_entry
, entry
);
81 mp_msg(MSGT_CFGPARSER
, MSGL_ERR
, "AECountItems() error %d\n", res
);
83 AEDisposeDesc(&docList
);
86 mp_msg(MSGT_CFGPARSER
, MSGL_ERR
, "AEGetParamDesc() error %d\n", res
);
88 QuitApplicationEventLoop();
92 play_tree_t
*macosx_finder_args(m_config_t
*config
, int argc
, char **argv
) {
93 ProcessSerialNumber myPsn
;
94 char myPsnStr
[5+10+1+10+1];
96 GetCurrentProcess(&myPsn
);
97 snprintf(myPsnStr
, 5+10+1+10+1, "-psn_%u_%u", myPsn
.highLongOfPSN
, myPsn
.lowLongOfPSN
);
98 myPsnStr
[5+10+1+10]=0;
100 if((argc
==2) && !strcmp(myPsnStr
, argv
[1])) {
101 m_config_set_option(config
, "quiet", NULL
);
103 AEInstallEventHandler(kCoreEventClass
, kAEOpenDocuments
, NewAEEventHandlerUPP(AppleEventHandlerProc
), 0, FALSE
);
104 RunApplicationEventLoop();