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 if (m_viewTab
.count() == 1) {
401 // Only one view is open currently and hence no tab is shown at
402 // all. Before creating a tab for 'url', provide a tab for the current URL.
403 const KUrl currentUrl
= m_activeViewContainer
->url();
404 m_tabBar
->addTab(KIcon(KMimeType::iconNameForUrl(currentUrl
)),
405 squeezedText(tabName(currentUrl
)));
406 m_tabBar
->blockSignals(false);
409 m_tabBar
->addTab(KIcon(KMimeType::iconNameForUrl(url
)),
410 squeezedText(tabName(url
)));
413 viewTab
.splitter
= new QSplitter(this);
414 viewTab
.splitter
->setChildrenCollapsible(false);
415 viewTab
.primaryView
= new DolphinViewContainer(this, viewTab
.splitter
, url
);
416 viewTab
.primaryView
->setActive(false);
417 connectViewSignals(viewTab
.primaryView
);
418 viewTab
.primaryView
->view()->reload();
420 m_viewTab
.append(viewTab
);
422 actionCollection()->action("close_tab")->setEnabled(true);
424 // provide a split view, if the startup settings are set this way
425 const GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
426 if (generalSettings
->splitView()) {
427 const int tabIndex
= m_viewTab
.count() - 1;
428 createSecondaryView(tabIndex
);
429 m_viewTab
[tabIndex
].secondaryView
->setActive(true);
430 m_viewTab
[tabIndex
].isPrimaryViewActive
= false;
434 void DolphinMainWindow::activateNextTab()
436 if ((m_viewTab
.count() == 1) || (m_tabBar
->count() < 2)) {
440 const int tabIndex
= (m_tabBar
->currentIndex() + 1) % m_tabBar
->count();
441 m_tabBar
->setCurrentIndex(tabIndex
);
444 void DolphinMainWindow::activatePrevTab()
446 if ((m_viewTab
.count() == 1) || (m_tabBar
->count() < 2)) {
450 int tabIndex
= m_tabBar
->currentIndex() - 1;
451 if (tabIndex
== -1) {
452 tabIndex
= m_tabBar
->count() - 1;
454 m_tabBar
->setCurrentIndex(tabIndex
);
457 void DolphinMainWindow::openInNewTab()
459 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
460 if ((list
.count() == 1) && list
[0].isDir()) {
461 openNewTab(m_activeViewContainer
->view()->selectedUrls()[0]);
465 void DolphinMainWindow::openInNewWindow()
467 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
468 if ((list
.count() == 1) && list
[0].isDir()) {
469 DolphinMainWindow
* window
= DolphinApplication::app()->createMainWindow();
470 window
->changeUrl(m_activeViewContainer
->view()->selectedUrls()[0]);
475 void DolphinMainWindow::toggleActiveView()
477 if (m_viewTab
[m_tabIndex
].secondaryView
== 0) {
478 // only one view is available
482 Q_ASSERT(m_activeViewContainer
!= 0);
483 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
485 DolphinViewContainer
* left
= m_viewTab
[m_tabIndex
].primaryView
;
486 DolphinViewContainer
* right
= m_viewTab
[m_tabIndex
].secondaryView
;
487 setActiveViewContainer(m_activeViewContainer
== right
? left
: right
);
490 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
492 DolphinSettings
& settings
= DolphinSettings::instance();
493 GeneralSettings
* generalSettings
= settings
.generalSettings();
495 // Find out if Dolphin is closed directly by the user or
496 // by the session manager because the session is closed
497 bool closedByUser
= true;
498 DolphinApplication
*application
= qobject_cast
<DolphinApplication
*>(qApp
);
499 if (application
&& application
->sessionSaving()) {
500 closedByUser
= false;
503 if ((m_viewTab
.count() > 1) && generalSettings
->confirmClosingMultipleTabs() && closedByUser
) {
504 // Ask the user if he really wants to quit and close all tabs.
505 // Open a confirmation dialog with 3 buttons:
506 // KDialog::Yes -> Quit
507 // KDialog::No -> Close only the current tab
508 // KDialog::Cancel -> do nothing
509 KDialog
*dialog
= new KDialog(this, Qt::Dialog
);
510 dialog
->setCaption(i18nc("@title:window", "Confirmation"));
511 dialog
->setButtons(KDialog::Yes
| KDialog::No
| KDialog::Cancel
);
512 dialog
->setModal(true);
513 dialog
->showButtonSeparator(true);
514 dialog
->setButtonGuiItem(KDialog::Yes
, KStandardGuiItem::quit());
515 dialog
->setButtonGuiItem(KDialog::No
, KGuiItem(i18n("C&lose Current Tab"), KIcon("tab-close")));
516 dialog
->setButtonGuiItem(KDialog::Cancel
, KStandardGuiItem::cancel());
517 dialog
->setDefaultButton(KDialog::Yes
);
519 bool doNotAskAgainCheckboxResult
= false;
521 const int result
= KMessageBox::createKMessageBox(dialog
,
522 QMessageBox::Warning
,
523 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
525 i18n("Do not ask again"),
526 &doNotAskAgainCheckboxResult
,
527 KMessageBox::Notify
);
529 if (doNotAskAgainCheckboxResult
) {
530 generalSettings
->setConfirmClosingMultipleTabs(false);
538 // Close only the current tab
546 generalSettings
->setFirstRun(false);
550 KXmlGuiWindow::closeEvent(event
);
553 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
555 const int tabCount
= m_viewTab
.count();
556 group
.writeEntry("Tab Count", tabCount
);
557 group
.writeEntry("Active Tab Index", m_tabBar
->currentIndex());
559 for (int i
= 0; i
< tabCount
; ++i
) {
560 const DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
561 group
.writeEntry(tabProperty("Primary URL", i
), cont
->url().url());
562 group
.writeEntry(tabProperty("Primary Editable", i
), cont
->isUrlEditable());
564 cont
= m_viewTab
[i
].secondaryView
;
566 group
.writeEntry(tabProperty("Secondary URL", i
), cont
->url().url());
567 group
.writeEntry(tabProperty("Secondary Editable", i
), cont
->isUrlEditable());
572 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
574 const int tabCount
= group
.readEntry("Tab Count", 1);
575 for (int i
= 0; i
< tabCount
; ++i
) {
576 DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
578 cont
->setUrl(group
.readEntry(tabProperty("Primary URL", i
)));
579 const bool editable
= group
.readEntry(tabProperty("Primary Editable", i
), false);
580 cont
->urlNavigator()->setUrlEditable(editable
);
582 cont
= m_viewTab
[i
].secondaryView
;
583 const QString secondaryUrl
= group
.readEntry(tabProperty("Secondary URL", i
));
584 if (!secondaryUrl
.isEmpty()) {
586 // a secondary view should be shown, but no one is available
587 // currently -> create a new view
589 cont
= m_viewTab
[i
].secondaryView
;
593 cont
->setUrl(secondaryUrl
);
594 const bool editable
= group
.readEntry(tabProperty("Secondary Editable", i
), false);
595 cont
->urlNavigator()->setUrlEditable(editable
);
596 } else if (cont
!= 0) {
597 // no secondary view should be shown, but the default setting shows
598 // one already -> close the view
602 // openNewTab() needs to be called only tabCount - 1 times
603 if (i
!= tabCount
- 1) {
608 const int index
= group
.readEntry("Active Tab Index", 0);
609 m_tabBar
->setCurrentIndex(index
);
612 void DolphinMainWindow::updateNewMenu()
614 m_newMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->showHiddenFiles());
615 m_newMenu
->slotCheckUpToDate();
616 m_newMenu
->setPopupFiles(activeViewContainer()->url());
619 void DolphinMainWindow::createDirectory()
621 m_newMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->showHiddenFiles());
622 m_newMenu
->setPopupFiles(activeViewContainer()->url());
623 m_newMenu
->createDirectory();
626 void DolphinMainWindow::quit()
631 void DolphinMainWindow::showErrorMessage(const QString
& message
)
633 if (!message
.isEmpty()) {
634 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
635 statusBar
->setMessage(message
, DolphinStatusBar::Error
);
639 void DolphinMainWindow::slotUndoAvailable(bool available
)
641 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
642 if (undoAction
!= 0) {
643 undoAction
->setEnabled(available
);
647 void DolphinMainWindow::restoreClosedTab(QAction
* action
)
649 if (action
->data().toBool()) {
650 // clear all actions except the "Empty Recently Closed Tabs"
651 // action and the separator
652 QList
<QAction
*> actions
= m_recentTabsMenu
->menu()->actions();
653 const int count
= actions
.size();
654 for (int i
= 2; i
< count
; ++i
) {
655 m_recentTabsMenu
->menu()->removeAction(actions
.at(i
));
658 const ClosedTab closedTab
= action
->data().value
<ClosedTab
>();
659 openNewTab(closedTab
.primaryUrl
);
660 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
662 if (closedTab
.isSplit
) {
663 // create secondary view
665 m_viewTab
[m_tabIndex
].secondaryView
->setUrl(closedTab
.secondaryUrl
);
668 m_recentTabsMenu
->removeAction(action
);
671 if (m_recentTabsMenu
->menu()->actions().count() == 2) {
672 m_recentTabsMenu
->setEnabled(false);
676 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
678 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
679 if (undoAction
!= 0) {
680 undoAction
->setText(text
);
684 void DolphinMainWindow::undo()
687 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
688 KIO::FileUndoManager::self()->undo();
691 void DolphinMainWindow::cut()
693 m_activeViewContainer
->view()->cutSelectedItems();
696 void DolphinMainWindow::copy()
698 m_activeViewContainer
->view()->copySelectedItems();
701 void DolphinMainWindow::paste()
703 m_activeViewContainer
->view()->paste();
706 void DolphinMainWindow::updatePasteAction()
708 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
709 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
710 pasteAction
->setEnabled(pasteInfo
.first
);
711 pasteAction
->setText(pasteInfo
.second
);
714 void DolphinMainWindow::selectAll()
718 // if the URL navigator is editable and focused, select the whole
719 // URL instead of all items of the view
721 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
722 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit(); // krazy:exclude=qclasses
723 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
724 lineEdit
->hasFocus();
726 lineEdit
->selectAll();
728 m_activeViewContainer
->view()->selectAll();
732 void DolphinMainWindow::invertSelection()
735 m_activeViewContainer
->view()->invertSelection();
738 void DolphinMainWindow::toggleSplitView()
740 if (m_viewTab
[m_tabIndex
].secondaryView
== 0) {
741 createSecondaryView(m_tabIndex
);
742 setActiveViewContainer(m_viewTab
[m_tabIndex
].secondaryView
);
743 } else if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
744 // remove secondary view
745 m_viewTab
[m_tabIndex
].secondaryView
->close();
746 m_viewTab
[m_tabIndex
].secondaryView
->deleteLater();
747 m_viewTab
[m_tabIndex
].secondaryView
= 0;
749 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
751 // The primary view is active and should be closed. Hence from a users point of view
752 // the content of the secondary view should be moved to the primary view.
753 // From an implementation point of view it is more efficient to close
754 // the primary view and exchange the internal pointers afterwards.
756 m_viewTab
[m_tabIndex
].primaryView
->close();
757 m_viewTab
[m_tabIndex
].primaryView
->deleteLater();
758 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
759 m_viewTab
[m_tabIndex
].secondaryView
= 0;
761 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
767 void DolphinMainWindow::reloadView()
770 m_activeViewContainer
->view()->reload();
773 void DolphinMainWindow::stopLoading()
777 void DolphinMainWindow::toggleFilterBarVisibility(bool show
)
779 m_activeViewContainer
->showFilterBar(show
);
782 void DolphinMainWindow::toggleEditLocation()
786 QAction
* action
= actionCollection()->action("editable_location");
787 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
788 urlNavigator
->setUrlEditable(action
->isChecked());
791 void DolphinMainWindow::replaceLocation()
793 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
794 navigator
->setUrlEditable(true);
795 navigator
->setFocus();
797 // select the whole text of the combo box editor
798 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit(); // krazy:exclude=qclasses
799 const QString text
= lineEdit
->text();
800 lineEdit
->setSelection(0, text
.length());
803 void DolphinMainWindow::goBack()
806 m_activeViewContainer
->urlNavigator()->goBack();
809 void DolphinMainWindow::goForward()
812 m_activeViewContainer
->urlNavigator()->goForward();
815 void DolphinMainWindow::goUp()
818 m_activeViewContainer
->urlNavigator()->goUp();
821 void DolphinMainWindow::goBack(Qt::MouseButtons buttons
)
823 // The default case (left button pressed) is handled in goBack().
824 if (buttons
== Qt::MidButton
) {
825 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
826 openNewTab(urlNavigator
->historyUrl(urlNavigator
->historyIndex() + 1));
830 void DolphinMainWindow::goForward(Qt::MouseButtons buttons
)
832 // The default case (left button pressed) is handled in goForward().
833 if (buttons
== Qt::MidButton
) {
834 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
835 openNewTab(urlNavigator
->historyUrl(urlNavigator
->historyIndex() - 1));
839 void DolphinMainWindow::goUp(Qt::MouseButtons buttons
)
841 // The default case (left button pressed) is handled in goUp().
842 if (buttons
== Qt::MidButton
) {
843 openNewTab(activeViewContainer()->url().upUrl());
847 void DolphinMainWindow::goHome()
850 m_activeViewContainer
->urlNavigator()->goHome();
853 void DolphinMainWindow::compareFiles()
855 // The method is only invoked if exactly 2 files have
856 // been selected. The selected files may be:
857 // - both in the primary view
858 // - both in the secondary view
859 // - one in the primary view and the other in the secondary
861 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
865 KUrl::List urls
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedUrls();
867 switch (urls
.count()) {
869 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
!= 0);
870 urls
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedUrls();
871 Q_ASSERT(urls
.count() == 2);
879 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
!= 0);
880 urls
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedUrls();
881 Q_ASSERT(urls
.count() == 1);
893 // may not happen: compareFiles may only get invoked if 2
894 // files are selected
899 QString
command("kompare -c \"");
900 command
.append(urlA
.pathOrUrl());
901 command
.append("\" \"");
902 command
.append(urlB
.pathOrUrl());
903 command
.append('\"');
904 KRun::runCommand(command
, "Kompare", "kompare", this);
907 void DolphinMainWindow::toggleShowMenuBar()
909 const bool visible
= menuBar()->isVisible();
910 menuBar()->setVisible(!visible
);
913 void DolphinMainWindow::openTerminal()
915 QString
dir(QDir::homePath());
917 // If the given directory is not local, it can still be the URL of an
918 // ioslave using UDS_LOCAL_PATH which to be converted first.
919 KUrl url
= KIO::NetAccess::mostLocalUrl(m_activeViewContainer
->url(), this);
921 //If the URL is local after the above conversion, set the directory.
922 if (url
.isLocalFile()) {
923 dir
= url
.toLocalFile();
926 KToolInvocation::invokeTerminal(QString(), dir
);
929 void DolphinMainWindow::editSettings()
931 if (m_settingsDialog
== 0) {
932 const KUrl
& url
= activeViewContainer()->url();
933 m_settingsDialog
= new DolphinSettingsDialog(url
, this);
934 m_settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
935 m_settingsDialog
->show();
937 m_settingsDialog
->raise();
941 void DolphinMainWindow::setActiveTab(int index
)
943 Q_ASSERT(index
>= 0);
944 Q_ASSERT(index
< m_viewTab
.count());
945 if (index
== m_tabIndex
) {
949 // hide current tab content
950 ViewTab
& hiddenTab
= m_viewTab
[m_tabIndex
];
951 hiddenTab
.isPrimaryViewActive
= hiddenTab
.primaryView
->isActive();
952 hiddenTab
.primaryView
->setActive(false);
953 if (hiddenTab
.secondaryView
!= 0) {
954 hiddenTab
.secondaryView
->setActive(false);
956 QSplitter
* splitter
= m_viewTab
[m_tabIndex
].splitter
;
958 m_centralWidgetLayout
->removeWidget(splitter
);
960 // show active tab content
963 ViewTab
& viewTab
= m_viewTab
[index
];
964 m_centralWidgetLayout
->addWidget(viewTab
.splitter
, 1);
965 viewTab
.primaryView
->show();
966 if (viewTab
.secondaryView
!= 0) {
967 viewTab
.secondaryView
->show();
969 viewTab
.splitter
->show();
971 setActiveViewContainer(viewTab
.isPrimaryViewActive
? viewTab
.primaryView
:
972 viewTab
.secondaryView
);
975 void DolphinMainWindow::closeTab()
977 closeTab(m_tabBar
->currentIndex());
980 void DolphinMainWindow::closeTab(int index
)
982 Q_ASSERT(index
>= 0);
983 Q_ASSERT(index
< m_viewTab
.count());
984 if (m_viewTab
.count() == 1) {
985 // the last tab may never get closed
989 if (index
== m_tabIndex
) {
990 // The tab that should be closed is the active tab. Activate the
991 // previous tab before closing the tab.
992 m_tabBar
->setCurrentIndex((index
> 0) ? index
- 1 : 1);
994 rememberClosedTab(index
);
997 m_viewTab
[index
].primaryView
->deleteLater();
998 if (m_viewTab
[index
].secondaryView
!= 0) {
999 m_viewTab
[index
].secondaryView
->deleteLater();
1001 m_viewTab
[index
].splitter
->deleteLater();
1002 m_viewTab
.erase(m_viewTab
.begin() + index
);
1004 m_tabBar
->blockSignals(true);
1005 m_tabBar
->removeTab(index
);
1007 if (m_tabIndex
> index
) {
1009 Q_ASSERT(m_tabIndex
>= 0);
1012 // if only one tab is left, also remove the tab entry so that
1013 // closing the last tab is not possible
1014 if (m_viewTab
.count() == 1) {
1015 m_tabBar
->removeTab(0);
1016 actionCollection()->action("close_tab")->setEnabled(false);
1018 m_tabBar
->blockSignals(false);
1022 void DolphinMainWindow::openTabContextMenu(int index
, const QPoint
& pos
)
1026 QAction
* newTabAction
= menu
.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab"));
1027 newTabAction
->setShortcut(actionCollection()->action("new_tab")->shortcut());
1029 QAction
* closeOtherTabsAction
= menu
.addAction(KIcon("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs"));
1031 QAction
* closeTabAction
= menu
.addAction(KIcon("tab-close"), i18nc("@action:inmenu", "Close Tab"));
1032 closeTabAction
->setShortcut(actionCollection()->action("close_tab")->shortcut());
1033 QAction
* selectedAction
= menu
.exec(pos
);
1034 if (selectedAction
== newTabAction
) {
1035 const ViewTab
& tab
= m_viewTab
[index
];
1036 Q_ASSERT(tab
.primaryView
!= 0);
1037 const KUrl url
= (tab
.secondaryView
!= 0) && tab
.secondaryView
->isActive() ?
1038 tab
.secondaryView
->url() : tab
.primaryView
->url();
1040 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
1041 } else if (selectedAction
== closeOtherTabsAction
) {
1042 const int count
= m_tabBar
->count();
1043 for (int i
= 0; i
< index
; ++i
) {
1046 for (int i
= index
+ 1; i
< count
; ++i
) {
1049 } else if (selectedAction
== closeTabAction
) {
1054 void DolphinMainWindow::handlePlacesClick(const KUrl
& url
, Qt::MouseButtons buttons
)
1056 if (buttons
& Qt::MidButton
) {
1058 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
1064 void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent
* event
, bool& canDecode
)
1066 canDecode
= KUrl::List::canDecode(event
->mimeData());
1069 void DolphinMainWindow::searchItems()
1072 const KUrl nepomukSearchUrl
= m_searchOptionsConfigurator
->nepomukSearchUrl();
1073 m_activeViewContainer
->setUrl(nepomukSearchUrl
);
1077 void DolphinMainWindow::slotTabMoved(int from
, int to
)
1079 m_viewTab
.move(from
, to
);
1080 m_tabIndex
= m_tabBar
->currentIndex();
1083 void DolphinMainWindow::showSearchOptions()
1086 m_searchOptionsConfigurator
->show();
1090 void DolphinMainWindow::init()
1092 DolphinSettings
& settings
= DolphinSettings::instance();
1094 // Check whether Dolphin runs the first time. If yes then
1095 // a proper default window size is given at the end of DolphinMainWindow::init().
1096 GeneralSettings
* generalSettings
= settings
.generalSettings();
1097 const bool firstRun
= generalSettings
->firstRun();
1099 generalSettings
->setViewPropsTimestamp(QDateTime::currentDateTime());
1102 setAcceptDrops(true);
1104 m_viewTab
[m_tabIndex
].splitter
= new QSplitter(this);
1105 m_viewTab
[m_tabIndex
].splitter
->setChildrenCollapsible(false);
1109 const KUrl
& homeUrl
= generalSettings
->homeUrl();
1110 setUrlAsCaption(homeUrl
);
1111 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
1112 connect(m_actionHandler
, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
1113 connect(m_actionHandler
, SIGNAL(createDirectory()), SLOT(createDirectory()));
1114 ViewProperties
props(homeUrl
);
1115 m_viewTab
[m_tabIndex
].primaryView
= new DolphinViewContainer(this,
1116 m_viewTab
[m_tabIndex
].splitter
,
1119 m_activeViewContainer
= m_viewTab
[m_tabIndex
].primaryView
;
1120 connectViewSignals(m_activeViewContainer
);
1121 DolphinView
* view
= m_activeViewContainer
->view();
1123 m_activeViewContainer
->show();
1124 m_actionHandler
->setCurrentView(view
);
1126 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
1127 connect(this, SIGNAL(urlChanged(const KUrl
&)),
1128 m_remoteEncoding
, SLOT(slotAboutToOpenUrl()));
1131 m_searchOptionsConfigurator
= new DolphinSearchOptionsConfigurator(this);
1132 m_searchOptionsConfigurator
->hide();
1133 connect(m_searchOptionsConfigurator
, SIGNAL(searchOptionsChanged()),
1134 this, SLOT(searchItems()));
1135 connect(this, SIGNAL(urlChanged(KUrl
)), m_searchOptionsConfigurator
, SLOT(setDirectory(KUrl
)));
1138 m_tabBar
= new KTabBar(this);
1139 m_tabBar
->setMovable(true);
1140 m_tabBar
->setTabsClosable(true);
1141 connect(m_tabBar
, SIGNAL(currentChanged(int)),
1142 this, SLOT(setActiveTab(int)));
1143 connect(m_tabBar
, SIGNAL(tabCloseRequested(int)),
1144 this, SLOT(closeTab(int)));
1145 connect(m_tabBar
, SIGNAL(contextMenu(int, const QPoint
&)),
1146 this, SLOT(openTabContextMenu(int, const QPoint
&)));
1147 connect(m_tabBar
, SIGNAL(newTabRequest()),
1148 this, SLOT(openNewTab()));
1149 connect(m_tabBar
, SIGNAL(testCanDecode(const QDragMoveEvent
*, bool&)),
1150 this, SLOT(slotTestCanDecode(const QDragMoveEvent
*, bool&)));
1151 connect(m_tabBar
, SIGNAL(wheelDelta(int)),
1152 this, SLOT(slotWheelMoved(int)));
1153 connect(m_tabBar
, SIGNAL(mouseMiddleClick(int)),
1154 this, SLOT(closeTab(int)));
1155 connect(m_tabBar
, SIGNAL(tabMoved(int, int)),
1156 this, SLOT(slotTabMoved(int, int)));
1158 m_tabBar
->blockSignals(true); // signals get unblocked after at least 2 tabs are open
1160 QWidget
* centralWidget
= new QWidget(this);
1161 m_centralWidgetLayout
= new QVBoxLayout(centralWidget
);
1162 m_centralWidgetLayout
->setSpacing(0);
1163 m_centralWidgetLayout
->setMargin(0);
1165 m_centralWidgetLayout
->addWidget(m_searchOptionsConfigurator
);
1167 m_centralWidgetLayout
->addWidget(m_tabBar
);
1168 m_centralWidgetLayout
->addWidget(m_viewTab
[m_tabIndex
].splitter
, 1);
1170 setCentralWidget(centralWidget
);
1172 emit
urlChanged(homeUrl
);
1174 setupGUI(Keys
| Save
| Create
| ToolBar
);
1176 m_searchBox
->setParent(toolBar("searchToolBar"));
1177 m_searchBox
->show();
1178 connect(m_searchBox
, SIGNAL(requestSearchOptions()),
1179 this, SLOT(showSearchOptions()));
1181 connect(m_searchBox
, SIGNAL(searchTextChanged(QString
)),
1182 m_searchOptionsConfigurator
, SLOT(setCustomSearchQuery(QString
)));
1185 stateChanged("new_file");
1187 QClipboard
* clipboard
= QApplication::clipboard();
1188 connect(clipboard
, SIGNAL(dataChanged()),
1189 this, SLOT(updatePasteAction()));
1190 updatePasteAction();
1193 if (generalSettings
->splitView()) {
1196 updateViewActions();
1198 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1199 showFilterBarAction
->setChecked(generalSettings
->filterBar());
1202 // assure a proper default size if Dolphin runs the first time
1206 m_showMenuBar
->setChecked(!menuBar()->isHidden()); // workaround for bug #171080
1209 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer
* viewContainer
)
1211 Q_ASSERT(viewContainer
!= 0);
1212 Q_ASSERT((viewContainer
== m_viewTab
[m_tabIndex
].primaryView
) ||
1213 (viewContainer
== m_viewTab
[m_tabIndex
].secondaryView
));
1214 if (m_activeViewContainer
== viewContainer
) {
1218 m_activeViewContainer
->setActive(false);
1219 m_activeViewContainer
= viewContainer
;
1221 // Activating the view container might trigger a recursive setActiveViewContainer() call
1222 // inside DolphinMainWindow::toggleActiveView() when having a split view. Temporary
1223 // disconnect the activated() signal in this case:
1224 disconnect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1225 m_activeViewContainer
->setActive(true);
1226 connect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1228 m_actionHandler
->setCurrentView(viewContainer
->view());
1231 updateEditActions();
1232 updateViewActions();
1235 const KUrl
& url
= m_activeViewContainer
->url();
1236 setUrlAsCaption(url
);
1237 if (m_viewTab
.count() > 1 && m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
1238 m_tabBar
->setTabText(m_tabIndex
, tabName(url
));
1239 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(KMimeType::iconNameForUrl(url
)));
1242 emit
urlChanged(url
);
1245 void DolphinMainWindow::setupActions()
1247 // setup 'File' menu
1248 m_newMenu
= new DolphinNewMenu(this, this);
1249 KMenu
* menu
= m_newMenu
->menu();
1250 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1251 menu
->setIcon(KIcon("document-new"));
1252 connect(menu
, SIGNAL(aboutToShow()),
1253 this, SLOT(updateNewMenu()));
1255 KAction
* newWindow
= actionCollection()->addAction("new_window");
1256 newWindow
->setIcon(KIcon("window-new"));
1257 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1258 newWindow
->setShortcut(Qt::CTRL
| Qt::Key_N
);
1259 connect(newWindow
, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1261 KAction
* newTab
= actionCollection()->addAction("new_tab");
1262 newTab
->setIcon(KIcon("tab-new"));
1263 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1264 newTab
->setShortcut(KShortcut(Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
));
1265 connect(newTab
, SIGNAL(triggered()), this, SLOT(openNewTab()));
1267 KAction
* closeTab
= actionCollection()->addAction("close_tab");
1268 closeTab
->setIcon(KIcon("tab-close"));
1269 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1270 closeTab
->setShortcut(Qt::CTRL
| Qt::Key_W
);
1271 closeTab
->setEnabled(false);
1272 connect(closeTab
, SIGNAL(triggered()), this, SLOT(closeTab()));
1274 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1276 // setup 'Edit' menu
1277 KStandardAction::undo(this,
1279 actionCollection());
1281 // need to remove shift+del from cut action, else the shortcut for deletejob
1283 KAction
* cut
= KStandardAction::cut(this, SLOT(cut()), actionCollection());
1284 KShortcut cutShortcut
= cut
->shortcut();
1285 cutShortcut
.remove(Qt::SHIFT
+ Qt::Key_Delete
, KShortcut::KeepEmpty
);
1286 cut
->setShortcut(cutShortcut
);
1287 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1288 KAction
* paste
= KStandardAction::paste(this, SLOT(paste()), actionCollection());
1289 // The text of the paste-action is modified dynamically by Dolphin
1290 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1291 // due to the long text, the text "Paste" is used:
1292 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1294 KAction
* selectAll
= actionCollection()->addAction("select_all");
1295 selectAll
->setText(i18nc("@action:inmenu Edit", "Select All"));
1296 selectAll
->setShortcut(Qt::CTRL
+ Qt::Key_A
);
1297 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
1299 KAction
* invertSelection
= actionCollection()->addAction("invert_selection");
1300 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1301 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1302 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
1304 // setup 'View' menu
1305 // (note that most of it is set up in DolphinViewActionHandler)
1307 KAction
* split
= actionCollection()->addAction("split_view");
1308 split
->setShortcut(Qt::Key_F3
);
1309 updateSplitAction();
1310 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1312 KAction
* reload
= actionCollection()->addAction("reload");
1313 reload
->setText(i18nc("@action:inmenu View", "Reload"));
1314 reload
->setShortcut(Qt::Key_F5
);
1315 reload
->setIcon(KIcon("view-refresh"));
1316 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
1318 KAction
* stop
= actionCollection()->addAction("stop");
1319 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1320 stop
->setToolTip(i18nc("@info", "Stop loading"));
1321 stop
->setIcon(KIcon("process-stop"));
1322 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
1324 KToggleAction
* showFullLocation
= actionCollection()->add
<KToggleAction
>("editable_location");
1325 showFullLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1326 showFullLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
1327 connect(showFullLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1329 KAction
* replaceLocation
= actionCollection()->addAction("replace_location");
1330 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1331 replaceLocation
->setShortcut(Qt::Key_F6
);
1332 connect(replaceLocation
, SIGNAL(triggered()), this, SLOT(replaceLocation()));
1335 KAction
* backAction
= KStandardAction::back(this, SLOT(goBack()), actionCollection());
1336 connect(backAction
, SIGNAL(triggered(Qt::MouseButtons
, Qt::KeyboardModifiers
)), this, SLOT(goBack(Qt::MouseButtons
)));
1337 KShortcut backShortcut
= backAction
->shortcut();
1338 backShortcut
.setAlternate(Qt::Key_Backspace
);
1339 backAction
->setShortcut(backShortcut
);
1341 m_recentTabsMenu
= new KActionMenu(i18n("Recently Closed Tabs"), this);
1342 m_recentTabsMenu
->setIcon(KIcon("edit-undo"));
1343 actionCollection()->addAction("closed_tabs", m_recentTabsMenu
);
1344 connect(m_recentTabsMenu
->menu(), SIGNAL(triggered(QAction
*)),
1345 this, SLOT(restoreClosedTab(QAction
*)));
1347 QAction
* action
= new QAction("Empty Recently Closed Tabs", m_recentTabsMenu
);
1348 action
->setIcon(KIcon("edit-clear-list"));
1349 action
->setData(QVariant::fromValue(true));
1350 m_recentTabsMenu
->addAction(action
);
1351 m_recentTabsMenu
->addSeparator();
1352 m_recentTabsMenu
->setEnabled(false);
1354 KAction
* forwardAction
= KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1355 connect(forwardAction
, SIGNAL(triggered(Qt::MouseButtons
, Qt::KeyboardModifiers
)), this, SLOT(goForward(Qt::MouseButtons
)));
1357 KAction
* upAction
= KStandardAction::up(this, SLOT(goUp()), actionCollection());
1358 connect(upAction
, SIGNAL(triggered(Qt::MouseButtons
, Qt::KeyboardModifiers
)), this, SLOT(goUp(Qt::MouseButtons
)));
1360 KStandardAction::home(this, SLOT(goHome()), actionCollection());
1362 // setup 'Tools' menu
1363 KToggleAction
* showSearchBar
= actionCollection()->add
<KToggleAction
>("show_search_bar");
1364 showSearchBar
->setText(i18nc("@action:inmenu Tools", "Show Search Bar"));
1365 showSearchBar
->setShortcut(Qt::CTRL
| Qt::Key_S
);
1366 connect(showSearchBar
, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
1368 KToggleAction
* showFilterBar
= actionCollection()->add
<KToggleAction
>("show_filter_bar");
1369 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1370 showFilterBar
->setIcon(KIcon("view-filter"));
1371 showFilterBar
->setShortcut(Qt::CTRL
| Qt::Key_I
);
1372 connect(showFilterBar
, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
1374 KAction
* compareFiles
= actionCollection()->addAction("compare_files");
1375 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1376 compareFiles
->setIcon(KIcon("kompare"));
1377 compareFiles
->setEnabled(false);
1378 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
1380 KAction
* openTerminal
= actionCollection()->addAction("open_terminal");
1381 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1382 openTerminal
->setIcon(KIcon("utilities-terminal"));
1383 openTerminal
->setShortcut(Qt::SHIFT
| Qt::Key_F4
);
1384 connect(openTerminal
, SIGNAL(triggered()), this, SLOT(openTerminal()));
1386 // setup 'Settings' menu
1387 m_showMenuBar
= KStandardAction::showMenubar(this, SLOT(toggleShowMenuBar()), actionCollection());
1388 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1390 // not in menu actions
1391 KAction
* activateNextTab
= actionCollection()->addAction("activate_next_tab");
1392 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1393 connect(activateNextTab
, SIGNAL(triggered()), SLOT(activateNextTab()));
1394 activateNextTab
->setShortcuts(QApplication::isRightToLeft() ? KStandardShortcut::tabPrev() :
1395 KStandardShortcut::tabNext());
1397 KAction
* activatePrevTab
= actionCollection()->addAction("activate_prev_tab");
1398 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1399 connect(activatePrevTab
, SIGNAL(triggered()), SLOT(activatePrevTab()));
1400 activatePrevTab
->setShortcuts(QApplication::isRightToLeft() ? KStandardShortcut::tabNext() :
1401 KStandardShortcut::tabPrev());
1404 KAction
* openInNewTab
= actionCollection()->addAction("open_in_new_tab");
1405 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1406 openInNewTab
->setIcon(KIcon("tab-new"));
1407 connect(openInNewTab
, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1409 KAction
* openInNewWindow
= actionCollection()->addAction("open_in_new_window");
1410 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1411 openInNewWindow
->setIcon(KIcon("window-new"));
1412 connect(openInNewWindow
, SIGNAL(triggered()), this, SLOT(openInNewWindow()));
1415 m_searchBox
= new DolphinSearchBox(this);
1416 connect(m_searchBox
, SIGNAL(search(QString
)), this, SLOT(searchItems()));
1418 KAction
* search
= new KAction(this);
1419 actionCollection()->addAction("search_bar", search
);
1420 search
->setText(i18nc("@action:inmenu", "Search Bar"));
1421 search
->setDefaultWidget(m_searchBox
);
1422 search
->setShortcutConfigurable(false);
1425 void DolphinMainWindow::setupDockWidgets()
1427 // setup "Information"
1428 QDockWidget
* infoDock
= new QDockWidget(i18nc("@title:window", "Information"));
1429 infoDock
->setObjectName("infoDock");
1430 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1431 Panel
* infoPanel
= new InformationPanel(infoDock
);
1432 connect(infoPanel
, SIGNAL(urlActivated(KUrl
)), this, SLOT(handleUrl(KUrl
)));
1433 infoDock
->setWidget(infoPanel
);
1435 QAction
* infoAction
= infoDock
->toggleViewAction();
1436 infoAction
->setText(i18nc("@title:window", "Information"));
1437 infoAction
->setShortcut(Qt::Key_F11
);
1438 infoAction
->setIcon(KIcon("dialog-information"));
1439 actionCollection()->addAction("show_info_panel", infoDock
->toggleViewAction());
1441 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1442 connect(this, SIGNAL(urlChanged(KUrl
)),
1443 infoPanel
, SLOT(setUrl(KUrl
)));
1444 connect(this, SIGNAL(selectionChanged(KFileItemList
)),
1445 infoPanel
, SLOT(setSelection(KFileItemList
)));
1446 connect(this, SIGNAL(requestItemInfo(KFileItem
)),
1447 infoPanel
, SLOT(requestDelayedItemInfo(KFileItem
)));
1450 QDockWidget
* foldersDock
= new QDockWidget(i18nc("@title:window", "Folders"));
1451 foldersDock
->setObjectName("foldersDock");
1452 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1453 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1454 foldersDock
->setWidget(foldersPanel
);
1456 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1457 foldersAction
->setText(i18nc("@title:window", "Folders"));
1458 foldersAction
->setShortcut(Qt::Key_F7
);
1459 foldersAction
->setIcon(KIcon("folder"));
1460 actionCollection()->addAction("show_folders_panel", foldersDock
->toggleViewAction());
1462 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1463 connect(this, SIGNAL(urlChanged(KUrl
)),
1464 foldersPanel
, SLOT(setUrl(KUrl
)));
1465 connect(foldersPanel
, SIGNAL(changeUrl(KUrl
, Qt::MouseButtons
)),
1466 this, SLOT(handlePlacesClick(KUrl
, Qt::MouseButtons
)));
1470 QDockWidget
* terminalDock
= new QDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1471 terminalDock
->setObjectName("terminalDock");
1472 terminalDock
->setAllowedAreas(Qt::TopDockWidgetArea
| Qt::BottomDockWidgetArea
);
1473 Panel
* terminalPanel
= new TerminalPanel(terminalDock
);
1474 terminalDock
->setWidget(terminalPanel
);
1476 connect(terminalPanel
, SIGNAL(hideTerminalPanel()), terminalDock
, SLOT(hide()));
1478 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1479 terminalAction
->setText(i18nc("@title:window Shell terminal", "Terminal"));
1480 terminalAction
->setShortcut(Qt::Key_F4
);
1481 terminalAction
->setIcon(KIcon("utilities-terminal"));
1482 actionCollection()->addAction("show_terminal_panel", terminalDock
->toggleViewAction());
1484 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1485 connect(this, SIGNAL(urlChanged(KUrl
)),
1486 terminalPanel
, SLOT(setUrl(KUrl
)));
1489 const bool firstRun
= DolphinSettings::instance().generalSettings()->firstRun();
1491 foldersDock
->hide();
1493 terminalDock
->hide();
1497 QDockWidget
* placesDock
= new QDockWidget(i18nc("@title:window", "Places"));
1498 placesDock
->setObjectName("placesDock");
1499 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1501 PlacesPanel
* placesPanel
= new PlacesPanel(placesDock
);
1502 placesDock
->setWidget(placesPanel
);
1503 placesPanel
->setModel(DolphinSettings::instance().placesModel());
1504 placesPanel
->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff
);
1506 QAction
* placesAction
= placesDock
->toggleViewAction();
1507 placesAction
->setText(i18nc("@title:window", "Places"));
1508 placesAction
->setShortcut(Qt::Key_F9
);
1509 placesAction
->setIcon(KIcon("bookmarks"));
1510 actionCollection()->addAction("show_places_panel", placesDock
->toggleViewAction());
1512 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1513 connect(placesPanel
, SIGNAL(urlChanged(KUrl
, Qt::MouseButtons
)),
1514 this, SLOT(handlePlacesClick(KUrl
, Qt::MouseButtons
)));
1515 connect(this, SIGNAL(urlChanged(KUrl
)),
1516 placesPanel
, SLOT(setUrl(KUrl
)));
1519 void DolphinMainWindow::updateEditActions()
1521 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1522 if (list
.isEmpty()) {
1523 stateChanged("has_no_selection");
1525 stateChanged("has_selection");
1527 KActionCollection
* col
= actionCollection();
1528 QAction
* renameAction
= col
->action("rename");
1529 QAction
* moveToTrashAction
= col
->action("move_to_trash");
1530 QAction
* deleteAction
= col
->action("delete");
1531 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
1532 QAction
* deleteWithTrashShortcut
= col
->action("delete_shortcut"); // see DolphinViewActionHandler
1534 KFileItemListProperties
capabilities(list
);
1535 const bool enableMoveToTrash
= capabilities
.isLocal() && capabilities
.supportsMoving();
1537 renameAction
->setEnabled(capabilities
.supportsMoving());
1538 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1539 deleteAction
->setEnabled(capabilities
.supportsDeleting());
1540 deleteWithTrashShortcut
->setEnabled(capabilities
.supportsDeleting() && !enableMoveToTrash
);
1541 cutAction
->setEnabled(capabilities
.supportsMoving());
1543 updatePasteAction();
1546 void DolphinMainWindow::updateViewActions()
1548 m_actionHandler
->updateViewActions();
1550 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1551 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
1553 updateSplitAction();
1555 QAction
* editableLocactionAction
= actionCollection()->action("editable_location");
1556 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
1557 editableLocactionAction
->setChecked(urlNavigator
->isUrlEditable());
1560 void DolphinMainWindow::updateGoActions()
1562 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
1563 const KUrl
& currentUrl
= m_activeViewContainer
->url();
1564 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
1567 void DolphinMainWindow::rememberClosedTab(int index
)
1569 KMenu
* tabsMenu
= m_recentTabsMenu
->menu();
1571 const QString primaryPath
= m_viewTab
[index
].primaryView
->url().path();
1572 const QString iconName
= KMimeType::iconNameForUrl(primaryPath
);
1574 QAction
* action
= new QAction(squeezedText(primaryPath
), tabsMenu
);
1576 ClosedTab closedTab
;
1577 closedTab
.primaryUrl
= m_viewTab
[index
].primaryView
->url();
1579 if (m_viewTab
[index
].secondaryView
!= 0) {
1580 closedTab
.secondaryUrl
= m_viewTab
[index
].secondaryView
->url();
1581 closedTab
.isSplit
= true;
1583 closedTab
.isSplit
= false;
1586 action
->setData(QVariant::fromValue(closedTab
));
1587 action
->setIcon(KIcon(iconName
));
1589 // add the closed tab menu entry after the separator and
1590 // "Empty Recently Closed Tabs" entry
1591 if (tabsMenu
->actions().size() == 2) {
1592 tabsMenu
->addAction(action
);
1594 tabsMenu
->insertAction(tabsMenu
->actions().at(2), action
);
1597 // assure that only up to 8 closed tabs are shown in the menu
1598 if (tabsMenu
->actions().size() > 8) {
1599 tabsMenu
->removeAction(tabsMenu
->actions().last());
1601 actionCollection()->action("closed_tabs")->setEnabled(true);
1602 KAcceleratorManager::manage(tabsMenu
);
1605 void DolphinMainWindow::clearStatusBar()
1607 m_activeViewContainer
->statusBar()->clear();
1610 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
1612 connect(container
, SIGNAL(showFilterBarChanged(bool)),
1613 this, SLOT(updateFilterBarAction(bool)));
1615 DolphinView
* view
= container
->view();
1616 connect(view
, SIGNAL(selectionChanged(KFileItemList
)),
1617 this, SLOT(slotSelectionChanged(KFileItemList
)));
1618 connect(view
, SIGNAL(requestItemInfo(KFileItem
)),
1619 this, SLOT(slotRequestItemInfo(KFileItem
)));
1620 connect(view
, SIGNAL(activated()),
1621 this, SLOT(toggleActiveView()));
1622 connect(view
, SIGNAL(tabRequested(const KUrl
&)),
1623 this, SLOT(openNewTab(const KUrl
&)));
1625 const KUrlNavigator
* navigator
= container
->urlNavigator();
1626 connect(navigator
, SIGNAL(urlChanged(const KUrl
&)),
1627 this, SLOT(changeUrl(const KUrl
&)));
1628 connect(navigator
, SIGNAL(historyChanged()),
1629 this, SLOT(updateHistory()));
1630 connect(navigator
, SIGNAL(editableStateChanged(bool)),
1631 this, SLOT(slotEditableStateChanged(bool)));
1634 void DolphinMainWindow::updateSplitAction()
1636 QAction
* splitAction
= actionCollection()->action("split_view");
1637 if (m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
1638 if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
1639 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
1640 splitAction
->setToolTip(i18nc("@info", "Close right view"));
1641 splitAction
->setIcon(KIcon("view-right-close"));
1643 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
1644 splitAction
->setToolTip(i18nc("@info", "Close left view"));
1645 splitAction
->setIcon(KIcon("view-left-close"));
1648 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
1649 splitAction
->setToolTip(i18nc("@info", "Split view"));
1650 splitAction
->setIcon(KIcon("view-right-new"));
1654 QString
DolphinMainWindow::tabName(const KUrl
& url
) const
1657 if (url
.equals(KUrl("file:///"))) {
1660 name
= url
.fileName();
1661 if (name
.isEmpty()) {
1662 name
= url
.protocol();
1664 // Make sure that a '&' inside the directory name is displayed correctly
1665 // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
1666 name
.replace('&', "&&");
1672 bool DolphinMainWindow::isKompareInstalled() const
1674 static bool initialized
= false;
1675 static bool installed
= false;
1677 // TODO: maybe replace this approach later by using a menu
1678 // plugin like kdiff3plugin.cpp
1679 installed
= !KGlobal::dirs()->findExe("kompare").isEmpty();
1685 void DolphinMainWindow::createSecondaryView(int tabIndex
)
1687 QSplitter
* splitter
= m_viewTab
[tabIndex
].splitter
;
1688 const int newWidth
= (m_viewTab
[tabIndex
].primaryView
->width() - splitter
->handleWidth()) / 2;
1690 const DolphinView
* view
= m_viewTab
[tabIndex
].primaryView
->view();
1691 m_viewTab
[tabIndex
].secondaryView
= new DolphinViewContainer(this, 0, view
->rootUrl());
1692 splitter
->addWidget(m_viewTab
[tabIndex
].secondaryView
);
1693 splitter
->setSizes(QList
<int>() << newWidth
<< newWidth
);
1694 connectViewSignals(m_viewTab
[tabIndex
].secondaryView
);
1695 m_viewTab
[tabIndex
].secondaryView
->view()->reload();
1696 m_viewTab
[tabIndex
].secondaryView
->setActive(false);
1697 m_viewTab
[tabIndex
].secondaryView
->show();
1700 QString
DolphinMainWindow::tabProperty(const QString
& property
, int tabIndex
) const
1702 return "Tab " + QString::number(tabIndex
) + ' ' + property
;
1705 void DolphinMainWindow::setUrlAsCaption(const KUrl
& url
)
1708 if (url
.equals(KUrl("file:///"))) {
1711 caption
= url
.fileName();
1712 if (caption
.isEmpty()) {
1713 caption
= url
.protocol();
1717 setCaption(caption
);
1720 void DolphinMainWindow::handleUrl(const KUrl
& url
)
1722 if (KProtocolManager::supportsListing(url
)) {
1723 activeViewContainer()->setUrl(url
);
1726 new KRun(url
, this);
1730 QString
DolphinMainWindow::squeezedText(const QString
& text
) const
1732 const QFontMetrics fm
= fontMetrics();
1733 return fm
.elidedText(text
, Qt::ElideMiddle
, fm
.maxWidth() * 10);
1736 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
1737 KIO::FileUndoManager::UiInterface()
1741 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
1745 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
1747 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
1749 DolphinStatusBar
* statusBar
= mainWin
->activeViewContainer()->statusBar();
1750 statusBar
->setMessage(job
->errorString(), DolphinStatusBar::Error
);
1752 KIO::FileUndoManager::UiInterface::jobError(job
);
1756 #include "dolphinmainwindow.moc"