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());
526 } else if ((list
.count() == 1) && list
[0].isDir()) {
527 openNewTab(list
[0].url());
531 void DolphinMainWindow::openInNewWindow()
535 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
536 if (list
.isEmpty()) {
537 newWindowUrl
= m_activeViewContainer
->url();
538 } else if ((list
.count() == 1) && list
[0].isDir()) {
539 newWindowUrl
= list
[0].url();
542 if (!newWindowUrl
.isEmpty()) {
543 KRun::run("dolphin %u", KUrl::List() << newWindowUrl
, this);
547 void DolphinMainWindow::toggleActiveView()
549 if (!m_viewTab
[m_tabIndex
].secondaryView
) {
550 // only one view is available
554 Q_ASSERT(m_activeViewContainer
);
555 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
557 DolphinViewContainer
* left
= m_viewTab
[m_tabIndex
].primaryView
;
558 DolphinViewContainer
* right
= m_viewTab
[m_tabIndex
].secondaryView
;
559 setActiveViewContainer(m_activeViewContainer
== right
? left
: right
);
562 void DolphinMainWindow::showEvent(QShowEvent
* event
)
564 KXmlGuiWindow::showEvent(event
);
565 if (!event
->spontaneous()) {
566 m_activeViewContainer
->view()->setFocus();
570 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
572 // Find out if Dolphin is closed directly by the user or
573 // by the session manager because the session is closed
574 bool closedByUser
= true;
575 DolphinApplication
*application
= qobject_cast
<DolphinApplication
*>(qApp
);
576 if (application
&& application
->sessionSaving()) {
577 closedByUser
= false;
580 if (m_viewTab
.count() > 1 && GeneralSettings::confirmClosingMultipleTabs() && closedByUser
) {
581 // Ask the user if he really wants to quit and close all tabs.
582 // Open a confirmation dialog with 3 buttons:
583 // KDialog::Yes -> Quit
584 // KDialog::No -> Close only the current tab
585 // KDialog::Cancel -> do nothing
586 KDialog
*dialog
= new KDialog(this, Qt::Dialog
);
587 dialog
->setCaption(i18nc("@title:window", "Confirmation"));
588 dialog
->setButtons(KDialog::Yes
| KDialog::No
| KDialog::Cancel
);
589 dialog
->setModal(true);
590 dialog
->setButtonGuiItem(KDialog::Yes
, KStandardGuiItem::quit());
591 dialog
->setButtonGuiItem(KDialog::No
, KGuiItem(i18n("C&lose Current Tab"), KIcon("tab-close")));
592 dialog
->setButtonGuiItem(KDialog::Cancel
, KStandardGuiItem::cancel());
593 dialog
->setDefaultButton(KDialog::Yes
);
595 bool doNotAskAgainCheckboxResult
= false;
597 const int result
= KMessageBox::createKMessageBox(dialog
,
598 QMessageBox::Warning
,
599 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
601 i18n("Do not ask again"),
602 &doNotAskAgainCheckboxResult
,
603 KMessageBox::Notify
);
605 if (doNotAskAgainCheckboxResult
) {
606 GeneralSettings::setConfirmClosingMultipleTabs(false);
614 // Close only the current tab
622 GeneralSettings::setVersion(CurrentDolphinVersion
);
623 GeneralSettings::self()->writeConfig();
625 KXmlGuiWindow::closeEvent(event
);
628 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
630 const int tabCount
= m_viewTab
.count();
631 group
.writeEntry("Tab Count", tabCount
);
632 group
.writeEntry("Active Tab Index", m_tabBar
->currentIndex());
634 for (int i
= 0; i
< tabCount
; ++i
) {
635 const DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
636 group
.writeEntry(tabProperty("Primary URL", i
), cont
->url().url());
637 group
.writeEntry(tabProperty("Primary Editable", i
),
638 cont
->urlNavigator()->isUrlEditable());
640 cont
= m_viewTab
[i
].secondaryView
;
642 group
.writeEntry(tabProperty("Secondary URL", i
), cont
->url().url());
643 group
.writeEntry(tabProperty("Secondary Editable", i
),
644 cont
->urlNavigator()->isUrlEditable());
649 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
651 const int tabCount
= group
.readEntry("Tab Count", 1);
652 for (int i
= 0; i
< tabCount
; ++i
) {
653 DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
655 cont
->setUrl(group
.readEntry(tabProperty("Primary URL", i
)));
656 const bool editable
= group
.readEntry(tabProperty("Primary Editable", i
), false);
657 cont
->urlNavigator()->setUrlEditable(editable
);
659 cont
= m_viewTab
[i
].secondaryView
;
660 const QString secondaryUrl
= group
.readEntry(tabProperty("Secondary URL", i
));
661 if (!secondaryUrl
.isEmpty()) {
663 // a secondary view should be shown, but no one is available
664 // currently -> create a new view
666 cont
= m_viewTab
[i
].secondaryView
;
670 cont
->setUrl(secondaryUrl
);
671 const bool editable
= group
.readEntry(tabProperty("Secondary Editable", i
), false);
672 cont
->urlNavigator()->setUrlEditable(editable
);
674 // no secondary view should be shown, but the default setting shows
675 // one already -> close the view
679 // openNewTab() needs to be called only tabCount - 1 times
680 if (i
!= tabCount
- 1) {
685 const int index
= group
.readEntry("Active Tab Index", 0);
686 m_tabBar
->setCurrentIndex(index
);
689 void DolphinMainWindow::updateNewMenu()
691 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
692 m_newFileMenu
->checkUpToDate();
693 m_newFileMenu
->setPopupFiles(activeViewContainer()->url());
696 void DolphinMainWindow::createDirectory()
698 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
699 m_newFileMenu
->setPopupFiles(activeViewContainer()->url());
700 m_newFileMenu
->createDirectory();
703 void DolphinMainWindow::quit()
708 void DolphinMainWindow::showErrorMessage(const QString
& message
)
710 m_activeViewContainer
->showMessage(message
, DolphinViewContainer::Error
);
713 void DolphinMainWindow::slotUndoAvailable(bool available
)
715 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
717 undoAction
->setEnabled(available
);
721 void DolphinMainWindow::restoreClosedTab(QAction
* action
)
723 if (action
->data().toBool()) {
724 // clear all actions except the "Empty Recently Closed Tabs"
725 // action and the separator
726 QList
<QAction
*> actions
= m_recentTabsMenu
->menu()->actions();
727 const int count
= actions
.size();
728 for (int i
= 2; i
< count
; ++i
) {
729 m_recentTabsMenu
->menu()->removeAction(actions
.at(i
));
732 const ClosedTab closedTab
= action
->data().value
<ClosedTab
>();
733 openNewTab(closedTab
.primaryUrl
);
734 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
736 if (closedTab
.isSplit
) {
737 // create secondary view
739 m_viewTab
[m_tabIndex
].secondaryView
->setUrl(closedTab
.secondaryUrl
);
742 m_recentTabsMenu
->removeAction(action
);
745 if (m_recentTabsMenu
->menu()->actions().count() == 2) {
746 m_recentTabsMenu
->setEnabled(false);
750 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
752 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
754 undoAction
->setText(text
);
758 void DolphinMainWindow::undo()
761 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
762 KIO::FileUndoManager::self()->undo();
765 void DolphinMainWindow::cut()
767 m_activeViewContainer
->view()->cutSelectedItems();
770 void DolphinMainWindow::copy()
772 m_activeViewContainer
->view()->copySelectedItems();
775 void DolphinMainWindow::paste()
777 m_activeViewContainer
->view()->paste();
780 void DolphinMainWindow::find()
782 m_activeViewContainer
->setSearchModeEnabled(true);
785 void DolphinMainWindow::updatePasteAction()
787 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
788 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
789 pasteAction
->setEnabled(pasteInfo
.first
);
790 pasteAction
->setText(pasteInfo
.second
);
793 void DolphinMainWindow::selectAll()
797 // if the URL navigator is editable and focused, select the whole
798 // URL instead of all items of the view
800 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
801 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit(); // krazy:exclude=qclasses
802 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
803 lineEdit
->hasFocus();
805 lineEdit
->selectAll();
807 m_activeViewContainer
->view()->selectAll();
811 void DolphinMainWindow::invertSelection()
814 m_activeViewContainer
->view()->invertSelection();
817 void DolphinMainWindow::toggleSplitView()
819 if (!m_viewTab
[m_tabIndex
].secondaryView
) {
820 createSecondaryView(m_tabIndex
);
821 setActiveViewContainer(m_viewTab
[m_tabIndex
].secondaryView
);
822 } else if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
823 // remove secondary view
824 m_viewTab
[m_tabIndex
].secondaryView
->close();
825 m_viewTab
[m_tabIndex
].secondaryView
->deleteLater();
826 m_viewTab
[m_tabIndex
].secondaryView
= 0;
828 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
830 // The primary view is active and should be closed. Hence from a users point of view
831 // the content of the secondary view should be moved to the primary view.
832 // From an implementation point of view it is more efficient to close
833 // the primary view and exchange the internal pointers afterwards.
835 m_viewTab
[m_tabIndex
].primaryView
->close();
836 m_viewTab
[m_tabIndex
].primaryView
->deleteLater();
837 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
838 m_viewTab
[m_tabIndex
].secondaryView
= 0;
840 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
846 void DolphinMainWindow::reloadView()
849 m_activeViewContainer
->view()->reload();
852 void DolphinMainWindow::stopLoading()
854 m_activeViewContainer
->view()->stopLoading();
857 void DolphinMainWindow::enableStopAction()
859 actionCollection()->action("stop")->setEnabled(true);
862 void DolphinMainWindow::disableStopAction()
864 actionCollection()->action("stop")->setEnabled(false);
867 void DolphinMainWindow::showFilterBar()
869 m_activeViewContainer
->setFilterBarVisible(true);
872 void DolphinMainWindow::toggleEditLocation()
876 QAction
* action
= actionCollection()->action("editable_location");
877 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
878 urlNavigator
->setUrlEditable(action
->isChecked());
881 void DolphinMainWindow::replaceLocation()
883 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
884 navigator
->setUrlEditable(true);
885 navigator
->setFocus();
887 // select the whole text of the combo box editor
888 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit(); // krazy:exclude=qclasses
889 lineEdit
->selectAll();
892 void DolphinMainWindow::togglePanelLockState()
894 const bool newLockState
= !GeneralSettings::lockPanels();
895 foreach (QObject
* child
, children()) {
896 DolphinDockWidget
* dock
= qobject_cast
<DolphinDockWidget
*>(child
);
898 dock
->setLocked(newLockState
);
902 GeneralSettings::setLockPanels(newLockState
);
905 void DolphinMainWindow::slotPlacesPanelVisibilityChanged(bool visible
)
907 const int tabCount
= m_viewTab
.count();
908 for (int i
= 0; i
< tabCount
; ++i
) {
909 ViewTab
& tab
= m_viewTab
[i
];
910 Q_ASSERT(tab
.primaryView
);
911 tab
.primaryView
->urlNavigator()->setPlacesSelectorVisible(!visible
);
912 if (tab
.secondaryView
) {
913 tab
.secondaryView
->urlNavigator()->setPlacesSelectorVisible(!visible
);
918 void DolphinMainWindow::goBack()
920 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
921 urlNavigator
->goBack();
923 if (urlNavigator
->locationState().isEmpty()) {
924 // An empty location state indicates a redirection URL,
925 // which must be skipped too
926 urlNavigator
->goBack();
930 void DolphinMainWindow::goForward()
932 m_activeViewContainer
->urlNavigator()->goForward();
935 void DolphinMainWindow::goUp()
937 m_activeViewContainer
->urlNavigator()->goUp();
940 void DolphinMainWindow::goHome()
942 m_activeViewContainer
->urlNavigator()->goHome();
945 void DolphinMainWindow::goBack(Qt::MouseButtons buttons
)
947 // The default case (left button pressed) is handled in goBack().
948 if (buttons
== Qt::MidButton
) {
949 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
950 const int index
= urlNavigator
->historyIndex() + 1;
951 openNewTab(urlNavigator
->locationUrl(index
));
955 void DolphinMainWindow::goForward(Qt::MouseButtons buttons
)
957 // The default case (left button pressed) is handled in goForward().
958 if (buttons
== Qt::MidButton
) {
959 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
960 const int index
= urlNavigator
->historyIndex() - 1;
961 openNewTab(urlNavigator
->locationUrl(index
));
965 void DolphinMainWindow::goUp(Qt::MouseButtons buttons
)
967 // The default case (left button pressed) is handled in goUp().
968 if (buttons
== Qt::MidButton
) {
969 openNewTab(activeViewContainer()->url().upUrl());
973 void DolphinMainWindow::goHome(Qt::MouseButtons buttons
)
975 // The default case (left button pressed) is handled in goHome().
976 if (buttons
== Qt::MidButton
) {
977 openNewTab(GeneralSettings::self()->homeUrl());
981 void DolphinMainWindow::compareFiles()
983 // The method is only invoked if exactly 2 files have
984 // been selected. The selected files may be:
985 // - both in the primary view
986 // - both in the secondary view
987 // - one in the primary view and the other in the secondary
989 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
994 KFileItemList items
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedItems();
996 switch (items
.count()) {
998 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
);
999 items
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItems();
1000 Q_ASSERT(items
.count() == 2);
1001 urlA
= items
[0].url();
1002 urlB
= items
[1].url();
1007 urlA
= items
[0].url();
1008 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
);
1009 items
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItems();
1010 Q_ASSERT(items
.count() == 1);
1011 urlB
= items
[0].url();
1016 urlA
= items
[0].url();
1017 urlB
= items
[1].url();
1022 // may not happen: compareFiles may only get invoked if 2
1023 // files are selected
1028 QString
command("kompare -c \"");
1029 command
.append(urlA
.pathOrUrl());
1030 command
.append("\" \"");
1031 command
.append(urlB
.pathOrUrl());
1032 command
.append('\"');
1033 KRun::runCommand(command
, "Kompare", "kompare", this);
1036 void DolphinMainWindow::toggleShowMenuBar()
1038 const bool visible
= menuBar()->isVisible();
1039 menuBar()->setVisible(!visible
);
1041 createControlButton();
1043 deleteControlButton();
1047 void DolphinMainWindow::openTerminal()
1049 QString
dir(QDir::homePath());
1051 // If the given directory is not local, it can still be the URL of an
1052 // ioslave using UDS_LOCAL_PATH which to be converted first.
1053 KUrl url
= KIO::NetAccess::mostLocalUrl(m_activeViewContainer
->url(), this);
1055 //If the URL is local after the above conversion, set the directory.
1056 if (url
.isLocalFile()) {
1057 dir
= url
.toLocalFile();
1060 KToolInvocation::invokeTerminal(QString(), dir
);
1063 void DolphinMainWindow::editSettings()
1065 if (!m_settingsDialog
) {
1066 DolphinViewContainer
* container
= activeViewContainer();
1067 container
->view()->writeSettings();
1069 const KUrl url
= container
->url();
1070 DolphinSettingsDialog
* settingsDialog
= new DolphinSettingsDialog(url
, this);
1071 connect(settingsDialog
, SIGNAL(settingsChanged()), this, SLOT(refreshViews()));
1072 settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1073 settingsDialog
->show();
1074 m_settingsDialog
= settingsDialog
;
1076 m_settingsDialog
.data()->raise();
1080 void DolphinMainWindow::setActiveTab(int index
)
1082 Q_ASSERT(index
>= 0);
1083 Q_ASSERT(index
< m_viewTab
.count());
1084 if (index
== m_tabIndex
) {
1088 // hide current tab content
1089 ViewTab
& hiddenTab
= m_viewTab
[m_tabIndex
];
1090 hiddenTab
.isPrimaryViewActive
= hiddenTab
.primaryView
->isActive();
1091 hiddenTab
.primaryView
->setActive(false);
1092 if (hiddenTab
.secondaryView
) {
1093 hiddenTab
.secondaryView
->setActive(false);
1095 QSplitter
* splitter
= m_viewTab
[m_tabIndex
].splitter
;
1097 m_centralWidgetLayout
->removeWidget(splitter
);
1099 // show active tab content
1102 ViewTab
& viewTab
= m_viewTab
[index
];
1103 m_centralWidgetLayout
->addWidget(viewTab
.splitter
, 1);
1104 viewTab
.primaryView
->show();
1105 if (viewTab
.secondaryView
) {
1106 viewTab
.secondaryView
->show();
1108 viewTab
.splitter
->show();
1110 if (!viewTab
.wasActive
) {
1111 viewTab
.wasActive
= true;
1113 // If the tab has not been activated yet the size of the KItemListView is
1114 // undefined and results in an unwanted animation. To prevent this a
1115 // reloading of the directory gets triggered.
1116 viewTab
.primaryView
->view()->reload();
1117 if (viewTab
.secondaryView
) {
1118 viewTab
.secondaryView
->view()->reload();
1122 setActiveViewContainer(viewTab
.isPrimaryViewActive
? viewTab
.primaryView
:
1123 viewTab
.secondaryView
);
1126 void DolphinMainWindow::closeTab()
1128 closeTab(m_tabBar
->currentIndex());
1131 void DolphinMainWindow::closeTab(int index
)
1133 Q_ASSERT(index
>= 0);
1134 Q_ASSERT(index
< m_viewTab
.count());
1135 if (m_viewTab
.count() == 1) {
1136 // the last tab may never get closed
1140 if (index
== m_tabIndex
) {
1141 // The tab that should be closed is the active tab. Activate the
1142 // previous tab before closing the tab.
1143 m_tabBar
->setCurrentIndex((index
> 0) ? index
- 1 : 1);
1145 rememberClosedTab(index
);
1148 m_viewTab
[index
].primaryView
->deleteLater();
1149 if (m_viewTab
[index
].secondaryView
) {
1150 m_viewTab
[index
].secondaryView
->deleteLater();
1152 m_viewTab
[index
].splitter
->deleteLater();
1153 m_viewTab
.erase(m_viewTab
.begin() + index
);
1155 m_tabBar
->blockSignals(true);
1156 m_tabBar
->removeTab(index
);
1158 if (m_tabIndex
> index
) {
1160 Q_ASSERT(m_tabIndex
>= 0);
1163 // if only one tab is left, also remove the tab entry so that
1164 // closing the last tab is not possible
1165 if (m_viewTab
.count() == 1) {
1166 m_tabBar
->removeTab(0);
1167 actionCollection()->action("close_tab")->setEnabled(false);
1169 m_tabBar
->blockSignals(false);
1173 void DolphinMainWindow::openTabContextMenu(int index
, const QPoint
& pos
)
1177 QAction
* newTabAction
= menu
.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab"));
1178 newTabAction
->setShortcut(actionCollection()->action("new_tab")->shortcut());
1180 QAction
* detachTabAction
= menu
.addAction(KIcon("tab-detach"), i18nc("@action:inmenu", "Detach Tab"));
1182 QAction
* closeOtherTabsAction
= menu
.addAction(KIcon("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs"));
1184 QAction
* closeTabAction
= menu
.addAction(KIcon("tab-close"), i18nc("@action:inmenu", "Close Tab"));
1185 closeTabAction
->setShortcut(actionCollection()->action("close_tab")->shortcut());
1186 QAction
* selectedAction
= menu
.exec(pos
);
1187 if (selectedAction
== newTabAction
) {
1188 const ViewTab
& tab
= m_viewTab
[index
];
1189 Q_ASSERT(tab
.primaryView
);
1190 const KUrl url
= tab
.secondaryView
&& tab
.secondaryView
->isActive() ?
1191 tab
.secondaryView
->url() : tab
.primaryView
->url();
1193 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
1194 } else if (selectedAction
== detachTabAction
) {
1195 const QString
separator(QLatin1Char(' '));
1196 QString command
= QLatin1String("dolphin");
1198 const ViewTab
& tab
= m_viewTab
[index
];
1199 Q_ASSERT(tab
.primaryView
);
1201 command
+= separator
+ tab
.primaryView
->url().url();
1202 if (tab
.secondaryView
) {
1203 command
+= separator
+ tab
.secondaryView
->url().url();
1204 command
+= separator
+ QLatin1String("-split");
1207 KRun::runCommand(command
, this);
1210 } else if (selectedAction
== closeOtherTabsAction
) {
1211 const int count
= m_tabBar
->count();
1212 for (int i
= 0; i
< index
; ++i
) {
1215 for (int i
= index
+ 1; i
< count
; ++i
) {
1218 } else if (selectedAction
== closeTabAction
) {
1223 void DolphinMainWindow::slotTabMoved(int from
, int to
)
1225 m_viewTab
.move(from
, to
);
1226 m_tabIndex
= m_tabBar
->currentIndex();
1229 void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent
* event
, bool& canDecode
)
1231 canDecode
= KUrl::List::canDecode(event
->mimeData());
1234 void DolphinMainWindow::handleUrl(const KUrl
& url
)
1236 delete m_lastHandleUrlStatJob
;
1237 m_lastHandleUrlStatJob
= 0;
1239 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1240 activeViewContainer()->setUrl(url
);
1241 } else if (KProtocolManager::supportsListing(url
)) {
1242 // stat the URL to see if it is a dir or not
1243 m_lastHandleUrlStatJob
= KIO::stat(url
, KIO::HideProgressInfo
);
1244 if (m_lastHandleUrlStatJob
->ui()) {
1245 m_lastHandleUrlStatJob
->ui()->setWindow(this);
1247 connect(m_lastHandleUrlStatJob
, SIGNAL(result(KJob
*)),
1248 this, SLOT(slotHandleUrlStatFinished(KJob
*)));
1251 new KRun(url
, this); // Automatically deletes itself after being finished
1255 void DolphinMainWindow::slotHandleUrlStatFinished(KJob
* job
)
1257 m_lastHandleUrlStatJob
= 0;
1258 const KIO::UDSEntry entry
= static_cast<KIO::StatJob
*>(job
)->statResult();
1259 const KUrl url
= static_cast<KIO::StatJob
*>(job
)->url();
1260 if (entry
.isDir()) {
1261 activeViewContainer()->setUrl(url
);
1263 new KRun(url
, this); // Automatically deletes itself after being finished
1267 void DolphinMainWindow::tabDropEvent(int tab
, QDropEvent
* event
)
1269 const KUrl::List urls
= KUrl::List::fromMimeData(event
->mimeData());
1270 if (!urls
.isEmpty() && tab
!= -1) {
1271 const ViewTab
& viewTab
= m_viewTab
[tab
];
1272 const DolphinView
* view
= viewTab
.isPrimaryViewActive
? viewTab
.primaryView
->view()
1273 : viewTab
.secondaryView
->view();
1275 DragAndDropHelper::dropUrls(view
->rootItem(), view
->url(), event
, error
);
1276 if (!error
.isEmpty()) {
1277 activeViewContainer()->showMessage(error
, DolphinViewContainer::Error
);
1282 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1284 newFileMenu()->setEnabled(isFolderWritable
);
1287 void DolphinMainWindow::openContextMenu(const QPoint
& pos
,
1288 const KFileItem
& item
,
1290 const QList
<QAction
*>& customActions
)
1292 QWeakPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, pos
, item
, url
);
1293 contextMenu
.data()->setCustomActions(customActions
);
1294 const DolphinContextMenu::Command command
= contextMenu
.data()->open();
1297 case DolphinContextMenu::OpenParentFolderInNewWindow
: {
1298 KRun::run("dolphin %u", KUrl::List() << item
.url().upUrl(), this);
1302 case DolphinContextMenu::OpenParentFolderInNewTab
:
1303 openNewTab(item
.url().upUrl());
1306 case DolphinContextMenu::None
:
1311 delete contextMenu
.data();
1314 void DolphinMainWindow::updateControlMenu()
1316 KMenu
* menu
= qobject_cast
<KMenu
*>(sender());
1319 // All actions get cleared by KMenu::clear(). The sub-menus are deleted
1320 // by connecting to the aboutToHide() signal from the parent-menu.
1323 KActionCollection
* ac
= actionCollection();
1325 // Add "Edit" actions
1326 bool added
= addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Undo
)), menu
) |
1327 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Find
)), menu
) |
1328 addActionToMenu(ac
->action("select_all"), menu
) |
1329 addActionToMenu(ac
->action("invert_selection"), menu
);
1332 menu
->addSeparator();
1335 // Add "View" actions
1336 if (!GeneralSettings::showZoomSlider()) {
1337 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomIn
)), menu
);
1338 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomOut
)), menu
);
1339 menu
->addSeparator();
1342 added
= addActionToMenu(ac
->action("view_mode"), menu
) |
1343 addActionToMenu(ac
->action("sort"), menu
) |
1344 addActionToMenu(ac
->action("additional_info"), menu
) |
1345 addActionToMenu(ac
->action("show_preview"), menu
) |
1346 addActionToMenu(ac
->action("show_in_groups"), menu
) |
1347 addActionToMenu(ac
->action("show_hidden_files"), menu
);
1350 menu
->addSeparator();
1353 added
= addActionToMenu(ac
->action("split_view"), menu
) |
1354 addActionToMenu(ac
->action("reload"), menu
) |
1355 addActionToMenu(ac
->action("view_properties"), menu
);
1357 menu
->addSeparator();
1360 addActionToMenu(ac
->action("panels"), menu
);
1361 KMenu
* locationBarMenu
= new KMenu(i18nc("@action:inmenu", "Location Bar"), menu
);
1362 locationBarMenu
->addAction(ac
->action("editable_location"));
1363 locationBarMenu
->addAction(ac
->action("replace_location"));
1364 menu
->addMenu(locationBarMenu
);
1366 menu
->addSeparator();
1369 KMenu
* goMenu
= new KMenu(i18nc("@action:inmenu", "Go"), menu
);
1370 connect(menu
, SIGNAL(aboutToHide()), goMenu
, SLOT(deleteLater()));
1371 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Back
)));
1372 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Forward
)));
1373 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Up
)));
1374 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Home
)));
1375 goMenu
->addAction(ac
->action("closed_tabs"));
1376 menu
->addMenu(goMenu
);
1379 KMenu
* toolsMenu
= new KMenu(i18nc("@action:inmenu", "Tools"), menu
);
1380 connect(menu
, SIGNAL(aboutToHide()), toolsMenu
, SLOT(deleteLater()));
1381 toolsMenu
->addAction(ac
->action("show_filter_bar"));
1382 toolsMenu
->addAction(ac
->action("compare_files"));
1383 toolsMenu
->addAction(ac
->action("open_terminal"));
1384 toolsMenu
->addAction(ac
->action("change_remote_encoding"));
1385 menu
->addMenu(toolsMenu
);
1387 // Add "Settings" menu entries
1388 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::KeyBindings
)), menu
);
1389 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ConfigureToolbars
)), menu
);
1390 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Preferences
)), menu
);
1393 KMenu
* helpMenu
= new KMenu(i18nc("@action:inmenu", "Help"), menu
);
1394 connect(menu
, SIGNAL(aboutToHide()), helpMenu
, SLOT(deleteLater()));
1395 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::HelpContents
)));
1396 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::WhatsThis
)));
1397 helpMenu
->addSeparator();
1398 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ReportBug
)));
1399 helpMenu
->addSeparator();
1400 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
)));
1401 helpMenu
->addSeparator();
1402 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::AboutApp
)));
1403 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::AboutKDE
)));
1404 menu
->addMenu(helpMenu
);
1406 menu
->addSeparator();
1407 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ShowMenubar
)), menu
);
1410 void DolphinMainWindow::updateToolBar()
1412 if (!menuBar()->isVisible()) {
1413 createControlButton();
1417 void DolphinMainWindow::slotControlButtonDeleted()
1419 m_controlButton
= 0;
1420 m_updateToolBarTimer
->start();
1423 void DolphinMainWindow::slotPanelErrorMessage(const QString
& error
)
1425 activeViewContainer()->showMessage(error
, DolphinViewContainer::Error
);
1428 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer
* viewContainer
)
1430 Q_ASSERT(viewContainer
);
1431 Q_ASSERT((viewContainer
== m_viewTab
[m_tabIndex
].primaryView
) ||
1432 (viewContainer
== m_viewTab
[m_tabIndex
].secondaryView
));
1433 if (m_activeViewContainer
== viewContainer
) {
1437 m_activeViewContainer
->setActive(false);
1438 m_activeViewContainer
= viewContainer
;
1440 // Activating the view container might trigger a recursive setActiveViewContainer() call
1441 // inside DolphinMainWindow::toggleActiveView() when having a split view. Temporary
1442 // disconnect the activated() signal in this case:
1443 disconnect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1444 m_activeViewContainer
->setActive(true);
1445 connect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1447 m_actionHandler
->setCurrentView(viewContainer
->view());
1450 updateEditActions();
1451 updateViewActions();
1454 const KUrl url
= m_activeViewContainer
->url();
1455 setUrlAsCaption(url
);
1456 if (m_viewTab
.count() > 1) {
1457 m_tabBar
->setTabText(m_tabIndex
, tabName(url
));
1458 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(KMimeType::iconNameForUrl(url
)));
1461 emit
urlChanged(url
);
1464 DolphinViewContainer
* DolphinMainWindow::createViewContainer(const KUrl
& url
, QWidget
* parent
)
1466 DolphinViewContainer
* container
= new DolphinViewContainer(url
, parent
);
1468 // The places-selector from the URL navigator should only be shown
1469 // if the places dock is invisible
1470 QDockWidget
* placesDock
= findChild
<QDockWidget
*>("placesDock");
1471 container
->urlNavigator()->setPlacesSelectorVisible(!placesDock
|| !placesDock
->isVisible());
1476 void DolphinMainWindow::setupActions()
1478 // setup 'File' menu
1479 m_newFileMenu
= new DolphinNewFileMenu(this);
1480 KMenu
* menu
= m_newFileMenu
->menu();
1481 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1482 menu
->setIcon(KIcon("document-new"));
1483 m_newFileMenu
->setDelayed(false);
1484 connect(menu
, SIGNAL(aboutToShow()),
1485 this, SLOT(updateNewMenu()));
1487 KAction
* newWindow
= actionCollection()->addAction("new_window");
1488 newWindow
->setIcon(KIcon("window-new"));
1489 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1490 newWindow
->setShortcut(Qt::CTRL
| Qt::Key_N
);
1491 connect(newWindow
, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1493 KAction
* newTab
= actionCollection()->addAction("new_tab");
1494 newTab
->setIcon(KIcon("tab-new"));
1495 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1496 newTab
->setShortcut(KShortcut(Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
));
1497 connect(newTab
, SIGNAL(triggered()), this, SLOT(openNewTab()));
1499 KAction
* closeTab
= actionCollection()->addAction("close_tab");
1500 closeTab
->setIcon(KIcon("tab-close"));
1501 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1502 closeTab
->setShortcut(Qt::CTRL
| Qt::Key_W
);
1503 closeTab
->setEnabled(false);
1504 connect(closeTab
, SIGNAL(triggered()), this, SLOT(closeTab()));
1506 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1508 // setup 'Edit' menu
1509 KStandardAction::undo(this,
1511 actionCollection());
1513 // need to remove shift+del from cut action, else the shortcut for deletejob
1515 KAction
* cut
= KStandardAction::cut(this, SLOT(cut()), actionCollection());
1516 KShortcut cutShortcut
= cut
->shortcut();
1517 cutShortcut
.remove(Qt::SHIFT
| Qt::Key_Delete
, KShortcut::KeepEmpty
);
1518 cut
->setShortcut(cutShortcut
);
1519 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1520 KAction
* paste
= KStandardAction::paste(this, SLOT(paste()), actionCollection());
1521 // The text of the paste-action is modified dynamically by Dolphin
1522 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1523 // due to the long text, the text "Paste" is used:
1524 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1526 KStandardAction::find(this, SLOT(find()), actionCollection());
1528 KAction
* selectAll
= actionCollection()->addAction("select_all");
1529 selectAll
->setText(i18nc("@action:inmenu Edit", "Select All"));
1530 selectAll
->setShortcut(Qt::CTRL
| Qt::Key_A
);
1531 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
1533 KAction
* invertSelection
= actionCollection()->addAction("invert_selection");
1534 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1535 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1536 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
1538 // setup 'View' menu
1539 // (note that most of it is set up in DolphinViewActionHandler)
1541 KAction
* split
= actionCollection()->addAction("split_view");
1542 split
->setShortcut(Qt::Key_F3
);
1543 updateSplitAction();
1544 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1546 KAction
* reload
= actionCollection()->addAction("reload");
1547 reload
->setText(i18nc("@action:inmenu View", "Reload"));
1548 reload
->setShortcut(Qt::Key_F5
);
1549 reload
->setIcon(KIcon("view-refresh"));
1550 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
1552 KAction
* stop
= actionCollection()->addAction("stop");
1553 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1554 stop
->setToolTip(i18nc("@info", "Stop loading"));
1555 stop
->setIcon(KIcon("process-stop"));
1556 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
1558 KToggleAction
* editableLocation
= actionCollection()->add
<KToggleAction
>("editable_location");
1559 editableLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1560 editableLocation
->setShortcut(Qt::Key_F6
);
1561 connect(editableLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1563 KAction
* replaceLocation
= actionCollection()->addAction("replace_location");
1564 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1565 replaceLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
1566 connect(replaceLocation
, SIGNAL(triggered()), this, SLOT(replaceLocation()));
1569 KAction
* backAction
= KStandardAction::back(this, SLOT(goBack()), actionCollection());
1570 connect(backAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goBack(Qt::MouseButtons
)));
1571 KShortcut backShortcut
= backAction
->shortcut();
1572 backShortcut
.setAlternate(Qt::Key_Backspace
);
1573 backAction
->setShortcut(backShortcut
);
1575 m_recentTabsMenu
= new KActionMenu(i18n("Recently Closed Tabs"), this);
1576 m_recentTabsMenu
->setIcon(KIcon("edit-undo"));
1577 m_recentTabsMenu
->setDelayed(false);
1578 actionCollection()->addAction("closed_tabs", m_recentTabsMenu
);
1579 connect(m_recentTabsMenu
->menu(), SIGNAL(triggered(QAction
*)),
1580 this, SLOT(restoreClosedTab(QAction
*)));
1582 QAction
* action
= new QAction(i18n("Empty Recently Closed Tabs"), m_recentTabsMenu
);
1583 action
->setIcon(KIcon("edit-clear-list"));
1584 action
->setData(QVariant::fromValue(true));
1585 m_recentTabsMenu
->addAction(action
);
1586 m_recentTabsMenu
->addSeparator();
1587 m_recentTabsMenu
->setEnabled(false);
1589 KAction
* forwardAction
= KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1590 connect(forwardAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goForward(Qt::MouseButtons
)));
1592 KAction
* upAction
= KStandardAction::up(this, SLOT(goUp()), actionCollection());
1593 connect(upAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goUp(Qt::MouseButtons
)));
1595 KAction
* homeAction
= KStandardAction::home(this, SLOT(goHome()), actionCollection());
1596 connect(homeAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goHome(Qt::MouseButtons
)));
1598 // setup 'Tools' menu
1599 KAction
* showFilterBar
= actionCollection()->addAction("show_filter_bar");
1600 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1601 showFilterBar
->setIcon(KIcon("view-filter"));
1602 showFilterBar
->setShortcut(Qt::CTRL
| Qt::Key_I
);
1603 connect(showFilterBar
, SIGNAL(triggered()), this, SLOT(showFilterBar()));
1605 KAction
* compareFiles
= actionCollection()->addAction("compare_files");
1606 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1607 compareFiles
->setIcon(KIcon("kompare"));
1608 compareFiles
->setEnabled(false);
1609 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
1611 KAction
* openTerminal
= actionCollection()->addAction("open_terminal");
1612 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1613 openTerminal
->setIcon(KIcon("utilities-terminal"));
1614 openTerminal
->setShortcut(Qt::SHIFT
| Qt::Key_F4
);
1615 connect(openTerminal
, SIGNAL(triggered()), this, SLOT(openTerminal()));
1617 // setup 'Settings' menu
1618 KToggleAction
* showMenuBar
= KStandardAction::showMenubar(0, 0, actionCollection());
1619 connect(showMenuBar
, SIGNAL(triggered(bool)), // Fixes #286822
1620 this, SLOT(toggleShowMenuBar()), Qt::QueuedConnection
);
1621 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1623 // not in menu actions
1624 QList
<QKeySequence
> nextTabKeys
;
1625 nextTabKeys
.append(KStandardShortcut::tabNext().primary());
1626 nextTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::Key_Tab
));
1628 QList
<QKeySequence
> prevTabKeys
;
1629 prevTabKeys
.append(KStandardShortcut::tabPrev().primary());
1630 prevTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::SHIFT
| Qt::Key_Tab
));
1632 KAction
* activateNextTab
= actionCollection()->addAction("activate_next_tab");
1633 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1634 connect(activateNextTab
, SIGNAL(triggered()), SLOT(activateNextTab()));
1635 activateNextTab
->setShortcuts(QApplication::isRightToLeft() ? prevTabKeys
: nextTabKeys
);
1637 KAction
* activatePrevTab
= actionCollection()->addAction("activate_prev_tab");
1638 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1639 connect(activatePrevTab
, SIGNAL(triggered()), SLOT(activatePrevTab()));
1640 activatePrevTab
->setShortcuts(QApplication::isRightToLeft() ? nextTabKeys
: prevTabKeys
);
1643 KAction
* openInNewTab
= actionCollection()->addAction("open_in_new_tab");
1644 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1645 openInNewTab
->setIcon(KIcon("tab-new"));
1646 connect(openInNewTab
, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1648 KAction
* openInNewWindow
= actionCollection()->addAction("open_in_new_window");
1649 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1650 openInNewWindow
->setIcon(KIcon("window-new"));
1651 connect(openInNewWindow
, SIGNAL(triggered()), this, SLOT(openInNewWindow()));
1654 void DolphinMainWindow::setupDockWidgets()
1656 const bool lock
= GeneralSettings::lockPanels();
1658 KDualAction
* lockLayoutAction
= actionCollection()->add
<KDualAction
>("lock_panels");
1659 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
1660 lockLayoutAction
->setActiveIcon(KIcon("object-unlocked"));
1661 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
1662 lockLayoutAction
->setInactiveIcon(KIcon("object-locked"));
1663 lockLayoutAction
->setActive(lock
);
1664 connect(lockLayoutAction
, SIGNAL(triggered()), this, SLOT(togglePanelLockState()));
1666 // Setup "Information"
1667 DolphinDockWidget
* infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
1668 infoDock
->setLocked(lock
);
1669 infoDock
->setObjectName("infoDock");
1670 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1671 Panel
* infoPanel
= new InformationPanel(infoDock
);
1672 infoPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1673 connect(infoPanel
, SIGNAL(urlActivated(KUrl
)), this, SLOT(handleUrl(KUrl
)));
1674 infoDock
->setWidget(infoPanel
);
1676 QAction
* infoAction
= infoDock
->toggleViewAction();
1677 createPanelAction(KIcon("dialog-information"), Qt::Key_F11
, infoAction
, "show_information_panel");
1679 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1680 connect(this, SIGNAL(urlChanged(KUrl
)),
1681 infoPanel
, SLOT(setUrl(KUrl
)));
1682 connect(this, SIGNAL(selectionChanged(KFileItemList
)),
1683 infoPanel
, SLOT(setSelection(KFileItemList
)));
1684 connect(this, SIGNAL(requestItemInfo(KFileItem
)),
1685 infoPanel
, SLOT(requestDelayedItemInfo(KFileItem
)));
1688 DolphinDockWidget
* foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
1689 foldersDock
->setLocked(lock
);
1690 foldersDock
->setObjectName("foldersDock");
1691 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1692 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1693 foldersPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1694 foldersDock
->setWidget(foldersPanel
);
1696 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1697 createPanelAction(KIcon("folder"), Qt::Key_F7
, foldersAction
, "show_folders_panel");
1699 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1700 connect(this, SIGNAL(urlChanged(KUrl
)),
1701 foldersPanel
, SLOT(setUrl(KUrl
)));
1702 connect(foldersPanel
, SIGNAL(folderActivated(KUrl
)),
1703 this, SLOT(changeUrl(KUrl
)));
1704 connect(foldersPanel
, SIGNAL(folderMiddleClicked(KUrl
)),
1705 this, SLOT(openNewTab(KUrl
)));
1706 connect(foldersPanel
, SIGNAL(errorMessage(QString
)),
1707 this, SLOT(slotPanelErrorMessage(QString
)));
1711 DolphinDockWidget
* terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1712 terminalDock
->setLocked(lock
);
1713 terminalDock
->setObjectName("terminalDock");
1714 terminalDock
->setAllowedAreas(Qt::TopDockWidgetArea
| Qt::BottomDockWidgetArea
);
1715 Panel
* terminalPanel
= new TerminalPanel(terminalDock
);
1716 terminalPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1717 terminalDock
->setWidget(terminalPanel
);
1719 connect(terminalPanel
, SIGNAL(hideTerminalPanel()), terminalDock
, SLOT(hide()));
1720 connect(terminalPanel
, SIGNAL(changeUrl(KUrl
)), this, SLOT(slotTerminalDirectoryChanged(KUrl
)));
1721 connect(terminalDock
, SIGNAL(visibilityChanged(bool)),
1722 terminalPanel
, SLOT(dockVisibilityChanged()));
1724 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1725 createPanelAction(KIcon("utilities-terminal"), Qt::Key_F4
, terminalAction
, "show_terminal_panel");
1727 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1728 connect(this, SIGNAL(urlChanged(KUrl
)),
1729 terminalPanel
, SLOT(setUrl(KUrl
)));
1732 if (GeneralSettings::version() < 200) {
1734 foldersDock
->hide();
1736 terminalDock
->hide();
1741 DolphinDockWidget
* placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
1742 placesDock
->setLocked(lock
);
1743 placesDock
->setObjectName("placesDock");
1744 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1746 PlacesPanel
* placesPanel
= new PlacesPanel(placesDock
);
1747 placesPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1748 placesDock
->setWidget(placesPanel
);
1750 QAction
* placesAction
= placesDock
->toggleViewAction();
1751 createPanelAction(KIcon("bookmarks"), Qt::Key_F9
, placesAction
, "show_places_panel");
1753 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1754 connect(placesPanel
, SIGNAL(placeActivated(KUrl
)),
1755 this, SLOT(changeUrl(KUrl
)));
1756 connect(placesPanel
, SIGNAL(placeMiddleClicked(KUrl
)),
1757 this, SLOT(openNewTab(KUrl
)));
1758 connect(placesPanel
, SIGNAL(errorMessage(QString
)),
1759 this, SLOT(slotPanelErrorMessage(QString
)));
1760 connect(this, SIGNAL(urlChanged(KUrl
)),
1761 placesPanel
, SLOT(setUrl(KUrl
)));
1762 connect(placesDock
, SIGNAL(visibilityChanged(bool)),
1763 this, SLOT(slotPlacesPanelVisibilityChanged(bool)));
1764 connect(this, SIGNAL(settingsChanged()),
1765 placesPanel
, SLOT(readSettings()));
1767 // Add actions into the "Panels" menu
1768 KActionMenu
* panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Panels"), this);
1769 actionCollection()->addAction("panels", panelsMenu
);
1770 panelsMenu
->setDelayed(false);
1771 const KActionCollection
* ac
= actionCollection();
1772 panelsMenu
->addAction(ac
->action("show_places_panel"));
1773 panelsMenu
->addAction(ac
->action("show_information_panel"));
1774 panelsMenu
->addAction(ac
->action("show_folders_panel"));
1776 panelsMenu
->addAction(ac
->action("show_terminal_panel"));
1778 panelsMenu
->addSeparator();
1779 panelsMenu
->addAction(lockLayoutAction
);
1782 void DolphinMainWindow::updateEditActions()
1784 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1785 if (list
.isEmpty()) {
1786 stateChanged("has_no_selection");
1788 stateChanged("has_selection");
1790 KActionCollection
* col
= actionCollection();
1791 QAction
* renameAction
= col
->action("rename");
1792 QAction
* moveToTrashAction
= col
->action("move_to_trash");
1793 QAction
* deleteAction
= col
->action("delete");
1794 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
1795 QAction
* deleteWithTrashShortcut
= col
->action("delete_shortcut"); // see DolphinViewActionHandler
1797 KFileItemListProperties
capabilities(list
);
1798 const bool enableMoveToTrash
= capabilities
.isLocal() && capabilities
.supportsMoving();
1800 renameAction
->setEnabled(capabilities
.supportsMoving());
1801 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1802 deleteAction
->setEnabled(capabilities
.supportsDeleting());
1803 deleteWithTrashShortcut
->setEnabled(capabilities
.supportsDeleting() && !enableMoveToTrash
);
1804 cutAction
->setEnabled(capabilities
.supportsMoving());
1806 updatePasteAction();
1809 void DolphinMainWindow::updateViewActions()
1811 m_actionHandler
->updateViewActions();
1813 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1814 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
1816 updateSplitAction();
1818 QAction
* editableLocactionAction
= actionCollection()->action("editable_location");
1819 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
1820 editableLocactionAction
->setChecked(urlNavigator
->isUrlEditable());
1823 void DolphinMainWindow::updateGoActions()
1825 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
1826 const KUrl currentUrl
= m_activeViewContainer
->url();
1827 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
1830 void DolphinMainWindow::createControlButton()
1832 if (m_controlButton
) {
1835 Q_ASSERT(!m_controlButton
);
1837 m_controlButton
= new QToolButton(this);
1838 m_controlButton
->setIcon(KIcon("applications-system"));
1839 m_controlButton
->setText(i18nc("@action", "Control"));
1840 m_controlButton
->setPopupMode(QToolButton::InstantPopup
);
1841 m_controlButton
->setToolButtonStyle(toolBar()->toolButtonStyle());
1843 KMenu
* controlMenu
= new KMenu(m_controlButton
);
1844 connect(controlMenu
, SIGNAL(aboutToShow()), this, SLOT(updateControlMenu()));
1846 m_controlButton
->setMenu(controlMenu
);
1848 toolBar()->addWidget(m_controlButton
);
1849 connect(toolBar(), SIGNAL(iconSizeChanged(QSize
)),
1850 m_controlButton
, SLOT(setIconSize(QSize
)));
1851 connect(toolBar(), SIGNAL(toolButtonStyleChanged(Qt::ToolButtonStyle
)),
1852 m_controlButton
, SLOT(setToolButtonStyle(Qt::ToolButtonStyle
)));
1854 // The added widgets are owned by the toolbar and may get deleted when e.g. the toolbar
1855 // gets edited. In this case we must add them again. The adding is done asynchronously by
1856 // m_updateToolBarTimer.
1857 connect(m_controlButton
, SIGNAL(destroyed()), this, SLOT(slotControlButtonDeleted()));
1858 m_updateToolBarTimer
= new QTimer(this);
1859 m_updateToolBarTimer
->setInterval(500);
1860 connect(m_updateToolBarTimer
, SIGNAL(timeout()), this, SLOT(updateToolBar()));
1863 void DolphinMainWindow::deleteControlButton()
1865 delete m_controlButton
;
1866 m_controlButton
= 0;
1868 delete m_updateToolBarTimer
;
1869 m_updateToolBarTimer
= 0;
1872 bool DolphinMainWindow::addActionToMenu(QAction
* action
, KMenu
* menu
)
1877 const KToolBar
* toolBarWidget
= toolBar();
1878 foreach (const QWidget
* widget
, action
->associatedWidgets()) {
1879 if (widget
== toolBarWidget
) {
1884 menu
->addAction(action
);
1888 void DolphinMainWindow::rememberClosedTab(int index
)
1890 KMenu
* tabsMenu
= m_recentTabsMenu
->menu();
1892 const QString primaryPath
= m_viewTab
[index
].primaryView
->url().path();
1893 const QString iconName
= KMimeType::iconNameForUrl(primaryPath
);
1895 QAction
* action
= new QAction(squeezedText(primaryPath
), tabsMenu
);
1897 ClosedTab closedTab
;
1898 closedTab
.primaryUrl
= m_viewTab
[index
].primaryView
->url();
1900 if (m_viewTab
[index
].secondaryView
) {
1901 closedTab
.secondaryUrl
= m_viewTab
[index
].secondaryView
->url();
1902 closedTab
.isSplit
= true;
1904 closedTab
.isSplit
= false;
1907 action
->setData(QVariant::fromValue(closedTab
));
1908 action
->setIcon(KIcon(iconName
));
1910 // add the closed tab menu entry after the separator and
1911 // "Empty Recently Closed Tabs" entry
1912 if (tabsMenu
->actions().size() == 2) {
1913 tabsMenu
->addAction(action
);
1915 tabsMenu
->insertAction(tabsMenu
->actions().at(2), action
);
1918 // assure that only up to 8 closed tabs are shown in the menu
1919 if (tabsMenu
->actions().size() > 8) {
1920 tabsMenu
->removeAction(tabsMenu
->actions().last());
1922 actionCollection()->action("closed_tabs")->setEnabled(true);
1923 KAcceleratorManager::manage(tabsMenu
);
1926 void DolphinMainWindow::refreshViews()
1928 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
1930 // remember the current active view, as because of
1931 // the refreshing the active view might change to
1932 // the secondary view
1933 DolphinViewContainer
* activeViewContainer
= m_activeViewContainer
;
1935 const int tabCount
= m_viewTab
.count();
1936 for (int i
= 0; i
< tabCount
; ++i
) {
1937 m_viewTab
[i
].primaryView
->readSettings();
1938 if (m_viewTab
[i
].secondaryView
) {
1939 m_viewTab
[i
].secondaryView
->readSettings();
1943 setActiveViewContainer(activeViewContainer
);
1945 if (GeneralSettings::modifiedStartupSettings()) {
1946 // The startup settings have been changed by the user (see bug #254947).
1947 // Synchronize the split-view setting with the active view:
1948 const bool splitView
= GeneralSettings::splitView();
1949 const ViewTab
& activeTab
= m_viewTab
[m_tabIndex
];
1950 const bool toggle
= ( splitView
&& !activeTab
.secondaryView
)
1951 || (!splitView
&& activeTab
.secondaryView
);
1957 emit
settingsChanged();
1960 void DolphinMainWindow::clearStatusBar()
1962 m_activeViewContainer
->statusBar()->resetToDefaultText();
1965 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
1967 connect(container
, SIGNAL(showFilterBarChanged(bool)),
1968 this, SLOT(updateFilterBarAction(bool)));
1969 connect(container
, SIGNAL(writeStateChanged(bool)),
1970 this, SLOT(slotWriteStateChanged(bool)));
1972 DolphinView
* view
= container
->view();
1973 connect(view
, SIGNAL(selectionChanged(KFileItemList
)),
1974 this, SLOT(slotSelectionChanged(KFileItemList
)));
1975 connect(view
, SIGNAL(requestItemInfo(KFileItem
)),
1976 this, SLOT(slotRequestItemInfo(KFileItem
)));
1977 connect(view
, SIGNAL(activated()),
1978 this, SLOT(toggleActiveView()));
1979 connect(view
, SIGNAL(tabRequested(KUrl
)),
1980 this, SLOT(openNewTab(KUrl
)));
1981 connect(view
, SIGNAL(requestContextMenu(QPoint
,KFileItem
,KUrl
,QList
<QAction
*>)),
1982 this, SLOT(openContextMenu(QPoint
,KFileItem
,KUrl
,QList
<QAction
*>)));
1983 connect(view
, SIGNAL(directoryLoadingStarted()),
1984 this, SLOT(enableStopAction()));
1985 connect(view
, SIGNAL(directoryLoadingCompleted()),
1986 this, SLOT(disableStopAction()));
1987 connect(view
, SIGNAL(goBackRequested()),
1988 this, SLOT(goBack()));
1989 connect(view
, SIGNAL(goForwardRequested()),
1990 this, SLOT(goForward()));
1992 const KUrlNavigator
* navigator
= container
->urlNavigator();
1993 connect(navigator
, SIGNAL(urlChanged(KUrl
)),
1994 this, SLOT(changeUrl(KUrl
)));
1995 connect(navigator
, SIGNAL(historyChanged()),
1996 this, SLOT(updateHistory()));
1997 connect(navigator
, SIGNAL(editableStateChanged(bool)),
1998 this, SLOT(slotEditableStateChanged(bool)));
1999 connect(navigator
, SIGNAL(tabRequested(KUrl
)),
2000 this, SLOT(openNewTab(KUrl
)));
2003 void DolphinMainWindow::updateSplitAction()
2005 QAction
* splitAction
= actionCollection()->action("split_view");
2006 if (m_viewTab
[m_tabIndex
].secondaryView
) {
2007 if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
2008 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
2009 splitAction
->setToolTip(i18nc("@info", "Close right view"));
2010 splitAction
->setIcon(KIcon("view-right-close"));
2012 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
2013 splitAction
->setToolTip(i18nc("@info", "Close left view"));
2014 splitAction
->setIcon(KIcon("view-left-close"));
2017 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
2018 splitAction
->setToolTip(i18nc("@info", "Split view"));
2019 splitAction
->setIcon(KIcon("view-right-new"));
2023 QString
DolphinMainWindow::tabName(const KUrl
& url
) const
2026 if (url
.equals(KUrl("file:///"))) {
2029 name
= url
.fileName();
2030 if (name
.isEmpty()) {
2031 name
= url
.protocol();
2033 // Make sure that a '&' inside the directory name is displayed correctly
2034 // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
2035 name
.replace('&', "&&");
2041 bool DolphinMainWindow::isKompareInstalled() const
2043 static bool initialized
= false;
2044 static bool installed
= false;
2046 // TODO: maybe replace this approach later by using a menu
2047 // plugin like kdiff3plugin.cpp
2048 installed
= !KGlobal::dirs()->findExe("kompare").isEmpty();
2054 void DolphinMainWindow::createSecondaryView(int tabIndex
)
2056 ViewTab
& viewTab
= m_viewTab
[tabIndex
];
2058 QSplitter
* splitter
= viewTab
.splitter
;
2059 const int newWidth
= (viewTab
.primaryView
->width() - splitter
->handleWidth()) / 2;
2061 const DolphinView
* view
= viewTab
.primaryView
->view();
2062 // The final parent of the new view container will be set by adding it
2063 // to the splitter. However, we must make sure that the DolphinMainWindow
2064 // is a parent of the view container already when it is constructed
2065 // because this enables the container's KFileItemModel to assign its
2066 // dir lister to the right main window. The dir lister can then cache
2067 // authentication data.
2068 viewTab
.secondaryView
= createViewContainer(view
->url(), this);
2069 splitter
->addWidget(viewTab
.secondaryView
);
2070 splitter
->setSizes(QList
<int>() << newWidth
<< newWidth
);
2072 connectViewSignals(viewTab
.secondaryView
);
2073 viewTab
.secondaryView
->setActive(false);
2074 viewTab
.secondaryView
->resize(newWidth
, viewTab
.primaryView
->height());
2075 viewTab
.secondaryView
->show();
2078 QString
DolphinMainWindow::tabProperty(const QString
& property
, int tabIndex
) const
2080 return "Tab " + QString::number(tabIndex
) + ' ' + property
;
2083 void DolphinMainWindow::setUrlAsCaption(const KUrl
& url
)
2086 if (!url
.isLocalFile()) {
2087 caption
.append(url
.protocol() + " - ");
2088 if (url
.hasHost()) {
2089 caption
.append(url
.host() + " - ");
2093 const QString fileName
= url
.fileName().isEmpty() ? "/" : url
.fileName();
2094 caption
.append(fileName
);
2096 setCaption(caption
);
2099 QString
DolphinMainWindow::squeezedText(const QString
& text
) const
2101 const QFontMetrics fm
= fontMetrics();
2102 return fm
.elidedText(text
, Qt::ElideMiddle
, fm
.maxWidth() * 10);
2105 void DolphinMainWindow::createPanelAction(const KIcon
& icon
,
2106 const QKeySequence
& shortcut
,
2107 QAction
* dockAction
,
2108 const QString
& actionName
)
2110 KAction
* panelAction
= actionCollection()->addAction(actionName
);
2111 panelAction
->setCheckable(true);
2112 panelAction
->setChecked(dockAction
->isChecked());
2113 panelAction
->setText(dockAction
->text());
2114 panelAction
->setIcon(icon
);
2115 panelAction
->setShortcut(shortcut
);
2117 connect(panelAction
, SIGNAL(triggered()), dockAction
, SLOT(trigger()));
2118 connect(dockAction
, SIGNAL(toggled(bool)), panelAction
, SLOT(setChecked(bool)));
2121 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
2122 KIO::FileUndoManager::UiInterface()
2126 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2130 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
2132 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
2134 DolphinViewContainer
* container
= mainWin
->activeViewContainer();
2135 container
->showMessage(job
->errorString(), DolphinViewContainer::Error
);
2137 KIO::FileUndoManager::UiInterface::jobError(job
);
2141 #include "dolphinmainwindow.moc"