Beispiel #1
0
  void TabEdit::changePOTCAR(QListWidgetItem *item)
  {
    QSettings settings; // Already set up in avogadro/src/main.cpp

    // Get symbol and filename
    QStringList strl = item->text().split(":");
    QString symbol   = strl.at(0).trimmed();
    QString filename = strl.at(1).trimmed();

    QStringList files;
    QString path = settings.value("xtalopt/templates/potcarPath", "").toString();
    QFileDialog dialog (NULL, QString("Select pot file for atom %1").arg(symbol), path);
    dialog.selectFile(filename);
    dialog.setFileMode(QFileDialog::ExistingFile);
    if (dialog.exec()) {
      files = dialog.selectedFiles();
      if (files.size() != 1) { return;} // Only one file per element
      filename = files.first();
      settings.setValue("xtalopt/templates/potcarPath", dialog.directory().absolutePath());
    }
    else { return;} // User cancel file selection.
    // "POTCAR info" is of type
    // QList<QHash<QString, QString> >
    // e.g. a list of hashes containing
    // [atomic symbol : pseudopotential file] pairs
    QVariantList potcarInfo = m_opt->optimizer()->getData("POTCAR info").toList();
    QVariantHash hash = potcarInfo.at(ui_list_optStep->currentRow()).toHash();
    hash.insert(symbol,QVariant(filename));
    potcarInfo.replace(ui_list_optStep->currentRow(), hash);
    m_opt->optimizer()->setData("POTCAR info", potcarInfo);
    qobject_cast<VASPOptimizer*>(m_opt->optimizer())->buildPOTCARs();
    updateEditWidget();
  }
Beispiel #2
0
void MainWindow::on_actionSave_triggered    ()
{
    QFile model{modelFilePath};
    QString modelFileName {model.fileName()};

    QFileDialog savePanel;
    savePanel.selectFile(modelFileName);

    QString newFileName = QFileDialog::getSaveFileName
            (
                this,
                "Save model",
                modelFilePath,
                tr("Model3D (*off)")
            );

    if(newFileName.isEmpty()) //--użytkownik kliknął cancel
        return;
    else
    {
        if(model.rename(newFileName))
            messageHandling(MessageType::log, "Plik z modelem został zapisany w: "+ newFileName);
        else
            messageHandling(MessageType::warning, "Plik z modelem nie został zapisany");
    }
}
Beispiel #3
0
  void TabProgress::injectStructureProgress()
  {
    // It doesn't matter what xtal was selected
    m_context_xtal = NULL;

    // Prompt for filename
    QSettings settings; // Already set up in avogadro/src/main.cpp
    QString filename = settings.value("xtalopt/opt/seedPath",
                                      m_opt->filePath).toString();

    // Launch file dialog
    QFileDialog dialog (m_dialog,
                        QString("Select structure file to use as seed"),
                        filename,
                        "Common formats (*POSCAR *CONTCAR *.got *.cml *cif"
                        " *.out);;All Files (*)");
    dialog.selectFile(filename);
    dialog.setFileMode(QFileDialog::ExistingFile);
    if (dialog.exec())
      filename = dialog.selectedFiles().first();
    else { return;} // User cancel file selection.

    settings.setValue("xtalopt/opt/seedPath", filename);

    // Load in background
    QtConcurrent::run(this, &TabProgress::injectStructureProgress_,
                      filename);
  }
Beispiel #4
0
/**
 * @brief Stores the debug information to a markdown file
 */
void SettingsDialog::on_saveDebugInfoButton_clicked() {
    QFileDialog dialog;
    dialog.setFileMode(QFileDialog::AnyFile);
    dialog.setAcceptMode(QFileDialog::AcceptSave);
    dialog.setDirectory(QDir::homePath());
    dialog.setNameFilter("Markdown files (*.md)");
    dialog.setWindowTitle("Save debug information");
    dialog.selectFile("QOwnNotes Debug Information.md");
    int ret = dialog.exec();

    if (ret == QDialog::Accepted) {
        QStringList fileNames = dialog.selectedFiles();
        if (fileNames.size() == 0) {
            return;
        }

        QFile file(fileNames.at(0));

        if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
            qWarning() << file.errorString();
            return;
        }

        QTextStream out(&file);
        out.setCodec("UTF-8");
        out << ui->debugInfoTextEdit->toPlainText();
        file.flush();
        file.close();
    }
}
Beispiel #5
0
bool FileSystem::saveAsDialog()
{
    QFileDialog dialog;
    dialog.setMimeTypeFilters(Config::supportedSaveMimeTypes());
    dialog.setAcceptMode(QFileDialog::AcceptSave);
    dialog.selectFile(getCurrentAbsoluteFileName());
    dialog.setDirectory(getCurrentAbsoluteFileName());
    dialog.selectMimeTypeFilter("image/jpeg");

    bool success;
    if(dialog.exec())
    {
        QImage img;
        if(SaveConfirmation::imageWasChanged(getCurrentAbsoluteFileName()))
        {
            img = SaveConfirmation::getChagedImage(getCurrentAbsoluteFileName());
            success = img.save(dialog.selectedFiles().first());
            if(success)
                SaveConfirmation::deleteImage(getCurrentAbsoluteFileName());
        }
        else
        {
            img.load(getCurrentAbsoluteFileName());
            success = img.save(dialog.selectedFiles().first());
        }
    }

    return success;
}
Beispiel #6
0
void StoreLabel::mousePressEvent (QMouseEvent *)
{
	QFileDialog *fileDialog;

	fileDialog = new QFileDialog(this, "Store folder path");
	fileDialog->setFileMode(QFileDialog::DirectoryOnly);
	fileDialog->selectFile(text());
	if (fileDialog->exec())
		setText(fileDialog->selectedFiles().at(0));
}
void LogFilePicker::openBrowseWindow()
{
    QFileDialog dialog;
    dialog.selectFile(m_fileEditBox->text());
    dialog.setFileMode(QFileDialog::AnyFile);
    if (!dialog.exec())
        return;

    m_fileEditBox->setText(dialog.selectedFiles()[0]);
}
void Prefs::on_scadExecutableBrowse() {
    QFileDialog *dlg = new QFileDialog(this);
    dlg->setFilter(QDir::Executable);
    dlg->selectFile(getValue("openscad/executable").toString());

    QString filename;
    if (dlg->exec())
        filename = dlg->selectedFiles().first();
    else
        return;

    setValue("openscad/executable", filename);
    scadExecutable->setText(filename);
    emit scadExecutableChanged(filename);
}
Beispiel #9
0
QString MainWindow::_getDatabasePathFromFileDialog() const
{
    QFileDialog dialog;
    dialog.setAcceptMode(QFileDialog::AcceptSave);
    dialog.setFileMode(QFileDialog::AnyFile);
    dialog.setOption(QFileDialog::DontConfirmOverwrite);

    dialog.selectFile("accountbook.db");
    dialog.setWindowTitle("選擇資料庫的位置和名稱");

    QString databasePath;
    if(dialog.exec())
        databasePath = dialog.selectedFiles()[0];
    return databasePath;
}
Beispiel #10
0
void Ruralcooperativequery::on_outButton_clicked()
{
	QAbstractItemModel* model=ui.tableView->model();
	if (model->rowCount()==0||model==NULL)
	{
		QString str = str.fromLocal8Bit("提示");
		QString str2 = str.fromLocal8Bit("无数据");
		QMessageBox box(QMessageBox::Warning,QString::fromLocal8Bit("警告"),str2);
		box.setStandardButtons (QMessageBox::Ok);
		box.setButtonText (QMessageBox::Ok,QString::fromLocal8Bit("确 定"));
		box.exec();
		return;
	}

	QFileDialog dlg;
	dlg.setAcceptMode(QFileDialog::AcceptSave);

	dlg.setDirectory(QDesktopServices::storageLocation(QDesktopServices::DesktopLocation));
	dlg.setNameFilter("*.xls");


	QList<QTreeWidgetItem*> list= ui.treeWidget->selectedItems();
	QTreeWidgetItem*item = list.at(0);
	QString strText = item->text(0);
	dlg.selectFile(strText+QString::fromLocal8Bit("(农合对应关系)"));
	if(dlg.exec()!= QDialog::Accepted)
		return;


	QString filePath=dlg.selectedFiles()[0];
	if(OdbcExcel::saveFromTable(filePath,ui.tableView,"")) {
		QString str = str.fromLocal8Bit("提示");
		QString str2 = str.fromLocal8Bit("保存成功");
		QMessageBox box(QMessageBox::Warning,QString::fromLocal8Bit("警告"),str2);
		box.setStandardButtons (QMessageBox::Ok);
		box.setButtonText (QMessageBox::Ok,QString::fromLocal8Bit("确 定"));
		box.exec();
	}
	else{
		QString str = str.fromLocal8Bit("错误");
		QString msg=str.fromLocal8Bit("保存失败!\n\r")+OdbcExcel::getError();
		QMessageBox box(QMessageBox::Warning,QString::fromLocal8Bit("警告"),msg);
		box.setStandardButtons (QMessageBox::Ok);
		box.setButtonText (QMessageBox::Ok,QString::fromLocal8Bit("确 定"));
		box.exec();
	}
}
Beispiel #11
0
void ReportEditWidget::saveToFile()
{
    QFileDialog dlg;
    dlg.setAcceptMode(QFileDialog::AcceptSave);
    dlg.setFileMode(QFileDialog::AnyFile);
    dlg.setViewMode(QFileDialog::List);

    QStringList filters;
    filters << tr("All reports (*.xml *.ncr *.ods)");
    filters << tr("NcReport (*.ncr)");
    filters << tr("CuteReport (*.xml)");
    filters << tr("OO Calc (*.ods)");
    filters << tr("All files (*.*)");
    dlg.setNameFilters(filters);

    QString ext;
    int type = ui->cmbType->currentKey().toInt();
    switch (type) {
    case Report::NcReportEngine :
        ext = ".ncr";
        dlg.selectFilter(filters.at(1));
        break;
    case Report::CuteReportEngine :
        ext = ".xml";
        dlg.selectFilter(filters.at(2));
        break;
    case Report::OpenOfficeEngine :
        ext = ".ods";
        dlg.selectFilter(filters.at(3));
        break;
    default:
        break;
    }

    dlg.selectFile(ui->edName->text() + ext);
    if (dlg.exec() == QDialog::Accepted) {
        QFile f(dlg.selectedFiles().first());
        if (!f.open(QIODevice::WriteOnly)) {
            QMessageBox::critical(this, tr("Save"), f.errorString());
            return;
        }

        f.write(m_data.toUtf8());
        f.close();
    }
}
Beispiel #12
0
void ExecLabel::mousePressEvent (QMouseEvent *)
{
	QFileDialog *fileDialog;
	QMessageBox messageBox;

	fileDialog = new QFileDialog(this, m_title + " - press Cancel for option to clear field");
	if (m_directory)
		fileDialog->setFileMode(QFileDialog::DirectoryOnly);
	fileDialog->selectFile(text());
	if (fileDialog->exec()) {
		setText(fileDialog->selectedFiles().at(0));
	} else {
		messageBox.setText("Do you want to clear this field?");
		messageBox.setIcon(QMessageBox::Question);
		messageBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
		if (messageBox.exec() == QMessageBox::Yes)
			setText("");
	}
}
Beispiel #13
0
void ReportEditWidget::chooseFile()
{
    QFileDialog dlg;
    dlg.setAcceptMode(QFileDialog::AcceptOpen);
    dlg.setFileMode(QFileDialog::ExistingFile);
    dlg.setViewMode(QFileDialog::List);

    QStringList filters;
    filters << tr("All reports (*.xml *.ncr *.ods)");
    filters << tr("NcReport (*.ncr)");
    filters << tr("CuteReport (*.xml)");
    filters << tr("OO Calc (*.ods)");
    filters << tr("All files (*.*)");
    dlg.setNameFilters(filters);

    dlg.selectFile(ui->edInFile->text());
    if (dlg.exec() == QDialog::Accepted) {
        ui->edInFile->setText(QDir::toNativeSeparators(dlg.selectedFiles().first()));
    }
}
Beispiel #14
0
void SyntroReview::saveButtonClicked(QAbstractButton *button)
{
	QFileDialog *fileDialog;

	if (m_CFSState != SYNTROREVIEW_CFS_STATE_OPEN)
		return;												// no open file anyway

	if (button == m_saveFrame){
		fileDialog = new QFileDialog(this, "JPEG (.jpg) file name");
		fileDialog->setAcceptMode(QFileDialog::AcceptSave);
		fileDialog->setFileMode(QFileDialog::AnyFile);
		fileDialog->selectFile(m_saveFilePath);
		fileDialog->setNameFilter("*.jpg");
		fileDialog->setDefaultSuffix("jpg");
		if (fileDialog->exec()) {
			m_saveFilePath = fileDialog->selectedFiles().at(0);
			saveCurrentFrame();
		}
	}
}
Beispiel #15
0
 void AbstractEditTab::saveScheme()
 {
   SETTINGS("");
   QString filename = settings->value(m_opt->getIDString().toLower() +
                                      "/edit/schemePath/", "").toString();
   QFileDialog dialog (NULL, tr("Save Optimization Scheme as..."),
                       filename, "*.scheme;;*.state;;*.*");
   dialog.setAcceptMode(QFileDialog::AcceptSave);
   dialog.selectFile(m_opt->optimizer()->getIDString() + ".scheme");
   dialog.setFileMode(QFileDialog::AnyFile);
   if (dialog.exec())
     filename = dialog.selectedFiles().first();
   else { // User cancel file selection.
     return;
   }
   settings->setValue(m_opt->getIDString().toLower() +
                      "/edit/schemePath/", filename);
   DESTROY_SETTINGS("");
   writeSettings(filename);
 }
Beispiel #16
0
void ImageViewer::saveFileToDisc()
{
    QFileDialog dialog;
    dialog.selectFile(m_ImageUrl.fileName().remove(m_ImageUrl.path()));
    dialog.setFileMode(QFileDialog::AnyFile);
    QUrl newURL = dialog.getSaveFileUrl(KStars::Instance(), i18n("Save Image")); // save-dialog with default filename
    if (!newURL.isEmpty())
    {
        QFile f (newURL.adjusted(QUrl::RemoveFilename|QUrl::StripTrailingSlash).path() + '/' +  newURL.fileName());
        if (f.exists())
        {
            int r=KMessageBox::warningContinueCancel(static_cast<QWidget *>(parent()),
                    i18n( "A file named \"%1\" already exists. "
                          "Overwrite it?" , newURL.fileName()),
                    i18n( "Overwrite File?" ),
                    KStandardGuiItem::overwrite() );
            if(r==KMessageBox::Cancel) return;

            f.remove();
        }
        saveFile (newURL);
    }
}
Beispiel #17
0
void Transcribe::pickFiles() {
  QFileDialog dlg;

  // Unfortunately, Android doesn't really work with the concept of files,
  // they are abstracted away. Since it would require a major effort to make
  // this work in the Android way, we'll just try to make the best of it.
#ifdef Q_OS_ANDROID
    // First see if we have storage permissions. We fail here if we don't have
    // them and let the callback to the request popup call this method again.
    if (!StoragePerm::instance()->tryPermission(std::bind(&Transcribe::pickFiles, this))) return;

    // Make the QFileDialog a bit better by maximizing it.
    dlg.setWindowState(Qt::WindowMaximized);
    dlg.setViewMode(QFileDialog::List);

    // Add the root and the internal memory location to the paths to choose
    // from. There are no real standard paths for this, let's hope Qt knows
    // what to do.
    QUrl home_url = QUrl::fromLocalFile(QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation).first());
    dlg.setDirectoryUrl(home_url);
    QList<QUrl> urls;
    urls << QUrl::fromLocalFile("/");
    urls << home_url;
    dlg.setSidebarUrls(urls);
#endif

  // Let the user pick an audio file
  dlg.setWindowTitle(tr("Open an audio file"));
  dlg.setNameFilter(tr("Audio files (*.wav *.mp3 *.aac *.amr *.aiff *.flac *.ogg *.wma, *.opus)"));
  dlg.setFileMode(QFileDialog::ExistingFile);
  dlg.setAcceptMode(QFileDialog::AcceptOpen);
  if (dlg.exec() == QDialog::Rejected || dlg.selectedFiles().count() != 1) {
    return;
  }

  m_restore_pos = 0;
  openAudioFile(dlg.selectedFiles().at(0));

#ifdef Q_OS_ANDROID
  QString audio_path = dlg.selectedFiles().at(0);
  QString text_path;

  // Check if the audio file is in our history
  if (!m_history.textFileForAudio(audio_path, text_path)) {
    // If not, create a new file in the app private folder based on the audio
    // file name. If a text file with the name already exists, append a number
    // to it.
    QString base_name = QFileInfo(audio_path).baseName();
    QDir home = QDir(QStandardPaths::writableLocation((QStandardPaths::AppDataLocation)));
    text_path = home.filePath(base_name + ".txt");
    short counter = 1;
    while (QFile::exists(text_path)) {
      text_path = home.filePath(QString("%1_%2.txt").arg(base_name).arg(counter, 2, 10, QChar('0')));
      counter++;
    }
  }

  openTextFile(text_path);
#else
  // Recycle the file dialog to let the user pick a text file for the
  // transcript. As a file suggestion, we base a txt file on the current audio
  // file.
  dlg.setWindowTitle(tr("Pick a text file for the transcript"));
  dlg.setNameFilter(tr("Text files (*.txt)"));
  dlg.setFileMode(QFileDialog::AnyFile);
  dlg.setAcceptMode(QFileDialog::AcceptSave);
  dlg.setOption(QFileDialog::DontConfirmOverwrite, true);
  dlg.setLabelText(QFileDialog::Accept, tr("Open/Create"));
  QFileInfo info(dlg.selectedFiles().at(0));
  dlg.setDirectory(info.absolutePath());
  dlg.selectFile(info.baseName() + ".txt");
  if (dlg.exec() == QDialog::Rejected || dlg.selectedFiles().count() != 1) {
    return;
  }

  openTextFile(dlg.selectedFiles().at(0));
#endif

  // saveHistory() is called when the audio file has finished loading, but we
  // need do it here as well because openTextFile() might return after the audio
  // file has finished loading. The joys of concurrency ...
  saveHistory();
}
Beispiel #18
0
void NWebView::downloadRequested(QNetworkRequest req) {
    QString urlString = req.url().toString();
    if (urlString == "")  {
        downloadImageAction()->trigger();
        return;
    }
    if (urlString.startsWith("nnres:")) {
        int pos = urlString.indexOf(global.attachmentNameDelimeter);
        QString extension = "";
        if (pos > 0) {
            extension = urlString.mid(pos+global.attachmentNameDelimeter.length());
            urlString = urlString.mid(0,pos);
        }
        urlString = urlString.mid(6);

        qint32 lid = urlString.toInt();
        ResourceTable resTable(global.db);
        Resource r;
        resTable.get(r, lid, false);
        QString filename;
        ResourceAttributes attributes;
        if (r.attributes.isSet())
            attributes = r.attributes;
        if (attributes.fileName.isSet())
            filename = attributes.fileName;
        else
            filename = urlString + QString(".") + extension;

        QFileDialog fd;
        fd.setFileMode(QFileDialog::AnyFile);
        fd.setWindowTitle(tr("Save File"));
        fd.setAcceptMode(QFileDialog::AcceptSave);
        fd.selectFile(filename);
        fd.setConfirmOverwrite(true);
        if (fd.exec()) {
            if (fd.selectedFiles().size() == 0)
                return;
            filename = fd.selectedFiles()[0];
            QFile newFile(filename);
            newFile.open(QIODevice::WriteOnly);
            Data d;
            if (r.data.isSet())
                d = r.data;
            QByteArray body;
            if (d.body.isSet())
                body = d.body;
            int size = 0;
            if (d.size.isSet())
                size = d.size;
            newFile.write(body, size);
            newFile.close();
            return;
        }
    }
    if (urlString.startsWith("file:////")) {
        if (!req.url().isValid())
            return;
        urlString = urlString.mid(8);
        QFileDialog fd;
        fd.setFileMode(QFileDialog::AnyFile);
        fd.setWindowTitle(tr("Save File"));
        fd.setAcceptMode(QFileDialog::AcceptSave);
        QString oldname = urlString;
        fd.selectFile(urlString.replace(global.fileManager.getDbaDirPath(), ""));
        fd.setConfirmOverwrite(true);
        if (fd.exec()) {
            if (fd.selectedFiles().size() == 0)
                return;
            QString newname = fd.selectedFiles()[0];
            QFile::remove(urlString);
            QFile::copy(oldname, newname);
            return;
        }

    }
}
Beispiel #19
0
  bool TabEdit::generateVASP_POTCAR_info()
  {
    XtalOpt *xtalopt = qobject_cast<XtalOpt*>(m_opt);
    QSettings settings; // Already set up in avogadro/src/main.cpp
    QString path = settings.value("xtalopt/templates/potcarPath", "").toString();
    QVariantList potcarInfo;

    // Generate list of symbols
    QList<QString> symbols;
    QList<uint> atomicNums = xtalopt->comp.keys();
    qSort(atomicNums);

    for (int i = 0; i < atomicNums.size(); i++)
      symbols.append(OpenBabel::etab.GetSymbol(atomicNums.at(i)));
    qSort(symbols);
    QStringList files;
    QString filename;
    QVariantHash hash;
    for (int i = 0; i < symbols.size(); i++) {
      QString path = settings.value("xtalopt/templates/potcarPath", "").toString();
      QFileDialog dialog (NULL, QString("Select pot file for atom %1").arg(symbols.at(i)), path);
      dialog.selectFile(path + "/" + symbols.at(i));
      dialog.setFileMode(QFileDialog::ExistingFile);
      if (dialog.exec()) {
        files = dialog.selectedFiles();
        if (files.size() != 1) { // Ask again!
          i--;
          continue;
        }
        filename = files.first();
        settings.setValue("xtalopt/templates/potcarPath", dialog.directory().absolutePath());
      }
      else {
        // User cancel file selection. Set template selection combo to
        // something else so the list will remain empty and be
        // detected when the search starts. Ref ticket 79.
        int curInd = ui_combo_templates->currentIndex();
        int maxInd = ui_combo_templates->count() - 1;
        int newInd = (curInd == maxInd) ? 0 : maxInd;
        ui_combo_templates->setCurrentIndex(newInd);
        return false;
      }
      hash.insert(symbols.at(i), QVariant(filename));
    }

    for (int i = 0; i < m_opt->optimizer()->getNumberOfOptSteps(); i++) {
      potcarInfo.append(QVariant(hash));
    }

    // Set composition in optimizer
    QVariantList toOpt;
    for (int i = 0; i < atomicNums.size(); i++) {
      toOpt.append(atomicNums.at(i));
    }
    m_opt->optimizer()->setData("Composition", toOpt);

    // Set POTCAR info
    m_opt->optimizer()->setData("POTCAR info", QVariant(potcarInfo));

    updateEditWidget();
    return true;
  }
Beispiel #20
0
/* static */
QStringList QIFileDialog::getOpenFileNames (const QString &aStartWith,
                                            const QString &aFilters,
                                            QWidget       *aParent,
                                            const QString &aCaption,
                                            QString       *aSelectedFilter /* = 0 */,
                                            bool           aResolveSymlinks /* = true */,
                                            bool           aSingleFile /* = false */)
{
/* It seems, running QFileDialog in separate thread is NOT needed under windows any more: */
#if defined (VBOX_WS_WIN) && (QT_VERSION < 0x040403)

    /**
     *  QEvent class reimplementation to carry Win32 API native dialog's
     *  result folder information
     */
    class GetOpenFileNameEvent : public OpenNativeDialogEvent
    {
    public:

        enum { TypeId = QEvent::User + 3 };

        GetOpenFileNameEvent (const QString &aResult)
            : OpenNativeDialogEvent (aResult, (QEvent::Type) TypeId) {}
    };

    /**
     *  QThread class reimplementation to open Win32 API native file dialog
     */
    class Thread : public QThread
    {
    public:

        Thread (QWidget *aParent, QObject *aTarget,
                const QString &aStartWith, const QString &aFilters,
                const QString &aCaption) :
                mParent (aParent), mTarget (aTarget),
                mStartWith (aStartWith), mFilters (aFilters),
                mCaption (aCaption) {}

        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));
        }

    private:

        QWidget *mParent;
        QObject *mTarget;
        QString mStartWith;
        QString mFilters;
        QString mCaption;
    };

    if (aSelectedFilter)
        *aSelectedFilter = QString::null;

    /* Local event loop to run while waiting for the result from another
     * thread */
    QEventLoop loop;

    QString startWith = QDir::toNativeSeparators (aStartWith);
    LoopObject loopObject ((QEvent::Type) GetOpenFileNameEvent::TypeId, loop);

    if (aParent)
        aParent->setWindowModality (Qt::WindowModal);

    Thread openDirThread (aParent, &loopObject, startWith, aFilters, aCaption);
    openDirThread.start();
    loop.exec();
    openDirThread.wait();

    if (aParent)
        aParent->setWindowModality (Qt::NonModal);

    return QStringList() << loopObject.result();

#elif defined (VBOX_WS_X11) && (QT_VERSION < 0x040400)

    /* Here is workaround for Qt4.3 bug with QFileDialog which crushes when
     * gets initial path as hidden directory if no hidden files are shown.
     * See http://trolltech.com/developer/task-tracker/index_html?method=entry&id=193483
     * for details */
    QFileDialog dlg (aParent);
    dlg.setWindowTitle (aCaption);
    dlg.setDirectory (aStartWith);
    dlg.setFilter (aFilters);
    if (aSingleFile)
        dlg.setFileMode (QFileDialog::ExistingFile);
    else
        dlg.setFileMode (QFileDialog::ExistingFiles);
    if (aSelectedFilter)
        dlg.selectFilter (*aSelectedFilter);
    dlg.setResolveSymlinks (aResolveSymlinks);
    QAction *hidden = dlg.findChild <QAction*> ("qt_show_hidden_action");
    if (hidden)
    {
        hidden->trigger();
        hidden->setVisible (false);
    }
    return dlg.exec() == QDialog::Accepted ? dlg.selectedFiles() : QStringList() << QString::null;

#elif defined (VBOX_WS_MAC) && (QT_VERSION >= 0x040600) && (QT_VERSION < 0x050000)

    /* After 4.5 exec ignores the Qt::Sheet flag.
     * See "New Ways of Using Dialogs" in http://doc.trolltech.com/qq/QtQuarterly30.pdf why.
     * We want the old behavior for file-save dialog. Unfortunately there is a bug in Qt 4.5.x
     * which result in showing the native & the Qt dialog at the same time. */
    QFileDialog dlg(aParent);
    dlg.setWindowTitle(aCaption);

    /* Some predictive algorithm which seems missed in native code. */
    QDir dir(aStartWith);
    while (!dir.isRoot() && !dir.exists())
        dir = QDir(QFileInfo(dir.absolutePath()).absolutePath());
    const QString strDirectory = dir.absolutePath();
    if (!strDirectory.isNull())
        dlg.setDirectory(strDirectory);
    if (strDirectory != aStartWith)
        dlg.selectFile(QFileInfo(aStartWith).absoluteFilePath());

    dlg.setNameFilter(aFilters);
    if (aSingleFile)
        dlg.setFileMode(QFileDialog::ExistingFile);
    else
        dlg.setFileMode(QFileDialog::ExistingFiles);
    if (aSelectedFilter)
        dlg.selectFilter(*aSelectedFilter);
    dlg.setResolveSymlinks(aResolveSymlinks);

    QEventLoop eventLoop;
    QObject::connect(&dlg, SIGNAL(finished(int)),
                     &eventLoop, SLOT(quit()));
    dlg.open();
    eventLoop.exec();

    return dlg.result() == QDialog::Accepted ? dlg.selectedFiles() : QStringList() << QString();

#else

    QFileDialog::Options o;
    if (!aResolveSymlinks)
        o |= QFileDialog::DontResolveSymlinks;
# if defined (VBOX_WS_X11)
    /** @todo see http://bugs.kde.org/show_bug.cgi?id=210904, make it conditional
     *        when this bug is fixed (xtracker 5167)
     *        Apparently not necessary anymore (xtracker 5748)! */
//    if (vboxGlobal().isKWinManaged())
//      o |= QFileDialog::DontUseNativeDialog;
# endif

    if (aSingleFile)
        return QStringList() << QFileDialog::getOpenFileName (aParent, aCaption, aStartWith,
                                                              aFilters, aSelectedFilter, o);
    else
        return QFileDialog::getOpenFileNames (aParent, aCaption, aStartWith,
                                              aFilters, aSelectedFilter, o);
#endif
}