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 <kparts/part.h>
24 #include <kparts/browserextension.h>
25 #include <kparts/fileinfoextension.h>
27 #include <QItemSelectionModel>
30 class DolphinViewActionHandler
;
35 class DolphinPartBrowserExtension
;
36 class DolphinSortFilterProxyModel
;
37 class DolphinRemoteEncoding
;
43 class DolphinPart
: public KParts::ReadOnlyPart
46 // Used by konqueror. Technically it means "we want undo enabled if
47 // there are things in the undo history and the current part is a dolphin part".
48 // Even though it's konqueror doing the undo...
49 Q_PROPERTY( bool supportsUndo READ supportsUndo
)
51 Q_PROPERTY( QString currentViewMode READ currentViewMode WRITE setCurrentViewMode
)
53 // Used by konqueror when typing something like /home/dfaure/*.diff in the location bar
54 Q_PROPERTY( QString nameFilter READ nameFilter WRITE setNameFilter
)
56 // Used by konqueror to implement the --select command-line option
57 Q_PROPERTY( KUrl::List filesToSelect READ filesToSelect WRITE setFilesToSelect
)
60 explicit DolphinPart(QWidget
* parentWidget
, QObject
* parent
, const QVariantList
& args
);
63 static KAboutData
* createAboutData();
66 * Standard KParts::ReadOnlyPart openUrl method.
67 * Called by Konqueror to view a directory in DolphinPart.
69 virtual bool openUrl(const KUrl
& url
);
71 /// see the supportsUndo property
72 bool supportsUndo() const { return true; }
75 * Used by konqueror for setting the view mode
76 * @param viewModeName internal name for the view mode, like "icons"
77 * Those names come from the Actions line in dolphinpart.desktop,
78 * and have to match the name of the KActions.
80 void setCurrentViewMode(const QString
& viewModeName
);
83 * Used by konqueror for displaying the current view mode.
84 * @see setCurrentViewMode
86 QString
currentViewMode() const;
88 /// Returns the view owned by this part; used by DolphinPartBrowserExtension
89 DolphinView
* view() { return m_view
; }
92 * Sets a name filter, like *.diff
94 void setNameFilter(const QString
& nameFilter
);
97 * Returns the current name filter. Used by konqueror to show it in the URL.
99 QString
nameFilter() const { return m_nameFilter
; }
103 * We reimplement openUrl so no need to implement openFile.
105 virtual bool openFile() { return true; }
109 * Emitted when the view mode changes. Used by konqueror.
111 void viewModeChanged();
115 * Emitted whenever the current URL is about to be changed.
117 void aboutToOpenURL();
120 void slotCompleted(const KUrl
& url
);
121 void slotCanceled(const KUrl
& url
);
122 void slotMessage(const QString
& msg
);
123 void slotErrorMessage(const QString
& msg
);
125 * Shows the information for the item \a item inside the statusbar. If the
126 * item is null, the default statusbar information is shown.
128 void slotRequestItemInfo(const KFileItem
& item
);
130 * Handles clicking on an item
132 void slotItemTriggered(const KFileItem
& item
);
134 * Creates a new window showing the content of \a url.
136 void createNewWindow(const KUrl
& url
);
138 * Opens the context menu on the current mouse position.
139 * @item File item context. If item is null, the context menu
140 * should be applied to \a url.
141 * @url URL which contains \a item.
142 * @customActions Actions that should be added to the context menu,
143 * if the file item is null.
145 void slotOpenContextMenu(const KFileItem
& item
,
147 const QList
<QAction
*>& customActions
);
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)
155 void slotRedirection(const KUrl
& oldUrl
, const KUrl
& newUrl
);
158 * Updates the state of the 'Edit' menu actions and emits
159 * the signal selectionChanged().
161 void slotSelectionChanged(const KFileItemList
& selection
);
164 * Updates the text of the paste action dependent from
165 * the number of items which are in the clipboard.
167 void updatePasteAction();
170 * Connected to all "Go" menu actions provided by DolphinPart
172 void slotGoTriggered(QAction
* action
);
175 * Connected to the "editMimeType" action
177 void slotEditMimeType();
180 * Connected to the "select_items_matching" action.
181 * Opens a dialog which permits to select all items matching a pattern like "*.jpg".
183 void slotSelectItemsMatchingPattern();
186 * Connected to the "unselect_items_matching" action.
187 * Opens a dialog which permits to unselect all items matching a pattern like "*.jpg".
189 void slotUnselectItemsMatchingPattern();
192 * Open a terminal window, starting with the current directory.
194 void slotOpenTerminal();
197 * Updates the 'Create New...' sub menu, just before it's shown.
199 void updateNewMenu();
202 * Updates the number of items (= number of files + number of
203 * directories) in the statusbar. If files are selected, the number
204 * of selected files and the sum of the filesize is shown.
206 void updateStatusBar();
209 * Notify container of folder loading progress.
211 void updateProgress(int percent
);
213 void createDirectory();
216 * Called by konqueror --select
218 void setFilesToSelect(const KUrl::List
& files
);
219 KUrl::List
filesToSelect() const { return KUrl::List(); } // silence moc
222 void createActions();
223 void createGoAction(const char* name
, const char* iconName
,
224 const QString
& text
, const QString
& url
,
225 QActionGroup
* actionGroup
);
227 void openSelectionDialog(const QString
& title
, const QString
& text
,
232 DolphinViewActionHandler
* m_actionHandler
;
233 DolphinRemoteEncoding
* m_remoteEncoding
;
234 KDirLister
* m_dirLister
;
235 DolphinModel
* m_dolphinModel
;
236 DolphinSortFilterProxyModel
* m_proxyModel
;
237 DolphinPartBrowserExtension
* m_extension
;
238 KNewFileMenu
* m_newFileMenu
;
239 QString m_nameFilter
;
240 Q_DISABLE_COPY(DolphinPart
)
243 class DolphinPartBrowserExtension
: public KParts::BrowserExtension
247 DolphinPartBrowserExtension( DolphinPart
* part
)
248 : KParts::BrowserExtension( part
), m_part(part
) {}
250 virtual void restoreState(QDataStream
&stream
);
251 virtual void saveState(QDataStream
&stream
);
257 void pasteTo(const KUrl
&);
258 void reparseConfiguration();
265 class DolphinPartFileInfoExtension
: public KParts::FileInfoExtension
270 DolphinPartFileInfoExtension(DolphinPart
* part
);
272 virtual QueryModes
supportedQueryModes() const;
273 virtual bool hasSelection() const;
275 virtual KFileItemList
queryFor(QueryMode mode
) const;
277 DolphinPart
* part() const;
280 #endif /* DOLPHINPART_H */