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>
27 #include "search/dolphinsearchoptionsconfigurator.h"
29 #include "dolphinapplication.h"
30 #include "dolphinnewmenu.h"
31 #include "search/dolphinsearchbox.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()
1006 const QString searchOptions
= m_searchOptionsConfigurator
->options();
1008 QString searchString
= m_searchBox
->text();
1009 if (!searchString
.isEmpty() && !searchOptions
.isEmpty()) {
1010 searchString
+= ' ' + searchOptions
;
1011 } else if (!searchOptions
.isEmpty()) {
1012 searchString
+= searchOptions
;
1015 if (!searchString
.isEmpty()) {
1016 m_activeViewContainer
->setUrl(KUrl("nepomuksearch:/" + searchString
));
1020 void DolphinMainWindow::slotTabMoved(int from
, int to
)
1022 m_viewTab
.move(from
, to
);
1023 m_tabIndex
= m_tabBar
->currentIndex();
1026 void DolphinMainWindow::showSearchOptions()
1029 m_searchOptionsConfigurator
->show();
1033 void DolphinMainWindow::init()
1035 DolphinSettings
& settings
= DolphinSettings::instance();
1037 // Check whether Dolphin runs the first time. If yes then
1038 // a proper default window size is given at the end of DolphinMainWindow::init().
1039 GeneralSettings
* generalSettings
= settings
.generalSettings();
1040 const bool firstRun
= generalSettings
->firstRun();
1042 generalSettings
->setViewPropsTimestamp(QDateTime::currentDateTime());
1045 setAcceptDrops(true);
1047 m_viewTab
[m_tabIndex
].splitter
= new QSplitter(this);
1048 m_viewTab
[m_tabIndex
].splitter
->setChildrenCollapsible(false);
1052 const KUrl
& homeUrl
= generalSettings
->homeUrl();
1053 setUrlAsCaption(homeUrl
);
1054 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
1055 connect(m_actionHandler
, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
1056 connect(m_actionHandler
, SIGNAL(createDirectory()), SLOT(createDirectory()));
1057 ViewProperties
props(homeUrl
);
1058 m_viewTab
[m_tabIndex
].primaryView
= new DolphinViewContainer(this,
1059 m_viewTab
[m_tabIndex
].splitter
,
1062 m_activeViewContainer
= m_viewTab
[m_tabIndex
].primaryView
;
1063 connectViewSignals(m_activeViewContainer
);
1064 DolphinView
* view
= m_activeViewContainer
->view();
1066 m_activeViewContainer
->show();
1067 m_actionHandler
->setCurrentView(view
);
1069 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
1070 connect(this, SIGNAL(urlChanged(const KUrl
&)),
1071 m_remoteEncoding
, SLOT(slotAboutToOpenUrl()));
1074 m_searchOptionsConfigurator
= new DolphinSearchOptionsConfigurator(this);
1075 m_searchOptionsConfigurator
->hide();
1076 connect(m_searchOptionsConfigurator
, SIGNAL(searchOptionsChanged(QString
)),
1077 this, SLOT(searchItems()));
1080 m_tabBar
= new KTabBar(this);
1081 m_tabBar
->setMovable(true);
1082 m_tabBar
->setTabsClosable(true);
1083 connect(m_tabBar
, SIGNAL(currentChanged(int)),
1084 this, SLOT(setActiveTab(int)));
1085 connect(m_tabBar
, SIGNAL(tabCloseRequested(int)),
1086 this, SLOT(closeTab(int)));
1087 connect(m_tabBar
, SIGNAL(contextMenu(int, const QPoint
&)),
1088 this, SLOT(openTabContextMenu(int, const QPoint
&)));
1089 connect(m_tabBar
, SIGNAL(newTabRequest()),
1090 this, SLOT(openNewTab()));
1091 connect(m_tabBar
, SIGNAL(testCanDecode(const QDragMoveEvent
*, bool&)),
1092 this, SLOT(slotTestCanDecode(const QDragMoveEvent
*, bool&)));
1093 connect(m_tabBar
, SIGNAL(wheelDelta(int)),
1094 this, SLOT(slotWheelMoved(int)));
1095 connect(m_tabBar
, SIGNAL(mouseMiddleClick(int)),
1096 this, SLOT(closeTab(int)));
1097 connect(m_tabBar
, SIGNAL(tabMoved(int, int)),
1098 this, SLOT(slotTabMoved(int, int)));
1100 m_tabBar
->blockSignals(true); // signals get unblocked after at least 2 tabs are open
1102 QWidget
* centralWidget
= new QWidget(this);
1103 m_centralWidgetLayout
= new QVBoxLayout(centralWidget
);
1104 m_centralWidgetLayout
->setSpacing(0);
1105 m_centralWidgetLayout
->setMargin(0);
1107 m_centralWidgetLayout
->addWidget(m_searchOptionsConfigurator
);
1109 m_centralWidgetLayout
->addWidget(m_tabBar
);
1110 m_centralWidgetLayout
->addWidget(m_viewTab
[m_tabIndex
].splitter
, 1);
1112 setCentralWidget(centralWidget
);
1114 emit
urlChanged(homeUrl
);
1116 setupGUI(Keys
| Save
| Create
| ToolBar
);
1118 m_searchBox
->setParent(toolBar("searchToolBar"));
1119 m_searchBox
->show();
1120 connect(m_searchBox
, SIGNAL(requestSearchOptions()),
1121 this, SLOT(showSearchOptions()));
1123 stateChanged("new_file");
1125 QClipboard
* clipboard
= QApplication::clipboard();
1126 connect(clipboard
, SIGNAL(dataChanged()),
1127 this, SLOT(updatePasteAction()));
1128 updatePasteAction();
1131 if (generalSettings
->splitView()) {
1134 updateViewActions();
1136 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1137 showFilterBarAction
->setChecked(generalSettings
->filterBar());
1140 // assure a proper default size if Dolphin runs the first time
1144 m_showMenuBar
->setChecked(!menuBar()->isHidden()); // workaround for bug #171080
1147 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer
* viewContainer
)
1149 Q_ASSERT(viewContainer
!= 0);
1150 Q_ASSERT((viewContainer
== m_viewTab
[m_tabIndex
].primaryView
) ||
1151 (viewContainer
== m_viewTab
[m_tabIndex
].secondaryView
));
1152 if (m_activeViewContainer
== viewContainer
) {
1156 m_activeViewContainer
->setActive(false);
1157 m_activeViewContainer
= viewContainer
;
1159 // Activating the view container might trigger a recursive setActiveViewContainer() call
1160 // inside DolphinMainWindow::toggleActiveView() when having a split view. Temporary
1161 // disconnect the activated() signal in this case:
1162 disconnect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1163 m_activeViewContainer
->setActive(true);
1164 connect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1166 m_actionHandler
->setCurrentView(viewContainer
->view());
1169 updateEditActions();
1170 updateViewActions();
1173 const KUrl
& url
= m_activeViewContainer
->url();
1174 setUrlAsCaption(url
);
1175 if (m_viewTab
.count() > 1 && m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
1176 m_tabBar
->setTabText(m_tabIndex
, tabName(url
));
1177 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(KMimeType::iconNameForUrl(url
)));
1180 emit
urlChanged(url
);
1183 void DolphinMainWindow::setupActions()
1185 // setup 'File' menu
1186 m_newMenu
= new DolphinNewMenu(this, this);
1187 KMenu
* menu
= m_newMenu
->menu();
1188 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1189 menu
->setIcon(KIcon("document-new"));
1190 connect(menu
, SIGNAL(aboutToShow()),
1191 this, SLOT(updateNewMenu()));
1193 KAction
* newWindow
= actionCollection()->addAction("new_window");
1194 newWindow
->setIcon(KIcon("window-new"));
1195 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1196 newWindow
->setShortcut(Qt::CTRL
| Qt::Key_N
);
1197 connect(newWindow
, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1199 KAction
* newTab
= actionCollection()->addAction("new_tab");
1200 newTab
->setIcon(KIcon("tab-new"));
1201 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1202 newTab
->setShortcut(KShortcut(Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
));
1203 connect(newTab
, SIGNAL(triggered()), this, SLOT(openNewTab()));
1205 KAction
* closeTab
= actionCollection()->addAction("close_tab");
1206 closeTab
->setIcon(KIcon("tab-close"));
1207 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1208 closeTab
->setShortcut(Qt::CTRL
| Qt::Key_W
);
1209 closeTab
->setEnabled(false);
1210 connect(closeTab
, SIGNAL(triggered()), this, SLOT(closeTab()));
1212 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1214 // setup 'Edit' menu
1215 KStandardAction::undo(this,
1217 actionCollection());
1219 // need to remove shift+del from cut action, else the shortcut for deletejob
1221 KAction
* cut
= KStandardAction::cut(this, SLOT(cut()), actionCollection());
1222 KShortcut cutShortcut
= cut
->shortcut();
1223 cutShortcut
.remove(Qt::SHIFT
+ Qt::Key_Delete
, KShortcut::KeepEmpty
);
1224 cut
->setShortcut(cutShortcut
);
1225 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1226 KAction
* paste
= KStandardAction::paste(this, SLOT(paste()), actionCollection());
1227 // The text of the paste-action is modified dynamically by Dolphin
1228 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1229 // due to the long text, the text "Paste" is used:
1230 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1232 KAction
* selectAll
= actionCollection()->addAction("select_all");
1233 selectAll
->setText(i18nc("@action:inmenu Edit", "Select All"));
1234 selectAll
->setShortcut(Qt::CTRL
+ Qt::Key_A
);
1235 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
1237 KAction
* invertSelection
= actionCollection()->addAction("invert_selection");
1238 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1239 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1240 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
1242 // setup 'View' menu
1243 // (note that most of it is set up in DolphinViewActionHandler)
1245 KAction
* split
= actionCollection()->addAction("split_view");
1246 split
->setShortcut(Qt::Key_F3
);
1247 updateSplitAction();
1248 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1250 KAction
* reload
= actionCollection()->addAction("reload");
1251 reload
->setText(i18nc("@action:inmenu View", "Reload"));
1252 reload
->setShortcut(Qt::Key_F5
);
1253 reload
->setIcon(KIcon("view-refresh"));
1254 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
1256 KAction
* stop
= actionCollection()->addAction("stop");
1257 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1258 stop
->setToolTip(i18nc("@info", "Stop loading"));
1259 stop
->setIcon(KIcon("process-stop"));
1260 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
1262 KToggleAction
* showFullLocation
= actionCollection()->add
<KToggleAction
>("editable_location");
1263 showFullLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1264 showFullLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
1265 connect(showFullLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1267 KAction
* replaceLocation
= actionCollection()->addAction("replace_location");
1268 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1269 replaceLocation
->setShortcut(Qt::Key_F6
);
1270 connect(replaceLocation
, SIGNAL(triggered()), this, SLOT(replaceLocation()));
1273 KAction
* backAction
= KStandardAction::back(this, SLOT(goBack()), actionCollection());
1274 connect(backAction
, SIGNAL(triggered(Qt::MouseButtons
, Qt::KeyboardModifiers
)), this, SLOT(goBack(Qt::MouseButtons
)));
1275 KShortcut backShortcut
= backAction
->shortcut();
1276 backShortcut
.setAlternate(Qt::Key_Backspace
);
1277 backAction
->setShortcut(backShortcut
);
1279 m_recentTabsMenu
= new KActionMenu(i18n("Recently Closed Tabs"), this);
1280 m_recentTabsMenu
->setIcon(KIcon("edit-undo"));
1281 actionCollection()->addAction("closed_tabs", m_recentTabsMenu
);
1282 connect(m_recentTabsMenu
->menu(), SIGNAL(triggered(QAction
*)),
1283 this, SLOT(restoreClosedTab(QAction
*)));
1285 QAction
* action
= new QAction("Empty Recently Closed Tabs", m_recentTabsMenu
);
1286 action
->setIcon(KIcon("edit-clear-list"));
1287 action
->setData(QVariant::fromValue(true));
1288 m_recentTabsMenu
->addAction(action
);
1289 m_recentTabsMenu
->addSeparator();
1290 m_recentTabsMenu
->setEnabled(false);
1292 KAction
* forwardAction
= KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1293 connect(forwardAction
, SIGNAL(triggered(Qt::MouseButtons
, Qt::KeyboardModifiers
)), this, SLOT(goForward(Qt::MouseButtons
)));
1295 KAction
* upAction
= KStandardAction::up(this, SLOT(goUp()), actionCollection());
1296 connect(upAction
, SIGNAL(triggered(Qt::MouseButtons
, Qt::KeyboardModifiers
)), this, SLOT(goUp(Qt::MouseButtons
)));
1298 KStandardAction::home(this, SLOT(goHome()), actionCollection());
1300 // setup 'Tools' menu
1301 KToggleAction
* showSearchBar
= actionCollection()->add
<KToggleAction
>("show_search_bar");
1302 showSearchBar
->setText(i18nc("@action:inmenu Tools", "Show Search Bar"));
1303 showSearchBar
->setShortcut(Qt::CTRL
| Qt::Key_S
);
1304 connect(showSearchBar
, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
1306 KToggleAction
* showFilterBar
= actionCollection()->add
<KToggleAction
>("show_filter_bar");
1307 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1308 showFilterBar
->setIcon(KIcon("view-filter"));
1309 showFilterBar
->setShortcut(Qt::CTRL
| Qt::Key_I
);
1310 connect(showFilterBar
, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
1312 KAction
* compareFiles
= actionCollection()->addAction("compare_files");
1313 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1314 compareFiles
->setIcon(KIcon("kompare"));
1315 compareFiles
->setEnabled(false);
1316 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
1318 KAction
* openTerminal
= actionCollection()->addAction("open_terminal");
1319 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1320 openTerminal
->setIcon(KIcon("utilities-terminal"));
1321 openTerminal
->setShortcut(Qt::SHIFT
| Qt::Key_F4
);
1322 connect(openTerminal
, SIGNAL(triggered()), this, SLOT(openTerminal()));
1324 // setup 'Settings' menu
1325 m_showMenuBar
= KStandardAction::showMenubar(this, SLOT(toggleShowMenuBar()), actionCollection());
1326 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1328 // not in menu actions
1329 KAction
* activateNextTab
= actionCollection()->addAction("activate_next_tab");
1330 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1331 connect(activateNextTab
, SIGNAL(triggered()), SLOT(activateNextTab()));
1332 activateNextTab
->setShortcuts(QApplication::isRightToLeft() ? KStandardShortcut::tabPrev() :
1333 KStandardShortcut::tabNext());
1335 KAction
* activatePrevTab
= actionCollection()->addAction("activate_prev_tab");
1336 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1337 connect(activatePrevTab
, SIGNAL(triggered()), SLOT(activatePrevTab()));
1338 activatePrevTab
->setShortcuts(QApplication::isRightToLeft() ? KStandardShortcut::tabNext() :
1339 KStandardShortcut::tabPrev());
1342 KAction
* openInNewTab
= actionCollection()->addAction("open_in_new_tab");
1343 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1344 openInNewTab
->setIcon(KIcon("tab-new"));
1345 connect(openInNewTab
, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1347 KAction
* openInNewWindow
= actionCollection()->addAction("open_in_new_window");
1348 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1349 openInNewWindow
->setIcon(KIcon("window-new"));
1350 connect(openInNewWindow
, SIGNAL(triggered()), this, SLOT(openInNewWindow()));
1353 m_searchBox
= new DolphinSearchBox(this);
1354 connect(m_searchBox
, SIGNAL(search(QString
)), this, SLOT(searchItems()));
1356 KAction
* search
= new KAction(this);
1357 actionCollection()->addAction("search_bar", search
);
1358 search
->setText(i18nc("@action:inmenu", "Search Bar"));
1359 search
->setDefaultWidget(m_searchBox
);
1360 search
->setShortcutConfigurable(false);
1363 void DolphinMainWindow::setupDockWidgets()
1365 // setup "Information"
1366 QDockWidget
* infoDock
= new QDockWidget(i18nc("@title:window", "Information"));
1367 infoDock
->setObjectName("infoDock");
1368 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1369 Panel
* infoPanel
= new InformationPanel(infoDock
);
1370 infoDock
->setWidget(infoPanel
);
1372 QAction
* infoAction
= infoDock
->toggleViewAction();
1373 infoAction
->setText(i18nc("@title:window", "Information"));
1374 infoAction
->setShortcut(Qt::Key_F11
);
1375 infoAction
->setIcon(KIcon("dialog-information"));
1376 actionCollection()->addAction("show_info_panel", infoDock
->toggleViewAction());
1378 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1379 connect(this, SIGNAL(urlChanged(KUrl
)),
1380 infoPanel
, SLOT(setUrl(KUrl
)));
1381 connect(this, SIGNAL(selectionChanged(KFileItemList
)),
1382 infoPanel
, SLOT(setSelection(KFileItemList
)));
1383 connect(this, SIGNAL(requestItemInfo(KFileItem
)),
1384 infoPanel
, SLOT(requestDelayedItemInfo(KFileItem
)));
1387 QDockWidget
* foldersDock
= new QDockWidget(i18nc("@title:window", "Folders"));
1388 foldersDock
->setObjectName("foldersDock");
1389 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1390 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1391 foldersDock
->setWidget(foldersPanel
);
1393 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1394 foldersAction
->setText(i18nc("@title:window", "Folders"));
1395 foldersAction
->setShortcut(Qt::Key_F7
);
1396 foldersAction
->setIcon(KIcon("folder"));
1397 actionCollection()->addAction("show_folders_panel", foldersDock
->toggleViewAction());
1399 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1400 connect(this, SIGNAL(urlChanged(KUrl
)),
1401 foldersPanel
, SLOT(setUrl(KUrl
)));
1402 connect(foldersPanel
, SIGNAL(changeUrl(KUrl
, Qt::MouseButtons
)),
1403 this, SLOT(handlePlacesClick(KUrl
, Qt::MouseButtons
)));
1404 connect(foldersPanel
, SIGNAL(changeSelection(KFileItemList
)),
1405 this, SLOT(changeSelection(KFileItemList
)));
1409 QDockWidget
* terminalDock
= new QDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1410 terminalDock
->setObjectName("terminalDock");
1411 terminalDock
->setAllowedAreas(Qt::TopDockWidgetArea
| Qt::BottomDockWidgetArea
);
1412 Panel
* terminalPanel
= new TerminalPanel(terminalDock
);
1413 terminalDock
->setWidget(terminalPanel
);
1415 connect(terminalPanel
, SIGNAL(hideTerminalPanel()), terminalDock
, SLOT(hide()));
1417 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1418 terminalAction
->setText(i18nc("@title:window Shell terminal", "Terminal"));
1419 terminalAction
->setShortcut(Qt::Key_F4
);
1420 terminalAction
->setIcon(KIcon("utilities-terminal"));
1421 actionCollection()->addAction("show_terminal_panel", terminalDock
->toggleViewAction());
1423 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1424 connect(this, SIGNAL(urlChanged(KUrl
)),
1425 terminalPanel
, SLOT(setUrl(KUrl
)));
1428 const bool firstRun
= DolphinSettings::instance().generalSettings()->firstRun();
1430 foldersDock
->hide();
1432 terminalDock
->hide();
1436 QDockWidget
* placesDock
= new QDockWidget(i18nc("@title:window", "Places"));
1437 placesDock
->setObjectName("placesDock");
1438 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1440 PlacesPanel
* placesPanel
= new PlacesPanel(placesDock
);
1441 placesDock
->setWidget(placesPanel
);
1442 placesPanel
->setModel(DolphinSettings::instance().placesModel());
1443 placesPanel
->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff
);
1445 QAction
* placesAction
= placesDock
->toggleViewAction();
1446 placesAction
->setText(i18nc("@title:window", "Places"));
1447 placesAction
->setShortcut(Qt::Key_F9
);
1448 placesAction
->setIcon(KIcon("bookmarks"));
1449 actionCollection()->addAction("show_places_panel", placesDock
->toggleViewAction());
1451 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1452 connect(placesPanel
, SIGNAL(urlChanged(KUrl
, Qt::MouseButtons
)),
1453 this, SLOT(handlePlacesClick(KUrl
, Qt::MouseButtons
)));
1454 connect(this, SIGNAL(urlChanged(KUrl
)),
1455 placesPanel
, SLOT(setUrl(KUrl
)));
1458 void DolphinMainWindow::updateEditActions()
1460 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1461 if (list
.isEmpty()) {
1462 stateChanged("has_no_selection");
1464 stateChanged("has_selection");
1466 KActionCollection
* col
= actionCollection();
1467 QAction
* renameAction
= col
->action("rename");
1468 QAction
* moveToTrashAction
= col
->action("move_to_trash");
1469 QAction
* deleteAction
= col
->action("delete");
1470 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
1471 QAction
* deleteWithTrashShortcut
= col
->action("delete_shortcut"); // see DolphinViewActionHandler
1473 KFileItemListProperties
capabilities(list
);
1474 const bool enableMoveToTrash
= capabilities
.isLocal() && capabilities
.supportsMoving();
1476 renameAction
->setEnabled(capabilities
.supportsMoving());
1477 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1478 deleteAction
->setEnabled(capabilities
.supportsDeleting());
1479 deleteWithTrashShortcut
->setEnabled(capabilities
.supportsDeleting() && !enableMoveToTrash
);
1480 cutAction
->setEnabled(capabilities
.supportsMoving());
1482 updatePasteAction();
1485 void DolphinMainWindow::updateViewActions()
1487 m_actionHandler
->updateViewActions();
1489 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1490 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
1492 updateSplitAction();
1494 QAction
* editableLocactionAction
= actionCollection()->action("editable_location");
1495 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
1496 editableLocactionAction
->setChecked(urlNavigator
->isUrlEditable());
1499 void DolphinMainWindow::updateGoActions()
1501 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
1502 const KUrl
& currentUrl
= m_activeViewContainer
->url();
1503 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
1506 void DolphinMainWindow::rememberClosedTab(int index
)
1508 KMenu
* tabsMenu
= m_recentTabsMenu
->menu();
1510 const QString primaryPath
= m_viewTab
[index
].primaryView
->url().path();
1511 const QString iconName
= KMimeType::iconNameForUrl(primaryPath
);
1513 QAction
* action
= new QAction(squeezedText(primaryPath
), tabsMenu
);
1515 ClosedTab closedTab
;
1516 closedTab
.primaryUrl
= m_viewTab
[index
].primaryView
->url();
1518 if (m_viewTab
[index
].secondaryView
!= 0) {
1519 closedTab
.secondaryUrl
= m_viewTab
[index
].secondaryView
->url();
1520 closedTab
.isSplit
= true;
1522 closedTab
.isSplit
= false;
1525 action
->setData(QVariant::fromValue(closedTab
));
1526 action
->setIcon(KIcon(iconName
));
1528 // add the closed tab menu entry after the separator and
1529 // "Empty Recently Closed Tabs" entry
1530 if (tabsMenu
->actions().size() == 2) {
1531 tabsMenu
->addAction(action
);
1533 tabsMenu
->insertAction(tabsMenu
->actions().at(2), action
);
1536 // assure that only up to 8 closed tabs are shown in the menu
1537 if (tabsMenu
->actions().size() > 8) {
1538 tabsMenu
->removeAction(tabsMenu
->actions().last());
1540 actionCollection()->action("closed_tabs")->setEnabled(true);
1541 KAcceleratorManager::manage(tabsMenu
);
1544 void DolphinMainWindow::clearStatusBar()
1546 m_activeViewContainer
->statusBar()->clear();
1549 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
1551 connect(container
, SIGNAL(showFilterBarChanged(bool)),
1552 this, SLOT(updateFilterBarAction(bool)));
1554 DolphinView
* view
= container
->view();
1555 connect(view
, SIGNAL(selectionChanged(KFileItemList
)),
1556 this, SLOT(slotSelectionChanged(KFileItemList
)));
1557 connect(view
, SIGNAL(requestItemInfo(KFileItem
)),
1558 this, SLOT(slotRequestItemInfo(KFileItem
)));
1559 connect(view
, SIGNAL(activated()),
1560 this, SLOT(toggleActiveView()));
1561 connect(view
, SIGNAL(tabRequested(const KUrl
&)),
1562 this, SLOT(openNewTab(const KUrl
&)));
1564 const KUrlNavigator
* navigator
= container
->urlNavigator();
1565 connect(navigator
, SIGNAL(urlChanged(const KUrl
&)),
1566 this, SLOT(changeUrl(const KUrl
&)));
1567 connect(navigator
, SIGNAL(historyChanged()),
1568 this, SLOT(updateHistory()));
1569 connect(navigator
, SIGNAL(editableStateChanged(bool)),
1570 this, SLOT(slotEditableStateChanged(bool)));
1573 void DolphinMainWindow::updateSplitAction()
1575 QAction
* splitAction
= actionCollection()->action("split_view");
1576 if (m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
1577 if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
1578 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
1579 splitAction
->setToolTip(i18nc("@info", "Close right view"));
1580 splitAction
->setIcon(KIcon("view-right-close"));
1582 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
1583 splitAction
->setToolTip(i18nc("@info", "Close left view"));
1584 splitAction
->setIcon(KIcon("view-left-close"));
1587 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
1588 splitAction
->setToolTip(i18nc("@info", "Split view"));
1589 splitAction
->setIcon(KIcon("view-right-new"));
1593 QString
DolphinMainWindow::tabName(const KUrl
& url
) const
1596 if (url
.equals(KUrl("file:///"))) {
1599 name
= url
.fileName();
1600 if (name
.isEmpty()) {
1601 name
= url
.protocol();
1603 // Make sure that a '&' inside the directory name is displayed correctly
1604 // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
1605 name
.replace('&', "&&");
1611 bool DolphinMainWindow::isKompareInstalled() const
1613 static bool initialized
= false;
1614 static bool installed
= false;
1616 // TODO: maybe replace this approach later by using a menu
1617 // plugin like kdiff3plugin.cpp
1618 installed
= !KGlobal::dirs()->findExe("kompare").isEmpty();
1624 void DolphinMainWindow::createSecondaryView(int tabIndex
)
1626 QSplitter
* splitter
= m_viewTab
[tabIndex
].splitter
;
1627 const int newWidth
= (m_viewTab
[tabIndex
].primaryView
->width() - splitter
->handleWidth()) / 2;
1629 const DolphinView
* view
= m_viewTab
[tabIndex
].primaryView
->view();
1630 m_viewTab
[tabIndex
].secondaryView
= new DolphinViewContainer(this, 0, view
->rootUrl());
1631 splitter
->addWidget(m_viewTab
[tabIndex
].secondaryView
);
1632 splitter
->setSizes(QList
<int>() << newWidth
<< newWidth
);
1633 connectViewSignals(m_viewTab
[tabIndex
].secondaryView
);
1634 m_viewTab
[tabIndex
].secondaryView
->view()->reload();
1635 m_viewTab
[tabIndex
].secondaryView
->setActive(false);
1636 m_viewTab
[tabIndex
].secondaryView
->show();
1639 QString
DolphinMainWindow::tabProperty(const QString
& property
, int tabIndex
) const
1641 return "Tab " + QString::number(tabIndex
) + ' ' + property
;
1644 void DolphinMainWindow::setUrlAsCaption(const KUrl
& url
)
1647 if (url
.equals(KUrl("file:///"))) {
1650 caption
= url
.fileName();
1651 if (caption
.isEmpty()) {
1652 caption
= url
.protocol();
1656 setCaption(caption
);
1659 QString
DolphinMainWindow::squeezedText(const QString
& text
) const
1661 const QFontMetrics fm
= fontMetrics();
1662 return fm
.elidedText(text
, Qt::ElideMiddle
, fm
.maxWidth() * 10);
1665 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
1666 KIO::FileUndoManager::UiInterface()
1670 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
1674 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
1676 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
1678 DolphinStatusBar
* statusBar
= mainWin
->activeViewContainer()->statusBar();
1679 statusBar
->setMessage(job
->errorString(), DolphinStatusBar::Error
);
1681 KIO::FileUndoManager::UiInterface::jobError(job
);
1685 #include "dolphinmainwindow.moc"