]>
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 "dolphinstatusbar.h"
32 #include "dolphinviewcontainer.h"
33 #include "panels/folders/folderspanel.h"
34 #include "panels/places/placespanel.h"
35 #include "panels/information/informationpanel.h"
36 #include "panels/information/metadatawidget.h"
37 #include "mainwindowadaptor.h"
38 #include "viewproperties.h"
41 #include "panels/terminal/terminalpanel.h"
44 #include "dolphin_generalsettings.h"
45 #include "dolphin_iconsmodesettings.h"
46 #include "draganddrophelper.h"
49 #include <kactioncollection.h>
51 #include <kdesktopfile.h>
52 #include <kdeversion.h>
53 #include <kfiledialog.h>
54 #include <kfileplacesmodel.h>
56 #include <klineedit.h>
59 #include <kiconloader.h>
60 #include <kio/netaccess.h>
61 #include <kinputdialog.h>
63 #include <kprotocolmanager.h>
66 #include <kmessagebox.h>
67 #include <konq_fileitemcapabilities.h>
68 #include <konqmimedata.h>
69 #include <kprotocolinfo.h>
72 #include <kstandarddirs.h>
73 #include <kstatusbar.h>
74 #include <kstandardaction.h>
76 #include <ktoggleaction.h>
77 #include <kurlnavigator.h>
79 #include <kurlcombobox.h>
81 #include <QDBusMessage>
86 #include <QDockWidget>
88 DolphinMainWindow::DolphinMainWindow(int id
) :
93 m_activeViewContainer(0),
94 m_centralWidgetLayout(0),
102 setObjectName("Dolphin#");
104 m_viewTab
.append(ViewTab());
106 new MainWindowAdaptor(this);
107 QDBusConnection::sessionBus().registerObject(QString("/dolphin/MainWindow%1").arg(m_id
), this);
109 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
110 undoManager
->setUiInterface(new UndoUiInterface());
112 connect(undoManager
, SIGNAL(undoAvailable(bool)),
113 this, SLOT(slotUndoAvailable(bool)));
114 connect(undoManager
, SIGNAL(undoTextChanged(const QString
&)),
115 this, SLOT(slotUndoTextChanged(const QString
&)));
116 connect(undoManager
, SIGNAL(jobRecordingStarted(CommandType
)),
117 this, SLOT(clearStatusBar()));
118 connect(undoManager
, SIGNAL(jobRecordingFinished(CommandType
)),
119 this, SLOT(showCommand(CommandType
)));
120 connect(DolphinSettings::instance().placesModel(), SIGNAL(errorMessage(const QString
&)),
121 this, SLOT(showErrorMessage(const QString
&)));
122 connect(&DragAndDropHelper::instance(), SIGNAL(errorMessage(const QString
&)),
123 this, SLOT(showErrorMessage(const QString
&)));
126 DolphinMainWindow::~DolphinMainWindow()
128 DolphinApplication::app()->removeMainWindow(this);
131 void DolphinMainWindow::toggleViews()
133 if (m_viewTab
[m_tabIndex
].primaryView
== 0) {
137 // move secondary view from the last position of the splitter
138 // to the first position
139 m_viewTab
[m_tabIndex
].splitter
->insertWidget(0, m_viewTab
[m_tabIndex
].secondaryView
);
141 DolphinViewContainer
* container
= m_viewTab
[m_tabIndex
].primaryView
;
142 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
143 m_viewTab
[m_tabIndex
].secondaryView
= container
;
146 void DolphinMainWindow::showCommand(CommandType command
)
148 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
150 case KIO::FileUndoManager::Copy
:
151 statusBar
->setMessage(i18nc("@info:status", "Copy operation completed."),
152 DolphinStatusBar::OperationCompleted
);
154 case KIO::FileUndoManager::Move
:
155 statusBar
->setMessage(i18nc("@info:status", "Move operation completed."),
156 DolphinStatusBar::OperationCompleted
);
158 case KIO::FileUndoManager::Link
:
159 statusBar
->setMessage(i18nc("@info:status", "Link operation completed."),
160 DolphinStatusBar::OperationCompleted
);
162 case KIO::FileUndoManager::Trash
:
163 statusBar
->setMessage(i18nc("@info:status", "Move to trash operation completed."),
164 DolphinStatusBar::OperationCompleted
);
166 case KIO::FileUndoManager::Rename
:
167 statusBar
->setMessage(i18nc("@info:status", "Renaming operation completed."),
168 DolphinStatusBar::OperationCompleted
);
171 case KIO::FileUndoManager::Mkdir
:
172 statusBar
->setMessage(i18nc("@info:status", "Created folder."),
173 DolphinStatusBar::OperationCompleted
);
181 void DolphinMainWindow::refreshViews()
183 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
185 // remember the current active view, as because of
186 // the refreshing the active view might change to
187 // the secondary view
188 DolphinViewContainer
* activeViewContainer
= m_activeViewContainer
;
190 const int tabCount
= m_viewTab
.count();
191 for (int i
= 0; i
< tabCount
; ++i
) {
192 m_viewTab
[i
].primaryView
->refresh();
193 if (m_viewTab
[i
].secondaryView
!= 0) {
194 m_viewTab
[i
].secondaryView
->refresh();
198 setActiveViewContainer(activeViewContainer
);
201 void DolphinMainWindow::pasteIntoFolder()
203 m_activeViewContainer
->view()->pasteIntoFolder();
206 void DolphinMainWindow::changeUrl(const KUrl
& url
)
208 if (!KProtocolManager::supportsListing(url
)) {
209 // The URL navigator only checks for validity, not
210 // if the URL can be listed. An error message is
211 // shown due to DolphinViewContainer::restoreView().
215 DolphinViewContainer
* view
= activeViewContainer();
221 setCaption(url
.fileName());
222 if (m_viewTab
.count() > 1) {
223 m_tabBar
->setTabText(m_tabIndex
, tabName(url
));
225 emit
urlChanged(url
);
229 void DolphinMainWindow::changeSelection(const KFileItemList
& selection
)
231 activeViewContainer()->view()->changeSelection(selection
);
234 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
236 KToggleAction
* editableLocationAction
=
237 static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
238 editableLocationAction
->setChecked(editable
);
241 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
245 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
246 int selectedUrlsCount
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedItemsCount();
247 if (m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
248 selectedUrlsCount
+= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItemsCount();
251 QAction
* compareFilesAction
= actionCollection()->action("compare_files");
252 if (selectedUrlsCount
== 2) {
253 compareFilesAction
->setEnabled(isKompareInstalled());
255 compareFilesAction
->setEnabled(false);
258 #if defined(QUICK_VIEW)
259 const bool activeViewHasSelection
= (activeViewContainer()->view()->selectedItemsCount() > 0);
260 actionCollection()->action("quick_view")->setEnabled(activeViewHasSelection
);
263 m_activeViewContainer
->updateStatusBar();
265 emit
selectionChanged(selection
);
268 void DolphinMainWindow::slotRequestItemInfo(const KFileItem
& item
)
270 emit
requestItemInfo(item
);
273 void DolphinMainWindow::updateHistory()
275 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
276 const int index
= urlNavigator
->historyIndex();
278 QAction
* backAction
= actionCollection()->action("go_back");
279 if (backAction
!= 0) {
280 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
283 QAction
* forwardAction
= actionCollection()->action("go_forward");
284 if (forwardAction
!= 0) {
285 forwardAction
->setEnabled(index
> 0);
289 void DolphinMainWindow::updateFilterBarAction(bool show
)
291 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
292 showFilterBarAction
->setChecked(show
);
295 void DolphinMainWindow::openNewMainWindow()
297 DolphinApplication::app()->createMainWindow()->show();
300 void DolphinMainWindow::openNewTab()
302 openNewTab(m_activeViewContainer
->url());
303 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
305 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
306 if (navigator
->isUrlEditable()) {
307 // if a new tab is opened and the URL is editable, assure that
308 // the user can edit the URL without manually setting the focus
309 navigator
->setFocus();
313 void DolphinMainWindow::openNewTab(const KUrl
& url
)
315 if (m_viewTab
.count() == 1) {
316 // Only one view is open currently and hence no tab is shown at
317 // all. Before creating a tab for 'url', provide a tab for the current URL.
318 m_tabBar
->addTab(KIcon("folder"), tabName(m_activeViewContainer
->url()));
319 m_tabBar
->blockSignals(false);
322 m_tabBar
->addTab(KIcon("folder"), tabName(url
));
325 viewTab
.splitter
= new QSplitter(this);
326 viewTab
.primaryView
= new DolphinViewContainer(this, viewTab
.splitter
, url
);
327 viewTab
.primaryView
->setActive(false);
328 connectViewSignals(viewTab
.primaryView
);
329 viewTab
.primaryView
->view()->reload();
331 m_viewTab
.append(viewTab
);
333 actionCollection()->action("close_tab")->setEnabled(true);
335 // provide a split view, if the startup settings are set this way
336 const GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
337 if (generalSettings
->splitView()) {
338 const int tabIndex
= m_viewTab
.count() - 1;
339 createSecondaryView(tabIndex
);
340 m_viewTab
[tabIndex
].secondaryView
->setActive(true);
341 m_viewTab
[tabIndex
].isPrimaryViewActive
= false;
345 void DolphinMainWindow::activateNextTab()
347 if (m_viewTab
.count() == 1 || m_tabBar
->count() < 2) {
351 const int tabIndex
= (m_tabBar
->currentIndex() + 1) % m_tabBar
->count();
352 m_tabBar
->setCurrentIndex(tabIndex
);
355 void DolphinMainWindow::activatePrevTab()
357 if (m_viewTab
.count() == 1 || m_tabBar
->count() < 2) {
361 int tabIndex
= m_tabBar
->currentIndex() - 1;
362 if (tabIndex
== -1) {
363 tabIndex
= m_tabBar
->count() - 1;
365 m_tabBar
->setCurrentIndex(tabIndex
);
368 void DolphinMainWindow::openInNewTab()
370 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
371 if ((list
.count() == 1) && list
[0].isDir()) {
372 openNewTab(m_activeViewContainer
->view()->selectedUrls()[0]);
376 void DolphinMainWindow::openInNewWindow()
378 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
379 if ((list
.count() == 1) && list
[0].isDir()) {
380 DolphinMainWindow
* window
= DolphinApplication::app()->createMainWindow();
381 window
->changeUrl(m_activeViewContainer
->view()->selectedUrls()[0]);
386 void DolphinMainWindow::toggleActiveView()
388 if (m_viewTab
[m_tabIndex
].secondaryView
== 0) {
389 // only one view is available
393 Q_ASSERT(m_activeViewContainer
!= 0);
394 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
396 DolphinViewContainer
* left
= m_viewTab
[m_tabIndex
].primaryView
;
397 DolphinViewContainer
* right
= m_viewTab
[m_tabIndex
].secondaryView
;
398 setActiveViewContainer(m_activeViewContainer
== right
? left
: right
);
401 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
403 DolphinSettings
& settings
= DolphinSettings::instance();
404 GeneralSettings
* generalSettings
= settings
.generalSettings();
405 generalSettings
->setFirstRun(false);
409 KXmlGuiWindow::closeEvent(event
);
412 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
414 // TODO: remember tabs
415 DolphinViewContainer
* cont
= m_viewTab
[m_tabIndex
].primaryView
;
416 group
.writeEntry("Primary Url", cont
->url().url());
417 group
.writeEntry("Primary Editable Url", cont
->isUrlEditable());
419 cont
= m_viewTab
[m_tabIndex
].secondaryView
;
421 group
.writeEntry("Secondary Url", cont
->url().url());
422 group
.writeEntry("Secondary Editable Url", cont
->isUrlEditable());
426 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
429 DolphinViewContainer
* cont
= m_viewTab
[m_tabIndex
].primaryView
;
431 cont
->setUrl(group
.readEntry("Primary Url"));
432 bool editable
= group
.readEntry("Primary Editable Url", false);
433 cont
->urlNavigator()->setUrlEditable(editable
);
435 cont
= m_viewTab
[m_tabIndex
].secondaryView
;
436 const QString secondaryUrl
= group
.readEntry("Secondary Url");
437 if (!secondaryUrl
.isEmpty()) {
439 // a secondary view should be shown, but no one is available
440 // currently -> create a new view
442 cont
= m_viewTab
[m_tabIndex
].secondaryView
;
446 cont
->setUrl(secondaryUrl
);
447 bool editable
= group
.readEntry("Secondary Editable Url", false);
448 cont
->urlNavigator()->setUrlEditable(editable
);
449 } else if (cont
!= 0) {
450 // no secondary view should be shown, but the default setting shows
451 // one already -> close the view
456 void DolphinMainWindow::updateNewMenu()
458 m_newMenu
->slotCheckUpToDate();
459 m_newMenu
->setPopupFiles(activeViewContainer()->url());
462 void DolphinMainWindow::quit()
467 void DolphinMainWindow::showErrorMessage(const QString
& message
)
469 if (!message
.isEmpty()) {
470 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
471 statusBar
->setMessage(message
, DolphinStatusBar::Error
);
475 void DolphinMainWindow::slotUndoAvailable(bool available
)
477 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
478 if (undoAction
!= 0) {
479 undoAction
->setEnabled(available
);
483 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
485 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
486 if (undoAction
!= 0) {
487 undoAction
->setText(text
);
491 void DolphinMainWindow::undo()
494 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
495 KIO::FileUndoManager::self()->undo();
498 void DolphinMainWindow::cut()
500 m_activeViewContainer
->view()->cutSelectedItems();
503 void DolphinMainWindow::copy()
505 m_activeViewContainer
->view()->copySelectedItems();
508 void DolphinMainWindow::paste()
510 m_activeViewContainer
->view()->paste();
513 void DolphinMainWindow::updatePasteAction()
515 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
516 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
517 pasteAction
->setEnabled(pasteInfo
.first
);
518 pasteAction
->setText(pasteInfo
.second
);
521 void DolphinMainWindow::selectAll()
525 // if the URL navigator is editable and focused, select the whole
526 // URL instead of all items of the view
528 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
529 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit();
530 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
531 lineEdit
->hasFocus();
533 lineEdit
->selectAll();
535 m_activeViewContainer
->view()->selectAll();
539 void DolphinMainWindow::invertSelection()
542 m_activeViewContainer
->view()->invertSelection();
545 void DolphinMainWindow::toggleSplitView()
547 if (m_viewTab
[m_tabIndex
].secondaryView
== 0) {
548 createSecondaryView(m_tabIndex
);
549 setActiveViewContainer(m_viewTab
[m_tabIndex
].secondaryView
);
550 } else if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
551 // remove secondary view
552 m_viewTab
[m_tabIndex
].secondaryView
->close();
553 m_viewTab
[m_tabIndex
].secondaryView
->deleteLater();
554 m_viewTab
[m_tabIndex
].secondaryView
= 0;
556 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
558 // The primary view is active and should be closed. Hence from a users point of view
559 // the content of the secondary view should be moved to the primary view.
560 // From an implementation point of view it is more efficient to close
561 // the primary view and exchange the internal pointers afterwards.
563 m_viewTab
[m_tabIndex
].primaryView
->close();
564 m_viewTab
[m_tabIndex
].primaryView
->deleteLater();
565 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
566 m_viewTab
[m_tabIndex
].secondaryView
= 0;
568 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
574 void DolphinMainWindow::reloadView()
577 m_activeViewContainer
->view()->reload();
580 void DolphinMainWindow::stopLoading()
584 void DolphinMainWindow::toggleFilterBarVisibility(bool show
)
586 m_activeViewContainer
->showFilterBar(show
);
589 void DolphinMainWindow::toggleEditLocation()
593 QAction
* action
= actionCollection()->action("editable_location");
594 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
595 urlNavigator
->setUrlEditable(action
->isChecked());
598 void DolphinMainWindow::replaceLocation()
600 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
601 navigator
->setUrlEditable(true);
602 navigator
->setFocus();
604 // select the whole text of the combo box editor
605 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit();
606 const QString text
= lineEdit
->text();
607 lineEdit
->setSelection(0, text
.length());
610 void DolphinMainWindow::goBack()
613 m_activeViewContainer
->urlNavigator()->goBack();
616 void DolphinMainWindow::goForward()
619 m_activeViewContainer
->urlNavigator()->goForward();
622 void DolphinMainWindow::goUp()
625 m_activeViewContainer
->urlNavigator()->goUp();
628 void DolphinMainWindow::goHome()
631 m_activeViewContainer
->urlNavigator()->goHome();
634 void DolphinMainWindow::compareFiles()
636 // The method is only invoked if exactly 2 files have
637 // been selected. The selected files may be:
638 // - both in the primary view
639 // - both in the secondary view
640 // - one in the primary view and the other in the secondary
642 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
646 KUrl::List urls
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedUrls();
648 switch (urls
.count()) {
650 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
!= 0);
651 urls
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedUrls();
652 Q_ASSERT(urls
.count() == 2);
660 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
!= 0);
661 urls
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedUrls();
662 Q_ASSERT(urls
.count() == 1);
674 // may not happen: compareFiles may only get invoked if 2
675 // files are selected
680 QString
command("kompare -c \"");
681 command
.append(urlA
.pathOrUrl());
682 command
.append("\" \"");
683 command
.append(urlB
.pathOrUrl());
684 command
.append('\"');
685 KRun::runCommand(command
, "Kompare", "kompare", this);
688 void DolphinMainWindow::quickView()
690 const KUrl::List urls
= activeViewContainer()->view()->selectedUrls();
691 Q_ASSERT(urls
.count() > 0);
693 QDBusMessage msg
= QDBusMessage::createMethodCall("org.kde.plasma", "/Previewer", "", "openFile");
694 foreach (const KUrl
& url
, urls
) {
695 msg
.setArguments(QList
<QVariant
>() << url
.prettyUrl());
696 QDBusConnection::sessionBus().send(msg
);
700 void DolphinMainWindow::toggleShowMenuBar()
702 const bool visible
= menuBar()->isVisible();
703 menuBar()->setVisible(!visible
);
706 void DolphinMainWindow::editSettings()
708 if (m_settingsDialog
== 0) {
709 const KUrl
& url
= activeViewContainer()->url();
710 m_settingsDialog
= new DolphinSettingsDialog(url
, this);
711 m_settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
712 m_settingsDialog
->show();
714 m_settingsDialog
->raise();
718 void DolphinMainWindow::setActiveTab(int index
)
720 Q_ASSERT(index
>= 0);
721 Q_ASSERT(index
< m_viewTab
.count());
722 if (index
== m_tabIndex
) {
726 // hide current tab content
727 ViewTab
& hiddenTab
= m_viewTab
[m_tabIndex
];
728 hiddenTab
.isPrimaryViewActive
= hiddenTab
.primaryView
->isActive();
729 hiddenTab
.primaryView
->setActive(false);
730 if (hiddenTab
.secondaryView
!= 0) {
731 hiddenTab
.secondaryView
->setActive(false);
733 QSplitter
* splitter
= m_viewTab
[m_tabIndex
].splitter
;
735 m_centralWidgetLayout
->removeWidget(splitter
);
737 // show active tab content
740 ViewTab
& viewTab
= m_viewTab
[index
];
741 m_centralWidgetLayout
->addWidget(viewTab
.splitter
);
742 viewTab
.primaryView
->show();
743 if (viewTab
.secondaryView
!= 0) {
744 viewTab
.secondaryView
->show();
746 viewTab
.splitter
->show();
748 setActiveViewContainer(viewTab
.isPrimaryViewActive
? viewTab
.primaryView
:
749 viewTab
.secondaryView
);
752 void DolphinMainWindow::closeTab()
754 closeTab(m_tabBar
->currentIndex());
757 void DolphinMainWindow::closeTab(int index
)
759 Q_ASSERT(index
>= 0);
760 Q_ASSERT(index
< m_viewTab
.count());
761 if (m_viewTab
.count() == 1) {
762 // the last tab may never get closed
766 if (index
== m_tabIndex
) {
767 // The tab that should be closed is the active tab. Activate the
768 // previous tab before closing the tab.
769 m_tabBar
->setCurrentIndex((index
> 0) ? index
- 1 : 1);
773 m_viewTab
[index
].primaryView
->deleteLater();
774 if (m_viewTab
[index
].secondaryView
!= 0) {
775 m_viewTab
[index
].secondaryView
->deleteLater();
777 m_viewTab
[index
].splitter
->deleteLater();
778 m_viewTab
.erase(m_viewTab
.begin() + index
);
780 m_tabBar
->blockSignals(true);
781 m_tabBar
->removeTab(index
);
783 if (m_tabIndex
> index
) {
785 Q_ASSERT(m_tabIndex
>= 0);
788 // if only one tab is left, also remove the tab entry so that
789 // closing the last tab is not possible
790 if (m_viewTab
.count() == 1) {
791 m_tabBar
->removeTab(0);
792 actionCollection()->action("close_tab")->setEnabled(false);
794 m_tabBar
->blockSignals(false);
798 void DolphinMainWindow::openTabContextMenu(int index
, const QPoint
& pos
)
802 QAction
* newTabAction
= menu
.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab"));
803 newTabAction
->setShortcut(actionCollection()->action("new_tab")->shortcut());
805 QAction
* closeOtherTabsAction
= menu
.addAction(KIcon("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs"));
807 QAction
* closeTabAction
= menu
.addAction(KIcon("tab-close"), i18nc("@action:inmenu", "Close Tab"));
808 closeTabAction
->setShortcut(actionCollection()->action("close_tab")->shortcut());
810 QAction
* selectedAction
= menu
.exec(pos
);
811 if (selectedAction
== newTabAction
) {
812 const ViewTab
& tab
= m_viewTab
[index
];
813 Q_ASSERT(tab
.primaryView
!= 0);
814 const KUrl url
= (tab
.secondaryView
!= 0) && tab
.secondaryView
->isActive() ?
815 tab
.secondaryView
->url() : tab
.primaryView
->url();
817 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
818 } else if (selectedAction
== closeOtherTabsAction
) {
819 const int count
= m_tabBar
->count();
820 for (int i
= 0; i
< index
; ++i
) {
823 for (int i
= index
+ 1; i
< count
; ++i
) {
826 } else if (selectedAction
== closeTabAction
) {
831 void DolphinMainWindow::handlePlacesClick(const KUrl
& url
, Qt::MouseButtons buttons
)
833 if (buttons
& Qt::MidButton
) {
835 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
841 void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent
* event
, bool& canDecode
)
843 canDecode
= KUrl::List::canDecode(event
->mimeData());
846 void DolphinMainWindow::searchItems()
848 const QString nepomukString
= "nepomuksearch:/" + m_searchBar
->text();
849 m_activeViewContainer
->setUrl(KUrl(nepomukString
));
853 void DolphinMainWindow::init()
855 DolphinSettings
& settings
= DolphinSettings::instance();
857 // Check whether Dolphin runs the first time. If yes then
858 // a proper default window size is given at the end of DolphinMainWindow::init().
859 GeneralSettings
* generalSettings
= settings
.generalSettings();
860 const bool firstRun
= generalSettings
->firstRun();
862 generalSettings
->setViewPropsTimestamp(QDateTime::currentDateTime());
865 setAcceptDrops(true);
867 m_viewTab
[m_tabIndex
].splitter
= new QSplitter(this);
871 const KUrl
& homeUrl
= generalSettings
->homeUrl();
872 setCaption(homeUrl
.fileName());
873 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
874 connect(m_actionHandler
, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
875 ViewProperties
props(homeUrl
);
876 m_viewTab
[m_tabIndex
].primaryView
= new DolphinViewContainer(this,
877 m_viewTab
[m_tabIndex
].splitter
,
880 m_activeViewContainer
= m_viewTab
[m_tabIndex
].primaryView
;
881 connectViewSignals(m_activeViewContainer
);
882 DolphinView
* view
= m_activeViewContainer
->view();
884 m_activeViewContainer
->show();
885 m_actionHandler
->setCurrentView(view
);
887 m_tabBar
= new KTabBar(this);
888 m_tabBar
->setCloseButtonEnabled(true);
889 connect(m_tabBar
, SIGNAL(currentChanged(int)),
890 this, SLOT(setActiveTab(int)));
891 connect(m_tabBar
, SIGNAL(closeRequest(int)),
892 this, SLOT(closeTab(int)));
893 connect(m_tabBar
, SIGNAL(contextMenu(int, const QPoint
&)),
894 this, SLOT(openTabContextMenu(int, const QPoint
&)));
895 connect(m_tabBar
, SIGNAL(newTabRequest()),
896 this, SLOT(openNewTab()));
897 connect(m_tabBar
, SIGNAL(testCanDecode(const QDragMoveEvent
*, bool&)),
898 this, SLOT(slotTestCanDecode(const QDragMoveEvent
*, bool&)));
899 m_tabBar
->blockSignals(true); // signals get unblocked after at least 2 tabs are open
901 QWidget
* centralWidget
= new QWidget(this);
902 m_centralWidgetLayout
= new QVBoxLayout(centralWidget
);
903 m_centralWidgetLayout
->setSpacing(0);
904 m_centralWidgetLayout
->setMargin(0);
905 m_centralWidgetLayout
->addWidget(m_tabBar
);
906 m_centralWidgetLayout
->addWidget(m_viewTab
[m_tabIndex
].splitter
);
908 setCentralWidget(centralWidget
);
910 emit
urlChanged(homeUrl
);
912 setupGUI(Keys
| Save
| Create
| ToolBar
);
914 m_searchBar
->setParent(toolBar("searchToolBar"));
915 m_searchBar
->setFont(KGlobalSettings::generalFont());
918 stateChanged("new_file");
920 QClipboard
* clipboard
= QApplication::clipboard();
921 connect(clipboard
, SIGNAL(dataChanged()),
922 this, SLOT(updatePasteAction()));
926 if (generalSettings
->splitView()) {
931 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
932 showFilterBarAction
->setChecked(generalSettings
->filterBar());
935 // assure a proper default size if Dolphin runs the first time
939 m_showMenuBar
->setChecked(!menuBar()->isHidden()); // workaround for bug #171080
942 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer
* viewContainer
)
944 Q_ASSERT(viewContainer
!= 0);
945 Q_ASSERT((viewContainer
== m_viewTab
[m_tabIndex
].primaryView
) ||
946 (viewContainer
== m_viewTab
[m_tabIndex
].secondaryView
));
947 if (m_activeViewContainer
== viewContainer
) {
951 m_activeViewContainer
->setActive(false);
952 m_activeViewContainer
= viewContainer
;
954 // Activating the view container might trigger a recursive setActiveViewContainer() call
955 // inside DolphinMainWindow::toggleActiveView() when having a split view. Temporary
956 // disconnect the activated() signal in this case:
957 disconnect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
958 m_activeViewContainer
->setActive(true);
959 connect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
961 m_actionHandler
->setCurrentView(viewContainer
->view());
968 const KUrl
& url
= m_activeViewContainer
->url();
969 setCaption(url
.fileName());
970 if (m_viewTab
.count() > 1) {
971 m_tabBar
->setTabText(m_tabIndex
, tabName(url
));
974 emit
urlChanged(url
);
977 void DolphinMainWindow::setupActions()
980 m_newMenu
= new DolphinNewMenu(this, this);
981 KMenu
* menu
= m_newMenu
->menu();
982 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
983 menu
->setIcon(KIcon("document-new"));
984 connect(menu
, SIGNAL(aboutToShow()),
985 this, SLOT(updateNewMenu()));
987 KAction
* newWindow
= actionCollection()->addAction("new_window");
988 newWindow
->setIcon(KIcon("window-new"));
989 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
990 newWindow
->setShortcut(Qt::CTRL
| Qt::Key_N
);
991 connect(newWindow
, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
993 KAction
* newTab
= actionCollection()->addAction("new_tab");
994 newTab
->setIcon(KIcon("tab-new"));
995 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
996 newTab
->setShortcut(KShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
, Qt::CTRL
| Qt::Key_T
));
997 connect(newTab
, SIGNAL(triggered()), this, SLOT(openNewTab()));
999 QAction
* closeTab
= actionCollection()->addAction("close_tab");
1000 closeTab
->setIcon(KIcon("tab-close"));
1001 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1002 closeTab
->setShortcut(Qt::CTRL
| Qt::Key_W
);
1003 closeTab
->setEnabled(false);
1004 connect(closeTab
, SIGNAL(triggered()), this, SLOT(closeTab()));
1006 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1008 // setup 'Edit' menu
1009 KStandardAction::undo(this,
1011 actionCollection());
1013 // need to remove shift+del from cut action, else the shortcut for deletejob
1015 KAction
* cut
= KStandardAction::cut(this, SLOT(cut()), actionCollection());
1016 KShortcut cutShortcut
= cut
->shortcut();
1017 cutShortcut
.remove(Qt::SHIFT
+ Qt::Key_Delete
, KShortcut::KeepEmpty
);
1018 cut
->setShortcut(cutShortcut
);
1019 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1020 KStandardAction::paste(this, SLOT(paste()), actionCollection());
1022 KAction
* selectAll
= actionCollection()->addAction("select_all");
1023 selectAll
->setText(i18nc("@action:inmenu Edit", "Select All"));
1024 selectAll
->setShortcut(Qt::CTRL
+ Qt::Key_A
);
1025 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
1027 KAction
* invertSelection
= actionCollection()->addAction("invert_selection");
1028 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1029 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1030 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
1032 // setup 'View' menu
1033 // (note that most of it is set up in DolphinViewActionHandler)
1035 KAction
* split
= actionCollection()->addAction("split_view");
1036 split
->setShortcut(Qt::Key_F3
);
1037 updateSplitAction();
1038 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1040 KAction
* reload
= actionCollection()->addAction("reload");
1041 reload
->setText(i18nc("@action:inmenu View", "Reload"));
1042 reload
->setShortcut(Qt::Key_F5
);
1043 reload
->setIcon(KIcon("view-refresh"));
1044 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
1046 KAction
* stop
= actionCollection()->addAction("stop");
1047 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1048 stop
->setIcon(KIcon("process-stop"));
1049 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
1051 KToggleAction
* showFullLocation
= actionCollection()->add
<KToggleAction
>("editable_location");
1052 showFullLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1053 showFullLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
1054 connect(showFullLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1056 KAction
* replaceLocation
= actionCollection()->addAction("replace_location");
1057 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1058 replaceLocation
->setShortcut(Qt::Key_F6
);
1059 connect(replaceLocation
, SIGNAL(triggered()), this, SLOT(replaceLocation()));
1062 KAction
* backAction
= KStandardAction::back(this, SLOT(goBack()), actionCollection());
1063 KShortcut backShortcut
= backAction
->shortcut();
1064 backShortcut
.setAlternate(Qt::Key_Backspace
);
1065 backAction
->setShortcut(backShortcut
);
1067 KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1068 KStandardAction::up(this, SLOT(goUp()), actionCollection());
1069 KStandardAction::home(this, SLOT(goHome()), actionCollection());
1071 // setup 'Tools' menu
1072 KToggleAction
* showSearchBar
= actionCollection()->add
<KToggleAction
>("show_search_bar");
1073 showSearchBar
->setText(i18nc("@action:inmenu Tools", "Show Search Bar"));
1074 showSearchBar
->setShortcut(Qt::CTRL
| Qt::Key_S
);
1075 connect(showSearchBar
, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
1077 KToggleAction
* showFilterBar
= actionCollection()->add
<KToggleAction
>("show_filter_bar");
1078 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1079 showFilterBar
->setShortcut(Qt::CTRL
| Qt::Key_I
);
1080 connect(showFilterBar
, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
1082 KAction
* compareFiles
= actionCollection()->addAction("compare_files");
1083 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1084 compareFiles
->setIcon(KIcon("kompare"));
1085 compareFiles
->setEnabled(false);
1086 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
1088 // disabled Quick View
1089 #if defined(QUICK_VIEW)
1090 KAction
* quickView
= actionCollection()->addAction("quick_view");
1091 quickView
->setText(i18nc("@action:inmenu Tools", "Quick View"));
1092 quickView
->setIcon(KIcon("view-preview"));
1093 quickView
->setShortcut(Qt::CTRL
+ Qt::Key_Return
);
1094 quickView
->setEnabled(false);
1095 connect(quickView
, SIGNAL(triggered()), this, SLOT(quickView()));
1098 // setup 'Settings' menu
1099 m_showMenuBar
= KStandardAction::showMenubar(this, SLOT(toggleShowMenuBar()), actionCollection());
1100 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1102 // not in menu actions
1103 KAction
* activateNextTab
= actionCollection()->addAction("activate_next_tab");
1104 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1105 connect(activateNextTab
, SIGNAL(triggered()), SLOT(activateNextTab()));
1106 activateNextTab
->setShortcuts(QApplication::isRightToLeft() ? KStandardShortcut::tabPrev() :
1107 KStandardShortcut::tabNext());
1109 KAction
* activatePrevTab
= actionCollection()->addAction("activate_prev_tab");
1110 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1111 connect(activatePrevTab
, SIGNAL(triggered()), SLOT(activatePrevTab()));
1112 activatePrevTab
->setShortcuts(QApplication::isRightToLeft() ? KStandardShortcut::tabNext() :
1113 KStandardShortcut::tabPrev());
1116 KAction
* openInNewTab
= actionCollection()->addAction("open_in_new_tab");
1117 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1118 openInNewTab
->setIcon(KIcon("tab-new"));
1119 connect(openInNewTab
, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1121 KAction
* openInNewWindow
= actionCollection()->addAction("open_in_new_window");
1122 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1123 openInNewWindow
->setIcon(KIcon("window-new"));
1124 connect(openInNewWindow
, SIGNAL(triggered()), this, SLOT(openInNewWindow()));
1127 m_searchBar
= new KLineEdit(this);
1128 m_searchBar
->setMinimumWidth(150);
1129 m_searchBar
->setClearButtonShown(true);
1130 connect(m_searchBar
, SIGNAL(returnPressed()), this, SLOT(searchItems()));
1132 KAction
* search
= new KAction(this);
1133 actionCollection()->addAction("search_bar", search
);
1134 search
->setText(i18nc("@action:inmenu", "Search Bar"));
1135 search
->setDefaultWidget(m_searchBar
);
1136 search
->setShortcutConfigurable(false);
1139 void DolphinMainWindow::setupDockWidgets()
1141 // setup "Information"
1142 QDockWidget
* infoDock
= new QDockWidget(i18nc("@title:window", "Information"));
1143 infoDock
->setObjectName("infoDock");
1144 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1145 Panel
* infoPanel
= new InformationPanel(infoDock
);
1146 infoDock
->setWidget(infoPanel
);
1148 QAction
* infoAction
= infoDock
->toggleViewAction();
1149 infoAction
->setText(i18nc("@title:window", "Information"));
1150 infoAction
->setShortcut(Qt::Key_F11
);
1151 infoAction
->setIcon(KIcon("dialog-information"));
1152 actionCollection()->addAction("show_info_panel", infoDock
->toggleViewAction());
1154 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1155 connect(this, SIGNAL(urlChanged(KUrl
)),
1156 infoPanel
, SLOT(setUrl(KUrl
)));
1157 connect(this, SIGNAL(selectionChanged(KFileItemList
)),
1158 infoPanel
, SLOT(setSelection(KFileItemList
)));
1159 connect(this, SIGNAL(requestItemInfo(KFileItem
)),
1160 infoPanel
, SLOT(requestDelayedItemInfo(KFileItem
)));
1163 QDockWidget
* foldersDock
= new QDockWidget(i18nc("@title:window", "Folders"));
1164 foldersDock
->setObjectName("foldersDock");
1165 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1166 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1167 foldersDock
->setWidget(foldersPanel
);
1169 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1170 foldersAction
->setText(i18nc("@title:window", "Folders"));
1171 foldersAction
->setShortcut(Qt::Key_F7
);
1172 foldersAction
->setIcon(KIcon("folder"));
1173 actionCollection()->addAction("show_folders_panel", foldersDock
->toggleViewAction());
1175 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1176 connect(this, SIGNAL(urlChanged(KUrl
)),
1177 foldersPanel
, SLOT(setUrl(KUrl
)));
1178 connect(foldersPanel
, SIGNAL(changeUrl(KUrl
, Qt::MouseButtons
)),
1179 this, SLOT(handlePlacesClick(KUrl
, Qt::MouseButtons
)));
1180 connect(foldersPanel
, SIGNAL(changeSelection(KFileItemList
)),
1181 this, SLOT(changeSelection(KFileItemList
)));
1185 QDockWidget
* terminalDock
= new QDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1186 terminalDock
->setObjectName("terminalDock");
1187 terminalDock
->setAllowedAreas(Qt::TopDockWidgetArea
| Qt::BottomDockWidgetArea
);
1188 Panel
* terminalPanel
= new TerminalPanel(terminalDock
);
1189 terminalDock
->setWidget(terminalPanel
);
1191 connect(terminalPanel
, SIGNAL(hideTerminalPanel()), terminalDock
, SLOT(hide()));
1193 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1194 terminalAction
->setText(i18nc("@title:window Shell terminal", "Terminal"));
1195 terminalAction
->setShortcut(Qt::Key_F4
);
1196 terminalAction
->setIcon(KIcon("terminal"));
1197 actionCollection()->addAction("show_terminal_panel", terminalDock
->toggleViewAction());
1199 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1200 connect(this, SIGNAL(urlChanged(KUrl
)),
1201 terminalPanel
, SLOT(setUrl(KUrl
)));
1204 const bool firstRun
= DolphinSettings::instance().generalSettings()->firstRun();
1206 foldersDock
->hide();
1208 terminalDock
->hide();
1212 QDockWidget
* placesDock
= new QDockWidget(i18nc("@title:window", "Places"));
1213 placesDock
->setObjectName("placesDock");
1214 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1216 PlacesPanel
* placesPanel
= new PlacesPanel(placesDock
);
1217 placesDock
->setWidget(placesPanel
);
1218 placesPanel
->setModel(DolphinSettings::instance().placesModel());
1219 placesPanel
->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff
);
1221 QAction
* placesAction
= placesDock
->toggleViewAction();
1222 placesAction
->setText(i18nc("@title:window", "Places"));
1223 placesAction
->setShortcut(Qt::Key_F9
);
1224 placesAction
->setIcon(KIcon("bookmarks"));
1225 actionCollection()->addAction("show_places_panel", placesDock
->toggleViewAction());
1227 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1228 connect(placesPanel
, SIGNAL(urlChanged(KUrl
, Qt::MouseButtons
)),
1229 this, SLOT(handlePlacesClick(KUrl
, Qt::MouseButtons
)));
1230 connect(this, SIGNAL(urlChanged(KUrl
)),
1231 placesPanel
, SLOT(setUrl(KUrl
)));
1234 void DolphinMainWindow::updateEditActions()
1236 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1237 if (list
.isEmpty()) {
1238 stateChanged("has_no_selection");
1240 stateChanged("has_selection");
1242 KActionCollection
* col
= actionCollection();
1243 QAction
* renameAction
= col
->action("rename");
1244 QAction
* moveToTrashAction
= col
->action("move_to_trash");
1245 QAction
* deleteAction
= col
->action("delete");
1246 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
1247 QAction
* deleteWithTrashShortcut
= col
->action("delete_shortcut"); // see DolphinViewActionHandler
1249 KonqFileItemCapabilities
capabilities(list
);
1250 const bool enableMoveToTrash
= capabilities
.isLocal() && capabilities
.supportsMoving();
1252 renameAction
->setEnabled(capabilities
.supportsMoving());
1253 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1254 deleteAction
->setEnabled(capabilities
.supportsDeleting());
1255 deleteWithTrashShortcut
->setEnabled(capabilities
.supportsDeleting() && !enableMoveToTrash
);
1256 cutAction
->setEnabled(capabilities
.supportsMoving());
1258 updatePasteAction();
1261 void DolphinMainWindow::updateViewActions()
1263 m_actionHandler
->updateViewActions();
1265 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1266 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
1268 updateSplitAction();
1270 QAction
* editableLocactionAction
= actionCollection()->action("editable_location");
1271 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
1272 editableLocactionAction
->setChecked(urlNavigator
->isUrlEditable());
1275 void DolphinMainWindow::updateGoActions()
1277 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
1278 const KUrl
& currentUrl
= m_activeViewContainer
->url();
1279 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
1282 void DolphinMainWindow::clearStatusBar()
1284 m_activeViewContainer
->statusBar()->clear();
1287 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
1289 connect(container
, SIGNAL(showFilterBarChanged(bool)),
1290 this, SLOT(updateFilterBarAction(bool)));
1292 DolphinView
* view
= container
->view();
1293 connect(view
, SIGNAL(selectionChanged(KFileItemList
)),
1294 this, SLOT(slotSelectionChanged(KFileItemList
)));
1295 connect(view
, SIGNAL(requestItemInfo(KFileItem
)),
1296 this, SLOT(slotRequestItemInfo(KFileItem
)));
1297 connect(view
, SIGNAL(activated()),
1298 this, SLOT(toggleActiveView()));
1299 connect(view
, SIGNAL(tabRequested(const KUrl
&)),
1300 this, SLOT(openNewTab(const KUrl
&)));
1302 const KUrlNavigator
* navigator
= container
->urlNavigator();
1303 connect(navigator
, SIGNAL(urlChanged(const KUrl
&)),
1304 this, SLOT(changeUrl(const KUrl
&)));
1305 connect(navigator
, SIGNAL(historyChanged()),
1306 this, SLOT(updateHistory()));
1307 connect(navigator
, SIGNAL(editableStateChanged(bool)),
1308 this, SLOT(slotEditableStateChanged(bool)));
1311 void DolphinMainWindow::updateSplitAction()
1313 QAction
* splitAction
= actionCollection()->action("split_view");
1314 if (m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
1315 if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
1316 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
1317 splitAction
->setIcon(KIcon("view-right-close"));
1319 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
1320 splitAction
->setIcon(KIcon("view-left-close"));
1323 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
1324 splitAction
->setIcon(KIcon("view-right-new"));
1328 QString
DolphinMainWindow::tabName(const KUrl
& url
) const
1331 if (url
.equals(KUrl("file:///"))) {
1334 name
= url
.fileName();
1335 if (name
.isEmpty()) {
1336 name
= url
.protocol();
1342 bool DolphinMainWindow::isKompareInstalled() const
1344 static bool initialized
= false;
1345 static bool installed
= false;
1347 // TODO: maybe replace this approach later by using a menu
1348 // plugin like kdiff3plugin.cpp
1349 installed
= !KGlobal::dirs()->findExe("kompare").isEmpty();
1355 void DolphinMainWindow::createSecondaryView(int tabIndex
)
1357 QSplitter
* splitter
= m_viewTab
[tabIndex
].splitter
;
1358 const int newWidth
= (m_viewTab
[tabIndex
].primaryView
->width() - splitter
->handleWidth()) / 2;
1360 const DolphinView
* view
= m_viewTab
[tabIndex
].primaryView
->view();
1361 m_viewTab
[tabIndex
].secondaryView
= new DolphinViewContainer(this, 0, view
->rootUrl());
1362 splitter
->addWidget(m_viewTab
[tabIndex
].secondaryView
);
1363 splitter
->setSizes(QList
<int>() << newWidth
<< newWidth
);
1364 connectViewSignals(m_viewTab
[tabIndex
].secondaryView
);
1365 m_viewTab
[tabIndex
].secondaryView
->view()->reload();
1366 m_viewTab
[tabIndex
].secondaryView
->setActive(false);
1367 m_viewTab
[tabIndex
].secondaryView
->show();
1370 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
1371 KIO::FileUndoManager::UiInterface()
1375 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
1379 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
1381 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
1383 DolphinStatusBar
* statusBar
= mainWin
->activeViewContainer()->statusBar();
1384 statusBar
->setMessage(job
->errorString(), DolphinStatusBar::Error
);
1386 KIO::FileUndoManager::UiInterface::jobError(job
);
1390 #include "dolphinmainwindow.moc"