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"
24 #include "dolphinremoteencoding.h"
26 #include <config-nepomuk.h>
28 #include "dolphinapplication.h"
29 #include "dolphinnewmenu.h"
30 #include "settings/dolphinsettings.h"
31 #include "settings/dolphinsettingsdialog.h"
32 #include "dolphinsearchbox.h"
33 #include "dolphinstatusbar.h"
34 #include "dolphinviewcontainer.h"
35 #include "panels/folders/folderspanel.h"
36 #include "panels/places/placespanel.h"
37 #include "panels/information/informationpanel.h"
38 #include "panels/information/metadatawidget.h"
39 #include "mainwindowadaptor.h"
40 #include "viewproperties.h"
43 #include "panels/terminal/terminalpanel.h"
46 #include "dolphin_generalsettings.h"
47 #include "dolphin_iconsmodesettings.h"
48 #include "draganddrophelper.h"
51 #include <kactioncollection.h>
53 #include <kdesktopfile.h>
54 #include <kdeversion.h>
55 #include <kfiledialog.h>
56 #include <kfileplacesmodel.h>
58 #include <klineedit.h>
61 #include <kiconloader.h>
62 #include <kio/netaccess.h>
63 #include <kinputdialog.h>
65 #include <kprotocolmanager.h>
68 #include <kmessagebox.h>
69 #include <kfileitemlistproperties.h>
70 #include <konqmimedata.h>
71 #include <kprotocolinfo.h>
74 #include <kstandarddirs.h>
75 #include <kstatusbar.h>
76 #include <kstandardaction.h>
78 #include <ktoggleaction.h>
79 #include <kurlnavigator.h>
81 #include <kurlcombobox.h>
82 #include <ktoolinvocation.h>
84 #include <QDBusMessage>
89 #include <QDockWidget>
90 #include <kacceleratormanager.h>
93 * Remembers the tab configuration if a tab has been closed.
94 * Each closed tab can be restored by the menu
95 * "Go -> Recently Closed Tabs".
103 Q_DECLARE_METATYPE(ClosedTab
)
105 DolphinMainWindow::DolphinMainWindow(int id
) :
110 m_activeViewContainer(0),
111 m_centralWidgetLayout(0),
120 setObjectName("Dolphin#");
122 m_viewTab
.append(ViewTab());
124 new MainWindowAdaptor(this);
125 QDBusConnection::sessionBus().registerObject(QString("/dolphin/MainWindow%1").arg(m_id
), this);
127 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
128 undoManager
->setUiInterface(new UndoUiInterface());
130 connect(undoManager
, SIGNAL(undoAvailable(bool)),
131 this, SLOT(slotUndoAvailable(bool)));
132 connect(undoManager
, SIGNAL(undoTextChanged(const QString
&)),
133 this, SLOT(slotUndoTextChanged(const QString
&)));
134 connect(undoManager
, SIGNAL(jobRecordingStarted(CommandType
)),
135 this, SLOT(clearStatusBar()));
136 connect(undoManager
, SIGNAL(jobRecordingFinished(CommandType
)),
137 this, SLOT(showCommand(CommandType
)));
138 connect(DolphinSettings::instance().placesModel(), SIGNAL(errorMessage(const QString
&)),
139 this, SLOT(showErrorMessage(const QString
&)));
140 connect(&DragAndDropHelper::instance(), SIGNAL(errorMessage(const QString
&)),
141 this, SLOT(showErrorMessage(const QString
&)));
144 DolphinMainWindow::~DolphinMainWindow()
146 DolphinApplication::app()->removeMainWindow(this);
149 void DolphinMainWindow::toggleViews()
151 if (m_viewTab
[m_tabIndex
].primaryView
== 0) {
155 // move secondary view from the last position of the splitter
156 // to the first position
157 m_viewTab
[m_tabIndex
].splitter
->insertWidget(0, m_viewTab
[m_tabIndex
].secondaryView
);
159 DolphinViewContainer
* container
= m_viewTab
[m_tabIndex
].primaryView
;
160 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
161 m_viewTab
[m_tabIndex
].secondaryView
= container
;
164 void DolphinMainWindow::showCommand(CommandType command
)
166 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
168 case KIO::FileUndoManager::Copy
:
169 statusBar
->setMessage(i18nc("@info:status", "Copy operation completed."),
170 DolphinStatusBar::OperationCompleted
);
172 case KIO::FileUndoManager::Move
:
173 statusBar
->setMessage(i18nc("@info:status", "Move operation completed."),
174 DolphinStatusBar::OperationCompleted
);
176 case KIO::FileUndoManager::Link
:
177 statusBar
->setMessage(i18nc("@info:status", "Link operation completed."),
178 DolphinStatusBar::OperationCompleted
);
180 case KIO::FileUndoManager::Trash
:
181 statusBar
->setMessage(i18nc("@info:status", "Move to trash operation completed."),
182 DolphinStatusBar::OperationCompleted
);
184 case KIO::FileUndoManager::Rename
:
185 statusBar
->setMessage(i18nc("@info:status", "Renaming operation completed."),
186 DolphinStatusBar::OperationCompleted
);
189 case KIO::FileUndoManager::Mkdir
:
190 statusBar
->setMessage(i18nc("@info:status", "Created folder."),
191 DolphinStatusBar::OperationCompleted
);
199 void DolphinMainWindow::refreshViews()
201 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
203 // remember the current active view, as because of
204 // the refreshing the active view might change to
205 // the secondary view
206 DolphinViewContainer
* activeViewContainer
= m_activeViewContainer
;
208 const int tabCount
= m_viewTab
.count();
209 for (int i
= 0; i
< tabCount
; ++i
) {
210 m_viewTab
[i
].primaryView
->refresh();
211 if (m_viewTab
[i
].secondaryView
!= 0) {
212 m_viewTab
[i
].secondaryView
->refresh();
216 setActiveViewContainer(activeViewContainer
);
219 void DolphinMainWindow::pasteIntoFolder()
221 m_activeViewContainer
->view()->pasteIntoFolder();
224 void DolphinMainWindow::changeUrl(const KUrl
& url
)
226 if (!KProtocolManager::supportsListing(url
)) {
227 // The URL navigator only checks for validity, not
228 // if the URL can be listed. An error message is
229 // shown due to DolphinViewContainer::restoreView().
233 DolphinViewContainer
* view
= activeViewContainer();
239 setCaption(url
.fileName());
240 if (m_viewTab
.count() > 1) {
241 m_tabBar
->setTabText(m_tabIndex
, tabName(url
));
243 const QString iconName
= KMimeType::iconNameForUrl(url
);
244 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(iconName
));
245 emit
urlChanged(url
);
249 void DolphinMainWindow::changeSelection(const KFileItemList
& selection
)
251 activeViewContainer()->view()->changeSelection(selection
);
254 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
256 KToggleAction
* editableLocationAction
=
257 static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
258 editableLocationAction
->setChecked(editable
);
261 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
265 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
266 int selectedUrlsCount
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedItemsCount();
267 if (m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
268 selectedUrlsCount
+= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItemsCount();
271 QAction
* compareFilesAction
= actionCollection()->action("compare_files");
272 if (selectedUrlsCount
== 2) {
273 compareFilesAction
->setEnabled(isKompareInstalled());
275 compareFilesAction
->setEnabled(false);
278 m_activeViewContainer
->updateStatusBar();
280 emit
selectionChanged(selection
);
283 void DolphinMainWindow::slotWheelMoved(int wheelDelta
)
285 if (wheelDelta
> 0) {
292 void DolphinMainWindow::slotRequestItemInfo(const KFileItem
& item
)
294 emit
requestItemInfo(item
);
297 void DolphinMainWindow::updateHistory()
299 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
300 const int index
= urlNavigator
->historyIndex();
302 QAction
* backAction
= actionCollection()->action("go_back");
303 if (backAction
!= 0) {
304 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
307 QAction
* forwardAction
= actionCollection()->action("go_forward");
308 if (forwardAction
!= 0) {
309 forwardAction
->setEnabled(index
> 0);
313 void DolphinMainWindow::updateFilterBarAction(bool show
)
315 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
316 showFilterBarAction
->setChecked(show
);
319 void DolphinMainWindow::openNewMainWindow()
321 DolphinApplication::app()->createMainWindow()->show();
324 void DolphinMainWindow::openNewTab()
326 openNewTab(m_activeViewContainer
->url());
327 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
329 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
330 if (navigator
->isUrlEditable()) {
331 // if a new tab is opened and the URL is editable, assure that
332 // the user can edit the URL without manually setting the focus
333 navigator
->setFocus();
337 void DolphinMainWindow::openNewTab(const KUrl
& url
)
339 const KIcon icon
= KIcon(KMimeType::iconNameForUrl(m_activeViewContainer
->url()));
340 if (m_viewTab
.count() == 1) {
341 // Only one view is open currently and hence no tab is shown at
342 // all. Before creating a tab for 'url', provide a tab for the current URL.
343 m_tabBar
->addTab(icon
, tabName(m_activeViewContainer
->url()));
344 m_tabBar
->blockSignals(false);
347 m_tabBar
->addTab(icon
, tabName(url
));
350 viewTab
.splitter
= new QSplitter(this);
351 viewTab
.splitter
->setChildrenCollapsible(false);
352 viewTab
.primaryView
= new DolphinViewContainer(this, viewTab
.splitter
, url
);
353 viewTab
.primaryView
->setActive(false);
354 connectViewSignals(viewTab
.primaryView
);
355 viewTab
.primaryView
->view()->reload();
357 m_viewTab
.append(viewTab
);
359 actionCollection()->action("close_tab")->setEnabled(true);
361 // provide a split view, if the startup settings are set this way
362 const GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
363 if (generalSettings
->splitView()) {
364 const int tabIndex
= m_viewTab
.count() - 1;
365 createSecondaryView(tabIndex
);
366 m_viewTab
[tabIndex
].secondaryView
->setActive(true);
367 m_viewTab
[tabIndex
].isPrimaryViewActive
= false;
371 void DolphinMainWindow::activateNextTab()
373 if ((m_viewTab
.count() == 1) || (m_tabBar
->count() < 2)) {
377 const int tabIndex
= (m_tabBar
->currentIndex() + 1) % m_tabBar
->count();
378 m_tabBar
->setCurrentIndex(tabIndex
);
381 void DolphinMainWindow::activatePrevTab()
383 if ((m_viewTab
.count() == 1) || (m_tabBar
->count() < 2)) {
387 int tabIndex
= m_tabBar
->currentIndex() - 1;
388 if (tabIndex
== -1) {
389 tabIndex
= m_tabBar
->count() - 1;
391 m_tabBar
->setCurrentIndex(tabIndex
);
394 void DolphinMainWindow::openInNewTab()
396 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
397 if ((list
.count() == 1) && list
[0].isDir()) {
398 openNewTab(m_activeViewContainer
->view()->selectedUrls()[0]);
402 void DolphinMainWindow::openInNewWindow()
404 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
405 if ((list
.count() == 1) && list
[0].isDir()) {
406 DolphinMainWindow
* window
= DolphinApplication::app()->createMainWindow();
407 window
->changeUrl(m_activeViewContainer
->view()->selectedUrls()[0]);
412 void DolphinMainWindow::toggleActiveView()
414 if (m_viewTab
[m_tabIndex
].secondaryView
== 0) {
415 // only one view is available
419 Q_ASSERT(m_activeViewContainer
!= 0);
420 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
422 DolphinViewContainer
* left
= m_viewTab
[m_tabIndex
].primaryView
;
423 DolphinViewContainer
* right
= m_viewTab
[m_tabIndex
].secondaryView
;
424 setActiveViewContainer(m_activeViewContainer
== right
? left
: right
);
427 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
429 DolphinSettings
& settings
= DolphinSettings::instance();
430 GeneralSettings
* generalSettings
= settings
.generalSettings();
432 if ((m_viewTab
.count() > 1) && generalSettings
->confirmClosingMultipleTabs()) {
433 // Ask the user if he really wants to quit and close all tabs.
434 // Open a confirmation dialog with 3 buttons:
435 // KDialog::Yes -> Quit
436 // KDialog::No -> Close only the current tab
437 // KDialog::Cancel -> do nothing
438 KDialog
*dialog
= new KDialog(this, Qt::Dialog
);
439 dialog
->setCaption(i18nc("@title:window", "Confirmation"));
440 dialog
->setButtons(KDialog::Yes
| KDialog::No
| KDialog::Cancel
);
441 dialog
->setModal(true);
442 dialog
->showButtonSeparator(true);
443 dialog
->setButtonGuiItem(KDialog::Yes
, KStandardGuiItem::quit());
444 dialog
->setButtonGuiItem(KDialog::No
, KGuiItem(i18n("C&lose Current Tab"), KIcon("tab-close")));
445 dialog
->setButtonGuiItem(KDialog::Cancel
, KStandardGuiItem::cancel());
446 dialog
->setDefaultButton(KDialog::Yes
);
448 bool doNotAskAgainCheckboxResult
= false;
450 const int result
= KMessageBox::createKMessageBox(dialog
,
451 QMessageBox::Warning
,
452 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
454 i18n("Do not ask again"),
455 &doNotAskAgainCheckboxResult
,
456 KMessageBox::Notify
);
458 if (doNotAskAgainCheckboxResult
) {
459 generalSettings
->setConfirmClosingMultipleTabs(false);
467 // Close only the current tab
475 generalSettings
->setFirstRun(false);
479 KXmlGuiWindow::closeEvent(event
);
482 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
484 const int tabCount
= m_viewTab
.count();
485 group
.writeEntry("Tab Count", tabCount
);
486 group
.writeEntry("Active Tab Index", m_tabBar
->currentIndex());
488 for (int i
= 0; i
< tabCount
; ++i
) {
489 const DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
490 group
.writeEntry(tabProperty("Primary URL", i
), cont
->url().url());
491 group
.writeEntry(tabProperty("Primary Editable", i
), cont
->isUrlEditable());
493 cont
= m_viewTab
[i
].secondaryView
;
495 group
.writeEntry(tabProperty("Secondary URL", i
), cont
->url().url());
496 group
.writeEntry(tabProperty("Secondary Editable", i
), cont
->isUrlEditable());
501 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
503 const int tabCount
= group
.readEntry("Tab Count", 1);
504 for (int i
= 0; i
< tabCount
; ++i
) {
505 DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
507 cont
->setUrl(group
.readEntry(tabProperty("Primary URL", i
)));
508 const bool editable
= group
.readEntry(tabProperty("Primary Editable", i
), false);
509 cont
->urlNavigator()->setUrlEditable(editable
);
511 cont
= m_viewTab
[i
].secondaryView
;
512 const QString secondaryUrl
= group
.readEntry(tabProperty("Secondary URL", i
));
513 if (!secondaryUrl
.isEmpty()) {
515 // a secondary view should be shown, but no one is available
516 // currently -> create a new view
518 cont
= m_viewTab
[i
].secondaryView
;
522 cont
->setUrl(secondaryUrl
);
523 const bool editable
= group
.readEntry(tabProperty("Secondary Editable", i
), false);
524 cont
->urlNavigator()->setUrlEditable(editable
);
525 } else if (cont
!= 0) {
526 // no secondary view should be shown, but the default setting shows
527 // one already -> close the view
531 // openNewTab() needs to be called only tabCount - 1 times
532 if (i
!= tabCount
- 1) {
537 const int index
= group
.readEntry("Active Tab Index", 0);
538 m_tabBar
->setCurrentIndex(index
);
541 void DolphinMainWindow::updateNewMenu()
543 m_newMenu
->slotCheckUpToDate();
544 m_newMenu
->setPopupFiles(activeViewContainer()->url());
547 void DolphinMainWindow::createDirectory()
549 m_newMenu
->setPopupFiles(activeViewContainer()->url());
550 m_newMenu
->createDirectory();
553 void DolphinMainWindow::quit()
558 void DolphinMainWindow::showErrorMessage(const QString
& message
)
560 if (!message
.isEmpty()) {
561 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
562 statusBar
->setMessage(message
, DolphinStatusBar::Error
);
566 void DolphinMainWindow::slotUndoAvailable(bool available
)
568 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
569 if (undoAction
!= 0) {
570 undoAction
->setEnabled(available
);
574 void DolphinMainWindow::restoreClosedTab(QAction
* action
)
576 if (action
->data().toBool()) {
577 // clear all actions except the "Empty Recently Closed Tabs"
578 // action and the separator
579 QList
<QAction
*> actions
= m_recentTabsMenu
->menu()->actions();
580 const int count
= actions
.size();
581 for (int i
= 2; i
< count
; ++i
) {
582 m_recentTabsMenu
->menu()->removeAction(actions
.at(i
));
585 const ClosedTab closedTab
= action
->data().value
<ClosedTab
>();
586 openNewTab(closedTab
.primaryUrl
);
587 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
589 if (closedTab
.isSplit
) {
590 // create secondary view
592 m_viewTab
[m_tabIndex
].secondaryView
->setUrl(closedTab
.secondaryUrl
);
595 m_recentTabsMenu
->removeAction(action
);
598 if (m_recentTabsMenu
->menu()->actions().count() == 2) {
599 m_recentTabsMenu
->setEnabled(false);
603 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
605 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
606 if (undoAction
!= 0) {
607 undoAction
->setText(text
);
611 void DolphinMainWindow::undo()
614 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
615 KIO::FileUndoManager::self()->undo();
618 void DolphinMainWindow::cut()
620 m_activeViewContainer
->view()->cutSelectedItems();
623 void DolphinMainWindow::copy()
625 m_activeViewContainer
->view()->copySelectedItems();
628 void DolphinMainWindow::paste()
630 m_activeViewContainer
->view()->paste();
633 void DolphinMainWindow::updatePasteAction()
635 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
636 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
637 pasteAction
->setEnabled(pasteInfo
.first
);
638 pasteAction
->setText(pasteInfo
.second
);
641 void DolphinMainWindow::selectAll()
645 // if the URL navigator is editable and focused, select the whole
646 // URL instead of all items of the view
648 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
649 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit();
650 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
651 lineEdit
->hasFocus();
653 lineEdit
->selectAll();
655 m_activeViewContainer
->view()->selectAll();
659 void DolphinMainWindow::invertSelection()
662 m_activeViewContainer
->view()->invertSelection();
665 void DolphinMainWindow::toggleSplitView()
667 if (m_viewTab
[m_tabIndex
].secondaryView
== 0) {
668 createSecondaryView(m_tabIndex
);
669 setActiveViewContainer(m_viewTab
[m_tabIndex
].secondaryView
);
670 } else if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
671 // remove secondary view
672 m_viewTab
[m_tabIndex
].secondaryView
->close();
673 m_viewTab
[m_tabIndex
].secondaryView
->deleteLater();
674 m_viewTab
[m_tabIndex
].secondaryView
= 0;
676 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
678 // The primary view is active and should be closed. Hence from a users point of view
679 // the content of the secondary view should be moved to the primary view.
680 // From an implementation point of view it is more efficient to close
681 // the primary view and exchange the internal pointers afterwards.
683 m_viewTab
[m_tabIndex
].primaryView
->close();
684 m_viewTab
[m_tabIndex
].primaryView
->deleteLater();
685 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
686 m_viewTab
[m_tabIndex
].secondaryView
= 0;
688 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
694 void DolphinMainWindow::reloadView()
697 m_activeViewContainer
->view()->reload();
700 void DolphinMainWindow::stopLoading()
704 void DolphinMainWindow::toggleFilterBarVisibility(bool show
)
706 m_activeViewContainer
->showFilterBar(show
);
709 void DolphinMainWindow::toggleEditLocation()
713 QAction
* action
= actionCollection()->action("editable_location");
714 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
715 urlNavigator
->setUrlEditable(action
->isChecked());
718 void DolphinMainWindow::replaceLocation()
720 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
721 navigator
->setUrlEditable(true);
722 navigator
->setFocus();
724 // select the whole text of the combo box editor
725 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit();
726 const QString text
= lineEdit
->text();
727 lineEdit
->setSelection(0, text
.length());
730 void DolphinMainWindow::goBack()
733 m_activeViewContainer
->urlNavigator()->goBack();
736 void DolphinMainWindow::goForward()
739 m_activeViewContainer
->urlNavigator()->goForward();
742 void DolphinMainWindow::goUp()
745 m_activeViewContainer
->urlNavigator()->goUp();
748 void DolphinMainWindow::goHome()
751 m_activeViewContainer
->urlNavigator()->goHome();
754 void DolphinMainWindow::compareFiles()
756 // The method is only invoked if exactly 2 files have
757 // been selected. The selected files may be:
758 // - both in the primary view
759 // - both in the secondary view
760 // - one in the primary view and the other in the secondary
762 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
766 KUrl::List urls
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedUrls();
768 switch (urls
.count()) {
770 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
!= 0);
771 urls
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedUrls();
772 Q_ASSERT(urls
.count() == 2);
780 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
!= 0);
781 urls
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedUrls();
782 Q_ASSERT(urls
.count() == 1);
794 // may not happen: compareFiles may only get invoked if 2
795 // files are selected
800 QString
command("kompare -c \"");
801 command
.append(urlA
.pathOrUrl());
802 command
.append("\" \"");
803 command
.append(urlB
.pathOrUrl());
804 command
.append('\"');
805 KRun::runCommand(command
, "Kompare", "kompare", this);
808 void DolphinMainWindow::toggleShowMenuBar()
810 const bool visible
= menuBar()->isVisible();
811 menuBar()->setVisible(!visible
);
814 void DolphinMainWindow::openTerminal()
816 KToolInvocation::invokeTerminal(QString(), m_activeViewContainer
->url().path());
819 void DolphinMainWindow::editSettings()
821 if (m_settingsDialog
== 0) {
822 const KUrl
& url
= activeViewContainer()->url();
823 m_settingsDialog
= new DolphinSettingsDialog(url
, this);
824 m_settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
825 m_settingsDialog
->show();
827 m_settingsDialog
->raise();
831 void DolphinMainWindow::setActiveTab(int index
)
833 Q_ASSERT(index
>= 0);
834 Q_ASSERT(index
< m_viewTab
.count());
835 if (index
== m_tabIndex
) {
839 // hide current tab content
840 ViewTab
& hiddenTab
= m_viewTab
[m_tabIndex
];
841 hiddenTab
.isPrimaryViewActive
= hiddenTab
.primaryView
->isActive();
842 hiddenTab
.primaryView
->setActive(false);
843 if (hiddenTab
.secondaryView
!= 0) {
844 hiddenTab
.secondaryView
->setActive(false);
846 QSplitter
* splitter
= m_viewTab
[m_tabIndex
].splitter
;
848 m_centralWidgetLayout
->removeWidget(splitter
);
850 // show active tab content
853 ViewTab
& viewTab
= m_viewTab
[index
];
854 m_centralWidgetLayout
->addWidget(viewTab
.splitter
);
855 viewTab
.primaryView
->show();
856 if (viewTab
.secondaryView
!= 0) {
857 viewTab
.secondaryView
->show();
859 viewTab
.splitter
->show();
861 setActiveViewContainer(viewTab
.isPrimaryViewActive
? viewTab
.primaryView
:
862 viewTab
.secondaryView
);
865 void DolphinMainWindow::closeTab()
867 closeTab(m_tabBar
->currentIndex());
870 void DolphinMainWindow::closeTab(int index
)
872 Q_ASSERT(index
>= 0);
873 Q_ASSERT(index
< m_viewTab
.count());
874 if (m_viewTab
.count() == 1) {
875 // the last tab may never get closed
879 if (index
== m_tabIndex
) {
880 // The tab that should be closed is the active tab. Activate the
881 // previous tab before closing the tab.
882 m_tabBar
->setCurrentIndex((index
> 0) ? index
- 1 : 1);
884 rememberClosedTab(index
);
887 m_viewTab
[index
].primaryView
->deleteLater();
888 if (m_viewTab
[index
].secondaryView
!= 0) {
889 m_viewTab
[index
].secondaryView
->deleteLater();
891 m_viewTab
[index
].splitter
->deleteLater();
892 m_viewTab
.erase(m_viewTab
.begin() + index
);
894 m_tabBar
->blockSignals(true);
895 m_tabBar
->removeTab(index
);
897 if (m_tabIndex
> index
) {
899 Q_ASSERT(m_tabIndex
>= 0);
902 // if only one tab is left, also remove the tab entry so that
903 // closing the last tab is not possible
904 if (m_viewTab
.count() == 1) {
905 m_tabBar
->removeTab(0);
906 actionCollection()->action("close_tab")->setEnabled(false);
908 m_tabBar
->blockSignals(false);
912 void DolphinMainWindow::openTabContextMenu(int index
, const QPoint
& pos
)
916 QAction
* newTabAction
= menu
.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab"));
917 newTabAction
->setShortcut(actionCollection()->action("new_tab")->shortcut());
919 QAction
* closeOtherTabsAction
= menu
.addAction(KIcon("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs"));
921 QAction
* closeTabAction
= menu
.addAction(KIcon("tab-close"), i18nc("@action:inmenu", "Close Tab"));
922 closeTabAction
->setShortcut(actionCollection()->action("close_tab")->shortcut());
923 QAction
* selectedAction
= menu
.exec(pos
);
924 if (selectedAction
== newTabAction
) {
925 const ViewTab
& tab
= m_viewTab
[index
];
926 Q_ASSERT(tab
.primaryView
!= 0);
927 const KUrl url
= (tab
.secondaryView
!= 0) && tab
.secondaryView
->isActive() ?
928 tab
.secondaryView
->url() : tab
.primaryView
->url();
930 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
931 } else if (selectedAction
== closeOtherTabsAction
) {
932 const int count
= m_tabBar
->count();
933 for (int i
= 0; i
< index
; ++i
) {
936 for (int i
= index
+ 1; i
< count
; ++i
) {
939 } else if (selectedAction
== closeTabAction
) {
944 void DolphinMainWindow::handlePlacesClick(const KUrl
& url
, Qt::MouseButtons buttons
)
946 if (buttons
& Qt::MidButton
) {
948 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
954 void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent
* event
, bool& canDecode
)
956 canDecode
= KUrl::List::canDecode(event
->mimeData());
959 void DolphinMainWindow::searchItems(const KUrl
& url
)
961 m_activeViewContainer
->setUrl(url
);
964 void DolphinMainWindow::slotTabMoved(int from
, int to
)
966 m_viewTab
.move(from
, to
);
967 m_tabIndex
= m_tabBar
->currentIndex();
970 void DolphinMainWindow::init()
972 DolphinSettings
& settings
= DolphinSettings::instance();
974 // Check whether Dolphin runs the first time. If yes then
975 // a proper default window size is given at the end of DolphinMainWindow::init().
976 GeneralSettings
* generalSettings
= settings
.generalSettings();
977 const bool firstRun
= generalSettings
->firstRun();
979 generalSettings
->setViewPropsTimestamp(QDateTime::currentDateTime());
982 setAcceptDrops(true);
984 m_viewTab
[m_tabIndex
].splitter
= new QSplitter(this);
985 m_viewTab
[m_tabIndex
].splitter
->setChildrenCollapsible(false);
989 const KUrl
& homeUrl
= generalSettings
->homeUrl();
990 setCaption(homeUrl
.fileName());
991 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
992 connect(m_actionHandler
, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
993 connect(m_actionHandler
, SIGNAL(createDirectory()), SLOT(createDirectory()));
994 ViewProperties
props(homeUrl
);
995 m_viewTab
[m_tabIndex
].primaryView
= new DolphinViewContainer(this,
996 m_viewTab
[m_tabIndex
].splitter
,
999 m_activeViewContainer
= m_viewTab
[m_tabIndex
].primaryView
;
1000 connectViewSignals(m_activeViewContainer
);
1001 DolphinView
* view
= m_activeViewContainer
->view();
1003 m_activeViewContainer
->show();
1004 m_actionHandler
->setCurrentView(view
);
1006 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
1007 connect(this, SIGNAL(urlChanged(const KUrl
&)),
1008 m_remoteEncoding
, SLOT(slotAboutToOpenUrl()));
1010 m_tabBar
= new KTabBar(this);
1011 m_tabBar
->setMovable(true);
1012 m_tabBar
->setTabsClosable(true);
1013 connect(m_tabBar
, SIGNAL(currentChanged(int)),
1014 this, SLOT(setActiveTab(int)));
1015 connect(m_tabBar
, SIGNAL(tabCloseRequested(int)),
1016 this, SLOT(closeTab(int)));
1017 connect(m_tabBar
, SIGNAL(contextMenu(int, const QPoint
&)),
1018 this, SLOT(openTabContextMenu(int, const QPoint
&)));
1019 connect(m_tabBar
, SIGNAL(newTabRequest()),
1020 this, SLOT(openNewTab()));
1021 connect(m_tabBar
, SIGNAL(testCanDecode(const QDragMoveEvent
*, bool&)),
1022 this, SLOT(slotTestCanDecode(const QDragMoveEvent
*, bool&)));
1023 connect(m_tabBar
, SIGNAL(wheelDelta(int)),
1024 this, SLOT(slotWheelMoved(int)));
1025 connect(m_tabBar
, SIGNAL(mouseMiddleClick(int)),
1026 this, SLOT(closeTab(int)));
1027 connect(m_tabBar
, SIGNAL(tabMoved(int, int)),
1028 this, SLOT(slotTabMoved(int, int)));
1030 m_tabBar
->blockSignals(true); // signals get unblocked after at least 2 tabs are open
1032 QWidget
* centralWidget
= new QWidget(this);
1033 m_centralWidgetLayout
= new QVBoxLayout(centralWidget
);
1034 m_centralWidgetLayout
->setSpacing(0);
1035 m_centralWidgetLayout
->setMargin(0);
1036 m_centralWidgetLayout
->addWidget(m_tabBar
);
1037 m_centralWidgetLayout
->addWidget(m_viewTab
[m_tabIndex
].splitter
);
1039 setCentralWidget(centralWidget
);
1041 emit
urlChanged(homeUrl
);
1043 setupGUI(Keys
| Save
| Create
| ToolBar
);
1045 m_searchBox
->setParent(toolBar("searchToolBar"));
1046 m_searchBox
->show();
1048 stateChanged("new_file");
1050 QClipboard
* clipboard
= QApplication::clipboard();
1051 connect(clipboard
, SIGNAL(dataChanged()),
1052 this, SLOT(updatePasteAction()));
1053 updatePasteAction();
1056 if (generalSettings
->splitView()) {
1059 updateViewActions();
1061 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1062 showFilterBarAction
->setChecked(generalSettings
->filterBar());
1065 // assure a proper default size if Dolphin runs the first time
1069 m_showMenuBar
->setChecked(!menuBar()->isHidden()); // workaround for bug #171080
1072 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer
* viewContainer
)
1074 Q_ASSERT(viewContainer
!= 0);
1075 Q_ASSERT((viewContainer
== m_viewTab
[m_tabIndex
].primaryView
) ||
1076 (viewContainer
== m_viewTab
[m_tabIndex
].secondaryView
));
1077 if (m_activeViewContainer
== viewContainer
) {
1081 m_activeViewContainer
->setActive(false);
1082 m_activeViewContainer
= viewContainer
;
1084 // Activating the view container might trigger a recursive setActiveViewContainer() call
1085 // inside DolphinMainWindow::toggleActiveView() when having a split view. Temporary
1086 // disconnect the activated() signal in this case:
1087 disconnect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1088 m_activeViewContainer
->setActive(true);
1089 connect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1091 m_actionHandler
->setCurrentView(viewContainer
->view());
1094 updateEditActions();
1095 updateViewActions();
1098 const KUrl
& url
= m_activeViewContainer
->url();
1099 setCaption(url
.fileName());
1100 if (m_viewTab
.count() > 1 && m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
1101 m_tabBar
->setTabText(m_tabIndex
, tabName(url
));
1102 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(KMimeType::iconNameForUrl(url
)));
1105 emit
urlChanged(url
);
1108 void DolphinMainWindow::setupActions()
1110 // setup 'File' menu
1111 m_newMenu
= new DolphinNewMenu(this, this);
1112 KMenu
* menu
= m_newMenu
->menu();
1113 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1114 menu
->setIcon(KIcon("document-new"));
1115 connect(menu
, SIGNAL(aboutToShow()),
1116 this, SLOT(updateNewMenu()));
1118 KAction
* newWindow
= actionCollection()->addAction("new_window");
1119 newWindow
->setIcon(KIcon("window-new"));
1120 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1121 newWindow
->setShortcut(Qt::CTRL
| Qt::Key_N
);
1122 connect(newWindow
, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1124 KAction
* newTab
= actionCollection()->addAction("new_tab");
1125 newTab
->setIcon(KIcon("tab-new"));
1126 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1127 newTab
->setShortcut(KShortcut(Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
));
1128 connect(newTab
, SIGNAL(triggered()), this, SLOT(openNewTab()));
1130 KAction
* closeTab
= actionCollection()->addAction("close_tab");
1131 closeTab
->setIcon(KIcon("tab-close"));
1132 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1133 closeTab
->setShortcut(Qt::CTRL
| Qt::Key_W
);
1134 closeTab
->setEnabled(false);
1135 connect(closeTab
, SIGNAL(triggered()), this, SLOT(closeTab()));
1137 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1139 // setup 'Edit' menu
1140 KStandardAction::undo(this,
1142 actionCollection());
1144 // need to remove shift+del from cut action, else the shortcut for deletejob
1146 KAction
* cut
= KStandardAction::cut(this, SLOT(cut()), actionCollection());
1147 KShortcut cutShortcut
= cut
->shortcut();
1148 cutShortcut
.remove(Qt::SHIFT
+ Qt::Key_Delete
, KShortcut::KeepEmpty
);
1149 cut
->setShortcut(cutShortcut
);
1150 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1151 KStandardAction::paste(this, SLOT(paste()), actionCollection());
1153 KAction
* selectAll
= actionCollection()->addAction("select_all");
1154 selectAll
->setText(i18nc("@action:inmenu Edit", "Select All"));
1155 selectAll
->setShortcut(Qt::CTRL
+ Qt::Key_A
);
1156 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
1158 KAction
* invertSelection
= actionCollection()->addAction("invert_selection");
1159 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1160 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1161 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
1163 // setup 'View' menu
1164 // (note that most of it is set up in DolphinViewActionHandler)
1166 KAction
* split
= actionCollection()->addAction("split_view");
1167 split
->setShortcut(Qt::Key_F3
);
1168 updateSplitAction();
1169 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1171 KAction
* reload
= actionCollection()->addAction("reload");
1172 reload
->setText(i18nc("@action:inmenu View", "Reload"));
1173 reload
->setShortcut(Qt::Key_F5
);
1174 reload
->setIcon(KIcon("view-refresh"));
1175 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
1177 KAction
* stop
= actionCollection()->addAction("stop");
1178 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1179 stop
->setIcon(KIcon("process-stop"));
1180 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
1182 KToggleAction
* showFullLocation
= actionCollection()->add
<KToggleAction
>("editable_location");
1183 showFullLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1184 showFullLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
1185 connect(showFullLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1187 KAction
* replaceLocation
= actionCollection()->addAction("replace_location");
1188 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1189 replaceLocation
->setShortcut(Qt::Key_F6
);
1190 connect(replaceLocation
, SIGNAL(triggered()), this, SLOT(replaceLocation()));
1193 KAction
* backAction
= KStandardAction::back(this, SLOT(goBack()), actionCollection());
1194 KShortcut backShortcut
= backAction
->shortcut();
1195 backShortcut
.setAlternate(Qt::Key_Backspace
);
1196 backAction
->setShortcut(backShortcut
);
1198 m_recentTabsMenu
= new KActionMenu(i18n("Recently Closed Tabs"), this);
1199 m_recentTabsMenu
->setIcon(KIcon("edit-undo"));
1200 actionCollection()->addAction("closed_tabs", m_recentTabsMenu
);
1201 connect(m_recentTabsMenu
->menu(), SIGNAL(triggered(QAction
*)),
1202 this, SLOT(restoreClosedTab(QAction
*)));
1204 QAction
* action
= new QAction("Empty Recently Closed Tabs", m_recentTabsMenu
);
1205 action
->setIcon(KIcon("edit-clear-list"));
1206 action
->setData(QVariant::fromValue(true));
1207 m_recentTabsMenu
->addAction(action
);
1208 m_recentTabsMenu
->addSeparator();
1209 m_recentTabsMenu
->setEnabled(false);
1211 KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1212 KStandardAction::up(this, SLOT(goUp()), actionCollection());
1213 KStandardAction::home(this, SLOT(goHome()), actionCollection());
1215 // setup 'Tools' menu
1216 KToggleAction
* showSearchBar
= actionCollection()->add
<KToggleAction
>("show_search_bar");
1217 showSearchBar
->setText(i18nc("@action:inmenu Tools", "Show Search Bar"));
1218 showSearchBar
->setShortcut(Qt::CTRL
| Qt::Key_S
);
1219 connect(showSearchBar
, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
1221 KToggleAction
* showFilterBar
= actionCollection()->add
<KToggleAction
>("show_filter_bar");
1222 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1223 showFilterBar
->setShortcut(Qt::CTRL
| Qt::Key_I
);
1224 connect(showFilterBar
, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
1226 KAction
* compareFiles
= actionCollection()->addAction("compare_files");
1227 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1228 compareFiles
->setIcon(KIcon("kompare"));
1229 compareFiles
->setEnabled(false);
1230 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
1232 KAction
* openTerminal
= actionCollection()->addAction("open_terminal");
1233 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1234 openTerminal
->setIcon(KIcon("terminal"));
1235 openTerminal
->setShortcut(Qt::SHIFT
| Qt::Key_F4
);
1236 connect(openTerminal
, SIGNAL(triggered()), this, SLOT(openTerminal()));
1238 // setup 'Settings' menu
1239 m_showMenuBar
= KStandardAction::showMenubar(this, SLOT(toggleShowMenuBar()), actionCollection());
1240 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1242 // not in menu actions
1243 KAction
* activateNextTab
= actionCollection()->addAction("activate_next_tab");
1244 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1245 connect(activateNextTab
, SIGNAL(triggered()), SLOT(activateNextTab()));
1246 activateNextTab
->setShortcuts(QApplication::isRightToLeft() ? KStandardShortcut::tabPrev() :
1247 KStandardShortcut::tabNext());
1249 KAction
* activatePrevTab
= actionCollection()->addAction("activate_prev_tab");
1250 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1251 connect(activatePrevTab
, SIGNAL(triggered()), SLOT(activatePrevTab()));
1252 activatePrevTab
->setShortcuts(QApplication::isRightToLeft() ? KStandardShortcut::tabNext() :
1253 KStandardShortcut::tabPrev());
1256 KAction
* openInNewTab
= actionCollection()->addAction("open_in_new_tab");
1257 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1258 openInNewTab
->setIcon(KIcon("tab-new"));
1259 connect(openInNewTab
, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1261 KAction
* openInNewWindow
= actionCollection()->addAction("open_in_new_window");
1262 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1263 openInNewWindow
->setIcon(KIcon("window-new"));
1264 connect(openInNewWindow
, SIGNAL(triggered()), this, SLOT(openInNewWindow()));
1267 m_searchBox
= new DolphinSearchBox(this);
1268 connect(m_searchBox
, SIGNAL(search(KUrl
)), this, SLOT(searchItems(KUrl
)));
1270 KAction
* search
= new KAction(this);
1271 actionCollection()->addAction("search_bar", search
);
1272 search
->setText(i18nc("@action:inmenu", "Search Bar"));
1273 search
->setDefaultWidget(m_searchBox
);
1274 search
->setShortcutConfigurable(false);
1277 void DolphinMainWindow::setupDockWidgets()
1279 // setup "Information"
1280 QDockWidget
* infoDock
= new QDockWidget(i18nc("@title:window", "Information"));
1281 infoDock
->setObjectName("infoDock");
1282 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1283 Panel
* infoPanel
= new InformationPanel(infoDock
);
1284 infoDock
->setWidget(infoPanel
);
1286 QAction
* infoAction
= infoDock
->toggleViewAction();
1287 infoAction
->setText(i18nc("@title:window", "Information"));
1288 infoAction
->setShortcut(Qt::Key_F11
);
1289 infoAction
->setIcon(KIcon("dialog-information"));
1290 actionCollection()->addAction("show_info_panel", infoDock
->toggleViewAction());
1292 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1293 connect(this, SIGNAL(urlChanged(KUrl
)),
1294 infoPanel
, SLOT(setUrl(KUrl
)));
1295 connect(this, SIGNAL(selectionChanged(KFileItemList
)),
1296 infoPanel
, SLOT(setSelection(KFileItemList
)));
1297 connect(this, SIGNAL(requestItemInfo(KFileItem
)),
1298 infoPanel
, SLOT(requestDelayedItemInfo(KFileItem
)));
1301 QDockWidget
* foldersDock
= new QDockWidget(i18nc("@title:window", "Folders"));
1302 foldersDock
->setObjectName("foldersDock");
1303 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1304 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1305 foldersDock
->setWidget(foldersPanel
);
1307 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1308 foldersAction
->setText(i18nc("@title:window", "Folders"));
1309 foldersAction
->setShortcut(Qt::Key_F7
);
1310 foldersAction
->setIcon(KIcon("folder"));
1311 actionCollection()->addAction("show_folders_panel", foldersDock
->toggleViewAction());
1313 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1314 connect(this, SIGNAL(urlChanged(KUrl
)),
1315 foldersPanel
, SLOT(setUrl(KUrl
)));
1316 connect(foldersPanel
, SIGNAL(changeUrl(KUrl
, Qt::MouseButtons
)),
1317 this, SLOT(handlePlacesClick(KUrl
, Qt::MouseButtons
)));
1318 connect(foldersPanel
, SIGNAL(changeSelection(KFileItemList
)),
1319 this, SLOT(changeSelection(KFileItemList
)));
1323 QDockWidget
* terminalDock
= new QDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1324 terminalDock
->setObjectName("terminalDock");
1325 terminalDock
->setAllowedAreas(Qt::TopDockWidgetArea
| Qt::BottomDockWidgetArea
);
1326 Panel
* terminalPanel
= new TerminalPanel(terminalDock
);
1327 terminalDock
->setWidget(terminalPanel
);
1329 connect(terminalPanel
, SIGNAL(hideTerminalPanel()), terminalDock
, SLOT(hide()));
1331 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1332 terminalAction
->setText(i18nc("@title:window Shell terminal", "Terminal"));
1333 terminalAction
->setShortcut(Qt::Key_F4
);
1334 terminalAction
->setIcon(KIcon("terminal"));
1335 actionCollection()->addAction("show_terminal_panel", terminalDock
->toggleViewAction());
1337 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1338 connect(this, SIGNAL(urlChanged(KUrl
)),
1339 terminalPanel
, SLOT(setUrl(KUrl
)));
1342 const bool firstRun
= DolphinSettings::instance().generalSettings()->firstRun();
1344 foldersDock
->hide();
1346 terminalDock
->hide();
1350 QDockWidget
* placesDock
= new QDockWidget(i18nc("@title:window", "Places"));
1351 placesDock
->setObjectName("placesDock");
1352 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1354 PlacesPanel
* placesPanel
= new PlacesPanel(placesDock
);
1355 placesDock
->setWidget(placesPanel
);
1356 placesPanel
->setModel(DolphinSettings::instance().placesModel());
1357 placesPanel
->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff
);
1359 QAction
* placesAction
= placesDock
->toggleViewAction();
1360 placesAction
->setText(i18nc("@title:window", "Places"));
1361 placesAction
->setShortcut(Qt::Key_F9
);
1362 placesAction
->setIcon(KIcon("bookmarks"));
1363 actionCollection()->addAction("show_places_panel", placesDock
->toggleViewAction());
1365 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1366 connect(placesPanel
, SIGNAL(urlChanged(KUrl
, Qt::MouseButtons
)),
1367 this, SLOT(handlePlacesClick(KUrl
, Qt::MouseButtons
)));
1368 connect(this, SIGNAL(urlChanged(KUrl
)),
1369 placesPanel
, SLOT(setUrl(KUrl
)));
1372 void DolphinMainWindow::updateEditActions()
1374 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1375 if (list
.isEmpty()) {
1376 stateChanged("has_no_selection");
1378 stateChanged("has_selection");
1380 KActionCollection
* col
= actionCollection();
1381 QAction
* renameAction
= col
->action("rename");
1382 QAction
* moveToTrashAction
= col
->action("move_to_trash");
1383 QAction
* deleteAction
= col
->action("delete");
1384 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
1385 QAction
* deleteWithTrashShortcut
= col
->action("delete_shortcut"); // see DolphinViewActionHandler
1387 KFileItemListProperties
capabilities(list
);
1388 const bool enableMoveToTrash
= capabilities
.isLocal() && capabilities
.supportsMoving();
1390 renameAction
->setEnabled(capabilities
.supportsMoving());
1391 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1392 deleteAction
->setEnabled(capabilities
.supportsDeleting());
1393 deleteWithTrashShortcut
->setEnabled(capabilities
.supportsDeleting() && !enableMoveToTrash
);
1394 cutAction
->setEnabled(capabilities
.supportsMoving());
1396 updatePasteAction();
1399 void DolphinMainWindow::updateViewActions()
1401 m_actionHandler
->updateViewActions();
1403 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1404 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
1406 updateSplitAction();
1408 QAction
* editableLocactionAction
= actionCollection()->action("editable_location");
1409 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
1410 editableLocactionAction
->setChecked(urlNavigator
->isUrlEditable());
1413 void DolphinMainWindow::updateGoActions()
1415 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
1416 const KUrl
& currentUrl
= m_activeViewContainer
->url();
1417 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
1420 void DolphinMainWindow::rememberClosedTab(int index
)
1422 KMenu
* tabsMenu
= m_recentTabsMenu
->menu();
1424 const QString primaryPath
= m_viewTab
[index
].primaryView
->url().path();
1425 const QString iconName
= KMimeType::iconNameForUrl(primaryPath
);
1427 const QFontMetrics fm
= fontMetrics();
1428 const QString actionText
= fm
.elidedText(primaryPath
, Qt::ElideMiddle
, fm
.maxWidth() * 20);
1430 QAction
* action
= new QAction(actionText
, tabsMenu
);
1432 ClosedTab closedTab
;
1433 closedTab
.primaryUrl
= m_viewTab
[index
].primaryView
->url();
1435 if (m_viewTab
[index
].secondaryView
!= 0) {
1436 closedTab
.secondaryUrl
= m_viewTab
[index
].secondaryView
->url();
1437 closedTab
.isSplit
= true;
1439 closedTab
.isSplit
= false;
1442 action
->setData(QVariant::fromValue(closedTab
));
1443 action
->setIcon(KIcon(iconName
));
1445 // add the closed tab menu entry after the separator and
1446 // "Empty Recently Closed Tabs" entry
1447 if (tabsMenu
->actions().size() == 2) {
1448 tabsMenu
->addAction(action
);
1450 tabsMenu
->insertAction(tabsMenu
->actions().at(2), action
);
1453 // assure that only up to 8 closed tabs are shown in the menu
1454 if (tabsMenu
->actions().size() > 8) {
1455 tabsMenu
->removeAction(tabsMenu
->actions().last());
1457 actionCollection()->action("closed_tabs")->setEnabled(true);
1458 KAcceleratorManager::manage(tabsMenu
);
1461 void DolphinMainWindow::clearStatusBar()
1463 m_activeViewContainer
->statusBar()->clear();
1466 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
1468 connect(container
, SIGNAL(showFilterBarChanged(bool)),
1469 this, SLOT(updateFilterBarAction(bool)));
1471 DolphinView
* view
= container
->view();
1472 connect(view
, SIGNAL(selectionChanged(KFileItemList
)),
1473 this, SLOT(slotSelectionChanged(KFileItemList
)));
1474 connect(view
, SIGNAL(requestItemInfo(KFileItem
)),
1475 this, SLOT(slotRequestItemInfo(KFileItem
)));
1476 connect(view
, SIGNAL(activated()),
1477 this, SLOT(toggleActiveView()));
1478 connect(view
, SIGNAL(tabRequested(const KUrl
&)),
1479 this, SLOT(openNewTab(const KUrl
&)));
1481 const KUrlNavigator
* navigator
= container
->urlNavigator();
1482 connect(navigator
, SIGNAL(urlChanged(const KUrl
&)),
1483 this, SLOT(changeUrl(const KUrl
&)));
1484 connect(navigator
, SIGNAL(historyChanged()),
1485 this, SLOT(updateHistory()));
1486 connect(navigator
, SIGNAL(editableStateChanged(bool)),
1487 this, SLOT(slotEditableStateChanged(bool)));
1490 void DolphinMainWindow::updateSplitAction()
1492 QAction
* splitAction
= actionCollection()->action("split_view");
1493 if (m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
1494 if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
1495 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
1496 splitAction
->setIcon(KIcon("view-right-close"));
1498 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
1499 splitAction
->setIcon(KIcon("view-left-close"));
1502 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
1503 splitAction
->setIcon(KIcon("view-right-new"));
1507 QString
DolphinMainWindow::tabName(const KUrl
& url
) const
1510 if (url
.equals(KUrl("file:///"))) {
1513 name
= url
.fileName();
1514 if (name
.isEmpty()) {
1515 name
= url
.protocol();
1517 // Make sure that a '&' inside the directory name is displayed correctly
1518 // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
1519 name
.replace('&', "&&");
1525 bool DolphinMainWindow::isKompareInstalled() const
1527 static bool initialized
= false;
1528 static bool installed
= false;
1530 // TODO: maybe replace this approach later by using a menu
1531 // plugin like kdiff3plugin.cpp
1532 installed
= !KGlobal::dirs()->findExe("kompare").isEmpty();
1538 void DolphinMainWindow::createSecondaryView(int tabIndex
)
1540 QSplitter
* splitter
= m_viewTab
[tabIndex
].splitter
;
1541 const int newWidth
= (m_viewTab
[tabIndex
].primaryView
->width() - splitter
->handleWidth()) / 2;
1543 const DolphinView
* view
= m_viewTab
[tabIndex
].primaryView
->view();
1544 m_viewTab
[tabIndex
].secondaryView
= new DolphinViewContainer(this, 0, view
->rootUrl());
1545 splitter
->addWidget(m_viewTab
[tabIndex
].secondaryView
);
1546 splitter
->setSizes(QList
<int>() << newWidth
<< newWidth
);
1547 connectViewSignals(m_viewTab
[tabIndex
].secondaryView
);
1548 m_viewTab
[tabIndex
].secondaryView
->view()->reload();
1549 m_viewTab
[tabIndex
].secondaryView
->setActive(false);
1550 m_viewTab
[tabIndex
].secondaryView
->show();
1553 QString
DolphinMainWindow::tabProperty(const QString
& property
, int tabIndex
) const
1555 return "Tab " + QString::number(tabIndex
) + ' ' + property
;
1558 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
1559 KIO::FileUndoManager::UiInterface()
1563 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
1567 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
1569 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
1571 DolphinStatusBar
* statusBar
= mainWin
->activeViewContainer()->statusBar();
1572 statusBar
->setMessage(job
->errorString(), DolphinStatusBar::Error
);
1574 KIO::FileUndoManager::UiInterface::jobError(job
);
1578 #include "dolphinmainwindow.moc"