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),
114 m_searchOptionsConfigurator(0),
122 setObjectName("Dolphin#");
124 m_viewTab
.append(ViewTab());
126 new MainWindowAdaptor(this);
127 QDBusConnection::sessionBus().registerObject(QString("/dolphin/MainWindow%1").arg(m_id
), this);
129 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
130 undoManager
->setUiInterface(new UndoUiInterface());
132 connect(undoManager
, SIGNAL(undoAvailable(bool)),
133 this, SLOT(slotUndoAvailable(bool)));
134 connect(undoManager
, SIGNAL(undoTextChanged(const QString
&)),
135 this, SLOT(slotUndoTextChanged(const QString
&)));
136 connect(undoManager
, SIGNAL(jobRecordingStarted(CommandType
)),
137 this, SLOT(clearStatusBar()));
138 connect(undoManager
, SIGNAL(jobRecordingFinished(CommandType
)),
139 this, SLOT(showCommand(CommandType
)));
140 connect(DolphinSettings::instance().placesModel(), SIGNAL(errorMessage(const QString
&)),
141 this, SLOT(showErrorMessage(const QString
&)));
142 connect(&DragAndDropHelper::instance(), SIGNAL(errorMessage(const QString
&)),
143 this, SLOT(showErrorMessage(const QString
&)));
146 DolphinMainWindow::~DolphinMainWindow()
148 DolphinApplication::app()->removeMainWindow(this);
151 void DolphinMainWindow::toggleViews()
153 if (m_viewTab
[m_tabIndex
].primaryView
== 0) {
157 // move secondary view from the last position of the splitter
158 // to the first position
159 m_viewTab
[m_tabIndex
].splitter
->insertWidget(0, m_viewTab
[m_tabIndex
].secondaryView
);
161 DolphinViewContainer
* container
= m_viewTab
[m_tabIndex
].primaryView
;
162 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
163 m_viewTab
[m_tabIndex
].secondaryView
= container
;
166 void DolphinMainWindow::showCommand(CommandType command
)
168 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
170 case KIO::FileUndoManager::Copy
:
171 statusBar
->setMessage(i18nc("@info:status", "Successfully copied."),
172 DolphinStatusBar::OperationCompleted
);
174 case KIO::FileUndoManager::Move
:
175 statusBar
->setMessage(i18nc("@info:status", "Successfully moved."),
176 DolphinStatusBar::OperationCompleted
);
178 case KIO::FileUndoManager::Link
:
179 statusBar
->setMessage(i18nc("@info:status", "Successfully linked."),
180 DolphinStatusBar::OperationCompleted
);
182 case KIO::FileUndoManager::Trash
:
183 statusBar
->setMessage(i18nc("@info:status", "Successfully moved to trash."),
184 DolphinStatusBar::OperationCompleted
);
186 case KIO::FileUndoManager::Rename
:
187 statusBar
->setMessage(i18nc("@info:status", "Successfully renamed."),
188 DolphinStatusBar::OperationCompleted
);
191 case KIO::FileUndoManager::Mkdir
:
192 statusBar
->setMessage(i18nc("@info:status", "Created folder."),
193 DolphinStatusBar::OperationCompleted
);
201 void DolphinMainWindow::refreshViews()
203 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
205 // remember the current active view, as because of
206 // the refreshing the active view might change to
207 // the secondary view
208 DolphinViewContainer
* activeViewContainer
= m_activeViewContainer
;
210 const int tabCount
= m_viewTab
.count();
211 for (int i
= 0; i
< tabCount
; ++i
) {
212 m_viewTab
[i
].primaryView
->refresh();
213 if (m_viewTab
[i
].secondaryView
!= 0) {
214 m_viewTab
[i
].secondaryView
->refresh();
218 setActiveViewContainer(activeViewContainer
);
221 void DolphinMainWindow::pasteIntoFolder()
223 m_activeViewContainer
->view()->pasteIntoFolder();
226 void DolphinMainWindow::changeUrl(const KUrl
& url
)
228 if (!KProtocolManager::supportsListing(url
)) {
229 // The URL navigator only checks for validity, not
230 // if the URL can be listed. An error message is
231 // shown due to DolphinViewContainer::restoreView().
235 DolphinViewContainer
* view
= activeViewContainer();
241 setUrlAsCaption(url
);
242 if (m_viewTab
.count() > 1) {
243 m_tabBar
->setTabText(m_tabIndex
, squeezedText(tabName(m_activeViewContainer
->url())));
245 const QString iconName
= KMimeType::iconNameForUrl(url
);
246 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(iconName
));
247 emit
urlChanged(url
);
251 void DolphinMainWindow::changeSelection(const KFileItemList
& selection
)
253 activeViewContainer()->view()->changeSelection(selection
);
256 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
258 KToggleAction
* editableLocationAction
=
259 static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
260 editableLocationAction
->setChecked(editable
);
263 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
267 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
268 int selectedUrlsCount
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedItemsCount();
269 if (m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
270 selectedUrlsCount
+= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItemsCount();
273 QAction
* compareFilesAction
= actionCollection()->action("compare_files");
274 if (selectedUrlsCount
== 2) {
275 compareFilesAction
->setEnabled(isKompareInstalled());
277 compareFilesAction
->setEnabled(false);
280 emit
selectionChanged(selection
);
283 void DolphinMainWindow::slotWheelMoved(int wheelDelta
)
285 if (wheelDelta
> 0) {
292 void DolphinMainWindow::slotRequestItemInfo(const KFileItem
& item
)
294 emit
requestItemInfo(item
);
297 void DolphinMainWindow::updateHistory()
299 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
300 const int index
= urlNavigator
->historyIndex();
302 QAction
* backAction
= actionCollection()->action("go_back");
303 backAction
->setToolTip(i18nc("@info", "Go back"));
304 if (backAction
!= 0) {
305 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
308 QAction
* forwardAction
= actionCollection()->action("go_forward");
309 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
310 if (forwardAction
!= 0) {
311 forwardAction
->setEnabled(index
> 0);
315 void DolphinMainWindow::updateFilterBarAction(bool show
)
317 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
318 showFilterBarAction
->setChecked(show
);
321 void DolphinMainWindow::openNewMainWindow()
323 DolphinApplication::app()->createMainWindow()->show();
326 void DolphinMainWindow::openNewTab()
328 openNewTab(m_activeViewContainer
->url());
329 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
331 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
332 if (navigator
->isUrlEditable()) {
333 // if a new tab is opened and the URL is editable, assure that
334 // the user can edit the URL without manually setting the focus
335 navigator
->setFocus();
339 void DolphinMainWindow::openNewTab(const KUrl
& url
)
341 const KIcon icon
= KIcon(KMimeType::iconNameForUrl(m_activeViewContainer
->url()));
342 if (m_viewTab
.count() == 1) {
343 // Only one view is open currently and hence no tab is shown at
344 // all. Before creating a tab for 'url', provide a tab for the current URL.
345 m_tabBar
->addTab(icon
, squeezedText(tabName(m_activeViewContainer
->url())));
346 m_tabBar
->blockSignals(false);
349 m_tabBar
->addTab(icon
, squeezedText(tabName(url
)));
352 viewTab
.splitter
= new QSplitter(this);
353 viewTab
.splitter
->setChildrenCollapsible(false);
354 viewTab
.primaryView
= new DolphinViewContainer(this, viewTab
.splitter
, url
);
355 viewTab
.primaryView
->setActive(false);
356 connectViewSignals(viewTab
.primaryView
);
357 viewTab
.primaryView
->view()->reload();
359 m_viewTab
.append(viewTab
);
361 actionCollection()->action("close_tab")->setEnabled(true);
363 // provide a split view, if the startup settings are set this way
364 const GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
365 if (generalSettings
->splitView()) {
366 const int tabIndex
= m_viewTab
.count() - 1;
367 createSecondaryView(tabIndex
);
368 m_viewTab
[tabIndex
].secondaryView
->setActive(true);
369 m_viewTab
[tabIndex
].isPrimaryViewActive
= false;
373 void DolphinMainWindow::activateNextTab()
375 if ((m_viewTab
.count() == 1) || (m_tabBar
->count() < 2)) {
379 const int tabIndex
= (m_tabBar
->currentIndex() + 1) % m_tabBar
->count();
380 m_tabBar
->setCurrentIndex(tabIndex
);
383 void DolphinMainWindow::activatePrevTab()
385 if ((m_viewTab
.count() == 1) || (m_tabBar
->count() < 2)) {
389 int tabIndex
= m_tabBar
->currentIndex() - 1;
390 if (tabIndex
== -1) {
391 tabIndex
= m_tabBar
->count() - 1;
393 m_tabBar
->setCurrentIndex(tabIndex
);
396 void DolphinMainWindow::openInNewTab()
398 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
399 if ((list
.count() == 1) && list
[0].isDir()) {
400 openNewTab(m_activeViewContainer
->view()->selectedUrls()[0]);
404 void DolphinMainWindow::openInNewWindow()
406 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
407 if ((list
.count() == 1) && list
[0].isDir()) {
408 DolphinMainWindow
* window
= DolphinApplication::app()->createMainWindow();
409 window
->changeUrl(m_activeViewContainer
->view()->selectedUrls()[0]);
414 void DolphinMainWindow::toggleActiveView()
416 if (m_viewTab
[m_tabIndex
].secondaryView
== 0) {
417 // only one view is available
421 Q_ASSERT(m_activeViewContainer
!= 0);
422 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
424 DolphinViewContainer
* left
= m_viewTab
[m_tabIndex
].primaryView
;
425 DolphinViewContainer
* right
= m_viewTab
[m_tabIndex
].secondaryView
;
426 setActiveViewContainer(m_activeViewContainer
== right
? left
: right
);
429 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
431 DolphinSettings
& settings
= DolphinSettings::instance();
432 GeneralSettings
* generalSettings
= settings
.generalSettings();
434 // Find out if Dolphin is closed directly by the user or
435 // by the session manager because the session is closed
436 bool closedByUser
= true;
437 DolphinApplication
*application
= qobject_cast
<DolphinApplication
*>(qApp
);
438 if (application
&& application
->sessionSaving()) {
439 closedByUser
= false;
442 if ((m_viewTab
.count() > 1) && generalSettings
->confirmClosingMultipleTabs() && closedByUser
) {
443 // Ask the user if he really wants to quit and close all tabs.
444 // Open a confirmation dialog with 3 buttons:
445 // KDialog::Yes -> Quit
446 // KDialog::No -> Close only the current tab
447 // KDialog::Cancel -> do nothing
448 KDialog
*dialog
= new KDialog(this, Qt::Dialog
);
449 dialog
->setCaption(i18nc("@title:window", "Confirmation"));
450 dialog
->setButtons(KDialog::Yes
| KDialog::No
| KDialog::Cancel
);
451 dialog
->setModal(true);
452 dialog
->showButtonSeparator(true);
453 dialog
->setButtonGuiItem(KDialog::Yes
, KStandardGuiItem::quit());
454 dialog
->setButtonGuiItem(KDialog::No
, KGuiItem(i18n("C&lose Current Tab"), KIcon("tab-close")));
455 dialog
->setButtonGuiItem(KDialog::Cancel
, KStandardGuiItem::cancel());
456 dialog
->setDefaultButton(KDialog::Yes
);
458 bool doNotAskAgainCheckboxResult
= false;
460 const int result
= KMessageBox::createKMessageBox(dialog
,
461 QMessageBox::Warning
,
462 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
464 i18n("Do not ask again"),
465 &doNotAskAgainCheckboxResult
,
466 KMessageBox::Notify
);
468 if (doNotAskAgainCheckboxResult
) {
469 generalSettings
->setConfirmClosingMultipleTabs(false);
477 // Close only the current tab
485 generalSettings
->setFirstRun(false);
489 KXmlGuiWindow::closeEvent(event
);
492 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
494 const int tabCount
= m_viewTab
.count();
495 group
.writeEntry("Tab Count", tabCount
);
496 group
.writeEntry("Active Tab Index", m_tabBar
->currentIndex());
498 for (int i
= 0; i
< tabCount
; ++i
) {
499 const DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
500 group
.writeEntry(tabProperty("Primary URL", i
), cont
->url().url());
501 group
.writeEntry(tabProperty("Primary Editable", i
), cont
->isUrlEditable());
503 cont
= m_viewTab
[i
].secondaryView
;
505 group
.writeEntry(tabProperty("Secondary URL", i
), cont
->url().url());
506 group
.writeEntry(tabProperty("Secondary Editable", i
), cont
->isUrlEditable());
511 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
513 const int tabCount
= group
.readEntry("Tab Count", 1);
514 for (int i
= 0; i
< tabCount
; ++i
) {
515 DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
517 cont
->setUrl(group
.readEntry(tabProperty("Primary URL", i
)));
518 const bool editable
= group
.readEntry(tabProperty("Primary Editable", i
), false);
519 cont
->urlNavigator()->setUrlEditable(editable
);
521 cont
= m_viewTab
[i
].secondaryView
;
522 const QString secondaryUrl
= group
.readEntry(tabProperty("Secondary URL", i
));
523 if (!secondaryUrl
.isEmpty()) {
525 // a secondary view should be shown, but no one is available
526 // currently -> create a new view
528 cont
= m_viewTab
[i
].secondaryView
;
532 cont
->setUrl(secondaryUrl
);
533 const bool editable
= group
.readEntry(tabProperty("Secondary Editable", i
), false);
534 cont
->urlNavigator()->setUrlEditable(editable
);
535 } else if (cont
!= 0) {
536 // no secondary view should be shown, but the default setting shows
537 // one already -> close the view
541 // openNewTab() needs to be called only tabCount - 1 times
542 if (i
!= tabCount
- 1) {
547 const int index
= group
.readEntry("Active Tab Index", 0);
548 m_tabBar
->setCurrentIndex(index
);
551 void DolphinMainWindow::updateNewMenu()
553 m_newMenu
->slotCheckUpToDate();
554 m_newMenu
->setPopupFiles(activeViewContainer()->url());
557 void DolphinMainWindow::createDirectory()
559 m_newMenu
->setPopupFiles(activeViewContainer()->url());
560 m_newMenu
->createDirectory();
563 void DolphinMainWindow::quit()
568 void DolphinMainWindow::showErrorMessage(const QString
& message
)
570 if (!message
.isEmpty()) {
571 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
572 statusBar
->setMessage(message
, DolphinStatusBar::Error
);
576 void DolphinMainWindow::slotUndoAvailable(bool available
)
578 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
579 if (undoAction
!= 0) {
580 undoAction
->setEnabled(available
);
584 void DolphinMainWindow::restoreClosedTab(QAction
* action
)
586 if (action
->data().toBool()) {
587 // clear all actions except the "Empty Recently Closed Tabs"
588 // action and the separator
589 QList
<QAction
*> actions
= m_recentTabsMenu
->menu()->actions();
590 const int count
= actions
.size();
591 for (int i
= 2; i
< count
; ++i
) {
592 m_recentTabsMenu
->menu()->removeAction(actions
.at(i
));
595 const ClosedTab closedTab
= action
->data().value
<ClosedTab
>();
596 openNewTab(closedTab
.primaryUrl
);
597 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
599 if (closedTab
.isSplit
) {
600 // create secondary view
602 m_viewTab
[m_tabIndex
].secondaryView
->setUrl(closedTab
.secondaryUrl
);
605 m_recentTabsMenu
->removeAction(action
);
608 if (m_recentTabsMenu
->menu()->actions().count() == 2) {
609 m_recentTabsMenu
->setEnabled(false);
613 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
615 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
616 if (undoAction
!= 0) {
617 undoAction
->setText(text
);
621 void DolphinMainWindow::undo()
624 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
625 KIO::FileUndoManager::self()->undo();
628 void DolphinMainWindow::cut()
630 m_activeViewContainer
->view()->cutSelectedItems();
633 void DolphinMainWindow::copy()
635 m_activeViewContainer
->view()->copySelectedItems();
638 void DolphinMainWindow::paste()
640 m_activeViewContainer
->view()->paste();
643 void DolphinMainWindow::updatePasteAction()
645 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
646 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
647 pasteAction
->setEnabled(pasteInfo
.first
);
648 pasteAction
->setText(pasteInfo
.second
);
651 void DolphinMainWindow::selectAll()
655 // if the URL navigator is editable and focused, select the whole
656 // URL instead of all items of the view
658 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
659 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit(); // krazy:exclude=qclasses
660 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
661 lineEdit
->hasFocus();
663 lineEdit
->selectAll();
665 m_activeViewContainer
->view()->selectAll();
669 void DolphinMainWindow::invertSelection()
672 m_activeViewContainer
->view()->invertSelection();
675 void DolphinMainWindow::toggleSplitView()
677 if (m_viewTab
[m_tabIndex
].secondaryView
== 0) {
678 createSecondaryView(m_tabIndex
);
679 setActiveViewContainer(m_viewTab
[m_tabIndex
].secondaryView
);
680 } else if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
681 // remove secondary view
682 m_viewTab
[m_tabIndex
].secondaryView
->close();
683 m_viewTab
[m_tabIndex
].secondaryView
->deleteLater();
684 m_viewTab
[m_tabIndex
].secondaryView
= 0;
686 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
688 // The primary view is active and should be closed. Hence from a users point of view
689 // the content of the secondary view should be moved to the primary view.
690 // From an implementation point of view it is more efficient to close
691 // the primary view and exchange the internal pointers afterwards.
693 m_viewTab
[m_tabIndex
].primaryView
->close();
694 m_viewTab
[m_tabIndex
].primaryView
->deleteLater();
695 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
696 m_viewTab
[m_tabIndex
].secondaryView
= 0;
698 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
704 void DolphinMainWindow::reloadView()
707 m_activeViewContainer
->view()->reload();
710 void DolphinMainWindow::stopLoading()
714 void DolphinMainWindow::toggleFilterBarVisibility(bool show
)
716 m_activeViewContainer
->showFilterBar(show
);
719 void DolphinMainWindow::toggleEditLocation()
723 QAction
* action
= actionCollection()->action("editable_location");
724 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
725 urlNavigator
->setUrlEditable(action
->isChecked());
728 void DolphinMainWindow::replaceLocation()
730 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
731 navigator
->setUrlEditable(true);
732 navigator
->setFocus();
734 // select the whole text of the combo box editor
735 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit(); // krazy:exclude=qclasses
736 const QString text
= lineEdit
->text();
737 lineEdit
->setSelection(0, text
.length());
740 void DolphinMainWindow::goBack()
743 m_activeViewContainer
->urlNavigator()->goBack();
746 void DolphinMainWindow::goForward()
749 m_activeViewContainer
->urlNavigator()->goForward();
752 void DolphinMainWindow::goUp()
755 m_activeViewContainer
->urlNavigator()->goUp();
758 void DolphinMainWindow::goBack(Qt::MouseButtons buttons
)
760 // The default case (left button pressed) is handled in goBack().
761 if (buttons
== Qt::MidButton
) {
762 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
763 openNewTab(urlNavigator
->historyUrl(urlNavigator
->historyIndex() + 1));
767 void DolphinMainWindow::goForward(Qt::MouseButtons buttons
)
769 // The default case (left button pressed) is handled in goForward().
770 if (buttons
== Qt::MidButton
) {
771 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
772 openNewTab(urlNavigator
->historyUrl(urlNavigator
->historyIndex() - 1));
776 void DolphinMainWindow::goUp(Qt::MouseButtons buttons
)
778 // The default case (left button pressed) is handled in goUp().
779 if (buttons
== Qt::MidButton
) {
780 openNewTab(activeViewContainer()->url().upUrl());
784 void DolphinMainWindow::goHome()
787 m_activeViewContainer
->urlNavigator()->goHome();
790 void DolphinMainWindow::compareFiles()
792 // The method is only invoked if exactly 2 files have
793 // been selected. The selected files may be:
794 // - both in the primary view
795 // - both in the secondary view
796 // - one in the primary view and the other in the secondary
798 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
802 KUrl::List urls
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedUrls();
804 switch (urls
.count()) {
806 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
!= 0);
807 urls
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedUrls();
808 Q_ASSERT(urls
.count() == 2);
816 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
!= 0);
817 urls
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedUrls();
818 Q_ASSERT(urls
.count() == 1);
830 // may not happen: compareFiles may only get invoked if 2
831 // files are selected
836 QString
command("kompare -c \"");
837 command
.append(urlA
.pathOrUrl());
838 command
.append("\" \"");
839 command
.append(urlB
.pathOrUrl());
840 command
.append('\"');
841 KRun::runCommand(command
, "Kompare", "kompare", this);
844 void DolphinMainWindow::toggleShowMenuBar()
846 const bool visible
= menuBar()->isVisible();
847 menuBar()->setVisible(!visible
);
850 void DolphinMainWindow::openTerminal()
852 QString
dir(QDir::homePath());
854 // If the given directory is not local, it can still be the URL of an
855 // ioslave using UDS_LOCAL_PATH which to be converted first.
856 KUrl url
= KIO::NetAccess::mostLocalUrl(m_activeViewContainer
->url(), this);
858 //If the URL is local after the above conversion, set the directory.
859 if (url
.isLocalFile()) {
860 dir
= url
.toLocalFile();
863 KToolInvocation::invokeTerminal(QString(), dir
);
866 void DolphinMainWindow::editSettings()
868 if (m_settingsDialog
== 0) {
869 const KUrl
& url
= activeViewContainer()->url();
870 m_settingsDialog
= new DolphinSettingsDialog(url
, this);
871 m_settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
872 m_settingsDialog
->show();
874 m_settingsDialog
->raise();
878 void DolphinMainWindow::setActiveTab(int index
)
880 Q_ASSERT(index
>= 0);
881 Q_ASSERT(index
< m_viewTab
.count());
882 if (index
== m_tabIndex
) {
886 // hide current tab content
887 ViewTab
& hiddenTab
= m_viewTab
[m_tabIndex
];
888 hiddenTab
.isPrimaryViewActive
= hiddenTab
.primaryView
->isActive();
889 hiddenTab
.primaryView
->setActive(false);
890 if (hiddenTab
.secondaryView
!= 0) {
891 hiddenTab
.secondaryView
->setActive(false);
893 QSplitter
* splitter
= m_viewTab
[m_tabIndex
].splitter
;
895 m_centralWidgetLayout
->removeWidget(splitter
);
897 // show active tab content
900 ViewTab
& viewTab
= m_viewTab
[index
];
901 m_centralWidgetLayout
->addWidget(viewTab
.splitter
, 1);
902 viewTab
.primaryView
->show();
903 if (viewTab
.secondaryView
!= 0) {
904 viewTab
.secondaryView
->show();
906 viewTab
.splitter
->show();
908 setActiveViewContainer(viewTab
.isPrimaryViewActive
? viewTab
.primaryView
:
909 viewTab
.secondaryView
);
912 void DolphinMainWindow::closeTab()
914 closeTab(m_tabBar
->currentIndex());
917 void DolphinMainWindow::closeTab(int index
)
919 Q_ASSERT(index
>= 0);
920 Q_ASSERT(index
< m_viewTab
.count());
921 if (m_viewTab
.count() == 1) {
922 // the last tab may never get closed
926 if (index
== m_tabIndex
) {
927 // The tab that should be closed is the active tab. Activate the
928 // previous tab before closing the tab.
929 m_tabBar
->setCurrentIndex((index
> 0) ? index
- 1 : 1);
931 rememberClosedTab(index
);
934 m_viewTab
[index
].primaryView
->deleteLater();
935 if (m_viewTab
[index
].secondaryView
!= 0) {
936 m_viewTab
[index
].secondaryView
->deleteLater();
938 m_viewTab
[index
].splitter
->deleteLater();
939 m_viewTab
.erase(m_viewTab
.begin() + index
);
941 m_tabBar
->blockSignals(true);
942 m_tabBar
->removeTab(index
);
944 if (m_tabIndex
> index
) {
946 Q_ASSERT(m_tabIndex
>= 0);
949 // if only one tab is left, also remove the tab entry so that
950 // closing the last tab is not possible
951 if (m_viewTab
.count() == 1) {
952 m_tabBar
->removeTab(0);
953 actionCollection()->action("close_tab")->setEnabled(false);
955 m_tabBar
->blockSignals(false);
959 void DolphinMainWindow::openTabContextMenu(int index
, const QPoint
& pos
)
963 QAction
* newTabAction
= menu
.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab"));
964 newTabAction
->setShortcut(actionCollection()->action("new_tab")->shortcut());
966 QAction
* closeOtherTabsAction
= menu
.addAction(KIcon("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs"));
968 QAction
* closeTabAction
= menu
.addAction(KIcon("tab-close"), i18nc("@action:inmenu", "Close Tab"));
969 closeTabAction
->setShortcut(actionCollection()->action("close_tab")->shortcut());
970 QAction
* selectedAction
= menu
.exec(pos
);
971 if (selectedAction
== newTabAction
) {
972 const ViewTab
& tab
= m_viewTab
[index
];
973 Q_ASSERT(tab
.primaryView
!= 0);
974 const KUrl url
= (tab
.secondaryView
!= 0) && tab
.secondaryView
->isActive() ?
975 tab
.secondaryView
->url() : tab
.primaryView
->url();
977 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
978 } else if (selectedAction
== closeOtherTabsAction
) {
979 const int count
= m_tabBar
->count();
980 for (int i
= 0; i
< index
; ++i
) {
983 for (int i
= index
+ 1; i
< count
; ++i
) {
986 } else if (selectedAction
== closeTabAction
) {
991 void DolphinMainWindow::handlePlacesClick(const KUrl
& url
, Qt::MouseButtons buttons
)
993 if (buttons
& Qt::MidButton
) {
995 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
1001 void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent
* event
, bool& canDecode
)
1003 canDecode
= KUrl::List::canDecode(event
->mimeData());
1006 void DolphinMainWindow::searchItems(const KUrl
& url
)
1008 m_activeViewContainer
->setUrl(url
);
1010 // The Nepomuk IO-slave does not provide any progress information. Give
1011 // an immediate hint to the user that a searching is done:
1012 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
1013 statusBar
->setProgressText(i18nc("@info", "Searching..."));
1014 statusBar
->setProgress(-1);
1017 void DolphinMainWindow::slotTabMoved(int from
, int to
)
1019 m_viewTab
.move(from
, to
);
1020 m_tabIndex
= m_tabBar
->currentIndex();
1023 void DolphinMainWindow::showSearchOptions()
1026 m_searchOptionsConfigurator
->show();
1030 void DolphinMainWindow::init()
1032 DolphinSettings
& settings
= DolphinSettings::instance();
1034 // Check whether Dolphin runs the first time. If yes then
1035 // a proper default window size is given at the end of DolphinMainWindow::init().
1036 GeneralSettings
* generalSettings
= settings
.generalSettings();
1037 const bool firstRun
= generalSettings
->firstRun();
1039 generalSettings
->setViewPropsTimestamp(QDateTime::currentDateTime());
1042 setAcceptDrops(true);
1044 m_viewTab
[m_tabIndex
].splitter
= new QSplitter(this);
1045 m_viewTab
[m_tabIndex
].splitter
->setChildrenCollapsible(false);
1049 const KUrl
& homeUrl
= generalSettings
->homeUrl();
1050 setUrlAsCaption(homeUrl
);
1051 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
1052 connect(m_actionHandler
, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
1053 connect(m_actionHandler
, SIGNAL(createDirectory()), SLOT(createDirectory()));
1054 ViewProperties
props(homeUrl
);
1055 m_viewTab
[m_tabIndex
].primaryView
= new DolphinViewContainer(this,
1056 m_viewTab
[m_tabIndex
].splitter
,
1059 m_activeViewContainer
= m_viewTab
[m_tabIndex
].primaryView
;
1060 connectViewSignals(m_activeViewContainer
);
1061 DolphinView
* view
= m_activeViewContainer
->view();
1063 m_activeViewContainer
->show();
1064 m_actionHandler
->setCurrentView(view
);
1066 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
1067 connect(this, SIGNAL(urlChanged(const KUrl
&)),
1068 m_remoteEncoding
, SLOT(slotAboutToOpenUrl()));
1071 m_searchOptionsConfigurator
= new DolphinSearchOptionsConfigurator(this);
1072 m_searchOptionsConfigurator
->hide();
1075 m_tabBar
= new KTabBar(this);
1076 m_tabBar
->setMovable(true);
1077 m_tabBar
->setTabsClosable(true);
1078 connect(m_tabBar
, SIGNAL(currentChanged(int)),
1079 this, SLOT(setActiveTab(int)));
1080 connect(m_tabBar
, SIGNAL(tabCloseRequested(int)),
1081 this, SLOT(closeTab(int)));
1082 connect(m_tabBar
, SIGNAL(contextMenu(int, const QPoint
&)),
1083 this, SLOT(openTabContextMenu(int, const QPoint
&)));
1084 connect(m_tabBar
, SIGNAL(newTabRequest()),
1085 this, SLOT(openNewTab()));
1086 connect(m_tabBar
, SIGNAL(testCanDecode(const QDragMoveEvent
*, bool&)),
1087 this, SLOT(slotTestCanDecode(const QDragMoveEvent
*, bool&)));
1088 connect(m_tabBar
, SIGNAL(wheelDelta(int)),
1089 this, SLOT(slotWheelMoved(int)));
1090 connect(m_tabBar
, SIGNAL(mouseMiddleClick(int)),
1091 this, SLOT(closeTab(int)));
1092 connect(m_tabBar
, SIGNAL(tabMoved(int, int)),
1093 this, SLOT(slotTabMoved(int, int)));
1095 m_tabBar
->blockSignals(true); // signals get unblocked after at least 2 tabs are open
1097 QWidget
* centralWidget
= new QWidget(this);
1098 m_centralWidgetLayout
= new QVBoxLayout(centralWidget
);
1099 m_centralWidgetLayout
->setSpacing(0);
1100 m_centralWidgetLayout
->setMargin(0);
1102 m_centralWidgetLayout
->addWidget(m_searchOptionsConfigurator
);
1104 m_centralWidgetLayout
->addWidget(m_tabBar
);
1105 m_centralWidgetLayout
->addWidget(m_viewTab
[m_tabIndex
].splitter
, 1);
1107 setCentralWidget(centralWidget
);
1109 emit
urlChanged(homeUrl
);
1111 setupGUI(Keys
| Save
| Create
| ToolBar
);
1113 m_searchBox
->setParent(toolBar("searchToolBar"));
1114 m_searchBox
->show();
1115 connect(m_searchBox
, SIGNAL(requestSearchOptions()),
1116 this, SLOT(showSearchOptions()));
1118 stateChanged("new_file");
1120 QClipboard
* clipboard
= QApplication::clipboard();
1121 connect(clipboard
, SIGNAL(dataChanged()),
1122 this, SLOT(updatePasteAction()));
1123 updatePasteAction();
1126 if (generalSettings
->splitView()) {
1129 updateViewActions();
1131 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1132 showFilterBarAction
->setChecked(generalSettings
->filterBar());
1135 // assure a proper default size if Dolphin runs the first time
1139 m_showMenuBar
->setChecked(!menuBar()->isHidden()); // workaround for bug #171080
1142 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer
* viewContainer
)
1144 Q_ASSERT(viewContainer
!= 0);
1145 Q_ASSERT((viewContainer
== m_viewTab
[m_tabIndex
].primaryView
) ||
1146 (viewContainer
== m_viewTab
[m_tabIndex
].secondaryView
));
1147 if (m_activeViewContainer
== viewContainer
) {
1151 m_activeViewContainer
->setActive(false);
1152 m_activeViewContainer
= viewContainer
;
1154 // Activating the view container might trigger a recursive setActiveViewContainer() call
1155 // inside DolphinMainWindow::toggleActiveView() when having a split view. Temporary
1156 // disconnect the activated() signal in this case:
1157 disconnect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1158 m_activeViewContainer
->setActive(true);
1159 connect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1161 m_actionHandler
->setCurrentView(viewContainer
->view());
1164 updateEditActions();
1165 updateViewActions();
1168 const KUrl
& url
= m_activeViewContainer
->url();
1169 setUrlAsCaption(url
);
1170 if (m_viewTab
.count() > 1 && m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
1171 m_tabBar
->setTabText(m_tabIndex
, tabName(url
));
1172 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(KMimeType::iconNameForUrl(url
)));
1175 emit
urlChanged(url
);
1178 void DolphinMainWindow::setupActions()
1180 // setup 'File' menu
1181 m_newMenu
= new DolphinNewMenu(this, this);
1182 KMenu
* menu
= m_newMenu
->menu();
1183 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1184 menu
->setIcon(KIcon("document-new"));
1185 connect(menu
, SIGNAL(aboutToShow()),
1186 this, SLOT(updateNewMenu()));
1188 KAction
* newWindow
= actionCollection()->addAction("new_window");
1189 newWindow
->setIcon(KIcon("window-new"));
1190 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1191 newWindow
->setShortcut(Qt::CTRL
| Qt::Key_N
);
1192 connect(newWindow
, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1194 KAction
* newTab
= actionCollection()->addAction("new_tab");
1195 newTab
->setIcon(KIcon("tab-new"));
1196 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1197 newTab
->setShortcut(KShortcut(Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
));
1198 connect(newTab
, SIGNAL(triggered()), this, SLOT(openNewTab()));
1200 KAction
* closeTab
= actionCollection()->addAction("close_tab");
1201 closeTab
->setIcon(KIcon("tab-close"));
1202 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1203 closeTab
->setShortcut(Qt::CTRL
| Qt::Key_W
);
1204 closeTab
->setEnabled(false);
1205 connect(closeTab
, SIGNAL(triggered()), this, SLOT(closeTab()));
1207 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1209 // setup 'Edit' menu
1210 KStandardAction::undo(this,
1212 actionCollection());
1214 // need to remove shift+del from cut action, else the shortcut for deletejob
1216 KAction
* cut
= KStandardAction::cut(this, SLOT(cut()), actionCollection());
1217 KShortcut cutShortcut
= cut
->shortcut();
1218 cutShortcut
.remove(Qt::SHIFT
+ Qt::Key_Delete
, KShortcut::KeepEmpty
);
1219 cut
->setShortcut(cutShortcut
);
1220 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1221 KAction
* paste
= KStandardAction::paste(this, SLOT(paste()), actionCollection());
1222 // The text of the paste-action is modified dynamically by Dolphin
1223 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1224 // due to the long text, the text "Paste" is used:
1225 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1227 KAction
* selectAll
= actionCollection()->addAction("select_all");
1228 selectAll
->setText(i18nc("@action:inmenu Edit", "Select All"));
1229 selectAll
->setShortcut(Qt::CTRL
+ Qt::Key_A
);
1230 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
1232 KAction
* invertSelection
= actionCollection()->addAction("invert_selection");
1233 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1234 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1235 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
1237 // setup 'View' menu
1238 // (note that most of it is set up in DolphinViewActionHandler)
1240 KAction
* split
= actionCollection()->addAction("split_view");
1241 split
->setShortcut(Qt::Key_F3
);
1242 updateSplitAction();
1243 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1245 KAction
* reload
= actionCollection()->addAction("reload");
1246 reload
->setText(i18nc("@action:inmenu View", "Reload"));
1247 reload
->setShortcut(Qt::Key_F5
);
1248 reload
->setIcon(KIcon("view-refresh"));
1249 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
1251 KAction
* stop
= actionCollection()->addAction("stop");
1252 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1253 stop
->setToolTip(i18nc("@info", "Stop loading"));
1254 stop
->setIcon(KIcon("process-stop"));
1255 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
1257 KToggleAction
* showFullLocation
= actionCollection()->add
<KToggleAction
>("editable_location");
1258 showFullLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1259 showFullLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
1260 connect(showFullLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1262 KAction
* replaceLocation
= actionCollection()->addAction("replace_location");
1263 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1264 replaceLocation
->setShortcut(Qt::Key_F6
);
1265 connect(replaceLocation
, SIGNAL(triggered()), this, SLOT(replaceLocation()));
1268 KAction
* backAction
= KStandardAction::back(this, SLOT(goBack()), actionCollection());
1269 connect(backAction
, SIGNAL(triggered(Qt::MouseButtons
, Qt::KeyboardModifiers
)), this, SLOT(goBack(Qt::MouseButtons
)));
1270 KShortcut backShortcut
= backAction
->shortcut();
1271 backShortcut
.setAlternate(Qt::Key_Backspace
);
1272 backAction
->setShortcut(backShortcut
);
1274 m_recentTabsMenu
= new KActionMenu(i18n("Recently Closed Tabs"), this);
1275 m_recentTabsMenu
->setIcon(KIcon("edit-undo"));
1276 actionCollection()->addAction("closed_tabs", m_recentTabsMenu
);
1277 connect(m_recentTabsMenu
->menu(), SIGNAL(triggered(QAction
*)),
1278 this, SLOT(restoreClosedTab(QAction
*)));
1280 QAction
* action
= new QAction("Empty Recently Closed Tabs", m_recentTabsMenu
);
1281 action
->setIcon(KIcon("edit-clear-list"));
1282 action
->setData(QVariant::fromValue(true));
1283 m_recentTabsMenu
->addAction(action
);
1284 m_recentTabsMenu
->addSeparator();
1285 m_recentTabsMenu
->setEnabled(false);
1287 KAction
* forwardAction
= KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1288 connect(forwardAction
, SIGNAL(triggered(Qt::MouseButtons
, Qt::KeyboardModifiers
)), this, SLOT(goForward(Qt::MouseButtons
)));
1290 KAction
* upAction
= KStandardAction::up(this, SLOT(goUp()), actionCollection());
1291 connect(upAction
, SIGNAL(triggered(Qt::MouseButtons
, Qt::KeyboardModifiers
)), this, SLOT(goUp(Qt::MouseButtons
)));
1293 KStandardAction::home(this, SLOT(goHome()), actionCollection());
1295 // setup 'Tools' menu
1296 KToggleAction
* showSearchBar
= actionCollection()->add
<KToggleAction
>("show_search_bar");
1297 showSearchBar
->setText(i18nc("@action:inmenu Tools", "Show Search Bar"));
1298 showSearchBar
->setShortcut(Qt::CTRL
| Qt::Key_S
);
1299 connect(showSearchBar
, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
1301 KToggleAction
* showFilterBar
= actionCollection()->add
<KToggleAction
>("show_filter_bar");
1302 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1303 showFilterBar
->setIcon(KIcon("view-filter"));
1304 showFilterBar
->setShortcut(Qt::CTRL
| Qt::Key_I
);
1305 connect(showFilterBar
, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
1307 KAction
* compareFiles
= actionCollection()->addAction("compare_files");
1308 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1309 compareFiles
->setIcon(KIcon("kompare"));
1310 compareFiles
->setEnabled(false);
1311 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
1313 KAction
* openTerminal
= actionCollection()->addAction("open_terminal");
1314 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1315 openTerminal
->setIcon(KIcon("utilities-terminal"));
1316 openTerminal
->setShortcut(Qt::SHIFT
| Qt::Key_F4
);
1317 connect(openTerminal
, SIGNAL(triggered()), this, SLOT(openTerminal()));
1319 // setup 'Settings' menu
1320 m_showMenuBar
= KStandardAction::showMenubar(this, SLOT(toggleShowMenuBar()), actionCollection());
1321 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1323 // not in menu actions
1324 KAction
* activateNextTab
= actionCollection()->addAction("activate_next_tab");
1325 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1326 connect(activateNextTab
, SIGNAL(triggered()), SLOT(activateNextTab()));
1327 activateNextTab
->setShortcuts(QApplication::isRightToLeft() ? KStandardShortcut::tabPrev() :
1328 KStandardShortcut::tabNext());
1330 KAction
* activatePrevTab
= actionCollection()->addAction("activate_prev_tab");
1331 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1332 connect(activatePrevTab
, SIGNAL(triggered()), SLOT(activatePrevTab()));
1333 activatePrevTab
->setShortcuts(QApplication::isRightToLeft() ? KStandardShortcut::tabNext() :
1334 KStandardShortcut::tabPrev());
1337 KAction
* openInNewTab
= actionCollection()->addAction("open_in_new_tab");
1338 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1339 openInNewTab
->setIcon(KIcon("tab-new"));
1340 connect(openInNewTab
, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1342 KAction
* openInNewWindow
= actionCollection()->addAction("open_in_new_window");
1343 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1344 openInNewWindow
->setIcon(KIcon("window-new"));
1345 connect(openInNewWindow
, SIGNAL(triggered()), this, SLOT(openInNewWindow()));
1348 m_searchBox
= new DolphinSearchBox(this);
1349 connect(m_searchBox
, SIGNAL(search(KUrl
)), this, SLOT(searchItems(KUrl
)));
1351 KAction
* search
= new KAction(this);
1352 actionCollection()->addAction("search_bar", search
);
1353 search
->setText(i18nc("@action:inmenu", "Search Bar"));
1354 search
->setDefaultWidget(m_searchBox
);
1355 search
->setShortcutConfigurable(false);
1358 void DolphinMainWindow::setupDockWidgets()
1360 // setup "Information"
1361 QDockWidget
* infoDock
= new QDockWidget(i18nc("@title:window", "Information"));
1362 infoDock
->setObjectName("infoDock");
1363 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1364 Panel
* infoPanel
= new InformationPanel(infoDock
);
1365 infoDock
->setWidget(infoPanel
);
1367 QAction
* infoAction
= infoDock
->toggleViewAction();
1368 infoAction
->setText(i18nc("@title:window", "Information"));
1369 infoAction
->setShortcut(Qt::Key_F11
);
1370 infoAction
->setIcon(KIcon("dialog-information"));
1371 actionCollection()->addAction("show_info_panel", infoDock
->toggleViewAction());
1373 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1374 connect(this, SIGNAL(urlChanged(KUrl
)),
1375 infoPanel
, SLOT(setUrl(KUrl
)));
1376 connect(this, SIGNAL(selectionChanged(KFileItemList
)),
1377 infoPanel
, SLOT(setSelection(KFileItemList
)));
1378 connect(this, SIGNAL(requestItemInfo(KFileItem
)),
1379 infoPanel
, SLOT(requestDelayedItemInfo(KFileItem
)));
1382 QDockWidget
* foldersDock
= new QDockWidget(i18nc("@title:window", "Folders"));
1383 foldersDock
->setObjectName("foldersDock");
1384 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1385 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1386 foldersDock
->setWidget(foldersPanel
);
1388 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1389 foldersAction
->setText(i18nc("@title:window", "Folders"));
1390 foldersAction
->setShortcut(Qt::Key_F7
);
1391 foldersAction
->setIcon(KIcon("folder"));
1392 actionCollection()->addAction("show_folders_panel", foldersDock
->toggleViewAction());
1394 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1395 connect(this, SIGNAL(urlChanged(KUrl
)),
1396 foldersPanel
, SLOT(setUrl(KUrl
)));
1397 connect(foldersPanel
, SIGNAL(changeUrl(KUrl
, Qt::MouseButtons
)),
1398 this, SLOT(handlePlacesClick(KUrl
, Qt::MouseButtons
)));
1399 connect(foldersPanel
, SIGNAL(changeSelection(KFileItemList
)),
1400 this, SLOT(changeSelection(KFileItemList
)));
1404 QDockWidget
* terminalDock
= new QDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1405 terminalDock
->setObjectName("terminalDock");
1406 terminalDock
->setAllowedAreas(Qt::TopDockWidgetArea
| Qt::BottomDockWidgetArea
);
1407 Panel
* terminalPanel
= new TerminalPanel(terminalDock
);
1408 terminalDock
->setWidget(terminalPanel
);
1410 connect(terminalPanel
, SIGNAL(hideTerminalPanel()), terminalDock
, SLOT(hide()));
1412 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1413 terminalAction
->setText(i18nc("@title:window Shell terminal", "Terminal"));
1414 terminalAction
->setShortcut(Qt::Key_F4
);
1415 terminalAction
->setIcon(KIcon("utilities-terminal"));
1416 actionCollection()->addAction("show_terminal_panel", terminalDock
->toggleViewAction());
1418 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1419 connect(this, SIGNAL(urlChanged(KUrl
)),
1420 terminalPanel
, SLOT(setUrl(KUrl
)));
1423 const bool firstRun
= DolphinSettings::instance().generalSettings()->firstRun();
1425 foldersDock
->hide();
1427 terminalDock
->hide();
1431 QDockWidget
* placesDock
= new QDockWidget(i18nc("@title:window", "Places"));
1432 placesDock
->setObjectName("placesDock");
1433 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1435 PlacesPanel
* placesPanel
= new PlacesPanel(placesDock
);
1436 placesDock
->setWidget(placesPanel
);
1437 placesPanel
->setModel(DolphinSettings::instance().placesModel());
1438 placesPanel
->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff
);
1440 QAction
* placesAction
= placesDock
->toggleViewAction();
1441 placesAction
->setText(i18nc("@title:window", "Places"));
1442 placesAction
->setShortcut(Qt::Key_F9
);
1443 placesAction
->setIcon(KIcon("bookmarks"));
1444 actionCollection()->addAction("show_places_panel", placesDock
->toggleViewAction());
1446 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1447 connect(placesPanel
, SIGNAL(urlChanged(KUrl
, Qt::MouseButtons
)),
1448 this, SLOT(handlePlacesClick(KUrl
, Qt::MouseButtons
)));
1449 connect(this, SIGNAL(urlChanged(KUrl
)),
1450 placesPanel
, SLOT(setUrl(KUrl
)));
1453 void DolphinMainWindow::updateEditActions()
1455 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1456 if (list
.isEmpty()) {
1457 stateChanged("has_no_selection");
1459 stateChanged("has_selection");
1461 KActionCollection
* col
= actionCollection();
1462 QAction
* renameAction
= col
->action("rename");
1463 QAction
* moveToTrashAction
= col
->action("move_to_trash");
1464 QAction
* deleteAction
= col
->action("delete");
1465 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
1466 QAction
* deleteWithTrashShortcut
= col
->action("delete_shortcut"); // see DolphinViewActionHandler
1468 KFileItemListProperties
capabilities(list
);
1469 const bool enableMoveToTrash
= capabilities
.isLocal() && capabilities
.supportsMoving();
1471 renameAction
->setEnabled(capabilities
.supportsMoving());
1472 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1473 deleteAction
->setEnabled(capabilities
.supportsDeleting());
1474 deleteWithTrashShortcut
->setEnabled(capabilities
.supportsDeleting() && !enableMoveToTrash
);
1475 cutAction
->setEnabled(capabilities
.supportsMoving());
1477 updatePasteAction();
1480 void DolphinMainWindow::updateViewActions()
1482 m_actionHandler
->updateViewActions();
1484 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1485 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
1487 updateSplitAction();
1489 QAction
* editableLocactionAction
= actionCollection()->action("editable_location");
1490 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
1491 editableLocactionAction
->setChecked(urlNavigator
->isUrlEditable());
1494 void DolphinMainWindow::updateGoActions()
1496 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
1497 const KUrl
& currentUrl
= m_activeViewContainer
->url();
1498 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
1501 void DolphinMainWindow::rememberClosedTab(int index
)
1503 KMenu
* tabsMenu
= m_recentTabsMenu
->menu();
1505 const QString primaryPath
= m_viewTab
[index
].primaryView
->url().path();
1506 const QString iconName
= KMimeType::iconNameForUrl(primaryPath
);
1508 QAction
* action
= new QAction(squeezedText(primaryPath
), tabsMenu
);
1510 ClosedTab closedTab
;
1511 closedTab
.primaryUrl
= m_viewTab
[index
].primaryView
->url();
1513 if (m_viewTab
[index
].secondaryView
!= 0) {
1514 closedTab
.secondaryUrl
= m_viewTab
[index
].secondaryView
->url();
1515 closedTab
.isSplit
= true;
1517 closedTab
.isSplit
= false;
1520 action
->setData(QVariant::fromValue(closedTab
));
1521 action
->setIcon(KIcon(iconName
));
1523 // add the closed tab menu entry after the separator and
1524 // "Empty Recently Closed Tabs" entry
1525 if (tabsMenu
->actions().size() == 2) {
1526 tabsMenu
->addAction(action
);
1528 tabsMenu
->insertAction(tabsMenu
->actions().at(2), action
);
1531 // assure that only up to 8 closed tabs are shown in the menu
1532 if (tabsMenu
->actions().size() > 8) {
1533 tabsMenu
->removeAction(tabsMenu
->actions().last());
1535 actionCollection()->action("closed_tabs")->setEnabled(true);
1536 KAcceleratorManager::manage(tabsMenu
);
1539 void DolphinMainWindow::clearStatusBar()
1541 m_activeViewContainer
->statusBar()->clear();
1544 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
1546 connect(container
, SIGNAL(showFilterBarChanged(bool)),
1547 this, SLOT(updateFilterBarAction(bool)));
1549 DolphinView
* view
= container
->view();
1550 connect(view
, SIGNAL(selectionChanged(KFileItemList
)),
1551 this, SLOT(slotSelectionChanged(KFileItemList
)));
1552 connect(view
, SIGNAL(requestItemInfo(KFileItem
)),
1553 this, SLOT(slotRequestItemInfo(KFileItem
)));
1554 connect(view
, SIGNAL(activated()),
1555 this, SLOT(toggleActiveView()));
1556 connect(view
, SIGNAL(tabRequested(const KUrl
&)),
1557 this, SLOT(openNewTab(const KUrl
&)));
1559 const KUrlNavigator
* navigator
= container
->urlNavigator();
1560 connect(navigator
, SIGNAL(urlChanged(const KUrl
&)),
1561 this, SLOT(changeUrl(const KUrl
&)));
1562 connect(navigator
, SIGNAL(historyChanged()),
1563 this, SLOT(updateHistory()));
1564 connect(navigator
, SIGNAL(editableStateChanged(bool)),
1565 this, SLOT(slotEditableStateChanged(bool)));
1568 void DolphinMainWindow::updateSplitAction()
1570 QAction
* splitAction
= actionCollection()->action("split_view");
1571 if (m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
1572 if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
1573 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
1574 splitAction
->setToolTip(i18nc("@info", "Close right view"));
1575 splitAction
->setIcon(KIcon("view-right-close"));
1577 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
1578 splitAction
->setToolTip(i18nc("@info", "Close left view"));
1579 splitAction
->setIcon(KIcon("view-left-close"));
1582 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
1583 splitAction
->setToolTip(i18nc("@info", "Split view"));
1584 splitAction
->setIcon(KIcon("view-right-new"));
1588 QString
DolphinMainWindow::tabName(const KUrl
& url
) const
1591 if (url
.equals(KUrl("file:///"))) {
1594 name
= url
.fileName();
1595 if (name
.isEmpty()) {
1596 name
= url
.protocol();
1598 // Make sure that a '&' inside the directory name is displayed correctly
1599 // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
1600 name
.replace('&', "&&");
1606 bool DolphinMainWindow::isKompareInstalled() const
1608 static bool initialized
= false;
1609 static bool installed
= false;
1611 // TODO: maybe replace this approach later by using a menu
1612 // plugin like kdiff3plugin.cpp
1613 installed
= !KGlobal::dirs()->findExe("kompare").isEmpty();
1619 void DolphinMainWindow::createSecondaryView(int tabIndex
)
1621 QSplitter
* splitter
= m_viewTab
[tabIndex
].splitter
;
1622 const int newWidth
= (m_viewTab
[tabIndex
].primaryView
->width() - splitter
->handleWidth()) / 2;
1624 const DolphinView
* view
= m_viewTab
[tabIndex
].primaryView
->view();
1625 m_viewTab
[tabIndex
].secondaryView
= new DolphinViewContainer(this, 0, view
->rootUrl());
1626 splitter
->addWidget(m_viewTab
[tabIndex
].secondaryView
);
1627 splitter
->setSizes(QList
<int>() << newWidth
<< newWidth
);
1628 connectViewSignals(m_viewTab
[tabIndex
].secondaryView
);
1629 m_viewTab
[tabIndex
].secondaryView
->view()->reload();
1630 m_viewTab
[tabIndex
].secondaryView
->setActive(false);
1631 m_viewTab
[tabIndex
].secondaryView
->show();
1634 QString
DolphinMainWindow::tabProperty(const QString
& property
, int tabIndex
) const
1636 return "Tab " + QString::number(tabIndex
) + ' ' + property
;
1639 void DolphinMainWindow::setUrlAsCaption(const KUrl
& url
)
1642 if (url
.equals(KUrl("file:///"))) {
1645 caption
= url
.fileName();
1646 if (caption
.isEmpty()) {
1647 caption
= url
.protocol();
1651 setCaption(caption
);
1654 QString
DolphinMainWindow::squeezedText(const QString
& text
) const
1656 const QFontMetrics fm
= fontMetrics();
1657 return fm
.elidedText(text
, Qt::ElideMiddle
, fm
.maxWidth() * 10);
1660 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
1661 KIO::FileUndoManager::UiInterface()
1665 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
1669 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
1671 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
1673 DolphinStatusBar
* statusBar
= mainWin
->activeViewContainer()->statusBar();
1674 statusBar
->setMessage(job
->errorString(), DolphinStatusBar::Error
);
1676 KIO::FileUndoManager::UiInterface::jobError(job
);
1680 #include "dolphinmainwindow.moc"