]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinpart.h
viewproperties: Fix leaking file descriptors
[dolphin.git] / src / dolphinpart.h
1 /* This file is part of the KDE project
2 SPDX-FileCopyrightText: 2007 David Faure <faure@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6
7 #ifndef DOLPHINPART_H
8 #define DOLPHINPART_H
9
10 #include <KParts/ReadOnlyPart>
11
12 #include <QAction>
13 #include <QUrl>
14
15 class DolphinNewFileMenu;
16 class DolphinViewActionHandler;
17 class QActionGroup;
18 class KFileItemList;
19 class KFileItem;
20 class DolphinPartBrowserExtension;
21 class DolphinRemoteEncoding;
22 class KDirLister;
23 class DolphinView;
24 class DolphinRemoveAction;
25
26 class DolphinPart : public KParts::ReadOnlyPart
27 {
28 Q_OBJECT
29 // Used by konqueror. Technically it means "we want undo enabled if
30 // there are things in the undo history and the current part is a dolphin part".
31 // Even though it's konqueror doing the undo...
32 Q_PROPERTY(bool supportsUndo READ supportsUndo CONSTANT)
33
34 Q_PROPERTY(QString currentViewMode READ currentViewMode WRITE setCurrentViewMode)
35
36 // Used by konqueror when typing something like /home/dfaure/*.diff in the location bar
37 Q_PROPERTY(QString nameFilter READ nameFilter WRITE setNameFilter)
38
39 // Used by konqueror to implement the --select command-line option
40 Q_PROPERTY(QList<QUrl> filesToSelect READ filesToSelect WRITE setFilesToSelect)
41
42 public:
43 explicit DolphinPart(QWidget *parentWidget, QObject *parent, const KPluginMetaData &metaData, const QVariantList &args);
44 ~DolphinPart() override;
45
46 /**
47 * Standard KParts::ReadOnlyPart openUrl method.
48 * Called by Konqueror to view a directory in DolphinPart.
49 */
50 bool openUrl(const QUrl &url) override;
51
52 /// see the supportsUndo property
53 bool supportsUndo() const
54 {
55 return true;
56 }
57
58 /**
59 * Used by konqueror for setting the view mode
60 * @param viewModeName internal name for the view mode, like "icons"
61 * Those names come from the Actions line in dolphinpart.desktop,
62 * and have to match the name of the KActions.
63 */
64 void setCurrentViewMode(const QString &viewModeName);
65
66 /**
67 * Used by konqueror for displaying the current view mode.
68 * @see setCurrentViewMode
69 */
70 QString currentViewMode() const;
71
72 /// Returns the view owned by this part; used by DolphinPartBrowserExtension
73 DolphinView *view()
74 {
75 return m_view;
76 }
77
78 /**
79 * Sets a name filter, like *.diff
80 */
81 void setNameFilter(const QString &nameFilter);
82
83 /**
84 * Returns the current name filter. Used by konqueror to show it in the URL.
85 */
86 QString nameFilter() const
87 {
88 return m_nameFilter;
89 }
90
91 /**
92 * Don't use this. Always @returns an empty list. It only exists to silence moc.
93 */
94 QList<QUrl> filesToSelect() const
95 {
96 return QList<QUrl>();
97 }
98
99 protected:
100 /**
101 * We reimplement openUrl so no need to implement openFile.
102 */
103 bool openFile() override
104 {
105 return true;
106 }
107
108 Q_SIGNALS:
109 /**
110 * Emitted when the view mode changes. Used by konqueror.
111 */
112 void viewModeChanged();
113
114 /**
115 * Emitted whenever the current URL is about to be changed.
116 */
117 void aboutToOpenURL();
118
119 private Q_SLOTS:
120 void slotMessage(const QString &msg);
121 void slotErrorMessage(const QString &msg);
122 /**
123 * Shows the information for the item \a item inside the statusbar. If the
124 * item is null, the default statusbar information is shown.
125 */
126 void slotRequestItemInfo(const KFileItem &item);
127 /**
128 * Handles clicking on an item
129 */
130 void slotItemActivated(const KFileItem &item);
131 /**
132 * Handles activation of multiple items
133 */
134 void slotItemsActivated(const KFileItemList &items);
135 /**
136 * Creates a new window showing the content of \a url.
137 */
138 void createNewWindow(const QUrl &url);
139 /**
140 * Opens the context menu on the current mouse position.
141 * @pos Position in screen coordinates.
142 * @item File item context. If item is null, the context menu
143 * should be applied to \a url.
144 * @selectedItems The selected items for which the context menu
145 * is opened. This list generally includes \a item.
146 * @url URL which contains \a item.
147 */
148 void slotOpenContextMenu(const QPoint &pos, const KFileItem &_item, const KFileItemList &selectedItems, const QUrl &);
149
150 /**
151 * Informs the host that we are opening \a url (e.g. after a redirection
152 * coming from KDirLister).
153 * Testcase 1: fish://localhost
154 * Testcase 2: showing a directory that is being renamed by another window (#180156)
155 */
156 void slotDirectoryRedirection(const QUrl &oldUrl, const QUrl &newUrl);
157
158 /**
159 * Updates the state of the 'Edit' menu actions and emits
160 * the signal selectionChanged().
161 */
162 void slotSelectionChanged(const KFileItemList &selection);
163
164 /**
165 * Updates the text of the paste action dependent from
166 * the number of items which are in the clipboard.
167 */
168 void updatePasteAction();
169
170 /**
171 * Connected to all "Go" menu actions provided by DolphinPart
172 */
173 void slotGoTriggered(QAction *action);
174
175 /**
176 * Connected to the "editMimeType" action
177 */
178 void slotEditMimeType();
179
180 /**
181 * Connected to the "select_items_matching" action.
182 * Opens a dialog which permits to select all items matching a pattern like "*.jpg".
183 */
184 void slotSelectItemsMatchingPattern();
185
186 /**
187 * Connected to the "unselect_items_matching" action.
188 * Opens a dialog which permits to unselect all items matching a pattern like "*.jpg".
189 */
190 void slotUnselectItemsMatchingPattern();
191
192 /**
193 * Open a terminal window, starting with the current directory.
194 */
195 void slotOpenTerminal();
196
197 /**
198 * Open preferred search tool in the current directory to find files.
199 */
200 void slotFindFile();
201
202 /**
203 * Updates the 'Create New...' sub menu, just before it's shown.
204 */
205 void updateNewMenu();
206
207 /**
208 * Updates the number of items (= number of files + number of
209 * directories) in the statusbar. If files are selected, the number
210 * of selected files and the sum of the filesize is shown.
211 */
212 void updateStatusBar();
213
214 /**
215 * Notify container of folder loading progress.
216 */
217 void updateProgress(int percent);
218
219 void createDirectory();
220
221 /**
222 * Called by konqueror --select
223 */
224 void setFilesToSelect(const QList<QUrl> &files);
225
226 bool eventFilter(QObject *, QEvent *) override;
227
228 private:
229 void createActions();
230 void createGoAction(const char *name, const char *iconName, const QString &text, const QString &url, QActionGroup *actionGroup);
231
232 void openSelectionDialog(const QString &title, const QString &text, bool selectItems);
233 QString urlToLocalFilePath(const QUrl &url);
234 QString localFilePathOrHome() const;
235
236 private:
237 DolphinView *m_view;
238 DolphinViewActionHandler *m_actionHandler;
239 DolphinRemoteEncoding *m_remoteEncoding;
240 DolphinPartBrowserExtension *m_extension;
241 DolphinNewFileMenu *m_newFileMenu;
242 QAction *m_findFileAction;
243 QAction *m_openTerminalAction;
244 QString m_nameFilter;
245 DolphinRemoveAction *m_removeAction;
246 Q_DISABLE_COPY(DolphinPart)
247 };
248
249 #endif /* DOLPHINPART_H */