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 QLabel; |
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 QString computeChecksum(QCryptographicHash::Algorithm algorithm, const QString &path); |
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, QLabel *label, QPushButton *copyButton); |
181 | |
182 | QString cachedChecksum(QCryptographicHash::Algorithm algorithm) const; |
183 | void cacheChecksum(const QString &checksum, QCryptographicHash::Algorithm algorithm); |
184 | |
185 | class KChecksumsPluginPrivate; |
186 | std::unique_ptr<KChecksumsPluginPrivate> d; |
187 | }; |
188 | |
189 | /** |
190 | * Used to edit the files containing |
191 | * [Desktop Entry] |
192 | * URL=.... |
193 | * |
194 | * Such files are used to represent a program in kicker and konqueror. |
195 | * @internal |
196 | */ |
197 | class KUrlPropsPlugin : public KPropertiesDialogPlugin |
198 | { |
199 | Q_OBJECT |
200 | public: |
201 | explicit KUrlPropsPlugin(KPropertiesDialog *_props); |
202 | ~KUrlPropsPlugin() override; |
203 | |
204 | void applyChanges() override; |
205 | |
206 | void setFileNameReadOnly(bool ro); |
207 | |
208 | static bool supports(const KFileItemList &_items); |
209 | |
210 | private: |
211 | class KUrlPropsPluginPrivate; |
212 | std::unique_ptr<KUrlPropsPluginPrivate> d; |
213 | }; |
214 | |
215 | /** |
216 | * Used to edit the files containing |
217 | * [Desktop Entry] |
218 | * Type=Application |
219 | * |
220 | * Such files are used to represent a program in kicker and konqueror. |
221 | * @internal |
222 | */ |
223 | class KDesktopPropsPlugin : public KPropertiesDialogPlugin |
224 | { |
225 | Q_OBJECT |
226 | public: |
227 | explicit KDesktopPropsPlugin(KPropertiesDialog *_props); |
228 | ~KDesktopPropsPlugin() override; |
229 | |
230 | void applyChanges() override; |
231 | |
232 | static bool supports(const KFileItemList &_items); |
233 | |
234 | public Q_SLOTS: |
235 | void slotAddFiletype(); |
236 | void slotDelFiletype(); |
237 | void slotBrowseExec(); |
238 | void slotAdvanced(); |
239 | |
240 | private: |
241 | void checkCommandChanged(); |
242 | |
243 | private: |
244 | class KDesktopPropsPluginPrivate; |
245 | std::unique_ptr<KDesktopPropsPluginPrivate> d; |
246 | }; |
247 | |
248 | } |
249 | |