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>
81 #include <ktoolinvocation.h>
83 #include <QDBusMessage>
88 #include <QDockWidget>
89 #include <kacceleratormanager.h>
92 * Remembers the tab configuration if a tab has been closed.
93 * Each closed tab can be restored by the menu
94 * "Go -> Recently Closed Tabs".
102 Q_DECLARE_METATYPE(ClosedTab
)
104 DolphinMainWindow::DolphinMainWindow(int id
) :
109 m_activeViewContainer(0),
110 m_centralWidgetLayout(0),
118 setObjectName("Dolphin#");
120 m_viewTab
.append(ViewTab());
122 new MainWindowAdaptor(this);
123 QDBusConnection::sessionBus().registerObject(QString("/dolphin/MainWindow%1").arg(m_id
), this);
125 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
126 undoManager
->setUiInterface(new UndoUiInterface());
128 connect(undoManager
, SIGNAL(undoAvailable(bool)),
129 this, SLOT(slotUndoAvailable(bool)));
130 connect(undoManager
, SIGNAL(undoTextChanged(const QString
&)),
131 this, SLOT(slotUndoTextChanged(const QString
&)));
132 connect(undoManager
, SIGNAL(jobRecordingStarted(CommandType
)),
133 this, SLOT(clearStatusBar()));
134 connect(undoManager
, SIGNAL(jobRecordingFinished(CommandType
)),
135 this, SLOT(showCommand(CommandType
)));
136 connect(DolphinSettings::instance().placesModel(), SIGNAL(errorMessage(const QString
&)),
137 this, SLOT(showErrorMessage(const QString
&)));
138 connect(&DragAndDropHelper::instance(), SIGNAL(errorMessage(const QString
&)),
139 this, SLOT(showErrorMessage(const QString
&)));
142 DolphinMainWindow::~DolphinMainWindow()
144 DolphinApplication::app()->removeMainWindow(this);
147 void DolphinMainWindow::toggleViews()
149 if (m_viewTab
[m_tabIndex
].primaryView
== 0) {
153 // move secondary view from the last position of the splitter
154 // to the first position
155 m_viewTab
[m_tabIndex
].splitter
->insertWidget(0, m_viewTab
[m_tabIndex
].secondaryView
);
157 DolphinViewContainer
* container
= m_viewTab
[m_tabIndex
].primaryView
;
158 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
159 m_viewTab
[m_tabIndex
].secondaryView
= container
;
162 void DolphinMainWindow::showCommand(CommandType command
)
164 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
166 case KIO::FileUndoManager::Copy
:
167 statusBar
->setMessage(i18nc("@info:status", "Copy operation completed."),
168 DolphinStatusBar::OperationCompleted
);
170 case KIO::FileUndoManager::Move
:
171 statusBar
->setMessage(i18nc("@info:status", "Move operation completed."),
172 DolphinStatusBar::OperationCompleted
);
174 case KIO::FileUndoManager::Link
:
175 statusBar
->setMessage(i18nc("@info:status", "Link operation completed."),
176 DolphinStatusBar::OperationCompleted
);
178 case KIO::FileUndoManager::Trash
:
179 statusBar
->setMessage(i18nc("@info:status", "Move to trash operation completed."),
180 DolphinStatusBar::OperationCompleted
);
182 case KIO::FileUndoManager::Rename
:
183 statusBar
->setMessage(i18nc("@info:status", "Renaming operation completed."),
184 DolphinStatusBar::OperationCompleted
);
187 case KIO::FileUndoManager::Mkdir
:
188 statusBar
->setMessage(i18nc("@info:status", "Created folder."),
189 DolphinStatusBar::OperationCompleted
);
197 void DolphinMainWindow::refreshViews()
199 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
201 // remember the current active view, as because of
202 // the refreshing the active view might change to
203 // the secondary view
204 DolphinViewContainer
* activeViewContainer
= m_activeViewContainer
;
206 const int tabCount
= m_viewTab
.count();
207 for (int i
= 0; i
< tabCount
; ++i
) {
208 m_viewTab
[i
].primaryView
->refresh();
209 if (m_viewTab
[i
].secondaryView
!= 0) {
210 m_viewTab
[i
].secondaryView
->refresh();
214 setActiveViewContainer(activeViewContainer
);
217 void DolphinMainWindow::pasteIntoFolder()
219 m_activeViewContainer
->view()->pasteIntoFolder();
222 void DolphinMainWindow::changeUrl(const KUrl
& url
)
224 if (!KProtocolManager::supportsListing(url
)) {
225 // The URL navigator only checks for validity, not
226 // if the URL can be listed. An error message is
227 // shown due to DolphinViewContainer::restoreView().
231 DolphinViewContainer
* view
= activeViewContainer();
237 setCaption(url
.fileName());
238 if (m_viewTab
.count() > 1) {
239 m_tabBar
->setTabText(m_tabIndex
, tabName(url
));
241 const QString iconName
= KMimeType::iconNameForUrl(url
);
242 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(iconName
));
243 emit
urlChanged(url
);
247 void DolphinMainWindow::changeSelection(const KFileItemList
& selection
)
249 activeViewContainer()->view()->changeSelection(selection
);
252 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
254 KToggleAction
* editableLocationAction
=
255 static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
256 editableLocationAction
->setChecked(editable
);
259 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
263 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
264 int selectedUrlsCount
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedItemsCount();
265 if (m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
266 selectedUrlsCount
+= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItemsCount();
269 QAction
* compareFilesAction
= actionCollection()->action("compare_files");
270 if (selectedUrlsCount
== 2) {
271 compareFilesAction
->setEnabled(isKompareInstalled());
273 compareFilesAction
->setEnabled(false);
276 m_activeViewContainer
->updateStatusBar();
278 emit
selectionChanged(selection
);
281 void DolphinMainWindow::slotWheelMoved(int wheelDelta
)
283 if (wheelDelta
> 0) {
290 void DolphinMainWindow::slotRequestItemInfo(const KFileItem
& item
)
292 emit
requestItemInfo(item
);
295 void DolphinMainWindow::updateHistory()
297 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
298 const int index
= urlNavigator
->historyIndex();
300 QAction
* backAction
= actionCollection()->action("go_back");
301 if (backAction
!= 0) {
302 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
305 QAction
* forwardAction
= actionCollection()->action("go_forward");
306 if (forwardAction
!= 0) {
307 forwardAction
->setEnabled(index
> 0);
311 void DolphinMainWindow::updateFilterBarAction(bool show
)
313 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
314 showFilterBarAction
->setChecked(show
);
317 void DolphinMainWindow::openNewMainWindow()
319 DolphinApplication::app()->createMainWindow()->show();
322 void DolphinMainWindow::openNewTab()
324 openNewTab(m_activeViewContainer
->url());
325 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
327 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
328 if (navigator
->isUrlEditable()) {
329 // if a new tab is opened and the URL is editable, assure that
330 // the user can edit the URL without manually setting the focus
331 navigator
->setFocus();
335 void DolphinMainWindow::openNewTab(const KUrl
& url
)
337 const KIcon icon
= KIcon(KMimeType::iconNameForUrl(m_activeViewContainer
->url()));
338 if (m_viewTab
.count() == 1) {
339 // Only one view is open currently and hence no tab is shown at
340 // all. Before creating a tab for 'url', provide a tab for the current URL.
341 m_tabBar
->addTab(icon
, tabName(m_activeViewContainer
->url()));
342 m_tabBar
->blockSignals(false);
345 m_tabBar
->addTab(icon
, tabName(url
));
348 viewTab
.splitter
= new QSplitter(this);
349 viewTab
.primaryView
= new DolphinViewContainer(this, viewTab
.splitter
, url
);
350 viewTab
.primaryView
->setActive(false);
351 connectViewSignals(viewTab
.primaryView
);
352 viewTab
.primaryView
->view()->reload();
354 m_viewTab
.append(viewTab
);
356 actionCollection()->action("close_tab")->setEnabled(true);
358 // provide a split view, if the startup settings are set this way
359 const GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
360 if (generalSettings
->splitView()) {
361 const int tabIndex
= m_viewTab
.count() - 1;
362 createSecondaryView(tabIndex
);
363 m_viewTab
[tabIndex
].secondaryView
->setActive(true);
364 m_viewTab
[tabIndex
].isPrimaryViewActive
= false;
368 void DolphinMainWindow::activateNextTab()
370 if ((m_viewTab
.count() == 1) || (m_tabBar
->count() < 2)) {
374 const int tabIndex
= (m_tabBar
->currentIndex() + 1) % m_tabBar
->count();
375 m_tabBar
->setCurrentIndex(tabIndex
);
378 void DolphinMainWindow::activatePrevTab()
380 if ((m_viewTab
.count() == 1) || (m_tabBar
->count() < 2)) {
384 int tabIndex
= m_tabBar
->currentIndex() - 1;
385 if (tabIndex
== -1) {
386 tabIndex
= m_tabBar
->count() - 1;
388 m_tabBar
->setCurrentIndex(tabIndex
);
391 void DolphinMainWindow::openInNewTab()
393 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
394 if ((list
.count() == 1) && list
[0].isDir()) {
395 openNewTab(m_activeViewContainer
->view()->selectedUrls()[0]);
399 void DolphinMainWindow::openInNewWindow()
401 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
402 if ((list
.count() == 1) && list
[0].isDir()) {
403 DolphinMainWindow
* window
= DolphinApplication::app()->createMainWindow();
404 window
->changeUrl(m_activeViewContainer
->view()->selectedUrls()[0]);
409 void DolphinMainWindow::toggleActiveView()
411 if (m_viewTab
[m_tabIndex
].secondaryView
== 0) {
412 // only one view is available
416 Q_ASSERT(m_activeViewContainer
!= 0);
417 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
419 DolphinViewContainer
* left
= m_viewTab
[m_tabIndex
].primaryView
;
420 DolphinViewContainer
* right
= m_viewTab
[m_tabIndex
].secondaryView
;
421 setActiveViewContainer(m_activeViewContainer
== right
? left
: right
);
424 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
426 DolphinSettings
& settings
= DolphinSettings::instance();
427 GeneralSettings
* generalSettings
= settings
.generalSettings();
429 if ((m_viewTab
.count() > 1) && generalSettings
->confirmClosingMultipleTabs()) {
430 // Ask the user if he really wants to quit and close all tabs.
431 // Open a confirmation dialog with 3 buttons:
432 // KDialog::Yes -> Quit
433 // KDialog::No -> Close only the current tab
434 // KDialog::Cancel -> do nothing
435 KDialog
*dialog
= new KDialog(this, Qt::Dialog
);
436 dialog
->setCaption(i18nc("@title:window", "Confirmation"));
437 dialog
->setButtons(KDialog::Yes
| KDialog::No
| KDialog::Cancel
);
438 dialog
->setModal(true);
439 dialog
->showButtonSeparator(true);
440 dialog
->setButtonGuiItem(KDialog::Yes
, KStandardGuiItem::quit());
441 dialog
->setButtonGuiItem(KDialog::No
, KGuiItem(i18n("C&lose Current Tab"), KIcon("tab-close")));
442 dialog
->setButtonGuiItem(KDialog::Cancel
, KStandardGuiItem::cancel());
443 dialog
->setDefaultButton(KDialog::Yes
);
445 bool doNotAskAgainCheckboxResult
= false;
447 const int result
= KMessageBox::createKMessageBox(dialog
,
448 QMessageBox::Warning
,
449 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
451 i18n("Do not ask again"),
452 &doNotAskAgainCheckboxResult
,
453 KMessageBox::Notify
);
455 if (doNotAskAgainCheckboxResult
) {
456 generalSettings
->setConfirmClosingMultipleTabs(false);
464 // Close only the current tab
472 generalSettings
->setFirstRun(false);
476 KXmlGuiWindow::closeEvent(event
);
479 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
481 // TODO: remember tabs
482 DolphinViewContainer
* cont
= m_viewTab
[m_tabIndex
].primaryView
;
483 group
.writeEntry("Primary Url", cont
->url().url());
484 group
.writeEntry("Primary Editable Url", cont
->isUrlEditable());
486 cont
= m_viewTab
[m_tabIndex
].secondaryView
;
488 group
.writeEntry("Secondary Url", cont
->url().url());
489 group
.writeEntry("Secondary Editable Url", cont
->isUrlEditable());
493 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
496 DolphinViewContainer
* cont
= m_viewTab
[m_tabIndex
].primaryView
;
498 cont
->setUrl(group
.readEntry("Primary Url"));
499 bool editable
= group
.readEntry("Primary Editable Url", false);
500 cont
->urlNavigator()->setUrlEditable(editable
);
502 cont
= m_viewTab
[m_tabIndex
].secondaryView
;
503 const QString secondaryUrl
= group
.readEntry("Secondary Url");
504 if (!secondaryUrl
.isEmpty()) {
506 // a secondary view should be shown, but no one is available
507 // currently -> create a new view
509 cont
= m_viewTab
[m_tabIndex
].secondaryView
;
513 cont
->setUrl(secondaryUrl
);
514 bool editable
= group
.readEntry("Secondary Editable Url", false);
515 cont
->urlNavigator()->setUrlEditable(editable
);
516 } else if (cont
!= 0) {
517 // no secondary view should be shown, but the default setting shows
518 // one already -> close the view
523 void DolphinMainWindow::updateNewMenu()
525 m_newMenu
->slotCheckUpToDate();
526 m_newMenu
->setPopupFiles(activeViewContainer()->url());
529 void DolphinMainWindow::quit()
534 void DolphinMainWindow::showErrorMessage(const QString
& message
)
536 if (!message
.isEmpty()) {
537 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
538 statusBar
->setMessage(message
, DolphinStatusBar::Error
);
542 void DolphinMainWindow::slotUndoAvailable(bool available
)
544 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
545 if (undoAction
!= 0) {
546 undoAction
->setEnabled(available
);
550 void DolphinMainWindow::restoreClosedTab(QAction
* action
)
552 if (action
->data().toBool()) {
553 // clear all actions except the "Empty Recently Closed Tabs"
554 // action and the separator
555 QList
<QAction
*> actions
= m_recentTabsMenu
->menu()->actions();
556 const int count
= actions
.size();
557 for (int i
= 2; i
< count
; ++i
) {
558 m_recentTabsMenu
->menu()->removeAction(actions
.at(i
));
561 const ClosedTab closedTab
= action
->data().value
<ClosedTab
>();
562 openNewTab(closedTab
.primaryUrl
);
563 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
565 if (closedTab
.isSplit
) {
566 // create secondary view
568 m_viewTab
[m_tabIndex
].secondaryView
->setUrl(closedTab
.secondaryUrl
);
571 m_recentTabsMenu
->removeAction(action
);
574 if (m_recentTabsMenu
->menu()->actions().count() == 2) {
575 m_recentTabsMenu
->setEnabled(false);
579 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
581 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
582 if (undoAction
!= 0) {
583 undoAction
->setText(text
);
587 void DolphinMainWindow::undo()
590 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
591 KIO::FileUndoManager::self()->undo();
594 void DolphinMainWindow::cut()
596 m_activeViewContainer
->view()->cutSelectedItems();
599 void DolphinMainWindow::copy()
601 m_activeViewContainer
->view()->copySelectedItems();
604 void DolphinMainWindow::paste()
606 m_activeViewContainer
->view()->paste();
609 void DolphinMainWindow::updatePasteAction()
611 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
612 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
613 pasteAction
->setEnabled(pasteInfo
.first
);
614 pasteAction
->setText(pasteInfo
.second
);
617 void DolphinMainWindow::selectAll()
621 // if the URL navigator is editable and focused, select the whole
622 // URL instead of all items of the view
624 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
625 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit();
626 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
627 lineEdit
->hasFocus();
629 lineEdit
->selectAll();
631 m_activeViewContainer
->view()->selectAll();
635 void DolphinMainWindow::invertSelection()
638 m_activeViewContainer
->view()->invertSelection();
641 void DolphinMainWindow::toggleSplitView()
643 if (m_viewTab
[m_tabIndex
].secondaryView
== 0) {
644 createSecondaryView(m_tabIndex
);
645 setActiveViewContainer(m_viewTab
[m_tabIndex
].secondaryView
);
646 } else if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
647 // remove secondary view
648 m_viewTab
[m_tabIndex
].secondaryView
->close();
649 m_viewTab
[m_tabIndex
].secondaryView
->deleteLater();
650 m_viewTab
[m_tabIndex
].secondaryView
= 0;
652 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
654 // The primary view is active and should be closed. Hence from a users point of view
655 // the content of the secondary view should be moved to the primary view.
656 // From an implementation point of view it is more efficient to close
657 // the primary view and exchange the internal pointers afterwards.
659 m_viewTab
[m_tabIndex
].primaryView
->close();
660 m_viewTab
[m_tabIndex
].primaryView
->deleteLater();
661 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
662 m_viewTab
[m_tabIndex
].secondaryView
= 0;
664 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
670 void DolphinMainWindow::reloadView()
673 m_activeViewContainer
->view()->reload();
676 void DolphinMainWindow::stopLoading()
680 void DolphinMainWindow::toggleFilterBarVisibility(bool show
)
682 m_activeViewContainer
->showFilterBar(show
);
685 void DolphinMainWindow::toggleEditLocation()
689 QAction
* action
= actionCollection()->action("editable_location");
690 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
691 urlNavigator
->setUrlEditable(action
->isChecked());
694 void DolphinMainWindow::replaceLocation()
696 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
697 navigator
->setUrlEditable(true);
698 navigator
->setFocus();
700 // select the whole text of the combo box editor
701 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit();
702 const QString text
= lineEdit
->text();
703 lineEdit
->setSelection(0, text
.length());
706 void DolphinMainWindow::goBack()
709 m_activeViewContainer
->urlNavigator()->goBack();
712 void DolphinMainWindow::goForward()
715 m_activeViewContainer
->urlNavigator()->goForward();
718 void DolphinMainWindow::goUp()
721 m_activeViewContainer
->urlNavigator()->goUp();
724 void DolphinMainWindow::goHome()
727 m_activeViewContainer
->urlNavigator()->goHome();
730 void DolphinMainWindow::compareFiles()
732 // The method is only invoked if exactly 2 files have
733 // been selected. The selected files may be:
734 // - both in the primary view
735 // - both in the secondary view
736 // - one in the primary view and the other in the secondary
738 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
742 KUrl::List urls
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedUrls();
744 switch (urls
.count()) {
746 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
!= 0);
747 urls
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedUrls();
748 Q_ASSERT(urls
.count() == 2);
756 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
!= 0);
757 urls
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedUrls();
758 Q_ASSERT(urls
.count() == 1);
770 // may not happen: compareFiles may only get invoked if 2
771 // files are selected
776 QString
command("kompare -c \"");
777 command
.append(urlA
.pathOrUrl());
778 command
.append("\" \"");
779 command
.append(urlB
.pathOrUrl());
780 command
.append('\"');
781 KRun::runCommand(command
, "Kompare", "kompare", this);
784 void DolphinMainWindow::toggleShowMenuBar()
786 const bool visible
= menuBar()->isVisible();
787 menuBar()->setVisible(!visible
);
790 void DolphinMainWindow::openTerminal()
792 KToolInvocation::invokeTerminal(QString(), m_activeViewContainer
->url().path());
795 void DolphinMainWindow::editSettings()
797 if (m_settingsDialog
== 0) {
798 const KUrl
& url
= activeViewContainer()->url();
799 m_settingsDialog
= new DolphinSettingsDialog(url
, this);
800 m_settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
801 m_settingsDialog
->show();
803 m_settingsDialog
->raise();
807 void DolphinMainWindow::setActiveTab(int index
)
809 Q_ASSERT(index
>= 0);
810 Q_ASSERT(index
< m_viewTab
.count());
811 if (index
== m_tabIndex
) {
815 // hide current tab content
816 ViewTab
& hiddenTab
= m_viewTab
[m_tabIndex
];
817 hiddenTab
.isPrimaryViewActive
= hiddenTab
.primaryView
->isActive();
818 hiddenTab
.primaryView
->setActive(false);
819 if (hiddenTab
.secondaryView
!= 0) {
820 hiddenTab
.secondaryView
->setActive(false);
822 QSplitter
* splitter
= m_viewTab
[m_tabIndex
].splitter
;
824 m_centralWidgetLayout
->removeWidget(splitter
);
826 // show active tab content
829 ViewTab
& viewTab
= m_viewTab
[index
];
830 m_centralWidgetLayout
->addWidget(viewTab
.splitter
);
831 viewTab
.primaryView
->show();
832 if (viewTab
.secondaryView
!= 0) {
833 viewTab
.secondaryView
->show();
835 viewTab
.splitter
->show();
837 setActiveViewContainer(viewTab
.isPrimaryViewActive
? viewTab
.primaryView
:
838 viewTab
.secondaryView
);
841 void DolphinMainWindow::closeTab()
843 closeTab(m_tabBar
->currentIndex());
846 void DolphinMainWindow::closeTab(int index
)
848 Q_ASSERT(index
>= 0);
849 Q_ASSERT(index
< m_viewTab
.count());
850 if (m_viewTab
.count() == 1) {
851 // the last tab may never get closed
855 if (index
== m_tabIndex
) {
856 // The tab that should be closed is the active tab. Activate the
857 // previous tab before closing the tab.
858 m_tabBar
->setCurrentIndex((index
> 0) ? index
- 1 : 1);
860 rememberClosedTab(index
);
863 m_viewTab
[index
].primaryView
->deleteLater();
864 if (m_viewTab
[index
].secondaryView
!= 0) {
865 m_viewTab
[index
].secondaryView
->deleteLater();
867 m_viewTab
[index
].splitter
->deleteLater();
868 m_viewTab
.erase(m_viewTab
.begin() + index
);
870 m_tabBar
->blockSignals(true);
871 m_tabBar
->removeTab(index
);
873 if (m_tabIndex
> index
) {
875 Q_ASSERT(m_tabIndex
>= 0);
878 // if only one tab is left, also remove the tab entry so that
879 // closing the last tab is not possible
880 if (m_viewTab
.count() == 1) {
881 m_tabBar
->removeTab(0);
882 actionCollection()->action("close_tab")->setEnabled(false);
884 m_tabBar
->blockSignals(false);
888 void DolphinMainWindow::openTabContextMenu(int index
, const QPoint
& pos
)
892 QAction
* newTabAction
= menu
.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab"));
893 newTabAction
->setShortcut(actionCollection()->action("new_tab")->shortcut());
895 QAction
* closeOtherTabsAction
= menu
.addAction(KIcon("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs"));
897 QAction
* closeTabAction
= menu
.addAction(KIcon("tab-close"), i18nc("@action:inmenu", "Close Tab"));
898 closeTabAction
->setShortcut(actionCollection()->action("close_tab")->shortcut());
899 QAction
* selectedAction
= menu
.exec(pos
);
900 if (selectedAction
== newTabAction
) {
901 const ViewTab
& tab
= m_viewTab
[index
];
902 Q_ASSERT(tab
.primaryView
!= 0);
903 const KUrl url
= (tab
.secondaryView
!= 0) && tab
.secondaryView
->isActive() ?
904 tab
.secondaryView
->url() : tab
.primaryView
->url();
906 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
907 } else if (selectedAction
== closeOtherTabsAction
) {
908 const int count
= m_tabBar
->count();
909 for (int i
= 0; i
< index
; ++i
) {
912 for (int i
= index
+ 1; i
< count
; ++i
) {
915 } else if (selectedAction
== closeTabAction
) {
920 void DolphinMainWindow::handlePlacesClick(const KUrl
& url
, Qt::MouseButtons buttons
)
922 if (buttons
& Qt::MidButton
) {
924 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
930 void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent
* event
, bool& canDecode
)
932 canDecode
= KUrl::List::canDecode(event
->mimeData());
935 void DolphinMainWindow::searchItems(const KUrl
& url
)
937 m_activeViewContainer
->setUrl(url
);
940 void DolphinMainWindow::init()
942 DolphinSettings
& settings
= DolphinSettings::instance();
944 // Check whether Dolphin runs the first time. If yes then
945 // a proper default window size is given at the end of DolphinMainWindow::init().
946 GeneralSettings
* generalSettings
= settings
.generalSettings();
947 const bool firstRun
= generalSettings
->firstRun();
949 generalSettings
->setViewPropsTimestamp(QDateTime::currentDateTime());
952 setAcceptDrops(true);
954 m_viewTab
[m_tabIndex
].splitter
= new QSplitter(this);
958 const KUrl
& homeUrl
= generalSettings
->homeUrl();
959 setCaption(homeUrl
.fileName());
960 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
961 connect(m_actionHandler
, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
962 ViewProperties
props(homeUrl
);
963 m_viewTab
[m_tabIndex
].primaryView
= new DolphinViewContainer(this,
964 m_viewTab
[m_tabIndex
].splitter
,
967 m_activeViewContainer
= m_viewTab
[m_tabIndex
].primaryView
;
968 connectViewSignals(m_activeViewContainer
);
969 DolphinView
* view
= m_activeViewContainer
->view();
971 m_activeViewContainer
->show();
972 m_actionHandler
->setCurrentView(view
);
974 m_tabBar
= new KTabBar(this);
975 m_tabBar
->setMovable(true);
976 m_tabBar
->setTabsClosable(true);
977 connect(m_tabBar
, SIGNAL(currentChanged(int)),
978 this, SLOT(setActiveTab(int)));
979 connect(m_tabBar
, SIGNAL(tabCloseRequested(int)),
980 this, SLOT(closeTab(int)));
981 connect(m_tabBar
, SIGNAL(contextMenu(int, const QPoint
&)),
982 this, SLOT(openTabContextMenu(int, const QPoint
&)));
983 connect(m_tabBar
, SIGNAL(newTabRequest()),
984 this, SLOT(openNewTab()));
985 connect(m_tabBar
, SIGNAL(testCanDecode(const QDragMoveEvent
*, bool&)),
986 this, SLOT(slotTestCanDecode(const QDragMoveEvent
*, bool&)));
987 connect(m_tabBar
, SIGNAL(wheelDelta(int)),
988 this, SLOT(slotWheelMoved(int)));
989 connect(m_tabBar
, SIGNAL(mouseMiddleClick(int)),
990 this, SLOT(closeTab(int)));
992 m_tabBar
->blockSignals(true); // signals get unblocked after at least 2 tabs are open
994 QWidget
* centralWidget
= new QWidget(this);
995 m_centralWidgetLayout
= new QVBoxLayout(centralWidget
);
996 m_centralWidgetLayout
->setSpacing(0);
997 m_centralWidgetLayout
->setMargin(0);
998 m_centralWidgetLayout
->addWidget(m_tabBar
);
999 m_centralWidgetLayout
->addWidget(m_viewTab
[m_tabIndex
].splitter
);
1001 setCentralWidget(centralWidget
);
1003 emit
urlChanged(homeUrl
);
1005 setupGUI(Keys
| Save
| Create
| ToolBar
);
1007 m_searchBox
->setParent(toolBar("searchToolBar"));
1008 m_searchBox
->show();
1010 stateChanged("new_file");
1012 QClipboard
* clipboard
= QApplication::clipboard();
1013 connect(clipboard
, SIGNAL(dataChanged()),
1014 this, SLOT(updatePasteAction()));
1015 updatePasteAction();
1018 if (generalSettings
->splitView()) {
1021 updateViewActions();
1023 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1024 showFilterBarAction
->setChecked(generalSettings
->filterBar());
1027 // assure a proper default size if Dolphin runs the first time
1031 m_showMenuBar
->setChecked(!menuBar()->isHidden()); // workaround for bug #171080
1034 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer
* viewContainer
)
1036 Q_ASSERT(viewContainer
!= 0);
1037 Q_ASSERT((viewContainer
== m_viewTab
[m_tabIndex
].primaryView
) ||
1038 (viewContainer
== m_viewTab
[m_tabIndex
].secondaryView
));
1039 if (m_activeViewContainer
== viewContainer
) {
1043 m_activeViewContainer
->setActive(false);
1044 m_activeViewContainer
= viewContainer
;
1046 // Activating the view container might trigger a recursive setActiveViewContainer() call
1047 // inside DolphinMainWindow::toggleActiveView() when having a split view. Temporary
1048 // disconnect the activated() signal in this case:
1049 disconnect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1050 m_activeViewContainer
->setActive(true);
1051 connect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1053 m_actionHandler
->setCurrentView(viewContainer
->view());
1056 updateEditActions();
1057 updateViewActions();
1060 const KUrl
& url
= m_activeViewContainer
->url();
1061 setCaption(url
.fileName());
1062 if (m_viewTab
.count() > 1 && m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
1063 m_tabBar
->setTabText(m_tabIndex
, tabName(url
));
1064 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(KMimeType::iconNameForUrl(url
)));
1067 emit
urlChanged(url
);
1070 void DolphinMainWindow::setupActions()
1072 // setup 'File' menu
1073 m_newMenu
= new DolphinNewMenu(this, this);
1074 KMenu
* menu
= m_newMenu
->menu();
1075 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1076 menu
->setIcon(KIcon("document-new"));
1077 connect(menu
, SIGNAL(aboutToShow()),
1078 this, SLOT(updateNewMenu()));
1080 KAction
* newWindow
= actionCollection()->addAction("new_window");
1081 newWindow
->setIcon(KIcon("window-new"));
1082 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1083 newWindow
->setShortcut(Qt::CTRL
| Qt::Key_N
);
1084 connect(newWindow
, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1086 KAction
* newTab
= actionCollection()->addAction("new_tab");
1087 newTab
->setIcon(KIcon("tab-new"));
1088 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1089 newTab
->setShortcut(KShortcut(Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
));
1090 connect(newTab
, SIGNAL(triggered()), this, SLOT(openNewTab()));
1092 KAction
* closeTab
= actionCollection()->addAction("close_tab");
1093 closeTab
->setIcon(KIcon("tab-close"));
1094 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1095 closeTab
->setShortcut(Qt::CTRL
| Qt::Key_W
);
1096 closeTab
->setEnabled(false);
1097 connect(closeTab
, SIGNAL(triggered()), this, SLOT(closeTab()));
1099 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1101 // setup 'Edit' menu
1102 KStandardAction::undo(this,
1104 actionCollection());
1106 // need to remove shift+del from cut action, else the shortcut for deletejob
1108 KAction
* cut
= KStandardAction::cut(this, SLOT(cut()), actionCollection());
1109 KShortcut cutShortcut
= cut
->shortcut();
1110 cutShortcut
.remove(Qt::SHIFT
+ Qt::Key_Delete
, KShortcut::KeepEmpty
);
1111 cut
->setShortcut(cutShortcut
);
1112 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1113 KStandardAction::paste(this, SLOT(paste()), actionCollection());
1115 KAction
* selectAll
= actionCollection()->addAction("select_all");
1116 selectAll
->setText(i18nc("@action:inmenu Edit", "Select All"));
1117 selectAll
->setShortcut(Qt::CTRL
+ Qt::Key_A
);
1118 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
1120 KAction
* invertSelection
= actionCollection()->addAction("invert_selection");
1121 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1122 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1123 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
1125 // setup 'View' menu
1126 // (note that most of it is set up in DolphinViewActionHandler)
1128 KAction
* split
= actionCollection()->addAction("split_view");
1129 split
->setShortcut(Qt::Key_F3
);
1130 updateSplitAction();
1131 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1133 KAction
* reload
= actionCollection()->addAction("reload");
1134 reload
->setText(i18nc("@action:inmenu View", "Reload"));
1135 reload
->setShortcut(Qt::Key_F5
);
1136 reload
->setIcon(KIcon("view-refresh"));
1137 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
1139 KAction
* stop
= actionCollection()->addAction("stop");
1140 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1141 stop
->setIcon(KIcon("process-stop"));
1142 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
1144 KToggleAction
* showFullLocation
= actionCollection()->add
<KToggleAction
>("editable_location");
1145 showFullLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1146 showFullLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
1147 connect(showFullLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1149 KAction
* replaceLocation
= actionCollection()->addAction("replace_location");
1150 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1151 replaceLocation
->setShortcut(Qt::Key_F6
);
1152 connect(replaceLocation
, SIGNAL(triggered()), this, SLOT(replaceLocation()));
1155 KAction
* backAction
= KStandardAction::back(this, SLOT(goBack()), actionCollection());
1156 KShortcut backShortcut
= backAction
->shortcut();
1157 backShortcut
.setAlternate(Qt::Key_Backspace
);
1158 backAction
->setShortcut(backShortcut
);
1160 m_recentTabsMenu
= new KActionMenu(i18n("Recently Closed Tabs"), this);
1161 m_recentTabsMenu
->setIcon(KIcon("edit-undo"));
1162 actionCollection()->addAction("closed_tabs", m_recentTabsMenu
);
1163 connect(m_recentTabsMenu
->menu(), SIGNAL(triggered(QAction
*)),
1164 this, SLOT(restoreClosedTab(QAction
*)));
1166 QAction
* action
= new QAction("Empty Recently Closed Tabs", m_recentTabsMenu
);
1167 action
->setIcon(KIcon("edit-clear-list"));
1168 action
->setData(QVariant::fromValue(true));
1169 m_recentTabsMenu
->addAction(action
);
1170 m_recentTabsMenu
->addSeparator();
1171 m_recentTabsMenu
->setEnabled(false);
1173 KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1174 KStandardAction::up(this, SLOT(goUp()), actionCollection());
1175 KStandardAction::home(this, SLOT(goHome()), actionCollection());
1177 // setup 'Tools' menu
1178 KToggleAction
* showSearchBar
= actionCollection()->add
<KToggleAction
>("show_search_bar");
1179 showSearchBar
->setText(i18nc("@action:inmenu Tools", "Show Search Bar"));
1180 showSearchBar
->setShortcut(Qt::CTRL
| Qt::Key_S
);
1181 connect(showSearchBar
, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
1183 KToggleAction
* showFilterBar
= actionCollection()->add
<KToggleAction
>("show_filter_bar");
1184 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1185 showFilterBar
->setShortcut(Qt::CTRL
| Qt::Key_I
);
1186 connect(showFilterBar
, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
1188 KAction
* compareFiles
= actionCollection()->addAction("compare_files");
1189 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1190 compareFiles
->setIcon(KIcon("kompare"));
1191 compareFiles
->setEnabled(false);
1192 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
1194 KAction
* openTerminal
= actionCollection()->addAction("open_terminal");
1195 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1196 openTerminal
->setIcon(KIcon("terminal"));
1197 openTerminal
->setShortcut(Qt::SHIFT
| Qt::Key_F4
);
1198 connect(openTerminal
, SIGNAL(triggered()), this, SLOT(openTerminal()));
1200 // setup 'Settings' menu
1201 m_showMenuBar
= KStandardAction::showMenubar(this, SLOT(toggleShowMenuBar()), actionCollection());
1202 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1204 // not in menu actions
1205 KAction
* activateNextTab
= actionCollection()->addAction("activate_next_tab");
1206 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1207 connect(activateNextTab
, SIGNAL(triggered()), SLOT(activateNextTab()));
1208 activateNextTab
->setShortcuts(QApplication::isRightToLeft() ? KStandardShortcut::tabPrev() :
1209 KStandardShortcut::tabNext());
1211 KAction
* activatePrevTab
= actionCollection()->addAction("activate_prev_tab");
1212 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1213 connect(activatePrevTab
, SIGNAL(triggered()), SLOT(activatePrevTab()));
1214 activatePrevTab
->setShortcuts(QApplication::isRightToLeft() ? KStandardShortcut::tabNext() :
1215 KStandardShortcut::tabPrev());
1218 KAction
* openInNewTab
= actionCollection()->addAction("open_in_new_tab");
1219 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1220 openInNewTab
->setIcon(KIcon("tab-new"));
1221 connect(openInNewTab
, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1223 KAction
* openInNewWindow
= actionCollection()->addAction("open_in_new_window");
1224 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1225 openInNewWindow
->setIcon(KIcon("window-new"));
1226 connect(openInNewWindow
, SIGNAL(triggered()), this, SLOT(openInNewWindow()));
1229 m_searchBox
= new DolphinSearchBox(this);
1230 connect(m_searchBox
, SIGNAL(search(KUrl
)), this, SLOT(searchItems(KUrl
)));
1232 KAction
* search
= new KAction(this);
1233 actionCollection()->addAction("search_bar", search
);
1234 search
->setText(i18nc("@action:inmenu", "Search Bar"));
1235 search
->setDefaultWidget(m_searchBox
);
1236 search
->setShortcutConfigurable(false);
1239 void DolphinMainWindow::setupDockWidgets()
1241 // setup "Information"
1242 QDockWidget
* infoDock
= new QDockWidget(i18nc("@title:window", "Information"));
1243 infoDock
->setObjectName("infoDock");
1244 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1245 Panel
* infoPanel
= new InformationPanel(infoDock
);
1246 infoDock
->setWidget(infoPanel
);
1248 QAction
* infoAction
= infoDock
->toggleViewAction();
1249 infoAction
->setText(i18nc("@title:window", "Information"));
1250 infoAction
->setShortcut(Qt::Key_F11
);
1251 infoAction
->setIcon(KIcon("dialog-information"));
1252 actionCollection()->addAction("show_info_panel", infoDock
->toggleViewAction());
1254 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1255 connect(this, SIGNAL(urlChanged(KUrl
)),
1256 infoPanel
, SLOT(setUrl(KUrl
)));
1257 connect(this, SIGNAL(selectionChanged(KFileItemList
)),
1258 infoPanel
, SLOT(setSelection(KFileItemList
)));
1259 connect(this, SIGNAL(requestItemInfo(KFileItem
)),
1260 infoPanel
, SLOT(requestDelayedItemInfo(KFileItem
)));
1263 QDockWidget
* foldersDock
= new QDockWidget(i18nc("@title:window", "Folders"));
1264 foldersDock
->setObjectName("foldersDock");
1265 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1266 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1267 foldersDock
->setWidget(foldersPanel
);
1269 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1270 foldersAction
->setText(i18nc("@title:window", "Folders"));
1271 foldersAction
->setShortcut(Qt::Key_F7
);
1272 foldersAction
->setIcon(KIcon("folder"));
1273 actionCollection()->addAction("show_folders_panel", foldersDock
->toggleViewAction());
1275 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1276 connect(this, SIGNAL(urlChanged(KUrl
)),
1277 foldersPanel
, SLOT(setUrl(KUrl
)));
1278 connect(foldersPanel
, SIGNAL(changeUrl(KUrl
, Qt::MouseButtons
)),
1279 this, SLOT(handlePlacesClick(KUrl
, Qt::MouseButtons
)));
1280 connect(foldersPanel
, SIGNAL(changeSelection(KFileItemList
)),
1281 this, SLOT(changeSelection(KFileItemList
)));
1285 QDockWidget
* terminalDock
= new QDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1286 terminalDock
->setObjectName("terminalDock");
1287 terminalDock
->setAllowedAreas(Qt::TopDockWidgetArea
| Qt::BottomDockWidgetArea
);
1288 Panel
* terminalPanel
= new TerminalPanel(terminalDock
);
1289 terminalDock
->setWidget(terminalPanel
);
1291 connect(terminalPanel
, SIGNAL(hideTerminalPanel()), terminalDock
, SLOT(hide()));
1293 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1294 terminalAction
->setText(i18nc("@title:window Shell terminal", "Terminal"));
1295 terminalAction
->setShortcut(Qt::Key_F4
);
1296 terminalAction
->setIcon(KIcon("terminal"));
1297 actionCollection()->addAction("show_terminal_panel", terminalDock
->toggleViewAction());
1299 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1300 connect(this, SIGNAL(urlChanged(KUrl
)),
1301 terminalPanel
, SLOT(setUrl(KUrl
)));
1304 const bool firstRun
= DolphinSettings::instance().generalSettings()->firstRun();
1306 foldersDock
->hide();
1308 terminalDock
->hide();
1312 QDockWidget
* placesDock
= new QDockWidget(i18nc("@title:window", "Places"));
1313 placesDock
->setObjectName("placesDock");
1314 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1316 PlacesPanel
* placesPanel
= new PlacesPanel(placesDock
);
1317 placesDock
->setWidget(placesPanel
);
1318 placesPanel
->setModel(DolphinSettings::instance().placesModel());
1319 placesPanel
->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff
);
1321 QAction
* placesAction
= placesDock
->toggleViewAction();
1322 placesAction
->setText(i18nc("@title:window", "Places"));
1323 placesAction
->setShortcut(Qt::Key_F9
);
1324 placesAction
->setIcon(KIcon("bookmarks"));
1325 actionCollection()->addAction("show_places_panel", placesDock
->toggleViewAction());
1327 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1328 connect(placesPanel
, SIGNAL(urlChanged(KUrl
, Qt::MouseButtons
)),
1329 this, SLOT(handlePlacesClick(KUrl
, Qt::MouseButtons
)));
1330 connect(this, SIGNAL(urlChanged(KUrl
)),
1331 placesPanel
, SLOT(setUrl(KUrl
)));
1334 void DolphinMainWindow::updateEditActions()
1336 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1337 if (list
.isEmpty()) {
1338 stateChanged("has_no_selection");
1340 stateChanged("has_selection");
1342 KActionCollection
* col
= actionCollection();
1343 QAction
* renameAction
= col
->action("rename");
1344 QAction
* moveToTrashAction
= col
->action("move_to_trash");
1345 QAction
* deleteAction
= col
->action("delete");
1346 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
1347 QAction
* deleteWithTrashShortcut
= col
->action("delete_shortcut"); // see DolphinViewActionHandler
1349 KonqFileItemCapabilities
capabilities(list
);
1350 const bool enableMoveToTrash
= capabilities
.isLocal() && capabilities
.supportsMoving();
1352 renameAction
->setEnabled(capabilities
.supportsMoving());
1353 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1354 deleteAction
->setEnabled(capabilities
.supportsDeleting());
1355 deleteWithTrashShortcut
->setEnabled(capabilities
.supportsDeleting() && !enableMoveToTrash
);
1356 cutAction
->setEnabled(capabilities
.supportsMoving());
1358 updatePasteAction();
1361 void DolphinMainWindow::updateViewActions()
1363 m_actionHandler
->updateViewActions();
1365 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1366 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
1368 updateSplitAction();
1370 QAction
* editableLocactionAction
= actionCollection()->action("editable_location");
1371 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
1372 editableLocactionAction
->setChecked(urlNavigator
->isUrlEditable());
1375 void DolphinMainWindow::updateGoActions()
1377 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
1378 const KUrl
& currentUrl
= m_activeViewContainer
->url();
1379 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
1382 void DolphinMainWindow::rememberClosedTab(int index
)
1384 KMenu
* tabsMenu
= m_recentTabsMenu
->menu();
1386 const QString primaryPath
= m_viewTab
[index
].primaryView
->url().path();
1387 const QString iconName
= KMimeType::iconNameForUrl(primaryPath
);
1389 const QFontMetrics fm
= fontMetrics();
1390 const QString actionText
= fm
.elidedText(primaryPath
, Qt::ElideMiddle
, fm
.maxWidth() * 20);
1392 QAction
* action
= new QAction(actionText
, tabsMenu
);
1394 ClosedTab closedTab
;
1395 closedTab
.primaryUrl
= m_viewTab
[index
].primaryView
->url();
1397 if (m_viewTab
[index
].secondaryView
!= 0) {
1398 closedTab
.secondaryUrl
= m_viewTab
[index
].secondaryView
->url();
1399 closedTab
.isSplit
= true;
1401 closedTab
.isSplit
= false;
1404 action
->setData(QVariant::fromValue(closedTab
));
1405 action
->setIcon(KIcon(iconName
));
1407 // add the closed tab menu entry after the separator and
1408 // "Empty Recently Closed Tabs" entry
1409 if (tabsMenu
->actions().size() == 2) {
1410 tabsMenu
->addAction(action
);
1412 tabsMenu
->insertAction(tabsMenu
->actions().at(2), action
);
1415 // assure that only up to 8 closed tabs are shown in the menu
1416 if (tabsMenu
->actions().size() > 8) {
1417 tabsMenu
->removeAction(tabsMenu
->actions().last());
1419 actionCollection()->action("closed_tabs")->setEnabled(true);
1420 KAcceleratorManager::manage(tabsMenu
);
1423 void DolphinMainWindow::clearStatusBar()
1425 m_activeViewContainer
->statusBar()->clear();
1428 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
1430 connect(container
, SIGNAL(showFilterBarChanged(bool)),
1431 this, SLOT(updateFilterBarAction(bool)));
1433 DolphinView
* view
= container
->view();
1434 connect(view
, SIGNAL(selectionChanged(KFileItemList
)),
1435 this, SLOT(slotSelectionChanged(KFileItemList
)));
1436 connect(view
, SIGNAL(requestItemInfo(KFileItem
)),
1437 this, SLOT(slotRequestItemInfo(KFileItem
)));
1438 connect(view
, SIGNAL(activated()),
1439 this, SLOT(toggleActiveView()));
1440 connect(view
, SIGNAL(tabRequested(const KUrl
&)),
1441 this, SLOT(openNewTab(const KUrl
&)));
1443 const KUrlNavigator
* navigator
= container
->urlNavigator();
1444 connect(navigator
, SIGNAL(urlChanged(const KUrl
&)),
1445 this, SLOT(changeUrl(const KUrl
&)));
1446 connect(navigator
, SIGNAL(historyChanged()),
1447 this, SLOT(updateHistory()));
1448 connect(navigator
, SIGNAL(editableStateChanged(bool)),
1449 this, SLOT(slotEditableStateChanged(bool)));
1452 void DolphinMainWindow::updateSplitAction()
1454 QAction
* splitAction
= actionCollection()->action("split_view");
1455 if (m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
1456 if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
1457 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
1458 splitAction
->setIcon(KIcon("view-right-close"));
1460 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
1461 splitAction
->setIcon(KIcon("view-left-close"));
1464 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
1465 splitAction
->setIcon(KIcon("view-right-new"));
1469 QString
DolphinMainWindow::tabName(const KUrl
& url
) const
1472 if (url
.equals(KUrl("file:///"))) {
1475 name
= url
.fileName();
1476 if (name
.isEmpty()) {
1477 name
= url
.protocol();
1479 // Make sure that a '&' inside the directory name is displayed correctly
1480 // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
1481 name
.replace('&', "&&");
1487 bool DolphinMainWindow::isKompareInstalled() const
1489 static bool initialized
= false;
1490 static bool installed
= false;
1492 // TODO: maybe replace this approach later by using a menu
1493 // plugin like kdiff3plugin.cpp
1494 installed
= !KGlobal::dirs()->findExe("kompare").isEmpty();
1500 void DolphinMainWindow::createSecondaryView(int tabIndex
)
1502 QSplitter
* splitter
= m_viewTab
[tabIndex
].splitter
;
1503 const int newWidth
= (m_viewTab
[tabIndex
].primaryView
->width() - splitter
->handleWidth()) / 2;
1505 const DolphinView
* view
= m_viewTab
[tabIndex
].primaryView
->view();
1506 m_viewTab
[tabIndex
].secondaryView
= new DolphinViewContainer(this, 0, view
->rootUrl());
1507 splitter
->addWidget(m_viewTab
[tabIndex
].secondaryView
);
1508 splitter
->setSizes(QList
<int>() << newWidth
<< newWidth
);
1509 connectViewSignals(m_viewTab
[tabIndex
].secondaryView
);
1510 m_viewTab
[tabIndex
].secondaryView
->view()->reload();
1511 m_viewTab
[tabIndex
].secondaryView
->setActive(false);
1512 m_viewTab
[tabIndex
].secondaryView
->show();
1515 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
1516 KIO::FileUndoManager::UiInterface()
1520 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
1524 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
1526 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
1528 DolphinStatusBar
* statusBar
= mainWin
->activeViewContainer()->statusBar();
1529 statusBar
->setMessage(job
->errorString(), DolphinStatusBar::Error
);
1531 KIO::FileUndoManager::UiInterface::jobError(job
);
1535 #include "dolphinmainwindow.moc"