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