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