44 #ifndef QT_NO_FILEDIALOG 46 #include <private/qfiledialog_p.h> 48 #include <private/qapplication_p.h> 55 #include <private/qsystemlibrary_p.h> 63 static const IID QT_IID_IFileOpenDialog = {0xd57c7288, 0xd4ad, 0x4768, {0xbe, 0x02, 0x9d, 0x96, 0x95, 0x32, 0xd9, 0x60} };
64 static const IID QT_IID_IShellItem = {0x43826d1e, 0xe718, 0x42ee, {0xbc, 0x55, 0xa1, 0xe2, 0x61, 0xc3, 0x7b, 0xfe} };
65 static const CLSID QT_CLSID_FileOpenDialog = {0xdc1c5a9c, 0xe88a, 0x4dde, {0xa5, 0xa1, 0x60, 0xf8, 0x2a, 0x20, 0xae, 0xf7} };
81 static bool triedResolve =
false;
83 #if !defined(Q_WS_WINCE) 143 for (; it != filterLst.
end(); ++
it) {
146 if (hideFiltersDetails) {
149 winfilters += r.
cap(1);
151 winfilters += subfilter;
153 winfilters +=
QChar();
155 winfilters +=
QChar();
158 winfilters +=
QChar();
170 const QString& initialSelection,
171 const QString& initialDirectory,
175 QFileDialog::Options options)
178 parent = parent->
window();
194 wchar_t *tInitSel =
new wchar_t[maxLen + 1];
200 OPENFILENAME* ofn =
new OPENFILENAME;
201 memset(ofn, 0,
sizeof(OPENFILENAME));
203 ofn->lStructSize =
sizeof(OPENFILENAME);
204 ofn->hwndOwner = parent ? parent->
winId() : 0;
205 ofn->lpstrFilter = (
wchar_t*)tFilters.
utf16();
206 ofn->lpstrFile = tInitSel;
207 ofn->nMaxFile = maxLen;
208 ofn->lpstrInitialDir = (
wchar_t*)tInitDir.
utf16();
209 ofn->lpstrTitle = (
wchar_t*)tTitle.
utf16();
210 ofn->Flags = (OFN_NOCHANGEDIR | OFN_HIDEREADONLY | OFN_EXPLORER | OFN_PATHMUSTEXIST);
213 ofn->Flags |= (OFN_FILEMUSTEXIST);
215 ofn->Flags |= (OFN_ALLOWMULTISELECT);
217 ofn->Flags |= OFN_OVERWRITEPROMPT;
224 delete [] (*ofn)->lpstrFile;
240 initialDirectory->
remove(0, 5);
243 if (initialDirectory && !fi.
isDir()) {
255 if (selectedFilter) {
257 idx = filterLst.
indexOf(*selectedFilter);
272 ofn->nFilterIndex = idx + 1;
273 if (GetOpenFileName(ofn)) {
275 selFilIdx = ofn->nFilterIndex;
287 *initialDirectory = fi.
path();
301 initialDirectory->
remove(0, 5);
304 if (initialDirectory && !fi.
isDir()) {
316 if (selectedFilter) {
318 idx = filterLst.
indexOf(*selectedFilter);
332 if (selectedFilter && !selectedFilter->
isEmpty()) {
336 if (firstDot != -1) {
337 defaultSaveExt.
remove(0, firstDot + 1);
339 defaultSaveExt.
clear();
349 ofn->lpstrDefExt = (
wchar_t*)defaultSaveExt.
utf16();
352 ofn->nFilterIndex = idx + 1;
353 if (GetSaveFileName(ofn)) {
355 selFilIdx = ofn->nFilterIndex;
359 #if defined(Q_WS_WINCE) 362 result = result.
left(semIndex);
373 *initialDirectory = fi.
path();
382 typedef HRESULT (WINAPI *PtrSHCreateItemFromParsingName)(PCWSTR pszPath, IBindCtx *pbc, REFIID riid,
void **ppv);
383 static PtrSHCreateItemFromParsingName pSHCreateItemFromParsingName = 0;
385 static bool qt_win_set_IFileDialogOptions(IFileDialog *pfd,
386 const QString& initialSelection,
387 const QString& initialDirectory,
391 QFileDialog::Options options)
393 if (!pSHCreateItemFromParsingName) {
396 pSHCreateItemFromParsingName = (PtrSHCreateItemFromParsingName)
397 shellLib.
resolve(
"SHCreateItemFromParsingName");
398 if (!pSHCreateItemFromParsingName)
408 for (; it != filterLst.
end(); ++
it) {
411 offsets<<currentOffset;
414 winfilters += subfilter;
415 winfilters +=
QChar();
416 currentOffset += subfilter.
size()+1;
417 offsets<<currentOffset;
420 winfilters +=
QChar();
421 currentOffset += spec.
size()+1;
427 wchar_t *szData = (
wchar_t*)winfilters.
utf16();
429 for(
int i = 0; i<numFilters; i++) {
430 filterSpec[i].
pszName = szData+offsets[i*2];
431 filterSpec[i].
pszSpec = szData+offsets[(i*2)+1];
433 hr = pfd->SetFileTypes(numFilters, filterSpec);
439 IShellItem *psiDefaultFolder;
440 hr = pSHCreateItemFromParsingName((
wchar_t*)tInitDir.
utf16(), NULL, QT_IID_IShellItem,
441 reinterpret_cast<void**
>(&psiDefaultFolder));
444 hr = pfd->SetFolder(psiDefaultFolder);
445 psiDefaultFolder->Release();
457 hr = pfd->SetFileName((
wchar_t*)initSel.
utf16());
461 hr = pfd->SetTitle((
wchar_t*)title.
utf16());
465 hr = pfd->GetOptions(&newOptions);
475 hr = pfd->SetOptions(newOptions);
477 return SUCCEEDED(hr);
484 int selectedFilterIndex)
492 IFileOpenDialog *pfd = 0;
493 HRESULT hr = CoCreateInstance(QT_CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, QT_IID_IFileOpenDialog,
494 reinterpret_cast<void**>(&pfd));
497 qt_win_set_IFileDialogOptions(pfd, args.
selection,
502 hr = pfd->SetFileTypeIndex(selectedFilterIndex+1);
505 parentWindow = parentWindow->
window();
509 hr = pfd->Show(parentWindow ? parentWindow->
winId() : 0);
512 IShellItemArray *psiaResults;
513 hr = pfd->GetResults(&psiaResults);
516 psiaResults->GetCount(&numItems);
517 for (DWORD i = 0; i<numItems; i++) {
519 hr = psiaResults->GetItemAt(i, &psi);
527 CoTaskMemFree(pszPath);
532 psiaResults->Release();
543 hr = pfd->GetFolder(&psi);
549 CoTaskMemFree(pszPath);
554 if (selectedFilter) {
556 hr = pfd->GetFileTypeIndex(&filetype);
557 if (SUCCEEDED(hr) && filetype && filetype <= (
quint32)filterList.
length()) {
559 *selectedFilter = filterList[filetype-1];
576 IFileOpenDialog *pfd = 0;
577 HRESULT hr = CoCreateInstance(QT_CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER,
578 QT_IID_IFileOpenDialog, reinterpret_cast<void**>(&pfd));
581 qt_win_set_IFileDialogOptions(pfd, args.
selection,
588 hr = pfd->GetOptions(&newOptions);
590 if (SUCCEEDED(hr) && SUCCEEDED((hr = pfd->SetOptions(newOptions)))) {
593 parentWindow = parentWindow->
window();
598 hr = pfd->Show(parentWindow ? parentWindow->
winId() : 0);
602 hr = pfd->GetResult(&psi);
609 CoTaskMemFree(pszPath);
635 initialDirectory->
remove(0, 5);
638 if (initialDirectory && !fi.
isDir()) {
649 if (selectedFilter) {
650 idx = filterLst.
indexOf(*selectedFilter);
658 return qt_win_CID_get_open_file_names(args, initialDirectory, filterLst, selectedFilter, idx);
674 ofn->nFilterIndex = idx + 1;
675 if (GetOpenFileName(ofn)) {
677 selFilIdx = ofn->nFilterIndex;
678 int offset = fileOrDir.
length() + 1;
679 if (ofn->lpstrFile[offset] == 0) {
706 *initialDirectory = fi.
path();
728 wchar_t path[MAX_PATH];
745 return qt_win_CID_get_existing_directory(args);
752 parent = parent->
window();
764 wchar_t path[MAX_PATH];
765 wchar_t initPath[MAX_PATH];
780 bi.
lParam = LPARAM(&initDir);
789 pMalloc->Free(pItemIDList);
static QString fromWCharArray(const wchar_t *, int size=-1)
Returns a copy of the string, where the encoding of string depends on the size of wchar...
The QDir class provides access to directory structures and their contents.
static QStringList qt_win_make_filters_list(const QString &filter)
static OPENFILENAME * qt_win_make_OFN(QWidget *parent, const QString &initialSelection, const QString &initialDirectory, const QString &title, const QString &filters, QFileDialog::FileMode mode, QFileDialog::Options options)
QString cap(int nth=0) const
Returns the text captured by the nth subexpression.
#define QT_END_NAMESPACE
This macro expands to.
The QRegExp class provides pattern matching using regular expressions.
#define it(className, varName)
The QDialog class is the base class of dialog windows.
BOOL(WINAPI * PtrSHGetPathFromIDList)(qt_LPITEMIDLIST, LPWSTR)
void setPath(const QString &path)
Sets the path of the directory to path.
QString & replace(int i, int len, QChar after)
#define BFFM_SETSELECTION
int length() const
Returns the number of characters in this string.
static QWidget * activeWindow()
Returns the application top-level window that has the keyboard input focus, or 0 if no application wi...
#define BFFM_SETSTATUSTEXT
QString fileName() const
Returns the name of the file, excluding the path.
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
#define BIF_NEWDIALOGSTYLE
QString qt_win_get_save_file_name(const QFileDialogArgs &args, QString *initialDirectory, QString *selectedFilter)
QString absoluteFilePath() const
Returns an absolute path including the file name.
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
void qt_win_eatMouseMove()
bool exists() const
Returns true if the file exists; otherwise returns false.
#define FOS_ALLOWMULTISELECT
static const WinVersion WindowsVersion
the version of the Windows operating system on which the application is run (Windows only) ...
The QString class provides a Unicode character string.
static QString currentPath()
Returns the absolute path of the application's current directory.
static QString qt_win_filter(const QString &filter, bool hideFiltersDetails)
The QChar class provides a 16-bit Unicode character.
iterator Iterator
Qt-style synonym for QList::iterator.
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
void append(const T &t)
Inserts value at the end of the list.
int indexOf(const QRegExp &rx, int from=0) const
Returns the index position of the first exact match of rx in the list, searching forward from index p...
#define QT_BEGIN_NAMESPACE
This macro expands to.
int indexIn(const QString &str, int offset=0, CaretMode caretMode=CaretAtZero) const
Attempts to find a match in str from position offset (0 by default).
bool isDir() const
Returns true if this object points to a directory or to a symbolic link to a directory; otherwise ret...
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
int size() const
Returns the number of characters in this string.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
static void qt_win_resolve_libs()
static QString qt_win_extract_filter(const QString &rawFilter)
const T & at(int i) const
Returns the item at index position i in the list.
The QStringList class provides a list of strings.
void setFile(const QString &file)
Sets the file that the QFileInfo provides information about to file.
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
#define FOS_PATHMUSTEXIST
static int __stdcall winGetExistDirCallbackProc(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData)
const char * qt_file_dialog_filter_reg_exp
#define TRUE
Synonym for true.
#define FOS_FORCEFILESYSTEM
QString join(const QString &sep) const
Joins all the string list's strings into a single string with each element separated by the given sep...
static const char *const filters[3]
HRESULT(WINAPI * PtrSHGetMalloc)(LPMALLOC *)
FileMode
This enum is used to indicate what the user may select in the file dialog; i.
QFileDialog::Options options
void * resolve(const char *symbol)
#define FOS_FILEMUSTEXIST
struct qt_ITEMIDLIST * qt_LPITEMIDLIST
static PtrSHGetMalloc ptrSHGetMalloc
void clear()
Clears the contents of the string and makes it empty.
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
int length() const
This function is identical to count().
const_iterator ConstIterator
Qt-style synonym for QList::const_iterator.
qt_LPCITEMIDLIST pidlRoot
static void qt_win_clean_up_OFN(OPENFILENAME **ofn)
QString qt_win_get_existing_directory(const QFileDialogArgs &args)
static QString qt_win_selected_filter(const QString &filter, DWORD idx)
#define FOS_OVERWRITEPROMPT
QFuture< void > filter(Sequence &sequence, FilterFunction filterFunction)
QStringList qt_win_get_open_file_names(const QFileDialogArgs &args, QString *initialDirectory, QString *selectedFilter)
static PtrSHBrowseForFolder ptrSHBrowseForFolder
QStringList split(const QString &sep, SplitBehavior behavior=KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const Q_REQUIRED_RESULT
Splits the string into substrings wherever sep occurs, and returns the list of those strings...
qt_LPITEMIDLIST(WINAPI * PtrSHBrowseForFolder)(qt_BROWSEINFO *)
QString qt_win_get_open_file_name(const QFileDialogArgs &args, QString *initialDirectory, QString *selectedFilter)
QString path() const
Returns the file's path.
QString & remove(int i, int len)
Removes n characters from the string, starting at the given position index, and returns a reference t...
static PtrSHGetPathFromIDList ptrSHGetPathFromIDList
The QFileInfo class provides system-independent file information.
static QString toNativeSeparators(const QString &pathName)
Returns pathName with the '/' separators converted to separators that are appropriate for the underly...
#define BIF_RETURNONLYFSDIRS
static void leaveModal(QWidget *)
static QString fileName(const QString &fileUrl)
QString absolutePath() const
Returns a file's path absolute path.
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
static void enterModal(QWidget *)
QStringList qt_make_filter_list(const QString &filter)
The QList class is a template class that provides lists.
const ushort * utf16() const
Returns the QString as a '\0\'-terminated array of unsigned shorts.
static QString homePath()
Returns the absolute path of the user's home directory.