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/dolphinsearchinformation.h"
39 #include "settings/dolphinsettings.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_iconsmodesettings.h"
53 #include "dolphin_searchsettings.h"
55 #include <KAcceleratorManager>
57 #include <KActionCollection>
58 #include <KActionMenu>
60 #include <KDesktopFile>
61 #include <kdeversion.h>
62 #include <kdualaction.h>
63 #include <KFileDialog>
64 #include <KFilePlacesModel>
69 #include <KIconLoader>
70 #include <KIO/NetAccess>
71 #include <KInputDialog>
73 #include <KProtocolManager>
76 #include <KMessageBox>
77 #include <KFileItemListProperties>
78 #include <konqmimedata.h>
79 #include <KProtocolInfo>
82 #include <KStandardDirs>
83 #include <kstatusbar.h>
84 #include <KStandardAction>
86 #include <KToggleAction>
87 #include <KUrlNavigator>
89 #include <KUrlComboBox>
90 #include <KToolInvocation>
92 #include <QDesktopWidget>
93 #include <QDBusMessage>
96 #include <QToolButton>
100 * Menu shown when pressing the configure-button in the toolbar.
102 class ToolBarMenu
: public KMenu
105 ToolBarMenu(QWidget
* parent
);
106 virtual ~ToolBarMenu();
108 virtual void showEvent(QShowEvent
* event
);
112 * Remembers the tab configuration if a tab has been closed.
113 * Each closed tab can be restored by the menu
114 * "Go -> Recently Closed Tabs".
122 Q_DECLARE_METATYPE(ClosedTab
)
124 DolphinMainWindow::DolphinMainWindow() :
128 m_activeViewContainer(0),
129 m_centralWidgetLayout(0),
136 m_openToolBarMenuButton(0),
137 m_updateToolBarTimer(0),
138 m_lastHandleUrlStatJob(0),
139 m_searchDockIsTemporaryVisible(false)
141 // Workaround for a X11-issue in combination with KModifierInfo
142 // (see DolphinContextMenu::initializeModifierKeyInfo() for
143 // more information):
144 DolphinContextMenu::initializeModifierKeyInfo();
146 setObjectName("Dolphin#");
148 m_viewTab
.append(ViewTab());
150 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
151 undoManager
->setUiInterface(new UndoUiInterface());
153 connect(undoManager
, SIGNAL(undoAvailable(bool)),
154 this, SLOT(slotUndoAvailable(bool)));
155 connect(undoManager
, SIGNAL(undoTextChanged(const QString
&)),
156 this, SLOT(slotUndoTextChanged(const QString
&)));
157 connect(undoManager
, SIGNAL(jobRecordingStarted(CommandType
)),
158 this, SLOT(clearStatusBar()));
159 connect(undoManager
, SIGNAL(jobRecordingFinished(CommandType
)),
160 this, SLOT(showCommand(CommandType
)));
161 connect(DolphinSettings::instance().placesModel(), SIGNAL(errorMessage(const QString
&)),
162 this, SLOT(showErrorMessage(const QString
&)));
163 connect(&DragAndDropHelper::instance(), SIGNAL(errorMessage(const QString
&)),
164 this, SLOT(showErrorMessage(const QString
&)));
166 const DolphinSettings
& settings
= DolphinSettings::instance();
168 GeneralSettings
* generalSettings
= settings
.generalSettings();
169 const bool firstRun
= generalSettings
->firstRun();
171 generalSettings
->setViewPropsTimestamp(QDateTime::currentDateTime());
174 setAcceptDrops(true);
176 m_viewTab
[m_tabIndex
].splitter
= new QSplitter(this);
177 m_viewTab
[m_tabIndex
].splitter
->setChildrenCollapsible(false);
181 const KUrl
homeUrl(generalSettings
->homeUrl());
182 setUrlAsCaption(homeUrl
);
183 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
184 connect(m_actionHandler
, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
185 connect(m_actionHandler
, SIGNAL(createDirectory()), SLOT(createDirectory()));
187 m_viewTab
[m_tabIndex
].primaryView
= createViewContainer(homeUrl
, m_viewTab
[m_tabIndex
].splitter
);
189 m_activeViewContainer
= m_viewTab
[m_tabIndex
].primaryView
;
190 connectViewSignals(m_activeViewContainer
);
191 DolphinView
* view
= m_activeViewContainer
->view();
192 m_activeViewContainer
->show();
193 m_actionHandler
->setCurrentView(view
);
195 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
196 connect(this, SIGNAL(urlChanged(const KUrl
&)),
197 m_remoteEncoding
, SLOT(slotAboutToOpenUrl()));
199 m_tabBar
= new KTabBar(this);
200 m_tabBar
->setMovable(true);
201 m_tabBar
->setTabsClosable(true);
202 connect(m_tabBar
, SIGNAL(currentChanged(int)),
203 this, SLOT(setActiveTab(int)));
204 connect(m_tabBar
, SIGNAL(tabCloseRequested(int)),
205 this, SLOT(closeTab(int)));
206 connect(m_tabBar
, SIGNAL(contextMenu(int, const QPoint
&)),
207 this, SLOT(openTabContextMenu(int, const QPoint
&)));
208 connect(m_tabBar
, SIGNAL(newTabRequest()),
209 this, SLOT(openNewTab()));
210 connect(m_tabBar
, SIGNAL(testCanDecode(const QDragMoveEvent
*, bool&)),
211 this, SLOT(slotTestCanDecode(const QDragMoveEvent
*, bool&)));
212 connect(m_tabBar
, SIGNAL(mouseMiddleClick(int)),
213 this, SLOT(closeTab(int)));
214 connect(m_tabBar
, SIGNAL(tabMoved(int, int)),
215 this, SLOT(slotTabMoved(int, int)));
216 connect(m_tabBar
, SIGNAL(receivedDropEvent(int, QDropEvent
*)),
217 this, SLOT(tabDropEvent(int, QDropEvent
*)));
219 m_tabBar
->blockSignals(true); // signals get unblocked after at least 2 tabs are open
221 QWidget
* centralWidget
= new QWidget(this);
222 m_centralWidgetLayout
= new QVBoxLayout(centralWidget
);
223 m_centralWidgetLayout
->setSpacing(0);
224 m_centralWidgetLayout
->setMargin(0);
225 m_centralWidgetLayout
->addWidget(m_tabBar
);
226 m_centralWidgetLayout
->addWidget(m_viewTab
[m_tabIndex
].splitter
, 1);
228 setCentralWidget(centralWidget
);
230 emit
urlChanged(homeUrl
);
232 setupGUI(Keys
| Save
| Create
| ToolBar
);
233 stateChanged("new_file");
235 QClipboard
* clipboard
= QApplication::clipboard();
236 connect(clipboard
, SIGNAL(dataChanged()),
237 this, SLOT(updatePasteAction()));
239 if (generalSettings
->splitView()) {
246 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
247 showFilterBarAction
->setChecked(generalSettings
->filterBar());
250 menuBar()->setVisible(false);
251 // Assure a proper default size if Dolphin runs the first time
255 const bool showMenu
= !menuBar()->isHidden();
256 QAction
* showMenuBarAction
= actionCollection()->action(KStandardAction::name(KStandardAction::ShowMenubar
));
257 showMenuBarAction
->setChecked(showMenu
); // workaround for bug #171080
259 createToolBarMenuButton();
263 DolphinMainWindow::~DolphinMainWindow()
267 void DolphinMainWindow::openDirectories(const QList
<KUrl
>& dirs
)
269 if (dirs
.isEmpty()) {
273 if (dirs
.count() == 1) {
274 m_activeViewContainer
->setUrl(dirs
.first());
278 const int oldOpenTabsCount
= m_viewTab
.count();
280 const GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
281 const bool hasSplitView
= generalSettings
->splitView();
283 // Open each directory inside a new tab. If the "split view" option has been enabled,
284 // always show two directories within one tab.
285 QList
<KUrl
>::const_iterator it
= dirs
.begin();
286 while (it
!= dirs
.end()) {
290 if (hasSplitView
&& (it
!= dirs
.end())) {
291 const int tabIndex
= m_viewTab
.count() - 1;
292 m_viewTab
[tabIndex
].secondaryView
->setUrl(*it
);
297 // Remove the previously opened tabs
298 for (int i
= 0; i
< oldOpenTabsCount
; ++i
) {
303 void DolphinMainWindow::openFiles(const QList
<KUrl
>& files
)
305 if (files
.isEmpty()) {
309 // Get all distinct directories from 'files' and open a tab
310 // for each directory. If the "split view" option is enabled, two
311 // directories are shown inside one tab (see openDirectories()).
313 foreach (const KUrl
& url
, files
) {
314 const KUrl
dir(url
.directory());
315 if (!dirs
.contains(dir
)) {
320 openDirectories(dirs
);
322 // Select the files. Although the files can be split between several
323 // tabs, there is no need to split 'files' accordingly, as
324 // the DolphinView will just ignore invalid selections.
325 const int tabCount
= m_viewTab
.count();
326 for (int i
= 0; i
< tabCount
; ++i
) {
327 m_viewTab
[i
].primaryView
->view()->markUrlsAsSelected(files
);
328 if (m_viewTab
[i
].secondaryView
) {
329 m_viewTab
[i
].secondaryView
->view()->markUrlsAsSelected(files
);
334 void DolphinMainWindow::showCommand(CommandType command
)
336 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
338 case KIO::FileUndoManager::Copy
:
339 statusBar
->setMessage(i18nc("@info:status", "Successfully copied."),
340 DolphinStatusBar::OperationCompleted
);
342 case KIO::FileUndoManager::Move
:
343 statusBar
->setMessage(i18nc("@info:status", "Successfully moved."),
344 DolphinStatusBar::OperationCompleted
);
346 case KIO::FileUndoManager::Link
:
347 statusBar
->setMessage(i18nc("@info:status", "Successfully linked."),
348 DolphinStatusBar::OperationCompleted
);
350 case KIO::FileUndoManager::Trash
:
351 statusBar
->setMessage(i18nc("@info:status", "Successfully moved to trash."),
352 DolphinStatusBar::OperationCompleted
);
354 case KIO::FileUndoManager::Rename
:
355 statusBar
->setMessage(i18nc("@info:status", "Successfully renamed."),
356 DolphinStatusBar::OperationCompleted
);
359 case KIO::FileUndoManager::Mkdir
:
360 statusBar
->setMessage(i18nc("@info:status", "Created folder."),
361 DolphinStatusBar::OperationCompleted
);
369 void DolphinMainWindow::refreshViews()
371 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
373 // remember the current active view, as because of
374 // the refreshing the active view might change to
375 // the secondary view
376 DolphinViewContainer
* activeViewContainer
= m_activeViewContainer
;
378 const int tabCount
= m_viewTab
.count();
379 for (int i
= 0; i
< tabCount
; ++i
) {
380 m_viewTab
[i
].primaryView
->refresh();
381 if (m_viewTab
[i
].secondaryView
) {
382 m_viewTab
[i
].secondaryView
->refresh();
386 setActiveViewContainer(activeViewContainer
);
388 const GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
389 if (generalSettings
->modifiedStartupSettings()) {
390 // The startup settings have been changed by the user (see bug #254947).
391 // Synchronize the split-view setting with the active view:
392 const bool splitView
= generalSettings
->splitView();
393 const ViewTab
& activeTab
= m_viewTab
[m_tabIndex
];
394 const bool toggle
= ( splitView
&& !activeTab
.secondaryView
)
395 || (!splitView
&& activeTab
.secondaryView
);
402 void DolphinMainWindow::pasteIntoFolder()
404 m_activeViewContainer
->view()->pasteIntoFolder();
407 void DolphinMainWindow::changeUrl(const KUrl
& url
)
409 if (!KProtocolManager::supportsListing(url
)) {
410 // The URL navigator only checks for validity, not
411 // if the URL can be listed. An error message is
412 // shown due to DolphinViewContainer::restoreView().
416 DolphinViewContainer
* view
= activeViewContainer();
422 setUrlAsCaption(url
);
423 if (m_viewTab
.count() > 1) {
424 m_tabBar
->setTabText(m_tabIndex
, squeezedText(tabName(m_activeViewContainer
->url())));
426 const QString iconName
= KMimeType::iconNameForUrl(url
);
427 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(iconName
));
428 emit
urlChanged(url
);
432 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
434 KToggleAction
* editableLocationAction
=
435 static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
436 editableLocationAction
->setChecked(editable
);
439 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
443 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
444 int selectedUrlsCount
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedItemsCount();
445 if (m_viewTab
[m_tabIndex
].secondaryView
) {
446 selectedUrlsCount
+= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItemsCount();
449 QAction
* compareFilesAction
= actionCollection()->action("compare_files");
450 if (selectedUrlsCount
== 2) {
451 compareFilesAction
->setEnabled(isKompareInstalled());
453 compareFilesAction
->setEnabled(false);
456 emit
selectionChanged(selection
);
459 void DolphinMainWindow::slotRequestItemInfo(const KFileItem
& item
)
461 emit
requestItemInfo(item
);
464 void DolphinMainWindow::updateHistory()
466 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
467 const int index
= urlNavigator
->historyIndex();
469 QAction
* backAction
= actionCollection()->action("go_back");
470 backAction
->setToolTip(i18nc("@info", "Go back"));
472 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
475 QAction
* forwardAction
= actionCollection()->action("go_forward");
476 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
478 forwardAction
->setEnabled(index
> 0);
482 void DolphinMainWindow::updateFilterBarAction(bool show
)
484 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
485 showFilterBarAction
->setChecked(show
);
488 void DolphinMainWindow::openNewMainWindow()
490 KRun::run("dolphin", KUrl::List(), this);
493 void DolphinMainWindow::openNewTab()
495 const bool isUrlEditable
= m_activeViewContainer
->urlNavigator()->isUrlEditable();
497 openNewTab(m_activeViewContainer
->url());
498 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
500 // The URL navigator of the new tab should have the same editable state
501 // as the current tab
502 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
503 navigator
->setUrlEditable(isUrlEditable
);
506 // If a new tab is opened and the URL is editable, assure that
507 // the user can edit the URL without manually setting the focus
508 navigator
->setFocus();
512 void DolphinMainWindow::openNewTab(const KUrl
& url
)
514 QWidget
* focusWidget
= QApplication::focusWidget();
516 if (m_viewTab
.count() == 1) {
517 // Only one view is open currently and hence no tab is shown at
518 // all. Before creating a tab for 'url', provide a tab for the current URL.
519 const KUrl currentUrl
= m_activeViewContainer
->url();
520 m_tabBar
->addTab(KIcon(KMimeType::iconNameForUrl(currentUrl
)),
521 squeezedText(tabName(currentUrl
)));
522 m_tabBar
->blockSignals(false);
525 m_tabBar
->addTab(KIcon(KMimeType::iconNameForUrl(url
)),
526 squeezedText(tabName(url
)));
529 viewTab
.splitter
= new QSplitter(this);
530 viewTab
.splitter
->setChildrenCollapsible(false);
531 viewTab
.primaryView
= createViewContainer(url
, viewTab
.splitter
);
532 viewTab
.primaryView
->setActive(false);
533 connectViewSignals(viewTab
.primaryView
);
535 m_viewTab
.append(viewTab
);
537 actionCollection()->action("close_tab")->setEnabled(true);
539 // provide a split view, if the startup settings are set this way
540 const GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
541 if (generalSettings
->splitView()) {
542 const int tabIndex
= m_viewTab
.count() - 1;
543 createSecondaryView(tabIndex
);
544 m_viewTab
[tabIndex
].secondaryView
->setActive(true);
545 m_viewTab
[tabIndex
].isPrimaryViewActive
= false;
549 // The DolphinViewContainer grabbed the keyboard focus. As the tab is opened
550 // in background, assure that the previous focused widget gets the focus back.
551 focusWidget
->setFocus();
555 void DolphinMainWindow::activateNextTab()
557 if ((m_viewTab
.count() == 1) || (m_tabBar
->count() < 2)) {
561 const int tabIndex
= (m_tabBar
->currentIndex() + 1) % m_tabBar
->count();
562 m_tabBar
->setCurrentIndex(tabIndex
);
565 void DolphinMainWindow::activatePrevTab()
567 if ((m_viewTab
.count() == 1) || (m_tabBar
->count() < 2)) {
571 int tabIndex
= m_tabBar
->currentIndex() - 1;
572 if (tabIndex
== -1) {
573 tabIndex
= m_tabBar
->count() - 1;
575 m_tabBar
->setCurrentIndex(tabIndex
);
578 void DolphinMainWindow::openInNewTab()
580 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
581 if (list
.isEmpty()) {
582 openNewTab(m_activeViewContainer
->url());
583 } else if ((list
.count() == 1) && list
[0].isDir()) {
584 openNewTab(list
[0].url());
588 void DolphinMainWindow::openInNewWindow()
592 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
593 if (list
.isEmpty()) {
594 newWindowUrl
= m_activeViewContainer
->url();
595 } else if ((list
.count() == 1) && list
[0].isDir()) {
596 newWindowUrl
= list
[0].url();
599 if (!newWindowUrl
.isEmpty()) {
600 KRun::run("dolphin", KUrl::List() << newWindowUrl
, this);
604 void DolphinMainWindow::toggleActiveView()
606 if (!m_viewTab
[m_tabIndex
].secondaryView
) {
607 // only one view is available
611 Q_ASSERT(m_activeViewContainer
);
612 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
614 DolphinViewContainer
* left
= m_viewTab
[m_tabIndex
].primaryView
;
615 DolphinViewContainer
* right
= m_viewTab
[m_tabIndex
].secondaryView
;
616 setActiveViewContainer(m_activeViewContainer
== right
? left
: right
);
619 void DolphinMainWindow::showEvent(QShowEvent
* event
)
621 KXmlGuiWindow::showEvent(event
);
622 if (!event
->spontaneous()) {
623 m_activeViewContainer
->view()->setFocus();
627 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
629 DolphinSettings
& settings
= DolphinSettings::instance();
630 GeneralSettings
* generalSettings
= settings
.generalSettings();
632 // Find out if Dolphin is closed directly by the user or
633 // by the session manager because the session is closed
634 bool closedByUser
= true;
635 DolphinApplication
*application
= qobject_cast
<DolphinApplication
*>(qApp
);
636 if (application
&& application
->sessionSaving()) {
637 closedByUser
= false;
640 if ((m_viewTab
.count() > 1) && generalSettings
->confirmClosingMultipleTabs() && closedByUser
) {
641 // Ask the user if he really wants to quit and close all tabs.
642 // Open a confirmation dialog with 3 buttons:
643 // KDialog::Yes -> Quit
644 // KDialog::No -> Close only the current tab
645 // KDialog::Cancel -> do nothing
646 KDialog
*dialog
= new KDialog(this, Qt::Dialog
);
647 dialog
->setCaption(i18nc("@title:window", "Confirmation"));
648 dialog
->setButtons(KDialog::Yes
| KDialog::No
| KDialog::Cancel
);
649 dialog
->setModal(true);
650 dialog
->setButtonGuiItem(KDialog::Yes
, KStandardGuiItem::quit());
651 dialog
->setButtonGuiItem(KDialog::No
, KGuiItem(i18n("C&lose Current Tab"), KIcon("tab-close")));
652 dialog
->setButtonGuiItem(KDialog::Cancel
, KStandardGuiItem::cancel());
653 dialog
->setDefaultButton(KDialog::Yes
);
655 bool doNotAskAgainCheckboxResult
= false;
657 const int result
= KMessageBox::createKMessageBox(dialog
,
658 QMessageBox::Warning
,
659 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
661 i18n("Do not ask again"),
662 &doNotAskAgainCheckboxResult
,
663 KMessageBox::Notify
);
665 if (doNotAskAgainCheckboxResult
) {
666 generalSettings
->setConfirmClosingMultipleTabs(false);
674 // Close only the current tab
682 generalSettings
->setFirstRun(false);
686 if (m_searchDockIsTemporaryVisible
) {
687 QDockWidget
* searchDock
= findChild
<QDockWidget
*>("searchDock");
691 m_searchDockIsTemporaryVisible
= false;
694 KXmlGuiWindow::closeEvent(event
);
697 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
699 const int tabCount
= m_viewTab
.count();
700 group
.writeEntry("Tab Count", tabCount
);
701 group
.writeEntry("Active Tab Index", m_tabBar
->currentIndex());
703 for (int i
= 0; i
< tabCount
; ++i
) {
704 const DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
705 group
.writeEntry(tabProperty("Primary URL", i
), cont
->url().url());
706 group
.writeEntry(tabProperty("Primary Editable", i
),
707 cont
->urlNavigator()->isUrlEditable());
709 cont
= m_viewTab
[i
].secondaryView
;
711 group
.writeEntry(tabProperty("Secondary URL", i
), cont
->url().url());
712 group
.writeEntry(tabProperty("Secondary Editable", i
),
713 cont
->urlNavigator()->isUrlEditable());
718 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
720 const int tabCount
= group
.readEntry("Tab Count", 1);
721 for (int i
= 0; i
< tabCount
; ++i
) {
722 DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
724 cont
->setUrl(group
.readEntry(tabProperty("Primary URL", i
)));
725 const bool editable
= group
.readEntry(tabProperty("Primary Editable", i
), false);
726 cont
->urlNavigator()->setUrlEditable(editable
);
728 cont
= m_viewTab
[i
].secondaryView
;
729 const QString secondaryUrl
= group
.readEntry(tabProperty("Secondary URL", i
));
730 if (!secondaryUrl
.isEmpty()) {
732 // a secondary view should be shown, but no one is available
733 // currently -> create a new view
735 cont
= m_viewTab
[i
].secondaryView
;
739 cont
->setUrl(secondaryUrl
);
740 const bool editable
= group
.readEntry(tabProperty("Secondary Editable", i
), false);
741 cont
->urlNavigator()->setUrlEditable(editable
);
743 // no secondary view should be shown, but the default setting shows
744 // one already -> close the view
748 // openNewTab() needs to be called only tabCount - 1 times
749 if (i
!= tabCount
- 1) {
754 const int index
= group
.readEntry("Active Tab Index", 0);
755 m_tabBar
->setCurrentIndex(index
);
758 void DolphinMainWindow::updateNewMenu()
760 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->showHiddenFiles());
761 m_newFileMenu
->checkUpToDate();
762 m_newFileMenu
->setPopupFiles(activeViewContainer()->url());
765 void DolphinMainWindow::createDirectory()
767 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->showHiddenFiles());
768 m_newFileMenu
->setPopupFiles(activeViewContainer()->url());
769 m_newFileMenu
->createDirectory();
772 void DolphinMainWindow::quit()
777 void DolphinMainWindow::showErrorMessage(const QString
& message
)
779 if (!message
.isEmpty()) {
780 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
781 statusBar
->setMessage(message
, DolphinStatusBar::Error
);
785 void DolphinMainWindow::slotUndoAvailable(bool available
)
787 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
789 undoAction
->setEnabled(available
);
793 void DolphinMainWindow::restoreClosedTab(QAction
* action
)
795 if (action
->data().toBool()) {
796 // clear all actions except the "Empty Recently Closed Tabs"
797 // action and the separator
798 QList
<QAction
*> actions
= m_recentTabsMenu
->menu()->actions();
799 const int count
= actions
.size();
800 for (int i
= 2; i
< count
; ++i
) {
801 m_recentTabsMenu
->menu()->removeAction(actions
.at(i
));
804 const ClosedTab closedTab
= action
->data().value
<ClosedTab
>();
805 openNewTab(closedTab
.primaryUrl
);
806 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
808 if (closedTab
.isSplit
) {
809 // create secondary view
811 m_viewTab
[m_tabIndex
].secondaryView
->setUrl(closedTab
.secondaryUrl
);
814 m_recentTabsMenu
->removeAction(action
);
817 if (m_recentTabsMenu
->menu()->actions().count() == 2) {
818 m_recentTabsMenu
->setEnabled(false);
822 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
824 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
826 undoAction
->setText(text
);
830 void DolphinMainWindow::undo()
833 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
834 KIO::FileUndoManager::self()->undo();
837 void DolphinMainWindow::cut()
839 m_activeViewContainer
->view()->cutSelectedItems();
842 void DolphinMainWindow::copy()
844 m_activeViewContainer
->view()->copySelectedItems();
847 void DolphinMainWindow::paste()
849 m_activeViewContainer
->view()->paste();
852 void DolphinMainWindow::find()
854 m_activeViewContainer
->setSearchModeEnabled(true);
857 void DolphinMainWindow::updatePasteAction()
859 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
860 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
861 pasteAction
->setEnabled(pasteInfo
.first
);
862 pasteAction
->setText(pasteInfo
.second
);
865 void DolphinMainWindow::selectAll()
869 // if the URL navigator is editable and focused, select the whole
870 // URL instead of all items of the view
872 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
873 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit(); // krazy:exclude=qclasses
874 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
875 lineEdit
->hasFocus();
877 lineEdit
->selectAll();
879 m_activeViewContainer
->view()->selectAll();
883 void DolphinMainWindow::invertSelection()
886 m_activeViewContainer
->view()->invertSelection();
889 void DolphinMainWindow::toggleSplitView()
891 if (!m_viewTab
[m_tabIndex
].secondaryView
) {
892 createSecondaryView(m_tabIndex
);
893 setActiveViewContainer(m_viewTab
[m_tabIndex
].secondaryView
);
894 } else if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
895 // remove secondary view
896 m_viewTab
[m_tabIndex
].secondaryView
->close();
897 m_viewTab
[m_tabIndex
].secondaryView
->deleteLater();
898 m_viewTab
[m_tabIndex
].secondaryView
= 0;
900 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
902 // The primary view is active and should be closed. Hence from a users point of view
903 // the content of the secondary view should be moved to the primary view.
904 // From an implementation point of view it is more efficient to close
905 // the primary view and exchange the internal pointers afterwards.
907 m_viewTab
[m_tabIndex
].primaryView
->close();
908 m_viewTab
[m_tabIndex
].primaryView
->deleteLater();
909 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
910 m_viewTab
[m_tabIndex
].secondaryView
= 0;
912 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
918 void DolphinMainWindow::reloadView()
921 m_activeViewContainer
->view()->reload();
924 void DolphinMainWindow::stopLoading()
926 m_activeViewContainer
->view()->stopLoading();
929 void DolphinMainWindow::enableStopAction()
931 actionCollection()->action("stop")->setEnabled(true);
934 void DolphinMainWindow::disableStopAction()
936 actionCollection()->action("stop")->setEnabled(false);
939 void DolphinMainWindow::showFilterBar()
941 m_activeViewContainer
->setFilterBarVisible(true);
944 void DolphinMainWindow::toggleEditLocation()
948 QAction
* action
= actionCollection()->action("editable_location");
949 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
950 urlNavigator
->setUrlEditable(action
->isChecked());
953 void DolphinMainWindow::replaceLocation()
955 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
956 navigator
->setUrlEditable(true);
957 navigator
->setFocus();
959 // select the whole text of the combo box editor
960 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit(); // krazy:exclude=qclasses
961 lineEdit
->selectAll();
964 void DolphinMainWindow::togglePanelLockState()
966 GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
968 const bool newLockState
= !generalSettings
->lockPanels();
969 foreach (QObject
* child
, children()) {
970 DolphinDockWidget
* dock
= qobject_cast
<DolphinDockWidget
*>(child
);
972 dock
->setLocked(newLockState
);
976 generalSettings
->setLockPanels(newLockState
);
979 void DolphinMainWindow::slotPlacesPanelVisibilityChanged(bool visible
)
981 const int tabCount
= m_viewTab
.count();
982 for (int i
= 0; i
< tabCount
; ++i
) {
983 ViewTab
& tab
= m_viewTab
[i
];
984 Q_ASSERT(tab
.primaryView
);
985 tab
.primaryView
->urlNavigator()->setPlacesSelectorVisible(!visible
);
986 if (tab
.secondaryView
) {
987 tab
.secondaryView
->urlNavigator()->setPlacesSelectorVisible(!visible
);
992 void DolphinMainWindow::goBack()
994 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
995 urlNavigator
->goBack();
997 if (urlNavigator
->locationState().isEmpty()) {
998 // An empty location state indicates a redirection URL,
999 // which must be skipped too
1000 urlNavigator
->goBack();
1004 void DolphinMainWindow::goForward()
1006 m_activeViewContainer
->urlNavigator()->goForward();
1009 void DolphinMainWindow::goUp()
1011 m_activeViewContainer
->urlNavigator()->goUp();
1014 void DolphinMainWindow::goHome()
1016 m_activeViewContainer
->urlNavigator()->goHome();
1019 void DolphinMainWindow::goBack(Qt::MouseButtons buttons
)
1021 // The default case (left button pressed) is handled in goBack().
1022 if (buttons
== Qt::MidButton
) {
1023 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
1024 const int index
= urlNavigator
->historyIndex() + 1;
1025 openNewTab(urlNavigator
->locationUrl(index
));
1029 void DolphinMainWindow::goForward(Qt::MouseButtons buttons
)
1031 // The default case (left button pressed) is handled in goForward().
1032 if (buttons
== Qt::MidButton
) {
1033 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
1034 const int index
= urlNavigator
->historyIndex() - 1;
1035 openNewTab(urlNavigator
->locationUrl(index
));
1039 void DolphinMainWindow::goUp(Qt::MouseButtons buttons
)
1041 // The default case (left button pressed) is handled in goUp().
1042 if (buttons
== Qt::MidButton
) {
1043 openNewTab(activeViewContainer()->url().upUrl());
1047 void DolphinMainWindow::compareFiles()
1049 // The method is only invoked if exactly 2 files have
1050 // been selected. The selected files may be:
1051 // - both in the primary view
1052 // - both in the secondary view
1053 // - one in the primary view and the other in the secondary
1055 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
1060 KFileItemList items
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedItems();
1062 switch (items
.count()) {
1064 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
);
1065 items
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItems();
1066 Q_ASSERT(items
.count() == 2);
1067 urlA
= items
[0].url();
1068 urlB
= items
[1].url();
1073 urlA
= items
[0].url();
1074 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
);
1075 items
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItems();
1076 Q_ASSERT(items
.count() == 1);
1077 urlB
= items
[0].url();
1082 urlA
= items
[0].url();
1083 urlB
= items
[1].url();
1088 // may not happen: compareFiles may only get invoked if 2
1089 // files are selected
1094 QString
command("kompare -c \"");
1095 command
.append(urlA
.pathOrUrl());
1096 command
.append("\" \"");
1097 command
.append(urlB
.pathOrUrl());
1098 command
.append('\"');
1099 KRun::runCommand(command
, "Kompare", "kompare", this);
1102 void DolphinMainWindow::toggleShowMenuBar()
1104 const bool visible
= menuBar()->isVisible();
1105 menuBar()->setVisible(!visible
);
1107 createToolBarMenuButton();
1109 deleteToolBarMenuButton();
1113 void DolphinMainWindow::openTerminal()
1115 QString
dir(QDir::homePath());
1117 // If the given directory is not local, it can still be the URL of an
1118 // ioslave using UDS_LOCAL_PATH which to be converted first.
1119 KUrl url
= KIO::NetAccess::mostLocalUrl(m_activeViewContainer
->url(), this);
1121 //If the URL is local after the above conversion, set the directory.
1122 if (url
.isLocalFile()) {
1123 dir
= url
.toLocalFile();
1126 KToolInvocation::invokeTerminal(QString(), dir
);
1129 void DolphinMainWindow::editSettings()
1131 if (!m_settingsDialog
) {
1132 const KUrl url
= activeViewContainer()->url();
1133 DolphinSettingsDialog
* settingsDialog
= new DolphinSettingsDialog(url
, this);
1134 connect(settingsDialog
, SIGNAL(settingsChanged()), this, SLOT(reloadView()));
1135 settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1136 settingsDialog
->show();
1137 m_settingsDialog
= settingsDialog
;
1139 m_settingsDialog
.data()->raise();
1143 void DolphinMainWindow::setActiveTab(int index
)
1145 Q_ASSERT(index
>= 0);
1146 Q_ASSERT(index
< m_viewTab
.count());
1147 if (index
== m_tabIndex
) {
1151 // hide current tab content
1152 ViewTab
& hiddenTab
= m_viewTab
[m_tabIndex
];
1153 hiddenTab
.isPrimaryViewActive
= hiddenTab
.primaryView
->isActive();
1154 hiddenTab
.primaryView
->setActive(false);
1155 if (hiddenTab
.secondaryView
) {
1156 hiddenTab
.secondaryView
->setActive(false);
1158 QSplitter
* splitter
= m_viewTab
[m_tabIndex
].splitter
;
1160 m_centralWidgetLayout
->removeWidget(splitter
);
1162 // show active tab content
1165 ViewTab
& viewTab
= m_viewTab
[index
];
1166 m_centralWidgetLayout
->addWidget(viewTab
.splitter
, 1);
1167 viewTab
.primaryView
->show();
1168 if (viewTab
.secondaryView
) {
1169 viewTab
.secondaryView
->show();
1171 viewTab
.splitter
->show();
1173 setActiveViewContainer(viewTab
.isPrimaryViewActive
? viewTab
.primaryView
:
1174 viewTab
.secondaryView
);
1177 void DolphinMainWindow::closeTab()
1179 closeTab(m_tabBar
->currentIndex());
1182 void DolphinMainWindow::closeTab(int index
)
1184 Q_ASSERT(index
>= 0);
1185 Q_ASSERT(index
< m_viewTab
.count());
1186 if (m_viewTab
.count() == 1) {
1187 // the last tab may never get closed
1191 if (index
== m_tabIndex
) {
1192 // The tab that should be closed is the active tab. Activate the
1193 // previous tab before closing the tab.
1194 m_tabBar
->setCurrentIndex((index
> 0) ? index
- 1 : 1);
1196 rememberClosedTab(index
);
1199 m_viewTab
[index
].primaryView
->deleteLater();
1200 if (m_viewTab
[index
].secondaryView
) {
1201 m_viewTab
[index
].secondaryView
->deleteLater();
1203 m_viewTab
[index
].splitter
->deleteLater();
1204 m_viewTab
.erase(m_viewTab
.begin() + index
);
1206 m_tabBar
->blockSignals(true);
1207 m_tabBar
->removeTab(index
);
1209 if (m_tabIndex
> index
) {
1211 Q_ASSERT(m_tabIndex
>= 0);
1214 // if only one tab is left, also remove the tab entry so that
1215 // closing the last tab is not possible
1216 if (m_viewTab
.count() == 1) {
1217 m_tabBar
->removeTab(0);
1218 actionCollection()->action("close_tab")->setEnabled(false);
1220 m_tabBar
->blockSignals(false);
1224 void DolphinMainWindow::openTabContextMenu(int index
, const QPoint
& pos
)
1228 QAction
* newTabAction
= menu
.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab"));
1229 newTabAction
->setShortcut(actionCollection()->action("new_tab")->shortcut());
1231 QAction
* detachTabAction
= menu
.addAction(KIcon("tab-detach"), i18nc("@action:inmenu", "Detach Tab"));
1233 QAction
* closeOtherTabsAction
= menu
.addAction(KIcon("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs"));
1235 QAction
* closeTabAction
= menu
.addAction(KIcon("tab-close"), i18nc("@action:inmenu", "Close Tab"));
1236 closeTabAction
->setShortcut(actionCollection()->action("close_tab")->shortcut());
1237 QAction
* selectedAction
= menu
.exec(pos
);
1238 if (selectedAction
== newTabAction
) {
1239 const ViewTab
& tab
= m_viewTab
[index
];
1240 Q_ASSERT(tab
.primaryView
);
1241 const KUrl url
= tab
.secondaryView
&& tab
.secondaryView
->isActive() ?
1242 tab
.secondaryView
->url() : tab
.primaryView
->url();
1244 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
1245 } else if (selectedAction
== detachTabAction
) {
1246 const QString
separator(QLatin1Char(' '));
1247 QString command
= QLatin1String("dolphin");
1249 const ViewTab
& tab
= m_viewTab
[index
];
1250 Q_ASSERT(tab
.primaryView
);
1252 command
+= separator
+ tab
.primaryView
->url().url();
1253 if (tab
.secondaryView
) {
1254 command
+= separator
+ tab
.secondaryView
->url().url();
1255 command
+= separator
+ QLatin1String("-split");
1258 KRun::runCommand(command
, this);
1261 } else if (selectedAction
== closeOtherTabsAction
) {
1262 const int count
= m_tabBar
->count();
1263 for (int i
= 0; i
< index
; ++i
) {
1266 for (int i
= index
+ 1; i
< count
; ++i
) {
1269 } else if (selectedAction
== closeTabAction
) {
1274 void DolphinMainWindow::slotTabMoved(int from
, int to
)
1276 m_viewTab
.move(from
, to
);
1277 m_tabIndex
= m_tabBar
->currentIndex();
1280 void DolphinMainWindow::handlePlacesClick(const KUrl
& url
, Qt::MouseButtons buttons
)
1282 if (buttons
& Qt::MidButton
) {
1284 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
1290 void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent
* event
, bool& canDecode
)
1292 canDecode
= KUrl::List::canDecode(event
->mimeData());
1295 void DolphinMainWindow::handleUrl(const KUrl
& url
)
1297 delete m_lastHandleUrlStatJob
;
1298 m_lastHandleUrlStatJob
= 0;
1300 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1301 activeViewContainer()->setUrl(url
);
1302 } else if (KProtocolManager::supportsListing(url
)) {
1303 // stat the URL to see if it is a dir or not
1304 m_lastHandleUrlStatJob
= KIO::stat(url
, KIO::HideProgressInfo
);
1305 connect(m_lastHandleUrlStatJob
, SIGNAL(result(KJob
*)),
1306 this, SLOT(slotHandleUrlStatFinished(KJob
*)));
1309 new KRun(url
, this);
1313 void DolphinMainWindow::slotHandleUrlStatFinished(KJob
* job
)
1315 m_lastHandleUrlStatJob
= 0;
1316 const KIO::UDSEntry entry
= static_cast<KIO::StatJob
*>(job
)->statResult();
1317 const KUrl url
= static_cast<KIO::StatJob
*>(job
)->url();
1318 if (entry
.isDir()) {
1319 activeViewContainer()->setUrl(url
);
1321 new KRun(url
, this);
1325 void DolphinMainWindow::tabDropEvent(int tab
, QDropEvent
* event
)
1327 const KUrl::List urls
= KUrl::List::fromMimeData(event
->mimeData());
1328 if (!urls
.isEmpty() && tab
!= -1) {
1329 const ViewTab
& viewTab
= m_viewTab
[tab
];
1330 const KUrl destPath
= viewTab
.isPrimaryViewActive
? viewTab
.primaryView
->url() : viewTab
.secondaryView
->url();
1331 DragAndDropHelper::instance().dropUrls(KFileItem(), destPath
, event
, m_tabBar
);
1335 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1337 newFileMenu()->setEnabled(isFolderWritable
);
1340 void DolphinMainWindow::slotSearchModeChanged(bool enabled
)
1343 const KUrl url
= m_activeViewContainer
->url();
1344 const DolphinSearchInformation
& searchInfo
= DolphinSearchInformation::instance();
1345 if (!searchInfo
.isIndexingEnabled() || !searchInfo
.isPathIndexed(url
)) {
1349 QDockWidget
* searchDock
= findChild
<QDockWidget
*>("searchDock");
1355 if (!searchDock
->isVisible()) {
1356 m_searchDockIsTemporaryVisible
= true;
1360 if (searchDock
->isVisible() && m_searchDockIsTemporaryVisible
) {
1363 m_searchDockIsTemporaryVisible
= false;
1366 SearchPanel
* searchPanel
= qobject_cast
<SearchPanel
*>(searchDock
->widget());
1368 // Per default any search-operation triggered by the Search Panel is done
1370 SearchPanel::SearchMode searchMode
= SearchPanel::Everywhere
;
1372 if (enabled
&& (SearchSettings::location() == QLatin1String("FromHere"))) {
1373 // Only if the search-mode is enabled it is visible for the user whether
1374 // a searching is done "Everywhere" or "From Here" (= current directory).
1375 searchMode
= SearchPanel::FromCurrentDir
;
1377 searchPanel
->setSearchMode(searchMode
);
1384 void DolphinMainWindow::openContextMenu(const KFileItem
& item
,
1386 const QList
<QAction
*>& customActions
)
1388 QPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, item
, url
);
1389 contextMenu
->setCustomActions(customActions
);
1390 const DolphinContextMenu::Command command
= contextMenu
->open();
1393 case DolphinContextMenu::OpenParentFolderInNewWindow
: {
1394 KRun::run("dolphin", KUrl::List() << item
.url().upUrl(), this);
1398 case DolphinContextMenu::OpenParentFolderInNewTab
:
1399 openNewTab(item
.url().upUrl());
1402 case DolphinContextMenu::None
:
1410 void DolphinMainWindow::updateToolBarMenu()
1412 KMenu
* menu
= qobject_cast
<KMenu
*>(sender());
1415 // All actions get cleared by KMenu::clear(). The sub-menus are deleted
1416 // by connecting to the aboutToHide() signal from the parent-menu.
1419 const GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
1421 KActionCollection
* ac
= actionCollection();
1423 // Add "Edit" actions
1424 bool added
= addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Undo
)), menu
) |
1425 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Find
)), menu
) |
1426 addActionToMenu(ac
->action("select_all"), menu
) |
1427 addActionToMenu(ac
->action("invert_selection"), menu
);
1430 menu
->addSeparator();
1433 // Add "View" actions
1434 if (!generalSettings
->showZoomSlider()) {
1435 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomIn
)), menu
);
1436 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomOut
)), menu
);
1437 menu
->addSeparator();
1440 added
= addActionToMenu(ac
->action("view_mode"), menu
) |
1441 addActionToMenu(ac
->action("sort"), menu
) |
1442 addActionToMenu(ac
->action("additional_info"), menu
) |
1443 addActionToMenu(ac
->action("show_preview"), menu
) |
1444 addActionToMenu(ac
->action("show_in_groups"), menu
) |
1445 addActionToMenu(ac
->action("show_hidden_files"), menu
);
1448 menu
->addSeparator();
1451 added
= addActionToMenu(ac
->action("split_view"), menu
) |
1452 addActionToMenu(ac
->action("reload"), menu
) |
1453 addActionToMenu(ac
->action("view_properties"), menu
);
1455 menu
->addSeparator();
1458 addActionToMenu(ac
->action("panels"), menu
);
1459 KMenu
* locationBarMenu
= new KMenu(i18nc("@action:inmenu", "Location Bar"), menu
);
1460 locationBarMenu
->addAction(ac
->action("editable_location"));
1461 locationBarMenu
->addAction(ac
->action("replace_location"));
1462 menu
->addMenu(locationBarMenu
);
1464 menu
->addSeparator();
1467 KMenu
* goMenu
= new KMenu(i18nc("@action:inmenu", "Go"), menu
);
1468 connect(menu
, SIGNAL(aboutToHide()), goMenu
, SLOT(deleteLater()));
1469 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Back
)));
1470 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Forward
)));
1471 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Up
)));
1472 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Home
)));
1473 goMenu
->addAction(ac
->action("closed_tabs"));
1474 menu
->addMenu(goMenu
);
1477 KMenu
* toolsMenu
= new KMenu(i18nc("@action:inmenu", "Tools"), menu
);
1478 connect(menu
, SIGNAL(aboutToHide()), toolsMenu
, SLOT(deleteLater()));
1479 toolsMenu
->addAction(ac
->action("show_filter_bar"));
1480 toolsMenu
->addAction(ac
->action("compare_files"));
1481 toolsMenu
->addAction(ac
->action("open_terminal"));
1482 toolsMenu
->addAction(ac
->action("change_remote_encoding"));
1483 menu
->addMenu(toolsMenu
);
1485 // Add "Settings" menu entries
1486 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::KeyBindings
)), menu
);
1487 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ConfigureToolbars
)), menu
);
1488 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Preferences
)), menu
);
1491 KMenu
* helpMenu
= new KMenu(i18nc("@action:inmenu", "Help"), menu
);
1492 connect(menu
, SIGNAL(aboutToHide()), helpMenu
, SLOT(deleteLater()));
1493 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::HelpContents
)));
1494 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::WhatsThis
)));
1495 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::AboutApp
)));
1496 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::AboutKDE
)));
1497 menu
->addMenu(helpMenu
);
1499 menu
->addSeparator();
1500 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ShowMenubar
)), menu
);
1503 void DolphinMainWindow::updateToolBar()
1505 if (!menuBar()->isVisible()) {
1506 createToolBarMenuButton();
1510 void DolphinMainWindow::slotToolBarSpacerDeleted()
1512 m_toolBarSpacer
= 0;
1513 m_updateToolBarTimer
->start();
1516 void DolphinMainWindow::slotToolBarMenuButtonDeleted()
1518 m_openToolBarMenuButton
= 0;
1519 m_updateToolBarTimer
->start();
1522 void DolphinMainWindow::slotToolBarIconSizeChanged(const QSize
& iconSize
)
1524 if (m_openToolBarMenuButton
) {
1525 m_openToolBarMenuButton
->setIconSize(iconSize
);
1529 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer
* viewContainer
)
1531 Q_ASSERT(viewContainer
);
1532 Q_ASSERT((viewContainer
== m_viewTab
[m_tabIndex
].primaryView
) ||
1533 (viewContainer
== m_viewTab
[m_tabIndex
].secondaryView
));
1534 if (m_activeViewContainer
== viewContainer
) {
1538 m_activeViewContainer
->setActive(false);
1539 m_activeViewContainer
= viewContainer
;
1541 // Activating the view container might trigger a recursive setActiveViewContainer() call
1542 // inside DolphinMainWindow::toggleActiveView() when having a split view. Temporary
1543 // disconnect the activated() signal in this case:
1544 disconnect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1545 m_activeViewContainer
->setActive(true);
1546 connect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1548 m_actionHandler
->setCurrentView(viewContainer
->view());
1551 updateEditActions();
1552 updateViewActions();
1555 const KUrl url
= m_activeViewContainer
->url();
1556 setUrlAsCaption(url
);
1557 if (m_viewTab
.count() > 1) {
1558 m_tabBar
->setTabText(m_tabIndex
, tabName(url
));
1559 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(KMimeType::iconNameForUrl(url
)));
1562 emit
urlChanged(url
);
1565 DolphinViewContainer
* DolphinMainWindow::createViewContainer(const KUrl
& url
, QWidget
* parent
)
1567 DolphinViewContainer
* container
= new DolphinViewContainer(url
, parent
);
1569 // The places-selector from the URL navigator should only be shown
1570 // if the places dock is invisible
1571 QDockWidget
* placesDock
= findChild
<QDockWidget
*>("placesDock");
1572 container
->urlNavigator()->setPlacesSelectorVisible(!placesDock
|| !placesDock
->isVisible());
1577 void DolphinMainWindow::setupActions()
1579 // setup 'File' menu
1580 m_newFileMenu
= new DolphinNewFileMenu(this);
1581 KMenu
* menu
= m_newFileMenu
->menu();
1582 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1583 menu
->setIcon(KIcon("document-new"));
1584 connect(menu
, SIGNAL(aboutToShow()),
1585 this, SLOT(updateNewMenu()));
1587 KAction
* newWindow
= actionCollection()->addAction("new_window");
1588 newWindow
->setIcon(KIcon("window-new"));
1589 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1590 newWindow
->setShortcut(Qt::CTRL
| Qt::Key_N
);
1591 connect(newWindow
, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1593 KAction
* newTab
= actionCollection()->addAction("new_tab");
1594 newTab
->setIcon(KIcon("tab-new"));
1595 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1596 newTab
->setShortcut(KShortcut(Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
));
1597 connect(newTab
, SIGNAL(triggered()), this, SLOT(openNewTab()));
1599 KAction
* closeTab
= actionCollection()->addAction("close_tab");
1600 closeTab
->setIcon(KIcon("tab-close"));
1601 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1602 closeTab
->setShortcut(Qt::CTRL
| Qt::Key_W
);
1603 closeTab
->setEnabled(false);
1604 connect(closeTab
, SIGNAL(triggered()), this, SLOT(closeTab()));
1606 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1608 // setup 'Edit' menu
1609 KStandardAction::undo(this,
1611 actionCollection());
1613 // need to remove shift+del from cut action, else the shortcut for deletejob
1615 KAction
* cut
= KStandardAction::cut(this, SLOT(cut()), actionCollection());
1616 KShortcut cutShortcut
= cut
->shortcut();
1617 cutShortcut
.remove(Qt::SHIFT
| Qt::Key_Delete
, KShortcut::KeepEmpty
);
1618 cut
->setShortcut(cutShortcut
);
1619 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1620 KAction
* paste
= KStandardAction::paste(this, SLOT(paste()), actionCollection());
1621 // The text of the paste-action is modified dynamically by Dolphin
1622 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1623 // due to the long text, the text "Paste" is used:
1624 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1626 KStandardAction::find(this, SLOT(find()), actionCollection());
1628 KAction
* selectAll
= actionCollection()->addAction("select_all");
1629 selectAll
->setText(i18nc("@action:inmenu Edit", "Select All"));
1630 selectAll
->setShortcut(Qt::CTRL
| Qt::Key_A
);
1631 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
1633 KAction
* invertSelection
= actionCollection()->addAction("invert_selection");
1634 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1635 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1636 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
1638 // setup 'View' menu
1639 // (note that most of it is set up in DolphinViewActionHandler)
1641 KAction
* split
= actionCollection()->addAction("split_view");
1642 split
->setShortcut(Qt::Key_F3
);
1643 updateSplitAction();
1644 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1646 KAction
* reload
= actionCollection()->addAction("reload");
1647 reload
->setText(i18nc("@action:inmenu View", "Reload"));
1648 reload
->setShortcut(Qt::Key_F5
);
1649 reload
->setIcon(KIcon("view-refresh"));
1650 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
1652 KAction
* stop
= actionCollection()->addAction("stop");
1653 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1654 stop
->setToolTip(i18nc("@info", "Stop loading"));
1655 stop
->setIcon(KIcon("process-stop"));
1656 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
1658 KToggleAction
* editableLocation
= actionCollection()->add
<KToggleAction
>("editable_location");
1659 editableLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1660 editableLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
1661 connect(editableLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1663 KAction
* replaceLocation
= actionCollection()->addAction("replace_location");
1664 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1665 replaceLocation
->setShortcut(Qt::Key_F6
);
1666 connect(replaceLocation
, SIGNAL(triggered()), this, SLOT(replaceLocation()));
1669 KAction
* backAction
= KStandardAction::back(this, SLOT(goBack()), actionCollection());
1670 connect(backAction
, SIGNAL(triggered(Qt::MouseButtons
, Qt::KeyboardModifiers
)), this, SLOT(goBack(Qt::MouseButtons
)));
1671 KShortcut backShortcut
= backAction
->shortcut();
1672 backShortcut
.setAlternate(Qt::Key_Backspace
);
1673 backAction
->setShortcut(backShortcut
);
1675 m_recentTabsMenu
= new KActionMenu(i18n("Recently Closed Tabs"), this);
1676 m_recentTabsMenu
->setIcon(KIcon("edit-undo"));
1677 actionCollection()->addAction("closed_tabs", m_recentTabsMenu
);
1678 connect(m_recentTabsMenu
->menu(), SIGNAL(triggered(QAction
*)),
1679 this, SLOT(restoreClosedTab(QAction
*)));
1681 QAction
* action
= new QAction(i18n("Empty Recently Closed Tabs"), m_recentTabsMenu
);
1682 action
->setIcon(KIcon("edit-clear-list"));
1683 action
->setData(QVariant::fromValue(true));
1684 m_recentTabsMenu
->addAction(action
);
1685 m_recentTabsMenu
->addSeparator();
1686 m_recentTabsMenu
->setEnabled(false);
1688 KAction
* forwardAction
= KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1689 connect(forwardAction
, SIGNAL(triggered(Qt::MouseButtons
, Qt::KeyboardModifiers
)), this, SLOT(goForward(Qt::MouseButtons
)));
1691 KAction
* upAction
= KStandardAction::up(this, SLOT(goUp()), actionCollection());
1692 connect(upAction
, SIGNAL(triggered(Qt::MouseButtons
, Qt::KeyboardModifiers
)), this, SLOT(goUp(Qt::MouseButtons
)));
1694 KStandardAction::home(this, SLOT(goHome()), actionCollection());
1696 // setup 'Tools' menu
1697 KAction
* showFilterBar
= actionCollection()->addAction("show_filter_bar");
1698 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1699 showFilterBar
->setIcon(KIcon("view-filter"));
1700 showFilterBar
->setShortcut(Qt::CTRL
| Qt::Key_I
);
1701 connect(showFilterBar
, SIGNAL(triggered()), this, SLOT(showFilterBar()));
1703 KAction
* compareFiles
= actionCollection()->addAction("compare_files");
1704 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1705 compareFiles
->setIcon(KIcon("kompare"));
1706 compareFiles
->setEnabled(false);
1707 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
1709 KAction
* openTerminal
= actionCollection()->addAction("open_terminal");
1710 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1711 openTerminal
->setIcon(KIcon("utilities-terminal"));
1712 openTerminal
->setShortcut(Qt::SHIFT
| Qt::Key_F4
);
1713 connect(openTerminal
, SIGNAL(triggered()), this, SLOT(openTerminal()));
1715 // setup 'Settings' menu
1716 KStandardAction::showMenubar(this, SLOT(toggleShowMenuBar()), actionCollection());
1717 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1719 // not in menu actions
1720 QList
<QKeySequence
> nextTabKeys
;
1721 nextTabKeys
.append(KStandardShortcut::tabNext().primary());
1722 nextTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::Key_Tab
));
1724 QList
<QKeySequence
> prevTabKeys
;
1725 prevTabKeys
.append(KStandardShortcut::tabPrev().primary());
1726 prevTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::SHIFT
| Qt::Key_Tab
));
1728 KAction
* activateNextTab
= actionCollection()->addAction("activate_next_tab");
1729 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1730 connect(activateNextTab
, SIGNAL(triggered()), SLOT(activateNextTab()));
1731 activateNextTab
->setShortcuts(QApplication::isRightToLeft() ? prevTabKeys
: nextTabKeys
);
1733 KAction
* activatePrevTab
= actionCollection()->addAction("activate_prev_tab");
1734 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1735 connect(activatePrevTab
, SIGNAL(triggered()), SLOT(activatePrevTab()));
1736 activatePrevTab
->setShortcuts(QApplication::isRightToLeft() ? nextTabKeys
: prevTabKeys
);
1739 KAction
* openInNewTab
= actionCollection()->addAction("open_in_new_tab");
1740 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1741 openInNewTab
->setIcon(KIcon("tab-new"));
1742 connect(openInNewTab
, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1744 KAction
* openInNewWindow
= actionCollection()->addAction("open_in_new_window");
1745 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1746 openInNewWindow
->setIcon(KIcon("window-new"));
1747 connect(openInNewWindow
, SIGNAL(triggered()), this, SLOT(openInNewWindow()));
1750 void DolphinMainWindow::setupDockWidgets()
1752 const bool lock
= DolphinSettings::instance().generalSettings()->lockPanels();
1754 KDualAction
* lockLayoutAction
= actionCollection()->add
<KDualAction
>("lock_panels");
1755 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
1756 lockLayoutAction
->setActiveIcon(KIcon("object-unlocked"));
1757 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
1758 lockLayoutAction
->setInactiveIcon(KIcon("object-locked"));
1759 lockLayoutAction
->setActive(lock
);
1760 connect(lockLayoutAction
, SIGNAL(triggered()), this, SLOT(togglePanelLockState()));
1762 // Setup "Information"
1763 DolphinDockWidget
* infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
1764 infoDock
->setLocked(lock
);
1765 infoDock
->setObjectName("infoDock");
1766 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1767 Panel
* infoPanel
= new InformationPanel(infoDock
);
1768 infoPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1769 connect(infoPanel
, SIGNAL(urlActivated(KUrl
)), this, SLOT(handleUrl(KUrl
)));
1770 infoDock
->setWidget(infoPanel
);
1772 QAction
* infoAction
= infoDock
->toggleViewAction();
1773 infoAction
->setIcon(KIcon("dialog-information"));
1774 infoAction
->setShortcut(Qt::Key_F11
);
1775 addActionCloneToCollection(infoAction
, "show_information_panel");
1777 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1778 connect(this, SIGNAL(urlChanged(KUrl
)),
1779 infoPanel
, SLOT(setUrl(KUrl
)));
1780 connect(this, SIGNAL(selectionChanged(KFileItemList
)),
1781 infoPanel
, SLOT(setSelection(KFileItemList
)));
1782 connect(this, SIGNAL(requestItemInfo(KFileItem
)),
1783 infoPanel
, SLOT(requestDelayedItemInfo(KFileItem
)));
1786 DolphinDockWidget
* foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
1787 foldersDock
->setLocked(lock
);
1788 foldersDock
->setObjectName("foldersDock");
1789 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1790 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1791 foldersPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1792 foldersDock
->setWidget(foldersPanel
);
1794 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1795 foldersAction
->setShortcut(Qt::Key_F7
);
1796 foldersAction
->setIcon(KIcon("folder"));
1797 addActionCloneToCollection(foldersAction
, "show_folders_panel");
1799 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1800 connect(this, SIGNAL(urlChanged(KUrl
)),
1801 foldersPanel
, SLOT(setUrl(KUrl
)));
1802 connect(foldersPanel
, SIGNAL(changeUrl(KUrl
, Qt::MouseButtons
)),
1803 this, SLOT(handlePlacesClick(KUrl
, Qt::MouseButtons
)));
1807 DolphinDockWidget
* terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1808 terminalDock
->setLocked(lock
);
1809 terminalDock
->setObjectName("terminalDock");
1810 terminalDock
->setAllowedAreas(Qt::TopDockWidgetArea
| Qt::BottomDockWidgetArea
);
1811 Panel
* terminalPanel
= new TerminalPanel(terminalDock
);
1812 terminalPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1813 terminalDock
->setWidget(terminalPanel
);
1815 connect(terminalPanel
, SIGNAL(hideTerminalPanel()), terminalDock
, SLOT(hide()));
1817 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1818 terminalAction
->setShortcut(Qt::Key_F4
);
1819 terminalAction
->setIcon(KIcon("utilities-terminal"));
1820 addActionCloneToCollection(terminalAction
, "show_terminal_panel");
1822 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1823 connect(this, SIGNAL(urlChanged(KUrl
)),
1824 terminalPanel
, SLOT(setUrl(KUrl
)));
1829 DolphinDockWidget
* searchDock
= new DolphinDockWidget(i18nc("@title:window", "Search"));
1830 searchDock
->setLocked(lock
);
1831 searchDock
->setObjectName("searchDock");
1832 searchDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1833 Panel
* searchPanel
= new SearchPanel(searchDock
);
1834 searchPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1835 connect(searchPanel
, SIGNAL(urlActivated(KUrl
)), this, SLOT(handleUrl(KUrl
)));
1836 searchDock
->setWidget(searchPanel
);
1838 QAction
* searchAction
= searchDock
->toggleViewAction();
1839 searchAction
->setShortcut(Qt::Key_F12
);
1840 searchAction
->setIcon(KIcon("system-search"));
1841 addActionCloneToCollection(searchAction
, "show_search_panel");
1842 addDockWidget(Qt::RightDockWidgetArea
, searchDock
);
1843 connect(this, SIGNAL(urlChanged(KUrl
)),
1844 searchPanel
, SLOT(setUrl(KUrl
)));
1847 const bool firstRun
= DolphinSettings::instance().generalSettings()->firstRun();
1850 foldersDock
->hide();
1852 terminalDock
->hide();
1860 DolphinDockWidget
* placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
1861 placesDock
->setLocked(lock
);
1862 placesDock
->setObjectName("placesDock");
1863 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1865 PlacesPanel
* placesPanel
= new PlacesPanel(placesDock
);
1866 QAction
* separator
= new QAction(placesPanel
);
1867 separator
->setSeparator(true);
1868 QList
<QAction
*> placesActions
;
1869 placesActions
.append(separator
);
1870 placesActions
.append(lockLayoutAction
);
1871 placesPanel
->addActions(placesActions
);
1872 placesPanel
->setModel(DolphinSettings::instance().placesModel());
1873 placesPanel
->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff
);
1874 placesDock
->setWidget(placesPanel
);
1876 QAction
* placesAction
= placesDock
->toggleViewAction();
1877 placesAction
->setShortcut(Qt::Key_F9
);
1878 placesAction
->setIcon(KIcon("bookmarks"));
1879 addActionCloneToCollection(placesAction
, "show_places_panel");
1881 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1882 connect(placesPanel
, SIGNAL(urlChanged(KUrl
, Qt::MouseButtons
)),
1883 this, SLOT(handlePlacesClick(KUrl
, Qt::MouseButtons
)));
1884 connect(this, SIGNAL(urlChanged(KUrl
)),
1885 placesPanel
, SLOT(setUrl(KUrl
)));
1886 connect(placesDock
, SIGNAL(visibilityChanged(bool)),
1887 this, SLOT(slotPlacesPanelVisibilityChanged(bool)));
1889 // Add actions into the "Panels" menu
1890 KActionMenu
* panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Panels"), this);
1891 actionCollection()->addAction("panels", panelsMenu
);
1892 panelsMenu
->setDelayed(false);
1893 panelsMenu
->addAction(placesAction
);
1894 panelsMenu
->addAction(infoAction
);
1895 panelsMenu
->addAction(foldersAction
);
1897 panelsMenu
->addAction(terminalAction
);
1900 panelsMenu
->addAction(searchAction
);
1902 panelsMenu
->addSeparator();
1903 panelsMenu
->addAction(lockLayoutAction
);
1906 void DolphinMainWindow::updateEditActions()
1908 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1909 if (list
.isEmpty()) {
1910 stateChanged("has_no_selection");
1912 stateChanged("has_selection");
1914 KActionCollection
* col
= actionCollection();
1915 QAction
* renameAction
= col
->action("rename");
1916 QAction
* moveToTrashAction
= col
->action("move_to_trash");
1917 QAction
* deleteAction
= col
->action("delete");
1918 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
1919 QAction
* deleteWithTrashShortcut
= col
->action("delete_shortcut"); // see DolphinViewActionHandler
1921 KFileItemListProperties
capabilities(list
);
1922 const bool enableMoveToTrash
= capabilities
.isLocal() && capabilities
.supportsMoving();
1924 renameAction
->setEnabled(capabilities
.supportsMoving());
1925 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1926 deleteAction
->setEnabled(capabilities
.supportsDeleting());
1927 deleteWithTrashShortcut
->setEnabled(capabilities
.supportsDeleting() && !enableMoveToTrash
);
1928 cutAction
->setEnabled(capabilities
.supportsMoving());
1930 updatePasteAction();
1933 void DolphinMainWindow::updateViewActions()
1935 m_actionHandler
->updateViewActions();
1937 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1938 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
1940 updateSplitAction();
1942 QAction
* editableLocactionAction
= actionCollection()->action("editable_location");
1943 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
1944 editableLocactionAction
->setChecked(urlNavigator
->isUrlEditable());
1947 void DolphinMainWindow::updateGoActions()
1949 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
1950 const KUrl currentUrl
= m_activeViewContainer
->url();
1951 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
1954 void DolphinMainWindow::createToolBarMenuButton()
1956 if (m_toolBarSpacer
&& m_openToolBarMenuButton
) {
1959 Q_ASSERT(!m_toolBarSpacer
);
1960 Q_ASSERT(!m_openToolBarMenuButton
);
1962 m_toolBarSpacer
= new QWidget(this);
1963 m_toolBarSpacer
->setSizePolicy(QSizePolicy::MinimumExpanding
, QSizePolicy::MinimumExpanding
);
1965 m_openToolBarMenuButton
= new QToolButton(this);
1966 m_openToolBarMenuButton
->setIcon(KIcon("configure"));
1967 m_openToolBarMenuButton
->setPopupMode(QToolButton::InstantPopup
);
1968 m_openToolBarMenuButton
->setToolTip(i18nc("@info:tooltip", "Configure and control Dolphin"));
1970 KMenu
* toolBarMenu
= new ToolBarMenu(m_openToolBarMenuButton
);
1971 connect(toolBarMenu
, SIGNAL(aboutToShow()), this, SLOT(updateToolBarMenu()));
1973 m_openToolBarMenuButton
->setMenu(toolBarMenu
);
1975 toolBar()->addWidget(m_toolBarSpacer
);
1976 toolBar()->addWidget(m_openToolBarMenuButton
);
1977 connect(toolBar(), SIGNAL(iconSizeChanged(QSize
)), this, SLOT(slotToolBarIconSizeChanged(QSize
)));
1979 // The added widgets are owned by the toolbar and may get deleted when e.g. the toolbar
1980 // gets edited. In this case we must add them again. The adding is done asynchronously by
1981 // m_updateToolBarTimer.
1982 connect(m_toolBarSpacer
, SIGNAL(destroyed()), this, SLOT(slotToolBarSpacerDeleted()));
1983 connect(m_openToolBarMenuButton
, SIGNAL(destroyed()), this, SLOT(slotToolBarMenuButtonDeleted()));
1984 m_updateToolBarTimer
= new QTimer(this);
1985 m_updateToolBarTimer
->setInterval(500);
1986 connect(m_updateToolBarTimer
, SIGNAL(timeout()), this, SLOT(updateToolBar()));
1989 void DolphinMainWindow::deleteToolBarMenuButton()
1991 delete m_toolBarSpacer
;
1992 m_toolBarSpacer
= 0;
1994 delete m_openToolBarMenuButton
;
1995 m_openToolBarMenuButton
= 0;
1997 delete m_updateToolBarTimer
;
1998 m_updateToolBarTimer
= 0;
2001 bool DolphinMainWindow::addActionToMenu(QAction
* action
, KMenu
* menu
)
2006 const KToolBar
* toolBarWidget
= toolBar();
2007 foreach (const QWidget
* widget
, action
->associatedWidgets()) {
2008 if (widget
== toolBarWidget
) {
2013 menu
->addAction(action
);
2017 void DolphinMainWindow::rememberClosedTab(int index
)
2019 KMenu
* tabsMenu
= m_recentTabsMenu
->menu();
2021 const QString primaryPath
= m_viewTab
[index
].primaryView
->url().path();
2022 const QString iconName
= KMimeType::iconNameForUrl(primaryPath
);
2024 QAction
* action
= new QAction(squeezedText(primaryPath
), tabsMenu
);
2026 ClosedTab closedTab
;
2027 closedTab
.primaryUrl
= m_viewTab
[index
].primaryView
->url();
2029 if (m_viewTab
[index
].secondaryView
) {
2030 closedTab
.secondaryUrl
= m_viewTab
[index
].secondaryView
->url();
2031 closedTab
.isSplit
= true;
2033 closedTab
.isSplit
= false;
2036 action
->setData(QVariant::fromValue(closedTab
));
2037 action
->setIcon(KIcon(iconName
));
2039 // add the closed tab menu entry after the separator and
2040 // "Empty Recently Closed Tabs" entry
2041 if (tabsMenu
->actions().size() == 2) {
2042 tabsMenu
->addAction(action
);
2044 tabsMenu
->insertAction(tabsMenu
->actions().at(2), action
);
2047 // assure that only up to 8 closed tabs are shown in the menu
2048 if (tabsMenu
->actions().size() > 8) {
2049 tabsMenu
->removeAction(tabsMenu
->actions().last());
2051 actionCollection()->action("closed_tabs")->setEnabled(true);
2052 KAcceleratorManager::manage(tabsMenu
);
2055 void DolphinMainWindow::clearStatusBar()
2057 m_activeViewContainer
->statusBar()->clear();
2060 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
2062 connect(container
, SIGNAL(showFilterBarChanged(bool)),
2063 this, SLOT(updateFilterBarAction(bool)));
2064 connect(container
, SIGNAL(writeStateChanged(bool)),
2065 this, SLOT(slotWriteStateChanged(bool)));
2066 connect(container
, SIGNAL(searchModeChanged(bool)),
2067 this, SLOT(slotSearchModeChanged(bool)));
2069 DolphinView
* view
= container
->view();
2070 connect(view
, SIGNAL(selectionChanged(KFileItemList
)),
2071 this, SLOT(slotSelectionChanged(KFileItemList
)));
2072 connect(view
, SIGNAL(requestItemInfo(KFileItem
)),
2073 this, SLOT(slotRequestItemInfo(KFileItem
)));
2074 connect(view
, SIGNAL(activated()),
2075 this, SLOT(toggleActiveView()));
2076 connect(view
, SIGNAL(tabRequested(const KUrl
&)),
2077 this, SLOT(openNewTab(const KUrl
&)));
2078 connect(view
, SIGNAL(requestContextMenu(KFileItem
, const KUrl
&, const QList
<QAction
*>&)),
2079 this, SLOT(openContextMenu(KFileItem
, const KUrl
&, const QList
<QAction
*>&)));
2080 connect(view
, SIGNAL(startedPathLoading(KUrl
)),
2081 this, SLOT(enableStopAction()));
2082 connect(view
, SIGNAL(finishedPathLoading(KUrl
)),
2083 this, SLOT(disableStopAction()));
2085 const KUrlNavigator
* navigator
= container
->urlNavigator();
2086 connect(navigator
, SIGNAL(urlChanged(const KUrl
&)),
2087 this, SLOT(changeUrl(const KUrl
&)));
2088 connect(navigator
, SIGNAL(historyChanged()),
2089 this, SLOT(updateHistory()));
2090 connect(navigator
, SIGNAL(editableStateChanged(bool)),
2091 this, SLOT(slotEditableStateChanged(bool)));
2092 connect(navigator
, SIGNAL(tabRequested(const KUrl
&)),
2093 this, SLOT(openNewTab(KUrl
)));
2096 void DolphinMainWindow::updateSplitAction()
2098 QAction
* splitAction
= actionCollection()->action("split_view");
2099 if (m_viewTab
[m_tabIndex
].secondaryView
) {
2100 if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
2101 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
2102 splitAction
->setToolTip(i18nc("@info", "Close right view"));
2103 splitAction
->setIcon(KIcon("view-right-close"));
2105 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
2106 splitAction
->setToolTip(i18nc("@info", "Close left view"));
2107 splitAction
->setIcon(KIcon("view-left-close"));
2110 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
2111 splitAction
->setToolTip(i18nc("@info", "Split view"));
2112 splitAction
->setIcon(KIcon("view-right-new"));
2116 QString
DolphinMainWindow::tabName(const KUrl
& url
) const
2119 if (url
.equals(KUrl("file:///"))) {
2122 name
= url
.fileName();
2123 if (name
.isEmpty()) {
2124 name
= url
.protocol();
2126 // Make sure that a '&' inside the directory name is displayed correctly
2127 // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
2128 name
.replace('&', "&&");
2134 bool DolphinMainWindow::isKompareInstalled() const
2136 static bool initialized
= false;
2137 static bool installed
= false;
2139 // TODO: maybe replace this approach later by using a menu
2140 // plugin like kdiff3plugin.cpp
2141 installed
= !KGlobal::dirs()->findExe("kompare").isEmpty();
2147 void DolphinMainWindow::createSecondaryView(int tabIndex
)
2149 QSplitter
* splitter
= m_viewTab
[tabIndex
].splitter
;
2150 const int newWidth
= (m_viewTab
[tabIndex
].primaryView
->width() - splitter
->handleWidth()) / 2;
2152 const DolphinView
* view
= m_viewTab
[tabIndex
].primaryView
->view();
2153 m_viewTab
[tabIndex
].secondaryView
= createViewContainer(view
->rootUrl(), 0);
2154 splitter
->addWidget(m_viewTab
[tabIndex
].secondaryView
);
2155 splitter
->setSizes(QList
<int>() << newWidth
<< newWidth
);
2156 connectViewSignals(m_viewTab
[tabIndex
].secondaryView
);
2157 m_viewTab
[tabIndex
].secondaryView
->setActive(false);
2158 m_viewTab
[tabIndex
].secondaryView
->show();
2161 QString
DolphinMainWindow::tabProperty(const QString
& property
, int tabIndex
) const
2163 return "Tab " + QString::number(tabIndex
) + ' ' + property
;
2166 void DolphinMainWindow::setUrlAsCaption(const KUrl
& url
)
2169 if (!url
.isLocalFile()) {
2170 caption
.append(url
.protocol() + " - ");
2171 if (url
.hasHost()) {
2172 caption
.append(url
.host() + " - ");
2176 const QString fileName
= url
.fileName().isEmpty() ? "/" : url
.fileName();
2177 caption
.append(fileName
);
2179 setCaption(caption
);
2182 QString
DolphinMainWindow::squeezedText(const QString
& text
) const
2184 const QFontMetrics fm
= fontMetrics();
2185 return fm
.elidedText(text
, Qt::ElideMiddle
, fm
.maxWidth() * 10);
2188 void DolphinMainWindow::addActionCloneToCollection(QAction
* action
, const QString
& actionName
)
2190 KAction
* actionClone
= actionCollection()->addAction(actionName
);
2191 actionClone
->setText(action
->text());
2192 actionClone
->setIcon(action
->icon());
2193 connect(actionClone
, SIGNAL(triggered()), action
, SLOT(trigger()));
2196 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
2197 KIO::FileUndoManager::UiInterface()
2201 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2205 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
2207 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
2209 DolphinStatusBar
* statusBar
= mainWin
->activeViewContainer()->statusBar();
2210 statusBar
->setMessage(job
->errorString(), DolphinStatusBar::Error
);
2212 KIO::FileUndoManager::UiInterface::jobError(job
);
2216 ToolBarMenu::ToolBarMenu(QWidget
* parent
) :
2221 ToolBarMenu::~ToolBarMenu()
2225 void ToolBarMenu::showEvent(QShowEvent
* event
)
2227 KMenu::showEvent(event
);
2229 // Adjust the position of the menu to be shown within the
2230 // Dolphin window to reduce the cases that sub-menus might overlap
2231 // the right screen border.
2233 QWidget
* button
= parentWidget();
2234 if (layoutDirection() == Qt::RightToLeft
) {
2235 pos
= button
->mapToGlobal(QPoint(0, button
->height()));
2237 pos
= button
->mapToGlobal(QPoint(button
->width(), button
->height()));
2238 pos
.rx() -= width();
2241 // Assure that the menu is not shown outside the screen boundaries and
2242 // that it does not overlap with the parent button.
2243 const QRect screen
= QApplication::desktop()->screenGeometry(QCursor::pos());
2246 } else if (pos
.x() + width() >= screen
.width()) {
2247 pos
.rx() = screen
.width() - width();
2252 } else if (pos
.y() + height() >= screen
.height()) {
2253 pos
.ry() = button
->mapToGlobal(QPoint(0, 0)).y() - height();
2259 #include "dolphinmainwindow.moc"