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 // Workaround for a X11-issue in combination with KModifierInfo
124 // (see DolphinContextMenu::initializeModifierKeyInfo() for
125 // more information):
126 DolphinContextMenu::initializeModifierKeyInfo();
128 setObjectName("Dolphin#");
130 m_viewTab
.append(ViewTab());
131 ViewTab
& viewTab
= m_viewTab
[m_tabIndex
];
132 viewTab
.wasActive
= true; // The first opened tab is automatically active
134 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
135 undoManager
->setUiInterface(new UndoUiInterface());
137 connect(undoManager
, SIGNAL(undoAvailable(bool)),
138 this, SLOT(slotUndoAvailable(bool)));
139 connect(undoManager
, SIGNAL(undoTextChanged(QString
)),
140 this, SLOT(slotUndoTextChanged(QString
)));
141 connect(undoManager
, SIGNAL(jobRecordingStarted(CommandType
)),
142 this, SLOT(clearStatusBar()));
143 connect(undoManager
, SIGNAL(jobRecordingFinished(CommandType
)),
144 this, SLOT(showCommand(CommandType
)));
146 GeneralSettings
* generalSettings
= GeneralSettings::self();
147 const bool firstRun
= (generalSettings
->version() < 200);
149 generalSettings
->setViewPropsTimestamp(QDateTime::currentDateTime());
152 setAcceptDrops(true);
154 viewTab
.splitter
= new QSplitter(this);
155 viewTab
.splitter
->setChildrenCollapsible(false);
159 const KUrl
homeUrl(generalSettings
->homeUrl());
160 setUrlAsCaption(homeUrl
);
161 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
162 connect(m_actionHandler
, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
163 connect(m_actionHandler
, SIGNAL(createDirectory()), SLOT(createDirectory()));
165 viewTab
.primaryView
= createViewContainer(homeUrl
, viewTab
.splitter
);
167 m_activeViewContainer
= viewTab
.primaryView
;
168 connectViewSignals(m_activeViewContainer
);
169 DolphinView
* view
= m_activeViewContainer
->view();
170 m_activeViewContainer
->show();
171 m_actionHandler
->setCurrentView(view
);
173 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
174 connect(this, SIGNAL(urlChanged(KUrl
)),
175 m_remoteEncoding
, SLOT(slotAboutToOpenUrl()));
177 m_tabBar
= new KTabBar(this);
178 m_tabBar
->setMovable(true);
179 m_tabBar
->setTabsClosable(true);
180 connect(m_tabBar
, SIGNAL(currentChanged(int)),
181 this, SLOT(setActiveTab(int)));
182 connect(m_tabBar
, SIGNAL(tabCloseRequested(int)),
183 this, SLOT(closeTab(int)));
184 connect(m_tabBar
, SIGNAL(contextMenu(int,QPoint
)),
185 this, SLOT(openTabContextMenu(int,QPoint
)));
186 connect(m_tabBar
, SIGNAL(newTabRequest()),
187 this, SLOT(openNewTab()));
188 connect(m_tabBar
, SIGNAL(testCanDecode(const QDragMoveEvent
*,bool&)),
189 this, SLOT(slotTestCanDecode(const QDragMoveEvent
*,bool&)));
190 connect(m_tabBar
, SIGNAL(mouseMiddleClick(int)),
191 this, SLOT(closeTab(int)));
192 connect(m_tabBar
, SIGNAL(tabMoved(int,int)),
193 this, SLOT(slotTabMoved(int,int)));
194 connect(m_tabBar
, SIGNAL(receivedDropEvent(int,QDropEvent
*)),
195 this, SLOT(tabDropEvent(int,QDropEvent
*)));
197 m_tabBar
->blockSignals(true); // signals get unblocked after at least 2 tabs are open
199 QWidget
* centralWidget
= new QWidget(this);
200 m_centralWidgetLayout
= new QVBoxLayout(centralWidget
);
201 m_centralWidgetLayout
->setSpacing(0);
202 m_centralWidgetLayout
->setMargin(0);
203 m_centralWidgetLayout
->addWidget(m_tabBar
);
204 m_centralWidgetLayout
->addWidget(viewTab
.splitter
, 1);
206 setCentralWidget(centralWidget
);
208 emit
urlChanged(homeUrl
);
210 setupGUI(Keys
| Save
| Create
| ToolBar
);
211 stateChanged("new_file");
213 QClipboard
* clipboard
= QApplication::clipboard();
214 connect(clipboard
, SIGNAL(dataChanged()),
215 this, SLOT(updatePasteAction()));
217 if (generalSettings
->splitView()) {
224 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
225 showFilterBarAction
->setChecked(generalSettings
->filterBar());
228 menuBar()->setVisible(false);
229 // Assure a proper default size if Dolphin runs the first time
233 const bool showMenu
= !menuBar()->isHidden();
234 QAction
* showMenuBarAction
= actionCollection()->action(KStandardAction::name(KStandardAction::ShowMenubar
));
235 showMenuBarAction
->setChecked(showMenu
); // workaround for bug #171080
237 createControlButton();
241 DolphinMainWindow::~DolphinMainWindow()
245 void DolphinMainWindow::openDirectories(const QList
<KUrl
>& dirs
)
247 if (dirs
.isEmpty()) {
251 if (dirs
.count() == 1) {
252 m_activeViewContainer
->setUrl(dirs
.first());
256 const int oldOpenTabsCount
= m_viewTab
.count();
258 const bool hasSplitView
= GeneralSettings::splitView();
260 // Open each directory inside a new tab. If the "split view" option has been enabled,
261 // always show two directories within one tab.
262 QList
<KUrl
>::const_iterator it
= dirs
.begin();
263 while (it
!= dirs
.end()) {
267 if (hasSplitView
&& (it
!= dirs
.end())) {
268 const int tabIndex
= m_viewTab
.count() - 1;
269 m_viewTab
[tabIndex
].secondaryView
->setUrl(*it
);
274 // Remove the previously opened tabs
275 for (int i
= 0; i
< oldOpenTabsCount
; ++i
) {
280 void DolphinMainWindow::openFiles(const QList
<KUrl
>& files
)
282 if (files
.isEmpty()) {
286 // Get all distinct directories from 'files' and open a tab
287 // for each directory. If the "split view" option is enabled, two
288 // directories are shown inside one tab (see openDirectories()).
290 foreach (const KUrl
& url
, files
) {
291 const KUrl
dir(url
.directory());
292 if (!dirs
.contains(dir
)) {
297 openDirectories(dirs
);
299 // Select the files. Although the files can be split between several
300 // tabs, there is no need to split 'files' accordingly, as
301 // the DolphinView will just ignore invalid selections.
302 const int tabCount
= m_viewTab
.count();
303 for (int i
= 0; i
< tabCount
; ++i
) {
304 m_viewTab
[i
].primaryView
->view()->markUrlsAsSelected(files
);
305 m_viewTab
[i
].primaryView
->view()->markUrlAsCurrent(files
.at(0));
306 if (m_viewTab
[i
].secondaryView
) {
307 m_viewTab
[i
].secondaryView
->view()->markUrlsAsSelected(files
);
308 m_viewTab
[i
].secondaryView
->view()->markUrlAsCurrent(files
.at(0));
313 void DolphinMainWindow::showCommand(CommandType command
)
315 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
317 case KIO::FileUndoManager::Copy
:
318 statusBar
->setText(i18nc("@info:status", "Successfully copied."));
320 case KIO::FileUndoManager::Move
:
321 statusBar
->setText(i18nc("@info:status", "Successfully moved."));
323 case KIO::FileUndoManager::Link
:
324 statusBar
->setText(i18nc("@info:status", "Successfully linked."));
326 case KIO::FileUndoManager::Trash
:
327 statusBar
->setText(i18nc("@info:status", "Successfully moved to trash."));
329 case KIO::FileUndoManager::Rename
:
330 statusBar
->setText(i18nc("@info:status", "Successfully renamed."));
333 case KIO::FileUndoManager::Mkdir
:
334 statusBar
->setText(i18nc("@info:status", "Created folder."));
342 void DolphinMainWindow::pasteIntoFolder()
344 m_activeViewContainer
->view()->pasteIntoFolder();
347 void DolphinMainWindow::changeUrl(const KUrl
& url
)
349 if (!KProtocolManager::supportsListing(url
)) {
350 // The URL navigator only checks for validity, not
351 // if the URL can be listed. An error message is
352 // shown due to DolphinViewContainer::restoreView().
356 DolphinViewContainer
* view
= activeViewContainer();
362 setUrlAsCaption(url
);
363 if (m_viewTab
.count() > 1) {
364 m_tabBar
->setTabText(m_tabIndex
, squeezedText(tabName(m_activeViewContainer
->url())));
366 const QString iconName
= KMimeType::iconNameForUrl(url
);
367 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(iconName
));
368 emit
urlChanged(url
);
372 void DolphinMainWindow::slotTerminalDirectoryChanged(const KUrl
& url
)
374 m_activeViewContainer
->setAutoGrabFocus(false);
376 m_activeViewContainer
->setAutoGrabFocus(true);
379 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
381 KToggleAction
* editableLocationAction
=
382 static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
383 editableLocationAction
->setChecked(editable
);
386 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
390 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
391 int selectedUrlsCount
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedItemsCount();
392 if (m_viewTab
[m_tabIndex
].secondaryView
) {
393 selectedUrlsCount
+= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItemsCount();
396 QAction
* compareFilesAction
= actionCollection()->action("compare_files");
397 if (selectedUrlsCount
== 2) {
398 compareFilesAction
->setEnabled(isKompareInstalled());
400 compareFilesAction
->setEnabled(false);
403 emit
selectionChanged(selection
);
406 void DolphinMainWindow::slotRequestItemInfo(const KFileItem
& item
)
408 emit
requestItemInfo(item
);
411 void DolphinMainWindow::updateHistory()
413 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
414 const int index
= urlNavigator
->historyIndex();
416 QAction
* backAction
= actionCollection()->action("go_back");
418 backAction
->setToolTip(i18nc("@info", "Go back"));
419 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
422 QAction
* forwardAction
= actionCollection()->action("go_forward");
424 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
425 forwardAction
->setEnabled(index
> 0);
429 void DolphinMainWindow::updateFilterBarAction(bool show
)
431 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
432 showFilterBarAction
->setChecked(show
);
435 void DolphinMainWindow::openNewMainWindow()
437 KRun::run("dolphin %u", KUrl::List(), this);
440 void DolphinMainWindow::openNewTab()
442 const bool isUrlEditable
= m_activeViewContainer
->urlNavigator()->isUrlEditable();
444 openNewTab(m_activeViewContainer
->url());
445 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
447 // The URL navigator of the new tab should have the same editable state
448 // as the current tab
449 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
450 navigator
->setUrlEditable(isUrlEditable
);
453 // If a new tab is opened and the URL is editable, assure that
454 // the user can edit the URL without manually setting the focus
455 navigator
->setFocus();
459 void DolphinMainWindow::openNewTab(const KUrl
& url
)
461 QWidget
* focusWidget
= QApplication::focusWidget();
463 if (m_viewTab
.count() == 1) {
464 // Only one view is open currently and hence no tab is shown at
465 // all. Before creating a tab for 'url', provide a tab for the current URL.
466 const KUrl currentUrl
= m_activeViewContainer
->url();
467 m_tabBar
->addTab(KIcon(KMimeType::iconNameForUrl(currentUrl
)),
468 squeezedText(tabName(currentUrl
)));
469 m_tabBar
->blockSignals(false);
472 m_tabBar
->addTab(KIcon(KMimeType::iconNameForUrl(url
)),
473 squeezedText(tabName(url
)));
476 viewTab
.splitter
= new QSplitter(this);
477 viewTab
.splitter
->setChildrenCollapsible(false);
478 viewTab
.primaryView
= createViewContainer(url
, viewTab
.splitter
);
479 viewTab
.primaryView
->setActive(false);
480 connectViewSignals(viewTab
.primaryView
);
482 m_viewTab
.append(viewTab
);
484 actionCollection()->action("close_tab")->setEnabled(true);
486 // Provide a split view, if the startup settings are set this way
487 if (GeneralSettings::splitView()) {
488 const int newTabIndex
= m_viewTab
.count() - 1;
489 createSecondaryView(newTabIndex
);
490 m_viewTab
[newTabIndex
].secondaryView
->setActive(true);
491 m_viewTab
[newTabIndex
].isPrimaryViewActive
= false;
495 // The DolphinViewContainer grabbed the keyboard focus. As the tab is opened
496 // in background, assure that the previous focused widget gets the focus back.
497 focusWidget
->setFocus();
501 void DolphinMainWindow::openNewActivatedTab(const KUrl
& url
)
504 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
507 void DolphinMainWindow::activateNextTab()
509 if (m_viewTab
.count() >= 2) {
510 const int tabIndex
= (m_tabBar
->currentIndex() + 1) % m_tabBar
->count();
511 m_tabBar
->setCurrentIndex(tabIndex
);
515 void DolphinMainWindow::activatePrevTab()
517 if (m_viewTab
.count() >= 2) {
518 int tabIndex
= m_tabBar
->currentIndex() - 1;
519 if (tabIndex
== -1) {
520 tabIndex
= m_tabBar
->count() - 1;
522 m_tabBar
->setCurrentIndex(tabIndex
);
526 void DolphinMainWindow::openInNewTab()
528 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
529 if (list
.isEmpty()) {
530 openNewTab(m_activeViewContainer
->url());
531 } else if ((list
.count() == 1) && list
[0].isDir()) {
532 openNewTab(list
[0].url());
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) && list
[0].isDir()) {
544 newWindowUrl
= list
[0].url();
547 if (!newWindowUrl
.isEmpty()) {
548 KRun::run("dolphin %u", KUrl::List() << newWindowUrl
, this);
552 void DolphinMainWindow::toggleActiveView()
554 if (!m_viewTab
[m_tabIndex
].secondaryView
) {
555 // only one view is available
559 Q_ASSERT(m_activeViewContainer
);
560 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
562 DolphinViewContainer
* left
= m_viewTab
[m_tabIndex
].primaryView
;
563 DolphinViewContainer
* right
= m_viewTab
[m_tabIndex
].secondaryView
;
564 setActiveViewContainer(m_activeViewContainer
== right
? left
: right
);
567 void DolphinMainWindow::showEvent(QShowEvent
* event
)
569 KXmlGuiWindow::showEvent(event
);
570 if (!event
->spontaneous()) {
571 m_activeViewContainer
->view()->setFocus();
575 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
577 // Find out if Dolphin is closed directly by the user or
578 // by the session manager because the session is closed
579 bool closedByUser
= true;
580 DolphinApplication
*application
= qobject_cast
<DolphinApplication
*>(qApp
);
581 if (application
&& application
->sessionSaving()) {
582 closedByUser
= false;
585 if (m_viewTab
.count() > 1 && GeneralSettings::confirmClosingMultipleTabs() && closedByUser
) {
586 // Ask the user if he really wants to quit and close all tabs.
587 // Open a confirmation dialog with 3 buttons:
588 // KDialog::Yes -> Quit
589 // KDialog::No -> Close only the current tab
590 // KDialog::Cancel -> do nothing
591 KDialog
*dialog
= new KDialog(this, Qt::Dialog
);
592 dialog
->setCaption(i18nc("@title:window", "Confirmation"));
593 dialog
->setButtons(KDialog::Yes
| KDialog::No
| KDialog::Cancel
);
594 dialog
->setModal(true);
595 dialog
->setButtonGuiItem(KDialog::Yes
, KStandardGuiItem::quit());
596 dialog
->setButtonGuiItem(KDialog::No
, KGuiItem(i18n("C&lose Current Tab"), KIcon("tab-close")));
597 dialog
->setButtonGuiItem(KDialog::Cancel
, KStandardGuiItem::cancel());
598 dialog
->setDefaultButton(KDialog::Yes
);
600 bool doNotAskAgainCheckboxResult
= false;
602 const int result
= KMessageBox::createKMessageBox(dialog
,
603 QMessageBox::Warning
,
604 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
606 i18n("Do not ask again"),
607 &doNotAskAgainCheckboxResult
,
608 KMessageBox::Notify
);
610 if (doNotAskAgainCheckboxResult
) {
611 GeneralSettings::setConfirmClosingMultipleTabs(false);
619 // Close only the current tab
627 GeneralSettings::setVersion(CurrentDolphinVersion
);
628 GeneralSettings::self()->writeConfig();
630 KXmlGuiWindow::closeEvent(event
);
633 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
635 const int tabCount
= m_viewTab
.count();
636 group
.writeEntry("Tab Count", tabCount
);
637 group
.writeEntry("Active Tab Index", m_tabBar
->currentIndex());
639 for (int i
= 0; i
< tabCount
; ++i
) {
640 const DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
641 group
.writeEntry(tabProperty("Primary URL", i
), cont
->url().url());
642 group
.writeEntry(tabProperty("Primary Editable", i
),
643 cont
->urlNavigator()->isUrlEditable());
645 cont
= m_viewTab
[i
].secondaryView
;
647 group
.writeEntry(tabProperty("Secondary URL", i
), cont
->url().url());
648 group
.writeEntry(tabProperty("Secondary Editable", i
),
649 cont
->urlNavigator()->isUrlEditable());
654 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
656 const int tabCount
= group
.readEntry("Tab Count", 1);
657 for (int i
= 0; i
< tabCount
; ++i
) {
658 DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
660 cont
->setUrl(group
.readEntry(tabProperty("Primary URL", i
)));
661 const bool editable
= group
.readEntry(tabProperty("Primary Editable", i
), false);
662 cont
->urlNavigator()->setUrlEditable(editable
);
664 cont
= m_viewTab
[i
].secondaryView
;
665 const QString secondaryUrl
= group
.readEntry(tabProperty("Secondary URL", i
));
666 if (!secondaryUrl
.isEmpty()) {
668 // a secondary view should be shown, but no one is available
669 // currently -> create a new view
671 cont
= m_viewTab
[i
].secondaryView
;
675 cont
->setUrl(secondaryUrl
);
676 const bool editable
= group
.readEntry(tabProperty("Secondary Editable", i
), false);
677 cont
->urlNavigator()->setUrlEditable(editable
);
679 // no secondary view should be shown, but the default setting shows
680 // one already -> close the view
684 // openNewTab() needs to be called only tabCount - 1 times
685 if (i
!= tabCount
- 1) {
690 const int index
= group
.readEntry("Active Tab Index", 0);
691 m_tabBar
->setCurrentIndex(index
);
694 void DolphinMainWindow::updateNewMenu()
696 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
697 m_newFileMenu
->checkUpToDate();
698 m_newFileMenu
->setPopupFiles(activeViewContainer()->url());
701 void DolphinMainWindow::createDirectory()
703 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
704 m_newFileMenu
->setPopupFiles(activeViewContainer()->url());
705 m_newFileMenu
->createDirectory();
708 void DolphinMainWindow::quit()
713 void DolphinMainWindow::showErrorMessage(const QString
& message
)
715 m_activeViewContainer
->showMessage(message
, DolphinViewContainer::Error
);
718 void DolphinMainWindow::slotUndoAvailable(bool available
)
720 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
722 undoAction
->setEnabled(available
);
726 void DolphinMainWindow::restoreClosedTab(QAction
* action
)
728 if (action
->data().toBool()) {
729 // clear all actions except the "Empty Recently Closed Tabs"
730 // action and the separator
731 QList
<QAction
*> actions
= m_recentTabsMenu
->menu()->actions();
732 const int count
= actions
.size();
733 for (int i
= 2; i
< count
; ++i
) {
734 m_recentTabsMenu
->menu()->removeAction(actions
.at(i
));
737 const ClosedTab closedTab
= action
->data().value
<ClosedTab
>();
738 openNewTab(closedTab
.primaryUrl
);
739 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
741 if (closedTab
.isSplit
) {
742 // create secondary view
744 m_viewTab
[m_tabIndex
].secondaryView
->setUrl(closedTab
.secondaryUrl
);
747 m_recentTabsMenu
->removeAction(action
);
750 if (m_recentTabsMenu
->menu()->actions().count() == 2) {
751 m_recentTabsMenu
->setEnabled(false);
755 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
757 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
759 undoAction
->setText(text
);
763 void DolphinMainWindow::undo()
766 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
767 KIO::FileUndoManager::self()->undo();
770 void DolphinMainWindow::cut()
772 m_activeViewContainer
->view()->cutSelectedItems();
775 void DolphinMainWindow::copy()
777 m_activeViewContainer
->view()->copySelectedItems();
780 void DolphinMainWindow::paste()
782 m_activeViewContainer
->view()->paste();
785 void DolphinMainWindow::find()
787 m_activeViewContainer
->setSearchModeEnabled(true);
790 void DolphinMainWindow::updatePasteAction()
792 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
793 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
794 pasteAction
->setEnabled(pasteInfo
.first
);
795 pasteAction
->setText(pasteInfo
.second
);
798 void DolphinMainWindow::selectAll()
802 // if the URL navigator is editable and focused, select the whole
803 // URL instead of all items of the view
805 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
806 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit(); // krazy:exclude=qclasses
807 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
808 lineEdit
->hasFocus();
810 lineEdit
->selectAll();
812 m_activeViewContainer
->view()->selectAll();
816 void DolphinMainWindow::invertSelection()
819 m_activeViewContainer
->view()->invertSelection();
822 void DolphinMainWindow::toggleSplitView()
824 if (!m_viewTab
[m_tabIndex
].secondaryView
) {
825 createSecondaryView(m_tabIndex
);
826 setActiveViewContainer(m_viewTab
[m_tabIndex
].secondaryView
);
827 } else if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
828 // remove secondary view
829 m_viewTab
[m_tabIndex
].secondaryView
->close();
830 m_viewTab
[m_tabIndex
].secondaryView
->deleteLater();
831 m_viewTab
[m_tabIndex
].secondaryView
= 0;
833 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
835 // The primary view is active and should be closed. Hence from a users point of view
836 // the content of the secondary view should be moved to the primary view.
837 // From an implementation point of view it is more efficient to close
838 // the primary view and exchange the internal pointers afterwards.
840 m_viewTab
[m_tabIndex
].primaryView
->close();
841 m_viewTab
[m_tabIndex
].primaryView
->deleteLater();
842 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
843 m_viewTab
[m_tabIndex
].secondaryView
= 0;
845 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
851 void DolphinMainWindow::reloadView()
854 m_activeViewContainer
->view()->reload();
857 void DolphinMainWindow::stopLoading()
859 m_activeViewContainer
->view()->stopLoading();
862 void DolphinMainWindow::enableStopAction()
864 actionCollection()->action("stop")->setEnabled(true);
867 void DolphinMainWindow::disableStopAction()
869 actionCollection()->action("stop")->setEnabled(false);
872 void DolphinMainWindow::showFilterBar()
874 m_activeViewContainer
->setFilterBarVisible(true);
877 void DolphinMainWindow::toggleEditLocation()
881 QAction
* action
= actionCollection()->action("editable_location");
882 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
883 urlNavigator
->setUrlEditable(action
->isChecked());
886 void DolphinMainWindow::replaceLocation()
888 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
889 navigator
->setUrlEditable(true);
890 navigator
->setFocus();
892 // select the whole text of the combo box editor
893 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit(); // krazy:exclude=qclasses
894 lineEdit
->selectAll();
897 void DolphinMainWindow::togglePanelLockState()
899 const bool newLockState
= !GeneralSettings::lockPanels();
900 foreach (QObject
* child
, children()) {
901 DolphinDockWidget
* dock
= qobject_cast
<DolphinDockWidget
*>(child
);
903 dock
->setLocked(newLockState
);
907 GeneralSettings::setLockPanels(newLockState
);
910 void DolphinMainWindow::slotPlacesPanelVisibilityChanged(bool visible
)
912 const int tabCount
= m_viewTab
.count();
913 for (int i
= 0; i
< tabCount
; ++i
) {
914 ViewTab
& tab
= m_viewTab
[i
];
915 Q_ASSERT(tab
.primaryView
);
916 tab
.primaryView
->urlNavigator()->setPlacesSelectorVisible(!visible
);
917 if (tab
.secondaryView
) {
918 tab
.secondaryView
->urlNavigator()->setPlacesSelectorVisible(!visible
);
923 void DolphinMainWindow::goBack()
925 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
926 urlNavigator
->goBack();
928 if (urlNavigator
->locationState().isEmpty()) {
929 // An empty location state indicates a redirection URL,
930 // which must be skipped too
931 urlNavigator
->goBack();
935 void DolphinMainWindow::goForward()
937 m_activeViewContainer
->urlNavigator()->goForward();
940 void DolphinMainWindow::goUp()
942 m_activeViewContainer
->urlNavigator()->goUp();
945 void DolphinMainWindow::goHome()
947 m_activeViewContainer
->urlNavigator()->goHome();
950 void DolphinMainWindow::goBack(Qt::MouseButtons buttons
)
952 // The default case (left button pressed) is handled in goBack().
953 if (buttons
== Qt::MidButton
) {
954 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
955 const int index
= urlNavigator
->historyIndex() + 1;
956 openNewTab(urlNavigator
->locationUrl(index
));
960 void DolphinMainWindow::goForward(Qt::MouseButtons buttons
)
962 // The default case (left button pressed) is handled in goForward().
963 if (buttons
== Qt::MidButton
) {
964 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
965 const int index
= urlNavigator
->historyIndex() - 1;
966 openNewTab(urlNavigator
->locationUrl(index
));
970 void DolphinMainWindow::goUp(Qt::MouseButtons buttons
)
972 // The default case (left button pressed) is handled in goUp().
973 if (buttons
== Qt::MidButton
) {
974 openNewTab(activeViewContainer()->url().upUrl());
978 void DolphinMainWindow::goHome(Qt::MouseButtons buttons
)
980 // The default case (left button pressed) is handled in goHome().
981 if (buttons
== Qt::MidButton
) {
982 openNewTab(GeneralSettings::self()->homeUrl());
986 void DolphinMainWindow::compareFiles()
988 // The method is only invoked if exactly 2 files have
989 // been selected. The selected files may be:
990 // - both in the primary view
991 // - both in the secondary view
992 // - one in the primary view and the other in the secondary
994 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
999 KFileItemList items
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedItems();
1001 switch (items
.count()) {
1003 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
);
1004 items
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItems();
1005 Q_ASSERT(items
.count() == 2);
1006 urlA
= items
[0].url();
1007 urlB
= items
[1].url();
1012 urlA
= items
[0].url();
1013 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
);
1014 items
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItems();
1015 Q_ASSERT(items
.count() == 1);
1016 urlB
= items
[0].url();
1021 urlA
= items
[0].url();
1022 urlB
= items
[1].url();
1027 // may not happen: compareFiles may only get invoked if 2
1028 // files are selected
1033 QString
command("kompare -c \"");
1034 command
.append(urlA
.pathOrUrl());
1035 command
.append("\" \"");
1036 command
.append(urlB
.pathOrUrl());
1037 command
.append('\"');
1038 KRun::runCommand(command
, "Kompare", "kompare", this);
1041 void DolphinMainWindow::toggleShowMenuBar()
1043 const bool visible
= menuBar()->isVisible();
1044 menuBar()->setVisible(!visible
);
1046 createControlButton();
1048 deleteControlButton();
1052 void DolphinMainWindow::openTerminal()
1054 QString
dir(QDir::homePath());
1056 // If the given directory is not local, it can still be the URL of an
1057 // ioslave using UDS_LOCAL_PATH which to be converted first.
1058 KUrl url
= KIO::NetAccess::mostLocalUrl(m_activeViewContainer
->url(), this);
1060 //If the URL is local after the above conversion, set the directory.
1061 if (url
.isLocalFile()) {
1062 dir
= url
.toLocalFile();
1065 KToolInvocation::invokeTerminal(QString(), dir
);
1068 void DolphinMainWindow::editSettings()
1070 if (!m_settingsDialog
) {
1071 DolphinViewContainer
* container
= activeViewContainer();
1072 container
->view()->writeSettings();
1074 const KUrl url
= container
->url();
1075 DolphinSettingsDialog
* settingsDialog
= new DolphinSettingsDialog(url
, this);
1076 connect(settingsDialog
, SIGNAL(settingsChanged()), this, SLOT(refreshViews()));
1077 settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1078 settingsDialog
->show();
1079 m_settingsDialog
= settingsDialog
;
1081 m_settingsDialog
.data()->raise();
1085 void DolphinMainWindow::setActiveTab(int index
)
1087 Q_ASSERT(index
>= 0);
1088 Q_ASSERT(index
< m_viewTab
.count());
1089 if (index
== m_tabIndex
) {
1093 // hide current tab content
1094 ViewTab
& hiddenTab
= m_viewTab
[m_tabIndex
];
1095 hiddenTab
.isPrimaryViewActive
= hiddenTab
.primaryView
->isActive();
1096 hiddenTab
.primaryView
->setActive(false);
1097 if (hiddenTab
.secondaryView
) {
1098 hiddenTab
.secondaryView
->setActive(false);
1100 QSplitter
* splitter
= m_viewTab
[m_tabIndex
].splitter
;
1102 m_centralWidgetLayout
->removeWidget(splitter
);
1104 // show active tab content
1107 ViewTab
& viewTab
= m_viewTab
[index
];
1108 m_centralWidgetLayout
->addWidget(viewTab
.splitter
, 1);
1109 viewTab
.primaryView
->show();
1110 if (viewTab
.secondaryView
) {
1111 viewTab
.secondaryView
->show();
1113 viewTab
.splitter
->show();
1115 if (!viewTab
.wasActive
) {
1116 viewTab
.wasActive
= true;
1118 // If the tab has not been activated yet the size of the KItemListView is
1119 // undefined and results in an unwanted animation. To prevent this a
1120 // reloading of the directory gets triggered.
1121 viewTab
.primaryView
->view()->reload();
1122 if (viewTab
.secondaryView
) {
1123 viewTab
.secondaryView
->view()->reload();
1127 setActiveViewContainer(viewTab
.isPrimaryViewActive
? viewTab
.primaryView
:
1128 viewTab
.secondaryView
);
1131 void DolphinMainWindow::closeTab()
1133 closeTab(m_tabBar
->currentIndex());
1136 void DolphinMainWindow::closeTab(int index
)
1138 Q_ASSERT(index
>= 0);
1139 Q_ASSERT(index
< m_viewTab
.count());
1140 if (m_viewTab
.count() == 1) {
1141 // the last tab may never get closed
1145 if (index
== m_tabIndex
) {
1146 // The tab that should be closed is the active tab. Activate the
1147 // previous tab before closing the tab.
1148 m_tabBar
->setCurrentIndex((index
> 0) ? index
- 1 : 1);
1150 rememberClosedTab(index
);
1153 m_viewTab
[index
].primaryView
->deleteLater();
1154 if (m_viewTab
[index
].secondaryView
) {
1155 m_viewTab
[index
].secondaryView
->deleteLater();
1157 m_viewTab
[index
].splitter
->deleteLater();
1158 m_viewTab
.erase(m_viewTab
.begin() + index
);
1160 m_tabBar
->blockSignals(true);
1161 m_tabBar
->removeTab(index
);
1163 if (m_tabIndex
> index
) {
1165 Q_ASSERT(m_tabIndex
>= 0);
1168 // if only one tab is left, also remove the tab entry so that
1169 // closing the last tab is not possible
1170 if (m_viewTab
.count() == 1) {
1171 m_tabBar
->removeTab(0);
1172 actionCollection()->action("close_tab")->setEnabled(false);
1174 m_tabBar
->blockSignals(false);
1178 void DolphinMainWindow::openTabContextMenu(int index
, const QPoint
& pos
)
1182 QAction
* newTabAction
= menu
.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab"));
1183 newTabAction
->setShortcut(actionCollection()->action("new_tab")->shortcut());
1185 QAction
* detachTabAction
= menu
.addAction(KIcon("tab-detach"), i18nc("@action:inmenu", "Detach Tab"));
1187 QAction
* closeOtherTabsAction
= menu
.addAction(KIcon("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs"));
1189 QAction
* closeTabAction
= menu
.addAction(KIcon("tab-close"), i18nc("@action:inmenu", "Close Tab"));
1190 closeTabAction
->setShortcut(actionCollection()->action("close_tab")->shortcut());
1191 QAction
* selectedAction
= menu
.exec(pos
);
1192 if (selectedAction
== newTabAction
) {
1193 const ViewTab
& tab
= m_viewTab
[index
];
1194 Q_ASSERT(tab
.primaryView
);
1195 const KUrl url
= tab
.secondaryView
&& tab
.secondaryView
->isActive() ?
1196 tab
.secondaryView
->url() : tab
.primaryView
->url();
1198 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
1199 } else if (selectedAction
== detachTabAction
) {
1200 const QString
separator(QLatin1Char(' '));
1201 QString command
= QLatin1String("dolphin");
1203 const ViewTab
& tab
= m_viewTab
[index
];
1204 Q_ASSERT(tab
.primaryView
);
1206 command
+= separator
+ tab
.primaryView
->url().url();
1207 if (tab
.secondaryView
) {
1208 command
+= separator
+ tab
.secondaryView
->url().url();
1209 command
+= separator
+ QLatin1String("-split");
1212 KRun::runCommand(command
, this);
1215 } else if (selectedAction
== closeOtherTabsAction
) {
1216 const int count
= m_tabBar
->count();
1217 for (int i
= 0; i
< index
; ++i
) {
1220 for (int i
= index
+ 1; i
< count
; ++i
) {
1223 } else if (selectedAction
== closeTabAction
) {
1228 void DolphinMainWindow::slotTabMoved(int from
, int to
)
1230 m_viewTab
.move(from
, to
);
1231 m_tabIndex
= m_tabBar
->currentIndex();
1234 void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent
* event
, bool& canDecode
)
1236 canDecode
= KUrl::List::canDecode(event
->mimeData());
1239 void DolphinMainWindow::handleUrl(const KUrl
& url
)
1241 delete m_lastHandleUrlStatJob
;
1242 m_lastHandleUrlStatJob
= 0;
1244 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1245 activeViewContainer()->setUrl(url
);
1246 } else if (KProtocolManager::supportsListing(url
)) {
1247 // stat the URL to see if it is a dir or not
1248 m_lastHandleUrlStatJob
= KIO::stat(url
, KIO::HideProgressInfo
);
1249 if (m_lastHandleUrlStatJob
->ui()) {
1250 m_lastHandleUrlStatJob
->ui()->setWindow(this);
1252 connect(m_lastHandleUrlStatJob
, SIGNAL(result(KJob
*)),
1253 this, SLOT(slotHandleUrlStatFinished(KJob
*)));
1256 new KRun(url
, this); // Automatically deletes itself after being finished
1260 void DolphinMainWindow::slotHandleUrlStatFinished(KJob
* job
)
1262 m_lastHandleUrlStatJob
= 0;
1263 const KIO::UDSEntry entry
= static_cast<KIO::StatJob
*>(job
)->statResult();
1264 const KUrl url
= static_cast<KIO::StatJob
*>(job
)->url();
1265 if (entry
.isDir()) {
1266 activeViewContainer()->setUrl(url
);
1268 new KRun(url
, this); // Automatically deletes itself after being finished
1272 void DolphinMainWindow::tabDropEvent(int tab
, QDropEvent
* event
)
1274 const KUrl::List urls
= KUrl::List::fromMimeData(event
->mimeData());
1275 if (!urls
.isEmpty() && tab
!= -1) {
1276 const ViewTab
& viewTab
= m_viewTab
[tab
];
1277 const DolphinView
* view
= viewTab
.isPrimaryViewActive
? viewTab
.primaryView
->view()
1278 : viewTab
.secondaryView
->view();
1280 DragAndDropHelper::dropUrls(view
->rootItem(), view
->url(), event
, error
);
1281 if (!error
.isEmpty()) {
1282 activeViewContainer()->showMessage(error
, DolphinViewContainer::Error
);
1287 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1289 newFileMenu()->setEnabled(isFolderWritable
);
1292 void DolphinMainWindow::openContextMenu(const QPoint
& pos
,
1293 const KFileItem
& item
,
1295 const QList
<QAction
*>& customActions
)
1297 QWeakPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, pos
, item
, url
);
1298 contextMenu
.data()->setCustomActions(customActions
);
1299 const DolphinContextMenu::Command command
= contextMenu
.data()->open();
1302 case DolphinContextMenu::OpenParentFolderInNewWindow
: {
1303 KRun::run("dolphin %u", KUrl::List() << item
.url().upUrl(), this);
1307 case DolphinContextMenu::OpenParentFolderInNewTab
:
1308 openNewTab(item
.url().upUrl());
1311 case DolphinContextMenu::None
:
1316 delete contextMenu
.data();
1319 void DolphinMainWindow::updateControlMenu()
1321 KMenu
* menu
= qobject_cast
<KMenu
*>(sender());
1324 // All actions get cleared by KMenu::clear(). The sub-menus are deleted
1325 // by connecting to the aboutToHide() signal from the parent-menu.
1328 KActionCollection
* ac
= actionCollection();
1330 // Add "Edit" actions
1331 bool added
= addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Undo
)), menu
) |
1332 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Find
)), menu
) |
1333 addActionToMenu(ac
->action("select_all"), menu
) |
1334 addActionToMenu(ac
->action("invert_selection"), menu
);
1337 menu
->addSeparator();
1340 // Add "View" actions
1341 if (!GeneralSettings::showZoomSlider()) {
1342 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomIn
)), menu
);
1343 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomOut
)), menu
);
1344 menu
->addSeparator();
1347 added
= addActionToMenu(ac
->action("view_mode"), menu
) |
1348 addActionToMenu(ac
->action("sort"), menu
) |
1349 addActionToMenu(ac
->action("additional_info"), menu
) |
1350 addActionToMenu(ac
->action("show_preview"), menu
) |
1351 addActionToMenu(ac
->action("show_in_groups"), menu
) |
1352 addActionToMenu(ac
->action("show_hidden_files"), menu
);
1355 menu
->addSeparator();
1358 added
= addActionToMenu(ac
->action("split_view"), menu
) |
1359 addActionToMenu(ac
->action("reload"), menu
) |
1360 addActionToMenu(ac
->action("view_properties"), menu
);
1362 menu
->addSeparator();
1365 addActionToMenu(ac
->action("panels"), menu
);
1366 KMenu
* locationBarMenu
= new KMenu(i18nc("@action:inmenu", "Location Bar"), menu
);
1367 locationBarMenu
->addAction(ac
->action("editable_location"));
1368 locationBarMenu
->addAction(ac
->action("replace_location"));
1369 menu
->addMenu(locationBarMenu
);
1371 menu
->addSeparator();
1374 KMenu
* goMenu
= new KMenu(i18nc("@action:inmenu", "Go"), menu
);
1375 connect(menu
, SIGNAL(aboutToHide()), goMenu
, SLOT(deleteLater()));
1376 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Back
)));
1377 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Forward
)));
1378 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Up
)));
1379 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Home
)));
1380 goMenu
->addAction(ac
->action("closed_tabs"));
1381 menu
->addMenu(goMenu
);
1384 KMenu
* toolsMenu
= new KMenu(i18nc("@action:inmenu", "Tools"), menu
);
1385 connect(menu
, SIGNAL(aboutToHide()), toolsMenu
, SLOT(deleteLater()));
1386 toolsMenu
->addAction(ac
->action("show_filter_bar"));
1387 toolsMenu
->addAction(ac
->action("compare_files"));
1388 toolsMenu
->addAction(ac
->action("open_terminal"));
1389 toolsMenu
->addAction(ac
->action("change_remote_encoding"));
1390 menu
->addMenu(toolsMenu
);
1392 // Add "Settings" menu entries
1393 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::KeyBindings
)), menu
);
1394 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ConfigureToolbars
)), menu
);
1395 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Preferences
)), menu
);
1398 KMenu
* helpMenu
= new KMenu(i18nc("@action:inmenu", "Help"), menu
);
1399 connect(menu
, SIGNAL(aboutToHide()), helpMenu
, SLOT(deleteLater()));
1400 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::HelpContents
)));
1401 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::WhatsThis
)));
1402 helpMenu
->addSeparator();
1403 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ReportBug
)));
1404 helpMenu
->addSeparator();
1405 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
)));
1406 helpMenu
->addSeparator();
1407 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::AboutApp
)));
1408 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::AboutKDE
)));
1409 menu
->addMenu(helpMenu
);
1411 menu
->addSeparator();
1412 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ShowMenubar
)), menu
);
1415 void DolphinMainWindow::updateToolBar()
1417 if (!menuBar()->isVisible()) {
1418 createControlButton();
1422 void DolphinMainWindow::slotControlButtonDeleted()
1424 m_controlButton
= 0;
1425 m_updateToolBarTimer
->start();
1428 void DolphinMainWindow::slotPanelErrorMessage(const QString
& error
)
1430 activeViewContainer()->showMessage(error
, DolphinViewContainer::Error
);
1433 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer
* viewContainer
)
1435 Q_ASSERT(viewContainer
);
1436 Q_ASSERT((viewContainer
== m_viewTab
[m_tabIndex
].primaryView
) ||
1437 (viewContainer
== m_viewTab
[m_tabIndex
].secondaryView
));
1438 if (m_activeViewContainer
== viewContainer
) {
1442 m_activeViewContainer
->setActive(false);
1443 m_activeViewContainer
= viewContainer
;
1445 // Activating the view container might trigger a recursive setActiveViewContainer() call
1446 // inside DolphinMainWindow::toggleActiveView() when having a split view. Temporary
1447 // disconnect the activated() signal in this case:
1448 disconnect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1449 m_activeViewContainer
->setActive(true);
1450 connect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1452 m_actionHandler
->setCurrentView(viewContainer
->view());
1455 updateEditActions();
1456 updateViewActions();
1459 const KUrl url
= m_activeViewContainer
->url();
1460 setUrlAsCaption(url
);
1461 if (m_viewTab
.count() > 1) {
1462 m_tabBar
->setTabText(m_tabIndex
, tabName(url
));
1463 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(KMimeType::iconNameForUrl(url
)));
1466 emit
urlChanged(url
);
1469 DolphinViewContainer
* DolphinMainWindow::createViewContainer(const KUrl
& url
, QWidget
* parent
)
1471 DolphinViewContainer
* container
= new DolphinViewContainer(url
, parent
);
1473 // The places-selector from the URL navigator should only be shown
1474 // if the places dock is invisible
1475 QDockWidget
* placesDock
= findChild
<QDockWidget
*>("placesDock");
1476 container
->urlNavigator()->setPlacesSelectorVisible(!placesDock
|| !placesDock
->isVisible());
1481 void DolphinMainWindow::setupActions()
1483 // setup 'File' menu
1484 m_newFileMenu
= new DolphinNewFileMenu(this);
1485 KMenu
* menu
= m_newFileMenu
->menu();
1486 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1487 menu
->setIcon(KIcon("document-new"));
1488 connect(menu
, SIGNAL(aboutToShow()),
1489 this, SLOT(updateNewMenu()));
1491 KAction
* newWindow
= actionCollection()->addAction("new_window");
1492 newWindow
->setIcon(KIcon("window-new"));
1493 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1494 newWindow
->setShortcut(Qt::CTRL
| Qt::Key_N
);
1495 connect(newWindow
, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1497 KAction
* newTab
= actionCollection()->addAction("new_tab");
1498 newTab
->setIcon(KIcon("tab-new"));
1499 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1500 newTab
->setShortcut(KShortcut(Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
));
1501 connect(newTab
, SIGNAL(triggered()), this, SLOT(openNewTab()));
1503 KAction
* closeTab
= actionCollection()->addAction("close_tab");
1504 closeTab
->setIcon(KIcon("tab-close"));
1505 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1506 closeTab
->setShortcut(Qt::CTRL
| Qt::Key_W
);
1507 closeTab
->setEnabled(false);
1508 connect(closeTab
, SIGNAL(triggered()), this, SLOT(closeTab()));
1510 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1512 // setup 'Edit' menu
1513 KStandardAction::undo(this,
1515 actionCollection());
1517 // need to remove shift+del from cut action, else the shortcut for deletejob
1519 KAction
* cut
= KStandardAction::cut(this, SLOT(cut()), actionCollection());
1520 KShortcut cutShortcut
= cut
->shortcut();
1521 cutShortcut
.remove(Qt::SHIFT
| Qt::Key_Delete
, KShortcut::KeepEmpty
);
1522 cut
->setShortcut(cutShortcut
);
1523 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1524 KAction
* paste
= KStandardAction::paste(this, SLOT(paste()), actionCollection());
1525 // The text of the paste-action is modified dynamically by Dolphin
1526 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1527 // due to the long text, the text "Paste" is used:
1528 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1530 KStandardAction::find(this, SLOT(find()), actionCollection());
1532 KAction
* selectAll
= actionCollection()->addAction("select_all");
1533 selectAll
->setText(i18nc("@action:inmenu Edit", "Select All"));
1534 selectAll
->setShortcut(Qt::CTRL
| Qt::Key_A
);
1535 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
1537 KAction
* invertSelection
= actionCollection()->addAction("invert_selection");
1538 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1539 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1540 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
1542 // setup 'View' menu
1543 // (note that most of it is set up in DolphinViewActionHandler)
1545 KAction
* split
= actionCollection()->addAction("split_view");
1546 split
->setShortcut(Qt::Key_F3
);
1547 updateSplitAction();
1548 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1550 KAction
* reload
= actionCollection()->addAction("reload");
1551 reload
->setText(i18nc("@action:inmenu View", "Reload"));
1552 reload
->setShortcut(Qt::Key_F5
);
1553 reload
->setIcon(KIcon("view-refresh"));
1554 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
1556 KAction
* stop
= actionCollection()->addAction("stop");
1557 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1558 stop
->setToolTip(i18nc("@info", "Stop loading"));
1559 stop
->setIcon(KIcon("process-stop"));
1560 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
1562 KToggleAction
* editableLocation
= actionCollection()->add
<KToggleAction
>("editable_location");
1563 editableLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1564 editableLocation
->setShortcut(Qt::Key_F6
);
1565 connect(editableLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1567 KAction
* replaceLocation
= actionCollection()->addAction("replace_location");
1568 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1569 replaceLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
1570 connect(replaceLocation
, SIGNAL(triggered()), this, SLOT(replaceLocation()));
1573 KAction
* backAction
= KStandardAction::back(this, SLOT(goBack()), actionCollection());
1574 connect(backAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goBack(Qt::MouseButtons
)));
1575 KShortcut backShortcut
= backAction
->shortcut();
1576 backShortcut
.setAlternate(Qt::Key_Backspace
);
1577 backAction
->setShortcut(backShortcut
);
1579 m_recentTabsMenu
= new KActionMenu(i18n("Recently Closed Tabs"), this);
1580 m_recentTabsMenu
->setIcon(KIcon("edit-undo"));
1581 actionCollection()->addAction("closed_tabs", m_recentTabsMenu
);
1582 connect(m_recentTabsMenu
->menu(), SIGNAL(triggered(QAction
*)),
1583 this, SLOT(restoreClosedTab(QAction
*)));
1585 QAction
* action
= new QAction(i18n("Empty Recently Closed Tabs"), m_recentTabsMenu
);
1586 action
->setIcon(KIcon("edit-clear-list"));
1587 action
->setData(QVariant::fromValue(true));
1588 m_recentTabsMenu
->addAction(action
);
1589 m_recentTabsMenu
->addSeparator();
1590 m_recentTabsMenu
->setEnabled(false);
1592 KAction
* forwardAction
= KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1593 connect(forwardAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goForward(Qt::MouseButtons
)));
1595 KAction
* upAction
= KStandardAction::up(this, SLOT(goUp()), actionCollection());
1596 connect(upAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goUp(Qt::MouseButtons
)));
1598 KAction
* homeAction
= KStandardAction::home(this, SLOT(goHome()), actionCollection());
1599 connect(homeAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goHome(Qt::MouseButtons
)));
1601 // setup 'Tools' menu
1602 KAction
* showFilterBar
= actionCollection()->addAction("show_filter_bar");
1603 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1604 showFilterBar
->setIcon(KIcon("view-filter"));
1605 showFilterBar
->setShortcut(Qt::CTRL
| Qt::Key_I
);
1606 connect(showFilterBar
, SIGNAL(triggered()), this, SLOT(showFilterBar()));
1608 KAction
* compareFiles
= actionCollection()->addAction("compare_files");
1609 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1610 compareFiles
->setIcon(KIcon("kompare"));
1611 compareFiles
->setEnabled(false);
1612 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
1614 KAction
* openTerminal
= actionCollection()->addAction("open_terminal");
1615 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1616 openTerminal
->setIcon(KIcon("utilities-terminal"));
1617 openTerminal
->setShortcut(Qt::SHIFT
| Qt::Key_F4
);
1618 connect(openTerminal
, SIGNAL(triggered()), this, SLOT(openTerminal()));
1620 // setup 'Settings' menu
1621 KToggleAction
* showMenuBar
= KStandardAction::showMenubar(0, 0, actionCollection());
1622 connect(showMenuBar
, SIGNAL(triggered(bool)), // Fixes #286822
1623 this, SLOT(toggleShowMenuBar()), Qt::QueuedConnection
);
1624 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1626 // not in menu actions
1627 QList
<QKeySequence
> nextTabKeys
;
1628 nextTabKeys
.append(KStandardShortcut::tabNext().primary());
1629 nextTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::Key_Tab
));
1631 QList
<QKeySequence
> prevTabKeys
;
1632 prevTabKeys
.append(KStandardShortcut::tabPrev().primary());
1633 prevTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::SHIFT
| Qt::Key_Tab
));
1635 KAction
* activateNextTab
= actionCollection()->addAction("activate_next_tab");
1636 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1637 connect(activateNextTab
, SIGNAL(triggered()), SLOT(activateNextTab()));
1638 activateNextTab
->setShortcuts(QApplication::isRightToLeft() ? prevTabKeys
: nextTabKeys
);
1640 KAction
* activatePrevTab
= actionCollection()->addAction("activate_prev_tab");
1641 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1642 connect(activatePrevTab
, SIGNAL(triggered()), SLOT(activatePrevTab()));
1643 activatePrevTab
->setShortcuts(QApplication::isRightToLeft() ? nextTabKeys
: prevTabKeys
);
1646 KAction
* openInNewTab
= actionCollection()->addAction("open_in_new_tab");
1647 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1648 openInNewTab
->setIcon(KIcon("tab-new"));
1649 connect(openInNewTab
, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1651 KAction
* openInNewWindow
= actionCollection()->addAction("open_in_new_window");
1652 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1653 openInNewWindow
->setIcon(KIcon("window-new"));
1654 connect(openInNewWindow
, SIGNAL(triggered()), this, SLOT(openInNewWindow()));
1657 void DolphinMainWindow::setupDockWidgets()
1659 const bool lock
= GeneralSettings::lockPanels();
1661 KDualAction
* lockLayoutAction
= actionCollection()->add
<KDualAction
>("lock_panels");
1662 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
1663 lockLayoutAction
->setActiveIcon(KIcon("object-unlocked"));
1664 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
1665 lockLayoutAction
->setInactiveIcon(KIcon("object-locked"));
1666 lockLayoutAction
->setActive(lock
);
1667 connect(lockLayoutAction
, SIGNAL(triggered()), this, SLOT(togglePanelLockState()));
1669 // Setup "Information"
1670 DolphinDockWidget
* infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
1671 infoDock
->setLocked(lock
);
1672 infoDock
->setObjectName("infoDock");
1673 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1674 Panel
* infoPanel
= new InformationPanel(infoDock
);
1675 infoPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1676 connect(infoPanel
, SIGNAL(urlActivated(KUrl
)), this, SLOT(handleUrl(KUrl
)));
1677 infoDock
->setWidget(infoPanel
);
1679 QAction
* infoAction
= infoDock
->toggleViewAction();
1680 createPanelAction(KIcon("dialog-information"), Qt::Key_F11
, infoAction
, "show_information_panel");
1682 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1683 connect(this, SIGNAL(urlChanged(KUrl
)),
1684 infoPanel
, SLOT(setUrl(KUrl
)));
1685 connect(this, SIGNAL(selectionChanged(KFileItemList
)),
1686 infoPanel
, SLOT(setSelection(KFileItemList
)));
1687 connect(this, SIGNAL(requestItemInfo(KFileItem
)),
1688 infoPanel
, SLOT(requestDelayedItemInfo(KFileItem
)));
1691 DolphinDockWidget
* foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
1692 foldersDock
->setLocked(lock
);
1693 foldersDock
->setObjectName("foldersDock");
1694 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1695 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1696 foldersPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1697 foldersDock
->setWidget(foldersPanel
);
1699 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1700 createPanelAction(KIcon("folder"), Qt::Key_F7
, foldersAction
, "show_folders_panel");
1702 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1703 connect(this, SIGNAL(urlChanged(KUrl
)),
1704 foldersPanel
, SLOT(setUrl(KUrl
)));
1705 connect(foldersPanel
, SIGNAL(folderActivated(KUrl
)),
1706 this, SLOT(changeUrl(KUrl
)));
1707 connect(foldersPanel
, SIGNAL(folderMiddleClicked(KUrl
)),
1708 this, SLOT(openNewTab(KUrl
)));
1709 connect(foldersPanel
, SIGNAL(errorMessage(QString
)),
1710 this, SLOT(slotPanelErrorMessage(QString
)));
1714 DolphinDockWidget
* terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1715 terminalDock
->setLocked(lock
);
1716 terminalDock
->setObjectName("terminalDock");
1717 terminalDock
->setAllowedAreas(Qt::TopDockWidgetArea
| Qt::BottomDockWidgetArea
);
1718 Panel
* terminalPanel
= new TerminalPanel(terminalDock
);
1719 terminalPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1720 terminalDock
->setWidget(terminalPanel
);
1722 connect(terminalPanel
, SIGNAL(hideTerminalPanel()), terminalDock
, SLOT(hide()));
1723 connect(terminalPanel
, SIGNAL(changeUrl(KUrl
)), this, SLOT(slotTerminalDirectoryChanged(KUrl
)));
1724 connect(terminalDock
, SIGNAL(visibilityChanged(bool)),
1725 terminalPanel
, SLOT(dockVisibilityChanged()));
1727 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1728 createPanelAction(KIcon("utilities-terminal"), Qt::Key_F4
, terminalAction
, "show_terminal_panel");
1730 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1731 connect(this, SIGNAL(urlChanged(KUrl
)),
1732 terminalPanel
, SLOT(setUrl(KUrl
)));
1735 if (GeneralSettings::version() < 200) {
1737 foldersDock
->hide();
1739 terminalDock
->hide();
1744 DolphinDockWidget
* placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
1745 placesDock
->setLocked(lock
);
1746 placesDock
->setObjectName("placesDock");
1747 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1749 PlacesPanel
* placesPanel
= new PlacesPanel(placesDock
);
1750 placesPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1751 placesDock
->setWidget(placesPanel
);
1753 QAction
* placesAction
= placesDock
->toggleViewAction();
1754 createPanelAction(KIcon("bookmarks"), Qt::Key_F9
, placesAction
, "show_places_panel");
1756 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1757 connect(placesPanel
, SIGNAL(placeActivated(KUrl
)),
1758 this, SLOT(changeUrl(KUrl
)));
1759 connect(placesPanel
, SIGNAL(placeMiddleClicked(KUrl
)),
1760 this, SLOT(openNewTab(KUrl
)));
1761 connect(placesPanel
, SIGNAL(errorMessage(QString
)),
1762 this, SLOT(slotPanelErrorMessage(QString
)));
1763 connect(this, SIGNAL(urlChanged(KUrl
)),
1764 placesPanel
, SLOT(setUrl(KUrl
)));
1765 connect(placesDock
, SIGNAL(visibilityChanged(bool)),
1766 this, SLOT(slotPlacesPanelVisibilityChanged(bool)));
1767 connect(this, SIGNAL(settingsChanged()),
1768 placesPanel
, SLOT(readSettings()));
1770 // Add actions into the "Panels" menu
1771 KActionMenu
* panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Panels"), this);
1772 actionCollection()->addAction("panels", panelsMenu
);
1773 panelsMenu
->setDelayed(false);
1774 const KActionCollection
* ac
= actionCollection();
1775 panelsMenu
->addAction(ac
->action("show_places_panel"));
1776 panelsMenu
->addAction(ac
->action("show_information_panel"));
1777 panelsMenu
->addAction(ac
->action("show_folders_panel"));
1779 panelsMenu
->addAction(ac
->action("show_terminal_panel"));
1781 panelsMenu
->addSeparator();
1782 panelsMenu
->addAction(lockLayoutAction
);
1785 void DolphinMainWindow::updateEditActions()
1787 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1788 if (list
.isEmpty()) {
1789 stateChanged("has_no_selection");
1791 stateChanged("has_selection");
1793 KActionCollection
* col
= actionCollection();
1794 QAction
* renameAction
= col
->action("rename");
1795 QAction
* moveToTrashAction
= col
->action("move_to_trash");
1796 QAction
* deleteAction
= col
->action("delete");
1797 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
1798 QAction
* deleteWithTrashShortcut
= col
->action("delete_shortcut"); // see DolphinViewActionHandler
1800 KFileItemListProperties
capabilities(list
);
1801 const bool enableMoveToTrash
= capabilities
.isLocal() && capabilities
.supportsMoving();
1803 renameAction
->setEnabled(capabilities
.supportsMoving());
1804 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1805 deleteAction
->setEnabled(capabilities
.supportsDeleting());
1806 deleteWithTrashShortcut
->setEnabled(capabilities
.supportsDeleting() && !enableMoveToTrash
);
1807 cutAction
->setEnabled(capabilities
.supportsMoving());
1809 updatePasteAction();
1812 void DolphinMainWindow::updateViewActions()
1814 m_actionHandler
->updateViewActions();
1816 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1817 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
1819 updateSplitAction();
1821 QAction
* editableLocactionAction
= actionCollection()->action("editable_location");
1822 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
1823 editableLocactionAction
->setChecked(urlNavigator
->isUrlEditable());
1826 void DolphinMainWindow::updateGoActions()
1828 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
1829 const KUrl currentUrl
= m_activeViewContainer
->url();
1830 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
1833 void DolphinMainWindow::createControlButton()
1835 if (m_controlButton
) {
1838 Q_ASSERT(!m_controlButton
);
1840 m_controlButton
= new QToolButton(this);
1841 m_controlButton
->setIcon(KIcon("applications-system"));
1842 m_controlButton
->setText(i18nc("@action", "Control"));
1843 m_controlButton
->setPopupMode(QToolButton::InstantPopup
);
1844 m_controlButton
->setToolButtonStyle(toolBar()->toolButtonStyle());
1846 KMenu
* controlMenu
= new KMenu(m_controlButton
);
1847 connect(controlMenu
, SIGNAL(aboutToShow()), this, SLOT(updateControlMenu()));
1849 m_controlButton
->setMenu(controlMenu
);
1851 toolBar()->addWidget(m_controlButton
);
1852 connect(toolBar(), SIGNAL(iconSizeChanged(QSize
)),
1853 m_controlButton
, SLOT(setIconSize(QSize
)));
1854 connect(toolBar(), SIGNAL(toolButtonStyleChanged(Qt::ToolButtonStyle
)),
1855 m_controlButton
, SLOT(setToolButtonStyle(Qt::ToolButtonStyle
)));
1857 // The added widgets are owned by the toolbar and may get deleted when e.g. the toolbar
1858 // gets edited. In this case we must add them again. The adding is done asynchronously by
1859 // m_updateToolBarTimer.
1860 connect(m_controlButton
, SIGNAL(destroyed()), this, SLOT(slotControlButtonDeleted()));
1861 m_updateToolBarTimer
= new QTimer(this);
1862 m_updateToolBarTimer
->setInterval(500);
1863 connect(m_updateToolBarTimer
, SIGNAL(timeout()), this, SLOT(updateToolBar()));
1866 void DolphinMainWindow::deleteControlButton()
1868 delete m_controlButton
;
1869 m_controlButton
= 0;
1871 delete m_updateToolBarTimer
;
1872 m_updateToolBarTimer
= 0;
1875 bool DolphinMainWindow::addActionToMenu(QAction
* action
, KMenu
* menu
)
1880 const KToolBar
* toolBarWidget
= toolBar();
1881 foreach (const QWidget
* widget
, action
->associatedWidgets()) {
1882 if (widget
== toolBarWidget
) {
1887 menu
->addAction(action
);
1891 void DolphinMainWindow::rememberClosedTab(int index
)
1893 KMenu
* tabsMenu
= m_recentTabsMenu
->menu();
1895 const QString primaryPath
= m_viewTab
[index
].primaryView
->url().path();
1896 const QString iconName
= KMimeType::iconNameForUrl(primaryPath
);
1898 QAction
* action
= new QAction(squeezedText(primaryPath
), tabsMenu
);
1900 ClosedTab closedTab
;
1901 closedTab
.primaryUrl
= m_viewTab
[index
].primaryView
->url();
1903 if (m_viewTab
[index
].secondaryView
) {
1904 closedTab
.secondaryUrl
= m_viewTab
[index
].secondaryView
->url();
1905 closedTab
.isSplit
= true;
1907 closedTab
.isSplit
= false;
1910 action
->setData(QVariant::fromValue(closedTab
));
1911 action
->setIcon(KIcon(iconName
));
1913 // add the closed tab menu entry after the separator and
1914 // "Empty Recently Closed Tabs" entry
1915 if (tabsMenu
->actions().size() == 2) {
1916 tabsMenu
->addAction(action
);
1918 tabsMenu
->insertAction(tabsMenu
->actions().at(2), action
);
1921 // assure that only up to 8 closed tabs are shown in the menu
1922 if (tabsMenu
->actions().size() > 8) {
1923 tabsMenu
->removeAction(tabsMenu
->actions().last());
1925 actionCollection()->action("closed_tabs")->setEnabled(true);
1926 KAcceleratorManager::manage(tabsMenu
);
1929 void DolphinMainWindow::refreshViews()
1931 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
1933 // remember the current active view, as because of
1934 // the refreshing the active view might change to
1935 // the secondary view
1936 DolphinViewContainer
* activeViewContainer
= m_activeViewContainer
;
1938 const int tabCount
= m_viewTab
.count();
1939 for (int i
= 0; i
< tabCount
; ++i
) {
1940 m_viewTab
[i
].primaryView
->readSettings();
1941 if (m_viewTab
[i
].secondaryView
) {
1942 m_viewTab
[i
].secondaryView
->readSettings();
1946 setActiveViewContainer(activeViewContainer
);
1948 if (GeneralSettings::modifiedStartupSettings()) {
1949 // The startup settings have been changed by the user (see bug #254947).
1950 // Synchronize the split-view setting with the active view:
1951 const bool splitView
= GeneralSettings::splitView();
1952 const ViewTab
& activeTab
= m_viewTab
[m_tabIndex
];
1953 const bool toggle
= ( splitView
&& !activeTab
.secondaryView
)
1954 || (!splitView
&& activeTab
.secondaryView
);
1960 emit
settingsChanged();
1963 void DolphinMainWindow::clearStatusBar()
1965 m_activeViewContainer
->statusBar()->resetToDefaultText();
1968 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
1970 connect(container
, SIGNAL(showFilterBarChanged(bool)),
1971 this, SLOT(updateFilterBarAction(bool)));
1972 connect(container
, SIGNAL(writeStateChanged(bool)),
1973 this, SLOT(slotWriteStateChanged(bool)));
1975 DolphinView
* view
= container
->view();
1976 connect(view
, SIGNAL(selectionChanged(KFileItemList
)),
1977 this, SLOT(slotSelectionChanged(KFileItemList
)));
1978 connect(view
, SIGNAL(requestItemInfo(KFileItem
)),
1979 this, SLOT(slotRequestItemInfo(KFileItem
)));
1980 connect(view
, SIGNAL(activated()),
1981 this, SLOT(toggleActiveView()));
1982 connect(view
, SIGNAL(tabRequested(KUrl
)),
1983 this, SLOT(openNewTab(KUrl
)));
1984 connect(view
, SIGNAL(requestContextMenu(QPoint
,KFileItem
,KUrl
,QList
<QAction
*>)),
1985 this, SLOT(openContextMenu(QPoint
,KFileItem
,KUrl
,QList
<QAction
*>)));
1986 connect(view
, SIGNAL(directoryLoadingStarted()),
1987 this, SLOT(enableStopAction()));
1988 connect(view
, SIGNAL(directoryLoadingCompleted()),
1989 this, SLOT(disableStopAction()));
1990 connect(view
, SIGNAL(goBackRequested()),
1991 this, SLOT(goBack()));
1992 connect(view
, SIGNAL(goForwardRequested()),
1993 this, SLOT(goForward()));
1995 const KUrlNavigator
* navigator
= container
->urlNavigator();
1996 connect(navigator
, SIGNAL(urlChanged(KUrl
)),
1997 this, SLOT(changeUrl(KUrl
)));
1998 connect(navigator
, SIGNAL(historyChanged()),
1999 this, SLOT(updateHistory()));
2000 connect(navigator
, SIGNAL(editableStateChanged(bool)),
2001 this, SLOT(slotEditableStateChanged(bool)));
2002 connect(navigator
, SIGNAL(tabRequested(KUrl
)),
2003 this, SLOT(openNewTab(KUrl
)));
2006 void DolphinMainWindow::updateSplitAction()
2008 QAction
* splitAction
= actionCollection()->action("split_view");
2009 if (m_viewTab
[m_tabIndex
].secondaryView
) {
2010 if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
2011 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
2012 splitAction
->setToolTip(i18nc("@info", "Close right view"));
2013 splitAction
->setIcon(KIcon("view-right-close"));
2015 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
2016 splitAction
->setToolTip(i18nc("@info", "Close left view"));
2017 splitAction
->setIcon(KIcon("view-left-close"));
2020 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
2021 splitAction
->setToolTip(i18nc("@info", "Split view"));
2022 splitAction
->setIcon(KIcon("view-right-new"));
2026 QString
DolphinMainWindow::tabName(const KUrl
& url
) const
2029 if (url
.equals(KUrl("file:///"))) {
2032 name
= url
.fileName();
2033 if (name
.isEmpty()) {
2034 name
= url
.protocol();
2036 // Make sure that a '&' inside the directory name is displayed correctly
2037 // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
2038 name
.replace('&', "&&");
2044 bool DolphinMainWindow::isKompareInstalled() const
2046 static bool initialized
= false;
2047 static bool installed
= false;
2049 // TODO: maybe replace this approach later by using a menu
2050 // plugin like kdiff3plugin.cpp
2051 installed
= !KGlobal::dirs()->findExe("kompare").isEmpty();
2057 void DolphinMainWindow::createSecondaryView(int tabIndex
)
2059 ViewTab
& viewTab
= m_viewTab
[tabIndex
];
2061 QSplitter
* splitter
= viewTab
.splitter
;
2062 const int newWidth
= (viewTab
.primaryView
->width() - splitter
->handleWidth()) / 2;
2064 const DolphinView
* view
= viewTab
.primaryView
->view();
2065 // The final parent of the new view container will be set by adding it
2066 // to the splitter. However, we must make sure that the DolphinMainWindow
2067 // is a parent of the view container already when it is constructed
2068 // because this enables the container's KFileItemModel to assign its
2069 // dir lister to the right main window. The dir lister can then cache
2070 // authentication data.
2071 viewTab
.secondaryView
= createViewContainer(view
->url(), this);
2072 splitter
->addWidget(viewTab
.secondaryView
);
2073 splitter
->setSizes(QList
<int>() << newWidth
<< newWidth
);
2075 connectViewSignals(viewTab
.secondaryView
);
2076 viewTab
.secondaryView
->setActive(false);
2077 viewTab
.secondaryView
->resize(newWidth
, viewTab
.primaryView
->height());
2078 viewTab
.secondaryView
->show();
2081 QString
DolphinMainWindow::tabProperty(const QString
& property
, int tabIndex
) const
2083 return "Tab " + QString::number(tabIndex
) + ' ' + property
;
2086 void DolphinMainWindow::setUrlAsCaption(const KUrl
& url
)
2089 if (!url
.isLocalFile()) {
2090 caption
.append(url
.protocol() + " - ");
2091 if (url
.hasHost()) {
2092 caption
.append(url
.host() + " - ");
2096 const QString fileName
= url
.fileName().isEmpty() ? "/" : url
.fileName();
2097 caption
.append(fileName
);
2099 setCaption(caption
);
2102 QString
DolphinMainWindow::squeezedText(const QString
& text
) const
2104 const QFontMetrics fm
= fontMetrics();
2105 return fm
.elidedText(text
, Qt::ElideMiddle
, fm
.maxWidth() * 10);
2108 void DolphinMainWindow::createPanelAction(const KIcon
& icon
,
2109 const QKeySequence
& shortcut
,
2110 QAction
* dockAction
,
2111 const QString
& actionName
)
2113 KAction
* panelAction
= actionCollection()->addAction(actionName
);
2114 panelAction
->setCheckable(true);
2115 panelAction
->setChecked(dockAction
->isChecked());
2116 panelAction
->setText(dockAction
->text());
2117 panelAction
->setIcon(icon
);
2118 panelAction
->setShortcut(shortcut
);
2120 connect(panelAction
, SIGNAL(triggered()), dockAction
, SLOT(trigger()));
2121 connect(dockAction
, SIGNAL(toggled(bool)), panelAction
, SLOT(setChecked(bool)));
2124 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
2125 KIO::FileUndoManager::UiInterface()
2129 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2133 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
2135 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
2137 DolphinViewContainer
* container
= mainWin
->activeViewContainer();
2138 container
->showMessage(job
->errorString(), DolphinViewContainer::Error
);
2140 KIO::FileUndoManager::UiInterface::jobError(job
);
2144 #include "dolphinmainwindow.moc"