1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz19@gmail.com> *
3 * Copyright (C) 2006 by Stefan Monov <logixoul@gmail.com> *
4 * Copyright (C) 2006 by Cvetoslav Ludmiloff <ludmiloff@gmail.com> *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20 ***************************************************************************/
22 #include "dolphinmainwindow.h"
24 #include <config-nepomuk.h>
26 #include "dolphinapplication.h"
27 #include "dolphindockwidget.h"
28 #include "dolphincontextmenu.h"
29 #include "dolphinnewfilemenu.h"
30 #include "dolphinviewcontainer.h"
31 #include "mainwindowadaptor.h"
33 #include "panels/search/searchpanel.h"
34 #include <Nepomuk/ResourceManager>
36 #include "panels/folders/folderspanel.h"
37 #include "panels/places/placespanel.h"
38 #include "panels/information/informationpanel.h"
39 #include "search/dolphinsearchinformation.h"
40 #include "settings/dolphinsettings.h"
41 #include "settings/dolphinsettingsdialog.h"
42 #include "statusbar/dolphinstatusbar.h"
43 #include "views/dolphinviewactionhandler.h"
44 #include "views/dolphinremoteencoding.h"
45 #include "views/draganddrophelper.h"
46 #include "views/viewproperties.h"
49 #include "panels/terminal/terminalpanel.h"
52 #include "dolphin_generalsettings.h"
53 #include "dolphin_iconsmodesettings.h"
54 #include "dolphin_searchsettings.h"
57 #include <KActionCollection>
58 #include <KActionMenu>
60 #include <KDesktopFile>
61 #include <kdeversion.h>
62 #include <kdualaction.h>
63 #include <KFileDialog>
64 #include <KFilePlacesModel>
69 #include <KIconLoader>
70 #include <KIO/NetAccess>
71 #include <KInputDialog>
73 #include <KProtocolManager>
76 #include <KMessageBox>
77 #include <KFileItemListProperties>
78 #include <konqmimedata.h>
79 #include <KProtocolInfo>
82 #include <KStandardDirs>
83 #include <kstatusbar.h>
84 #include <KStandardAction>
86 #include <KToggleAction>
87 #include <KUrlNavigator>
89 #include <KUrlComboBox>
90 #include <KToolInvocation>
92 #include <QDBusMessage>
96 #include <kacceleratormanager.h>
99 * Remembers the tab configuration if a tab has been closed.
100 * Each closed tab can be restored by the menu
101 * "Go -> Recently Closed Tabs".
109 Q_DECLARE_METATYPE(ClosedTab
)
111 DolphinMainWindow::DolphinMainWindow(int id
) :
116 m_activeViewContainer(0),
117 m_centralWidgetLayout(0),
124 m_lastHandleUrlStatJob(0),
125 m_searchDockIsTemporaryVisible(false)
127 // Workaround for a X11-issue in combination with KModifierInfo
128 // (see DolphinContextMenu::initializeModifierKeyInfo() for
129 // more information):
130 DolphinContextMenu::initializeModifierKeyInfo();
132 setObjectName("Dolphin#");
134 m_viewTab
.append(ViewTab());
136 new MainWindowAdaptor(this);
137 QDBusConnection::sessionBus().registerObject(QString("/dolphin/MainWindow%1").arg(m_id
), this);
139 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
140 undoManager
->setUiInterface(new UndoUiInterface());
142 connect(undoManager
, SIGNAL(undoAvailable(bool)),
143 this, SLOT(slotUndoAvailable(bool)));
144 connect(undoManager
, SIGNAL(undoTextChanged(const QString
&)),
145 this, SLOT(slotUndoTextChanged(const QString
&)));
146 connect(undoManager
, SIGNAL(jobRecordingStarted(CommandType
)),
147 this, SLOT(clearStatusBar()));
148 connect(undoManager
, SIGNAL(jobRecordingFinished(CommandType
)),
149 this, SLOT(showCommand(CommandType
)));
150 connect(DolphinSettings::instance().placesModel(), SIGNAL(errorMessage(const QString
&)),
151 this, SLOT(showErrorMessage(const QString
&)));
152 connect(&DragAndDropHelper::instance(), SIGNAL(errorMessage(const QString
&)),
153 this, SLOT(showErrorMessage(const QString
&)));
156 DolphinMainWindow::~DolphinMainWindow()
158 DolphinApplication::app()->removeMainWindow(this);
161 void DolphinMainWindow::openDirectories(const QList
<KUrl
>& dirs
)
163 if (dirs
.isEmpty()) {
167 if (dirs
.count() == 1) {
168 m_activeViewContainer
->setUrl(dirs
.first());
172 const int oldOpenTabsCount
= m_viewTab
.count();
174 const GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
175 const bool hasSplitView
= generalSettings
->splitView();
177 // Open each directory inside a new tab. If the "split view" option has been enabled,
178 // always show two directories within one tab.
179 QList
<KUrl
>::const_iterator it
= dirs
.begin();
180 while (it
!= dirs
.end()) {
184 if (hasSplitView
&& (it
!= dirs
.end())) {
185 const int tabIndex
= m_viewTab
.count() - 1;
186 m_viewTab
[tabIndex
].secondaryView
->setUrl(*it
);
191 // remove the previously opened tabs
192 for (int i
= 0; i
< oldOpenTabsCount
; ++i
) {
197 void DolphinMainWindow::openFiles(const QList
<KUrl
>& files
)
199 if (files
.isEmpty()) {
203 // Get all distinct directories from 'files' and open a tab
204 // for each directory. If the "split view" option is enabled, two
205 // directories are shown inside one tab (see openDirectories()).
207 foreach (const KUrl
& url
, files
) {
208 const KUrl
dir(url
.directory());
209 if (!dirs
.contains(dir
)) {
214 openDirectories(dirs
);
216 // Select the files. Although the files can be split between several
217 // tabs, there is no need to split 'files' accordingly, as
218 // the DolphinView will just ignore invalid selections.
219 const int tabCount
= m_viewTab
.count();
220 for (int i
= 0; i
< tabCount
; ++i
) {
221 m_viewTab
[i
].primaryView
->view()->markUrlsAsSelected(files
);
222 if (m_viewTab
[i
].secondaryView
) {
223 m_viewTab
[i
].secondaryView
->view()->markUrlsAsSelected(files
);
228 void DolphinMainWindow::showCommand(CommandType command
)
230 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
232 case KIO::FileUndoManager::Copy
:
233 statusBar
->setMessage(i18nc("@info:status", "Successfully copied."),
234 DolphinStatusBar::OperationCompleted
);
236 case KIO::FileUndoManager::Move
:
237 statusBar
->setMessage(i18nc("@info:status", "Successfully moved."),
238 DolphinStatusBar::OperationCompleted
);
240 case KIO::FileUndoManager::Link
:
241 statusBar
->setMessage(i18nc("@info:status", "Successfully linked."),
242 DolphinStatusBar::OperationCompleted
);
244 case KIO::FileUndoManager::Trash
:
245 statusBar
->setMessage(i18nc("@info:status", "Successfully moved to trash."),
246 DolphinStatusBar::OperationCompleted
);
248 case KIO::FileUndoManager::Rename
:
249 statusBar
->setMessage(i18nc("@info:status", "Successfully renamed."),
250 DolphinStatusBar::OperationCompleted
);
253 case KIO::FileUndoManager::Mkdir
:
254 statusBar
->setMessage(i18nc("@info:status", "Created folder."),
255 DolphinStatusBar::OperationCompleted
);
263 void DolphinMainWindow::refreshViews()
265 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
267 // remember the current active view, as because of
268 // the refreshing the active view might change to
269 // the secondary view
270 DolphinViewContainer
* activeViewContainer
= m_activeViewContainer
;
272 const int tabCount
= m_viewTab
.count();
273 for (int i
= 0; i
< tabCount
; ++i
) {
274 m_viewTab
[i
].primaryView
->refresh();
275 if (m_viewTab
[i
].secondaryView
) {
276 m_viewTab
[i
].secondaryView
->refresh();
280 setActiveViewContainer(activeViewContainer
);
282 const GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
283 if (generalSettings
->modifiedStartupSettings()) {
284 // The startup settings have been changed by the user (see bug #254947).
285 // Synchronize the split-view setting with the active view:
286 const bool splitView
= generalSettings
->splitView();
287 const ViewTab
& activeTab
= m_viewTab
[m_tabIndex
];
288 const bool toggle
= ( splitView
&& !activeTab
.secondaryView
)
289 || (!splitView
&& activeTab
.secondaryView
);
296 void DolphinMainWindow::pasteIntoFolder()
298 m_activeViewContainer
->view()->pasteIntoFolder();
301 void DolphinMainWindow::changeUrl(const KUrl
& url
)
303 if (!KProtocolManager::supportsListing(url
)) {
304 // The URL navigator only checks for validity, not
305 // if the URL can be listed. An error message is
306 // shown due to DolphinViewContainer::restoreView().
310 DolphinViewContainer
* view
= activeViewContainer();
316 setUrlAsCaption(url
);
317 if (m_viewTab
.count() > 1) {
318 m_tabBar
->setTabText(m_tabIndex
, squeezedText(tabName(m_activeViewContainer
->url())));
320 const QString iconName
= KMimeType::iconNameForUrl(url
);
321 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(iconName
));
322 emit
urlChanged(url
);
326 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
328 KToggleAction
* editableLocationAction
=
329 static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
330 editableLocationAction
->setChecked(editable
);
333 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
337 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
338 int selectedUrlsCount
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedItemsCount();
339 if (m_viewTab
[m_tabIndex
].secondaryView
) {
340 selectedUrlsCount
+= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItemsCount();
343 QAction
* compareFilesAction
= actionCollection()->action("compare_files");
344 if (selectedUrlsCount
== 2) {
345 compareFilesAction
->setEnabled(isKompareInstalled());
347 compareFilesAction
->setEnabled(false);
350 emit
selectionChanged(selection
);
353 void DolphinMainWindow::slotRequestItemInfo(const KFileItem
& item
)
355 emit
requestItemInfo(item
);
358 void DolphinMainWindow::updateHistory()
360 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
361 const int index
= urlNavigator
->historyIndex();
363 QAction
* backAction
= actionCollection()->action("go_back");
364 backAction
->setToolTip(i18nc("@info", "Go back"));
366 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
369 QAction
* forwardAction
= actionCollection()->action("go_forward");
370 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
372 forwardAction
->setEnabled(index
> 0);
376 void DolphinMainWindow::updateFilterBarAction(bool show
)
378 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
379 showFilterBarAction
->setChecked(show
);
382 void DolphinMainWindow::openNewMainWindow()
384 DolphinApplication::app()->createMainWindow()->show();
387 void DolphinMainWindow::openNewTab()
389 const bool isUrlEditable
= m_activeViewContainer
->urlNavigator()->isUrlEditable();
391 openNewTab(m_activeViewContainer
->url());
392 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
394 // The URL navigator of the new tab should have the same editable state
395 // as the current tab
396 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
397 navigator
->setUrlEditable(isUrlEditable
);
400 // If a new tab is opened and the URL is editable, assure that
401 // the user can edit the URL without manually setting the focus
402 navigator
->setFocus();
406 void DolphinMainWindow::openNewTab(const KUrl
& url
)
408 QWidget
* focusWidget
= QApplication::focusWidget();
410 if (m_viewTab
.count() == 1) {
411 // Only one view is open currently and hence no tab is shown at
412 // all. Before creating a tab for 'url', provide a tab for the current URL.
413 const KUrl currentUrl
= m_activeViewContainer
->url();
414 m_tabBar
->addTab(KIcon(KMimeType::iconNameForUrl(currentUrl
)),
415 squeezedText(tabName(currentUrl
)));
416 m_tabBar
->blockSignals(false);
419 m_tabBar
->addTab(KIcon(KMimeType::iconNameForUrl(url
)),
420 squeezedText(tabName(url
)));
423 viewTab
.splitter
= new QSplitter(this);
424 viewTab
.splitter
->setChildrenCollapsible(false);
425 viewTab
.primaryView
= new DolphinViewContainer(url
, viewTab
.splitter
);
426 viewTab
.primaryView
->setActive(false);
427 connectViewSignals(viewTab
.primaryView
);
429 m_viewTab
.append(viewTab
);
431 actionCollection()->action("close_tab")->setEnabled(true);
433 // provide a split view, if the startup settings are set this way
434 const GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
435 if (generalSettings
->splitView()) {
436 const int tabIndex
= m_viewTab
.count() - 1;
437 createSecondaryView(tabIndex
);
438 m_viewTab
[tabIndex
].secondaryView
->setActive(true);
439 m_viewTab
[tabIndex
].isPrimaryViewActive
= false;
443 // The DolphinViewContainer grabbed the keyboard focus. As the tab is opened
444 // in background, assure that the previous focused widget gets the focus back.
445 focusWidget
->setFocus();
449 void DolphinMainWindow::activateNextTab()
451 if ((m_viewTab
.count() == 1) || (m_tabBar
->count() < 2)) {
455 const int tabIndex
= (m_tabBar
->currentIndex() + 1) % m_tabBar
->count();
456 m_tabBar
->setCurrentIndex(tabIndex
);
459 void DolphinMainWindow::activatePrevTab()
461 if ((m_viewTab
.count() == 1) || (m_tabBar
->count() < 2)) {
465 int tabIndex
= m_tabBar
->currentIndex() - 1;
466 if (tabIndex
== -1) {
467 tabIndex
= m_tabBar
->count() - 1;
469 m_tabBar
->setCurrentIndex(tabIndex
);
472 void DolphinMainWindow::openInNewTab()
474 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
475 if (list
.isEmpty()) {
476 openNewTab(m_activeViewContainer
->url());
477 } else if ((list
.count() == 1) && list
[0].isDir()) {
478 openNewTab(list
[0].url());
482 void DolphinMainWindow::openInNewWindow()
486 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
487 if (list
.isEmpty()) {
488 newWindowUrl
= m_activeViewContainer
->url();
489 } else if ((list
.count() == 1) && list
[0].isDir()) {
490 newWindowUrl
= list
[0].url();
493 if (!newWindowUrl
.isEmpty()) {
494 DolphinMainWindow
* window
= DolphinApplication::app()->createMainWindow();
495 window
->changeUrl(newWindowUrl
);
500 void DolphinMainWindow::toggleActiveView()
502 if (!m_viewTab
[m_tabIndex
].secondaryView
) {
503 // only one view is available
507 Q_ASSERT(m_activeViewContainer
);
508 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
510 DolphinViewContainer
* left
= m_viewTab
[m_tabIndex
].primaryView
;
511 DolphinViewContainer
* right
= m_viewTab
[m_tabIndex
].secondaryView
;
512 setActiveViewContainer(m_activeViewContainer
== right
? left
: right
);
515 void DolphinMainWindow::showEvent(QShowEvent
* event
)
517 KXmlGuiWindow::showEvent(event
);
518 if (!event
->spontaneous()) {
519 m_activeViewContainer
->view()->setFocus();
523 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
525 DolphinSettings
& settings
= DolphinSettings::instance();
526 GeneralSettings
* generalSettings
= settings
.generalSettings();
528 // Find out if Dolphin is closed directly by the user or
529 // by the session manager because the session is closed
530 bool closedByUser
= true;
531 DolphinApplication
*application
= qobject_cast
<DolphinApplication
*>(qApp
);
532 if (application
&& application
->sessionSaving()) {
533 closedByUser
= false;
536 if ((m_viewTab
.count() > 1) && generalSettings
->confirmClosingMultipleTabs() && closedByUser
) {
537 // Ask the user if he really wants to quit and close all tabs.
538 // Open a confirmation dialog with 3 buttons:
539 // KDialog::Yes -> Quit
540 // KDialog::No -> Close only the current tab
541 // KDialog::Cancel -> do nothing
542 KDialog
*dialog
= new KDialog(this, Qt::Dialog
);
543 dialog
->setCaption(i18nc("@title:window", "Confirmation"));
544 dialog
->setButtons(KDialog::Yes
| KDialog::No
| KDialog::Cancel
);
545 dialog
->setModal(true);
546 dialog
->setButtonGuiItem(KDialog::Yes
, KStandardGuiItem::quit());
547 dialog
->setButtonGuiItem(KDialog::No
, KGuiItem(i18n("C&lose Current Tab"), KIcon("tab-close")));
548 dialog
->setButtonGuiItem(KDialog::Cancel
, KStandardGuiItem::cancel());
549 dialog
->setDefaultButton(KDialog::Yes
);
551 bool doNotAskAgainCheckboxResult
= false;
553 const int result
= KMessageBox::createKMessageBox(dialog
,
554 QMessageBox::Warning
,
555 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
557 i18n("Do not ask again"),
558 &doNotAskAgainCheckboxResult
,
559 KMessageBox::Notify
);
561 if (doNotAskAgainCheckboxResult
) {
562 generalSettings
->setConfirmClosingMultipleTabs(false);
570 // Close only the current tab
578 generalSettings
->setFirstRun(false);
582 if (m_searchDockIsTemporaryVisible
) {
583 QDockWidget
* searchDock
= findChild
<QDockWidget
*>("searchDock");
587 m_searchDockIsTemporaryVisible
= false;
590 KXmlGuiWindow::closeEvent(event
);
593 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
595 const int tabCount
= m_viewTab
.count();
596 group
.writeEntry("Tab Count", tabCount
);
597 group
.writeEntry("Active Tab Index", m_tabBar
->currentIndex());
599 for (int i
= 0; i
< tabCount
; ++i
) {
600 const DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
601 group
.writeEntry(tabProperty("Primary URL", i
), cont
->url().url());
602 group
.writeEntry(tabProperty("Primary Editable", i
),
603 cont
->urlNavigator()->isUrlEditable());
605 cont
= m_viewTab
[i
].secondaryView
;
607 group
.writeEntry(tabProperty("Secondary URL", i
), cont
->url().url());
608 group
.writeEntry(tabProperty("Secondary Editable", i
),
609 cont
->urlNavigator()->isUrlEditable());
614 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
616 const int tabCount
= group
.readEntry("Tab Count", 1);
617 for (int i
= 0; i
< tabCount
; ++i
) {
618 DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
620 cont
->setUrl(group
.readEntry(tabProperty("Primary URL", i
)));
621 const bool editable
= group
.readEntry(tabProperty("Primary Editable", i
), false);
622 cont
->urlNavigator()->setUrlEditable(editable
);
624 cont
= m_viewTab
[i
].secondaryView
;
625 const QString secondaryUrl
= group
.readEntry(tabProperty("Secondary URL", i
));
626 if (!secondaryUrl
.isEmpty()) {
628 // a secondary view should be shown, but no one is available
629 // currently -> create a new view
631 cont
= m_viewTab
[i
].secondaryView
;
635 cont
->setUrl(secondaryUrl
);
636 const bool editable
= group
.readEntry(tabProperty("Secondary Editable", i
), false);
637 cont
->urlNavigator()->setUrlEditable(editable
);
639 // no secondary view should be shown, but the default setting shows
640 // one already -> close the view
644 // openNewTab() needs to be called only tabCount - 1 times
645 if (i
!= tabCount
- 1) {
650 const int index
= group
.readEntry("Active Tab Index", 0);
651 m_tabBar
->setCurrentIndex(index
);
654 void DolphinMainWindow::updateNewMenu()
656 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->showHiddenFiles());
657 m_newFileMenu
->checkUpToDate();
658 m_newFileMenu
->setPopupFiles(activeViewContainer()->url());
661 void DolphinMainWindow::createDirectory()
663 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->showHiddenFiles());
664 m_newFileMenu
->setPopupFiles(activeViewContainer()->url());
665 m_newFileMenu
->createDirectory();
668 void DolphinMainWindow::quit()
673 void DolphinMainWindow::showErrorMessage(const QString
& message
)
675 if (!message
.isEmpty()) {
676 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
677 statusBar
->setMessage(message
, DolphinStatusBar::Error
);
681 void DolphinMainWindow::slotUndoAvailable(bool available
)
683 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
685 undoAction
->setEnabled(available
);
689 void DolphinMainWindow::restoreClosedTab(QAction
* action
)
691 if (action
->data().toBool()) {
692 // clear all actions except the "Empty Recently Closed Tabs"
693 // action and the separator
694 QList
<QAction
*> actions
= m_recentTabsMenu
->menu()->actions();
695 const int count
= actions
.size();
696 for (int i
= 2; i
< count
; ++i
) {
697 m_recentTabsMenu
->menu()->removeAction(actions
.at(i
));
700 const ClosedTab closedTab
= action
->data().value
<ClosedTab
>();
701 openNewTab(closedTab
.primaryUrl
);
702 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
704 if (closedTab
.isSplit
) {
705 // create secondary view
707 m_viewTab
[m_tabIndex
].secondaryView
->setUrl(closedTab
.secondaryUrl
);
710 m_recentTabsMenu
->removeAction(action
);
713 if (m_recentTabsMenu
->menu()->actions().count() == 2) {
714 m_recentTabsMenu
->setEnabled(false);
718 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
720 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
722 undoAction
->setText(text
);
726 void DolphinMainWindow::undo()
729 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
730 KIO::FileUndoManager::self()->undo();
733 void DolphinMainWindow::cut()
735 m_activeViewContainer
->view()->cutSelectedItems();
738 void DolphinMainWindow::copy()
740 m_activeViewContainer
->view()->copySelectedItems();
743 void DolphinMainWindow::paste()
745 m_activeViewContainer
->view()->paste();
748 void DolphinMainWindow::find()
750 m_activeViewContainer
->setSearchModeEnabled(true);
753 void DolphinMainWindow::updatePasteAction()
755 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
756 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
757 pasteAction
->setEnabled(pasteInfo
.first
);
758 pasteAction
->setText(pasteInfo
.second
);
761 void DolphinMainWindow::selectAll()
765 // if the URL navigator is editable and focused, select the whole
766 // URL instead of all items of the view
768 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
769 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit(); // krazy:exclude=qclasses
770 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
771 lineEdit
->hasFocus();
773 lineEdit
->selectAll();
775 m_activeViewContainer
->view()->selectAll();
779 void DolphinMainWindow::invertSelection()
782 m_activeViewContainer
->view()->invertSelection();
785 void DolphinMainWindow::toggleSplitView()
787 if (!m_viewTab
[m_tabIndex
].secondaryView
) {
788 createSecondaryView(m_tabIndex
);
789 setActiveViewContainer(m_viewTab
[m_tabIndex
].secondaryView
);
790 } else if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
791 // remove secondary view
792 m_viewTab
[m_tabIndex
].secondaryView
->close();
793 m_viewTab
[m_tabIndex
].secondaryView
->deleteLater();
794 m_viewTab
[m_tabIndex
].secondaryView
= 0;
796 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
798 // The primary view is active and should be closed. Hence from a users point of view
799 // the content of the secondary view should be moved to the primary view.
800 // From an implementation point of view it is more efficient to close
801 // the primary view and exchange the internal pointers afterwards.
803 m_viewTab
[m_tabIndex
].primaryView
->close();
804 m_viewTab
[m_tabIndex
].primaryView
->deleteLater();
805 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
806 m_viewTab
[m_tabIndex
].secondaryView
= 0;
808 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
814 void DolphinMainWindow::reloadView()
817 m_activeViewContainer
->view()->reload();
820 void DolphinMainWindow::stopLoading()
822 m_activeViewContainer
->view()->stopLoading();
825 void DolphinMainWindow::enableStopAction()
827 actionCollection()->action("stop")->setEnabled(true);
830 void DolphinMainWindow::disableStopAction()
832 actionCollection()->action("stop")->setEnabled(false);
835 void DolphinMainWindow::showFilterBar()
837 m_activeViewContainer
->setFilterBarVisible(true);
840 void DolphinMainWindow::toggleEditLocation()
844 QAction
* action
= actionCollection()->action("editable_location");
845 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
846 urlNavigator
->setUrlEditable(action
->isChecked());
849 void DolphinMainWindow::replaceLocation()
851 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
852 navigator
->setUrlEditable(true);
853 navigator
->setFocus();
855 // select the whole text of the combo box editor
856 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit(); // krazy:exclude=qclasses
857 lineEdit
->selectAll();
860 void DolphinMainWindow::togglePanelLockState()
862 GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
864 const bool newLockState
= !generalSettings
->lockPanels();
865 foreach (QObject
* child
, children()) {
866 DolphinDockWidget
* dock
= qobject_cast
<DolphinDockWidget
*>(child
);
868 dock
->setLocked(newLockState
);
872 generalSettings
->setLockPanels(newLockState
);
875 void DolphinMainWindow::goBack()
879 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
880 urlNavigator
->goBack();
882 if (urlNavigator
->locationState().isEmpty()) {
883 // An empty location state indicates a redirection URL,
884 // which must be skipped too
885 urlNavigator
->goBack();
889 void DolphinMainWindow::goForward()
892 m_activeViewContainer
->urlNavigator()->goForward();
895 void DolphinMainWindow::goUp()
898 m_activeViewContainer
->urlNavigator()->goUp();
901 void DolphinMainWindow::goBack(Qt::MouseButtons buttons
)
903 // The default case (left button pressed) is handled in goBack().
904 if (buttons
== Qt::MidButton
) {
905 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
906 const int index
= urlNavigator
->historyIndex() + 1;
907 openNewTab(urlNavigator
->locationUrl(index
));
911 void DolphinMainWindow::goForward(Qt::MouseButtons buttons
)
913 // The default case (left button pressed) is handled in goForward().
914 if (buttons
== Qt::MidButton
) {
915 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
916 const int index
= urlNavigator
->historyIndex() - 1;
917 openNewTab(urlNavigator
->locationUrl(index
));
921 void DolphinMainWindow::goUp(Qt::MouseButtons buttons
)
923 // The default case (left button pressed) is handled in goUp().
924 if (buttons
== Qt::MidButton
) {
925 openNewTab(activeViewContainer()->url().upUrl());
929 void DolphinMainWindow::goHome()
932 m_activeViewContainer
->urlNavigator()->goHome();
935 void DolphinMainWindow::compareFiles()
937 // The method is only invoked if exactly 2 files have
938 // been selected. The selected files may be:
939 // - both in the primary view
940 // - both in the secondary view
941 // - one in the primary view and the other in the secondary
943 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
948 KFileItemList items
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedItems();
950 switch (items
.count()) {
952 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
);
953 items
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItems();
954 Q_ASSERT(items
.count() == 2);
955 urlA
= items
[0].url();
956 urlB
= items
[1].url();
961 urlA
= items
[0].url();
962 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
);
963 items
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItems();
964 Q_ASSERT(items
.count() == 1);
965 urlB
= items
[0].url();
970 urlA
= items
[0].url();
971 urlB
= items
[1].url();
976 // may not happen: compareFiles may only get invoked if 2
977 // files are selected
982 QString
command("kompare -c \"");
983 command
.append(urlA
.pathOrUrl());
984 command
.append("\" \"");
985 command
.append(urlB
.pathOrUrl());
986 command
.append('\"');
987 KRun::runCommand(command
, "Kompare", "kompare", this);
990 void DolphinMainWindow::toggleShowMenuBar()
992 const bool visible
= menuBar()->isVisible();
993 menuBar()->setVisible(!visible
);
996 void DolphinMainWindow::openTerminal()
998 QString
dir(QDir::homePath());
1000 // If the given directory is not local, it can still be the URL of an
1001 // ioslave using UDS_LOCAL_PATH which to be converted first.
1002 KUrl url
= KIO::NetAccess::mostLocalUrl(m_activeViewContainer
->url(), this);
1004 //If the URL is local after the above conversion, set the directory.
1005 if (url
.isLocalFile()) {
1006 dir
= url
.toLocalFile();
1009 KToolInvocation::invokeTerminal(QString(), dir
);
1012 void DolphinMainWindow::editSettings()
1014 if (!m_settingsDialog
) {
1015 const KUrl url
= activeViewContainer()->url();
1016 m_settingsDialog
= new DolphinSettingsDialog(url
, this);
1017 m_settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1018 m_settingsDialog
->show();
1020 m_settingsDialog
->raise();
1024 void DolphinMainWindow::setActiveTab(int index
)
1026 Q_ASSERT(index
>= 0);
1027 Q_ASSERT(index
< m_viewTab
.count());
1028 if (index
== m_tabIndex
) {
1032 // hide current tab content
1033 ViewTab
& hiddenTab
= m_viewTab
[m_tabIndex
];
1034 hiddenTab
.isPrimaryViewActive
= hiddenTab
.primaryView
->isActive();
1035 hiddenTab
.primaryView
->setActive(false);
1036 if (hiddenTab
.secondaryView
) {
1037 hiddenTab
.secondaryView
->setActive(false);
1039 QSplitter
* splitter
= m_viewTab
[m_tabIndex
].splitter
;
1041 m_centralWidgetLayout
->removeWidget(splitter
);
1043 // show active tab content
1046 ViewTab
& viewTab
= m_viewTab
[index
];
1047 m_centralWidgetLayout
->addWidget(viewTab
.splitter
, 1);
1048 viewTab
.primaryView
->show();
1049 if (viewTab
.secondaryView
) {
1050 viewTab
.secondaryView
->show();
1052 viewTab
.splitter
->show();
1054 setActiveViewContainer(viewTab
.isPrimaryViewActive
? viewTab
.primaryView
:
1055 viewTab
.secondaryView
);
1058 void DolphinMainWindow::closeTab()
1060 closeTab(m_tabBar
->currentIndex());
1063 void DolphinMainWindow::closeTab(int index
)
1065 Q_ASSERT(index
>= 0);
1066 Q_ASSERT(index
< m_viewTab
.count());
1067 if (m_viewTab
.count() == 1) {
1068 // the last tab may never get closed
1072 if (index
== m_tabIndex
) {
1073 // The tab that should be closed is the active tab. Activate the
1074 // previous tab before closing the tab.
1075 m_tabBar
->setCurrentIndex((index
> 0) ? index
- 1 : 1);
1077 rememberClosedTab(index
);
1080 m_viewTab
[index
].primaryView
->deleteLater();
1081 if (m_viewTab
[index
].secondaryView
) {
1082 m_viewTab
[index
].secondaryView
->deleteLater();
1084 m_viewTab
[index
].splitter
->deleteLater();
1085 m_viewTab
.erase(m_viewTab
.begin() + index
);
1087 m_tabBar
->blockSignals(true);
1088 m_tabBar
->removeTab(index
);
1090 if (m_tabIndex
> index
) {
1092 Q_ASSERT(m_tabIndex
>= 0);
1095 // if only one tab is left, also remove the tab entry so that
1096 // closing the last tab is not possible
1097 if (m_viewTab
.count() == 1) {
1098 m_tabBar
->removeTab(0);
1099 actionCollection()->action("close_tab")->setEnabled(false);
1101 m_tabBar
->blockSignals(false);
1105 void DolphinMainWindow::openTabContextMenu(int index
, const QPoint
& pos
)
1109 QAction
* newTabAction
= menu
.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab"));
1110 newTabAction
->setShortcut(actionCollection()->action("new_tab")->shortcut());
1112 QAction
* detachTabAction
= menu
.addAction(KIcon("tab-detach"), i18nc("@action:inmenu", "Detach Tab"));
1114 QAction
* closeOtherTabsAction
= menu
.addAction(KIcon("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs"));
1116 QAction
* closeTabAction
= menu
.addAction(KIcon("tab-close"), i18nc("@action:inmenu", "Close Tab"));
1117 closeTabAction
->setShortcut(actionCollection()->action("close_tab")->shortcut());
1118 QAction
* selectedAction
= menu
.exec(pos
);
1119 if (selectedAction
== newTabAction
) {
1120 const ViewTab
& tab
= m_viewTab
[index
];
1121 Q_ASSERT(tab
.primaryView
);
1122 const KUrl url
= tab
.secondaryView
&& tab
.secondaryView
->isActive() ?
1123 tab
.secondaryView
->url() : tab
.primaryView
->url();
1125 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
1126 } else if (selectedAction
== detachTabAction
) {
1127 const ViewTab
& tab
= m_viewTab
[index
];
1128 Q_ASSERT(tab
.primaryView
);
1129 const KUrl primaryUrl
= tab
.primaryView
->url();
1130 DolphinMainWindow
* window
= DolphinApplication::app()->createMainWindow();
1131 window
->changeUrl(primaryUrl
);
1133 if (tab
.secondaryView
) {
1134 const KUrl secondaryUrl
= tab
.secondaryView
->url();
1135 if (!window
->m_viewTab
[0].secondaryView
) {
1136 window
->toggleSplitView();
1138 window
->m_viewTab
[0].secondaryView
->setUrl(secondaryUrl
);
1139 if (tab
.primaryView
->isActive()) {
1140 window
->m_viewTab
[0].primaryView
->setActive(true);
1142 window
->m_viewTab
[0].secondaryView
->setActive(true);
1147 } else if (selectedAction
== closeOtherTabsAction
) {
1148 const int count
= m_tabBar
->count();
1149 for (int i
= 0; i
< index
; ++i
) {
1152 for (int i
= index
+ 1; i
< count
; ++i
) {
1155 } else if (selectedAction
== closeTabAction
) {
1160 void DolphinMainWindow::slotTabMoved(int from
, int to
)
1162 m_viewTab
.move(from
, to
);
1163 m_tabIndex
= m_tabBar
->currentIndex();
1166 void DolphinMainWindow::handlePlacesClick(const KUrl
& url
, Qt::MouseButtons buttons
)
1168 if (buttons
& Qt::MidButton
) {
1170 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
1176 void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent
* event
, bool& canDecode
)
1178 canDecode
= KUrl::List::canDecode(event
->mimeData());
1181 void DolphinMainWindow::handleUrl(const KUrl
& url
)
1183 delete m_lastHandleUrlStatJob
;
1184 m_lastHandleUrlStatJob
= 0;
1186 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1187 activeViewContainer()->setUrl(url
);
1188 } else if (KProtocolManager::supportsListing(url
)) {
1189 // stat the URL to see if it is a dir or not
1190 m_lastHandleUrlStatJob
= KIO::stat(url
, KIO::HideProgressInfo
);
1191 connect(m_lastHandleUrlStatJob
, SIGNAL(result(KJob
*)),
1192 this, SLOT(slotHandleUrlStatFinished(KJob
*)));
1195 new KRun(url
, this);
1199 void DolphinMainWindow::slotHandleUrlStatFinished(KJob
* job
)
1201 m_lastHandleUrlStatJob
= 0;
1202 const KIO::UDSEntry entry
= static_cast<KIO::StatJob
*>(job
)->statResult();
1203 const KUrl url
= static_cast<KIO::StatJob
*>(job
)->url();
1204 if (entry
.isDir()) {
1205 activeViewContainer()->setUrl(url
);
1207 new KRun(url
, this);
1211 void DolphinMainWindow::tabDropEvent(int tab
, QDropEvent
* event
)
1213 const KUrl::List urls
= KUrl::List::fromMimeData(event
->mimeData());
1214 if (!urls
.isEmpty() && tab
!= -1) {
1215 const ViewTab
& viewTab
= m_viewTab
[tab
];
1216 const KUrl destPath
= viewTab
.isPrimaryViewActive
? viewTab
.primaryView
->url() : viewTab
.secondaryView
->url();
1217 DragAndDropHelper::instance().dropUrls(KFileItem(), destPath
, event
, m_tabBar
);
1221 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1223 newFileMenu()->setEnabled(isFolderWritable
);
1226 void DolphinMainWindow::slotSearchModeChanged(bool enabled
)
1229 const KUrl url
= m_activeViewContainer
->url();
1230 const DolphinSearchInformation
& searchInfo
= DolphinSearchInformation::instance();
1231 if (!searchInfo
.isIndexingEnabled() || !searchInfo
.isPathIndexed(url
)) {
1235 QDockWidget
* searchDock
= findChild
<QDockWidget
*>("searchDock");
1241 if (!searchDock
->isVisible()) {
1242 m_searchDockIsTemporaryVisible
= true;
1246 if (searchDock
->isVisible() && m_searchDockIsTemporaryVisible
) {
1249 m_searchDockIsTemporaryVisible
= false;
1252 SearchPanel
* searchPanel
= qobject_cast
<SearchPanel
*>(searchDock
->widget());
1254 // Per default any search-operation triggered by the Search Panel is done
1256 SearchPanel::SearchMode searchMode
= SearchPanel::Everywhere
;
1258 if (enabled
&& (SearchSettings::location() == QLatin1String("FromHere"))) {
1259 // Only if the search-mode is enabled it is visible for the user whether
1260 // a searching is done "Everywhere" or "From Here" (= current directory).
1261 searchMode
= SearchPanel::FromCurrentDir
;
1263 searchPanel
->setSearchMode(searchMode
);
1270 void DolphinMainWindow::openContextMenu(const KFileItem
& item
,
1272 const QList
<QAction
*>& customActions
)
1274 QPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, item
, url
);
1275 contextMenu
->setCustomActions(customActions
);
1276 const DolphinContextMenu::Command command
= contextMenu
->open();
1279 case DolphinContextMenu::OpenParentFolderInNewWindow
: {
1280 DolphinMainWindow
* window
= DolphinApplication::app()->createMainWindow();
1281 window
->changeUrl(item
.url().upUrl());
1286 case DolphinContextMenu::OpenParentFolderInNewTab
:
1287 openNewTab(item
.url().upUrl());
1290 case DolphinContextMenu::None
:
1298 void DolphinMainWindow::init()
1300 DolphinSettings
& settings
= DolphinSettings::instance();
1302 // Check whether Dolphin runs the first time. If yes then
1303 // a proper default window size is given at the end of DolphinMainWindow::init().
1304 GeneralSettings
* generalSettings
= settings
.generalSettings();
1305 const bool firstRun
= generalSettings
->firstRun();
1307 generalSettings
->setViewPropsTimestamp(QDateTime::currentDateTime());
1310 setAcceptDrops(true);
1312 m_viewTab
[m_tabIndex
].splitter
= new QSplitter(this);
1313 m_viewTab
[m_tabIndex
].splitter
->setChildrenCollapsible(false);
1317 const KUrl
homeUrl(generalSettings
->homeUrl());
1318 setUrlAsCaption(homeUrl
);
1319 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
1320 connect(m_actionHandler
, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
1321 connect(m_actionHandler
, SIGNAL(createDirectory()), SLOT(createDirectory()));
1322 ViewProperties
props(homeUrl
);
1323 m_viewTab
[m_tabIndex
].primaryView
= new DolphinViewContainer(homeUrl
,
1324 m_viewTab
[m_tabIndex
].splitter
);
1326 m_activeViewContainer
= m_viewTab
[m_tabIndex
].primaryView
;
1327 connectViewSignals(m_activeViewContainer
);
1328 DolphinView
* view
= m_activeViewContainer
->view();
1329 m_activeViewContainer
->show();
1330 m_actionHandler
->setCurrentView(view
);
1332 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
1333 connect(this, SIGNAL(urlChanged(const KUrl
&)),
1334 m_remoteEncoding
, SLOT(slotAboutToOpenUrl()));
1336 m_tabBar
= new KTabBar(this);
1337 m_tabBar
->setMovable(true);
1338 m_tabBar
->setTabsClosable(true);
1339 connect(m_tabBar
, SIGNAL(currentChanged(int)),
1340 this, SLOT(setActiveTab(int)));
1341 connect(m_tabBar
, SIGNAL(tabCloseRequested(int)),
1342 this, SLOT(closeTab(int)));
1343 connect(m_tabBar
, SIGNAL(contextMenu(int, const QPoint
&)),
1344 this, SLOT(openTabContextMenu(int, const QPoint
&)));
1345 connect(m_tabBar
, SIGNAL(newTabRequest()),
1346 this, SLOT(openNewTab()));
1347 connect(m_tabBar
, SIGNAL(testCanDecode(const QDragMoveEvent
*, bool&)),
1348 this, SLOT(slotTestCanDecode(const QDragMoveEvent
*, bool&)));
1349 connect(m_tabBar
, SIGNAL(mouseMiddleClick(int)),
1350 this, SLOT(closeTab(int)));
1351 connect(m_tabBar
, SIGNAL(tabMoved(int, int)),
1352 this, SLOT(slotTabMoved(int, int)));
1353 connect(m_tabBar
, SIGNAL(receivedDropEvent(int, QDropEvent
*)),
1354 this, SLOT(tabDropEvent(int, QDropEvent
*)));
1356 m_tabBar
->blockSignals(true); // signals get unblocked after at least 2 tabs are open
1358 QWidget
* centralWidget
= new QWidget(this);
1359 m_centralWidgetLayout
= new QVBoxLayout(centralWidget
);
1360 m_centralWidgetLayout
->setSpacing(0);
1361 m_centralWidgetLayout
->setMargin(0);
1362 m_centralWidgetLayout
->addWidget(m_tabBar
);
1363 m_centralWidgetLayout
->addWidget(m_viewTab
[m_tabIndex
].splitter
, 1);
1365 setCentralWidget(centralWidget
);
1367 emit
urlChanged(homeUrl
);
1369 setupGUI(Keys
| Save
| Create
| ToolBar
);
1370 stateChanged("new_file");
1372 QClipboard
* clipboard
= QApplication::clipboard();
1373 connect(clipboard
, SIGNAL(dataChanged()),
1374 this, SLOT(updatePasteAction()));
1376 if (generalSettings
->splitView()) {
1379 updateEditActions();
1380 updateViewActions();
1383 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1384 showFilterBarAction
->setChecked(generalSettings
->filterBar());
1387 // assure a proper default size if Dolphin runs the first time
1391 m_showMenuBar
->setChecked(!menuBar()->isHidden()); // workaround for bug #171080
1394 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer
* viewContainer
)
1396 Q_ASSERT(viewContainer
);
1397 Q_ASSERT((viewContainer
== m_viewTab
[m_tabIndex
].primaryView
) ||
1398 (viewContainer
== m_viewTab
[m_tabIndex
].secondaryView
));
1399 if (m_activeViewContainer
== viewContainer
) {
1403 m_activeViewContainer
->setActive(false);
1404 m_activeViewContainer
= viewContainer
;
1406 // Activating the view container might trigger a recursive setActiveViewContainer() call
1407 // inside DolphinMainWindow::toggleActiveView() when having a split view. Temporary
1408 // disconnect the activated() signal in this case:
1409 disconnect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1410 m_activeViewContainer
->setActive(true);
1411 connect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1413 m_actionHandler
->setCurrentView(viewContainer
->view());
1416 updateEditActions();
1417 updateViewActions();
1420 const KUrl url
= m_activeViewContainer
->url();
1421 setUrlAsCaption(url
);
1422 if (m_viewTab
.count() > 1) {
1423 m_tabBar
->setTabText(m_tabIndex
, tabName(url
));
1424 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(KMimeType::iconNameForUrl(url
)));
1427 emit
urlChanged(url
);
1430 void DolphinMainWindow::setupActions()
1432 // setup 'File' menu
1433 m_newFileMenu
= new DolphinNewFileMenu(this);
1434 KMenu
* menu
= m_newFileMenu
->menu();
1435 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1436 menu
->setIcon(KIcon("document-new"));
1437 connect(menu
, SIGNAL(aboutToShow()),
1438 this, SLOT(updateNewMenu()));
1440 KAction
* newWindow
= actionCollection()->addAction("new_window");
1441 newWindow
->setIcon(KIcon("window-new"));
1442 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1443 newWindow
->setShortcut(Qt::CTRL
| Qt::Key_N
);
1444 connect(newWindow
, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1446 KAction
* newTab
= actionCollection()->addAction("new_tab");
1447 newTab
->setIcon(KIcon("tab-new"));
1448 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1449 newTab
->setShortcut(KShortcut(Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
));
1450 connect(newTab
, SIGNAL(triggered()), this, SLOT(openNewTab()));
1452 KAction
* closeTab
= actionCollection()->addAction("close_tab");
1453 closeTab
->setIcon(KIcon("tab-close"));
1454 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1455 closeTab
->setShortcut(Qt::CTRL
| Qt::Key_W
);
1456 closeTab
->setEnabled(false);
1457 connect(closeTab
, SIGNAL(triggered()), this, SLOT(closeTab()));
1459 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1461 // setup 'Edit' menu
1462 KStandardAction::undo(this,
1464 actionCollection());
1466 // need to remove shift+del from cut action, else the shortcut for deletejob
1468 KAction
* cut
= KStandardAction::cut(this, SLOT(cut()), actionCollection());
1469 KShortcut cutShortcut
= cut
->shortcut();
1470 cutShortcut
.remove(Qt::SHIFT
| Qt::Key_Delete
, KShortcut::KeepEmpty
);
1471 cut
->setShortcut(cutShortcut
);
1472 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1473 KAction
* paste
= KStandardAction::paste(this, SLOT(paste()), actionCollection());
1474 // The text of the paste-action is modified dynamically by Dolphin
1475 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1476 // due to the long text, the text "Paste" is used:
1477 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1479 KStandardAction::find(this, SLOT(find()), actionCollection());
1481 KAction
* selectAll
= actionCollection()->addAction("select_all");
1482 selectAll
->setText(i18nc("@action:inmenu Edit", "Select All"));
1483 selectAll
->setShortcut(Qt::CTRL
| Qt::Key_A
);
1484 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
1486 KAction
* invertSelection
= actionCollection()->addAction("invert_selection");
1487 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1488 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1489 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
1491 // setup 'View' menu
1492 // (note that most of it is set up in DolphinViewActionHandler)
1494 KAction
* split
= actionCollection()->addAction("split_view");
1495 split
->setShortcut(Qt::Key_F3
);
1496 updateSplitAction();
1497 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1499 KAction
* reload
= actionCollection()->addAction("reload");
1500 reload
->setText(i18nc("@action:inmenu View", "Reload"));
1501 reload
->setShortcut(Qt::Key_F5
);
1502 reload
->setIcon(KIcon("view-refresh"));
1503 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
1505 KAction
* stop
= actionCollection()->addAction("stop");
1506 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1507 stop
->setToolTip(i18nc("@info", "Stop loading"));
1508 stop
->setIcon(KIcon("process-stop"));
1509 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
1511 KToggleAction
* showFullLocation
= actionCollection()->add
<KToggleAction
>("editable_location");
1512 showFullLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1513 showFullLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
1514 connect(showFullLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1516 KAction
* replaceLocation
= actionCollection()->addAction("replace_location");
1517 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1518 replaceLocation
->setShortcut(Qt::Key_F6
);
1519 connect(replaceLocation
, SIGNAL(triggered()), this, SLOT(replaceLocation()));
1522 KAction
* backAction
= KStandardAction::back(this, SLOT(goBack()), actionCollection());
1523 connect(backAction
, SIGNAL(triggered(Qt::MouseButtons
, Qt::KeyboardModifiers
)), this, SLOT(goBack(Qt::MouseButtons
)));
1524 KShortcut backShortcut
= backAction
->shortcut();
1525 backShortcut
.setAlternate(Qt::Key_Backspace
);
1526 backAction
->setShortcut(backShortcut
);
1528 m_recentTabsMenu
= new KActionMenu(i18n("Recently Closed Tabs"), this);
1529 m_recentTabsMenu
->setIcon(KIcon("edit-undo"));
1530 actionCollection()->addAction("closed_tabs", m_recentTabsMenu
);
1531 connect(m_recentTabsMenu
->menu(), SIGNAL(triggered(QAction
*)),
1532 this, SLOT(restoreClosedTab(QAction
*)));
1534 QAction
* action
= new QAction("Empty Recently Closed Tabs", m_recentTabsMenu
);
1535 action
->setIcon(KIcon("edit-clear-list"));
1536 action
->setData(QVariant::fromValue(true));
1537 m_recentTabsMenu
->addAction(action
);
1538 m_recentTabsMenu
->addSeparator();
1539 m_recentTabsMenu
->setEnabled(false);
1541 KAction
* forwardAction
= KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1542 connect(forwardAction
, SIGNAL(triggered(Qt::MouseButtons
, Qt::KeyboardModifiers
)), this, SLOT(goForward(Qt::MouseButtons
)));
1544 KAction
* upAction
= KStandardAction::up(this, SLOT(goUp()), actionCollection());
1545 connect(upAction
, SIGNAL(triggered(Qt::MouseButtons
, Qt::KeyboardModifiers
)), this, SLOT(goUp(Qt::MouseButtons
)));
1547 KStandardAction::home(this, SLOT(goHome()), actionCollection());
1549 // setup 'Tools' menu
1550 KAction
* showFilterBar
= actionCollection()->addAction("show_filter_bar");
1551 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1552 showFilterBar
->setIcon(KIcon("view-filter"));
1553 showFilterBar
->setShortcut(Qt::CTRL
| Qt::Key_I
);
1554 connect(showFilterBar
, SIGNAL(triggered()), this, SLOT(showFilterBar()));
1556 KAction
* compareFiles
= actionCollection()->addAction("compare_files");
1557 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1558 compareFiles
->setIcon(KIcon("kompare"));
1559 compareFiles
->setEnabled(false);
1560 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
1562 KAction
* openTerminal
= actionCollection()->addAction("open_terminal");
1563 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1564 openTerminal
->setIcon(KIcon("utilities-terminal"));
1565 openTerminal
->setShortcut(Qt::SHIFT
| Qt::Key_F4
);
1566 connect(openTerminal
, SIGNAL(triggered()), this, SLOT(openTerminal()));
1568 // setup 'Settings' menu
1569 m_showMenuBar
= KStandardAction::showMenubar(this, SLOT(toggleShowMenuBar()), actionCollection());
1570 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1572 // not in menu actions
1573 QList
<QKeySequence
> nextTabKeys
;
1574 nextTabKeys
.append(KStandardShortcut::tabNext().primary());
1575 nextTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::Key_Tab
));
1577 QList
<QKeySequence
> prevTabKeys
;
1578 prevTabKeys
.append(KStandardShortcut::tabPrev().primary());
1579 prevTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::SHIFT
| Qt::Key_Tab
));
1581 KAction
* activateNextTab
= actionCollection()->addAction("activate_next_tab");
1582 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1583 connect(activateNextTab
, SIGNAL(triggered()), SLOT(activateNextTab()));
1584 activateNextTab
->setShortcuts(QApplication::isRightToLeft() ? prevTabKeys
: nextTabKeys
);
1586 KAction
* activatePrevTab
= actionCollection()->addAction("activate_prev_tab");
1587 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1588 connect(activatePrevTab
, SIGNAL(triggered()), SLOT(activatePrevTab()));
1589 activatePrevTab
->setShortcuts(QApplication::isRightToLeft() ? nextTabKeys
: prevTabKeys
);
1592 KAction
* openInNewTab
= actionCollection()->addAction("open_in_new_tab");
1593 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1594 openInNewTab
->setIcon(KIcon("tab-new"));
1595 connect(openInNewTab
, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1597 KAction
* openInNewWindow
= actionCollection()->addAction("open_in_new_window");
1598 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1599 openInNewWindow
->setIcon(KIcon("window-new"));
1600 connect(openInNewWindow
, SIGNAL(triggered()), this, SLOT(openInNewWindow()));
1603 void DolphinMainWindow::setupDockWidgets()
1605 const bool lock
= DolphinSettings::instance().generalSettings()->lockPanels();
1607 KDualAction
* lockLayoutAction
= actionCollection()->add
<KDualAction
>("lock_panels");
1608 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
1609 lockLayoutAction
->setActiveIcon(KIcon("object-unlocked"));
1610 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
1611 lockLayoutAction
->setInactiveIcon(KIcon("object-locked"));
1612 lockLayoutAction
->setActive(lock
);
1613 connect(lockLayoutAction
, SIGNAL(triggered()), this, SLOT(togglePanelLockState()));
1615 // Setup "Information"
1616 DolphinDockWidget
* infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
1617 infoDock
->setLocked(lock
);
1618 infoDock
->setObjectName("infoDock");
1619 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1620 Panel
* infoPanel
= new InformationPanel(infoDock
);
1621 infoPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1622 connect(infoPanel
, SIGNAL(urlActivated(KUrl
)), this, SLOT(handleUrl(KUrl
)));
1623 infoDock
->setWidget(infoPanel
);
1625 QAction
* infoAction
= infoDock
->toggleViewAction();
1626 infoAction
->setIcon(KIcon("dialog-information"));
1627 infoAction
->setShortcut(Qt::Key_F11
);
1628 addActionCloneToCollection(infoAction
, "show_information_panel");
1630 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1631 connect(this, SIGNAL(urlChanged(KUrl
)),
1632 infoPanel
, SLOT(setUrl(KUrl
)));
1633 connect(this, SIGNAL(selectionChanged(KFileItemList
)),
1634 infoPanel
, SLOT(setSelection(KFileItemList
)));
1635 connect(this, SIGNAL(requestItemInfo(KFileItem
)),
1636 infoPanel
, SLOT(requestDelayedItemInfo(KFileItem
)));
1639 DolphinDockWidget
* foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
1640 foldersDock
->setLocked(lock
);
1641 foldersDock
->setObjectName("foldersDock");
1642 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1643 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1644 foldersPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1645 foldersDock
->setWidget(foldersPanel
);
1647 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1648 foldersAction
->setShortcut(Qt::Key_F7
);
1649 foldersAction
->setIcon(KIcon("folder"));
1650 addActionCloneToCollection(foldersAction
, "show_folders_panel");
1652 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1653 connect(this, SIGNAL(urlChanged(KUrl
)),
1654 foldersPanel
, SLOT(setUrl(KUrl
)));
1655 connect(foldersPanel
, SIGNAL(changeUrl(KUrl
, Qt::MouseButtons
)),
1656 this, SLOT(handlePlacesClick(KUrl
, Qt::MouseButtons
)));
1660 DolphinDockWidget
* terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1661 terminalDock
->setLocked(lock
);
1662 terminalDock
->setObjectName("terminalDock");
1663 terminalDock
->setAllowedAreas(Qt::TopDockWidgetArea
| Qt::BottomDockWidgetArea
);
1664 Panel
* terminalPanel
= new TerminalPanel(terminalDock
);
1665 terminalPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1666 terminalDock
->setWidget(terminalPanel
);
1668 connect(terminalPanel
, SIGNAL(hideTerminalPanel()), terminalDock
, SLOT(hide()));
1670 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1671 terminalAction
->setShortcut(Qt::Key_F4
);
1672 terminalAction
->setIcon(KIcon("utilities-terminal"));
1673 addActionCloneToCollection(terminalAction
, "show_terminal_panel");
1675 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1676 connect(this, SIGNAL(urlChanged(KUrl
)),
1677 terminalPanel
, SLOT(setUrl(KUrl
)));
1682 DolphinDockWidget
* searchDock
= new DolphinDockWidget(i18nc("@title:window", "Search"));
1683 searchDock
->setLocked(lock
);
1684 searchDock
->setObjectName("searchDock");
1685 searchDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1686 Panel
* searchPanel
= new SearchPanel(searchDock
);
1687 searchPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1688 connect(searchPanel
, SIGNAL(urlActivated(KUrl
)), this, SLOT(handleUrl(KUrl
)));
1689 searchDock
->setWidget(searchPanel
);
1691 QAction
* searchAction
= searchDock
->toggleViewAction();
1692 searchAction
->setShortcut(Qt::Key_F12
);
1693 searchAction
->setIcon(KIcon("system-search"));
1694 addActionCloneToCollection(searchAction
, "show_search_panel");
1695 addDockWidget(Qt::RightDockWidgetArea
, searchDock
);
1696 connect(this, SIGNAL(urlChanged(KUrl
)),
1697 searchPanel
, SLOT(setUrl(KUrl
)));
1700 const bool firstRun
= DolphinSettings::instance().generalSettings()->firstRun();
1703 foldersDock
->hide();
1705 terminalDock
->hide();
1713 DolphinDockWidget
* placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
1714 placesDock
->setLocked(lock
);
1715 placesDock
->setObjectName("placesDock");
1716 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1718 PlacesPanel
* placesPanel
= new PlacesPanel(placesDock
);
1719 QAction
* separator
= new QAction(placesPanel
);
1720 separator
->setSeparator(true);
1721 QList
<QAction
*> placesActions
;
1722 placesActions
.append(separator
);
1723 placesActions
.append(lockLayoutAction
);
1724 placesPanel
->addActions(placesActions
);
1725 placesPanel
->setModel(DolphinSettings::instance().placesModel());
1726 placesPanel
->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff
);
1727 placesDock
->setWidget(placesPanel
);
1729 QAction
* placesAction
= placesDock
->toggleViewAction();
1730 placesAction
->setShortcut(Qt::Key_F9
);
1731 placesAction
->setIcon(KIcon("bookmarks"));
1732 addActionCloneToCollection(placesAction
, "show_places_panel");
1734 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1735 connect(placesPanel
, SIGNAL(urlChanged(KUrl
, Qt::MouseButtons
)),
1736 this, SLOT(handlePlacesClick(KUrl
, Qt::MouseButtons
)));
1737 connect(this, SIGNAL(urlChanged(KUrl
)),
1738 placesPanel
, SLOT(setUrl(KUrl
)));
1740 // Add actions into the "Panels" menu
1741 KActionMenu
* panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Panels"), this);
1742 actionCollection()->addAction("panels", panelsMenu
);
1743 panelsMenu
->setDelayed(false);
1744 panelsMenu
->addAction(placesAction
);
1745 panelsMenu
->addAction(infoAction
);
1746 panelsMenu
->addAction(foldersAction
);
1748 panelsMenu
->addAction(terminalAction
);
1751 panelsMenu
->addAction(searchAction
);
1753 panelsMenu
->addSeparator();
1754 panelsMenu
->addAction(lockLayoutAction
);
1757 void DolphinMainWindow::updateEditActions()
1759 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1760 if (list
.isEmpty()) {
1761 stateChanged("has_no_selection");
1763 stateChanged("has_selection");
1765 KActionCollection
* col
= actionCollection();
1766 QAction
* renameAction
= col
->action("rename");
1767 QAction
* moveToTrashAction
= col
->action("move_to_trash");
1768 QAction
* deleteAction
= col
->action("delete");
1769 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
1770 QAction
* deleteWithTrashShortcut
= col
->action("delete_shortcut"); // see DolphinViewActionHandler
1772 KFileItemListProperties
capabilities(list
);
1773 const bool enableMoveToTrash
= capabilities
.isLocal() && capabilities
.supportsMoving();
1775 renameAction
->setEnabled(capabilities
.supportsMoving());
1776 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1777 deleteAction
->setEnabled(capabilities
.supportsDeleting());
1778 deleteWithTrashShortcut
->setEnabled(capabilities
.supportsDeleting() && !enableMoveToTrash
);
1779 cutAction
->setEnabled(capabilities
.supportsMoving());
1781 updatePasteAction();
1784 void DolphinMainWindow::updateViewActions()
1786 m_actionHandler
->updateViewActions();
1788 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1789 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
1791 updateSplitAction();
1793 QAction
* editableLocactionAction
= actionCollection()->action("editable_location");
1794 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
1795 editableLocactionAction
->setChecked(urlNavigator
->isUrlEditable());
1798 void DolphinMainWindow::updateGoActions()
1800 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
1801 const KUrl currentUrl
= m_activeViewContainer
->url();
1802 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
1805 void DolphinMainWindow::rememberClosedTab(int index
)
1807 KMenu
* tabsMenu
= m_recentTabsMenu
->menu();
1809 const QString primaryPath
= m_viewTab
[index
].primaryView
->url().path();
1810 const QString iconName
= KMimeType::iconNameForUrl(primaryPath
);
1812 QAction
* action
= new QAction(squeezedText(primaryPath
), tabsMenu
);
1814 ClosedTab closedTab
;
1815 closedTab
.primaryUrl
= m_viewTab
[index
].primaryView
->url();
1817 if (m_viewTab
[index
].secondaryView
) {
1818 closedTab
.secondaryUrl
= m_viewTab
[index
].secondaryView
->url();
1819 closedTab
.isSplit
= true;
1821 closedTab
.isSplit
= false;
1824 action
->setData(QVariant::fromValue(closedTab
));
1825 action
->setIcon(KIcon(iconName
));
1827 // add the closed tab menu entry after the separator and
1828 // "Empty Recently Closed Tabs" entry
1829 if (tabsMenu
->actions().size() == 2) {
1830 tabsMenu
->addAction(action
);
1832 tabsMenu
->insertAction(tabsMenu
->actions().at(2), action
);
1835 // assure that only up to 8 closed tabs are shown in the menu
1836 if (tabsMenu
->actions().size() > 8) {
1837 tabsMenu
->removeAction(tabsMenu
->actions().last());
1839 actionCollection()->action("closed_tabs")->setEnabled(true);
1840 KAcceleratorManager::manage(tabsMenu
);
1843 void DolphinMainWindow::clearStatusBar()
1845 m_activeViewContainer
->statusBar()->clear();
1848 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
1850 connect(container
, SIGNAL(showFilterBarChanged(bool)),
1851 this, SLOT(updateFilterBarAction(bool)));
1852 connect(container
, SIGNAL(writeStateChanged(bool)),
1853 this, SLOT(slotWriteStateChanged(bool)));
1854 connect(container
, SIGNAL(searchModeChanged(bool)),
1855 this, SLOT(slotSearchModeChanged(bool)));
1857 DolphinView
* view
= container
->view();
1858 connect(view
, SIGNAL(selectionChanged(KFileItemList
)),
1859 this, SLOT(slotSelectionChanged(KFileItemList
)));
1860 connect(view
, SIGNAL(requestItemInfo(KFileItem
)),
1861 this, SLOT(slotRequestItemInfo(KFileItem
)));
1862 connect(view
, SIGNAL(activated()),
1863 this, SLOT(toggleActiveView()));
1864 connect(view
, SIGNAL(tabRequested(const KUrl
&)),
1865 this, SLOT(openNewTab(const KUrl
&)));
1866 connect(view
, SIGNAL(requestContextMenu(KFileItem
, const KUrl
&, const QList
<QAction
*>&)),
1867 this, SLOT(openContextMenu(KFileItem
, const KUrl
&, const QList
<QAction
*>&)));
1868 connect(view
, SIGNAL(startedPathLoading(KUrl
)),
1869 this, SLOT(enableStopAction()));
1870 connect(view
, SIGNAL(finishedPathLoading(KUrl
)),
1871 this, SLOT(disableStopAction()));
1873 const KUrlNavigator
* navigator
= container
->urlNavigator();
1874 connect(navigator
, SIGNAL(urlChanged(const KUrl
&)),
1875 this, SLOT(changeUrl(const KUrl
&)));
1876 connect(navigator
, SIGNAL(historyChanged()),
1877 this, SLOT(updateHistory()));
1878 connect(navigator
, SIGNAL(editableStateChanged(bool)),
1879 this, SLOT(slotEditableStateChanged(bool)));
1880 connect(navigator
, SIGNAL(tabRequested(const KUrl
&)),
1881 this, SLOT(openNewTab(KUrl
)));
1884 void DolphinMainWindow::updateSplitAction()
1886 QAction
* splitAction
= actionCollection()->action("split_view");
1887 if (m_viewTab
[m_tabIndex
].secondaryView
) {
1888 if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
1889 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
1890 splitAction
->setToolTip(i18nc("@info", "Close right view"));
1891 splitAction
->setIcon(KIcon("view-right-close"));
1893 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
1894 splitAction
->setToolTip(i18nc("@info", "Close left view"));
1895 splitAction
->setIcon(KIcon("view-left-close"));
1898 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
1899 splitAction
->setToolTip(i18nc("@info", "Split view"));
1900 splitAction
->setIcon(KIcon("view-right-new"));
1904 QString
DolphinMainWindow::tabName(const KUrl
& url
) const
1907 if (url
.equals(KUrl("file:///"))) {
1910 name
= url
.fileName();
1911 if (name
.isEmpty()) {
1912 name
= url
.protocol();
1914 // Make sure that a '&' inside the directory name is displayed correctly
1915 // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
1916 name
.replace('&', "&&");
1922 bool DolphinMainWindow::isKompareInstalled() const
1924 static bool initialized
= false;
1925 static bool installed
= false;
1927 // TODO: maybe replace this approach later by using a menu
1928 // plugin like kdiff3plugin.cpp
1929 installed
= !KGlobal::dirs()->findExe("kompare").isEmpty();
1935 void DolphinMainWindow::createSecondaryView(int tabIndex
)
1937 QSplitter
* splitter
= m_viewTab
[tabIndex
].splitter
;
1938 const int newWidth
= (m_viewTab
[tabIndex
].primaryView
->width() - splitter
->handleWidth()) / 2;
1940 const DolphinView
* view
= m_viewTab
[tabIndex
].primaryView
->view();
1941 m_viewTab
[tabIndex
].secondaryView
= new DolphinViewContainer(view
->rootUrl(), 0);
1942 splitter
->addWidget(m_viewTab
[tabIndex
].secondaryView
);
1943 splitter
->setSizes(QList
<int>() << newWidth
<< newWidth
);
1944 connectViewSignals(m_viewTab
[tabIndex
].secondaryView
);
1945 m_viewTab
[tabIndex
].secondaryView
->setActive(false);
1946 m_viewTab
[tabIndex
].secondaryView
->show();
1949 QString
DolphinMainWindow::tabProperty(const QString
& property
, int tabIndex
) const
1951 return "Tab " + QString::number(tabIndex
) + ' ' + property
;
1954 void DolphinMainWindow::setUrlAsCaption(const KUrl
& url
)
1957 if (!url
.isLocalFile()) {
1958 caption
.append(url
.protocol() + " - ");
1959 if (url
.hasHost()) {
1960 caption
.append(url
.host() + " - ");
1964 const QString fileName
= url
.fileName().isEmpty() ? "/" : url
.fileName();
1965 caption
.append(fileName
);
1967 setCaption(caption
);
1970 QString
DolphinMainWindow::squeezedText(const QString
& text
) const
1972 const QFontMetrics fm
= fontMetrics();
1973 return fm
.elidedText(text
, Qt::ElideMiddle
, fm
.maxWidth() * 10);
1976 void DolphinMainWindow::addActionCloneToCollection(QAction
* action
, const QString
& actionName
)
1978 KAction
* actionClone
= actionCollection()->addAction(actionName
);
1979 actionClone
->setText(action
->text());
1980 actionClone
->setIcon(action
->icon());
1981 connect(actionClone
, SIGNAL(triggered()), action
, SLOT(trigger()));
1984 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
1985 KIO::FileUndoManager::UiInterface()
1989 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
1993 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
1995 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
1997 DolphinStatusBar
* statusBar
= mainWin
->activeViewContainer()->statusBar();
1998 statusBar
->setMessage(job
->errorString(), DolphinStatusBar::Error
);
2000 KIO::FileUndoManager::UiInterface::jobError(job
);
2004 #include "dolphinmainwindow.moc"