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>
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 if ((m_viewTab
.count() > 1) && generalSettings
->confirmClosingMultipleTabs()) {
430 // Ask the user if he really wants to quit and close all tabs.
431 // Open a confirmation dialog with 3 buttons:
432 // KDialog::Yes -> Quit
433 // KDialog::No -> Close only the current tab
434 // KDialog::Cancel -> do nothing
435 KDialog
*dialog
= new KDialog(this, Qt::Dialog
);
436 dialog
->setCaption(i18nc("@title:window", "Confirmation"));
437 dialog
->setButtons(KDialog::Yes
| KDialog::No
| KDialog::Cancel
);
438 dialog
->setModal(true);
439 dialog
->showButtonSeparator(true);
440 dialog
->setButtonGuiItem(KDialog::Yes
, KStandardGuiItem::quit());
441 dialog
->setButtonGuiItem(KDialog::No
, KGuiItem(i18n("C&lose Current Tab"), KIcon("tab-close")));
442 dialog
->setButtonGuiItem(KDialog::Cancel
, KStandardGuiItem::cancel());
443 dialog
->setDefaultButton(KDialog::Yes
);
445 bool doNotAskAgainCheckboxResult
= false;
447 const int result
= KMessageBox::createKMessageBox(dialog
,
448 QMessageBox::Warning
,
449 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
451 i18n("Do not ask again"),
452 &doNotAskAgainCheckboxResult
,
453 KMessageBox::Notify
);
455 if (doNotAskAgainCheckboxResult
) {
456 generalSettings
->setConfirmClosingMultipleTabs(false);
464 // Close only the current tab
472 generalSettings
->setFirstRun(false);
476 KXmlGuiWindow::closeEvent(event
);
479 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
481 const int tabCount
= m_viewTab
.count();
482 group
.writeEntry("Tab Count", tabCount
);
483 group
.writeEntry("Active Tab Index", m_tabBar
->currentIndex());
485 for (int i
= 0; i
< tabCount
; ++i
) {
486 const DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
487 group
.writeEntry(tabProperty("Primary URL", i
), cont
->url().url());
488 group
.writeEntry(tabProperty("Primary Editable", i
), cont
->isUrlEditable());
490 cont
= m_viewTab
[i
].secondaryView
;
492 group
.writeEntry(tabProperty("Secondary URL", i
), cont
->url().url());
493 group
.writeEntry(tabProperty("Secondary Editable", i
), cont
->isUrlEditable());
498 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
500 const int tabCount
= group
.readEntry("Tab Count", 1);
501 for (int i
= 0; i
< tabCount
; ++i
) {
502 DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
504 cont
->setUrl(group
.readEntry(tabProperty("Primary URL", i
)));
505 const bool editable
= group
.readEntry(tabProperty("Primary Editable", i
), false);
506 cont
->urlNavigator()->setUrlEditable(editable
);
508 cont
= m_viewTab
[i
].secondaryView
;
509 const QString secondaryUrl
= group
.readEntry(tabProperty("Secondary URL", i
));
510 if (!secondaryUrl
.isEmpty()) {
512 // a secondary view should be shown, but no one is available
513 // currently -> create a new view
515 cont
= m_viewTab
[i
].secondaryView
;
519 cont
->setUrl(secondaryUrl
);
520 const bool editable
= group
.readEntry(tabProperty("Secondary Editable", i
), false);
521 cont
->urlNavigator()->setUrlEditable(editable
);
522 } else if (cont
!= 0) {
523 // no secondary view should be shown, but the default setting shows
524 // one already -> close the view
528 // openNewTab() needs to be called only tabCount - 1 times
529 if (i
!= tabCount
- 1) {
534 const int index
= group
.readEntry("Active Tab Index", 0);
535 m_tabBar
->setCurrentIndex(index
);
538 void DolphinMainWindow::updateNewMenu()
540 m_newMenu
->slotCheckUpToDate();
541 m_newMenu
->setPopupFiles(activeViewContainer()->url());
544 void DolphinMainWindow::createDirectory()
546 m_newMenu
->setPopupFiles(activeViewContainer()->url());
547 m_newMenu
->createDirectory();
550 void DolphinMainWindow::quit()
555 void DolphinMainWindow::showErrorMessage(const QString
& message
)
557 if (!message
.isEmpty()) {
558 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
559 statusBar
->setMessage(message
, DolphinStatusBar::Error
);
563 void DolphinMainWindow::slotUndoAvailable(bool available
)
565 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
566 if (undoAction
!= 0) {
567 undoAction
->setEnabled(available
);
571 void DolphinMainWindow::restoreClosedTab(QAction
* action
)
573 if (action
->data().toBool()) {
574 // clear all actions except the "Empty Recently Closed Tabs"
575 // action and the separator
576 QList
<QAction
*> actions
= m_recentTabsMenu
->menu()->actions();
577 const int count
= actions
.size();
578 for (int i
= 2; i
< count
; ++i
) {
579 m_recentTabsMenu
->menu()->removeAction(actions
.at(i
));
582 const ClosedTab closedTab
= action
->data().value
<ClosedTab
>();
583 openNewTab(closedTab
.primaryUrl
);
584 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
586 if (closedTab
.isSplit
) {
587 // create secondary view
589 m_viewTab
[m_tabIndex
].secondaryView
->setUrl(closedTab
.secondaryUrl
);
592 m_recentTabsMenu
->removeAction(action
);
595 if (m_recentTabsMenu
->menu()->actions().count() == 2) {
596 m_recentTabsMenu
->setEnabled(false);
600 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
602 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
603 if (undoAction
!= 0) {
604 undoAction
->setText(text
);
608 void DolphinMainWindow::undo()
611 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
612 KIO::FileUndoManager::self()->undo();
615 void DolphinMainWindow::cut()
617 m_activeViewContainer
->view()->cutSelectedItems();
620 void DolphinMainWindow::copy()
622 m_activeViewContainer
->view()->copySelectedItems();
625 void DolphinMainWindow::paste()
627 m_activeViewContainer
->view()->paste();
630 void DolphinMainWindow::updatePasteAction()
632 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
633 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
634 pasteAction
->setEnabled(pasteInfo
.first
);
635 pasteAction
->setText(pasteInfo
.second
);
638 void DolphinMainWindow::selectAll()
642 // if the URL navigator is editable and focused, select the whole
643 // URL instead of all items of the view
645 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
646 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit(); // krazy:exclude=qclasses
647 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
648 lineEdit
->hasFocus();
650 lineEdit
->selectAll();
652 m_activeViewContainer
->view()->selectAll();
656 void DolphinMainWindow::invertSelection()
659 m_activeViewContainer
->view()->invertSelection();
662 void DolphinMainWindow::toggleSplitView()
664 if (m_viewTab
[m_tabIndex
].secondaryView
== 0) {
665 createSecondaryView(m_tabIndex
);
666 setActiveViewContainer(m_viewTab
[m_tabIndex
].secondaryView
);
667 } else if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
668 // remove secondary view
669 m_viewTab
[m_tabIndex
].secondaryView
->close();
670 m_viewTab
[m_tabIndex
].secondaryView
->deleteLater();
671 m_viewTab
[m_tabIndex
].secondaryView
= 0;
673 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
675 // The primary view is active and should be closed. Hence from a users point of view
676 // the content of the secondary view should be moved to the primary view.
677 // From an implementation point of view it is more efficient to close
678 // the primary view and exchange the internal pointers afterwards.
680 m_viewTab
[m_tabIndex
].primaryView
->close();
681 m_viewTab
[m_tabIndex
].primaryView
->deleteLater();
682 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
683 m_viewTab
[m_tabIndex
].secondaryView
= 0;
685 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
691 void DolphinMainWindow::reloadView()
694 m_activeViewContainer
->view()->reload();
697 void DolphinMainWindow::stopLoading()
701 void DolphinMainWindow::toggleFilterBarVisibility(bool show
)
703 m_activeViewContainer
->showFilterBar(show
);
706 void DolphinMainWindow::toggleEditLocation()
710 QAction
* action
= actionCollection()->action("editable_location");
711 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
712 urlNavigator
->setUrlEditable(action
->isChecked());
715 void DolphinMainWindow::replaceLocation()
717 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
718 navigator
->setUrlEditable(true);
719 navigator
->setFocus();
721 // select the whole text of the combo box editor
722 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit(); // krazy:exclude=qclasses
723 const QString text
= lineEdit
->text();
724 lineEdit
->setSelection(0, text
.length());
727 void DolphinMainWindow::goBack()
730 m_activeViewContainer
->urlNavigator()->goBack();
733 void DolphinMainWindow::goForward()
736 m_activeViewContainer
->urlNavigator()->goForward();
739 void DolphinMainWindow::goUp()
742 m_activeViewContainer
->urlNavigator()->goUp();
745 void DolphinMainWindow::goHome()
748 m_activeViewContainer
->urlNavigator()->goHome();
751 void DolphinMainWindow::compareFiles()
753 // The method is only invoked if exactly 2 files have
754 // been selected. The selected files may be:
755 // - both in the primary view
756 // - both in the secondary view
757 // - one in the primary view and the other in the secondary
759 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
763 KUrl::List urls
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedUrls();
765 switch (urls
.count()) {
767 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
!= 0);
768 urls
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedUrls();
769 Q_ASSERT(urls
.count() == 2);
777 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
!= 0);
778 urls
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedUrls();
779 Q_ASSERT(urls
.count() == 1);
791 // may not happen: compareFiles may only get invoked if 2
792 // files are selected
797 QString
command("kompare -c \"");
798 command
.append(urlA
.pathOrUrl());
799 command
.append("\" \"");
800 command
.append(urlB
.pathOrUrl());
801 command
.append('\"');
802 KRun::runCommand(command
, "Kompare", "kompare", this);
805 void DolphinMainWindow::toggleShowMenuBar()
807 const bool visible
= menuBar()->isVisible();
808 menuBar()->setVisible(!visible
);
811 void DolphinMainWindow::openTerminal()
813 QString
dir(QDir::homePath());
815 // If the given directory is not local, it can still be the URL of an
816 // ioslave using UDS_LOCAL_PATH which to be converted first.
817 KUrl url
= KIO::NetAccess::mostLocalUrl(m_activeViewContainer
->url(), this);
819 //If the URL is local after the above conversion, set the directory.
820 if (url
.isLocalFile()) {
821 dir
= url
.toLocalFile();
824 KToolInvocation::invokeTerminal(QString(), dir
);
827 void DolphinMainWindow::editSettings()
829 if (m_settingsDialog
== 0) {
830 const KUrl
& url
= activeViewContainer()->url();
831 m_settingsDialog
= new DolphinSettingsDialog(url
, this);
832 m_settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
833 m_settingsDialog
->show();
835 m_settingsDialog
->raise();
839 void DolphinMainWindow::setActiveTab(int index
)
841 Q_ASSERT(index
>= 0);
842 Q_ASSERT(index
< m_viewTab
.count());
843 if (index
== m_tabIndex
) {
847 // hide current tab content
848 ViewTab
& hiddenTab
= m_viewTab
[m_tabIndex
];
849 hiddenTab
.isPrimaryViewActive
= hiddenTab
.primaryView
->isActive();
850 hiddenTab
.primaryView
->setActive(false);
851 if (hiddenTab
.secondaryView
!= 0) {
852 hiddenTab
.secondaryView
->setActive(false);
854 QSplitter
* splitter
= m_viewTab
[m_tabIndex
].splitter
;
856 m_centralWidgetLayout
->removeWidget(splitter
);
858 // show active tab content
861 ViewTab
& viewTab
= m_viewTab
[index
];
862 m_centralWidgetLayout
->addWidget(viewTab
.splitter
);
863 viewTab
.primaryView
->show();
864 if (viewTab
.secondaryView
!= 0) {
865 viewTab
.secondaryView
->show();
867 viewTab
.splitter
->show();
869 setActiveViewContainer(viewTab
.isPrimaryViewActive
? viewTab
.primaryView
:
870 viewTab
.secondaryView
);
873 void DolphinMainWindow::closeTab()
875 closeTab(m_tabBar
->currentIndex());
878 void DolphinMainWindow::closeTab(int index
)
880 Q_ASSERT(index
>= 0);
881 Q_ASSERT(index
< m_viewTab
.count());
882 if (m_viewTab
.count() == 1) {
883 // the last tab may never get closed
887 if (index
== m_tabIndex
) {
888 // The tab that should be closed is the active tab. Activate the
889 // previous tab before closing the tab.
890 m_tabBar
->setCurrentIndex((index
> 0) ? index
- 1 : 1);
892 rememberClosedTab(index
);
895 m_viewTab
[index
].primaryView
->deleteLater();
896 if (m_viewTab
[index
].secondaryView
!= 0) {
897 m_viewTab
[index
].secondaryView
->deleteLater();
899 m_viewTab
[index
].splitter
->deleteLater();
900 m_viewTab
.erase(m_viewTab
.begin() + index
);
902 m_tabBar
->blockSignals(true);
903 m_tabBar
->removeTab(index
);
905 if (m_tabIndex
> index
) {
907 Q_ASSERT(m_tabIndex
>= 0);
910 // if only one tab is left, also remove the tab entry so that
911 // closing the last tab is not possible
912 if (m_viewTab
.count() == 1) {
913 m_tabBar
->removeTab(0);
914 actionCollection()->action("close_tab")->setEnabled(false);
916 m_tabBar
->blockSignals(false);
920 void DolphinMainWindow::openTabContextMenu(int index
, const QPoint
& pos
)
924 QAction
* newTabAction
= menu
.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab"));
925 newTabAction
->setShortcut(actionCollection()->action("new_tab")->shortcut());
927 QAction
* closeOtherTabsAction
= menu
.addAction(KIcon("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs"));
929 QAction
* closeTabAction
= menu
.addAction(KIcon("tab-close"), i18nc("@action:inmenu", "Close Tab"));
930 closeTabAction
->setShortcut(actionCollection()->action("close_tab")->shortcut());
931 QAction
* selectedAction
= menu
.exec(pos
);
932 if (selectedAction
== newTabAction
) {
933 const ViewTab
& tab
= m_viewTab
[index
];
934 Q_ASSERT(tab
.primaryView
!= 0);
935 const KUrl url
= (tab
.secondaryView
!= 0) && tab
.secondaryView
->isActive() ?
936 tab
.secondaryView
->url() : tab
.primaryView
->url();
938 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
939 } else if (selectedAction
== closeOtherTabsAction
) {
940 const int count
= m_tabBar
->count();
941 for (int i
= 0; i
< index
; ++i
) {
944 for (int i
= index
+ 1; i
< count
; ++i
) {
947 } else if (selectedAction
== closeTabAction
) {
952 void DolphinMainWindow::handlePlacesClick(const KUrl
& url
, Qt::MouseButtons buttons
)
954 if (buttons
& Qt::MidButton
) {
956 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
962 void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent
* event
, bool& canDecode
)
964 canDecode
= KUrl::List::canDecode(event
->mimeData());
967 void DolphinMainWindow::searchItems(const KUrl
& url
)
969 m_activeViewContainer
->setUrl(url
);
972 void DolphinMainWindow::slotTabMoved(int from
, int to
)
974 m_viewTab
.move(from
, to
);
975 m_tabIndex
= m_tabBar
->currentIndex();
978 void DolphinMainWindow::init()
980 DolphinSettings
& settings
= DolphinSettings::instance();
982 // Check whether Dolphin runs the first time. If yes then
983 // a proper default window size is given at the end of DolphinMainWindow::init().
984 GeneralSettings
* generalSettings
= settings
.generalSettings();
985 const bool firstRun
= generalSettings
->firstRun();
987 generalSettings
->setViewPropsTimestamp(QDateTime::currentDateTime());
990 setAcceptDrops(true);
992 m_viewTab
[m_tabIndex
].splitter
= new QSplitter(this);
993 m_viewTab
[m_tabIndex
].splitter
->setChildrenCollapsible(false);
997 const KUrl
& homeUrl
= generalSettings
->homeUrl();
998 setUrlAsCaption(homeUrl
);
999 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
1000 connect(m_actionHandler
, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
1001 connect(m_actionHandler
, SIGNAL(createDirectory()), SLOT(createDirectory()));
1002 ViewProperties
props(homeUrl
);
1003 m_viewTab
[m_tabIndex
].primaryView
= new DolphinViewContainer(this,
1004 m_viewTab
[m_tabIndex
].splitter
,
1007 m_activeViewContainer
= m_viewTab
[m_tabIndex
].primaryView
;
1008 connectViewSignals(m_activeViewContainer
);
1009 DolphinView
* view
= m_activeViewContainer
->view();
1011 m_activeViewContainer
->show();
1012 m_actionHandler
->setCurrentView(view
);
1014 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
1015 connect(this, SIGNAL(urlChanged(const KUrl
&)),
1016 m_remoteEncoding
, SLOT(slotAboutToOpenUrl()));
1018 m_tabBar
= new KTabBar(this);
1019 m_tabBar
->setMovable(true);
1020 m_tabBar
->setTabsClosable(true);
1021 connect(m_tabBar
, SIGNAL(currentChanged(int)),
1022 this, SLOT(setActiveTab(int)));
1023 connect(m_tabBar
, SIGNAL(tabCloseRequested(int)),
1024 this, SLOT(closeTab(int)));
1025 connect(m_tabBar
, SIGNAL(contextMenu(int, const QPoint
&)),
1026 this, SLOT(openTabContextMenu(int, const QPoint
&)));
1027 connect(m_tabBar
, SIGNAL(newTabRequest()),
1028 this, SLOT(openNewTab()));
1029 connect(m_tabBar
, SIGNAL(testCanDecode(const QDragMoveEvent
*, bool&)),
1030 this, SLOT(slotTestCanDecode(const QDragMoveEvent
*, bool&)));
1031 connect(m_tabBar
, SIGNAL(wheelDelta(int)),
1032 this, SLOT(slotWheelMoved(int)));
1033 connect(m_tabBar
, SIGNAL(mouseMiddleClick(int)),
1034 this, SLOT(closeTab(int)));
1035 connect(m_tabBar
, SIGNAL(tabMoved(int, int)),
1036 this, SLOT(slotTabMoved(int, int)));
1038 m_tabBar
->blockSignals(true); // signals get unblocked after at least 2 tabs are open
1040 QWidget
* centralWidget
= new QWidget(this);
1041 m_centralWidgetLayout
= new QVBoxLayout(centralWidget
);
1042 m_centralWidgetLayout
->setSpacing(0);
1043 m_centralWidgetLayout
->setMargin(0);
1044 m_centralWidgetLayout
->addWidget(m_tabBar
);
1045 m_centralWidgetLayout
->addWidget(m_viewTab
[m_tabIndex
].splitter
);
1047 setCentralWidget(centralWidget
);
1049 emit
urlChanged(homeUrl
);
1051 setupGUI(Keys
| Save
| Create
| ToolBar
);
1053 m_searchBox
->setParent(toolBar("searchToolBar"));
1054 m_searchBox
->show();
1056 stateChanged("new_file");
1058 QClipboard
* clipboard
= QApplication::clipboard();
1059 connect(clipboard
, SIGNAL(dataChanged()),
1060 this, SLOT(updatePasteAction()));
1061 updatePasteAction();
1064 if (generalSettings
->splitView()) {
1067 updateViewActions();
1069 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1070 showFilterBarAction
->setChecked(generalSettings
->filterBar());
1073 // assure a proper default size if Dolphin runs the first time
1077 m_showMenuBar
->setChecked(!menuBar()->isHidden()); // workaround for bug #171080
1080 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer
* viewContainer
)
1082 Q_ASSERT(viewContainer
!= 0);
1083 Q_ASSERT((viewContainer
== m_viewTab
[m_tabIndex
].primaryView
) ||
1084 (viewContainer
== m_viewTab
[m_tabIndex
].secondaryView
));
1085 if (m_activeViewContainer
== viewContainer
) {
1089 m_activeViewContainer
->setActive(false);
1090 m_activeViewContainer
= viewContainer
;
1092 // Activating the view container might trigger a recursive setActiveViewContainer() call
1093 // inside DolphinMainWindow::toggleActiveView() when having a split view. Temporary
1094 // disconnect the activated() signal in this case:
1095 disconnect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1096 m_activeViewContainer
->setActive(true);
1097 connect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1099 m_actionHandler
->setCurrentView(viewContainer
->view());
1102 updateEditActions();
1103 updateViewActions();
1106 const KUrl
& url
= m_activeViewContainer
->url();
1107 setUrlAsCaption(url
);
1108 if (m_viewTab
.count() > 1 && m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
1109 m_tabBar
->setTabText(m_tabIndex
, tabName(url
));
1110 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(KMimeType::iconNameForUrl(url
)));
1113 emit
urlChanged(url
);
1116 void DolphinMainWindow::setupActions()
1118 // setup 'File' menu
1119 m_newMenu
= new DolphinNewMenu(this, this);
1120 KMenu
* menu
= m_newMenu
->menu();
1121 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1122 menu
->setIcon(KIcon("document-new"));
1123 connect(menu
, SIGNAL(aboutToShow()),
1124 this, SLOT(updateNewMenu()));
1126 KAction
* newWindow
= actionCollection()->addAction("new_window");
1127 newWindow
->setIcon(KIcon("window-new"));
1128 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1129 newWindow
->setShortcut(Qt::CTRL
| Qt::Key_N
);
1130 connect(newWindow
, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1132 KAction
* newTab
= actionCollection()->addAction("new_tab");
1133 newTab
->setIcon(KIcon("tab-new"));
1134 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1135 newTab
->setShortcut(KShortcut(Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
));
1136 connect(newTab
, SIGNAL(triggered()), this, SLOT(openNewTab()));
1138 KAction
* closeTab
= actionCollection()->addAction("close_tab");
1139 closeTab
->setIcon(KIcon("tab-close"));
1140 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1141 closeTab
->setShortcut(Qt::CTRL
| Qt::Key_W
);
1142 closeTab
->setEnabled(false);
1143 connect(closeTab
, SIGNAL(triggered()), this, SLOT(closeTab()));
1145 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1147 // setup 'Edit' menu
1148 KStandardAction::undo(this,
1150 actionCollection());
1152 // need to remove shift+del from cut action, else the shortcut for deletejob
1154 KAction
* cut
= KStandardAction::cut(this, SLOT(cut()), actionCollection());
1155 KShortcut cutShortcut
= cut
->shortcut();
1156 cutShortcut
.remove(Qt::SHIFT
+ Qt::Key_Delete
, KShortcut::KeepEmpty
);
1157 cut
->setShortcut(cutShortcut
);
1158 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1159 KStandardAction::paste(this, SLOT(paste()), actionCollection());
1161 KAction
* selectAll
= actionCollection()->addAction("select_all");
1162 selectAll
->setText(i18nc("@action:inmenu Edit", "Select All"));
1163 selectAll
->setShortcut(Qt::CTRL
+ Qt::Key_A
);
1164 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
1166 KAction
* invertSelection
= actionCollection()->addAction("invert_selection");
1167 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1168 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1169 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
1171 // setup 'View' menu
1172 // (note that most of it is set up in DolphinViewActionHandler)
1174 KAction
* split
= actionCollection()->addAction("split_view");
1175 split
->setShortcut(Qt::Key_F3
);
1176 updateSplitAction();
1177 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1179 KAction
* reload
= actionCollection()->addAction("reload");
1180 reload
->setText(i18nc("@action:inmenu View", "Reload"));
1181 reload
->setShortcut(Qt::Key_F5
);
1182 reload
->setIcon(KIcon("view-refresh"));
1183 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
1185 KAction
* stop
= actionCollection()->addAction("stop");
1186 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1187 stop
->setIcon(KIcon("process-stop"));
1188 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
1190 KToggleAction
* showFullLocation
= actionCollection()->add
<KToggleAction
>("editable_location");
1191 showFullLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1192 showFullLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
1193 connect(showFullLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1195 KAction
* replaceLocation
= actionCollection()->addAction("replace_location");
1196 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1197 replaceLocation
->setShortcut(Qt::Key_F6
);
1198 connect(replaceLocation
, SIGNAL(triggered()), this, SLOT(replaceLocation()));
1201 KAction
* backAction
= KStandardAction::back(this, SLOT(goBack()), actionCollection());
1202 KShortcut backShortcut
= backAction
->shortcut();
1203 backShortcut
.setAlternate(Qt::Key_Backspace
);
1204 backAction
->setShortcut(backShortcut
);
1206 m_recentTabsMenu
= new KActionMenu(i18n("Recently Closed Tabs"), this);
1207 m_recentTabsMenu
->setIcon(KIcon("edit-undo"));
1208 actionCollection()->addAction("closed_tabs", m_recentTabsMenu
);
1209 connect(m_recentTabsMenu
->menu(), SIGNAL(triggered(QAction
*)),
1210 this, SLOT(restoreClosedTab(QAction
*)));
1212 QAction
* action
= new QAction("Empty Recently Closed Tabs", m_recentTabsMenu
);
1213 action
->setIcon(KIcon("edit-clear-list"));
1214 action
->setData(QVariant::fromValue(true));
1215 m_recentTabsMenu
->addAction(action
);
1216 m_recentTabsMenu
->addSeparator();
1217 m_recentTabsMenu
->setEnabled(false);
1219 KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1220 KStandardAction::up(this, SLOT(goUp()), actionCollection());
1221 KStandardAction::home(this, SLOT(goHome()), actionCollection());
1223 // setup 'Tools' menu
1224 KToggleAction
* showSearchBar
= actionCollection()->add
<KToggleAction
>("show_search_bar");
1225 showSearchBar
->setText(i18nc("@action:inmenu Tools", "Show Search Bar"));
1226 showSearchBar
->setShortcut(Qt::CTRL
| Qt::Key_S
);
1227 connect(showSearchBar
, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
1229 KToggleAction
* showFilterBar
= actionCollection()->add
<KToggleAction
>("show_filter_bar");
1230 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1231 showFilterBar
->setShortcut(Qt::CTRL
| Qt::Key_I
);
1232 connect(showFilterBar
, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
1234 KAction
* compareFiles
= actionCollection()->addAction("compare_files");
1235 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1236 compareFiles
->setIcon(KIcon("kompare"));
1237 compareFiles
->setEnabled(false);
1238 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
1240 KAction
* openTerminal
= actionCollection()->addAction("open_terminal");
1241 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1242 openTerminal
->setIcon(KIcon("utilities-terminal"));
1243 openTerminal
->setShortcut(Qt::SHIFT
| Qt::Key_F4
);
1244 connect(openTerminal
, SIGNAL(triggered()), this, SLOT(openTerminal()));
1246 // setup 'Settings' menu
1247 m_showMenuBar
= KStandardAction::showMenubar(this, SLOT(toggleShowMenuBar()), actionCollection());
1248 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1250 // not in menu actions
1251 KAction
* activateNextTab
= actionCollection()->addAction("activate_next_tab");
1252 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1253 connect(activateNextTab
, SIGNAL(triggered()), SLOT(activateNextTab()));
1254 activateNextTab
->setShortcuts(QApplication::isRightToLeft() ? KStandardShortcut::tabPrev() :
1255 KStandardShortcut::tabNext());
1257 KAction
* activatePrevTab
= actionCollection()->addAction("activate_prev_tab");
1258 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1259 connect(activatePrevTab
, SIGNAL(triggered()), SLOT(activatePrevTab()));
1260 activatePrevTab
->setShortcuts(QApplication::isRightToLeft() ? KStandardShortcut::tabNext() :
1261 KStandardShortcut::tabPrev());
1264 KAction
* openInNewTab
= actionCollection()->addAction("open_in_new_tab");
1265 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1266 openInNewTab
->setIcon(KIcon("tab-new"));
1267 connect(openInNewTab
, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1269 KAction
* openInNewWindow
= actionCollection()->addAction("open_in_new_window");
1270 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1271 openInNewWindow
->setIcon(KIcon("window-new"));
1272 connect(openInNewWindow
, SIGNAL(triggered()), this, SLOT(openInNewWindow()));
1275 m_searchBox
= new DolphinSearchBox(this);
1276 connect(m_searchBox
, SIGNAL(search(KUrl
)), this, SLOT(searchItems(KUrl
)));
1278 KAction
* search
= new KAction(this);
1279 actionCollection()->addAction("search_bar", search
);
1280 search
->setText(i18nc("@action:inmenu", "Search Bar"));
1281 search
->setDefaultWidget(m_searchBox
);
1282 search
->setShortcutConfigurable(false);
1285 void DolphinMainWindow::setupDockWidgets()
1287 // setup "Information"
1288 QDockWidget
* infoDock
= new QDockWidget(i18nc("@title:window", "Information"));
1289 infoDock
->setObjectName("infoDock");
1290 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1291 Panel
* infoPanel
= new InformationPanel(infoDock
);
1292 infoDock
->setWidget(infoPanel
);
1294 QAction
* infoAction
= infoDock
->toggleViewAction();
1295 infoAction
->setText(i18nc("@title:window", "Information"));
1296 infoAction
->setShortcut(Qt::Key_F11
);
1297 infoAction
->setIcon(KIcon("dialog-information"));
1298 actionCollection()->addAction("show_info_panel", infoDock
->toggleViewAction());
1300 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1301 connect(this, SIGNAL(urlChanged(KUrl
)),
1302 infoPanel
, SLOT(setUrl(KUrl
)));
1303 connect(this, SIGNAL(selectionChanged(KFileItemList
)),
1304 infoPanel
, SLOT(setSelection(KFileItemList
)));
1305 connect(this, SIGNAL(requestItemInfo(KFileItem
)),
1306 infoPanel
, SLOT(requestDelayedItemInfo(KFileItem
)));
1309 QDockWidget
* foldersDock
= new QDockWidget(i18nc("@title:window", "Folders"));
1310 foldersDock
->setObjectName("foldersDock");
1311 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1312 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1313 foldersDock
->setWidget(foldersPanel
);
1315 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1316 foldersAction
->setText(i18nc("@title:window", "Folders"));
1317 foldersAction
->setShortcut(Qt::Key_F7
);
1318 foldersAction
->setIcon(KIcon("folder"));
1319 actionCollection()->addAction("show_folders_panel", foldersDock
->toggleViewAction());
1321 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1322 connect(this, SIGNAL(urlChanged(KUrl
)),
1323 foldersPanel
, SLOT(setUrl(KUrl
)));
1324 connect(foldersPanel
, SIGNAL(changeUrl(KUrl
, Qt::MouseButtons
)),
1325 this, SLOT(handlePlacesClick(KUrl
, Qt::MouseButtons
)));
1326 connect(foldersPanel
, SIGNAL(changeSelection(KFileItemList
)),
1327 this, SLOT(changeSelection(KFileItemList
)));
1331 QDockWidget
* terminalDock
= new QDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1332 terminalDock
->setObjectName("terminalDock");
1333 terminalDock
->setAllowedAreas(Qt::TopDockWidgetArea
| Qt::BottomDockWidgetArea
);
1334 Panel
* terminalPanel
= new TerminalPanel(terminalDock
);
1335 terminalDock
->setWidget(terminalPanel
);
1337 connect(terminalPanel
, SIGNAL(hideTerminalPanel()), terminalDock
, SLOT(hide()));
1339 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1340 terminalAction
->setText(i18nc("@title:window Shell terminal", "Terminal"));
1341 terminalAction
->setShortcut(Qt::Key_F4
);
1342 terminalAction
->setIcon(KIcon("utilities-terminal"));
1343 actionCollection()->addAction("show_terminal_panel", terminalDock
->toggleViewAction());
1345 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1346 connect(this, SIGNAL(urlChanged(KUrl
)),
1347 terminalPanel
, SLOT(setUrl(KUrl
)));
1350 const bool firstRun
= DolphinSettings::instance().generalSettings()->firstRun();
1352 foldersDock
->hide();
1354 terminalDock
->hide();
1358 QDockWidget
* placesDock
= new QDockWidget(i18nc("@title:window", "Places"));
1359 placesDock
->setObjectName("placesDock");
1360 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1362 PlacesPanel
* placesPanel
= new PlacesPanel(placesDock
);
1363 placesDock
->setWidget(placesPanel
);
1364 placesPanel
->setModel(DolphinSettings::instance().placesModel());
1365 placesPanel
->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff
);
1367 QAction
* placesAction
= placesDock
->toggleViewAction();
1368 placesAction
->setText(i18nc("@title:window", "Places"));
1369 placesAction
->setShortcut(Qt::Key_F9
);
1370 placesAction
->setIcon(KIcon("bookmarks"));
1371 actionCollection()->addAction("show_places_panel", placesDock
->toggleViewAction());
1373 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1374 connect(placesPanel
, SIGNAL(urlChanged(KUrl
, Qt::MouseButtons
)),
1375 this, SLOT(handlePlacesClick(KUrl
, Qt::MouseButtons
)));
1376 connect(this, SIGNAL(urlChanged(KUrl
)),
1377 placesPanel
, SLOT(setUrl(KUrl
)));
1380 void DolphinMainWindow::updateEditActions()
1382 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1383 if (list
.isEmpty()) {
1384 stateChanged("has_no_selection");
1386 stateChanged("has_selection");
1388 KActionCollection
* col
= actionCollection();
1389 QAction
* renameAction
= col
->action("rename");
1390 QAction
* moveToTrashAction
= col
->action("move_to_trash");
1391 QAction
* deleteAction
= col
->action("delete");
1392 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
1393 QAction
* deleteWithTrashShortcut
= col
->action("delete_shortcut"); // see DolphinViewActionHandler
1395 KFileItemListProperties
capabilities(list
);
1396 const bool enableMoveToTrash
= capabilities
.isLocal() && capabilities
.supportsMoving();
1398 renameAction
->setEnabled(capabilities
.supportsMoving());
1399 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1400 deleteAction
->setEnabled(capabilities
.supportsDeleting());
1401 deleteWithTrashShortcut
->setEnabled(capabilities
.supportsDeleting() && !enableMoveToTrash
);
1402 cutAction
->setEnabled(capabilities
.supportsMoving());
1404 updatePasteAction();
1407 void DolphinMainWindow::updateViewActions()
1409 m_actionHandler
->updateViewActions();
1411 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1412 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
1414 updateSplitAction();
1416 QAction
* editableLocactionAction
= actionCollection()->action("editable_location");
1417 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
1418 editableLocactionAction
->setChecked(urlNavigator
->isUrlEditable());
1421 void DolphinMainWindow::updateGoActions()
1423 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
1424 const KUrl
& currentUrl
= m_activeViewContainer
->url();
1425 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
1428 void DolphinMainWindow::rememberClosedTab(int index
)
1430 KMenu
* tabsMenu
= m_recentTabsMenu
->menu();
1432 const QString primaryPath
= m_viewTab
[index
].primaryView
->url().path();
1433 const QString iconName
= KMimeType::iconNameForUrl(primaryPath
);
1435 QAction
* action
= new QAction(squeezedText(primaryPath
), tabsMenu
);
1437 ClosedTab closedTab
;
1438 closedTab
.primaryUrl
= m_viewTab
[index
].primaryView
->url();
1440 if (m_viewTab
[index
].secondaryView
!= 0) {
1441 closedTab
.secondaryUrl
= m_viewTab
[index
].secondaryView
->url();
1442 closedTab
.isSplit
= true;
1444 closedTab
.isSplit
= false;
1447 action
->setData(QVariant::fromValue(closedTab
));
1448 action
->setIcon(KIcon(iconName
));
1450 // add the closed tab menu entry after the separator and
1451 // "Empty Recently Closed Tabs" entry
1452 if (tabsMenu
->actions().size() == 2) {
1453 tabsMenu
->addAction(action
);
1455 tabsMenu
->insertAction(tabsMenu
->actions().at(2), action
);
1458 // assure that only up to 8 closed tabs are shown in the menu
1459 if (tabsMenu
->actions().size() > 8) {
1460 tabsMenu
->removeAction(tabsMenu
->actions().last());
1462 actionCollection()->action("closed_tabs")->setEnabled(true);
1463 KAcceleratorManager::manage(tabsMenu
);
1466 void DolphinMainWindow::clearStatusBar()
1468 m_activeViewContainer
->statusBar()->clear();
1471 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
1473 connect(container
, SIGNAL(showFilterBarChanged(bool)),
1474 this, SLOT(updateFilterBarAction(bool)));
1476 DolphinView
* view
= container
->view();
1477 connect(view
, SIGNAL(selectionChanged(KFileItemList
)),
1478 this, SLOT(slotSelectionChanged(KFileItemList
)));
1479 connect(view
, SIGNAL(requestItemInfo(KFileItem
)),
1480 this, SLOT(slotRequestItemInfo(KFileItem
)));
1481 connect(view
, SIGNAL(activated()),
1482 this, SLOT(toggleActiveView()));
1483 connect(view
, SIGNAL(tabRequested(const KUrl
&)),
1484 this, SLOT(openNewTab(const KUrl
&)));
1486 const KUrlNavigator
* navigator
= container
->urlNavigator();
1487 connect(navigator
, SIGNAL(urlChanged(const KUrl
&)),
1488 this, SLOT(changeUrl(const KUrl
&)));
1489 connect(navigator
, SIGNAL(historyChanged()),
1490 this, SLOT(updateHistory()));
1491 connect(navigator
, SIGNAL(editableStateChanged(bool)),
1492 this, SLOT(slotEditableStateChanged(bool)));
1495 void DolphinMainWindow::updateSplitAction()
1497 QAction
* splitAction
= actionCollection()->action("split_view");
1498 if (m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
1499 if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
1500 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
1501 splitAction
->setIcon(KIcon("view-right-close"));
1503 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
1504 splitAction
->setIcon(KIcon("view-left-close"));
1507 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
1508 splitAction
->setIcon(KIcon("view-right-new"));
1512 QString
DolphinMainWindow::tabName(const KUrl
& url
) const
1515 if (url
.equals(KUrl("file:///"))) {
1518 name
= url
.fileName();
1519 if (name
.isEmpty()) {
1520 name
= url
.protocol();
1522 // Make sure that a '&' inside the directory name is displayed correctly
1523 // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
1524 name
.replace('&', "&&");
1530 bool DolphinMainWindow::isKompareInstalled() const
1532 static bool initialized
= false;
1533 static bool installed
= false;
1535 // TODO: maybe replace this approach later by using a menu
1536 // plugin like kdiff3plugin.cpp
1537 installed
= !KGlobal::dirs()->findExe("kompare").isEmpty();
1543 void DolphinMainWindow::createSecondaryView(int tabIndex
)
1545 QSplitter
* splitter
= m_viewTab
[tabIndex
].splitter
;
1546 const int newWidth
= (m_viewTab
[tabIndex
].primaryView
->width() - splitter
->handleWidth()) / 2;
1548 const DolphinView
* view
= m_viewTab
[tabIndex
].primaryView
->view();
1549 m_viewTab
[tabIndex
].secondaryView
= new DolphinViewContainer(this, 0, view
->rootUrl());
1550 splitter
->addWidget(m_viewTab
[tabIndex
].secondaryView
);
1551 splitter
->setSizes(QList
<int>() << newWidth
<< newWidth
);
1552 connectViewSignals(m_viewTab
[tabIndex
].secondaryView
);
1553 m_viewTab
[tabIndex
].secondaryView
->view()->reload();
1554 m_viewTab
[tabIndex
].secondaryView
->setActive(false);
1555 m_viewTab
[tabIndex
].secondaryView
->show();
1558 QString
DolphinMainWindow::tabProperty(const QString
& property
, int tabIndex
) const
1560 return "Tab " + QString::number(tabIndex
) + ' ' + property
;
1563 void DolphinMainWindow::setUrlAsCaption(const KUrl
& url
)
1566 if (url
.equals(KUrl("file:///"))) {
1569 caption
= url
.fileName();
1570 if (caption
.isEmpty()) {
1571 caption
= url
.protocol();
1575 setCaption(caption
);
1578 QString
DolphinMainWindow::squeezedText(const QString
& text
) const
1580 const QFontMetrics fm
= fontMetrics();
1581 return fm
.elidedText(text
, Qt::ElideMiddle
, fm
.maxWidth() * 10);
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"