]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinpart.h
Fix compile against the minimum required kdelibs version (v4.7.97)
[dolphin.git] / src / dolphinpart.h
1 /* This file is part of the KDE project
2 Copyright (c) 2007 David Faure <faure@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
18 */
19
20 #ifndef DOLPHINPART_H
21 #define DOLPHINPART_H
22
23 #include <kdeversion.h>
24
25 #include <kparts/part.h>
26 #include <kparts/browserextension.h>
27 #include <kparts/fileinfoextension.h>
28
29 #if KDE_IS_VERSION(4, 9, 2)
30 #include <kparts/listingextension.h>
31 #endif
32
33 #include <QItemSelectionModel>
34
35 class KNewFileMenu;
36 class DolphinViewActionHandler;
37 class QActionGroup;
38 class KAction;
39 class KFileItemList;
40 class KFileItem;
41 class DolphinPartBrowserExtension;
42 class DolphinSortFilterProxyModel;
43 class DolphinRemoteEncoding;
44 class DolphinModel;
45 class KDirLister;
46 class DolphinView;
47 class KAboutData;
48
49 class DolphinPart : public KParts::ReadOnlyPart
50 {
51 Q_OBJECT
52 // Used by konqueror. Technically it means "we want undo enabled if
53 // there are things in the undo history and the current part is a dolphin part".
54 // Even though it's konqueror doing the undo...
55 Q_PROPERTY( bool supportsUndo READ supportsUndo )
56
57 Q_PROPERTY( QString currentViewMode READ currentViewMode WRITE setCurrentViewMode )
58
59 // Used by konqueror when typing something like /home/dfaure/*.diff in the location bar
60 Q_PROPERTY( QString nameFilter READ nameFilter WRITE setNameFilter )
61
62 // Used by konqueror to implement the --select command-line option
63 Q_PROPERTY( KUrl::List filesToSelect READ filesToSelect WRITE setFilesToSelect )
64
65 public:
66 explicit DolphinPart(QWidget* parentWidget, QObject* parent, const QVariantList& args);
67 ~DolphinPart();
68
69 static KAboutData* createAboutData();
70
71 /**
72 * Standard KParts::ReadOnlyPart openUrl method.
73 * Called by Konqueror to view a directory in DolphinPart.
74 */
75 virtual bool openUrl(const KUrl& url);
76
77 /// see the supportsUndo property
78 bool supportsUndo() const { return true; }
79
80 /**
81 * Used by konqueror for setting the view mode
82 * @param viewModeName internal name for the view mode, like "icons"
83 * Those names come from the Actions line in dolphinpart.desktop,
84 * and have to match the name of the KActions.
85 */
86 void setCurrentViewMode(const QString& viewModeName);
87
88 /**
89 * Used by konqueror for displaying the current view mode.
90 * @see setCurrentViewMode
91 */
92 QString currentViewMode() const;
93
94 /// Returns the view owned by this part; used by DolphinPartBrowserExtension
95 DolphinView* view() { return m_view; }
96
97 /**
98 * Sets a name filter, like *.diff
99 */
100 void setNameFilter(const QString& nameFilter);
101
102 /**
103 * Returns the current name filter. Used by konqueror to show it in the URL.
104 */
105 QString nameFilter() const { return m_nameFilter; }
106
107 protected:
108 /**
109 * We reimplement openUrl so no need to implement openFile.
110 */
111 virtual bool openFile() { return true; }
112
113 Q_SIGNALS:
114 /**
115 * Emitted when the view mode changes. Used by konqueror.
116 */
117 void viewModeChanged();
118
119
120 /**
121 * Emitted whenever the current URL is about to be changed.
122 */
123 void aboutToOpenURL();
124
125 private Q_SLOTS:
126 void slotMessage(const QString& msg);
127 void slotErrorMessage(const QString& msg);
128 /**
129 * Shows the information for the item \a item inside the statusbar. If the
130 * item is null, the default statusbar information is shown.
131 */
132 void slotRequestItemInfo(const KFileItem& item);
133 /**
134 * Handles clicking on an item
135 */
136 void slotItemActivated(const KFileItem& item);
137 /**
138 * Creates a new window showing the content of \a url.
139 */
140 void createNewWindow(const KUrl& url);
141 /**
142 * Opens the context menu on the current mouse position.
143 * @pos Position in screen coordinates.
144 * @item File item context. If item is null, the context menu
145 * should be applied to \a url.
146 * @url URL which contains \a item.
147 * @customActions Actions that should be added to the context menu,
148 * if the file item is null.
149 */
150 void slotOpenContextMenu(const QPoint& pos,
151 const KFileItem& item,
152 const KUrl& url,
153 const QList<QAction*>& customActions);
154
155 /**
156 * Informs the host that we are opening \a url (e.g. after a redirection
157 * coming from KDirLister).
158 * Testcase 1: fish://localhost
159 * Testcase 2: showing a directory that is being renamed by another window (#180156)
160 */
161 void slotDirectoryRedirection(const KUrl& oldUrl, const KUrl& newUrl);
162
163 /**
164 * Updates the state of the 'Edit' menu actions and emits
165 * the signal selectionChanged().
166 */
167 void slotSelectionChanged(const KFileItemList& selection);
168
169 /**
170 * Updates the text of the paste action dependent from
171 * the number of items which are in the clipboard.
172 */
173 void updatePasteAction();
174
175 /**
176 * Connected to all "Go" menu actions provided by DolphinPart
177 */
178 void slotGoTriggered(QAction* action);
179
180 /**
181 * Connected to the "editMimeType" action
182 */
183 void slotEditMimeType();
184
185 /**
186 * Connected to the "select_items_matching" action.
187 * Opens a dialog which permits to select all items matching a pattern like "*.jpg".
188 */
189 void slotSelectItemsMatchingPattern();
190
191 /**
192 * Connected to the "unselect_items_matching" action.
193 * Opens a dialog which permits to unselect all items matching a pattern like "*.jpg".
194 */
195 void slotUnselectItemsMatchingPattern();
196
197 /**
198 * Open a terminal window, starting with the current directory.
199 */
200 void slotOpenTerminal();
201
202 /**
203 * Open KFind with the current path.
204 */
205 void slotFindFile();
206
207 /**
208 * Updates the 'Create New...' sub menu, just before it's shown.
209 */
210 void updateNewMenu();
211
212 /**
213 * Updates the number of items (= number of files + number of
214 * directories) in the statusbar. If files are selected, the number
215 * of selected files and the sum of the filesize is shown.
216 */
217 void updateStatusBar();
218
219 /**
220 * Notify container of folder loading progress.
221 */
222 void updateProgress(int percent);
223
224 void createDirectory();
225
226 /**
227 * Called by konqueror --select
228 */
229 void setFilesToSelect(const KUrl::List& files);
230 KUrl::List filesToSelect() const { return KUrl::List(); } // silence moc
231
232 private:
233 void createActions();
234 void createGoAction(const char* name, const char* iconName,
235 const QString& text, const QString& url,
236 QActionGroup* actionGroup);
237
238 void openSelectionDialog(const QString& title, const QString& text,
239 bool selectItems);
240
241 private:
242 DolphinView* m_view;
243 DolphinViewActionHandler* m_actionHandler;
244 DolphinRemoteEncoding* m_remoteEncoding;
245 DolphinPartBrowserExtension* m_extension;
246 KNewFileMenu* m_newFileMenu;
247 KAction* m_findFileAction;
248 KAction* m_openTerminalAction;
249 QString m_nameFilter;
250 Q_DISABLE_COPY(DolphinPart)
251 };
252
253 class DolphinPartBrowserExtension : public KParts::BrowserExtension
254 {
255 Q_OBJECT
256 public:
257 DolphinPartBrowserExtension( DolphinPart* part )
258 : KParts::BrowserExtension( part ), m_part(part) {}
259
260 virtual void restoreState(QDataStream &stream);
261 virtual void saveState(QDataStream &stream);
262
263 public Q_SLOTS:
264 void cut();
265 void copy();
266 void paste();
267 void pasteTo(const KUrl&);
268 void reparseConfiguration();
269
270 private:
271 DolphinPart* m_part;
272 };
273
274
275 class DolphinPartFileInfoExtension : public KParts::FileInfoExtension
276 {
277 Q_OBJECT
278
279 public:
280 DolphinPartFileInfoExtension(DolphinPart* part);
281
282 virtual QueryModes supportedQueryModes() const;
283 virtual bool hasSelection() const;
284
285 virtual KFileItemList queryFor(QueryMode mode) const;
286 protected:
287 DolphinPart* part() const;
288 };
289
290 #if KDE_IS_VERSION(4, 9, 2)
291 class DolphinPartListingFilterExtension : public KParts::ListingFilterExtension
292 {
293 Q_OBJECT
294
295 public:
296 DolphinPartListingFilterExtension (DolphinPart* part);
297 virtual FilterModes supportedFilterModes() const;
298 virtual bool supportsMultipleFilters (FilterMode mode) const;
299 virtual QVariant filter (FilterMode mode) const;
300 virtual void setFilter (FilterMode mode, const QVariant& filter);
301
302 private:
303 DolphinPart* m_part;
304 };
305
306 class DolphinPartListingNotificationExtension : public KParts::ListingNotificationExtension
307 {
308 Q_OBJECT
309
310 public:
311 DolphinPartListingNotificationExtension(DolphinPart* part);
312 virtual NotificationEventTypes supportedNotificationEventTypes() const;
313
314 public Q_SLOTS:
315 void slotNewItems(const KFileItemList&);
316 void slotItemsDeleted(const KFileItemList&);
317 };
318 #endif
319
320 #endif /* DOLPHINPART_H */