1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz19@gmail.com> *
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 "dolphindockwidget.h"
28 #include "dolphincontextmenu.h"
29 #include "dolphinnewfilemenu.h"
30 #include "dolphinviewcontainer.h"
31 #include "mainwindowadaptor.h"
33 #include "panels/search/searchpanel.h"
34 #include <Nepomuk/ResourceManager>
36 #include "panels/folders/folderspanel.h"
37 #include "panels/places/placespanel.h"
38 #include "panels/information/informationpanel.h"
39 #include "search/dolphinsearchinformation.h"
40 #include "settings/dolphinsettings.h"
41 #include "settings/dolphinsettingsdialog.h"
42 #include "statusbar/dolphinstatusbar.h"
43 #include "views/dolphinviewactionhandler.h"
44 #include "views/dolphinremoteencoding.h"
45 #include "views/draganddrophelper.h"
46 #include "views/viewproperties.h"
49 #include "panels/terminal/terminalpanel.h"
52 #include "dolphin_generalsettings.h"
53 #include "dolphin_iconsmodesettings.h"
54 #include "dolphin_searchsettings.h"
57 #include <KActionCollection>
58 #include <KActionMenu>
60 #include <KDesktopFile>
61 #include <kdeversion.h>
62 #include <kdualaction.h>
63 #include <KFileDialog>
64 #include <KFilePlacesModel>
69 #include <KIconLoader>
70 #include <KIO/NetAccess>
71 #include <KInputDialog>
73 #include <KProtocolManager>
76 #include <KMessageBox>
77 #include <KFileItemListProperties>
78 #include <konqmimedata.h>
79 #include <KProtocolInfo>
82 #include <KStandardDirs>
83 #include <kstatusbar.h>
84 #include <KStandardAction>
86 #include <KToggleAction>
87 #include <KUrlNavigator>
89 #include <KUrlComboBox>
90 #include <KToolInvocation>
92 #include <QDBusMessage>
96 #include <kacceleratormanager.h>
99 * Remembers the tab configuration if a tab has been closed.
100 * Each closed tab can be restored by the menu
101 * "Go -> Recently Closed Tabs".
109 Q_DECLARE_METATYPE(ClosedTab
)
111 DolphinMainWindow::DolphinMainWindow(int id
) :
116 m_activeViewContainer(0),
117 m_centralWidgetLayout(0),
124 m_lastHandleUrlStatJob(0),
125 m_searchDockIsTemporaryVisible(false)
127 // Workaround for a X11-issue in combination with KModifierInfo
128 // (see DolphinContextMenu::initializeModifierKeyInfo() for
129 // more information):
130 DolphinContextMenu::initializeModifierKeyInfo();
132 setObjectName("Dolphin#");
134 m_viewTab
.append(ViewTab());
136 new MainWindowAdaptor(this);
137 QDBusConnection::sessionBus().registerObject(QString("/dolphin/MainWindow%1").arg(m_id
), this);
139 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
140 undoManager
->setUiInterface(new UndoUiInterface());
142 connect(undoManager
, SIGNAL(undoAvailable(bool)),
143 this, SLOT(slotUndoAvailable(bool)));
144 connect(undoManager
, SIGNAL(undoTextChanged(const QString
&)),
145 this, SLOT(slotUndoTextChanged(const QString
&)));
146 connect(undoManager
, SIGNAL(jobRecordingStarted(CommandType
)),
147 this, SLOT(clearStatusBar()));
148 connect(undoManager
, SIGNAL(jobRecordingFinished(CommandType
)),
149 this, SLOT(showCommand(CommandType
)));
150 connect(DolphinSettings::instance().placesModel(), SIGNAL(errorMessage(const QString
&)),
151 this, SLOT(showErrorMessage(const QString
&)));
152 connect(&DragAndDropHelper::instance(), SIGNAL(errorMessage(const QString
&)),
153 this, SLOT(showErrorMessage(const QString
&)));
156 DolphinMainWindow::~DolphinMainWindow()
158 DolphinApplication::app()->removeMainWindow(this);
161 void DolphinMainWindow::openDirectories(const QList
<KUrl
>& dirs
)
163 if (dirs
.isEmpty()) {
167 if (dirs
.count() == 1) {
168 m_activeViewContainer
->setUrl(dirs
.first());
172 const int oldOpenTabsCount
= m_viewTab
.count();
174 const GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
175 const bool hasSplitView
= generalSettings
->splitView();
177 // Open each directory inside a new tab. If the "split view" option has been enabled,
178 // always show two directories within one tab.
179 QList
<KUrl
>::const_iterator it
= dirs
.begin();
180 while (it
!= dirs
.end()) {
184 if (hasSplitView
&& (it
!= dirs
.end())) {
185 const int tabIndex
= m_viewTab
.count() - 1;
186 m_viewTab
[tabIndex
].secondaryView
->setUrl(*it
);
191 // remove the previously opened tabs
192 for (int i
= 0; i
< oldOpenTabsCount
; ++i
) {
197 void DolphinMainWindow::openFiles(const QList
<KUrl
>& files
)
199 if (files
.isEmpty()) {
203 // Get all distinct directories from 'files' and open a tab
204 // for each directory. If the "split view" option is enabled, two
205 // directories are shown inside one tab (see openDirectories()).
207 foreach (const KUrl
& url
, files
) {
208 const KUrl
dir(url
.directory());
209 if (!dirs
.contains(dir
)) {
214 openDirectories(dirs
);
216 // Select the files. Although the files can be split between several
217 // tabs, there is no need to split 'files' accordingly, as
218 // the DolphinView will just ignore invalid selections.
219 const int tabCount
= m_viewTab
.count();
220 for (int i
= 0; i
< tabCount
; ++i
) {
221 m_viewTab
[i
].primaryView
->view()->markUrlsAsSelected(files
);
222 if (m_viewTab
[i
].secondaryView
) {
223 m_viewTab
[i
].secondaryView
->view()->markUrlsAsSelected(files
);
228 void DolphinMainWindow::showCommand(CommandType command
)
230 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
232 case KIO::FileUndoManager::Copy
:
233 statusBar
->setMessage(i18nc("@info:status", "Successfully copied."),
234 DolphinStatusBar::OperationCompleted
);
236 case KIO::FileUndoManager::Move
:
237 statusBar
->setMessage(i18nc("@info:status", "Successfully moved."),
238 DolphinStatusBar::OperationCompleted
);
240 case KIO::FileUndoManager::Link
:
241 statusBar
->setMessage(i18nc("@info:status", "Successfully linked."),
242 DolphinStatusBar::OperationCompleted
);
244 case KIO::FileUndoManager::Trash
:
245 statusBar
->setMessage(i18nc("@info:status", "Successfully moved to trash."),
246 DolphinStatusBar::OperationCompleted
);
248 case KIO::FileUndoManager::Rename
:
249 statusBar
->setMessage(i18nc("@info:status", "Successfully renamed."),
250 DolphinStatusBar::OperationCompleted
);
253 case KIO::FileUndoManager::Mkdir
:
254 statusBar
->setMessage(i18nc("@info:status", "Created folder."),
255 DolphinStatusBar::OperationCompleted
);
263 void DolphinMainWindow::refreshViews()
265 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
267 // remember the current active view, as because of
268 // the refreshing the active view might change to
269 // the secondary view
270 DolphinViewContainer
* activeViewContainer
= m_activeViewContainer
;
272 const int tabCount
= m_viewTab
.count();
273 for (int i
= 0; i
< tabCount
; ++i
) {
274 m_viewTab
[i
].primaryView
->refresh();
275 if (m_viewTab
[i
].secondaryView
) {
276 m_viewTab
[i
].secondaryView
->refresh();
280 setActiveViewContainer(activeViewContainer
);
282 const GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
283 if (generalSettings
->modifiedStartupSettings()) {
284 // The startup settings have been changed by the user (see bug #254947).
285 // Synchronize the split-view setting with the active view:
286 const bool splitView
= generalSettings
->splitView();
287 const ViewTab
& activeTab
= m_viewTab
[m_tabIndex
];
288 const bool toggle
= ( splitView
&& !activeTab
.secondaryView
)
289 || (!splitView
&& activeTab
.secondaryView
);
296 void DolphinMainWindow::pasteIntoFolder()
298 m_activeViewContainer
->view()->pasteIntoFolder();
301 void DolphinMainWindow::changeUrl(const KUrl
& url
)
303 if (!KProtocolManager::supportsListing(url
)) {
304 // The URL navigator only checks for validity, not
305 // if the URL can be listed. An error message is
306 // shown due to DolphinViewContainer::restoreView().
310 DolphinViewContainer
* view
= activeViewContainer();
316 setUrlAsCaption(url
);
317 if (m_viewTab
.count() > 1) {
318 m_tabBar
->setTabText(m_tabIndex
, squeezedText(tabName(m_activeViewContainer
->url())));
320 const QString iconName
= KMimeType::iconNameForUrl(url
);
321 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(iconName
));
322 emit
urlChanged(url
);
326 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
328 KToggleAction
* editableLocationAction
=
329 static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
330 editableLocationAction
->setChecked(editable
);
333 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
337 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
338 int selectedUrlsCount
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedItemsCount();
339 if (m_viewTab
[m_tabIndex
].secondaryView
) {
340 selectedUrlsCount
+= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItemsCount();
343 QAction
* compareFilesAction
= actionCollection()->action("compare_files");
344 if (selectedUrlsCount
== 2) {
345 compareFilesAction
->setEnabled(isKompareInstalled());
347 compareFilesAction
->setEnabled(false);
350 emit
selectionChanged(selection
);
353 void DolphinMainWindow::slotRequestItemInfo(const KFileItem
& item
)
355 emit
requestItemInfo(item
);
358 void DolphinMainWindow::updateHistory()
360 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
361 const int index
= urlNavigator
->historyIndex();
363 QAction
* backAction
= actionCollection()->action("go_back");
364 backAction
->setToolTip(i18nc("@info", "Go back"));
366 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
369 QAction
* forwardAction
= actionCollection()->action("go_forward");
370 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
372 forwardAction
->setEnabled(index
> 0);
376 void DolphinMainWindow::updateFilterBarAction(bool show
)
378 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
379 showFilterBarAction
->setChecked(show
);
382 void DolphinMainWindow::openNewMainWindow()
384 DolphinApplication::app()->createMainWindow()->show();
387 void DolphinMainWindow::openNewTab()
389 const bool isUrlEditable
= m_activeViewContainer
->urlNavigator()->isUrlEditable();
391 openNewTab(m_activeViewContainer
->url());
392 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
394 // The URL navigator of the new tab should have the same editable state
395 // as the current tab
396 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
397 navigator
->setUrlEditable(isUrlEditable
);
400 // If a new tab is opened and the URL is editable, assure that
401 // the user can edit the URL without manually setting the focus
402 navigator
->setFocus();
406 void DolphinMainWindow::openNewTab(const KUrl
& url
)
408 QWidget
* focusWidget
= QApplication::focusWidget();
410 if (m_viewTab
.count() == 1) {
411 // Only one view is open currently and hence no tab is shown at
412 // all. Before creating a tab for 'url', provide a tab for the current URL.
413 const KUrl currentUrl
= m_activeViewContainer
->url();
414 m_tabBar
->addTab(KIcon(KMimeType::iconNameForUrl(currentUrl
)),
415 squeezedText(tabName(currentUrl
)));
416 m_tabBar
->blockSignals(false);
419 m_tabBar
->addTab(KIcon(KMimeType::iconNameForUrl(url
)),
420 squeezedText(tabName(url
)));
423 viewTab
.splitter
= new QSplitter(this);
424 viewTab
.splitter
->setChildrenCollapsible(false);
425 viewTab
.primaryView
= createViewContainer(url
, viewTab
.splitter
);
426 viewTab
.primaryView
->setActive(false);
427 connectViewSignals(viewTab
.primaryView
);
429 m_viewTab
.append(viewTab
);
431 actionCollection()->action("close_tab")->setEnabled(true);
433 // provide a split view, if the startup settings are set this way
434 const GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
435 if (generalSettings
->splitView()) {
436 const int tabIndex
= m_viewTab
.count() - 1;
437 createSecondaryView(tabIndex
);
438 m_viewTab
[tabIndex
].secondaryView
->setActive(true);
439 m_viewTab
[tabIndex
].isPrimaryViewActive
= false;
443 // The DolphinViewContainer grabbed the keyboard focus. As the tab is opened
444 // in background, assure that the previous focused widget gets the focus back.
445 focusWidget
->setFocus();
449 void DolphinMainWindow::activateNextTab()
451 if ((m_viewTab
.count() == 1) || (m_tabBar
->count() < 2)) {
455 const int tabIndex
= (m_tabBar
->currentIndex() + 1) % m_tabBar
->count();
456 m_tabBar
->setCurrentIndex(tabIndex
);
459 void DolphinMainWindow::activatePrevTab()
461 if ((m_viewTab
.count() == 1) || (m_tabBar
->count() < 2)) {
465 int tabIndex
= m_tabBar
->currentIndex() - 1;
466 if (tabIndex
== -1) {
467 tabIndex
= m_tabBar
->count() - 1;
469 m_tabBar
->setCurrentIndex(tabIndex
);
472 void DolphinMainWindow::openInNewTab()
474 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
475 if (list
.isEmpty()) {
476 openNewTab(m_activeViewContainer
->url());
477 } else if ((list
.count() == 1) && list
[0].isDir()) {
478 openNewTab(list
[0].url());
482 void DolphinMainWindow::openInNewWindow()
486 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
487 if (list
.isEmpty()) {
488 newWindowUrl
= m_activeViewContainer
->url();
489 } else if ((list
.count() == 1) && list
[0].isDir()) {
490 newWindowUrl
= list
[0].url();
493 if (!newWindowUrl
.isEmpty()) {
494 DolphinMainWindow
* window
= DolphinApplication::app()->createMainWindow();
495 window
->changeUrl(newWindowUrl
);
500 void DolphinMainWindow::toggleActiveView()
502 if (!m_viewTab
[m_tabIndex
].secondaryView
) {
503 // only one view is available
507 Q_ASSERT(m_activeViewContainer
);
508 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
510 DolphinViewContainer
* left
= m_viewTab
[m_tabIndex
].primaryView
;
511 DolphinViewContainer
* right
= m_viewTab
[m_tabIndex
].secondaryView
;
512 setActiveViewContainer(m_activeViewContainer
== right
? left
: right
);
515 void DolphinMainWindow::showEvent(QShowEvent
* event
)
517 KXmlGuiWindow::showEvent(event
);
518 if (!event
->spontaneous()) {
519 m_activeViewContainer
->view()->setFocus();
523 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
525 DolphinSettings
& settings
= DolphinSettings::instance();
526 GeneralSettings
* generalSettings
= settings
.generalSettings();
528 // Find out if Dolphin is closed directly by the user or
529 // by the session manager because the session is closed
530 bool closedByUser
= true;
531 DolphinApplication
*application
= qobject_cast
<DolphinApplication
*>(qApp
);
532 if (application
&& application
->sessionSaving()) {
533 closedByUser
= false;
536 if ((m_viewTab
.count() > 1) && generalSettings
->confirmClosingMultipleTabs() && closedByUser
) {
537 // Ask the user if he really wants to quit and close all tabs.
538 // Open a confirmation dialog with 3 buttons:
539 // KDialog::Yes -> Quit
540 // KDialog::No -> Close only the current tab
541 // KDialog::Cancel -> do nothing
542 KDialog
*dialog
= new KDialog(this, Qt::Dialog
);
543 dialog
->setCaption(i18nc("@title:window", "Confirmation"));
544 dialog
->setButtons(KDialog::Yes
| KDialog::No
| KDialog::Cancel
);
545 dialog
->setModal(true);
546 dialog
->setButtonGuiItem(KDialog::Yes
, KStandardGuiItem::quit());
547 dialog
->setButtonGuiItem(KDialog::No
, KGuiItem(i18n("C&lose Current Tab"), KIcon("tab-close")));
548 dialog
->setButtonGuiItem(KDialog::Cancel
, KStandardGuiItem::cancel());
549 dialog
->setDefaultButton(KDialog::Yes
);
551 bool doNotAskAgainCheckboxResult
= false;
553 const int result
= KMessageBox::createKMessageBox(dialog
,
554 QMessageBox::Warning
,
555 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
557 i18n("Do not ask again"),
558 &doNotAskAgainCheckboxResult
,
559 KMessageBox::Notify
);
561 if (doNotAskAgainCheckboxResult
) {
562 generalSettings
->setConfirmClosingMultipleTabs(false);
570 // Close only the current tab
578 generalSettings
->setFirstRun(false);
582 if (m_searchDockIsTemporaryVisible
) {
583 QDockWidget
* searchDock
= findChild
<QDockWidget
*>("searchDock");
587 m_searchDockIsTemporaryVisible
= false;
590 KXmlGuiWindow::closeEvent(event
);
593 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
595 const int tabCount
= m_viewTab
.count();
596 group
.writeEntry("Tab Count", tabCount
);
597 group
.writeEntry("Active Tab Index", m_tabBar
->currentIndex());
599 for (int i
= 0; i
< tabCount
; ++i
) {
600 const DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
601 group
.writeEntry(tabProperty("Primary URL", i
), cont
->url().url());
602 group
.writeEntry(tabProperty("Primary Editable", i
),
603 cont
->urlNavigator()->isUrlEditable());
605 cont
= m_viewTab
[i
].secondaryView
;
607 group
.writeEntry(tabProperty("Secondary URL", i
), cont
->url().url());
608 group
.writeEntry(tabProperty("Secondary Editable", i
),
609 cont
->urlNavigator()->isUrlEditable());
614 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
616 const int tabCount
= group
.readEntry("Tab Count", 1);
617 for (int i
= 0; i
< tabCount
; ++i
) {
618 DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
620 cont
->setUrl(group
.readEntry(tabProperty("Primary URL", i
)));
621 const bool editable
= group
.readEntry(tabProperty("Primary Editable", i
), false);
622 cont
->urlNavigator()->setUrlEditable(editable
);
624 cont
= m_viewTab
[i
].secondaryView
;
625 const QString secondaryUrl
= group
.readEntry(tabProperty("Secondary URL", i
));
626 if (!secondaryUrl
.isEmpty()) {
628 // a secondary view should be shown, but no one is available
629 // currently -> create a new view
631 cont
= m_viewTab
[i
].secondaryView
;
635 cont
->setUrl(secondaryUrl
);
636 const bool editable
= group
.readEntry(tabProperty("Secondary Editable", i
), false);
637 cont
->urlNavigator()->setUrlEditable(editable
);
639 // no secondary view should be shown, but the default setting shows
640 // one already -> close the view
644 // openNewTab() needs to be called only tabCount - 1 times
645 if (i
!= tabCount
- 1) {
650 const int index
= group
.readEntry("Active Tab Index", 0);
651 m_tabBar
->setCurrentIndex(index
);
654 void DolphinMainWindow::updateNewMenu()
656 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->showHiddenFiles());
657 m_newFileMenu
->checkUpToDate();
658 m_newFileMenu
->setPopupFiles(activeViewContainer()->url());
661 void DolphinMainWindow::createDirectory()
663 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->showHiddenFiles());
664 m_newFileMenu
->setPopupFiles(activeViewContainer()->url());
665 m_newFileMenu
->createDirectory();
668 void DolphinMainWindow::quit()
673 void DolphinMainWindow::showErrorMessage(const QString
& message
)
675 if (!message
.isEmpty()) {
676 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
677 statusBar
->setMessage(message
, DolphinStatusBar::Error
);
681 void DolphinMainWindow::slotUndoAvailable(bool available
)
683 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
685 undoAction
->setEnabled(available
);
689 void DolphinMainWindow::restoreClosedTab(QAction
* action
)
691 if (action
->data().toBool()) {
692 // clear all actions except the "Empty Recently Closed Tabs"
693 // action and the separator
694 QList
<QAction
*> actions
= m_recentTabsMenu
->menu()->actions();
695 const int count
= actions
.size();
696 for (int i
= 2; i
< count
; ++i
) {
697 m_recentTabsMenu
->menu()->removeAction(actions
.at(i
));
700 const ClosedTab closedTab
= action
->data().value
<ClosedTab
>();
701 openNewTab(closedTab
.primaryUrl
);
702 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
704 if (closedTab
.isSplit
) {
705 // create secondary view
707 m_viewTab
[m_tabIndex
].secondaryView
->setUrl(closedTab
.secondaryUrl
);
710 m_recentTabsMenu
->removeAction(action
);
713 if (m_recentTabsMenu
->menu()->actions().count() == 2) {
714 m_recentTabsMenu
->setEnabled(false);
718 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
720 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
722 undoAction
->setText(text
);
726 void DolphinMainWindow::undo()
729 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
730 KIO::FileUndoManager::self()->undo();
733 void DolphinMainWindow::cut()
735 m_activeViewContainer
->view()->cutSelectedItems();
738 void DolphinMainWindow::copy()
740 m_activeViewContainer
->view()->copySelectedItems();
743 void DolphinMainWindow::paste()
745 m_activeViewContainer
->view()->paste();
748 void DolphinMainWindow::find()
750 m_activeViewContainer
->setSearchModeEnabled(true);
753 void DolphinMainWindow::updatePasteAction()
755 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
756 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
757 pasteAction
->setEnabled(pasteInfo
.first
);
758 pasteAction
->setText(pasteInfo
.second
);
761 void DolphinMainWindow::selectAll()
765 // if the URL navigator is editable and focused, select the whole
766 // URL instead of all items of the view
768 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
769 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit(); // krazy:exclude=qclasses
770 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
771 lineEdit
->hasFocus();
773 lineEdit
->selectAll();
775 m_activeViewContainer
->view()->selectAll();
779 void DolphinMainWindow::invertSelection()
782 m_activeViewContainer
->view()->invertSelection();
785 void DolphinMainWindow::toggleSplitView()
787 if (!m_viewTab
[m_tabIndex
].secondaryView
) {
788 createSecondaryView(m_tabIndex
);
789 setActiveViewContainer(m_viewTab
[m_tabIndex
].secondaryView
);
790 } else if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
791 // remove secondary view
792 m_viewTab
[m_tabIndex
].secondaryView
->close();
793 m_viewTab
[m_tabIndex
].secondaryView
->deleteLater();
794 m_viewTab
[m_tabIndex
].secondaryView
= 0;
796 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
798 // The primary view is active and should be closed. Hence from a users point of view
799 // the content of the secondary view should be moved to the primary view.
800 // From an implementation point of view it is more efficient to close
801 // the primary view and exchange the internal pointers afterwards.
803 m_viewTab
[m_tabIndex
].primaryView
->close();
804 m_viewTab
[m_tabIndex
].primaryView
->deleteLater();
805 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
806 m_viewTab
[m_tabIndex
].secondaryView
= 0;
808 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
814 void DolphinMainWindow::reloadView()
817 m_activeViewContainer
->view()->reload();
820 void DolphinMainWindow::stopLoading()
822 m_activeViewContainer
->view()->stopLoading();
825 void DolphinMainWindow::enableStopAction()
827 actionCollection()->action("stop")->setEnabled(true);
830 void DolphinMainWindow::disableStopAction()
832 actionCollection()->action("stop")->setEnabled(false);
835 void DolphinMainWindow::showFilterBar()
837 m_activeViewContainer
->setFilterBarVisible(true);
840 void DolphinMainWindow::toggleEditLocation()
844 QAction
* action
= actionCollection()->action("editable_location");
845 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
846 urlNavigator
->setUrlEditable(action
->isChecked());
849 void DolphinMainWindow::replaceLocation()
851 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
852 navigator
->setUrlEditable(true);
853 navigator
->setFocus();
855 // select the whole text of the combo box editor
856 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit(); // krazy:exclude=qclasses
857 lineEdit
->selectAll();
860 void DolphinMainWindow::togglePanelLockState()
862 GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
864 const bool newLockState
= !generalSettings
->lockPanels();
865 foreach (QObject
* child
, children()) {
866 DolphinDockWidget
* dock
= qobject_cast
<DolphinDockWidget
*>(child
);
868 dock
->setLocked(newLockState
);
872 generalSettings
->setLockPanels(newLockState
);
875 void DolphinMainWindow::slotPlacesPanelVisibilityChanged(bool visible
)
877 const int tabCount
= m_viewTab
.count();
878 for (int i
= 0; i
< tabCount
; ++i
) {
879 ViewTab
& tab
= m_viewTab
[i
];
880 Q_ASSERT(tab
.primaryView
);
881 tab
.primaryView
->urlNavigator()->setPlacesSelectorVisible(!visible
);
882 if (tab
.secondaryView
) {
883 tab
.secondaryView
->urlNavigator()->setPlacesSelectorVisible(!visible
);
888 void DolphinMainWindow::goBack()
892 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
893 urlNavigator
->goBack();
895 if (urlNavigator
->locationState().isEmpty()) {
896 // An empty location state indicates a redirection URL,
897 // which must be skipped too
898 urlNavigator
->goBack();
902 void DolphinMainWindow::goForward()
905 m_activeViewContainer
->urlNavigator()->goForward();
908 void DolphinMainWindow::goUp()
911 m_activeViewContainer
->urlNavigator()->goUp();
914 void DolphinMainWindow::goBack(Qt::MouseButtons buttons
)
916 // The default case (left button pressed) is handled in goBack().
917 if (buttons
== Qt::MidButton
) {
918 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
919 const int index
= urlNavigator
->historyIndex() + 1;
920 openNewTab(urlNavigator
->locationUrl(index
));
924 void DolphinMainWindow::goForward(Qt::MouseButtons buttons
)
926 // The default case (left button pressed) is handled in goForward().
927 if (buttons
== Qt::MidButton
) {
928 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
929 const int index
= urlNavigator
->historyIndex() - 1;
930 openNewTab(urlNavigator
->locationUrl(index
));
934 void DolphinMainWindow::goUp(Qt::MouseButtons buttons
)
936 // The default case (left button pressed) is handled in goUp().
937 if (buttons
== Qt::MidButton
) {
938 openNewTab(activeViewContainer()->url().upUrl());
942 void DolphinMainWindow::goHome()
945 m_activeViewContainer
->urlNavigator()->goHome();
948 void DolphinMainWindow::compareFiles()
950 // The method is only invoked if exactly 2 files have
951 // been selected. The selected files may be:
952 // - both in the primary view
953 // - both in the secondary view
954 // - one in the primary view and the other in the secondary
956 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
961 KFileItemList items
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedItems();
963 switch (items
.count()) {
965 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
);
966 items
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItems();
967 Q_ASSERT(items
.count() == 2);
968 urlA
= items
[0].url();
969 urlB
= items
[1].url();
974 urlA
= items
[0].url();
975 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
);
976 items
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItems();
977 Q_ASSERT(items
.count() == 1);
978 urlB
= items
[0].url();
983 urlA
= items
[0].url();
984 urlB
= items
[1].url();
989 // may not happen: compareFiles may only get invoked if 2
990 // files are selected
995 QString
command("kompare -c \"");
996 command
.append(urlA
.pathOrUrl());
997 command
.append("\" \"");
998 command
.append(urlB
.pathOrUrl());
999 command
.append('\"');
1000 KRun::runCommand(command
, "Kompare", "kompare", this);
1003 void DolphinMainWindow::toggleShowMenuBar()
1005 const bool visible
= menuBar()->isVisible();
1006 menuBar()->setVisible(!visible
);
1009 void DolphinMainWindow::openTerminal()
1011 QString
dir(QDir::homePath());
1013 // If the given directory is not local, it can still be the URL of an
1014 // ioslave using UDS_LOCAL_PATH which to be converted first.
1015 KUrl url
= KIO::NetAccess::mostLocalUrl(m_activeViewContainer
->url(), this);
1017 //If the URL is local after the above conversion, set the directory.
1018 if (url
.isLocalFile()) {
1019 dir
= url
.toLocalFile();
1022 KToolInvocation::invokeTerminal(QString(), dir
);
1025 void DolphinMainWindow::editSettings()
1027 if (!m_settingsDialog
) {
1028 const KUrl url
= activeViewContainer()->url();
1029 m_settingsDialog
= new DolphinSettingsDialog(url
, this);
1030 m_settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1031 m_settingsDialog
->show();
1033 m_settingsDialog
->raise();
1037 void DolphinMainWindow::setActiveTab(int index
)
1039 Q_ASSERT(index
>= 0);
1040 Q_ASSERT(index
< m_viewTab
.count());
1041 if (index
== m_tabIndex
) {
1045 // hide current tab content
1046 ViewTab
& hiddenTab
= m_viewTab
[m_tabIndex
];
1047 hiddenTab
.isPrimaryViewActive
= hiddenTab
.primaryView
->isActive();
1048 hiddenTab
.primaryView
->setActive(false);
1049 if (hiddenTab
.secondaryView
) {
1050 hiddenTab
.secondaryView
->setActive(false);
1052 QSplitter
* splitter
= m_viewTab
[m_tabIndex
].splitter
;
1054 m_centralWidgetLayout
->removeWidget(splitter
);
1056 // show active tab content
1059 ViewTab
& viewTab
= m_viewTab
[index
];
1060 m_centralWidgetLayout
->addWidget(viewTab
.splitter
, 1);
1061 viewTab
.primaryView
->show();
1062 if (viewTab
.secondaryView
) {
1063 viewTab
.secondaryView
->show();
1065 viewTab
.splitter
->show();
1067 setActiveViewContainer(viewTab
.isPrimaryViewActive
? viewTab
.primaryView
:
1068 viewTab
.secondaryView
);
1071 void DolphinMainWindow::closeTab()
1073 closeTab(m_tabBar
->currentIndex());
1076 void DolphinMainWindow::closeTab(int index
)
1078 Q_ASSERT(index
>= 0);
1079 Q_ASSERT(index
< m_viewTab
.count());
1080 if (m_viewTab
.count() == 1) {
1081 // the last tab may never get closed
1085 if (index
== m_tabIndex
) {
1086 // The tab that should be closed is the active tab. Activate the
1087 // previous tab before closing the tab.
1088 m_tabBar
->setCurrentIndex((index
> 0) ? index
- 1 : 1);
1090 rememberClosedTab(index
);
1093 m_viewTab
[index
].primaryView
->deleteLater();
1094 if (m_viewTab
[index
].secondaryView
) {
1095 m_viewTab
[index
].secondaryView
->deleteLater();
1097 m_viewTab
[index
].splitter
->deleteLater();
1098 m_viewTab
.erase(m_viewTab
.begin() + index
);
1100 m_tabBar
->blockSignals(true);
1101 m_tabBar
->removeTab(index
);
1103 if (m_tabIndex
> index
) {
1105 Q_ASSERT(m_tabIndex
>= 0);
1108 // if only one tab is left, also remove the tab entry so that
1109 // closing the last tab is not possible
1110 if (m_viewTab
.count() == 1) {
1111 m_tabBar
->removeTab(0);
1112 actionCollection()->action("close_tab")->setEnabled(false);
1114 m_tabBar
->blockSignals(false);
1118 void DolphinMainWindow::openTabContextMenu(int index
, const QPoint
& pos
)
1122 QAction
* newTabAction
= menu
.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab"));
1123 newTabAction
->setShortcut(actionCollection()->action("new_tab")->shortcut());
1125 QAction
* detachTabAction
= menu
.addAction(KIcon("tab-detach"), i18nc("@action:inmenu", "Detach Tab"));
1127 QAction
* closeOtherTabsAction
= menu
.addAction(KIcon("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs"));
1129 QAction
* closeTabAction
= menu
.addAction(KIcon("tab-close"), i18nc("@action:inmenu", "Close Tab"));
1130 closeTabAction
->setShortcut(actionCollection()->action("close_tab")->shortcut());
1131 QAction
* selectedAction
= menu
.exec(pos
);
1132 if (selectedAction
== newTabAction
) {
1133 const ViewTab
& tab
= m_viewTab
[index
];
1134 Q_ASSERT(tab
.primaryView
);
1135 const KUrl url
= tab
.secondaryView
&& tab
.secondaryView
->isActive() ?
1136 tab
.secondaryView
->url() : tab
.primaryView
->url();
1138 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
1139 } else if (selectedAction
== detachTabAction
) {
1140 const ViewTab
& tab
= m_viewTab
[index
];
1141 Q_ASSERT(tab
.primaryView
);
1142 const KUrl primaryUrl
= tab
.primaryView
->url();
1143 DolphinMainWindow
* window
= DolphinApplication::app()->createMainWindow();
1144 window
->changeUrl(primaryUrl
);
1146 if (tab
.secondaryView
) {
1147 const KUrl secondaryUrl
= tab
.secondaryView
->url();
1148 if (!window
->m_viewTab
[0].secondaryView
) {
1149 window
->toggleSplitView();
1151 window
->m_viewTab
[0].secondaryView
->setUrl(secondaryUrl
);
1152 if (tab
.primaryView
->isActive()) {
1153 window
->m_viewTab
[0].primaryView
->setActive(true);
1155 window
->m_viewTab
[0].secondaryView
->setActive(true);
1160 } else if (selectedAction
== closeOtherTabsAction
) {
1161 const int count
= m_tabBar
->count();
1162 for (int i
= 0; i
< index
; ++i
) {
1165 for (int i
= index
+ 1; i
< count
; ++i
) {
1168 } else if (selectedAction
== closeTabAction
) {
1173 void DolphinMainWindow::slotTabMoved(int from
, int to
)
1175 m_viewTab
.move(from
, to
);
1176 m_tabIndex
= m_tabBar
->currentIndex();
1179 void DolphinMainWindow::handlePlacesClick(const KUrl
& url
, Qt::MouseButtons buttons
)
1181 if (buttons
& Qt::MidButton
) {
1183 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
1189 void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent
* event
, bool& canDecode
)
1191 canDecode
= KUrl::List::canDecode(event
->mimeData());
1194 void DolphinMainWindow::handleUrl(const KUrl
& url
)
1196 delete m_lastHandleUrlStatJob
;
1197 m_lastHandleUrlStatJob
= 0;
1199 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1200 activeViewContainer()->setUrl(url
);
1201 } else if (KProtocolManager::supportsListing(url
)) {
1202 // stat the URL to see if it is a dir or not
1203 m_lastHandleUrlStatJob
= KIO::stat(url
, KIO::HideProgressInfo
);
1204 connect(m_lastHandleUrlStatJob
, SIGNAL(result(KJob
*)),
1205 this, SLOT(slotHandleUrlStatFinished(KJob
*)));
1208 new KRun(url
, this);
1212 void DolphinMainWindow::slotHandleUrlStatFinished(KJob
* job
)
1214 m_lastHandleUrlStatJob
= 0;
1215 const KIO::UDSEntry entry
= static_cast<KIO::StatJob
*>(job
)->statResult();
1216 const KUrl url
= static_cast<KIO::StatJob
*>(job
)->url();
1217 if (entry
.isDir()) {
1218 activeViewContainer()->setUrl(url
);
1220 new KRun(url
, this);
1224 void DolphinMainWindow::tabDropEvent(int tab
, QDropEvent
* event
)
1226 const KUrl::List urls
= KUrl::List::fromMimeData(event
->mimeData());
1227 if (!urls
.isEmpty() && tab
!= -1) {
1228 const ViewTab
& viewTab
= m_viewTab
[tab
];
1229 const KUrl destPath
= viewTab
.isPrimaryViewActive
? viewTab
.primaryView
->url() : viewTab
.secondaryView
->url();
1230 DragAndDropHelper::instance().dropUrls(KFileItem(), destPath
, event
, m_tabBar
);
1234 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1236 newFileMenu()->setEnabled(isFolderWritable
);
1239 void DolphinMainWindow::slotSearchModeChanged(bool enabled
)
1242 const KUrl url
= m_activeViewContainer
->url();
1243 const DolphinSearchInformation
& searchInfo
= DolphinSearchInformation::instance();
1244 if (!searchInfo
.isIndexingEnabled() || !searchInfo
.isPathIndexed(url
)) {
1248 QDockWidget
* searchDock
= findChild
<QDockWidget
*>("searchDock");
1254 if (!searchDock
->isVisible()) {
1255 m_searchDockIsTemporaryVisible
= true;
1259 if (searchDock
->isVisible() && m_searchDockIsTemporaryVisible
) {
1262 m_searchDockIsTemporaryVisible
= false;
1265 SearchPanel
* searchPanel
= qobject_cast
<SearchPanel
*>(searchDock
->widget());
1267 // Per default any search-operation triggered by the Search Panel is done
1269 SearchPanel::SearchMode searchMode
= SearchPanel::Everywhere
;
1271 if (enabled
&& (SearchSettings::location() == QLatin1String("FromHere"))) {
1272 // Only if the search-mode is enabled it is visible for the user whether
1273 // a searching is done "Everywhere" or "From Here" (= current directory).
1274 searchMode
= SearchPanel::FromCurrentDir
;
1276 searchPanel
->setSearchMode(searchMode
);
1283 void DolphinMainWindow::openContextMenu(const KFileItem
& item
,
1285 const QList
<QAction
*>& customActions
)
1287 QPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, item
, url
);
1288 contextMenu
->setCustomActions(customActions
);
1289 const DolphinContextMenu::Command command
= contextMenu
->open();
1292 case DolphinContextMenu::OpenParentFolderInNewWindow
: {
1293 DolphinMainWindow
* window
= DolphinApplication::app()->createMainWindow();
1294 window
->changeUrl(item
.url().upUrl());
1299 case DolphinContextMenu::OpenParentFolderInNewTab
:
1300 openNewTab(item
.url().upUrl());
1303 case DolphinContextMenu::None
:
1311 void DolphinMainWindow::init()
1313 DolphinSettings
& settings
= DolphinSettings::instance();
1315 // Check whether Dolphin runs the first time. If yes then
1316 // a proper default window size is given at the end of DolphinMainWindow::init().
1317 GeneralSettings
* generalSettings
= settings
.generalSettings();
1318 const bool firstRun
= generalSettings
->firstRun();
1320 generalSettings
->setViewPropsTimestamp(QDateTime::currentDateTime());
1323 setAcceptDrops(true);
1325 m_viewTab
[m_tabIndex
].splitter
= new QSplitter(this);
1326 m_viewTab
[m_tabIndex
].splitter
->setChildrenCollapsible(false);
1330 const KUrl
homeUrl(generalSettings
->homeUrl());
1331 setUrlAsCaption(homeUrl
);
1332 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
1333 connect(m_actionHandler
, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
1334 connect(m_actionHandler
, SIGNAL(createDirectory()), SLOT(createDirectory()));
1336 m_viewTab
[m_tabIndex
].primaryView
= createViewContainer(homeUrl
, m_viewTab
[m_tabIndex
].splitter
);
1338 m_activeViewContainer
= m_viewTab
[m_tabIndex
].primaryView
;
1339 connectViewSignals(m_activeViewContainer
);
1340 DolphinView
* view
= m_activeViewContainer
->view();
1341 m_activeViewContainer
->show();
1342 m_actionHandler
->setCurrentView(view
);
1344 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
1345 connect(this, SIGNAL(urlChanged(const KUrl
&)),
1346 m_remoteEncoding
, SLOT(slotAboutToOpenUrl()));
1348 m_tabBar
= new KTabBar(this);
1349 m_tabBar
->setMovable(true);
1350 m_tabBar
->setTabsClosable(true);
1351 connect(m_tabBar
, SIGNAL(currentChanged(int)),
1352 this, SLOT(setActiveTab(int)));
1353 connect(m_tabBar
, SIGNAL(tabCloseRequested(int)),
1354 this, SLOT(closeTab(int)));
1355 connect(m_tabBar
, SIGNAL(contextMenu(int, const QPoint
&)),
1356 this, SLOT(openTabContextMenu(int, const QPoint
&)));
1357 connect(m_tabBar
, SIGNAL(newTabRequest()),
1358 this, SLOT(openNewTab()));
1359 connect(m_tabBar
, SIGNAL(testCanDecode(const QDragMoveEvent
*, bool&)),
1360 this, SLOT(slotTestCanDecode(const QDragMoveEvent
*, bool&)));
1361 connect(m_tabBar
, SIGNAL(mouseMiddleClick(int)),
1362 this, SLOT(closeTab(int)));
1363 connect(m_tabBar
, SIGNAL(tabMoved(int, int)),
1364 this, SLOT(slotTabMoved(int, int)));
1365 connect(m_tabBar
, SIGNAL(receivedDropEvent(int, QDropEvent
*)),
1366 this, SLOT(tabDropEvent(int, QDropEvent
*)));
1368 m_tabBar
->blockSignals(true); // signals get unblocked after at least 2 tabs are open
1370 QWidget
* centralWidget
= new QWidget(this);
1371 m_centralWidgetLayout
= new QVBoxLayout(centralWidget
);
1372 m_centralWidgetLayout
->setSpacing(0);
1373 m_centralWidgetLayout
->setMargin(0);
1374 m_centralWidgetLayout
->addWidget(m_tabBar
);
1375 m_centralWidgetLayout
->addWidget(m_viewTab
[m_tabIndex
].splitter
, 1);
1377 setCentralWidget(centralWidget
);
1379 emit
urlChanged(homeUrl
);
1381 setupGUI(Keys
| Save
| Create
| ToolBar
);
1382 stateChanged("new_file");
1384 QClipboard
* clipboard
= QApplication::clipboard();
1385 connect(clipboard
, SIGNAL(dataChanged()),
1386 this, SLOT(updatePasteAction()));
1388 if (generalSettings
->splitView()) {
1391 updateEditActions();
1392 updateViewActions();
1395 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1396 showFilterBarAction
->setChecked(generalSettings
->filterBar());
1399 // assure a proper default size if Dolphin runs the first time
1403 m_showMenuBar
->setChecked(!menuBar()->isHidden()); // workaround for bug #171080
1406 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer
* viewContainer
)
1408 Q_ASSERT(viewContainer
);
1409 Q_ASSERT((viewContainer
== m_viewTab
[m_tabIndex
].primaryView
) ||
1410 (viewContainer
== m_viewTab
[m_tabIndex
].secondaryView
));
1411 if (m_activeViewContainer
== viewContainer
) {
1415 m_activeViewContainer
->setActive(false);
1416 m_activeViewContainer
= viewContainer
;
1418 // Activating the view container might trigger a recursive setActiveViewContainer() call
1419 // inside DolphinMainWindow::toggleActiveView() when having a split view. Temporary
1420 // disconnect the activated() signal in this case:
1421 disconnect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1422 m_activeViewContainer
->setActive(true);
1423 connect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1425 m_actionHandler
->setCurrentView(viewContainer
->view());
1428 updateEditActions();
1429 updateViewActions();
1432 const KUrl url
= m_activeViewContainer
->url();
1433 setUrlAsCaption(url
);
1434 if (m_viewTab
.count() > 1) {
1435 m_tabBar
->setTabText(m_tabIndex
, tabName(url
));
1436 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(KMimeType::iconNameForUrl(url
)));
1439 emit
urlChanged(url
);
1442 DolphinViewContainer
* DolphinMainWindow::createViewContainer(const KUrl
& url
, QWidget
* parent
)
1444 DolphinViewContainer
* container
= new DolphinViewContainer(url
, parent
);
1446 // The places-selector from the URL navigator should only be shown
1447 // if the places dock is invisible
1448 QDockWidget
* placesDock
= findChild
<QDockWidget
*>("placesDock");
1449 container
->urlNavigator()->setPlacesSelectorVisible(!placesDock
|| !placesDock
->isVisible());
1454 void DolphinMainWindow::setupActions()
1456 // setup 'File' menu
1457 m_newFileMenu
= new DolphinNewFileMenu(this);
1458 KMenu
* menu
= m_newFileMenu
->menu();
1459 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1460 menu
->setIcon(KIcon("document-new"));
1461 connect(menu
, SIGNAL(aboutToShow()),
1462 this, SLOT(updateNewMenu()));
1464 KAction
* newWindow
= actionCollection()->addAction("new_window");
1465 newWindow
->setIcon(KIcon("window-new"));
1466 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1467 newWindow
->setShortcut(Qt::CTRL
| Qt::Key_N
);
1468 connect(newWindow
, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1470 KAction
* newTab
= actionCollection()->addAction("new_tab");
1471 newTab
->setIcon(KIcon("tab-new"));
1472 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1473 newTab
->setShortcut(KShortcut(Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
));
1474 connect(newTab
, SIGNAL(triggered()), this, SLOT(openNewTab()));
1476 KAction
* closeTab
= actionCollection()->addAction("close_tab");
1477 closeTab
->setIcon(KIcon("tab-close"));
1478 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1479 closeTab
->setShortcut(Qt::CTRL
| Qt::Key_W
);
1480 closeTab
->setEnabled(false);
1481 connect(closeTab
, SIGNAL(triggered()), this, SLOT(closeTab()));
1483 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1485 // setup 'Edit' menu
1486 KStandardAction::undo(this,
1488 actionCollection());
1490 // need to remove shift+del from cut action, else the shortcut for deletejob
1492 KAction
* cut
= KStandardAction::cut(this, SLOT(cut()), actionCollection());
1493 KShortcut cutShortcut
= cut
->shortcut();
1494 cutShortcut
.remove(Qt::SHIFT
| Qt::Key_Delete
, KShortcut::KeepEmpty
);
1495 cut
->setShortcut(cutShortcut
);
1496 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1497 KAction
* paste
= KStandardAction::paste(this, SLOT(paste()), actionCollection());
1498 // The text of the paste-action is modified dynamically by Dolphin
1499 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1500 // due to the long text, the text "Paste" is used:
1501 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1503 KStandardAction::find(this, SLOT(find()), actionCollection());
1505 KAction
* selectAll
= actionCollection()->addAction("select_all");
1506 selectAll
->setText(i18nc("@action:inmenu Edit", "Select All"));
1507 selectAll
->setShortcut(Qt::CTRL
| Qt::Key_A
);
1508 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
1510 KAction
* invertSelection
= actionCollection()->addAction("invert_selection");
1511 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1512 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1513 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
1515 // setup 'View' menu
1516 // (note that most of it is set up in DolphinViewActionHandler)
1518 KAction
* split
= actionCollection()->addAction("split_view");
1519 split
->setShortcut(Qt::Key_F3
);
1520 updateSplitAction();
1521 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1523 KAction
* reload
= actionCollection()->addAction("reload");
1524 reload
->setText(i18nc("@action:inmenu View", "Reload"));
1525 reload
->setShortcut(Qt::Key_F5
);
1526 reload
->setIcon(KIcon("view-refresh"));
1527 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
1529 KAction
* stop
= actionCollection()->addAction("stop");
1530 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1531 stop
->setToolTip(i18nc("@info", "Stop loading"));
1532 stop
->setIcon(KIcon("process-stop"));
1533 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
1535 KToggleAction
* showFullLocation
= actionCollection()->add
<KToggleAction
>("editable_location");
1536 showFullLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1537 showFullLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
1538 connect(showFullLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1540 KAction
* replaceLocation
= actionCollection()->addAction("replace_location");
1541 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1542 replaceLocation
->setShortcut(Qt::Key_F6
);
1543 connect(replaceLocation
, SIGNAL(triggered()), this, SLOT(replaceLocation()));
1546 KAction
* backAction
= KStandardAction::back(this, SLOT(goBack()), actionCollection());
1547 connect(backAction
, SIGNAL(triggered(Qt::MouseButtons
, Qt::KeyboardModifiers
)), this, SLOT(goBack(Qt::MouseButtons
)));
1548 KShortcut backShortcut
= backAction
->shortcut();
1549 backShortcut
.setAlternate(Qt::Key_Backspace
);
1550 backAction
->setShortcut(backShortcut
);
1552 m_recentTabsMenu
= new KActionMenu(i18n("Recently Closed Tabs"), this);
1553 m_recentTabsMenu
->setIcon(KIcon("edit-undo"));
1554 actionCollection()->addAction("closed_tabs", m_recentTabsMenu
);
1555 connect(m_recentTabsMenu
->menu(), SIGNAL(triggered(QAction
*)),
1556 this, SLOT(restoreClosedTab(QAction
*)));
1558 QAction
* action
= new QAction("Empty Recently Closed Tabs", m_recentTabsMenu
);
1559 action
->setIcon(KIcon("edit-clear-list"));
1560 action
->setData(QVariant::fromValue(true));
1561 m_recentTabsMenu
->addAction(action
);
1562 m_recentTabsMenu
->addSeparator();
1563 m_recentTabsMenu
->setEnabled(false);
1565 KAction
* forwardAction
= KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1566 connect(forwardAction
, SIGNAL(triggered(Qt::MouseButtons
, Qt::KeyboardModifiers
)), this, SLOT(goForward(Qt::MouseButtons
)));
1568 KAction
* upAction
= KStandardAction::up(this, SLOT(goUp()), actionCollection());
1569 connect(upAction
, SIGNAL(triggered(Qt::MouseButtons
, Qt::KeyboardModifiers
)), this, SLOT(goUp(Qt::MouseButtons
)));
1571 KStandardAction::home(this, SLOT(goHome()), actionCollection());
1573 // setup 'Tools' menu
1574 KAction
* showFilterBar
= actionCollection()->addAction("show_filter_bar");
1575 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1576 showFilterBar
->setIcon(KIcon("view-filter"));
1577 showFilterBar
->setShortcut(Qt::CTRL
| Qt::Key_I
);
1578 connect(showFilterBar
, SIGNAL(triggered()), this, SLOT(showFilterBar()));
1580 KAction
* compareFiles
= actionCollection()->addAction("compare_files");
1581 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1582 compareFiles
->setIcon(KIcon("kompare"));
1583 compareFiles
->setEnabled(false);
1584 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
1586 KAction
* openTerminal
= actionCollection()->addAction("open_terminal");
1587 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1588 openTerminal
->setIcon(KIcon("utilities-terminal"));
1589 openTerminal
->setShortcut(Qt::SHIFT
| Qt::Key_F4
);
1590 connect(openTerminal
, SIGNAL(triggered()), this, SLOT(openTerminal()));
1592 // setup 'Settings' menu
1593 m_showMenuBar
= KStandardAction::showMenubar(this, SLOT(toggleShowMenuBar()), actionCollection());
1594 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1596 // not in menu actions
1597 QList
<QKeySequence
> nextTabKeys
;
1598 nextTabKeys
.append(KStandardShortcut::tabNext().primary());
1599 nextTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::Key_Tab
));
1601 QList
<QKeySequence
> prevTabKeys
;
1602 prevTabKeys
.append(KStandardShortcut::tabPrev().primary());
1603 prevTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::SHIFT
| Qt::Key_Tab
));
1605 KAction
* activateNextTab
= actionCollection()->addAction("activate_next_tab");
1606 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1607 connect(activateNextTab
, SIGNAL(triggered()), SLOT(activateNextTab()));
1608 activateNextTab
->setShortcuts(QApplication::isRightToLeft() ? prevTabKeys
: nextTabKeys
);
1610 KAction
* activatePrevTab
= actionCollection()->addAction("activate_prev_tab");
1611 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1612 connect(activatePrevTab
, SIGNAL(triggered()), SLOT(activatePrevTab()));
1613 activatePrevTab
->setShortcuts(QApplication::isRightToLeft() ? nextTabKeys
: prevTabKeys
);
1616 KAction
* openInNewTab
= actionCollection()->addAction("open_in_new_tab");
1617 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1618 openInNewTab
->setIcon(KIcon("tab-new"));
1619 connect(openInNewTab
, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1621 KAction
* openInNewWindow
= actionCollection()->addAction("open_in_new_window");
1622 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1623 openInNewWindow
->setIcon(KIcon("window-new"));
1624 connect(openInNewWindow
, SIGNAL(triggered()), this, SLOT(openInNewWindow()));
1627 void DolphinMainWindow::setupDockWidgets()
1629 const bool lock
= DolphinSettings::instance().generalSettings()->lockPanels();
1631 KDualAction
* lockLayoutAction
= actionCollection()->add
<KDualAction
>("lock_panels");
1632 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
1633 lockLayoutAction
->setActiveIcon(KIcon("object-unlocked"));
1634 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
1635 lockLayoutAction
->setInactiveIcon(KIcon("object-locked"));
1636 lockLayoutAction
->setActive(lock
);
1637 connect(lockLayoutAction
, SIGNAL(triggered()), this, SLOT(togglePanelLockState()));
1639 // Setup "Information"
1640 DolphinDockWidget
* infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
1641 infoDock
->setLocked(lock
);
1642 infoDock
->setObjectName("infoDock");
1643 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1644 Panel
* infoPanel
= new InformationPanel(infoDock
);
1645 infoPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1646 connect(infoPanel
, SIGNAL(urlActivated(KUrl
)), this, SLOT(handleUrl(KUrl
)));
1647 infoDock
->setWidget(infoPanel
);
1649 QAction
* infoAction
= infoDock
->toggleViewAction();
1650 infoAction
->setIcon(KIcon("dialog-information"));
1651 infoAction
->setShortcut(Qt::Key_F11
);
1652 addActionCloneToCollection(infoAction
, "show_information_panel");
1654 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1655 connect(this, SIGNAL(urlChanged(KUrl
)),
1656 infoPanel
, SLOT(setUrl(KUrl
)));
1657 connect(this, SIGNAL(selectionChanged(KFileItemList
)),
1658 infoPanel
, SLOT(setSelection(KFileItemList
)));
1659 connect(this, SIGNAL(requestItemInfo(KFileItem
)),
1660 infoPanel
, SLOT(requestDelayedItemInfo(KFileItem
)));
1663 DolphinDockWidget
* foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
1664 foldersDock
->setLocked(lock
);
1665 foldersDock
->setObjectName("foldersDock");
1666 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1667 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1668 foldersPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1669 foldersDock
->setWidget(foldersPanel
);
1671 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1672 foldersAction
->setShortcut(Qt::Key_F7
);
1673 foldersAction
->setIcon(KIcon("folder"));
1674 addActionCloneToCollection(foldersAction
, "show_folders_panel");
1676 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1677 connect(this, SIGNAL(urlChanged(KUrl
)),
1678 foldersPanel
, SLOT(setUrl(KUrl
)));
1679 connect(foldersPanel
, SIGNAL(changeUrl(KUrl
, Qt::MouseButtons
)),
1680 this, SLOT(handlePlacesClick(KUrl
, Qt::MouseButtons
)));
1684 DolphinDockWidget
* terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1685 terminalDock
->setLocked(lock
);
1686 terminalDock
->setObjectName("terminalDock");
1687 terminalDock
->setAllowedAreas(Qt::TopDockWidgetArea
| Qt::BottomDockWidgetArea
);
1688 Panel
* terminalPanel
= new TerminalPanel(terminalDock
);
1689 terminalPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1690 terminalDock
->setWidget(terminalPanel
);
1692 connect(terminalPanel
, SIGNAL(hideTerminalPanel()), terminalDock
, SLOT(hide()));
1694 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1695 terminalAction
->setShortcut(Qt::Key_F4
);
1696 terminalAction
->setIcon(KIcon("utilities-terminal"));
1697 addActionCloneToCollection(terminalAction
, "show_terminal_panel");
1699 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1700 connect(this, SIGNAL(urlChanged(KUrl
)),
1701 terminalPanel
, SLOT(setUrl(KUrl
)));
1706 DolphinDockWidget
* searchDock
= new DolphinDockWidget(i18nc("@title:window", "Search"));
1707 searchDock
->setLocked(lock
);
1708 searchDock
->setObjectName("searchDock");
1709 searchDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1710 Panel
* searchPanel
= new SearchPanel(searchDock
);
1711 searchPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1712 connect(searchPanel
, SIGNAL(urlActivated(KUrl
)), this, SLOT(handleUrl(KUrl
)));
1713 searchDock
->setWidget(searchPanel
);
1715 QAction
* searchAction
= searchDock
->toggleViewAction();
1716 searchAction
->setShortcut(Qt::Key_F12
);
1717 searchAction
->setIcon(KIcon("system-search"));
1718 addActionCloneToCollection(searchAction
, "show_search_panel");
1719 addDockWidget(Qt::RightDockWidgetArea
, searchDock
);
1720 connect(this, SIGNAL(urlChanged(KUrl
)),
1721 searchPanel
, SLOT(setUrl(KUrl
)));
1724 const bool firstRun
= DolphinSettings::instance().generalSettings()->firstRun();
1727 foldersDock
->hide();
1729 terminalDock
->hide();
1737 DolphinDockWidget
* placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
1738 placesDock
->setLocked(lock
);
1739 placesDock
->setObjectName("placesDock");
1740 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1742 PlacesPanel
* placesPanel
= new PlacesPanel(placesDock
);
1743 QAction
* separator
= new QAction(placesPanel
);
1744 separator
->setSeparator(true);
1745 QList
<QAction
*> placesActions
;
1746 placesActions
.append(separator
);
1747 placesActions
.append(lockLayoutAction
);
1748 placesPanel
->addActions(placesActions
);
1749 placesPanel
->setModel(DolphinSettings::instance().placesModel());
1750 placesPanel
->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff
);
1751 placesDock
->setWidget(placesPanel
);
1753 QAction
* placesAction
= placesDock
->toggleViewAction();
1754 placesAction
->setShortcut(Qt::Key_F9
);
1755 placesAction
->setIcon(KIcon("bookmarks"));
1756 addActionCloneToCollection(placesAction
, "show_places_panel");
1758 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1759 connect(placesPanel
, SIGNAL(urlChanged(KUrl
, Qt::MouseButtons
)),
1760 this, SLOT(handlePlacesClick(KUrl
, Qt::MouseButtons
)));
1761 connect(this, SIGNAL(urlChanged(KUrl
)),
1762 placesPanel
, SLOT(setUrl(KUrl
)));
1763 connect(placesDock
, SIGNAL(visibilityChanged(bool)),
1764 this, SLOT(slotPlacesPanelVisibilityChanged(bool)));
1766 // Add actions into the "Panels" menu
1767 KActionMenu
* panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Panels"), this);
1768 actionCollection()->addAction("panels", panelsMenu
);
1769 panelsMenu
->setDelayed(false);
1770 panelsMenu
->addAction(placesAction
);
1771 panelsMenu
->addAction(infoAction
);
1772 panelsMenu
->addAction(foldersAction
);
1774 panelsMenu
->addAction(terminalAction
);
1777 panelsMenu
->addAction(searchAction
);
1779 panelsMenu
->addSeparator();
1780 panelsMenu
->addAction(lockLayoutAction
);
1783 void DolphinMainWindow::updateEditActions()
1785 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1786 if (list
.isEmpty()) {
1787 stateChanged("has_no_selection");
1789 stateChanged("has_selection");
1791 KActionCollection
* col
= actionCollection();
1792 QAction
* renameAction
= col
->action("rename");
1793 QAction
* moveToTrashAction
= col
->action("move_to_trash");
1794 QAction
* deleteAction
= col
->action("delete");
1795 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
1796 QAction
* deleteWithTrashShortcut
= col
->action("delete_shortcut"); // see DolphinViewActionHandler
1798 KFileItemListProperties
capabilities(list
);
1799 const bool enableMoveToTrash
= capabilities
.isLocal() && capabilities
.supportsMoving();
1801 renameAction
->setEnabled(capabilities
.supportsMoving());
1802 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1803 deleteAction
->setEnabled(capabilities
.supportsDeleting());
1804 deleteWithTrashShortcut
->setEnabled(capabilities
.supportsDeleting() && !enableMoveToTrash
);
1805 cutAction
->setEnabled(capabilities
.supportsMoving());
1807 updatePasteAction();
1810 void DolphinMainWindow::updateViewActions()
1812 m_actionHandler
->updateViewActions();
1814 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1815 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
1817 updateSplitAction();
1819 QAction
* editableLocactionAction
= actionCollection()->action("editable_location");
1820 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
1821 editableLocactionAction
->setChecked(urlNavigator
->isUrlEditable());
1824 void DolphinMainWindow::updateGoActions()
1826 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
1827 const KUrl currentUrl
= m_activeViewContainer
->url();
1828 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
1831 void DolphinMainWindow::rememberClosedTab(int index
)
1833 KMenu
* tabsMenu
= m_recentTabsMenu
->menu();
1835 const QString primaryPath
= m_viewTab
[index
].primaryView
->url().path();
1836 const QString iconName
= KMimeType::iconNameForUrl(primaryPath
);
1838 QAction
* action
= new QAction(squeezedText(primaryPath
), tabsMenu
);
1840 ClosedTab closedTab
;
1841 closedTab
.primaryUrl
= m_viewTab
[index
].primaryView
->url();
1843 if (m_viewTab
[index
].secondaryView
) {
1844 closedTab
.secondaryUrl
= m_viewTab
[index
].secondaryView
->url();
1845 closedTab
.isSplit
= true;
1847 closedTab
.isSplit
= false;
1850 action
->setData(QVariant::fromValue(closedTab
));
1851 action
->setIcon(KIcon(iconName
));
1853 // add the closed tab menu entry after the separator and
1854 // "Empty Recently Closed Tabs" entry
1855 if (tabsMenu
->actions().size() == 2) {
1856 tabsMenu
->addAction(action
);
1858 tabsMenu
->insertAction(tabsMenu
->actions().at(2), action
);
1861 // assure that only up to 8 closed tabs are shown in the menu
1862 if (tabsMenu
->actions().size() > 8) {
1863 tabsMenu
->removeAction(tabsMenu
->actions().last());
1865 actionCollection()->action("closed_tabs")->setEnabled(true);
1866 KAcceleratorManager::manage(tabsMenu
);
1869 void DolphinMainWindow::clearStatusBar()
1871 m_activeViewContainer
->statusBar()->clear();
1874 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
1876 connect(container
, SIGNAL(showFilterBarChanged(bool)),
1877 this, SLOT(updateFilterBarAction(bool)));
1878 connect(container
, SIGNAL(writeStateChanged(bool)),
1879 this, SLOT(slotWriteStateChanged(bool)));
1880 connect(container
, SIGNAL(searchModeChanged(bool)),
1881 this, SLOT(slotSearchModeChanged(bool)));
1883 DolphinView
* view
= container
->view();
1884 connect(view
, SIGNAL(selectionChanged(KFileItemList
)),
1885 this, SLOT(slotSelectionChanged(KFileItemList
)));
1886 connect(view
, SIGNAL(requestItemInfo(KFileItem
)),
1887 this, SLOT(slotRequestItemInfo(KFileItem
)));
1888 connect(view
, SIGNAL(activated()),
1889 this, SLOT(toggleActiveView()));
1890 connect(view
, SIGNAL(tabRequested(const KUrl
&)),
1891 this, SLOT(openNewTab(const KUrl
&)));
1892 connect(view
, SIGNAL(requestContextMenu(KFileItem
, const KUrl
&, const QList
<QAction
*>&)),
1893 this, SLOT(openContextMenu(KFileItem
, const KUrl
&, const QList
<QAction
*>&)));
1894 connect(view
, SIGNAL(startedPathLoading(KUrl
)),
1895 this, SLOT(enableStopAction()));
1896 connect(view
, SIGNAL(finishedPathLoading(KUrl
)),
1897 this, SLOT(disableStopAction()));
1899 const KUrlNavigator
* navigator
= container
->urlNavigator();
1900 connect(navigator
, SIGNAL(urlChanged(const KUrl
&)),
1901 this, SLOT(changeUrl(const KUrl
&)));
1902 connect(navigator
, SIGNAL(historyChanged()),
1903 this, SLOT(updateHistory()));
1904 connect(navigator
, SIGNAL(editableStateChanged(bool)),
1905 this, SLOT(slotEditableStateChanged(bool)));
1906 connect(navigator
, SIGNAL(tabRequested(const KUrl
&)),
1907 this, SLOT(openNewTab(KUrl
)));
1910 void DolphinMainWindow::updateSplitAction()
1912 QAction
* splitAction
= actionCollection()->action("split_view");
1913 if (m_viewTab
[m_tabIndex
].secondaryView
) {
1914 if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
1915 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
1916 splitAction
->setToolTip(i18nc("@info", "Close right view"));
1917 splitAction
->setIcon(KIcon("view-right-close"));
1919 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
1920 splitAction
->setToolTip(i18nc("@info", "Close left view"));
1921 splitAction
->setIcon(KIcon("view-left-close"));
1924 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
1925 splitAction
->setToolTip(i18nc("@info", "Split view"));
1926 splitAction
->setIcon(KIcon("view-right-new"));
1930 QString
DolphinMainWindow::tabName(const KUrl
& url
) const
1933 if (url
.equals(KUrl("file:///"))) {
1936 name
= url
.fileName();
1937 if (name
.isEmpty()) {
1938 name
= url
.protocol();
1940 // Make sure that a '&' inside the directory name is displayed correctly
1941 // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
1942 name
.replace('&', "&&");
1948 bool DolphinMainWindow::isKompareInstalled() const
1950 static bool initialized
= false;
1951 static bool installed
= false;
1953 // TODO: maybe replace this approach later by using a menu
1954 // plugin like kdiff3plugin.cpp
1955 installed
= !KGlobal::dirs()->findExe("kompare").isEmpty();
1961 void DolphinMainWindow::createSecondaryView(int tabIndex
)
1963 QSplitter
* splitter
= m_viewTab
[tabIndex
].splitter
;
1964 const int newWidth
= (m_viewTab
[tabIndex
].primaryView
->width() - splitter
->handleWidth()) / 2;
1966 const DolphinView
* view
= m_viewTab
[tabIndex
].primaryView
->view();
1967 m_viewTab
[tabIndex
].secondaryView
= createViewContainer(view
->rootUrl(), 0);
1968 splitter
->addWidget(m_viewTab
[tabIndex
].secondaryView
);
1969 splitter
->setSizes(QList
<int>() << newWidth
<< newWidth
);
1970 connectViewSignals(m_viewTab
[tabIndex
].secondaryView
);
1971 m_viewTab
[tabIndex
].secondaryView
->setActive(false);
1972 m_viewTab
[tabIndex
].secondaryView
->show();
1975 QString
DolphinMainWindow::tabProperty(const QString
& property
, int tabIndex
) const
1977 return "Tab " + QString::number(tabIndex
) + ' ' + property
;
1980 void DolphinMainWindow::setUrlAsCaption(const KUrl
& url
)
1983 if (!url
.isLocalFile()) {
1984 caption
.append(url
.protocol() + " - ");
1985 if (url
.hasHost()) {
1986 caption
.append(url
.host() + " - ");
1990 const QString fileName
= url
.fileName().isEmpty() ? "/" : url
.fileName();
1991 caption
.append(fileName
);
1993 setCaption(caption
);
1996 QString
DolphinMainWindow::squeezedText(const QString
& text
) const
1998 const QFontMetrics fm
= fontMetrics();
1999 return fm
.elidedText(text
, Qt::ElideMiddle
, fm
.maxWidth() * 10);
2002 void DolphinMainWindow::addActionCloneToCollection(QAction
* action
, const QString
& actionName
)
2004 KAction
* actionClone
= actionCollection()->addAction(actionName
);
2005 actionClone
->setText(action
->text());
2006 actionClone
->setIcon(action
->icon());
2007 connect(actionClone
, SIGNAL(triggered()), action
, SLOT(trigger()));
2010 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
2011 KIO::FileUndoManager::UiInterface()
2015 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2019 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
2021 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
2023 DolphinStatusBar
* statusBar
= mainWin
->activeViewContainer()->statusBar();
2024 statusBar
->setMessage(job
->errorString(), DolphinStatusBar::Error
);
2026 KIO::FileUndoManager::UiInterface::jobError(job
);
2030 #include "dolphinmainwindow.moc"