1 | /*************************************************************************** |
2 | * Copyright (C) 2006 by Peter Penz <peter.penz19@gmail.com> * |
3 | * Copyright (C) 2006 by Stefan Monov <logixoul@gmail.com> * |
4 | * Copyright (C) 2006 by Cvetoslav Ludmiloff <ludmiloff@gmail.com> * |
5 | * * |
6 | * This program is free software; you can redistribute it and/or modify * |
7 | * it under the terms of the GNU General Public License as published by * |
8 | * the Free Software Foundation; either version 2 of the License, or * |
9 | * (at your option) any later version. * |
10 | * * |
11 | * This program is distributed in the hope that it will be useful, * |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
14 | * GNU General Public License for more details. * |
15 | * * |
16 | * You should have received a copy of the GNU General Public License * |
17 | * along with this program; if not, write to the * |
18 | * Free Software Foundation, Inc., * |
19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * |
20 | ***************************************************************************/ |
21 | |
22 | #ifndef DOLPHIN_MAINWINDOW_H |
23 | #define DOLPHIN_MAINWINDOW_H |
24 | |
25 | #include <config-baloo.h> |
26 | |
27 | #include <KFileItemDelegate> |
28 | #include <kio/fileundomanager.h> |
29 | #include <ksortablelist.h> |
30 | #include <kxmlguiwindow.h> |
31 | #include <KIcon> |
32 | |
33 | #include <QList> |
34 | #include <QWeakPointer> |
35 | |
36 | typedef KIO::FileUndoManager::CommandType CommandType; |
37 | |
38 | class DolphinViewActionHandler; |
39 | class DolphinApplication; |
40 | class DolphinSettingsDialog; |
41 | class DolphinViewContainer; |
42 | class DolphinRemoteEncoding; |
43 | class DolphinTabPage; |
44 | class KAction; |
45 | class KFileItem; |
46 | class KFileItemList; |
47 | class KJob; |
48 | class ; |
49 | class KTabBar; |
50 | class KUrl; |
51 | class QSplitter; |
52 | class QToolButton; |
53 | class QVBoxLayout; |
54 | |
55 | /** |
56 | * @short Main window for Dolphin. |
57 | * |
58 | * Handles the menus, toolbars and Dolphin views. |
59 | */ |
60 | class DolphinMainWindow: public KXmlGuiWindow |
61 | { |
62 | Q_OBJECT |
63 | Q_CLASSINFO("D-Bus Interface" , "org.kde.dolphin.MainWindow" ) |
64 | Q_PROPERTY(int id READ getId SCRIPTABLE true) |
65 | friend class DolphinApplication; |
66 | |
67 | public: |
68 | DolphinMainWindow(); |
69 | virtual ~DolphinMainWindow(); |
70 | |
71 | /** |
72 | * Returns the currently active view. |
73 | * All menu actions are applied to this view. When |
74 | * having a split view setup, the nonactive view |
75 | * is usually shown in darker colors. |
76 | */ |
77 | DolphinViewContainer* activeViewContainer() const; |
78 | |
79 | /** |
80 | * Opens each directory in \p dirs in a separate tab. If the "split view" |
81 | * option is enabled, 2 directories are collected within one tab. |
82 | */ |
83 | void openDirectories(const QList<KUrl>& dirs); |
84 | |
85 | /** |
86 | * Opens the directory which contains the files \p files |
87 | * and selects all files (implements the --select option |
88 | * of Dolphin). |
89 | */ |
90 | void openFiles(const QList<KUrl>& files); |
91 | |
92 | /** |
93 | * Returns the 'Create New...' sub menu which also can be shared |
94 | * with other menus (e. g. a context menu). |
95 | */ |
96 | KNewFileMenu* newFileMenu() const; |
97 | |
98 | public slots: |
99 | /** |
100 | * Pastes the clipboard data into the currently selected folder |
101 | * of the active view. If not exactly one folder is selected, |
102 | * no pasting is done at all. |
103 | */ |
104 | void pasteIntoFolder(); |
105 | |
106 | /** |
107 | * Returns the main window ID used through DBus. |
108 | */ |
109 | int getId() const; |
110 | |
111 | /** |
112 | * Implementation of the MainWindowAdaptor/QDBusAbstractAdaptor interface. |
113 | * Inform all affected dolphin components (panels, views) of an URL |
114 | * change. |
115 | */ |
116 | void changeUrl(const KUrl& url); |
117 | |
118 | /** |
119 | * The current directory of the Terminal Panel has changed, probably because |
120 | * the user entered a 'cd' command. This slot calls changeUrl(url) and makes |
121 | * sure that the panel keeps the keyboard focus. |
122 | */ |
123 | void slotTerminalDirectoryChanged(const KUrl& url); |
124 | |
125 | /** Stores all settings and quits Dolphin. */ |
126 | void quit(); |
127 | |
128 | signals: |
129 | /** |
130 | * Is sent if the selection of the currently active view has |
131 | * been changed. |
132 | */ |
133 | void selectionChanged(const KFileItemList& selection); |
134 | |
135 | /** |
136 | * Is sent if the url of the currently active view has |
137 | * been changed. |
138 | */ |
139 | void urlChanged(const KUrl& url); |
140 | |
141 | /** |
142 | * Is emitted if information of an item is requested to be shown e. g. in the panel. |
143 | * If item is null, no item information request is pending. |
144 | */ |
145 | void requestItemInfo(const KFileItem& item); |
146 | |
147 | /** |
148 | * Is emitted if the settings have been changed. |
149 | */ |
150 | void settingsChanged(); |
151 | |
152 | /** |
153 | * Is emitted when a tab has been closed. |
154 | */ |
155 | void rememberClosedTab(const KUrl& primaryUrl, const KUrl& secondaryUrl); |
156 | |
157 | protected: |
158 | /** @see QWidget::showEvent() */ |
159 | virtual void showEvent(QShowEvent* event); |
160 | |
161 | /** @see QMainWindow::closeEvent() */ |
162 | virtual void closeEvent(QCloseEvent* event); |
163 | |
164 | /** @see KMainWindow::saveProperties() */ |
165 | virtual void saveProperties(KConfigGroup& group); |
166 | |
167 | /** @see KMainWindow::readProperties() */ |
168 | virtual void readProperties(const KConfigGroup& group); |
169 | |
170 | private slots: |
171 | /** |
172 | * Refreshes the views of the main window by recreating them according to |
173 | * the given Dolphin settings. |
174 | */ |
175 | void refreshViews(); |
176 | |
177 | void clearStatusBar(); |
178 | |
179 | /** Updates the 'Create New...' sub menu. */ |
180 | void updateNewMenu(); |
181 | |
182 | void createDirectory(); |
183 | |
184 | /** Shows the error message in the status bar of the active view. */ |
185 | void showErrorMessage(const QString& message); |
186 | |
187 | /** |
188 | * Updates the state of the 'Undo' menu action dependent |
189 | * on the parameter \a available. |
190 | */ |
191 | void slotUndoAvailable(bool available); |
192 | |
193 | /** Sets the text of the 'Undo' menu action to \a text. */ |
194 | void slotUndoTextChanged(const QString& text); |
195 | |
196 | /** Performs the current undo operation. */ |
197 | void undo(); |
198 | |
199 | /** |
200 | * Copies all selected items to the clipboard and marks |
201 | * the items as cut. |
202 | */ |
203 | void cut(); |
204 | |
205 | /** Copies all selected items to the clipboard. */ |
206 | void copy(); |
207 | |
208 | /** Pastes the clipboard data to the active view. */ |
209 | void paste(); |
210 | |
211 | /** Replaces the URL navigator by a search box to find files. */ |
212 | void find(); |
213 | |
214 | /** |
215 | * Updates the text of the paste action dependent on |
216 | * the number of items which are in the clipboard. |
217 | */ |
218 | void updatePasteAction(); |
219 | |
220 | /** Selects all items from the active view. */ |
221 | void selectAll(); |
222 | |
223 | /** |
224 | * Inverts the selection of all items of the active view: |
225 | * Selected items get nonselected and nonselected items get |
226 | * selected. |
227 | */ |
228 | void invertSelection(); |
229 | |
230 | /** |
231 | * Switches between one and two views: |
232 | * If one view is visible, it will get split into two views. |
233 | * If already two views are visible, the active view gets closed. |
234 | */ |
235 | void toggleSplitView(); |
236 | |
237 | /** Reloads the currently active view. */ |
238 | void reloadView(); |
239 | |
240 | /** Stops the loading process for the currently active view. */ |
241 | void stopLoading(); |
242 | |
243 | void enableStopAction(); |
244 | void disableStopAction(); |
245 | |
246 | void showFilterBar(); |
247 | |
248 | /** |
249 | * Toggles between edit and browse mode of the navigation bar. |
250 | */ |
251 | void toggleEditLocation(); |
252 | |
253 | /** |
254 | * Switches to the edit mode of the navigation bar and selects |
255 | * the whole URL, so that it can be replaced by the user. If the edit mode is |
256 | * already active, it is assured that the navigation bar get focused. |
257 | */ |
258 | void replaceLocation(); |
259 | |
260 | /** |
261 | * Toggles the state of the panels between a locked and unlocked layout. |
262 | */ |
263 | void togglePanelLockState(); |
264 | |
265 | /** |
266 | * Is invoked if the Places panel got visible/invisible and takes care |
267 | * that the places-selector of all views is only shown if the Places panel |
268 | * is invisible. |
269 | */ |
270 | void slotPlacesPanelVisibilityChanged(bool visible); |
271 | |
272 | /** Goes back one step of the URL history. */ |
273 | void goBack(); |
274 | |
275 | /** Goes forward one step of the URL history. */ |
276 | void goForward(); |
277 | |
278 | /** Goes up one hierarchy of the current URL. */ |
279 | void goUp(); |
280 | |
281 | /** Changes the location to the home URL. */ |
282 | void goHome(); |
283 | |
284 | /** |
285 | * Open the previous URL in the URL history in a new tab |
286 | * if the middle mouse button is clicked. |
287 | */ |
288 | void goBack(Qt::MouseButtons buttons); |
289 | |
290 | /** |
291 | * Open the next URL in the URL history in a new tab |
292 | * if the middle mouse button is clicked. |
293 | */ |
294 | void goForward(Qt::MouseButtons buttons); |
295 | |
296 | /** |
297 | * Open the URL one hierarchy above the current URL in a new tab |
298 | * if the middle mouse button is clicked. |
299 | */ |
300 | void goUp(Qt::MouseButtons buttons); |
301 | |
302 | /** |
303 | * Open the home URL in a new tab |
304 | */ |
305 | void goHome(Qt::MouseButtons buttons); |
306 | |
307 | /** Opens Kompare for 2 selected files. */ |
308 | void compareFiles(); |
309 | |
310 | /** |
311 | * Hides the menu bar if it is visible, makes the menu bar |
312 | * visible if it is hidden. |
313 | */ |
314 | void toggleShowMenuBar(); |
315 | |
316 | /** Opens a terminal window for the current location. */ |
317 | void openTerminal(); |
318 | |
319 | /** Opens the settings dialog for Dolphin. */ |
320 | void editSettings(); |
321 | |
322 | /** Updates the state of the 'Show Full Location' action. */ |
323 | void slotEditableStateChanged(bool editable); |
324 | |
325 | /** |
326 | * Updates the state of the 'Edit' menu actions and emits |
327 | * the signal selectionChanged(). |
328 | */ |
329 | void slotSelectionChanged(const KFileItemList& selection); |
330 | |
331 | /** Emits the signal requestItemInfo(). */ |
332 | void slotRequestItemInfo(const KFileItem&); |
333 | |
334 | /** |
335 | * Updates the state of the 'Back' and 'Forward' menu |
336 | * actions corresponding to the current history. |
337 | */ |
338 | void updateHistory(); |
339 | |
340 | /** Updates the state of the 'Show filter bar' menu action. */ |
341 | void updateFilterBarAction(bool show); |
342 | |
343 | /** Open a new main window. */ |
344 | void openNewMainWindow(); |
345 | |
346 | /** Opens a new view with the current URL that is part of a tab. */ |
347 | void openNewTab(); |
348 | |
349 | /** |
350 | * Opens a new tab in the background showing the URL \a primaryUrl and the |
351 | * optional URL \a secondaryUrl. |
352 | */ |
353 | void openNewTab(const KUrl& primaryUrl, const KUrl& secondaryUrl = KUrl()); |
354 | |
355 | /** |
356 | * Opens a new tab showing the URL \a primaryUrl and the optional URL |
357 | * \a secondaryUrl and activates the tab. |
358 | */ |
359 | void openNewActivatedTab(const KUrl& primaryUrl, const KUrl& secondaryUrl = KUrl()); |
360 | |
361 | void activateNextTab(); |
362 | |
363 | void activatePrevTab(); |
364 | |
365 | /** |
366 | * Opens the selected folder in a new tab. |
367 | */ |
368 | void openInNewTab(); |
369 | |
370 | /** |
371 | * Opens the selected folder in a new window. |
372 | */ |
373 | void openInNewWindow(); |
374 | |
375 | /** |
376 | * Indicates in the statusbar that the execution of the command \a command |
377 | * has been finished. |
378 | */ |
379 | void showCommand(CommandType command); |
380 | |
381 | /** |
382 | * Activates the tab with the index \a index, which means that the current view |
383 | * is replaced by the view of the given tab. |
384 | */ |
385 | void setActiveTab(int index); |
386 | |
387 | /** Closes the currently active tab. */ |
388 | void closeTab(); |
389 | |
390 | /** |
391 | * Closes the tab with the index \a index and activates the tab with index - 1. |
392 | */ |
393 | void closeTab(int index); |
394 | |
395 | /** |
396 | * Opens a context menu for the tab with the index \a index |
397 | * on the position \a pos. |
398 | */ |
399 | void openTabContextMenu(int index, const QPoint& pos); |
400 | |
401 | /** |
402 | * Is connected to the QTabBar signal tabMoved(int from, int to). |
403 | * Reorders the list of tabs after a tab was moved in the tab bar |
404 | * and sets m_tabIndex to the new index of the current tab. |
405 | */ |
406 | void slotTabMoved(int from, int to); |
407 | |
408 | /** |
409 | * Is connected to the KTabBar signal testCanDecode() and adjusts |
410 | * the output parameter \a accept. |
411 | */ |
412 | void slotTestCanDecode(const QDragMoveEvent* event, bool& accept); |
413 | |
414 | /** |
415 | * If the URL can be listed, open it in the current view, otherwise |
416 | * run it through KRun. |
417 | */ |
418 | void handleUrl(const KUrl& url); |
419 | |
420 | /** |
421 | * handleUrl() can trigger a stat job to see if the url can actually |
422 | * be listed. |
423 | */ |
424 | void slotHandleUrlStatFinished(KJob* job); |
425 | |
426 | /** |
427 | * Is connected to the KTabBar signal receivedDropEvent. |
428 | * Allows dragging and dropping files onto tabs. |
429 | */ |
430 | void tabDropEvent(int tab, QDropEvent* event); |
431 | |
432 | /** |
433 | * Is invoked when the write state of a folder has been changed and |
434 | * enables/disables the "Create New..." menu entry. |
435 | */ |
436 | void slotWriteStateChanged(bool isFolderWritable); |
437 | |
438 | /** |
439 | * Opens the context menu on the current mouse position. |
440 | * @pos Position in screen coordinates. |
441 | * @item File item context. If item is null, the context menu |
442 | * should be applied to \a url. |
443 | * @url URL which contains \a item. |
444 | * @customActions Actions that should be added to the context menu, |
445 | * if the file item is null. |
446 | */ |
447 | void openContextMenu(const QPoint& pos, |
448 | const KFileItem& item, |
449 | const KUrl& url, |
450 | const QList<QAction*>& customActions); |
451 | |
452 | void updateControlMenu(); |
453 | void updateToolBar(); |
454 | void slotControlButtonDeleted(); |
455 | |
456 | /** |
457 | * Is called if a panel emits an error-message and shows |
458 | * the error-message in the active view-container. |
459 | */ |
460 | void slotPanelErrorMessage(const QString& error); |
461 | |
462 | /** |
463 | * Is called if the user clicked an item in the Places Panel. |
464 | * Reloads the view if \a url is the current URL already, and changes the |
465 | * current URL otherwise. |
466 | */ |
467 | void slotPlaceActivated(const KUrl& url); |
468 | |
469 | void activeViewChanged(); |
470 | |
471 | private: |
472 | /** |
473 | * Activates the given view, which means that |
474 | * all menu actions are applied to this view. When |
475 | * having a split view setup, the nonactive view |
476 | * is usually shown in darker colors. |
477 | */ |
478 | void setActiveViewContainer(DolphinViewContainer* view); |
479 | |
480 | void setupActions(); |
481 | void setupDockWidgets(); |
482 | void updateEditActions(); |
483 | void updateViewActions(); |
484 | void updateGoActions(); |
485 | |
486 | void createControlButton(); |
487 | void deleteControlButton(); |
488 | |
489 | /** |
490 | * Adds the action \p action to the menu \p menu in |
491 | * case if it has not added already to the toolbar. |
492 | * @return True if the action has been added to the menu. |
493 | */ |
494 | bool addActionToMenu(QAction* action, KMenu* ); |
495 | |
496 | /** |
497 | * Connects the signals from the created DolphinView with |
498 | * the DolphinViewContainer \a container with the corresponding slots of |
499 | * the DolphinMainWindow. This method must be invoked each |
500 | * time a DolphinView has been created. |
501 | */ |
502 | void connectViewSignals(DolphinViewContainer* container); |
503 | |
504 | /** |
505 | * Updates the text of the split action: |
506 | * If two views are shown, the text is set to "Split", |
507 | * otherwise the text is set to "Join". The icon |
508 | * is updated to match with the text and the currently active view. |
509 | */ |
510 | void updateSplitAction(); |
511 | |
512 | /** Returns the name of the tab for the URL \a url. */ |
513 | QString tabName(const KUrl& url) const; |
514 | |
515 | |
516 | bool isKompareInstalled() const; |
517 | |
518 | /** |
519 | * Sets the window caption to url.fileName() if this is non-empty, |
520 | * "/" if the URL is "file:///", and url.protocol() otherwise. |
521 | */ |
522 | void setUrlAsCaption(const KUrl& url); |
523 | |
524 | QString squeezedText(const QString& text) const; |
525 | |
526 | /** |
527 | * Creates an action for showing/hiding a panel, that is accessible |
528 | * in "Configure toolbars..." and "Configure shortcuts...". This is necessary |
529 | * as the action for toggling the dock visibility is done by Qt which |
530 | * is no KAction instance. |
531 | */ |
532 | void createPanelAction(const KIcon& icon, |
533 | const QKeySequence& shortcut, |
534 | QAction* dockAction, |
535 | const QString& actionName); |
536 | |
537 | private: |
538 | /** |
539 | * Implements a custom error handling for the undo manager. This |
540 | * assures that all errors are shown in the status bar of Dolphin |
541 | * instead as modal error dialog with an OK button. |
542 | */ |
543 | class UndoUiInterface : public KIO::FileUndoManager::UiInterface |
544 | { |
545 | public: |
546 | UndoUiInterface(); |
547 | virtual ~UndoUiInterface(); |
548 | virtual void jobError(KIO::Job* job); |
549 | }; |
550 | |
551 | KNewFileMenu* m_newFileMenu; |
552 | KTabBar* m_tabBar; |
553 | DolphinViewContainer* m_activeViewContainer; |
554 | QVBoxLayout* m_centralWidgetLayout; |
555 | int m_id; |
556 | |
557 | int m_tabIndex; |
558 | QList<DolphinTabPage*> m_viewTab; |
559 | |
560 | DolphinViewActionHandler* m_actionHandler; |
561 | DolphinRemoteEncoding* m_remoteEncoding; |
562 | QWeakPointer<DolphinSettingsDialog> m_settingsDialog; |
563 | |
564 | // Members for the toolbar menu that is shown when the menubar is hidden: |
565 | QToolButton* m_controlButton; |
566 | QTimer* m_updateToolBarTimer; |
567 | |
568 | KIO::Job* m_lastHandleUrlStatJob; |
569 | }; |
570 | |
571 | inline DolphinViewContainer* DolphinMainWindow::activeViewContainer() const |
572 | { |
573 | return m_activeViewContainer; |
574 | } |
575 | |
576 | inline KNewFileMenu* DolphinMainWindow::newFileMenu() const |
577 | { |
578 | return m_newFileMenu; |
579 | } |
580 | |
581 | inline int DolphinMainWindow::getId() const |
582 | { |
583 | return m_id; |
584 | } |
585 | |
586 | #endif // DOLPHIN_MAINWINDOW_H |
587 | |
588 | |