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 <KIO/JobUiDelegate>
71 #include <KInputDialog>
73 #include <KProtocolManager>
76 #include <KMessageBox>
77 #include <KFileItemListProperties>
78 #include <konqmimedata.h>
79 #include <KProtocolInfo>
82 #include <KStandardDirs>
83 #include <kstatusbar.h>
84 #include <KStandardAction>
86 #include <KToggleAction>
87 #include <KUrlNavigator>
89 #include <KUrlComboBox>
90 #include <KToolInvocation>
92 #include "views/dolphinplacesmodel.h"
94 #include <QDesktopWidget>
95 #include <QDBusMessage>
98 #include <QToolButton>
102 // Used for GeneralSettings::version() to determine whether
103 // an updated version of Dolphin is running.
104 const int CurrentDolphinVersion
= 200;
108 * Remembers the tab configuration if a tab has been closed.
109 * Each closed tab can be restored by the menu
110 * "Go -> Recently Closed Tabs".
118 Q_DECLARE_METATYPE(ClosedTab
)
120 DolphinMainWindow::DolphinMainWindow() :
124 m_activeViewContainer(0),
125 m_centralWidgetLayout(0),
132 m_updateToolBarTimer(0),
133 m_lastHandleUrlStatJob(0),
134 m_searchDockIsTemporaryVisible(false)
136 DolphinPlacesModel::setModel(new KFilePlacesModel(this));
137 connect(DolphinPlacesModel::instance(), SIGNAL(errorMessage(QString
)),
138 this, SLOT(showErrorMessage(QString
)));
140 // Workaround for a X11-issue in combination with KModifierInfo
141 // (see DolphinContextMenu::initializeModifierKeyInfo() for
142 // more information):
143 DolphinContextMenu::initializeModifierKeyInfo();
145 setObjectName("Dolphin#");
147 m_viewTab
.append(ViewTab());
148 ViewTab
& viewTab
= m_viewTab
[m_tabIndex
];
149 viewTab
.wasActive
= true; // The first opened tab is automatically active
151 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
152 undoManager
->setUiInterface(new UndoUiInterface());
154 connect(undoManager
, SIGNAL(undoAvailable(bool)),
155 this, SLOT(slotUndoAvailable(bool)));
156 connect(undoManager
, SIGNAL(undoTextChanged(QString
)),
157 this, SLOT(slotUndoTextChanged(QString
)));
158 connect(undoManager
, SIGNAL(jobRecordingStarted(CommandType
)),
159 this, SLOT(clearStatusBar()));
160 connect(undoManager
, SIGNAL(jobRecordingFinished(CommandType
)),
161 this, SLOT(showCommand(CommandType
)));
163 GeneralSettings
* generalSettings
= GeneralSettings::self();
164 const bool firstRun
= (generalSettings
->version() < 200);
166 generalSettings
->setViewPropsTimestamp(QDateTime::currentDateTime());
169 setAcceptDrops(true);
171 viewTab
.splitter
= new QSplitter(this);
172 viewTab
.splitter
->setChildrenCollapsible(false);
176 const KUrl
homeUrl(generalSettings
->homeUrl());
177 setUrlAsCaption(homeUrl
);
178 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
179 connect(m_actionHandler
, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
180 connect(m_actionHandler
, SIGNAL(createDirectory()), SLOT(createDirectory()));
182 viewTab
.primaryView
= createViewContainer(homeUrl
, viewTab
.splitter
);
184 m_activeViewContainer
= viewTab
.primaryView
;
185 connectViewSignals(m_activeViewContainer
);
186 DolphinView
* view
= m_activeViewContainer
->view();
187 m_activeViewContainer
->show();
188 m_actionHandler
->setCurrentView(view
);
190 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
191 connect(this, SIGNAL(urlChanged(KUrl
)),
192 m_remoteEncoding
, SLOT(slotAboutToOpenUrl()));
194 m_tabBar
= new KTabBar(this);
195 m_tabBar
->setMovable(true);
196 m_tabBar
->setTabsClosable(true);
197 connect(m_tabBar
, SIGNAL(currentChanged(int)),
198 this, SLOT(setActiveTab(int)));
199 connect(m_tabBar
, SIGNAL(tabCloseRequested(int)),
200 this, SLOT(closeTab(int)));
201 connect(m_tabBar
, SIGNAL(contextMenu(int,QPoint
)),
202 this, SLOT(openTabContextMenu(int,QPoint
)));
203 connect(m_tabBar
, SIGNAL(newTabRequest()),
204 this, SLOT(openNewTab()));
205 connect(m_tabBar
, SIGNAL(testCanDecode(const QDragMoveEvent
*,bool&)),
206 this, SLOT(slotTestCanDecode(const QDragMoveEvent
*,bool&)));
207 connect(m_tabBar
, SIGNAL(mouseMiddleClick(int)),
208 this, SLOT(closeTab(int)));
209 connect(m_tabBar
, SIGNAL(tabMoved(int,int)),
210 this, SLOT(slotTabMoved(int,int)));
211 connect(m_tabBar
, SIGNAL(receivedDropEvent(int,QDropEvent
*)),
212 this, SLOT(tabDropEvent(int,QDropEvent
*)));
214 m_tabBar
->blockSignals(true); // signals get unblocked after at least 2 tabs are open
216 QWidget
* centralWidget
= new QWidget(this);
217 m_centralWidgetLayout
= new QVBoxLayout(centralWidget
);
218 m_centralWidgetLayout
->setSpacing(0);
219 m_centralWidgetLayout
->setMargin(0);
220 m_centralWidgetLayout
->addWidget(m_tabBar
);
221 m_centralWidgetLayout
->addWidget(viewTab
.splitter
, 1);
223 setCentralWidget(centralWidget
);
225 emit
urlChanged(homeUrl
);
227 setupGUI(Keys
| Save
| Create
| ToolBar
);
228 stateChanged("new_file");
230 QClipboard
* clipboard
= QApplication::clipboard();
231 connect(clipboard
, SIGNAL(dataChanged()),
232 this, SLOT(updatePasteAction()));
234 if (generalSettings
->splitView()) {
241 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
242 showFilterBarAction
->setChecked(generalSettings
->filterBar());
245 menuBar()->setVisible(false);
246 // Assure a proper default size if Dolphin runs the first time
250 const bool showMenu
= !menuBar()->isHidden();
251 QAction
* showMenuBarAction
= actionCollection()->action(KStandardAction::name(KStandardAction::ShowMenubar
));
252 showMenuBarAction
->setChecked(showMenu
); // workaround for bug #171080
254 createControlButton();
258 DolphinMainWindow::~DolphinMainWindow()
262 void DolphinMainWindow::openDirectories(const QList
<KUrl
>& dirs
)
264 if (dirs
.isEmpty()) {
268 if (dirs
.count() == 1) {
269 m_activeViewContainer
->setUrl(dirs
.first());
273 const int oldOpenTabsCount
= m_viewTab
.count();
275 const bool hasSplitView
= GeneralSettings::splitView();
277 // Open each directory inside a new tab. If the "split view" option has been enabled,
278 // always show two directories within one tab.
279 QList
<KUrl
>::const_iterator it
= dirs
.begin();
280 while (it
!= dirs
.end()) {
284 if (hasSplitView
&& (it
!= dirs
.end())) {
285 const int tabIndex
= m_viewTab
.count() - 1;
286 m_viewTab
[tabIndex
].secondaryView
->setUrl(*it
);
291 // Remove the previously opened tabs
292 for (int i
= 0; i
< oldOpenTabsCount
; ++i
) {
297 void DolphinMainWindow::openFiles(const QList
<KUrl
>& files
)
299 if (files
.isEmpty()) {
303 // Get all distinct directories from 'files' and open a tab
304 // for each directory. If the "split view" option is enabled, two
305 // directories are shown inside one tab (see openDirectories()).
307 foreach (const KUrl
& url
, files
) {
308 const KUrl
dir(url
.directory());
309 if (!dirs
.contains(dir
)) {
314 openDirectories(dirs
);
316 // Select the files. Although the files can be split between several
317 // tabs, there is no need to split 'files' accordingly, as
318 // the DolphinView will just ignore invalid selections.
319 const int tabCount
= m_viewTab
.count();
320 for (int i
= 0; i
< tabCount
; ++i
) {
321 m_viewTab
[i
].primaryView
->view()->markUrlsAsSelected(files
);
322 m_viewTab
[i
].primaryView
->view()->markUrlAsCurrent(files
.at(0));
323 if (m_viewTab
[i
].secondaryView
) {
324 m_viewTab
[i
].secondaryView
->view()->markUrlsAsSelected(files
);
325 m_viewTab
[i
].secondaryView
->view()->markUrlAsCurrent(files
.at(0));
330 void DolphinMainWindow::showCommand(CommandType command
)
332 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
334 case KIO::FileUndoManager::Copy
:
335 statusBar
->setText(i18nc("@info:status", "Successfully copied."));
337 case KIO::FileUndoManager::Move
:
338 statusBar
->setText(i18nc("@info:status", "Successfully moved."));
340 case KIO::FileUndoManager::Link
:
341 statusBar
->setText(i18nc("@info:status", "Successfully linked."));
343 case KIO::FileUndoManager::Trash
:
344 statusBar
->setText(i18nc("@info:status", "Successfully moved to trash."));
346 case KIO::FileUndoManager::Rename
:
347 statusBar
->setText(i18nc("@info:status", "Successfully renamed."));
350 case KIO::FileUndoManager::Mkdir
:
351 statusBar
->setText(i18nc("@info:status", "Created folder."));
359 void DolphinMainWindow::pasteIntoFolder()
361 m_activeViewContainer
->view()->pasteIntoFolder();
364 void DolphinMainWindow::changeUrl(const KUrl
& url
)
366 if (!KProtocolManager::supportsListing(url
)) {
367 // The URL navigator only checks for validity, not
368 // if the URL can be listed. An error message is
369 // shown due to DolphinViewContainer::restoreView().
373 DolphinViewContainer
* view
= activeViewContainer();
379 setUrlAsCaption(url
);
380 if (m_viewTab
.count() > 1) {
381 m_tabBar
->setTabText(m_tabIndex
, squeezedText(tabName(m_activeViewContainer
->url())));
383 const QString iconName
= KMimeType::iconNameForUrl(url
);
384 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(iconName
));
385 emit
urlChanged(url
);
389 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
391 KToggleAction
* editableLocationAction
=
392 static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
393 editableLocationAction
->setChecked(editable
);
396 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
400 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
401 int selectedUrlsCount
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedItemsCount();
402 if (m_viewTab
[m_tabIndex
].secondaryView
) {
403 selectedUrlsCount
+= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItemsCount();
406 QAction
* compareFilesAction
= actionCollection()->action("compare_files");
407 if (selectedUrlsCount
== 2) {
408 compareFilesAction
->setEnabled(isKompareInstalled());
410 compareFilesAction
->setEnabled(false);
413 emit
selectionChanged(selection
);
416 void DolphinMainWindow::slotRequestItemInfo(const KFileItem
& item
)
418 emit
requestItemInfo(item
);
421 void DolphinMainWindow::updateHistory()
423 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
424 const int index
= urlNavigator
->historyIndex();
426 QAction
* backAction
= actionCollection()->action("go_back");
428 backAction
->setToolTip(i18nc("@info", "Go back"));
429 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
432 QAction
* forwardAction
= actionCollection()->action("go_forward");
434 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
435 forwardAction
->setEnabled(index
> 0);
439 void DolphinMainWindow::updateFilterBarAction(bool show
)
441 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
442 showFilterBarAction
->setChecked(show
);
445 void DolphinMainWindow::openNewMainWindow()
447 KRun::run("dolphin", KUrl::List(), this);
450 void DolphinMainWindow::openNewTab()
452 const bool isUrlEditable
= m_activeViewContainer
->urlNavigator()->isUrlEditable();
454 openNewTab(m_activeViewContainer
->url());
455 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
457 // The URL navigator of the new tab should have the same editable state
458 // as the current tab
459 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
460 navigator
->setUrlEditable(isUrlEditable
);
463 // If a new tab is opened and the URL is editable, assure that
464 // the user can edit the URL without manually setting the focus
465 navigator
->setFocus();
469 void DolphinMainWindow::openNewTab(const KUrl
& url
)
471 QWidget
* focusWidget
= QApplication::focusWidget();
473 if (m_viewTab
.count() == 1) {
474 // Only one view is open currently and hence no tab is shown at
475 // all. Before creating a tab for 'url', provide a tab for the current URL.
476 const KUrl currentUrl
= m_activeViewContainer
->url();
477 m_tabBar
->addTab(KIcon(KMimeType::iconNameForUrl(currentUrl
)),
478 squeezedText(tabName(currentUrl
)));
479 m_tabBar
->blockSignals(false);
482 m_tabBar
->addTab(KIcon(KMimeType::iconNameForUrl(url
)),
483 squeezedText(tabName(url
)));
486 viewTab
.splitter
= new QSplitter(this);
487 viewTab
.splitter
->setChildrenCollapsible(false);
488 viewTab
.primaryView
= createViewContainer(url
, viewTab
.splitter
);
489 viewTab
.primaryView
->setActive(false);
490 connectViewSignals(viewTab
.primaryView
);
492 m_viewTab
.append(viewTab
);
494 actionCollection()->action("close_tab")->setEnabled(true);
496 // Provide a split view, if the startup settings are set this way
497 if (GeneralSettings::splitView()) {
498 const int newTabIndex
= m_viewTab
.count() - 1;
499 createSecondaryView(newTabIndex
);
500 m_viewTab
[newTabIndex
].secondaryView
->setActive(true);
501 m_viewTab
[newTabIndex
].isPrimaryViewActive
= false;
505 // The DolphinViewContainer grabbed the keyboard focus. As the tab is opened
506 // in background, assure that the previous focused widget gets the focus back.
507 focusWidget
->setFocus();
511 void DolphinMainWindow::activateNextTab()
513 if (m_viewTab
.count() >= 2) {
514 const int tabIndex
= (m_tabBar
->currentIndex() + 1) % m_tabBar
->count();
515 m_tabBar
->setCurrentIndex(tabIndex
);
519 void DolphinMainWindow::activatePrevTab()
521 if (m_viewTab
.count() >= 2) {
522 int tabIndex
= m_tabBar
->currentIndex() - 1;
523 if (tabIndex
== -1) {
524 tabIndex
= m_tabBar
->count() - 1;
526 m_tabBar
->setCurrentIndex(tabIndex
);
530 void DolphinMainWindow::openInNewTab()
532 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
533 if (list
.isEmpty()) {
534 openNewTab(m_activeViewContainer
->url());
535 } else if ((list
.count() == 1) && list
[0].isDir()) {
536 openNewTab(list
[0].url());
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) && list
[0].isDir()) {
548 newWindowUrl
= list
[0].url();
551 if (!newWindowUrl
.isEmpty()) {
552 KRun::run("dolphin", KUrl::List() << newWindowUrl
, this);
556 void DolphinMainWindow::toggleActiveView()
558 if (!m_viewTab
[m_tabIndex
].secondaryView
) {
559 // only one view is available
563 Q_ASSERT(m_activeViewContainer
);
564 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
566 DolphinViewContainer
* left
= m_viewTab
[m_tabIndex
].primaryView
;
567 DolphinViewContainer
* right
= m_viewTab
[m_tabIndex
].secondaryView
;
568 setActiveViewContainer(m_activeViewContainer
== right
? left
: right
);
571 void DolphinMainWindow::showEvent(QShowEvent
* event
)
573 KXmlGuiWindow::showEvent(event
);
574 if (!event
->spontaneous()) {
575 m_activeViewContainer
->view()->setFocus();
579 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
581 // Find out if Dolphin is closed directly by the user or
582 // by the session manager because the session is closed
583 bool closedByUser
= true;
584 DolphinApplication
*application
= qobject_cast
<DolphinApplication
*>(qApp
);
585 if (application
&& application
->sessionSaving()) {
586 closedByUser
= false;
589 if (m_viewTab
.count() > 1 && GeneralSettings::confirmClosingMultipleTabs() && closedByUser
) {
590 // Ask the user if he really wants to quit and close all tabs.
591 // Open a confirmation dialog with 3 buttons:
592 // KDialog::Yes -> Quit
593 // KDialog::No -> Close only the current tab
594 // KDialog::Cancel -> do nothing
595 KDialog
*dialog
= new KDialog(this, Qt::Dialog
);
596 dialog
->setCaption(i18nc("@title:window", "Confirmation"));
597 dialog
->setButtons(KDialog::Yes
| KDialog::No
| KDialog::Cancel
);
598 dialog
->setModal(true);
599 dialog
->setButtonGuiItem(KDialog::Yes
, KStandardGuiItem::quit());
600 dialog
->setButtonGuiItem(KDialog::No
, KGuiItem(i18n("C&lose Current Tab"), KIcon("tab-close")));
601 dialog
->setButtonGuiItem(KDialog::Cancel
, KStandardGuiItem::cancel());
602 dialog
->setDefaultButton(KDialog::Yes
);
604 bool doNotAskAgainCheckboxResult
= false;
606 const int result
= KMessageBox::createKMessageBox(dialog
,
607 QMessageBox::Warning
,
608 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
610 i18n("Do not ask again"),
611 &doNotAskAgainCheckboxResult
,
612 KMessageBox::Notify
);
614 if (doNotAskAgainCheckboxResult
) {
615 GeneralSettings::setConfirmClosingMultipleTabs(false);
623 // Close only the current tab
631 GeneralSettings::setVersion(CurrentDolphinVersion
);
632 GeneralSettings::self()->writeConfig();
634 if (m_searchDockIsTemporaryVisible
) {
635 QDockWidget
* searchDock
= findChild
<QDockWidget
*>("searchDock");
639 m_searchDockIsTemporaryVisible
= false;
642 KXmlGuiWindow::closeEvent(event
);
645 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
647 const int tabCount
= m_viewTab
.count();
648 group
.writeEntry("Tab Count", tabCount
);
649 group
.writeEntry("Active Tab Index", m_tabBar
->currentIndex());
651 for (int i
= 0; i
< tabCount
; ++i
) {
652 const DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
653 group
.writeEntry(tabProperty("Primary URL", i
), cont
->url().url());
654 group
.writeEntry(tabProperty("Primary Editable", i
),
655 cont
->urlNavigator()->isUrlEditable());
657 cont
= m_viewTab
[i
].secondaryView
;
659 group
.writeEntry(tabProperty("Secondary URL", i
), cont
->url().url());
660 group
.writeEntry(tabProperty("Secondary Editable", i
),
661 cont
->urlNavigator()->isUrlEditable());
666 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
668 const int tabCount
= group
.readEntry("Tab Count", 1);
669 for (int i
= 0; i
< tabCount
; ++i
) {
670 DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
672 cont
->setUrl(group
.readEntry(tabProperty("Primary URL", i
)));
673 const bool editable
= group
.readEntry(tabProperty("Primary Editable", i
), false);
674 cont
->urlNavigator()->setUrlEditable(editable
);
676 cont
= m_viewTab
[i
].secondaryView
;
677 const QString secondaryUrl
= group
.readEntry(tabProperty("Secondary URL", i
));
678 if (!secondaryUrl
.isEmpty()) {
680 // a secondary view should be shown, but no one is available
681 // currently -> create a new view
683 cont
= m_viewTab
[i
].secondaryView
;
687 cont
->setUrl(secondaryUrl
);
688 const bool editable
= group
.readEntry(tabProperty("Secondary Editable", i
), false);
689 cont
->urlNavigator()->setUrlEditable(editable
);
691 // no secondary view should be shown, but the default setting shows
692 // one already -> close the view
696 // openNewTab() needs to be called only tabCount - 1 times
697 if (i
!= tabCount
- 1) {
702 const int index
= group
.readEntry("Active Tab Index", 0);
703 m_tabBar
->setCurrentIndex(index
);
706 void DolphinMainWindow::updateNewMenu()
708 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
709 m_newFileMenu
->checkUpToDate();
710 m_newFileMenu
->setPopupFiles(activeViewContainer()->url());
713 void DolphinMainWindow::createDirectory()
715 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
716 m_newFileMenu
->setPopupFiles(activeViewContainer()->url());
717 m_newFileMenu
->createDirectory();
720 void DolphinMainWindow::quit()
725 void DolphinMainWindow::showErrorMessage(const QString
& message
)
727 m_activeViewContainer
->showMessage(message
, DolphinViewContainer::Error
);
730 void DolphinMainWindow::slotUndoAvailable(bool available
)
732 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
734 undoAction
->setEnabled(available
);
738 void DolphinMainWindow::restoreClosedTab(QAction
* action
)
740 if (action
->data().toBool()) {
741 // clear all actions except the "Empty Recently Closed Tabs"
742 // action and the separator
743 QList
<QAction
*> actions
= m_recentTabsMenu
->menu()->actions();
744 const int count
= actions
.size();
745 for (int i
= 2; i
< count
; ++i
) {
746 m_recentTabsMenu
->menu()->removeAction(actions
.at(i
));
749 const ClosedTab closedTab
= action
->data().value
<ClosedTab
>();
750 openNewTab(closedTab
.primaryUrl
);
751 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
753 if (closedTab
.isSplit
) {
754 // create secondary view
756 m_viewTab
[m_tabIndex
].secondaryView
->setUrl(closedTab
.secondaryUrl
);
759 m_recentTabsMenu
->removeAction(action
);
762 if (m_recentTabsMenu
->menu()->actions().count() == 2) {
763 m_recentTabsMenu
->setEnabled(false);
767 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
769 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
771 undoAction
->setText(text
);
775 void DolphinMainWindow::undo()
778 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
779 KIO::FileUndoManager::self()->undo();
782 void DolphinMainWindow::cut()
784 m_activeViewContainer
->view()->cutSelectedItems();
787 void DolphinMainWindow::copy()
789 m_activeViewContainer
->view()->copySelectedItems();
792 void DolphinMainWindow::paste()
794 m_activeViewContainer
->view()->paste();
797 void DolphinMainWindow::find()
799 m_activeViewContainer
->setSearchModeEnabled(true);
802 void DolphinMainWindow::slotSearchLocationChanged()
805 QDockWidget
* searchDock
= findChild
<QDockWidget
*>("searchDock");
810 SearchPanel
* searchPanel
= qobject_cast
<SearchPanel
*>(searchDock
->widget());
812 searchPanel
->setSearchLocation(SearchSettings::location() == QLatin1String("FromHere")
813 ? SearchPanel::FromCurrentDir
814 : SearchPanel::Everywhere
);
819 void DolphinMainWindow::updatePasteAction()
821 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
822 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
823 pasteAction
->setEnabled(pasteInfo
.first
);
824 pasteAction
->setText(pasteInfo
.second
);
827 void DolphinMainWindow::selectAll()
831 // if the URL navigator is editable and focused, select the whole
832 // URL instead of all items of the view
834 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
835 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit(); // krazy:exclude=qclasses
836 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
837 lineEdit
->hasFocus();
839 lineEdit
->selectAll();
841 m_activeViewContainer
->view()->selectAll();
845 void DolphinMainWindow::invertSelection()
848 m_activeViewContainer
->view()->invertSelection();
851 void DolphinMainWindow::toggleSplitView()
853 if (!m_viewTab
[m_tabIndex
].secondaryView
) {
854 createSecondaryView(m_tabIndex
);
855 setActiveViewContainer(m_viewTab
[m_tabIndex
].secondaryView
);
856 } else if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
857 // remove secondary view
858 m_viewTab
[m_tabIndex
].secondaryView
->close();
859 m_viewTab
[m_tabIndex
].secondaryView
->deleteLater();
860 m_viewTab
[m_tabIndex
].secondaryView
= 0;
862 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
864 // The primary view is active and should be closed. Hence from a users point of view
865 // the content of the secondary view should be moved to the primary view.
866 // From an implementation point of view it is more efficient to close
867 // the primary view and exchange the internal pointers afterwards.
869 m_viewTab
[m_tabIndex
].primaryView
->close();
870 m_viewTab
[m_tabIndex
].primaryView
->deleteLater();
871 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
872 m_viewTab
[m_tabIndex
].secondaryView
= 0;
874 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
880 void DolphinMainWindow::reloadView()
883 m_activeViewContainer
->view()->reload();
886 void DolphinMainWindow::stopLoading()
888 m_activeViewContainer
->view()->stopLoading();
891 void DolphinMainWindow::enableStopAction()
893 actionCollection()->action("stop")->setEnabled(true);
896 void DolphinMainWindow::disableStopAction()
898 actionCollection()->action("stop")->setEnabled(false);
901 void DolphinMainWindow::showFilterBar()
903 m_activeViewContainer
->setFilterBarVisible(true);
906 void DolphinMainWindow::toggleEditLocation()
910 QAction
* action
= actionCollection()->action("editable_location");
911 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
912 urlNavigator
->setUrlEditable(action
->isChecked());
915 void DolphinMainWindow::replaceLocation()
917 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
918 navigator
->setUrlEditable(true);
919 navigator
->setFocus();
921 // select the whole text of the combo box editor
922 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit(); // krazy:exclude=qclasses
923 lineEdit
->selectAll();
926 void DolphinMainWindow::togglePanelLockState()
928 const bool newLockState
= !GeneralSettings::lockPanels();
929 foreach (QObject
* child
, children()) {
930 DolphinDockWidget
* dock
= qobject_cast
<DolphinDockWidget
*>(child
);
932 dock
->setLocked(newLockState
);
936 GeneralSettings::setLockPanels(newLockState
);
939 void DolphinMainWindow::slotPlacesPanelVisibilityChanged(bool visible
)
941 const int tabCount
= m_viewTab
.count();
942 for (int i
= 0; i
< tabCount
; ++i
) {
943 ViewTab
& tab
= m_viewTab
[i
];
944 Q_ASSERT(tab
.primaryView
);
945 tab
.primaryView
->urlNavigator()->setPlacesSelectorVisible(!visible
);
946 if (tab
.secondaryView
) {
947 tab
.secondaryView
->urlNavigator()->setPlacesSelectorVisible(!visible
);
952 void DolphinMainWindow::goBack()
954 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
955 urlNavigator
->goBack();
957 if (urlNavigator
->locationState().isEmpty()) {
958 // An empty location state indicates a redirection URL,
959 // which must be skipped too
960 urlNavigator
->goBack();
964 void DolphinMainWindow::goForward()
966 m_activeViewContainer
->urlNavigator()->goForward();
969 void DolphinMainWindow::goUp()
971 m_activeViewContainer
->urlNavigator()->goUp();
974 void DolphinMainWindow::goHome()
976 m_activeViewContainer
->urlNavigator()->goHome();
979 void DolphinMainWindow::goBack(Qt::MouseButtons buttons
)
981 // The default case (left button pressed) is handled in goBack().
982 if (buttons
== Qt::MidButton
) {
983 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
984 const int index
= urlNavigator
->historyIndex() + 1;
985 openNewTab(urlNavigator
->locationUrl(index
));
989 void DolphinMainWindow::goForward(Qt::MouseButtons buttons
)
991 // The default case (left button pressed) is handled in goForward().
992 if (buttons
== Qt::MidButton
) {
993 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
994 const int index
= urlNavigator
->historyIndex() - 1;
995 openNewTab(urlNavigator
->locationUrl(index
));
999 void DolphinMainWindow::goUp(Qt::MouseButtons buttons
)
1001 // The default case (left button pressed) is handled in goUp().
1002 if (buttons
== Qt::MidButton
) {
1003 openNewTab(activeViewContainer()->url().upUrl());
1007 void DolphinMainWindow::goHome(Qt::MouseButtons buttons
)
1009 // The default case (left button pressed) is handled in goHome().
1010 if (buttons
== Qt::MidButton
) {
1011 openNewTab(GeneralSettings::self()->homeUrl());
1015 void DolphinMainWindow::compareFiles()
1017 // The method is only invoked if exactly 2 files have
1018 // been selected. The selected files may be:
1019 // - both in the primary view
1020 // - both in the secondary view
1021 // - one in the primary view and the other in the secondary
1023 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
1028 KFileItemList items
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedItems();
1030 switch (items
.count()) {
1032 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
);
1033 items
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItems();
1034 Q_ASSERT(items
.count() == 2);
1035 urlA
= items
[0].url();
1036 urlB
= items
[1].url();
1041 urlA
= items
[0].url();
1042 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
);
1043 items
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItems();
1044 Q_ASSERT(items
.count() == 1);
1045 urlB
= items
[0].url();
1050 urlA
= items
[0].url();
1051 urlB
= items
[1].url();
1056 // may not happen: compareFiles may only get invoked if 2
1057 // files are selected
1062 QString
command("kompare -c \"");
1063 command
.append(urlA
.pathOrUrl());
1064 command
.append("\" \"");
1065 command
.append(urlB
.pathOrUrl());
1066 command
.append('\"');
1067 KRun::runCommand(command
, "Kompare", "kompare", this);
1070 void DolphinMainWindow::toggleShowMenuBar()
1072 const bool visible
= menuBar()->isVisible();
1073 menuBar()->setVisible(!visible
);
1075 createControlButton();
1077 deleteControlButton();
1081 void DolphinMainWindow::openTerminal()
1083 QString
dir(QDir::homePath());
1085 // If the given directory is not local, it can still be the URL of an
1086 // ioslave using UDS_LOCAL_PATH which to be converted first.
1087 KUrl url
= KIO::NetAccess::mostLocalUrl(m_activeViewContainer
->url(), this);
1089 //If the URL is local after the above conversion, set the directory.
1090 if (url
.isLocalFile()) {
1091 dir
= url
.toLocalFile();
1094 KToolInvocation::invokeTerminal(QString(), dir
);
1097 void DolphinMainWindow::editSettings()
1099 if (!m_settingsDialog
) {
1100 DolphinViewContainer
* container
= activeViewContainer();
1101 container
->view()->writeSettings();
1103 const KUrl url
= container
->url();
1104 DolphinSettingsDialog
* settingsDialog
= new DolphinSettingsDialog(url
, this);
1105 connect(settingsDialog
, SIGNAL(settingsChanged()), this, SLOT(refreshViews()));
1106 settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1107 settingsDialog
->show();
1108 m_settingsDialog
= settingsDialog
;
1110 m_settingsDialog
.data()->raise();
1114 void DolphinMainWindow::setActiveTab(int index
)
1116 Q_ASSERT(index
>= 0);
1117 Q_ASSERT(index
< m_viewTab
.count());
1118 if (index
== m_tabIndex
) {
1122 // hide current tab content
1123 ViewTab
& hiddenTab
= m_viewTab
[m_tabIndex
];
1124 hiddenTab
.isPrimaryViewActive
= hiddenTab
.primaryView
->isActive();
1125 hiddenTab
.primaryView
->setActive(false);
1126 if (hiddenTab
.secondaryView
) {
1127 hiddenTab
.secondaryView
->setActive(false);
1129 QSplitter
* splitter
= m_viewTab
[m_tabIndex
].splitter
;
1131 m_centralWidgetLayout
->removeWidget(splitter
);
1133 // show active tab content
1136 ViewTab
& viewTab
= m_viewTab
[index
];
1137 m_centralWidgetLayout
->addWidget(viewTab
.splitter
, 1);
1138 viewTab
.primaryView
->show();
1139 if (viewTab
.secondaryView
) {
1140 viewTab
.secondaryView
->show();
1142 viewTab
.splitter
->show();
1144 if (!viewTab
.wasActive
) {
1145 viewTab
.wasActive
= true;
1147 // If the tab has not been activated yet the size of the KItemListView is
1148 // undefined and results in an unwanted animation. To prevent this a
1149 // reloading of the directory gets triggered.
1150 viewTab
.primaryView
->view()->reload();
1151 if (viewTab
.secondaryView
) {
1152 viewTab
.secondaryView
->view()->reload();
1156 setActiveViewContainer(viewTab
.isPrimaryViewActive
? viewTab
.primaryView
:
1157 viewTab
.secondaryView
);
1160 void DolphinMainWindow::closeTab()
1162 closeTab(m_tabBar
->currentIndex());
1165 void DolphinMainWindow::closeTab(int index
)
1167 Q_ASSERT(index
>= 0);
1168 Q_ASSERT(index
< m_viewTab
.count());
1169 if (m_viewTab
.count() == 1) {
1170 // the last tab may never get closed
1174 if (index
== m_tabIndex
) {
1175 // The tab that should be closed is the active tab. Activate the
1176 // previous tab before closing the tab.
1177 m_tabBar
->setCurrentIndex((index
> 0) ? index
- 1 : 1);
1179 rememberClosedTab(index
);
1182 m_viewTab
[index
].primaryView
->deleteLater();
1183 if (m_viewTab
[index
].secondaryView
) {
1184 m_viewTab
[index
].secondaryView
->deleteLater();
1186 m_viewTab
[index
].splitter
->deleteLater();
1187 m_viewTab
.erase(m_viewTab
.begin() + index
);
1189 m_tabBar
->blockSignals(true);
1190 m_tabBar
->removeTab(index
);
1192 if (m_tabIndex
> index
) {
1194 Q_ASSERT(m_tabIndex
>= 0);
1197 // if only one tab is left, also remove the tab entry so that
1198 // closing the last tab is not possible
1199 if (m_viewTab
.count() == 1) {
1200 m_tabBar
->removeTab(0);
1201 actionCollection()->action("close_tab")->setEnabled(false);
1203 m_tabBar
->blockSignals(false);
1207 void DolphinMainWindow::openTabContextMenu(int index
, const QPoint
& pos
)
1211 QAction
* newTabAction
= menu
.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab"));
1212 newTabAction
->setShortcut(actionCollection()->action("new_tab")->shortcut());
1214 QAction
* detachTabAction
= menu
.addAction(KIcon("tab-detach"), i18nc("@action:inmenu", "Detach Tab"));
1216 QAction
* closeOtherTabsAction
= menu
.addAction(KIcon("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs"));
1218 QAction
* closeTabAction
= menu
.addAction(KIcon("tab-close"), i18nc("@action:inmenu", "Close Tab"));
1219 closeTabAction
->setShortcut(actionCollection()->action("close_tab")->shortcut());
1220 QAction
* selectedAction
= menu
.exec(pos
);
1221 if (selectedAction
== newTabAction
) {
1222 const ViewTab
& tab
= m_viewTab
[index
];
1223 Q_ASSERT(tab
.primaryView
);
1224 const KUrl url
= tab
.secondaryView
&& tab
.secondaryView
->isActive() ?
1225 tab
.secondaryView
->url() : tab
.primaryView
->url();
1227 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
1228 } else if (selectedAction
== detachTabAction
) {
1229 const QString
separator(QLatin1Char(' '));
1230 QString command
= QLatin1String("dolphin");
1232 const ViewTab
& tab
= m_viewTab
[index
];
1233 Q_ASSERT(tab
.primaryView
);
1235 command
+= separator
+ tab
.primaryView
->url().url();
1236 if (tab
.secondaryView
) {
1237 command
+= separator
+ tab
.secondaryView
->url().url();
1238 command
+= separator
+ QLatin1String("-split");
1241 KRun::runCommand(command
, this);
1244 } else if (selectedAction
== closeOtherTabsAction
) {
1245 const int count
= m_tabBar
->count();
1246 for (int i
= 0; i
< index
; ++i
) {
1249 for (int i
= index
+ 1; i
< count
; ++i
) {
1252 } else if (selectedAction
== closeTabAction
) {
1257 void DolphinMainWindow::slotTabMoved(int from
, int to
)
1259 m_viewTab
.move(from
, to
);
1260 m_tabIndex
= m_tabBar
->currentIndex();
1263 void DolphinMainWindow::handlePlacesClick(const KUrl
& url
, Qt::MouseButtons buttons
)
1265 if (buttons
& Qt::MidButton
) {
1267 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
1273 void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent
* event
, bool& canDecode
)
1275 canDecode
= KUrl::List::canDecode(event
->mimeData());
1278 void DolphinMainWindow::handleUrl(const KUrl
& url
)
1280 delete m_lastHandleUrlStatJob
;
1281 m_lastHandleUrlStatJob
= 0;
1283 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1284 activeViewContainer()->setUrl(url
);
1285 } else if (KProtocolManager::supportsListing(url
)) {
1286 // stat the URL to see if it is a dir or not
1287 m_lastHandleUrlStatJob
= KIO::stat(url
, KIO::HideProgressInfo
);
1288 if (m_lastHandleUrlStatJob
->ui()) {
1289 m_lastHandleUrlStatJob
->ui()->setWindow(this);
1291 connect(m_lastHandleUrlStatJob
, SIGNAL(result(KJob
*)),
1292 this, SLOT(slotHandleUrlStatFinished(KJob
*)));
1295 new KRun(url
, this); // Automatically deletes itself after being finished
1299 void DolphinMainWindow::slotHandleUrlStatFinished(KJob
* job
)
1301 m_lastHandleUrlStatJob
= 0;
1302 const KIO::UDSEntry entry
= static_cast<KIO::StatJob
*>(job
)->statResult();
1303 const KUrl url
= static_cast<KIO::StatJob
*>(job
)->url();
1304 if (entry
.isDir()) {
1305 activeViewContainer()->setUrl(url
);
1307 new KRun(url
, this); // Automatically deletes itself after being finished
1311 void DolphinMainWindow::tabDropEvent(int tab
, QDropEvent
* event
)
1313 const KUrl::List urls
= KUrl::List::fromMimeData(event
->mimeData());
1314 if (!urls
.isEmpty() && tab
!= -1) {
1315 const ViewTab
& viewTab
= m_viewTab
[tab
];
1316 const DolphinView
* view
= viewTab
.isPrimaryViewActive
? viewTab
.primaryView
->view()
1317 : viewTab
.secondaryView
->view();
1318 const QString error
= DragAndDropHelper::dropUrls(view
->rootItem(), view
->url(), event
);
1319 if (!error
.isEmpty()) {
1320 activeViewContainer()->showMessage(error
, DolphinViewContainer::Error
);
1325 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1327 newFileMenu()->setEnabled(isFolderWritable
);
1330 void DolphinMainWindow::slotSearchModeChanged(bool enabled
)
1333 const DolphinSearchInformation
& searchInfo
= DolphinSearchInformation::instance();
1334 if (!searchInfo
.isIndexingEnabled()) {
1338 QDockWidget
* searchDock
= findChild
<QDockWidget
*>("searchDock");
1344 if (!searchDock
->isVisible()) {
1345 m_searchDockIsTemporaryVisible
= true;
1349 if (searchDock
->isVisible() && m_searchDockIsTemporaryVisible
) {
1352 m_searchDockIsTemporaryVisible
= false;
1355 SearchPanel
* searchPanel
= qobject_cast
<SearchPanel
*>(searchDock
->widget());
1361 SearchPanel::SearchLocation searchLocation
= SearchPanel::Everywhere
;
1362 const KUrl url
= m_activeViewContainer
->url();
1363 const bool isSearchUrl
= (url
.protocol() == QLatin1String("nepomuksearch"));
1364 if ((SearchSettings::location() == QLatin1String("FromHere") && !isSearchUrl
)) {
1365 searchLocation
= SearchPanel::FromCurrentDir
;
1367 searchPanel
->setSearchLocation(searchLocation
);
1369 searchPanel
->setSearchLocation(SearchPanel::Everywhere
);
1376 void DolphinMainWindow::openContextMenu(const QPoint
& pos
,
1377 const KFileItem
& item
,
1379 const QList
<QAction
*>& customActions
)
1381 QWeakPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, pos
, item
, url
);
1382 contextMenu
.data()->setCustomActions(customActions
);
1383 const DolphinContextMenu::Command command
= contextMenu
.data()->open();
1386 case DolphinContextMenu::OpenParentFolderInNewWindow
: {
1387 KRun::run("dolphin", KUrl::List() << item
.url().upUrl(), this);
1391 case DolphinContextMenu::OpenParentFolderInNewTab
:
1392 openNewTab(item
.url().upUrl());
1395 case DolphinContextMenu::None
:
1400 delete contextMenu
.data();
1403 void DolphinMainWindow::updateControlMenu()
1405 KMenu
* menu
= qobject_cast
<KMenu
*>(sender());
1408 // All actions get cleared by KMenu::clear(). The sub-menus are deleted
1409 // by connecting to the aboutToHide() signal from the parent-menu.
1412 KActionCollection
* ac
= actionCollection();
1414 // Add "Edit" actions
1415 bool added
= addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Undo
)), menu
) |
1416 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Find
)), menu
) |
1417 addActionToMenu(ac
->action("select_all"), menu
) |
1418 addActionToMenu(ac
->action("invert_selection"), menu
);
1421 menu
->addSeparator();
1424 // Add "View" actions
1425 if (!GeneralSettings::showZoomSlider()) {
1426 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomIn
)), menu
);
1427 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomOut
)), menu
);
1428 menu
->addSeparator();
1431 added
= addActionToMenu(ac
->action("view_mode"), menu
) |
1432 addActionToMenu(ac
->action("sort"), menu
) |
1433 addActionToMenu(ac
->action("additional_info"), menu
) |
1434 addActionToMenu(ac
->action("show_preview"), menu
) |
1435 addActionToMenu(ac
->action("show_in_groups"), menu
) |
1436 addActionToMenu(ac
->action("show_hidden_files"), menu
);
1439 menu
->addSeparator();
1442 added
= addActionToMenu(ac
->action("split_view"), menu
) |
1443 addActionToMenu(ac
->action("reload"), menu
) |
1444 addActionToMenu(ac
->action("view_properties"), menu
);
1446 menu
->addSeparator();
1449 addActionToMenu(ac
->action("panels"), menu
);
1450 KMenu
* locationBarMenu
= new KMenu(i18nc("@action:inmenu", "Location Bar"), menu
);
1451 locationBarMenu
->addAction(ac
->action("editable_location"));
1452 locationBarMenu
->addAction(ac
->action("replace_location"));
1453 menu
->addMenu(locationBarMenu
);
1455 menu
->addSeparator();
1458 KMenu
* goMenu
= new KMenu(i18nc("@action:inmenu", "Go"), menu
);
1459 connect(menu
, SIGNAL(aboutToHide()), goMenu
, SLOT(deleteLater()));
1460 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Back
)));
1461 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Forward
)));
1462 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Up
)));
1463 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Home
)));
1464 goMenu
->addAction(ac
->action("closed_tabs"));
1465 menu
->addMenu(goMenu
);
1468 KMenu
* toolsMenu
= new KMenu(i18nc("@action:inmenu", "Tools"), menu
);
1469 connect(menu
, SIGNAL(aboutToHide()), toolsMenu
, SLOT(deleteLater()));
1470 toolsMenu
->addAction(ac
->action("show_filter_bar"));
1471 toolsMenu
->addAction(ac
->action("compare_files"));
1472 toolsMenu
->addAction(ac
->action("open_terminal"));
1473 toolsMenu
->addAction(ac
->action("change_remote_encoding"));
1474 menu
->addMenu(toolsMenu
);
1476 // Add "Settings" menu entries
1477 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::KeyBindings
)), menu
);
1478 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ConfigureToolbars
)), menu
);
1479 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Preferences
)), menu
);
1482 KMenu
* helpMenu
= new KMenu(i18nc("@action:inmenu", "Help"), menu
);
1483 connect(menu
, SIGNAL(aboutToHide()), helpMenu
, SLOT(deleteLater()));
1484 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::HelpContents
)));
1485 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::WhatsThis
)));
1486 helpMenu
->addSeparator();
1487 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ReportBug
)));
1488 helpMenu
->addSeparator();
1489 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
)));
1490 helpMenu
->addSeparator();
1491 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::AboutApp
)));
1492 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::AboutKDE
)));
1493 menu
->addMenu(helpMenu
);
1495 menu
->addSeparator();
1496 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ShowMenubar
)), menu
);
1499 void DolphinMainWindow::updateToolBar()
1501 if (!menuBar()->isVisible()) {
1502 createControlButton();
1506 void DolphinMainWindow::slotControlButtonDeleted()
1508 m_controlButton
= 0;
1509 m_updateToolBarTimer
->start();
1512 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer
* viewContainer
)
1514 Q_ASSERT(viewContainer
);
1515 Q_ASSERT((viewContainer
== m_viewTab
[m_tabIndex
].primaryView
) ||
1516 (viewContainer
== m_viewTab
[m_tabIndex
].secondaryView
));
1517 if (m_activeViewContainer
== viewContainer
) {
1521 m_activeViewContainer
->setActive(false);
1522 m_activeViewContainer
= viewContainer
;
1524 // Activating the view container might trigger a recursive setActiveViewContainer() call
1525 // inside DolphinMainWindow::toggleActiveView() when having a split view. Temporary
1526 // disconnect the activated() signal in this case:
1527 disconnect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1528 m_activeViewContainer
->setActive(true);
1529 connect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1531 m_actionHandler
->setCurrentView(viewContainer
->view());
1534 updateEditActions();
1535 updateViewActions();
1538 const KUrl url
= m_activeViewContainer
->url();
1539 setUrlAsCaption(url
);
1540 if (m_viewTab
.count() > 1) {
1541 m_tabBar
->setTabText(m_tabIndex
, tabName(url
));
1542 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(KMimeType::iconNameForUrl(url
)));
1545 emit
urlChanged(url
);
1548 DolphinViewContainer
* DolphinMainWindow::createViewContainer(const KUrl
& url
, QWidget
* parent
)
1550 DolphinViewContainer
* container
= new DolphinViewContainer(url
, parent
);
1552 // The places-selector from the URL navigator should only be shown
1553 // if the places dock is invisible
1554 QDockWidget
* placesDock
= findChild
<QDockWidget
*>("placesDock");
1555 container
->urlNavigator()->setPlacesSelectorVisible(!placesDock
|| !placesDock
->isVisible());
1560 void DolphinMainWindow::setupActions()
1562 // setup 'File' menu
1563 m_newFileMenu
= new DolphinNewFileMenu(this);
1564 KMenu
* menu
= m_newFileMenu
->menu();
1565 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1566 menu
->setIcon(KIcon("document-new"));
1567 connect(menu
, SIGNAL(aboutToShow()),
1568 this, SLOT(updateNewMenu()));
1570 KAction
* newWindow
= actionCollection()->addAction("new_window");
1571 newWindow
->setIcon(KIcon("window-new"));
1572 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1573 newWindow
->setShortcut(Qt::CTRL
| Qt::Key_N
);
1574 connect(newWindow
, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1576 KAction
* newTab
= actionCollection()->addAction("new_tab");
1577 newTab
->setIcon(KIcon("tab-new"));
1578 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1579 newTab
->setShortcut(KShortcut(Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
));
1580 connect(newTab
, SIGNAL(triggered()), this, SLOT(openNewTab()));
1582 KAction
* closeTab
= actionCollection()->addAction("close_tab");
1583 closeTab
->setIcon(KIcon("tab-close"));
1584 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1585 closeTab
->setShortcut(Qt::CTRL
| Qt::Key_W
);
1586 closeTab
->setEnabled(false);
1587 connect(closeTab
, SIGNAL(triggered()), this, SLOT(closeTab()));
1589 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1591 // setup 'Edit' menu
1592 KStandardAction::undo(this,
1594 actionCollection());
1596 // need to remove shift+del from cut action, else the shortcut for deletejob
1598 KAction
* cut
= KStandardAction::cut(this, SLOT(cut()), actionCollection());
1599 KShortcut cutShortcut
= cut
->shortcut();
1600 cutShortcut
.remove(Qt::SHIFT
| Qt::Key_Delete
, KShortcut::KeepEmpty
);
1601 cut
->setShortcut(cutShortcut
);
1602 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1603 KAction
* paste
= KStandardAction::paste(this, SLOT(paste()), actionCollection());
1604 // The text of the paste-action is modified dynamically by Dolphin
1605 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1606 // due to the long text, the text "Paste" is used:
1607 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1609 KStandardAction::find(this, SLOT(find()), actionCollection());
1611 KAction
* selectAll
= actionCollection()->addAction("select_all");
1612 selectAll
->setText(i18nc("@action:inmenu Edit", "Select All"));
1613 selectAll
->setShortcut(Qt::CTRL
| Qt::Key_A
);
1614 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
1616 KAction
* invertSelection
= actionCollection()->addAction("invert_selection");
1617 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1618 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1619 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
1621 // setup 'View' menu
1622 // (note that most of it is set up in DolphinViewActionHandler)
1624 KAction
* split
= actionCollection()->addAction("split_view");
1625 split
->setShortcut(Qt::Key_F3
);
1626 updateSplitAction();
1627 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1629 KAction
* reload
= actionCollection()->addAction("reload");
1630 reload
->setText(i18nc("@action:inmenu View", "Reload"));
1631 reload
->setShortcut(Qt::Key_F5
);
1632 reload
->setIcon(KIcon("view-refresh"));
1633 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
1635 KAction
* stop
= actionCollection()->addAction("stop");
1636 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1637 stop
->setToolTip(i18nc("@info", "Stop loading"));
1638 stop
->setIcon(KIcon("process-stop"));
1639 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
1641 KToggleAction
* editableLocation
= actionCollection()->add
<KToggleAction
>("editable_location");
1642 editableLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1643 editableLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
1644 connect(editableLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1646 KAction
* replaceLocation
= actionCollection()->addAction("replace_location");
1647 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1648 replaceLocation
->setShortcut(Qt::Key_F6
);
1649 connect(replaceLocation
, SIGNAL(triggered()), this, SLOT(replaceLocation()));
1652 KAction
* backAction
= KStandardAction::back(this, SLOT(goBack()), actionCollection());
1653 connect(backAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goBack(Qt::MouseButtons
)));
1654 KShortcut backShortcut
= backAction
->shortcut();
1655 backShortcut
.setAlternate(Qt::Key_Backspace
);
1656 backAction
->setShortcut(backShortcut
);
1658 m_recentTabsMenu
= new KActionMenu(i18n("Recently Closed Tabs"), this);
1659 m_recentTabsMenu
->setIcon(KIcon("edit-undo"));
1660 actionCollection()->addAction("closed_tabs", m_recentTabsMenu
);
1661 connect(m_recentTabsMenu
->menu(), SIGNAL(triggered(QAction
*)),
1662 this, SLOT(restoreClosedTab(QAction
*)));
1664 QAction
* action
= new QAction(i18n("Empty Recently Closed Tabs"), m_recentTabsMenu
);
1665 action
->setIcon(KIcon("edit-clear-list"));
1666 action
->setData(QVariant::fromValue(true));
1667 m_recentTabsMenu
->addAction(action
);
1668 m_recentTabsMenu
->addSeparator();
1669 m_recentTabsMenu
->setEnabled(false);
1671 KAction
* forwardAction
= KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1672 connect(forwardAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goForward(Qt::MouseButtons
)));
1674 KAction
* upAction
= KStandardAction::up(this, SLOT(goUp()), actionCollection());
1675 connect(upAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goUp(Qt::MouseButtons
)));
1677 KAction
* homeAction
= KStandardAction::home(this, SLOT(goHome()), actionCollection());
1678 connect(homeAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goHome(Qt::MouseButtons
)));
1680 // setup 'Tools' menu
1681 KAction
* showFilterBar
= actionCollection()->addAction("show_filter_bar");
1682 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1683 showFilterBar
->setIcon(KIcon("view-filter"));
1684 showFilterBar
->setShortcut(Qt::CTRL
| Qt::Key_I
);
1685 connect(showFilterBar
, SIGNAL(triggered()), this, SLOT(showFilterBar()));
1687 KAction
* compareFiles
= actionCollection()->addAction("compare_files");
1688 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1689 compareFiles
->setIcon(KIcon("kompare"));
1690 compareFiles
->setEnabled(false);
1691 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
1693 KAction
* openTerminal
= actionCollection()->addAction("open_terminal");
1694 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1695 openTerminal
->setIcon(KIcon("utilities-terminal"));
1696 openTerminal
->setShortcut(Qt::SHIFT
| Qt::Key_F4
);
1697 connect(openTerminal
, SIGNAL(triggered()), this, SLOT(openTerminal()));
1699 // setup 'Settings' menu
1700 KToggleAction
* showMenuBar
= KStandardAction::showMenubar(0, 0, actionCollection());
1701 connect(showMenuBar
, SIGNAL(triggered(bool)), // Fixes #286822
1702 this, SLOT(toggleShowMenuBar()), Qt::QueuedConnection
);
1703 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1705 // not in menu actions
1706 QList
<QKeySequence
> nextTabKeys
;
1707 nextTabKeys
.append(KStandardShortcut::tabNext().primary());
1708 nextTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::Key_Tab
));
1710 QList
<QKeySequence
> prevTabKeys
;
1711 prevTabKeys
.append(KStandardShortcut::tabPrev().primary());
1712 prevTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::SHIFT
| Qt::Key_Tab
));
1714 KAction
* activateNextTab
= actionCollection()->addAction("activate_next_tab");
1715 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1716 connect(activateNextTab
, SIGNAL(triggered()), SLOT(activateNextTab()));
1717 activateNextTab
->setShortcuts(QApplication::isRightToLeft() ? prevTabKeys
: nextTabKeys
);
1719 KAction
* activatePrevTab
= actionCollection()->addAction("activate_prev_tab");
1720 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1721 connect(activatePrevTab
, SIGNAL(triggered()), SLOT(activatePrevTab()));
1722 activatePrevTab
->setShortcuts(QApplication::isRightToLeft() ? nextTabKeys
: prevTabKeys
);
1725 KAction
* openInNewTab
= actionCollection()->addAction("open_in_new_tab");
1726 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1727 openInNewTab
->setIcon(KIcon("tab-new"));
1728 connect(openInNewTab
, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1730 KAction
* openInNewWindow
= actionCollection()->addAction("open_in_new_window");
1731 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1732 openInNewWindow
->setIcon(KIcon("window-new"));
1733 connect(openInNewWindow
, SIGNAL(triggered()), this, SLOT(openInNewWindow()));
1736 void DolphinMainWindow::setupDockWidgets()
1738 const bool lock
= GeneralSettings::lockPanels();
1740 KDualAction
* lockLayoutAction
= actionCollection()->add
<KDualAction
>("lock_panels");
1741 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
1742 lockLayoutAction
->setActiveIcon(KIcon("object-unlocked"));
1743 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
1744 lockLayoutAction
->setInactiveIcon(KIcon("object-locked"));
1745 lockLayoutAction
->setActive(lock
);
1746 connect(lockLayoutAction
, SIGNAL(triggered()), this, SLOT(togglePanelLockState()));
1748 // Setup "Information"
1749 DolphinDockWidget
* infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
1750 infoDock
->setLocked(lock
);
1751 infoDock
->setObjectName("infoDock");
1752 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1753 Panel
* infoPanel
= new InformationPanel(infoDock
);
1754 infoPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1755 connect(infoPanel
, SIGNAL(urlActivated(KUrl
)), this, SLOT(handleUrl(KUrl
)));
1756 infoDock
->setWidget(infoPanel
);
1758 QAction
* infoAction
= infoDock
->toggleViewAction();
1759 createPanelAction(KIcon("dialog-information"), Qt::Key_F11
, infoAction
, "show_information_panel");
1761 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1762 connect(this, SIGNAL(urlChanged(KUrl
)),
1763 infoPanel
, SLOT(setUrl(KUrl
)));
1764 connect(this, SIGNAL(selectionChanged(KFileItemList
)),
1765 infoPanel
, SLOT(setSelection(KFileItemList
)));
1766 connect(this, SIGNAL(requestItemInfo(KFileItem
)),
1767 infoPanel
, SLOT(requestDelayedItemInfo(KFileItem
)));
1770 DolphinDockWidget
* foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
1771 foldersDock
->setLocked(lock
);
1772 foldersDock
->setObjectName("foldersDock");
1773 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1774 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1775 foldersPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1776 foldersDock
->setWidget(foldersPanel
);
1778 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1779 createPanelAction(KIcon("folder"), Qt::Key_F7
, foldersAction
, "show_folders_panel");
1781 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1782 connect(this, SIGNAL(urlChanged(KUrl
)),
1783 foldersPanel
, SLOT(setUrl(KUrl
)));
1784 connect(foldersPanel
, SIGNAL(changeUrl(KUrl
,Qt::MouseButtons
)),
1785 this, SLOT(handlePlacesClick(KUrl
,Qt::MouseButtons
)));
1789 DolphinDockWidget
* terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1790 terminalDock
->setLocked(lock
);
1791 terminalDock
->setObjectName("terminalDock");
1792 terminalDock
->setAllowedAreas(Qt::TopDockWidgetArea
| Qt::BottomDockWidgetArea
);
1793 Panel
* terminalPanel
= new TerminalPanel(terminalDock
);
1794 terminalPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1795 terminalDock
->setWidget(terminalPanel
);
1797 connect(terminalPanel
, SIGNAL(hideTerminalPanel()), terminalDock
, SLOT(hide()));
1798 connect(terminalDock
, SIGNAL(visibilityChanged(bool)),
1799 terminalPanel
, SLOT(dockVisibilityChanged()));
1801 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1802 createPanelAction(KIcon("utilities-terminal"), Qt::Key_F4
, terminalAction
, "show_terminal_panel");
1804 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1805 connect(this, SIGNAL(urlChanged(KUrl
)),
1806 terminalPanel
, SLOT(setUrl(KUrl
)));
1811 DolphinDockWidget
* searchDock
= new DolphinDockWidget(i18nc("@title:window", "Search"));
1812 searchDock
->setLocked(lock
);
1813 searchDock
->setObjectName("searchDock");
1814 searchDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1815 Panel
* searchPanel
= new SearchPanel(searchDock
);
1816 searchPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1817 connect(searchPanel
, SIGNAL(urlActivated(KUrl
)), this, SLOT(handleUrl(KUrl
)));
1818 searchDock
->setWidget(searchPanel
);
1820 QAction
* searchAction
= searchDock
->toggleViewAction();
1821 createPanelAction(KIcon("system-search"), Qt::Key_F12
, searchAction
, "show_search_panel");
1822 addDockWidget(Qt::RightDockWidgetArea
, searchDock
);
1823 connect(this, SIGNAL(urlChanged(KUrl
)),
1824 searchPanel
, SLOT(setUrl(KUrl
)));
1827 if (GeneralSettings::version() < 200) {
1829 foldersDock
->hide();
1831 terminalDock
->hide();
1839 DolphinDockWidget
* placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
1840 placesDock
->setLocked(lock
);
1841 placesDock
->setObjectName("placesDock");
1842 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1844 PlacesPanel
* placesPanel
= new PlacesPanel(placesDock
);
1845 QAction
* separator
= new QAction(placesPanel
);
1846 separator
->setSeparator(true);
1847 QList
<QAction
*> placesActions
;
1848 placesActions
.append(separator
);
1849 placesActions
.append(lockLayoutAction
);
1850 //placesPanel->addActions(placesActions);
1851 //placesPanel->setModel(DolphinPlacesModel::instance());
1852 //placesPanel->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
1853 placesDock
->setWidget(placesPanel
);
1855 QAction
* placesAction
= placesDock
->toggleViewAction();
1856 createPanelAction(KIcon("bookmarks"), Qt::Key_F9
, placesAction
, "show_places_panel");
1858 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1859 //connect(placesPanel, SIGNAL(urlChanged(KUrl,Qt::MouseButtons)),
1860 // this, SLOT(handlePlacesClick(KUrl,Qt::MouseButtons)));
1861 connect(this, SIGNAL(urlChanged(KUrl
)),
1862 placesPanel
, SLOT(setUrl(KUrl
)));
1863 connect(placesDock
, SIGNAL(visibilityChanged(bool)),
1864 this, SLOT(slotPlacesPanelVisibilityChanged(bool)));
1866 // Add actions into the "Panels" menu
1867 KActionMenu
* panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Panels"), this);
1868 actionCollection()->addAction("panels", panelsMenu
);
1869 panelsMenu
->setDelayed(false);
1870 const KActionCollection
* ac
= actionCollection();
1871 panelsMenu
->addAction(ac
->action("show_places_panel"));
1872 panelsMenu
->addAction(ac
->action("show_information_panel"));
1873 panelsMenu
->addAction(ac
->action("show_folders_panel"));
1875 panelsMenu
->addAction(ac
->action("show_terminal_panel"));
1878 panelsMenu
->addAction(ac
->action("show_search_panel"));
1880 panelsMenu
->addSeparator();
1881 panelsMenu
->addAction(lockLayoutAction
);
1884 void DolphinMainWindow::updateEditActions()
1886 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1887 if (list
.isEmpty()) {
1888 stateChanged("has_no_selection");
1890 stateChanged("has_selection");
1892 KActionCollection
* col
= actionCollection();
1893 QAction
* renameAction
= col
->action("rename");
1894 QAction
* moveToTrashAction
= col
->action("move_to_trash");
1895 QAction
* deleteAction
= col
->action("delete");
1896 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
1897 QAction
* deleteWithTrashShortcut
= col
->action("delete_shortcut"); // see DolphinViewActionHandler
1899 KFileItemListProperties
capabilities(list
);
1900 const bool enableMoveToTrash
= capabilities
.isLocal() && capabilities
.supportsMoving();
1902 renameAction
->setEnabled(capabilities
.supportsMoving());
1903 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1904 deleteAction
->setEnabled(capabilities
.supportsDeleting());
1905 deleteWithTrashShortcut
->setEnabled(capabilities
.supportsDeleting() && !enableMoveToTrash
);
1906 cutAction
->setEnabled(capabilities
.supportsMoving());
1908 updatePasteAction();
1911 void DolphinMainWindow::updateViewActions()
1913 m_actionHandler
->updateViewActions();
1915 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1916 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
1918 updateSplitAction();
1920 QAction
* editableLocactionAction
= actionCollection()->action("editable_location");
1921 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
1922 editableLocactionAction
->setChecked(urlNavigator
->isUrlEditable());
1925 void DolphinMainWindow::updateGoActions()
1927 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
1928 const KUrl currentUrl
= m_activeViewContainer
->url();
1929 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
1932 void DolphinMainWindow::createControlButton()
1934 if (m_controlButton
) {
1937 Q_ASSERT(!m_controlButton
);
1939 m_controlButton
= new QToolButton(this);
1940 m_controlButton
->setIcon(KIcon("applications-system"));
1941 m_controlButton
->setText(i18nc("@action", "Control"));
1942 m_controlButton
->setPopupMode(QToolButton::InstantPopup
);
1943 m_controlButton
->setToolButtonStyle(toolBar()->toolButtonStyle());
1945 KMenu
* controlMenu
= new KMenu(m_controlButton
);
1946 connect(controlMenu
, SIGNAL(aboutToShow()), this, SLOT(updateControlMenu()));
1948 m_controlButton
->setMenu(controlMenu
);
1950 toolBar()->addWidget(m_controlButton
);
1951 connect(toolBar(), SIGNAL(iconSizeChanged(QSize
)),
1952 m_controlButton
, SLOT(setIconSize(QSize
)));
1953 connect(toolBar(), SIGNAL(toolButtonStyleChanged(Qt::ToolButtonStyle
)),
1954 m_controlButton
, SLOT(setToolButtonStyle(Qt::ToolButtonStyle
)));
1956 // The added widgets are owned by the toolbar and may get deleted when e.g. the toolbar
1957 // gets edited. In this case we must add them again. The adding is done asynchronously by
1958 // m_updateToolBarTimer.
1959 connect(m_controlButton
, SIGNAL(destroyed()), this, SLOT(slotControlButtonDeleted()));
1960 m_updateToolBarTimer
= new QTimer(this);
1961 m_updateToolBarTimer
->setInterval(500);
1962 connect(m_updateToolBarTimer
, SIGNAL(timeout()), this, SLOT(updateToolBar()));
1965 void DolphinMainWindow::deleteControlButton()
1967 delete m_controlButton
;
1968 m_controlButton
= 0;
1970 delete m_updateToolBarTimer
;
1971 m_updateToolBarTimer
= 0;
1974 bool DolphinMainWindow::addActionToMenu(QAction
* action
, KMenu
* menu
)
1979 const KToolBar
* toolBarWidget
= toolBar();
1980 foreach (const QWidget
* widget
, action
->associatedWidgets()) {
1981 if (widget
== toolBarWidget
) {
1986 menu
->addAction(action
);
1990 void DolphinMainWindow::rememberClosedTab(int index
)
1992 KMenu
* tabsMenu
= m_recentTabsMenu
->menu();
1994 const QString primaryPath
= m_viewTab
[index
].primaryView
->url().path();
1995 const QString iconName
= KMimeType::iconNameForUrl(primaryPath
);
1997 QAction
* action
= new QAction(squeezedText(primaryPath
), tabsMenu
);
1999 ClosedTab closedTab
;
2000 closedTab
.primaryUrl
= m_viewTab
[index
].primaryView
->url();
2002 if (m_viewTab
[index
].secondaryView
) {
2003 closedTab
.secondaryUrl
= m_viewTab
[index
].secondaryView
->url();
2004 closedTab
.isSplit
= true;
2006 closedTab
.isSplit
= false;
2009 action
->setData(QVariant::fromValue(closedTab
));
2010 action
->setIcon(KIcon(iconName
));
2012 // add the closed tab menu entry after the separator and
2013 // "Empty Recently Closed Tabs" entry
2014 if (tabsMenu
->actions().size() == 2) {
2015 tabsMenu
->addAction(action
);
2017 tabsMenu
->insertAction(tabsMenu
->actions().at(2), action
);
2020 // assure that only up to 8 closed tabs are shown in the menu
2021 if (tabsMenu
->actions().size() > 8) {
2022 tabsMenu
->removeAction(tabsMenu
->actions().last());
2024 actionCollection()->action("closed_tabs")->setEnabled(true);
2025 KAcceleratorManager::manage(tabsMenu
);
2028 void DolphinMainWindow::refreshViews()
2030 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
2032 // remember the current active view, as because of
2033 // the refreshing the active view might change to
2034 // the secondary view
2035 DolphinViewContainer
* activeViewContainer
= m_activeViewContainer
;
2037 const int tabCount
= m_viewTab
.count();
2038 for (int i
= 0; i
< tabCount
; ++i
) {
2039 m_viewTab
[i
].primaryView
->readSettings();
2040 if (m_viewTab
[i
].secondaryView
) {
2041 m_viewTab
[i
].secondaryView
->readSettings();
2045 setActiveViewContainer(activeViewContainer
);
2047 if (GeneralSettings::modifiedStartupSettings()) {
2048 // The startup settings have been changed by the user (see bug #254947).
2049 // Synchronize the split-view setting with the active view:
2050 const bool splitView
= GeneralSettings::splitView();
2051 const ViewTab
& activeTab
= m_viewTab
[m_tabIndex
];
2052 const bool toggle
= ( splitView
&& !activeTab
.secondaryView
)
2053 || (!splitView
&& activeTab
.secondaryView
);
2060 void DolphinMainWindow::clearStatusBar()
2062 m_activeViewContainer
->statusBar()->resetToDefaultText();
2065 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
2067 connect(container
, SIGNAL(showFilterBarChanged(bool)),
2068 this, SLOT(updateFilterBarAction(bool)));
2069 connect(container
, SIGNAL(writeStateChanged(bool)),
2070 this, SLOT(slotWriteStateChanged(bool)));
2071 connect(container
, SIGNAL(searchModeChanged(bool)),
2072 this, SLOT(slotSearchModeChanged(bool)));
2074 const DolphinSearchBox
* searchBox
= container
->searchBox();
2075 connect(searchBox
, SIGNAL(searchLocationChanged(SearchLocation
)),
2076 this, SLOT(slotSearchLocationChanged()));
2078 DolphinView
* view
= container
->view();
2079 connect(view
, SIGNAL(selectionChanged(KFileItemList
)),
2080 this, SLOT(slotSelectionChanged(KFileItemList
)));
2081 connect(view
, SIGNAL(requestItemInfo(KFileItem
)),
2082 this, SLOT(slotRequestItemInfo(KFileItem
)));
2083 connect(view
, SIGNAL(activated()),
2084 this, SLOT(toggleActiveView()));
2085 connect(view
, SIGNAL(tabRequested(KUrl
)),
2086 this, SLOT(openNewTab(KUrl
)));
2087 connect(view
, SIGNAL(requestContextMenu(QPoint
,KFileItem
,KUrl
,QList
<QAction
*>)),
2088 this, SLOT(openContextMenu(QPoint
,KFileItem
,KUrl
,QList
<QAction
*>)));
2089 connect(view
, SIGNAL(directoryLoadingStarted()),
2090 this, SLOT(enableStopAction()));
2091 connect(view
, SIGNAL(directoryLoadingCompleted()),
2092 this, SLOT(disableStopAction()));
2093 connect(view
, SIGNAL(goBackRequested()),
2094 this, SLOT(goBack()));
2095 connect(view
, SIGNAL(goForwardRequested()),
2096 this, SLOT(goForward()));
2098 const KUrlNavigator
* navigator
= container
->urlNavigator();
2099 connect(navigator
, SIGNAL(urlChanged(KUrl
)),
2100 this, SLOT(changeUrl(KUrl
)));
2101 connect(navigator
, SIGNAL(historyChanged()),
2102 this, SLOT(updateHistory()));
2103 connect(navigator
, SIGNAL(editableStateChanged(bool)),
2104 this, SLOT(slotEditableStateChanged(bool)));
2105 connect(navigator
, SIGNAL(tabRequested(KUrl
)),
2106 this, SLOT(openNewTab(KUrl
)));
2109 void DolphinMainWindow::updateSplitAction()
2111 QAction
* splitAction
= actionCollection()->action("split_view");
2112 if (m_viewTab
[m_tabIndex
].secondaryView
) {
2113 if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
2114 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
2115 splitAction
->setToolTip(i18nc("@info", "Close right view"));
2116 splitAction
->setIcon(KIcon("view-right-close"));
2118 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
2119 splitAction
->setToolTip(i18nc("@info", "Close left view"));
2120 splitAction
->setIcon(KIcon("view-left-close"));
2123 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
2124 splitAction
->setToolTip(i18nc("@info", "Split view"));
2125 splitAction
->setIcon(KIcon("view-right-new"));
2129 QString
DolphinMainWindow::tabName(const KUrl
& url
) const
2132 if (url
.equals(KUrl("file:///"))) {
2135 name
= url
.fileName();
2136 if (name
.isEmpty()) {
2137 name
= url
.protocol();
2139 // Make sure that a '&' inside the directory name is displayed correctly
2140 // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
2141 name
.replace('&', "&&");
2147 bool DolphinMainWindow::isKompareInstalled() const
2149 static bool initialized
= false;
2150 static bool installed
= false;
2152 // TODO: maybe replace this approach later by using a menu
2153 // plugin like kdiff3plugin.cpp
2154 installed
= !KGlobal::dirs()->findExe("kompare").isEmpty();
2160 void DolphinMainWindow::createSecondaryView(int tabIndex
)
2162 ViewTab
& viewTab
= m_viewTab
[tabIndex
];
2164 QSplitter
* splitter
= viewTab
.splitter
;
2165 const int newWidth
= (viewTab
.primaryView
->width() - splitter
->handleWidth()) / 2;
2167 const DolphinView
* view
= viewTab
.primaryView
->view();
2168 viewTab
.secondaryView
= createViewContainer(view
->url(), 0);
2169 splitter
->addWidget(viewTab
.secondaryView
);
2170 splitter
->setSizes(QList
<int>() << newWidth
<< newWidth
);
2172 connectViewSignals(viewTab
.secondaryView
);
2173 viewTab
.secondaryView
->setActive(false);
2174 viewTab
.secondaryView
->resize(newWidth
, viewTab
.primaryView
->height());
2175 viewTab
.secondaryView
->show();
2178 QString
DolphinMainWindow::tabProperty(const QString
& property
, int tabIndex
) const
2180 return "Tab " + QString::number(tabIndex
) + ' ' + property
;
2183 void DolphinMainWindow::setUrlAsCaption(const KUrl
& url
)
2186 if (!url
.isLocalFile()) {
2187 caption
.append(url
.protocol() + " - ");
2188 if (url
.hasHost()) {
2189 caption
.append(url
.host() + " - ");
2193 const QString fileName
= url
.fileName().isEmpty() ? "/" : url
.fileName();
2194 caption
.append(fileName
);
2196 setCaption(caption
);
2199 QString
DolphinMainWindow::squeezedText(const QString
& text
) const
2201 const QFontMetrics fm
= fontMetrics();
2202 return fm
.elidedText(text
, Qt::ElideMiddle
, fm
.maxWidth() * 10);
2205 void DolphinMainWindow::createPanelAction(const KIcon
& icon
,
2206 const QKeySequence
& shortcut
,
2207 QAction
* dockAction
,
2208 const QString
& actionName
)
2210 KAction
* panelAction
= actionCollection()->addAction(actionName
);
2211 panelAction
->setCheckable(true);
2212 panelAction
->setChecked(dockAction
->isChecked());
2213 panelAction
->setText(dockAction
->text());
2214 panelAction
->setIcon(icon
);
2215 panelAction
->setShortcut(shortcut
);
2217 connect(panelAction
, SIGNAL(triggered()), dockAction
, SLOT(trigger()));
2218 connect(dockAction
, SIGNAL(toggled(bool)), panelAction
, SLOT(setChecked(bool)));
2221 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
2222 KIO::FileUndoManager::UiInterface()
2226 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2230 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
2232 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
2234 DolphinViewContainer
* container
= mainWin
->activeViewContainer();
2235 container
->showMessage(job
->errorString(), DolphinViewContainer::Error
);
2237 KIO::FileUndoManager::UiInterface::jobError(job
);
2241 #include "dolphinmainwindow.moc"