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 "dolphinapplication.h"
29 #include "dolphinnewmenu.h"
30 #include "search/dolphinsearchbox.h"
31 #include "search/dolphinsearchoptionsconfigurator.h"
32 #include "settings/dolphinsettings.h"
33 #include "settings/dolphinsettingsdialog.h"
34 #include "dolphinviewcontainer.h"
35 #include "panels/folders/folderspanel.h"
36 #include "panels/places/placespanel.h"
37 #include "panels/information/informationpanel.h"
38 #include "mainwindowadaptor.h"
39 #include "statusbar/dolphinstatusbar.h"
40 #include "viewproperties.h"
43 #include "panels/terminal/terminalpanel.h"
46 #include "dolphin_generalsettings.h"
47 #include "dolphin_iconsmodesettings.h"
48 #include "draganddrophelper.h"
51 #include <kactioncollection.h>
53 #include <kdesktopfile.h>
54 #include <kdeversion.h>
55 #include <kfiledialog.h>
56 #include <kfileplacesmodel.h>
58 #include <klineedit.h>
61 #include <kiconloader.h>
62 #include <kio/netaccess.h>
63 #include <kinputdialog.h>
65 #include <kprotocolmanager.h>
68 #include <kmessagebox.h>
69 #include <kfileitemlistproperties.h>
70 #include <konqmimedata.h>
71 #include <kprotocolinfo.h>
74 #include <kstandarddirs.h>
75 #include <kstatusbar.h>
76 #include <kstandardaction.h>
78 #include <ktoggleaction.h>
79 #include <kurlnavigator.h>
81 #include <kurlcombobox.h>
82 #include <ktoolinvocation.h>
84 #include <QDBusMessage>
88 #include <QDockWidget>
89 #include <kacceleratormanager.h>
92 * Remembers the tab configuration if a tab has been closed.
93 * Each closed tab can be restored by the menu
94 * "Go -> Recently Closed Tabs".
102 Q_DECLARE_METATYPE(ClosedTab
)
104 DolphinMainWindow::DolphinMainWindow(int id
) :
109 m_activeViewContainer(0),
110 m_centralWidgetLayout(0),
112 m_searchOptionsConfigurator(0),
120 setObjectName("Dolphin#");
122 m_viewTab
.append(ViewTab());
124 new MainWindowAdaptor(this);
125 QDBusConnection::sessionBus().registerObject(QString("/dolphin/MainWindow%1").arg(m_id
), this);
127 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
128 undoManager
->setUiInterface(new UndoUiInterface());
130 connect(undoManager
, SIGNAL(undoAvailable(bool)),
131 this, SLOT(slotUndoAvailable(bool)));
132 connect(undoManager
, SIGNAL(undoTextChanged(const QString
&)),
133 this, SLOT(slotUndoTextChanged(const QString
&)));
134 connect(undoManager
, SIGNAL(jobRecordingStarted(CommandType
)),
135 this, SLOT(clearStatusBar()));
136 connect(undoManager
, SIGNAL(jobRecordingFinished(CommandType
)),
137 this, SLOT(showCommand(CommandType
)));
138 connect(DolphinSettings::instance().placesModel(), SIGNAL(errorMessage(const QString
&)),
139 this, SLOT(showErrorMessage(const QString
&)));
140 connect(&DragAndDropHelper::instance(), SIGNAL(errorMessage(const QString
&)),
141 this, SLOT(showErrorMessage(const QString
&)));
144 DolphinMainWindow::~DolphinMainWindow()
146 DolphinApplication::app()->removeMainWindow(this);
149 void DolphinMainWindow::toggleViews()
151 if (m_viewTab
[m_tabIndex
].primaryView
== 0) {
155 // move secondary view from the last position of the splitter
156 // to the first position
157 m_viewTab
[m_tabIndex
].splitter
->insertWidget(0, m_viewTab
[m_tabIndex
].secondaryView
);
159 DolphinViewContainer
* container
= m_viewTab
[m_tabIndex
].primaryView
;
160 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
161 m_viewTab
[m_tabIndex
].secondaryView
= container
;
164 void DolphinMainWindow::showCommand(CommandType command
)
166 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
168 case KIO::FileUndoManager::Copy
:
169 statusBar
->setMessage(i18nc("@info:status", "Successfully copied."),
170 DolphinStatusBar::OperationCompleted
);
172 case KIO::FileUndoManager::Move
:
173 statusBar
->setMessage(i18nc("@info:status", "Successfully moved."),
174 DolphinStatusBar::OperationCompleted
);
176 case KIO::FileUndoManager::Link
:
177 statusBar
->setMessage(i18nc("@info:status", "Successfully linked."),
178 DolphinStatusBar::OperationCompleted
);
180 case KIO::FileUndoManager::Trash
:
181 statusBar
->setMessage(i18nc("@info:status", "Successfully moved to trash."),
182 DolphinStatusBar::OperationCompleted
);
184 case KIO::FileUndoManager::Rename
:
185 statusBar
->setMessage(i18nc("@info:status", "Successfully renamed."),
186 DolphinStatusBar::OperationCompleted
);
189 case KIO::FileUndoManager::Mkdir
:
190 statusBar
->setMessage(i18nc("@info:status", "Created folder."),
191 DolphinStatusBar::OperationCompleted
);
199 void DolphinMainWindow::refreshViews()
201 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
203 // remember the current active view, as because of
204 // the refreshing the active view might change to
205 // the secondary view
206 DolphinViewContainer
* activeViewContainer
= m_activeViewContainer
;
208 const int tabCount
= m_viewTab
.count();
209 for (int i
= 0; i
< tabCount
; ++i
) {
210 m_viewTab
[i
].primaryView
->refresh();
211 if (m_viewTab
[i
].secondaryView
!= 0) {
212 m_viewTab
[i
].secondaryView
->refresh();
216 setActiveViewContainer(activeViewContainer
);
219 void DolphinMainWindow::pasteIntoFolder()
221 m_activeViewContainer
->view()->pasteIntoFolder();
224 void DolphinMainWindow::changeUrl(const KUrl
& url
)
226 if (!KProtocolManager::supportsListing(url
)) {
227 // The URL navigator only checks for validity, not
228 // if the URL can be listed. An error message is
229 // shown due to DolphinViewContainer::restoreView().
233 DolphinViewContainer
* view
= activeViewContainer();
239 setUrlAsCaption(url
);
240 if (m_viewTab
.count() > 1) {
241 m_tabBar
->setTabText(m_tabIndex
, squeezedText(tabName(m_activeViewContainer
->url())));
243 const QString iconName
= KMimeType::iconNameForUrl(url
);
244 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(iconName
));
245 emit
urlChanged(url
);
249 void DolphinMainWindow::changeSelection(const KFileItemList
& selection
)
251 activeViewContainer()->view()->changeSelection(selection
);
254 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
256 KToggleAction
* editableLocationAction
=
257 static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
258 editableLocationAction
->setChecked(editable
);
261 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
265 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
266 int selectedUrlsCount
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedItemsCount();
267 if (m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
268 selectedUrlsCount
+= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItemsCount();
271 QAction
* compareFilesAction
= actionCollection()->action("compare_files");
272 if (selectedUrlsCount
== 2) {
273 compareFilesAction
->setEnabled(isKompareInstalled());
275 compareFilesAction
->setEnabled(false);
278 emit
selectionChanged(selection
);
281 void DolphinMainWindow::slotWheelMoved(int wheelDelta
)
283 if (wheelDelta
> 0) {
290 void DolphinMainWindow::slotRequestItemInfo(const KFileItem
& item
)
292 emit
requestItemInfo(item
);
295 void DolphinMainWindow::updateHistory()
297 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
298 const int index
= urlNavigator
->historyIndex();
300 QAction
* backAction
= actionCollection()->action("go_back");
301 backAction
->setToolTip(i18nc("@info", "Go back"));
302 if (backAction
!= 0) {
303 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
306 QAction
* forwardAction
= actionCollection()->action("go_forward");
307 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
308 if (forwardAction
!= 0) {
309 forwardAction
->setEnabled(index
> 0);
313 void DolphinMainWindow::updateFilterBarAction(bool show
)
315 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
316 showFilterBarAction
->setChecked(show
);
319 void DolphinMainWindow::openNewMainWindow()
321 DolphinApplication::app()->createMainWindow()->show();
324 void DolphinMainWindow::openNewTab()
326 openNewTab(m_activeViewContainer
->url());
327 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
329 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
330 if (navigator
->isUrlEditable()) {
331 // if a new tab is opened and the URL is editable, assure that
332 // the user can edit the URL without manually setting the focus
333 navigator
->setFocus();
337 void DolphinMainWindow::openNewTab(const KUrl
& url
)
339 const KIcon icon
= KIcon(KMimeType::iconNameForUrl(m_activeViewContainer
->url()));
340 if (m_viewTab
.count() == 1) {
341 // Only one view is open currently and hence no tab is shown at
342 // all. Before creating a tab for 'url', provide a tab for the current URL.
343 m_tabBar
->addTab(icon
, squeezedText(tabName(m_activeViewContainer
->url())));
344 m_tabBar
->blockSignals(false);
347 m_tabBar
->addTab(icon
, squeezedText(tabName(url
)));
350 viewTab
.splitter
= new QSplitter(this);
351 viewTab
.splitter
->setChildrenCollapsible(false);
352 viewTab
.primaryView
= new DolphinViewContainer(this, viewTab
.splitter
, url
);
353 viewTab
.primaryView
->setActive(false);
354 connectViewSignals(viewTab
.primaryView
);
355 viewTab
.primaryView
->view()->reload();
357 m_viewTab
.append(viewTab
);
359 actionCollection()->action("close_tab")->setEnabled(true);
361 // provide a split view, if the startup settings are set this way
362 const GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
363 if (generalSettings
->splitView()) {
364 const int tabIndex
= m_viewTab
.count() - 1;
365 createSecondaryView(tabIndex
);
366 m_viewTab
[tabIndex
].secondaryView
->setActive(true);
367 m_viewTab
[tabIndex
].isPrimaryViewActive
= false;
371 void DolphinMainWindow::activateNextTab()
373 if ((m_viewTab
.count() == 1) || (m_tabBar
->count() < 2)) {
377 const int tabIndex
= (m_tabBar
->currentIndex() + 1) % m_tabBar
->count();
378 m_tabBar
->setCurrentIndex(tabIndex
);
381 void DolphinMainWindow::activatePrevTab()
383 if ((m_viewTab
.count() == 1) || (m_tabBar
->count() < 2)) {
387 int tabIndex
= m_tabBar
->currentIndex() - 1;
388 if (tabIndex
== -1) {
389 tabIndex
= m_tabBar
->count() - 1;
391 m_tabBar
->setCurrentIndex(tabIndex
);
394 void DolphinMainWindow::openInNewTab()
396 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
397 if ((list
.count() == 1) && list
[0].isDir()) {
398 openNewTab(m_activeViewContainer
->view()->selectedUrls()[0]);
402 void DolphinMainWindow::openInNewWindow()
404 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
405 if ((list
.count() == 1) && list
[0].isDir()) {
406 DolphinMainWindow
* window
= DolphinApplication::app()->createMainWindow();
407 window
->changeUrl(m_activeViewContainer
->view()->selectedUrls()[0]);
412 void DolphinMainWindow::toggleActiveView()
414 if (m_viewTab
[m_tabIndex
].secondaryView
== 0) {
415 // only one view is available
419 Q_ASSERT(m_activeViewContainer
!= 0);
420 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
422 DolphinViewContainer
* left
= m_viewTab
[m_tabIndex
].primaryView
;
423 DolphinViewContainer
* right
= m_viewTab
[m_tabIndex
].secondaryView
;
424 setActiveViewContainer(m_activeViewContainer
== right
? left
: right
);
427 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
429 DolphinSettings
& settings
= DolphinSettings::instance();
430 GeneralSettings
* generalSettings
= settings
.generalSettings();
432 // Find out if Dolphin is closed directly by the user or
433 // by the session manager because the session is closed
434 bool closedByUser
= true;
435 DolphinApplication
*application
= qobject_cast
<DolphinApplication
*>(qApp
);
436 if (application
&& application
->sessionSaving()) {
437 closedByUser
= false;
440 if ((m_viewTab
.count() > 1) && generalSettings
->confirmClosingMultipleTabs() && closedByUser
) {
441 // Ask the user if he really wants to quit and close all tabs.
442 // Open a confirmation dialog with 3 buttons:
443 // KDialog::Yes -> Quit
444 // KDialog::No -> Close only the current tab
445 // KDialog::Cancel -> do nothing
446 KDialog
*dialog
= new KDialog(this, Qt::Dialog
);
447 dialog
->setCaption(i18nc("@title:window", "Confirmation"));
448 dialog
->setButtons(KDialog::Yes
| KDialog::No
| KDialog::Cancel
);
449 dialog
->setModal(true);
450 dialog
->showButtonSeparator(true);
451 dialog
->setButtonGuiItem(KDialog::Yes
, KStandardGuiItem::quit());
452 dialog
->setButtonGuiItem(KDialog::No
, KGuiItem(i18n("C&lose Current Tab"), KIcon("tab-close")));
453 dialog
->setButtonGuiItem(KDialog::Cancel
, KStandardGuiItem::cancel());
454 dialog
->setDefaultButton(KDialog::Yes
);
456 bool doNotAskAgainCheckboxResult
= false;
458 const int result
= KMessageBox::createKMessageBox(dialog
,
459 QMessageBox::Warning
,
460 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
462 i18n("Do not ask again"),
463 &doNotAskAgainCheckboxResult
,
464 KMessageBox::Notify
);
466 if (doNotAskAgainCheckboxResult
) {
467 generalSettings
->setConfirmClosingMultipleTabs(false);
475 // Close only the current tab
483 generalSettings
->setFirstRun(false);
487 KXmlGuiWindow::closeEvent(event
);
490 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
492 const int tabCount
= m_viewTab
.count();
493 group
.writeEntry("Tab Count", tabCount
);
494 group
.writeEntry("Active Tab Index", m_tabBar
->currentIndex());
496 for (int i
= 0; i
< tabCount
; ++i
) {
497 const DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
498 group
.writeEntry(tabProperty("Primary URL", i
), cont
->url().url());
499 group
.writeEntry(tabProperty("Primary Editable", i
), cont
->isUrlEditable());
501 cont
= m_viewTab
[i
].secondaryView
;
503 group
.writeEntry(tabProperty("Secondary URL", i
), cont
->url().url());
504 group
.writeEntry(tabProperty("Secondary Editable", i
), cont
->isUrlEditable());
509 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
511 const int tabCount
= group
.readEntry("Tab Count", 1);
512 for (int i
= 0; i
< tabCount
; ++i
) {
513 DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
515 cont
->setUrl(group
.readEntry(tabProperty("Primary URL", i
)));
516 const bool editable
= group
.readEntry(tabProperty("Primary Editable", i
), false);
517 cont
->urlNavigator()->setUrlEditable(editable
);
519 cont
= m_viewTab
[i
].secondaryView
;
520 const QString secondaryUrl
= group
.readEntry(tabProperty("Secondary URL", i
));
521 if (!secondaryUrl
.isEmpty()) {
523 // a secondary view should be shown, but no one is available
524 // currently -> create a new view
526 cont
= m_viewTab
[i
].secondaryView
;
530 cont
->setUrl(secondaryUrl
);
531 const bool editable
= group
.readEntry(tabProperty("Secondary Editable", i
), false);
532 cont
->urlNavigator()->setUrlEditable(editable
);
533 } else if (cont
!= 0) {
534 // no secondary view should be shown, but the default setting shows
535 // one already -> close the view
539 // openNewTab() needs to be called only tabCount - 1 times
540 if (i
!= tabCount
- 1) {
545 const int index
= group
.readEntry("Active Tab Index", 0);
546 m_tabBar
->setCurrentIndex(index
);
549 void DolphinMainWindow::updateNewMenu()
551 m_newMenu
->slotCheckUpToDate();
552 m_newMenu
->setPopupFiles(activeViewContainer()->url());
555 void DolphinMainWindow::createDirectory()
557 m_newMenu
->setPopupFiles(activeViewContainer()->url());
558 m_newMenu
->createDirectory();
561 void DolphinMainWindow::quit()
566 void DolphinMainWindow::showErrorMessage(const QString
& message
)
568 if (!message
.isEmpty()) {
569 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
570 statusBar
->setMessage(message
, DolphinStatusBar::Error
);
574 void DolphinMainWindow::slotUndoAvailable(bool available
)
576 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
577 if (undoAction
!= 0) {
578 undoAction
->setEnabled(available
);
582 void DolphinMainWindow::restoreClosedTab(QAction
* action
)
584 if (action
->data().toBool()) {
585 // clear all actions except the "Empty Recently Closed Tabs"
586 // action and the separator
587 QList
<QAction
*> actions
= m_recentTabsMenu
->menu()->actions();
588 const int count
= actions
.size();
589 for (int i
= 2; i
< count
; ++i
) {
590 m_recentTabsMenu
->menu()->removeAction(actions
.at(i
));
593 const ClosedTab closedTab
= action
->data().value
<ClosedTab
>();
594 openNewTab(closedTab
.primaryUrl
);
595 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
597 if (closedTab
.isSplit
) {
598 // create secondary view
600 m_viewTab
[m_tabIndex
].secondaryView
->setUrl(closedTab
.secondaryUrl
);
603 m_recentTabsMenu
->removeAction(action
);
606 if (m_recentTabsMenu
->menu()->actions().count() == 2) {
607 m_recentTabsMenu
->setEnabled(false);
611 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
613 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
614 if (undoAction
!= 0) {
615 undoAction
->setText(text
);
619 void DolphinMainWindow::undo()
622 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
623 KIO::FileUndoManager::self()->undo();
626 void DolphinMainWindow::cut()
628 m_activeViewContainer
->view()->cutSelectedItems();
631 void DolphinMainWindow::copy()
633 m_activeViewContainer
->view()->copySelectedItems();
636 void DolphinMainWindow::paste()
638 m_activeViewContainer
->view()->paste();
641 void DolphinMainWindow::updatePasteAction()
643 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
644 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
645 pasteAction
->setEnabled(pasteInfo
.first
);
646 pasteAction
->setText(pasteInfo
.second
);
649 void DolphinMainWindow::selectAll()
653 // if the URL navigator is editable and focused, select the whole
654 // URL instead of all items of the view
656 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
657 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit(); // krazy:exclude=qclasses
658 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
659 lineEdit
->hasFocus();
661 lineEdit
->selectAll();
663 m_activeViewContainer
->view()->selectAll();
667 void DolphinMainWindow::invertSelection()
670 m_activeViewContainer
->view()->invertSelection();
673 void DolphinMainWindow::toggleSplitView()
675 if (m_viewTab
[m_tabIndex
].secondaryView
== 0) {
676 createSecondaryView(m_tabIndex
);
677 setActiveViewContainer(m_viewTab
[m_tabIndex
].secondaryView
);
678 } else if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
679 // remove secondary view
680 m_viewTab
[m_tabIndex
].secondaryView
->close();
681 m_viewTab
[m_tabIndex
].secondaryView
->deleteLater();
682 m_viewTab
[m_tabIndex
].secondaryView
= 0;
684 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
686 // The primary view is active and should be closed. Hence from a users point of view
687 // the content of the secondary view should be moved to the primary view.
688 // From an implementation point of view it is more efficient to close
689 // the primary view and exchange the internal pointers afterwards.
691 m_viewTab
[m_tabIndex
].primaryView
->close();
692 m_viewTab
[m_tabIndex
].primaryView
->deleteLater();
693 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
694 m_viewTab
[m_tabIndex
].secondaryView
= 0;
696 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
702 void DolphinMainWindow::reloadView()
705 m_activeViewContainer
->view()->reload();
708 void DolphinMainWindow::stopLoading()
712 void DolphinMainWindow::toggleFilterBarVisibility(bool show
)
714 m_activeViewContainer
->showFilterBar(show
);
717 void DolphinMainWindow::toggleEditLocation()
721 QAction
* action
= actionCollection()->action("editable_location");
722 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
723 urlNavigator
->setUrlEditable(action
->isChecked());
726 void DolphinMainWindow::replaceLocation()
728 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
729 navigator
->setUrlEditable(true);
730 navigator
->setFocus();
732 // select the whole text of the combo box editor
733 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit(); // krazy:exclude=qclasses
734 const QString text
= lineEdit
->text();
735 lineEdit
->setSelection(0, text
.length());
738 void DolphinMainWindow::goBack()
741 m_activeViewContainer
->urlNavigator()->goBack();
744 void DolphinMainWindow::goForward()
747 m_activeViewContainer
->urlNavigator()->goForward();
750 void DolphinMainWindow::goUp()
753 m_activeViewContainer
->urlNavigator()->goUp();
756 void DolphinMainWindow::goBack(Qt::MouseButtons buttons
)
758 // The default case (left button pressed) is handled in goBack().
759 if (buttons
== Qt::MidButton
) {
760 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
761 openNewTab(urlNavigator
->historyUrl(urlNavigator
->historyIndex() + 1));
765 void DolphinMainWindow::goForward(Qt::MouseButtons buttons
)
767 // The default case (left button pressed) is handled in goForward().
768 if (buttons
== Qt::MidButton
) {
769 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
770 openNewTab(urlNavigator
->historyUrl(urlNavigator
->historyIndex() - 1));
774 void DolphinMainWindow::goUp(Qt::MouseButtons buttons
)
776 // The default case (left button pressed) is handled in goUp().
777 if (buttons
== Qt::MidButton
) {
778 openNewTab(activeViewContainer()->url().upUrl());
782 void DolphinMainWindow::goHome()
785 m_activeViewContainer
->urlNavigator()->goHome();
788 void DolphinMainWindow::compareFiles()
790 // The method is only invoked if exactly 2 files have
791 // been selected. The selected files may be:
792 // - both in the primary view
793 // - both in the secondary view
794 // - one in the primary view and the other in the secondary
796 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
800 KUrl::List urls
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedUrls();
802 switch (urls
.count()) {
804 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
!= 0);
805 urls
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedUrls();
806 Q_ASSERT(urls
.count() == 2);
814 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
!= 0);
815 urls
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedUrls();
816 Q_ASSERT(urls
.count() == 1);
828 // may not happen: compareFiles may only get invoked if 2
829 // files are selected
834 QString
command("kompare -c \"");
835 command
.append(urlA
.pathOrUrl());
836 command
.append("\" \"");
837 command
.append(urlB
.pathOrUrl());
838 command
.append('\"');
839 KRun::runCommand(command
, "Kompare", "kompare", this);
842 void DolphinMainWindow::toggleShowMenuBar()
844 const bool visible
= menuBar()->isVisible();
845 menuBar()->setVisible(!visible
);
848 void DolphinMainWindow::openTerminal()
850 QString
dir(QDir::homePath());
852 // If the given directory is not local, it can still be the URL of an
853 // ioslave using UDS_LOCAL_PATH which to be converted first.
854 KUrl url
= KIO::NetAccess::mostLocalUrl(m_activeViewContainer
->url(), this);
856 //If the URL is local after the above conversion, set the directory.
857 if (url
.isLocalFile()) {
858 dir
= url
.toLocalFile();
861 KToolInvocation::invokeTerminal(QString(), dir
);
864 void DolphinMainWindow::editSettings()
866 if (m_settingsDialog
== 0) {
867 const KUrl
& url
= activeViewContainer()->url();
868 m_settingsDialog
= new DolphinSettingsDialog(url
, this);
869 m_settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
870 m_settingsDialog
->show();
872 m_settingsDialog
->raise();
876 void DolphinMainWindow::setActiveTab(int index
)
878 Q_ASSERT(index
>= 0);
879 Q_ASSERT(index
< m_viewTab
.count());
880 if (index
== m_tabIndex
) {
884 // hide current tab content
885 ViewTab
& hiddenTab
= m_viewTab
[m_tabIndex
];
886 hiddenTab
.isPrimaryViewActive
= hiddenTab
.primaryView
->isActive();
887 hiddenTab
.primaryView
->setActive(false);
888 if (hiddenTab
.secondaryView
!= 0) {
889 hiddenTab
.secondaryView
->setActive(false);
891 QSplitter
* splitter
= m_viewTab
[m_tabIndex
].splitter
;
893 m_centralWidgetLayout
->removeWidget(splitter
);
895 // show active tab content
898 ViewTab
& viewTab
= m_viewTab
[index
];
899 m_centralWidgetLayout
->addWidget(viewTab
.splitter
, 1);
900 viewTab
.primaryView
->show();
901 if (viewTab
.secondaryView
!= 0) {
902 viewTab
.secondaryView
->show();
904 viewTab
.splitter
->show();
906 setActiveViewContainer(viewTab
.isPrimaryViewActive
? viewTab
.primaryView
:
907 viewTab
.secondaryView
);
910 void DolphinMainWindow::closeTab()
912 closeTab(m_tabBar
->currentIndex());
915 void DolphinMainWindow::closeTab(int index
)
917 Q_ASSERT(index
>= 0);
918 Q_ASSERT(index
< m_viewTab
.count());
919 if (m_viewTab
.count() == 1) {
920 // the last tab may never get closed
924 if (index
== m_tabIndex
) {
925 // The tab that should be closed is the active tab. Activate the
926 // previous tab before closing the tab.
927 m_tabBar
->setCurrentIndex((index
> 0) ? index
- 1 : 1);
929 rememberClosedTab(index
);
932 m_viewTab
[index
].primaryView
->deleteLater();
933 if (m_viewTab
[index
].secondaryView
!= 0) {
934 m_viewTab
[index
].secondaryView
->deleteLater();
936 m_viewTab
[index
].splitter
->deleteLater();
937 m_viewTab
.erase(m_viewTab
.begin() + index
);
939 m_tabBar
->blockSignals(true);
940 m_tabBar
->removeTab(index
);
942 if (m_tabIndex
> index
) {
944 Q_ASSERT(m_tabIndex
>= 0);
947 // if only one tab is left, also remove the tab entry so that
948 // closing the last tab is not possible
949 if (m_viewTab
.count() == 1) {
950 m_tabBar
->removeTab(0);
951 actionCollection()->action("close_tab")->setEnabled(false);
953 m_tabBar
->blockSignals(false);
957 void DolphinMainWindow::openTabContextMenu(int index
, const QPoint
& pos
)
961 QAction
* newTabAction
= menu
.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab"));
962 newTabAction
->setShortcut(actionCollection()->action("new_tab")->shortcut());
964 QAction
* closeOtherTabsAction
= menu
.addAction(KIcon("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs"));
966 QAction
* closeTabAction
= menu
.addAction(KIcon("tab-close"), i18nc("@action:inmenu", "Close Tab"));
967 closeTabAction
->setShortcut(actionCollection()->action("close_tab")->shortcut());
968 QAction
* selectedAction
= menu
.exec(pos
);
969 if (selectedAction
== newTabAction
) {
970 const ViewTab
& tab
= m_viewTab
[index
];
971 Q_ASSERT(tab
.primaryView
!= 0);
972 const KUrl url
= (tab
.secondaryView
!= 0) && tab
.secondaryView
->isActive() ?
973 tab
.secondaryView
->url() : tab
.primaryView
->url();
975 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
976 } else if (selectedAction
== closeOtherTabsAction
) {
977 const int count
= m_tabBar
->count();
978 for (int i
= 0; i
< index
; ++i
) {
981 for (int i
= index
+ 1; i
< count
; ++i
) {
984 } else if (selectedAction
== closeTabAction
) {
989 void DolphinMainWindow::handlePlacesClick(const KUrl
& url
, Qt::MouseButtons buttons
)
991 if (buttons
& Qt::MidButton
) {
993 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
999 void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent
* event
, bool& canDecode
)
1001 canDecode
= KUrl::List::canDecode(event
->mimeData());
1004 void DolphinMainWindow::searchItems(const KUrl
& url
)
1006 m_activeViewContainer
->setUrl(url
);
1009 void DolphinMainWindow::slotTabMoved(int from
, int to
)
1011 m_viewTab
.move(from
, to
);
1012 m_tabIndex
= m_tabBar
->currentIndex();
1015 void DolphinMainWindow::showSearchOptions()
1017 m_searchOptionsConfigurator
->show();
1020 void DolphinMainWindow::init()
1022 DolphinSettings
& settings
= DolphinSettings::instance();
1024 // Check whether Dolphin runs the first time. If yes then
1025 // a proper default window size is given at the end of DolphinMainWindow::init().
1026 GeneralSettings
* generalSettings
= settings
.generalSettings();
1027 const bool firstRun
= generalSettings
->firstRun();
1029 generalSettings
->setViewPropsTimestamp(QDateTime::currentDateTime());
1032 setAcceptDrops(true);
1034 m_viewTab
[m_tabIndex
].splitter
= new QSplitter(this);
1035 m_viewTab
[m_tabIndex
].splitter
->setChildrenCollapsible(false);
1039 const KUrl
& homeUrl
= generalSettings
->homeUrl();
1040 setUrlAsCaption(homeUrl
);
1041 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
1042 connect(m_actionHandler
, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
1043 connect(m_actionHandler
, SIGNAL(createDirectory()), SLOT(createDirectory()));
1044 ViewProperties
props(homeUrl
);
1045 m_viewTab
[m_tabIndex
].primaryView
= new DolphinViewContainer(this,
1046 m_viewTab
[m_tabIndex
].splitter
,
1049 m_activeViewContainer
= m_viewTab
[m_tabIndex
].primaryView
;
1050 connectViewSignals(m_activeViewContainer
);
1051 DolphinView
* view
= m_activeViewContainer
->view();
1053 m_activeViewContainer
->show();
1054 m_actionHandler
->setCurrentView(view
);
1056 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
1057 connect(this, SIGNAL(urlChanged(const KUrl
&)),
1058 m_remoteEncoding
, SLOT(slotAboutToOpenUrl()));
1060 m_searchOptionsConfigurator
= new DolphinSearchOptionsConfigurator(this);
1061 m_searchOptionsConfigurator
->hide();
1063 m_tabBar
= new KTabBar(this);
1064 m_tabBar
->setMovable(true);
1065 m_tabBar
->setTabsClosable(true);
1066 connect(m_tabBar
, SIGNAL(currentChanged(int)),
1067 this, SLOT(setActiveTab(int)));
1068 connect(m_tabBar
, SIGNAL(tabCloseRequested(int)),
1069 this, SLOT(closeTab(int)));
1070 connect(m_tabBar
, SIGNAL(contextMenu(int, const QPoint
&)),
1071 this, SLOT(openTabContextMenu(int, const QPoint
&)));
1072 connect(m_tabBar
, SIGNAL(newTabRequest()),
1073 this, SLOT(openNewTab()));
1074 connect(m_tabBar
, SIGNAL(testCanDecode(const QDragMoveEvent
*, bool&)),
1075 this, SLOT(slotTestCanDecode(const QDragMoveEvent
*, bool&)));
1076 connect(m_tabBar
, SIGNAL(wheelDelta(int)),
1077 this, SLOT(slotWheelMoved(int)));
1078 connect(m_tabBar
, SIGNAL(mouseMiddleClick(int)),
1079 this, SLOT(closeTab(int)));
1080 connect(m_tabBar
, SIGNAL(tabMoved(int, int)),
1081 this, SLOT(slotTabMoved(int, int)));
1083 m_tabBar
->blockSignals(true); // signals get unblocked after at least 2 tabs are open
1085 QWidget
* centralWidget
= new QWidget(this);
1086 m_centralWidgetLayout
= new QVBoxLayout(centralWidget
);
1087 m_centralWidgetLayout
->setSpacing(0);
1088 m_centralWidgetLayout
->setMargin(0);
1089 m_centralWidgetLayout
->addWidget(m_searchOptionsConfigurator
);
1090 m_centralWidgetLayout
->addWidget(m_tabBar
);
1091 m_centralWidgetLayout
->addWidget(m_viewTab
[m_tabIndex
].splitter
, 1);
1093 setCentralWidget(centralWidget
);
1095 emit
urlChanged(homeUrl
);
1097 setupGUI(Keys
| Save
| Create
| ToolBar
);
1099 m_searchBox
->setParent(toolBar("searchToolBar"));
1100 m_searchBox
->show();
1101 connect(m_searchBox
, SIGNAL(requestSearchOptions()),
1102 this, SLOT(showSearchOptions()));
1104 stateChanged("new_file");
1106 QClipboard
* clipboard
= QApplication::clipboard();
1107 connect(clipboard
, SIGNAL(dataChanged()),
1108 this, SLOT(updatePasteAction()));
1109 updatePasteAction();
1112 if (generalSettings
->splitView()) {
1115 updateViewActions();
1117 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1118 showFilterBarAction
->setChecked(generalSettings
->filterBar());
1121 // assure a proper default size if Dolphin runs the first time
1125 m_showMenuBar
->setChecked(!menuBar()->isHidden()); // workaround for bug #171080
1128 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer
* viewContainer
)
1130 Q_ASSERT(viewContainer
!= 0);
1131 Q_ASSERT((viewContainer
== m_viewTab
[m_tabIndex
].primaryView
) ||
1132 (viewContainer
== m_viewTab
[m_tabIndex
].secondaryView
));
1133 if (m_activeViewContainer
== viewContainer
) {
1137 m_activeViewContainer
->setActive(false);
1138 m_activeViewContainer
= viewContainer
;
1140 // Activating the view container might trigger a recursive setActiveViewContainer() call
1141 // inside DolphinMainWindow::toggleActiveView() when having a split view. Temporary
1142 // disconnect the activated() signal in this case:
1143 disconnect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1144 m_activeViewContainer
->setActive(true);
1145 connect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1147 m_actionHandler
->setCurrentView(viewContainer
->view());
1150 updateEditActions();
1151 updateViewActions();
1154 const KUrl
& url
= m_activeViewContainer
->url();
1155 setUrlAsCaption(url
);
1156 if (m_viewTab
.count() > 1 && m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
1157 m_tabBar
->setTabText(m_tabIndex
, tabName(url
));
1158 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(KMimeType::iconNameForUrl(url
)));
1161 emit
urlChanged(url
);
1164 void DolphinMainWindow::setupActions()
1166 // setup 'File' menu
1167 m_newMenu
= new DolphinNewMenu(this, this);
1168 KMenu
* menu
= m_newMenu
->menu();
1169 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1170 menu
->setIcon(KIcon("document-new"));
1171 connect(menu
, SIGNAL(aboutToShow()),
1172 this, SLOT(updateNewMenu()));
1174 KAction
* newWindow
= actionCollection()->addAction("new_window");
1175 newWindow
->setIcon(KIcon("window-new"));
1176 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1177 newWindow
->setShortcut(Qt::CTRL
| Qt::Key_N
);
1178 connect(newWindow
, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1180 KAction
* newTab
= actionCollection()->addAction("new_tab");
1181 newTab
->setIcon(KIcon("tab-new"));
1182 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1183 newTab
->setShortcut(KShortcut(Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
));
1184 connect(newTab
, SIGNAL(triggered()), this, SLOT(openNewTab()));
1186 KAction
* closeTab
= actionCollection()->addAction("close_tab");
1187 closeTab
->setIcon(KIcon("tab-close"));
1188 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1189 closeTab
->setShortcut(Qt::CTRL
| Qt::Key_W
);
1190 closeTab
->setEnabled(false);
1191 connect(closeTab
, SIGNAL(triggered()), this, SLOT(closeTab()));
1193 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1195 // setup 'Edit' menu
1196 KStandardAction::undo(this,
1198 actionCollection());
1200 // need to remove shift+del from cut action, else the shortcut for deletejob
1202 KAction
* cut
= KStandardAction::cut(this, SLOT(cut()), actionCollection());
1203 KShortcut cutShortcut
= cut
->shortcut();
1204 cutShortcut
.remove(Qt::SHIFT
+ Qt::Key_Delete
, KShortcut::KeepEmpty
);
1205 cut
->setShortcut(cutShortcut
);
1206 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1207 KAction
* paste
= KStandardAction::paste(this, SLOT(paste()), actionCollection());
1208 // The text of the paste-action is modified dynamically by Dolphin
1209 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1210 // due to the long text, the text "Paste" is used:
1211 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1213 KAction
* selectAll
= actionCollection()->addAction("select_all");
1214 selectAll
->setText(i18nc("@action:inmenu Edit", "Select All"));
1215 selectAll
->setShortcut(Qt::CTRL
+ Qt::Key_A
);
1216 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
1218 KAction
* invertSelection
= actionCollection()->addAction("invert_selection");
1219 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1220 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1221 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
1223 // setup 'View' menu
1224 // (note that most of it is set up in DolphinViewActionHandler)
1226 KAction
* split
= actionCollection()->addAction("split_view");
1227 split
->setShortcut(Qt::Key_F3
);
1228 updateSplitAction();
1229 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1231 KAction
* reload
= actionCollection()->addAction("reload");
1232 reload
->setText(i18nc("@action:inmenu View", "Reload"));
1233 reload
->setShortcut(Qt::Key_F5
);
1234 reload
->setIcon(KIcon("view-refresh"));
1235 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
1237 KAction
* stop
= actionCollection()->addAction("stop");
1238 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1239 stop
->setToolTip(i18nc("@info", "Stop loading"));
1240 stop
->setIcon(KIcon("process-stop"));
1241 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
1243 KToggleAction
* showFullLocation
= actionCollection()->add
<KToggleAction
>("editable_location");
1244 showFullLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1245 showFullLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
1246 connect(showFullLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1248 KAction
* replaceLocation
= actionCollection()->addAction("replace_location");
1249 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1250 replaceLocation
->setShortcut(Qt::Key_F6
);
1251 connect(replaceLocation
, SIGNAL(triggered()), this, SLOT(replaceLocation()));
1254 KAction
* backAction
= KStandardAction::back(this, SLOT(goBack()), actionCollection());
1255 connect(backAction
, SIGNAL(triggered(Qt::MouseButtons
, Qt::KeyboardModifiers
)), this, SLOT(goBack(Qt::MouseButtons
)));
1256 KShortcut backShortcut
= backAction
->shortcut();
1257 backShortcut
.setAlternate(Qt::Key_Backspace
);
1258 backAction
->setShortcut(backShortcut
);
1260 m_recentTabsMenu
= new KActionMenu(i18n("Recently Closed Tabs"), this);
1261 m_recentTabsMenu
->setIcon(KIcon("edit-undo"));
1262 actionCollection()->addAction("closed_tabs", m_recentTabsMenu
);
1263 connect(m_recentTabsMenu
->menu(), SIGNAL(triggered(QAction
*)),
1264 this, SLOT(restoreClosedTab(QAction
*)));
1266 QAction
* action
= new QAction("Empty Recently Closed Tabs", m_recentTabsMenu
);
1267 action
->setIcon(KIcon("edit-clear-list"));
1268 action
->setData(QVariant::fromValue(true));
1269 m_recentTabsMenu
->addAction(action
);
1270 m_recentTabsMenu
->addSeparator();
1271 m_recentTabsMenu
->setEnabled(false);
1273 KAction
* forwardAction
= KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1274 connect(forwardAction
, SIGNAL(triggered(Qt::MouseButtons
, Qt::KeyboardModifiers
)), this, SLOT(goForward(Qt::MouseButtons
)));
1276 KAction
* upAction
= KStandardAction::up(this, SLOT(goUp()), actionCollection());
1277 connect(upAction
, SIGNAL(triggered(Qt::MouseButtons
, Qt::KeyboardModifiers
)), this, SLOT(goUp(Qt::MouseButtons
)));
1279 KStandardAction::home(this, SLOT(goHome()), actionCollection());
1281 // setup 'Tools' menu
1282 KToggleAction
* showSearchBar
= actionCollection()->add
<KToggleAction
>("show_search_bar");
1283 showSearchBar
->setText(i18nc("@action:inmenu Tools", "Show Search Bar"));
1284 showSearchBar
->setShortcut(Qt::CTRL
| Qt::Key_S
);
1285 connect(showSearchBar
, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
1287 KToggleAction
* showFilterBar
= actionCollection()->add
<KToggleAction
>("show_filter_bar");
1288 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1289 showFilterBar
->setIcon(KIcon("view-filter"));
1290 showFilterBar
->setShortcut(Qt::CTRL
| Qt::Key_I
);
1291 connect(showFilterBar
, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
1293 KAction
* compareFiles
= actionCollection()->addAction("compare_files");
1294 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1295 compareFiles
->setIcon(KIcon("kompare"));
1296 compareFiles
->setEnabled(false);
1297 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
1299 KAction
* openTerminal
= actionCollection()->addAction("open_terminal");
1300 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1301 openTerminal
->setIcon(KIcon("utilities-terminal"));
1302 openTerminal
->setShortcut(Qt::SHIFT
| Qt::Key_F4
);
1303 connect(openTerminal
, SIGNAL(triggered()), this, SLOT(openTerminal()));
1305 // setup 'Settings' menu
1306 m_showMenuBar
= KStandardAction::showMenubar(this, SLOT(toggleShowMenuBar()), actionCollection());
1307 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1309 // not in menu actions
1310 KAction
* activateNextTab
= actionCollection()->addAction("activate_next_tab");
1311 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1312 connect(activateNextTab
, SIGNAL(triggered()), SLOT(activateNextTab()));
1313 activateNextTab
->setShortcuts(QApplication::isRightToLeft() ? KStandardShortcut::tabPrev() :
1314 KStandardShortcut::tabNext());
1316 KAction
* activatePrevTab
= actionCollection()->addAction("activate_prev_tab");
1317 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1318 connect(activatePrevTab
, SIGNAL(triggered()), SLOT(activatePrevTab()));
1319 activatePrevTab
->setShortcuts(QApplication::isRightToLeft() ? KStandardShortcut::tabNext() :
1320 KStandardShortcut::tabPrev());
1323 KAction
* openInNewTab
= actionCollection()->addAction("open_in_new_tab");
1324 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1325 openInNewTab
->setIcon(KIcon("tab-new"));
1326 connect(openInNewTab
, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1328 KAction
* openInNewWindow
= actionCollection()->addAction("open_in_new_window");
1329 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1330 openInNewWindow
->setIcon(KIcon("window-new"));
1331 connect(openInNewWindow
, SIGNAL(triggered()), this, SLOT(openInNewWindow()));
1334 m_searchBox
= new DolphinSearchBox(this);
1335 connect(m_searchBox
, SIGNAL(search(KUrl
)), this, SLOT(searchItems(KUrl
)));
1337 KAction
* search
= new KAction(this);
1338 actionCollection()->addAction("search_bar", search
);
1339 search
->setText(i18nc("@action:inmenu", "Search Bar"));
1340 search
->setDefaultWidget(m_searchBox
);
1341 search
->setShortcutConfigurable(false);
1344 void DolphinMainWindow::setupDockWidgets()
1346 // setup "Information"
1347 QDockWidget
* infoDock
= new QDockWidget(i18nc("@title:window", "Information"));
1348 infoDock
->setObjectName("infoDock");
1349 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1350 Panel
* infoPanel
= new InformationPanel(infoDock
);
1351 infoDock
->setWidget(infoPanel
);
1353 QAction
* infoAction
= infoDock
->toggleViewAction();
1354 infoAction
->setText(i18nc("@title:window", "Information"));
1355 infoAction
->setShortcut(Qt::Key_F11
);
1356 infoAction
->setIcon(KIcon("dialog-information"));
1357 actionCollection()->addAction("show_info_panel", infoDock
->toggleViewAction());
1359 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1360 connect(this, SIGNAL(urlChanged(KUrl
)),
1361 infoPanel
, SLOT(setUrl(KUrl
)));
1362 connect(this, SIGNAL(selectionChanged(KFileItemList
)),
1363 infoPanel
, SLOT(setSelection(KFileItemList
)));
1364 connect(this, SIGNAL(requestItemInfo(KFileItem
)),
1365 infoPanel
, SLOT(requestDelayedItemInfo(KFileItem
)));
1368 QDockWidget
* foldersDock
= new QDockWidget(i18nc("@title:window", "Folders"));
1369 foldersDock
->setObjectName("foldersDock");
1370 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1371 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1372 foldersDock
->setWidget(foldersPanel
);
1374 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1375 foldersAction
->setText(i18nc("@title:window", "Folders"));
1376 foldersAction
->setShortcut(Qt::Key_F7
);
1377 foldersAction
->setIcon(KIcon("folder"));
1378 actionCollection()->addAction("show_folders_panel", foldersDock
->toggleViewAction());
1380 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1381 connect(this, SIGNAL(urlChanged(KUrl
)),
1382 foldersPanel
, SLOT(setUrl(KUrl
)));
1383 connect(foldersPanel
, SIGNAL(changeUrl(KUrl
, Qt::MouseButtons
)),
1384 this, SLOT(handlePlacesClick(KUrl
, Qt::MouseButtons
)));
1385 connect(foldersPanel
, SIGNAL(changeSelection(KFileItemList
)),
1386 this, SLOT(changeSelection(KFileItemList
)));
1390 QDockWidget
* terminalDock
= new QDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1391 terminalDock
->setObjectName("terminalDock");
1392 terminalDock
->setAllowedAreas(Qt::TopDockWidgetArea
| Qt::BottomDockWidgetArea
);
1393 Panel
* terminalPanel
= new TerminalPanel(terminalDock
);
1394 terminalDock
->setWidget(terminalPanel
);
1396 connect(terminalPanel
, SIGNAL(hideTerminalPanel()), terminalDock
, SLOT(hide()));
1398 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1399 terminalAction
->setText(i18nc("@title:window Shell terminal", "Terminal"));
1400 terminalAction
->setShortcut(Qt::Key_F4
);
1401 terminalAction
->setIcon(KIcon("utilities-terminal"));
1402 actionCollection()->addAction("show_terminal_panel", terminalDock
->toggleViewAction());
1404 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1405 connect(this, SIGNAL(urlChanged(KUrl
)),
1406 terminalPanel
, SLOT(setUrl(KUrl
)));
1409 const bool firstRun
= DolphinSettings::instance().generalSettings()->firstRun();
1411 foldersDock
->hide();
1413 terminalDock
->hide();
1417 QDockWidget
* placesDock
= new QDockWidget(i18nc("@title:window", "Places"));
1418 placesDock
->setObjectName("placesDock");
1419 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1421 PlacesPanel
* placesPanel
= new PlacesPanel(placesDock
);
1422 placesDock
->setWidget(placesPanel
);
1423 placesPanel
->setModel(DolphinSettings::instance().placesModel());
1424 placesPanel
->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff
);
1426 QAction
* placesAction
= placesDock
->toggleViewAction();
1427 placesAction
->setText(i18nc("@title:window", "Places"));
1428 placesAction
->setShortcut(Qt::Key_F9
);
1429 placesAction
->setIcon(KIcon("bookmarks"));
1430 actionCollection()->addAction("show_places_panel", placesDock
->toggleViewAction());
1432 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1433 connect(placesPanel
, SIGNAL(urlChanged(KUrl
, Qt::MouseButtons
)),
1434 this, SLOT(handlePlacesClick(KUrl
, Qt::MouseButtons
)));
1435 connect(this, SIGNAL(urlChanged(KUrl
)),
1436 placesPanel
, SLOT(setUrl(KUrl
)));
1439 void DolphinMainWindow::updateEditActions()
1441 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1442 if (list
.isEmpty()) {
1443 stateChanged("has_no_selection");
1445 stateChanged("has_selection");
1447 KActionCollection
* col
= actionCollection();
1448 QAction
* renameAction
= col
->action("rename");
1449 QAction
* moveToTrashAction
= col
->action("move_to_trash");
1450 QAction
* deleteAction
= col
->action("delete");
1451 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
1452 QAction
* deleteWithTrashShortcut
= col
->action("delete_shortcut"); // see DolphinViewActionHandler
1454 KFileItemListProperties
capabilities(list
);
1455 const bool enableMoveToTrash
= capabilities
.isLocal() && capabilities
.supportsMoving();
1457 renameAction
->setEnabled(capabilities
.supportsMoving());
1458 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1459 deleteAction
->setEnabled(capabilities
.supportsDeleting());
1460 deleteWithTrashShortcut
->setEnabled(capabilities
.supportsDeleting() && !enableMoveToTrash
);
1461 cutAction
->setEnabled(capabilities
.supportsMoving());
1463 updatePasteAction();
1466 void DolphinMainWindow::updateViewActions()
1468 m_actionHandler
->updateViewActions();
1470 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1471 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
1473 updateSplitAction();
1475 QAction
* editableLocactionAction
= actionCollection()->action("editable_location");
1476 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
1477 editableLocactionAction
->setChecked(urlNavigator
->isUrlEditable());
1480 void DolphinMainWindow::updateGoActions()
1482 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
1483 const KUrl
& currentUrl
= m_activeViewContainer
->url();
1484 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
1487 void DolphinMainWindow::rememberClosedTab(int index
)
1489 KMenu
* tabsMenu
= m_recentTabsMenu
->menu();
1491 const QString primaryPath
= m_viewTab
[index
].primaryView
->url().path();
1492 const QString iconName
= KMimeType::iconNameForUrl(primaryPath
);
1494 QAction
* action
= new QAction(squeezedText(primaryPath
), tabsMenu
);
1496 ClosedTab closedTab
;
1497 closedTab
.primaryUrl
= m_viewTab
[index
].primaryView
->url();
1499 if (m_viewTab
[index
].secondaryView
!= 0) {
1500 closedTab
.secondaryUrl
= m_viewTab
[index
].secondaryView
->url();
1501 closedTab
.isSplit
= true;
1503 closedTab
.isSplit
= false;
1506 action
->setData(QVariant::fromValue(closedTab
));
1507 action
->setIcon(KIcon(iconName
));
1509 // add the closed tab menu entry after the separator and
1510 // "Empty Recently Closed Tabs" entry
1511 if (tabsMenu
->actions().size() == 2) {
1512 tabsMenu
->addAction(action
);
1514 tabsMenu
->insertAction(tabsMenu
->actions().at(2), action
);
1517 // assure that only up to 8 closed tabs are shown in the menu
1518 if (tabsMenu
->actions().size() > 8) {
1519 tabsMenu
->removeAction(tabsMenu
->actions().last());
1521 actionCollection()->action("closed_tabs")->setEnabled(true);
1522 KAcceleratorManager::manage(tabsMenu
);
1525 void DolphinMainWindow::clearStatusBar()
1527 m_activeViewContainer
->statusBar()->clear();
1530 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
1532 connect(container
, SIGNAL(showFilterBarChanged(bool)),
1533 this, SLOT(updateFilterBarAction(bool)));
1535 DolphinView
* view
= container
->view();
1536 connect(view
, SIGNAL(selectionChanged(KFileItemList
)),
1537 this, SLOT(slotSelectionChanged(KFileItemList
)));
1538 connect(view
, SIGNAL(requestItemInfo(KFileItem
)),
1539 this, SLOT(slotRequestItemInfo(KFileItem
)));
1540 connect(view
, SIGNAL(activated()),
1541 this, SLOT(toggleActiveView()));
1542 connect(view
, SIGNAL(tabRequested(const KUrl
&)),
1543 this, SLOT(openNewTab(const KUrl
&)));
1545 const KUrlNavigator
* navigator
= container
->urlNavigator();
1546 connect(navigator
, SIGNAL(urlChanged(const KUrl
&)),
1547 this, SLOT(changeUrl(const KUrl
&)));
1548 connect(navigator
, SIGNAL(historyChanged()),
1549 this, SLOT(updateHistory()));
1550 connect(navigator
, SIGNAL(editableStateChanged(bool)),
1551 this, SLOT(slotEditableStateChanged(bool)));
1554 void DolphinMainWindow::updateSplitAction()
1556 QAction
* splitAction
= actionCollection()->action("split_view");
1557 if (m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
1558 if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
1559 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
1560 splitAction
->setToolTip(i18nc("@info", "Close right view"));
1561 splitAction
->setIcon(KIcon("view-right-close"));
1563 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
1564 splitAction
->setToolTip(i18nc("@info", "Close left view"));
1565 splitAction
->setIcon(KIcon("view-left-close"));
1568 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
1569 splitAction
->setToolTip(i18nc("@info", "Split view"));
1570 splitAction
->setIcon(KIcon("view-right-new"));
1574 QString
DolphinMainWindow::tabName(const KUrl
& url
) const
1577 if (url
.equals(KUrl("file:///"))) {
1580 name
= url
.fileName();
1581 if (name
.isEmpty()) {
1582 name
= url
.protocol();
1584 // Make sure that a '&' inside the directory name is displayed correctly
1585 // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
1586 name
.replace('&', "&&");
1592 bool DolphinMainWindow::isKompareInstalled() const
1594 static bool initialized
= false;
1595 static bool installed
= false;
1597 // TODO: maybe replace this approach later by using a menu
1598 // plugin like kdiff3plugin.cpp
1599 installed
= !KGlobal::dirs()->findExe("kompare").isEmpty();
1605 void DolphinMainWindow::createSecondaryView(int tabIndex
)
1607 QSplitter
* splitter
= m_viewTab
[tabIndex
].splitter
;
1608 const int newWidth
= (m_viewTab
[tabIndex
].primaryView
->width() - splitter
->handleWidth()) / 2;
1610 const DolphinView
* view
= m_viewTab
[tabIndex
].primaryView
->view();
1611 m_viewTab
[tabIndex
].secondaryView
= new DolphinViewContainer(this, 0, view
->rootUrl());
1612 splitter
->addWidget(m_viewTab
[tabIndex
].secondaryView
);
1613 splitter
->setSizes(QList
<int>() << newWidth
<< newWidth
);
1614 connectViewSignals(m_viewTab
[tabIndex
].secondaryView
);
1615 m_viewTab
[tabIndex
].secondaryView
->view()->reload();
1616 m_viewTab
[tabIndex
].secondaryView
->setActive(false);
1617 m_viewTab
[tabIndex
].secondaryView
->show();
1620 QString
DolphinMainWindow::tabProperty(const QString
& property
, int tabIndex
) const
1622 return "Tab " + QString::number(tabIndex
) + ' ' + property
;
1625 void DolphinMainWindow::setUrlAsCaption(const KUrl
& url
)
1628 if (url
.equals(KUrl("file:///"))) {
1631 caption
= url
.fileName();
1632 if (caption
.isEmpty()) {
1633 caption
= url
.protocol();
1637 setCaption(caption
);
1640 QString
DolphinMainWindow::squeezedText(const QString
& text
) const
1642 const QFontMetrics fm
= fontMetrics();
1643 return fm
.elidedText(text
, Qt::ElideMiddle
, fm
.maxWidth() * 10);
1646 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
1647 KIO::FileUndoManager::UiInterface()
1651 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
1655 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
1657 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
1659 DolphinStatusBar
* statusBar
= mainWin
->activeViewContainer()->statusBar();
1660 statusBar
->setMessage(job
->errorString(), DolphinStatusBar::Error
);
1662 KIO::FileUndoManager::UiInterface::jobError(job
);
1666 #include "dolphinmainwindow.moc"