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>
26 #include <QItemSelectionModel>
29 class DolphinViewActionHandler
;
34 class DolphinPartBrowserExtension
;
35 class DolphinSortFilterProxyModel
;
36 class DolphinRemoteEncoding
;
42 class DolphinPart
: public KParts::ReadOnlyPart
45 // Used by konqueror. Technically it means "we want undo enabled if
46 // there are things in the undo history and the current part is a dolphin part".
47 // Even though it's konqueror doing the undo...
48 Q_PROPERTY( bool supportsUndo READ supportsUndo
)
50 Q_PROPERTY( QString currentViewMode READ currentViewMode WRITE setCurrentViewMode
)
52 // Used by konqueror when typing something like /home/dfaure/*.diff in the location bar
53 Q_PROPERTY( QString nameFilter READ nameFilter WRITE setNameFilter
)
55 // Used by konqueror to implement the --select command-line option
56 Q_PROPERTY( KUrl::List filesToSelect READ filesToSelect WRITE setFilesToSelect
)
59 explicit DolphinPart(QWidget
* parentWidget
, QObject
* parent
, const QVariantList
& args
);
62 static KAboutData
* createAboutData();
65 * Standard KParts::ReadOnlyPart openUrl method.
66 * Called by Konqueror to view a directory in DolphinPart.
68 virtual bool openUrl(const KUrl
& url
);
70 /// see the supportsUndo property
71 bool supportsUndo() const { return true; }
74 * Used by konqueror for setting the view mode
75 * @param viewModeName internal name for the view mode, like "icons"
76 * Those names come from the Actions line in dolphinpart.desktop,
77 * and have to match the name of the KActions.
79 void setCurrentViewMode(const QString
& viewModeName
);
82 * Used by konqueror for displaying the current view mode.
83 * @see setCurrentViewMode
85 QString
currentViewMode() const;
87 /// Returns the view owned by this part; used by DolphinPartBrowserExtension
88 DolphinView
* view() { return m_view
; }
91 * Sets a name filter, like *.diff
93 void setNameFilter(const QString
& nameFilter
);
96 * Returns the current name filter. Used by konqueror to show it in the URL.
98 QString
nameFilter() const { return m_nameFilter
; }
102 * We reimplement openUrl so no need to implement openFile.
104 virtual bool openFile() { return true; }
108 * Emitted when the view mode changes. Used by konqueror.
110 void viewModeChanged();
114 * Emitted whenever the current URL is about to be changed.
116 void aboutToOpenURL();
119 void slotCompleted(const KUrl
& url
);
120 void slotCanceled(const KUrl
& url
);
121 void slotMessage(const QString
& msg
);
122 void slotErrorMessage(const QString
& msg
);
124 * Shows the information for the item \a item inside the statusbar. If the
125 * item is null, the default statusbar information is shown.
127 void slotRequestItemInfo(const KFileItem
& item
);
129 * Handles clicking on an item
131 void slotItemTriggered(const KFileItem
& item
);
133 * Creates a new window showing the content of \a url.
135 void createNewWindow(const KUrl
& url
);
137 * Opens the context menu on the current mouse position.
138 * @item File item context. If item is null, the context menu
139 * should be applied to \a url.
140 * @url URL which contains \a item.
141 * @customActions Actions that should be added to the context menu,
142 * if the file item is null.
144 void slotOpenContextMenu(const KFileItem
& item
,
146 const QList
<QAction
*>& customActions
);
149 * Informs the host that we are opening \a url (e.g. after a redirection
150 * coming from KDirLister).
151 * Testcase 1: fish://localhost
152 * Testcase 2: showing a directory that is being renamed by another window (#180156)
154 void slotRedirection(const KUrl
& oldUrl
, const KUrl
& newUrl
);
157 * Updates the state of the 'Edit' menu actions and emits
158 * the signal selectionChanged().
160 void slotSelectionChanged(const KFileItemList
& selection
);
163 * Updates the text of the paste action dependent from
164 * the number of items which are in the clipboard.
166 void updatePasteAction();
169 * Connected to all "Go" menu actions provided by DolphinPart
171 void slotGoTriggered(QAction
* action
);
174 * Connected to the "editMimeType" action
176 void slotEditMimeType();
179 * Connected to the "select_items_matching" action.
180 * Opens a dialog which permits to select all items matching a pattern like "*.jpg".
182 void slotSelectItemsMatchingPattern();
185 * Connected to the "unselect_items_matching" action.
186 * Opens a dialog which permits to unselect all items matching a pattern like "*.jpg".
188 void slotUnselectItemsMatchingPattern();
191 * Open a terminal window, starting with the current directory.
193 void slotOpenTerminal();
196 * Updates the 'Create New...' sub menu, just before it's shown.
198 void updateNewMenu();
201 * Updates the number of items (= number of files + number of
202 * directories) in the statusbar. If files are selected, the number
203 * of selected files and the sum of the filesize is shown.
205 void updateStatusBar();
208 * Notify container of folder loading progress.
210 void updateProgress(int percent
);
212 void createDirectory();
215 * Called by konqueror --select
217 void setFilesToSelect(const KUrl::List
& files
);
218 KUrl::List
filesToSelect() const { return KUrl::List(); } // silence moc
221 void createActions();
222 void createGoAction(const char* name
, const char* iconName
,
223 const QString
& text
, const QString
& url
,
224 QActionGroup
* actionGroup
);
226 void openSelectionDialog(const QString
& title
, const QString
& text
,
227 QItemSelectionModel::SelectionFlags command
);
229 QItemSelection
childrenMatchingPattern(const QModelIndex
& parent
, const QRegExp
& patternRegExp
);
233 DolphinViewActionHandler
* m_actionHandler
;
234 DolphinRemoteEncoding
* m_remoteEncoding
;
235 KDirLister
* m_dirLister
;
236 DolphinModel
* m_dolphinModel
;
237 DolphinSortFilterProxyModel
* m_proxyModel
;
238 DolphinPartBrowserExtension
* m_extension
;
239 KNewFileMenu
* m_newMenu
;
240 QString m_nameFilter
;
241 Q_DISABLE_COPY(DolphinPart
)
244 class DolphinPartBrowserExtension
: public KParts::BrowserExtension
248 DolphinPartBrowserExtension( DolphinPart
* part
)
249 : KParts::BrowserExtension( part
), m_part(part
) {}
251 virtual void restoreState(QDataStream
&stream
);
252 virtual void saveState(QDataStream
&stream
);
258 void pasteTo(const KUrl
&);
259 void reparseConfiguration();
265 #endif /* DOLPHINPART_H */