1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz19@gmail.com> *
3 * Copyright (C) 2006 by Stefan Monov <logixoul@gmail.com> *
4 * Copyright (C) 2006 by Cvetoslav Ludmiloff <ludmiloff@gmail.com> *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20 ***************************************************************************/
22 #include "dolphinmainwindow.h"
24 #include "dolphinapplication.h"
25 #include "dolphindockwidget.h"
26 #include "dolphincontextmenu.h"
27 #include "dolphinnewfilemenu.h"
28 #include "dolphinrecenttabsmenu.h"
29 #include "dolphinviewcontainer.h"
30 #include "panels/folders/folderspanel.h"
31 #include "panels/places/placespanel.h"
32 #include "panels/information/informationpanel.h"
33 #include "settings/dolphinsettingsdialog.h"
34 #include "statusbar/dolphinstatusbar.h"
35 #include "views/dolphinviewactionhandler.h"
36 #include "views/dolphinremoteencoding.h"
37 #include "views/draganddrophelper.h"
38 #include "views/viewproperties.h"
39 #include "views/dolphinnewfilemenuobserver.h"
42 #include "panels/terminal/terminalpanel.h"
45 #include "dolphin_generalsettings.h"
47 #include <KAcceleratorManager>
49 #include <KActionCollection>
50 #include <KActionMenu>
52 #include <KDesktopFile>
53 #include <kdeversion.h>
54 #include <kdualaction.h>
55 #include <KFileDialog>
60 #include <KIconLoader>
61 #include <KIO/NetAccess>
62 #include <KIO/JobUiDelegate>
63 #include <KInputDialog>
65 #include <KProtocolManager>
68 #include <KMessageBox>
69 #include <KFileItemListProperties>
70 #include <konqmimedata.h>
71 #include <KProtocolInfo>
74 #include <KStandardDirs>
75 #include <kstatusbar.h>
76 #include <KStandardAction>
78 #include <KToggleAction>
79 #include <KUrlNavigator>
81 #include <KUrlComboBox>
82 #include <KToolInvocation>
84 #include <QDesktopWidget>
85 #include <QDBusMessage>
88 #include <QToolButton>
92 // Used for GeneralSettings::version() to determine whether
93 // an updated version of Dolphin is running.
94 const int CurrentDolphinVersion
= 200;
97 DolphinMainWindow::DolphinMainWindow() :
101 m_activeViewContainer(0),
102 m_centralWidgetLayout(0),
109 m_updateToolBarTimer(0),
110 m_lastHandleUrlStatJob(0)
112 setObjectName("Dolphin#");
114 m_viewTab
.append(ViewTab());
115 ViewTab
& viewTab
= m_viewTab
[m_tabIndex
];
116 viewTab
.wasActive
= true; // The first opened tab is automatically active
118 connect(&DolphinNewFileMenuObserver::instance(), SIGNAL(errorMessage(QString
)),
119 this, SLOT(showErrorMessage(QString
)));
121 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
122 undoManager
->setUiInterface(new UndoUiInterface());
124 connect(undoManager
, SIGNAL(undoAvailable(bool)),
125 this, SLOT(slotUndoAvailable(bool)));
126 connect(undoManager
, SIGNAL(undoTextChanged(QString
)),
127 this, SLOT(slotUndoTextChanged(QString
)));
128 connect(undoManager
, SIGNAL(jobRecordingStarted(CommandType
)),
129 this, SLOT(clearStatusBar()));
130 connect(undoManager
, SIGNAL(jobRecordingFinished(CommandType
)),
131 this, SLOT(showCommand(CommandType
)));
133 GeneralSettings
* generalSettings
= GeneralSettings::self();
134 const bool firstRun
= (generalSettings
->version() < 200);
136 generalSettings
->setViewPropsTimestamp(QDateTime::currentDateTime());
139 setAcceptDrops(true);
141 viewTab
.splitter
= new QSplitter(this);
142 viewTab
.splitter
->setChildrenCollapsible(false);
146 const KUrl
homeUrl(generalSettings
->homeUrl());
147 setUrlAsCaption(homeUrl
);
148 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
149 connect(m_actionHandler
, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
150 connect(m_actionHandler
, SIGNAL(createDirectory()), SLOT(createDirectory()));
152 viewTab
.primaryView
= createViewContainer(homeUrl
, viewTab
.splitter
);
154 m_activeViewContainer
= viewTab
.primaryView
;
155 connectViewSignals(m_activeViewContainer
);
156 DolphinView
* view
= m_activeViewContainer
->view();
157 m_activeViewContainer
->show();
158 m_actionHandler
->setCurrentView(view
);
160 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
161 connect(this, SIGNAL(urlChanged(KUrl
)),
162 m_remoteEncoding
, SLOT(slotAboutToOpenUrl()));
164 m_tabBar
= new KTabBar(this);
165 m_tabBar
->setMovable(true);
166 m_tabBar
->setTabsClosable(true);
167 connect(m_tabBar
, SIGNAL(currentChanged(int)),
168 this, SLOT(setActiveTab(int)));
169 connect(m_tabBar
, SIGNAL(tabCloseRequested(int)),
170 this, SLOT(closeTab(int)));
171 connect(m_tabBar
, SIGNAL(contextMenu(int,QPoint
)),
172 this, SLOT(openTabContextMenu(int,QPoint
)));
173 connect(m_tabBar
, SIGNAL(newTabRequest()),
174 this, SLOT(openNewTab()));
175 connect(m_tabBar
, SIGNAL(testCanDecode(const QDragMoveEvent
*,bool&)),
176 this, SLOT(slotTestCanDecode(const QDragMoveEvent
*,bool&)));
177 connect(m_tabBar
, SIGNAL(mouseMiddleClick(int)),
178 this, SLOT(closeTab(int)));
179 connect(m_tabBar
, SIGNAL(tabMoved(int,int)),
180 this, SLOT(slotTabMoved(int,int)));
181 connect(m_tabBar
, SIGNAL(receivedDropEvent(int,QDropEvent
*)),
182 this, SLOT(tabDropEvent(int,QDropEvent
*)));
184 m_tabBar
->blockSignals(true); // signals get unblocked after at least 2 tabs are open
186 QWidget
* centralWidget
= new QWidget(this);
187 m_centralWidgetLayout
= new QVBoxLayout(centralWidget
);
188 m_centralWidgetLayout
->setSpacing(0);
189 m_centralWidgetLayout
->setMargin(0);
190 m_centralWidgetLayout
->addWidget(m_tabBar
);
191 m_centralWidgetLayout
->addWidget(viewTab
.splitter
, 1);
193 setCentralWidget(centralWidget
);
195 emit
urlChanged(homeUrl
);
197 setupGUI(Keys
| Save
| Create
| ToolBar
);
198 stateChanged("new_file");
200 QClipboard
* clipboard
= QApplication::clipboard();
201 connect(clipboard
, SIGNAL(dataChanged()),
202 this, SLOT(updatePasteAction()));
204 if (generalSettings
->splitView()) {
212 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
213 showFilterBarAction
->setChecked(generalSettings
->filterBar());
216 menuBar()->setVisible(false);
217 // Assure a proper default size if Dolphin runs the first time
221 const bool showMenu
= !menuBar()->isHidden();
222 QAction
* showMenuBarAction
= actionCollection()->action(KStandardAction::name(KStandardAction::ShowMenubar
));
223 showMenuBarAction
->setChecked(showMenu
); // workaround for bug #171080
225 createControlButton();
229 DolphinMainWindow::~DolphinMainWindow()
233 void DolphinMainWindow::openDirectories(const QList
<KUrl
>& dirs
)
235 if (dirs
.isEmpty()) {
239 if (dirs
.count() == 1) {
240 m_activeViewContainer
->setUrl(dirs
.first());
244 const int oldOpenTabsCount
= m_viewTab
.count();
246 const bool hasSplitView
= GeneralSettings::splitView();
248 // Open each directory inside a new tab. If the "split view" option has been enabled,
249 // always show two directories within one tab.
250 QList
<KUrl
>::const_iterator it
= dirs
.constBegin();
251 while (it
!= dirs
.constEnd()) {
255 if (hasSplitView
&& (it
!= dirs
.constEnd())) {
256 const int tabIndex
= m_viewTab
.count() - 1;
257 m_viewTab
[tabIndex
].secondaryView
->setUrl(*it
);
262 // Remove the previously opened tabs
263 for (int i
= 0; i
< oldOpenTabsCount
; ++i
) {
268 void DolphinMainWindow::openFiles(const QList
<KUrl
>& files
)
270 if (files
.isEmpty()) {
274 // Get all distinct directories from 'files' and open a tab
275 // for each directory. If the "split view" option is enabled, two
276 // directories are shown inside one tab (see openDirectories()).
278 foreach (const KUrl
& url
, files
) {
279 const KUrl
dir(url
.directory());
280 if (!dirs
.contains(dir
)) {
285 openDirectories(dirs
);
287 // Select the files. Although the files can be split between several
288 // tabs, there is no need to split 'files' accordingly, as
289 // the DolphinView will just ignore invalid selections.
290 const int tabCount
= m_viewTab
.count();
291 for (int i
= 0; i
< tabCount
; ++i
) {
292 m_viewTab
[i
].primaryView
->view()->markUrlsAsSelected(files
);
293 m_viewTab
[i
].primaryView
->view()->markUrlAsCurrent(files
.at(0));
294 if (m_viewTab
[i
].secondaryView
) {
295 m_viewTab
[i
].secondaryView
->view()->markUrlsAsSelected(files
);
296 m_viewTab
[i
].secondaryView
->view()->markUrlAsCurrent(files
.at(0));
301 void DolphinMainWindow::showCommand(CommandType command
)
303 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
305 case KIO::FileUndoManager::Copy
:
306 statusBar
->setText(i18nc("@info:status", "Successfully copied."));
308 case KIO::FileUndoManager::Move
:
309 statusBar
->setText(i18nc("@info:status", "Successfully moved."));
311 case KIO::FileUndoManager::Link
:
312 statusBar
->setText(i18nc("@info:status", "Successfully linked."));
314 case KIO::FileUndoManager::Trash
:
315 statusBar
->setText(i18nc("@info:status", "Successfully moved to trash."));
317 case KIO::FileUndoManager::Rename
:
318 statusBar
->setText(i18nc("@info:status", "Successfully renamed."));
321 case KIO::FileUndoManager::Mkdir
:
322 statusBar
->setText(i18nc("@info:status", "Created folder."));
330 void DolphinMainWindow::pasteIntoFolder()
332 m_activeViewContainer
->view()->pasteIntoFolder();
335 void DolphinMainWindow::changeUrl(const KUrl
& url
)
337 if (!KProtocolManager::supportsListing(url
)) {
338 // The URL navigator only checks for validity, not
339 // if the URL can be listed. An error message is
340 // shown due to DolphinViewContainer::restoreView().
344 DolphinViewContainer
* view
= activeViewContainer();
351 setUrlAsCaption(url
);
352 if (m_viewTab
.count() > 1) {
353 m_tabBar
->setTabText(m_tabIndex
, squeezedText(tabName(m_activeViewContainer
->url())));
355 const QString iconName
= KMimeType::iconNameForUrl(url
);
356 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(iconName
));
357 emit
urlChanged(url
);
361 void DolphinMainWindow::slotTerminalDirectoryChanged(const KUrl
& url
)
363 m_activeViewContainer
->setAutoGrabFocus(false);
365 m_activeViewContainer
->setAutoGrabFocus(true);
368 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
370 KToggleAction
* editableLocationAction
=
371 static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
372 editableLocationAction
->setChecked(editable
);
375 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
379 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
380 int selectedUrlsCount
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedItemsCount();
381 if (m_viewTab
[m_tabIndex
].secondaryView
) {
382 selectedUrlsCount
+= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItemsCount();
385 QAction
* compareFilesAction
= actionCollection()->action("compare_files");
386 if (selectedUrlsCount
== 2) {
387 compareFilesAction
->setEnabled(isKompareInstalled());
389 compareFilesAction
->setEnabled(false);
392 emit
selectionChanged(selection
);
395 void DolphinMainWindow::slotRequestItemInfo(const KFileItem
& item
)
397 emit
requestItemInfo(item
);
400 void DolphinMainWindow::updateHistory()
402 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
403 const int index
= urlNavigator
->historyIndex();
405 QAction
* backAction
= actionCollection()->action("go_back");
407 backAction
->setToolTip(i18nc("@info", "Go back"));
408 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
411 QAction
* forwardAction
= actionCollection()->action("go_forward");
413 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
414 forwardAction
->setEnabled(index
> 0);
418 void DolphinMainWindow::updateFilterBarAction(bool show
)
420 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
421 showFilterBarAction
->setChecked(show
);
424 void DolphinMainWindow::openNewMainWindow()
426 KRun::run("dolphin %u", KUrl::List(), this);
429 void DolphinMainWindow::openNewTab()
431 const bool isUrlEditable
= m_activeViewContainer
->urlNavigator()->isUrlEditable();
433 openNewTab(m_activeViewContainer
->url());
434 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
436 // The URL navigator of the new tab should have the same editable state
437 // as the current tab
438 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
439 navigator
->setUrlEditable(isUrlEditable
);
442 // If a new tab is opened and the URL is editable, assure that
443 // the user can edit the URL without manually setting the focus
444 navigator
->setFocus();
448 void DolphinMainWindow::openNewTab(const KUrl
& url
)
450 QWidget
* focusWidget
= QApplication::focusWidget();
452 if (m_viewTab
.count() == 1) {
453 // Only one view is open currently and hence no tab is shown at
454 // all. Before creating a tab for 'url', provide a tab for the current URL.
455 const KUrl currentUrl
= m_activeViewContainer
->url();
456 m_tabBar
->addTab(KIcon(KMimeType::iconNameForUrl(currentUrl
)),
457 squeezedText(tabName(currentUrl
)));
458 m_tabBar
->blockSignals(false);
461 m_tabBar
->addTab(KIcon(KMimeType::iconNameForUrl(url
)),
462 squeezedText(tabName(url
)));
465 viewTab
.splitter
= new QSplitter(this);
466 viewTab
.splitter
->setChildrenCollapsible(false);
467 viewTab
.primaryView
= createViewContainer(url
, viewTab
.splitter
);
468 viewTab
.primaryView
->setActive(false);
469 connectViewSignals(viewTab
.primaryView
);
471 m_viewTab
.append(viewTab
);
473 actionCollection()->action("close_tab")->setEnabled(true);
474 actionCollection()->action("activate_prev_tab")->setEnabled(true);
475 actionCollection()->action("activate_next_tab")->setEnabled(true);
477 // Provide a split view, if the startup settings are set this way
478 if (GeneralSettings::splitView()) {
479 const int newTabIndex
= m_viewTab
.count() - 1;
480 createSecondaryView(newTabIndex
);
481 m_viewTab
[newTabIndex
].secondaryView
->setActive(true);
482 m_viewTab
[newTabIndex
].isPrimaryViewActive
= false;
486 // The DolphinViewContainer grabbed the keyboard focus. As the tab is opened
487 // in background, assure that the previous focused widget gets the focus back.
488 focusWidget
->setFocus();
492 void DolphinMainWindow::openNewActivatedTab(const KUrl
& url
)
495 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
498 void DolphinMainWindow::activateNextTab()
500 if (m_viewTab
.count() >= 2) {
501 const int tabIndex
= (m_tabBar
->currentIndex() + 1) % m_tabBar
->count();
502 m_tabBar
->setCurrentIndex(tabIndex
);
506 void DolphinMainWindow::activatePrevTab()
508 if (m_viewTab
.count() >= 2) {
509 int tabIndex
= m_tabBar
->currentIndex() - 1;
510 if (tabIndex
== -1) {
511 tabIndex
= m_tabBar
->count() - 1;
513 m_tabBar
->setCurrentIndex(tabIndex
);
517 void DolphinMainWindow::openInNewTab()
519 const KFileItemList
& list
= m_activeViewContainer
->view()->selectedItems();
520 if (list
.isEmpty()) {
521 openNewTab(m_activeViewContainer
->url());
523 foreach (const KFileItem
& item
, list
) {
524 const KUrl
& url
= DolphinView::openItemAsFolderUrl(item
);
525 if (!url
.isEmpty()) {
532 void DolphinMainWindow::openInNewWindow()
536 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
537 if (list
.isEmpty()) {
538 newWindowUrl
= m_activeViewContainer
->url();
539 } else if (list
.count() == 1) {
540 const KFileItem
& item
= list
.first();
541 newWindowUrl
= DolphinView::openItemAsFolderUrl(item
);
544 if (!newWindowUrl
.isEmpty()) {
545 KRun::run("dolphin %u", KUrl::List() << newWindowUrl
, this);
549 void DolphinMainWindow::toggleActiveView()
551 if (!m_viewTab
[m_tabIndex
].secondaryView
) {
552 // only one view is available
556 Q_ASSERT(m_activeViewContainer
);
557 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
559 DolphinViewContainer
* left
= m_viewTab
[m_tabIndex
].primaryView
;
560 DolphinViewContainer
* right
= m_viewTab
[m_tabIndex
].secondaryView
;
561 setActiveViewContainer(m_activeViewContainer
== right
? left
: right
);
564 void DolphinMainWindow::showEvent(QShowEvent
* event
)
566 KXmlGuiWindow::showEvent(event
);
567 if (!event
->spontaneous()) {
568 m_activeViewContainer
->view()->setFocus();
572 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
574 // Find out if Dolphin is closed directly by the user or
575 // by the session manager because the session is closed
576 bool closedByUser
= true;
577 DolphinApplication
*application
= qobject_cast
<DolphinApplication
*>(qApp
);
578 if (application
&& application
->sessionSaving()) {
579 closedByUser
= false;
582 if (m_viewTab
.count() > 1 && GeneralSettings::confirmClosingMultipleTabs() && closedByUser
) {
583 // Ask the user if he really wants to quit and close all tabs.
584 // Open a confirmation dialog with 3 buttons:
585 // KDialog::Yes -> Quit
586 // KDialog::No -> Close only the current tab
587 // KDialog::Cancel -> do nothing
588 KDialog
*dialog
= new KDialog(this, Qt::Dialog
);
589 dialog
->setCaption(i18nc("@title:window", "Confirmation"));
590 dialog
->setButtons(KDialog::Yes
| KDialog::No
| KDialog::Cancel
);
591 dialog
->setModal(true);
592 dialog
->setButtonGuiItem(KDialog::Yes
, KStandardGuiItem::quit());
593 dialog
->setButtonGuiItem(KDialog::No
, KGuiItem(i18n("C&lose Current Tab"), KIcon("tab-close")));
594 dialog
->setButtonGuiItem(KDialog::Cancel
, KStandardGuiItem::cancel());
595 dialog
->setDefaultButton(KDialog::Yes
);
597 bool doNotAskAgainCheckboxResult
= false;
599 const int result
= KMessageBox::createKMessageBox(dialog
,
600 QMessageBox::Warning
,
601 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
603 i18n("Do not ask again"),
604 &doNotAskAgainCheckboxResult
,
605 KMessageBox::Notify
);
607 if (doNotAskAgainCheckboxResult
) {
608 GeneralSettings::setConfirmClosingMultipleTabs(false);
616 // Close only the current tab
624 GeneralSettings::setVersion(CurrentDolphinVersion
);
625 GeneralSettings::self()->writeConfig();
627 KXmlGuiWindow::closeEvent(event
);
630 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
632 const int tabCount
= m_viewTab
.count();
633 group
.writeEntry("Tab Count", tabCount
);
634 group
.writeEntry("Active Tab Index", m_tabBar
->currentIndex());
636 for (int i
= 0; i
< tabCount
; ++i
) {
637 const DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
638 group
.writeEntry(tabProperty("Primary URL", i
), cont
->url().url());
639 group
.writeEntry(tabProperty("Primary Editable", i
),
640 cont
->urlNavigator()->isUrlEditable());
642 cont
= m_viewTab
[i
].secondaryView
;
644 group
.writeEntry(tabProperty("Secondary URL", i
), cont
->url().url());
645 group
.writeEntry(tabProperty("Secondary Editable", i
),
646 cont
->urlNavigator()->isUrlEditable());
651 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
653 const int tabCount
= group
.readEntry("Tab Count", 1);
654 for (int i
= 0; i
< tabCount
; ++i
) {
655 DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
657 cont
->setUrl(group
.readEntry(tabProperty("Primary URL", i
)));
658 const bool editable
= group
.readEntry(tabProperty("Primary Editable", i
), false);
659 cont
->urlNavigator()->setUrlEditable(editable
);
661 cont
= m_viewTab
[i
].secondaryView
;
662 const QString secondaryUrl
= group
.readEntry(tabProperty("Secondary URL", i
));
663 if (!secondaryUrl
.isEmpty()) {
665 // a secondary view should be shown, but no one is available
666 // currently -> create a new view
668 cont
= m_viewTab
[i
].secondaryView
;
672 // The right view must be activated before the URL is set. Changing
673 // the URL in the right view will emit the right URL navigator's
674 // urlChanged(KUrl) signal, which is connected to the changeUrl(KUrl)
675 // slot. That slot will change the URL in the left view if it is still
676 // active. See https://bugs.kde.org/show_bug.cgi?id=330047.
677 setActiveViewContainer(cont
);
679 cont
->setUrl(secondaryUrl
);
680 const bool editable
= group
.readEntry(tabProperty("Secondary Editable", i
), false);
681 cont
->urlNavigator()->setUrlEditable(editable
);
683 // no secondary view should be shown, but the default setting shows
684 // one already -> close the view
688 // openNewTab() needs to be called only tabCount - 1 times
689 if (i
!= tabCount
- 1) {
694 const int index
= group
.readEntry("Active Tab Index", 0);
695 m_tabBar
->setCurrentIndex(index
);
698 void DolphinMainWindow::updateNewMenu()
700 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
701 m_newFileMenu
->checkUpToDate();
702 m_newFileMenu
->setPopupFiles(activeViewContainer()->url());
705 void DolphinMainWindow::createDirectory()
707 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
708 m_newFileMenu
->setPopupFiles(activeViewContainer()->url());
709 m_newFileMenu
->createDirectory();
712 void DolphinMainWindow::quit()
717 void DolphinMainWindow::showErrorMessage(const QString
& message
)
719 m_activeViewContainer
->showMessage(message
, DolphinViewContainer::Error
);
722 void DolphinMainWindow::slotUndoAvailable(bool available
)
724 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
726 undoAction
->setEnabled(available
);
730 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
732 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
734 undoAction
->setText(text
);
738 void DolphinMainWindow::undo()
741 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
742 KIO::FileUndoManager::self()->undo();
745 void DolphinMainWindow::cut()
747 m_activeViewContainer
->view()->cutSelectedItems();
750 void DolphinMainWindow::copy()
752 m_activeViewContainer
->view()->copySelectedItems();
755 void DolphinMainWindow::paste()
757 m_activeViewContainer
->view()->paste();
760 void DolphinMainWindow::find()
762 m_activeViewContainer
->setSearchModeEnabled(true);
765 void DolphinMainWindow::updatePasteAction()
767 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
768 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
769 pasteAction
->setEnabled(pasteInfo
.first
);
770 pasteAction
->setText(pasteInfo
.second
);
773 void DolphinMainWindow::selectAll()
777 // if the URL navigator is editable and focused, select the whole
778 // URL instead of all items of the view
780 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
781 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit(); // krazy:exclude=qclasses
782 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
783 lineEdit
->hasFocus();
785 lineEdit
->selectAll();
787 m_activeViewContainer
->view()->selectAll();
791 void DolphinMainWindow::invertSelection()
794 m_activeViewContainer
->view()->invertSelection();
797 void DolphinMainWindow::toggleSplitView()
799 if (!m_viewTab
[m_tabIndex
].secondaryView
) {
800 createSecondaryView(m_tabIndex
);
801 setActiveViewContainer(m_viewTab
[m_tabIndex
].secondaryView
);
802 } else if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
803 // remove secondary view
804 m_viewTab
[m_tabIndex
].secondaryView
->close();
805 m_viewTab
[m_tabIndex
].secondaryView
->deleteLater();
806 m_viewTab
[m_tabIndex
].secondaryView
= 0;
808 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
810 // The primary view is active and should be closed. Hence from a users point of view
811 // the content of the secondary view should be moved to the primary view.
812 // From an implementation point of view it is more efficient to close
813 // the primary view and exchange the internal pointers afterwards.
815 m_viewTab
[m_tabIndex
].primaryView
->close();
816 m_viewTab
[m_tabIndex
].primaryView
->deleteLater();
817 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
818 m_viewTab
[m_tabIndex
].secondaryView
= 0;
820 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
826 void DolphinMainWindow::reloadView()
829 m_activeViewContainer
->view()->reload();
832 void DolphinMainWindow::stopLoading()
834 m_activeViewContainer
->view()->stopLoading();
837 void DolphinMainWindow::enableStopAction()
839 actionCollection()->action("stop")->setEnabled(true);
842 void DolphinMainWindow::disableStopAction()
844 actionCollection()->action("stop")->setEnabled(false);
847 void DolphinMainWindow::showFilterBar()
849 m_activeViewContainer
->setFilterBarVisible(true);
852 void DolphinMainWindow::toggleEditLocation()
856 QAction
* action
= actionCollection()->action("editable_location");
857 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
858 urlNavigator
->setUrlEditable(action
->isChecked());
861 void DolphinMainWindow::replaceLocation()
863 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
864 navigator
->setUrlEditable(true);
865 navigator
->setFocus();
867 // select the whole text of the combo box editor
868 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit(); // krazy:exclude=qclasses
869 lineEdit
->selectAll();
872 void DolphinMainWindow::togglePanelLockState()
874 const bool newLockState
= !GeneralSettings::lockPanels();
875 foreach (QObject
* child
, children()) {
876 DolphinDockWidget
* dock
= qobject_cast
<DolphinDockWidget
*>(child
);
878 dock
->setLocked(newLockState
);
882 GeneralSettings::setLockPanels(newLockState
);
885 void DolphinMainWindow::slotPlacesPanelVisibilityChanged(bool visible
)
887 const int tabCount
= m_viewTab
.count();
888 for (int i
= 0; i
< tabCount
; ++i
) {
889 ViewTab
& tab
= m_viewTab
[i
];
890 Q_ASSERT(tab
.primaryView
);
891 tab
.primaryView
->urlNavigator()->setPlacesSelectorVisible(!visible
);
892 if (tab
.secondaryView
) {
893 tab
.secondaryView
->urlNavigator()->setPlacesSelectorVisible(!visible
);
898 void DolphinMainWindow::goBack()
900 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
901 urlNavigator
->goBack();
903 if (urlNavigator
->locationState().isEmpty()) {
904 // An empty location state indicates a redirection URL,
905 // which must be skipped too
906 urlNavigator
->goBack();
910 void DolphinMainWindow::goForward()
912 m_activeViewContainer
->urlNavigator()->goForward();
915 void DolphinMainWindow::goUp()
917 m_activeViewContainer
->urlNavigator()->goUp();
920 void DolphinMainWindow::goHome()
922 m_activeViewContainer
->urlNavigator()->goHome();
925 void DolphinMainWindow::goBack(Qt::MouseButtons buttons
)
927 // The default case (left button pressed) is handled in goBack().
928 if (buttons
== Qt::MidButton
) {
929 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
930 const int index
= urlNavigator
->historyIndex() + 1;
931 openNewTab(urlNavigator
->locationUrl(index
));
935 void DolphinMainWindow::goForward(Qt::MouseButtons buttons
)
937 // The default case (left button pressed) is handled in goForward().
938 if (buttons
== Qt::MidButton
) {
939 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
940 const int index
= urlNavigator
->historyIndex() - 1;
941 openNewTab(urlNavigator
->locationUrl(index
));
945 void DolphinMainWindow::goUp(Qt::MouseButtons buttons
)
947 // The default case (left button pressed) is handled in goUp().
948 if (buttons
== Qt::MidButton
) {
949 openNewTab(activeViewContainer()->url().upUrl());
953 void DolphinMainWindow::goHome(Qt::MouseButtons buttons
)
955 // The default case (left button pressed) is handled in goHome().
956 if (buttons
== Qt::MidButton
) {
957 openNewTab(GeneralSettings::self()->homeUrl());
961 void DolphinMainWindow::compareFiles()
963 const DolphinViewContainer
* primaryViewContainer
= m_viewTab
[m_tabIndex
].primaryView
;
964 Q_ASSERT(primaryViewContainer
);
965 KFileItemList items
= primaryViewContainer
->view()->selectedItems();
967 const DolphinViewContainer
* secondaryViewContainer
= m_viewTab
[m_tabIndex
].secondaryView
;
968 if (secondaryViewContainer
) {
969 items
.append(secondaryViewContainer
->view()->selectedItems());
972 if (items
.count() != 2) {
973 // The action is disabled in this case, but it could have been triggered
974 // via D-Bus, see https://bugs.kde.org/show_bug.cgi?id=325517
978 KUrl urlA
= items
.at(0).url();
979 KUrl urlB
= items
.at(1).url();
981 QString
command("kompare -c \"");
982 command
.append(urlA
.pathOrUrl());
983 command
.append("\" \"");
984 command
.append(urlB
.pathOrUrl());
985 command
.append('\"');
986 KRun::runCommand(command
, "Kompare", "kompare", this);
989 void DolphinMainWindow::toggleShowMenuBar()
991 const bool visible
= menuBar()->isVisible();
992 menuBar()->setVisible(!visible
);
994 createControlButton();
996 deleteControlButton();
1000 void DolphinMainWindow::openTerminal()
1002 QString
dir(QDir::homePath());
1004 // If the given directory is not local, it can still be the URL of an
1005 // ioslave using UDS_LOCAL_PATH which to be converted first.
1006 KUrl url
= KIO::NetAccess::mostLocalUrl(m_activeViewContainer
->url(), this);
1008 //If the URL is local after the above conversion, set the directory.
1009 if (url
.isLocalFile()) {
1010 dir
= url
.toLocalFile();
1013 KToolInvocation::invokeTerminal(QString(), dir
);
1016 void DolphinMainWindow::editSettings()
1018 if (!m_settingsDialog
) {
1019 DolphinViewContainer
* container
= activeViewContainer();
1020 container
->view()->writeSettings();
1022 const KUrl url
= container
->url();
1023 DolphinSettingsDialog
* settingsDialog
= new DolphinSettingsDialog(url
, this);
1024 connect(settingsDialog
, SIGNAL(settingsChanged()), this, SLOT(refreshViews()));
1025 settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1026 settingsDialog
->show();
1027 m_settingsDialog
= settingsDialog
;
1029 m_settingsDialog
.data()->raise();
1033 void DolphinMainWindow::setActiveTab(int index
)
1035 Q_ASSERT(index
>= 0);
1036 Q_ASSERT(index
< m_viewTab
.count());
1037 if (index
== m_tabIndex
) {
1041 // hide current tab content
1042 ViewTab
& hiddenTab
= m_viewTab
[m_tabIndex
];
1043 hiddenTab
.isPrimaryViewActive
= hiddenTab
.primaryView
->isActive();
1044 hiddenTab
.primaryView
->setActive(false);
1045 if (hiddenTab
.secondaryView
) {
1046 hiddenTab
.secondaryView
->setActive(false);
1048 QSplitter
* splitter
= m_viewTab
[m_tabIndex
].splitter
;
1050 m_centralWidgetLayout
->removeWidget(splitter
);
1052 // show active tab content
1055 ViewTab
& viewTab
= m_viewTab
[index
];
1056 m_centralWidgetLayout
->addWidget(viewTab
.splitter
, 1);
1057 viewTab
.primaryView
->show();
1058 if (viewTab
.secondaryView
) {
1059 viewTab
.secondaryView
->show();
1061 viewTab
.splitter
->show();
1063 if (!viewTab
.wasActive
) {
1064 viewTab
.wasActive
= true;
1066 // If the tab has not been activated yet the size of the KItemListView is
1067 // undefined and results in an unwanted animation. To prevent this a
1068 // reloading of the directory gets triggered.
1069 viewTab
.primaryView
->view()->reload();
1070 if (viewTab
.secondaryView
) {
1071 viewTab
.secondaryView
->view()->reload();
1075 setActiveViewContainer(viewTab
.isPrimaryViewActive
? viewTab
.primaryView
:
1076 viewTab
.secondaryView
);
1079 void DolphinMainWindow::closeTab()
1081 closeTab(m_tabBar
->currentIndex());
1084 void DolphinMainWindow::closeTab(int index
)
1086 Q_ASSERT(index
>= 0);
1087 Q_ASSERT(index
< m_viewTab
.count());
1088 if (m_viewTab
.count() == 1) {
1089 // the last tab may never get closed
1093 if (index
== m_tabIndex
) {
1094 // The tab that should be closed is the active tab. Activate the
1095 // previous tab before closing the tab.
1096 m_tabBar
->setCurrentIndex((index
> 0) ? index
- 1 : 1);
1099 const KUrl
primaryUrl(m_viewTab
[index
].primaryView
->url());
1100 const KUrl
secondaryUrl(m_viewTab
[index
].secondaryView
? m_viewTab
[index
].secondaryView
->url() : KUrl());
1101 emit
rememberClosedTab(primaryUrl
, secondaryUrl
);
1104 m_viewTab
[index
].primaryView
->deleteLater();
1105 if (m_viewTab
[index
].secondaryView
) {
1106 m_viewTab
[index
].secondaryView
->deleteLater();
1108 m_viewTab
[index
].splitter
->deleteLater();
1109 m_viewTab
.erase(m_viewTab
.begin() + index
);
1111 m_tabBar
->blockSignals(true);
1112 m_tabBar
->removeTab(index
);
1114 if (m_tabIndex
> index
) {
1116 Q_ASSERT(m_tabIndex
>= 0);
1119 // if only one tab is left, also remove the tab entry so that
1120 // closing the last tab is not possible
1121 if (m_viewTab
.count() == 1) {
1122 m_tabBar
->removeTab(0);
1123 actionCollection()->action("close_tab")->setEnabled(false);
1124 actionCollection()->action("activate_prev_tab")->setEnabled(false);
1125 actionCollection()->action("activate_next_tab")->setEnabled(false);
1127 m_tabBar
->blockSignals(false);
1131 void DolphinMainWindow::openTabContextMenu(int index
, const QPoint
& pos
)
1135 QAction
* newTabAction
= menu
.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab"));
1136 newTabAction
->setShortcut(actionCollection()->action("new_tab")->shortcut());
1138 QAction
* detachTabAction
= menu
.addAction(KIcon("tab-detach"), i18nc("@action:inmenu", "Detach Tab"));
1140 QAction
* closeOtherTabsAction
= menu
.addAction(KIcon("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs"));
1142 QAction
* closeTabAction
= menu
.addAction(KIcon("tab-close"), i18nc("@action:inmenu", "Close Tab"));
1143 closeTabAction
->setShortcut(actionCollection()->action("close_tab")->shortcut());
1144 QAction
* selectedAction
= menu
.exec(pos
);
1145 if (selectedAction
== newTabAction
) {
1146 const ViewTab
& tab
= m_viewTab
[index
];
1147 Q_ASSERT(tab
.primaryView
);
1148 const KUrl url
= tab
.secondaryView
&& tab
.secondaryView
->isActive() ?
1149 tab
.secondaryView
->url() : tab
.primaryView
->url();
1151 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
1152 } else if (selectedAction
== detachTabAction
) {
1153 const QString
separator(QLatin1Char(' '));
1154 QString command
= QLatin1String("dolphin");
1156 const ViewTab
& tab
= m_viewTab
[index
];
1157 Q_ASSERT(tab
.primaryView
);
1159 command
+= separator
+ tab
.primaryView
->url().url();
1160 if (tab
.secondaryView
) {
1161 command
+= separator
+ tab
.secondaryView
->url().url();
1162 command
+= separator
+ QLatin1String("-split");
1165 KRun::runCommand(command
, this);
1168 } else if (selectedAction
== closeOtherTabsAction
) {
1169 const int count
= m_tabBar
->count();
1170 for (int i
= 0; i
< index
; ++i
) {
1173 for (int i
= index
+ 1; i
< count
; ++i
) {
1176 } else if (selectedAction
== closeTabAction
) {
1181 void DolphinMainWindow::slotTabMoved(int from
, int to
)
1183 m_viewTab
.move(from
, to
);
1184 m_tabIndex
= m_tabBar
->currentIndex();
1187 void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent
* event
, bool& canDecode
)
1189 canDecode
= KUrl::List::canDecode(event
->mimeData());
1192 void DolphinMainWindow::handleUrl(const KUrl
& url
)
1194 delete m_lastHandleUrlStatJob
;
1195 m_lastHandleUrlStatJob
= 0;
1197 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1198 activeViewContainer()->setUrl(url
);
1199 } else if (KProtocolManager::supportsListing(url
)) {
1200 // stat the URL to see if it is a dir or not
1201 m_lastHandleUrlStatJob
= KIO::stat(url
, KIO::HideProgressInfo
);
1202 if (m_lastHandleUrlStatJob
->ui()) {
1203 m_lastHandleUrlStatJob
->ui()->setWindow(this);
1205 connect(m_lastHandleUrlStatJob
, SIGNAL(result(KJob
*)),
1206 this, SLOT(slotHandleUrlStatFinished(KJob
*)));
1209 new KRun(url
, this); // Automatically deletes itself after being finished
1213 void DolphinMainWindow::slotHandleUrlStatFinished(KJob
* job
)
1215 m_lastHandleUrlStatJob
= 0;
1216 const KIO::UDSEntry entry
= static_cast<KIO::StatJob
*>(job
)->statResult();
1217 const KUrl url
= static_cast<KIO::StatJob
*>(job
)->url();
1218 if (entry
.isDir()) {
1219 activeViewContainer()->setUrl(url
);
1221 new KRun(url
, this); // Automatically deletes itself after being finished
1225 void DolphinMainWindow::tabDropEvent(int tab
, QDropEvent
* event
)
1227 const KUrl::List urls
= KUrl::List::fromMimeData(event
->mimeData());
1228 if (!urls
.isEmpty() && tab
!= -1) {
1229 const ViewTab
& viewTab
= m_viewTab
[tab
];
1230 const DolphinView
* view
= viewTab
.isPrimaryViewActive
? viewTab
.primaryView
->view()
1231 : viewTab
.secondaryView
->view();
1233 DragAndDropHelper::dropUrls(view
->rootItem(), view
->url(), event
, error
);
1234 if (!error
.isEmpty()) {
1235 activeViewContainer()->showMessage(error
, DolphinViewContainer::Error
);
1240 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1242 newFileMenu()->setEnabled(isFolderWritable
);
1245 void DolphinMainWindow::openContextMenu(const QPoint
& pos
,
1246 const KFileItem
& item
,
1248 const QList
<QAction
*>& customActions
)
1250 QWeakPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, pos
, item
, url
);
1251 contextMenu
.data()->setCustomActions(customActions
);
1252 const DolphinContextMenu::Command command
= contextMenu
.data()->open();
1255 case DolphinContextMenu::OpenParentFolderInNewWindow
: {
1256 KRun::run("dolphin %u", KUrl::List() << item
.url().upUrl(), this);
1260 case DolphinContextMenu::OpenParentFolderInNewTab
:
1261 openNewTab(item
.url().upUrl());
1264 case DolphinContextMenu::None
:
1269 delete contextMenu
.data();
1272 void DolphinMainWindow::updateControlMenu()
1274 KMenu
* menu
= qobject_cast
<KMenu
*>(sender());
1277 // All actions get cleared by KMenu::clear(). The sub-menus are deleted
1278 // by connecting to the aboutToHide() signal from the parent-menu.
1281 KActionCollection
* ac
= actionCollection();
1283 // Add "Edit" actions
1284 bool added
= addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Undo
)), menu
) |
1285 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Find
)), menu
) |
1286 addActionToMenu(ac
->action("select_all"), menu
) |
1287 addActionToMenu(ac
->action("invert_selection"), menu
);
1290 menu
->addSeparator();
1293 // Add "View" actions
1294 if (!GeneralSettings::showZoomSlider()) {
1295 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomIn
)), menu
);
1296 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomOut
)), menu
);
1297 menu
->addSeparator();
1300 added
= addActionToMenu(ac
->action("view_mode"), menu
) |
1301 addActionToMenu(ac
->action("sort"), menu
) |
1302 addActionToMenu(ac
->action("additional_info"), menu
) |
1303 addActionToMenu(ac
->action("show_preview"), menu
) |
1304 addActionToMenu(ac
->action("show_in_groups"), menu
) |
1305 addActionToMenu(ac
->action("show_hidden_files"), menu
);
1308 menu
->addSeparator();
1311 added
= addActionToMenu(ac
->action("split_view"), menu
) |
1312 addActionToMenu(ac
->action("reload"), menu
) |
1313 addActionToMenu(ac
->action("view_properties"), menu
);
1315 menu
->addSeparator();
1318 addActionToMenu(ac
->action("panels"), menu
);
1319 KMenu
* locationBarMenu
= new KMenu(i18nc("@action:inmenu", "Location Bar"), menu
);
1320 locationBarMenu
->addAction(ac
->action("editable_location"));
1321 locationBarMenu
->addAction(ac
->action("replace_location"));
1322 menu
->addMenu(locationBarMenu
);
1324 menu
->addSeparator();
1327 KMenu
* goMenu
= new KMenu(i18nc("@action:inmenu", "Go"), menu
);
1328 connect(menu
, SIGNAL(aboutToHide()), goMenu
, SLOT(deleteLater()));
1329 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Back
)));
1330 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Forward
)));
1331 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Up
)));
1332 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Home
)));
1333 goMenu
->addAction(ac
->action("closed_tabs"));
1334 menu
->addMenu(goMenu
);
1337 KMenu
* toolsMenu
= new KMenu(i18nc("@action:inmenu", "Tools"), menu
);
1338 connect(menu
, SIGNAL(aboutToHide()), toolsMenu
, SLOT(deleteLater()));
1339 toolsMenu
->addAction(ac
->action("show_filter_bar"));
1340 toolsMenu
->addAction(ac
->action("compare_files"));
1341 toolsMenu
->addAction(ac
->action("open_terminal"));
1342 toolsMenu
->addAction(ac
->action("change_remote_encoding"));
1343 menu
->addMenu(toolsMenu
);
1345 // Add "Settings" menu entries
1346 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::KeyBindings
)), menu
);
1347 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ConfigureToolbars
)), menu
);
1348 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Preferences
)), menu
);
1351 KMenu
* helpMenu
= new KMenu(i18nc("@action:inmenu", "Help"), menu
);
1352 connect(menu
, SIGNAL(aboutToHide()), helpMenu
, SLOT(deleteLater()));
1353 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::HelpContents
)));
1354 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::WhatsThis
)));
1355 helpMenu
->addSeparator();
1356 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ReportBug
)));
1357 helpMenu
->addSeparator();
1358 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
)));
1359 helpMenu
->addSeparator();
1360 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::AboutApp
)));
1361 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::AboutKDE
)));
1362 menu
->addMenu(helpMenu
);
1364 menu
->addSeparator();
1365 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ShowMenubar
)), menu
);
1368 void DolphinMainWindow::updateToolBar()
1370 if (!menuBar()->isVisible()) {
1371 createControlButton();
1375 void DolphinMainWindow::slotControlButtonDeleted()
1377 m_controlButton
= 0;
1378 m_updateToolBarTimer
->start();
1381 void DolphinMainWindow::slotPanelErrorMessage(const QString
& error
)
1383 activeViewContainer()->showMessage(error
, DolphinViewContainer::Error
);
1386 void DolphinMainWindow::slotPlaceActivated(const KUrl
& url
)
1388 DolphinViewContainer
* view
= activeViewContainer();
1390 if (view
->url() == url
) {
1391 // We can end up here if the user clicked a device in the Places Panel
1392 // which had been unmounted earlier, see https://bugs.kde.org/show_bug.cgi?id=161385.
1399 void DolphinMainWindow::restoreClosedTab(const KUrl
& primaryUrl
, const KUrl
& secondaryUrl
)
1401 openNewActivatedTab(primaryUrl
);
1403 if (!secondaryUrl
.isEmpty() && secondaryUrl
.isValid()) {
1404 const int index
= m_tabBar
->currentIndex();
1405 createSecondaryView(index
);
1406 setActiveViewContainer(m_viewTab
[index
].secondaryView
);
1407 m_viewTab
[index
].secondaryView
->setUrl(secondaryUrl
);
1411 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer
* viewContainer
)
1413 Q_ASSERT(viewContainer
);
1414 Q_ASSERT((viewContainer
== m_viewTab
[m_tabIndex
].primaryView
) ||
1415 (viewContainer
== m_viewTab
[m_tabIndex
].secondaryView
));
1416 if (m_activeViewContainer
== viewContainer
) {
1420 m_activeViewContainer
->setActive(false);
1421 m_activeViewContainer
= viewContainer
;
1423 // Activating the view container might trigger a recursive setActiveViewContainer() call
1424 // inside DolphinMainWindow::toggleActiveView() when having a split view. Temporary
1425 // disconnect the activated() signal in this case:
1426 disconnect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1427 m_activeViewContainer
->setActive(true);
1428 connect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1430 m_actionHandler
->setCurrentView(viewContainer
->view());
1433 updateEditActions();
1434 updatePasteAction();
1435 updateViewActions();
1438 const KUrl url
= m_activeViewContainer
->url();
1439 setUrlAsCaption(url
);
1440 if (m_viewTab
.count() > 1) {
1441 m_tabBar
->setTabText(m_tabIndex
, tabName(url
));
1442 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(KMimeType::iconNameForUrl(url
)));
1445 emit
urlChanged(url
);
1448 DolphinViewContainer
* DolphinMainWindow::createViewContainer(const KUrl
& url
, QWidget
* parent
)
1450 DolphinViewContainer
* container
= new DolphinViewContainer(url
, parent
);
1452 // The places-selector from the URL navigator should only be shown
1453 // if the places dock is invisible
1454 QDockWidget
* placesDock
= findChild
<QDockWidget
*>("placesDock");
1455 container
->urlNavigator()->setPlacesSelectorVisible(!placesDock
|| !placesDock
->isVisible());
1460 void DolphinMainWindow::setupActions()
1462 // setup 'File' menu
1463 m_newFileMenu
= new DolphinNewFileMenu(actionCollection(), this);
1464 KMenu
* menu
= m_newFileMenu
->menu();
1465 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1466 menu
->setIcon(KIcon("document-new"));
1467 m_newFileMenu
->setDelayed(false);
1468 connect(menu
, SIGNAL(aboutToShow()),
1469 this, SLOT(updateNewMenu()));
1471 KAction
* newWindow
= actionCollection()->addAction("new_window");
1472 newWindow
->setIcon(KIcon("window-new"));
1473 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1474 newWindow
->setShortcut(Qt::CTRL
| Qt::Key_N
);
1475 connect(newWindow
, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1477 KAction
* newTab
= actionCollection()->addAction("new_tab");
1478 newTab
->setIcon(KIcon("tab-new"));
1479 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1480 newTab
->setShortcut(KShortcut(Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
));
1481 connect(newTab
, SIGNAL(triggered()), this, SLOT(openNewTab()));
1483 KAction
* closeTab
= actionCollection()->addAction("close_tab");
1484 closeTab
->setIcon(KIcon("tab-close"));
1485 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1486 closeTab
->setShortcut(Qt::CTRL
| Qt::Key_W
);
1487 closeTab
->setEnabled(false);
1488 connect(closeTab
, SIGNAL(triggered()), this, SLOT(closeTab()));
1490 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1492 // setup 'Edit' menu
1493 KStandardAction::undo(this,
1495 actionCollection());
1497 // need to remove shift+del from cut action, else the shortcut for deletejob
1499 KAction
* cut
= KStandardAction::cut(this, SLOT(cut()), actionCollection());
1500 KShortcut cutShortcut
= cut
->shortcut();
1501 cutShortcut
.remove(Qt::SHIFT
| Qt::Key_Delete
, KShortcut::KeepEmpty
);
1502 cut
->setShortcut(cutShortcut
);
1503 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1504 KAction
* paste
= KStandardAction::paste(this, SLOT(paste()), actionCollection());
1505 // The text of the paste-action is modified dynamically by Dolphin
1506 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1507 // due to the long text, the text "Paste" is used:
1508 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1510 KStandardAction::find(this, SLOT(find()), actionCollection());
1512 KAction
* selectAll
= actionCollection()->addAction("select_all");
1513 selectAll
->setText(i18nc("@action:inmenu Edit", "Select All"));
1514 selectAll
->setShortcut(Qt::CTRL
| Qt::Key_A
);
1515 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
1517 KAction
* invertSelection
= actionCollection()->addAction("invert_selection");
1518 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1519 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1520 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
1522 // setup 'View' menu
1523 // (note that most of it is set up in DolphinViewActionHandler)
1525 KAction
* split
= actionCollection()->addAction("split_view");
1526 split
->setShortcut(Qt::Key_F3
);
1527 updateSplitAction();
1528 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1530 KAction
* reload
= actionCollection()->addAction("reload");
1531 reload
->setText(i18nc("@action:inmenu View", "Reload"));
1532 reload
->setShortcut(Qt::Key_F5
);
1533 reload
->setIcon(KIcon("view-refresh"));
1534 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
1536 KAction
* stop
= actionCollection()->addAction("stop");
1537 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1538 stop
->setToolTip(i18nc("@info", "Stop loading"));
1539 stop
->setIcon(KIcon("process-stop"));
1540 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
1542 KToggleAction
* editableLocation
= actionCollection()->add
<KToggleAction
>("editable_location");
1543 editableLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1544 editableLocation
->setShortcut(Qt::Key_F6
);
1545 connect(editableLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1547 KAction
* replaceLocation
= actionCollection()->addAction("replace_location");
1548 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1549 replaceLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
1550 connect(replaceLocation
, SIGNAL(triggered()), this, SLOT(replaceLocation()));
1553 KAction
* backAction
= KStandardAction::back(this, SLOT(goBack()), actionCollection());
1554 connect(backAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goBack(Qt::MouseButtons
)));
1555 KShortcut backShortcut
= backAction
->shortcut();
1556 backShortcut
.setAlternate(Qt::Key_Backspace
);
1557 backAction
->setShortcut(backShortcut
);
1559 DolphinRecentTabsMenu
* recentTabsMenu
= new DolphinRecentTabsMenu(this);
1560 actionCollection()->addAction("closed_tabs", recentTabsMenu
);
1561 connect(this, SIGNAL(rememberClosedTab(KUrl
,KUrl
)),
1562 recentTabsMenu
, SLOT(rememberClosedTab(KUrl
,KUrl
)));
1563 connect(recentTabsMenu
, SIGNAL(restoreClosedTab(KUrl
,KUrl
)),
1564 this, SLOT(restoreClosedTab(KUrl
,KUrl
)));
1566 KAction
* forwardAction
= KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1567 connect(forwardAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goForward(Qt::MouseButtons
)));
1569 KAction
* upAction
= KStandardAction::up(this, SLOT(goUp()), actionCollection());
1570 connect(upAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goUp(Qt::MouseButtons
)));
1572 KAction
* homeAction
= KStandardAction::home(this, SLOT(goHome()), actionCollection());
1573 connect(homeAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goHome(Qt::MouseButtons
)));
1575 // setup 'Tools' menu
1576 KAction
* showFilterBar
= actionCollection()->addAction("show_filter_bar");
1577 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1578 showFilterBar
->setIcon(KIcon("view-filter"));
1579 showFilterBar
->setShortcut(Qt::CTRL
| Qt::Key_I
);
1580 connect(showFilterBar
, SIGNAL(triggered()), this, SLOT(showFilterBar()));
1582 KAction
* compareFiles
= actionCollection()->addAction("compare_files");
1583 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1584 compareFiles
->setIcon(KIcon("kompare"));
1585 compareFiles
->setEnabled(false);
1586 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
1588 KAction
* openTerminal
= actionCollection()->addAction("open_terminal");
1589 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1590 openTerminal
->setIcon(KIcon("utilities-terminal"));
1591 openTerminal
->setShortcut(Qt::SHIFT
| Qt::Key_F4
);
1592 connect(openTerminal
, SIGNAL(triggered()), this, SLOT(openTerminal()));
1594 // setup 'Settings' menu
1595 KToggleAction
* showMenuBar
= KStandardAction::showMenubar(0, 0, actionCollection());
1596 connect(showMenuBar
, SIGNAL(triggered(bool)), // Fixes #286822
1597 this, SLOT(toggleShowMenuBar()), Qt::QueuedConnection
);
1598 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1600 // not in menu actions
1601 QList
<QKeySequence
> nextTabKeys
;
1602 nextTabKeys
.append(KStandardShortcut::tabNext().primary());
1603 nextTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::Key_Tab
));
1605 QList
<QKeySequence
> prevTabKeys
;
1606 prevTabKeys
.append(KStandardShortcut::tabPrev().primary());
1607 prevTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::SHIFT
| Qt::Key_Tab
));
1609 KAction
* activateNextTab
= actionCollection()->addAction("activate_next_tab");
1610 activateNextTab
->setIconText(i18nc("@action:inmenu", "Next Tab"));
1611 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1612 activateNextTab
->setEnabled(false);
1613 connect(activateNextTab
, SIGNAL(triggered()), SLOT(activateNextTab()));
1614 activateNextTab
->setShortcuts(QApplication::isRightToLeft() ? prevTabKeys
: nextTabKeys
);
1616 KAction
* activatePrevTab
= actionCollection()->addAction("activate_prev_tab");
1617 activatePrevTab
->setIconText(i18nc("@action:inmenu", "Previous Tab"));
1618 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1619 activatePrevTab
->setEnabled(false);
1620 connect(activatePrevTab
, SIGNAL(triggered()), SLOT(activatePrevTab()));
1621 activatePrevTab
->setShortcuts(QApplication::isRightToLeft() ? nextTabKeys
: prevTabKeys
);
1624 KAction
* openInNewTab
= actionCollection()->addAction("open_in_new_tab");
1625 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1626 openInNewTab
->setIcon(KIcon("tab-new"));
1627 connect(openInNewTab
, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1629 KAction
* openInNewTabs
= actionCollection()->addAction("open_in_new_tabs");
1630 openInNewTabs
->setText(i18nc("@action:inmenu", "Open in New Tabs"));
1631 openInNewTabs
->setIcon(KIcon("tab-new"));
1632 connect(openInNewTabs
, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1634 KAction
* openInNewWindow
= actionCollection()->addAction("open_in_new_window");
1635 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1636 openInNewWindow
->setIcon(KIcon("window-new"));
1637 connect(openInNewWindow
, SIGNAL(triggered()), this, SLOT(openInNewWindow()));
1640 void DolphinMainWindow::setupDockWidgets()
1642 const bool lock
= GeneralSettings::lockPanels();
1644 KDualAction
* lockLayoutAction
= actionCollection()->add
<KDualAction
>("lock_panels");
1645 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
1646 lockLayoutAction
->setActiveIcon(KIcon("object-unlocked"));
1647 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
1648 lockLayoutAction
->setInactiveIcon(KIcon("object-locked"));
1649 lockLayoutAction
->setActive(lock
);
1650 connect(lockLayoutAction
, SIGNAL(triggered()), this, SLOT(togglePanelLockState()));
1652 // Setup "Information"
1653 DolphinDockWidget
* infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
1654 infoDock
->setLocked(lock
);
1655 infoDock
->setObjectName("infoDock");
1656 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1657 Panel
* infoPanel
= new InformationPanel(infoDock
);
1658 infoPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1659 connect(infoPanel
, SIGNAL(urlActivated(KUrl
)), this, SLOT(handleUrl(KUrl
)));
1660 infoDock
->setWidget(infoPanel
);
1662 QAction
* infoAction
= infoDock
->toggleViewAction();
1663 createPanelAction(KIcon("dialog-information"), Qt::Key_F11
, infoAction
, "show_information_panel");
1665 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1666 connect(this, SIGNAL(urlChanged(KUrl
)),
1667 infoPanel
, SLOT(setUrl(KUrl
)));
1668 connect(this, SIGNAL(selectionChanged(KFileItemList
)),
1669 infoPanel
, SLOT(setSelection(KFileItemList
)));
1670 connect(this, SIGNAL(requestItemInfo(KFileItem
)),
1671 infoPanel
, SLOT(requestDelayedItemInfo(KFileItem
)));
1674 DolphinDockWidget
* foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
1675 foldersDock
->setLocked(lock
);
1676 foldersDock
->setObjectName("foldersDock");
1677 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1678 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1679 foldersPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1680 foldersDock
->setWidget(foldersPanel
);
1682 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1683 createPanelAction(KIcon("folder"), Qt::Key_F7
, foldersAction
, "show_folders_panel");
1685 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1686 connect(this, SIGNAL(urlChanged(KUrl
)),
1687 foldersPanel
, SLOT(setUrl(KUrl
)));
1688 connect(foldersPanel
, SIGNAL(folderActivated(KUrl
)),
1689 this, SLOT(changeUrl(KUrl
)));
1690 connect(foldersPanel
, SIGNAL(folderMiddleClicked(KUrl
)),
1691 this, SLOT(openNewTab(KUrl
)));
1692 connect(foldersPanel
, SIGNAL(errorMessage(QString
)),
1693 this, SLOT(slotPanelErrorMessage(QString
)));
1697 DolphinDockWidget
* terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1698 terminalDock
->setLocked(lock
);
1699 terminalDock
->setObjectName("terminalDock");
1700 terminalDock
->setAllowedAreas(Qt::TopDockWidgetArea
| Qt::BottomDockWidgetArea
);
1701 Panel
* terminalPanel
= new TerminalPanel(terminalDock
);
1702 terminalPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1703 terminalDock
->setWidget(terminalPanel
);
1705 connect(terminalPanel
, SIGNAL(hideTerminalPanel()), terminalDock
, SLOT(hide()));
1706 connect(terminalPanel
, SIGNAL(changeUrl(KUrl
)), this, SLOT(slotTerminalDirectoryChanged(KUrl
)));
1707 connect(terminalDock
, SIGNAL(visibilityChanged(bool)),
1708 terminalPanel
, SLOT(dockVisibilityChanged()));
1710 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1711 createPanelAction(KIcon("utilities-terminal"), Qt::Key_F4
, terminalAction
, "show_terminal_panel");
1713 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1714 connect(this, SIGNAL(urlChanged(KUrl
)),
1715 terminalPanel
, SLOT(setUrl(KUrl
)));
1718 if (GeneralSettings::version() < 200) {
1720 foldersDock
->hide();
1722 terminalDock
->hide();
1727 DolphinDockWidget
* placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
1728 placesDock
->setLocked(lock
);
1729 placesDock
->setObjectName("placesDock");
1730 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1732 PlacesPanel
* placesPanel
= new PlacesPanel(placesDock
);
1733 placesPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1734 placesDock
->setWidget(placesPanel
);
1736 QAction
* placesAction
= placesDock
->toggleViewAction();
1737 createPanelAction(KIcon("bookmarks"), Qt::Key_F9
, placesAction
, "show_places_panel");
1739 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1740 connect(placesPanel
, SIGNAL(placeActivated(KUrl
)),
1741 this, SLOT(slotPlaceActivated(KUrl
)));
1742 connect(placesPanel
, SIGNAL(placeMiddleClicked(KUrl
)),
1743 this, SLOT(openNewTab(KUrl
)));
1744 connect(placesPanel
, SIGNAL(errorMessage(QString
)),
1745 this, SLOT(slotPanelErrorMessage(QString
)));
1746 connect(this, SIGNAL(urlChanged(KUrl
)),
1747 placesPanel
, SLOT(setUrl(KUrl
)));
1748 connect(placesDock
, SIGNAL(visibilityChanged(bool)),
1749 this, SLOT(slotPlacesPanelVisibilityChanged(bool)));
1750 connect(this, SIGNAL(settingsChanged()),
1751 placesPanel
, SLOT(readSettings()));
1753 // Add actions into the "Panels" menu
1754 KActionMenu
* panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Panels"), this);
1755 actionCollection()->addAction("panels", panelsMenu
);
1756 panelsMenu
->setDelayed(false);
1757 const KActionCollection
* ac
= actionCollection();
1758 panelsMenu
->addAction(ac
->action("show_places_panel"));
1759 panelsMenu
->addAction(ac
->action("show_information_panel"));
1760 panelsMenu
->addAction(ac
->action("show_folders_panel"));
1762 panelsMenu
->addAction(ac
->action("show_terminal_panel"));
1764 panelsMenu
->addSeparator();
1765 panelsMenu
->addAction(lockLayoutAction
);
1768 void DolphinMainWindow::updateEditActions()
1770 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1771 if (list
.isEmpty()) {
1772 stateChanged("has_no_selection");
1774 stateChanged("has_selection");
1776 KActionCollection
* col
= actionCollection();
1777 QAction
* renameAction
= col
->action("rename");
1778 QAction
* moveToTrashAction
= col
->action("move_to_trash");
1779 QAction
* deleteAction
= col
->action("delete");
1780 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
1781 QAction
* deleteWithTrashShortcut
= col
->action("delete_shortcut"); // see DolphinViewActionHandler
1783 KFileItemListProperties
capabilities(list
);
1784 const bool enableMoveToTrash
= capabilities
.isLocal() && capabilities
.supportsMoving();
1786 renameAction
->setEnabled(capabilities
.supportsMoving());
1787 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1788 deleteAction
->setEnabled(capabilities
.supportsDeleting());
1789 deleteWithTrashShortcut
->setEnabled(capabilities
.supportsDeleting() && !enableMoveToTrash
);
1790 cutAction
->setEnabled(capabilities
.supportsMoving());
1794 void DolphinMainWindow::updateViewActions()
1796 m_actionHandler
->updateViewActions();
1798 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1799 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
1801 updateSplitAction();
1803 QAction
* editableLocactionAction
= actionCollection()->action("editable_location");
1804 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
1805 editableLocactionAction
->setChecked(urlNavigator
->isUrlEditable());
1808 void DolphinMainWindow::updateGoActions()
1810 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
1811 const KUrl currentUrl
= m_activeViewContainer
->url();
1812 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
1815 void DolphinMainWindow::createControlButton()
1817 if (m_controlButton
) {
1820 Q_ASSERT(!m_controlButton
);
1822 m_controlButton
= new QToolButton(this);
1823 m_controlButton
->setIcon(KIcon("applications-system"));
1824 m_controlButton
->setText(i18nc("@action", "Control"));
1825 m_controlButton
->setPopupMode(QToolButton::InstantPopup
);
1826 m_controlButton
->setToolButtonStyle(toolBar()->toolButtonStyle());
1828 KMenu
* controlMenu
= new KMenu(m_controlButton
);
1829 connect(controlMenu
, SIGNAL(aboutToShow()), this, SLOT(updateControlMenu()));
1831 m_controlButton
->setMenu(controlMenu
);
1833 toolBar()->addWidget(m_controlButton
);
1834 connect(toolBar(), SIGNAL(iconSizeChanged(QSize
)),
1835 m_controlButton
, SLOT(setIconSize(QSize
)));
1836 connect(toolBar(), SIGNAL(toolButtonStyleChanged(Qt::ToolButtonStyle
)),
1837 m_controlButton
, SLOT(setToolButtonStyle(Qt::ToolButtonStyle
)));
1839 // The added widgets are owned by the toolbar and may get deleted when e.g. the toolbar
1840 // gets edited. In this case we must add them again. The adding is done asynchronously by
1841 // m_updateToolBarTimer.
1842 connect(m_controlButton
, SIGNAL(destroyed()), this, SLOT(slotControlButtonDeleted()));
1843 m_updateToolBarTimer
= new QTimer(this);
1844 m_updateToolBarTimer
->setInterval(500);
1845 connect(m_updateToolBarTimer
, SIGNAL(timeout()), this, SLOT(updateToolBar()));
1848 void DolphinMainWindow::deleteControlButton()
1850 delete m_controlButton
;
1851 m_controlButton
= 0;
1853 delete m_updateToolBarTimer
;
1854 m_updateToolBarTimer
= 0;
1857 bool DolphinMainWindow::addActionToMenu(QAction
* action
, KMenu
* menu
)
1862 const KToolBar
* toolBarWidget
= toolBar();
1863 foreach (const QWidget
* widget
, action
->associatedWidgets()) {
1864 if (widget
== toolBarWidget
) {
1869 menu
->addAction(action
);
1873 void DolphinMainWindow::refreshViews()
1875 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
1877 // remember the current active view, as because of
1878 // the refreshing the active view might change to
1879 // the secondary view
1880 DolphinViewContainer
* activeViewContainer
= m_activeViewContainer
;
1882 const int tabCount
= m_viewTab
.count();
1883 for (int i
= 0; i
< tabCount
; ++i
) {
1884 m_viewTab
[i
].primaryView
->readSettings();
1885 if (m_viewTab
[i
].secondaryView
) {
1886 m_viewTab
[i
].secondaryView
->readSettings();
1890 setActiveViewContainer(activeViewContainer
);
1892 if (GeneralSettings::modifiedStartupSettings()) {
1893 // The startup settings have been changed by the user (see bug #254947).
1894 // Synchronize the split-view setting with the active view:
1895 const bool splitView
= GeneralSettings::splitView();
1896 const ViewTab
& activeTab
= m_viewTab
[m_tabIndex
];
1897 const bool toggle
= ( splitView
&& !activeTab
.secondaryView
)
1898 || (!splitView
&& activeTab
.secondaryView
);
1904 emit
settingsChanged();
1907 void DolphinMainWindow::clearStatusBar()
1909 m_activeViewContainer
->statusBar()->resetToDefaultText();
1912 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
1914 connect(container
, SIGNAL(showFilterBarChanged(bool)),
1915 this, SLOT(updateFilterBarAction(bool)));
1916 connect(container
, SIGNAL(writeStateChanged(bool)),
1917 this, SLOT(slotWriteStateChanged(bool)));
1919 DolphinView
* view
= container
->view();
1920 connect(view
, SIGNAL(selectionChanged(KFileItemList
)),
1921 this, SLOT(slotSelectionChanged(KFileItemList
)));
1922 connect(view
, SIGNAL(requestItemInfo(KFileItem
)),
1923 this, SLOT(slotRequestItemInfo(KFileItem
)));
1924 connect(view
, SIGNAL(activated()),
1925 this, SLOT(toggleActiveView()));
1926 connect(view
, SIGNAL(tabRequested(KUrl
)),
1927 this, SLOT(openNewTab(KUrl
)));
1928 connect(view
, SIGNAL(requestContextMenu(QPoint
,KFileItem
,KUrl
,QList
<QAction
*>)),
1929 this, SLOT(openContextMenu(QPoint
,KFileItem
,KUrl
,QList
<QAction
*>)));
1930 connect(view
, SIGNAL(directoryLoadingStarted()),
1931 this, SLOT(enableStopAction()));
1932 connect(view
, SIGNAL(directoryLoadingCompleted()),
1933 this, SLOT(disableStopAction()));
1934 connect(view
, SIGNAL(goBackRequested()),
1935 this, SLOT(goBack()));
1936 connect(view
, SIGNAL(goForwardRequested()),
1937 this, SLOT(goForward()));
1939 const KUrlNavigator
* navigator
= container
->urlNavigator();
1940 connect(navigator
, SIGNAL(urlChanged(KUrl
)),
1941 this, SLOT(changeUrl(KUrl
)));
1942 connect(navigator
, SIGNAL(historyChanged()),
1943 this, SLOT(updateHistory()));
1944 connect(navigator
, SIGNAL(editableStateChanged(bool)),
1945 this, SLOT(slotEditableStateChanged(bool)));
1946 connect(navigator
, SIGNAL(tabRequested(KUrl
)),
1947 this, SLOT(openNewTab(KUrl
)));
1950 void DolphinMainWindow::updateSplitAction()
1952 QAction
* splitAction
= actionCollection()->action("split_view");
1953 if (m_viewTab
[m_tabIndex
].secondaryView
) {
1954 if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
1955 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
1956 splitAction
->setToolTip(i18nc("@info", "Close right view"));
1957 splitAction
->setIcon(KIcon("view-right-close"));
1959 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
1960 splitAction
->setToolTip(i18nc("@info", "Close left view"));
1961 splitAction
->setIcon(KIcon("view-left-close"));
1964 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
1965 splitAction
->setToolTip(i18nc("@info", "Split view"));
1966 splitAction
->setIcon(KIcon("view-right-new"));
1970 QString
DolphinMainWindow::tabName(const KUrl
& url
) const
1973 if (url
.equals(KUrl("file:///"))) {
1976 name
= url
.fileName();
1977 if (name
.isEmpty()) {
1978 name
= url
.protocol();
1980 // Make sure that a '&' inside the directory name is displayed correctly
1981 // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
1982 name
.replace('&', "&&");
1988 bool DolphinMainWindow::isKompareInstalled() const
1990 static bool initialized
= false;
1991 static bool installed
= false;
1993 // TODO: maybe replace this approach later by using a menu
1994 // plugin like kdiff3plugin.cpp
1995 installed
= !KGlobal::dirs()->findExe("kompare").isEmpty();
2001 void DolphinMainWindow::createSecondaryView(int tabIndex
)
2003 ViewTab
& viewTab
= m_viewTab
[tabIndex
];
2005 QSplitter
* splitter
= viewTab
.splitter
;
2006 const int newWidth
= (viewTab
.primaryView
->width() - splitter
->handleWidth()) / 2;
2008 const DolphinView
* view
= viewTab
.primaryView
->view();
2009 // The final parent of the new view container will be set by adding it
2010 // to the splitter. However, we must make sure that the DolphinMainWindow
2011 // is a parent of the view container already when it is constructed
2012 // because this enables the container's KFileItemModel to assign its
2013 // dir lister to the right main window. The dir lister can then cache
2014 // authentication data.
2015 viewTab
.secondaryView
= createViewContainer(view
->url(), this);
2016 splitter
->addWidget(viewTab
.secondaryView
);
2017 splitter
->setSizes(QList
<int>() << newWidth
<< newWidth
);
2019 connectViewSignals(viewTab
.secondaryView
);
2020 viewTab
.secondaryView
->setActive(false);
2021 viewTab
.secondaryView
->resize(newWidth
, viewTab
.primaryView
->height());
2022 viewTab
.secondaryView
->show();
2025 QString
DolphinMainWindow::tabProperty(const QString
& property
, int tabIndex
) const
2027 return "Tab " + QString::number(tabIndex
) + ' ' + property
;
2030 void DolphinMainWindow::setUrlAsCaption(const KUrl
& url
)
2033 if (!url
.isLocalFile()) {
2034 caption
.append(url
.protocol() + " - ");
2035 if (url
.hasHost()) {
2036 caption
.append(url
.host() + " - ");
2040 const QString fileName
= url
.fileName().isEmpty() ? "/" : url
.fileName();
2041 caption
.append(fileName
);
2043 setCaption(caption
);
2046 QString
DolphinMainWindow::squeezedText(const QString
& text
) const
2048 const QFontMetrics fm
= fontMetrics();
2049 return fm
.elidedText(text
, Qt::ElideMiddle
, fm
.maxWidth() * 10);
2052 void DolphinMainWindow::createPanelAction(const KIcon
& icon
,
2053 const QKeySequence
& shortcut
,
2054 QAction
* dockAction
,
2055 const QString
& actionName
)
2057 KAction
* panelAction
= actionCollection()->addAction(actionName
);
2058 panelAction
->setCheckable(true);
2059 panelAction
->setChecked(dockAction
->isChecked());
2060 panelAction
->setText(dockAction
->text());
2061 panelAction
->setIcon(icon
);
2062 panelAction
->setShortcut(shortcut
);
2064 connect(panelAction
, SIGNAL(triggered()), dockAction
, SLOT(trigger()));
2065 connect(dockAction
, SIGNAL(toggled(bool)), panelAction
, SLOT(setChecked(bool)));
2068 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
2069 KIO::FileUndoManager::UiInterface()
2073 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2077 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
2079 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
2081 DolphinViewContainer
* container
= mainWin
->activeViewContainer();
2082 container
->showMessage(job
->errorString(), DolphinViewContainer::Error
);
2084 KIO::FileUndoManager::UiInterface::jobError(job
);
2088 #include "dolphinmainwindow.moc"