2010-04-07 06:52:24 +00:00
|
|
|
/* Copyright 2010 Hardcoded Software (http://www.hardcoded.net)
|
|
|
|
|
|
|
|
This software is licensed under the "BSD" License as described in the "LICENSE" file,
|
|
|
|
which should be included with this package. The terms are also available at
|
|
|
|
http://www.hardcoded.net/licenses/bsd_license
|
|
|
|
*/
|
|
|
|
|
2010-04-06 06:58:56 +00:00
|
|
|
#define PY_SSIZE_T_CLEAN
|
|
|
|
#include "Python.h"
|
|
|
|
#include <CoreServices/CoreServices.h>
|
|
|
|
|
2010-04-06 16:04:32 +00:00
|
|
|
static PyObject* send2trash_osx_send(PyObject *self, PyObject *args)
|
2010-04-06 06:58:56 +00:00
|
|
|
{
|
|
|
|
UInt8 *utf8_chars;
|
|
|
|
FSRef fp;
|
|
|
|
OSStatus op_result;
|
|
|
|
|
|
|
|
if (!PyArg_ParseTuple(args, "es", "utf-8", &utf8_chars)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
FSPathMakeRefWithOptions(utf8_chars, kFSPathMakeRefDoNotFollowLeafSymlink, &fp, NULL);
|
|
|
|
op_result = FSMoveObjectToTrashSync(&fp, NULL, kFSFileOperationDefaultOptions);
|
|
|
|
if (op_result != noErr) {
|
2010-04-06 07:04:04 +00:00
|
|
|
PyErr_SetString(PyExc_OSError, GetMacOSStatusCommentString(op_result));
|
2010-04-06 06:58:56 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return Py_None;
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyMethodDef TrashMethods[] = {
|
2010-04-06 16:04:32 +00:00
|
|
|
{"send", send2trash_osx_send, METH_VARARGS, ""},
|
2010-04-07 11:16:51 +00:00
|
|
|
{NULL, NULL, 0, NULL}
|
2010-04-06 06:58:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
PyMODINIT_FUNC
|
2010-04-06 16:04:32 +00:00
|
|
|
init_send2trash_osx(void)
|
2010-04-06 06:58:56 +00:00
|
|
|
{
|
2010-04-06 16:04:32 +00:00
|
|
|
PyObject *m = Py_InitModule("_send2trash_osx", TrashMethods);
|
2010-04-06 06:58:56 +00:00
|
|
|
if (m == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|