File indexing completed on 2024-12-08 03:40:48

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