dolphinmainwindow.h 20.2 KB
Newer Older
1
/***************************************************************************
2
 *   Copyright (C) 2006 by Peter Penz <peter.penz19@gmail.com>             *
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
 *   Copyright (C) 2006 by Stefan Monov <logixoul@gmail.com>               *
 *   Copyright (C) 2006 by Cvetoslav Ludmiloff <ludmiloff@gmail.com>       *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
19
 *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
20 21
 ***************************************************************************/

22 23
#ifndef DOLPHIN_MAINWINDOW_H
#define DOLPHIN_MAINWINDOW_H
24

25
#include "dolphintabwidget.h"
Vishesh Handa's avatar
Vishesh Handa committed
26
#include <config-baloo.h>
27
#include <kio/fileundomanager.h>
28
#include <KSortableList>
29
#include <kxmlguiwindow.h>
30

Roman Inflianskas's avatar
Roman Inflianskas committed
31
#include <QIcon>
32
#include <QList>
33
#include <QMenu>
34
#include <QPointer>
Roman Inflianskas's avatar
Roman Inflianskas committed
35
#include <QUrl>
David Hallas's avatar
David Hallas committed
36
#include <QVector>
37

38 39
typedef KIO::FileUndoManager::CommandType CommandType;

David Hallas's avatar
David Hallas committed
40
class DolphinBookmarkHandler;
41
class DolphinViewActionHandler;
42
class DolphinSettingsDialog;
43
class DolphinViewContainer;
Rahman Duran's avatar
Rahman Duran committed
44
class DolphinRemoteEncoding;
45
class DolphinTabWidget;
46 47
class KFileItem;
class KFileItemList;
48
class KJob;
49
class KNewFileMenu;
50
class KHelpMenu;
51
class KToolBarPopupAction;
52
class QToolButton;
53
class QIcon;
54 55
class PlacesPanel;
class TerminalPanel;
56 57 58 59 60

/**
 * @short Main window for Dolphin.
 *
 * Handles the menus, toolbars and Dolphin views.
61
 */
62
class DolphinMainWindow: public KXmlGuiWindow
63 64
{
    Q_OBJECT
65 66
    Q_CLASSINFO("D-Bus Interface", "org.kde.dolphin.MainWindow")

67
public:
68
    DolphinMainWindow();
69
    ~DolphinMainWindow() override;
70

71
    /**
72 73 74
     * Returns the currently active view.
     * All menu actions are applied to this view. When
     * having a split view setup, the nonactive view
75 76
     * is usually shown in darker colors.
     */
77
    DolphinViewContainer* activeViewContainer() const;
78

David Hallas's avatar
David Hallas committed
79 80 81 82 83
    /**
     * Returns view container for all tabs
     */
    QVector<DolphinViewContainer*> viewContainers() const;

84
    /**
85 86 87
     * Opens each directory in \p dirs in a separate tab. If \a splitView is set,
     * 2 directories are collected within one tab.
     * \pre \a dirs must contain at least one url.
88
     */
89
    void openDirectories(const QList<QUrl> &dirs, bool splitView);
90

91
    /**
92 93 94
     * Opens the directories which contain the files \p files and selects all files.
     * If \a splitView is set, 2 directories are collected within one tab.
     * \pre \a files must contain at least one url.
95
     */
96
    void openFiles(const QList<QUrl>& files, bool splitView);
97

98 99 100 101
    /**
     * Returns the 'Create New...' sub menu which also can be shared
     * with other menus (e. g. a context menu).
     */
Peter Penz's avatar
Peter Penz committed
102
    KNewFileMenu* newFileMenu() const;
103

104 105
    void setTabsToHomeIfMountPathOpen(const QString& mountPath);

106
public slots:
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
    /**
     * Opens each directory in \p dirs in a separate tab. If \a splitView is set,
     * 2 directories are collected within one tab.
     * \pre \a dirs must contain at least one url.
     *
     * @note this function is overloaded so that it is callable via DBus.
     */
    void openDirectories(const QStringList &dirs, bool splitView);

    /**
     * Opens the directories which contain the files \p files and selects all files.
     * If \a splitView is set, 2 directories are collected within one tab.
     * \pre \a files must contain at least one url.
     *
     * @note this is overloaded so that this function is callable via DBus.
     */
    void openFiles(const QStringList &files, bool splitView);

    /**
     * Tries to raise/activate the Dolphin window.
     */
    void activateWindow();

    /**
     * Determines if a URL is open in any tab.
     * @note Use of QString instead of QUrl is required to be callable via DBus.
     *
     * @param url URL to look for
     * @returns true if url is currently open in a tab, false otherwise.
     */
    bool isUrlOpen(const QString &url);


140 141 142 143 144 145 146
    /**
     * Pastes the clipboard data into the currently selected folder
     * of the active view. If not exactly one folder is selected,
     * no pasting is done at all.
     */
    void pasteIntoFolder();

147
    /**
148
     * Implementation of the MainWindowAdaptor/QDBusAbstractAdaptor interface.
149
     * Inform all affected dolphin components (panels, views) of an URL
150 151
     * change.
     */
Lukáš Tinkl's avatar
Lukáš Tinkl committed
152
    void changeUrl(const QUrl& url);
153

154 155 156 157 158
    /**
     * The current directory of the Terminal Panel has changed, probably because
     * the user entered a 'cd' command. This slot calls changeUrl(url) and makes
     * sure that the panel keeps the keyboard focus.
     */
Lukáš Tinkl's avatar
Lukáš Tinkl committed
159
    void slotTerminalDirectoryChanged(const QUrl& url);
160

161 162 163
    /** Stores all settings and quits Dolphin. */
    void quit();

David Hallas's avatar
David Hallas committed
164 165 166 167 168 169 170 171 172 173
    /**
     * Opens a new tab and places it after the current tab
     */
    void openNewTabAfterCurrentTab(const QUrl& url);

    /**
     * Opens a new tab and places it as the last tab
     */
    void openNewTabAfterLastTab(const QUrl& url);

174 175
signals:
    /**
176
     * Is sent if the selection of the currently active view has
177 178
     * been changed.
     */
179
    void selectionChanged(const KFileItemList& selection);
180 181 182 183 184

    /**
     * Is sent if the url of the currently active view has
     * been changed.
     */
Lukáš Tinkl's avatar
Lukáš Tinkl committed
185
    void urlChanged(const QUrl& url);
186

Peter Penz's avatar
Peter Penz committed
187
    /**
188
     * Is emitted if information of an item is requested to be shown e. g. in the panel.
189
     * If item is null, no item information request is pending.
Peter Penz's avatar
Peter Penz committed
190
     */
191
    void requestItemInfo(const KFileItem& item);
Peter Penz's avatar
Peter Penz committed
192

193 194 195 196 197
    /**
     * Is emitted if the settings have been changed.
     */
    void settingsChanged();

198
protected:
199
    /** @see QWidget::showEvent() */
200
    void showEvent(QShowEvent* event) override;
201

Peter Penz's avatar
Peter Penz committed
202
    /** @see QMainWindow::closeEvent() */
203
    void closeEvent(QCloseEvent* event) override;
204

Peter Penz's avatar
Peter Penz committed
205
    /** @see KMainWindow::saveProperties() */
206
    void saveProperties(KConfigGroup& group) override;
207

Peter Penz's avatar
Peter Penz committed
208
    /** @see KMainWindow::readProperties() */
209
    void readProperties(const KConfigGroup& group) override;
210

211 212 213 214 215
    /** Handles QWhatsThisClickedEvent and passes all others on. */
    bool event(QEvent* event) override;
    /** Handles QWhatsThisClickedEvent and passes all others on. */
    bool eventFilter(QObject*, QEvent*) override;

216
private slots:
217 218 219 220 221 222
    /**
     * Refreshes the views of the main window by recreating them according to
     * the given Dolphin settings.
     */
    void refreshViews();

223
    void clearStatusBar();
David Faure's avatar
David Faure committed
224

225 226
    /** Updates the 'Create New...' sub menu. */
    void updateNewMenu();
227

228 229
    void createDirectory();

230 231 232
    /** Shows the error message in the status bar of the active view. */
    void showErrorMessage(const QString& message);

233 234
    /**
     * Updates the state of the 'Undo' menu action dependent
235
     * on the parameter \a available.
236 237 238 239 240 241
     */
    void slotUndoAvailable(bool available);

    /** Sets the text of the 'Undo' menu action to \a text. */
    void slotUndoTextChanged(const QString& text);

242 243 244
    /** Performs the current undo operation. */
    void undo();

245 246
    /**
     * Copies all selected items to the clipboard and marks
247
     * the items as cut.
248 249 250 251 252 253 254 255 256
     */
    void cut();

    /** Copies all selected items to the clipboard. */
    void copy();

    /** Pastes the clipboard data to the active view. */
    void paste();

257 258 259
    /** Replaces the URL navigator by a search box to find files. */
    void find();

260 261 262
    /** Updates the state of the search action according to the view container. */
    void updateSearchAction();

263
    /**
264
     * Updates the text of the paste action dependent on
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281
     * the number of items which are in the clipboard.
     */
    void updatePasteAction();

    /** Selects all items from the active view. */
    void selectAll();

    /**
     * Inverts the selection of all items of the active view:
     * Selected items get nonselected and nonselected items get
     * selected.
     */
    void invertSelection();

    /**
     * Switches between one and two views:
     * If one view is visible, it will get split into two views.
282
     * If already two views are visible, the active view gets closed.
283 284 285
     */
    void toggleSplitView();

arnav dhamija's avatar
arnav dhamija committed
286
    /** Dedicated action to open the stash:/ ioslave in split view. */
287 288
    void toggleSplitStash();

289
    /** Reloads the currently active view. */
290 291
    void reloadView();

292
    /** Stops the loading process for the currently active view. */
293 294
    void stopLoading();

295 296 297
    void enableStopAction();
    void disableStopAction();

298
    void showFilterBar();
299 300

    /**
301
     * Toggles between edit and browse mode of the navigation bar.
302 303 304 305
     */
    void toggleEditLocation();

    /**
306 307
     * Switches to the edit mode of the navigation bar and selects
     * the whole URL, so that it can be replaced by the user. If the edit mode is
308 309
     * already active, it is assured that the navigation bar get focused.
     */
310
    void replaceLocation();
311

312 313 314 315 316
    /**
     * Toggles the state of the panels between a locked and unlocked layout.
     */
    void togglePanelLockState();

317 318 319 320 321 322
    /**
     * Is invoked if the Terminal panel got visible/invisible and takes care
     * that the active view has the focus if the Terminal panel is invisible.
     */
    void slotTerminalPanelVisibilityChanged();

323
    /** Goes back one step of the URL history. */
324 325
    void goBack();

326
    /** Goes forward one step of the URL history. */
327 328
    void goForward();

329
    /** Goes up one hierarchy of the current URL. */
330 331
    void goUp();

Peter Penz's avatar
Peter Penz committed
332 333 334
    /** Changes the location to the home URL. */
    void goHome();

335 336
    /** Open the previous URL in the URL history in a new tab. */
    void goBackInNewTab();
337

338 339
    /** Open the next URL in the URL history in a new tab. */
    void goForwardInNewTab();
340

341 342
    /** Open the URL one hierarchy above the current URL in a new tab. */
    void goUpInNewTab();
343

344 345
    /** * Open the home URL in a new tab. */
    void goHomeInNewTab();
346

347 348 349
    /** Opens Kompare for 2 selected files. */
    void compareFiles();

Peter Penz's avatar
Peter Penz committed
350 351 352 353 354 355
    /**
     * Hides the menu bar if it is visible, makes the menu bar
     * visible if it is hidden.
     */
    void toggleShowMenuBar();

356 357 358 359 360 361
    /** Updates "Open Preferred Search Tool" action. */
    void updateOpenPreferredSearchToolAction();

    /** Opens preferred search tool for the current location. */
    void openPreferredSearchTool();

362 363 364
    /** Opens a terminal window for the current location. */
    void openTerminal();

365 366 367
    /** Focus a Terminal Panel. */
    void focusTerminalPanel();

368 369 370
    /** Opens the settings dialog for Dolphin. */
    void editSettings();

371 372 373
    /** Updates the state of the 'Show Full Location' action. */
    void slotEditableStateChanged(bool editable);

Peter Penz's avatar
Peter Penz committed
374 375 376 377
    /**
     * Updates the state of the 'Edit' menu actions and emits
     * the signal selectionChanged().
     */
378
    void slotSelectionChanged(const KFileItemList& selection);
379 380 381

    /**
     * Updates the state of the 'Back' and 'Forward' menu
382
     * actions corresponding to the current history.
383
     */
384
    void updateHistory();
385 386 387 388 389 390

    /** Updates the state of the 'Show filter bar' menu action. */
    void updateFilterBarAction(bool show);

    /** Open a new main window. */
    void openNewMainWindow();
391

392 393 394 395 396
    /**
     * Opens a new view with the current URL that is part of a tab and
     * activates it.
     */
    void openNewActivatedTab();
397

398 399 400 401 402
    /**
     * Adds the current URL as an entry to the Places panel
     */
    void addToPlaces();

403
    /**
404
     * Opens a new tab in the background showing the URL \a url.
405
     */
406 407
    void openNewTab(const QUrl& url, DolphinTabWidget::TabPlacement tabPlacement);

408 409 410 411 412 413 414 415 416 417
    /**
     * Opens the selected folder in a new tab.
     */
    void openInNewTab();

    /**
     * Opens the selected folder in a new window.
     */
    void openInNewWindow();

418 419 420 421 422
    /**
     * Show the target of the selected symlink
     */
    void showTarget();

423 424 425 426 427
    /**
     * Indicates in the statusbar that the execution of the command \a command
     * has been finished.
     */
    void showCommand(CommandType command);
428

429
    /**
430
     * If the URL can be listed, open it in the current view, otherwise
431 432
     * run it through KRun.
     */
Lukáš Tinkl's avatar
Lukáš Tinkl committed
433
    void handleUrl(const QUrl& url);
434

435 436 437 438 439 440
    /**
     * handleUrl() can trigger a stat job to see if the url can actually
     * be listed.
     */
    void slotHandleUrlStatFinished(KJob* job);

441 442 443 444 445 446 447 448
    /**
     * Is invoked when the write state of a folder has been changed and
     * enables/disables the "Create New..." menu entry.
     */
    void slotWriteStateChanged(bool isFolderWritable);

    /**
     * Opens the context menu on the current mouse position.
Peter Penz's avatar
Peter Penz committed
449
     * @pos           Position in screen coordinates.
450 451 452 453 454 455
     * @item          File item context. If item is null, the context menu
     *                should be applied to \a url.
     * @url           URL which contains \a item.
     * @customActions Actions that should be added to the context menu,
     *                if the file item is null.
     */
Peter Penz's avatar
Peter Penz committed
456 457
    void openContextMenu(const QPoint& pos,
                         const KFileItem& item,
Lukáš Tinkl's avatar
Lukáš Tinkl committed
458
                         const QUrl& url,
459 460
                         const QList<QAction*>& customActions);

461
    void updateControlMenu();
462
    void updateToolBar();
463
    void slotControlButtonDeleted();
464

465 466 467 468 469
    /**
     * Is called if the user clicked an item in the Places Panel.
     * Reloads the view if \a url is the current URL already, and changes the
     * current URL otherwise.
     */
Lukáš Tinkl's avatar
Lukáš Tinkl committed
470
    void slotPlaceActivated(const QUrl& url);
471

472 473 474 475 476 477 478 479 480
    /**
     * Is called if the another view has been activated by changing the current
     * tab or activating another view in split-view mode.
     *
     * Activates the given view, which means that all menu actions are applied
     * to this view. When having a split view setup, the nonactive view is
     * usually shown in darker colors.
     */
    void activeViewChanged(DolphinViewContainer* viewContainer);
481

482 483
    void closedTabsCountChanged(unsigned int count);

484
    /**
485 486
     * Is called if a new tab has been opened or a tab has been closed to
     * enable/disable the tab actions.
487
     */
488
    void tabCountChanged(int count);
489

490
    /**
David Hallas's avatar
David Hallas committed
491
     * Updates the Window Title with the caption from the active view container
492
     */
David Hallas's avatar
David Hallas committed
493
    void updateWindowTitle();
494

495 496 497 498 499 500 501 502 503 504 505 506 507 508 509
    /**
     * This slot is called when the user requested to unmount a removable media
     * from the places menu
     */
    void slotStorageTearDownFromPlacesRequested(const QString& mountPath);

    /**
     * This slot is called when the user requested to unmount a removable media
     * _not_ from the dolphin's places menu (from the notification area for e.g.)
     * This slot is basically connected to each removable device's
     * Solid::StorageAccess::teardownRequested(const QString & udi)
     * signal through the places panel.
     */
    void slotStorageTearDownExternallyRequested(const QString& mountPath);

510 511 512 513 514
    /**
     * Is called when the view has finished loading the directory.
     */
    void slotDirectoryLoadingCompleted();

515 516 517 518 519 520 521 522
    /**
     * Is called when the user middle clicks a toolbar button.
     *
     * Here middle clicking Back/Forward/Up/Home will open the resulting
     * folder in a new tab.
     */
    void slotToolBarActionMiddleClicked(QAction *action);

523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552
    /**
     * Is called before the Back popup menu is shown. This slot will populate
     * the menu with history data
     */
    void slotAboutToShowBackPopupMenu();

    /**
      * This slot is used by the Back Popup Menu to go back to a specific
      * history index. The QAction::data will carry an int with the index
      * to go to.
      */
    void slotGoBack(QAction* action);

    /**
     * Middle clicking Back/Forward will open the resulting folder in a new tab.
     */
    void slotBackForwardActionMiddleClicked(QAction *action);

    /**
     * Is called before the Forward popup menu is shown. This slot will populate
     * the menu with history data
     */
    void slotAboutToShowForwardPopupMenu();

    /**
      * This slot is used by the Forward Popup Menu to go forward to a specific
      * history index. The QAction::data will carry an int with the index
      * to go to.
      */
    void slotGoForward(QAction* action);
553
private:
554 555 556
    /**
     * Sets up the various menus and actions and connects them.
     */
557
    void setupActions();
558 559 560 561

    /**
     * Sets up the dock widgets and their panels.
     */
562
    void setupDockWidgets();
563

564
    void updateFileAndEditActions();
565 566 567
    void updateViewActions();
    void updateGoActions();

568 569
    void createControlButton();
    void deleteControlButton();
570 571 572 573 574 575

    /**
     * Adds the action \p action to the menu \p menu in
     * case if it has not added already to the toolbar.
     * @return True if the action has been added to the menu.
     */
576
    bool addActionToMenu(QAction* action, QMenu* menu);
577

578 579
    /**
     * Connects the signals from the created DolphinView with
580
     * the DolphinViewContainer \a container with the corresponding slots of
581 582 583
     * the DolphinMainWindow. This method must be invoked each
     * time a DolphinView has been created.
     */
584
    void connectViewSignals(DolphinViewContainer* container);
585

586 587
    /**
     * Updates the text of the split action:
588
     * If two views are shown, the text is set to "Split",
589
     * otherwise the text is set to "Join". The icon
590
     * is updated to match with the text and the currently active view.
591
     */
592
    void updateSplitAction();
593

594
    bool isKompareInstalled() const;
595

596
    /**
597 598 599 600 601
     * Creates an action for showing/hiding a panel, that is accessible
     * in "Configure toolbars..." and "Configure shortcuts...". This is necessary
     * as the action for toggling the dock visibility is done by Qt which
     * is no KAction instance.
     */
602
    void createPanelAction(const QIcon &icon,
603 604 605
                           const QKeySequence& shortcut,
                           QAction* dockAction,
                           const QString& actionName);
606

607 608 609
    /** Adds "What's This?" texts to many widgets and StandardActions. */
    void setupWhatsThis();

610 611 612 613 614 615 616 617 618
    /**
     * Returns the KIO::StatJob::mostLocalUrl() for the active container URL
     * if it's a local file. Otherwise returns the user's home path.
     */
    QString activeContainerLocalPath();

    /** Returns preferred search tool as configured in "More Search Tools" menu. */
    QPointer<QAction> preferredSearchTool();

619
private:
620 621 622 623 624
    /**
     * Implements a custom error handling for the undo manager. This
     * assures that all errors are shown in the status bar of Dolphin
     * instead as modal error dialog with an OK button.
     */
625
    class UndoUiInterface : public KIO::FileUndoManager::UiInterface
626
    {
627
    public:
628
        UndoUiInterface();
629 630
        ~UndoUiInterface() override;
        void jobError(KIO::Job* job) override;
631
    };
632

Peter Penz's avatar
Peter Penz committed
633
    KNewFileMenu* m_newFileMenu;
634
    KHelpMenu* m_helpMenu;
635
    DolphinTabWidget* m_tabWidget;
636
    DolphinViewContainer* m_activeViewContainer;
637

638
    DolphinViewActionHandler* m_actionHandler;
Rahman Duran's avatar
Rahman Duran committed
639
    DolphinRemoteEncoding* m_remoteEncoding;
640
    QPointer<DolphinSettingsDialog> m_settingsDialog;
David Hallas's avatar
David Hallas committed
641
    DolphinBookmarkHandler* m_bookmarkHandler;
642

643
    // Members for the toolbar menu that is shown when the menubar is hidden:
644
    QToolButton* m_controlButton;
645 646
    QTimer* m_updateToolBarTimer;

647
    KIO::Job* m_lastHandleUrlStatJob;
648 649 650 651

    TerminalPanel* m_terminalPanel;
    PlacesPanel* m_placesPanel;
    bool m_tearDownFromPlacesRequested;
652 653 654

    KToolBarPopupAction* m_backAction;
    KToolBarPopupAction* m_forwardAction;
655 656 657

    QMenu m_searchTools;

658 659
};

660
inline DolphinViewContainer* DolphinMainWindow::activeViewContainer() const
661 662 663 664
{
    return m_activeViewContainer;
}

Peter Penz's avatar
Peter Penz committed
665
inline KNewFileMenu* DolphinMainWindow::newFileMenu() const
666
{
Peter Penz's avatar
Peter Penz committed
667
    return m_newFileMenu;
668 669
}

670
#endif // DOLPHIN_MAINWINDOW_H
arnav dhamija's avatar
arnav dhamija committed
671