In the application that I work on, I need to use a QFileDialog that is non-native (QFileDialog::DontUseNativeDialog) because we need to add some custom logic in the folder selection (like if the folder contains a file, this part is out of the scope of this question). I can add the desired paths on the side bar by using:
QFileDialog *fd = new QFileDialog(parent, caption, updateLastAccessedDir(dir));
fd->setOptions(options | QFileDialog::DontUseNativeDialog);
QFileInfoList drives = QDir::drives();
for (auto d : drives)
fd->sidebarUrls()->append(QUrl::fromLocalFile(d.path()));
fd->sidebarUrls()->append(QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)));
fd->sidebarUrls()->append(QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation)));
fd->sidebarUrls()->append(QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::DesktopLocation)));
I want to be able to also add the bookmarked locations that the user has in the native file explorer. However, I do not know how to get the list of these paths.
Is there any way of getting the list of bookmarked paths in the native file explorer in c++? This is a Ubuntu and Windows application so it would be perfect if the solution is not OS-dependent (which I'm afraid will not be possible).
Related
I display objects, some of which are files and folders in TTreeView, TListView and a few other custom controls.
When a folder is selected, I display its contents (files and folders) in TListViewand I use the Windows System Image List to assign an icon. I call SHGetFileInfoW to obtain an icon index. SHGetFileInfoW is also used to obtain the System Image List Handle:
SHFILEINFOW info ;
DWORD Flags = (SHGFI_SMALLICON | SHGFI_SYSICONINDEX | SHGFI_OVERLAYINDEX) // for instance
ImageList->Handle = SHGetFileInfoW( L"",
0,
&info,
sizeof(SHFILEINFOW),
Flags
) ;
My program also keeps its own ImageList with icons, since it displays more than just files and folders. In TreeView for instance a combination of 'other objects' and folder objects will be shown:
To keep folder icons consistent (same) between TreeView and ListView on different versions of the Windows OS, I copy the Windows System folder icon to my own ImageList during program start.
This way both TreeView and ListView use the same folder icon, and the icon is that of the OS the software is running on.
This has worked well for many years across many OS, from Win2K to W11. However I'd like to try the reverse approach now IF at all possible. I'd like to use my own folder icon in both ListView and TreeView. For TreeView this is not a problem, but for ListView it is an issue in every situation where files and folders are displayed together, since I use the Windows System Image List to display the file icons and hence also folder icons.
I can think of a workaround where I create the needed registry entries to register a very unique file extension that is associated with a folder icon in my executable. I could then use that for folders. But it's a workaround that may not always work perfectly if Windows doesn't refresh immediately etc.
So, the question, is it at all possible to add an icon to the System Image List during program execution ? Is there a Windows API call that does this ? If so I could use that Index then to display folder icons in ListView.
Yes and no.
First off, in Windows NT based systems, the system image list is per-process and is not a full copy of the real list. In Windows 95 it really was global. This means the design never intended for people to add extra HICONs on their own directly into the list.
While it is called the system image list, the only thing it stores are file type icons and the shell extension overlays, it is not a general icon list.
There are two ways to add icons to the list:
The common way is to use one of the shell functions (like SHGetFileInfo) to ask for information about a file path or extension.
The other way is to call Shell_GetCachedImageIndex. This function used to be undocumented and was only documented because of the DOJ trial.
My suggestion: Use your own custom imagelist with your custom images. In slot 0 place an empty icon that you draw on top of with custom draw (not owner-draw).
My task is to program change sorting parameter of files and folders in my operating system.
In the article on the MSDN:
under
Modifying the Windows Explorer Toolbar
indicated
In addition to modifying the Windows Explorer menu bar, you can also add buttons to the toolbar. And an example code.
But example of this modifying the Windows Explorer menu bar is not there, the only thing is there it's button adding example.
An alternative article has an example of opening it, so my question is: is it even possible, and if it is, how to do it?
The folder sort settings are saved to:
HKCU\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\Bags\
HKCU\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\BagMRU
The entries look like:
You would need to loop through all of these registry entries and change the 'Sort' key. This would only affect folders which have already been accessed.
If you want to see how these lists are parsed, run ShellBagsView while running ProcMon and log all the interactions with the registry.
To do it, not programatically you can follow these instructions:
https://superuser.com/a/1481763/1043059
I am trying to wrap my head around Microsoft's shell extension context menu handler example.
Its implementation only shows a context menu on a .cpp file right-click. I want to try to extend it to allow it to show the context menu whenever a folder, drive, or empty space is right-clicked in Explorer as well.
So far I was only able to modify it to register right-clicks for all file types, not just .cpp files by specifying * when registering it:
hr = RegisterShellExtContextMenuHandler(L"*",
CLSID_FileContextMenuExt,
L"CppShellExtContextMenuHandler.FileContextMenuExt");
I must be missing something else because it won't pop up for folders. I have tried this suggestion but it did not work.
How can I extend this sample to also have it work for folders? Am I missing something from the registry?
Edit: Thanks to Igor's suggestion, I got it to work for folders and drives, but it does not show up when you right-click the desktop or when you right click blank space in a folder, and I did register for Directory\Background and DesktopBackground. Why is this?
I have a problem with QFileDialog in a software that my friend and I are developing.
The software is a CAD programmed in C++/Qt(5.6) , so it uses a lot the MVC design pattern. The problem is the following :
We use QFileDialog when we are about to load or save a project.
-When we start the software and we first load the project, everything works fine
-When we try to load again, the QFileDialog doesn't display well. It does not seem frozen, the only displayed part (folders part, on the left) responds but does not display any file on the center.
The only difference I see is that after the first load, QGraphicsItem are created and updated in order to display the parts of the loaded project.
Do you know what could be the problem ?
EDIT - The Code
QFileDialog fileDialog(0,tr("Load Project"), "./..", tr("CAD files (*.json)"));
fileDialog.setAcceptMode(QFileDialog::AcceptOpen);
fileDialog.setFileMode(QFileDialog::ExistingFiles);
if (QDialog::Accepted != fileDialog.exec())
return NULL;
QStringList sel = fileDialog.selectedFiles();
EDIT 2 - A working solution
By forcing Qt not to use the native dialog we can display a window correctly.
fileDialog.setOption(QFileDialog::DontUseNativeDialog,true);
We are on Linux Mint 17.2, with cinnamon. Did you know any conflict between Qt and Cinnamon ?
It might be a problem with the relative directory/path "./..". Try replacing it with something else, for example QDir::home().absolutePath()
QFileDialog fileDialog(0,
tr("Load Project"),
QDir::home().absolutePath(),
tr("CAD files (*.json)"));
Qt might also conflicting with something that is installed on the machine, as noted by #ElevenJune:
By forcing Qt not to use the native dialog we can display a window correctly.
That sounds like a conflict to me... Are you using any other libraries than Qt within the app?
Is there any way to add folders to the sidebar in an MFC CFileDialog? (You know, the bar with shortcuts to "Recent Documents", "My Documents", etc. on the left side of the dialog.) Note that I do not mean that I want the user to have to hack the registry or something to permanently add folders to the sidebar system-wide, I'm talking about having my program add a folder to the side-bar for its own file dialogs. So far my research leads me to believe that for XP I can create a custom dialog and replace the side-bar with my own side bar that has the folders in it, but this won't work on Vista (and by extension Windows 7 I'm assuming). So does anyone know a, preferably low pain, way to add folders to that side-bar?
Since Vista there is the IFileDialog which have the AddPlace(...) method.
You will need to write a wrapper that will use CFileDialog (On XP) or IFileDialog (Vista and up).