2 /* ========================= Module _Launch ========================= */
8 #include "pymactoolbox.h"
10 /* Macro to test whether a weak-loaded CFM function exists */
11 #define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
12 PyErr_SetString(PyExc_NotImplementedError, \
13 "Not available in this shared library/OS version"); \
18 #if PY_VERSION_HEX < 0x02040000
19 PyObject
*PyMac_GetOSErrException(void);
22 #include <ApplicationServices/ApplicationServices.h>
25 ** Optional CFStringRef. None will pass NULL
28 OptCFStringRefObj_Convert(PyObject
*v
, CFStringRef
*spec
)
34 return CFStringRefObj_Convert(v
, spec
);
38 OptCFStringRefObj_New(CFStringRef it
)
44 return CFStringRefObj_New(it
);
48 ** Convert LSItemInfoRecord to Python.
51 LSItemInfoRecord_New(LSItemInfoRecord
*it
)
54 return Py_BuildValue("{s:is:O&s:O&s:O&s:O&s:i}",
56 "filetype", PyMac_BuildOSType
, it
->filetype
,
57 "creator", PyMac_BuildOSType
, it
->creator
,
58 "extension", OptCFStringRefObj_New
, it
->extension
,
59 "iconFileName", OptCFStringRefObj_New
, it
->iconFileName
,
60 "kindID", it
->kindID
);
62 return Py_BuildValue("{s:is:O&s:O&s:O&}",
64 "filetype", PyMac_BuildOSType
, it
->filetype
,
65 "creator", PyMac_BuildOSType
, it
->creator
,
66 "extension", OptCFStringRefObj_New
, it
->extension
);
70 static PyObject
*Launch_Error
;
72 static PyObject
*Launch_LSCopyItemInfoForRef(PyObject
*_self
, PyObject
*_args
)
74 PyObject
*_res
= NULL
;
77 LSRequestedInfo inWhichInfo
;
78 LSItemInfoRecord outItemInfo
;
79 if (!PyArg_ParseTuple(_args
, "O&l",
80 PyMac_GetFSRef
, &inItemRef
,
83 _err
= LSCopyItemInfoForRef(&inItemRef
,
86 if (_err
!= noErr
) return PyMac_Error(_err
);
87 _res
= Py_BuildValue("O&",
88 LSItemInfoRecord_New
, &outItemInfo
);
92 static PyObject
*Launch_LSCopyItemInfoForURL(PyObject
*_self
, PyObject
*_args
)
94 PyObject
*_res
= NULL
;
97 LSRequestedInfo inWhichInfo
;
98 LSItemInfoRecord outItemInfo
;
99 if (!PyArg_ParseTuple(_args
, "O&l",
100 CFURLRefObj_Convert
, &inURL
,
103 _err
= LSCopyItemInfoForURL(inURL
,
106 if (_err
!= noErr
) return PyMac_Error(_err
);
107 _res
= Py_BuildValue("O&",
108 LSItemInfoRecord_New
, &outItemInfo
);
112 static PyObject
*Launch_LSGetExtensionInfo(PyObject
*_self
, PyObject
*_args
)
114 PyObject
*_res
= NULL
;
116 UniChar
*inNameLen__in__
;
117 UniCharCount inNameLen__len__
;
118 int inNameLen__in_len__
;
119 UniCharCount outExtStartIndex
;
120 if (!PyArg_ParseTuple(_args
, "u#",
121 &inNameLen__in__
, &inNameLen__in_len__
))
123 inNameLen__len__
= inNameLen__in_len__
;
124 _err
= LSGetExtensionInfo(inNameLen__len__
, inNameLen__in__
,
126 if (_err
!= noErr
) return PyMac_Error(_err
);
127 _res
= Py_BuildValue("l",
132 static PyObject
*Launch_LSCopyDisplayNameForRef(PyObject
*_self
, PyObject
*_args
)
134 PyObject
*_res
= NULL
;
137 CFStringRef outDisplayName
;
138 if (!PyArg_ParseTuple(_args
, "O&",
139 PyMac_GetFSRef
, &inRef
))
141 _err
= LSCopyDisplayNameForRef(&inRef
,
143 if (_err
!= noErr
) return PyMac_Error(_err
);
144 _res
= Py_BuildValue("O&",
145 CFStringRefObj_New
, outDisplayName
);
149 static PyObject
*Launch_LSCopyDisplayNameForURL(PyObject
*_self
, PyObject
*_args
)
151 PyObject
*_res
= NULL
;
154 CFStringRef outDisplayName
;
155 if (!PyArg_ParseTuple(_args
, "O&",
156 CFURLRefObj_Convert
, &inURL
))
158 _err
= LSCopyDisplayNameForURL(inURL
,
160 if (_err
!= noErr
) return PyMac_Error(_err
);
161 _res
= Py_BuildValue("O&",
162 CFStringRefObj_New
, outDisplayName
);
166 static PyObject
*Launch_LSSetExtensionHiddenForRef(PyObject
*_self
, PyObject
*_args
)
168 PyObject
*_res
= NULL
;
172 if (!PyArg_ParseTuple(_args
, "O&b",
173 PyMac_GetFSRef
, &inRef
,
176 _err
= LSSetExtensionHiddenForRef(&inRef
,
178 if (_err
!= noErr
) return PyMac_Error(_err
);
184 static PyObject
*Launch_LSSetExtensionHiddenForURL(PyObject
*_self
, PyObject
*_args
)
186 PyObject
*_res
= NULL
;
190 if (!PyArg_ParseTuple(_args
, "O&b",
191 CFURLRefObj_Convert
, &inURL
,
194 _err
= LSSetExtensionHiddenForURL(inURL
,
196 if (_err
!= noErr
) return PyMac_Error(_err
);
202 static PyObject
*Launch_LSCopyKindStringForRef(PyObject
*_self
, PyObject
*_args
)
204 PyObject
*_res
= NULL
;
207 CFStringRef outKindString
;
208 if (!PyArg_ParseTuple(_args
, "O&",
209 PyMac_GetFSRef
, &inFSRef
))
211 _err
= LSCopyKindStringForRef(&inFSRef
,
213 if (_err
!= noErr
) return PyMac_Error(_err
);
214 _res
= Py_BuildValue("O&",
215 CFStringRefObj_New
, outKindString
);
219 static PyObject
*Launch_LSCopyKindStringForURL(PyObject
*_self
, PyObject
*_args
)
221 PyObject
*_res
= NULL
;
224 CFStringRef outKindString
;
225 if (!PyArg_ParseTuple(_args
, "O&",
226 CFURLRefObj_Convert
, &inURL
))
228 _err
= LSCopyKindStringForURL(inURL
,
230 if (_err
!= noErr
) return PyMac_Error(_err
);
231 _res
= Py_BuildValue("O&",
232 CFStringRefObj_New
, outKindString
);
236 static PyObject
*Launch_LSGetApplicationForItem(PyObject
*_self
, PyObject
*_args
)
238 PyObject
*_res
= NULL
;
241 LSRolesMask inRoleMask
;
244 if (!PyArg_ParseTuple(_args
, "O&l",
245 PyMac_GetFSRef
, &inItemRef
,
248 _err
= LSGetApplicationForItem(&inItemRef
,
252 if (_err
!= noErr
) return PyMac_Error(_err
);
253 _res
= Py_BuildValue("O&O&",
254 PyMac_BuildFSRef
, &outAppRef
,
255 CFURLRefObj_New
, outAppURL
);
259 static PyObject
*Launch_LSGetApplicationForInfo(PyObject
*_self
, PyObject
*_args
)
261 PyObject
*_res
= NULL
;
265 CFStringRef inExtension
;
266 LSRolesMask inRoleMask
;
269 if (!PyArg_ParseTuple(_args
, "O&O&O&l",
270 PyMac_GetOSType
, &inType
,
271 PyMac_GetOSType
, &inCreator
,
272 OptCFStringRefObj_Convert
, &inExtension
,
275 _err
= LSGetApplicationForInfo(inType
,
281 if (_err
!= noErr
) return PyMac_Error(_err
);
282 _res
= Py_BuildValue("O&O&",
283 PyMac_BuildFSRef
, &outAppRef
,
284 CFURLRefObj_New
, outAppURL
);
288 static PyObject
*Launch_LSGetApplicationForURL(PyObject
*_self
, PyObject
*_args
)
290 PyObject
*_res
= NULL
;
293 LSRolesMask inRoleMask
;
296 if (!PyArg_ParseTuple(_args
, "O&l",
297 CFURLRefObj_Convert
, &inURL
,
300 _err
= LSGetApplicationForURL(inURL
,
304 if (_err
!= noErr
) return PyMac_Error(_err
);
305 _res
= Py_BuildValue("O&O&",
306 PyMac_BuildFSRef
, &outAppRef
,
307 CFURLRefObj_New
, outAppURL
);
311 static PyObject
*Launch_LSFindApplicationForInfo(PyObject
*_self
, PyObject
*_args
)
313 PyObject
*_res
= NULL
;
316 CFStringRef inBundleID
;
320 if (!PyArg_ParseTuple(_args
, "O&O&O&",
321 PyMac_GetOSType
, &inCreator
,
322 OptCFStringRefObj_Convert
, &inBundleID
,
323 OptCFStringRefObj_Convert
, &inName
))
325 _err
= LSFindApplicationForInfo(inCreator
,
330 if (_err
!= noErr
) return PyMac_Error(_err
);
331 _res
= Py_BuildValue("O&O&",
332 PyMac_BuildFSRef
, &outAppRef
,
333 CFURLRefObj_New
, outAppURL
);
337 static PyObject
*Launch_LSCanRefAcceptItem(PyObject
*_self
, PyObject
*_args
)
339 PyObject
*_res
= NULL
;
343 LSRolesMask inRoleMask
;
344 LSAcceptanceFlags inFlags
;
345 Boolean outAcceptsItem
;
346 if (!PyArg_ParseTuple(_args
, "O&O&ll",
347 PyMac_GetFSRef
, &inItemFSRef
,
348 PyMac_GetFSRef
, &inTargetRef
,
352 _err
= LSCanRefAcceptItem(&inItemFSRef
,
357 if (_err
!= noErr
) return PyMac_Error(_err
);
358 _res
= Py_BuildValue("b",
363 static PyObject
*Launch_LSCanURLAcceptURL(PyObject
*_self
, PyObject
*_args
)
365 PyObject
*_res
= NULL
;
368 CFURLRef inTargetURL
;
369 LSRolesMask inRoleMask
;
370 LSAcceptanceFlags inFlags
;
371 Boolean outAcceptsItem
;
372 if (!PyArg_ParseTuple(_args
, "O&O&ll",
373 CFURLRefObj_Convert
, &inItemURL
,
374 CFURLRefObj_Convert
, &inTargetURL
,
378 _err
= LSCanURLAcceptURL(inItemURL
,
383 if (_err
!= noErr
) return PyMac_Error(_err
);
384 _res
= Py_BuildValue("b",
389 static PyObject
*Launch_LSOpenFSRef(PyObject
*_self
, PyObject
*_args
)
391 PyObject
*_res
= NULL
;
394 FSRef outLaunchedRef
;
395 if (!PyArg_ParseTuple(_args
, "O&",
396 PyMac_GetFSRef
, &inRef
))
398 _err
= LSOpenFSRef(&inRef
,
400 if (_err
!= noErr
) return PyMac_Error(_err
);
401 _res
= Py_BuildValue("O&",
402 PyMac_BuildFSRef
, &outLaunchedRef
);
406 static PyObject
*Launch_LSOpenCFURLRef(PyObject
*_self
, PyObject
*_args
)
408 PyObject
*_res
= NULL
;
411 CFURLRef outLaunchedURL
;
412 if (!PyArg_ParseTuple(_args
, "O&",
413 CFURLRefObj_Convert
, &inURL
))
415 _err
= LSOpenCFURLRef(inURL
,
417 if (_err
!= noErr
) return PyMac_Error(_err
);
418 _res
= Py_BuildValue("O&",
419 CFURLRefObj_New
, outLaunchedURL
);
423 static PyMethodDef Launch_methods
[] = {
424 {"LSCopyItemInfoForRef", (PyCFunction
)Launch_LSCopyItemInfoForRef
, 1,
425 PyDoc_STR("(FSRef inItemRef, LSRequestedInfo inWhichInfo) -> (LSItemInfoRecord outItemInfo)")},
426 {"LSCopyItemInfoForURL", (PyCFunction
)Launch_LSCopyItemInfoForURL
, 1,
427 PyDoc_STR("(CFURLRef inURL, LSRequestedInfo inWhichInfo) -> (LSItemInfoRecord outItemInfo)")},
428 {"LSGetExtensionInfo", (PyCFunction
)Launch_LSGetExtensionInfo
, 1,
429 PyDoc_STR("(Buffer inNameLen) -> (UniCharCount outExtStartIndex)")},
430 {"LSCopyDisplayNameForRef", (PyCFunction
)Launch_LSCopyDisplayNameForRef
, 1,
431 PyDoc_STR("(FSRef inRef) -> (CFStringRef outDisplayName)")},
432 {"LSCopyDisplayNameForURL", (PyCFunction
)Launch_LSCopyDisplayNameForURL
, 1,
433 PyDoc_STR("(CFURLRef inURL) -> (CFStringRef outDisplayName)")},
434 {"LSSetExtensionHiddenForRef", (PyCFunction
)Launch_LSSetExtensionHiddenForRef
, 1,
435 PyDoc_STR("(FSRef inRef, Boolean inHide) -> None")},
436 {"LSSetExtensionHiddenForURL", (PyCFunction
)Launch_LSSetExtensionHiddenForURL
, 1,
437 PyDoc_STR("(CFURLRef inURL, Boolean inHide) -> None")},
438 {"LSCopyKindStringForRef", (PyCFunction
)Launch_LSCopyKindStringForRef
, 1,
439 PyDoc_STR("(FSRef inFSRef) -> (CFStringRef outKindString)")},
440 {"LSCopyKindStringForURL", (PyCFunction
)Launch_LSCopyKindStringForURL
, 1,
441 PyDoc_STR("(CFURLRef inURL) -> (CFStringRef outKindString)")},
442 {"LSGetApplicationForItem", (PyCFunction
)Launch_LSGetApplicationForItem
, 1,
443 PyDoc_STR("(FSRef inItemRef, LSRolesMask inRoleMask) -> (FSRef outAppRef, CFURLRef outAppURL)")},
444 {"LSGetApplicationForInfo", (PyCFunction
)Launch_LSGetApplicationForInfo
, 1,
445 PyDoc_STR("(OSType inType, OSType inCreator, CFStringRef inExtension, LSRolesMask inRoleMask) -> (FSRef outAppRef, CFURLRef outAppURL)")},
446 {"LSGetApplicationForURL", (PyCFunction
)Launch_LSGetApplicationForURL
, 1,
447 PyDoc_STR("(CFURLRef inURL, LSRolesMask inRoleMask) -> (FSRef outAppRef, CFURLRef outAppURL)")},
448 {"LSFindApplicationForInfo", (PyCFunction
)Launch_LSFindApplicationForInfo
, 1,
449 PyDoc_STR("(OSType inCreator, CFStringRef inBundleID, CFStringRef inName) -> (FSRef outAppRef, CFURLRef outAppURL)")},
450 {"LSCanRefAcceptItem", (PyCFunction
)Launch_LSCanRefAcceptItem
, 1,
451 PyDoc_STR("(FSRef inItemFSRef, FSRef inTargetRef, LSRolesMask inRoleMask, LSAcceptanceFlags inFlags) -> (Boolean outAcceptsItem)")},
452 {"LSCanURLAcceptURL", (PyCFunction
)Launch_LSCanURLAcceptURL
, 1,
453 PyDoc_STR("(CFURLRef inItemURL, CFURLRef inTargetURL, LSRolesMask inRoleMask, LSAcceptanceFlags inFlags) -> (Boolean outAcceptsItem)")},
454 {"LSOpenFSRef", (PyCFunction
)Launch_LSOpenFSRef
, 1,
455 PyDoc_STR("(FSRef inRef) -> (FSRef outLaunchedRef)")},
456 {"LSOpenCFURLRef", (PyCFunction
)Launch_LSOpenCFURLRef
, 1,
457 PyDoc_STR("(CFURLRef inURL) -> (CFURLRef outLaunchedURL)")},
464 void init_Launch(void)
472 m
= Py_InitModule("_Launch", Launch_methods
);
473 d
= PyModule_GetDict(m
);
474 Launch_Error
= PyMac_GetOSErrException();
475 if (Launch_Error
== NULL
||
476 PyDict_SetItemString(d
, "Error", Launch_Error
) != 0)
480 /* ======================= End module _Launch ======================= */