Exemplo n.º 1
0
static PyObject *Launch_LSGetApplicationForInfo(PyObject *_self, PyObject *_args)
{
    PyObject *_res = NULL;
    OSStatus _err;
    OSType inType;
    OSType inCreator;
    CFStringRef inExtension;
    LSRolesMask inRoleMask;
    FSRef outAppRef;
    CFURLRef outAppURL;
    if (!PyArg_ParseTuple(_args, "O&O&O&l",
                          PyMac_GetOSType, &inType,
                          PyMac_GetOSType, &inCreator,
                          OptCFStringRefObj_Convert, &inExtension,
                          &inRoleMask))
        return NULL;
    _err = LSGetApplicationForInfo(inType,
                                   inCreator,
                                   inExtension,
                                   inRoleMask,
                                   &outAppRef,
                                   &outAppURL);
    if (_err != noErr) return PyMac_Error(_err);
    _res = Py_BuildValue("O&O&",
                         PyMac_BuildFSRef, &outAppRef,
                         CFURLRefObj_New, outAppURL);
    return _res;
}
Exemplo n.º 2
0
// Look up the (locale) display name and icon file associated with a UTI
void wxMimeTypesManagerImpl::LoadDisplayDataForUti(const wxString& uti)
{
    // Keys in to Info.plist
    const static wxCFStringRef docTypesKey( "CFBundleDocumentTypes" );
    const static wxCFStringRef descKey( "CFBundleTypeName" );
    const static wxCFStringRef iconKey( "CFBundleTypeIconFile" );

    // The call for finding the preferred application for a UTI is LSCopyDefaultRoleHandlerForContentType
    // This returns an empty string on OS X 10.5
    // Instead it is necessary to get the primary extension and use LSGetApplicationForInfo
    wxCFStringRef ext = UTTypeCopyPreferredTagWithClass( wxCFStringRef( uti ), kUTTagClassFilenameExtension );

    // Look up the preferred application
    CFURLRef appUrl;
    OSStatus status = LSGetApplicationForInfo( kLSUnknownType, kLSUnknownCreator, ext, kLSRolesAll, NULL, &appUrl );

    if( status != noErr )
        return;

    // Create a bundle object for that application
    wxCFRef< CFBundleRef > bundle;
    bundle = wxCFRef< CFBundleRef >( CFBundleCreate( kCFAllocatorDefault, appUrl ) );

    if( !bundle )
        return;

    // Also get the open command while we have the bundle
    wxCFStringRef cfsAppPath(CFURLCopyFileSystemPath(appUrl, kCFURLPOSIXPathStyle));
    m_utiMap[ uti ].application = cfsAppPath.AsString();

    // Get all the document type data in this bundle
    CFTypeRef docTypeData;
    docTypeData = CFBundleGetValueForInfoDictionaryKey( bundle, docTypesKey );

    if( !docTypeData )
        return;

    // Find the document type entry that matches ext
    CFDictionaryRef docType;
    docType = GetDocTypeForExt( docTypeData, ext );

    if( !docType )
        return;

    // Get the display name for docType
    wxCFStringRef description = reinterpret_cast< CFStringRef >( CFDictionaryGetValue( docType, descKey ) );
    wxCFRetain( description.get() );
    m_utiMap[ uti ].description = description.AsString();

    // Get the icon path for docType
    CFStringRef iconFile = reinterpret_cast< CFStringRef > ( CFDictionaryGetValue( docType, iconKey ) );
    m_utiMap[ uti ].iconLoc.SetFileName( GetPathForIconFile( bundle, iconFile ) );
}
Exemplo n.º 3
0
Notificator::Notificator(const QString &programName, QSystemTrayIcon *trayicon, QWidget *parent):
    QObject(parent),
    parent(parent),
    programName(programName),
    mode(None),
    trayIcon(trayicon)
#ifdef USE_DBUS
    ,interface(0)
#endif
{
    if(trayicon && trayicon->supportsMessages())
    {
        mode = QSystemTray;
    }
#ifdef USE_DBUS
    interface = new QDBusInterface("org.freedesktop.Notifications",
          "/org/freedesktop/Notifications", "org.freedesktop.Notifications");
    if(interface->isValid())
    {
        mode = Freedesktop;
    }
#endif
#ifdef Q_OS_MAC
        printf("notification::begin\n");
        // check if users OS has support for NSUserNotification
        if( MacNotificationHandler::instance()->hasUserNotificationCenterSupport()) {
            printf("notification::has\n");
            mode = UserNotificationCenter;
        } else {
            printf("notification::no\n");
            // Check if Growl is installed (based on Qt's tray icon implementation)
            CFURLRef cfurl;
           OSStatus status = LSGetApplicationForInfo(kLSUnknownType, kLSUnknownCreator, CFSTR("growlTicket"), kLSRolesAll, 0, &cfurl);
           if (status != kLSApplicationNotFoundErr) {
                CFBundleRef bundle = CFBundleCreate(0, cfurl);
                if (CFStringCompare(CFBundleGetIdentifier(bundle), CFSTR("com.Growl.GrowlHelperApp"), kCFCompareCaseInsensitive | kCFCompareBackwards) == kCFCompareEqualTo) {
                    if (CFStringHasSuffix(CFURLGetString(cfurl), CFSTR("/Growl.app/")))
                    mode = Growl13;
                else
                    mode = Growl12;
                }
            CFRelease(cfurl);
            CFRelease(bundle);
         }
    }
#endif
}