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 "search/dolphinsearchoptionsconfigurator.h"
31 #include "dolphinapplication.h"
32 #include "dolphinnewmenu.h"
33 #include "search/dolphinsearchbox.h"
34 #include "settings/dolphinsettings.h"
35 #include "settings/dolphinsettingsdialog.h"
36 #include "dolphinviewcontainer.h"
37 #include "panels/folders/folderspanel.h"
38 #include "panels/places/placespanel.h"
39 #include "panels/information/informationpanel.h"
40 #include "mainwindowadaptor.h"
41 #include "statusbar/dolphinstatusbar.h"
42 #include "viewproperties.h"
45 #include "panels/terminal/terminalpanel.h"
48 #include "dolphin_generalsettings.h"
49 #include "dolphin_iconsmodesettings.h"
50 #include "draganddrophelper.h"
53 #include <kactioncollection.h>
55 #include <kdesktopfile.h>
56 #include <kdeversion.h>
57 #include <kfiledialog.h>
58 #include <kfileplacesmodel.h>
60 #include <klineedit.h>
63 #include <kiconloader.h>
64 #include <kio/netaccess.h>
65 #include <kinputdialog.h>
67 #include <kprotocolmanager.h>
70 #include <kmessagebox.h>
71 #include <kfileitemlistproperties.h>
72 #include <konqmimedata.h>
73 #include <kprotocolinfo.h>
76 #include <kstandarddirs.h>
77 #include <kstatusbar.h>
78 #include <kstandardaction.h>
80 #include <ktoggleaction.h>
81 #include <kurlnavigator.h>
83 #include <kurlcombobox.h>
84 #include <ktoolinvocation.h>
86 #include <QDBusMessage>
90 #include <QDockWidget>
91 #include <kacceleratormanager.h>
94 * Remembers the tab configuration if a tab has been closed.
95 * Each closed tab can be restored by the menu
96 * "Go -> Recently Closed Tabs".
104 Q_DECLARE_METATYPE(ClosedTab
)
106 DolphinMainWindow::DolphinMainWindow(int id
) :
111 m_activeViewContainer(0),
112 m_centralWidgetLayout(0),
115 m_searchOptionsConfigurator(0),
124 setObjectName("Dolphin#");
126 m_viewTab
.append(ViewTab());
128 new MainWindowAdaptor(this);
129 QDBusConnection::sessionBus().registerObject(QString("/dolphin/MainWindow%1").arg(m_id
), this);
131 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
132 undoManager
->setUiInterface(new UndoUiInterface());
134 connect(undoManager
, SIGNAL(undoAvailable(bool)),
135 this, SLOT(slotUndoAvailable(bool)));
136 connect(undoManager
, SIGNAL(undoTextChanged(const QString
&)),
137 this, SLOT(slotUndoTextChanged(const QString
&)));
138 connect(undoManager
, SIGNAL(jobRecordingStarted(CommandType
)),
139 this, SLOT(clearStatusBar()));
140 connect(undoManager
, SIGNAL(jobRecordingFinished(CommandType
)),
141 this, SLOT(showCommand(CommandType
)));
142 connect(DolphinSettings::instance().placesModel(), SIGNAL(errorMessage(const QString
&)),
143 this, SLOT(showErrorMessage(const QString
&)));
144 connect(&DragAndDropHelper::instance(), SIGNAL(errorMessage(const QString
&)),
145 this, SLOT(showErrorMessage(const QString
&)));
148 DolphinMainWindow::~DolphinMainWindow()
150 DolphinApplication::app()->removeMainWindow(this);
153 void DolphinMainWindow::openDirectories(const QList
<KUrl
>& dirs
)
155 if (dirs
.isEmpty()) {
159 const int oldOpenTabsCount
= m_viewTab
.count();
161 const GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
162 const bool hasSplitView
= generalSettings
->splitView();
164 // Open each directory inside a new tab. If the "split view" option has been enabled,
165 // always show two directories within one tab.
166 QList
<KUrl
>::const_iterator it
= dirs
.begin();
167 while (it
!= dirs
.end()) {
171 if (hasSplitView
&& (it
!= dirs
.end())) {
172 const int tabIndex
= m_viewTab
.count() - 1;
173 m_viewTab
[tabIndex
].secondaryView
->setUrl(*it
);
178 // remove the previously opened tabs
179 for (int i
= 0; i
< oldOpenTabsCount
; ++i
) {
184 void DolphinMainWindow::openFiles(const QList
<KUrl
>& files
)
186 if (files
.isEmpty()) {
190 // Get all distinct directories from 'files' and open a tab
191 // for each directory. If the "split view" option is enabled, two
192 // directories are shown inside one tab (see openDirectories()).
194 foreach (const KUrl
& url
, files
) {
195 const KUrl
dir(url
.directory());
196 if (!dirs
.contains(dir
)) {
201 openDirectories(dirs
);
203 // Select the files. Although the files can be split between several
204 // tabs, there is no need to split 'files' accordingly, as
205 // the DolphinView will just ignore invalid selections.
206 const int tabCount
= m_viewTab
.count();
207 for (int i
= 0; i
< tabCount
; ++i
) {
208 m_viewTab
[i
].primaryView
->view()->markUrlsAsSelected(files
);
209 if (m_viewTab
[i
].secondaryView
!= 0) {
210 m_viewTab
[i
].secondaryView
->view()->markUrlsAsSelected(files
);
215 void DolphinMainWindow::toggleViews()
217 if (m_viewTab
[m_tabIndex
].primaryView
== 0) {
221 // move secondary view from the last position of the splitter
222 // to the first position
223 m_viewTab
[m_tabIndex
].splitter
->insertWidget(0, m_viewTab
[m_tabIndex
].secondaryView
);
225 DolphinViewContainer
* container
= m_viewTab
[m_tabIndex
].primaryView
;
226 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
227 m_viewTab
[m_tabIndex
].secondaryView
= container
;
230 void DolphinMainWindow::showCommand(CommandType command
)
232 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
234 case KIO::FileUndoManager::Copy
:
235 statusBar
->setMessage(i18nc("@info:status", "Successfully copied."),
236 DolphinStatusBar::OperationCompleted
);
238 case KIO::FileUndoManager::Move
:
239 statusBar
->setMessage(i18nc("@info:status", "Successfully moved."),
240 DolphinStatusBar::OperationCompleted
);
242 case KIO::FileUndoManager::Link
:
243 statusBar
->setMessage(i18nc("@info:status", "Successfully linked."),
244 DolphinStatusBar::OperationCompleted
);
246 case KIO::FileUndoManager::Trash
:
247 statusBar
->setMessage(i18nc("@info:status", "Successfully moved to trash."),
248 DolphinStatusBar::OperationCompleted
);
250 case KIO::FileUndoManager::Rename
:
251 statusBar
->setMessage(i18nc("@info:status", "Successfully renamed."),
252 DolphinStatusBar::OperationCompleted
);
255 case KIO::FileUndoManager::Mkdir
:
256 statusBar
->setMessage(i18nc("@info:status", "Created folder."),
257 DolphinStatusBar::OperationCompleted
);
265 void DolphinMainWindow::refreshViews()
267 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
269 // remember the current active view, as because of
270 // the refreshing the active view might change to
271 // the secondary view
272 DolphinViewContainer
* activeViewContainer
= m_activeViewContainer
;
274 const int tabCount
= m_viewTab
.count();
275 for (int i
= 0; i
< tabCount
; ++i
) {
276 m_viewTab
[i
].primaryView
->refresh();
277 if (m_viewTab
[i
].secondaryView
!= 0) {
278 m_viewTab
[i
].secondaryView
->refresh();
282 setActiveViewContainer(activeViewContainer
);
285 void DolphinMainWindow::pasteIntoFolder()
287 m_activeViewContainer
->view()->pasteIntoFolder();
290 void DolphinMainWindow::changeUrl(const KUrl
& url
)
292 if (!KProtocolManager::supportsListing(url
)) {
293 // The URL navigator only checks for validity, not
294 // if the URL can be listed. An error message is
295 // shown due to DolphinViewContainer::restoreView().
299 DolphinViewContainer
* view
= activeViewContainer();
305 setUrlAsCaption(url
);
306 if (m_viewTab
.count() > 1) {
307 m_tabBar
->setTabText(m_tabIndex
, squeezedText(tabName(m_activeViewContainer
->url())));
309 const QString iconName
= KMimeType::iconNameForUrl(url
);
310 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(iconName
));
311 emit
urlChanged(url
);
315 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
317 KToggleAction
* editableLocationAction
=
318 static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
319 editableLocationAction
->setChecked(editable
);
322 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
326 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
327 int selectedUrlsCount
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedItemsCount();
328 if (m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
329 selectedUrlsCount
+= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItemsCount();
332 QAction
* compareFilesAction
= actionCollection()->action("compare_files");
333 if (selectedUrlsCount
== 2) {
334 compareFilesAction
->setEnabled(isKompareInstalled());
336 compareFilesAction
->setEnabled(false);
339 emit
selectionChanged(selection
);
342 void DolphinMainWindow::slotWheelMoved(int wheelDelta
)
344 if (wheelDelta
> 0) {
351 void DolphinMainWindow::slotRequestItemInfo(const KFileItem
& item
)
353 emit
requestItemInfo(item
);
356 void DolphinMainWindow::updateHistory()
358 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
359 const int index
= urlNavigator
->historyIndex();
361 QAction
* backAction
= actionCollection()->action("go_back");
362 backAction
->setToolTip(i18nc("@info", "Go back"));
363 if (backAction
!= 0) {
364 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
367 QAction
* forwardAction
= actionCollection()->action("go_forward");
368 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
369 if (forwardAction
!= 0) {
370 forwardAction
->setEnabled(index
> 0);
374 void DolphinMainWindow::updateFilterBarAction(bool show
)
376 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
377 showFilterBarAction
->setChecked(show
);
380 void DolphinMainWindow::openNewMainWindow()
382 DolphinApplication::app()->createMainWindow()->show();
385 void DolphinMainWindow::openNewTab()
387 openNewTab(m_activeViewContainer
->url());
388 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
390 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
391 if (navigator
->isUrlEditable()) {
392 // if a new tab is opened and the URL is editable, assure that
393 // the user can edit the URL without manually setting the focus
394 navigator
->setFocus();
398 void DolphinMainWindow::openNewTab(const KUrl
& url
)
400 QWidget
* focusWidget
= QApplication::focusWidget();
402 if (m_viewTab
.count() == 1) {
403 // Only one view is open currently and hence no tab is shown at
404 // all. Before creating a tab for 'url', provide a tab for the current URL.
405 const KUrl currentUrl
= m_activeViewContainer
->url();
406 m_tabBar
->addTab(KIcon(KMimeType::iconNameForUrl(currentUrl
)),
407 squeezedText(tabName(currentUrl
)));
408 m_tabBar
->blockSignals(false);
411 m_tabBar
->addTab(KIcon(KMimeType::iconNameForUrl(url
)),
412 squeezedText(tabName(url
)));
415 viewTab
.splitter
= new QSplitter(this);
416 viewTab
.splitter
->setChildrenCollapsible(false);
417 viewTab
.primaryView
= new DolphinViewContainer(this, viewTab
.splitter
, url
);
418 viewTab
.primaryView
->setActive(false);
419 connectViewSignals(viewTab
.primaryView
);
420 viewTab
.primaryView
->view()->reload();
422 m_viewTab
.append(viewTab
);
424 actionCollection()->action("close_tab")->setEnabled(true);
426 // provide a split view, if the startup settings are set this way
427 const GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
428 if (generalSettings
->splitView()) {
429 const int tabIndex
= m_viewTab
.count() - 1;
430 createSecondaryView(tabIndex
);
431 m_viewTab
[tabIndex
].secondaryView
->setActive(true);
432 m_viewTab
[tabIndex
].isPrimaryViewActive
= false;
435 if (focusWidget
!= 0) {
436 // The DolphinViewContainer grabbed the keyboard focus. As the tab is opened
437 // in background, assure that the previous focused widget gets the focus back.
438 focusWidget
->setFocus();
442 void DolphinMainWindow::activateNextTab()
444 if ((m_viewTab
.count() == 1) || (m_tabBar
->count() < 2)) {
448 const int tabIndex
= (m_tabBar
->currentIndex() + 1) % m_tabBar
->count();
449 m_tabBar
->setCurrentIndex(tabIndex
);
452 void DolphinMainWindow::activatePrevTab()
454 if ((m_viewTab
.count() == 1) || (m_tabBar
->count() < 2)) {
458 int tabIndex
= m_tabBar
->currentIndex() - 1;
459 if (tabIndex
== -1) {
460 tabIndex
= m_tabBar
->count() - 1;
462 m_tabBar
->setCurrentIndex(tabIndex
);
465 void DolphinMainWindow::openInNewTab()
467 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
468 if ((list
.count() == 1) && list
[0].isDir()) {
469 openNewTab(m_activeViewContainer
->view()->selectedUrls()[0]);
473 void DolphinMainWindow::openInNewWindow()
475 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
476 if ((list
.count() == 1) && list
[0].isDir()) {
477 DolphinMainWindow
* window
= DolphinApplication::app()->createMainWindow();
478 window
->changeUrl(m_activeViewContainer
->view()->selectedUrls()[0]);
483 void DolphinMainWindow::toggleActiveView()
485 if (m_viewTab
[m_tabIndex
].secondaryView
== 0) {
486 // only one view is available
490 Q_ASSERT(m_activeViewContainer
!= 0);
491 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
493 DolphinViewContainer
* left
= m_viewTab
[m_tabIndex
].primaryView
;
494 DolphinViewContainer
* right
= m_viewTab
[m_tabIndex
].secondaryView
;
495 setActiveViewContainer(m_activeViewContainer
== right
? left
: right
);
498 void DolphinMainWindow::showEvent(QShowEvent
* event
)
500 KXmlGuiWindow::showEvent(event
);
501 if (!event
->spontaneous()) {
502 m_activeViewContainer
->view()->setFocus();
506 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
508 DolphinSettings
& settings
= DolphinSettings::instance();
509 GeneralSettings
* generalSettings
= settings
.generalSettings();
511 // Find out if Dolphin is closed directly by the user or
512 // by the session manager because the session is closed
513 bool closedByUser
= true;
514 DolphinApplication
*application
= qobject_cast
<DolphinApplication
*>(qApp
);
515 if (application
&& application
->sessionSaving()) {
516 closedByUser
= false;
519 if ((m_viewTab
.count() > 1) && generalSettings
->confirmClosingMultipleTabs() && closedByUser
) {
520 // Ask the user if he really wants to quit and close all tabs.
521 // Open a confirmation dialog with 3 buttons:
522 // KDialog::Yes -> Quit
523 // KDialog::No -> Close only the current tab
524 // KDialog::Cancel -> do nothing
525 KDialog
*dialog
= new KDialog(this, Qt::Dialog
);
526 dialog
->setCaption(i18nc("@title:window", "Confirmation"));
527 dialog
->setButtons(KDialog::Yes
| KDialog::No
| KDialog::Cancel
);
528 dialog
->setModal(true);
529 dialog
->showButtonSeparator(true);
530 dialog
->setButtonGuiItem(KDialog::Yes
, KStandardGuiItem::quit());
531 dialog
->setButtonGuiItem(KDialog::No
, KGuiItem(i18n("C&lose Current Tab"), KIcon("tab-close")));
532 dialog
->setButtonGuiItem(KDialog::Cancel
, KStandardGuiItem::cancel());
533 dialog
->setDefaultButton(KDialog::Yes
);
535 bool doNotAskAgainCheckboxResult
= false;
537 const int result
= KMessageBox::createKMessageBox(dialog
,
538 QMessageBox::Warning
,
539 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
541 i18n("Do not ask again"),
542 &doNotAskAgainCheckboxResult
,
543 KMessageBox::Notify
);
545 if (doNotAskAgainCheckboxResult
) {
546 generalSettings
->setConfirmClosingMultipleTabs(false);
554 // Close only the current tab
562 generalSettings
->setFirstRun(false);
566 KXmlGuiWindow::closeEvent(event
);
569 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
571 const int tabCount
= m_viewTab
.count();
572 group
.writeEntry("Tab Count", tabCount
);
573 group
.writeEntry("Active Tab Index", m_tabBar
->currentIndex());
575 for (int i
= 0; i
< tabCount
; ++i
) {
576 const DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
577 group
.writeEntry(tabProperty("Primary URL", i
), cont
->url().url());
578 group
.writeEntry(tabProperty("Primary Editable", i
), cont
->isUrlEditable());
580 cont
= m_viewTab
[i
].secondaryView
;
582 group
.writeEntry(tabProperty("Secondary URL", i
), cont
->url().url());
583 group
.writeEntry(tabProperty("Secondary Editable", i
), cont
->isUrlEditable());
588 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
590 const int tabCount
= group
.readEntry("Tab Count", 1);
591 for (int i
= 0; i
< tabCount
; ++i
) {
592 DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
594 cont
->setUrl(group
.readEntry(tabProperty("Primary URL", i
)));
595 const bool editable
= group
.readEntry(tabProperty("Primary Editable", i
), false);
596 cont
->urlNavigator()->setUrlEditable(editable
);
598 cont
= m_viewTab
[i
].secondaryView
;
599 const QString secondaryUrl
= group
.readEntry(tabProperty("Secondary URL", i
));
600 if (!secondaryUrl
.isEmpty()) {
602 // a secondary view should be shown, but no one is available
603 // currently -> create a new view
605 cont
= m_viewTab
[i
].secondaryView
;
609 cont
->setUrl(secondaryUrl
);
610 const bool editable
= group
.readEntry(tabProperty("Secondary Editable", i
), false);
611 cont
->urlNavigator()->setUrlEditable(editable
);
612 } else if (cont
!= 0) {
613 // no secondary view should be shown, but the default setting shows
614 // one already -> close the view
618 // openNewTab() needs to be called only tabCount - 1 times
619 if (i
!= tabCount
- 1) {
624 const int index
= group
.readEntry("Active Tab Index", 0);
625 m_tabBar
->setCurrentIndex(index
);
628 void DolphinMainWindow::updateNewMenu()
630 m_newMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->showHiddenFiles());
631 m_newMenu
->slotCheckUpToDate();
632 m_newMenu
->setPopupFiles(activeViewContainer()->url());
635 void DolphinMainWindow::createDirectory()
637 m_newMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->showHiddenFiles());
638 m_newMenu
->setPopupFiles(activeViewContainer()->url());
639 m_newMenu
->createDirectory();
642 void DolphinMainWindow::quit()
647 void DolphinMainWindow::showErrorMessage(const QString
& message
)
649 if (!message
.isEmpty()) {
650 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
651 statusBar
->setMessage(message
, DolphinStatusBar::Error
);
655 void DolphinMainWindow::slotUndoAvailable(bool available
)
657 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
658 if (undoAction
!= 0) {
659 undoAction
->setEnabled(available
);
663 void DolphinMainWindow::restoreClosedTab(QAction
* action
)
665 if (action
->data().toBool()) {
666 // clear all actions except the "Empty Recently Closed Tabs"
667 // action and the separator
668 QList
<QAction
*> actions
= m_recentTabsMenu
->menu()->actions();
669 const int count
= actions
.size();
670 for (int i
= 2; i
< count
; ++i
) {
671 m_recentTabsMenu
->menu()->removeAction(actions
.at(i
));
674 const ClosedTab closedTab
= action
->data().value
<ClosedTab
>();
675 openNewTab(closedTab
.primaryUrl
);
676 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
678 if (closedTab
.isSplit
) {
679 // create secondary view
681 m_viewTab
[m_tabIndex
].secondaryView
->setUrl(closedTab
.secondaryUrl
);
684 m_recentTabsMenu
->removeAction(action
);
687 if (m_recentTabsMenu
->menu()->actions().count() == 2) {
688 m_recentTabsMenu
->setEnabled(false);
692 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
694 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
695 if (undoAction
!= 0) {
696 undoAction
->setText(text
);
700 void DolphinMainWindow::undo()
703 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
704 KIO::FileUndoManager::self()->undo();
707 void DolphinMainWindow::cut()
709 m_activeViewContainer
->view()->cutSelectedItems();
712 void DolphinMainWindow::copy()
714 m_activeViewContainer
->view()->copySelectedItems();
717 void DolphinMainWindow::paste()
719 m_activeViewContainer
->view()->paste();
722 void DolphinMainWindow::updatePasteAction()
724 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
725 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
726 pasteAction
->setEnabled(pasteInfo
.first
);
727 pasteAction
->setText(pasteInfo
.second
);
730 void DolphinMainWindow::selectAll()
734 // if the URL navigator is editable and focused, select the whole
735 // URL instead of all items of the view
737 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
738 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit(); // krazy:exclude=qclasses
739 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
740 lineEdit
->hasFocus();
742 lineEdit
->selectAll();
744 m_activeViewContainer
->view()->selectAll();
748 void DolphinMainWindow::invertSelection()
751 m_activeViewContainer
->view()->invertSelection();
754 void DolphinMainWindow::toggleSplitView()
756 if (m_viewTab
[m_tabIndex
].secondaryView
== 0) {
757 createSecondaryView(m_tabIndex
);
758 setActiveViewContainer(m_viewTab
[m_tabIndex
].secondaryView
);
759 } else if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
760 // remove secondary view
761 m_viewTab
[m_tabIndex
].secondaryView
->close();
762 m_viewTab
[m_tabIndex
].secondaryView
->deleteLater();
763 m_viewTab
[m_tabIndex
].secondaryView
= 0;
765 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
767 // The primary view is active and should be closed. Hence from a users point of view
768 // the content of the secondary view should be moved to the primary view.
769 // From an implementation point of view it is more efficient to close
770 // the primary view and exchange the internal pointers afterwards.
772 m_viewTab
[m_tabIndex
].primaryView
->close();
773 m_viewTab
[m_tabIndex
].primaryView
->deleteLater();
774 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
775 m_viewTab
[m_tabIndex
].secondaryView
= 0;
777 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
783 void DolphinMainWindow::reloadView()
786 m_activeViewContainer
->view()->reload();
789 void DolphinMainWindow::stopLoading()
793 void DolphinMainWindow::toggleFilterBarVisibility(bool show
)
795 m_activeViewContainer
->showFilterBar(show
);
798 void DolphinMainWindow::toggleEditLocation()
802 QAction
* action
= actionCollection()->action("editable_location");
803 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
804 urlNavigator
->setUrlEditable(action
->isChecked());
807 void DolphinMainWindow::replaceLocation()
809 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
810 navigator
->setUrlEditable(true);
811 navigator
->setFocus();
813 // select the whole text of the combo box editor
814 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit(); // krazy:exclude=qclasses
815 const QString text
= lineEdit
->text();
816 lineEdit
->setSelection(0, text
.length());
819 void DolphinMainWindow::goBack()
822 m_activeViewContainer
->urlNavigator()->goBack();
825 void DolphinMainWindow::goForward()
828 m_activeViewContainer
->urlNavigator()->goForward();
831 void DolphinMainWindow::goUp()
834 m_activeViewContainer
->urlNavigator()->goUp();
837 void DolphinMainWindow::goBack(Qt::MouseButtons buttons
)
839 // The default case (left button pressed) is handled in goBack().
840 if (buttons
== Qt::MidButton
) {
841 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
842 openNewTab(urlNavigator
->historyUrl(urlNavigator
->historyIndex() + 1));
846 void DolphinMainWindow::goForward(Qt::MouseButtons buttons
)
848 // The default case (left button pressed) is handled in goForward().
849 if (buttons
== Qt::MidButton
) {
850 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
851 openNewTab(urlNavigator
->historyUrl(urlNavigator
->historyIndex() - 1));
855 void DolphinMainWindow::goUp(Qt::MouseButtons buttons
)
857 // The default case (left button pressed) is handled in goUp().
858 if (buttons
== Qt::MidButton
) {
859 openNewTab(activeViewContainer()->url().upUrl());
863 void DolphinMainWindow::goHome()
866 m_activeViewContainer
->urlNavigator()->goHome();
869 void DolphinMainWindow::compareFiles()
871 // The method is only invoked if exactly 2 files have
872 // been selected. The selected files may be:
873 // - both in the primary view
874 // - both in the secondary view
875 // - one in the primary view and the other in the secondary
877 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
881 KUrl::List urls
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedUrls();
883 switch (urls
.count()) {
885 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
!= 0);
886 urls
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedUrls();
887 Q_ASSERT(urls
.count() == 2);
895 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
!= 0);
896 urls
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedUrls();
897 Q_ASSERT(urls
.count() == 1);
909 // may not happen: compareFiles may only get invoked if 2
910 // files are selected
915 QString
command("kompare -c \"");
916 command
.append(urlA
.pathOrUrl());
917 command
.append("\" \"");
918 command
.append(urlB
.pathOrUrl());
919 command
.append('\"');
920 KRun::runCommand(command
, "Kompare", "kompare", this);
923 void DolphinMainWindow::toggleShowMenuBar()
925 const bool visible
= menuBar()->isVisible();
926 menuBar()->setVisible(!visible
);
929 void DolphinMainWindow::openTerminal()
931 QString
dir(QDir::homePath());
933 // If the given directory is not local, it can still be the URL of an
934 // ioslave using UDS_LOCAL_PATH which to be converted first.
935 KUrl url
= KIO::NetAccess::mostLocalUrl(m_activeViewContainer
->url(), this);
937 //If the URL is local after the above conversion, set the directory.
938 if (url
.isLocalFile()) {
939 dir
= url
.toLocalFile();
942 KToolInvocation::invokeTerminal(QString(), dir
);
945 void DolphinMainWindow::editSettings()
947 if (m_settingsDialog
== 0) {
948 const KUrl
& url
= activeViewContainer()->url();
949 m_settingsDialog
= new DolphinSettingsDialog(url
, this);
950 m_settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
951 m_settingsDialog
->show();
953 m_settingsDialog
->raise();
957 void DolphinMainWindow::setActiveTab(int index
)
959 Q_ASSERT(index
>= 0);
960 Q_ASSERT(index
< m_viewTab
.count());
961 if (index
== m_tabIndex
) {
965 // hide current tab content
966 ViewTab
& hiddenTab
= m_viewTab
[m_tabIndex
];
967 hiddenTab
.isPrimaryViewActive
= hiddenTab
.primaryView
->isActive();
968 hiddenTab
.primaryView
->setActive(false);
969 if (hiddenTab
.secondaryView
!= 0) {
970 hiddenTab
.secondaryView
->setActive(false);
972 QSplitter
* splitter
= m_viewTab
[m_tabIndex
].splitter
;
974 m_centralWidgetLayout
->removeWidget(splitter
);
976 // show active tab content
979 ViewTab
& viewTab
= m_viewTab
[index
];
980 m_centralWidgetLayout
->addWidget(viewTab
.splitter
, 1);
981 viewTab
.primaryView
->show();
982 if (viewTab
.secondaryView
!= 0) {
983 viewTab
.secondaryView
->show();
985 viewTab
.splitter
->show();
987 setActiveViewContainer(viewTab
.isPrimaryViewActive
? viewTab
.primaryView
:
988 viewTab
.secondaryView
);
991 void DolphinMainWindow::closeTab()
993 closeTab(m_tabBar
->currentIndex());
996 void DolphinMainWindow::closeTab(int index
)
998 Q_ASSERT(index
>= 0);
999 Q_ASSERT(index
< m_viewTab
.count());
1000 if (m_viewTab
.count() == 1) {
1001 // the last tab may never get closed
1005 if (index
== m_tabIndex
) {
1006 // The tab that should be closed is the active tab. Activate the
1007 // previous tab before closing the tab.
1008 m_tabBar
->setCurrentIndex((index
> 0) ? index
- 1 : 1);
1010 rememberClosedTab(index
);
1013 m_viewTab
[index
].primaryView
->deleteLater();
1014 if (m_viewTab
[index
].secondaryView
!= 0) {
1015 m_viewTab
[index
].secondaryView
->deleteLater();
1017 m_viewTab
[index
].splitter
->deleteLater();
1018 m_viewTab
.erase(m_viewTab
.begin() + index
);
1020 m_tabBar
->blockSignals(true);
1021 m_tabBar
->removeTab(index
);
1023 if (m_tabIndex
> index
) {
1025 Q_ASSERT(m_tabIndex
>= 0);
1028 // if only one tab is left, also remove the tab entry so that
1029 // closing the last tab is not possible
1030 if (m_viewTab
.count() == 1) {
1031 m_tabBar
->removeTab(0);
1032 actionCollection()->action("close_tab")->setEnabled(false);
1034 m_tabBar
->blockSignals(false);
1038 void DolphinMainWindow::openTabContextMenu(int index
, const QPoint
& pos
)
1042 QAction
* newTabAction
= menu
.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab"));
1043 newTabAction
->setShortcut(actionCollection()->action("new_tab")->shortcut());
1045 QAction
* closeOtherTabsAction
= menu
.addAction(KIcon("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs"));
1047 QAction
* closeTabAction
= menu
.addAction(KIcon("tab-close"), i18nc("@action:inmenu", "Close Tab"));
1048 closeTabAction
->setShortcut(actionCollection()->action("close_tab")->shortcut());
1049 QAction
* selectedAction
= menu
.exec(pos
);
1050 if (selectedAction
== newTabAction
) {
1051 const ViewTab
& tab
= m_viewTab
[index
];
1052 Q_ASSERT(tab
.primaryView
!= 0);
1053 const KUrl url
= (tab
.secondaryView
!= 0) && tab
.secondaryView
->isActive() ?
1054 tab
.secondaryView
->url() : tab
.primaryView
->url();
1056 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
1057 } else if (selectedAction
== closeOtherTabsAction
) {
1058 const int count
= m_tabBar
->count();
1059 for (int i
= 0; i
< index
; ++i
) {
1062 for (int i
= index
+ 1; i
< count
; ++i
) {
1065 } else if (selectedAction
== closeTabAction
) {
1070 void DolphinMainWindow::handlePlacesClick(const KUrl
& url
, Qt::MouseButtons buttons
)
1072 if (buttons
& Qt::MidButton
) {
1074 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
1080 void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent
* event
, bool& canDecode
)
1082 canDecode
= KUrl::List::canDecode(event
->mimeData());
1085 void DolphinMainWindow::searchItems()
1088 const KUrl nepomukSearchUrl
= m_searchOptionsConfigurator
->nepomukSearchUrl();
1089 m_activeViewContainer
->setUrl(nepomukSearchUrl
);
1093 void DolphinMainWindow::slotTabMoved(int from
, int to
)
1095 m_viewTab
.move(from
, to
);
1096 m_tabIndex
= m_tabBar
->currentIndex();
1099 void DolphinMainWindow::showSearchOptions()
1102 m_searchOptionsConfigurator
->show();
1106 void DolphinMainWindow::init()
1108 DolphinSettings
& settings
= DolphinSettings::instance();
1110 // Check whether Dolphin runs the first time. If yes then
1111 // a proper default window size is given at the end of DolphinMainWindow::init().
1112 GeneralSettings
* generalSettings
= settings
.generalSettings();
1113 const bool firstRun
= generalSettings
->firstRun();
1115 generalSettings
->setViewPropsTimestamp(QDateTime::currentDateTime());
1118 setAcceptDrops(true);
1120 m_viewTab
[m_tabIndex
].splitter
= new QSplitter(this);
1121 m_viewTab
[m_tabIndex
].splitter
->setChildrenCollapsible(false);
1125 const KUrl
& homeUrl
= generalSettings
->homeUrl();
1126 setUrlAsCaption(homeUrl
);
1127 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
1128 connect(m_actionHandler
, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
1129 connect(m_actionHandler
, SIGNAL(createDirectory()), SLOT(createDirectory()));
1130 ViewProperties
props(homeUrl
);
1131 m_viewTab
[m_tabIndex
].primaryView
= new DolphinViewContainer(this,
1132 m_viewTab
[m_tabIndex
].splitter
,
1135 m_activeViewContainer
= m_viewTab
[m_tabIndex
].primaryView
;
1136 connectViewSignals(m_activeViewContainer
);
1137 DolphinView
* view
= m_activeViewContainer
->view();
1139 m_activeViewContainer
->show();
1140 m_actionHandler
->setCurrentView(view
);
1142 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
1143 connect(this, SIGNAL(urlChanged(const KUrl
&)),
1144 m_remoteEncoding
, SLOT(slotAboutToOpenUrl()));
1147 m_searchOptionsConfigurator
= new DolphinSearchOptionsConfigurator(this);
1148 m_searchOptionsConfigurator
->hide();
1149 connect(m_searchOptionsConfigurator
, SIGNAL(searchOptionsChanged()),
1150 this, SLOT(searchItems()));
1151 connect(this, SIGNAL(urlChanged(KUrl
)), m_searchOptionsConfigurator
, SLOT(setDirectory(KUrl
)));
1154 m_tabBar
= new KTabBar(this);
1155 m_tabBar
->setMovable(true);
1156 m_tabBar
->setTabsClosable(true);
1157 connect(m_tabBar
, SIGNAL(currentChanged(int)),
1158 this, SLOT(setActiveTab(int)));
1159 connect(m_tabBar
, SIGNAL(tabCloseRequested(int)),
1160 this, SLOT(closeTab(int)));
1161 connect(m_tabBar
, SIGNAL(contextMenu(int, const QPoint
&)),
1162 this, SLOT(openTabContextMenu(int, const QPoint
&)));
1163 connect(m_tabBar
, SIGNAL(newTabRequest()),
1164 this, SLOT(openNewTab()));
1165 connect(m_tabBar
, SIGNAL(testCanDecode(const QDragMoveEvent
*, bool&)),
1166 this, SLOT(slotTestCanDecode(const QDragMoveEvent
*, bool&)));
1167 connect(m_tabBar
, SIGNAL(wheelDelta(int)),
1168 this, SLOT(slotWheelMoved(int)));
1169 connect(m_tabBar
, SIGNAL(mouseMiddleClick(int)),
1170 this, SLOT(closeTab(int)));
1171 connect(m_tabBar
, SIGNAL(tabMoved(int, int)),
1172 this, SLOT(slotTabMoved(int, int)));
1174 m_tabBar
->blockSignals(true); // signals get unblocked after at least 2 tabs are open
1176 QWidget
* centralWidget
= new QWidget(this);
1177 m_centralWidgetLayout
= new QVBoxLayout(centralWidget
);
1178 m_centralWidgetLayout
->setSpacing(0);
1179 m_centralWidgetLayout
->setMargin(0);
1181 m_centralWidgetLayout
->addWidget(m_searchOptionsConfigurator
);
1183 m_centralWidgetLayout
->addWidget(m_tabBar
);
1184 m_centralWidgetLayout
->addWidget(m_viewTab
[m_tabIndex
].splitter
, 1);
1186 setCentralWidget(centralWidget
);
1188 emit
urlChanged(homeUrl
);
1190 setupGUI(Keys
| Save
| Create
| ToolBar
);
1192 m_searchBox
->setParent(toolBar("searchToolBar"));
1193 m_searchBox
->show();
1194 connect(m_searchBox
, SIGNAL(requestSearchOptions()),
1195 this, SLOT(showSearchOptions()));
1197 connect(m_searchBox
, SIGNAL(searchTextChanged(QString
)),
1198 m_searchOptionsConfigurator
, SLOT(setCustomSearchQuery(QString
)));
1201 stateChanged("new_file");
1203 QClipboard
* clipboard
= QApplication::clipboard();
1204 connect(clipboard
, SIGNAL(dataChanged()),
1205 this, SLOT(updatePasteAction()));
1206 updatePasteAction();
1209 if (generalSettings
->splitView()) {
1212 updateViewActions();
1214 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1215 showFilterBarAction
->setChecked(generalSettings
->filterBar());
1218 // assure a proper default size if Dolphin runs the first time
1222 m_showMenuBar
->setChecked(!menuBar()->isHidden()); // workaround for bug #171080
1225 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer
* viewContainer
)
1227 Q_ASSERT(viewContainer
!= 0);
1228 Q_ASSERT((viewContainer
== m_viewTab
[m_tabIndex
].primaryView
) ||
1229 (viewContainer
== m_viewTab
[m_tabIndex
].secondaryView
));
1230 if (m_activeViewContainer
== viewContainer
) {
1234 m_activeViewContainer
->setActive(false);
1235 m_activeViewContainer
= viewContainer
;
1237 // Activating the view container might trigger a recursive setActiveViewContainer() call
1238 // inside DolphinMainWindow::toggleActiveView() when having a split view. Temporary
1239 // disconnect the activated() signal in this case:
1240 disconnect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1241 m_activeViewContainer
->setActive(true);
1242 connect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1244 m_actionHandler
->setCurrentView(viewContainer
->view());
1247 updateEditActions();
1248 updateViewActions();
1251 const KUrl
& url
= m_activeViewContainer
->url();
1252 setUrlAsCaption(url
);
1253 if (m_viewTab
.count() > 1 && m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
1254 m_tabBar
->setTabText(m_tabIndex
, tabName(url
));
1255 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(KMimeType::iconNameForUrl(url
)));
1258 emit
urlChanged(url
);
1261 void DolphinMainWindow::setupActions()
1263 // setup 'File' menu
1264 m_newMenu
= new DolphinNewMenu(this, this);
1265 KMenu
* menu
= m_newMenu
->menu();
1266 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1267 menu
->setIcon(KIcon("document-new"));
1268 connect(menu
, SIGNAL(aboutToShow()),
1269 this, SLOT(updateNewMenu()));
1271 KAction
* newWindow
= actionCollection()->addAction("new_window");
1272 newWindow
->setIcon(KIcon("window-new"));
1273 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1274 newWindow
->setShortcut(Qt::CTRL
| Qt::Key_N
);
1275 connect(newWindow
, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1277 KAction
* newTab
= actionCollection()->addAction("new_tab");
1278 newTab
->setIcon(KIcon("tab-new"));
1279 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1280 newTab
->setShortcut(KShortcut(Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
));
1281 connect(newTab
, SIGNAL(triggered()), this, SLOT(openNewTab()));
1283 KAction
* closeTab
= actionCollection()->addAction("close_tab");
1284 closeTab
->setIcon(KIcon("tab-close"));
1285 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1286 closeTab
->setShortcut(Qt::CTRL
| Qt::Key_W
);
1287 closeTab
->setEnabled(false);
1288 connect(closeTab
, SIGNAL(triggered()), this, SLOT(closeTab()));
1290 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1292 // setup 'Edit' menu
1293 KStandardAction::undo(this,
1295 actionCollection());
1297 // need to remove shift+del from cut action, else the shortcut for deletejob
1299 KAction
* cut
= KStandardAction::cut(this, SLOT(cut()), actionCollection());
1300 KShortcut cutShortcut
= cut
->shortcut();
1301 cutShortcut
.remove(Qt::SHIFT
+ Qt::Key_Delete
, KShortcut::KeepEmpty
);
1302 cut
->setShortcut(cutShortcut
);
1303 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1304 KAction
* paste
= KStandardAction::paste(this, SLOT(paste()), actionCollection());
1305 // The text of the paste-action is modified dynamically by Dolphin
1306 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1307 // due to the long text, the text "Paste" is used:
1308 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1310 KAction
* selectAll
= actionCollection()->addAction("select_all");
1311 selectAll
->setText(i18nc("@action:inmenu Edit", "Select All"));
1312 selectAll
->setShortcut(Qt::CTRL
+ Qt::Key_A
);
1313 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
1315 KAction
* invertSelection
= actionCollection()->addAction("invert_selection");
1316 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1317 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1318 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
1320 // setup 'View' menu
1321 // (note that most of it is set up in DolphinViewActionHandler)
1323 KAction
* split
= actionCollection()->addAction("split_view");
1324 split
->setShortcut(Qt::Key_F3
);
1325 updateSplitAction();
1326 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1328 KAction
* reload
= actionCollection()->addAction("reload");
1329 reload
->setText(i18nc("@action:inmenu View", "Reload"));
1330 reload
->setShortcut(Qt::Key_F5
);
1331 reload
->setIcon(KIcon("view-refresh"));
1332 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
1334 KAction
* stop
= actionCollection()->addAction("stop");
1335 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1336 stop
->setToolTip(i18nc("@info", "Stop loading"));
1337 stop
->setIcon(KIcon("process-stop"));
1338 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
1340 KToggleAction
* showFullLocation
= actionCollection()->add
<KToggleAction
>("editable_location");
1341 showFullLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1342 showFullLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
1343 connect(showFullLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1345 KAction
* replaceLocation
= actionCollection()->addAction("replace_location");
1346 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1347 replaceLocation
->setShortcut(Qt::Key_F6
);
1348 connect(replaceLocation
, SIGNAL(triggered()), this, SLOT(replaceLocation()));
1351 KAction
* backAction
= KStandardAction::back(this, SLOT(goBack()), actionCollection());
1352 connect(backAction
, SIGNAL(triggered(Qt::MouseButtons
, Qt::KeyboardModifiers
)), this, SLOT(goBack(Qt::MouseButtons
)));
1353 KShortcut backShortcut
= backAction
->shortcut();
1354 backShortcut
.setAlternate(Qt::Key_Backspace
);
1355 backAction
->setShortcut(backShortcut
);
1357 m_recentTabsMenu
= new KActionMenu(i18n("Recently Closed Tabs"), this);
1358 m_recentTabsMenu
->setIcon(KIcon("edit-undo"));
1359 actionCollection()->addAction("closed_tabs", m_recentTabsMenu
);
1360 connect(m_recentTabsMenu
->menu(), SIGNAL(triggered(QAction
*)),
1361 this, SLOT(restoreClosedTab(QAction
*)));
1363 QAction
* action
= new QAction("Empty Recently Closed Tabs", m_recentTabsMenu
);
1364 action
->setIcon(KIcon("edit-clear-list"));
1365 action
->setData(QVariant::fromValue(true));
1366 m_recentTabsMenu
->addAction(action
);
1367 m_recentTabsMenu
->addSeparator();
1368 m_recentTabsMenu
->setEnabled(false);
1370 KAction
* forwardAction
= KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1371 connect(forwardAction
, SIGNAL(triggered(Qt::MouseButtons
, Qt::KeyboardModifiers
)), this, SLOT(goForward(Qt::MouseButtons
)));
1373 KAction
* upAction
= KStandardAction::up(this, SLOT(goUp()), actionCollection());
1374 connect(upAction
, SIGNAL(triggered(Qt::MouseButtons
, Qt::KeyboardModifiers
)), this, SLOT(goUp(Qt::MouseButtons
)));
1376 KStandardAction::home(this, SLOT(goHome()), actionCollection());
1378 // setup 'Tools' menu
1379 KToggleAction
* showSearchBar
= actionCollection()->add
<KToggleAction
>("show_search_bar");
1380 showSearchBar
->setText(i18nc("@action:inmenu Tools", "Show Search Bar"));
1381 showSearchBar
->setShortcut(Qt::CTRL
| Qt::Key_S
);
1382 connect(showSearchBar
, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
1384 KToggleAction
* showFilterBar
= actionCollection()->add
<KToggleAction
>("show_filter_bar");
1385 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1386 showFilterBar
->setIcon(KIcon("view-filter"));
1387 showFilterBar
->setShortcut(Qt::CTRL
| Qt::Key_I
);
1388 connect(showFilterBar
, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
1390 KAction
* compareFiles
= actionCollection()->addAction("compare_files");
1391 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1392 compareFiles
->setIcon(KIcon("kompare"));
1393 compareFiles
->setEnabled(false);
1394 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
1396 KAction
* openTerminal
= actionCollection()->addAction("open_terminal");
1397 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1398 openTerminal
->setIcon(KIcon("utilities-terminal"));
1399 openTerminal
->setShortcut(Qt::SHIFT
| Qt::Key_F4
);
1400 connect(openTerminal
, SIGNAL(triggered()), this, SLOT(openTerminal()));
1402 // setup 'Settings' menu
1403 m_showMenuBar
= KStandardAction::showMenubar(this, SLOT(toggleShowMenuBar()), actionCollection());
1404 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1406 // not in menu actions
1407 KAction
* activateNextTab
= actionCollection()->addAction("activate_next_tab");
1408 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1409 connect(activateNextTab
, SIGNAL(triggered()), SLOT(activateNextTab()));
1410 activateNextTab
->setShortcuts(QApplication::isRightToLeft() ? KStandardShortcut::tabPrev() :
1411 KStandardShortcut::tabNext());
1413 KAction
* activatePrevTab
= actionCollection()->addAction("activate_prev_tab");
1414 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1415 connect(activatePrevTab
, SIGNAL(triggered()), SLOT(activatePrevTab()));
1416 activatePrevTab
->setShortcuts(QApplication::isRightToLeft() ? KStandardShortcut::tabNext() :
1417 KStandardShortcut::tabPrev());
1420 KAction
* openInNewTab
= actionCollection()->addAction("open_in_new_tab");
1421 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1422 openInNewTab
->setIcon(KIcon("tab-new"));
1423 connect(openInNewTab
, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1425 KAction
* openInNewWindow
= actionCollection()->addAction("open_in_new_window");
1426 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1427 openInNewWindow
->setIcon(KIcon("window-new"));
1428 connect(openInNewWindow
, SIGNAL(triggered()), this, SLOT(openInNewWindow()));
1431 m_searchBox
= new DolphinSearchBox(this);
1432 connect(m_searchBox
, SIGNAL(search(QString
)), this, SLOT(searchItems()));
1434 KAction
* search
= new KAction(this);
1435 actionCollection()->addAction("search_bar", search
);
1436 search
->setText(i18nc("@action:inmenu", "Search Bar"));
1437 search
->setDefaultWidget(m_searchBox
);
1438 search
->setShortcutConfigurable(false);
1441 void DolphinMainWindow::setupDockWidgets()
1443 // setup "Information"
1444 QDockWidget
* infoDock
= new QDockWidget(i18nc("@title:window", "Information"));
1445 infoDock
->setObjectName("infoDock");
1446 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1447 Panel
* infoPanel
= new InformationPanel(infoDock
);
1448 connect(infoPanel
, SIGNAL(urlActivated(KUrl
)), this, SLOT(handleUrl(KUrl
)));
1449 infoDock
->setWidget(infoPanel
);
1451 KAction
* infoAction
= new KAction(this);
1452 infoAction
->setText(i18nc("@title:window", "Information"));
1453 infoAction
->setShortcut(Qt::Key_F11
);
1454 infoAction
->setIcon(KIcon("dialog-information"));
1455 actionCollection()->addAction("show_info_panel", infoAction
);
1456 connect(infoAction
, SIGNAL(triggered()), infoDock
->toggleViewAction(), SLOT(trigger()));
1458 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1459 connect(this, SIGNAL(urlChanged(KUrl
)),
1460 infoPanel
, SLOT(setUrl(KUrl
)));
1461 connect(this, SIGNAL(selectionChanged(KFileItemList
)),
1462 infoPanel
, SLOT(setSelection(KFileItemList
)));
1463 connect(this, SIGNAL(requestItemInfo(KFileItem
)),
1464 infoPanel
, SLOT(requestDelayedItemInfo(KFileItem
)));
1467 QDockWidget
* foldersDock
= new QDockWidget(i18nc("@title:window", "Folders"));
1468 foldersDock
->setObjectName("foldersDock");
1469 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1470 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1471 foldersDock
->setWidget(foldersPanel
);
1473 KAction
* foldersAction
= new KAction(this);
1474 foldersAction
->setText(i18nc("@title:window", "Folders"));
1475 foldersAction
->setShortcut(Qt::Key_F7
);
1476 foldersAction
->setIcon(KIcon("folder"));
1477 actionCollection()->addAction("show_folders_panel", foldersAction
);
1478 connect(foldersAction
, SIGNAL(triggered()), foldersDock
->toggleViewAction(), SLOT(trigger()));
1480 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1481 connect(this, SIGNAL(urlChanged(KUrl
)),
1482 foldersPanel
, SLOT(setUrl(KUrl
)));
1483 connect(foldersPanel
, SIGNAL(changeUrl(KUrl
, Qt::MouseButtons
)),
1484 this, SLOT(handlePlacesClick(KUrl
, Qt::MouseButtons
)));
1488 QDockWidget
* terminalDock
= new QDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1489 terminalDock
->setObjectName("terminalDock");
1490 terminalDock
->setAllowedAreas(Qt::TopDockWidgetArea
| Qt::BottomDockWidgetArea
);
1491 Panel
* terminalPanel
= new TerminalPanel(terminalDock
);
1492 terminalDock
->setWidget(terminalPanel
);
1494 connect(terminalPanel
, SIGNAL(hideTerminalPanel()), terminalDock
, SLOT(hide()));
1496 KAction
* terminalAction
= new KAction(this);
1497 terminalAction
->setText(i18nc("@title:window Shell terminal", "Terminal"));
1498 terminalAction
->setShortcut(Qt::Key_F4
);
1499 terminalAction
->setIcon(KIcon("utilities-terminal"));
1500 actionCollection()->addAction("show_terminal_panel", terminalAction
);
1501 connect(terminalAction
, SIGNAL(triggered()), terminalDock
->toggleViewAction(), SLOT(trigger()));
1503 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1504 connect(this, SIGNAL(urlChanged(KUrl
)),
1505 terminalPanel
, SLOT(setUrl(KUrl
)));
1508 const bool firstRun
= DolphinSettings::instance().generalSettings()->firstRun();
1510 foldersDock
->hide();
1512 terminalDock
->hide();
1517 QDockWidget
* placesDock
= new QDockWidget(i18nc("@title:window", "Places"));
1518 placesDock
->setObjectName("placesDock");
1519 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1521 PlacesPanel
* placesPanel
= new PlacesPanel(placesDock
);
1522 placesDock
->setWidget(placesPanel
);
1523 placesPanel
->setModel(DolphinSettings::instance().placesModel());
1524 placesPanel
->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff
);
1526 KAction
* placesAction
= new KAction(this);
1527 placesAction
->setText(i18nc("@title:window", "Places"));
1528 placesAction
->setShortcut(Qt::Key_F9
);
1529 placesAction
->setIcon(KIcon("bookmarks"));
1530 actionCollection()->addAction("show_places_panel", placesAction
);
1531 connect(placesAction
, SIGNAL(triggered()), placesDock
->toggleViewAction(), SLOT(trigger()));
1533 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1534 connect(placesPanel
, SIGNAL(urlChanged(KUrl
, Qt::MouseButtons
)),
1535 this, SLOT(handlePlacesClick(KUrl
, Qt::MouseButtons
)));
1536 connect(this, SIGNAL(urlChanged(KUrl
)),
1537 placesPanel
, SLOT(setUrl(KUrl
)));
1540 void DolphinMainWindow::updateEditActions()
1542 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1543 if (list
.isEmpty()) {
1544 stateChanged("has_no_selection");
1546 stateChanged("has_selection");
1548 KActionCollection
* col
= actionCollection();
1549 QAction
* renameAction
= col
->action("rename");
1550 QAction
* moveToTrashAction
= col
->action("move_to_trash");
1551 QAction
* deleteAction
= col
->action("delete");
1552 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
1553 QAction
* deleteWithTrashShortcut
= col
->action("delete_shortcut"); // see DolphinViewActionHandler
1555 KFileItemListProperties
capabilities(list
);
1556 const bool enableMoveToTrash
= capabilities
.isLocal() && capabilities
.supportsMoving();
1558 renameAction
->setEnabled(capabilities
.supportsMoving());
1559 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1560 deleteAction
->setEnabled(capabilities
.supportsDeleting());
1561 deleteWithTrashShortcut
->setEnabled(capabilities
.supportsDeleting() && !enableMoveToTrash
);
1562 cutAction
->setEnabled(capabilities
.supportsMoving());
1564 updatePasteAction();
1567 void DolphinMainWindow::updateViewActions()
1569 m_actionHandler
->updateViewActions();
1571 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1572 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
1574 updateSplitAction();
1576 QAction
* editableLocactionAction
= actionCollection()->action("editable_location");
1577 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
1578 editableLocactionAction
->setChecked(urlNavigator
->isUrlEditable());
1581 void DolphinMainWindow::updateGoActions()
1583 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
1584 const KUrl
& currentUrl
= m_activeViewContainer
->url();
1585 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
1588 void DolphinMainWindow::rememberClosedTab(int index
)
1590 KMenu
* tabsMenu
= m_recentTabsMenu
->menu();
1592 const QString primaryPath
= m_viewTab
[index
].primaryView
->url().path();
1593 const QString iconName
= KMimeType::iconNameForUrl(primaryPath
);
1595 QAction
* action
= new QAction(squeezedText(primaryPath
), tabsMenu
);
1597 ClosedTab closedTab
;
1598 closedTab
.primaryUrl
= m_viewTab
[index
].primaryView
->url();
1600 if (m_viewTab
[index
].secondaryView
!= 0) {
1601 closedTab
.secondaryUrl
= m_viewTab
[index
].secondaryView
->url();
1602 closedTab
.isSplit
= true;
1604 closedTab
.isSplit
= false;
1607 action
->setData(QVariant::fromValue(closedTab
));
1608 action
->setIcon(KIcon(iconName
));
1610 // add the closed tab menu entry after the separator and
1611 // "Empty Recently Closed Tabs" entry
1612 if (tabsMenu
->actions().size() == 2) {
1613 tabsMenu
->addAction(action
);
1615 tabsMenu
->insertAction(tabsMenu
->actions().at(2), action
);
1618 // assure that only up to 8 closed tabs are shown in the menu
1619 if (tabsMenu
->actions().size() > 8) {
1620 tabsMenu
->removeAction(tabsMenu
->actions().last());
1622 actionCollection()->action("closed_tabs")->setEnabled(true);
1623 KAcceleratorManager::manage(tabsMenu
);
1626 void DolphinMainWindow::clearStatusBar()
1628 m_activeViewContainer
->statusBar()->clear();
1631 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
1633 connect(container
, SIGNAL(showFilterBarChanged(bool)),
1634 this, SLOT(updateFilterBarAction(bool)));
1636 DolphinView
* view
= container
->view();
1637 connect(view
, SIGNAL(selectionChanged(KFileItemList
)),
1638 this, SLOT(slotSelectionChanged(KFileItemList
)));
1639 connect(view
, SIGNAL(requestItemInfo(KFileItem
)),
1640 this, SLOT(slotRequestItemInfo(KFileItem
)));
1641 connect(view
, SIGNAL(activated()),
1642 this, SLOT(toggleActiveView()));
1643 connect(view
, SIGNAL(tabRequested(const KUrl
&)),
1644 this, SLOT(openNewTab(const KUrl
&)));
1646 const KUrlNavigator
* navigator
= container
->urlNavigator();
1647 connect(navigator
, SIGNAL(urlChanged(const KUrl
&)),
1648 this, SLOT(changeUrl(const KUrl
&)));
1649 connect(navigator
, SIGNAL(historyChanged()),
1650 this, SLOT(updateHistory()));
1651 connect(navigator
, SIGNAL(editableStateChanged(bool)),
1652 this, SLOT(slotEditableStateChanged(bool)));
1655 void DolphinMainWindow::updateSplitAction()
1657 QAction
* splitAction
= actionCollection()->action("split_view");
1658 if (m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
1659 if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
1660 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
1661 splitAction
->setToolTip(i18nc("@info", "Close right view"));
1662 splitAction
->setIcon(KIcon("view-right-close"));
1664 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
1665 splitAction
->setToolTip(i18nc("@info", "Close left view"));
1666 splitAction
->setIcon(KIcon("view-left-close"));
1669 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
1670 splitAction
->setToolTip(i18nc("@info", "Split view"));
1671 splitAction
->setIcon(KIcon("view-right-new"));
1675 QString
DolphinMainWindow::tabName(const KUrl
& url
) const
1678 if (url
.equals(KUrl("file:///"))) {
1681 name
= url
.fileName();
1682 if (name
.isEmpty()) {
1683 name
= url
.protocol();
1685 // Make sure that a '&' inside the directory name is displayed correctly
1686 // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
1687 name
.replace('&', "&&");
1693 bool DolphinMainWindow::isKompareInstalled() const
1695 static bool initialized
= false;
1696 static bool installed
= false;
1698 // TODO: maybe replace this approach later by using a menu
1699 // plugin like kdiff3plugin.cpp
1700 installed
= !KGlobal::dirs()->findExe("kompare").isEmpty();
1706 void DolphinMainWindow::createSecondaryView(int tabIndex
)
1708 QSplitter
* splitter
= m_viewTab
[tabIndex
].splitter
;
1709 const int newWidth
= (m_viewTab
[tabIndex
].primaryView
->width() - splitter
->handleWidth()) / 2;
1711 const DolphinView
* view
= m_viewTab
[tabIndex
].primaryView
->view();
1712 m_viewTab
[tabIndex
].secondaryView
= new DolphinViewContainer(this, 0, view
->rootUrl());
1713 splitter
->addWidget(m_viewTab
[tabIndex
].secondaryView
);
1714 splitter
->setSizes(QList
<int>() << newWidth
<< newWidth
);
1715 connectViewSignals(m_viewTab
[tabIndex
].secondaryView
);
1716 m_viewTab
[tabIndex
].secondaryView
->view()->reload();
1717 m_viewTab
[tabIndex
].secondaryView
->setActive(false);
1718 m_viewTab
[tabIndex
].secondaryView
->show();
1721 QString
DolphinMainWindow::tabProperty(const QString
& property
, int tabIndex
) const
1723 return "Tab " + QString::number(tabIndex
) + ' ' + property
;
1726 void DolphinMainWindow::setUrlAsCaption(const KUrl
& url
)
1729 if (url
.equals(KUrl("file:///"))) {
1732 caption
= url
.fileName();
1733 if (caption
.isEmpty()) {
1734 caption
= url
.protocol();
1738 setCaption(caption
);
1741 void DolphinMainWindow::handleUrl(const KUrl
& url
)
1743 if (KProtocolManager::supportsListing(url
)) {
1744 activeViewContainer()->setUrl(url
);
1747 new KRun(url
, this);
1751 QString
DolphinMainWindow::squeezedText(const QString
& text
) const
1753 const QFontMetrics fm
= fontMetrics();
1754 return fm
.elidedText(text
, Qt::ElideMiddle
, fm
.maxWidth() * 10);
1757 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
1758 KIO::FileUndoManager::UiInterface()
1762 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
1766 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
1768 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
1770 DolphinStatusBar
* statusBar
= mainWin
->activeViewContainer()->statusBar();
1771 statusBar
->setMessage(job
->errorString(), DolphinStatusBar::Error
);
1773 KIO::FileUndoManager::UiInterface::jobError(job
);
1777 #include "dolphinmainwindow.moc"