| 1 | /* |
| 2 | This file is part of the KDE project |
| 3 | SPDX-FileCopyrightText: 1998, 1999 Torben Weis <weis@kde.org> |
| 4 | SPDX-FileCopyrightText: 1999, 2000 Preston Brown <pbrown@kde.org> |
| 5 | SPDX-FileCopyrightText: 2000 Simon Hausmann <hausmann@kde.org> |
| 6 | SPDX-FileCopyrightText: 2000 David Faure <faure@kde.org> |
| 7 | |
| 8 | SPDX-License-Identifier: LGPL-2.0-or-later |
| 9 | */ |
| 10 | |
| 11 | /* |
| 12 | * This file holds the definitions for all classes used to |
| 13 | * display a properties dialog. |
| 14 | */ |
| 15 | |
| 16 | #pragma once |
| 17 | |
| 18 | #include "kpropertiesdialog.h" |
| 19 | #include "kpropertiesdialogplugin.h" |
| 20 | |
| 21 | #include <QCryptographicHash> |
| 22 | |
| 23 | class QComboBox; |
| 24 | class QLineEdit; |
| 25 | class KJob; |
| 26 | namespace KIO |
| 27 | { |
| 28 | class Job; |
| 29 | } |
| 30 | |
| 31 | namespace KDEPrivate |
| 32 | { |
| 33 | /*! |
| 34 | * 'General' plugin |
| 35 | * This plugin displays the name of the file, its size and access times. |
| 36 | * \internal |
| 37 | */ |
| 38 | class KFilePropsPlugin : public KPropertiesDialogPlugin |
| 39 | { |
| 40 | Q_OBJECT |
| 41 | public: |
| 42 | explicit KFilePropsPlugin(KPropertiesDialog *_props); |
| 43 | ~KFilePropsPlugin() override; |
| 44 | |
| 45 | /*! |
| 46 | * Applies all changes made. This plugin must be always the first |
| 47 | * plugin in the dialog, since this function may rename the file which |
| 48 | * may confuse other applyChanges functions. |
| 49 | */ |
| 50 | void applyChanges() override; |
| 51 | |
| 52 | /*! |
| 53 | * Tests whether the files specified by _items need a 'General' plugin. |
| 54 | */ |
| 55 | static bool supports(const KFileItemList &_items); |
| 56 | |
| 57 | /*! |
| 58 | * Called after all plugins applied their changes |
| 59 | */ |
| 60 | void postApplyChanges(); |
| 61 | |
| 62 | void setFileNameReadOnly(bool ro); |
| 63 | |
| 64 | protected Q_SLOTS: |
| 65 | void slotEditFileType(); |
| 66 | void slotCopyFinished(KJob *); |
| 67 | void slotFileRenamed(KIO::Job *, const QUrl &, const QUrl &); |
| 68 | void slotDirSizeUpdate(); |
| 69 | void slotDirSizeFinished(KJob *); |
| 70 | void slotFreeSpaceResult(KJob *); |
| 71 | void slotSizeStop(); |
| 72 | void slotSizeDetermine(); |
| 73 | void slotSizeDetails(); |
| 74 | |
| 75 | Q_SIGNALS: |
| 76 | void changesApplied(); |
| 77 | |
| 78 | private Q_SLOTS: |
| 79 | void nameFileChanged(const QString &text); |
| 80 | void slotIconChanged(); |
| 81 | |
| 82 | private: |
| 83 | bool enableIconButton() const; |
| 84 | void determineRelativePath(const QString &path); |
| 85 | void applyIconChanges(); |
| 86 | void updateDefaultHandler(const QString &mimeType); |
| 87 | |
| 88 | class KFilePropsPluginPrivate; |
| 89 | std::unique_ptr<KFilePropsPluginPrivate> d; |
| 90 | }; |
| 91 | |
| 92 | /*! |
| 93 | * 'Permissions' plugin |
| 94 | * In this plugin you can modify permissions and change |
| 95 | * the owner of a file. |
| 96 | * \internal |
| 97 | */ |
| 98 | class KFilePermissionsPropsPlugin : public KPropertiesDialogPlugin |
| 99 | { |
| 100 | Q_OBJECT |
| 101 | public: |
| 102 | enum PermissionsMode { |
| 103 | PermissionsOnlyFiles = 0, |
| 104 | PermissionsOnlyDirs = 1, |
| 105 | PermissionsOnlyLinks = 2, |
| 106 | PermissionsMixed = 3, |
| 107 | }; |
| 108 | |
| 109 | enum PermissionsTarget { |
| 110 | PermissionsOwner = 0, |
| 111 | PermissionsGroup = 1, |
| 112 | PermissionsOthers = 2, |
| 113 | }; |
| 114 | |
| 115 | explicit KFilePermissionsPropsPlugin(KPropertiesDialog *_props); |
| 116 | ~KFilePermissionsPropsPlugin() override; |
| 117 | |
| 118 | void applyChanges() override; |
| 119 | |
| 120 | /*! |
| 121 | * Tests whether the file specified by _items needs a 'Permissions' plugin. |
| 122 | */ |
| 123 | static bool supports(const KFileItemList &_items); |
| 124 | |
| 125 | private Q_SLOTS: |
| 126 | void slotShowAdvancedPermissions(); |
| 127 | |
| 128 | Q_SIGNALS: |
| 129 | void changesApplied(); |
| 130 | |
| 131 | private: |
| 132 | void setComboContent(QComboBox *combo, PermissionsTarget target, mode_t permissions, mode_t partial); |
| 133 | bool isIrregular(mode_t permissions, bool isDir, bool isLink); |
| 134 | void enableAccessControls(bool enable); |
| 135 | void updateAccessControls(); |
| 136 | void getPermissionMasks(mode_t &andFilePermissions, mode_t &andDirPermissions, mode_t &orFilePermissions, mode_t &orDirPermissions); |
| 137 | |
| 138 | static const mode_t permissionsMasks[3]; |
| 139 | static const mode_t standardPermissions[4]; |
| 140 | |
| 141 | static const mode_t fperm[3][4]; |
| 142 | |
| 143 | class KFilePermissionsPropsPluginPrivate; |
| 144 | std::unique_ptr<KFilePermissionsPropsPluginPrivate> d; |
| 145 | }; |
| 146 | |
| 147 | class KChecksumsPlugin : public KPropertiesDialogPlugin |
| 148 | { |
| 149 | Q_OBJECT |
| 150 | public: |
| 151 | explicit KChecksumsPlugin(KPropertiesDialog *dialog); |
| 152 | ~KChecksumsPlugin() override; |
| 153 | |
| 154 | static bool supports(const KFileItemList &items); |
| 155 | |
| 156 | private Q_SLOTS: |
| 157 | void slotInvalidateCache(); |
| 158 | void slotShowMd5(); |
| 159 | void slotShowSha1(); |
| 160 | void slotShowSha256(); |
| 161 | void slotShowSha512(); |
| 162 | /*! |
| 163 | * Compare @p input (required to be lowercase) with the checksum in cache. |
| 164 | */ |
| 165 | void slotVerifyChecksum(const QString &input); |
| 166 | |
| 167 | private: |
| 168 | static bool isMd5(const QString &input); |
| 169 | static bool isSha1(const QString &input); |
| 170 | static bool isSha256(const QString &input); |
| 171 | static bool isSha512(const QString &input); |
| 172 | static QPair<QString, bool> computeChecksum(QCryptographicHash::Algorithm algorithm, const KFileItemList &items); |
| 173 | static QCryptographicHash::Algorithm detectAlgorithm(const QString &input); |
| 174 | |
| 175 | void setDefaultState(); |
| 176 | void setInvalidChecksumState(); |
| 177 | void setMatchState(); |
| 178 | void setMismatchState(); |
| 179 | void setVerifyState(); |
| 180 | void showChecksum(QCryptographicHash::Algorithm algorithm, QLineEdit *label, QPushButton *copyButton); |
| 181 | |
| 182 | QString cachedChecksum(QCryptographicHash::Algorithm algorithm) const; |
| 183 | void cacheChecksum(const QString &checksum, QCryptographicHash::Algorithm algorithm); |
| 184 | |
| 185 | bool cachedMultiFileMatch(QCryptographicHash::Algorithm algorithm) const; |
| 186 | void cacheMultiFileMatch(const bool &isMatch, QCryptographicHash::Algorithm algorithm); |
| 187 | |
| 188 | class KChecksumsPluginPrivate; |
| 189 | std::unique_ptr<KChecksumsPluginPrivate> d; |
| 190 | }; |
| 191 | |
| 192 | /*! |
| 193 | * Used to edit the files containing |
| 194 | * [Desktop Entry] |
| 195 | * URL=.... |
| 196 | * |
| 197 | * Such files are used to represent a program in kicker and konqueror. |
| 198 | * \internal |
| 199 | */ |
| 200 | class KUrlPropsPlugin : public KPropertiesDialogPlugin |
| 201 | { |
| 202 | Q_OBJECT |
| 203 | public: |
| 204 | explicit KUrlPropsPlugin(KPropertiesDialog *_props); |
| 205 | ~KUrlPropsPlugin() override; |
| 206 | |
| 207 | void applyChanges() override; |
| 208 | |
| 209 | void setFileNameReadOnly(bool ro); |
| 210 | |
| 211 | static bool supports(const KFileItemList &_items); |
| 212 | |
| 213 | private: |
| 214 | class KUrlPropsPluginPrivate; |
| 215 | std::unique_ptr<KUrlPropsPluginPrivate> d; |
| 216 | }; |
| 217 | |
| 218 | /*! |
| 219 | * Used to edit the files containing |
| 220 | * [Desktop Entry] |
| 221 | * Type=Application |
| 222 | * |
| 223 | * Such files are used to represent a program in kicker and konqueror. |
| 224 | * \internal |
| 225 | */ |
| 226 | class KDesktopPropsPlugin : public KPropertiesDialogPlugin |
| 227 | { |
| 228 | Q_OBJECT |
| 229 | public: |
| 230 | explicit KDesktopPropsPlugin(KPropertiesDialog *_props); |
| 231 | ~KDesktopPropsPlugin() override; |
| 232 | |
| 233 | void applyChanges() override; |
| 234 | |
| 235 | static bool supports(const KFileItemList &_items); |
| 236 | |
| 237 | public Q_SLOTS: |
| 238 | void slotAddFiletype(); |
| 239 | void slotDelFiletype(); |
| 240 | void slotBrowseExec(); |
| 241 | void slotAdvanced(); |
| 242 | |
| 243 | private: |
| 244 | void checkCommandChanged(); |
| 245 | |
| 246 | private: |
| 247 | class KDesktopPropsPluginPrivate; |
| 248 | std::unique_ptr<KDesktopPropsPluginPrivate> d; |
| 249 | }; |
| 250 | |
| 251 | } |
| 252 | |