File indexing completed on 2024-05-19 03:58:29

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 <QPushButton>
0011 #include <QUrl>
0012 
0013 int main(int argc, char **argv)
0014 {
0015     QApplication app(argc, argv);
0016 
0017     KFileWidget *fileWidget = new KFileWidget(QUrl(QStringLiteral("kfiledialog:///OpenDialog")), nullptr);
0018     fileWidget->setMode(KFile::Files | KFile::ExistingOnly);
0019     fileWidget->setAttribute(Qt::WA_DeleteOnClose);
0020     fileWidget->show();
0021 
0022     app.connect(fileWidget, &KFileWidget::accepted, fileWidget, [&app, fileWidget]() {
0023         qDebug() << "accepted";
0024         fileWidget->accept();
0025         qDebug() << "Selected File:" << fileWidget->selectedFile();
0026         qDebug() << "Selected Url:" << fileWidget->selectedUrl();
0027         qDebug() << "Selected Files:" << fileWidget->selectedFiles();
0028         qDebug() << "Selected Urls:" << fileWidget->selectedUrls();
0029         app.exit();
0030     });
0031 
0032     QObject::connect(fileWidget, &KFileWidget::destroyed, &app, &QApplication::quit);
0033 
0034     fileWidget->okButton()->show();
0035     QObject::connect(fileWidget->okButton(), &QPushButton::clicked, fileWidget, &KFileWidget::slotOk);
0036 
0037     fileWidget->cancelButton()->show();
0038     QObject::connect(fileWidget->cancelButton(), &QPushButton::clicked, &app, &QApplication::quit);
0039 
0040     return app.exec();
0041 }