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>
54 #include <KFilePlacesModel>
59 #include <KIconLoader>
60 #include <KIO/NetAccess>
61 #include <KIO/JobUiDelegate>
62 #include <KInputDialog>
64 #include <KProtocolManager>
67 #include <KMessageBox>
68 #include <KFileItemListProperties>
69 #include <konqmimedata.h>
70 #include <KProtocolInfo>
73 #include <KStandardDirs>
74 #include <kstatusbar.h>
75 #include <KStandardAction>
77 #include <KToggleAction>
78 #include <KUrlNavigator>
80 #include <KUrlComboBox>
81 #include <KToolInvocation>
83 #include "views/dolphinplacesmodel.h"
85 #include <QDesktopWidget>
86 #include <QDBusMessage>
89 #include <QToolButton>
93 // Used for GeneralSettings::version() to determine whether
94 // an updated version of Dolphin is running.
95 const int CurrentDolphinVersion
= 200;
99 * Remembers the tab configuration if a tab has been closed.
100 * Each closed tab can be restored by the menu
101 * "Go -> Recently Closed Tabs".
109 Q_DECLARE_METATYPE(ClosedTab
)
111 DolphinMainWindow::DolphinMainWindow() :
115 m_activeViewContainer(0),
116 m_centralWidgetLayout(0),
123 m_updateToolBarTimer(0),
124 m_lastHandleUrlStatJob(0)
126 DolphinPlacesModel::setModel(new KFilePlacesModel(this));
127 connect(DolphinPlacesModel::instance(), SIGNAL(errorMessage(QString
)),
128 this, SLOT(showErrorMessage(QString
)));
130 // Workaround for a X11-issue in combination with KModifierInfo
131 // (see DolphinContextMenu::initializeModifierKeyInfo() for
132 // more information):
133 DolphinContextMenu::initializeModifierKeyInfo();
135 setObjectName("Dolphin#");
137 m_viewTab
.append(ViewTab());
138 ViewTab
& viewTab
= m_viewTab
[m_tabIndex
];
139 viewTab
.wasActive
= true; // The first opened tab is automatically active
141 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
142 undoManager
->setUiInterface(new UndoUiInterface());
144 connect(undoManager
, SIGNAL(undoAvailable(bool)),
145 this, SLOT(slotUndoAvailable(bool)));
146 connect(undoManager
, SIGNAL(undoTextChanged(QString
)),
147 this, SLOT(slotUndoTextChanged(QString
)));
148 connect(undoManager
, SIGNAL(jobRecordingStarted(CommandType
)),
149 this, SLOT(clearStatusBar()));
150 connect(undoManager
, SIGNAL(jobRecordingFinished(CommandType
)),
151 this, SLOT(showCommand(CommandType
)));
153 GeneralSettings
* generalSettings
= GeneralSettings::self();
154 const bool firstRun
= (generalSettings
->version() < 200);
156 generalSettings
->setViewPropsTimestamp(QDateTime::currentDateTime());
159 setAcceptDrops(true);
161 viewTab
.splitter
= new QSplitter(this);
162 viewTab
.splitter
->setChildrenCollapsible(false);
166 const KUrl
homeUrl(generalSettings
->homeUrl());
167 setUrlAsCaption(homeUrl
);
168 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
169 connect(m_actionHandler
, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
170 connect(m_actionHandler
, SIGNAL(createDirectory()), SLOT(createDirectory()));
172 viewTab
.primaryView
= createViewContainer(homeUrl
, viewTab
.splitter
);
174 m_activeViewContainer
= viewTab
.primaryView
;
175 connectViewSignals(m_activeViewContainer
);
176 DolphinView
* view
= m_activeViewContainer
->view();
177 m_activeViewContainer
->show();
178 m_actionHandler
->setCurrentView(view
);
180 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
181 connect(this, SIGNAL(urlChanged(KUrl
)),
182 m_remoteEncoding
, SLOT(slotAboutToOpenUrl()));
184 m_tabBar
= new KTabBar(this);
185 m_tabBar
->setMovable(true);
186 m_tabBar
->setTabsClosable(true);
187 connect(m_tabBar
, SIGNAL(currentChanged(int)),
188 this, SLOT(setActiveTab(int)));
189 connect(m_tabBar
, SIGNAL(tabCloseRequested(int)),
190 this, SLOT(closeTab(int)));
191 connect(m_tabBar
, SIGNAL(contextMenu(int,QPoint
)),
192 this, SLOT(openTabContextMenu(int,QPoint
)));
193 connect(m_tabBar
, SIGNAL(newTabRequest()),
194 this, SLOT(openNewTab()));
195 connect(m_tabBar
, SIGNAL(testCanDecode(const QDragMoveEvent
*,bool&)),
196 this, SLOT(slotTestCanDecode(const QDragMoveEvent
*,bool&)));
197 connect(m_tabBar
, SIGNAL(mouseMiddleClick(int)),
198 this, SLOT(closeTab(int)));
199 connect(m_tabBar
, SIGNAL(tabMoved(int,int)),
200 this, SLOT(slotTabMoved(int,int)));
201 connect(m_tabBar
, SIGNAL(receivedDropEvent(int,QDropEvent
*)),
202 this, SLOT(tabDropEvent(int,QDropEvent
*)));
204 m_tabBar
->blockSignals(true); // signals get unblocked after at least 2 tabs are open
206 QWidget
* centralWidget
= new QWidget(this);
207 m_centralWidgetLayout
= new QVBoxLayout(centralWidget
);
208 m_centralWidgetLayout
->setSpacing(0);
209 m_centralWidgetLayout
->setMargin(0);
210 m_centralWidgetLayout
->addWidget(m_tabBar
);
211 m_centralWidgetLayout
->addWidget(viewTab
.splitter
, 1);
213 setCentralWidget(centralWidget
);
215 emit
urlChanged(homeUrl
);
217 setupGUI(Keys
| Save
| Create
| ToolBar
);
218 stateChanged("new_file");
220 QClipboard
* clipboard
= QApplication::clipboard();
221 connect(clipboard
, SIGNAL(dataChanged()),
222 this, SLOT(updatePasteAction()));
224 if (generalSettings
->splitView()) {
231 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
232 showFilterBarAction
->setChecked(generalSettings
->filterBar());
235 menuBar()->setVisible(false);
236 // Assure a proper default size if Dolphin runs the first time
240 const bool showMenu
= !menuBar()->isHidden();
241 QAction
* showMenuBarAction
= actionCollection()->action(KStandardAction::name(KStandardAction::ShowMenubar
));
242 showMenuBarAction
->setChecked(showMenu
); // workaround for bug #171080
244 createControlButton();
248 DolphinMainWindow::~DolphinMainWindow()
252 void DolphinMainWindow::openDirectories(const QList
<KUrl
>& dirs
)
254 if (dirs
.isEmpty()) {
258 if (dirs
.count() == 1) {
259 m_activeViewContainer
->setUrl(dirs
.first());
263 const int oldOpenTabsCount
= m_viewTab
.count();
265 const bool hasSplitView
= GeneralSettings::splitView();
267 // Open each directory inside a new tab. If the "split view" option has been enabled,
268 // always show two directories within one tab.
269 QList
<KUrl
>::const_iterator it
= dirs
.begin();
270 while (it
!= dirs
.end()) {
274 if (hasSplitView
&& (it
!= dirs
.end())) {
275 const int tabIndex
= m_viewTab
.count() - 1;
276 m_viewTab
[tabIndex
].secondaryView
->setUrl(*it
);
281 // Remove the previously opened tabs
282 for (int i
= 0; i
< oldOpenTabsCount
; ++i
) {
287 void DolphinMainWindow::openFiles(const QList
<KUrl
>& files
)
289 if (files
.isEmpty()) {
293 // Get all distinct directories from 'files' and open a tab
294 // for each directory. If the "split view" option is enabled, two
295 // directories are shown inside one tab (see openDirectories()).
297 foreach (const KUrl
& url
, files
) {
298 const KUrl
dir(url
.directory());
299 if (!dirs
.contains(dir
)) {
304 openDirectories(dirs
);
306 // Select the files. Although the files can be split between several
307 // tabs, there is no need to split 'files' accordingly, as
308 // the DolphinView will just ignore invalid selections.
309 const int tabCount
= m_viewTab
.count();
310 for (int i
= 0; i
< tabCount
; ++i
) {
311 m_viewTab
[i
].primaryView
->view()->markUrlsAsSelected(files
);
312 m_viewTab
[i
].primaryView
->view()->markUrlAsCurrent(files
.at(0));
313 if (m_viewTab
[i
].secondaryView
) {
314 m_viewTab
[i
].secondaryView
->view()->markUrlsAsSelected(files
);
315 m_viewTab
[i
].secondaryView
->view()->markUrlAsCurrent(files
.at(0));
320 void DolphinMainWindow::showCommand(CommandType command
)
322 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
324 case KIO::FileUndoManager::Copy
:
325 statusBar
->setText(i18nc("@info:status", "Successfully copied."));
327 case KIO::FileUndoManager::Move
:
328 statusBar
->setText(i18nc("@info:status", "Successfully moved."));
330 case KIO::FileUndoManager::Link
:
331 statusBar
->setText(i18nc("@info:status", "Successfully linked."));
333 case KIO::FileUndoManager::Trash
:
334 statusBar
->setText(i18nc("@info:status", "Successfully moved to trash."));
336 case KIO::FileUndoManager::Rename
:
337 statusBar
->setText(i18nc("@info:status", "Successfully renamed."));
340 case KIO::FileUndoManager::Mkdir
:
341 statusBar
->setText(i18nc("@info:status", "Created folder."));
349 void DolphinMainWindow::pasteIntoFolder()
351 m_activeViewContainer
->view()->pasteIntoFolder();
354 void DolphinMainWindow::changeUrl(const KUrl
& url
)
356 if (!KProtocolManager::supportsListing(url
)) {
357 // The URL navigator only checks for validity, not
358 // if the URL can be listed. An error message is
359 // shown due to DolphinViewContainer::restoreView().
363 DolphinViewContainer
* view
= activeViewContainer();
369 setUrlAsCaption(url
);
370 if (m_viewTab
.count() > 1) {
371 m_tabBar
->setTabText(m_tabIndex
, squeezedText(tabName(m_activeViewContainer
->url())));
373 const QString iconName
= KMimeType::iconNameForUrl(url
);
374 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(iconName
));
375 emit
urlChanged(url
);
379 void DolphinMainWindow::slotTerminalDirectoryChanged(const KUrl
& url
)
381 m_activeViewContainer
->setAutoGrabFocus(false);
383 m_activeViewContainer
->setAutoGrabFocus(true);
386 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
388 KToggleAction
* editableLocationAction
=
389 static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
390 editableLocationAction
->setChecked(editable
);
393 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
397 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
398 int selectedUrlsCount
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedItemsCount();
399 if (m_viewTab
[m_tabIndex
].secondaryView
) {
400 selectedUrlsCount
+= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItemsCount();
403 QAction
* compareFilesAction
= actionCollection()->action("compare_files");
404 if (selectedUrlsCount
== 2) {
405 compareFilesAction
->setEnabled(isKompareInstalled());
407 compareFilesAction
->setEnabled(false);
410 emit
selectionChanged(selection
);
413 void DolphinMainWindow::slotRequestItemInfo(const KFileItem
& item
)
415 emit
requestItemInfo(item
);
418 void DolphinMainWindow::updateHistory()
420 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
421 const int index
= urlNavigator
->historyIndex();
423 QAction
* backAction
= actionCollection()->action("go_back");
425 backAction
->setToolTip(i18nc("@info", "Go back"));
426 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
429 QAction
* forwardAction
= actionCollection()->action("go_forward");
431 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
432 forwardAction
->setEnabled(index
> 0);
436 void DolphinMainWindow::updateFilterBarAction(bool show
)
438 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
439 showFilterBarAction
->setChecked(show
);
442 void DolphinMainWindow::openNewMainWindow()
444 KRun::run("dolphin", KUrl::List(), this);
447 void DolphinMainWindow::openNewTab()
449 const bool isUrlEditable
= m_activeViewContainer
->urlNavigator()->isUrlEditable();
451 openNewTab(m_activeViewContainer
->url());
452 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
454 // The URL navigator of the new tab should have the same editable state
455 // as the current tab
456 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
457 navigator
->setUrlEditable(isUrlEditable
);
460 // If a new tab is opened and the URL is editable, assure that
461 // the user can edit the URL without manually setting the focus
462 navigator
->setFocus();
466 void DolphinMainWindow::openNewTab(const KUrl
& url
)
468 QWidget
* focusWidget
= QApplication::focusWidget();
470 if (m_viewTab
.count() == 1) {
471 // Only one view is open currently and hence no tab is shown at
472 // all. Before creating a tab for 'url', provide a tab for the current URL.
473 const KUrl currentUrl
= m_activeViewContainer
->url();
474 m_tabBar
->addTab(KIcon(KMimeType::iconNameForUrl(currentUrl
)),
475 squeezedText(tabName(currentUrl
)));
476 m_tabBar
->blockSignals(false);
479 m_tabBar
->addTab(KIcon(KMimeType::iconNameForUrl(url
)),
480 squeezedText(tabName(url
)));
483 viewTab
.splitter
= new QSplitter(this);
484 viewTab
.splitter
->setChildrenCollapsible(false);
485 viewTab
.primaryView
= createViewContainer(url
, viewTab
.splitter
);
486 viewTab
.primaryView
->setActive(false);
487 connectViewSignals(viewTab
.primaryView
);
489 m_viewTab
.append(viewTab
);
491 actionCollection()->action("close_tab")->setEnabled(true);
493 // Provide a split view, if the startup settings are set this way
494 if (GeneralSettings::splitView()) {
495 const int newTabIndex
= m_viewTab
.count() - 1;
496 createSecondaryView(newTabIndex
);
497 m_viewTab
[newTabIndex
].secondaryView
->setActive(true);
498 m_viewTab
[newTabIndex
].isPrimaryViewActive
= false;
502 // The DolphinViewContainer grabbed the keyboard focus. As the tab is opened
503 // in background, assure that the previous focused widget gets the focus back.
504 focusWidget
->setFocus();
508 void DolphinMainWindow::openNewActivatedTab(const KUrl
& url
)
511 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
514 void DolphinMainWindow::activateNextTab()
516 if (m_viewTab
.count() >= 2) {
517 const int tabIndex
= (m_tabBar
->currentIndex() + 1) % m_tabBar
->count();
518 m_tabBar
->setCurrentIndex(tabIndex
);
522 void DolphinMainWindow::activatePrevTab()
524 if (m_viewTab
.count() >= 2) {
525 int tabIndex
= m_tabBar
->currentIndex() - 1;
526 if (tabIndex
== -1) {
527 tabIndex
= m_tabBar
->count() - 1;
529 m_tabBar
->setCurrentIndex(tabIndex
);
533 void DolphinMainWindow::openInNewTab()
535 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
536 if (list
.isEmpty()) {
537 openNewTab(m_activeViewContainer
->url());
538 } else if ((list
.count() == 1) && list
[0].isDir()) {
539 openNewTab(list
[0].url());
543 void DolphinMainWindow::openInNewWindow()
547 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
548 if (list
.isEmpty()) {
549 newWindowUrl
= m_activeViewContainer
->url();
550 } else if ((list
.count() == 1) && list
[0].isDir()) {
551 newWindowUrl
= list
[0].url();
554 if (!newWindowUrl
.isEmpty()) {
555 KRun::run("dolphin", KUrl::List() << newWindowUrl
, this);
559 void DolphinMainWindow::toggleActiveView()
561 if (!m_viewTab
[m_tabIndex
].secondaryView
) {
562 // only one view is available
566 Q_ASSERT(m_activeViewContainer
);
567 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
569 DolphinViewContainer
* left
= m_viewTab
[m_tabIndex
].primaryView
;
570 DolphinViewContainer
* right
= m_viewTab
[m_tabIndex
].secondaryView
;
571 setActiveViewContainer(m_activeViewContainer
== right
? left
: right
);
574 void DolphinMainWindow::showEvent(QShowEvent
* event
)
576 KXmlGuiWindow::showEvent(event
);
577 if (!event
->spontaneous()) {
578 m_activeViewContainer
->view()->setFocus();
582 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
584 // Find out if Dolphin is closed directly by the user or
585 // by the session manager because the session is closed
586 bool closedByUser
= true;
587 DolphinApplication
*application
= qobject_cast
<DolphinApplication
*>(qApp
);
588 if (application
&& application
->sessionSaving()) {
589 closedByUser
= false;
592 if (m_viewTab
.count() > 1 && GeneralSettings::confirmClosingMultipleTabs() && closedByUser
) {
593 // Ask the user if he really wants to quit and close all tabs.
594 // Open a confirmation dialog with 3 buttons:
595 // KDialog::Yes -> Quit
596 // KDialog::No -> Close only the current tab
597 // KDialog::Cancel -> do nothing
598 KDialog
*dialog
= new KDialog(this, Qt::Dialog
);
599 dialog
->setCaption(i18nc("@title:window", "Confirmation"));
600 dialog
->setButtons(KDialog::Yes
| KDialog::No
| KDialog::Cancel
);
601 dialog
->setModal(true);
602 dialog
->setButtonGuiItem(KDialog::Yes
, KStandardGuiItem::quit());
603 dialog
->setButtonGuiItem(KDialog::No
, KGuiItem(i18n("C&lose Current Tab"), KIcon("tab-close")));
604 dialog
->setButtonGuiItem(KDialog::Cancel
, KStandardGuiItem::cancel());
605 dialog
->setDefaultButton(KDialog::Yes
);
607 bool doNotAskAgainCheckboxResult
= false;
609 const int result
= KMessageBox::createKMessageBox(dialog
,
610 QMessageBox::Warning
,
611 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
613 i18n("Do not ask again"),
614 &doNotAskAgainCheckboxResult
,
615 KMessageBox::Notify
);
617 if (doNotAskAgainCheckboxResult
) {
618 GeneralSettings::setConfirmClosingMultipleTabs(false);
626 // Close only the current tab
634 GeneralSettings::setVersion(CurrentDolphinVersion
);
635 GeneralSettings::self()->writeConfig();
637 KXmlGuiWindow::closeEvent(event
);
640 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
642 const int tabCount
= m_viewTab
.count();
643 group
.writeEntry("Tab Count", tabCount
);
644 group
.writeEntry("Active Tab Index", m_tabBar
->currentIndex());
646 for (int i
= 0; i
< tabCount
; ++i
) {
647 const DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
648 group
.writeEntry(tabProperty("Primary URL", i
), cont
->url().url());
649 group
.writeEntry(tabProperty("Primary Editable", i
),
650 cont
->urlNavigator()->isUrlEditable());
652 cont
= m_viewTab
[i
].secondaryView
;
654 group
.writeEntry(tabProperty("Secondary URL", i
), cont
->url().url());
655 group
.writeEntry(tabProperty("Secondary Editable", i
),
656 cont
->urlNavigator()->isUrlEditable());
661 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
663 const int tabCount
= group
.readEntry("Tab Count", 1);
664 for (int i
= 0; i
< tabCount
; ++i
) {
665 DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
667 cont
->setUrl(group
.readEntry(tabProperty("Primary URL", i
)));
668 const bool editable
= group
.readEntry(tabProperty("Primary Editable", i
), false);
669 cont
->urlNavigator()->setUrlEditable(editable
);
671 cont
= m_viewTab
[i
].secondaryView
;
672 const QString secondaryUrl
= group
.readEntry(tabProperty("Secondary URL", i
));
673 if (!secondaryUrl
.isEmpty()) {
675 // a secondary view should be shown, but no one is available
676 // currently -> create a new view
678 cont
= m_viewTab
[i
].secondaryView
;
682 cont
->setUrl(secondaryUrl
);
683 const bool editable
= group
.readEntry(tabProperty("Secondary Editable", i
), false);
684 cont
->urlNavigator()->setUrlEditable(editable
);
686 // no secondary view should be shown, but the default setting shows
687 // one already -> close the view
691 // openNewTab() needs to be called only tabCount - 1 times
692 if (i
!= tabCount
- 1) {
697 const int index
= group
.readEntry("Active Tab Index", 0);
698 m_tabBar
->setCurrentIndex(index
);
701 void DolphinMainWindow::updateNewMenu()
703 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
704 m_newFileMenu
->checkUpToDate();
705 m_newFileMenu
->setPopupFiles(activeViewContainer()->url());
708 void DolphinMainWindow::createDirectory()
710 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
711 m_newFileMenu
->setPopupFiles(activeViewContainer()->url());
712 m_newFileMenu
->createDirectory();
715 void DolphinMainWindow::quit()
720 void DolphinMainWindow::showErrorMessage(const QString
& message
)
722 m_activeViewContainer
->showMessage(message
, DolphinViewContainer::Error
);
725 void DolphinMainWindow::slotUndoAvailable(bool available
)
727 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
729 undoAction
->setEnabled(available
);
733 void DolphinMainWindow::restoreClosedTab(QAction
* action
)
735 if (action
->data().toBool()) {
736 // clear all actions except the "Empty Recently Closed Tabs"
737 // action and the separator
738 QList
<QAction
*> actions
= m_recentTabsMenu
->menu()->actions();
739 const int count
= actions
.size();
740 for (int i
= 2; i
< count
; ++i
) {
741 m_recentTabsMenu
->menu()->removeAction(actions
.at(i
));
744 const ClosedTab closedTab
= action
->data().value
<ClosedTab
>();
745 openNewTab(closedTab
.primaryUrl
);
746 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
748 if (closedTab
.isSplit
) {
749 // create secondary view
751 m_viewTab
[m_tabIndex
].secondaryView
->setUrl(closedTab
.secondaryUrl
);
754 m_recentTabsMenu
->removeAction(action
);
757 if (m_recentTabsMenu
->menu()->actions().count() == 2) {
758 m_recentTabsMenu
->setEnabled(false);
762 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
764 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
766 undoAction
->setText(text
);
770 void DolphinMainWindow::undo()
773 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
774 KIO::FileUndoManager::self()->undo();
777 void DolphinMainWindow::cut()
779 m_activeViewContainer
->view()->cutSelectedItems();
782 void DolphinMainWindow::copy()
784 m_activeViewContainer
->view()->copySelectedItems();
787 void DolphinMainWindow::paste()
789 m_activeViewContainer
->view()->paste();
792 void DolphinMainWindow::find()
794 m_activeViewContainer
->setSearchModeEnabled(true);
797 void DolphinMainWindow::updatePasteAction()
799 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
800 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
801 pasteAction
->setEnabled(pasteInfo
.first
);
802 pasteAction
->setText(pasteInfo
.second
);
805 void DolphinMainWindow::selectAll()
809 // if the URL navigator is editable and focused, select the whole
810 // URL instead of all items of the view
812 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
813 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit(); // krazy:exclude=qclasses
814 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
815 lineEdit
->hasFocus();
817 lineEdit
->selectAll();
819 m_activeViewContainer
->view()->selectAll();
823 void DolphinMainWindow::invertSelection()
826 m_activeViewContainer
->view()->invertSelection();
829 void DolphinMainWindow::toggleSplitView()
831 if (!m_viewTab
[m_tabIndex
].secondaryView
) {
832 createSecondaryView(m_tabIndex
);
833 setActiveViewContainer(m_viewTab
[m_tabIndex
].secondaryView
);
834 } else if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
835 // remove secondary view
836 m_viewTab
[m_tabIndex
].secondaryView
->close();
837 m_viewTab
[m_tabIndex
].secondaryView
->deleteLater();
838 m_viewTab
[m_tabIndex
].secondaryView
= 0;
840 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
842 // The primary view is active and should be closed. Hence from a users point of view
843 // the content of the secondary view should be moved to the primary view.
844 // From an implementation point of view it is more efficient to close
845 // the primary view and exchange the internal pointers afterwards.
847 m_viewTab
[m_tabIndex
].primaryView
->close();
848 m_viewTab
[m_tabIndex
].primaryView
->deleteLater();
849 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
850 m_viewTab
[m_tabIndex
].secondaryView
= 0;
852 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
858 void DolphinMainWindow::reloadView()
861 m_activeViewContainer
->view()->reload();
864 void DolphinMainWindow::stopLoading()
866 m_activeViewContainer
->view()->stopLoading();
869 void DolphinMainWindow::enableStopAction()
871 actionCollection()->action("stop")->setEnabled(true);
874 void DolphinMainWindow::disableStopAction()
876 actionCollection()->action("stop")->setEnabled(false);
879 void DolphinMainWindow::showFilterBar()
881 m_activeViewContainer
->setFilterBarVisible(true);
884 void DolphinMainWindow::toggleEditLocation()
888 QAction
* action
= actionCollection()->action("editable_location");
889 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
890 urlNavigator
->setUrlEditable(action
->isChecked());
893 void DolphinMainWindow::replaceLocation()
895 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
896 navigator
->setUrlEditable(true);
897 navigator
->setFocus();
899 // select the whole text of the combo box editor
900 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit(); // krazy:exclude=qclasses
901 lineEdit
->selectAll();
904 void DolphinMainWindow::togglePanelLockState()
906 const bool newLockState
= !GeneralSettings::lockPanels();
907 foreach (QObject
* child
, children()) {
908 DolphinDockWidget
* dock
= qobject_cast
<DolphinDockWidget
*>(child
);
910 dock
->setLocked(newLockState
);
914 GeneralSettings::setLockPanels(newLockState
);
917 void DolphinMainWindow::slotPlacesPanelVisibilityChanged(bool visible
)
919 const int tabCount
= m_viewTab
.count();
920 for (int i
= 0; i
< tabCount
; ++i
) {
921 ViewTab
& tab
= m_viewTab
[i
];
922 Q_ASSERT(tab
.primaryView
);
923 tab
.primaryView
->urlNavigator()->setPlacesSelectorVisible(!visible
);
924 if (tab
.secondaryView
) {
925 tab
.secondaryView
->urlNavigator()->setPlacesSelectorVisible(!visible
);
930 void DolphinMainWindow::goBack()
932 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
933 urlNavigator
->goBack();
935 if (urlNavigator
->locationState().isEmpty()) {
936 // An empty location state indicates a redirection URL,
937 // which must be skipped too
938 urlNavigator
->goBack();
942 void DolphinMainWindow::goForward()
944 m_activeViewContainer
->urlNavigator()->goForward();
947 void DolphinMainWindow::goUp()
949 m_activeViewContainer
->urlNavigator()->goUp();
952 void DolphinMainWindow::goHome()
954 m_activeViewContainer
->urlNavigator()->goHome();
957 void DolphinMainWindow::goBack(Qt::MouseButtons buttons
)
959 // The default case (left button pressed) is handled in goBack().
960 if (buttons
== Qt::MidButton
) {
961 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
962 const int index
= urlNavigator
->historyIndex() + 1;
963 openNewTab(urlNavigator
->locationUrl(index
));
967 void DolphinMainWindow::goForward(Qt::MouseButtons buttons
)
969 // The default case (left button pressed) is handled in goForward().
970 if (buttons
== Qt::MidButton
) {
971 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
972 const int index
= urlNavigator
->historyIndex() - 1;
973 openNewTab(urlNavigator
->locationUrl(index
));
977 void DolphinMainWindow::goUp(Qt::MouseButtons buttons
)
979 // The default case (left button pressed) is handled in goUp().
980 if (buttons
== Qt::MidButton
) {
981 openNewTab(activeViewContainer()->url().upUrl());
985 void DolphinMainWindow::goHome(Qt::MouseButtons buttons
)
987 // The default case (left button pressed) is handled in goHome().
988 if (buttons
== Qt::MidButton
) {
989 openNewTab(GeneralSettings::self()->homeUrl());
993 void DolphinMainWindow::compareFiles()
995 // The method is only invoked if exactly 2 files have
996 // been selected. The selected files may be:
997 // - both in the primary view
998 // - both in the secondary view
999 // - one in the primary view and the other in the secondary
1001 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
1006 KFileItemList items
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedItems();
1008 switch (items
.count()) {
1010 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
);
1011 items
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItems();
1012 Q_ASSERT(items
.count() == 2);
1013 urlA
= items
[0].url();
1014 urlB
= items
[1].url();
1019 urlA
= items
[0].url();
1020 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
);
1021 items
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItems();
1022 Q_ASSERT(items
.count() == 1);
1023 urlB
= items
[0].url();
1028 urlA
= items
[0].url();
1029 urlB
= items
[1].url();
1034 // may not happen: compareFiles may only get invoked if 2
1035 // files are selected
1040 QString
command("kompare -c \"");
1041 command
.append(urlA
.pathOrUrl());
1042 command
.append("\" \"");
1043 command
.append(urlB
.pathOrUrl());
1044 command
.append('\"');
1045 KRun::runCommand(command
, "Kompare", "kompare", this);
1048 void DolphinMainWindow::toggleShowMenuBar()
1050 const bool visible
= menuBar()->isVisible();
1051 menuBar()->setVisible(!visible
);
1053 createControlButton();
1055 deleteControlButton();
1059 void DolphinMainWindow::openTerminal()
1061 QString
dir(QDir::homePath());
1063 // If the given directory is not local, it can still be the URL of an
1064 // ioslave using UDS_LOCAL_PATH which to be converted first.
1065 KUrl url
= KIO::NetAccess::mostLocalUrl(m_activeViewContainer
->url(), this);
1067 //If the URL is local after the above conversion, set the directory.
1068 if (url
.isLocalFile()) {
1069 dir
= url
.toLocalFile();
1072 KToolInvocation::invokeTerminal(QString(), dir
);
1075 void DolphinMainWindow::editSettings()
1077 if (!m_settingsDialog
) {
1078 DolphinViewContainer
* container
= activeViewContainer();
1079 container
->view()->writeSettings();
1081 const KUrl url
= container
->url();
1082 DolphinSettingsDialog
* settingsDialog
= new DolphinSettingsDialog(url
, this);
1083 connect(settingsDialog
, SIGNAL(settingsChanged()), this, SLOT(refreshViews()));
1084 settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1085 settingsDialog
->show();
1086 m_settingsDialog
= settingsDialog
;
1088 m_settingsDialog
.data()->raise();
1092 void DolphinMainWindow::setActiveTab(int index
)
1094 Q_ASSERT(index
>= 0);
1095 Q_ASSERT(index
< m_viewTab
.count());
1096 if (index
== m_tabIndex
) {
1100 // hide current tab content
1101 ViewTab
& hiddenTab
= m_viewTab
[m_tabIndex
];
1102 hiddenTab
.isPrimaryViewActive
= hiddenTab
.primaryView
->isActive();
1103 hiddenTab
.primaryView
->setActive(false);
1104 if (hiddenTab
.secondaryView
) {
1105 hiddenTab
.secondaryView
->setActive(false);
1107 QSplitter
* splitter
= m_viewTab
[m_tabIndex
].splitter
;
1109 m_centralWidgetLayout
->removeWidget(splitter
);
1111 // show active tab content
1114 ViewTab
& viewTab
= m_viewTab
[index
];
1115 m_centralWidgetLayout
->addWidget(viewTab
.splitter
, 1);
1116 viewTab
.primaryView
->show();
1117 if (viewTab
.secondaryView
) {
1118 viewTab
.secondaryView
->show();
1120 viewTab
.splitter
->show();
1122 if (!viewTab
.wasActive
) {
1123 viewTab
.wasActive
= true;
1125 // If the tab has not been activated yet the size of the KItemListView is
1126 // undefined and results in an unwanted animation. To prevent this a
1127 // reloading of the directory gets triggered.
1128 viewTab
.primaryView
->view()->reload();
1129 if (viewTab
.secondaryView
) {
1130 viewTab
.secondaryView
->view()->reload();
1134 setActiveViewContainer(viewTab
.isPrimaryViewActive
? viewTab
.primaryView
:
1135 viewTab
.secondaryView
);
1138 void DolphinMainWindow::closeTab()
1140 closeTab(m_tabBar
->currentIndex());
1143 void DolphinMainWindow::closeTab(int index
)
1145 Q_ASSERT(index
>= 0);
1146 Q_ASSERT(index
< m_viewTab
.count());
1147 if (m_viewTab
.count() == 1) {
1148 // the last tab may never get closed
1152 if (index
== m_tabIndex
) {
1153 // The tab that should be closed is the active tab. Activate the
1154 // previous tab before closing the tab.
1155 m_tabBar
->setCurrentIndex((index
> 0) ? index
- 1 : 1);
1157 rememberClosedTab(index
);
1160 m_viewTab
[index
].primaryView
->deleteLater();
1161 if (m_viewTab
[index
].secondaryView
) {
1162 m_viewTab
[index
].secondaryView
->deleteLater();
1164 m_viewTab
[index
].splitter
->deleteLater();
1165 m_viewTab
.erase(m_viewTab
.begin() + index
);
1167 m_tabBar
->blockSignals(true);
1168 m_tabBar
->removeTab(index
);
1170 if (m_tabIndex
> index
) {
1172 Q_ASSERT(m_tabIndex
>= 0);
1175 // if only one tab is left, also remove the tab entry so that
1176 // closing the last tab is not possible
1177 if (m_viewTab
.count() == 1) {
1178 m_tabBar
->removeTab(0);
1179 actionCollection()->action("close_tab")->setEnabled(false);
1181 m_tabBar
->blockSignals(false);
1185 void DolphinMainWindow::openTabContextMenu(int index
, const QPoint
& pos
)
1189 QAction
* newTabAction
= menu
.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab"));
1190 newTabAction
->setShortcut(actionCollection()->action("new_tab")->shortcut());
1192 QAction
* detachTabAction
= menu
.addAction(KIcon("tab-detach"), i18nc("@action:inmenu", "Detach Tab"));
1194 QAction
* closeOtherTabsAction
= menu
.addAction(KIcon("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs"));
1196 QAction
* closeTabAction
= menu
.addAction(KIcon("tab-close"), i18nc("@action:inmenu", "Close Tab"));
1197 closeTabAction
->setShortcut(actionCollection()->action("close_tab")->shortcut());
1198 QAction
* selectedAction
= menu
.exec(pos
);
1199 if (selectedAction
== newTabAction
) {
1200 const ViewTab
& tab
= m_viewTab
[index
];
1201 Q_ASSERT(tab
.primaryView
);
1202 const KUrl url
= tab
.secondaryView
&& tab
.secondaryView
->isActive() ?
1203 tab
.secondaryView
->url() : tab
.primaryView
->url();
1205 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
1206 } else if (selectedAction
== detachTabAction
) {
1207 const QString
separator(QLatin1Char(' '));
1208 QString command
= QLatin1String("dolphin");
1210 const ViewTab
& tab
= m_viewTab
[index
];
1211 Q_ASSERT(tab
.primaryView
);
1213 command
+= separator
+ tab
.primaryView
->url().url();
1214 if (tab
.secondaryView
) {
1215 command
+= separator
+ tab
.secondaryView
->url().url();
1216 command
+= separator
+ QLatin1String("-split");
1219 KRun::runCommand(command
, this);
1222 } else if (selectedAction
== closeOtherTabsAction
) {
1223 const int count
= m_tabBar
->count();
1224 for (int i
= 0; i
< index
; ++i
) {
1227 for (int i
= index
+ 1; i
< count
; ++i
) {
1230 } else if (selectedAction
== closeTabAction
) {
1235 void DolphinMainWindow::slotTabMoved(int from
, int to
)
1237 m_viewTab
.move(from
, to
);
1238 m_tabIndex
= m_tabBar
->currentIndex();
1241 void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent
* event
, bool& canDecode
)
1243 canDecode
= KUrl::List::canDecode(event
->mimeData());
1246 void DolphinMainWindow::handleUrl(const KUrl
& url
)
1248 delete m_lastHandleUrlStatJob
;
1249 m_lastHandleUrlStatJob
= 0;
1251 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1252 activeViewContainer()->setUrl(url
);
1253 } else if (KProtocolManager::supportsListing(url
)) {
1254 // stat the URL to see if it is a dir or not
1255 m_lastHandleUrlStatJob
= KIO::stat(url
, KIO::HideProgressInfo
);
1256 if (m_lastHandleUrlStatJob
->ui()) {
1257 m_lastHandleUrlStatJob
->ui()->setWindow(this);
1259 connect(m_lastHandleUrlStatJob
, SIGNAL(result(KJob
*)),
1260 this, SLOT(slotHandleUrlStatFinished(KJob
*)));
1263 new KRun(url
, this); // Automatically deletes itself after being finished
1267 void DolphinMainWindow::slotHandleUrlStatFinished(KJob
* job
)
1269 m_lastHandleUrlStatJob
= 0;
1270 const KIO::UDSEntry entry
= static_cast<KIO::StatJob
*>(job
)->statResult();
1271 const KUrl url
= static_cast<KIO::StatJob
*>(job
)->url();
1272 if (entry
.isDir()) {
1273 activeViewContainer()->setUrl(url
);
1275 new KRun(url
, this); // Automatically deletes itself after being finished
1279 void DolphinMainWindow::tabDropEvent(int tab
, QDropEvent
* event
)
1281 const KUrl::List urls
= KUrl::List::fromMimeData(event
->mimeData());
1282 if (!urls
.isEmpty() && tab
!= -1) {
1283 const ViewTab
& viewTab
= m_viewTab
[tab
];
1284 const DolphinView
* view
= viewTab
.isPrimaryViewActive
? viewTab
.primaryView
->view()
1285 : viewTab
.secondaryView
->view();
1286 const QString error
= DragAndDropHelper::dropUrls(view
->rootItem(), view
->url(), event
);
1287 if (!error
.isEmpty()) {
1288 activeViewContainer()->showMessage(error
, DolphinViewContainer::Error
);
1293 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1295 newFileMenu()->setEnabled(isFolderWritable
);
1298 void DolphinMainWindow::openContextMenu(const QPoint
& pos
,
1299 const KFileItem
& item
,
1301 const QList
<QAction
*>& customActions
)
1303 QWeakPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, pos
, item
, url
);
1304 contextMenu
.data()->setCustomActions(customActions
);
1305 const DolphinContextMenu::Command command
= contextMenu
.data()->open();
1308 case DolphinContextMenu::OpenParentFolderInNewWindow
: {
1309 KRun::run("dolphin", KUrl::List() << item
.url().upUrl(), this);
1313 case DolphinContextMenu::OpenParentFolderInNewTab
:
1314 openNewTab(item
.url().upUrl());
1317 case DolphinContextMenu::None
:
1322 delete contextMenu
.data();
1325 void DolphinMainWindow::updateControlMenu()
1327 KMenu
* menu
= qobject_cast
<KMenu
*>(sender());
1330 // All actions get cleared by KMenu::clear(). The sub-menus are deleted
1331 // by connecting to the aboutToHide() signal from the parent-menu.
1334 KActionCollection
* ac
= actionCollection();
1336 // Add "Edit" actions
1337 bool added
= addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Undo
)), menu
) |
1338 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Find
)), menu
) |
1339 addActionToMenu(ac
->action("select_all"), menu
) |
1340 addActionToMenu(ac
->action("invert_selection"), menu
);
1343 menu
->addSeparator();
1346 // Add "View" actions
1347 if (!GeneralSettings::showZoomSlider()) {
1348 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomIn
)), menu
);
1349 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomOut
)), menu
);
1350 menu
->addSeparator();
1353 added
= addActionToMenu(ac
->action("view_mode"), menu
) |
1354 addActionToMenu(ac
->action("sort"), menu
) |
1355 addActionToMenu(ac
->action("additional_info"), menu
) |
1356 addActionToMenu(ac
->action("show_preview"), menu
) |
1357 addActionToMenu(ac
->action("show_in_groups"), menu
) |
1358 addActionToMenu(ac
->action("show_hidden_files"), menu
);
1361 menu
->addSeparator();
1364 added
= addActionToMenu(ac
->action("split_view"), menu
) |
1365 addActionToMenu(ac
->action("reload"), menu
) |
1366 addActionToMenu(ac
->action("view_properties"), menu
);
1368 menu
->addSeparator();
1371 addActionToMenu(ac
->action("panels"), menu
);
1372 KMenu
* locationBarMenu
= new KMenu(i18nc("@action:inmenu", "Location Bar"), menu
);
1373 locationBarMenu
->addAction(ac
->action("editable_location"));
1374 locationBarMenu
->addAction(ac
->action("replace_location"));
1375 menu
->addMenu(locationBarMenu
);
1377 menu
->addSeparator();
1380 KMenu
* goMenu
= new KMenu(i18nc("@action:inmenu", "Go"), menu
);
1381 connect(menu
, SIGNAL(aboutToHide()), goMenu
, SLOT(deleteLater()));
1382 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Back
)));
1383 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Forward
)));
1384 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Up
)));
1385 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Home
)));
1386 goMenu
->addAction(ac
->action("closed_tabs"));
1387 menu
->addMenu(goMenu
);
1390 KMenu
* toolsMenu
= new KMenu(i18nc("@action:inmenu", "Tools"), menu
);
1391 connect(menu
, SIGNAL(aboutToHide()), toolsMenu
, SLOT(deleteLater()));
1392 toolsMenu
->addAction(ac
->action("show_filter_bar"));
1393 toolsMenu
->addAction(ac
->action("compare_files"));
1394 toolsMenu
->addAction(ac
->action("open_terminal"));
1395 toolsMenu
->addAction(ac
->action("change_remote_encoding"));
1396 menu
->addMenu(toolsMenu
);
1398 // Add "Settings" menu entries
1399 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::KeyBindings
)), menu
);
1400 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ConfigureToolbars
)), menu
);
1401 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Preferences
)), menu
);
1404 KMenu
* helpMenu
= new KMenu(i18nc("@action:inmenu", "Help"), menu
);
1405 connect(menu
, SIGNAL(aboutToHide()), helpMenu
, SLOT(deleteLater()));
1406 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::HelpContents
)));
1407 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::WhatsThis
)));
1408 helpMenu
->addSeparator();
1409 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ReportBug
)));
1410 helpMenu
->addSeparator();
1411 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
)));
1412 helpMenu
->addSeparator();
1413 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::AboutApp
)));
1414 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::AboutKDE
)));
1415 menu
->addMenu(helpMenu
);
1417 menu
->addSeparator();
1418 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ShowMenubar
)), menu
);
1421 void DolphinMainWindow::updateToolBar()
1423 if (!menuBar()->isVisible()) {
1424 createControlButton();
1428 void DolphinMainWindow::slotControlButtonDeleted()
1430 m_controlButton
= 0;
1431 m_updateToolBarTimer
->start();
1434 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer
* viewContainer
)
1436 Q_ASSERT(viewContainer
);
1437 Q_ASSERT((viewContainer
== m_viewTab
[m_tabIndex
].primaryView
) ||
1438 (viewContainer
== m_viewTab
[m_tabIndex
].secondaryView
));
1439 if (m_activeViewContainer
== viewContainer
) {
1443 m_activeViewContainer
->setActive(false);
1444 m_activeViewContainer
= viewContainer
;
1446 // Activating the view container might trigger a recursive setActiveViewContainer() call
1447 // inside DolphinMainWindow::toggleActiveView() when having a split view. Temporary
1448 // disconnect the activated() signal in this case:
1449 disconnect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1450 m_activeViewContainer
->setActive(true);
1451 connect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1453 m_actionHandler
->setCurrentView(viewContainer
->view());
1456 updateEditActions();
1457 updateViewActions();
1460 const KUrl url
= m_activeViewContainer
->url();
1461 setUrlAsCaption(url
);
1462 if (m_viewTab
.count() > 1) {
1463 m_tabBar
->setTabText(m_tabIndex
, tabName(url
));
1464 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(KMimeType::iconNameForUrl(url
)));
1467 emit
urlChanged(url
);
1470 DolphinViewContainer
* DolphinMainWindow::createViewContainer(const KUrl
& url
, QWidget
* parent
)
1472 DolphinViewContainer
* container
= new DolphinViewContainer(url
, parent
);
1474 // The places-selector from the URL navigator should only be shown
1475 // if the places dock is invisible
1476 QDockWidget
* placesDock
= findChild
<QDockWidget
*>("placesDock");
1477 container
->urlNavigator()->setPlacesSelectorVisible(!placesDock
|| !placesDock
->isVisible());
1482 void DolphinMainWindow::setupActions()
1484 // setup 'File' menu
1485 m_newFileMenu
= new DolphinNewFileMenu(this);
1486 KMenu
* menu
= m_newFileMenu
->menu();
1487 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1488 menu
->setIcon(KIcon("document-new"));
1489 connect(menu
, SIGNAL(aboutToShow()),
1490 this, SLOT(updateNewMenu()));
1492 KAction
* newWindow
= actionCollection()->addAction("new_window");
1493 newWindow
->setIcon(KIcon("window-new"));
1494 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1495 newWindow
->setShortcut(Qt::CTRL
| Qt::Key_N
);
1496 connect(newWindow
, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1498 KAction
* newTab
= actionCollection()->addAction("new_tab");
1499 newTab
->setIcon(KIcon("tab-new"));
1500 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1501 newTab
->setShortcut(KShortcut(Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
));
1502 connect(newTab
, SIGNAL(triggered()), this, SLOT(openNewTab()));
1504 KAction
* closeTab
= actionCollection()->addAction("close_tab");
1505 closeTab
->setIcon(KIcon("tab-close"));
1506 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1507 closeTab
->setShortcut(Qt::CTRL
| Qt::Key_W
);
1508 closeTab
->setEnabled(false);
1509 connect(closeTab
, SIGNAL(triggered()), this, SLOT(closeTab()));
1511 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1513 // setup 'Edit' menu
1514 KStandardAction::undo(this,
1516 actionCollection());
1518 // need to remove shift+del from cut action, else the shortcut for deletejob
1520 KAction
* cut
= KStandardAction::cut(this, SLOT(cut()), actionCollection());
1521 KShortcut cutShortcut
= cut
->shortcut();
1522 cutShortcut
.remove(Qt::SHIFT
| Qt::Key_Delete
, KShortcut::KeepEmpty
);
1523 cut
->setShortcut(cutShortcut
);
1524 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1525 KAction
* paste
= KStandardAction::paste(this, SLOT(paste()), actionCollection());
1526 // The text of the paste-action is modified dynamically by Dolphin
1527 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1528 // due to the long text, the text "Paste" is used:
1529 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1531 KStandardAction::find(this, SLOT(find()), actionCollection());
1533 KAction
* selectAll
= actionCollection()->addAction("select_all");
1534 selectAll
->setText(i18nc("@action:inmenu Edit", "Select All"));
1535 selectAll
->setShortcut(Qt::CTRL
| Qt::Key_A
);
1536 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
1538 KAction
* invertSelection
= actionCollection()->addAction("invert_selection");
1539 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1540 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1541 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
1543 // setup 'View' menu
1544 // (note that most of it is set up in DolphinViewActionHandler)
1546 KAction
* split
= actionCollection()->addAction("split_view");
1547 split
->setShortcut(Qt::Key_F3
);
1548 updateSplitAction();
1549 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1551 KAction
* reload
= actionCollection()->addAction("reload");
1552 reload
->setText(i18nc("@action:inmenu View", "Reload"));
1553 reload
->setShortcut(Qt::Key_F5
);
1554 reload
->setIcon(KIcon("view-refresh"));
1555 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
1557 KAction
* stop
= actionCollection()->addAction("stop");
1558 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1559 stop
->setToolTip(i18nc("@info", "Stop loading"));
1560 stop
->setIcon(KIcon("process-stop"));
1561 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
1563 KToggleAction
* editableLocation
= actionCollection()->add
<KToggleAction
>("editable_location");
1564 editableLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1565 editableLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
1566 connect(editableLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1568 KAction
* replaceLocation
= actionCollection()->addAction("replace_location");
1569 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1570 replaceLocation
->setShortcut(Qt::Key_F6
);
1571 connect(replaceLocation
, SIGNAL(triggered()), this, SLOT(replaceLocation()));
1574 KAction
* backAction
= KStandardAction::back(this, SLOT(goBack()), actionCollection());
1575 connect(backAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goBack(Qt::MouseButtons
)));
1576 KShortcut backShortcut
= backAction
->shortcut();
1577 backShortcut
.setAlternate(Qt::Key_Backspace
);
1578 backAction
->setShortcut(backShortcut
);
1580 m_recentTabsMenu
= new KActionMenu(i18n("Recently Closed Tabs"), this);
1581 m_recentTabsMenu
->setIcon(KIcon("edit-undo"));
1582 actionCollection()->addAction("closed_tabs", m_recentTabsMenu
);
1583 connect(m_recentTabsMenu
->menu(), SIGNAL(triggered(QAction
*)),
1584 this, SLOT(restoreClosedTab(QAction
*)));
1586 QAction
* action
= new QAction(i18n("Empty Recently Closed Tabs"), m_recentTabsMenu
);
1587 action
->setIcon(KIcon("edit-clear-list"));
1588 action
->setData(QVariant::fromValue(true));
1589 m_recentTabsMenu
->addAction(action
);
1590 m_recentTabsMenu
->addSeparator();
1591 m_recentTabsMenu
->setEnabled(false);
1593 KAction
* forwardAction
= KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1594 connect(forwardAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goForward(Qt::MouseButtons
)));
1596 KAction
* upAction
= KStandardAction::up(this, SLOT(goUp()), actionCollection());
1597 connect(upAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goUp(Qt::MouseButtons
)));
1599 KAction
* homeAction
= KStandardAction::home(this, SLOT(goHome()), actionCollection());
1600 connect(homeAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goHome(Qt::MouseButtons
)));
1602 // setup 'Tools' menu
1603 KAction
* showFilterBar
= actionCollection()->addAction("show_filter_bar");
1604 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1605 showFilterBar
->setIcon(KIcon("view-filter"));
1606 showFilterBar
->setShortcut(Qt::CTRL
| Qt::Key_I
);
1607 connect(showFilterBar
, SIGNAL(triggered()), this, SLOT(showFilterBar()));
1609 KAction
* compareFiles
= actionCollection()->addAction("compare_files");
1610 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1611 compareFiles
->setIcon(KIcon("kompare"));
1612 compareFiles
->setEnabled(false);
1613 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
1615 KAction
* openTerminal
= actionCollection()->addAction("open_terminal");
1616 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1617 openTerminal
->setIcon(KIcon("utilities-terminal"));
1618 openTerminal
->setShortcut(Qt::SHIFT
| Qt::Key_F4
);
1619 connect(openTerminal
, SIGNAL(triggered()), this, SLOT(openTerminal()));
1621 // setup 'Settings' menu
1622 KToggleAction
* showMenuBar
= KStandardAction::showMenubar(0, 0, actionCollection());
1623 connect(showMenuBar
, SIGNAL(triggered(bool)), // Fixes #286822
1624 this, SLOT(toggleShowMenuBar()), Qt::QueuedConnection
);
1625 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1627 // not in menu actions
1628 QList
<QKeySequence
> nextTabKeys
;
1629 nextTabKeys
.append(KStandardShortcut::tabNext().primary());
1630 nextTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::Key_Tab
));
1632 QList
<QKeySequence
> prevTabKeys
;
1633 prevTabKeys
.append(KStandardShortcut::tabPrev().primary());
1634 prevTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::SHIFT
| Qt::Key_Tab
));
1636 KAction
* activateNextTab
= actionCollection()->addAction("activate_next_tab");
1637 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1638 connect(activateNextTab
, SIGNAL(triggered()), SLOT(activateNextTab()));
1639 activateNextTab
->setShortcuts(QApplication::isRightToLeft() ? prevTabKeys
: nextTabKeys
);
1641 KAction
* activatePrevTab
= actionCollection()->addAction("activate_prev_tab");
1642 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1643 connect(activatePrevTab
, SIGNAL(triggered()), SLOT(activatePrevTab()));
1644 activatePrevTab
->setShortcuts(QApplication::isRightToLeft() ? nextTabKeys
: prevTabKeys
);
1647 KAction
* openInNewTab
= actionCollection()->addAction("open_in_new_tab");
1648 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1649 openInNewTab
->setIcon(KIcon("tab-new"));
1650 connect(openInNewTab
, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1652 KAction
* openInNewWindow
= actionCollection()->addAction("open_in_new_window");
1653 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1654 openInNewWindow
->setIcon(KIcon("window-new"));
1655 connect(openInNewWindow
, SIGNAL(triggered()), this, SLOT(openInNewWindow()));
1658 void DolphinMainWindow::setupDockWidgets()
1660 const bool lock
= GeneralSettings::lockPanels();
1662 KDualAction
* lockLayoutAction
= actionCollection()->add
<KDualAction
>("lock_panels");
1663 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
1664 lockLayoutAction
->setActiveIcon(KIcon("object-unlocked"));
1665 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
1666 lockLayoutAction
->setInactiveIcon(KIcon("object-locked"));
1667 lockLayoutAction
->setActive(lock
);
1668 connect(lockLayoutAction
, SIGNAL(triggered()), this, SLOT(togglePanelLockState()));
1670 // Setup "Information"
1671 DolphinDockWidget
* infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
1672 infoDock
->setLocked(lock
);
1673 infoDock
->setObjectName("infoDock");
1674 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1675 Panel
* infoPanel
= new InformationPanel(infoDock
);
1676 infoPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1677 connect(infoPanel
, SIGNAL(urlActivated(KUrl
)), this, SLOT(handleUrl(KUrl
)));
1678 infoDock
->setWidget(infoPanel
);
1680 QAction
* infoAction
= infoDock
->toggleViewAction();
1681 createPanelAction(KIcon("dialog-information"), Qt::Key_F11
, infoAction
, "show_information_panel");
1683 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1684 connect(this, SIGNAL(urlChanged(KUrl
)),
1685 infoPanel
, SLOT(setUrl(KUrl
)));
1686 connect(this, SIGNAL(selectionChanged(KFileItemList
)),
1687 infoPanel
, SLOT(setSelection(KFileItemList
)));
1688 connect(this, SIGNAL(requestItemInfo(KFileItem
)),
1689 infoPanel
, SLOT(requestDelayedItemInfo(KFileItem
)));
1692 DolphinDockWidget
* foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
1693 foldersDock
->setLocked(lock
);
1694 foldersDock
->setObjectName("foldersDock");
1695 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1696 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1697 foldersPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1698 foldersDock
->setWidget(foldersPanel
);
1700 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1701 createPanelAction(KIcon("folder"), Qt::Key_F7
, foldersAction
, "show_folders_panel");
1703 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1704 connect(this, SIGNAL(urlChanged(KUrl
)),
1705 foldersPanel
, SLOT(setUrl(KUrl
)));
1706 connect(foldersPanel
, SIGNAL(folderActivated(KUrl
)),
1707 this, SLOT(changeUrl(KUrl
)));
1708 connect(foldersPanel
, SIGNAL(folderMiddleClicked(KUrl
)),
1709 this, SLOT(openNewActivatedTab(KUrl
)));
1713 DolphinDockWidget
* terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1714 terminalDock
->setLocked(lock
);
1715 terminalDock
->setObjectName("terminalDock");
1716 terminalDock
->setAllowedAreas(Qt::TopDockWidgetArea
| Qt::BottomDockWidgetArea
);
1717 Panel
* terminalPanel
= new TerminalPanel(terminalDock
);
1718 terminalPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1719 terminalDock
->setWidget(terminalPanel
);
1721 connect(terminalPanel
, SIGNAL(hideTerminalPanel()), terminalDock
, SLOT(hide()));
1722 connect(terminalPanel
, SIGNAL(changeUrl(KUrl
)), this, SLOT(slotTerminalDirectoryChanged(KUrl
)));
1723 connect(terminalDock
, SIGNAL(visibilityChanged(bool)),
1724 terminalPanel
, SLOT(dockVisibilityChanged()));
1726 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1727 createPanelAction(KIcon("utilities-terminal"), Qt::Key_F4
, terminalAction
, "show_terminal_panel");
1729 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1730 connect(this, SIGNAL(urlChanged(KUrl
)),
1731 terminalPanel
, SLOT(setUrl(KUrl
)));
1734 if (GeneralSettings::version() < 200) {
1736 foldersDock
->hide();
1738 terminalDock
->hide();
1743 DolphinDockWidget
* placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
1744 placesDock
->setLocked(lock
);
1745 placesDock
->setObjectName("placesDock");
1746 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1748 PlacesPanel
* placesPanel
= new PlacesPanel(placesDock
);
1749 placesPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1750 placesDock
->setWidget(placesPanel
);
1752 QAction
* placesAction
= placesDock
->toggleViewAction();
1753 createPanelAction(KIcon("bookmarks"), Qt::Key_F9
, placesAction
, "show_places_panel");
1755 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1756 connect(placesPanel
, SIGNAL(placeActivated(KUrl
)),
1757 this, SLOT(changeUrl(KUrl
)));
1758 connect(placesPanel
, SIGNAL(placeMiddleClicked(KUrl
)),
1759 this, SLOT(openNewActivatedTab(KUrl
)));
1760 connect(this, SIGNAL(urlChanged(KUrl
)),
1761 placesPanel
, SLOT(setUrl(KUrl
)));
1762 connect(placesDock
, SIGNAL(visibilityChanged(bool)),
1763 this, SLOT(slotPlacesPanelVisibilityChanged(bool)));
1765 // Add actions into the "Panels" menu
1766 KActionMenu
* panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Panels"), this);
1767 actionCollection()->addAction("panels", panelsMenu
);
1768 panelsMenu
->setDelayed(false);
1769 const KActionCollection
* ac
= actionCollection();
1770 panelsMenu
->addAction(ac
->action("show_places_panel"));
1771 panelsMenu
->addAction(ac
->action("show_information_panel"));
1772 panelsMenu
->addAction(ac
->action("show_folders_panel"));
1774 panelsMenu
->addAction(ac
->action("show_terminal_panel"));
1776 panelsMenu
->addSeparator();
1777 panelsMenu
->addAction(lockLayoutAction
);
1780 void DolphinMainWindow::updateEditActions()
1782 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1783 if (list
.isEmpty()) {
1784 stateChanged("has_no_selection");
1786 stateChanged("has_selection");
1788 KActionCollection
* col
= actionCollection();
1789 QAction
* renameAction
= col
->action("rename");
1790 QAction
* moveToTrashAction
= col
->action("move_to_trash");
1791 QAction
* deleteAction
= col
->action("delete");
1792 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
1793 QAction
* deleteWithTrashShortcut
= col
->action("delete_shortcut"); // see DolphinViewActionHandler
1795 KFileItemListProperties
capabilities(list
);
1796 const bool enableMoveToTrash
= capabilities
.isLocal() && capabilities
.supportsMoving();
1798 renameAction
->setEnabled(capabilities
.supportsMoving());
1799 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1800 deleteAction
->setEnabled(capabilities
.supportsDeleting());
1801 deleteWithTrashShortcut
->setEnabled(capabilities
.supportsDeleting() && !enableMoveToTrash
);
1802 cutAction
->setEnabled(capabilities
.supportsMoving());
1804 updatePasteAction();
1807 void DolphinMainWindow::updateViewActions()
1809 m_actionHandler
->updateViewActions();
1811 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1812 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
1814 updateSplitAction();
1816 QAction
* editableLocactionAction
= actionCollection()->action("editable_location");
1817 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
1818 editableLocactionAction
->setChecked(urlNavigator
->isUrlEditable());
1821 void DolphinMainWindow::updateGoActions()
1823 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
1824 const KUrl currentUrl
= m_activeViewContainer
->url();
1825 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
1828 void DolphinMainWindow::createControlButton()
1830 if (m_controlButton
) {
1833 Q_ASSERT(!m_controlButton
);
1835 m_controlButton
= new QToolButton(this);
1836 m_controlButton
->setIcon(KIcon("applications-system"));
1837 m_controlButton
->setText(i18nc("@action", "Control"));
1838 m_controlButton
->setPopupMode(QToolButton::InstantPopup
);
1839 m_controlButton
->setToolButtonStyle(toolBar()->toolButtonStyle());
1841 KMenu
* controlMenu
= new KMenu(m_controlButton
);
1842 connect(controlMenu
, SIGNAL(aboutToShow()), this, SLOT(updateControlMenu()));
1844 m_controlButton
->setMenu(controlMenu
);
1846 toolBar()->addWidget(m_controlButton
);
1847 connect(toolBar(), SIGNAL(iconSizeChanged(QSize
)),
1848 m_controlButton
, SLOT(setIconSize(QSize
)));
1849 connect(toolBar(), SIGNAL(toolButtonStyleChanged(Qt::ToolButtonStyle
)),
1850 m_controlButton
, SLOT(setToolButtonStyle(Qt::ToolButtonStyle
)));
1852 // The added widgets are owned by the toolbar and may get deleted when e.g. the toolbar
1853 // gets edited. In this case we must add them again. The adding is done asynchronously by
1854 // m_updateToolBarTimer.
1855 connect(m_controlButton
, SIGNAL(destroyed()), this, SLOT(slotControlButtonDeleted()));
1856 m_updateToolBarTimer
= new QTimer(this);
1857 m_updateToolBarTimer
->setInterval(500);
1858 connect(m_updateToolBarTimer
, SIGNAL(timeout()), this, SLOT(updateToolBar()));
1861 void DolphinMainWindow::deleteControlButton()
1863 delete m_controlButton
;
1864 m_controlButton
= 0;
1866 delete m_updateToolBarTimer
;
1867 m_updateToolBarTimer
= 0;
1870 bool DolphinMainWindow::addActionToMenu(QAction
* action
, KMenu
* menu
)
1875 const KToolBar
* toolBarWidget
= toolBar();
1876 foreach (const QWidget
* widget
, action
->associatedWidgets()) {
1877 if (widget
== toolBarWidget
) {
1882 menu
->addAction(action
);
1886 void DolphinMainWindow::rememberClosedTab(int index
)
1888 KMenu
* tabsMenu
= m_recentTabsMenu
->menu();
1890 const QString primaryPath
= m_viewTab
[index
].primaryView
->url().path();
1891 const QString iconName
= KMimeType::iconNameForUrl(primaryPath
);
1893 QAction
* action
= new QAction(squeezedText(primaryPath
), tabsMenu
);
1895 ClosedTab closedTab
;
1896 closedTab
.primaryUrl
= m_viewTab
[index
].primaryView
->url();
1898 if (m_viewTab
[index
].secondaryView
) {
1899 closedTab
.secondaryUrl
= m_viewTab
[index
].secondaryView
->url();
1900 closedTab
.isSplit
= true;
1902 closedTab
.isSplit
= false;
1905 action
->setData(QVariant::fromValue(closedTab
));
1906 action
->setIcon(KIcon(iconName
));
1908 // add the closed tab menu entry after the separator and
1909 // "Empty Recently Closed Tabs" entry
1910 if (tabsMenu
->actions().size() == 2) {
1911 tabsMenu
->addAction(action
);
1913 tabsMenu
->insertAction(tabsMenu
->actions().at(2), action
);
1916 // assure that only up to 8 closed tabs are shown in the menu
1917 if (tabsMenu
->actions().size() > 8) {
1918 tabsMenu
->removeAction(tabsMenu
->actions().last());
1920 actionCollection()->action("closed_tabs")->setEnabled(true);
1921 KAcceleratorManager::manage(tabsMenu
);
1924 void DolphinMainWindow::refreshViews()
1926 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
1928 // remember the current active view, as because of
1929 // the refreshing the active view might change to
1930 // the secondary view
1931 DolphinViewContainer
* activeViewContainer
= m_activeViewContainer
;
1933 const int tabCount
= m_viewTab
.count();
1934 for (int i
= 0; i
< tabCount
; ++i
) {
1935 m_viewTab
[i
].primaryView
->readSettings();
1936 if (m_viewTab
[i
].secondaryView
) {
1937 m_viewTab
[i
].secondaryView
->readSettings();
1941 setActiveViewContainer(activeViewContainer
);
1943 if (GeneralSettings::modifiedStartupSettings()) {
1944 // The startup settings have been changed by the user (see bug #254947).
1945 // Synchronize the split-view setting with the active view:
1946 const bool splitView
= GeneralSettings::splitView();
1947 const ViewTab
& activeTab
= m_viewTab
[m_tabIndex
];
1948 const bool toggle
= ( splitView
&& !activeTab
.secondaryView
)
1949 || (!splitView
&& activeTab
.secondaryView
);
1956 void DolphinMainWindow::clearStatusBar()
1958 m_activeViewContainer
->statusBar()->resetToDefaultText();
1961 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
1963 connect(container
, SIGNAL(showFilterBarChanged(bool)),
1964 this, SLOT(updateFilterBarAction(bool)));
1965 connect(container
, SIGNAL(writeStateChanged(bool)),
1966 this, SLOT(slotWriteStateChanged(bool)));
1968 DolphinView
* view
= container
->view();
1969 connect(view
, SIGNAL(selectionChanged(KFileItemList
)),
1970 this, SLOT(slotSelectionChanged(KFileItemList
)));
1971 connect(view
, SIGNAL(requestItemInfo(KFileItem
)),
1972 this, SLOT(slotRequestItemInfo(KFileItem
)));
1973 connect(view
, SIGNAL(activated()),
1974 this, SLOT(toggleActiveView()));
1975 connect(view
, SIGNAL(tabRequested(KUrl
)),
1976 this, SLOT(openNewTab(KUrl
)));
1977 connect(view
, SIGNAL(requestContextMenu(QPoint
,KFileItem
,KUrl
,QList
<QAction
*>)),
1978 this, SLOT(openContextMenu(QPoint
,KFileItem
,KUrl
,QList
<QAction
*>)));
1979 connect(view
, SIGNAL(directoryLoadingStarted()),
1980 this, SLOT(enableStopAction()));
1981 connect(view
, SIGNAL(directoryLoadingCompleted()),
1982 this, SLOT(disableStopAction()));
1983 connect(view
, SIGNAL(goBackRequested()),
1984 this, SLOT(goBack()));
1985 connect(view
, SIGNAL(goForwardRequested()),
1986 this, SLOT(goForward()));
1988 const KUrlNavigator
* navigator
= container
->urlNavigator();
1989 connect(navigator
, SIGNAL(urlChanged(KUrl
)),
1990 this, SLOT(changeUrl(KUrl
)));
1991 connect(navigator
, SIGNAL(historyChanged()),
1992 this, SLOT(updateHistory()));
1993 connect(navigator
, SIGNAL(editableStateChanged(bool)),
1994 this, SLOT(slotEditableStateChanged(bool)));
1995 connect(navigator
, SIGNAL(tabRequested(KUrl
)),
1996 this, SLOT(openNewTab(KUrl
)));
1999 void DolphinMainWindow::updateSplitAction()
2001 QAction
* splitAction
= actionCollection()->action("split_view");
2002 if (m_viewTab
[m_tabIndex
].secondaryView
) {
2003 if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
2004 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
2005 splitAction
->setToolTip(i18nc("@info", "Close right view"));
2006 splitAction
->setIcon(KIcon("view-right-close"));
2008 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
2009 splitAction
->setToolTip(i18nc("@info", "Close left view"));
2010 splitAction
->setIcon(KIcon("view-left-close"));
2013 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
2014 splitAction
->setToolTip(i18nc("@info", "Split view"));
2015 splitAction
->setIcon(KIcon("view-right-new"));
2019 QString
DolphinMainWindow::tabName(const KUrl
& url
) const
2022 if (url
.equals(KUrl("file:///"))) {
2025 name
= url
.fileName();
2026 if (name
.isEmpty()) {
2027 name
= url
.protocol();
2029 // Make sure that a '&' inside the directory name is displayed correctly
2030 // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
2031 name
.replace('&', "&&");
2037 bool DolphinMainWindow::isKompareInstalled() const
2039 static bool initialized
= false;
2040 static bool installed
= false;
2042 // TODO: maybe replace this approach later by using a menu
2043 // plugin like kdiff3plugin.cpp
2044 installed
= !KGlobal::dirs()->findExe("kompare").isEmpty();
2050 void DolphinMainWindow::createSecondaryView(int tabIndex
)
2052 ViewTab
& viewTab
= m_viewTab
[tabIndex
];
2054 QSplitter
* splitter
= viewTab
.splitter
;
2055 const int newWidth
= (viewTab
.primaryView
->width() - splitter
->handleWidth()) / 2;
2057 const DolphinView
* view
= viewTab
.primaryView
->view();
2058 viewTab
.secondaryView
= createViewContainer(view
->url(), 0);
2059 splitter
->addWidget(viewTab
.secondaryView
);
2060 splitter
->setSizes(QList
<int>() << newWidth
<< newWidth
);
2062 connectViewSignals(viewTab
.secondaryView
);
2063 viewTab
.secondaryView
->setActive(false);
2064 viewTab
.secondaryView
->resize(newWidth
, viewTab
.primaryView
->height());
2065 viewTab
.secondaryView
->show();
2068 QString
DolphinMainWindow::tabProperty(const QString
& property
, int tabIndex
) const
2070 return "Tab " + QString::number(tabIndex
) + ' ' + property
;
2073 void DolphinMainWindow::setUrlAsCaption(const KUrl
& url
)
2076 if (!url
.isLocalFile()) {
2077 caption
.append(url
.protocol() + " - ");
2078 if (url
.hasHost()) {
2079 caption
.append(url
.host() + " - ");
2083 const QString fileName
= url
.fileName().isEmpty() ? "/" : url
.fileName();
2084 caption
.append(fileName
);
2086 setCaption(caption
);
2089 QString
DolphinMainWindow::squeezedText(const QString
& text
) const
2091 const QFontMetrics fm
= fontMetrics();
2092 return fm
.elidedText(text
, Qt::ElideMiddle
, fm
.maxWidth() * 10);
2095 void DolphinMainWindow::createPanelAction(const KIcon
& icon
,
2096 const QKeySequence
& shortcut
,
2097 QAction
* dockAction
,
2098 const QString
& actionName
)
2100 KAction
* panelAction
= actionCollection()->addAction(actionName
);
2101 panelAction
->setCheckable(true);
2102 panelAction
->setChecked(dockAction
->isChecked());
2103 panelAction
->setText(dockAction
->text());
2104 panelAction
->setIcon(icon
);
2105 panelAction
->setShortcut(shortcut
);
2107 connect(panelAction
, SIGNAL(triggered()), dockAction
, SLOT(trigger()));
2108 connect(dockAction
, SIGNAL(toggled(bool)), panelAction
, SLOT(setChecked(bool)));
2111 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
2112 KIO::FileUndoManager::UiInterface()
2116 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2120 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
2122 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
2124 DolphinViewContainer
* container
= mainWin
->activeViewContainer();
2125 container
->showMessage(job
->errorString(), DolphinViewContainer::Error
);
2127 KIO::FileUndoManager::UiInterface::jobError(job
);
2131 #include "dolphinmainwindow.moc"