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),
117 m_lastHandleUrlStatJob(0)
119 // Workaround for a X11-issue in combination with KModifierInfo
120 // (see DolphinContextMenu::initializeModifierKeyInfo() for
121 // more information):
122 DolphinContextMenu::initializeModifierKeyInfo();
124 setObjectName("Dolphin#");
126 m_viewTab
.append(ViewTab());
128 new MainWindowAdaptor(this);
129 QDBusConnection::sessionBus().registerObject(QString("/dolphin/MainWindow%1").arg(m_id
), this);
131 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
132 undoManager
->setUiInterface(new UndoUiInterface());
134 connect(undoManager
, SIGNAL(undoAvailable(bool)),
135 this, SLOT(slotUndoAvailable(bool)));
136 connect(undoManager
, SIGNAL(undoTextChanged(const QString
&)),
137 this, SLOT(slotUndoTextChanged(const QString
&)));
138 connect(undoManager
, SIGNAL(jobRecordingStarted(CommandType
)),
139 this, SLOT(clearStatusBar()));
140 connect(undoManager
, SIGNAL(jobRecordingFinished(CommandType
)),
141 this, SLOT(showCommand(CommandType
)));
142 connect(DolphinSettings::instance().placesModel(), SIGNAL(errorMessage(const QString
&)),
143 this, SLOT(showErrorMessage(const QString
&)));
144 connect(&DragAndDropHelper::instance(), SIGNAL(errorMessage(const QString
&)),
145 this, SLOT(showErrorMessage(const QString
&)));
148 DolphinMainWindow::~DolphinMainWindow()
150 DolphinApplication::app()->removeMainWindow(this);
153 void DolphinMainWindow::openDirectories(const QList
<KUrl
>& dirs
)
155 if (dirs
.isEmpty()) {
159 const int oldOpenTabsCount
= m_viewTab
.count();
161 const GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
162 const bool hasSplitView
= generalSettings
->splitView();
164 // Open each directory inside a new tab. If the "split view" option has been enabled,
165 // always show two directories within one tab.
166 QList
<KUrl
>::const_iterator it
= dirs
.begin();
167 while (it
!= dirs
.end()) {
171 if (hasSplitView
&& (it
!= dirs
.end())) {
172 const int tabIndex
= m_viewTab
.count() - 1;
173 m_viewTab
[tabIndex
].secondaryView
->setUrl(*it
);
178 // remove the previously opened tabs
179 for (int i
= 0; i
< oldOpenTabsCount
; ++i
) {
184 void DolphinMainWindow::openFiles(const QList
<KUrl
>& files
)
186 if (files
.isEmpty()) {
190 // Get all distinct directories from 'files' and open a tab
191 // for each directory. If the "split view" option is enabled, two
192 // directories are shown inside one tab (see openDirectories()).
194 foreach (const KUrl
& url
, files
) {
195 const KUrl
dir(url
.directory());
196 if (!dirs
.contains(dir
)) {
201 openDirectories(dirs
);
203 // Select the files. Although the files can be split between several
204 // tabs, there is no need to split 'files' accordingly, as
205 // the DolphinView will just ignore invalid selections.
206 const int tabCount
= m_viewTab
.count();
207 for (int i
= 0; i
< tabCount
; ++i
) {
208 m_viewTab
[i
].primaryView
->view()->markUrlsAsSelected(files
);
209 if (m_viewTab
[i
].secondaryView
!= 0) {
210 m_viewTab
[i
].secondaryView
->view()->markUrlsAsSelected(files
);
215 void DolphinMainWindow::toggleViews()
217 if (m_viewTab
[m_tabIndex
].primaryView
== 0) {
221 // move secondary view from the last position of the splitter
222 // to the first position
223 m_viewTab
[m_tabIndex
].splitter
->insertWidget(0, m_viewTab
[m_tabIndex
].secondaryView
);
225 DolphinViewContainer
* container
= m_viewTab
[m_tabIndex
].primaryView
;
226 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
227 m_viewTab
[m_tabIndex
].secondaryView
= container
;
230 void DolphinMainWindow::showCommand(CommandType command
)
232 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
234 case KIO::FileUndoManager::Copy
:
235 statusBar
->setMessage(i18nc("@info:status", "Successfully copied."),
236 DolphinStatusBar::OperationCompleted
);
238 case KIO::FileUndoManager::Move
:
239 statusBar
->setMessage(i18nc("@info:status", "Successfully moved."),
240 DolphinStatusBar::OperationCompleted
);
242 case KIO::FileUndoManager::Link
:
243 statusBar
->setMessage(i18nc("@info:status", "Successfully linked."),
244 DolphinStatusBar::OperationCompleted
);
246 case KIO::FileUndoManager::Trash
:
247 statusBar
->setMessage(i18nc("@info:status", "Successfully moved to trash."),
248 DolphinStatusBar::OperationCompleted
);
250 case KIO::FileUndoManager::Rename
:
251 statusBar
->setMessage(i18nc("@info:status", "Successfully renamed."),
252 DolphinStatusBar::OperationCompleted
);
255 case KIO::FileUndoManager::Mkdir
:
256 statusBar
->setMessage(i18nc("@info:status", "Created folder."),
257 DolphinStatusBar::OperationCompleted
);
265 void DolphinMainWindow::refreshViews()
267 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
269 // remember the current active view, as because of
270 // the refreshing the active view might change to
271 // the secondary view
272 DolphinViewContainer
* activeViewContainer
= m_activeViewContainer
;
274 const int tabCount
= m_viewTab
.count();
275 for (int i
= 0; i
< tabCount
; ++i
) {
276 m_viewTab
[i
].primaryView
->refresh();
277 if (m_viewTab
[i
].secondaryView
!= 0) {
278 m_viewTab
[i
].secondaryView
->refresh();
282 setActiveViewContainer(activeViewContainer
);
285 void DolphinMainWindow::pasteIntoFolder()
287 m_activeViewContainer
->view()->pasteIntoFolder();
290 void DolphinMainWindow::changeUrl(const KUrl
& url
)
292 if (!KProtocolManager::supportsListing(url
)) {
293 // The URL navigator only checks for validity, not
294 // if the URL can be listed. An error message is
295 // shown due to DolphinViewContainer::restoreView().
299 DolphinViewContainer
* view
= activeViewContainer();
305 setUrlAsCaption(url
);
306 if (m_viewTab
.count() > 1) {
307 m_tabBar
->setTabText(m_tabIndex
, squeezedText(tabName(m_activeViewContainer
->url())));
309 const QString iconName
= KMimeType::iconNameForUrl(url
);
310 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(iconName
));
311 emit
urlChanged(url
);
315 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
317 KToggleAction
* editableLocationAction
=
318 static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
319 editableLocationAction
->setChecked(editable
);
322 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
326 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
327 int selectedUrlsCount
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedItemsCount();
328 if (m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
329 selectedUrlsCount
+= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItemsCount();
332 QAction
* compareFilesAction
= actionCollection()->action("compare_files");
333 if (selectedUrlsCount
== 2) {
334 compareFilesAction
->setEnabled(isKompareInstalled());
336 compareFilesAction
->setEnabled(false);
339 emit
selectionChanged(selection
);
342 void DolphinMainWindow::slotRequestItemInfo(const KFileItem
& item
)
344 emit
requestItemInfo(item
);
347 void DolphinMainWindow::updateHistory()
349 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
350 const int index
= urlNavigator
->historyIndex();
352 QAction
* backAction
= actionCollection()->action("go_back");
353 backAction
->setToolTip(i18nc("@info", "Go back"));
354 if (backAction
!= 0) {
355 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
358 QAction
* forwardAction
= actionCollection()->action("go_forward");
359 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
360 if (forwardAction
!= 0) {
361 forwardAction
->setEnabled(index
> 0);
365 void DolphinMainWindow::updateFilterBarAction(bool show
)
367 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
368 showFilterBarAction
->setChecked(show
);
371 void DolphinMainWindow::openNewMainWindow()
373 DolphinApplication::app()->createMainWindow()->show();
376 void DolphinMainWindow::openNewTab()
378 const bool isUrlEditable
= m_activeViewContainer
->urlNavigator()->isUrlEditable();
380 openNewTab(m_activeViewContainer
->url());
381 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
383 // The URL navigator of the new tab should have the same editable state
384 // as the current tab
385 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
386 navigator
->setUrlEditable(isUrlEditable
);
389 // If a new tab is opened and the URL is editable, assure that
390 // the user can edit the URL without manually setting the focus
391 navigator
->setFocus();
395 void DolphinMainWindow::openNewTab(const KUrl
& url
)
397 QWidget
* focusWidget
= QApplication::focusWidget();
399 if (m_viewTab
.count() == 1) {
400 // Only one view is open currently and hence no tab is shown at
401 // all. Before creating a tab for 'url', provide a tab for the current URL.
402 const KUrl currentUrl
= m_activeViewContainer
->url();
403 m_tabBar
->addTab(KIcon(KMimeType::iconNameForUrl(currentUrl
)),
404 squeezedText(tabName(currentUrl
)));
405 m_tabBar
->blockSignals(false);
408 m_tabBar
->addTab(KIcon(KMimeType::iconNameForUrl(url
)),
409 squeezedText(tabName(url
)));
412 viewTab
.splitter
= new QSplitter(this);
413 viewTab
.splitter
->setChildrenCollapsible(false);
414 viewTab
.primaryView
= new DolphinViewContainer(url
, viewTab
.splitter
);
415 viewTab
.primaryView
->setActive(false);
416 connectViewSignals(viewTab
.primaryView
);
417 viewTab
.primaryView
->view()->reload();
419 m_viewTab
.append(viewTab
);
421 actionCollection()->action("close_tab")->setEnabled(true);
423 // provide a split view, if the startup settings are set this way
424 const GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
425 if (generalSettings
->splitView()) {
426 const int tabIndex
= m_viewTab
.count() - 1;
427 createSecondaryView(tabIndex
);
428 m_viewTab
[tabIndex
].secondaryView
->setActive(true);
429 m_viewTab
[tabIndex
].isPrimaryViewActive
= false;
432 if (focusWidget
!= 0) {
433 // The DolphinViewContainer grabbed the keyboard focus. As the tab is opened
434 // in background, assure that the previous focused widget gets the focus back.
435 focusWidget
->setFocus();
439 void DolphinMainWindow::activateNextTab()
441 if ((m_viewTab
.count() == 1) || (m_tabBar
->count() < 2)) {
445 const int tabIndex
= (m_tabBar
->currentIndex() + 1) % m_tabBar
->count();
446 m_tabBar
->setCurrentIndex(tabIndex
);
449 void DolphinMainWindow::activatePrevTab()
451 if ((m_viewTab
.count() == 1) || (m_tabBar
->count() < 2)) {
455 int tabIndex
= m_tabBar
->currentIndex() - 1;
456 if (tabIndex
== -1) {
457 tabIndex
= m_tabBar
->count() - 1;
459 m_tabBar
->setCurrentIndex(tabIndex
);
462 void DolphinMainWindow::openInNewTab()
464 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
465 if ((list
.count() == 1) && list
[0].isDir()) {
466 openNewTab(m_activeViewContainer
->view()->selectedUrls()[0]);
470 void DolphinMainWindow::openInNewWindow()
472 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
473 if ((list
.count() == 1) && list
[0].isDir()) {
474 DolphinMainWindow
* window
= DolphinApplication::app()->createMainWindow();
475 window
->changeUrl(m_activeViewContainer
->view()->selectedUrls()[0]);
480 void DolphinMainWindow::toggleActiveView()
482 if (m_viewTab
[m_tabIndex
].secondaryView
== 0) {
483 // only one view is available
487 Q_ASSERT(m_activeViewContainer
!= 0);
488 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
490 DolphinViewContainer
* left
= m_viewTab
[m_tabIndex
].primaryView
;
491 DolphinViewContainer
* right
= m_viewTab
[m_tabIndex
].secondaryView
;
492 setActiveViewContainer(m_activeViewContainer
== right
? left
: right
);
495 void DolphinMainWindow::showEvent(QShowEvent
* event
)
497 KXmlGuiWindow::showEvent(event
);
498 if (!event
->spontaneous()) {
499 m_activeViewContainer
->view()->setFocus();
503 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
505 DolphinSettings
& settings
= DolphinSettings::instance();
506 GeneralSettings
* generalSettings
= settings
.generalSettings();
508 // Find out if Dolphin is closed directly by the user or
509 // by the session manager because the session is closed
510 bool closedByUser
= true;
511 DolphinApplication
*application
= qobject_cast
<DolphinApplication
*>(qApp
);
512 if (application
&& application
->sessionSaving()) {
513 closedByUser
= false;
516 if ((m_viewTab
.count() > 1) && generalSettings
->confirmClosingMultipleTabs() && closedByUser
) {
517 // Ask the user if he really wants to quit and close all tabs.
518 // Open a confirmation dialog with 3 buttons:
519 // KDialog::Yes -> Quit
520 // KDialog::No -> Close only the current tab
521 // KDialog::Cancel -> do nothing
522 KDialog
*dialog
= new KDialog(this, Qt::Dialog
);
523 dialog
->setCaption(i18nc("@title:window", "Confirmation"));
524 dialog
->setButtons(KDialog::Yes
| KDialog::No
| KDialog::Cancel
);
525 dialog
->setModal(true);
526 dialog
->setButtonGuiItem(KDialog::Yes
, KStandardGuiItem::quit());
527 dialog
->setButtonGuiItem(KDialog::No
, KGuiItem(i18n("C&lose Current Tab"), KIcon("tab-close")));
528 dialog
->setButtonGuiItem(KDialog::Cancel
, KStandardGuiItem::cancel());
529 dialog
->setDefaultButton(KDialog::Yes
);
531 bool doNotAskAgainCheckboxResult
= false;
533 const int result
= KMessageBox::createKMessageBox(dialog
,
534 QMessageBox::Warning
,
535 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
537 i18n("Do not ask again"),
538 &doNotAskAgainCheckboxResult
,
539 KMessageBox::Notify
);
541 if (doNotAskAgainCheckboxResult
) {
542 generalSettings
->setConfirmClosingMultipleTabs(false);
550 // Close only the current tab
558 generalSettings
->setFirstRun(false);
562 KXmlGuiWindow::closeEvent(event
);
565 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
567 const int tabCount
= m_viewTab
.count();
568 group
.writeEntry("Tab Count", tabCount
);
569 group
.writeEntry("Active Tab Index", m_tabBar
->currentIndex());
571 for (int i
= 0; i
< tabCount
; ++i
) {
572 const DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
573 group
.writeEntry(tabProperty("Primary URL", i
), cont
->url().url());
574 group
.writeEntry(tabProperty("Primary Editable", i
),
575 cont
->urlNavigator()->isUrlEditable());
577 cont
= m_viewTab
[i
].secondaryView
;
579 group
.writeEntry(tabProperty("Secondary URL", i
), cont
->url().url());
580 group
.writeEntry(tabProperty("Secondary Editable", i
),
581 cont
->urlNavigator()->isUrlEditable());
586 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
588 const int tabCount
= group
.readEntry("Tab Count", 1);
589 for (int i
= 0; i
< tabCount
; ++i
) {
590 DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
592 cont
->setUrl(group
.readEntry(tabProperty("Primary URL", i
)));
593 const bool editable
= group
.readEntry(tabProperty("Primary Editable", i
), false);
594 cont
->urlNavigator()->setUrlEditable(editable
);
596 cont
= m_viewTab
[i
].secondaryView
;
597 const QString secondaryUrl
= group
.readEntry(tabProperty("Secondary URL", i
));
598 if (!secondaryUrl
.isEmpty()) {
600 // a secondary view should be shown, but no one is available
601 // currently -> create a new view
603 cont
= m_viewTab
[i
].secondaryView
;
607 cont
->setUrl(secondaryUrl
);
608 const bool editable
= group
.readEntry(tabProperty("Secondary Editable", i
), false);
609 cont
->urlNavigator()->setUrlEditable(editable
);
610 } else if (cont
!= 0) {
611 // no secondary view should be shown, but the default setting shows
612 // one already -> close the view
616 // openNewTab() needs to be called only tabCount - 1 times
617 if (i
!= tabCount
- 1) {
622 const int index
= group
.readEntry("Active Tab Index", 0);
623 m_tabBar
->setCurrentIndex(index
);
626 void DolphinMainWindow::updateNewMenu()
628 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->showHiddenFiles());
629 m_newFileMenu
->checkUpToDate();
630 m_newFileMenu
->setPopupFiles(activeViewContainer()->url());
633 void DolphinMainWindow::createDirectory()
635 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->showHiddenFiles());
636 m_newFileMenu
->setPopupFiles(activeViewContainer()->url());
637 m_newFileMenu
->createDirectory();
640 void DolphinMainWindow::quit()
645 void DolphinMainWindow::showErrorMessage(const QString
& message
)
647 if (!message
.isEmpty()) {
648 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
649 statusBar
->setMessage(message
, DolphinStatusBar::Error
);
653 void DolphinMainWindow::slotUndoAvailable(bool available
)
655 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
656 if (undoAction
!= 0) {
657 undoAction
->setEnabled(available
);
661 void DolphinMainWindow::restoreClosedTab(QAction
* action
)
663 if (action
->data().toBool()) {
664 // clear all actions except the "Empty Recently Closed Tabs"
665 // action and the separator
666 QList
<QAction
*> actions
= m_recentTabsMenu
->menu()->actions();
667 const int count
= actions
.size();
668 for (int i
= 2; i
< count
; ++i
) {
669 m_recentTabsMenu
->menu()->removeAction(actions
.at(i
));
672 const ClosedTab closedTab
= action
->data().value
<ClosedTab
>();
673 openNewTab(closedTab
.primaryUrl
);
674 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
676 if (closedTab
.isSplit
) {
677 // create secondary view
679 m_viewTab
[m_tabIndex
].secondaryView
->setUrl(closedTab
.secondaryUrl
);
682 m_recentTabsMenu
->removeAction(action
);
685 if (m_recentTabsMenu
->menu()->actions().count() == 2) {
686 m_recentTabsMenu
->setEnabled(false);
690 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
692 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
693 if (undoAction
!= 0) {
694 undoAction
->setText(text
);
698 void DolphinMainWindow::undo()
701 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
702 KIO::FileUndoManager::self()->undo();
705 void DolphinMainWindow::cut()
707 m_activeViewContainer
->view()->cutSelectedItems();
710 void DolphinMainWindow::copy()
712 m_activeViewContainer
->view()->copySelectedItems();
715 void DolphinMainWindow::paste()
717 m_activeViewContainer
->view()->paste();
720 void DolphinMainWindow::find()
722 m_activeViewContainer
->setSearchModeEnabled(true);
725 void DolphinMainWindow::updatePasteAction()
727 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
728 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
729 pasteAction
->setEnabled(pasteInfo
.first
);
730 pasteAction
->setText(pasteInfo
.second
);
733 void DolphinMainWindow::selectAll()
737 // if the URL navigator is editable and focused, select the whole
738 // URL instead of all items of the view
740 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
741 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit(); // krazy:exclude=qclasses
742 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
743 lineEdit
->hasFocus();
745 lineEdit
->selectAll();
747 m_activeViewContainer
->view()->selectAll();
751 void DolphinMainWindow::invertSelection()
754 m_activeViewContainer
->view()->invertSelection();
757 void DolphinMainWindow::toggleSplitView()
759 if (m_viewTab
[m_tabIndex
].secondaryView
== 0) {
760 createSecondaryView(m_tabIndex
);
761 setActiveViewContainer(m_viewTab
[m_tabIndex
].secondaryView
);
762 } else if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
763 // remove secondary view
764 m_viewTab
[m_tabIndex
].secondaryView
->close();
765 m_viewTab
[m_tabIndex
].secondaryView
->deleteLater();
766 m_viewTab
[m_tabIndex
].secondaryView
= 0;
768 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
770 // The primary view is active and should be closed. Hence from a users point of view
771 // the content of the secondary view should be moved to the primary view.
772 // From an implementation point of view it is more efficient to close
773 // the primary view and exchange the internal pointers afterwards.
775 m_viewTab
[m_tabIndex
].primaryView
->close();
776 m_viewTab
[m_tabIndex
].primaryView
->deleteLater();
777 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
778 m_viewTab
[m_tabIndex
].secondaryView
= 0;
780 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
786 void DolphinMainWindow::reloadView()
789 m_activeViewContainer
->view()->reload();
792 void DolphinMainWindow::stopLoading()
794 m_activeViewContainer
->view()->stopLoading();
797 void DolphinMainWindow::enableStopAction()
799 actionCollection()->action("stop")->setEnabled(true);
802 void DolphinMainWindow::disableStopAction()
804 actionCollection()->action("stop")->setEnabled(false);
807 void DolphinMainWindow::toggleFilterBarVisibility(bool show
)
809 m_activeViewContainer
->showFilterBar(show
);
812 void DolphinMainWindow::toggleEditLocation()
816 QAction
* action
= actionCollection()->action("editable_location");
817 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
818 urlNavigator
->setUrlEditable(action
->isChecked());
821 void DolphinMainWindow::replaceLocation()
823 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
824 navigator
->setUrlEditable(true);
825 navigator
->setFocus();
827 // select the whole text of the combo box editor
828 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit(); // krazy:exclude=qclasses
829 const QString text
= lineEdit
->text();
830 lineEdit
->setSelection(0, text
.length());
833 void DolphinMainWindow::goBack()
837 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
838 urlNavigator
->goBack();
840 if (urlNavigator
->locationState().isEmpty()) {
841 // An empty location state indicates a redirection URL,
842 // which must be skipped too
843 urlNavigator
->goBack();
847 void DolphinMainWindow::goForward()
850 m_activeViewContainer
->urlNavigator()->goForward();
853 void DolphinMainWindow::goUp()
856 m_activeViewContainer
->urlNavigator()->goUp();
859 void DolphinMainWindow::goBack(Qt::MouseButtons buttons
)
861 // The default case (left button pressed) is handled in goBack().
862 if (buttons
== Qt::MidButton
) {
863 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
864 const int index
= urlNavigator
->historyIndex() + 1;
865 openNewTab(urlNavigator
->locationUrl(index
));
869 void DolphinMainWindow::goForward(Qt::MouseButtons buttons
)
871 // The default case (left button pressed) is handled in goForward().
872 if (buttons
== Qt::MidButton
) {
873 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
874 const int index
= urlNavigator
->historyIndex() - 1;
875 openNewTab(urlNavigator
->locationUrl(index
));
879 void DolphinMainWindow::goUp(Qt::MouseButtons buttons
)
881 // The default case (left button pressed) is handled in goUp().
882 if (buttons
== Qt::MidButton
) {
883 openNewTab(activeViewContainer()->url().upUrl());
887 void DolphinMainWindow::goHome()
890 m_activeViewContainer
->urlNavigator()->goHome();
893 void DolphinMainWindow::compareFiles()
895 // The method is only invoked if exactly 2 files have
896 // been selected. The selected files may be:
897 // - both in the primary view
898 // - both in the secondary view
899 // - one in the primary view and the other in the secondary
901 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
905 KUrl::List urls
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedUrls();
907 switch (urls
.count()) {
909 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
!= 0);
910 urls
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedUrls();
911 Q_ASSERT(urls
.count() == 2);
919 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
!= 0);
920 urls
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedUrls();
921 Q_ASSERT(urls
.count() == 1);
933 // may not happen: compareFiles may only get invoked if 2
934 // files are selected
939 QString
command("kompare -c \"");
940 command
.append(urlA
.pathOrUrl());
941 command
.append("\" \"");
942 command
.append(urlB
.pathOrUrl());
943 command
.append('\"');
944 KRun::runCommand(command
, "Kompare", "kompare", this);
947 void DolphinMainWindow::toggleShowMenuBar()
949 const bool visible
= menuBar()->isVisible();
950 menuBar()->setVisible(!visible
);
953 void DolphinMainWindow::openTerminal()
955 QString
dir(QDir::homePath());
957 // If the given directory is not local, it can still be the URL of an
958 // ioslave using UDS_LOCAL_PATH which to be converted first.
959 KUrl url
= KIO::NetAccess::mostLocalUrl(m_activeViewContainer
->url(), this);
961 //If the URL is local after the above conversion, set the directory.
962 if (url
.isLocalFile()) {
963 dir
= url
.toLocalFile();
966 KToolInvocation::invokeTerminal(QString(), dir
);
969 void DolphinMainWindow::editSettings()
971 if (m_settingsDialog
== 0) {
972 const KUrl url
= activeViewContainer()->url();
973 m_settingsDialog
= new DolphinSettingsDialog(url
, this);
974 m_settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
975 m_settingsDialog
->show();
977 m_settingsDialog
->raise();
981 void DolphinMainWindow::setActiveTab(int index
)
983 Q_ASSERT(index
>= 0);
984 Q_ASSERT(index
< m_viewTab
.count());
985 if (index
== m_tabIndex
) {
989 // hide current tab content
990 ViewTab
& hiddenTab
= m_viewTab
[m_tabIndex
];
991 hiddenTab
.isPrimaryViewActive
= hiddenTab
.primaryView
->isActive();
992 hiddenTab
.primaryView
->setActive(false);
993 if (hiddenTab
.secondaryView
!= 0) {
994 hiddenTab
.secondaryView
->setActive(false);
996 QSplitter
* splitter
= m_viewTab
[m_tabIndex
].splitter
;
998 m_centralWidgetLayout
->removeWidget(splitter
);
1000 // show active tab content
1003 ViewTab
& viewTab
= m_viewTab
[index
];
1004 m_centralWidgetLayout
->addWidget(viewTab
.splitter
, 1);
1005 viewTab
.primaryView
->show();
1006 if (viewTab
.secondaryView
!= 0) {
1007 viewTab
.secondaryView
->show();
1009 viewTab
.splitter
->show();
1011 setActiveViewContainer(viewTab
.isPrimaryViewActive
? viewTab
.primaryView
:
1012 viewTab
.secondaryView
);
1015 void DolphinMainWindow::closeTab()
1017 closeTab(m_tabBar
->currentIndex());
1020 void DolphinMainWindow::closeTab(int index
)
1022 Q_ASSERT(index
>= 0);
1023 Q_ASSERT(index
< m_viewTab
.count());
1024 if (m_viewTab
.count() == 1) {
1025 // the last tab may never get closed
1029 if (index
== m_tabIndex
) {
1030 // The tab that should be closed is the active tab. Activate the
1031 // previous tab before closing the tab.
1032 m_tabBar
->setCurrentIndex((index
> 0) ? index
- 1 : 1);
1034 rememberClosedTab(index
);
1037 m_viewTab
[index
].primaryView
->deleteLater();
1038 if (m_viewTab
[index
].secondaryView
!= 0) {
1039 m_viewTab
[index
].secondaryView
->deleteLater();
1041 m_viewTab
[index
].splitter
->deleteLater();
1042 m_viewTab
.erase(m_viewTab
.begin() + index
);
1044 m_tabBar
->blockSignals(true);
1045 m_tabBar
->removeTab(index
);
1047 if (m_tabIndex
> index
) {
1049 Q_ASSERT(m_tabIndex
>= 0);
1052 // if only one tab is left, also remove the tab entry so that
1053 // closing the last tab is not possible
1054 if (m_viewTab
.count() == 1) {
1055 m_tabBar
->removeTab(0);
1056 actionCollection()->action("close_tab")->setEnabled(false);
1058 m_tabBar
->blockSignals(false);
1062 void DolphinMainWindow::openTabContextMenu(int index
, const QPoint
& pos
)
1066 QAction
* newTabAction
= menu
.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab"));
1067 newTabAction
->setShortcut(actionCollection()->action("new_tab")->shortcut());
1069 QAction
* detachTabAction
= menu
.addAction(KIcon("tab-detach"), i18nc("@action:inmenu", "Detach Tab"));
1071 QAction
* closeOtherTabsAction
= menu
.addAction(KIcon("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs"));
1073 QAction
* closeTabAction
= menu
.addAction(KIcon("tab-close"), i18nc("@action:inmenu", "Close Tab"));
1074 closeTabAction
->setShortcut(actionCollection()->action("close_tab")->shortcut());
1075 QAction
* selectedAction
= menu
.exec(pos
);
1076 if (selectedAction
== newTabAction
) {
1077 const ViewTab
& tab
= m_viewTab
[index
];
1078 Q_ASSERT(tab
.primaryView
!= 0);
1079 const KUrl url
= (tab
.secondaryView
!= 0) && tab
.secondaryView
->isActive() ?
1080 tab
.secondaryView
->url() : tab
.primaryView
->url();
1082 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
1083 } else if (selectedAction
== detachTabAction
) {
1084 const ViewTab
& tab
= m_viewTab
[index
];
1085 Q_ASSERT(tab
.primaryView
!= 0);
1086 const KUrl primaryUrl
= tab
.primaryView
->url();
1087 DolphinMainWindow
* window
= DolphinApplication::app()->createMainWindow();
1088 window
->changeUrl(primaryUrl
);
1090 if (tab
.secondaryView
!= 0) {
1091 const KUrl secondaryUrl
= tab
.secondaryView
->url();
1092 window
->toggleSplitView();
1093 window
->m_viewTab
[0].secondaryView
->setUrl(secondaryUrl
);
1094 if (tab
.primaryView
->isActive()) {
1095 window
->m_viewTab
[0].primaryView
->setActive(true);
1097 window
->m_viewTab
[0].secondaryView
->setActive(true);
1102 } else if (selectedAction
== closeOtherTabsAction
) {
1103 const int count
= m_tabBar
->count();
1104 for (int i
= 0; i
< index
; ++i
) {
1107 for (int i
= index
+ 1; i
< count
; ++i
) {
1110 } else if (selectedAction
== closeTabAction
) {
1115 void DolphinMainWindow::slotTabMoved(int from
, int to
)
1117 m_viewTab
.move(from
, to
);
1118 m_tabIndex
= m_tabBar
->currentIndex();
1121 void DolphinMainWindow::handlePlacesClick(const KUrl
& url
, Qt::MouseButtons buttons
)
1123 if (buttons
& Qt::MidButton
) {
1125 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
1131 void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent
* event
, bool& canDecode
)
1133 canDecode
= KUrl::List::canDecode(event
->mimeData());
1136 void DolphinMainWindow::handleUrl(const KUrl
& url
)
1138 delete m_lastHandleUrlStatJob
;
1139 m_lastHandleUrlStatJob
= 0;
1141 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1142 activeViewContainer()->setUrl(url
);
1143 } else if (KProtocolManager::supportsListing(url
)) {
1144 // stat the URL to see if it is a dir or not
1145 m_lastHandleUrlStatJob
= KIO::stat(url
, KIO::HideProgressInfo
);
1146 connect(m_lastHandleUrlStatJob
, SIGNAL(result(KJob
*)),
1147 this, SLOT(slotHandleUrlStatFinished(KJob
*)));
1150 new KRun(url
, this);
1154 void DolphinMainWindow::slotHandleUrlStatFinished(KJob
* job
)
1156 m_lastHandleUrlStatJob
= 0;
1157 const KIO::UDSEntry entry
= static_cast<KIO::StatJob
*>(job
)->statResult();
1158 const KUrl url
= static_cast<KIO::StatJob
*>(job
)->url();
1159 if ( entry
.isDir() ) {
1160 activeViewContainer()->setUrl(url
);
1162 new KRun(url
, this);
1166 void DolphinMainWindow::tabDropEvent(int tab
, QDropEvent
* event
)
1168 const KUrl::List urls
= KUrl::List::fromMimeData(event
->mimeData());
1169 if (!urls
.isEmpty() && tab
!= -1) {
1170 const ViewTab
& viewTab
= m_viewTab
[tab
];
1171 const KUrl destPath
= viewTab
.isPrimaryViewActive
? viewTab
.primaryView
->url() : viewTab
.secondaryView
->url();
1172 DragAndDropHelper::instance().dropUrls(KFileItem(), destPath
, event
, m_tabBar
);
1176 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1178 newFileMenu()->setEnabled(isFolderWritable
);
1181 void DolphinMainWindow::openContextMenu(const KFileItem
& item
,
1183 const QList
<QAction
*>& customActions
)
1185 DolphinContextMenu
contextMenu(this, item
, url
);
1186 contextMenu
.setCustomActions(customActions
);
1187 const DolphinContextMenu::Command command
= contextMenu
.open();
1190 case DolphinContextMenu::OpenParentFolderInNewWindow
: {
1191 DolphinMainWindow
* window
= DolphinApplication::app()->createMainWindow();
1192 window
->changeUrl(item
.url().upUrl());
1197 case DolphinContextMenu::OpenParentFolderInNewTab
:
1198 openNewTab(item
.url().upUrl());
1201 case DolphinContextMenu::None
:
1207 void DolphinMainWindow::init()
1209 DolphinSettings
& settings
= DolphinSettings::instance();
1211 // Check whether Dolphin runs the first time. If yes then
1212 // a proper default window size is given at the end of DolphinMainWindow::init().
1213 GeneralSettings
* generalSettings
= settings
.generalSettings();
1214 const bool firstRun
= generalSettings
->firstRun();
1216 generalSettings
->setViewPropsTimestamp(QDateTime::currentDateTime());
1219 setAcceptDrops(true);
1221 m_viewTab
[m_tabIndex
].splitter
= new QSplitter(this);
1222 m_viewTab
[m_tabIndex
].splitter
->setChildrenCollapsible(false);
1226 const KUrl
homeUrl(generalSettings
->homeUrl());
1227 setUrlAsCaption(homeUrl
);
1228 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
1229 connect(m_actionHandler
, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
1230 connect(m_actionHandler
, SIGNAL(createDirectory()), SLOT(createDirectory()));
1231 ViewProperties
props(homeUrl
);
1232 m_viewTab
[m_tabIndex
].primaryView
= new DolphinViewContainer(homeUrl
,
1233 m_viewTab
[m_tabIndex
].splitter
);
1235 m_activeViewContainer
= m_viewTab
[m_tabIndex
].primaryView
;
1236 connectViewSignals(m_activeViewContainer
);
1237 DolphinView
* view
= m_activeViewContainer
->view();
1239 m_activeViewContainer
->show();
1240 m_actionHandler
->setCurrentView(view
);
1242 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
1243 connect(this, SIGNAL(urlChanged(const KUrl
&)),
1244 m_remoteEncoding
, SLOT(slotAboutToOpenUrl()));
1246 m_tabBar
= new KTabBar(this);
1247 m_tabBar
->setMovable(true);
1248 m_tabBar
->setTabsClosable(true);
1249 connect(m_tabBar
, SIGNAL(currentChanged(int)),
1250 this, SLOT(setActiveTab(int)));
1251 connect(m_tabBar
, SIGNAL(tabCloseRequested(int)),
1252 this, SLOT(closeTab(int)));
1253 connect(m_tabBar
, SIGNAL(contextMenu(int, const QPoint
&)),
1254 this, SLOT(openTabContextMenu(int, const QPoint
&)));
1255 connect(m_tabBar
, SIGNAL(newTabRequest()),
1256 this, SLOT(openNewTab()));
1257 connect(m_tabBar
, SIGNAL(testCanDecode(const QDragMoveEvent
*, bool&)),
1258 this, SLOT(slotTestCanDecode(const QDragMoveEvent
*, bool&)));
1259 connect(m_tabBar
, SIGNAL(mouseMiddleClick(int)),
1260 this, SLOT(closeTab(int)));
1261 connect(m_tabBar
, SIGNAL(tabMoved(int, int)),
1262 this, SLOT(slotTabMoved(int, int)));
1263 connect(m_tabBar
, SIGNAL(receivedDropEvent(int, QDropEvent
*)),
1264 this, SLOT(tabDropEvent(int, QDropEvent
*)));
1266 m_tabBar
->blockSignals(true); // signals get unblocked after at least 2 tabs are open
1268 QWidget
* centralWidget
= new QWidget(this);
1269 m_centralWidgetLayout
= new QVBoxLayout(centralWidget
);
1270 m_centralWidgetLayout
->setSpacing(0);
1271 m_centralWidgetLayout
->setMargin(0);
1272 m_centralWidgetLayout
->addWidget(m_tabBar
);
1273 m_centralWidgetLayout
->addWidget(m_viewTab
[m_tabIndex
].splitter
, 1);
1275 setCentralWidget(centralWidget
);
1277 emit
urlChanged(homeUrl
);
1279 setupGUI(Keys
| Save
| Create
| ToolBar
);
1280 stateChanged("new_file");
1282 QClipboard
* clipboard
= QApplication::clipboard();
1283 connect(clipboard
, SIGNAL(dataChanged()),
1284 this, SLOT(updatePasteAction()));
1286 if (generalSettings
->splitView()) {
1289 updateEditActions();
1290 updateViewActions();
1293 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1294 showFilterBarAction
->setChecked(generalSettings
->filterBar());
1297 // assure a proper default size if Dolphin runs the first time
1301 m_showMenuBar
->setChecked(!menuBar()->isHidden()); // workaround for bug #171080
1304 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer
* viewContainer
)
1306 Q_ASSERT(viewContainer
!= 0);
1307 Q_ASSERT((viewContainer
== m_viewTab
[m_tabIndex
].primaryView
) ||
1308 (viewContainer
== m_viewTab
[m_tabIndex
].secondaryView
));
1309 if (m_activeViewContainer
== viewContainer
) {
1313 m_activeViewContainer
->setActive(false);
1314 m_activeViewContainer
= viewContainer
;
1316 // Activating the view container might trigger a recursive setActiveViewContainer() call
1317 // inside DolphinMainWindow::toggleActiveView() when having a split view. Temporary
1318 // disconnect the activated() signal in this case:
1319 disconnect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1320 m_activeViewContainer
->setActive(true);
1321 connect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1323 m_actionHandler
->setCurrentView(viewContainer
->view());
1326 updateEditActions();
1327 updateViewActions();
1330 const KUrl url
= m_activeViewContainer
->url();
1331 setUrlAsCaption(url
);
1332 if (m_viewTab
.count() > 1) {
1333 m_tabBar
->setTabText(m_tabIndex
, tabName(url
));
1334 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(KMimeType::iconNameForUrl(url
)));
1337 emit
urlChanged(url
);
1340 void DolphinMainWindow::setupActions()
1342 // setup 'File' menu
1343 m_newFileMenu
= new DolphinNewFileMenu(this, this);
1344 KMenu
* menu
= m_newFileMenu
->menu();
1345 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1346 menu
->setIcon(KIcon("document-new"));
1347 connect(menu
, SIGNAL(aboutToShow()),
1348 this, SLOT(updateNewMenu()));
1350 KAction
* newWindow
= actionCollection()->addAction("new_window");
1351 newWindow
->setIcon(KIcon("window-new"));
1352 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1353 newWindow
->setShortcut(Qt::CTRL
| Qt::Key_N
);
1354 connect(newWindow
, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1356 KAction
* newTab
= actionCollection()->addAction("new_tab");
1357 newTab
->setIcon(KIcon("tab-new"));
1358 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1359 newTab
->setShortcut(KShortcut(Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
));
1360 connect(newTab
, SIGNAL(triggered()), this, SLOT(openNewTab()));
1362 KAction
* closeTab
= actionCollection()->addAction("close_tab");
1363 closeTab
->setIcon(KIcon("tab-close"));
1364 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1365 closeTab
->setShortcut(Qt::CTRL
| Qt::Key_W
);
1366 closeTab
->setEnabled(false);
1367 connect(closeTab
, SIGNAL(triggered()), this, SLOT(closeTab()));
1369 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1371 // setup 'Edit' menu
1372 KStandardAction::undo(this,
1374 actionCollection());
1376 // need to remove shift+del from cut action, else the shortcut for deletejob
1378 KAction
* cut
= KStandardAction::cut(this, SLOT(cut()), actionCollection());
1379 KShortcut cutShortcut
= cut
->shortcut();
1380 cutShortcut
.remove(Qt::SHIFT
+ Qt::Key_Delete
, KShortcut::KeepEmpty
);
1381 cut
->setShortcut(cutShortcut
);
1382 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1383 KAction
* paste
= KStandardAction::paste(this, SLOT(paste()), actionCollection());
1384 // The text of the paste-action is modified dynamically by Dolphin
1385 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1386 // due to the long text, the text "Paste" is used:
1387 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1389 KStandardAction::find(this, SLOT(find()), actionCollection());
1391 KAction
* selectAll
= actionCollection()->addAction("select_all");
1392 selectAll
->setText(i18nc("@action:inmenu Edit", "Select All"));
1393 selectAll
->setShortcut(Qt::CTRL
+ Qt::Key_A
);
1394 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
1396 KAction
* invertSelection
= actionCollection()->addAction("invert_selection");
1397 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1398 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1399 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
1401 // setup 'View' menu
1402 // (note that most of it is set up in DolphinViewActionHandler)
1404 KAction
* split
= actionCollection()->addAction("split_view");
1405 split
->setShortcut(Qt::Key_F3
);
1406 updateSplitAction();
1407 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1409 KAction
* reload
= actionCollection()->addAction("reload");
1410 reload
->setText(i18nc("@action:inmenu View", "Reload"));
1411 reload
->setShortcut(Qt::Key_F5
);
1412 reload
->setIcon(KIcon("view-refresh"));
1413 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
1415 KAction
* stop
= actionCollection()->addAction("stop");
1416 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1417 stop
->setToolTip(i18nc("@info", "Stop loading"));
1418 stop
->setIcon(KIcon("process-stop"));
1419 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
1421 KToggleAction
* showFullLocation
= actionCollection()->add
<KToggleAction
>("editable_location");
1422 showFullLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1423 showFullLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
1424 connect(showFullLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1426 KAction
* replaceLocation
= actionCollection()->addAction("replace_location");
1427 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1428 replaceLocation
->setShortcut(Qt::Key_F6
);
1429 connect(replaceLocation
, SIGNAL(triggered()), this, SLOT(replaceLocation()));
1432 KAction
* backAction
= KStandardAction::back(this, SLOT(goBack()), actionCollection());
1433 connect(backAction
, SIGNAL(triggered(Qt::MouseButtons
, Qt::KeyboardModifiers
)), this, SLOT(goBack(Qt::MouseButtons
)));
1434 KShortcut backShortcut
= backAction
->shortcut();
1435 backShortcut
.setAlternate(Qt::Key_Backspace
);
1436 backAction
->setShortcut(backShortcut
);
1438 m_recentTabsMenu
= new KActionMenu(i18n("Recently Closed Tabs"), this);
1439 m_recentTabsMenu
->setIcon(KIcon("edit-undo"));
1440 actionCollection()->addAction("closed_tabs", m_recentTabsMenu
);
1441 connect(m_recentTabsMenu
->menu(), SIGNAL(triggered(QAction
*)),
1442 this, SLOT(restoreClosedTab(QAction
*)));
1444 QAction
* action
= new QAction("Empty Recently Closed Tabs", m_recentTabsMenu
);
1445 action
->setIcon(KIcon("edit-clear-list"));
1446 action
->setData(QVariant::fromValue(true));
1447 m_recentTabsMenu
->addAction(action
);
1448 m_recentTabsMenu
->addSeparator();
1449 m_recentTabsMenu
->setEnabled(false);
1451 KAction
* forwardAction
= KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1452 connect(forwardAction
, SIGNAL(triggered(Qt::MouseButtons
, Qt::KeyboardModifiers
)), this, SLOT(goForward(Qt::MouseButtons
)));
1454 KAction
* upAction
= KStandardAction::up(this, SLOT(goUp()), actionCollection());
1455 connect(upAction
, SIGNAL(triggered(Qt::MouseButtons
, Qt::KeyboardModifiers
)), this, SLOT(goUp(Qt::MouseButtons
)));
1457 KStandardAction::home(this, SLOT(goHome()), actionCollection());
1459 // setup 'Tools' menu
1460 KToggleAction
* showFilterBar
= actionCollection()->add
<KToggleAction
>("show_filter_bar");
1461 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1462 showFilterBar
->setIcon(KIcon("view-filter"));
1463 showFilterBar
->setShortcut(Qt::CTRL
| Qt::Key_I
);
1464 connect(showFilterBar
, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
1466 KAction
* compareFiles
= actionCollection()->addAction("compare_files");
1467 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1468 compareFiles
->setIcon(KIcon("kompare"));
1469 compareFiles
->setEnabled(false);
1470 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
1472 KAction
* openTerminal
= actionCollection()->addAction("open_terminal");
1473 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1474 openTerminal
->setIcon(KIcon("utilities-terminal"));
1475 openTerminal
->setShortcut(Qt::SHIFT
| Qt::Key_F4
);
1476 connect(openTerminal
, SIGNAL(triggered()), this, SLOT(openTerminal()));
1478 // setup 'Settings' menu
1479 m_showMenuBar
= KStandardAction::showMenubar(this, SLOT(toggleShowMenuBar()), actionCollection());
1480 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1482 // not in menu actions
1483 QList
<QKeySequence
> nextTabKeys
;
1484 nextTabKeys
.append(KStandardShortcut::tabNext().primary());
1485 nextTabKeys
.append(QKeySequence(Qt::CTRL
+ Qt::Key_Tab
));
1487 QList
<QKeySequence
> prevTabKeys
;
1488 prevTabKeys
.append(KStandardShortcut::tabPrev().primary());
1489 prevTabKeys
.append(QKeySequence(Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_Tab
));
1491 KAction
* activateNextTab
= actionCollection()->addAction("activate_next_tab");
1492 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1493 connect(activateNextTab
, SIGNAL(triggered()), SLOT(activateNextTab()));
1494 activateNextTab
->setShortcuts(QApplication::isRightToLeft() ? prevTabKeys
: nextTabKeys
);
1496 KAction
* activatePrevTab
= actionCollection()->addAction("activate_prev_tab");
1497 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1498 connect(activatePrevTab
, SIGNAL(triggered()), SLOT(activatePrevTab()));
1499 activatePrevTab
->setShortcuts(QApplication::isRightToLeft() ? nextTabKeys
: prevTabKeys
);
1502 KAction
* openInNewTab
= actionCollection()->addAction("open_in_new_tab");
1503 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1504 openInNewTab
->setIcon(KIcon("tab-new"));
1505 connect(openInNewTab
, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1507 KAction
* openInNewWindow
= actionCollection()->addAction("open_in_new_window");
1508 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1509 openInNewWindow
->setIcon(KIcon("window-new"));
1510 connect(openInNewWindow
, SIGNAL(triggered()), this, SLOT(openInNewWindow()));
1513 void DolphinMainWindow::setupDockWidgets()
1515 // setup "Information"
1516 QDockWidget
* infoDock
= new QDockWidget(i18nc("@title:window", "Information"));
1517 infoDock
->setObjectName("infoDock");
1518 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1519 Panel
* infoPanel
= new InformationPanel(infoDock
);
1520 connect(infoPanel
, SIGNAL(urlActivated(KUrl
)), this, SLOT(handleUrl(KUrl
)));
1521 infoDock
->setWidget(infoPanel
);
1523 QAction
* infoAction
= infoDock
->toggleViewAction();
1524 infoAction
->setIcon(KIcon("dialog-information"));
1525 infoAction
->setShortcut(Qt::Key_F11
);
1527 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1528 connect(this, SIGNAL(urlChanged(KUrl
)),
1529 infoPanel
, SLOT(setUrl(KUrl
)));
1530 connect(this, SIGNAL(selectionChanged(KFileItemList
)),
1531 infoPanel
, SLOT(setSelection(KFileItemList
)));
1532 connect(this, SIGNAL(requestItemInfo(KFileItem
)),
1533 infoPanel
, SLOT(requestDelayedItemInfo(KFileItem
)));
1536 QDockWidget
* foldersDock
= new QDockWidget(i18nc("@title:window", "Folders"));
1537 foldersDock
->setObjectName("foldersDock");
1538 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1539 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1540 foldersDock
->setWidget(foldersPanel
);
1542 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1543 foldersAction
->setShortcut(Qt::Key_F7
);
1544 foldersAction
->setIcon(KIcon("folder"));
1546 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1547 connect(this, SIGNAL(urlChanged(KUrl
)),
1548 foldersPanel
, SLOT(setUrl(KUrl
)));
1549 connect(foldersPanel
, SIGNAL(changeUrl(KUrl
, Qt::MouseButtons
)),
1550 this, SLOT(handlePlacesClick(KUrl
, Qt::MouseButtons
)));
1554 QDockWidget
* terminalDock
= new QDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1555 terminalDock
->setObjectName("terminalDock");
1556 terminalDock
->setAllowedAreas(Qt::TopDockWidgetArea
| Qt::BottomDockWidgetArea
);
1557 Panel
* terminalPanel
= new TerminalPanel(terminalDock
);
1558 terminalDock
->setWidget(terminalPanel
);
1560 connect(terminalPanel
, SIGNAL(hideTerminalPanel()), terminalDock
, SLOT(hide()));
1562 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1563 terminalAction
->setShortcut(Qt::Key_F4
);
1564 terminalAction
->setIcon(KIcon("utilities-terminal"));
1566 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1567 connect(this, SIGNAL(urlChanged(KUrl
)),
1568 terminalPanel
, SLOT(setUrl(KUrl
)));
1571 const bool firstRun
= DolphinSettings::instance().generalSettings()->firstRun();
1574 foldersDock
->hide();
1576 terminalDock
->hide();
1581 QDockWidget
* placesDock
= new QDockWidget(i18nc("@title:window", "Places"));
1582 placesDock
->setObjectName("placesDock");
1583 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1585 PlacesPanel
* placesPanel
= new PlacesPanel(placesDock
);
1586 placesDock
->setWidget(placesPanel
);
1587 placesPanel
->setModel(DolphinSettings::instance().placesModel());
1588 placesPanel
->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff
);
1590 QAction
* placesAction
= placesDock
->toggleViewAction();
1591 placesAction
->setShortcut(Qt::Key_F9
);
1592 placesAction
->setIcon(KIcon("bookmarks"));
1594 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1595 connect(placesPanel
, SIGNAL(urlChanged(KUrl
, Qt::MouseButtons
)),
1596 this, SLOT(handlePlacesClick(KUrl
, Qt::MouseButtons
)));
1597 connect(this, SIGNAL(urlChanged(KUrl
)),
1598 placesPanel
, SLOT(setUrl(KUrl
)));
1600 KActionMenu
* panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Panels"), this);
1601 actionCollection()->addAction("panels", panelsMenu
);
1602 panelsMenu
->setDelayed(false);
1603 panelsMenu
->addAction(placesAction
);
1604 panelsMenu
->addAction(infoAction
);
1605 panelsMenu
->addAction(foldersAction
);
1607 panelsMenu
->addAction(terminalAction
);
1611 void DolphinMainWindow::updateEditActions()
1613 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1614 if (list
.isEmpty()) {
1615 stateChanged("has_no_selection");
1617 stateChanged("has_selection");
1619 KActionCollection
* col
= actionCollection();
1620 QAction
* renameAction
= col
->action("rename");
1621 QAction
* moveToTrashAction
= col
->action("move_to_trash");
1622 QAction
* deleteAction
= col
->action("delete");
1623 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
1624 QAction
* deleteWithTrashShortcut
= col
->action("delete_shortcut"); // see DolphinViewActionHandler
1626 KFileItemListProperties
capabilities(list
);
1627 const bool enableMoveToTrash
= capabilities
.isLocal() && capabilities
.supportsMoving();
1629 renameAction
->setEnabled(capabilities
.supportsMoving());
1630 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1631 deleteAction
->setEnabled(capabilities
.supportsDeleting());
1632 deleteWithTrashShortcut
->setEnabled(capabilities
.supportsDeleting() && !enableMoveToTrash
);
1633 cutAction
->setEnabled(capabilities
.supportsMoving());
1635 updatePasteAction();
1638 void DolphinMainWindow::updateViewActions()
1640 m_actionHandler
->updateViewActions();
1642 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1643 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
1645 updateSplitAction();
1647 QAction
* editableLocactionAction
= actionCollection()->action("editable_location");
1648 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
1649 editableLocactionAction
->setChecked(urlNavigator
->isUrlEditable());
1652 void DolphinMainWindow::updateGoActions()
1654 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
1655 const KUrl currentUrl
= m_activeViewContainer
->url();
1656 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
1659 void DolphinMainWindow::rememberClosedTab(int index
)
1661 KMenu
* tabsMenu
= m_recentTabsMenu
->menu();
1663 const QString primaryPath
= m_viewTab
[index
].primaryView
->url().path();
1664 const QString iconName
= KMimeType::iconNameForUrl(primaryPath
);
1666 QAction
* action
= new QAction(squeezedText(primaryPath
), tabsMenu
);
1668 ClosedTab closedTab
;
1669 closedTab
.primaryUrl
= m_viewTab
[index
].primaryView
->url();
1671 if (m_viewTab
[index
].secondaryView
!= 0) {
1672 closedTab
.secondaryUrl
= m_viewTab
[index
].secondaryView
->url();
1673 closedTab
.isSplit
= true;
1675 closedTab
.isSplit
= false;
1678 action
->setData(QVariant::fromValue(closedTab
));
1679 action
->setIcon(KIcon(iconName
));
1681 // add the closed tab menu entry after the separator and
1682 // "Empty Recently Closed Tabs" entry
1683 if (tabsMenu
->actions().size() == 2) {
1684 tabsMenu
->addAction(action
);
1686 tabsMenu
->insertAction(tabsMenu
->actions().at(2), action
);
1689 // assure that only up to 8 closed tabs are shown in the menu
1690 if (tabsMenu
->actions().size() > 8) {
1691 tabsMenu
->removeAction(tabsMenu
->actions().last());
1693 actionCollection()->action("closed_tabs")->setEnabled(true);
1694 KAcceleratorManager::manage(tabsMenu
);
1697 void DolphinMainWindow::clearStatusBar()
1699 m_activeViewContainer
->statusBar()->clear();
1702 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
1704 connect(container
, SIGNAL(showFilterBarChanged(bool)),
1705 this, SLOT(updateFilterBarAction(bool)));
1706 connect(container
, SIGNAL(writeStateChanged(bool)),
1707 this, SLOT(slotWriteStateChanged(bool)));
1709 DolphinView
* view
= container
->view();
1710 connect(view
, SIGNAL(selectionChanged(KFileItemList
)),
1711 this, SLOT(slotSelectionChanged(KFileItemList
)));
1712 connect(view
, SIGNAL(requestItemInfo(KFileItem
)),
1713 this, SLOT(slotRequestItemInfo(KFileItem
)));
1714 connect(view
, SIGNAL(activated()),
1715 this, SLOT(toggleActiveView()));
1716 connect(view
, SIGNAL(tabRequested(const KUrl
&)),
1717 this, SLOT(openNewTab(const KUrl
&)));
1718 connect(view
, SIGNAL(requestContextMenu(KFileItem
, const KUrl
&, const QList
<QAction
*>&)),
1719 this, SLOT(openContextMenu(KFileItem
, const KUrl
&, const QList
<QAction
*>&)));
1720 connect(view
, SIGNAL(startedPathLoading(KUrl
)),
1721 this, SLOT(enableStopAction()));
1722 connect(view
, SIGNAL(finishedPathLoading(KUrl
)),
1723 this, SLOT(disableStopAction()));
1725 const KUrlNavigator
* navigator
= container
->urlNavigator();
1726 connect(navigator
, SIGNAL(urlChanged(const KUrl
&)),
1727 this, SLOT(changeUrl(const KUrl
&)));
1728 connect(navigator
, SIGNAL(historyChanged()),
1729 this, SLOT(updateHistory()));
1730 connect(navigator
, SIGNAL(editableStateChanged(bool)),
1731 this, SLOT(slotEditableStateChanged(bool)));
1732 connect(navigator
, SIGNAL(tabRequested(const KUrl
&)),
1733 this, SLOT(openNewTab(KUrl
)));
1736 void DolphinMainWindow::updateSplitAction()
1738 QAction
* splitAction
= actionCollection()->action("split_view");
1739 if (m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
1740 if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
1741 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
1742 splitAction
->setToolTip(i18nc("@info", "Close right view"));
1743 splitAction
->setIcon(KIcon("view-right-close"));
1745 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
1746 splitAction
->setToolTip(i18nc("@info", "Close left view"));
1747 splitAction
->setIcon(KIcon("view-left-close"));
1750 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
1751 splitAction
->setToolTip(i18nc("@info", "Split view"));
1752 splitAction
->setIcon(KIcon("view-right-new"));
1756 QString
DolphinMainWindow::tabName(const KUrl
& url
) const
1759 if (url
.equals(KUrl("file:///"))) {
1762 name
= url
.fileName();
1763 if (name
.isEmpty()) {
1764 name
= url
.protocol();
1766 // Make sure that a '&' inside the directory name is displayed correctly
1767 // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
1768 name
.replace('&', "&&");
1774 bool DolphinMainWindow::isKompareInstalled() const
1776 static bool initialized
= false;
1777 static bool installed
= false;
1779 // TODO: maybe replace this approach later by using a menu
1780 // plugin like kdiff3plugin.cpp
1781 installed
= !KGlobal::dirs()->findExe("kompare").isEmpty();
1787 void DolphinMainWindow::createSecondaryView(int tabIndex
)
1789 QSplitter
* splitter
= m_viewTab
[tabIndex
].splitter
;
1790 const int newWidth
= (m_viewTab
[tabIndex
].primaryView
->width() - splitter
->handleWidth()) / 2;
1792 const DolphinView
* view
= m_viewTab
[tabIndex
].primaryView
->view();
1793 m_viewTab
[tabIndex
].secondaryView
= new DolphinViewContainer(view
->rootUrl(), 0);
1794 splitter
->addWidget(m_viewTab
[tabIndex
].secondaryView
);
1795 splitter
->setSizes(QList
<int>() << newWidth
<< newWidth
);
1796 connectViewSignals(m_viewTab
[tabIndex
].secondaryView
);
1797 m_viewTab
[tabIndex
].secondaryView
->view()->reload();
1798 m_viewTab
[tabIndex
].secondaryView
->setActive(false);
1799 m_viewTab
[tabIndex
].secondaryView
->show();
1802 QString
DolphinMainWindow::tabProperty(const QString
& property
, int tabIndex
) const
1804 return "Tab " + QString::number(tabIndex
) + ' ' + property
;
1807 void DolphinMainWindow::setUrlAsCaption(const KUrl
& url
)
1810 if (!url
.isLocalFile()) {
1811 caption
.append(url
.protocol() + " - ");
1812 if (url
.hasHost()) {
1813 caption
.append(url
.host() + " - ");
1817 const QString fileName
= url
.fileName().isEmpty() ? "/" : url
.fileName();
1818 caption
.append(fileName
);
1820 setCaption(caption
);
1823 QString
DolphinMainWindow::squeezedText(const QString
& text
) const
1825 const QFontMetrics fm
= fontMetrics();
1826 return fm
.elidedText(text
, Qt::ElideMiddle
, fm
.maxWidth() * 10);
1829 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
1830 KIO::FileUndoManager::UiInterface()
1834 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
1838 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
1840 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
1842 DolphinStatusBar
* statusBar
= mainWin
->activeViewContainer()->statusBar();
1843 statusBar
->setMessage(job
->errorString(), DolphinStatusBar::Error
);
1845 KIO::FileUndoManager::UiInterface::jobError(job
);
1849 #include "dolphinmainwindow.moc"