File indexing completed on 2024-11-24 04:44:36
0001 /* 0002 SPDX-FileCopyrightText: 2008 Bertjan Broeksema <b.broeksema@kdemail.org> 0003 SPDX-FileCopyrightText: 2008 Volker Krause <vkrause@kde.org> 0004 SPDX-FileCopyrightText: 2010, 2011 David Jarvie <djarvie@kde.org> 0005 0006 SPDX-License-Identifier: LGPL-2.0-or-later 0007 */ 0008 0009 #pragma once 0010 0011 #include "akonadi-singlefileresource_export.h" 0012 0013 #include "ui_singlefileresourceconfigwidget_desktop.h" 0014 0015 #include <QUrl> 0016 class KConfigDialogManager; 0017 class KJob; 0018 class QPushButton; 0019 0020 namespace KIO 0021 { 0022 class StatJob; 0023 } 0024 0025 namespace Akonadi 0026 { 0027 class SingleFileValidatingWidget; 0028 0029 /** 0030 * Base class for the configuration dialog for single file based resources. 0031 * @see SingleFileResourceConfigWidget 0032 */ 0033 class AKONADI_SINGLEFILERESOURCE_EXPORT SingleFileResourceConfigWidgetBase : public QWidget 0034 { 0035 Q_OBJECT 0036 public: 0037 explicit SingleFileResourceConfigWidgetBase(QWidget *parent); 0038 ~SingleFileResourceConfigWidgetBase() override; 0039 0040 /** 0041 * Adds @param page to the tabwidget. This can be used to add custom 0042 * settings for a specific single file resource. 0043 */ 0044 void addPage(const QString &title, QWidget *page); 0045 0046 /** 0047 * Set file extension filter. 0048 */ 0049 void setFilter(const QString &filter); 0050 0051 /** 0052 * Enable and show, or disable and hide, the monitor option. 0053 * If the option is disabled, its value will not be saved. 0054 * By default, the monitor option is enabled. 0055 */ 0056 void setMonitorEnabled(bool enable); 0057 0058 /** 0059 * Return the file URL. 0060 */ 0061 QUrl url() const; 0062 0063 /** 0064 * Set the file URL. 0065 */ 0066 void setUrl(const QUrl &url); 0067 0068 /** 0069 * Specify whether the file must be local. 0070 * The default is to allow both local and remote files. 0071 */ 0072 void setLocalFileOnly(bool local); 0073 0074 /** 0075 * Add a widget to the dialog. 0076 */ 0077 void appendWidget(SingleFileValidatingWidget *widget); 0078 0079 virtual bool save() const = 0; 0080 virtual void load() = 0; 0081 Q_SIGNALS: 0082 void okEnabled(bool enabled); 0083 0084 protected: 0085 Ui::SingleFileResourceConfigWidget ui; 0086 KConfigDialogManager *mManager = nullptr; 0087 0088 private: 0089 void validate(); 0090 void slotStatJobResult(KJob *); 0091 KIO::StatJob *mStatJob = nullptr; 0092 SingleFileValidatingWidget *mAppendedWidget = nullptr; 0093 bool mDirUrlChecked = false; 0094 bool mMonitorEnabled = false; 0095 bool mLocalFileOnly = false; 0096 QPushButton *mOkButton = nullptr; 0097 }; 0098 0099 /** 0100 * Base class for widgets added to SingleFileResourceConfigWidgetBase 0101 * using its appendWidget() method. 0102 * 0103 * Derived classes must implement validate() andQ_EMIT changed() when 0104 * appropriate. 0105 */ 0106 class AKONADI_SINGLEFILERESOURCE_EXPORT SingleFileValidatingWidget : public QWidget 0107 { 0108 Q_OBJECT 0109 public: 0110 explicit SingleFileValidatingWidget(QWidget *parent = nullptr); 0111 0112 /** 0113 * Return whether the widget's value is valid when the dialog is 0114 * accepted. 0115 */ 0116 virtual bool validate() const = 0; 0117 0118 Q_SIGNALS: 0119 /** 0120 * Signal emitted when the widget's value changes in a way which 0121 * might affect the result of validate(). 0122 */ 0123 void changed(); 0124 }; 0125 }