~ubuntu-branches/debian/sid/calibre/sid

« back to all changes in this revision

Viewing changes to src/calibre/devices/usbobserver/usbobserver.c

  • Committer: Package Import Robot
  • Author(s): Martin Pitt
  • Date: 2014-05-14 18:17:50 UTC
  • mto: This revision was merged to the branch mainline in revision 75.
  • Revision ID: package-import@ubuntu.com-20140514181750-efj1wymey2vb4cao
Tags: upstream-1.36.0+dfsg
ImportĀ upstreamĀ versionĀ 1.36.0+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
313
313
 
314
314
}
315
315
 
 
316
static PyObject*
 
317
usbobserver_user_locale(PyObject *self, PyObject *args) {
 
318
        CFStringRef id = NULL;
 
319
        CFLocaleRef loc = NULL;
 
320
        char buf[512] = {0};
 
321
        PyObject *ans = NULL;
 
322
        int ok = 0;
 
323
 
 
324
        loc = CFLocaleCopyCurrent();
 
325
        if (loc) {
 
326
            id = CFLocaleGetIdentifier(loc);
 
327
            if (id && CFStringGetCString(id, buf, 512, kCFStringEncodingUTF8)) {
 
328
                ok = 1;
 
329
                ans = PyUnicode_FromString(buf);
 
330
            }
 
331
        }
 
332
 
 
333
        if (loc) CFRelease(loc);
 
334
        if (ok) return ans;
 
335
        Py_RETURN_NONE;
 
336
}
 
337
 
 
338
static PyObject*
 
339
usbobserver_date_fmt(PyObject *self, PyObject *args) {
 
340
        CFStringRef fmt = NULL;
 
341
        CFLocaleRef loc = NULL;
 
342
        CFDateFormatterRef formatter = NULL;
 
343
        char buf[512] = {0};
 
344
        PyObject *ans = NULL;
 
345
        int ok = 0;
 
346
 
 
347
        loc = CFLocaleCopyCurrent();
 
348
        if (loc) {
 
349
            formatter = CFDateFormatterCreate(kCFAllocatorDefault, loc, kCFDateFormatterShortStyle, kCFDateFormatterNoStyle);
 
350
            if (formatter) {
 
351
                fmt = CFDateFormatterGetFormat(formatter);
 
352
                if (fmt && CFStringGetCString(fmt, buf, 512, kCFStringEncodingUTF8)) {
 
353
                    ok = 1;
 
354
                    ans = PyUnicode_FromString(buf);
 
355
                }
 
356
            }
 
357
        }
 
358
        if (formatter) CFRelease(formatter);
 
359
        if (loc) CFRelease(loc);
 
360
        if (ok) return ans;
 
361
        Py_RETURN_NONE;
 
362
}
 
363
 
 
364
 
316
365
static PyMethodDef usbobserver_methods[] = {
317
366
    {"get_usb_devices", usbobserver_get_usb_devices, METH_VARARGS, 
318
367
     "Get list of connected USB devices. Returns a list of tuples. Each tuple is of the form (vendor_id, product_id, bcd, manufacturer, product, serial number)."
326
375
    {"send2trash", usbobserver_send2trash, METH_VARARGS, 
327
376
     "send2trash(unicode object) -> Send specified file/dir to trash"
328
377
    },
 
378
    {"user_locale", usbobserver_user_locale, METH_VARARGS, 
 
379
     "user_locale() -> The name of the current user's locale or None if an error occurred"
 
380
    },
 
381
    {"date_format", usbobserver_date_fmt, METH_VARARGS, 
 
382
     "date_format() -> The (short) date format used by the user's current locale"
 
383
    },
 
384
 
 
385
 
329
386
 
330
387
    {NULL, NULL, 0, NULL}
331
388
};