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 const KUrl url
= activeViewContainer()->url();
1122 DolphinSettingsDialog
* settingsDialog
= new DolphinSettingsDialog(url
, this);
1123 connect(settingsDialog
, SIGNAL(settingsChanged()), this, SLOT(refreshViews()));
1124 settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1125 settingsDialog
->show();
1126 m_settingsDialog
= settingsDialog
;
1128 m_settingsDialog
.data()->raise();
1132 void DolphinMainWindow::setActiveTab(int index
)
1134 Q_ASSERT(index
>= 0);
1135 Q_ASSERT(index
< m_viewTab
.count());
1136 if (index
== m_tabIndex
) {
1140 // hide current tab content
1141 ViewTab
& hiddenTab
= m_viewTab
[m_tabIndex
];
1142 hiddenTab
.isPrimaryViewActive
= hiddenTab
.primaryView
->isActive();
1143 hiddenTab
.primaryView
->setActive(false);
1144 if (hiddenTab
.secondaryView
) {
1145 hiddenTab
.secondaryView
->setActive(false);
1147 QSplitter
* splitter
= m_viewTab
[m_tabIndex
].splitter
;
1149 m_centralWidgetLayout
->removeWidget(splitter
);
1151 // show active tab content
1154 ViewTab
& viewTab
= m_viewTab
[index
];
1155 m_centralWidgetLayout
->addWidget(viewTab
.splitter
, 1);
1156 viewTab
.primaryView
->show();
1157 if (viewTab
.secondaryView
) {
1158 viewTab
.secondaryView
->show();
1160 viewTab
.splitter
->show();
1162 if (!viewTab
.wasActive
) {
1163 viewTab
.wasActive
= true;
1165 // If the tab has not been activated yet the size of the KItemListView is
1166 // undefined and results in an unwanted animation. To prevent this a
1167 // reloading of the directory gets triggered.
1168 viewTab
.primaryView
->view()->reload();
1169 if (viewTab
.secondaryView
) {
1170 viewTab
.secondaryView
->view()->reload();
1174 setActiveViewContainer(viewTab
.isPrimaryViewActive
? viewTab
.primaryView
:
1175 viewTab
.secondaryView
);
1178 void DolphinMainWindow::closeTab()
1180 closeTab(m_tabBar
->currentIndex());
1183 void DolphinMainWindow::closeTab(int index
)
1185 Q_ASSERT(index
>= 0);
1186 Q_ASSERT(index
< m_viewTab
.count());
1187 if (m_viewTab
.count() == 1) {
1188 // the last tab may never get closed
1192 if (index
== m_tabIndex
) {
1193 // The tab that should be closed is the active tab. Activate the
1194 // previous tab before closing the tab.
1195 m_tabBar
->setCurrentIndex((index
> 0) ? index
- 1 : 1);
1197 rememberClosedTab(index
);
1200 m_viewTab
[index
].primaryView
->deleteLater();
1201 if (m_viewTab
[index
].secondaryView
) {
1202 m_viewTab
[index
].secondaryView
->deleteLater();
1204 m_viewTab
[index
].splitter
->deleteLater();
1205 m_viewTab
.erase(m_viewTab
.begin() + index
);
1207 m_tabBar
->blockSignals(true);
1208 m_tabBar
->removeTab(index
);
1210 if (m_tabIndex
> index
) {
1212 Q_ASSERT(m_tabIndex
>= 0);
1215 // if only one tab is left, also remove the tab entry so that
1216 // closing the last tab is not possible
1217 if (m_viewTab
.count() == 1) {
1218 m_tabBar
->removeTab(0);
1219 actionCollection()->action("close_tab")->setEnabled(false);
1221 m_tabBar
->blockSignals(false);
1225 void DolphinMainWindow::openTabContextMenu(int index
, const QPoint
& pos
)
1229 QAction
* newTabAction
= menu
.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab"));
1230 newTabAction
->setShortcut(actionCollection()->action("new_tab")->shortcut());
1232 QAction
* detachTabAction
= menu
.addAction(KIcon("tab-detach"), i18nc("@action:inmenu", "Detach Tab"));
1234 QAction
* closeOtherTabsAction
= menu
.addAction(KIcon("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs"));
1236 QAction
* closeTabAction
= menu
.addAction(KIcon("tab-close"), i18nc("@action:inmenu", "Close Tab"));
1237 closeTabAction
->setShortcut(actionCollection()->action("close_tab")->shortcut());
1238 QAction
* selectedAction
= menu
.exec(pos
);
1239 if (selectedAction
== newTabAction
) {
1240 const ViewTab
& tab
= m_viewTab
[index
];
1241 Q_ASSERT(tab
.primaryView
);
1242 const KUrl url
= tab
.secondaryView
&& tab
.secondaryView
->isActive() ?
1243 tab
.secondaryView
->url() : tab
.primaryView
->url();
1245 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
1246 } else if (selectedAction
== detachTabAction
) {
1247 const QString
separator(QLatin1Char(' '));
1248 QString command
= QLatin1String("dolphin");
1250 const ViewTab
& tab
= m_viewTab
[index
];
1251 Q_ASSERT(tab
.primaryView
);
1253 command
+= separator
+ tab
.primaryView
->url().url();
1254 if (tab
.secondaryView
) {
1255 command
+= separator
+ tab
.secondaryView
->url().url();
1256 command
+= separator
+ QLatin1String("-split");
1259 KRun::runCommand(command
, this);
1262 } else if (selectedAction
== closeOtherTabsAction
) {
1263 const int count
= m_tabBar
->count();
1264 for (int i
= 0; i
< index
; ++i
) {
1267 for (int i
= index
+ 1; i
< count
; ++i
) {
1270 } else if (selectedAction
== closeTabAction
) {
1275 void DolphinMainWindow::slotTabMoved(int from
, int to
)
1277 m_viewTab
.move(from
, to
);
1278 m_tabIndex
= m_tabBar
->currentIndex();
1281 void DolphinMainWindow::handlePlacesClick(const KUrl
& url
, Qt::MouseButtons buttons
)
1283 if (buttons
& Qt::MidButton
) {
1285 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
1291 void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent
* event
, bool& canDecode
)
1293 canDecode
= KUrl::List::canDecode(event
->mimeData());
1296 void DolphinMainWindow::handleUrl(const KUrl
& url
)
1298 delete m_lastHandleUrlStatJob
;
1299 m_lastHandleUrlStatJob
= 0;
1301 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1302 activeViewContainer()->setUrl(url
);
1303 } else if (KProtocolManager::supportsListing(url
)) {
1304 // stat the URL to see if it is a dir or not
1305 m_lastHandleUrlStatJob
= KIO::stat(url
, KIO::HideProgressInfo
);
1306 connect(m_lastHandleUrlStatJob
, SIGNAL(result(KJob
*)),
1307 this, SLOT(slotHandleUrlStatFinished(KJob
*)));
1310 new KRun(url
, this);
1314 void DolphinMainWindow::slotHandleUrlStatFinished(KJob
* job
)
1316 m_lastHandleUrlStatJob
= 0;
1317 const KIO::UDSEntry entry
= static_cast<KIO::StatJob
*>(job
)->statResult();
1318 const KUrl url
= static_cast<KIO::StatJob
*>(job
)->url();
1319 if (entry
.isDir()) {
1320 activeViewContainer()->setUrl(url
);
1322 new KRun(url
, this);
1326 void DolphinMainWindow::tabDropEvent(int tab
, QDropEvent
* event
)
1328 const KUrl::List urls
= KUrl::List::fromMimeData(event
->mimeData());
1329 if (!urls
.isEmpty() && tab
!= -1) {
1330 const ViewTab
& viewTab
= m_viewTab
[tab
];
1331 const DolphinView
* view
= viewTab
.isPrimaryViewActive
? viewTab
.primaryView
->view()
1332 : viewTab
.secondaryView
->view();
1333 DragAndDropHelper::dropUrls(view
->rootItem(), event
);
1337 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1339 newFileMenu()->setEnabled(isFolderWritable
);
1342 void DolphinMainWindow::slotSearchModeChanged(bool enabled
)
1345 const DolphinSearchInformation
& searchInfo
= DolphinSearchInformation::instance();
1346 if (!searchInfo
.isIndexingEnabled()) {
1350 QDockWidget
* searchDock
= findChild
<QDockWidget
*>("searchDock");
1356 if (!searchDock
->isVisible()) {
1357 m_searchDockIsTemporaryVisible
= true;
1361 if (searchDock
->isVisible() && m_searchDockIsTemporaryVisible
) {
1364 m_searchDockIsTemporaryVisible
= false;
1367 SearchPanel
* searchPanel
= qobject_cast
<SearchPanel
*>(searchDock
->widget());
1373 SearchPanel::SearchLocation searchLocation
= SearchPanel::Everywhere
;
1374 const KUrl url
= m_activeViewContainer
->url();
1375 const bool isSearchUrl
= (url
.protocol() == QLatin1String("nepomuksearch"));
1376 if ((SearchSettings::location() == QLatin1String("FromHere") && !isSearchUrl
)) {
1377 searchLocation
= SearchPanel::FromCurrentDir
;
1379 searchPanel
->setSearchLocation(searchLocation
);
1381 searchPanel
->setSearchLocation(SearchPanel::Everywhere
);
1388 void DolphinMainWindow::openContextMenu(const QPoint
& pos
,
1389 const KFileItem
& item
,
1391 const QList
<QAction
*>& customActions
)
1393 QWeakPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, pos
, item
, url
);
1394 contextMenu
.data()->setCustomActions(customActions
);
1395 const DolphinContextMenu::Command command
= contextMenu
.data()->open();
1398 case DolphinContextMenu::OpenParentFolderInNewWindow
: {
1399 KRun::run("dolphin", KUrl::List() << item
.url().upUrl(), this);
1403 case DolphinContextMenu::OpenParentFolderInNewTab
:
1404 openNewTab(item
.url().upUrl());
1407 case DolphinContextMenu::None
:
1412 delete contextMenu
.data();
1415 void DolphinMainWindow::updateToolBarMenu()
1417 KMenu
* menu
= qobject_cast
<KMenu
*>(sender());
1420 // All actions get cleared by KMenu::clear(). The sub-menus are deleted
1421 // by connecting to the aboutToHide() signal from the parent-menu.
1424 KActionCollection
* ac
= actionCollection();
1426 // Add "Edit" actions
1427 bool added
= addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Undo
)), menu
) |
1428 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Find
)), menu
) |
1429 addActionToMenu(ac
->action("select_all"), menu
) |
1430 addActionToMenu(ac
->action("invert_selection"), menu
);
1433 menu
->addSeparator();
1436 // Add "View" actions
1437 if (!GeneralSettings::showZoomSlider()) {
1438 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomIn
)), menu
);
1439 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomOut
)), menu
);
1440 menu
->addSeparator();
1443 added
= addActionToMenu(ac
->action("view_mode"), menu
) |
1444 addActionToMenu(ac
->action("sort"), menu
) |
1445 addActionToMenu(ac
->action("additional_info"), menu
) |
1446 addActionToMenu(ac
->action("show_preview"), menu
) |
1447 addActionToMenu(ac
->action("show_in_groups"), menu
) |
1448 addActionToMenu(ac
->action("show_hidden_files"), menu
);
1451 menu
->addSeparator();
1454 added
= addActionToMenu(ac
->action("split_view"), menu
) |
1455 addActionToMenu(ac
->action("reload"), menu
) |
1456 addActionToMenu(ac
->action("view_properties"), menu
);
1458 menu
->addSeparator();
1461 addActionToMenu(ac
->action("panels"), menu
);
1462 KMenu
* locationBarMenu
= new KMenu(i18nc("@action:inmenu", "Location Bar"), menu
);
1463 locationBarMenu
->addAction(ac
->action("editable_location"));
1464 locationBarMenu
->addAction(ac
->action("replace_location"));
1465 menu
->addMenu(locationBarMenu
);
1467 menu
->addSeparator();
1470 KMenu
* goMenu
= new KMenu(i18nc("@action:inmenu", "Go"), menu
);
1471 connect(menu
, SIGNAL(aboutToHide()), goMenu
, SLOT(deleteLater()));
1472 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Back
)));
1473 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Forward
)));
1474 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Up
)));
1475 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Home
)));
1476 goMenu
->addAction(ac
->action("closed_tabs"));
1477 menu
->addMenu(goMenu
);
1480 KMenu
* toolsMenu
= new KMenu(i18nc("@action:inmenu", "Tools"), menu
);
1481 connect(menu
, SIGNAL(aboutToHide()), toolsMenu
, SLOT(deleteLater()));
1482 toolsMenu
->addAction(ac
->action("show_filter_bar"));
1483 toolsMenu
->addAction(ac
->action("compare_files"));
1484 toolsMenu
->addAction(ac
->action("open_terminal"));
1485 toolsMenu
->addAction(ac
->action("change_remote_encoding"));
1486 menu
->addMenu(toolsMenu
);
1488 // Add "Settings" menu entries
1489 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::KeyBindings
)), menu
);
1490 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ConfigureToolbars
)), menu
);
1491 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Preferences
)), menu
);
1494 KMenu
* helpMenu
= new KMenu(i18nc("@action:inmenu", "Help"), menu
);
1495 connect(menu
, SIGNAL(aboutToHide()), helpMenu
, SLOT(deleteLater()));
1496 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::HelpContents
)));
1497 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::WhatsThis
)));
1498 helpMenu
->addSeparator();
1499 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ReportBug
)));
1500 helpMenu
->addSeparator();
1501 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
)));
1502 helpMenu
->addSeparator();
1503 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::AboutApp
)));
1504 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::AboutKDE
)));
1505 menu
->addMenu(helpMenu
);
1507 menu
->addSeparator();
1508 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ShowMenubar
)), menu
);
1511 void DolphinMainWindow::updateToolBar()
1513 if (!menuBar()->isVisible()) {
1514 createToolBarMenuButton();
1518 void DolphinMainWindow::slotToolBarSpacerDeleted()
1520 m_toolBarSpacer
= 0;
1521 m_updateToolBarTimer
->start();
1524 void DolphinMainWindow::slotToolBarMenuButtonDeleted()
1526 m_openToolBarMenuButton
= 0;
1527 m_updateToolBarTimer
->start();
1530 void DolphinMainWindow::slotToolBarIconSizeChanged(const QSize
& iconSize
)
1532 if (m_openToolBarMenuButton
) {
1533 m_openToolBarMenuButton
->setIconSize(iconSize
);
1537 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer
* viewContainer
)
1539 Q_ASSERT(viewContainer
);
1540 Q_ASSERT((viewContainer
== m_viewTab
[m_tabIndex
].primaryView
) ||
1541 (viewContainer
== m_viewTab
[m_tabIndex
].secondaryView
));
1542 if (m_activeViewContainer
== viewContainer
) {
1546 m_activeViewContainer
->setActive(false);
1547 m_activeViewContainer
= viewContainer
;
1549 // Activating the view container might trigger a recursive setActiveViewContainer() call
1550 // inside DolphinMainWindow::toggleActiveView() when having a split view. Temporary
1551 // disconnect the activated() signal in this case:
1552 disconnect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1553 m_activeViewContainer
->setActive(true);
1554 connect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1556 m_actionHandler
->setCurrentView(viewContainer
->view());
1559 updateEditActions();
1560 updateViewActions();
1563 const KUrl url
= m_activeViewContainer
->url();
1564 setUrlAsCaption(url
);
1565 if (m_viewTab
.count() > 1) {
1566 m_tabBar
->setTabText(m_tabIndex
, tabName(url
));
1567 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(KMimeType::iconNameForUrl(url
)));
1570 emit
urlChanged(url
);
1573 DolphinViewContainer
* DolphinMainWindow::createViewContainer(const KUrl
& url
, QWidget
* parent
)
1575 DolphinViewContainer
* container
= new DolphinViewContainer(url
, parent
);
1577 // The places-selector from the URL navigator should only be shown
1578 // if the places dock is invisible
1579 QDockWidget
* placesDock
= findChild
<QDockWidget
*>("placesDock");
1580 container
->urlNavigator()->setPlacesSelectorVisible(!placesDock
|| !placesDock
->isVisible());
1585 void DolphinMainWindow::setupActions()
1587 // setup 'File' menu
1588 m_newFileMenu
= new DolphinNewFileMenu(this);
1589 KMenu
* menu
= m_newFileMenu
->menu();
1590 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1591 menu
->setIcon(KIcon("document-new"));
1592 connect(menu
, SIGNAL(aboutToShow()),
1593 this, SLOT(updateNewMenu()));
1595 KAction
* newWindow
= actionCollection()->addAction("new_window");
1596 newWindow
->setIcon(KIcon("window-new"));
1597 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1598 newWindow
->setShortcut(Qt::CTRL
| Qt::Key_N
);
1599 connect(newWindow
, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1601 KAction
* newTab
= actionCollection()->addAction("new_tab");
1602 newTab
->setIcon(KIcon("tab-new"));
1603 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1604 newTab
->setShortcut(KShortcut(Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
));
1605 connect(newTab
, SIGNAL(triggered()), this, SLOT(openNewTab()));
1607 KAction
* closeTab
= actionCollection()->addAction("close_tab");
1608 closeTab
->setIcon(KIcon("tab-close"));
1609 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1610 closeTab
->setShortcut(Qt::CTRL
| Qt::Key_W
);
1611 closeTab
->setEnabled(false);
1612 connect(closeTab
, SIGNAL(triggered()), this, SLOT(closeTab()));
1614 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1616 // setup 'Edit' menu
1617 KStandardAction::undo(this,
1619 actionCollection());
1621 // need to remove shift+del from cut action, else the shortcut for deletejob
1623 KAction
* cut
= KStandardAction::cut(this, SLOT(cut()), actionCollection());
1624 KShortcut cutShortcut
= cut
->shortcut();
1625 cutShortcut
.remove(Qt::SHIFT
| Qt::Key_Delete
, KShortcut::KeepEmpty
);
1626 cut
->setShortcut(cutShortcut
);
1627 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1628 KAction
* paste
= KStandardAction::paste(this, SLOT(paste()), actionCollection());
1629 // The text of the paste-action is modified dynamically by Dolphin
1630 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1631 // due to the long text, the text "Paste" is used:
1632 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1634 KStandardAction::find(this, SLOT(find()), actionCollection());
1636 KAction
* selectAll
= actionCollection()->addAction("select_all");
1637 selectAll
->setText(i18nc("@action:inmenu Edit", "Select All"));
1638 selectAll
->setShortcut(Qt::CTRL
| Qt::Key_A
);
1639 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
1641 KAction
* invertSelection
= actionCollection()->addAction("invert_selection");
1642 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1643 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1644 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
1646 // setup 'View' menu
1647 // (note that most of it is set up in DolphinViewActionHandler)
1649 KAction
* split
= actionCollection()->addAction("split_view");
1650 split
->setShortcut(Qt::Key_F3
);
1651 updateSplitAction();
1652 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1654 KAction
* reload
= actionCollection()->addAction("reload");
1655 reload
->setText(i18nc("@action:inmenu View", "Reload"));
1656 reload
->setShortcut(Qt::Key_F5
);
1657 reload
->setIcon(KIcon("view-refresh"));
1658 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
1660 KAction
* stop
= actionCollection()->addAction("stop");
1661 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1662 stop
->setToolTip(i18nc("@info", "Stop loading"));
1663 stop
->setIcon(KIcon("process-stop"));
1664 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
1666 KToggleAction
* editableLocation
= actionCollection()->add
<KToggleAction
>("editable_location");
1667 editableLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1668 editableLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
1669 connect(editableLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1671 KAction
* replaceLocation
= actionCollection()->addAction("replace_location");
1672 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1673 replaceLocation
->setShortcut(Qt::Key_F6
);
1674 connect(replaceLocation
, SIGNAL(triggered()), this, SLOT(replaceLocation()));
1677 KAction
* backAction
= KStandardAction::back(this, SLOT(goBack()), actionCollection());
1678 connect(backAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goBack(Qt::MouseButtons
)));
1679 KShortcut backShortcut
= backAction
->shortcut();
1680 backShortcut
.setAlternate(Qt::Key_Backspace
);
1681 backAction
->setShortcut(backShortcut
);
1683 m_recentTabsMenu
= new KActionMenu(i18n("Recently Closed Tabs"), this);
1684 m_recentTabsMenu
->setIcon(KIcon("edit-undo"));
1685 actionCollection()->addAction("closed_tabs", m_recentTabsMenu
);
1686 connect(m_recentTabsMenu
->menu(), SIGNAL(triggered(QAction
*)),
1687 this, SLOT(restoreClosedTab(QAction
*)));
1689 QAction
* action
= new QAction(i18n("Empty Recently Closed Tabs"), m_recentTabsMenu
);
1690 action
->setIcon(KIcon("edit-clear-list"));
1691 action
->setData(QVariant::fromValue(true));
1692 m_recentTabsMenu
->addAction(action
);
1693 m_recentTabsMenu
->addSeparator();
1694 m_recentTabsMenu
->setEnabled(false);
1696 KAction
* forwardAction
= KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1697 connect(forwardAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goForward(Qt::MouseButtons
)));
1699 KAction
* upAction
= KStandardAction::up(this, SLOT(goUp()), actionCollection());
1700 connect(upAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goUp(Qt::MouseButtons
)));
1702 KAction
* homeAction
= KStandardAction::home(this, SLOT(goHome()), actionCollection());
1703 connect(homeAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goHome(Qt::MouseButtons
)));
1705 // setup 'Tools' menu
1706 KAction
* showFilterBar
= actionCollection()->addAction("show_filter_bar");
1707 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1708 showFilterBar
->setIcon(KIcon("view-filter"));
1709 showFilterBar
->setShortcut(Qt::CTRL
| Qt::Key_I
);
1710 connect(showFilterBar
, SIGNAL(triggered()), this, SLOT(showFilterBar()));
1712 KAction
* compareFiles
= actionCollection()->addAction("compare_files");
1713 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1714 compareFiles
->setIcon(KIcon("kompare"));
1715 compareFiles
->setEnabled(false);
1716 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
1718 KAction
* openTerminal
= actionCollection()->addAction("open_terminal");
1719 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1720 openTerminal
->setIcon(KIcon("utilities-terminal"));
1721 openTerminal
->setShortcut(Qt::SHIFT
| Qt::Key_F4
);
1722 connect(openTerminal
, SIGNAL(triggered()), this, SLOT(openTerminal()));
1724 // setup 'Settings' menu
1725 KToggleAction
* showMenuBar
= KStandardAction::showMenubar(0, 0, actionCollection());
1726 connect(showMenuBar
, SIGNAL(triggered(bool)), // Fixes #286822
1727 this, SLOT(toggleShowMenuBar()), Qt::QueuedConnection
);
1728 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1730 // not in menu actions
1731 QList
<QKeySequence
> nextTabKeys
;
1732 nextTabKeys
.append(KStandardShortcut::tabNext().primary());
1733 nextTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::Key_Tab
));
1735 QList
<QKeySequence
> prevTabKeys
;
1736 prevTabKeys
.append(KStandardShortcut::tabPrev().primary());
1737 prevTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::SHIFT
| Qt::Key_Tab
));
1739 KAction
* activateNextTab
= actionCollection()->addAction("activate_next_tab");
1740 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1741 connect(activateNextTab
, SIGNAL(triggered()), SLOT(activateNextTab()));
1742 activateNextTab
->setShortcuts(QApplication::isRightToLeft() ? prevTabKeys
: nextTabKeys
);
1744 KAction
* activatePrevTab
= actionCollection()->addAction("activate_prev_tab");
1745 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1746 connect(activatePrevTab
, SIGNAL(triggered()), SLOT(activatePrevTab()));
1747 activatePrevTab
->setShortcuts(QApplication::isRightToLeft() ? nextTabKeys
: prevTabKeys
);
1750 KAction
* openInNewTab
= actionCollection()->addAction("open_in_new_tab");
1751 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1752 openInNewTab
->setIcon(KIcon("tab-new"));
1753 connect(openInNewTab
, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1755 KAction
* openInNewWindow
= actionCollection()->addAction("open_in_new_window");
1756 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1757 openInNewWindow
->setIcon(KIcon("window-new"));
1758 connect(openInNewWindow
, SIGNAL(triggered()), this, SLOT(openInNewWindow()));
1761 void DolphinMainWindow::setupDockWidgets()
1763 const bool lock
= GeneralSettings::lockPanels();
1765 KDualAction
* lockLayoutAction
= actionCollection()->add
<KDualAction
>("lock_panels");
1766 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
1767 lockLayoutAction
->setActiveIcon(KIcon("object-unlocked"));
1768 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
1769 lockLayoutAction
->setInactiveIcon(KIcon("object-locked"));
1770 lockLayoutAction
->setActive(lock
);
1771 connect(lockLayoutAction
, SIGNAL(triggered()), this, SLOT(togglePanelLockState()));
1773 // Setup "Information"
1774 DolphinDockWidget
* infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
1775 infoDock
->setLocked(lock
);
1776 infoDock
->setObjectName("infoDock");
1777 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1778 Panel
* infoPanel
= new InformationPanel(infoDock
);
1779 infoPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1780 connect(infoPanel
, SIGNAL(urlActivated(KUrl
)), this, SLOT(handleUrl(KUrl
)));
1781 infoDock
->setWidget(infoPanel
);
1783 QAction
* infoAction
= infoDock
->toggleViewAction();
1784 createPanelAction(KIcon("dialog-information"), Qt::Key_F11
, infoAction
, "show_information_panel");
1786 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1787 connect(this, SIGNAL(urlChanged(KUrl
)),
1788 infoPanel
, SLOT(setUrl(KUrl
)));
1789 connect(this, SIGNAL(selectionChanged(KFileItemList
)),
1790 infoPanel
, SLOT(setSelection(KFileItemList
)));
1791 connect(this, SIGNAL(requestItemInfo(KFileItem
)),
1792 infoPanel
, SLOT(requestDelayedItemInfo(KFileItem
)));
1795 DolphinDockWidget
* foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
1796 foldersDock
->setLocked(lock
);
1797 foldersDock
->setObjectName("foldersDock");
1798 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1799 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1800 foldersPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1801 foldersDock
->setWidget(foldersPanel
);
1803 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1804 createPanelAction(KIcon("folder"), Qt::Key_F7
, foldersAction
, "show_folders_panel");
1806 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1807 connect(this, SIGNAL(urlChanged(KUrl
)),
1808 foldersPanel
, SLOT(setUrl(KUrl
)));
1809 connect(foldersPanel
, SIGNAL(changeUrl(KUrl
,Qt::MouseButtons
)),
1810 this, SLOT(handlePlacesClick(KUrl
,Qt::MouseButtons
)));
1814 DolphinDockWidget
* terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1815 terminalDock
->setLocked(lock
);
1816 terminalDock
->setObjectName("terminalDock");
1817 terminalDock
->setAllowedAreas(Qt::TopDockWidgetArea
| Qt::BottomDockWidgetArea
);
1818 Panel
* terminalPanel
= new TerminalPanel(terminalDock
);
1819 terminalPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1820 terminalDock
->setWidget(terminalPanel
);
1822 connect(terminalPanel
, SIGNAL(hideTerminalPanel()), terminalDock
, SLOT(hide()));
1823 connect(terminalDock
, SIGNAL(visibilityChanged(bool)),
1824 terminalPanel
, SLOT(dockVisibilityChanged()));
1826 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1827 createPanelAction(KIcon("utilities-terminal"), Qt::Key_F4
, terminalAction
, "show_terminal_panel");
1829 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1830 connect(this, SIGNAL(urlChanged(KUrl
)),
1831 terminalPanel
, SLOT(setUrl(KUrl
)));
1836 DolphinDockWidget
* searchDock
= new DolphinDockWidget(i18nc("@title:window", "Search"));
1837 searchDock
->setLocked(lock
);
1838 searchDock
->setObjectName("searchDock");
1839 searchDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1840 Panel
* searchPanel
= new SearchPanel(searchDock
);
1841 searchPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1842 connect(searchPanel
, SIGNAL(urlActivated(KUrl
)), this, SLOT(handleUrl(KUrl
)));
1843 searchDock
->setWidget(searchPanel
);
1845 QAction
* searchAction
= searchDock
->toggleViewAction();
1846 createPanelAction(KIcon("system-search"), Qt::Key_F12
, searchAction
, "show_search_panel");
1847 addDockWidget(Qt::RightDockWidgetArea
, searchDock
);
1848 connect(this, SIGNAL(urlChanged(KUrl
)),
1849 searchPanel
, SLOT(setUrl(KUrl
)));
1852 if (GeneralSettings::version() < 200) {
1854 foldersDock
->hide();
1856 terminalDock
->hide();
1864 DolphinDockWidget
* placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
1865 placesDock
->setLocked(lock
);
1866 placesDock
->setObjectName("placesDock");
1867 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1869 PlacesPanel
* placesPanel
= new PlacesPanel(placesDock
);
1870 QAction
* separator
= new QAction(placesPanel
);
1871 separator
->setSeparator(true);
1872 QList
<QAction
*> placesActions
;
1873 placesActions
.append(separator
);
1874 placesActions
.append(lockLayoutAction
);
1875 placesPanel
->addActions(placesActions
);
1876 placesPanel
->setModel(DolphinPlacesModel::instance());
1877 placesPanel
->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff
);
1878 placesDock
->setWidget(placesPanel
);
1880 QAction
* placesAction
= placesDock
->toggleViewAction();
1881 createPanelAction(KIcon("bookmarks"), Qt::Key_F9
, placesAction
, "show_places_panel");
1883 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1884 connect(placesPanel
, SIGNAL(urlChanged(KUrl
,Qt::MouseButtons
)),
1885 this, SLOT(handlePlacesClick(KUrl
,Qt::MouseButtons
)));
1886 connect(this, SIGNAL(urlChanged(KUrl
)),
1887 placesPanel
, SLOT(setUrl(KUrl
)));
1888 connect(placesDock
, SIGNAL(visibilityChanged(bool)),
1889 this, SLOT(slotPlacesPanelVisibilityChanged(bool)));
1891 // Add actions into the "Panels" menu
1892 KActionMenu
* panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Panels"), this);
1893 actionCollection()->addAction("panels", panelsMenu
);
1894 panelsMenu
->setDelayed(false);
1895 const KActionCollection
* ac
= actionCollection();
1896 panelsMenu
->addAction(ac
->action("show_places_panel"));
1897 panelsMenu
->addAction(ac
->action("show_information_panel"));
1898 panelsMenu
->addAction(ac
->action("show_folders_panel"));
1900 panelsMenu
->addAction(ac
->action("show_terminal_panel"));
1903 panelsMenu
->addAction(ac
->action("show_search_panel"));
1905 panelsMenu
->addSeparator();
1906 panelsMenu
->addAction(lockLayoutAction
);
1909 void DolphinMainWindow::updateEditActions()
1911 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1912 if (list
.isEmpty()) {
1913 stateChanged("has_no_selection");
1915 stateChanged("has_selection");
1917 KActionCollection
* col
= actionCollection();
1918 QAction
* renameAction
= col
->action("rename");
1919 QAction
* moveToTrashAction
= col
->action("move_to_trash");
1920 QAction
* deleteAction
= col
->action("delete");
1921 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
1922 QAction
* deleteWithTrashShortcut
= col
->action("delete_shortcut"); // see DolphinViewActionHandler
1924 KFileItemListProperties
capabilities(list
);
1925 const bool enableMoveToTrash
= capabilities
.isLocal() && capabilities
.supportsMoving();
1927 renameAction
->setEnabled(capabilities
.supportsMoving());
1928 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1929 deleteAction
->setEnabled(capabilities
.supportsDeleting());
1930 deleteWithTrashShortcut
->setEnabled(capabilities
.supportsDeleting() && !enableMoveToTrash
);
1931 cutAction
->setEnabled(capabilities
.supportsMoving());
1933 updatePasteAction();
1936 void DolphinMainWindow::updateViewActions()
1938 m_actionHandler
->updateViewActions();
1940 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1941 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
1943 updateSplitAction();
1945 QAction
* editableLocactionAction
= actionCollection()->action("editable_location");
1946 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
1947 editableLocactionAction
->setChecked(urlNavigator
->isUrlEditable());
1950 void DolphinMainWindow::updateGoActions()
1952 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
1953 const KUrl currentUrl
= m_activeViewContainer
->url();
1954 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
1957 void DolphinMainWindow::createToolBarMenuButton()
1959 if (m_toolBarSpacer
&& m_openToolBarMenuButton
) {
1962 Q_ASSERT(!m_toolBarSpacer
);
1963 Q_ASSERT(!m_openToolBarMenuButton
);
1965 m_toolBarSpacer
= new QWidget(this);
1966 m_toolBarSpacer
->setSizePolicy(QSizePolicy::MinimumExpanding
, QSizePolicy::MinimumExpanding
);
1968 m_openToolBarMenuButton
= new QToolButton(this);
1969 m_openToolBarMenuButton
->setIcon(KIcon("configure"));
1970 m_openToolBarMenuButton
->setPopupMode(QToolButton::InstantPopup
);
1971 m_openToolBarMenuButton
->setToolTip(i18nc("@info:tooltip", "Configure and control Dolphin"));
1973 KMenu
* toolBarMenu
= new ToolBarMenu(m_openToolBarMenuButton
);
1974 connect(toolBarMenu
, SIGNAL(aboutToShow()), this, SLOT(updateToolBarMenu()));
1976 m_openToolBarMenuButton
->setMenu(toolBarMenu
);
1978 toolBar()->addWidget(m_toolBarSpacer
);
1979 toolBar()->addWidget(m_openToolBarMenuButton
);
1980 connect(toolBar(), SIGNAL(iconSizeChanged(QSize
)), this, SLOT(slotToolBarIconSizeChanged(QSize
)));
1982 // The added widgets are owned by the toolbar and may get deleted when e.g. the toolbar
1983 // gets edited. In this case we must add them again. The adding is done asynchronously by
1984 // m_updateToolBarTimer.
1985 connect(m_toolBarSpacer
, SIGNAL(destroyed()), this, SLOT(slotToolBarSpacerDeleted()));
1986 connect(m_openToolBarMenuButton
, SIGNAL(destroyed()), this, SLOT(slotToolBarMenuButtonDeleted()));
1987 m_updateToolBarTimer
= new QTimer(this);
1988 m_updateToolBarTimer
->setInterval(500);
1989 connect(m_updateToolBarTimer
, SIGNAL(timeout()), this, SLOT(updateToolBar()));
1992 void DolphinMainWindow::deleteToolBarMenuButton()
1994 delete m_toolBarSpacer
;
1995 m_toolBarSpacer
= 0;
1997 delete m_openToolBarMenuButton
;
1998 m_openToolBarMenuButton
= 0;
2000 delete m_updateToolBarTimer
;
2001 m_updateToolBarTimer
= 0;
2004 bool DolphinMainWindow::addActionToMenu(QAction
* action
, KMenu
* menu
)
2009 const KToolBar
* toolBarWidget
= toolBar();
2010 foreach (const QWidget
* widget
, action
->associatedWidgets()) {
2011 if (widget
== toolBarWidget
) {
2016 menu
->addAction(action
);
2020 void DolphinMainWindow::rememberClosedTab(int index
)
2022 KMenu
* tabsMenu
= m_recentTabsMenu
->menu();
2024 const QString primaryPath
= m_viewTab
[index
].primaryView
->url().path();
2025 const QString iconName
= KMimeType::iconNameForUrl(primaryPath
);
2027 QAction
* action
= new QAction(squeezedText(primaryPath
), tabsMenu
);
2029 ClosedTab closedTab
;
2030 closedTab
.primaryUrl
= m_viewTab
[index
].primaryView
->url();
2032 if (m_viewTab
[index
].secondaryView
) {
2033 closedTab
.secondaryUrl
= m_viewTab
[index
].secondaryView
->url();
2034 closedTab
.isSplit
= true;
2036 closedTab
.isSplit
= false;
2039 action
->setData(QVariant::fromValue(closedTab
));
2040 action
->setIcon(KIcon(iconName
));
2042 // add the closed tab menu entry after the separator and
2043 // "Empty Recently Closed Tabs" entry
2044 if (tabsMenu
->actions().size() == 2) {
2045 tabsMenu
->addAction(action
);
2047 tabsMenu
->insertAction(tabsMenu
->actions().at(2), action
);
2050 // assure that only up to 8 closed tabs are shown in the menu
2051 if (tabsMenu
->actions().size() > 8) {
2052 tabsMenu
->removeAction(tabsMenu
->actions().last());
2054 actionCollection()->action("closed_tabs")->setEnabled(true);
2055 KAcceleratorManager::manage(tabsMenu
);
2058 void DolphinMainWindow::refreshViews()
2060 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
2062 // remember the current active view, as because of
2063 // the refreshing the active view might change to
2064 // the secondary view
2065 DolphinViewContainer
* activeViewContainer
= m_activeViewContainer
;
2067 const int tabCount
= m_viewTab
.count();
2068 for (int i
= 0; i
< tabCount
; ++i
) {
2069 m_viewTab
[i
].primaryView
->refresh();
2070 if (m_viewTab
[i
].secondaryView
) {
2071 m_viewTab
[i
].secondaryView
->refresh();
2075 setActiveViewContainer(activeViewContainer
);
2077 if (GeneralSettings::modifiedStartupSettings()) {
2078 // The startup settings have been changed by the user (see bug #254947).
2079 // Synchronize the split-view setting with the active view:
2080 const bool splitView
= GeneralSettings::splitView();
2081 const ViewTab
& activeTab
= m_viewTab
[m_tabIndex
];
2082 const bool toggle
= ( splitView
&& !activeTab
.secondaryView
)
2083 || (!splitView
&& activeTab
.secondaryView
);
2090 void DolphinMainWindow::clearStatusBar()
2092 m_activeViewContainer
->statusBar()->clear();
2095 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
2097 connect(container
, SIGNAL(showFilterBarChanged(bool)),
2098 this, SLOT(updateFilterBarAction(bool)));
2099 connect(container
, SIGNAL(writeStateChanged(bool)),
2100 this, SLOT(slotWriteStateChanged(bool)));
2101 connect(container
, SIGNAL(searchModeChanged(bool)),
2102 this, SLOT(slotSearchModeChanged(bool)));
2104 const DolphinSearchBox
* searchBox
= container
->searchBox();
2105 connect(searchBox
, SIGNAL(searchLocationChanged(SearchLocation
)),
2106 this, SLOT(slotSearchLocationChanged()));
2108 DolphinView
* view
= container
->view();
2109 connect(view
, SIGNAL(selectionChanged(KFileItemList
)),
2110 this, SLOT(slotSelectionChanged(KFileItemList
)));
2111 connect(view
, SIGNAL(requestItemInfo(KFileItem
)),
2112 this, SLOT(slotRequestItemInfo(KFileItem
)));
2113 connect(view
, SIGNAL(activated()),
2114 this, SLOT(toggleActiveView()));
2115 connect(view
, SIGNAL(tabRequested(KUrl
)),
2116 this, SLOT(openNewTab(KUrl
)));
2117 connect(view
, SIGNAL(requestContextMenu(QPoint
,KFileItem
,KUrl
,QList
<QAction
*>)),
2118 this, SLOT(openContextMenu(QPoint
,KFileItem
,KUrl
,QList
<QAction
*>)));
2119 connect(view
, SIGNAL(startedPathLoading(KUrl
)),
2120 this, SLOT(enableStopAction()));
2121 connect(view
, SIGNAL(finishedPathLoading(KUrl
)),
2122 this, SLOT(disableStopAction()));
2124 const KUrlNavigator
* navigator
= container
->urlNavigator();
2125 connect(navigator
, SIGNAL(urlChanged(KUrl
)),
2126 this, SLOT(changeUrl(KUrl
)));
2127 connect(navigator
, SIGNAL(historyChanged()),
2128 this, SLOT(updateHistory()));
2129 connect(navigator
, SIGNAL(editableStateChanged(bool)),
2130 this, SLOT(slotEditableStateChanged(bool)));
2131 connect(navigator
, SIGNAL(tabRequested(KUrl
)),
2132 this, SLOT(openNewTab(KUrl
)));
2135 void DolphinMainWindow::updateSplitAction()
2137 QAction
* splitAction
= actionCollection()->action("split_view");
2138 if (m_viewTab
[m_tabIndex
].secondaryView
) {
2139 if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
2140 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
2141 splitAction
->setToolTip(i18nc("@info", "Close right view"));
2142 splitAction
->setIcon(KIcon("view-right-close"));
2144 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
2145 splitAction
->setToolTip(i18nc("@info", "Close left view"));
2146 splitAction
->setIcon(KIcon("view-left-close"));
2149 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
2150 splitAction
->setToolTip(i18nc("@info", "Split view"));
2151 splitAction
->setIcon(KIcon("view-right-new"));
2155 QString
DolphinMainWindow::tabName(const KUrl
& url
) const
2158 if (url
.equals(KUrl("file:///"))) {
2161 name
= url
.fileName();
2162 if (name
.isEmpty()) {
2163 name
= url
.protocol();
2165 // Make sure that a '&' inside the directory name is displayed correctly
2166 // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
2167 name
.replace('&', "&&");
2173 bool DolphinMainWindow::isKompareInstalled() const
2175 static bool initialized
= false;
2176 static bool installed
= false;
2178 // TODO: maybe replace this approach later by using a menu
2179 // plugin like kdiff3plugin.cpp
2180 installed
= !KGlobal::dirs()->findExe("kompare").isEmpty();
2186 void DolphinMainWindow::createSecondaryView(int tabIndex
)
2188 ViewTab
& viewTab
= m_viewTab
[tabIndex
];
2190 QSplitter
* splitter
= viewTab
.splitter
;
2191 const int newWidth
= (viewTab
.primaryView
->width() - splitter
->handleWidth()) / 2;
2193 const DolphinView
* view
= viewTab
.primaryView
->view();
2194 viewTab
.secondaryView
= createViewContainer(view
->url(), 0);
2195 splitter
->addWidget(viewTab
.secondaryView
);
2196 splitter
->setSizes(QList
<int>() << newWidth
<< newWidth
);
2198 connectViewSignals(viewTab
.secondaryView
);
2199 viewTab
.secondaryView
->setActive(false);
2200 viewTab
.secondaryView
->resize(newWidth
, viewTab
.primaryView
->height());
2201 viewTab
.secondaryView
->show();
2204 QString
DolphinMainWindow::tabProperty(const QString
& property
, int tabIndex
) const
2206 return "Tab " + QString::number(tabIndex
) + ' ' + property
;
2209 void DolphinMainWindow::setUrlAsCaption(const KUrl
& url
)
2212 if (!url
.isLocalFile()) {
2213 caption
.append(url
.protocol() + " - ");
2214 if (url
.hasHost()) {
2215 caption
.append(url
.host() + " - ");
2219 const QString fileName
= url
.fileName().isEmpty() ? "/" : url
.fileName();
2220 caption
.append(fileName
);
2222 setCaption(caption
);
2225 QString
DolphinMainWindow::squeezedText(const QString
& text
) const
2227 const QFontMetrics fm
= fontMetrics();
2228 return fm
.elidedText(text
, Qt::ElideMiddle
, fm
.maxWidth() * 10);
2231 void DolphinMainWindow::createPanelAction(const KIcon
& icon
,
2232 const QKeySequence
& shortcut
,
2233 QAction
* dockAction
,
2234 const QString
& actionName
)
2236 KAction
* panelAction
= actionCollection()->addAction(actionName
);
2237 panelAction
->setCheckable(true);
2238 panelAction
->setChecked(dockAction
->isChecked());
2239 panelAction
->setText(dockAction
->text());
2240 panelAction
->setIcon(icon
);
2241 panelAction
->setShortcut(shortcut
);
2243 connect(panelAction
, SIGNAL(triggered()), dockAction
, SLOT(trigger()));
2244 connect(dockAction
, SIGNAL(toggled(bool)), panelAction
, SLOT(setChecked(bool)));
2247 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
2248 KIO::FileUndoManager::UiInterface()
2252 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2256 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
2258 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
2260 DolphinStatusBar
* statusBar
= mainWin
->activeViewContainer()->statusBar();
2261 statusBar
->setMessage(job
->errorString(), DolphinStatusBar::Error
);
2263 KIO::FileUndoManager::UiInterface::jobError(job
);
2267 ToolBarMenu::ToolBarMenu(QWidget
* parent
) :
2272 ToolBarMenu::~ToolBarMenu()
2276 void ToolBarMenu::showEvent(QShowEvent
* event
)
2278 KMenu::showEvent(event
);
2280 // Adjust the position of the menu to be shown within the
2281 // Dolphin window to reduce the cases that sub-menus might overlap
2282 // the right screen border.
2284 QWidget
* button
= parentWidget();
2285 if (layoutDirection() == Qt::RightToLeft
) {
2286 pos
= button
->mapToGlobal(QPoint(0, button
->height()));
2288 pos
= button
->mapToGlobal(QPoint(button
->width(), button
->height()));
2289 pos
.rx() -= width();
2292 // Assure that the menu is not shown outside the screen boundaries and
2293 // that it does not overlap with the parent button.
2294 const QRect screen
= QApplication::desktop()->screenGeometry(QCursor::pos());
2295 if (pos
.x() < screen
.x()) {
2296 pos
.rx() = screen
.x();
2297 } else if (pos
.x() + width() > screen
.x() + screen
.width()) {
2298 pos
.rx() = screen
.x() + screen
.width() - width();
2301 if (pos
.y() < screen
.y()) {
2302 pos
.ry() = screen
.y();
2303 } else if (pos
.y() + height() > screen
.y() + screen
.height()) {
2304 pos
.ry() = button
->mapToGlobal(QPoint(0, 0)).y() - height();
2310 #include "dolphinmainwindow.moc"