diff --git a/krita/ui/widgets/kis_url_requester.cpp b/krita/ui/widgets/kis_url_requester.cpp index 9e62f53cc8e..cfb7919e086 100644 --- a/krita/ui/widgets/kis_url_requester.cpp +++ b/krita/ui/widgets/kis_url_requester.cpp @@ -1,124 +1,144 @@ /* * Copyright (c) 2015 Dmitry Kazakov * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "kis_url_requester.h" #include "ui_wdg_url_requester.h" #include #include #include "KoIcon.h" #include "kis_debug.h" KisUrlRequester::KisUrlRequester(QWidget *parent) : QWidget(parent) , m_ui(new Ui::WdgUrlRequester) , m_mode(KoFileDialog::OpenFile) { m_ui->setupUi(this); m_ui->btnSelectFile->setIcon(koIcon("folder")); connect(m_ui->btnSelectFile, SIGNAL(clicked()), SLOT(slotSelectFile())); connect(m_ui->txtFileName, SIGNAL(textChanged(const QString&)), SIGNAL(textChanged(const QString&))); } KisUrlRequester::~KisUrlRequester() { } void KisUrlRequester::setStartDir(const QString &path) { m_basePath = path; } void KisUrlRequester::setFileName(const QString &path) { m_ui->txtFileName->setText(path); KUrl url(path); emit urlSelected(url); } QString KisUrlRequester::fileName() const { return m_ui->txtFileName->text(); } KUrl KisUrlRequester::url() const { return KUrl(fileName()); } void KisUrlRequester::setUrl(const KUrl &urlObj) { QString url = urlObj.path(); if (m_basePath.isEmpty()) { setFileName(url); } else { QDir d(m_basePath); setFileName(d.relativeFilePath(url)); } } void KisUrlRequester::setMode(KoFileDialog::DialogType mode) { m_mode = mode; } KoFileDialog::DialogType KisUrlRequester::mode() const { return m_mode; } void KisUrlRequester::setMimeTypeFilters(const QStringList &filterList, QString defaultFilter) { m_mime_filter_list = filterList; m_mime_default_filter = defaultFilter; } +void KisUrlRequester::setNameFilter(const QString& filter) +{ + m_nameFilter = filter; +} + + void KisUrlRequester::slotSelectFile() { KoFileDialog dialog(this, m_mode, "OpenDocument"); - if (m_mode == KoFileDialog::OpenFile) { + if (m_mode == KoFileDialog::OpenFile) + { dialog.setCaption(i18n("Select a file to load...")); } - else if (m_mode == KoFileDialog::OpenDirectory) { + else if (m_mode == KoFileDialog::OpenDirectory) + { dialog.setCaption(i18n("Select a directory to load...")); } dialog.setDefaultDir(m_basePath.isEmpty() ? QDesktopServices::storageLocation(QDesktopServices::PicturesLocation) : m_basePath); + if (m_mime_filter_list.isEmpty()) + { dialog.setMimeTypeFilters(KisImportExportManager::mimeFilter("application/x-krita", KisImportExportManager::Import)); + } else + { dialog.setMimeTypeFilters(m_mime_filter_list, m_mime_default_filter); + } + + if (!m_nameFilter.isEmpty()) + { + dialog.setNameFilter(m_nameFilter); + } + QString url = dialog.url(); - if (m_basePath.isEmpty()) { + if (m_basePath.isEmpty()) + { setFileName(url); - } else + } + else { QDir d(m_basePath); setFileName(d.relativeFilePath(url)); } - } diff --git a/krita/ui/widgets/kis_url_requester.h b/krita/ui/widgets/kis_url_requester.h index 7aa006b61f4..9afc3633078 100644 --- a/krita/ui/widgets/kis_url_requester.h +++ b/krita/ui/widgets/kis_url_requester.h @@ -1,85 +1,91 @@ /* * Copyright (c) 2015 Dmitry Kazakov * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KIS_URL_REQUESTER_H #define KIS_URL_REQUESTER_H #include "krita_export.h" #include #include #include #include namespace Ui { class WdgUrlRequester; } /** * This represents an editable file name. * Visual it presents a QLineEdit + a buton that pops up * a file chooser. * * Signals are fired when the user changes the text * or selects a new file via the button/file chooser. */ class KRITAUI_EXPORT KisUrlRequester : public QWidget { Q_OBJECT public: explicit KisUrlRequester(QWidget *parent = 0); ~KisUrlRequester(); void setStartDir(const QString &path); KUrl url() const; void setUrl(const KUrl &url); void setMode(KoFileDialog::DialogType mode); KoFileDialog::DialogType mode() const; /** * Sets the mime type filters to use, same format as KoFileDialog::setMimeTypeFilters. * If this is not called, the default list is used, which simply selects all the image * file formats Krita can load. */ void setMimeTypeFilters(const QStringList &filterList, QString defaultFilter = QString()); + /** + * Sets the name filter, same as KoFileDialog::setNameFilter + */ + void setNameFilter(const QString &filter); + public Q_SLOTS: void slotSelectFile(); Q_SIGNALS: void textChanged(const QString &fileName); void urlSelected(const KUrl &url); private: QString fileName() const; void setFileName(const QString &path); private: QScopedPointer m_ui; QString m_basePath; KoFileDialog::DialogType m_mode; QStringList m_mime_filter_list; QString m_mime_default_filter; + QString m_nameFilter; }; #endif // KIS_URL_REQUESTER_H