File indexing completed on 2024-06-16 13:00:18

0001 /*
0002     This file is part of the KDE libraries
0003     SPDX-FileCopyrightText: 2015 David Faure <faure@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #include <KFileWidget>
0009 #include <QApplication>
0010 #include <QDebug>
0011 #include <QPushButton>
0012 #include <QUrl>
0013 
0014 int main(int argc, char **argv)
0015 {
0016     QApplication app(argc, argv);
0017 
0018     KFileWidget *fileWidget = new KFileWidget(QUrl(QStringLiteral("kfiledialog:///OpenDialog")), nullptr);
0019     fileWidget->setMode(KFile::Files | KFile::ExistingOnly);
0020     fileWidget->setAttribute(Qt::WA_DeleteOnClose);
0021     fileWidget->show();
0022 
0023     app.connect(fileWidget, &KFileWidget::accepted, fileWidget, [&app, fileWidget]() {
0024         qDebug() << "accepted";
0025         fileWidget->accept();
0026         qDebug() << "Selected File:" << fileWidget->selectedFile();
0027         qDebug() << "Selected Url:" << fileWidget->selectedUrl();
0028         qDebug() << "Selected Files:" << fileWidget->selectedFiles();
0029         qDebug() << "Selected Urls:" << fileWidget->selectedUrls();
0030         app.exit();
0031     });
0032 
0033     QObject::connect(fileWidget, &KFileWidget::destroyed, &app, &QApplication::quit);
0034 
0035     fileWidget->okButton()->show();
0036     QObject::connect(fileWidget->okButton(), &QPushButton::clicked, fileWidget, &KFileWidget::slotOk);
0037 
0038     fileWidget->cancelButton()->show();
0039     QObject::connect(fileWidget->cancelButton(), &QPushButton::clicked, &app, &QApplication::quit);
0040 
0041     return app.exec();
0042 }