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 "settings/dolphinsettings.h"
31 #include "settings/dolphinsettingsdialog.h"
32 #include "dolphinsearchbox.h"
33 #include "dolphinviewcontainer.h"
34 #include "panels/folders/folderspanel.h"
35 #include "panels/places/placespanel.h"
36 #include "panels/information/informationpanel.h"
37 #include "panels/information/metadatawidget.h"
38 #include "mainwindowadaptor.h"
39 #include "statusbar/dolphinstatusbar.h"
40 #include "viewproperties.h"
43 #include "panels/terminal/terminalpanel.h"
46 #include "dolphin_generalsettings.h"
47 #include "dolphin_iconsmodesettings.h"
48 #include "draganddrophelper.h"
51 #include <kactioncollection.h>
53 #include <kdesktopfile.h>
54 #include <kdeversion.h>
55 #include <kfiledialog.h>
56 #include <kfileplacesmodel.h>
58 #include <klineedit.h>
61 #include <kiconloader.h>
62 #include <kio/netaccess.h>
63 #include <kinputdialog.h>
65 #include <kprotocolmanager.h>
68 #include <kmessagebox.h>
69 #include <kfileitemlistproperties.h>
70 #include <konqmimedata.h>
71 #include <kprotocolinfo.h>
74 #include <kstandarddirs.h>
75 #include <kstatusbar.h>
76 #include <kstandardaction.h>
78 #include <ktoggleaction.h>
79 #include <kurlnavigator.h>
81 #include <kurlcombobox.h>
82 #include <ktoolinvocation.h>
84 #include <QDBusMessage>
88 #include <QDockWidget>
89 #include <kacceleratormanager.h>
92 * Remembers the tab configuration if a tab has been closed.
93 * Each closed tab can be restored by the menu
94 * "Go -> Recently Closed Tabs".
102 Q_DECLARE_METATYPE(ClosedTab
)
104 DolphinMainWindow::DolphinMainWindow(int id
) :
109 m_activeViewContainer(0),
110 m_centralWidgetLayout(0),
119 setObjectName("Dolphin#");
121 m_viewTab
.append(ViewTab());
123 new MainWindowAdaptor(this);
124 QDBusConnection::sessionBus().registerObject(QString("/dolphin/MainWindow%1").arg(m_id
), this);
126 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
127 undoManager
->setUiInterface(new UndoUiInterface());
129 connect(undoManager
, SIGNAL(undoAvailable(bool)),
130 this, SLOT(slotUndoAvailable(bool)));
131 connect(undoManager
, SIGNAL(undoTextChanged(const QString
&)),
132 this, SLOT(slotUndoTextChanged(const QString
&)));
133 connect(undoManager
, SIGNAL(jobRecordingStarted(CommandType
)),
134 this, SLOT(clearStatusBar()));
135 connect(undoManager
, SIGNAL(jobRecordingFinished(CommandType
)),
136 this, SLOT(showCommand(CommandType
)));
137 connect(DolphinSettings::instance().placesModel(), SIGNAL(errorMessage(const QString
&)),
138 this, SLOT(showErrorMessage(const QString
&)));
139 connect(&DragAndDropHelper::instance(), SIGNAL(errorMessage(const QString
&)),
140 this, SLOT(showErrorMessage(const QString
&)));
143 DolphinMainWindow::~DolphinMainWindow()
145 DolphinApplication::app()->removeMainWindow(this);
148 void DolphinMainWindow::toggleViews()
150 if (m_viewTab
[m_tabIndex
].primaryView
== 0) {
154 // move secondary view from the last position of the splitter
155 // to the first position
156 m_viewTab
[m_tabIndex
].splitter
->insertWidget(0, m_viewTab
[m_tabIndex
].secondaryView
);
158 DolphinViewContainer
* container
= m_viewTab
[m_tabIndex
].primaryView
;
159 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
160 m_viewTab
[m_tabIndex
].secondaryView
= container
;
163 void DolphinMainWindow::showCommand(CommandType command
)
165 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
167 case KIO::FileUndoManager::Copy
:
168 statusBar
->setMessage(i18nc("@info:status", "Copy operation completed."),
169 DolphinStatusBar::OperationCompleted
);
171 case KIO::FileUndoManager::Move
:
172 statusBar
->setMessage(i18nc("@info:status", "Move operation completed."),
173 DolphinStatusBar::OperationCompleted
);
175 case KIO::FileUndoManager::Link
:
176 statusBar
->setMessage(i18nc("@info:status", "Link operation completed."),
177 DolphinStatusBar::OperationCompleted
);
179 case KIO::FileUndoManager::Trash
:
180 statusBar
->setMessage(i18nc("@info:status", "Move to trash operation completed."),
181 DolphinStatusBar::OperationCompleted
);
183 case KIO::FileUndoManager::Rename
:
184 statusBar
->setMessage(i18nc("@info:status", "Renaming operation completed."),
185 DolphinStatusBar::OperationCompleted
);
188 case KIO::FileUndoManager::Mkdir
:
189 statusBar
->setMessage(i18nc("@info:status", "Created folder."),
190 DolphinStatusBar::OperationCompleted
);
198 void DolphinMainWindow::refreshViews()
200 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
202 // remember the current active view, as because of
203 // the refreshing the active view might change to
204 // the secondary view
205 DolphinViewContainer
* activeViewContainer
= m_activeViewContainer
;
207 const int tabCount
= m_viewTab
.count();
208 for (int i
= 0; i
< tabCount
; ++i
) {
209 m_viewTab
[i
].primaryView
->refresh();
210 if (m_viewTab
[i
].secondaryView
!= 0) {
211 m_viewTab
[i
].secondaryView
->refresh();
215 setActiveViewContainer(activeViewContainer
);
218 void DolphinMainWindow::pasteIntoFolder()
220 m_activeViewContainer
->view()->pasteIntoFolder();
223 void DolphinMainWindow::changeUrl(const KUrl
& url
)
225 if (!KProtocolManager::supportsListing(url
)) {
226 // The URL navigator only checks for validity, not
227 // if the URL can be listed. An error message is
228 // shown due to DolphinViewContainer::restoreView().
232 DolphinViewContainer
* view
= activeViewContainer();
238 setUrlAsCaption(url
);
239 if (m_viewTab
.count() > 1) {
240 m_tabBar
->setTabText(m_tabIndex
, squeezedText(tabName(m_activeViewContainer
->url())));
242 const QString iconName
= KMimeType::iconNameForUrl(url
);
243 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(iconName
));
244 emit
urlChanged(url
);
248 void DolphinMainWindow::changeSelection(const KFileItemList
& selection
)
250 activeViewContainer()->view()->changeSelection(selection
);
253 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
255 KToggleAction
* editableLocationAction
=
256 static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
257 editableLocationAction
->setChecked(editable
);
260 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
264 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
265 int selectedUrlsCount
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedItemsCount();
266 if (m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
267 selectedUrlsCount
+= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItemsCount();
270 QAction
* compareFilesAction
= actionCollection()->action("compare_files");
271 if (selectedUrlsCount
== 2) {
272 compareFilesAction
->setEnabled(isKompareInstalled());
274 compareFilesAction
->setEnabled(false);
277 emit
selectionChanged(selection
);
280 void DolphinMainWindow::slotWheelMoved(int wheelDelta
)
282 if (wheelDelta
> 0) {
289 void DolphinMainWindow::slotRequestItemInfo(const KFileItem
& item
)
291 emit
requestItemInfo(item
);
294 void DolphinMainWindow::updateHistory()
296 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
297 const int index
= urlNavigator
->historyIndex();
299 QAction
* backAction
= actionCollection()->action("go_back");
300 if (backAction
!= 0) {
301 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
304 QAction
* forwardAction
= actionCollection()->action("go_forward");
305 if (forwardAction
!= 0) {
306 forwardAction
->setEnabled(index
> 0);
310 void DolphinMainWindow::updateFilterBarAction(bool show
)
312 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
313 showFilterBarAction
->setChecked(show
);
316 void DolphinMainWindow::openNewMainWindow()
318 DolphinApplication::app()->createMainWindow()->show();
321 void DolphinMainWindow::openNewTab()
323 openNewTab(m_activeViewContainer
->url());
324 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
326 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
327 if (navigator
->isUrlEditable()) {
328 // if a new tab is opened and the URL is editable, assure that
329 // the user can edit the URL without manually setting the focus
330 navigator
->setFocus();
334 void DolphinMainWindow::openNewTab(const KUrl
& url
)
336 const KIcon icon
= KIcon(KMimeType::iconNameForUrl(m_activeViewContainer
->url()));
337 if (m_viewTab
.count() == 1) {
338 // Only one view is open currently and hence no tab is shown at
339 // all. Before creating a tab for 'url', provide a tab for the current URL.
340 m_tabBar
->addTab(icon
, squeezedText(tabName(m_activeViewContainer
->url())));
341 m_tabBar
->blockSignals(false);
344 m_tabBar
->addTab(icon
, squeezedText(tabName(url
)));
347 viewTab
.splitter
= new QSplitter(this);
348 viewTab
.splitter
->setChildrenCollapsible(false);
349 viewTab
.primaryView
= new DolphinViewContainer(this, viewTab
.splitter
, url
);
350 viewTab
.primaryView
->setActive(false);
351 connectViewSignals(viewTab
.primaryView
);
352 viewTab
.primaryView
->view()->reload();
354 m_viewTab
.append(viewTab
);
356 actionCollection()->action("close_tab")->setEnabled(true);
358 // provide a split view, if the startup settings are set this way
359 const GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
360 if (generalSettings
->splitView()) {
361 const int tabIndex
= m_viewTab
.count() - 1;
362 createSecondaryView(tabIndex
);
363 m_viewTab
[tabIndex
].secondaryView
->setActive(true);
364 m_viewTab
[tabIndex
].isPrimaryViewActive
= false;
368 void DolphinMainWindow::activateNextTab()
370 if ((m_viewTab
.count() == 1) || (m_tabBar
->count() < 2)) {
374 const int tabIndex
= (m_tabBar
->currentIndex() + 1) % m_tabBar
->count();
375 m_tabBar
->setCurrentIndex(tabIndex
);
378 void DolphinMainWindow::activatePrevTab()
380 if ((m_viewTab
.count() == 1) || (m_tabBar
->count() < 2)) {
384 int tabIndex
= m_tabBar
->currentIndex() - 1;
385 if (tabIndex
== -1) {
386 tabIndex
= m_tabBar
->count() - 1;
388 m_tabBar
->setCurrentIndex(tabIndex
);
391 void DolphinMainWindow::openInNewTab()
393 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
394 if ((list
.count() == 1) && list
[0].isDir()) {
395 openNewTab(m_activeViewContainer
->view()->selectedUrls()[0]);
399 void DolphinMainWindow::openInNewWindow()
401 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
402 if ((list
.count() == 1) && list
[0].isDir()) {
403 DolphinMainWindow
* window
= DolphinApplication::app()->createMainWindow();
404 window
->changeUrl(m_activeViewContainer
->view()->selectedUrls()[0]);
409 void DolphinMainWindow::toggleActiveView()
411 if (m_viewTab
[m_tabIndex
].secondaryView
== 0) {
412 // only one view is available
416 Q_ASSERT(m_activeViewContainer
!= 0);
417 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
419 DolphinViewContainer
* left
= m_viewTab
[m_tabIndex
].primaryView
;
420 DolphinViewContainer
* right
= m_viewTab
[m_tabIndex
].secondaryView
;
421 setActiveViewContainer(m_activeViewContainer
== right
? left
: right
);
424 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
426 DolphinSettings
& settings
= DolphinSettings::instance();
427 GeneralSettings
* generalSettings
= settings
.generalSettings();
429 // Find out if Dolphin is closed directly by the user or
430 // by the session manager because the session is closed
431 bool closedByUser
= true;
432 DolphinApplication
*application
= qobject_cast
<DolphinApplication
*>(qApp
);
433 if (application
&& application
->sessionSaving()) {
434 closedByUser
= false;
437 if ((m_viewTab
.count() > 1) && generalSettings
->confirmClosingMultipleTabs() && closedByUser
) {
438 // Ask the user if he really wants to quit and close all tabs.
439 // Open a confirmation dialog with 3 buttons:
440 // KDialog::Yes -> Quit
441 // KDialog::No -> Close only the current tab
442 // KDialog::Cancel -> do nothing
443 KDialog
*dialog
= new KDialog(this, Qt::Dialog
);
444 dialog
->setCaption(i18nc("@title:window", "Confirmation"));
445 dialog
->setButtons(KDialog::Yes
| KDialog::No
| KDialog::Cancel
);
446 dialog
->setModal(true);
447 dialog
->showButtonSeparator(true);
448 dialog
->setButtonGuiItem(KDialog::Yes
, KStandardGuiItem::quit());
449 dialog
->setButtonGuiItem(KDialog::No
, KGuiItem(i18n("C&lose Current Tab"), KIcon("tab-close")));
450 dialog
->setButtonGuiItem(KDialog::Cancel
, KStandardGuiItem::cancel());
451 dialog
->setDefaultButton(KDialog::Yes
);
453 bool doNotAskAgainCheckboxResult
= false;
455 const int result
= KMessageBox::createKMessageBox(dialog
,
456 QMessageBox::Warning
,
457 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
459 i18n("Do not ask again"),
460 &doNotAskAgainCheckboxResult
,
461 KMessageBox::Notify
);
463 if (doNotAskAgainCheckboxResult
) {
464 generalSettings
->setConfirmClosingMultipleTabs(false);
472 // Close only the current tab
480 generalSettings
->setFirstRun(false);
484 KXmlGuiWindow::closeEvent(event
);
487 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
489 const int tabCount
= m_viewTab
.count();
490 group
.writeEntry("Tab Count", tabCount
);
491 group
.writeEntry("Active Tab Index", m_tabBar
->currentIndex());
493 for (int i
= 0; i
< tabCount
; ++i
) {
494 const DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
495 group
.writeEntry(tabProperty("Primary URL", i
), cont
->url().url());
496 group
.writeEntry(tabProperty("Primary Editable", i
), cont
->isUrlEditable());
498 cont
= m_viewTab
[i
].secondaryView
;
500 group
.writeEntry(tabProperty("Secondary URL", i
), cont
->url().url());
501 group
.writeEntry(tabProperty("Secondary Editable", i
), cont
->isUrlEditable());
506 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
508 const int tabCount
= group
.readEntry("Tab Count", 1);
509 for (int i
= 0; i
< tabCount
; ++i
) {
510 DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
512 cont
->setUrl(group
.readEntry(tabProperty("Primary URL", i
)));
513 const bool editable
= group
.readEntry(tabProperty("Primary Editable", i
), false);
514 cont
->urlNavigator()->setUrlEditable(editable
);
516 cont
= m_viewTab
[i
].secondaryView
;
517 const QString secondaryUrl
= group
.readEntry(tabProperty("Secondary URL", i
));
518 if (!secondaryUrl
.isEmpty()) {
520 // a secondary view should be shown, but no one is available
521 // currently -> create a new view
523 cont
= m_viewTab
[i
].secondaryView
;
527 cont
->setUrl(secondaryUrl
);
528 const bool editable
= group
.readEntry(tabProperty("Secondary Editable", i
), false);
529 cont
->urlNavigator()->setUrlEditable(editable
);
530 } else if (cont
!= 0) {
531 // no secondary view should be shown, but the default setting shows
532 // one already -> close the view
536 // openNewTab() needs to be called only tabCount - 1 times
537 if (i
!= tabCount
- 1) {
542 const int index
= group
.readEntry("Active Tab Index", 0);
543 m_tabBar
->setCurrentIndex(index
);
546 void DolphinMainWindow::updateNewMenu()
548 m_newMenu
->slotCheckUpToDate();
549 m_newMenu
->setPopupFiles(activeViewContainer()->url());
552 void DolphinMainWindow::createDirectory()
554 m_newMenu
->setPopupFiles(activeViewContainer()->url());
555 m_newMenu
->createDirectory();
558 void DolphinMainWindow::quit()
563 void DolphinMainWindow::showErrorMessage(const QString
& message
)
565 if (!message
.isEmpty()) {
566 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
567 statusBar
->setMessage(message
, DolphinStatusBar::Error
);
571 void DolphinMainWindow::slotUndoAvailable(bool available
)
573 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
574 if (undoAction
!= 0) {
575 undoAction
->setEnabled(available
);
579 void DolphinMainWindow::restoreClosedTab(QAction
* action
)
581 if (action
->data().toBool()) {
582 // clear all actions except the "Empty Recently Closed Tabs"
583 // action and the separator
584 QList
<QAction
*> actions
= m_recentTabsMenu
->menu()->actions();
585 const int count
= actions
.size();
586 for (int i
= 2; i
< count
; ++i
) {
587 m_recentTabsMenu
->menu()->removeAction(actions
.at(i
));
590 const ClosedTab closedTab
= action
->data().value
<ClosedTab
>();
591 openNewTab(closedTab
.primaryUrl
);
592 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
594 if (closedTab
.isSplit
) {
595 // create secondary view
597 m_viewTab
[m_tabIndex
].secondaryView
->setUrl(closedTab
.secondaryUrl
);
600 m_recentTabsMenu
->removeAction(action
);
603 if (m_recentTabsMenu
->menu()->actions().count() == 2) {
604 m_recentTabsMenu
->setEnabled(false);
608 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
610 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
611 if (undoAction
!= 0) {
612 undoAction
->setText(text
);
616 void DolphinMainWindow::undo()
619 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
620 KIO::FileUndoManager::self()->undo();
623 void DolphinMainWindow::cut()
625 m_activeViewContainer
->view()->cutSelectedItems();
628 void DolphinMainWindow::copy()
630 m_activeViewContainer
->view()->copySelectedItems();
633 void DolphinMainWindow::paste()
635 m_activeViewContainer
->view()->paste();
638 void DolphinMainWindow::updatePasteAction()
640 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
641 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
642 pasteAction
->setEnabled(pasteInfo
.first
);
643 pasteAction
->setText(pasteInfo
.second
);
646 void DolphinMainWindow::selectAll()
650 // if the URL navigator is editable and focused, select the whole
651 // URL instead of all items of the view
653 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
654 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit(); // krazy:exclude=qclasses
655 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
656 lineEdit
->hasFocus();
658 lineEdit
->selectAll();
660 m_activeViewContainer
->view()->selectAll();
664 void DolphinMainWindow::invertSelection()
667 m_activeViewContainer
->view()->invertSelection();
670 void DolphinMainWindow::toggleSplitView()
672 if (m_viewTab
[m_tabIndex
].secondaryView
== 0) {
673 createSecondaryView(m_tabIndex
);
674 setActiveViewContainer(m_viewTab
[m_tabIndex
].secondaryView
);
675 } else if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
676 // remove secondary view
677 m_viewTab
[m_tabIndex
].secondaryView
->close();
678 m_viewTab
[m_tabIndex
].secondaryView
->deleteLater();
679 m_viewTab
[m_tabIndex
].secondaryView
= 0;
681 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
683 // The primary view is active and should be closed. Hence from a users point of view
684 // the content of the secondary view should be moved to the primary view.
685 // From an implementation point of view it is more efficient to close
686 // the primary view and exchange the internal pointers afterwards.
688 m_viewTab
[m_tabIndex
].primaryView
->close();
689 m_viewTab
[m_tabIndex
].primaryView
->deleteLater();
690 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
691 m_viewTab
[m_tabIndex
].secondaryView
= 0;
693 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
699 void DolphinMainWindow::reloadView()
702 m_activeViewContainer
->view()->reload();
705 void DolphinMainWindow::stopLoading()
709 void DolphinMainWindow::toggleFilterBarVisibility(bool show
)
711 m_activeViewContainer
->showFilterBar(show
);
714 void DolphinMainWindow::toggleEditLocation()
718 QAction
* action
= actionCollection()->action("editable_location");
719 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
720 urlNavigator
->setUrlEditable(action
->isChecked());
723 void DolphinMainWindow::replaceLocation()
725 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
726 navigator
->setUrlEditable(true);
727 navigator
->setFocus();
729 // select the whole text of the combo box editor
730 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit(); // krazy:exclude=qclasses
731 const QString text
= lineEdit
->text();
732 lineEdit
->setSelection(0, text
.length());
735 void DolphinMainWindow::goBack()
738 m_activeViewContainer
->urlNavigator()->goBack();
741 void DolphinMainWindow::goForward()
744 m_activeViewContainer
->urlNavigator()->goForward();
747 void DolphinMainWindow::goUp()
750 m_activeViewContainer
->urlNavigator()->goUp();
753 void DolphinMainWindow::goHome()
756 m_activeViewContainer
->urlNavigator()->goHome();
759 void DolphinMainWindow::compareFiles()
761 // The method is only invoked if exactly 2 files have
762 // been selected. The selected files may be:
763 // - both in the primary view
764 // - both in the secondary view
765 // - one in the primary view and the other in the secondary
767 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
771 KUrl::List urls
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedUrls();
773 switch (urls
.count()) {
775 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
!= 0);
776 urls
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedUrls();
777 Q_ASSERT(urls
.count() == 2);
785 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
!= 0);
786 urls
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedUrls();
787 Q_ASSERT(urls
.count() == 1);
799 // may not happen: compareFiles may only get invoked if 2
800 // files are selected
805 QString
command("kompare -c \"");
806 command
.append(urlA
.pathOrUrl());
807 command
.append("\" \"");
808 command
.append(urlB
.pathOrUrl());
809 command
.append('\"');
810 KRun::runCommand(command
, "Kompare", "kompare", this);
813 void DolphinMainWindow::toggleShowMenuBar()
815 const bool visible
= menuBar()->isVisible();
816 menuBar()->setVisible(!visible
);
819 void DolphinMainWindow::openTerminal()
821 QString
dir(QDir::homePath());
823 // If the given directory is not local, it can still be the URL of an
824 // ioslave using UDS_LOCAL_PATH which to be converted first.
825 KUrl url
= KIO::NetAccess::mostLocalUrl(m_activeViewContainer
->url(), this);
827 //If the URL is local after the above conversion, set the directory.
828 if (url
.isLocalFile()) {
829 dir
= url
.toLocalFile();
832 KToolInvocation::invokeTerminal(QString(), dir
);
835 void DolphinMainWindow::editSettings()
837 if (m_settingsDialog
== 0) {
838 const KUrl
& url
= activeViewContainer()->url();
839 m_settingsDialog
= new DolphinSettingsDialog(url
, this);
840 m_settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
841 m_settingsDialog
->show();
843 m_settingsDialog
->raise();
847 void DolphinMainWindow::setActiveTab(int index
)
849 Q_ASSERT(index
>= 0);
850 Q_ASSERT(index
< m_viewTab
.count());
851 if (index
== m_tabIndex
) {
855 // hide current tab content
856 ViewTab
& hiddenTab
= m_viewTab
[m_tabIndex
];
857 hiddenTab
.isPrimaryViewActive
= hiddenTab
.primaryView
->isActive();
858 hiddenTab
.primaryView
->setActive(false);
859 if (hiddenTab
.secondaryView
!= 0) {
860 hiddenTab
.secondaryView
->setActive(false);
862 QSplitter
* splitter
= m_viewTab
[m_tabIndex
].splitter
;
864 m_centralWidgetLayout
->removeWidget(splitter
);
866 // show active tab content
869 ViewTab
& viewTab
= m_viewTab
[index
];
870 m_centralWidgetLayout
->addWidget(viewTab
.splitter
);
871 viewTab
.primaryView
->show();
872 if (viewTab
.secondaryView
!= 0) {
873 viewTab
.secondaryView
->show();
875 viewTab
.splitter
->show();
877 setActiveViewContainer(viewTab
.isPrimaryViewActive
? viewTab
.primaryView
:
878 viewTab
.secondaryView
);
881 void DolphinMainWindow::closeTab()
883 closeTab(m_tabBar
->currentIndex());
886 void DolphinMainWindow::closeTab(int index
)
888 Q_ASSERT(index
>= 0);
889 Q_ASSERT(index
< m_viewTab
.count());
890 if (m_viewTab
.count() == 1) {
891 // the last tab may never get closed
895 if (index
== m_tabIndex
) {
896 // The tab that should be closed is the active tab. Activate the
897 // previous tab before closing the tab.
898 m_tabBar
->setCurrentIndex((index
> 0) ? index
- 1 : 1);
900 rememberClosedTab(index
);
903 m_viewTab
[index
].primaryView
->deleteLater();
904 if (m_viewTab
[index
].secondaryView
!= 0) {
905 m_viewTab
[index
].secondaryView
->deleteLater();
907 m_viewTab
[index
].splitter
->deleteLater();
908 m_viewTab
.erase(m_viewTab
.begin() + index
);
910 m_tabBar
->blockSignals(true);
911 m_tabBar
->removeTab(index
);
913 if (m_tabIndex
> index
) {
915 Q_ASSERT(m_tabIndex
>= 0);
918 // if only one tab is left, also remove the tab entry so that
919 // closing the last tab is not possible
920 if (m_viewTab
.count() == 1) {
921 m_tabBar
->removeTab(0);
922 actionCollection()->action("close_tab")->setEnabled(false);
924 m_tabBar
->blockSignals(false);
928 void DolphinMainWindow::openTabContextMenu(int index
, const QPoint
& pos
)
932 QAction
* newTabAction
= menu
.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab"));
933 newTabAction
->setShortcut(actionCollection()->action("new_tab")->shortcut());
935 QAction
* closeOtherTabsAction
= menu
.addAction(KIcon("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs"));
937 QAction
* closeTabAction
= menu
.addAction(KIcon("tab-close"), i18nc("@action:inmenu", "Close Tab"));
938 closeTabAction
->setShortcut(actionCollection()->action("close_tab")->shortcut());
939 QAction
* selectedAction
= menu
.exec(pos
);
940 if (selectedAction
== newTabAction
) {
941 const ViewTab
& tab
= m_viewTab
[index
];
942 Q_ASSERT(tab
.primaryView
!= 0);
943 const KUrl url
= (tab
.secondaryView
!= 0) && tab
.secondaryView
->isActive() ?
944 tab
.secondaryView
->url() : tab
.primaryView
->url();
946 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
947 } else if (selectedAction
== closeOtherTabsAction
) {
948 const int count
= m_tabBar
->count();
949 for (int i
= 0; i
< index
; ++i
) {
952 for (int i
= index
+ 1; i
< count
; ++i
) {
955 } else if (selectedAction
== closeTabAction
) {
960 void DolphinMainWindow::handlePlacesClick(const KUrl
& url
, Qt::MouseButtons buttons
)
962 if (buttons
& Qt::MidButton
) {
964 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
970 void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent
* event
, bool& canDecode
)
972 canDecode
= KUrl::List::canDecode(event
->mimeData());
975 void DolphinMainWindow::searchItems(const KUrl
& url
)
977 m_activeViewContainer
->setUrl(url
);
980 void DolphinMainWindow::slotTabMoved(int from
, int to
)
982 m_viewTab
.move(from
, to
);
983 m_tabIndex
= m_tabBar
->currentIndex();
986 void DolphinMainWindow::init()
988 DolphinSettings
& settings
= DolphinSettings::instance();
990 // Check whether Dolphin runs the first time. If yes then
991 // a proper default window size is given at the end of DolphinMainWindow::init().
992 GeneralSettings
* generalSettings
= settings
.generalSettings();
993 const bool firstRun
= generalSettings
->firstRun();
995 generalSettings
->setViewPropsTimestamp(QDateTime::currentDateTime());
998 setAcceptDrops(true);
1000 m_viewTab
[m_tabIndex
].splitter
= new QSplitter(this);
1001 m_viewTab
[m_tabIndex
].splitter
->setChildrenCollapsible(false);
1005 const KUrl
& homeUrl
= generalSettings
->homeUrl();
1006 setUrlAsCaption(homeUrl
);
1007 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
1008 connect(m_actionHandler
, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
1009 connect(m_actionHandler
, SIGNAL(createDirectory()), SLOT(createDirectory()));
1010 ViewProperties
props(homeUrl
);
1011 m_viewTab
[m_tabIndex
].primaryView
= new DolphinViewContainer(this,
1012 m_viewTab
[m_tabIndex
].splitter
,
1015 m_activeViewContainer
= m_viewTab
[m_tabIndex
].primaryView
;
1016 connectViewSignals(m_activeViewContainer
);
1017 DolphinView
* view
= m_activeViewContainer
->view();
1019 m_activeViewContainer
->show();
1020 m_actionHandler
->setCurrentView(view
);
1022 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
1023 connect(this, SIGNAL(urlChanged(const KUrl
&)),
1024 m_remoteEncoding
, SLOT(slotAboutToOpenUrl()));
1026 m_tabBar
= new KTabBar(this);
1027 m_tabBar
->setMovable(true);
1028 m_tabBar
->setTabsClosable(true);
1029 connect(m_tabBar
, SIGNAL(currentChanged(int)),
1030 this, SLOT(setActiveTab(int)));
1031 connect(m_tabBar
, SIGNAL(tabCloseRequested(int)),
1032 this, SLOT(closeTab(int)));
1033 connect(m_tabBar
, SIGNAL(contextMenu(int, const QPoint
&)),
1034 this, SLOT(openTabContextMenu(int, const QPoint
&)));
1035 connect(m_tabBar
, SIGNAL(newTabRequest()),
1036 this, SLOT(openNewTab()));
1037 connect(m_tabBar
, SIGNAL(testCanDecode(const QDragMoveEvent
*, bool&)),
1038 this, SLOT(slotTestCanDecode(const QDragMoveEvent
*, bool&)));
1039 connect(m_tabBar
, SIGNAL(wheelDelta(int)),
1040 this, SLOT(slotWheelMoved(int)));
1041 connect(m_tabBar
, SIGNAL(mouseMiddleClick(int)),
1042 this, SLOT(closeTab(int)));
1043 connect(m_tabBar
, SIGNAL(tabMoved(int, int)),
1044 this, SLOT(slotTabMoved(int, int)));
1046 m_tabBar
->blockSignals(true); // signals get unblocked after at least 2 tabs are open
1048 QWidget
* centralWidget
= new QWidget(this);
1049 m_centralWidgetLayout
= new QVBoxLayout(centralWidget
);
1050 m_centralWidgetLayout
->setSpacing(0);
1051 m_centralWidgetLayout
->setMargin(0);
1052 m_centralWidgetLayout
->addWidget(m_tabBar
);
1053 m_centralWidgetLayout
->addWidget(m_viewTab
[m_tabIndex
].splitter
);
1055 setCentralWidget(centralWidget
);
1057 emit
urlChanged(homeUrl
);
1059 setupGUI(Keys
| Save
| Create
| ToolBar
);
1061 m_searchBox
->setParent(toolBar("searchToolBar"));
1062 m_searchBox
->show();
1064 stateChanged("new_file");
1066 QClipboard
* clipboard
= QApplication::clipboard();
1067 connect(clipboard
, SIGNAL(dataChanged()),
1068 this, SLOT(updatePasteAction()));
1069 updatePasteAction();
1072 if (generalSettings
->splitView()) {
1075 updateViewActions();
1077 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1078 showFilterBarAction
->setChecked(generalSettings
->filterBar());
1081 // assure a proper default size if Dolphin runs the first time
1085 m_showMenuBar
->setChecked(!menuBar()->isHidden()); // workaround for bug #171080
1088 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer
* viewContainer
)
1090 Q_ASSERT(viewContainer
!= 0);
1091 Q_ASSERT((viewContainer
== m_viewTab
[m_tabIndex
].primaryView
) ||
1092 (viewContainer
== m_viewTab
[m_tabIndex
].secondaryView
));
1093 if (m_activeViewContainer
== viewContainer
) {
1097 m_activeViewContainer
->setActive(false);
1098 m_activeViewContainer
= viewContainer
;
1100 // Activating the view container might trigger a recursive setActiveViewContainer() call
1101 // inside DolphinMainWindow::toggleActiveView() when having a split view. Temporary
1102 // disconnect the activated() signal in this case:
1103 disconnect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1104 m_activeViewContainer
->setActive(true);
1105 connect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1107 m_actionHandler
->setCurrentView(viewContainer
->view());
1110 updateEditActions();
1111 updateViewActions();
1114 const KUrl
& url
= m_activeViewContainer
->url();
1115 setUrlAsCaption(url
);
1116 if (m_viewTab
.count() > 1 && m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
1117 m_tabBar
->setTabText(m_tabIndex
, tabName(url
));
1118 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(KMimeType::iconNameForUrl(url
)));
1121 emit
urlChanged(url
);
1124 void DolphinMainWindow::setupActions()
1126 // setup 'File' menu
1127 m_newMenu
= new DolphinNewMenu(this, this);
1128 KMenu
* menu
= m_newMenu
->menu();
1129 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1130 menu
->setIcon(KIcon("document-new"));
1131 connect(menu
, SIGNAL(aboutToShow()),
1132 this, SLOT(updateNewMenu()));
1134 KAction
* newWindow
= actionCollection()->addAction("new_window");
1135 newWindow
->setIcon(KIcon("window-new"));
1136 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1137 newWindow
->setShortcut(Qt::CTRL
| Qt::Key_N
);
1138 connect(newWindow
, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1140 KAction
* newTab
= actionCollection()->addAction("new_tab");
1141 newTab
->setIcon(KIcon("tab-new"));
1142 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1143 newTab
->setShortcut(KShortcut(Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
));
1144 connect(newTab
, SIGNAL(triggered()), this, SLOT(openNewTab()));
1146 KAction
* closeTab
= actionCollection()->addAction("close_tab");
1147 closeTab
->setIcon(KIcon("tab-close"));
1148 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1149 closeTab
->setShortcut(Qt::CTRL
| Qt::Key_W
);
1150 closeTab
->setEnabled(false);
1151 connect(closeTab
, SIGNAL(triggered()), this, SLOT(closeTab()));
1153 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1155 // setup 'Edit' menu
1156 KStandardAction::undo(this,
1158 actionCollection());
1160 // need to remove shift+del from cut action, else the shortcut for deletejob
1162 KAction
* cut
= KStandardAction::cut(this, SLOT(cut()), actionCollection());
1163 KShortcut cutShortcut
= cut
->shortcut();
1164 cutShortcut
.remove(Qt::SHIFT
+ Qt::Key_Delete
, KShortcut::KeepEmpty
);
1165 cut
->setShortcut(cutShortcut
);
1166 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1167 KAction
* paste
= KStandardAction::paste(this, SLOT(paste()), actionCollection());
1168 // The text of the paste-action is modified dynamically by Dolphin
1169 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1170 // due to the long text, the text "Paste" is used:
1171 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1173 KAction
* selectAll
= actionCollection()->addAction("select_all");
1174 selectAll
->setText(i18nc("@action:inmenu Edit", "Select All"));
1175 selectAll
->setShortcut(Qt::CTRL
+ Qt::Key_A
);
1176 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
1178 KAction
* invertSelection
= actionCollection()->addAction("invert_selection");
1179 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1180 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1181 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
1183 // setup 'View' menu
1184 // (note that most of it is set up in DolphinViewActionHandler)
1186 KAction
* split
= actionCollection()->addAction("split_view");
1187 split
->setShortcut(Qt::Key_F3
);
1188 updateSplitAction();
1189 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1191 KAction
* reload
= actionCollection()->addAction("reload");
1192 reload
->setText(i18nc("@action:inmenu View", "Reload"));
1193 reload
->setShortcut(Qt::Key_F5
);
1194 reload
->setIcon(KIcon("view-refresh"));
1195 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
1197 KAction
* stop
= actionCollection()->addAction("stop");
1198 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1199 stop
->setIcon(KIcon("process-stop"));
1200 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
1202 KToggleAction
* showFullLocation
= actionCollection()->add
<KToggleAction
>("editable_location");
1203 showFullLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1204 showFullLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
1205 connect(showFullLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1207 KAction
* replaceLocation
= actionCollection()->addAction("replace_location");
1208 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1209 replaceLocation
->setShortcut(Qt::Key_F6
);
1210 connect(replaceLocation
, SIGNAL(triggered()), this, SLOT(replaceLocation()));
1213 KAction
* backAction
= KStandardAction::back(this, SLOT(goBack()), actionCollection());
1214 KShortcut backShortcut
= backAction
->shortcut();
1215 backShortcut
.setAlternate(Qt::Key_Backspace
);
1216 backAction
->setShortcut(backShortcut
);
1218 m_recentTabsMenu
= new KActionMenu(i18n("Recently Closed Tabs"), this);
1219 m_recentTabsMenu
->setIcon(KIcon("edit-undo"));
1220 actionCollection()->addAction("closed_tabs", m_recentTabsMenu
);
1221 connect(m_recentTabsMenu
->menu(), SIGNAL(triggered(QAction
*)),
1222 this, SLOT(restoreClosedTab(QAction
*)));
1224 QAction
* action
= new QAction("Empty Recently Closed Tabs", m_recentTabsMenu
);
1225 action
->setIcon(KIcon("edit-clear-list"));
1226 action
->setData(QVariant::fromValue(true));
1227 m_recentTabsMenu
->addAction(action
);
1228 m_recentTabsMenu
->addSeparator();
1229 m_recentTabsMenu
->setEnabled(false);
1231 KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1232 KStandardAction::up(this, SLOT(goUp()), actionCollection());
1233 KStandardAction::home(this, SLOT(goHome()), actionCollection());
1235 // setup 'Tools' menu
1236 KToggleAction
* showSearchBar
= actionCollection()->add
<KToggleAction
>("show_search_bar");
1237 showSearchBar
->setText(i18nc("@action:inmenu Tools", "Show Search Bar"));
1238 showSearchBar
->setShortcut(Qt::CTRL
| Qt::Key_S
);
1239 connect(showSearchBar
, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
1241 KToggleAction
* showFilterBar
= actionCollection()->add
<KToggleAction
>("show_filter_bar");
1242 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1243 showFilterBar
->setIcon(KIcon("view-filter"));
1244 showFilterBar
->setShortcut(Qt::CTRL
| Qt::Key_I
);
1245 connect(showFilterBar
, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
1247 KAction
* compareFiles
= actionCollection()->addAction("compare_files");
1248 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1249 compareFiles
->setIcon(KIcon("kompare"));
1250 compareFiles
->setEnabled(false);
1251 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
1253 KAction
* openTerminal
= actionCollection()->addAction("open_terminal");
1254 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1255 openTerminal
->setIcon(KIcon("utilities-terminal"));
1256 openTerminal
->setShortcut(Qt::SHIFT
| Qt::Key_F4
);
1257 connect(openTerminal
, SIGNAL(triggered()), this, SLOT(openTerminal()));
1259 // setup 'Settings' menu
1260 m_showMenuBar
= KStandardAction::showMenubar(this, SLOT(toggleShowMenuBar()), actionCollection());
1261 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1263 // not in menu actions
1264 KAction
* activateNextTab
= actionCollection()->addAction("activate_next_tab");
1265 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1266 connect(activateNextTab
, SIGNAL(triggered()), SLOT(activateNextTab()));
1267 activateNextTab
->setShortcuts(QApplication::isRightToLeft() ? KStandardShortcut::tabPrev() :
1268 KStandardShortcut::tabNext());
1270 KAction
* activatePrevTab
= actionCollection()->addAction("activate_prev_tab");
1271 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1272 connect(activatePrevTab
, SIGNAL(triggered()), SLOT(activatePrevTab()));
1273 activatePrevTab
->setShortcuts(QApplication::isRightToLeft() ? KStandardShortcut::tabNext() :
1274 KStandardShortcut::tabPrev());
1277 KAction
* openInNewTab
= actionCollection()->addAction("open_in_new_tab");
1278 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1279 openInNewTab
->setIcon(KIcon("tab-new"));
1280 connect(openInNewTab
, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1282 KAction
* openInNewWindow
= actionCollection()->addAction("open_in_new_window");
1283 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1284 openInNewWindow
->setIcon(KIcon("window-new"));
1285 connect(openInNewWindow
, SIGNAL(triggered()), this, SLOT(openInNewWindow()));
1288 m_searchBox
= new DolphinSearchBox(this);
1289 connect(m_searchBox
, SIGNAL(search(KUrl
)), this, SLOT(searchItems(KUrl
)));
1291 KAction
* search
= new KAction(this);
1292 actionCollection()->addAction("search_bar", search
);
1293 search
->setText(i18nc("@action:inmenu", "Search Bar"));
1294 search
->setDefaultWidget(m_searchBox
);
1295 search
->setShortcutConfigurable(false);
1298 void DolphinMainWindow::setupDockWidgets()
1300 // setup "Information"
1301 QDockWidget
* infoDock
= new QDockWidget(i18nc("@title:window", "Information"));
1302 infoDock
->setObjectName("infoDock");
1303 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1304 Panel
* infoPanel
= new InformationPanel(infoDock
);
1305 infoDock
->setWidget(infoPanel
);
1307 QAction
* infoAction
= infoDock
->toggleViewAction();
1308 infoAction
->setText(i18nc("@title:window", "Information"));
1309 infoAction
->setShortcut(Qt::Key_F11
);
1310 infoAction
->setIcon(KIcon("dialog-information"));
1311 actionCollection()->addAction("show_info_panel", infoDock
->toggleViewAction());
1313 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1314 connect(this, SIGNAL(urlChanged(KUrl
)),
1315 infoPanel
, SLOT(setUrl(KUrl
)));
1316 connect(this, SIGNAL(selectionChanged(KFileItemList
)),
1317 infoPanel
, SLOT(setSelection(KFileItemList
)));
1318 connect(this, SIGNAL(requestItemInfo(KFileItem
)),
1319 infoPanel
, SLOT(requestDelayedItemInfo(KFileItem
)));
1322 QDockWidget
* foldersDock
= new QDockWidget(i18nc("@title:window", "Folders"));
1323 foldersDock
->setObjectName("foldersDock");
1324 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1325 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1326 foldersDock
->setWidget(foldersPanel
);
1328 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1329 foldersAction
->setText(i18nc("@title:window", "Folders"));
1330 foldersAction
->setShortcut(Qt::Key_F7
);
1331 foldersAction
->setIcon(KIcon("folder"));
1332 actionCollection()->addAction("show_folders_panel", foldersDock
->toggleViewAction());
1334 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1335 connect(this, SIGNAL(urlChanged(KUrl
)),
1336 foldersPanel
, SLOT(setUrl(KUrl
)));
1337 connect(foldersPanel
, SIGNAL(changeUrl(KUrl
, Qt::MouseButtons
)),
1338 this, SLOT(handlePlacesClick(KUrl
, Qt::MouseButtons
)));
1339 connect(foldersPanel
, SIGNAL(changeSelection(KFileItemList
)),
1340 this, SLOT(changeSelection(KFileItemList
)));
1344 QDockWidget
* terminalDock
= new QDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1345 terminalDock
->setObjectName("terminalDock");
1346 terminalDock
->setAllowedAreas(Qt::TopDockWidgetArea
| Qt::BottomDockWidgetArea
);
1347 Panel
* terminalPanel
= new TerminalPanel(terminalDock
);
1348 terminalDock
->setWidget(terminalPanel
);
1350 connect(terminalPanel
, SIGNAL(hideTerminalPanel()), terminalDock
, SLOT(hide()));
1352 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1353 terminalAction
->setText(i18nc("@title:window Shell terminal", "Terminal"));
1354 terminalAction
->setShortcut(Qt::Key_F4
);
1355 terminalAction
->setIcon(KIcon("utilities-terminal"));
1356 actionCollection()->addAction("show_terminal_panel", terminalDock
->toggleViewAction());
1358 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1359 connect(this, SIGNAL(urlChanged(KUrl
)),
1360 terminalPanel
, SLOT(setUrl(KUrl
)));
1363 const bool firstRun
= DolphinSettings::instance().generalSettings()->firstRun();
1365 foldersDock
->hide();
1367 terminalDock
->hide();
1371 QDockWidget
* placesDock
= new QDockWidget(i18nc("@title:window", "Places"));
1372 placesDock
->setObjectName("placesDock");
1373 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1375 PlacesPanel
* placesPanel
= new PlacesPanel(placesDock
);
1376 placesDock
->setWidget(placesPanel
);
1377 placesPanel
->setModel(DolphinSettings::instance().placesModel());
1378 placesPanel
->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff
);
1380 QAction
* placesAction
= placesDock
->toggleViewAction();
1381 placesAction
->setText(i18nc("@title:window", "Places"));
1382 placesAction
->setShortcut(Qt::Key_F9
);
1383 placesAction
->setIcon(KIcon("bookmarks"));
1384 actionCollection()->addAction("show_places_panel", placesDock
->toggleViewAction());
1386 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1387 connect(placesPanel
, SIGNAL(urlChanged(KUrl
, Qt::MouseButtons
)),
1388 this, SLOT(handlePlacesClick(KUrl
, Qt::MouseButtons
)));
1389 connect(this, SIGNAL(urlChanged(KUrl
)),
1390 placesPanel
, SLOT(setUrl(KUrl
)));
1393 void DolphinMainWindow::updateEditActions()
1395 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1396 if (list
.isEmpty()) {
1397 stateChanged("has_no_selection");
1399 stateChanged("has_selection");
1401 KActionCollection
* col
= actionCollection();
1402 QAction
* renameAction
= col
->action("rename");
1403 QAction
* moveToTrashAction
= col
->action("move_to_trash");
1404 QAction
* deleteAction
= col
->action("delete");
1405 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
1406 QAction
* deleteWithTrashShortcut
= col
->action("delete_shortcut"); // see DolphinViewActionHandler
1408 KFileItemListProperties
capabilities(list
);
1409 const bool enableMoveToTrash
= capabilities
.isLocal() && capabilities
.supportsMoving();
1411 renameAction
->setEnabled(capabilities
.supportsMoving());
1412 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1413 deleteAction
->setEnabled(capabilities
.supportsDeleting());
1414 deleteWithTrashShortcut
->setEnabled(capabilities
.supportsDeleting() && !enableMoveToTrash
);
1415 cutAction
->setEnabled(capabilities
.supportsMoving());
1417 updatePasteAction();
1420 void DolphinMainWindow::updateViewActions()
1422 m_actionHandler
->updateViewActions();
1424 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1425 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
1427 updateSplitAction();
1429 QAction
* editableLocactionAction
= actionCollection()->action("editable_location");
1430 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
1431 editableLocactionAction
->setChecked(urlNavigator
->isUrlEditable());
1434 void DolphinMainWindow::updateGoActions()
1436 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
1437 const KUrl
& currentUrl
= m_activeViewContainer
->url();
1438 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
1441 void DolphinMainWindow::rememberClosedTab(int index
)
1443 KMenu
* tabsMenu
= m_recentTabsMenu
->menu();
1445 const QString primaryPath
= m_viewTab
[index
].primaryView
->url().path();
1446 const QString iconName
= KMimeType::iconNameForUrl(primaryPath
);
1448 QAction
* action
= new QAction(squeezedText(primaryPath
), tabsMenu
);
1450 ClosedTab closedTab
;
1451 closedTab
.primaryUrl
= m_viewTab
[index
].primaryView
->url();
1453 if (m_viewTab
[index
].secondaryView
!= 0) {
1454 closedTab
.secondaryUrl
= m_viewTab
[index
].secondaryView
->url();
1455 closedTab
.isSplit
= true;
1457 closedTab
.isSplit
= false;
1460 action
->setData(QVariant::fromValue(closedTab
));
1461 action
->setIcon(KIcon(iconName
));
1463 // add the closed tab menu entry after the separator and
1464 // "Empty Recently Closed Tabs" entry
1465 if (tabsMenu
->actions().size() == 2) {
1466 tabsMenu
->addAction(action
);
1468 tabsMenu
->insertAction(tabsMenu
->actions().at(2), action
);
1471 // assure that only up to 8 closed tabs are shown in the menu
1472 if (tabsMenu
->actions().size() > 8) {
1473 tabsMenu
->removeAction(tabsMenu
->actions().last());
1475 actionCollection()->action("closed_tabs")->setEnabled(true);
1476 KAcceleratorManager::manage(tabsMenu
);
1479 void DolphinMainWindow::clearStatusBar()
1481 m_activeViewContainer
->statusBar()->clear();
1484 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
1486 connect(container
, SIGNAL(showFilterBarChanged(bool)),
1487 this, SLOT(updateFilterBarAction(bool)));
1489 DolphinView
* view
= container
->view();
1490 connect(view
, SIGNAL(selectionChanged(KFileItemList
)),
1491 this, SLOT(slotSelectionChanged(KFileItemList
)));
1492 connect(view
, SIGNAL(requestItemInfo(KFileItem
)),
1493 this, SLOT(slotRequestItemInfo(KFileItem
)));
1494 connect(view
, SIGNAL(activated()),
1495 this, SLOT(toggleActiveView()));
1496 connect(view
, SIGNAL(tabRequested(const KUrl
&)),
1497 this, SLOT(openNewTab(const KUrl
&)));
1499 const KUrlNavigator
* navigator
= container
->urlNavigator();
1500 connect(navigator
, SIGNAL(urlChanged(const KUrl
&)),
1501 this, SLOT(changeUrl(const KUrl
&)));
1502 connect(navigator
, SIGNAL(historyChanged()),
1503 this, SLOT(updateHistory()));
1504 connect(navigator
, SIGNAL(editableStateChanged(bool)),
1505 this, SLOT(slotEditableStateChanged(bool)));
1508 void DolphinMainWindow::updateSplitAction()
1510 QAction
* splitAction
= actionCollection()->action("split_view");
1511 if (m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
1512 if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
1513 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
1514 splitAction
->setIcon(KIcon("view-right-close"));
1516 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
1517 splitAction
->setIcon(KIcon("view-left-close"));
1520 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
1521 splitAction
->setIcon(KIcon("view-right-new"));
1525 QString
DolphinMainWindow::tabName(const KUrl
& url
) const
1528 if (url
.equals(KUrl("file:///"))) {
1531 name
= url
.fileName();
1532 if (name
.isEmpty()) {
1533 name
= url
.protocol();
1535 // Make sure that a '&' inside the directory name is displayed correctly
1536 // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
1537 name
.replace('&', "&&");
1543 bool DolphinMainWindow::isKompareInstalled() const
1545 static bool initialized
= false;
1546 static bool installed
= false;
1548 // TODO: maybe replace this approach later by using a menu
1549 // plugin like kdiff3plugin.cpp
1550 installed
= !KGlobal::dirs()->findExe("kompare").isEmpty();
1556 void DolphinMainWindow::createSecondaryView(int tabIndex
)
1558 QSplitter
* splitter
= m_viewTab
[tabIndex
].splitter
;
1559 const int newWidth
= (m_viewTab
[tabIndex
].primaryView
->width() - splitter
->handleWidth()) / 2;
1561 const DolphinView
* view
= m_viewTab
[tabIndex
].primaryView
->view();
1562 m_viewTab
[tabIndex
].secondaryView
= new DolphinViewContainer(this, 0, view
->rootUrl());
1563 splitter
->addWidget(m_viewTab
[tabIndex
].secondaryView
);
1564 splitter
->setSizes(QList
<int>() << newWidth
<< newWidth
);
1565 connectViewSignals(m_viewTab
[tabIndex
].secondaryView
);
1566 m_viewTab
[tabIndex
].secondaryView
->view()->reload();
1567 m_viewTab
[tabIndex
].secondaryView
->setActive(false);
1568 m_viewTab
[tabIndex
].secondaryView
->show();
1571 QString
DolphinMainWindow::tabProperty(const QString
& property
, int tabIndex
) const
1573 return "Tab " + QString::number(tabIndex
) + ' ' + property
;
1576 void DolphinMainWindow::setUrlAsCaption(const KUrl
& url
)
1579 if (url
.equals(KUrl("file:///"))) {
1582 caption
= url
.fileName();
1583 if (caption
.isEmpty()) {
1584 caption
= url
.protocol();
1588 setCaption(caption
);
1591 QString
DolphinMainWindow::squeezedText(const QString
& text
) const
1593 const QFontMetrics fm
= fontMetrics();
1594 return fm
.elidedText(text
, Qt::ElideMiddle
, fm
.maxWidth() * 10);
1597 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
1598 KIO::FileUndoManager::UiInterface()
1602 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
1606 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
1608 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
1610 DolphinStatusBar
* statusBar
= mainWin
->activeViewContainer()->statusBar();
1611 statusBar
->setMessage(job
->errorString(), DolphinStatusBar::Error
);
1613 KIO::FileUndoManager::UiInterface::jobError(job
);
1617 #include "dolphinmainwindow.moc"