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