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