]>
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>
90 * Remembers the tab configuration if a tab has been closed.
91 * Each closed tab can be restored by the menu
92 * "Go -> Recently Closed Tabs".
100 Q_DECLARE_METATYPE(ClosedTab
)
102 DolphinMainWindow::DolphinMainWindow(int id
) :
107 m_activeViewContainer(0),
108 m_centralWidgetLayout(0),
116 setObjectName("Dolphin#");
118 m_viewTab
.append(ViewTab());
120 new MainWindowAdaptor(this);
121 QDBusConnection::sessionBus().registerObject(QString("/dolphin/MainWindow%1").arg(m_id
), this);
123 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
124 undoManager
->setUiInterface(new UndoUiInterface());
126 connect(undoManager
, SIGNAL(undoAvailable(bool)),
127 this, SLOT(slotUndoAvailable(bool)));
128 connect(undoManager
, SIGNAL(undoTextChanged(const QString
&)),
129 this, SLOT(slotUndoTextChanged(const QString
&)));
130 connect(undoManager
, SIGNAL(jobRecordingStarted(CommandType
)),
131 this, SLOT(clearStatusBar()));
132 connect(undoManager
, SIGNAL(jobRecordingFinished(CommandType
)),
133 this, SLOT(showCommand(CommandType
)));
134 connect(DolphinSettings::instance().placesModel(), SIGNAL(errorMessage(const QString
&)),
135 this, SLOT(showErrorMessage(const QString
&)));
136 connect(&DragAndDropHelper::instance(), SIGNAL(errorMessage(const QString
&)),
137 this, SLOT(showErrorMessage(const QString
&)));
140 DolphinMainWindow::~DolphinMainWindow()
142 DolphinApplication::app()->removeMainWindow(this);
145 void DolphinMainWindow::toggleViews()
147 if (m_viewTab
[m_tabIndex
].primaryView
== 0) {
151 // move secondary view from the last position of the splitter
152 // to the first position
153 m_viewTab
[m_tabIndex
].splitter
->insertWidget(0, m_viewTab
[m_tabIndex
].secondaryView
);
155 DolphinViewContainer
* container
= m_viewTab
[m_tabIndex
].primaryView
;
156 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
157 m_viewTab
[m_tabIndex
].secondaryView
= container
;
160 void DolphinMainWindow::showCommand(CommandType command
)
162 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
164 case KIO::FileUndoManager::Copy
:
165 statusBar
->setMessage(i18nc("@info:status", "Copy operation completed."),
166 DolphinStatusBar::OperationCompleted
);
168 case KIO::FileUndoManager::Move
:
169 statusBar
->setMessage(i18nc("@info:status", "Move operation completed."),
170 DolphinStatusBar::OperationCompleted
);
172 case KIO::FileUndoManager::Link
:
173 statusBar
->setMessage(i18nc("@info:status", "Link operation completed."),
174 DolphinStatusBar::OperationCompleted
);
176 case KIO::FileUndoManager::Trash
:
177 statusBar
->setMessage(i18nc("@info:status", "Move to trash operation completed."),
178 DolphinStatusBar::OperationCompleted
);
180 case KIO::FileUndoManager::Rename
:
181 statusBar
->setMessage(i18nc("@info:status", "Renaming operation completed."),
182 DolphinStatusBar::OperationCompleted
);
185 case KIO::FileUndoManager::Mkdir
:
186 statusBar
->setMessage(i18nc("@info:status", "Created folder."),
187 DolphinStatusBar::OperationCompleted
);
195 void DolphinMainWindow::refreshViews()
197 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
199 // remember the current active view, as because of
200 // the refreshing the active view might change to
201 // the secondary view
202 DolphinViewContainer
* activeViewContainer
= m_activeViewContainer
;
204 const int tabCount
= m_viewTab
.count();
205 for (int i
= 0; i
< tabCount
; ++i
) {
206 m_viewTab
[i
].primaryView
->refresh();
207 if (m_viewTab
[i
].secondaryView
!= 0) {
208 m_viewTab
[i
].secondaryView
->refresh();
212 setActiveViewContainer(activeViewContainer
);
215 void DolphinMainWindow::pasteIntoFolder()
217 m_activeViewContainer
->view()->pasteIntoFolder();
220 void DolphinMainWindow::changeUrl(const KUrl
& url
)
222 if (!KProtocolManager::supportsListing(url
)) {
223 // The URL navigator only checks for validity, not
224 // if the URL can be listed. An error message is
225 // shown due to DolphinViewContainer::restoreView().
229 DolphinViewContainer
* view
= activeViewContainer();
235 setCaption(url
.fileName());
236 if (m_viewTab
.count() > 1) {
237 m_tabBar
->setTabText(m_tabIndex
, tabName(url
));
239 emit
urlChanged(url
);
243 void DolphinMainWindow::changeSelection(const KFileItemList
& selection
)
245 activeViewContainer()->view()->changeSelection(selection
);
248 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
250 KToggleAction
* editableLocationAction
=
251 static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
252 editableLocationAction
->setChecked(editable
);
255 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
259 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
260 int selectedUrlsCount
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedItemsCount();
261 if (m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
262 selectedUrlsCount
+= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItemsCount();
265 QAction
* compareFilesAction
= actionCollection()->action("compare_files");
266 if (selectedUrlsCount
== 2) {
267 compareFilesAction
->setEnabled(isKompareInstalled());
269 compareFilesAction
->setEnabled(false);
272 m_activeViewContainer
->updateStatusBar();
274 emit
selectionChanged(selection
);
277 void DolphinMainWindow::slotWheelMoved(int wheelDelta
)
279 if (wheelDelta
> 0) {
286 void DolphinMainWindow::slotRequestItemInfo(const KFileItem
& item
)
288 emit
requestItemInfo(item
);
291 void DolphinMainWindow::updateHistory()
293 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
294 const int index
= urlNavigator
->historyIndex();
296 QAction
* backAction
= actionCollection()->action("go_back");
297 if (backAction
!= 0) {
298 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
301 QAction
* forwardAction
= actionCollection()->action("go_forward");
302 if (forwardAction
!= 0) {
303 forwardAction
->setEnabled(index
> 0);
307 void DolphinMainWindow::updateFilterBarAction(bool show
)
309 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
310 showFilterBarAction
->setChecked(show
);
313 void DolphinMainWindow::openNewMainWindow()
315 DolphinApplication::app()->createMainWindow()->show();
318 void DolphinMainWindow::openNewTab()
320 openNewTab(m_activeViewContainer
->url());
321 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
323 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
324 if (navigator
->isUrlEditable()) {
325 // if a new tab is opened and the URL is editable, assure that
326 // the user can edit the URL without manually setting the focus
327 navigator
->setFocus();
331 void DolphinMainWindow::openNewTab(const KUrl
& url
)
333 if (m_viewTab
.count() == 1) {
334 // Only one view is open currently and hence no tab is shown at
335 // all. Before creating a tab for 'url', provide a tab for the current URL.
336 m_tabBar
->addTab(KIcon("folder"), tabName(m_activeViewContainer
->url()));
337 m_tabBar
->blockSignals(false);
340 m_tabBar
->addTab(KIcon("folder"), tabName(url
));
343 viewTab
.splitter
= new QSplitter(this);
344 viewTab
.primaryView
= new DolphinViewContainer(this, viewTab
.splitter
, url
);
345 viewTab
.primaryView
->setActive(false);
346 connectViewSignals(viewTab
.primaryView
);
347 viewTab
.primaryView
->view()->reload();
349 m_viewTab
.append(viewTab
);
351 actionCollection()->action("close_tab")->setEnabled(true);
353 // provide a split view, if the startup settings are set this way
354 const GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
355 if (generalSettings
->splitView()) {
356 const int tabIndex
= m_viewTab
.count() - 1;
357 createSecondaryView(tabIndex
);
358 m_viewTab
[tabIndex
].secondaryView
->setActive(true);
359 m_viewTab
[tabIndex
].isPrimaryViewActive
= false;
363 void DolphinMainWindow::activateNextTab()
365 if ((m_viewTab
.count() == 1) || (m_tabBar
->count() < 2)) {
369 const int tabIndex
= (m_tabBar
->currentIndex() + 1) % m_tabBar
->count();
370 m_tabBar
->setCurrentIndex(tabIndex
);
373 void DolphinMainWindow::activatePrevTab()
375 if ((m_viewTab
.count() == 1) || (m_tabBar
->count() < 2)) {
379 int tabIndex
= m_tabBar
->currentIndex() - 1;
380 if (tabIndex
== -1) {
381 tabIndex
= m_tabBar
->count() - 1;
383 m_tabBar
->setCurrentIndex(tabIndex
);
386 void DolphinMainWindow::openInNewTab()
388 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
389 if ((list
.count() == 1) && list
[0].isDir()) {
390 openNewTab(m_activeViewContainer
->view()->selectedUrls()[0]);
394 void DolphinMainWindow::openInNewWindow()
396 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
397 if ((list
.count() == 1) && list
[0].isDir()) {
398 DolphinMainWindow
* window
= DolphinApplication::app()->createMainWindow();
399 window
->changeUrl(m_activeViewContainer
->view()->selectedUrls()[0]);
404 void DolphinMainWindow::toggleActiveView()
406 if (m_viewTab
[m_tabIndex
].secondaryView
== 0) {
407 // only one view is available
411 Q_ASSERT(m_activeViewContainer
!= 0);
412 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
414 DolphinViewContainer
* left
= m_viewTab
[m_tabIndex
].primaryView
;
415 DolphinViewContainer
* right
= m_viewTab
[m_tabIndex
].secondaryView
;
416 setActiveViewContainer(m_activeViewContainer
== right
? left
: right
);
419 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
421 DolphinSettings
& settings
= DolphinSettings::instance();
422 GeneralSettings
* generalSettings
= settings
.generalSettings();
423 generalSettings
->setFirstRun(false);
427 KXmlGuiWindow::closeEvent(event
);
430 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
432 // TODO: remember tabs
433 DolphinViewContainer
* cont
= m_viewTab
[m_tabIndex
].primaryView
;
434 group
.writeEntry("Primary Url", cont
->url().url());
435 group
.writeEntry("Primary Editable Url", cont
->isUrlEditable());
437 cont
= m_viewTab
[m_tabIndex
].secondaryView
;
439 group
.writeEntry("Secondary Url", cont
->url().url());
440 group
.writeEntry("Secondary Editable Url", cont
->isUrlEditable());
444 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
447 DolphinViewContainer
* cont
= m_viewTab
[m_tabIndex
].primaryView
;
449 cont
->setUrl(group
.readEntry("Primary Url"));
450 bool editable
= group
.readEntry("Primary Editable Url", false);
451 cont
->urlNavigator()->setUrlEditable(editable
);
453 cont
= m_viewTab
[m_tabIndex
].secondaryView
;
454 const QString secondaryUrl
= group
.readEntry("Secondary Url");
455 if (!secondaryUrl
.isEmpty()) {
457 // a secondary view should be shown, but no one is available
458 // currently -> create a new view
460 cont
= m_viewTab
[m_tabIndex
].secondaryView
;
464 cont
->setUrl(secondaryUrl
);
465 bool editable
= group
.readEntry("Secondary Editable Url", false);
466 cont
->urlNavigator()->setUrlEditable(editable
);
467 } else if (cont
!= 0) {
468 // no secondary view should be shown, but the default setting shows
469 // one already -> close the view
474 void DolphinMainWindow::updateNewMenu()
476 m_newMenu
->slotCheckUpToDate();
477 m_newMenu
->setPopupFiles(activeViewContainer()->url());
480 void DolphinMainWindow::quit()
485 void DolphinMainWindow::showErrorMessage(const QString
& message
)
487 if (!message
.isEmpty()) {
488 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
489 statusBar
->setMessage(message
, DolphinStatusBar::Error
);
493 void DolphinMainWindow::slotUndoAvailable(bool available
)
495 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
496 if (undoAction
!= 0) {
497 undoAction
->setEnabled(available
);
501 void DolphinMainWindow::restoreClosedTab(QAction
* action
)
503 if (action
->data().toBool()) {
504 // clear all actions except the "Empty Recently Closed Tabs"
505 // action and the separator
506 QList
<QAction
*> actions
= m_recentTabsMenu
->menu()->actions();
507 const int count
= actions
.size();
508 for (int i
= 2; i
< count
; i
++) {
509 m_recentTabsMenu
->menu()->removeAction(actions
.at(i
));
512 const ClosedTab closedTab
= action
->data().value
<ClosedTab
>();
513 openNewTab(closedTab
.primaryUrl
);
514 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
516 if (closedTab
.isSplit
) {
517 // create secondary view
519 m_viewTab
[m_tabIndex
].secondaryView
->setUrl(closedTab
.secondaryUrl
);
522 m_recentTabsMenu
->removeAction(action
);
525 if (m_recentTabsMenu
->menu()->actions().count() == 2) {
526 m_recentTabsMenu
->setEnabled(false);
530 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
532 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
533 if (undoAction
!= 0) {
534 undoAction
->setText(text
);
538 void DolphinMainWindow::undo()
541 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
542 KIO::FileUndoManager::self()->undo();
545 void DolphinMainWindow::cut()
547 m_activeViewContainer
->view()->cutSelectedItems();
550 void DolphinMainWindow::copy()
552 m_activeViewContainer
->view()->copySelectedItems();
555 void DolphinMainWindow::paste()
557 m_activeViewContainer
->view()->paste();
560 void DolphinMainWindow::updatePasteAction()
562 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
563 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
564 pasteAction
->setEnabled(pasteInfo
.first
);
565 pasteAction
->setText(pasteInfo
.second
);
568 void DolphinMainWindow::selectAll()
572 // if the URL navigator is editable and focused, select the whole
573 // URL instead of all items of the view
575 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
576 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit();
577 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
578 lineEdit
->hasFocus();
580 lineEdit
->selectAll();
582 m_activeViewContainer
->view()->selectAll();
586 void DolphinMainWindow::invertSelection()
589 m_activeViewContainer
->view()->invertSelection();
592 void DolphinMainWindow::toggleSplitView()
594 if (m_viewTab
[m_tabIndex
].secondaryView
== 0) {
595 createSecondaryView(m_tabIndex
);
596 setActiveViewContainer(m_viewTab
[m_tabIndex
].secondaryView
);
597 } else if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
598 // remove secondary view
599 m_viewTab
[m_tabIndex
].secondaryView
->close();
600 m_viewTab
[m_tabIndex
].secondaryView
->deleteLater();
601 m_viewTab
[m_tabIndex
].secondaryView
= 0;
603 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
605 // The primary view is active and should be closed. Hence from a users point of view
606 // the content of the secondary view should be moved to the primary view.
607 // From an implementation point of view it is more efficient to close
608 // the primary view and exchange the internal pointers afterwards.
610 m_viewTab
[m_tabIndex
].primaryView
->close();
611 m_viewTab
[m_tabIndex
].primaryView
->deleteLater();
612 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
613 m_viewTab
[m_tabIndex
].secondaryView
= 0;
615 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
621 void DolphinMainWindow::reloadView()
624 m_activeViewContainer
->view()->reload();
627 void DolphinMainWindow::stopLoading()
631 void DolphinMainWindow::toggleFilterBarVisibility(bool show
)
633 m_activeViewContainer
->showFilterBar(show
);
636 void DolphinMainWindow::toggleEditLocation()
640 QAction
* action
= actionCollection()->action("editable_location");
641 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
642 urlNavigator
->setUrlEditable(action
->isChecked());
645 void DolphinMainWindow::replaceLocation()
647 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
648 navigator
->setUrlEditable(true);
649 navigator
->setFocus();
651 // select the whole text of the combo box editor
652 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit();
653 const QString text
= lineEdit
->text();
654 lineEdit
->setSelection(0, text
.length());
657 void DolphinMainWindow::goBack()
660 m_activeViewContainer
->urlNavigator()->goBack();
663 void DolphinMainWindow::goForward()
666 m_activeViewContainer
->urlNavigator()->goForward();
669 void DolphinMainWindow::goUp()
672 m_activeViewContainer
->urlNavigator()->goUp();
675 void DolphinMainWindow::goHome()
678 m_activeViewContainer
->urlNavigator()->goHome();
681 void DolphinMainWindow::compareFiles()
683 // The method is only invoked if exactly 2 files have
684 // been selected. The selected files may be:
685 // - both in the primary view
686 // - both in the secondary view
687 // - one in the primary view and the other in the secondary
689 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
693 KUrl::List urls
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedUrls();
695 switch (urls
.count()) {
697 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
!= 0);
698 urls
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedUrls();
699 Q_ASSERT(urls
.count() == 2);
707 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
!= 0);
708 urls
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedUrls();
709 Q_ASSERT(urls
.count() == 1);
721 // may not happen: compareFiles may only get invoked if 2
722 // files are selected
727 QString
command("kompare -c \"");
728 command
.append(urlA
.pathOrUrl());
729 command
.append("\" \"");
730 command
.append(urlB
.pathOrUrl());
731 command
.append('\"');
732 KRun::runCommand(command
, "Kompare", "kompare", this);
735 void DolphinMainWindow::toggleShowMenuBar()
737 const bool visible
= menuBar()->isVisible();
738 menuBar()->setVisible(!visible
);
741 void DolphinMainWindow::editSettings()
743 if (m_settingsDialog
== 0) {
744 const KUrl
& url
= activeViewContainer()->url();
745 m_settingsDialog
= new DolphinSettingsDialog(url
, this);
746 m_settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
747 m_settingsDialog
->show();
749 m_settingsDialog
->raise();
753 void DolphinMainWindow::setActiveTab(int index
)
755 Q_ASSERT(index
>= 0);
756 Q_ASSERT(index
< m_viewTab
.count());
757 if (index
== m_tabIndex
) {
761 // hide current tab content
762 ViewTab
& hiddenTab
= m_viewTab
[m_tabIndex
];
763 hiddenTab
.isPrimaryViewActive
= hiddenTab
.primaryView
->isActive();
764 hiddenTab
.primaryView
->setActive(false);
765 if (hiddenTab
.secondaryView
!= 0) {
766 hiddenTab
.secondaryView
->setActive(false);
768 QSplitter
* splitter
= m_viewTab
[m_tabIndex
].splitter
;
770 m_centralWidgetLayout
->removeWidget(splitter
);
772 // show active tab content
775 ViewTab
& viewTab
= m_viewTab
[index
];
776 m_centralWidgetLayout
->addWidget(viewTab
.splitter
);
777 viewTab
.primaryView
->show();
778 if (viewTab
.secondaryView
!= 0) {
779 viewTab
.secondaryView
->show();
781 viewTab
.splitter
->show();
783 setActiveViewContainer(viewTab
.isPrimaryViewActive
? viewTab
.primaryView
:
784 viewTab
.secondaryView
);
787 void DolphinMainWindow::closeTab()
789 closeTab(m_tabBar
->currentIndex());
792 void DolphinMainWindow::closeTab(int index
)
794 Q_ASSERT(index
>= 0);
795 Q_ASSERT(index
< m_viewTab
.count());
796 if (m_viewTab
.count() == 1) {
797 // the last tab may never get closed
801 if (index
== m_tabIndex
) {
802 // The tab that should be closed is the active tab. Activate the
803 // previous tab before closing the tab.
804 m_tabBar
->setCurrentIndex((index
> 0) ? index
- 1 : 1);
806 rememberClosedTab(index
);
809 m_viewTab
[index
].primaryView
->deleteLater();
810 if (m_viewTab
[index
].secondaryView
!= 0) {
811 m_viewTab
[index
].secondaryView
->deleteLater();
813 m_viewTab
[index
].splitter
->deleteLater();
814 m_viewTab
.erase(m_viewTab
.begin() + index
);
816 m_tabBar
->blockSignals(true);
817 m_tabBar
->removeTab(index
);
819 if (m_tabIndex
> index
) {
821 Q_ASSERT(m_tabIndex
>= 0);
824 // if only one tab is left, also remove the tab entry so that
825 // closing the last tab is not possible
826 if (m_viewTab
.count() == 1) {
827 m_tabBar
->removeTab(0);
828 actionCollection()->action("close_tab")->setEnabled(false);
830 m_tabBar
->blockSignals(false);
834 void DolphinMainWindow::openTabContextMenu(int index
, const QPoint
& pos
)
838 QAction
* newTabAction
= menu
.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab"));
839 newTabAction
->setShortcut(actionCollection()->action("new_tab")->shortcut());
841 QAction
* closeOtherTabsAction
= menu
.addAction(KIcon("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs"));
843 QAction
* closeTabAction
= menu
.addAction(KIcon("tab-close"), i18nc("@action:inmenu", "Close Tab"));
844 closeTabAction
->setShortcut(actionCollection()->action("close_tab")->shortcut());
846 QAction
* selectedAction
= menu
.exec(pos
);
847 if (selectedAction
== newTabAction
) {
848 const ViewTab
& tab
= m_viewTab
[index
];
849 Q_ASSERT(tab
.primaryView
!= 0);
850 const KUrl url
= (tab
.secondaryView
!= 0) && tab
.secondaryView
->isActive() ?
851 tab
.secondaryView
->url() : tab
.primaryView
->url();
853 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
854 } else if (selectedAction
== closeOtherTabsAction
) {
855 const int count
= m_tabBar
->count();
856 for (int i
= 0; i
< index
; ++i
) {
859 for (int i
= index
+ 1; i
< count
; ++i
) {
862 } else if (selectedAction
== closeTabAction
) {
867 void DolphinMainWindow::handlePlacesClick(const KUrl
& url
, Qt::MouseButtons buttons
)
869 if (buttons
& Qt::MidButton
) {
871 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
877 void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent
* event
, bool& canDecode
)
879 canDecode
= KUrl::List::canDecode(event
->mimeData());
882 void DolphinMainWindow::searchItems(const KUrl
& url
)
884 m_activeViewContainer
->setUrl(url
);
887 void DolphinMainWindow::init()
889 DolphinSettings
& settings
= DolphinSettings::instance();
891 // Check whether Dolphin runs the first time. If yes then
892 // a proper default window size is given at the end of DolphinMainWindow::init().
893 GeneralSettings
* generalSettings
= settings
.generalSettings();
894 const bool firstRun
= generalSettings
->firstRun();
896 generalSettings
->setViewPropsTimestamp(QDateTime::currentDateTime());
899 setAcceptDrops(true);
901 m_viewTab
[m_tabIndex
].splitter
= new QSplitter(this);
905 const KUrl
& homeUrl
= generalSettings
->homeUrl();
906 setCaption(homeUrl
.fileName());
907 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
908 connect(m_actionHandler
, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
909 ViewProperties
props(homeUrl
);
910 m_viewTab
[m_tabIndex
].primaryView
= new DolphinViewContainer(this,
911 m_viewTab
[m_tabIndex
].splitter
,
914 m_activeViewContainer
= m_viewTab
[m_tabIndex
].primaryView
;
915 connectViewSignals(m_activeViewContainer
);
916 DolphinView
* view
= m_activeViewContainer
->view();
918 m_activeViewContainer
->show();
919 m_actionHandler
->setCurrentView(view
);
921 m_tabBar
= new KTabBar(this);
922 m_tabBar
->setMovable(true);
923 m_tabBar
->setTabsClosable(true);
924 connect(m_tabBar
, SIGNAL(currentChanged(int)),
925 this, SLOT(setActiveTab(int)));
926 connect(m_tabBar
, SIGNAL(tabCloseRequested(int)),
927 this, SLOT(closeTab(int)));
928 connect(m_tabBar
, SIGNAL(contextMenu(int, const QPoint
&)),
929 this, SLOT(openTabContextMenu(int, const QPoint
&)));
930 connect(m_tabBar
, SIGNAL(newTabRequest()),
931 this, SLOT(openNewTab()));
932 connect(m_tabBar
, SIGNAL(testCanDecode(const QDragMoveEvent
*, bool&)),
933 this, SLOT(slotTestCanDecode(const QDragMoveEvent
*, bool&)));
934 connect(m_tabBar
, SIGNAL(wheelDelta(int)),
935 this, SLOT(slotWheelMoved(int)));
936 connect(m_tabBar
, SIGNAL(mouseMiddleClick(int)),
937 this, SLOT(closeTab(int)));
939 m_tabBar
->blockSignals(true); // signals get unblocked after at least 2 tabs are open
941 QWidget
* centralWidget
= new QWidget(this);
942 m_centralWidgetLayout
= new QVBoxLayout(centralWidget
);
943 m_centralWidgetLayout
->setSpacing(0);
944 m_centralWidgetLayout
->setMargin(0);
945 m_centralWidgetLayout
->addWidget(m_tabBar
);
946 m_centralWidgetLayout
->addWidget(m_viewTab
[m_tabIndex
].splitter
);
948 setCentralWidget(centralWidget
);
950 emit
urlChanged(homeUrl
);
952 setupGUI(Keys
| Save
| Create
| ToolBar
);
954 m_searchBox
->setParent(toolBar("searchToolBar"));
957 stateChanged("new_file");
959 QClipboard
* clipboard
= QApplication::clipboard();
960 connect(clipboard
, SIGNAL(dataChanged()),
961 this, SLOT(updatePasteAction()));
965 if (generalSettings
->splitView()) {
970 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
971 showFilterBarAction
->setChecked(generalSettings
->filterBar());
974 // assure a proper default size if Dolphin runs the first time
978 m_showMenuBar
->setChecked(!menuBar()->isHidden()); // workaround for bug #171080
981 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer
* viewContainer
)
983 Q_ASSERT(viewContainer
!= 0);
984 Q_ASSERT((viewContainer
== m_viewTab
[m_tabIndex
].primaryView
) ||
985 (viewContainer
== m_viewTab
[m_tabIndex
].secondaryView
));
986 if (m_activeViewContainer
== viewContainer
) {
990 m_activeViewContainer
->setActive(false);
991 m_activeViewContainer
= viewContainer
;
993 // Activating the view container might trigger a recursive setActiveViewContainer() call
994 // inside DolphinMainWindow::toggleActiveView() when having a split view. Temporary
995 // disconnect the activated() signal in this case:
996 disconnect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
997 m_activeViewContainer
->setActive(true);
998 connect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1000 m_actionHandler
->setCurrentView(viewContainer
->view());
1003 updateEditActions();
1004 updateViewActions();
1007 const KUrl
& url
= m_activeViewContainer
->url();
1008 setCaption(url
.fileName());
1009 if (m_viewTab
.count() > 1) {
1010 m_tabBar
->setTabText(m_tabIndex
, tabName(url
));
1013 emit
urlChanged(url
);
1016 void DolphinMainWindow::setupActions()
1018 // setup 'File' menu
1019 m_newMenu
= new DolphinNewMenu(this, this);
1020 KMenu
* menu
= m_newMenu
->menu();
1021 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1022 menu
->setIcon(KIcon("document-new"));
1023 connect(menu
, SIGNAL(aboutToShow()),
1024 this, SLOT(updateNewMenu()));
1026 KAction
* newWindow
= actionCollection()->addAction("new_window");
1027 newWindow
->setIcon(KIcon("window-new"));
1028 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1029 newWindow
->setShortcut(Qt::CTRL
| Qt::Key_N
);
1030 connect(newWindow
, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1032 KAction
* newTab
= actionCollection()->addAction("new_tab");
1033 newTab
->setIcon(KIcon("tab-new"));
1034 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1035 newTab
->setShortcut(KShortcut(Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
));
1036 connect(newTab
, SIGNAL(triggered()), this, SLOT(openNewTab()));
1038 KAction
* closeTab
= actionCollection()->addAction("close_tab");
1039 closeTab
->setIcon(KIcon("tab-close"));
1040 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1041 closeTab
->setShortcut(Qt::CTRL
| Qt::Key_W
);
1042 closeTab
->setEnabled(false);
1043 connect(closeTab
, SIGNAL(triggered()), this, SLOT(closeTab()));
1045 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1047 // setup 'Edit' menu
1048 KStandardAction::undo(this,
1050 actionCollection());
1052 // need to remove shift+del from cut action, else the shortcut for deletejob
1054 KAction
* cut
= KStandardAction::cut(this, SLOT(cut()), actionCollection());
1055 KShortcut cutShortcut
= cut
->shortcut();
1056 cutShortcut
.remove(Qt::SHIFT
+ Qt::Key_Delete
, KShortcut::KeepEmpty
);
1057 cut
->setShortcut(cutShortcut
);
1058 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1059 KStandardAction::paste(this, SLOT(paste()), actionCollection());
1061 KAction
* selectAll
= actionCollection()->addAction("select_all");
1062 selectAll
->setText(i18nc("@action:inmenu Edit", "Select All"));
1063 selectAll
->setShortcut(Qt::CTRL
+ Qt::Key_A
);
1064 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
1066 KAction
* invertSelection
= actionCollection()->addAction("invert_selection");
1067 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1068 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1069 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
1071 // setup 'View' menu
1072 // (note that most of it is set up in DolphinViewActionHandler)
1074 KAction
* split
= actionCollection()->addAction("split_view");
1075 split
->setShortcut(Qt::Key_F3
);
1076 updateSplitAction();
1077 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1079 KAction
* reload
= actionCollection()->addAction("reload");
1080 reload
->setText(i18nc("@action:inmenu View", "Reload"));
1081 reload
->setShortcut(Qt::Key_F5
);
1082 reload
->setIcon(KIcon("view-refresh"));
1083 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
1085 KAction
* stop
= actionCollection()->addAction("stop");
1086 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1087 stop
->setIcon(KIcon("process-stop"));
1088 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
1090 KToggleAction
* showFullLocation
= actionCollection()->add
<KToggleAction
>("editable_location");
1091 showFullLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1092 showFullLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
1093 connect(showFullLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1095 KAction
* replaceLocation
= actionCollection()->addAction("replace_location");
1096 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1097 replaceLocation
->setShortcut(Qt::Key_F6
);
1098 connect(replaceLocation
, SIGNAL(triggered()), this, SLOT(replaceLocation()));
1101 KAction
* backAction
= KStandardAction::back(this, SLOT(goBack()), actionCollection());
1102 KShortcut backShortcut
= backAction
->shortcut();
1103 backShortcut
.setAlternate(Qt::Key_Backspace
);
1104 backAction
->setShortcut(backShortcut
);
1106 m_recentTabsMenu
= new KActionMenu(i18n("&Recently Closed Tabs"), this);
1107 m_recentTabsMenu
->setIcon(KIcon("edit-undo"));
1108 actionCollection()->addAction("closed_tabs", m_recentTabsMenu
);
1109 connect(m_recentTabsMenu
->menu(), SIGNAL(triggered(QAction
*)),
1110 this, SLOT(restoreClosedTab(QAction
*)));
1112 QAction
* action
= new QAction("&Empty Recently Closed Tabs", m_recentTabsMenu
);
1113 action
->setIcon(KIcon("edit-clear-list"));
1114 action
->setData(QVariant::fromValue(true));
1115 m_recentTabsMenu
->addAction(action
);
1116 m_recentTabsMenu
->addSeparator();
1117 m_recentTabsMenu
->setEnabled(false);
1119 KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1120 KStandardAction::up(this, SLOT(goUp()), actionCollection());
1121 KStandardAction::home(this, SLOT(goHome()), actionCollection());
1123 // setup 'Tools' menu
1124 KToggleAction
* showSearchBar
= actionCollection()->add
<KToggleAction
>("show_search_bar");
1125 showSearchBar
->setText(i18nc("@action:inmenu Tools", "Show Search Bar"));
1126 showSearchBar
->setShortcut(Qt::CTRL
| Qt::Key_S
);
1127 connect(showSearchBar
, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
1129 KToggleAction
* showFilterBar
= actionCollection()->add
<KToggleAction
>("show_filter_bar");
1130 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1131 showFilterBar
->setShortcut(Qt::CTRL
| Qt::Key_I
);
1132 connect(showFilterBar
, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
1134 KAction
* compareFiles
= actionCollection()->addAction("compare_files");
1135 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1136 compareFiles
->setIcon(KIcon("kompare"));
1137 compareFiles
->setEnabled(false);
1138 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
1140 // setup 'Settings' menu
1141 m_showMenuBar
= KStandardAction::showMenubar(this, SLOT(toggleShowMenuBar()), actionCollection());
1142 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1144 // not in menu actions
1145 KAction
* activateNextTab
= actionCollection()->addAction("activate_next_tab");
1146 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1147 connect(activateNextTab
, SIGNAL(triggered()), SLOT(activateNextTab()));
1148 activateNextTab
->setShortcuts(QApplication::isRightToLeft() ? KStandardShortcut::tabPrev() :
1149 KStandardShortcut::tabNext());
1151 KAction
* activatePrevTab
= actionCollection()->addAction("activate_prev_tab");
1152 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1153 connect(activatePrevTab
, SIGNAL(triggered()), SLOT(activatePrevTab()));
1154 activatePrevTab
->setShortcuts(QApplication::isRightToLeft() ? KStandardShortcut::tabNext() :
1155 KStandardShortcut::tabPrev());
1158 KAction
* openInNewTab
= actionCollection()->addAction("open_in_new_tab");
1159 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1160 openInNewTab
->setIcon(KIcon("tab-new"));
1161 connect(openInNewTab
, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1163 KAction
* openInNewWindow
= actionCollection()->addAction("open_in_new_window");
1164 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1165 openInNewWindow
->setIcon(KIcon("window-new"));
1166 connect(openInNewWindow
, SIGNAL(triggered()), this, SLOT(openInNewWindow()));
1169 m_searchBox
= new DolphinSearchBox(this);
1170 connect(m_searchBox
, SIGNAL(search(KUrl
)), this, SLOT(searchItems(KUrl
)));
1172 KAction
* search
= new KAction(this);
1173 actionCollection()->addAction("search_bar", search
);
1174 search
->setText(i18nc("@action:inmenu", "Search Bar"));
1175 search
->setDefaultWidget(m_searchBox
);
1176 search
->setShortcutConfigurable(false);
1179 void DolphinMainWindow::setupDockWidgets()
1181 // setup "Information"
1182 QDockWidget
* infoDock
= new QDockWidget(i18nc("@title:window", "Information"));
1183 infoDock
->setObjectName("infoDock");
1184 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1185 Panel
* infoPanel
= new InformationPanel(infoDock
);
1186 infoDock
->setWidget(infoPanel
);
1188 QAction
* infoAction
= infoDock
->toggleViewAction();
1189 infoAction
->setText(i18nc("@title:window", "Information"));
1190 infoAction
->setShortcut(Qt::Key_F11
);
1191 infoAction
->setIcon(KIcon("dialog-information"));
1192 actionCollection()->addAction("show_info_panel", infoDock
->toggleViewAction());
1194 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1195 connect(this, SIGNAL(urlChanged(KUrl
)),
1196 infoPanel
, SLOT(setUrl(KUrl
)));
1197 connect(this, SIGNAL(selectionChanged(KFileItemList
)),
1198 infoPanel
, SLOT(setSelection(KFileItemList
)));
1199 connect(this, SIGNAL(requestItemInfo(KFileItem
)),
1200 infoPanel
, SLOT(requestDelayedItemInfo(KFileItem
)));
1203 QDockWidget
* foldersDock
= new QDockWidget(i18nc("@title:window", "Folders"));
1204 foldersDock
->setObjectName("foldersDock");
1205 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1206 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1207 foldersDock
->setWidget(foldersPanel
);
1209 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1210 foldersAction
->setText(i18nc("@title:window", "Folders"));
1211 foldersAction
->setShortcut(Qt::Key_F7
);
1212 foldersAction
->setIcon(KIcon("folder"));
1213 actionCollection()->addAction("show_folders_panel", foldersDock
->toggleViewAction());
1215 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1216 connect(this, SIGNAL(urlChanged(KUrl
)),
1217 foldersPanel
, SLOT(setUrl(KUrl
)));
1218 connect(foldersPanel
, SIGNAL(changeUrl(KUrl
, Qt::MouseButtons
)),
1219 this, SLOT(handlePlacesClick(KUrl
, Qt::MouseButtons
)));
1220 connect(foldersPanel
, SIGNAL(changeSelection(KFileItemList
)),
1221 this, SLOT(changeSelection(KFileItemList
)));
1225 QDockWidget
* terminalDock
= new QDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1226 terminalDock
->setObjectName("terminalDock");
1227 terminalDock
->setAllowedAreas(Qt::TopDockWidgetArea
| Qt::BottomDockWidgetArea
);
1228 Panel
* terminalPanel
= new TerminalPanel(terminalDock
);
1229 terminalDock
->setWidget(terminalPanel
);
1231 connect(terminalPanel
, SIGNAL(hideTerminalPanel()), terminalDock
, SLOT(hide()));
1233 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1234 terminalAction
->setText(i18nc("@title:window Shell terminal", "Terminal"));
1235 terminalAction
->setShortcut(Qt::Key_F4
);
1236 terminalAction
->setIcon(KIcon("terminal"));
1237 actionCollection()->addAction("show_terminal_panel", terminalDock
->toggleViewAction());
1239 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1240 connect(this, SIGNAL(urlChanged(KUrl
)),
1241 terminalPanel
, SLOT(setUrl(KUrl
)));
1244 const bool firstRun
= DolphinSettings::instance().generalSettings()->firstRun();
1246 foldersDock
->hide();
1248 terminalDock
->hide();
1252 QDockWidget
* placesDock
= new QDockWidget(i18nc("@title:window", "Places"));
1253 placesDock
->setObjectName("placesDock");
1254 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1256 PlacesPanel
* placesPanel
= new PlacesPanel(placesDock
);
1257 placesDock
->setWidget(placesPanel
);
1258 placesPanel
->setModel(DolphinSettings::instance().placesModel());
1259 placesPanel
->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff
);
1261 QAction
* placesAction
= placesDock
->toggleViewAction();
1262 placesAction
->setText(i18nc("@title:window", "Places"));
1263 placesAction
->setShortcut(Qt::Key_F9
);
1264 placesAction
->setIcon(KIcon("bookmarks"));
1265 actionCollection()->addAction("show_places_panel", placesDock
->toggleViewAction());
1267 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1268 connect(placesPanel
, SIGNAL(urlChanged(KUrl
, Qt::MouseButtons
)),
1269 this, SLOT(handlePlacesClick(KUrl
, Qt::MouseButtons
)));
1270 connect(this, SIGNAL(urlChanged(KUrl
)),
1271 placesPanel
, SLOT(setUrl(KUrl
)));
1274 void DolphinMainWindow::updateEditActions()
1276 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1277 if (list
.isEmpty()) {
1278 stateChanged("has_no_selection");
1280 stateChanged("has_selection");
1282 KActionCollection
* col
= actionCollection();
1283 QAction
* renameAction
= col
->action("rename");
1284 QAction
* moveToTrashAction
= col
->action("move_to_trash");
1285 QAction
* deleteAction
= col
->action("delete");
1286 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
1287 QAction
* deleteWithTrashShortcut
= col
->action("delete_shortcut"); // see DolphinViewActionHandler
1289 KonqFileItemCapabilities
capabilities(list
);
1290 const bool enableMoveToTrash
= capabilities
.isLocal() && capabilities
.supportsMoving();
1292 renameAction
->setEnabled(capabilities
.supportsMoving());
1293 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1294 deleteAction
->setEnabled(capabilities
.supportsDeleting());
1295 deleteWithTrashShortcut
->setEnabled(capabilities
.supportsDeleting() && !enableMoveToTrash
);
1296 cutAction
->setEnabled(capabilities
.supportsMoving());
1298 updatePasteAction();
1301 void DolphinMainWindow::updateViewActions()
1303 m_actionHandler
->updateViewActions();
1305 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1306 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
1308 updateSplitAction();
1310 QAction
* editableLocactionAction
= actionCollection()->action("editable_location");
1311 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
1312 editableLocactionAction
->setChecked(urlNavigator
->isUrlEditable());
1315 void DolphinMainWindow::updateGoActions()
1317 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
1318 const KUrl
& currentUrl
= m_activeViewContainer
->url();
1319 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
1322 void DolphinMainWindow::rememberClosedTab(int index
)
1324 KMenu
* tabsMenu
= m_recentTabsMenu
->menu();
1326 const QString primaryPath
= m_viewTab
[index
].primaryView
->url().path();
1327 const QString iconName
= KMimeType::iconNameForUrl(primaryPath
);
1329 QAction
* action
= new QAction(primaryPath
, tabsMenu
);
1331 ClosedTab closedTab
;
1332 closedTab
.primaryUrl
= m_viewTab
[index
].primaryView
->url();
1334 if (m_viewTab
[index
].secondaryView
!= 0) {
1335 closedTab
.secondaryUrl
= m_viewTab
[index
].secondaryView
->url();
1336 closedTab
.isSplit
= true;
1338 closedTab
.isSplit
= false;
1341 action
->setData(QVariant::fromValue(closedTab
));
1342 action
->setIcon(KIcon(iconName
));
1344 // add the closed tab menu entry after the separator and
1345 // "Empty Recently Closed Tabs" entry
1346 if (tabsMenu
->actions().size() == 2) {
1347 tabsMenu
->addAction(action
);
1349 tabsMenu
->insertAction(tabsMenu
->actions().at(2), action
);
1351 actionCollection()->action("closed_tabs")->setEnabled(true);
1354 void DolphinMainWindow::clearStatusBar()
1356 m_activeViewContainer
->statusBar()->clear();
1359 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
1361 connect(container
, SIGNAL(showFilterBarChanged(bool)),
1362 this, SLOT(updateFilterBarAction(bool)));
1364 DolphinView
* view
= container
->view();
1365 connect(view
, SIGNAL(selectionChanged(KFileItemList
)),
1366 this, SLOT(slotSelectionChanged(KFileItemList
)));
1367 connect(view
, SIGNAL(requestItemInfo(KFileItem
)),
1368 this, SLOT(slotRequestItemInfo(KFileItem
)));
1369 connect(view
, SIGNAL(activated()),
1370 this, SLOT(toggleActiveView()));
1371 connect(view
, SIGNAL(tabRequested(const KUrl
&)),
1372 this, SLOT(openNewTab(const KUrl
&)));
1374 const KUrlNavigator
* navigator
= container
->urlNavigator();
1375 connect(navigator
, SIGNAL(urlChanged(const KUrl
&)),
1376 this, SLOT(changeUrl(const KUrl
&)));
1377 connect(navigator
, SIGNAL(historyChanged()),
1378 this, SLOT(updateHistory()));
1379 connect(navigator
, SIGNAL(editableStateChanged(bool)),
1380 this, SLOT(slotEditableStateChanged(bool)));
1383 void DolphinMainWindow::updateSplitAction()
1385 QAction
* splitAction
= actionCollection()->action("split_view");
1386 if (m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
1387 if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
1388 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
1389 splitAction
->setIcon(KIcon("view-right-close"));
1391 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
1392 splitAction
->setIcon(KIcon("view-left-close"));
1395 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
1396 splitAction
->setIcon(KIcon("view-right-new"));
1400 QString
DolphinMainWindow::tabName(const KUrl
& url
) const
1403 if (url
.equals(KUrl("file:///"))) {
1406 name
= url
.fileName();
1407 if (name
.isEmpty()) {
1408 name
= url
.protocol();
1410 // Make sure that a '&' inside the directory name is displayed correctly
1411 // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
1412 name
.replace('&', "&&");
1418 bool DolphinMainWindow::isKompareInstalled() const
1420 static bool initialized
= false;
1421 static bool installed
= false;
1423 // TODO: maybe replace this approach later by using a menu
1424 // plugin like kdiff3plugin.cpp
1425 installed
= !KGlobal::dirs()->findExe("kompare").isEmpty();
1431 void DolphinMainWindow::createSecondaryView(int tabIndex
)
1433 QSplitter
* splitter
= m_viewTab
[tabIndex
].splitter
;
1434 const int newWidth
= (m_viewTab
[tabIndex
].primaryView
->width() - splitter
->handleWidth()) / 2;
1436 const DolphinView
* view
= m_viewTab
[tabIndex
].primaryView
->view();
1437 m_viewTab
[tabIndex
].secondaryView
= new DolphinViewContainer(this, 0, view
->rootUrl());
1438 splitter
->addWidget(m_viewTab
[tabIndex
].secondaryView
);
1439 splitter
->setSizes(QList
<int>() << newWidth
<< newWidth
);
1440 connectViewSignals(m_viewTab
[tabIndex
].secondaryView
);
1441 m_viewTab
[tabIndex
].secondaryView
->view()->reload();
1442 m_viewTab
[tabIndex
].secondaryView
->setActive(false);
1443 m_viewTab
[tabIndex
].secondaryView
->show();
1446 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
1447 KIO::FileUndoManager::UiInterface()
1451 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
1455 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
1457 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
1459 DolphinStatusBar
* statusBar
= mainWin
->activeViewContainer()->statusBar();
1460 statusBar
->setMessage(job
->errorString(), DolphinStatusBar::Error
);
1462 KIO::FileUndoManager::UiInterface::jobError(job
);
1466 #include "dolphinmainwindow.moc"