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 const KIcon icon
= KIcon(KMimeType::iconNameForUrl(m_activeViewContainer
->url()));
401 if (m_viewTab
.count() == 1) {
402 // Only one view is open currently and hence no tab is shown at
403 // all. Before creating a tab for 'url', provide a tab for the current URL.
404 m_tabBar
->addTab(icon
, squeezedText(tabName(m_activeViewContainer
->url())));
405 m_tabBar
->blockSignals(false);
408 m_tabBar
->addTab(icon
, squeezedText(tabName(url
)));
411 viewTab
.splitter
= new QSplitter(this);
412 viewTab
.splitter
->setChildrenCollapsible(false);
413 viewTab
.primaryView
= new DolphinViewContainer(this, viewTab
.splitter
, url
);
414 viewTab
.primaryView
->setActive(false);
415 connectViewSignals(viewTab
.primaryView
);
416 viewTab
.primaryView
->view()->reload();
418 m_viewTab
.append(viewTab
);
420 actionCollection()->action("close_tab")->setEnabled(true);
422 // provide a split view, if the startup settings are set this way
423 const GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
424 if (generalSettings
->splitView()) {
425 const int tabIndex
= m_viewTab
.count() - 1;
426 createSecondaryView(tabIndex
);
427 m_viewTab
[tabIndex
].secondaryView
->setActive(true);
428 m_viewTab
[tabIndex
].isPrimaryViewActive
= false;
432 void DolphinMainWindow::activateNextTab()
434 if ((m_viewTab
.count() == 1) || (m_tabBar
->count() < 2)) {
438 const int tabIndex
= (m_tabBar
->currentIndex() + 1) % m_tabBar
->count();
439 m_tabBar
->setCurrentIndex(tabIndex
);
442 void DolphinMainWindow::activatePrevTab()
444 if ((m_viewTab
.count() == 1) || (m_tabBar
->count() < 2)) {
448 int tabIndex
= m_tabBar
->currentIndex() - 1;
449 if (tabIndex
== -1) {
450 tabIndex
= m_tabBar
->count() - 1;
452 m_tabBar
->setCurrentIndex(tabIndex
);
455 void DolphinMainWindow::openInNewTab()
457 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
458 if ((list
.count() == 1) && list
[0].isDir()) {
459 openNewTab(m_activeViewContainer
->view()->selectedUrls()[0]);
463 void DolphinMainWindow::openInNewWindow()
465 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
466 if ((list
.count() == 1) && list
[0].isDir()) {
467 DolphinMainWindow
* window
= DolphinApplication::app()->createMainWindow();
468 window
->changeUrl(m_activeViewContainer
->view()->selectedUrls()[0]);
473 void DolphinMainWindow::toggleActiveView()
475 if (m_viewTab
[m_tabIndex
].secondaryView
== 0) {
476 // only one view is available
480 Q_ASSERT(m_activeViewContainer
!= 0);
481 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
483 DolphinViewContainer
* left
= m_viewTab
[m_tabIndex
].primaryView
;
484 DolphinViewContainer
* right
= m_viewTab
[m_tabIndex
].secondaryView
;
485 setActiveViewContainer(m_activeViewContainer
== right
? left
: right
);
488 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
490 DolphinSettings
& settings
= DolphinSettings::instance();
491 GeneralSettings
* generalSettings
= settings
.generalSettings();
493 // Find out if Dolphin is closed directly by the user or
494 // by the session manager because the session is closed
495 bool closedByUser
= true;
496 DolphinApplication
*application
= qobject_cast
<DolphinApplication
*>(qApp
);
497 if (application
&& application
->sessionSaving()) {
498 closedByUser
= false;
501 if ((m_viewTab
.count() > 1) && generalSettings
->confirmClosingMultipleTabs() && closedByUser
) {
502 // Ask the user if he really wants to quit and close all tabs.
503 // Open a confirmation dialog with 3 buttons:
504 // KDialog::Yes -> Quit
505 // KDialog::No -> Close only the current tab
506 // KDialog::Cancel -> do nothing
507 KDialog
*dialog
= new KDialog(this, Qt::Dialog
);
508 dialog
->setCaption(i18nc("@title:window", "Confirmation"));
509 dialog
->setButtons(KDialog::Yes
| KDialog::No
| KDialog::Cancel
);
510 dialog
->setModal(true);
511 dialog
->showButtonSeparator(true);
512 dialog
->setButtonGuiItem(KDialog::Yes
, KStandardGuiItem::quit());
513 dialog
->setButtonGuiItem(KDialog::No
, KGuiItem(i18n("C&lose Current Tab"), KIcon("tab-close")));
514 dialog
->setButtonGuiItem(KDialog::Cancel
, KStandardGuiItem::cancel());
515 dialog
->setDefaultButton(KDialog::Yes
);
517 bool doNotAskAgainCheckboxResult
= false;
519 const int result
= KMessageBox::createKMessageBox(dialog
,
520 QMessageBox::Warning
,
521 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
523 i18n("Do not ask again"),
524 &doNotAskAgainCheckboxResult
,
525 KMessageBox::Notify
);
527 if (doNotAskAgainCheckboxResult
) {
528 generalSettings
->setConfirmClosingMultipleTabs(false);
536 // Close only the current tab
544 generalSettings
->setFirstRun(false);
548 KXmlGuiWindow::closeEvent(event
);
551 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
553 const int tabCount
= m_viewTab
.count();
554 group
.writeEntry("Tab Count", tabCount
);
555 group
.writeEntry("Active Tab Index", m_tabBar
->currentIndex());
557 for (int i
= 0; i
< tabCount
; ++i
) {
558 const DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
559 group
.writeEntry(tabProperty("Primary URL", i
), cont
->url().url());
560 group
.writeEntry(tabProperty("Primary Editable", i
), cont
->isUrlEditable());
562 cont
= m_viewTab
[i
].secondaryView
;
564 group
.writeEntry(tabProperty("Secondary URL", i
), cont
->url().url());
565 group
.writeEntry(tabProperty("Secondary Editable", i
), cont
->isUrlEditable());
570 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
572 const int tabCount
= group
.readEntry("Tab Count", 1);
573 for (int i
= 0; i
< tabCount
; ++i
) {
574 DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
576 cont
->setUrl(group
.readEntry(tabProperty("Primary URL", i
)));
577 const bool editable
= group
.readEntry(tabProperty("Primary Editable", i
), false);
578 cont
->urlNavigator()->setUrlEditable(editable
);
580 cont
= m_viewTab
[i
].secondaryView
;
581 const QString secondaryUrl
= group
.readEntry(tabProperty("Secondary URL", i
));
582 if (!secondaryUrl
.isEmpty()) {
584 // a secondary view should be shown, but no one is available
585 // currently -> create a new view
587 cont
= m_viewTab
[i
].secondaryView
;
591 cont
->setUrl(secondaryUrl
);
592 const bool editable
= group
.readEntry(tabProperty("Secondary Editable", i
), false);
593 cont
->urlNavigator()->setUrlEditable(editable
);
594 } else if (cont
!= 0) {
595 // no secondary view should be shown, but the default setting shows
596 // one already -> close the view
600 // openNewTab() needs to be called only tabCount - 1 times
601 if (i
!= tabCount
- 1) {
606 const int index
= group
.readEntry("Active Tab Index", 0);
607 m_tabBar
->setCurrentIndex(index
);
610 void DolphinMainWindow::updateNewMenu()
612 m_newMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->showHiddenFiles());
613 m_newMenu
->slotCheckUpToDate();
614 m_newMenu
->setPopupFiles(activeViewContainer()->url());
617 void DolphinMainWindow::createDirectory()
619 m_newMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->showHiddenFiles());
620 m_newMenu
->setPopupFiles(activeViewContainer()->url());
621 m_newMenu
->createDirectory();
624 void DolphinMainWindow::quit()
629 void DolphinMainWindow::showErrorMessage(const QString
& message
)
631 if (!message
.isEmpty()) {
632 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
633 statusBar
->setMessage(message
, DolphinStatusBar::Error
);
637 void DolphinMainWindow::slotUndoAvailable(bool available
)
639 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
640 if (undoAction
!= 0) {
641 undoAction
->setEnabled(available
);
645 void DolphinMainWindow::restoreClosedTab(QAction
* action
)
647 if (action
->data().toBool()) {
648 // clear all actions except the "Empty Recently Closed Tabs"
649 // action and the separator
650 QList
<QAction
*> actions
= m_recentTabsMenu
->menu()->actions();
651 const int count
= actions
.size();
652 for (int i
= 2; i
< count
; ++i
) {
653 m_recentTabsMenu
->menu()->removeAction(actions
.at(i
));
656 const ClosedTab closedTab
= action
->data().value
<ClosedTab
>();
657 openNewTab(closedTab
.primaryUrl
);
658 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
660 if (closedTab
.isSplit
) {
661 // create secondary view
663 m_viewTab
[m_tabIndex
].secondaryView
->setUrl(closedTab
.secondaryUrl
);
666 m_recentTabsMenu
->removeAction(action
);
669 if (m_recentTabsMenu
->menu()->actions().count() == 2) {
670 m_recentTabsMenu
->setEnabled(false);
674 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
676 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
677 if (undoAction
!= 0) {
678 undoAction
->setText(text
);
682 void DolphinMainWindow::undo()
685 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
686 KIO::FileUndoManager::self()->undo();
689 void DolphinMainWindow::cut()
691 m_activeViewContainer
->view()->cutSelectedItems();
694 void DolphinMainWindow::copy()
696 m_activeViewContainer
->view()->copySelectedItems();
699 void DolphinMainWindow::paste()
701 m_activeViewContainer
->view()->paste();
704 void DolphinMainWindow::updatePasteAction()
706 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
707 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
708 pasteAction
->setEnabled(pasteInfo
.first
);
709 pasteAction
->setText(pasteInfo
.second
);
712 void DolphinMainWindow::selectAll()
716 // if the URL navigator is editable and focused, select the whole
717 // URL instead of all items of the view
719 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
720 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit(); // krazy:exclude=qclasses
721 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
722 lineEdit
->hasFocus();
724 lineEdit
->selectAll();
726 m_activeViewContainer
->view()->selectAll();
730 void DolphinMainWindow::invertSelection()
733 m_activeViewContainer
->view()->invertSelection();
736 void DolphinMainWindow::toggleSplitView()
738 if (m_viewTab
[m_tabIndex
].secondaryView
== 0) {
739 createSecondaryView(m_tabIndex
);
740 setActiveViewContainer(m_viewTab
[m_tabIndex
].secondaryView
);
741 } else if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
742 // remove secondary view
743 m_viewTab
[m_tabIndex
].secondaryView
->close();
744 m_viewTab
[m_tabIndex
].secondaryView
->deleteLater();
745 m_viewTab
[m_tabIndex
].secondaryView
= 0;
747 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
749 // The primary view is active and should be closed. Hence from a users point of view
750 // the content of the secondary view should be moved to the primary view.
751 // From an implementation point of view it is more efficient to close
752 // the primary view and exchange the internal pointers afterwards.
754 m_viewTab
[m_tabIndex
].primaryView
->close();
755 m_viewTab
[m_tabIndex
].primaryView
->deleteLater();
756 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
757 m_viewTab
[m_tabIndex
].secondaryView
= 0;
759 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
765 void DolphinMainWindow::reloadView()
768 m_activeViewContainer
->view()->reload();
771 void DolphinMainWindow::stopLoading()
775 void DolphinMainWindow::toggleFilterBarVisibility(bool show
)
777 m_activeViewContainer
->showFilterBar(show
);
780 void DolphinMainWindow::toggleEditLocation()
784 QAction
* action
= actionCollection()->action("editable_location");
785 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
786 urlNavigator
->setUrlEditable(action
->isChecked());
789 void DolphinMainWindow::replaceLocation()
791 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
792 navigator
->setUrlEditable(true);
793 navigator
->setFocus();
795 // select the whole text of the combo box editor
796 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit(); // krazy:exclude=qclasses
797 const QString text
= lineEdit
->text();
798 lineEdit
->setSelection(0, text
.length());
801 void DolphinMainWindow::goBack()
804 m_activeViewContainer
->urlNavigator()->goBack();
807 void DolphinMainWindow::goForward()
810 m_activeViewContainer
->urlNavigator()->goForward();
813 void DolphinMainWindow::goUp()
816 m_activeViewContainer
->urlNavigator()->goUp();
819 void DolphinMainWindow::goBack(Qt::MouseButtons buttons
)
821 // The default case (left button pressed) is handled in goBack().
822 if (buttons
== Qt::MidButton
) {
823 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
824 openNewTab(urlNavigator
->historyUrl(urlNavigator
->historyIndex() + 1));
828 void DolphinMainWindow::goForward(Qt::MouseButtons buttons
)
830 // The default case (left button pressed) is handled in goForward().
831 if (buttons
== Qt::MidButton
) {
832 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
833 openNewTab(urlNavigator
->historyUrl(urlNavigator
->historyIndex() - 1));
837 void DolphinMainWindow::goUp(Qt::MouseButtons buttons
)
839 // The default case (left button pressed) is handled in goUp().
840 if (buttons
== Qt::MidButton
) {
841 openNewTab(activeViewContainer()->url().upUrl());
845 void DolphinMainWindow::goHome()
848 m_activeViewContainer
->urlNavigator()->goHome();
851 void DolphinMainWindow::compareFiles()
853 // The method is only invoked if exactly 2 files have
854 // been selected. The selected files may be:
855 // - both in the primary view
856 // - both in the secondary view
857 // - one in the primary view and the other in the secondary
859 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
863 KUrl::List urls
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedUrls();
865 switch (urls
.count()) {
867 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
!= 0);
868 urls
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedUrls();
869 Q_ASSERT(urls
.count() == 2);
877 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
!= 0);
878 urls
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedUrls();
879 Q_ASSERT(urls
.count() == 1);
891 // may not happen: compareFiles may only get invoked if 2
892 // files are selected
897 QString
command("kompare -c \"");
898 command
.append(urlA
.pathOrUrl());
899 command
.append("\" \"");
900 command
.append(urlB
.pathOrUrl());
901 command
.append('\"');
902 KRun::runCommand(command
, "Kompare", "kompare", this);
905 void DolphinMainWindow::toggleShowMenuBar()
907 const bool visible
= menuBar()->isVisible();
908 menuBar()->setVisible(!visible
);
911 void DolphinMainWindow::openTerminal()
913 QString
dir(QDir::homePath());
915 // If the given directory is not local, it can still be the URL of an
916 // ioslave using UDS_LOCAL_PATH which to be converted first.
917 KUrl url
= KIO::NetAccess::mostLocalUrl(m_activeViewContainer
->url(), this);
919 //If the URL is local after the above conversion, set the directory.
920 if (url
.isLocalFile()) {
921 dir
= url
.toLocalFile();
924 KToolInvocation::invokeTerminal(QString(), dir
);
927 void DolphinMainWindow::editSettings()
929 if (m_settingsDialog
== 0) {
930 const KUrl
& url
= activeViewContainer()->url();
931 m_settingsDialog
= new DolphinSettingsDialog(url
, this);
932 m_settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
933 m_settingsDialog
->show();
935 m_settingsDialog
->raise();
939 void DolphinMainWindow::setActiveTab(int index
)
941 Q_ASSERT(index
>= 0);
942 Q_ASSERT(index
< m_viewTab
.count());
943 if (index
== m_tabIndex
) {
947 // hide current tab content
948 ViewTab
& hiddenTab
= m_viewTab
[m_tabIndex
];
949 hiddenTab
.isPrimaryViewActive
= hiddenTab
.primaryView
->isActive();
950 hiddenTab
.primaryView
->setActive(false);
951 if (hiddenTab
.secondaryView
!= 0) {
952 hiddenTab
.secondaryView
->setActive(false);
954 QSplitter
* splitter
= m_viewTab
[m_tabIndex
].splitter
;
956 m_centralWidgetLayout
->removeWidget(splitter
);
958 // show active tab content
961 ViewTab
& viewTab
= m_viewTab
[index
];
962 m_centralWidgetLayout
->addWidget(viewTab
.splitter
, 1);
963 viewTab
.primaryView
->show();
964 if (viewTab
.secondaryView
!= 0) {
965 viewTab
.secondaryView
->show();
967 viewTab
.splitter
->show();
969 setActiveViewContainer(viewTab
.isPrimaryViewActive
? viewTab
.primaryView
:
970 viewTab
.secondaryView
);
973 void DolphinMainWindow::closeTab()
975 closeTab(m_tabBar
->currentIndex());
978 void DolphinMainWindow::closeTab(int index
)
980 Q_ASSERT(index
>= 0);
981 Q_ASSERT(index
< m_viewTab
.count());
982 if (m_viewTab
.count() == 1) {
983 // the last tab may never get closed
987 if (index
== m_tabIndex
) {
988 // The tab that should be closed is the active tab. Activate the
989 // previous tab before closing the tab.
990 m_tabBar
->setCurrentIndex((index
> 0) ? index
- 1 : 1);
992 rememberClosedTab(index
);
995 m_viewTab
[index
].primaryView
->deleteLater();
996 if (m_viewTab
[index
].secondaryView
!= 0) {
997 m_viewTab
[index
].secondaryView
->deleteLater();
999 m_viewTab
[index
].splitter
->deleteLater();
1000 m_viewTab
.erase(m_viewTab
.begin() + index
);
1002 m_tabBar
->blockSignals(true);
1003 m_tabBar
->removeTab(index
);
1005 if (m_tabIndex
> index
) {
1007 Q_ASSERT(m_tabIndex
>= 0);
1010 // if only one tab is left, also remove the tab entry so that
1011 // closing the last tab is not possible
1012 if (m_viewTab
.count() == 1) {
1013 m_tabBar
->removeTab(0);
1014 actionCollection()->action("close_tab")->setEnabled(false);
1016 m_tabBar
->blockSignals(false);
1020 void DolphinMainWindow::openTabContextMenu(int index
, const QPoint
& pos
)
1024 QAction
* newTabAction
= menu
.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab"));
1025 newTabAction
->setShortcut(actionCollection()->action("new_tab")->shortcut());
1027 QAction
* closeOtherTabsAction
= menu
.addAction(KIcon("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs"));
1029 QAction
* closeTabAction
= menu
.addAction(KIcon("tab-close"), i18nc("@action:inmenu", "Close Tab"));
1030 closeTabAction
->setShortcut(actionCollection()->action("close_tab")->shortcut());
1031 QAction
* selectedAction
= menu
.exec(pos
);
1032 if (selectedAction
== newTabAction
) {
1033 const ViewTab
& tab
= m_viewTab
[index
];
1034 Q_ASSERT(tab
.primaryView
!= 0);
1035 const KUrl url
= (tab
.secondaryView
!= 0) && tab
.secondaryView
->isActive() ?
1036 tab
.secondaryView
->url() : tab
.primaryView
->url();
1038 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
1039 } else if (selectedAction
== closeOtherTabsAction
) {
1040 const int count
= m_tabBar
->count();
1041 for (int i
= 0; i
< index
; ++i
) {
1044 for (int i
= index
+ 1; i
< count
; ++i
) {
1047 } else if (selectedAction
== closeTabAction
) {
1052 void DolphinMainWindow::handlePlacesClick(const KUrl
& url
, Qt::MouseButtons buttons
)
1054 if (buttons
& Qt::MidButton
) {
1056 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
1062 void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent
* event
, bool& canDecode
)
1064 canDecode
= KUrl::List::canDecode(event
->mimeData());
1067 void DolphinMainWindow::searchItems()
1070 const KUrl nepomukSearchUrl
= m_searchOptionsConfigurator
->nepomukSearchUrl();
1071 m_activeViewContainer
->setUrl(nepomukSearchUrl
);
1075 void DolphinMainWindow::slotTabMoved(int from
, int to
)
1077 m_viewTab
.move(from
, to
);
1078 m_tabIndex
= m_tabBar
->currentIndex();
1081 void DolphinMainWindow::showSearchOptions()
1084 m_searchOptionsConfigurator
->show();
1088 void DolphinMainWindow::init()
1090 DolphinSettings
& settings
= DolphinSettings::instance();
1092 // Check whether Dolphin runs the first time. If yes then
1093 // a proper default window size is given at the end of DolphinMainWindow::init().
1094 GeneralSettings
* generalSettings
= settings
.generalSettings();
1095 const bool firstRun
= generalSettings
->firstRun();
1097 generalSettings
->setViewPropsTimestamp(QDateTime::currentDateTime());
1100 setAcceptDrops(true);
1102 m_viewTab
[m_tabIndex
].splitter
= new QSplitter(this);
1103 m_viewTab
[m_tabIndex
].splitter
->setChildrenCollapsible(false);
1107 const KUrl
& homeUrl
= generalSettings
->homeUrl();
1108 setUrlAsCaption(homeUrl
);
1109 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
1110 connect(m_actionHandler
, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
1111 connect(m_actionHandler
, SIGNAL(createDirectory()), SLOT(createDirectory()));
1112 ViewProperties
props(homeUrl
);
1113 m_viewTab
[m_tabIndex
].primaryView
= new DolphinViewContainer(this,
1114 m_viewTab
[m_tabIndex
].splitter
,
1117 m_activeViewContainer
= m_viewTab
[m_tabIndex
].primaryView
;
1118 connectViewSignals(m_activeViewContainer
);
1119 DolphinView
* view
= m_activeViewContainer
->view();
1121 m_activeViewContainer
->show();
1122 m_actionHandler
->setCurrentView(view
);
1124 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
1125 connect(this, SIGNAL(urlChanged(const KUrl
&)),
1126 m_remoteEncoding
, SLOT(slotAboutToOpenUrl()));
1129 m_searchOptionsConfigurator
= new DolphinSearchOptionsConfigurator(this);
1130 m_searchOptionsConfigurator
->hide();
1131 connect(m_searchOptionsConfigurator
, SIGNAL(searchOptionsChanged()),
1132 this, SLOT(searchItems()));
1133 connect(this, SIGNAL(urlChanged(KUrl
)), m_searchOptionsConfigurator
, SLOT(setDirectory(KUrl
)));
1136 m_tabBar
= new KTabBar(this);
1137 m_tabBar
->setMovable(true);
1138 m_tabBar
->setTabsClosable(true);
1139 connect(m_tabBar
, SIGNAL(currentChanged(int)),
1140 this, SLOT(setActiveTab(int)));
1141 connect(m_tabBar
, SIGNAL(tabCloseRequested(int)),
1142 this, SLOT(closeTab(int)));
1143 connect(m_tabBar
, SIGNAL(contextMenu(int, const QPoint
&)),
1144 this, SLOT(openTabContextMenu(int, const QPoint
&)));
1145 connect(m_tabBar
, SIGNAL(newTabRequest()),
1146 this, SLOT(openNewTab()));
1147 connect(m_tabBar
, SIGNAL(testCanDecode(const QDragMoveEvent
*, bool&)),
1148 this, SLOT(slotTestCanDecode(const QDragMoveEvent
*, bool&)));
1149 connect(m_tabBar
, SIGNAL(wheelDelta(int)),
1150 this, SLOT(slotWheelMoved(int)));
1151 connect(m_tabBar
, SIGNAL(mouseMiddleClick(int)),
1152 this, SLOT(closeTab(int)));
1153 connect(m_tabBar
, SIGNAL(tabMoved(int, int)),
1154 this, SLOT(slotTabMoved(int, int)));
1156 m_tabBar
->blockSignals(true); // signals get unblocked after at least 2 tabs are open
1158 QWidget
* centralWidget
= new QWidget(this);
1159 m_centralWidgetLayout
= new QVBoxLayout(centralWidget
);
1160 m_centralWidgetLayout
->setSpacing(0);
1161 m_centralWidgetLayout
->setMargin(0);
1163 m_centralWidgetLayout
->addWidget(m_searchOptionsConfigurator
);
1165 m_centralWidgetLayout
->addWidget(m_tabBar
);
1166 m_centralWidgetLayout
->addWidget(m_viewTab
[m_tabIndex
].splitter
, 1);
1168 setCentralWidget(centralWidget
);
1170 emit
urlChanged(homeUrl
);
1172 setupGUI(Keys
| Save
| Create
| ToolBar
);
1174 m_searchBox
->setParent(toolBar("searchToolBar"));
1175 m_searchBox
->show();
1176 connect(m_searchBox
, SIGNAL(requestSearchOptions()),
1177 this, SLOT(showSearchOptions()));
1179 connect(m_searchBox
, SIGNAL(searchTextChanged(QString
)),
1180 m_searchOptionsConfigurator
, SLOT(setCustomSearchQuery(QString
)));
1183 stateChanged("new_file");
1185 QClipboard
* clipboard
= QApplication::clipboard();
1186 connect(clipboard
, SIGNAL(dataChanged()),
1187 this, SLOT(updatePasteAction()));
1188 updatePasteAction();
1191 if (generalSettings
->splitView()) {
1194 updateViewActions();
1196 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1197 showFilterBarAction
->setChecked(generalSettings
->filterBar());
1200 // assure a proper default size if Dolphin runs the first time
1204 m_showMenuBar
->setChecked(!menuBar()->isHidden()); // workaround for bug #171080
1207 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer
* viewContainer
)
1209 Q_ASSERT(viewContainer
!= 0);
1210 Q_ASSERT((viewContainer
== m_viewTab
[m_tabIndex
].primaryView
) ||
1211 (viewContainer
== m_viewTab
[m_tabIndex
].secondaryView
));
1212 if (m_activeViewContainer
== viewContainer
) {
1216 m_activeViewContainer
->setActive(false);
1217 m_activeViewContainer
= viewContainer
;
1219 // Activating the view container might trigger a recursive setActiveViewContainer() call
1220 // inside DolphinMainWindow::toggleActiveView() when having a split view. Temporary
1221 // disconnect the activated() signal in this case:
1222 disconnect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1223 m_activeViewContainer
->setActive(true);
1224 connect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1226 m_actionHandler
->setCurrentView(viewContainer
->view());
1229 updateEditActions();
1230 updateViewActions();
1233 const KUrl
& url
= m_activeViewContainer
->url();
1234 setUrlAsCaption(url
);
1235 if (m_viewTab
.count() > 1 && m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
1236 m_tabBar
->setTabText(m_tabIndex
, tabName(url
));
1237 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(KMimeType::iconNameForUrl(url
)));
1240 emit
urlChanged(url
);
1243 void DolphinMainWindow::setupActions()
1245 // setup 'File' menu
1246 m_newMenu
= new DolphinNewMenu(this, this);
1247 KMenu
* menu
= m_newMenu
->menu();
1248 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1249 menu
->setIcon(KIcon("document-new"));
1250 connect(menu
, SIGNAL(aboutToShow()),
1251 this, SLOT(updateNewMenu()));
1253 KAction
* newWindow
= actionCollection()->addAction("new_window");
1254 newWindow
->setIcon(KIcon("window-new"));
1255 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1256 newWindow
->setShortcut(Qt::CTRL
| Qt::Key_N
);
1257 connect(newWindow
, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1259 KAction
* newTab
= actionCollection()->addAction("new_tab");
1260 newTab
->setIcon(KIcon("tab-new"));
1261 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1262 newTab
->setShortcut(KShortcut(Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
));
1263 connect(newTab
, SIGNAL(triggered()), this, SLOT(openNewTab()));
1265 KAction
* closeTab
= actionCollection()->addAction("close_tab");
1266 closeTab
->setIcon(KIcon("tab-close"));
1267 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1268 closeTab
->setShortcut(Qt::CTRL
| Qt::Key_W
);
1269 closeTab
->setEnabled(false);
1270 connect(closeTab
, SIGNAL(triggered()), this, SLOT(closeTab()));
1272 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1274 // setup 'Edit' menu
1275 KStandardAction::undo(this,
1277 actionCollection());
1279 // need to remove shift+del from cut action, else the shortcut for deletejob
1281 KAction
* cut
= KStandardAction::cut(this, SLOT(cut()), actionCollection());
1282 KShortcut cutShortcut
= cut
->shortcut();
1283 cutShortcut
.remove(Qt::SHIFT
+ Qt::Key_Delete
, KShortcut::KeepEmpty
);
1284 cut
->setShortcut(cutShortcut
);
1285 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1286 KAction
* paste
= KStandardAction::paste(this, SLOT(paste()), actionCollection());
1287 // The text of the paste-action is modified dynamically by Dolphin
1288 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1289 // due to the long text, the text "Paste" is used:
1290 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1292 KAction
* selectAll
= actionCollection()->addAction("select_all");
1293 selectAll
->setText(i18nc("@action:inmenu Edit", "Select All"));
1294 selectAll
->setShortcut(Qt::CTRL
+ Qt::Key_A
);
1295 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
1297 KAction
* invertSelection
= actionCollection()->addAction("invert_selection");
1298 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1299 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1300 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
1302 // setup 'View' menu
1303 // (note that most of it is set up in DolphinViewActionHandler)
1305 KAction
* split
= actionCollection()->addAction("split_view");
1306 split
->setShortcut(Qt::Key_F3
);
1307 updateSplitAction();
1308 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1310 KAction
* reload
= actionCollection()->addAction("reload");
1311 reload
->setText(i18nc("@action:inmenu View", "Reload"));
1312 reload
->setShortcut(Qt::Key_F5
);
1313 reload
->setIcon(KIcon("view-refresh"));
1314 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
1316 KAction
* stop
= actionCollection()->addAction("stop");
1317 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1318 stop
->setToolTip(i18nc("@info", "Stop loading"));
1319 stop
->setIcon(KIcon("process-stop"));
1320 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
1322 KToggleAction
* showFullLocation
= actionCollection()->add
<KToggleAction
>("editable_location");
1323 showFullLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1324 showFullLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
1325 connect(showFullLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1327 KAction
* replaceLocation
= actionCollection()->addAction("replace_location");
1328 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1329 replaceLocation
->setShortcut(Qt::Key_F6
);
1330 connect(replaceLocation
, SIGNAL(triggered()), this, SLOT(replaceLocation()));
1333 KAction
* backAction
= KStandardAction::back(this, SLOT(goBack()), actionCollection());
1334 connect(backAction
, SIGNAL(triggered(Qt::MouseButtons
, Qt::KeyboardModifiers
)), this, SLOT(goBack(Qt::MouseButtons
)));
1335 KShortcut backShortcut
= backAction
->shortcut();
1336 backShortcut
.setAlternate(Qt::Key_Backspace
);
1337 backAction
->setShortcut(backShortcut
);
1339 m_recentTabsMenu
= new KActionMenu(i18n("Recently Closed Tabs"), this);
1340 m_recentTabsMenu
->setIcon(KIcon("edit-undo"));
1341 actionCollection()->addAction("closed_tabs", m_recentTabsMenu
);
1342 connect(m_recentTabsMenu
->menu(), SIGNAL(triggered(QAction
*)),
1343 this, SLOT(restoreClosedTab(QAction
*)));
1345 QAction
* action
= new QAction("Empty Recently Closed Tabs", m_recentTabsMenu
);
1346 action
->setIcon(KIcon("edit-clear-list"));
1347 action
->setData(QVariant::fromValue(true));
1348 m_recentTabsMenu
->addAction(action
);
1349 m_recentTabsMenu
->addSeparator();
1350 m_recentTabsMenu
->setEnabled(false);
1352 KAction
* forwardAction
= KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1353 connect(forwardAction
, SIGNAL(triggered(Qt::MouseButtons
, Qt::KeyboardModifiers
)), this, SLOT(goForward(Qt::MouseButtons
)));
1355 KAction
* upAction
= KStandardAction::up(this, SLOT(goUp()), actionCollection());
1356 connect(upAction
, SIGNAL(triggered(Qt::MouseButtons
, Qt::KeyboardModifiers
)), this, SLOT(goUp(Qt::MouseButtons
)));
1358 KStandardAction::home(this, SLOT(goHome()), actionCollection());
1360 // setup 'Tools' menu
1361 KToggleAction
* showSearchBar
= actionCollection()->add
<KToggleAction
>("show_search_bar");
1362 showSearchBar
->setText(i18nc("@action:inmenu Tools", "Show Search Bar"));
1363 showSearchBar
->setShortcut(Qt::CTRL
| Qt::Key_S
);
1364 connect(showSearchBar
, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
1366 KToggleAction
* showFilterBar
= actionCollection()->add
<KToggleAction
>("show_filter_bar");
1367 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1368 showFilterBar
->setIcon(KIcon("view-filter"));
1369 showFilterBar
->setShortcut(Qt::CTRL
| Qt::Key_I
);
1370 connect(showFilterBar
, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
1372 KAction
* compareFiles
= actionCollection()->addAction("compare_files");
1373 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1374 compareFiles
->setIcon(KIcon("kompare"));
1375 compareFiles
->setEnabled(false);
1376 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
1378 KAction
* openTerminal
= actionCollection()->addAction("open_terminal");
1379 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1380 openTerminal
->setIcon(KIcon("utilities-terminal"));
1381 openTerminal
->setShortcut(Qt::SHIFT
| Qt::Key_F4
);
1382 connect(openTerminal
, SIGNAL(triggered()), this, SLOT(openTerminal()));
1384 // setup 'Settings' menu
1385 m_showMenuBar
= KStandardAction::showMenubar(this, SLOT(toggleShowMenuBar()), actionCollection());
1386 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1388 // not in menu actions
1389 KAction
* activateNextTab
= actionCollection()->addAction("activate_next_tab");
1390 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1391 connect(activateNextTab
, SIGNAL(triggered()), SLOT(activateNextTab()));
1392 activateNextTab
->setShortcuts(QApplication::isRightToLeft() ? KStandardShortcut::tabPrev() :
1393 KStandardShortcut::tabNext());
1395 KAction
* activatePrevTab
= actionCollection()->addAction("activate_prev_tab");
1396 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1397 connect(activatePrevTab
, SIGNAL(triggered()), SLOT(activatePrevTab()));
1398 activatePrevTab
->setShortcuts(QApplication::isRightToLeft() ? KStandardShortcut::tabNext() :
1399 KStandardShortcut::tabPrev());
1402 KAction
* openInNewTab
= actionCollection()->addAction("open_in_new_tab");
1403 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1404 openInNewTab
->setIcon(KIcon("tab-new"));
1405 connect(openInNewTab
, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1407 KAction
* openInNewWindow
= actionCollection()->addAction("open_in_new_window");
1408 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1409 openInNewWindow
->setIcon(KIcon("window-new"));
1410 connect(openInNewWindow
, SIGNAL(triggered()), this, SLOT(openInNewWindow()));
1413 m_searchBox
= new DolphinSearchBox(this);
1414 connect(m_searchBox
, SIGNAL(search(QString
)), this, SLOT(searchItems()));
1416 KAction
* search
= new KAction(this);
1417 actionCollection()->addAction("search_bar", search
);
1418 search
->setText(i18nc("@action:inmenu", "Search Bar"));
1419 search
->setDefaultWidget(m_searchBox
);
1420 search
->setShortcutConfigurable(false);
1423 void DolphinMainWindow::setupDockWidgets()
1425 // setup "Information"
1426 QDockWidget
* infoDock
= new QDockWidget(i18nc("@title:window", "Information"));
1427 infoDock
->setObjectName("infoDock");
1428 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1429 Panel
* infoPanel
= new InformationPanel(infoDock
);
1430 connect(infoPanel
, SIGNAL(urlActivated(KUrl
)), this, SLOT(handleUrl(KUrl
)));
1431 infoDock
->setWidget(infoPanel
);
1433 QAction
* infoAction
= infoDock
->toggleViewAction();
1434 infoAction
->setText(i18nc("@title:window", "Information"));
1435 infoAction
->setShortcut(Qt::Key_F11
);
1436 infoAction
->setIcon(KIcon("dialog-information"));
1437 actionCollection()->addAction("show_info_panel", infoDock
->toggleViewAction());
1439 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1440 connect(this, SIGNAL(urlChanged(KUrl
)),
1441 infoPanel
, SLOT(setUrl(KUrl
)));
1442 connect(this, SIGNAL(selectionChanged(KFileItemList
)),
1443 infoPanel
, SLOT(setSelection(KFileItemList
)));
1444 connect(this, SIGNAL(requestItemInfo(KFileItem
)),
1445 infoPanel
, SLOT(requestDelayedItemInfo(KFileItem
)));
1448 QDockWidget
* foldersDock
= new QDockWidget(i18nc("@title:window", "Folders"));
1449 foldersDock
->setObjectName("foldersDock");
1450 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1451 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1452 foldersDock
->setWidget(foldersPanel
);
1454 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1455 foldersAction
->setText(i18nc("@title:window", "Folders"));
1456 foldersAction
->setShortcut(Qt::Key_F7
);
1457 foldersAction
->setIcon(KIcon("folder"));
1458 actionCollection()->addAction("show_folders_panel", foldersDock
->toggleViewAction());
1460 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1461 connect(this, SIGNAL(urlChanged(KUrl
)),
1462 foldersPanel
, SLOT(setUrl(KUrl
)));
1463 connect(foldersPanel
, SIGNAL(changeUrl(KUrl
, Qt::MouseButtons
)),
1464 this, SLOT(handlePlacesClick(KUrl
, Qt::MouseButtons
)));
1468 QDockWidget
* terminalDock
= new QDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1469 terminalDock
->setObjectName("terminalDock");
1470 terminalDock
->setAllowedAreas(Qt::TopDockWidgetArea
| Qt::BottomDockWidgetArea
);
1471 Panel
* terminalPanel
= new TerminalPanel(terminalDock
);
1472 terminalDock
->setWidget(terminalPanel
);
1474 connect(terminalPanel
, SIGNAL(hideTerminalPanel()), terminalDock
, SLOT(hide()));
1476 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1477 terminalAction
->setText(i18nc("@title:window Shell terminal", "Terminal"));
1478 terminalAction
->setShortcut(Qt::Key_F4
);
1479 terminalAction
->setIcon(KIcon("utilities-terminal"));
1480 actionCollection()->addAction("show_terminal_panel", terminalDock
->toggleViewAction());
1482 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1483 connect(this, SIGNAL(urlChanged(KUrl
)),
1484 terminalPanel
, SLOT(setUrl(KUrl
)));
1487 const bool firstRun
= DolphinSettings::instance().generalSettings()->firstRun();
1489 foldersDock
->hide();
1491 terminalDock
->hide();
1495 QDockWidget
* placesDock
= new QDockWidget(i18nc("@title:window", "Places"));
1496 placesDock
->setObjectName("placesDock");
1497 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1499 PlacesPanel
* placesPanel
= new PlacesPanel(placesDock
);
1500 placesDock
->setWidget(placesPanel
);
1501 placesPanel
->setModel(DolphinSettings::instance().placesModel());
1502 placesPanel
->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff
);
1504 QAction
* placesAction
= placesDock
->toggleViewAction();
1505 placesAction
->setText(i18nc("@title:window", "Places"));
1506 placesAction
->setShortcut(Qt::Key_F9
);
1507 placesAction
->setIcon(KIcon("bookmarks"));
1508 actionCollection()->addAction("show_places_panel", placesDock
->toggleViewAction());
1510 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1511 connect(placesPanel
, SIGNAL(urlChanged(KUrl
, Qt::MouseButtons
)),
1512 this, SLOT(handlePlacesClick(KUrl
, Qt::MouseButtons
)));
1513 connect(this, SIGNAL(urlChanged(KUrl
)),
1514 placesPanel
, SLOT(setUrl(KUrl
)));
1517 void DolphinMainWindow::updateEditActions()
1519 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1520 if (list
.isEmpty()) {
1521 stateChanged("has_no_selection");
1523 stateChanged("has_selection");
1525 KActionCollection
* col
= actionCollection();
1526 QAction
* renameAction
= col
->action("rename");
1527 QAction
* moveToTrashAction
= col
->action("move_to_trash");
1528 QAction
* deleteAction
= col
->action("delete");
1529 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
1530 QAction
* deleteWithTrashShortcut
= col
->action("delete_shortcut"); // see DolphinViewActionHandler
1532 KFileItemListProperties
capabilities(list
);
1533 const bool enableMoveToTrash
= capabilities
.isLocal() && capabilities
.supportsMoving();
1535 renameAction
->setEnabled(capabilities
.supportsMoving());
1536 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1537 deleteAction
->setEnabled(capabilities
.supportsDeleting());
1538 deleteWithTrashShortcut
->setEnabled(capabilities
.supportsDeleting() && !enableMoveToTrash
);
1539 cutAction
->setEnabled(capabilities
.supportsMoving());
1541 updatePasteAction();
1544 void DolphinMainWindow::updateViewActions()
1546 m_actionHandler
->updateViewActions();
1548 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1549 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
1551 updateSplitAction();
1553 QAction
* editableLocactionAction
= actionCollection()->action("editable_location");
1554 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
1555 editableLocactionAction
->setChecked(urlNavigator
->isUrlEditable());
1558 void DolphinMainWindow::updateGoActions()
1560 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
1561 const KUrl
& currentUrl
= m_activeViewContainer
->url();
1562 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
1565 void DolphinMainWindow::rememberClosedTab(int index
)
1567 KMenu
* tabsMenu
= m_recentTabsMenu
->menu();
1569 const QString primaryPath
= m_viewTab
[index
].primaryView
->url().path();
1570 const QString iconName
= KMimeType::iconNameForUrl(primaryPath
);
1572 QAction
* action
= new QAction(squeezedText(primaryPath
), tabsMenu
);
1574 ClosedTab closedTab
;
1575 closedTab
.primaryUrl
= m_viewTab
[index
].primaryView
->url();
1577 if (m_viewTab
[index
].secondaryView
!= 0) {
1578 closedTab
.secondaryUrl
= m_viewTab
[index
].secondaryView
->url();
1579 closedTab
.isSplit
= true;
1581 closedTab
.isSplit
= false;
1584 action
->setData(QVariant::fromValue(closedTab
));
1585 action
->setIcon(KIcon(iconName
));
1587 // add the closed tab menu entry after the separator and
1588 // "Empty Recently Closed Tabs" entry
1589 if (tabsMenu
->actions().size() == 2) {
1590 tabsMenu
->addAction(action
);
1592 tabsMenu
->insertAction(tabsMenu
->actions().at(2), action
);
1595 // assure that only up to 8 closed tabs are shown in the menu
1596 if (tabsMenu
->actions().size() > 8) {
1597 tabsMenu
->removeAction(tabsMenu
->actions().last());
1599 actionCollection()->action("closed_tabs")->setEnabled(true);
1600 KAcceleratorManager::manage(tabsMenu
);
1603 void DolphinMainWindow::clearStatusBar()
1605 m_activeViewContainer
->statusBar()->clear();
1608 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
1610 connect(container
, SIGNAL(showFilterBarChanged(bool)),
1611 this, SLOT(updateFilterBarAction(bool)));
1613 DolphinView
* view
= container
->view();
1614 connect(view
, SIGNAL(selectionChanged(KFileItemList
)),
1615 this, SLOT(slotSelectionChanged(KFileItemList
)));
1616 connect(view
, SIGNAL(requestItemInfo(KFileItem
)),
1617 this, SLOT(slotRequestItemInfo(KFileItem
)));
1618 connect(view
, SIGNAL(activated()),
1619 this, SLOT(toggleActiveView()));
1620 connect(view
, SIGNAL(tabRequested(const KUrl
&)),
1621 this, SLOT(openNewTab(const KUrl
&)));
1623 const KUrlNavigator
* navigator
= container
->urlNavigator();
1624 connect(navigator
, SIGNAL(urlChanged(const KUrl
&)),
1625 this, SLOT(changeUrl(const KUrl
&)));
1626 connect(navigator
, SIGNAL(historyChanged()),
1627 this, SLOT(updateHistory()));
1628 connect(navigator
, SIGNAL(editableStateChanged(bool)),
1629 this, SLOT(slotEditableStateChanged(bool)));
1632 void DolphinMainWindow::updateSplitAction()
1634 QAction
* splitAction
= actionCollection()->action("split_view");
1635 if (m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
1636 if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
1637 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
1638 splitAction
->setToolTip(i18nc("@info", "Close right view"));
1639 splitAction
->setIcon(KIcon("view-right-close"));
1641 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
1642 splitAction
->setToolTip(i18nc("@info", "Close left view"));
1643 splitAction
->setIcon(KIcon("view-left-close"));
1646 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
1647 splitAction
->setToolTip(i18nc("@info", "Split view"));
1648 splitAction
->setIcon(KIcon("view-right-new"));
1652 QString
DolphinMainWindow::tabName(const KUrl
& url
) const
1655 if (url
.equals(KUrl("file:///"))) {
1658 name
= url
.fileName();
1659 if (name
.isEmpty()) {
1660 name
= url
.protocol();
1662 // Make sure that a '&' inside the directory name is displayed correctly
1663 // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
1664 name
.replace('&', "&&");
1670 bool DolphinMainWindow::isKompareInstalled() const
1672 static bool initialized
= false;
1673 static bool installed
= false;
1675 // TODO: maybe replace this approach later by using a menu
1676 // plugin like kdiff3plugin.cpp
1677 installed
= !KGlobal::dirs()->findExe("kompare").isEmpty();
1683 void DolphinMainWindow::createSecondaryView(int tabIndex
)
1685 QSplitter
* splitter
= m_viewTab
[tabIndex
].splitter
;
1686 const int newWidth
= (m_viewTab
[tabIndex
].primaryView
->width() - splitter
->handleWidth()) / 2;
1688 const DolphinView
* view
= m_viewTab
[tabIndex
].primaryView
->view();
1689 m_viewTab
[tabIndex
].secondaryView
= new DolphinViewContainer(this, 0, view
->rootUrl());
1690 splitter
->addWidget(m_viewTab
[tabIndex
].secondaryView
);
1691 splitter
->setSizes(QList
<int>() << newWidth
<< newWidth
);
1692 connectViewSignals(m_viewTab
[tabIndex
].secondaryView
);
1693 m_viewTab
[tabIndex
].secondaryView
->view()->reload();
1694 m_viewTab
[tabIndex
].secondaryView
->setActive(false);
1695 m_viewTab
[tabIndex
].secondaryView
->show();
1698 QString
DolphinMainWindow::tabProperty(const QString
& property
, int tabIndex
) const
1700 return "Tab " + QString::number(tabIndex
) + ' ' + property
;
1703 void DolphinMainWindow::setUrlAsCaption(const KUrl
& url
)
1706 if (url
.equals(KUrl("file:///"))) {
1709 caption
= url
.fileName();
1710 if (caption
.isEmpty()) {
1711 caption
= url
.protocol();
1715 setCaption(caption
);
1718 void DolphinMainWindow::handleUrl(const KUrl
& url
)
1720 if (KProtocolManager::supportsListing(url
)) {
1721 activeViewContainer()->setUrl(url
);
1724 new KRun(url
, this);
1728 QString
DolphinMainWindow::squeezedText(const QString
& text
) const
1730 const QFontMetrics fm
= fontMetrics();
1731 return fm
.elidedText(text
, Qt::ElideMiddle
, fm
.maxWidth() * 10);
1734 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
1735 KIO::FileUndoManager::UiInterface()
1739 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
1743 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
1745 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
1747 DolphinStatusBar
* statusBar
= mainWin
->activeViewContainer()->statusBar();
1748 statusBar
->setMessage(job
->errorString(), DolphinStatusBar::Error
);
1750 KIO::FileUndoManager::UiInterface::jobError(job
);
1754 #include "dolphinmainwindow.moc"