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
->setText(i18nc("@info:status", "Successfully copied."));
336 case KIO::FileUndoManager::Move
:
337 statusBar
->setText(i18nc("@info:status", "Successfully moved."));
339 case KIO::FileUndoManager::Link
:
340 statusBar
->setText(i18nc("@info:status", "Successfully linked."));
342 case KIO::FileUndoManager::Trash
:
343 statusBar
->setText(i18nc("@info:status", "Successfully moved to trash."));
345 case KIO::FileUndoManager::Rename
:
346 statusBar
->setText(i18nc("@info:status", "Successfully renamed."));
349 case KIO::FileUndoManager::Mkdir
:
350 statusBar
->setText(i18nc("@info:status", "Created folder."));
358 void DolphinMainWindow::pasteIntoFolder()
360 m_activeViewContainer
->view()->pasteIntoFolder();
363 void DolphinMainWindow::changeUrl(const KUrl
& url
)
365 if (!KProtocolManager::supportsListing(url
)) {
366 // The URL navigator only checks for validity, not
367 // if the URL can be listed. An error message is
368 // shown due to DolphinViewContainer::restoreView().
372 DolphinViewContainer
* view
= activeViewContainer();
378 setUrlAsCaption(url
);
379 if (m_viewTab
.count() > 1) {
380 m_tabBar
->setTabText(m_tabIndex
, squeezedText(tabName(m_activeViewContainer
->url())));
382 const QString iconName
= KMimeType::iconNameForUrl(url
);
383 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(iconName
));
384 emit
urlChanged(url
);
388 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
390 KToggleAction
* editableLocationAction
=
391 static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
392 editableLocationAction
->setChecked(editable
);
395 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
399 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
400 int selectedUrlsCount
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedItemsCount();
401 if (m_viewTab
[m_tabIndex
].secondaryView
) {
402 selectedUrlsCount
+= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItemsCount();
405 QAction
* compareFilesAction
= actionCollection()->action("compare_files");
406 if (selectedUrlsCount
== 2) {
407 compareFilesAction
->setEnabled(isKompareInstalled());
409 compareFilesAction
->setEnabled(false);
412 emit
selectionChanged(selection
);
415 void DolphinMainWindow::slotRequestItemInfo(const KFileItem
& item
)
417 emit
requestItemInfo(item
);
420 void DolphinMainWindow::updateHistory()
422 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
423 const int index
= urlNavigator
->historyIndex();
425 QAction
* backAction
= actionCollection()->action("go_back");
427 backAction
->setToolTip(i18nc("@info", "Go back"));
428 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
431 QAction
* forwardAction
= actionCollection()->action("go_forward");
433 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
434 forwardAction
->setEnabled(index
> 0);
438 void DolphinMainWindow::updateFilterBarAction(bool show
)
440 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
441 showFilterBarAction
->setChecked(show
);
444 void DolphinMainWindow::openNewMainWindow()
446 KRun::run("dolphin", KUrl::List(), this);
449 void DolphinMainWindow::openNewTab()
451 const bool isUrlEditable
= m_activeViewContainer
->urlNavigator()->isUrlEditable();
453 openNewTab(m_activeViewContainer
->url());
454 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
456 // The URL navigator of the new tab should have the same editable state
457 // as the current tab
458 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
459 navigator
->setUrlEditable(isUrlEditable
);
462 // If a new tab is opened and the URL is editable, assure that
463 // the user can edit the URL without manually setting the focus
464 navigator
->setFocus();
468 void DolphinMainWindow::openNewTab(const KUrl
& url
)
470 QWidget
* focusWidget
= QApplication::focusWidget();
472 if (m_viewTab
.count() == 1) {
473 // Only one view is open currently and hence no tab is shown at
474 // all. Before creating a tab for 'url', provide a tab for the current URL.
475 const KUrl currentUrl
= m_activeViewContainer
->url();
476 m_tabBar
->addTab(KIcon(KMimeType::iconNameForUrl(currentUrl
)),
477 squeezedText(tabName(currentUrl
)));
478 m_tabBar
->blockSignals(false);
481 m_tabBar
->addTab(KIcon(KMimeType::iconNameForUrl(url
)),
482 squeezedText(tabName(url
)));
485 viewTab
.splitter
= new QSplitter(this);
486 viewTab
.splitter
->setChildrenCollapsible(false);
487 viewTab
.primaryView
= createViewContainer(url
, viewTab
.splitter
);
488 viewTab
.primaryView
->setActive(false);
489 connectViewSignals(viewTab
.primaryView
);
491 m_viewTab
.append(viewTab
);
493 actionCollection()->action("close_tab")->setEnabled(true);
495 // Provide a split view, if the startup settings are set this way
496 if (GeneralSettings::splitView()) {
497 const int newTabIndex
= m_viewTab
.count() - 1;
498 createSecondaryView(newTabIndex
);
499 m_viewTab
[newTabIndex
].secondaryView
->setActive(true);
500 m_viewTab
[newTabIndex
].isPrimaryViewActive
= false;
504 // The DolphinViewContainer grabbed the keyboard focus. As the tab is opened
505 // in background, assure that the previous focused widget gets the focus back.
506 focusWidget
->setFocus();
510 void DolphinMainWindow::activateNextTab()
512 if (m_viewTab
.count() >= 2) {
513 const int tabIndex
= (m_tabBar
->currentIndex() + 1) % m_tabBar
->count();
514 m_tabBar
->setCurrentIndex(tabIndex
);
518 void DolphinMainWindow::activatePrevTab()
520 if (m_viewTab
.count() >= 2) {
521 int tabIndex
= m_tabBar
->currentIndex() - 1;
522 if (tabIndex
== -1) {
523 tabIndex
= m_tabBar
->count() - 1;
525 m_tabBar
->setCurrentIndex(tabIndex
);
529 void DolphinMainWindow::openInNewTab()
531 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
532 if (list
.isEmpty()) {
533 openNewTab(m_activeViewContainer
->url());
534 } else if ((list
.count() == 1) && list
[0].isDir()) {
535 openNewTab(list
[0].url());
539 void DolphinMainWindow::openInNewWindow()
543 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
544 if (list
.isEmpty()) {
545 newWindowUrl
= m_activeViewContainer
->url();
546 } else if ((list
.count() == 1) && list
[0].isDir()) {
547 newWindowUrl
= list
[0].url();
550 if (!newWindowUrl
.isEmpty()) {
551 KRun::run("dolphin", KUrl::List() << newWindowUrl
, this);
555 void DolphinMainWindow::toggleActiveView()
557 if (!m_viewTab
[m_tabIndex
].secondaryView
) {
558 // only one view is available
562 Q_ASSERT(m_activeViewContainer
);
563 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
565 DolphinViewContainer
* left
= m_viewTab
[m_tabIndex
].primaryView
;
566 DolphinViewContainer
* right
= m_viewTab
[m_tabIndex
].secondaryView
;
567 setActiveViewContainer(m_activeViewContainer
== right
? left
: right
);
570 void DolphinMainWindow::showEvent(QShowEvent
* event
)
572 KXmlGuiWindow::showEvent(event
);
573 if (!event
->spontaneous()) {
574 m_activeViewContainer
->view()->setFocus();
578 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
580 // Find out if Dolphin is closed directly by the user or
581 // by the session manager because the session is closed
582 bool closedByUser
= true;
583 DolphinApplication
*application
= qobject_cast
<DolphinApplication
*>(qApp
);
584 if (application
&& application
->sessionSaving()) {
585 closedByUser
= false;
588 if (m_viewTab
.count() > 1 && GeneralSettings::confirmClosingMultipleTabs() && closedByUser
) {
589 // Ask the user if he really wants to quit and close all tabs.
590 // Open a confirmation dialog with 3 buttons:
591 // KDialog::Yes -> Quit
592 // KDialog::No -> Close only the current tab
593 // KDialog::Cancel -> do nothing
594 KDialog
*dialog
= new KDialog(this, Qt::Dialog
);
595 dialog
->setCaption(i18nc("@title:window", "Confirmation"));
596 dialog
->setButtons(KDialog::Yes
| KDialog::No
| KDialog::Cancel
);
597 dialog
->setModal(true);
598 dialog
->setButtonGuiItem(KDialog::Yes
, KStandardGuiItem::quit());
599 dialog
->setButtonGuiItem(KDialog::No
, KGuiItem(i18n("C&lose Current Tab"), KIcon("tab-close")));
600 dialog
->setButtonGuiItem(KDialog::Cancel
, KStandardGuiItem::cancel());
601 dialog
->setDefaultButton(KDialog::Yes
);
603 bool doNotAskAgainCheckboxResult
= false;
605 const int result
= KMessageBox::createKMessageBox(dialog
,
606 QMessageBox::Warning
,
607 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
609 i18n("Do not ask again"),
610 &doNotAskAgainCheckboxResult
,
611 KMessageBox::Notify
);
613 if (doNotAskAgainCheckboxResult
) {
614 GeneralSettings::setConfirmClosingMultipleTabs(false);
622 // Close only the current tab
630 GeneralSettings::setVersion(CurrentDolphinVersion
);
631 GeneralSettings::self()->writeConfig();
633 if (m_searchDockIsTemporaryVisible
) {
634 QDockWidget
* searchDock
= findChild
<QDockWidget
*>("searchDock");
638 m_searchDockIsTemporaryVisible
= false;
641 KXmlGuiWindow::closeEvent(event
);
644 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
646 const int tabCount
= m_viewTab
.count();
647 group
.writeEntry("Tab Count", tabCount
);
648 group
.writeEntry("Active Tab Index", m_tabBar
->currentIndex());
650 for (int i
= 0; i
< tabCount
; ++i
) {
651 const DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
652 group
.writeEntry(tabProperty("Primary URL", i
), cont
->url().url());
653 group
.writeEntry(tabProperty("Primary Editable", i
),
654 cont
->urlNavigator()->isUrlEditable());
656 cont
= m_viewTab
[i
].secondaryView
;
658 group
.writeEntry(tabProperty("Secondary URL", i
), cont
->url().url());
659 group
.writeEntry(tabProperty("Secondary Editable", i
),
660 cont
->urlNavigator()->isUrlEditable());
665 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
667 const int tabCount
= group
.readEntry("Tab Count", 1);
668 for (int i
= 0; i
< tabCount
; ++i
) {
669 DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
671 cont
->setUrl(group
.readEntry(tabProperty("Primary URL", i
)));
672 const bool editable
= group
.readEntry(tabProperty("Primary Editable", i
), false);
673 cont
->urlNavigator()->setUrlEditable(editable
);
675 cont
= m_viewTab
[i
].secondaryView
;
676 const QString secondaryUrl
= group
.readEntry(tabProperty("Secondary URL", i
));
677 if (!secondaryUrl
.isEmpty()) {
679 // a secondary view should be shown, but no one is available
680 // currently -> create a new view
682 cont
= m_viewTab
[i
].secondaryView
;
686 cont
->setUrl(secondaryUrl
);
687 const bool editable
= group
.readEntry(tabProperty("Secondary Editable", i
), false);
688 cont
->urlNavigator()->setUrlEditable(editable
);
690 // no secondary view should be shown, but the default setting shows
691 // one already -> close the view
695 // openNewTab() needs to be called only tabCount - 1 times
696 if (i
!= tabCount
- 1) {
701 const int index
= group
.readEntry("Active Tab Index", 0);
702 m_tabBar
->setCurrentIndex(index
);
705 void DolphinMainWindow::updateNewMenu()
707 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
708 m_newFileMenu
->checkUpToDate();
709 m_newFileMenu
->setPopupFiles(activeViewContainer()->url());
712 void DolphinMainWindow::createDirectory()
714 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
715 m_newFileMenu
->setPopupFiles(activeViewContainer()->url());
716 m_newFileMenu
->createDirectory();
719 void DolphinMainWindow::quit()
724 void DolphinMainWindow::showErrorMessage(const QString
& message
)
726 m_activeViewContainer
->showMessage(message
, DolphinViewContainer::Error
);
729 void DolphinMainWindow::slotUndoAvailable(bool available
)
731 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
733 undoAction
->setEnabled(available
);
737 void DolphinMainWindow::restoreClosedTab(QAction
* action
)
739 if (action
->data().toBool()) {
740 // clear all actions except the "Empty Recently Closed Tabs"
741 // action and the separator
742 QList
<QAction
*> actions
= m_recentTabsMenu
->menu()->actions();
743 const int count
= actions
.size();
744 for (int i
= 2; i
< count
; ++i
) {
745 m_recentTabsMenu
->menu()->removeAction(actions
.at(i
));
748 const ClosedTab closedTab
= action
->data().value
<ClosedTab
>();
749 openNewTab(closedTab
.primaryUrl
);
750 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
752 if (closedTab
.isSplit
) {
753 // create secondary view
755 m_viewTab
[m_tabIndex
].secondaryView
->setUrl(closedTab
.secondaryUrl
);
758 m_recentTabsMenu
->removeAction(action
);
761 if (m_recentTabsMenu
->menu()->actions().count() == 2) {
762 m_recentTabsMenu
->setEnabled(false);
766 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
768 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
770 undoAction
->setText(text
);
774 void DolphinMainWindow::undo()
777 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
778 KIO::FileUndoManager::self()->undo();
781 void DolphinMainWindow::cut()
783 m_activeViewContainer
->view()->cutSelectedItems();
786 void DolphinMainWindow::copy()
788 m_activeViewContainer
->view()->copySelectedItems();
791 void DolphinMainWindow::paste()
793 m_activeViewContainer
->view()->paste();
796 void DolphinMainWindow::find()
798 m_activeViewContainer
->setSearchModeEnabled(true);
801 void DolphinMainWindow::slotSearchLocationChanged()
804 QDockWidget
* searchDock
= findChild
<QDockWidget
*>("searchDock");
809 SearchPanel
* searchPanel
= qobject_cast
<SearchPanel
*>(searchDock
->widget());
811 searchPanel
->setSearchLocation(SearchSettings::location() == QLatin1String("FromHere")
812 ? SearchPanel::FromCurrentDir
813 : SearchPanel::Everywhere
);
818 void DolphinMainWindow::updatePasteAction()
820 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
821 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
822 pasteAction
->setEnabled(pasteInfo
.first
);
823 pasteAction
->setText(pasteInfo
.second
);
826 void DolphinMainWindow::selectAll()
830 // if the URL navigator is editable and focused, select the whole
831 // URL instead of all items of the view
833 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
834 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit(); // krazy:exclude=qclasses
835 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
836 lineEdit
->hasFocus();
838 lineEdit
->selectAll();
840 m_activeViewContainer
->view()->selectAll();
844 void DolphinMainWindow::invertSelection()
847 m_activeViewContainer
->view()->invertSelection();
850 void DolphinMainWindow::toggleSplitView()
852 if (!m_viewTab
[m_tabIndex
].secondaryView
) {
853 createSecondaryView(m_tabIndex
);
854 setActiveViewContainer(m_viewTab
[m_tabIndex
].secondaryView
);
855 } else if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
856 // remove secondary view
857 m_viewTab
[m_tabIndex
].secondaryView
->close();
858 m_viewTab
[m_tabIndex
].secondaryView
->deleteLater();
859 m_viewTab
[m_tabIndex
].secondaryView
= 0;
861 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
863 // The primary view is active and should be closed. Hence from a users point of view
864 // the content of the secondary view should be moved to the primary view.
865 // From an implementation point of view it is more efficient to close
866 // the primary view and exchange the internal pointers afterwards.
868 m_viewTab
[m_tabIndex
].primaryView
->close();
869 m_viewTab
[m_tabIndex
].primaryView
->deleteLater();
870 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
871 m_viewTab
[m_tabIndex
].secondaryView
= 0;
873 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
879 void DolphinMainWindow::reloadView()
882 m_activeViewContainer
->view()->reload();
885 void DolphinMainWindow::stopLoading()
887 m_activeViewContainer
->view()->stopLoading();
890 void DolphinMainWindow::enableStopAction()
892 actionCollection()->action("stop")->setEnabled(true);
895 void DolphinMainWindow::disableStopAction()
897 actionCollection()->action("stop")->setEnabled(false);
900 void DolphinMainWindow::showFilterBar()
902 m_activeViewContainer
->setFilterBarVisible(true);
905 void DolphinMainWindow::toggleEditLocation()
909 QAction
* action
= actionCollection()->action("editable_location");
910 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
911 urlNavigator
->setUrlEditable(action
->isChecked());
914 void DolphinMainWindow::replaceLocation()
916 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
917 navigator
->setUrlEditable(true);
918 navigator
->setFocus();
920 // select the whole text of the combo box editor
921 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit(); // krazy:exclude=qclasses
922 lineEdit
->selectAll();
925 void DolphinMainWindow::togglePanelLockState()
927 const bool newLockState
= !GeneralSettings::lockPanels();
928 foreach (QObject
* child
, children()) {
929 DolphinDockWidget
* dock
= qobject_cast
<DolphinDockWidget
*>(child
);
931 dock
->setLocked(newLockState
);
935 GeneralSettings::setLockPanels(newLockState
);
938 void DolphinMainWindow::slotPlacesPanelVisibilityChanged(bool visible
)
940 const int tabCount
= m_viewTab
.count();
941 for (int i
= 0; i
< tabCount
; ++i
) {
942 ViewTab
& tab
= m_viewTab
[i
];
943 Q_ASSERT(tab
.primaryView
);
944 tab
.primaryView
->urlNavigator()->setPlacesSelectorVisible(!visible
);
945 if (tab
.secondaryView
) {
946 tab
.secondaryView
->urlNavigator()->setPlacesSelectorVisible(!visible
);
951 void DolphinMainWindow::goBack()
953 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
954 urlNavigator
->goBack();
956 if (urlNavigator
->locationState().isEmpty()) {
957 // An empty location state indicates a redirection URL,
958 // which must be skipped too
959 urlNavigator
->goBack();
963 void DolphinMainWindow::goForward()
965 m_activeViewContainer
->urlNavigator()->goForward();
968 void DolphinMainWindow::goUp()
970 m_activeViewContainer
->urlNavigator()->goUp();
973 void DolphinMainWindow::goHome()
975 m_activeViewContainer
->urlNavigator()->goHome();
978 void DolphinMainWindow::goBack(Qt::MouseButtons buttons
)
980 // The default case (left button pressed) is handled in goBack().
981 if (buttons
== Qt::MidButton
) {
982 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
983 const int index
= urlNavigator
->historyIndex() + 1;
984 openNewTab(urlNavigator
->locationUrl(index
));
988 void DolphinMainWindow::goForward(Qt::MouseButtons buttons
)
990 // The default case (left button pressed) is handled in goForward().
991 if (buttons
== Qt::MidButton
) {
992 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
993 const int index
= urlNavigator
->historyIndex() - 1;
994 openNewTab(urlNavigator
->locationUrl(index
));
998 void DolphinMainWindow::goUp(Qt::MouseButtons buttons
)
1000 // The default case (left button pressed) is handled in goUp().
1001 if (buttons
== Qt::MidButton
) {
1002 openNewTab(activeViewContainer()->url().upUrl());
1006 void DolphinMainWindow::goHome(Qt::MouseButtons buttons
)
1008 // The default case (left button pressed) is handled in goHome().
1009 if (buttons
== Qt::MidButton
) {
1010 openNewTab(GeneralSettings::self()->homeUrl());
1014 void DolphinMainWindow::compareFiles()
1016 // The method is only invoked if exactly 2 files have
1017 // been selected. The selected files may be:
1018 // - both in the primary view
1019 // - both in the secondary view
1020 // - one in the primary view and the other in the secondary
1022 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
1027 KFileItemList items
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedItems();
1029 switch (items
.count()) {
1031 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
);
1032 items
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItems();
1033 Q_ASSERT(items
.count() == 2);
1034 urlA
= items
[0].url();
1035 urlB
= items
[1].url();
1040 urlA
= items
[0].url();
1041 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
);
1042 items
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItems();
1043 Q_ASSERT(items
.count() == 1);
1044 urlB
= items
[0].url();
1049 urlA
= items
[0].url();
1050 urlB
= items
[1].url();
1055 // may not happen: compareFiles may only get invoked if 2
1056 // files are selected
1061 QString
command("kompare -c \"");
1062 command
.append(urlA
.pathOrUrl());
1063 command
.append("\" \"");
1064 command
.append(urlB
.pathOrUrl());
1065 command
.append('\"');
1066 KRun::runCommand(command
, "Kompare", "kompare", this);
1069 void DolphinMainWindow::toggleShowMenuBar()
1071 const bool visible
= menuBar()->isVisible();
1072 menuBar()->setVisible(!visible
);
1074 createControlButton();
1076 deleteControlButton();
1080 void DolphinMainWindow::openTerminal()
1082 QString
dir(QDir::homePath());
1084 // If the given directory is not local, it can still be the URL of an
1085 // ioslave using UDS_LOCAL_PATH which to be converted first.
1086 KUrl url
= KIO::NetAccess::mostLocalUrl(m_activeViewContainer
->url(), this);
1088 //If the URL is local after the above conversion, set the directory.
1089 if (url
.isLocalFile()) {
1090 dir
= url
.toLocalFile();
1093 KToolInvocation::invokeTerminal(QString(), dir
);
1096 void DolphinMainWindow::editSettings()
1098 if (!m_settingsDialog
) {
1099 DolphinViewContainer
* container
= activeViewContainer();
1100 container
->view()->writeSettings();
1102 const KUrl url
= container
->url();
1103 DolphinSettingsDialog
* settingsDialog
= new DolphinSettingsDialog(url
, this);
1104 connect(settingsDialog
, SIGNAL(settingsChanged()), this, SLOT(refreshViews()));
1105 settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1106 settingsDialog
->show();
1107 m_settingsDialog
= settingsDialog
;
1109 m_settingsDialog
.data()->raise();
1113 void DolphinMainWindow::setActiveTab(int index
)
1115 Q_ASSERT(index
>= 0);
1116 Q_ASSERT(index
< m_viewTab
.count());
1117 if (index
== m_tabIndex
) {
1121 // hide current tab content
1122 ViewTab
& hiddenTab
= m_viewTab
[m_tabIndex
];
1123 hiddenTab
.isPrimaryViewActive
= hiddenTab
.primaryView
->isActive();
1124 hiddenTab
.primaryView
->setActive(false);
1125 if (hiddenTab
.secondaryView
) {
1126 hiddenTab
.secondaryView
->setActive(false);
1128 QSplitter
* splitter
= m_viewTab
[m_tabIndex
].splitter
;
1130 m_centralWidgetLayout
->removeWidget(splitter
);
1132 // show active tab content
1135 ViewTab
& viewTab
= m_viewTab
[index
];
1136 m_centralWidgetLayout
->addWidget(viewTab
.splitter
, 1);
1137 viewTab
.primaryView
->show();
1138 if (viewTab
.secondaryView
) {
1139 viewTab
.secondaryView
->show();
1141 viewTab
.splitter
->show();
1143 if (!viewTab
.wasActive
) {
1144 viewTab
.wasActive
= true;
1146 // If the tab has not been activated yet the size of the KItemListView is
1147 // undefined and results in an unwanted animation. To prevent this a
1148 // reloading of the directory gets triggered.
1149 viewTab
.primaryView
->view()->reload();
1150 if (viewTab
.secondaryView
) {
1151 viewTab
.secondaryView
->view()->reload();
1155 setActiveViewContainer(viewTab
.isPrimaryViewActive
? viewTab
.primaryView
:
1156 viewTab
.secondaryView
);
1159 void DolphinMainWindow::closeTab()
1161 closeTab(m_tabBar
->currentIndex());
1164 void DolphinMainWindow::closeTab(int index
)
1166 Q_ASSERT(index
>= 0);
1167 Q_ASSERT(index
< m_viewTab
.count());
1168 if (m_viewTab
.count() == 1) {
1169 // the last tab may never get closed
1173 if (index
== m_tabIndex
) {
1174 // The tab that should be closed is the active tab. Activate the
1175 // previous tab before closing the tab.
1176 m_tabBar
->setCurrentIndex((index
> 0) ? index
- 1 : 1);
1178 rememberClosedTab(index
);
1181 m_viewTab
[index
].primaryView
->deleteLater();
1182 if (m_viewTab
[index
].secondaryView
) {
1183 m_viewTab
[index
].secondaryView
->deleteLater();
1185 m_viewTab
[index
].splitter
->deleteLater();
1186 m_viewTab
.erase(m_viewTab
.begin() + index
);
1188 m_tabBar
->blockSignals(true);
1189 m_tabBar
->removeTab(index
);
1191 if (m_tabIndex
> index
) {
1193 Q_ASSERT(m_tabIndex
>= 0);
1196 // if only one tab is left, also remove the tab entry so that
1197 // closing the last tab is not possible
1198 if (m_viewTab
.count() == 1) {
1199 m_tabBar
->removeTab(0);
1200 actionCollection()->action("close_tab")->setEnabled(false);
1202 m_tabBar
->blockSignals(false);
1206 void DolphinMainWindow::openTabContextMenu(int index
, const QPoint
& pos
)
1210 QAction
* newTabAction
= menu
.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab"));
1211 newTabAction
->setShortcut(actionCollection()->action("new_tab")->shortcut());
1213 QAction
* detachTabAction
= menu
.addAction(KIcon("tab-detach"), i18nc("@action:inmenu", "Detach Tab"));
1215 QAction
* closeOtherTabsAction
= menu
.addAction(KIcon("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs"));
1217 QAction
* closeTabAction
= menu
.addAction(KIcon("tab-close"), i18nc("@action:inmenu", "Close Tab"));
1218 closeTabAction
->setShortcut(actionCollection()->action("close_tab")->shortcut());
1219 QAction
* selectedAction
= menu
.exec(pos
);
1220 if (selectedAction
== newTabAction
) {
1221 const ViewTab
& tab
= m_viewTab
[index
];
1222 Q_ASSERT(tab
.primaryView
);
1223 const KUrl url
= tab
.secondaryView
&& tab
.secondaryView
->isActive() ?
1224 tab
.secondaryView
->url() : tab
.primaryView
->url();
1226 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
1227 } else if (selectedAction
== detachTabAction
) {
1228 const QString
separator(QLatin1Char(' '));
1229 QString command
= QLatin1String("dolphin");
1231 const ViewTab
& tab
= m_viewTab
[index
];
1232 Q_ASSERT(tab
.primaryView
);
1234 command
+= separator
+ tab
.primaryView
->url().url();
1235 if (tab
.secondaryView
) {
1236 command
+= separator
+ tab
.secondaryView
->url().url();
1237 command
+= separator
+ QLatin1String("-split");
1240 KRun::runCommand(command
, this);
1243 } else if (selectedAction
== closeOtherTabsAction
) {
1244 const int count
= m_tabBar
->count();
1245 for (int i
= 0; i
< index
; ++i
) {
1248 for (int i
= index
+ 1; i
< count
; ++i
) {
1251 } else if (selectedAction
== closeTabAction
) {
1256 void DolphinMainWindow::slotTabMoved(int from
, int to
)
1258 m_viewTab
.move(from
, to
);
1259 m_tabIndex
= m_tabBar
->currentIndex();
1262 void DolphinMainWindow::handlePlacesClick(const KUrl
& url
, Qt::MouseButtons buttons
)
1264 if (buttons
& Qt::MidButton
) {
1266 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
1272 void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent
* event
, bool& canDecode
)
1274 canDecode
= KUrl::List::canDecode(event
->mimeData());
1277 void DolphinMainWindow::handleUrl(const KUrl
& url
)
1279 delete m_lastHandleUrlStatJob
;
1280 m_lastHandleUrlStatJob
= 0;
1282 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1283 activeViewContainer()->setUrl(url
);
1284 } else if (KProtocolManager::supportsListing(url
)) {
1285 // stat the URL to see if it is a dir or not
1286 m_lastHandleUrlStatJob
= KIO::stat(url
, KIO::HideProgressInfo
);
1287 connect(m_lastHandleUrlStatJob
, SIGNAL(result(KJob
*)),
1288 this, SLOT(slotHandleUrlStatFinished(KJob
*)));
1291 new KRun(url
, this);
1295 void DolphinMainWindow::slotHandleUrlStatFinished(KJob
* job
)
1297 m_lastHandleUrlStatJob
= 0;
1298 const KIO::UDSEntry entry
= static_cast<KIO::StatJob
*>(job
)->statResult();
1299 const KUrl url
= static_cast<KIO::StatJob
*>(job
)->url();
1300 if (entry
.isDir()) {
1301 activeViewContainer()->setUrl(url
);
1303 new KRun(url
, this);
1307 void DolphinMainWindow::tabDropEvent(int tab
, QDropEvent
* event
)
1309 const KUrl::List urls
= KUrl::List::fromMimeData(event
->mimeData());
1310 if (!urls
.isEmpty() && tab
!= -1) {
1311 const ViewTab
& viewTab
= m_viewTab
[tab
];
1312 const DolphinView
* view
= viewTab
.isPrimaryViewActive
? viewTab
.primaryView
->view()
1313 : viewTab
.secondaryView
->view();
1314 const QString error
= DragAndDropHelper::dropUrls(view
->rootItem(), view
->url(), event
);
1315 if (!error
.isEmpty()) {
1316 activeViewContainer()->showMessage(error
, DolphinViewContainer::Error
);
1321 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1323 newFileMenu()->setEnabled(isFolderWritable
);
1326 void DolphinMainWindow::slotSearchModeChanged(bool enabled
)
1329 const DolphinSearchInformation
& searchInfo
= DolphinSearchInformation::instance();
1330 if (!searchInfo
.isIndexingEnabled()) {
1334 QDockWidget
* searchDock
= findChild
<QDockWidget
*>("searchDock");
1340 if (!searchDock
->isVisible()) {
1341 m_searchDockIsTemporaryVisible
= true;
1345 if (searchDock
->isVisible() && m_searchDockIsTemporaryVisible
) {
1348 m_searchDockIsTemporaryVisible
= false;
1351 SearchPanel
* searchPanel
= qobject_cast
<SearchPanel
*>(searchDock
->widget());
1357 SearchPanel::SearchLocation searchLocation
= SearchPanel::Everywhere
;
1358 const KUrl url
= m_activeViewContainer
->url();
1359 const bool isSearchUrl
= (url
.protocol() == QLatin1String("nepomuksearch"));
1360 if ((SearchSettings::location() == QLatin1String("FromHere") && !isSearchUrl
)) {
1361 searchLocation
= SearchPanel::FromCurrentDir
;
1363 searchPanel
->setSearchLocation(searchLocation
);
1365 searchPanel
->setSearchLocation(SearchPanel::Everywhere
);
1372 void DolphinMainWindow::openContextMenu(const QPoint
& pos
,
1373 const KFileItem
& item
,
1375 const QList
<QAction
*>& customActions
)
1377 QWeakPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, pos
, item
, url
);
1378 contextMenu
.data()->setCustomActions(customActions
);
1379 const DolphinContextMenu::Command command
= contextMenu
.data()->open();
1382 case DolphinContextMenu::OpenParentFolderInNewWindow
: {
1383 KRun::run("dolphin", KUrl::List() << item
.url().upUrl(), this);
1387 case DolphinContextMenu::OpenParentFolderInNewTab
:
1388 openNewTab(item
.url().upUrl());
1391 case DolphinContextMenu::None
:
1396 delete contextMenu
.data();
1399 void DolphinMainWindow::updateControlMenu()
1401 KMenu
* menu
= qobject_cast
<KMenu
*>(sender());
1404 // All actions get cleared by KMenu::clear(). The sub-menus are deleted
1405 // by connecting to the aboutToHide() signal from the parent-menu.
1408 KActionCollection
* ac
= actionCollection();
1410 // Add "Edit" actions
1411 bool added
= addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Undo
)), menu
) |
1412 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Find
)), menu
) |
1413 addActionToMenu(ac
->action("select_all"), menu
) |
1414 addActionToMenu(ac
->action("invert_selection"), menu
);
1417 menu
->addSeparator();
1420 // Add "View" actions
1421 if (!GeneralSettings::showZoomSlider()) {
1422 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomIn
)), menu
);
1423 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomOut
)), menu
);
1424 menu
->addSeparator();
1427 added
= addActionToMenu(ac
->action("view_mode"), menu
) |
1428 addActionToMenu(ac
->action("sort"), menu
) |
1429 addActionToMenu(ac
->action("additional_info"), menu
) |
1430 addActionToMenu(ac
->action("show_preview"), menu
) |
1431 addActionToMenu(ac
->action("show_in_groups"), menu
) |
1432 addActionToMenu(ac
->action("show_hidden_files"), menu
);
1435 menu
->addSeparator();
1438 added
= addActionToMenu(ac
->action("split_view"), menu
) |
1439 addActionToMenu(ac
->action("reload"), menu
) |
1440 addActionToMenu(ac
->action("view_properties"), menu
);
1442 menu
->addSeparator();
1445 addActionToMenu(ac
->action("panels"), menu
);
1446 KMenu
* locationBarMenu
= new KMenu(i18nc("@action:inmenu", "Location Bar"), menu
);
1447 locationBarMenu
->addAction(ac
->action("editable_location"));
1448 locationBarMenu
->addAction(ac
->action("replace_location"));
1449 menu
->addMenu(locationBarMenu
);
1451 menu
->addSeparator();
1454 KMenu
* goMenu
= new KMenu(i18nc("@action:inmenu", "Go"), menu
);
1455 connect(menu
, SIGNAL(aboutToHide()), goMenu
, SLOT(deleteLater()));
1456 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Back
)));
1457 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Forward
)));
1458 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Up
)));
1459 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Home
)));
1460 goMenu
->addAction(ac
->action("closed_tabs"));
1461 menu
->addMenu(goMenu
);
1464 KMenu
* toolsMenu
= new KMenu(i18nc("@action:inmenu", "Tools"), menu
);
1465 connect(menu
, SIGNAL(aboutToHide()), toolsMenu
, SLOT(deleteLater()));
1466 toolsMenu
->addAction(ac
->action("show_filter_bar"));
1467 toolsMenu
->addAction(ac
->action("compare_files"));
1468 toolsMenu
->addAction(ac
->action("open_terminal"));
1469 toolsMenu
->addAction(ac
->action("change_remote_encoding"));
1470 menu
->addMenu(toolsMenu
);
1472 // Add "Settings" menu entries
1473 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::KeyBindings
)), menu
);
1474 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ConfigureToolbars
)), menu
);
1475 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Preferences
)), menu
);
1478 KMenu
* helpMenu
= new KMenu(i18nc("@action:inmenu", "Help"), menu
);
1479 connect(menu
, SIGNAL(aboutToHide()), helpMenu
, SLOT(deleteLater()));
1480 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::HelpContents
)));
1481 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::WhatsThis
)));
1482 helpMenu
->addSeparator();
1483 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ReportBug
)));
1484 helpMenu
->addSeparator();
1485 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
)));
1486 helpMenu
->addSeparator();
1487 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::AboutApp
)));
1488 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::AboutKDE
)));
1489 menu
->addMenu(helpMenu
);
1491 menu
->addSeparator();
1492 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ShowMenubar
)), menu
);
1495 void DolphinMainWindow::updateToolBar()
1497 if (!menuBar()->isVisible()) {
1498 createControlButton();
1502 void DolphinMainWindow::slotControlButtonDeleted()
1504 m_controlButton
= 0;
1505 m_updateToolBarTimer
->start();
1508 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer
* viewContainer
)
1510 Q_ASSERT(viewContainer
);
1511 Q_ASSERT((viewContainer
== m_viewTab
[m_tabIndex
].primaryView
) ||
1512 (viewContainer
== m_viewTab
[m_tabIndex
].secondaryView
));
1513 if (m_activeViewContainer
== viewContainer
) {
1517 m_activeViewContainer
->setActive(false);
1518 m_activeViewContainer
= viewContainer
;
1520 // Activating the view container might trigger a recursive setActiveViewContainer() call
1521 // inside DolphinMainWindow::toggleActiveView() when having a split view. Temporary
1522 // disconnect the activated() signal in this case:
1523 disconnect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1524 m_activeViewContainer
->setActive(true);
1525 connect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1527 m_actionHandler
->setCurrentView(viewContainer
->view());
1530 updateEditActions();
1531 updateViewActions();
1534 const KUrl url
= m_activeViewContainer
->url();
1535 setUrlAsCaption(url
);
1536 if (m_viewTab
.count() > 1) {
1537 m_tabBar
->setTabText(m_tabIndex
, tabName(url
));
1538 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(KMimeType::iconNameForUrl(url
)));
1541 emit
urlChanged(url
);
1544 DolphinViewContainer
* DolphinMainWindow::createViewContainer(const KUrl
& url
, QWidget
* parent
)
1546 DolphinViewContainer
* container
= new DolphinViewContainer(url
, parent
);
1548 // The places-selector from the URL navigator should only be shown
1549 // if the places dock is invisible
1550 QDockWidget
* placesDock
= findChild
<QDockWidget
*>("placesDock");
1551 container
->urlNavigator()->setPlacesSelectorVisible(!placesDock
|| !placesDock
->isVisible());
1556 void DolphinMainWindow::setupActions()
1558 // setup 'File' menu
1559 m_newFileMenu
= new DolphinNewFileMenu(this);
1560 KMenu
* menu
= m_newFileMenu
->menu();
1561 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1562 menu
->setIcon(KIcon("document-new"));
1563 connect(menu
, SIGNAL(aboutToShow()),
1564 this, SLOT(updateNewMenu()));
1566 KAction
* newWindow
= actionCollection()->addAction("new_window");
1567 newWindow
->setIcon(KIcon("window-new"));
1568 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1569 newWindow
->setShortcut(Qt::CTRL
| Qt::Key_N
);
1570 connect(newWindow
, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1572 KAction
* newTab
= actionCollection()->addAction("new_tab");
1573 newTab
->setIcon(KIcon("tab-new"));
1574 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1575 newTab
->setShortcut(KShortcut(Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
));
1576 connect(newTab
, SIGNAL(triggered()), this, SLOT(openNewTab()));
1578 KAction
* closeTab
= actionCollection()->addAction("close_tab");
1579 closeTab
->setIcon(KIcon("tab-close"));
1580 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1581 closeTab
->setShortcut(Qt::CTRL
| Qt::Key_W
);
1582 closeTab
->setEnabled(false);
1583 connect(closeTab
, SIGNAL(triggered()), this, SLOT(closeTab()));
1585 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1587 // setup 'Edit' menu
1588 KStandardAction::undo(this,
1590 actionCollection());
1592 // need to remove shift+del from cut action, else the shortcut for deletejob
1594 KAction
* cut
= KStandardAction::cut(this, SLOT(cut()), actionCollection());
1595 KShortcut cutShortcut
= cut
->shortcut();
1596 cutShortcut
.remove(Qt::SHIFT
| Qt::Key_Delete
, KShortcut::KeepEmpty
);
1597 cut
->setShortcut(cutShortcut
);
1598 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1599 KAction
* paste
= KStandardAction::paste(this, SLOT(paste()), actionCollection());
1600 // The text of the paste-action is modified dynamically by Dolphin
1601 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1602 // due to the long text, the text "Paste" is used:
1603 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1605 KStandardAction::find(this, SLOT(find()), actionCollection());
1607 KAction
* selectAll
= actionCollection()->addAction("select_all");
1608 selectAll
->setText(i18nc("@action:inmenu Edit", "Select All"));
1609 selectAll
->setShortcut(Qt::CTRL
| Qt::Key_A
);
1610 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
1612 KAction
* invertSelection
= actionCollection()->addAction("invert_selection");
1613 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1614 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1615 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
1617 // setup 'View' menu
1618 // (note that most of it is set up in DolphinViewActionHandler)
1620 KAction
* split
= actionCollection()->addAction("split_view");
1621 split
->setShortcut(Qt::Key_F3
);
1622 updateSplitAction();
1623 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1625 KAction
* reload
= actionCollection()->addAction("reload");
1626 reload
->setText(i18nc("@action:inmenu View", "Reload"));
1627 reload
->setShortcut(Qt::Key_F5
);
1628 reload
->setIcon(KIcon("view-refresh"));
1629 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
1631 KAction
* stop
= actionCollection()->addAction("stop");
1632 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1633 stop
->setToolTip(i18nc("@info", "Stop loading"));
1634 stop
->setIcon(KIcon("process-stop"));
1635 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
1637 KToggleAction
* editableLocation
= actionCollection()->add
<KToggleAction
>("editable_location");
1638 editableLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1639 editableLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
1640 connect(editableLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1642 KAction
* replaceLocation
= actionCollection()->addAction("replace_location");
1643 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1644 replaceLocation
->setShortcut(Qt::Key_F6
);
1645 connect(replaceLocation
, SIGNAL(triggered()), this, SLOT(replaceLocation()));
1648 KAction
* backAction
= KStandardAction::back(this, SLOT(goBack()), actionCollection());
1649 connect(backAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goBack(Qt::MouseButtons
)));
1650 KShortcut backShortcut
= backAction
->shortcut();
1651 backShortcut
.setAlternate(Qt::Key_Backspace
);
1652 backAction
->setShortcut(backShortcut
);
1654 m_recentTabsMenu
= new KActionMenu(i18n("Recently Closed Tabs"), this);
1655 m_recentTabsMenu
->setIcon(KIcon("edit-undo"));
1656 actionCollection()->addAction("closed_tabs", m_recentTabsMenu
);
1657 connect(m_recentTabsMenu
->menu(), SIGNAL(triggered(QAction
*)),
1658 this, SLOT(restoreClosedTab(QAction
*)));
1660 QAction
* action
= new QAction(i18n("Empty Recently Closed Tabs"), m_recentTabsMenu
);
1661 action
->setIcon(KIcon("edit-clear-list"));
1662 action
->setData(QVariant::fromValue(true));
1663 m_recentTabsMenu
->addAction(action
);
1664 m_recentTabsMenu
->addSeparator();
1665 m_recentTabsMenu
->setEnabled(false);
1667 KAction
* forwardAction
= KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1668 connect(forwardAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goForward(Qt::MouseButtons
)));
1670 KAction
* upAction
= KStandardAction::up(this, SLOT(goUp()), actionCollection());
1671 connect(upAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goUp(Qt::MouseButtons
)));
1673 KAction
* homeAction
= KStandardAction::home(this, SLOT(goHome()), actionCollection());
1674 connect(homeAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goHome(Qt::MouseButtons
)));
1676 // setup 'Tools' menu
1677 KAction
* showFilterBar
= actionCollection()->addAction("show_filter_bar");
1678 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1679 showFilterBar
->setIcon(KIcon("view-filter"));
1680 showFilterBar
->setShortcut(Qt::CTRL
| Qt::Key_I
);
1681 connect(showFilterBar
, SIGNAL(triggered()), this, SLOT(showFilterBar()));
1683 KAction
* compareFiles
= actionCollection()->addAction("compare_files");
1684 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1685 compareFiles
->setIcon(KIcon("kompare"));
1686 compareFiles
->setEnabled(false);
1687 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
1689 KAction
* openTerminal
= actionCollection()->addAction("open_terminal");
1690 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1691 openTerminal
->setIcon(KIcon("utilities-terminal"));
1692 openTerminal
->setShortcut(Qt::SHIFT
| Qt::Key_F4
);
1693 connect(openTerminal
, SIGNAL(triggered()), this, SLOT(openTerminal()));
1695 // setup 'Settings' menu
1696 KToggleAction
* showMenuBar
= KStandardAction::showMenubar(0, 0, actionCollection());
1697 connect(showMenuBar
, SIGNAL(triggered(bool)), // Fixes #286822
1698 this, SLOT(toggleShowMenuBar()), Qt::QueuedConnection
);
1699 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1701 // not in menu actions
1702 QList
<QKeySequence
> nextTabKeys
;
1703 nextTabKeys
.append(KStandardShortcut::tabNext().primary());
1704 nextTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::Key_Tab
));
1706 QList
<QKeySequence
> prevTabKeys
;
1707 prevTabKeys
.append(KStandardShortcut::tabPrev().primary());
1708 prevTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::SHIFT
| Qt::Key_Tab
));
1710 KAction
* activateNextTab
= actionCollection()->addAction("activate_next_tab");
1711 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1712 connect(activateNextTab
, SIGNAL(triggered()), SLOT(activateNextTab()));
1713 activateNextTab
->setShortcuts(QApplication::isRightToLeft() ? prevTabKeys
: nextTabKeys
);
1715 KAction
* activatePrevTab
= actionCollection()->addAction("activate_prev_tab");
1716 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1717 connect(activatePrevTab
, SIGNAL(triggered()), SLOT(activatePrevTab()));
1718 activatePrevTab
->setShortcuts(QApplication::isRightToLeft() ? nextTabKeys
: prevTabKeys
);
1721 KAction
* openInNewTab
= actionCollection()->addAction("open_in_new_tab");
1722 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1723 openInNewTab
->setIcon(KIcon("tab-new"));
1724 connect(openInNewTab
, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1726 KAction
* openInNewWindow
= actionCollection()->addAction("open_in_new_window");
1727 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1728 openInNewWindow
->setIcon(KIcon("window-new"));
1729 connect(openInNewWindow
, SIGNAL(triggered()), this, SLOT(openInNewWindow()));
1732 void DolphinMainWindow::setupDockWidgets()
1734 const bool lock
= GeneralSettings::lockPanels();
1736 KDualAction
* lockLayoutAction
= actionCollection()->add
<KDualAction
>("lock_panels");
1737 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
1738 lockLayoutAction
->setActiveIcon(KIcon("object-unlocked"));
1739 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
1740 lockLayoutAction
->setInactiveIcon(KIcon("object-locked"));
1741 lockLayoutAction
->setActive(lock
);
1742 connect(lockLayoutAction
, SIGNAL(triggered()), this, SLOT(togglePanelLockState()));
1744 // Setup "Information"
1745 DolphinDockWidget
* infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
1746 infoDock
->setLocked(lock
);
1747 infoDock
->setObjectName("infoDock");
1748 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1749 Panel
* infoPanel
= new InformationPanel(infoDock
);
1750 infoPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1751 connect(infoPanel
, SIGNAL(urlActivated(KUrl
)), this, SLOT(handleUrl(KUrl
)));
1752 infoDock
->setWidget(infoPanel
);
1754 QAction
* infoAction
= infoDock
->toggleViewAction();
1755 createPanelAction(KIcon("dialog-information"), Qt::Key_F11
, infoAction
, "show_information_panel");
1757 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1758 connect(this, SIGNAL(urlChanged(KUrl
)),
1759 infoPanel
, SLOT(setUrl(KUrl
)));
1760 connect(this, SIGNAL(selectionChanged(KFileItemList
)),
1761 infoPanel
, SLOT(setSelection(KFileItemList
)));
1762 connect(this, SIGNAL(requestItemInfo(KFileItem
)),
1763 infoPanel
, SLOT(requestDelayedItemInfo(KFileItem
)));
1766 DolphinDockWidget
* foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
1767 foldersDock
->setLocked(lock
);
1768 foldersDock
->setObjectName("foldersDock");
1769 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1770 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1771 foldersPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1772 foldersDock
->setWidget(foldersPanel
);
1774 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1775 createPanelAction(KIcon("folder"), Qt::Key_F7
, foldersAction
, "show_folders_panel");
1777 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1778 connect(this, SIGNAL(urlChanged(KUrl
)),
1779 foldersPanel
, SLOT(setUrl(KUrl
)));
1780 connect(foldersPanel
, SIGNAL(changeUrl(KUrl
,Qt::MouseButtons
)),
1781 this, SLOT(handlePlacesClick(KUrl
,Qt::MouseButtons
)));
1785 DolphinDockWidget
* terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1786 terminalDock
->setLocked(lock
);
1787 terminalDock
->setObjectName("terminalDock");
1788 terminalDock
->setAllowedAreas(Qt::TopDockWidgetArea
| Qt::BottomDockWidgetArea
);
1789 Panel
* terminalPanel
= new TerminalPanel(terminalDock
);
1790 terminalPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1791 terminalDock
->setWidget(terminalPanel
);
1793 connect(terminalPanel
, SIGNAL(hideTerminalPanel()), terminalDock
, SLOT(hide()));
1794 connect(terminalDock
, SIGNAL(visibilityChanged(bool)),
1795 terminalPanel
, SLOT(dockVisibilityChanged()));
1797 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1798 createPanelAction(KIcon("utilities-terminal"), Qt::Key_F4
, terminalAction
, "show_terminal_panel");
1800 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1801 connect(this, SIGNAL(urlChanged(KUrl
)),
1802 terminalPanel
, SLOT(setUrl(KUrl
)));
1807 DolphinDockWidget
* searchDock
= new DolphinDockWidget(i18nc("@title:window", "Search"));
1808 searchDock
->setLocked(lock
);
1809 searchDock
->setObjectName("searchDock");
1810 searchDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1811 Panel
* searchPanel
= new SearchPanel(searchDock
);
1812 searchPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1813 connect(searchPanel
, SIGNAL(urlActivated(KUrl
)), this, SLOT(handleUrl(KUrl
)));
1814 searchDock
->setWidget(searchPanel
);
1816 QAction
* searchAction
= searchDock
->toggleViewAction();
1817 createPanelAction(KIcon("system-search"), Qt::Key_F12
, searchAction
, "show_search_panel");
1818 addDockWidget(Qt::RightDockWidgetArea
, searchDock
);
1819 connect(this, SIGNAL(urlChanged(KUrl
)),
1820 searchPanel
, SLOT(setUrl(KUrl
)));
1823 if (GeneralSettings::version() < 200) {
1825 foldersDock
->hide();
1827 terminalDock
->hide();
1835 DolphinDockWidget
* placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
1836 placesDock
->setLocked(lock
);
1837 placesDock
->setObjectName("placesDock");
1838 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1840 PlacesPanel
* placesPanel
= new PlacesPanel(placesDock
);
1841 QAction
* separator
= new QAction(placesPanel
);
1842 separator
->setSeparator(true);
1843 QList
<QAction
*> placesActions
;
1844 placesActions
.append(separator
);
1845 placesActions
.append(lockLayoutAction
);
1846 placesPanel
->addActions(placesActions
);
1847 placesPanel
->setModel(DolphinPlacesModel::instance());
1848 placesPanel
->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff
);
1849 placesDock
->setWidget(placesPanel
);
1851 QAction
* placesAction
= placesDock
->toggleViewAction();
1852 createPanelAction(KIcon("bookmarks"), Qt::Key_F9
, placesAction
, "show_places_panel");
1854 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1855 connect(placesPanel
, SIGNAL(urlChanged(KUrl
,Qt::MouseButtons
)),
1856 this, SLOT(handlePlacesClick(KUrl
,Qt::MouseButtons
)));
1857 connect(this, SIGNAL(urlChanged(KUrl
)),
1858 placesPanel
, SLOT(setUrl(KUrl
)));
1859 connect(placesDock
, SIGNAL(visibilityChanged(bool)),
1860 this, SLOT(slotPlacesPanelVisibilityChanged(bool)));
1862 // Add actions into the "Panels" menu
1863 KActionMenu
* panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Panels"), this);
1864 actionCollection()->addAction("panels", panelsMenu
);
1865 panelsMenu
->setDelayed(false);
1866 const KActionCollection
* ac
= actionCollection();
1867 panelsMenu
->addAction(ac
->action("show_places_panel"));
1868 panelsMenu
->addAction(ac
->action("show_information_panel"));
1869 panelsMenu
->addAction(ac
->action("show_folders_panel"));
1871 panelsMenu
->addAction(ac
->action("show_terminal_panel"));
1874 panelsMenu
->addAction(ac
->action("show_search_panel"));
1876 panelsMenu
->addSeparator();
1877 panelsMenu
->addAction(lockLayoutAction
);
1880 void DolphinMainWindow::updateEditActions()
1882 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1883 if (list
.isEmpty()) {
1884 stateChanged("has_no_selection");
1886 stateChanged("has_selection");
1888 KActionCollection
* col
= actionCollection();
1889 QAction
* renameAction
= col
->action("rename");
1890 QAction
* moveToTrashAction
= col
->action("move_to_trash");
1891 QAction
* deleteAction
= col
->action("delete");
1892 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
1893 QAction
* deleteWithTrashShortcut
= col
->action("delete_shortcut"); // see DolphinViewActionHandler
1895 KFileItemListProperties
capabilities(list
);
1896 const bool enableMoveToTrash
= capabilities
.isLocal() && capabilities
.supportsMoving();
1898 renameAction
->setEnabled(capabilities
.supportsMoving());
1899 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1900 deleteAction
->setEnabled(capabilities
.supportsDeleting());
1901 deleteWithTrashShortcut
->setEnabled(capabilities
.supportsDeleting() && !enableMoveToTrash
);
1902 cutAction
->setEnabled(capabilities
.supportsMoving());
1904 updatePasteAction();
1907 void DolphinMainWindow::updateViewActions()
1909 m_actionHandler
->updateViewActions();
1911 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1912 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
1914 updateSplitAction();
1916 QAction
* editableLocactionAction
= actionCollection()->action("editable_location");
1917 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
1918 editableLocactionAction
->setChecked(urlNavigator
->isUrlEditable());
1921 void DolphinMainWindow::updateGoActions()
1923 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
1924 const KUrl currentUrl
= m_activeViewContainer
->url();
1925 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
1928 void DolphinMainWindow::createControlButton()
1930 if (m_controlButton
) {
1933 Q_ASSERT(!m_controlButton
);
1935 m_controlButton
= new QToolButton(this);
1936 m_controlButton
->setIcon(KIcon("applications-system"));
1937 m_controlButton
->setText(i18nc("@action", "Control"));
1938 m_controlButton
->setPopupMode(QToolButton::InstantPopup
);
1939 m_controlButton
->setToolButtonStyle(toolBar()->toolButtonStyle());
1941 KMenu
* controlMenu
= new KMenu(m_controlButton
);
1942 connect(controlMenu
, SIGNAL(aboutToShow()), this, SLOT(updateControlMenu()));
1944 m_controlButton
->setMenu(controlMenu
);
1946 toolBar()->addWidget(m_controlButton
);
1947 connect(toolBar(), SIGNAL(iconSizeChanged(QSize
)),
1948 m_controlButton
, SLOT(setIconSize(QSize
)));
1949 connect(toolBar(), SIGNAL(toolButtonStyleChanged(Qt::ToolButtonStyle
)),
1950 m_controlButton
, SLOT(setToolButtonStyle(Qt::ToolButtonStyle
)));
1952 // The added widgets are owned by the toolbar and may get deleted when e.g. the toolbar
1953 // gets edited. In this case we must add them again. The adding is done asynchronously by
1954 // m_updateToolBarTimer.
1955 connect(m_controlButton
, SIGNAL(destroyed()), this, SLOT(slotControlButtonDeleted()));
1956 m_updateToolBarTimer
= new QTimer(this);
1957 m_updateToolBarTimer
->setInterval(500);
1958 connect(m_updateToolBarTimer
, SIGNAL(timeout()), this, SLOT(updateToolBar()));
1961 void DolphinMainWindow::deleteControlButton()
1963 delete m_controlButton
;
1964 m_controlButton
= 0;
1966 delete m_updateToolBarTimer
;
1967 m_updateToolBarTimer
= 0;
1970 bool DolphinMainWindow::addActionToMenu(QAction
* action
, KMenu
* menu
)
1975 const KToolBar
* toolBarWidget
= toolBar();
1976 foreach (const QWidget
* widget
, action
->associatedWidgets()) {
1977 if (widget
== toolBarWidget
) {
1982 menu
->addAction(action
);
1986 void DolphinMainWindow::rememberClosedTab(int index
)
1988 KMenu
* tabsMenu
= m_recentTabsMenu
->menu();
1990 const QString primaryPath
= m_viewTab
[index
].primaryView
->url().path();
1991 const QString iconName
= KMimeType::iconNameForUrl(primaryPath
);
1993 QAction
* action
= new QAction(squeezedText(primaryPath
), tabsMenu
);
1995 ClosedTab closedTab
;
1996 closedTab
.primaryUrl
= m_viewTab
[index
].primaryView
->url();
1998 if (m_viewTab
[index
].secondaryView
) {
1999 closedTab
.secondaryUrl
= m_viewTab
[index
].secondaryView
->url();
2000 closedTab
.isSplit
= true;
2002 closedTab
.isSplit
= false;
2005 action
->setData(QVariant::fromValue(closedTab
));
2006 action
->setIcon(KIcon(iconName
));
2008 // add the closed tab menu entry after the separator and
2009 // "Empty Recently Closed Tabs" entry
2010 if (tabsMenu
->actions().size() == 2) {
2011 tabsMenu
->addAction(action
);
2013 tabsMenu
->insertAction(tabsMenu
->actions().at(2), action
);
2016 // assure that only up to 8 closed tabs are shown in the menu
2017 if (tabsMenu
->actions().size() > 8) {
2018 tabsMenu
->removeAction(tabsMenu
->actions().last());
2020 actionCollection()->action("closed_tabs")->setEnabled(true);
2021 KAcceleratorManager::manage(tabsMenu
);
2024 void DolphinMainWindow::refreshViews()
2026 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
2028 // remember the current active view, as because of
2029 // the refreshing the active view might change to
2030 // the secondary view
2031 DolphinViewContainer
* activeViewContainer
= m_activeViewContainer
;
2033 const int tabCount
= m_viewTab
.count();
2034 for (int i
= 0; i
< tabCount
; ++i
) {
2035 m_viewTab
[i
].primaryView
->readSettings();
2036 if (m_viewTab
[i
].secondaryView
) {
2037 m_viewTab
[i
].secondaryView
->readSettings();
2041 setActiveViewContainer(activeViewContainer
);
2043 if (GeneralSettings::modifiedStartupSettings()) {
2044 // The startup settings have been changed by the user (see bug #254947).
2045 // Synchronize the split-view setting with the active view:
2046 const bool splitView
= GeneralSettings::splitView();
2047 const ViewTab
& activeTab
= m_viewTab
[m_tabIndex
];
2048 const bool toggle
= ( splitView
&& !activeTab
.secondaryView
)
2049 || (!splitView
&& activeTab
.secondaryView
);
2056 void DolphinMainWindow::clearStatusBar()
2058 m_activeViewContainer
->statusBar()->resetToDefaultText();
2061 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
2063 connect(container
, SIGNAL(showFilterBarChanged(bool)),
2064 this, SLOT(updateFilterBarAction(bool)));
2065 connect(container
, SIGNAL(writeStateChanged(bool)),
2066 this, SLOT(slotWriteStateChanged(bool)));
2067 connect(container
, SIGNAL(searchModeChanged(bool)),
2068 this, SLOT(slotSearchModeChanged(bool)));
2070 const DolphinSearchBox
* searchBox
= container
->searchBox();
2071 connect(searchBox
, SIGNAL(searchLocationChanged(SearchLocation
)),
2072 this, SLOT(slotSearchLocationChanged()));
2074 DolphinView
* view
= container
->view();
2075 connect(view
, SIGNAL(selectionChanged(KFileItemList
)),
2076 this, SLOT(slotSelectionChanged(KFileItemList
)));
2077 connect(view
, SIGNAL(requestItemInfo(KFileItem
)),
2078 this, SLOT(slotRequestItemInfo(KFileItem
)));
2079 connect(view
, SIGNAL(activated()),
2080 this, SLOT(toggleActiveView()));
2081 connect(view
, SIGNAL(tabRequested(KUrl
)),
2082 this, SLOT(openNewTab(KUrl
)));
2083 connect(view
, SIGNAL(requestContextMenu(QPoint
,KFileItem
,KUrl
,QList
<QAction
*>)),
2084 this, SLOT(openContextMenu(QPoint
,KFileItem
,KUrl
,QList
<QAction
*>)));
2085 connect(view
, SIGNAL(directoryLoadingStarted()),
2086 this, SLOT(enableStopAction()));
2087 connect(view
, SIGNAL(directoryLoadingCompleted()),
2088 this, SLOT(disableStopAction()));
2089 connect(view
, SIGNAL(goBackRequested()),
2090 this, SLOT(goBack()));
2091 connect(view
, SIGNAL(goForwardRequested()),
2092 this, SLOT(goForward()));
2094 const KUrlNavigator
* navigator
= container
->urlNavigator();
2095 connect(navigator
, SIGNAL(urlChanged(KUrl
)),
2096 this, SLOT(changeUrl(KUrl
)));
2097 connect(navigator
, SIGNAL(historyChanged()),
2098 this, SLOT(updateHistory()));
2099 connect(navigator
, SIGNAL(editableStateChanged(bool)),
2100 this, SLOT(slotEditableStateChanged(bool)));
2101 connect(navigator
, SIGNAL(tabRequested(KUrl
)),
2102 this, SLOT(openNewTab(KUrl
)));
2105 void DolphinMainWindow::updateSplitAction()
2107 QAction
* splitAction
= actionCollection()->action("split_view");
2108 if (m_viewTab
[m_tabIndex
].secondaryView
) {
2109 if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
2110 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
2111 splitAction
->setToolTip(i18nc("@info", "Close right view"));
2112 splitAction
->setIcon(KIcon("view-right-close"));
2114 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
2115 splitAction
->setToolTip(i18nc("@info", "Close left view"));
2116 splitAction
->setIcon(KIcon("view-left-close"));
2119 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
2120 splitAction
->setToolTip(i18nc("@info", "Split view"));
2121 splitAction
->setIcon(KIcon("view-right-new"));
2125 QString
DolphinMainWindow::tabName(const KUrl
& url
) const
2128 if (url
.equals(KUrl("file:///"))) {
2131 name
= url
.fileName();
2132 if (name
.isEmpty()) {
2133 name
= url
.protocol();
2135 // Make sure that a '&' inside the directory name is displayed correctly
2136 // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
2137 name
.replace('&', "&&");
2143 bool DolphinMainWindow::isKompareInstalled() const
2145 static bool initialized
= false;
2146 static bool installed
= false;
2148 // TODO: maybe replace this approach later by using a menu
2149 // plugin like kdiff3plugin.cpp
2150 installed
= !KGlobal::dirs()->findExe("kompare").isEmpty();
2156 void DolphinMainWindow::createSecondaryView(int tabIndex
)
2158 ViewTab
& viewTab
= m_viewTab
[tabIndex
];
2160 QSplitter
* splitter
= viewTab
.splitter
;
2161 const int newWidth
= (viewTab
.primaryView
->width() - splitter
->handleWidth()) / 2;
2163 const DolphinView
* view
= viewTab
.primaryView
->view();
2164 viewTab
.secondaryView
= createViewContainer(view
->url(), 0);
2165 splitter
->addWidget(viewTab
.secondaryView
);
2166 splitter
->setSizes(QList
<int>() << newWidth
<< newWidth
);
2168 connectViewSignals(viewTab
.secondaryView
);
2169 viewTab
.secondaryView
->setActive(false);
2170 viewTab
.secondaryView
->resize(newWidth
, viewTab
.primaryView
->height());
2171 viewTab
.secondaryView
->show();
2174 QString
DolphinMainWindow::tabProperty(const QString
& property
, int tabIndex
) const
2176 return "Tab " + QString::number(tabIndex
) + ' ' + property
;
2179 void DolphinMainWindow::setUrlAsCaption(const KUrl
& url
)
2182 if (!url
.isLocalFile()) {
2183 caption
.append(url
.protocol() + " - ");
2184 if (url
.hasHost()) {
2185 caption
.append(url
.host() + " - ");
2189 const QString fileName
= url
.fileName().isEmpty() ? "/" : url
.fileName();
2190 caption
.append(fileName
);
2192 setCaption(caption
);
2195 QString
DolphinMainWindow::squeezedText(const QString
& text
) const
2197 const QFontMetrics fm
= fontMetrics();
2198 return fm
.elidedText(text
, Qt::ElideMiddle
, fm
.maxWidth() * 10);
2201 void DolphinMainWindow::createPanelAction(const KIcon
& icon
,
2202 const QKeySequence
& shortcut
,
2203 QAction
* dockAction
,
2204 const QString
& actionName
)
2206 KAction
* panelAction
= actionCollection()->addAction(actionName
);
2207 panelAction
->setCheckable(true);
2208 panelAction
->setChecked(dockAction
->isChecked());
2209 panelAction
->setText(dockAction
->text());
2210 panelAction
->setIcon(icon
);
2211 panelAction
->setShortcut(shortcut
);
2213 connect(panelAction
, SIGNAL(triggered()), dockAction
, SLOT(trigger()));
2214 connect(dockAction
, SIGNAL(toggled(bool)), panelAction
, SLOT(setChecked(bool)));
2217 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
2218 KIO::FileUndoManager::UiInterface()
2222 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2226 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
2228 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
2230 DolphinViewContainer
* container
= mainWin
->activeViewContainer();
2231 container
->showMessage(job
->errorString(), DolphinViewContainer::Error
);
2233 KIO::FileUndoManager::UiInterface::jobError(job
);
2237 #include "dolphinmainwindow.moc"