]>
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 const QString iconName
= KMimeType::iconNameForUrl(url
);
241 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(iconName
));
242 emit
urlChanged(url
);
246 void DolphinMainWindow::changeSelection(const KFileItemList
& selection
)
248 activeViewContainer()->view()->changeSelection(selection
);
251 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
253 KToggleAction
* editableLocationAction
=
254 static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
255 editableLocationAction
->setChecked(editable
);
258 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
262 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
263 int selectedUrlsCount
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedItemsCount();
264 if (m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
265 selectedUrlsCount
+= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItemsCount();
268 QAction
* compareFilesAction
= actionCollection()->action("compare_files");
269 if (selectedUrlsCount
== 2) {
270 compareFilesAction
->setEnabled(isKompareInstalled());
272 compareFilesAction
->setEnabled(false);
275 m_activeViewContainer
->updateStatusBar();
277 emit
selectionChanged(selection
);
280 void DolphinMainWindow::slotWheelMoved(int wheelDelta
)
282 if (wheelDelta
> 0) {
289 void DolphinMainWindow::slotRequestItemInfo(const KFileItem
& item
)
291 emit
requestItemInfo(item
);
294 void DolphinMainWindow::updateHistory()
296 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
297 const int index
= urlNavigator
->historyIndex();
299 QAction
* backAction
= actionCollection()->action("go_back");
300 if (backAction
!= 0) {
301 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
304 QAction
* forwardAction
= actionCollection()->action("go_forward");
305 if (forwardAction
!= 0) {
306 forwardAction
->setEnabled(index
> 0);
310 void DolphinMainWindow::updateFilterBarAction(bool show
)
312 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
313 showFilterBarAction
->setChecked(show
);
316 void DolphinMainWindow::openNewMainWindow()
318 DolphinApplication::app()->createMainWindow()->show();
321 void DolphinMainWindow::openNewTab()
323 openNewTab(m_activeViewContainer
->url());
324 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
326 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
327 if (navigator
->isUrlEditable()) {
328 // if a new tab is opened and the URL is editable, assure that
329 // the user can edit the URL without manually setting the focus
330 navigator
->setFocus();
334 void DolphinMainWindow::openNewTab(const KUrl
& url
)
336 const KIcon icon
= KIcon(KMimeType::iconNameForUrl(m_activeViewContainer
->url()));
337 if (m_viewTab
.count() == 1) {
338 // Only one view is open currently and hence no tab is shown at
339 // all. Before creating a tab for 'url', provide a tab for the current URL.
340 m_tabBar
->addTab(icon
, tabName(m_activeViewContainer
->url()));
341 m_tabBar
->blockSignals(false);
344 m_tabBar
->addTab(icon
, tabName(url
));
347 viewTab
.splitter
= new QSplitter(this);
348 viewTab
.primaryView
= new DolphinViewContainer(this, viewTab
.splitter
, url
);
349 viewTab
.primaryView
->setActive(false);
350 connectViewSignals(viewTab
.primaryView
);
351 viewTab
.primaryView
->view()->reload();
353 m_viewTab
.append(viewTab
);
355 actionCollection()->action("close_tab")->setEnabled(true);
357 // provide a split view, if the startup settings are set this way
358 const GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
359 if (generalSettings
->splitView()) {
360 const int tabIndex
= m_viewTab
.count() - 1;
361 createSecondaryView(tabIndex
);
362 m_viewTab
[tabIndex
].secondaryView
->setActive(true);
363 m_viewTab
[tabIndex
].isPrimaryViewActive
= false;
367 void DolphinMainWindow::activateNextTab()
369 if ((m_viewTab
.count() == 1) || (m_tabBar
->count() < 2)) {
373 const int tabIndex
= (m_tabBar
->currentIndex() + 1) % m_tabBar
->count();
374 m_tabBar
->setCurrentIndex(tabIndex
);
377 void DolphinMainWindow::activatePrevTab()
379 if ((m_viewTab
.count() == 1) || (m_tabBar
->count() < 2)) {
383 int tabIndex
= m_tabBar
->currentIndex() - 1;
384 if (tabIndex
== -1) {
385 tabIndex
= m_tabBar
->count() - 1;
387 m_tabBar
->setCurrentIndex(tabIndex
);
390 void DolphinMainWindow::openInNewTab()
392 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
393 if ((list
.count() == 1) && list
[0].isDir()) {
394 openNewTab(m_activeViewContainer
->view()->selectedUrls()[0]);
398 void DolphinMainWindow::openInNewWindow()
400 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
401 if ((list
.count() == 1) && list
[0].isDir()) {
402 DolphinMainWindow
* window
= DolphinApplication::app()->createMainWindow();
403 window
->changeUrl(m_activeViewContainer
->view()->selectedUrls()[0]);
408 void DolphinMainWindow::toggleActiveView()
410 if (m_viewTab
[m_tabIndex
].secondaryView
== 0) {
411 // only one view is available
415 Q_ASSERT(m_activeViewContainer
!= 0);
416 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
418 DolphinViewContainer
* left
= m_viewTab
[m_tabIndex
].primaryView
;
419 DolphinViewContainer
* right
= m_viewTab
[m_tabIndex
].secondaryView
;
420 setActiveViewContainer(m_activeViewContainer
== right
? left
: right
);
423 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
425 DolphinSettings
& settings
= DolphinSettings::instance();
426 GeneralSettings
* generalSettings
= settings
.generalSettings();
427 generalSettings
->setFirstRun(false);
431 KXmlGuiWindow::closeEvent(event
);
434 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
436 // TODO: remember tabs
437 DolphinViewContainer
* cont
= m_viewTab
[m_tabIndex
].primaryView
;
438 group
.writeEntry("Primary Url", cont
->url().url());
439 group
.writeEntry("Primary Editable Url", cont
->isUrlEditable());
441 cont
= m_viewTab
[m_tabIndex
].secondaryView
;
443 group
.writeEntry("Secondary Url", cont
->url().url());
444 group
.writeEntry("Secondary Editable Url", cont
->isUrlEditable());
448 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
451 DolphinViewContainer
* cont
= m_viewTab
[m_tabIndex
].primaryView
;
453 cont
->setUrl(group
.readEntry("Primary Url"));
454 bool editable
= group
.readEntry("Primary Editable Url", false);
455 cont
->urlNavigator()->setUrlEditable(editable
);
457 cont
= m_viewTab
[m_tabIndex
].secondaryView
;
458 const QString secondaryUrl
= group
.readEntry("Secondary Url");
459 if (!secondaryUrl
.isEmpty()) {
461 // a secondary view should be shown, but no one is available
462 // currently -> create a new view
464 cont
= m_viewTab
[m_tabIndex
].secondaryView
;
468 cont
->setUrl(secondaryUrl
);
469 bool editable
= group
.readEntry("Secondary Editable Url", false);
470 cont
->urlNavigator()->setUrlEditable(editable
);
471 } else if (cont
!= 0) {
472 // no secondary view should be shown, but the default setting shows
473 // one already -> close the view
478 void DolphinMainWindow::updateNewMenu()
480 m_newMenu
->slotCheckUpToDate();
481 m_newMenu
->setPopupFiles(activeViewContainer()->url());
484 void DolphinMainWindow::quit()
489 void DolphinMainWindow::showErrorMessage(const QString
& message
)
491 if (!message
.isEmpty()) {
492 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
493 statusBar
->setMessage(message
, DolphinStatusBar::Error
);
497 void DolphinMainWindow::slotUndoAvailable(bool available
)
499 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
500 if (undoAction
!= 0) {
501 undoAction
->setEnabled(available
);
505 void DolphinMainWindow::restoreClosedTab(QAction
* action
)
507 if (action
->data().toBool()) {
508 // clear all actions except the "Empty Recently Closed Tabs"
509 // action and the separator
510 QList
<QAction
*> actions
= m_recentTabsMenu
->menu()->actions();
511 const int count
= actions
.size();
512 for (int i
= 2; i
< count
; i
++) {
513 m_recentTabsMenu
->menu()->removeAction(actions
.at(i
));
516 const ClosedTab closedTab
= action
->data().value
<ClosedTab
>();
517 openNewTab(closedTab
.primaryUrl
);
518 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
520 if (closedTab
.isSplit
) {
521 // create secondary view
523 m_viewTab
[m_tabIndex
].secondaryView
->setUrl(closedTab
.secondaryUrl
);
526 m_recentTabsMenu
->removeAction(action
);
529 if (m_recentTabsMenu
->menu()->actions().count() == 2) {
530 m_recentTabsMenu
->setEnabled(false);
534 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
536 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
537 if (undoAction
!= 0) {
538 undoAction
->setText(text
);
542 void DolphinMainWindow::undo()
545 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
546 KIO::FileUndoManager::self()->undo();
549 void DolphinMainWindow::cut()
551 m_activeViewContainer
->view()->cutSelectedItems();
554 void DolphinMainWindow::copy()
556 m_activeViewContainer
->view()->copySelectedItems();
559 void DolphinMainWindow::paste()
561 m_activeViewContainer
->view()->paste();
564 void DolphinMainWindow::updatePasteAction()
566 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
567 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
568 pasteAction
->setEnabled(pasteInfo
.first
);
569 pasteAction
->setText(pasteInfo
.second
);
572 void DolphinMainWindow::selectAll()
576 // if the URL navigator is editable and focused, select the whole
577 // URL instead of all items of the view
579 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
580 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit();
581 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
582 lineEdit
->hasFocus();
584 lineEdit
->selectAll();
586 m_activeViewContainer
->view()->selectAll();
590 void DolphinMainWindow::invertSelection()
593 m_activeViewContainer
->view()->invertSelection();
596 void DolphinMainWindow::toggleSplitView()
598 if (m_viewTab
[m_tabIndex
].secondaryView
== 0) {
599 createSecondaryView(m_tabIndex
);
600 setActiveViewContainer(m_viewTab
[m_tabIndex
].secondaryView
);
601 } else if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
602 // remove secondary view
603 m_viewTab
[m_tabIndex
].secondaryView
->close();
604 m_viewTab
[m_tabIndex
].secondaryView
->deleteLater();
605 m_viewTab
[m_tabIndex
].secondaryView
= 0;
607 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
609 // The primary view is active and should be closed. Hence from a users point of view
610 // the content of the secondary view should be moved to the primary view.
611 // From an implementation point of view it is more efficient to close
612 // the primary view and exchange the internal pointers afterwards.
614 m_viewTab
[m_tabIndex
].primaryView
->close();
615 m_viewTab
[m_tabIndex
].primaryView
->deleteLater();
616 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
617 m_viewTab
[m_tabIndex
].secondaryView
= 0;
619 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
625 void DolphinMainWindow::reloadView()
628 m_activeViewContainer
->view()->reload();
631 void DolphinMainWindow::stopLoading()
635 void DolphinMainWindow::toggleFilterBarVisibility(bool show
)
637 m_activeViewContainer
->showFilterBar(show
);
640 void DolphinMainWindow::toggleEditLocation()
644 QAction
* action
= actionCollection()->action("editable_location");
645 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
646 urlNavigator
->setUrlEditable(action
->isChecked());
649 void DolphinMainWindow::replaceLocation()
651 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
652 navigator
->setUrlEditable(true);
653 navigator
->setFocus();
655 // select the whole text of the combo box editor
656 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit();
657 const QString text
= lineEdit
->text();
658 lineEdit
->setSelection(0, text
.length());
661 void DolphinMainWindow::goBack()
664 m_activeViewContainer
->urlNavigator()->goBack();
667 void DolphinMainWindow::goForward()
670 m_activeViewContainer
->urlNavigator()->goForward();
673 void DolphinMainWindow::goUp()
676 m_activeViewContainer
->urlNavigator()->goUp();
679 void DolphinMainWindow::goHome()
682 m_activeViewContainer
->urlNavigator()->goHome();
685 void DolphinMainWindow::compareFiles()
687 // The method is only invoked if exactly 2 files have
688 // been selected. The selected files may be:
689 // - both in the primary view
690 // - both in the secondary view
691 // - one in the primary view and the other in the secondary
693 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
697 KUrl::List urls
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedUrls();
699 switch (urls
.count()) {
701 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
!= 0);
702 urls
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedUrls();
703 Q_ASSERT(urls
.count() == 2);
711 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
!= 0);
712 urls
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedUrls();
713 Q_ASSERT(urls
.count() == 1);
725 // may not happen: compareFiles may only get invoked if 2
726 // files are selected
731 QString
command("kompare -c \"");
732 command
.append(urlA
.pathOrUrl());
733 command
.append("\" \"");
734 command
.append(urlB
.pathOrUrl());
735 command
.append('\"');
736 KRun::runCommand(command
, "Kompare", "kompare", this);
739 void DolphinMainWindow::toggleShowMenuBar()
741 const bool visible
= menuBar()->isVisible();
742 menuBar()->setVisible(!visible
);
745 void DolphinMainWindow::editSettings()
747 if (m_settingsDialog
== 0) {
748 const KUrl
& url
= activeViewContainer()->url();
749 m_settingsDialog
= new DolphinSettingsDialog(url
, this);
750 m_settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
751 m_settingsDialog
->show();
753 m_settingsDialog
->raise();
757 void DolphinMainWindow::setActiveTab(int index
)
759 Q_ASSERT(index
>= 0);
760 Q_ASSERT(index
< m_viewTab
.count());
761 if (index
== m_tabIndex
) {
765 // hide current tab content
766 ViewTab
& hiddenTab
= m_viewTab
[m_tabIndex
];
767 hiddenTab
.isPrimaryViewActive
= hiddenTab
.primaryView
->isActive();
768 hiddenTab
.primaryView
->setActive(false);
769 if (hiddenTab
.secondaryView
!= 0) {
770 hiddenTab
.secondaryView
->setActive(false);
772 QSplitter
* splitter
= m_viewTab
[m_tabIndex
].splitter
;
774 m_centralWidgetLayout
->removeWidget(splitter
);
776 // show active tab content
779 ViewTab
& viewTab
= m_viewTab
[index
];
780 m_centralWidgetLayout
->addWidget(viewTab
.splitter
);
781 viewTab
.primaryView
->show();
782 if (viewTab
.secondaryView
!= 0) {
783 viewTab
.secondaryView
->show();
785 viewTab
.splitter
->show();
787 setActiveViewContainer(viewTab
.isPrimaryViewActive
? viewTab
.primaryView
:
788 viewTab
.secondaryView
);
791 void DolphinMainWindow::closeTab()
793 closeTab(m_tabBar
->currentIndex());
796 void DolphinMainWindow::closeTab(int index
)
798 Q_ASSERT(index
>= 0);
799 Q_ASSERT(index
< m_viewTab
.count());
800 if (m_viewTab
.count() == 1) {
801 // the last tab may never get closed
805 if (index
== m_tabIndex
) {
806 // The tab that should be closed is the active tab. Activate the
807 // previous tab before closing the tab.
808 m_tabBar
->setCurrentIndex((index
> 0) ? index
- 1 : 1);
810 rememberClosedTab(index
);
813 m_viewTab
[index
].primaryView
->deleteLater();
814 if (m_viewTab
[index
].secondaryView
!= 0) {
815 m_viewTab
[index
].secondaryView
->deleteLater();
817 m_viewTab
[index
].splitter
->deleteLater();
818 m_viewTab
.erase(m_viewTab
.begin() + index
);
820 m_tabBar
->blockSignals(true);
821 m_tabBar
->removeTab(index
);
823 if (m_tabIndex
> index
) {
825 Q_ASSERT(m_tabIndex
>= 0);
828 // if only one tab is left, also remove the tab entry so that
829 // closing the last tab is not possible
830 if (m_viewTab
.count() == 1) {
831 m_tabBar
->removeTab(0);
832 actionCollection()->action("close_tab")->setEnabled(false);
834 m_tabBar
->blockSignals(false);
838 void DolphinMainWindow::openTabContextMenu(int index
, const QPoint
& pos
)
842 QAction
* newTabAction
= menu
.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab"));
843 newTabAction
->setShortcut(actionCollection()->action("new_tab")->shortcut());
845 QAction
* closeOtherTabsAction
= menu
.addAction(KIcon("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs"));
847 QAction
* closeTabAction
= menu
.addAction(KIcon("tab-close"), i18nc("@action:inmenu", "Close Tab"));
848 closeTabAction
->setShortcut(actionCollection()->action("close_tab")->shortcut());
850 QAction
* selectedAction
= menu
.exec(pos
);
851 if (selectedAction
== newTabAction
) {
852 const ViewTab
& tab
= m_viewTab
[index
];
853 Q_ASSERT(tab
.primaryView
!= 0);
854 const KUrl url
= (tab
.secondaryView
!= 0) && tab
.secondaryView
->isActive() ?
855 tab
.secondaryView
->url() : tab
.primaryView
->url();
857 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
858 } else if (selectedAction
== closeOtherTabsAction
) {
859 const int count
= m_tabBar
->count();
860 for (int i
= 0; i
< index
; ++i
) {
863 for (int i
= index
+ 1; i
< count
; ++i
) {
866 } else if (selectedAction
== closeTabAction
) {
871 void DolphinMainWindow::handlePlacesClick(const KUrl
& url
, Qt::MouseButtons buttons
)
873 if (buttons
& Qt::MidButton
) {
875 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
881 void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent
* event
, bool& canDecode
)
883 canDecode
= KUrl::List::canDecode(event
->mimeData());
886 void DolphinMainWindow::searchItems(const KUrl
& url
)
888 m_activeViewContainer
->setUrl(url
);
891 void DolphinMainWindow::init()
893 DolphinSettings
& settings
= DolphinSettings::instance();
895 // Check whether Dolphin runs the first time. If yes then
896 // a proper default window size is given at the end of DolphinMainWindow::init().
897 GeneralSettings
* generalSettings
= settings
.generalSettings();
898 const bool firstRun
= generalSettings
->firstRun();
900 generalSettings
->setViewPropsTimestamp(QDateTime::currentDateTime());
903 setAcceptDrops(true);
905 m_viewTab
[m_tabIndex
].splitter
= new QSplitter(this);
909 const KUrl
& homeUrl
= generalSettings
->homeUrl();
910 setCaption(homeUrl
.fileName());
911 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
912 connect(m_actionHandler
, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
913 ViewProperties
props(homeUrl
);
914 m_viewTab
[m_tabIndex
].primaryView
= new DolphinViewContainer(this,
915 m_viewTab
[m_tabIndex
].splitter
,
918 m_activeViewContainer
= m_viewTab
[m_tabIndex
].primaryView
;
919 connectViewSignals(m_activeViewContainer
);
920 DolphinView
* view
= m_activeViewContainer
->view();
922 m_activeViewContainer
->show();
923 m_actionHandler
->setCurrentView(view
);
925 m_tabBar
= new KTabBar(this);
926 m_tabBar
->setMovable(true);
927 m_tabBar
->setTabsClosable(true);
928 connect(m_tabBar
, SIGNAL(currentChanged(int)),
929 this, SLOT(setActiveTab(int)));
930 connect(m_tabBar
, SIGNAL(tabCloseRequested(int)),
931 this, SLOT(closeTab(int)));
932 connect(m_tabBar
, SIGNAL(contextMenu(int, const QPoint
&)),
933 this, SLOT(openTabContextMenu(int, const QPoint
&)));
934 connect(m_tabBar
, SIGNAL(newTabRequest()),
935 this, SLOT(openNewTab()));
936 connect(m_tabBar
, SIGNAL(testCanDecode(const QDragMoveEvent
*, bool&)),
937 this, SLOT(slotTestCanDecode(const QDragMoveEvent
*, bool&)));
938 connect(m_tabBar
, SIGNAL(wheelDelta(int)),
939 this, SLOT(slotWheelMoved(int)));
940 connect(m_tabBar
, SIGNAL(mouseMiddleClick(int)),
941 this, SLOT(closeTab(int)));
943 m_tabBar
->blockSignals(true); // signals get unblocked after at least 2 tabs are open
945 QWidget
* centralWidget
= new QWidget(this);
946 m_centralWidgetLayout
= new QVBoxLayout(centralWidget
);
947 m_centralWidgetLayout
->setSpacing(0);
948 m_centralWidgetLayout
->setMargin(0);
949 m_centralWidgetLayout
->addWidget(m_tabBar
);
950 m_centralWidgetLayout
->addWidget(m_viewTab
[m_tabIndex
].splitter
);
952 setCentralWidget(centralWidget
);
954 emit
urlChanged(homeUrl
);
956 setupGUI(Keys
| Save
| Create
| ToolBar
);
958 m_searchBox
->setParent(toolBar("searchToolBar"));
961 stateChanged("new_file");
963 QClipboard
* clipboard
= QApplication::clipboard();
964 connect(clipboard
, SIGNAL(dataChanged()),
965 this, SLOT(updatePasteAction()));
969 if (generalSettings
->splitView()) {
974 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
975 showFilterBarAction
->setChecked(generalSettings
->filterBar());
978 // assure a proper default size if Dolphin runs the first time
982 m_showMenuBar
->setChecked(!menuBar()->isHidden()); // workaround for bug #171080
985 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer
* viewContainer
)
987 Q_ASSERT(viewContainer
!= 0);
988 Q_ASSERT((viewContainer
== m_viewTab
[m_tabIndex
].primaryView
) ||
989 (viewContainer
== m_viewTab
[m_tabIndex
].secondaryView
));
990 if (m_activeViewContainer
== viewContainer
) {
994 m_activeViewContainer
->setActive(false);
995 m_activeViewContainer
= viewContainer
;
997 // Activating the view container might trigger a recursive setActiveViewContainer() call
998 // inside DolphinMainWindow::toggleActiveView() when having a split view. Temporary
999 // disconnect the activated() signal in this case:
1000 disconnect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1001 m_activeViewContainer
->setActive(true);
1002 connect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1004 m_actionHandler
->setCurrentView(viewContainer
->view());
1007 updateEditActions();
1008 updateViewActions();
1011 const KUrl
& url
= m_activeViewContainer
->url();
1012 setCaption(url
.fileName());
1013 if (m_viewTab
.count() > 1 && m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
1014 m_tabBar
->setTabText(m_tabIndex
, tabName(url
));
1015 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(KMimeType::iconNameForUrl(url
)));
1018 emit
urlChanged(url
);
1021 void DolphinMainWindow::setupActions()
1023 // setup 'File' menu
1024 m_newMenu
= new DolphinNewMenu(this, this);
1025 KMenu
* menu
= m_newMenu
->menu();
1026 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1027 menu
->setIcon(KIcon("document-new"));
1028 connect(menu
, SIGNAL(aboutToShow()),
1029 this, SLOT(updateNewMenu()));
1031 KAction
* newWindow
= actionCollection()->addAction("new_window");
1032 newWindow
->setIcon(KIcon("window-new"));
1033 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1034 newWindow
->setShortcut(Qt::CTRL
| Qt::Key_N
);
1035 connect(newWindow
, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1037 KAction
* newTab
= actionCollection()->addAction("new_tab");
1038 newTab
->setIcon(KIcon("tab-new"));
1039 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1040 newTab
->setShortcut(KShortcut(Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
));
1041 connect(newTab
, SIGNAL(triggered()), this, SLOT(openNewTab()));
1043 KAction
* closeTab
= actionCollection()->addAction("close_tab");
1044 closeTab
->setIcon(KIcon("tab-close"));
1045 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1046 closeTab
->setShortcut(Qt::CTRL
| Qt::Key_W
);
1047 closeTab
->setEnabled(false);
1048 connect(closeTab
, SIGNAL(triggered()), this, SLOT(closeTab()));
1050 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1052 // setup 'Edit' menu
1053 KStandardAction::undo(this,
1055 actionCollection());
1057 // need to remove shift+del from cut action, else the shortcut for deletejob
1059 KAction
* cut
= KStandardAction::cut(this, SLOT(cut()), actionCollection());
1060 KShortcut cutShortcut
= cut
->shortcut();
1061 cutShortcut
.remove(Qt::SHIFT
+ Qt::Key_Delete
, KShortcut::KeepEmpty
);
1062 cut
->setShortcut(cutShortcut
);
1063 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1064 KStandardAction::paste(this, SLOT(paste()), actionCollection());
1066 KAction
* selectAll
= actionCollection()->addAction("select_all");
1067 selectAll
->setText(i18nc("@action:inmenu Edit", "Select All"));
1068 selectAll
->setShortcut(Qt::CTRL
+ Qt::Key_A
);
1069 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
1071 KAction
* invertSelection
= actionCollection()->addAction("invert_selection");
1072 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1073 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1074 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
1076 // setup 'View' menu
1077 // (note that most of it is set up in DolphinViewActionHandler)
1079 KAction
* split
= actionCollection()->addAction("split_view");
1080 split
->setShortcut(Qt::Key_F3
);
1081 updateSplitAction();
1082 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1084 KAction
* reload
= actionCollection()->addAction("reload");
1085 reload
->setText(i18nc("@action:inmenu View", "Reload"));
1086 reload
->setShortcut(Qt::Key_F5
);
1087 reload
->setIcon(KIcon("view-refresh"));
1088 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
1090 KAction
* stop
= actionCollection()->addAction("stop");
1091 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1092 stop
->setIcon(KIcon("process-stop"));
1093 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
1095 KToggleAction
* showFullLocation
= actionCollection()->add
<KToggleAction
>("editable_location");
1096 showFullLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1097 showFullLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
1098 connect(showFullLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1100 KAction
* replaceLocation
= actionCollection()->addAction("replace_location");
1101 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1102 replaceLocation
->setShortcut(Qt::Key_F6
);
1103 connect(replaceLocation
, SIGNAL(triggered()), this, SLOT(replaceLocation()));
1106 KAction
* backAction
= KStandardAction::back(this, SLOT(goBack()), actionCollection());
1107 KShortcut backShortcut
= backAction
->shortcut();
1108 backShortcut
.setAlternate(Qt::Key_Backspace
);
1109 backAction
->setShortcut(backShortcut
);
1111 m_recentTabsMenu
= new KActionMenu(i18n("&Recently Closed Tabs"), this);
1112 m_recentTabsMenu
->setIcon(KIcon("edit-undo"));
1113 actionCollection()->addAction("closed_tabs", m_recentTabsMenu
);
1114 connect(m_recentTabsMenu
->menu(), SIGNAL(triggered(QAction
*)),
1115 this, SLOT(restoreClosedTab(QAction
*)));
1117 QAction
* action
= new QAction("&Empty Recently Closed Tabs", m_recentTabsMenu
);
1118 action
->setIcon(KIcon("edit-clear-list"));
1119 action
->setData(QVariant::fromValue(true));
1120 m_recentTabsMenu
->addAction(action
);
1121 m_recentTabsMenu
->addSeparator();
1122 m_recentTabsMenu
->setEnabled(false);
1124 KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1125 KStandardAction::up(this, SLOT(goUp()), actionCollection());
1126 KStandardAction::home(this, SLOT(goHome()), actionCollection());
1128 // setup 'Tools' menu
1129 KToggleAction
* showSearchBar
= actionCollection()->add
<KToggleAction
>("show_search_bar");
1130 showSearchBar
->setText(i18nc("@action:inmenu Tools", "Show Search Bar"));
1131 showSearchBar
->setShortcut(Qt::CTRL
| Qt::Key_S
);
1132 connect(showSearchBar
, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
1134 KToggleAction
* showFilterBar
= actionCollection()->add
<KToggleAction
>("show_filter_bar");
1135 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1136 showFilterBar
->setShortcut(Qt::CTRL
| Qt::Key_I
);
1137 connect(showFilterBar
, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
1139 KAction
* compareFiles
= actionCollection()->addAction("compare_files");
1140 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1141 compareFiles
->setIcon(KIcon("kompare"));
1142 compareFiles
->setEnabled(false);
1143 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
1145 // setup 'Settings' menu
1146 m_showMenuBar
= KStandardAction::showMenubar(this, SLOT(toggleShowMenuBar()), actionCollection());
1147 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1149 // not in menu actions
1150 KAction
* activateNextTab
= actionCollection()->addAction("activate_next_tab");
1151 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1152 connect(activateNextTab
, SIGNAL(triggered()), SLOT(activateNextTab()));
1153 activateNextTab
->setShortcuts(QApplication::isRightToLeft() ? KStandardShortcut::tabPrev() :
1154 KStandardShortcut::tabNext());
1156 KAction
* activatePrevTab
= actionCollection()->addAction("activate_prev_tab");
1157 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1158 connect(activatePrevTab
, SIGNAL(triggered()), SLOT(activatePrevTab()));
1159 activatePrevTab
->setShortcuts(QApplication::isRightToLeft() ? KStandardShortcut::tabNext() :
1160 KStandardShortcut::tabPrev());
1163 KAction
* openInNewTab
= actionCollection()->addAction("open_in_new_tab");
1164 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1165 openInNewTab
->setIcon(KIcon("tab-new"));
1166 connect(openInNewTab
, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1168 KAction
* openInNewWindow
= actionCollection()->addAction("open_in_new_window");
1169 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1170 openInNewWindow
->setIcon(KIcon("window-new"));
1171 connect(openInNewWindow
, SIGNAL(triggered()), this, SLOT(openInNewWindow()));
1174 m_searchBox
= new DolphinSearchBox(this);
1175 connect(m_searchBox
, SIGNAL(search(KUrl
)), this, SLOT(searchItems(KUrl
)));
1177 KAction
* search
= new KAction(this);
1178 actionCollection()->addAction("search_bar", search
);
1179 search
->setText(i18nc("@action:inmenu", "Search Bar"));
1180 search
->setDefaultWidget(m_searchBox
);
1181 search
->setShortcutConfigurable(false);
1184 void DolphinMainWindow::setupDockWidgets()
1186 // setup "Information"
1187 QDockWidget
* infoDock
= new QDockWidget(i18nc("@title:window", "Information"));
1188 infoDock
->setObjectName("infoDock");
1189 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1190 Panel
* infoPanel
= new InformationPanel(infoDock
);
1191 infoDock
->setWidget(infoPanel
);
1193 QAction
* infoAction
= infoDock
->toggleViewAction();
1194 infoAction
->setText(i18nc("@title:window", "Information"));
1195 infoAction
->setShortcut(Qt::Key_F11
);
1196 infoAction
->setIcon(KIcon("dialog-information"));
1197 actionCollection()->addAction("show_info_panel", infoDock
->toggleViewAction());
1199 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1200 connect(this, SIGNAL(urlChanged(KUrl
)),
1201 infoPanel
, SLOT(setUrl(KUrl
)));
1202 connect(this, SIGNAL(selectionChanged(KFileItemList
)),
1203 infoPanel
, SLOT(setSelection(KFileItemList
)));
1204 connect(this, SIGNAL(requestItemInfo(KFileItem
)),
1205 infoPanel
, SLOT(requestDelayedItemInfo(KFileItem
)));
1208 QDockWidget
* foldersDock
= new QDockWidget(i18nc("@title:window", "Folders"));
1209 foldersDock
->setObjectName("foldersDock");
1210 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1211 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1212 foldersDock
->setWidget(foldersPanel
);
1214 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1215 foldersAction
->setText(i18nc("@title:window", "Folders"));
1216 foldersAction
->setShortcut(Qt::Key_F7
);
1217 foldersAction
->setIcon(KIcon("folder"));
1218 actionCollection()->addAction("show_folders_panel", foldersDock
->toggleViewAction());
1220 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1221 connect(this, SIGNAL(urlChanged(KUrl
)),
1222 foldersPanel
, SLOT(setUrl(KUrl
)));
1223 connect(foldersPanel
, SIGNAL(changeUrl(KUrl
, Qt::MouseButtons
)),
1224 this, SLOT(handlePlacesClick(KUrl
, Qt::MouseButtons
)));
1225 connect(foldersPanel
, SIGNAL(changeSelection(KFileItemList
)),
1226 this, SLOT(changeSelection(KFileItemList
)));
1230 QDockWidget
* terminalDock
= new QDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1231 terminalDock
->setObjectName("terminalDock");
1232 terminalDock
->setAllowedAreas(Qt::TopDockWidgetArea
| Qt::BottomDockWidgetArea
);
1233 Panel
* terminalPanel
= new TerminalPanel(terminalDock
);
1234 terminalDock
->setWidget(terminalPanel
);
1236 connect(terminalPanel
, SIGNAL(hideTerminalPanel()), terminalDock
, SLOT(hide()));
1238 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1239 terminalAction
->setText(i18nc("@title:window Shell terminal", "Terminal"));
1240 terminalAction
->setShortcut(Qt::Key_F4
);
1241 terminalAction
->setIcon(KIcon("terminal"));
1242 actionCollection()->addAction("show_terminal_panel", terminalDock
->toggleViewAction());
1244 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1245 connect(this, SIGNAL(urlChanged(KUrl
)),
1246 terminalPanel
, SLOT(setUrl(KUrl
)));
1249 const bool firstRun
= DolphinSettings::instance().generalSettings()->firstRun();
1251 foldersDock
->hide();
1253 terminalDock
->hide();
1257 QDockWidget
* placesDock
= new QDockWidget(i18nc("@title:window", "Places"));
1258 placesDock
->setObjectName("placesDock");
1259 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1261 PlacesPanel
* placesPanel
= new PlacesPanel(placesDock
);
1262 placesDock
->setWidget(placesPanel
);
1263 placesPanel
->setModel(DolphinSettings::instance().placesModel());
1264 placesPanel
->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff
);
1266 QAction
* placesAction
= placesDock
->toggleViewAction();
1267 placesAction
->setText(i18nc("@title:window", "Places"));
1268 placesAction
->setShortcut(Qt::Key_F9
);
1269 placesAction
->setIcon(KIcon("bookmarks"));
1270 actionCollection()->addAction("show_places_panel", placesDock
->toggleViewAction());
1272 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1273 connect(placesPanel
, SIGNAL(urlChanged(KUrl
, Qt::MouseButtons
)),
1274 this, SLOT(handlePlacesClick(KUrl
, Qt::MouseButtons
)));
1275 connect(this, SIGNAL(urlChanged(KUrl
)),
1276 placesPanel
, SLOT(setUrl(KUrl
)));
1279 void DolphinMainWindow::updateEditActions()
1281 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1282 if (list
.isEmpty()) {
1283 stateChanged("has_no_selection");
1285 stateChanged("has_selection");
1287 KActionCollection
* col
= actionCollection();
1288 QAction
* renameAction
= col
->action("rename");
1289 QAction
* moveToTrashAction
= col
->action("move_to_trash");
1290 QAction
* deleteAction
= col
->action("delete");
1291 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
1292 QAction
* deleteWithTrashShortcut
= col
->action("delete_shortcut"); // see DolphinViewActionHandler
1294 KonqFileItemCapabilities
capabilities(list
);
1295 const bool enableMoveToTrash
= capabilities
.isLocal() && capabilities
.supportsMoving();
1297 renameAction
->setEnabled(capabilities
.supportsMoving());
1298 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1299 deleteAction
->setEnabled(capabilities
.supportsDeleting());
1300 deleteWithTrashShortcut
->setEnabled(capabilities
.supportsDeleting() && !enableMoveToTrash
);
1301 cutAction
->setEnabled(capabilities
.supportsMoving());
1303 updatePasteAction();
1306 void DolphinMainWindow::updateViewActions()
1308 m_actionHandler
->updateViewActions();
1310 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1311 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
1313 updateSplitAction();
1315 QAction
* editableLocactionAction
= actionCollection()->action("editable_location");
1316 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
1317 editableLocactionAction
->setChecked(urlNavigator
->isUrlEditable());
1320 void DolphinMainWindow::updateGoActions()
1322 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
1323 const KUrl
& currentUrl
= m_activeViewContainer
->url();
1324 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
1327 void DolphinMainWindow::rememberClosedTab(int index
)
1329 KMenu
* tabsMenu
= m_recentTabsMenu
->menu();
1331 const QString primaryPath
= m_viewTab
[index
].primaryView
->url().path();
1332 const QString iconName
= KMimeType::iconNameForUrl(primaryPath
);
1334 const QFontMetrics fm
= fontMetrics();
1335 const QString actionText
= fm
.elidedText(primaryPath
, Qt::ElideMiddle
, fm
.maxWidth() * 20);
1337 QAction
* action
= new QAction(actionText
, tabsMenu
);
1339 ClosedTab closedTab
;
1340 closedTab
.primaryUrl
= m_viewTab
[index
].primaryView
->url();
1342 if (m_viewTab
[index
].secondaryView
!= 0) {
1343 closedTab
.secondaryUrl
= m_viewTab
[index
].secondaryView
->url();
1344 closedTab
.isSplit
= true;
1346 closedTab
.isSplit
= false;
1349 action
->setData(QVariant::fromValue(closedTab
));
1350 action
->setIcon(KIcon(iconName
));
1352 // add the closed tab menu entry after the separator and
1353 // "Empty Recently Closed Tabs" entry
1354 if (tabsMenu
->actions().size() == 2) {
1355 tabsMenu
->addAction(action
);
1357 tabsMenu
->insertAction(tabsMenu
->actions().at(2), action
);
1359 //10 is the limit, remove the oldest one to make room. It's actually 8, since
1360 //the separator and the "Empty Recently Closed Tabs" entry count as one
1361 if (tabsMenu
->actions().size() > 8) {
1362 tabsMenu
->removeAction(tabsMenu
->actions().last());
1364 actionCollection()->action("closed_tabs")->setEnabled(true);
1365 KAcceleratorManager::manage(tabsMenu
);
1368 void DolphinMainWindow::clearStatusBar()
1370 m_activeViewContainer
->statusBar()->clear();
1373 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
1375 connect(container
, SIGNAL(showFilterBarChanged(bool)),
1376 this, SLOT(updateFilterBarAction(bool)));
1378 DolphinView
* view
= container
->view();
1379 connect(view
, SIGNAL(selectionChanged(KFileItemList
)),
1380 this, SLOT(slotSelectionChanged(KFileItemList
)));
1381 connect(view
, SIGNAL(requestItemInfo(KFileItem
)),
1382 this, SLOT(slotRequestItemInfo(KFileItem
)));
1383 connect(view
, SIGNAL(activated()),
1384 this, SLOT(toggleActiveView()));
1385 connect(view
, SIGNAL(tabRequested(const KUrl
&)),
1386 this, SLOT(openNewTab(const KUrl
&)));
1388 const KUrlNavigator
* navigator
= container
->urlNavigator();
1389 connect(navigator
, SIGNAL(urlChanged(const KUrl
&)),
1390 this, SLOT(changeUrl(const KUrl
&)));
1391 connect(navigator
, SIGNAL(historyChanged()),
1392 this, SLOT(updateHistory()));
1393 connect(navigator
, SIGNAL(editableStateChanged(bool)),
1394 this, SLOT(slotEditableStateChanged(bool)));
1397 void DolphinMainWindow::updateSplitAction()
1399 QAction
* splitAction
= actionCollection()->action("split_view");
1400 if (m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
1401 if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
1402 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
1403 splitAction
->setIcon(KIcon("view-right-close"));
1405 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
1406 splitAction
->setIcon(KIcon("view-left-close"));
1409 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
1410 splitAction
->setIcon(KIcon("view-right-new"));
1414 QString
DolphinMainWindow::tabName(const KUrl
& url
) const
1417 if (url
.equals(KUrl("file:///"))) {
1420 name
= url
.fileName();
1421 if (name
.isEmpty()) {
1422 name
= url
.protocol();
1424 // Make sure that a '&' inside the directory name is displayed correctly
1425 // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
1426 name
.replace('&', "&&");
1432 bool DolphinMainWindow::isKompareInstalled() const
1434 static bool initialized
= false;
1435 static bool installed
= false;
1437 // TODO: maybe replace this approach later by using a menu
1438 // plugin like kdiff3plugin.cpp
1439 installed
= !KGlobal::dirs()->findExe("kompare").isEmpty();
1445 void DolphinMainWindow::createSecondaryView(int tabIndex
)
1447 QSplitter
* splitter
= m_viewTab
[tabIndex
].splitter
;
1448 const int newWidth
= (m_viewTab
[tabIndex
].primaryView
->width() - splitter
->handleWidth()) / 2;
1450 const DolphinView
* view
= m_viewTab
[tabIndex
].primaryView
->view();
1451 m_viewTab
[tabIndex
].secondaryView
= new DolphinViewContainer(this, 0, view
->rootUrl());
1452 splitter
->addWidget(m_viewTab
[tabIndex
].secondaryView
);
1453 splitter
->setSizes(QList
<int>() << newWidth
<< newWidth
);
1454 connectViewSignals(m_viewTab
[tabIndex
].secondaryView
);
1455 m_viewTab
[tabIndex
].secondaryView
->view()->reload();
1456 m_viewTab
[tabIndex
].secondaryView
->setActive(false);
1457 m_viewTab
[tabIndex
].secondaryView
->show();
1460 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
1461 KIO::FileUndoManager::UiInterface()
1465 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
1469 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
1471 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
1473 DolphinStatusBar
* statusBar
= mainWin
->activeViewContainer()->statusBar();
1474 statusBar
->setMessage(job
->errorString(), DolphinStatusBar::Error
);
1476 KIO::FileUndoManager::UiInterface::jobError(job
);
1480 #include "dolphinmainwindow.moc"