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> *
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. *
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. *
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 ***************************************************************************/
22 #include "dolphinmainwindow.h"
24 #include "dolphinapplication.h"
25 #include "dolphindockwidget.h"
26 #include "dolphincontextmenu.h"
27 #include "dolphinnewfilemenu.h"
28 #include "dolphinrecenttabsmenu.h"
29 #include "dolphintabbar.h"
30 #include "dolphinviewcontainer.h"
31 #include "dolphintabpage.h"
32 #include "panels/folders/folderspanel.h"
33 #include "panels/places/placespanel.h"
34 #include "panels/information/informationpanel.h"
35 #include "settings/dolphinsettingsdialog.h"
36 #include "statusbar/dolphinstatusbar.h"
37 #include "views/dolphinviewactionhandler.h"
38 #include "views/dolphinremoteencoding.h"
39 #include "views/draganddrophelper.h"
40 #include "views/viewproperties.h"
41 #include "views/dolphinnewfilemenuobserver.h"
44 #include "panels/terminal/terminalpanel.h"
47 #include "dolphin_generalsettings.h"
49 #include <KAcceleratorManager>
51 #include <KActionCollection>
52 #include <KActionMenu>
54 #include <KDesktopFile>
55 #include <kdeversion.h>
56 #include <kdualaction.h>
57 #include <KFileDialog>
62 #include <KIconLoader>
63 #include <KIO/NetAccess>
64 #include <KIO/JobUiDelegate>
65 #include <KInputDialog>
67 #include <KProtocolManager>
70 #include <KMessageBox>
71 #include <KFileItemListProperties>
72 #include <konqmimedata.h>
73 #include <KProtocolInfo>
76 #include <KStandardDirs>
77 #include <kstatusbar.h>
78 #include <KStandardAction>
79 #include <KToggleAction>
80 #include <KUrlNavigator>
82 #include <KUrlComboBox>
83 #include <KToolInvocation>
85 #include <QDesktopWidget>
86 #include <QDBusMessage>
89 #include <QToolButton>
92 // Used for GeneralSettings::version() to determine whether
93 // an updated version of Dolphin is running.
94 const int CurrentDolphinVersion
= 200;
97 DolphinMainWindow::DolphinMainWindow() :
101 m_activeViewContainer(0),
102 m_centralWidgetLayout(0),
109 m_updateToolBarTimer(0),
110 m_lastHandleUrlStatJob(0)
112 setObjectName("Dolphin#");
114 connect(&DolphinNewFileMenuObserver::instance(), SIGNAL(errorMessage(QString
)),
115 this, SLOT(showErrorMessage(QString
)));
117 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
118 undoManager
->setUiInterface(new UndoUiInterface());
120 connect(undoManager
, SIGNAL(undoAvailable(bool)),
121 this, SLOT(slotUndoAvailable(bool)));
122 connect(undoManager
, SIGNAL(undoTextChanged(QString
)),
123 this, SLOT(slotUndoTextChanged(QString
)));
124 connect(undoManager
, SIGNAL(jobRecordingStarted(CommandType
)),
125 this, SLOT(clearStatusBar()));
126 connect(undoManager
, SIGNAL(jobRecordingFinished(CommandType
)),
127 this, SLOT(showCommand(CommandType
)));
129 GeneralSettings
* generalSettings
= GeneralSettings::self();
130 const bool firstRun
= (generalSettings
->version() < 200);
132 generalSettings
->setViewPropsTimestamp(QDateTime::currentDateTime());
135 setAcceptDrops(true);
139 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
140 connect(m_actionHandler
, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
141 connect(m_actionHandler
, SIGNAL(createDirectory()), SLOT(createDirectory()));
143 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
144 connect(this, SIGNAL(urlChanged(KUrl
)),
145 m_remoteEncoding
, SLOT(slotAboutToOpenUrl()));
147 m_tabBar
= new DolphinTabBar(this);
148 connect(m_tabBar
, SIGNAL(currentChanged(int)),
149 this, SLOT(setActiveTab(int)));
150 connect(m_tabBar
, SIGNAL(tabCloseRequested(int)),
151 this, SLOT(closeTab(int)));
152 connect(m_tabBar
, SIGNAL(openNewActivatedTab(int)),
153 this, SLOT(openNewActivatedTab(int)));
154 connect(m_tabBar
, SIGNAL(tabMoved(int,int)),
155 this, SLOT(slotTabMoved(int,int)));
156 connect(m_tabBar
, SIGNAL(tabDropEvent(int,QDropEvent
*)),
157 this, SLOT(tabDropEvent(int,QDropEvent
*)));
158 connect(m_tabBar
, SIGNAL(tabDetachRequested(int)),
159 this, SLOT(detachTab(int)));
161 m_tabBar
->blockSignals(true); // signals get unblocked after at least 2 tabs are open
164 QWidget
* centralWidget
= new QWidget(this);
165 m_centralWidgetLayout
= new QVBoxLayout(centralWidget
);
166 m_centralWidgetLayout
->setSpacing(0);
167 m_centralWidgetLayout
->setMargin(0);
168 m_centralWidgetLayout
->addWidget(m_tabBar
);
170 setCentralWidget(centralWidget
);
173 setupGUI(Keys
| Save
| Create
| ToolBar
);
174 stateChanged("new_file");
176 QClipboard
* clipboard
= QApplication::clipboard();
177 connect(clipboard
, SIGNAL(dataChanged()),
178 this, SLOT(updatePasteAction()));
180 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
181 showFilterBarAction
->setChecked(generalSettings
->filterBar());
184 menuBar()->setVisible(false);
185 // Assure a proper default size if Dolphin runs the first time
189 const bool showMenu
= !menuBar()->isHidden();
190 QAction
* showMenuBarAction
= actionCollection()->action(KStandardAction::name(KStandardAction::ShowMenubar
));
191 showMenuBarAction
->setChecked(showMenu
); // workaround for bug #171080
193 createControlButton();
197 DolphinMainWindow::~DolphinMainWindow()
201 void DolphinMainWindow::openDirectories(const QList
<KUrl
>& dirs
)
203 const bool hasSplitView
= GeneralSettings::splitView();
205 // Open each directory inside a new tab. If the "split view" option has been enabled,
206 // always show two directories within one tab.
207 QList
<KUrl
>::const_iterator it
= dirs
.constBegin();
208 while (it
!= dirs
.constEnd()) {
209 const KUrl
& primaryUrl
= *(it
++);
210 if (hasSplitView
&& (it
!= dirs
.constEnd())) {
211 const KUrl
& secondaryUrl
= *(it
++);
212 openNewTab(primaryUrl
, secondaryUrl
);
214 openNewTab(primaryUrl
);
219 void DolphinMainWindow::openFiles(const QList
<KUrl
>& files
)
221 if (files
.isEmpty()) {
225 // Get all distinct directories from 'files' and open a tab
226 // for each directory. If the "split view" option is enabled, two
227 // directories are shown inside one tab (see openDirectories()).
229 foreach (const KUrl
& url
, files
) {
230 const KUrl
dir(url
.directory());
231 if (!dirs
.contains(dir
)) {
236 openDirectories(dirs
);
238 // Select the files. Although the files can be split between several
239 // tabs, there is no need to split 'files' accordingly, as
240 // the DolphinView will just ignore invalid selections.
241 foreach (DolphinTabPage
* tabPage
, m_viewTab
) {
242 tabPage
->markUrlsAsSelected(files
);
243 tabPage
->markUrlAsCurrent(files
.first());
247 void DolphinMainWindow::showCommand(CommandType command
)
249 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
251 case KIO::FileUndoManager::Copy
:
252 statusBar
->setText(i18nc("@info:status", "Successfully copied."));
254 case KIO::FileUndoManager::Move
:
255 statusBar
->setText(i18nc("@info:status", "Successfully moved."));
257 case KIO::FileUndoManager::Link
:
258 statusBar
->setText(i18nc("@info:status", "Successfully linked."));
260 case KIO::FileUndoManager::Trash
:
261 statusBar
->setText(i18nc("@info:status", "Successfully moved to trash."));
263 case KIO::FileUndoManager::Rename
:
264 statusBar
->setText(i18nc("@info:status", "Successfully renamed."));
267 case KIO::FileUndoManager::Mkdir
:
268 statusBar
->setText(i18nc("@info:status", "Created folder."));
276 void DolphinMainWindow::pasteIntoFolder()
278 m_activeViewContainer
->view()->pasteIntoFolder();
281 void DolphinMainWindow::changeUrl(const KUrl
& url
)
283 if (!KProtocolManager::supportsListing(url
)) {
284 // The URL navigator only checks for validity, not
285 // if the URL can be listed. An error message is
286 // shown due to DolphinViewContainer::restoreView().
290 DolphinViewContainer
* view
= activeViewContainer();
297 setUrlAsCaption(url
);
299 const QString iconName
= KMimeType::iconNameForUrl(url
);
300 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(iconName
));
301 m_tabBar
->setTabText(m_tabIndex
, squeezedText(tabName(view
->url())));
303 emit
urlChanged(url
);
307 void DolphinMainWindow::slotTerminalDirectoryChanged(const KUrl
& url
)
309 m_activeViewContainer
->setAutoGrabFocus(false);
311 m_activeViewContainer
->setAutoGrabFocus(true);
314 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
316 KToggleAction
* editableLocationAction
=
317 static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
318 editableLocationAction
->setChecked(editable
);
321 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
325 const int selectedUrlsCount
= m_viewTab
.at(m_tabIndex
)->selectedItemsCount();
327 QAction
* compareFilesAction
= actionCollection()->action("compare_files");
328 if (selectedUrlsCount
== 2) {
329 compareFilesAction
->setEnabled(isKompareInstalled());
331 compareFilesAction
->setEnabled(false);
334 emit
selectionChanged(selection
);
337 void DolphinMainWindow::slotRequestItemInfo(const KFileItem
& item
)
339 emit
requestItemInfo(item
);
342 void DolphinMainWindow::updateHistory()
344 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
345 const int index
= urlNavigator
->historyIndex();
347 QAction
* backAction
= actionCollection()->action("go_back");
349 backAction
->setToolTip(i18nc("@info", "Go back"));
350 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
353 QAction
* forwardAction
= actionCollection()->action("go_forward");
355 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
356 forwardAction
->setEnabled(index
> 0);
360 void DolphinMainWindow::updateFilterBarAction(bool show
)
362 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
363 showFilterBarAction
->setChecked(show
);
366 void DolphinMainWindow::openNewMainWindow()
368 KRun::run("dolphin %u", KUrl::List(), this);
371 void DolphinMainWindow::openNewTab()
373 const bool isUrlEditable
= m_activeViewContainer
->urlNavigator()->isUrlEditable();
375 openNewTab(m_activeViewContainer
->url());
376 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
378 // The URL navigator of the new tab should have the same editable state
379 // as the current tab
380 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
381 navigator
->setUrlEditable(isUrlEditable
);
384 // If a new tab is opened and the URL is editable, assure that
385 // the user can edit the URL without manually setting the focus
386 navigator
->setFocus();
390 void DolphinMainWindow::openNewTab(const KUrl
& primaryUrl
, const KUrl
& secondaryUrl
)
392 QWidget
* focusWidget
= QApplication::focusWidget();
394 DolphinTabPage
* tabPage
= new DolphinTabPage(primaryUrl
, secondaryUrl
, this);
395 m_viewTab
.append(tabPage
);
397 connect(tabPage
, SIGNAL(activeViewChanged()),
398 this, SLOT(activeViewChanged()));
400 // The places-selector from the URL navigator should only be shown
401 // if the places dock is invisible
402 QDockWidget
* placesDock
= findChild
<QDockWidget
*>("placesDock");
403 const bool placesSelectorVisible
= !placesDock
|| !placesDock
->isVisible();
404 tabPage
->setPlacesSelectorVisible(placesSelectorVisible
);
406 DolphinViewContainer
* primaryContainer
= tabPage
->primaryViewContainer();
407 connectViewSignals(primaryContainer
);
409 if (tabPage
->splitViewEnabled()) {
410 DolphinViewContainer
* secondaryContainer
= tabPage
->secondaryViewContainer();
411 connectViewSignals(secondaryContainer
);
416 m_tabBar
->addTab(KIcon(KMimeType::iconNameForUrl(primaryUrl
)),
417 squeezedText(tabName(primaryUrl
)));
419 if (m_viewTab
.count() > 1) {
420 actionCollection()->action("close_tab")->setEnabled(true);
421 actionCollection()->action("activate_prev_tab")->setEnabled(true);
422 actionCollection()->action("activate_next_tab")->setEnabled(true);
424 m_tabBar
->blockSignals(false);
428 // The DolphinViewContainer grabbed the keyboard focus. As the tab is opened
429 // in background, assure that the previous focused widget gets the focus back.
430 focusWidget
->setFocus();
434 void DolphinMainWindow::openNewActivatedTab(const KUrl
& primaryUrl
, const KUrl
& secondaryUrl
)
436 openNewTab(primaryUrl
, secondaryUrl
);
437 setActiveTab(m_viewTab
.count() - 1);
440 void DolphinMainWindow::openNewActivatedTab(int index
)
442 Q_ASSERT(index
>= 0);
443 const DolphinTabPage
* tabPage
= m_viewTab
.at(index
);
444 openNewActivatedTab(tabPage
->activeViewContainer()->url());
447 void DolphinMainWindow::activateNextTab()
449 if (m_viewTab
.count() >= 2) {
450 const int tabIndex
= (m_tabBar
->currentIndex() + 1) % m_tabBar
->count();
451 setActiveTab(tabIndex
);
455 void DolphinMainWindow::activatePrevTab()
457 if (m_viewTab
.count() >= 2) {
458 int tabIndex
= m_tabBar
->currentIndex() - 1;
459 if (tabIndex
== -1) {
460 tabIndex
= m_tabBar
->count() - 1;
462 setActiveTab(tabIndex
);
466 void DolphinMainWindow::openInNewTab()
468 const KFileItemList
& list
= m_activeViewContainer
->view()->selectedItems();
469 if (list
.isEmpty()) {
470 openNewTab(m_activeViewContainer
->url());
472 foreach (const KFileItem
& item
, list
) {
473 const KUrl
& url
= DolphinView::openItemAsFolderUrl(item
);
474 if (!url
.isEmpty()) {
481 void DolphinMainWindow::openInNewWindow()
485 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
486 if (list
.isEmpty()) {
487 newWindowUrl
= m_activeViewContainer
->url();
488 } else if (list
.count() == 1) {
489 const KFileItem
& item
= list
.first();
490 newWindowUrl
= DolphinView::openItemAsFolderUrl(item
);
493 if (!newWindowUrl
.isEmpty()) {
494 KRun::run("dolphin %u", KUrl::List() << newWindowUrl
, this);
498 void DolphinMainWindow::showEvent(QShowEvent
* event
)
500 KXmlGuiWindow::showEvent(event
);
502 if (!m_activeViewContainer
&& m_viewTab
.count() > 0) {
503 // If we have no active view container yet, we set the primary view container
504 // of the first tab as active view container.
508 if (!event
->spontaneous()) {
509 m_activeViewContainer
->view()->setFocus();
513 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
515 // Find out if Dolphin is closed directly by the user or
516 // by the session manager because the session is closed
517 bool closedByUser
= true;
518 DolphinApplication
*application
= qobject_cast
<DolphinApplication
*>(qApp
);
519 if (application
&& application
->sessionSaving()) {
520 closedByUser
= false;
523 if (m_viewTab
.count() > 1 && GeneralSettings::confirmClosingMultipleTabs() && closedByUser
) {
524 // Ask the user if he really wants to quit and close all tabs.
525 // Open a confirmation dialog with 3 buttons:
526 // KDialog::Yes -> Quit
527 // KDialog::No -> Close only the current tab
528 // KDialog::Cancel -> do nothing
529 KDialog
*dialog
= new KDialog(this, Qt::Dialog
);
530 dialog
->setCaption(i18nc("@title:window", "Confirmation"));
531 dialog
->setButtons(KDialog::Yes
| KDialog::No
| KDialog::Cancel
);
532 dialog
->setModal(true);
533 dialog
->setButtonGuiItem(KDialog::Yes
, KStandardGuiItem::quit());
534 dialog
->setButtonGuiItem(KDialog::No
, KGuiItem(i18n("C&lose Current Tab"), KIcon("tab-close")));
535 dialog
->setButtonGuiItem(KDialog::Cancel
, KStandardGuiItem::cancel());
536 dialog
->setDefaultButton(KDialog::Yes
);
538 bool doNotAskAgainCheckboxResult
= false;
540 const int result
= KMessageBox::createKMessageBox(dialog
,
541 QMessageBox::Warning
,
542 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
544 i18n("Do not ask again"),
545 &doNotAskAgainCheckboxResult
,
546 KMessageBox::Notify
);
548 if (doNotAskAgainCheckboxResult
) {
549 GeneralSettings::setConfirmClosingMultipleTabs(false);
557 // Close only the current tab
565 GeneralSettings::setVersion(CurrentDolphinVersion
);
566 GeneralSettings::self()->writeConfig();
568 KXmlGuiWindow::closeEvent(event
);
571 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
573 const int tabCount
= m_viewTab
.count();
574 group
.writeEntry("Tab Count", tabCount
);
575 group
.writeEntry("Active Tab Index", m_tabBar
->currentIndex());
577 for (int i
= 0; i
< tabCount
; ++i
) {
578 const DolphinTabPage
* tabPage
= m_viewTab
.at(i
);
579 group
.writeEntry("Tab " % QString::number(i
), tabPage
->saveState());
583 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
585 const int tabCount
= group
.readEntry("Tab Count", 1);
586 for (int i
= 0; i
< tabCount
; ++i
) {
587 const QByteArray state
= group
.readEntry("Tab " % QString::number(i
), QByteArray());
588 DolphinTabPage
* tabPage
= m_viewTab
.at(i
);
589 tabPage
->restoreState(state
);
591 // openNewTab() needs to be called only tabCount - 1 times
592 if (i
!= tabCount
- 1) {
597 const int index
= group
.readEntry("Active Tab Index", 0);
598 m_tabBar
->setCurrentIndex(index
);
601 void DolphinMainWindow::updateNewMenu()
603 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
604 m_newFileMenu
->checkUpToDate();
605 m_newFileMenu
->setPopupFiles(activeViewContainer()->url());
608 void DolphinMainWindow::createDirectory()
610 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
611 m_newFileMenu
->setPopupFiles(activeViewContainer()->url());
612 m_newFileMenu
->createDirectory();
615 void DolphinMainWindow::quit()
620 void DolphinMainWindow::showErrorMessage(const QString
& message
)
622 m_activeViewContainer
->showMessage(message
, DolphinViewContainer::Error
);
625 void DolphinMainWindow::slotUndoAvailable(bool available
)
627 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
629 undoAction
->setEnabled(available
);
633 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
635 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
637 undoAction
->setText(text
);
641 void DolphinMainWindow::undo()
644 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
645 KIO::FileUndoManager::self()->undo();
648 void DolphinMainWindow::cut()
650 m_activeViewContainer
->view()->cutSelectedItems();
653 void DolphinMainWindow::copy()
655 m_activeViewContainer
->view()->copySelectedItems();
658 void DolphinMainWindow::paste()
660 m_activeViewContainer
->view()->paste();
663 void DolphinMainWindow::find()
665 m_activeViewContainer
->setSearchModeEnabled(true);
668 void DolphinMainWindow::updatePasteAction()
670 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
671 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
672 pasteAction
->setEnabled(pasteInfo
.first
);
673 pasteAction
->setText(pasteInfo
.second
);
676 void DolphinMainWindow::selectAll()
680 // if the URL navigator is editable and focused, select the whole
681 // URL instead of all items of the view
683 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
684 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit(); // krazy:exclude=qclasses
685 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
686 lineEdit
->hasFocus();
688 lineEdit
->selectAll();
690 m_activeViewContainer
->view()->selectAll();
694 void DolphinMainWindow::invertSelection()
697 m_activeViewContainer
->view()->invertSelection();
700 void DolphinMainWindow::toggleSplitView()
702 DolphinTabPage
* tabPage
= m_viewTab
.at(m_tabIndex
);
703 tabPage
->setSplitViewEnabled(!tabPage
->splitViewEnabled());
705 if (tabPage
->splitViewEnabled()) {
706 connectViewSignals(tabPage
->secondaryViewContainer());
712 void DolphinMainWindow::reloadView()
715 m_activeViewContainer
->view()->reload();
718 void DolphinMainWindow::stopLoading()
720 m_activeViewContainer
->view()->stopLoading();
723 void DolphinMainWindow::enableStopAction()
725 actionCollection()->action("stop")->setEnabled(true);
728 void DolphinMainWindow::disableStopAction()
730 actionCollection()->action("stop")->setEnabled(false);
733 void DolphinMainWindow::showFilterBar()
735 m_activeViewContainer
->setFilterBarVisible(true);
738 void DolphinMainWindow::toggleEditLocation()
742 QAction
* action
= actionCollection()->action("editable_location");
743 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
744 urlNavigator
->setUrlEditable(action
->isChecked());
747 void DolphinMainWindow::replaceLocation()
749 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
750 navigator
->setUrlEditable(true);
751 navigator
->setFocus();
753 // select the whole text of the combo box editor
754 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit(); // krazy:exclude=qclasses
755 lineEdit
->selectAll();
758 void DolphinMainWindow::togglePanelLockState()
760 const bool newLockState
= !GeneralSettings::lockPanels();
761 foreach (QObject
* child
, children()) {
762 DolphinDockWidget
* dock
= qobject_cast
<DolphinDockWidget
*>(child
);
764 dock
->setLocked(newLockState
);
768 GeneralSettings::setLockPanels(newLockState
);
771 void DolphinMainWindow::slotPlacesPanelVisibilityChanged(bool visible
)
773 foreach (DolphinTabPage
* tabPage
, m_viewTab
) {
774 // The Places selector in the location bar should be shown if and only if the Places panel is hidden.
775 tabPage
->setPlacesSelectorVisible(!visible
);
779 void DolphinMainWindow::goBack()
781 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
782 urlNavigator
->goBack();
784 if (urlNavigator
->locationState().isEmpty()) {
785 // An empty location state indicates a redirection URL,
786 // which must be skipped too
787 urlNavigator
->goBack();
791 void DolphinMainWindow::goForward()
793 m_activeViewContainer
->urlNavigator()->goForward();
796 void DolphinMainWindow::goUp()
798 m_activeViewContainer
->urlNavigator()->goUp();
801 void DolphinMainWindow::goHome()
803 m_activeViewContainer
->urlNavigator()->goHome();
806 void DolphinMainWindow::goBack(Qt::MouseButtons buttons
)
808 // The default case (left button pressed) is handled in goBack().
809 if (buttons
== Qt::MidButton
) {
810 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
811 const int index
= urlNavigator
->historyIndex() + 1;
812 openNewTab(urlNavigator
->locationUrl(index
));
816 void DolphinMainWindow::goForward(Qt::MouseButtons buttons
)
818 // The default case (left button pressed) is handled in goForward().
819 if (buttons
== Qt::MidButton
) {
820 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
821 const int index
= urlNavigator
->historyIndex() - 1;
822 openNewTab(urlNavigator
->locationUrl(index
));
826 void DolphinMainWindow::goUp(Qt::MouseButtons buttons
)
828 // The default case (left button pressed) is handled in goUp().
829 if (buttons
== Qt::MidButton
) {
830 openNewTab(activeViewContainer()->url().upUrl());
834 void DolphinMainWindow::goHome(Qt::MouseButtons buttons
)
836 // The default case (left button pressed) is handled in goHome().
837 if (buttons
== Qt::MidButton
) {
838 openNewTab(GeneralSettings::self()->homeUrl());
842 void DolphinMainWindow::compareFiles()
844 const KFileItemList items
= m_viewTab
.at(m_tabIndex
)->selectedItems();
845 if (items
.count() != 2) {
846 // The action is disabled in this case, but it could have been triggered
847 // via D-Bus, see https://bugs.kde.org/show_bug.cgi?id=325517
851 KUrl urlA
= items
.at(0).url();
852 KUrl urlB
= items
.at(1).url();
854 QString
command("kompare -c \"");
855 command
.append(urlA
.pathOrUrl());
856 command
.append("\" \"");
857 command
.append(urlB
.pathOrUrl());
858 command
.append('\"');
859 KRun::runCommand(command
, "Kompare", "kompare", this);
862 void DolphinMainWindow::toggleShowMenuBar()
864 const bool visible
= menuBar()->isVisible();
865 menuBar()->setVisible(!visible
);
867 createControlButton();
869 deleteControlButton();
873 void DolphinMainWindow::openTerminal()
875 QString
dir(QDir::homePath());
877 // If the given directory is not local, it can still be the URL of an
878 // ioslave using UDS_LOCAL_PATH which to be converted first.
879 KUrl url
= KIO::NetAccess::mostLocalUrl(m_activeViewContainer
->url(), this);
881 //If the URL is local after the above conversion, set the directory.
882 if (url
.isLocalFile()) {
883 dir
= url
.toLocalFile();
886 KToolInvocation::invokeTerminal(QString(), dir
);
889 void DolphinMainWindow::editSettings()
891 if (!m_settingsDialog
) {
892 DolphinViewContainer
* container
= activeViewContainer();
893 container
->view()->writeSettings();
895 const KUrl url
= container
->url();
896 DolphinSettingsDialog
* settingsDialog
= new DolphinSettingsDialog(url
, this);
897 connect(settingsDialog
, SIGNAL(settingsChanged()), this, SLOT(refreshViews()));
898 settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
899 settingsDialog
->show();
900 m_settingsDialog
= settingsDialog
;
902 m_settingsDialog
.data()->raise();
906 void DolphinMainWindow::setActiveTab(int index
)
908 Q_ASSERT(index
>= 0);
909 Q_ASSERT(index
< m_viewTab
.count());
910 if (index
== m_tabIndex
) {
914 m_tabBar
->setCurrentIndex(index
);
916 // hide current tab content
917 if (m_tabIndex
>= 0) {
918 DolphinTabPage
* hiddenTabPage
= m_viewTab
.at(m_tabIndex
);
919 hiddenTabPage
->hide();
920 m_centralWidgetLayout
->removeWidget(hiddenTabPage
);
923 // show active tab content
926 DolphinTabPage
* tabPage
= m_viewTab
.at(index
);
927 m_centralWidgetLayout
->addWidget(tabPage
, 1);
930 setActiveViewContainer(tabPage
->activeViewContainer());
933 void DolphinMainWindow::closeTab()
935 closeTab(m_tabBar
->currentIndex());
938 void DolphinMainWindow::closeTab(int index
)
940 Q_ASSERT(index
>= 0);
941 Q_ASSERT(index
< m_viewTab
.count());
942 if (m_viewTab
.count() == 1) {
943 // the last tab may never get closed
947 if (index
== m_tabIndex
) {
948 // The tab that should be closed is the active tab. Activate the
949 // previous tab before closing the tab.
950 m_tabBar
->setCurrentIndex((index
> 0) ? index
- 1 : 1);
953 DolphinTabPage
* tabPage
= m_viewTab
.at(index
);
955 if (tabPage
->splitViewEnabled()) {
956 emit
rememberClosedTab(tabPage
->primaryViewContainer()->url(),
957 tabPage
->secondaryViewContainer()->url());
959 emit
rememberClosedTab(tabPage
->primaryViewContainer()->url(), KUrl());
963 m_viewTab
.removeAt(index
);
964 tabPage
->deleteLater();
966 m_tabBar
->blockSignals(true);
967 m_tabBar
->removeTab(index
);
969 if (m_tabIndex
> index
) {
971 Q_ASSERT(m_tabIndex
>= 0);
974 // if only one tab is left, also remove the tab entry so that
975 // closing the last tab is not possible
976 if (m_viewTab
.count() < 2) {
977 actionCollection()->action("close_tab")->setEnabled(false);
978 actionCollection()->action("activate_prev_tab")->setEnabled(false);
979 actionCollection()->action("activate_next_tab")->setEnabled(false);
982 m_tabBar
->blockSignals(false);
986 void DolphinMainWindow::detachTab(int index
)
988 Q_ASSERT(index
>= 0);
990 const QString
separator(QLatin1Char(' '));
991 QString command
= QLatin1String("dolphin");
993 const DolphinTabPage
* tabPage
= m_viewTab
.at(index
);
994 command
+= separator
+ tabPage
->primaryViewContainer()->url().url();
995 if (tabPage
->splitViewEnabled()) {
996 command
+= separator
+ tabPage
->secondaryViewContainer()->url().url();
997 command
+= separator
+ QLatin1String("-split");
1000 KRun::runCommand(command
, this);
1005 void DolphinMainWindow::slotTabMoved(int from
, int to
)
1007 m_viewTab
.move(from
, to
);
1008 m_tabIndex
= m_tabBar
->currentIndex();
1011 void DolphinMainWindow::handleUrl(const KUrl
& url
)
1013 delete m_lastHandleUrlStatJob
;
1014 m_lastHandleUrlStatJob
= 0;
1016 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1017 activeViewContainer()->setUrl(url
);
1018 } else if (KProtocolManager::supportsListing(url
)) {
1019 // stat the URL to see if it is a dir or not
1020 m_lastHandleUrlStatJob
= KIO::stat(url
, KIO::HideProgressInfo
);
1021 if (m_lastHandleUrlStatJob
->ui()) {
1022 m_lastHandleUrlStatJob
->ui()->setWindow(this);
1024 connect(m_lastHandleUrlStatJob
, SIGNAL(result(KJob
*)),
1025 this, SLOT(slotHandleUrlStatFinished(KJob
*)));
1028 new KRun(url
, this); // Automatically deletes itself after being finished
1032 void DolphinMainWindow::slotHandleUrlStatFinished(KJob
* job
)
1034 m_lastHandleUrlStatJob
= 0;
1035 const KIO::UDSEntry entry
= static_cast<KIO::StatJob
*>(job
)->statResult();
1036 const KUrl url
= static_cast<KIO::StatJob
*>(job
)->url();
1037 if (entry
.isDir()) {
1038 activeViewContainer()->setUrl(url
);
1040 new KRun(url
, this); // Automatically deletes itself after being finished
1044 void DolphinMainWindow::tabDropEvent(int tab
, QDropEvent
* event
)
1046 const KUrl::List urls
= KUrl::List::fromMimeData(event
->mimeData());
1047 if (!urls
.isEmpty() && tab
!= -1) {
1048 const DolphinView
* view
= m_viewTab
.at(tab
)->activeViewContainer()->view();
1051 DragAndDropHelper::dropUrls(view
->rootItem(), view
->url(), event
, error
);
1052 if (!error
.isEmpty()) {
1053 activeViewContainer()->showMessage(error
, DolphinViewContainer::Error
);
1058 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1060 newFileMenu()->setEnabled(isFolderWritable
);
1063 void DolphinMainWindow::openContextMenu(const QPoint
& pos
,
1064 const KFileItem
& item
,
1066 const QList
<QAction
*>& customActions
)
1068 QWeakPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, pos
, item
, url
);
1069 contextMenu
.data()->setCustomActions(customActions
);
1070 const DolphinContextMenu::Command command
= contextMenu
.data()->open();
1073 case DolphinContextMenu::OpenParentFolderInNewWindow
: {
1074 KRun::run("dolphin %u", KUrl::List() << item
.url().upUrl(), this);
1078 case DolphinContextMenu::OpenParentFolderInNewTab
:
1079 openNewTab(item
.url().upUrl());
1082 case DolphinContextMenu::None
:
1087 delete contextMenu
.data();
1090 void DolphinMainWindow::updateControlMenu()
1092 KMenu
* menu
= qobject_cast
<KMenu
*>(sender());
1095 // All actions get cleared by KMenu::clear(). The sub-menus are deleted
1096 // by connecting to the aboutToHide() signal from the parent-menu.
1099 KActionCollection
* ac
= actionCollection();
1101 // Add "Edit" actions
1102 bool added
= addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Undo
)), menu
) |
1103 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Find
)), menu
) |
1104 addActionToMenu(ac
->action("select_all"), menu
) |
1105 addActionToMenu(ac
->action("invert_selection"), menu
);
1108 menu
->addSeparator();
1111 // Add "View" actions
1112 if (!GeneralSettings::showZoomSlider()) {
1113 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomIn
)), menu
);
1114 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomOut
)), menu
);
1115 menu
->addSeparator();
1118 added
= addActionToMenu(ac
->action("view_mode"), menu
) |
1119 addActionToMenu(ac
->action("sort"), menu
) |
1120 addActionToMenu(ac
->action("additional_info"), menu
) |
1121 addActionToMenu(ac
->action("show_preview"), menu
) |
1122 addActionToMenu(ac
->action("show_in_groups"), menu
) |
1123 addActionToMenu(ac
->action("show_hidden_files"), menu
);
1126 menu
->addSeparator();
1129 added
= addActionToMenu(ac
->action("split_view"), menu
) |
1130 addActionToMenu(ac
->action("reload"), menu
) |
1131 addActionToMenu(ac
->action("view_properties"), menu
);
1133 menu
->addSeparator();
1136 addActionToMenu(ac
->action("panels"), menu
);
1137 KMenu
* locationBarMenu
= new KMenu(i18nc("@action:inmenu", "Location Bar"), menu
);
1138 locationBarMenu
->addAction(ac
->action("editable_location"));
1139 locationBarMenu
->addAction(ac
->action("replace_location"));
1140 menu
->addMenu(locationBarMenu
);
1142 menu
->addSeparator();
1145 KMenu
* goMenu
= new KMenu(i18nc("@action:inmenu", "Go"), menu
);
1146 connect(menu
, SIGNAL(aboutToHide()), goMenu
, SLOT(deleteLater()));
1147 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Back
)));
1148 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Forward
)));
1149 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Up
)));
1150 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Home
)));
1151 goMenu
->addAction(ac
->action("closed_tabs"));
1152 menu
->addMenu(goMenu
);
1155 KMenu
* toolsMenu
= new KMenu(i18nc("@action:inmenu", "Tools"), menu
);
1156 connect(menu
, SIGNAL(aboutToHide()), toolsMenu
, SLOT(deleteLater()));
1157 toolsMenu
->addAction(ac
->action("show_filter_bar"));
1158 toolsMenu
->addAction(ac
->action("compare_files"));
1159 toolsMenu
->addAction(ac
->action("open_terminal"));
1160 toolsMenu
->addAction(ac
->action("change_remote_encoding"));
1161 menu
->addMenu(toolsMenu
);
1163 // Add "Settings" menu entries
1164 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::KeyBindings
)), menu
);
1165 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ConfigureToolbars
)), menu
);
1166 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Preferences
)), menu
);
1169 KMenu
* helpMenu
= new KMenu(i18nc("@action:inmenu", "Help"), menu
);
1170 connect(menu
, SIGNAL(aboutToHide()), helpMenu
, SLOT(deleteLater()));
1171 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::HelpContents
)));
1172 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::WhatsThis
)));
1173 helpMenu
->addSeparator();
1174 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ReportBug
)));
1175 helpMenu
->addSeparator();
1176 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
)));
1177 helpMenu
->addSeparator();
1178 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::AboutApp
)));
1179 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::AboutKDE
)));
1180 menu
->addMenu(helpMenu
);
1182 menu
->addSeparator();
1183 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ShowMenubar
)), menu
);
1186 void DolphinMainWindow::updateToolBar()
1188 if (!menuBar()->isVisible()) {
1189 createControlButton();
1193 void DolphinMainWindow::slotControlButtonDeleted()
1195 m_controlButton
= 0;
1196 m_updateToolBarTimer
->start();
1199 void DolphinMainWindow::slotPanelErrorMessage(const QString
& error
)
1201 activeViewContainer()->showMessage(error
, DolphinViewContainer::Error
);
1204 void DolphinMainWindow::slotPlaceActivated(const KUrl
& url
)
1206 DolphinViewContainer
* view
= activeViewContainer();
1208 if (view
->url() == url
) {
1209 // We can end up here if the user clicked a device in the Places Panel
1210 // which had been unmounted earlier, see https://bugs.kde.org/show_bug.cgi?id=161385.
1217 void DolphinMainWindow::activeViewChanged()
1219 const DolphinTabPage
* tabPage
= m_viewTab
.at(m_tabIndex
);
1220 setActiveViewContainer(tabPage
->activeViewContainer());
1223 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer
* viewContainer
)
1225 Q_ASSERT(viewContainer
);
1226 Q_ASSERT((viewContainer
== m_viewTab
.at(m_tabIndex
)->primaryViewContainer()) ||
1227 (viewContainer
== m_viewTab
.at(m_tabIndex
)->secondaryViewContainer()));
1228 if (m_activeViewContainer
== viewContainer
) {
1232 m_activeViewContainer
= viewContainer
;
1233 m_actionHandler
->setCurrentView(viewContainer
->view());
1236 updateEditActions();
1237 updatePasteAction();
1238 updateViewActions();
1241 const KUrl url
= m_activeViewContainer
->url();
1242 setUrlAsCaption(url
);
1243 m_tabBar
->setTabText(m_tabIndex
, squeezedText(tabName(url
)));
1244 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(KMimeType::iconNameForUrl(url
)));
1246 emit
urlChanged(url
);
1249 void DolphinMainWindow::setupActions()
1251 // setup 'File' menu
1252 m_newFileMenu
= new DolphinNewFileMenu(actionCollection(), this);
1253 KMenu
* menu
= m_newFileMenu
->menu();
1254 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1255 menu
->setIcon(KIcon("document-new"));
1256 m_newFileMenu
->setDelayed(false);
1257 connect(menu
, SIGNAL(aboutToShow()),
1258 this, SLOT(updateNewMenu()));
1260 KAction
* newWindow
= actionCollection()->addAction("new_window");
1261 newWindow
->setIcon(KIcon("window-new"));
1262 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1263 newWindow
->setShortcut(Qt::CTRL
| Qt::Key_N
);
1264 connect(newWindow
, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1266 KAction
* newTab
= actionCollection()->addAction("new_tab");
1267 newTab
->setIcon(KIcon("tab-new"));
1268 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1269 newTab
->setShortcut(KShortcut(Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
));
1270 connect(newTab
, SIGNAL(triggered()), this, SLOT(openNewTab()));
1272 KAction
* closeTab
= actionCollection()->addAction("close_tab");
1273 closeTab
->setIcon(KIcon("tab-close"));
1274 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1275 closeTab
->setShortcut(Qt::CTRL
| Qt::Key_W
);
1276 closeTab
->setEnabled(false);
1277 connect(closeTab
, SIGNAL(triggered()), this, SLOT(closeTab()));
1279 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1281 // setup 'Edit' menu
1282 KStandardAction::undo(this,
1284 actionCollection());
1286 // need to remove shift+del from cut action, else the shortcut for deletejob
1288 KAction
* cut
= KStandardAction::cut(this, SLOT(cut()), actionCollection());
1289 KShortcut cutShortcut
= cut
->shortcut();
1290 cutShortcut
.remove(Qt::SHIFT
| Qt::Key_Delete
, KShortcut::KeepEmpty
);
1291 cut
->setShortcut(cutShortcut
);
1292 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1293 KAction
* paste
= KStandardAction::paste(this, SLOT(paste()), actionCollection());
1294 // The text of the paste-action is modified dynamically by Dolphin
1295 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1296 // due to the long text, the text "Paste" is used:
1297 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1299 KStandardAction::find(this, SLOT(find()), actionCollection());
1301 KAction
* selectAll
= actionCollection()->addAction("select_all");
1302 selectAll
->setText(i18nc("@action:inmenu Edit", "Select All"));
1303 selectAll
->setShortcut(Qt::CTRL
| Qt::Key_A
);
1304 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
1306 KAction
* invertSelection
= actionCollection()->addAction("invert_selection");
1307 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1308 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1309 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
1311 // setup 'View' menu
1312 // (note that most of it is set up in DolphinViewActionHandler)
1314 KAction
* split
= actionCollection()->addAction("split_view");
1315 split
->setShortcut(Qt::Key_F3
);
1316 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1318 KAction
* reload
= actionCollection()->addAction("reload");
1319 reload
->setText(i18nc("@action:inmenu View", "Reload"));
1320 reload
->setShortcut(Qt::Key_F5
);
1321 reload
->setIcon(KIcon("view-refresh"));
1322 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
1324 KAction
* stop
= actionCollection()->addAction("stop");
1325 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1326 stop
->setToolTip(i18nc("@info", "Stop loading"));
1327 stop
->setIcon(KIcon("process-stop"));
1328 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
1330 KToggleAction
* editableLocation
= actionCollection()->add
<KToggleAction
>("editable_location");
1331 editableLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1332 editableLocation
->setShortcut(Qt::Key_F6
);
1333 connect(editableLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1335 KAction
* replaceLocation
= actionCollection()->addAction("replace_location");
1336 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1337 replaceLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
1338 connect(replaceLocation
, SIGNAL(triggered()), this, SLOT(replaceLocation()));
1341 KAction
* backAction
= KStandardAction::back(this, SLOT(goBack()), actionCollection());
1342 connect(backAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goBack(Qt::MouseButtons
)));
1343 KShortcut backShortcut
= backAction
->shortcut();
1344 backShortcut
.setAlternate(Qt::Key_Backspace
);
1345 backAction
->setShortcut(backShortcut
);
1347 DolphinRecentTabsMenu
* recentTabsMenu
= new DolphinRecentTabsMenu(this);
1348 actionCollection()->addAction("closed_tabs", recentTabsMenu
);
1349 connect(this, SIGNAL(rememberClosedTab(KUrl
,KUrl
)),
1350 recentTabsMenu
, SLOT(rememberClosedTab(KUrl
,KUrl
)));
1351 connect(recentTabsMenu
, SIGNAL(restoreClosedTab(KUrl
,KUrl
)),
1352 this, SLOT(openNewActivatedTab(KUrl
,KUrl
)));
1354 KAction
* forwardAction
= KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1355 connect(forwardAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goForward(Qt::MouseButtons
)));
1357 KAction
* upAction
= KStandardAction::up(this, SLOT(goUp()), actionCollection());
1358 connect(upAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goUp(Qt::MouseButtons
)));
1360 KAction
* homeAction
= KStandardAction::home(this, SLOT(goHome()), actionCollection());
1361 connect(homeAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goHome(Qt::MouseButtons
)));
1363 // setup 'Tools' menu
1364 KAction
* showFilterBar
= actionCollection()->addAction("show_filter_bar");
1365 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1366 showFilterBar
->setIcon(KIcon("view-filter"));
1367 showFilterBar
->setShortcut(Qt::CTRL
| Qt::Key_I
);
1368 connect(showFilterBar
, SIGNAL(triggered()), this, SLOT(showFilterBar()));
1370 KAction
* compareFiles
= actionCollection()->addAction("compare_files");
1371 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1372 compareFiles
->setIcon(KIcon("kompare"));
1373 compareFiles
->setEnabled(false);
1374 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
1376 KAction
* openTerminal
= actionCollection()->addAction("open_terminal");
1377 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1378 openTerminal
->setIcon(KIcon("utilities-terminal"));
1379 openTerminal
->setShortcut(Qt::SHIFT
| Qt::Key_F4
);
1380 connect(openTerminal
, SIGNAL(triggered()), this, SLOT(openTerminal()));
1382 // setup 'Settings' menu
1383 KToggleAction
* showMenuBar
= KStandardAction::showMenubar(0, 0, actionCollection());
1384 connect(showMenuBar
, SIGNAL(triggered(bool)), // Fixes #286822
1385 this, SLOT(toggleShowMenuBar()), Qt::QueuedConnection
);
1386 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1388 // not in menu actions
1389 QList
<QKeySequence
> nextTabKeys
;
1390 nextTabKeys
.append(KStandardShortcut::tabNext().primary());
1391 nextTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::Key_Tab
));
1393 QList
<QKeySequence
> prevTabKeys
;
1394 prevTabKeys
.append(KStandardShortcut::tabPrev().primary());
1395 prevTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::SHIFT
| Qt::Key_Tab
));
1397 KAction
* activateNextTab
= actionCollection()->addAction("activate_next_tab");
1398 activateNextTab
->setIconText(i18nc("@action:inmenu", "Next Tab"));
1399 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1400 activateNextTab
->setEnabled(false);
1401 connect(activateNextTab
, SIGNAL(triggered()), SLOT(activateNextTab()));
1402 activateNextTab
->setShortcuts(QApplication::isRightToLeft() ? prevTabKeys
: nextTabKeys
);
1404 KAction
* activatePrevTab
= actionCollection()->addAction("activate_prev_tab");
1405 activatePrevTab
->setIconText(i18nc("@action:inmenu", "Previous Tab"));
1406 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1407 activatePrevTab
->setEnabled(false);
1408 connect(activatePrevTab
, SIGNAL(triggered()), SLOT(activatePrevTab()));
1409 activatePrevTab
->setShortcuts(QApplication::isRightToLeft() ? nextTabKeys
: prevTabKeys
);
1412 KAction
* openInNewTab
= actionCollection()->addAction("open_in_new_tab");
1413 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1414 openInNewTab
->setIcon(KIcon("tab-new"));
1415 connect(openInNewTab
, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1417 KAction
* openInNewTabs
= actionCollection()->addAction("open_in_new_tabs");
1418 openInNewTabs
->setText(i18nc("@action:inmenu", "Open in New Tabs"));
1419 openInNewTabs
->setIcon(KIcon("tab-new"));
1420 connect(openInNewTabs
, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1422 KAction
* openInNewWindow
= actionCollection()->addAction("open_in_new_window");
1423 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1424 openInNewWindow
->setIcon(KIcon("window-new"));
1425 connect(openInNewWindow
, SIGNAL(triggered()), this, SLOT(openInNewWindow()));
1428 void DolphinMainWindow::setupDockWidgets()
1430 const bool lock
= GeneralSettings::lockPanels();
1432 KDualAction
* lockLayoutAction
= actionCollection()->add
<KDualAction
>("lock_panels");
1433 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
1434 lockLayoutAction
->setActiveIcon(KIcon("object-unlocked"));
1435 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
1436 lockLayoutAction
->setInactiveIcon(KIcon("object-locked"));
1437 lockLayoutAction
->setActive(lock
);
1438 connect(lockLayoutAction
, SIGNAL(triggered()), this, SLOT(togglePanelLockState()));
1440 // Setup "Information"
1441 DolphinDockWidget
* infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
1442 infoDock
->setLocked(lock
);
1443 infoDock
->setObjectName("infoDock");
1444 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1445 Panel
* infoPanel
= new InformationPanel(infoDock
);
1446 infoPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1447 connect(infoPanel
, SIGNAL(urlActivated(KUrl
)), this, SLOT(handleUrl(KUrl
)));
1448 infoDock
->setWidget(infoPanel
);
1450 QAction
* infoAction
= infoDock
->toggleViewAction();
1451 createPanelAction(KIcon("dialog-information"), Qt::Key_F11
, infoAction
, "show_information_panel");
1453 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1454 connect(this, SIGNAL(urlChanged(KUrl
)),
1455 infoPanel
, SLOT(setUrl(KUrl
)));
1456 connect(this, SIGNAL(selectionChanged(KFileItemList
)),
1457 infoPanel
, SLOT(setSelection(KFileItemList
)));
1458 connect(this, SIGNAL(requestItemInfo(KFileItem
)),
1459 infoPanel
, SLOT(requestDelayedItemInfo(KFileItem
)));
1462 DolphinDockWidget
* foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
1463 foldersDock
->setLocked(lock
);
1464 foldersDock
->setObjectName("foldersDock");
1465 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1466 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1467 foldersPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1468 foldersDock
->setWidget(foldersPanel
);
1470 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1471 createPanelAction(KIcon("folder"), Qt::Key_F7
, foldersAction
, "show_folders_panel");
1473 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1474 connect(this, SIGNAL(urlChanged(KUrl
)),
1475 foldersPanel
, SLOT(setUrl(KUrl
)));
1476 connect(foldersPanel
, SIGNAL(folderActivated(KUrl
)),
1477 this, SLOT(changeUrl(KUrl
)));
1478 connect(foldersPanel
, SIGNAL(folderMiddleClicked(KUrl
)),
1479 this, SLOT(openNewTab(KUrl
)));
1480 connect(foldersPanel
, SIGNAL(errorMessage(QString
)),
1481 this, SLOT(slotPanelErrorMessage(QString
)));
1485 DolphinDockWidget
* terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1486 terminalDock
->setLocked(lock
);
1487 terminalDock
->setObjectName("terminalDock");
1488 terminalDock
->setAllowedAreas(Qt::TopDockWidgetArea
| Qt::BottomDockWidgetArea
);
1489 Panel
* terminalPanel
= new TerminalPanel(terminalDock
);
1490 terminalPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1491 terminalDock
->setWidget(terminalPanel
);
1493 connect(terminalPanel
, SIGNAL(hideTerminalPanel()), terminalDock
, SLOT(hide()));
1494 connect(terminalPanel
, SIGNAL(changeUrl(KUrl
)), this, SLOT(slotTerminalDirectoryChanged(KUrl
)));
1495 connect(terminalDock
, SIGNAL(visibilityChanged(bool)),
1496 terminalPanel
, SLOT(dockVisibilityChanged()));
1498 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1499 createPanelAction(KIcon("utilities-terminal"), Qt::Key_F4
, terminalAction
, "show_terminal_panel");
1501 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1502 connect(this, SIGNAL(urlChanged(KUrl
)),
1503 terminalPanel
, SLOT(setUrl(KUrl
)));
1506 if (GeneralSettings::version() < 200) {
1508 foldersDock
->hide();
1510 terminalDock
->hide();
1515 DolphinDockWidget
* placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
1516 placesDock
->setLocked(lock
);
1517 placesDock
->setObjectName("placesDock");
1518 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1520 PlacesPanel
* placesPanel
= new PlacesPanel(placesDock
);
1521 placesPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1522 placesDock
->setWidget(placesPanel
);
1524 QAction
* placesAction
= placesDock
->toggleViewAction();
1525 createPanelAction(KIcon("bookmarks"), Qt::Key_F9
, placesAction
, "show_places_panel");
1527 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1528 connect(placesPanel
, SIGNAL(placeActivated(KUrl
)),
1529 this, SLOT(slotPlaceActivated(KUrl
)));
1530 connect(placesPanel
, SIGNAL(placeMiddleClicked(KUrl
)),
1531 this, SLOT(openNewTab(KUrl
)));
1532 connect(placesPanel
, SIGNAL(errorMessage(QString
)),
1533 this, SLOT(slotPanelErrorMessage(QString
)));
1534 connect(this, SIGNAL(urlChanged(KUrl
)),
1535 placesPanel
, SLOT(setUrl(KUrl
)));
1536 connect(placesDock
, SIGNAL(visibilityChanged(bool)),
1537 this, SLOT(slotPlacesPanelVisibilityChanged(bool)));
1538 connect(this, SIGNAL(settingsChanged()),
1539 placesPanel
, SLOT(readSettings()));
1541 // Add actions into the "Panels" menu
1542 KActionMenu
* panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Panels"), this);
1543 actionCollection()->addAction("panels", panelsMenu
);
1544 panelsMenu
->setDelayed(false);
1545 const KActionCollection
* ac
= actionCollection();
1546 panelsMenu
->addAction(ac
->action("show_places_panel"));
1547 panelsMenu
->addAction(ac
->action("show_information_panel"));
1548 panelsMenu
->addAction(ac
->action("show_folders_panel"));
1550 panelsMenu
->addAction(ac
->action("show_terminal_panel"));
1552 panelsMenu
->addSeparator();
1553 panelsMenu
->addAction(lockLayoutAction
);
1556 void DolphinMainWindow::updateEditActions()
1558 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1559 if (list
.isEmpty()) {
1560 stateChanged("has_no_selection");
1562 stateChanged("has_selection");
1564 KActionCollection
* col
= actionCollection();
1565 QAction
* renameAction
= col
->action("rename");
1566 QAction
* moveToTrashAction
= col
->action("move_to_trash");
1567 QAction
* deleteAction
= col
->action("delete");
1568 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
1569 QAction
* deleteWithTrashShortcut
= col
->action("delete_shortcut"); // see DolphinViewActionHandler
1571 KFileItemListProperties
capabilities(list
);
1572 const bool enableMoveToTrash
= capabilities
.isLocal() && capabilities
.supportsMoving();
1574 renameAction
->setEnabled(capabilities
.supportsMoving());
1575 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1576 deleteAction
->setEnabled(capabilities
.supportsDeleting());
1577 deleteWithTrashShortcut
->setEnabled(capabilities
.supportsDeleting() && !enableMoveToTrash
);
1578 cutAction
->setEnabled(capabilities
.supportsMoving());
1582 void DolphinMainWindow::updateViewActions()
1584 m_actionHandler
->updateViewActions();
1586 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1587 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
1589 updateSplitAction();
1591 QAction
* editableLocactionAction
= actionCollection()->action("editable_location");
1592 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
1593 editableLocactionAction
->setChecked(urlNavigator
->isUrlEditable());
1596 void DolphinMainWindow::updateGoActions()
1598 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
1599 const KUrl currentUrl
= m_activeViewContainer
->url();
1600 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
1603 void DolphinMainWindow::createControlButton()
1605 if (m_controlButton
) {
1608 Q_ASSERT(!m_controlButton
);
1610 m_controlButton
= new QToolButton(this);
1611 m_controlButton
->setIcon(KIcon("applications-system"));
1612 m_controlButton
->setText(i18nc("@action", "Control"));
1613 m_controlButton
->setPopupMode(QToolButton::InstantPopup
);
1614 m_controlButton
->setToolButtonStyle(toolBar()->toolButtonStyle());
1616 KMenu
* controlMenu
= new KMenu(m_controlButton
);
1617 connect(controlMenu
, SIGNAL(aboutToShow()), this, SLOT(updateControlMenu()));
1619 m_controlButton
->setMenu(controlMenu
);
1621 toolBar()->addWidget(m_controlButton
);
1622 connect(toolBar(), SIGNAL(iconSizeChanged(QSize
)),
1623 m_controlButton
, SLOT(setIconSize(QSize
)));
1624 connect(toolBar(), SIGNAL(toolButtonStyleChanged(Qt::ToolButtonStyle
)),
1625 m_controlButton
, SLOT(setToolButtonStyle(Qt::ToolButtonStyle
)));
1627 // The added widgets are owned by the toolbar and may get deleted when e.g. the toolbar
1628 // gets edited. In this case we must add them again. The adding is done asynchronously by
1629 // m_updateToolBarTimer.
1630 connect(m_controlButton
, SIGNAL(destroyed()), this, SLOT(slotControlButtonDeleted()));
1631 m_updateToolBarTimer
= new QTimer(this);
1632 m_updateToolBarTimer
->setInterval(500);
1633 connect(m_updateToolBarTimer
, SIGNAL(timeout()), this, SLOT(updateToolBar()));
1636 void DolphinMainWindow::deleteControlButton()
1638 delete m_controlButton
;
1639 m_controlButton
= 0;
1641 delete m_updateToolBarTimer
;
1642 m_updateToolBarTimer
= 0;
1645 bool DolphinMainWindow::addActionToMenu(QAction
* action
, KMenu
* menu
)
1650 const KToolBar
* toolBarWidget
= toolBar();
1651 foreach (const QWidget
* widget
, action
->associatedWidgets()) {
1652 if (widget
== toolBarWidget
) {
1657 menu
->addAction(action
);
1661 void DolphinMainWindow::refreshViews()
1663 foreach (DolphinTabPage
* tabPage
, m_viewTab
) {
1664 tabPage
->refreshViews();
1667 if (GeneralSettings::modifiedStartupSettings()) {
1668 // The startup settings have been changed by the user (see bug #254947).
1669 // Synchronize the split-view setting with the active view:
1670 const bool splitView
= GeneralSettings::splitView();
1671 m_viewTab
.at(m_tabIndex
)->setSplitViewEnabled(splitView
);
1672 updateSplitAction();
1675 emit
settingsChanged();
1678 void DolphinMainWindow::clearStatusBar()
1680 m_activeViewContainer
->statusBar()->resetToDefaultText();
1683 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
1685 connect(container
, SIGNAL(showFilterBarChanged(bool)),
1686 this, SLOT(updateFilterBarAction(bool)));
1687 connect(container
, SIGNAL(writeStateChanged(bool)),
1688 this, SLOT(slotWriteStateChanged(bool)));
1690 const DolphinView
* view
= container
->view();
1691 connect(view
, SIGNAL(selectionChanged(KFileItemList
)),
1692 this, SLOT(slotSelectionChanged(KFileItemList
)));
1693 connect(view
, SIGNAL(requestItemInfo(KFileItem
)),
1694 this, SLOT(slotRequestItemInfo(KFileItem
)));
1695 connect(view
, SIGNAL(tabRequested(KUrl
)),
1696 this, SLOT(openNewTab(KUrl
)));
1697 connect(view
, SIGNAL(requestContextMenu(QPoint
,KFileItem
,KUrl
,QList
<QAction
*>)),
1698 this, SLOT(openContextMenu(QPoint
,KFileItem
,KUrl
,QList
<QAction
*>)));
1699 connect(view
, SIGNAL(directoryLoadingStarted()),
1700 this, SLOT(enableStopAction()));
1701 connect(view
, SIGNAL(directoryLoadingCompleted()),
1702 this, SLOT(disableStopAction()));
1703 connect(view
, SIGNAL(goBackRequested()),
1704 this, SLOT(goBack()));
1705 connect(view
, SIGNAL(goForwardRequested()),
1706 this, SLOT(goForward()));
1708 const KUrlNavigator
* navigator
= container
->urlNavigator();
1709 connect(navigator
, SIGNAL(urlChanged(KUrl
)),
1710 this, SLOT(changeUrl(KUrl
)));
1711 connect(navigator
, SIGNAL(historyChanged()),
1712 this, SLOT(updateHistory()));
1713 connect(navigator
, SIGNAL(editableStateChanged(bool)),
1714 this, SLOT(slotEditableStateChanged(bool)));
1715 connect(navigator
, SIGNAL(tabRequested(KUrl
)),
1716 this, SLOT(openNewTab(KUrl
)));
1719 void DolphinMainWindow::updateSplitAction()
1721 QAction
* splitAction
= actionCollection()->action("split_view");
1722 const DolphinTabPage
* tabPage
= m_viewTab
.at(m_tabIndex
);
1723 if (tabPage
->splitViewEnabled()) {
1724 if (tabPage
->primaryViewActive()) {
1725 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
1726 splitAction
->setToolTip(i18nc("@info", "Close left view"));
1727 splitAction
->setIcon(KIcon("view-left-close"));
1729 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
1730 splitAction
->setToolTip(i18nc("@info", "Close right view"));
1731 splitAction
->setIcon(KIcon("view-right-close"));
1734 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
1735 splitAction
->setToolTip(i18nc("@info", "Split view"));
1736 splitAction
->setIcon(KIcon("view-right-new"));
1740 QString
DolphinMainWindow::tabName(const KUrl
& url
) const
1743 if (url
.equals(KUrl("file:///"))) {
1746 name
= url
.fileName();
1747 if (name
.isEmpty()) {
1748 name
= url
.protocol();
1750 // Make sure that a '&' inside the directory name is displayed correctly
1751 // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
1752 name
.replace('&', "&&");
1758 bool DolphinMainWindow::isKompareInstalled() const
1760 static bool initialized
= false;
1761 static bool installed
= false;
1763 // TODO: maybe replace this approach later by using a menu
1764 // plugin like kdiff3plugin.cpp
1765 installed
= !KGlobal::dirs()->findExe("kompare").isEmpty();
1771 void DolphinMainWindow::setUrlAsCaption(const KUrl
& url
)
1774 if (!url
.isLocalFile()) {
1775 caption
.append(url
.protocol() + " - ");
1776 if (url
.hasHost()) {
1777 caption
.append(url
.host() + " - ");
1781 const QString fileName
= url
.fileName().isEmpty() ? "/" : url
.fileName();
1782 caption
.append(fileName
);
1784 setCaption(caption
);
1787 QString
DolphinMainWindow::squeezedText(const QString
& text
) const
1789 const QFontMetrics fm
= fontMetrics();
1790 return fm
.elidedText(text
, Qt::ElideMiddle
, fm
.maxWidth() * 10);
1793 void DolphinMainWindow::createPanelAction(const KIcon
& icon
,
1794 const QKeySequence
& shortcut
,
1795 QAction
* dockAction
,
1796 const QString
& actionName
)
1798 KAction
* panelAction
= actionCollection()->addAction(actionName
);
1799 panelAction
->setCheckable(true);
1800 panelAction
->setChecked(dockAction
->isChecked());
1801 panelAction
->setText(dockAction
->text());
1802 panelAction
->setIcon(icon
);
1803 panelAction
->setShortcut(shortcut
);
1805 connect(panelAction
, SIGNAL(triggered()), dockAction
, SLOT(trigger()));
1806 connect(dockAction
, SIGNAL(toggled(bool)), panelAction
, SLOT(setChecked(bool)));
1809 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
1810 KIO::FileUndoManager::UiInterface()
1814 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
1818 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
1820 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
1822 DolphinViewContainer
* container
= mainWin
->activeViewContainer();
1823 container
->showMessage(job
->errorString(), DolphinViewContainer::Error
);
1825 KIO::FileUndoManager::UiInterface::jobError(job
);
1829 #include "dolphinmainwindow.moc"