static bool isPackage(const QFileSystemMetaData &data, const QFileSystemEntry &entry) { if (!data.isDirectory()) return false; QFileInfo info(entry.filePath()); QString suffix = info.suffix(); if (suffix.length() > 0) { // First step: is the extension known ? CFStringRef extensionRef = QCFString::toCFStringRef(suffix); CFStringRef uniformTypeIdentifier = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, extensionRef, NULL); if (UTTypeConformsTo(uniformTypeIdentifier, kUTTypeBundle)) return true; // Second step: check if an application knows the package type CFStringRef path = QCFString::toCFStringRef(entry.filePath()); QCFType<CFURLRef> url = CFURLCreateWithFileSystemPath(0, path, kCFURLPOSIXPathStyle, true); UInt32 type, creator; // Well created packages have the PkgInfo file if (CFBundleGetPackageInfoInDirectory(url, &type, &creator)) return true; // Find if an application other than Finder claims to know how to handle the package QCFType<CFURLRef> application; LSGetApplicationForURL(url, kLSRolesEditor|kLSRolesViewer|kLSRolesViewer, NULL, &application); if (application) { QCFType<CFBundleRef> bundle = CFBundleCreate(kCFAllocatorDefault, application); CFStringRef identifier = CFBundleGetIdentifier(bundle); QString applicationId = QCFString::toQString(identifier); if (applicationId != QLatin1String("com.apple.finder")) return true; } } // Third step: check if the directory has the package bit set FSRef packageRef; FSPathMakeRef((UInt8 *)entry.nativeFilePath().constData(), &packageRef, NULL); FSCatalogInfo catalogInfo; FSGetCatalogInfo(&packageRef, kFSCatInfoFinderInfo, &catalogInfo, NULL, NULL, NULL); FolderInfo *folderInfo = reinterpret_cast<FolderInfo *>(catalogInfo.finderInfo); return folderInfo->finderFlags & kHasBundle; }
static bool isPackage(const QFileSystemMetaData &data, const QFileSystemEntry &entry) { if (!data.isDirectory()) return false; QFileInfo info(entry.filePath()); QString suffix = info.suffix(); if (suffix.length() > 0) { // First step: is the extension known ? QCFType<CFStringRef> extensionRef = QCFString::toCFStringRef(suffix); QCFType<CFStringRef> uniformTypeIdentifier = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, extensionRef, NULL); if (UTTypeConformsTo(uniformTypeIdentifier, kUTTypeBundle)) return true; // Second step: check if an application knows the package type QCFType<CFStringRef> path = QCFString::toCFStringRef(entry.filePath()); QCFType<CFURLRef> url = CFURLCreateWithFileSystemPath(0, path, kCFURLPOSIXPathStyle, true); UInt32 type, creator; // Well created packages have the PkgInfo file if (CFBundleGetPackageInfoInDirectory(url, &type, &creator)) return true; #ifdef Q_OS_OSX // Find if an application other than Finder claims to know how to handle the package QCFType<CFURLRef> application; LSGetApplicationForURL(url, kLSRolesEditor|kLSRolesViewer|kLSRolesViewer, NULL, &application); if (application) { QCFType<CFBundleRef> bundle = CFBundleCreate(kCFAllocatorDefault, application); CFStringRef identifier = CFBundleGetIdentifier(bundle); QString applicationId = QCFString::toQString(identifier); if (applicationId != QLatin1String("com.apple.finder")) return true; } #endif } // Third step: check if the directory has the package bit set return hasResourcePropertyFlag(data, entry, kCFURLIsPackageKey); }
static PyObject *Launch_LSGetApplicationForURL(PyObject *_self, PyObject *_args) { PyObject *_res = NULL; OSStatus _err; CFURLRef inURL; LSRolesMask inRoleMask; FSRef outAppRef; CFURLRef outAppURL; if (!PyArg_ParseTuple(_args, "O&l", CFURLRefObj_Convert, &inURL, &inRoleMask)) return NULL; _err = LSGetApplicationForURL(inURL, inRoleMask, &outAppRef, &outAppURL); if (_err != noErr) return PyMac_Error(_err); _res = Py_BuildValue("O&O&", PyMac_BuildFSRef, &outAppRef, CFURLRefObj_New, outAppURL); return _res; }
void Common::mailTo( const QUrl &url ) { #if defined(Q_OS_WIN32) QString file = url.queryItemValue( "attachment" ); QByteArray filePath = QDir::toNativeSeparators( file ).toLatin1(); QByteArray fileName = QFileInfo( file ).fileName().toLatin1(); QByteArray subject = url.queryItemValue( "subject" ).toLatin1(); MapiFileDesc doc[1]; doc[0].ulReserved = 0; doc[0].flFlags = 0; doc[0].nPosition = -1; doc[0].lpszPathName = const_cast<char*>(filePath.constData()); doc[0].lpszFileName = const_cast<char*>(fileName.constData()); doc[0].lpFileType = NULL; // Create message MapiMessage message; message.ulReserved = 0; message.lpszSubject = const_cast<char*>(subject.constData()); message.lpszNoteText = ""; message.lpszMessageType = NULL; message.lpszDateReceived = NULL; message.lpszConversationID = NULL; message.flFlags = 0; message.lpOriginator = NULL; message.nRecipCount = 0; message.lpRecips = NULL; message.nFileCount = 1; message.lpFiles = (lpMapiFileDesc)&doc; QLibrary lib("mapi32"); typedef ULONG (PASCAL *SendMail)(ULONG,ULONG,MapiMessage*,FLAGS,ULONG); SendMail mapi = (SendMail)lib.resolve("MAPISendMail"); if( mapi ) { mapi( NULL, 0, &message, MAPI_LOGON_UI|MAPI_DIALOG, 0 ); return; } #elif defined(Q_OS_MAC) CFURLRef emailUrl = CFURLCreateWithString( kCFAllocatorDefault, CFSTR("mailto:"), 0 ); CFURLRef appUrl = 0; CFStringRef appPath = 0; if( LSGetApplicationForURL( emailUrl, kLSRolesAll, NULL, &appUrl ) == noErr ) { appPath = CFURLCopyFileSystemPath( appUrl, kCFURLPOSIXPathStyle ); CFRelease( appUrl ); } CFRelease( emailUrl ); if( appPath ) { QProcess p; p.start( "/usr/bin/osascript", QStringList() << "-" << url.queryItemValue("attachment") << url.queryItemValue("subject") ); p.waitForStarted(); QTextStream s( &p ); if( CFStringCompare( appPath, CFSTR("/Applications/Mail.app"), 0 ) == kCFCompareEqualTo ) { s << "on run argv" << endl << "set vattachment to (item 1 of argv)" << endl << "set vsubject to (item 2 of argv)" << endl << "tell application \"Mail\"" << endl << "set composeMessage to make new outgoing message at beginning with properties {visible:true}" << endl << "tell composeMessage" << endl << "set subject to vsubject" << endl << "set content to \" \"" << endl << "tell content" << endl << "make new attachment with properties {file name: vattachment} at after the last word of the last paragraph" << endl << "end tell" << endl << "end tell" << endl << "activate" << endl << "end tell" << endl << "end run" << endl; } else if( CFStringFind( appPath, CFSTR("Entourage"), 0 ).location != kCFNotFound ) { s << "on run argv" << endl << "set vattachment to (item 1 of argv)" << endl << "set vsubject to (item 2 of argv)" << endl << "tell application \"Microsoft Entourage\"" << endl << "set vmessage to make new outgoing message with properties" << endl << "{subject:vsubject, attachments:vattachment}" << endl << "open vmessage" << endl << "activate" << endl << "end tell" << endl << "end run" << endl; } #if 0 else if(CFStringCompare(appPath, CFSTR("/Applications/Thunderbird.app"), 0) == kCFCompareEqualTo) { // TODO: Handle Thunderbird here? Impossible? } #endif CFRelease( appPath ); p.closeWriteChannel(); p.waitForFinished(); if( p.exitCode() == 0 ) return; } #elif defined(Q_OS_LINUX) QByteArray thunderbird; QProcess p; QStringList env = QProcess::systemEnvironment(); if( env.indexOf( QRegExp("KDE_FULL_SESSION.*") ) != -1 ) { p.start( "kreadconfig", QStringList() << "--file" << "emaildefaults" << "--group" << "PROFILE_Default" << "--key" << "EmailClient" ); p.waitForFinished(); QByteArray data = p.readAllStandardOutput().trimmed(); if( data.contains("thunderbird") ) thunderbird = data; } else if( env.indexOf( QRegExp("GNOME_DESKTOP_SESSION_ID.*") ) != -1 ) { p.start( "gconftool-2", QStringList() << "--get" << "/desktop/gnome/url-handlers/mailto/command" ); p.waitForFinished(); QByteArray data = p.readAllStandardOutput(); if( data.contains("thunderbird") ) thunderbird = data.split(' ').value(0); } /* else { p.start( "xprop", QStringList() << "-root" << "_DT_SAVE_MODE" ); p.waitForFinished(); if( p.readAllStandardOutput().contains("xfce4") ) {} }*/ if( !thunderbird.isEmpty() ) { if( p.startDetached( thunderbird, QStringList() << "-compose" << QString( "subject='%1',attachment='%2'" ) .arg( url.queryItemValue( "subject" ) ) .arg( QUrl::fromLocalFile( url.queryItemValue( "attachment" ) ).toString() ) ) ); return; } else { if( p.startDetached( "xdg-email", QStringList() << "--subject" << url.queryItemValue( "subject" ) << "--attach" << url.queryItemValue( "attachment" ) ) ) return; } #endif QDesktopServices::openUrl( url ); }