QString QFileDialog::winGetOpenFileName(const QString &initialSelection, const QString &filter, QString* initialDirectory, QWidget *parent, const char* /*name*/, const QString& caption, QString* selectedFilter) { QString result; QString isel = initialSelection; if (initialDirectory && initialDirectory->left(5) == "file:") initialDirectory->remove(0, 5); QFileInfo fi(*initialDirectory); if (initialDirectory && !fi.isDir()) { *initialDirectory = fi.dirPath(true); if (isel.isEmpty()) isel = fi.fileName(); } if (!fi.exists()) *initialDirectory = QDir::homeDirPath(); QString title = caption; if (title.isNull()) title = tr("Open"); DWORD selFilIdx; int idx = 0; if (selectedFilter && !selectedFilter->isEmpty()) { QStringList filterLst = makeFiltersList(filter); idx = filterLst.findIndex(*selectedFilter); } if (parent) { QEvent e(QEvent::WindowBlocked); QApplication::sendEvent(parent, &e); qt_enter_modal(parent); } QT_WA({ // Use Unicode strings and API OPENFILENAME* ofn = makeOFN(parent, isel, *initialDirectory, title, winFilter(filter), ExistingFile); if (idx) ofn->nFilterIndex = idx + 1; if (GetOpenFileName(ofn)) { result = QString::fromUcs2((ushort*)ofn->lpstrFile); selFilIdx = ofn->nFilterIndex; } cleanUpOFN(&ofn); } , {
QStringList Q3FileDialog::winGetOpenFileNames(const QString &filter, QString* initialDirectory, QWidget *parent, const char* /*name*/, const QString& caption, QString* selectedFilter) { QStringList result; QFileInfo fi; QDir dir; QString isel; if (initialDirectory && initialDirectory->left(5) == QLatin1String("file:")) initialDirectory->remove(0, 5); fi = QFileInfo(*initialDirectory); if (initialDirectory && !fi.isDir()) { *initialDirectory = fi.dirPath(true); isel = fi.fileName(); } if (!fi.exists()) *initialDirectory = QDir::homeDirPath(); QString title = caption; if (title.isNull()) title = tr("Open "); DWORD selFilIdx = 0; int idx = 0; if (selectedFilter && !selectedFilter->isEmpty()) { QStringList filterLst = makeFiltersList(filter); idx = filterLst.findIndex(*selectedFilter); } if (parent) { QEvent e(QEvent::WindowBlocked); QApplication::sendEvent(parent, &e); QApplicationPrivate::enterModal(parent); } OPENFILENAME* ofn = makeOFN(parent, isel, *initialDirectory, title, winFilter(filter), ExistingFiles); if (idx) ofn->nFilterIndex = idx + 1; if (GetOpenFileName(ofn)) { QString fileOrDir = QString::fromWCharArray(ofn->lpstrFile); selFilIdx = ofn->nFilterIndex; int offset = fileOrDir.length() + 1; if (ofn->lpstrFile[offset] == 0) { // Only one file selected; has full path fi.setFile(fileOrDir); QString res = fi.absFilePath(); if (!res.isEmpty()) result.append(res); } else { // Several files selected; first string is path dir.setPath(fileOrDir); QString f; while (!(f = QString::fromWCharArray(ofn->lpstrFile + offset)).isEmpty()) { fi.setFile(dir, f); QString res = fi.absFilePath(); if (!res.isEmpty()) result.append(res); offset += f.length() + 1; } } } cleanUpOFN(&ofn); if (parent) { QApplicationPrivate::leaveModal(parent); QEvent e(QEvent::WindowUnblocked); QApplication::sendEvent(parent, &e); } if (!result.isEmpty()) { *initialDirectory = fi.dirPath(); // only save the path if there is a result if (selectedFilter) *selectedFilter = selFilter(filter, selFilIdx); } return result; }
QString Q3FileDialog::winGetSaveFileName(const QString &initialSelection, const QString &filter, QString* initialDirectory, QWidget *parent, const char* /*name*/, const QString& caption, QString* selectedFilter) { QString result; QString isel = initialSelection; if (initialDirectory && initialDirectory->left(5) == QLatin1String("file:")) initialDirectory->remove(0, 5); QFileInfo fi(*initialDirectory); if (initialDirectory && !fi.isDir()) { *initialDirectory = fi.dirPath(true); if (isel.isEmpty()) isel = fi.fileName(); } if (!fi.exists()) *initialDirectory = QDir::homeDirPath(); QString title = caption; if (title.isNull()) title = tr("Save As"); DWORD selFilIdx = 0; int idx = 0; if (selectedFilter && !selectedFilter->isEmpty()) { QStringList filterLst = makeFiltersList(filter); idx = filterLst.findIndex(*selectedFilter); } if (parent) { QEvent e(QEvent::WindowBlocked); QApplication::sendEvent(parent, &e); QApplicationPrivate::enterModal(parent); } OPENFILENAME* ofn = makeOFN(parent, isel, *initialDirectory, title, winFilter(filter), AnyFile); if (idx) ofn->nFilterIndex = idx + 1; if (GetSaveFileName(ofn)) { result = QString::fromWCharArray(ofn->lpstrFile); selFilIdx = ofn->nFilterIndex; } cleanUpOFN(&ofn); if (parent) { QApplicationPrivate::leaveModal(parent); QEvent e(QEvent::WindowUnblocked); QApplication::sendEvent(parent, &e); } if (result.isEmpty()) { return result; } else { QFileInfo fi(result); *initialDirectory = fi.dirPath(); if (selectedFilter) *selectedFilter = selFilter(filter, selFilIdx); return fi.absFilePath(); } }
virtual void run() { QString result; QString workDir; QString initSel; QFileInfo fi (mStartWith); if (fi.isDir()) workDir = mStartWith; else { workDir = fi.absolutePath(); initSel = fi.fileName(); } workDir = QDir::toNativeSeparators (workDir); if (!workDir.endsWith ("\\")) workDir += "\\"; QString title = mCaption.isNull() ? tr ("Select a file") : mCaption; QWidget *topParent = windowManager().realParentWindow(mParent ? mParent : windowManager().mainWindowShown()); QString winFilters = winFilter (mFilters); AssertCompile (sizeof (TCHAR) == sizeof (QChar)); TCHAR buf [1024]; if (initSel.length() > 0 && initSel.length() < sizeof (buf)) memcpy (buf, initSel.isNull() ? 0 : initSel.utf16(), (initSel.length() + 1) * sizeof (TCHAR)); else buf [0] = 0; OPENFILENAME ofn; memset (&ofn, 0, sizeof (OPENFILENAME)); ofn.lStructSize = sizeof (OPENFILENAME); ofn.hwndOwner = topParent ? topParent->winId() : 0; ofn.lpstrFilter = (TCHAR *)(winFilters.isNull() ? 0 : winFilters.utf16()); ofn.lpstrFile = buf; ofn.nMaxFile = sizeof (buf) - 1; ofn.lpstrInitialDir = (TCHAR *)(workDir.isNull() ? 0 : workDir.utf16()); ofn.lpstrTitle = (TCHAR *)(title.isNull() ? 0 : title.utf16()); ofn.Flags = (OFN_NOCHANGEDIR | OFN_HIDEREADONLY | OFN_EXPLORER | OFN_ENABLEHOOK | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST); ofn.lpfnHook = OFNHookProc; if (GetOpenFileName (&ofn)) { result = QString::fromUtf16 ((ushort *) ofn.lpstrFile); } // qt_win_eatMouseMove(); MSG msg = {0, 0, 0, 0, 0, 0, 0}; while (PeekMessage (&msg, 0, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_REMOVE)); if (msg.message == WM_MOUSEMOVE) PostMessage (msg.hwnd, msg.message, 0, msg.lParam); result = result.isEmpty() ? result : QFileInfo (result).absoluteFilePath(); QApplication::postEvent (mTarget, new GetOpenFileNameEvent (result)); }
// Use Unicode strings and API OPENFILENAME* ofn = makeOFN(parent, isel, *initialDirectory, title, winFilter(filter), ExistingFile); if (idx) ofn->nFilterIndex = idx + 1; if (GetOpenFileName(ofn)) { result = QString::fromUcs2((ushort*)ofn->lpstrFile); selFilIdx = ofn->nFilterIndex; } cleanUpOFN(&ofn); } , { // Use ANSI strings and API OPENFILENAMEA* ofn = makeOFNA(parent, isel, *initialDirectory, title, winFilter(filter), ExistingFile); if (idx) ofn->nFilterIndex = idx + 1; if (GetOpenFileNameA(ofn)) { result = QString::fromLocal8Bit(ofn->lpstrFile); selFilIdx = ofn->nFilterIndex; } cleanUpOFNA(&ofn); }); if (parent) { qt_leave_modal(parent); QEvent e(QEvent::WindowUnblocked); QApplication::sendEvent(parent, &e); } if (result.isEmpty()) {