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 <config-nepomuk.h>
26 #include "dolphinapplication.h"
27 #include "dolphindockwidget.h"
28 #include "dolphincontextmenu.h"
29 #include "dolphinnewfilemenu.h"
30 #include "dolphinviewcontainer.h"
32 #include "panels/search/searchpanel.h"
33 #include <Nepomuk/ResourceManager>
35 #include "panels/folders/folderspanel.h"
36 #include "panels/places/placespanel.h"
37 #include "panels/information/informationpanel.h"
38 #include "search/dolphinsearchbox.h"
39 #include "search/dolphinsearchinformation.h"
40 #include "settings/dolphinsettingsdialog.h"
41 #include "statusbar/dolphinstatusbar.h"
42 #include "views/dolphinviewactionhandler.h"
43 #include "views/dolphinremoteencoding.h"
44 #include "views/draganddrophelper.h"
45 #include "views/viewproperties.h"
48 #include "panels/terminal/terminalpanel.h"
51 #include "dolphin_generalsettings.h"
52 #include "dolphin_searchsettings.h"
54 #include <KAcceleratorManager>
56 #include <KActionCollection>
57 #include <KActionMenu>
59 #include <KDesktopFile>
60 #include <kdeversion.h>
61 #include <kdualaction.h>
62 #include <KFileDialog>
63 #include <KFilePlacesModel>
68 #include <KIconLoader>
69 #include <KIO/NetAccess>
70 #include <KInputDialog>
72 #include <KProtocolManager>
75 #include <KMessageBox>
76 #include <KFileItemListProperties>
77 #include <konqmimedata.h>
78 #include <KProtocolInfo>
81 #include <KStandardDirs>
82 #include <kstatusbar.h>
83 #include <KStandardAction>
85 #include <KToggleAction>
86 #include <KUrlNavigator>
88 #include <KUrlComboBox>
89 #include <KToolInvocation>
91 #include "views/dolphinplacesmodel.h"
93 #include <QDesktopWidget>
94 #include <QDBusMessage>
97 #include <QToolButton>
101 // Used for GeneralSettings::version() to determine whether
102 // an updated version of Dolphin is running.
103 const int CurrentDolphinVersion
= 200;
107 * Remembers the tab configuration if a tab has been closed.
108 * Each closed tab can be restored by the menu
109 * "Go -> Recently Closed Tabs".
117 Q_DECLARE_METATYPE(ClosedTab
)
119 DolphinMainWindow::DolphinMainWindow() :
123 m_activeViewContainer(0),
124 m_centralWidgetLayout(0),
131 m_updateToolBarTimer(0),
132 m_lastHandleUrlStatJob(0),
133 m_searchDockIsTemporaryVisible(false)
135 DolphinPlacesModel::setModel(new KFilePlacesModel(this));
136 connect(DolphinPlacesModel::instance(), SIGNAL(errorMessage(QString
)),
137 this, SLOT(showErrorMessage(QString
)));
139 // Workaround for a X11-issue in combination with KModifierInfo
140 // (see DolphinContextMenu::initializeModifierKeyInfo() for
141 // more information):
142 DolphinContextMenu::initializeModifierKeyInfo();
144 setObjectName("Dolphin#");
146 m_viewTab
.append(ViewTab());
147 ViewTab
& viewTab
= m_viewTab
[m_tabIndex
];
148 viewTab
.wasActive
= true; // The first opened tab is automatically active
150 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
151 undoManager
->setUiInterface(new UndoUiInterface());
153 connect(undoManager
, SIGNAL(undoAvailable(bool)),
154 this, SLOT(slotUndoAvailable(bool)));
155 connect(undoManager
, SIGNAL(undoTextChanged(QString
)),
156 this, SLOT(slotUndoTextChanged(QString
)));
157 connect(undoManager
, SIGNAL(jobRecordingStarted(CommandType
)),
158 this, SLOT(clearStatusBar()));
159 connect(undoManager
, SIGNAL(jobRecordingFinished(CommandType
)),
160 this, SLOT(showCommand(CommandType
)));
162 GeneralSettings
* generalSettings
= GeneralSettings::self();
163 const bool firstRun
= (generalSettings
->version() < 200);
165 generalSettings
->setViewPropsTimestamp(QDateTime::currentDateTime());
168 setAcceptDrops(true);
170 viewTab
.splitter
= new QSplitter(this);
171 viewTab
.splitter
->setChildrenCollapsible(false);
175 const KUrl
homeUrl(generalSettings
->homeUrl());
176 setUrlAsCaption(homeUrl
);
177 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
178 connect(m_actionHandler
, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
179 connect(m_actionHandler
, SIGNAL(createDirectory()), SLOT(createDirectory()));
181 viewTab
.primaryView
= createViewContainer(homeUrl
, viewTab
.splitter
);
183 m_activeViewContainer
= viewTab
.primaryView
;
184 connectViewSignals(m_activeViewContainer
);
185 DolphinView
* view
= m_activeViewContainer
->view();
186 m_activeViewContainer
->show();
187 m_actionHandler
->setCurrentView(view
);
189 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
190 connect(this, SIGNAL(urlChanged(KUrl
)),
191 m_remoteEncoding
, SLOT(slotAboutToOpenUrl()));
193 m_tabBar
= new KTabBar(this);
194 m_tabBar
->setMovable(true);
195 m_tabBar
->setTabsClosable(true);
196 connect(m_tabBar
, SIGNAL(currentChanged(int)),
197 this, SLOT(setActiveTab(int)));
198 connect(m_tabBar
, SIGNAL(tabCloseRequested(int)),
199 this, SLOT(closeTab(int)));
200 connect(m_tabBar
, SIGNAL(contextMenu(int,QPoint
)),
201 this, SLOT(openTabContextMenu(int,QPoint
)));
202 connect(m_tabBar
, SIGNAL(newTabRequest()),
203 this, SLOT(openNewTab()));
204 connect(m_tabBar
, SIGNAL(testCanDecode(const QDragMoveEvent
*,bool&)),
205 this, SLOT(slotTestCanDecode(const QDragMoveEvent
*,bool&)));
206 connect(m_tabBar
, SIGNAL(mouseMiddleClick(int)),
207 this, SLOT(closeTab(int)));
208 connect(m_tabBar
, SIGNAL(tabMoved(int,int)),
209 this, SLOT(slotTabMoved(int,int)));
210 connect(m_tabBar
, SIGNAL(receivedDropEvent(int,QDropEvent
*)),
211 this, SLOT(tabDropEvent(int,QDropEvent
*)));
213 m_tabBar
->blockSignals(true); // signals get unblocked after at least 2 tabs are open
215 QWidget
* centralWidget
= new QWidget(this);
216 m_centralWidgetLayout
= new QVBoxLayout(centralWidget
);
217 m_centralWidgetLayout
->setSpacing(0);
218 m_centralWidgetLayout
->setMargin(0);
219 m_centralWidgetLayout
->addWidget(m_tabBar
);
220 m_centralWidgetLayout
->addWidget(viewTab
.splitter
, 1);
222 setCentralWidget(centralWidget
);
224 emit
urlChanged(homeUrl
);
226 setupGUI(Keys
| Save
| Create
| ToolBar
);
227 stateChanged("new_file");
229 QClipboard
* clipboard
= QApplication::clipboard();
230 connect(clipboard
, SIGNAL(dataChanged()),
231 this, SLOT(updatePasteAction()));
233 if (generalSettings
->splitView()) {
240 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
241 showFilterBarAction
->setChecked(generalSettings
->filterBar());
244 menuBar()->setVisible(false);
245 // Assure a proper default size if Dolphin runs the first time
249 const bool showMenu
= !menuBar()->isHidden();
250 QAction
* showMenuBarAction
= actionCollection()->action(KStandardAction::name(KStandardAction::ShowMenubar
));
251 showMenuBarAction
->setChecked(showMenu
); // workaround for bug #171080
253 createControlButton();
257 DolphinMainWindow::~DolphinMainWindow()
261 void DolphinMainWindow::openDirectories(const QList
<KUrl
>& dirs
)
263 if (dirs
.isEmpty()) {
267 if (dirs
.count() == 1) {
268 m_activeViewContainer
->setUrl(dirs
.first());
272 const int oldOpenTabsCount
= m_viewTab
.count();
274 const bool hasSplitView
= GeneralSettings::splitView();
276 // Open each directory inside a new tab. If the "split view" option has been enabled,
277 // always show two directories within one tab.
278 QList
<KUrl
>::const_iterator it
= dirs
.begin();
279 while (it
!= dirs
.end()) {
283 if (hasSplitView
&& (it
!= dirs
.end())) {
284 const int tabIndex
= m_viewTab
.count() - 1;
285 m_viewTab
[tabIndex
].secondaryView
->setUrl(*it
);
290 // Remove the previously opened tabs
291 for (int i
= 0; i
< oldOpenTabsCount
; ++i
) {
296 void DolphinMainWindow::openFiles(const QList
<KUrl
>& files
)
298 if (files
.isEmpty()) {
302 // Get all distinct directories from 'files' and open a tab
303 // for each directory. If the "split view" option is enabled, two
304 // directories are shown inside one tab (see openDirectories()).
306 foreach (const KUrl
& url
, files
) {
307 const KUrl
dir(url
.directory());
308 if (!dirs
.contains(dir
)) {
313 openDirectories(dirs
);
315 // Select the files. Although the files can be split between several
316 // tabs, there is no need to split 'files' accordingly, as
317 // the DolphinView will just ignore invalid selections.
318 const int tabCount
= m_viewTab
.count();
319 for (int i
= 0; i
< tabCount
; ++i
) {
320 m_viewTab
[i
].primaryView
->view()->markUrlsAsSelected(files
);
321 m_viewTab
[i
].primaryView
->view()->markUrlAsCurrent(files
.at(0));
322 if (m_viewTab
[i
].secondaryView
) {
323 m_viewTab
[i
].secondaryView
->view()->markUrlsAsSelected(files
);
324 m_viewTab
[i
].secondaryView
->view()->markUrlAsCurrent(files
.at(0));
329 void DolphinMainWindow::showCommand(CommandType command
)
331 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
333 case KIO::FileUndoManager::Copy
:
334 statusBar
->setMessage(i18nc("@info:status", "Successfully copied."),
335 DolphinStatusBar::OperationCompleted
);
337 case KIO::FileUndoManager::Move
:
338 statusBar
->setMessage(i18nc("@info:status", "Successfully moved."),
339 DolphinStatusBar::OperationCompleted
);
341 case KIO::FileUndoManager::Link
:
342 statusBar
->setMessage(i18nc("@info:status", "Successfully linked."),
343 DolphinStatusBar::OperationCompleted
);
345 case KIO::FileUndoManager::Trash
:
346 statusBar
->setMessage(i18nc("@info:status", "Successfully moved to trash."),
347 DolphinStatusBar::OperationCompleted
);
349 case KIO::FileUndoManager::Rename
:
350 statusBar
->setMessage(i18nc("@info:status", "Successfully renamed."),
351 DolphinStatusBar::OperationCompleted
);
354 case KIO::FileUndoManager::Mkdir
:
355 statusBar
->setMessage(i18nc("@info:status", "Created folder."),
356 DolphinStatusBar::OperationCompleted
);
364 void DolphinMainWindow::pasteIntoFolder()
366 m_activeViewContainer
->view()->pasteIntoFolder();
369 void DolphinMainWindow::changeUrl(const KUrl
& url
)
371 if (!KProtocolManager::supportsListing(url
)) {
372 // The URL navigator only checks for validity, not
373 // if the URL can be listed. An error message is
374 // shown due to DolphinViewContainer::restoreView().
378 DolphinViewContainer
* view
= activeViewContainer();
384 setUrlAsCaption(url
);
385 if (m_viewTab
.count() > 1) {
386 m_tabBar
->setTabText(m_tabIndex
, squeezedText(tabName(m_activeViewContainer
->url())));
388 const QString iconName
= KMimeType::iconNameForUrl(url
);
389 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(iconName
));
390 emit
urlChanged(url
);
394 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
396 KToggleAction
* editableLocationAction
=
397 static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
398 editableLocationAction
->setChecked(editable
);
401 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
405 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
406 int selectedUrlsCount
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedItemsCount();
407 if (m_viewTab
[m_tabIndex
].secondaryView
) {
408 selectedUrlsCount
+= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItemsCount();
411 QAction
* compareFilesAction
= actionCollection()->action("compare_files");
412 if (selectedUrlsCount
== 2) {
413 compareFilesAction
->setEnabled(isKompareInstalled());
415 compareFilesAction
->setEnabled(false);
418 emit
selectionChanged(selection
);
421 void DolphinMainWindow::slotRequestItemInfo(const KFileItem
& item
)
423 emit
requestItemInfo(item
);
426 void DolphinMainWindow::updateHistory()
428 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
429 const int index
= urlNavigator
->historyIndex();
431 QAction
* backAction
= actionCollection()->action("go_back");
433 backAction
->setToolTip(i18nc("@info", "Go back"));
434 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
437 QAction
* forwardAction
= actionCollection()->action("go_forward");
439 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
440 forwardAction
->setEnabled(index
> 0);
444 void DolphinMainWindow::updateFilterBarAction(bool show
)
446 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
447 showFilterBarAction
->setChecked(show
);
450 void DolphinMainWindow::openNewMainWindow()
452 KRun::run("dolphin", KUrl::List(), this);
455 void DolphinMainWindow::openNewTab()
457 const bool isUrlEditable
= m_activeViewContainer
->urlNavigator()->isUrlEditable();
459 openNewTab(m_activeViewContainer
->url());
460 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
462 // The URL navigator of the new tab should have the same editable state
463 // as the current tab
464 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
465 navigator
->setUrlEditable(isUrlEditable
);
468 // If a new tab is opened and the URL is editable, assure that
469 // the user can edit the URL without manually setting the focus
470 navigator
->setFocus();
474 void DolphinMainWindow::openNewTab(const KUrl
& url
)
476 QWidget
* focusWidget
= QApplication::focusWidget();
478 if (m_viewTab
.count() == 1) {
479 // Only one view is open currently and hence no tab is shown at
480 // all. Before creating a tab for 'url', provide a tab for the current URL.
481 const KUrl currentUrl
= m_activeViewContainer
->url();
482 m_tabBar
->addTab(KIcon(KMimeType::iconNameForUrl(currentUrl
)),
483 squeezedText(tabName(currentUrl
)));
484 m_tabBar
->blockSignals(false);
487 m_tabBar
->addTab(KIcon(KMimeType::iconNameForUrl(url
)),
488 squeezedText(tabName(url
)));
491 viewTab
.splitter
= new QSplitter(this);
492 viewTab
.splitter
->setChildrenCollapsible(false);
493 viewTab
.primaryView
= createViewContainer(url
, viewTab
.splitter
);
494 viewTab
.primaryView
->setActive(false);
495 connectViewSignals(viewTab
.primaryView
);
497 m_viewTab
.append(viewTab
);
499 actionCollection()->action("close_tab")->setEnabled(true);
501 // Provide a split view, if the startup settings are set this way
502 if (GeneralSettings::splitView()) {
503 const int newTabIndex
= m_viewTab
.count() - 1;
504 createSecondaryView(newTabIndex
);
505 m_viewTab
[newTabIndex
].secondaryView
->setActive(true);
506 m_viewTab
[newTabIndex
].isPrimaryViewActive
= false;
510 // The DolphinViewContainer grabbed the keyboard focus. As the tab is opened
511 // in background, assure that the previous focused widget gets the focus back.
512 focusWidget
->setFocus();
516 void DolphinMainWindow::activateNextTab()
518 if (m_viewTab
.count() >= 2) {
519 const int tabIndex
= (m_tabBar
->currentIndex() + 1) % m_tabBar
->count();
520 m_tabBar
->setCurrentIndex(tabIndex
);
524 void DolphinMainWindow::activatePrevTab()
526 if (m_viewTab
.count() >= 2) {
527 int tabIndex
= m_tabBar
->currentIndex() - 1;
528 if (tabIndex
== -1) {
529 tabIndex
= m_tabBar
->count() - 1;
531 m_tabBar
->setCurrentIndex(tabIndex
);
535 void DolphinMainWindow::openInNewTab()
537 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
538 if (list
.isEmpty()) {
539 openNewTab(m_activeViewContainer
->url());
540 } else if ((list
.count() == 1) && list
[0].isDir()) {
541 openNewTab(list
[0].url());
545 void DolphinMainWindow::openInNewWindow()
549 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
550 if (list
.isEmpty()) {
551 newWindowUrl
= m_activeViewContainer
->url();
552 } else if ((list
.count() == 1) && list
[0].isDir()) {
553 newWindowUrl
= list
[0].url();
556 if (!newWindowUrl
.isEmpty()) {
557 KRun::run("dolphin", KUrl::List() << newWindowUrl
, this);
561 void DolphinMainWindow::toggleActiveView()
563 if (!m_viewTab
[m_tabIndex
].secondaryView
) {
564 // only one view is available
568 Q_ASSERT(m_activeViewContainer
);
569 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
571 DolphinViewContainer
* left
= m_viewTab
[m_tabIndex
].primaryView
;
572 DolphinViewContainer
* right
= m_viewTab
[m_tabIndex
].secondaryView
;
573 setActiveViewContainer(m_activeViewContainer
== right
? left
: right
);
576 void DolphinMainWindow::showEvent(QShowEvent
* event
)
578 KXmlGuiWindow::showEvent(event
);
579 if (!event
->spontaneous()) {
580 m_activeViewContainer
->view()->setFocus();
584 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
586 // Find out if Dolphin is closed directly by the user or
587 // by the session manager because the session is closed
588 bool closedByUser
= true;
589 DolphinApplication
*application
= qobject_cast
<DolphinApplication
*>(qApp
);
590 if (application
&& application
->sessionSaving()) {
591 closedByUser
= false;
594 if (m_viewTab
.count() > 1 && GeneralSettings::confirmClosingMultipleTabs() && closedByUser
) {
595 // Ask the user if he really wants to quit and close all tabs.
596 // Open a confirmation dialog with 3 buttons:
597 // KDialog::Yes -> Quit
598 // KDialog::No -> Close only the current tab
599 // KDialog::Cancel -> do nothing
600 KDialog
*dialog
= new KDialog(this, Qt::Dialog
);
601 dialog
->setCaption(i18nc("@title:window", "Confirmation"));
602 dialog
->setButtons(KDialog::Yes
| KDialog::No
| KDialog::Cancel
);
603 dialog
->setModal(true);
604 dialog
->setButtonGuiItem(KDialog::Yes
, KStandardGuiItem::quit());
605 dialog
->setButtonGuiItem(KDialog::No
, KGuiItem(i18n("C&lose Current Tab"), KIcon("tab-close")));
606 dialog
->setButtonGuiItem(KDialog::Cancel
, KStandardGuiItem::cancel());
607 dialog
->setDefaultButton(KDialog::Yes
);
609 bool doNotAskAgainCheckboxResult
= false;
611 const int result
= KMessageBox::createKMessageBox(dialog
,
612 QMessageBox::Warning
,
613 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
615 i18n("Do not ask again"),
616 &doNotAskAgainCheckboxResult
,
617 KMessageBox::Notify
);
619 if (doNotAskAgainCheckboxResult
) {
620 GeneralSettings::setConfirmClosingMultipleTabs(false);
628 // Close only the current tab
636 GeneralSettings::setVersion(CurrentDolphinVersion
);
637 GeneralSettings::self()->writeConfig();
639 if (m_searchDockIsTemporaryVisible
) {
640 QDockWidget
* searchDock
= findChild
<QDockWidget
*>("searchDock");
644 m_searchDockIsTemporaryVisible
= false;
647 KXmlGuiWindow::closeEvent(event
);
650 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
652 const int tabCount
= m_viewTab
.count();
653 group
.writeEntry("Tab Count", tabCount
);
654 group
.writeEntry("Active Tab Index", m_tabBar
->currentIndex());
656 for (int i
= 0; i
< tabCount
; ++i
) {
657 const DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
658 group
.writeEntry(tabProperty("Primary URL", i
), cont
->url().url());
659 group
.writeEntry(tabProperty("Primary Editable", i
),
660 cont
->urlNavigator()->isUrlEditable());
662 cont
= m_viewTab
[i
].secondaryView
;
664 group
.writeEntry(tabProperty("Secondary URL", i
), cont
->url().url());
665 group
.writeEntry(tabProperty("Secondary Editable", i
),
666 cont
->urlNavigator()->isUrlEditable());
671 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
673 const int tabCount
= group
.readEntry("Tab Count", 1);
674 for (int i
= 0; i
< tabCount
; ++i
) {
675 DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
677 cont
->setUrl(group
.readEntry(tabProperty("Primary URL", i
)));
678 const bool editable
= group
.readEntry(tabProperty("Primary Editable", i
), false);
679 cont
->urlNavigator()->setUrlEditable(editable
);
681 cont
= m_viewTab
[i
].secondaryView
;
682 const QString secondaryUrl
= group
.readEntry(tabProperty("Secondary URL", i
));
683 if (!secondaryUrl
.isEmpty()) {
685 // a secondary view should be shown, but no one is available
686 // currently -> create a new view
688 cont
= m_viewTab
[i
].secondaryView
;
692 cont
->setUrl(secondaryUrl
);
693 const bool editable
= group
.readEntry(tabProperty("Secondary Editable", i
), false);
694 cont
->urlNavigator()->setUrlEditable(editable
);
696 // no secondary view should be shown, but the default setting shows
697 // one already -> close the view
701 // openNewTab() needs to be called only tabCount - 1 times
702 if (i
!= tabCount
- 1) {
707 const int index
= group
.readEntry("Active Tab Index", 0);
708 m_tabBar
->setCurrentIndex(index
);
711 void DolphinMainWindow::updateNewMenu()
713 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
714 m_newFileMenu
->checkUpToDate();
715 m_newFileMenu
->setPopupFiles(activeViewContainer()->url());
718 void DolphinMainWindow::createDirectory()
720 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
721 m_newFileMenu
->setPopupFiles(activeViewContainer()->url());
722 m_newFileMenu
->createDirectory();
725 void DolphinMainWindow::quit()
730 void DolphinMainWindow::showErrorMessage(const QString
& message
)
732 if (!message
.isEmpty()) {
733 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
734 statusBar
->setMessage(message
, DolphinStatusBar::Error
);
738 void DolphinMainWindow::slotUndoAvailable(bool available
)
740 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
742 undoAction
->setEnabled(available
);
746 void DolphinMainWindow::restoreClosedTab(QAction
* action
)
748 if (action
->data().toBool()) {
749 // clear all actions except the "Empty Recently Closed Tabs"
750 // action and the separator
751 QList
<QAction
*> actions
= m_recentTabsMenu
->menu()->actions();
752 const int count
= actions
.size();
753 for (int i
= 2; i
< count
; ++i
) {
754 m_recentTabsMenu
->menu()->removeAction(actions
.at(i
));
757 const ClosedTab closedTab
= action
->data().value
<ClosedTab
>();
758 openNewTab(closedTab
.primaryUrl
);
759 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
761 if (closedTab
.isSplit
) {
762 // create secondary view
764 m_viewTab
[m_tabIndex
].secondaryView
->setUrl(closedTab
.secondaryUrl
);
767 m_recentTabsMenu
->removeAction(action
);
770 if (m_recentTabsMenu
->menu()->actions().count() == 2) {
771 m_recentTabsMenu
->setEnabled(false);
775 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
777 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
779 undoAction
->setText(text
);
783 void DolphinMainWindow::undo()
786 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
787 KIO::FileUndoManager::self()->undo();
790 void DolphinMainWindow::cut()
792 m_activeViewContainer
->view()->cutSelectedItems();
795 void DolphinMainWindow::copy()
797 m_activeViewContainer
->view()->copySelectedItems();
800 void DolphinMainWindow::paste()
802 m_activeViewContainer
->view()->paste();
805 void DolphinMainWindow::find()
807 m_activeViewContainer
->setSearchModeEnabled(true);
810 void DolphinMainWindow::slotSearchLocationChanged()
813 QDockWidget
* searchDock
= findChild
<QDockWidget
*>("searchDock");
818 SearchPanel
* searchPanel
= qobject_cast
<SearchPanel
*>(searchDock
->widget());
820 searchPanel
->setSearchLocation(SearchSettings::location() == QLatin1String("FromHere")
821 ? SearchPanel::FromCurrentDir
822 : SearchPanel::Everywhere
);
827 void DolphinMainWindow::updatePasteAction()
829 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
830 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
831 pasteAction
->setEnabled(pasteInfo
.first
);
832 pasteAction
->setText(pasteInfo
.second
);
835 void DolphinMainWindow::selectAll()
839 // if the URL navigator is editable and focused, select the whole
840 // URL instead of all items of the view
842 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
843 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit(); // krazy:exclude=qclasses
844 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
845 lineEdit
->hasFocus();
847 lineEdit
->selectAll();
849 m_activeViewContainer
->view()->selectAll();
853 void DolphinMainWindow::invertSelection()
856 m_activeViewContainer
->view()->invertSelection();
859 void DolphinMainWindow::toggleSplitView()
861 if (!m_viewTab
[m_tabIndex
].secondaryView
) {
862 createSecondaryView(m_tabIndex
);
863 setActiveViewContainer(m_viewTab
[m_tabIndex
].secondaryView
);
864 } else if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
865 // remove secondary view
866 m_viewTab
[m_tabIndex
].secondaryView
->close();
867 m_viewTab
[m_tabIndex
].secondaryView
->deleteLater();
868 m_viewTab
[m_tabIndex
].secondaryView
= 0;
870 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
872 // The primary view is active and should be closed. Hence from a users point of view
873 // the content of the secondary view should be moved to the primary view.
874 // From an implementation point of view it is more efficient to close
875 // the primary view and exchange the internal pointers afterwards.
877 m_viewTab
[m_tabIndex
].primaryView
->close();
878 m_viewTab
[m_tabIndex
].primaryView
->deleteLater();
879 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
880 m_viewTab
[m_tabIndex
].secondaryView
= 0;
882 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
888 void DolphinMainWindow::reloadView()
891 m_activeViewContainer
->view()->reload();
894 void DolphinMainWindow::stopLoading()
896 m_activeViewContainer
->view()->stopLoading();
899 void DolphinMainWindow::enableStopAction()
901 actionCollection()->action("stop")->setEnabled(true);
904 void DolphinMainWindow::disableStopAction()
906 actionCollection()->action("stop")->setEnabled(false);
909 void DolphinMainWindow::showFilterBar()
911 m_activeViewContainer
->setFilterBarVisible(true);
914 void DolphinMainWindow::toggleEditLocation()
918 QAction
* action
= actionCollection()->action("editable_location");
919 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
920 urlNavigator
->setUrlEditable(action
->isChecked());
923 void DolphinMainWindow::replaceLocation()
925 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
926 navigator
->setUrlEditable(true);
927 navigator
->setFocus();
929 // select the whole text of the combo box editor
930 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit(); // krazy:exclude=qclasses
931 lineEdit
->selectAll();
934 void DolphinMainWindow::togglePanelLockState()
936 const bool newLockState
= !GeneralSettings::lockPanels();
937 foreach (QObject
* child
, children()) {
938 DolphinDockWidget
* dock
= qobject_cast
<DolphinDockWidget
*>(child
);
940 dock
->setLocked(newLockState
);
944 GeneralSettings::setLockPanels(newLockState
);
947 void DolphinMainWindow::slotPlacesPanelVisibilityChanged(bool visible
)
949 const int tabCount
= m_viewTab
.count();
950 for (int i
= 0; i
< tabCount
; ++i
) {
951 ViewTab
& tab
= m_viewTab
[i
];
952 Q_ASSERT(tab
.primaryView
);
953 tab
.primaryView
->urlNavigator()->setPlacesSelectorVisible(!visible
);
954 if (tab
.secondaryView
) {
955 tab
.secondaryView
->urlNavigator()->setPlacesSelectorVisible(!visible
);
960 void DolphinMainWindow::goBack()
962 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
963 urlNavigator
->goBack();
965 if (urlNavigator
->locationState().isEmpty()) {
966 // An empty location state indicates a redirection URL,
967 // which must be skipped too
968 urlNavigator
->goBack();
972 void DolphinMainWindow::goForward()
974 m_activeViewContainer
->urlNavigator()->goForward();
977 void DolphinMainWindow::goUp()
979 m_activeViewContainer
->urlNavigator()->goUp();
982 void DolphinMainWindow::goHome()
984 m_activeViewContainer
->urlNavigator()->goHome();
987 void DolphinMainWindow::goBack(Qt::MouseButtons buttons
)
989 // The default case (left button pressed) is handled in goBack().
990 if (buttons
== Qt::MidButton
) {
991 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
992 const int index
= urlNavigator
->historyIndex() + 1;
993 openNewTab(urlNavigator
->locationUrl(index
));
997 void DolphinMainWindow::goForward(Qt::MouseButtons buttons
)
999 // The default case (left button pressed) is handled in goForward().
1000 if (buttons
== Qt::MidButton
) {
1001 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
1002 const int index
= urlNavigator
->historyIndex() - 1;
1003 openNewTab(urlNavigator
->locationUrl(index
));
1007 void DolphinMainWindow::goUp(Qt::MouseButtons buttons
)
1009 // The default case (left button pressed) is handled in goUp().
1010 if (buttons
== Qt::MidButton
) {
1011 openNewTab(activeViewContainer()->url().upUrl());
1015 void DolphinMainWindow::goHome(Qt::MouseButtons buttons
)
1017 // The default case (left button pressed) is handled in goHome().
1018 if (buttons
== Qt::MidButton
) {
1019 openNewTab(GeneralSettings::self()->homeUrl());
1023 void DolphinMainWindow::compareFiles()
1025 // The method is only invoked if exactly 2 files have
1026 // been selected. The selected files may be:
1027 // - both in the primary view
1028 // - both in the secondary view
1029 // - one in the primary view and the other in the secondary
1031 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
1036 KFileItemList items
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedItems();
1038 switch (items
.count()) {
1040 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
);
1041 items
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItems();
1042 Q_ASSERT(items
.count() == 2);
1043 urlA
= items
[0].url();
1044 urlB
= items
[1].url();
1049 urlA
= items
[0].url();
1050 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
);
1051 items
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItems();
1052 Q_ASSERT(items
.count() == 1);
1053 urlB
= items
[0].url();
1058 urlA
= items
[0].url();
1059 urlB
= items
[1].url();
1064 // may not happen: compareFiles may only get invoked if 2
1065 // files are selected
1070 QString
command("kompare -c \"");
1071 command
.append(urlA
.pathOrUrl());
1072 command
.append("\" \"");
1073 command
.append(urlB
.pathOrUrl());
1074 command
.append('\"');
1075 KRun::runCommand(command
, "Kompare", "kompare", this);
1078 void DolphinMainWindow::toggleShowMenuBar()
1080 const bool visible
= menuBar()->isVisible();
1081 menuBar()->setVisible(!visible
);
1083 createControlButton();
1085 deleteControlButton();
1089 void DolphinMainWindow::openTerminal()
1091 QString
dir(QDir::homePath());
1093 // If the given directory is not local, it can still be the URL of an
1094 // ioslave using UDS_LOCAL_PATH which to be converted first.
1095 KUrl url
= KIO::NetAccess::mostLocalUrl(m_activeViewContainer
->url(), this);
1097 //If the URL is local after the above conversion, set the directory.
1098 if (url
.isLocalFile()) {
1099 dir
= url
.toLocalFile();
1102 KToolInvocation::invokeTerminal(QString(), dir
);
1105 void DolphinMainWindow::editSettings()
1107 if (!m_settingsDialog
) {
1108 DolphinViewContainer
* container
= activeViewContainer();
1109 container
->view()->writeSettings();
1111 const KUrl url
= container
->url();
1112 DolphinSettingsDialog
* settingsDialog
= new DolphinSettingsDialog(url
, this);
1113 connect(settingsDialog
, SIGNAL(settingsChanged()), this, SLOT(refreshViews()));
1114 settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1115 settingsDialog
->show();
1116 m_settingsDialog
= settingsDialog
;
1118 m_settingsDialog
.data()->raise();
1122 void DolphinMainWindow::setActiveTab(int index
)
1124 Q_ASSERT(index
>= 0);
1125 Q_ASSERT(index
< m_viewTab
.count());
1126 if (index
== m_tabIndex
) {
1130 // hide current tab content
1131 ViewTab
& hiddenTab
= m_viewTab
[m_tabIndex
];
1132 hiddenTab
.isPrimaryViewActive
= hiddenTab
.primaryView
->isActive();
1133 hiddenTab
.primaryView
->setActive(false);
1134 if (hiddenTab
.secondaryView
) {
1135 hiddenTab
.secondaryView
->setActive(false);
1137 QSplitter
* splitter
= m_viewTab
[m_tabIndex
].splitter
;
1139 m_centralWidgetLayout
->removeWidget(splitter
);
1141 // show active tab content
1144 ViewTab
& viewTab
= m_viewTab
[index
];
1145 m_centralWidgetLayout
->addWidget(viewTab
.splitter
, 1);
1146 viewTab
.primaryView
->show();
1147 if (viewTab
.secondaryView
) {
1148 viewTab
.secondaryView
->show();
1150 viewTab
.splitter
->show();
1152 if (!viewTab
.wasActive
) {
1153 viewTab
.wasActive
= true;
1155 // If the tab has not been activated yet the size of the KItemListView is
1156 // undefined and results in an unwanted animation. To prevent this a
1157 // reloading of the directory gets triggered.
1158 viewTab
.primaryView
->view()->reload();
1159 if (viewTab
.secondaryView
) {
1160 viewTab
.secondaryView
->view()->reload();
1164 setActiveViewContainer(viewTab
.isPrimaryViewActive
? viewTab
.primaryView
:
1165 viewTab
.secondaryView
);
1168 void DolphinMainWindow::closeTab()
1170 closeTab(m_tabBar
->currentIndex());
1173 void DolphinMainWindow::closeTab(int index
)
1175 Q_ASSERT(index
>= 0);
1176 Q_ASSERT(index
< m_viewTab
.count());
1177 if (m_viewTab
.count() == 1) {
1178 // the last tab may never get closed
1182 if (index
== m_tabIndex
) {
1183 // The tab that should be closed is the active tab. Activate the
1184 // previous tab before closing the tab.
1185 m_tabBar
->setCurrentIndex((index
> 0) ? index
- 1 : 1);
1187 rememberClosedTab(index
);
1190 m_viewTab
[index
].primaryView
->deleteLater();
1191 if (m_viewTab
[index
].secondaryView
) {
1192 m_viewTab
[index
].secondaryView
->deleteLater();
1194 m_viewTab
[index
].splitter
->deleteLater();
1195 m_viewTab
.erase(m_viewTab
.begin() + index
);
1197 m_tabBar
->blockSignals(true);
1198 m_tabBar
->removeTab(index
);
1200 if (m_tabIndex
> index
) {
1202 Q_ASSERT(m_tabIndex
>= 0);
1205 // if only one tab is left, also remove the tab entry so that
1206 // closing the last tab is not possible
1207 if (m_viewTab
.count() == 1) {
1208 m_tabBar
->removeTab(0);
1209 actionCollection()->action("close_tab")->setEnabled(false);
1211 m_tabBar
->blockSignals(false);
1215 void DolphinMainWindow::openTabContextMenu(int index
, const QPoint
& pos
)
1219 QAction
* newTabAction
= menu
.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab"));
1220 newTabAction
->setShortcut(actionCollection()->action("new_tab")->shortcut());
1222 QAction
* detachTabAction
= menu
.addAction(KIcon("tab-detach"), i18nc("@action:inmenu", "Detach Tab"));
1224 QAction
* closeOtherTabsAction
= menu
.addAction(KIcon("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs"));
1226 QAction
* closeTabAction
= menu
.addAction(KIcon("tab-close"), i18nc("@action:inmenu", "Close Tab"));
1227 closeTabAction
->setShortcut(actionCollection()->action("close_tab")->shortcut());
1228 QAction
* selectedAction
= menu
.exec(pos
);
1229 if (selectedAction
== newTabAction
) {
1230 const ViewTab
& tab
= m_viewTab
[index
];
1231 Q_ASSERT(tab
.primaryView
);
1232 const KUrl url
= tab
.secondaryView
&& tab
.secondaryView
->isActive() ?
1233 tab
.secondaryView
->url() : tab
.primaryView
->url();
1235 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
1236 } else if (selectedAction
== detachTabAction
) {
1237 const QString
separator(QLatin1Char(' '));
1238 QString command
= QLatin1String("dolphin");
1240 const ViewTab
& tab
= m_viewTab
[index
];
1241 Q_ASSERT(tab
.primaryView
);
1243 command
+= separator
+ tab
.primaryView
->url().url();
1244 if (tab
.secondaryView
) {
1245 command
+= separator
+ tab
.secondaryView
->url().url();
1246 command
+= separator
+ QLatin1String("-split");
1249 KRun::runCommand(command
, this);
1252 } else if (selectedAction
== closeOtherTabsAction
) {
1253 const int count
= m_tabBar
->count();
1254 for (int i
= 0; i
< index
; ++i
) {
1257 for (int i
= index
+ 1; i
< count
; ++i
) {
1260 } else if (selectedAction
== closeTabAction
) {
1265 void DolphinMainWindow::slotTabMoved(int from
, int to
)
1267 m_viewTab
.move(from
, to
);
1268 m_tabIndex
= m_tabBar
->currentIndex();
1271 void DolphinMainWindow::handlePlacesClick(const KUrl
& url
, Qt::MouseButtons buttons
)
1273 if (buttons
& Qt::MidButton
) {
1275 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
1281 void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent
* event
, bool& canDecode
)
1283 canDecode
= KUrl::List::canDecode(event
->mimeData());
1286 void DolphinMainWindow::handleUrl(const KUrl
& url
)
1288 delete m_lastHandleUrlStatJob
;
1289 m_lastHandleUrlStatJob
= 0;
1291 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1292 activeViewContainer()->setUrl(url
);
1293 } else if (KProtocolManager::supportsListing(url
)) {
1294 // stat the URL to see if it is a dir or not
1295 m_lastHandleUrlStatJob
= KIO::stat(url
, KIO::HideProgressInfo
);
1296 connect(m_lastHandleUrlStatJob
, SIGNAL(result(KJob
*)),
1297 this, SLOT(slotHandleUrlStatFinished(KJob
*)));
1300 new KRun(url
, this);
1304 void DolphinMainWindow::slotHandleUrlStatFinished(KJob
* job
)
1306 m_lastHandleUrlStatJob
= 0;
1307 const KIO::UDSEntry entry
= static_cast<KIO::StatJob
*>(job
)->statResult();
1308 const KUrl url
= static_cast<KIO::StatJob
*>(job
)->url();
1309 if (entry
.isDir()) {
1310 activeViewContainer()->setUrl(url
);
1312 new KRun(url
, this);
1316 void DolphinMainWindow::tabDropEvent(int tab
, QDropEvent
* event
)
1318 const KUrl::List urls
= KUrl::List::fromMimeData(event
->mimeData());
1319 if (!urls
.isEmpty() && tab
!= -1) {
1320 const ViewTab
& viewTab
= m_viewTab
[tab
];
1321 const DolphinView
* view
= viewTab
.isPrimaryViewActive
? viewTab
.primaryView
->view()
1322 : viewTab
.secondaryView
->view();
1323 DragAndDropHelper::dropUrls(view
->rootItem(), view
->url(), event
);
1327 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1329 newFileMenu()->setEnabled(isFolderWritable
);
1332 void DolphinMainWindow::slotSearchModeChanged(bool enabled
)
1335 const DolphinSearchInformation
& searchInfo
= DolphinSearchInformation::instance();
1336 if (!searchInfo
.isIndexingEnabled()) {
1340 QDockWidget
* searchDock
= findChild
<QDockWidget
*>("searchDock");
1346 if (!searchDock
->isVisible()) {
1347 m_searchDockIsTemporaryVisible
= true;
1351 if (searchDock
->isVisible() && m_searchDockIsTemporaryVisible
) {
1354 m_searchDockIsTemporaryVisible
= false;
1357 SearchPanel
* searchPanel
= qobject_cast
<SearchPanel
*>(searchDock
->widget());
1363 SearchPanel::SearchLocation searchLocation
= SearchPanel::Everywhere
;
1364 const KUrl url
= m_activeViewContainer
->url();
1365 const bool isSearchUrl
= (url
.protocol() == QLatin1String("nepomuksearch"));
1366 if ((SearchSettings::location() == QLatin1String("FromHere") && !isSearchUrl
)) {
1367 searchLocation
= SearchPanel::FromCurrentDir
;
1369 searchPanel
->setSearchLocation(searchLocation
);
1371 searchPanel
->setSearchLocation(SearchPanel::Everywhere
);
1378 void DolphinMainWindow::openContextMenu(const QPoint
& pos
,
1379 const KFileItem
& item
,
1381 const QList
<QAction
*>& customActions
)
1383 QWeakPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, pos
, item
, url
);
1384 contextMenu
.data()->setCustomActions(customActions
);
1385 const DolphinContextMenu::Command command
= contextMenu
.data()->open();
1388 case DolphinContextMenu::OpenParentFolderInNewWindow
: {
1389 KRun::run("dolphin", KUrl::List() << item
.url().upUrl(), this);
1393 case DolphinContextMenu::OpenParentFolderInNewTab
:
1394 openNewTab(item
.url().upUrl());
1397 case DolphinContextMenu::None
:
1402 delete contextMenu
.data();
1405 void DolphinMainWindow::updateControlMenu()
1407 KMenu
* menu
= qobject_cast
<KMenu
*>(sender());
1410 // All actions get cleared by KMenu::clear(). The sub-menus are deleted
1411 // by connecting to the aboutToHide() signal from the parent-menu.
1414 KActionCollection
* ac
= actionCollection();
1416 // Add "Edit" actions
1417 bool added
= addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Undo
)), menu
) |
1418 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Find
)), menu
) |
1419 addActionToMenu(ac
->action("select_all"), menu
) |
1420 addActionToMenu(ac
->action("invert_selection"), menu
);
1423 menu
->addSeparator();
1426 // Add "View" actions
1427 if (!GeneralSettings::showZoomSlider()) {
1428 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomIn
)), menu
);
1429 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomOut
)), menu
);
1430 menu
->addSeparator();
1433 added
= addActionToMenu(ac
->action("view_mode"), menu
) |
1434 addActionToMenu(ac
->action("sort"), menu
) |
1435 addActionToMenu(ac
->action("additional_info"), menu
) |
1436 addActionToMenu(ac
->action("show_preview"), menu
) |
1437 addActionToMenu(ac
->action("show_in_groups"), menu
) |
1438 addActionToMenu(ac
->action("show_hidden_files"), menu
);
1441 menu
->addSeparator();
1444 added
= addActionToMenu(ac
->action("split_view"), menu
) |
1445 addActionToMenu(ac
->action("reload"), menu
) |
1446 addActionToMenu(ac
->action("view_properties"), menu
);
1448 menu
->addSeparator();
1451 addActionToMenu(ac
->action("panels"), menu
);
1452 KMenu
* locationBarMenu
= new KMenu(i18nc("@action:inmenu", "Location Bar"), menu
);
1453 locationBarMenu
->addAction(ac
->action("editable_location"));
1454 locationBarMenu
->addAction(ac
->action("replace_location"));
1455 menu
->addMenu(locationBarMenu
);
1457 menu
->addSeparator();
1460 KMenu
* goMenu
= new KMenu(i18nc("@action:inmenu", "Go"), menu
);
1461 connect(menu
, SIGNAL(aboutToHide()), goMenu
, SLOT(deleteLater()));
1462 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Back
)));
1463 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Forward
)));
1464 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Up
)));
1465 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Home
)));
1466 goMenu
->addAction(ac
->action("closed_tabs"));
1467 menu
->addMenu(goMenu
);
1470 KMenu
* toolsMenu
= new KMenu(i18nc("@action:inmenu", "Tools"), menu
);
1471 connect(menu
, SIGNAL(aboutToHide()), toolsMenu
, SLOT(deleteLater()));
1472 toolsMenu
->addAction(ac
->action("show_filter_bar"));
1473 toolsMenu
->addAction(ac
->action("compare_files"));
1474 toolsMenu
->addAction(ac
->action("open_terminal"));
1475 toolsMenu
->addAction(ac
->action("change_remote_encoding"));
1476 menu
->addMenu(toolsMenu
);
1478 // Add "Settings" menu entries
1479 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::KeyBindings
)), menu
);
1480 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ConfigureToolbars
)), menu
);
1481 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Preferences
)), menu
);
1484 KMenu
* helpMenu
= new KMenu(i18nc("@action:inmenu", "Help"), menu
);
1485 connect(menu
, SIGNAL(aboutToHide()), helpMenu
, SLOT(deleteLater()));
1486 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::HelpContents
)));
1487 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::WhatsThis
)));
1488 helpMenu
->addSeparator();
1489 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ReportBug
)));
1490 helpMenu
->addSeparator();
1491 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
)));
1492 helpMenu
->addSeparator();
1493 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::AboutApp
)));
1494 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::AboutKDE
)));
1495 menu
->addMenu(helpMenu
);
1497 menu
->addSeparator();
1498 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ShowMenubar
)), menu
);
1501 void DolphinMainWindow::updateToolBar()
1503 if (!menuBar()->isVisible()) {
1504 createControlButton();
1508 void DolphinMainWindow::slotControlButtonDeleted()
1510 m_controlButton
= 0;
1511 m_updateToolBarTimer
->start();
1514 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer
* viewContainer
)
1516 Q_ASSERT(viewContainer
);
1517 Q_ASSERT((viewContainer
== m_viewTab
[m_tabIndex
].primaryView
) ||
1518 (viewContainer
== m_viewTab
[m_tabIndex
].secondaryView
));
1519 if (m_activeViewContainer
== viewContainer
) {
1523 m_activeViewContainer
->setActive(false);
1524 m_activeViewContainer
= viewContainer
;
1526 // Activating the view container might trigger a recursive setActiveViewContainer() call
1527 // inside DolphinMainWindow::toggleActiveView() when having a split view. Temporary
1528 // disconnect the activated() signal in this case:
1529 disconnect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1530 m_activeViewContainer
->setActive(true);
1531 connect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1533 m_actionHandler
->setCurrentView(viewContainer
->view());
1536 updateEditActions();
1537 updateViewActions();
1540 const KUrl url
= m_activeViewContainer
->url();
1541 setUrlAsCaption(url
);
1542 if (m_viewTab
.count() > 1) {
1543 m_tabBar
->setTabText(m_tabIndex
, tabName(url
));
1544 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(KMimeType::iconNameForUrl(url
)));
1547 emit
urlChanged(url
);
1550 DolphinViewContainer
* DolphinMainWindow::createViewContainer(const KUrl
& url
, QWidget
* parent
)
1552 DolphinViewContainer
* container
= new DolphinViewContainer(url
, parent
);
1554 // The places-selector from the URL navigator should only be shown
1555 // if the places dock is invisible
1556 QDockWidget
* placesDock
= findChild
<QDockWidget
*>("placesDock");
1557 container
->urlNavigator()->setPlacesSelectorVisible(!placesDock
|| !placesDock
->isVisible());
1562 void DolphinMainWindow::setupActions()
1564 // setup 'File' menu
1565 m_newFileMenu
= new DolphinNewFileMenu(this);
1566 KMenu
* menu
= m_newFileMenu
->menu();
1567 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1568 menu
->setIcon(KIcon("document-new"));
1569 connect(menu
, SIGNAL(aboutToShow()),
1570 this, SLOT(updateNewMenu()));
1572 KAction
* newWindow
= actionCollection()->addAction("new_window");
1573 newWindow
->setIcon(KIcon("window-new"));
1574 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1575 newWindow
->setShortcut(Qt::CTRL
| Qt::Key_N
);
1576 connect(newWindow
, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1578 KAction
* newTab
= actionCollection()->addAction("new_tab");
1579 newTab
->setIcon(KIcon("tab-new"));
1580 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1581 newTab
->setShortcut(KShortcut(Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
));
1582 connect(newTab
, SIGNAL(triggered()), this, SLOT(openNewTab()));
1584 KAction
* closeTab
= actionCollection()->addAction("close_tab");
1585 closeTab
->setIcon(KIcon("tab-close"));
1586 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1587 closeTab
->setShortcut(Qt::CTRL
| Qt::Key_W
);
1588 closeTab
->setEnabled(false);
1589 connect(closeTab
, SIGNAL(triggered()), this, SLOT(closeTab()));
1591 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1593 // setup 'Edit' menu
1594 KStandardAction::undo(this,
1596 actionCollection());
1598 // need to remove shift+del from cut action, else the shortcut for deletejob
1600 KAction
* cut
= KStandardAction::cut(this, SLOT(cut()), actionCollection());
1601 KShortcut cutShortcut
= cut
->shortcut();
1602 cutShortcut
.remove(Qt::SHIFT
| Qt::Key_Delete
, KShortcut::KeepEmpty
);
1603 cut
->setShortcut(cutShortcut
);
1604 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1605 KAction
* paste
= KStandardAction::paste(this, SLOT(paste()), actionCollection());
1606 // The text of the paste-action is modified dynamically by Dolphin
1607 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1608 // due to the long text, the text "Paste" is used:
1609 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1611 KStandardAction::find(this, SLOT(find()), actionCollection());
1613 KAction
* selectAll
= actionCollection()->addAction("select_all");
1614 selectAll
->setText(i18nc("@action:inmenu Edit", "Select All"));
1615 selectAll
->setShortcut(Qt::CTRL
| Qt::Key_A
);
1616 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
1618 KAction
* invertSelection
= actionCollection()->addAction("invert_selection");
1619 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1620 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1621 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
1623 // setup 'View' menu
1624 // (note that most of it is set up in DolphinViewActionHandler)
1626 KAction
* split
= actionCollection()->addAction("split_view");
1627 split
->setShortcut(Qt::Key_F3
);
1628 updateSplitAction();
1629 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1631 KAction
* reload
= actionCollection()->addAction("reload");
1632 reload
->setText(i18nc("@action:inmenu View", "Reload"));
1633 reload
->setShortcut(Qt::Key_F5
);
1634 reload
->setIcon(KIcon("view-refresh"));
1635 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
1637 KAction
* stop
= actionCollection()->addAction("stop");
1638 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1639 stop
->setToolTip(i18nc("@info", "Stop loading"));
1640 stop
->setIcon(KIcon("process-stop"));
1641 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
1643 KToggleAction
* editableLocation
= actionCollection()->add
<KToggleAction
>("editable_location");
1644 editableLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1645 editableLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
1646 connect(editableLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1648 KAction
* replaceLocation
= actionCollection()->addAction("replace_location");
1649 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1650 replaceLocation
->setShortcut(Qt::Key_F6
);
1651 connect(replaceLocation
, SIGNAL(triggered()), this, SLOT(replaceLocation()));
1654 KAction
* backAction
= KStandardAction::back(this, SLOT(goBack()), actionCollection());
1655 connect(backAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goBack(Qt::MouseButtons
)));
1656 KShortcut backShortcut
= backAction
->shortcut();
1657 backShortcut
.setAlternate(Qt::Key_Backspace
);
1658 backAction
->setShortcut(backShortcut
);
1660 m_recentTabsMenu
= new KActionMenu(i18n("Recently Closed Tabs"), this);
1661 m_recentTabsMenu
->setIcon(KIcon("edit-undo"));
1662 actionCollection()->addAction("closed_tabs", m_recentTabsMenu
);
1663 connect(m_recentTabsMenu
->menu(), SIGNAL(triggered(QAction
*)),
1664 this, SLOT(restoreClosedTab(QAction
*)));
1666 QAction
* action
= new QAction(i18n("Empty Recently Closed Tabs"), m_recentTabsMenu
);
1667 action
->setIcon(KIcon("edit-clear-list"));
1668 action
->setData(QVariant::fromValue(true));
1669 m_recentTabsMenu
->addAction(action
);
1670 m_recentTabsMenu
->addSeparator();
1671 m_recentTabsMenu
->setEnabled(false);
1673 KAction
* forwardAction
= KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1674 connect(forwardAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goForward(Qt::MouseButtons
)));
1676 KAction
* upAction
= KStandardAction::up(this, SLOT(goUp()), actionCollection());
1677 connect(upAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goUp(Qt::MouseButtons
)));
1679 KAction
* homeAction
= KStandardAction::home(this, SLOT(goHome()), actionCollection());
1680 connect(homeAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goHome(Qt::MouseButtons
)));
1682 // setup 'Tools' menu
1683 KAction
* showFilterBar
= actionCollection()->addAction("show_filter_bar");
1684 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1685 showFilterBar
->setIcon(KIcon("view-filter"));
1686 showFilterBar
->setShortcut(Qt::CTRL
| Qt::Key_I
);
1687 connect(showFilterBar
, SIGNAL(triggered()), this, SLOT(showFilterBar()));
1689 KAction
* compareFiles
= actionCollection()->addAction("compare_files");
1690 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1691 compareFiles
->setIcon(KIcon("kompare"));
1692 compareFiles
->setEnabled(false);
1693 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
1695 KAction
* openTerminal
= actionCollection()->addAction("open_terminal");
1696 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1697 openTerminal
->setIcon(KIcon("utilities-terminal"));
1698 openTerminal
->setShortcut(Qt::SHIFT
| Qt::Key_F4
);
1699 connect(openTerminal
, SIGNAL(triggered()), this, SLOT(openTerminal()));
1701 // setup 'Settings' menu
1702 KToggleAction
* showMenuBar
= KStandardAction::showMenubar(0, 0, actionCollection());
1703 connect(showMenuBar
, SIGNAL(triggered(bool)), // Fixes #286822
1704 this, SLOT(toggleShowMenuBar()), Qt::QueuedConnection
);
1705 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1707 // not in menu actions
1708 QList
<QKeySequence
> nextTabKeys
;
1709 nextTabKeys
.append(KStandardShortcut::tabNext().primary());
1710 nextTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::Key_Tab
));
1712 QList
<QKeySequence
> prevTabKeys
;
1713 prevTabKeys
.append(KStandardShortcut::tabPrev().primary());
1714 prevTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::SHIFT
| Qt::Key_Tab
));
1716 KAction
* activateNextTab
= actionCollection()->addAction("activate_next_tab");
1717 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1718 connect(activateNextTab
, SIGNAL(triggered()), SLOT(activateNextTab()));
1719 activateNextTab
->setShortcuts(QApplication::isRightToLeft() ? prevTabKeys
: nextTabKeys
);
1721 KAction
* activatePrevTab
= actionCollection()->addAction("activate_prev_tab");
1722 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1723 connect(activatePrevTab
, SIGNAL(triggered()), SLOT(activatePrevTab()));
1724 activatePrevTab
->setShortcuts(QApplication::isRightToLeft() ? nextTabKeys
: prevTabKeys
);
1727 KAction
* openInNewTab
= actionCollection()->addAction("open_in_new_tab");
1728 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1729 openInNewTab
->setIcon(KIcon("tab-new"));
1730 connect(openInNewTab
, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1732 KAction
* openInNewWindow
= actionCollection()->addAction("open_in_new_window");
1733 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1734 openInNewWindow
->setIcon(KIcon("window-new"));
1735 connect(openInNewWindow
, SIGNAL(triggered()), this, SLOT(openInNewWindow()));
1738 void DolphinMainWindow::setupDockWidgets()
1740 const bool lock
= GeneralSettings::lockPanels();
1742 KDualAction
* lockLayoutAction
= actionCollection()->add
<KDualAction
>("lock_panels");
1743 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
1744 lockLayoutAction
->setActiveIcon(KIcon("object-unlocked"));
1745 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
1746 lockLayoutAction
->setInactiveIcon(KIcon("object-locked"));
1747 lockLayoutAction
->setActive(lock
);
1748 connect(lockLayoutAction
, SIGNAL(triggered()), this, SLOT(togglePanelLockState()));
1750 // Setup "Information"
1751 DolphinDockWidget
* infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
1752 infoDock
->setLocked(lock
);
1753 infoDock
->setObjectName("infoDock");
1754 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1755 Panel
* infoPanel
= new InformationPanel(infoDock
);
1756 infoPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1757 connect(infoPanel
, SIGNAL(urlActivated(KUrl
)), this, SLOT(handleUrl(KUrl
)));
1758 infoDock
->setWidget(infoPanel
);
1760 QAction
* infoAction
= infoDock
->toggleViewAction();
1761 createPanelAction(KIcon("dialog-information"), Qt::Key_F11
, infoAction
, "show_information_panel");
1763 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1764 connect(this, SIGNAL(urlChanged(KUrl
)),
1765 infoPanel
, SLOT(setUrl(KUrl
)));
1766 connect(this, SIGNAL(selectionChanged(KFileItemList
)),
1767 infoPanel
, SLOT(setSelection(KFileItemList
)));
1768 connect(this, SIGNAL(requestItemInfo(KFileItem
)),
1769 infoPanel
, SLOT(requestDelayedItemInfo(KFileItem
)));
1772 DolphinDockWidget
* foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
1773 foldersDock
->setLocked(lock
);
1774 foldersDock
->setObjectName("foldersDock");
1775 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1776 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1777 foldersPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1778 foldersDock
->setWidget(foldersPanel
);
1780 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1781 createPanelAction(KIcon("folder"), Qt::Key_F7
, foldersAction
, "show_folders_panel");
1783 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1784 connect(this, SIGNAL(urlChanged(KUrl
)),
1785 foldersPanel
, SLOT(setUrl(KUrl
)));
1786 connect(foldersPanel
, SIGNAL(changeUrl(KUrl
,Qt::MouseButtons
)),
1787 this, SLOT(handlePlacesClick(KUrl
,Qt::MouseButtons
)));
1791 DolphinDockWidget
* terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1792 terminalDock
->setLocked(lock
);
1793 terminalDock
->setObjectName("terminalDock");
1794 terminalDock
->setAllowedAreas(Qt::TopDockWidgetArea
| Qt::BottomDockWidgetArea
);
1795 Panel
* terminalPanel
= new TerminalPanel(terminalDock
);
1796 terminalPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1797 terminalDock
->setWidget(terminalPanel
);
1799 connect(terminalPanel
, SIGNAL(hideTerminalPanel()), terminalDock
, SLOT(hide()));
1800 connect(terminalDock
, SIGNAL(visibilityChanged(bool)),
1801 terminalPanel
, SLOT(dockVisibilityChanged()));
1803 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1804 createPanelAction(KIcon("utilities-terminal"), Qt::Key_F4
, terminalAction
, "show_terminal_panel");
1806 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1807 connect(this, SIGNAL(urlChanged(KUrl
)),
1808 terminalPanel
, SLOT(setUrl(KUrl
)));
1813 DolphinDockWidget
* searchDock
= new DolphinDockWidget(i18nc("@title:window", "Search"));
1814 searchDock
->setLocked(lock
);
1815 searchDock
->setObjectName("searchDock");
1816 searchDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1817 Panel
* searchPanel
= new SearchPanel(searchDock
);
1818 searchPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1819 connect(searchPanel
, SIGNAL(urlActivated(KUrl
)), this, SLOT(handleUrl(KUrl
)));
1820 searchDock
->setWidget(searchPanel
);
1822 QAction
* searchAction
= searchDock
->toggleViewAction();
1823 createPanelAction(KIcon("system-search"), Qt::Key_F12
, searchAction
, "show_search_panel");
1824 addDockWidget(Qt::RightDockWidgetArea
, searchDock
);
1825 connect(this, SIGNAL(urlChanged(KUrl
)),
1826 searchPanel
, SLOT(setUrl(KUrl
)));
1829 if (GeneralSettings::version() < 200) {
1831 foldersDock
->hide();
1833 terminalDock
->hide();
1841 DolphinDockWidget
* placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
1842 placesDock
->setLocked(lock
);
1843 placesDock
->setObjectName("placesDock");
1844 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1846 PlacesPanel
* placesPanel
= new PlacesPanel(placesDock
);
1847 QAction
* separator
= new QAction(placesPanel
);
1848 separator
->setSeparator(true);
1849 QList
<QAction
*> placesActions
;
1850 placesActions
.append(separator
);
1851 placesActions
.append(lockLayoutAction
);
1852 placesPanel
->addActions(placesActions
);
1853 placesPanel
->setModel(DolphinPlacesModel::instance());
1854 placesPanel
->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff
);
1855 placesDock
->setWidget(placesPanel
);
1857 QAction
* placesAction
= placesDock
->toggleViewAction();
1858 createPanelAction(KIcon("bookmarks"), Qt::Key_F9
, placesAction
, "show_places_panel");
1860 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1861 connect(placesPanel
, SIGNAL(urlChanged(KUrl
,Qt::MouseButtons
)),
1862 this, SLOT(handlePlacesClick(KUrl
,Qt::MouseButtons
)));
1863 connect(this, SIGNAL(urlChanged(KUrl
)),
1864 placesPanel
, SLOT(setUrl(KUrl
)));
1865 connect(placesDock
, SIGNAL(visibilityChanged(bool)),
1866 this, SLOT(slotPlacesPanelVisibilityChanged(bool)));
1868 // Add actions into the "Panels" menu
1869 KActionMenu
* panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Panels"), this);
1870 actionCollection()->addAction("panels", panelsMenu
);
1871 panelsMenu
->setDelayed(false);
1872 const KActionCollection
* ac
= actionCollection();
1873 panelsMenu
->addAction(ac
->action("show_places_panel"));
1874 panelsMenu
->addAction(ac
->action("show_information_panel"));
1875 panelsMenu
->addAction(ac
->action("show_folders_panel"));
1877 panelsMenu
->addAction(ac
->action("show_terminal_panel"));
1880 panelsMenu
->addAction(ac
->action("show_search_panel"));
1882 panelsMenu
->addSeparator();
1883 panelsMenu
->addAction(lockLayoutAction
);
1886 void DolphinMainWindow::updateEditActions()
1888 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1889 if (list
.isEmpty()) {
1890 stateChanged("has_no_selection");
1892 stateChanged("has_selection");
1894 KActionCollection
* col
= actionCollection();
1895 QAction
* renameAction
= col
->action("rename");
1896 QAction
* moveToTrashAction
= col
->action("move_to_trash");
1897 QAction
* deleteAction
= col
->action("delete");
1898 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
1899 QAction
* deleteWithTrashShortcut
= col
->action("delete_shortcut"); // see DolphinViewActionHandler
1901 KFileItemListProperties
capabilities(list
);
1902 const bool enableMoveToTrash
= capabilities
.isLocal() && capabilities
.supportsMoving();
1904 renameAction
->setEnabled(capabilities
.supportsMoving());
1905 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1906 deleteAction
->setEnabled(capabilities
.supportsDeleting());
1907 deleteWithTrashShortcut
->setEnabled(capabilities
.supportsDeleting() && !enableMoveToTrash
);
1908 cutAction
->setEnabled(capabilities
.supportsMoving());
1910 updatePasteAction();
1913 void DolphinMainWindow::updateViewActions()
1915 m_actionHandler
->updateViewActions();
1917 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1918 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
1920 updateSplitAction();
1922 QAction
* editableLocactionAction
= actionCollection()->action("editable_location");
1923 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
1924 editableLocactionAction
->setChecked(urlNavigator
->isUrlEditable());
1927 void DolphinMainWindow::updateGoActions()
1929 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
1930 const KUrl currentUrl
= m_activeViewContainer
->url();
1931 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
1934 void DolphinMainWindow::createControlButton()
1936 if (m_controlButton
) {
1939 Q_ASSERT(!m_controlButton
);
1941 m_controlButton
= new QToolButton(this);
1942 m_controlButton
->setIcon(KIcon("applications-system"));
1943 m_controlButton
->setText(i18nc("@action", "Control"));
1944 m_controlButton
->setPopupMode(QToolButton::InstantPopup
);
1945 m_controlButton
->setToolButtonStyle(toolBar()->toolButtonStyle());
1947 KMenu
* controlMenu
= new KMenu(m_controlButton
);
1948 connect(controlMenu
, SIGNAL(aboutToShow()), this, SLOT(updateControlMenu()));
1950 m_controlButton
->setMenu(controlMenu
);
1952 toolBar()->addWidget(m_controlButton
);
1953 connect(toolBar(), SIGNAL(iconSizeChanged(QSize
)),
1954 m_controlButton
, SLOT(setIconSize(QSize
)));
1955 connect(toolBar(), SIGNAL(toolButtonStyleChanged(Qt::ToolButtonStyle
)),
1956 m_controlButton
, SLOT(setToolButtonStyle(Qt::ToolButtonStyle
)));
1958 // The added widgets are owned by the toolbar and may get deleted when e.g. the toolbar
1959 // gets edited. In this case we must add them again. The adding is done asynchronously by
1960 // m_updateToolBarTimer.
1961 connect(m_controlButton
, SIGNAL(destroyed()), this, SLOT(slotControlButtonDeleted()));
1962 m_updateToolBarTimer
= new QTimer(this);
1963 m_updateToolBarTimer
->setInterval(500);
1964 connect(m_updateToolBarTimer
, SIGNAL(timeout()), this, SLOT(updateToolBar()));
1967 void DolphinMainWindow::deleteControlButton()
1969 delete m_controlButton
;
1970 m_controlButton
= 0;
1972 delete m_updateToolBarTimer
;
1973 m_updateToolBarTimer
= 0;
1976 bool DolphinMainWindow::addActionToMenu(QAction
* action
, KMenu
* menu
)
1981 const KToolBar
* toolBarWidget
= toolBar();
1982 foreach (const QWidget
* widget
, action
->associatedWidgets()) {
1983 if (widget
== toolBarWidget
) {
1988 menu
->addAction(action
);
1992 void DolphinMainWindow::rememberClosedTab(int index
)
1994 KMenu
* tabsMenu
= m_recentTabsMenu
->menu();
1996 const QString primaryPath
= m_viewTab
[index
].primaryView
->url().path();
1997 const QString iconName
= KMimeType::iconNameForUrl(primaryPath
);
1999 QAction
* action
= new QAction(squeezedText(primaryPath
), tabsMenu
);
2001 ClosedTab closedTab
;
2002 closedTab
.primaryUrl
= m_viewTab
[index
].primaryView
->url();
2004 if (m_viewTab
[index
].secondaryView
) {
2005 closedTab
.secondaryUrl
= m_viewTab
[index
].secondaryView
->url();
2006 closedTab
.isSplit
= true;
2008 closedTab
.isSplit
= false;
2011 action
->setData(QVariant::fromValue(closedTab
));
2012 action
->setIcon(KIcon(iconName
));
2014 // add the closed tab menu entry after the separator and
2015 // "Empty Recently Closed Tabs" entry
2016 if (tabsMenu
->actions().size() == 2) {
2017 tabsMenu
->addAction(action
);
2019 tabsMenu
->insertAction(tabsMenu
->actions().at(2), action
);
2022 // assure that only up to 8 closed tabs are shown in the menu
2023 if (tabsMenu
->actions().size() > 8) {
2024 tabsMenu
->removeAction(tabsMenu
->actions().last());
2026 actionCollection()->action("closed_tabs")->setEnabled(true);
2027 KAcceleratorManager::manage(tabsMenu
);
2030 void DolphinMainWindow::refreshViews()
2032 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
2034 // remember the current active view, as because of
2035 // the refreshing the active view might change to
2036 // the secondary view
2037 DolphinViewContainer
* activeViewContainer
= m_activeViewContainer
;
2039 const int tabCount
= m_viewTab
.count();
2040 for (int i
= 0; i
< tabCount
; ++i
) {
2041 m_viewTab
[i
].primaryView
->readSettings();
2042 if (m_viewTab
[i
].secondaryView
) {
2043 m_viewTab
[i
].secondaryView
->readSettings();
2047 setActiveViewContainer(activeViewContainer
);
2049 if (GeneralSettings::modifiedStartupSettings()) {
2050 // The startup settings have been changed by the user (see bug #254947).
2051 // Synchronize the split-view setting with the active view:
2052 const bool splitView
= GeneralSettings::splitView();
2053 const ViewTab
& activeTab
= m_viewTab
[m_tabIndex
];
2054 const bool toggle
= ( splitView
&& !activeTab
.secondaryView
)
2055 || (!splitView
&& activeTab
.secondaryView
);
2062 void DolphinMainWindow::clearStatusBar()
2064 m_activeViewContainer
->statusBar()->clear();
2067 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
2069 connect(container
, SIGNAL(showFilterBarChanged(bool)),
2070 this, SLOT(updateFilterBarAction(bool)));
2071 connect(container
, SIGNAL(writeStateChanged(bool)),
2072 this, SLOT(slotWriteStateChanged(bool)));
2073 connect(container
, SIGNAL(searchModeChanged(bool)),
2074 this, SLOT(slotSearchModeChanged(bool)));
2076 const DolphinSearchBox
* searchBox
= container
->searchBox();
2077 connect(searchBox
, SIGNAL(searchLocationChanged(SearchLocation
)),
2078 this, SLOT(slotSearchLocationChanged()));
2080 DolphinView
* view
= container
->view();
2081 connect(view
, SIGNAL(selectionChanged(KFileItemList
)),
2082 this, SLOT(slotSelectionChanged(KFileItemList
)));
2083 connect(view
, SIGNAL(requestItemInfo(KFileItem
)),
2084 this, SLOT(slotRequestItemInfo(KFileItem
)));
2085 connect(view
, SIGNAL(activated()),
2086 this, SLOT(toggleActiveView()));
2087 connect(view
, SIGNAL(tabRequested(KUrl
)),
2088 this, SLOT(openNewTab(KUrl
)));
2089 connect(view
, SIGNAL(requestContextMenu(QPoint
,KFileItem
,KUrl
,QList
<QAction
*>)),
2090 this, SLOT(openContextMenu(QPoint
,KFileItem
,KUrl
,QList
<QAction
*>)));
2091 connect(view
, SIGNAL(dirLoadingStarted()),
2092 this, SLOT(enableStopAction()));
2093 connect(view
, SIGNAL(dirLoadingCompleted()),
2094 this, SLOT(disableStopAction()));
2095 connect(view
, SIGNAL(goBackRequested()),
2096 this, SLOT(goBack()));
2097 connect(view
, SIGNAL(goForwardRequested()),
2098 this, SLOT(goForward()));
2100 const KUrlNavigator
* navigator
= container
->urlNavigator();
2101 connect(navigator
, SIGNAL(urlChanged(KUrl
)),
2102 this, SLOT(changeUrl(KUrl
)));
2103 connect(navigator
, SIGNAL(historyChanged()),
2104 this, SLOT(updateHistory()));
2105 connect(navigator
, SIGNAL(editableStateChanged(bool)),
2106 this, SLOT(slotEditableStateChanged(bool)));
2107 connect(navigator
, SIGNAL(tabRequested(KUrl
)),
2108 this, SLOT(openNewTab(KUrl
)));
2111 void DolphinMainWindow::updateSplitAction()
2113 QAction
* splitAction
= actionCollection()->action("split_view");
2114 if (m_viewTab
[m_tabIndex
].secondaryView
) {
2115 if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
2116 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
2117 splitAction
->setToolTip(i18nc("@info", "Close right view"));
2118 splitAction
->setIcon(KIcon("view-right-close"));
2120 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
2121 splitAction
->setToolTip(i18nc("@info", "Close left view"));
2122 splitAction
->setIcon(KIcon("view-left-close"));
2125 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
2126 splitAction
->setToolTip(i18nc("@info", "Split view"));
2127 splitAction
->setIcon(KIcon("view-right-new"));
2131 QString
DolphinMainWindow::tabName(const KUrl
& url
) const
2134 if (url
.equals(KUrl("file:///"))) {
2137 name
= url
.fileName();
2138 if (name
.isEmpty()) {
2139 name
= url
.protocol();
2141 // Make sure that a '&' inside the directory name is displayed correctly
2142 // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
2143 name
.replace('&', "&&");
2149 bool DolphinMainWindow::isKompareInstalled() const
2151 static bool initialized
= false;
2152 static bool installed
= false;
2154 // TODO: maybe replace this approach later by using a menu
2155 // plugin like kdiff3plugin.cpp
2156 installed
= !KGlobal::dirs()->findExe("kompare").isEmpty();
2162 void DolphinMainWindow::createSecondaryView(int tabIndex
)
2164 ViewTab
& viewTab
= m_viewTab
[tabIndex
];
2166 QSplitter
* splitter
= viewTab
.splitter
;
2167 const int newWidth
= (viewTab
.primaryView
->width() - splitter
->handleWidth()) / 2;
2169 const DolphinView
* view
= viewTab
.primaryView
->view();
2170 viewTab
.secondaryView
= createViewContainer(view
->url(), 0);
2171 splitter
->addWidget(viewTab
.secondaryView
);
2172 splitter
->setSizes(QList
<int>() << newWidth
<< newWidth
);
2174 connectViewSignals(viewTab
.secondaryView
);
2175 viewTab
.secondaryView
->setActive(false);
2176 viewTab
.secondaryView
->resize(newWidth
, viewTab
.primaryView
->height());
2177 viewTab
.secondaryView
->show();
2180 QString
DolphinMainWindow::tabProperty(const QString
& property
, int tabIndex
) const
2182 return "Tab " + QString::number(tabIndex
) + ' ' + property
;
2185 void DolphinMainWindow::setUrlAsCaption(const KUrl
& url
)
2188 if (!url
.isLocalFile()) {
2189 caption
.append(url
.protocol() + " - ");
2190 if (url
.hasHost()) {
2191 caption
.append(url
.host() + " - ");
2195 const QString fileName
= url
.fileName().isEmpty() ? "/" : url
.fileName();
2196 caption
.append(fileName
);
2198 setCaption(caption
);
2201 QString
DolphinMainWindow::squeezedText(const QString
& text
) const
2203 const QFontMetrics fm
= fontMetrics();
2204 return fm
.elidedText(text
, Qt::ElideMiddle
, fm
.maxWidth() * 10);
2207 void DolphinMainWindow::createPanelAction(const KIcon
& icon
,
2208 const QKeySequence
& shortcut
,
2209 QAction
* dockAction
,
2210 const QString
& actionName
)
2212 KAction
* panelAction
= actionCollection()->addAction(actionName
);
2213 panelAction
->setCheckable(true);
2214 panelAction
->setChecked(dockAction
->isChecked());
2215 panelAction
->setText(dockAction
->text());
2216 panelAction
->setIcon(icon
);
2217 panelAction
->setShortcut(shortcut
);
2219 connect(panelAction
, SIGNAL(triggered()), dockAction
, SLOT(trigger()));
2220 connect(dockAction
, SIGNAL(toggled(bool)), panelAction
, SLOT(setChecked(bool)));
2223 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
2224 KIO::FileUndoManager::UiInterface()
2228 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2232 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
2234 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
2236 DolphinStatusBar
* statusBar
= mainWin
->activeViewContainer()->statusBar();
2237 statusBar
->setMessage(job
->errorString(), DolphinStatusBar::Error
);
2239 KIO::FileUndoManager::UiInterface::jobError(job
);
2243 #include "dolphinmainwindow.moc"