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