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"
56 #include <KActionCollection>
57 #include <KActionMenu>
59 #include <KDesktopFile>
60 #include <kdeversion.h>
61 #include <kdualaction.h>
62 #include <KFileDialog>
63 #include <KFilePlacesModel>
68 #include <KIconLoader>
69 #include <KIO/NetAccess>
70 #include <KInputDialog>
72 #include <KProtocolManager>
75 #include <KMessageBox>
76 #include <KFileItemListProperties>
77 #include <konqmimedata.h>
78 #include <KProtocolInfo>
81 #include <KStandardDirs>
82 #include <kstatusbar.h>
83 #include <KStandardAction>
85 #include <KToggleAction>
86 #include <KUrlNavigator>
88 #include <KUrlComboBox>
89 #include <KToolInvocation>
91 #include <QDBusMessage>
95 #include <kacceleratormanager.h>
98 * Remembers the tab configuration if a tab has been closed.
99 * Each closed tab can be restored by the menu
100 * "Go -> Recently Closed Tabs".
108 Q_DECLARE_METATYPE(ClosedTab
)
110 DolphinMainWindow::DolphinMainWindow(int id
) :
115 m_activeViewContainer(0),
116 m_centralWidgetLayout(0),
123 m_lastHandleUrlStatJob(0),
124 m_searchDockIsTemporaryVisible(false)
126 // Workaround for a X11-issue in combination with KModifierInfo
127 // (see DolphinContextMenu::initializeModifierKeyInfo() for
128 // more information):
129 DolphinContextMenu::initializeModifierKeyInfo();
131 setObjectName("Dolphin#");
133 m_viewTab
.append(ViewTab());
135 new MainWindowAdaptor(this);
136 QDBusConnection::sessionBus().registerObject(QString("/dolphin/MainWindow%1").arg(m_id
), this);
138 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
139 undoManager
->setUiInterface(new UndoUiInterface());
141 connect(undoManager
, SIGNAL(undoAvailable(bool)),
142 this, SLOT(slotUndoAvailable(bool)));
143 connect(undoManager
, SIGNAL(undoTextChanged(const QString
&)),
144 this, SLOT(slotUndoTextChanged(const QString
&)));
145 connect(undoManager
, SIGNAL(jobRecordingStarted(CommandType
)),
146 this, SLOT(clearStatusBar()));
147 connect(undoManager
, SIGNAL(jobRecordingFinished(CommandType
)),
148 this, SLOT(showCommand(CommandType
)));
149 connect(DolphinSettings::instance().placesModel(), SIGNAL(errorMessage(const QString
&)),
150 this, SLOT(showErrorMessage(const QString
&)));
151 connect(&DragAndDropHelper::instance(), SIGNAL(errorMessage(const QString
&)),
152 this, SLOT(showErrorMessage(const QString
&)));
155 DolphinMainWindow::~DolphinMainWindow()
157 DolphinApplication::app()->removeMainWindow(this);
160 void DolphinMainWindow::openDirectories(const QList
<KUrl
>& dirs
)
162 if (dirs
.isEmpty()) {
166 if (dirs
.count() == 1) {
167 m_activeViewContainer
->setUrl(dirs
.first());
171 const int oldOpenTabsCount
= m_viewTab
.count();
173 const GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
174 const bool hasSplitView
= generalSettings
->splitView();
176 // Open each directory inside a new tab. If the "split view" option has been enabled,
177 // always show two directories within one tab.
178 QList
<KUrl
>::const_iterator it
= dirs
.begin();
179 while (it
!= dirs
.end()) {
183 if (hasSplitView
&& (it
!= dirs
.end())) {
184 const int tabIndex
= m_viewTab
.count() - 1;
185 m_viewTab
[tabIndex
].secondaryView
->setUrl(*it
);
190 // remove the previously opened tabs
191 for (int i
= 0; i
< oldOpenTabsCount
; ++i
) {
196 void DolphinMainWindow::openFiles(const QList
<KUrl
>& files
)
198 if (files
.isEmpty()) {
202 // Get all distinct directories from 'files' and open a tab
203 // for each directory. If the "split view" option is enabled, two
204 // directories are shown inside one tab (see openDirectories()).
206 foreach (const KUrl
& url
, files
) {
207 const KUrl
dir(url
.directory());
208 if (!dirs
.contains(dir
)) {
213 openDirectories(dirs
);
215 // Select the files. Although the files can be split between several
216 // tabs, there is no need to split 'files' accordingly, as
217 // the DolphinView will just ignore invalid selections.
218 const int tabCount
= m_viewTab
.count();
219 for (int i
= 0; i
< tabCount
; ++i
) {
220 m_viewTab
[i
].primaryView
->view()->markUrlsAsSelected(files
);
221 if (m_viewTab
[i
].secondaryView
) {
222 m_viewTab
[i
].secondaryView
->view()->markUrlsAsSelected(files
);
227 void DolphinMainWindow::showCommand(CommandType command
)
229 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
231 case KIO::FileUndoManager::Copy
:
232 statusBar
->setMessage(i18nc("@info:status", "Successfully copied."),
233 DolphinStatusBar::OperationCompleted
);
235 case KIO::FileUndoManager::Move
:
236 statusBar
->setMessage(i18nc("@info:status", "Successfully moved."),
237 DolphinStatusBar::OperationCompleted
);
239 case KIO::FileUndoManager::Link
:
240 statusBar
->setMessage(i18nc("@info:status", "Successfully linked."),
241 DolphinStatusBar::OperationCompleted
);
243 case KIO::FileUndoManager::Trash
:
244 statusBar
->setMessage(i18nc("@info:status", "Successfully moved to trash."),
245 DolphinStatusBar::OperationCompleted
);
247 case KIO::FileUndoManager::Rename
:
248 statusBar
->setMessage(i18nc("@info:status", "Successfully renamed."),
249 DolphinStatusBar::OperationCompleted
);
252 case KIO::FileUndoManager::Mkdir
:
253 statusBar
->setMessage(i18nc("@info:status", "Created folder."),
254 DolphinStatusBar::OperationCompleted
);
262 void DolphinMainWindow::refreshViews()
264 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
266 // remember the current active view, as because of
267 // the refreshing the active view might change to
268 // the secondary view
269 DolphinViewContainer
* activeViewContainer
= m_activeViewContainer
;
271 const int tabCount
= m_viewTab
.count();
272 for (int i
= 0; i
< tabCount
; ++i
) {
273 m_viewTab
[i
].primaryView
->refresh();
274 if (m_viewTab
[i
].secondaryView
) {
275 m_viewTab
[i
].secondaryView
->refresh();
279 setActiveViewContainer(activeViewContainer
);
281 const GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
282 if (generalSettings
->modifiedStartupSettings()) {
283 // The startup settings have been changed by the user (see bug #254947).
284 // Synchronize the split-view setting with the active view:
285 const bool splitView
= generalSettings
->splitView();
286 const ViewTab
& activeTab
= m_viewTab
[m_tabIndex
];
287 const bool toggle
= ( splitView
&& !activeTab
.secondaryView
)
288 || (!splitView
&& activeTab
.secondaryView
);
295 void DolphinMainWindow::pasteIntoFolder()
297 m_activeViewContainer
->view()->pasteIntoFolder();
300 void DolphinMainWindow::changeUrl(const KUrl
& url
)
302 if (!KProtocolManager::supportsListing(url
)) {
303 // The URL navigator only checks for validity, not
304 // if the URL can be listed. An error message is
305 // shown due to DolphinViewContainer::restoreView().
309 DolphinViewContainer
* view
= activeViewContainer();
315 setUrlAsCaption(url
);
316 if (m_viewTab
.count() > 1) {
317 m_tabBar
->setTabText(m_tabIndex
, squeezedText(tabName(m_activeViewContainer
->url())));
319 const QString iconName
= KMimeType::iconNameForUrl(url
);
320 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(iconName
));
321 emit
urlChanged(url
);
325 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
327 KToggleAction
* editableLocationAction
=
328 static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
329 editableLocationAction
->setChecked(editable
);
332 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
336 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
337 int selectedUrlsCount
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedItemsCount();
338 if (m_viewTab
[m_tabIndex
].secondaryView
) {
339 selectedUrlsCount
+= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItemsCount();
342 QAction
* compareFilesAction
= actionCollection()->action("compare_files");
343 if (selectedUrlsCount
== 2) {
344 compareFilesAction
->setEnabled(isKompareInstalled());
346 compareFilesAction
->setEnabled(false);
349 emit
selectionChanged(selection
);
352 void DolphinMainWindow::slotRequestItemInfo(const KFileItem
& item
)
354 emit
requestItemInfo(item
);
357 void DolphinMainWindow::updateHistory()
359 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
360 const int index
= urlNavigator
->historyIndex();
362 QAction
* backAction
= actionCollection()->action("go_back");
363 backAction
->setToolTip(i18nc("@info", "Go back"));
365 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
368 QAction
* forwardAction
= actionCollection()->action("go_forward");
369 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
371 forwardAction
->setEnabled(index
> 0);
375 void DolphinMainWindow::updateFilterBarAction(bool show
)
377 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
378 showFilterBarAction
->setChecked(show
);
381 void DolphinMainWindow::openNewMainWindow()
383 DolphinApplication::app()->createMainWindow()->show();
386 void DolphinMainWindow::openNewTab()
388 const bool isUrlEditable
= m_activeViewContainer
->urlNavigator()->isUrlEditable();
390 openNewTab(m_activeViewContainer
->url());
391 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
393 // The URL navigator of the new tab should have the same editable state
394 // as the current tab
395 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
396 navigator
->setUrlEditable(isUrlEditable
);
399 // If a new tab is opened and the URL is editable, assure that
400 // the user can edit the URL without manually setting the focus
401 navigator
->setFocus();
405 void DolphinMainWindow::openNewTab(const KUrl
& url
)
407 QWidget
* focusWidget
= QApplication::focusWidget();
409 if (m_viewTab
.count() == 1) {
410 // Only one view is open currently and hence no tab is shown at
411 // all. Before creating a tab for 'url', provide a tab for the current URL.
412 const KUrl currentUrl
= m_activeViewContainer
->url();
413 m_tabBar
->addTab(KIcon(KMimeType::iconNameForUrl(currentUrl
)),
414 squeezedText(tabName(currentUrl
)));
415 m_tabBar
->blockSignals(false);
418 m_tabBar
->addTab(KIcon(KMimeType::iconNameForUrl(url
)),
419 squeezedText(tabName(url
)));
422 viewTab
.splitter
= new QSplitter(this);
423 viewTab
.splitter
->setChildrenCollapsible(false);
424 viewTab
.primaryView
= new DolphinViewContainer(url
, viewTab
.splitter
);
425 viewTab
.primaryView
->setActive(false);
426 connectViewSignals(viewTab
.primaryView
);
428 m_viewTab
.append(viewTab
);
430 actionCollection()->action("close_tab")->setEnabled(true);
432 // provide a split view, if the startup settings are set this way
433 const GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
434 if (generalSettings
->splitView()) {
435 const int tabIndex
= m_viewTab
.count() - 1;
436 createSecondaryView(tabIndex
);
437 m_viewTab
[tabIndex
].secondaryView
->setActive(true);
438 m_viewTab
[tabIndex
].isPrimaryViewActive
= false;
442 // The DolphinViewContainer grabbed the keyboard focus. As the tab is opened
443 // in background, assure that the previous focused widget gets the focus back.
444 focusWidget
->setFocus();
448 void DolphinMainWindow::activateNextTab()
450 if ((m_viewTab
.count() == 1) || (m_tabBar
->count() < 2)) {
454 const int tabIndex
= (m_tabBar
->currentIndex() + 1) % m_tabBar
->count();
455 m_tabBar
->setCurrentIndex(tabIndex
);
458 void DolphinMainWindow::activatePrevTab()
460 if ((m_viewTab
.count() == 1) || (m_tabBar
->count() < 2)) {
464 int tabIndex
= m_tabBar
->currentIndex() - 1;
465 if (tabIndex
== -1) {
466 tabIndex
= m_tabBar
->count() - 1;
468 m_tabBar
->setCurrentIndex(tabIndex
);
471 void DolphinMainWindow::openInNewTab()
473 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
474 if (list
.isEmpty()) {
475 openNewTab(m_activeViewContainer
->url());
476 } else if ((list
.count() == 1) && list
[0].isDir()) {
477 openNewTab(list
[0].url());
481 void DolphinMainWindow::openInNewWindow()
485 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
486 if (list
.isEmpty()) {
487 newWindowUrl
= m_activeViewContainer
->url();
488 } else if ((list
.count() == 1) && list
[0].isDir()) {
489 newWindowUrl
= list
[0].url();
492 if (!newWindowUrl
.isEmpty()) {
493 DolphinMainWindow
* window
= DolphinApplication::app()->createMainWindow();
494 window
->changeUrl(newWindowUrl
);
499 void DolphinMainWindow::toggleActiveView()
501 if (!m_viewTab
[m_tabIndex
].secondaryView
) {
502 // only one view is available
506 Q_ASSERT(m_activeViewContainer
);
507 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
509 DolphinViewContainer
* left
= m_viewTab
[m_tabIndex
].primaryView
;
510 DolphinViewContainer
* right
= m_viewTab
[m_tabIndex
].secondaryView
;
511 setActiveViewContainer(m_activeViewContainer
== right
? left
: right
);
514 void DolphinMainWindow::showEvent(QShowEvent
* event
)
516 KXmlGuiWindow::showEvent(event
);
517 if (!event
->spontaneous()) {
518 m_activeViewContainer
->view()->setFocus();
522 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
524 DolphinSettings
& settings
= DolphinSettings::instance();
525 GeneralSettings
* generalSettings
= settings
.generalSettings();
527 // Find out if Dolphin is closed directly by the user or
528 // by the session manager because the session is closed
529 bool closedByUser
= true;
530 DolphinApplication
*application
= qobject_cast
<DolphinApplication
*>(qApp
);
531 if (application
&& application
->sessionSaving()) {
532 closedByUser
= false;
535 if ((m_viewTab
.count() > 1) && generalSettings
->confirmClosingMultipleTabs() && closedByUser
) {
536 // Ask the user if he really wants to quit and close all tabs.
537 // Open a confirmation dialog with 3 buttons:
538 // KDialog::Yes -> Quit
539 // KDialog::No -> Close only the current tab
540 // KDialog::Cancel -> do nothing
541 KDialog
*dialog
= new KDialog(this, Qt::Dialog
);
542 dialog
->setCaption(i18nc("@title:window", "Confirmation"));
543 dialog
->setButtons(KDialog::Yes
| KDialog::No
| KDialog::Cancel
);
544 dialog
->setModal(true);
545 dialog
->setButtonGuiItem(KDialog::Yes
, KStandardGuiItem::quit());
546 dialog
->setButtonGuiItem(KDialog::No
, KGuiItem(i18n("C&lose Current Tab"), KIcon("tab-close")));
547 dialog
->setButtonGuiItem(KDialog::Cancel
, KStandardGuiItem::cancel());
548 dialog
->setDefaultButton(KDialog::Yes
);
550 bool doNotAskAgainCheckboxResult
= false;
552 const int result
= KMessageBox::createKMessageBox(dialog
,
553 QMessageBox::Warning
,
554 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
556 i18n("Do not ask again"),
557 &doNotAskAgainCheckboxResult
,
558 KMessageBox::Notify
);
560 if (doNotAskAgainCheckboxResult
) {
561 generalSettings
->setConfirmClosingMultipleTabs(false);
569 // Close only the current tab
577 generalSettings
->setFirstRun(false);
581 if (m_searchDockIsTemporaryVisible
) {
582 QDockWidget
* searchDock
= findChild
<QDockWidget
*>("searchDock");
586 m_searchDockIsTemporaryVisible
= false;
589 KXmlGuiWindow::closeEvent(event
);
592 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
594 const int tabCount
= m_viewTab
.count();
595 group
.writeEntry("Tab Count", tabCount
);
596 group
.writeEntry("Active Tab Index", m_tabBar
->currentIndex());
598 for (int i
= 0; i
< tabCount
; ++i
) {
599 const DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
600 group
.writeEntry(tabProperty("Primary URL", i
), cont
->url().url());
601 group
.writeEntry(tabProperty("Primary Editable", i
),
602 cont
->urlNavigator()->isUrlEditable());
604 cont
= m_viewTab
[i
].secondaryView
;
606 group
.writeEntry(tabProperty("Secondary URL", i
), cont
->url().url());
607 group
.writeEntry(tabProperty("Secondary Editable", i
),
608 cont
->urlNavigator()->isUrlEditable());
613 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
615 const int tabCount
= group
.readEntry("Tab Count", 1);
616 for (int i
= 0; i
< tabCount
; ++i
) {
617 DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
619 cont
->setUrl(group
.readEntry(tabProperty("Primary URL", i
)));
620 const bool editable
= group
.readEntry(tabProperty("Primary Editable", i
), false);
621 cont
->urlNavigator()->setUrlEditable(editable
);
623 cont
= m_viewTab
[i
].secondaryView
;
624 const QString secondaryUrl
= group
.readEntry(tabProperty("Secondary URL", i
));
625 if (!secondaryUrl
.isEmpty()) {
627 // a secondary view should be shown, but no one is available
628 // currently -> create a new view
630 cont
= m_viewTab
[i
].secondaryView
;
634 cont
->setUrl(secondaryUrl
);
635 const bool editable
= group
.readEntry(tabProperty("Secondary Editable", i
), false);
636 cont
->urlNavigator()->setUrlEditable(editable
);
638 // no secondary view should be shown, but the default setting shows
639 // one already -> close the view
643 // openNewTab() needs to be called only tabCount - 1 times
644 if (i
!= tabCount
- 1) {
649 const int index
= group
.readEntry("Active Tab Index", 0);
650 m_tabBar
->setCurrentIndex(index
);
653 void DolphinMainWindow::updateNewMenu()
655 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->showHiddenFiles());
656 m_newFileMenu
->checkUpToDate();
657 m_newFileMenu
->setPopupFiles(activeViewContainer()->url());
660 void DolphinMainWindow::createDirectory()
662 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->showHiddenFiles());
663 m_newFileMenu
->setPopupFiles(activeViewContainer()->url());
664 m_newFileMenu
->createDirectory();
667 void DolphinMainWindow::quit()
672 void DolphinMainWindow::showErrorMessage(const QString
& message
)
674 if (!message
.isEmpty()) {
675 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
676 statusBar
->setMessage(message
, DolphinStatusBar::Error
);
680 void DolphinMainWindow::slotUndoAvailable(bool available
)
682 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
684 undoAction
->setEnabled(available
);
688 void DolphinMainWindow::restoreClosedTab(QAction
* action
)
690 if (action
->data().toBool()) {
691 // clear all actions except the "Empty Recently Closed Tabs"
692 // action and the separator
693 QList
<QAction
*> actions
= m_recentTabsMenu
->menu()->actions();
694 const int count
= actions
.size();
695 for (int i
= 2; i
< count
; ++i
) {
696 m_recentTabsMenu
->menu()->removeAction(actions
.at(i
));
699 const ClosedTab closedTab
= action
->data().value
<ClosedTab
>();
700 openNewTab(closedTab
.primaryUrl
);
701 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
703 if (closedTab
.isSplit
) {
704 // create secondary view
706 m_viewTab
[m_tabIndex
].secondaryView
->setUrl(closedTab
.secondaryUrl
);
709 m_recentTabsMenu
->removeAction(action
);
712 if (m_recentTabsMenu
->menu()->actions().count() == 2) {
713 m_recentTabsMenu
->setEnabled(false);
717 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
719 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
721 undoAction
->setText(text
);
725 void DolphinMainWindow::undo()
728 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
729 KIO::FileUndoManager::self()->undo();
732 void DolphinMainWindow::cut()
734 m_activeViewContainer
->view()->cutSelectedItems();
737 void DolphinMainWindow::copy()
739 m_activeViewContainer
->view()->copySelectedItems();
742 void DolphinMainWindow::paste()
744 m_activeViewContainer
->view()->paste();
747 void DolphinMainWindow::find()
749 m_activeViewContainer
->setSearchModeEnabled(true);
752 void DolphinMainWindow::updatePasteAction()
754 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
755 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
756 pasteAction
->setEnabled(pasteInfo
.first
);
757 pasteAction
->setText(pasteInfo
.second
);
760 void DolphinMainWindow::selectAll()
764 // if the URL navigator is editable and focused, select the whole
765 // URL instead of all items of the view
767 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
768 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit(); // krazy:exclude=qclasses
769 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
770 lineEdit
->hasFocus();
772 lineEdit
->selectAll();
774 m_activeViewContainer
->view()->selectAll();
778 void DolphinMainWindow::invertSelection()
781 m_activeViewContainer
->view()->invertSelection();
784 void DolphinMainWindow::toggleSplitView()
786 if (!m_viewTab
[m_tabIndex
].secondaryView
) {
787 createSecondaryView(m_tabIndex
);
788 setActiveViewContainer(m_viewTab
[m_tabIndex
].secondaryView
);
789 } else if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
790 // remove secondary view
791 m_viewTab
[m_tabIndex
].secondaryView
->close();
792 m_viewTab
[m_tabIndex
].secondaryView
->deleteLater();
793 m_viewTab
[m_tabIndex
].secondaryView
= 0;
795 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
797 // The primary view is active and should be closed. Hence from a users point of view
798 // the content of the secondary view should be moved to the primary view.
799 // From an implementation point of view it is more efficient to close
800 // the primary view and exchange the internal pointers afterwards.
802 m_viewTab
[m_tabIndex
].primaryView
->close();
803 m_viewTab
[m_tabIndex
].primaryView
->deleteLater();
804 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
805 m_viewTab
[m_tabIndex
].secondaryView
= 0;
807 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
813 void DolphinMainWindow::reloadView()
816 m_activeViewContainer
->view()->reload();
819 void DolphinMainWindow::stopLoading()
821 m_activeViewContainer
->view()->stopLoading();
824 void DolphinMainWindow::enableStopAction()
826 actionCollection()->action("stop")->setEnabled(true);
829 void DolphinMainWindow::disableStopAction()
831 actionCollection()->action("stop")->setEnabled(false);
834 void DolphinMainWindow::showFilterBar()
836 m_activeViewContainer
->setFilterBarVisible(true);
839 void DolphinMainWindow::toggleEditLocation()
843 QAction
* action
= actionCollection()->action("editable_location");
844 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
845 urlNavigator
->setUrlEditable(action
->isChecked());
848 void DolphinMainWindow::replaceLocation()
850 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
851 navigator
->setUrlEditable(true);
852 navigator
->setFocus();
854 // select the whole text of the combo box editor
855 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit(); // krazy:exclude=qclasses
856 lineEdit
->selectAll();
859 void DolphinMainWindow::togglePanelLockState()
861 GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
863 const bool newLockState
= !generalSettings
->lockPanels();
864 foreach (QObject
* child
, children()) {
865 DolphinDockWidget
* dock
= qobject_cast
<DolphinDockWidget
*>(child
);
867 dock
->setLocked(newLockState
);
871 generalSettings
->setLockPanels(newLockState
);
874 void DolphinMainWindow::goBack()
878 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
879 urlNavigator
->goBack();
881 if (urlNavigator
->locationState().isEmpty()) {
882 // An empty location state indicates a redirection URL,
883 // which must be skipped too
884 urlNavigator
->goBack();
888 void DolphinMainWindow::goForward()
891 m_activeViewContainer
->urlNavigator()->goForward();
894 void DolphinMainWindow::goUp()
897 m_activeViewContainer
->urlNavigator()->goUp();
900 void DolphinMainWindow::goBack(Qt::MouseButtons buttons
)
902 // The default case (left button pressed) is handled in goBack().
903 if (buttons
== Qt::MidButton
) {
904 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
905 const int index
= urlNavigator
->historyIndex() + 1;
906 openNewTab(urlNavigator
->locationUrl(index
));
910 void DolphinMainWindow::goForward(Qt::MouseButtons buttons
)
912 // The default case (left button pressed) is handled in goForward().
913 if (buttons
== Qt::MidButton
) {
914 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
915 const int index
= urlNavigator
->historyIndex() - 1;
916 openNewTab(urlNavigator
->locationUrl(index
));
920 void DolphinMainWindow::goUp(Qt::MouseButtons buttons
)
922 // The default case (left button pressed) is handled in goUp().
923 if (buttons
== Qt::MidButton
) {
924 openNewTab(activeViewContainer()->url().upUrl());
928 void DolphinMainWindow::goHome()
931 m_activeViewContainer
->urlNavigator()->goHome();
934 void DolphinMainWindow::compareFiles()
936 // The method is only invoked if exactly 2 files have
937 // been selected. The selected files may be:
938 // - both in the primary view
939 // - both in the secondary view
940 // - one in the primary view and the other in the secondary
942 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
947 KFileItemList items
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedItems();
949 switch (items
.count()) {
951 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
);
952 items
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItems();
953 Q_ASSERT(items
.count() == 2);
954 urlA
= items
[0].url();
955 urlB
= items
[1].url();
960 urlA
= items
[0].url();
961 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
);
962 items
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItems();
963 Q_ASSERT(items
.count() == 1);
964 urlB
= items
[0].url();
969 urlA
= items
[0].url();
970 urlB
= items
[1].url();
975 // may not happen: compareFiles may only get invoked if 2
976 // files are selected
981 QString
command("kompare -c \"");
982 command
.append(urlA
.pathOrUrl());
983 command
.append("\" \"");
984 command
.append(urlB
.pathOrUrl());
985 command
.append('\"');
986 KRun::runCommand(command
, "Kompare", "kompare", this);
989 void DolphinMainWindow::toggleShowMenuBar()
991 const bool visible
= menuBar()->isVisible();
992 menuBar()->setVisible(!visible
);
995 void DolphinMainWindow::openTerminal()
997 QString
dir(QDir::homePath());
999 // If the given directory is not local, it can still be the URL of an
1000 // ioslave using UDS_LOCAL_PATH which to be converted first.
1001 KUrl url
= KIO::NetAccess::mostLocalUrl(m_activeViewContainer
->url(), this);
1003 //If the URL is local after the above conversion, set the directory.
1004 if (url
.isLocalFile()) {
1005 dir
= url
.toLocalFile();
1008 KToolInvocation::invokeTerminal(QString(), dir
);
1011 void DolphinMainWindow::editSettings()
1013 if (!m_settingsDialog
) {
1014 const KUrl url
= activeViewContainer()->url();
1015 m_settingsDialog
= new DolphinSettingsDialog(url
, this);
1016 m_settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1017 m_settingsDialog
->show();
1019 m_settingsDialog
->raise();
1023 void DolphinMainWindow::setActiveTab(int index
)
1025 Q_ASSERT(index
>= 0);
1026 Q_ASSERT(index
< m_viewTab
.count());
1027 if (index
== m_tabIndex
) {
1031 // hide current tab content
1032 ViewTab
& hiddenTab
= m_viewTab
[m_tabIndex
];
1033 hiddenTab
.isPrimaryViewActive
= hiddenTab
.primaryView
->isActive();
1034 hiddenTab
.primaryView
->setActive(false);
1035 if (hiddenTab
.secondaryView
) {
1036 hiddenTab
.secondaryView
->setActive(false);
1038 QSplitter
* splitter
= m_viewTab
[m_tabIndex
].splitter
;
1040 m_centralWidgetLayout
->removeWidget(splitter
);
1042 // show active tab content
1045 ViewTab
& viewTab
= m_viewTab
[index
];
1046 m_centralWidgetLayout
->addWidget(viewTab
.splitter
, 1);
1047 viewTab
.primaryView
->show();
1048 if (viewTab
.secondaryView
) {
1049 viewTab
.secondaryView
->show();
1051 viewTab
.splitter
->show();
1053 setActiveViewContainer(viewTab
.isPrimaryViewActive
? viewTab
.primaryView
:
1054 viewTab
.secondaryView
);
1057 void DolphinMainWindow::closeTab()
1059 closeTab(m_tabBar
->currentIndex());
1062 void DolphinMainWindow::closeTab(int index
)
1064 Q_ASSERT(index
>= 0);
1065 Q_ASSERT(index
< m_viewTab
.count());
1066 if (m_viewTab
.count() == 1) {
1067 // the last tab may never get closed
1071 if (index
== m_tabIndex
) {
1072 // The tab that should be closed is the active tab. Activate the
1073 // previous tab before closing the tab.
1074 m_tabBar
->setCurrentIndex((index
> 0) ? index
- 1 : 1);
1076 rememberClosedTab(index
);
1079 m_viewTab
[index
].primaryView
->deleteLater();
1080 if (m_viewTab
[index
].secondaryView
) {
1081 m_viewTab
[index
].secondaryView
->deleteLater();
1083 m_viewTab
[index
].splitter
->deleteLater();
1084 m_viewTab
.erase(m_viewTab
.begin() + index
);
1086 m_tabBar
->blockSignals(true);
1087 m_tabBar
->removeTab(index
);
1089 if (m_tabIndex
> index
) {
1091 Q_ASSERT(m_tabIndex
>= 0);
1094 // if only one tab is left, also remove the tab entry so that
1095 // closing the last tab is not possible
1096 if (m_viewTab
.count() == 1) {
1097 m_tabBar
->removeTab(0);
1098 actionCollection()->action("close_tab")->setEnabled(false);
1100 m_tabBar
->blockSignals(false);
1104 void DolphinMainWindow::openTabContextMenu(int index
, const QPoint
& pos
)
1108 QAction
* newTabAction
= menu
.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab"));
1109 newTabAction
->setShortcut(actionCollection()->action("new_tab")->shortcut());
1111 QAction
* detachTabAction
= menu
.addAction(KIcon("tab-detach"), i18nc("@action:inmenu", "Detach Tab"));
1113 QAction
* closeOtherTabsAction
= menu
.addAction(KIcon("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs"));
1115 QAction
* closeTabAction
= menu
.addAction(KIcon("tab-close"), i18nc("@action:inmenu", "Close Tab"));
1116 closeTabAction
->setShortcut(actionCollection()->action("close_tab")->shortcut());
1117 QAction
* selectedAction
= menu
.exec(pos
);
1118 if (selectedAction
== newTabAction
) {
1119 const ViewTab
& tab
= m_viewTab
[index
];
1120 Q_ASSERT(tab
.primaryView
);
1121 const KUrl url
= tab
.secondaryView
&& tab
.secondaryView
->isActive() ?
1122 tab
.secondaryView
->url() : tab
.primaryView
->url();
1124 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
1125 } else if (selectedAction
== detachTabAction
) {
1126 const ViewTab
& tab
= m_viewTab
[index
];
1127 Q_ASSERT(tab
.primaryView
);
1128 const KUrl primaryUrl
= tab
.primaryView
->url();
1129 DolphinMainWindow
* window
= DolphinApplication::app()->createMainWindow();
1130 window
->changeUrl(primaryUrl
);
1132 if (tab
.secondaryView
) {
1133 const KUrl secondaryUrl
= tab
.secondaryView
->url();
1134 if (!window
->m_viewTab
[0].secondaryView
) {
1135 window
->toggleSplitView();
1137 window
->m_viewTab
[0].secondaryView
->setUrl(secondaryUrl
);
1138 if (tab
.primaryView
->isActive()) {
1139 window
->m_viewTab
[0].primaryView
->setActive(true);
1141 window
->m_viewTab
[0].secondaryView
->setActive(true);
1146 } else if (selectedAction
== closeOtherTabsAction
) {
1147 const int count
= m_tabBar
->count();
1148 for (int i
= 0; i
< index
; ++i
) {
1151 for (int i
= index
+ 1; i
< count
; ++i
) {
1154 } else if (selectedAction
== closeTabAction
) {
1159 void DolphinMainWindow::slotTabMoved(int from
, int to
)
1161 m_viewTab
.move(from
, to
);
1162 m_tabIndex
= m_tabBar
->currentIndex();
1165 void DolphinMainWindow::handlePlacesClick(const KUrl
& url
, Qt::MouseButtons buttons
)
1167 if (buttons
& Qt::MidButton
) {
1169 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
1175 void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent
* event
, bool& canDecode
)
1177 canDecode
= KUrl::List::canDecode(event
->mimeData());
1180 void DolphinMainWindow::handleUrl(const KUrl
& url
)
1182 delete m_lastHandleUrlStatJob
;
1183 m_lastHandleUrlStatJob
= 0;
1185 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1186 activeViewContainer()->setUrl(url
);
1187 } else if (KProtocolManager::supportsListing(url
)) {
1188 // stat the URL to see if it is a dir or not
1189 m_lastHandleUrlStatJob
= KIO::stat(url
, KIO::HideProgressInfo
);
1190 connect(m_lastHandleUrlStatJob
, SIGNAL(result(KJob
*)),
1191 this, SLOT(slotHandleUrlStatFinished(KJob
*)));
1194 new KRun(url
, this);
1198 void DolphinMainWindow::slotHandleUrlStatFinished(KJob
* job
)
1200 m_lastHandleUrlStatJob
= 0;
1201 const KIO::UDSEntry entry
= static_cast<KIO::StatJob
*>(job
)->statResult();
1202 const KUrl url
= static_cast<KIO::StatJob
*>(job
)->url();
1203 if (entry
.isDir()) {
1204 activeViewContainer()->setUrl(url
);
1206 new KRun(url
, this);
1210 void DolphinMainWindow::tabDropEvent(int tab
, QDropEvent
* event
)
1212 const KUrl::List urls
= KUrl::List::fromMimeData(event
->mimeData());
1213 if (!urls
.isEmpty() && tab
!= -1) {
1214 const ViewTab
& viewTab
= m_viewTab
[tab
];
1215 const KUrl destPath
= viewTab
.isPrimaryViewActive
? viewTab
.primaryView
->url() : viewTab
.secondaryView
->url();
1216 DragAndDropHelper::instance().dropUrls(KFileItem(), destPath
, event
, m_tabBar
);
1220 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1222 newFileMenu()->setEnabled(isFolderWritable
);
1225 void DolphinMainWindow::slotSearchModeChanged(bool enabled
)
1228 const KUrl url
= m_activeViewContainer
->url();
1229 const DolphinSearchInformation
& searchInfo
= DolphinSearchInformation::instance();
1230 if (!searchInfo
.isIndexingEnabled() || !searchInfo
.isPathIndexed(url
)) {
1234 QDockWidget
* searchDock
= findChild
<QDockWidget
*>("searchDock");
1240 if (!searchDock
->isVisible()) {
1241 m_searchDockIsTemporaryVisible
= true;
1245 if (searchDock
->isVisible() && m_searchDockIsTemporaryVisible
) {
1248 m_searchDockIsTemporaryVisible
= false;
1255 void DolphinMainWindow::openContextMenu(const KFileItem
& item
,
1257 const QList
<QAction
*>& customActions
)
1259 QPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, item
, url
);
1260 contextMenu
->setCustomActions(customActions
);
1261 const DolphinContextMenu::Command command
= contextMenu
->open();
1264 case DolphinContextMenu::OpenParentFolderInNewWindow
: {
1265 DolphinMainWindow
* window
= DolphinApplication::app()->createMainWindow();
1266 window
->changeUrl(item
.url().upUrl());
1271 case DolphinContextMenu::OpenParentFolderInNewTab
:
1272 openNewTab(item
.url().upUrl());
1275 case DolphinContextMenu::None
:
1283 void DolphinMainWindow::init()
1285 DolphinSettings
& settings
= DolphinSettings::instance();
1287 // Check whether Dolphin runs the first time. If yes then
1288 // a proper default window size is given at the end of DolphinMainWindow::init().
1289 GeneralSettings
* generalSettings
= settings
.generalSettings();
1290 const bool firstRun
= generalSettings
->firstRun();
1292 generalSettings
->setViewPropsTimestamp(QDateTime::currentDateTime());
1295 setAcceptDrops(true);
1297 m_viewTab
[m_tabIndex
].splitter
= new QSplitter(this);
1298 m_viewTab
[m_tabIndex
].splitter
->setChildrenCollapsible(false);
1302 const KUrl
homeUrl(generalSettings
->homeUrl());
1303 setUrlAsCaption(homeUrl
);
1304 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
1305 connect(m_actionHandler
, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
1306 connect(m_actionHandler
, SIGNAL(createDirectory()), SLOT(createDirectory()));
1307 ViewProperties
props(homeUrl
);
1308 m_viewTab
[m_tabIndex
].primaryView
= new DolphinViewContainer(homeUrl
,
1309 m_viewTab
[m_tabIndex
].splitter
);
1311 m_activeViewContainer
= m_viewTab
[m_tabIndex
].primaryView
;
1312 connectViewSignals(m_activeViewContainer
);
1313 DolphinView
* view
= m_activeViewContainer
->view();
1314 m_activeViewContainer
->show();
1315 m_actionHandler
->setCurrentView(view
);
1317 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
1318 connect(this, SIGNAL(urlChanged(const KUrl
&)),
1319 m_remoteEncoding
, SLOT(slotAboutToOpenUrl()));
1321 m_tabBar
= new KTabBar(this);
1322 m_tabBar
->setMovable(true);
1323 m_tabBar
->setTabsClosable(true);
1324 connect(m_tabBar
, SIGNAL(currentChanged(int)),
1325 this, SLOT(setActiveTab(int)));
1326 connect(m_tabBar
, SIGNAL(tabCloseRequested(int)),
1327 this, SLOT(closeTab(int)));
1328 connect(m_tabBar
, SIGNAL(contextMenu(int, const QPoint
&)),
1329 this, SLOT(openTabContextMenu(int, const QPoint
&)));
1330 connect(m_tabBar
, SIGNAL(newTabRequest()),
1331 this, SLOT(openNewTab()));
1332 connect(m_tabBar
, SIGNAL(testCanDecode(const QDragMoveEvent
*, bool&)),
1333 this, SLOT(slotTestCanDecode(const QDragMoveEvent
*, bool&)));
1334 connect(m_tabBar
, SIGNAL(mouseMiddleClick(int)),
1335 this, SLOT(closeTab(int)));
1336 connect(m_tabBar
, SIGNAL(tabMoved(int, int)),
1337 this, SLOT(slotTabMoved(int, int)));
1338 connect(m_tabBar
, SIGNAL(receivedDropEvent(int, QDropEvent
*)),
1339 this, SLOT(tabDropEvent(int, QDropEvent
*)));
1341 m_tabBar
->blockSignals(true); // signals get unblocked after at least 2 tabs are open
1343 QWidget
* centralWidget
= new QWidget(this);
1344 m_centralWidgetLayout
= new QVBoxLayout(centralWidget
);
1345 m_centralWidgetLayout
->setSpacing(0);
1346 m_centralWidgetLayout
->setMargin(0);
1347 m_centralWidgetLayout
->addWidget(m_tabBar
);
1348 m_centralWidgetLayout
->addWidget(m_viewTab
[m_tabIndex
].splitter
, 1);
1350 setCentralWidget(centralWidget
);
1352 emit
urlChanged(homeUrl
);
1354 setupGUI(Keys
| Save
| Create
| ToolBar
);
1355 stateChanged("new_file");
1357 QClipboard
* clipboard
= QApplication::clipboard();
1358 connect(clipboard
, SIGNAL(dataChanged()),
1359 this, SLOT(updatePasteAction()));
1361 if (generalSettings
->splitView()) {
1364 updateEditActions();
1365 updateViewActions();
1368 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1369 showFilterBarAction
->setChecked(generalSettings
->filterBar());
1372 // assure a proper default size if Dolphin runs the first time
1376 m_showMenuBar
->setChecked(!menuBar()->isHidden()); // workaround for bug #171080
1379 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer
* viewContainer
)
1381 Q_ASSERT(viewContainer
);
1382 Q_ASSERT((viewContainer
== m_viewTab
[m_tabIndex
].primaryView
) ||
1383 (viewContainer
== m_viewTab
[m_tabIndex
].secondaryView
));
1384 if (m_activeViewContainer
== viewContainer
) {
1388 m_activeViewContainer
->setActive(false);
1389 m_activeViewContainer
= viewContainer
;
1391 // Activating the view container might trigger a recursive setActiveViewContainer() call
1392 // inside DolphinMainWindow::toggleActiveView() when having a split view. Temporary
1393 // disconnect the activated() signal in this case:
1394 disconnect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1395 m_activeViewContainer
->setActive(true);
1396 connect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1398 m_actionHandler
->setCurrentView(viewContainer
->view());
1401 updateEditActions();
1402 updateViewActions();
1405 const KUrl url
= m_activeViewContainer
->url();
1406 setUrlAsCaption(url
);
1407 if (m_viewTab
.count() > 1) {
1408 m_tabBar
->setTabText(m_tabIndex
, tabName(url
));
1409 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(KMimeType::iconNameForUrl(url
)));
1412 emit
urlChanged(url
);
1415 void DolphinMainWindow::setupActions()
1417 // setup 'File' menu
1418 m_newFileMenu
= new DolphinNewFileMenu(this);
1419 KMenu
* menu
= m_newFileMenu
->menu();
1420 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1421 menu
->setIcon(KIcon("document-new"));
1422 connect(menu
, SIGNAL(aboutToShow()),
1423 this, SLOT(updateNewMenu()));
1425 KAction
* newWindow
= actionCollection()->addAction("new_window");
1426 newWindow
->setIcon(KIcon("window-new"));
1427 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1428 newWindow
->setShortcut(Qt::CTRL
| Qt::Key_N
);
1429 connect(newWindow
, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1431 KAction
* newTab
= actionCollection()->addAction("new_tab");
1432 newTab
->setIcon(KIcon("tab-new"));
1433 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1434 newTab
->setShortcut(KShortcut(Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
));
1435 connect(newTab
, SIGNAL(triggered()), this, SLOT(openNewTab()));
1437 KAction
* closeTab
= actionCollection()->addAction("close_tab");
1438 closeTab
->setIcon(KIcon("tab-close"));
1439 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1440 closeTab
->setShortcut(Qt::CTRL
| Qt::Key_W
);
1441 closeTab
->setEnabled(false);
1442 connect(closeTab
, SIGNAL(triggered()), this, SLOT(closeTab()));
1444 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1446 // setup 'Edit' menu
1447 KStandardAction::undo(this,
1449 actionCollection());
1451 // need to remove shift+del from cut action, else the shortcut for deletejob
1453 KAction
* cut
= KStandardAction::cut(this, SLOT(cut()), actionCollection());
1454 KShortcut cutShortcut
= cut
->shortcut();
1455 cutShortcut
.remove(Qt::SHIFT
| Qt::Key_Delete
, KShortcut::KeepEmpty
);
1456 cut
->setShortcut(cutShortcut
);
1457 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1458 KAction
* paste
= KStandardAction::paste(this, SLOT(paste()), actionCollection());
1459 // The text of the paste-action is modified dynamically by Dolphin
1460 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1461 // due to the long text, the text "Paste" is used:
1462 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1464 KStandardAction::find(this, SLOT(find()), actionCollection());
1466 KAction
* selectAll
= actionCollection()->addAction("select_all");
1467 selectAll
->setText(i18nc("@action:inmenu Edit", "Select All"));
1468 selectAll
->setShortcut(Qt::CTRL
| Qt::Key_A
);
1469 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
1471 KAction
* invertSelection
= actionCollection()->addAction("invert_selection");
1472 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1473 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1474 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
1476 // setup 'View' menu
1477 // (note that most of it is set up in DolphinViewActionHandler)
1479 KAction
* split
= actionCollection()->addAction("split_view");
1480 split
->setShortcut(Qt::Key_F3
);
1481 updateSplitAction();
1482 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1484 KAction
* reload
= actionCollection()->addAction("reload");
1485 reload
->setText(i18nc("@action:inmenu View", "Reload"));
1486 reload
->setShortcut(Qt::Key_F5
);
1487 reload
->setIcon(KIcon("view-refresh"));
1488 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
1490 KAction
* stop
= actionCollection()->addAction("stop");
1491 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1492 stop
->setToolTip(i18nc("@info", "Stop loading"));
1493 stop
->setIcon(KIcon("process-stop"));
1494 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
1496 KToggleAction
* showFullLocation
= actionCollection()->add
<KToggleAction
>("editable_location");
1497 showFullLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1498 showFullLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
1499 connect(showFullLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1501 KAction
* replaceLocation
= actionCollection()->addAction("replace_location");
1502 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1503 replaceLocation
->setShortcut(Qt::Key_F6
);
1504 connect(replaceLocation
, SIGNAL(triggered()), this, SLOT(replaceLocation()));
1507 KAction
* backAction
= KStandardAction::back(this, SLOT(goBack()), actionCollection());
1508 connect(backAction
, SIGNAL(triggered(Qt::MouseButtons
, Qt::KeyboardModifiers
)), this, SLOT(goBack(Qt::MouseButtons
)));
1509 KShortcut backShortcut
= backAction
->shortcut();
1510 backShortcut
.setAlternate(Qt::Key_Backspace
);
1511 backAction
->setShortcut(backShortcut
);
1513 m_recentTabsMenu
= new KActionMenu(i18n("Recently Closed Tabs"), this);
1514 m_recentTabsMenu
->setIcon(KIcon("edit-undo"));
1515 actionCollection()->addAction("closed_tabs", m_recentTabsMenu
);
1516 connect(m_recentTabsMenu
->menu(), SIGNAL(triggered(QAction
*)),
1517 this, SLOT(restoreClosedTab(QAction
*)));
1519 QAction
* action
= new QAction("Empty Recently Closed Tabs", m_recentTabsMenu
);
1520 action
->setIcon(KIcon("edit-clear-list"));
1521 action
->setData(QVariant::fromValue(true));
1522 m_recentTabsMenu
->addAction(action
);
1523 m_recentTabsMenu
->addSeparator();
1524 m_recentTabsMenu
->setEnabled(false);
1526 KAction
* forwardAction
= KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1527 connect(forwardAction
, SIGNAL(triggered(Qt::MouseButtons
, Qt::KeyboardModifiers
)), this, SLOT(goForward(Qt::MouseButtons
)));
1529 KAction
* upAction
= KStandardAction::up(this, SLOT(goUp()), actionCollection());
1530 connect(upAction
, SIGNAL(triggered(Qt::MouseButtons
, Qt::KeyboardModifiers
)), this, SLOT(goUp(Qt::MouseButtons
)));
1532 KStandardAction::home(this, SLOT(goHome()), actionCollection());
1534 // setup 'Tools' menu
1535 KAction
* showFilterBar
= actionCollection()->addAction("show_filter_bar");
1536 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1537 showFilterBar
->setIcon(KIcon("view-filter"));
1538 showFilterBar
->setShortcut(Qt::CTRL
| Qt::Key_I
);
1539 connect(showFilterBar
, SIGNAL(triggered()), this, SLOT(showFilterBar()));
1541 KAction
* compareFiles
= actionCollection()->addAction("compare_files");
1542 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1543 compareFiles
->setIcon(KIcon("kompare"));
1544 compareFiles
->setEnabled(false);
1545 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
1547 KAction
* openTerminal
= actionCollection()->addAction("open_terminal");
1548 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1549 openTerminal
->setIcon(KIcon("utilities-terminal"));
1550 openTerminal
->setShortcut(Qt::SHIFT
| Qt::Key_F4
);
1551 connect(openTerminal
, SIGNAL(triggered()), this, SLOT(openTerminal()));
1553 // setup 'Settings' menu
1554 m_showMenuBar
= KStandardAction::showMenubar(this, SLOT(toggleShowMenuBar()), actionCollection());
1555 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1557 // not in menu actions
1558 QList
<QKeySequence
> nextTabKeys
;
1559 nextTabKeys
.append(KStandardShortcut::tabNext().primary());
1560 nextTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::Key_Tab
));
1562 QList
<QKeySequence
> prevTabKeys
;
1563 prevTabKeys
.append(KStandardShortcut::tabPrev().primary());
1564 prevTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::SHIFT
| Qt::Key_Tab
));
1566 KAction
* activateNextTab
= actionCollection()->addAction("activate_next_tab");
1567 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1568 connect(activateNextTab
, SIGNAL(triggered()), SLOT(activateNextTab()));
1569 activateNextTab
->setShortcuts(QApplication::isRightToLeft() ? prevTabKeys
: nextTabKeys
);
1571 KAction
* activatePrevTab
= actionCollection()->addAction("activate_prev_tab");
1572 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1573 connect(activatePrevTab
, SIGNAL(triggered()), SLOT(activatePrevTab()));
1574 activatePrevTab
->setShortcuts(QApplication::isRightToLeft() ? nextTabKeys
: prevTabKeys
);
1577 KAction
* openInNewTab
= actionCollection()->addAction("open_in_new_tab");
1578 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1579 openInNewTab
->setIcon(KIcon("tab-new"));
1580 connect(openInNewTab
, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1582 KAction
* openInNewWindow
= actionCollection()->addAction("open_in_new_window");
1583 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1584 openInNewWindow
->setIcon(KIcon("window-new"));
1585 connect(openInNewWindow
, SIGNAL(triggered()), this, SLOT(openInNewWindow()));
1588 void DolphinMainWindow::setupDockWidgets()
1590 const bool lock
= DolphinSettings::instance().generalSettings()->lockPanels();
1592 KDualAction
* lockLayoutAction
= actionCollection()->add
<KDualAction
>("lock_panels");
1593 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
1594 lockLayoutAction
->setActiveIcon(KIcon("object-unlocked"));
1595 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
1596 lockLayoutAction
->setInactiveIcon(KIcon("object-locked"));
1597 lockLayoutAction
->setActive(lock
);
1598 connect(lockLayoutAction
, SIGNAL(triggered()), this, SLOT(togglePanelLockState()));
1600 // Setup "Information"
1601 DolphinDockWidget
* infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
1602 infoDock
->setLocked(lock
);
1603 infoDock
->setObjectName("infoDock");
1604 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1605 Panel
* infoPanel
= new InformationPanel(infoDock
);
1606 infoPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1607 connect(infoPanel
, SIGNAL(urlActivated(KUrl
)), this, SLOT(handleUrl(KUrl
)));
1608 infoDock
->setWidget(infoPanel
);
1610 QAction
* infoAction
= infoDock
->toggleViewAction();
1611 infoAction
->setIcon(KIcon("dialog-information"));
1612 infoAction
->setShortcut(Qt::Key_F11
);
1613 addActionCloneToCollection(infoAction
, "show_information_panel");
1615 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1616 connect(this, SIGNAL(urlChanged(KUrl
)),
1617 infoPanel
, SLOT(setUrl(KUrl
)));
1618 connect(this, SIGNAL(selectionChanged(KFileItemList
)),
1619 infoPanel
, SLOT(setSelection(KFileItemList
)));
1620 connect(this, SIGNAL(requestItemInfo(KFileItem
)),
1621 infoPanel
, SLOT(requestDelayedItemInfo(KFileItem
)));
1624 DolphinDockWidget
* foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
1625 foldersDock
->setLocked(lock
);
1626 foldersDock
->setObjectName("foldersDock");
1627 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1628 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1629 foldersPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1630 foldersDock
->setWidget(foldersPanel
);
1632 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1633 foldersAction
->setShortcut(Qt::Key_F7
);
1634 foldersAction
->setIcon(KIcon("folder"));
1635 addActionCloneToCollection(foldersAction
, "show_folders_panel");
1637 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1638 connect(this, SIGNAL(urlChanged(KUrl
)),
1639 foldersPanel
, SLOT(setUrl(KUrl
)));
1640 connect(foldersPanel
, SIGNAL(changeUrl(KUrl
, Qt::MouseButtons
)),
1641 this, SLOT(handlePlacesClick(KUrl
, Qt::MouseButtons
)));
1645 DolphinDockWidget
* terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1646 terminalDock
->setLocked(lock
);
1647 terminalDock
->setObjectName("terminalDock");
1648 terminalDock
->setAllowedAreas(Qt::TopDockWidgetArea
| Qt::BottomDockWidgetArea
);
1649 Panel
* terminalPanel
= new TerminalPanel(terminalDock
);
1650 terminalPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1651 terminalDock
->setWidget(terminalPanel
);
1653 connect(terminalPanel
, SIGNAL(hideTerminalPanel()), terminalDock
, SLOT(hide()));
1655 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1656 terminalAction
->setShortcut(Qt::Key_F4
);
1657 terminalAction
->setIcon(KIcon("utilities-terminal"));
1658 addActionCloneToCollection(terminalAction
, "show_terminal_panel");
1660 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1661 connect(this, SIGNAL(urlChanged(KUrl
)),
1662 terminalPanel
, SLOT(setUrl(KUrl
)));
1667 DolphinDockWidget
* searchDock
= new DolphinDockWidget(i18nc("@title:window", "Search"));
1668 searchDock
->setLocked(lock
);
1669 searchDock
->setObjectName("searchDock");
1670 searchDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1671 Panel
* searchPanel
= new SearchPanel(searchDock
);
1672 searchPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1673 connect(searchPanel
, SIGNAL(urlActivated(KUrl
)), this, SLOT(handleUrl(KUrl
)));
1674 searchDock
->setWidget(searchPanel
);
1676 QAction
* searchAction
= searchDock
->toggleViewAction();
1677 searchAction
->setShortcut(Qt::Key_F12
);
1678 searchAction
->setIcon(KIcon("system-search"));
1679 addActionCloneToCollection(searchAction
, "show_search_panel");
1680 addDockWidget(Qt::RightDockWidgetArea
, searchDock
);
1681 connect(this, SIGNAL(urlChanged(KUrl
)),
1682 searchPanel
, SLOT(setUrl(KUrl
)));
1685 const bool firstRun
= DolphinSettings::instance().generalSettings()->firstRun();
1688 foldersDock
->hide();
1690 terminalDock
->hide();
1698 DolphinDockWidget
* placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
1699 placesDock
->setLocked(lock
);
1700 placesDock
->setObjectName("placesDock");
1701 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1703 PlacesPanel
* placesPanel
= new PlacesPanel(placesDock
);
1704 QAction
* separator
= new QAction(placesPanel
);
1705 separator
->setSeparator(true);
1706 QList
<QAction
*> placesActions
;
1707 placesActions
.append(separator
);
1708 placesActions
.append(lockLayoutAction
);
1709 placesPanel
->addActions(placesActions
);
1710 placesPanel
->setModel(DolphinSettings::instance().placesModel());
1711 placesPanel
->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff
);
1712 placesDock
->setWidget(placesPanel
);
1714 QAction
* placesAction
= placesDock
->toggleViewAction();
1715 placesAction
->setShortcut(Qt::Key_F9
);
1716 placesAction
->setIcon(KIcon("bookmarks"));
1717 addActionCloneToCollection(placesAction
, "show_places_panel");
1719 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1720 connect(placesPanel
, SIGNAL(urlChanged(KUrl
, Qt::MouseButtons
)),
1721 this, SLOT(handlePlacesClick(KUrl
, Qt::MouseButtons
)));
1722 connect(this, SIGNAL(urlChanged(KUrl
)),
1723 placesPanel
, SLOT(setUrl(KUrl
)));
1725 // Add actions into the "Panels" menu
1726 KActionMenu
* panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Panels"), this);
1727 actionCollection()->addAction("panels", panelsMenu
);
1728 panelsMenu
->setDelayed(false);
1729 panelsMenu
->addAction(placesAction
);
1730 panelsMenu
->addAction(infoAction
);
1731 panelsMenu
->addAction(foldersAction
);
1733 panelsMenu
->addAction(terminalAction
);
1736 panelsMenu
->addAction(searchAction
);
1738 panelsMenu
->addSeparator();
1739 panelsMenu
->addAction(lockLayoutAction
);
1742 void DolphinMainWindow::updateEditActions()
1744 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1745 if (list
.isEmpty()) {
1746 stateChanged("has_no_selection");
1748 stateChanged("has_selection");
1750 KActionCollection
* col
= actionCollection();
1751 QAction
* renameAction
= col
->action("rename");
1752 QAction
* moveToTrashAction
= col
->action("move_to_trash");
1753 QAction
* deleteAction
= col
->action("delete");
1754 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
1755 QAction
* deleteWithTrashShortcut
= col
->action("delete_shortcut"); // see DolphinViewActionHandler
1757 KFileItemListProperties
capabilities(list
);
1758 const bool enableMoveToTrash
= capabilities
.isLocal() && capabilities
.supportsMoving();
1760 renameAction
->setEnabled(capabilities
.supportsMoving());
1761 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1762 deleteAction
->setEnabled(capabilities
.supportsDeleting());
1763 deleteWithTrashShortcut
->setEnabled(capabilities
.supportsDeleting() && !enableMoveToTrash
);
1764 cutAction
->setEnabled(capabilities
.supportsMoving());
1766 updatePasteAction();
1769 void DolphinMainWindow::updateViewActions()
1771 m_actionHandler
->updateViewActions();
1773 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1774 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
1776 updateSplitAction();
1778 QAction
* editableLocactionAction
= actionCollection()->action("editable_location");
1779 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
1780 editableLocactionAction
->setChecked(urlNavigator
->isUrlEditable());
1783 void DolphinMainWindow::updateGoActions()
1785 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
1786 const KUrl currentUrl
= m_activeViewContainer
->url();
1787 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
1790 void DolphinMainWindow::rememberClosedTab(int index
)
1792 KMenu
* tabsMenu
= m_recentTabsMenu
->menu();
1794 const QString primaryPath
= m_viewTab
[index
].primaryView
->url().path();
1795 const QString iconName
= KMimeType::iconNameForUrl(primaryPath
);
1797 QAction
* action
= new QAction(squeezedText(primaryPath
), tabsMenu
);
1799 ClosedTab closedTab
;
1800 closedTab
.primaryUrl
= m_viewTab
[index
].primaryView
->url();
1802 if (m_viewTab
[index
].secondaryView
) {
1803 closedTab
.secondaryUrl
= m_viewTab
[index
].secondaryView
->url();
1804 closedTab
.isSplit
= true;
1806 closedTab
.isSplit
= false;
1809 action
->setData(QVariant::fromValue(closedTab
));
1810 action
->setIcon(KIcon(iconName
));
1812 // add the closed tab menu entry after the separator and
1813 // "Empty Recently Closed Tabs" entry
1814 if (tabsMenu
->actions().size() == 2) {
1815 tabsMenu
->addAction(action
);
1817 tabsMenu
->insertAction(tabsMenu
->actions().at(2), action
);
1820 // assure that only up to 8 closed tabs are shown in the menu
1821 if (tabsMenu
->actions().size() > 8) {
1822 tabsMenu
->removeAction(tabsMenu
->actions().last());
1824 actionCollection()->action("closed_tabs")->setEnabled(true);
1825 KAcceleratorManager::manage(tabsMenu
);
1828 void DolphinMainWindow::clearStatusBar()
1830 m_activeViewContainer
->statusBar()->clear();
1833 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
1835 connect(container
, SIGNAL(showFilterBarChanged(bool)),
1836 this, SLOT(updateFilterBarAction(bool)));
1837 connect(container
, SIGNAL(writeStateChanged(bool)),
1838 this, SLOT(slotWriteStateChanged(bool)));
1839 connect(container
, SIGNAL(searchModeChanged(bool)),
1840 this, SLOT(slotSearchModeChanged(bool)));
1842 DolphinView
* view
= container
->view();
1843 connect(view
, SIGNAL(selectionChanged(KFileItemList
)),
1844 this, SLOT(slotSelectionChanged(KFileItemList
)));
1845 connect(view
, SIGNAL(requestItemInfo(KFileItem
)),
1846 this, SLOT(slotRequestItemInfo(KFileItem
)));
1847 connect(view
, SIGNAL(activated()),
1848 this, SLOT(toggleActiveView()));
1849 connect(view
, SIGNAL(tabRequested(const KUrl
&)),
1850 this, SLOT(openNewTab(const KUrl
&)));
1851 connect(view
, SIGNAL(requestContextMenu(KFileItem
, const KUrl
&, const QList
<QAction
*>&)),
1852 this, SLOT(openContextMenu(KFileItem
, const KUrl
&, const QList
<QAction
*>&)));
1853 connect(view
, SIGNAL(startedPathLoading(KUrl
)),
1854 this, SLOT(enableStopAction()));
1855 connect(view
, SIGNAL(finishedPathLoading(KUrl
)),
1856 this, SLOT(disableStopAction()));
1858 const KUrlNavigator
* navigator
= container
->urlNavigator();
1859 connect(navigator
, SIGNAL(urlChanged(const KUrl
&)),
1860 this, SLOT(changeUrl(const KUrl
&)));
1861 connect(navigator
, SIGNAL(historyChanged()),
1862 this, SLOT(updateHistory()));
1863 connect(navigator
, SIGNAL(editableStateChanged(bool)),
1864 this, SLOT(slotEditableStateChanged(bool)));
1865 connect(navigator
, SIGNAL(tabRequested(const KUrl
&)),
1866 this, SLOT(openNewTab(KUrl
)));
1869 void DolphinMainWindow::updateSplitAction()
1871 QAction
* splitAction
= actionCollection()->action("split_view");
1872 if (m_viewTab
[m_tabIndex
].secondaryView
) {
1873 if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
1874 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
1875 splitAction
->setToolTip(i18nc("@info", "Close right view"));
1876 splitAction
->setIcon(KIcon("view-right-close"));
1878 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
1879 splitAction
->setToolTip(i18nc("@info", "Close left view"));
1880 splitAction
->setIcon(KIcon("view-left-close"));
1883 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
1884 splitAction
->setToolTip(i18nc("@info", "Split view"));
1885 splitAction
->setIcon(KIcon("view-right-new"));
1889 QString
DolphinMainWindow::tabName(const KUrl
& url
) const
1892 if (url
.equals(KUrl("file:///"))) {
1895 name
= url
.fileName();
1896 if (name
.isEmpty()) {
1897 name
= url
.protocol();
1899 // Make sure that a '&' inside the directory name is displayed correctly
1900 // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
1901 name
.replace('&', "&&");
1907 bool DolphinMainWindow::isKompareInstalled() const
1909 static bool initialized
= false;
1910 static bool installed
= false;
1912 // TODO: maybe replace this approach later by using a menu
1913 // plugin like kdiff3plugin.cpp
1914 installed
= !KGlobal::dirs()->findExe("kompare").isEmpty();
1920 void DolphinMainWindow::createSecondaryView(int tabIndex
)
1922 QSplitter
* splitter
= m_viewTab
[tabIndex
].splitter
;
1923 const int newWidth
= (m_viewTab
[tabIndex
].primaryView
->width() - splitter
->handleWidth()) / 2;
1925 const DolphinView
* view
= m_viewTab
[tabIndex
].primaryView
->view();
1926 m_viewTab
[tabIndex
].secondaryView
= new DolphinViewContainer(view
->rootUrl(), 0);
1927 splitter
->addWidget(m_viewTab
[tabIndex
].secondaryView
);
1928 splitter
->setSizes(QList
<int>() << newWidth
<< newWidth
);
1929 connectViewSignals(m_viewTab
[tabIndex
].secondaryView
);
1930 m_viewTab
[tabIndex
].secondaryView
->setActive(false);
1931 m_viewTab
[tabIndex
].secondaryView
->show();
1934 QString
DolphinMainWindow::tabProperty(const QString
& property
, int tabIndex
) const
1936 return "Tab " + QString::number(tabIndex
) + ' ' + property
;
1939 void DolphinMainWindow::setUrlAsCaption(const KUrl
& url
)
1942 if (!url
.isLocalFile()) {
1943 caption
.append(url
.protocol() + " - ");
1944 if (url
.hasHost()) {
1945 caption
.append(url
.host() + " - ");
1949 const QString fileName
= url
.fileName().isEmpty() ? "/" : url
.fileName();
1950 caption
.append(fileName
);
1952 setCaption(caption
);
1955 QString
DolphinMainWindow::squeezedText(const QString
& text
) const
1957 const QFontMetrics fm
= fontMetrics();
1958 return fm
.elidedText(text
, Qt::ElideMiddle
, fm
.maxWidth() * 10);
1961 void DolphinMainWindow::addActionCloneToCollection(QAction
* action
, const QString
& actionName
)
1963 KAction
* actionClone
= actionCollection()->addAction(actionName
);
1964 actionClone
->setText(action
->text());
1965 actionClone
->setIcon(action
->icon());
1966 connect(actionClone
, SIGNAL(triggered()), action
, SLOT(trigger()));
1969 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
1970 KIO::FileUndoManager::UiInterface()
1974 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
1978 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
1980 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
1982 DolphinStatusBar
* statusBar
= mainWin
->activeViewContainer()->statusBar();
1983 statusBar
->setMessage(job
->errorString(), DolphinStatusBar::Error
);
1985 KIO::FileUndoManager::UiInterface::jobError(job
);
1989 #include "dolphinmainwindow.moc"