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 const int tabCount
= m_viewTab
.count();
482 group
.writeEntry("Tab Count", tabCount
);
483 group
.writeEntry("Active Tab Index", m_tabBar
->currentIndex());
485 for (int i
= 0; i
< tabCount
; ++i
) {
486 const DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
487 group
.writeEntry(tabProperty("Primary URL", i
), cont
->url().url());
488 group
.writeEntry(tabProperty("Primary Editable", i
), cont
->isUrlEditable());
490 cont
= m_viewTab
[i
].secondaryView
;
492 group
.writeEntry(tabProperty("Secondary URL", i
), cont
->url().url());
493 group
.writeEntry(tabProperty("Secondary Editable", i
), cont
->isUrlEditable());
498 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
500 const int tabCount
= group
.readEntry("Tab Count", 1);
501 for (int i
= 0; i
< tabCount
; ++i
) {
502 DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
504 cont
->setUrl(group
.readEntry(tabProperty("Primary URL", i
)));
505 const bool editable
= group
.readEntry(tabProperty("Primary Editable", i
), false);
506 cont
->urlNavigator()->setUrlEditable(editable
);
508 cont
= m_viewTab
[i
].secondaryView
;
509 const QString secondaryUrl
= group
.readEntry(tabProperty("Secondary URL", i
));
510 if (!secondaryUrl
.isEmpty()) {
512 // a secondary view should be shown, but no one is available
513 // currently -> create a new view
515 cont
= m_viewTab
[i
].secondaryView
;
519 cont
->setUrl(secondaryUrl
);
520 const bool editable
= group
.readEntry(tabProperty("Secondary Editable", i
), false);
521 cont
->urlNavigator()->setUrlEditable(editable
);
522 } else if (cont
!= 0) {
523 // no secondary view should be shown, but the default setting shows
524 // one already -> close the view
528 // openNewTab() needs to be called only tabCount - 1 times
529 if (i
!= tabCount
- 1) {
534 const int index
= group
.readEntry("Active Tab Index", 0);
535 m_tabBar
->setCurrentIndex(index
);
538 void DolphinMainWindow::updateNewMenu()
540 m_newMenu
->slotCheckUpToDate();
541 m_newMenu
->setPopupFiles(activeViewContainer()->url());
544 void DolphinMainWindow::quit()
549 void DolphinMainWindow::showErrorMessage(const QString
& message
)
551 if (!message
.isEmpty()) {
552 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
553 statusBar
->setMessage(message
, DolphinStatusBar::Error
);
557 void DolphinMainWindow::slotUndoAvailable(bool available
)
559 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
560 if (undoAction
!= 0) {
561 undoAction
->setEnabled(available
);
565 void DolphinMainWindow::restoreClosedTab(QAction
* action
)
567 if (action
->data().toBool()) {
568 // clear all actions except the "Empty Recently Closed Tabs"
569 // action and the separator
570 QList
<QAction
*> actions
= m_recentTabsMenu
->menu()->actions();
571 const int count
= actions
.size();
572 for (int i
= 2; i
< count
; ++i
) {
573 m_recentTabsMenu
->menu()->removeAction(actions
.at(i
));
576 const ClosedTab closedTab
= action
->data().value
<ClosedTab
>();
577 openNewTab(closedTab
.primaryUrl
);
578 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
580 if (closedTab
.isSplit
) {
581 // create secondary view
583 m_viewTab
[m_tabIndex
].secondaryView
->setUrl(closedTab
.secondaryUrl
);
586 m_recentTabsMenu
->removeAction(action
);
589 if (m_recentTabsMenu
->menu()->actions().count() == 2) {
590 m_recentTabsMenu
->setEnabled(false);
594 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
596 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
597 if (undoAction
!= 0) {
598 undoAction
->setText(text
);
602 void DolphinMainWindow::undo()
605 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
606 KIO::FileUndoManager::self()->undo();
609 void DolphinMainWindow::cut()
611 m_activeViewContainer
->view()->cutSelectedItems();
614 void DolphinMainWindow::copy()
616 m_activeViewContainer
->view()->copySelectedItems();
619 void DolphinMainWindow::paste()
621 m_activeViewContainer
->view()->paste();
624 void DolphinMainWindow::updatePasteAction()
626 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
627 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
628 pasteAction
->setEnabled(pasteInfo
.first
);
629 pasteAction
->setText(pasteInfo
.second
);
632 void DolphinMainWindow::selectAll()
636 // if the URL navigator is editable and focused, select the whole
637 // URL instead of all items of the view
639 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
640 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit();
641 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
642 lineEdit
->hasFocus();
644 lineEdit
->selectAll();
646 m_activeViewContainer
->view()->selectAll();
650 void DolphinMainWindow::invertSelection()
653 m_activeViewContainer
->view()->invertSelection();
656 void DolphinMainWindow::toggleSplitView()
658 if (m_viewTab
[m_tabIndex
].secondaryView
== 0) {
659 createSecondaryView(m_tabIndex
);
660 setActiveViewContainer(m_viewTab
[m_tabIndex
].secondaryView
);
661 } else if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
662 // remove secondary view
663 m_viewTab
[m_tabIndex
].secondaryView
->close();
664 m_viewTab
[m_tabIndex
].secondaryView
->deleteLater();
665 m_viewTab
[m_tabIndex
].secondaryView
= 0;
667 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
669 // The primary view is active and should be closed. Hence from a users point of view
670 // the content of the secondary view should be moved to the primary view.
671 // From an implementation point of view it is more efficient to close
672 // the primary view and exchange the internal pointers afterwards.
674 m_viewTab
[m_tabIndex
].primaryView
->close();
675 m_viewTab
[m_tabIndex
].primaryView
->deleteLater();
676 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
677 m_viewTab
[m_tabIndex
].secondaryView
= 0;
679 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
685 void DolphinMainWindow::reloadView()
688 m_activeViewContainer
->view()->reload();
691 void DolphinMainWindow::stopLoading()
695 void DolphinMainWindow::toggleFilterBarVisibility(bool show
)
697 m_activeViewContainer
->showFilterBar(show
);
700 void DolphinMainWindow::toggleEditLocation()
704 QAction
* action
= actionCollection()->action("editable_location");
705 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
706 urlNavigator
->setUrlEditable(action
->isChecked());
709 void DolphinMainWindow::replaceLocation()
711 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
712 navigator
->setUrlEditable(true);
713 navigator
->setFocus();
715 // select the whole text of the combo box editor
716 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit();
717 const QString text
= lineEdit
->text();
718 lineEdit
->setSelection(0, text
.length());
721 void DolphinMainWindow::goBack()
724 m_activeViewContainer
->urlNavigator()->goBack();
727 void DolphinMainWindow::goForward()
730 m_activeViewContainer
->urlNavigator()->goForward();
733 void DolphinMainWindow::goUp()
736 m_activeViewContainer
->urlNavigator()->goUp();
739 void DolphinMainWindow::goHome()
742 m_activeViewContainer
->urlNavigator()->goHome();
745 void DolphinMainWindow::compareFiles()
747 // The method is only invoked if exactly 2 files have
748 // been selected. The selected files may be:
749 // - both in the primary view
750 // - both in the secondary view
751 // - one in the primary view and the other in the secondary
753 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
757 KUrl::List urls
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedUrls();
759 switch (urls
.count()) {
761 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
!= 0);
762 urls
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedUrls();
763 Q_ASSERT(urls
.count() == 2);
771 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
!= 0);
772 urls
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedUrls();
773 Q_ASSERT(urls
.count() == 1);
785 // may not happen: compareFiles may only get invoked if 2
786 // files are selected
791 QString
command("kompare -c \"");
792 command
.append(urlA
.pathOrUrl());
793 command
.append("\" \"");
794 command
.append(urlB
.pathOrUrl());
795 command
.append('\"');
796 KRun::runCommand(command
, "Kompare", "kompare", this);
799 void DolphinMainWindow::toggleShowMenuBar()
801 const bool visible
= menuBar()->isVisible();
802 menuBar()->setVisible(!visible
);
805 void DolphinMainWindow::openTerminal()
807 KToolInvocation::invokeTerminal(QString(), m_activeViewContainer
->url().path());
810 void DolphinMainWindow::editSettings()
812 if (m_settingsDialog
== 0) {
813 const KUrl
& url
= activeViewContainer()->url();
814 m_settingsDialog
= new DolphinSettingsDialog(url
, this);
815 m_settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
816 m_settingsDialog
->show();
818 m_settingsDialog
->raise();
822 void DolphinMainWindow::setActiveTab(int index
)
824 Q_ASSERT(index
>= 0);
825 Q_ASSERT(index
< m_viewTab
.count());
826 if (index
== m_tabIndex
) {
830 // hide current tab content
831 ViewTab
& hiddenTab
= m_viewTab
[m_tabIndex
];
832 hiddenTab
.isPrimaryViewActive
= hiddenTab
.primaryView
->isActive();
833 hiddenTab
.primaryView
->setActive(false);
834 if (hiddenTab
.secondaryView
!= 0) {
835 hiddenTab
.secondaryView
->setActive(false);
837 QSplitter
* splitter
= m_viewTab
[m_tabIndex
].splitter
;
839 m_centralWidgetLayout
->removeWidget(splitter
);
841 // show active tab content
844 ViewTab
& viewTab
= m_viewTab
[index
];
845 m_centralWidgetLayout
->addWidget(viewTab
.splitter
);
846 viewTab
.primaryView
->show();
847 if (viewTab
.secondaryView
!= 0) {
848 viewTab
.secondaryView
->show();
850 viewTab
.splitter
->show();
852 setActiveViewContainer(viewTab
.isPrimaryViewActive
? viewTab
.primaryView
:
853 viewTab
.secondaryView
);
856 void DolphinMainWindow::closeTab()
858 closeTab(m_tabBar
->currentIndex());
861 void DolphinMainWindow::closeTab(int index
)
863 Q_ASSERT(index
>= 0);
864 Q_ASSERT(index
< m_viewTab
.count());
865 if (m_viewTab
.count() == 1) {
866 // the last tab may never get closed
870 if (index
== m_tabIndex
) {
871 // The tab that should be closed is the active tab. Activate the
872 // previous tab before closing the tab.
873 m_tabBar
->setCurrentIndex((index
> 0) ? index
- 1 : 1);
875 rememberClosedTab(index
);
878 m_viewTab
[index
].primaryView
->deleteLater();
879 if (m_viewTab
[index
].secondaryView
!= 0) {
880 m_viewTab
[index
].secondaryView
->deleteLater();
882 m_viewTab
[index
].splitter
->deleteLater();
883 m_viewTab
.erase(m_viewTab
.begin() + index
);
885 m_tabBar
->blockSignals(true);
886 m_tabBar
->removeTab(index
);
888 if (m_tabIndex
> index
) {
890 Q_ASSERT(m_tabIndex
>= 0);
893 // if only one tab is left, also remove the tab entry so that
894 // closing the last tab is not possible
895 if (m_viewTab
.count() == 1) {
896 m_tabBar
->removeTab(0);
897 actionCollection()->action("close_tab")->setEnabled(false);
899 m_tabBar
->blockSignals(false);
903 void DolphinMainWindow::openTabContextMenu(int index
, const QPoint
& pos
)
907 QAction
* newTabAction
= menu
.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab"));
908 newTabAction
->setShortcut(actionCollection()->action("new_tab")->shortcut());
910 QAction
* closeOtherTabsAction
= menu
.addAction(KIcon("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs"));
912 QAction
* closeTabAction
= menu
.addAction(KIcon("tab-close"), i18nc("@action:inmenu", "Close Tab"));
913 closeTabAction
->setShortcut(actionCollection()->action("close_tab")->shortcut());
914 QAction
* selectedAction
= menu
.exec(pos
);
915 if (selectedAction
== newTabAction
) {
916 const ViewTab
& tab
= m_viewTab
[index
];
917 Q_ASSERT(tab
.primaryView
!= 0);
918 const KUrl url
= (tab
.secondaryView
!= 0) && tab
.secondaryView
->isActive() ?
919 tab
.secondaryView
->url() : tab
.primaryView
->url();
921 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
922 } else if (selectedAction
== closeOtherTabsAction
) {
923 const int count
= m_tabBar
->count();
924 for (int i
= 0; i
< index
; ++i
) {
927 for (int i
= index
+ 1; i
< count
; ++i
) {
930 } else if (selectedAction
== closeTabAction
) {
935 void DolphinMainWindow::handlePlacesClick(const KUrl
& url
, Qt::MouseButtons buttons
)
937 if (buttons
& Qt::MidButton
) {
939 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
945 void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent
* event
, bool& canDecode
)
947 canDecode
= KUrl::List::canDecode(event
->mimeData());
950 void DolphinMainWindow::searchItems(const KUrl
& url
)
952 m_activeViewContainer
->setUrl(url
);
955 void DolphinMainWindow::init()
957 DolphinSettings
& settings
= DolphinSettings::instance();
959 // Check whether Dolphin runs the first time. If yes then
960 // a proper default window size is given at the end of DolphinMainWindow::init().
961 GeneralSettings
* generalSettings
= settings
.generalSettings();
962 const bool firstRun
= generalSettings
->firstRun();
964 generalSettings
->setViewPropsTimestamp(QDateTime::currentDateTime());
967 setAcceptDrops(true);
969 m_viewTab
[m_tabIndex
].splitter
= new QSplitter(this);
973 const KUrl
& homeUrl
= generalSettings
->homeUrl();
974 setCaption(homeUrl
.fileName());
975 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
976 connect(m_actionHandler
, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
977 ViewProperties
props(homeUrl
);
978 m_viewTab
[m_tabIndex
].primaryView
= new DolphinViewContainer(this,
979 m_viewTab
[m_tabIndex
].splitter
,
982 m_activeViewContainer
= m_viewTab
[m_tabIndex
].primaryView
;
983 connectViewSignals(m_activeViewContainer
);
984 DolphinView
* view
= m_activeViewContainer
->view();
986 m_activeViewContainer
->show();
987 m_actionHandler
->setCurrentView(view
);
989 m_tabBar
= new KTabBar(this);
990 m_tabBar
->setMovable(true);
991 m_tabBar
->setTabsClosable(true);
992 connect(m_tabBar
, SIGNAL(currentChanged(int)),
993 this, SLOT(setActiveTab(int)));
994 connect(m_tabBar
, SIGNAL(tabCloseRequested(int)),
995 this, SLOT(closeTab(int)));
996 connect(m_tabBar
, SIGNAL(contextMenu(int, const QPoint
&)),
997 this, SLOT(openTabContextMenu(int, const QPoint
&)));
998 connect(m_tabBar
, SIGNAL(newTabRequest()),
999 this, SLOT(openNewTab()));
1000 connect(m_tabBar
, SIGNAL(testCanDecode(const QDragMoveEvent
*, bool&)),
1001 this, SLOT(slotTestCanDecode(const QDragMoveEvent
*, bool&)));
1002 connect(m_tabBar
, SIGNAL(wheelDelta(int)),
1003 this, SLOT(slotWheelMoved(int)));
1004 connect(m_tabBar
, SIGNAL(mouseMiddleClick(int)),
1005 this, SLOT(closeTab(int)));
1007 m_tabBar
->blockSignals(true); // signals get unblocked after at least 2 tabs are open
1009 QWidget
* centralWidget
= new QWidget(this);
1010 m_centralWidgetLayout
= new QVBoxLayout(centralWidget
);
1011 m_centralWidgetLayout
->setSpacing(0);
1012 m_centralWidgetLayout
->setMargin(0);
1013 m_centralWidgetLayout
->addWidget(m_tabBar
);
1014 m_centralWidgetLayout
->addWidget(m_viewTab
[m_tabIndex
].splitter
);
1016 setCentralWidget(centralWidget
);
1018 emit
urlChanged(homeUrl
);
1020 setupGUI(Keys
| Save
| Create
| ToolBar
);
1022 m_searchBox
->setParent(toolBar("searchToolBar"));
1023 m_searchBox
->show();
1025 stateChanged("new_file");
1027 QClipboard
* clipboard
= QApplication::clipboard();
1028 connect(clipboard
, SIGNAL(dataChanged()),
1029 this, SLOT(updatePasteAction()));
1030 updatePasteAction();
1033 if (generalSettings
->splitView()) {
1036 updateViewActions();
1038 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1039 showFilterBarAction
->setChecked(generalSettings
->filterBar());
1042 // assure a proper default size if Dolphin runs the first time
1046 m_showMenuBar
->setChecked(!menuBar()->isHidden()); // workaround for bug #171080
1049 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer
* viewContainer
)
1051 Q_ASSERT(viewContainer
!= 0);
1052 Q_ASSERT((viewContainer
== m_viewTab
[m_tabIndex
].primaryView
) ||
1053 (viewContainer
== m_viewTab
[m_tabIndex
].secondaryView
));
1054 if (m_activeViewContainer
== viewContainer
) {
1058 m_activeViewContainer
->setActive(false);
1059 m_activeViewContainer
= viewContainer
;
1061 // Activating the view container might trigger a recursive setActiveViewContainer() call
1062 // inside DolphinMainWindow::toggleActiveView() when having a split view. Temporary
1063 // disconnect the activated() signal in this case:
1064 disconnect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1065 m_activeViewContainer
->setActive(true);
1066 connect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1068 m_actionHandler
->setCurrentView(viewContainer
->view());
1071 updateEditActions();
1072 updateViewActions();
1075 const KUrl
& url
= m_activeViewContainer
->url();
1076 setCaption(url
.fileName());
1077 if (m_viewTab
.count() > 1 && m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
1078 m_tabBar
->setTabText(m_tabIndex
, tabName(url
));
1079 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(KMimeType::iconNameForUrl(url
)));
1082 emit
urlChanged(url
);
1085 void DolphinMainWindow::setupActions()
1087 // setup 'File' menu
1088 m_newMenu
= new DolphinNewMenu(this, this);
1089 KMenu
* menu
= m_newMenu
->menu();
1090 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1091 menu
->setIcon(KIcon("document-new"));
1092 connect(menu
, SIGNAL(aboutToShow()),
1093 this, SLOT(updateNewMenu()));
1095 KAction
* newWindow
= actionCollection()->addAction("new_window");
1096 newWindow
->setIcon(KIcon("window-new"));
1097 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1098 newWindow
->setShortcut(Qt::CTRL
| Qt::Key_N
);
1099 connect(newWindow
, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1101 KAction
* newTab
= actionCollection()->addAction("new_tab");
1102 newTab
->setIcon(KIcon("tab-new"));
1103 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1104 newTab
->setShortcut(KShortcut(Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
));
1105 connect(newTab
, SIGNAL(triggered()), this, SLOT(openNewTab()));
1107 KAction
* closeTab
= actionCollection()->addAction("close_tab");
1108 closeTab
->setIcon(KIcon("tab-close"));
1109 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1110 closeTab
->setShortcut(Qt::CTRL
| Qt::Key_W
);
1111 closeTab
->setEnabled(false);
1112 connect(closeTab
, SIGNAL(triggered()), this, SLOT(closeTab()));
1114 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1116 // setup 'Edit' menu
1117 KStandardAction::undo(this,
1119 actionCollection());
1121 // need to remove shift+del from cut action, else the shortcut for deletejob
1123 KAction
* cut
= KStandardAction::cut(this, SLOT(cut()), actionCollection());
1124 KShortcut cutShortcut
= cut
->shortcut();
1125 cutShortcut
.remove(Qt::SHIFT
+ Qt::Key_Delete
, KShortcut::KeepEmpty
);
1126 cut
->setShortcut(cutShortcut
);
1127 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1128 KStandardAction::paste(this, SLOT(paste()), actionCollection());
1130 KAction
* selectAll
= actionCollection()->addAction("select_all");
1131 selectAll
->setText(i18nc("@action:inmenu Edit", "Select All"));
1132 selectAll
->setShortcut(Qt::CTRL
+ Qt::Key_A
);
1133 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
1135 KAction
* invertSelection
= actionCollection()->addAction("invert_selection");
1136 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1137 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1138 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
1140 // setup 'View' menu
1141 // (note that most of it is set up in DolphinViewActionHandler)
1143 KAction
* split
= actionCollection()->addAction("split_view");
1144 split
->setShortcut(Qt::Key_F3
);
1145 updateSplitAction();
1146 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1148 KAction
* reload
= actionCollection()->addAction("reload");
1149 reload
->setText(i18nc("@action:inmenu View", "Reload"));
1150 reload
->setShortcut(Qt::Key_F5
);
1151 reload
->setIcon(KIcon("view-refresh"));
1152 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
1154 KAction
* stop
= actionCollection()->addAction("stop");
1155 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1156 stop
->setIcon(KIcon("process-stop"));
1157 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
1159 KToggleAction
* showFullLocation
= actionCollection()->add
<KToggleAction
>("editable_location");
1160 showFullLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1161 showFullLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
1162 connect(showFullLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1164 KAction
* replaceLocation
= actionCollection()->addAction("replace_location");
1165 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1166 replaceLocation
->setShortcut(Qt::Key_F6
);
1167 connect(replaceLocation
, SIGNAL(triggered()), this, SLOT(replaceLocation()));
1170 KAction
* backAction
= KStandardAction::back(this, SLOT(goBack()), actionCollection());
1171 KShortcut backShortcut
= backAction
->shortcut();
1172 backShortcut
.setAlternate(Qt::Key_Backspace
);
1173 backAction
->setShortcut(backShortcut
);
1175 m_recentTabsMenu
= new KActionMenu(i18n("Recently Closed Tabs"), this);
1176 m_recentTabsMenu
->setIcon(KIcon("edit-undo"));
1177 actionCollection()->addAction("closed_tabs", m_recentTabsMenu
);
1178 connect(m_recentTabsMenu
->menu(), SIGNAL(triggered(QAction
*)),
1179 this, SLOT(restoreClosedTab(QAction
*)));
1181 QAction
* action
= new QAction("Empty Recently Closed Tabs", m_recentTabsMenu
);
1182 action
->setIcon(KIcon("edit-clear-list"));
1183 action
->setData(QVariant::fromValue(true));
1184 m_recentTabsMenu
->addAction(action
);
1185 m_recentTabsMenu
->addSeparator();
1186 m_recentTabsMenu
->setEnabled(false);
1188 KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1189 KStandardAction::up(this, SLOT(goUp()), actionCollection());
1190 KStandardAction::home(this, SLOT(goHome()), actionCollection());
1192 // setup 'Tools' menu
1193 KToggleAction
* showSearchBar
= actionCollection()->add
<KToggleAction
>("show_search_bar");
1194 showSearchBar
->setText(i18nc("@action:inmenu Tools", "Show Search Bar"));
1195 showSearchBar
->setShortcut(Qt::CTRL
| Qt::Key_S
);
1196 connect(showSearchBar
, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
1198 KToggleAction
* showFilterBar
= actionCollection()->add
<KToggleAction
>("show_filter_bar");
1199 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1200 showFilterBar
->setShortcut(Qt::CTRL
| Qt::Key_I
);
1201 connect(showFilterBar
, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
1203 KAction
* compareFiles
= actionCollection()->addAction("compare_files");
1204 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1205 compareFiles
->setIcon(KIcon("kompare"));
1206 compareFiles
->setEnabled(false);
1207 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
1209 KAction
* openTerminal
= actionCollection()->addAction("open_terminal");
1210 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1211 openTerminal
->setIcon(KIcon("terminal"));
1212 openTerminal
->setShortcut(Qt::SHIFT
| Qt::Key_F4
);
1213 connect(openTerminal
, SIGNAL(triggered()), this, SLOT(openTerminal()));
1215 // setup 'Settings' menu
1216 m_showMenuBar
= KStandardAction::showMenubar(this, SLOT(toggleShowMenuBar()), actionCollection());
1217 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1219 // not in menu actions
1220 KAction
* activateNextTab
= actionCollection()->addAction("activate_next_tab");
1221 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1222 connect(activateNextTab
, SIGNAL(triggered()), SLOT(activateNextTab()));
1223 activateNextTab
->setShortcuts(QApplication::isRightToLeft() ? KStandardShortcut::tabPrev() :
1224 KStandardShortcut::tabNext());
1226 KAction
* activatePrevTab
= actionCollection()->addAction("activate_prev_tab");
1227 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1228 connect(activatePrevTab
, SIGNAL(triggered()), SLOT(activatePrevTab()));
1229 activatePrevTab
->setShortcuts(QApplication::isRightToLeft() ? KStandardShortcut::tabNext() :
1230 KStandardShortcut::tabPrev());
1233 KAction
* openInNewTab
= actionCollection()->addAction("open_in_new_tab");
1234 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1235 openInNewTab
->setIcon(KIcon("tab-new"));
1236 connect(openInNewTab
, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1238 KAction
* openInNewWindow
= actionCollection()->addAction("open_in_new_window");
1239 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1240 openInNewWindow
->setIcon(KIcon("window-new"));
1241 connect(openInNewWindow
, SIGNAL(triggered()), this, SLOT(openInNewWindow()));
1244 m_searchBox
= new DolphinSearchBox(this);
1245 connect(m_searchBox
, SIGNAL(search(KUrl
)), this, SLOT(searchItems(KUrl
)));
1247 KAction
* search
= new KAction(this);
1248 actionCollection()->addAction("search_bar", search
);
1249 search
->setText(i18nc("@action:inmenu", "Search Bar"));
1250 search
->setDefaultWidget(m_searchBox
);
1251 search
->setShortcutConfigurable(false);
1254 void DolphinMainWindow::setupDockWidgets()
1256 // setup "Information"
1257 QDockWidget
* infoDock
= new QDockWidget(i18nc("@title:window", "Information"));
1258 infoDock
->setObjectName("infoDock");
1259 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1260 Panel
* infoPanel
= new InformationPanel(infoDock
);
1261 infoDock
->setWidget(infoPanel
);
1263 QAction
* infoAction
= infoDock
->toggleViewAction();
1264 infoAction
->setText(i18nc("@title:window", "Information"));
1265 infoAction
->setShortcut(Qt::Key_F11
);
1266 infoAction
->setIcon(KIcon("dialog-information"));
1267 actionCollection()->addAction("show_info_panel", infoDock
->toggleViewAction());
1269 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1270 connect(this, SIGNAL(urlChanged(KUrl
)),
1271 infoPanel
, SLOT(setUrl(KUrl
)));
1272 connect(this, SIGNAL(selectionChanged(KFileItemList
)),
1273 infoPanel
, SLOT(setSelection(KFileItemList
)));
1274 connect(this, SIGNAL(requestItemInfo(KFileItem
)),
1275 infoPanel
, SLOT(requestDelayedItemInfo(KFileItem
)));
1278 QDockWidget
* foldersDock
= new QDockWidget(i18nc("@title:window", "Folders"));
1279 foldersDock
->setObjectName("foldersDock");
1280 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1281 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1282 foldersDock
->setWidget(foldersPanel
);
1284 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1285 foldersAction
->setText(i18nc("@title:window", "Folders"));
1286 foldersAction
->setShortcut(Qt::Key_F7
);
1287 foldersAction
->setIcon(KIcon("folder"));
1288 actionCollection()->addAction("show_folders_panel", foldersDock
->toggleViewAction());
1290 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1291 connect(this, SIGNAL(urlChanged(KUrl
)),
1292 foldersPanel
, SLOT(setUrl(KUrl
)));
1293 connect(foldersPanel
, SIGNAL(changeUrl(KUrl
, Qt::MouseButtons
)),
1294 this, SLOT(handlePlacesClick(KUrl
, Qt::MouseButtons
)));
1295 connect(foldersPanel
, SIGNAL(changeSelection(KFileItemList
)),
1296 this, SLOT(changeSelection(KFileItemList
)));
1300 QDockWidget
* terminalDock
= new QDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1301 terminalDock
->setObjectName("terminalDock");
1302 terminalDock
->setAllowedAreas(Qt::TopDockWidgetArea
| Qt::BottomDockWidgetArea
);
1303 Panel
* terminalPanel
= new TerminalPanel(terminalDock
);
1304 terminalDock
->setWidget(terminalPanel
);
1306 connect(terminalPanel
, SIGNAL(hideTerminalPanel()), terminalDock
, SLOT(hide()));
1308 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1309 terminalAction
->setText(i18nc("@title:window Shell terminal", "Terminal"));
1310 terminalAction
->setShortcut(Qt::Key_F4
);
1311 terminalAction
->setIcon(KIcon("terminal"));
1312 actionCollection()->addAction("show_terminal_panel", terminalDock
->toggleViewAction());
1314 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1315 connect(this, SIGNAL(urlChanged(KUrl
)),
1316 terminalPanel
, SLOT(setUrl(KUrl
)));
1319 const bool firstRun
= DolphinSettings::instance().generalSettings()->firstRun();
1321 foldersDock
->hide();
1323 terminalDock
->hide();
1327 QDockWidget
* placesDock
= new QDockWidget(i18nc("@title:window", "Places"));
1328 placesDock
->setObjectName("placesDock");
1329 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1331 PlacesPanel
* placesPanel
= new PlacesPanel(placesDock
);
1332 placesDock
->setWidget(placesPanel
);
1333 placesPanel
->setModel(DolphinSettings::instance().placesModel());
1334 placesPanel
->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff
);
1336 QAction
* placesAction
= placesDock
->toggleViewAction();
1337 placesAction
->setText(i18nc("@title:window", "Places"));
1338 placesAction
->setShortcut(Qt::Key_F9
);
1339 placesAction
->setIcon(KIcon("bookmarks"));
1340 actionCollection()->addAction("show_places_panel", placesDock
->toggleViewAction());
1342 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1343 connect(placesPanel
, SIGNAL(urlChanged(KUrl
, Qt::MouseButtons
)),
1344 this, SLOT(handlePlacesClick(KUrl
, Qt::MouseButtons
)));
1345 connect(this, SIGNAL(urlChanged(KUrl
)),
1346 placesPanel
, SLOT(setUrl(KUrl
)));
1349 void DolphinMainWindow::updateEditActions()
1351 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1352 if (list
.isEmpty()) {
1353 stateChanged("has_no_selection");
1355 stateChanged("has_selection");
1357 KActionCollection
* col
= actionCollection();
1358 QAction
* renameAction
= col
->action("rename");
1359 QAction
* moveToTrashAction
= col
->action("move_to_trash");
1360 QAction
* deleteAction
= col
->action("delete");
1361 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
1362 QAction
* deleteWithTrashShortcut
= col
->action("delete_shortcut"); // see DolphinViewActionHandler
1364 KonqFileItemCapabilities
capabilities(list
);
1365 const bool enableMoveToTrash
= capabilities
.isLocal() && capabilities
.supportsMoving();
1367 renameAction
->setEnabled(capabilities
.supportsMoving());
1368 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1369 deleteAction
->setEnabled(capabilities
.supportsDeleting());
1370 deleteWithTrashShortcut
->setEnabled(capabilities
.supportsDeleting() && !enableMoveToTrash
);
1371 cutAction
->setEnabled(capabilities
.supportsMoving());
1373 updatePasteAction();
1376 void DolphinMainWindow::updateViewActions()
1378 m_actionHandler
->updateViewActions();
1380 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1381 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
1383 updateSplitAction();
1385 QAction
* editableLocactionAction
= actionCollection()->action("editable_location");
1386 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
1387 editableLocactionAction
->setChecked(urlNavigator
->isUrlEditable());
1390 void DolphinMainWindow::updateGoActions()
1392 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
1393 const KUrl
& currentUrl
= m_activeViewContainer
->url();
1394 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
1397 void DolphinMainWindow::rememberClosedTab(int index
)
1399 KMenu
* tabsMenu
= m_recentTabsMenu
->menu();
1401 const QString primaryPath
= m_viewTab
[index
].primaryView
->url().path();
1402 const QString iconName
= KMimeType::iconNameForUrl(primaryPath
);
1404 const QFontMetrics fm
= fontMetrics();
1405 const QString actionText
= fm
.elidedText(primaryPath
, Qt::ElideMiddle
, fm
.maxWidth() * 20);
1407 QAction
* action
= new QAction(actionText
, tabsMenu
);
1409 ClosedTab closedTab
;
1410 closedTab
.primaryUrl
= m_viewTab
[index
].primaryView
->url();
1412 if (m_viewTab
[index
].secondaryView
!= 0) {
1413 closedTab
.secondaryUrl
= m_viewTab
[index
].secondaryView
->url();
1414 closedTab
.isSplit
= true;
1416 closedTab
.isSplit
= false;
1419 action
->setData(QVariant::fromValue(closedTab
));
1420 action
->setIcon(KIcon(iconName
));
1422 // add the closed tab menu entry after the separator and
1423 // "Empty Recently Closed Tabs" entry
1424 if (tabsMenu
->actions().size() == 2) {
1425 tabsMenu
->addAction(action
);
1427 tabsMenu
->insertAction(tabsMenu
->actions().at(2), action
);
1430 // assure that only up to 8 closed tabs are shown in the menu
1431 if (tabsMenu
->actions().size() > 8) {
1432 tabsMenu
->removeAction(tabsMenu
->actions().last());
1434 actionCollection()->action("closed_tabs")->setEnabled(true);
1435 KAcceleratorManager::manage(tabsMenu
);
1438 void DolphinMainWindow::clearStatusBar()
1440 m_activeViewContainer
->statusBar()->clear();
1443 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
1445 connect(container
, SIGNAL(showFilterBarChanged(bool)),
1446 this, SLOT(updateFilterBarAction(bool)));
1448 DolphinView
* view
= container
->view();
1449 connect(view
, SIGNAL(selectionChanged(KFileItemList
)),
1450 this, SLOT(slotSelectionChanged(KFileItemList
)));
1451 connect(view
, SIGNAL(requestItemInfo(KFileItem
)),
1452 this, SLOT(slotRequestItemInfo(KFileItem
)));
1453 connect(view
, SIGNAL(activated()),
1454 this, SLOT(toggleActiveView()));
1455 connect(view
, SIGNAL(tabRequested(const KUrl
&)),
1456 this, SLOT(openNewTab(const KUrl
&)));
1458 const KUrlNavigator
* navigator
= container
->urlNavigator();
1459 connect(navigator
, SIGNAL(urlChanged(const KUrl
&)),
1460 this, SLOT(changeUrl(const KUrl
&)));
1461 connect(navigator
, SIGNAL(historyChanged()),
1462 this, SLOT(updateHistory()));
1463 connect(navigator
, SIGNAL(editableStateChanged(bool)),
1464 this, SLOT(slotEditableStateChanged(bool)));
1467 void DolphinMainWindow::updateSplitAction()
1469 QAction
* splitAction
= actionCollection()->action("split_view");
1470 if (m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
1471 if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
1472 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
1473 splitAction
->setIcon(KIcon("view-right-close"));
1475 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
1476 splitAction
->setIcon(KIcon("view-left-close"));
1479 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
1480 splitAction
->setIcon(KIcon("view-right-new"));
1484 QString
DolphinMainWindow::tabName(const KUrl
& url
) const
1487 if (url
.equals(KUrl("file:///"))) {
1490 name
= url
.fileName();
1491 if (name
.isEmpty()) {
1492 name
= url
.protocol();
1494 // Make sure that a '&' inside the directory name is displayed correctly
1495 // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
1496 name
.replace('&', "&&");
1502 bool DolphinMainWindow::isKompareInstalled() const
1504 static bool initialized
= false;
1505 static bool installed
= false;
1507 // TODO: maybe replace this approach later by using a menu
1508 // plugin like kdiff3plugin.cpp
1509 installed
= !KGlobal::dirs()->findExe("kompare").isEmpty();
1515 void DolphinMainWindow::createSecondaryView(int tabIndex
)
1517 QSplitter
* splitter
= m_viewTab
[tabIndex
].splitter
;
1518 const int newWidth
= (m_viewTab
[tabIndex
].primaryView
->width() - splitter
->handleWidth()) / 2;
1520 const DolphinView
* view
= m_viewTab
[tabIndex
].primaryView
->view();
1521 m_viewTab
[tabIndex
].secondaryView
= new DolphinViewContainer(this, 0, view
->rootUrl());
1522 splitter
->addWidget(m_viewTab
[tabIndex
].secondaryView
);
1523 splitter
->setSizes(QList
<int>() << newWidth
<< newWidth
);
1524 connectViewSignals(m_viewTab
[tabIndex
].secondaryView
);
1525 m_viewTab
[tabIndex
].secondaryView
->view()->reload();
1526 m_viewTab
[tabIndex
].secondaryView
->setActive(false);
1527 m_viewTab
[tabIndex
].secondaryView
->show();
1530 QString
DolphinMainWindow::tabProperty(const QString
& property
, int tabIndex
) const
1532 return "Tab " + QString::number(tabIndex
) + ' ' + property
;
1535 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
1536 KIO::FileUndoManager::UiInterface()
1540 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
1544 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
1546 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
1548 DolphinStatusBar
* statusBar
= mainWin
->activeViewContainer()->statusBar();
1549 statusBar
->setMessage(job
->errorString(), DolphinStatusBar::Error
);
1551 KIO::FileUndoManager::UiInterface::jobError(job
);
1555 #include "dolphinmainwindow.moc"