File indexing completed on 2024-04-21 15:00:58

0001 /*
0002     This file is part of the KDE project
0003     SPDX-FileCopyrightText: 1998, 1999 Torben Weis <weis@kde.org>
0004     SPDX-FileCopyrightText: 1999, 2000 Preston Brown <pbrown@kde.org>
0005     SPDX-FileCopyrightText: 2000 Simon Hausmann <hausmann@kde.org>
0006     SPDX-FileCopyrightText: 2000 David Faure <faure@kde.org>
0007 
0008     SPDX-License-Identifier: LGPL-2.0-or-later
0009 */
0010 
0011 /*
0012  * This file holds the definitions for all classes used to
0013  * display a properties dialog.
0014  */
0015 
0016 #ifndef KPROPERTIESDIALOGP_H
0017 #define KPROPERTIESDIALOGP_H
0018 
0019 #include "kpropertiesdialog.h"
0020 
0021 #include <QCryptographicHash>
0022 
0023 class QComboBox;
0024 class QLabel;
0025 
0026 namespace KDEPrivate
0027 {
0028 /**
0029  * 'General' plugin
0030  *  This plugin displays the name of the file, its size and access times.
0031  * @internal
0032  */
0033 class KFilePropsPlugin : public KPropertiesDialogPlugin
0034 {
0035     Q_OBJECT
0036 public:
0037     /**
0038      * Constructor
0039      */
0040     explicit KFilePropsPlugin(KPropertiesDialog *_props);
0041     ~KFilePropsPlugin() override;
0042 
0043     /**
0044      * Applies all changes made.  This plugin must be always the first
0045      * plugin in the dialog, since this function may rename the file which
0046      * may confuse other applyChanges functions.
0047      */
0048     void applyChanges() override;
0049 
0050     /**
0051      * Tests whether the files specified by _items need a 'General' plugin.
0052      */
0053     static bool supports(const KFileItemList &_items);
0054 
0055     /**
0056      * Called after all plugins applied their changes
0057      */
0058     void postApplyChanges();
0059 
0060     void setFileNameReadOnly(bool ro);
0061 
0062 protected Q_SLOTS:
0063     void slotEditFileType();
0064     void slotCopyFinished(KJob *);
0065     void slotFileRenamed(KIO::Job *, const QUrl &, const QUrl &);
0066     void slotDirSizeUpdate();
0067     void slotDirSizeFinished(KJob *);
0068     void slotFreeSpaceResult(KIO::Job *job, KIO::filesize_t size, KIO::filesize_t available);
0069     void slotSizeStop();
0070     void slotSizeDetermine();
0071     void slotSizeDetails();
0072 
0073 Q_SIGNALS:
0074     void changesApplied();
0075 
0076 private Q_SLOTS:
0077     void nameFileChanged(const QString &text);
0078     void slotIconChanged();
0079 
0080 private:
0081     bool enableIconButton() const;
0082     void determineRelativePath(const QString &path);
0083     void applyIconChanges();
0084     void updateDefaultHandler(const QString &mimeType);
0085 
0086     class KFilePropsPluginPrivate;
0087     std::unique_ptr<KFilePropsPluginPrivate> d;
0088 };
0089 
0090 /**
0091  * 'Permissions' plugin
0092  * In this plugin you can modify permissions and change
0093  * the owner of a file.
0094  * @internal
0095  */
0096 class KFilePermissionsPropsPlugin : public KPropertiesDialogPlugin
0097 {
0098     Q_OBJECT
0099 public:
0100     enum PermissionsMode {
0101         PermissionsOnlyFiles = 0,
0102         PermissionsOnlyDirs = 1,
0103         PermissionsOnlyLinks = 2,
0104         PermissionsMixed = 3,
0105     };
0106 
0107     enum PermissionsTarget {
0108         PermissionsOwner = 0,
0109         PermissionsGroup = 1,
0110         PermissionsOthers = 2,
0111     };
0112 
0113     /**
0114      * Constructor
0115      */
0116     explicit KFilePermissionsPropsPlugin(KPropertiesDialog *_props);
0117     ~KFilePermissionsPropsPlugin() override;
0118 
0119     void applyChanges() override;
0120 
0121     /**
0122      * Tests whether the file specified by _items needs a 'Permissions' plugin.
0123      */
0124     static bool supports(const KFileItemList &_items);
0125 
0126 private Q_SLOTS:
0127     void slotShowAdvancedPermissions();
0128 
0129 Q_SIGNALS:
0130     void changesApplied();
0131 
0132 private:
0133     void setComboContent(QComboBox *combo, PermissionsTarget target, mode_t permissions, mode_t partial);
0134     bool isIrregular(mode_t permissions, bool isDir, bool isLink);
0135     void enableAccessControls(bool enable);
0136     void updateAccessControls();
0137     void getPermissionMasks(mode_t &andFilePermissions, mode_t &andDirPermissions, mode_t &orFilePermissions, mode_t &orDirPermissions);
0138 
0139     static const mode_t permissionsMasks[3];
0140     static const mode_t standardPermissions[4];
0141 
0142     static const mode_t fperm[3][4];
0143 
0144     class KFilePermissionsPropsPluginPrivate;
0145     std::unique_ptr<KFilePermissionsPropsPluginPrivate> d;
0146 };
0147 
0148 class KChecksumsPlugin : public KPropertiesDialogPlugin
0149 {
0150     Q_OBJECT
0151 public:
0152     explicit KChecksumsPlugin(KPropertiesDialog *dialog);
0153     ~KChecksumsPlugin() override;
0154 
0155     static bool supports(const KFileItemList &items);
0156 
0157 private Q_SLOTS:
0158     void slotInvalidateCache();
0159     void slotShowMd5();
0160     void slotShowSha1();
0161     void slotShowSha256();
0162     void slotShowSha512();
0163     /**
0164      * Compare @p input (required to be lowercase) with the checksum in cache.
0165      */
0166     void slotVerifyChecksum(const QString &input);
0167 
0168 private:
0169     static bool isMd5(const QString &input);
0170     static bool isSha1(const QString &input);
0171     static bool isSha256(const QString &input);
0172     static bool isSha512(const QString &input);
0173     static QString computeChecksum(QCryptographicHash::Algorithm algorithm, const QString &path);
0174     static QCryptographicHash::Algorithm detectAlgorithm(const QString &input);
0175 
0176     void setDefaultState();
0177     void setInvalidChecksumState();
0178     void setMatchState();
0179     void setMismatchState();
0180     void setVerifyState();
0181     void showChecksum(QCryptographicHash::Algorithm algorithm, QLabel *label, QPushButton *copyButton);
0182 
0183     QString cachedChecksum(QCryptographicHash::Algorithm algorithm) const;
0184     void cacheChecksum(const QString &checksum, QCryptographicHash::Algorithm algorithm);
0185 
0186     class KChecksumsPluginPrivate;
0187     std::unique_ptr<KChecksumsPluginPrivate> d;
0188 };
0189 
0190 /**
0191  * Used to edit the files containing
0192  * [Desktop Entry]
0193  * URL=....
0194  *
0195  * Such files are used to represent a program in kicker and konqueror.
0196  * @internal
0197  */
0198 class KUrlPropsPlugin : public KPropertiesDialogPlugin
0199 {
0200     Q_OBJECT
0201 public:
0202     /**
0203      * Constructor
0204      */
0205     explicit KUrlPropsPlugin(KPropertiesDialog *_props);
0206     ~KUrlPropsPlugin() override;
0207 
0208     void applyChanges() override;
0209 
0210     void setFileNameReadOnly(bool ro);
0211 
0212     static bool supports(const KFileItemList &_items);
0213 
0214 private:
0215     class KUrlPropsPluginPrivate;
0216     std::unique_ptr<KUrlPropsPluginPrivate> d;
0217 };
0218 
0219 /**
0220  * Used to edit the files containing
0221  * [Desktop Entry]
0222  * Type=Application
0223  *
0224  * Such files are used to represent a program in kicker and konqueror.
0225  * @internal
0226  */
0227 class KDesktopPropsPlugin : public KPropertiesDialogPlugin
0228 {
0229     Q_OBJECT
0230 public:
0231     /**
0232      * Constructor
0233      */
0234     explicit KDesktopPropsPlugin(KPropertiesDialog *_props);
0235     ~KDesktopPropsPlugin() override;
0236 
0237     void applyChanges() override;
0238 
0239     static bool supports(const KFileItemList &_items);
0240 
0241 public Q_SLOTS:
0242     void slotAddFiletype();
0243     void slotDelFiletype();
0244     void slotBrowseExec();
0245     void slotAdvanced();
0246 
0247 private:
0248     void checkCommandChanged();
0249 
0250 private:
0251     class KDesktopPropsPluginPrivate;
0252     std::unique_ptr<KDesktopPropsPluginPrivate> d;
0253 };
0254 
0255 }
0256 
0257 #endif