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"
24 #include <config-nepomuk.h>
26 #include "dolphinapplication.h"
27 #include "dolphincontextmenu.h"
28 #include "dolphinnewfilemenu.h"
29 #include "dolphinviewcontainer.h"
30 #include "mainwindowadaptor.h"
31 #include "panels/folders/folderspanel.h"
32 #include "panels/places/placespanel.h"
33 #include "panels/information/informationpanel.h"
34 #include "settings/dolphinsettings.h"
35 #include "settings/dolphinsettingsdialog.h"
36 #include "statusbar/dolphinstatusbar.h"
37 #include "views/dolphinviewactionhandler.h"
38 #include "views/dolphinremoteencoding.h"
39 #include "views/draganddrophelper.h"
40 #include "views/viewproperties.h"
43 #include "panels/terminal/terminalpanel.h"
46 #include "dolphin_generalsettings.h"
47 #include "dolphin_iconsmodesettings.h"
50 #include <kactioncollection.h>
51 #include <kactionmenu.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),
118 m_lastHandleUrlStatJob(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::openDirectories(const QList
<KUrl
>& dirs
)
151 if (dirs
.isEmpty()) {
155 const int oldOpenTabsCount
= m_viewTab
.count();
157 const GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
158 const bool hasSplitView
= generalSettings
->splitView();
160 // Open each directory inside a new tab. If the "split view" option has been enabled,
161 // always show two directories within one tab.
162 QList
<KUrl
>::const_iterator it
= dirs
.begin();
163 while (it
!= dirs
.end()) {
167 if (hasSplitView
&& (it
!= dirs
.end())) {
168 const int tabIndex
= m_viewTab
.count() - 1;
169 m_viewTab
[tabIndex
].secondaryView
->setUrl(*it
);
174 // remove the previously opened tabs
175 for (int i
= 0; i
< oldOpenTabsCount
; ++i
) {
180 void DolphinMainWindow::openFiles(const QList
<KUrl
>& files
)
182 if (files
.isEmpty()) {
186 // Get all distinct directories from 'files' and open a tab
187 // for each directory. If the "split view" option is enabled, two
188 // directories are shown inside one tab (see openDirectories()).
190 foreach (const KUrl
& url
, files
) {
191 const KUrl
dir(url
.directory());
192 if (!dirs
.contains(dir
)) {
197 openDirectories(dirs
);
199 // Select the files. Although the files can be split between several
200 // tabs, there is no need to split 'files' accordingly, as
201 // the DolphinView will just ignore invalid selections.
202 const int tabCount
= m_viewTab
.count();
203 for (int i
= 0; i
< tabCount
; ++i
) {
204 m_viewTab
[i
].primaryView
->view()->markUrlsAsSelected(files
);
205 if (m_viewTab
[i
].secondaryView
!= 0) {
206 m_viewTab
[i
].secondaryView
->view()->markUrlsAsSelected(files
);
211 void DolphinMainWindow::toggleViews()
213 if (m_viewTab
[m_tabIndex
].primaryView
== 0) {
217 // move secondary view from the last position of the splitter
218 // to the first position
219 m_viewTab
[m_tabIndex
].splitter
->insertWidget(0, m_viewTab
[m_tabIndex
].secondaryView
);
221 DolphinViewContainer
* container
= m_viewTab
[m_tabIndex
].primaryView
;
222 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
223 m_viewTab
[m_tabIndex
].secondaryView
= container
;
226 void DolphinMainWindow::showCommand(CommandType command
)
228 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
230 case KIO::FileUndoManager::Copy
:
231 statusBar
->setMessage(i18nc("@info:status", "Successfully copied."),
232 DolphinStatusBar::OperationCompleted
);
234 case KIO::FileUndoManager::Move
:
235 statusBar
->setMessage(i18nc("@info:status", "Successfully moved."),
236 DolphinStatusBar::OperationCompleted
);
238 case KIO::FileUndoManager::Link
:
239 statusBar
->setMessage(i18nc("@info:status", "Successfully linked."),
240 DolphinStatusBar::OperationCompleted
);
242 case KIO::FileUndoManager::Trash
:
243 statusBar
->setMessage(i18nc("@info:status", "Successfully moved to trash."),
244 DolphinStatusBar::OperationCompleted
);
246 case KIO::FileUndoManager::Rename
:
247 statusBar
->setMessage(i18nc("@info:status", "Successfully renamed."),
248 DolphinStatusBar::OperationCompleted
);
251 case KIO::FileUndoManager::Mkdir
:
252 statusBar
->setMessage(i18nc("@info:status", "Created folder."),
253 DolphinStatusBar::OperationCompleted
);
261 void DolphinMainWindow::refreshViews()
263 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
265 // remember the current active view, as because of
266 // the refreshing the active view might change to
267 // the secondary view
268 DolphinViewContainer
* activeViewContainer
= m_activeViewContainer
;
270 const int tabCount
= m_viewTab
.count();
271 for (int i
= 0; i
< tabCount
; ++i
) {
272 m_viewTab
[i
].primaryView
->refresh();
273 if (m_viewTab
[i
].secondaryView
!= 0) {
274 m_viewTab
[i
].secondaryView
->refresh();
278 setActiveViewContainer(activeViewContainer
);
281 void DolphinMainWindow::pasteIntoFolder()
283 m_activeViewContainer
->view()->pasteIntoFolder();
286 void DolphinMainWindow::changeUrl(const KUrl
& url
)
288 if (!KProtocolManager::supportsListing(url
)) {
289 // The URL navigator only checks for validity, not
290 // if the URL can be listed. An error message is
291 // shown due to DolphinViewContainer::restoreView().
295 DolphinViewContainer
* view
= activeViewContainer();
301 setUrlAsCaption(url
);
302 if (m_viewTab
.count() > 1) {
303 m_tabBar
->setTabText(m_tabIndex
, squeezedText(tabName(m_activeViewContainer
->url())));
305 const QString iconName
= KMimeType::iconNameForUrl(url
);
306 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(iconName
));
307 emit
urlChanged(url
);
311 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
313 KToggleAction
* editableLocationAction
=
314 static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
315 editableLocationAction
->setChecked(editable
);
318 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
322 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
323 int selectedUrlsCount
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedItemsCount();
324 if (m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
325 selectedUrlsCount
+= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItemsCount();
328 QAction
* compareFilesAction
= actionCollection()->action("compare_files");
329 if (selectedUrlsCount
== 2) {
330 compareFilesAction
->setEnabled(isKompareInstalled());
332 compareFilesAction
->setEnabled(false);
335 emit
selectionChanged(selection
);
338 void DolphinMainWindow::slotRequestItemInfo(const KFileItem
& item
)
340 emit
requestItemInfo(item
);
343 void DolphinMainWindow::updateHistory()
345 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
346 const int index
= urlNavigator
->historyIndex();
348 QAction
* backAction
= actionCollection()->action("go_back");
349 backAction
->setToolTip(i18nc("@info", "Go back"));
350 if (backAction
!= 0) {
351 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
354 QAction
* forwardAction
= actionCollection()->action("go_forward");
355 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
356 if (forwardAction
!= 0) {
357 forwardAction
->setEnabled(index
> 0);
361 void DolphinMainWindow::updateFilterBarAction(bool show
)
363 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
364 showFilterBarAction
->setChecked(show
);
367 void DolphinMainWindow::openNewMainWindow()
369 DolphinApplication::app()->createMainWindow()->show();
372 void DolphinMainWindow::openNewTab()
374 const bool isUrlEditable
= m_activeViewContainer
->urlNavigator()->isUrlEditable();
376 openNewTab(m_activeViewContainer
->url());
377 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
379 // The URL navigator of the new tab should have the same editable state
380 // as the current tab
381 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
382 navigator
->setUrlEditable(isUrlEditable
);
385 // If a new tab is opened and the URL is editable, assure that
386 // the user can edit the URL without manually setting the focus
387 navigator
->setFocus();
391 void DolphinMainWindow::openNewTab(const KUrl
& url
)
393 QWidget
* focusWidget
= QApplication::focusWidget();
395 if (m_viewTab
.count() == 1) {
396 // Only one view is open currently and hence no tab is shown at
397 // all. Before creating a tab for 'url', provide a tab for the current URL.
398 const KUrl currentUrl
= m_activeViewContainer
->url();
399 m_tabBar
->addTab(KIcon(KMimeType::iconNameForUrl(currentUrl
)),
400 squeezedText(tabName(currentUrl
)));
401 m_tabBar
->blockSignals(false);
404 m_tabBar
->addTab(KIcon(KMimeType::iconNameForUrl(url
)),
405 squeezedText(tabName(url
)));
408 viewTab
.splitter
= new QSplitter(this);
409 viewTab
.splitter
->setChildrenCollapsible(false);
410 viewTab
.primaryView
= new DolphinViewContainer(url
, viewTab
.splitter
);
411 viewTab
.primaryView
->setActive(false);
412 connectViewSignals(viewTab
.primaryView
);
413 viewTab
.primaryView
->view()->reload();
415 m_viewTab
.append(viewTab
);
417 actionCollection()->action("close_tab")->setEnabled(true);
419 // provide a split view, if the startup settings are set this way
420 const GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
421 if (generalSettings
->splitView()) {
422 const int tabIndex
= m_viewTab
.count() - 1;
423 createSecondaryView(tabIndex
);
424 m_viewTab
[tabIndex
].secondaryView
->setActive(true);
425 m_viewTab
[tabIndex
].isPrimaryViewActive
= false;
428 if (focusWidget
!= 0) {
429 // The DolphinViewContainer grabbed the keyboard focus. As the tab is opened
430 // in background, assure that the previous focused widget gets the focus back.
431 focusWidget
->setFocus();
435 void DolphinMainWindow::activateNextTab()
437 if ((m_viewTab
.count() == 1) || (m_tabBar
->count() < 2)) {
441 const int tabIndex
= (m_tabBar
->currentIndex() + 1) % m_tabBar
->count();
442 m_tabBar
->setCurrentIndex(tabIndex
);
445 void DolphinMainWindow::activatePrevTab()
447 if ((m_viewTab
.count() == 1) || (m_tabBar
->count() < 2)) {
451 int tabIndex
= m_tabBar
->currentIndex() - 1;
452 if (tabIndex
== -1) {
453 tabIndex
= m_tabBar
->count() - 1;
455 m_tabBar
->setCurrentIndex(tabIndex
);
458 void DolphinMainWindow::openInNewTab()
460 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
461 if ((list
.count() == 1) && list
[0].isDir()) {
462 openNewTab(m_activeViewContainer
->view()->selectedUrls()[0]);
466 void DolphinMainWindow::openInNewWindow()
468 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
469 if ((list
.count() == 1) && list
[0].isDir()) {
470 DolphinMainWindow
* window
= DolphinApplication::app()->createMainWindow();
471 window
->changeUrl(m_activeViewContainer
->view()->selectedUrls()[0]);
476 void DolphinMainWindow::toggleActiveView()
478 if (m_viewTab
[m_tabIndex
].secondaryView
== 0) {
479 // only one view is available
483 Q_ASSERT(m_activeViewContainer
!= 0);
484 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
486 DolphinViewContainer
* left
= m_viewTab
[m_tabIndex
].primaryView
;
487 DolphinViewContainer
* right
= m_viewTab
[m_tabIndex
].secondaryView
;
488 setActiveViewContainer(m_activeViewContainer
== right
? left
: right
);
491 void DolphinMainWindow::showEvent(QShowEvent
* event
)
493 KXmlGuiWindow::showEvent(event
);
494 if (!event
->spontaneous()) {
495 m_activeViewContainer
->view()->setFocus();
499 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
501 DolphinSettings
& settings
= DolphinSettings::instance();
502 GeneralSettings
* generalSettings
= settings
.generalSettings();
504 // Find out if Dolphin is closed directly by the user or
505 // by the session manager because the session is closed
506 bool closedByUser
= true;
507 DolphinApplication
*application
= qobject_cast
<DolphinApplication
*>(qApp
);
508 if (application
&& application
->sessionSaving()) {
509 closedByUser
= false;
512 if ((m_viewTab
.count() > 1) && generalSettings
->confirmClosingMultipleTabs() && closedByUser
) {
513 // Ask the user if he really wants to quit and close all tabs.
514 // Open a confirmation dialog with 3 buttons:
515 // KDialog::Yes -> Quit
516 // KDialog::No -> Close only the current tab
517 // KDialog::Cancel -> do nothing
518 KDialog
*dialog
= new KDialog(this, Qt::Dialog
);
519 dialog
->setCaption(i18nc("@title:window", "Confirmation"));
520 dialog
->setButtons(KDialog::Yes
| KDialog::No
| KDialog::Cancel
);
521 dialog
->setModal(true);
522 dialog
->setButtonGuiItem(KDialog::Yes
, KStandardGuiItem::quit());
523 dialog
->setButtonGuiItem(KDialog::No
, KGuiItem(i18n("C&lose Current Tab"), KIcon("tab-close")));
524 dialog
->setButtonGuiItem(KDialog::Cancel
, KStandardGuiItem::cancel());
525 dialog
->setDefaultButton(KDialog::Yes
);
527 bool doNotAskAgainCheckboxResult
= false;
529 const int result
= KMessageBox::createKMessageBox(dialog
,
530 QMessageBox::Warning
,
531 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
533 i18n("Do not ask again"),
534 &doNotAskAgainCheckboxResult
,
535 KMessageBox::Notify
);
537 if (doNotAskAgainCheckboxResult
) {
538 generalSettings
->setConfirmClosingMultipleTabs(false);
546 // Close only the current tab
554 generalSettings
->setFirstRun(false);
558 KXmlGuiWindow::closeEvent(event
);
561 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
563 const int tabCount
= m_viewTab
.count();
564 group
.writeEntry("Tab Count", tabCount
);
565 group
.writeEntry("Active Tab Index", m_tabBar
->currentIndex());
567 for (int i
= 0; i
< tabCount
; ++i
) {
568 const DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
569 group
.writeEntry(tabProperty("Primary URL", i
), cont
->url().url());
570 group
.writeEntry(tabProperty("Primary Editable", i
),
571 cont
->urlNavigator()->isUrlEditable());
573 cont
= m_viewTab
[i
].secondaryView
;
575 group
.writeEntry(tabProperty("Secondary URL", i
), cont
->url().url());
576 group
.writeEntry(tabProperty("Secondary Editable", i
),
577 cont
->urlNavigator()->isUrlEditable());
582 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
584 const int tabCount
= group
.readEntry("Tab Count", 1);
585 for (int i
= 0; i
< tabCount
; ++i
) {
586 DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
588 cont
->setUrl(group
.readEntry(tabProperty("Primary URL", i
)));
589 const bool editable
= group
.readEntry(tabProperty("Primary Editable", i
), false);
590 cont
->urlNavigator()->setUrlEditable(editable
);
592 cont
= m_viewTab
[i
].secondaryView
;
593 const QString secondaryUrl
= group
.readEntry(tabProperty("Secondary URL", i
));
594 if (!secondaryUrl
.isEmpty()) {
596 // a secondary view should be shown, but no one is available
597 // currently -> create a new view
599 cont
= m_viewTab
[i
].secondaryView
;
603 cont
->setUrl(secondaryUrl
);
604 const bool editable
= group
.readEntry(tabProperty("Secondary Editable", i
), false);
605 cont
->urlNavigator()->setUrlEditable(editable
);
606 } else if (cont
!= 0) {
607 // no secondary view should be shown, but the default setting shows
608 // one already -> close the view
612 // openNewTab() needs to be called only tabCount - 1 times
613 if (i
!= tabCount
- 1) {
618 const int index
= group
.readEntry("Active Tab Index", 0);
619 m_tabBar
->setCurrentIndex(index
);
622 void DolphinMainWindow::updateNewMenu()
624 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->showHiddenFiles());
625 m_newFileMenu
->checkUpToDate();
626 m_newFileMenu
->setPopupFiles(activeViewContainer()->url());
629 void DolphinMainWindow::createDirectory()
631 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->showHiddenFiles());
632 m_newFileMenu
->setPopupFiles(activeViewContainer()->url());
633 m_newFileMenu
->createDirectory();
636 void DolphinMainWindow::quit()
641 void DolphinMainWindow::showErrorMessage(const QString
& message
)
643 if (!message
.isEmpty()) {
644 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
645 statusBar
->setMessage(message
, DolphinStatusBar::Error
);
649 void DolphinMainWindow::slotUndoAvailable(bool available
)
651 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
652 if (undoAction
!= 0) {
653 undoAction
->setEnabled(available
);
657 void DolphinMainWindow::restoreClosedTab(QAction
* action
)
659 if (action
->data().toBool()) {
660 // clear all actions except the "Empty Recently Closed Tabs"
661 // action and the separator
662 QList
<QAction
*> actions
= m_recentTabsMenu
->menu()->actions();
663 const int count
= actions
.size();
664 for (int i
= 2; i
< count
; ++i
) {
665 m_recentTabsMenu
->menu()->removeAction(actions
.at(i
));
668 const ClosedTab closedTab
= action
->data().value
<ClosedTab
>();
669 openNewTab(closedTab
.primaryUrl
);
670 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
672 if (closedTab
.isSplit
) {
673 // create secondary view
675 m_viewTab
[m_tabIndex
].secondaryView
->setUrl(closedTab
.secondaryUrl
);
678 m_recentTabsMenu
->removeAction(action
);
681 if (m_recentTabsMenu
->menu()->actions().count() == 2) {
682 m_recentTabsMenu
->setEnabled(false);
686 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
688 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
689 if (undoAction
!= 0) {
690 undoAction
->setText(text
);
694 void DolphinMainWindow::undo()
697 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
698 KIO::FileUndoManager::self()->undo();
701 void DolphinMainWindow::cut()
703 m_activeViewContainer
->view()->cutSelectedItems();
706 void DolphinMainWindow::copy()
708 m_activeViewContainer
->view()->copySelectedItems();
711 void DolphinMainWindow::paste()
713 m_activeViewContainer
->view()->paste();
716 void DolphinMainWindow::find()
718 m_activeViewContainer
->setSearchModeEnabled(true);
721 void DolphinMainWindow::updatePasteAction()
723 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
724 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
725 pasteAction
->setEnabled(pasteInfo
.first
);
726 pasteAction
->setText(pasteInfo
.second
);
729 void DolphinMainWindow::selectAll()
733 // if the URL navigator is editable and focused, select the whole
734 // URL instead of all items of the view
736 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
737 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit(); // krazy:exclude=qclasses
738 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
739 lineEdit
->hasFocus();
741 lineEdit
->selectAll();
743 m_activeViewContainer
->view()->selectAll();
747 void DolphinMainWindow::invertSelection()
750 m_activeViewContainer
->view()->invertSelection();
753 void DolphinMainWindow::toggleSplitView()
755 if (m_viewTab
[m_tabIndex
].secondaryView
== 0) {
756 createSecondaryView(m_tabIndex
);
757 setActiveViewContainer(m_viewTab
[m_tabIndex
].secondaryView
);
758 } else if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
759 // remove secondary view
760 m_viewTab
[m_tabIndex
].secondaryView
->close();
761 m_viewTab
[m_tabIndex
].secondaryView
->deleteLater();
762 m_viewTab
[m_tabIndex
].secondaryView
= 0;
764 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
766 // The primary view is active and should be closed. Hence from a users point of view
767 // the content of the secondary view should be moved to the primary view.
768 // From an implementation point of view it is more efficient to close
769 // the primary view and exchange the internal pointers afterwards.
771 m_viewTab
[m_tabIndex
].primaryView
->close();
772 m_viewTab
[m_tabIndex
].primaryView
->deleteLater();
773 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
774 m_viewTab
[m_tabIndex
].secondaryView
= 0;
776 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
782 void DolphinMainWindow::reloadView()
785 m_activeViewContainer
->view()->reload();
788 void DolphinMainWindow::stopLoading()
792 void DolphinMainWindow::toggleFilterBarVisibility(bool show
)
794 m_activeViewContainer
->showFilterBar(show
);
797 void DolphinMainWindow::toggleEditLocation()
801 QAction
* action
= actionCollection()->action("editable_location");
802 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
803 urlNavigator
->setUrlEditable(action
->isChecked());
806 void DolphinMainWindow::replaceLocation()
808 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
809 navigator
->setUrlEditable(true);
810 navigator
->setFocus();
812 // select the whole text of the combo box editor
813 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit(); // krazy:exclude=qclasses
814 const QString text
= lineEdit
->text();
815 lineEdit
->setSelection(0, text
.length());
818 void DolphinMainWindow::goBack()
822 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
823 urlNavigator
->goBack();
825 if (urlNavigator
->locationState().isEmpty()) {
826 // An empty location state indicates a redirection URL,
827 // which must be skipped too
828 urlNavigator
->goBack();
832 void DolphinMainWindow::goForward()
835 m_activeViewContainer
->urlNavigator()->goForward();
838 void DolphinMainWindow::goUp()
841 m_activeViewContainer
->urlNavigator()->goUp();
844 void DolphinMainWindow::goBack(Qt::MouseButtons buttons
)
846 // The default case (left button pressed) is handled in goBack().
847 if (buttons
== Qt::MidButton
) {
848 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
849 const int index
= urlNavigator
->historyIndex() + 1;
850 openNewTab(urlNavigator
->locationUrl(index
));
854 void DolphinMainWindow::goForward(Qt::MouseButtons buttons
)
856 // The default case (left button pressed) is handled in goForward().
857 if (buttons
== Qt::MidButton
) {
858 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
859 const int index
= urlNavigator
->historyIndex() - 1;
860 openNewTab(urlNavigator
->locationUrl(index
));
864 void DolphinMainWindow::goUp(Qt::MouseButtons buttons
)
866 // The default case (left button pressed) is handled in goUp().
867 if (buttons
== Qt::MidButton
) {
868 openNewTab(activeViewContainer()->url().upUrl());
872 void DolphinMainWindow::goHome()
875 m_activeViewContainer
->urlNavigator()->goHome();
878 void DolphinMainWindow::compareFiles()
880 // The method is only invoked if exactly 2 files have
881 // been selected. The selected files may be:
882 // - both in the primary view
883 // - both in the secondary view
884 // - one in the primary view and the other in the secondary
886 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
890 KUrl::List urls
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedUrls();
892 switch (urls
.count()) {
894 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
!= 0);
895 urls
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedUrls();
896 Q_ASSERT(urls
.count() == 2);
904 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
!= 0);
905 urls
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedUrls();
906 Q_ASSERT(urls
.count() == 1);
918 // may not happen: compareFiles may only get invoked if 2
919 // files are selected
924 QString
command("kompare -c \"");
925 command
.append(urlA
.pathOrUrl());
926 command
.append("\" \"");
927 command
.append(urlB
.pathOrUrl());
928 command
.append('\"');
929 KRun::runCommand(command
, "Kompare", "kompare", this);
932 void DolphinMainWindow::toggleShowMenuBar()
934 const bool visible
= menuBar()->isVisible();
935 menuBar()->setVisible(!visible
);
938 void DolphinMainWindow::openTerminal()
940 QString
dir(QDir::homePath());
942 // If the given directory is not local, it can still be the URL of an
943 // ioslave using UDS_LOCAL_PATH which to be converted first.
944 KUrl url
= KIO::NetAccess::mostLocalUrl(m_activeViewContainer
->url(), this);
946 //If the URL is local after the above conversion, set the directory.
947 if (url
.isLocalFile()) {
948 dir
= url
.toLocalFile();
951 KToolInvocation::invokeTerminal(QString(), dir
);
954 void DolphinMainWindow::editSettings()
956 if (m_settingsDialog
== 0) {
957 const KUrl
& url
= activeViewContainer()->url();
958 m_settingsDialog
= new DolphinSettingsDialog(url
, this);
959 m_settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
960 m_settingsDialog
->show();
962 m_settingsDialog
->raise();
966 void DolphinMainWindow::setActiveTab(int index
)
968 Q_ASSERT(index
>= 0);
969 Q_ASSERT(index
< m_viewTab
.count());
970 if (index
== m_tabIndex
) {
974 // hide current tab content
975 ViewTab
& hiddenTab
= m_viewTab
[m_tabIndex
];
976 hiddenTab
.isPrimaryViewActive
= hiddenTab
.primaryView
->isActive();
977 hiddenTab
.primaryView
->setActive(false);
978 if (hiddenTab
.secondaryView
!= 0) {
979 hiddenTab
.secondaryView
->setActive(false);
981 QSplitter
* splitter
= m_viewTab
[m_tabIndex
].splitter
;
983 m_centralWidgetLayout
->removeWidget(splitter
);
985 // show active tab content
988 ViewTab
& viewTab
= m_viewTab
[index
];
989 m_centralWidgetLayout
->addWidget(viewTab
.splitter
, 1);
990 viewTab
.primaryView
->show();
991 if (viewTab
.secondaryView
!= 0) {
992 viewTab
.secondaryView
->show();
994 viewTab
.splitter
->show();
996 setActiveViewContainer(viewTab
.isPrimaryViewActive
? viewTab
.primaryView
:
997 viewTab
.secondaryView
);
1000 void DolphinMainWindow::closeTab()
1002 closeTab(m_tabBar
->currentIndex());
1005 void DolphinMainWindow::closeTab(int index
)
1007 Q_ASSERT(index
>= 0);
1008 Q_ASSERT(index
< m_viewTab
.count());
1009 if (m_viewTab
.count() == 1) {
1010 // the last tab may never get closed
1014 if (index
== m_tabIndex
) {
1015 // The tab that should be closed is the active tab. Activate the
1016 // previous tab before closing the tab.
1017 m_tabBar
->setCurrentIndex((index
> 0) ? index
- 1 : 1);
1019 rememberClosedTab(index
);
1022 m_viewTab
[index
].primaryView
->deleteLater();
1023 if (m_viewTab
[index
].secondaryView
!= 0) {
1024 m_viewTab
[index
].secondaryView
->deleteLater();
1026 m_viewTab
[index
].splitter
->deleteLater();
1027 m_viewTab
.erase(m_viewTab
.begin() + index
);
1029 m_tabBar
->blockSignals(true);
1030 m_tabBar
->removeTab(index
);
1032 if (m_tabIndex
> index
) {
1034 Q_ASSERT(m_tabIndex
>= 0);
1037 // if only one tab is left, also remove the tab entry so that
1038 // closing the last tab is not possible
1039 if (m_viewTab
.count() == 1) {
1040 m_tabBar
->removeTab(0);
1041 actionCollection()->action("close_tab")->setEnabled(false);
1043 m_tabBar
->blockSignals(false);
1047 void DolphinMainWindow::openTabContextMenu(int index
, const QPoint
& pos
)
1051 QAction
* newTabAction
= menu
.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab"));
1052 newTabAction
->setShortcut(actionCollection()->action("new_tab")->shortcut());
1054 QAction
* detachTabAction
= menu
.addAction(KIcon("tab-detach"), i18nc("@action:inmenu", "Detach Tab"));
1056 QAction
* closeOtherTabsAction
= menu
.addAction(KIcon("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs"));
1058 QAction
* closeTabAction
= menu
.addAction(KIcon("tab-close"), i18nc("@action:inmenu", "Close Tab"));
1059 closeTabAction
->setShortcut(actionCollection()->action("close_tab")->shortcut());
1060 QAction
* selectedAction
= menu
.exec(pos
);
1061 if (selectedAction
== newTabAction
) {
1062 const ViewTab
& tab
= m_viewTab
[index
];
1063 Q_ASSERT(tab
.primaryView
!= 0);
1064 const KUrl url
= (tab
.secondaryView
!= 0) && tab
.secondaryView
->isActive() ?
1065 tab
.secondaryView
->url() : tab
.primaryView
->url();
1067 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
1068 } else if (selectedAction
== detachTabAction
) {
1069 const ViewTab
& tab
= m_viewTab
[index
];
1070 Q_ASSERT(tab
.primaryView
!= 0);
1071 const KUrl primaryUrl
= tab
.primaryView
->url();
1072 DolphinMainWindow
* window
= DolphinApplication::app()->createMainWindow();
1073 window
->changeUrl(primaryUrl
);
1075 if (tab
.secondaryView
!= 0) {
1076 const KUrl secondaryUrl
= tab
.secondaryView
->url();
1077 window
->toggleSplitView();
1078 window
->m_viewTab
[0].secondaryView
->setUrl(secondaryUrl
);
1079 if (tab
.primaryView
->isActive()) {
1080 window
->m_viewTab
[0].primaryView
->setActive(true);
1082 window
->m_viewTab
[0].secondaryView
->setActive(true);
1087 } else if (selectedAction
== closeOtherTabsAction
) {
1088 const int count
= m_tabBar
->count();
1089 for (int i
= 0; i
< index
; ++i
) {
1092 for (int i
= index
+ 1; i
< count
; ++i
) {
1095 } else if (selectedAction
== closeTabAction
) {
1100 void DolphinMainWindow::slotTabMoved(int from
, int to
)
1102 m_viewTab
.move(from
, to
);
1103 m_tabIndex
= m_tabBar
->currentIndex();
1106 void DolphinMainWindow::handlePlacesClick(const KUrl
& url
, Qt::MouseButtons buttons
)
1108 if (buttons
& Qt::MidButton
) {
1110 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
1116 void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent
* event
, bool& canDecode
)
1118 canDecode
= KUrl::List::canDecode(event
->mimeData());
1121 void DolphinMainWindow::handleUrl(const KUrl
& url
)
1123 delete m_lastHandleUrlStatJob
;
1124 m_lastHandleUrlStatJob
= 0;
1126 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1127 activeViewContainer()->setUrl(url
);
1128 } else if (KProtocolManager::supportsListing(url
)) {
1129 // stat the URL to see if it is a dir or not
1130 m_lastHandleUrlStatJob
= KIO::stat(url
, KIO::HideProgressInfo
);
1131 connect(m_lastHandleUrlStatJob
, SIGNAL(result(KJob
*)),
1132 this, SLOT(slotHandleUrlStatFinished(KJob
*)));
1135 new KRun(url
, this);
1139 void DolphinMainWindow::slotHandleUrlStatFinished(KJob
* job
)
1141 m_lastHandleUrlStatJob
= 0;
1142 const KIO::UDSEntry entry
= static_cast<KIO::StatJob
*>(job
)->statResult();
1143 const KUrl url
= static_cast<KIO::StatJob
*>(job
)->url();
1144 if ( entry
.isDir() ) {
1145 activeViewContainer()->setUrl(url
);
1147 new KRun(url
, this);
1151 void DolphinMainWindow::tabDropEvent(int tab
, QDropEvent
* event
)
1153 const KUrl::List urls
= KUrl::List::fromMimeData(event
->mimeData());
1154 if (!urls
.isEmpty() && tab
!= -1) {
1155 const ViewTab
& viewTab
= m_viewTab
[tab
];
1156 const KUrl destPath
= viewTab
.isPrimaryViewActive
? viewTab
.primaryView
->url() : viewTab
.secondaryView
->url();
1157 DragAndDropHelper::instance().dropUrls(KFileItem(), destPath
, event
, m_tabBar
);
1161 void DolphinMainWindow::slotCaptionStatFinished(KJob
* job
)
1163 m_captionStatJob
= 0;
1164 const KIO::UDSEntry entry
= static_cast<KIO::StatJob
*>(job
)->statResult();
1165 const QString name
= entry
.stringValue(KIO::UDSEntry::UDS_DISPLAY_NAME
);
1169 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1171 newFileMenu()->setEnabled(isFolderWritable
);
1174 void DolphinMainWindow::openContextMenu(const KFileItem
& item
,
1176 const QList
<QAction
*>& customActions
)
1178 DolphinContextMenu
contextMenu(this, item
, url
);
1179 contextMenu
.setCustomActions(customActions
);
1183 void DolphinMainWindow::init()
1185 DolphinSettings
& settings
= DolphinSettings::instance();
1187 // Check whether Dolphin runs the first time. If yes then
1188 // a proper default window size is given at the end of DolphinMainWindow::init().
1189 GeneralSettings
* generalSettings
= settings
.generalSettings();
1190 const bool firstRun
= generalSettings
->firstRun();
1192 generalSettings
->setViewPropsTimestamp(QDateTime::currentDateTime());
1195 setAcceptDrops(true);
1197 m_viewTab
[m_tabIndex
].splitter
= new QSplitter(this);
1198 m_viewTab
[m_tabIndex
].splitter
->setChildrenCollapsible(false);
1202 const KUrl
& homeUrl
= generalSettings
->homeUrl();
1203 setUrlAsCaption(homeUrl
);
1204 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
1205 connect(m_actionHandler
, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
1206 connect(m_actionHandler
, SIGNAL(createDirectory()), SLOT(createDirectory()));
1207 ViewProperties
props(homeUrl
);
1208 m_viewTab
[m_tabIndex
].primaryView
= new DolphinViewContainer(homeUrl
,
1209 m_viewTab
[m_tabIndex
].splitter
);
1211 m_activeViewContainer
= m_viewTab
[m_tabIndex
].primaryView
;
1212 connectViewSignals(m_activeViewContainer
);
1213 DolphinView
* view
= m_activeViewContainer
->view();
1215 m_activeViewContainer
->show();
1216 m_actionHandler
->setCurrentView(view
);
1218 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
1219 connect(this, SIGNAL(urlChanged(const KUrl
&)),
1220 m_remoteEncoding
, SLOT(slotAboutToOpenUrl()));
1222 m_tabBar
= new KTabBar(this);
1223 m_tabBar
->setMovable(true);
1224 m_tabBar
->setTabsClosable(true);
1225 connect(m_tabBar
, SIGNAL(currentChanged(int)),
1226 this, SLOT(setActiveTab(int)));
1227 connect(m_tabBar
, SIGNAL(tabCloseRequested(int)),
1228 this, SLOT(closeTab(int)));
1229 connect(m_tabBar
, SIGNAL(contextMenu(int, const QPoint
&)),
1230 this, SLOT(openTabContextMenu(int, const QPoint
&)));
1231 connect(m_tabBar
, SIGNAL(newTabRequest()),
1232 this, SLOT(openNewTab()));
1233 connect(m_tabBar
, SIGNAL(testCanDecode(const QDragMoveEvent
*, bool&)),
1234 this, SLOT(slotTestCanDecode(const QDragMoveEvent
*, bool&)));
1235 connect(m_tabBar
, SIGNAL(mouseMiddleClick(int)),
1236 this, SLOT(closeTab(int)));
1237 connect(m_tabBar
, SIGNAL(tabMoved(int, int)),
1238 this, SLOT(slotTabMoved(int, int)));
1239 connect(m_tabBar
, SIGNAL(receivedDropEvent(int, QDropEvent
*)),
1240 this, SLOT(tabDropEvent(int, QDropEvent
*)));
1242 m_tabBar
->blockSignals(true); // signals get unblocked after at least 2 tabs are open
1244 QWidget
* centralWidget
= new QWidget(this);
1245 m_centralWidgetLayout
= new QVBoxLayout(centralWidget
);
1246 m_centralWidgetLayout
->setSpacing(0);
1247 m_centralWidgetLayout
->setMargin(0);
1248 m_centralWidgetLayout
->addWidget(m_tabBar
);
1249 m_centralWidgetLayout
->addWidget(m_viewTab
[m_tabIndex
].splitter
, 1);
1251 setCentralWidget(centralWidget
);
1253 emit
urlChanged(homeUrl
);
1255 setupGUI(Keys
| Save
| Create
| ToolBar
);
1256 stateChanged("new_file");
1258 QClipboard
* clipboard
= QApplication::clipboard();
1259 connect(clipboard
, SIGNAL(dataChanged()),
1260 this, SLOT(updatePasteAction()));
1262 if (generalSettings
->splitView()) {
1265 updateEditActions();
1266 updateViewActions();
1269 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1270 showFilterBarAction
->setChecked(generalSettings
->filterBar());
1273 // assure a proper default size if Dolphin runs the first time
1277 m_showMenuBar
->setChecked(!menuBar()->isHidden()); // workaround for bug #171080
1280 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer
* viewContainer
)
1282 Q_ASSERT(viewContainer
!= 0);
1283 Q_ASSERT((viewContainer
== m_viewTab
[m_tabIndex
].primaryView
) ||
1284 (viewContainer
== m_viewTab
[m_tabIndex
].secondaryView
));
1285 if (m_activeViewContainer
== viewContainer
) {
1289 m_activeViewContainer
->setActive(false);
1290 m_activeViewContainer
= viewContainer
;
1292 // Activating the view container might trigger a recursive setActiveViewContainer() call
1293 // inside DolphinMainWindow::toggleActiveView() when having a split view. Temporary
1294 // disconnect the activated() signal in this case:
1295 disconnect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1296 m_activeViewContainer
->setActive(true);
1297 connect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1299 m_actionHandler
->setCurrentView(viewContainer
->view());
1302 updateEditActions();
1303 updateViewActions();
1306 const KUrl
& url
= m_activeViewContainer
->url();
1307 setUrlAsCaption(url
);
1308 if (m_viewTab
.count() > 1 && m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
1309 m_tabBar
->setTabText(m_tabIndex
, tabName(url
));
1310 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(KMimeType::iconNameForUrl(url
)));
1313 emit
urlChanged(url
);
1316 void DolphinMainWindow::setupActions()
1318 // setup 'File' menu
1319 m_newFileMenu
= new DolphinNewFileMenu(this, this);
1320 KMenu
* menu
= m_newFileMenu
->menu();
1321 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1322 menu
->setIcon(KIcon("document-new"));
1323 connect(menu
, SIGNAL(aboutToShow()),
1324 this, SLOT(updateNewMenu()));
1326 KAction
* newWindow
= actionCollection()->addAction("new_window");
1327 newWindow
->setIcon(KIcon("window-new"));
1328 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1329 newWindow
->setShortcut(Qt::CTRL
| Qt::Key_N
);
1330 connect(newWindow
, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1332 KAction
* newTab
= actionCollection()->addAction("new_tab");
1333 newTab
->setIcon(KIcon("tab-new"));
1334 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1335 newTab
->setShortcut(KShortcut(Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
));
1336 connect(newTab
, SIGNAL(triggered()), this, SLOT(openNewTab()));
1338 KAction
* closeTab
= actionCollection()->addAction("close_tab");
1339 closeTab
->setIcon(KIcon("tab-close"));
1340 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1341 closeTab
->setShortcut(Qt::CTRL
| Qt::Key_W
);
1342 closeTab
->setEnabled(false);
1343 connect(closeTab
, SIGNAL(triggered()), this, SLOT(closeTab()));
1345 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1347 // setup 'Edit' menu
1348 KStandardAction::undo(this,
1350 actionCollection());
1352 // need to remove shift+del from cut action, else the shortcut for deletejob
1354 KAction
* cut
= KStandardAction::cut(this, SLOT(cut()), actionCollection());
1355 KShortcut cutShortcut
= cut
->shortcut();
1356 cutShortcut
.remove(Qt::SHIFT
+ Qt::Key_Delete
, KShortcut::KeepEmpty
);
1357 cut
->setShortcut(cutShortcut
);
1358 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1359 KAction
* paste
= KStandardAction::paste(this, SLOT(paste()), actionCollection());
1360 // The text of the paste-action is modified dynamically by Dolphin
1361 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1362 // due to the long text, the text "Paste" is used:
1363 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1365 KStandardAction::find(this, SLOT(find()), actionCollection());
1367 KAction
* selectAll
= actionCollection()->addAction("select_all");
1368 selectAll
->setText(i18nc("@action:inmenu Edit", "Select All"));
1369 selectAll
->setShortcut(Qt::CTRL
+ Qt::Key_A
);
1370 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
1372 KAction
* invertSelection
= actionCollection()->addAction("invert_selection");
1373 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1374 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1375 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
1377 // setup 'View' menu
1378 // (note that most of it is set up in DolphinViewActionHandler)
1380 KAction
* split
= actionCollection()->addAction("split_view");
1381 split
->setShortcut(Qt::Key_F3
);
1382 updateSplitAction();
1383 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1385 KAction
* reload
= actionCollection()->addAction("reload");
1386 reload
->setText(i18nc("@action:inmenu View", "Reload"));
1387 reload
->setShortcut(Qt::Key_F5
);
1388 reload
->setIcon(KIcon("view-refresh"));
1389 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
1391 KAction
* stop
= actionCollection()->addAction("stop");
1392 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1393 stop
->setToolTip(i18nc("@info", "Stop loading"));
1394 stop
->setIcon(KIcon("process-stop"));
1395 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
1397 KToggleAction
* showFullLocation
= actionCollection()->add
<KToggleAction
>("editable_location");
1398 showFullLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1399 showFullLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
1400 connect(showFullLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1402 KAction
* replaceLocation
= actionCollection()->addAction("replace_location");
1403 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1404 replaceLocation
->setShortcut(Qt::Key_F6
);
1405 connect(replaceLocation
, SIGNAL(triggered()), this, SLOT(replaceLocation()));
1408 KAction
* backAction
= KStandardAction::back(this, SLOT(goBack()), actionCollection());
1409 connect(backAction
, SIGNAL(triggered(Qt::MouseButtons
, Qt::KeyboardModifiers
)), this, SLOT(goBack(Qt::MouseButtons
)));
1410 KShortcut backShortcut
= backAction
->shortcut();
1411 backShortcut
.setAlternate(Qt::Key_Backspace
);
1412 backAction
->setShortcut(backShortcut
);
1414 m_recentTabsMenu
= new KActionMenu(i18n("Recently Closed Tabs"), this);
1415 m_recentTabsMenu
->setIcon(KIcon("edit-undo"));
1416 actionCollection()->addAction("closed_tabs", m_recentTabsMenu
);
1417 connect(m_recentTabsMenu
->menu(), SIGNAL(triggered(QAction
*)),
1418 this, SLOT(restoreClosedTab(QAction
*)));
1420 QAction
* action
= new QAction("Empty Recently Closed Tabs", m_recentTabsMenu
);
1421 action
->setIcon(KIcon("edit-clear-list"));
1422 action
->setData(QVariant::fromValue(true));
1423 m_recentTabsMenu
->addAction(action
);
1424 m_recentTabsMenu
->addSeparator();
1425 m_recentTabsMenu
->setEnabled(false);
1427 KAction
* forwardAction
= KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1428 connect(forwardAction
, SIGNAL(triggered(Qt::MouseButtons
, Qt::KeyboardModifiers
)), this, SLOT(goForward(Qt::MouseButtons
)));
1430 KAction
* upAction
= KStandardAction::up(this, SLOT(goUp()), actionCollection());
1431 connect(upAction
, SIGNAL(triggered(Qt::MouseButtons
, Qt::KeyboardModifiers
)), this, SLOT(goUp(Qt::MouseButtons
)));
1433 KStandardAction::home(this, SLOT(goHome()), actionCollection());
1435 // setup 'Tools' menu
1436 KToggleAction
* showFilterBar
= actionCollection()->add
<KToggleAction
>("show_filter_bar");
1437 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1438 showFilterBar
->setIcon(KIcon("view-filter"));
1439 showFilterBar
->setShortcut(Qt::CTRL
| Qt::Key_I
);
1440 connect(showFilterBar
, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
1442 KAction
* compareFiles
= actionCollection()->addAction("compare_files");
1443 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1444 compareFiles
->setIcon(KIcon("kompare"));
1445 compareFiles
->setEnabled(false);
1446 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
1448 KAction
* openTerminal
= actionCollection()->addAction("open_terminal");
1449 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1450 openTerminal
->setIcon(KIcon("utilities-terminal"));
1451 openTerminal
->setShortcut(Qt::SHIFT
| Qt::Key_F4
);
1452 connect(openTerminal
, SIGNAL(triggered()), this, SLOT(openTerminal()));
1454 // setup 'Settings' menu
1455 m_showMenuBar
= KStandardAction::showMenubar(this, SLOT(toggleShowMenuBar()), actionCollection());
1456 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1458 // not in menu actions
1459 QList
<QKeySequence
> nextTabKeys
;
1460 nextTabKeys
.append(KStandardShortcut::tabNext().primary());
1461 nextTabKeys
.append(QKeySequence(Qt::CTRL
+ Qt::Key_Tab
));
1463 QList
<QKeySequence
> prevTabKeys
;
1464 prevTabKeys
.append(KStandardShortcut::tabPrev().primary());
1465 prevTabKeys
.append(QKeySequence(Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_Tab
));
1467 KAction
* activateNextTab
= actionCollection()->addAction("activate_next_tab");
1468 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1469 connect(activateNextTab
, SIGNAL(triggered()), SLOT(activateNextTab()));
1470 activateNextTab
->setShortcuts(QApplication::isRightToLeft() ? prevTabKeys
: nextTabKeys
);
1472 KAction
* activatePrevTab
= actionCollection()->addAction("activate_prev_tab");
1473 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1474 connect(activatePrevTab
, SIGNAL(triggered()), SLOT(activatePrevTab()));
1475 activatePrevTab
->setShortcuts(QApplication::isRightToLeft() ? nextTabKeys
: prevTabKeys
);
1478 KAction
* openInNewTab
= actionCollection()->addAction("open_in_new_tab");
1479 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1480 openInNewTab
->setIcon(KIcon("tab-new"));
1481 connect(openInNewTab
, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1483 KAction
* openInNewWindow
= actionCollection()->addAction("open_in_new_window");
1484 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1485 openInNewWindow
->setIcon(KIcon("window-new"));
1486 connect(openInNewWindow
, SIGNAL(triggered()), this, SLOT(openInNewWindow()));
1489 void DolphinMainWindow::setupDockWidgets()
1491 // setup "Information"
1492 QDockWidget
* infoDock
= new QDockWidget(i18nc("@title:window", "Information"));
1493 infoDock
->setObjectName("infoDock");
1494 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1495 Panel
* infoPanel
= new InformationPanel(infoDock
);
1496 connect(infoPanel
, SIGNAL(urlActivated(KUrl
)), this, SLOT(handleUrl(KUrl
)));
1497 infoDock
->setWidget(infoPanel
);
1499 QAction
* infoAction
= infoDock
->toggleViewAction();
1500 infoAction
->setIcon(KIcon("dialog-information"));
1501 infoAction
->setShortcut(Qt::Key_F11
);
1503 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1504 connect(this, SIGNAL(urlChanged(KUrl
)),
1505 infoPanel
, SLOT(setUrl(KUrl
)));
1506 connect(this, SIGNAL(selectionChanged(KFileItemList
)),
1507 infoPanel
, SLOT(setSelection(KFileItemList
)));
1508 connect(this, SIGNAL(requestItemInfo(KFileItem
)),
1509 infoPanel
, SLOT(requestDelayedItemInfo(KFileItem
)));
1512 QDockWidget
* foldersDock
= new QDockWidget(i18nc("@title:window", "Folders"));
1513 foldersDock
->setObjectName("foldersDock");
1514 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1515 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1516 foldersDock
->setWidget(foldersPanel
);
1518 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1519 foldersAction
->setShortcut(Qt::Key_F7
);
1520 foldersAction
->setIcon(KIcon("folder"));
1522 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1523 connect(this, SIGNAL(urlChanged(KUrl
)),
1524 foldersPanel
, SLOT(setUrl(KUrl
)));
1525 connect(foldersPanel
, SIGNAL(changeUrl(KUrl
, Qt::MouseButtons
)),
1526 this, SLOT(handlePlacesClick(KUrl
, Qt::MouseButtons
)));
1530 QDockWidget
* terminalDock
= new QDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1531 terminalDock
->setObjectName("terminalDock");
1532 terminalDock
->setAllowedAreas(Qt::TopDockWidgetArea
| Qt::BottomDockWidgetArea
);
1533 Panel
* terminalPanel
= new TerminalPanel(terminalDock
);
1534 terminalDock
->setWidget(terminalPanel
);
1536 connect(terminalPanel
, SIGNAL(hideTerminalPanel()), terminalDock
, SLOT(hide()));
1538 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1539 terminalAction
->setShortcut(Qt::Key_F4
);
1540 terminalAction
->setIcon(KIcon("utilities-terminal"));
1542 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1543 connect(this, SIGNAL(urlChanged(KUrl
)),
1544 terminalPanel
, SLOT(setUrl(KUrl
)));
1547 const bool firstRun
= DolphinSettings::instance().generalSettings()->firstRun();
1550 foldersDock
->hide();
1552 terminalDock
->hide();
1557 QDockWidget
* placesDock
= new QDockWidget(i18nc("@title:window", "Places"));
1558 placesDock
->setObjectName("placesDock");
1559 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1561 PlacesPanel
* placesPanel
= new PlacesPanel(placesDock
);
1562 placesDock
->setWidget(placesPanel
);
1563 placesPanel
->setModel(DolphinSettings::instance().placesModel());
1564 placesPanel
->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff
);
1566 QAction
* placesAction
= placesDock
->toggleViewAction();
1567 placesAction
->setShortcut(Qt::Key_F9
);
1568 placesAction
->setIcon(KIcon("bookmarks"));
1570 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1571 connect(placesPanel
, SIGNAL(urlChanged(KUrl
, Qt::MouseButtons
)),
1572 this, SLOT(handlePlacesClick(KUrl
, Qt::MouseButtons
)));
1573 connect(this, SIGNAL(urlChanged(KUrl
)),
1574 placesPanel
, SLOT(setUrl(KUrl
)));
1576 KActionMenu
* panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Panels"), this);
1577 actionCollection()->addAction("panels", panelsMenu
);
1578 panelsMenu
->setDelayed(false);
1579 panelsMenu
->addAction(placesAction
);
1580 panelsMenu
->addAction(infoAction
);
1581 panelsMenu
->addAction(foldersAction
);
1583 panelsMenu
->addAction(terminalAction
);
1587 void DolphinMainWindow::updateEditActions()
1589 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1590 if (list
.isEmpty()) {
1591 stateChanged("has_no_selection");
1593 stateChanged("has_selection");
1595 KActionCollection
* col
= actionCollection();
1596 QAction
* renameAction
= col
->action("rename");
1597 QAction
* moveToTrashAction
= col
->action("move_to_trash");
1598 QAction
* deleteAction
= col
->action("delete");
1599 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
1600 QAction
* deleteWithTrashShortcut
= col
->action("delete_shortcut"); // see DolphinViewActionHandler
1602 KFileItemListProperties
capabilities(list
);
1603 const bool enableMoveToTrash
= capabilities
.isLocal() && capabilities
.supportsMoving();
1605 renameAction
->setEnabled(capabilities
.supportsMoving());
1606 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1607 deleteAction
->setEnabled(capabilities
.supportsDeleting());
1608 deleteWithTrashShortcut
->setEnabled(capabilities
.supportsDeleting() && !enableMoveToTrash
);
1609 cutAction
->setEnabled(capabilities
.supportsMoving());
1611 updatePasteAction();
1614 void DolphinMainWindow::updateViewActions()
1616 m_actionHandler
->updateViewActions();
1618 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1619 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
1621 updateSplitAction();
1623 QAction
* editableLocactionAction
= actionCollection()->action("editable_location");
1624 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
1625 editableLocactionAction
->setChecked(urlNavigator
->isUrlEditable());
1628 void DolphinMainWindow::updateGoActions()
1630 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
1631 const KUrl
& currentUrl
= m_activeViewContainer
->url();
1632 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
1635 void DolphinMainWindow::rememberClosedTab(int index
)
1637 KMenu
* tabsMenu
= m_recentTabsMenu
->menu();
1639 const QString primaryPath
= m_viewTab
[index
].primaryView
->url().path();
1640 const QString iconName
= KMimeType::iconNameForUrl(primaryPath
);
1642 QAction
* action
= new QAction(squeezedText(primaryPath
), tabsMenu
);
1644 ClosedTab closedTab
;
1645 closedTab
.primaryUrl
= m_viewTab
[index
].primaryView
->url();
1647 if (m_viewTab
[index
].secondaryView
!= 0) {
1648 closedTab
.secondaryUrl
= m_viewTab
[index
].secondaryView
->url();
1649 closedTab
.isSplit
= true;
1651 closedTab
.isSplit
= false;
1654 action
->setData(QVariant::fromValue(closedTab
));
1655 action
->setIcon(KIcon(iconName
));
1657 // add the closed tab menu entry after the separator and
1658 // "Empty Recently Closed Tabs" entry
1659 if (tabsMenu
->actions().size() == 2) {
1660 tabsMenu
->addAction(action
);
1662 tabsMenu
->insertAction(tabsMenu
->actions().at(2), action
);
1665 // assure that only up to 8 closed tabs are shown in the menu
1666 if (tabsMenu
->actions().size() > 8) {
1667 tabsMenu
->removeAction(tabsMenu
->actions().last());
1669 actionCollection()->action("closed_tabs")->setEnabled(true);
1670 KAcceleratorManager::manage(tabsMenu
);
1673 void DolphinMainWindow::clearStatusBar()
1675 m_activeViewContainer
->statusBar()->clear();
1678 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
1680 connect(container
, SIGNAL(showFilterBarChanged(bool)),
1681 this, SLOT(updateFilterBarAction(bool)));
1682 connect(container
, SIGNAL(writeStateChanged(bool)),
1683 this, SLOT(slotWriteStateChanged(bool)));
1685 DolphinView
* view
= container
->view();
1686 connect(view
, SIGNAL(selectionChanged(KFileItemList
)),
1687 this, SLOT(slotSelectionChanged(KFileItemList
)));
1688 connect(view
, SIGNAL(requestItemInfo(KFileItem
)),
1689 this, SLOT(slotRequestItemInfo(KFileItem
)));
1690 connect(view
, SIGNAL(activated()),
1691 this, SLOT(toggleActiveView()));
1692 connect(view
, SIGNAL(tabRequested(const KUrl
&)),
1693 this, SLOT(openNewTab(const KUrl
&)));
1694 connect(view
, SIGNAL(requestContextMenu(KFileItem
, const KUrl
&, const QList
<QAction
*>&)),
1695 this, SLOT(openContextMenu(KFileItem
, const KUrl
&, const QList
<QAction
*>&)));
1697 const KUrlNavigator
* navigator
= container
->urlNavigator();
1698 connect(navigator
, SIGNAL(urlChanged(const KUrl
&)),
1699 this, SLOT(changeUrl(const KUrl
&)));
1700 connect(navigator
, SIGNAL(historyChanged()),
1701 this, SLOT(updateHistory()));
1702 connect(navigator
, SIGNAL(editableStateChanged(bool)),
1703 this, SLOT(slotEditableStateChanged(bool)));
1704 connect(navigator
, SIGNAL(tabRequested(const KUrl
&)),
1705 this, SLOT(openNewTab(KUrl
)));
1708 void DolphinMainWindow::updateSplitAction()
1710 QAction
* splitAction
= actionCollection()->action("split_view");
1711 if (m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
1712 if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
1713 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
1714 splitAction
->setToolTip(i18nc("@info", "Close right view"));
1715 splitAction
->setIcon(KIcon("view-right-close"));
1717 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
1718 splitAction
->setToolTip(i18nc("@info", "Close left view"));
1719 splitAction
->setIcon(KIcon("view-left-close"));
1722 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
1723 splitAction
->setToolTip(i18nc("@info", "Split view"));
1724 splitAction
->setIcon(KIcon("view-right-new"));
1728 QString
DolphinMainWindow::tabName(const KUrl
& url
) const
1731 if (url
.equals(KUrl("file:///"))) {
1734 name
= url
.fileName();
1735 if (name
.isEmpty()) {
1736 name
= url
.protocol();
1738 // Make sure that a '&' inside the directory name is displayed correctly
1739 // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
1740 name
.replace('&', "&&");
1746 bool DolphinMainWindow::isKompareInstalled() const
1748 static bool initialized
= false;
1749 static bool installed
= false;
1751 // TODO: maybe replace this approach later by using a menu
1752 // plugin like kdiff3plugin.cpp
1753 installed
= !KGlobal::dirs()->findExe("kompare").isEmpty();
1759 void DolphinMainWindow::createSecondaryView(int tabIndex
)
1761 QSplitter
* splitter
= m_viewTab
[tabIndex
].splitter
;
1762 const int newWidth
= (m_viewTab
[tabIndex
].primaryView
->width() - splitter
->handleWidth()) / 2;
1764 const DolphinView
* view
= m_viewTab
[tabIndex
].primaryView
->view();
1765 m_viewTab
[tabIndex
].secondaryView
= new DolphinViewContainer(view
->rootUrl(), 0);
1766 splitter
->addWidget(m_viewTab
[tabIndex
].secondaryView
);
1767 splitter
->setSizes(QList
<int>() << newWidth
<< newWidth
);
1768 connectViewSignals(m_viewTab
[tabIndex
].secondaryView
);
1769 m_viewTab
[tabIndex
].secondaryView
->view()->reload();
1770 m_viewTab
[tabIndex
].secondaryView
->setActive(false);
1771 m_viewTab
[tabIndex
].secondaryView
->show();
1774 QString
DolphinMainWindow::tabProperty(const QString
& property
, int tabIndex
) const
1776 return "Tab " + QString::number(tabIndex
) + ' ' + property
;
1779 void DolphinMainWindow::setUrlAsCaption(const KUrl
& url
)
1781 delete m_captionStatJob
;
1782 m_captionStatJob
= 0;
1784 if (url
.protocol() == QLatin1String("file")) {
1786 if (url
.equals(KUrl("file:///"))) {
1789 caption
= url
.fileName();
1790 if (caption
.isEmpty()) {
1791 caption
= url
.protocol();
1795 setCaption(caption
);
1797 m_captionStatJob
= KIO::stat(url
, KIO::HideProgressInfo
);
1798 connect(m_captionStatJob
, SIGNAL(result(KJob
*)),
1799 this, SLOT(slotCaptionStatFinished(KJob
*)));
1803 QString
DolphinMainWindow::squeezedText(const QString
& text
) const
1805 const QFontMetrics fm
= fontMetrics();
1806 return fm
.elidedText(text
, Qt::ElideMiddle
, fm
.maxWidth() * 10);
1809 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
1810 KIO::FileUndoManager::UiInterface()
1814 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
1818 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
1820 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
1822 DolphinStatusBar
* statusBar
= mainWin
->activeViewContainer()->statusBar();
1823 statusBar
->setMessage(job
->errorString(), DolphinStatusBar::Error
);
1825 KIO::FileUndoManager::UiInterface::jobError(job
);
1829 #include "dolphinmainwindow.moc"