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/dolphinsettings.h"
41 #include "settings/dolphinsettingsdialog.h"
42 #include "statusbar/dolphinstatusbar.h"
43 #include "views/dolphinviewactionhandler.h"
44 #include "views/dolphinremoteencoding.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 <QDesktopWidget>
92 #include <QDBusMessage>
95 #include <QToolButton>
99 // Used for GeneralSettings::version() to determine whether
100 // an updated version of Dolphin is running.
101 const int CurrentDolphinVersion
= 200;
105 * Menu shown when pressing the configure-button in the toolbar.
107 class ToolBarMenu
: public KMenu
110 ToolBarMenu(QWidget
* parent
);
111 virtual ~ToolBarMenu();
113 virtual void showEvent(QShowEvent
* event
);
117 * Remembers the tab configuration if a tab has been closed.
118 * Each closed tab can be restored by the menu
119 * "Go -> Recently Closed Tabs".
127 Q_DECLARE_METATYPE(ClosedTab
)
129 DolphinMainWindow::DolphinMainWindow() :
133 m_activeViewContainer(0),
134 m_centralWidgetLayout(0),
141 m_openToolBarMenuButton(0),
142 m_updateToolBarTimer(0),
143 m_lastHandleUrlStatJob(0),
144 m_searchDockIsTemporaryVisible(false)
146 // Workaround for a X11-issue in combination with KModifierInfo
147 // (see DolphinContextMenu::initializeModifierKeyInfo() for
148 // more information):
149 DolphinContextMenu::initializeModifierKeyInfo();
151 setObjectName("Dolphin#");
153 m_viewTab
.append(ViewTab());
155 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
156 undoManager
->setUiInterface(new UndoUiInterface());
158 connect(undoManager
, SIGNAL(undoAvailable(bool)),
159 this, SLOT(slotUndoAvailable(bool)));
160 connect(undoManager
, SIGNAL(undoTextChanged(QString
)),
161 this, SLOT(slotUndoTextChanged(QString
)));
162 connect(undoManager
, SIGNAL(jobRecordingStarted(CommandType
)),
163 this, SLOT(clearStatusBar()));
164 connect(undoManager
, SIGNAL(jobRecordingFinished(CommandType
)),
165 this, SLOT(showCommand(CommandType
)));
166 connect(DolphinSettings::instance().placesModel(), SIGNAL(errorMessage(QString
)),
167 this, SLOT(showErrorMessage(QString
)));
169 GeneralSettings
* generalSettings
= GeneralSettings::self();
170 const bool firstRun
= (generalSettings
->version() < 200);
172 generalSettings
->setViewPropsTimestamp(QDateTime::currentDateTime());
175 setAcceptDrops(true);
177 m_viewTab
[m_tabIndex
].splitter
= new QSplitter(this);
178 m_viewTab
[m_tabIndex
].splitter
->setChildrenCollapsible(false);
182 const KUrl
homeUrl(generalSettings
->homeUrl());
183 setUrlAsCaption(homeUrl
);
184 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
185 connect(m_actionHandler
, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
186 connect(m_actionHandler
, SIGNAL(createDirectory()), SLOT(createDirectory()));
188 m_viewTab
[m_tabIndex
].primaryView
= createViewContainer(homeUrl
, m_viewTab
[m_tabIndex
].splitter
);
190 m_activeViewContainer
= m_viewTab
[m_tabIndex
].primaryView
;
191 connectViewSignals(m_activeViewContainer
);
192 DolphinView
* view
= m_activeViewContainer
->view();
193 m_activeViewContainer
->show();
194 m_actionHandler
->setCurrentView(view
);
196 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
197 connect(this, SIGNAL(urlChanged(KUrl
)),
198 m_remoteEncoding
, SLOT(slotAboutToOpenUrl()));
200 m_tabBar
= new KTabBar(this);
201 m_tabBar
->setMovable(true);
202 m_tabBar
->setTabsClosable(true);
203 connect(m_tabBar
, SIGNAL(currentChanged(int)),
204 this, SLOT(setActiveTab(int)));
205 connect(m_tabBar
, SIGNAL(tabCloseRequested(int)),
206 this, SLOT(closeTab(int)));
207 connect(m_tabBar
, SIGNAL(contextMenu(int,QPoint
)),
208 this, SLOT(openTabContextMenu(int,QPoint
)));
209 connect(m_tabBar
, SIGNAL(newTabRequest()),
210 this, SLOT(openNewTab()));
211 connect(m_tabBar
, SIGNAL(testCanDecode(const QDragMoveEvent
*,bool&)),
212 this, SLOT(slotTestCanDecode(const QDragMoveEvent
*,bool&)));
213 connect(m_tabBar
, SIGNAL(mouseMiddleClick(int)),
214 this, SLOT(closeTab(int)));
215 connect(m_tabBar
, SIGNAL(tabMoved(int,int)),
216 this, SLOT(slotTabMoved(int,int)));
217 connect(m_tabBar
, SIGNAL(receivedDropEvent(int,QDropEvent
*)),
218 this, SLOT(tabDropEvent(int,QDropEvent
*)));
220 m_tabBar
->blockSignals(true); // signals get unblocked after at least 2 tabs are open
222 QWidget
* centralWidget
= new QWidget(this);
223 m_centralWidgetLayout
= new QVBoxLayout(centralWidget
);
224 m_centralWidgetLayout
->setSpacing(0);
225 m_centralWidgetLayout
->setMargin(0);
226 m_centralWidgetLayout
->addWidget(m_tabBar
);
227 m_centralWidgetLayout
->addWidget(m_viewTab
[m_tabIndex
].splitter
, 1);
229 setCentralWidget(centralWidget
);
231 emit
urlChanged(homeUrl
);
233 setupGUI(Keys
| Save
| Create
| ToolBar
);
234 stateChanged("new_file");
236 QClipboard
* clipboard
= QApplication::clipboard();
237 connect(clipboard
, SIGNAL(dataChanged()),
238 this, SLOT(updatePasteAction()));
240 if (generalSettings
->splitView()) {
247 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
248 showFilterBarAction
->setChecked(generalSettings
->filterBar());
251 menuBar()->setVisible(false);
252 // Assure a proper default size if Dolphin runs the first time
256 const bool showMenu
= !menuBar()->isHidden();
257 QAction
* showMenuBarAction
= actionCollection()->action(KStandardAction::name(KStandardAction::ShowMenubar
));
258 showMenuBarAction
->setChecked(showMenu
); // workaround for bug #171080
260 createToolBarMenuButton();
264 DolphinMainWindow::~DolphinMainWindow()
268 void DolphinMainWindow::openDirectories(const QList
<KUrl
>& dirs
)
270 if (dirs
.isEmpty()) {
274 if (dirs
.count() == 1) {
275 m_activeViewContainer
->setUrl(dirs
.first());
279 const int oldOpenTabsCount
= m_viewTab
.count();
281 const GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
282 const bool hasSplitView
= generalSettings
->splitView();
284 // Open each directory inside a new tab. If the "split view" option has been enabled,
285 // always show two directories within one tab.
286 QList
<KUrl
>::const_iterator it
= dirs
.begin();
287 while (it
!= dirs
.end()) {
291 if (hasSplitView
&& (it
!= dirs
.end())) {
292 const int tabIndex
= m_viewTab
.count() - 1;
293 m_viewTab
[tabIndex
].secondaryView
->setUrl(*it
);
298 // Remove the previously opened tabs
299 for (int i
= 0; i
< oldOpenTabsCount
; ++i
) {
304 void DolphinMainWindow::openFiles(const QList
<KUrl
>& files
)
306 if (files
.isEmpty()) {
310 // Get all distinct directories from 'files' and open a tab
311 // for each directory. If the "split view" option is enabled, two
312 // directories are shown inside one tab (see openDirectories()).
314 foreach (const KUrl
& url
, files
) {
315 const KUrl
dir(url
.directory());
316 if (!dirs
.contains(dir
)) {
321 openDirectories(dirs
);
323 // Select the files. Although the files can be split between several
324 // tabs, there is no need to split 'files' accordingly, as
325 // the DolphinView will just ignore invalid selections.
326 const int tabCount
= m_viewTab
.count();
327 for (int i
= 0; i
< tabCount
; ++i
) {
328 m_viewTab
[i
].primaryView
->view()->markUrlsAsSelected(files
);
329 m_viewTab
[i
].primaryView
->view()->markUrlAsCurrent(files
.at(0));
330 if (m_viewTab
[i
].secondaryView
) {
331 m_viewTab
[i
].secondaryView
->view()->markUrlsAsSelected(files
);
332 m_viewTab
[i
].secondaryView
->view()->markUrlAsCurrent(files
.at(0));
337 void DolphinMainWindow::showCommand(CommandType command
)
339 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
341 case KIO::FileUndoManager::Copy
:
342 statusBar
->setMessage(i18nc("@info:status", "Successfully copied."),
343 DolphinStatusBar::OperationCompleted
);
345 case KIO::FileUndoManager::Move
:
346 statusBar
->setMessage(i18nc("@info:status", "Successfully moved."),
347 DolphinStatusBar::OperationCompleted
);
349 case KIO::FileUndoManager::Link
:
350 statusBar
->setMessage(i18nc("@info:status", "Successfully linked."),
351 DolphinStatusBar::OperationCompleted
);
353 case KIO::FileUndoManager::Trash
:
354 statusBar
->setMessage(i18nc("@info:status", "Successfully moved to trash."),
355 DolphinStatusBar::OperationCompleted
);
357 case KIO::FileUndoManager::Rename
:
358 statusBar
->setMessage(i18nc("@info:status", "Successfully renamed."),
359 DolphinStatusBar::OperationCompleted
);
362 case KIO::FileUndoManager::Mkdir
:
363 statusBar
->setMessage(i18nc("@info:status", "Created folder."),
364 DolphinStatusBar::OperationCompleted
);
372 void DolphinMainWindow::pasteIntoFolder()
374 m_activeViewContainer
->view()->pasteIntoFolder();
377 void DolphinMainWindow::changeUrl(const KUrl
& url
)
379 if (!KProtocolManager::supportsListing(url
)) {
380 // The URL navigator only checks for validity, not
381 // if the URL can be listed. An error message is
382 // shown due to DolphinViewContainer::restoreView().
386 DolphinViewContainer
* view
= activeViewContainer();
392 setUrlAsCaption(url
);
393 if (m_viewTab
.count() > 1) {
394 m_tabBar
->setTabText(m_tabIndex
, squeezedText(tabName(m_activeViewContainer
->url())));
396 const QString iconName
= KMimeType::iconNameForUrl(url
);
397 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(iconName
));
398 emit
urlChanged(url
);
402 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
404 KToggleAction
* editableLocationAction
=
405 static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
406 editableLocationAction
->setChecked(editable
);
409 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
413 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
414 int selectedUrlsCount
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedItemsCount();
415 if (m_viewTab
[m_tabIndex
].secondaryView
) {
416 selectedUrlsCount
+= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItemsCount();
419 QAction
* compareFilesAction
= actionCollection()->action("compare_files");
420 if (selectedUrlsCount
== 2) {
421 compareFilesAction
->setEnabled(isKompareInstalled());
423 compareFilesAction
->setEnabled(false);
426 emit
selectionChanged(selection
);
429 void DolphinMainWindow::slotRequestItemInfo(const KFileItem
& item
)
431 emit
requestItemInfo(item
);
434 void DolphinMainWindow::updateHistory()
436 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
437 const int index
= urlNavigator
->historyIndex();
439 QAction
* backAction
= actionCollection()->action("go_back");
441 backAction
->setToolTip(i18nc("@info", "Go back"));
442 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
445 QAction
* forwardAction
= actionCollection()->action("go_forward");
447 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
448 forwardAction
->setEnabled(index
> 0);
452 void DolphinMainWindow::updateFilterBarAction(bool show
)
454 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
455 showFilterBarAction
->setChecked(show
);
458 void DolphinMainWindow::openNewMainWindow()
460 KRun::run("dolphin", KUrl::List(), this);
463 void DolphinMainWindow::openNewTab()
465 const bool isUrlEditable
= m_activeViewContainer
->urlNavigator()->isUrlEditable();
467 openNewTab(m_activeViewContainer
->url());
468 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
470 // The URL navigator of the new tab should have the same editable state
471 // as the current tab
472 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
473 navigator
->setUrlEditable(isUrlEditable
);
476 // If a new tab is opened and the URL is editable, assure that
477 // the user can edit the URL without manually setting the focus
478 navigator
->setFocus();
482 void DolphinMainWindow::openNewTab(const KUrl
& url
)
484 QWidget
* focusWidget
= QApplication::focusWidget();
486 if (m_viewTab
.count() == 1) {
487 // Only one view is open currently and hence no tab is shown at
488 // all. Before creating a tab for 'url', provide a tab for the current URL.
489 const KUrl currentUrl
= m_activeViewContainer
->url();
490 m_tabBar
->addTab(KIcon(KMimeType::iconNameForUrl(currentUrl
)),
491 squeezedText(tabName(currentUrl
)));
492 m_tabBar
->blockSignals(false);
495 m_tabBar
->addTab(KIcon(KMimeType::iconNameForUrl(url
)),
496 squeezedText(tabName(url
)));
499 viewTab
.splitter
= new QSplitter(this);
500 viewTab
.splitter
->setChildrenCollapsible(false);
501 viewTab
.primaryView
= createViewContainer(url
, viewTab
.splitter
);
502 viewTab
.primaryView
->setActive(false);
503 connectViewSignals(viewTab
.primaryView
);
505 m_viewTab
.append(viewTab
);
507 actionCollection()->action("close_tab")->setEnabled(true);
509 // provide a split view, if the startup settings are set this way
510 const GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
511 if (generalSettings
->splitView()) {
512 const int tabIndex
= m_viewTab
.count() - 1;
513 createSecondaryView(tabIndex
);
514 m_viewTab
[tabIndex
].secondaryView
->setActive(true);
515 m_viewTab
[tabIndex
].isPrimaryViewActive
= false;
519 // The DolphinViewContainer grabbed the keyboard focus. As the tab is opened
520 // in background, assure that the previous focused widget gets the focus back.
521 focusWidget
->setFocus();
525 void DolphinMainWindow::activateNextTab()
527 if ((m_viewTab
.count() == 1) || (m_tabBar
->count() < 2)) {
531 const int tabIndex
= (m_tabBar
->currentIndex() + 1) % m_tabBar
->count();
532 m_tabBar
->setCurrentIndex(tabIndex
);
535 void DolphinMainWindow::activatePrevTab()
537 if ((m_viewTab
.count() == 1) || (m_tabBar
->count() < 2)) {
541 int tabIndex
= m_tabBar
->currentIndex() - 1;
542 if (tabIndex
== -1) {
543 tabIndex
= m_tabBar
->count() - 1;
545 m_tabBar
->setCurrentIndex(tabIndex
);
548 void DolphinMainWindow::openInNewTab()
550 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
551 if (list
.isEmpty()) {
552 openNewTab(m_activeViewContainer
->url());
553 } else if ((list
.count() == 1) && list
[0].isDir()) {
554 openNewTab(list
[0].url());
558 void DolphinMainWindow::openInNewWindow()
562 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
563 if (list
.isEmpty()) {
564 newWindowUrl
= m_activeViewContainer
->url();
565 } else if ((list
.count() == 1) && list
[0].isDir()) {
566 newWindowUrl
= list
[0].url();
569 if (!newWindowUrl
.isEmpty()) {
570 KRun::run("dolphin", KUrl::List() << newWindowUrl
, this);
574 void DolphinMainWindow::toggleActiveView()
576 if (!m_viewTab
[m_tabIndex
].secondaryView
) {
577 // only one view is available
581 Q_ASSERT(m_activeViewContainer
);
582 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
584 DolphinViewContainer
* left
= m_viewTab
[m_tabIndex
].primaryView
;
585 DolphinViewContainer
* right
= m_viewTab
[m_tabIndex
].secondaryView
;
586 setActiveViewContainer(m_activeViewContainer
== right
? left
: right
);
589 void DolphinMainWindow::showEvent(QShowEvent
* event
)
591 KXmlGuiWindow::showEvent(event
);
592 if (!event
->spontaneous()) {
593 m_activeViewContainer
->view()->setFocus();
597 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
599 GeneralSettings
* generalSettings
= GeneralSettings::self();
601 // Find out if Dolphin is closed directly by the user or
602 // by the session manager because the session is closed
603 bool closedByUser
= true;
604 DolphinApplication
*application
= qobject_cast
<DolphinApplication
*>(qApp
);
605 if (application
&& application
->sessionSaving()) {
606 closedByUser
= false;
609 if ((m_viewTab
.count() > 1) && generalSettings
->confirmClosingMultipleTabs() && closedByUser
) {
610 // Ask the user if he really wants to quit and close all tabs.
611 // Open a confirmation dialog with 3 buttons:
612 // KDialog::Yes -> Quit
613 // KDialog::No -> Close only the current tab
614 // KDialog::Cancel -> do nothing
615 KDialog
*dialog
= new KDialog(this, Qt::Dialog
);
616 dialog
->setCaption(i18nc("@title:window", "Confirmation"));
617 dialog
->setButtons(KDialog::Yes
| KDialog::No
| KDialog::Cancel
);
618 dialog
->setModal(true);
619 dialog
->setButtonGuiItem(KDialog::Yes
, KStandardGuiItem::quit());
620 dialog
->setButtonGuiItem(KDialog::No
, KGuiItem(i18n("C&lose Current Tab"), KIcon("tab-close")));
621 dialog
->setButtonGuiItem(KDialog::Cancel
, KStandardGuiItem::cancel());
622 dialog
->setDefaultButton(KDialog::Yes
);
624 bool doNotAskAgainCheckboxResult
= false;
626 const int result
= KMessageBox::createKMessageBox(dialog
,
627 QMessageBox::Warning
,
628 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
630 i18n("Do not ask again"),
631 &doNotAskAgainCheckboxResult
,
632 KMessageBox::Notify
);
634 if (doNotAskAgainCheckboxResult
) {
635 generalSettings
->setConfirmClosingMultipleTabs(false);
643 // Close only the current tab
651 generalSettings
->setVersion(CurrentDolphinVersion
);
652 generalSettings
->writeConfig();
654 if (m_searchDockIsTemporaryVisible
) {
655 QDockWidget
* searchDock
= findChild
<QDockWidget
*>("searchDock");
659 m_searchDockIsTemporaryVisible
= false;
662 KXmlGuiWindow::closeEvent(event
);
665 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
667 const int tabCount
= m_viewTab
.count();
668 group
.writeEntry("Tab Count", tabCount
);
669 group
.writeEntry("Active Tab Index", m_tabBar
->currentIndex());
671 for (int i
= 0; i
< tabCount
; ++i
) {
672 const DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
673 group
.writeEntry(tabProperty("Primary URL", i
), cont
->url().url());
674 group
.writeEntry(tabProperty("Primary Editable", i
),
675 cont
->urlNavigator()->isUrlEditable());
677 cont
= m_viewTab
[i
].secondaryView
;
679 group
.writeEntry(tabProperty("Secondary URL", i
), cont
->url().url());
680 group
.writeEntry(tabProperty("Secondary Editable", i
),
681 cont
->urlNavigator()->isUrlEditable());
686 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
688 const int tabCount
= group
.readEntry("Tab Count", 1);
689 for (int i
= 0; i
< tabCount
; ++i
) {
690 DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
692 cont
->setUrl(group
.readEntry(tabProperty("Primary URL", i
)));
693 const bool editable
= group
.readEntry(tabProperty("Primary Editable", i
), false);
694 cont
->urlNavigator()->setUrlEditable(editable
);
696 cont
= m_viewTab
[i
].secondaryView
;
697 const QString secondaryUrl
= group
.readEntry(tabProperty("Secondary URL", i
));
698 if (!secondaryUrl
.isEmpty()) {
700 // a secondary view should be shown, but no one is available
701 // currently -> create a new view
703 cont
= m_viewTab
[i
].secondaryView
;
707 cont
->setUrl(secondaryUrl
);
708 const bool editable
= group
.readEntry(tabProperty("Secondary Editable", i
), false);
709 cont
->urlNavigator()->setUrlEditable(editable
);
711 // no secondary view should be shown, but the default setting shows
712 // one already -> close the view
716 // openNewTab() needs to be called only tabCount - 1 times
717 if (i
!= tabCount
- 1) {
722 const int index
= group
.readEntry("Active Tab Index", 0);
723 m_tabBar
->setCurrentIndex(index
);
726 void DolphinMainWindow::updateNewMenu()
728 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
729 m_newFileMenu
->checkUpToDate();
730 m_newFileMenu
->setPopupFiles(activeViewContainer()->url());
733 void DolphinMainWindow::createDirectory()
735 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
736 m_newFileMenu
->setPopupFiles(activeViewContainer()->url());
737 m_newFileMenu
->createDirectory();
740 void DolphinMainWindow::quit()
745 void DolphinMainWindow::showErrorMessage(const QString
& message
)
747 if (!message
.isEmpty()) {
748 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
749 statusBar
->setMessage(message
, DolphinStatusBar::Error
);
753 void DolphinMainWindow::slotUndoAvailable(bool available
)
755 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
757 undoAction
->setEnabled(available
);
761 void DolphinMainWindow::restoreClosedTab(QAction
* action
)
763 if (action
->data().toBool()) {
764 // clear all actions except the "Empty Recently Closed Tabs"
765 // action and the separator
766 QList
<QAction
*> actions
= m_recentTabsMenu
->menu()->actions();
767 const int count
= actions
.size();
768 for (int i
= 2; i
< count
; ++i
) {
769 m_recentTabsMenu
->menu()->removeAction(actions
.at(i
));
772 const ClosedTab closedTab
= action
->data().value
<ClosedTab
>();
773 openNewTab(closedTab
.primaryUrl
);
774 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
776 if (closedTab
.isSplit
) {
777 // create secondary view
779 m_viewTab
[m_tabIndex
].secondaryView
->setUrl(closedTab
.secondaryUrl
);
782 m_recentTabsMenu
->removeAction(action
);
785 if (m_recentTabsMenu
->menu()->actions().count() == 2) {
786 m_recentTabsMenu
->setEnabled(false);
790 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
792 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
794 undoAction
->setText(text
);
798 void DolphinMainWindow::undo()
801 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
802 KIO::FileUndoManager::self()->undo();
805 void DolphinMainWindow::cut()
807 m_activeViewContainer
->view()->cutSelectedItems();
810 void DolphinMainWindow::copy()
812 m_activeViewContainer
->view()->copySelectedItems();
815 void DolphinMainWindow::paste()
817 m_activeViewContainer
->view()->paste();
820 void DolphinMainWindow::find()
822 m_activeViewContainer
->setSearchModeEnabled(true);
825 void DolphinMainWindow::slotSearchLocationChanged()
828 QDockWidget
* searchDock
= findChild
<QDockWidget
*>("searchDock");
833 SearchPanel
* searchPanel
= qobject_cast
<SearchPanel
*>(searchDock
->widget());
835 searchPanel
->setSearchLocation(SearchSettings::location() == QLatin1String("FromHere")
836 ? SearchPanel::FromCurrentDir
837 : SearchPanel::Everywhere
);
842 void DolphinMainWindow::updatePasteAction()
844 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
845 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
846 pasteAction
->setEnabled(pasteInfo
.first
);
847 pasteAction
->setText(pasteInfo
.second
);
850 void DolphinMainWindow::selectAll()
854 // if the URL navigator is editable and focused, select the whole
855 // URL instead of all items of the view
857 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
858 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit(); // krazy:exclude=qclasses
859 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
860 lineEdit
->hasFocus();
862 lineEdit
->selectAll();
864 m_activeViewContainer
->view()->selectAll();
868 void DolphinMainWindow::invertSelection()
871 m_activeViewContainer
->view()->invertSelection();
874 void DolphinMainWindow::toggleSplitView()
876 if (!m_viewTab
[m_tabIndex
].secondaryView
) {
877 createSecondaryView(m_tabIndex
);
878 setActiveViewContainer(m_viewTab
[m_tabIndex
].secondaryView
);
879 } else if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
880 // remove secondary view
881 m_viewTab
[m_tabIndex
].secondaryView
->close();
882 m_viewTab
[m_tabIndex
].secondaryView
->deleteLater();
883 m_viewTab
[m_tabIndex
].secondaryView
= 0;
885 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
887 // The primary view is active and should be closed. Hence from a users point of view
888 // the content of the secondary view should be moved to the primary view.
889 // From an implementation point of view it is more efficient to close
890 // the primary view and exchange the internal pointers afterwards.
892 m_viewTab
[m_tabIndex
].primaryView
->close();
893 m_viewTab
[m_tabIndex
].primaryView
->deleteLater();
894 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
895 m_viewTab
[m_tabIndex
].secondaryView
= 0;
897 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
903 void DolphinMainWindow::reloadView()
906 m_activeViewContainer
->view()->reload();
909 void DolphinMainWindow::stopLoading()
911 m_activeViewContainer
->view()->stopLoading();
914 void DolphinMainWindow::enableStopAction()
916 actionCollection()->action("stop")->setEnabled(true);
919 void DolphinMainWindow::disableStopAction()
921 actionCollection()->action("stop")->setEnabled(false);
924 void DolphinMainWindow::showFilterBar()
926 m_activeViewContainer
->setFilterBarVisible(true);
929 void DolphinMainWindow::toggleEditLocation()
933 QAction
* action
= actionCollection()->action("editable_location");
934 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
935 urlNavigator
->setUrlEditable(action
->isChecked());
938 void DolphinMainWindow::replaceLocation()
940 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
941 navigator
->setUrlEditable(true);
942 navigator
->setFocus();
944 // select the whole text of the combo box editor
945 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit(); // krazy:exclude=qclasses
946 lineEdit
->selectAll();
949 void DolphinMainWindow::togglePanelLockState()
951 GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
953 const bool newLockState
= !generalSettings
->lockPanels();
954 foreach (QObject
* child
, children()) {
955 DolphinDockWidget
* dock
= qobject_cast
<DolphinDockWidget
*>(child
);
957 dock
->setLocked(newLockState
);
961 generalSettings
->setLockPanels(newLockState
);
964 void DolphinMainWindow::slotPlacesPanelVisibilityChanged(bool visible
)
966 const int tabCount
= m_viewTab
.count();
967 for (int i
= 0; i
< tabCount
; ++i
) {
968 ViewTab
& tab
= m_viewTab
[i
];
969 Q_ASSERT(tab
.primaryView
);
970 tab
.primaryView
->urlNavigator()->setPlacesSelectorVisible(!visible
);
971 if (tab
.secondaryView
) {
972 tab
.secondaryView
->urlNavigator()->setPlacesSelectorVisible(!visible
);
977 void DolphinMainWindow::goBack()
979 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
980 urlNavigator
->goBack();
982 if (urlNavigator
->locationState().isEmpty()) {
983 // An empty location state indicates a redirection URL,
984 // which must be skipped too
985 urlNavigator
->goBack();
989 void DolphinMainWindow::goForward()
991 m_activeViewContainer
->urlNavigator()->goForward();
994 void DolphinMainWindow::goUp()
996 m_activeViewContainer
->urlNavigator()->goUp();
999 void DolphinMainWindow::goHome()
1001 m_activeViewContainer
->urlNavigator()->goHome();
1004 void DolphinMainWindow::goBack(Qt::MouseButtons buttons
)
1006 // The default case (left button pressed) is handled in goBack().
1007 if (buttons
== Qt::MidButton
) {
1008 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
1009 const int index
= urlNavigator
->historyIndex() + 1;
1010 openNewTab(urlNavigator
->locationUrl(index
));
1014 void DolphinMainWindow::goForward(Qt::MouseButtons buttons
)
1016 // The default case (left button pressed) is handled in goForward().
1017 if (buttons
== Qt::MidButton
) {
1018 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
1019 const int index
= urlNavigator
->historyIndex() - 1;
1020 openNewTab(urlNavigator
->locationUrl(index
));
1024 void DolphinMainWindow::goUp(Qt::MouseButtons buttons
)
1026 // The default case (left button pressed) is handled in goUp().
1027 if (buttons
== Qt::MidButton
) {
1028 openNewTab(activeViewContainer()->url().upUrl());
1032 void DolphinMainWindow::compareFiles()
1034 // The method is only invoked if exactly 2 files have
1035 // been selected. The selected files may be:
1036 // - both in the primary view
1037 // - both in the secondary view
1038 // - one in the primary view and the other in the secondary
1040 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
1045 KFileItemList items
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedItems();
1047 switch (items
.count()) {
1049 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
);
1050 items
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItems();
1051 Q_ASSERT(items
.count() == 2);
1052 urlA
= items
[0].url();
1053 urlB
= items
[1].url();
1058 urlA
= items
[0].url();
1059 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
);
1060 items
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItems();
1061 Q_ASSERT(items
.count() == 1);
1062 urlB
= items
[0].url();
1067 urlA
= items
[0].url();
1068 urlB
= items
[1].url();
1073 // may not happen: compareFiles may only get invoked if 2
1074 // files are selected
1079 QString
command("kompare -c \"");
1080 command
.append(urlA
.pathOrUrl());
1081 command
.append("\" \"");
1082 command
.append(urlB
.pathOrUrl());
1083 command
.append('\"');
1084 KRun::runCommand(command
, "Kompare", "kompare", this);
1087 void DolphinMainWindow::toggleShowMenuBar()
1089 const bool visible
= menuBar()->isVisible();
1090 menuBar()->setVisible(!visible
);
1092 createToolBarMenuButton();
1094 deleteToolBarMenuButton();
1098 void DolphinMainWindow::openTerminal()
1100 QString
dir(QDir::homePath());
1102 // If the given directory is not local, it can still be the URL of an
1103 // ioslave using UDS_LOCAL_PATH which to be converted first.
1104 KUrl url
= KIO::NetAccess::mostLocalUrl(m_activeViewContainer
->url(), this);
1106 //If the URL is local after the above conversion, set the directory.
1107 if (url
.isLocalFile()) {
1108 dir
= url
.toLocalFile();
1111 KToolInvocation::invokeTerminal(QString(), dir
);
1114 void DolphinMainWindow::editSettings()
1116 if (!m_settingsDialog
) {
1117 const KUrl url
= activeViewContainer()->url();
1118 DolphinSettingsDialog
* settingsDialog
= new DolphinSettingsDialog(url
, this);
1119 connect(settingsDialog
, SIGNAL(settingsChanged()), this, SLOT(refreshViews()));
1120 settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1121 settingsDialog
->show();
1122 m_settingsDialog
= settingsDialog
;
1124 m_settingsDialog
.data()->raise();
1128 void DolphinMainWindow::setActiveTab(int index
)
1130 Q_ASSERT(index
>= 0);
1131 Q_ASSERT(index
< m_viewTab
.count());
1132 if (index
== m_tabIndex
) {
1136 // hide current tab content
1137 ViewTab
& hiddenTab
= m_viewTab
[m_tabIndex
];
1138 hiddenTab
.isPrimaryViewActive
= hiddenTab
.primaryView
->isActive();
1139 hiddenTab
.primaryView
->setActive(false);
1140 if (hiddenTab
.secondaryView
) {
1141 hiddenTab
.secondaryView
->setActive(false);
1143 QSplitter
* splitter
= m_viewTab
[m_tabIndex
].splitter
;
1145 m_centralWidgetLayout
->removeWidget(splitter
);
1147 // show active tab content
1150 ViewTab
& viewTab
= m_viewTab
[index
];
1151 m_centralWidgetLayout
->addWidget(viewTab
.splitter
, 1);
1152 viewTab
.primaryView
->show();
1153 if (viewTab
.secondaryView
) {
1154 viewTab
.secondaryView
->show();
1156 viewTab
.splitter
->show();
1158 setActiveViewContainer(viewTab
.isPrimaryViewActive
? viewTab
.primaryView
:
1159 viewTab
.secondaryView
);
1162 void DolphinMainWindow::closeTab()
1164 closeTab(m_tabBar
->currentIndex());
1167 void DolphinMainWindow::closeTab(int index
)
1169 Q_ASSERT(index
>= 0);
1170 Q_ASSERT(index
< m_viewTab
.count());
1171 if (m_viewTab
.count() == 1) {
1172 // the last tab may never get closed
1176 if (index
== m_tabIndex
) {
1177 // The tab that should be closed is the active tab. Activate the
1178 // previous tab before closing the tab.
1179 m_tabBar
->setCurrentIndex((index
> 0) ? index
- 1 : 1);
1181 rememberClosedTab(index
);
1184 m_viewTab
[index
].primaryView
->deleteLater();
1185 if (m_viewTab
[index
].secondaryView
) {
1186 m_viewTab
[index
].secondaryView
->deleteLater();
1188 m_viewTab
[index
].splitter
->deleteLater();
1189 m_viewTab
.erase(m_viewTab
.begin() + index
);
1191 m_tabBar
->blockSignals(true);
1192 m_tabBar
->removeTab(index
);
1194 if (m_tabIndex
> index
) {
1196 Q_ASSERT(m_tabIndex
>= 0);
1199 // if only one tab is left, also remove the tab entry so that
1200 // closing the last tab is not possible
1201 if (m_viewTab
.count() == 1) {
1202 m_tabBar
->removeTab(0);
1203 actionCollection()->action("close_tab")->setEnabled(false);
1205 m_tabBar
->blockSignals(false);
1209 void DolphinMainWindow::openTabContextMenu(int index
, const QPoint
& pos
)
1213 QAction
* newTabAction
= menu
.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab"));
1214 newTabAction
->setShortcut(actionCollection()->action("new_tab")->shortcut());
1216 QAction
* detachTabAction
= menu
.addAction(KIcon("tab-detach"), i18nc("@action:inmenu", "Detach Tab"));
1218 QAction
* closeOtherTabsAction
= menu
.addAction(KIcon("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs"));
1220 QAction
* closeTabAction
= menu
.addAction(KIcon("tab-close"), i18nc("@action:inmenu", "Close Tab"));
1221 closeTabAction
->setShortcut(actionCollection()->action("close_tab")->shortcut());
1222 QAction
* selectedAction
= menu
.exec(pos
);
1223 if (selectedAction
== newTabAction
) {
1224 const ViewTab
& tab
= m_viewTab
[index
];
1225 Q_ASSERT(tab
.primaryView
);
1226 const KUrl url
= tab
.secondaryView
&& tab
.secondaryView
->isActive() ?
1227 tab
.secondaryView
->url() : tab
.primaryView
->url();
1229 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
1230 } else if (selectedAction
== detachTabAction
) {
1231 const QString
separator(QLatin1Char(' '));
1232 QString command
= QLatin1String("dolphin");
1234 const ViewTab
& tab
= m_viewTab
[index
];
1235 Q_ASSERT(tab
.primaryView
);
1237 command
+= separator
+ tab
.primaryView
->url().url();
1238 if (tab
.secondaryView
) {
1239 command
+= separator
+ tab
.secondaryView
->url().url();
1240 command
+= separator
+ QLatin1String("-split");
1243 KRun::runCommand(command
, this);
1246 } else if (selectedAction
== closeOtherTabsAction
) {
1247 const int count
= m_tabBar
->count();
1248 for (int i
= 0; i
< index
; ++i
) {
1251 for (int i
= index
+ 1; i
< count
; ++i
) {
1254 } else if (selectedAction
== closeTabAction
) {
1259 void DolphinMainWindow::slotTabMoved(int from
, int to
)
1261 m_viewTab
.move(from
, to
);
1262 m_tabIndex
= m_tabBar
->currentIndex();
1265 void DolphinMainWindow::handlePlacesClick(const KUrl
& url
, Qt::MouseButtons buttons
)
1267 if (buttons
& Qt::MidButton
) {
1269 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
1275 void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent
* event
, bool& canDecode
)
1277 canDecode
= KUrl::List::canDecode(event
->mimeData());
1280 void DolphinMainWindow::handleUrl(const KUrl
& url
)
1282 delete m_lastHandleUrlStatJob
;
1283 m_lastHandleUrlStatJob
= 0;
1285 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1286 activeViewContainer()->setUrl(url
);
1287 } else if (KProtocolManager::supportsListing(url
)) {
1288 // stat the URL to see if it is a dir or not
1289 m_lastHandleUrlStatJob
= KIO::stat(url
, KIO::HideProgressInfo
);
1290 connect(m_lastHandleUrlStatJob
, SIGNAL(result(KJob
*)),
1291 this, SLOT(slotHandleUrlStatFinished(KJob
*)));
1294 new KRun(url
, this);
1298 void DolphinMainWindow::slotHandleUrlStatFinished(KJob
* job
)
1300 m_lastHandleUrlStatJob
= 0;
1301 const KIO::UDSEntry entry
= static_cast<KIO::StatJob
*>(job
)->statResult();
1302 const KUrl url
= static_cast<KIO::StatJob
*>(job
)->url();
1303 if (entry
.isDir()) {
1304 activeViewContainer()->setUrl(url
);
1306 new KRun(url
, this);
1310 void DolphinMainWindow::tabDropEvent(int tab
, QDropEvent
* event
)
1312 const KUrl::List urls
= KUrl::List::fromMimeData(event
->mimeData());
1313 if (!urls
.isEmpty() && tab
!= -1) {
1314 const ViewTab
& viewTab
= m_viewTab
[tab
];
1315 const KUrl destPath
= viewTab
.isPrimaryViewActive
? viewTab
.primaryView
->url() : viewTab
.secondaryView
->url();
1317 //DragAndDropHelper::instance().dropUrls(KFileItem(), destPath, event, m_tabBar);
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::updateToolBarMenu()
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 const GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
1410 KActionCollection
* ac
= actionCollection();
1412 // Add "Edit" actions
1413 bool added
= addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Undo
)), menu
) |
1414 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Find
)), menu
) |
1415 addActionToMenu(ac
->action("select_all"), menu
) |
1416 addActionToMenu(ac
->action("invert_selection"), menu
);
1419 menu
->addSeparator();
1422 // Add "View" actions
1423 if (!generalSettings
->showZoomSlider()) {
1424 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomIn
)), menu
);
1425 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomOut
)), menu
);
1426 menu
->addSeparator();
1429 added
= addActionToMenu(ac
->action("view_mode"), menu
) |
1430 addActionToMenu(ac
->action("sort"), menu
) |
1431 addActionToMenu(ac
->action("additional_info"), menu
) |
1432 addActionToMenu(ac
->action("show_preview"), menu
) |
1433 addActionToMenu(ac
->action("show_in_groups"), menu
) |
1434 addActionToMenu(ac
->action("show_hidden_files"), menu
);
1437 menu
->addSeparator();
1440 added
= addActionToMenu(ac
->action("split_view"), menu
) |
1441 addActionToMenu(ac
->action("reload"), menu
) |
1442 addActionToMenu(ac
->action("view_properties"), menu
);
1444 menu
->addSeparator();
1447 addActionToMenu(ac
->action("panels"), menu
);
1448 KMenu
* locationBarMenu
= new KMenu(i18nc("@action:inmenu", "Location Bar"), menu
);
1449 locationBarMenu
->addAction(ac
->action("editable_location"));
1450 locationBarMenu
->addAction(ac
->action("replace_location"));
1451 menu
->addMenu(locationBarMenu
);
1453 menu
->addSeparator();
1456 KMenu
* goMenu
= new KMenu(i18nc("@action:inmenu", "Go"), menu
);
1457 connect(menu
, SIGNAL(aboutToHide()), goMenu
, SLOT(deleteLater()));
1458 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Back
)));
1459 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Forward
)));
1460 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Up
)));
1461 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Home
)));
1462 goMenu
->addAction(ac
->action("closed_tabs"));
1463 menu
->addMenu(goMenu
);
1466 KMenu
* toolsMenu
= new KMenu(i18nc("@action:inmenu", "Tools"), menu
);
1467 connect(menu
, SIGNAL(aboutToHide()), toolsMenu
, SLOT(deleteLater()));
1468 toolsMenu
->addAction(ac
->action("show_filter_bar"));
1469 toolsMenu
->addAction(ac
->action("compare_files"));
1470 toolsMenu
->addAction(ac
->action("open_terminal"));
1471 toolsMenu
->addAction(ac
->action("change_remote_encoding"));
1472 menu
->addMenu(toolsMenu
);
1474 // Add "Settings" menu entries
1475 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::KeyBindings
)), menu
);
1476 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ConfigureToolbars
)), menu
);
1477 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Preferences
)), menu
);
1480 KMenu
* helpMenu
= new KMenu(i18nc("@action:inmenu", "Help"), menu
);
1481 connect(menu
, SIGNAL(aboutToHide()), helpMenu
, SLOT(deleteLater()));
1482 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::HelpContents
)));
1483 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::WhatsThis
)));
1484 helpMenu
->addSeparator();
1485 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ReportBug
)));
1486 helpMenu
->addSeparator();
1487 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
)));
1488 helpMenu
->addSeparator();
1489 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::AboutApp
)));
1490 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::AboutKDE
)));
1491 menu
->addMenu(helpMenu
);
1493 menu
->addSeparator();
1494 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ShowMenubar
)), menu
);
1497 void DolphinMainWindow::updateToolBar()
1499 if (!menuBar()->isVisible()) {
1500 createToolBarMenuButton();
1504 void DolphinMainWindow::slotToolBarSpacerDeleted()
1506 m_toolBarSpacer
= 0;
1507 m_updateToolBarTimer
->start();
1510 void DolphinMainWindow::slotToolBarMenuButtonDeleted()
1512 m_openToolBarMenuButton
= 0;
1513 m_updateToolBarTimer
->start();
1516 void DolphinMainWindow::slotToolBarIconSizeChanged(const QSize
& iconSize
)
1518 if (m_openToolBarMenuButton
) {
1519 m_openToolBarMenuButton
->setIconSize(iconSize
);
1523 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer
* viewContainer
)
1525 Q_ASSERT(viewContainer
);
1526 Q_ASSERT((viewContainer
== m_viewTab
[m_tabIndex
].primaryView
) ||
1527 (viewContainer
== m_viewTab
[m_tabIndex
].secondaryView
));
1528 if (m_activeViewContainer
== viewContainer
) {
1532 m_activeViewContainer
->setActive(false);
1533 m_activeViewContainer
= viewContainer
;
1535 // Activating the view container might trigger a recursive setActiveViewContainer() call
1536 // inside DolphinMainWindow::toggleActiveView() when having a split view. Temporary
1537 // disconnect the activated() signal in this case:
1538 disconnect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1539 m_activeViewContainer
->setActive(true);
1540 connect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1542 m_actionHandler
->setCurrentView(viewContainer
->view());
1545 updateEditActions();
1546 updateViewActions();
1549 const KUrl url
= m_activeViewContainer
->url();
1550 setUrlAsCaption(url
);
1551 if (m_viewTab
.count() > 1) {
1552 m_tabBar
->setTabText(m_tabIndex
, tabName(url
));
1553 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(KMimeType::iconNameForUrl(url
)));
1556 emit
urlChanged(url
);
1559 DolphinViewContainer
* DolphinMainWindow::createViewContainer(const KUrl
& url
, QWidget
* parent
)
1561 DolphinViewContainer
* container
= new DolphinViewContainer(url
, parent
);
1563 // The places-selector from the URL navigator should only be shown
1564 // if the places dock is invisible
1565 QDockWidget
* placesDock
= findChild
<QDockWidget
*>("placesDock");
1566 container
->urlNavigator()->setPlacesSelectorVisible(!placesDock
|| !placesDock
->isVisible());
1571 void DolphinMainWindow::setupActions()
1573 // setup 'File' menu
1574 m_newFileMenu
= new DolphinNewFileMenu(this);
1575 KMenu
* menu
= m_newFileMenu
->menu();
1576 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1577 menu
->setIcon(KIcon("document-new"));
1578 connect(menu
, SIGNAL(aboutToShow()),
1579 this, SLOT(updateNewMenu()));
1581 KAction
* newWindow
= actionCollection()->addAction("new_window");
1582 newWindow
->setIcon(KIcon("window-new"));
1583 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1584 newWindow
->setShortcut(Qt::CTRL
| Qt::Key_N
);
1585 connect(newWindow
, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1587 KAction
* newTab
= actionCollection()->addAction("new_tab");
1588 newTab
->setIcon(KIcon("tab-new"));
1589 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1590 newTab
->setShortcut(KShortcut(Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
));
1591 connect(newTab
, SIGNAL(triggered()), this, SLOT(openNewTab()));
1593 KAction
* closeTab
= actionCollection()->addAction("close_tab");
1594 closeTab
->setIcon(KIcon("tab-close"));
1595 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1596 closeTab
->setShortcut(Qt::CTRL
| Qt::Key_W
);
1597 closeTab
->setEnabled(false);
1598 connect(closeTab
, SIGNAL(triggered()), this, SLOT(closeTab()));
1600 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1602 // setup 'Edit' menu
1603 KStandardAction::undo(this,
1605 actionCollection());
1607 // need to remove shift+del from cut action, else the shortcut for deletejob
1609 KAction
* cut
= KStandardAction::cut(this, SLOT(cut()), actionCollection());
1610 KShortcut cutShortcut
= cut
->shortcut();
1611 cutShortcut
.remove(Qt::SHIFT
| Qt::Key_Delete
, KShortcut::KeepEmpty
);
1612 cut
->setShortcut(cutShortcut
);
1613 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1614 KAction
* paste
= KStandardAction::paste(this, SLOT(paste()), actionCollection());
1615 // The text of the paste-action is modified dynamically by Dolphin
1616 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1617 // due to the long text, the text "Paste" is used:
1618 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1620 KStandardAction::find(this, SLOT(find()), actionCollection());
1622 KAction
* selectAll
= actionCollection()->addAction("select_all");
1623 selectAll
->setText(i18nc("@action:inmenu Edit", "Select All"));
1624 selectAll
->setShortcut(Qt::CTRL
| Qt::Key_A
);
1625 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
1627 KAction
* invertSelection
= actionCollection()->addAction("invert_selection");
1628 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1629 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1630 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
1632 // setup 'View' menu
1633 // (note that most of it is set up in DolphinViewActionHandler)
1635 KAction
* split
= actionCollection()->addAction("split_view");
1636 split
->setShortcut(Qt::Key_F3
);
1637 updateSplitAction();
1638 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1640 KAction
* reload
= actionCollection()->addAction("reload");
1641 reload
->setText(i18nc("@action:inmenu View", "Reload"));
1642 reload
->setShortcut(Qt::Key_F5
);
1643 reload
->setIcon(KIcon("view-refresh"));
1644 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
1646 KAction
* stop
= actionCollection()->addAction("stop");
1647 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1648 stop
->setToolTip(i18nc("@info", "Stop loading"));
1649 stop
->setIcon(KIcon("process-stop"));
1650 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
1652 KToggleAction
* editableLocation
= actionCollection()->add
<KToggleAction
>("editable_location");
1653 editableLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1654 editableLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
1655 connect(editableLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1657 KAction
* replaceLocation
= actionCollection()->addAction("replace_location");
1658 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1659 replaceLocation
->setShortcut(Qt::Key_F6
);
1660 connect(replaceLocation
, SIGNAL(triggered()), this, SLOT(replaceLocation()));
1663 KAction
* backAction
= KStandardAction::back(this, SLOT(goBack()), actionCollection());
1664 connect(backAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goBack(Qt::MouseButtons
)));
1665 KShortcut backShortcut
= backAction
->shortcut();
1666 backShortcut
.setAlternate(Qt::Key_Backspace
);
1667 backAction
->setShortcut(backShortcut
);
1669 m_recentTabsMenu
= new KActionMenu(i18n("Recently Closed Tabs"), this);
1670 m_recentTabsMenu
->setIcon(KIcon("edit-undo"));
1671 actionCollection()->addAction("closed_tabs", m_recentTabsMenu
);
1672 connect(m_recentTabsMenu
->menu(), SIGNAL(triggered(QAction
*)),
1673 this, SLOT(restoreClosedTab(QAction
*)));
1675 QAction
* action
= new QAction(i18n("Empty Recently Closed Tabs"), m_recentTabsMenu
);
1676 action
->setIcon(KIcon("edit-clear-list"));
1677 action
->setData(QVariant::fromValue(true));
1678 m_recentTabsMenu
->addAction(action
);
1679 m_recentTabsMenu
->addSeparator();
1680 m_recentTabsMenu
->setEnabled(false);
1682 KAction
* forwardAction
= KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1683 connect(forwardAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goForward(Qt::MouseButtons
)));
1685 KAction
* upAction
= KStandardAction::up(this, SLOT(goUp()), actionCollection());
1686 connect(upAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goUp(Qt::MouseButtons
)));
1688 KStandardAction::home(this, SLOT(goHome()), actionCollection());
1690 // setup 'Tools' menu
1691 KAction
* showFilterBar
= actionCollection()->addAction("show_filter_bar");
1692 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1693 showFilterBar
->setIcon(KIcon("view-filter"));
1694 showFilterBar
->setShortcut(Qt::CTRL
| Qt::Key_I
);
1695 connect(showFilterBar
, SIGNAL(triggered()), this, SLOT(showFilterBar()));
1697 KAction
* compareFiles
= actionCollection()->addAction("compare_files");
1698 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1699 compareFiles
->setIcon(KIcon("kompare"));
1700 compareFiles
->setEnabled(false);
1701 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
1703 KAction
* openTerminal
= actionCollection()->addAction("open_terminal");
1704 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1705 openTerminal
->setIcon(KIcon("utilities-terminal"));
1706 openTerminal
->setShortcut(Qt::SHIFT
| Qt::Key_F4
);
1707 connect(openTerminal
, SIGNAL(triggered()), this, SLOT(openTerminal()));
1709 // setup 'Settings' menu
1710 KStandardAction::showMenubar(this, SLOT(toggleShowMenuBar()), actionCollection());
1711 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1713 // not in menu actions
1714 QList
<QKeySequence
> nextTabKeys
;
1715 nextTabKeys
.append(KStandardShortcut::tabNext().primary());
1716 nextTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::Key_Tab
));
1718 QList
<QKeySequence
> prevTabKeys
;
1719 prevTabKeys
.append(KStandardShortcut::tabPrev().primary());
1720 prevTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::SHIFT
| Qt::Key_Tab
));
1722 KAction
* activateNextTab
= actionCollection()->addAction("activate_next_tab");
1723 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1724 connect(activateNextTab
, SIGNAL(triggered()), SLOT(activateNextTab()));
1725 activateNextTab
->setShortcuts(QApplication::isRightToLeft() ? prevTabKeys
: nextTabKeys
);
1727 KAction
* activatePrevTab
= actionCollection()->addAction("activate_prev_tab");
1728 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1729 connect(activatePrevTab
, SIGNAL(triggered()), SLOT(activatePrevTab()));
1730 activatePrevTab
->setShortcuts(QApplication::isRightToLeft() ? nextTabKeys
: prevTabKeys
);
1733 KAction
* openInNewTab
= actionCollection()->addAction("open_in_new_tab");
1734 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1735 openInNewTab
->setIcon(KIcon("tab-new"));
1736 connect(openInNewTab
, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1738 KAction
* openInNewWindow
= actionCollection()->addAction("open_in_new_window");
1739 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1740 openInNewWindow
->setIcon(KIcon("window-new"));
1741 connect(openInNewWindow
, SIGNAL(triggered()), this, SLOT(openInNewWindow()));
1744 void DolphinMainWindow::setupDockWidgets()
1746 const bool lock
= DolphinSettings::instance().generalSettings()->lockPanels();
1748 KDualAction
* lockLayoutAction
= actionCollection()->add
<KDualAction
>("lock_panels");
1749 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
1750 lockLayoutAction
->setActiveIcon(KIcon("object-unlocked"));
1751 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
1752 lockLayoutAction
->setInactiveIcon(KIcon("object-locked"));
1753 lockLayoutAction
->setActive(lock
);
1754 connect(lockLayoutAction
, SIGNAL(triggered()), this, SLOT(togglePanelLockState()));
1756 // Setup "Information"
1757 DolphinDockWidget
* infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
1758 infoDock
->setLocked(lock
);
1759 infoDock
->setObjectName("infoDock");
1760 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1761 Panel
* infoPanel
= new InformationPanel(infoDock
);
1762 infoPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1763 connect(infoPanel
, SIGNAL(urlActivated(KUrl
)), this, SLOT(handleUrl(KUrl
)));
1764 infoDock
->setWidget(infoPanel
);
1766 QAction
* infoAction
= infoDock
->toggleViewAction();
1767 createPanelAction(KIcon("dialog-information"), Qt::Key_F11
, infoAction
, "show_information_panel");
1769 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1770 connect(this, SIGNAL(urlChanged(KUrl
)),
1771 infoPanel
, SLOT(setUrl(KUrl
)));
1772 connect(this, SIGNAL(selectionChanged(KFileItemList
)),
1773 infoPanel
, SLOT(setSelection(KFileItemList
)));
1774 connect(this, SIGNAL(requestItemInfo(KFileItem
)),
1775 infoPanel
, SLOT(requestDelayedItemInfo(KFileItem
)));
1778 DolphinDockWidget
* foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
1779 foldersDock
->setLocked(lock
);
1780 foldersDock
->setObjectName("foldersDock");
1781 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1782 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1783 foldersPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1784 foldersDock
->setWidget(foldersPanel
);
1786 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1787 createPanelAction(KIcon("folder"), Qt::Key_F7
, foldersAction
, "show_folders_panel");
1789 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1790 connect(this, SIGNAL(urlChanged(KUrl
)),
1791 foldersPanel
, SLOT(setUrl(KUrl
)));
1792 connect(foldersPanel
, SIGNAL(changeUrl(KUrl
,Qt::MouseButtons
)),
1793 this, SLOT(handlePlacesClick(KUrl
,Qt::MouseButtons
)));
1797 DolphinDockWidget
* terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1798 terminalDock
->setLocked(lock
);
1799 terminalDock
->setObjectName("terminalDock");
1800 terminalDock
->setAllowedAreas(Qt::TopDockWidgetArea
| Qt::BottomDockWidgetArea
);
1801 Panel
* terminalPanel
= new TerminalPanel(terminalDock
);
1802 terminalPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1803 terminalDock
->setWidget(terminalPanel
);
1805 connect(terminalPanel
, SIGNAL(hideTerminalPanel()), terminalDock
, SLOT(hide()));
1806 connect(terminalDock
, SIGNAL(visibilityChanged(bool)),
1807 terminalPanel
, SLOT(dockVisibilityChanged()));
1809 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1810 createPanelAction(KIcon("utilities-terminal"), Qt::Key_F4
, terminalAction
, "show_terminal_panel");
1812 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1813 connect(this, SIGNAL(urlChanged(KUrl
)),
1814 terminalPanel
, SLOT(setUrl(KUrl
)));
1819 DolphinDockWidget
* searchDock
= new DolphinDockWidget(i18nc("@title:window", "Search"));
1820 searchDock
->setLocked(lock
);
1821 searchDock
->setObjectName("searchDock");
1822 searchDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1823 Panel
* searchPanel
= new SearchPanel(searchDock
);
1824 searchPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1825 connect(searchPanel
, SIGNAL(urlActivated(KUrl
)), this, SLOT(handleUrl(KUrl
)));
1826 searchDock
->setWidget(searchPanel
);
1828 QAction
* searchAction
= searchDock
->toggleViewAction();
1829 createPanelAction(KIcon("system-search"), Qt::Key_F12
, searchAction
, "show_search_panel");
1830 addDockWidget(Qt::RightDockWidgetArea
, searchDock
);
1831 connect(this, SIGNAL(urlChanged(KUrl
)),
1832 searchPanel
, SLOT(setUrl(KUrl
)));
1835 if (DolphinSettings::instance().generalSettings()->version() < 200) {
1837 foldersDock
->hide();
1839 terminalDock
->hide();
1847 DolphinDockWidget
* placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
1848 placesDock
->setLocked(lock
);
1849 placesDock
->setObjectName("placesDock");
1850 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1852 PlacesPanel
* placesPanel
= new PlacesPanel(placesDock
);
1853 QAction
* separator
= new QAction(placesPanel
);
1854 separator
->setSeparator(true);
1855 QList
<QAction
*> placesActions
;
1856 placesActions
.append(separator
);
1857 placesActions
.append(lockLayoutAction
);
1858 placesPanel
->addActions(placesActions
);
1859 placesPanel
->setModel(DolphinSettings::instance().placesModel());
1860 placesPanel
->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff
);
1861 placesDock
->setWidget(placesPanel
);
1863 QAction
* placesAction
= placesDock
->toggleViewAction();
1864 createPanelAction(KIcon("bookmarks"), Qt::Key_F9
, placesAction
, "show_places_panel");
1866 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1867 connect(placesPanel
, SIGNAL(urlChanged(KUrl
,Qt::MouseButtons
)),
1868 this, SLOT(handlePlacesClick(KUrl
,Qt::MouseButtons
)));
1869 connect(this, SIGNAL(urlChanged(KUrl
)),
1870 placesPanel
, SLOT(setUrl(KUrl
)));
1871 connect(placesDock
, SIGNAL(visibilityChanged(bool)),
1872 this, SLOT(slotPlacesPanelVisibilityChanged(bool)));
1874 // Add actions into the "Panels" menu
1875 KActionMenu
* panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Panels"), this);
1876 actionCollection()->addAction("panels", panelsMenu
);
1877 panelsMenu
->setDelayed(false);
1878 panelsMenu
->addAction(placesAction
);
1879 panelsMenu
->addAction(infoAction
);
1880 panelsMenu
->addAction(foldersAction
);
1882 panelsMenu
->addAction(terminalAction
);
1885 panelsMenu
->addAction(searchAction
);
1887 panelsMenu
->addSeparator();
1888 panelsMenu
->addAction(lockLayoutAction
);
1891 void DolphinMainWindow::updateEditActions()
1893 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1894 if (list
.isEmpty()) {
1895 stateChanged("has_no_selection");
1897 stateChanged("has_selection");
1899 KActionCollection
* col
= actionCollection();
1900 QAction
* renameAction
= col
->action("rename");
1901 QAction
* moveToTrashAction
= col
->action("move_to_trash");
1902 QAction
* deleteAction
= col
->action("delete");
1903 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
1904 QAction
* deleteWithTrashShortcut
= col
->action("delete_shortcut"); // see DolphinViewActionHandler
1906 KFileItemListProperties
capabilities(list
);
1907 const bool enableMoveToTrash
= capabilities
.isLocal() && capabilities
.supportsMoving();
1909 renameAction
->setEnabled(capabilities
.supportsMoving());
1910 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1911 deleteAction
->setEnabled(capabilities
.supportsDeleting());
1912 deleteWithTrashShortcut
->setEnabled(capabilities
.supportsDeleting() && !enableMoveToTrash
);
1913 cutAction
->setEnabled(capabilities
.supportsMoving());
1915 updatePasteAction();
1918 void DolphinMainWindow::updateViewActions()
1920 m_actionHandler
->updateViewActions();
1922 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1923 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
1925 updateSplitAction();
1927 QAction
* editableLocactionAction
= actionCollection()->action("editable_location");
1928 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
1929 editableLocactionAction
->setChecked(urlNavigator
->isUrlEditable());
1932 void DolphinMainWindow::updateGoActions()
1934 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
1935 const KUrl currentUrl
= m_activeViewContainer
->url();
1936 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
1939 void DolphinMainWindow::createToolBarMenuButton()
1941 if (m_toolBarSpacer
&& m_openToolBarMenuButton
) {
1944 Q_ASSERT(!m_toolBarSpacer
);
1945 Q_ASSERT(!m_openToolBarMenuButton
);
1947 m_toolBarSpacer
= new QWidget(this);
1948 m_toolBarSpacer
->setSizePolicy(QSizePolicy::MinimumExpanding
, QSizePolicy::MinimumExpanding
);
1950 m_openToolBarMenuButton
= new QToolButton(this);
1951 m_openToolBarMenuButton
->setIcon(KIcon("configure"));
1952 m_openToolBarMenuButton
->setPopupMode(QToolButton::InstantPopup
);
1953 m_openToolBarMenuButton
->setToolTip(i18nc("@info:tooltip", "Configure and control Dolphin"));
1955 KMenu
* toolBarMenu
= new ToolBarMenu(m_openToolBarMenuButton
);
1956 connect(toolBarMenu
, SIGNAL(aboutToShow()), this, SLOT(updateToolBarMenu()));
1958 m_openToolBarMenuButton
->setMenu(toolBarMenu
);
1960 toolBar()->addWidget(m_toolBarSpacer
);
1961 toolBar()->addWidget(m_openToolBarMenuButton
);
1962 connect(toolBar(), SIGNAL(iconSizeChanged(QSize
)), this, SLOT(slotToolBarIconSizeChanged(QSize
)));
1964 // The added widgets are owned by the toolbar and may get deleted when e.g. the toolbar
1965 // gets edited. In this case we must add them again. The adding is done asynchronously by
1966 // m_updateToolBarTimer.
1967 connect(m_toolBarSpacer
, SIGNAL(destroyed()), this, SLOT(slotToolBarSpacerDeleted()));
1968 connect(m_openToolBarMenuButton
, SIGNAL(destroyed()), this, SLOT(slotToolBarMenuButtonDeleted()));
1969 m_updateToolBarTimer
= new QTimer(this);
1970 m_updateToolBarTimer
->setInterval(500);
1971 connect(m_updateToolBarTimer
, SIGNAL(timeout()), this, SLOT(updateToolBar()));
1974 void DolphinMainWindow::deleteToolBarMenuButton()
1976 delete m_toolBarSpacer
;
1977 m_toolBarSpacer
= 0;
1979 delete m_openToolBarMenuButton
;
1980 m_openToolBarMenuButton
= 0;
1982 delete m_updateToolBarTimer
;
1983 m_updateToolBarTimer
= 0;
1986 bool DolphinMainWindow::addActionToMenu(QAction
* action
, KMenu
* menu
)
1991 const KToolBar
* toolBarWidget
= toolBar();
1992 foreach (const QWidget
* widget
, action
->associatedWidgets()) {
1993 if (widget
== toolBarWidget
) {
1998 menu
->addAction(action
);
2002 void DolphinMainWindow::rememberClosedTab(int index
)
2004 KMenu
* tabsMenu
= m_recentTabsMenu
->menu();
2006 const QString primaryPath
= m_viewTab
[index
].primaryView
->url().path();
2007 const QString iconName
= KMimeType::iconNameForUrl(primaryPath
);
2009 QAction
* action
= new QAction(squeezedText(primaryPath
), tabsMenu
);
2011 ClosedTab closedTab
;
2012 closedTab
.primaryUrl
= m_viewTab
[index
].primaryView
->url();
2014 if (m_viewTab
[index
].secondaryView
) {
2015 closedTab
.secondaryUrl
= m_viewTab
[index
].secondaryView
->url();
2016 closedTab
.isSplit
= true;
2018 closedTab
.isSplit
= false;
2021 action
->setData(QVariant::fromValue(closedTab
));
2022 action
->setIcon(KIcon(iconName
));
2024 // add the closed tab menu entry after the separator and
2025 // "Empty Recently Closed Tabs" entry
2026 if (tabsMenu
->actions().size() == 2) {
2027 tabsMenu
->addAction(action
);
2029 tabsMenu
->insertAction(tabsMenu
->actions().at(2), action
);
2032 // assure that only up to 8 closed tabs are shown in the menu
2033 if (tabsMenu
->actions().size() > 8) {
2034 tabsMenu
->removeAction(tabsMenu
->actions().last());
2036 actionCollection()->action("closed_tabs")->setEnabled(true);
2037 KAcceleratorManager::manage(tabsMenu
);
2040 void DolphinMainWindow::refreshViews()
2042 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
2044 // remember the current active view, as because of
2045 // the refreshing the active view might change to
2046 // the secondary view
2047 DolphinViewContainer
* activeViewContainer
= m_activeViewContainer
;
2049 const int tabCount
= m_viewTab
.count();
2050 for (int i
= 0; i
< tabCount
; ++i
) {
2051 m_viewTab
[i
].primaryView
->refresh();
2052 if (m_viewTab
[i
].secondaryView
) {
2053 m_viewTab
[i
].secondaryView
->refresh();
2057 setActiveViewContainer(activeViewContainer
);
2059 const GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
2060 if (generalSettings
->modifiedStartupSettings()) {
2061 // The startup settings have been changed by the user (see bug #254947).
2062 // Synchronize the split-view setting with the active view:
2063 const bool splitView
= generalSettings
->splitView();
2064 const ViewTab
& activeTab
= m_viewTab
[m_tabIndex
];
2065 const bool toggle
= ( splitView
&& !activeTab
.secondaryView
)
2066 || (!splitView
&& activeTab
.secondaryView
);
2073 void DolphinMainWindow::clearStatusBar()
2075 m_activeViewContainer
->statusBar()->clear();
2078 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
2080 connect(container
, SIGNAL(showFilterBarChanged(bool)),
2081 this, SLOT(updateFilterBarAction(bool)));
2082 connect(container
, SIGNAL(writeStateChanged(bool)),
2083 this, SLOT(slotWriteStateChanged(bool)));
2084 connect(container
, SIGNAL(searchModeChanged(bool)),
2085 this, SLOT(slotSearchModeChanged(bool)));
2087 const DolphinSearchBox
* searchBox
= container
->searchBox();
2088 connect(searchBox
, SIGNAL(searchLocationChanged(SearchLocation
)),
2089 this, SLOT(slotSearchLocationChanged()));
2091 DolphinView
* view
= container
->view();
2092 connect(view
, SIGNAL(selectionChanged(KFileItemList
)),
2093 this, SLOT(slotSelectionChanged(KFileItemList
)));
2094 connect(view
, SIGNAL(requestItemInfo(KFileItem
)),
2095 this, SLOT(slotRequestItemInfo(KFileItem
)));
2096 connect(view
, SIGNAL(activated()),
2097 this, SLOT(toggleActiveView()));
2098 connect(view
, SIGNAL(tabRequested(KUrl
)),
2099 this, SLOT(openNewTab(KUrl
)));
2100 connect(view
, SIGNAL(requestContextMenu(QPoint
,KFileItem
,KUrl
,QList
<QAction
*>)),
2101 this, SLOT(openContextMenu(QPoint
,KFileItem
,KUrl
,QList
<QAction
*>)));
2102 connect(view
, SIGNAL(startedPathLoading(KUrl
)),
2103 this, SLOT(enableStopAction()));
2104 connect(view
, SIGNAL(finishedPathLoading(KUrl
)),
2105 this, SLOT(disableStopAction()));
2107 const KUrlNavigator
* navigator
= container
->urlNavigator();
2108 connect(navigator
, SIGNAL(urlChanged(KUrl
)),
2109 this, SLOT(changeUrl(KUrl
)));
2110 connect(navigator
, SIGNAL(historyChanged()),
2111 this, SLOT(updateHistory()));
2112 connect(navigator
, SIGNAL(editableStateChanged(bool)),
2113 this, SLOT(slotEditableStateChanged(bool)));
2114 connect(navigator
, SIGNAL(tabRequested(KUrl
)),
2115 this, SLOT(openNewTab(KUrl
)));
2118 void DolphinMainWindow::updateSplitAction()
2120 QAction
* splitAction
= actionCollection()->action("split_view");
2121 if (m_viewTab
[m_tabIndex
].secondaryView
) {
2122 if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
2123 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
2124 splitAction
->setToolTip(i18nc("@info", "Close right view"));
2125 splitAction
->setIcon(KIcon("view-right-close"));
2127 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
2128 splitAction
->setToolTip(i18nc("@info", "Close left view"));
2129 splitAction
->setIcon(KIcon("view-left-close"));
2132 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
2133 splitAction
->setToolTip(i18nc("@info", "Split view"));
2134 splitAction
->setIcon(KIcon("view-right-new"));
2138 QString
DolphinMainWindow::tabName(const KUrl
& url
) const
2141 if (url
.equals(KUrl("file:///"))) {
2144 name
= url
.fileName();
2145 if (name
.isEmpty()) {
2146 name
= url
.protocol();
2148 // Make sure that a '&' inside the directory name is displayed correctly
2149 // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
2150 name
.replace('&', "&&");
2156 bool DolphinMainWindow::isKompareInstalled() const
2158 static bool initialized
= false;
2159 static bool installed
= false;
2161 // TODO: maybe replace this approach later by using a menu
2162 // plugin like kdiff3plugin.cpp
2163 installed
= !KGlobal::dirs()->findExe("kompare").isEmpty();
2169 void DolphinMainWindow::createSecondaryView(int tabIndex
)
2171 QSplitter
* splitter
= m_viewTab
[tabIndex
].splitter
;
2172 const int newWidth
= (m_viewTab
[tabIndex
].primaryView
->width() - splitter
->handleWidth()) / 2;
2174 const DolphinView
* view
= m_viewTab
[tabIndex
].primaryView
->view();
2175 m_viewTab
[tabIndex
].secondaryView
= createViewContainer(view
->url(), 0);
2176 splitter
->addWidget(m_viewTab
[tabIndex
].secondaryView
);
2177 splitter
->setSizes(QList
<int>() << newWidth
<< newWidth
);
2178 connectViewSignals(m_viewTab
[tabIndex
].secondaryView
);
2179 m_viewTab
[tabIndex
].secondaryView
->setActive(false);
2180 m_viewTab
[tabIndex
].secondaryView
->show();
2183 QString
DolphinMainWindow::tabProperty(const QString
& property
, int tabIndex
) const
2185 return "Tab " + QString::number(tabIndex
) + ' ' + property
;
2188 void DolphinMainWindow::setUrlAsCaption(const KUrl
& url
)
2191 if (!url
.isLocalFile()) {
2192 caption
.append(url
.protocol() + " - ");
2193 if (url
.hasHost()) {
2194 caption
.append(url
.host() + " - ");
2198 const QString fileName
= url
.fileName().isEmpty() ? "/" : url
.fileName();
2199 caption
.append(fileName
);
2201 setCaption(caption
);
2204 QString
DolphinMainWindow::squeezedText(const QString
& text
) const
2206 const QFontMetrics fm
= fontMetrics();
2207 return fm
.elidedText(text
, Qt::ElideMiddle
, fm
.maxWidth() * 10);
2210 void DolphinMainWindow::createPanelAction(const KIcon
& icon
,
2211 const QKeySequence
& shortcut
,
2212 QAction
* dockAction
,
2213 const QString
& actionName
)
2215 KAction
* panelAction
= actionCollection()->addAction(actionName
);
2216 panelAction
->setText(dockAction
->text());
2217 panelAction
->setIcon(icon
);
2218 panelAction
->setShortcut(shortcut
);
2220 dockAction
->setIcon(icon
);
2221 connect(panelAction
, SIGNAL(triggered()), dockAction
, SLOT(trigger()));
2224 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
2225 KIO::FileUndoManager::UiInterface()
2229 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2233 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
2235 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
2237 DolphinStatusBar
* statusBar
= mainWin
->activeViewContainer()->statusBar();
2238 statusBar
->setMessage(job
->errorString(), DolphinStatusBar::Error
);
2240 KIO::FileUndoManager::UiInterface::jobError(job
);
2244 ToolBarMenu::ToolBarMenu(QWidget
* parent
) :
2249 ToolBarMenu::~ToolBarMenu()
2253 void ToolBarMenu::showEvent(QShowEvent
* event
)
2255 KMenu::showEvent(event
);
2257 // Adjust the position of the menu to be shown within the
2258 // Dolphin window to reduce the cases that sub-menus might overlap
2259 // the right screen border.
2261 QWidget
* button
= parentWidget();
2262 if (layoutDirection() == Qt::RightToLeft
) {
2263 pos
= button
->mapToGlobal(QPoint(0, button
->height()));
2265 pos
= button
->mapToGlobal(QPoint(button
->width(), button
->height()));
2266 pos
.rx() -= width();
2269 // Assure that the menu is not shown outside the screen boundaries and
2270 // that it does not overlap with the parent button.
2271 const QRect screen
= QApplication::desktop()->screenGeometry(QCursor::pos());
2272 if (pos
.x() < screen
.x()) {
2273 pos
.rx() = screen
.x();
2274 } else if (pos
.x() + width() > screen
.x() + screen
.width()) {
2275 pos
.rx() = screen
.x() + screen
.width() - width();
2278 if (pos
.y() < screen
.y()) {
2279 pos
.ry() = screen
.y();
2280 } else if (pos
.y() + height() > screen
.y() + screen
.height()) {
2281 pos
.ry() = button
->mapToGlobal(QPoint(0, 0)).y() - height();
2287 #include "dolphinmainwindow.moc"