File indexing completed on 2024-11-24 04:42:33

0001 /*
0002  *  singlefileresourceconfigdialog.h - configuration dialog for single file resources.
0003  *  Program:  kalarm
0004  *  SPDX-FileCopyrightText: 2020-2022 David Jarvie <djarvie@kde.org>
0005  *
0006  *  SPDX-License-Identifier: GPL-2.0-or-later
0007  */
0008 
0009 #pragma once
0010 
0011 #include "kalarmcalendar/kacalendar.h"
0012 
0013 #include <QDialog>
0014 #include <QUrl>
0015 
0016 class KJob;
0017 namespace KIO { class StatJob; }
0018 class Ui_SingleFileResourceConfigWidget;
0019 
0020 class SingleFileResourceConfigDialog : public QDialog
0021 {
0022     Q_OBJECT
0023 public:
0024     SingleFileResourceConfigDialog(bool create, QWidget* parent);
0025     ~SingleFileResourceConfigDialog() override;
0026 
0027     /** Return the file URL. */
0028     QUrl url() const;
0029 
0030     /** Set the file URL. */
0031     void setUrl(const QUrl& url, bool readOnly = false);
0032 
0033     /** Return the resource's display name. */
0034     QString displayName() const;
0035 
0036     /** Set the resource's display name. */
0037     void setDisplayName(const QString& name);
0038 
0039     /** Return whether the resource is read-only. */
0040     bool readOnly() const;
0041 
0042     /** Set the read-only status of the resource. */
0043     void setReadOnly(bool readonly);
0044 
0045     /** Return the resource's alarm type. */
0046     KAlarmCal::CalEvent::Type alarmType() const;
0047 
0048     /** Set the resource's alarm type. */
0049     void setAlarmType(KAlarmCal::CalEvent::Type);
0050 
0051     /** Set a function to validate the entered URL.
0052      *  The function should return an error text to display to the user, or
0053      *  empty string if no error.
0054      */
0055     void setUrlValidation(QString (*func)(const QUrl&));
0056 
0057 protected:
0058     void showEvent(QShowEvent*) override;
0059 
0060 private Q_SLOTS:
0061     void validate();
0062     void slotStatJobResult(KJob*);
0063 
0064 private:
0065     void initiateUrlStatusCheck(const QUrl&);
0066     void enableOkButton();
0067     void disableOkButton(const QString& statusMessage, bool errorColour = false);
0068 
0069     Ui_SingleFileResourceConfigWidget* mUi {nullptr};
0070     QString     (*mUrlValidationFunc)(const QUrl&) {nullptr};
0071     KIO::StatJob* mStatJob {nullptr};
0072     const bool    mCreating;              // whether creating or editing the resource
0073     bool          mCheckingDir {false};
0074 };
0075 
0076 // vim: et sw=4: