1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> *
3 * Copyright (C) 2006 by Stefan Monov <logixoul@gmail.com> *
4 * Copyright (C) 2006 by Cvetoslav Ludmiloff <ludmiloff@gmail.com> *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20 ***************************************************************************/
22 #include "dolphinmainwindow.h"
23 #include "dolphinviewactionhandler.h"
24 #include "dolphinremoteencoding.h"
26 #include <config-nepomuk.h>
28 #include "search/dolphinsearchoptionsconfigurator.h"
31 #include "dolphinapplication.h"
32 #include "dolphinnewmenu.h"
33 #include "search/dolphinsearchbox.h"
34 #include "settings/dolphinsettings.h"
35 #include "settings/dolphinsettingsdialog.h"
36 #include "dolphinviewcontainer.h"
37 #include "panels/folders/folderspanel.h"
38 #include "panels/places/placespanel.h"
39 #include "panels/information/informationpanel.h"
40 #include "mainwindowadaptor.h"
41 #include "statusbar/dolphinstatusbar.h"
42 #include "viewproperties.h"
45 #include "panels/terminal/terminalpanel.h"
48 #include "dolphin_generalsettings.h"
49 #include "dolphin_iconsmodesettings.h"
50 #include "draganddrophelper.h"
53 #include <kactioncollection.h>
55 #include <kdesktopfile.h>
56 #include <kdeversion.h>
57 #include <kfiledialog.h>
58 #include <kfileplacesmodel.h>
60 #include <klineedit.h>
63 #include <kiconloader.h>
64 #include <kio/netaccess.h>
65 #include <kinputdialog.h>
67 #include <kprotocolmanager.h>
70 #include <kmessagebox.h>
71 #include <kfileitemlistproperties.h>
72 #include <konqmimedata.h>
73 #include <kprotocolinfo.h>
76 #include <kstandarddirs.h>
77 #include <kstatusbar.h>
78 #include <kstandardaction.h>
80 #include <ktoggleaction.h>
81 #include <kurlnavigator.h>
83 #include <kurlcombobox.h>
84 #include <ktoolinvocation.h>
86 #include <QDBusMessage>
90 #include <QDockWidget>
91 #include <kacceleratormanager.h>
94 * Remembers the tab configuration if a tab has been closed.
95 * Each closed tab can be restored by the menu
96 * "Go -> Recently Closed Tabs".
104 Q_DECLARE_METATYPE(ClosedTab
)
106 DolphinMainWindow::DolphinMainWindow(int id
) :
111 m_activeViewContainer(0),
112 m_centralWidgetLayout(0),
115 m_searchOptionsConfigurator(0),
124 setObjectName("Dolphin#");
126 m_viewTab
.append(ViewTab());
128 new MainWindowAdaptor(this);
129 QDBusConnection::sessionBus().registerObject(QString("/dolphin/MainWindow%1").arg(m_id
), this);
131 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
132 undoManager
->setUiInterface(new UndoUiInterface());
134 connect(undoManager
, SIGNAL(undoAvailable(bool)),
135 this, SLOT(slotUndoAvailable(bool)));
136 connect(undoManager
, SIGNAL(undoTextChanged(const QString
&)),
137 this, SLOT(slotUndoTextChanged(const QString
&)));
138 connect(undoManager
, SIGNAL(jobRecordingStarted(CommandType
)),
139 this, SLOT(clearStatusBar()));
140 connect(undoManager
, SIGNAL(jobRecordingFinished(CommandType
)),
141 this, SLOT(showCommand(CommandType
)));
142 connect(DolphinSettings::instance().placesModel(), SIGNAL(errorMessage(const QString
&)),
143 this, SLOT(showErrorMessage(const QString
&)));
144 connect(&DragAndDropHelper::instance(), SIGNAL(errorMessage(const QString
&)),
145 this, SLOT(showErrorMessage(const QString
&)));
148 DolphinMainWindow::~DolphinMainWindow()
150 DolphinApplication::app()->removeMainWindow(this);
153 void DolphinMainWindow::toggleViews()
155 if (m_viewTab
[m_tabIndex
].primaryView
== 0) {
159 // move secondary view from the last position of the splitter
160 // to the first position
161 m_viewTab
[m_tabIndex
].splitter
->insertWidget(0, m_viewTab
[m_tabIndex
].secondaryView
);
163 DolphinViewContainer
* container
= m_viewTab
[m_tabIndex
].primaryView
;
164 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
165 m_viewTab
[m_tabIndex
].secondaryView
= container
;
168 void DolphinMainWindow::showCommand(CommandType command
)
170 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
172 case KIO::FileUndoManager::Copy
:
173 statusBar
->setMessage(i18nc("@info:status", "Successfully copied."),
174 DolphinStatusBar::OperationCompleted
);
176 case KIO::FileUndoManager::Move
:
177 statusBar
->setMessage(i18nc("@info:status", "Successfully moved."),
178 DolphinStatusBar::OperationCompleted
);
180 case KIO::FileUndoManager::Link
:
181 statusBar
->setMessage(i18nc("@info:status", "Successfully linked."),
182 DolphinStatusBar::OperationCompleted
);
184 case KIO::FileUndoManager::Trash
:
185 statusBar
->setMessage(i18nc("@info:status", "Successfully moved to trash."),
186 DolphinStatusBar::OperationCompleted
);
188 case KIO::FileUndoManager::Rename
:
189 statusBar
->setMessage(i18nc("@info:status", "Successfully renamed."),
190 DolphinStatusBar::OperationCompleted
);
193 case KIO::FileUndoManager::Mkdir
:
194 statusBar
->setMessage(i18nc("@info:status", "Created folder."),
195 DolphinStatusBar::OperationCompleted
);
203 void DolphinMainWindow::refreshViews()
205 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
207 // remember the current active view, as because of
208 // the refreshing the active view might change to
209 // the secondary view
210 DolphinViewContainer
* activeViewContainer
= m_activeViewContainer
;
212 const int tabCount
= m_viewTab
.count();
213 for (int i
= 0; i
< tabCount
; ++i
) {
214 m_viewTab
[i
].primaryView
->refresh();
215 if (m_viewTab
[i
].secondaryView
!= 0) {
216 m_viewTab
[i
].secondaryView
->refresh();
220 setActiveViewContainer(activeViewContainer
);
223 void DolphinMainWindow::pasteIntoFolder()
225 m_activeViewContainer
->view()->pasteIntoFolder();
228 void DolphinMainWindow::changeUrl(const KUrl
& url
)
230 if (!KProtocolManager::supportsListing(url
)) {
231 // The URL navigator only checks for validity, not
232 // if the URL can be listed. An error message is
233 // shown due to DolphinViewContainer::restoreView().
237 DolphinViewContainer
* view
= activeViewContainer();
243 setUrlAsCaption(url
);
244 if (m_viewTab
.count() > 1) {
245 m_tabBar
->setTabText(m_tabIndex
, squeezedText(tabName(m_activeViewContainer
->url())));
247 const QString iconName
= KMimeType::iconNameForUrl(url
);
248 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(iconName
));
249 emit
urlChanged(url
);
253 void DolphinMainWindow::changeSelection(const KFileItemList
& selection
)
255 activeViewContainer()->view()->changeSelection(selection
);
258 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
260 KToggleAction
* editableLocationAction
=
261 static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
262 editableLocationAction
->setChecked(editable
);
265 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
269 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
270 int selectedUrlsCount
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedItemsCount();
271 if (m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
272 selectedUrlsCount
+= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItemsCount();
275 QAction
* compareFilesAction
= actionCollection()->action("compare_files");
276 if (selectedUrlsCount
== 2) {
277 compareFilesAction
->setEnabled(isKompareInstalled());
279 compareFilesAction
->setEnabled(false);
282 emit
selectionChanged(selection
);
285 void DolphinMainWindow::slotWheelMoved(int wheelDelta
)
287 if (wheelDelta
> 0) {
294 void DolphinMainWindow::slotRequestItemInfo(const KFileItem
& item
)
296 emit
requestItemInfo(item
);
299 void DolphinMainWindow::updateHistory()
301 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
302 const int index
= urlNavigator
->historyIndex();
304 QAction
* backAction
= actionCollection()->action("go_back");
305 backAction
->setToolTip(i18nc("@info", "Go back"));
306 if (backAction
!= 0) {
307 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
310 QAction
* forwardAction
= actionCollection()->action("go_forward");
311 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
312 if (forwardAction
!= 0) {
313 forwardAction
->setEnabled(index
> 0);
317 void DolphinMainWindow::updateFilterBarAction(bool show
)
319 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
320 showFilterBarAction
->setChecked(show
);
323 void DolphinMainWindow::openNewMainWindow()
325 DolphinApplication::app()->createMainWindow()->show();
328 void DolphinMainWindow::openNewTab()
330 openNewTab(m_activeViewContainer
->url());
331 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
333 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
334 if (navigator
->isUrlEditable()) {
335 // if a new tab is opened and the URL is editable, assure that
336 // the user can edit the URL without manually setting the focus
337 navigator
->setFocus();
341 void DolphinMainWindow::openNewTab(const KUrl
& url
)
343 const KIcon icon
= KIcon(KMimeType::iconNameForUrl(m_activeViewContainer
->url()));
344 if (m_viewTab
.count() == 1) {
345 // Only one view is open currently and hence no tab is shown at
346 // all. Before creating a tab for 'url', provide a tab for the current URL.
347 m_tabBar
->addTab(icon
, squeezedText(tabName(m_activeViewContainer
->url())));
348 m_tabBar
->blockSignals(false);
351 m_tabBar
->addTab(icon
, squeezedText(tabName(url
)));
354 viewTab
.splitter
= new QSplitter(this);
355 viewTab
.splitter
->setChildrenCollapsible(false);
356 viewTab
.primaryView
= new DolphinViewContainer(this, viewTab
.splitter
, url
);
357 viewTab
.primaryView
->setActive(false);
358 connectViewSignals(viewTab
.primaryView
);
359 viewTab
.primaryView
->view()->reload();
361 m_viewTab
.append(viewTab
);
363 actionCollection()->action("close_tab")->setEnabled(true);
365 // provide a split view, if the startup settings are set this way
366 const GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
367 if (generalSettings
->splitView()) {
368 const int tabIndex
= m_viewTab
.count() - 1;
369 createSecondaryView(tabIndex
);
370 m_viewTab
[tabIndex
].secondaryView
->setActive(true);
371 m_viewTab
[tabIndex
].isPrimaryViewActive
= false;
375 void DolphinMainWindow::activateNextTab()
377 if ((m_viewTab
.count() == 1) || (m_tabBar
->count() < 2)) {
381 const int tabIndex
= (m_tabBar
->currentIndex() + 1) % m_tabBar
->count();
382 m_tabBar
->setCurrentIndex(tabIndex
);
385 void DolphinMainWindow::activatePrevTab()
387 if ((m_viewTab
.count() == 1) || (m_tabBar
->count() < 2)) {
391 int tabIndex
= m_tabBar
->currentIndex() - 1;
392 if (tabIndex
== -1) {
393 tabIndex
= m_tabBar
->count() - 1;
395 m_tabBar
->setCurrentIndex(tabIndex
);
398 void DolphinMainWindow::openInNewTab()
400 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
401 if ((list
.count() == 1) && list
[0].isDir()) {
402 openNewTab(m_activeViewContainer
->view()->selectedUrls()[0]);
406 void DolphinMainWindow::openInNewWindow()
408 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
409 if ((list
.count() == 1) && list
[0].isDir()) {
410 DolphinMainWindow
* window
= DolphinApplication::app()->createMainWindow();
411 window
->changeUrl(m_activeViewContainer
->view()->selectedUrls()[0]);
416 void DolphinMainWindow::toggleActiveView()
418 if (m_viewTab
[m_tabIndex
].secondaryView
== 0) {
419 // only one view is available
423 Q_ASSERT(m_activeViewContainer
!= 0);
424 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
426 DolphinViewContainer
* left
= m_viewTab
[m_tabIndex
].primaryView
;
427 DolphinViewContainer
* right
= m_viewTab
[m_tabIndex
].secondaryView
;
428 setActiveViewContainer(m_activeViewContainer
== right
? left
: right
);
431 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
433 DolphinSettings
& settings
= DolphinSettings::instance();
434 GeneralSettings
* generalSettings
= settings
.generalSettings();
436 // Find out if Dolphin is closed directly by the user or
437 // by the session manager because the session is closed
438 bool closedByUser
= true;
439 DolphinApplication
*application
= qobject_cast
<DolphinApplication
*>(qApp
);
440 if (application
&& application
->sessionSaving()) {
441 closedByUser
= false;
444 if ((m_viewTab
.count() > 1) && generalSettings
->confirmClosingMultipleTabs() && closedByUser
) {
445 // Ask the user if he really wants to quit and close all tabs.
446 // Open a confirmation dialog with 3 buttons:
447 // KDialog::Yes -> Quit
448 // KDialog::No -> Close only the current tab
449 // KDialog::Cancel -> do nothing
450 KDialog
*dialog
= new KDialog(this, Qt::Dialog
);
451 dialog
->setCaption(i18nc("@title:window", "Confirmation"));
452 dialog
->setButtons(KDialog::Yes
| KDialog::No
| KDialog::Cancel
);
453 dialog
->setModal(true);
454 dialog
->showButtonSeparator(true);
455 dialog
->setButtonGuiItem(KDialog::Yes
, KStandardGuiItem::quit());
456 dialog
->setButtonGuiItem(KDialog::No
, KGuiItem(i18n("C&lose Current Tab"), KIcon("tab-close")));
457 dialog
->setButtonGuiItem(KDialog::Cancel
, KStandardGuiItem::cancel());
458 dialog
->setDefaultButton(KDialog::Yes
);
460 bool doNotAskAgainCheckboxResult
= false;
462 const int result
= KMessageBox::createKMessageBox(dialog
,
463 QMessageBox::Warning
,
464 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
466 i18n("Do not ask again"),
467 &doNotAskAgainCheckboxResult
,
468 KMessageBox::Notify
);
470 if (doNotAskAgainCheckboxResult
) {
471 generalSettings
->setConfirmClosingMultipleTabs(false);
479 // Close only the current tab
487 generalSettings
->setFirstRun(false);
491 KXmlGuiWindow::closeEvent(event
);
494 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
496 const int tabCount
= m_viewTab
.count();
497 group
.writeEntry("Tab Count", tabCount
);
498 group
.writeEntry("Active Tab Index", m_tabBar
->currentIndex());
500 for (int i
= 0; i
< tabCount
; ++i
) {
501 const DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
502 group
.writeEntry(tabProperty("Primary URL", i
), cont
->url().url());
503 group
.writeEntry(tabProperty("Primary Editable", i
), cont
->isUrlEditable());
505 cont
= m_viewTab
[i
].secondaryView
;
507 group
.writeEntry(tabProperty("Secondary URL", i
), cont
->url().url());
508 group
.writeEntry(tabProperty("Secondary Editable", i
), cont
->isUrlEditable());
513 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
515 const int tabCount
= group
.readEntry("Tab Count", 1);
516 for (int i
= 0; i
< tabCount
; ++i
) {
517 DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
519 cont
->setUrl(group
.readEntry(tabProperty("Primary URL", i
)));
520 const bool editable
= group
.readEntry(tabProperty("Primary Editable", i
), false);
521 cont
->urlNavigator()->setUrlEditable(editable
);
523 cont
= m_viewTab
[i
].secondaryView
;
524 const QString secondaryUrl
= group
.readEntry(tabProperty("Secondary URL", i
));
525 if (!secondaryUrl
.isEmpty()) {
527 // a secondary view should be shown, but no one is available
528 // currently -> create a new view
530 cont
= m_viewTab
[i
].secondaryView
;
534 cont
->setUrl(secondaryUrl
);
535 const bool editable
= group
.readEntry(tabProperty("Secondary Editable", i
), false);
536 cont
->urlNavigator()->setUrlEditable(editable
);
537 } else if (cont
!= 0) {
538 // no secondary view should be shown, but the default setting shows
539 // one already -> close the view
543 // openNewTab() needs to be called only tabCount - 1 times
544 if (i
!= tabCount
- 1) {
549 const int index
= group
.readEntry("Active Tab Index", 0);
550 m_tabBar
->setCurrentIndex(index
);
553 void DolphinMainWindow::updateNewMenu()
555 m_newMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->showHiddenFiles());
556 m_newMenu
->slotCheckUpToDate();
557 m_newMenu
->setPopupFiles(activeViewContainer()->url());
560 void DolphinMainWindow::createDirectory()
562 m_newMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->showHiddenFiles());
563 m_newMenu
->setPopupFiles(activeViewContainer()->url());
564 m_newMenu
->createDirectory();
567 void DolphinMainWindow::quit()
572 void DolphinMainWindow::showErrorMessage(const QString
& message
)
574 if (!message
.isEmpty()) {
575 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
576 statusBar
->setMessage(message
, DolphinStatusBar::Error
);
580 void DolphinMainWindow::slotUndoAvailable(bool available
)
582 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
583 if (undoAction
!= 0) {
584 undoAction
->setEnabled(available
);
588 void DolphinMainWindow::restoreClosedTab(QAction
* action
)
590 if (action
->data().toBool()) {
591 // clear all actions except the "Empty Recently Closed Tabs"
592 // action and the separator
593 QList
<QAction
*> actions
= m_recentTabsMenu
->menu()->actions();
594 const int count
= actions
.size();
595 for (int i
= 2; i
< count
; ++i
) {
596 m_recentTabsMenu
->menu()->removeAction(actions
.at(i
));
599 const ClosedTab closedTab
= action
->data().value
<ClosedTab
>();
600 openNewTab(closedTab
.primaryUrl
);
601 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
603 if (closedTab
.isSplit
) {
604 // create secondary view
606 m_viewTab
[m_tabIndex
].secondaryView
->setUrl(closedTab
.secondaryUrl
);
609 m_recentTabsMenu
->removeAction(action
);
612 if (m_recentTabsMenu
->menu()->actions().count() == 2) {
613 m_recentTabsMenu
->setEnabled(false);
617 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
619 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
620 if (undoAction
!= 0) {
621 undoAction
->setText(text
);
625 void DolphinMainWindow::undo()
628 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
629 KIO::FileUndoManager::self()->undo();
632 void DolphinMainWindow::cut()
634 m_activeViewContainer
->view()->cutSelectedItems();
637 void DolphinMainWindow::copy()
639 m_activeViewContainer
->view()->copySelectedItems();
642 void DolphinMainWindow::paste()
644 m_activeViewContainer
->view()->paste();
647 void DolphinMainWindow::updatePasteAction()
649 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
650 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
651 pasteAction
->setEnabled(pasteInfo
.first
);
652 pasteAction
->setText(pasteInfo
.second
);
655 void DolphinMainWindow::selectAll()
659 // if the URL navigator is editable and focused, select the whole
660 // URL instead of all items of the view
662 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
663 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit(); // krazy:exclude=qclasses
664 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
665 lineEdit
->hasFocus();
667 lineEdit
->selectAll();
669 m_activeViewContainer
->view()->selectAll();
673 void DolphinMainWindow::invertSelection()
676 m_activeViewContainer
->view()->invertSelection();
679 void DolphinMainWindow::toggleSplitView()
681 if (m_viewTab
[m_tabIndex
].secondaryView
== 0) {
682 createSecondaryView(m_tabIndex
);
683 setActiveViewContainer(m_viewTab
[m_tabIndex
].secondaryView
);
684 } else if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
685 // remove secondary view
686 m_viewTab
[m_tabIndex
].secondaryView
->close();
687 m_viewTab
[m_tabIndex
].secondaryView
->deleteLater();
688 m_viewTab
[m_tabIndex
].secondaryView
= 0;
690 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
692 // The primary view is active and should be closed. Hence from a users point of view
693 // the content of the secondary view should be moved to the primary view.
694 // From an implementation point of view it is more efficient to close
695 // the primary view and exchange the internal pointers afterwards.
697 m_viewTab
[m_tabIndex
].primaryView
->close();
698 m_viewTab
[m_tabIndex
].primaryView
->deleteLater();
699 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
700 m_viewTab
[m_tabIndex
].secondaryView
= 0;
702 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
708 void DolphinMainWindow::reloadView()
711 m_activeViewContainer
->view()->reload();
714 void DolphinMainWindow::stopLoading()
718 void DolphinMainWindow::toggleFilterBarVisibility(bool show
)
720 m_activeViewContainer
->showFilterBar(show
);
723 void DolphinMainWindow::toggleEditLocation()
727 QAction
* action
= actionCollection()->action("editable_location");
728 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
729 urlNavigator
->setUrlEditable(action
->isChecked());
732 void DolphinMainWindow::replaceLocation()
734 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
735 navigator
->setUrlEditable(true);
736 navigator
->setFocus();
738 // select the whole text of the combo box editor
739 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit(); // krazy:exclude=qclasses
740 const QString text
= lineEdit
->text();
741 lineEdit
->setSelection(0, text
.length());
744 void DolphinMainWindow::goBack()
747 m_activeViewContainer
->urlNavigator()->goBack();
750 void DolphinMainWindow::goForward()
753 m_activeViewContainer
->urlNavigator()->goForward();
756 void DolphinMainWindow::goUp()
759 m_activeViewContainer
->urlNavigator()->goUp();
762 void DolphinMainWindow::goBack(Qt::MouseButtons buttons
)
764 // The default case (left button pressed) is handled in goBack().
765 if (buttons
== Qt::MidButton
) {
766 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
767 openNewTab(urlNavigator
->historyUrl(urlNavigator
->historyIndex() + 1));
771 void DolphinMainWindow::goForward(Qt::MouseButtons buttons
)
773 // The default case (left button pressed) is handled in goForward().
774 if (buttons
== Qt::MidButton
) {
775 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
776 openNewTab(urlNavigator
->historyUrl(urlNavigator
->historyIndex() - 1));
780 void DolphinMainWindow::goUp(Qt::MouseButtons buttons
)
782 // The default case (left button pressed) is handled in goUp().
783 if (buttons
== Qt::MidButton
) {
784 openNewTab(activeViewContainer()->url().upUrl());
788 void DolphinMainWindow::goHome()
791 m_activeViewContainer
->urlNavigator()->goHome();
794 void DolphinMainWindow::compareFiles()
796 // The method is only invoked if exactly 2 files have
797 // been selected. The selected files may be:
798 // - both in the primary view
799 // - both in the secondary view
800 // - one in the primary view and the other in the secondary
802 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
806 KUrl::List urls
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedUrls();
808 switch (urls
.count()) {
810 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
!= 0);
811 urls
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedUrls();
812 Q_ASSERT(urls
.count() == 2);
820 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
!= 0);
821 urls
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedUrls();
822 Q_ASSERT(urls
.count() == 1);
834 // may not happen: compareFiles may only get invoked if 2
835 // files are selected
840 QString
command("kompare -c \"");
841 command
.append(urlA
.pathOrUrl());
842 command
.append("\" \"");
843 command
.append(urlB
.pathOrUrl());
844 command
.append('\"');
845 KRun::runCommand(command
, "Kompare", "kompare", this);
848 void DolphinMainWindow::toggleShowMenuBar()
850 const bool visible
= menuBar()->isVisible();
851 menuBar()->setVisible(!visible
);
854 void DolphinMainWindow::openTerminal()
856 QString
dir(QDir::homePath());
858 // If the given directory is not local, it can still be the URL of an
859 // ioslave using UDS_LOCAL_PATH which to be converted first.
860 KUrl url
= KIO::NetAccess::mostLocalUrl(m_activeViewContainer
->url(), this);
862 //If the URL is local after the above conversion, set the directory.
863 if (url
.isLocalFile()) {
864 dir
= url
.toLocalFile();
867 KToolInvocation::invokeTerminal(QString(), dir
);
870 void DolphinMainWindow::editSettings()
872 if (m_settingsDialog
== 0) {
873 const KUrl
& url
= activeViewContainer()->url();
874 m_settingsDialog
= new DolphinSettingsDialog(url
, this);
875 m_settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
876 m_settingsDialog
->show();
878 m_settingsDialog
->raise();
882 void DolphinMainWindow::setActiveTab(int index
)
884 Q_ASSERT(index
>= 0);
885 Q_ASSERT(index
< m_viewTab
.count());
886 if (index
== m_tabIndex
) {
890 // hide current tab content
891 ViewTab
& hiddenTab
= m_viewTab
[m_tabIndex
];
892 hiddenTab
.isPrimaryViewActive
= hiddenTab
.primaryView
->isActive();
893 hiddenTab
.primaryView
->setActive(false);
894 if (hiddenTab
.secondaryView
!= 0) {
895 hiddenTab
.secondaryView
->setActive(false);
897 QSplitter
* splitter
= m_viewTab
[m_tabIndex
].splitter
;
899 m_centralWidgetLayout
->removeWidget(splitter
);
901 // show active tab content
904 ViewTab
& viewTab
= m_viewTab
[index
];
905 m_centralWidgetLayout
->addWidget(viewTab
.splitter
, 1);
906 viewTab
.primaryView
->show();
907 if (viewTab
.secondaryView
!= 0) {
908 viewTab
.secondaryView
->show();
910 viewTab
.splitter
->show();
912 setActiveViewContainer(viewTab
.isPrimaryViewActive
? viewTab
.primaryView
:
913 viewTab
.secondaryView
);
916 void DolphinMainWindow::closeTab()
918 closeTab(m_tabBar
->currentIndex());
921 void DolphinMainWindow::closeTab(int index
)
923 Q_ASSERT(index
>= 0);
924 Q_ASSERT(index
< m_viewTab
.count());
925 if (m_viewTab
.count() == 1) {
926 // the last tab may never get closed
930 if (index
== m_tabIndex
) {
931 // The tab that should be closed is the active tab. Activate the
932 // previous tab before closing the tab.
933 m_tabBar
->setCurrentIndex((index
> 0) ? index
- 1 : 1);
935 rememberClosedTab(index
);
938 m_viewTab
[index
].primaryView
->deleteLater();
939 if (m_viewTab
[index
].secondaryView
!= 0) {
940 m_viewTab
[index
].secondaryView
->deleteLater();
942 m_viewTab
[index
].splitter
->deleteLater();
943 m_viewTab
.erase(m_viewTab
.begin() + index
);
945 m_tabBar
->blockSignals(true);
946 m_tabBar
->removeTab(index
);
948 if (m_tabIndex
> index
) {
950 Q_ASSERT(m_tabIndex
>= 0);
953 // if only one tab is left, also remove the tab entry so that
954 // closing the last tab is not possible
955 if (m_viewTab
.count() == 1) {
956 m_tabBar
->removeTab(0);
957 actionCollection()->action("close_tab")->setEnabled(false);
959 m_tabBar
->blockSignals(false);
963 void DolphinMainWindow::openTabContextMenu(int index
, const QPoint
& pos
)
967 QAction
* newTabAction
= menu
.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab"));
968 newTabAction
->setShortcut(actionCollection()->action("new_tab")->shortcut());
970 QAction
* closeOtherTabsAction
= menu
.addAction(KIcon("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs"));
972 QAction
* closeTabAction
= menu
.addAction(KIcon("tab-close"), i18nc("@action:inmenu", "Close Tab"));
973 closeTabAction
->setShortcut(actionCollection()->action("close_tab")->shortcut());
974 QAction
* selectedAction
= menu
.exec(pos
);
975 if (selectedAction
== newTabAction
) {
976 const ViewTab
& tab
= m_viewTab
[index
];
977 Q_ASSERT(tab
.primaryView
!= 0);
978 const KUrl url
= (tab
.secondaryView
!= 0) && tab
.secondaryView
->isActive() ?
979 tab
.secondaryView
->url() : tab
.primaryView
->url();
981 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
982 } else if (selectedAction
== closeOtherTabsAction
) {
983 const int count
= m_tabBar
->count();
984 for (int i
= 0; i
< index
; ++i
) {
987 for (int i
= index
+ 1; i
< count
; ++i
) {
990 } else if (selectedAction
== closeTabAction
) {
995 void DolphinMainWindow::handlePlacesClick(const KUrl
& url
, Qt::MouseButtons buttons
)
997 if (buttons
& Qt::MidButton
) {
999 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
1005 void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent
* event
, bool& canDecode
)
1007 canDecode
= KUrl::List::canDecode(event
->mimeData());
1010 void DolphinMainWindow::searchItems()
1013 const QString searchOptions
= m_searchOptionsConfigurator
->options();
1015 QString searchString
= m_searchBox
->text();
1016 if (!searchString
.isEmpty() && !searchOptions
.isEmpty()) {
1017 searchString
+= ' ' + searchOptions
;
1018 } else if (!searchOptions
.isEmpty()) {
1019 searchString
+= searchOptions
;
1022 if (!searchString
.isEmpty()) {
1023 m_activeViewContainer
->setUrl(KUrl("nepomuksearch:/" + searchString
));
1028 void DolphinMainWindow::slotTabMoved(int from
, int to
)
1030 m_viewTab
.move(from
, to
);
1031 m_tabIndex
= m_tabBar
->currentIndex();
1034 void DolphinMainWindow::showSearchOptions()
1037 m_searchOptionsConfigurator
->show();
1041 void DolphinMainWindow::init()
1043 DolphinSettings
& settings
= DolphinSettings::instance();
1045 // Check whether Dolphin runs the first time. If yes then
1046 // a proper default window size is given at the end of DolphinMainWindow::init().
1047 GeneralSettings
* generalSettings
= settings
.generalSettings();
1048 const bool firstRun
= generalSettings
->firstRun();
1050 generalSettings
->setViewPropsTimestamp(QDateTime::currentDateTime());
1053 setAcceptDrops(true);
1055 m_viewTab
[m_tabIndex
].splitter
= new QSplitter(this);
1056 m_viewTab
[m_tabIndex
].splitter
->setChildrenCollapsible(false);
1060 const KUrl
& homeUrl
= generalSettings
->homeUrl();
1061 setUrlAsCaption(homeUrl
);
1062 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
1063 connect(m_actionHandler
, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
1064 connect(m_actionHandler
, SIGNAL(createDirectory()), SLOT(createDirectory()));
1065 ViewProperties
props(homeUrl
);
1066 m_viewTab
[m_tabIndex
].primaryView
= new DolphinViewContainer(this,
1067 m_viewTab
[m_tabIndex
].splitter
,
1070 m_activeViewContainer
= m_viewTab
[m_tabIndex
].primaryView
;
1071 connectViewSignals(m_activeViewContainer
);
1072 DolphinView
* view
= m_activeViewContainer
->view();
1074 m_activeViewContainer
->show();
1075 m_actionHandler
->setCurrentView(view
);
1077 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
1078 connect(this, SIGNAL(urlChanged(const KUrl
&)),
1079 m_remoteEncoding
, SLOT(slotAboutToOpenUrl()));
1082 m_searchOptionsConfigurator
= new DolphinSearchOptionsConfigurator(this);
1083 m_searchOptionsConfigurator
->hide();
1084 connect(m_searchOptionsConfigurator
, SIGNAL(searchOptionsChanged(QString
)),
1085 this, SLOT(searchItems()));
1088 m_tabBar
= new KTabBar(this);
1089 m_tabBar
->setMovable(true);
1090 m_tabBar
->setTabsClosable(true);
1091 connect(m_tabBar
, SIGNAL(currentChanged(int)),
1092 this, SLOT(setActiveTab(int)));
1093 connect(m_tabBar
, SIGNAL(tabCloseRequested(int)),
1094 this, SLOT(closeTab(int)));
1095 connect(m_tabBar
, SIGNAL(contextMenu(int, const QPoint
&)),
1096 this, SLOT(openTabContextMenu(int, const QPoint
&)));
1097 connect(m_tabBar
, SIGNAL(newTabRequest()),
1098 this, SLOT(openNewTab()));
1099 connect(m_tabBar
, SIGNAL(testCanDecode(const QDragMoveEvent
*, bool&)),
1100 this, SLOT(slotTestCanDecode(const QDragMoveEvent
*, bool&)));
1101 connect(m_tabBar
, SIGNAL(wheelDelta(int)),
1102 this, SLOT(slotWheelMoved(int)));
1103 connect(m_tabBar
, SIGNAL(mouseMiddleClick(int)),
1104 this, SLOT(closeTab(int)));
1105 connect(m_tabBar
, SIGNAL(tabMoved(int, int)),
1106 this, SLOT(slotTabMoved(int, int)));
1108 m_tabBar
->blockSignals(true); // signals get unblocked after at least 2 tabs are open
1110 QWidget
* centralWidget
= new QWidget(this);
1111 m_centralWidgetLayout
= new QVBoxLayout(centralWidget
);
1112 m_centralWidgetLayout
->setSpacing(0);
1113 m_centralWidgetLayout
->setMargin(0);
1115 m_centralWidgetLayout
->addWidget(m_searchOptionsConfigurator
);
1117 m_centralWidgetLayout
->addWidget(m_tabBar
);
1118 m_centralWidgetLayout
->addWidget(m_viewTab
[m_tabIndex
].splitter
, 1);
1120 setCentralWidget(centralWidget
);
1122 emit
urlChanged(homeUrl
);
1124 setupGUI(Keys
| Save
| Create
| ToolBar
);
1126 m_searchBox
->setParent(toolBar("searchToolBar"));
1127 m_searchBox
->show();
1128 connect(m_searchBox
, SIGNAL(requestSearchOptions()),
1129 this, SLOT(showSearchOptions()));
1131 stateChanged("new_file");
1133 QClipboard
* clipboard
= QApplication::clipboard();
1134 connect(clipboard
, SIGNAL(dataChanged()),
1135 this, SLOT(updatePasteAction()));
1136 updatePasteAction();
1139 if (generalSettings
->splitView()) {
1142 updateViewActions();
1144 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1145 showFilterBarAction
->setChecked(generalSettings
->filterBar());
1148 // assure a proper default size if Dolphin runs the first time
1152 m_showMenuBar
->setChecked(!menuBar()->isHidden()); // workaround for bug #171080
1155 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer
* viewContainer
)
1157 Q_ASSERT(viewContainer
!= 0);
1158 Q_ASSERT((viewContainer
== m_viewTab
[m_tabIndex
].primaryView
) ||
1159 (viewContainer
== m_viewTab
[m_tabIndex
].secondaryView
));
1160 if (m_activeViewContainer
== viewContainer
) {
1164 m_activeViewContainer
->setActive(false);
1165 m_activeViewContainer
= viewContainer
;
1167 // Activating the view container might trigger a recursive setActiveViewContainer() call
1168 // inside DolphinMainWindow::toggleActiveView() when having a split view. Temporary
1169 // disconnect the activated() signal in this case:
1170 disconnect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1171 m_activeViewContainer
->setActive(true);
1172 connect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1174 m_actionHandler
->setCurrentView(viewContainer
->view());
1177 updateEditActions();
1178 updateViewActions();
1181 const KUrl
& url
= m_activeViewContainer
->url();
1182 setUrlAsCaption(url
);
1183 if (m_viewTab
.count() > 1 && m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
1184 m_tabBar
->setTabText(m_tabIndex
, tabName(url
));
1185 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(KMimeType::iconNameForUrl(url
)));
1188 emit
urlChanged(url
);
1191 void DolphinMainWindow::setupActions()
1193 // setup 'File' menu
1194 m_newMenu
= new DolphinNewMenu(this, this);
1195 KMenu
* menu
= m_newMenu
->menu();
1196 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1197 menu
->setIcon(KIcon("document-new"));
1198 connect(menu
, SIGNAL(aboutToShow()),
1199 this, SLOT(updateNewMenu()));
1201 KAction
* newWindow
= actionCollection()->addAction("new_window");
1202 newWindow
->setIcon(KIcon("window-new"));
1203 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1204 newWindow
->setShortcut(Qt::CTRL
| Qt::Key_N
);
1205 connect(newWindow
, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1207 KAction
* newTab
= actionCollection()->addAction("new_tab");
1208 newTab
->setIcon(KIcon("tab-new"));
1209 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1210 newTab
->setShortcut(KShortcut(Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
));
1211 connect(newTab
, SIGNAL(triggered()), this, SLOT(openNewTab()));
1213 KAction
* closeTab
= actionCollection()->addAction("close_tab");
1214 closeTab
->setIcon(KIcon("tab-close"));
1215 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1216 closeTab
->setShortcut(Qt::CTRL
| Qt::Key_W
);
1217 closeTab
->setEnabled(false);
1218 connect(closeTab
, SIGNAL(triggered()), this, SLOT(closeTab()));
1220 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1222 // setup 'Edit' menu
1223 KStandardAction::undo(this,
1225 actionCollection());
1227 // need to remove shift+del from cut action, else the shortcut for deletejob
1229 KAction
* cut
= KStandardAction::cut(this, SLOT(cut()), actionCollection());
1230 KShortcut cutShortcut
= cut
->shortcut();
1231 cutShortcut
.remove(Qt::SHIFT
+ Qt::Key_Delete
, KShortcut::KeepEmpty
);
1232 cut
->setShortcut(cutShortcut
);
1233 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1234 KAction
* paste
= KStandardAction::paste(this, SLOT(paste()), actionCollection());
1235 // The text of the paste-action is modified dynamically by Dolphin
1236 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1237 // due to the long text, the text "Paste" is used:
1238 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1240 KAction
* selectAll
= actionCollection()->addAction("select_all");
1241 selectAll
->setText(i18nc("@action:inmenu Edit", "Select All"));
1242 selectAll
->setShortcut(Qt::CTRL
+ Qt::Key_A
);
1243 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
1245 KAction
* invertSelection
= actionCollection()->addAction("invert_selection");
1246 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1247 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1248 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
1250 // setup 'View' menu
1251 // (note that most of it is set up in DolphinViewActionHandler)
1253 KAction
* split
= actionCollection()->addAction("split_view");
1254 split
->setShortcut(Qt::Key_F3
);
1255 updateSplitAction();
1256 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1258 KAction
* reload
= actionCollection()->addAction("reload");
1259 reload
->setText(i18nc("@action:inmenu View", "Reload"));
1260 reload
->setShortcut(Qt::Key_F5
);
1261 reload
->setIcon(KIcon("view-refresh"));
1262 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
1264 KAction
* stop
= actionCollection()->addAction("stop");
1265 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1266 stop
->setToolTip(i18nc("@info", "Stop loading"));
1267 stop
->setIcon(KIcon("process-stop"));
1268 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
1270 KToggleAction
* showFullLocation
= actionCollection()->add
<KToggleAction
>("editable_location");
1271 showFullLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1272 showFullLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
1273 connect(showFullLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1275 KAction
* replaceLocation
= actionCollection()->addAction("replace_location");
1276 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1277 replaceLocation
->setShortcut(Qt::Key_F6
);
1278 connect(replaceLocation
, SIGNAL(triggered()), this, SLOT(replaceLocation()));
1281 KAction
* backAction
= KStandardAction::back(this, SLOT(goBack()), actionCollection());
1282 connect(backAction
, SIGNAL(triggered(Qt::MouseButtons
, Qt::KeyboardModifiers
)), this, SLOT(goBack(Qt::MouseButtons
)));
1283 KShortcut backShortcut
= backAction
->shortcut();
1284 backShortcut
.setAlternate(Qt::Key_Backspace
);
1285 backAction
->setShortcut(backShortcut
);
1287 m_recentTabsMenu
= new KActionMenu(i18n("Recently Closed Tabs"), this);
1288 m_recentTabsMenu
->setIcon(KIcon("edit-undo"));
1289 actionCollection()->addAction("closed_tabs", m_recentTabsMenu
);
1290 connect(m_recentTabsMenu
->menu(), SIGNAL(triggered(QAction
*)),
1291 this, SLOT(restoreClosedTab(QAction
*)));
1293 QAction
* action
= new QAction("Empty Recently Closed Tabs", m_recentTabsMenu
);
1294 action
->setIcon(KIcon("edit-clear-list"));
1295 action
->setData(QVariant::fromValue(true));
1296 m_recentTabsMenu
->addAction(action
);
1297 m_recentTabsMenu
->addSeparator();
1298 m_recentTabsMenu
->setEnabled(false);
1300 KAction
* forwardAction
= KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1301 connect(forwardAction
, SIGNAL(triggered(Qt::MouseButtons
, Qt::KeyboardModifiers
)), this, SLOT(goForward(Qt::MouseButtons
)));
1303 KAction
* upAction
= KStandardAction::up(this, SLOT(goUp()), actionCollection());
1304 connect(upAction
, SIGNAL(triggered(Qt::MouseButtons
, Qt::KeyboardModifiers
)), this, SLOT(goUp(Qt::MouseButtons
)));
1306 KStandardAction::home(this, SLOT(goHome()), actionCollection());
1308 // setup 'Tools' menu
1309 KToggleAction
* showSearchBar
= actionCollection()->add
<KToggleAction
>("show_search_bar");
1310 showSearchBar
->setText(i18nc("@action:inmenu Tools", "Show Search Bar"));
1311 showSearchBar
->setShortcut(Qt::CTRL
| Qt::Key_S
);
1312 connect(showSearchBar
, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
1314 KToggleAction
* showFilterBar
= actionCollection()->add
<KToggleAction
>("show_filter_bar");
1315 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1316 showFilterBar
->setIcon(KIcon("view-filter"));
1317 showFilterBar
->setShortcut(Qt::CTRL
| Qt::Key_I
);
1318 connect(showFilterBar
, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
1320 KAction
* compareFiles
= actionCollection()->addAction("compare_files");
1321 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1322 compareFiles
->setIcon(KIcon("kompare"));
1323 compareFiles
->setEnabled(false);
1324 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
1326 KAction
* openTerminal
= actionCollection()->addAction("open_terminal");
1327 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1328 openTerminal
->setIcon(KIcon("utilities-terminal"));
1329 openTerminal
->setShortcut(Qt::SHIFT
| Qt::Key_F4
);
1330 connect(openTerminal
, SIGNAL(triggered()), this, SLOT(openTerminal()));
1332 // setup 'Settings' menu
1333 m_showMenuBar
= KStandardAction::showMenubar(this, SLOT(toggleShowMenuBar()), actionCollection());
1334 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1336 // not in menu actions
1337 KAction
* activateNextTab
= actionCollection()->addAction("activate_next_tab");
1338 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1339 connect(activateNextTab
, SIGNAL(triggered()), SLOT(activateNextTab()));
1340 activateNextTab
->setShortcuts(QApplication::isRightToLeft() ? KStandardShortcut::tabPrev() :
1341 KStandardShortcut::tabNext());
1343 KAction
* activatePrevTab
= actionCollection()->addAction("activate_prev_tab");
1344 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1345 connect(activatePrevTab
, SIGNAL(triggered()), SLOT(activatePrevTab()));
1346 activatePrevTab
->setShortcuts(QApplication::isRightToLeft() ? KStandardShortcut::tabNext() :
1347 KStandardShortcut::tabPrev());
1350 KAction
* openInNewTab
= actionCollection()->addAction("open_in_new_tab");
1351 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1352 openInNewTab
->setIcon(KIcon("tab-new"));
1353 connect(openInNewTab
, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1355 KAction
* openInNewWindow
= actionCollection()->addAction("open_in_new_window");
1356 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1357 openInNewWindow
->setIcon(KIcon("window-new"));
1358 connect(openInNewWindow
, SIGNAL(triggered()), this, SLOT(openInNewWindow()));
1361 m_searchBox
= new DolphinSearchBox(this);
1362 connect(m_searchBox
, SIGNAL(search(QString
)), this, SLOT(searchItems()));
1364 KAction
* search
= new KAction(this);
1365 actionCollection()->addAction("search_bar", search
);
1366 search
->setText(i18nc("@action:inmenu", "Search Bar"));
1367 search
->setDefaultWidget(m_searchBox
);
1368 search
->setShortcutConfigurable(false);
1371 void DolphinMainWindow::setupDockWidgets()
1373 // setup "Information"
1374 QDockWidget
* infoDock
= new QDockWidget(i18nc("@title:window", "Information"));
1375 infoDock
->setObjectName("infoDock");
1376 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1377 Panel
* infoPanel
= new InformationPanel(infoDock
);
1378 infoDock
->setWidget(infoPanel
);
1380 QAction
* infoAction
= infoDock
->toggleViewAction();
1381 infoAction
->setText(i18nc("@title:window", "Information"));
1382 infoAction
->setShortcut(Qt::Key_F11
);
1383 infoAction
->setIcon(KIcon("dialog-information"));
1384 actionCollection()->addAction("show_info_panel", infoDock
->toggleViewAction());
1386 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1387 connect(this, SIGNAL(urlChanged(KUrl
)),
1388 infoPanel
, SLOT(setUrl(KUrl
)));
1389 connect(this, SIGNAL(selectionChanged(KFileItemList
)),
1390 infoPanel
, SLOT(setSelection(KFileItemList
)));
1391 connect(this, SIGNAL(requestItemInfo(KFileItem
)),
1392 infoPanel
, SLOT(requestDelayedItemInfo(KFileItem
)));
1395 QDockWidget
* foldersDock
= new QDockWidget(i18nc("@title:window", "Folders"));
1396 foldersDock
->setObjectName("foldersDock");
1397 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1398 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1399 foldersDock
->setWidget(foldersPanel
);
1401 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1402 foldersAction
->setText(i18nc("@title:window", "Folders"));
1403 foldersAction
->setShortcut(Qt::Key_F7
);
1404 foldersAction
->setIcon(KIcon("folder"));
1405 actionCollection()->addAction("show_folders_panel", foldersDock
->toggleViewAction());
1407 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1408 connect(this, SIGNAL(urlChanged(KUrl
)),
1409 foldersPanel
, SLOT(setUrl(KUrl
)));
1410 connect(foldersPanel
, SIGNAL(changeUrl(KUrl
, Qt::MouseButtons
)),
1411 this, SLOT(handlePlacesClick(KUrl
, Qt::MouseButtons
)));
1412 connect(foldersPanel
, SIGNAL(changeSelection(KFileItemList
)),
1413 this, SLOT(changeSelection(KFileItemList
)));
1417 QDockWidget
* terminalDock
= new QDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1418 terminalDock
->setObjectName("terminalDock");
1419 terminalDock
->setAllowedAreas(Qt::TopDockWidgetArea
| Qt::BottomDockWidgetArea
);
1420 Panel
* terminalPanel
= new TerminalPanel(terminalDock
);
1421 terminalDock
->setWidget(terminalPanel
);
1423 connect(terminalPanel
, SIGNAL(hideTerminalPanel()), terminalDock
, SLOT(hide()));
1425 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1426 terminalAction
->setText(i18nc("@title:window Shell terminal", "Terminal"));
1427 terminalAction
->setShortcut(Qt::Key_F4
);
1428 terminalAction
->setIcon(KIcon("utilities-terminal"));
1429 actionCollection()->addAction("show_terminal_panel", terminalDock
->toggleViewAction());
1431 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1432 connect(this, SIGNAL(urlChanged(KUrl
)),
1433 terminalPanel
, SLOT(setUrl(KUrl
)));
1436 const bool firstRun
= DolphinSettings::instance().generalSettings()->firstRun();
1438 foldersDock
->hide();
1440 terminalDock
->hide();
1444 QDockWidget
* placesDock
= new QDockWidget(i18nc("@title:window", "Places"));
1445 placesDock
->setObjectName("placesDock");
1446 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1448 PlacesPanel
* placesPanel
= new PlacesPanel(placesDock
);
1449 placesDock
->setWidget(placesPanel
);
1450 placesPanel
->setModel(DolphinSettings::instance().placesModel());
1451 placesPanel
->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff
);
1453 QAction
* placesAction
= placesDock
->toggleViewAction();
1454 placesAction
->setText(i18nc("@title:window", "Places"));
1455 placesAction
->setShortcut(Qt::Key_F9
);
1456 placesAction
->setIcon(KIcon("bookmarks"));
1457 actionCollection()->addAction("show_places_panel", placesDock
->toggleViewAction());
1459 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1460 connect(placesPanel
, SIGNAL(urlChanged(KUrl
, Qt::MouseButtons
)),
1461 this, SLOT(handlePlacesClick(KUrl
, Qt::MouseButtons
)));
1462 connect(this, SIGNAL(urlChanged(KUrl
)),
1463 placesPanel
, SLOT(setUrl(KUrl
)));
1466 void DolphinMainWindow::updateEditActions()
1468 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1469 if (list
.isEmpty()) {
1470 stateChanged("has_no_selection");
1472 stateChanged("has_selection");
1474 KActionCollection
* col
= actionCollection();
1475 QAction
* renameAction
= col
->action("rename");
1476 QAction
* moveToTrashAction
= col
->action("move_to_trash");
1477 QAction
* deleteAction
= col
->action("delete");
1478 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
1479 QAction
* deleteWithTrashShortcut
= col
->action("delete_shortcut"); // see DolphinViewActionHandler
1481 KFileItemListProperties
capabilities(list
);
1482 const bool enableMoveToTrash
= capabilities
.isLocal() && capabilities
.supportsMoving();
1484 renameAction
->setEnabled(capabilities
.supportsMoving());
1485 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1486 deleteAction
->setEnabled(capabilities
.supportsDeleting());
1487 deleteWithTrashShortcut
->setEnabled(capabilities
.supportsDeleting() && !enableMoveToTrash
);
1488 cutAction
->setEnabled(capabilities
.supportsMoving());
1490 updatePasteAction();
1493 void DolphinMainWindow::updateViewActions()
1495 m_actionHandler
->updateViewActions();
1497 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1498 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
1500 updateSplitAction();
1502 QAction
* editableLocactionAction
= actionCollection()->action("editable_location");
1503 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
1504 editableLocactionAction
->setChecked(urlNavigator
->isUrlEditable());
1507 void DolphinMainWindow::updateGoActions()
1509 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
1510 const KUrl
& currentUrl
= m_activeViewContainer
->url();
1511 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
1514 void DolphinMainWindow::rememberClosedTab(int index
)
1516 KMenu
* tabsMenu
= m_recentTabsMenu
->menu();
1518 const QString primaryPath
= m_viewTab
[index
].primaryView
->url().path();
1519 const QString iconName
= KMimeType::iconNameForUrl(primaryPath
);
1521 QAction
* action
= new QAction(squeezedText(primaryPath
), tabsMenu
);
1523 ClosedTab closedTab
;
1524 closedTab
.primaryUrl
= m_viewTab
[index
].primaryView
->url();
1526 if (m_viewTab
[index
].secondaryView
!= 0) {
1527 closedTab
.secondaryUrl
= m_viewTab
[index
].secondaryView
->url();
1528 closedTab
.isSplit
= true;
1530 closedTab
.isSplit
= false;
1533 action
->setData(QVariant::fromValue(closedTab
));
1534 action
->setIcon(KIcon(iconName
));
1536 // add the closed tab menu entry after the separator and
1537 // "Empty Recently Closed Tabs" entry
1538 if (tabsMenu
->actions().size() == 2) {
1539 tabsMenu
->addAction(action
);
1541 tabsMenu
->insertAction(tabsMenu
->actions().at(2), action
);
1544 // assure that only up to 8 closed tabs are shown in the menu
1545 if (tabsMenu
->actions().size() > 8) {
1546 tabsMenu
->removeAction(tabsMenu
->actions().last());
1548 actionCollection()->action("closed_tabs")->setEnabled(true);
1549 KAcceleratorManager::manage(tabsMenu
);
1552 void DolphinMainWindow::clearStatusBar()
1554 m_activeViewContainer
->statusBar()->clear();
1557 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
1559 connect(container
, SIGNAL(showFilterBarChanged(bool)),
1560 this, SLOT(updateFilterBarAction(bool)));
1562 DolphinView
* view
= container
->view();
1563 connect(view
, SIGNAL(selectionChanged(KFileItemList
)),
1564 this, SLOT(slotSelectionChanged(KFileItemList
)));
1565 connect(view
, SIGNAL(requestItemInfo(KFileItem
)),
1566 this, SLOT(slotRequestItemInfo(KFileItem
)));
1567 connect(view
, SIGNAL(activated()),
1568 this, SLOT(toggleActiveView()));
1569 connect(view
, SIGNAL(tabRequested(const KUrl
&)),
1570 this, SLOT(openNewTab(const KUrl
&)));
1572 const KUrlNavigator
* navigator
= container
->urlNavigator();
1573 connect(navigator
, SIGNAL(urlChanged(const KUrl
&)),
1574 this, SLOT(changeUrl(const KUrl
&)));
1575 connect(navigator
, SIGNAL(historyChanged()),
1576 this, SLOT(updateHistory()));
1577 connect(navigator
, SIGNAL(editableStateChanged(bool)),
1578 this, SLOT(slotEditableStateChanged(bool)));
1581 void DolphinMainWindow::updateSplitAction()
1583 QAction
* splitAction
= actionCollection()->action("split_view");
1584 if (m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
1585 if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
1586 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
1587 splitAction
->setToolTip(i18nc("@info", "Close right view"));
1588 splitAction
->setIcon(KIcon("view-right-close"));
1590 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
1591 splitAction
->setToolTip(i18nc("@info", "Close left view"));
1592 splitAction
->setIcon(KIcon("view-left-close"));
1595 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
1596 splitAction
->setToolTip(i18nc("@info", "Split view"));
1597 splitAction
->setIcon(KIcon("view-right-new"));
1601 QString
DolphinMainWindow::tabName(const KUrl
& url
) const
1604 if (url
.equals(KUrl("file:///"))) {
1607 name
= url
.fileName();
1608 if (name
.isEmpty()) {
1609 name
= url
.protocol();
1611 // Make sure that a '&' inside the directory name is displayed correctly
1612 // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
1613 name
.replace('&', "&&");
1619 bool DolphinMainWindow::isKompareInstalled() const
1621 static bool initialized
= false;
1622 static bool installed
= false;
1624 // TODO: maybe replace this approach later by using a menu
1625 // plugin like kdiff3plugin.cpp
1626 installed
= !KGlobal::dirs()->findExe("kompare").isEmpty();
1632 void DolphinMainWindow::createSecondaryView(int tabIndex
)
1634 QSplitter
* splitter
= m_viewTab
[tabIndex
].splitter
;
1635 const int newWidth
= (m_viewTab
[tabIndex
].primaryView
->width() - splitter
->handleWidth()) / 2;
1637 const DolphinView
* view
= m_viewTab
[tabIndex
].primaryView
->view();
1638 m_viewTab
[tabIndex
].secondaryView
= new DolphinViewContainer(this, 0, view
->rootUrl());
1639 splitter
->addWidget(m_viewTab
[tabIndex
].secondaryView
);
1640 splitter
->setSizes(QList
<int>() << newWidth
<< newWidth
);
1641 connectViewSignals(m_viewTab
[tabIndex
].secondaryView
);
1642 m_viewTab
[tabIndex
].secondaryView
->view()->reload();
1643 m_viewTab
[tabIndex
].secondaryView
->setActive(false);
1644 m_viewTab
[tabIndex
].secondaryView
->show();
1647 QString
DolphinMainWindow::tabProperty(const QString
& property
, int tabIndex
) const
1649 return "Tab " + QString::number(tabIndex
) + ' ' + property
;
1652 void DolphinMainWindow::setUrlAsCaption(const KUrl
& url
)
1655 if (url
.equals(KUrl("file:///"))) {
1658 caption
= url
.fileName();
1659 if (caption
.isEmpty()) {
1660 caption
= url
.protocol();
1664 setCaption(caption
);
1667 QString
DolphinMainWindow::squeezedText(const QString
& text
) const
1669 const QFontMetrics fm
= fontMetrics();
1670 return fm
.elidedText(text
, Qt::ElideMiddle
, fm
.maxWidth() * 10);
1673 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
1674 KIO::FileUndoManager::UiInterface()
1678 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
1682 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
1684 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
1686 DolphinStatusBar
* statusBar
= mainWin
->activeViewContainer()->statusBar();
1687 statusBar
->setMessage(job
->errorString(), DolphinStatusBar::Error
);
1689 KIO::FileUndoManager::UiInterface::jobError(job
);
1693 #include "dolphinmainwindow.moc"