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 "dolphinapplication.h"
29 #include "dolphinnewmenu.h"
30 #include "search/dolphinsearchbox.h"
31 #include "search/dolphinsearchoptionsconfigurator.h"
32 #include "settings/dolphinsettings.h"
33 #include "settings/dolphinsettingsdialog.h"
34 #include "dolphinviewcontainer.h"
35 #include "panels/folders/folderspanel.h"
36 #include "panels/places/placespanel.h"
37 #include "panels/information/informationpanel.h"
38 #include "panels/information/metadatawidget.h"
39 #include "mainwindowadaptor.h"
40 #include "statusbar/dolphinstatusbar.h"
41 #include "viewproperties.h"
44 #include "panels/terminal/terminalpanel.h"
47 #include "dolphin_generalsettings.h"
48 #include "dolphin_iconsmodesettings.h"
49 #include "draganddrophelper.h"
52 #include <kactioncollection.h>
54 #include <kdesktopfile.h>
55 #include <kdeversion.h>
56 #include <kfiledialog.h>
57 #include <kfileplacesmodel.h>
59 #include <klineedit.h>
62 #include <kiconloader.h>
63 #include <kio/netaccess.h>
64 #include <kinputdialog.h>
66 #include <kprotocolmanager.h>
69 #include <kmessagebox.h>
70 #include <kfileitemlistproperties.h>
71 #include <konqmimedata.h>
72 #include <kprotocolinfo.h>
75 #include <kstandarddirs.h>
76 #include <kstatusbar.h>
77 #include <kstandardaction.h>
79 #include <ktoggleaction.h>
80 #include <kurlnavigator.h>
82 #include <kurlcombobox.h>
83 #include <ktoolinvocation.h>
85 #include <QDBusMessage>
89 #include <QDockWidget>
90 #include <kacceleratormanager.h>
93 * Remembers the tab configuration if a tab has been closed.
94 * Each closed tab can be restored by the menu
95 * "Go -> Recently Closed Tabs".
103 Q_DECLARE_METATYPE(ClosedTab
)
105 DolphinMainWindow::DolphinMainWindow(int id
) :
110 m_activeViewContainer(0),
111 m_centralWidgetLayout(0),
113 m_searchOptionsConfigurator(0),
121 setObjectName("Dolphin#");
123 m_viewTab
.append(ViewTab());
125 new MainWindowAdaptor(this);
126 QDBusConnection::sessionBus().registerObject(QString("/dolphin/MainWindow%1").arg(m_id
), this);
128 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
129 undoManager
->setUiInterface(new UndoUiInterface());
131 connect(undoManager
, SIGNAL(undoAvailable(bool)),
132 this, SLOT(slotUndoAvailable(bool)));
133 connect(undoManager
, SIGNAL(undoTextChanged(const QString
&)),
134 this, SLOT(slotUndoTextChanged(const QString
&)));
135 connect(undoManager
, SIGNAL(jobRecordingStarted(CommandType
)),
136 this, SLOT(clearStatusBar()));
137 connect(undoManager
, SIGNAL(jobRecordingFinished(CommandType
)),
138 this, SLOT(showCommand(CommandType
)));
139 connect(DolphinSettings::instance().placesModel(), SIGNAL(errorMessage(const QString
&)),
140 this, SLOT(showErrorMessage(const QString
&)));
141 connect(&DragAndDropHelper::instance(), SIGNAL(errorMessage(const QString
&)),
142 this, SLOT(showErrorMessage(const QString
&)));
145 DolphinMainWindow::~DolphinMainWindow()
147 DolphinApplication::app()->removeMainWindow(this);
150 void DolphinMainWindow::toggleViews()
152 if (m_viewTab
[m_tabIndex
].primaryView
== 0) {
156 // move secondary view from the last position of the splitter
157 // to the first position
158 m_viewTab
[m_tabIndex
].splitter
->insertWidget(0, m_viewTab
[m_tabIndex
].secondaryView
);
160 DolphinViewContainer
* container
= m_viewTab
[m_tabIndex
].primaryView
;
161 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
162 m_viewTab
[m_tabIndex
].secondaryView
= container
;
165 void DolphinMainWindow::showCommand(CommandType command
)
167 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
169 case KIO::FileUndoManager::Copy
:
170 statusBar
->setMessage(i18nc("@info:status", "Successfully copied."),
171 DolphinStatusBar::OperationCompleted
);
173 case KIO::FileUndoManager::Move
:
174 statusBar
->setMessage(i18nc("@info:status", "Successfully moved."),
175 DolphinStatusBar::OperationCompleted
);
177 case KIO::FileUndoManager::Link
:
178 statusBar
->setMessage(i18nc("@info:status", "Successfully linked."),
179 DolphinStatusBar::OperationCompleted
);
181 case KIO::FileUndoManager::Trash
:
182 statusBar
->setMessage(i18nc("@info:status", "Successfully moved to trash."),
183 DolphinStatusBar::OperationCompleted
);
185 case KIO::FileUndoManager::Rename
:
186 statusBar
->setMessage(i18nc("@info:status", "Successfully renamed."),
187 DolphinStatusBar::OperationCompleted
);
190 case KIO::FileUndoManager::Mkdir
:
191 statusBar
->setMessage(i18nc("@info:status", "Created folder."),
192 DolphinStatusBar::OperationCompleted
);
200 void DolphinMainWindow::refreshViews()
202 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
204 // remember the current active view, as because of
205 // the refreshing the active view might change to
206 // the secondary view
207 DolphinViewContainer
* activeViewContainer
= m_activeViewContainer
;
209 const int tabCount
= m_viewTab
.count();
210 for (int i
= 0; i
< tabCount
; ++i
) {
211 m_viewTab
[i
].primaryView
->refresh();
212 if (m_viewTab
[i
].secondaryView
!= 0) {
213 m_viewTab
[i
].secondaryView
->refresh();
217 setActiveViewContainer(activeViewContainer
);
220 void DolphinMainWindow::pasteIntoFolder()
222 m_activeViewContainer
->view()->pasteIntoFolder();
225 void DolphinMainWindow::changeUrl(const KUrl
& url
)
227 if (!KProtocolManager::supportsListing(url
)) {
228 // The URL navigator only checks for validity, not
229 // if the URL can be listed. An error message is
230 // shown due to DolphinViewContainer::restoreView().
234 DolphinViewContainer
* view
= activeViewContainer();
240 setUrlAsCaption(url
);
241 if (m_viewTab
.count() > 1) {
242 m_tabBar
->setTabText(m_tabIndex
, squeezedText(tabName(m_activeViewContainer
->url())));
244 const QString iconName
= KMimeType::iconNameForUrl(url
);
245 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(iconName
));
246 emit
urlChanged(url
);
250 void DolphinMainWindow::changeSelection(const KFileItemList
& selection
)
252 activeViewContainer()->view()->changeSelection(selection
);
255 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
257 KToggleAction
* editableLocationAction
=
258 static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
259 editableLocationAction
->setChecked(editable
);
262 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
266 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
267 int selectedUrlsCount
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedItemsCount();
268 if (m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
269 selectedUrlsCount
+= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItemsCount();
272 QAction
* compareFilesAction
= actionCollection()->action("compare_files");
273 if (selectedUrlsCount
== 2) {
274 compareFilesAction
->setEnabled(isKompareInstalled());
276 compareFilesAction
->setEnabled(false);
279 emit
selectionChanged(selection
);
282 void DolphinMainWindow::slotWheelMoved(int wheelDelta
)
284 if (wheelDelta
> 0) {
291 void DolphinMainWindow::slotRequestItemInfo(const KFileItem
& item
)
293 emit
requestItemInfo(item
);
296 void DolphinMainWindow::updateHistory()
298 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
299 const int index
= urlNavigator
->historyIndex();
301 QAction
* backAction
= actionCollection()->action("go_back");
302 if (backAction
!= 0) {
303 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
306 QAction
* forwardAction
= actionCollection()->action("go_forward");
307 if (forwardAction
!= 0) {
308 forwardAction
->setEnabled(index
> 0);
312 void DolphinMainWindow::updateFilterBarAction(bool show
)
314 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
315 showFilterBarAction
->setChecked(show
);
318 void DolphinMainWindow::openNewMainWindow()
320 DolphinApplication::app()->createMainWindow()->show();
323 void DolphinMainWindow::openNewTab()
325 openNewTab(m_activeViewContainer
->url());
326 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
328 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
329 if (navigator
->isUrlEditable()) {
330 // if a new tab is opened and the URL is editable, assure that
331 // the user can edit the URL without manually setting the focus
332 navigator
->setFocus();
336 void DolphinMainWindow::openNewTab(const KUrl
& url
)
338 const KIcon icon
= KIcon(KMimeType::iconNameForUrl(m_activeViewContainer
->url()));
339 if (m_viewTab
.count() == 1) {
340 // Only one view is open currently and hence no tab is shown at
341 // all. Before creating a tab for 'url', provide a tab for the current URL.
342 m_tabBar
->addTab(icon
, squeezedText(tabName(m_activeViewContainer
->url())));
343 m_tabBar
->blockSignals(false);
346 m_tabBar
->addTab(icon
, squeezedText(tabName(url
)));
349 viewTab
.splitter
= new QSplitter(this);
350 viewTab
.splitter
->setChildrenCollapsible(false);
351 viewTab
.primaryView
= new DolphinViewContainer(this, viewTab
.splitter
, url
);
352 viewTab
.primaryView
->setActive(false);
353 connectViewSignals(viewTab
.primaryView
);
354 viewTab
.primaryView
->view()->reload();
356 m_viewTab
.append(viewTab
);
358 actionCollection()->action("close_tab")->setEnabled(true);
360 // provide a split view, if the startup settings are set this way
361 const GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
362 if (generalSettings
->splitView()) {
363 const int tabIndex
= m_viewTab
.count() - 1;
364 createSecondaryView(tabIndex
);
365 m_viewTab
[tabIndex
].secondaryView
->setActive(true);
366 m_viewTab
[tabIndex
].isPrimaryViewActive
= false;
370 void DolphinMainWindow::activateNextTab()
372 if ((m_viewTab
.count() == 1) || (m_tabBar
->count() < 2)) {
376 const int tabIndex
= (m_tabBar
->currentIndex() + 1) % m_tabBar
->count();
377 m_tabBar
->setCurrentIndex(tabIndex
);
380 void DolphinMainWindow::activatePrevTab()
382 if ((m_viewTab
.count() == 1) || (m_tabBar
->count() < 2)) {
386 int tabIndex
= m_tabBar
->currentIndex() - 1;
387 if (tabIndex
== -1) {
388 tabIndex
= m_tabBar
->count() - 1;
390 m_tabBar
->setCurrentIndex(tabIndex
);
393 void DolphinMainWindow::openInNewTab()
395 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
396 if ((list
.count() == 1) && list
[0].isDir()) {
397 openNewTab(m_activeViewContainer
->view()->selectedUrls()[0]);
401 void DolphinMainWindow::openInNewWindow()
403 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
404 if ((list
.count() == 1) && list
[0].isDir()) {
405 DolphinMainWindow
* window
= DolphinApplication::app()->createMainWindow();
406 window
->changeUrl(m_activeViewContainer
->view()->selectedUrls()[0]);
411 void DolphinMainWindow::toggleActiveView()
413 if (m_viewTab
[m_tabIndex
].secondaryView
== 0) {
414 // only one view is available
418 Q_ASSERT(m_activeViewContainer
!= 0);
419 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
421 DolphinViewContainer
* left
= m_viewTab
[m_tabIndex
].primaryView
;
422 DolphinViewContainer
* right
= m_viewTab
[m_tabIndex
].secondaryView
;
423 setActiveViewContainer(m_activeViewContainer
== right
? left
: right
);
426 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
428 DolphinSettings
& settings
= DolphinSettings::instance();
429 GeneralSettings
* generalSettings
= settings
.generalSettings();
431 // Find out if Dolphin is closed directly by the user or
432 // by the session manager because the session is closed
433 bool closedByUser
= true;
434 DolphinApplication
*application
= qobject_cast
<DolphinApplication
*>(qApp
);
435 if (application
&& application
->sessionSaving()) {
436 closedByUser
= false;
439 if ((m_viewTab
.count() > 1) && generalSettings
->confirmClosingMultipleTabs() && closedByUser
) {
440 // Ask the user if he really wants to quit and close all tabs.
441 // Open a confirmation dialog with 3 buttons:
442 // KDialog::Yes -> Quit
443 // KDialog::No -> Close only the current tab
444 // KDialog::Cancel -> do nothing
445 KDialog
*dialog
= new KDialog(this, Qt::Dialog
);
446 dialog
->setCaption(i18nc("@title:window", "Confirmation"));
447 dialog
->setButtons(KDialog::Yes
| KDialog::No
| KDialog::Cancel
);
448 dialog
->setModal(true);
449 dialog
->showButtonSeparator(true);
450 dialog
->setButtonGuiItem(KDialog::Yes
, KStandardGuiItem::quit());
451 dialog
->setButtonGuiItem(KDialog::No
, KGuiItem(i18n("C&lose Current Tab"), KIcon("tab-close")));
452 dialog
->setButtonGuiItem(KDialog::Cancel
, KStandardGuiItem::cancel());
453 dialog
->setDefaultButton(KDialog::Yes
);
455 bool doNotAskAgainCheckboxResult
= false;
457 const int result
= KMessageBox::createKMessageBox(dialog
,
458 QMessageBox::Warning
,
459 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
461 i18n("Do not ask again"),
462 &doNotAskAgainCheckboxResult
,
463 KMessageBox::Notify
);
465 if (doNotAskAgainCheckboxResult
) {
466 generalSettings
->setConfirmClosingMultipleTabs(false);
474 // Close only the current tab
482 generalSettings
->setFirstRun(false);
486 KXmlGuiWindow::closeEvent(event
);
489 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
491 const int tabCount
= m_viewTab
.count();
492 group
.writeEntry("Tab Count", tabCount
);
493 group
.writeEntry("Active Tab Index", m_tabBar
->currentIndex());
495 for (int i
= 0; i
< tabCount
; ++i
) {
496 const DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
497 group
.writeEntry(tabProperty("Primary URL", i
), cont
->url().url());
498 group
.writeEntry(tabProperty("Primary Editable", i
), cont
->isUrlEditable());
500 cont
= m_viewTab
[i
].secondaryView
;
502 group
.writeEntry(tabProperty("Secondary URL", i
), cont
->url().url());
503 group
.writeEntry(tabProperty("Secondary Editable", i
), cont
->isUrlEditable());
508 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
510 const int tabCount
= group
.readEntry("Tab Count", 1);
511 for (int i
= 0; i
< tabCount
; ++i
) {
512 DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
514 cont
->setUrl(group
.readEntry(tabProperty("Primary URL", i
)));
515 const bool editable
= group
.readEntry(tabProperty("Primary Editable", i
), false);
516 cont
->urlNavigator()->setUrlEditable(editable
);
518 cont
= m_viewTab
[i
].secondaryView
;
519 const QString secondaryUrl
= group
.readEntry(tabProperty("Secondary URL", i
));
520 if (!secondaryUrl
.isEmpty()) {
522 // a secondary view should be shown, but no one is available
523 // currently -> create a new view
525 cont
= m_viewTab
[i
].secondaryView
;
529 cont
->setUrl(secondaryUrl
);
530 const bool editable
= group
.readEntry(tabProperty("Secondary Editable", i
), false);
531 cont
->urlNavigator()->setUrlEditable(editable
);
532 } else if (cont
!= 0) {
533 // no secondary view should be shown, but the default setting shows
534 // one already -> close the view
538 // openNewTab() needs to be called only tabCount - 1 times
539 if (i
!= tabCount
- 1) {
544 const int index
= group
.readEntry("Active Tab Index", 0);
545 m_tabBar
->setCurrentIndex(index
);
548 void DolphinMainWindow::updateNewMenu()
550 m_newMenu
->slotCheckUpToDate();
551 m_newMenu
->setPopupFiles(activeViewContainer()->url());
554 void DolphinMainWindow::createDirectory()
556 m_newMenu
->setPopupFiles(activeViewContainer()->url());
557 m_newMenu
->createDirectory();
560 void DolphinMainWindow::quit()
565 void DolphinMainWindow::showErrorMessage(const QString
& message
)
567 if (!message
.isEmpty()) {
568 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
569 statusBar
->setMessage(message
, DolphinStatusBar::Error
);
573 void DolphinMainWindow::slotUndoAvailable(bool available
)
575 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
576 if (undoAction
!= 0) {
577 undoAction
->setEnabled(available
);
581 void DolphinMainWindow::restoreClosedTab(QAction
* action
)
583 if (action
->data().toBool()) {
584 // clear all actions except the "Empty Recently Closed Tabs"
585 // action and the separator
586 QList
<QAction
*> actions
= m_recentTabsMenu
->menu()->actions();
587 const int count
= actions
.size();
588 for (int i
= 2; i
< count
; ++i
) {
589 m_recentTabsMenu
->menu()->removeAction(actions
.at(i
));
592 const ClosedTab closedTab
= action
->data().value
<ClosedTab
>();
593 openNewTab(closedTab
.primaryUrl
);
594 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
596 if (closedTab
.isSplit
) {
597 // create secondary view
599 m_viewTab
[m_tabIndex
].secondaryView
->setUrl(closedTab
.secondaryUrl
);
602 m_recentTabsMenu
->removeAction(action
);
605 if (m_recentTabsMenu
->menu()->actions().count() == 2) {
606 m_recentTabsMenu
->setEnabled(false);
610 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
612 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
613 if (undoAction
!= 0) {
614 undoAction
->setText(text
);
618 void DolphinMainWindow::undo()
621 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
622 KIO::FileUndoManager::self()->undo();
625 void DolphinMainWindow::cut()
627 m_activeViewContainer
->view()->cutSelectedItems();
630 void DolphinMainWindow::copy()
632 m_activeViewContainer
->view()->copySelectedItems();
635 void DolphinMainWindow::paste()
637 m_activeViewContainer
->view()->paste();
640 void DolphinMainWindow::updatePasteAction()
642 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
643 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
644 pasteAction
->setEnabled(pasteInfo
.first
);
645 pasteAction
->setText(pasteInfo
.second
);
648 void DolphinMainWindow::selectAll()
652 // if the URL navigator is editable and focused, select the whole
653 // URL instead of all items of the view
655 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
656 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit(); // krazy:exclude=qclasses
657 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
658 lineEdit
->hasFocus();
660 lineEdit
->selectAll();
662 m_activeViewContainer
->view()->selectAll();
666 void DolphinMainWindow::invertSelection()
669 m_activeViewContainer
->view()->invertSelection();
672 void DolphinMainWindow::toggleSplitView()
674 if (m_viewTab
[m_tabIndex
].secondaryView
== 0) {
675 createSecondaryView(m_tabIndex
);
676 setActiveViewContainer(m_viewTab
[m_tabIndex
].secondaryView
);
677 } else if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
678 // remove secondary view
679 m_viewTab
[m_tabIndex
].secondaryView
->close();
680 m_viewTab
[m_tabIndex
].secondaryView
->deleteLater();
681 m_viewTab
[m_tabIndex
].secondaryView
= 0;
683 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
685 // The primary view is active and should be closed. Hence from a users point of view
686 // the content of the secondary view should be moved to the primary view.
687 // From an implementation point of view it is more efficient to close
688 // the primary view and exchange the internal pointers afterwards.
690 m_viewTab
[m_tabIndex
].primaryView
->close();
691 m_viewTab
[m_tabIndex
].primaryView
->deleteLater();
692 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
693 m_viewTab
[m_tabIndex
].secondaryView
= 0;
695 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
701 void DolphinMainWindow::reloadView()
704 m_activeViewContainer
->view()->reload();
707 void DolphinMainWindow::stopLoading()
711 void DolphinMainWindow::toggleFilterBarVisibility(bool show
)
713 m_activeViewContainer
->showFilterBar(show
);
716 void DolphinMainWindow::toggleEditLocation()
720 QAction
* action
= actionCollection()->action("editable_location");
721 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
722 urlNavigator
->setUrlEditable(action
->isChecked());
725 void DolphinMainWindow::replaceLocation()
727 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
728 navigator
->setUrlEditable(true);
729 navigator
->setFocus();
731 // select the whole text of the combo box editor
732 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit(); // krazy:exclude=qclasses
733 const QString text
= lineEdit
->text();
734 lineEdit
->setSelection(0, text
.length());
737 void DolphinMainWindow::goBack()
740 m_activeViewContainer
->urlNavigator()->goBack();
743 void DolphinMainWindow::goForward()
746 m_activeViewContainer
->urlNavigator()->goForward();
749 void DolphinMainWindow::goUp()
752 m_activeViewContainer
->urlNavigator()->goUp();
755 void DolphinMainWindow::goHome()
758 m_activeViewContainer
->urlNavigator()->goHome();
761 void DolphinMainWindow::compareFiles()
763 // The method is only invoked if exactly 2 files have
764 // been selected. The selected files may be:
765 // - both in the primary view
766 // - both in the secondary view
767 // - one in the primary view and the other in the secondary
769 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
773 KUrl::List urls
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedUrls();
775 switch (urls
.count()) {
777 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
!= 0);
778 urls
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedUrls();
779 Q_ASSERT(urls
.count() == 2);
787 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
!= 0);
788 urls
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedUrls();
789 Q_ASSERT(urls
.count() == 1);
801 // may not happen: compareFiles may only get invoked if 2
802 // files are selected
807 QString
command("kompare -c \"");
808 command
.append(urlA
.pathOrUrl());
809 command
.append("\" \"");
810 command
.append(urlB
.pathOrUrl());
811 command
.append('\"');
812 KRun::runCommand(command
, "Kompare", "kompare", this);
815 void DolphinMainWindow::toggleShowMenuBar()
817 const bool visible
= menuBar()->isVisible();
818 menuBar()->setVisible(!visible
);
821 void DolphinMainWindow::openTerminal()
823 QString
dir(QDir::homePath());
825 // If the given directory is not local, it can still be the URL of an
826 // ioslave using UDS_LOCAL_PATH which to be converted first.
827 KUrl url
= KIO::NetAccess::mostLocalUrl(m_activeViewContainer
->url(), this);
829 //If the URL is local after the above conversion, set the directory.
830 if (url
.isLocalFile()) {
831 dir
= url
.toLocalFile();
834 KToolInvocation::invokeTerminal(QString(), dir
);
837 void DolphinMainWindow::editSettings()
839 if (m_settingsDialog
== 0) {
840 const KUrl
& url
= activeViewContainer()->url();
841 m_settingsDialog
= new DolphinSettingsDialog(url
, this);
842 m_settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
843 m_settingsDialog
->show();
845 m_settingsDialog
->raise();
849 void DolphinMainWindow::setActiveTab(int index
)
851 Q_ASSERT(index
>= 0);
852 Q_ASSERT(index
< m_viewTab
.count());
853 if (index
== m_tabIndex
) {
857 // hide current tab content
858 ViewTab
& hiddenTab
= m_viewTab
[m_tabIndex
];
859 hiddenTab
.isPrimaryViewActive
= hiddenTab
.primaryView
->isActive();
860 hiddenTab
.primaryView
->setActive(false);
861 if (hiddenTab
.secondaryView
!= 0) {
862 hiddenTab
.secondaryView
->setActive(false);
864 QSplitter
* splitter
= m_viewTab
[m_tabIndex
].splitter
;
866 m_centralWidgetLayout
->removeWidget(splitter
);
868 // show active tab content
871 ViewTab
& viewTab
= m_viewTab
[index
];
872 m_centralWidgetLayout
->addWidget(viewTab
.splitter
, 1);
873 viewTab
.primaryView
->show();
874 if (viewTab
.secondaryView
!= 0) {
875 viewTab
.secondaryView
->show();
877 viewTab
.splitter
->show();
879 setActiveViewContainer(viewTab
.isPrimaryViewActive
? viewTab
.primaryView
:
880 viewTab
.secondaryView
);
883 void DolphinMainWindow::closeTab()
885 closeTab(m_tabBar
->currentIndex());
888 void DolphinMainWindow::closeTab(int index
)
890 Q_ASSERT(index
>= 0);
891 Q_ASSERT(index
< m_viewTab
.count());
892 if (m_viewTab
.count() == 1) {
893 // the last tab may never get closed
897 if (index
== m_tabIndex
) {
898 // The tab that should be closed is the active tab. Activate the
899 // previous tab before closing the tab.
900 m_tabBar
->setCurrentIndex((index
> 0) ? index
- 1 : 1);
902 rememberClosedTab(index
);
905 m_viewTab
[index
].primaryView
->deleteLater();
906 if (m_viewTab
[index
].secondaryView
!= 0) {
907 m_viewTab
[index
].secondaryView
->deleteLater();
909 m_viewTab
[index
].splitter
->deleteLater();
910 m_viewTab
.erase(m_viewTab
.begin() + index
);
912 m_tabBar
->blockSignals(true);
913 m_tabBar
->removeTab(index
);
915 if (m_tabIndex
> index
) {
917 Q_ASSERT(m_tabIndex
>= 0);
920 // if only one tab is left, also remove the tab entry so that
921 // closing the last tab is not possible
922 if (m_viewTab
.count() == 1) {
923 m_tabBar
->removeTab(0);
924 actionCollection()->action("close_tab")->setEnabled(false);
926 m_tabBar
->blockSignals(false);
930 void DolphinMainWindow::openTabContextMenu(int index
, const QPoint
& pos
)
934 QAction
* newTabAction
= menu
.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab"));
935 newTabAction
->setShortcut(actionCollection()->action("new_tab")->shortcut());
937 QAction
* closeOtherTabsAction
= menu
.addAction(KIcon("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs"));
939 QAction
* closeTabAction
= menu
.addAction(KIcon("tab-close"), i18nc("@action:inmenu", "Close Tab"));
940 closeTabAction
->setShortcut(actionCollection()->action("close_tab")->shortcut());
941 QAction
* selectedAction
= menu
.exec(pos
);
942 if (selectedAction
== newTabAction
) {
943 const ViewTab
& tab
= m_viewTab
[index
];
944 Q_ASSERT(tab
.primaryView
!= 0);
945 const KUrl url
= (tab
.secondaryView
!= 0) && tab
.secondaryView
->isActive() ?
946 tab
.secondaryView
->url() : tab
.primaryView
->url();
948 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
949 } else if (selectedAction
== closeOtherTabsAction
) {
950 const int count
= m_tabBar
->count();
951 for (int i
= 0; i
< index
; ++i
) {
954 for (int i
= index
+ 1; i
< count
; ++i
) {
957 } else if (selectedAction
== closeTabAction
) {
962 void DolphinMainWindow::handlePlacesClick(const KUrl
& url
, Qt::MouseButtons buttons
)
964 if (buttons
& Qt::MidButton
) {
966 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
972 void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent
* event
, bool& canDecode
)
974 canDecode
= KUrl::List::canDecode(event
->mimeData());
977 void DolphinMainWindow::searchItems(const KUrl
& url
)
979 m_activeViewContainer
->setUrl(url
);
982 void DolphinMainWindow::slotTabMoved(int from
, int to
)
984 m_viewTab
.move(from
, to
);
985 m_tabIndex
= m_tabBar
->currentIndex();
988 void DolphinMainWindow::slotSearchBoxTextChanged(const QString
& text
)
990 m_searchOptionsConfigurator
->setVisible(!text
.isEmpty());
993 void DolphinMainWindow::init()
995 DolphinSettings
& settings
= DolphinSettings::instance();
997 // Check whether Dolphin runs the first time. If yes then
998 // a proper default window size is given at the end of DolphinMainWindow::init().
999 GeneralSettings
* generalSettings
= settings
.generalSettings();
1000 const bool firstRun
= generalSettings
->firstRun();
1002 generalSettings
->setViewPropsTimestamp(QDateTime::currentDateTime());
1005 setAcceptDrops(true);
1007 m_viewTab
[m_tabIndex
].splitter
= new QSplitter(this);
1008 m_viewTab
[m_tabIndex
].splitter
->setChildrenCollapsible(false);
1012 const KUrl
& homeUrl
= generalSettings
->homeUrl();
1013 setUrlAsCaption(homeUrl
);
1014 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
1015 connect(m_actionHandler
, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
1016 connect(m_actionHandler
, SIGNAL(createDirectory()), SLOT(createDirectory()));
1017 ViewProperties
props(homeUrl
);
1018 m_viewTab
[m_tabIndex
].primaryView
= new DolphinViewContainer(this,
1019 m_viewTab
[m_tabIndex
].splitter
,
1022 m_activeViewContainer
= m_viewTab
[m_tabIndex
].primaryView
;
1023 connectViewSignals(m_activeViewContainer
);
1024 DolphinView
* view
= m_activeViewContainer
->view();
1026 m_activeViewContainer
->show();
1027 m_actionHandler
->setCurrentView(view
);
1029 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
1030 connect(this, SIGNAL(urlChanged(const KUrl
&)),
1031 m_remoteEncoding
, SLOT(slotAboutToOpenUrl()));
1033 m_searchOptionsConfigurator
= new DolphinSearchOptionsConfigurator(this);
1034 m_searchOptionsConfigurator
->hide();
1036 m_tabBar
= new KTabBar(this);
1037 m_tabBar
->setMovable(true);
1038 m_tabBar
->setTabsClosable(true);
1039 connect(m_tabBar
, SIGNAL(currentChanged(int)),
1040 this, SLOT(setActiveTab(int)));
1041 connect(m_tabBar
, SIGNAL(tabCloseRequested(int)),
1042 this, SLOT(closeTab(int)));
1043 connect(m_tabBar
, SIGNAL(contextMenu(int, const QPoint
&)),
1044 this, SLOT(openTabContextMenu(int, const QPoint
&)));
1045 connect(m_tabBar
, SIGNAL(newTabRequest()),
1046 this, SLOT(openNewTab()));
1047 connect(m_tabBar
, SIGNAL(testCanDecode(const QDragMoveEvent
*, bool&)),
1048 this, SLOT(slotTestCanDecode(const QDragMoveEvent
*, bool&)));
1049 connect(m_tabBar
, SIGNAL(wheelDelta(int)),
1050 this, SLOT(slotWheelMoved(int)));
1051 connect(m_tabBar
, SIGNAL(mouseMiddleClick(int)),
1052 this, SLOT(closeTab(int)));
1053 connect(m_tabBar
, SIGNAL(tabMoved(int, int)),
1054 this, SLOT(slotTabMoved(int, int)));
1056 m_tabBar
->blockSignals(true); // signals get unblocked after at least 2 tabs are open
1058 QWidget
* centralWidget
= new QWidget(this);
1059 m_centralWidgetLayout
= new QVBoxLayout(centralWidget
);
1060 m_centralWidgetLayout
->setSpacing(0);
1061 m_centralWidgetLayout
->setMargin(0);
1062 m_centralWidgetLayout
->addWidget(m_searchOptionsConfigurator
);
1063 m_centralWidgetLayout
->addWidget(m_tabBar
);
1064 m_centralWidgetLayout
->addWidget(m_viewTab
[m_tabIndex
].splitter
, 1);
1066 setCentralWidget(centralWidget
);
1068 emit
urlChanged(homeUrl
);
1070 setupGUI(Keys
| Save
| Create
| ToolBar
);
1072 m_searchBox
->setParent(toolBar("searchToolBar"));
1073 m_searchBox
->show();
1074 connect(m_searchBox
, SIGNAL(textChanged(const QString
&)),
1075 this, SLOT(slotSearchBoxTextChanged(const QString
&)));
1077 stateChanged("new_file");
1079 QClipboard
* clipboard
= QApplication::clipboard();
1080 connect(clipboard
, SIGNAL(dataChanged()),
1081 this, SLOT(updatePasteAction()));
1082 updatePasteAction();
1085 if (generalSettings
->splitView()) {
1088 updateViewActions();
1090 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1091 showFilterBarAction
->setChecked(generalSettings
->filterBar());
1094 // assure a proper default size if Dolphin runs the first time
1098 m_showMenuBar
->setChecked(!menuBar()->isHidden()); // workaround for bug #171080
1101 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer
* viewContainer
)
1103 Q_ASSERT(viewContainer
!= 0);
1104 Q_ASSERT((viewContainer
== m_viewTab
[m_tabIndex
].primaryView
) ||
1105 (viewContainer
== m_viewTab
[m_tabIndex
].secondaryView
));
1106 if (m_activeViewContainer
== viewContainer
) {
1110 m_activeViewContainer
->setActive(false);
1111 m_activeViewContainer
= viewContainer
;
1113 // Activating the view container might trigger a recursive setActiveViewContainer() call
1114 // inside DolphinMainWindow::toggleActiveView() when having a split view. Temporary
1115 // disconnect the activated() signal in this case:
1116 disconnect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1117 m_activeViewContainer
->setActive(true);
1118 connect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1120 m_actionHandler
->setCurrentView(viewContainer
->view());
1123 updateEditActions();
1124 updateViewActions();
1127 const KUrl
& url
= m_activeViewContainer
->url();
1128 setUrlAsCaption(url
);
1129 if (m_viewTab
.count() > 1 && m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
1130 m_tabBar
->setTabText(m_tabIndex
, tabName(url
));
1131 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(KMimeType::iconNameForUrl(url
)));
1134 emit
urlChanged(url
);
1137 void DolphinMainWindow::setupActions()
1139 // setup 'File' menu
1140 m_newMenu
= new DolphinNewMenu(this, this);
1141 KMenu
* menu
= m_newMenu
->menu();
1142 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1143 menu
->setIcon(KIcon("document-new"));
1144 connect(menu
, SIGNAL(aboutToShow()),
1145 this, SLOT(updateNewMenu()));
1147 KAction
* newWindow
= actionCollection()->addAction("new_window");
1148 newWindow
->setIcon(KIcon("window-new"));
1149 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1150 newWindow
->setShortcut(Qt::CTRL
| Qt::Key_N
);
1151 connect(newWindow
, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1153 KAction
* newTab
= actionCollection()->addAction("new_tab");
1154 newTab
->setIcon(KIcon("tab-new"));
1155 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1156 newTab
->setShortcut(KShortcut(Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
));
1157 connect(newTab
, SIGNAL(triggered()), this, SLOT(openNewTab()));
1159 KAction
* closeTab
= actionCollection()->addAction("close_tab");
1160 closeTab
->setIcon(KIcon("tab-close"));
1161 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1162 closeTab
->setShortcut(Qt::CTRL
| Qt::Key_W
);
1163 closeTab
->setEnabled(false);
1164 connect(closeTab
, SIGNAL(triggered()), this, SLOT(closeTab()));
1166 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1168 // setup 'Edit' menu
1169 KStandardAction::undo(this,
1171 actionCollection());
1173 // need to remove shift+del from cut action, else the shortcut for deletejob
1175 KAction
* cut
= KStandardAction::cut(this, SLOT(cut()), actionCollection());
1176 KShortcut cutShortcut
= cut
->shortcut();
1177 cutShortcut
.remove(Qt::SHIFT
+ Qt::Key_Delete
, KShortcut::KeepEmpty
);
1178 cut
->setShortcut(cutShortcut
);
1179 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1180 KAction
* paste
= KStandardAction::paste(this, SLOT(paste()), actionCollection());
1181 // The text of the paste-action is modified dynamically by Dolphin
1182 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1183 // due to the long text, the text "Paste" is used:
1184 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1186 KAction
* selectAll
= actionCollection()->addAction("select_all");
1187 selectAll
->setText(i18nc("@action:inmenu Edit", "Select All"));
1188 selectAll
->setShortcut(Qt::CTRL
+ Qt::Key_A
);
1189 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
1191 KAction
* invertSelection
= actionCollection()->addAction("invert_selection");
1192 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1193 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1194 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
1196 // setup 'View' menu
1197 // (note that most of it is set up in DolphinViewActionHandler)
1199 KAction
* split
= actionCollection()->addAction("split_view");
1200 split
->setShortcut(Qt::Key_F3
);
1201 updateSplitAction();
1202 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1204 KAction
* reload
= actionCollection()->addAction("reload");
1205 reload
->setText(i18nc("@action:inmenu View", "Reload"));
1206 reload
->setShortcut(Qt::Key_F5
);
1207 reload
->setIcon(KIcon("view-refresh"));
1208 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
1210 KAction
* stop
= actionCollection()->addAction("stop");
1211 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1212 stop
->setIcon(KIcon("process-stop"));
1213 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
1215 KToggleAction
* showFullLocation
= actionCollection()->add
<KToggleAction
>("editable_location");
1216 showFullLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1217 showFullLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
1218 connect(showFullLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1220 KAction
* replaceLocation
= actionCollection()->addAction("replace_location");
1221 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1222 replaceLocation
->setShortcut(Qt::Key_F6
);
1223 connect(replaceLocation
, SIGNAL(triggered()), this, SLOT(replaceLocation()));
1226 KAction
* backAction
= KStandardAction::back(this, SLOT(goBack()), actionCollection());
1227 KShortcut backShortcut
= backAction
->shortcut();
1228 backShortcut
.setAlternate(Qt::Key_Backspace
);
1229 backAction
->setShortcut(backShortcut
);
1231 m_recentTabsMenu
= new KActionMenu(i18n("Recently Closed Tabs"), this);
1232 m_recentTabsMenu
->setIcon(KIcon("edit-undo"));
1233 actionCollection()->addAction("closed_tabs", m_recentTabsMenu
);
1234 connect(m_recentTabsMenu
->menu(), SIGNAL(triggered(QAction
*)),
1235 this, SLOT(restoreClosedTab(QAction
*)));
1237 QAction
* action
= new QAction("Empty Recently Closed Tabs", m_recentTabsMenu
);
1238 action
->setIcon(KIcon("edit-clear-list"));
1239 action
->setData(QVariant::fromValue(true));
1240 m_recentTabsMenu
->addAction(action
);
1241 m_recentTabsMenu
->addSeparator();
1242 m_recentTabsMenu
->setEnabled(false);
1244 KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1245 KStandardAction::up(this, SLOT(goUp()), actionCollection());
1246 KStandardAction::home(this, SLOT(goHome()), actionCollection());
1248 // setup 'Tools' menu
1249 KToggleAction
* showSearchBar
= actionCollection()->add
<KToggleAction
>("show_search_bar");
1250 showSearchBar
->setText(i18nc("@action:inmenu Tools", "Show Search Bar"));
1251 showSearchBar
->setShortcut(Qt::CTRL
| Qt::Key_S
);
1252 connect(showSearchBar
, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
1254 KToggleAction
* showFilterBar
= actionCollection()->add
<KToggleAction
>("show_filter_bar");
1255 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1256 showFilterBar
->setIcon(KIcon("view-filter"));
1257 showFilterBar
->setShortcut(Qt::CTRL
| Qt::Key_I
);
1258 connect(showFilterBar
, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
1260 KAction
* compareFiles
= actionCollection()->addAction("compare_files");
1261 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1262 compareFiles
->setIcon(KIcon("kompare"));
1263 compareFiles
->setEnabled(false);
1264 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
1266 KAction
* openTerminal
= actionCollection()->addAction("open_terminal");
1267 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1268 openTerminal
->setIcon(KIcon("utilities-terminal"));
1269 openTerminal
->setShortcut(Qt::SHIFT
| Qt::Key_F4
);
1270 connect(openTerminal
, SIGNAL(triggered()), this, SLOT(openTerminal()));
1272 // setup 'Settings' menu
1273 m_showMenuBar
= KStandardAction::showMenubar(this, SLOT(toggleShowMenuBar()), actionCollection());
1274 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1276 // not in menu actions
1277 KAction
* activateNextTab
= actionCollection()->addAction("activate_next_tab");
1278 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1279 connect(activateNextTab
, SIGNAL(triggered()), SLOT(activateNextTab()));
1280 activateNextTab
->setShortcuts(QApplication::isRightToLeft() ? KStandardShortcut::tabPrev() :
1281 KStandardShortcut::tabNext());
1283 KAction
* activatePrevTab
= actionCollection()->addAction("activate_prev_tab");
1284 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1285 connect(activatePrevTab
, SIGNAL(triggered()), SLOT(activatePrevTab()));
1286 activatePrevTab
->setShortcuts(QApplication::isRightToLeft() ? KStandardShortcut::tabNext() :
1287 KStandardShortcut::tabPrev());
1290 KAction
* openInNewTab
= actionCollection()->addAction("open_in_new_tab");
1291 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1292 openInNewTab
->setIcon(KIcon("tab-new"));
1293 connect(openInNewTab
, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1295 KAction
* openInNewWindow
= actionCollection()->addAction("open_in_new_window");
1296 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1297 openInNewWindow
->setIcon(KIcon("window-new"));
1298 connect(openInNewWindow
, SIGNAL(triggered()), this, SLOT(openInNewWindow()));
1301 m_searchBox
= new DolphinSearchBox(this);
1302 connect(m_searchBox
, SIGNAL(search(KUrl
)), this, SLOT(searchItems(KUrl
)));
1304 KAction
* search
= new KAction(this);
1305 actionCollection()->addAction("search_bar", search
);
1306 search
->setText(i18nc("@action:inmenu", "Search Bar"));
1307 search
->setDefaultWidget(m_searchBox
);
1308 search
->setShortcutConfigurable(false);
1311 void DolphinMainWindow::setupDockWidgets()
1313 // setup "Information"
1314 QDockWidget
* infoDock
= new QDockWidget(i18nc("@title:window", "Information"));
1315 infoDock
->setObjectName("infoDock");
1316 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1317 Panel
* infoPanel
= new InformationPanel(infoDock
);
1318 infoDock
->setWidget(infoPanel
);
1320 QAction
* infoAction
= infoDock
->toggleViewAction();
1321 infoAction
->setText(i18nc("@title:window", "Information"));
1322 infoAction
->setShortcut(Qt::Key_F11
);
1323 infoAction
->setIcon(KIcon("dialog-information"));
1324 actionCollection()->addAction("show_info_panel", infoDock
->toggleViewAction());
1326 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1327 connect(this, SIGNAL(urlChanged(KUrl
)),
1328 infoPanel
, SLOT(setUrl(KUrl
)));
1329 connect(this, SIGNAL(selectionChanged(KFileItemList
)),
1330 infoPanel
, SLOT(setSelection(KFileItemList
)));
1331 connect(this, SIGNAL(requestItemInfo(KFileItem
)),
1332 infoPanel
, SLOT(requestDelayedItemInfo(KFileItem
)));
1335 QDockWidget
* foldersDock
= new QDockWidget(i18nc("@title:window", "Folders"));
1336 foldersDock
->setObjectName("foldersDock");
1337 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1338 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1339 foldersDock
->setWidget(foldersPanel
);
1341 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1342 foldersAction
->setText(i18nc("@title:window", "Folders"));
1343 foldersAction
->setShortcut(Qt::Key_F7
);
1344 foldersAction
->setIcon(KIcon("folder"));
1345 actionCollection()->addAction("show_folders_panel", foldersDock
->toggleViewAction());
1347 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1348 connect(this, SIGNAL(urlChanged(KUrl
)),
1349 foldersPanel
, SLOT(setUrl(KUrl
)));
1350 connect(foldersPanel
, SIGNAL(changeUrl(KUrl
, Qt::MouseButtons
)),
1351 this, SLOT(handlePlacesClick(KUrl
, Qt::MouseButtons
)));
1352 connect(foldersPanel
, SIGNAL(changeSelection(KFileItemList
)),
1353 this, SLOT(changeSelection(KFileItemList
)));
1357 QDockWidget
* terminalDock
= new QDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1358 terminalDock
->setObjectName("terminalDock");
1359 terminalDock
->setAllowedAreas(Qt::TopDockWidgetArea
| Qt::BottomDockWidgetArea
);
1360 Panel
* terminalPanel
= new TerminalPanel(terminalDock
);
1361 terminalDock
->setWidget(terminalPanel
);
1363 connect(terminalPanel
, SIGNAL(hideTerminalPanel()), terminalDock
, SLOT(hide()));
1365 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1366 terminalAction
->setText(i18nc("@title:window Shell terminal", "Terminal"));
1367 terminalAction
->setShortcut(Qt::Key_F4
);
1368 terminalAction
->setIcon(KIcon("utilities-terminal"));
1369 actionCollection()->addAction("show_terminal_panel", terminalDock
->toggleViewAction());
1371 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1372 connect(this, SIGNAL(urlChanged(KUrl
)),
1373 terminalPanel
, SLOT(setUrl(KUrl
)));
1376 const bool firstRun
= DolphinSettings::instance().generalSettings()->firstRun();
1378 foldersDock
->hide();
1380 terminalDock
->hide();
1384 QDockWidget
* placesDock
= new QDockWidget(i18nc("@title:window", "Places"));
1385 placesDock
->setObjectName("placesDock");
1386 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1388 PlacesPanel
* placesPanel
= new PlacesPanel(placesDock
);
1389 placesDock
->setWidget(placesPanel
);
1390 placesPanel
->setModel(DolphinSettings::instance().placesModel());
1391 placesPanel
->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff
);
1393 QAction
* placesAction
= placesDock
->toggleViewAction();
1394 placesAction
->setText(i18nc("@title:window", "Places"));
1395 placesAction
->setShortcut(Qt::Key_F9
);
1396 placesAction
->setIcon(KIcon("bookmarks"));
1397 actionCollection()->addAction("show_places_panel", placesDock
->toggleViewAction());
1399 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1400 connect(placesPanel
, SIGNAL(urlChanged(KUrl
, Qt::MouseButtons
)),
1401 this, SLOT(handlePlacesClick(KUrl
, Qt::MouseButtons
)));
1402 connect(this, SIGNAL(urlChanged(KUrl
)),
1403 placesPanel
, SLOT(setUrl(KUrl
)));
1406 void DolphinMainWindow::updateEditActions()
1408 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1409 if (list
.isEmpty()) {
1410 stateChanged("has_no_selection");
1412 stateChanged("has_selection");
1414 KActionCollection
* col
= actionCollection();
1415 QAction
* renameAction
= col
->action("rename");
1416 QAction
* moveToTrashAction
= col
->action("move_to_trash");
1417 QAction
* deleteAction
= col
->action("delete");
1418 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
1419 QAction
* deleteWithTrashShortcut
= col
->action("delete_shortcut"); // see DolphinViewActionHandler
1421 KFileItemListProperties
capabilities(list
);
1422 const bool enableMoveToTrash
= capabilities
.isLocal() && capabilities
.supportsMoving();
1424 renameAction
->setEnabled(capabilities
.supportsMoving());
1425 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1426 deleteAction
->setEnabled(capabilities
.supportsDeleting());
1427 deleteWithTrashShortcut
->setEnabled(capabilities
.supportsDeleting() && !enableMoveToTrash
);
1428 cutAction
->setEnabled(capabilities
.supportsMoving());
1430 updatePasteAction();
1433 void DolphinMainWindow::updateViewActions()
1435 m_actionHandler
->updateViewActions();
1437 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1438 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
1440 updateSplitAction();
1442 QAction
* editableLocactionAction
= actionCollection()->action("editable_location");
1443 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
1444 editableLocactionAction
->setChecked(urlNavigator
->isUrlEditable());
1447 void DolphinMainWindow::updateGoActions()
1449 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
1450 const KUrl
& currentUrl
= m_activeViewContainer
->url();
1451 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
1454 void DolphinMainWindow::rememberClosedTab(int index
)
1456 KMenu
* tabsMenu
= m_recentTabsMenu
->menu();
1458 const QString primaryPath
= m_viewTab
[index
].primaryView
->url().path();
1459 const QString iconName
= KMimeType::iconNameForUrl(primaryPath
);
1461 QAction
* action
= new QAction(squeezedText(primaryPath
), tabsMenu
);
1463 ClosedTab closedTab
;
1464 closedTab
.primaryUrl
= m_viewTab
[index
].primaryView
->url();
1466 if (m_viewTab
[index
].secondaryView
!= 0) {
1467 closedTab
.secondaryUrl
= m_viewTab
[index
].secondaryView
->url();
1468 closedTab
.isSplit
= true;
1470 closedTab
.isSplit
= false;
1473 action
->setData(QVariant::fromValue(closedTab
));
1474 action
->setIcon(KIcon(iconName
));
1476 // add the closed tab menu entry after the separator and
1477 // "Empty Recently Closed Tabs" entry
1478 if (tabsMenu
->actions().size() == 2) {
1479 tabsMenu
->addAction(action
);
1481 tabsMenu
->insertAction(tabsMenu
->actions().at(2), action
);
1484 // assure that only up to 8 closed tabs are shown in the menu
1485 if (tabsMenu
->actions().size() > 8) {
1486 tabsMenu
->removeAction(tabsMenu
->actions().last());
1488 actionCollection()->action("closed_tabs")->setEnabled(true);
1489 KAcceleratorManager::manage(tabsMenu
);
1492 void DolphinMainWindow::clearStatusBar()
1494 m_activeViewContainer
->statusBar()->clear();
1497 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
1499 connect(container
, SIGNAL(showFilterBarChanged(bool)),
1500 this, SLOT(updateFilterBarAction(bool)));
1502 DolphinView
* view
= container
->view();
1503 connect(view
, SIGNAL(selectionChanged(KFileItemList
)),
1504 this, SLOT(slotSelectionChanged(KFileItemList
)));
1505 connect(view
, SIGNAL(requestItemInfo(KFileItem
)),
1506 this, SLOT(slotRequestItemInfo(KFileItem
)));
1507 connect(view
, SIGNAL(activated()),
1508 this, SLOT(toggleActiveView()));
1509 connect(view
, SIGNAL(tabRequested(const KUrl
&)),
1510 this, SLOT(openNewTab(const KUrl
&)));
1512 const KUrlNavigator
* navigator
= container
->urlNavigator();
1513 connect(navigator
, SIGNAL(urlChanged(const KUrl
&)),
1514 this, SLOT(changeUrl(const KUrl
&)));
1515 connect(navigator
, SIGNAL(historyChanged()),
1516 this, SLOT(updateHistory()));
1517 connect(navigator
, SIGNAL(editableStateChanged(bool)),
1518 this, SLOT(slotEditableStateChanged(bool)));
1521 void DolphinMainWindow::updateSplitAction()
1523 QAction
* splitAction
= actionCollection()->action("split_view");
1524 if (m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
1525 if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
1526 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
1527 splitAction
->setIcon(KIcon("view-right-close"));
1529 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
1530 splitAction
->setIcon(KIcon("view-left-close"));
1533 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
1534 splitAction
->setIcon(KIcon("view-right-new"));
1538 QString
DolphinMainWindow::tabName(const KUrl
& url
) const
1541 if (url
.equals(KUrl("file:///"))) {
1544 name
= url
.fileName();
1545 if (name
.isEmpty()) {
1546 name
= url
.protocol();
1548 // Make sure that a '&' inside the directory name is displayed correctly
1549 // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
1550 name
.replace('&', "&&");
1556 bool DolphinMainWindow::isKompareInstalled() const
1558 static bool initialized
= false;
1559 static bool installed
= false;
1561 // TODO: maybe replace this approach later by using a menu
1562 // plugin like kdiff3plugin.cpp
1563 installed
= !KGlobal::dirs()->findExe("kompare").isEmpty();
1569 void DolphinMainWindow::createSecondaryView(int tabIndex
)
1571 QSplitter
* splitter
= m_viewTab
[tabIndex
].splitter
;
1572 const int newWidth
= (m_viewTab
[tabIndex
].primaryView
->width() - splitter
->handleWidth()) / 2;
1574 const DolphinView
* view
= m_viewTab
[tabIndex
].primaryView
->view();
1575 m_viewTab
[tabIndex
].secondaryView
= new DolphinViewContainer(this, 0, view
->rootUrl());
1576 splitter
->addWidget(m_viewTab
[tabIndex
].secondaryView
);
1577 splitter
->setSizes(QList
<int>() << newWidth
<< newWidth
);
1578 connectViewSignals(m_viewTab
[tabIndex
].secondaryView
);
1579 m_viewTab
[tabIndex
].secondaryView
->view()->reload();
1580 m_viewTab
[tabIndex
].secondaryView
->setActive(false);
1581 m_viewTab
[tabIndex
].secondaryView
->show();
1584 QString
DolphinMainWindow::tabProperty(const QString
& property
, int tabIndex
) const
1586 return "Tab " + QString::number(tabIndex
) + ' ' + property
;
1589 void DolphinMainWindow::setUrlAsCaption(const KUrl
& url
)
1592 if (url
.equals(KUrl("file:///"))) {
1595 caption
= url
.fileName();
1596 if (caption
.isEmpty()) {
1597 caption
= url
.protocol();
1601 setCaption(caption
);
1604 QString
DolphinMainWindow::squeezedText(const QString
& text
) const
1606 const QFontMetrics fm
= fontMetrics();
1607 return fm
.elidedText(text
, Qt::ElideMiddle
, fm
.maxWidth() * 10);
1610 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
1611 KIO::FileUndoManager::UiInterface()
1615 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
1619 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
1621 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
1623 DolphinStatusBar
* statusBar
= mainWin
->activeViewContainer()->statusBar();
1624 statusBar
->setMessage(job
->errorString(), DolphinStatusBar::Error
);
1626 KIO::FileUndoManager::UiInterface::jobError(job
);
1630 #include "dolphinmainwindow.moc"