1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz19@gmail.com> *
3 * Copyright (C) 2006 by Stefan Monov <logixoul@gmail.com> *
4 * Copyright (C) 2006 by Cvetoslav Ludmiloff <ludmiloff@gmail.com> *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20 ***************************************************************************/
22 #include "dolphinmainwindow.h"
24 #include "dolphinapplication.h"
25 #include "dolphindockwidget.h"
26 #include "dolphincontextmenu.h"
27 #include "dolphinnewfilemenu.h"
28 #include "dolphinviewcontainer.h"
29 #include "panels/folders/folderspanel.h"
30 #include "panels/places/placespanel.h"
31 #include "panels/information/informationpanel.h"
32 #include "settings/dolphinsettingsdialog.h"
33 #include "statusbar/dolphinstatusbar.h"
34 #include "views/dolphinviewactionhandler.h"
35 #include "views/dolphinremoteencoding.h"
36 #include "views/draganddrophelper.h"
37 #include "views/viewproperties.h"
40 #include "panels/terminal/terminalpanel.h"
43 #include "dolphin_generalsettings.h"
45 #include <KAcceleratorManager>
47 #include <KActionCollection>
48 #include <KActionMenu>
50 #include <KDesktopFile>
51 #include <kdeversion.h>
52 #include <kdualaction.h>
53 #include <KFileDialog>
54 #include <KFilePlacesModel>
59 #include <KIconLoader>
60 #include <KIO/NetAccess>
61 #include <KIO/JobUiDelegate>
62 #include <KInputDialog>
64 #include <KProtocolManager>
67 #include <KMessageBox>
68 #include <KFileItemListProperties>
69 #include <konqmimedata.h>
70 #include <KProtocolInfo>
73 #include <KStandardDirs>
74 #include <kstatusbar.h>
75 #include <KStandardAction>
77 #include <KToggleAction>
78 #include <KUrlNavigator>
80 #include <KUrlComboBox>
81 #include <KToolInvocation>
83 #include <QDesktopWidget>
84 #include <QDBusMessage>
87 #include <QToolButton>
91 // Used for GeneralSettings::version() to determine whether
92 // an updated version of Dolphin is running.
93 const int CurrentDolphinVersion
= 200;
97 * Remembers the tab configuration if a tab has been closed.
98 * Each closed tab can be restored by the menu
99 * "Go -> Recently Closed Tabs".
107 Q_DECLARE_METATYPE(ClosedTab
)
109 DolphinMainWindow::DolphinMainWindow() :
113 m_activeViewContainer(0),
114 m_centralWidgetLayout(0),
121 m_updateToolBarTimer(0),
122 m_lastHandleUrlStatJob(0)
124 // Workaround for a X11-issue in combination with KModifierInfo
125 // (see DolphinContextMenu::initializeModifierKeyInfo() for
126 // more information):
127 DolphinContextMenu::initializeModifierKeyInfo();
129 setObjectName("Dolphin#");
131 m_viewTab
.append(ViewTab());
132 ViewTab
& viewTab
= m_viewTab
[m_tabIndex
];
133 viewTab
.wasActive
= true; // The first opened tab is automatically active
135 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
136 undoManager
->setUiInterface(new UndoUiInterface());
138 connect(undoManager
, SIGNAL(undoAvailable(bool)),
139 this, SLOT(slotUndoAvailable(bool)));
140 connect(undoManager
, SIGNAL(undoTextChanged(QString
)),
141 this, SLOT(slotUndoTextChanged(QString
)));
142 connect(undoManager
, SIGNAL(jobRecordingStarted(CommandType
)),
143 this, SLOT(clearStatusBar()));
144 connect(undoManager
, SIGNAL(jobRecordingFinished(CommandType
)),
145 this, SLOT(showCommand(CommandType
)));
147 GeneralSettings
* generalSettings
= GeneralSettings::self();
148 const bool firstRun
= (generalSettings
->version() < 200);
150 generalSettings
->setViewPropsTimestamp(QDateTime::currentDateTime());
153 setAcceptDrops(true);
155 viewTab
.splitter
= new QSplitter(this);
156 viewTab
.splitter
->setChildrenCollapsible(false);
160 const KUrl
homeUrl(generalSettings
->homeUrl());
161 setUrlAsCaption(homeUrl
);
162 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
163 connect(m_actionHandler
, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
164 connect(m_actionHandler
, SIGNAL(createDirectory()), SLOT(createDirectory()));
166 viewTab
.primaryView
= createViewContainer(homeUrl
, viewTab
.splitter
);
168 m_activeViewContainer
= viewTab
.primaryView
;
169 connectViewSignals(m_activeViewContainer
);
170 DolphinView
* view
= m_activeViewContainer
->view();
171 m_activeViewContainer
->show();
172 m_actionHandler
->setCurrentView(view
);
174 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
175 connect(this, SIGNAL(urlChanged(KUrl
)),
176 m_remoteEncoding
, SLOT(slotAboutToOpenUrl()));
178 m_tabBar
= new KTabBar(this);
179 m_tabBar
->setMovable(true);
180 m_tabBar
->setTabsClosable(true);
181 connect(m_tabBar
, SIGNAL(currentChanged(int)),
182 this, SLOT(setActiveTab(int)));
183 connect(m_tabBar
, SIGNAL(tabCloseRequested(int)),
184 this, SLOT(closeTab(int)));
185 connect(m_tabBar
, SIGNAL(contextMenu(int,QPoint
)),
186 this, SLOT(openTabContextMenu(int,QPoint
)));
187 connect(m_tabBar
, SIGNAL(newTabRequest()),
188 this, SLOT(openNewTab()));
189 connect(m_tabBar
, SIGNAL(testCanDecode(const QDragMoveEvent
*,bool&)),
190 this, SLOT(slotTestCanDecode(const QDragMoveEvent
*,bool&)));
191 connect(m_tabBar
, SIGNAL(mouseMiddleClick(int)),
192 this, SLOT(closeTab(int)));
193 connect(m_tabBar
, SIGNAL(tabMoved(int,int)),
194 this, SLOT(slotTabMoved(int,int)));
195 connect(m_tabBar
, SIGNAL(receivedDropEvent(int,QDropEvent
*)),
196 this, SLOT(tabDropEvent(int,QDropEvent
*)));
198 m_tabBar
->blockSignals(true); // signals get unblocked after at least 2 tabs are open
200 QWidget
* centralWidget
= new QWidget(this);
201 m_centralWidgetLayout
= new QVBoxLayout(centralWidget
);
202 m_centralWidgetLayout
->setSpacing(0);
203 m_centralWidgetLayout
->setMargin(0);
204 m_centralWidgetLayout
->addWidget(m_tabBar
);
205 m_centralWidgetLayout
->addWidget(viewTab
.splitter
, 1);
207 setCentralWidget(centralWidget
);
209 emit
urlChanged(homeUrl
);
211 setupGUI(Keys
| Save
| Create
| ToolBar
);
212 stateChanged("new_file");
214 QClipboard
* clipboard
= QApplication::clipboard();
215 connect(clipboard
, SIGNAL(dataChanged()),
216 this, SLOT(updatePasteAction()));
218 if (generalSettings
->splitView()) {
225 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
226 showFilterBarAction
->setChecked(generalSettings
->filterBar());
229 menuBar()->setVisible(false);
230 // Assure a proper default size if Dolphin runs the first time
234 const bool showMenu
= !menuBar()->isHidden();
235 QAction
* showMenuBarAction
= actionCollection()->action(KStandardAction::name(KStandardAction::ShowMenubar
));
236 showMenuBarAction
->setChecked(showMenu
); // workaround for bug #171080
238 createControlButton();
242 DolphinMainWindow::~DolphinMainWindow()
246 void DolphinMainWindow::openDirectories(const QList
<KUrl
>& dirs
)
248 if (dirs
.isEmpty()) {
252 if (dirs
.count() == 1) {
253 m_activeViewContainer
->setUrl(dirs
.first());
257 const int oldOpenTabsCount
= m_viewTab
.count();
259 const bool hasSplitView
= GeneralSettings::splitView();
261 // Open each directory inside a new tab. If the "split view" option has been enabled,
262 // always show two directories within one tab.
263 QList
<KUrl
>::const_iterator it
= dirs
.begin();
264 while (it
!= dirs
.end()) {
268 if (hasSplitView
&& (it
!= dirs
.end())) {
269 const int tabIndex
= m_viewTab
.count() - 1;
270 m_viewTab
[tabIndex
].secondaryView
->setUrl(*it
);
275 // Remove the previously opened tabs
276 for (int i
= 0; i
< oldOpenTabsCount
; ++i
) {
281 void DolphinMainWindow::openFiles(const QList
<KUrl
>& files
)
283 if (files
.isEmpty()) {
287 // Get all distinct directories from 'files' and open a tab
288 // for each directory. If the "split view" option is enabled, two
289 // directories are shown inside one tab (see openDirectories()).
291 foreach (const KUrl
& url
, files
) {
292 const KUrl
dir(url
.directory());
293 if (!dirs
.contains(dir
)) {
298 openDirectories(dirs
);
300 // Select the files. Although the files can be split between several
301 // tabs, there is no need to split 'files' accordingly, as
302 // the DolphinView will just ignore invalid selections.
303 const int tabCount
= m_viewTab
.count();
304 for (int i
= 0; i
< tabCount
; ++i
) {
305 m_viewTab
[i
].primaryView
->view()->markUrlsAsSelected(files
);
306 m_viewTab
[i
].primaryView
->view()->markUrlAsCurrent(files
.at(0));
307 if (m_viewTab
[i
].secondaryView
) {
308 m_viewTab
[i
].secondaryView
->view()->markUrlsAsSelected(files
);
309 m_viewTab
[i
].secondaryView
->view()->markUrlAsCurrent(files
.at(0));
314 void DolphinMainWindow::showCommand(CommandType command
)
316 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
318 case KIO::FileUndoManager::Copy
:
319 statusBar
->setText(i18nc("@info:status", "Successfully copied."));
321 case KIO::FileUndoManager::Move
:
322 statusBar
->setText(i18nc("@info:status", "Successfully moved."));
324 case KIO::FileUndoManager::Link
:
325 statusBar
->setText(i18nc("@info:status", "Successfully linked."));
327 case KIO::FileUndoManager::Trash
:
328 statusBar
->setText(i18nc("@info:status", "Successfully moved to trash."));
330 case KIO::FileUndoManager::Rename
:
331 statusBar
->setText(i18nc("@info:status", "Successfully renamed."));
334 case KIO::FileUndoManager::Mkdir
:
335 statusBar
->setText(i18nc("@info:status", "Created folder."));
343 void DolphinMainWindow::pasteIntoFolder()
345 m_activeViewContainer
->view()->pasteIntoFolder();
348 void DolphinMainWindow::changeUrl(const KUrl
& url
)
350 if (!KProtocolManager::supportsListing(url
)) {
351 // The URL navigator only checks for validity, not
352 // if the URL can be listed. An error message is
353 // shown due to DolphinViewContainer::restoreView().
357 DolphinViewContainer
* view
= activeViewContainer();
363 setUrlAsCaption(url
);
364 if (m_viewTab
.count() > 1) {
365 m_tabBar
->setTabText(m_tabIndex
, squeezedText(tabName(m_activeViewContainer
->url())));
367 const QString iconName
= KMimeType::iconNameForUrl(url
);
368 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(iconName
));
369 emit
urlChanged(url
);
373 void DolphinMainWindow::slotTerminalDirectoryChanged(const KUrl
& url
)
375 m_activeViewContainer
->setAutoGrabFocus(false);
377 m_activeViewContainer
->setAutoGrabFocus(true);
380 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
382 KToggleAction
* editableLocationAction
=
383 static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
384 editableLocationAction
->setChecked(editable
);
387 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
391 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
392 int selectedUrlsCount
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedItemsCount();
393 if (m_viewTab
[m_tabIndex
].secondaryView
) {
394 selectedUrlsCount
+= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItemsCount();
397 QAction
* compareFilesAction
= actionCollection()->action("compare_files");
398 if (selectedUrlsCount
== 2) {
399 compareFilesAction
->setEnabled(isKompareInstalled());
401 compareFilesAction
->setEnabled(false);
404 emit
selectionChanged(selection
);
407 void DolphinMainWindow::slotRequestItemInfo(const KFileItem
& item
)
409 emit
requestItemInfo(item
);
412 void DolphinMainWindow::updateHistory()
414 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
415 const int index
= urlNavigator
->historyIndex();
417 QAction
* backAction
= actionCollection()->action("go_back");
419 backAction
->setToolTip(i18nc("@info", "Go back"));
420 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
423 QAction
* forwardAction
= actionCollection()->action("go_forward");
425 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
426 forwardAction
->setEnabled(index
> 0);
430 void DolphinMainWindow::updateFilterBarAction(bool show
)
432 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
433 showFilterBarAction
->setChecked(show
);
436 void DolphinMainWindow::openNewMainWindow()
438 KRun::run("dolphin", KUrl::List(), this);
441 void DolphinMainWindow::openNewTab()
443 const bool isUrlEditable
= m_activeViewContainer
->urlNavigator()->isUrlEditable();
445 openNewTab(m_activeViewContainer
->url());
446 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
448 // The URL navigator of the new tab should have the same editable state
449 // as the current tab
450 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
451 navigator
->setUrlEditable(isUrlEditable
);
454 // If a new tab is opened and the URL is editable, assure that
455 // the user can edit the URL without manually setting the focus
456 navigator
->setFocus();
460 void DolphinMainWindow::openNewTab(const KUrl
& url
)
462 QWidget
* focusWidget
= QApplication::focusWidget();
464 if (m_viewTab
.count() == 1) {
465 // Only one view is open currently and hence no tab is shown at
466 // all. Before creating a tab for 'url', provide a tab for the current URL.
467 const KUrl currentUrl
= m_activeViewContainer
->url();
468 m_tabBar
->addTab(KIcon(KMimeType::iconNameForUrl(currentUrl
)),
469 squeezedText(tabName(currentUrl
)));
470 m_tabBar
->blockSignals(false);
473 m_tabBar
->addTab(KIcon(KMimeType::iconNameForUrl(url
)),
474 squeezedText(tabName(url
)));
477 viewTab
.splitter
= new QSplitter(this);
478 viewTab
.splitter
->setChildrenCollapsible(false);
479 viewTab
.primaryView
= createViewContainer(url
, viewTab
.splitter
);
480 viewTab
.primaryView
->setActive(false);
481 connectViewSignals(viewTab
.primaryView
);
483 m_viewTab
.append(viewTab
);
485 actionCollection()->action("close_tab")->setEnabled(true);
487 // Provide a split view, if the startup settings are set this way
488 if (GeneralSettings::splitView()) {
489 const int newTabIndex
= m_viewTab
.count() - 1;
490 createSecondaryView(newTabIndex
);
491 m_viewTab
[newTabIndex
].secondaryView
->setActive(true);
492 m_viewTab
[newTabIndex
].isPrimaryViewActive
= false;
496 // The DolphinViewContainer grabbed the keyboard focus. As the tab is opened
497 // in background, assure that the previous focused widget gets the focus back.
498 focusWidget
->setFocus();
502 void DolphinMainWindow::openNewActivatedTab(const KUrl
& url
)
505 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
508 void DolphinMainWindow::activateNextTab()
510 if (m_viewTab
.count() >= 2) {
511 const int tabIndex
= (m_tabBar
->currentIndex() + 1) % m_tabBar
->count();
512 m_tabBar
->setCurrentIndex(tabIndex
);
516 void DolphinMainWindow::activatePrevTab()
518 if (m_viewTab
.count() >= 2) {
519 int tabIndex
= m_tabBar
->currentIndex() - 1;
520 if (tabIndex
== -1) {
521 tabIndex
= m_tabBar
->count() - 1;
523 m_tabBar
->setCurrentIndex(tabIndex
);
527 void DolphinMainWindow::openInNewTab()
529 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
530 if (list
.isEmpty()) {
531 openNewTab(m_activeViewContainer
->url());
532 } else if ((list
.count() == 1) && list
[0].isDir()) {
533 openNewTab(list
[0].url());
537 void DolphinMainWindow::openInNewWindow()
541 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
542 if (list
.isEmpty()) {
543 newWindowUrl
= m_activeViewContainer
->url();
544 } else if ((list
.count() == 1) && list
[0].isDir()) {
545 newWindowUrl
= list
[0].url();
548 if (!newWindowUrl
.isEmpty()) {
549 KRun::run("dolphin", KUrl::List() << newWindowUrl
, this);
553 void DolphinMainWindow::toggleActiveView()
555 if (!m_viewTab
[m_tabIndex
].secondaryView
) {
556 // only one view is available
560 Q_ASSERT(m_activeViewContainer
);
561 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
563 DolphinViewContainer
* left
= m_viewTab
[m_tabIndex
].primaryView
;
564 DolphinViewContainer
* right
= m_viewTab
[m_tabIndex
].secondaryView
;
565 setActiveViewContainer(m_activeViewContainer
== right
? left
: right
);
568 void DolphinMainWindow::showEvent(QShowEvent
* event
)
570 KXmlGuiWindow::showEvent(event
);
571 if (!event
->spontaneous()) {
572 m_activeViewContainer
->view()->setFocus();
576 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
578 // Find out if Dolphin is closed directly by the user or
579 // by the session manager because the session is closed
580 bool closedByUser
= true;
581 DolphinApplication
*application
= qobject_cast
<DolphinApplication
*>(qApp
);
582 if (application
&& application
->sessionSaving()) {
583 closedByUser
= false;
586 if (m_viewTab
.count() > 1 && GeneralSettings::confirmClosingMultipleTabs() && closedByUser
) {
587 // Ask the user if he really wants to quit and close all tabs.
588 // Open a confirmation dialog with 3 buttons:
589 // KDialog::Yes -> Quit
590 // KDialog::No -> Close only the current tab
591 // KDialog::Cancel -> do nothing
592 KDialog
*dialog
= new KDialog(this, Qt::Dialog
);
593 dialog
->setCaption(i18nc("@title:window", "Confirmation"));
594 dialog
->setButtons(KDialog::Yes
| KDialog::No
| KDialog::Cancel
);
595 dialog
->setModal(true);
596 dialog
->setButtonGuiItem(KDialog::Yes
, KStandardGuiItem::quit());
597 dialog
->setButtonGuiItem(KDialog::No
, KGuiItem(i18n("C&lose Current Tab"), KIcon("tab-close")));
598 dialog
->setButtonGuiItem(KDialog::Cancel
, KStandardGuiItem::cancel());
599 dialog
->setDefaultButton(KDialog::Yes
);
601 bool doNotAskAgainCheckboxResult
= false;
603 const int result
= KMessageBox::createKMessageBox(dialog
,
604 QMessageBox::Warning
,
605 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
607 i18n("Do not ask again"),
608 &doNotAskAgainCheckboxResult
,
609 KMessageBox::Notify
);
611 if (doNotAskAgainCheckboxResult
) {
612 GeneralSettings::setConfirmClosingMultipleTabs(false);
620 // Close only the current tab
628 GeneralSettings::setVersion(CurrentDolphinVersion
);
629 GeneralSettings::self()->writeConfig();
631 KXmlGuiWindow::closeEvent(event
);
634 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
636 const int tabCount
= m_viewTab
.count();
637 group
.writeEntry("Tab Count", tabCount
);
638 group
.writeEntry("Active Tab Index", m_tabBar
->currentIndex());
640 for (int i
= 0; i
< tabCount
; ++i
) {
641 const DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
642 group
.writeEntry(tabProperty("Primary URL", i
), cont
->url().url());
643 group
.writeEntry(tabProperty("Primary Editable", i
),
644 cont
->urlNavigator()->isUrlEditable());
646 cont
= m_viewTab
[i
].secondaryView
;
648 group
.writeEntry(tabProperty("Secondary URL", i
), cont
->url().url());
649 group
.writeEntry(tabProperty("Secondary Editable", i
),
650 cont
->urlNavigator()->isUrlEditable());
655 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
657 const int tabCount
= group
.readEntry("Tab Count", 1);
658 for (int i
= 0; i
< tabCount
; ++i
) {
659 DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
661 cont
->setUrl(group
.readEntry(tabProperty("Primary URL", i
)));
662 const bool editable
= group
.readEntry(tabProperty("Primary Editable", i
), false);
663 cont
->urlNavigator()->setUrlEditable(editable
);
665 cont
= m_viewTab
[i
].secondaryView
;
666 const QString secondaryUrl
= group
.readEntry(tabProperty("Secondary URL", i
));
667 if (!secondaryUrl
.isEmpty()) {
669 // a secondary view should be shown, but no one is available
670 // currently -> create a new view
672 cont
= m_viewTab
[i
].secondaryView
;
676 cont
->setUrl(secondaryUrl
);
677 const bool editable
= group
.readEntry(tabProperty("Secondary Editable", i
), false);
678 cont
->urlNavigator()->setUrlEditable(editable
);
680 // no secondary view should be shown, but the default setting shows
681 // one already -> close the view
685 // openNewTab() needs to be called only tabCount - 1 times
686 if (i
!= tabCount
- 1) {
691 const int index
= group
.readEntry("Active Tab Index", 0);
692 m_tabBar
->setCurrentIndex(index
);
695 void DolphinMainWindow::updateNewMenu()
697 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
698 m_newFileMenu
->checkUpToDate();
699 m_newFileMenu
->setPopupFiles(activeViewContainer()->url());
702 void DolphinMainWindow::createDirectory()
704 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
705 m_newFileMenu
->setPopupFiles(activeViewContainer()->url());
706 m_newFileMenu
->createDirectory();
709 void DolphinMainWindow::quit()
714 void DolphinMainWindow::showErrorMessage(const QString
& message
)
716 m_activeViewContainer
->showMessage(message
, DolphinViewContainer::Error
);
719 void DolphinMainWindow::slotUndoAvailable(bool available
)
721 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
723 undoAction
->setEnabled(available
);
727 void DolphinMainWindow::restoreClosedTab(QAction
* action
)
729 if (action
->data().toBool()) {
730 // clear all actions except the "Empty Recently Closed Tabs"
731 // action and the separator
732 QList
<QAction
*> actions
= m_recentTabsMenu
->menu()->actions();
733 const int count
= actions
.size();
734 for (int i
= 2; i
< count
; ++i
) {
735 m_recentTabsMenu
->menu()->removeAction(actions
.at(i
));
738 const ClosedTab closedTab
= action
->data().value
<ClosedTab
>();
739 openNewTab(closedTab
.primaryUrl
);
740 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
742 if (closedTab
.isSplit
) {
743 // create secondary view
745 m_viewTab
[m_tabIndex
].secondaryView
->setUrl(closedTab
.secondaryUrl
);
748 m_recentTabsMenu
->removeAction(action
);
751 if (m_recentTabsMenu
->menu()->actions().count() == 2) {
752 m_recentTabsMenu
->setEnabled(false);
756 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
758 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
760 undoAction
->setText(text
);
764 void DolphinMainWindow::undo()
767 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
768 KIO::FileUndoManager::self()->undo();
771 void DolphinMainWindow::cut()
773 m_activeViewContainer
->view()->cutSelectedItems();
776 void DolphinMainWindow::copy()
778 m_activeViewContainer
->view()->copySelectedItems();
781 void DolphinMainWindow::paste()
783 m_activeViewContainer
->view()->paste();
786 void DolphinMainWindow::find()
788 m_activeViewContainer
->setSearchModeEnabled(true);
791 void DolphinMainWindow::updatePasteAction()
793 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
794 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
795 pasteAction
->setEnabled(pasteInfo
.first
);
796 pasteAction
->setText(pasteInfo
.second
);
799 void DolphinMainWindow::selectAll()
803 // if the URL navigator is editable and focused, select the whole
804 // URL instead of all items of the view
806 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
807 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit(); // krazy:exclude=qclasses
808 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
809 lineEdit
->hasFocus();
811 lineEdit
->selectAll();
813 m_activeViewContainer
->view()->selectAll();
817 void DolphinMainWindow::invertSelection()
820 m_activeViewContainer
->view()->invertSelection();
823 void DolphinMainWindow::toggleSplitView()
825 if (!m_viewTab
[m_tabIndex
].secondaryView
) {
826 createSecondaryView(m_tabIndex
);
827 setActiveViewContainer(m_viewTab
[m_tabIndex
].secondaryView
);
828 } else if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
829 // remove secondary view
830 m_viewTab
[m_tabIndex
].secondaryView
->close();
831 m_viewTab
[m_tabIndex
].secondaryView
->deleteLater();
832 m_viewTab
[m_tabIndex
].secondaryView
= 0;
834 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
836 // The primary view is active and should be closed. Hence from a users point of view
837 // the content of the secondary view should be moved to the primary view.
838 // From an implementation point of view it is more efficient to close
839 // the primary view and exchange the internal pointers afterwards.
841 m_viewTab
[m_tabIndex
].primaryView
->close();
842 m_viewTab
[m_tabIndex
].primaryView
->deleteLater();
843 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
844 m_viewTab
[m_tabIndex
].secondaryView
= 0;
846 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
852 void DolphinMainWindow::reloadView()
855 m_activeViewContainer
->view()->reload();
858 void DolphinMainWindow::stopLoading()
860 m_activeViewContainer
->view()->stopLoading();
863 void DolphinMainWindow::enableStopAction()
865 actionCollection()->action("stop")->setEnabled(true);
868 void DolphinMainWindow::disableStopAction()
870 actionCollection()->action("stop")->setEnabled(false);
873 void DolphinMainWindow::showFilterBar()
875 m_activeViewContainer
->setFilterBarVisible(true);
878 void DolphinMainWindow::toggleEditLocation()
882 QAction
* action
= actionCollection()->action("editable_location");
883 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
884 urlNavigator
->setUrlEditable(action
->isChecked());
887 void DolphinMainWindow::replaceLocation()
889 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
890 navigator
->setUrlEditable(true);
891 navigator
->setFocus();
893 // select the whole text of the combo box editor
894 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit(); // krazy:exclude=qclasses
895 lineEdit
->selectAll();
898 void DolphinMainWindow::togglePanelLockState()
900 const bool newLockState
= !GeneralSettings::lockPanels();
901 foreach (QObject
* child
, children()) {
902 DolphinDockWidget
* dock
= qobject_cast
<DolphinDockWidget
*>(child
);
904 dock
->setLocked(newLockState
);
908 GeneralSettings::setLockPanels(newLockState
);
911 void DolphinMainWindow::slotPlacesPanelVisibilityChanged(bool visible
)
913 const int tabCount
= m_viewTab
.count();
914 for (int i
= 0; i
< tabCount
; ++i
) {
915 ViewTab
& tab
= m_viewTab
[i
];
916 Q_ASSERT(tab
.primaryView
);
917 tab
.primaryView
->urlNavigator()->setPlacesSelectorVisible(!visible
);
918 if (tab
.secondaryView
) {
919 tab
.secondaryView
->urlNavigator()->setPlacesSelectorVisible(!visible
);
924 void DolphinMainWindow::goBack()
926 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
927 urlNavigator
->goBack();
929 if (urlNavigator
->locationState().isEmpty()) {
930 // An empty location state indicates a redirection URL,
931 // which must be skipped too
932 urlNavigator
->goBack();
936 void DolphinMainWindow::goForward()
938 m_activeViewContainer
->urlNavigator()->goForward();
941 void DolphinMainWindow::goUp()
943 m_activeViewContainer
->urlNavigator()->goUp();
946 void DolphinMainWindow::goHome()
948 m_activeViewContainer
->urlNavigator()->goHome();
951 void DolphinMainWindow::goBack(Qt::MouseButtons buttons
)
953 // The default case (left button pressed) is handled in goBack().
954 if (buttons
== Qt::MidButton
) {
955 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
956 const int index
= urlNavigator
->historyIndex() + 1;
957 openNewTab(urlNavigator
->locationUrl(index
));
961 void DolphinMainWindow::goForward(Qt::MouseButtons buttons
)
963 // The default case (left button pressed) is handled in goForward().
964 if (buttons
== Qt::MidButton
) {
965 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
966 const int index
= urlNavigator
->historyIndex() - 1;
967 openNewTab(urlNavigator
->locationUrl(index
));
971 void DolphinMainWindow::goUp(Qt::MouseButtons buttons
)
973 // The default case (left button pressed) is handled in goUp().
974 if (buttons
== Qt::MidButton
) {
975 openNewTab(activeViewContainer()->url().upUrl());
979 void DolphinMainWindow::goHome(Qt::MouseButtons buttons
)
981 // The default case (left button pressed) is handled in goHome().
982 if (buttons
== Qt::MidButton
) {
983 openNewTab(GeneralSettings::self()->homeUrl());
987 void DolphinMainWindow::compareFiles()
989 // The method is only invoked if exactly 2 files have
990 // been selected. The selected files may be:
991 // - both in the primary view
992 // - both in the secondary view
993 // - one in the primary view and the other in the secondary
995 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
1000 KFileItemList items
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedItems();
1002 switch (items
.count()) {
1004 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
);
1005 items
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItems();
1006 Q_ASSERT(items
.count() == 2);
1007 urlA
= items
[0].url();
1008 urlB
= items
[1].url();
1013 urlA
= items
[0].url();
1014 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
);
1015 items
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItems();
1016 Q_ASSERT(items
.count() == 1);
1017 urlB
= items
[0].url();
1022 urlA
= items
[0].url();
1023 urlB
= items
[1].url();
1028 // may not happen: compareFiles may only get invoked if 2
1029 // files are selected
1034 QString
command("kompare -c \"");
1035 command
.append(urlA
.pathOrUrl());
1036 command
.append("\" \"");
1037 command
.append(urlB
.pathOrUrl());
1038 command
.append('\"');
1039 KRun::runCommand(command
, "Kompare", "kompare", this);
1042 void DolphinMainWindow::toggleShowMenuBar()
1044 const bool visible
= menuBar()->isVisible();
1045 menuBar()->setVisible(!visible
);
1047 createControlButton();
1049 deleteControlButton();
1053 void DolphinMainWindow::openTerminal()
1055 QString
dir(QDir::homePath());
1057 // If the given directory is not local, it can still be the URL of an
1058 // ioslave using UDS_LOCAL_PATH which to be converted first.
1059 KUrl url
= KIO::NetAccess::mostLocalUrl(m_activeViewContainer
->url(), this);
1061 //If the URL is local after the above conversion, set the directory.
1062 if (url
.isLocalFile()) {
1063 dir
= url
.toLocalFile();
1066 KToolInvocation::invokeTerminal(QString(), dir
);
1069 void DolphinMainWindow::editSettings()
1071 if (!m_settingsDialog
) {
1072 DolphinViewContainer
* container
= activeViewContainer();
1073 container
->view()->writeSettings();
1075 const KUrl url
= container
->url();
1076 DolphinSettingsDialog
* settingsDialog
= new DolphinSettingsDialog(url
, this);
1077 connect(settingsDialog
, SIGNAL(settingsChanged()), this, SLOT(refreshViews()));
1078 settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1079 settingsDialog
->show();
1080 m_settingsDialog
= settingsDialog
;
1082 m_settingsDialog
.data()->raise();
1086 void DolphinMainWindow::setActiveTab(int index
)
1088 Q_ASSERT(index
>= 0);
1089 Q_ASSERT(index
< m_viewTab
.count());
1090 if (index
== m_tabIndex
) {
1094 // hide current tab content
1095 ViewTab
& hiddenTab
= m_viewTab
[m_tabIndex
];
1096 hiddenTab
.isPrimaryViewActive
= hiddenTab
.primaryView
->isActive();
1097 hiddenTab
.primaryView
->setActive(false);
1098 if (hiddenTab
.secondaryView
) {
1099 hiddenTab
.secondaryView
->setActive(false);
1101 QSplitter
* splitter
= m_viewTab
[m_tabIndex
].splitter
;
1103 m_centralWidgetLayout
->removeWidget(splitter
);
1105 // show active tab content
1108 ViewTab
& viewTab
= m_viewTab
[index
];
1109 m_centralWidgetLayout
->addWidget(viewTab
.splitter
, 1);
1110 viewTab
.primaryView
->show();
1111 if (viewTab
.secondaryView
) {
1112 viewTab
.secondaryView
->show();
1114 viewTab
.splitter
->show();
1116 if (!viewTab
.wasActive
) {
1117 viewTab
.wasActive
= true;
1119 // If the tab has not been activated yet the size of the KItemListView is
1120 // undefined and results in an unwanted animation. To prevent this a
1121 // reloading of the directory gets triggered.
1122 viewTab
.primaryView
->view()->reload();
1123 if (viewTab
.secondaryView
) {
1124 viewTab
.secondaryView
->view()->reload();
1128 setActiveViewContainer(viewTab
.isPrimaryViewActive
? viewTab
.primaryView
:
1129 viewTab
.secondaryView
);
1132 void DolphinMainWindow::closeTab()
1134 closeTab(m_tabBar
->currentIndex());
1137 void DolphinMainWindow::closeTab(int index
)
1139 Q_ASSERT(index
>= 0);
1140 Q_ASSERT(index
< m_viewTab
.count());
1141 if (m_viewTab
.count() == 1) {
1142 // the last tab may never get closed
1146 if (index
== m_tabIndex
) {
1147 // The tab that should be closed is the active tab. Activate the
1148 // previous tab before closing the tab.
1149 m_tabBar
->setCurrentIndex((index
> 0) ? index
- 1 : 1);
1151 rememberClosedTab(index
);
1154 m_viewTab
[index
].primaryView
->deleteLater();
1155 if (m_viewTab
[index
].secondaryView
) {
1156 m_viewTab
[index
].secondaryView
->deleteLater();
1158 m_viewTab
[index
].splitter
->deleteLater();
1159 m_viewTab
.erase(m_viewTab
.begin() + index
);
1161 m_tabBar
->blockSignals(true);
1162 m_tabBar
->removeTab(index
);
1164 if (m_tabIndex
> index
) {
1166 Q_ASSERT(m_tabIndex
>= 0);
1169 // if only one tab is left, also remove the tab entry so that
1170 // closing the last tab is not possible
1171 if (m_viewTab
.count() == 1) {
1172 m_tabBar
->removeTab(0);
1173 actionCollection()->action("close_tab")->setEnabled(false);
1175 m_tabBar
->blockSignals(false);
1179 void DolphinMainWindow::openTabContextMenu(int index
, const QPoint
& pos
)
1183 QAction
* newTabAction
= menu
.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab"));
1184 newTabAction
->setShortcut(actionCollection()->action("new_tab")->shortcut());
1186 QAction
* detachTabAction
= menu
.addAction(KIcon("tab-detach"), i18nc("@action:inmenu", "Detach Tab"));
1188 QAction
* closeOtherTabsAction
= menu
.addAction(KIcon("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs"));
1190 QAction
* closeTabAction
= menu
.addAction(KIcon("tab-close"), i18nc("@action:inmenu", "Close Tab"));
1191 closeTabAction
->setShortcut(actionCollection()->action("close_tab")->shortcut());
1192 QAction
* selectedAction
= menu
.exec(pos
);
1193 if (selectedAction
== newTabAction
) {
1194 const ViewTab
& tab
= m_viewTab
[index
];
1195 Q_ASSERT(tab
.primaryView
);
1196 const KUrl url
= tab
.secondaryView
&& tab
.secondaryView
->isActive() ?
1197 tab
.secondaryView
->url() : tab
.primaryView
->url();
1199 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
1200 } else if (selectedAction
== detachTabAction
) {
1201 const QString
separator(QLatin1Char(' '));
1202 QString command
= QLatin1String("dolphin");
1204 const ViewTab
& tab
= m_viewTab
[index
];
1205 Q_ASSERT(tab
.primaryView
);
1207 command
+= separator
+ tab
.primaryView
->url().url();
1208 if (tab
.secondaryView
) {
1209 command
+= separator
+ tab
.secondaryView
->url().url();
1210 command
+= separator
+ QLatin1String("-split");
1213 KRun::runCommand(command
, this);
1216 } else if (selectedAction
== closeOtherTabsAction
) {
1217 const int count
= m_tabBar
->count();
1218 for (int i
= 0; i
< index
; ++i
) {
1221 for (int i
= index
+ 1; i
< count
; ++i
) {
1224 } else if (selectedAction
== closeTabAction
) {
1229 void DolphinMainWindow::slotTabMoved(int from
, int to
)
1231 m_viewTab
.move(from
, to
);
1232 m_tabIndex
= m_tabBar
->currentIndex();
1235 void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent
* event
, bool& canDecode
)
1237 canDecode
= KUrl::List::canDecode(event
->mimeData());
1240 void DolphinMainWindow::handleUrl(const KUrl
& url
)
1242 delete m_lastHandleUrlStatJob
;
1243 m_lastHandleUrlStatJob
= 0;
1245 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1246 activeViewContainer()->setUrl(url
);
1247 } else if (KProtocolManager::supportsListing(url
)) {
1248 // stat the URL to see if it is a dir or not
1249 m_lastHandleUrlStatJob
= KIO::stat(url
, KIO::HideProgressInfo
);
1250 if (m_lastHandleUrlStatJob
->ui()) {
1251 m_lastHandleUrlStatJob
->ui()->setWindow(this);
1253 connect(m_lastHandleUrlStatJob
, SIGNAL(result(KJob
*)),
1254 this, SLOT(slotHandleUrlStatFinished(KJob
*)));
1257 new KRun(url
, this); // Automatically deletes itself after being finished
1261 void DolphinMainWindow::slotHandleUrlStatFinished(KJob
* job
)
1263 m_lastHandleUrlStatJob
= 0;
1264 const KIO::UDSEntry entry
= static_cast<KIO::StatJob
*>(job
)->statResult();
1265 const KUrl url
= static_cast<KIO::StatJob
*>(job
)->url();
1266 if (entry
.isDir()) {
1267 activeViewContainer()->setUrl(url
);
1269 new KRun(url
, this); // Automatically deletes itself after being finished
1273 void DolphinMainWindow::tabDropEvent(int tab
, QDropEvent
* event
)
1275 const KUrl::List urls
= KUrl::List::fromMimeData(event
->mimeData());
1276 if (!urls
.isEmpty() && tab
!= -1) {
1277 const ViewTab
& viewTab
= m_viewTab
[tab
];
1278 const DolphinView
* view
= viewTab
.isPrimaryViewActive
? viewTab
.primaryView
->view()
1279 : viewTab
.secondaryView
->view();
1280 const QString error
= DragAndDropHelper::dropUrls(view
->rootItem(), view
->url(), event
);
1281 if (!error
.isEmpty()) {
1282 activeViewContainer()->showMessage(error
, DolphinViewContainer::Error
);
1287 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1289 newFileMenu()->setEnabled(isFolderWritable
);
1292 void DolphinMainWindow::openContextMenu(const QPoint
& pos
,
1293 const KFileItem
& item
,
1295 const QList
<QAction
*>& customActions
)
1297 QWeakPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, pos
, item
, url
);
1298 contextMenu
.data()->setCustomActions(customActions
);
1299 const DolphinContextMenu::Command command
= contextMenu
.data()->open();
1302 case DolphinContextMenu::OpenParentFolderInNewWindow
: {
1303 KRun::run("dolphin", KUrl::List() << item
.url().upUrl(), this);
1307 case DolphinContextMenu::OpenParentFolderInNewTab
:
1308 openNewTab(item
.url().upUrl());
1311 case DolphinContextMenu::None
:
1316 delete contextMenu
.data();
1319 void DolphinMainWindow::updateControlMenu()
1321 KMenu
* menu
= qobject_cast
<KMenu
*>(sender());
1324 // All actions get cleared by KMenu::clear(). The sub-menus are deleted
1325 // by connecting to the aboutToHide() signal from the parent-menu.
1328 KActionCollection
* ac
= actionCollection();
1330 // Add "Edit" actions
1331 bool added
= addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Undo
)), menu
) |
1332 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Find
)), menu
) |
1333 addActionToMenu(ac
->action("select_all"), menu
) |
1334 addActionToMenu(ac
->action("invert_selection"), menu
);
1337 menu
->addSeparator();
1340 // Add "View" actions
1341 if (!GeneralSettings::showZoomSlider()) {
1342 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomIn
)), menu
);
1343 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomOut
)), menu
);
1344 menu
->addSeparator();
1347 added
= addActionToMenu(ac
->action("view_mode"), menu
) |
1348 addActionToMenu(ac
->action("sort"), menu
) |
1349 addActionToMenu(ac
->action("additional_info"), menu
) |
1350 addActionToMenu(ac
->action("show_preview"), menu
) |
1351 addActionToMenu(ac
->action("show_in_groups"), menu
) |
1352 addActionToMenu(ac
->action("show_hidden_files"), menu
);
1355 menu
->addSeparator();
1358 added
= addActionToMenu(ac
->action("split_view"), menu
) |
1359 addActionToMenu(ac
->action("reload"), menu
) |
1360 addActionToMenu(ac
->action("view_properties"), menu
);
1362 menu
->addSeparator();
1365 addActionToMenu(ac
->action("panels"), menu
);
1366 KMenu
* locationBarMenu
= new KMenu(i18nc("@action:inmenu", "Location Bar"), menu
);
1367 locationBarMenu
->addAction(ac
->action("editable_location"));
1368 locationBarMenu
->addAction(ac
->action("replace_location"));
1369 menu
->addMenu(locationBarMenu
);
1371 menu
->addSeparator();
1374 KMenu
* goMenu
= new KMenu(i18nc("@action:inmenu", "Go"), menu
);
1375 connect(menu
, SIGNAL(aboutToHide()), goMenu
, SLOT(deleteLater()));
1376 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Back
)));
1377 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Forward
)));
1378 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Up
)));
1379 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Home
)));
1380 goMenu
->addAction(ac
->action("closed_tabs"));
1381 menu
->addMenu(goMenu
);
1384 KMenu
* toolsMenu
= new KMenu(i18nc("@action:inmenu", "Tools"), menu
);
1385 connect(menu
, SIGNAL(aboutToHide()), toolsMenu
, SLOT(deleteLater()));
1386 toolsMenu
->addAction(ac
->action("show_filter_bar"));
1387 toolsMenu
->addAction(ac
->action("compare_files"));
1388 toolsMenu
->addAction(ac
->action("open_terminal"));
1389 toolsMenu
->addAction(ac
->action("change_remote_encoding"));
1390 menu
->addMenu(toolsMenu
);
1392 // Add "Settings" menu entries
1393 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::KeyBindings
)), menu
);
1394 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ConfigureToolbars
)), menu
);
1395 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Preferences
)), menu
);
1398 KMenu
* helpMenu
= new KMenu(i18nc("@action:inmenu", "Help"), menu
);
1399 connect(menu
, SIGNAL(aboutToHide()), helpMenu
, SLOT(deleteLater()));
1400 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::HelpContents
)));
1401 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::WhatsThis
)));
1402 helpMenu
->addSeparator();
1403 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ReportBug
)));
1404 helpMenu
->addSeparator();
1405 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
)));
1406 helpMenu
->addSeparator();
1407 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::AboutApp
)));
1408 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::AboutKDE
)));
1409 menu
->addMenu(helpMenu
);
1411 menu
->addSeparator();
1412 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ShowMenubar
)), menu
);
1415 void DolphinMainWindow::updateToolBar()
1417 if (!menuBar()->isVisible()) {
1418 createControlButton();
1422 void DolphinMainWindow::slotControlButtonDeleted()
1424 m_controlButton
= 0;
1425 m_updateToolBarTimer
->start();
1428 void DolphinMainWindow::slotPanelErrorMessage(const QString
& error
)
1430 activeViewContainer()->showMessage(error
, DolphinViewContainer::Error
);
1433 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer
* viewContainer
)
1435 Q_ASSERT(viewContainer
);
1436 Q_ASSERT((viewContainer
== m_viewTab
[m_tabIndex
].primaryView
) ||
1437 (viewContainer
== m_viewTab
[m_tabIndex
].secondaryView
));
1438 if (m_activeViewContainer
== viewContainer
) {
1442 m_activeViewContainer
->setActive(false);
1443 m_activeViewContainer
= viewContainer
;
1445 // Activating the view container might trigger a recursive setActiveViewContainer() call
1446 // inside DolphinMainWindow::toggleActiveView() when having a split view. Temporary
1447 // disconnect the activated() signal in this case:
1448 disconnect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1449 m_activeViewContainer
->setActive(true);
1450 connect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1452 m_actionHandler
->setCurrentView(viewContainer
->view());
1455 updateEditActions();
1456 updateViewActions();
1459 const KUrl url
= m_activeViewContainer
->url();
1460 setUrlAsCaption(url
);
1461 if (m_viewTab
.count() > 1) {
1462 m_tabBar
->setTabText(m_tabIndex
, tabName(url
));
1463 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(KMimeType::iconNameForUrl(url
)));
1466 emit
urlChanged(url
);
1469 DolphinViewContainer
* DolphinMainWindow::createViewContainer(const KUrl
& url
, QWidget
* parent
)
1471 DolphinViewContainer
* container
= new DolphinViewContainer(url
, parent
);
1473 // The places-selector from the URL navigator should only be shown
1474 // if the places dock is invisible
1475 QDockWidget
* placesDock
= findChild
<QDockWidget
*>("placesDock");
1476 container
->urlNavigator()->setPlacesSelectorVisible(!placesDock
|| !placesDock
->isVisible());
1481 void DolphinMainWindow::setupActions()
1483 // setup 'File' menu
1484 m_newFileMenu
= new DolphinNewFileMenu(this);
1485 KMenu
* menu
= m_newFileMenu
->menu();
1486 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1487 menu
->setIcon(KIcon("document-new"));
1488 connect(menu
, SIGNAL(aboutToShow()),
1489 this, SLOT(updateNewMenu()));
1491 KAction
* newWindow
= actionCollection()->addAction("new_window");
1492 newWindow
->setIcon(KIcon("window-new"));
1493 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1494 newWindow
->setShortcut(Qt::CTRL
| Qt::Key_N
);
1495 connect(newWindow
, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1497 KAction
* newTab
= actionCollection()->addAction("new_tab");
1498 newTab
->setIcon(KIcon("tab-new"));
1499 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1500 newTab
->setShortcut(KShortcut(Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
));
1501 connect(newTab
, SIGNAL(triggered()), this, SLOT(openNewTab()));
1503 KAction
* closeTab
= actionCollection()->addAction("close_tab");
1504 closeTab
->setIcon(KIcon("tab-close"));
1505 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1506 closeTab
->setShortcut(Qt::CTRL
| Qt::Key_W
);
1507 closeTab
->setEnabled(false);
1508 connect(closeTab
, SIGNAL(triggered()), this, SLOT(closeTab()));
1510 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1512 // setup 'Edit' menu
1513 KStandardAction::undo(this,
1515 actionCollection());
1517 // need to remove shift+del from cut action, else the shortcut for deletejob
1519 KAction
* cut
= KStandardAction::cut(this, SLOT(cut()), actionCollection());
1520 KShortcut cutShortcut
= cut
->shortcut();
1521 cutShortcut
.remove(Qt::SHIFT
| Qt::Key_Delete
, KShortcut::KeepEmpty
);
1522 cut
->setShortcut(cutShortcut
);
1523 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1524 KAction
* paste
= KStandardAction::paste(this, SLOT(paste()), actionCollection());
1525 // The text of the paste-action is modified dynamically by Dolphin
1526 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1527 // due to the long text, the text "Paste" is used:
1528 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1530 KStandardAction::find(this, SLOT(find()), actionCollection());
1532 KAction
* selectAll
= actionCollection()->addAction("select_all");
1533 selectAll
->setText(i18nc("@action:inmenu Edit", "Select All"));
1534 selectAll
->setShortcut(Qt::CTRL
| Qt::Key_A
);
1535 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
1537 KAction
* invertSelection
= actionCollection()->addAction("invert_selection");
1538 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1539 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1540 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
1542 // setup 'View' menu
1543 // (note that most of it is set up in DolphinViewActionHandler)
1545 KAction
* split
= actionCollection()->addAction("split_view");
1546 split
->setShortcut(Qt::Key_F3
);
1547 updateSplitAction();
1548 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1550 KAction
* reload
= actionCollection()->addAction("reload");
1551 reload
->setText(i18nc("@action:inmenu View", "Reload"));
1552 reload
->setShortcut(Qt::Key_F5
);
1553 reload
->setIcon(KIcon("view-refresh"));
1554 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
1556 KAction
* stop
= actionCollection()->addAction("stop");
1557 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1558 stop
->setToolTip(i18nc("@info", "Stop loading"));
1559 stop
->setIcon(KIcon("process-stop"));
1560 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
1562 KToggleAction
* editableLocation
= actionCollection()->add
<KToggleAction
>("editable_location");
1563 editableLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1564 editableLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
1565 connect(editableLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1567 KAction
* replaceLocation
= actionCollection()->addAction("replace_location");
1568 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1569 replaceLocation
->setShortcut(Qt::Key_F6
);
1570 connect(replaceLocation
, SIGNAL(triggered()), this, SLOT(replaceLocation()));
1573 KAction
* backAction
= KStandardAction::back(this, SLOT(goBack()), actionCollection());
1574 connect(backAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goBack(Qt::MouseButtons
)));
1575 KShortcut backShortcut
= backAction
->shortcut();
1576 backShortcut
.setAlternate(Qt::Key_Backspace
);
1577 backAction
->setShortcut(backShortcut
);
1579 m_recentTabsMenu
= new KActionMenu(i18n("Recently Closed Tabs"), this);
1580 m_recentTabsMenu
->setIcon(KIcon("edit-undo"));
1581 actionCollection()->addAction("closed_tabs", m_recentTabsMenu
);
1582 connect(m_recentTabsMenu
->menu(), SIGNAL(triggered(QAction
*)),
1583 this, SLOT(restoreClosedTab(QAction
*)));
1585 QAction
* action
= new QAction(i18n("Empty Recently Closed Tabs"), m_recentTabsMenu
);
1586 action
->setIcon(KIcon("edit-clear-list"));
1587 action
->setData(QVariant::fromValue(true));
1588 m_recentTabsMenu
->addAction(action
);
1589 m_recentTabsMenu
->addSeparator();
1590 m_recentTabsMenu
->setEnabled(false);
1592 KAction
* forwardAction
= KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1593 connect(forwardAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goForward(Qt::MouseButtons
)));
1595 KAction
* upAction
= KStandardAction::up(this, SLOT(goUp()), actionCollection());
1596 connect(upAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goUp(Qt::MouseButtons
)));
1598 KAction
* homeAction
= KStandardAction::home(this, SLOT(goHome()), actionCollection());
1599 connect(homeAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goHome(Qt::MouseButtons
)));
1601 // setup 'Tools' menu
1602 KAction
* showFilterBar
= actionCollection()->addAction("show_filter_bar");
1603 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1604 showFilterBar
->setIcon(KIcon("view-filter"));
1605 showFilterBar
->setShortcut(Qt::CTRL
| Qt::Key_I
);
1606 connect(showFilterBar
, SIGNAL(triggered()), this, SLOT(showFilterBar()));
1608 KAction
* compareFiles
= actionCollection()->addAction("compare_files");
1609 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1610 compareFiles
->setIcon(KIcon("kompare"));
1611 compareFiles
->setEnabled(false);
1612 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
1614 KAction
* openTerminal
= actionCollection()->addAction("open_terminal");
1615 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1616 openTerminal
->setIcon(KIcon("utilities-terminal"));
1617 openTerminal
->setShortcut(Qt::SHIFT
| Qt::Key_F4
);
1618 connect(openTerminal
, SIGNAL(triggered()), this, SLOT(openTerminal()));
1620 // setup 'Settings' menu
1621 KToggleAction
* showMenuBar
= KStandardAction::showMenubar(0, 0, actionCollection());
1622 connect(showMenuBar
, SIGNAL(triggered(bool)), // Fixes #286822
1623 this, SLOT(toggleShowMenuBar()), Qt::QueuedConnection
);
1624 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1626 // not in menu actions
1627 QList
<QKeySequence
> nextTabKeys
;
1628 nextTabKeys
.append(KStandardShortcut::tabNext().primary());
1629 nextTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::Key_Tab
));
1631 QList
<QKeySequence
> prevTabKeys
;
1632 prevTabKeys
.append(KStandardShortcut::tabPrev().primary());
1633 prevTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::SHIFT
| Qt::Key_Tab
));
1635 KAction
* activateNextTab
= actionCollection()->addAction("activate_next_tab");
1636 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1637 connect(activateNextTab
, SIGNAL(triggered()), SLOT(activateNextTab()));
1638 activateNextTab
->setShortcuts(QApplication::isRightToLeft() ? prevTabKeys
: nextTabKeys
);
1640 KAction
* activatePrevTab
= actionCollection()->addAction("activate_prev_tab");
1641 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1642 connect(activatePrevTab
, SIGNAL(triggered()), SLOT(activatePrevTab()));
1643 activatePrevTab
->setShortcuts(QApplication::isRightToLeft() ? nextTabKeys
: prevTabKeys
);
1646 KAction
* openInNewTab
= actionCollection()->addAction("open_in_new_tab");
1647 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1648 openInNewTab
->setIcon(KIcon("tab-new"));
1649 connect(openInNewTab
, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1651 KAction
* openInNewWindow
= actionCollection()->addAction("open_in_new_window");
1652 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1653 openInNewWindow
->setIcon(KIcon("window-new"));
1654 connect(openInNewWindow
, SIGNAL(triggered()), this, SLOT(openInNewWindow()));
1657 void DolphinMainWindow::setupDockWidgets()
1659 const bool lock
= GeneralSettings::lockPanels();
1661 KDualAction
* lockLayoutAction
= actionCollection()->add
<KDualAction
>("lock_panels");
1662 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
1663 lockLayoutAction
->setActiveIcon(KIcon("object-unlocked"));
1664 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
1665 lockLayoutAction
->setInactiveIcon(KIcon("object-locked"));
1666 lockLayoutAction
->setActive(lock
);
1667 connect(lockLayoutAction
, SIGNAL(triggered()), this, SLOT(togglePanelLockState()));
1669 // Setup "Information"
1670 DolphinDockWidget
* infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
1671 infoDock
->setLocked(lock
);
1672 infoDock
->setObjectName("infoDock");
1673 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1674 Panel
* infoPanel
= new InformationPanel(infoDock
);
1675 infoPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1676 connect(infoPanel
, SIGNAL(urlActivated(KUrl
)), this, SLOT(handleUrl(KUrl
)));
1677 infoDock
->setWidget(infoPanel
);
1679 QAction
* infoAction
= infoDock
->toggleViewAction();
1680 createPanelAction(KIcon("dialog-information"), Qt::Key_F11
, infoAction
, "show_information_panel");
1682 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1683 connect(this, SIGNAL(urlChanged(KUrl
)),
1684 infoPanel
, SLOT(setUrl(KUrl
)));
1685 connect(this, SIGNAL(selectionChanged(KFileItemList
)),
1686 infoPanel
, SLOT(setSelection(KFileItemList
)));
1687 connect(this, SIGNAL(requestItemInfo(KFileItem
)),
1688 infoPanel
, SLOT(requestDelayedItemInfo(KFileItem
)));
1691 DolphinDockWidget
* foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
1692 foldersDock
->setLocked(lock
);
1693 foldersDock
->setObjectName("foldersDock");
1694 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1695 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1696 foldersPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1697 foldersDock
->setWidget(foldersPanel
);
1699 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1700 createPanelAction(KIcon("folder"), Qt::Key_F7
, foldersAction
, "show_folders_panel");
1702 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1703 connect(this, SIGNAL(urlChanged(KUrl
)),
1704 foldersPanel
, SLOT(setUrl(KUrl
)));
1705 connect(foldersPanel
, SIGNAL(folderActivated(KUrl
)),
1706 this, SLOT(changeUrl(KUrl
)));
1707 connect(foldersPanel
, SIGNAL(folderMiddleClicked(KUrl
)),
1708 this, SLOT(openNewActivatedTab(KUrl
)));
1709 connect(foldersPanel
, SIGNAL(errorMessage(QString
)),
1710 this, SLOT(slotPanelErrorMessage(QString
)));
1714 DolphinDockWidget
* terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1715 terminalDock
->setLocked(lock
);
1716 terminalDock
->setObjectName("terminalDock");
1717 terminalDock
->setAllowedAreas(Qt::TopDockWidgetArea
| Qt::BottomDockWidgetArea
);
1718 Panel
* terminalPanel
= new TerminalPanel(terminalDock
);
1719 terminalPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1720 terminalDock
->setWidget(terminalPanel
);
1722 connect(terminalPanel
, SIGNAL(hideTerminalPanel()), terminalDock
, SLOT(hide()));
1723 connect(terminalPanel
, SIGNAL(changeUrl(KUrl
)), this, SLOT(slotTerminalDirectoryChanged(KUrl
)));
1724 connect(terminalDock
, SIGNAL(visibilityChanged(bool)),
1725 terminalPanel
, SLOT(dockVisibilityChanged()));
1727 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1728 createPanelAction(KIcon("utilities-terminal"), Qt::Key_F4
, terminalAction
, "show_terminal_panel");
1730 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1731 connect(this, SIGNAL(urlChanged(KUrl
)),
1732 terminalPanel
, SLOT(setUrl(KUrl
)));
1735 if (GeneralSettings::version() < 200) {
1737 foldersDock
->hide();
1739 terminalDock
->hide();
1744 DolphinDockWidget
* placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
1745 placesDock
->setLocked(lock
);
1746 placesDock
->setObjectName("placesDock");
1747 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1749 PlacesPanel
* placesPanel
= new PlacesPanel(placesDock
);
1750 placesPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1751 placesDock
->setWidget(placesPanel
);
1753 QAction
* placesAction
= placesDock
->toggleViewAction();
1754 createPanelAction(KIcon("bookmarks"), Qt::Key_F9
, placesAction
, "show_places_panel");
1756 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1757 connect(placesPanel
, SIGNAL(placeActivated(KUrl
)),
1758 this, SLOT(changeUrl(KUrl
)));
1759 connect(placesPanel
, SIGNAL(placeMiddleClicked(KUrl
)),
1760 this, SLOT(openNewActivatedTab(KUrl
)));
1761 connect(placesPanel
, SIGNAL(errorMessage(QString
)),
1762 this, SLOT(slotPanelErrorMessage(QString
)));
1763 connect(this, SIGNAL(urlChanged(KUrl
)),
1764 placesPanel
, SLOT(setUrl(KUrl
)));
1765 connect(placesDock
, SIGNAL(visibilityChanged(bool)),
1766 this, SLOT(slotPlacesPanelVisibilityChanged(bool)));
1768 // Add actions into the "Panels" menu
1769 KActionMenu
* panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Panels"), this);
1770 actionCollection()->addAction("panels", panelsMenu
);
1771 panelsMenu
->setDelayed(false);
1772 const KActionCollection
* ac
= actionCollection();
1773 panelsMenu
->addAction(ac
->action("show_places_panel"));
1774 panelsMenu
->addAction(ac
->action("show_information_panel"));
1775 panelsMenu
->addAction(ac
->action("show_folders_panel"));
1777 panelsMenu
->addAction(ac
->action("show_terminal_panel"));
1779 panelsMenu
->addSeparator();
1780 panelsMenu
->addAction(lockLayoutAction
);
1783 void DolphinMainWindow::updateEditActions()
1785 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1786 if (list
.isEmpty()) {
1787 stateChanged("has_no_selection");
1789 stateChanged("has_selection");
1791 KActionCollection
* col
= actionCollection();
1792 QAction
* renameAction
= col
->action("rename");
1793 QAction
* moveToTrashAction
= col
->action("move_to_trash");
1794 QAction
* deleteAction
= col
->action("delete");
1795 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
1796 QAction
* deleteWithTrashShortcut
= col
->action("delete_shortcut"); // see DolphinViewActionHandler
1798 KFileItemListProperties
capabilities(list
);
1799 const bool enableMoveToTrash
= capabilities
.isLocal() && capabilities
.supportsMoving();
1801 renameAction
->setEnabled(capabilities
.supportsMoving());
1802 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1803 deleteAction
->setEnabled(capabilities
.supportsDeleting());
1804 deleteWithTrashShortcut
->setEnabled(capabilities
.supportsDeleting() && !enableMoveToTrash
);
1805 cutAction
->setEnabled(capabilities
.supportsMoving());
1807 updatePasteAction();
1810 void DolphinMainWindow::updateViewActions()
1812 m_actionHandler
->updateViewActions();
1814 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1815 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
1817 updateSplitAction();
1819 QAction
* editableLocactionAction
= actionCollection()->action("editable_location");
1820 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
1821 editableLocactionAction
->setChecked(urlNavigator
->isUrlEditable());
1824 void DolphinMainWindow::updateGoActions()
1826 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
1827 const KUrl currentUrl
= m_activeViewContainer
->url();
1828 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
1831 void DolphinMainWindow::createControlButton()
1833 if (m_controlButton
) {
1836 Q_ASSERT(!m_controlButton
);
1838 m_controlButton
= new QToolButton(this);
1839 m_controlButton
->setIcon(KIcon("applications-system"));
1840 m_controlButton
->setText(i18nc("@action", "Control"));
1841 m_controlButton
->setPopupMode(QToolButton::InstantPopup
);
1842 m_controlButton
->setToolButtonStyle(toolBar()->toolButtonStyle());
1844 KMenu
* controlMenu
= new KMenu(m_controlButton
);
1845 connect(controlMenu
, SIGNAL(aboutToShow()), this, SLOT(updateControlMenu()));
1847 m_controlButton
->setMenu(controlMenu
);
1849 toolBar()->addWidget(m_controlButton
);
1850 connect(toolBar(), SIGNAL(iconSizeChanged(QSize
)),
1851 m_controlButton
, SLOT(setIconSize(QSize
)));
1852 connect(toolBar(), SIGNAL(toolButtonStyleChanged(Qt::ToolButtonStyle
)),
1853 m_controlButton
, SLOT(setToolButtonStyle(Qt::ToolButtonStyle
)));
1855 // The added widgets are owned by the toolbar and may get deleted when e.g. the toolbar
1856 // gets edited. In this case we must add them again. The adding is done asynchronously by
1857 // m_updateToolBarTimer.
1858 connect(m_controlButton
, SIGNAL(destroyed()), this, SLOT(slotControlButtonDeleted()));
1859 m_updateToolBarTimer
= new QTimer(this);
1860 m_updateToolBarTimer
->setInterval(500);
1861 connect(m_updateToolBarTimer
, SIGNAL(timeout()), this, SLOT(updateToolBar()));
1864 void DolphinMainWindow::deleteControlButton()
1866 delete m_controlButton
;
1867 m_controlButton
= 0;
1869 delete m_updateToolBarTimer
;
1870 m_updateToolBarTimer
= 0;
1873 bool DolphinMainWindow::addActionToMenu(QAction
* action
, KMenu
* menu
)
1878 const KToolBar
* toolBarWidget
= toolBar();
1879 foreach (const QWidget
* widget
, action
->associatedWidgets()) {
1880 if (widget
== toolBarWidget
) {
1885 menu
->addAction(action
);
1889 void DolphinMainWindow::rememberClosedTab(int index
)
1891 KMenu
* tabsMenu
= m_recentTabsMenu
->menu();
1893 const QString primaryPath
= m_viewTab
[index
].primaryView
->url().path();
1894 const QString iconName
= KMimeType::iconNameForUrl(primaryPath
);
1896 QAction
* action
= new QAction(squeezedText(primaryPath
), tabsMenu
);
1898 ClosedTab closedTab
;
1899 closedTab
.primaryUrl
= m_viewTab
[index
].primaryView
->url();
1901 if (m_viewTab
[index
].secondaryView
) {
1902 closedTab
.secondaryUrl
= m_viewTab
[index
].secondaryView
->url();
1903 closedTab
.isSplit
= true;
1905 closedTab
.isSplit
= false;
1908 action
->setData(QVariant::fromValue(closedTab
));
1909 action
->setIcon(KIcon(iconName
));
1911 // add the closed tab menu entry after the separator and
1912 // "Empty Recently Closed Tabs" entry
1913 if (tabsMenu
->actions().size() == 2) {
1914 tabsMenu
->addAction(action
);
1916 tabsMenu
->insertAction(tabsMenu
->actions().at(2), action
);
1919 // assure that only up to 8 closed tabs are shown in the menu
1920 if (tabsMenu
->actions().size() > 8) {
1921 tabsMenu
->removeAction(tabsMenu
->actions().last());
1923 actionCollection()->action("closed_tabs")->setEnabled(true);
1924 KAcceleratorManager::manage(tabsMenu
);
1927 void DolphinMainWindow::refreshViews()
1929 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
1931 // remember the current active view, as because of
1932 // the refreshing the active view might change to
1933 // the secondary view
1934 DolphinViewContainer
* activeViewContainer
= m_activeViewContainer
;
1936 const int tabCount
= m_viewTab
.count();
1937 for (int i
= 0; i
< tabCount
; ++i
) {
1938 m_viewTab
[i
].primaryView
->readSettings();
1939 if (m_viewTab
[i
].secondaryView
) {
1940 m_viewTab
[i
].secondaryView
->readSettings();
1944 setActiveViewContainer(activeViewContainer
);
1946 if (GeneralSettings::modifiedStartupSettings()) {
1947 // The startup settings have been changed by the user (see bug #254947).
1948 // Synchronize the split-view setting with the active view:
1949 const bool splitView
= GeneralSettings::splitView();
1950 const ViewTab
& activeTab
= m_viewTab
[m_tabIndex
];
1951 const bool toggle
= ( splitView
&& !activeTab
.secondaryView
)
1952 || (!splitView
&& activeTab
.secondaryView
);
1959 void DolphinMainWindow::clearStatusBar()
1961 m_activeViewContainer
->statusBar()->resetToDefaultText();
1964 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
1966 connect(container
, SIGNAL(showFilterBarChanged(bool)),
1967 this, SLOT(updateFilterBarAction(bool)));
1968 connect(container
, SIGNAL(writeStateChanged(bool)),
1969 this, SLOT(slotWriteStateChanged(bool)));
1971 DolphinView
* view
= container
->view();
1972 connect(view
, SIGNAL(selectionChanged(KFileItemList
)),
1973 this, SLOT(slotSelectionChanged(KFileItemList
)));
1974 connect(view
, SIGNAL(requestItemInfo(KFileItem
)),
1975 this, SLOT(slotRequestItemInfo(KFileItem
)));
1976 connect(view
, SIGNAL(activated()),
1977 this, SLOT(toggleActiveView()));
1978 connect(view
, SIGNAL(tabRequested(KUrl
)),
1979 this, SLOT(openNewTab(KUrl
)));
1980 connect(view
, SIGNAL(requestContextMenu(QPoint
,KFileItem
,KUrl
,QList
<QAction
*>)),
1981 this, SLOT(openContextMenu(QPoint
,KFileItem
,KUrl
,QList
<QAction
*>)));
1982 connect(view
, SIGNAL(directoryLoadingStarted()),
1983 this, SLOT(enableStopAction()));
1984 connect(view
, SIGNAL(directoryLoadingCompleted()),
1985 this, SLOT(disableStopAction()));
1986 connect(view
, SIGNAL(goBackRequested()),
1987 this, SLOT(goBack()));
1988 connect(view
, SIGNAL(goForwardRequested()),
1989 this, SLOT(goForward()));
1991 const KUrlNavigator
* navigator
= container
->urlNavigator();
1992 connect(navigator
, SIGNAL(urlChanged(KUrl
)),
1993 this, SLOT(changeUrl(KUrl
)));
1994 connect(navigator
, SIGNAL(historyChanged()),
1995 this, SLOT(updateHistory()));
1996 connect(navigator
, SIGNAL(editableStateChanged(bool)),
1997 this, SLOT(slotEditableStateChanged(bool)));
1998 connect(navigator
, SIGNAL(tabRequested(KUrl
)),
1999 this, SLOT(openNewTab(KUrl
)));
2002 void DolphinMainWindow::updateSplitAction()
2004 QAction
* splitAction
= actionCollection()->action("split_view");
2005 if (m_viewTab
[m_tabIndex
].secondaryView
) {
2006 if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
2007 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
2008 splitAction
->setToolTip(i18nc("@info", "Close right view"));
2009 splitAction
->setIcon(KIcon("view-right-close"));
2011 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
2012 splitAction
->setToolTip(i18nc("@info", "Close left view"));
2013 splitAction
->setIcon(KIcon("view-left-close"));
2016 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
2017 splitAction
->setToolTip(i18nc("@info", "Split view"));
2018 splitAction
->setIcon(KIcon("view-right-new"));
2022 QString
DolphinMainWindow::tabName(const KUrl
& url
) const
2025 if (url
.equals(KUrl("file:///"))) {
2028 name
= url
.fileName();
2029 if (name
.isEmpty()) {
2030 name
= url
.protocol();
2032 // Make sure that a '&' inside the directory name is displayed correctly
2033 // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
2034 name
.replace('&', "&&");
2040 bool DolphinMainWindow::isKompareInstalled() const
2042 static bool initialized
= false;
2043 static bool installed
= false;
2045 // TODO: maybe replace this approach later by using a menu
2046 // plugin like kdiff3plugin.cpp
2047 installed
= !KGlobal::dirs()->findExe("kompare").isEmpty();
2053 void DolphinMainWindow::createSecondaryView(int tabIndex
)
2055 ViewTab
& viewTab
= m_viewTab
[tabIndex
];
2057 QSplitter
* splitter
= viewTab
.splitter
;
2058 const int newWidth
= (viewTab
.primaryView
->width() - splitter
->handleWidth()) / 2;
2060 const DolphinView
* view
= viewTab
.primaryView
->view();
2061 viewTab
.secondaryView
= createViewContainer(view
->url(), 0);
2062 splitter
->addWidget(viewTab
.secondaryView
);
2063 splitter
->setSizes(QList
<int>() << newWidth
<< newWidth
);
2065 connectViewSignals(viewTab
.secondaryView
);
2066 viewTab
.secondaryView
->setActive(false);
2067 viewTab
.secondaryView
->resize(newWidth
, viewTab
.primaryView
->height());
2068 viewTab
.secondaryView
->show();
2071 QString
DolphinMainWindow::tabProperty(const QString
& property
, int tabIndex
) const
2073 return "Tab " + QString::number(tabIndex
) + ' ' + property
;
2076 void DolphinMainWindow::setUrlAsCaption(const KUrl
& url
)
2079 if (!url
.isLocalFile()) {
2080 caption
.append(url
.protocol() + " - ");
2081 if (url
.hasHost()) {
2082 caption
.append(url
.host() + " - ");
2086 const QString fileName
= url
.fileName().isEmpty() ? "/" : url
.fileName();
2087 caption
.append(fileName
);
2089 setCaption(caption
);
2092 QString
DolphinMainWindow::squeezedText(const QString
& text
) const
2094 const QFontMetrics fm
= fontMetrics();
2095 return fm
.elidedText(text
, Qt::ElideMiddle
, fm
.maxWidth() * 10);
2098 void DolphinMainWindow::createPanelAction(const KIcon
& icon
,
2099 const QKeySequence
& shortcut
,
2100 QAction
* dockAction
,
2101 const QString
& actionName
)
2103 KAction
* panelAction
= actionCollection()->addAction(actionName
);
2104 panelAction
->setCheckable(true);
2105 panelAction
->setChecked(dockAction
->isChecked());
2106 panelAction
->setText(dockAction
->text());
2107 panelAction
->setIcon(icon
);
2108 panelAction
->setShortcut(shortcut
);
2110 connect(panelAction
, SIGNAL(triggered()), dockAction
, SLOT(trigger()));
2111 connect(dockAction
, SIGNAL(toggled(bool)), panelAction
, SLOT(setChecked(bool)));
2114 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
2115 KIO::FileUndoManager::UiInterface()
2119 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2123 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
2125 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
2127 DolphinViewContainer
* container
= mainWin
->activeViewContainer();
2128 container
->showMessage(job
->errorString(), DolphinViewContainer::Error
);
2130 KIO::FileUndoManager::UiInterface::jobError(job
);
2134 #include "dolphinmainwindow.moc"