]>
cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> *
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"
23 #include "dolphinviewactionhandler.h"
25 #include <config-nepomuk.h>
27 #include "dolphinapplication.h"
28 #include "dolphinnewmenu.h"
29 #include "settings/dolphinsettings.h"
30 #include "settings/dolphinsettingsdialog.h"
31 #include "dolphinsearchbox.h"
32 #include "dolphinstatusbar.h"
33 #include "dolphinviewcontainer.h"
34 #include "panels/folders/folderspanel.h"
35 #include "panels/places/placespanel.h"
36 #include "panels/information/informationpanel.h"
37 #include "panels/information/metadatawidget.h"
38 #include "mainwindowadaptor.h"
39 #include "viewproperties.h"
42 #include "panels/terminal/terminalpanel.h"
45 #include "dolphin_generalsettings.h"
46 #include "dolphin_iconsmodesettings.h"
47 #include "draganddrophelper.h"
50 #include <kactioncollection.h>
52 #include <kdesktopfile.h>
53 #include <kdeversion.h>
54 #include <kfiledialog.h>
55 #include <kfileplacesmodel.h>
57 #include <klineedit.h>
60 #include <kiconloader.h>
61 #include <kio/netaccess.h>
62 #include <kinputdialog.h>
64 #include <kprotocolmanager.h>
67 #include <kmessagebox.h>
68 #include <konq_fileitemcapabilities.h>
69 #include <konqmimedata.h>
70 #include <kprotocolinfo.h>
73 #include <kstandarddirs.h>
74 #include <kstatusbar.h>
75 #include <kstandardaction.h>
77 #include <ktoggleaction.h>
78 #include <kurlnavigator.h>
80 #include <kurlcombobox.h>
82 #include <QDBusMessage>
87 #include <QDockWidget>
88 #include <kacceleratormanager.h>
91 * Remembers the tab configuration if a tab has been closed.
92 * Each closed tab can be restored by the menu
93 * "Go -> Recently Closed Tabs".
101 Q_DECLARE_METATYPE(ClosedTab
)
103 DolphinMainWindow::DolphinMainWindow(int id
) :
108 m_activeViewContainer(0),
109 m_centralWidgetLayout(0),
117 setObjectName("Dolphin#");
119 m_viewTab
.append(ViewTab());
121 new MainWindowAdaptor(this);
122 QDBusConnection::sessionBus().registerObject(QString("/dolphin/MainWindow%1").arg(m_id
), this);
124 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
125 undoManager
->setUiInterface(new UndoUiInterface());
127 connect(undoManager
, SIGNAL(undoAvailable(bool)),
128 this, SLOT(slotUndoAvailable(bool)));
129 connect(undoManager
, SIGNAL(undoTextChanged(const QString
&)),
130 this, SLOT(slotUndoTextChanged(const QString
&)));
131 connect(undoManager
, SIGNAL(jobRecordingStarted(CommandType
)),
132 this, SLOT(clearStatusBar()));
133 connect(undoManager
, SIGNAL(jobRecordingFinished(CommandType
)),
134 this, SLOT(showCommand(CommandType
)));
135 connect(DolphinSettings::instance().placesModel(), SIGNAL(errorMessage(const QString
&)),
136 this, SLOT(showErrorMessage(const QString
&)));
137 connect(&DragAndDropHelper::instance(), SIGNAL(errorMessage(const QString
&)),
138 this, SLOT(showErrorMessage(const QString
&)));
141 DolphinMainWindow::~DolphinMainWindow()
143 DolphinApplication::app()->removeMainWindow(this);
146 void DolphinMainWindow::toggleViews()
148 if (m_viewTab
[m_tabIndex
].primaryView
== 0) {
152 // move secondary view from the last position of the splitter
153 // to the first position
154 m_viewTab
[m_tabIndex
].splitter
->insertWidget(0, m_viewTab
[m_tabIndex
].secondaryView
);
156 DolphinViewContainer
* container
= m_viewTab
[m_tabIndex
].primaryView
;
157 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
158 m_viewTab
[m_tabIndex
].secondaryView
= container
;
161 void DolphinMainWindow::showCommand(CommandType command
)
163 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
165 case KIO::FileUndoManager::Copy
:
166 statusBar
->setMessage(i18nc("@info:status", "Copy operation completed."),
167 DolphinStatusBar::OperationCompleted
);
169 case KIO::FileUndoManager::Move
:
170 statusBar
->setMessage(i18nc("@info:status", "Move operation completed."),
171 DolphinStatusBar::OperationCompleted
);
173 case KIO::FileUndoManager::Link
:
174 statusBar
->setMessage(i18nc("@info:status", "Link operation completed."),
175 DolphinStatusBar::OperationCompleted
);
177 case KIO::FileUndoManager::Trash
:
178 statusBar
->setMessage(i18nc("@info:status", "Move to trash operation completed."),
179 DolphinStatusBar::OperationCompleted
);
181 case KIO::FileUndoManager::Rename
:
182 statusBar
->setMessage(i18nc("@info:status", "Renaming operation completed."),
183 DolphinStatusBar::OperationCompleted
);
186 case KIO::FileUndoManager::Mkdir
:
187 statusBar
->setMessage(i18nc("@info:status", "Created folder."),
188 DolphinStatusBar::OperationCompleted
);
196 void DolphinMainWindow::refreshViews()
198 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
200 // remember the current active view, as because of
201 // the refreshing the active view might change to
202 // the secondary view
203 DolphinViewContainer
* activeViewContainer
= m_activeViewContainer
;
205 const int tabCount
= m_viewTab
.count();
206 for (int i
= 0; i
< tabCount
; ++i
) {
207 m_viewTab
[i
].primaryView
->refresh();
208 if (m_viewTab
[i
].secondaryView
!= 0) {
209 m_viewTab
[i
].secondaryView
->refresh();
213 setActiveViewContainer(activeViewContainer
);
216 void DolphinMainWindow::pasteIntoFolder()
218 m_activeViewContainer
->view()->pasteIntoFolder();
221 void DolphinMainWindow::changeUrl(const KUrl
& url
)
223 if (!KProtocolManager::supportsListing(url
)) {
224 // The URL navigator only checks for validity, not
225 // if the URL can be listed. An error message is
226 // shown due to DolphinViewContainer::restoreView().
230 DolphinViewContainer
* view
= activeViewContainer();
236 setCaption(url
.fileName());
237 if (m_viewTab
.count() > 1) {
238 m_tabBar
->setTabText(m_tabIndex
, tabName(url
));
240 emit
urlChanged(url
);
244 void DolphinMainWindow::changeSelection(const KFileItemList
& selection
)
246 activeViewContainer()->view()->changeSelection(selection
);
249 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
251 KToggleAction
* editableLocationAction
=
252 static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
253 editableLocationAction
->setChecked(editable
);
256 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
260 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
261 int selectedUrlsCount
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedItemsCount();
262 if (m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
263 selectedUrlsCount
+= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItemsCount();
266 QAction
* compareFilesAction
= actionCollection()->action("compare_files");
267 if (selectedUrlsCount
== 2) {
268 compareFilesAction
->setEnabled(isKompareInstalled());
270 compareFilesAction
->setEnabled(false);
273 m_activeViewContainer
->updateStatusBar();
275 emit
selectionChanged(selection
);
278 void DolphinMainWindow::slotWheelMoved(int wheelDelta
)
280 if (wheelDelta
> 0) {
287 void DolphinMainWindow::slotRequestItemInfo(const KFileItem
& item
)
289 emit
requestItemInfo(item
);
292 void DolphinMainWindow::updateHistory()
294 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
295 const int index
= urlNavigator
->historyIndex();
297 QAction
* backAction
= actionCollection()->action("go_back");
298 if (backAction
!= 0) {
299 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
302 QAction
* forwardAction
= actionCollection()->action("go_forward");
303 if (forwardAction
!= 0) {
304 forwardAction
->setEnabled(index
> 0);
308 void DolphinMainWindow::updateFilterBarAction(bool show
)
310 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
311 showFilterBarAction
->setChecked(show
);
314 void DolphinMainWindow::openNewMainWindow()
316 DolphinApplication::app()->createMainWindow()->show();
319 void DolphinMainWindow::openNewTab()
321 openNewTab(m_activeViewContainer
->url());
322 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
324 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
325 if (navigator
->isUrlEditable()) {
326 // if a new tab is opened and the URL is editable, assure that
327 // the user can edit the URL without manually setting the focus
328 navigator
->setFocus();
332 void DolphinMainWindow::openNewTab(const KUrl
& url
)
334 if (m_viewTab
.count() == 1) {
335 // Only one view is open currently and hence no tab is shown at
336 // all. Before creating a tab for 'url', provide a tab for the current URL.
337 m_tabBar
->addTab(KIcon("folder"), tabName(m_activeViewContainer
->url()));
338 m_tabBar
->blockSignals(false);
341 m_tabBar
->addTab(KIcon("folder"), tabName(url
));
344 viewTab
.splitter
= new QSplitter(this);
345 viewTab
.primaryView
= new DolphinViewContainer(this, viewTab
.splitter
, url
);
346 viewTab
.primaryView
->setActive(false);
347 connectViewSignals(viewTab
.primaryView
);
348 viewTab
.primaryView
->view()->reload();
350 m_viewTab
.append(viewTab
);
352 actionCollection()->action("close_tab")->setEnabled(true);
354 // provide a split view, if the startup settings are set this way
355 const GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
356 if (generalSettings
->splitView()) {
357 const int tabIndex
= m_viewTab
.count() - 1;
358 createSecondaryView(tabIndex
);
359 m_viewTab
[tabIndex
].secondaryView
->setActive(true);
360 m_viewTab
[tabIndex
].isPrimaryViewActive
= false;
364 void DolphinMainWindow::activateNextTab()
366 if ((m_viewTab
.count() == 1) || (m_tabBar
->count() < 2)) {
370 const int tabIndex
= (m_tabBar
->currentIndex() + 1) % m_tabBar
->count();
371 m_tabBar
->setCurrentIndex(tabIndex
);
374 void DolphinMainWindow::activatePrevTab()
376 if ((m_viewTab
.count() == 1) || (m_tabBar
->count() < 2)) {
380 int tabIndex
= m_tabBar
->currentIndex() - 1;
381 if (tabIndex
== -1) {
382 tabIndex
= m_tabBar
->count() - 1;
384 m_tabBar
->setCurrentIndex(tabIndex
);
387 void DolphinMainWindow::openInNewTab()
389 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
390 if ((list
.count() == 1) && list
[0].isDir()) {
391 openNewTab(m_activeViewContainer
->view()->selectedUrls()[0]);
395 void DolphinMainWindow::openInNewWindow()
397 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
398 if ((list
.count() == 1) && list
[0].isDir()) {
399 DolphinMainWindow
* window
= DolphinApplication::app()->createMainWindow();
400 window
->changeUrl(m_activeViewContainer
->view()->selectedUrls()[0]);
405 void DolphinMainWindow::toggleActiveView()
407 if (m_viewTab
[m_tabIndex
].secondaryView
== 0) {
408 // only one view is available
412 Q_ASSERT(m_activeViewContainer
!= 0);
413 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
415 DolphinViewContainer
* left
= m_viewTab
[m_tabIndex
].primaryView
;
416 DolphinViewContainer
* right
= m_viewTab
[m_tabIndex
].secondaryView
;
417 setActiveViewContainer(m_activeViewContainer
== right
? left
: right
);
420 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
422 DolphinSettings
& settings
= DolphinSettings::instance();
423 GeneralSettings
* generalSettings
= settings
.generalSettings();
424 generalSettings
->setFirstRun(false);
428 KXmlGuiWindow::closeEvent(event
);
431 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
433 // TODO: remember tabs
434 DolphinViewContainer
* cont
= m_viewTab
[m_tabIndex
].primaryView
;
435 group
.writeEntry("Primary Url", cont
->url().url());
436 group
.writeEntry("Primary Editable Url", cont
->isUrlEditable());
438 cont
= m_viewTab
[m_tabIndex
].secondaryView
;
440 group
.writeEntry("Secondary Url", cont
->url().url());
441 group
.writeEntry("Secondary Editable Url", cont
->isUrlEditable());
445 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
448 DolphinViewContainer
* cont
= m_viewTab
[m_tabIndex
].primaryView
;
450 cont
->setUrl(group
.readEntry("Primary Url"));
451 bool editable
= group
.readEntry("Primary Editable Url", false);
452 cont
->urlNavigator()->setUrlEditable(editable
);
454 cont
= m_viewTab
[m_tabIndex
].secondaryView
;
455 const QString secondaryUrl
= group
.readEntry("Secondary Url");
456 if (!secondaryUrl
.isEmpty()) {
458 // a secondary view should be shown, but no one is available
459 // currently -> create a new view
461 cont
= m_viewTab
[m_tabIndex
].secondaryView
;
465 cont
->setUrl(secondaryUrl
);
466 bool editable
= group
.readEntry("Secondary Editable Url", false);
467 cont
->urlNavigator()->setUrlEditable(editable
);
468 } else if (cont
!= 0) {
469 // no secondary view should be shown, but the default setting shows
470 // one already -> close the view
475 void DolphinMainWindow::updateNewMenu()
477 m_newMenu
->slotCheckUpToDate();
478 m_newMenu
->setPopupFiles(activeViewContainer()->url());
481 void DolphinMainWindow::quit()
486 void DolphinMainWindow::showErrorMessage(const QString
& message
)
488 if (!message
.isEmpty()) {
489 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
490 statusBar
->setMessage(message
, DolphinStatusBar::Error
);
494 void DolphinMainWindow::slotUndoAvailable(bool available
)
496 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
497 if (undoAction
!= 0) {
498 undoAction
->setEnabled(available
);
502 void DolphinMainWindow::restoreClosedTab(QAction
* action
)
504 if (action
->data().toBool()) {
505 // clear all actions except the "Empty Recently Closed Tabs"
506 // action and the separator
507 QList
<QAction
*> actions
= m_recentTabsMenu
->menu()->actions();
508 const int count
= actions
.size();
509 for (int i
= 2; i
< count
; i
++) {
510 m_recentTabsMenu
->menu()->removeAction(actions
.at(i
));
513 const ClosedTab closedTab
= action
->data().value
<ClosedTab
>();
514 openNewTab(closedTab
.primaryUrl
);
515 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
517 if (closedTab
.isSplit
) {
518 // create secondary view
520 m_viewTab
[m_tabIndex
].secondaryView
->setUrl(closedTab
.secondaryUrl
);
523 m_recentTabsMenu
->removeAction(action
);
526 if (m_recentTabsMenu
->menu()->actions().count() == 2) {
527 m_recentTabsMenu
->setEnabled(false);
531 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
533 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
534 if (undoAction
!= 0) {
535 undoAction
->setText(text
);
539 void DolphinMainWindow::undo()
542 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
543 KIO::FileUndoManager::self()->undo();
546 void DolphinMainWindow::cut()
548 m_activeViewContainer
->view()->cutSelectedItems();
551 void DolphinMainWindow::copy()
553 m_activeViewContainer
->view()->copySelectedItems();
556 void DolphinMainWindow::paste()
558 m_activeViewContainer
->view()->paste();
561 void DolphinMainWindow::updatePasteAction()
563 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
564 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
565 pasteAction
->setEnabled(pasteInfo
.first
);
566 pasteAction
->setText(pasteInfo
.second
);
569 void DolphinMainWindow::selectAll()
573 // if the URL navigator is editable and focused, select the whole
574 // URL instead of all items of the view
576 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
577 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit();
578 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
579 lineEdit
->hasFocus();
581 lineEdit
->selectAll();
583 m_activeViewContainer
->view()->selectAll();
587 void DolphinMainWindow::invertSelection()
590 m_activeViewContainer
->view()->invertSelection();
593 void DolphinMainWindow::toggleSplitView()
595 if (m_viewTab
[m_tabIndex
].secondaryView
== 0) {
596 createSecondaryView(m_tabIndex
);
597 setActiveViewContainer(m_viewTab
[m_tabIndex
].secondaryView
);
598 } else if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
599 // remove secondary view
600 m_viewTab
[m_tabIndex
].secondaryView
->close();
601 m_viewTab
[m_tabIndex
].secondaryView
->deleteLater();
602 m_viewTab
[m_tabIndex
].secondaryView
= 0;
604 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
606 // The primary view is active and should be closed. Hence from a users point of view
607 // the content of the secondary view should be moved to the primary view.
608 // From an implementation point of view it is more efficient to close
609 // the primary view and exchange the internal pointers afterwards.
611 m_viewTab
[m_tabIndex
].primaryView
->close();
612 m_viewTab
[m_tabIndex
].primaryView
->deleteLater();
613 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
614 m_viewTab
[m_tabIndex
].secondaryView
= 0;
616 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
622 void DolphinMainWindow::reloadView()
625 m_activeViewContainer
->view()->reload();
628 void DolphinMainWindow::stopLoading()
632 void DolphinMainWindow::toggleFilterBarVisibility(bool show
)
634 m_activeViewContainer
->showFilterBar(show
);
637 void DolphinMainWindow::toggleEditLocation()
641 QAction
* action
= actionCollection()->action("editable_location");
642 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
643 urlNavigator
->setUrlEditable(action
->isChecked());
646 void DolphinMainWindow::replaceLocation()
648 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
649 navigator
->setUrlEditable(true);
650 navigator
->setFocus();
652 // select the whole text of the combo box editor
653 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit();
654 const QString text
= lineEdit
->text();
655 lineEdit
->setSelection(0, text
.length());
658 void DolphinMainWindow::goBack()
661 m_activeViewContainer
->urlNavigator()->goBack();
664 void DolphinMainWindow::goForward()
667 m_activeViewContainer
->urlNavigator()->goForward();
670 void DolphinMainWindow::goUp()
673 m_activeViewContainer
->urlNavigator()->goUp();
676 void DolphinMainWindow::goHome()
679 m_activeViewContainer
->urlNavigator()->goHome();
682 void DolphinMainWindow::compareFiles()
684 // The method is only invoked if exactly 2 files have
685 // been selected. The selected files may be:
686 // - both in the primary view
687 // - both in the secondary view
688 // - one in the primary view and the other in the secondary
690 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
694 KUrl::List urls
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedUrls();
696 switch (urls
.count()) {
698 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
!= 0);
699 urls
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedUrls();
700 Q_ASSERT(urls
.count() == 2);
708 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
!= 0);
709 urls
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedUrls();
710 Q_ASSERT(urls
.count() == 1);
722 // may not happen: compareFiles may only get invoked if 2
723 // files are selected
728 QString
command("kompare -c \"");
729 command
.append(urlA
.pathOrUrl());
730 command
.append("\" \"");
731 command
.append(urlB
.pathOrUrl());
732 command
.append('\"');
733 KRun::runCommand(command
, "Kompare", "kompare", this);
736 void DolphinMainWindow::toggleShowMenuBar()
738 const bool visible
= menuBar()->isVisible();
739 menuBar()->setVisible(!visible
);
742 void DolphinMainWindow::editSettings()
744 if (m_settingsDialog
== 0) {
745 const KUrl
& url
= activeViewContainer()->url();
746 m_settingsDialog
= new DolphinSettingsDialog(url
, this);
747 m_settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
748 m_settingsDialog
->show();
750 m_settingsDialog
->raise();
754 void DolphinMainWindow::setActiveTab(int index
)
756 Q_ASSERT(index
>= 0);
757 Q_ASSERT(index
< m_viewTab
.count());
758 if (index
== m_tabIndex
) {
762 // hide current tab content
763 ViewTab
& hiddenTab
= m_viewTab
[m_tabIndex
];
764 hiddenTab
.isPrimaryViewActive
= hiddenTab
.primaryView
->isActive();
765 hiddenTab
.primaryView
->setActive(false);
766 if (hiddenTab
.secondaryView
!= 0) {
767 hiddenTab
.secondaryView
->setActive(false);
769 QSplitter
* splitter
= m_viewTab
[m_tabIndex
].splitter
;
771 m_centralWidgetLayout
->removeWidget(splitter
);
773 // show active tab content
776 ViewTab
& viewTab
= m_viewTab
[index
];
777 m_centralWidgetLayout
->addWidget(viewTab
.splitter
);
778 viewTab
.primaryView
->show();
779 if (viewTab
.secondaryView
!= 0) {
780 viewTab
.secondaryView
->show();
782 viewTab
.splitter
->show();
784 setActiveViewContainer(viewTab
.isPrimaryViewActive
? viewTab
.primaryView
:
785 viewTab
.secondaryView
);
788 void DolphinMainWindow::closeTab()
790 closeTab(m_tabBar
->currentIndex());
793 void DolphinMainWindow::closeTab(int index
)
795 Q_ASSERT(index
>= 0);
796 Q_ASSERT(index
< m_viewTab
.count());
797 if (m_viewTab
.count() == 1) {
798 // the last tab may never get closed
802 if (index
== m_tabIndex
) {
803 // The tab that should be closed is the active tab. Activate the
804 // previous tab before closing the tab.
805 m_tabBar
->setCurrentIndex((index
> 0) ? index
- 1 : 1);
807 rememberClosedTab(index
);
810 m_viewTab
[index
].primaryView
->deleteLater();
811 if (m_viewTab
[index
].secondaryView
!= 0) {
812 m_viewTab
[index
].secondaryView
->deleteLater();
814 m_viewTab
[index
].splitter
->deleteLater();
815 m_viewTab
.erase(m_viewTab
.begin() + index
);
817 m_tabBar
->blockSignals(true);
818 m_tabBar
->removeTab(index
);
820 if (m_tabIndex
> index
) {
822 Q_ASSERT(m_tabIndex
>= 0);
825 // if only one tab is left, also remove the tab entry so that
826 // closing the last tab is not possible
827 if (m_viewTab
.count() == 1) {
828 m_tabBar
->removeTab(0);
829 actionCollection()->action("close_tab")->setEnabled(false);
831 m_tabBar
->blockSignals(false);
835 void DolphinMainWindow::openTabContextMenu(int index
, const QPoint
& pos
)
839 QAction
* newTabAction
= menu
.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab"));
840 newTabAction
->setShortcut(actionCollection()->action("new_tab")->shortcut());
842 QAction
* closeOtherTabsAction
= menu
.addAction(KIcon("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs"));
844 QAction
* closeTabAction
= menu
.addAction(KIcon("tab-close"), i18nc("@action:inmenu", "Close Tab"));
845 closeTabAction
->setShortcut(actionCollection()->action("close_tab")->shortcut());
847 QAction
* selectedAction
= menu
.exec(pos
);
848 if (selectedAction
== newTabAction
) {
849 const ViewTab
& tab
= m_viewTab
[index
];
850 Q_ASSERT(tab
.primaryView
!= 0);
851 const KUrl url
= (tab
.secondaryView
!= 0) && tab
.secondaryView
->isActive() ?
852 tab
.secondaryView
->url() : tab
.primaryView
->url();
854 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
855 } else if (selectedAction
== closeOtherTabsAction
) {
856 const int count
= m_tabBar
->count();
857 for (int i
= 0; i
< index
; ++i
) {
860 for (int i
= index
+ 1; i
< count
; ++i
) {
863 } else if (selectedAction
== closeTabAction
) {
868 void DolphinMainWindow::handlePlacesClick(const KUrl
& url
, Qt::MouseButtons buttons
)
870 if (buttons
& Qt::MidButton
) {
872 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
878 void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent
* event
, bool& canDecode
)
880 canDecode
= KUrl::List::canDecode(event
->mimeData());
883 void DolphinMainWindow::searchItems(const KUrl
& url
)
885 m_activeViewContainer
->setUrl(url
);
888 void DolphinMainWindow::init()
890 DolphinSettings
& settings
= DolphinSettings::instance();
892 // Check whether Dolphin runs the first time. If yes then
893 // a proper default window size is given at the end of DolphinMainWindow::init().
894 GeneralSettings
* generalSettings
= settings
.generalSettings();
895 const bool firstRun
= generalSettings
->firstRun();
897 generalSettings
->setViewPropsTimestamp(QDateTime::currentDateTime());
900 setAcceptDrops(true);
902 m_viewTab
[m_tabIndex
].splitter
= new QSplitter(this);
906 const KUrl
& homeUrl
= generalSettings
->homeUrl();
907 setCaption(homeUrl
.fileName());
908 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
909 connect(m_actionHandler
, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
910 ViewProperties
props(homeUrl
);
911 m_viewTab
[m_tabIndex
].primaryView
= new DolphinViewContainer(this,
912 m_viewTab
[m_tabIndex
].splitter
,
915 m_activeViewContainer
= m_viewTab
[m_tabIndex
].primaryView
;
916 connectViewSignals(m_activeViewContainer
);
917 DolphinView
* view
= m_activeViewContainer
->view();
919 m_activeViewContainer
->show();
920 m_actionHandler
->setCurrentView(view
);
922 m_tabBar
= new KTabBar(this);
923 m_tabBar
->setMovable(true);
924 m_tabBar
->setTabsClosable(true);
925 connect(m_tabBar
, SIGNAL(currentChanged(int)),
926 this, SLOT(setActiveTab(int)));
927 connect(m_tabBar
, SIGNAL(tabCloseRequested(int)),
928 this, SLOT(closeTab(int)));
929 connect(m_tabBar
, SIGNAL(contextMenu(int, const QPoint
&)),
930 this, SLOT(openTabContextMenu(int, const QPoint
&)));
931 connect(m_tabBar
, SIGNAL(newTabRequest()),
932 this, SLOT(openNewTab()));
933 connect(m_tabBar
, SIGNAL(testCanDecode(const QDragMoveEvent
*, bool&)),
934 this, SLOT(slotTestCanDecode(const QDragMoveEvent
*, bool&)));
935 connect(m_tabBar
, SIGNAL(wheelDelta(int)),
936 this, SLOT(slotWheelMoved(int)));
937 connect(m_tabBar
, SIGNAL(mouseMiddleClick(int)),
938 this, SLOT(closeTab(int)));
940 m_tabBar
->blockSignals(true); // signals get unblocked after at least 2 tabs are open
942 QWidget
* centralWidget
= new QWidget(this);
943 m_centralWidgetLayout
= new QVBoxLayout(centralWidget
);
944 m_centralWidgetLayout
->setSpacing(0);
945 m_centralWidgetLayout
->setMargin(0);
946 m_centralWidgetLayout
->addWidget(m_tabBar
);
947 m_centralWidgetLayout
->addWidget(m_viewTab
[m_tabIndex
].splitter
);
949 setCentralWidget(centralWidget
);
951 emit
urlChanged(homeUrl
);
953 setupGUI(Keys
| Save
| Create
| ToolBar
);
955 m_searchBox
->setParent(toolBar("searchToolBar"));
958 stateChanged("new_file");
960 QClipboard
* clipboard
= QApplication::clipboard();
961 connect(clipboard
, SIGNAL(dataChanged()),
962 this, SLOT(updatePasteAction()));
966 if (generalSettings
->splitView()) {
971 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
972 showFilterBarAction
->setChecked(generalSettings
->filterBar());
975 // assure a proper default size if Dolphin runs the first time
979 m_showMenuBar
->setChecked(!menuBar()->isHidden()); // workaround for bug #171080
982 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer
* viewContainer
)
984 Q_ASSERT(viewContainer
!= 0);
985 Q_ASSERT((viewContainer
== m_viewTab
[m_tabIndex
].primaryView
) ||
986 (viewContainer
== m_viewTab
[m_tabIndex
].secondaryView
));
987 if (m_activeViewContainer
== viewContainer
) {
991 m_activeViewContainer
->setActive(false);
992 m_activeViewContainer
= viewContainer
;
994 // Activating the view container might trigger a recursive setActiveViewContainer() call
995 // inside DolphinMainWindow::toggleActiveView() when having a split view. Temporary
996 // disconnect the activated() signal in this case:
997 disconnect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
998 m_activeViewContainer
->setActive(true);
999 connect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1001 m_actionHandler
->setCurrentView(viewContainer
->view());
1004 updateEditActions();
1005 updateViewActions();
1008 const KUrl
& url
= m_activeViewContainer
->url();
1009 setCaption(url
.fileName());
1010 if (m_viewTab
.count() > 1 && m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
1011 m_tabBar
->setTabText(m_tabIndex
, tabName(url
));
1014 emit
urlChanged(url
);
1017 void DolphinMainWindow::setupActions()
1019 // setup 'File' menu
1020 m_newMenu
= new DolphinNewMenu(this, this);
1021 KMenu
* menu
= m_newMenu
->menu();
1022 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1023 menu
->setIcon(KIcon("document-new"));
1024 connect(menu
, SIGNAL(aboutToShow()),
1025 this, SLOT(updateNewMenu()));
1027 KAction
* newWindow
= actionCollection()->addAction("new_window");
1028 newWindow
->setIcon(KIcon("window-new"));
1029 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1030 newWindow
->setShortcut(Qt::CTRL
| Qt::Key_N
);
1031 connect(newWindow
, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1033 KAction
* newTab
= actionCollection()->addAction("new_tab");
1034 newTab
->setIcon(KIcon("tab-new"));
1035 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1036 newTab
->setShortcut(KShortcut(Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
));
1037 connect(newTab
, SIGNAL(triggered()), this, SLOT(openNewTab()));
1039 KAction
* closeTab
= actionCollection()->addAction("close_tab");
1040 closeTab
->setIcon(KIcon("tab-close"));
1041 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1042 closeTab
->setShortcut(Qt::CTRL
| Qt::Key_W
);
1043 closeTab
->setEnabled(false);
1044 connect(closeTab
, SIGNAL(triggered()), this, SLOT(closeTab()));
1046 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1048 // setup 'Edit' menu
1049 KStandardAction::undo(this,
1051 actionCollection());
1053 // need to remove shift+del from cut action, else the shortcut for deletejob
1055 KAction
* cut
= KStandardAction::cut(this, SLOT(cut()), actionCollection());
1056 KShortcut cutShortcut
= cut
->shortcut();
1057 cutShortcut
.remove(Qt::SHIFT
+ Qt::Key_Delete
, KShortcut::KeepEmpty
);
1058 cut
->setShortcut(cutShortcut
);
1059 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1060 KStandardAction::paste(this, SLOT(paste()), actionCollection());
1062 KAction
* selectAll
= actionCollection()->addAction("select_all");
1063 selectAll
->setText(i18nc("@action:inmenu Edit", "Select All"));
1064 selectAll
->setShortcut(Qt::CTRL
+ Qt::Key_A
);
1065 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
1067 KAction
* invertSelection
= actionCollection()->addAction("invert_selection");
1068 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1069 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1070 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
1072 // setup 'View' menu
1073 // (note that most of it is set up in DolphinViewActionHandler)
1075 KAction
* split
= actionCollection()->addAction("split_view");
1076 split
->setShortcut(Qt::Key_F3
);
1077 updateSplitAction();
1078 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1080 KAction
* reload
= actionCollection()->addAction("reload");
1081 reload
->setText(i18nc("@action:inmenu View", "Reload"));
1082 reload
->setShortcut(Qt::Key_F5
);
1083 reload
->setIcon(KIcon("view-refresh"));
1084 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
1086 KAction
* stop
= actionCollection()->addAction("stop");
1087 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1088 stop
->setIcon(KIcon("process-stop"));
1089 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
1091 KToggleAction
* showFullLocation
= actionCollection()->add
<KToggleAction
>("editable_location");
1092 showFullLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1093 showFullLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
1094 connect(showFullLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1096 KAction
* replaceLocation
= actionCollection()->addAction("replace_location");
1097 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1098 replaceLocation
->setShortcut(Qt::Key_F6
);
1099 connect(replaceLocation
, SIGNAL(triggered()), this, SLOT(replaceLocation()));
1102 KAction
* backAction
= KStandardAction::back(this, SLOT(goBack()), actionCollection());
1103 KShortcut backShortcut
= backAction
->shortcut();
1104 backShortcut
.setAlternate(Qt::Key_Backspace
);
1105 backAction
->setShortcut(backShortcut
);
1107 m_recentTabsMenu
= new KActionMenu(i18n("&Recently Closed Tabs"), this);
1108 m_recentTabsMenu
->setIcon(KIcon("edit-undo"));
1109 actionCollection()->addAction("closed_tabs", m_recentTabsMenu
);
1110 connect(m_recentTabsMenu
->menu(), SIGNAL(triggered(QAction
*)),
1111 this, SLOT(restoreClosedTab(QAction
*)));
1113 QAction
* action
= new QAction("&Empty Recently Closed Tabs", m_recentTabsMenu
);
1114 action
->setIcon(KIcon("edit-clear-list"));
1115 action
->setData(QVariant::fromValue(true));
1116 m_recentTabsMenu
->addAction(action
);
1117 m_recentTabsMenu
->addSeparator();
1118 m_recentTabsMenu
->setEnabled(false);
1120 KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1121 KStandardAction::up(this, SLOT(goUp()), actionCollection());
1122 KStandardAction::home(this, SLOT(goHome()), actionCollection());
1124 // setup 'Tools' menu
1125 KToggleAction
* showSearchBar
= actionCollection()->add
<KToggleAction
>("show_search_bar");
1126 showSearchBar
->setText(i18nc("@action:inmenu Tools", "Show Search Bar"));
1127 showSearchBar
->setShortcut(Qt::CTRL
| Qt::Key_S
);
1128 connect(showSearchBar
, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
1130 KToggleAction
* showFilterBar
= actionCollection()->add
<KToggleAction
>("show_filter_bar");
1131 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1132 showFilterBar
->setShortcut(Qt::CTRL
| Qt::Key_I
);
1133 connect(showFilterBar
, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
1135 KAction
* compareFiles
= actionCollection()->addAction("compare_files");
1136 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1137 compareFiles
->setIcon(KIcon("kompare"));
1138 compareFiles
->setEnabled(false);
1139 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
1141 // setup 'Settings' menu
1142 m_showMenuBar
= KStandardAction::showMenubar(this, SLOT(toggleShowMenuBar()), actionCollection());
1143 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1145 // not in menu actions
1146 KAction
* activateNextTab
= actionCollection()->addAction("activate_next_tab");
1147 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1148 connect(activateNextTab
, SIGNAL(triggered()), SLOT(activateNextTab()));
1149 activateNextTab
->setShortcuts(QApplication::isRightToLeft() ? KStandardShortcut::tabPrev() :
1150 KStandardShortcut::tabNext());
1152 KAction
* activatePrevTab
= actionCollection()->addAction("activate_prev_tab");
1153 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1154 connect(activatePrevTab
, SIGNAL(triggered()), SLOT(activatePrevTab()));
1155 activatePrevTab
->setShortcuts(QApplication::isRightToLeft() ? KStandardShortcut::tabNext() :
1156 KStandardShortcut::tabPrev());
1159 KAction
* openInNewTab
= actionCollection()->addAction("open_in_new_tab");
1160 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1161 openInNewTab
->setIcon(KIcon("tab-new"));
1162 connect(openInNewTab
, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1164 KAction
* openInNewWindow
= actionCollection()->addAction("open_in_new_window");
1165 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1166 openInNewWindow
->setIcon(KIcon("window-new"));
1167 connect(openInNewWindow
, SIGNAL(triggered()), this, SLOT(openInNewWindow()));
1170 m_searchBox
= new DolphinSearchBox(this);
1171 connect(m_searchBox
, SIGNAL(search(KUrl
)), this, SLOT(searchItems(KUrl
)));
1173 KAction
* search
= new KAction(this);
1174 actionCollection()->addAction("search_bar", search
);
1175 search
->setText(i18nc("@action:inmenu", "Search Bar"));
1176 search
->setDefaultWidget(m_searchBox
);
1177 search
->setShortcutConfigurable(false);
1180 void DolphinMainWindow::setupDockWidgets()
1182 // setup "Information"
1183 QDockWidget
* infoDock
= new QDockWidget(i18nc("@title:window", "Information"));
1184 infoDock
->setObjectName("infoDock");
1185 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1186 Panel
* infoPanel
= new InformationPanel(infoDock
);
1187 infoDock
->setWidget(infoPanel
);
1189 QAction
* infoAction
= infoDock
->toggleViewAction();
1190 infoAction
->setText(i18nc("@title:window", "Information"));
1191 infoAction
->setShortcut(Qt::Key_F11
);
1192 infoAction
->setIcon(KIcon("dialog-information"));
1193 actionCollection()->addAction("show_info_panel", infoDock
->toggleViewAction());
1195 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1196 connect(this, SIGNAL(urlChanged(KUrl
)),
1197 infoPanel
, SLOT(setUrl(KUrl
)));
1198 connect(this, SIGNAL(selectionChanged(KFileItemList
)),
1199 infoPanel
, SLOT(setSelection(KFileItemList
)));
1200 connect(this, SIGNAL(requestItemInfo(KFileItem
)),
1201 infoPanel
, SLOT(requestDelayedItemInfo(KFileItem
)));
1204 QDockWidget
* foldersDock
= new QDockWidget(i18nc("@title:window", "Folders"));
1205 foldersDock
->setObjectName("foldersDock");
1206 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1207 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1208 foldersDock
->setWidget(foldersPanel
);
1210 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1211 foldersAction
->setText(i18nc("@title:window", "Folders"));
1212 foldersAction
->setShortcut(Qt::Key_F7
);
1213 foldersAction
->setIcon(KIcon("folder"));
1214 actionCollection()->addAction("show_folders_panel", foldersDock
->toggleViewAction());
1216 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1217 connect(this, SIGNAL(urlChanged(KUrl
)),
1218 foldersPanel
, SLOT(setUrl(KUrl
)));
1219 connect(foldersPanel
, SIGNAL(changeUrl(KUrl
, Qt::MouseButtons
)),
1220 this, SLOT(handlePlacesClick(KUrl
, Qt::MouseButtons
)));
1221 connect(foldersPanel
, SIGNAL(changeSelection(KFileItemList
)),
1222 this, SLOT(changeSelection(KFileItemList
)));
1226 QDockWidget
* terminalDock
= new QDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1227 terminalDock
->setObjectName("terminalDock");
1228 terminalDock
->setAllowedAreas(Qt::TopDockWidgetArea
| Qt::BottomDockWidgetArea
);
1229 Panel
* terminalPanel
= new TerminalPanel(terminalDock
);
1230 terminalDock
->setWidget(terminalPanel
);
1232 connect(terminalPanel
, SIGNAL(hideTerminalPanel()), terminalDock
, SLOT(hide()));
1234 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1235 terminalAction
->setText(i18nc("@title:window Shell terminal", "Terminal"));
1236 terminalAction
->setShortcut(Qt::Key_F4
);
1237 terminalAction
->setIcon(KIcon("terminal"));
1238 actionCollection()->addAction("show_terminal_panel", terminalDock
->toggleViewAction());
1240 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1241 connect(this, SIGNAL(urlChanged(KUrl
)),
1242 terminalPanel
, SLOT(setUrl(KUrl
)));
1245 const bool firstRun
= DolphinSettings::instance().generalSettings()->firstRun();
1247 foldersDock
->hide();
1249 terminalDock
->hide();
1253 QDockWidget
* placesDock
= new QDockWidget(i18nc("@title:window", "Places"));
1254 placesDock
->setObjectName("placesDock");
1255 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1257 PlacesPanel
* placesPanel
= new PlacesPanel(placesDock
);
1258 placesDock
->setWidget(placesPanel
);
1259 placesPanel
->setModel(DolphinSettings::instance().placesModel());
1260 placesPanel
->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff
);
1262 QAction
* placesAction
= placesDock
->toggleViewAction();
1263 placesAction
->setText(i18nc("@title:window", "Places"));
1264 placesAction
->setShortcut(Qt::Key_F9
);
1265 placesAction
->setIcon(KIcon("bookmarks"));
1266 actionCollection()->addAction("show_places_panel", placesDock
->toggleViewAction());
1268 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1269 connect(placesPanel
, SIGNAL(urlChanged(KUrl
, Qt::MouseButtons
)),
1270 this, SLOT(handlePlacesClick(KUrl
, Qt::MouseButtons
)));
1271 connect(this, SIGNAL(urlChanged(KUrl
)),
1272 placesPanel
, SLOT(setUrl(KUrl
)));
1275 void DolphinMainWindow::updateEditActions()
1277 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1278 if (list
.isEmpty()) {
1279 stateChanged("has_no_selection");
1281 stateChanged("has_selection");
1283 KActionCollection
* col
= actionCollection();
1284 QAction
* renameAction
= col
->action("rename");
1285 QAction
* moveToTrashAction
= col
->action("move_to_trash");
1286 QAction
* deleteAction
= col
->action("delete");
1287 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
1288 QAction
* deleteWithTrashShortcut
= col
->action("delete_shortcut"); // see DolphinViewActionHandler
1290 KonqFileItemCapabilities
capabilities(list
);
1291 const bool enableMoveToTrash
= capabilities
.isLocal() && capabilities
.supportsMoving();
1293 renameAction
->setEnabled(capabilities
.supportsMoving());
1294 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1295 deleteAction
->setEnabled(capabilities
.supportsDeleting());
1296 deleteWithTrashShortcut
->setEnabled(capabilities
.supportsDeleting() && !enableMoveToTrash
);
1297 cutAction
->setEnabled(capabilities
.supportsMoving());
1299 updatePasteAction();
1302 void DolphinMainWindow::updateViewActions()
1304 m_actionHandler
->updateViewActions();
1306 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1307 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
1309 updateSplitAction();
1311 QAction
* editableLocactionAction
= actionCollection()->action("editable_location");
1312 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
1313 editableLocactionAction
->setChecked(urlNavigator
->isUrlEditable());
1316 void DolphinMainWindow::updateGoActions()
1318 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
1319 const KUrl
& currentUrl
= m_activeViewContainer
->url();
1320 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
1323 void DolphinMainWindow::rememberClosedTab(int index
)
1325 KMenu
* tabsMenu
= m_recentTabsMenu
->menu();
1327 const QString primaryPath
= m_viewTab
[index
].primaryView
->url().path();
1328 const QString iconName
= KMimeType::iconNameForUrl(primaryPath
);
1330 const QFontMetrics fm
= fontMetrics();
1331 const QString actionText
= fm
.elidedText(primaryPath
, Qt::ElideMiddle
, fm
.maxWidth() * 20);
1333 QAction
* action
= new QAction(actionText
, tabsMenu
);
1335 ClosedTab closedTab
;
1336 closedTab
.primaryUrl
= m_viewTab
[index
].primaryView
->url();
1338 if (m_viewTab
[index
].secondaryView
!= 0) {
1339 closedTab
.secondaryUrl
= m_viewTab
[index
].secondaryView
->url();
1340 closedTab
.isSplit
= true;
1342 closedTab
.isSplit
= false;
1345 action
->setData(QVariant::fromValue(closedTab
));
1346 action
->setIcon(KIcon(iconName
));
1348 // add the closed tab menu entry after the separator and
1349 // "Empty Recently Closed Tabs" entry
1350 if (tabsMenu
->actions().size() == 2) {
1351 tabsMenu
->addAction(action
);
1353 tabsMenu
->insertAction(tabsMenu
->actions().at(2), action
);
1355 //10 is the limit, remove the oldest one to make room. It's actually 8, since
1356 //the separator and the "Empty Recently Closed Tabs" entry count as one
1357 if (tabsMenu
->actions().size() > 8) {
1358 tabsMenu
->removeAction(tabsMenu
->actions().last());
1360 actionCollection()->action("closed_tabs")->setEnabled(true);
1361 KAcceleratorManager::manage(tabsMenu
);
1364 void DolphinMainWindow::clearStatusBar()
1366 m_activeViewContainer
->statusBar()->clear();
1369 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
1371 connect(container
, SIGNAL(showFilterBarChanged(bool)),
1372 this, SLOT(updateFilterBarAction(bool)));
1374 DolphinView
* view
= container
->view();
1375 connect(view
, SIGNAL(selectionChanged(KFileItemList
)),
1376 this, SLOT(slotSelectionChanged(KFileItemList
)));
1377 connect(view
, SIGNAL(requestItemInfo(KFileItem
)),
1378 this, SLOT(slotRequestItemInfo(KFileItem
)));
1379 connect(view
, SIGNAL(activated()),
1380 this, SLOT(toggleActiveView()));
1381 connect(view
, SIGNAL(tabRequested(const KUrl
&)),
1382 this, SLOT(openNewTab(const KUrl
&)));
1384 const KUrlNavigator
* navigator
= container
->urlNavigator();
1385 connect(navigator
, SIGNAL(urlChanged(const KUrl
&)),
1386 this, SLOT(changeUrl(const KUrl
&)));
1387 connect(navigator
, SIGNAL(historyChanged()),
1388 this, SLOT(updateHistory()));
1389 connect(navigator
, SIGNAL(editableStateChanged(bool)),
1390 this, SLOT(slotEditableStateChanged(bool)));
1393 void DolphinMainWindow::updateSplitAction()
1395 QAction
* splitAction
= actionCollection()->action("split_view");
1396 if (m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
1397 if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
1398 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
1399 splitAction
->setIcon(KIcon("view-right-close"));
1401 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
1402 splitAction
->setIcon(KIcon("view-left-close"));
1405 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
1406 splitAction
->setIcon(KIcon("view-right-new"));
1410 QString
DolphinMainWindow::tabName(const KUrl
& url
) const
1413 if (url
.equals(KUrl("file:///"))) {
1416 name
= url
.fileName();
1417 if (name
.isEmpty()) {
1418 name
= url
.protocol();
1420 // Make sure that a '&' inside the directory name is displayed correctly
1421 // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
1422 name
.replace('&', "&&");
1428 bool DolphinMainWindow::isKompareInstalled() const
1430 static bool initialized
= false;
1431 static bool installed
= false;
1433 // TODO: maybe replace this approach later by using a menu
1434 // plugin like kdiff3plugin.cpp
1435 installed
= !KGlobal::dirs()->findExe("kompare").isEmpty();
1441 void DolphinMainWindow::createSecondaryView(int tabIndex
)
1443 QSplitter
* splitter
= m_viewTab
[tabIndex
].splitter
;
1444 const int newWidth
= (m_viewTab
[tabIndex
].primaryView
->width() - splitter
->handleWidth()) / 2;
1446 const DolphinView
* view
= m_viewTab
[tabIndex
].primaryView
->view();
1447 m_viewTab
[tabIndex
].secondaryView
= new DolphinViewContainer(this, 0, view
->rootUrl());
1448 splitter
->addWidget(m_viewTab
[tabIndex
].secondaryView
);
1449 splitter
->setSizes(QList
<int>() << newWidth
<< newWidth
);
1450 connectViewSignals(m_viewTab
[tabIndex
].secondaryView
);
1451 m_viewTab
[tabIndex
].secondaryView
->view()->reload();
1452 m_viewTab
[tabIndex
].secondaryView
->setActive(false);
1453 m_viewTab
[tabIndex
].secondaryView
->show();
1456 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
1457 KIO::FileUndoManager::UiInterface()
1461 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
1465 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
1467 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
1469 DolphinStatusBar
* statusBar
= mainWin
->activeViewContainer()->statusBar();
1470 statusBar
->setMessage(job
->errorString(), DolphinStatusBar::Error
);
1472 KIO::FileUndoManager::UiInterface::jobError(job
);
1476 #include "dolphinmainwindow.moc"