2012-10-25 10:45:13 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2016-01-15 12:36:27 +00:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2012-10-25 10:45:13 +00:00
|
|
|
**
|
2013-05-24 13:49:24 +00:00
|
|
|
** This file is part of the test suite of the Qt Toolkit.
|
2012-10-25 10:45:13 +00:00
|
|
|
**
|
2016-01-15 12:36:27 +00:00
|
|
|
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
|
2012-10-25 10:45:13 +00:00
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2015-01-28 08:44:43 +00:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
2016-01-15 12:36:27 +00:00
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2012-10-25 10:45:13 +00:00
|
|
|
**
|
2016-01-15 12:36:27 +00:00
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2012-10-25 10:45:13 +00:00
|
|
|
**
|
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "filedialogpanel.h"
|
2013-11-01 11:46:42 +00:00
|
|
|
#include "utils.h"
|
2012-10-25 10:45:13 +00:00
|
|
|
|
|
|
|
#include <QGridLayout>
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
#include <QHBoxLayout>
|
2013-01-17 14:49:42 +00:00
|
|
|
#include <QGridLayout>
|
2012-10-25 10:45:13 +00:00
|
|
|
#include <QFormLayout>
|
|
|
|
#include <QSpacerItem>
|
|
|
|
#include <QGroupBox>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QCheckBox>
|
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QPlainTextEdit>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QApplication>
|
2015-03-05 13:27:44 +00:00
|
|
|
#include <QUrl>
|
2012-10-25 10:45:13 +00:00
|
|
|
|
|
|
|
#include <QTimer>
|
|
|
|
#include <QDebug>
|
|
|
|
|
2013-11-01 11:46:42 +00:00
|
|
|
const FlagData acceptModeComboData[] =
|
2012-10-25 10:45:13 +00:00
|
|
|
{
|
|
|
|
{"AcceptOpen", QFileDialog::AcceptOpen },
|
|
|
|
{"AcceptSave", QFileDialog::AcceptSave }
|
|
|
|
};
|
|
|
|
|
2013-11-01 11:46:42 +00:00
|
|
|
const FlagData viewModeComboData[] =
|
2012-10-25 10:45:13 +00:00
|
|
|
{
|
|
|
|
{"Detail", QFileDialog::Detail},
|
|
|
|
{"List", QFileDialog::List}
|
|
|
|
};
|
|
|
|
|
2013-11-01 11:46:42 +00:00
|
|
|
const FlagData fileModeComboData[] =
|
2012-10-25 10:45:13 +00:00
|
|
|
{
|
|
|
|
{"AnyFile", QFileDialog::AnyFile},
|
|
|
|
{"ExistingFile", QFileDialog::ExistingFile},
|
|
|
|
{"ExistingFiles", QFileDialog::ExistingFiles},
|
|
|
|
{"Directory", QFileDialog::Directory},
|
|
|
|
{"DirectoryOnly", QFileDialog::DirectoryOnly}
|
|
|
|
};
|
|
|
|
|
2013-01-17 14:49:42 +00:00
|
|
|
static inline QPushButton *addButton(const QString &description, QGridLayout *layout,
|
|
|
|
int &row, int column, QObject *receiver, const char *slotFunc)
|
2012-10-25 10:45:13 +00:00
|
|
|
{
|
2012-12-21 14:51:50 +00:00
|
|
|
QPushButton *button = new QPushButton(description);
|
2012-10-25 10:45:13 +00:00
|
|
|
QObject::connect(button, SIGNAL(clicked()), receiver, slotFunc);
|
2013-01-17 14:49:42 +00:00
|
|
|
layout->addWidget(button, row++, column);
|
2013-01-16 14:12:29 +00:00
|
|
|
return button;
|
2012-10-25 10:45:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// A line edit for editing the label fields of the dialog, keeping track of whether it has
|
|
|
|
// been modified by the user to avoid applying Qt's default texts to native dialogs.
|
|
|
|
|
|
|
|
class LabelLineEdit : public QLineEdit
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit LabelLineEdit(QFileDialog::DialogLabel label, QWidget *parent = 0) : QLineEdit(parent), m_label(label), m_dirty(false)
|
|
|
|
{
|
|
|
|
connect(this, SIGNAL(textEdited(QString)), this, SLOT(setDirty()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void restoreDefault(const QFileDialog *d)
|
|
|
|
{
|
|
|
|
setText(d->labelText(m_label));
|
|
|
|
m_dirty = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void apply(QFileDialog *d) const
|
|
|
|
{
|
|
|
|
if (m_dirty)
|
|
|
|
d->setLabelText(m_label, text());
|
|
|
|
}
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void setDirty() { m_dirty = true; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
const QFileDialog::DialogLabel m_label;
|
|
|
|
bool m_dirty;
|
|
|
|
};
|
|
|
|
|
|
|
|
FileDialogPanel::FileDialogPanel(QWidget *parent)
|
|
|
|
: QWidget(parent)
|
2013-12-10 10:19:16 +00:00
|
|
|
, m_showDirsOnly(new QCheckBox(tr("Show dirs only")))
|
2012-10-25 10:45:13 +00:00
|
|
|
, m_readOnly(new QCheckBox(tr("Read only")))
|
|
|
|
, m_confirmOverWrite(new QCheckBox(tr("Confirm overwrite")))
|
|
|
|
, m_nameFilterDetailsVisible(new QCheckBox(tr("Name filter details visible")))
|
|
|
|
, m_resolveSymLinks(new QCheckBox(tr("Resolve symlinks")))
|
|
|
|
, m_native(new QCheckBox(tr("Use native dialog")))
|
2013-04-29 11:58:23 +00:00
|
|
|
, m_customDirIcons(new QCheckBox(tr("Don't use custom directory icons")))
|
2013-11-01 11:46:42 +00:00
|
|
|
, m_acceptMode(createCombo(this, acceptModeComboData, sizeof(acceptModeComboData)/sizeof(FlagData)))
|
|
|
|
, m_fileMode(createCombo(this, fileModeComboData, sizeof(fileModeComboData)/sizeof(FlagData)))
|
|
|
|
, m_viewMode(createCombo(this, viewModeComboData, sizeof(viewModeComboData)/sizeof(FlagData)))
|
2013-03-14 13:41:47 +00:00
|
|
|
, m_allowedSchemes(new QLineEdit(this))
|
2012-10-25 10:45:13 +00:00
|
|
|
, m_defaultSuffix(new QLineEdit(this))
|
|
|
|
, m_directory(new QLineEdit(this))
|
|
|
|
, m_selectedFileName(new QLineEdit(this))
|
2013-08-27 12:10:45 +00:00
|
|
|
, m_useMimeTypeFilters(new QCheckBox(this))
|
2012-10-25 10:45:13 +00:00
|
|
|
, m_nameFilters(new QPlainTextEdit)
|
|
|
|
, m_selectedNameFilter(new QLineEdit(this))
|
2013-01-16 14:12:29 +00:00
|
|
|
, m_deleteNonModalDialogButton(0)
|
2013-01-17 14:49:42 +00:00
|
|
|
, m_deleteModalDialogButton(0)
|
2012-10-25 10:45:13 +00:00
|
|
|
{
|
|
|
|
// Options
|
|
|
|
QGroupBox *optionsGroupBox = new QGroupBox(tr("Options"));
|
|
|
|
QFormLayout *optionsLayout = new QFormLayout(optionsGroupBox);
|
|
|
|
optionsLayout->addRow(tr("AcceptMode:"), m_acceptMode);
|
|
|
|
optionsLayout->addRow(tr("FileMode:"), m_fileMode);
|
|
|
|
optionsLayout->addRow(tr("ViewMode:"), m_viewMode);
|
2013-03-14 13:41:47 +00:00
|
|
|
optionsLayout->addRow(tr("Allowed Schemes:"), m_allowedSchemes);
|
2013-12-10 10:19:16 +00:00
|
|
|
optionsLayout->addRow(m_showDirsOnly);
|
2012-10-25 10:45:13 +00:00
|
|
|
optionsLayout->addRow(m_native);
|
|
|
|
optionsLayout->addRow(m_confirmOverWrite);
|
|
|
|
optionsLayout->addRow(m_nameFilterDetailsVisible);
|
|
|
|
optionsLayout->addRow(m_resolveSymLinks);
|
|
|
|
optionsLayout->addRow(m_readOnly);
|
2013-04-29 11:58:23 +00:00
|
|
|
optionsLayout->addRow(m_customDirIcons);
|
2012-10-25 10:45:13 +00:00
|
|
|
|
|
|
|
// Files
|
|
|
|
QGroupBox *filesGroupBox = new QGroupBox(tr("Files / Filters"));
|
2013-08-27 12:10:45 +00:00
|
|
|
filesLayout = new QFormLayout(filesGroupBox);
|
2012-10-25 10:45:13 +00:00
|
|
|
filesLayout->addRow(tr("Default Suffix:"), m_defaultSuffix);
|
|
|
|
filesLayout->addRow(tr("Directory:"), m_directory);
|
|
|
|
filesLayout->addRow(tr("Selected file:"), m_selectedFileName);
|
2013-08-27 12:10:45 +00:00
|
|
|
filesLayout->addRow(tr("Use mime type filters:"), m_useMimeTypeFilters);
|
2012-10-25 10:45:13 +00:00
|
|
|
m_nameFilters->setMaximumHeight(80);
|
|
|
|
filesLayout->addRow(tr("Name filters:"), m_nameFilters);
|
|
|
|
filesLayout->addRow(tr("Selected name filter:"), m_selectedNameFilter);
|
|
|
|
|
|
|
|
// Optional labels
|
|
|
|
QGroupBox *labelsGroupBox = new QGroupBox(tr("Labels"));
|
|
|
|
QFormLayout *labelsLayout = new QFormLayout(labelsGroupBox);
|
|
|
|
m_labelLineEdits.push_back(new LabelLineEdit(QFileDialog::LookIn, this));
|
|
|
|
labelsLayout->addRow(tr("Look in label:"), m_labelLineEdits.back());
|
|
|
|
m_labelLineEdits.push_back(new LabelLineEdit(QFileDialog::FileName, this));
|
|
|
|
labelsLayout->addRow(tr("File name label:"), m_labelLineEdits.back());
|
|
|
|
m_labelLineEdits.push_back(new LabelLineEdit(QFileDialog::FileType, this));
|
|
|
|
labelsLayout->addRow(tr("File type label:"), m_labelLineEdits.back());
|
|
|
|
m_labelLineEdits.push_back(new LabelLineEdit(QFileDialog::Accept, this));
|
|
|
|
labelsLayout->addRow(tr("Accept label:"), m_labelLineEdits.back());
|
|
|
|
m_labelLineEdits.push_back(new LabelLineEdit(QFileDialog::Reject, this));
|
|
|
|
labelsLayout->addRow(tr("Reject label:"), m_labelLineEdits.back());
|
|
|
|
|
|
|
|
// Buttons
|
|
|
|
QGroupBox *buttonsGroupBox = new QGroupBox(tr("Show"));
|
2013-01-17 14:49:42 +00:00
|
|
|
QGridLayout *buttonLayout = new QGridLayout(buttonsGroupBox);
|
|
|
|
int row = 0;
|
|
|
|
int column = 0;
|
|
|
|
addButton(tr("Exec modal"), buttonLayout, row, column, this, SLOT(execModal()));
|
|
|
|
addButton(tr("Show modal"), buttonLayout, row, column, this, SLOT(showModal()));
|
|
|
|
m_deleteModalDialogButton =
|
|
|
|
addButton(tr("Delete modal"), buttonLayout, row, column, this, SLOT(deleteModalDialog()));
|
|
|
|
addButton(tr("Show non-modal"), buttonLayout, row, column, this, SLOT(showNonModal()));
|
|
|
|
m_deleteNonModalDialogButton =
|
|
|
|
addButton(tr("Delete non-modal"), buttonLayout, row, column, this, SLOT(deleteNonModalDialog()));
|
|
|
|
row = 0;
|
|
|
|
column++;
|
|
|
|
addButton(tr("getOpenFileName"), buttonLayout, row, column, this, SLOT(getOpenFileName()));
|
2013-03-14 13:41:47 +00:00
|
|
|
addButton(tr("getOpenFileUrl"), buttonLayout, row, column, this, SLOT(getOpenFileUrl()));
|
2013-01-17 14:49:42 +00:00
|
|
|
addButton(tr("getOpenFileNames"), buttonLayout, row, column, this, SLOT(getOpenFileNames()));
|
2013-03-14 13:41:47 +00:00
|
|
|
addButton(tr("getOpenFileUrls"), buttonLayout, row, column, this, SLOT(getOpenFileUrls()));
|
2013-01-17 14:49:42 +00:00
|
|
|
addButton(tr("getSaveFileName"), buttonLayout, row, column, this, SLOT(getSaveFileName()));
|
2013-03-14 13:41:47 +00:00
|
|
|
addButton(tr("getSaveFileUrl"), buttonLayout, row, column, this, SLOT(getSaveFileUrl()));
|
2013-01-17 14:49:42 +00:00
|
|
|
addButton(tr("getExistingDirectory"), buttonLayout, row, column, this, SLOT(getExistingDirectory()));
|
2013-03-14 13:41:47 +00:00
|
|
|
addButton(tr("getExistingDirectoryUrl"), buttonLayout, row, column, this, SLOT(getExistingDirectoryUrl()));
|
2013-01-17 14:49:42 +00:00
|
|
|
addButton(tr("Restore defaults"), buttonLayout, row, column, this, SLOT(restoreDefaults()));
|
2012-10-25 10:45:13 +00:00
|
|
|
|
|
|
|
// Main layout
|
|
|
|
QGridLayout *gridLayout = new QGridLayout(this);
|
|
|
|
gridLayout->addWidget(optionsGroupBox, 0, 0);
|
|
|
|
gridLayout->addWidget(filesGroupBox, 0, 1);
|
|
|
|
gridLayout->addWidget(labelsGroupBox, 1, 0);
|
|
|
|
gridLayout->addWidget(buttonsGroupBox, 1, 1);
|
|
|
|
|
2013-08-27 12:10:45 +00:00
|
|
|
connect(m_useMimeTypeFilters, SIGNAL(toggled(bool)), this, SLOT(useMimeTypeFilters(bool)));
|
|
|
|
|
2013-02-05 15:54:58 +00:00
|
|
|
enableDeleteModalDialogButton();
|
2013-01-16 14:12:29 +00:00
|
|
|
enableDeleteNonModalDialogButton();
|
2012-10-25 10:45:13 +00:00
|
|
|
restoreDefaults();
|
|
|
|
}
|
|
|
|
|
2013-01-17 14:49:42 +00:00
|
|
|
void FileDialogPanel::execModal()
|
2012-10-25 10:45:13 +00:00
|
|
|
{
|
|
|
|
QFileDialog dialog(this);
|
|
|
|
applySettings(&dialog);
|
2013-01-17 14:49:42 +00:00
|
|
|
connect(&dialog, SIGNAL(accepted()), this, SLOT(accepted()));
|
2012-10-25 10:45:13 +00:00
|
|
|
dialog.setWindowTitle(tr("Modal File Dialog Qt %1").arg(QLatin1String(QT_VERSION_STR)));
|
|
|
|
dialog.exec();
|
|
|
|
}
|
|
|
|
|
2013-01-17 14:49:42 +00:00
|
|
|
void FileDialogPanel::showModal()
|
|
|
|
{
|
|
|
|
if (m_modalDialog.isNull()) {
|
|
|
|
static int n = 0;
|
|
|
|
m_modalDialog = new QFileDialog(this);
|
|
|
|
m_modalDialog->setModal(true);
|
|
|
|
connect(m_modalDialog.data(), SIGNAL(accepted()), this, SLOT(accepted()));
|
|
|
|
m_modalDialog->setWindowTitle(tr("Modal File Dialog #%1 Qt %2")
|
|
|
|
.arg(++n)
|
|
|
|
.arg(QLatin1String(QT_VERSION_STR)));
|
2013-02-05 15:54:58 +00:00
|
|
|
enableDeleteModalDialogButton();
|
2013-01-17 14:49:42 +00:00
|
|
|
}
|
|
|
|
applySettings(m_modalDialog);
|
|
|
|
m_modalDialog->show();
|
|
|
|
}
|
|
|
|
|
2012-10-25 10:45:13 +00:00
|
|
|
void FileDialogPanel::showNonModal()
|
|
|
|
{
|
2013-01-16 14:12:29 +00:00
|
|
|
if (m_nonModalDialog.isNull()) {
|
|
|
|
static int n = 0;
|
|
|
|
m_nonModalDialog = new QFileDialog(this);
|
2013-01-17 14:49:42 +00:00
|
|
|
connect(m_nonModalDialog.data(), SIGNAL(accepted()), this, SLOT(accepted()));
|
2013-01-16 14:12:29 +00:00
|
|
|
m_nonModalDialog->setWindowTitle(tr("Non-Modal File Dialog #%1 Qt %2")
|
|
|
|
.arg(++n)
|
|
|
|
.arg(QLatin1String(QT_VERSION_STR)));
|
|
|
|
enableDeleteNonModalDialogButton();
|
|
|
|
}
|
|
|
|
applySettings(m_nonModalDialog);
|
|
|
|
m_nonModalDialog->show();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FileDialogPanel::deleteNonModalDialog()
|
|
|
|
{
|
|
|
|
if (!m_nonModalDialog.isNull())
|
|
|
|
delete m_nonModalDialog;
|
|
|
|
enableDeleteNonModalDialogButton();
|
|
|
|
}
|
|
|
|
|
2013-01-17 14:49:42 +00:00
|
|
|
void FileDialogPanel::deleteModalDialog()
|
|
|
|
{
|
|
|
|
if (!m_modalDialog.isNull())
|
|
|
|
delete m_modalDialog;
|
|
|
|
enableDeleteModalDialogButton();
|
|
|
|
}
|
|
|
|
|
2013-01-16 14:12:29 +00:00
|
|
|
void FileDialogPanel::enableDeleteNonModalDialogButton()
|
|
|
|
{
|
|
|
|
m_deleteNonModalDialogButton->setEnabled(!m_nonModalDialog.isNull());
|
2012-10-25 10:45:13 +00:00
|
|
|
}
|
|
|
|
|
2013-01-17 14:49:42 +00:00
|
|
|
void FileDialogPanel::enableDeleteModalDialogButton()
|
|
|
|
{
|
|
|
|
m_deleteModalDialogButton->setEnabled(!m_modalDialog.isNull());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-10-25 10:45:13 +00:00
|
|
|
QString FileDialogPanel::filterString() const
|
|
|
|
{
|
|
|
|
return m_nameFilters->toPlainText().trimmed().replace(QLatin1String("\n"), QLatin1String(";;"));
|
|
|
|
}
|
|
|
|
|
2014-07-14 08:11:39 +00:00
|
|
|
QUrl FileDialogPanel::currentDirectoryUrl() const
|
|
|
|
{
|
|
|
|
return QUrl::fromUserInput(m_directory->text().trimmed());
|
|
|
|
}
|
|
|
|
|
2012-10-25 10:45:13 +00:00
|
|
|
QFileDialog::Options FileDialogPanel::options() const
|
|
|
|
{
|
|
|
|
QFileDialog::Options result;
|
2013-12-10 10:19:16 +00:00
|
|
|
if (m_showDirsOnly->isChecked())
|
|
|
|
result |= QFileDialog::ShowDirsOnly;
|
2012-10-25 10:45:13 +00:00
|
|
|
if (!m_nameFilterDetailsVisible->isChecked())
|
|
|
|
result |= QFileDialog::HideNameFilterDetails;
|
|
|
|
if (!m_resolveSymLinks->isChecked())
|
|
|
|
result |= QFileDialog::DontResolveSymlinks;
|
|
|
|
if (m_readOnly->isChecked())
|
|
|
|
result |= QFileDialog::ReadOnly;
|
|
|
|
if (!m_confirmOverWrite->isChecked())
|
|
|
|
result |= QFileDialog::DontConfirmOverwrite;
|
|
|
|
if (!m_native->isChecked())
|
|
|
|
result |= QFileDialog::DontUseNativeDialog;
|
2017-06-13 01:56:16 +00:00
|
|
|
if (m_customDirIcons->isChecked())
|
2013-04-29 11:58:23 +00:00
|
|
|
result |= QFileDialog::DontUseCustomDirectoryIcons;
|
2012-10-25 10:45:13 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-03-14 13:41:47 +00:00
|
|
|
QStringList FileDialogPanel::allowedSchemes() const
|
|
|
|
{
|
|
|
|
return m_allowedSchemes->text().simplified().split(' ', QString::SkipEmptyParts);
|
|
|
|
}
|
|
|
|
|
2012-10-25 10:45:13 +00:00
|
|
|
void FileDialogPanel::getOpenFileNames()
|
|
|
|
{
|
|
|
|
QString selectedFilter = m_selectedNameFilter->text().trimmed();
|
|
|
|
const QStringList files =
|
|
|
|
QFileDialog::getOpenFileNames(this, tr("getOpenFileNames Qt %1").arg(QLatin1String(QT_VERSION_STR)),
|
|
|
|
m_directory->text(), filterString(), &selectedFilter, options());
|
|
|
|
if (!files.isEmpty()) {
|
|
|
|
QString result;
|
|
|
|
QDebug(&result).nospace()
|
|
|
|
<< "Files: " << files
|
|
|
|
<< "\nName filter: " << selectedFilter;
|
|
|
|
QMessageBox::information(this, tr("getOpenFileNames"), result, QMessageBox::Ok);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-14 13:41:47 +00:00
|
|
|
void FileDialogPanel::getOpenFileUrls()
|
|
|
|
{
|
2013-11-01 15:05:39 +00:00
|
|
|
#if QT_VERSION >= 0x050000
|
2013-03-14 13:41:47 +00:00
|
|
|
QString selectedFilter = m_selectedNameFilter->text().trimmed();
|
|
|
|
const QList<QUrl> files =
|
|
|
|
QFileDialog::getOpenFileUrls(this, tr("getOpenFileNames Qt %1").arg(QLatin1String(QT_VERSION_STR)),
|
2014-07-14 08:11:39 +00:00
|
|
|
currentDirectoryUrl(), filterString(), &selectedFilter, options(),
|
2013-03-14 13:41:47 +00:00
|
|
|
allowedSchemes());
|
|
|
|
if (!files.isEmpty()) {
|
|
|
|
QString result;
|
|
|
|
QDebug(&result).nospace()
|
|
|
|
<< "Files: " << QUrl::toStringList(files)
|
|
|
|
<< "\nName filter: " << selectedFilter;
|
|
|
|
QMessageBox::information(this, tr("getOpenFileNames"), result, QMessageBox::Ok);
|
|
|
|
}
|
2013-11-01 15:05:39 +00:00
|
|
|
#endif // Qt 5
|
2013-03-14 13:41:47 +00:00
|
|
|
}
|
|
|
|
|
2012-10-25 10:45:13 +00:00
|
|
|
void FileDialogPanel::getOpenFileName()
|
|
|
|
{
|
|
|
|
QString selectedFilter = m_selectedNameFilter->text().trimmed();
|
|
|
|
const QString file =
|
|
|
|
QFileDialog::getOpenFileName(this, tr("getOpenFileName Qt %1").arg(QLatin1String(QT_VERSION_STR)),
|
|
|
|
m_directory->text(), filterString(), &selectedFilter, options());
|
|
|
|
if (!file.isEmpty()) {
|
|
|
|
QString result;
|
|
|
|
QDebug(&result).nospace()
|
|
|
|
<< "File: " << file
|
|
|
|
<< "\nName filter: " << selectedFilter;
|
|
|
|
QMessageBox::information(this, tr("getOpenFileName"), result, QMessageBox::Ok);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-14 13:41:47 +00:00
|
|
|
void FileDialogPanel::getOpenFileUrl()
|
|
|
|
{
|
2013-11-01 15:05:39 +00:00
|
|
|
#if QT_VERSION >= 0x050000
|
2013-03-14 13:41:47 +00:00
|
|
|
QString selectedFilter = m_selectedNameFilter->text().trimmed();
|
|
|
|
const QUrl file =
|
|
|
|
QFileDialog::getOpenFileUrl(this, tr("getOpenFileUrl Qt %1").arg(QLatin1String(QT_VERSION_STR)),
|
2014-07-14 08:11:39 +00:00
|
|
|
currentDirectoryUrl(), filterString(), &selectedFilter, options(),
|
2013-03-14 13:41:47 +00:00
|
|
|
allowedSchemes());
|
|
|
|
if (file.isValid()) {
|
|
|
|
QString result;
|
|
|
|
QDebug(&result).nospace()
|
|
|
|
<< "File: " << file.toString()
|
|
|
|
<< "\nName filter: " << selectedFilter;
|
|
|
|
QMessageBox::information(this, tr("getOpenFileName"), result, QMessageBox::Ok);
|
|
|
|
}
|
2013-11-01 15:05:39 +00:00
|
|
|
#endif // Qt 5
|
2013-03-14 13:41:47 +00:00
|
|
|
}
|
|
|
|
|
2012-10-25 10:45:13 +00:00
|
|
|
void FileDialogPanel::getSaveFileName()
|
|
|
|
{
|
|
|
|
QString selectedFilter = m_selectedNameFilter->text().trimmed();
|
|
|
|
const QString file =
|
|
|
|
QFileDialog::getSaveFileName(this, tr("getSaveFileName Qt %1").arg(QLatin1String(QT_VERSION_STR)),
|
|
|
|
m_directory->text(), filterString(), &selectedFilter, options());
|
|
|
|
if (!file.isEmpty()) {
|
|
|
|
QString result;
|
|
|
|
QDebug(&result).nospace()
|
|
|
|
<< "File: " << file
|
|
|
|
<< "\nName filter: " << selectedFilter;
|
|
|
|
QMessageBox::information(this, tr("getSaveFileNames"), result, QMessageBox::Ok);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-14 13:41:47 +00:00
|
|
|
void FileDialogPanel::getSaveFileUrl()
|
|
|
|
{
|
2013-11-01 15:05:39 +00:00
|
|
|
#if QT_VERSION >= 0x050000
|
2013-03-14 13:41:47 +00:00
|
|
|
QString selectedFilter = m_selectedNameFilter->text().trimmed();
|
|
|
|
const QUrl file =
|
|
|
|
QFileDialog::getSaveFileUrl(this, tr("getSaveFileName Qt %1").arg(QLatin1String(QT_VERSION_STR)),
|
2014-07-14 08:11:39 +00:00
|
|
|
currentDirectoryUrl(), filterString(), &selectedFilter, options(),
|
2013-03-14 13:41:47 +00:00
|
|
|
allowedSchemes());
|
|
|
|
if (file.isValid()) {
|
|
|
|
QString result;
|
|
|
|
QDebug(&result).nospace()
|
|
|
|
<< "File: " << file.toString()
|
|
|
|
<< "\nName filter: " << selectedFilter;
|
|
|
|
QMessageBox::information(this, tr("getSaveFileNames"), result, QMessageBox::Ok);
|
|
|
|
}
|
2013-11-01 15:05:39 +00:00
|
|
|
#endif // Qt 5
|
2013-03-14 13:41:47 +00:00
|
|
|
}
|
|
|
|
|
2012-10-25 10:45:13 +00:00
|
|
|
void FileDialogPanel::getExistingDirectory()
|
|
|
|
{
|
|
|
|
const QString dir =
|
|
|
|
QFileDialog::getExistingDirectory(this, tr("getExistingDirectory Qt %1").arg(QLatin1String(QT_VERSION_STR)),
|
|
|
|
m_directory->text(), options() | QFileDialog::ShowDirsOnly);
|
|
|
|
if (!dir.isEmpty())
|
|
|
|
QMessageBox::information(this, tr("getExistingDirectory"), QLatin1String("Directory: ") + dir, QMessageBox::Ok);
|
|
|
|
}
|
|
|
|
|
2013-03-14 13:41:47 +00:00
|
|
|
void FileDialogPanel::getExistingDirectoryUrl()
|
|
|
|
{
|
2013-11-01 15:05:39 +00:00
|
|
|
#if QT_VERSION >= 0x050000
|
2013-03-14 13:41:47 +00:00
|
|
|
const QUrl dir =
|
|
|
|
QFileDialog::getExistingDirectoryUrl(this, tr("getExistingDirectory Qt %1").arg(QLatin1String(QT_VERSION_STR)),
|
2014-07-14 08:11:39 +00:00
|
|
|
currentDirectoryUrl(), options() | QFileDialog::ShowDirsOnly,
|
2013-03-14 13:41:47 +00:00
|
|
|
allowedSchemes());
|
|
|
|
if (!dir.isEmpty())
|
|
|
|
QMessageBox::information(this, tr("getExistingDirectory"), QLatin1String("Directory: ") + dir.toString(), QMessageBox::Ok);
|
2013-11-01 15:05:39 +00:00
|
|
|
#endif // Qt 5
|
2013-03-14 13:41:47 +00:00
|
|
|
}
|
|
|
|
|
2012-10-25 10:45:13 +00:00
|
|
|
void FileDialogPanel::restoreDefaults()
|
|
|
|
{
|
|
|
|
QFileDialog d;
|
|
|
|
setComboBoxValue(m_acceptMode, d.acceptMode());
|
|
|
|
setComboBoxValue(m_fileMode, d.fileMode());
|
|
|
|
setComboBoxValue(m_viewMode, d.viewMode());
|
2013-12-10 10:19:16 +00:00
|
|
|
m_showDirsOnly->setChecked(d.testOption(QFileDialog::ShowDirsOnly));
|
2013-03-14 13:41:47 +00:00
|
|
|
m_allowedSchemes->setText(QString());
|
2012-10-25 10:45:13 +00:00
|
|
|
m_confirmOverWrite->setChecked(d.confirmOverwrite());
|
|
|
|
m_nameFilterDetailsVisible->setChecked(d.isNameFilterDetailsVisible());
|
|
|
|
m_resolveSymLinks->setChecked(d.resolveSymlinks());
|
|
|
|
m_readOnly->setChecked(d.isReadOnly());
|
|
|
|
m_native->setChecked(true);
|
2013-04-29 11:58:23 +00:00
|
|
|
m_customDirIcons->setChecked(d.testOption(QFileDialog::DontUseCustomDirectoryIcons));
|
2012-10-25 10:45:13 +00:00
|
|
|
m_directory->setText(QDir::homePath());
|
2013-04-23 11:50:01 +00:00
|
|
|
m_defaultSuffix->setText(QLatin1String("txt"));
|
2013-08-27 12:10:45 +00:00
|
|
|
m_useMimeTypeFilters->setChecked(false);
|
|
|
|
useMimeTypeFilters(false);
|
2012-10-25 10:45:13 +00:00
|
|
|
m_selectedFileName->setText(QString());
|
|
|
|
m_selectedNameFilter->setText(QString());
|
|
|
|
foreach (LabelLineEdit *l, m_labelLineEdits)
|
|
|
|
l->restoreDefault(&d);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FileDialogPanel::applySettings(QFileDialog *d) const
|
|
|
|
{
|
|
|
|
d->setAcceptMode(comboBoxValue<QFileDialog::AcceptMode>(m_acceptMode));
|
|
|
|
d->setViewMode(comboBoxValue<QFileDialog::ViewMode>(m_viewMode));
|
|
|
|
d->setFileMode(comboBoxValue<QFileDialog::FileMode>(m_fileMode));
|
|
|
|
d->setOptions(options());
|
|
|
|
d->setDefaultSuffix(m_defaultSuffix->text().trimmed());
|
2013-02-15 08:42:13 +00:00
|
|
|
const QString directory = m_directory->text().trimmed();
|
|
|
|
if (!directory.isEmpty())
|
|
|
|
d->setDirectory(directory);
|
2012-10-25 10:45:13 +00:00
|
|
|
const QString file = m_selectedFileName->text().trimmed();
|
|
|
|
if (!file.isEmpty())
|
|
|
|
d->selectFile(file);
|
|
|
|
const QString filter = m_selectedNameFilter->text().trimmed();
|
2013-08-27 12:10:45 +00:00
|
|
|
const QStringList filters = m_nameFilters->toPlainText().trimmed().split(QLatin1Char('\n'), QString::SkipEmptyParts);
|
|
|
|
if (!m_useMimeTypeFilters->isChecked()) {
|
|
|
|
d->setNameFilters(filters);
|
|
|
|
if (!filter.isEmpty())
|
|
|
|
d->selectNameFilter(filter);
|
|
|
|
} else {
|
2013-11-01 15:05:39 +00:00
|
|
|
#if QT_VERSION >= 0x050000
|
2013-08-27 12:10:45 +00:00
|
|
|
d->setMimeTypeFilters(filters);
|
|
|
|
if (!filter.isEmpty())
|
|
|
|
d->selectMimeTypeFilter(filter);
|
2013-11-01 15:05:39 +00:00
|
|
|
#endif // Qt 5
|
2013-08-27 12:10:45 +00:00
|
|
|
}
|
2012-10-25 10:45:13 +00:00
|
|
|
foreach (LabelLineEdit *l, m_labelLineEdits)
|
|
|
|
l->apply(d);
|
|
|
|
}
|
|
|
|
|
2013-08-27 12:10:45 +00:00
|
|
|
void FileDialogPanel::useMimeTypeFilters(bool b)
|
|
|
|
{
|
|
|
|
QWidget *textEdit = filesLayout->labelForField(m_nameFilters);
|
|
|
|
if (QLabel *label = qobject_cast<QLabel *>(textEdit))
|
|
|
|
label->setText(b ? tr("Mime type filters:") : tr("Name filters:"));
|
|
|
|
QWidget *w = filesLayout->labelForField(m_selectedNameFilter);
|
|
|
|
if (QLabel *label = qobject_cast<QLabel *>(w))
|
|
|
|
label->setText(b ? tr("Selected mime type filter:") : tr("Selected name filter:"));
|
|
|
|
|
|
|
|
if (b)
|
|
|
|
m_nameFilters->setPlainText(QLatin1String("image/jpeg\nimage/png\ntext/plain\napplication/octet-stream"));
|
|
|
|
else
|
|
|
|
m_nameFilters->setPlainText(QLatin1String("Any files (*)\nImage files (*.png *.xpm *.jpg)\nText files (*.txt)"));
|
|
|
|
}
|
|
|
|
|
2012-10-25 10:45:13 +00:00
|
|
|
void FileDialogPanel::accepted()
|
|
|
|
{
|
|
|
|
const QFileDialog *d = qobject_cast<const QFileDialog *>(sender());
|
|
|
|
Q_ASSERT(d);
|
|
|
|
m_result.clear();
|
|
|
|
QDebug(&m_result).nospace()
|
|
|
|
<< "Files: " << d->selectedFiles()
|
|
|
|
<< "\nDirectory: " << d->directory().absolutePath()
|
|
|
|
<< "\nName filter: " << d->selectedNameFilter();
|
|
|
|
QTimer::singleShot(0, this, SLOT(showAcceptedResult())); // Avoid problems with the closing (modal) dialog as parent.
|
|
|
|
}
|
|
|
|
|
|
|
|
void FileDialogPanel::showAcceptedResult()
|
|
|
|
{
|
|
|
|
QMessageBox::information(this, tr("File Dialog Accepted"), m_result, QMessageBox::Ok);
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "filedialogpanel.moc"
|