1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz19@gmail.com> *
3 * Copyright (C) 2006 by Stefan Monov <logixoul@gmail.com> *
4 * Copyright (C) 2006 by Cvetoslav Ludmiloff <ludmiloff@gmail.com> *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20 ***************************************************************************/
22 #include "dolphinmainwindow.h"
24 #include <config-nepomuk.h>
26 #include "dolphinapplication.h"
27 #include "dolphindockwidget.h"
28 #include "dolphincontextmenu.h"
29 #include "dolphinnewfilemenu.h"
30 #include "dolphinviewcontainer.h"
32 #include "panels/search/searchpanel.h"
33 #include <Nepomuk/ResourceManager>
35 #include "panels/folders/folderspanel.h"
36 #include "panels/places/placespanel.h"
37 #include "panels/information/informationpanel.h"
38 #include "search/dolphinsearchbox.h"
39 #include "search/dolphinsearchinformation.h"
40 #include "settings/dolphinsettingsdialog.h"
41 #include "statusbar/dolphinstatusbar.h"
42 #include "views/dolphinviewactionhandler.h"
43 #include "views/dolphinremoteencoding.h"
44 #include "views/draganddrophelper.h"
45 #include "views/viewproperties.h"
48 #include "panels/terminal/terminalpanel.h"
51 #include "dolphin_generalsettings.h"
52 #include "dolphin_searchsettings.h"
54 #include <KAcceleratorManager>
56 #include <KActionCollection>
57 #include <KActionMenu>
59 #include <KDesktopFile>
60 #include <kdeversion.h>
61 #include <kdualaction.h>
62 #include <KFileDialog>
63 #include <KFilePlacesModel>
68 #include <KIconLoader>
69 #include <KIO/NetAccess>
70 #include <KInputDialog>
72 #include <KProtocolManager>
75 #include <KMessageBox>
76 #include <KFileItemListProperties>
77 #include <konqmimedata.h>
78 #include <KProtocolInfo>
81 #include <KStandardDirs>
82 #include <kstatusbar.h>
83 #include <KStandardAction>
85 #include <KToggleAction>
86 #include <KUrlNavigator>
88 #include <KUrlComboBox>
89 #include <KToolInvocation>
91 #include "views/dolphinplacesmodel.h"
93 #include <QDesktopWidget>
94 #include <QDBusMessage>
97 #include <QToolButton>
101 // Used for GeneralSettings::version() to determine whether
102 // an updated version of Dolphin is running.
103 const int CurrentDolphinVersion
= 200;
107 * Menu shown when pressing the configure-button in the toolbar.
109 class ToolBarMenu
: public KMenu
112 ToolBarMenu(QWidget
* parent
);
113 virtual ~ToolBarMenu();
115 virtual void showEvent(QShowEvent
* event
);
119 * Remembers the tab configuration if a tab has been closed.
120 * Each closed tab can be restored by the menu
121 * "Go -> Recently Closed Tabs".
129 Q_DECLARE_METATYPE(ClosedTab
)
131 DolphinMainWindow::DolphinMainWindow() :
135 m_activeViewContainer(0),
136 m_centralWidgetLayout(0),
143 m_openToolBarMenuButton(0),
144 m_updateToolBarTimer(0),
145 m_lastHandleUrlStatJob(0),
146 m_searchDockIsTemporaryVisible(false)
148 DolphinPlacesModel::setModel(new KFilePlacesModel(this));
149 connect(DolphinPlacesModel::instance(), SIGNAL(errorMessage(QString
)),
150 this, SLOT(showErrorMessage(QString
)));
152 // Workaround for a X11-issue in combination with KModifierInfo
153 // (see DolphinContextMenu::initializeModifierKeyInfo() for
154 // more information):
155 DolphinContextMenu::initializeModifierKeyInfo();
157 setObjectName("Dolphin#");
159 m_viewTab
.append(ViewTab());
160 ViewTab
& viewTab
= m_viewTab
[m_tabIndex
];
161 viewTab
.wasActive
= true; // The first opened tab is automatically active
163 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
164 undoManager
->setUiInterface(new UndoUiInterface());
166 connect(undoManager
, SIGNAL(undoAvailable(bool)),
167 this, SLOT(slotUndoAvailable(bool)));
168 connect(undoManager
, SIGNAL(undoTextChanged(QString
)),
169 this, SLOT(slotUndoTextChanged(QString
)));
170 connect(undoManager
, SIGNAL(jobRecordingStarted(CommandType
)),
171 this, SLOT(clearStatusBar()));
172 connect(undoManager
, SIGNAL(jobRecordingFinished(CommandType
)),
173 this, SLOT(showCommand(CommandType
)));
175 GeneralSettings
* generalSettings
= GeneralSettings::self();
176 const bool firstRun
= (generalSettings
->version() < 200);
178 generalSettings
->setViewPropsTimestamp(QDateTime::currentDateTime());
181 setAcceptDrops(true);
183 viewTab
.splitter
= new QSplitter(this);
184 viewTab
.splitter
->setChildrenCollapsible(false);
188 const KUrl
homeUrl(generalSettings
->homeUrl());
189 setUrlAsCaption(homeUrl
);
190 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
191 connect(m_actionHandler
, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
192 connect(m_actionHandler
, SIGNAL(createDirectory()), SLOT(createDirectory()));
194 viewTab
.primaryView
= createViewContainer(homeUrl
, viewTab
.splitter
);
196 m_activeViewContainer
= viewTab
.primaryView
;
197 connectViewSignals(m_activeViewContainer
);
198 DolphinView
* view
= m_activeViewContainer
->view();
199 m_activeViewContainer
->show();
200 m_actionHandler
->setCurrentView(view
);
202 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
203 connect(this, SIGNAL(urlChanged(KUrl
)),
204 m_remoteEncoding
, SLOT(slotAboutToOpenUrl()));
206 m_tabBar
= new KTabBar(this);
207 m_tabBar
->setMovable(true);
208 m_tabBar
->setTabsClosable(true);
209 connect(m_tabBar
, SIGNAL(currentChanged(int)),
210 this, SLOT(setActiveTab(int)));
211 connect(m_tabBar
, SIGNAL(tabCloseRequested(int)),
212 this, SLOT(closeTab(int)));
213 connect(m_tabBar
, SIGNAL(contextMenu(int,QPoint
)),
214 this, SLOT(openTabContextMenu(int,QPoint
)));
215 connect(m_tabBar
, SIGNAL(newTabRequest()),
216 this, SLOT(openNewTab()));
217 connect(m_tabBar
, SIGNAL(testCanDecode(const QDragMoveEvent
*,bool&)),
218 this, SLOT(slotTestCanDecode(const QDragMoveEvent
*,bool&)));
219 connect(m_tabBar
, SIGNAL(mouseMiddleClick(int)),
220 this, SLOT(closeTab(int)));
221 connect(m_tabBar
, SIGNAL(tabMoved(int,int)),
222 this, SLOT(slotTabMoved(int,int)));
223 connect(m_tabBar
, SIGNAL(receivedDropEvent(int,QDropEvent
*)),
224 this, SLOT(tabDropEvent(int,QDropEvent
*)));
226 m_tabBar
->blockSignals(true); // signals get unblocked after at least 2 tabs are open
228 QWidget
* centralWidget
= new QWidget(this);
229 m_centralWidgetLayout
= new QVBoxLayout(centralWidget
);
230 m_centralWidgetLayout
->setSpacing(0);
231 m_centralWidgetLayout
->setMargin(0);
232 m_centralWidgetLayout
->addWidget(m_tabBar
);
233 m_centralWidgetLayout
->addWidget(viewTab
.splitter
, 1);
235 setCentralWidget(centralWidget
);
237 emit
urlChanged(homeUrl
);
239 setupGUI(Keys
| Save
| Create
| ToolBar
);
240 stateChanged("new_file");
242 QClipboard
* clipboard
= QApplication::clipboard();
243 connect(clipboard
, SIGNAL(dataChanged()),
244 this, SLOT(updatePasteAction()));
246 if (generalSettings
->splitView()) {
253 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
254 showFilterBarAction
->setChecked(generalSettings
->filterBar());
257 menuBar()->setVisible(false);
258 // Assure a proper default size if Dolphin runs the first time
262 const bool showMenu
= !menuBar()->isHidden();
263 QAction
* showMenuBarAction
= actionCollection()->action(KStandardAction::name(KStandardAction::ShowMenubar
));
264 showMenuBarAction
->setChecked(showMenu
); // workaround for bug #171080
266 createToolBarMenuButton();
270 DolphinMainWindow::~DolphinMainWindow()
274 void DolphinMainWindow::openDirectories(const QList
<KUrl
>& dirs
)
276 if (dirs
.isEmpty()) {
280 if (dirs
.count() == 1) {
281 m_activeViewContainer
->setUrl(dirs
.first());
285 const int oldOpenTabsCount
= m_viewTab
.count();
287 const bool hasSplitView
= GeneralSettings::splitView();
289 // Open each directory inside a new tab. If the "split view" option has been enabled,
290 // always show two directories within one tab.
291 QList
<KUrl
>::const_iterator it
= dirs
.begin();
292 while (it
!= dirs
.end()) {
296 if (hasSplitView
&& (it
!= dirs
.end())) {
297 const int tabIndex
= m_viewTab
.count() - 1;
298 m_viewTab
[tabIndex
].secondaryView
->setUrl(*it
);
303 // Remove the previously opened tabs
304 for (int i
= 0; i
< oldOpenTabsCount
; ++i
) {
309 void DolphinMainWindow::openFiles(const QList
<KUrl
>& files
)
311 if (files
.isEmpty()) {
315 // Get all distinct directories from 'files' and open a tab
316 // for each directory. If the "split view" option is enabled, two
317 // directories are shown inside one tab (see openDirectories()).
319 foreach (const KUrl
& url
, files
) {
320 const KUrl
dir(url
.directory());
321 if (!dirs
.contains(dir
)) {
326 openDirectories(dirs
);
328 // Select the files. Although the files can be split between several
329 // tabs, there is no need to split 'files' accordingly, as
330 // the DolphinView will just ignore invalid selections.
331 const int tabCount
= m_viewTab
.count();
332 for (int i
= 0; i
< tabCount
; ++i
) {
333 m_viewTab
[i
].primaryView
->view()->markUrlsAsSelected(files
);
334 m_viewTab
[i
].primaryView
->view()->markUrlAsCurrent(files
.at(0));
335 if (m_viewTab
[i
].secondaryView
) {
336 m_viewTab
[i
].secondaryView
->view()->markUrlsAsSelected(files
);
337 m_viewTab
[i
].secondaryView
->view()->markUrlAsCurrent(files
.at(0));
342 void DolphinMainWindow::showCommand(CommandType command
)
344 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
346 case KIO::FileUndoManager::Copy
:
347 statusBar
->setMessage(i18nc("@info:status", "Successfully copied."),
348 DolphinStatusBar::OperationCompleted
);
350 case KIO::FileUndoManager::Move
:
351 statusBar
->setMessage(i18nc("@info:status", "Successfully moved."),
352 DolphinStatusBar::OperationCompleted
);
354 case KIO::FileUndoManager::Link
:
355 statusBar
->setMessage(i18nc("@info:status", "Successfully linked."),
356 DolphinStatusBar::OperationCompleted
);
358 case KIO::FileUndoManager::Trash
:
359 statusBar
->setMessage(i18nc("@info:status", "Successfully moved to trash."),
360 DolphinStatusBar::OperationCompleted
);
362 case KIO::FileUndoManager::Rename
:
363 statusBar
->setMessage(i18nc("@info:status", "Successfully renamed."),
364 DolphinStatusBar::OperationCompleted
);
367 case KIO::FileUndoManager::Mkdir
:
368 statusBar
->setMessage(i18nc("@info:status", "Created folder."),
369 DolphinStatusBar::OperationCompleted
);
377 void DolphinMainWindow::pasteIntoFolder()
379 m_activeViewContainer
->view()->pasteIntoFolder();
382 void DolphinMainWindow::changeUrl(const KUrl
& url
)
384 if (!KProtocolManager::supportsListing(url
)) {
385 // The URL navigator only checks for validity, not
386 // if the URL can be listed. An error message is
387 // shown due to DolphinViewContainer::restoreView().
391 DolphinViewContainer
* view
= activeViewContainer();
397 setUrlAsCaption(url
);
398 if (m_viewTab
.count() > 1) {
399 m_tabBar
->setTabText(m_tabIndex
, squeezedText(tabName(m_activeViewContainer
->url())));
401 const QString iconName
= KMimeType::iconNameForUrl(url
);
402 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(iconName
));
403 emit
urlChanged(url
);
407 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
409 KToggleAction
* editableLocationAction
=
410 static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
411 editableLocationAction
->setChecked(editable
);
414 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
418 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
419 int selectedUrlsCount
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedItemsCount();
420 if (m_viewTab
[m_tabIndex
].secondaryView
) {
421 selectedUrlsCount
+= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItemsCount();
424 QAction
* compareFilesAction
= actionCollection()->action("compare_files");
425 if (selectedUrlsCount
== 2) {
426 compareFilesAction
->setEnabled(isKompareInstalled());
428 compareFilesAction
->setEnabled(false);
431 emit
selectionChanged(selection
);
434 void DolphinMainWindow::slotRequestItemInfo(const KFileItem
& item
)
436 emit
requestItemInfo(item
);
439 void DolphinMainWindow::updateHistory()
441 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
442 const int index
= urlNavigator
->historyIndex();
444 QAction
* backAction
= actionCollection()->action("go_back");
446 backAction
->setToolTip(i18nc("@info", "Go back"));
447 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
450 QAction
* forwardAction
= actionCollection()->action("go_forward");
452 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
453 forwardAction
->setEnabled(index
> 0);
457 void DolphinMainWindow::updateFilterBarAction(bool show
)
459 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
460 showFilterBarAction
->setChecked(show
);
463 void DolphinMainWindow::openNewMainWindow()
465 KRun::run("dolphin", KUrl::List(), this);
468 void DolphinMainWindow::openNewTab()
470 const bool isUrlEditable
= m_activeViewContainer
->urlNavigator()->isUrlEditable();
472 openNewTab(m_activeViewContainer
->url());
473 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
475 // The URL navigator of the new tab should have the same editable state
476 // as the current tab
477 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
478 navigator
->setUrlEditable(isUrlEditable
);
481 // If a new tab is opened and the URL is editable, assure that
482 // the user can edit the URL without manually setting the focus
483 navigator
->setFocus();
487 void DolphinMainWindow::openNewTab(const KUrl
& url
)
489 QWidget
* focusWidget
= QApplication::focusWidget();
491 if (m_viewTab
.count() == 1) {
492 // Only one view is open currently and hence no tab is shown at
493 // all. Before creating a tab for 'url', provide a tab for the current URL.
494 const KUrl currentUrl
= m_activeViewContainer
->url();
495 m_tabBar
->addTab(KIcon(KMimeType::iconNameForUrl(currentUrl
)),
496 squeezedText(tabName(currentUrl
)));
497 m_tabBar
->blockSignals(false);
500 m_tabBar
->addTab(KIcon(KMimeType::iconNameForUrl(url
)),
501 squeezedText(tabName(url
)));
504 viewTab
.splitter
= new QSplitter(this);
505 viewTab
.splitter
->setChildrenCollapsible(false);
506 viewTab
.primaryView
= createViewContainer(url
, viewTab
.splitter
);
507 viewTab
.primaryView
->setActive(false);
508 connectViewSignals(viewTab
.primaryView
);
510 m_viewTab
.append(viewTab
);
512 actionCollection()->action("close_tab")->setEnabled(true);
514 // Provide a split view, if the startup settings are set this way
515 if (GeneralSettings::splitView()) {
516 const int newTabIndex
= m_viewTab
.count() - 1;
517 createSecondaryView(newTabIndex
);
518 m_viewTab
[newTabIndex
].secondaryView
->setActive(true);
519 m_viewTab
[newTabIndex
].isPrimaryViewActive
= false;
523 // The DolphinViewContainer grabbed the keyboard focus. As the tab is opened
524 // in background, assure that the previous focused widget gets the focus back.
525 focusWidget
->setFocus();
529 void DolphinMainWindow::activateNextTab()
531 if (m_viewTab
.count() >= 2) {
532 const int tabIndex
= (m_tabBar
->currentIndex() + 1) % m_tabBar
->count();
533 m_tabBar
->setCurrentIndex(tabIndex
);
537 void DolphinMainWindow::activatePrevTab()
539 if (m_viewTab
.count() >= 2) {
540 int tabIndex
= m_tabBar
->currentIndex() - 1;
541 if (tabIndex
== -1) {
542 tabIndex
= m_tabBar
->count() - 1;
544 m_tabBar
->setCurrentIndex(tabIndex
);
548 void DolphinMainWindow::openInNewTab()
550 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
551 if (list
.isEmpty()) {
552 openNewTab(m_activeViewContainer
->url());
553 } else if ((list
.count() == 1) && list
[0].isDir()) {
554 openNewTab(list
[0].url());
558 void DolphinMainWindow::openInNewWindow()
562 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
563 if (list
.isEmpty()) {
564 newWindowUrl
= m_activeViewContainer
->url();
565 } else if ((list
.count() == 1) && list
[0].isDir()) {
566 newWindowUrl
= list
[0].url();
569 if (!newWindowUrl
.isEmpty()) {
570 KRun::run("dolphin", KUrl::List() << newWindowUrl
, this);
574 void DolphinMainWindow::toggleActiveView()
576 if (!m_viewTab
[m_tabIndex
].secondaryView
) {
577 // only one view is available
581 Q_ASSERT(m_activeViewContainer
);
582 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
584 DolphinViewContainer
* left
= m_viewTab
[m_tabIndex
].primaryView
;
585 DolphinViewContainer
* right
= m_viewTab
[m_tabIndex
].secondaryView
;
586 setActiveViewContainer(m_activeViewContainer
== right
? left
: right
);
589 void DolphinMainWindow::showEvent(QShowEvent
* event
)
591 KXmlGuiWindow::showEvent(event
);
592 if (!event
->spontaneous()) {
593 m_activeViewContainer
->view()->setFocus();
597 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
599 // Find out if Dolphin is closed directly by the user or
600 // by the session manager because the session is closed
601 bool closedByUser
= true;
602 DolphinApplication
*application
= qobject_cast
<DolphinApplication
*>(qApp
);
603 if (application
&& application
->sessionSaving()) {
604 closedByUser
= false;
607 if (m_viewTab
.count() > 1 && GeneralSettings::confirmClosingMultipleTabs() && closedByUser
) {
608 // Ask the user if he really wants to quit and close all tabs.
609 // Open a confirmation dialog with 3 buttons:
610 // KDialog::Yes -> Quit
611 // KDialog::No -> Close only the current tab
612 // KDialog::Cancel -> do nothing
613 KDialog
*dialog
= new KDialog(this, Qt::Dialog
);
614 dialog
->setCaption(i18nc("@title:window", "Confirmation"));
615 dialog
->setButtons(KDialog::Yes
| KDialog::No
| KDialog::Cancel
);
616 dialog
->setModal(true);
617 dialog
->setButtonGuiItem(KDialog::Yes
, KStandardGuiItem::quit());
618 dialog
->setButtonGuiItem(KDialog::No
, KGuiItem(i18n("C&lose Current Tab"), KIcon("tab-close")));
619 dialog
->setButtonGuiItem(KDialog::Cancel
, KStandardGuiItem::cancel());
620 dialog
->setDefaultButton(KDialog::Yes
);
622 bool doNotAskAgainCheckboxResult
= false;
624 const int result
= KMessageBox::createKMessageBox(dialog
,
625 QMessageBox::Warning
,
626 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
628 i18n("Do not ask again"),
629 &doNotAskAgainCheckboxResult
,
630 KMessageBox::Notify
);
632 if (doNotAskAgainCheckboxResult
) {
633 GeneralSettings::setConfirmClosingMultipleTabs(false);
641 // Close only the current tab
649 GeneralSettings::setVersion(CurrentDolphinVersion
);
650 GeneralSettings::self()->writeConfig();
652 if (m_searchDockIsTemporaryVisible
) {
653 QDockWidget
* searchDock
= findChild
<QDockWidget
*>("searchDock");
657 m_searchDockIsTemporaryVisible
= false;
660 KXmlGuiWindow::closeEvent(event
);
663 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
665 const int tabCount
= m_viewTab
.count();
666 group
.writeEntry("Tab Count", tabCount
);
667 group
.writeEntry("Active Tab Index", m_tabBar
->currentIndex());
669 for (int i
= 0; i
< tabCount
; ++i
) {
670 const DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
671 group
.writeEntry(tabProperty("Primary URL", i
), cont
->url().url());
672 group
.writeEntry(tabProperty("Primary Editable", i
),
673 cont
->urlNavigator()->isUrlEditable());
675 cont
= m_viewTab
[i
].secondaryView
;
677 group
.writeEntry(tabProperty("Secondary URL", i
), cont
->url().url());
678 group
.writeEntry(tabProperty("Secondary Editable", i
),
679 cont
->urlNavigator()->isUrlEditable());
684 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
686 const int tabCount
= group
.readEntry("Tab Count", 1);
687 for (int i
= 0; i
< tabCount
; ++i
) {
688 DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
690 cont
->setUrl(group
.readEntry(tabProperty("Primary URL", i
)));
691 const bool editable
= group
.readEntry(tabProperty("Primary Editable", i
), false);
692 cont
->urlNavigator()->setUrlEditable(editable
);
694 cont
= m_viewTab
[i
].secondaryView
;
695 const QString secondaryUrl
= group
.readEntry(tabProperty("Secondary URL", i
));
696 if (!secondaryUrl
.isEmpty()) {
698 // a secondary view should be shown, but no one is available
699 // currently -> create a new view
701 cont
= m_viewTab
[i
].secondaryView
;
705 cont
->setUrl(secondaryUrl
);
706 const bool editable
= group
.readEntry(tabProperty("Secondary Editable", i
), false);
707 cont
->urlNavigator()->setUrlEditable(editable
);
709 // no secondary view should be shown, but the default setting shows
710 // one already -> close the view
714 // openNewTab() needs to be called only tabCount - 1 times
715 if (i
!= tabCount
- 1) {
720 const int index
= group
.readEntry("Active Tab Index", 0);
721 m_tabBar
->setCurrentIndex(index
);
724 void DolphinMainWindow::updateNewMenu()
726 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
727 m_newFileMenu
->checkUpToDate();
728 m_newFileMenu
->setPopupFiles(activeViewContainer()->url());
731 void DolphinMainWindow::createDirectory()
733 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
734 m_newFileMenu
->setPopupFiles(activeViewContainer()->url());
735 m_newFileMenu
->createDirectory();
738 void DolphinMainWindow::quit()
743 void DolphinMainWindow::showErrorMessage(const QString
& message
)
745 if (!message
.isEmpty()) {
746 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
747 statusBar
->setMessage(message
, DolphinStatusBar::Error
);
751 void DolphinMainWindow::slotUndoAvailable(bool available
)
753 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
755 undoAction
->setEnabled(available
);
759 void DolphinMainWindow::restoreClosedTab(QAction
* action
)
761 if (action
->data().toBool()) {
762 // clear all actions except the "Empty Recently Closed Tabs"
763 // action and the separator
764 QList
<QAction
*> actions
= m_recentTabsMenu
->menu()->actions();
765 const int count
= actions
.size();
766 for (int i
= 2; i
< count
; ++i
) {
767 m_recentTabsMenu
->menu()->removeAction(actions
.at(i
));
770 const ClosedTab closedTab
= action
->data().value
<ClosedTab
>();
771 openNewTab(closedTab
.primaryUrl
);
772 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
774 if (closedTab
.isSplit
) {
775 // create secondary view
777 m_viewTab
[m_tabIndex
].secondaryView
->setUrl(closedTab
.secondaryUrl
);
780 m_recentTabsMenu
->removeAction(action
);
783 if (m_recentTabsMenu
->menu()->actions().count() == 2) {
784 m_recentTabsMenu
->setEnabled(false);
788 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
790 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
792 undoAction
->setText(text
);
796 void DolphinMainWindow::undo()
799 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
800 KIO::FileUndoManager::self()->undo();
803 void DolphinMainWindow::cut()
805 m_activeViewContainer
->view()->cutSelectedItems();
808 void DolphinMainWindow::copy()
810 m_activeViewContainer
->view()->copySelectedItems();
813 void DolphinMainWindow::paste()
815 m_activeViewContainer
->view()->paste();
818 void DolphinMainWindow::find()
820 m_activeViewContainer
->setSearchModeEnabled(true);
823 void DolphinMainWindow::slotSearchLocationChanged()
826 QDockWidget
* searchDock
= findChild
<QDockWidget
*>("searchDock");
831 SearchPanel
* searchPanel
= qobject_cast
<SearchPanel
*>(searchDock
->widget());
833 searchPanel
->setSearchLocation(SearchSettings::location() == QLatin1String("FromHere")
834 ? SearchPanel::FromCurrentDir
835 : SearchPanel::Everywhere
);
840 void DolphinMainWindow::updatePasteAction()
842 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
843 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
844 pasteAction
->setEnabled(pasteInfo
.first
);
845 pasteAction
->setText(pasteInfo
.second
);
848 void DolphinMainWindow::selectAll()
852 // if the URL navigator is editable and focused, select the whole
853 // URL instead of all items of the view
855 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
856 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit(); // krazy:exclude=qclasses
857 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
858 lineEdit
->hasFocus();
860 lineEdit
->selectAll();
862 m_activeViewContainer
->view()->selectAll();
866 void DolphinMainWindow::invertSelection()
869 m_activeViewContainer
->view()->invertSelection();
872 void DolphinMainWindow::toggleSplitView()
874 if (!m_viewTab
[m_tabIndex
].secondaryView
) {
875 createSecondaryView(m_tabIndex
);
876 setActiveViewContainer(m_viewTab
[m_tabIndex
].secondaryView
);
877 } else if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
878 // remove secondary view
879 m_viewTab
[m_tabIndex
].secondaryView
->close();
880 m_viewTab
[m_tabIndex
].secondaryView
->deleteLater();
881 m_viewTab
[m_tabIndex
].secondaryView
= 0;
883 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
885 // The primary view is active and should be closed. Hence from a users point of view
886 // the content of the secondary view should be moved to the primary view.
887 // From an implementation point of view it is more efficient to close
888 // the primary view and exchange the internal pointers afterwards.
890 m_viewTab
[m_tabIndex
].primaryView
->close();
891 m_viewTab
[m_tabIndex
].primaryView
->deleteLater();
892 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
893 m_viewTab
[m_tabIndex
].secondaryView
= 0;
895 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
901 void DolphinMainWindow::reloadView()
904 m_activeViewContainer
->view()->reload();
907 void DolphinMainWindow::stopLoading()
909 m_activeViewContainer
->view()->stopLoading();
912 void DolphinMainWindow::enableStopAction()
914 actionCollection()->action("stop")->setEnabled(true);
917 void DolphinMainWindow::disableStopAction()
919 actionCollection()->action("stop")->setEnabled(false);
922 void DolphinMainWindow::showFilterBar()
924 m_activeViewContainer
->setFilterBarVisible(true);
927 void DolphinMainWindow::toggleEditLocation()
931 QAction
* action
= actionCollection()->action("editable_location");
932 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
933 urlNavigator
->setUrlEditable(action
->isChecked());
936 void DolphinMainWindow::replaceLocation()
938 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
939 navigator
->setUrlEditable(true);
940 navigator
->setFocus();
942 // select the whole text of the combo box editor
943 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit(); // krazy:exclude=qclasses
944 lineEdit
->selectAll();
947 void DolphinMainWindow::togglePanelLockState()
949 const bool newLockState
= !GeneralSettings::lockPanels();
950 foreach (QObject
* child
, children()) {
951 DolphinDockWidget
* dock
= qobject_cast
<DolphinDockWidget
*>(child
);
953 dock
->setLocked(newLockState
);
957 GeneralSettings::setLockPanels(newLockState
);
960 void DolphinMainWindow::slotPlacesPanelVisibilityChanged(bool visible
)
962 const int tabCount
= m_viewTab
.count();
963 for (int i
= 0; i
< tabCount
; ++i
) {
964 ViewTab
& tab
= m_viewTab
[i
];
965 Q_ASSERT(tab
.primaryView
);
966 tab
.primaryView
->urlNavigator()->setPlacesSelectorVisible(!visible
);
967 if (tab
.secondaryView
) {
968 tab
.secondaryView
->urlNavigator()->setPlacesSelectorVisible(!visible
);
973 void DolphinMainWindow::goBack()
975 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
976 urlNavigator
->goBack();
978 if (urlNavigator
->locationState().isEmpty()) {
979 // An empty location state indicates a redirection URL,
980 // which must be skipped too
981 urlNavigator
->goBack();
985 void DolphinMainWindow::goForward()
987 m_activeViewContainer
->urlNavigator()->goForward();
990 void DolphinMainWindow::goUp()
992 m_activeViewContainer
->urlNavigator()->goUp();
995 void DolphinMainWindow::goHome()
997 m_activeViewContainer
->urlNavigator()->goHome();
1000 void DolphinMainWindow::goBack(Qt::MouseButtons buttons
)
1002 // The default case (left button pressed) is handled in goBack().
1003 if (buttons
== Qt::MidButton
) {
1004 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
1005 const int index
= urlNavigator
->historyIndex() + 1;
1006 openNewTab(urlNavigator
->locationUrl(index
));
1010 void DolphinMainWindow::goForward(Qt::MouseButtons buttons
)
1012 // The default case (left button pressed) is handled in goForward().
1013 if (buttons
== Qt::MidButton
) {
1014 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
1015 const int index
= urlNavigator
->historyIndex() - 1;
1016 openNewTab(urlNavigator
->locationUrl(index
));
1020 void DolphinMainWindow::goUp(Qt::MouseButtons buttons
)
1022 // The default case (left button pressed) is handled in goUp().
1023 if (buttons
== Qt::MidButton
) {
1024 openNewTab(activeViewContainer()->url().upUrl());
1028 void DolphinMainWindow::goHome(Qt::MouseButtons buttons
)
1030 // The default case (left button pressed) is handled in goHome().
1031 if (buttons
== Qt::MidButton
) {
1032 openNewTab(GeneralSettings::self()->homeUrl());
1036 void DolphinMainWindow::compareFiles()
1038 // The method is only invoked if exactly 2 files have
1039 // been selected. The selected files may be:
1040 // - both in the primary view
1041 // - both in the secondary view
1042 // - one in the primary view and the other in the secondary
1044 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
1049 KFileItemList items
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedItems();
1051 switch (items
.count()) {
1053 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
);
1054 items
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItems();
1055 Q_ASSERT(items
.count() == 2);
1056 urlA
= items
[0].url();
1057 urlB
= items
[1].url();
1062 urlA
= items
[0].url();
1063 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
);
1064 items
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItems();
1065 Q_ASSERT(items
.count() == 1);
1066 urlB
= items
[0].url();
1071 urlA
= items
[0].url();
1072 urlB
= items
[1].url();
1077 // may not happen: compareFiles may only get invoked if 2
1078 // files are selected
1083 QString
command("kompare -c \"");
1084 command
.append(urlA
.pathOrUrl());
1085 command
.append("\" \"");
1086 command
.append(urlB
.pathOrUrl());
1087 command
.append('\"');
1088 KRun::runCommand(command
, "Kompare", "kompare", this);
1091 void DolphinMainWindow::toggleShowMenuBar()
1093 const bool visible
= menuBar()->isVisible();
1094 menuBar()->setVisible(!visible
);
1096 createToolBarMenuButton();
1098 deleteToolBarMenuButton();
1102 void DolphinMainWindow::openTerminal()
1104 QString
dir(QDir::homePath());
1106 // If the given directory is not local, it can still be the URL of an
1107 // ioslave using UDS_LOCAL_PATH which to be converted first.
1108 KUrl url
= KIO::NetAccess::mostLocalUrl(m_activeViewContainer
->url(), this);
1110 //If the URL is local after the above conversion, set the directory.
1111 if (url
.isLocalFile()) {
1112 dir
= url
.toLocalFile();
1115 KToolInvocation::invokeTerminal(QString(), dir
);
1118 void DolphinMainWindow::editSettings()
1120 if (!m_settingsDialog
) {
1121 DolphinViewContainer
* container
= activeViewContainer();
1122 container
->view()->writeSettings();
1124 const KUrl url
= container
->url();
1125 DolphinSettingsDialog
* settingsDialog
= new DolphinSettingsDialog(url
, this);
1126 connect(settingsDialog
, SIGNAL(settingsChanged()), this, SLOT(refreshViews()));
1127 settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1128 settingsDialog
->show();
1129 m_settingsDialog
= settingsDialog
;
1131 m_settingsDialog
.data()->raise();
1135 void DolphinMainWindow::setActiveTab(int index
)
1137 Q_ASSERT(index
>= 0);
1138 Q_ASSERT(index
< m_viewTab
.count());
1139 if (index
== m_tabIndex
) {
1143 // hide current tab content
1144 ViewTab
& hiddenTab
= m_viewTab
[m_tabIndex
];
1145 hiddenTab
.isPrimaryViewActive
= hiddenTab
.primaryView
->isActive();
1146 hiddenTab
.primaryView
->setActive(false);
1147 if (hiddenTab
.secondaryView
) {
1148 hiddenTab
.secondaryView
->setActive(false);
1150 QSplitter
* splitter
= m_viewTab
[m_tabIndex
].splitter
;
1152 m_centralWidgetLayout
->removeWidget(splitter
);
1154 // show active tab content
1157 ViewTab
& viewTab
= m_viewTab
[index
];
1158 m_centralWidgetLayout
->addWidget(viewTab
.splitter
, 1);
1159 viewTab
.primaryView
->show();
1160 if (viewTab
.secondaryView
) {
1161 viewTab
.secondaryView
->show();
1163 viewTab
.splitter
->show();
1165 if (!viewTab
.wasActive
) {
1166 viewTab
.wasActive
= true;
1168 // If the tab has not been activated yet the size of the KItemListView is
1169 // undefined and results in an unwanted animation. To prevent this a
1170 // reloading of the directory gets triggered.
1171 viewTab
.primaryView
->view()->reload();
1172 if (viewTab
.secondaryView
) {
1173 viewTab
.secondaryView
->view()->reload();
1177 setActiveViewContainer(viewTab
.isPrimaryViewActive
? viewTab
.primaryView
:
1178 viewTab
.secondaryView
);
1181 void DolphinMainWindow::closeTab()
1183 closeTab(m_tabBar
->currentIndex());
1186 void DolphinMainWindow::closeTab(int index
)
1188 Q_ASSERT(index
>= 0);
1189 Q_ASSERT(index
< m_viewTab
.count());
1190 if (m_viewTab
.count() == 1) {
1191 // the last tab may never get closed
1195 if (index
== m_tabIndex
) {
1196 // The tab that should be closed is the active tab. Activate the
1197 // previous tab before closing the tab.
1198 m_tabBar
->setCurrentIndex((index
> 0) ? index
- 1 : 1);
1200 rememberClosedTab(index
);
1203 m_viewTab
[index
].primaryView
->deleteLater();
1204 if (m_viewTab
[index
].secondaryView
) {
1205 m_viewTab
[index
].secondaryView
->deleteLater();
1207 m_viewTab
[index
].splitter
->deleteLater();
1208 m_viewTab
.erase(m_viewTab
.begin() + index
);
1210 m_tabBar
->blockSignals(true);
1211 m_tabBar
->removeTab(index
);
1213 if (m_tabIndex
> index
) {
1215 Q_ASSERT(m_tabIndex
>= 0);
1218 // if only one tab is left, also remove the tab entry so that
1219 // closing the last tab is not possible
1220 if (m_viewTab
.count() == 1) {
1221 m_tabBar
->removeTab(0);
1222 actionCollection()->action("close_tab")->setEnabled(false);
1224 m_tabBar
->blockSignals(false);
1228 void DolphinMainWindow::openTabContextMenu(int index
, const QPoint
& pos
)
1232 QAction
* newTabAction
= menu
.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab"));
1233 newTabAction
->setShortcut(actionCollection()->action("new_tab")->shortcut());
1235 QAction
* detachTabAction
= menu
.addAction(KIcon("tab-detach"), i18nc("@action:inmenu", "Detach Tab"));
1237 QAction
* closeOtherTabsAction
= menu
.addAction(KIcon("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs"));
1239 QAction
* closeTabAction
= menu
.addAction(KIcon("tab-close"), i18nc("@action:inmenu", "Close Tab"));
1240 closeTabAction
->setShortcut(actionCollection()->action("close_tab")->shortcut());
1241 QAction
* selectedAction
= menu
.exec(pos
);
1242 if (selectedAction
== newTabAction
) {
1243 const ViewTab
& tab
= m_viewTab
[index
];
1244 Q_ASSERT(tab
.primaryView
);
1245 const KUrl url
= tab
.secondaryView
&& tab
.secondaryView
->isActive() ?
1246 tab
.secondaryView
->url() : tab
.primaryView
->url();
1248 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
1249 } else if (selectedAction
== detachTabAction
) {
1250 const QString
separator(QLatin1Char(' '));
1251 QString command
= QLatin1String("dolphin");
1253 const ViewTab
& tab
= m_viewTab
[index
];
1254 Q_ASSERT(tab
.primaryView
);
1256 command
+= separator
+ tab
.primaryView
->url().url();
1257 if (tab
.secondaryView
) {
1258 command
+= separator
+ tab
.secondaryView
->url().url();
1259 command
+= separator
+ QLatin1String("-split");
1262 KRun::runCommand(command
, this);
1265 } else if (selectedAction
== closeOtherTabsAction
) {
1266 const int count
= m_tabBar
->count();
1267 for (int i
= 0; i
< index
; ++i
) {
1270 for (int i
= index
+ 1; i
< count
; ++i
) {
1273 } else if (selectedAction
== closeTabAction
) {
1278 void DolphinMainWindow::slotTabMoved(int from
, int to
)
1280 m_viewTab
.move(from
, to
);
1281 m_tabIndex
= m_tabBar
->currentIndex();
1284 void DolphinMainWindow::handlePlacesClick(const KUrl
& url
, Qt::MouseButtons buttons
)
1286 if (buttons
& Qt::MidButton
) {
1288 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
1294 void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent
* event
, bool& canDecode
)
1296 canDecode
= KUrl::List::canDecode(event
->mimeData());
1299 void DolphinMainWindow::handleUrl(const KUrl
& url
)
1301 delete m_lastHandleUrlStatJob
;
1302 m_lastHandleUrlStatJob
= 0;
1304 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1305 activeViewContainer()->setUrl(url
);
1306 } else if (KProtocolManager::supportsListing(url
)) {
1307 // stat the URL to see if it is a dir or not
1308 m_lastHandleUrlStatJob
= KIO::stat(url
, KIO::HideProgressInfo
);
1309 connect(m_lastHandleUrlStatJob
, SIGNAL(result(KJob
*)),
1310 this, SLOT(slotHandleUrlStatFinished(KJob
*)));
1313 new KRun(url
, this);
1317 void DolphinMainWindow::slotHandleUrlStatFinished(KJob
* job
)
1319 m_lastHandleUrlStatJob
= 0;
1320 const KIO::UDSEntry entry
= static_cast<KIO::StatJob
*>(job
)->statResult();
1321 const KUrl url
= static_cast<KIO::StatJob
*>(job
)->url();
1322 if (entry
.isDir()) {
1323 activeViewContainer()->setUrl(url
);
1325 new KRun(url
, this);
1329 void DolphinMainWindow::tabDropEvent(int tab
, QDropEvent
* event
)
1331 const KUrl::List urls
= KUrl::List::fromMimeData(event
->mimeData());
1332 if (!urls
.isEmpty() && tab
!= -1) {
1333 const ViewTab
& viewTab
= m_viewTab
[tab
];
1334 const DolphinView
* view
= viewTab
.isPrimaryViewActive
? viewTab
.primaryView
->view()
1335 : viewTab
.secondaryView
->view();
1336 DragAndDropHelper::dropUrls(view
->rootItem(), view
->url(), event
);
1340 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1342 newFileMenu()->setEnabled(isFolderWritable
);
1345 void DolphinMainWindow::slotSearchModeChanged(bool enabled
)
1348 const DolphinSearchInformation
& searchInfo
= DolphinSearchInformation::instance();
1349 if (!searchInfo
.isIndexingEnabled()) {
1353 QDockWidget
* searchDock
= findChild
<QDockWidget
*>("searchDock");
1359 if (!searchDock
->isVisible()) {
1360 m_searchDockIsTemporaryVisible
= true;
1364 if (searchDock
->isVisible() && m_searchDockIsTemporaryVisible
) {
1367 m_searchDockIsTemporaryVisible
= false;
1370 SearchPanel
* searchPanel
= qobject_cast
<SearchPanel
*>(searchDock
->widget());
1376 SearchPanel::SearchLocation searchLocation
= SearchPanel::Everywhere
;
1377 const KUrl url
= m_activeViewContainer
->url();
1378 const bool isSearchUrl
= (url
.protocol() == QLatin1String("nepomuksearch"));
1379 if ((SearchSettings::location() == QLatin1String("FromHere") && !isSearchUrl
)) {
1380 searchLocation
= SearchPanel::FromCurrentDir
;
1382 searchPanel
->setSearchLocation(searchLocation
);
1384 searchPanel
->setSearchLocation(SearchPanel::Everywhere
);
1391 void DolphinMainWindow::openContextMenu(const QPoint
& pos
,
1392 const KFileItem
& item
,
1394 const QList
<QAction
*>& customActions
)
1396 QWeakPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, pos
, item
, url
);
1397 contextMenu
.data()->setCustomActions(customActions
);
1398 const DolphinContextMenu::Command command
= contextMenu
.data()->open();
1401 case DolphinContextMenu::OpenParentFolderInNewWindow
: {
1402 KRun::run("dolphin", KUrl::List() << item
.url().upUrl(), this);
1406 case DolphinContextMenu::OpenParentFolderInNewTab
:
1407 openNewTab(item
.url().upUrl());
1410 case DolphinContextMenu::None
:
1415 delete contextMenu
.data();
1418 void DolphinMainWindow::updateToolBarMenu()
1420 KMenu
* menu
= qobject_cast
<KMenu
*>(sender());
1423 // All actions get cleared by KMenu::clear(). The sub-menus are deleted
1424 // by connecting to the aboutToHide() signal from the parent-menu.
1427 KActionCollection
* ac
= actionCollection();
1429 // Add "Edit" actions
1430 bool added
= addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Undo
)), menu
) |
1431 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Find
)), menu
) |
1432 addActionToMenu(ac
->action("select_all"), menu
) |
1433 addActionToMenu(ac
->action("invert_selection"), menu
);
1436 menu
->addSeparator();
1439 // Add "View" actions
1440 if (!GeneralSettings::showZoomSlider()) {
1441 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomIn
)), menu
);
1442 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomOut
)), menu
);
1443 menu
->addSeparator();
1446 added
= addActionToMenu(ac
->action("view_mode"), menu
) |
1447 addActionToMenu(ac
->action("sort"), menu
) |
1448 addActionToMenu(ac
->action("additional_info"), menu
) |
1449 addActionToMenu(ac
->action("show_preview"), menu
) |
1450 addActionToMenu(ac
->action("show_in_groups"), menu
) |
1451 addActionToMenu(ac
->action("show_hidden_files"), menu
);
1454 menu
->addSeparator();
1457 added
= addActionToMenu(ac
->action("split_view"), menu
) |
1458 addActionToMenu(ac
->action("reload"), menu
) |
1459 addActionToMenu(ac
->action("view_properties"), menu
);
1461 menu
->addSeparator();
1464 addActionToMenu(ac
->action("panels"), menu
);
1465 KMenu
* locationBarMenu
= new KMenu(i18nc("@action:inmenu", "Location Bar"), menu
);
1466 locationBarMenu
->addAction(ac
->action("editable_location"));
1467 locationBarMenu
->addAction(ac
->action("replace_location"));
1468 menu
->addMenu(locationBarMenu
);
1470 menu
->addSeparator();
1473 KMenu
* goMenu
= new KMenu(i18nc("@action:inmenu", "Go"), menu
);
1474 connect(menu
, SIGNAL(aboutToHide()), goMenu
, SLOT(deleteLater()));
1475 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Back
)));
1476 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Forward
)));
1477 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Up
)));
1478 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Home
)));
1479 goMenu
->addAction(ac
->action("closed_tabs"));
1480 menu
->addMenu(goMenu
);
1483 KMenu
* toolsMenu
= new KMenu(i18nc("@action:inmenu", "Tools"), menu
);
1484 connect(menu
, SIGNAL(aboutToHide()), toolsMenu
, SLOT(deleteLater()));
1485 toolsMenu
->addAction(ac
->action("show_filter_bar"));
1486 toolsMenu
->addAction(ac
->action("compare_files"));
1487 toolsMenu
->addAction(ac
->action("open_terminal"));
1488 toolsMenu
->addAction(ac
->action("change_remote_encoding"));
1489 menu
->addMenu(toolsMenu
);
1491 // Add "Settings" menu entries
1492 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::KeyBindings
)), menu
);
1493 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ConfigureToolbars
)), menu
);
1494 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Preferences
)), menu
);
1497 KMenu
* helpMenu
= new KMenu(i18nc("@action:inmenu", "Help"), menu
);
1498 connect(menu
, SIGNAL(aboutToHide()), helpMenu
, SLOT(deleteLater()));
1499 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::HelpContents
)));
1500 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::WhatsThis
)));
1501 helpMenu
->addSeparator();
1502 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ReportBug
)));
1503 helpMenu
->addSeparator();
1504 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
)));
1505 helpMenu
->addSeparator();
1506 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::AboutApp
)));
1507 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::AboutKDE
)));
1508 menu
->addMenu(helpMenu
);
1510 menu
->addSeparator();
1511 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ShowMenubar
)), menu
);
1514 void DolphinMainWindow::updateToolBar()
1516 if (!menuBar()->isVisible()) {
1517 createToolBarMenuButton();
1521 void DolphinMainWindow::slotToolBarSpacerDeleted()
1523 m_toolBarSpacer
= 0;
1524 m_updateToolBarTimer
->start();
1527 void DolphinMainWindow::slotToolBarMenuButtonDeleted()
1529 m_openToolBarMenuButton
= 0;
1530 m_updateToolBarTimer
->start();
1533 void DolphinMainWindow::slotToolBarIconSizeChanged(const QSize
& iconSize
)
1535 if (m_openToolBarMenuButton
) {
1536 m_openToolBarMenuButton
->setIconSize(iconSize
);
1540 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer
* viewContainer
)
1542 Q_ASSERT(viewContainer
);
1543 Q_ASSERT((viewContainer
== m_viewTab
[m_tabIndex
].primaryView
) ||
1544 (viewContainer
== m_viewTab
[m_tabIndex
].secondaryView
));
1545 if (m_activeViewContainer
== viewContainer
) {
1549 m_activeViewContainer
->setActive(false);
1550 m_activeViewContainer
= viewContainer
;
1552 // Activating the view container might trigger a recursive setActiveViewContainer() call
1553 // inside DolphinMainWindow::toggleActiveView() when having a split view. Temporary
1554 // disconnect the activated() signal in this case:
1555 disconnect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1556 m_activeViewContainer
->setActive(true);
1557 connect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1559 m_actionHandler
->setCurrentView(viewContainer
->view());
1562 updateEditActions();
1563 updateViewActions();
1566 const KUrl url
= m_activeViewContainer
->url();
1567 setUrlAsCaption(url
);
1568 if (m_viewTab
.count() > 1) {
1569 m_tabBar
->setTabText(m_tabIndex
, tabName(url
));
1570 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(KMimeType::iconNameForUrl(url
)));
1573 emit
urlChanged(url
);
1576 DolphinViewContainer
* DolphinMainWindow::createViewContainer(const KUrl
& url
, QWidget
* parent
)
1578 DolphinViewContainer
* container
= new DolphinViewContainer(url
, parent
);
1580 // The places-selector from the URL navigator should only be shown
1581 // if the places dock is invisible
1582 QDockWidget
* placesDock
= findChild
<QDockWidget
*>("placesDock");
1583 container
->urlNavigator()->setPlacesSelectorVisible(!placesDock
|| !placesDock
->isVisible());
1588 void DolphinMainWindow::setupActions()
1590 // setup 'File' menu
1591 m_newFileMenu
= new DolphinNewFileMenu(this);
1592 KMenu
* menu
= m_newFileMenu
->menu();
1593 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1594 menu
->setIcon(KIcon("document-new"));
1595 connect(menu
, SIGNAL(aboutToShow()),
1596 this, SLOT(updateNewMenu()));
1598 KAction
* newWindow
= actionCollection()->addAction("new_window");
1599 newWindow
->setIcon(KIcon("window-new"));
1600 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1601 newWindow
->setShortcut(Qt::CTRL
| Qt::Key_N
);
1602 connect(newWindow
, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1604 KAction
* newTab
= actionCollection()->addAction("new_tab");
1605 newTab
->setIcon(KIcon("tab-new"));
1606 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1607 newTab
->setShortcut(KShortcut(Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
));
1608 connect(newTab
, SIGNAL(triggered()), this, SLOT(openNewTab()));
1610 KAction
* closeTab
= actionCollection()->addAction("close_tab");
1611 closeTab
->setIcon(KIcon("tab-close"));
1612 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1613 closeTab
->setShortcut(Qt::CTRL
| Qt::Key_W
);
1614 closeTab
->setEnabled(false);
1615 connect(closeTab
, SIGNAL(triggered()), this, SLOT(closeTab()));
1617 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1619 // setup 'Edit' menu
1620 KStandardAction::undo(this,
1622 actionCollection());
1624 // need to remove shift+del from cut action, else the shortcut for deletejob
1626 KAction
* cut
= KStandardAction::cut(this, SLOT(cut()), actionCollection());
1627 KShortcut cutShortcut
= cut
->shortcut();
1628 cutShortcut
.remove(Qt::SHIFT
| Qt::Key_Delete
, KShortcut::KeepEmpty
);
1629 cut
->setShortcut(cutShortcut
);
1630 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1631 KAction
* paste
= KStandardAction::paste(this, SLOT(paste()), actionCollection());
1632 // The text of the paste-action is modified dynamically by Dolphin
1633 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1634 // due to the long text, the text "Paste" is used:
1635 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1637 KStandardAction::find(this, SLOT(find()), actionCollection());
1639 KAction
* selectAll
= actionCollection()->addAction("select_all");
1640 selectAll
->setText(i18nc("@action:inmenu Edit", "Select All"));
1641 selectAll
->setShortcut(Qt::CTRL
| Qt::Key_A
);
1642 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
1644 KAction
* invertSelection
= actionCollection()->addAction("invert_selection");
1645 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1646 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1647 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
1649 // setup 'View' menu
1650 // (note that most of it is set up in DolphinViewActionHandler)
1652 KAction
* split
= actionCollection()->addAction("split_view");
1653 split
->setShortcut(Qt::Key_F3
);
1654 updateSplitAction();
1655 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1657 KAction
* reload
= actionCollection()->addAction("reload");
1658 reload
->setText(i18nc("@action:inmenu View", "Reload"));
1659 reload
->setShortcut(Qt::Key_F5
);
1660 reload
->setIcon(KIcon("view-refresh"));
1661 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
1663 KAction
* stop
= actionCollection()->addAction("stop");
1664 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1665 stop
->setToolTip(i18nc("@info", "Stop loading"));
1666 stop
->setIcon(KIcon("process-stop"));
1667 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
1669 KToggleAction
* editableLocation
= actionCollection()->add
<KToggleAction
>("editable_location");
1670 editableLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1671 editableLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
1672 connect(editableLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1674 KAction
* replaceLocation
= actionCollection()->addAction("replace_location");
1675 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1676 replaceLocation
->setShortcut(Qt::Key_F6
);
1677 connect(replaceLocation
, SIGNAL(triggered()), this, SLOT(replaceLocation()));
1680 KAction
* backAction
= KStandardAction::back(this, SLOT(goBack()), actionCollection());
1681 connect(backAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goBack(Qt::MouseButtons
)));
1682 KShortcut backShortcut
= backAction
->shortcut();
1683 backShortcut
.setAlternate(Qt::Key_Backspace
);
1684 backAction
->setShortcut(backShortcut
);
1686 m_recentTabsMenu
= new KActionMenu(i18n("Recently Closed Tabs"), this);
1687 m_recentTabsMenu
->setIcon(KIcon("edit-undo"));
1688 actionCollection()->addAction("closed_tabs", m_recentTabsMenu
);
1689 connect(m_recentTabsMenu
->menu(), SIGNAL(triggered(QAction
*)),
1690 this, SLOT(restoreClosedTab(QAction
*)));
1692 QAction
* action
= new QAction(i18n("Empty Recently Closed Tabs"), m_recentTabsMenu
);
1693 action
->setIcon(KIcon("edit-clear-list"));
1694 action
->setData(QVariant::fromValue(true));
1695 m_recentTabsMenu
->addAction(action
);
1696 m_recentTabsMenu
->addSeparator();
1697 m_recentTabsMenu
->setEnabled(false);
1699 KAction
* forwardAction
= KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1700 connect(forwardAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goForward(Qt::MouseButtons
)));
1702 KAction
* upAction
= KStandardAction::up(this, SLOT(goUp()), actionCollection());
1703 connect(upAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goUp(Qt::MouseButtons
)));
1705 KAction
* homeAction
= KStandardAction::home(this, SLOT(goHome()), actionCollection());
1706 connect(homeAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goHome(Qt::MouseButtons
)));
1708 // setup 'Tools' menu
1709 KAction
* showFilterBar
= actionCollection()->addAction("show_filter_bar");
1710 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1711 showFilterBar
->setIcon(KIcon("view-filter"));
1712 showFilterBar
->setShortcut(Qt::CTRL
| Qt::Key_I
);
1713 connect(showFilterBar
, SIGNAL(triggered()), this, SLOT(showFilterBar()));
1715 KAction
* compareFiles
= actionCollection()->addAction("compare_files");
1716 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1717 compareFiles
->setIcon(KIcon("kompare"));
1718 compareFiles
->setEnabled(false);
1719 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
1721 KAction
* openTerminal
= actionCollection()->addAction("open_terminal");
1722 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1723 openTerminal
->setIcon(KIcon("utilities-terminal"));
1724 openTerminal
->setShortcut(Qt::SHIFT
| Qt::Key_F4
);
1725 connect(openTerminal
, SIGNAL(triggered()), this, SLOT(openTerminal()));
1727 // setup 'Settings' menu
1728 KToggleAction
* showMenuBar
= KStandardAction::showMenubar(0, 0, actionCollection());
1729 connect(showMenuBar
, SIGNAL(triggered(bool)), // Fixes #286822
1730 this, SLOT(toggleShowMenuBar()), Qt::QueuedConnection
);
1731 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1733 // not in menu actions
1734 QList
<QKeySequence
> nextTabKeys
;
1735 nextTabKeys
.append(KStandardShortcut::tabNext().primary());
1736 nextTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::Key_Tab
));
1738 QList
<QKeySequence
> prevTabKeys
;
1739 prevTabKeys
.append(KStandardShortcut::tabPrev().primary());
1740 prevTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::SHIFT
| Qt::Key_Tab
));
1742 KAction
* activateNextTab
= actionCollection()->addAction("activate_next_tab");
1743 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1744 connect(activateNextTab
, SIGNAL(triggered()), SLOT(activateNextTab()));
1745 activateNextTab
->setShortcuts(QApplication::isRightToLeft() ? prevTabKeys
: nextTabKeys
);
1747 KAction
* activatePrevTab
= actionCollection()->addAction("activate_prev_tab");
1748 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1749 connect(activatePrevTab
, SIGNAL(triggered()), SLOT(activatePrevTab()));
1750 activatePrevTab
->setShortcuts(QApplication::isRightToLeft() ? nextTabKeys
: prevTabKeys
);
1753 KAction
* openInNewTab
= actionCollection()->addAction("open_in_new_tab");
1754 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1755 openInNewTab
->setIcon(KIcon("tab-new"));
1756 connect(openInNewTab
, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1758 KAction
* openInNewWindow
= actionCollection()->addAction("open_in_new_window");
1759 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1760 openInNewWindow
->setIcon(KIcon("window-new"));
1761 connect(openInNewWindow
, SIGNAL(triggered()), this, SLOT(openInNewWindow()));
1764 void DolphinMainWindow::setupDockWidgets()
1766 const bool lock
= GeneralSettings::lockPanels();
1768 KDualAction
* lockLayoutAction
= actionCollection()->add
<KDualAction
>("lock_panels");
1769 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
1770 lockLayoutAction
->setActiveIcon(KIcon("object-unlocked"));
1771 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
1772 lockLayoutAction
->setInactiveIcon(KIcon("object-locked"));
1773 lockLayoutAction
->setActive(lock
);
1774 connect(lockLayoutAction
, SIGNAL(triggered()), this, SLOT(togglePanelLockState()));
1776 // Setup "Information"
1777 DolphinDockWidget
* infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
1778 infoDock
->setLocked(lock
);
1779 infoDock
->setObjectName("infoDock");
1780 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1781 Panel
* infoPanel
= new InformationPanel(infoDock
);
1782 infoPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1783 connect(infoPanel
, SIGNAL(urlActivated(KUrl
)), this, SLOT(handleUrl(KUrl
)));
1784 infoDock
->setWidget(infoPanel
);
1786 QAction
* infoAction
= infoDock
->toggleViewAction();
1787 createPanelAction(KIcon("dialog-information"), Qt::Key_F11
, infoAction
, "show_information_panel");
1789 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1790 connect(this, SIGNAL(urlChanged(KUrl
)),
1791 infoPanel
, SLOT(setUrl(KUrl
)));
1792 connect(this, SIGNAL(selectionChanged(KFileItemList
)),
1793 infoPanel
, SLOT(setSelection(KFileItemList
)));
1794 connect(this, SIGNAL(requestItemInfo(KFileItem
)),
1795 infoPanel
, SLOT(requestDelayedItemInfo(KFileItem
)));
1798 DolphinDockWidget
* foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
1799 foldersDock
->setLocked(lock
);
1800 foldersDock
->setObjectName("foldersDock");
1801 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1802 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1803 foldersPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1804 foldersDock
->setWidget(foldersPanel
);
1806 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1807 createPanelAction(KIcon("folder"), Qt::Key_F7
, foldersAction
, "show_folders_panel");
1809 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1810 connect(this, SIGNAL(urlChanged(KUrl
)),
1811 foldersPanel
, SLOT(setUrl(KUrl
)));
1812 connect(foldersPanel
, SIGNAL(changeUrl(KUrl
,Qt::MouseButtons
)),
1813 this, SLOT(handlePlacesClick(KUrl
,Qt::MouseButtons
)));
1817 DolphinDockWidget
* terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1818 terminalDock
->setLocked(lock
);
1819 terminalDock
->setObjectName("terminalDock");
1820 terminalDock
->setAllowedAreas(Qt::TopDockWidgetArea
| Qt::BottomDockWidgetArea
);
1821 Panel
* terminalPanel
= new TerminalPanel(terminalDock
);
1822 terminalPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1823 terminalDock
->setWidget(terminalPanel
);
1825 connect(terminalPanel
, SIGNAL(hideTerminalPanel()), terminalDock
, SLOT(hide()));
1826 connect(terminalDock
, SIGNAL(visibilityChanged(bool)),
1827 terminalPanel
, SLOT(dockVisibilityChanged()));
1829 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1830 createPanelAction(KIcon("utilities-terminal"), Qt::Key_F4
, terminalAction
, "show_terminal_panel");
1832 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1833 connect(this, SIGNAL(urlChanged(KUrl
)),
1834 terminalPanel
, SLOT(setUrl(KUrl
)));
1839 DolphinDockWidget
* searchDock
= new DolphinDockWidget(i18nc("@title:window", "Search"));
1840 searchDock
->setLocked(lock
);
1841 searchDock
->setObjectName("searchDock");
1842 searchDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1843 Panel
* searchPanel
= new SearchPanel(searchDock
);
1844 searchPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1845 connect(searchPanel
, SIGNAL(urlActivated(KUrl
)), this, SLOT(handleUrl(KUrl
)));
1846 searchDock
->setWidget(searchPanel
);
1848 QAction
* searchAction
= searchDock
->toggleViewAction();
1849 createPanelAction(KIcon("system-search"), Qt::Key_F12
, searchAction
, "show_search_panel");
1850 addDockWidget(Qt::RightDockWidgetArea
, searchDock
);
1851 connect(this, SIGNAL(urlChanged(KUrl
)),
1852 searchPanel
, SLOT(setUrl(KUrl
)));
1855 if (GeneralSettings::version() < 200) {
1857 foldersDock
->hide();
1859 terminalDock
->hide();
1867 DolphinDockWidget
* placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
1868 placesDock
->setLocked(lock
);
1869 placesDock
->setObjectName("placesDock");
1870 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1872 PlacesPanel
* placesPanel
= new PlacesPanel(placesDock
);
1873 QAction
* separator
= new QAction(placesPanel
);
1874 separator
->setSeparator(true);
1875 QList
<QAction
*> placesActions
;
1876 placesActions
.append(separator
);
1877 placesActions
.append(lockLayoutAction
);
1878 placesPanel
->addActions(placesActions
);
1879 placesPanel
->setModel(DolphinPlacesModel::instance());
1880 placesPanel
->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff
);
1881 placesDock
->setWidget(placesPanel
);
1883 QAction
* placesAction
= placesDock
->toggleViewAction();
1884 createPanelAction(KIcon("bookmarks"), Qt::Key_F9
, placesAction
, "show_places_panel");
1886 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1887 connect(placesPanel
, SIGNAL(urlChanged(KUrl
,Qt::MouseButtons
)),
1888 this, SLOT(handlePlacesClick(KUrl
,Qt::MouseButtons
)));
1889 connect(this, SIGNAL(urlChanged(KUrl
)),
1890 placesPanel
, SLOT(setUrl(KUrl
)));
1891 connect(placesDock
, SIGNAL(visibilityChanged(bool)),
1892 this, SLOT(slotPlacesPanelVisibilityChanged(bool)));
1894 // Add actions into the "Panels" menu
1895 KActionMenu
* panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Panels"), this);
1896 actionCollection()->addAction("panels", panelsMenu
);
1897 panelsMenu
->setDelayed(false);
1898 const KActionCollection
* ac
= actionCollection();
1899 panelsMenu
->addAction(ac
->action("show_places_panel"));
1900 panelsMenu
->addAction(ac
->action("show_information_panel"));
1901 panelsMenu
->addAction(ac
->action("show_folders_panel"));
1903 panelsMenu
->addAction(ac
->action("show_terminal_panel"));
1906 panelsMenu
->addAction(ac
->action("show_search_panel"));
1908 panelsMenu
->addSeparator();
1909 panelsMenu
->addAction(lockLayoutAction
);
1912 void DolphinMainWindow::updateEditActions()
1914 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1915 if (list
.isEmpty()) {
1916 stateChanged("has_no_selection");
1918 stateChanged("has_selection");
1920 KActionCollection
* col
= actionCollection();
1921 QAction
* renameAction
= col
->action("rename");
1922 QAction
* moveToTrashAction
= col
->action("move_to_trash");
1923 QAction
* deleteAction
= col
->action("delete");
1924 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
1925 QAction
* deleteWithTrashShortcut
= col
->action("delete_shortcut"); // see DolphinViewActionHandler
1927 KFileItemListProperties
capabilities(list
);
1928 const bool enableMoveToTrash
= capabilities
.isLocal() && capabilities
.supportsMoving();
1930 renameAction
->setEnabled(capabilities
.supportsMoving());
1931 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1932 deleteAction
->setEnabled(capabilities
.supportsDeleting());
1933 deleteWithTrashShortcut
->setEnabled(capabilities
.supportsDeleting() && !enableMoveToTrash
);
1934 cutAction
->setEnabled(capabilities
.supportsMoving());
1936 updatePasteAction();
1939 void DolphinMainWindow::updateViewActions()
1941 m_actionHandler
->updateViewActions();
1943 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1944 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
1946 updateSplitAction();
1948 QAction
* editableLocactionAction
= actionCollection()->action("editable_location");
1949 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
1950 editableLocactionAction
->setChecked(urlNavigator
->isUrlEditable());
1953 void DolphinMainWindow::updateGoActions()
1955 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
1956 const KUrl currentUrl
= m_activeViewContainer
->url();
1957 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
1960 void DolphinMainWindow::createToolBarMenuButton()
1962 if (m_toolBarSpacer
&& m_openToolBarMenuButton
) {
1965 Q_ASSERT(!m_toolBarSpacer
);
1966 Q_ASSERT(!m_openToolBarMenuButton
);
1968 m_toolBarSpacer
= new QWidget(this);
1969 m_toolBarSpacer
->setSizePolicy(QSizePolicy::MinimumExpanding
, QSizePolicy::MinimumExpanding
);
1971 m_openToolBarMenuButton
= new QToolButton(this);
1972 m_openToolBarMenuButton
->setIcon(KIcon("configure"));
1973 m_openToolBarMenuButton
->setPopupMode(QToolButton::InstantPopup
);
1974 m_openToolBarMenuButton
->setToolTip(i18nc("@info:tooltip", "Configure and control Dolphin"));
1976 KMenu
* toolBarMenu
= new ToolBarMenu(m_openToolBarMenuButton
);
1977 connect(toolBarMenu
, SIGNAL(aboutToShow()), this, SLOT(updateToolBarMenu()));
1979 m_openToolBarMenuButton
->setMenu(toolBarMenu
);
1981 toolBar()->addWidget(m_toolBarSpacer
);
1982 toolBar()->addWidget(m_openToolBarMenuButton
);
1983 connect(toolBar(), SIGNAL(iconSizeChanged(QSize
)), this, SLOT(slotToolBarIconSizeChanged(QSize
)));
1985 // The added widgets are owned by the toolbar and may get deleted when e.g. the toolbar
1986 // gets edited. In this case we must add them again. The adding is done asynchronously by
1987 // m_updateToolBarTimer.
1988 connect(m_toolBarSpacer
, SIGNAL(destroyed()), this, SLOT(slotToolBarSpacerDeleted()));
1989 connect(m_openToolBarMenuButton
, SIGNAL(destroyed()), this, SLOT(slotToolBarMenuButtonDeleted()));
1990 m_updateToolBarTimer
= new QTimer(this);
1991 m_updateToolBarTimer
->setInterval(500);
1992 connect(m_updateToolBarTimer
, SIGNAL(timeout()), this, SLOT(updateToolBar()));
1995 void DolphinMainWindow::deleteToolBarMenuButton()
1997 delete m_toolBarSpacer
;
1998 m_toolBarSpacer
= 0;
2000 delete m_openToolBarMenuButton
;
2001 m_openToolBarMenuButton
= 0;
2003 delete m_updateToolBarTimer
;
2004 m_updateToolBarTimer
= 0;
2007 bool DolphinMainWindow::addActionToMenu(QAction
* action
, KMenu
* menu
)
2012 const KToolBar
* toolBarWidget
= toolBar();
2013 foreach (const QWidget
* widget
, action
->associatedWidgets()) {
2014 if (widget
== toolBarWidget
) {
2019 menu
->addAction(action
);
2023 void DolphinMainWindow::rememberClosedTab(int index
)
2025 KMenu
* tabsMenu
= m_recentTabsMenu
->menu();
2027 const QString primaryPath
= m_viewTab
[index
].primaryView
->url().path();
2028 const QString iconName
= KMimeType::iconNameForUrl(primaryPath
);
2030 QAction
* action
= new QAction(squeezedText(primaryPath
), tabsMenu
);
2032 ClosedTab closedTab
;
2033 closedTab
.primaryUrl
= m_viewTab
[index
].primaryView
->url();
2035 if (m_viewTab
[index
].secondaryView
) {
2036 closedTab
.secondaryUrl
= m_viewTab
[index
].secondaryView
->url();
2037 closedTab
.isSplit
= true;
2039 closedTab
.isSplit
= false;
2042 action
->setData(QVariant::fromValue(closedTab
));
2043 action
->setIcon(KIcon(iconName
));
2045 // add the closed tab menu entry after the separator and
2046 // "Empty Recently Closed Tabs" entry
2047 if (tabsMenu
->actions().size() == 2) {
2048 tabsMenu
->addAction(action
);
2050 tabsMenu
->insertAction(tabsMenu
->actions().at(2), action
);
2053 // assure that only up to 8 closed tabs are shown in the menu
2054 if (tabsMenu
->actions().size() > 8) {
2055 tabsMenu
->removeAction(tabsMenu
->actions().last());
2057 actionCollection()->action("closed_tabs")->setEnabled(true);
2058 KAcceleratorManager::manage(tabsMenu
);
2061 void DolphinMainWindow::refreshViews()
2063 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
2065 // remember the current active view, as because of
2066 // the refreshing the active view might change to
2067 // the secondary view
2068 DolphinViewContainer
* activeViewContainer
= m_activeViewContainer
;
2070 const int tabCount
= m_viewTab
.count();
2071 for (int i
= 0; i
< tabCount
; ++i
) {
2072 m_viewTab
[i
].primaryView
->readSettings();
2073 if (m_viewTab
[i
].secondaryView
) {
2074 m_viewTab
[i
].secondaryView
->readSettings();
2078 setActiveViewContainer(activeViewContainer
);
2080 if (GeneralSettings::modifiedStartupSettings()) {
2081 // The startup settings have been changed by the user (see bug #254947).
2082 // Synchronize the split-view setting with the active view:
2083 const bool splitView
= GeneralSettings::splitView();
2084 const ViewTab
& activeTab
= m_viewTab
[m_tabIndex
];
2085 const bool toggle
= ( splitView
&& !activeTab
.secondaryView
)
2086 || (!splitView
&& activeTab
.secondaryView
);
2093 void DolphinMainWindow::clearStatusBar()
2095 m_activeViewContainer
->statusBar()->clear();
2098 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
2100 connect(container
, SIGNAL(showFilterBarChanged(bool)),
2101 this, SLOT(updateFilterBarAction(bool)));
2102 connect(container
, SIGNAL(writeStateChanged(bool)),
2103 this, SLOT(slotWriteStateChanged(bool)));
2104 connect(container
, SIGNAL(searchModeChanged(bool)),
2105 this, SLOT(slotSearchModeChanged(bool)));
2107 const DolphinSearchBox
* searchBox
= container
->searchBox();
2108 connect(searchBox
, SIGNAL(searchLocationChanged(SearchLocation
)),
2109 this, SLOT(slotSearchLocationChanged()));
2111 DolphinView
* view
= container
->view();
2112 connect(view
, SIGNAL(selectionChanged(KFileItemList
)),
2113 this, SLOT(slotSelectionChanged(KFileItemList
)));
2114 connect(view
, SIGNAL(requestItemInfo(KFileItem
)),
2115 this, SLOT(slotRequestItemInfo(KFileItem
)));
2116 connect(view
, SIGNAL(activated()),
2117 this, SLOT(toggleActiveView()));
2118 connect(view
, SIGNAL(tabRequested(KUrl
)),
2119 this, SLOT(openNewTab(KUrl
)));
2120 connect(view
, SIGNAL(requestContextMenu(QPoint
,KFileItem
,KUrl
,QList
<QAction
*>)),
2121 this, SLOT(openContextMenu(QPoint
,KFileItem
,KUrl
,QList
<QAction
*>)));
2122 connect(view
, SIGNAL(startedPathLoading(KUrl
)),
2123 this, SLOT(enableStopAction()));
2124 connect(view
, SIGNAL(finishedPathLoading(KUrl
)),
2125 this, SLOT(disableStopAction()));
2127 const KUrlNavigator
* navigator
= container
->urlNavigator();
2128 connect(navigator
, SIGNAL(urlChanged(KUrl
)),
2129 this, SLOT(changeUrl(KUrl
)));
2130 connect(navigator
, SIGNAL(historyChanged()),
2131 this, SLOT(updateHistory()));
2132 connect(navigator
, SIGNAL(editableStateChanged(bool)),
2133 this, SLOT(slotEditableStateChanged(bool)));
2134 connect(navigator
, SIGNAL(tabRequested(KUrl
)),
2135 this, SLOT(openNewTab(KUrl
)));
2138 void DolphinMainWindow::updateSplitAction()
2140 QAction
* splitAction
= actionCollection()->action("split_view");
2141 if (m_viewTab
[m_tabIndex
].secondaryView
) {
2142 if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
2143 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
2144 splitAction
->setToolTip(i18nc("@info", "Close right view"));
2145 splitAction
->setIcon(KIcon("view-right-close"));
2147 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
2148 splitAction
->setToolTip(i18nc("@info", "Close left view"));
2149 splitAction
->setIcon(KIcon("view-left-close"));
2152 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
2153 splitAction
->setToolTip(i18nc("@info", "Split view"));
2154 splitAction
->setIcon(KIcon("view-right-new"));
2158 QString
DolphinMainWindow::tabName(const KUrl
& url
) const
2161 if (url
.equals(KUrl("file:///"))) {
2164 name
= url
.fileName();
2165 if (name
.isEmpty()) {
2166 name
= url
.protocol();
2168 // Make sure that a '&' inside the directory name is displayed correctly
2169 // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
2170 name
.replace('&', "&&");
2176 bool DolphinMainWindow::isKompareInstalled() const
2178 static bool initialized
= false;
2179 static bool installed
= false;
2181 // TODO: maybe replace this approach later by using a menu
2182 // plugin like kdiff3plugin.cpp
2183 installed
= !KGlobal::dirs()->findExe("kompare").isEmpty();
2189 void DolphinMainWindow::createSecondaryView(int tabIndex
)
2191 ViewTab
& viewTab
= m_viewTab
[tabIndex
];
2193 QSplitter
* splitter
= viewTab
.splitter
;
2194 const int newWidth
= (viewTab
.primaryView
->width() - splitter
->handleWidth()) / 2;
2196 const DolphinView
* view
= viewTab
.primaryView
->view();
2197 viewTab
.secondaryView
= createViewContainer(view
->url(), 0);
2198 splitter
->addWidget(viewTab
.secondaryView
);
2199 splitter
->setSizes(QList
<int>() << newWidth
<< newWidth
);
2201 connectViewSignals(viewTab
.secondaryView
);
2202 viewTab
.secondaryView
->setActive(false);
2203 viewTab
.secondaryView
->resize(newWidth
, viewTab
.primaryView
->height());
2204 viewTab
.secondaryView
->show();
2207 QString
DolphinMainWindow::tabProperty(const QString
& property
, int tabIndex
) const
2209 return "Tab " + QString::number(tabIndex
) + ' ' + property
;
2212 void DolphinMainWindow::setUrlAsCaption(const KUrl
& url
)
2215 if (!url
.isLocalFile()) {
2216 caption
.append(url
.protocol() + " - ");
2217 if (url
.hasHost()) {
2218 caption
.append(url
.host() + " - ");
2222 const QString fileName
= url
.fileName().isEmpty() ? "/" : url
.fileName();
2223 caption
.append(fileName
);
2225 setCaption(caption
);
2228 QString
DolphinMainWindow::squeezedText(const QString
& text
) const
2230 const QFontMetrics fm
= fontMetrics();
2231 return fm
.elidedText(text
, Qt::ElideMiddle
, fm
.maxWidth() * 10);
2234 void DolphinMainWindow::createPanelAction(const KIcon
& icon
,
2235 const QKeySequence
& shortcut
,
2236 QAction
* dockAction
,
2237 const QString
& actionName
)
2239 KAction
* panelAction
= actionCollection()->addAction(actionName
);
2240 panelAction
->setCheckable(true);
2241 panelAction
->setChecked(dockAction
->isChecked());
2242 panelAction
->setText(dockAction
->text());
2243 panelAction
->setIcon(icon
);
2244 panelAction
->setShortcut(shortcut
);
2246 connect(panelAction
, SIGNAL(triggered()), dockAction
, SLOT(trigger()));
2247 connect(dockAction
, SIGNAL(toggled(bool)), panelAction
, SLOT(setChecked(bool)));
2250 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
2251 KIO::FileUndoManager::UiInterface()
2255 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2259 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
2261 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
2263 DolphinStatusBar
* statusBar
= mainWin
->activeViewContainer()->statusBar();
2264 statusBar
->setMessage(job
->errorString(), DolphinStatusBar::Error
);
2266 KIO::FileUndoManager::UiInterface::jobError(job
);
2270 ToolBarMenu::ToolBarMenu(QWidget
* parent
) :
2275 ToolBarMenu::~ToolBarMenu()
2279 void ToolBarMenu::showEvent(QShowEvent
* event
)
2281 KMenu::showEvent(event
);
2283 // Adjust the position of the menu to be shown within the
2284 // Dolphin window to reduce the cases that sub-menus might overlap
2285 // the right screen border.
2287 QWidget
* button
= parentWidget();
2288 if (layoutDirection() == Qt::RightToLeft
) {
2289 pos
= button
->mapToGlobal(QPoint(0, button
->height()));
2291 pos
= button
->mapToGlobal(QPoint(button
->width(), button
->height()));
2292 pos
.rx() -= width();
2295 // Assure that the menu is not shown outside the screen boundaries and
2296 // that it does not overlap with the parent button.
2297 const QRect screen
= QApplication::desktop()->screenGeometry(QCursor::pos());
2298 if (pos
.x() < screen
.x()) {
2299 pos
.rx() = screen
.x();
2300 } else if (pos
.x() + width() > screen
.x() + screen
.width()) {
2301 pos
.rx() = screen
.x() + screen
.width() - width();
2304 if (pos
.y() < screen
.y()) {
2305 pos
.ry() = screen
.y();
2306 } else if (pos
.y() + height() > screen
.y() + screen
.height()) {
2307 pos
.ry() = button
->mapToGlobal(QPoint(0, 0)).y() - height();
2313 #include "dolphinmainwindow.moc"