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