]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinpart.h
dolphinpart: port to new KPluginMetaData-based KParts API
[dolphin.git] / src / dolphinpart.h
1 /* This file is part of the KDE project
2 SPDX-FileCopyrightText: 2007 David Faure <faure@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6
7 #ifndef DOLPHINPART_H
8 #define DOLPHINPART_H
9
10 #include <KParts/ReadOnlyPart>
11
12 #include <QUrl>
13
14 class DolphinNewFileMenu;
15 class DolphinViewActionHandler;
16 class QActionGroup;
17 class KFileItemList;
18 class KFileItem;
19 class DolphinPartBrowserExtension;
20 class DolphinRemoteEncoding;
21 class KDirLister;
22 class DolphinView;
23 class DolphinRemoveAction;
24
25 class DolphinPart : public KParts::ReadOnlyPart
26 {
27 Q_OBJECT
28 // Used by konqueror. Technically it means "we want undo enabled if
29 // there are things in the undo history and the current part is a dolphin part".
30 // Even though it's konqueror doing the undo...
31 Q_PROPERTY( bool supportsUndo READ supportsUndo )
32
33 Q_PROPERTY( QString currentViewMode READ currentViewMode WRITE setCurrentViewMode )
34
35 // Used by konqueror when typing something like /home/dfaure/*.diff in the location bar
36 Q_PROPERTY( QString nameFilter READ nameFilter WRITE setNameFilter )
37
38 // Used by konqueror to implement the --select command-line option
39 Q_PROPERTY( QList<QUrl> filesToSelect READ filesToSelect WRITE setFilesToSelect )
40
41 public:
42 explicit DolphinPart(QWidget* parentWidget, QObject* parent,
43 const KPluginMetaData& metaData, const QVariantList& args);
44 ~DolphinPart() override;
45
46 /**
47 * Standard KParts::ReadOnlyPart openUrl method.
48 * Called by Konqueror to view a directory in DolphinPart.
49 */
50 bool openUrl(const QUrl& url) override;
51
52 /// see the supportsUndo property
53 bool supportsUndo() const { return true; }
54
55 /**
56 * Used by konqueror for setting the view mode
57 * @param viewModeName internal name for the view mode, like "icons"
58 * Those names come from the Actions line in dolphinpart.desktop,
59 * and have to match the name of the KActions.
60 */
61 void setCurrentViewMode(const QString& viewModeName);
62
63 /**
64 * Used by konqueror for displaying the current view mode.
65 * @see setCurrentViewMode
66 */
67 QString currentViewMode() const;
68
69 /// Returns the view owned by this part; used by DolphinPartBrowserExtension
70 DolphinView* view() { return m_view; }
71
72 /**
73 * Sets a name filter, like *.diff
74 */
75 void setNameFilter(const QString& nameFilter);
76
77 /**
78 * Returns the current name filter. Used by konqueror to show it in the URL.
79 */
80 QString nameFilter() const { return m_nameFilter; }
81
82 protected:
83 /**
84 * We reimplement openUrl so no need to implement openFile.
85 */
86 bool openFile() override { return true; }
87
88 Q_SIGNALS:
89 /**
90 * Emitted when the view mode changes. Used by konqueror.
91 */
92 void viewModeChanged();
93
94
95 /**
96 * Emitted whenever the current URL is about to be changed.
97 */
98 void aboutToOpenURL();
99
100 private Q_SLOTS:
101 void slotMessage(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 slotItemActivated(const KFileItem& item);
112 /**
113 * Handles activation of multiple items
114 */
115 void slotItemsActivated(const KFileItemList& items);
116 /**
117 * Creates a new window showing the content of \a url.
118 */
119 void createNewWindow(const QUrl &url);
120 /**
121 * Opens the context menu on the current mouse position.
122 * @pos Position in screen coordinates.
123 * @item File item context. If item is null, the context menu
124 * should be applied to \a url.
125 * @url URL which contains \a item.
126 * @customActions Actions that should be added to the context menu,
127 * if the file item is null.
128 */
129 void slotOpenContextMenu(const QPoint& pos,
130 const KFileItem& item,
131 const QUrl& url,
132 const QList<QAction*>& customActions);
133
134 /**
135 * Informs the host that we are opening \a url (e.g. after a redirection
136 * coming from KDirLister).
137 * Testcase 1: fish://localhost
138 * Testcase 2: showing a directory that is being renamed by another window (#180156)
139 */
140 void slotDirectoryRedirection(const QUrl& oldUrl, const QUrl& newUrl);
141
142 /**
143 * Updates the state of the 'Edit' menu actions and emits
144 * the signal selectionChanged().
145 */
146 void slotSelectionChanged(const KFileItemList& selection);
147
148 /**
149 * Updates the text of the paste action dependent from
150 * the number of items which are in the clipboard.
151 */
152 void updatePasteAction();
153
154 /**
155 * Connected to all "Go" menu actions provided by DolphinPart
156 */
157 void slotGoTriggered(QAction* action);
158
159 /**
160 * Connected to the "editMimeType" action
161 */
162 void slotEditMimeType();
163
164 /**
165 * Connected to the "select_items_matching" action.
166 * Opens a dialog which permits to select all items matching a pattern like "*.jpg".
167 */
168 void slotSelectItemsMatchingPattern();
169
170 /**
171 * Connected to the "unselect_items_matching" action.
172 * Opens a dialog which permits to unselect all items matching a pattern like "*.jpg".
173 */
174 void slotUnselectItemsMatchingPattern();
175
176 /**
177 * Open a terminal window, starting with the current directory.
178 */
179 void slotOpenTerminal();
180
181 /**
182 * Open preferred search tool in the current directory to find files.
183 */
184 void slotFindFile();
185
186 /**
187 * Updates the 'Create New...' sub menu, just before it's shown.
188 */
189 void updateNewMenu();
190
191 /**
192 * Updates the number of items (= number of files + number of
193 * directories) in the statusbar. If files are selected, the number
194 * of selected files and the sum of the filesize is shown.
195 */
196 void updateStatusBar();
197
198 /**
199 * Notify container of folder loading progress.
200 */
201 void updateProgress(int percent);
202
203 void createDirectory();
204
205 /**
206 * Called by konqueror --select
207 */
208 void setFilesToSelect(const QList<QUrl> &files);
209 QList<QUrl> filesToSelect() const { return QList<QUrl>(); } // silence moc
210
211 bool eventFilter(QObject*, QEvent*) override;
212
213 private:
214 void createActions();
215 void createGoAction(const char* name, const char* iconName,
216 const QString& text, const QString& url,
217 QActionGroup* actionGroup);
218
219 void openSelectionDialog(const QString& title, const QString& text,
220 bool selectItems);
221
222 private:
223 DolphinView* m_view;
224 DolphinViewActionHandler* m_actionHandler;
225 DolphinRemoteEncoding* m_remoteEncoding;
226 DolphinPartBrowserExtension* m_extension;
227 DolphinNewFileMenu* m_newFileMenu;
228 QAction* m_findFileAction;
229 QAction* m_openTerminalAction;
230 QString m_nameFilter;
231 DolphinRemoveAction* m_removeAction;
232 Q_DISABLE_COPY(DolphinPart)
233 };
234
235 #endif /* DOLPHINPART_H */