static void setupFavLink_private(const QString &folder) { // Nautilus: add to ~/.gtk-bookmarks QFile gtkBookmarks(QDir::homePath()+QLatin1String("/.gtk-bookmarks")); QByteArray folderUrl = "file://" + folder.toUtf8(); if (gtkBookmarks.open(QFile::ReadWrite)) { QByteArray places = gtkBookmarks.readAll(); if (!places.contains(folderUrl)) { places += folderUrl; gtkBookmarks.reset(); gtkBookmarks.write(places + '\n'); } } }
void Utility::setupFavLink(const QString &folder) { #ifdef Q_OS_WIN // Windows Explorer: Place under "Favorites" (Links) wchar_t path[MAX_PATH]; SHGetSpecialFolderPath(0, path, CSIDL_PROFILE, FALSE); QString profile = QDir::fromNativeSeparators(QString::fromWCharArray(path)); QDir folderDir(QDir::fromNativeSeparators(folder)); QString linkName = profile+QLatin1String("/Links/") + folderDir.dirName() + QLatin1String(".lnk"); if (!QFile::link(folder, linkName)) qDebug() << Q_FUNC_INFO << "linking" << folder << "to" << linkName << "failed!"; #elif defined (Q_OS_MAC) // Finder: Place under "Places"/"Favorites" on the left sidebar CFStringRef folderCFStr = CFStringCreateWithCString(0, folder.toUtf8().data(), kCFStringEncodingUTF8); CFURLRef urlRef = CFURLCreateWithFileSystemPath (0, folderCFStr, kCFURLPOSIXPathStyle, true); LSSharedFileListRef placesItems = LSSharedFileListCreate(0, kLSSharedFileListFavoriteItems, 0); if (placesItems) { //Insert an item to the list. LSSharedFileListItemRef item = LSSharedFileListInsertItemURL(placesItems, kLSSharedFileListItemLast, 0, 0, urlRef, 0, 0); if (item) CFRelease(item); } CFRelease(placesItems); CFRelease(folderCFStr); CFRelease(urlRef); #elif defined (Q_OS_UNIX) // Nautilus: add to ~/.gtk-bookmarks QFile gtkBookmarks(QDir::homePath()+QLatin1String("/.gtk-bookmarks")); QByteArray folderUrl = "file://" + folder.toUtf8(); if (gtkBookmarks.open(QFile::ReadWrite)) { QByteArray places = gtkBookmarks.readAll(); if (!places.contains(folderUrl)) { places += folderUrl; gtkBookmarks.reset(); gtkBookmarks.write(places + '\n'); } } #endif }