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 setObjectName("Dolphin#");
121 m_viewTab
.append(ViewTab());
123 new MainWindowAdaptor(this);
124 QDBusConnection::sessionBus().registerObject(QString("/dolphin/MainWindow%1").arg(m_id
), this);
126 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
127 undoManager
->setUiInterface(new UndoUiInterface());
129 connect(undoManager
, SIGNAL(undoAvailable(bool)),
130 this, SLOT(slotUndoAvailable(bool)));
131 connect(undoManager
, SIGNAL(undoTextChanged(const QString
&)),
132 this, SLOT(slotUndoTextChanged(const QString
&)));
133 connect(undoManager
, SIGNAL(jobRecordingStarted(CommandType
)),
134 this, SLOT(clearStatusBar()));
135 connect(undoManager
, SIGNAL(jobRecordingFinished(CommandType
)),
136 this, SLOT(showCommand(CommandType
)));
137 connect(DolphinSettings::instance().placesModel(), SIGNAL(errorMessage(const QString
&)),
138 this, SLOT(showErrorMessage(const QString
&)));
139 connect(&DragAndDropHelper::instance(), SIGNAL(errorMessage(const QString
&)),
140 this, SLOT(showErrorMessage(const QString
&)));
143 DolphinMainWindow::~DolphinMainWindow()
145 DolphinApplication::app()->removeMainWindow(this);
148 void DolphinMainWindow::openDirectories(const QList
<KUrl
>& dirs
)
150 if (dirs
.isEmpty()) {
154 const int oldOpenTabsCount
= m_viewTab
.count();
156 const GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
157 const bool hasSplitView
= generalSettings
->splitView();
159 // Open each directory inside a new tab. If the "split view" option has been enabled,
160 // always show two directories within one tab.
161 QList
<KUrl
>::const_iterator it
= dirs
.begin();
162 while (it
!= dirs
.end()) {
166 if (hasSplitView
&& (it
!= dirs
.end())) {
167 const int tabIndex
= m_viewTab
.count() - 1;
168 m_viewTab
[tabIndex
].secondaryView
->setUrl(*it
);
173 // remove the previously opened tabs
174 for (int i
= 0; i
< oldOpenTabsCount
; ++i
) {
179 void DolphinMainWindow::openFiles(const QList
<KUrl
>& files
)
181 if (files
.isEmpty()) {
185 // Get all distinct directories from 'files' and open a tab
186 // for each directory. If the "split view" option is enabled, two
187 // directories are shown inside one tab (see openDirectories()).
189 foreach (const KUrl
& url
, files
) {
190 const KUrl
dir(url
.directory());
191 if (!dirs
.contains(dir
)) {
196 openDirectories(dirs
);
198 // Select the files. Although the files can be split between several
199 // tabs, there is no need to split 'files' accordingly, as
200 // the DolphinView will just ignore invalid selections.
201 const int tabCount
= m_viewTab
.count();
202 for (int i
= 0; i
< tabCount
; ++i
) {
203 m_viewTab
[i
].primaryView
->view()->markUrlsAsSelected(files
);
204 if (m_viewTab
[i
].secondaryView
!= 0) {
205 m_viewTab
[i
].secondaryView
->view()->markUrlsAsSelected(files
);
210 void DolphinMainWindow::toggleViews()
212 if (m_viewTab
[m_tabIndex
].primaryView
== 0) {
216 // move secondary view from the last position of the splitter
217 // to the first position
218 m_viewTab
[m_tabIndex
].splitter
->insertWidget(0, m_viewTab
[m_tabIndex
].secondaryView
);
220 DolphinViewContainer
* container
= m_viewTab
[m_tabIndex
].primaryView
;
221 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
222 m_viewTab
[m_tabIndex
].secondaryView
= container
;
225 void DolphinMainWindow::showCommand(CommandType command
)
227 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
229 case KIO::FileUndoManager::Copy
:
230 statusBar
->setMessage(i18nc("@info:status", "Successfully copied."),
231 DolphinStatusBar::OperationCompleted
);
233 case KIO::FileUndoManager::Move
:
234 statusBar
->setMessage(i18nc("@info:status", "Successfully moved."),
235 DolphinStatusBar::OperationCompleted
);
237 case KIO::FileUndoManager::Link
:
238 statusBar
->setMessage(i18nc("@info:status", "Successfully linked."),
239 DolphinStatusBar::OperationCompleted
);
241 case KIO::FileUndoManager::Trash
:
242 statusBar
->setMessage(i18nc("@info:status", "Successfully moved to trash."),
243 DolphinStatusBar::OperationCompleted
);
245 case KIO::FileUndoManager::Rename
:
246 statusBar
->setMessage(i18nc("@info:status", "Successfully renamed."),
247 DolphinStatusBar::OperationCompleted
);
250 case KIO::FileUndoManager::Mkdir
:
251 statusBar
->setMessage(i18nc("@info:status", "Created folder."),
252 DolphinStatusBar::OperationCompleted
);
260 void DolphinMainWindow::refreshViews()
262 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
264 // remember the current active view, as because of
265 // the refreshing the active view might change to
266 // the secondary view
267 DolphinViewContainer
* activeViewContainer
= m_activeViewContainer
;
269 const int tabCount
= m_viewTab
.count();
270 for (int i
= 0; i
< tabCount
; ++i
) {
271 m_viewTab
[i
].primaryView
->refresh();
272 if (m_viewTab
[i
].secondaryView
!= 0) {
273 m_viewTab
[i
].secondaryView
->refresh();
277 setActiveViewContainer(activeViewContainer
);
280 void DolphinMainWindow::pasteIntoFolder()
282 m_activeViewContainer
->view()->pasteIntoFolder();
285 void DolphinMainWindow::changeUrl(const KUrl
& url
)
287 if (!KProtocolManager::supportsListing(url
)) {
288 // The URL navigator only checks for validity, not
289 // if the URL can be listed. An error message is
290 // shown due to DolphinViewContainer::restoreView().
294 DolphinViewContainer
* view
= activeViewContainer();
300 setUrlAsCaption(url
);
301 if (m_viewTab
.count() > 1) {
302 m_tabBar
->setTabText(m_tabIndex
, squeezedText(tabName(m_activeViewContainer
->url())));
304 const QString iconName
= KMimeType::iconNameForUrl(url
);
305 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(iconName
));
306 emit
urlChanged(url
);
310 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
312 KToggleAction
* editableLocationAction
=
313 static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
314 editableLocationAction
->setChecked(editable
);
317 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
321 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
322 int selectedUrlsCount
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedItemsCount();
323 if (m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
324 selectedUrlsCount
+= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItemsCount();
327 QAction
* compareFilesAction
= actionCollection()->action("compare_files");
328 if (selectedUrlsCount
== 2) {
329 compareFilesAction
->setEnabled(isKompareInstalled());
331 compareFilesAction
->setEnabled(false);
334 emit
selectionChanged(selection
);
337 void DolphinMainWindow::slotRequestItemInfo(const KFileItem
& item
)
339 emit
requestItemInfo(item
);
342 void DolphinMainWindow::updateHistory()
344 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
345 const int index
= urlNavigator
->historyIndex();
347 QAction
* backAction
= actionCollection()->action("go_back");
348 backAction
->setToolTip(i18nc("@info", "Go back"));
349 if (backAction
!= 0) {
350 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
353 QAction
* forwardAction
= actionCollection()->action("go_forward");
354 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
355 if (forwardAction
!= 0) {
356 forwardAction
->setEnabled(index
> 0);
360 void DolphinMainWindow::updateFilterBarAction(bool show
)
362 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
363 showFilterBarAction
->setChecked(show
);
366 void DolphinMainWindow::openNewMainWindow()
368 DolphinApplication::app()->createMainWindow()->show();
371 void DolphinMainWindow::openNewTab()
373 const bool isUrlEditable
= m_activeViewContainer
->urlNavigator()->isUrlEditable();
375 openNewTab(m_activeViewContainer
->url());
376 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
378 // The URL navigator of the new tab should have the same editable state
379 // as the current tab
380 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
381 navigator
->setUrlEditable(isUrlEditable
);
384 // If a new tab is opened and the URL is editable, assure that
385 // the user can edit the URL without manually setting the focus
386 navigator
->setFocus();
390 void DolphinMainWindow::openNewTab(const KUrl
& url
)
392 QWidget
* focusWidget
= QApplication::focusWidget();
394 if (m_viewTab
.count() == 1) {
395 // Only one view is open currently and hence no tab is shown at
396 // all. Before creating a tab for 'url', provide a tab for the current URL.
397 const KUrl currentUrl
= m_activeViewContainer
->url();
398 m_tabBar
->addTab(KIcon(KMimeType::iconNameForUrl(currentUrl
)),
399 squeezedText(tabName(currentUrl
)));
400 m_tabBar
->blockSignals(false);
403 m_tabBar
->addTab(KIcon(KMimeType::iconNameForUrl(url
)),
404 squeezedText(tabName(url
)));
407 viewTab
.splitter
= new QSplitter(this);
408 viewTab
.splitter
->setChildrenCollapsible(false);
409 viewTab
.primaryView
= new DolphinViewContainer(url
, viewTab
.splitter
);
410 viewTab
.primaryView
->setActive(false);
411 connectViewSignals(viewTab
.primaryView
);
412 viewTab
.primaryView
->view()->reload();
414 m_viewTab
.append(viewTab
);
416 actionCollection()->action("close_tab")->setEnabled(true);
418 // provide a split view, if the startup settings are set this way
419 const GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
420 if (generalSettings
->splitView()) {
421 const int tabIndex
= m_viewTab
.count() - 1;
422 createSecondaryView(tabIndex
);
423 m_viewTab
[tabIndex
].secondaryView
->setActive(true);
424 m_viewTab
[tabIndex
].isPrimaryViewActive
= false;
427 if (focusWidget
!= 0) {
428 // The DolphinViewContainer grabbed the keyboard focus. As the tab is opened
429 // in background, assure that the previous focused widget gets the focus back.
430 focusWidget
->setFocus();
434 void DolphinMainWindow::activateNextTab()
436 if ((m_viewTab
.count() == 1) || (m_tabBar
->count() < 2)) {
440 const int tabIndex
= (m_tabBar
->currentIndex() + 1) % m_tabBar
->count();
441 m_tabBar
->setCurrentIndex(tabIndex
);
444 void DolphinMainWindow::activatePrevTab()
446 if ((m_viewTab
.count() == 1) || (m_tabBar
->count() < 2)) {
450 int tabIndex
= m_tabBar
->currentIndex() - 1;
451 if (tabIndex
== -1) {
452 tabIndex
= m_tabBar
->count() - 1;
454 m_tabBar
->setCurrentIndex(tabIndex
);
457 void DolphinMainWindow::openInNewTab()
459 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
460 if ((list
.count() == 1) && list
[0].isDir()) {
461 openNewTab(m_activeViewContainer
->view()->selectedUrls()[0]);
465 void DolphinMainWindow::openInNewWindow()
467 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
468 if ((list
.count() == 1) && list
[0].isDir()) {
469 DolphinMainWindow
* window
= DolphinApplication::app()->createMainWindow();
470 window
->changeUrl(m_activeViewContainer
->view()->selectedUrls()[0]);
475 void DolphinMainWindow::toggleActiveView()
477 if (m_viewTab
[m_tabIndex
].secondaryView
== 0) {
478 // only one view is available
482 Q_ASSERT(m_activeViewContainer
!= 0);
483 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
485 DolphinViewContainer
* left
= m_viewTab
[m_tabIndex
].primaryView
;
486 DolphinViewContainer
* right
= m_viewTab
[m_tabIndex
].secondaryView
;
487 setActiveViewContainer(m_activeViewContainer
== right
? left
: right
);
490 void DolphinMainWindow::showEvent(QShowEvent
* event
)
492 KXmlGuiWindow::showEvent(event
);
493 if (!event
->spontaneous()) {
494 m_activeViewContainer
->view()->setFocus();
498 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
500 DolphinSettings
& settings
= DolphinSettings::instance();
501 GeneralSettings
* generalSettings
= settings
.generalSettings();
503 // Find out if Dolphin is closed directly by the user or
504 // by the session manager because the session is closed
505 bool closedByUser
= true;
506 DolphinApplication
*application
= qobject_cast
<DolphinApplication
*>(qApp
);
507 if (application
&& application
->sessionSaving()) {
508 closedByUser
= false;
511 if ((m_viewTab
.count() > 1) && generalSettings
->confirmClosingMultipleTabs() && closedByUser
) {
512 // Ask the user if he really wants to quit and close all tabs.
513 // Open a confirmation dialog with 3 buttons:
514 // KDialog::Yes -> Quit
515 // KDialog::No -> Close only the current tab
516 // KDialog::Cancel -> do nothing
517 KDialog
*dialog
= new KDialog(this, Qt::Dialog
);
518 dialog
->setCaption(i18nc("@title:window", "Confirmation"));
519 dialog
->setButtons(KDialog::Yes
| KDialog::No
| KDialog::Cancel
);
520 dialog
->setModal(true);
521 dialog
->setButtonGuiItem(KDialog::Yes
, KStandardGuiItem::quit());
522 dialog
->setButtonGuiItem(KDialog::No
, KGuiItem(i18n("C&lose Current Tab"), KIcon("tab-close")));
523 dialog
->setButtonGuiItem(KDialog::Cancel
, KStandardGuiItem::cancel());
524 dialog
->setDefaultButton(KDialog::Yes
);
526 bool doNotAskAgainCheckboxResult
= false;
528 const int result
= KMessageBox::createKMessageBox(dialog
,
529 QMessageBox::Warning
,
530 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
532 i18n("Do not ask again"),
533 &doNotAskAgainCheckboxResult
,
534 KMessageBox::Notify
);
536 if (doNotAskAgainCheckboxResult
) {
537 generalSettings
->setConfirmClosingMultipleTabs(false);
545 // Close only the current tab
553 generalSettings
->setFirstRun(false);
557 KXmlGuiWindow::closeEvent(event
);
560 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
562 const int tabCount
= m_viewTab
.count();
563 group
.writeEntry("Tab Count", tabCount
);
564 group
.writeEntry("Active Tab Index", m_tabBar
->currentIndex());
566 for (int i
= 0; i
< tabCount
; ++i
) {
567 const DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
568 group
.writeEntry(tabProperty("Primary URL", i
), cont
->url().url());
569 group
.writeEntry(tabProperty("Primary Editable", i
),
570 cont
->urlNavigator()->isUrlEditable());
572 cont
= m_viewTab
[i
].secondaryView
;
574 group
.writeEntry(tabProperty("Secondary URL", i
), cont
->url().url());
575 group
.writeEntry(tabProperty("Secondary Editable", i
),
576 cont
->urlNavigator()->isUrlEditable());
581 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
583 const int tabCount
= group
.readEntry("Tab Count", 1);
584 for (int i
= 0; i
< tabCount
; ++i
) {
585 DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
587 cont
->setUrl(group
.readEntry(tabProperty("Primary URL", i
)));
588 const bool editable
= group
.readEntry(tabProperty("Primary Editable", i
), false);
589 cont
->urlNavigator()->setUrlEditable(editable
);
591 cont
= m_viewTab
[i
].secondaryView
;
592 const QString secondaryUrl
= group
.readEntry(tabProperty("Secondary URL", i
));
593 if (!secondaryUrl
.isEmpty()) {
595 // a secondary view should be shown, but no one is available
596 // currently -> create a new view
598 cont
= m_viewTab
[i
].secondaryView
;
602 cont
->setUrl(secondaryUrl
);
603 const bool editable
= group
.readEntry(tabProperty("Secondary Editable", i
), false);
604 cont
->urlNavigator()->setUrlEditable(editable
);
605 } else if (cont
!= 0) {
606 // no secondary view should be shown, but the default setting shows
607 // one already -> close the view
611 // openNewTab() needs to be called only tabCount - 1 times
612 if (i
!= tabCount
- 1) {
617 const int index
= group
.readEntry("Active Tab Index", 0);
618 m_tabBar
->setCurrentIndex(index
);
621 void DolphinMainWindow::updateNewMenu()
623 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->showHiddenFiles());
624 m_newFileMenu
->checkUpToDate();
625 m_newFileMenu
->setPopupFiles(activeViewContainer()->url());
628 void DolphinMainWindow::createDirectory()
630 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->showHiddenFiles());
631 m_newFileMenu
->setPopupFiles(activeViewContainer()->url());
632 m_newFileMenu
->createDirectory();
635 void DolphinMainWindow::quit()
640 void DolphinMainWindow::showErrorMessage(const QString
& message
)
642 if (!message
.isEmpty()) {
643 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
644 statusBar
->setMessage(message
, DolphinStatusBar::Error
);
648 void DolphinMainWindow::slotUndoAvailable(bool available
)
650 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
651 if (undoAction
!= 0) {
652 undoAction
->setEnabled(available
);
656 void DolphinMainWindow::restoreClosedTab(QAction
* action
)
658 if (action
->data().toBool()) {
659 // clear all actions except the "Empty Recently Closed Tabs"
660 // action and the separator
661 QList
<QAction
*> actions
= m_recentTabsMenu
->menu()->actions();
662 const int count
= actions
.size();
663 for (int i
= 2; i
< count
; ++i
) {
664 m_recentTabsMenu
->menu()->removeAction(actions
.at(i
));
667 const ClosedTab closedTab
= action
->data().value
<ClosedTab
>();
668 openNewTab(closedTab
.primaryUrl
);
669 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
671 if (closedTab
.isSplit
) {
672 // create secondary view
674 m_viewTab
[m_tabIndex
].secondaryView
->setUrl(closedTab
.secondaryUrl
);
677 m_recentTabsMenu
->removeAction(action
);
680 if (m_recentTabsMenu
->menu()->actions().count() == 2) {
681 m_recentTabsMenu
->setEnabled(false);
685 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
687 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
688 if (undoAction
!= 0) {
689 undoAction
->setText(text
);
693 void DolphinMainWindow::undo()
696 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
697 KIO::FileUndoManager::self()->undo();
700 void DolphinMainWindow::cut()
702 m_activeViewContainer
->view()->cutSelectedItems();
705 void DolphinMainWindow::copy()
707 m_activeViewContainer
->view()->copySelectedItems();
710 void DolphinMainWindow::paste()
712 m_activeViewContainer
->view()->paste();
715 void DolphinMainWindow::find()
717 m_activeViewContainer
->setSearchModeEnabled(true);
720 void DolphinMainWindow::updatePasteAction()
722 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
723 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
724 pasteAction
->setEnabled(pasteInfo
.first
);
725 pasteAction
->setText(pasteInfo
.second
);
728 void DolphinMainWindow::selectAll()
732 // if the URL navigator is editable and focused, select the whole
733 // URL instead of all items of the view
735 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
736 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit(); // krazy:exclude=qclasses
737 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
738 lineEdit
->hasFocus();
740 lineEdit
->selectAll();
742 m_activeViewContainer
->view()->selectAll();
746 void DolphinMainWindow::invertSelection()
749 m_activeViewContainer
->view()->invertSelection();
752 void DolphinMainWindow::toggleSplitView()
754 if (m_viewTab
[m_tabIndex
].secondaryView
== 0) {
755 createSecondaryView(m_tabIndex
);
756 setActiveViewContainer(m_viewTab
[m_tabIndex
].secondaryView
);
757 } else if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
758 // remove secondary view
759 m_viewTab
[m_tabIndex
].secondaryView
->close();
760 m_viewTab
[m_tabIndex
].secondaryView
->deleteLater();
761 m_viewTab
[m_tabIndex
].secondaryView
= 0;
763 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
765 // The primary view is active and should be closed. Hence from a users point of view
766 // the content of the secondary view should be moved to the primary view.
767 // From an implementation point of view it is more efficient to close
768 // the primary view and exchange the internal pointers afterwards.
770 m_viewTab
[m_tabIndex
].primaryView
->close();
771 m_viewTab
[m_tabIndex
].primaryView
->deleteLater();
772 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
773 m_viewTab
[m_tabIndex
].secondaryView
= 0;
775 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
781 void DolphinMainWindow::reloadView()
784 m_activeViewContainer
->view()->reload();
787 void DolphinMainWindow::stopLoading()
791 void DolphinMainWindow::toggleFilterBarVisibility(bool show
)
793 m_activeViewContainer
->showFilterBar(show
);
796 void DolphinMainWindow::toggleEditLocation()
800 QAction
* action
= actionCollection()->action("editable_location");
801 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
802 urlNavigator
->setUrlEditable(action
->isChecked());
805 void DolphinMainWindow::replaceLocation()
807 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
808 navigator
->setUrlEditable(true);
809 navigator
->setFocus();
811 // select the whole text of the combo box editor
812 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit(); // krazy:exclude=qclasses
813 const QString text
= lineEdit
->text();
814 lineEdit
->setSelection(0, text
.length());
817 void DolphinMainWindow::goBack()
821 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
822 urlNavigator
->goBack();
824 if (urlNavigator
->locationState().isEmpty()) {
825 // An empty location state indicates a redirection URL,
826 // which must be skipped too
827 urlNavigator
->goBack();
831 void DolphinMainWindow::goForward()
834 m_activeViewContainer
->urlNavigator()->goForward();
837 void DolphinMainWindow::goUp()
840 m_activeViewContainer
->urlNavigator()->goUp();
843 void DolphinMainWindow::goBack(Qt::MouseButtons buttons
)
845 // The default case (left button pressed) is handled in goBack().
846 if (buttons
== Qt::MidButton
) {
847 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
848 const int index
= urlNavigator
->historyIndex() + 1;
849 openNewTab(urlNavigator
->locationUrl(index
));
853 void DolphinMainWindow::goForward(Qt::MouseButtons buttons
)
855 // The default case (left button pressed) is handled in goForward().
856 if (buttons
== Qt::MidButton
) {
857 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
858 const int index
= urlNavigator
->historyIndex() - 1;
859 openNewTab(urlNavigator
->locationUrl(index
));
863 void DolphinMainWindow::goUp(Qt::MouseButtons buttons
)
865 // The default case (left button pressed) is handled in goUp().
866 if (buttons
== Qt::MidButton
) {
867 openNewTab(activeViewContainer()->url().upUrl());
871 void DolphinMainWindow::goHome()
874 m_activeViewContainer
->urlNavigator()->goHome();
877 void DolphinMainWindow::compareFiles()
879 // The method is only invoked if exactly 2 files have
880 // been selected. The selected files may be:
881 // - both in the primary view
882 // - both in the secondary view
883 // - one in the primary view and the other in the secondary
885 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
889 KUrl::List urls
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedUrls();
891 switch (urls
.count()) {
893 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
!= 0);
894 urls
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedUrls();
895 Q_ASSERT(urls
.count() == 2);
903 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
!= 0);
904 urls
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedUrls();
905 Q_ASSERT(urls
.count() == 1);
917 // may not happen: compareFiles may only get invoked if 2
918 // files are selected
923 QString
command("kompare -c \"");
924 command
.append(urlA
.pathOrUrl());
925 command
.append("\" \"");
926 command
.append(urlB
.pathOrUrl());
927 command
.append('\"');
928 KRun::runCommand(command
, "Kompare", "kompare", this);
931 void DolphinMainWindow::toggleShowMenuBar()
933 const bool visible
= menuBar()->isVisible();
934 menuBar()->setVisible(!visible
);
937 void DolphinMainWindow::openTerminal()
939 QString
dir(QDir::homePath());
941 // If the given directory is not local, it can still be the URL of an
942 // ioslave using UDS_LOCAL_PATH which to be converted first.
943 KUrl url
= KIO::NetAccess::mostLocalUrl(m_activeViewContainer
->url(), this);
945 //If the URL is local after the above conversion, set the directory.
946 if (url
.isLocalFile()) {
947 dir
= url
.toLocalFile();
950 KToolInvocation::invokeTerminal(QString(), dir
);
953 void DolphinMainWindow::editSettings()
955 if (m_settingsDialog
== 0) {
956 const KUrl
& url
= activeViewContainer()->url();
957 m_settingsDialog
= new DolphinSettingsDialog(url
, this);
958 m_settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
959 m_settingsDialog
->show();
961 m_settingsDialog
->raise();
965 void DolphinMainWindow::setActiveTab(int index
)
967 Q_ASSERT(index
>= 0);
968 Q_ASSERT(index
< m_viewTab
.count());
969 if (index
== m_tabIndex
) {
973 // hide current tab content
974 ViewTab
& hiddenTab
= m_viewTab
[m_tabIndex
];
975 hiddenTab
.isPrimaryViewActive
= hiddenTab
.primaryView
->isActive();
976 hiddenTab
.primaryView
->setActive(false);
977 if (hiddenTab
.secondaryView
!= 0) {
978 hiddenTab
.secondaryView
->setActive(false);
980 QSplitter
* splitter
= m_viewTab
[m_tabIndex
].splitter
;
982 m_centralWidgetLayout
->removeWidget(splitter
);
984 // show active tab content
987 ViewTab
& viewTab
= m_viewTab
[index
];
988 m_centralWidgetLayout
->addWidget(viewTab
.splitter
, 1);
989 viewTab
.primaryView
->show();
990 if (viewTab
.secondaryView
!= 0) {
991 viewTab
.secondaryView
->show();
993 viewTab
.splitter
->show();
995 setActiveViewContainer(viewTab
.isPrimaryViewActive
? viewTab
.primaryView
:
996 viewTab
.secondaryView
);
999 void DolphinMainWindow::closeTab()
1001 closeTab(m_tabBar
->currentIndex());
1004 void DolphinMainWindow::closeTab(int index
)
1006 Q_ASSERT(index
>= 0);
1007 Q_ASSERT(index
< m_viewTab
.count());
1008 if (m_viewTab
.count() == 1) {
1009 // the last tab may never get closed
1013 if (index
== m_tabIndex
) {
1014 // The tab that should be closed is the active tab. Activate the
1015 // previous tab before closing the tab.
1016 m_tabBar
->setCurrentIndex((index
> 0) ? index
- 1 : 1);
1018 rememberClosedTab(index
);
1021 m_viewTab
[index
].primaryView
->deleteLater();
1022 if (m_viewTab
[index
].secondaryView
!= 0) {
1023 m_viewTab
[index
].secondaryView
->deleteLater();
1025 m_viewTab
[index
].splitter
->deleteLater();
1026 m_viewTab
.erase(m_viewTab
.begin() + index
);
1028 m_tabBar
->blockSignals(true);
1029 m_tabBar
->removeTab(index
);
1031 if (m_tabIndex
> index
) {
1033 Q_ASSERT(m_tabIndex
>= 0);
1036 // if only one tab is left, also remove the tab entry so that
1037 // closing the last tab is not possible
1038 if (m_viewTab
.count() == 1) {
1039 m_tabBar
->removeTab(0);
1040 actionCollection()->action("close_tab")->setEnabled(false);
1042 m_tabBar
->blockSignals(false);
1046 void DolphinMainWindow::openTabContextMenu(int index
, const QPoint
& pos
)
1050 QAction
* newTabAction
= menu
.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab"));
1051 newTabAction
->setShortcut(actionCollection()->action("new_tab")->shortcut());
1053 QAction
* detachTabAction
= menu
.addAction(KIcon("tab-detach"), i18nc("@action:inmenu", "Detach Tab"));
1055 QAction
* closeOtherTabsAction
= menu
.addAction(KIcon("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs"));
1057 QAction
* closeTabAction
= menu
.addAction(KIcon("tab-close"), i18nc("@action:inmenu", "Close Tab"));
1058 closeTabAction
->setShortcut(actionCollection()->action("close_tab")->shortcut());
1059 QAction
* selectedAction
= menu
.exec(pos
);
1060 if (selectedAction
== newTabAction
) {
1061 const ViewTab
& tab
= m_viewTab
[index
];
1062 Q_ASSERT(tab
.primaryView
!= 0);
1063 const KUrl url
= (tab
.secondaryView
!= 0) && tab
.secondaryView
->isActive() ?
1064 tab
.secondaryView
->url() : tab
.primaryView
->url();
1066 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
1067 } else if (selectedAction
== detachTabAction
) {
1068 const ViewTab
& tab
= m_viewTab
[index
];
1069 Q_ASSERT(tab
.primaryView
!= 0);
1070 const KUrl primaryUrl
= tab
.primaryView
->url();
1071 DolphinMainWindow
* window
= DolphinApplication::app()->createMainWindow();
1072 window
->changeUrl(primaryUrl
);
1074 if (tab
.secondaryView
!= 0) {
1075 const KUrl secondaryUrl
= tab
.secondaryView
->url();
1076 window
->toggleSplitView();
1077 window
->m_viewTab
[0].secondaryView
->setUrl(secondaryUrl
);
1078 if (tab
.primaryView
->isActive()) {
1079 window
->m_viewTab
[0].primaryView
->setActive(true);
1081 window
->m_viewTab
[0].secondaryView
->setActive(true);
1086 } else if (selectedAction
== closeOtherTabsAction
) {
1087 const int count
= m_tabBar
->count();
1088 for (int i
= 0; i
< index
; ++i
) {
1091 for (int i
= index
+ 1; i
< count
; ++i
) {
1094 } else if (selectedAction
== closeTabAction
) {
1099 void DolphinMainWindow::slotTabMoved(int from
, int to
)
1101 m_viewTab
.move(from
, to
);
1102 m_tabIndex
= m_tabBar
->currentIndex();
1105 void DolphinMainWindow::handlePlacesClick(const KUrl
& url
, Qt::MouseButtons buttons
)
1107 if (buttons
& Qt::MidButton
) {
1109 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
1115 void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent
* event
, bool& canDecode
)
1117 canDecode
= KUrl::List::canDecode(event
->mimeData());
1120 void DolphinMainWindow::handleUrl(const KUrl
& url
)
1122 delete m_lastHandleUrlStatJob
;
1123 m_lastHandleUrlStatJob
= 0;
1125 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1126 activeViewContainer()->setUrl(url
);
1127 } else if (KProtocolManager::supportsListing(url
)) {
1128 // stat the URL to see if it is a dir or not
1129 m_lastHandleUrlStatJob
= KIO::stat(url
, KIO::HideProgressInfo
);
1130 connect(m_lastHandleUrlStatJob
, SIGNAL(result(KJob
*)),
1131 this, SLOT(slotHandleUrlStatFinished(KJob
*)));
1134 new KRun(url
, this);
1138 void DolphinMainWindow::slotHandleUrlStatFinished(KJob
* job
)
1140 m_lastHandleUrlStatJob
= 0;
1141 const KIO::UDSEntry entry
= static_cast<KIO::StatJob
*>(job
)->statResult();
1142 const KUrl url
= static_cast<KIO::StatJob
*>(job
)->url();
1143 if ( entry
.isDir() ) {
1144 activeViewContainer()->setUrl(url
);
1146 new KRun(url
, this);
1150 void DolphinMainWindow::tabDropEvent(int tab
, QDropEvent
* event
)
1152 const KUrl::List urls
= KUrl::List::fromMimeData(event
->mimeData());
1153 if (!urls
.isEmpty() && tab
!= -1) {
1154 const ViewTab
& viewTab
= m_viewTab
[tab
];
1155 const KUrl destPath
= viewTab
.isPrimaryViewActive
? viewTab
.primaryView
->url() : viewTab
.secondaryView
->url();
1156 DragAndDropHelper::instance().dropUrls(KFileItem(), destPath
, event
, m_tabBar
);
1160 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1162 newFileMenu()->setEnabled(isFolderWritable
);
1165 void DolphinMainWindow::openContextMenu(const KFileItem
& item
,
1167 const QList
<QAction
*>& customActions
)
1169 DolphinContextMenu
contextMenu(this, item
, url
);
1170 contextMenu
.setCustomActions(customActions
);
1174 void DolphinMainWindow::init()
1176 DolphinSettings
& settings
= DolphinSettings::instance();
1178 // Check whether Dolphin runs the first time. If yes then
1179 // a proper default window size is given at the end of DolphinMainWindow::init().
1180 GeneralSettings
* generalSettings
= settings
.generalSettings();
1181 const bool firstRun
= generalSettings
->firstRun();
1183 generalSettings
->setViewPropsTimestamp(QDateTime::currentDateTime());
1186 setAcceptDrops(true);
1188 m_viewTab
[m_tabIndex
].splitter
= new QSplitter(this);
1189 m_viewTab
[m_tabIndex
].splitter
->setChildrenCollapsible(false);
1193 const KUrl
& homeUrl
= generalSettings
->homeUrl();
1194 setUrlAsCaption(homeUrl
);
1195 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
1196 connect(m_actionHandler
, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
1197 connect(m_actionHandler
, SIGNAL(createDirectory()), SLOT(createDirectory()));
1198 ViewProperties
props(homeUrl
);
1199 m_viewTab
[m_tabIndex
].primaryView
= new DolphinViewContainer(homeUrl
,
1200 m_viewTab
[m_tabIndex
].splitter
);
1202 m_activeViewContainer
= m_viewTab
[m_tabIndex
].primaryView
;
1203 connectViewSignals(m_activeViewContainer
);
1204 DolphinView
* view
= m_activeViewContainer
->view();
1206 m_activeViewContainer
->show();
1207 m_actionHandler
->setCurrentView(view
);
1209 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
1210 connect(this, SIGNAL(urlChanged(const KUrl
&)),
1211 m_remoteEncoding
, SLOT(slotAboutToOpenUrl()));
1213 m_tabBar
= new KTabBar(this);
1214 m_tabBar
->setMovable(true);
1215 m_tabBar
->setTabsClosable(true);
1216 connect(m_tabBar
, SIGNAL(currentChanged(int)),
1217 this, SLOT(setActiveTab(int)));
1218 connect(m_tabBar
, SIGNAL(tabCloseRequested(int)),
1219 this, SLOT(closeTab(int)));
1220 connect(m_tabBar
, SIGNAL(contextMenu(int, const QPoint
&)),
1221 this, SLOT(openTabContextMenu(int, const QPoint
&)));
1222 connect(m_tabBar
, SIGNAL(newTabRequest()),
1223 this, SLOT(openNewTab()));
1224 connect(m_tabBar
, SIGNAL(testCanDecode(const QDragMoveEvent
*, bool&)),
1225 this, SLOT(slotTestCanDecode(const QDragMoveEvent
*, bool&)));
1226 connect(m_tabBar
, SIGNAL(mouseMiddleClick(int)),
1227 this, SLOT(closeTab(int)));
1228 connect(m_tabBar
, SIGNAL(tabMoved(int, int)),
1229 this, SLOT(slotTabMoved(int, int)));
1230 connect(m_tabBar
, SIGNAL(receivedDropEvent(int, QDropEvent
*)),
1231 this, SLOT(tabDropEvent(int, QDropEvent
*)));
1233 m_tabBar
->blockSignals(true); // signals get unblocked after at least 2 tabs are open
1235 QWidget
* centralWidget
= new QWidget(this);
1236 m_centralWidgetLayout
= new QVBoxLayout(centralWidget
);
1237 m_centralWidgetLayout
->setSpacing(0);
1238 m_centralWidgetLayout
->setMargin(0);
1239 m_centralWidgetLayout
->addWidget(m_tabBar
);
1240 m_centralWidgetLayout
->addWidget(m_viewTab
[m_tabIndex
].splitter
, 1);
1242 setCentralWidget(centralWidget
);
1244 emit
urlChanged(homeUrl
);
1246 setupGUI(Keys
| Save
| Create
| ToolBar
);
1247 stateChanged("new_file");
1249 QClipboard
* clipboard
= QApplication::clipboard();
1250 connect(clipboard
, SIGNAL(dataChanged()),
1251 this, SLOT(updatePasteAction()));
1253 if (generalSettings
->splitView()) {
1256 updateEditActions();
1257 updateViewActions();
1260 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1261 showFilterBarAction
->setChecked(generalSettings
->filterBar());
1264 // assure a proper default size if Dolphin runs the first time
1268 m_showMenuBar
->setChecked(!menuBar()->isHidden()); // workaround for bug #171080
1271 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer
* viewContainer
)
1273 Q_ASSERT(viewContainer
!= 0);
1274 Q_ASSERT((viewContainer
== m_viewTab
[m_tabIndex
].primaryView
) ||
1275 (viewContainer
== m_viewTab
[m_tabIndex
].secondaryView
));
1276 if (m_activeViewContainer
== viewContainer
) {
1280 m_activeViewContainer
->setActive(false);
1281 m_activeViewContainer
= viewContainer
;
1283 // Activating the view container might trigger a recursive setActiveViewContainer() call
1284 // inside DolphinMainWindow::toggleActiveView() when having a split view. Temporary
1285 // disconnect the activated() signal in this case:
1286 disconnect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1287 m_activeViewContainer
->setActive(true);
1288 connect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1290 m_actionHandler
->setCurrentView(viewContainer
->view());
1293 updateEditActions();
1294 updateViewActions();
1297 const KUrl
& url
= m_activeViewContainer
->url();
1298 setUrlAsCaption(url
);
1299 if (m_viewTab
.count() > 1 && m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
1300 m_tabBar
->setTabText(m_tabIndex
, tabName(url
));
1301 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(KMimeType::iconNameForUrl(url
)));
1304 emit
urlChanged(url
);
1307 void DolphinMainWindow::setupActions()
1309 // setup 'File' menu
1310 m_newFileMenu
= new DolphinNewFileMenu(this, this);
1311 KMenu
* menu
= m_newFileMenu
->menu();
1312 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1313 menu
->setIcon(KIcon("document-new"));
1314 connect(menu
, SIGNAL(aboutToShow()),
1315 this, SLOT(updateNewMenu()));
1317 KAction
* newWindow
= actionCollection()->addAction("new_window");
1318 newWindow
->setIcon(KIcon("window-new"));
1319 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1320 newWindow
->setShortcut(Qt::CTRL
| Qt::Key_N
);
1321 connect(newWindow
, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1323 KAction
* newTab
= actionCollection()->addAction("new_tab");
1324 newTab
->setIcon(KIcon("tab-new"));
1325 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1326 newTab
->setShortcut(KShortcut(Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
));
1327 connect(newTab
, SIGNAL(triggered()), this, SLOT(openNewTab()));
1329 KAction
* closeTab
= actionCollection()->addAction("close_tab");
1330 closeTab
->setIcon(KIcon("tab-close"));
1331 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1332 closeTab
->setShortcut(Qt::CTRL
| Qt::Key_W
);
1333 closeTab
->setEnabled(false);
1334 connect(closeTab
, SIGNAL(triggered()), this, SLOT(closeTab()));
1336 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1338 // setup 'Edit' menu
1339 KStandardAction::undo(this,
1341 actionCollection());
1343 // need to remove shift+del from cut action, else the shortcut for deletejob
1345 KAction
* cut
= KStandardAction::cut(this, SLOT(cut()), actionCollection());
1346 KShortcut cutShortcut
= cut
->shortcut();
1347 cutShortcut
.remove(Qt::SHIFT
+ Qt::Key_Delete
, KShortcut::KeepEmpty
);
1348 cut
->setShortcut(cutShortcut
);
1349 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1350 KAction
* paste
= KStandardAction::paste(this, SLOT(paste()), actionCollection());
1351 // The text of the paste-action is modified dynamically by Dolphin
1352 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1353 // due to the long text, the text "Paste" is used:
1354 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1356 KStandardAction::find(this, SLOT(find()), actionCollection());
1358 KAction
* selectAll
= actionCollection()->addAction("select_all");
1359 selectAll
->setText(i18nc("@action:inmenu Edit", "Select All"));
1360 selectAll
->setShortcut(Qt::CTRL
+ Qt::Key_A
);
1361 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
1363 KAction
* invertSelection
= actionCollection()->addAction("invert_selection");
1364 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1365 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1366 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
1368 // setup 'View' menu
1369 // (note that most of it is set up in DolphinViewActionHandler)
1371 KAction
* split
= actionCollection()->addAction("split_view");
1372 split
->setShortcut(Qt::Key_F3
);
1373 updateSplitAction();
1374 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1376 KAction
* reload
= actionCollection()->addAction("reload");
1377 reload
->setText(i18nc("@action:inmenu View", "Reload"));
1378 reload
->setShortcut(Qt::Key_F5
);
1379 reload
->setIcon(KIcon("view-refresh"));
1380 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
1382 KAction
* stop
= actionCollection()->addAction("stop");
1383 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1384 stop
->setToolTip(i18nc("@info", "Stop loading"));
1385 stop
->setIcon(KIcon("process-stop"));
1386 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
1388 KToggleAction
* showFullLocation
= actionCollection()->add
<KToggleAction
>("editable_location");
1389 showFullLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1390 showFullLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
1391 connect(showFullLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1393 KAction
* replaceLocation
= actionCollection()->addAction("replace_location");
1394 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1395 replaceLocation
->setShortcut(Qt::Key_F6
);
1396 connect(replaceLocation
, SIGNAL(triggered()), this, SLOT(replaceLocation()));
1399 KAction
* backAction
= KStandardAction::back(this, SLOT(goBack()), actionCollection());
1400 connect(backAction
, SIGNAL(triggered(Qt::MouseButtons
, Qt::KeyboardModifiers
)), this, SLOT(goBack(Qt::MouseButtons
)));
1401 KShortcut backShortcut
= backAction
->shortcut();
1402 backShortcut
.setAlternate(Qt::Key_Backspace
);
1403 backAction
->setShortcut(backShortcut
);
1405 m_recentTabsMenu
= new KActionMenu(i18n("Recently Closed Tabs"), this);
1406 m_recentTabsMenu
->setIcon(KIcon("edit-undo"));
1407 actionCollection()->addAction("closed_tabs", m_recentTabsMenu
);
1408 connect(m_recentTabsMenu
->menu(), SIGNAL(triggered(QAction
*)),
1409 this, SLOT(restoreClosedTab(QAction
*)));
1411 QAction
* action
= new QAction("Empty Recently Closed Tabs", m_recentTabsMenu
);
1412 action
->setIcon(KIcon("edit-clear-list"));
1413 action
->setData(QVariant::fromValue(true));
1414 m_recentTabsMenu
->addAction(action
);
1415 m_recentTabsMenu
->addSeparator();
1416 m_recentTabsMenu
->setEnabled(false);
1418 KAction
* forwardAction
= KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1419 connect(forwardAction
, SIGNAL(triggered(Qt::MouseButtons
, Qt::KeyboardModifiers
)), this, SLOT(goForward(Qt::MouseButtons
)));
1421 KAction
* upAction
= KStandardAction::up(this, SLOT(goUp()), actionCollection());
1422 connect(upAction
, SIGNAL(triggered(Qt::MouseButtons
, Qt::KeyboardModifiers
)), this, SLOT(goUp(Qt::MouseButtons
)));
1424 KStandardAction::home(this, SLOT(goHome()), actionCollection());
1426 // setup 'Tools' menu
1427 KToggleAction
* showFilterBar
= actionCollection()->add
<KToggleAction
>("show_filter_bar");
1428 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1429 showFilterBar
->setIcon(KIcon("view-filter"));
1430 showFilterBar
->setShortcut(Qt::CTRL
| Qt::Key_I
);
1431 connect(showFilterBar
, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
1433 KAction
* compareFiles
= actionCollection()->addAction("compare_files");
1434 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1435 compareFiles
->setIcon(KIcon("kompare"));
1436 compareFiles
->setEnabled(false);
1437 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
1439 KAction
* openTerminal
= actionCollection()->addAction("open_terminal");
1440 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1441 openTerminal
->setIcon(KIcon("utilities-terminal"));
1442 openTerminal
->setShortcut(Qt::SHIFT
| Qt::Key_F4
);
1443 connect(openTerminal
, SIGNAL(triggered()), this, SLOT(openTerminal()));
1445 // setup 'Settings' menu
1446 m_showMenuBar
= KStandardAction::showMenubar(this, SLOT(toggleShowMenuBar()), actionCollection());
1447 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1449 // not in menu actions
1450 QList
<QKeySequence
> nextTabKeys
;
1451 nextTabKeys
.append(KStandardShortcut::tabNext().primary());
1452 nextTabKeys
.append(QKeySequence(Qt::CTRL
+ Qt::Key_Tab
));
1454 QList
<QKeySequence
> prevTabKeys
;
1455 prevTabKeys
.append(KStandardShortcut::tabPrev().primary());
1456 prevTabKeys
.append(QKeySequence(Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_Tab
));
1458 KAction
* activateNextTab
= actionCollection()->addAction("activate_next_tab");
1459 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1460 connect(activateNextTab
, SIGNAL(triggered()), SLOT(activateNextTab()));
1461 activateNextTab
->setShortcuts(QApplication::isRightToLeft() ? prevTabKeys
: nextTabKeys
);
1463 KAction
* activatePrevTab
= actionCollection()->addAction("activate_prev_tab");
1464 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1465 connect(activatePrevTab
, SIGNAL(triggered()), SLOT(activatePrevTab()));
1466 activatePrevTab
->setShortcuts(QApplication::isRightToLeft() ? nextTabKeys
: prevTabKeys
);
1469 KAction
* openInNewTab
= actionCollection()->addAction("open_in_new_tab");
1470 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1471 openInNewTab
->setIcon(KIcon("tab-new"));
1472 connect(openInNewTab
, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1474 KAction
* openInNewWindow
= actionCollection()->addAction("open_in_new_window");
1475 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1476 openInNewWindow
->setIcon(KIcon("window-new"));
1477 connect(openInNewWindow
, SIGNAL(triggered()), this, SLOT(openInNewWindow()));
1480 void DolphinMainWindow::setupDockWidgets()
1482 // setup "Information"
1483 QDockWidget
* infoDock
= new QDockWidget(i18nc("@title:window", "Information"));
1484 infoDock
->setObjectName("infoDock");
1485 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1486 Panel
* infoPanel
= new InformationPanel(infoDock
);
1487 connect(infoPanel
, SIGNAL(urlActivated(KUrl
)), this, SLOT(handleUrl(KUrl
)));
1488 infoDock
->setWidget(infoPanel
);
1490 QAction
* infoAction
= infoDock
->toggleViewAction();
1491 infoAction
->setIcon(KIcon("dialog-information"));
1492 infoAction
->setShortcut(Qt::Key_F11
);
1494 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1495 connect(this, SIGNAL(urlChanged(KUrl
)),
1496 infoPanel
, SLOT(setUrl(KUrl
)));
1497 connect(this, SIGNAL(selectionChanged(KFileItemList
)),
1498 infoPanel
, SLOT(setSelection(KFileItemList
)));
1499 connect(this, SIGNAL(requestItemInfo(KFileItem
)),
1500 infoPanel
, SLOT(requestDelayedItemInfo(KFileItem
)));
1503 QDockWidget
* foldersDock
= new QDockWidget(i18nc("@title:window", "Folders"));
1504 foldersDock
->setObjectName("foldersDock");
1505 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1506 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1507 foldersDock
->setWidget(foldersPanel
);
1509 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1510 foldersAction
->setShortcut(Qt::Key_F7
);
1511 foldersAction
->setIcon(KIcon("folder"));
1513 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1514 connect(this, SIGNAL(urlChanged(KUrl
)),
1515 foldersPanel
, SLOT(setUrl(KUrl
)));
1516 connect(foldersPanel
, SIGNAL(changeUrl(KUrl
, Qt::MouseButtons
)),
1517 this, SLOT(handlePlacesClick(KUrl
, Qt::MouseButtons
)));
1521 QDockWidget
* terminalDock
= new QDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1522 terminalDock
->setObjectName("terminalDock");
1523 terminalDock
->setAllowedAreas(Qt::TopDockWidgetArea
| Qt::BottomDockWidgetArea
);
1524 Panel
* terminalPanel
= new TerminalPanel(terminalDock
);
1525 terminalDock
->setWidget(terminalPanel
);
1527 connect(terminalPanel
, SIGNAL(hideTerminalPanel()), terminalDock
, SLOT(hide()));
1529 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1530 terminalAction
->setShortcut(Qt::Key_F4
);
1531 terminalAction
->setIcon(KIcon("utilities-terminal"));
1533 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1534 connect(this, SIGNAL(urlChanged(KUrl
)),
1535 terminalPanel
, SLOT(setUrl(KUrl
)));
1538 const bool firstRun
= DolphinSettings::instance().generalSettings()->firstRun();
1541 foldersDock
->hide();
1543 terminalDock
->hide();
1548 QDockWidget
* placesDock
= new QDockWidget(i18nc("@title:window", "Places"));
1549 placesDock
->setObjectName("placesDock");
1550 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1552 PlacesPanel
* placesPanel
= new PlacesPanel(placesDock
);
1553 placesDock
->setWidget(placesPanel
);
1554 placesPanel
->setModel(DolphinSettings::instance().placesModel());
1555 placesPanel
->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff
);
1557 QAction
* placesAction
= placesDock
->toggleViewAction();
1558 placesAction
->setShortcut(Qt::Key_F9
);
1559 placesAction
->setIcon(KIcon("bookmarks"));
1561 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1562 connect(placesPanel
, SIGNAL(urlChanged(KUrl
, Qt::MouseButtons
)),
1563 this, SLOT(handlePlacesClick(KUrl
, Qt::MouseButtons
)));
1564 connect(this, SIGNAL(urlChanged(KUrl
)),
1565 placesPanel
, SLOT(setUrl(KUrl
)));
1567 KActionMenu
* panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Panels"), this);
1568 actionCollection()->addAction("panels", panelsMenu
);
1569 panelsMenu
->setDelayed(false);
1570 panelsMenu
->addAction(placesAction
);
1571 panelsMenu
->addAction(infoAction
);
1572 panelsMenu
->addAction(foldersAction
);
1574 panelsMenu
->addAction(terminalAction
);
1578 void DolphinMainWindow::updateEditActions()
1580 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1581 if (list
.isEmpty()) {
1582 stateChanged("has_no_selection");
1584 stateChanged("has_selection");
1586 KActionCollection
* col
= actionCollection();
1587 QAction
* renameAction
= col
->action("rename");
1588 QAction
* moveToTrashAction
= col
->action("move_to_trash");
1589 QAction
* deleteAction
= col
->action("delete");
1590 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
1591 QAction
* deleteWithTrashShortcut
= col
->action("delete_shortcut"); // see DolphinViewActionHandler
1593 KFileItemListProperties
capabilities(list
);
1594 const bool enableMoveToTrash
= capabilities
.isLocal() && capabilities
.supportsMoving();
1596 renameAction
->setEnabled(capabilities
.supportsMoving());
1597 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1598 deleteAction
->setEnabled(capabilities
.supportsDeleting());
1599 deleteWithTrashShortcut
->setEnabled(capabilities
.supportsDeleting() && !enableMoveToTrash
);
1600 cutAction
->setEnabled(capabilities
.supportsMoving());
1602 updatePasteAction();
1605 void DolphinMainWindow::updateViewActions()
1607 m_actionHandler
->updateViewActions();
1609 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1610 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
1612 updateSplitAction();
1614 QAction
* editableLocactionAction
= actionCollection()->action("editable_location");
1615 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
1616 editableLocactionAction
->setChecked(urlNavigator
->isUrlEditable());
1619 void DolphinMainWindow::updateGoActions()
1621 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
1622 const KUrl
& currentUrl
= m_activeViewContainer
->url();
1623 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
1626 void DolphinMainWindow::rememberClosedTab(int index
)
1628 KMenu
* tabsMenu
= m_recentTabsMenu
->menu();
1630 const QString primaryPath
= m_viewTab
[index
].primaryView
->url().path();
1631 const QString iconName
= KMimeType::iconNameForUrl(primaryPath
);
1633 QAction
* action
= new QAction(squeezedText(primaryPath
), tabsMenu
);
1635 ClosedTab closedTab
;
1636 closedTab
.primaryUrl
= m_viewTab
[index
].primaryView
->url();
1638 if (m_viewTab
[index
].secondaryView
!= 0) {
1639 closedTab
.secondaryUrl
= m_viewTab
[index
].secondaryView
->url();
1640 closedTab
.isSplit
= true;
1642 closedTab
.isSplit
= false;
1645 action
->setData(QVariant::fromValue(closedTab
));
1646 action
->setIcon(KIcon(iconName
));
1648 // add the closed tab menu entry after the separator and
1649 // "Empty Recently Closed Tabs" entry
1650 if (tabsMenu
->actions().size() == 2) {
1651 tabsMenu
->addAction(action
);
1653 tabsMenu
->insertAction(tabsMenu
->actions().at(2), action
);
1656 // assure that only up to 8 closed tabs are shown in the menu
1657 if (tabsMenu
->actions().size() > 8) {
1658 tabsMenu
->removeAction(tabsMenu
->actions().last());
1660 actionCollection()->action("closed_tabs")->setEnabled(true);
1661 KAcceleratorManager::manage(tabsMenu
);
1664 void DolphinMainWindow::clearStatusBar()
1666 m_activeViewContainer
->statusBar()->clear();
1669 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
1671 connect(container
, SIGNAL(showFilterBarChanged(bool)),
1672 this, SLOT(updateFilterBarAction(bool)));
1673 connect(container
, SIGNAL(writeStateChanged(bool)),
1674 this, SLOT(slotWriteStateChanged(bool)));
1676 DolphinView
* view
= container
->view();
1677 connect(view
, SIGNAL(selectionChanged(KFileItemList
)),
1678 this, SLOT(slotSelectionChanged(KFileItemList
)));
1679 connect(view
, SIGNAL(requestItemInfo(KFileItem
)),
1680 this, SLOT(slotRequestItemInfo(KFileItem
)));
1681 connect(view
, SIGNAL(activated()),
1682 this, SLOT(toggleActiveView()));
1683 connect(view
, SIGNAL(tabRequested(const KUrl
&)),
1684 this, SLOT(openNewTab(const KUrl
&)));
1685 connect(view
, SIGNAL(requestContextMenu(KFileItem
, const KUrl
&, const QList
<QAction
*>&)),
1686 this, SLOT(openContextMenu(KFileItem
, const KUrl
&, const QList
<QAction
*>&)));
1688 const KUrlNavigator
* navigator
= container
->urlNavigator();
1689 connect(navigator
, SIGNAL(urlChanged(const KUrl
&)),
1690 this, SLOT(changeUrl(const KUrl
&)));
1691 connect(navigator
, SIGNAL(historyChanged()),
1692 this, SLOT(updateHistory()));
1693 connect(navigator
, SIGNAL(editableStateChanged(bool)),
1694 this, SLOT(slotEditableStateChanged(bool)));
1695 connect(navigator
, SIGNAL(tabRequested(const KUrl
&)),
1696 this, SLOT(openNewTab(KUrl
)));
1699 void DolphinMainWindow::updateSplitAction()
1701 QAction
* splitAction
= actionCollection()->action("split_view");
1702 if (m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
1703 if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
1704 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
1705 splitAction
->setToolTip(i18nc("@info", "Close right view"));
1706 splitAction
->setIcon(KIcon("view-right-close"));
1708 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
1709 splitAction
->setToolTip(i18nc("@info", "Close left view"));
1710 splitAction
->setIcon(KIcon("view-left-close"));
1713 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
1714 splitAction
->setToolTip(i18nc("@info", "Split view"));
1715 splitAction
->setIcon(KIcon("view-right-new"));
1719 QString
DolphinMainWindow::tabName(const KUrl
& url
) const
1722 if (url
.equals(KUrl("file:///"))) {
1725 name
= url
.fileName();
1726 if (name
.isEmpty()) {
1727 name
= url
.protocol();
1729 // Make sure that a '&' inside the directory name is displayed correctly
1730 // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
1731 name
.replace('&', "&&");
1737 bool DolphinMainWindow::isKompareInstalled() const
1739 static bool initialized
= false;
1740 static bool installed
= false;
1742 // TODO: maybe replace this approach later by using a menu
1743 // plugin like kdiff3plugin.cpp
1744 installed
= !KGlobal::dirs()->findExe("kompare").isEmpty();
1750 void DolphinMainWindow::createSecondaryView(int tabIndex
)
1752 QSplitter
* splitter
= m_viewTab
[tabIndex
].splitter
;
1753 const int newWidth
= (m_viewTab
[tabIndex
].primaryView
->width() - splitter
->handleWidth()) / 2;
1755 const DolphinView
* view
= m_viewTab
[tabIndex
].primaryView
->view();
1756 m_viewTab
[tabIndex
].secondaryView
= new DolphinViewContainer(view
->rootUrl(), 0);
1757 splitter
->addWidget(m_viewTab
[tabIndex
].secondaryView
);
1758 splitter
->setSizes(QList
<int>() << newWidth
<< newWidth
);
1759 connectViewSignals(m_viewTab
[tabIndex
].secondaryView
);
1760 m_viewTab
[tabIndex
].secondaryView
->view()->reload();
1761 m_viewTab
[tabIndex
].secondaryView
->setActive(false);
1762 m_viewTab
[tabIndex
].secondaryView
->show();
1765 QString
DolphinMainWindow::tabProperty(const QString
& property
, int tabIndex
) const
1767 return "Tab " + QString::number(tabIndex
) + ' ' + property
;
1770 void DolphinMainWindow::setUrlAsCaption(const KUrl
& url
)
1773 if (!url
.isLocalFile()) {
1774 caption
.append(url
.protocol() + " - ");
1775 if (url
.hasHost()) {
1776 caption
.append(url
.host() + " - ");
1780 const QString fileName
= url
.fileName().isEmpty() ? "/" : url
.fileName();
1781 caption
.append(fileName
);
1783 setCaption(caption
);
1786 QString
DolphinMainWindow::squeezedText(const QString
& text
) const
1788 const QFontMetrics fm
= fontMetrics();
1789 return fm
.elidedText(text
, Qt::ElideMiddle
, fm
.maxWidth() * 10);
1792 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
1793 KIO::FileUndoManager::UiInterface()
1797 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
1801 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
1803 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
1805 DolphinStatusBar
* statusBar
= mainWin
->activeViewContainer()->statusBar();
1806 statusBar
->setMessage(job
->errorString(), DolphinStatusBar::Error
);
1808 KIO::FileUndoManager::UiInterface::jobError(job
);
1812 #include "dolphinmainwindow.moc"