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
.isEmpty()) {
466 openNewTab(m_activeViewContainer
->url());
467 } else if ((list
.count() == 1) && list
[0].isDir()) {
468 openNewTab(m_activeViewContainer
->view()->selectedUrls()[0]);
472 void DolphinMainWindow::openInNewWindow()
476 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
477 if (list
.isEmpty()) {
478 newWindowUrl
= m_activeViewContainer
->url();
479 } else if ((list
.count() == 1) && list
[0].isDir()) {
480 newWindowUrl
= m_activeViewContainer
->view()->selectedUrls()[0];
483 if (!newWindowUrl
.isEmpty()) {
484 DolphinMainWindow
* window
= DolphinApplication::app()->createMainWindow();
485 window
->changeUrl(newWindowUrl
);
490 void DolphinMainWindow::toggleActiveView()
492 if (m_viewTab
[m_tabIndex
].secondaryView
== 0) {
493 // only one view is available
497 Q_ASSERT(m_activeViewContainer
!= 0);
498 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
500 DolphinViewContainer
* left
= m_viewTab
[m_tabIndex
].primaryView
;
501 DolphinViewContainer
* right
= m_viewTab
[m_tabIndex
].secondaryView
;
502 setActiveViewContainer(m_activeViewContainer
== right
? left
: right
);
505 void DolphinMainWindow::showEvent(QShowEvent
* event
)
507 KXmlGuiWindow::showEvent(event
);
508 if (!event
->spontaneous()) {
509 m_activeViewContainer
->view()->setFocus();
513 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
515 DolphinSettings
& settings
= DolphinSettings::instance();
516 GeneralSettings
* generalSettings
= settings
.generalSettings();
518 // Find out if Dolphin is closed directly by the user or
519 // by the session manager because the session is closed
520 bool closedByUser
= true;
521 DolphinApplication
*application
= qobject_cast
<DolphinApplication
*>(qApp
);
522 if (application
&& application
->sessionSaving()) {
523 closedByUser
= false;
526 if ((m_viewTab
.count() > 1) && generalSettings
->confirmClosingMultipleTabs() && closedByUser
) {
527 // Ask the user if he really wants to quit and close all tabs.
528 // Open a confirmation dialog with 3 buttons:
529 // KDialog::Yes -> Quit
530 // KDialog::No -> Close only the current tab
531 // KDialog::Cancel -> do nothing
532 KDialog
*dialog
= new KDialog(this, Qt::Dialog
);
533 dialog
->setCaption(i18nc("@title:window", "Confirmation"));
534 dialog
->setButtons(KDialog::Yes
| KDialog::No
| KDialog::Cancel
);
535 dialog
->setModal(true);
536 dialog
->setButtonGuiItem(KDialog::Yes
, KStandardGuiItem::quit());
537 dialog
->setButtonGuiItem(KDialog::No
, KGuiItem(i18n("C&lose Current Tab"), KIcon("tab-close")));
538 dialog
->setButtonGuiItem(KDialog::Cancel
, KStandardGuiItem::cancel());
539 dialog
->setDefaultButton(KDialog::Yes
);
541 bool doNotAskAgainCheckboxResult
= false;
543 const int result
= KMessageBox::createKMessageBox(dialog
,
544 QMessageBox::Warning
,
545 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
547 i18n("Do not ask again"),
548 &doNotAskAgainCheckboxResult
,
549 KMessageBox::Notify
);
551 if (doNotAskAgainCheckboxResult
) {
552 generalSettings
->setConfirmClosingMultipleTabs(false);
560 // Close only the current tab
568 generalSettings
->setFirstRun(false);
572 KXmlGuiWindow::closeEvent(event
);
575 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
577 const int tabCount
= m_viewTab
.count();
578 group
.writeEntry("Tab Count", tabCount
);
579 group
.writeEntry("Active Tab Index", m_tabBar
->currentIndex());
581 for (int i
= 0; i
< tabCount
; ++i
) {
582 const DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
583 group
.writeEntry(tabProperty("Primary URL", i
), cont
->url().url());
584 group
.writeEntry(tabProperty("Primary Editable", i
),
585 cont
->urlNavigator()->isUrlEditable());
587 cont
= m_viewTab
[i
].secondaryView
;
589 group
.writeEntry(tabProperty("Secondary URL", i
), cont
->url().url());
590 group
.writeEntry(tabProperty("Secondary Editable", i
),
591 cont
->urlNavigator()->isUrlEditable());
596 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
598 const int tabCount
= group
.readEntry("Tab Count", 1);
599 for (int i
= 0; i
< tabCount
; ++i
) {
600 DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
602 cont
->setUrl(group
.readEntry(tabProperty("Primary URL", i
)));
603 const bool editable
= group
.readEntry(tabProperty("Primary Editable", i
), false);
604 cont
->urlNavigator()->setUrlEditable(editable
);
606 cont
= m_viewTab
[i
].secondaryView
;
607 const QString secondaryUrl
= group
.readEntry(tabProperty("Secondary URL", i
));
608 if (!secondaryUrl
.isEmpty()) {
610 // a secondary view should be shown, but no one is available
611 // currently -> create a new view
613 cont
= m_viewTab
[i
].secondaryView
;
617 cont
->setUrl(secondaryUrl
);
618 const bool editable
= group
.readEntry(tabProperty("Secondary Editable", i
), false);
619 cont
->urlNavigator()->setUrlEditable(editable
);
620 } else if (cont
!= 0) {
621 // no secondary view should be shown, but the default setting shows
622 // one already -> close the view
626 // openNewTab() needs to be called only tabCount - 1 times
627 if (i
!= tabCount
- 1) {
632 const int index
= group
.readEntry("Active Tab Index", 0);
633 m_tabBar
->setCurrentIndex(index
);
636 void DolphinMainWindow::updateNewMenu()
638 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->showHiddenFiles());
639 m_newFileMenu
->checkUpToDate();
640 m_newFileMenu
->setPopupFiles(activeViewContainer()->url());
643 void DolphinMainWindow::createDirectory()
645 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->showHiddenFiles());
646 m_newFileMenu
->setPopupFiles(activeViewContainer()->url());
647 m_newFileMenu
->createDirectory();
650 void DolphinMainWindow::quit()
655 void DolphinMainWindow::showErrorMessage(const QString
& message
)
657 if (!message
.isEmpty()) {
658 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
659 statusBar
->setMessage(message
, DolphinStatusBar::Error
);
663 void DolphinMainWindow::slotUndoAvailable(bool available
)
665 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
666 if (undoAction
!= 0) {
667 undoAction
->setEnabled(available
);
671 void DolphinMainWindow::restoreClosedTab(QAction
* action
)
673 if (action
->data().toBool()) {
674 // clear all actions except the "Empty Recently Closed Tabs"
675 // action and the separator
676 QList
<QAction
*> actions
= m_recentTabsMenu
->menu()->actions();
677 const int count
= actions
.size();
678 for (int i
= 2; i
< count
; ++i
) {
679 m_recentTabsMenu
->menu()->removeAction(actions
.at(i
));
682 const ClosedTab closedTab
= action
->data().value
<ClosedTab
>();
683 openNewTab(closedTab
.primaryUrl
);
684 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
686 if (closedTab
.isSplit
) {
687 // create secondary view
689 m_viewTab
[m_tabIndex
].secondaryView
->setUrl(closedTab
.secondaryUrl
);
692 m_recentTabsMenu
->removeAction(action
);
695 if (m_recentTabsMenu
->menu()->actions().count() == 2) {
696 m_recentTabsMenu
->setEnabled(false);
700 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
702 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
703 if (undoAction
!= 0) {
704 undoAction
->setText(text
);
708 void DolphinMainWindow::undo()
711 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
712 KIO::FileUndoManager::self()->undo();
715 void DolphinMainWindow::cut()
717 m_activeViewContainer
->view()->cutSelectedItems();
720 void DolphinMainWindow::copy()
722 m_activeViewContainer
->view()->copySelectedItems();
725 void DolphinMainWindow::paste()
727 m_activeViewContainer
->view()->paste();
730 void DolphinMainWindow::find()
732 m_activeViewContainer
->setSearchModeEnabled(true);
735 void DolphinMainWindow::updatePasteAction()
737 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
738 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
739 pasteAction
->setEnabled(pasteInfo
.first
);
740 pasteAction
->setText(pasteInfo
.second
);
743 void DolphinMainWindow::selectAll()
747 // if the URL navigator is editable and focused, select the whole
748 // URL instead of all items of the view
750 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
751 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit(); // krazy:exclude=qclasses
752 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
753 lineEdit
->hasFocus();
755 lineEdit
->selectAll();
757 m_activeViewContainer
->view()->selectAll();
761 void DolphinMainWindow::invertSelection()
764 m_activeViewContainer
->view()->invertSelection();
767 void DolphinMainWindow::toggleSplitView()
769 if (m_viewTab
[m_tabIndex
].secondaryView
== 0) {
770 createSecondaryView(m_tabIndex
);
771 setActiveViewContainer(m_viewTab
[m_tabIndex
].secondaryView
);
772 } else if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
773 // remove secondary view
774 m_viewTab
[m_tabIndex
].secondaryView
->close();
775 m_viewTab
[m_tabIndex
].secondaryView
->deleteLater();
776 m_viewTab
[m_tabIndex
].secondaryView
= 0;
778 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
780 // The primary view is active and should be closed. Hence from a users point of view
781 // the content of the secondary view should be moved to the primary view.
782 // From an implementation point of view it is more efficient to close
783 // the primary view and exchange the internal pointers afterwards.
785 m_viewTab
[m_tabIndex
].primaryView
->close();
786 m_viewTab
[m_tabIndex
].primaryView
->deleteLater();
787 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
788 m_viewTab
[m_tabIndex
].secondaryView
= 0;
790 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
796 void DolphinMainWindow::reloadView()
799 m_activeViewContainer
->view()->reload();
802 void DolphinMainWindow::stopLoading()
804 m_activeViewContainer
->view()->stopLoading();
807 void DolphinMainWindow::enableStopAction()
809 actionCollection()->action("stop")->setEnabled(true);
812 void DolphinMainWindow::disableStopAction()
814 actionCollection()->action("stop")->setEnabled(false);
817 void DolphinMainWindow::toggleFilterBarVisibility(bool show
)
819 m_activeViewContainer
->showFilterBar(show
);
822 void DolphinMainWindow::toggleEditLocation()
826 QAction
* action
= actionCollection()->action("editable_location");
827 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
828 urlNavigator
->setUrlEditable(action
->isChecked());
831 void DolphinMainWindow::replaceLocation()
833 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
834 navigator
->setUrlEditable(true);
835 navigator
->setFocus();
837 // select the whole text of the combo box editor
838 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit(); // krazy:exclude=qclasses
839 const QString text
= lineEdit
->text();
840 lineEdit
->setSelection(0, text
.length());
843 void DolphinMainWindow::goBack()
847 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
848 urlNavigator
->goBack();
850 if (urlNavigator
->locationState().isEmpty()) {
851 // An empty location state indicates a redirection URL,
852 // which must be skipped too
853 urlNavigator
->goBack();
857 void DolphinMainWindow::goForward()
860 m_activeViewContainer
->urlNavigator()->goForward();
863 void DolphinMainWindow::goUp()
866 m_activeViewContainer
->urlNavigator()->goUp();
869 void DolphinMainWindow::goBack(Qt::MouseButtons buttons
)
871 // The default case (left button pressed) is handled in goBack().
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::goForward(Qt::MouseButtons buttons
)
881 // The default case (left button pressed) is handled in goForward().
882 if (buttons
== Qt::MidButton
) {
883 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
884 const int index
= urlNavigator
->historyIndex() - 1;
885 openNewTab(urlNavigator
->locationUrl(index
));
889 void DolphinMainWindow::goUp(Qt::MouseButtons buttons
)
891 // The default case (left button pressed) is handled in goUp().
892 if (buttons
== Qt::MidButton
) {
893 openNewTab(activeViewContainer()->url().upUrl());
897 void DolphinMainWindow::goHome()
900 m_activeViewContainer
->urlNavigator()->goHome();
903 void DolphinMainWindow::compareFiles()
905 // The method is only invoked if exactly 2 files have
906 // been selected. The selected files may be:
907 // - both in the primary view
908 // - both in the secondary view
909 // - one in the primary view and the other in the secondary
911 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
915 KUrl::List urls
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedUrls();
917 switch (urls
.count()) {
919 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
!= 0);
920 urls
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedUrls();
921 Q_ASSERT(urls
.count() == 2);
929 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
!= 0);
930 urls
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedUrls();
931 Q_ASSERT(urls
.count() == 1);
943 // may not happen: compareFiles may only get invoked if 2
944 // files are selected
949 QString
command("kompare -c \"");
950 command
.append(urlA
.pathOrUrl());
951 command
.append("\" \"");
952 command
.append(urlB
.pathOrUrl());
953 command
.append('\"');
954 KRun::runCommand(command
, "Kompare", "kompare", this);
957 void DolphinMainWindow::toggleShowMenuBar()
959 const bool visible
= menuBar()->isVisible();
960 menuBar()->setVisible(!visible
);
963 void DolphinMainWindow::openTerminal()
965 QString
dir(QDir::homePath());
967 // If the given directory is not local, it can still be the URL of an
968 // ioslave using UDS_LOCAL_PATH which to be converted first.
969 KUrl url
= KIO::NetAccess::mostLocalUrl(m_activeViewContainer
->url(), this);
971 //If the URL is local after the above conversion, set the directory.
972 if (url
.isLocalFile()) {
973 dir
= url
.toLocalFile();
976 KToolInvocation::invokeTerminal(QString(), dir
);
979 void DolphinMainWindow::editSettings()
981 if (m_settingsDialog
== 0) {
982 const KUrl url
= activeViewContainer()->url();
983 m_settingsDialog
= new DolphinSettingsDialog(url
, this);
984 m_settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
985 m_settingsDialog
->show();
987 m_settingsDialog
->raise();
991 void DolphinMainWindow::setActiveTab(int index
)
993 Q_ASSERT(index
>= 0);
994 Q_ASSERT(index
< m_viewTab
.count());
995 if (index
== m_tabIndex
) {
999 // hide current tab content
1000 ViewTab
& hiddenTab
= m_viewTab
[m_tabIndex
];
1001 hiddenTab
.isPrimaryViewActive
= hiddenTab
.primaryView
->isActive();
1002 hiddenTab
.primaryView
->setActive(false);
1003 if (hiddenTab
.secondaryView
!= 0) {
1004 hiddenTab
.secondaryView
->setActive(false);
1006 QSplitter
* splitter
= m_viewTab
[m_tabIndex
].splitter
;
1008 m_centralWidgetLayout
->removeWidget(splitter
);
1010 // show active tab content
1013 ViewTab
& viewTab
= m_viewTab
[index
];
1014 m_centralWidgetLayout
->addWidget(viewTab
.splitter
, 1);
1015 viewTab
.primaryView
->show();
1016 if (viewTab
.secondaryView
!= 0) {
1017 viewTab
.secondaryView
->show();
1019 viewTab
.splitter
->show();
1021 setActiveViewContainer(viewTab
.isPrimaryViewActive
? viewTab
.primaryView
:
1022 viewTab
.secondaryView
);
1025 void DolphinMainWindow::closeTab()
1027 closeTab(m_tabBar
->currentIndex());
1030 void DolphinMainWindow::closeTab(int index
)
1032 Q_ASSERT(index
>= 0);
1033 Q_ASSERT(index
< m_viewTab
.count());
1034 if (m_viewTab
.count() == 1) {
1035 // the last tab may never get closed
1039 if (index
== m_tabIndex
) {
1040 // The tab that should be closed is the active tab. Activate the
1041 // previous tab before closing the tab.
1042 m_tabBar
->setCurrentIndex((index
> 0) ? index
- 1 : 1);
1044 rememberClosedTab(index
);
1047 m_viewTab
[index
].primaryView
->deleteLater();
1048 if (m_viewTab
[index
].secondaryView
!= 0) {
1049 m_viewTab
[index
].secondaryView
->deleteLater();
1051 m_viewTab
[index
].splitter
->deleteLater();
1052 m_viewTab
.erase(m_viewTab
.begin() + index
);
1054 m_tabBar
->blockSignals(true);
1055 m_tabBar
->removeTab(index
);
1057 if (m_tabIndex
> index
) {
1059 Q_ASSERT(m_tabIndex
>= 0);
1062 // if only one tab is left, also remove the tab entry so that
1063 // closing the last tab is not possible
1064 if (m_viewTab
.count() == 1) {
1065 m_tabBar
->removeTab(0);
1066 actionCollection()->action("close_tab")->setEnabled(false);
1068 m_tabBar
->blockSignals(false);
1072 void DolphinMainWindow::openTabContextMenu(int index
, const QPoint
& pos
)
1076 QAction
* newTabAction
= menu
.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab"));
1077 newTabAction
->setShortcut(actionCollection()->action("new_tab")->shortcut());
1079 QAction
* detachTabAction
= menu
.addAction(KIcon("tab-detach"), i18nc("@action:inmenu", "Detach Tab"));
1081 QAction
* closeOtherTabsAction
= menu
.addAction(KIcon("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs"));
1083 QAction
* closeTabAction
= menu
.addAction(KIcon("tab-close"), i18nc("@action:inmenu", "Close Tab"));
1084 closeTabAction
->setShortcut(actionCollection()->action("close_tab")->shortcut());
1085 QAction
* selectedAction
= menu
.exec(pos
);
1086 if (selectedAction
== newTabAction
) {
1087 const ViewTab
& tab
= m_viewTab
[index
];
1088 Q_ASSERT(tab
.primaryView
!= 0);
1089 const KUrl url
= (tab
.secondaryView
!= 0) && tab
.secondaryView
->isActive() ?
1090 tab
.secondaryView
->url() : tab
.primaryView
->url();
1092 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
1093 } else if (selectedAction
== detachTabAction
) {
1094 const ViewTab
& tab
= m_viewTab
[index
];
1095 Q_ASSERT(tab
.primaryView
!= 0);
1096 const KUrl primaryUrl
= tab
.primaryView
->url();
1097 DolphinMainWindow
* window
= DolphinApplication::app()->createMainWindow();
1098 window
->changeUrl(primaryUrl
);
1100 if (tab
.secondaryView
!= 0) {
1101 const KUrl secondaryUrl
= tab
.secondaryView
->url();
1102 window
->toggleSplitView();
1103 window
->m_viewTab
[0].secondaryView
->setUrl(secondaryUrl
);
1104 if (tab
.primaryView
->isActive()) {
1105 window
->m_viewTab
[0].primaryView
->setActive(true);
1107 window
->m_viewTab
[0].secondaryView
->setActive(true);
1112 } else if (selectedAction
== closeOtherTabsAction
) {
1113 const int count
= m_tabBar
->count();
1114 for (int i
= 0; i
< index
; ++i
) {
1117 for (int i
= index
+ 1; i
< count
; ++i
) {
1120 } else if (selectedAction
== closeTabAction
) {
1125 void DolphinMainWindow::slotTabMoved(int from
, int to
)
1127 m_viewTab
.move(from
, to
);
1128 m_tabIndex
= m_tabBar
->currentIndex();
1131 void DolphinMainWindow::handlePlacesClick(const KUrl
& url
, Qt::MouseButtons buttons
)
1133 if (buttons
& Qt::MidButton
) {
1135 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
1141 void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent
* event
, bool& canDecode
)
1143 canDecode
= KUrl::List::canDecode(event
->mimeData());
1146 void DolphinMainWindow::handleUrl(const KUrl
& url
)
1148 delete m_lastHandleUrlStatJob
;
1149 m_lastHandleUrlStatJob
= 0;
1151 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1152 activeViewContainer()->setUrl(url
);
1153 } else if (KProtocolManager::supportsListing(url
)) {
1154 // stat the URL to see if it is a dir or not
1155 m_lastHandleUrlStatJob
= KIO::stat(url
, KIO::HideProgressInfo
);
1156 connect(m_lastHandleUrlStatJob
, SIGNAL(result(KJob
*)),
1157 this, SLOT(slotHandleUrlStatFinished(KJob
*)));
1160 new KRun(url
, this);
1164 void DolphinMainWindow::slotHandleUrlStatFinished(KJob
* job
)
1166 m_lastHandleUrlStatJob
= 0;
1167 const KIO::UDSEntry entry
= static_cast<KIO::StatJob
*>(job
)->statResult();
1168 const KUrl url
= static_cast<KIO::StatJob
*>(job
)->url();
1169 if ( entry
.isDir() ) {
1170 activeViewContainer()->setUrl(url
);
1172 new KRun(url
, this);
1176 void DolphinMainWindow::tabDropEvent(int tab
, QDropEvent
* event
)
1178 const KUrl::List urls
= KUrl::List::fromMimeData(event
->mimeData());
1179 if (!urls
.isEmpty() && tab
!= -1) {
1180 const ViewTab
& viewTab
= m_viewTab
[tab
];
1181 const KUrl destPath
= viewTab
.isPrimaryViewActive
? viewTab
.primaryView
->url() : viewTab
.secondaryView
->url();
1182 DragAndDropHelper::instance().dropUrls(KFileItem(), destPath
, event
, m_tabBar
);
1186 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1188 newFileMenu()->setEnabled(isFolderWritable
);
1191 void DolphinMainWindow::openContextMenu(const KFileItem
& item
,
1193 const QList
<QAction
*>& customActions
)
1195 DolphinContextMenu
contextMenu(this, item
, url
);
1196 contextMenu
.setCustomActions(customActions
);
1197 const DolphinContextMenu::Command command
= contextMenu
.open();
1200 case DolphinContextMenu::OpenParentFolderInNewWindow
: {
1201 DolphinMainWindow
* window
= DolphinApplication::app()->createMainWindow();
1202 window
->changeUrl(item
.url().upUrl());
1207 case DolphinContextMenu::OpenParentFolderInNewTab
:
1208 openNewTab(item
.url().upUrl());
1211 case DolphinContextMenu::None
:
1217 void DolphinMainWindow::init()
1219 DolphinSettings
& settings
= DolphinSettings::instance();
1221 // Check whether Dolphin runs the first time. If yes then
1222 // a proper default window size is given at the end of DolphinMainWindow::init().
1223 GeneralSettings
* generalSettings
= settings
.generalSettings();
1224 const bool firstRun
= generalSettings
->firstRun();
1226 generalSettings
->setViewPropsTimestamp(QDateTime::currentDateTime());
1229 setAcceptDrops(true);
1231 m_viewTab
[m_tabIndex
].splitter
= new QSplitter(this);
1232 m_viewTab
[m_tabIndex
].splitter
->setChildrenCollapsible(false);
1236 const KUrl
homeUrl(generalSettings
->homeUrl());
1237 setUrlAsCaption(homeUrl
);
1238 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
1239 connect(m_actionHandler
, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
1240 connect(m_actionHandler
, SIGNAL(createDirectory()), SLOT(createDirectory()));
1241 ViewProperties
props(homeUrl
);
1242 m_viewTab
[m_tabIndex
].primaryView
= new DolphinViewContainer(homeUrl
,
1243 m_viewTab
[m_tabIndex
].splitter
);
1245 m_activeViewContainer
= m_viewTab
[m_tabIndex
].primaryView
;
1246 connectViewSignals(m_activeViewContainer
);
1247 DolphinView
* view
= m_activeViewContainer
->view();
1249 m_activeViewContainer
->show();
1250 m_actionHandler
->setCurrentView(view
);
1252 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
1253 connect(this, SIGNAL(urlChanged(const KUrl
&)),
1254 m_remoteEncoding
, SLOT(slotAboutToOpenUrl()));
1256 m_tabBar
= new KTabBar(this);
1257 m_tabBar
->setMovable(true);
1258 m_tabBar
->setTabsClosable(true);
1259 connect(m_tabBar
, SIGNAL(currentChanged(int)),
1260 this, SLOT(setActiveTab(int)));
1261 connect(m_tabBar
, SIGNAL(tabCloseRequested(int)),
1262 this, SLOT(closeTab(int)));
1263 connect(m_tabBar
, SIGNAL(contextMenu(int, const QPoint
&)),
1264 this, SLOT(openTabContextMenu(int, const QPoint
&)));
1265 connect(m_tabBar
, SIGNAL(newTabRequest()),
1266 this, SLOT(openNewTab()));
1267 connect(m_tabBar
, SIGNAL(testCanDecode(const QDragMoveEvent
*, bool&)),
1268 this, SLOT(slotTestCanDecode(const QDragMoveEvent
*, bool&)));
1269 connect(m_tabBar
, SIGNAL(mouseMiddleClick(int)),
1270 this, SLOT(closeTab(int)));
1271 connect(m_tabBar
, SIGNAL(tabMoved(int, int)),
1272 this, SLOT(slotTabMoved(int, int)));
1273 connect(m_tabBar
, SIGNAL(receivedDropEvent(int, QDropEvent
*)),
1274 this, SLOT(tabDropEvent(int, QDropEvent
*)));
1276 m_tabBar
->blockSignals(true); // signals get unblocked after at least 2 tabs are open
1278 QWidget
* centralWidget
= new QWidget(this);
1279 m_centralWidgetLayout
= new QVBoxLayout(centralWidget
);
1280 m_centralWidgetLayout
->setSpacing(0);
1281 m_centralWidgetLayout
->setMargin(0);
1282 m_centralWidgetLayout
->addWidget(m_tabBar
);
1283 m_centralWidgetLayout
->addWidget(m_viewTab
[m_tabIndex
].splitter
, 1);
1285 setCentralWidget(centralWidget
);
1287 emit
urlChanged(homeUrl
);
1289 setupGUI(Keys
| Save
| Create
| ToolBar
);
1290 stateChanged("new_file");
1292 QClipboard
* clipboard
= QApplication::clipboard();
1293 connect(clipboard
, SIGNAL(dataChanged()),
1294 this, SLOT(updatePasteAction()));
1296 if (generalSettings
->splitView()) {
1299 updateEditActions();
1300 updateViewActions();
1303 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1304 showFilterBarAction
->setChecked(generalSettings
->filterBar());
1307 // assure a proper default size if Dolphin runs the first time
1311 m_showMenuBar
->setChecked(!menuBar()->isHidden()); // workaround for bug #171080
1314 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer
* viewContainer
)
1316 Q_ASSERT(viewContainer
!= 0);
1317 Q_ASSERT((viewContainer
== m_viewTab
[m_tabIndex
].primaryView
) ||
1318 (viewContainer
== m_viewTab
[m_tabIndex
].secondaryView
));
1319 if (m_activeViewContainer
== viewContainer
) {
1323 m_activeViewContainer
->setActive(false);
1324 m_activeViewContainer
= viewContainer
;
1326 // Activating the view container might trigger a recursive setActiveViewContainer() call
1327 // inside DolphinMainWindow::toggleActiveView() when having a split view. Temporary
1328 // disconnect the activated() signal in this case:
1329 disconnect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1330 m_activeViewContainer
->setActive(true);
1331 connect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1333 m_actionHandler
->setCurrentView(viewContainer
->view());
1336 updateEditActions();
1337 updateViewActions();
1340 const KUrl url
= m_activeViewContainer
->url();
1341 setUrlAsCaption(url
);
1342 if (m_viewTab
.count() > 1) {
1343 m_tabBar
->setTabText(m_tabIndex
, tabName(url
));
1344 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(KMimeType::iconNameForUrl(url
)));
1347 emit
urlChanged(url
);
1350 void DolphinMainWindow::setupActions()
1352 // setup 'File' menu
1353 m_newFileMenu
= new DolphinNewFileMenu(this, this);
1354 KMenu
* menu
= m_newFileMenu
->menu();
1355 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1356 menu
->setIcon(KIcon("document-new"));
1357 connect(menu
, SIGNAL(aboutToShow()),
1358 this, SLOT(updateNewMenu()));
1360 KAction
* newWindow
= actionCollection()->addAction("new_window");
1361 newWindow
->setIcon(KIcon("window-new"));
1362 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1363 newWindow
->setShortcut(Qt::CTRL
| Qt::Key_N
);
1364 connect(newWindow
, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1366 KAction
* newTab
= actionCollection()->addAction("new_tab");
1367 newTab
->setIcon(KIcon("tab-new"));
1368 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1369 newTab
->setShortcut(KShortcut(Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
));
1370 connect(newTab
, SIGNAL(triggered()), this, SLOT(openNewTab()));
1372 KAction
* closeTab
= actionCollection()->addAction("close_tab");
1373 closeTab
->setIcon(KIcon("tab-close"));
1374 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1375 closeTab
->setShortcut(Qt::CTRL
| Qt::Key_W
);
1376 closeTab
->setEnabled(false);
1377 connect(closeTab
, SIGNAL(triggered()), this, SLOT(closeTab()));
1379 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1381 // setup 'Edit' menu
1382 KStandardAction::undo(this,
1384 actionCollection());
1386 // need to remove shift+del from cut action, else the shortcut for deletejob
1388 KAction
* cut
= KStandardAction::cut(this, SLOT(cut()), actionCollection());
1389 KShortcut cutShortcut
= cut
->shortcut();
1390 cutShortcut
.remove(Qt::SHIFT
+ Qt::Key_Delete
, KShortcut::KeepEmpty
);
1391 cut
->setShortcut(cutShortcut
);
1392 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1393 KAction
* paste
= KStandardAction::paste(this, SLOT(paste()), actionCollection());
1394 // The text of the paste-action is modified dynamically by Dolphin
1395 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1396 // due to the long text, the text "Paste" is used:
1397 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1399 KStandardAction::find(this, SLOT(find()), actionCollection());
1401 KAction
* selectAll
= actionCollection()->addAction("select_all");
1402 selectAll
->setText(i18nc("@action:inmenu Edit", "Select All"));
1403 selectAll
->setShortcut(Qt::CTRL
+ Qt::Key_A
);
1404 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
1406 KAction
* invertSelection
= actionCollection()->addAction("invert_selection");
1407 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1408 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1409 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
1411 // setup 'View' menu
1412 // (note that most of it is set up in DolphinViewActionHandler)
1414 KAction
* split
= actionCollection()->addAction("split_view");
1415 split
->setShortcut(Qt::Key_F3
);
1416 updateSplitAction();
1417 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1419 KAction
* reload
= actionCollection()->addAction("reload");
1420 reload
->setText(i18nc("@action:inmenu View", "Reload"));
1421 reload
->setShortcut(Qt::Key_F5
);
1422 reload
->setIcon(KIcon("view-refresh"));
1423 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
1425 KAction
* stop
= actionCollection()->addAction("stop");
1426 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1427 stop
->setToolTip(i18nc("@info", "Stop loading"));
1428 stop
->setIcon(KIcon("process-stop"));
1429 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
1431 KToggleAction
* showFullLocation
= actionCollection()->add
<KToggleAction
>("editable_location");
1432 showFullLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1433 showFullLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
1434 connect(showFullLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1436 KAction
* replaceLocation
= actionCollection()->addAction("replace_location");
1437 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1438 replaceLocation
->setShortcut(Qt::Key_F6
);
1439 connect(replaceLocation
, SIGNAL(triggered()), this, SLOT(replaceLocation()));
1442 KAction
* backAction
= KStandardAction::back(this, SLOT(goBack()), actionCollection());
1443 connect(backAction
, SIGNAL(triggered(Qt::MouseButtons
, Qt::KeyboardModifiers
)), this, SLOT(goBack(Qt::MouseButtons
)));
1444 KShortcut backShortcut
= backAction
->shortcut();
1445 backShortcut
.setAlternate(Qt::Key_Backspace
);
1446 backAction
->setShortcut(backShortcut
);
1448 m_recentTabsMenu
= new KActionMenu(i18n("Recently Closed Tabs"), this);
1449 m_recentTabsMenu
->setIcon(KIcon("edit-undo"));
1450 actionCollection()->addAction("closed_tabs", m_recentTabsMenu
);
1451 connect(m_recentTabsMenu
->menu(), SIGNAL(triggered(QAction
*)),
1452 this, SLOT(restoreClosedTab(QAction
*)));
1454 QAction
* action
= new QAction("Empty Recently Closed Tabs", m_recentTabsMenu
);
1455 action
->setIcon(KIcon("edit-clear-list"));
1456 action
->setData(QVariant::fromValue(true));
1457 m_recentTabsMenu
->addAction(action
);
1458 m_recentTabsMenu
->addSeparator();
1459 m_recentTabsMenu
->setEnabled(false);
1461 KAction
* forwardAction
= KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1462 connect(forwardAction
, SIGNAL(triggered(Qt::MouseButtons
, Qt::KeyboardModifiers
)), this, SLOT(goForward(Qt::MouseButtons
)));
1464 KAction
* upAction
= KStandardAction::up(this, SLOT(goUp()), actionCollection());
1465 connect(upAction
, SIGNAL(triggered(Qt::MouseButtons
, Qt::KeyboardModifiers
)), this, SLOT(goUp(Qt::MouseButtons
)));
1467 KStandardAction::home(this, SLOT(goHome()), actionCollection());
1469 // setup 'Tools' menu
1470 KToggleAction
* showFilterBar
= actionCollection()->add
<KToggleAction
>("show_filter_bar");
1471 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1472 showFilterBar
->setIcon(KIcon("view-filter"));
1473 showFilterBar
->setShortcut(Qt::CTRL
| Qt::Key_I
);
1474 connect(showFilterBar
, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
1476 KAction
* compareFiles
= actionCollection()->addAction("compare_files");
1477 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1478 compareFiles
->setIcon(KIcon("kompare"));
1479 compareFiles
->setEnabled(false);
1480 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
1482 KAction
* openTerminal
= actionCollection()->addAction("open_terminal");
1483 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1484 openTerminal
->setIcon(KIcon("utilities-terminal"));
1485 openTerminal
->setShortcut(Qt::SHIFT
| Qt::Key_F4
);
1486 connect(openTerminal
, SIGNAL(triggered()), this, SLOT(openTerminal()));
1488 // setup 'Settings' menu
1489 m_showMenuBar
= KStandardAction::showMenubar(this, SLOT(toggleShowMenuBar()), actionCollection());
1490 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1492 // not in menu actions
1493 QList
<QKeySequence
> nextTabKeys
;
1494 nextTabKeys
.append(KStandardShortcut::tabNext().primary());
1495 nextTabKeys
.append(QKeySequence(Qt::CTRL
+ Qt::Key_Tab
));
1497 QList
<QKeySequence
> prevTabKeys
;
1498 prevTabKeys
.append(KStandardShortcut::tabPrev().primary());
1499 prevTabKeys
.append(QKeySequence(Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_Tab
));
1501 KAction
* activateNextTab
= actionCollection()->addAction("activate_next_tab");
1502 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1503 connect(activateNextTab
, SIGNAL(triggered()), SLOT(activateNextTab()));
1504 activateNextTab
->setShortcuts(QApplication::isRightToLeft() ? prevTabKeys
: nextTabKeys
);
1506 KAction
* activatePrevTab
= actionCollection()->addAction("activate_prev_tab");
1507 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1508 connect(activatePrevTab
, SIGNAL(triggered()), SLOT(activatePrevTab()));
1509 activatePrevTab
->setShortcuts(QApplication::isRightToLeft() ? nextTabKeys
: prevTabKeys
);
1512 KAction
* openInNewTab
= actionCollection()->addAction("open_in_new_tab");
1513 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1514 openInNewTab
->setIcon(KIcon("tab-new"));
1515 connect(openInNewTab
, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1517 KAction
* openInNewWindow
= actionCollection()->addAction("open_in_new_window");
1518 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1519 openInNewWindow
->setIcon(KIcon("window-new"));
1520 connect(openInNewWindow
, SIGNAL(triggered()), this, SLOT(openInNewWindow()));
1523 void DolphinMainWindow::setupDockWidgets()
1525 // setup "Information"
1526 QDockWidget
* infoDock
= new QDockWidget(i18nc("@title:window", "Information"));
1527 infoDock
->setObjectName("infoDock");
1528 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1529 Panel
* infoPanel
= new InformationPanel(infoDock
);
1530 connect(infoPanel
, SIGNAL(urlActivated(KUrl
)), this, SLOT(handleUrl(KUrl
)));
1531 infoDock
->setWidget(infoPanel
);
1533 QAction
* infoAction
= infoDock
->toggleViewAction();
1534 infoAction
->setIcon(KIcon("dialog-information"));
1535 infoAction
->setShortcut(Qt::Key_F11
);
1537 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1538 connect(this, SIGNAL(urlChanged(KUrl
)),
1539 infoPanel
, SLOT(setUrl(KUrl
)));
1540 connect(this, SIGNAL(selectionChanged(KFileItemList
)),
1541 infoPanel
, SLOT(setSelection(KFileItemList
)));
1542 connect(this, SIGNAL(requestItemInfo(KFileItem
)),
1543 infoPanel
, SLOT(requestDelayedItemInfo(KFileItem
)));
1546 QDockWidget
* foldersDock
= new QDockWidget(i18nc("@title:window", "Folders"));
1547 foldersDock
->setObjectName("foldersDock");
1548 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1549 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1550 foldersDock
->setWidget(foldersPanel
);
1552 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1553 foldersAction
->setShortcut(Qt::Key_F7
);
1554 foldersAction
->setIcon(KIcon("folder"));
1556 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1557 connect(this, SIGNAL(urlChanged(KUrl
)),
1558 foldersPanel
, SLOT(setUrl(KUrl
)));
1559 connect(foldersPanel
, SIGNAL(changeUrl(KUrl
, Qt::MouseButtons
)),
1560 this, SLOT(handlePlacesClick(KUrl
, Qt::MouseButtons
)));
1564 QDockWidget
* terminalDock
= new QDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1565 terminalDock
->setObjectName("terminalDock");
1566 terminalDock
->setAllowedAreas(Qt::TopDockWidgetArea
| Qt::BottomDockWidgetArea
);
1567 Panel
* terminalPanel
= new TerminalPanel(terminalDock
);
1568 terminalDock
->setWidget(terminalPanel
);
1570 connect(terminalPanel
, SIGNAL(hideTerminalPanel()), terminalDock
, SLOT(hide()));
1572 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1573 terminalAction
->setShortcut(Qt::Key_F4
);
1574 terminalAction
->setIcon(KIcon("utilities-terminal"));
1576 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1577 connect(this, SIGNAL(urlChanged(KUrl
)),
1578 terminalPanel
, SLOT(setUrl(KUrl
)));
1581 const bool firstRun
= DolphinSettings::instance().generalSettings()->firstRun();
1584 foldersDock
->hide();
1586 terminalDock
->hide();
1591 QDockWidget
* placesDock
= new QDockWidget(i18nc("@title:window", "Places"));
1592 placesDock
->setObjectName("placesDock");
1593 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1595 PlacesPanel
* placesPanel
= new PlacesPanel(placesDock
);
1596 placesDock
->setWidget(placesPanel
);
1597 placesPanel
->setModel(DolphinSettings::instance().placesModel());
1598 placesPanel
->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff
);
1600 QAction
* placesAction
= placesDock
->toggleViewAction();
1601 placesAction
->setShortcut(Qt::Key_F9
);
1602 placesAction
->setIcon(KIcon("bookmarks"));
1604 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1605 connect(placesPanel
, SIGNAL(urlChanged(KUrl
, Qt::MouseButtons
)),
1606 this, SLOT(handlePlacesClick(KUrl
, Qt::MouseButtons
)));
1607 connect(this, SIGNAL(urlChanged(KUrl
)),
1608 placesPanel
, SLOT(setUrl(KUrl
)));
1610 KActionMenu
* panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Panels"), this);
1611 actionCollection()->addAction("panels", panelsMenu
);
1612 panelsMenu
->setDelayed(false);
1613 panelsMenu
->addAction(placesAction
);
1614 panelsMenu
->addAction(infoAction
);
1615 panelsMenu
->addAction(foldersAction
);
1617 panelsMenu
->addAction(terminalAction
);
1621 void DolphinMainWindow::updateEditActions()
1623 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1624 if (list
.isEmpty()) {
1625 stateChanged("has_no_selection");
1627 stateChanged("has_selection");
1629 KActionCollection
* col
= actionCollection();
1630 QAction
* renameAction
= col
->action("rename");
1631 QAction
* moveToTrashAction
= col
->action("move_to_trash");
1632 QAction
* deleteAction
= col
->action("delete");
1633 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
1634 QAction
* deleteWithTrashShortcut
= col
->action("delete_shortcut"); // see DolphinViewActionHandler
1636 KFileItemListProperties
capabilities(list
);
1637 const bool enableMoveToTrash
= capabilities
.isLocal() && capabilities
.supportsMoving();
1639 renameAction
->setEnabled(capabilities
.supportsMoving());
1640 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1641 deleteAction
->setEnabled(capabilities
.supportsDeleting());
1642 deleteWithTrashShortcut
->setEnabled(capabilities
.supportsDeleting() && !enableMoveToTrash
);
1643 cutAction
->setEnabled(capabilities
.supportsMoving());
1645 updatePasteAction();
1648 void DolphinMainWindow::updateViewActions()
1650 m_actionHandler
->updateViewActions();
1652 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1653 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
1655 updateSplitAction();
1657 QAction
* editableLocactionAction
= actionCollection()->action("editable_location");
1658 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
1659 editableLocactionAction
->setChecked(urlNavigator
->isUrlEditable());
1662 void DolphinMainWindow::updateGoActions()
1664 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
1665 const KUrl currentUrl
= m_activeViewContainer
->url();
1666 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
1669 void DolphinMainWindow::rememberClosedTab(int index
)
1671 KMenu
* tabsMenu
= m_recentTabsMenu
->menu();
1673 const QString primaryPath
= m_viewTab
[index
].primaryView
->url().path();
1674 const QString iconName
= KMimeType::iconNameForUrl(primaryPath
);
1676 QAction
* action
= new QAction(squeezedText(primaryPath
), tabsMenu
);
1678 ClosedTab closedTab
;
1679 closedTab
.primaryUrl
= m_viewTab
[index
].primaryView
->url();
1681 if (m_viewTab
[index
].secondaryView
!= 0) {
1682 closedTab
.secondaryUrl
= m_viewTab
[index
].secondaryView
->url();
1683 closedTab
.isSplit
= true;
1685 closedTab
.isSplit
= false;
1688 action
->setData(QVariant::fromValue(closedTab
));
1689 action
->setIcon(KIcon(iconName
));
1691 // add the closed tab menu entry after the separator and
1692 // "Empty Recently Closed Tabs" entry
1693 if (tabsMenu
->actions().size() == 2) {
1694 tabsMenu
->addAction(action
);
1696 tabsMenu
->insertAction(tabsMenu
->actions().at(2), action
);
1699 // assure that only up to 8 closed tabs are shown in the menu
1700 if (tabsMenu
->actions().size() > 8) {
1701 tabsMenu
->removeAction(tabsMenu
->actions().last());
1703 actionCollection()->action("closed_tabs")->setEnabled(true);
1704 KAcceleratorManager::manage(tabsMenu
);
1707 void DolphinMainWindow::clearStatusBar()
1709 m_activeViewContainer
->statusBar()->clear();
1712 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
1714 connect(container
, SIGNAL(showFilterBarChanged(bool)),
1715 this, SLOT(updateFilterBarAction(bool)));
1716 connect(container
, SIGNAL(writeStateChanged(bool)),
1717 this, SLOT(slotWriteStateChanged(bool)));
1719 DolphinView
* view
= container
->view();
1720 connect(view
, SIGNAL(selectionChanged(KFileItemList
)),
1721 this, SLOT(slotSelectionChanged(KFileItemList
)));
1722 connect(view
, SIGNAL(requestItemInfo(KFileItem
)),
1723 this, SLOT(slotRequestItemInfo(KFileItem
)));
1724 connect(view
, SIGNAL(activated()),
1725 this, SLOT(toggleActiveView()));
1726 connect(view
, SIGNAL(tabRequested(const KUrl
&)),
1727 this, SLOT(openNewTab(const KUrl
&)));
1728 connect(view
, SIGNAL(requestContextMenu(KFileItem
, const KUrl
&, const QList
<QAction
*>&)),
1729 this, SLOT(openContextMenu(KFileItem
, const KUrl
&, const QList
<QAction
*>&)));
1730 connect(view
, SIGNAL(startedPathLoading(KUrl
)),
1731 this, SLOT(enableStopAction()));
1732 connect(view
, SIGNAL(finishedPathLoading(KUrl
)),
1733 this, SLOT(disableStopAction()));
1735 const KUrlNavigator
* navigator
= container
->urlNavigator();
1736 connect(navigator
, SIGNAL(urlChanged(const KUrl
&)),
1737 this, SLOT(changeUrl(const KUrl
&)));
1738 connect(navigator
, SIGNAL(historyChanged()),
1739 this, SLOT(updateHistory()));
1740 connect(navigator
, SIGNAL(editableStateChanged(bool)),
1741 this, SLOT(slotEditableStateChanged(bool)));
1742 connect(navigator
, SIGNAL(tabRequested(const KUrl
&)),
1743 this, SLOT(openNewTab(KUrl
)));
1746 void DolphinMainWindow::updateSplitAction()
1748 QAction
* splitAction
= actionCollection()->action("split_view");
1749 if (m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
1750 if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
1751 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
1752 splitAction
->setToolTip(i18nc("@info", "Close right view"));
1753 splitAction
->setIcon(KIcon("view-right-close"));
1755 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
1756 splitAction
->setToolTip(i18nc("@info", "Close left view"));
1757 splitAction
->setIcon(KIcon("view-left-close"));
1760 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
1761 splitAction
->setToolTip(i18nc("@info", "Split view"));
1762 splitAction
->setIcon(KIcon("view-right-new"));
1766 QString
DolphinMainWindow::tabName(const KUrl
& url
) const
1769 if (url
.equals(KUrl("file:///"))) {
1772 name
= url
.fileName();
1773 if (name
.isEmpty()) {
1774 name
= url
.protocol();
1776 // Make sure that a '&' inside the directory name is displayed correctly
1777 // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
1778 name
.replace('&', "&&");
1784 bool DolphinMainWindow::isKompareInstalled() const
1786 static bool initialized
= false;
1787 static bool installed
= false;
1789 // TODO: maybe replace this approach later by using a menu
1790 // plugin like kdiff3plugin.cpp
1791 installed
= !KGlobal::dirs()->findExe("kompare").isEmpty();
1797 void DolphinMainWindow::createSecondaryView(int tabIndex
)
1799 QSplitter
* splitter
= m_viewTab
[tabIndex
].splitter
;
1800 const int newWidth
= (m_viewTab
[tabIndex
].primaryView
->width() - splitter
->handleWidth()) / 2;
1802 const DolphinView
* view
= m_viewTab
[tabIndex
].primaryView
->view();
1803 m_viewTab
[tabIndex
].secondaryView
= new DolphinViewContainer(view
->rootUrl(), 0);
1804 splitter
->addWidget(m_viewTab
[tabIndex
].secondaryView
);
1805 splitter
->setSizes(QList
<int>() << newWidth
<< newWidth
);
1806 connectViewSignals(m_viewTab
[tabIndex
].secondaryView
);
1807 m_viewTab
[tabIndex
].secondaryView
->view()->reload();
1808 m_viewTab
[tabIndex
].secondaryView
->setActive(false);
1809 m_viewTab
[tabIndex
].secondaryView
->show();
1812 QString
DolphinMainWindow::tabProperty(const QString
& property
, int tabIndex
) const
1814 return "Tab " + QString::number(tabIndex
) + ' ' + property
;
1817 void DolphinMainWindow::setUrlAsCaption(const KUrl
& url
)
1820 if (!url
.isLocalFile()) {
1821 caption
.append(url
.protocol() + " - ");
1822 if (url
.hasHost()) {
1823 caption
.append(url
.host() + " - ");
1827 const QString fileName
= url
.fileName().isEmpty() ? "/" : url
.fileName();
1828 caption
.append(fileName
);
1830 setCaption(caption
);
1833 QString
DolphinMainWindow::squeezedText(const QString
& text
) const
1835 const QFontMetrics fm
= fontMetrics();
1836 return fm
.elidedText(text
, Qt::ElideMiddle
, fm
.maxWidth() * 10);
1839 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
1840 KIO::FileUndoManager::UiInterface()
1844 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
1848 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
1850 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
1852 DolphinStatusBar
* statusBar
= mainWin
->activeViewContainer()->statusBar();
1853 statusBar
->setMessage(job
->errorString(), DolphinStatusBar::Error
);
1855 KIO::FileUndoManager::UiInterface::jobError(job
);
1859 #include "dolphinmainwindow.moc"