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 "dolphinstatusbar.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 "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>
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),
120 setObjectName("Dolphin#");
122 m_viewTab
.append(ViewTab());
124 new MainWindowAdaptor(this);
125 QDBusConnection::sessionBus().registerObject(QString("/dolphin/MainWindow%1").arg(m_id
), this);
127 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
128 undoManager
->setUiInterface(new UndoUiInterface());
130 connect(undoManager
, SIGNAL(undoAvailable(bool)),
131 this, SLOT(slotUndoAvailable(bool)));
132 connect(undoManager
, SIGNAL(undoTextChanged(const QString
&)),
133 this, SLOT(slotUndoTextChanged(const QString
&)));
134 connect(undoManager
, SIGNAL(jobRecordingStarted(CommandType
)),
135 this, SLOT(clearStatusBar()));
136 connect(undoManager
, SIGNAL(jobRecordingFinished(CommandType
)),
137 this, SLOT(showCommand(CommandType
)));
138 connect(DolphinSettings::instance().placesModel(), SIGNAL(errorMessage(const QString
&)),
139 this, SLOT(showErrorMessage(const QString
&)));
140 connect(&DragAndDropHelper::instance(), SIGNAL(errorMessage(const QString
&)),
141 this, SLOT(showErrorMessage(const QString
&)));
144 DolphinMainWindow::~DolphinMainWindow()
146 DolphinApplication::app()->removeMainWindow(this);
149 void DolphinMainWindow::toggleViews()
151 if (m_viewTab
[m_tabIndex
].primaryView
== 0) {
155 // move secondary view from the last position of the splitter
156 // to the first position
157 m_viewTab
[m_tabIndex
].splitter
->insertWidget(0, m_viewTab
[m_tabIndex
].secondaryView
);
159 DolphinViewContainer
* container
= m_viewTab
[m_tabIndex
].primaryView
;
160 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
161 m_viewTab
[m_tabIndex
].secondaryView
= container
;
164 void DolphinMainWindow::showCommand(CommandType command
)
166 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
168 case KIO::FileUndoManager::Copy
:
169 statusBar
->setMessage(i18nc("@info:status", "Copy operation completed."),
170 DolphinStatusBar::OperationCompleted
);
172 case KIO::FileUndoManager::Move
:
173 statusBar
->setMessage(i18nc("@info:status", "Move operation completed."),
174 DolphinStatusBar::OperationCompleted
);
176 case KIO::FileUndoManager::Link
:
177 statusBar
->setMessage(i18nc("@info:status", "Link operation completed."),
178 DolphinStatusBar::OperationCompleted
);
180 case KIO::FileUndoManager::Trash
:
181 statusBar
->setMessage(i18nc("@info:status", "Move to trash operation completed."),
182 DolphinStatusBar::OperationCompleted
);
184 case KIO::FileUndoManager::Rename
:
185 statusBar
->setMessage(i18nc("@info:status", "Renaming operation completed."),
186 DolphinStatusBar::OperationCompleted
);
189 case KIO::FileUndoManager::Mkdir
:
190 statusBar
->setMessage(i18nc("@info:status", "Created folder."),
191 DolphinStatusBar::OperationCompleted
);
199 void DolphinMainWindow::refreshViews()
201 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
203 // remember the current active view, as because of
204 // the refreshing the active view might change to
205 // the secondary view
206 DolphinViewContainer
* activeViewContainer
= m_activeViewContainer
;
208 const int tabCount
= m_viewTab
.count();
209 for (int i
= 0; i
< tabCount
; ++i
) {
210 m_viewTab
[i
].primaryView
->refresh();
211 if (m_viewTab
[i
].secondaryView
!= 0) {
212 m_viewTab
[i
].secondaryView
->refresh();
216 setActiveViewContainer(activeViewContainer
);
219 void DolphinMainWindow::pasteIntoFolder()
221 m_activeViewContainer
->view()->pasteIntoFolder();
224 void DolphinMainWindow::changeUrl(const KUrl
& url
)
226 if (!KProtocolManager::supportsListing(url
)) {
227 // The URL navigator only checks for validity, not
228 // if the URL can be listed. An error message is
229 // shown due to DolphinViewContainer::restoreView().
233 DolphinViewContainer
* view
= activeViewContainer();
239 setUrlAsCaption(url
);
240 if (m_viewTab
.count() > 1) {
241 m_tabBar
->setTabText(m_tabIndex
, tabName(url
));
243 const QString iconName
= KMimeType::iconNameForUrl(url
);
244 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(iconName
));
245 emit
urlChanged(url
);
249 void DolphinMainWindow::changeSelection(const KFileItemList
& selection
)
251 activeViewContainer()->view()->changeSelection(selection
);
254 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
256 KToggleAction
* editableLocationAction
=
257 static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
258 editableLocationAction
->setChecked(editable
);
261 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
265 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
266 int selectedUrlsCount
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedItemsCount();
267 if (m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
268 selectedUrlsCount
+= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItemsCount();
271 QAction
* compareFilesAction
= actionCollection()->action("compare_files");
272 if (selectedUrlsCount
== 2) {
273 compareFilesAction
->setEnabled(isKompareInstalled());
275 compareFilesAction
->setEnabled(false);
278 m_activeViewContainer
->updateStatusBar();
280 emit
selectionChanged(selection
);
283 void DolphinMainWindow::slotWheelMoved(int wheelDelta
)
285 if (wheelDelta
> 0) {
292 void DolphinMainWindow::slotRequestItemInfo(const KFileItem
& item
)
294 emit
requestItemInfo(item
);
297 void DolphinMainWindow::updateHistory()
299 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
300 const int index
= urlNavigator
->historyIndex();
302 QAction
* backAction
= actionCollection()->action("go_back");
303 if (backAction
!= 0) {
304 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
307 QAction
* forwardAction
= actionCollection()->action("go_forward");
308 if (forwardAction
!= 0) {
309 forwardAction
->setEnabled(index
> 0);
313 void DolphinMainWindow::updateFilterBarAction(bool show
)
315 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
316 showFilterBarAction
->setChecked(show
);
319 void DolphinMainWindow::openNewMainWindow()
321 DolphinApplication::app()->createMainWindow()->show();
324 void DolphinMainWindow::openNewTab()
326 openNewTab(m_activeViewContainer
->url());
327 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
329 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
330 if (navigator
->isUrlEditable()) {
331 // if a new tab is opened and the URL is editable, assure that
332 // the user can edit the URL without manually setting the focus
333 navigator
->setFocus();
337 void DolphinMainWindow::openNewTab(const KUrl
& url
)
339 const KIcon icon
= KIcon(KMimeType::iconNameForUrl(m_activeViewContainer
->url()));
340 if (m_viewTab
.count() == 1) {
341 // Only one view is open currently and hence no tab is shown at
342 // all. Before creating a tab for 'url', provide a tab for the current URL.
343 m_tabBar
->addTab(icon
, tabName(m_activeViewContainer
->url()));
344 m_tabBar
->blockSignals(false);
347 m_tabBar
->addTab(icon
, tabName(url
));
350 viewTab
.splitter
= new QSplitter(this);
351 viewTab
.splitter
->setChildrenCollapsible(false);
352 viewTab
.primaryView
= new DolphinViewContainer(this, viewTab
.splitter
, url
);
353 viewTab
.primaryView
->setActive(false);
354 connectViewSignals(viewTab
.primaryView
);
355 viewTab
.primaryView
->view()->reload();
357 m_viewTab
.append(viewTab
);
359 actionCollection()->action("close_tab")->setEnabled(true);
361 // provide a split view, if the startup settings are set this way
362 const GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
363 if (generalSettings
->splitView()) {
364 const int tabIndex
= m_viewTab
.count() - 1;
365 createSecondaryView(tabIndex
);
366 m_viewTab
[tabIndex
].secondaryView
->setActive(true);
367 m_viewTab
[tabIndex
].isPrimaryViewActive
= false;
371 void DolphinMainWindow::activateNextTab()
373 if ((m_viewTab
.count() == 1) || (m_tabBar
->count() < 2)) {
377 const int tabIndex
= (m_tabBar
->currentIndex() + 1) % m_tabBar
->count();
378 m_tabBar
->setCurrentIndex(tabIndex
);
381 void DolphinMainWindow::activatePrevTab()
383 if ((m_viewTab
.count() == 1) || (m_tabBar
->count() < 2)) {
387 int tabIndex
= m_tabBar
->currentIndex() - 1;
388 if (tabIndex
== -1) {
389 tabIndex
= m_tabBar
->count() - 1;
391 m_tabBar
->setCurrentIndex(tabIndex
);
394 void DolphinMainWindow::openInNewTab()
396 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
397 if ((list
.count() == 1) && list
[0].isDir()) {
398 openNewTab(m_activeViewContainer
->view()->selectedUrls()[0]);
402 void DolphinMainWindow::openInNewWindow()
404 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
405 if ((list
.count() == 1) && list
[0].isDir()) {
406 DolphinMainWindow
* window
= DolphinApplication::app()->createMainWindow();
407 window
->changeUrl(m_activeViewContainer
->view()->selectedUrls()[0]);
412 void DolphinMainWindow::toggleActiveView()
414 if (m_viewTab
[m_tabIndex
].secondaryView
== 0) {
415 // only one view is available
419 Q_ASSERT(m_activeViewContainer
!= 0);
420 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
422 DolphinViewContainer
* left
= m_viewTab
[m_tabIndex
].primaryView
;
423 DolphinViewContainer
* right
= m_viewTab
[m_tabIndex
].secondaryView
;
424 setActiveViewContainer(m_activeViewContainer
== right
? left
: right
);
427 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
429 DolphinSettings
& settings
= DolphinSettings::instance();
430 GeneralSettings
* generalSettings
= settings
.generalSettings();
432 if ((m_viewTab
.count() > 1) && generalSettings
->confirmClosingMultipleTabs()) {
433 // Ask the user if he really wants to quit and close all tabs.
434 // Open a confirmation dialog with 3 buttons:
435 // KDialog::Yes -> Quit
436 // KDialog::No -> Close only the current tab
437 // KDialog::Cancel -> do nothing
438 KDialog
*dialog
= new KDialog(this, Qt::Dialog
);
439 dialog
->setCaption(i18nc("@title:window", "Confirmation"));
440 dialog
->setButtons(KDialog::Yes
| KDialog::No
| KDialog::Cancel
);
441 dialog
->setModal(true);
442 dialog
->showButtonSeparator(true);
443 dialog
->setButtonGuiItem(KDialog::Yes
, KStandardGuiItem::quit());
444 dialog
->setButtonGuiItem(KDialog::No
, KGuiItem(i18n("C&lose Current Tab"), KIcon("tab-close")));
445 dialog
->setButtonGuiItem(KDialog::Cancel
, KStandardGuiItem::cancel());
446 dialog
->setDefaultButton(KDialog::Yes
);
448 bool doNotAskAgainCheckboxResult
= false;
450 const int result
= KMessageBox::createKMessageBox(dialog
,
451 QMessageBox::Warning
,
452 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
454 i18n("Do not ask again"),
455 &doNotAskAgainCheckboxResult
,
456 KMessageBox::Notify
);
458 if (doNotAskAgainCheckboxResult
) {
459 generalSettings
->setConfirmClosingMultipleTabs(false);
467 // Close only the current tab
475 generalSettings
->setFirstRun(false);
479 KXmlGuiWindow::closeEvent(event
);
482 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
484 const int tabCount
= m_viewTab
.count();
485 group
.writeEntry("Tab Count", tabCount
);
486 group
.writeEntry("Active Tab Index", m_tabBar
->currentIndex());
488 for (int i
= 0; i
< tabCount
; ++i
) {
489 const DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
490 group
.writeEntry(tabProperty("Primary URL", i
), cont
->url().url());
491 group
.writeEntry(tabProperty("Primary Editable", i
), cont
->isUrlEditable());
493 cont
= m_viewTab
[i
].secondaryView
;
495 group
.writeEntry(tabProperty("Secondary URL", i
), cont
->url().url());
496 group
.writeEntry(tabProperty("Secondary Editable", i
), cont
->isUrlEditable());
501 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
503 const int tabCount
= group
.readEntry("Tab Count", 1);
504 for (int i
= 0; i
< tabCount
; ++i
) {
505 DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
507 cont
->setUrl(group
.readEntry(tabProperty("Primary URL", i
)));
508 const bool editable
= group
.readEntry(tabProperty("Primary Editable", i
), false);
509 cont
->urlNavigator()->setUrlEditable(editable
);
511 cont
= m_viewTab
[i
].secondaryView
;
512 const QString secondaryUrl
= group
.readEntry(tabProperty("Secondary URL", i
));
513 if (!secondaryUrl
.isEmpty()) {
515 // a secondary view should be shown, but no one is available
516 // currently -> create a new view
518 cont
= m_viewTab
[i
].secondaryView
;
522 cont
->setUrl(secondaryUrl
);
523 const bool editable
= group
.readEntry(tabProperty("Secondary Editable", i
), false);
524 cont
->urlNavigator()->setUrlEditable(editable
);
525 } else if (cont
!= 0) {
526 // no secondary view should be shown, but the default setting shows
527 // one already -> close the view
531 // openNewTab() needs to be called only tabCount - 1 times
532 if (i
!= tabCount
- 1) {
537 const int index
= group
.readEntry("Active Tab Index", 0);
538 m_tabBar
->setCurrentIndex(index
);
541 void DolphinMainWindow::updateNewMenu()
543 m_newMenu
->slotCheckUpToDate();
544 m_newMenu
->setPopupFiles(activeViewContainer()->url());
547 void DolphinMainWindow::createDirectory()
549 m_newMenu
->setPopupFiles(activeViewContainer()->url());
550 m_newMenu
->createDirectory();
553 void DolphinMainWindow::quit()
558 void DolphinMainWindow::showErrorMessage(const QString
& message
)
560 if (!message
.isEmpty()) {
561 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
562 statusBar
->setMessage(message
, DolphinStatusBar::Error
);
566 void DolphinMainWindow::slotUndoAvailable(bool available
)
568 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
569 if (undoAction
!= 0) {
570 undoAction
->setEnabled(available
);
574 void DolphinMainWindow::restoreClosedTab(QAction
* action
)
576 if (action
->data().toBool()) {
577 // clear all actions except the "Empty Recently Closed Tabs"
578 // action and the separator
579 QList
<QAction
*> actions
= m_recentTabsMenu
->menu()->actions();
580 const int count
= actions
.size();
581 for (int i
= 2; i
< count
; ++i
) {
582 m_recentTabsMenu
->menu()->removeAction(actions
.at(i
));
585 const ClosedTab closedTab
= action
->data().value
<ClosedTab
>();
586 openNewTab(closedTab
.primaryUrl
);
587 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
589 if (closedTab
.isSplit
) {
590 // create secondary view
592 m_viewTab
[m_tabIndex
].secondaryView
->setUrl(closedTab
.secondaryUrl
);
595 m_recentTabsMenu
->removeAction(action
);
598 if (m_recentTabsMenu
->menu()->actions().count() == 2) {
599 m_recentTabsMenu
->setEnabled(false);
603 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
605 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
606 if (undoAction
!= 0) {
607 undoAction
->setText(text
);
611 void DolphinMainWindow::undo()
614 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
615 KIO::FileUndoManager::self()->undo();
618 void DolphinMainWindow::cut()
620 m_activeViewContainer
->view()->cutSelectedItems();
623 void DolphinMainWindow::copy()
625 m_activeViewContainer
->view()->copySelectedItems();
628 void DolphinMainWindow::paste()
630 m_activeViewContainer
->view()->paste();
633 void DolphinMainWindow::updatePasteAction()
635 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
636 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
637 pasteAction
->setEnabled(pasteInfo
.first
);
638 pasteAction
->setText(pasteInfo
.second
);
641 void DolphinMainWindow::selectAll()
645 // if the URL navigator is editable and focused, select the whole
646 // URL instead of all items of the view
648 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
649 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit();
650 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
651 lineEdit
->hasFocus();
653 lineEdit
->selectAll();
655 m_activeViewContainer
->view()->selectAll();
659 void DolphinMainWindow::invertSelection()
662 m_activeViewContainer
->view()->invertSelection();
665 void DolphinMainWindow::toggleSplitView()
667 if (m_viewTab
[m_tabIndex
].secondaryView
== 0) {
668 createSecondaryView(m_tabIndex
);
669 setActiveViewContainer(m_viewTab
[m_tabIndex
].secondaryView
);
670 } else if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
671 // remove secondary view
672 m_viewTab
[m_tabIndex
].secondaryView
->close();
673 m_viewTab
[m_tabIndex
].secondaryView
->deleteLater();
674 m_viewTab
[m_tabIndex
].secondaryView
= 0;
676 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
678 // The primary view is active and should be closed. Hence from a users point of view
679 // the content of the secondary view should be moved to the primary view.
680 // From an implementation point of view it is more efficient to close
681 // the primary view and exchange the internal pointers afterwards.
683 m_viewTab
[m_tabIndex
].primaryView
->close();
684 m_viewTab
[m_tabIndex
].primaryView
->deleteLater();
685 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
686 m_viewTab
[m_tabIndex
].secondaryView
= 0;
688 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
694 void DolphinMainWindow::reloadView()
697 m_activeViewContainer
->view()->reload();
700 void DolphinMainWindow::stopLoading()
704 void DolphinMainWindow::toggleFilterBarVisibility(bool show
)
706 m_activeViewContainer
->showFilterBar(show
);
709 void DolphinMainWindow::toggleEditLocation()
713 QAction
* action
= actionCollection()->action("editable_location");
714 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
715 urlNavigator
->setUrlEditable(action
->isChecked());
718 void DolphinMainWindow::replaceLocation()
720 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
721 navigator
->setUrlEditable(true);
722 navigator
->setFocus();
724 // select the whole text of the combo box editor
725 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit();
726 const QString text
= lineEdit
->text();
727 lineEdit
->setSelection(0, text
.length());
730 void DolphinMainWindow::goBack()
733 m_activeViewContainer
->urlNavigator()->goBack();
736 void DolphinMainWindow::goForward()
739 m_activeViewContainer
->urlNavigator()->goForward();
742 void DolphinMainWindow::goUp()
745 m_activeViewContainer
->urlNavigator()->goUp();
748 void DolphinMainWindow::goHome()
751 m_activeViewContainer
->urlNavigator()->goHome();
754 void DolphinMainWindow::compareFiles()
756 // The method is only invoked if exactly 2 files have
757 // been selected. The selected files may be:
758 // - both in the primary view
759 // - both in the secondary view
760 // - one in the primary view and the other in the secondary
762 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
766 KUrl::List urls
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedUrls();
768 switch (urls
.count()) {
770 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
!= 0);
771 urls
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedUrls();
772 Q_ASSERT(urls
.count() == 2);
780 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
!= 0);
781 urls
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedUrls();
782 Q_ASSERT(urls
.count() == 1);
794 // may not happen: compareFiles may only get invoked if 2
795 // files are selected
800 QString
command("kompare -c \"");
801 command
.append(urlA
.pathOrUrl());
802 command
.append("\" \"");
803 command
.append(urlB
.pathOrUrl());
804 command
.append('\"');
805 KRun::runCommand(command
, "Kompare", "kompare", this);
808 void DolphinMainWindow::toggleShowMenuBar()
810 const bool visible
= menuBar()->isVisible();
811 menuBar()->setVisible(!visible
);
814 void DolphinMainWindow::openTerminal()
816 QString
dir(QDir::homePath());
818 // If the given directory is not local, it can still be the URL of an
819 // ioslave using UDS_LOCAL_PATH which to be converted first.
820 KUrl url
= KIO::NetAccess::mostLocalUrl(m_activeViewContainer
->url(), this);
822 //If the URL is local after the above conversion, set the directory.
823 if (url
.isLocalFile()) {
824 dir
= url
.toLocalFile();
827 KToolInvocation::invokeTerminal(QString(), dir
);
830 void DolphinMainWindow::editSettings()
832 if (m_settingsDialog
== 0) {
833 const KUrl
& url
= activeViewContainer()->url();
834 m_settingsDialog
= new DolphinSettingsDialog(url
, this);
835 m_settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
836 m_settingsDialog
->show();
838 m_settingsDialog
->raise();
842 void DolphinMainWindow::setActiveTab(int index
)
844 Q_ASSERT(index
>= 0);
845 Q_ASSERT(index
< m_viewTab
.count());
846 if (index
== m_tabIndex
) {
850 // hide current tab content
851 ViewTab
& hiddenTab
= m_viewTab
[m_tabIndex
];
852 hiddenTab
.isPrimaryViewActive
= hiddenTab
.primaryView
->isActive();
853 hiddenTab
.primaryView
->setActive(false);
854 if (hiddenTab
.secondaryView
!= 0) {
855 hiddenTab
.secondaryView
->setActive(false);
857 QSplitter
* splitter
= m_viewTab
[m_tabIndex
].splitter
;
859 m_centralWidgetLayout
->removeWidget(splitter
);
861 // show active tab content
864 ViewTab
& viewTab
= m_viewTab
[index
];
865 m_centralWidgetLayout
->addWidget(viewTab
.splitter
);
866 viewTab
.primaryView
->show();
867 if (viewTab
.secondaryView
!= 0) {
868 viewTab
.secondaryView
->show();
870 viewTab
.splitter
->show();
872 setActiveViewContainer(viewTab
.isPrimaryViewActive
? viewTab
.primaryView
:
873 viewTab
.secondaryView
);
876 void DolphinMainWindow::closeTab()
878 closeTab(m_tabBar
->currentIndex());
881 void DolphinMainWindow::closeTab(int index
)
883 Q_ASSERT(index
>= 0);
884 Q_ASSERT(index
< m_viewTab
.count());
885 if (m_viewTab
.count() == 1) {
886 // the last tab may never get closed
890 if (index
== m_tabIndex
) {
891 // The tab that should be closed is the active tab. Activate the
892 // previous tab before closing the tab.
893 m_tabBar
->setCurrentIndex((index
> 0) ? index
- 1 : 1);
895 rememberClosedTab(index
);
898 m_viewTab
[index
].primaryView
->deleteLater();
899 if (m_viewTab
[index
].secondaryView
!= 0) {
900 m_viewTab
[index
].secondaryView
->deleteLater();
902 m_viewTab
[index
].splitter
->deleteLater();
903 m_viewTab
.erase(m_viewTab
.begin() + index
);
905 m_tabBar
->blockSignals(true);
906 m_tabBar
->removeTab(index
);
908 if (m_tabIndex
> index
) {
910 Q_ASSERT(m_tabIndex
>= 0);
913 // if only one tab is left, also remove the tab entry so that
914 // closing the last tab is not possible
915 if (m_viewTab
.count() == 1) {
916 m_tabBar
->removeTab(0);
917 actionCollection()->action("close_tab")->setEnabled(false);
919 m_tabBar
->blockSignals(false);
923 void DolphinMainWindow::openTabContextMenu(int index
, const QPoint
& pos
)
927 QAction
* newTabAction
= menu
.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab"));
928 newTabAction
->setShortcut(actionCollection()->action("new_tab")->shortcut());
930 QAction
* closeOtherTabsAction
= menu
.addAction(KIcon("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs"));
932 QAction
* closeTabAction
= menu
.addAction(KIcon("tab-close"), i18nc("@action:inmenu", "Close Tab"));
933 closeTabAction
->setShortcut(actionCollection()->action("close_tab")->shortcut());
934 QAction
* selectedAction
= menu
.exec(pos
);
935 if (selectedAction
== newTabAction
) {
936 const ViewTab
& tab
= m_viewTab
[index
];
937 Q_ASSERT(tab
.primaryView
!= 0);
938 const KUrl url
= (tab
.secondaryView
!= 0) && tab
.secondaryView
->isActive() ?
939 tab
.secondaryView
->url() : tab
.primaryView
->url();
941 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
942 } else if (selectedAction
== closeOtherTabsAction
) {
943 const int count
= m_tabBar
->count();
944 for (int i
= 0; i
< index
; ++i
) {
947 for (int i
= index
+ 1; i
< count
; ++i
) {
950 } else if (selectedAction
== closeTabAction
) {
955 void DolphinMainWindow::handlePlacesClick(const KUrl
& url
, Qt::MouseButtons buttons
)
957 if (buttons
& Qt::MidButton
) {
959 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
965 void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent
* event
, bool& canDecode
)
967 canDecode
= KUrl::List::canDecode(event
->mimeData());
970 void DolphinMainWindow::searchItems(const KUrl
& url
)
972 m_activeViewContainer
->setUrl(url
);
975 void DolphinMainWindow::slotTabMoved(int from
, int to
)
977 m_viewTab
.move(from
, to
);
978 m_tabIndex
= m_tabBar
->currentIndex();
981 void DolphinMainWindow::init()
983 DolphinSettings
& settings
= DolphinSettings::instance();
985 // Check whether Dolphin runs the first time. If yes then
986 // a proper default window size is given at the end of DolphinMainWindow::init().
987 GeneralSettings
* generalSettings
= settings
.generalSettings();
988 const bool firstRun
= generalSettings
->firstRun();
990 generalSettings
->setViewPropsTimestamp(QDateTime::currentDateTime());
993 setAcceptDrops(true);
995 m_viewTab
[m_tabIndex
].splitter
= new QSplitter(this);
996 m_viewTab
[m_tabIndex
].splitter
->setChildrenCollapsible(false);
1000 const KUrl
& homeUrl
= generalSettings
->homeUrl();
1001 setUrlAsCaption(homeUrl
);
1002 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
1003 connect(m_actionHandler
, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
1004 connect(m_actionHandler
, SIGNAL(createDirectory()), SLOT(createDirectory()));
1005 ViewProperties
props(homeUrl
);
1006 m_viewTab
[m_tabIndex
].primaryView
= new DolphinViewContainer(this,
1007 m_viewTab
[m_tabIndex
].splitter
,
1010 m_activeViewContainer
= m_viewTab
[m_tabIndex
].primaryView
;
1011 connectViewSignals(m_activeViewContainer
);
1012 DolphinView
* view
= m_activeViewContainer
->view();
1014 m_activeViewContainer
->show();
1015 m_actionHandler
->setCurrentView(view
);
1017 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
1018 connect(this, SIGNAL(urlChanged(const KUrl
&)),
1019 m_remoteEncoding
, SLOT(slotAboutToOpenUrl()));
1021 m_tabBar
= new KTabBar(this);
1022 m_tabBar
->setMovable(true);
1023 m_tabBar
->setTabsClosable(true);
1024 connect(m_tabBar
, SIGNAL(currentChanged(int)),
1025 this, SLOT(setActiveTab(int)));
1026 connect(m_tabBar
, SIGNAL(tabCloseRequested(int)),
1027 this, SLOT(closeTab(int)));
1028 connect(m_tabBar
, SIGNAL(contextMenu(int, const QPoint
&)),
1029 this, SLOT(openTabContextMenu(int, const QPoint
&)));
1030 connect(m_tabBar
, SIGNAL(newTabRequest()),
1031 this, SLOT(openNewTab()));
1032 connect(m_tabBar
, SIGNAL(testCanDecode(const QDragMoveEvent
*, bool&)),
1033 this, SLOT(slotTestCanDecode(const QDragMoveEvent
*, bool&)));
1034 connect(m_tabBar
, SIGNAL(wheelDelta(int)),
1035 this, SLOT(slotWheelMoved(int)));
1036 connect(m_tabBar
, SIGNAL(mouseMiddleClick(int)),
1037 this, SLOT(closeTab(int)));
1038 connect(m_tabBar
, SIGNAL(tabMoved(int, int)),
1039 this, SLOT(slotTabMoved(int, int)));
1041 m_tabBar
->blockSignals(true); // signals get unblocked after at least 2 tabs are open
1043 QWidget
* centralWidget
= new QWidget(this);
1044 m_centralWidgetLayout
= new QVBoxLayout(centralWidget
);
1045 m_centralWidgetLayout
->setSpacing(0);
1046 m_centralWidgetLayout
->setMargin(0);
1047 m_centralWidgetLayout
->addWidget(m_tabBar
);
1048 m_centralWidgetLayout
->addWidget(m_viewTab
[m_tabIndex
].splitter
);
1050 setCentralWidget(centralWidget
);
1052 emit
urlChanged(homeUrl
);
1054 setupGUI(Keys
| Save
| Create
| ToolBar
);
1056 m_searchBox
->setParent(toolBar("searchToolBar"));
1057 m_searchBox
->show();
1059 stateChanged("new_file");
1061 QClipboard
* clipboard
= QApplication::clipboard();
1062 connect(clipboard
, SIGNAL(dataChanged()),
1063 this, SLOT(updatePasteAction()));
1064 updatePasteAction();
1067 if (generalSettings
->splitView()) {
1070 updateViewActions();
1072 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1073 showFilterBarAction
->setChecked(generalSettings
->filterBar());
1076 // assure a proper default size if Dolphin runs the first time
1080 m_showMenuBar
->setChecked(!menuBar()->isHidden()); // workaround for bug #171080
1083 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer
* viewContainer
)
1085 Q_ASSERT(viewContainer
!= 0);
1086 Q_ASSERT((viewContainer
== m_viewTab
[m_tabIndex
].primaryView
) ||
1087 (viewContainer
== m_viewTab
[m_tabIndex
].secondaryView
));
1088 if (m_activeViewContainer
== viewContainer
) {
1092 m_activeViewContainer
->setActive(false);
1093 m_activeViewContainer
= viewContainer
;
1095 // Activating the view container might trigger a recursive setActiveViewContainer() call
1096 // inside DolphinMainWindow::toggleActiveView() when having a split view. Temporary
1097 // disconnect the activated() signal in this case:
1098 disconnect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1099 m_activeViewContainer
->setActive(true);
1100 connect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1102 m_actionHandler
->setCurrentView(viewContainer
->view());
1105 updateEditActions();
1106 updateViewActions();
1109 const KUrl
& url
= m_activeViewContainer
->url();
1110 setUrlAsCaption(url
);
1111 if (m_viewTab
.count() > 1 && m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
1112 m_tabBar
->setTabText(m_tabIndex
, tabName(url
));
1113 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(KMimeType::iconNameForUrl(url
)));
1116 emit
urlChanged(url
);
1119 void DolphinMainWindow::setupActions()
1121 // setup 'File' menu
1122 m_newMenu
= new DolphinNewMenu(this, this);
1123 KMenu
* menu
= m_newMenu
->menu();
1124 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1125 menu
->setIcon(KIcon("document-new"));
1126 connect(menu
, SIGNAL(aboutToShow()),
1127 this, SLOT(updateNewMenu()));
1129 KAction
* newWindow
= actionCollection()->addAction("new_window");
1130 newWindow
->setIcon(KIcon("window-new"));
1131 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1132 newWindow
->setShortcut(Qt::CTRL
| Qt::Key_N
);
1133 connect(newWindow
, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1135 KAction
* newTab
= actionCollection()->addAction("new_tab");
1136 newTab
->setIcon(KIcon("tab-new"));
1137 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1138 newTab
->setShortcut(KShortcut(Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
));
1139 connect(newTab
, SIGNAL(triggered()), this, SLOT(openNewTab()));
1141 KAction
* closeTab
= actionCollection()->addAction("close_tab");
1142 closeTab
->setIcon(KIcon("tab-close"));
1143 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1144 closeTab
->setShortcut(Qt::CTRL
| Qt::Key_W
);
1145 closeTab
->setEnabled(false);
1146 connect(closeTab
, SIGNAL(triggered()), this, SLOT(closeTab()));
1148 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1150 // setup 'Edit' menu
1151 KStandardAction::undo(this,
1153 actionCollection());
1155 // need to remove shift+del from cut action, else the shortcut for deletejob
1157 KAction
* cut
= KStandardAction::cut(this, SLOT(cut()), actionCollection());
1158 KShortcut cutShortcut
= cut
->shortcut();
1159 cutShortcut
.remove(Qt::SHIFT
+ Qt::Key_Delete
, KShortcut::KeepEmpty
);
1160 cut
->setShortcut(cutShortcut
);
1161 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1162 KStandardAction::paste(this, SLOT(paste()), actionCollection());
1164 KAction
* selectAll
= actionCollection()->addAction("select_all");
1165 selectAll
->setText(i18nc("@action:inmenu Edit", "Select All"));
1166 selectAll
->setShortcut(Qt::CTRL
+ Qt::Key_A
);
1167 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
1169 KAction
* invertSelection
= actionCollection()->addAction("invert_selection");
1170 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1171 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1172 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
1174 // setup 'View' menu
1175 // (note that most of it is set up in DolphinViewActionHandler)
1177 KAction
* split
= actionCollection()->addAction("split_view");
1178 split
->setShortcut(Qt::Key_F3
);
1179 updateSplitAction();
1180 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1182 KAction
* reload
= actionCollection()->addAction("reload");
1183 reload
->setText(i18nc("@action:inmenu View", "Reload"));
1184 reload
->setShortcut(Qt::Key_F5
);
1185 reload
->setIcon(KIcon("view-refresh"));
1186 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
1188 KAction
* stop
= actionCollection()->addAction("stop");
1189 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1190 stop
->setIcon(KIcon("process-stop"));
1191 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
1193 KToggleAction
* showFullLocation
= actionCollection()->add
<KToggleAction
>("editable_location");
1194 showFullLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1195 showFullLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
1196 connect(showFullLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1198 KAction
* replaceLocation
= actionCollection()->addAction("replace_location");
1199 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1200 replaceLocation
->setShortcut(Qt::Key_F6
);
1201 connect(replaceLocation
, SIGNAL(triggered()), this, SLOT(replaceLocation()));
1204 KAction
* backAction
= KStandardAction::back(this, SLOT(goBack()), actionCollection());
1205 KShortcut backShortcut
= backAction
->shortcut();
1206 backShortcut
.setAlternate(Qt::Key_Backspace
);
1207 backAction
->setShortcut(backShortcut
);
1209 m_recentTabsMenu
= new KActionMenu(i18n("Recently Closed Tabs"), this);
1210 m_recentTabsMenu
->setIcon(KIcon("edit-undo"));
1211 actionCollection()->addAction("closed_tabs", m_recentTabsMenu
);
1212 connect(m_recentTabsMenu
->menu(), SIGNAL(triggered(QAction
*)),
1213 this, SLOT(restoreClosedTab(QAction
*)));
1215 QAction
* action
= new QAction("Empty Recently Closed Tabs", m_recentTabsMenu
);
1216 action
->setIcon(KIcon("edit-clear-list"));
1217 action
->setData(QVariant::fromValue(true));
1218 m_recentTabsMenu
->addAction(action
);
1219 m_recentTabsMenu
->addSeparator();
1220 m_recentTabsMenu
->setEnabled(false);
1222 KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1223 KStandardAction::up(this, SLOT(goUp()), actionCollection());
1224 KStandardAction::home(this, SLOT(goHome()), actionCollection());
1226 // setup 'Tools' menu
1227 KToggleAction
* showSearchBar
= actionCollection()->add
<KToggleAction
>("show_search_bar");
1228 showSearchBar
->setText(i18nc("@action:inmenu Tools", "Show Search Bar"));
1229 showSearchBar
->setShortcut(Qt::CTRL
| Qt::Key_S
);
1230 connect(showSearchBar
, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
1232 KToggleAction
* showFilterBar
= actionCollection()->add
<KToggleAction
>("show_filter_bar");
1233 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1234 showFilterBar
->setShortcut(Qt::CTRL
| Qt::Key_I
);
1235 connect(showFilterBar
, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
1237 KAction
* compareFiles
= actionCollection()->addAction("compare_files");
1238 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1239 compareFiles
->setIcon(KIcon("kompare"));
1240 compareFiles
->setEnabled(false);
1241 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
1243 KAction
* openTerminal
= actionCollection()->addAction("open_terminal");
1244 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1245 openTerminal
->setIcon(KIcon("terminal"));
1246 openTerminal
->setShortcut(Qt::SHIFT
| Qt::Key_F4
);
1247 connect(openTerminal
, SIGNAL(triggered()), this, SLOT(openTerminal()));
1249 // setup 'Settings' menu
1250 m_showMenuBar
= KStandardAction::showMenubar(this, SLOT(toggleShowMenuBar()), actionCollection());
1251 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1253 // not in menu actions
1254 KAction
* activateNextTab
= actionCollection()->addAction("activate_next_tab");
1255 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1256 connect(activateNextTab
, SIGNAL(triggered()), SLOT(activateNextTab()));
1257 activateNextTab
->setShortcuts(QApplication::isRightToLeft() ? KStandardShortcut::tabPrev() :
1258 KStandardShortcut::tabNext());
1260 KAction
* activatePrevTab
= actionCollection()->addAction("activate_prev_tab");
1261 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1262 connect(activatePrevTab
, SIGNAL(triggered()), SLOT(activatePrevTab()));
1263 activatePrevTab
->setShortcuts(QApplication::isRightToLeft() ? KStandardShortcut::tabNext() :
1264 KStandardShortcut::tabPrev());
1267 KAction
* openInNewTab
= actionCollection()->addAction("open_in_new_tab");
1268 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1269 openInNewTab
->setIcon(KIcon("tab-new"));
1270 connect(openInNewTab
, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1272 KAction
* openInNewWindow
= actionCollection()->addAction("open_in_new_window");
1273 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1274 openInNewWindow
->setIcon(KIcon("window-new"));
1275 connect(openInNewWindow
, SIGNAL(triggered()), this, SLOT(openInNewWindow()));
1278 m_searchBox
= new DolphinSearchBox(this);
1279 connect(m_searchBox
, SIGNAL(search(KUrl
)), this, SLOT(searchItems(KUrl
)));
1281 KAction
* search
= new KAction(this);
1282 actionCollection()->addAction("search_bar", search
);
1283 search
->setText(i18nc("@action:inmenu", "Search Bar"));
1284 search
->setDefaultWidget(m_searchBox
);
1285 search
->setShortcutConfigurable(false);
1288 void DolphinMainWindow::setupDockWidgets()
1290 // setup "Information"
1291 QDockWidget
* infoDock
= new QDockWidget(i18nc("@title:window", "Information"));
1292 infoDock
->setObjectName("infoDock");
1293 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1294 Panel
* infoPanel
= new InformationPanel(infoDock
);
1295 infoDock
->setWidget(infoPanel
);
1297 QAction
* infoAction
= infoDock
->toggleViewAction();
1298 infoAction
->setText(i18nc("@title:window", "Information"));
1299 infoAction
->setShortcut(Qt::Key_F11
);
1300 infoAction
->setIcon(KIcon("dialog-information"));
1301 actionCollection()->addAction("show_info_panel", infoDock
->toggleViewAction());
1303 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1304 connect(this, SIGNAL(urlChanged(KUrl
)),
1305 infoPanel
, SLOT(setUrl(KUrl
)));
1306 connect(this, SIGNAL(selectionChanged(KFileItemList
)),
1307 infoPanel
, SLOT(setSelection(KFileItemList
)));
1308 connect(this, SIGNAL(requestItemInfo(KFileItem
)),
1309 infoPanel
, SLOT(requestDelayedItemInfo(KFileItem
)));
1312 QDockWidget
* foldersDock
= new QDockWidget(i18nc("@title:window", "Folders"));
1313 foldersDock
->setObjectName("foldersDock");
1314 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1315 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1316 foldersDock
->setWidget(foldersPanel
);
1318 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1319 foldersAction
->setText(i18nc("@title:window", "Folders"));
1320 foldersAction
->setShortcut(Qt::Key_F7
);
1321 foldersAction
->setIcon(KIcon("folder"));
1322 actionCollection()->addAction("show_folders_panel", foldersDock
->toggleViewAction());
1324 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1325 connect(this, SIGNAL(urlChanged(KUrl
)),
1326 foldersPanel
, SLOT(setUrl(KUrl
)));
1327 connect(foldersPanel
, SIGNAL(changeUrl(KUrl
, Qt::MouseButtons
)),
1328 this, SLOT(handlePlacesClick(KUrl
, Qt::MouseButtons
)));
1329 connect(foldersPanel
, SIGNAL(changeSelection(KFileItemList
)),
1330 this, SLOT(changeSelection(KFileItemList
)));
1334 QDockWidget
* terminalDock
= new QDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1335 terminalDock
->setObjectName("terminalDock");
1336 terminalDock
->setAllowedAreas(Qt::TopDockWidgetArea
| Qt::BottomDockWidgetArea
);
1337 Panel
* terminalPanel
= new TerminalPanel(terminalDock
);
1338 terminalDock
->setWidget(terminalPanel
);
1340 connect(terminalPanel
, SIGNAL(hideTerminalPanel()), terminalDock
, SLOT(hide()));
1342 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1343 terminalAction
->setText(i18nc("@title:window Shell terminal", "Terminal"));
1344 terminalAction
->setShortcut(Qt::Key_F4
);
1345 terminalAction
->setIcon(KIcon("terminal"));
1346 actionCollection()->addAction("show_terminal_panel", terminalDock
->toggleViewAction());
1348 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1349 connect(this, SIGNAL(urlChanged(KUrl
)),
1350 terminalPanel
, SLOT(setUrl(KUrl
)));
1353 const bool firstRun
= DolphinSettings::instance().generalSettings()->firstRun();
1355 foldersDock
->hide();
1357 terminalDock
->hide();
1361 QDockWidget
* placesDock
= new QDockWidget(i18nc("@title:window", "Places"));
1362 placesDock
->setObjectName("placesDock");
1363 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1365 PlacesPanel
* placesPanel
= new PlacesPanel(placesDock
);
1366 placesDock
->setWidget(placesPanel
);
1367 placesPanel
->setModel(DolphinSettings::instance().placesModel());
1368 placesPanel
->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff
);
1370 QAction
* placesAction
= placesDock
->toggleViewAction();
1371 placesAction
->setText(i18nc("@title:window", "Places"));
1372 placesAction
->setShortcut(Qt::Key_F9
);
1373 placesAction
->setIcon(KIcon("bookmarks"));
1374 actionCollection()->addAction("show_places_panel", placesDock
->toggleViewAction());
1376 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1377 connect(placesPanel
, SIGNAL(urlChanged(KUrl
, Qt::MouseButtons
)),
1378 this, SLOT(handlePlacesClick(KUrl
, Qt::MouseButtons
)));
1379 connect(this, SIGNAL(urlChanged(KUrl
)),
1380 placesPanel
, SLOT(setUrl(KUrl
)));
1383 void DolphinMainWindow::updateEditActions()
1385 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1386 if (list
.isEmpty()) {
1387 stateChanged("has_no_selection");
1389 stateChanged("has_selection");
1391 KActionCollection
* col
= actionCollection();
1392 QAction
* renameAction
= col
->action("rename");
1393 QAction
* moveToTrashAction
= col
->action("move_to_trash");
1394 QAction
* deleteAction
= col
->action("delete");
1395 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
1396 QAction
* deleteWithTrashShortcut
= col
->action("delete_shortcut"); // see DolphinViewActionHandler
1398 KFileItemListProperties
capabilities(list
);
1399 const bool enableMoveToTrash
= capabilities
.isLocal() && capabilities
.supportsMoving();
1401 renameAction
->setEnabled(capabilities
.supportsMoving());
1402 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1403 deleteAction
->setEnabled(capabilities
.supportsDeleting());
1404 deleteWithTrashShortcut
->setEnabled(capabilities
.supportsDeleting() && !enableMoveToTrash
);
1405 cutAction
->setEnabled(capabilities
.supportsMoving());
1407 updatePasteAction();
1410 void DolphinMainWindow::updateViewActions()
1412 m_actionHandler
->updateViewActions();
1414 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1415 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
1417 updateSplitAction();
1419 QAction
* editableLocactionAction
= actionCollection()->action("editable_location");
1420 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
1421 editableLocactionAction
->setChecked(urlNavigator
->isUrlEditable());
1424 void DolphinMainWindow::updateGoActions()
1426 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
1427 const KUrl
& currentUrl
= m_activeViewContainer
->url();
1428 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
1431 void DolphinMainWindow::rememberClosedTab(int index
)
1433 KMenu
* tabsMenu
= m_recentTabsMenu
->menu();
1435 const QString primaryPath
= m_viewTab
[index
].primaryView
->url().path();
1436 const QString iconName
= KMimeType::iconNameForUrl(primaryPath
);
1438 const QFontMetrics fm
= fontMetrics();
1439 const QString actionText
= fm
.elidedText(primaryPath
, Qt::ElideMiddle
, fm
.maxWidth() * 20);
1441 QAction
* action
= new QAction(actionText
, tabsMenu
);
1443 ClosedTab closedTab
;
1444 closedTab
.primaryUrl
= m_viewTab
[index
].primaryView
->url();
1446 if (m_viewTab
[index
].secondaryView
!= 0) {
1447 closedTab
.secondaryUrl
= m_viewTab
[index
].secondaryView
->url();
1448 closedTab
.isSplit
= true;
1450 closedTab
.isSplit
= false;
1453 action
->setData(QVariant::fromValue(closedTab
));
1454 action
->setIcon(KIcon(iconName
));
1456 // add the closed tab menu entry after the separator and
1457 // "Empty Recently Closed Tabs" entry
1458 if (tabsMenu
->actions().size() == 2) {
1459 tabsMenu
->addAction(action
);
1461 tabsMenu
->insertAction(tabsMenu
->actions().at(2), action
);
1464 // assure that only up to 8 closed tabs are shown in the menu
1465 if (tabsMenu
->actions().size() > 8) {
1466 tabsMenu
->removeAction(tabsMenu
->actions().last());
1468 actionCollection()->action("closed_tabs")->setEnabled(true);
1469 KAcceleratorManager::manage(tabsMenu
);
1472 void DolphinMainWindow::clearStatusBar()
1474 m_activeViewContainer
->statusBar()->clear();
1477 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
1479 connect(container
, SIGNAL(showFilterBarChanged(bool)),
1480 this, SLOT(updateFilterBarAction(bool)));
1482 DolphinView
* view
= container
->view();
1483 connect(view
, SIGNAL(selectionChanged(KFileItemList
)),
1484 this, SLOT(slotSelectionChanged(KFileItemList
)));
1485 connect(view
, SIGNAL(requestItemInfo(KFileItem
)),
1486 this, SLOT(slotRequestItemInfo(KFileItem
)));
1487 connect(view
, SIGNAL(activated()),
1488 this, SLOT(toggleActiveView()));
1489 connect(view
, SIGNAL(tabRequested(const KUrl
&)),
1490 this, SLOT(openNewTab(const KUrl
&)));
1492 const KUrlNavigator
* navigator
= container
->urlNavigator();
1493 connect(navigator
, SIGNAL(urlChanged(const KUrl
&)),
1494 this, SLOT(changeUrl(const KUrl
&)));
1495 connect(navigator
, SIGNAL(historyChanged()),
1496 this, SLOT(updateHistory()));
1497 connect(navigator
, SIGNAL(editableStateChanged(bool)),
1498 this, SLOT(slotEditableStateChanged(bool)));
1501 void DolphinMainWindow::updateSplitAction()
1503 QAction
* splitAction
= actionCollection()->action("split_view");
1504 if (m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
1505 if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
1506 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
1507 splitAction
->setIcon(KIcon("view-right-close"));
1509 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
1510 splitAction
->setIcon(KIcon("view-left-close"));
1513 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
1514 splitAction
->setIcon(KIcon("view-right-new"));
1518 QString
DolphinMainWindow::tabName(const KUrl
& url
) const
1521 if (url
.equals(KUrl("file:///"))) {
1524 name
= url
.fileName();
1525 if (name
.isEmpty()) {
1526 name
= url
.protocol();
1528 // Make sure that a '&' inside the directory name is displayed correctly
1529 // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
1530 name
.replace('&', "&&");
1536 bool DolphinMainWindow::isKompareInstalled() const
1538 static bool initialized
= false;
1539 static bool installed
= false;
1541 // TODO: maybe replace this approach later by using a menu
1542 // plugin like kdiff3plugin.cpp
1543 installed
= !KGlobal::dirs()->findExe("kompare").isEmpty();
1549 void DolphinMainWindow::createSecondaryView(int tabIndex
)
1551 QSplitter
* splitter
= m_viewTab
[tabIndex
].splitter
;
1552 const int newWidth
= (m_viewTab
[tabIndex
].primaryView
->width() - splitter
->handleWidth()) / 2;
1554 const DolphinView
* view
= m_viewTab
[tabIndex
].primaryView
->view();
1555 m_viewTab
[tabIndex
].secondaryView
= new DolphinViewContainer(this, 0, view
->rootUrl());
1556 splitter
->addWidget(m_viewTab
[tabIndex
].secondaryView
);
1557 splitter
->setSizes(QList
<int>() << newWidth
<< newWidth
);
1558 connectViewSignals(m_viewTab
[tabIndex
].secondaryView
);
1559 m_viewTab
[tabIndex
].secondaryView
->view()->reload();
1560 m_viewTab
[tabIndex
].secondaryView
->setActive(false);
1561 m_viewTab
[tabIndex
].secondaryView
->show();
1564 QString
DolphinMainWindow::tabProperty(const QString
& property
, int tabIndex
) const
1566 return "Tab " + QString::number(tabIndex
) + ' ' + property
;
1569 void DolphinMainWindow::setUrlAsCaption(const KUrl
& url
)
1572 if (url
.equals(KUrl("file:///"))) {
1575 caption
= url
.fileName();
1576 if (caption
.isEmpty()) {
1577 caption
= url
.protocol();
1581 setCaption(caption
);
1584 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
1585 KIO::FileUndoManager::UiInterface()
1589 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
1593 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
1595 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
1597 DolphinStatusBar
* statusBar
= mainWin
->activeViewContainer()->statusBar();
1598 statusBar
->setMessage(job
->errorString(), DolphinStatusBar::Error
);
1600 KIO::FileUndoManager::UiInterface::jobError(job
);
1604 #include "dolphinmainwindow.moc"