1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz19@gmail.com> *
3 * Copyright (C) 2006 by Stefan Monov <logixoul@gmail.com> *
4 * Copyright (C) 2006 by Cvetoslav Ludmiloff <ludmiloff@gmail.com> *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20 ***************************************************************************/
22 #include "dolphinmainwindow.h"
24 #include <config-nepomuk.h>
26 #include "dolphinapplication.h"
27 #include "dolphindockwidget.h"
28 #include "dolphincontextmenu.h"
29 #include "dolphinnewfilemenu.h"
30 #include "dolphinviewcontainer.h"
32 #include "panels/search/searchpanel.h"
33 #include <Nepomuk/ResourceManager>
35 #include "panels/folders/folderspanel.h"
36 #include "panels/places/placespanel.h"
37 #include "panels/information/informationpanel.h"
38 #include "search/dolphinsearchbox.h"
39 #include "search/dolphinsearchinformation.h"
40 #include "settings/dolphinsettingsdialog.h"
41 #include "statusbar/dolphinstatusbar.h"
42 #include "views/dolphinviewactionhandler.h"
43 #include "views/dolphinremoteencoding.h"
44 #include "views/viewproperties.h"
47 #include "panels/terminal/terminalpanel.h"
50 #include "dolphin_generalsettings.h"
51 #include "dolphin_searchsettings.h"
53 #include <KAcceleratorManager>
55 #include <KActionCollection>
56 #include <KActionMenu>
58 #include <KDesktopFile>
59 #include <kdeversion.h>
60 #include <kdualaction.h>
61 #include <KFileDialog>
62 #include <KFilePlacesModel>
67 #include <KIconLoader>
68 #include <KIO/NetAccess>
69 #include <KInputDialog>
71 #include <KProtocolManager>
74 #include <KMessageBox>
75 #include <KFileItemListProperties>
76 #include <konqmimedata.h>
77 #include <KProtocolInfo>
80 #include <KStandardDirs>
81 #include <kstatusbar.h>
82 #include <KStandardAction>
84 #include <KToggleAction>
85 #include <KUrlNavigator>
87 #include <KUrlComboBox>
88 #include <KToolInvocation>
90 #include "views/dolphinplacesmodel.h"
92 #include <QDesktopWidget>
93 #include <QDBusMessage>
96 #include <QToolButton>
100 // Used for GeneralSettings::version() to determine whether
101 // an updated version of Dolphin is running.
102 const int CurrentDolphinVersion
= 200;
106 * Menu shown when pressing the configure-button in the toolbar.
108 class ToolBarMenu
: public KMenu
111 ToolBarMenu(QWidget
* parent
);
112 virtual ~ToolBarMenu();
114 virtual void showEvent(QShowEvent
* event
);
118 * Remembers the tab configuration if a tab has been closed.
119 * Each closed tab can be restored by the menu
120 * "Go -> Recently Closed Tabs".
128 Q_DECLARE_METATYPE(ClosedTab
)
130 DolphinMainWindow::DolphinMainWindow() :
134 m_activeViewContainer(0),
135 m_centralWidgetLayout(0),
142 m_openToolBarMenuButton(0),
143 m_updateToolBarTimer(0),
144 m_lastHandleUrlStatJob(0),
145 m_searchDockIsTemporaryVisible(false)
147 DolphinPlacesModel::setModel(new KFilePlacesModel(this));
148 connect(DolphinPlacesModel::instance(), SIGNAL(errorMessage(QString
)),
149 this, SLOT(showErrorMessage(QString
)));
151 // Workaround for a X11-issue in combination with KModifierInfo
152 // (see DolphinContextMenu::initializeModifierKeyInfo() for
153 // more information):
154 DolphinContextMenu::initializeModifierKeyInfo();
156 setObjectName("Dolphin#");
158 m_viewTab
.append(ViewTab());
160 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
161 undoManager
->setUiInterface(new UndoUiInterface());
163 connect(undoManager
, SIGNAL(undoAvailable(bool)),
164 this, SLOT(slotUndoAvailable(bool)));
165 connect(undoManager
, SIGNAL(undoTextChanged(QString
)),
166 this, SLOT(slotUndoTextChanged(QString
)));
167 connect(undoManager
, SIGNAL(jobRecordingStarted(CommandType
)),
168 this, SLOT(clearStatusBar()));
169 connect(undoManager
, SIGNAL(jobRecordingFinished(CommandType
)),
170 this, SLOT(showCommand(CommandType
)));
172 GeneralSettings
* generalSettings
= GeneralSettings::self();
173 const bool firstRun
= (generalSettings
->version() < 200);
175 generalSettings
->setViewPropsTimestamp(QDateTime::currentDateTime());
178 setAcceptDrops(true);
180 m_viewTab
[m_tabIndex
].splitter
= new QSplitter(this);
181 m_viewTab
[m_tabIndex
].splitter
->setChildrenCollapsible(false);
185 const KUrl
homeUrl(generalSettings
->homeUrl());
186 setUrlAsCaption(homeUrl
);
187 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
188 connect(m_actionHandler
, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
189 connect(m_actionHandler
, SIGNAL(createDirectory()), SLOT(createDirectory()));
191 m_viewTab
[m_tabIndex
].primaryView
= createViewContainer(homeUrl
, m_viewTab
[m_tabIndex
].splitter
);
193 m_activeViewContainer
= m_viewTab
[m_tabIndex
].primaryView
;
194 connectViewSignals(m_activeViewContainer
);
195 DolphinView
* view
= m_activeViewContainer
->view();
196 m_activeViewContainer
->show();
197 m_actionHandler
->setCurrentView(view
);
199 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
200 connect(this, SIGNAL(urlChanged(KUrl
)),
201 m_remoteEncoding
, SLOT(slotAboutToOpenUrl()));
203 m_tabBar
= new KTabBar(this);
204 m_tabBar
->setMovable(true);
205 m_tabBar
->setTabsClosable(true);
206 connect(m_tabBar
, SIGNAL(currentChanged(int)),
207 this, SLOT(setActiveTab(int)));
208 connect(m_tabBar
, SIGNAL(tabCloseRequested(int)),
209 this, SLOT(closeTab(int)));
210 connect(m_tabBar
, SIGNAL(contextMenu(int,QPoint
)),
211 this, SLOT(openTabContextMenu(int,QPoint
)));
212 connect(m_tabBar
, SIGNAL(newTabRequest()),
213 this, SLOT(openNewTab()));
214 connect(m_tabBar
, SIGNAL(testCanDecode(const QDragMoveEvent
*,bool&)),
215 this, SLOT(slotTestCanDecode(const QDragMoveEvent
*,bool&)));
216 connect(m_tabBar
, SIGNAL(mouseMiddleClick(int)),
217 this, SLOT(closeTab(int)));
218 connect(m_tabBar
, SIGNAL(tabMoved(int,int)),
219 this, SLOT(slotTabMoved(int,int)));
220 connect(m_tabBar
, SIGNAL(receivedDropEvent(int,QDropEvent
*)),
221 this, SLOT(tabDropEvent(int,QDropEvent
*)));
223 m_tabBar
->blockSignals(true); // signals get unblocked after at least 2 tabs are open
225 QWidget
* centralWidget
= new QWidget(this);
226 m_centralWidgetLayout
= new QVBoxLayout(centralWidget
);
227 m_centralWidgetLayout
->setSpacing(0);
228 m_centralWidgetLayout
->setMargin(0);
229 m_centralWidgetLayout
->addWidget(m_tabBar
);
230 m_centralWidgetLayout
->addWidget(m_viewTab
[m_tabIndex
].splitter
, 1);
232 setCentralWidget(centralWidget
);
234 emit
urlChanged(homeUrl
);
236 setupGUI(Keys
| Save
| Create
| ToolBar
);
237 stateChanged("new_file");
239 QClipboard
* clipboard
= QApplication::clipboard();
240 connect(clipboard
, SIGNAL(dataChanged()),
241 this, SLOT(updatePasteAction()));
243 if (generalSettings
->splitView()) {
250 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
251 showFilterBarAction
->setChecked(generalSettings
->filterBar());
254 menuBar()->setVisible(false);
255 // Assure a proper default size if Dolphin runs the first time
259 const bool showMenu
= !menuBar()->isHidden();
260 QAction
* showMenuBarAction
= actionCollection()->action(KStandardAction::name(KStandardAction::ShowMenubar
));
261 showMenuBarAction
->setChecked(showMenu
); // workaround for bug #171080
263 createToolBarMenuButton();
267 DolphinMainWindow::~DolphinMainWindow()
271 void DolphinMainWindow::openDirectories(const QList
<KUrl
>& dirs
)
273 if (dirs
.isEmpty()) {
277 if (dirs
.count() == 1) {
278 m_activeViewContainer
->setUrl(dirs
.first());
282 const int oldOpenTabsCount
= m_viewTab
.count();
284 const bool hasSplitView
= GeneralSettings::splitView();
286 // Open each directory inside a new tab. If the "split view" option has been enabled,
287 // always show two directories within one tab.
288 QList
<KUrl
>::const_iterator it
= dirs
.begin();
289 while (it
!= dirs
.end()) {
293 if (hasSplitView
&& (it
!= dirs
.end())) {
294 const int tabIndex
= m_viewTab
.count() - 1;
295 m_viewTab
[tabIndex
].secondaryView
->setUrl(*it
);
300 // Remove the previously opened tabs
301 for (int i
= 0; i
< oldOpenTabsCount
; ++i
) {
306 void DolphinMainWindow::openFiles(const QList
<KUrl
>& files
)
308 if (files
.isEmpty()) {
312 // Get all distinct directories from 'files' and open a tab
313 // for each directory. If the "split view" option is enabled, two
314 // directories are shown inside one tab (see openDirectories()).
316 foreach (const KUrl
& url
, files
) {
317 const KUrl
dir(url
.directory());
318 if (!dirs
.contains(dir
)) {
323 openDirectories(dirs
);
325 // Select the files. Although the files can be split between several
326 // tabs, there is no need to split 'files' accordingly, as
327 // the DolphinView will just ignore invalid selections.
328 const int tabCount
= m_viewTab
.count();
329 for (int i
= 0; i
< tabCount
; ++i
) {
330 m_viewTab
[i
].primaryView
->view()->markUrlsAsSelected(files
);
331 m_viewTab
[i
].primaryView
->view()->markUrlAsCurrent(files
.at(0));
332 if (m_viewTab
[i
].secondaryView
) {
333 m_viewTab
[i
].secondaryView
->view()->markUrlsAsSelected(files
);
334 m_viewTab
[i
].secondaryView
->view()->markUrlAsCurrent(files
.at(0));
339 void DolphinMainWindow::showCommand(CommandType command
)
341 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
343 case KIO::FileUndoManager::Copy
:
344 statusBar
->setMessage(i18nc("@info:status", "Successfully copied."),
345 DolphinStatusBar::OperationCompleted
);
347 case KIO::FileUndoManager::Move
:
348 statusBar
->setMessage(i18nc("@info:status", "Successfully moved."),
349 DolphinStatusBar::OperationCompleted
);
351 case KIO::FileUndoManager::Link
:
352 statusBar
->setMessage(i18nc("@info:status", "Successfully linked."),
353 DolphinStatusBar::OperationCompleted
);
355 case KIO::FileUndoManager::Trash
:
356 statusBar
->setMessage(i18nc("@info:status", "Successfully moved to trash."),
357 DolphinStatusBar::OperationCompleted
);
359 case KIO::FileUndoManager::Rename
:
360 statusBar
->setMessage(i18nc("@info:status", "Successfully renamed."),
361 DolphinStatusBar::OperationCompleted
);
364 case KIO::FileUndoManager::Mkdir
:
365 statusBar
->setMessage(i18nc("@info:status", "Created folder."),
366 DolphinStatusBar::OperationCompleted
);
374 void DolphinMainWindow::pasteIntoFolder()
376 m_activeViewContainer
->view()->pasteIntoFolder();
379 void DolphinMainWindow::changeUrl(const KUrl
& url
)
381 if (!KProtocolManager::supportsListing(url
)) {
382 // The URL navigator only checks for validity, not
383 // if the URL can be listed. An error message is
384 // shown due to DolphinViewContainer::restoreView().
388 DolphinViewContainer
* view
= activeViewContainer();
394 setUrlAsCaption(url
);
395 if (m_viewTab
.count() > 1) {
396 m_tabBar
->setTabText(m_tabIndex
, squeezedText(tabName(m_activeViewContainer
->url())));
398 const QString iconName
= KMimeType::iconNameForUrl(url
);
399 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(iconName
));
400 emit
urlChanged(url
);
404 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
406 KToggleAction
* editableLocationAction
=
407 static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
408 editableLocationAction
->setChecked(editable
);
411 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
415 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
416 int selectedUrlsCount
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedItemsCount();
417 if (m_viewTab
[m_tabIndex
].secondaryView
) {
418 selectedUrlsCount
+= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItemsCount();
421 QAction
* compareFilesAction
= actionCollection()->action("compare_files");
422 if (selectedUrlsCount
== 2) {
423 compareFilesAction
->setEnabled(isKompareInstalled());
425 compareFilesAction
->setEnabled(false);
428 emit
selectionChanged(selection
);
431 void DolphinMainWindow::slotRequestItemInfo(const KFileItem
& item
)
433 emit
requestItemInfo(item
);
436 void DolphinMainWindow::updateHistory()
438 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
439 const int index
= urlNavigator
->historyIndex();
441 QAction
* backAction
= actionCollection()->action("go_back");
443 backAction
->setToolTip(i18nc("@info", "Go back"));
444 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
447 QAction
* forwardAction
= actionCollection()->action("go_forward");
449 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
450 forwardAction
->setEnabled(index
> 0);
454 void DolphinMainWindow::updateFilterBarAction(bool show
)
456 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
457 showFilterBarAction
->setChecked(show
);
460 void DolphinMainWindow::openNewMainWindow()
462 KRun::run("dolphin", KUrl::List(), this);
465 void DolphinMainWindow::openNewTab()
467 const bool isUrlEditable
= m_activeViewContainer
->urlNavigator()->isUrlEditable();
469 openNewTab(m_activeViewContainer
->url());
470 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
472 // The URL navigator of the new tab should have the same editable state
473 // as the current tab
474 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
475 navigator
->setUrlEditable(isUrlEditable
);
478 // If a new tab is opened and the URL is editable, assure that
479 // the user can edit the URL without manually setting the focus
480 navigator
->setFocus();
484 void DolphinMainWindow::openNewTab(const KUrl
& url
)
486 QWidget
* focusWidget
= QApplication::focusWidget();
488 if (m_viewTab
.count() == 1) {
489 // Only one view is open currently and hence no tab is shown at
490 // all. Before creating a tab for 'url', provide a tab for the current URL.
491 const KUrl currentUrl
= m_activeViewContainer
->url();
492 m_tabBar
->addTab(KIcon(KMimeType::iconNameForUrl(currentUrl
)),
493 squeezedText(tabName(currentUrl
)));
494 m_tabBar
->blockSignals(false);
497 m_tabBar
->addTab(KIcon(KMimeType::iconNameForUrl(url
)),
498 squeezedText(tabName(url
)));
501 viewTab
.splitter
= new QSplitter(this);
502 viewTab
.splitter
->setChildrenCollapsible(false);
503 viewTab
.primaryView
= createViewContainer(url
, viewTab
.splitter
);
504 viewTab
.primaryView
->setActive(false);
505 connectViewSignals(viewTab
.primaryView
);
507 const int newTabIndex
= m_viewTab
.count();
508 m_viewTab
.append(viewTab
);
510 actionCollection()->action("close_tab")->setEnabled(true);
512 // provide a split view, if the startup settings are set this way
513 if (GeneralSettings::splitView()) {
514 createSecondaryView(newTabIndex
);
515 viewTab
.secondaryView
->setActive(true);
516 viewTab
.isPrimaryViewActive
= false;
520 // The DolphinViewContainer grabbed the keyboard focus. As the tab is opened
521 // in background, assure that the previous focused widget gets the focus back.
522 focusWidget
->setFocus();
525 // TODO: Temporary switching to the new tab is a workaround/hack to prevent that
526 // the KItemListView from the DolphinView is initialized with a too small size.
527 // The small size results in an unwanted animation of the items when showing the
528 // tab the first time, as the KItemListView size will be adjusted on-the-fly.
529 const int currentTabIndex
= m_tabIndex
;
530 m_tabBar
->setCurrentIndex(newTabIndex
);
531 m_tabBar
->setCurrentIndex(currentTabIndex
);
534 void DolphinMainWindow::activateNextTab()
536 if (m_viewTab
.count() >= 2) {
537 const int tabIndex
= (m_tabBar
->currentIndex() + 1) % m_tabBar
->count();
538 m_tabBar
->setCurrentIndex(tabIndex
);
542 void DolphinMainWindow::activatePrevTab()
544 if (m_viewTab
.count() >= 2) {
545 int tabIndex
= m_tabBar
->currentIndex() - 1;
546 if (tabIndex
== -1) {
547 tabIndex
= m_tabBar
->count() - 1;
549 m_tabBar
->setCurrentIndex(tabIndex
);
553 void DolphinMainWindow::openInNewTab()
555 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
556 if (list
.isEmpty()) {
557 openNewTab(m_activeViewContainer
->url());
558 } else if ((list
.count() == 1) && list
[0].isDir()) {
559 openNewTab(list
[0].url());
563 void DolphinMainWindow::openInNewWindow()
567 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
568 if (list
.isEmpty()) {
569 newWindowUrl
= m_activeViewContainer
->url();
570 } else if ((list
.count() == 1) && list
[0].isDir()) {
571 newWindowUrl
= list
[0].url();
574 if (!newWindowUrl
.isEmpty()) {
575 KRun::run("dolphin", KUrl::List() << newWindowUrl
, this);
579 void DolphinMainWindow::toggleActiveView()
581 if (!m_viewTab
[m_tabIndex
].secondaryView
) {
582 // only one view is available
586 Q_ASSERT(m_activeViewContainer
);
587 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
589 DolphinViewContainer
* left
= m_viewTab
[m_tabIndex
].primaryView
;
590 DolphinViewContainer
* right
= m_viewTab
[m_tabIndex
].secondaryView
;
591 setActiveViewContainer(m_activeViewContainer
== right
? left
: right
);
594 void DolphinMainWindow::showEvent(QShowEvent
* event
)
596 KXmlGuiWindow::showEvent(event
);
597 if (!event
->spontaneous()) {
598 m_activeViewContainer
->view()->setFocus();
602 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
604 // Find out if Dolphin is closed directly by the user or
605 // by the session manager because the session is closed
606 bool closedByUser
= true;
607 DolphinApplication
*application
= qobject_cast
<DolphinApplication
*>(qApp
);
608 if (application
&& application
->sessionSaving()) {
609 closedByUser
= false;
612 if (m_viewTab
.count() > 1 && GeneralSettings::confirmClosingMultipleTabs() && closedByUser
) {
613 // Ask the user if he really wants to quit and close all tabs.
614 // Open a confirmation dialog with 3 buttons:
615 // KDialog::Yes -> Quit
616 // KDialog::No -> Close only the current tab
617 // KDialog::Cancel -> do nothing
618 KDialog
*dialog
= new KDialog(this, Qt::Dialog
);
619 dialog
->setCaption(i18nc("@title:window", "Confirmation"));
620 dialog
->setButtons(KDialog::Yes
| KDialog::No
| KDialog::Cancel
);
621 dialog
->setModal(true);
622 dialog
->setButtonGuiItem(KDialog::Yes
, KStandardGuiItem::quit());
623 dialog
->setButtonGuiItem(KDialog::No
, KGuiItem(i18n("C&lose Current Tab"), KIcon("tab-close")));
624 dialog
->setButtonGuiItem(KDialog::Cancel
, KStandardGuiItem::cancel());
625 dialog
->setDefaultButton(KDialog::Yes
);
627 bool doNotAskAgainCheckboxResult
= false;
629 const int result
= KMessageBox::createKMessageBox(dialog
,
630 QMessageBox::Warning
,
631 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
633 i18n("Do not ask again"),
634 &doNotAskAgainCheckboxResult
,
635 KMessageBox::Notify
);
637 if (doNotAskAgainCheckboxResult
) {
638 GeneralSettings::setConfirmClosingMultipleTabs(false);
646 // Close only the current tab
654 GeneralSettings::setVersion(CurrentDolphinVersion
);
655 GeneralSettings::self()->writeConfig();
657 if (m_searchDockIsTemporaryVisible
) {
658 QDockWidget
* searchDock
= findChild
<QDockWidget
*>("searchDock");
662 m_searchDockIsTemporaryVisible
= false;
665 KXmlGuiWindow::closeEvent(event
);
668 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
670 const int tabCount
= m_viewTab
.count();
671 group
.writeEntry("Tab Count", tabCount
);
672 group
.writeEntry("Active Tab Index", m_tabBar
->currentIndex());
674 for (int i
= 0; i
< tabCount
; ++i
) {
675 const DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
676 group
.writeEntry(tabProperty("Primary URL", i
), cont
->url().url());
677 group
.writeEntry(tabProperty("Primary Editable", i
),
678 cont
->urlNavigator()->isUrlEditable());
680 cont
= m_viewTab
[i
].secondaryView
;
682 group
.writeEntry(tabProperty("Secondary URL", i
), cont
->url().url());
683 group
.writeEntry(tabProperty("Secondary Editable", i
),
684 cont
->urlNavigator()->isUrlEditable());
689 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
691 const int tabCount
= group
.readEntry("Tab Count", 1);
692 for (int i
= 0; i
< tabCount
; ++i
) {
693 DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
695 cont
->setUrl(group
.readEntry(tabProperty("Primary URL", i
)));
696 const bool editable
= group
.readEntry(tabProperty("Primary Editable", i
), false);
697 cont
->urlNavigator()->setUrlEditable(editable
);
699 cont
= m_viewTab
[i
].secondaryView
;
700 const QString secondaryUrl
= group
.readEntry(tabProperty("Secondary URL", i
));
701 if (!secondaryUrl
.isEmpty()) {
703 // a secondary view should be shown, but no one is available
704 // currently -> create a new view
706 cont
= m_viewTab
[i
].secondaryView
;
710 cont
->setUrl(secondaryUrl
);
711 const bool editable
= group
.readEntry(tabProperty("Secondary Editable", i
), false);
712 cont
->urlNavigator()->setUrlEditable(editable
);
714 // no secondary view should be shown, but the default setting shows
715 // one already -> close the view
719 // openNewTab() needs to be called only tabCount - 1 times
720 if (i
!= tabCount
- 1) {
725 const int index
= group
.readEntry("Active Tab Index", 0);
726 m_tabBar
->setCurrentIndex(index
);
729 void DolphinMainWindow::updateNewMenu()
731 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
732 m_newFileMenu
->checkUpToDate();
733 m_newFileMenu
->setPopupFiles(activeViewContainer()->url());
736 void DolphinMainWindow::createDirectory()
738 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
739 m_newFileMenu
->setPopupFiles(activeViewContainer()->url());
740 m_newFileMenu
->createDirectory();
743 void DolphinMainWindow::quit()
748 void DolphinMainWindow::showErrorMessage(const QString
& message
)
750 if (!message
.isEmpty()) {
751 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
752 statusBar
->setMessage(message
, DolphinStatusBar::Error
);
756 void DolphinMainWindow::slotUndoAvailable(bool available
)
758 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
760 undoAction
->setEnabled(available
);
764 void DolphinMainWindow::restoreClosedTab(QAction
* action
)
766 if (action
->data().toBool()) {
767 // clear all actions except the "Empty Recently Closed Tabs"
768 // action and the separator
769 QList
<QAction
*> actions
= m_recentTabsMenu
->menu()->actions();
770 const int count
= actions
.size();
771 for (int i
= 2; i
< count
; ++i
) {
772 m_recentTabsMenu
->menu()->removeAction(actions
.at(i
));
775 const ClosedTab closedTab
= action
->data().value
<ClosedTab
>();
776 openNewTab(closedTab
.primaryUrl
);
777 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
779 if (closedTab
.isSplit
) {
780 // create secondary view
782 m_viewTab
[m_tabIndex
].secondaryView
->setUrl(closedTab
.secondaryUrl
);
785 m_recentTabsMenu
->removeAction(action
);
788 if (m_recentTabsMenu
->menu()->actions().count() == 2) {
789 m_recentTabsMenu
->setEnabled(false);
793 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
795 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
797 undoAction
->setText(text
);
801 void DolphinMainWindow::undo()
804 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
805 KIO::FileUndoManager::self()->undo();
808 void DolphinMainWindow::cut()
810 m_activeViewContainer
->view()->cutSelectedItems();
813 void DolphinMainWindow::copy()
815 m_activeViewContainer
->view()->copySelectedItems();
818 void DolphinMainWindow::paste()
820 m_activeViewContainer
->view()->paste();
823 void DolphinMainWindow::find()
825 m_activeViewContainer
->setSearchModeEnabled(true);
828 void DolphinMainWindow::slotSearchLocationChanged()
831 QDockWidget
* searchDock
= findChild
<QDockWidget
*>("searchDock");
836 SearchPanel
* searchPanel
= qobject_cast
<SearchPanel
*>(searchDock
->widget());
838 searchPanel
->setSearchLocation(SearchSettings::location() == QLatin1String("FromHere")
839 ? SearchPanel::FromCurrentDir
840 : SearchPanel::Everywhere
);
845 void DolphinMainWindow::updatePasteAction()
847 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
848 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
849 pasteAction
->setEnabled(pasteInfo
.first
);
850 pasteAction
->setText(pasteInfo
.second
);
853 void DolphinMainWindow::selectAll()
857 // if the URL navigator is editable and focused, select the whole
858 // URL instead of all items of the view
860 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
861 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit(); // krazy:exclude=qclasses
862 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
863 lineEdit
->hasFocus();
865 lineEdit
->selectAll();
867 m_activeViewContainer
->view()->selectAll();
871 void DolphinMainWindow::invertSelection()
874 m_activeViewContainer
->view()->invertSelection();
877 void DolphinMainWindow::toggleSplitView()
879 if (!m_viewTab
[m_tabIndex
].secondaryView
) {
880 createSecondaryView(m_tabIndex
);
881 setActiveViewContainer(m_viewTab
[m_tabIndex
].secondaryView
);
882 } else if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
883 // remove secondary view
884 m_viewTab
[m_tabIndex
].secondaryView
->close();
885 m_viewTab
[m_tabIndex
].secondaryView
->deleteLater();
886 m_viewTab
[m_tabIndex
].secondaryView
= 0;
888 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
890 // The primary view is active and should be closed. Hence from a users point of view
891 // the content of the secondary view should be moved to the primary view.
892 // From an implementation point of view it is more efficient to close
893 // the primary view and exchange the internal pointers afterwards.
895 m_viewTab
[m_tabIndex
].primaryView
->close();
896 m_viewTab
[m_tabIndex
].primaryView
->deleteLater();
897 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
898 m_viewTab
[m_tabIndex
].secondaryView
= 0;
900 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
906 void DolphinMainWindow::reloadView()
909 m_activeViewContainer
->view()->reload();
912 void DolphinMainWindow::stopLoading()
914 m_activeViewContainer
->view()->stopLoading();
917 void DolphinMainWindow::enableStopAction()
919 actionCollection()->action("stop")->setEnabled(true);
922 void DolphinMainWindow::disableStopAction()
924 actionCollection()->action("stop")->setEnabled(false);
927 void DolphinMainWindow::showFilterBar()
929 m_activeViewContainer
->setFilterBarVisible(true);
932 void DolphinMainWindow::toggleEditLocation()
936 QAction
* action
= actionCollection()->action("editable_location");
937 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
938 urlNavigator
->setUrlEditable(action
->isChecked());
941 void DolphinMainWindow::replaceLocation()
943 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
944 navigator
->setUrlEditable(true);
945 navigator
->setFocus();
947 // select the whole text of the combo box editor
948 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit(); // krazy:exclude=qclasses
949 lineEdit
->selectAll();
952 void DolphinMainWindow::togglePanelLockState()
954 const bool newLockState
= !GeneralSettings::lockPanels();
955 foreach (QObject
* child
, children()) {
956 DolphinDockWidget
* dock
= qobject_cast
<DolphinDockWidget
*>(child
);
958 dock
->setLocked(newLockState
);
962 GeneralSettings::setLockPanels(newLockState
);
965 void DolphinMainWindow::slotPlacesPanelVisibilityChanged(bool visible
)
967 const int tabCount
= m_viewTab
.count();
968 for (int i
= 0; i
< tabCount
; ++i
) {
969 ViewTab
& tab
= m_viewTab
[i
];
970 Q_ASSERT(tab
.primaryView
);
971 tab
.primaryView
->urlNavigator()->setPlacesSelectorVisible(!visible
);
972 if (tab
.secondaryView
) {
973 tab
.secondaryView
->urlNavigator()->setPlacesSelectorVisible(!visible
);
978 void DolphinMainWindow::goBack()
980 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
981 urlNavigator
->goBack();
983 if (urlNavigator
->locationState().isEmpty()) {
984 // An empty location state indicates a redirection URL,
985 // which must be skipped too
986 urlNavigator
->goBack();
990 void DolphinMainWindow::goForward()
992 m_activeViewContainer
->urlNavigator()->goForward();
995 void DolphinMainWindow::goUp()
997 m_activeViewContainer
->urlNavigator()->goUp();
1000 void DolphinMainWindow::goHome()
1002 m_activeViewContainer
->urlNavigator()->goHome();
1005 void DolphinMainWindow::goBack(Qt::MouseButtons buttons
)
1007 // The default case (left button pressed) is handled in goBack().
1008 if (buttons
== Qt::MidButton
) {
1009 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
1010 const int index
= urlNavigator
->historyIndex() + 1;
1011 openNewTab(urlNavigator
->locationUrl(index
));
1015 void DolphinMainWindow::goForward(Qt::MouseButtons buttons
)
1017 // The default case (left button pressed) is handled in goForward().
1018 if (buttons
== Qt::MidButton
) {
1019 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
1020 const int index
= urlNavigator
->historyIndex() - 1;
1021 openNewTab(urlNavigator
->locationUrl(index
));
1025 void DolphinMainWindow::goUp(Qt::MouseButtons buttons
)
1027 // The default case (left button pressed) is handled in goUp().
1028 if (buttons
== Qt::MidButton
) {
1029 openNewTab(activeViewContainer()->url().upUrl());
1033 void DolphinMainWindow::compareFiles()
1035 // The method is only invoked if exactly 2 files have
1036 // been selected. The selected files may be:
1037 // - both in the primary view
1038 // - both in the secondary view
1039 // - one in the primary view and the other in the secondary
1041 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
1046 KFileItemList items
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedItems();
1048 switch (items
.count()) {
1050 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
);
1051 items
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItems();
1052 Q_ASSERT(items
.count() == 2);
1053 urlA
= items
[0].url();
1054 urlB
= items
[1].url();
1059 urlA
= items
[0].url();
1060 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
);
1061 items
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItems();
1062 Q_ASSERT(items
.count() == 1);
1063 urlB
= items
[0].url();
1068 urlA
= items
[0].url();
1069 urlB
= items
[1].url();
1074 // may not happen: compareFiles may only get invoked if 2
1075 // files are selected
1080 QString
command("kompare -c \"");
1081 command
.append(urlA
.pathOrUrl());
1082 command
.append("\" \"");
1083 command
.append(urlB
.pathOrUrl());
1084 command
.append('\"');
1085 KRun::runCommand(command
, "Kompare", "kompare", this);
1088 void DolphinMainWindow::toggleShowMenuBar()
1090 const bool visible
= menuBar()->isVisible();
1091 menuBar()->setVisible(!visible
);
1093 createToolBarMenuButton();
1095 deleteToolBarMenuButton();
1099 void DolphinMainWindow::openTerminal()
1101 QString
dir(QDir::homePath());
1103 // If the given directory is not local, it can still be the URL of an
1104 // ioslave using UDS_LOCAL_PATH which to be converted first.
1105 KUrl url
= KIO::NetAccess::mostLocalUrl(m_activeViewContainer
->url(), this);
1107 //If the URL is local after the above conversion, set the directory.
1108 if (url
.isLocalFile()) {
1109 dir
= url
.toLocalFile();
1112 KToolInvocation::invokeTerminal(QString(), dir
);
1115 void DolphinMainWindow::editSettings()
1117 if (!m_settingsDialog
) {
1118 const KUrl url
= activeViewContainer()->url();
1119 DolphinSettingsDialog
* settingsDialog
= new DolphinSettingsDialog(url
, this);
1120 connect(settingsDialog
, SIGNAL(settingsChanged()), this, SLOT(refreshViews()));
1121 settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1122 settingsDialog
->show();
1123 m_settingsDialog
= settingsDialog
;
1125 m_settingsDialog
.data()->raise();
1129 void DolphinMainWindow::setActiveTab(int index
)
1131 Q_ASSERT(index
>= 0);
1132 Q_ASSERT(index
< m_viewTab
.count());
1133 if (index
== m_tabIndex
) {
1137 // hide current tab content
1138 ViewTab
& hiddenTab
= m_viewTab
[m_tabIndex
];
1139 hiddenTab
.isPrimaryViewActive
= hiddenTab
.primaryView
->isActive();
1140 hiddenTab
.primaryView
->setActive(false);
1141 if (hiddenTab
.secondaryView
) {
1142 hiddenTab
.secondaryView
->setActive(false);
1144 QSplitter
* splitter
= m_viewTab
[m_tabIndex
].splitter
;
1146 m_centralWidgetLayout
->removeWidget(splitter
);
1148 // show active tab content
1151 ViewTab
& viewTab
= m_viewTab
[index
];
1152 m_centralWidgetLayout
->addWidget(viewTab
.splitter
, 1);
1153 viewTab
.primaryView
->show();
1154 if (viewTab
.secondaryView
) {
1155 viewTab
.secondaryView
->show();
1157 viewTab
.splitter
->show();
1159 setActiveViewContainer(viewTab
.isPrimaryViewActive
? viewTab
.primaryView
:
1160 viewTab
.secondaryView
);
1163 void DolphinMainWindow::closeTab()
1165 closeTab(m_tabBar
->currentIndex());
1168 void DolphinMainWindow::closeTab(int index
)
1170 Q_ASSERT(index
>= 0);
1171 Q_ASSERT(index
< m_viewTab
.count());
1172 if (m_viewTab
.count() == 1) {
1173 // the last tab may never get closed
1177 if (index
== m_tabIndex
) {
1178 // The tab that should be closed is the active tab. Activate the
1179 // previous tab before closing the tab.
1180 m_tabBar
->setCurrentIndex((index
> 0) ? index
- 1 : 1);
1182 rememberClosedTab(index
);
1185 m_viewTab
[index
].primaryView
->deleteLater();
1186 if (m_viewTab
[index
].secondaryView
) {
1187 m_viewTab
[index
].secondaryView
->deleteLater();
1189 m_viewTab
[index
].splitter
->deleteLater();
1190 m_viewTab
.erase(m_viewTab
.begin() + index
);
1192 m_tabBar
->blockSignals(true);
1193 m_tabBar
->removeTab(index
);
1195 if (m_tabIndex
> index
) {
1197 Q_ASSERT(m_tabIndex
>= 0);
1200 // if only one tab is left, also remove the tab entry so that
1201 // closing the last tab is not possible
1202 if (m_viewTab
.count() == 1) {
1203 m_tabBar
->removeTab(0);
1204 actionCollection()->action("close_tab")->setEnabled(false);
1206 m_tabBar
->blockSignals(false);
1210 void DolphinMainWindow::openTabContextMenu(int index
, const QPoint
& pos
)
1214 QAction
* newTabAction
= menu
.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab"));
1215 newTabAction
->setShortcut(actionCollection()->action("new_tab")->shortcut());
1217 QAction
* detachTabAction
= menu
.addAction(KIcon("tab-detach"), i18nc("@action:inmenu", "Detach Tab"));
1219 QAction
* closeOtherTabsAction
= menu
.addAction(KIcon("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs"));
1221 QAction
* closeTabAction
= menu
.addAction(KIcon("tab-close"), i18nc("@action:inmenu", "Close Tab"));
1222 closeTabAction
->setShortcut(actionCollection()->action("close_tab")->shortcut());
1223 QAction
* selectedAction
= menu
.exec(pos
);
1224 if (selectedAction
== newTabAction
) {
1225 const ViewTab
& tab
= m_viewTab
[index
];
1226 Q_ASSERT(tab
.primaryView
);
1227 const KUrl url
= tab
.secondaryView
&& tab
.secondaryView
->isActive() ?
1228 tab
.secondaryView
->url() : tab
.primaryView
->url();
1230 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
1231 } else if (selectedAction
== detachTabAction
) {
1232 const QString
separator(QLatin1Char(' '));
1233 QString command
= QLatin1String("dolphin");
1235 const ViewTab
& tab
= m_viewTab
[index
];
1236 Q_ASSERT(tab
.primaryView
);
1238 command
+= separator
+ tab
.primaryView
->url().url();
1239 if (tab
.secondaryView
) {
1240 command
+= separator
+ tab
.secondaryView
->url().url();
1241 command
+= separator
+ QLatin1String("-split");
1244 KRun::runCommand(command
, this);
1247 } else if (selectedAction
== closeOtherTabsAction
) {
1248 const int count
= m_tabBar
->count();
1249 for (int i
= 0; i
< index
; ++i
) {
1252 for (int i
= index
+ 1; i
< count
; ++i
) {
1255 } else if (selectedAction
== closeTabAction
) {
1260 void DolphinMainWindow::slotTabMoved(int from
, int to
)
1262 m_viewTab
.move(from
, to
);
1263 m_tabIndex
= m_tabBar
->currentIndex();
1266 void DolphinMainWindow::handlePlacesClick(const KUrl
& url
, Qt::MouseButtons buttons
)
1268 if (buttons
& Qt::MidButton
) {
1270 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
1276 void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent
* event
, bool& canDecode
)
1278 canDecode
= KUrl::List::canDecode(event
->mimeData());
1281 void DolphinMainWindow::handleUrl(const KUrl
& url
)
1283 delete m_lastHandleUrlStatJob
;
1284 m_lastHandleUrlStatJob
= 0;
1286 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1287 activeViewContainer()->setUrl(url
);
1288 } else if (KProtocolManager::supportsListing(url
)) {
1289 // stat the URL to see if it is a dir or not
1290 m_lastHandleUrlStatJob
= KIO::stat(url
, KIO::HideProgressInfo
);
1291 connect(m_lastHandleUrlStatJob
, SIGNAL(result(KJob
*)),
1292 this, SLOT(slotHandleUrlStatFinished(KJob
*)));
1295 new KRun(url
, this);
1299 void DolphinMainWindow::slotHandleUrlStatFinished(KJob
* job
)
1301 m_lastHandleUrlStatJob
= 0;
1302 const KIO::UDSEntry entry
= static_cast<KIO::StatJob
*>(job
)->statResult();
1303 const KUrl url
= static_cast<KIO::StatJob
*>(job
)->url();
1304 if (entry
.isDir()) {
1305 activeViewContainer()->setUrl(url
);
1307 new KRun(url
, this);
1311 void DolphinMainWindow::tabDropEvent(int tab
, QDropEvent
* event
)
1313 const KUrl::List urls
= KUrl::List::fromMimeData(event
->mimeData());
1314 if (!urls
.isEmpty() && tab
!= -1) {
1315 const ViewTab
& viewTab
= m_viewTab
[tab
];
1316 const KUrl destPath
= viewTab
.isPrimaryViewActive
? viewTab
.primaryView
->url() : viewTab
.secondaryView
->url();
1318 //DragAndDropHelper::instance().dropUrls(KFileItem(), destPath, event, m_tabBar);
1322 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1324 newFileMenu()->setEnabled(isFolderWritable
);
1327 void DolphinMainWindow::slotSearchModeChanged(bool enabled
)
1330 const DolphinSearchInformation
& searchInfo
= DolphinSearchInformation::instance();
1331 if (!searchInfo
.isIndexingEnabled()) {
1335 QDockWidget
* searchDock
= findChild
<QDockWidget
*>("searchDock");
1341 if (!searchDock
->isVisible()) {
1342 m_searchDockIsTemporaryVisible
= true;
1346 if (searchDock
->isVisible() && m_searchDockIsTemporaryVisible
) {
1349 m_searchDockIsTemporaryVisible
= false;
1352 SearchPanel
* searchPanel
= qobject_cast
<SearchPanel
*>(searchDock
->widget());
1358 SearchPanel::SearchLocation searchLocation
= SearchPanel::Everywhere
;
1359 const KUrl url
= m_activeViewContainer
->url();
1360 const bool isSearchUrl
= (url
.protocol() == QLatin1String("nepomuksearch"));
1361 if ((SearchSettings::location() == QLatin1String("FromHere") && !isSearchUrl
)) {
1362 searchLocation
= SearchPanel::FromCurrentDir
;
1364 searchPanel
->setSearchLocation(searchLocation
);
1366 searchPanel
->setSearchLocation(SearchPanel::Everywhere
);
1373 void DolphinMainWindow::openContextMenu(const QPoint
& pos
,
1374 const KFileItem
& item
,
1376 const QList
<QAction
*>& customActions
)
1378 QWeakPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, pos
, item
, url
);
1379 contextMenu
.data()->setCustomActions(customActions
);
1380 const DolphinContextMenu::Command command
= contextMenu
.data()->open();
1383 case DolphinContextMenu::OpenParentFolderInNewWindow
: {
1384 KRun::run("dolphin", KUrl::List() << item
.url().upUrl(), this);
1388 case DolphinContextMenu::OpenParentFolderInNewTab
:
1389 openNewTab(item
.url().upUrl());
1392 case DolphinContextMenu::None
:
1397 delete contextMenu
.data();
1400 void DolphinMainWindow::updateToolBarMenu()
1402 KMenu
* menu
= qobject_cast
<KMenu
*>(sender());
1405 // All actions get cleared by KMenu::clear(). The sub-menus are deleted
1406 // by connecting to the aboutToHide() signal from the parent-menu.
1409 KActionCollection
* ac
= actionCollection();
1411 // Add "Edit" actions
1412 bool added
= addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Undo
)), menu
) |
1413 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Find
)), menu
) |
1414 addActionToMenu(ac
->action("select_all"), menu
) |
1415 addActionToMenu(ac
->action("invert_selection"), menu
);
1418 menu
->addSeparator();
1421 // Add "View" actions
1422 if (!GeneralSettings::showZoomSlider()) {
1423 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomIn
)), menu
);
1424 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomOut
)), menu
);
1425 menu
->addSeparator();
1428 added
= addActionToMenu(ac
->action("view_mode"), menu
) |
1429 addActionToMenu(ac
->action("sort"), menu
) |
1430 addActionToMenu(ac
->action("additional_info"), menu
) |
1431 addActionToMenu(ac
->action("show_preview"), menu
) |
1432 addActionToMenu(ac
->action("show_in_groups"), menu
) |
1433 addActionToMenu(ac
->action("show_hidden_files"), menu
);
1436 menu
->addSeparator();
1439 added
= addActionToMenu(ac
->action("split_view"), menu
) |
1440 addActionToMenu(ac
->action("reload"), menu
) |
1441 addActionToMenu(ac
->action("view_properties"), menu
);
1443 menu
->addSeparator();
1446 addActionToMenu(ac
->action("panels"), menu
);
1447 KMenu
* locationBarMenu
= new KMenu(i18nc("@action:inmenu", "Location Bar"), menu
);
1448 locationBarMenu
->addAction(ac
->action("editable_location"));
1449 locationBarMenu
->addAction(ac
->action("replace_location"));
1450 menu
->addMenu(locationBarMenu
);
1452 menu
->addSeparator();
1455 KMenu
* goMenu
= new KMenu(i18nc("@action:inmenu", "Go"), menu
);
1456 connect(menu
, SIGNAL(aboutToHide()), goMenu
, SLOT(deleteLater()));
1457 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Back
)));
1458 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Forward
)));
1459 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Up
)));
1460 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Home
)));
1461 goMenu
->addAction(ac
->action("closed_tabs"));
1462 menu
->addMenu(goMenu
);
1465 KMenu
* toolsMenu
= new KMenu(i18nc("@action:inmenu", "Tools"), menu
);
1466 connect(menu
, SIGNAL(aboutToHide()), toolsMenu
, SLOT(deleteLater()));
1467 toolsMenu
->addAction(ac
->action("show_filter_bar"));
1468 toolsMenu
->addAction(ac
->action("compare_files"));
1469 toolsMenu
->addAction(ac
->action("open_terminal"));
1470 toolsMenu
->addAction(ac
->action("change_remote_encoding"));
1471 menu
->addMenu(toolsMenu
);
1473 // Add "Settings" menu entries
1474 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::KeyBindings
)), menu
);
1475 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ConfigureToolbars
)), menu
);
1476 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Preferences
)), menu
);
1479 KMenu
* helpMenu
= new KMenu(i18nc("@action:inmenu", "Help"), menu
);
1480 connect(menu
, SIGNAL(aboutToHide()), helpMenu
, SLOT(deleteLater()));
1481 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::HelpContents
)));
1482 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::WhatsThis
)));
1483 helpMenu
->addSeparator();
1484 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ReportBug
)));
1485 helpMenu
->addSeparator();
1486 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
)));
1487 helpMenu
->addSeparator();
1488 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::AboutApp
)));
1489 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::AboutKDE
)));
1490 menu
->addMenu(helpMenu
);
1492 menu
->addSeparator();
1493 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ShowMenubar
)), menu
);
1496 void DolphinMainWindow::updateToolBar()
1498 if (!menuBar()->isVisible()) {
1499 createToolBarMenuButton();
1503 void DolphinMainWindow::slotToolBarSpacerDeleted()
1505 m_toolBarSpacer
= 0;
1506 m_updateToolBarTimer
->start();
1509 void DolphinMainWindow::slotToolBarMenuButtonDeleted()
1511 m_openToolBarMenuButton
= 0;
1512 m_updateToolBarTimer
->start();
1515 void DolphinMainWindow::slotToolBarIconSizeChanged(const QSize
& iconSize
)
1517 if (m_openToolBarMenuButton
) {
1518 m_openToolBarMenuButton
->setIconSize(iconSize
);
1522 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer
* viewContainer
)
1524 Q_ASSERT(viewContainer
);
1525 Q_ASSERT((viewContainer
== m_viewTab
[m_tabIndex
].primaryView
) ||
1526 (viewContainer
== m_viewTab
[m_tabIndex
].secondaryView
));
1527 if (m_activeViewContainer
== viewContainer
) {
1531 m_activeViewContainer
->setActive(false);
1532 m_activeViewContainer
= viewContainer
;
1534 // Activating the view container might trigger a recursive setActiveViewContainer() call
1535 // inside DolphinMainWindow::toggleActiveView() when having a split view. Temporary
1536 // disconnect the activated() signal in this case:
1537 disconnect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1538 m_activeViewContainer
->setActive(true);
1539 connect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1541 m_actionHandler
->setCurrentView(viewContainer
->view());
1544 updateEditActions();
1545 updateViewActions();
1548 const KUrl url
= m_activeViewContainer
->url();
1549 setUrlAsCaption(url
);
1550 if (m_viewTab
.count() > 1) {
1551 m_tabBar
->setTabText(m_tabIndex
, tabName(url
));
1552 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(KMimeType::iconNameForUrl(url
)));
1555 emit
urlChanged(url
);
1558 DolphinViewContainer
* DolphinMainWindow::createViewContainer(const KUrl
& url
, QWidget
* parent
)
1560 DolphinViewContainer
* container
= new DolphinViewContainer(url
, parent
);
1562 // The places-selector from the URL navigator should only be shown
1563 // if the places dock is invisible
1564 QDockWidget
* placesDock
= findChild
<QDockWidget
*>("placesDock");
1565 container
->urlNavigator()->setPlacesSelectorVisible(!placesDock
|| !placesDock
->isVisible());
1570 void DolphinMainWindow::setupActions()
1572 // setup 'File' menu
1573 m_newFileMenu
= new DolphinNewFileMenu(this);
1574 KMenu
* menu
= m_newFileMenu
->menu();
1575 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1576 menu
->setIcon(KIcon("document-new"));
1577 connect(menu
, SIGNAL(aboutToShow()),
1578 this, SLOT(updateNewMenu()));
1580 KAction
* newWindow
= actionCollection()->addAction("new_window");
1581 newWindow
->setIcon(KIcon("window-new"));
1582 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1583 newWindow
->setShortcut(Qt::CTRL
| Qt::Key_N
);
1584 connect(newWindow
, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1586 KAction
* newTab
= actionCollection()->addAction("new_tab");
1587 newTab
->setIcon(KIcon("tab-new"));
1588 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1589 newTab
->setShortcut(KShortcut(Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
));
1590 connect(newTab
, SIGNAL(triggered()), this, SLOT(openNewTab()));
1592 KAction
* closeTab
= actionCollection()->addAction("close_tab");
1593 closeTab
->setIcon(KIcon("tab-close"));
1594 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1595 closeTab
->setShortcut(Qt::CTRL
| Qt::Key_W
);
1596 closeTab
->setEnabled(false);
1597 connect(closeTab
, SIGNAL(triggered()), this, SLOT(closeTab()));
1599 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1601 // setup 'Edit' menu
1602 KStandardAction::undo(this,
1604 actionCollection());
1606 // need to remove shift+del from cut action, else the shortcut for deletejob
1608 KAction
* cut
= KStandardAction::cut(this, SLOT(cut()), actionCollection());
1609 KShortcut cutShortcut
= cut
->shortcut();
1610 cutShortcut
.remove(Qt::SHIFT
| Qt::Key_Delete
, KShortcut::KeepEmpty
);
1611 cut
->setShortcut(cutShortcut
);
1612 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1613 KAction
* paste
= KStandardAction::paste(this, SLOT(paste()), actionCollection());
1614 // The text of the paste-action is modified dynamically by Dolphin
1615 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1616 // due to the long text, the text "Paste" is used:
1617 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1619 KStandardAction::find(this, SLOT(find()), actionCollection());
1621 KAction
* selectAll
= actionCollection()->addAction("select_all");
1622 selectAll
->setText(i18nc("@action:inmenu Edit", "Select All"));
1623 selectAll
->setShortcut(Qt::CTRL
| Qt::Key_A
);
1624 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
1626 KAction
* invertSelection
= actionCollection()->addAction("invert_selection");
1627 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1628 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1629 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
1631 // setup 'View' menu
1632 // (note that most of it is set up in DolphinViewActionHandler)
1634 KAction
* split
= actionCollection()->addAction("split_view");
1635 split
->setShortcut(Qt::Key_F3
);
1636 updateSplitAction();
1637 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1639 KAction
* reload
= actionCollection()->addAction("reload");
1640 reload
->setText(i18nc("@action:inmenu View", "Reload"));
1641 reload
->setShortcut(Qt::Key_F5
);
1642 reload
->setIcon(KIcon("view-refresh"));
1643 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
1645 KAction
* stop
= actionCollection()->addAction("stop");
1646 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1647 stop
->setToolTip(i18nc("@info", "Stop loading"));
1648 stop
->setIcon(KIcon("process-stop"));
1649 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
1651 KToggleAction
* editableLocation
= actionCollection()->add
<KToggleAction
>("editable_location");
1652 editableLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1653 editableLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
1654 connect(editableLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1656 KAction
* replaceLocation
= actionCollection()->addAction("replace_location");
1657 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1658 replaceLocation
->setShortcut(Qt::Key_F6
);
1659 connect(replaceLocation
, SIGNAL(triggered()), this, SLOT(replaceLocation()));
1662 KAction
* backAction
= KStandardAction::back(this, SLOT(goBack()), actionCollection());
1663 connect(backAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goBack(Qt::MouseButtons
)));
1664 KShortcut backShortcut
= backAction
->shortcut();
1665 backShortcut
.setAlternate(Qt::Key_Backspace
);
1666 backAction
->setShortcut(backShortcut
);
1668 m_recentTabsMenu
= new KActionMenu(i18n("Recently Closed Tabs"), this);
1669 m_recentTabsMenu
->setIcon(KIcon("edit-undo"));
1670 actionCollection()->addAction("closed_tabs", m_recentTabsMenu
);
1671 connect(m_recentTabsMenu
->menu(), SIGNAL(triggered(QAction
*)),
1672 this, SLOT(restoreClosedTab(QAction
*)));
1674 QAction
* action
= new QAction(i18n("Empty Recently Closed Tabs"), m_recentTabsMenu
);
1675 action
->setIcon(KIcon("edit-clear-list"));
1676 action
->setData(QVariant::fromValue(true));
1677 m_recentTabsMenu
->addAction(action
);
1678 m_recentTabsMenu
->addSeparator();
1679 m_recentTabsMenu
->setEnabled(false);
1681 KAction
* forwardAction
= KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1682 connect(forwardAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goForward(Qt::MouseButtons
)));
1684 KAction
* upAction
= KStandardAction::up(this, SLOT(goUp()), actionCollection());
1685 connect(upAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goUp(Qt::MouseButtons
)));
1687 KStandardAction::home(this, SLOT(goHome()), actionCollection());
1689 // setup 'Tools' menu
1690 KAction
* showFilterBar
= actionCollection()->addAction("show_filter_bar");
1691 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1692 showFilterBar
->setIcon(KIcon("view-filter"));
1693 showFilterBar
->setShortcut(Qt::CTRL
| Qt::Key_I
);
1694 connect(showFilterBar
, SIGNAL(triggered()), this, SLOT(showFilterBar()));
1696 KAction
* compareFiles
= actionCollection()->addAction("compare_files");
1697 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1698 compareFiles
->setIcon(KIcon("kompare"));
1699 compareFiles
->setEnabled(false);
1700 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
1702 KAction
* openTerminal
= actionCollection()->addAction("open_terminal");
1703 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1704 openTerminal
->setIcon(KIcon("utilities-terminal"));
1705 openTerminal
->setShortcut(Qt::SHIFT
| Qt::Key_F4
);
1706 connect(openTerminal
, SIGNAL(triggered()), this, SLOT(openTerminal()));
1708 // setup 'Settings' menu
1709 KToggleAction
* showMenuBar
= KStandardAction::showMenubar(0, 0, actionCollection());
1710 connect(showMenuBar
, SIGNAL(triggered(bool)), // Fixes #286822
1711 this, SLOT(toggleShowMenuBar()), Qt::QueuedConnection
);
1712 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1714 // not in menu actions
1715 QList
<QKeySequence
> nextTabKeys
;
1716 nextTabKeys
.append(KStandardShortcut::tabNext().primary());
1717 nextTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::Key_Tab
));
1719 QList
<QKeySequence
> prevTabKeys
;
1720 prevTabKeys
.append(KStandardShortcut::tabPrev().primary());
1721 prevTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::SHIFT
| Qt::Key_Tab
));
1723 KAction
* activateNextTab
= actionCollection()->addAction("activate_next_tab");
1724 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1725 connect(activateNextTab
, SIGNAL(triggered()), SLOT(activateNextTab()));
1726 activateNextTab
->setShortcuts(QApplication::isRightToLeft() ? prevTabKeys
: nextTabKeys
);
1728 KAction
* activatePrevTab
= actionCollection()->addAction("activate_prev_tab");
1729 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1730 connect(activatePrevTab
, SIGNAL(triggered()), SLOT(activatePrevTab()));
1731 activatePrevTab
->setShortcuts(QApplication::isRightToLeft() ? nextTabKeys
: prevTabKeys
);
1734 KAction
* openInNewTab
= actionCollection()->addAction("open_in_new_tab");
1735 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1736 openInNewTab
->setIcon(KIcon("tab-new"));
1737 connect(openInNewTab
, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1739 KAction
* openInNewWindow
= actionCollection()->addAction("open_in_new_window");
1740 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1741 openInNewWindow
->setIcon(KIcon("window-new"));
1742 connect(openInNewWindow
, SIGNAL(triggered()), this, SLOT(openInNewWindow()));
1745 void DolphinMainWindow::setupDockWidgets()
1747 const bool lock
= GeneralSettings::lockPanels();
1749 KDualAction
* lockLayoutAction
= actionCollection()->add
<KDualAction
>("lock_panels");
1750 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
1751 lockLayoutAction
->setActiveIcon(KIcon("object-unlocked"));
1752 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
1753 lockLayoutAction
->setInactiveIcon(KIcon("object-locked"));
1754 lockLayoutAction
->setActive(lock
);
1755 connect(lockLayoutAction
, SIGNAL(triggered()), this, SLOT(togglePanelLockState()));
1757 // Setup "Information"
1758 DolphinDockWidget
* infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
1759 infoDock
->setLocked(lock
);
1760 infoDock
->setObjectName("infoDock");
1761 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1762 Panel
* infoPanel
= new InformationPanel(infoDock
);
1763 infoPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1764 connect(infoPanel
, SIGNAL(urlActivated(KUrl
)), this, SLOT(handleUrl(KUrl
)));
1765 infoDock
->setWidget(infoPanel
);
1767 QAction
* infoAction
= infoDock
->toggleViewAction();
1768 createPanelAction(KIcon("dialog-information"), Qt::Key_F11
, infoAction
, "show_information_panel");
1770 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1771 connect(this, SIGNAL(urlChanged(KUrl
)),
1772 infoPanel
, SLOT(setUrl(KUrl
)));
1773 connect(this, SIGNAL(selectionChanged(KFileItemList
)),
1774 infoPanel
, SLOT(setSelection(KFileItemList
)));
1775 connect(this, SIGNAL(requestItemInfo(KFileItem
)),
1776 infoPanel
, SLOT(requestDelayedItemInfo(KFileItem
)));
1779 DolphinDockWidget
* foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
1780 foldersDock
->setLocked(lock
);
1781 foldersDock
->setObjectName("foldersDock");
1782 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1783 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1784 foldersPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1785 foldersDock
->setWidget(foldersPanel
);
1787 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1788 createPanelAction(KIcon("folder"), Qt::Key_F7
, foldersAction
, "show_folders_panel");
1790 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1791 connect(this, SIGNAL(urlChanged(KUrl
)),
1792 foldersPanel
, SLOT(setUrl(KUrl
)));
1793 connect(foldersPanel
, SIGNAL(changeUrl(KUrl
,Qt::MouseButtons
)),
1794 this, SLOT(handlePlacesClick(KUrl
,Qt::MouseButtons
)));
1798 DolphinDockWidget
* terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1799 terminalDock
->setLocked(lock
);
1800 terminalDock
->setObjectName("terminalDock");
1801 terminalDock
->setAllowedAreas(Qt::TopDockWidgetArea
| Qt::BottomDockWidgetArea
);
1802 Panel
* terminalPanel
= new TerminalPanel(terminalDock
);
1803 terminalPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1804 terminalDock
->setWidget(terminalPanel
);
1806 connect(terminalPanel
, SIGNAL(hideTerminalPanel()), terminalDock
, SLOT(hide()));
1807 connect(terminalDock
, SIGNAL(visibilityChanged(bool)),
1808 terminalPanel
, SLOT(dockVisibilityChanged()));
1810 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1811 createPanelAction(KIcon("utilities-terminal"), Qt::Key_F4
, terminalAction
, "show_terminal_panel");
1813 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1814 connect(this, SIGNAL(urlChanged(KUrl
)),
1815 terminalPanel
, SLOT(setUrl(KUrl
)));
1820 DolphinDockWidget
* searchDock
= new DolphinDockWidget(i18nc("@title:window", "Search"));
1821 searchDock
->setLocked(lock
);
1822 searchDock
->setObjectName("searchDock");
1823 searchDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1824 Panel
* searchPanel
= new SearchPanel(searchDock
);
1825 searchPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1826 connect(searchPanel
, SIGNAL(urlActivated(KUrl
)), this, SLOT(handleUrl(KUrl
)));
1827 searchDock
->setWidget(searchPanel
);
1829 QAction
* searchAction
= searchDock
->toggleViewAction();
1830 createPanelAction(KIcon("system-search"), Qt::Key_F12
, searchAction
, "show_search_panel");
1831 addDockWidget(Qt::RightDockWidgetArea
, searchDock
);
1832 connect(this, SIGNAL(urlChanged(KUrl
)),
1833 searchPanel
, SLOT(setUrl(KUrl
)));
1836 if (GeneralSettings::version() < 200) {
1838 foldersDock
->hide();
1840 terminalDock
->hide();
1848 DolphinDockWidget
* placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
1849 placesDock
->setLocked(lock
);
1850 placesDock
->setObjectName("placesDock");
1851 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1853 PlacesPanel
* placesPanel
= new PlacesPanel(placesDock
);
1854 QAction
* separator
= new QAction(placesPanel
);
1855 separator
->setSeparator(true);
1856 QList
<QAction
*> placesActions
;
1857 placesActions
.append(separator
);
1858 placesActions
.append(lockLayoutAction
);
1859 placesPanel
->addActions(placesActions
);
1860 placesPanel
->setModel(DolphinPlacesModel::instance());
1861 placesPanel
->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff
);
1862 placesDock
->setWidget(placesPanel
);
1864 QAction
* placesAction
= placesDock
->toggleViewAction();
1865 createPanelAction(KIcon("bookmarks"), Qt::Key_F9
, placesAction
, "show_places_panel");
1867 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1868 connect(placesPanel
, SIGNAL(urlChanged(KUrl
,Qt::MouseButtons
)),
1869 this, SLOT(handlePlacesClick(KUrl
,Qt::MouseButtons
)));
1870 connect(this, SIGNAL(urlChanged(KUrl
)),
1871 placesPanel
, SLOT(setUrl(KUrl
)));
1872 connect(placesDock
, SIGNAL(visibilityChanged(bool)),
1873 this, SLOT(slotPlacesPanelVisibilityChanged(bool)));
1875 // Add actions into the "Panels" menu
1876 KActionMenu
* panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Panels"), this);
1877 actionCollection()->addAction("panels", panelsMenu
);
1878 panelsMenu
->setDelayed(false);
1879 const KActionCollection
* ac
= actionCollection();
1880 panelsMenu
->addAction(ac
->action("show_places_panel"));
1881 panelsMenu
->addAction(ac
->action("show_information_panel"));
1882 panelsMenu
->addAction(ac
->action("show_folders_panel"));
1884 panelsMenu
->addAction(ac
->action("show_terminal_panel"));
1887 panelsMenu
->addAction(ac
->action("show_search_panel"));
1889 panelsMenu
->addSeparator();
1890 panelsMenu
->addAction(lockLayoutAction
);
1893 void DolphinMainWindow::updateEditActions()
1895 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1896 if (list
.isEmpty()) {
1897 stateChanged("has_no_selection");
1899 stateChanged("has_selection");
1901 KActionCollection
* col
= actionCollection();
1902 QAction
* renameAction
= col
->action("rename");
1903 QAction
* moveToTrashAction
= col
->action("move_to_trash");
1904 QAction
* deleteAction
= col
->action("delete");
1905 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
1906 QAction
* deleteWithTrashShortcut
= col
->action("delete_shortcut"); // see DolphinViewActionHandler
1908 KFileItemListProperties
capabilities(list
);
1909 const bool enableMoveToTrash
= capabilities
.isLocal() && capabilities
.supportsMoving();
1911 renameAction
->setEnabled(capabilities
.supportsMoving());
1912 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1913 deleteAction
->setEnabled(capabilities
.supportsDeleting());
1914 deleteWithTrashShortcut
->setEnabled(capabilities
.supportsDeleting() && !enableMoveToTrash
);
1915 cutAction
->setEnabled(capabilities
.supportsMoving());
1917 updatePasteAction();
1920 void DolphinMainWindow::updateViewActions()
1922 m_actionHandler
->updateViewActions();
1924 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1925 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
1927 updateSplitAction();
1929 QAction
* editableLocactionAction
= actionCollection()->action("editable_location");
1930 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
1931 editableLocactionAction
->setChecked(urlNavigator
->isUrlEditable());
1934 void DolphinMainWindow::updateGoActions()
1936 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
1937 const KUrl currentUrl
= m_activeViewContainer
->url();
1938 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
1941 void DolphinMainWindow::createToolBarMenuButton()
1943 if (m_toolBarSpacer
&& m_openToolBarMenuButton
) {
1946 Q_ASSERT(!m_toolBarSpacer
);
1947 Q_ASSERT(!m_openToolBarMenuButton
);
1949 m_toolBarSpacer
= new QWidget(this);
1950 m_toolBarSpacer
->setSizePolicy(QSizePolicy::MinimumExpanding
, QSizePolicy::MinimumExpanding
);
1952 m_openToolBarMenuButton
= new QToolButton(this);
1953 m_openToolBarMenuButton
->setIcon(KIcon("configure"));
1954 m_openToolBarMenuButton
->setPopupMode(QToolButton::InstantPopup
);
1955 m_openToolBarMenuButton
->setToolTip(i18nc("@info:tooltip", "Configure and control Dolphin"));
1957 KMenu
* toolBarMenu
= new ToolBarMenu(m_openToolBarMenuButton
);
1958 connect(toolBarMenu
, SIGNAL(aboutToShow()), this, SLOT(updateToolBarMenu()));
1960 m_openToolBarMenuButton
->setMenu(toolBarMenu
);
1962 toolBar()->addWidget(m_toolBarSpacer
);
1963 toolBar()->addWidget(m_openToolBarMenuButton
);
1964 connect(toolBar(), SIGNAL(iconSizeChanged(QSize
)), this, SLOT(slotToolBarIconSizeChanged(QSize
)));
1966 // The added widgets are owned by the toolbar and may get deleted when e.g. the toolbar
1967 // gets edited. In this case we must add them again. The adding is done asynchronously by
1968 // m_updateToolBarTimer.
1969 connect(m_toolBarSpacer
, SIGNAL(destroyed()), this, SLOT(slotToolBarSpacerDeleted()));
1970 connect(m_openToolBarMenuButton
, SIGNAL(destroyed()), this, SLOT(slotToolBarMenuButtonDeleted()));
1971 m_updateToolBarTimer
= new QTimer(this);
1972 m_updateToolBarTimer
->setInterval(500);
1973 connect(m_updateToolBarTimer
, SIGNAL(timeout()), this, SLOT(updateToolBar()));
1976 void DolphinMainWindow::deleteToolBarMenuButton()
1978 delete m_toolBarSpacer
;
1979 m_toolBarSpacer
= 0;
1981 delete m_openToolBarMenuButton
;
1982 m_openToolBarMenuButton
= 0;
1984 delete m_updateToolBarTimer
;
1985 m_updateToolBarTimer
= 0;
1988 bool DolphinMainWindow::addActionToMenu(QAction
* action
, KMenu
* menu
)
1993 const KToolBar
* toolBarWidget
= toolBar();
1994 foreach (const QWidget
* widget
, action
->associatedWidgets()) {
1995 if (widget
== toolBarWidget
) {
2000 menu
->addAction(action
);
2004 void DolphinMainWindow::rememberClosedTab(int index
)
2006 KMenu
* tabsMenu
= m_recentTabsMenu
->menu();
2008 const QString primaryPath
= m_viewTab
[index
].primaryView
->url().path();
2009 const QString iconName
= KMimeType::iconNameForUrl(primaryPath
);
2011 QAction
* action
= new QAction(squeezedText(primaryPath
), tabsMenu
);
2013 ClosedTab closedTab
;
2014 closedTab
.primaryUrl
= m_viewTab
[index
].primaryView
->url();
2016 if (m_viewTab
[index
].secondaryView
) {
2017 closedTab
.secondaryUrl
= m_viewTab
[index
].secondaryView
->url();
2018 closedTab
.isSplit
= true;
2020 closedTab
.isSplit
= false;
2023 action
->setData(QVariant::fromValue(closedTab
));
2024 action
->setIcon(KIcon(iconName
));
2026 // add the closed tab menu entry after the separator and
2027 // "Empty Recently Closed Tabs" entry
2028 if (tabsMenu
->actions().size() == 2) {
2029 tabsMenu
->addAction(action
);
2031 tabsMenu
->insertAction(tabsMenu
->actions().at(2), action
);
2034 // assure that only up to 8 closed tabs are shown in the menu
2035 if (tabsMenu
->actions().size() > 8) {
2036 tabsMenu
->removeAction(tabsMenu
->actions().last());
2038 actionCollection()->action("closed_tabs")->setEnabled(true);
2039 KAcceleratorManager::manage(tabsMenu
);
2042 void DolphinMainWindow::refreshViews()
2044 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
2046 // remember the current active view, as because of
2047 // the refreshing the active view might change to
2048 // the secondary view
2049 DolphinViewContainer
* activeViewContainer
= m_activeViewContainer
;
2051 const int tabCount
= m_viewTab
.count();
2052 for (int i
= 0; i
< tabCount
; ++i
) {
2053 m_viewTab
[i
].primaryView
->refresh();
2054 if (m_viewTab
[i
].secondaryView
) {
2055 m_viewTab
[i
].secondaryView
->refresh();
2059 setActiveViewContainer(activeViewContainer
);
2061 if (GeneralSettings::modifiedStartupSettings()) {
2062 // The startup settings have been changed by the user (see bug #254947).
2063 // Synchronize the split-view setting with the active view:
2064 const bool splitView
= GeneralSettings::splitView();
2065 const ViewTab
& activeTab
= m_viewTab
[m_tabIndex
];
2066 const bool toggle
= ( splitView
&& !activeTab
.secondaryView
)
2067 || (!splitView
&& activeTab
.secondaryView
);
2074 void DolphinMainWindow::clearStatusBar()
2076 m_activeViewContainer
->statusBar()->clear();
2079 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
2081 connect(container
, SIGNAL(showFilterBarChanged(bool)),
2082 this, SLOT(updateFilterBarAction(bool)));
2083 connect(container
, SIGNAL(writeStateChanged(bool)),
2084 this, SLOT(slotWriteStateChanged(bool)));
2085 connect(container
, SIGNAL(searchModeChanged(bool)),
2086 this, SLOT(slotSearchModeChanged(bool)));
2088 const DolphinSearchBox
* searchBox
= container
->searchBox();
2089 connect(searchBox
, SIGNAL(searchLocationChanged(SearchLocation
)),
2090 this, SLOT(slotSearchLocationChanged()));
2092 DolphinView
* view
= container
->view();
2093 connect(view
, SIGNAL(selectionChanged(KFileItemList
)),
2094 this, SLOT(slotSelectionChanged(KFileItemList
)));
2095 connect(view
, SIGNAL(requestItemInfo(KFileItem
)),
2096 this, SLOT(slotRequestItemInfo(KFileItem
)));
2097 connect(view
, SIGNAL(activated()),
2098 this, SLOT(toggleActiveView()));
2099 connect(view
, SIGNAL(tabRequested(KUrl
)),
2100 this, SLOT(openNewTab(KUrl
)));
2101 connect(view
, SIGNAL(requestContextMenu(QPoint
,KFileItem
,KUrl
,QList
<QAction
*>)),
2102 this, SLOT(openContextMenu(QPoint
,KFileItem
,KUrl
,QList
<QAction
*>)));
2103 connect(view
, SIGNAL(startedPathLoading(KUrl
)),
2104 this, SLOT(enableStopAction()));
2105 connect(view
, SIGNAL(finishedPathLoading(KUrl
)),
2106 this, SLOT(disableStopAction()));
2108 const KUrlNavigator
* navigator
= container
->urlNavigator();
2109 connect(navigator
, SIGNAL(urlChanged(KUrl
)),
2110 this, SLOT(changeUrl(KUrl
)));
2111 connect(navigator
, SIGNAL(historyChanged()),
2112 this, SLOT(updateHistory()));
2113 connect(navigator
, SIGNAL(editableStateChanged(bool)),
2114 this, SLOT(slotEditableStateChanged(bool)));
2115 connect(navigator
, SIGNAL(tabRequested(KUrl
)),
2116 this, SLOT(openNewTab(KUrl
)));
2119 void DolphinMainWindow::updateSplitAction()
2121 QAction
* splitAction
= actionCollection()->action("split_view");
2122 if (m_viewTab
[m_tabIndex
].secondaryView
) {
2123 if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
2124 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
2125 splitAction
->setToolTip(i18nc("@info", "Close right view"));
2126 splitAction
->setIcon(KIcon("view-right-close"));
2128 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
2129 splitAction
->setToolTip(i18nc("@info", "Close left view"));
2130 splitAction
->setIcon(KIcon("view-left-close"));
2133 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
2134 splitAction
->setToolTip(i18nc("@info", "Split view"));
2135 splitAction
->setIcon(KIcon("view-right-new"));
2139 QString
DolphinMainWindow::tabName(const KUrl
& url
) const
2142 if (url
.equals(KUrl("file:///"))) {
2145 name
= url
.fileName();
2146 if (name
.isEmpty()) {
2147 name
= url
.protocol();
2149 // Make sure that a '&' inside the directory name is displayed correctly
2150 // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
2151 name
.replace('&', "&&");
2157 bool DolphinMainWindow::isKompareInstalled() const
2159 static bool initialized
= false;
2160 static bool installed
= false;
2162 // TODO: maybe replace this approach later by using a menu
2163 // plugin like kdiff3plugin.cpp
2164 installed
= !KGlobal::dirs()->findExe("kompare").isEmpty();
2170 void DolphinMainWindow::createSecondaryView(int tabIndex
)
2172 ViewTab
& viewTab
= m_viewTab
[tabIndex
];
2174 QSplitter
* splitter
= viewTab
.splitter
;
2175 const int newWidth
= (viewTab
.primaryView
->width() - splitter
->handleWidth()) / 2;
2177 const DolphinView
* view
= viewTab
.primaryView
->view();
2178 viewTab
.secondaryView
= createViewContainer(view
->url(), 0);
2179 splitter
->addWidget(viewTab
.secondaryView
);
2180 splitter
->setSizes(QList
<int>() << newWidth
<< newWidth
);
2182 connectViewSignals(viewTab
.secondaryView
);
2183 viewTab
.secondaryView
->setActive(false);
2184 viewTab
.secondaryView
->resize(newWidth
, viewTab
.primaryView
->height());
2185 viewTab
.secondaryView
->show();
2188 QString
DolphinMainWindow::tabProperty(const QString
& property
, int tabIndex
) const
2190 return "Tab " + QString::number(tabIndex
) + ' ' + property
;
2193 void DolphinMainWindow::setUrlAsCaption(const KUrl
& url
)
2196 if (!url
.isLocalFile()) {
2197 caption
.append(url
.protocol() + " - ");
2198 if (url
.hasHost()) {
2199 caption
.append(url
.host() + " - ");
2203 const QString fileName
= url
.fileName().isEmpty() ? "/" : url
.fileName();
2204 caption
.append(fileName
);
2206 setCaption(caption
);
2209 QString
DolphinMainWindow::squeezedText(const QString
& text
) const
2211 const QFontMetrics fm
= fontMetrics();
2212 return fm
.elidedText(text
, Qt::ElideMiddle
, fm
.maxWidth() * 10);
2215 void DolphinMainWindow::createPanelAction(const KIcon
& icon
,
2216 const QKeySequence
& shortcut
,
2217 QAction
* dockAction
,
2218 const QString
& actionName
)
2220 KAction
* panelAction
= actionCollection()->addAction(actionName
);
2221 panelAction
->setCheckable(true);
2222 panelAction
->setChecked(dockAction
->isChecked());
2223 panelAction
->setText(dockAction
->text());
2224 panelAction
->setIcon(icon
);
2225 panelAction
->setShortcut(shortcut
);
2227 connect(panelAction
, SIGNAL(triggered()), dockAction
, SLOT(trigger()));
2228 connect(dockAction
, SIGNAL(toggled(bool)), panelAction
, SLOT(setChecked(bool)));
2231 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
2232 KIO::FileUndoManager::UiInterface()
2236 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2240 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
2242 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
2244 DolphinStatusBar
* statusBar
= mainWin
->activeViewContainer()->statusBar();
2245 statusBar
->setMessage(job
->errorString(), DolphinStatusBar::Error
);
2247 KIO::FileUndoManager::UiInterface::jobError(job
);
2251 ToolBarMenu::ToolBarMenu(QWidget
* parent
) :
2256 ToolBarMenu::~ToolBarMenu()
2260 void ToolBarMenu::showEvent(QShowEvent
* event
)
2262 KMenu::showEvent(event
);
2264 // Adjust the position of the menu to be shown within the
2265 // Dolphin window to reduce the cases that sub-menus might overlap
2266 // the right screen border.
2268 QWidget
* button
= parentWidget();
2269 if (layoutDirection() == Qt::RightToLeft
) {
2270 pos
= button
->mapToGlobal(QPoint(0, button
->height()));
2272 pos
= button
->mapToGlobal(QPoint(button
->width(), button
->height()));
2273 pos
.rx() -= width();
2276 // Assure that the menu is not shown outside the screen boundaries and
2277 // that it does not overlap with the parent button.
2278 const QRect screen
= QApplication::desktop()->screenGeometry(QCursor::pos());
2279 if (pos
.x() < screen
.x()) {
2280 pos
.rx() = screen
.x();
2281 } else if (pos
.x() + width() > screen
.x() + screen
.width()) {
2282 pos
.rx() = screen
.x() + screen
.width() - width();
2285 if (pos
.y() < screen
.y()) {
2286 pos
.ry() = screen
.y();
2287 } else if (pos
.y() + height() > screen
.y() + screen
.height()) {
2288 pos
.ry() = button
->mapToGlobal(QPoint(0, 0)).y() - height();
2294 #include "dolphinmainwindow.moc"