File indexing completed on 2025-01-26 05:06:20

0001 /*
0002     SPDX-FileCopyrightText: 2014 Eike Hein <hein@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "directorypicker.h"
0008 
0009 #include <QFileDialog>
0010 #include <QStandardPaths>
0011 
0012 #include <KLocalizedString>
0013 
0014 DirectoryPicker::DirectoryPicker(QObject *parent)
0015     : QObject(parent)
0016 {
0017 }
0018 
0019 DirectoryPicker::~DirectoryPicker()
0020 {
0021     delete m_dialog;
0022 }
0023 
0024 QUrl DirectoryPicker::url() const
0025 {
0026     return m_url;
0027 }
0028 
0029 void DirectoryPicker::open()
0030 {
0031     if (!m_dialog) {
0032         m_dialog = new QFileDialog(nullptr, i18n("Select Folder"), QStandardPaths::standardLocations(QStandardPaths::HomeLocation).at(0));
0033         m_dialog->setFileMode(QFileDialog::Directory);
0034         m_dialog->setOption(QFileDialog::ShowDirsOnly, true);
0035         connect(m_dialog, &QDialog::accepted, this, &DirectoryPicker::dialogAccepted);
0036     }
0037 
0038     m_dialog->show();
0039     m_dialog->raise();
0040     m_dialog->activateWindow();
0041 }
0042 
0043 void DirectoryPicker::dialogAccepted()
0044 {
0045     const QList<QUrl> &urls = m_dialog->selectedUrls();
0046 
0047     if (!urls.isEmpty()) {
0048         m_url = urls.at(0);
0049 
0050         Q_EMIT urlChanged();
0051     }
0052 }