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 "dolphindockwidget.h"
28 #include "dolphincontextmenu.h"
29 #include "dolphinnewfilemenu.h"
30 #include "dolphinviewcontainer.h"
31 #include "mainwindowadaptor.h"
33 #include "panels/filter/filterpanel.h"
34 #include <nepomuk/resourcemanager.h>
36 #include "panels/folders/folderspanel.h"
37 #include "panels/places/placespanel.h"
38 #include "panels/information/informationpanel.h"
39 #include "settings/dolphinsettings.h"
40 #include "settings/dolphinsettingsdialog.h"
41 #include "statusbar/dolphinstatusbar.h"
42 #include "views/dolphinviewactionhandler.h"
43 #include "views/dolphinremoteencoding.h"
44 #include "views/draganddrophelper.h"
45 #include "views/viewproperties.h"
48 #include "panels/terminal/terminalpanel.h"
51 #include "dolphin_generalsettings.h"
52 #include "dolphin_iconsmodesettings.h"
55 #include <kactioncollection.h>
56 #include <kactionmenu.h>
58 #include <kdesktopfile.h>
59 #include <kdeversion.h>
60 #include <kdualaction.h>
61 #include <kfiledialog.h>
62 #include <kfileplacesmodel.h>
64 #include <klineedit.h>
67 #include <kiconloader.h>
68 #include <kio/netaccess.h>
69 #include <kinputdialog.h>
71 #include <kprotocolmanager.h>
74 #include <kmessagebox.h>
75 #include <kfileitemlistproperties.h>
76 #include <konqmimedata.h>
77 #include <kprotocolinfo.h>
80 #include <kstandarddirs.h>
81 #include <kstatusbar.h>
82 #include <kstandardaction.h>
84 #include <ktoggleaction.h>
85 #include <kurlnavigator.h>
87 #include <kurlcombobox.h>
88 #include <ktoolinvocation.h>
90 #include <QDBusMessage>
94 #include <kacceleratormanager.h>
97 * Remembers the tab configuration if a tab has been closed.
98 * Each closed tab can be restored by the menu
99 * "Go -> Recently Closed Tabs".
107 Q_DECLARE_METATYPE(ClosedTab
)
109 DolphinMainWindow::DolphinMainWindow(int id
) :
114 m_activeViewContainer(0),
115 m_centralWidgetLayout(0),
122 m_lastHandleUrlStatJob(0),
123 m_filterDockIsTemporaryVisible(false)
125 // Workaround for a X11-issue in combination with KModifierInfo
126 // (see DolphinContextMenu::initializeModifierKeyInfo() for
127 // more information):
128 DolphinContextMenu::initializeModifierKeyInfo();
130 setObjectName("Dolphin#");
132 m_viewTab
.append(ViewTab());
134 new MainWindowAdaptor(this);
135 QDBusConnection::sessionBus().registerObject(QString("/dolphin/MainWindow%1").arg(m_id
), this);
137 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
138 undoManager
->setUiInterface(new UndoUiInterface());
140 connect(undoManager
, SIGNAL(undoAvailable(bool)),
141 this, SLOT(slotUndoAvailable(bool)));
142 connect(undoManager
, SIGNAL(undoTextChanged(const QString
&)),
143 this, SLOT(slotUndoTextChanged(const QString
&)));
144 connect(undoManager
, SIGNAL(jobRecordingStarted(CommandType
)),
145 this, SLOT(clearStatusBar()));
146 connect(undoManager
, SIGNAL(jobRecordingFinished(CommandType
)),
147 this, SLOT(showCommand(CommandType
)));
148 connect(DolphinSettings::instance().placesModel(), SIGNAL(errorMessage(const QString
&)),
149 this, SLOT(showErrorMessage(const QString
&)));
150 connect(&DragAndDropHelper::instance(), SIGNAL(errorMessage(const QString
&)),
151 this, SLOT(showErrorMessage(const QString
&)));
154 DolphinMainWindow::~DolphinMainWindow()
156 DolphinApplication::app()->removeMainWindow(this);
159 void DolphinMainWindow::openDirectories(const QList
<KUrl
>& dirs
)
161 if (dirs
.isEmpty()) {
165 const int oldOpenTabsCount
= m_viewTab
.count();
167 const GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
168 const bool hasSplitView
= generalSettings
->splitView();
170 // Open each directory inside a new tab. If the "split view" option has been enabled,
171 // always show two directories within one tab.
172 QList
<KUrl
>::const_iterator it
= dirs
.begin();
173 while (it
!= dirs
.end()) {
177 if (hasSplitView
&& (it
!= dirs
.end())) {
178 const int tabIndex
= m_viewTab
.count() - 1;
179 m_viewTab
[tabIndex
].secondaryView
->setUrl(*it
);
184 // remove the previously opened tabs
185 for (int i
= 0; i
< oldOpenTabsCount
; ++i
) {
190 void DolphinMainWindow::openFiles(const QList
<KUrl
>& files
)
192 if (files
.isEmpty()) {
196 // Get all distinct directories from 'files' and open a tab
197 // for each directory. If the "split view" option is enabled, two
198 // directories are shown inside one tab (see openDirectories()).
200 foreach (const KUrl
& url
, files
) {
201 const KUrl
dir(url
.directory());
202 if (!dirs
.contains(dir
)) {
207 openDirectories(dirs
);
209 // Select the files. Although the files can be split between several
210 // tabs, there is no need to split 'files' accordingly, as
211 // the DolphinView will just ignore invalid selections.
212 const int tabCount
= m_viewTab
.count();
213 for (int i
= 0; i
< tabCount
; ++i
) {
214 m_viewTab
[i
].primaryView
->view()->markUrlsAsSelected(files
);
215 if (m_viewTab
[i
].secondaryView
!= 0) {
216 m_viewTab
[i
].secondaryView
->view()->markUrlsAsSelected(files
);
221 void DolphinMainWindow::showCommand(CommandType command
)
223 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
225 case KIO::FileUndoManager::Copy
:
226 statusBar
->setMessage(i18nc("@info:status", "Successfully copied."),
227 DolphinStatusBar::OperationCompleted
);
229 case KIO::FileUndoManager::Move
:
230 statusBar
->setMessage(i18nc("@info:status", "Successfully moved."),
231 DolphinStatusBar::OperationCompleted
);
233 case KIO::FileUndoManager::Link
:
234 statusBar
->setMessage(i18nc("@info:status", "Successfully linked."),
235 DolphinStatusBar::OperationCompleted
);
237 case KIO::FileUndoManager::Trash
:
238 statusBar
->setMessage(i18nc("@info:status", "Successfully moved to trash."),
239 DolphinStatusBar::OperationCompleted
);
241 case KIO::FileUndoManager::Rename
:
242 statusBar
->setMessage(i18nc("@info:status", "Successfully renamed."),
243 DolphinStatusBar::OperationCompleted
);
246 case KIO::FileUndoManager::Mkdir
:
247 statusBar
->setMessage(i18nc("@info:status", "Created folder."),
248 DolphinStatusBar::OperationCompleted
);
256 void DolphinMainWindow::refreshViews()
258 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
260 // remember the current active view, as because of
261 // the refreshing the active view might change to
262 // the secondary view
263 DolphinViewContainer
* activeViewContainer
= m_activeViewContainer
;
265 const int tabCount
= m_viewTab
.count();
266 for (int i
= 0; i
< tabCount
; ++i
) {
267 m_viewTab
[i
].primaryView
->refresh();
268 if (m_viewTab
[i
].secondaryView
!= 0) {
269 m_viewTab
[i
].secondaryView
->refresh();
273 setActiveViewContainer(activeViewContainer
);
275 const GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
276 if (generalSettings
->modifiedStartupSettings()) {
277 // The startup settings have been changed by the user (see bug #254947).
278 // Synchronize the split-view setting with the active view:
279 const bool splitView
= generalSettings
->splitView();
280 const ViewTab
& activeTab
= m_viewTab
[m_tabIndex
];
281 const bool toggle
= ( splitView
&& (activeTab
.secondaryView
== 0))
282 || (!splitView
&& (activeTab
.secondaryView
!= 0));
289 void DolphinMainWindow::pasteIntoFolder()
291 m_activeViewContainer
->view()->pasteIntoFolder();
294 void DolphinMainWindow::changeUrl(const KUrl
& url
)
296 if (!KProtocolManager::supportsListing(url
)) {
297 // The URL navigator only checks for validity, not
298 // if the URL can be listed. An error message is
299 // shown due to DolphinViewContainer::restoreView().
303 DolphinViewContainer
* view
= activeViewContainer();
309 setUrlAsCaption(url
);
310 if (m_viewTab
.count() > 1) {
311 m_tabBar
->setTabText(m_tabIndex
, squeezedText(tabName(m_activeViewContainer
->url())));
313 const QString iconName
= KMimeType::iconNameForUrl(url
);
314 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(iconName
));
315 emit
urlChanged(url
);
319 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
321 KToggleAction
* editableLocationAction
=
322 static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
323 editableLocationAction
->setChecked(editable
);
326 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
330 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
331 int selectedUrlsCount
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedItemsCount();
332 if (m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
333 selectedUrlsCount
+= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItemsCount();
336 QAction
* compareFilesAction
= actionCollection()->action("compare_files");
337 if (selectedUrlsCount
== 2) {
338 compareFilesAction
->setEnabled(isKompareInstalled());
340 compareFilesAction
->setEnabled(false);
343 emit
selectionChanged(selection
);
346 void DolphinMainWindow::slotRequestItemInfo(const KFileItem
& item
)
348 emit
requestItemInfo(item
);
351 void DolphinMainWindow::updateHistory()
353 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
354 const int index
= urlNavigator
->historyIndex();
356 QAction
* backAction
= actionCollection()->action("go_back");
357 backAction
->setToolTip(i18nc("@info", "Go back"));
358 if (backAction
!= 0) {
359 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
362 QAction
* forwardAction
= actionCollection()->action("go_forward");
363 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
364 if (forwardAction
!= 0) {
365 forwardAction
->setEnabled(index
> 0);
369 void DolphinMainWindow::updateFilterBarAction(bool show
)
371 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
372 showFilterBarAction
->setChecked(show
);
375 void DolphinMainWindow::openNewMainWindow()
377 DolphinApplication::app()->createMainWindow()->show();
380 void DolphinMainWindow::openNewTab()
382 const bool isUrlEditable
= m_activeViewContainer
->urlNavigator()->isUrlEditable();
384 openNewTab(m_activeViewContainer
->url());
385 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
387 // The URL navigator of the new tab should have the same editable state
388 // as the current tab
389 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
390 navigator
->setUrlEditable(isUrlEditable
);
393 // If a new tab is opened and the URL is editable, assure that
394 // the user can edit the URL without manually setting the focus
395 navigator
->setFocus();
399 void DolphinMainWindow::openNewTab(const KUrl
& url
)
401 QWidget
* focusWidget
= QApplication::focusWidget();
403 if (m_viewTab
.count() == 1) {
404 // Only one view is open currently and hence no tab is shown at
405 // all. Before creating a tab for 'url', provide a tab for the current URL.
406 const KUrl currentUrl
= m_activeViewContainer
->url();
407 m_tabBar
->addTab(KIcon(KMimeType::iconNameForUrl(currentUrl
)),
408 squeezedText(tabName(currentUrl
)));
409 m_tabBar
->blockSignals(false);
412 m_tabBar
->addTab(KIcon(KMimeType::iconNameForUrl(url
)),
413 squeezedText(tabName(url
)));
416 viewTab
.splitter
= new QSplitter(this);
417 viewTab
.splitter
->setChildrenCollapsible(false);
418 viewTab
.primaryView
= new DolphinViewContainer(url
, viewTab
.splitter
);
419 viewTab
.primaryView
->setActive(false);
420 connectViewSignals(viewTab
.primaryView
);
421 viewTab
.primaryView
->view()->reload();
423 m_viewTab
.append(viewTab
);
425 actionCollection()->action("close_tab")->setEnabled(true);
427 // provide a split view, if the startup settings are set this way
428 const GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
429 if (generalSettings
->splitView()) {
430 const int tabIndex
= m_viewTab
.count() - 1;
431 createSecondaryView(tabIndex
);
432 m_viewTab
[tabIndex
].secondaryView
->setActive(true);
433 m_viewTab
[tabIndex
].isPrimaryViewActive
= false;
436 if (focusWidget
!= 0) {
437 // The DolphinViewContainer grabbed the keyboard focus. As the tab is opened
438 // in background, assure that the previous focused widget gets the focus back.
439 focusWidget
->setFocus();
443 void DolphinMainWindow::activateNextTab()
445 if ((m_viewTab
.count() == 1) || (m_tabBar
->count() < 2)) {
449 const int tabIndex
= (m_tabBar
->currentIndex() + 1) % m_tabBar
->count();
450 m_tabBar
->setCurrentIndex(tabIndex
);
453 void DolphinMainWindow::activatePrevTab()
455 if ((m_viewTab
.count() == 1) || (m_tabBar
->count() < 2)) {
459 int tabIndex
= m_tabBar
->currentIndex() - 1;
460 if (tabIndex
== -1) {
461 tabIndex
= m_tabBar
->count() - 1;
463 m_tabBar
->setCurrentIndex(tabIndex
);
466 void DolphinMainWindow::openInNewTab()
468 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
469 if (list
.isEmpty()) {
470 openNewTab(m_activeViewContainer
->url());
471 } else if ((list
.count() == 1) && list
[0].isDir()) {
472 openNewTab(list
[0].url());
476 void DolphinMainWindow::openInNewWindow()
480 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
481 if (list
.isEmpty()) {
482 newWindowUrl
= m_activeViewContainer
->url();
483 } else if ((list
.count() == 1) && list
[0].isDir()) {
484 newWindowUrl
= list
[0].url();
487 if (!newWindowUrl
.isEmpty()) {
488 DolphinMainWindow
* window
= DolphinApplication::app()->createMainWindow();
489 window
->changeUrl(newWindowUrl
);
494 void DolphinMainWindow::toggleActiveView()
496 if (m_viewTab
[m_tabIndex
].secondaryView
== 0) {
497 // only one view is available
501 Q_ASSERT(m_activeViewContainer
!= 0);
502 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
504 DolphinViewContainer
* left
= m_viewTab
[m_tabIndex
].primaryView
;
505 DolphinViewContainer
* right
= m_viewTab
[m_tabIndex
].secondaryView
;
506 setActiveViewContainer(m_activeViewContainer
== right
? left
: right
);
509 void DolphinMainWindow::showEvent(QShowEvent
* event
)
511 KXmlGuiWindow::showEvent(event
);
512 if (!event
->spontaneous()) {
513 m_activeViewContainer
->view()->setFocus();
517 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
519 DolphinSettings
& settings
= DolphinSettings::instance();
520 GeneralSettings
* generalSettings
= settings
.generalSettings();
522 // Find out if Dolphin is closed directly by the user or
523 // by the session manager because the session is closed
524 bool closedByUser
= true;
525 DolphinApplication
*application
= qobject_cast
<DolphinApplication
*>(qApp
);
526 if (application
&& application
->sessionSaving()) {
527 closedByUser
= false;
530 if ((m_viewTab
.count() > 1) && generalSettings
->confirmClosingMultipleTabs() && closedByUser
) {
531 // Ask the user if he really wants to quit and close all tabs.
532 // Open a confirmation dialog with 3 buttons:
533 // KDialog::Yes -> Quit
534 // KDialog::No -> Close only the current tab
535 // KDialog::Cancel -> do nothing
536 KDialog
*dialog
= new KDialog(this, Qt::Dialog
);
537 dialog
->setCaption(i18nc("@title:window", "Confirmation"));
538 dialog
->setButtons(KDialog::Yes
| KDialog::No
| KDialog::Cancel
);
539 dialog
->setModal(true);
540 dialog
->setButtonGuiItem(KDialog::Yes
, KStandardGuiItem::quit());
541 dialog
->setButtonGuiItem(KDialog::No
, KGuiItem(i18n("C&lose Current Tab"), KIcon("tab-close")));
542 dialog
->setButtonGuiItem(KDialog::Cancel
, KStandardGuiItem::cancel());
543 dialog
->setDefaultButton(KDialog::Yes
);
545 bool doNotAskAgainCheckboxResult
= false;
547 const int result
= KMessageBox::createKMessageBox(dialog
,
548 QMessageBox::Warning
,
549 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
551 i18n("Do not ask again"),
552 &doNotAskAgainCheckboxResult
,
553 KMessageBox::Notify
);
555 if (doNotAskAgainCheckboxResult
) {
556 generalSettings
->setConfirmClosingMultipleTabs(false);
564 // Close only the current tab
572 generalSettings
->setFirstRun(false);
576 if (m_filterDockIsTemporaryVisible
) {
577 QDockWidget
* filterDock
= findChild
<QDockWidget
*>("filterDock");
578 if (filterDock
!= 0) {
581 m_filterDockIsTemporaryVisible
= false;
584 KXmlGuiWindow::closeEvent(event
);
587 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
589 const int tabCount
= m_viewTab
.count();
590 group
.writeEntry("Tab Count", tabCount
);
591 group
.writeEntry("Active Tab Index", m_tabBar
->currentIndex());
593 for (int i
= 0; i
< tabCount
; ++i
) {
594 const DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
595 group
.writeEntry(tabProperty("Primary URL", i
), cont
->url().url());
596 group
.writeEntry(tabProperty("Primary Editable", i
),
597 cont
->urlNavigator()->isUrlEditable());
599 cont
= m_viewTab
[i
].secondaryView
;
601 group
.writeEntry(tabProperty("Secondary URL", i
), cont
->url().url());
602 group
.writeEntry(tabProperty("Secondary Editable", i
),
603 cont
->urlNavigator()->isUrlEditable());
608 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
610 const int tabCount
= group
.readEntry("Tab Count", 1);
611 for (int i
= 0; i
< tabCount
; ++i
) {
612 DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
614 cont
->setUrl(group
.readEntry(tabProperty("Primary URL", i
)));
615 const bool editable
= group
.readEntry(tabProperty("Primary Editable", i
), false);
616 cont
->urlNavigator()->setUrlEditable(editable
);
618 cont
= m_viewTab
[i
].secondaryView
;
619 const QString secondaryUrl
= group
.readEntry(tabProperty("Secondary URL", i
));
620 if (!secondaryUrl
.isEmpty()) {
622 // a secondary view should be shown, but no one is available
623 // currently -> create a new view
625 cont
= m_viewTab
[i
].secondaryView
;
629 cont
->setUrl(secondaryUrl
);
630 const bool editable
= group
.readEntry(tabProperty("Secondary Editable", i
), false);
631 cont
->urlNavigator()->setUrlEditable(editable
);
632 } else if (cont
!= 0) {
633 // no secondary view should be shown, but the default setting shows
634 // one already -> close the view
638 // openNewTab() needs to be called only tabCount - 1 times
639 if (i
!= tabCount
- 1) {
644 const int index
= group
.readEntry("Active Tab Index", 0);
645 m_tabBar
->setCurrentIndex(index
);
648 void DolphinMainWindow::updateNewMenu()
650 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->showHiddenFiles());
651 m_newFileMenu
->checkUpToDate();
652 m_newFileMenu
->setPopupFiles(activeViewContainer()->url());
655 void DolphinMainWindow::createDirectory()
657 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->showHiddenFiles());
658 m_newFileMenu
->setPopupFiles(activeViewContainer()->url());
659 m_newFileMenu
->createDirectory();
662 void DolphinMainWindow::quit()
667 void DolphinMainWindow::showErrorMessage(const QString
& message
)
669 if (!message
.isEmpty()) {
670 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
671 statusBar
->setMessage(message
, DolphinStatusBar::Error
);
675 void DolphinMainWindow::slotUndoAvailable(bool available
)
677 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
678 if (undoAction
!= 0) {
679 undoAction
->setEnabled(available
);
683 void DolphinMainWindow::restoreClosedTab(QAction
* action
)
685 if (action
->data().toBool()) {
686 // clear all actions except the "Empty Recently Closed Tabs"
687 // action and the separator
688 QList
<QAction
*> actions
= m_recentTabsMenu
->menu()->actions();
689 const int count
= actions
.size();
690 for (int i
= 2; i
< count
; ++i
) {
691 m_recentTabsMenu
->menu()->removeAction(actions
.at(i
));
694 const ClosedTab closedTab
= action
->data().value
<ClosedTab
>();
695 openNewTab(closedTab
.primaryUrl
);
696 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
698 if (closedTab
.isSplit
) {
699 // create secondary view
701 m_viewTab
[m_tabIndex
].secondaryView
->setUrl(closedTab
.secondaryUrl
);
704 m_recentTabsMenu
->removeAction(action
);
707 if (m_recentTabsMenu
->menu()->actions().count() == 2) {
708 m_recentTabsMenu
->setEnabled(false);
712 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
714 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
715 if (undoAction
!= 0) {
716 undoAction
->setText(text
);
720 void DolphinMainWindow::undo()
723 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
724 KIO::FileUndoManager::self()->undo();
727 void DolphinMainWindow::cut()
729 m_activeViewContainer
->view()->cutSelectedItems();
732 void DolphinMainWindow::copy()
734 m_activeViewContainer
->view()->copySelectedItems();
737 void DolphinMainWindow::paste()
739 m_activeViewContainer
->view()->paste();
742 void DolphinMainWindow::find()
744 m_activeViewContainer
->setSearchModeEnabled(true);
747 void DolphinMainWindow::updatePasteAction()
749 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
750 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
751 pasteAction
->setEnabled(pasteInfo
.first
);
752 pasteAction
->setText(pasteInfo
.second
);
755 void DolphinMainWindow::selectAll()
759 // if the URL navigator is editable and focused, select the whole
760 // URL instead of all items of the view
762 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
763 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit(); // krazy:exclude=qclasses
764 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
765 lineEdit
->hasFocus();
767 lineEdit
->selectAll();
769 m_activeViewContainer
->view()->selectAll();
773 void DolphinMainWindow::invertSelection()
776 m_activeViewContainer
->view()->invertSelection();
779 void DolphinMainWindow::toggleSplitView()
781 if (m_viewTab
[m_tabIndex
].secondaryView
== 0) {
782 createSecondaryView(m_tabIndex
);
783 setActiveViewContainer(m_viewTab
[m_tabIndex
].secondaryView
);
784 } else if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
785 // remove secondary view
786 m_viewTab
[m_tabIndex
].secondaryView
->close();
787 m_viewTab
[m_tabIndex
].secondaryView
->deleteLater();
788 m_viewTab
[m_tabIndex
].secondaryView
= 0;
790 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
792 // The primary view is active and should be closed. Hence from a users point of view
793 // the content of the secondary view should be moved to the primary view.
794 // From an implementation point of view it is more efficient to close
795 // the primary view and exchange the internal pointers afterwards.
797 m_viewTab
[m_tabIndex
].primaryView
->close();
798 m_viewTab
[m_tabIndex
].primaryView
->deleteLater();
799 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
800 m_viewTab
[m_tabIndex
].secondaryView
= 0;
802 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
808 void DolphinMainWindow::reloadView()
811 m_activeViewContainer
->view()->reload();
814 void DolphinMainWindow::stopLoading()
816 m_activeViewContainer
->view()->stopLoading();
819 void DolphinMainWindow::enableStopAction()
821 actionCollection()->action("stop")->setEnabled(true);
824 void DolphinMainWindow::disableStopAction()
826 actionCollection()->action("stop")->setEnabled(false);
829 void DolphinMainWindow::showFilterBar()
831 m_activeViewContainer
->setFilterBarVisible(true);
834 void DolphinMainWindow::toggleEditLocation()
838 QAction
* action
= actionCollection()->action("editable_location");
839 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
840 urlNavigator
->setUrlEditable(action
->isChecked());
843 void DolphinMainWindow::replaceLocation()
845 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
846 navigator
->setUrlEditable(true);
848 // select the whole text of the combo box editor
849 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit(); // krazy:exclude=qclasses
850 lineEdit
->selectAll();
853 void DolphinMainWindow::togglePanelLockState()
855 GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
857 const bool newLockState
= !generalSettings
->lockPanels();
858 foreach (QObject
* child
, children()) {
859 DolphinDockWidget
* dock
= qobject_cast
<DolphinDockWidget
*>(child
);
861 dock
->setLocked(newLockState
);
865 generalSettings
->setLockPanels(newLockState
);
868 void DolphinMainWindow::goBack()
872 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
873 urlNavigator
->goBack();
875 if (urlNavigator
->locationState().isEmpty()) {
876 // An empty location state indicates a redirection URL,
877 // which must be skipped too
878 urlNavigator
->goBack();
882 void DolphinMainWindow::goForward()
885 m_activeViewContainer
->urlNavigator()->goForward();
888 void DolphinMainWindow::goUp()
891 m_activeViewContainer
->urlNavigator()->goUp();
894 void DolphinMainWindow::goBack(Qt::MouseButtons buttons
)
896 // The default case (left button pressed) is handled in goBack().
897 if (buttons
== Qt::MidButton
) {
898 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
899 const int index
= urlNavigator
->historyIndex() + 1;
900 openNewTab(urlNavigator
->locationUrl(index
));
904 void DolphinMainWindow::goForward(Qt::MouseButtons buttons
)
906 // The default case (left button pressed) is handled in goForward().
907 if (buttons
== Qt::MidButton
) {
908 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
909 const int index
= urlNavigator
->historyIndex() - 1;
910 openNewTab(urlNavigator
->locationUrl(index
));
914 void DolphinMainWindow::goUp(Qt::MouseButtons buttons
)
916 // The default case (left button pressed) is handled in goUp().
917 if (buttons
== Qt::MidButton
) {
918 openNewTab(activeViewContainer()->url().upUrl());
922 void DolphinMainWindow::goHome()
925 m_activeViewContainer
->urlNavigator()->goHome();
928 void DolphinMainWindow::compareFiles()
930 // The method is only invoked if exactly 2 files have
931 // been selected. The selected files may be:
932 // - both in the primary view
933 // - both in the secondary view
934 // - one in the primary view and the other in the secondary
936 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
941 KFileItemList items
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedItems();
943 switch (items
.count()) {
945 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
!= 0);
946 items
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItems();
947 Q_ASSERT(items
.count() == 2);
948 urlA
= items
[0].url();
949 urlB
= items
[1].url();
954 urlA
= items
[0].url();
955 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
!= 0);
956 items
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItems();
957 Q_ASSERT(items
.count() == 1);
958 urlB
= items
[0].url();
963 urlA
= items
[0].url();
964 urlB
= items
[1].url();
969 // may not happen: compareFiles may only get invoked if 2
970 // files are selected
975 QString
command("kompare -c \"");
976 command
.append(urlA
.pathOrUrl());
977 command
.append("\" \"");
978 command
.append(urlB
.pathOrUrl());
979 command
.append('\"');
980 KRun::runCommand(command
, "Kompare", "kompare", this);
983 void DolphinMainWindow::toggleShowMenuBar()
985 const bool visible
= menuBar()->isVisible();
986 menuBar()->setVisible(!visible
);
989 void DolphinMainWindow::openTerminal()
991 QString
dir(QDir::homePath());
993 // If the given directory is not local, it can still be the URL of an
994 // ioslave using UDS_LOCAL_PATH which to be converted first.
995 KUrl url
= KIO::NetAccess::mostLocalUrl(m_activeViewContainer
->url(), this);
997 //If the URL is local after the above conversion, set the directory.
998 if (url
.isLocalFile()) {
999 dir
= url
.toLocalFile();
1002 KToolInvocation::invokeTerminal(QString(), dir
);
1005 void DolphinMainWindow::editSettings()
1007 if (m_settingsDialog
== 0) {
1008 const KUrl url
= activeViewContainer()->url();
1009 m_settingsDialog
= new DolphinSettingsDialog(url
, this);
1010 m_settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1011 m_settingsDialog
->show();
1013 m_settingsDialog
->raise();
1017 void DolphinMainWindow::setActiveTab(int index
)
1019 Q_ASSERT(index
>= 0);
1020 Q_ASSERT(index
< m_viewTab
.count());
1021 if (index
== m_tabIndex
) {
1025 // hide current tab content
1026 ViewTab
& hiddenTab
= m_viewTab
[m_tabIndex
];
1027 hiddenTab
.isPrimaryViewActive
= hiddenTab
.primaryView
->isActive();
1028 hiddenTab
.primaryView
->setActive(false);
1029 if (hiddenTab
.secondaryView
!= 0) {
1030 hiddenTab
.secondaryView
->setActive(false);
1032 QSplitter
* splitter
= m_viewTab
[m_tabIndex
].splitter
;
1034 m_centralWidgetLayout
->removeWidget(splitter
);
1036 // show active tab content
1039 ViewTab
& viewTab
= m_viewTab
[index
];
1040 m_centralWidgetLayout
->addWidget(viewTab
.splitter
, 1);
1041 viewTab
.primaryView
->show();
1042 if (viewTab
.secondaryView
!= 0) {
1043 viewTab
.secondaryView
->show();
1045 viewTab
.splitter
->show();
1047 setActiveViewContainer(viewTab
.isPrimaryViewActive
? viewTab
.primaryView
:
1048 viewTab
.secondaryView
);
1051 void DolphinMainWindow::closeTab()
1053 closeTab(m_tabBar
->currentIndex());
1056 void DolphinMainWindow::closeTab(int index
)
1058 Q_ASSERT(index
>= 0);
1059 Q_ASSERT(index
< m_viewTab
.count());
1060 if (m_viewTab
.count() == 1) {
1061 // the last tab may never get closed
1065 if (index
== m_tabIndex
) {
1066 // The tab that should be closed is the active tab. Activate the
1067 // previous tab before closing the tab.
1068 m_tabBar
->setCurrentIndex((index
> 0) ? index
- 1 : 1);
1070 rememberClosedTab(index
);
1073 m_viewTab
[index
].primaryView
->deleteLater();
1074 if (m_viewTab
[index
].secondaryView
!= 0) {
1075 m_viewTab
[index
].secondaryView
->deleteLater();
1077 m_viewTab
[index
].splitter
->deleteLater();
1078 m_viewTab
.erase(m_viewTab
.begin() + index
);
1080 m_tabBar
->blockSignals(true);
1081 m_tabBar
->removeTab(index
);
1083 if (m_tabIndex
> index
) {
1085 Q_ASSERT(m_tabIndex
>= 0);
1088 // if only one tab is left, also remove the tab entry so that
1089 // closing the last tab is not possible
1090 if (m_viewTab
.count() == 1) {
1091 m_tabBar
->removeTab(0);
1092 actionCollection()->action("close_tab")->setEnabled(false);
1094 m_tabBar
->blockSignals(false);
1098 void DolphinMainWindow::openTabContextMenu(int index
, const QPoint
& pos
)
1102 QAction
* newTabAction
= menu
.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab"));
1103 newTabAction
->setShortcut(actionCollection()->action("new_tab")->shortcut());
1105 QAction
* detachTabAction
= menu
.addAction(KIcon("tab-detach"), i18nc("@action:inmenu", "Detach Tab"));
1107 QAction
* closeOtherTabsAction
= menu
.addAction(KIcon("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs"));
1109 QAction
* closeTabAction
= menu
.addAction(KIcon("tab-close"), i18nc("@action:inmenu", "Close Tab"));
1110 closeTabAction
->setShortcut(actionCollection()->action("close_tab")->shortcut());
1111 QAction
* selectedAction
= menu
.exec(pos
);
1112 if (selectedAction
== newTabAction
) {
1113 const ViewTab
& tab
= m_viewTab
[index
];
1114 Q_ASSERT(tab
.primaryView
!= 0);
1115 const KUrl url
= (tab
.secondaryView
!= 0) && tab
.secondaryView
->isActive() ?
1116 tab
.secondaryView
->url() : tab
.primaryView
->url();
1118 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
1119 } else if (selectedAction
== detachTabAction
) {
1120 const ViewTab
& tab
= m_viewTab
[index
];
1121 Q_ASSERT(tab
.primaryView
!= 0);
1122 const KUrl primaryUrl
= tab
.primaryView
->url();
1123 DolphinMainWindow
* window
= DolphinApplication::app()->createMainWindow();
1124 window
->changeUrl(primaryUrl
);
1126 if (tab
.secondaryView
!= 0) {
1127 const KUrl secondaryUrl
= tab
.secondaryView
->url();
1128 window
->toggleSplitView();
1129 window
->m_viewTab
[0].secondaryView
->setUrl(secondaryUrl
);
1130 if (tab
.primaryView
->isActive()) {
1131 window
->m_viewTab
[0].primaryView
->setActive(true);
1133 window
->m_viewTab
[0].secondaryView
->setActive(true);
1138 } else if (selectedAction
== closeOtherTabsAction
) {
1139 const int count
= m_tabBar
->count();
1140 for (int i
= 0; i
< index
; ++i
) {
1143 for (int i
= index
+ 1; i
< count
; ++i
) {
1146 } else if (selectedAction
== closeTabAction
) {
1151 void DolphinMainWindow::slotTabMoved(int from
, int to
)
1153 m_viewTab
.move(from
, to
);
1154 m_tabIndex
= m_tabBar
->currentIndex();
1157 void DolphinMainWindow::handlePlacesClick(const KUrl
& url
, Qt::MouseButtons buttons
)
1159 if (buttons
& Qt::MidButton
) {
1161 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
1167 void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent
* event
, bool& canDecode
)
1169 canDecode
= KUrl::List::canDecode(event
->mimeData());
1172 void DolphinMainWindow::handleUrl(const KUrl
& url
)
1174 delete m_lastHandleUrlStatJob
;
1175 m_lastHandleUrlStatJob
= 0;
1177 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1178 activeViewContainer()->setUrl(url
);
1179 } else if (KProtocolManager::supportsListing(url
)) {
1180 // stat the URL to see if it is a dir or not
1181 m_lastHandleUrlStatJob
= KIO::stat(url
, KIO::HideProgressInfo
);
1182 connect(m_lastHandleUrlStatJob
, SIGNAL(result(KJob
*)),
1183 this, SLOT(slotHandleUrlStatFinished(KJob
*)));
1186 new KRun(url
, this);
1190 void DolphinMainWindow::slotHandleUrlStatFinished(KJob
* job
)
1192 m_lastHandleUrlStatJob
= 0;
1193 const KIO::UDSEntry entry
= static_cast<KIO::StatJob
*>(job
)->statResult();
1194 const KUrl url
= static_cast<KIO::StatJob
*>(job
)->url();
1195 if (entry
.isDir()) {
1196 activeViewContainer()->setUrl(url
);
1198 new KRun(url
, this);
1202 void DolphinMainWindow::tabDropEvent(int tab
, QDropEvent
* event
)
1204 const KUrl::List urls
= KUrl::List::fromMimeData(event
->mimeData());
1205 if (!urls
.isEmpty() && tab
!= -1) {
1206 const ViewTab
& viewTab
= m_viewTab
[tab
];
1207 const KUrl destPath
= viewTab
.isPrimaryViewActive
? viewTab
.primaryView
->url() : viewTab
.secondaryView
->url();
1208 DragAndDropHelper::instance().dropUrls(KFileItem(), destPath
, event
, m_tabBar
);
1212 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1214 newFileMenu()->setEnabled(isFolderWritable
);
1217 void DolphinMainWindow::slotSearchModeChanged(bool enabled
)
1220 if (Nepomuk::ResourceManager::instance()->init() != 0) {
1221 // Currently the Filter Panel only works with Nepomuk enabled
1225 QDockWidget
* filterDock
= findChild
<QDockWidget
*>("filterDock");
1226 if ((filterDock
== 0) || !filterDock
->isEnabled()) {
1231 if (!filterDock
->isVisible()) {
1232 m_filterDockIsTemporaryVisible
= true;
1236 if (filterDock
->isVisible() && m_filterDockIsTemporaryVisible
) {
1239 m_filterDockIsTemporaryVisible
= false;
1246 void DolphinMainWindow::openContextMenu(const KFileItem
& item
,
1248 const QList
<QAction
*>& customActions
)
1250 QPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, item
, url
);
1251 contextMenu
->setCustomActions(customActions
);
1252 const DolphinContextMenu::Command command
= contextMenu
->open();
1255 case DolphinContextMenu::OpenParentFolderInNewWindow
: {
1256 DolphinMainWindow
* window
= DolphinApplication::app()->createMainWindow();
1257 window
->changeUrl(item
.url().upUrl());
1262 case DolphinContextMenu::OpenParentFolderInNewTab
:
1263 openNewTab(item
.url().upUrl());
1266 case DolphinContextMenu::None
:
1274 void DolphinMainWindow::init()
1276 DolphinSettings
& settings
= DolphinSettings::instance();
1278 // Check whether Dolphin runs the first time. If yes then
1279 // a proper default window size is given at the end of DolphinMainWindow::init().
1280 GeneralSettings
* generalSettings
= settings
.generalSettings();
1281 const bool firstRun
= generalSettings
->firstRun();
1283 generalSettings
->setViewPropsTimestamp(QDateTime::currentDateTime());
1286 setAcceptDrops(true);
1288 m_viewTab
[m_tabIndex
].splitter
= new QSplitter(this);
1289 m_viewTab
[m_tabIndex
].splitter
->setChildrenCollapsible(false);
1293 const KUrl
homeUrl(generalSettings
->homeUrl());
1294 setUrlAsCaption(homeUrl
);
1295 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
1296 connect(m_actionHandler
, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
1297 connect(m_actionHandler
, SIGNAL(createDirectory()), SLOT(createDirectory()));
1298 ViewProperties
props(homeUrl
);
1299 m_viewTab
[m_tabIndex
].primaryView
= new DolphinViewContainer(homeUrl
,
1300 m_viewTab
[m_tabIndex
].splitter
);
1302 m_activeViewContainer
= m_viewTab
[m_tabIndex
].primaryView
;
1303 connectViewSignals(m_activeViewContainer
);
1304 DolphinView
* view
= m_activeViewContainer
->view();
1306 m_activeViewContainer
->show();
1307 m_actionHandler
->setCurrentView(view
);
1309 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
1310 connect(this, SIGNAL(urlChanged(const KUrl
&)),
1311 m_remoteEncoding
, SLOT(slotAboutToOpenUrl()));
1313 m_tabBar
= new KTabBar(this);
1314 m_tabBar
->setMovable(true);
1315 m_tabBar
->setTabsClosable(true);
1316 connect(m_tabBar
, SIGNAL(currentChanged(int)),
1317 this, SLOT(setActiveTab(int)));
1318 connect(m_tabBar
, SIGNAL(tabCloseRequested(int)),
1319 this, SLOT(closeTab(int)));
1320 connect(m_tabBar
, SIGNAL(contextMenu(int, const QPoint
&)),
1321 this, SLOT(openTabContextMenu(int, const QPoint
&)));
1322 connect(m_tabBar
, SIGNAL(newTabRequest()),
1323 this, SLOT(openNewTab()));
1324 connect(m_tabBar
, SIGNAL(testCanDecode(const QDragMoveEvent
*, bool&)),
1325 this, SLOT(slotTestCanDecode(const QDragMoveEvent
*, bool&)));
1326 connect(m_tabBar
, SIGNAL(mouseMiddleClick(int)),
1327 this, SLOT(closeTab(int)));
1328 connect(m_tabBar
, SIGNAL(tabMoved(int, int)),
1329 this, SLOT(slotTabMoved(int, int)));
1330 connect(m_tabBar
, SIGNAL(receivedDropEvent(int, QDropEvent
*)),
1331 this, SLOT(tabDropEvent(int, QDropEvent
*)));
1333 m_tabBar
->blockSignals(true); // signals get unblocked after at least 2 tabs are open
1335 QWidget
* centralWidget
= new QWidget(this);
1336 m_centralWidgetLayout
= new QVBoxLayout(centralWidget
);
1337 m_centralWidgetLayout
->setSpacing(0);
1338 m_centralWidgetLayout
->setMargin(0);
1339 m_centralWidgetLayout
->addWidget(m_tabBar
);
1340 m_centralWidgetLayout
->addWidget(m_viewTab
[m_tabIndex
].splitter
, 1);
1342 setCentralWidget(centralWidget
);
1344 emit
urlChanged(homeUrl
);
1346 setupGUI(Keys
| Save
| Create
| ToolBar
);
1347 stateChanged("new_file");
1349 QClipboard
* clipboard
= QApplication::clipboard();
1350 connect(clipboard
, SIGNAL(dataChanged()),
1351 this, SLOT(updatePasteAction()));
1353 if (generalSettings
->splitView()) {
1356 updateEditActions();
1357 updateViewActions();
1360 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1361 showFilterBarAction
->setChecked(generalSettings
->filterBar());
1364 // assure a proper default size if Dolphin runs the first time
1368 m_showMenuBar
->setChecked(!menuBar()->isHidden()); // workaround for bug #171080
1371 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer
* viewContainer
)
1373 Q_ASSERT(viewContainer
!= 0);
1374 Q_ASSERT((viewContainer
== m_viewTab
[m_tabIndex
].primaryView
) ||
1375 (viewContainer
== m_viewTab
[m_tabIndex
].secondaryView
));
1376 if (m_activeViewContainer
== viewContainer
) {
1380 m_activeViewContainer
->setActive(false);
1381 m_activeViewContainer
= viewContainer
;
1383 // Activating the view container might trigger a recursive setActiveViewContainer() call
1384 // inside DolphinMainWindow::toggleActiveView() when having a split view. Temporary
1385 // disconnect the activated() signal in this case:
1386 disconnect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1387 m_activeViewContainer
->setActive(true);
1388 connect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1390 m_actionHandler
->setCurrentView(viewContainer
->view());
1393 updateEditActions();
1394 updateViewActions();
1397 const KUrl url
= m_activeViewContainer
->url();
1398 setUrlAsCaption(url
);
1399 if (m_viewTab
.count() > 1) {
1400 m_tabBar
->setTabText(m_tabIndex
, tabName(url
));
1401 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(KMimeType::iconNameForUrl(url
)));
1404 emit
urlChanged(url
);
1407 void DolphinMainWindow::setupActions()
1409 // setup 'File' menu
1410 m_newFileMenu
= new DolphinNewFileMenu(this, this);
1411 KMenu
* menu
= m_newFileMenu
->menu();
1412 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1413 menu
->setIcon(KIcon("document-new"));
1414 connect(menu
, SIGNAL(aboutToShow()),
1415 this, SLOT(updateNewMenu()));
1417 KAction
* newWindow
= actionCollection()->addAction("new_window");
1418 newWindow
->setIcon(KIcon("window-new"));
1419 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1420 newWindow
->setShortcut(Qt::CTRL
| Qt::Key_N
);
1421 connect(newWindow
, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1423 KAction
* newTab
= actionCollection()->addAction("new_tab");
1424 newTab
->setIcon(KIcon("tab-new"));
1425 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1426 newTab
->setShortcut(KShortcut(Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
));
1427 connect(newTab
, SIGNAL(triggered()), this, SLOT(openNewTab()));
1429 KAction
* closeTab
= actionCollection()->addAction("close_tab");
1430 closeTab
->setIcon(KIcon("tab-close"));
1431 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1432 closeTab
->setShortcut(Qt::CTRL
| Qt::Key_W
);
1433 closeTab
->setEnabled(false);
1434 connect(closeTab
, SIGNAL(triggered()), this, SLOT(closeTab()));
1436 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1438 // setup 'Edit' menu
1439 KStandardAction::undo(this,
1441 actionCollection());
1443 // need to remove shift+del from cut action, else the shortcut for deletejob
1445 KAction
* cut
= KStandardAction::cut(this, SLOT(cut()), actionCollection());
1446 KShortcut cutShortcut
= cut
->shortcut();
1447 cutShortcut
.remove(Qt::SHIFT
+ Qt::Key_Delete
, KShortcut::KeepEmpty
);
1448 cut
->setShortcut(cutShortcut
);
1449 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1450 KAction
* paste
= KStandardAction::paste(this, SLOT(paste()), actionCollection());
1451 // The text of the paste-action is modified dynamically by Dolphin
1452 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1453 // due to the long text, the text "Paste" is used:
1454 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1456 KStandardAction::find(this, SLOT(find()), actionCollection());
1458 KAction
* selectAll
= actionCollection()->addAction("select_all");
1459 selectAll
->setText(i18nc("@action:inmenu Edit", "Select All"));
1460 selectAll
->setShortcut(Qt::CTRL
+ Qt::Key_A
);
1461 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
1463 KAction
* invertSelection
= actionCollection()->addAction("invert_selection");
1464 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1465 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1466 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
1468 // setup 'View' menu
1469 // (note that most of it is set up in DolphinViewActionHandler)
1471 KAction
* split
= actionCollection()->addAction("split_view");
1472 split
->setShortcut(Qt::Key_F3
);
1473 updateSplitAction();
1474 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1476 KAction
* reload
= actionCollection()->addAction("reload");
1477 reload
->setText(i18nc("@action:inmenu View", "Reload"));
1478 reload
->setShortcut(Qt::Key_F5
);
1479 reload
->setIcon(KIcon("view-refresh"));
1480 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
1482 KAction
* stop
= actionCollection()->addAction("stop");
1483 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1484 stop
->setToolTip(i18nc("@info", "Stop loading"));
1485 stop
->setIcon(KIcon("process-stop"));
1486 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
1488 KToggleAction
* showFullLocation
= actionCollection()->add
<KToggleAction
>("editable_location");
1489 showFullLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1490 showFullLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
1491 connect(showFullLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1493 KAction
* replaceLocation
= actionCollection()->addAction("replace_location");
1494 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1495 replaceLocation
->setShortcut(Qt::Key_F6
);
1496 connect(replaceLocation
, SIGNAL(triggered()), this, SLOT(replaceLocation()));
1499 KAction
* backAction
= KStandardAction::back(this, SLOT(goBack()), actionCollection());
1500 connect(backAction
, SIGNAL(triggered(Qt::MouseButtons
, Qt::KeyboardModifiers
)), this, SLOT(goBack(Qt::MouseButtons
)));
1501 KShortcut backShortcut
= backAction
->shortcut();
1502 backShortcut
.setAlternate(Qt::Key_Backspace
);
1503 backAction
->setShortcut(backShortcut
);
1505 m_recentTabsMenu
= new KActionMenu(i18n("Recently Closed Tabs"), this);
1506 m_recentTabsMenu
->setIcon(KIcon("edit-undo"));
1507 actionCollection()->addAction("closed_tabs", m_recentTabsMenu
);
1508 connect(m_recentTabsMenu
->menu(), SIGNAL(triggered(QAction
*)),
1509 this, SLOT(restoreClosedTab(QAction
*)));
1511 QAction
* action
= new QAction("Empty Recently Closed Tabs", m_recentTabsMenu
);
1512 action
->setIcon(KIcon("edit-clear-list"));
1513 action
->setData(QVariant::fromValue(true));
1514 m_recentTabsMenu
->addAction(action
);
1515 m_recentTabsMenu
->addSeparator();
1516 m_recentTabsMenu
->setEnabled(false);
1518 KAction
* forwardAction
= KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1519 connect(forwardAction
, SIGNAL(triggered(Qt::MouseButtons
, Qt::KeyboardModifiers
)), this, SLOT(goForward(Qt::MouseButtons
)));
1521 KAction
* upAction
= KStandardAction::up(this, SLOT(goUp()), actionCollection());
1522 connect(upAction
, SIGNAL(triggered(Qt::MouseButtons
, Qt::KeyboardModifiers
)), this, SLOT(goUp(Qt::MouseButtons
)));
1524 KStandardAction::home(this, SLOT(goHome()), actionCollection());
1526 // setup 'Tools' menu
1527 KAction
* showFilterBar
= actionCollection()->addAction("show_filter_bar");
1528 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1529 showFilterBar
->setIcon(KIcon("view-filter"));
1530 showFilterBar
->setShortcut(Qt::CTRL
| Qt::Key_I
);
1531 connect(showFilterBar
, SIGNAL(triggered()), this, SLOT(showFilterBar()));
1533 KAction
* compareFiles
= actionCollection()->addAction("compare_files");
1534 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1535 compareFiles
->setIcon(KIcon("kompare"));
1536 compareFiles
->setEnabled(false);
1537 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
1539 KAction
* openTerminal
= actionCollection()->addAction("open_terminal");
1540 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1541 openTerminal
->setIcon(KIcon("utilities-terminal"));
1542 openTerminal
->setShortcut(Qt::SHIFT
| Qt::Key_F4
);
1543 connect(openTerminal
, SIGNAL(triggered()), this, SLOT(openTerminal()));
1545 // setup 'Settings' menu
1546 m_showMenuBar
= KStandardAction::showMenubar(this, SLOT(toggleShowMenuBar()), actionCollection());
1547 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1549 // not in menu actions
1550 QList
<QKeySequence
> nextTabKeys
;
1551 nextTabKeys
.append(KStandardShortcut::tabNext().primary());
1552 nextTabKeys
.append(QKeySequence(Qt::CTRL
+ Qt::Key_Tab
));
1554 QList
<QKeySequence
> prevTabKeys
;
1555 prevTabKeys
.append(KStandardShortcut::tabPrev().primary());
1556 prevTabKeys
.append(QKeySequence(Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_Tab
));
1558 KAction
* activateNextTab
= actionCollection()->addAction("activate_next_tab");
1559 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1560 connect(activateNextTab
, SIGNAL(triggered()), SLOT(activateNextTab()));
1561 activateNextTab
->setShortcuts(QApplication::isRightToLeft() ? prevTabKeys
: nextTabKeys
);
1563 KAction
* activatePrevTab
= actionCollection()->addAction("activate_prev_tab");
1564 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1565 connect(activatePrevTab
, SIGNAL(triggered()), SLOT(activatePrevTab()));
1566 activatePrevTab
->setShortcuts(QApplication::isRightToLeft() ? nextTabKeys
: prevTabKeys
);
1569 KAction
* openInNewTab
= actionCollection()->addAction("open_in_new_tab");
1570 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1571 openInNewTab
->setIcon(KIcon("tab-new"));
1572 connect(openInNewTab
, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1574 KAction
* openInNewWindow
= actionCollection()->addAction("open_in_new_window");
1575 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1576 openInNewWindow
->setIcon(KIcon("window-new"));
1577 connect(openInNewWindow
, SIGNAL(triggered()), this, SLOT(openInNewWindow()));
1580 void DolphinMainWindow::setupDockWidgets()
1582 const bool lock
= DolphinSettings::instance().generalSettings()->lockPanels();
1584 KDualAction
* lockLayoutAction
= actionCollection()->add
<KDualAction
>("lock_panels");
1585 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
1586 lockLayoutAction
->setActiveIcon(KIcon("object-unlocked"));
1587 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
1588 lockLayoutAction
->setInactiveIcon(KIcon("object-locked"));
1589 lockLayoutAction
->setActive(lock
);
1590 connect(lockLayoutAction
, SIGNAL(triggered()), this, SLOT(togglePanelLockState()));
1592 // Setup "Information"
1593 DolphinDockWidget
* infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
1594 infoDock
->setLocked(lock
);
1595 infoDock
->setObjectName("infoDock");
1596 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1597 Panel
* infoPanel
= new InformationPanel(infoDock
);
1598 infoPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1599 connect(infoPanel
, SIGNAL(urlActivated(KUrl
)), this, SLOT(handleUrl(KUrl
)));
1600 infoDock
->setWidget(infoPanel
);
1602 QAction
* infoAction
= infoDock
->toggleViewAction();
1603 infoAction
->setIcon(KIcon("dialog-information"));
1604 infoAction
->setShortcut(Qt::Key_F11
);
1605 addActionCloneToCollection(infoAction
, "show_information_panel");
1607 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1608 connect(this, SIGNAL(urlChanged(KUrl
)),
1609 infoPanel
, SLOT(setUrl(KUrl
)));
1610 connect(this, SIGNAL(selectionChanged(KFileItemList
)),
1611 infoPanel
, SLOT(setSelection(KFileItemList
)));
1612 connect(this, SIGNAL(requestItemInfo(KFileItem
)),
1613 infoPanel
, SLOT(requestDelayedItemInfo(KFileItem
)));
1616 DolphinDockWidget
* foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
1617 foldersDock
->setLocked(lock
);
1618 foldersDock
->setObjectName("foldersDock");
1619 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1620 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1621 foldersPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1622 foldersDock
->setWidget(foldersPanel
);
1624 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1625 foldersAction
->setShortcut(Qt::Key_F7
);
1626 foldersAction
->setIcon(KIcon("folder"));
1627 addActionCloneToCollection(foldersAction
, "show_folders_panel");
1629 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1630 connect(this, SIGNAL(urlChanged(KUrl
)),
1631 foldersPanel
, SLOT(setUrl(KUrl
)));
1632 connect(foldersPanel
, SIGNAL(changeUrl(KUrl
, Qt::MouseButtons
)),
1633 this, SLOT(handlePlacesClick(KUrl
, Qt::MouseButtons
)));
1637 DolphinDockWidget
* terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1638 terminalDock
->setLocked(lock
);
1639 terminalDock
->setObjectName("terminalDock");
1640 terminalDock
->setAllowedAreas(Qt::TopDockWidgetArea
| Qt::BottomDockWidgetArea
);
1641 Panel
* terminalPanel
= new TerminalPanel(terminalDock
);
1642 terminalPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1643 terminalDock
->setWidget(terminalPanel
);
1645 connect(terminalPanel
, SIGNAL(hideTerminalPanel()), terminalDock
, SLOT(hide()));
1647 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1648 terminalAction
->setShortcut(Qt::Key_F4
);
1649 terminalAction
->setIcon(KIcon("utilities-terminal"));
1650 addActionCloneToCollection(terminalAction
, "show_terminal_panel");
1652 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1653 connect(this, SIGNAL(urlChanged(KUrl
)),
1654 terminalPanel
, SLOT(setUrl(KUrl
)));
1659 DolphinDockWidget
* filterDock
= new DolphinDockWidget(i18nc("@title:window", "Filter"));
1660 filterDock
->setLocked(lock
);
1661 filterDock
->setObjectName("filterDock");
1662 filterDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1663 Panel
* filterPanel
= new FilterPanel(filterDock
);
1664 filterPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1665 connect(filterPanel
, SIGNAL(urlActivated(KUrl
)), this, SLOT(handleUrl(KUrl
)));
1666 filterDock
->setWidget(filterPanel
);
1668 QAction
* filterAction
= filterDock
->toggleViewAction();
1669 filterAction
->setShortcut(Qt::Key_F12
);
1670 filterAction
->setIcon(KIcon("view-filter"));
1671 addActionCloneToCollection(filterAction
, "show_filter_panel");
1672 addDockWidget(Qt::RightDockWidgetArea
, filterDock
);
1673 connect(this, SIGNAL(urlChanged(KUrl
)),
1674 filterPanel
, SLOT(setUrl(KUrl
)));
1677 const bool firstRun
= DolphinSettings::instance().generalSettings()->firstRun();
1680 foldersDock
->hide();
1682 terminalDock
->hide();
1690 DolphinDockWidget
* placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
1691 placesDock
->setLocked(lock
);
1692 placesDock
->setObjectName("placesDock");
1693 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1695 PlacesPanel
* placesPanel
= new PlacesPanel(placesDock
);
1696 QAction
* separator
= new QAction(placesPanel
);
1697 separator
->setSeparator(true);
1698 QList
<QAction
*> placesActions
;
1699 placesActions
.append(separator
);
1700 placesActions
.append(lockLayoutAction
);
1701 placesPanel
->addActions(placesActions
);
1702 placesPanel
->setModel(DolphinSettings::instance().placesModel());
1703 placesPanel
->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff
);
1704 placesDock
->setWidget(placesPanel
);
1706 QAction
* placesAction
= placesDock
->toggleViewAction();
1707 placesAction
->setShortcut(Qt::Key_F9
);
1708 placesAction
->setIcon(KIcon("bookmarks"));
1709 addActionCloneToCollection(placesAction
, "show_places_panel");
1711 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1712 connect(placesPanel
, SIGNAL(urlChanged(KUrl
, Qt::MouseButtons
)),
1713 this, SLOT(handlePlacesClick(KUrl
, Qt::MouseButtons
)));
1714 connect(this, SIGNAL(urlChanged(KUrl
)),
1715 placesPanel
, SLOT(setUrl(KUrl
)));
1717 // Add actions into the "Panels" menu
1718 KActionMenu
* panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Panels"), this);
1719 actionCollection()->addAction("panels", panelsMenu
);
1720 panelsMenu
->setDelayed(false);
1721 panelsMenu
->addAction(placesAction
);
1722 panelsMenu
->addAction(infoAction
);
1723 panelsMenu
->addAction(foldersAction
);
1725 panelsMenu
->addAction(terminalAction
);
1728 panelsMenu
->addAction(filterAction
);
1730 panelsMenu
->addSeparator();
1731 panelsMenu
->addAction(lockLayoutAction
);
1734 void DolphinMainWindow::updateEditActions()
1736 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1737 if (list
.isEmpty()) {
1738 stateChanged("has_no_selection");
1740 stateChanged("has_selection");
1742 KActionCollection
* col
= actionCollection();
1743 QAction
* renameAction
= col
->action("rename");
1744 QAction
* moveToTrashAction
= col
->action("move_to_trash");
1745 QAction
* deleteAction
= col
->action("delete");
1746 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
1747 QAction
* deleteWithTrashShortcut
= col
->action("delete_shortcut"); // see DolphinViewActionHandler
1749 KFileItemListProperties
capabilities(list
);
1750 const bool enableMoveToTrash
= capabilities
.isLocal() && capabilities
.supportsMoving();
1752 renameAction
->setEnabled(capabilities
.supportsMoving());
1753 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1754 deleteAction
->setEnabled(capabilities
.supportsDeleting());
1755 deleteWithTrashShortcut
->setEnabled(capabilities
.supportsDeleting() && !enableMoveToTrash
);
1756 cutAction
->setEnabled(capabilities
.supportsMoving());
1758 updatePasteAction();
1761 void DolphinMainWindow::updateViewActions()
1763 m_actionHandler
->updateViewActions();
1765 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1766 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
1768 updateSplitAction();
1770 QAction
* editableLocactionAction
= actionCollection()->action("editable_location");
1771 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
1772 editableLocactionAction
->setChecked(urlNavigator
->isUrlEditable());
1775 void DolphinMainWindow::updateGoActions()
1777 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
1778 const KUrl currentUrl
= m_activeViewContainer
->url();
1779 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
1782 void DolphinMainWindow::rememberClosedTab(int index
)
1784 KMenu
* tabsMenu
= m_recentTabsMenu
->menu();
1786 const QString primaryPath
= m_viewTab
[index
].primaryView
->url().path();
1787 const QString iconName
= KMimeType::iconNameForUrl(primaryPath
);
1789 QAction
* action
= new QAction(squeezedText(primaryPath
), tabsMenu
);
1791 ClosedTab closedTab
;
1792 closedTab
.primaryUrl
= m_viewTab
[index
].primaryView
->url();
1794 if (m_viewTab
[index
].secondaryView
!= 0) {
1795 closedTab
.secondaryUrl
= m_viewTab
[index
].secondaryView
->url();
1796 closedTab
.isSplit
= true;
1798 closedTab
.isSplit
= false;
1801 action
->setData(QVariant::fromValue(closedTab
));
1802 action
->setIcon(KIcon(iconName
));
1804 // add the closed tab menu entry after the separator and
1805 // "Empty Recently Closed Tabs" entry
1806 if (tabsMenu
->actions().size() == 2) {
1807 tabsMenu
->addAction(action
);
1809 tabsMenu
->insertAction(tabsMenu
->actions().at(2), action
);
1812 // assure that only up to 8 closed tabs are shown in the menu
1813 if (tabsMenu
->actions().size() > 8) {
1814 tabsMenu
->removeAction(tabsMenu
->actions().last());
1816 actionCollection()->action("closed_tabs")->setEnabled(true);
1817 KAcceleratorManager::manage(tabsMenu
);
1820 void DolphinMainWindow::clearStatusBar()
1822 m_activeViewContainer
->statusBar()->clear();
1825 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
1827 connect(container
, SIGNAL(showFilterBarChanged(bool)),
1828 this, SLOT(updateFilterBarAction(bool)));
1829 connect(container
, SIGNAL(writeStateChanged(bool)),
1830 this, SLOT(slotWriteStateChanged(bool)));
1831 connect(container
, SIGNAL(searchModeChanged(bool)),
1832 this, SLOT(slotSearchModeChanged(bool)));
1834 DolphinView
* view
= container
->view();
1835 connect(view
, SIGNAL(selectionChanged(KFileItemList
)),
1836 this, SLOT(slotSelectionChanged(KFileItemList
)));
1837 connect(view
, SIGNAL(requestItemInfo(KFileItem
)),
1838 this, SLOT(slotRequestItemInfo(KFileItem
)));
1839 connect(view
, SIGNAL(activated()),
1840 this, SLOT(toggleActiveView()));
1841 connect(view
, SIGNAL(tabRequested(const KUrl
&)),
1842 this, SLOT(openNewTab(const KUrl
&)));
1843 connect(view
, SIGNAL(requestContextMenu(KFileItem
, const KUrl
&, const QList
<QAction
*>&)),
1844 this, SLOT(openContextMenu(KFileItem
, const KUrl
&, const QList
<QAction
*>&)));
1845 connect(view
, SIGNAL(startedPathLoading(KUrl
)),
1846 this, SLOT(enableStopAction()));
1847 connect(view
, SIGNAL(finishedPathLoading(KUrl
)),
1848 this, SLOT(disableStopAction()));
1850 const KUrlNavigator
* navigator
= container
->urlNavigator();
1851 connect(navigator
, SIGNAL(urlChanged(const KUrl
&)),
1852 this, SLOT(changeUrl(const KUrl
&)));
1853 connect(navigator
, SIGNAL(historyChanged()),
1854 this, SLOT(updateHistory()));
1855 connect(navigator
, SIGNAL(editableStateChanged(bool)),
1856 this, SLOT(slotEditableStateChanged(bool)));
1857 connect(navigator
, SIGNAL(tabRequested(const KUrl
&)),
1858 this, SLOT(openNewTab(KUrl
)));
1861 void DolphinMainWindow::updateSplitAction()
1863 QAction
* splitAction
= actionCollection()->action("split_view");
1864 if (m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
1865 if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
1866 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
1867 splitAction
->setToolTip(i18nc("@info", "Close right view"));
1868 splitAction
->setIcon(KIcon("view-right-close"));
1870 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
1871 splitAction
->setToolTip(i18nc("@info", "Close left view"));
1872 splitAction
->setIcon(KIcon("view-left-close"));
1875 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
1876 splitAction
->setToolTip(i18nc("@info", "Split view"));
1877 splitAction
->setIcon(KIcon("view-right-new"));
1881 QString
DolphinMainWindow::tabName(const KUrl
& url
) const
1884 if (url
.equals(KUrl("file:///"))) {
1887 name
= url
.fileName();
1888 if (name
.isEmpty()) {
1889 name
= url
.protocol();
1891 // Make sure that a '&' inside the directory name is displayed correctly
1892 // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
1893 name
.replace('&', "&&");
1899 bool DolphinMainWindow::isKompareInstalled() const
1901 static bool initialized
= false;
1902 static bool installed
= false;
1904 // TODO: maybe replace this approach later by using a menu
1905 // plugin like kdiff3plugin.cpp
1906 installed
= !KGlobal::dirs()->findExe("kompare").isEmpty();
1912 void DolphinMainWindow::createSecondaryView(int tabIndex
)
1914 QSplitter
* splitter
= m_viewTab
[tabIndex
].splitter
;
1915 const int newWidth
= (m_viewTab
[tabIndex
].primaryView
->width() - splitter
->handleWidth()) / 2;
1917 const DolphinView
* view
= m_viewTab
[tabIndex
].primaryView
->view();
1918 m_viewTab
[tabIndex
].secondaryView
= new DolphinViewContainer(view
->rootUrl(), 0);
1919 splitter
->addWidget(m_viewTab
[tabIndex
].secondaryView
);
1920 splitter
->setSizes(QList
<int>() << newWidth
<< newWidth
);
1921 connectViewSignals(m_viewTab
[tabIndex
].secondaryView
);
1922 m_viewTab
[tabIndex
].secondaryView
->view()->reload();
1923 m_viewTab
[tabIndex
].secondaryView
->setActive(false);
1924 m_viewTab
[tabIndex
].secondaryView
->show();
1927 QString
DolphinMainWindow::tabProperty(const QString
& property
, int tabIndex
) const
1929 return "Tab " + QString::number(tabIndex
) + ' ' + property
;
1932 void DolphinMainWindow::setUrlAsCaption(const KUrl
& url
)
1935 if (!url
.isLocalFile()) {
1936 caption
.append(url
.protocol() + " - ");
1937 if (url
.hasHost()) {
1938 caption
.append(url
.host() + " - ");
1942 const QString fileName
= url
.fileName().isEmpty() ? "/" : url
.fileName();
1943 caption
.append(fileName
);
1945 setCaption(caption
);
1948 QString
DolphinMainWindow::squeezedText(const QString
& text
) const
1950 const QFontMetrics fm
= fontMetrics();
1951 return fm
.elidedText(text
, Qt::ElideMiddle
, fm
.maxWidth() * 10);
1954 void DolphinMainWindow::addActionCloneToCollection(QAction
* action
, const QString
& actionName
)
1956 KAction
* actionClone
= actionCollection()->addAction(actionName
);
1957 actionClone
->setText(action
->text());
1958 actionClone
->setIcon(action
->icon());
1959 connect(actionClone
, SIGNAL(triggered()), action
, SLOT(trigger()));
1962 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
1963 KIO::FileUndoManager::UiInterface()
1967 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
1971 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
1973 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
1975 DolphinStatusBar
* statusBar
= mainWin
->activeViewContainer()->statusBar();
1976 statusBar
->setMessage(job
->errorString(), DolphinStatusBar::Error
);
1978 KIO::FileUndoManager::UiInterface::jobError(job
);
1982 #include "dolphinmainwindow.moc"