File indexing completed on 2024-10-13 03:38:17

0001 /*
0002     This file is part of the KDE libraries
0003     SPDX-FileCopyrightText: 2017 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
0004     Work sponsored by the LiMux project of the city of Munich
0005 
0006     SPDX-License-Identifier: LGPL-2.0-only
0007 */
0008 
0009 #include "kfilecustomdialog.h"
0010 
0011 #include <QPushButton>
0012 #include <QUrl>
0013 #include <QVBoxLayout>
0014 
0015 class KFileCustomDialogPrivate
0016 {
0017 public:
0018     explicit KFileCustomDialogPrivate(KFileCustomDialog *qq)
0019         : q(qq)
0020     {
0021     }
0022     void init(const QUrl &startDir);
0023 
0024     KFileWidget *mFileWidget = nullptr;
0025     KFileCustomDialog *const q;
0026 };
0027 
0028 void KFileCustomDialogPrivate::init(const QUrl &startDir)
0029 {
0030     QVBoxLayout *mainLayout = new QVBoxLayout(q);
0031     mainLayout->setObjectName(QStringLiteral("mainlayout"));
0032 
0033     mFileWidget = new KFileWidget(startDir, q);
0034     mFileWidget->setObjectName(QStringLiteral("filewidget"));
0035     mainLayout->addWidget(mFileWidget);
0036 
0037     mFileWidget->okButton()->show();
0038     q->connect(mFileWidget->okButton(), &QPushButton::clicked, q, [this]() {
0039         mFileWidget->slotOk();
0040     });
0041     mFileWidget->cancelButton()->show();
0042     q->connect(mFileWidget->cancelButton(), &QPushButton::clicked, q, [this]() {
0043         mFileWidget->slotCancel();
0044         q->reject();
0045     });
0046     q->connect(mFileWidget, &KFileWidget::accepted, q, [this] {
0047         q->accept();
0048     });
0049 }
0050 
0051 KFileCustomDialog::KFileCustomDialog(QWidget *parent)
0052     : QDialog(parent)
0053     , d(new KFileCustomDialogPrivate(this))
0054 {
0055     d->init(QUrl());
0056 }
0057 
0058 KFileCustomDialog::KFileCustomDialog(const QUrl &startDir, QWidget *parent)
0059     : QDialog(parent)
0060     , d(new KFileCustomDialogPrivate(this))
0061 {
0062     d->init(startDir);
0063 }
0064 
0065 KFileCustomDialog::~KFileCustomDialog() = default;
0066 
0067 void KFileCustomDialog::setUrl(const QUrl &url)
0068 {
0069     d->mFileWidget->setUrl(url);
0070 }
0071 
0072 void KFileCustomDialog::setCustomWidget(QWidget *widget)
0073 {
0074     d->mFileWidget->setCustomWidget(QString(), widget);
0075 }
0076 
0077 KFileWidget *KFileCustomDialog::fileWidget() const
0078 {
0079     return d->mFileWidget;
0080 }
0081 
0082 void KFileCustomDialog::setOperationMode(KFileWidget::OperationMode op)
0083 {
0084     d->mFileWidget->setOperationMode(op);
0085 }
0086 
0087 void KFileCustomDialog::accept()
0088 {
0089     d->mFileWidget->accept();
0090     QDialog::accept();
0091 }
0092 
0093 #include "moc_kfilecustomdialog.cpp"