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