1 /* This file is part of the KDE project
2 Copyright (c) 2007 David Faure <faure@kde.org>
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.
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.
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.
23 #include <kdeversion.h>
25 #include <kparts/part.h>
26 #include <kparts/browserextension.h>
27 #include <kparts/fileinfoextension.h>
29 #if KDE_IS_VERSION(4, 9, 2)
30 #include <kparts/listingextension.h>
33 #include <QItemSelectionModel>
36 class DolphinViewActionHandler
;
41 class DolphinPartBrowserExtension
;
42 class DolphinSortFilterProxyModel
;
43 class DolphinRemoteEncoding
;
49 class DolphinPart
: public KParts::ReadOnlyPart
52 // Used by konqueror. Technically it means "we want undo enabled if
53 // there are things in the undo history and the current part is a dolphin part".
54 // Even though it's konqueror doing the undo...
55 Q_PROPERTY( bool supportsUndo READ supportsUndo
)
57 Q_PROPERTY( QString currentViewMode READ currentViewMode WRITE setCurrentViewMode
)
59 // Used by konqueror when typing something like /home/dfaure/*.diff in the location bar
60 Q_PROPERTY( QString nameFilter READ nameFilter WRITE setNameFilter
)
62 // Used by konqueror to implement the --select command-line option
63 Q_PROPERTY( KUrl::List filesToSelect READ filesToSelect WRITE setFilesToSelect
)
66 explicit DolphinPart(QWidget
* parentWidget
, QObject
* parent
, const QVariantList
& args
);
69 static KAboutData
* createAboutData();
72 * Standard KParts::ReadOnlyPart openUrl method.
73 * Called by Konqueror to view a directory in DolphinPart.
75 virtual bool openUrl(const KUrl
& url
);
77 /// see the supportsUndo property
78 bool supportsUndo() const { return true; }
81 * Used by konqueror for setting the view mode
82 * @param viewModeName internal name for the view mode, like "icons"
83 * Those names come from the Actions line in dolphinpart.desktop,
84 * and have to match the name of the KActions.
86 void setCurrentViewMode(const QString
& viewModeName
);
89 * Used by konqueror for displaying the current view mode.
90 * @see setCurrentViewMode
92 QString
currentViewMode() const;
94 /// Returns the view owned by this part; used by DolphinPartBrowserExtension
95 DolphinView
* view() { return m_view
; }
98 * Sets a name filter, like *.diff
100 void setNameFilter(const QString
& nameFilter
);
103 * Returns the current name filter. Used by konqueror to show it in the URL.
105 QString
nameFilter() const { return m_nameFilter
; }
109 * We reimplement openUrl so no need to implement openFile.
111 virtual bool openFile() { return true; }
115 * Emitted when the view mode changes. Used by konqueror.
117 void viewModeChanged();
121 * Emitted whenever the current URL is about to be changed.
123 void aboutToOpenURL();
126 void slotMessage(const QString
& msg
);
127 void slotErrorMessage(const QString
& msg
);
129 * Shows the information for the item \a item inside the statusbar. If the
130 * item is null, the default statusbar information is shown.
132 void slotRequestItemInfo(const KFileItem
& item
);
134 * Handles clicking on an item
136 void slotItemActivated(const KFileItem
& item
);
138 * Creates a new window showing the content of \a url.
140 void createNewWindow(const KUrl
& url
);
142 * Opens the context menu on the current mouse position.
143 * @pos Position in screen coordinates.
144 * @item File item context. If item is null, the context menu
145 * should be applied to \a url.
146 * @url URL which contains \a item.
147 * @customActions Actions that should be added to the context menu,
148 * if the file item is null.
150 void slotOpenContextMenu(const QPoint
& pos
,
151 const KFileItem
& item
,
153 const QList
<QAction
*>& customActions
);
156 * Informs the host that we are opening \a url (e.g. after a redirection
157 * coming from KDirLister).
158 * Testcase 1: fish://localhost
159 * Testcase 2: showing a directory that is being renamed by another window (#180156)
161 void slotDirectoryRedirection(const KUrl
& oldUrl
, const KUrl
& newUrl
);
164 * Updates the state of the 'Edit' menu actions and emits
165 * the signal selectionChanged().
167 void slotSelectionChanged(const KFileItemList
& selection
);
170 * Updates the text of the paste action dependent from
171 * the number of items which are in the clipboard.
173 void updatePasteAction();
176 * Connected to all "Go" menu actions provided by DolphinPart
178 void slotGoTriggered(QAction
* action
);
181 * Connected to the "editMimeType" action
183 void slotEditMimeType();
186 * Connected to the "select_items_matching" action.
187 * Opens a dialog which permits to select all items matching a pattern like "*.jpg".
189 void slotSelectItemsMatchingPattern();
192 * Connected to the "unselect_items_matching" action.
193 * Opens a dialog which permits to unselect all items matching a pattern like "*.jpg".
195 void slotUnselectItemsMatchingPattern();
198 * Open a terminal window, starting with the current directory.
200 void slotOpenTerminal();
203 * Open KFind with the current path.
208 * Updates the 'Create New...' sub menu, just before it's shown.
210 void updateNewMenu();
213 * Updates the number of items (= number of files + number of
214 * directories) in the statusbar. If files are selected, the number
215 * of selected files and the sum of the filesize is shown.
217 void updateStatusBar();
220 * Notify container of folder loading progress.
222 void updateProgress(int percent
);
224 void createDirectory();
227 * Called by konqueror --select
229 void setFilesToSelect(const KUrl::List
& files
);
230 KUrl::List
filesToSelect() const { return KUrl::List(); } // silence moc
233 void createActions();
234 void createGoAction(const char* name
, const char* iconName
,
235 const QString
& text
, const QString
& url
,
236 QActionGroup
* actionGroup
);
238 void openSelectionDialog(const QString
& title
, const QString
& text
,
243 DolphinViewActionHandler
* m_actionHandler
;
244 DolphinRemoteEncoding
* m_remoteEncoding
;
245 DolphinPartBrowserExtension
* m_extension
;
246 KNewFileMenu
* m_newFileMenu
;
247 KAction
* m_findFileAction
;
248 KAction
* m_openTerminalAction
;
249 QString m_nameFilter
;
250 Q_DISABLE_COPY(DolphinPart
)
253 class DolphinPartBrowserExtension
: public KParts::BrowserExtension
257 DolphinPartBrowserExtension( DolphinPart
* part
)
258 : KParts::BrowserExtension( part
), m_part(part
) {}
260 virtual void restoreState(QDataStream
&stream
);
261 virtual void saveState(QDataStream
&stream
);
267 void pasteTo(const KUrl
&);
268 void reparseConfiguration();
275 class DolphinPartFileInfoExtension
: public KParts::FileInfoExtension
280 DolphinPartFileInfoExtension(DolphinPart
* part
);
282 virtual QueryModes
supportedQueryModes() const;
283 virtual bool hasSelection() const;
285 virtual KFileItemList
queryFor(QueryMode mode
) const;
287 DolphinPart
* part() const;
290 #if KDE_IS_VERSION(4, 9, 2)
291 class DolphinPartListingFilterExtension
: public KParts::ListingFilterExtension
296 DolphinPartListingFilterExtension (DolphinPart
* part
);
297 virtual FilterModes
supportedFilterModes() const;
298 virtual bool supportsMultipleFilters (FilterMode mode
) const;
299 virtual QVariant
filter (FilterMode mode
) const;
300 virtual void setFilter (FilterMode mode
, const QVariant
& filter
);
306 class DolphinPartListingNotificationExtension
: public KParts::ListingNotificationExtension
311 DolphinPartListingNotificationExtension(DolphinPart
* part
);
312 virtual NotificationEventTypes
supportedNotificationEventTypes() const;
315 void slotNewItems(const KFileItemList
&);
316 void slotItemsDeleted(const KFileItemList
&);
320 #endif /* DOLPHINPART_H */