| 184 | } |
| 185 | |
| 186 | QSharedPointer<Library> LibraryManager::createLibraryFromKnownFolders(QList<KNOWNFOLDERID>& kfList) |
| 187 | { |
| 188 | QSharedPointer<LibraryImpl> library(NULL); |
| 189 | if (!_comInitialized || !_pSHGetKnownFolderIDList || !_pSHCreateItemFromIDList) |
| 190 | return library; |
| 191 | |
| 192 | QString libraryName; |
| 193 | QString iconPath; |
| 194 | QList<QString> directories; |
| 195 | QListIterator<KNOWNFOLDERID> iter(kfList); |
| 196 | while (iter.hasNext()) |
| 197 | { |
| 198 | const KNOWNFOLDERID& id = iter.next(); |
| 199 | PIDLIST_ABSOLUTE pidl; |
| 200 | if (SUCCEEDED(_pSHGetKnownFolderIDList(id, KF_FLAG_DEFAULT_PATH, NULL, &pidl))) |
| 201 | { |
| 202 | IShellItem* item; |
| 203 | if (SUCCEEDED(_pSHCreateItemFromIDList(pidl, IID_PPV_ARGS(&item)))) |
| 204 | { |
| 205 | LPWSTR path; |
| 206 | if (SUCCEEDED(item->GetDisplayName(SIGDN_DESKTOPABSOLUTEPARSING, &path))) |
| 207 | { |
| 208 | directories.append(QString::fromUtf16((const ushort*) path)); |
| 209 | CoTaskMemFree(path); |
| 210 | |
| 211 | if (id == kfList.front()) |
| 212 | { |
| 213 | // This is the first directory, so use it's folder name as the name of the Library |
| 214 | LPWSTR name; |
| 215 | if (SUCCEEDED(item->GetDisplayName(SIGDN_NORMALDISPLAY, &name))) |
| 216 | { |
| 217 | libraryName = QString::fromUtf16((const ushort*) name); |
| 218 | CoTaskMemFree(name); |
| 219 | } |
| 220 | } |
| 221 | } |
| 222 | item->Release(); |
| 223 | } |
| 224 | CoTaskMemFree(pidl); |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | if (directories.isEmpty()) |
| 229 | return library; |
| 230 | |
| 231 | library = QSharedPointer<LibraryImpl>(new LibraryImpl(libraryName)); |
| 232 | library->setTextureKey(QString_NT("library_default.folder.icon")); |
| 233 | library->setFolderPaths(directories); |
| 234 | library->setHashKey(QString_NT("lib_%1").arg(directories.front())); |
| 235 | library->setValid(true); |
| 236 | return library; |
| 237 | } |
| 238 | |
| 239 | QSharedPointer<Library> LibraryManager::createDesktopLibrary() |
| 240 | { |
nothing calls this directly
no test coverage detected