]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinpart.h
Merge remote-tracking branch 'origin/KDE/4.11'
[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 <kparts/part.h>
24 #include <kparts/browserextension.h>
25 #include <kparts/fileinfoextension.h>
26
27 #include <QItemSelectionModel>
28
29 class DolphinNewFileMenu;
30 class DolphinViewActionHandler;
31 class QActionGroup;
32 class KAction;
33 class KFileItemList;
34 class KFileItem;
35 class DolphinPartBrowserExtension;
36 class DolphinSortFilterProxyModel;
37 class DolphinRemoteEncoding;
38 class DolphinModel;
39 class KDirLister;
40 class DolphinView;
41 class KAboutData;
42 class DolphinRemoveAction;
43
44 class DolphinPart : public KParts::ReadOnlyPart
45 {
46 Q_OBJECT
47 // Used by konqueror. Technically it means "we want undo enabled if
48 // there are things in the undo history and the current part is a dolphin part".
49 // Even though it's konqueror doing the undo...
50 Q_PROPERTY( bool supportsUndo READ supportsUndo )
51
52 Q_PROPERTY( QString currentViewMode READ currentViewMode WRITE setCurrentViewMode )
53
54 // Used by konqueror when typing something like /home/dfaure/*.diff in the location bar
55 Q_PROPERTY( QString nameFilter READ nameFilter WRITE setNameFilter )
56
57 // Used by konqueror to implement the --select command-line option
58 Q_PROPERTY( KUrl::List filesToSelect READ filesToSelect WRITE setFilesToSelect )
59
60 public:
61 explicit DolphinPart(QWidget* parentWidget, QObject* parent, const QVariantList& args);
62 ~DolphinPart();
63
64 static KAboutData* createAboutData();
65
66 /**
67 * Standard KParts::ReadOnlyPart openUrl method.
68 * Called by Konqueror to view a directory in DolphinPart.
69 */
70 virtual bool openUrl(const KUrl& url);
71
72 /// see the supportsUndo property
73 bool supportsUndo() const { return true; }
74
75 /**
76 * Used by konqueror for setting the view mode
77 * @param viewModeName internal name for the view mode, like "icons"
78 * Those names come from the Actions line in dolphinpart.desktop,
79 * and have to match the name of the KActions.
80 */
81 void setCurrentViewMode(const QString& viewModeName);
82
83 /**
84 * Used by konqueror for displaying the current view mode.
85 * @see setCurrentViewMode
86 */
87 QString currentViewMode() const;
88
89 /// Returns the view owned by this part; used by DolphinPartBrowserExtension
90 DolphinView* view() { return m_view; }
91
92 /**
93 * Sets a name filter, like *.diff
94 */
95 void setNameFilter(const QString& nameFilter);
96
97 /**
98 * Returns the current name filter. Used by konqueror to show it in the URL.
99 */
100 QString nameFilter() const { return m_nameFilter; }
101
102 protected:
103 /**
104 * We reimplement openUrl so no need to implement openFile.
105 */
106 virtual bool openFile() { return true; }
107
108 Q_SIGNALS:
109 /**
110 * Emitted when the view mode changes. Used by konqueror.
111 */
112 void viewModeChanged();
113
114
115 /**
116 * Emitted whenever the current URL is about to be changed.
117 */
118 void aboutToOpenURL();
119
120 private Q_SLOTS:
121 void slotMessage(const QString& msg);
122 void slotErrorMessage(const QString& msg);
123 /**
124 * Shows the information for the item \a item inside the statusbar. If the
125 * item is null, the default statusbar information is shown.
126 */
127 void slotRequestItemInfo(const KFileItem& item);
128 /**
129 * Handles clicking on an item
130 */
131 void slotItemActivated(const KFileItem& item);
132 /**
133 * Handles activation of multiple items
134 */
135 void slotItemsActivated(const KFileItemList& items);
136 /**
137 * Creates a new window showing the content of \a url.
138 */
139 void createNewWindow(const KUrl& url);
140 /**
141 * Opens the context menu on the current mouse position.
142 * @pos Position in screen coordinates.
143 * @item File item context. If item is null, the context menu
144 * should be applied to \a url.
145 * @url URL which contains \a item.
146 * @customActions Actions that should be added to the context menu,
147 * if the file item is null.
148 */
149 void slotOpenContextMenu(const QPoint& pos,
150 const KFileItem& item,
151 const KUrl& url,
152 const QList<QAction*>& customActions);
153
154 /**
155 * Informs the host that we are opening \a url (e.g. after a redirection
156 * coming from KDirLister).
157 * Testcase 1: fish://localhost
158 * Testcase 2: showing a directory that is being renamed by another window (#180156)
159 */
160 void slotDirectoryRedirection(const KUrl& oldUrl, const KUrl& newUrl);
161
162 /**
163 * Updates the state of the 'Edit' menu actions and emits
164 * the signal selectionChanged().
165 */
166 void slotSelectionChanged(const KFileItemList& selection);
167
168 /**
169 * Updates the text of the paste action dependent from
170 * the number of items which are in the clipboard.
171 */
172 void updatePasteAction();
173
174 /**
175 * Connected to all "Go" menu actions provided by DolphinPart
176 */
177 void slotGoTriggered(QAction* action);
178
179 /**
180 * Connected to the "editMimeType" action
181 */
182 void slotEditMimeType();
183
184 /**
185 * Connected to the "select_items_matching" action.
186 * Opens a dialog which permits to select all items matching a pattern like "*.jpg".
187 */
188 void slotSelectItemsMatchingPattern();
189
190 /**
191 * Connected to the "unselect_items_matching" action.
192 * Opens a dialog which permits to unselect all items matching a pattern like "*.jpg".
193 */
194 void slotUnselectItemsMatchingPattern();
195
196 /**
197 * Open a terminal window, starting with the current directory.
198 */
199 void slotOpenTerminal();
200
201 /**
202 * Open KFind with the current path.
203 */
204 void slotFindFile();
205
206 /**
207 * Updates the 'Create New...' sub menu, just before it's shown.
208 */
209 void updateNewMenu();
210
211 /**
212 * Updates the number of items (= number of files + number of
213 * directories) in the statusbar. If files are selected, the number
214 * of selected files and the sum of the filesize is shown.
215 */
216 void updateStatusBar();
217
218 /**
219 * Notify container of folder loading progress.
220 */
221 void updateProgress(int percent);
222
223 void createDirectory();
224
225 /**
226 * Called by konqueror --select
227 */
228 void setFilesToSelect(const KUrl::List& files);
229 KUrl::List filesToSelect() const { return KUrl::List(); } // silence moc
230
231 virtual bool eventFilter(QObject*, QEvent*);
232
233 private:
234 void createActions();
235 void createGoAction(const char* name, const char* iconName,
236 const QString& text, const QString& url,
237 QActionGroup* actionGroup);
238
239 void openSelectionDialog(const QString& title, const QString& text,
240 bool selectItems);
241
242 private:
243 DolphinView* m_view;
244 DolphinViewActionHandler* m_actionHandler;
245 DolphinRemoteEncoding* m_remoteEncoding;
246 DolphinPartBrowserExtension* m_extension;
247 DolphinNewFileMenu* m_newFileMenu;
248 KAction* m_findFileAction;
249 KAction* m_openTerminalAction;
250 QString m_nameFilter;
251 DolphinRemoveAction* m_removeAction;
252 Q_DISABLE_COPY(DolphinPart)
253 };
254
255 class DolphinPartBrowserExtension : public KParts::BrowserExtension
256 {
257 Q_OBJECT
258 public:
259 DolphinPartBrowserExtension( DolphinPart* part )
260 : KParts::BrowserExtension( part ), m_part(part) {}
261
262 virtual void restoreState(QDataStream &stream);
263 virtual void saveState(QDataStream &stream);
264
265 public Q_SLOTS:
266 void cut();
267 void copy();
268 void paste();
269 void pasteTo(const KUrl&);
270 void reparseConfiguration();
271
272 private:
273 DolphinPart* m_part;
274 };
275
276
277 class DolphinPartFileInfoExtension : public KParts::FileInfoExtension
278 {
279 Q_OBJECT
280
281 public:
282 DolphinPartFileInfoExtension(DolphinPart* part);
283
284 virtual QueryModes supportedQueryModes() const;
285 virtual bool hasSelection() const;
286
287 virtual KFileItemList queryFor(QueryMode mode) const;
288 protected:
289 DolphinPart* part() const;
290 };
291
292 #endif /* DOLPHINPART_H */