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"
38 #include "views/dolphinnewfilemenuobserver.h"
41 #include "panels/terminal/terminalpanel.h"
44 #include "dolphin_generalsettings.h"
46 #include <KAcceleratorManager>
48 #include <KActionCollection>
49 #include <KActionMenu>
51 #include <KDesktopFile>
52 #include <kdeversion.h>
53 #include <kdualaction.h>
54 #include <KFileDialog>
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 <QDesktopWidget>
84 #include <QDBusMessage>
87 #include <QToolButton>
91 // Used for GeneralSettings::version() to determine whether
92 // an updated version of Dolphin is running.
93 const int CurrentDolphinVersion
= 200;
97 * Remembers the tab configuration if a tab has been closed.
98 * Each closed tab can be restored by the menu
99 * "Go -> Recently Closed Tabs".
107 Q_DECLARE_METATYPE(ClosedTab
)
109 DolphinMainWindow::DolphinMainWindow() :
113 m_activeViewContainer(0),
114 m_centralWidgetLayout(0),
121 m_updateToolBarTimer(0),
122 m_lastHandleUrlStatJob(0)
124 setObjectName("Dolphin#");
126 m_viewTab
.append(ViewTab());
127 ViewTab
& viewTab
= m_viewTab
[m_tabIndex
];
128 viewTab
.wasActive
= true; // The first opened tab is automatically active
130 connect(&DolphinNewFileMenuObserver::instance(), SIGNAL(errorMessage(QString
)),
131 this, SLOT(showErrorMessage(QString
)));
133 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
134 undoManager
->setUiInterface(new UndoUiInterface());
136 connect(undoManager
, SIGNAL(undoAvailable(bool)),
137 this, SLOT(slotUndoAvailable(bool)));
138 connect(undoManager
, SIGNAL(undoTextChanged(QString
)),
139 this, SLOT(slotUndoTextChanged(QString
)));
140 connect(undoManager
, SIGNAL(jobRecordingStarted(CommandType
)),
141 this, SLOT(clearStatusBar()));
142 connect(undoManager
, SIGNAL(jobRecordingFinished(CommandType
)),
143 this, SLOT(showCommand(CommandType
)));
145 GeneralSettings
* generalSettings
= GeneralSettings::self();
146 const bool firstRun
= (generalSettings
->version() < 200);
148 generalSettings
->setViewPropsTimestamp(QDateTime::currentDateTime());
151 setAcceptDrops(true);
153 viewTab
.splitter
= new QSplitter(this);
154 viewTab
.splitter
->setChildrenCollapsible(false);
158 const KUrl
homeUrl(generalSettings
->homeUrl());
159 setUrlAsCaption(homeUrl
);
160 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
161 connect(m_actionHandler
, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
162 connect(m_actionHandler
, SIGNAL(createDirectory()), SLOT(createDirectory()));
164 viewTab
.primaryView
= createViewContainer(homeUrl
, viewTab
.splitter
);
166 m_activeViewContainer
= viewTab
.primaryView
;
167 connectViewSignals(m_activeViewContainer
);
168 DolphinView
* view
= m_activeViewContainer
->view();
169 m_activeViewContainer
->show();
170 m_actionHandler
->setCurrentView(view
);
172 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
173 connect(this, SIGNAL(urlChanged(KUrl
)),
174 m_remoteEncoding
, SLOT(slotAboutToOpenUrl()));
176 m_tabBar
= new KTabBar(this);
177 m_tabBar
->setMovable(true);
178 m_tabBar
->setTabsClosable(true);
179 connect(m_tabBar
, SIGNAL(currentChanged(int)),
180 this, SLOT(setActiveTab(int)));
181 connect(m_tabBar
, SIGNAL(tabCloseRequested(int)),
182 this, SLOT(closeTab(int)));
183 connect(m_tabBar
, SIGNAL(contextMenu(int,QPoint
)),
184 this, SLOT(openTabContextMenu(int,QPoint
)));
185 connect(m_tabBar
, SIGNAL(newTabRequest()),
186 this, SLOT(openNewTab()));
187 connect(m_tabBar
, SIGNAL(testCanDecode(const QDragMoveEvent
*,bool&)),
188 this, SLOT(slotTestCanDecode(const QDragMoveEvent
*,bool&)));
189 connect(m_tabBar
, SIGNAL(mouseMiddleClick(int)),
190 this, SLOT(closeTab(int)));
191 connect(m_tabBar
, SIGNAL(tabMoved(int,int)),
192 this, SLOT(slotTabMoved(int,int)));
193 connect(m_tabBar
, SIGNAL(receivedDropEvent(int,QDropEvent
*)),
194 this, SLOT(tabDropEvent(int,QDropEvent
*)));
196 m_tabBar
->blockSignals(true); // signals get unblocked after at least 2 tabs are open
198 QWidget
* centralWidget
= new QWidget(this);
199 m_centralWidgetLayout
= new QVBoxLayout(centralWidget
);
200 m_centralWidgetLayout
->setSpacing(0);
201 m_centralWidgetLayout
->setMargin(0);
202 m_centralWidgetLayout
->addWidget(m_tabBar
);
203 m_centralWidgetLayout
->addWidget(viewTab
.splitter
, 1);
205 setCentralWidget(centralWidget
);
207 emit
urlChanged(homeUrl
);
209 setupGUI(Keys
| Save
| Create
| ToolBar
);
210 stateChanged("new_file");
212 QClipboard
* clipboard
= QApplication::clipboard();
213 connect(clipboard
, SIGNAL(dataChanged()),
214 this, SLOT(updatePasteAction()));
216 if (generalSettings
->splitView()) {
223 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
224 showFilterBarAction
->setChecked(generalSettings
->filterBar());
227 menuBar()->setVisible(false);
228 // Assure a proper default size if Dolphin runs the first time
232 const bool showMenu
= !menuBar()->isHidden();
233 QAction
* showMenuBarAction
= actionCollection()->action(KStandardAction::name(KStandardAction::ShowMenubar
));
234 showMenuBarAction
->setChecked(showMenu
); // workaround for bug #171080
236 createControlButton();
240 DolphinMainWindow::~DolphinMainWindow()
244 void DolphinMainWindow::openDirectories(const QList
<KUrl
>& dirs
)
246 if (dirs
.isEmpty()) {
250 if (dirs
.count() == 1) {
251 m_activeViewContainer
->setUrl(dirs
.first());
255 const int oldOpenTabsCount
= m_viewTab
.count();
257 const bool hasSplitView
= GeneralSettings::splitView();
259 // Open each directory inside a new tab. If the "split view" option has been enabled,
260 // always show two directories within one tab.
261 QList
<KUrl
>::const_iterator it
= dirs
.begin();
262 while (it
!= dirs
.end()) {
266 if (hasSplitView
&& (it
!= dirs
.end())) {
267 const int tabIndex
= m_viewTab
.count() - 1;
268 m_viewTab
[tabIndex
].secondaryView
->setUrl(*it
);
273 // Remove the previously opened tabs
274 for (int i
= 0; i
< oldOpenTabsCount
; ++i
) {
279 void DolphinMainWindow::openFiles(const QList
<KUrl
>& files
)
281 if (files
.isEmpty()) {
285 // Get all distinct directories from 'files' and open a tab
286 // for each directory. If the "split view" option is enabled, two
287 // directories are shown inside one tab (see openDirectories()).
289 foreach (const KUrl
& url
, files
) {
290 const KUrl
dir(url
.directory());
291 if (!dirs
.contains(dir
)) {
296 openDirectories(dirs
);
298 // Select the files. Although the files can be split between several
299 // tabs, there is no need to split 'files' accordingly, as
300 // the DolphinView will just ignore invalid selections.
301 const int tabCount
= m_viewTab
.count();
302 for (int i
= 0; i
< tabCount
; ++i
) {
303 m_viewTab
[i
].primaryView
->view()->markUrlsAsSelected(files
);
304 m_viewTab
[i
].primaryView
->view()->markUrlAsCurrent(files
.at(0));
305 if (m_viewTab
[i
].secondaryView
) {
306 m_viewTab
[i
].secondaryView
->view()->markUrlsAsSelected(files
);
307 m_viewTab
[i
].secondaryView
->view()->markUrlAsCurrent(files
.at(0));
312 void DolphinMainWindow::showCommand(CommandType command
)
314 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
316 case KIO::FileUndoManager::Copy
:
317 statusBar
->setText(i18nc("@info:status", "Successfully copied."));
319 case KIO::FileUndoManager::Move
:
320 statusBar
->setText(i18nc("@info:status", "Successfully moved."));
322 case KIO::FileUndoManager::Link
:
323 statusBar
->setText(i18nc("@info:status", "Successfully linked."));
325 case KIO::FileUndoManager::Trash
:
326 statusBar
->setText(i18nc("@info:status", "Successfully moved to trash."));
328 case KIO::FileUndoManager::Rename
:
329 statusBar
->setText(i18nc("@info:status", "Successfully renamed."));
332 case KIO::FileUndoManager::Mkdir
:
333 statusBar
->setText(i18nc("@info:status", "Created folder."));
341 void DolphinMainWindow::pasteIntoFolder()
343 m_activeViewContainer
->view()->pasteIntoFolder();
346 void DolphinMainWindow::changeUrl(const KUrl
& url
)
348 if (!KProtocolManager::supportsListing(url
)) {
349 // The URL navigator only checks for validity, not
350 // if the URL can be listed. An error message is
351 // shown due to DolphinViewContainer::restoreView().
355 DolphinViewContainer
* view
= activeViewContainer();
361 setUrlAsCaption(url
);
362 if (m_viewTab
.count() > 1) {
363 m_tabBar
->setTabText(m_tabIndex
, squeezedText(tabName(m_activeViewContainer
->url())));
365 const QString iconName
= KMimeType::iconNameForUrl(url
);
366 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(iconName
));
367 emit
urlChanged(url
);
371 void DolphinMainWindow::slotTerminalDirectoryChanged(const KUrl
& url
)
373 m_activeViewContainer
->setAutoGrabFocus(false);
375 m_activeViewContainer
->setAutoGrabFocus(true);
378 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
380 KToggleAction
* editableLocationAction
=
381 static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
382 editableLocationAction
->setChecked(editable
);
385 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
389 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
390 int selectedUrlsCount
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedItemsCount();
391 if (m_viewTab
[m_tabIndex
].secondaryView
) {
392 selectedUrlsCount
+= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItemsCount();
395 QAction
* compareFilesAction
= actionCollection()->action("compare_files");
396 if (selectedUrlsCount
== 2) {
397 compareFilesAction
->setEnabled(isKompareInstalled());
399 compareFilesAction
->setEnabled(false);
402 emit
selectionChanged(selection
);
405 void DolphinMainWindow::slotRequestItemInfo(const KFileItem
& item
)
407 emit
requestItemInfo(item
);
410 void DolphinMainWindow::updateHistory()
412 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
413 const int index
= urlNavigator
->historyIndex();
415 QAction
* backAction
= actionCollection()->action("go_back");
417 backAction
->setToolTip(i18nc("@info", "Go back"));
418 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
421 QAction
* forwardAction
= actionCollection()->action("go_forward");
423 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
424 forwardAction
->setEnabled(index
> 0);
428 void DolphinMainWindow::updateFilterBarAction(bool show
)
430 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
431 showFilterBarAction
->setChecked(show
);
434 void DolphinMainWindow::openNewMainWindow()
436 KRun::run("dolphin %u", KUrl::List(), this);
439 void DolphinMainWindow::openNewTab()
441 const bool isUrlEditable
= m_activeViewContainer
->urlNavigator()->isUrlEditable();
443 openNewTab(m_activeViewContainer
->url());
444 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
446 // The URL navigator of the new tab should have the same editable state
447 // as the current tab
448 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
449 navigator
->setUrlEditable(isUrlEditable
);
452 // If a new tab is opened and the URL is editable, assure that
453 // the user can edit the URL without manually setting the focus
454 navigator
->setFocus();
458 void DolphinMainWindow::openNewTab(const KUrl
& url
)
460 QWidget
* focusWidget
= QApplication::focusWidget();
462 if (m_viewTab
.count() == 1) {
463 // Only one view is open currently and hence no tab is shown at
464 // all. Before creating a tab for 'url', provide a tab for the current URL.
465 const KUrl currentUrl
= m_activeViewContainer
->url();
466 m_tabBar
->addTab(KIcon(KMimeType::iconNameForUrl(currentUrl
)),
467 squeezedText(tabName(currentUrl
)));
468 m_tabBar
->blockSignals(false);
471 m_tabBar
->addTab(KIcon(KMimeType::iconNameForUrl(url
)),
472 squeezedText(tabName(url
)));
475 viewTab
.splitter
= new QSplitter(this);
476 viewTab
.splitter
->setChildrenCollapsible(false);
477 viewTab
.primaryView
= createViewContainer(url
, viewTab
.splitter
);
478 viewTab
.primaryView
->setActive(false);
479 connectViewSignals(viewTab
.primaryView
);
481 m_viewTab
.append(viewTab
);
483 actionCollection()->action("close_tab")->setEnabled(true);
485 // Provide a split view, if the startup settings are set this way
486 if (GeneralSettings::splitView()) {
487 const int newTabIndex
= m_viewTab
.count() - 1;
488 createSecondaryView(newTabIndex
);
489 m_viewTab
[newTabIndex
].secondaryView
->setActive(true);
490 m_viewTab
[newTabIndex
].isPrimaryViewActive
= false;
494 // The DolphinViewContainer grabbed the keyboard focus. As the tab is opened
495 // in background, assure that the previous focused widget gets the focus back.
496 focusWidget
->setFocus();
500 void DolphinMainWindow::openNewActivatedTab(const KUrl
& url
)
503 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
506 void DolphinMainWindow::activateNextTab()
508 if (m_viewTab
.count() >= 2) {
509 const int tabIndex
= (m_tabBar
->currentIndex() + 1) % m_tabBar
->count();
510 m_tabBar
->setCurrentIndex(tabIndex
);
514 void DolphinMainWindow::activatePrevTab()
516 if (m_viewTab
.count() >= 2) {
517 int tabIndex
= m_tabBar
->currentIndex() - 1;
518 if (tabIndex
== -1) {
519 tabIndex
= m_tabBar
->count() - 1;
521 m_tabBar
->setCurrentIndex(tabIndex
);
525 void DolphinMainWindow::openInNewTab()
527 const KFileItemList
& list
= m_activeViewContainer
->view()->selectedItems();
528 if (list
.isEmpty()) {
529 openNewTab(m_activeViewContainer
->url());
531 foreach (const KFileItem
& item
, list
) {
532 const KUrl
& url
= DolphinView::openItemAsFolderUrl(item
);
533 if (!url
.isEmpty()) {
540 void DolphinMainWindow::openInNewWindow()
544 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
545 if (list
.isEmpty()) {
546 newWindowUrl
= m_activeViewContainer
->url();
547 } else if (list
.count() == 1) {
548 const KFileItem
& item
= list
.first();
549 newWindowUrl
= DolphinView::openItemAsFolderUrl(item
);
552 if (!newWindowUrl
.isEmpty()) {
553 KRun::run("dolphin %u", KUrl::List() << newWindowUrl
, this);
557 void DolphinMainWindow::toggleActiveView()
559 if (!m_viewTab
[m_tabIndex
].secondaryView
) {
560 // only one view is available
564 Q_ASSERT(m_activeViewContainer
);
565 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
567 DolphinViewContainer
* left
= m_viewTab
[m_tabIndex
].primaryView
;
568 DolphinViewContainer
* right
= m_viewTab
[m_tabIndex
].secondaryView
;
569 setActiveViewContainer(m_activeViewContainer
== right
? left
: right
);
572 void DolphinMainWindow::showEvent(QShowEvent
* event
)
574 KXmlGuiWindow::showEvent(event
);
575 if (!event
->spontaneous()) {
576 m_activeViewContainer
->view()->setFocus();
580 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
582 // Find out if Dolphin is closed directly by the user or
583 // by the session manager because the session is closed
584 bool closedByUser
= true;
585 DolphinApplication
*application
= qobject_cast
<DolphinApplication
*>(qApp
);
586 if (application
&& application
->sessionSaving()) {
587 closedByUser
= false;
590 if (m_viewTab
.count() > 1 && GeneralSettings::confirmClosingMultipleTabs() && closedByUser
) {
591 // Ask the user if he really wants to quit and close all tabs.
592 // Open a confirmation dialog with 3 buttons:
593 // KDialog::Yes -> Quit
594 // KDialog::No -> Close only the current tab
595 // KDialog::Cancel -> do nothing
596 KDialog
*dialog
= new KDialog(this, Qt::Dialog
);
597 dialog
->setCaption(i18nc("@title:window", "Confirmation"));
598 dialog
->setButtons(KDialog::Yes
| KDialog::No
| KDialog::Cancel
);
599 dialog
->setModal(true);
600 dialog
->setButtonGuiItem(KDialog::Yes
, KStandardGuiItem::quit());
601 dialog
->setButtonGuiItem(KDialog::No
, KGuiItem(i18n("C&lose Current Tab"), KIcon("tab-close")));
602 dialog
->setButtonGuiItem(KDialog::Cancel
, KStandardGuiItem::cancel());
603 dialog
->setDefaultButton(KDialog::Yes
);
605 bool doNotAskAgainCheckboxResult
= false;
607 const int result
= KMessageBox::createKMessageBox(dialog
,
608 QMessageBox::Warning
,
609 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
611 i18n("Do not ask again"),
612 &doNotAskAgainCheckboxResult
,
613 KMessageBox::Notify
);
615 if (doNotAskAgainCheckboxResult
) {
616 GeneralSettings::setConfirmClosingMultipleTabs(false);
624 // Close only the current tab
632 GeneralSettings::setVersion(CurrentDolphinVersion
);
633 GeneralSettings::self()->writeConfig();
635 KXmlGuiWindow::closeEvent(event
);
638 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
640 const int tabCount
= m_viewTab
.count();
641 group
.writeEntry("Tab Count", tabCount
);
642 group
.writeEntry("Active Tab Index", m_tabBar
->currentIndex());
644 for (int i
= 0; i
< tabCount
; ++i
) {
645 const DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
646 group
.writeEntry(tabProperty("Primary URL", i
), cont
->url().url());
647 group
.writeEntry(tabProperty("Primary Editable", i
),
648 cont
->urlNavigator()->isUrlEditable());
650 cont
= m_viewTab
[i
].secondaryView
;
652 group
.writeEntry(tabProperty("Secondary URL", i
), cont
->url().url());
653 group
.writeEntry(tabProperty("Secondary Editable", i
),
654 cont
->urlNavigator()->isUrlEditable());
659 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
661 const int tabCount
= group
.readEntry("Tab Count", 1);
662 for (int i
= 0; i
< tabCount
; ++i
) {
663 DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
665 cont
->setUrl(group
.readEntry(tabProperty("Primary URL", i
)));
666 const bool editable
= group
.readEntry(tabProperty("Primary Editable", i
), false);
667 cont
->urlNavigator()->setUrlEditable(editable
);
669 cont
= m_viewTab
[i
].secondaryView
;
670 const QString secondaryUrl
= group
.readEntry(tabProperty("Secondary URL", i
));
671 if (!secondaryUrl
.isEmpty()) {
673 // a secondary view should be shown, but no one is available
674 // currently -> create a new view
676 cont
= m_viewTab
[i
].secondaryView
;
680 cont
->setUrl(secondaryUrl
);
681 const bool editable
= group
.readEntry(tabProperty("Secondary Editable", i
), false);
682 cont
->urlNavigator()->setUrlEditable(editable
);
684 // no secondary view should be shown, but the default setting shows
685 // one already -> close the view
689 // openNewTab() needs to be called only tabCount - 1 times
690 if (i
!= tabCount
- 1) {
695 const int index
= group
.readEntry("Active Tab Index", 0);
696 m_tabBar
->setCurrentIndex(index
);
699 void DolphinMainWindow::updateNewMenu()
701 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
702 m_newFileMenu
->checkUpToDate();
703 m_newFileMenu
->setPopupFiles(activeViewContainer()->url());
706 void DolphinMainWindow::createDirectory()
708 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
709 m_newFileMenu
->setPopupFiles(activeViewContainer()->url());
710 m_newFileMenu
->createDirectory();
713 void DolphinMainWindow::quit()
718 void DolphinMainWindow::showErrorMessage(const QString
& message
)
720 m_activeViewContainer
->showMessage(message
, DolphinViewContainer::Error
);
723 void DolphinMainWindow::slotUndoAvailable(bool available
)
725 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
727 undoAction
->setEnabled(available
);
731 void DolphinMainWindow::restoreClosedTab(QAction
* action
)
733 if (action
->data().toBool()) {
734 // clear all actions except the "Empty Recently Closed Tabs"
735 // action and the separator
736 QList
<QAction
*> actions
= m_recentTabsMenu
->menu()->actions();
737 const int count
= actions
.size();
738 for (int i
= 2; i
< count
; ++i
) {
739 m_recentTabsMenu
->menu()->removeAction(actions
.at(i
));
742 const ClosedTab closedTab
= action
->data().value
<ClosedTab
>();
743 openNewTab(closedTab
.primaryUrl
);
744 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
746 if (closedTab
.isSplit
) {
747 // create secondary view
749 m_viewTab
[m_tabIndex
].secondaryView
->setUrl(closedTab
.secondaryUrl
);
752 m_recentTabsMenu
->removeAction(action
);
755 if (m_recentTabsMenu
->menu()->actions().count() == 2) {
756 m_recentTabsMenu
->setEnabled(false);
760 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
762 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
764 undoAction
->setText(text
);
768 void DolphinMainWindow::undo()
771 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
772 KIO::FileUndoManager::self()->undo();
775 void DolphinMainWindow::cut()
777 m_activeViewContainer
->view()->cutSelectedItems();
780 void DolphinMainWindow::copy()
782 m_activeViewContainer
->view()->copySelectedItems();
785 void DolphinMainWindow::paste()
787 m_activeViewContainer
->view()->paste();
790 void DolphinMainWindow::find()
792 m_activeViewContainer
->setSearchModeEnabled(true);
795 void DolphinMainWindow::updatePasteAction()
797 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
798 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
799 pasteAction
->setEnabled(pasteInfo
.first
);
800 pasteAction
->setText(pasteInfo
.second
);
803 void DolphinMainWindow::selectAll()
807 // if the URL navigator is editable and focused, select the whole
808 // URL instead of all items of the view
810 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
811 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit(); // krazy:exclude=qclasses
812 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
813 lineEdit
->hasFocus();
815 lineEdit
->selectAll();
817 m_activeViewContainer
->view()->selectAll();
821 void DolphinMainWindow::invertSelection()
824 m_activeViewContainer
->view()->invertSelection();
827 void DolphinMainWindow::toggleSplitView()
829 if (!m_viewTab
[m_tabIndex
].secondaryView
) {
830 createSecondaryView(m_tabIndex
);
831 setActiveViewContainer(m_viewTab
[m_tabIndex
].secondaryView
);
832 } else if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
833 // remove secondary view
834 m_viewTab
[m_tabIndex
].secondaryView
->close();
835 m_viewTab
[m_tabIndex
].secondaryView
->deleteLater();
836 m_viewTab
[m_tabIndex
].secondaryView
= 0;
838 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
840 // The primary view is active and should be closed. Hence from a users point of view
841 // the content of the secondary view should be moved to the primary view.
842 // From an implementation point of view it is more efficient to close
843 // the primary view and exchange the internal pointers afterwards.
845 m_viewTab
[m_tabIndex
].primaryView
->close();
846 m_viewTab
[m_tabIndex
].primaryView
->deleteLater();
847 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
848 m_viewTab
[m_tabIndex
].secondaryView
= 0;
850 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
856 void DolphinMainWindow::reloadView()
859 m_activeViewContainer
->view()->reload();
862 void DolphinMainWindow::stopLoading()
864 m_activeViewContainer
->view()->stopLoading();
867 void DolphinMainWindow::enableStopAction()
869 actionCollection()->action("stop")->setEnabled(true);
872 void DolphinMainWindow::disableStopAction()
874 actionCollection()->action("stop")->setEnabled(false);
877 void DolphinMainWindow::showFilterBar()
879 m_activeViewContainer
->setFilterBarVisible(true);
882 void DolphinMainWindow::toggleEditLocation()
886 QAction
* action
= actionCollection()->action("editable_location");
887 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
888 urlNavigator
->setUrlEditable(action
->isChecked());
891 void DolphinMainWindow::replaceLocation()
893 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
894 navigator
->setUrlEditable(true);
895 navigator
->setFocus();
897 // select the whole text of the combo box editor
898 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit(); // krazy:exclude=qclasses
899 lineEdit
->selectAll();
902 void DolphinMainWindow::togglePanelLockState()
904 const bool newLockState
= !GeneralSettings::lockPanels();
905 foreach (QObject
* child
, children()) {
906 DolphinDockWidget
* dock
= qobject_cast
<DolphinDockWidget
*>(child
);
908 dock
->setLocked(newLockState
);
912 GeneralSettings::setLockPanels(newLockState
);
915 void DolphinMainWindow::slotPlacesPanelVisibilityChanged(bool visible
)
917 const int tabCount
= m_viewTab
.count();
918 for (int i
= 0; i
< tabCount
; ++i
) {
919 ViewTab
& tab
= m_viewTab
[i
];
920 Q_ASSERT(tab
.primaryView
);
921 tab
.primaryView
->urlNavigator()->setPlacesSelectorVisible(!visible
);
922 if (tab
.secondaryView
) {
923 tab
.secondaryView
->urlNavigator()->setPlacesSelectorVisible(!visible
);
928 void DolphinMainWindow::goBack()
930 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
931 urlNavigator
->goBack();
933 if (urlNavigator
->locationState().isEmpty()) {
934 // An empty location state indicates a redirection URL,
935 // which must be skipped too
936 urlNavigator
->goBack();
940 void DolphinMainWindow::goForward()
942 m_activeViewContainer
->urlNavigator()->goForward();
945 void DolphinMainWindow::goUp()
947 m_activeViewContainer
->urlNavigator()->goUp();
950 void DolphinMainWindow::goHome()
952 m_activeViewContainer
->urlNavigator()->goHome();
955 void DolphinMainWindow::goBack(Qt::MouseButtons buttons
)
957 // The default case (left button pressed) is handled in goBack().
958 if (buttons
== Qt::MidButton
) {
959 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
960 const int index
= urlNavigator
->historyIndex() + 1;
961 openNewTab(urlNavigator
->locationUrl(index
));
965 void DolphinMainWindow::goForward(Qt::MouseButtons buttons
)
967 // The default case (left button pressed) is handled in goForward().
968 if (buttons
== Qt::MidButton
) {
969 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
970 const int index
= urlNavigator
->historyIndex() - 1;
971 openNewTab(urlNavigator
->locationUrl(index
));
975 void DolphinMainWindow::goUp(Qt::MouseButtons buttons
)
977 // The default case (left button pressed) is handled in goUp().
978 if (buttons
== Qt::MidButton
) {
979 openNewTab(activeViewContainer()->url().upUrl());
983 void DolphinMainWindow::goHome(Qt::MouseButtons buttons
)
985 // The default case (left button pressed) is handled in goHome().
986 if (buttons
== Qt::MidButton
) {
987 openNewTab(GeneralSettings::self()->homeUrl());
991 void DolphinMainWindow::compareFiles()
993 // The method is only invoked if exactly 2 files have
994 // been selected. The selected files may be:
995 // - both in the primary view
996 // - both in the secondary view
997 // - one in the primary view and the other in the secondary
999 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
1004 KFileItemList items
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedItems();
1006 switch (items
.count()) {
1008 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
);
1009 items
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItems();
1010 Q_ASSERT(items
.count() == 2);
1011 urlA
= items
[0].url();
1012 urlB
= items
[1].url();
1017 urlA
= items
[0].url();
1018 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
);
1019 items
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItems();
1020 Q_ASSERT(items
.count() == 1);
1021 urlB
= items
[0].url();
1026 urlA
= items
[0].url();
1027 urlB
= items
[1].url();
1032 // may not happen: compareFiles may only get invoked if 2
1033 // files are selected
1038 QString
command("kompare -c \"");
1039 command
.append(urlA
.pathOrUrl());
1040 command
.append("\" \"");
1041 command
.append(urlB
.pathOrUrl());
1042 command
.append('\"');
1043 KRun::runCommand(command
, "Kompare", "kompare", this);
1046 void DolphinMainWindow::toggleShowMenuBar()
1048 const bool visible
= menuBar()->isVisible();
1049 menuBar()->setVisible(!visible
);
1051 createControlButton();
1053 deleteControlButton();
1057 void DolphinMainWindow::openTerminal()
1059 QString
dir(QDir::homePath());
1061 // If the given directory is not local, it can still be the URL of an
1062 // ioslave using UDS_LOCAL_PATH which to be converted first.
1063 KUrl url
= KIO::NetAccess::mostLocalUrl(m_activeViewContainer
->url(), this);
1065 //If the URL is local after the above conversion, set the directory.
1066 if (url
.isLocalFile()) {
1067 dir
= url
.toLocalFile();
1070 KToolInvocation::invokeTerminal(QString(), dir
);
1073 void DolphinMainWindow::editSettings()
1075 if (!m_settingsDialog
) {
1076 DolphinViewContainer
* container
= activeViewContainer();
1077 container
->view()->writeSettings();
1079 const KUrl url
= container
->url();
1080 DolphinSettingsDialog
* settingsDialog
= new DolphinSettingsDialog(url
, this);
1081 connect(settingsDialog
, SIGNAL(settingsChanged()), this, SLOT(refreshViews()));
1082 settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1083 settingsDialog
->show();
1084 m_settingsDialog
= settingsDialog
;
1086 m_settingsDialog
.data()->raise();
1090 void DolphinMainWindow::setActiveTab(int index
)
1092 Q_ASSERT(index
>= 0);
1093 Q_ASSERT(index
< m_viewTab
.count());
1094 if (index
== m_tabIndex
) {
1098 // hide current tab content
1099 ViewTab
& hiddenTab
= m_viewTab
[m_tabIndex
];
1100 hiddenTab
.isPrimaryViewActive
= hiddenTab
.primaryView
->isActive();
1101 hiddenTab
.primaryView
->setActive(false);
1102 if (hiddenTab
.secondaryView
) {
1103 hiddenTab
.secondaryView
->setActive(false);
1105 QSplitter
* splitter
= m_viewTab
[m_tabIndex
].splitter
;
1107 m_centralWidgetLayout
->removeWidget(splitter
);
1109 // show active tab content
1112 ViewTab
& viewTab
= m_viewTab
[index
];
1113 m_centralWidgetLayout
->addWidget(viewTab
.splitter
, 1);
1114 viewTab
.primaryView
->show();
1115 if (viewTab
.secondaryView
) {
1116 viewTab
.secondaryView
->show();
1118 viewTab
.splitter
->show();
1120 if (!viewTab
.wasActive
) {
1121 viewTab
.wasActive
= true;
1123 // If the tab has not been activated yet the size of the KItemListView is
1124 // undefined and results in an unwanted animation. To prevent this a
1125 // reloading of the directory gets triggered.
1126 viewTab
.primaryView
->view()->reload();
1127 if (viewTab
.secondaryView
) {
1128 viewTab
.secondaryView
->view()->reload();
1132 setActiveViewContainer(viewTab
.isPrimaryViewActive
? viewTab
.primaryView
:
1133 viewTab
.secondaryView
);
1136 void DolphinMainWindow::closeTab()
1138 closeTab(m_tabBar
->currentIndex());
1141 void DolphinMainWindow::closeTab(int index
)
1143 Q_ASSERT(index
>= 0);
1144 Q_ASSERT(index
< m_viewTab
.count());
1145 if (m_viewTab
.count() == 1) {
1146 // the last tab may never get closed
1150 if (index
== m_tabIndex
) {
1151 // The tab that should be closed is the active tab. Activate the
1152 // previous tab before closing the tab.
1153 m_tabBar
->setCurrentIndex((index
> 0) ? index
- 1 : 1);
1155 rememberClosedTab(index
);
1158 m_viewTab
[index
].primaryView
->deleteLater();
1159 if (m_viewTab
[index
].secondaryView
) {
1160 m_viewTab
[index
].secondaryView
->deleteLater();
1162 m_viewTab
[index
].splitter
->deleteLater();
1163 m_viewTab
.erase(m_viewTab
.begin() + index
);
1165 m_tabBar
->blockSignals(true);
1166 m_tabBar
->removeTab(index
);
1168 if (m_tabIndex
> index
) {
1170 Q_ASSERT(m_tabIndex
>= 0);
1173 // if only one tab is left, also remove the tab entry so that
1174 // closing the last tab is not possible
1175 if (m_viewTab
.count() == 1) {
1176 m_tabBar
->removeTab(0);
1177 actionCollection()->action("close_tab")->setEnabled(false);
1179 m_tabBar
->blockSignals(false);
1183 void DolphinMainWindow::openTabContextMenu(int index
, const QPoint
& pos
)
1187 QAction
* newTabAction
= menu
.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab"));
1188 newTabAction
->setShortcut(actionCollection()->action("new_tab")->shortcut());
1190 QAction
* detachTabAction
= menu
.addAction(KIcon("tab-detach"), i18nc("@action:inmenu", "Detach Tab"));
1192 QAction
* closeOtherTabsAction
= menu
.addAction(KIcon("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs"));
1194 QAction
* closeTabAction
= menu
.addAction(KIcon("tab-close"), i18nc("@action:inmenu", "Close Tab"));
1195 closeTabAction
->setShortcut(actionCollection()->action("close_tab")->shortcut());
1196 QAction
* selectedAction
= menu
.exec(pos
);
1197 if (selectedAction
== newTabAction
) {
1198 const ViewTab
& tab
= m_viewTab
[index
];
1199 Q_ASSERT(tab
.primaryView
);
1200 const KUrl url
= tab
.secondaryView
&& tab
.secondaryView
->isActive() ?
1201 tab
.secondaryView
->url() : tab
.primaryView
->url();
1203 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
1204 } else if (selectedAction
== detachTabAction
) {
1205 const QString
separator(QLatin1Char(' '));
1206 QString command
= QLatin1String("dolphin");
1208 const ViewTab
& tab
= m_viewTab
[index
];
1209 Q_ASSERT(tab
.primaryView
);
1211 command
+= separator
+ tab
.primaryView
->url().url();
1212 if (tab
.secondaryView
) {
1213 command
+= separator
+ tab
.secondaryView
->url().url();
1214 command
+= separator
+ QLatin1String("-split");
1217 KRun::runCommand(command
, this);
1220 } else if (selectedAction
== closeOtherTabsAction
) {
1221 const int count
= m_tabBar
->count();
1222 for (int i
= 0; i
< index
; ++i
) {
1225 for (int i
= index
+ 1; i
< count
; ++i
) {
1228 } else if (selectedAction
== closeTabAction
) {
1233 void DolphinMainWindow::slotTabMoved(int from
, int to
)
1235 m_viewTab
.move(from
, to
);
1236 m_tabIndex
= m_tabBar
->currentIndex();
1239 void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent
* event
, bool& canDecode
)
1241 canDecode
= KUrl::List::canDecode(event
->mimeData());
1244 void DolphinMainWindow::handleUrl(const KUrl
& url
)
1246 delete m_lastHandleUrlStatJob
;
1247 m_lastHandleUrlStatJob
= 0;
1249 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1250 activeViewContainer()->setUrl(url
);
1251 } else if (KProtocolManager::supportsListing(url
)) {
1252 // stat the URL to see if it is a dir or not
1253 m_lastHandleUrlStatJob
= KIO::stat(url
, KIO::HideProgressInfo
);
1254 if (m_lastHandleUrlStatJob
->ui()) {
1255 m_lastHandleUrlStatJob
->ui()->setWindow(this);
1257 connect(m_lastHandleUrlStatJob
, SIGNAL(result(KJob
*)),
1258 this, SLOT(slotHandleUrlStatFinished(KJob
*)));
1261 new KRun(url
, this); // Automatically deletes itself after being finished
1265 void DolphinMainWindow::slotHandleUrlStatFinished(KJob
* job
)
1267 m_lastHandleUrlStatJob
= 0;
1268 const KIO::UDSEntry entry
= static_cast<KIO::StatJob
*>(job
)->statResult();
1269 const KUrl url
= static_cast<KIO::StatJob
*>(job
)->url();
1270 if (entry
.isDir()) {
1271 activeViewContainer()->setUrl(url
);
1273 new KRun(url
, this); // Automatically deletes itself after being finished
1277 void DolphinMainWindow::tabDropEvent(int tab
, QDropEvent
* event
)
1279 const KUrl::List urls
= KUrl::List::fromMimeData(event
->mimeData());
1280 if (!urls
.isEmpty() && tab
!= -1) {
1281 const ViewTab
& viewTab
= m_viewTab
[tab
];
1282 const DolphinView
* view
= viewTab
.isPrimaryViewActive
? viewTab
.primaryView
->view()
1283 : viewTab
.secondaryView
->view();
1285 DragAndDropHelper::dropUrls(view
->rootItem(), view
->url(), event
, error
);
1286 if (!error
.isEmpty()) {
1287 activeViewContainer()->showMessage(error
, DolphinViewContainer::Error
);
1292 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1294 newFileMenu()->setEnabled(isFolderWritable
);
1297 void DolphinMainWindow::openContextMenu(const QPoint
& pos
,
1298 const KFileItem
& item
,
1300 const QList
<QAction
*>& customActions
)
1302 QWeakPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, pos
, item
, url
);
1303 contextMenu
.data()->setCustomActions(customActions
);
1304 const DolphinContextMenu::Command command
= contextMenu
.data()->open();
1307 case DolphinContextMenu::OpenParentFolderInNewWindow
: {
1308 KRun::run("dolphin %u", KUrl::List() << item
.url().upUrl(), this);
1312 case DolphinContextMenu::OpenParentFolderInNewTab
:
1313 openNewTab(item
.url().upUrl());
1316 case DolphinContextMenu::None
:
1321 delete contextMenu
.data();
1324 void DolphinMainWindow::updateControlMenu()
1326 KMenu
* menu
= qobject_cast
<KMenu
*>(sender());
1329 // All actions get cleared by KMenu::clear(). The sub-menus are deleted
1330 // by connecting to the aboutToHide() signal from the parent-menu.
1333 KActionCollection
* ac
= actionCollection();
1335 // Add "Edit" actions
1336 bool added
= addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Undo
)), menu
) |
1337 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Find
)), menu
) |
1338 addActionToMenu(ac
->action("select_all"), menu
) |
1339 addActionToMenu(ac
->action("invert_selection"), menu
);
1342 menu
->addSeparator();
1345 // Add "View" actions
1346 if (!GeneralSettings::showZoomSlider()) {
1347 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomIn
)), menu
);
1348 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomOut
)), menu
);
1349 menu
->addSeparator();
1352 added
= addActionToMenu(ac
->action("view_mode"), menu
) |
1353 addActionToMenu(ac
->action("sort"), menu
) |
1354 addActionToMenu(ac
->action("additional_info"), menu
) |
1355 addActionToMenu(ac
->action("show_preview"), menu
) |
1356 addActionToMenu(ac
->action("show_in_groups"), menu
) |
1357 addActionToMenu(ac
->action("show_hidden_files"), menu
);
1360 menu
->addSeparator();
1363 added
= addActionToMenu(ac
->action("split_view"), menu
) |
1364 addActionToMenu(ac
->action("reload"), menu
) |
1365 addActionToMenu(ac
->action("view_properties"), menu
);
1367 menu
->addSeparator();
1370 addActionToMenu(ac
->action("panels"), menu
);
1371 KMenu
* locationBarMenu
= new KMenu(i18nc("@action:inmenu", "Location Bar"), menu
);
1372 locationBarMenu
->addAction(ac
->action("editable_location"));
1373 locationBarMenu
->addAction(ac
->action("replace_location"));
1374 menu
->addMenu(locationBarMenu
);
1376 menu
->addSeparator();
1379 KMenu
* goMenu
= new KMenu(i18nc("@action:inmenu", "Go"), menu
);
1380 connect(menu
, SIGNAL(aboutToHide()), goMenu
, SLOT(deleteLater()));
1381 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Back
)));
1382 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Forward
)));
1383 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Up
)));
1384 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Home
)));
1385 goMenu
->addAction(ac
->action("closed_tabs"));
1386 menu
->addMenu(goMenu
);
1389 KMenu
* toolsMenu
= new KMenu(i18nc("@action:inmenu", "Tools"), menu
);
1390 connect(menu
, SIGNAL(aboutToHide()), toolsMenu
, SLOT(deleteLater()));
1391 toolsMenu
->addAction(ac
->action("show_filter_bar"));
1392 toolsMenu
->addAction(ac
->action("compare_files"));
1393 toolsMenu
->addAction(ac
->action("open_terminal"));
1394 toolsMenu
->addAction(ac
->action("change_remote_encoding"));
1395 menu
->addMenu(toolsMenu
);
1397 // Add "Settings" menu entries
1398 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::KeyBindings
)), menu
);
1399 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ConfigureToolbars
)), menu
);
1400 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Preferences
)), menu
);
1403 KMenu
* helpMenu
= new KMenu(i18nc("@action:inmenu", "Help"), menu
);
1404 connect(menu
, SIGNAL(aboutToHide()), helpMenu
, SLOT(deleteLater()));
1405 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::HelpContents
)));
1406 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::WhatsThis
)));
1407 helpMenu
->addSeparator();
1408 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ReportBug
)));
1409 helpMenu
->addSeparator();
1410 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
)));
1411 helpMenu
->addSeparator();
1412 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::AboutApp
)));
1413 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::AboutKDE
)));
1414 menu
->addMenu(helpMenu
);
1416 menu
->addSeparator();
1417 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ShowMenubar
)), menu
);
1420 void DolphinMainWindow::updateToolBar()
1422 if (!menuBar()->isVisible()) {
1423 createControlButton();
1427 void DolphinMainWindow::slotControlButtonDeleted()
1429 m_controlButton
= 0;
1430 m_updateToolBarTimer
->start();
1433 void DolphinMainWindow::slotPanelErrorMessage(const QString
& error
)
1435 activeViewContainer()->showMessage(error
, DolphinViewContainer::Error
);
1438 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer
* viewContainer
)
1440 Q_ASSERT(viewContainer
);
1441 Q_ASSERT((viewContainer
== m_viewTab
[m_tabIndex
].primaryView
) ||
1442 (viewContainer
== m_viewTab
[m_tabIndex
].secondaryView
));
1443 if (m_activeViewContainer
== viewContainer
) {
1447 m_activeViewContainer
->setActive(false);
1448 m_activeViewContainer
= viewContainer
;
1450 // Activating the view container might trigger a recursive setActiveViewContainer() call
1451 // inside DolphinMainWindow::toggleActiveView() when having a split view. Temporary
1452 // disconnect the activated() signal in this case:
1453 disconnect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1454 m_activeViewContainer
->setActive(true);
1455 connect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1457 m_actionHandler
->setCurrentView(viewContainer
->view());
1460 updateEditActions();
1461 updateViewActions();
1464 const KUrl url
= m_activeViewContainer
->url();
1465 setUrlAsCaption(url
);
1466 if (m_viewTab
.count() > 1) {
1467 m_tabBar
->setTabText(m_tabIndex
, tabName(url
));
1468 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(KMimeType::iconNameForUrl(url
)));
1471 emit
urlChanged(url
);
1474 DolphinViewContainer
* DolphinMainWindow::createViewContainer(const KUrl
& url
, QWidget
* parent
)
1476 DolphinViewContainer
* container
= new DolphinViewContainer(url
, parent
);
1478 // The places-selector from the URL navigator should only be shown
1479 // if the places dock is invisible
1480 QDockWidget
* placesDock
= findChild
<QDockWidget
*>("placesDock");
1481 container
->urlNavigator()->setPlacesSelectorVisible(!placesDock
|| !placesDock
->isVisible());
1486 void DolphinMainWindow::setupActions()
1488 // setup 'File' menu
1489 m_newFileMenu
= new DolphinNewFileMenu(actionCollection(), this);
1490 KMenu
* menu
= m_newFileMenu
->menu();
1491 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1492 menu
->setIcon(KIcon("document-new"));
1493 m_newFileMenu
->setDelayed(false);
1494 connect(menu
, SIGNAL(aboutToShow()),
1495 this, SLOT(updateNewMenu()));
1497 KAction
* newWindow
= actionCollection()->addAction("new_window");
1498 newWindow
->setIcon(KIcon("window-new"));
1499 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1500 newWindow
->setShortcut(Qt::CTRL
| Qt::Key_N
);
1501 connect(newWindow
, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1503 KAction
* newTab
= actionCollection()->addAction("new_tab");
1504 newTab
->setIcon(KIcon("tab-new"));
1505 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1506 newTab
->setShortcut(KShortcut(Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
));
1507 connect(newTab
, SIGNAL(triggered()), this, SLOT(openNewTab()));
1509 KAction
* closeTab
= actionCollection()->addAction("close_tab");
1510 closeTab
->setIcon(KIcon("tab-close"));
1511 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1512 closeTab
->setShortcut(Qt::CTRL
| Qt::Key_W
);
1513 closeTab
->setEnabled(false);
1514 connect(closeTab
, SIGNAL(triggered()), this, SLOT(closeTab()));
1516 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1518 // setup 'Edit' menu
1519 KStandardAction::undo(this,
1521 actionCollection());
1523 // need to remove shift+del from cut action, else the shortcut for deletejob
1525 KAction
* cut
= KStandardAction::cut(this, SLOT(cut()), actionCollection());
1526 KShortcut cutShortcut
= cut
->shortcut();
1527 cutShortcut
.remove(Qt::SHIFT
| Qt::Key_Delete
, KShortcut::KeepEmpty
);
1528 cut
->setShortcut(cutShortcut
);
1529 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1530 KAction
* paste
= KStandardAction::paste(this, SLOT(paste()), actionCollection());
1531 // The text of the paste-action is modified dynamically by Dolphin
1532 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1533 // due to the long text, the text "Paste" is used:
1534 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1536 KStandardAction::find(this, SLOT(find()), actionCollection());
1538 KAction
* selectAll
= actionCollection()->addAction("select_all");
1539 selectAll
->setText(i18nc("@action:inmenu Edit", "Select All"));
1540 selectAll
->setShortcut(Qt::CTRL
| Qt::Key_A
);
1541 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
1543 KAction
* invertSelection
= actionCollection()->addAction("invert_selection");
1544 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1545 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1546 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
1548 // setup 'View' menu
1549 // (note that most of it is set up in DolphinViewActionHandler)
1551 KAction
* split
= actionCollection()->addAction("split_view");
1552 split
->setShortcut(Qt::Key_F3
);
1553 updateSplitAction();
1554 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1556 KAction
* reload
= actionCollection()->addAction("reload");
1557 reload
->setText(i18nc("@action:inmenu View", "Reload"));
1558 reload
->setShortcut(Qt::Key_F5
);
1559 reload
->setIcon(KIcon("view-refresh"));
1560 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
1562 KAction
* stop
= actionCollection()->addAction("stop");
1563 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1564 stop
->setToolTip(i18nc("@info", "Stop loading"));
1565 stop
->setIcon(KIcon("process-stop"));
1566 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
1568 KToggleAction
* editableLocation
= actionCollection()->add
<KToggleAction
>("editable_location");
1569 editableLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1570 editableLocation
->setShortcut(Qt::Key_F6
);
1571 connect(editableLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1573 KAction
* replaceLocation
= actionCollection()->addAction("replace_location");
1574 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1575 replaceLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
1576 connect(replaceLocation
, SIGNAL(triggered()), this, SLOT(replaceLocation()));
1579 KAction
* backAction
= KStandardAction::back(this, SLOT(goBack()), actionCollection());
1580 connect(backAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goBack(Qt::MouseButtons
)));
1581 KShortcut backShortcut
= backAction
->shortcut();
1582 backShortcut
.setAlternate(Qt::Key_Backspace
);
1583 backAction
->setShortcut(backShortcut
);
1585 m_recentTabsMenu
= new KActionMenu(i18n("Recently Closed Tabs"), this);
1586 m_recentTabsMenu
->setIcon(KIcon("edit-undo"));
1587 m_recentTabsMenu
->setDelayed(false);
1588 actionCollection()->addAction("closed_tabs", m_recentTabsMenu
);
1589 connect(m_recentTabsMenu
->menu(), SIGNAL(triggered(QAction
*)),
1590 this, SLOT(restoreClosedTab(QAction
*)));
1592 QAction
* action
= new QAction(i18n("Empty Recently Closed Tabs"), m_recentTabsMenu
);
1593 action
->setIcon(KIcon("edit-clear-list"));
1594 action
->setData(QVariant::fromValue(true));
1595 m_recentTabsMenu
->addAction(action
);
1596 m_recentTabsMenu
->addSeparator();
1597 m_recentTabsMenu
->setEnabled(false);
1599 KAction
* forwardAction
= KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1600 connect(forwardAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goForward(Qt::MouseButtons
)));
1602 KAction
* upAction
= KStandardAction::up(this, SLOT(goUp()), actionCollection());
1603 connect(upAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goUp(Qt::MouseButtons
)));
1605 KAction
* homeAction
= KStandardAction::home(this, SLOT(goHome()), actionCollection());
1606 connect(homeAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goHome(Qt::MouseButtons
)));
1608 // setup 'Tools' menu
1609 KAction
* showFilterBar
= actionCollection()->addAction("show_filter_bar");
1610 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1611 showFilterBar
->setIcon(KIcon("view-filter"));
1612 showFilterBar
->setShortcut(Qt::CTRL
| Qt::Key_I
);
1613 connect(showFilterBar
, SIGNAL(triggered()), this, SLOT(showFilterBar()));
1615 KAction
* compareFiles
= actionCollection()->addAction("compare_files");
1616 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1617 compareFiles
->setIcon(KIcon("kompare"));
1618 compareFiles
->setEnabled(false);
1619 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
1621 KAction
* openTerminal
= actionCollection()->addAction("open_terminal");
1622 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1623 openTerminal
->setIcon(KIcon("utilities-terminal"));
1624 openTerminal
->setShortcut(Qt::SHIFT
| Qt::Key_F4
);
1625 connect(openTerminal
, SIGNAL(triggered()), this, SLOT(openTerminal()));
1627 // setup 'Settings' menu
1628 KToggleAction
* showMenuBar
= KStandardAction::showMenubar(0, 0, actionCollection());
1629 connect(showMenuBar
, SIGNAL(triggered(bool)), // Fixes #286822
1630 this, SLOT(toggleShowMenuBar()), Qt::QueuedConnection
);
1631 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1633 // not in menu actions
1634 QList
<QKeySequence
> nextTabKeys
;
1635 nextTabKeys
.append(KStandardShortcut::tabNext().primary());
1636 nextTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::Key_Tab
));
1638 QList
<QKeySequence
> prevTabKeys
;
1639 prevTabKeys
.append(KStandardShortcut::tabPrev().primary());
1640 prevTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::SHIFT
| Qt::Key_Tab
));
1642 KAction
* activateNextTab
= actionCollection()->addAction("activate_next_tab");
1643 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1644 connect(activateNextTab
, SIGNAL(triggered()), SLOT(activateNextTab()));
1645 activateNextTab
->setShortcuts(QApplication::isRightToLeft() ? prevTabKeys
: nextTabKeys
);
1647 KAction
* activatePrevTab
= actionCollection()->addAction("activate_prev_tab");
1648 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1649 connect(activatePrevTab
, SIGNAL(triggered()), SLOT(activatePrevTab()));
1650 activatePrevTab
->setShortcuts(QApplication::isRightToLeft() ? nextTabKeys
: prevTabKeys
);
1653 KAction
* openInNewTab
= actionCollection()->addAction("open_in_new_tab");
1654 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1655 openInNewTab
->setIcon(KIcon("tab-new"));
1656 connect(openInNewTab
, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1658 KAction
* openInNewTabs
= actionCollection()->addAction("open_in_new_tabs");
1659 openInNewTabs
->setText(i18nc("@action:inmenu", "Open in New Tabs"));
1660 openInNewTabs
->setIcon(KIcon("tab-new"));
1661 connect(openInNewTabs
, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1663 KAction
* openInNewWindow
= actionCollection()->addAction("open_in_new_window");
1664 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1665 openInNewWindow
->setIcon(KIcon("window-new"));
1666 connect(openInNewWindow
, SIGNAL(triggered()), this, SLOT(openInNewWindow()));
1669 void DolphinMainWindow::setupDockWidgets()
1671 const bool lock
= GeneralSettings::lockPanels();
1673 KDualAction
* lockLayoutAction
= actionCollection()->add
<KDualAction
>("lock_panels");
1674 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
1675 lockLayoutAction
->setActiveIcon(KIcon("object-unlocked"));
1676 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
1677 lockLayoutAction
->setInactiveIcon(KIcon("object-locked"));
1678 lockLayoutAction
->setActive(lock
);
1679 connect(lockLayoutAction
, SIGNAL(triggered()), this, SLOT(togglePanelLockState()));
1681 // Setup "Information"
1682 DolphinDockWidget
* infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
1683 infoDock
->setLocked(lock
);
1684 infoDock
->setObjectName("infoDock");
1685 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1686 Panel
* infoPanel
= new InformationPanel(infoDock
);
1687 infoPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1688 connect(infoPanel
, SIGNAL(urlActivated(KUrl
)), this, SLOT(handleUrl(KUrl
)));
1689 infoDock
->setWidget(infoPanel
);
1691 QAction
* infoAction
= infoDock
->toggleViewAction();
1692 createPanelAction(KIcon("dialog-information"), Qt::Key_F11
, infoAction
, "show_information_panel");
1694 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1695 connect(this, SIGNAL(urlChanged(KUrl
)),
1696 infoPanel
, SLOT(setUrl(KUrl
)));
1697 connect(this, SIGNAL(selectionChanged(KFileItemList
)),
1698 infoPanel
, SLOT(setSelection(KFileItemList
)));
1699 connect(this, SIGNAL(requestItemInfo(KFileItem
)),
1700 infoPanel
, SLOT(requestDelayedItemInfo(KFileItem
)));
1703 DolphinDockWidget
* foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
1704 foldersDock
->setLocked(lock
);
1705 foldersDock
->setObjectName("foldersDock");
1706 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1707 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1708 foldersPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1709 foldersDock
->setWidget(foldersPanel
);
1711 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1712 createPanelAction(KIcon("folder"), Qt::Key_F7
, foldersAction
, "show_folders_panel");
1714 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1715 connect(this, SIGNAL(urlChanged(KUrl
)),
1716 foldersPanel
, SLOT(setUrl(KUrl
)));
1717 connect(foldersPanel
, SIGNAL(folderActivated(KUrl
)),
1718 this, SLOT(changeUrl(KUrl
)));
1719 connect(foldersPanel
, SIGNAL(folderMiddleClicked(KUrl
)),
1720 this, SLOT(openNewTab(KUrl
)));
1721 connect(foldersPanel
, SIGNAL(errorMessage(QString
)),
1722 this, SLOT(slotPanelErrorMessage(QString
)));
1726 DolphinDockWidget
* terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1727 terminalDock
->setLocked(lock
);
1728 terminalDock
->setObjectName("terminalDock");
1729 terminalDock
->setAllowedAreas(Qt::TopDockWidgetArea
| Qt::BottomDockWidgetArea
);
1730 Panel
* terminalPanel
= new TerminalPanel(terminalDock
);
1731 terminalPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1732 terminalDock
->setWidget(terminalPanel
);
1734 connect(terminalPanel
, SIGNAL(hideTerminalPanel()), terminalDock
, SLOT(hide()));
1735 connect(terminalPanel
, SIGNAL(changeUrl(KUrl
)), this, SLOT(slotTerminalDirectoryChanged(KUrl
)));
1736 connect(terminalDock
, SIGNAL(visibilityChanged(bool)),
1737 terminalPanel
, SLOT(dockVisibilityChanged()));
1739 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1740 createPanelAction(KIcon("utilities-terminal"), Qt::Key_F4
, terminalAction
, "show_terminal_panel");
1742 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1743 connect(this, SIGNAL(urlChanged(KUrl
)),
1744 terminalPanel
, SLOT(setUrl(KUrl
)));
1747 if (GeneralSettings::version() < 200) {
1749 foldersDock
->hide();
1751 terminalDock
->hide();
1756 DolphinDockWidget
* placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
1757 placesDock
->setLocked(lock
);
1758 placesDock
->setObjectName("placesDock");
1759 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1761 PlacesPanel
* placesPanel
= new PlacesPanel(placesDock
);
1762 placesPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1763 placesDock
->setWidget(placesPanel
);
1765 QAction
* placesAction
= placesDock
->toggleViewAction();
1766 createPanelAction(KIcon("bookmarks"), Qt::Key_F9
, placesAction
, "show_places_panel");
1768 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1769 connect(placesPanel
, SIGNAL(placeActivated(KUrl
)),
1770 this, SLOT(changeUrl(KUrl
)));
1771 connect(placesPanel
, SIGNAL(placeMiddleClicked(KUrl
)),
1772 this, SLOT(openNewTab(KUrl
)));
1773 connect(placesPanel
, SIGNAL(errorMessage(QString
)),
1774 this, SLOT(slotPanelErrorMessage(QString
)));
1775 connect(this, SIGNAL(urlChanged(KUrl
)),
1776 placesPanel
, SLOT(setUrl(KUrl
)));
1777 connect(placesDock
, SIGNAL(visibilityChanged(bool)),
1778 this, SLOT(slotPlacesPanelVisibilityChanged(bool)));
1779 connect(this, SIGNAL(settingsChanged()),
1780 placesPanel
, SLOT(readSettings()));
1782 // Add actions into the "Panels" menu
1783 KActionMenu
* panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Panels"), this);
1784 actionCollection()->addAction("panels", panelsMenu
);
1785 panelsMenu
->setDelayed(false);
1786 const KActionCollection
* ac
= actionCollection();
1787 panelsMenu
->addAction(ac
->action("show_places_panel"));
1788 panelsMenu
->addAction(ac
->action("show_information_panel"));
1789 panelsMenu
->addAction(ac
->action("show_folders_panel"));
1791 panelsMenu
->addAction(ac
->action("show_terminal_panel"));
1793 panelsMenu
->addSeparator();
1794 panelsMenu
->addAction(lockLayoutAction
);
1797 void DolphinMainWindow::updateEditActions()
1799 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1800 if (list
.isEmpty()) {
1801 stateChanged("has_no_selection");
1803 stateChanged("has_selection");
1805 KActionCollection
* col
= actionCollection();
1806 QAction
* renameAction
= col
->action("rename");
1807 QAction
* moveToTrashAction
= col
->action("move_to_trash");
1808 QAction
* deleteAction
= col
->action("delete");
1809 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
1810 QAction
* deleteWithTrashShortcut
= col
->action("delete_shortcut"); // see DolphinViewActionHandler
1812 KFileItemListProperties
capabilities(list
);
1813 const bool enableMoveToTrash
= capabilities
.isLocal() && capabilities
.supportsMoving();
1815 renameAction
->setEnabled(capabilities
.supportsMoving());
1816 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1817 deleteAction
->setEnabled(capabilities
.supportsDeleting());
1818 deleteWithTrashShortcut
->setEnabled(capabilities
.supportsDeleting() && !enableMoveToTrash
);
1819 cutAction
->setEnabled(capabilities
.supportsMoving());
1821 updatePasteAction();
1824 void DolphinMainWindow::updateViewActions()
1826 m_actionHandler
->updateViewActions();
1828 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1829 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
1831 updateSplitAction();
1833 QAction
* editableLocactionAction
= actionCollection()->action("editable_location");
1834 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
1835 editableLocactionAction
->setChecked(urlNavigator
->isUrlEditable());
1838 void DolphinMainWindow::updateGoActions()
1840 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
1841 const KUrl currentUrl
= m_activeViewContainer
->url();
1842 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
1845 void DolphinMainWindow::createControlButton()
1847 if (m_controlButton
) {
1850 Q_ASSERT(!m_controlButton
);
1852 m_controlButton
= new QToolButton(this);
1853 m_controlButton
->setIcon(KIcon("applications-system"));
1854 m_controlButton
->setText(i18nc("@action", "Control"));
1855 m_controlButton
->setPopupMode(QToolButton::InstantPopup
);
1856 m_controlButton
->setToolButtonStyle(toolBar()->toolButtonStyle());
1858 KMenu
* controlMenu
= new KMenu(m_controlButton
);
1859 connect(controlMenu
, SIGNAL(aboutToShow()), this, SLOT(updateControlMenu()));
1861 m_controlButton
->setMenu(controlMenu
);
1863 toolBar()->addWidget(m_controlButton
);
1864 connect(toolBar(), SIGNAL(iconSizeChanged(QSize
)),
1865 m_controlButton
, SLOT(setIconSize(QSize
)));
1866 connect(toolBar(), SIGNAL(toolButtonStyleChanged(Qt::ToolButtonStyle
)),
1867 m_controlButton
, SLOT(setToolButtonStyle(Qt::ToolButtonStyle
)));
1869 // The added widgets are owned by the toolbar and may get deleted when e.g. the toolbar
1870 // gets edited. In this case we must add them again. The adding is done asynchronously by
1871 // m_updateToolBarTimer.
1872 connect(m_controlButton
, SIGNAL(destroyed()), this, SLOT(slotControlButtonDeleted()));
1873 m_updateToolBarTimer
= new QTimer(this);
1874 m_updateToolBarTimer
->setInterval(500);
1875 connect(m_updateToolBarTimer
, SIGNAL(timeout()), this, SLOT(updateToolBar()));
1878 void DolphinMainWindow::deleteControlButton()
1880 delete m_controlButton
;
1881 m_controlButton
= 0;
1883 delete m_updateToolBarTimer
;
1884 m_updateToolBarTimer
= 0;
1887 bool DolphinMainWindow::addActionToMenu(QAction
* action
, KMenu
* menu
)
1892 const KToolBar
* toolBarWidget
= toolBar();
1893 foreach (const QWidget
* widget
, action
->associatedWidgets()) {
1894 if (widget
== toolBarWidget
) {
1899 menu
->addAction(action
);
1903 void DolphinMainWindow::rememberClosedTab(int index
)
1905 KMenu
* tabsMenu
= m_recentTabsMenu
->menu();
1907 const QString primaryPath
= m_viewTab
[index
].primaryView
->url().path();
1908 const QString iconName
= KMimeType::iconNameForUrl(primaryPath
);
1910 QAction
* action
= new QAction(squeezedText(primaryPath
), tabsMenu
);
1912 ClosedTab closedTab
;
1913 closedTab
.primaryUrl
= m_viewTab
[index
].primaryView
->url();
1915 if (m_viewTab
[index
].secondaryView
) {
1916 closedTab
.secondaryUrl
= m_viewTab
[index
].secondaryView
->url();
1917 closedTab
.isSplit
= true;
1919 closedTab
.isSplit
= false;
1922 action
->setData(QVariant::fromValue(closedTab
));
1923 action
->setIcon(KIcon(iconName
));
1925 // add the closed tab menu entry after the separator and
1926 // "Empty Recently Closed Tabs" entry
1927 if (tabsMenu
->actions().size() == 2) {
1928 tabsMenu
->addAction(action
);
1930 tabsMenu
->insertAction(tabsMenu
->actions().at(2), action
);
1933 // assure that only up to 8 closed tabs are shown in the menu
1934 if (tabsMenu
->actions().size() > 8) {
1935 tabsMenu
->removeAction(tabsMenu
->actions().last());
1937 actionCollection()->action("closed_tabs")->setEnabled(true);
1938 KAcceleratorManager::manage(tabsMenu
);
1941 void DolphinMainWindow::refreshViews()
1943 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
1945 // remember the current active view, as because of
1946 // the refreshing the active view might change to
1947 // the secondary view
1948 DolphinViewContainer
* activeViewContainer
= m_activeViewContainer
;
1950 const int tabCount
= m_viewTab
.count();
1951 for (int i
= 0; i
< tabCount
; ++i
) {
1952 m_viewTab
[i
].primaryView
->readSettings();
1953 if (m_viewTab
[i
].secondaryView
) {
1954 m_viewTab
[i
].secondaryView
->readSettings();
1958 setActiveViewContainer(activeViewContainer
);
1960 if (GeneralSettings::modifiedStartupSettings()) {
1961 // The startup settings have been changed by the user (see bug #254947).
1962 // Synchronize the split-view setting with the active view:
1963 const bool splitView
= GeneralSettings::splitView();
1964 const ViewTab
& activeTab
= m_viewTab
[m_tabIndex
];
1965 const bool toggle
= ( splitView
&& !activeTab
.secondaryView
)
1966 || (!splitView
&& activeTab
.secondaryView
);
1972 emit
settingsChanged();
1975 void DolphinMainWindow::clearStatusBar()
1977 m_activeViewContainer
->statusBar()->resetToDefaultText();
1980 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
1982 connect(container
, SIGNAL(showFilterBarChanged(bool)),
1983 this, SLOT(updateFilterBarAction(bool)));
1984 connect(container
, SIGNAL(writeStateChanged(bool)),
1985 this, SLOT(slotWriteStateChanged(bool)));
1987 DolphinView
* view
= container
->view();
1988 connect(view
, SIGNAL(selectionChanged(KFileItemList
)),
1989 this, SLOT(slotSelectionChanged(KFileItemList
)));
1990 connect(view
, SIGNAL(requestItemInfo(KFileItem
)),
1991 this, SLOT(slotRequestItemInfo(KFileItem
)));
1992 connect(view
, SIGNAL(activated()),
1993 this, SLOT(toggleActiveView()));
1994 connect(view
, SIGNAL(tabRequested(KUrl
)),
1995 this, SLOT(openNewTab(KUrl
)));
1996 connect(view
, SIGNAL(requestContextMenu(QPoint
,KFileItem
,KUrl
,QList
<QAction
*>)),
1997 this, SLOT(openContextMenu(QPoint
,KFileItem
,KUrl
,QList
<QAction
*>)));
1998 connect(view
, SIGNAL(directoryLoadingStarted()),
1999 this, SLOT(enableStopAction()));
2000 connect(view
, SIGNAL(directoryLoadingCompleted()),
2001 this, SLOT(disableStopAction()));
2002 connect(view
, SIGNAL(goBackRequested()),
2003 this, SLOT(goBack()));
2004 connect(view
, SIGNAL(goForwardRequested()),
2005 this, SLOT(goForward()));
2007 const KUrlNavigator
* navigator
= container
->urlNavigator();
2008 connect(navigator
, SIGNAL(urlChanged(KUrl
)),
2009 this, SLOT(changeUrl(KUrl
)));
2010 connect(navigator
, SIGNAL(historyChanged()),
2011 this, SLOT(updateHistory()));
2012 connect(navigator
, SIGNAL(editableStateChanged(bool)),
2013 this, SLOT(slotEditableStateChanged(bool)));
2014 connect(navigator
, SIGNAL(tabRequested(KUrl
)),
2015 this, SLOT(openNewTab(KUrl
)));
2018 void DolphinMainWindow::updateSplitAction()
2020 QAction
* splitAction
= actionCollection()->action("split_view");
2021 if (m_viewTab
[m_tabIndex
].secondaryView
) {
2022 if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
2023 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
2024 splitAction
->setToolTip(i18nc("@info", "Close right view"));
2025 splitAction
->setIcon(KIcon("view-right-close"));
2027 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
2028 splitAction
->setToolTip(i18nc("@info", "Close left view"));
2029 splitAction
->setIcon(KIcon("view-left-close"));
2032 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
2033 splitAction
->setToolTip(i18nc("@info", "Split view"));
2034 splitAction
->setIcon(KIcon("view-right-new"));
2038 QString
DolphinMainWindow::tabName(const KUrl
& url
) const
2041 if (url
.equals(KUrl("file:///"))) {
2044 name
= url
.fileName();
2045 if (name
.isEmpty()) {
2046 name
= url
.protocol();
2048 // Make sure that a '&' inside the directory name is displayed correctly
2049 // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
2050 name
.replace('&', "&&");
2056 bool DolphinMainWindow::isKompareInstalled() const
2058 static bool initialized
= false;
2059 static bool installed
= false;
2061 // TODO: maybe replace this approach later by using a menu
2062 // plugin like kdiff3plugin.cpp
2063 installed
= !KGlobal::dirs()->findExe("kompare").isEmpty();
2069 void DolphinMainWindow::createSecondaryView(int tabIndex
)
2071 ViewTab
& viewTab
= m_viewTab
[tabIndex
];
2073 QSplitter
* splitter
= viewTab
.splitter
;
2074 const int newWidth
= (viewTab
.primaryView
->width() - splitter
->handleWidth()) / 2;
2076 const DolphinView
* view
= viewTab
.primaryView
->view();
2077 // The final parent of the new view container will be set by adding it
2078 // to the splitter. However, we must make sure that the DolphinMainWindow
2079 // is a parent of the view container already when it is constructed
2080 // because this enables the container's KFileItemModel to assign its
2081 // dir lister to the right main window. The dir lister can then cache
2082 // authentication data.
2083 viewTab
.secondaryView
= createViewContainer(view
->url(), this);
2084 splitter
->addWidget(viewTab
.secondaryView
);
2085 splitter
->setSizes(QList
<int>() << newWidth
<< newWidth
);
2087 connectViewSignals(viewTab
.secondaryView
);
2088 viewTab
.secondaryView
->setActive(false);
2089 viewTab
.secondaryView
->resize(newWidth
, viewTab
.primaryView
->height());
2090 viewTab
.secondaryView
->show();
2093 QString
DolphinMainWindow::tabProperty(const QString
& property
, int tabIndex
) const
2095 return "Tab " + QString::number(tabIndex
) + ' ' + property
;
2098 void DolphinMainWindow::setUrlAsCaption(const KUrl
& url
)
2101 if (!url
.isLocalFile()) {
2102 caption
.append(url
.protocol() + " - ");
2103 if (url
.hasHost()) {
2104 caption
.append(url
.host() + " - ");
2108 const QString fileName
= url
.fileName().isEmpty() ? "/" : url
.fileName();
2109 caption
.append(fileName
);
2111 setCaption(caption
);
2114 QString
DolphinMainWindow::squeezedText(const QString
& text
) const
2116 const QFontMetrics fm
= fontMetrics();
2117 return fm
.elidedText(text
, Qt::ElideMiddle
, fm
.maxWidth() * 10);
2120 void DolphinMainWindow::createPanelAction(const KIcon
& icon
,
2121 const QKeySequence
& shortcut
,
2122 QAction
* dockAction
,
2123 const QString
& actionName
)
2125 KAction
* panelAction
= actionCollection()->addAction(actionName
);
2126 panelAction
->setCheckable(true);
2127 panelAction
->setChecked(dockAction
->isChecked());
2128 panelAction
->setText(dockAction
->text());
2129 panelAction
->setIcon(icon
);
2130 panelAction
->setShortcut(shortcut
);
2132 connect(panelAction
, SIGNAL(triggered()), dockAction
, SLOT(trigger()));
2133 connect(dockAction
, SIGNAL(toggled(bool)), panelAction
, SLOT(setChecked(bool)));
2136 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
2137 KIO::FileUndoManager::UiInterface()
2141 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2145 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
2147 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
2149 DolphinViewContainer
* container
= mainWin
->activeViewContainer();
2150 container
->showMessage(job
->errorString(), DolphinViewContainer::Error
);
2152 KIO::FileUndoManager::UiInterface::jobError(job
);
2156 #include "dolphinmainwindow.moc"