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 "dolphinviewcontainer.h"
29 #include "panels/folders/folderspanel.h"
30 #include "panels/places/placespanel.h"
31 #include "panels/information/informationpanel.h"
32 #include "settings/dolphinsettingsdialog.h"
33 #include "statusbar/dolphinstatusbar.h"
34 #include "views/dolphinviewactionhandler.h"
35 #include "views/dolphinremoteencoding.h"
36 #include "views/draganddrophelper.h"
37 #include "views/viewproperties.h"
40 #include "panels/terminal/terminalpanel.h"
43 #include "dolphin_generalsettings.h"
45 #include <KAcceleratorManager>
47 #include <KActionCollection>
48 #include <KActionMenu>
50 #include <KDesktopFile>
51 #include <kdeversion.h>
52 #include <kdualaction.h>
53 #include <KFileDialog>
58 #include <KIconLoader>
59 #include <KIO/NetAccess>
60 #include <KIO/JobUiDelegate>
61 #include <KInputDialog>
63 #include <KProtocolManager>
66 #include <KMessageBox>
67 #include <KFileItemListProperties>
68 #include <konqmimedata.h>
69 #include <KProtocolInfo>
72 #include <KStandardDirs>
73 #include <kstatusbar.h>
74 #include <KStandardAction>
76 #include <KToggleAction>
77 #include <KUrlNavigator>
79 #include <KUrlComboBox>
80 #include <KToolInvocation>
82 #include <QDesktopWidget>
83 #include <QDBusMessage>
86 #include <QToolButton>
90 // Used for GeneralSettings::version() to determine whether
91 // an updated version of Dolphin is running.
92 const int CurrentDolphinVersion
= 200;
96 * Remembers the tab configuration if a tab has been closed.
97 * Each closed tab can be restored by the menu
98 * "Go -> Recently Closed Tabs".
106 Q_DECLARE_METATYPE(ClosedTab
)
108 DolphinMainWindow::DolphinMainWindow() :
112 m_activeViewContainer(0),
113 m_centralWidgetLayout(0),
120 m_updateToolBarTimer(0),
121 m_lastHandleUrlStatJob(0)
123 setObjectName("Dolphin#");
125 m_viewTab
.append(ViewTab());
126 ViewTab
& viewTab
= m_viewTab
[m_tabIndex
];
127 viewTab
.wasActive
= true; // The first opened tab is automatically active
129 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
130 undoManager
->setUiInterface(new UndoUiInterface());
132 connect(undoManager
, SIGNAL(undoAvailable(bool)),
133 this, SLOT(slotUndoAvailable(bool)));
134 connect(undoManager
, SIGNAL(undoTextChanged(QString
)),
135 this, SLOT(slotUndoTextChanged(QString
)));
136 connect(undoManager
, SIGNAL(jobRecordingStarted(CommandType
)),
137 this, SLOT(clearStatusBar()));
138 connect(undoManager
, SIGNAL(jobRecordingFinished(CommandType
)),
139 this, SLOT(showCommand(CommandType
)));
141 GeneralSettings
* generalSettings
= GeneralSettings::self();
142 const bool firstRun
= (generalSettings
->version() < 200);
144 generalSettings
->setViewPropsTimestamp(QDateTime::currentDateTime());
147 setAcceptDrops(true);
149 viewTab
.splitter
= new QSplitter(this);
150 viewTab
.splitter
->setChildrenCollapsible(false);
154 const KUrl
homeUrl(generalSettings
->homeUrl());
155 setUrlAsCaption(homeUrl
);
156 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
157 connect(m_actionHandler
, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
158 connect(m_actionHandler
, SIGNAL(createDirectory()), SLOT(createDirectory()));
160 viewTab
.primaryView
= createViewContainer(homeUrl
, viewTab
.splitter
);
162 m_activeViewContainer
= viewTab
.primaryView
;
163 connectViewSignals(m_activeViewContainer
);
164 DolphinView
* view
= m_activeViewContainer
->view();
165 m_activeViewContainer
->show();
166 m_actionHandler
->setCurrentView(view
);
168 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
169 connect(this, SIGNAL(urlChanged(KUrl
)),
170 m_remoteEncoding
, SLOT(slotAboutToOpenUrl()));
172 m_tabBar
= new KTabBar(this);
173 m_tabBar
->setMovable(true);
174 m_tabBar
->setTabsClosable(true);
175 connect(m_tabBar
, SIGNAL(currentChanged(int)),
176 this, SLOT(setActiveTab(int)));
177 connect(m_tabBar
, SIGNAL(tabCloseRequested(int)),
178 this, SLOT(closeTab(int)));
179 connect(m_tabBar
, SIGNAL(contextMenu(int,QPoint
)),
180 this, SLOT(openTabContextMenu(int,QPoint
)));
181 connect(m_tabBar
, SIGNAL(newTabRequest()),
182 this, SLOT(openNewTab()));
183 connect(m_tabBar
, SIGNAL(testCanDecode(const QDragMoveEvent
*,bool&)),
184 this, SLOT(slotTestCanDecode(const QDragMoveEvent
*,bool&)));
185 connect(m_tabBar
, SIGNAL(mouseMiddleClick(int)),
186 this, SLOT(closeTab(int)));
187 connect(m_tabBar
, SIGNAL(tabMoved(int,int)),
188 this, SLOT(slotTabMoved(int,int)));
189 connect(m_tabBar
, SIGNAL(receivedDropEvent(int,QDropEvent
*)),
190 this, SLOT(tabDropEvent(int,QDropEvent
*)));
192 m_tabBar
->blockSignals(true); // signals get unblocked after at least 2 tabs are open
194 QWidget
* centralWidget
= new QWidget(this);
195 m_centralWidgetLayout
= new QVBoxLayout(centralWidget
);
196 m_centralWidgetLayout
->setSpacing(0);
197 m_centralWidgetLayout
->setMargin(0);
198 m_centralWidgetLayout
->addWidget(m_tabBar
);
199 m_centralWidgetLayout
->addWidget(viewTab
.splitter
, 1);
201 setCentralWidget(centralWidget
);
203 emit
urlChanged(homeUrl
);
205 setupGUI(Keys
| Save
| Create
| ToolBar
);
206 stateChanged("new_file");
208 QClipboard
* clipboard
= QApplication::clipboard();
209 connect(clipboard
, SIGNAL(dataChanged()),
210 this, SLOT(updatePasteAction()));
212 if (generalSettings
->splitView()) {
219 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
220 showFilterBarAction
->setChecked(generalSettings
->filterBar());
223 menuBar()->setVisible(false);
224 // Assure a proper default size if Dolphin runs the first time
228 const bool showMenu
= !menuBar()->isHidden();
229 QAction
* showMenuBarAction
= actionCollection()->action(KStandardAction::name(KStandardAction::ShowMenubar
));
230 showMenuBarAction
->setChecked(showMenu
); // workaround for bug #171080
232 createControlButton();
236 DolphinMainWindow::~DolphinMainWindow()
240 void DolphinMainWindow::openDirectories(const QList
<KUrl
>& dirs
)
242 if (dirs
.isEmpty()) {
246 if (dirs
.count() == 1) {
247 m_activeViewContainer
->setUrl(dirs
.first());
251 const int oldOpenTabsCount
= m_viewTab
.count();
253 const bool hasSplitView
= GeneralSettings::splitView();
255 // Open each directory inside a new tab. If the "split view" option has been enabled,
256 // always show two directories within one tab.
257 QList
<KUrl
>::const_iterator it
= dirs
.begin();
258 while (it
!= dirs
.end()) {
262 if (hasSplitView
&& (it
!= dirs
.end())) {
263 const int tabIndex
= m_viewTab
.count() - 1;
264 m_viewTab
[tabIndex
].secondaryView
->setUrl(*it
);
269 // Remove the previously opened tabs
270 for (int i
= 0; i
< oldOpenTabsCount
; ++i
) {
275 void DolphinMainWindow::openFiles(const QList
<KUrl
>& files
)
277 if (files
.isEmpty()) {
281 // Get all distinct directories from 'files' and open a tab
282 // for each directory. If the "split view" option is enabled, two
283 // directories are shown inside one tab (see openDirectories()).
285 foreach (const KUrl
& url
, files
) {
286 const KUrl
dir(url
.directory());
287 if (!dirs
.contains(dir
)) {
292 openDirectories(dirs
);
294 // Select the files. Although the files can be split between several
295 // tabs, there is no need to split 'files' accordingly, as
296 // the DolphinView will just ignore invalid selections.
297 const int tabCount
= m_viewTab
.count();
298 for (int i
= 0; i
< tabCount
; ++i
) {
299 m_viewTab
[i
].primaryView
->view()->markUrlsAsSelected(files
);
300 m_viewTab
[i
].primaryView
->view()->markUrlAsCurrent(files
.at(0));
301 if (m_viewTab
[i
].secondaryView
) {
302 m_viewTab
[i
].secondaryView
->view()->markUrlsAsSelected(files
);
303 m_viewTab
[i
].secondaryView
->view()->markUrlAsCurrent(files
.at(0));
308 void DolphinMainWindow::showCommand(CommandType command
)
310 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
312 case KIO::FileUndoManager::Copy
:
313 statusBar
->setText(i18nc("@info:status", "Successfully copied."));
315 case KIO::FileUndoManager::Move
:
316 statusBar
->setText(i18nc("@info:status", "Successfully moved."));
318 case KIO::FileUndoManager::Link
:
319 statusBar
->setText(i18nc("@info:status", "Successfully linked."));
321 case KIO::FileUndoManager::Trash
:
322 statusBar
->setText(i18nc("@info:status", "Successfully moved to trash."));
324 case KIO::FileUndoManager::Rename
:
325 statusBar
->setText(i18nc("@info:status", "Successfully renamed."));
328 case KIO::FileUndoManager::Mkdir
:
329 statusBar
->setText(i18nc("@info:status", "Created folder."));
337 void DolphinMainWindow::pasteIntoFolder()
339 m_activeViewContainer
->view()->pasteIntoFolder();
342 void DolphinMainWindow::changeUrl(const KUrl
& url
)
344 if (!KProtocolManager::supportsListing(url
)) {
345 // The URL navigator only checks for validity, not
346 // if the URL can be listed. An error message is
347 // shown due to DolphinViewContainer::restoreView().
351 DolphinViewContainer
* view
= activeViewContainer();
357 setUrlAsCaption(url
);
358 if (m_viewTab
.count() > 1) {
359 m_tabBar
->setTabText(m_tabIndex
, squeezedText(tabName(m_activeViewContainer
->url())));
361 const QString iconName
= KMimeType::iconNameForUrl(url
);
362 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(iconName
));
363 emit
urlChanged(url
);
367 void DolphinMainWindow::slotTerminalDirectoryChanged(const KUrl
& url
)
369 m_activeViewContainer
->setAutoGrabFocus(false);
371 m_activeViewContainer
->setAutoGrabFocus(true);
374 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
376 KToggleAction
* editableLocationAction
=
377 static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
378 editableLocationAction
->setChecked(editable
);
381 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
385 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
386 int selectedUrlsCount
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedItemsCount();
387 if (m_viewTab
[m_tabIndex
].secondaryView
) {
388 selectedUrlsCount
+= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItemsCount();
391 QAction
* compareFilesAction
= actionCollection()->action("compare_files");
392 if (selectedUrlsCount
== 2) {
393 compareFilesAction
->setEnabled(isKompareInstalled());
395 compareFilesAction
->setEnabled(false);
398 emit
selectionChanged(selection
);
401 void DolphinMainWindow::slotRequestItemInfo(const KFileItem
& item
)
403 emit
requestItemInfo(item
);
406 void DolphinMainWindow::updateHistory()
408 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
409 const int index
= urlNavigator
->historyIndex();
411 QAction
* backAction
= actionCollection()->action("go_back");
413 backAction
->setToolTip(i18nc("@info", "Go back"));
414 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
417 QAction
* forwardAction
= actionCollection()->action("go_forward");
419 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
420 forwardAction
->setEnabled(index
> 0);
424 void DolphinMainWindow::updateFilterBarAction(bool show
)
426 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
427 showFilterBarAction
->setChecked(show
);
430 void DolphinMainWindow::openNewMainWindow()
432 KRun::run("dolphin %u", KUrl::List(), this);
435 void DolphinMainWindow::openNewTab()
437 const bool isUrlEditable
= m_activeViewContainer
->urlNavigator()->isUrlEditable();
439 openNewTab(m_activeViewContainer
->url());
440 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
442 // The URL navigator of the new tab should have the same editable state
443 // as the current tab
444 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
445 navigator
->setUrlEditable(isUrlEditable
);
448 // If a new tab is opened and the URL is editable, assure that
449 // the user can edit the URL without manually setting the focus
450 navigator
->setFocus();
454 void DolphinMainWindow::openNewTab(const KUrl
& url
)
456 QWidget
* focusWidget
= QApplication::focusWidget();
458 if (m_viewTab
.count() == 1) {
459 // Only one view is open currently and hence no tab is shown at
460 // all. Before creating a tab for 'url', provide a tab for the current URL.
461 const KUrl currentUrl
= m_activeViewContainer
->url();
462 m_tabBar
->addTab(KIcon(KMimeType::iconNameForUrl(currentUrl
)),
463 squeezedText(tabName(currentUrl
)));
464 m_tabBar
->blockSignals(false);
467 m_tabBar
->addTab(KIcon(KMimeType::iconNameForUrl(url
)),
468 squeezedText(tabName(url
)));
471 viewTab
.splitter
= new QSplitter(this);
472 viewTab
.splitter
->setChildrenCollapsible(false);
473 viewTab
.primaryView
= createViewContainer(url
, viewTab
.splitter
);
474 viewTab
.primaryView
->setActive(false);
475 connectViewSignals(viewTab
.primaryView
);
477 m_viewTab
.append(viewTab
);
479 actionCollection()->action("close_tab")->setEnabled(true);
481 // Provide a split view, if the startup settings are set this way
482 if (GeneralSettings::splitView()) {
483 const int newTabIndex
= m_viewTab
.count() - 1;
484 createSecondaryView(newTabIndex
);
485 m_viewTab
[newTabIndex
].secondaryView
->setActive(true);
486 m_viewTab
[newTabIndex
].isPrimaryViewActive
= false;
490 // The DolphinViewContainer grabbed the keyboard focus. As the tab is opened
491 // in background, assure that the previous focused widget gets the focus back.
492 focusWidget
->setFocus();
496 void DolphinMainWindow::openNewActivatedTab(const KUrl
& url
)
499 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
502 void DolphinMainWindow::activateNextTab()
504 if (m_viewTab
.count() >= 2) {
505 const int tabIndex
= (m_tabBar
->currentIndex() + 1) % m_tabBar
->count();
506 m_tabBar
->setCurrentIndex(tabIndex
);
510 void DolphinMainWindow::activatePrevTab()
512 if (m_viewTab
.count() >= 2) {
513 int tabIndex
= m_tabBar
->currentIndex() - 1;
514 if (tabIndex
== -1) {
515 tabIndex
= m_tabBar
->count() - 1;
517 m_tabBar
->setCurrentIndex(tabIndex
);
521 void DolphinMainWindow::openInNewTab()
523 const KFileItemList
& list
= m_activeViewContainer
->view()->selectedItems();
524 if (list
.isEmpty()) {
525 openNewTab(m_activeViewContainer
->url());
527 foreach (const KFileItem
& item
, list
) {
528 const KUrl
& url
= DolphinView::openItemAsFolderUrl(item
);
529 if (!url
.isEmpty()) {
536 void DolphinMainWindow::openInNewWindow()
540 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
541 if (list
.isEmpty()) {
542 newWindowUrl
= m_activeViewContainer
->url();
543 } else if (list
.count() == 1) {
544 const KFileItem
& item
= list
.first();
545 newWindowUrl
= DolphinView::openItemAsFolderUrl(item
);
548 if (!newWindowUrl
.isEmpty()) {
549 KRun::run("dolphin %u", KUrl::List() << newWindowUrl
, this);
553 void DolphinMainWindow::toggleActiveView()
555 if (!m_viewTab
[m_tabIndex
].secondaryView
) {
556 // only one view is available
560 Q_ASSERT(m_activeViewContainer
);
561 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
563 DolphinViewContainer
* left
= m_viewTab
[m_tabIndex
].primaryView
;
564 DolphinViewContainer
* right
= m_viewTab
[m_tabIndex
].secondaryView
;
565 setActiveViewContainer(m_activeViewContainer
== right
? left
: right
);
568 void DolphinMainWindow::showEvent(QShowEvent
* event
)
570 KXmlGuiWindow::showEvent(event
);
571 if (!event
->spontaneous()) {
572 m_activeViewContainer
->view()->setFocus();
576 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
578 // Find out if Dolphin is closed directly by the user or
579 // by the session manager because the session is closed
580 bool closedByUser
= true;
581 DolphinApplication
*application
= qobject_cast
<DolphinApplication
*>(qApp
);
582 if (application
&& application
->sessionSaving()) {
583 closedByUser
= false;
586 if (m_viewTab
.count() > 1 && GeneralSettings::confirmClosingMultipleTabs() && closedByUser
) {
587 // Ask the user if he really wants to quit and close all tabs.
588 // Open a confirmation dialog with 3 buttons:
589 // KDialog::Yes -> Quit
590 // KDialog::No -> Close only the current tab
591 // KDialog::Cancel -> do nothing
592 KDialog
*dialog
= new KDialog(this, Qt::Dialog
);
593 dialog
->setCaption(i18nc("@title:window", "Confirmation"));
594 dialog
->setButtons(KDialog::Yes
| KDialog::No
| KDialog::Cancel
);
595 dialog
->setModal(true);
596 dialog
->setButtonGuiItem(KDialog::Yes
, KStandardGuiItem::quit());
597 dialog
->setButtonGuiItem(KDialog::No
, KGuiItem(i18n("C&lose Current Tab"), KIcon("tab-close")));
598 dialog
->setButtonGuiItem(KDialog::Cancel
, KStandardGuiItem::cancel());
599 dialog
->setDefaultButton(KDialog::Yes
);
601 bool doNotAskAgainCheckboxResult
= false;
603 const int result
= KMessageBox::createKMessageBox(dialog
,
604 QMessageBox::Warning
,
605 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
607 i18n("Do not ask again"),
608 &doNotAskAgainCheckboxResult
,
609 KMessageBox::Notify
);
611 if (doNotAskAgainCheckboxResult
) {
612 GeneralSettings::setConfirmClosingMultipleTabs(false);
620 // Close only the current tab
628 GeneralSettings::setVersion(CurrentDolphinVersion
);
629 GeneralSettings::self()->writeConfig();
631 KXmlGuiWindow::closeEvent(event
);
634 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
636 const int tabCount
= m_viewTab
.count();
637 group
.writeEntry("Tab Count", tabCount
);
638 group
.writeEntry("Active Tab Index", m_tabBar
->currentIndex());
640 for (int i
= 0; i
< tabCount
; ++i
) {
641 const DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
642 group
.writeEntry(tabProperty("Primary URL", i
), cont
->url().url());
643 group
.writeEntry(tabProperty("Primary Editable", i
),
644 cont
->urlNavigator()->isUrlEditable());
646 cont
= m_viewTab
[i
].secondaryView
;
648 group
.writeEntry(tabProperty("Secondary URL", i
), cont
->url().url());
649 group
.writeEntry(tabProperty("Secondary Editable", i
),
650 cont
->urlNavigator()->isUrlEditable());
655 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
657 const int tabCount
= group
.readEntry("Tab Count", 1);
658 for (int i
= 0; i
< tabCount
; ++i
) {
659 DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
661 cont
->setUrl(group
.readEntry(tabProperty("Primary URL", i
)));
662 const bool editable
= group
.readEntry(tabProperty("Primary Editable", i
), false);
663 cont
->urlNavigator()->setUrlEditable(editable
);
665 cont
= m_viewTab
[i
].secondaryView
;
666 const QString secondaryUrl
= group
.readEntry(tabProperty("Secondary URL", i
));
667 if (!secondaryUrl
.isEmpty()) {
669 // a secondary view should be shown, but no one is available
670 // currently -> create a new view
672 cont
= m_viewTab
[i
].secondaryView
;
676 cont
->setUrl(secondaryUrl
);
677 const bool editable
= group
.readEntry(tabProperty("Secondary Editable", i
), false);
678 cont
->urlNavigator()->setUrlEditable(editable
);
680 // no secondary view should be shown, but the default setting shows
681 // one already -> close the view
685 // openNewTab() needs to be called only tabCount - 1 times
686 if (i
!= tabCount
- 1) {
691 const int index
= group
.readEntry("Active Tab Index", 0);
692 m_tabBar
->setCurrentIndex(index
);
695 void DolphinMainWindow::updateNewMenu()
697 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
698 m_newFileMenu
->checkUpToDate();
699 m_newFileMenu
->setPopupFiles(activeViewContainer()->url());
702 void DolphinMainWindow::createDirectory()
704 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
705 m_newFileMenu
->setPopupFiles(activeViewContainer()->url());
706 m_newFileMenu
->createDirectory();
709 void DolphinMainWindow::quit()
714 void DolphinMainWindow::showErrorMessage(const QString
& message
)
716 m_activeViewContainer
->showMessage(message
, DolphinViewContainer::Error
);
719 void DolphinMainWindow::slotUndoAvailable(bool available
)
721 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
723 undoAction
->setEnabled(available
);
727 void DolphinMainWindow::restoreClosedTab(QAction
* action
)
729 if (action
->data().toBool()) {
730 // clear all actions except the "Empty Recently Closed Tabs"
731 // action and the separator
732 QList
<QAction
*> actions
= m_recentTabsMenu
->menu()->actions();
733 const int count
= actions
.size();
734 for (int i
= 2; i
< count
; ++i
) {
735 m_recentTabsMenu
->menu()->removeAction(actions
.at(i
));
738 const ClosedTab closedTab
= action
->data().value
<ClosedTab
>();
739 openNewTab(closedTab
.primaryUrl
);
740 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
742 if (closedTab
.isSplit
) {
743 // create secondary view
745 m_viewTab
[m_tabIndex
].secondaryView
->setUrl(closedTab
.secondaryUrl
);
748 m_recentTabsMenu
->removeAction(action
);
751 if (m_recentTabsMenu
->menu()->actions().count() == 2) {
752 m_recentTabsMenu
->setEnabled(false);
756 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
758 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
760 undoAction
->setText(text
);
764 void DolphinMainWindow::undo()
767 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
768 KIO::FileUndoManager::self()->undo();
771 void DolphinMainWindow::cut()
773 m_activeViewContainer
->view()->cutSelectedItems();
776 void DolphinMainWindow::copy()
778 m_activeViewContainer
->view()->copySelectedItems();
781 void DolphinMainWindow::paste()
783 m_activeViewContainer
->view()->paste();
786 void DolphinMainWindow::find()
788 m_activeViewContainer
->setSearchModeEnabled(true);
791 void DolphinMainWindow::updatePasteAction()
793 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
794 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
795 pasteAction
->setEnabled(pasteInfo
.first
);
796 pasteAction
->setText(pasteInfo
.second
);
799 void DolphinMainWindow::selectAll()
803 // if the URL navigator is editable and focused, select the whole
804 // URL instead of all items of the view
806 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
807 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit(); // krazy:exclude=qclasses
808 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
809 lineEdit
->hasFocus();
811 lineEdit
->selectAll();
813 m_activeViewContainer
->view()->selectAll();
817 void DolphinMainWindow::invertSelection()
820 m_activeViewContainer
->view()->invertSelection();
823 void DolphinMainWindow::toggleSplitView()
825 if (!m_viewTab
[m_tabIndex
].secondaryView
) {
826 createSecondaryView(m_tabIndex
);
827 setActiveViewContainer(m_viewTab
[m_tabIndex
].secondaryView
);
828 } else if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
829 // remove secondary view
830 m_viewTab
[m_tabIndex
].secondaryView
->close();
831 m_viewTab
[m_tabIndex
].secondaryView
->deleteLater();
832 m_viewTab
[m_tabIndex
].secondaryView
= 0;
834 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
836 // The primary view is active and should be closed. Hence from a users point of view
837 // the content of the secondary view should be moved to the primary view.
838 // From an implementation point of view it is more efficient to close
839 // the primary view and exchange the internal pointers afterwards.
841 m_viewTab
[m_tabIndex
].primaryView
->close();
842 m_viewTab
[m_tabIndex
].primaryView
->deleteLater();
843 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
844 m_viewTab
[m_tabIndex
].secondaryView
= 0;
846 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
852 void DolphinMainWindow::reloadView()
855 m_activeViewContainer
->view()->reload();
858 void DolphinMainWindow::stopLoading()
860 m_activeViewContainer
->view()->stopLoading();
863 void DolphinMainWindow::enableStopAction()
865 actionCollection()->action("stop")->setEnabled(true);
868 void DolphinMainWindow::disableStopAction()
870 actionCollection()->action("stop")->setEnabled(false);
873 void DolphinMainWindow::showFilterBar()
875 m_activeViewContainer
->setFilterBarVisible(true);
878 void DolphinMainWindow::toggleEditLocation()
882 QAction
* action
= actionCollection()->action("editable_location");
883 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
884 urlNavigator
->setUrlEditable(action
->isChecked());
887 void DolphinMainWindow::replaceLocation()
889 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
890 navigator
->setUrlEditable(true);
891 navigator
->setFocus();
893 // select the whole text of the combo box editor
894 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit(); // krazy:exclude=qclasses
895 lineEdit
->selectAll();
898 void DolphinMainWindow::togglePanelLockState()
900 const bool newLockState
= !GeneralSettings::lockPanels();
901 foreach (QObject
* child
, children()) {
902 DolphinDockWidget
* dock
= qobject_cast
<DolphinDockWidget
*>(child
);
904 dock
->setLocked(newLockState
);
908 GeneralSettings::setLockPanels(newLockState
);
911 void DolphinMainWindow::slotPlacesPanelVisibilityChanged(bool visible
)
913 const int tabCount
= m_viewTab
.count();
914 for (int i
= 0; i
< tabCount
; ++i
) {
915 ViewTab
& tab
= m_viewTab
[i
];
916 Q_ASSERT(tab
.primaryView
);
917 tab
.primaryView
->urlNavigator()->setPlacesSelectorVisible(!visible
);
918 if (tab
.secondaryView
) {
919 tab
.secondaryView
->urlNavigator()->setPlacesSelectorVisible(!visible
);
924 void DolphinMainWindow::goBack()
926 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
927 urlNavigator
->goBack();
929 if (urlNavigator
->locationState().isEmpty()) {
930 // An empty location state indicates a redirection URL,
931 // which must be skipped too
932 urlNavigator
->goBack();
936 void DolphinMainWindow::goForward()
938 m_activeViewContainer
->urlNavigator()->goForward();
941 void DolphinMainWindow::goUp()
943 m_activeViewContainer
->urlNavigator()->goUp();
946 void DolphinMainWindow::goHome()
948 m_activeViewContainer
->urlNavigator()->goHome();
951 void DolphinMainWindow::goBack(Qt::MouseButtons buttons
)
953 // The default case (left button pressed) is handled in goBack().
954 if (buttons
== Qt::MidButton
) {
955 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
956 const int index
= urlNavigator
->historyIndex() + 1;
957 openNewTab(urlNavigator
->locationUrl(index
));
961 void DolphinMainWindow::goForward(Qt::MouseButtons buttons
)
963 // The default case (left button pressed) is handled in goForward().
964 if (buttons
== Qt::MidButton
) {
965 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
966 const int index
= urlNavigator
->historyIndex() - 1;
967 openNewTab(urlNavigator
->locationUrl(index
));
971 void DolphinMainWindow::goUp(Qt::MouseButtons buttons
)
973 // The default case (left button pressed) is handled in goUp().
974 if (buttons
== Qt::MidButton
) {
975 openNewTab(activeViewContainer()->url().upUrl());
979 void DolphinMainWindow::goHome(Qt::MouseButtons buttons
)
981 // The default case (left button pressed) is handled in goHome().
982 if (buttons
== Qt::MidButton
) {
983 openNewTab(GeneralSettings::self()->homeUrl());
987 void DolphinMainWindow::compareFiles()
989 const DolphinViewContainer
* primaryViewContainer
= m_viewTab
[m_tabIndex
].primaryView
;
990 Q_ASSERT(primaryViewContainer
);
991 KFileItemList items
= primaryViewContainer
->view()->selectedItems();
993 const DolphinViewContainer
* secondaryViewContainer
= m_viewTab
[m_tabIndex
].secondaryView
;
994 if (secondaryViewContainer
) {
995 items
.append(secondaryViewContainer
->view()->selectedItems());
998 if (items
.count() != 2) {
999 // The action is disabled in this case, but it could have been triggered
1000 // via D-Bus, see https://bugs.kde.org/show_bug.cgi?id=325517
1004 KUrl urlA
= items
.at(0).url();
1005 KUrl urlB
= items
.at(1).url();
1007 QString
command("kompare -c \"");
1008 command
.append(urlA
.pathOrUrl());
1009 command
.append("\" \"");
1010 command
.append(urlB
.pathOrUrl());
1011 command
.append('\"');
1012 KRun::runCommand(command
, "Kompare", "kompare", this);
1015 void DolphinMainWindow::toggleShowMenuBar()
1017 const bool visible
= menuBar()->isVisible();
1018 menuBar()->setVisible(!visible
);
1020 createControlButton();
1022 deleteControlButton();
1026 void DolphinMainWindow::openTerminal()
1028 QString
dir(QDir::homePath());
1030 // If the given directory is not local, it can still be the URL of an
1031 // ioslave using UDS_LOCAL_PATH which to be converted first.
1032 KUrl url
= KIO::NetAccess::mostLocalUrl(m_activeViewContainer
->url(), this);
1034 //If the URL is local after the above conversion, set the directory.
1035 if (url
.isLocalFile()) {
1036 dir
= url
.toLocalFile();
1039 KToolInvocation::invokeTerminal(QString(), dir
);
1042 void DolphinMainWindow::editSettings()
1044 if (!m_settingsDialog
) {
1045 DolphinViewContainer
* container
= activeViewContainer();
1046 container
->view()->writeSettings();
1048 const KUrl url
= container
->url();
1049 DolphinSettingsDialog
* settingsDialog
= new DolphinSettingsDialog(url
, this);
1050 connect(settingsDialog
, SIGNAL(settingsChanged()), this, SLOT(refreshViews()));
1051 settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1052 settingsDialog
->show();
1053 m_settingsDialog
= settingsDialog
;
1055 m_settingsDialog
.data()->raise();
1059 void DolphinMainWindow::setActiveTab(int index
)
1061 Q_ASSERT(index
>= 0);
1062 Q_ASSERT(index
< m_viewTab
.count());
1063 if (index
== m_tabIndex
) {
1067 // hide current tab content
1068 ViewTab
& hiddenTab
= m_viewTab
[m_tabIndex
];
1069 hiddenTab
.isPrimaryViewActive
= hiddenTab
.primaryView
->isActive();
1070 hiddenTab
.primaryView
->setActive(false);
1071 if (hiddenTab
.secondaryView
) {
1072 hiddenTab
.secondaryView
->setActive(false);
1074 QSplitter
* splitter
= m_viewTab
[m_tabIndex
].splitter
;
1076 m_centralWidgetLayout
->removeWidget(splitter
);
1078 // show active tab content
1081 ViewTab
& viewTab
= m_viewTab
[index
];
1082 m_centralWidgetLayout
->addWidget(viewTab
.splitter
, 1);
1083 viewTab
.primaryView
->show();
1084 if (viewTab
.secondaryView
) {
1085 viewTab
.secondaryView
->show();
1087 viewTab
.splitter
->show();
1089 if (!viewTab
.wasActive
) {
1090 viewTab
.wasActive
= true;
1092 // If the tab has not been activated yet the size of the KItemListView is
1093 // undefined and results in an unwanted animation. To prevent this a
1094 // reloading of the directory gets triggered.
1095 viewTab
.primaryView
->view()->reload();
1096 if (viewTab
.secondaryView
) {
1097 viewTab
.secondaryView
->view()->reload();
1101 setActiveViewContainer(viewTab
.isPrimaryViewActive
? viewTab
.primaryView
:
1102 viewTab
.secondaryView
);
1105 void DolphinMainWindow::closeTab()
1107 closeTab(m_tabBar
->currentIndex());
1110 void DolphinMainWindow::closeTab(int index
)
1112 Q_ASSERT(index
>= 0);
1113 Q_ASSERT(index
< m_viewTab
.count());
1114 if (m_viewTab
.count() == 1) {
1115 // the last tab may never get closed
1119 if (index
== m_tabIndex
) {
1120 // The tab that should be closed is the active tab. Activate the
1121 // previous tab before closing the tab.
1122 m_tabBar
->setCurrentIndex((index
> 0) ? index
- 1 : 1);
1124 rememberClosedTab(index
);
1127 m_viewTab
[index
].primaryView
->deleteLater();
1128 if (m_viewTab
[index
].secondaryView
) {
1129 m_viewTab
[index
].secondaryView
->deleteLater();
1131 m_viewTab
[index
].splitter
->deleteLater();
1132 m_viewTab
.erase(m_viewTab
.begin() + index
);
1134 m_tabBar
->blockSignals(true);
1135 m_tabBar
->removeTab(index
);
1137 if (m_tabIndex
> index
) {
1139 Q_ASSERT(m_tabIndex
>= 0);
1142 // if only one tab is left, also remove the tab entry so that
1143 // closing the last tab is not possible
1144 if (m_viewTab
.count() == 1) {
1145 m_tabBar
->removeTab(0);
1146 actionCollection()->action("close_tab")->setEnabled(false);
1148 m_tabBar
->blockSignals(false);
1152 void DolphinMainWindow::openTabContextMenu(int index
, const QPoint
& pos
)
1156 QAction
* newTabAction
= menu
.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab"));
1157 newTabAction
->setShortcut(actionCollection()->action("new_tab")->shortcut());
1159 QAction
* detachTabAction
= menu
.addAction(KIcon("tab-detach"), i18nc("@action:inmenu", "Detach Tab"));
1161 QAction
* closeOtherTabsAction
= menu
.addAction(KIcon("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs"));
1163 QAction
* closeTabAction
= menu
.addAction(KIcon("tab-close"), i18nc("@action:inmenu", "Close Tab"));
1164 closeTabAction
->setShortcut(actionCollection()->action("close_tab")->shortcut());
1165 QAction
* selectedAction
= menu
.exec(pos
);
1166 if (selectedAction
== newTabAction
) {
1167 const ViewTab
& tab
= m_viewTab
[index
];
1168 Q_ASSERT(tab
.primaryView
);
1169 const KUrl url
= tab
.secondaryView
&& tab
.secondaryView
->isActive() ?
1170 tab
.secondaryView
->url() : tab
.primaryView
->url();
1172 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
1173 } else if (selectedAction
== detachTabAction
) {
1174 const QString
separator(QLatin1Char(' '));
1175 QString command
= QLatin1String("dolphin");
1177 const ViewTab
& tab
= m_viewTab
[index
];
1178 Q_ASSERT(tab
.primaryView
);
1180 command
+= separator
+ tab
.primaryView
->url().url();
1181 if (tab
.secondaryView
) {
1182 command
+= separator
+ tab
.secondaryView
->url().url();
1183 command
+= separator
+ QLatin1String("-split");
1186 KRun::runCommand(command
, this);
1189 } else if (selectedAction
== closeOtherTabsAction
) {
1190 const int count
= m_tabBar
->count();
1191 for (int i
= 0; i
< index
; ++i
) {
1194 for (int i
= index
+ 1; i
< count
; ++i
) {
1197 } else if (selectedAction
== closeTabAction
) {
1202 void DolphinMainWindow::slotTabMoved(int from
, int to
)
1204 m_viewTab
.move(from
, to
);
1205 m_tabIndex
= m_tabBar
->currentIndex();
1208 void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent
* event
, bool& canDecode
)
1210 canDecode
= KUrl::List::canDecode(event
->mimeData());
1213 void DolphinMainWindow::handleUrl(const KUrl
& url
)
1215 delete m_lastHandleUrlStatJob
;
1216 m_lastHandleUrlStatJob
= 0;
1218 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1219 activeViewContainer()->setUrl(url
);
1220 } else if (KProtocolManager::supportsListing(url
)) {
1221 // stat the URL to see if it is a dir or not
1222 m_lastHandleUrlStatJob
= KIO::stat(url
, KIO::HideProgressInfo
);
1223 if (m_lastHandleUrlStatJob
->ui()) {
1224 m_lastHandleUrlStatJob
->ui()->setWindow(this);
1226 connect(m_lastHandleUrlStatJob
, SIGNAL(result(KJob
*)),
1227 this, SLOT(slotHandleUrlStatFinished(KJob
*)));
1230 new KRun(url
, this); // Automatically deletes itself after being finished
1234 void DolphinMainWindow::slotHandleUrlStatFinished(KJob
* job
)
1236 m_lastHandleUrlStatJob
= 0;
1237 const KIO::UDSEntry entry
= static_cast<KIO::StatJob
*>(job
)->statResult();
1238 const KUrl url
= static_cast<KIO::StatJob
*>(job
)->url();
1239 if (entry
.isDir()) {
1240 activeViewContainer()->setUrl(url
);
1242 new KRun(url
, this); // Automatically deletes itself after being finished
1246 void DolphinMainWindow::tabDropEvent(int tab
, QDropEvent
* event
)
1248 const KUrl::List urls
= KUrl::List::fromMimeData(event
->mimeData());
1249 if (!urls
.isEmpty() && tab
!= -1) {
1250 const ViewTab
& viewTab
= m_viewTab
[tab
];
1251 const DolphinView
* view
= viewTab
.isPrimaryViewActive
? viewTab
.primaryView
->view()
1252 : viewTab
.secondaryView
->view();
1254 DragAndDropHelper::dropUrls(view
->rootItem(), view
->url(), event
, error
);
1255 if (!error
.isEmpty()) {
1256 activeViewContainer()->showMessage(error
, DolphinViewContainer::Error
);
1261 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1263 newFileMenu()->setEnabled(isFolderWritable
);
1266 void DolphinMainWindow::openContextMenu(const QPoint
& pos
,
1267 const KFileItem
& item
,
1269 const QList
<QAction
*>& customActions
)
1271 QWeakPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, pos
, item
, url
);
1272 contextMenu
.data()->setCustomActions(customActions
);
1273 const DolphinContextMenu::Command command
= contextMenu
.data()->open();
1276 case DolphinContextMenu::OpenParentFolderInNewWindow
: {
1277 KRun::run("dolphin %u", KUrl::List() << item
.url().upUrl(), this);
1281 case DolphinContextMenu::OpenParentFolderInNewTab
:
1282 openNewTab(item
.url().upUrl());
1285 case DolphinContextMenu::None
:
1290 delete contextMenu
.data();
1293 void DolphinMainWindow::updateControlMenu()
1295 KMenu
* menu
= qobject_cast
<KMenu
*>(sender());
1298 // All actions get cleared by KMenu::clear(). The sub-menus are deleted
1299 // by connecting to the aboutToHide() signal from the parent-menu.
1302 KActionCollection
* ac
= actionCollection();
1304 // Add "Edit" actions
1305 bool added
= addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Undo
)), menu
) |
1306 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Find
)), menu
) |
1307 addActionToMenu(ac
->action("select_all"), menu
) |
1308 addActionToMenu(ac
->action("invert_selection"), menu
);
1311 menu
->addSeparator();
1314 // Add "View" actions
1315 if (!GeneralSettings::showZoomSlider()) {
1316 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomIn
)), menu
);
1317 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomOut
)), menu
);
1318 menu
->addSeparator();
1321 added
= addActionToMenu(ac
->action("view_mode"), menu
) |
1322 addActionToMenu(ac
->action("sort"), menu
) |
1323 addActionToMenu(ac
->action("additional_info"), menu
) |
1324 addActionToMenu(ac
->action("show_preview"), menu
) |
1325 addActionToMenu(ac
->action("show_in_groups"), menu
) |
1326 addActionToMenu(ac
->action("show_hidden_files"), menu
);
1329 menu
->addSeparator();
1332 added
= addActionToMenu(ac
->action("split_view"), menu
) |
1333 addActionToMenu(ac
->action("reload"), menu
) |
1334 addActionToMenu(ac
->action("view_properties"), menu
);
1336 menu
->addSeparator();
1339 addActionToMenu(ac
->action("panels"), menu
);
1340 KMenu
* locationBarMenu
= new KMenu(i18nc("@action:inmenu", "Location Bar"), menu
);
1341 locationBarMenu
->addAction(ac
->action("editable_location"));
1342 locationBarMenu
->addAction(ac
->action("replace_location"));
1343 menu
->addMenu(locationBarMenu
);
1345 menu
->addSeparator();
1348 KMenu
* goMenu
= new KMenu(i18nc("@action:inmenu", "Go"), menu
);
1349 connect(menu
, SIGNAL(aboutToHide()), goMenu
, SLOT(deleteLater()));
1350 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Back
)));
1351 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Forward
)));
1352 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Up
)));
1353 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Home
)));
1354 goMenu
->addAction(ac
->action("closed_tabs"));
1355 menu
->addMenu(goMenu
);
1358 KMenu
* toolsMenu
= new KMenu(i18nc("@action:inmenu", "Tools"), menu
);
1359 connect(menu
, SIGNAL(aboutToHide()), toolsMenu
, SLOT(deleteLater()));
1360 toolsMenu
->addAction(ac
->action("show_filter_bar"));
1361 toolsMenu
->addAction(ac
->action("compare_files"));
1362 toolsMenu
->addAction(ac
->action("open_terminal"));
1363 toolsMenu
->addAction(ac
->action("change_remote_encoding"));
1364 menu
->addMenu(toolsMenu
);
1366 // Add "Settings" menu entries
1367 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::KeyBindings
)), menu
);
1368 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ConfigureToolbars
)), menu
);
1369 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Preferences
)), menu
);
1372 KMenu
* helpMenu
= new KMenu(i18nc("@action:inmenu", "Help"), menu
);
1373 connect(menu
, SIGNAL(aboutToHide()), helpMenu
, SLOT(deleteLater()));
1374 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::HelpContents
)));
1375 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::WhatsThis
)));
1376 helpMenu
->addSeparator();
1377 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ReportBug
)));
1378 helpMenu
->addSeparator();
1379 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
)));
1380 helpMenu
->addSeparator();
1381 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::AboutApp
)));
1382 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::AboutKDE
)));
1383 menu
->addMenu(helpMenu
);
1385 menu
->addSeparator();
1386 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ShowMenubar
)), menu
);
1389 void DolphinMainWindow::updateToolBar()
1391 if (!menuBar()->isVisible()) {
1392 createControlButton();
1396 void DolphinMainWindow::slotControlButtonDeleted()
1398 m_controlButton
= 0;
1399 m_updateToolBarTimer
->start();
1402 void DolphinMainWindow::slotPanelErrorMessage(const QString
& error
)
1404 activeViewContainer()->showMessage(error
, DolphinViewContainer::Error
);
1407 void DolphinMainWindow::slotPlaceActivated(const KUrl
& url
)
1409 DolphinViewContainer
* view
= activeViewContainer();
1411 if (view
->url() == url
) {
1412 // We can end up here if the user clicked a device in the Places Panel
1413 // which had been unmounted earlier, see https://bugs.kde.org/show_bug.cgi?id=161385.
1420 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer
* viewContainer
)
1422 Q_ASSERT(viewContainer
);
1423 Q_ASSERT((viewContainer
== m_viewTab
[m_tabIndex
].primaryView
) ||
1424 (viewContainer
== m_viewTab
[m_tabIndex
].secondaryView
));
1425 if (m_activeViewContainer
== viewContainer
) {
1429 m_activeViewContainer
->setActive(false);
1430 m_activeViewContainer
= viewContainer
;
1432 // Activating the view container might trigger a recursive setActiveViewContainer() call
1433 // inside DolphinMainWindow::toggleActiveView() when having a split view. Temporary
1434 // disconnect the activated() signal in this case:
1435 disconnect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1436 m_activeViewContainer
->setActive(true);
1437 connect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1439 m_actionHandler
->setCurrentView(viewContainer
->view());
1442 updateEditActions();
1443 updateViewActions();
1446 const KUrl url
= m_activeViewContainer
->url();
1447 setUrlAsCaption(url
);
1448 if (m_viewTab
.count() > 1) {
1449 m_tabBar
->setTabText(m_tabIndex
, tabName(url
));
1450 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(KMimeType::iconNameForUrl(url
)));
1453 emit
urlChanged(url
);
1456 DolphinViewContainer
* DolphinMainWindow::createViewContainer(const KUrl
& url
, QWidget
* parent
)
1458 DolphinViewContainer
* container
= new DolphinViewContainer(url
, parent
);
1460 // The places-selector from the URL navigator should only be shown
1461 // if the places dock is invisible
1462 QDockWidget
* placesDock
= findChild
<QDockWidget
*>("placesDock");
1463 container
->urlNavigator()->setPlacesSelectorVisible(!placesDock
|| !placesDock
->isVisible());
1468 void DolphinMainWindow::setupActions()
1470 // setup 'File' menu
1471 m_newFileMenu
= new DolphinNewFileMenu(this);
1472 KMenu
* menu
= m_newFileMenu
->menu();
1473 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1474 menu
->setIcon(KIcon("document-new"));
1475 m_newFileMenu
->setDelayed(false);
1476 connect(menu
, SIGNAL(aboutToShow()),
1477 this, SLOT(updateNewMenu()));
1479 KAction
* newWindow
= actionCollection()->addAction("new_window");
1480 newWindow
->setIcon(KIcon("window-new"));
1481 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1482 newWindow
->setShortcut(Qt::CTRL
| Qt::Key_N
);
1483 connect(newWindow
, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1485 KAction
* newTab
= actionCollection()->addAction("new_tab");
1486 newTab
->setIcon(KIcon("tab-new"));
1487 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1488 newTab
->setShortcut(KShortcut(Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
));
1489 connect(newTab
, SIGNAL(triggered()), this, SLOT(openNewTab()));
1491 KAction
* closeTab
= actionCollection()->addAction("close_tab");
1492 closeTab
->setIcon(KIcon("tab-close"));
1493 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1494 closeTab
->setShortcut(Qt::CTRL
| Qt::Key_W
);
1495 closeTab
->setEnabled(false);
1496 connect(closeTab
, SIGNAL(triggered()), this, SLOT(closeTab()));
1498 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1500 // setup 'Edit' menu
1501 KStandardAction::undo(this,
1503 actionCollection());
1505 // need to remove shift+del from cut action, else the shortcut for deletejob
1507 KAction
* cut
= KStandardAction::cut(this, SLOT(cut()), actionCollection());
1508 KShortcut cutShortcut
= cut
->shortcut();
1509 cutShortcut
.remove(Qt::SHIFT
| Qt::Key_Delete
, KShortcut::KeepEmpty
);
1510 cut
->setShortcut(cutShortcut
);
1511 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1512 KAction
* paste
= KStandardAction::paste(this, SLOT(paste()), actionCollection());
1513 // The text of the paste-action is modified dynamically by Dolphin
1514 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1515 // due to the long text, the text "Paste" is used:
1516 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1518 KStandardAction::find(this, SLOT(find()), actionCollection());
1520 KAction
* selectAll
= actionCollection()->addAction("select_all");
1521 selectAll
->setText(i18nc("@action:inmenu Edit", "Select All"));
1522 selectAll
->setShortcut(Qt::CTRL
| Qt::Key_A
);
1523 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
1525 KAction
* invertSelection
= actionCollection()->addAction("invert_selection");
1526 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1527 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1528 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
1530 // setup 'View' menu
1531 // (note that most of it is set up in DolphinViewActionHandler)
1533 KAction
* split
= actionCollection()->addAction("split_view");
1534 split
->setShortcut(Qt::Key_F3
);
1535 updateSplitAction();
1536 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1538 KAction
* reload
= actionCollection()->addAction("reload");
1539 reload
->setText(i18nc("@action:inmenu View", "Reload"));
1540 reload
->setShortcut(Qt::Key_F5
);
1541 reload
->setIcon(KIcon("view-refresh"));
1542 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
1544 KAction
* stop
= actionCollection()->addAction("stop");
1545 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1546 stop
->setToolTip(i18nc("@info", "Stop loading"));
1547 stop
->setIcon(KIcon("process-stop"));
1548 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
1550 KToggleAction
* editableLocation
= actionCollection()->add
<KToggleAction
>("editable_location");
1551 editableLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1552 editableLocation
->setShortcut(Qt::Key_F6
);
1553 connect(editableLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1555 KAction
* replaceLocation
= actionCollection()->addAction("replace_location");
1556 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1557 replaceLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
1558 connect(replaceLocation
, SIGNAL(triggered()), this, SLOT(replaceLocation()));
1561 KAction
* backAction
= KStandardAction::back(this, SLOT(goBack()), actionCollection());
1562 connect(backAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goBack(Qt::MouseButtons
)));
1563 KShortcut backShortcut
= backAction
->shortcut();
1564 backShortcut
.setAlternate(Qt::Key_Backspace
);
1565 backAction
->setShortcut(backShortcut
);
1567 m_recentTabsMenu
= new KActionMenu(i18n("Recently Closed Tabs"), this);
1568 m_recentTabsMenu
->setIcon(KIcon("edit-undo"));
1569 m_recentTabsMenu
->setDelayed(false);
1570 actionCollection()->addAction("closed_tabs", m_recentTabsMenu
);
1571 connect(m_recentTabsMenu
->menu(), SIGNAL(triggered(QAction
*)),
1572 this, SLOT(restoreClosedTab(QAction
*)));
1574 QAction
* action
= new QAction(i18n("Empty Recently Closed Tabs"), m_recentTabsMenu
);
1575 action
->setIcon(KIcon("edit-clear-list"));
1576 action
->setData(QVariant::fromValue(true));
1577 m_recentTabsMenu
->addAction(action
);
1578 m_recentTabsMenu
->addSeparator();
1579 m_recentTabsMenu
->setEnabled(false);
1581 KAction
* forwardAction
= KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1582 connect(forwardAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goForward(Qt::MouseButtons
)));
1584 KAction
* upAction
= KStandardAction::up(this, SLOT(goUp()), actionCollection());
1585 connect(upAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goUp(Qt::MouseButtons
)));
1587 KAction
* homeAction
= KStandardAction::home(this, SLOT(goHome()), actionCollection());
1588 connect(homeAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goHome(Qt::MouseButtons
)));
1590 // setup 'Tools' menu
1591 KAction
* showFilterBar
= actionCollection()->addAction("show_filter_bar");
1592 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1593 showFilterBar
->setIcon(KIcon("view-filter"));
1594 showFilterBar
->setShortcut(Qt::CTRL
| Qt::Key_I
);
1595 connect(showFilterBar
, SIGNAL(triggered()), this, SLOT(showFilterBar()));
1597 KAction
* compareFiles
= actionCollection()->addAction("compare_files");
1598 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1599 compareFiles
->setIcon(KIcon("kompare"));
1600 compareFiles
->setEnabled(false);
1601 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
1603 KAction
* openTerminal
= actionCollection()->addAction("open_terminal");
1604 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1605 openTerminal
->setIcon(KIcon("utilities-terminal"));
1606 openTerminal
->setShortcut(Qt::SHIFT
| Qt::Key_F4
);
1607 connect(openTerminal
, SIGNAL(triggered()), this, SLOT(openTerminal()));
1609 // setup 'Settings' menu
1610 KToggleAction
* showMenuBar
= KStandardAction::showMenubar(0, 0, actionCollection());
1611 connect(showMenuBar
, SIGNAL(triggered(bool)), // Fixes #286822
1612 this, SLOT(toggleShowMenuBar()), Qt::QueuedConnection
);
1613 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1615 // not in menu actions
1616 QList
<QKeySequence
> nextTabKeys
;
1617 nextTabKeys
.append(KStandardShortcut::tabNext().primary());
1618 nextTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::Key_Tab
));
1620 QList
<QKeySequence
> prevTabKeys
;
1621 prevTabKeys
.append(KStandardShortcut::tabPrev().primary());
1622 prevTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::SHIFT
| Qt::Key_Tab
));
1624 KAction
* activateNextTab
= actionCollection()->addAction("activate_next_tab");
1625 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1626 connect(activateNextTab
, SIGNAL(triggered()), SLOT(activateNextTab()));
1627 activateNextTab
->setShortcuts(QApplication::isRightToLeft() ? prevTabKeys
: nextTabKeys
);
1629 KAction
* activatePrevTab
= actionCollection()->addAction("activate_prev_tab");
1630 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1631 connect(activatePrevTab
, SIGNAL(triggered()), SLOT(activatePrevTab()));
1632 activatePrevTab
->setShortcuts(QApplication::isRightToLeft() ? nextTabKeys
: prevTabKeys
);
1635 KAction
* openInNewTab
= actionCollection()->addAction("open_in_new_tab");
1636 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1637 openInNewTab
->setIcon(KIcon("tab-new"));
1638 connect(openInNewTab
, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1640 KAction
* openInNewTabs
= actionCollection()->addAction("open_in_new_tabs");
1641 openInNewTabs
->setText(i18nc("@action:inmenu", "Open in New Tabs"));
1642 openInNewTabs
->setIcon(KIcon("tab-new"));
1643 connect(openInNewTabs
, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1645 KAction
* openInNewWindow
= actionCollection()->addAction("open_in_new_window");
1646 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1647 openInNewWindow
->setIcon(KIcon("window-new"));
1648 connect(openInNewWindow
, SIGNAL(triggered()), this, SLOT(openInNewWindow()));
1651 void DolphinMainWindow::setupDockWidgets()
1653 const bool lock
= GeneralSettings::lockPanels();
1655 KDualAction
* lockLayoutAction
= actionCollection()->add
<KDualAction
>("lock_panels");
1656 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
1657 lockLayoutAction
->setActiveIcon(KIcon("object-unlocked"));
1658 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
1659 lockLayoutAction
->setInactiveIcon(KIcon("object-locked"));
1660 lockLayoutAction
->setActive(lock
);
1661 connect(lockLayoutAction
, SIGNAL(triggered()), this, SLOT(togglePanelLockState()));
1663 // Setup "Information"
1664 DolphinDockWidget
* infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
1665 infoDock
->setLocked(lock
);
1666 infoDock
->setObjectName("infoDock");
1667 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1668 Panel
* infoPanel
= new InformationPanel(infoDock
);
1669 infoPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1670 connect(infoPanel
, SIGNAL(urlActivated(KUrl
)), this, SLOT(handleUrl(KUrl
)));
1671 infoDock
->setWidget(infoPanel
);
1673 QAction
* infoAction
= infoDock
->toggleViewAction();
1674 createPanelAction(KIcon("dialog-information"), Qt::Key_F11
, infoAction
, "show_information_panel");
1676 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1677 connect(this, SIGNAL(urlChanged(KUrl
)),
1678 infoPanel
, SLOT(setUrl(KUrl
)));
1679 connect(this, SIGNAL(selectionChanged(KFileItemList
)),
1680 infoPanel
, SLOT(setSelection(KFileItemList
)));
1681 connect(this, SIGNAL(requestItemInfo(KFileItem
)),
1682 infoPanel
, SLOT(requestDelayedItemInfo(KFileItem
)));
1685 DolphinDockWidget
* foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
1686 foldersDock
->setLocked(lock
);
1687 foldersDock
->setObjectName("foldersDock");
1688 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1689 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1690 foldersPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1691 foldersDock
->setWidget(foldersPanel
);
1693 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1694 createPanelAction(KIcon("folder"), Qt::Key_F7
, foldersAction
, "show_folders_panel");
1696 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1697 connect(this, SIGNAL(urlChanged(KUrl
)),
1698 foldersPanel
, SLOT(setUrl(KUrl
)));
1699 connect(foldersPanel
, SIGNAL(folderActivated(KUrl
)),
1700 this, SLOT(changeUrl(KUrl
)));
1701 connect(foldersPanel
, SIGNAL(folderMiddleClicked(KUrl
)),
1702 this, SLOT(openNewTab(KUrl
)));
1703 connect(foldersPanel
, SIGNAL(errorMessage(QString
)),
1704 this, SLOT(slotPanelErrorMessage(QString
)));
1708 DolphinDockWidget
* terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1709 terminalDock
->setLocked(lock
);
1710 terminalDock
->setObjectName("terminalDock");
1711 terminalDock
->setAllowedAreas(Qt::TopDockWidgetArea
| Qt::BottomDockWidgetArea
);
1712 Panel
* terminalPanel
= new TerminalPanel(terminalDock
);
1713 terminalPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1714 terminalDock
->setWidget(terminalPanel
);
1716 connect(terminalPanel
, SIGNAL(hideTerminalPanel()), terminalDock
, SLOT(hide()));
1717 connect(terminalPanel
, SIGNAL(changeUrl(KUrl
)), this, SLOT(slotTerminalDirectoryChanged(KUrl
)));
1718 connect(terminalDock
, SIGNAL(visibilityChanged(bool)),
1719 terminalPanel
, SLOT(dockVisibilityChanged()));
1721 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1722 createPanelAction(KIcon("utilities-terminal"), Qt::Key_F4
, terminalAction
, "show_terminal_panel");
1724 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1725 connect(this, SIGNAL(urlChanged(KUrl
)),
1726 terminalPanel
, SLOT(setUrl(KUrl
)));
1729 if (GeneralSettings::version() < 200) {
1731 foldersDock
->hide();
1733 terminalDock
->hide();
1738 DolphinDockWidget
* placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
1739 placesDock
->setLocked(lock
);
1740 placesDock
->setObjectName("placesDock");
1741 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1743 PlacesPanel
* placesPanel
= new PlacesPanel(placesDock
);
1744 placesPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1745 placesDock
->setWidget(placesPanel
);
1747 QAction
* placesAction
= placesDock
->toggleViewAction();
1748 createPanelAction(KIcon("bookmarks"), Qt::Key_F9
, placesAction
, "show_places_panel");
1750 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1751 connect(placesPanel
, SIGNAL(placeActivated(KUrl
)),
1752 this, SLOT(slotPlaceActivated(KUrl
)));
1753 connect(placesPanel
, SIGNAL(placeMiddleClicked(KUrl
)),
1754 this, SLOT(openNewTab(KUrl
)));
1755 connect(placesPanel
, SIGNAL(errorMessage(QString
)),
1756 this, SLOT(slotPanelErrorMessage(QString
)));
1757 connect(this, SIGNAL(urlChanged(KUrl
)),
1758 placesPanel
, SLOT(setUrl(KUrl
)));
1759 connect(placesDock
, SIGNAL(visibilityChanged(bool)),
1760 this, SLOT(slotPlacesPanelVisibilityChanged(bool)));
1761 connect(this, SIGNAL(settingsChanged()),
1762 placesPanel
, SLOT(readSettings()));
1764 // Add actions into the "Panels" menu
1765 KActionMenu
* panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Panels"), this);
1766 actionCollection()->addAction("panels", panelsMenu
);
1767 panelsMenu
->setDelayed(false);
1768 const KActionCollection
* ac
= actionCollection();
1769 panelsMenu
->addAction(ac
->action("show_places_panel"));
1770 panelsMenu
->addAction(ac
->action("show_information_panel"));
1771 panelsMenu
->addAction(ac
->action("show_folders_panel"));
1773 panelsMenu
->addAction(ac
->action("show_terminal_panel"));
1775 panelsMenu
->addSeparator();
1776 panelsMenu
->addAction(lockLayoutAction
);
1779 void DolphinMainWindow::updateEditActions()
1781 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1782 if (list
.isEmpty()) {
1783 stateChanged("has_no_selection");
1785 stateChanged("has_selection");
1787 KActionCollection
* col
= actionCollection();
1788 QAction
* renameAction
= col
->action("rename");
1789 QAction
* moveToTrashAction
= col
->action("move_to_trash");
1790 QAction
* deleteAction
= col
->action("delete");
1791 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
1792 QAction
* deleteWithTrashShortcut
= col
->action("delete_shortcut"); // see DolphinViewActionHandler
1794 KFileItemListProperties
capabilities(list
);
1795 const bool enableMoveToTrash
= capabilities
.isLocal() && capabilities
.supportsMoving();
1797 renameAction
->setEnabled(capabilities
.supportsMoving());
1798 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1799 deleteAction
->setEnabled(capabilities
.supportsDeleting());
1800 deleteWithTrashShortcut
->setEnabled(capabilities
.supportsDeleting() && !enableMoveToTrash
);
1801 cutAction
->setEnabled(capabilities
.supportsMoving());
1803 updatePasteAction();
1806 void DolphinMainWindow::updateViewActions()
1808 m_actionHandler
->updateViewActions();
1810 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1811 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
1813 updateSplitAction();
1815 QAction
* editableLocactionAction
= actionCollection()->action("editable_location");
1816 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
1817 editableLocactionAction
->setChecked(urlNavigator
->isUrlEditable());
1820 void DolphinMainWindow::updateGoActions()
1822 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
1823 const KUrl currentUrl
= m_activeViewContainer
->url();
1824 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
1827 void DolphinMainWindow::createControlButton()
1829 if (m_controlButton
) {
1832 Q_ASSERT(!m_controlButton
);
1834 m_controlButton
= new QToolButton(this);
1835 m_controlButton
->setIcon(KIcon("applications-system"));
1836 m_controlButton
->setText(i18nc("@action", "Control"));
1837 m_controlButton
->setPopupMode(QToolButton::InstantPopup
);
1838 m_controlButton
->setToolButtonStyle(toolBar()->toolButtonStyle());
1840 KMenu
* controlMenu
= new KMenu(m_controlButton
);
1841 connect(controlMenu
, SIGNAL(aboutToShow()), this, SLOT(updateControlMenu()));
1843 m_controlButton
->setMenu(controlMenu
);
1845 toolBar()->addWidget(m_controlButton
);
1846 connect(toolBar(), SIGNAL(iconSizeChanged(QSize
)),
1847 m_controlButton
, SLOT(setIconSize(QSize
)));
1848 connect(toolBar(), SIGNAL(toolButtonStyleChanged(Qt::ToolButtonStyle
)),
1849 m_controlButton
, SLOT(setToolButtonStyle(Qt::ToolButtonStyle
)));
1851 // The added widgets are owned by the toolbar and may get deleted when e.g. the toolbar
1852 // gets edited. In this case we must add them again. The adding is done asynchronously by
1853 // m_updateToolBarTimer.
1854 connect(m_controlButton
, SIGNAL(destroyed()), this, SLOT(slotControlButtonDeleted()));
1855 m_updateToolBarTimer
= new QTimer(this);
1856 m_updateToolBarTimer
->setInterval(500);
1857 connect(m_updateToolBarTimer
, SIGNAL(timeout()), this, SLOT(updateToolBar()));
1860 void DolphinMainWindow::deleteControlButton()
1862 delete m_controlButton
;
1863 m_controlButton
= 0;
1865 delete m_updateToolBarTimer
;
1866 m_updateToolBarTimer
= 0;
1869 bool DolphinMainWindow::addActionToMenu(QAction
* action
, KMenu
* menu
)
1874 const KToolBar
* toolBarWidget
= toolBar();
1875 foreach (const QWidget
* widget
, action
->associatedWidgets()) {
1876 if (widget
== toolBarWidget
) {
1881 menu
->addAction(action
);
1885 void DolphinMainWindow::rememberClosedTab(int index
)
1887 KMenu
* tabsMenu
= m_recentTabsMenu
->menu();
1889 const QString primaryPath
= m_viewTab
[index
].primaryView
->url().path();
1890 const QString iconName
= KMimeType::iconNameForUrl(primaryPath
);
1892 QAction
* action
= new QAction(squeezedText(primaryPath
), tabsMenu
);
1894 ClosedTab closedTab
;
1895 closedTab
.primaryUrl
= m_viewTab
[index
].primaryView
->url();
1897 if (m_viewTab
[index
].secondaryView
) {
1898 closedTab
.secondaryUrl
= m_viewTab
[index
].secondaryView
->url();
1899 closedTab
.isSplit
= true;
1901 closedTab
.isSplit
= false;
1904 action
->setData(QVariant::fromValue(closedTab
));
1905 action
->setIcon(KIcon(iconName
));
1907 // add the closed tab menu entry after the separator and
1908 // "Empty Recently Closed Tabs" entry
1909 if (tabsMenu
->actions().size() == 2) {
1910 tabsMenu
->addAction(action
);
1912 tabsMenu
->insertAction(tabsMenu
->actions().at(2), action
);
1915 // assure that only up to 8 closed tabs are shown in the menu
1916 if (tabsMenu
->actions().size() > 8) {
1917 tabsMenu
->removeAction(tabsMenu
->actions().last());
1919 actionCollection()->action("closed_tabs")->setEnabled(true);
1920 KAcceleratorManager::manage(tabsMenu
);
1923 void DolphinMainWindow::refreshViews()
1925 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
1927 // remember the current active view, as because of
1928 // the refreshing the active view might change to
1929 // the secondary view
1930 DolphinViewContainer
* activeViewContainer
= m_activeViewContainer
;
1932 const int tabCount
= m_viewTab
.count();
1933 for (int i
= 0; i
< tabCount
; ++i
) {
1934 m_viewTab
[i
].primaryView
->readSettings();
1935 if (m_viewTab
[i
].secondaryView
) {
1936 m_viewTab
[i
].secondaryView
->readSettings();
1940 setActiveViewContainer(activeViewContainer
);
1942 if (GeneralSettings::modifiedStartupSettings()) {
1943 // The startup settings have been changed by the user (see bug #254947).
1944 // Synchronize the split-view setting with the active view:
1945 const bool splitView
= GeneralSettings::splitView();
1946 const ViewTab
& activeTab
= m_viewTab
[m_tabIndex
];
1947 const bool toggle
= ( splitView
&& !activeTab
.secondaryView
)
1948 || (!splitView
&& activeTab
.secondaryView
);
1954 emit
settingsChanged();
1957 void DolphinMainWindow::clearStatusBar()
1959 m_activeViewContainer
->statusBar()->resetToDefaultText();
1962 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
1964 connect(container
, SIGNAL(showFilterBarChanged(bool)),
1965 this, SLOT(updateFilterBarAction(bool)));
1966 connect(container
, SIGNAL(writeStateChanged(bool)),
1967 this, SLOT(slotWriteStateChanged(bool)));
1969 DolphinView
* view
= container
->view();
1970 connect(view
, SIGNAL(selectionChanged(KFileItemList
)),
1971 this, SLOT(slotSelectionChanged(KFileItemList
)));
1972 connect(view
, SIGNAL(requestItemInfo(KFileItem
)),
1973 this, SLOT(slotRequestItemInfo(KFileItem
)));
1974 connect(view
, SIGNAL(activated()),
1975 this, SLOT(toggleActiveView()));
1976 connect(view
, SIGNAL(tabRequested(KUrl
)),
1977 this, SLOT(openNewTab(KUrl
)));
1978 connect(view
, SIGNAL(requestContextMenu(QPoint
,KFileItem
,KUrl
,QList
<QAction
*>)),
1979 this, SLOT(openContextMenu(QPoint
,KFileItem
,KUrl
,QList
<QAction
*>)));
1980 connect(view
, SIGNAL(directoryLoadingStarted()),
1981 this, SLOT(enableStopAction()));
1982 connect(view
, SIGNAL(directoryLoadingCompleted()),
1983 this, SLOT(disableStopAction()));
1984 connect(view
, SIGNAL(goBackRequested()),
1985 this, SLOT(goBack()));
1986 connect(view
, SIGNAL(goForwardRequested()),
1987 this, SLOT(goForward()));
1989 const KUrlNavigator
* navigator
= container
->urlNavigator();
1990 connect(navigator
, SIGNAL(urlChanged(KUrl
)),
1991 this, SLOT(changeUrl(KUrl
)));
1992 connect(navigator
, SIGNAL(historyChanged()),
1993 this, SLOT(updateHistory()));
1994 connect(navigator
, SIGNAL(editableStateChanged(bool)),
1995 this, SLOT(slotEditableStateChanged(bool)));
1996 connect(navigator
, SIGNAL(tabRequested(KUrl
)),
1997 this, SLOT(openNewTab(KUrl
)));
2000 void DolphinMainWindow::updateSplitAction()
2002 QAction
* splitAction
= actionCollection()->action("split_view");
2003 if (m_viewTab
[m_tabIndex
].secondaryView
) {
2004 if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
2005 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
2006 splitAction
->setToolTip(i18nc("@info", "Close right view"));
2007 splitAction
->setIcon(KIcon("view-right-close"));
2009 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
2010 splitAction
->setToolTip(i18nc("@info", "Close left view"));
2011 splitAction
->setIcon(KIcon("view-left-close"));
2014 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
2015 splitAction
->setToolTip(i18nc("@info", "Split view"));
2016 splitAction
->setIcon(KIcon("view-right-new"));
2020 QString
DolphinMainWindow::tabName(const KUrl
& url
) const
2023 if (url
.equals(KUrl("file:///"))) {
2026 name
= url
.fileName();
2027 if (name
.isEmpty()) {
2028 name
= url
.protocol();
2030 // Make sure that a '&' inside the directory name is displayed correctly
2031 // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
2032 name
.replace('&', "&&");
2038 bool DolphinMainWindow::isKompareInstalled() const
2040 static bool initialized
= false;
2041 static bool installed
= false;
2043 // TODO: maybe replace this approach later by using a menu
2044 // plugin like kdiff3plugin.cpp
2045 installed
= !KGlobal::dirs()->findExe("kompare").isEmpty();
2051 void DolphinMainWindow::createSecondaryView(int tabIndex
)
2053 ViewTab
& viewTab
= m_viewTab
[tabIndex
];
2055 QSplitter
* splitter
= viewTab
.splitter
;
2056 const int newWidth
= (viewTab
.primaryView
->width() - splitter
->handleWidth()) / 2;
2058 const DolphinView
* view
= viewTab
.primaryView
->view();
2059 // The final parent of the new view container will be set by adding it
2060 // to the splitter. However, we must make sure that the DolphinMainWindow
2061 // is a parent of the view container already when it is constructed
2062 // because this enables the container's KFileItemModel to assign its
2063 // dir lister to the right main window. The dir lister can then cache
2064 // authentication data.
2065 viewTab
.secondaryView
= createViewContainer(view
->url(), this);
2066 splitter
->addWidget(viewTab
.secondaryView
);
2067 splitter
->setSizes(QList
<int>() << newWidth
<< newWidth
);
2069 connectViewSignals(viewTab
.secondaryView
);
2070 viewTab
.secondaryView
->setActive(false);
2071 viewTab
.secondaryView
->resize(newWidth
, viewTab
.primaryView
->height());
2072 viewTab
.secondaryView
->show();
2075 QString
DolphinMainWindow::tabProperty(const QString
& property
, int tabIndex
) const
2077 return "Tab " + QString::number(tabIndex
) + ' ' + property
;
2080 void DolphinMainWindow::setUrlAsCaption(const KUrl
& url
)
2083 if (!url
.isLocalFile()) {
2084 caption
.append(url
.protocol() + " - ");
2085 if (url
.hasHost()) {
2086 caption
.append(url
.host() + " - ");
2090 const QString fileName
= url
.fileName().isEmpty() ? "/" : url
.fileName();
2091 caption
.append(fileName
);
2093 setCaption(caption
);
2096 QString
DolphinMainWindow::squeezedText(const QString
& text
) const
2098 const QFontMetrics fm
= fontMetrics();
2099 return fm
.elidedText(text
, Qt::ElideMiddle
, fm
.maxWidth() * 10);
2102 void DolphinMainWindow::createPanelAction(const KIcon
& icon
,
2103 const QKeySequence
& shortcut
,
2104 QAction
* dockAction
,
2105 const QString
& actionName
)
2107 KAction
* panelAction
= actionCollection()->addAction(actionName
);
2108 panelAction
->setCheckable(true);
2109 panelAction
->setChecked(dockAction
->isChecked());
2110 panelAction
->setText(dockAction
->text());
2111 panelAction
->setIcon(icon
);
2112 panelAction
->setShortcut(shortcut
);
2114 connect(panelAction
, SIGNAL(triggered()), dockAction
, SLOT(trigger()));
2115 connect(dockAction
, SIGNAL(toggled(bool)), panelAction
, SLOT(setChecked(bool)));
2118 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
2119 KIO::FileUndoManager::UiInterface()
2123 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2127 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
2129 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
2131 DolphinViewContainer
* container
= mainWin
->activeViewContainer();
2132 container
->showMessage(job
->errorString(), DolphinViewContainer::Error
);
2134 KIO::FileUndoManager::UiInterface::jobError(job
);
2138 #include "dolphinmainwindow.moc"