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 "search/dolphinsearchoptionsconfigurator.h"
35 #include "settings/dolphinsettings.h"
36 #include "settings/dolphinsettingsdialog.h"
37 #include "dolphinviewcontainer.h"
38 #include "panels/folders/folderspanel.h"
39 #include "panels/places/placespanel.h"
40 #include "panels/information/informationpanel.h"
41 #include "mainwindowadaptor.h"
42 #include "statusbar/dolphinstatusbar.h"
43 #include "viewproperties.h"
46 #include "panels/terminal/terminalpanel.h"
49 #include "dolphin_generalsettings.h"
50 #include "dolphin_iconsmodesettings.h"
51 #include "draganddrophelper.h"
54 #include <kactioncollection.h>
56 #include <kdesktopfile.h>
57 #include <kdeversion.h>
58 #include <kfiledialog.h>
59 #include <kfileplacesmodel.h>
61 #include <klineedit.h>
64 #include <kiconloader.h>
65 #include <kio/netaccess.h>
66 #include <kinputdialog.h>
68 #include <kprotocolmanager.h>
71 #include <kmessagebox.h>
72 #include <kfileitemlistproperties.h>
73 #include <konqmimedata.h>
74 #include <kprotocolinfo.h>
77 #include <kstandarddirs.h>
78 #include <kstatusbar.h>
79 #include <kstandardaction.h>
81 #include <ktoggleaction.h>
82 #include <kurlnavigator.h>
84 #include <kurlcombobox.h>
85 #include <ktoolinvocation.h>
87 #include <QDBusMessage>
91 #include <QDockWidget>
92 #include <kacceleratormanager.h>
95 * Remembers the tab configuration if a tab has been closed.
96 * Each closed tab can be restored by the menu
97 * "Go -> Recently Closed Tabs".
105 Q_DECLARE_METATYPE(ClosedTab
)
107 DolphinMainWindow::DolphinMainWindow(int id
) :
112 m_activeViewContainer(0),
113 m_centralWidgetLayout(0),
116 m_searchOptionsConfigurator(0),
125 setObjectName("Dolphin#");
127 m_viewTab
.append(ViewTab());
129 new MainWindowAdaptor(this);
130 QDBusConnection::sessionBus().registerObject(QString("/dolphin/MainWindow%1").arg(m_id
), this);
132 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
133 undoManager
->setUiInterface(new UndoUiInterface());
135 connect(undoManager
, SIGNAL(undoAvailable(bool)),
136 this, SLOT(slotUndoAvailable(bool)));
137 connect(undoManager
, SIGNAL(undoTextChanged(const QString
&)),
138 this, SLOT(slotUndoTextChanged(const QString
&)));
139 connect(undoManager
, SIGNAL(jobRecordingStarted(CommandType
)),
140 this, SLOT(clearStatusBar()));
141 connect(undoManager
, SIGNAL(jobRecordingFinished(CommandType
)),
142 this, SLOT(showCommand(CommandType
)));
143 connect(DolphinSettings::instance().placesModel(), SIGNAL(errorMessage(const QString
&)),
144 this, SLOT(showErrorMessage(const QString
&)));
145 connect(&DragAndDropHelper::instance(), SIGNAL(errorMessage(const QString
&)),
146 this, SLOT(showErrorMessage(const QString
&)));
149 DolphinMainWindow::~DolphinMainWindow()
151 DolphinApplication::app()->removeMainWindow(this);
154 void DolphinMainWindow::openDirectories(const QList
<KUrl
>& dirs
)
156 if (dirs
.isEmpty()) {
160 const int oldOpenTabsCount
= m_viewTab
.count();
162 const GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
163 const bool hasSplitView
= generalSettings
->splitView();
165 // Open each directory inside a new tab. If the "split view" option has been enabled,
166 // always show two directories within one tab.
167 QList
<KUrl
>::const_iterator it
= dirs
.begin();
168 while (it
!= dirs
.end()) {
172 if (hasSplitView
&& (it
!= dirs
.end())) {
173 const int tabIndex
= m_viewTab
.count() - 1;
174 m_viewTab
[tabIndex
].secondaryView
->setUrl(*it
);
179 // remove the previously opened tabs
180 for (int i
= 0; i
< oldOpenTabsCount
; ++i
) {
185 void DolphinMainWindow::openFiles(const QList
<KUrl
>& files
)
187 if (files
.isEmpty()) {
191 // Get all distinct directories from 'files' and open a tab
192 // for each directory. If the "split view" option is enabled, two
193 // directories are shown inside one tab (see openDirectories()).
195 foreach (const KUrl
& url
, files
) {
196 const KUrl
dir(url
.directory());
197 if (!dirs
.contains(dir
)) {
202 openDirectories(dirs
);
204 // Select the files. Although the files can be split between several
205 // tabs, there is no need to split 'files' accordingly, as
206 // the DolphinView will just ignore invalid selections.
207 const int tabCount
= m_viewTab
.count();
208 for (int i
= 0; i
< tabCount
; ++i
) {
209 m_viewTab
[i
].primaryView
->view()->markUrlsAsSelected(files
);
210 if (m_viewTab
[i
].secondaryView
!= 0) {
211 m_viewTab
[i
].secondaryView
->view()->markUrlsAsSelected(files
);
216 void DolphinMainWindow::toggleViews()
218 if (m_viewTab
[m_tabIndex
].primaryView
== 0) {
222 // move secondary view from the last position of the splitter
223 // to the first position
224 m_viewTab
[m_tabIndex
].splitter
->insertWidget(0, m_viewTab
[m_tabIndex
].secondaryView
);
226 DolphinViewContainer
* container
= m_viewTab
[m_tabIndex
].primaryView
;
227 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
228 m_viewTab
[m_tabIndex
].secondaryView
= container
;
231 void DolphinMainWindow::showCommand(CommandType command
)
233 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
235 case KIO::FileUndoManager::Copy
:
236 statusBar
->setMessage(i18nc("@info:status", "Successfully copied."),
237 DolphinStatusBar::OperationCompleted
);
239 case KIO::FileUndoManager::Move
:
240 statusBar
->setMessage(i18nc("@info:status", "Successfully moved."),
241 DolphinStatusBar::OperationCompleted
);
243 case KIO::FileUndoManager::Link
:
244 statusBar
->setMessage(i18nc("@info:status", "Successfully linked."),
245 DolphinStatusBar::OperationCompleted
);
247 case KIO::FileUndoManager::Trash
:
248 statusBar
->setMessage(i18nc("@info:status", "Successfully moved to trash."),
249 DolphinStatusBar::OperationCompleted
);
251 case KIO::FileUndoManager::Rename
:
252 statusBar
->setMessage(i18nc("@info:status", "Successfully renamed."),
253 DolphinStatusBar::OperationCompleted
);
256 case KIO::FileUndoManager::Mkdir
:
257 statusBar
->setMessage(i18nc("@info:status", "Created folder."),
258 DolphinStatusBar::OperationCompleted
);
266 void DolphinMainWindow::refreshViews()
268 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
270 // remember the current active view, as because of
271 // the refreshing the active view might change to
272 // the secondary view
273 DolphinViewContainer
* activeViewContainer
= m_activeViewContainer
;
275 const int tabCount
= m_viewTab
.count();
276 for (int i
= 0; i
< tabCount
; ++i
) {
277 m_viewTab
[i
].primaryView
->refresh();
278 if (m_viewTab
[i
].secondaryView
!= 0) {
279 m_viewTab
[i
].secondaryView
->refresh();
283 setActiveViewContainer(activeViewContainer
);
286 void DolphinMainWindow::pasteIntoFolder()
288 m_activeViewContainer
->view()->pasteIntoFolder();
291 void DolphinMainWindow::changeUrl(const KUrl
& url
)
293 if (!KProtocolManager::supportsListing(url
)) {
294 // The URL navigator only checks for validity, not
295 // if the URL can be listed. An error message is
296 // shown due to DolphinViewContainer::restoreView().
300 DolphinViewContainer
* view
= activeViewContainer();
306 setUrlAsCaption(url
);
307 if (m_viewTab
.count() > 1) {
308 m_tabBar
->setTabText(m_tabIndex
, squeezedText(tabName(m_activeViewContainer
->url())));
310 const QString iconName
= KMimeType::iconNameForUrl(url
);
311 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(iconName
));
312 emit
urlChanged(url
);
316 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
318 KToggleAction
* editableLocationAction
=
319 static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
320 editableLocationAction
->setChecked(editable
);
323 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
327 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
328 int selectedUrlsCount
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedItemsCount();
329 if (m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
330 selectedUrlsCount
+= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItemsCount();
333 QAction
* compareFilesAction
= actionCollection()->action("compare_files");
334 if (selectedUrlsCount
== 2) {
335 compareFilesAction
->setEnabled(isKompareInstalled());
337 compareFilesAction
->setEnabled(false);
340 emit
selectionChanged(selection
);
343 void DolphinMainWindow::slotWheelMoved(int wheelDelta
)
345 if (wheelDelta
> 0) {
352 void DolphinMainWindow::slotRequestItemInfo(const KFileItem
& item
)
354 emit
requestItemInfo(item
);
357 void DolphinMainWindow::updateHistory()
359 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
360 const int index
= urlNavigator
->historyIndex();
362 QAction
* backAction
= actionCollection()->action("go_back");
363 backAction
->setToolTip(i18nc("@info", "Go back"));
364 if (backAction
!= 0) {
365 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
368 QAction
* forwardAction
= actionCollection()->action("go_forward");
369 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
370 if (forwardAction
!= 0) {
371 forwardAction
->setEnabled(index
> 0);
375 void DolphinMainWindow::updateFilterBarAction(bool show
)
377 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
378 showFilterBarAction
->setChecked(show
);
381 void DolphinMainWindow::openNewMainWindow()
383 DolphinApplication::app()->createMainWindow()->show();
386 void DolphinMainWindow::openNewTab()
388 openNewTab(m_activeViewContainer
->url());
389 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
391 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
392 if (navigator
->isUrlEditable()) {
393 // if a new tab is opened and the URL is editable, assure that
394 // the user can edit the URL without manually setting the focus
395 navigator
->setFocus();
399 void DolphinMainWindow::openNewTab(const KUrl
& url
)
401 const KIcon icon
= KIcon(KMimeType::iconNameForUrl(m_activeViewContainer
->url()));
402 if (m_viewTab
.count() == 1) {
403 // Only one view is open currently and hence no tab is shown at
404 // all. Before creating a tab for 'url', provide a tab for the current URL.
405 m_tabBar
->addTab(icon
, squeezedText(tabName(m_activeViewContainer
->url())));
406 m_tabBar
->blockSignals(false);
409 m_tabBar
->addTab(icon
, squeezedText(tabName(url
)));
412 viewTab
.splitter
= new QSplitter(this);
413 viewTab
.splitter
->setChildrenCollapsible(false);
414 viewTab
.primaryView
= new DolphinViewContainer(this, viewTab
.splitter
, url
);
415 viewTab
.primaryView
->setActive(false);
416 connectViewSignals(viewTab
.primaryView
);
417 viewTab
.primaryView
->view()->reload();
419 m_viewTab
.append(viewTab
);
421 actionCollection()->action("close_tab")->setEnabled(true);
423 // provide a split view, if the startup settings are set this way
424 const GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
425 if (generalSettings
->splitView()) {
426 const int tabIndex
= m_viewTab
.count() - 1;
427 createSecondaryView(tabIndex
);
428 m_viewTab
[tabIndex
].secondaryView
->setActive(true);
429 m_viewTab
[tabIndex
].isPrimaryViewActive
= false;
433 void DolphinMainWindow::activateNextTab()
435 if ((m_viewTab
.count() == 1) || (m_tabBar
->count() < 2)) {
439 const int tabIndex
= (m_tabBar
->currentIndex() + 1) % m_tabBar
->count();
440 m_tabBar
->setCurrentIndex(tabIndex
);
443 void DolphinMainWindow::activatePrevTab()
445 if ((m_viewTab
.count() == 1) || (m_tabBar
->count() < 2)) {
449 int tabIndex
= m_tabBar
->currentIndex() - 1;
450 if (tabIndex
== -1) {
451 tabIndex
= m_tabBar
->count() - 1;
453 m_tabBar
->setCurrentIndex(tabIndex
);
456 void DolphinMainWindow::openInNewTab()
458 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
459 if ((list
.count() == 1) && list
[0].isDir()) {
460 openNewTab(m_activeViewContainer
->view()->selectedUrls()[0]);
464 void DolphinMainWindow::openInNewWindow()
466 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
467 if ((list
.count() == 1) && list
[0].isDir()) {
468 DolphinMainWindow
* window
= DolphinApplication::app()->createMainWindow();
469 window
->changeUrl(m_activeViewContainer
->view()->selectedUrls()[0]);
474 void DolphinMainWindow::toggleActiveView()
476 if (m_viewTab
[m_tabIndex
].secondaryView
== 0) {
477 // only one view is available
481 Q_ASSERT(m_activeViewContainer
!= 0);
482 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
484 DolphinViewContainer
* left
= m_viewTab
[m_tabIndex
].primaryView
;
485 DolphinViewContainer
* right
= m_viewTab
[m_tabIndex
].secondaryView
;
486 setActiveViewContainer(m_activeViewContainer
== right
? left
: right
);
489 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
491 DolphinSettings
& settings
= DolphinSettings::instance();
492 GeneralSettings
* generalSettings
= settings
.generalSettings();
494 // Find out if Dolphin is closed directly by the user or
495 // by the session manager because the session is closed
496 bool closedByUser
= true;
497 DolphinApplication
*application
= qobject_cast
<DolphinApplication
*>(qApp
);
498 if (application
&& application
->sessionSaving()) {
499 closedByUser
= false;
502 if ((m_viewTab
.count() > 1) && generalSettings
->confirmClosingMultipleTabs() && closedByUser
) {
503 // Ask the user if he really wants to quit and close all tabs.
504 // Open a confirmation dialog with 3 buttons:
505 // KDialog::Yes -> Quit
506 // KDialog::No -> Close only the current tab
507 // KDialog::Cancel -> do nothing
508 KDialog
*dialog
= new KDialog(this, Qt::Dialog
);
509 dialog
->setCaption(i18nc("@title:window", "Confirmation"));
510 dialog
->setButtons(KDialog::Yes
| KDialog::No
| KDialog::Cancel
);
511 dialog
->setModal(true);
512 dialog
->showButtonSeparator(true);
513 dialog
->setButtonGuiItem(KDialog::Yes
, KStandardGuiItem::quit());
514 dialog
->setButtonGuiItem(KDialog::No
, KGuiItem(i18n("C&lose Current Tab"), KIcon("tab-close")));
515 dialog
->setButtonGuiItem(KDialog::Cancel
, KStandardGuiItem::cancel());
516 dialog
->setDefaultButton(KDialog::Yes
);
518 bool doNotAskAgainCheckboxResult
= false;
520 const int result
= KMessageBox::createKMessageBox(dialog
,
521 QMessageBox::Warning
,
522 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
524 i18n("Do not ask again"),
525 &doNotAskAgainCheckboxResult
,
526 KMessageBox::Notify
);
528 if (doNotAskAgainCheckboxResult
) {
529 generalSettings
->setConfirmClosingMultipleTabs(false);
537 // Close only the current tab
545 generalSettings
->setFirstRun(false);
549 KXmlGuiWindow::closeEvent(event
);
552 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
554 const int tabCount
= m_viewTab
.count();
555 group
.writeEntry("Tab Count", tabCount
);
556 group
.writeEntry("Active Tab Index", m_tabBar
->currentIndex());
558 for (int i
= 0; i
< tabCount
; ++i
) {
559 const DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
560 group
.writeEntry(tabProperty("Primary URL", i
), cont
->url().url());
561 group
.writeEntry(tabProperty("Primary Editable", i
), cont
->isUrlEditable());
563 cont
= m_viewTab
[i
].secondaryView
;
565 group
.writeEntry(tabProperty("Secondary URL", i
), cont
->url().url());
566 group
.writeEntry(tabProperty("Secondary Editable", i
), cont
->isUrlEditable());
571 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
573 const int tabCount
= group
.readEntry("Tab Count", 1);
574 for (int i
= 0; i
< tabCount
; ++i
) {
575 DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
577 cont
->setUrl(group
.readEntry(tabProperty("Primary URL", i
)));
578 const bool editable
= group
.readEntry(tabProperty("Primary Editable", i
), false);
579 cont
->urlNavigator()->setUrlEditable(editable
);
581 cont
= m_viewTab
[i
].secondaryView
;
582 const QString secondaryUrl
= group
.readEntry(tabProperty("Secondary URL", i
));
583 if (!secondaryUrl
.isEmpty()) {
585 // a secondary view should be shown, but no one is available
586 // currently -> create a new view
588 cont
= m_viewTab
[i
].secondaryView
;
592 cont
->setUrl(secondaryUrl
);
593 const bool editable
= group
.readEntry(tabProperty("Secondary Editable", i
), false);
594 cont
->urlNavigator()->setUrlEditable(editable
);
595 } else if (cont
!= 0) {
596 // no secondary view should be shown, but the default setting shows
597 // one already -> close the view
601 // openNewTab() needs to be called only tabCount - 1 times
602 if (i
!= tabCount
- 1) {
607 const int index
= group
.readEntry("Active Tab Index", 0);
608 m_tabBar
->setCurrentIndex(index
);
611 void DolphinMainWindow::updateNewMenu()
613 m_newMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->showHiddenFiles());
614 m_newMenu
->slotCheckUpToDate();
615 m_newMenu
->setPopupFiles(activeViewContainer()->url());
618 void DolphinMainWindow::createDirectory()
620 m_newMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->showHiddenFiles());
621 m_newMenu
->setPopupFiles(activeViewContainer()->url());
622 m_newMenu
->createDirectory();
625 void DolphinMainWindow::quit()
630 void DolphinMainWindow::showErrorMessage(const QString
& message
)
632 if (!message
.isEmpty()) {
633 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
634 statusBar
->setMessage(message
, DolphinStatusBar::Error
);
638 void DolphinMainWindow::slotUndoAvailable(bool available
)
640 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
641 if (undoAction
!= 0) {
642 undoAction
->setEnabled(available
);
646 void DolphinMainWindow::restoreClosedTab(QAction
* action
)
648 if (action
->data().toBool()) {
649 // clear all actions except the "Empty Recently Closed Tabs"
650 // action and the separator
651 QList
<QAction
*> actions
= m_recentTabsMenu
->menu()->actions();
652 const int count
= actions
.size();
653 for (int i
= 2; i
< count
; ++i
) {
654 m_recentTabsMenu
->menu()->removeAction(actions
.at(i
));
657 const ClosedTab closedTab
= action
->data().value
<ClosedTab
>();
658 openNewTab(closedTab
.primaryUrl
);
659 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
661 if (closedTab
.isSplit
) {
662 // create secondary view
664 m_viewTab
[m_tabIndex
].secondaryView
->setUrl(closedTab
.secondaryUrl
);
667 m_recentTabsMenu
->removeAction(action
);
670 if (m_recentTabsMenu
->menu()->actions().count() == 2) {
671 m_recentTabsMenu
->setEnabled(false);
675 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
677 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
678 if (undoAction
!= 0) {
679 undoAction
->setText(text
);
683 void DolphinMainWindow::undo()
686 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
687 KIO::FileUndoManager::self()->undo();
690 void DolphinMainWindow::cut()
692 m_activeViewContainer
->view()->cutSelectedItems();
695 void DolphinMainWindow::copy()
697 m_activeViewContainer
->view()->copySelectedItems();
700 void DolphinMainWindow::paste()
702 m_activeViewContainer
->view()->paste();
705 void DolphinMainWindow::updatePasteAction()
707 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
708 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
709 pasteAction
->setEnabled(pasteInfo
.first
);
710 pasteAction
->setText(pasteInfo
.second
);
713 void DolphinMainWindow::selectAll()
717 // if the URL navigator is editable and focused, select the whole
718 // URL instead of all items of the view
720 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
721 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit(); // krazy:exclude=qclasses
722 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
723 lineEdit
->hasFocus();
725 lineEdit
->selectAll();
727 m_activeViewContainer
->view()->selectAll();
731 void DolphinMainWindow::invertSelection()
734 m_activeViewContainer
->view()->invertSelection();
737 void DolphinMainWindow::toggleSplitView()
739 if (m_viewTab
[m_tabIndex
].secondaryView
== 0) {
740 createSecondaryView(m_tabIndex
);
741 setActiveViewContainer(m_viewTab
[m_tabIndex
].secondaryView
);
742 } else if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
743 // remove secondary view
744 m_viewTab
[m_tabIndex
].secondaryView
->close();
745 m_viewTab
[m_tabIndex
].secondaryView
->deleteLater();
746 m_viewTab
[m_tabIndex
].secondaryView
= 0;
748 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
750 // The primary view is active and should be closed. Hence from a users point of view
751 // the content of the secondary view should be moved to the primary view.
752 // From an implementation point of view it is more efficient to close
753 // the primary view and exchange the internal pointers afterwards.
755 m_viewTab
[m_tabIndex
].primaryView
->close();
756 m_viewTab
[m_tabIndex
].primaryView
->deleteLater();
757 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
758 m_viewTab
[m_tabIndex
].secondaryView
= 0;
760 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
766 void DolphinMainWindow::reloadView()
769 m_activeViewContainer
->view()->reload();
772 void DolphinMainWindow::stopLoading()
776 void DolphinMainWindow::toggleFilterBarVisibility(bool show
)
778 m_activeViewContainer
->showFilterBar(show
);
781 void DolphinMainWindow::toggleEditLocation()
785 QAction
* action
= actionCollection()->action("editable_location");
786 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
787 urlNavigator
->setUrlEditable(action
->isChecked());
790 void DolphinMainWindow::replaceLocation()
792 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
793 navigator
->setUrlEditable(true);
794 navigator
->setFocus();
796 // select the whole text of the combo box editor
797 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit(); // krazy:exclude=qclasses
798 const QString text
= lineEdit
->text();
799 lineEdit
->setSelection(0, text
.length());
802 void DolphinMainWindow::goBack()
805 m_activeViewContainer
->urlNavigator()->goBack();
808 void DolphinMainWindow::goForward()
811 m_activeViewContainer
->urlNavigator()->goForward();
814 void DolphinMainWindow::goUp()
817 m_activeViewContainer
->urlNavigator()->goUp();
820 void DolphinMainWindow::goBack(Qt::MouseButtons buttons
)
822 // The default case (left button pressed) is handled in goBack().
823 if (buttons
== Qt::MidButton
) {
824 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
825 openNewTab(urlNavigator
->historyUrl(urlNavigator
->historyIndex() + 1));
829 void DolphinMainWindow::goForward(Qt::MouseButtons buttons
)
831 // The default case (left button pressed) is handled in goForward().
832 if (buttons
== Qt::MidButton
) {
833 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
834 openNewTab(urlNavigator
->historyUrl(urlNavigator
->historyIndex() - 1));
838 void DolphinMainWindow::goUp(Qt::MouseButtons buttons
)
840 // The default case (left button pressed) is handled in goUp().
841 if (buttons
== Qt::MidButton
) {
842 openNewTab(activeViewContainer()->url().upUrl());
846 void DolphinMainWindow::goHome()
849 m_activeViewContainer
->urlNavigator()->goHome();
852 void DolphinMainWindow::compareFiles()
854 // The method is only invoked if exactly 2 files have
855 // been selected. The selected files may be:
856 // - both in the primary view
857 // - both in the secondary view
858 // - one in the primary view and the other in the secondary
860 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
864 KUrl::List urls
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedUrls();
866 switch (urls
.count()) {
868 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
!= 0);
869 urls
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedUrls();
870 Q_ASSERT(urls
.count() == 2);
878 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
!= 0);
879 urls
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedUrls();
880 Q_ASSERT(urls
.count() == 1);
892 // may not happen: compareFiles may only get invoked if 2
893 // files are selected
898 QString
command("kompare -c \"");
899 command
.append(urlA
.pathOrUrl());
900 command
.append("\" \"");
901 command
.append(urlB
.pathOrUrl());
902 command
.append('\"');
903 KRun::runCommand(command
, "Kompare", "kompare", this);
906 void DolphinMainWindow::toggleShowMenuBar()
908 const bool visible
= menuBar()->isVisible();
909 menuBar()->setVisible(!visible
);
912 void DolphinMainWindow::openTerminal()
914 QString
dir(QDir::homePath());
916 // If the given directory is not local, it can still be the URL of an
917 // ioslave using UDS_LOCAL_PATH which to be converted first.
918 KUrl url
= KIO::NetAccess::mostLocalUrl(m_activeViewContainer
->url(), this);
920 //If the URL is local after the above conversion, set the directory.
921 if (url
.isLocalFile()) {
922 dir
= url
.toLocalFile();
925 KToolInvocation::invokeTerminal(QString(), dir
);
928 void DolphinMainWindow::editSettings()
930 if (m_settingsDialog
== 0) {
931 const KUrl
& url
= activeViewContainer()->url();
932 m_settingsDialog
= new DolphinSettingsDialog(url
, this);
933 m_settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
934 m_settingsDialog
->show();
936 m_settingsDialog
->raise();
940 void DolphinMainWindow::setActiveTab(int index
)
942 Q_ASSERT(index
>= 0);
943 Q_ASSERT(index
< m_viewTab
.count());
944 if (index
== m_tabIndex
) {
948 // hide current tab content
949 ViewTab
& hiddenTab
= m_viewTab
[m_tabIndex
];
950 hiddenTab
.isPrimaryViewActive
= hiddenTab
.primaryView
->isActive();
951 hiddenTab
.primaryView
->setActive(false);
952 if (hiddenTab
.secondaryView
!= 0) {
953 hiddenTab
.secondaryView
->setActive(false);
955 QSplitter
* splitter
= m_viewTab
[m_tabIndex
].splitter
;
957 m_centralWidgetLayout
->removeWidget(splitter
);
959 // show active tab content
962 ViewTab
& viewTab
= m_viewTab
[index
];
963 m_centralWidgetLayout
->addWidget(viewTab
.splitter
, 1);
964 viewTab
.primaryView
->show();
965 if (viewTab
.secondaryView
!= 0) {
966 viewTab
.secondaryView
->show();
968 viewTab
.splitter
->show();
970 setActiveViewContainer(viewTab
.isPrimaryViewActive
? viewTab
.primaryView
:
971 viewTab
.secondaryView
);
974 void DolphinMainWindow::closeTab()
976 closeTab(m_tabBar
->currentIndex());
979 void DolphinMainWindow::closeTab(int index
)
981 Q_ASSERT(index
>= 0);
982 Q_ASSERT(index
< m_viewTab
.count());
983 if (m_viewTab
.count() == 1) {
984 // the last tab may never get closed
988 if (index
== m_tabIndex
) {
989 // The tab that should be closed is the active tab. Activate the
990 // previous tab before closing the tab.
991 m_tabBar
->setCurrentIndex((index
> 0) ? index
- 1 : 1);
993 rememberClosedTab(index
);
996 m_viewTab
[index
].primaryView
->deleteLater();
997 if (m_viewTab
[index
].secondaryView
!= 0) {
998 m_viewTab
[index
].secondaryView
->deleteLater();
1000 m_viewTab
[index
].splitter
->deleteLater();
1001 m_viewTab
.erase(m_viewTab
.begin() + index
);
1003 m_tabBar
->blockSignals(true);
1004 m_tabBar
->removeTab(index
);
1006 if (m_tabIndex
> index
) {
1008 Q_ASSERT(m_tabIndex
>= 0);
1011 // if only one tab is left, also remove the tab entry so that
1012 // closing the last tab is not possible
1013 if (m_viewTab
.count() == 1) {
1014 m_tabBar
->removeTab(0);
1015 actionCollection()->action("close_tab")->setEnabled(false);
1017 m_tabBar
->blockSignals(false);
1021 void DolphinMainWindow::openTabContextMenu(int index
, const QPoint
& pos
)
1025 QAction
* newTabAction
= menu
.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab"));
1026 newTabAction
->setShortcut(actionCollection()->action("new_tab")->shortcut());
1028 QAction
* closeOtherTabsAction
= menu
.addAction(KIcon("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs"));
1030 QAction
* closeTabAction
= menu
.addAction(KIcon("tab-close"), i18nc("@action:inmenu", "Close Tab"));
1031 closeTabAction
->setShortcut(actionCollection()->action("close_tab")->shortcut());
1032 QAction
* selectedAction
= menu
.exec(pos
);
1033 if (selectedAction
== newTabAction
) {
1034 const ViewTab
& tab
= m_viewTab
[index
];
1035 Q_ASSERT(tab
.primaryView
!= 0);
1036 const KUrl url
= (tab
.secondaryView
!= 0) && tab
.secondaryView
->isActive() ?
1037 tab
.secondaryView
->url() : tab
.primaryView
->url();
1039 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
1040 } else if (selectedAction
== closeOtherTabsAction
) {
1041 const int count
= m_tabBar
->count();
1042 for (int i
= 0; i
< index
; ++i
) {
1045 for (int i
= index
+ 1; i
< count
; ++i
) {
1048 } else if (selectedAction
== closeTabAction
) {
1053 void DolphinMainWindow::handlePlacesClick(const KUrl
& url
, Qt::MouseButtons buttons
)
1055 if (buttons
& Qt::MidButton
) {
1057 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
1063 void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent
* event
, bool& canDecode
)
1065 canDecode
= KUrl::List::canDecode(event
->mimeData());
1068 void DolphinMainWindow::searchItems()
1071 const KUrl nepomukSearchUrl
= m_searchOptionsConfigurator
->nepomukSearchUrl();
1072 m_activeViewContainer
->setUrl(nepomukSearchUrl
);
1076 void DolphinMainWindow::slotTabMoved(int from
, int to
)
1078 m_viewTab
.move(from
, to
);
1079 m_tabIndex
= m_tabBar
->currentIndex();
1082 void DolphinMainWindow::showSearchOptions()
1085 m_searchOptionsConfigurator
->show();
1089 void DolphinMainWindow::init()
1091 DolphinSettings
& settings
= DolphinSettings::instance();
1093 // Check whether Dolphin runs the first time. If yes then
1094 // a proper default window size is given at the end of DolphinMainWindow::init().
1095 GeneralSettings
* generalSettings
= settings
.generalSettings();
1096 const bool firstRun
= generalSettings
->firstRun();
1098 generalSettings
->setViewPropsTimestamp(QDateTime::currentDateTime());
1101 setAcceptDrops(true);
1103 m_viewTab
[m_tabIndex
].splitter
= new QSplitter(this);
1104 m_viewTab
[m_tabIndex
].splitter
->setChildrenCollapsible(false);
1108 const KUrl
& homeUrl
= generalSettings
->homeUrl();
1109 setUrlAsCaption(homeUrl
);
1110 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
1111 connect(m_actionHandler
, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
1112 connect(m_actionHandler
, SIGNAL(createDirectory()), SLOT(createDirectory()));
1113 ViewProperties
props(homeUrl
);
1114 m_viewTab
[m_tabIndex
].primaryView
= new DolphinViewContainer(this,
1115 m_viewTab
[m_tabIndex
].splitter
,
1118 m_activeViewContainer
= m_viewTab
[m_tabIndex
].primaryView
;
1119 connectViewSignals(m_activeViewContainer
);
1120 DolphinView
* view
= m_activeViewContainer
->view();
1122 m_activeViewContainer
->show();
1123 m_actionHandler
->setCurrentView(view
);
1125 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
1126 connect(this, SIGNAL(urlChanged(const KUrl
&)),
1127 m_remoteEncoding
, SLOT(slotAboutToOpenUrl()));
1130 m_searchOptionsConfigurator
= new DolphinSearchOptionsConfigurator(this);
1131 m_searchOptionsConfigurator
->hide();
1132 connect(m_searchOptionsConfigurator
, SIGNAL(searchOptionsChanged()),
1133 this, SLOT(searchItems()));
1134 connect(this, SIGNAL(urlChanged(KUrl
)), m_searchOptionsConfigurator
, SLOT(setDirectory(KUrl
)));
1137 m_tabBar
= new KTabBar(this);
1138 m_tabBar
->setMovable(true);
1139 m_tabBar
->setTabsClosable(true);
1140 connect(m_tabBar
, SIGNAL(currentChanged(int)),
1141 this, SLOT(setActiveTab(int)));
1142 connect(m_tabBar
, SIGNAL(tabCloseRequested(int)),
1143 this, SLOT(closeTab(int)));
1144 connect(m_tabBar
, SIGNAL(contextMenu(int, const QPoint
&)),
1145 this, SLOT(openTabContextMenu(int, const QPoint
&)));
1146 connect(m_tabBar
, SIGNAL(newTabRequest()),
1147 this, SLOT(openNewTab()));
1148 connect(m_tabBar
, SIGNAL(testCanDecode(const QDragMoveEvent
*, bool&)),
1149 this, SLOT(slotTestCanDecode(const QDragMoveEvent
*, bool&)));
1150 connect(m_tabBar
, SIGNAL(wheelDelta(int)),
1151 this, SLOT(slotWheelMoved(int)));
1152 connect(m_tabBar
, SIGNAL(mouseMiddleClick(int)),
1153 this, SLOT(closeTab(int)));
1154 connect(m_tabBar
, SIGNAL(tabMoved(int, int)),
1155 this, SLOT(slotTabMoved(int, int)));
1157 m_tabBar
->blockSignals(true); // signals get unblocked after at least 2 tabs are open
1159 QWidget
* centralWidget
= new QWidget(this);
1160 m_centralWidgetLayout
= new QVBoxLayout(centralWidget
);
1161 m_centralWidgetLayout
->setSpacing(0);
1162 m_centralWidgetLayout
->setMargin(0);
1164 m_centralWidgetLayout
->addWidget(m_searchOptionsConfigurator
);
1166 m_centralWidgetLayout
->addWidget(m_tabBar
);
1167 m_centralWidgetLayout
->addWidget(m_viewTab
[m_tabIndex
].splitter
, 1);
1169 setCentralWidget(centralWidget
);
1171 emit
urlChanged(homeUrl
);
1173 setupGUI(Keys
| Save
| Create
| ToolBar
);
1175 m_searchBox
->setParent(toolBar("searchToolBar"));
1176 m_searchBox
->show();
1177 connect(m_searchBox
, SIGNAL(requestSearchOptions()),
1178 this, SLOT(showSearchOptions()));
1180 connect(m_searchBox
, SIGNAL(searchTextChanged(QString
)),
1181 m_searchOptionsConfigurator
, SLOT(setCustomSearchQuery(QString
)));
1184 stateChanged("new_file");
1186 QClipboard
* clipboard
= QApplication::clipboard();
1187 connect(clipboard
, SIGNAL(dataChanged()),
1188 this, SLOT(updatePasteAction()));
1189 updatePasteAction();
1192 if (generalSettings
->splitView()) {
1195 updateViewActions();
1197 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1198 showFilterBarAction
->setChecked(generalSettings
->filterBar());
1201 // assure a proper default size if Dolphin runs the first time
1205 m_showMenuBar
->setChecked(!menuBar()->isHidden()); // workaround for bug #171080
1208 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer
* viewContainer
)
1210 Q_ASSERT(viewContainer
!= 0);
1211 Q_ASSERT((viewContainer
== m_viewTab
[m_tabIndex
].primaryView
) ||
1212 (viewContainer
== m_viewTab
[m_tabIndex
].secondaryView
));
1213 if (m_activeViewContainer
== viewContainer
) {
1217 m_activeViewContainer
->setActive(false);
1218 m_activeViewContainer
= viewContainer
;
1220 // Activating the view container might trigger a recursive setActiveViewContainer() call
1221 // inside DolphinMainWindow::toggleActiveView() when having a split view. Temporary
1222 // disconnect the activated() signal in this case:
1223 disconnect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1224 m_activeViewContainer
->setActive(true);
1225 connect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1227 m_actionHandler
->setCurrentView(viewContainer
->view());
1230 updateEditActions();
1231 updateViewActions();
1234 const KUrl
& url
= m_activeViewContainer
->url();
1235 setUrlAsCaption(url
);
1236 if (m_viewTab
.count() > 1 && m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
1237 m_tabBar
->setTabText(m_tabIndex
, tabName(url
));
1238 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(KMimeType::iconNameForUrl(url
)));
1241 emit
urlChanged(url
);
1244 void DolphinMainWindow::setupActions()
1246 // setup 'File' menu
1247 m_newMenu
= new DolphinNewMenu(this, this);
1248 KMenu
* menu
= m_newMenu
->menu();
1249 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1250 menu
->setIcon(KIcon("document-new"));
1251 connect(menu
, SIGNAL(aboutToShow()),
1252 this, SLOT(updateNewMenu()));
1254 KAction
* newWindow
= actionCollection()->addAction("new_window");
1255 newWindow
->setIcon(KIcon("window-new"));
1256 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1257 newWindow
->setShortcut(Qt::CTRL
| Qt::Key_N
);
1258 connect(newWindow
, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1260 KAction
* newTab
= actionCollection()->addAction("new_tab");
1261 newTab
->setIcon(KIcon("tab-new"));
1262 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1263 newTab
->setShortcut(KShortcut(Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
));
1264 connect(newTab
, SIGNAL(triggered()), this, SLOT(openNewTab()));
1266 KAction
* closeTab
= actionCollection()->addAction("close_tab");
1267 closeTab
->setIcon(KIcon("tab-close"));
1268 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1269 closeTab
->setShortcut(Qt::CTRL
| Qt::Key_W
);
1270 closeTab
->setEnabled(false);
1271 connect(closeTab
, SIGNAL(triggered()), this, SLOT(closeTab()));
1273 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1275 // setup 'Edit' menu
1276 KStandardAction::undo(this,
1278 actionCollection());
1280 // need to remove shift+del from cut action, else the shortcut for deletejob
1282 KAction
* cut
= KStandardAction::cut(this, SLOT(cut()), actionCollection());
1283 KShortcut cutShortcut
= cut
->shortcut();
1284 cutShortcut
.remove(Qt::SHIFT
+ Qt::Key_Delete
, KShortcut::KeepEmpty
);
1285 cut
->setShortcut(cutShortcut
);
1286 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1287 KAction
* paste
= KStandardAction::paste(this, SLOT(paste()), actionCollection());
1288 // The text of the paste-action is modified dynamically by Dolphin
1289 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1290 // due to the long text, the text "Paste" is used:
1291 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1293 KAction
* selectAll
= actionCollection()->addAction("select_all");
1294 selectAll
->setText(i18nc("@action:inmenu Edit", "Select All"));
1295 selectAll
->setShortcut(Qt::CTRL
+ Qt::Key_A
);
1296 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
1298 KAction
* invertSelection
= actionCollection()->addAction("invert_selection");
1299 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1300 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1301 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
1303 // setup 'View' menu
1304 // (note that most of it is set up in DolphinViewActionHandler)
1306 KAction
* split
= actionCollection()->addAction("split_view");
1307 split
->setShortcut(Qt::Key_F3
);
1308 updateSplitAction();
1309 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1311 KAction
* reload
= actionCollection()->addAction("reload");
1312 reload
->setText(i18nc("@action:inmenu View", "Reload"));
1313 reload
->setShortcut(Qt::Key_F5
);
1314 reload
->setIcon(KIcon("view-refresh"));
1315 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
1317 KAction
* stop
= actionCollection()->addAction("stop");
1318 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1319 stop
->setToolTip(i18nc("@info", "Stop loading"));
1320 stop
->setIcon(KIcon("process-stop"));
1321 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
1323 KToggleAction
* showFullLocation
= actionCollection()->add
<KToggleAction
>("editable_location");
1324 showFullLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1325 showFullLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
1326 connect(showFullLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1328 KAction
* replaceLocation
= actionCollection()->addAction("replace_location");
1329 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1330 replaceLocation
->setShortcut(Qt::Key_F6
);
1331 connect(replaceLocation
, SIGNAL(triggered()), this, SLOT(replaceLocation()));
1334 KAction
* backAction
= KStandardAction::back(this, SLOT(goBack()), actionCollection());
1335 connect(backAction
, SIGNAL(triggered(Qt::MouseButtons
, Qt::KeyboardModifiers
)), this, SLOT(goBack(Qt::MouseButtons
)));
1336 KShortcut backShortcut
= backAction
->shortcut();
1337 backShortcut
.setAlternate(Qt::Key_Backspace
);
1338 backAction
->setShortcut(backShortcut
);
1340 m_recentTabsMenu
= new KActionMenu(i18n("Recently Closed Tabs"), this);
1341 m_recentTabsMenu
->setIcon(KIcon("edit-undo"));
1342 actionCollection()->addAction("closed_tabs", m_recentTabsMenu
);
1343 connect(m_recentTabsMenu
->menu(), SIGNAL(triggered(QAction
*)),
1344 this, SLOT(restoreClosedTab(QAction
*)));
1346 QAction
* action
= new QAction("Empty Recently Closed Tabs", m_recentTabsMenu
);
1347 action
->setIcon(KIcon("edit-clear-list"));
1348 action
->setData(QVariant::fromValue(true));
1349 m_recentTabsMenu
->addAction(action
);
1350 m_recentTabsMenu
->addSeparator();
1351 m_recentTabsMenu
->setEnabled(false);
1353 KAction
* forwardAction
= KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1354 connect(forwardAction
, SIGNAL(triggered(Qt::MouseButtons
, Qt::KeyboardModifiers
)), this, SLOT(goForward(Qt::MouseButtons
)));
1356 KAction
* upAction
= KStandardAction::up(this, SLOT(goUp()), actionCollection());
1357 connect(upAction
, SIGNAL(triggered(Qt::MouseButtons
, Qt::KeyboardModifiers
)), this, SLOT(goUp(Qt::MouseButtons
)));
1359 KStandardAction::home(this, SLOT(goHome()), actionCollection());
1361 // setup 'Tools' menu
1362 KToggleAction
* showSearchBar
= actionCollection()->add
<KToggleAction
>("show_search_bar");
1363 showSearchBar
->setText(i18nc("@action:inmenu Tools", "Show Search Bar"));
1364 showSearchBar
->setShortcut(Qt::CTRL
| Qt::Key_S
);
1365 connect(showSearchBar
, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
1367 KToggleAction
* showFilterBar
= actionCollection()->add
<KToggleAction
>("show_filter_bar");
1368 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1369 showFilterBar
->setIcon(KIcon("view-filter"));
1370 showFilterBar
->setShortcut(Qt::CTRL
| Qt::Key_I
);
1371 connect(showFilterBar
, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
1373 KAction
* compareFiles
= actionCollection()->addAction("compare_files");
1374 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1375 compareFiles
->setIcon(KIcon("kompare"));
1376 compareFiles
->setEnabled(false);
1377 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
1379 KAction
* openTerminal
= actionCollection()->addAction("open_terminal");
1380 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1381 openTerminal
->setIcon(KIcon("utilities-terminal"));
1382 openTerminal
->setShortcut(Qt::SHIFT
| Qt::Key_F4
);
1383 connect(openTerminal
, SIGNAL(triggered()), this, SLOT(openTerminal()));
1385 // setup 'Settings' menu
1386 m_showMenuBar
= KStandardAction::showMenubar(this, SLOT(toggleShowMenuBar()), actionCollection());
1387 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1389 // not in menu actions
1390 KAction
* activateNextTab
= actionCollection()->addAction("activate_next_tab");
1391 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1392 connect(activateNextTab
, SIGNAL(triggered()), SLOT(activateNextTab()));
1393 activateNextTab
->setShortcuts(QApplication::isRightToLeft() ? KStandardShortcut::tabPrev() :
1394 KStandardShortcut::tabNext());
1396 KAction
* activatePrevTab
= actionCollection()->addAction("activate_prev_tab");
1397 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1398 connect(activatePrevTab
, SIGNAL(triggered()), SLOT(activatePrevTab()));
1399 activatePrevTab
->setShortcuts(QApplication::isRightToLeft() ? KStandardShortcut::tabNext() :
1400 KStandardShortcut::tabPrev());
1403 KAction
* openInNewTab
= actionCollection()->addAction("open_in_new_tab");
1404 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1405 openInNewTab
->setIcon(KIcon("tab-new"));
1406 connect(openInNewTab
, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1408 KAction
* openInNewWindow
= actionCollection()->addAction("open_in_new_window");
1409 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1410 openInNewWindow
->setIcon(KIcon("window-new"));
1411 connect(openInNewWindow
, SIGNAL(triggered()), this, SLOT(openInNewWindow()));
1414 m_searchBox
= new DolphinSearchBox(this);
1415 connect(m_searchBox
, SIGNAL(search(QString
)), this, SLOT(searchItems()));
1417 KAction
* search
= new KAction(this);
1418 actionCollection()->addAction("search_bar", search
);
1419 search
->setText(i18nc("@action:inmenu", "Search Bar"));
1420 search
->setDefaultWidget(m_searchBox
);
1421 search
->setShortcutConfigurable(false);
1424 void DolphinMainWindow::setupDockWidgets()
1426 // setup "Information"
1427 QDockWidget
* infoDock
= new QDockWidget(i18nc("@title:window", "Information"));
1428 infoDock
->setObjectName("infoDock");
1429 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1430 Panel
* infoPanel
= new InformationPanel(infoDock
);
1431 connect(infoPanel
, SIGNAL(urlActivated(KUrl
)), this, SLOT(handleUrl(KUrl
)));
1432 infoDock
->setWidget(infoPanel
);
1434 QAction
* infoAction
= infoDock
->toggleViewAction();
1435 infoAction
->setText(i18nc("@title:window", "Information"));
1436 infoAction
->setShortcut(Qt::Key_F11
);
1437 infoAction
->setIcon(KIcon("dialog-information"));
1438 actionCollection()->addAction("show_info_panel", infoDock
->toggleViewAction());
1440 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1441 connect(this, SIGNAL(urlChanged(KUrl
)),
1442 infoPanel
, SLOT(setUrl(KUrl
)));
1443 connect(this, SIGNAL(selectionChanged(KFileItemList
)),
1444 infoPanel
, SLOT(setSelection(KFileItemList
)));
1445 connect(this, SIGNAL(requestItemInfo(KFileItem
)),
1446 infoPanel
, SLOT(requestDelayedItemInfo(KFileItem
)));
1449 QDockWidget
* foldersDock
= new QDockWidget(i18nc("@title:window", "Folders"));
1450 foldersDock
->setObjectName("foldersDock");
1451 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1452 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1453 foldersDock
->setWidget(foldersPanel
);
1455 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1456 foldersAction
->setText(i18nc("@title:window", "Folders"));
1457 foldersAction
->setShortcut(Qt::Key_F7
);
1458 foldersAction
->setIcon(KIcon("folder"));
1459 actionCollection()->addAction("show_folders_panel", foldersDock
->toggleViewAction());
1461 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1462 connect(this, SIGNAL(urlChanged(KUrl
)),
1463 foldersPanel
, SLOT(setUrl(KUrl
)));
1464 connect(foldersPanel
, SIGNAL(changeUrl(KUrl
, Qt::MouseButtons
)),
1465 this, SLOT(handlePlacesClick(KUrl
, Qt::MouseButtons
)));
1469 QDockWidget
* terminalDock
= new QDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1470 terminalDock
->setObjectName("terminalDock");
1471 terminalDock
->setAllowedAreas(Qt::TopDockWidgetArea
| Qt::BottomDockWidgetArea
);
1472 Panel
* terminalPanel
= new TerminalPanel(terminalDock
);
1473 terminalDock
->setWidget(terminalPanel
);
1475 connect(terminalPanel
, SIGNAL(hideTerminalPanel()), terminalDock
, SLOT(hide()));
1477 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1478 terminalAction
->setText(i18nc("@title:window Shell terminal", "Terminal"));
1479 terminalAction
->setShortcut(Qt::Key_F4
);
1480 terminalAction
->setIcon(KIcon("utilities-terminal"));
1481 actionCollection()->addAction("show_terminal_panel", terminalDock
->toggleViewAction());
1483 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1484 connect(this, SIGNAL(urlChanged(KUrl
)),
1485 terminalPanel
, SLOT(setUrl(KUrl
)));
1488 const bool firstRun
= DolphinSettings::instance().generalSettings()->firstRun();
1490 foldersDock
->hide();
1492 terminalDock
->hide();
1496 QDockWidget
* placesDock
= new QDockWidget(i18nc("@title:window", "Places"));
1497 placesDock
->setObjectName("placesDock");
1498 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1500 PlacesPanel
* placesPanel
= new PlacesPanel(placesDock
);
1501 placesDock
->setWidget(placesPanel
);
1502 placesPanel
->setModel(DolphinSettings::instance().placesModel());
1503 placesPanel
->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff
);
1505 QAction
* placesAction
= placesDock
->toggleViewAction();
1506 placesAction
->setText(i18nc("@title:window", "Places"));
1507 placesAction
->setShortcut(Qt::Key_F9
);
1508 placesAction
->setIcon(KIcon("bookmarks"));
1509 actionCollection()->addAction("show_places_panel", placesDock
->toggleViewAction());
1511 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1512 connect(placesPanel
, SIGNAL(urlChanged(KUrl
, Qt::MouseButtons
)),
1513 this, SLOT(handlePlacesClick(KUrl
, Qt::MouseButtons
)));
1514 connect(this, SIGNAL(urlChanged(KUrl
)),
1515 placesPanel
, SLOT(setUrl(KUrl
)));
1518 void DolphinMainWindow::updateEditActions()
1520 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1521 if (list
.isEmpty()) {
1522 stateChanged("has_no_selection");
1524 stateChanged("has_selection");
1526 KActionCollection
* col
= actionCollection();
1527 QAction
* renameAction
= col
->action("rename");
1528 QAction
* moveToTrashAction
= col
->action("move_to_trash");
1529 QAction
* deleteAction
= col
->action("delete");
1530 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
1531 QAction
* deleteWithTrashShortcut
= col
->action("delete_shortcut"); // see DolphinViewActionHandler
1533 KFileItemListProperties
capabilities(list
);
1534 const bool enableMoveToTrash
= capabilities
.isLocal() && capabilities
.supportsMoving();
1536 renameAction
->setEnabled(capabilities
.supportsMoving());
1537 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1538 deleteAction
->setEnabled(capabilities
.supportsDeleting());
1539 deleteWithTrashShortcut
->setEnabled(capabilities
.supportsDeleting() && !enableMoveToTrash
);
1540 cutAction
->setEnabled(capabilities
.supportsMoving());
1542 updatePasteAction();
1545 void DolphinMainWindow::updateViewActions()
1547 m_actionHandler
->updateViewActions();
1549 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1550 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
1552 updateSplitAction();
1554 QAction
* editableLocactionAction
= actionCollection()->action("editable_location");
1555 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
1556 editableLocactionAction
->setChecked(urlNavigator
->isUrlEditable());
1559 void DolphinMainWindow::updateGoActions()
1561 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
1562 const KUrl
& currentUrl
= m_activeViewContainer
->url();
1563 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
1566 void DolphinMainWindow::rememberClosedTab(int index
)
1568 KMenu
* tabsMenu
= m_recentTabsMenu
->menu();
1570 const QString primaryPath
= m_viewTab
[index
].primaryView
->url().path();
1571 const QString iconName
= KMimeType::iconNameForUrl(primaryPath
);
1573 QAction
* action
= new QAction(squeezedText(primaryPath
), tabsMenu
);
1575 ClosedTab closedTab
;
1576 closedTab
.primaryUrl
= m_viewTab
[index
].primaryView
->url();
1578 if (m_viewTab
[index
].secondaryView
!= 0) {
1579 closedTab
.secondaryUrl
= m_viewTab
[index
].secondaryView
->url();
1580 closedTab
.isSplit
= true;
1582 closedTab
.isSplit
= false;
1585 action
->setData(QVariant::fromValue(closedTab
));
1586 action
->setIcon(KIcon(iconName
));
1588 // add the closed tab menu entry after the separator and
1589 // "Empty Recently Closed Tabs" entry
1590 if (tabsMenu
->actions().size() == 2) {
1591 tabsMenu
->addAction(action
);
1593 tabsMenu
->insertAction(tabsMenu
->actions().at(2), action
);
1596 // assure that only up to 8 closed tabs are shown in the menu
1597 if (tabsMenu
->actions().size() > 8) {
1598 tabsMenu
->removeAction(tabsMenu
->actions().last());
1600 actionCollection()->action("closed_tabs")->setEnabled(true);
1601 KAcceleratorManager::manage(tabsMenu
);
1604 void DolphinMainWindow::clearStatusBar()
1606 m_activeViewContainer
->statusBar()->clear();
1609 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
1611 connect(container
, SIGNAL(showFilterBarChanged(bool)),
1612 this, SLOT(updateFilterBarAction(bool)));
1614 DolphinView
* view
= container
->view();
1615 connect(view
, SIGNAL(selectionChanged(KFileItemList
)),
1616 this, SLOT(slotSelectionChanged(KFileItemList
)));
1617 connect(view
, SIGNAL(requestItemInfo(KFileItem
)),
1618 this, SLOT(slotRequestItemInfo(KFileItem
)));
1619 connect(view
, SIGNAL(activated()),
1620 this, SLOT(toggleActiveView()));
1621 connect(view
, SIGNAL(tabRequested(const KUrl
&)),
1622 this, SLOT(openNewTab(const KUrl
&)));
1624 const KUrlNavigator
* navigator
= container
->urlNavigator();
1625 connect(navigator
, SIGNAL(urlChanged(const KUrl
&)),
1626 this, SLOT(changeUrl(const KUrl
&)));
1627 connect(navigator
, SIGNAL(historyChanged()),
1628 this, SLOT(updateHistory()));
1629 connect(navigator
, SIGNAL(editableStateChanged(bool)),
1630 this, SLOT(slotEditableStateChanged(bool)));
1633 void DolphinMainWindow::updateSplitAction()
1635 QAction
* splitAction
= actionCollection()->action("split_view");
1636 if (m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
1637 if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
1638 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
1639 splitAction
->setToolTip(i18nc("@info", "Close right view"));
1640 splitAction
->setIcon(KIcon("view-right-close"));
1642 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
1643 splitAction
->setToolTip(i18nc("@info", "Close left view"));
1644 splitAction
->setIcon(KIcon("view-left-close"));
1647 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
1648 splitAction
->setToolTip(i18nc("@info", "Split view"));
1649 splitAction
->setIcon(KIcon("view-right-new"));
1653 QString
DolphinMainWindow::tabName(const KUrl
& url
) const
1656 if (url
.equals(KUrl("file:///"))) {
1659 name
= url
.fileName();
1660 if (name
.isEmpty()) {
1661 name
= url
.protocol();
1663 // Make sure that a '&' inside the directory name is displayed correctly
1664 // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
1665 name
.replace('&', "&&");
1671 bool DolphinMainWindow::isKompareInstalled() const
1673 static bool initialized
= false;
1674 static bool installed
= false;
1676 // TODO: maybe replace this approach later by using a menu
1677 // plugin like kdiff3plugin.cpp
1678 installed
= !KGlobal::dirs()->findExe("kompare").isEmpty();
1684 void DolphinMainWindow::createSecondaryView(int tabIndex
)
1686 QSplitter
* splitter
= m_viewTab
[tabIndex
].splitter
;
1687 const int newWidth
= (m_viewTab
[tabIndex
].primaryView
->width() - splitter
->handleWidth()) / 2;
1689 const DolphinView
* view
= m_viewTab
[tabIndex
].primaryView
->view();
1690 m_viewTab
[tabIndex
].secondaryView
= new DolphinViewContainer(this, 0, view
->rootUrl());
1691 splitter
->addWidget(m_viewTab
[tabIndex
].secondaryView
);
1692 splitter
->setSizes(QList
<int>() << newWidth
<< newWidth
);
1693 connectViewSignals(m_viewTab
[tabIndex
].secondaryView
);
1694 m_viewTab
[tabIndex
].secondaryView
->view()->reload();
1695 m_viewTab
[tabIndex
].secondaryView
->setActive(false);
1696 m_viewTab
[tabIndex
].secondaryView
->show();
1699 QString
DolphinMainWindow::tabProperty(const QString
& property
, int tabIndex
) const
1701 return "Tab " + QString::number(tabIndex
) + ' ' + property
;
1704 void DolphinMainWindow::setUrlAsCaption(const KUrl
& url
)
1707 if (url
.equals(KUrl("file:///"))) {
1710 caption
= url
.fileName();
1711 if (caption
.isEmpty()) {
1712 caption
= url
.protocol();
1716 setCaption(caption
);
1719 void DolphinMainWindow::handleUrl(const KUrl
& url
)
1721 if (KProtocolManager::supportsListing(url
)) {
1722 activeViewContainer()->setUrl(url
);
1725 new KRun(url
, this);
1729 QString
DolphinMainWindow::squeezedText(const QString
& text
) const
1731 const QFontMetrics fm
= fontMetrics();
1732 return fm
.elidedText(text
, Qt::ElideMiddle
, fm
.maxWidth() * 10);
1735 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
1736 KIO::FileUndoManager::UiInterface()
1740 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
1744 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
1746 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
1748 DolphinStatusBar
* statusBar
= mainWin
->activeViewContainer()->statusBar();
1749 statusBar
->setMessage(job
->errorString(), DolphinStatusBar::Error
);
1751 KIO::FileUndoManager::UiInterface::jobError(job
);
1755 #include "dolphinmainwindow.moc"