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 if (backAction
!= 0) {
302 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
305 QAction
* forwardAction
= actionCollection()->action("go_forward");
306 if (forwardAction
!= 0) {
307 forwardAction
->setEnabled(index
> 0);
311 void DolphinMainWindow::updateFilterBarAction(bool show
)
313 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
314 showFilterBarAction
->setChecked(show
);
317 void DolphinMainWindow::openNewMainWindow()
319 DolphinApplication::app()->createMainWindow()->show();
322 void DolphinMainWindow::openNewTab()
324 openNewTab(m_activeViewContainer
->url());
325 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
327 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
328 if (navigator
->isUrlEditable()) {
329 // if a new tab is opened and the URL is editable, assure that
330 // the user can edit the URL without manually setting the focus
331 navigator
->setFocus();
335 void DolphinMainWindow::openNewTab(const KUrl
& url
)
337 const KIcon icon
= KIcon(KMimeType::iconNameForUrl(m_activeViewContainer
->url()));
338 if (m_viewTab
.count() == 1) {
339 // Only one view is open currently and hence no tab is shown at
340 // all. Before creating a tab for 'url', provide a tab for the current URL.
341 m_tabBar
->addTab(icon
, squeezedText(tabName(m_activeViewContainer
->url())));
342 m_tabBar
->blockSignals(false);
345 m_tabBar
->addTab(icon
, squeezedText(tabName(url
)));
348 viewTab
.splitter
= new QSplitter(this);
349 viewTab
.splitter
->setChildrenCollapsible(false);
350 viewTab
.primaryView
= new DolphinViewContainer(this, viewTab
.splitter
, url
);
351 viewTab
.primaryView
->setActive(false);
352 connectViewSignals(viewTab
.primaryView
);
353 viewTab
.primaryView
->view()->reload();
355 m_viewTab
.append(viewTab
);
357 actionCollection()->action("close_tab")->setEnabled(true);
359 // provide a split view, if the startup settings are set this way
360 const GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
361 if (generalSettings
->splitView()) {
362 const int tabIndex
= m_viewTab
.count() - 1;
363 createSecondaryView(tabIndex
);
364 m_viewTab
[tabIndex
].secondaryView
->setActive(true);
365 m_viewTab
[tabIndex
].isPrimaryViewActive
= false;
369 void DolphinMainWindow::activateNextTab()
371 if ((m_viewTab
.count() == 1) || (m_tabBar
->count() < 2)) {
375 const int tabIndex
= (m_tabBar
->currentIndex() + 1) % m_tabBar
->count();
376 m_tabBar
->setCurrentIndex(tabIndex
);
379 void DolphinMainWindow::activatePrevTab()
381 if ((m_viewTab
.count() == 1) || (m_tabBar
->count() < 2)) {
385 int tabIndex
= m_tabBar
->currentIndex() - 1;
386 if (tabIndex
== -1) {
387 tabIndex
= m_tabBar
->count() - 1;
389 m_tabBar
->setCurrentIndex(tabIndex
);
392 void DolphinMainWindow::openInNewTab()
394 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
395 if ((list
.count() == 1) && list
[0].isDir()) {
396 openNewTab(m_activeViewContainer
->view()->selectedUrls()[0]);
400 void DolphinMainWindow::openInNewWindow()
402 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
403 if ((list
.count() == 1) && list
[0].isDir()) {
404 DolphinMainWindow
* window
= DolphinApplication::app()->createMainWindow();
405 window
->changeUrl(m_activeViewContainer
->view()->selectedUrls()[0]);
410 void DolphinMainWindow::toggleActiveView()
412 if (m_viewTab
[m_tabIndex
].secondaryView
== 0) {
413 // only one view is available
417 Q_ASSERT(m_activeViewContainer
!= 0);
418 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
420 DolphinViewContainer
* left
= m_viewTab
[m_tabIndex
].primaryView
;
421 DolphinViewContainer
* right
= m_viewTab
[m_tabIndex
].secondaryView
;
422 setActiveViewContainer(m_activeViewContainer
== right
? left
: right
);
425 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
427 DolphinSettings
& settings
= DolphinSettings::instance();
428 GeneralSettings
* generalSettings
= settings
.generalSettings();
430 // Find out if Dolphin is closed directly by the user or
431 // by the session manager because the session is closed
432 bool closedByUser
= true;
433 DolphinApplication
*application
= qobject_cast
<DolphinApplication
*>(qApp
);
434 if (application
&& application
->sessionSaving()) {
435 closedByUser
= false;
438 if ((m_viewTab
.count() > 1) && generalSettings
->confirmClosingMultipleTabs() && closedByUser
) {
439 // Ask the user if he really wants to quit and close all tabs.
440 // Open a confirmation dialog with 3 buttons:
441 // KDialog::Yes -> Quit
442 // KDialog::No -> Close only the current tab
443 // KDialog::Cancel -> do nothing
444 KDialog
*dialog
= new KDialog(this, Qt::Dialog
);
445 dialog
->setCaption(i18nc("@title:window", "Confirmation"));
446 dialog
->setButtons(KDialog::Yes
| KDialog::No
| KDialog::Cancel
);
447 dialog
->setModal(true);
448 dialog
->showButtonSeparator(true);
449 dialog
->setButtonGuiItem(KDialog::Yes
, KStandardGuiItem::quit());
450 dialog
->setButtonGuiItem(KDialog::No
, KGuiItem(i18n("C&lose Current Tab"), KIcon("tab-close")));
451 dialog
->setButtonGuiItem(KDialog::Cancel
, KStandardGuiItem::cancel());
452 dialog
->setDefaultButton(KDialog::Yes
);
454 bool doNotAskAgainCheckboxResult
= false;
456 const int result
= KMessageBox::createKMessageBox(dialog
,
457 QMessageBox::Warning
,
458 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
460 i18n("Do not ask again"),
461 &doNotAskAgainCheckboxResult
,
462 KMessageBox::Notify
);
464 if (doNotAskAgainCheckboxResult
) {
465 generalSettings
->setConfirmClosingMultipleTabs(false);
473 // Close only the current tab
481 generalSettings
->setFirstRun(false);
485 KXmlGuiWindow::closeEvent(event
);
488 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
490 const int tabCount
= m_viewTab
.count();
491 group
.writeEntry("Tab Count", tabCount
);
492 group
.writeEntry("Active Tab Index", m_tabBar
->currentIndex());
494 for (int i
= 0; i
< tabCount
; ++i
) {
495 const DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
496 group
.writeEntry(tabProperty("Primary URL", i
), cont
->url().url());
497 group
.writeEntry(tabProperty("Primary Editable", i
), cont
->isUrlEditable());
499 cont
= m_viewTab
[i
].secondaryView
;
501 group
.writeEntry(tabProperty("Secondary URL", i
), cont
->url().url());
502 group
.writeEntry(tabProperty("Secondary Editable", i
), cont
->isUrlEditable());
507 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
509 const int tabCount
= group
.readEntry("Tab Count", 1);
510 for (int i
= 0; i
< tabCount
; ++i
) {
511 DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
513 cont
->setUrl(group
.readEntry(tabProperty("Primary URL", i
)));
514 const bool editable
= group
.readEntry(tabProperty("Primary Editable", i
), false);
515 cont
->urlNavigator()->setUrlEditable(editable
);
517 cont
= m_viewTab
[i
].secondaryView
;
518 const QString secondaryUrl
= group
.readEntry(tabProperty("Secondary URL", i
));
519 if (!secondaryUrl
.isEmpty()) {
521 // a secondary view should be shown, but no one is available
522 // currently -> create a new view
524 cont
= m_viewTab
[i
].secondaryView
;
528 cont
->setUrl(secondaryUrl
);
529 const bool editable
= group
.readEntry(tabProperty("Secondary Editable", i
), false);
530 cont
->urlNavigator()->setUrlEditable(editable
);
531 } else if (cont
!= 0) {
532 // no secondary view should be shown, but the default setting shows
533 // one already -> close the view
537 // openNewTab() needs to be called only tabCount - 1 times
538 if (i
!= tabCount
- 1) {
543 const int index
= group
.readEntry("Active Tab Index", 0);
544 m_tabBar
->setCurrentIndex(index
);
547 void DolphinMainWindow::updateNewMenu()
549 m_newMenu
->slotCheckUpToDate();
550 m_newMenu
->setPopupFiles(activeViewContainer()->url());
553 void DolphinMainWindow::createDirectory()
555 m_newMenu
->setPopupFiles(activeViewContainer()->url());
556 m_newMenu
->createDirectory();
559 void DolphinMainWindow::quit()
564 void DolphinMainWindow::showErrorMessage(const QString
& message
)
566 if (!message
.isEmpty()) {
567 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
568 statusBar
->setMessage(message
, DolphinStatusBar::Error
);
572 void DolphinMainWindow::slotUndoAvailable(bool available
)
574 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
575 if (undoAction
!= 0) {
576 undoAction
->setEnabled(available
);
580 void DolphinMainWindow::restoreClosedTab(QAction
* action
)
582 if (action
->data().toBool()) {
583 // clear all actions except the "Empty Recently Closed Tabs"
584 // action and the separator
585 QList
<QAction
*> actions
= m_recentTabsMenu
->menu()->actions();
586 const int count
= actions
.size();
587 for (int i
= 2; i
< count
; ++i
) {
588 m_recentTabsMenu
->menu()->removeAction(actions
.at(i
));
591 const ClosedTab closedTab
= action
->data().value
<ClosedTab
>();
592 openNewTab(closedTab
.primaryUrl
);
593 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
595 if (closedTab
.isSplit
) {
596 // create secondary view
598 m_viewTab
[m_tabIndex
].secondaryView
->setUrl(closedTab
.secondaryUrl
);
601 m_recentTabsMenu
->removeAction(action
);
604 if (m_recentTabsMenu
->menu()->actions().count() == 2) {
605 m_recentTabsMenu
->setEnabled(false);
609 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
611 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
612 if (undoAction
!= 0) {
613 undoAction
->setText(text
);
617 void DolphinMainWindow::undo()
620 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
621 KIO::FileUndoManager::self()->undo();
624 void DolphinMainWindow::cut()
626 m_activeViewContainer
->view()->cutSelectedItems();
629 void DolphinMainWindow::copy()
631 m_activeViewContainer
->view()->copySelectedItems();
634 void DolphinMainWindow::paste()
636 m_activeViewContainer
->view()->paste();
639 void DolphinMainWindow::updatePasteAction()
641 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
642 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
643 pasteAction
->setEnabled(pasteInfo
.first
);
644 pasteAction
->setText(pasteInfo
.second
);
647 void DolphinMainWindow::selectAll()
651 // if the URL navigator is editable and focused, select the whole
652 // URL instead of all items of the view
654 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
655 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit(); // krazy:exclude=qclasses
656 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
657 lineEdit
->hasFocus();
659 lineEdit
->selectAll();
661 m_activeViewContainer
->view()->selectAll();
665 void DolphinMainWindow::invertSelection()
668 m_activeViewContainer
->view()->invertSelection();
671 void DolphinMainWindow::toggleSplitView()
673 if (m_viewTab
[m_tabIndex
].secondaryView
== 0) {
674 createSecondaryView(m_tabIndex
);
675 setActiveViewContainer(m_viewTab
[m_tabIndex
].secondaryView
);
676 } else if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
677 // remove secondary view
678 m_viewTab
[m_tabIndex
].secondaryView
->close();
679 m_viewTab
[m_tabIndex
].secondaryView
->deleteLater();
680 m_viewTab
[m_tabIndex
].secondaryView
= 0;
682 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
684 // The primary view is active and should be closed. Hence from a users point of view
685 // the content of the secondary view should be moved to the primary view.
686 // From an implementation point of view it is more efficient to close
687 // the primary view and exchange the internal pointers afterwards.
689 m_viewTab
[m_tabIndex
].primaryView
->close();
690 m_viewTab
[m_tabIndex
].primaryView
->deleteLater();
691 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
692 m_viewTab
[m_tabIndex
].secondaryView
= 0;
694 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
700 void DolphinMainWindow::reloadView()
703 m_activeViewContainer
->view()->reload();
706 void DolphinMainWindow::stopLoading()
710 void DolphinMainWindow::toggleFilterBarVisibility(bool show
)
712 m_activeViewContainer
->showFilterBar(show
);
715 void DolphinMainWindow::toggleEditLocation()
719 QAction
* action
= actionCollection()->action("editable_location");
720 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
721 urlNavigator
->setUrlEditable(action
->isChecked());
724 void DolphinMainWindow::replaceLocation()
726 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
727 navigator
->setUrlEditable(true);
728 navigator
->setFocus();
730 // select the whole text of the combo box editor
731 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit(); // krazy:exclude=qclasses
732 const QString text
= lineEdit
->text();
733 lineEdit
->setSelection(0, text
.length());
736 void DolphinMainWindow::goBack()
739 m_activeViewContainer
->urlNavigator()->goBack();
742 void DolphinMainWindow::goForward()
745 m_activeViewContainer
->urlNavigator()->goForward();
748 void DolphinMainWindow::goUp()
751 m_activeViewContainer
->urlNavigator()->goUp();
754 void DolphinMainWindow::goHome()
757 m_activeViewContainer
->urlNavigator()->goHome();
760 void DolphinMainWindow::compareFiles()
762 // The method is only invoked if exactly 2 files have
763 // been selected. The selected files may be:
764 // - both in the primary view
765 // - both in the secondary view
766 // - one in the primary view and the other in the secondary
768 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
772 KUrl::List urls
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedUrls();
774 switch (urls
.count()) {
776 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
!= 0);
777 urls
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedUrls();
778 Q_ASSERT(urls
.count() == 2);
786 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
!= 0);
787 urls
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedUrls();
788 Q_ASSERT(urls
.count() == 1);
800 // may not happen: compareFiles may only get invoked if 2
801 // files are selected
806 QString
command("kompare -c \"");
807 command
.append(urlA
.pathOrUrl());
808 command
.append("\" \"");
809 command
.append(urlB
.pathOrUrl());
810 command
.append('\"');
811 KRun::runCommand(command
, "Kompare", "kompare", this);
814 void DolphinMainWindow::toggleShowMenuBar()
816 const bool visible
= menuBar()->isVisible();
817 menuBar()->setVisible(!visible
);
820 void DolphinMainWindow::openTerminal()
822 QString
dir(QDir::homePath());
824 // If the given directory is not local, it can still be the URL of an
825 // ioslave using UDS_LOCAL_PATH which to be converted first.
826 KUrl url
= KIO::NetAccess::mostLocalUrl(m_activeViewContainer
->url(), this);
828 //If the URL is local after the above conversion, set the directory.
829 if (url
.isLocalFile()) {
830 dir
= url
.toLocalFile();
833 KToolInvocation::invokeTerminal(QString(), dir
);
836 void DolphinMainWindow::editSettings()
838 if (m_settingsDialog
== 0) {
839 const KUrl
& url
= activeViewContainer()->url();
840 m_settingsDialog
= new DolphinSettingsDialog(url
, this);
841 m_settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
842 m_settingsDialog
->show();
844 m_settingsDialog
->raise();
848 void DolphinMainWindow::setActiveTab(int index
)
850 Q_ASSERT(index
>= 0);
851 Q_ASSERT(index
< m_viewTab
.count());
852 if (index
== m_tabIndex
) {
856 // hide current tab content
857 ViewTab
& hiddenTab
= m_viewTab
[m_tabIndex
];
858 hiddenTab
.isPrimaryViewActive
= hiddenTab
.primaryView
->isActive();
859 hiddenTab
.primaryView
->setActive(false);
860 if (hiddenTab
.secondaryView
!= 0) {
861 hiddenTab
.secondaryView
->setActive(false);
863 QSplitter
* splitter
= m_viewTab
[m_tabIndex
].splitter
;
865 m_centralWidgetLayout
->removeWidget(splitter
);
867 // show active tab content
870 ViewTab
& viewTab
= m_viewTab
[index
];
871 m_centralWidgetLayout
->addWidget(viewTab
.splitter
, 1);
872 viewTab
.primaryView
->show();
873 if (viewTab
.secondaryView
!= 0) {
874 viewTab
.secondaryView
->show();
876 viewTab
.splitter
->show();
878 setActiveViewContainer(viewTab
.isPrimaryViewActive
? viewTab
.primaryView
:
879 viewTab
.secondaryView
);
882 void DolphinMainWindow::closeTab()
884 closeTab(m_tabBar
->currentIndex());
887 void DolphinMainWindow::closeTab(int index
)
889 Q_ASSERT(index
>= 0);
890 Q_ASSERT(index
< m_viewTab
.count());
891 if (m_viewTab
.count() == 1) {
892 // the last tab may never get closed
896 if (index
== m_tabIndex
) {
897 // The tab that should be closed is the active tab. Activate the
898 // previous tab before closing the tab.
899 m_tabBar
->setCurrentIndex((index
> 0) ? index
- 1 : 1);
901 rememberClosedTab(index
);
904 m_viewTab
[index
].primaryView
->deleteLater();
905 if (m_viewTab
[index
].secondaryView
!= 0) {
906 m_viewTab
[index
].secondaryView
->deleteLater();
908 m_viewTab
[index
].splitter
->deleteLater();
909 m_viewTab
.erase(m_viewTab
.begin() + index
);
911 m_tabBar
->blockSignals(true);
912 m_tabBar
->removeTab(index
);
914 if (m_tabIndex
> index
) {
916 Q_ASSERT(m_tabIndex
>= 0);
919 // if only one tab is left, also remove the tab entry so that
920 // closing the last tab is not possible
921 if (m_viewTab
.count() == 1) {
922 m_tabBar
->removeTab(0);
923 actionCollection()->action("close_tab")->setEnabled(false);
925 m_tabBar
->blockSignals(false);
929 void DolphinMainWindow::openTabContextMenu(int index
, const QPoint
& pos
)
933 QAction
* newTabAction
= menu
.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab"));
934 newTabAction
->setShortcut(actionCollection()->action("new_tab")->shortcut());
936 QAction
* closeOtherTabsAction
= menu
.addAction(KIcon("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs"));
938 QAction
* closeTabAction
= menu
.addAction(KIcon("tab-close"), i18nc("@action:inmenu", "Close Tab"));
939 closeTabAction
->setShortcut(actionCollection()->action("close_tab")->shortcut());
940 QAction
* selectedAction
= menu
.exec(pos
);
941 if (selectedAction
== newTabAction
) {
942 const ViewTab
& tab
= m_viewTab
[index
];
943 Q_ASSERT(tab
.primaryView
!= 0);
944 const KUrl url
= (tab
.secondaryView
!= 0) && tab
.secondaryView
->isActive() ?
945 tab
.secondaryView
->url() : tab
.primaryView
->url();
947 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
948 } else if (selectedAction
== closeOtherTabsAction
) {
949 const int count
= m_tabBar
->count();
950 for (int i
= 0; i
< index
; ++i
) {
953 for (int i
= index
+ 1; i
< count
; ++i
) {
956 } else if (selectedAction
== closeTabAction
) {
961 void DolphinMainWindow::handlePlacesClick(const KUrl
& url
, Qt::MouseButtons buttons
)
963 if (buttons
& Qt::MidButton
) {
965 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
971 void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent
* event
, bool& canDecode
)
973 canDecode
= KUrl::List::canDecode(event
->mimeData());
976 void DolphinMainWindow::searchItems(const KUrl
& url
)
978 m_activeViewContainer
->setUrl(url
);
981 void DolphinMainWindow::slotTabMoved(int from
, int to
)
983 m_viewTab
.move(from
, to
);
984 m_tabIndex
= m_tabBar
->currentIndex();
987 void DolphinMainWindow::slotSearchBoxTextChanged(const QString
& text
)
989 m_searchOptionsConfigurator
->setVisible(!text
.isEmpty());
992 void DolphinMainWindow::init()
994 DolphinSettings
& settings
= DolphinSettings::instance();
996 // Check whether Dolphin runs the first time. If yes then
997 // a proper default window size is given at the end of DolphinMainWindow::init().
998 GeneralSettings
* generalSettings
= settings
.generalSettings();
999 const bool firstRun
= generalSettings
->firstRun();
1001 generalSettings
->setViewPropsTimestamp(QDateTime::currentDateTime());
1004 setAcceptDrops(true);
1006 m_viewTab
[m_tabIndex
].splitter
= new QSplitter(this);
1007 m_viewTab
[m_tabIndex
].splitter
->setChildrenCollapsible(false);
1011 const KUrl
& homeUrl
= generalSettings
->homeUrl();
1012 setUrlAsCaption(homeUrl
);
1013 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
1014 connect(m_actionHandler
, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
1015 connect(m_actionHandler
, SIGNAL(createDirectory()), SLOT(createDirectory()));
1016 ViewProperties
props(homeUrl
);
1017 m_viewTab
[m_tabIndex
].primaryView
= new DolphinViewContainer(this,
1018 m_viewTab
[m_tabIndex
].splitter
,
1021 m_activeViewContainer
= m_viewTab
[m_tabIndex
].primaryView
;
1022 connectViewSignals(m_activeViewContainer
);
1023 DolphinView
* view
= m_activeViewContainer
->view();
1025 m_activeViewContainer
->show();
1026 m_actionHandler
->setCurrentView(view
);
1028 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
1029 connect(this, SIGNAL(urlChanged(const KUrl
&)),
1030 m_remoteEncoding
, SLOT(slotAboutToOpenUrl()));
1032 m_searchOptionsConfigurator
= new DolphinSearchOptionsConfigurator(this);
1033 m_searchOptionsConfigurator
->hide();
1035 m_tabBar
= new KTabBar(this);
1036 m_tabBar
->setMovable(true);
1037 m_tabBar
->setTabsClosable(true);
1038 connect(m_tabBar
, SIGNAL(currentChanged(int)),
1039 this, SLOT(setActiveTab(int)));
1040 connect(m_tabBar
, SIGNAL(tabCloseRequested(int)),
1041 this, SLOT(closeTab(int)));
1042 connect(m_tabBar
, SIGNAL(contextMenu(int, const QPoint
&)),
1043 this, SLOT(openTabContextMenu(int, const QPoint
&)));
1044 connect(m_tabBar
, SIGNAL(newTabRequest()),
1045 this, SLOT(openNewTab()));
1046 connect(m_tabBar
, SIGNAL(testCanDecode(const QDragMoveEvent
*, bool&)),
1047 this, SLOT(slotTestCanDecode(const QDragMoveEvent
*, bool&)));
1048 connect(m_tabBar
, SIGNAL(wheelDelta(int)),
1049 this, SLOT(slotWheelMoved(int)));
1050 connect(m_tabBar
, SIGNAL(mouseMiddleClick(int)),
1051 this, SLOT(closeTab(int)));
1052 connect(m_tabBar
, SIGNAL(tabMoved(int, int)),
1053 this, SLOT(slotTabMoved(int, int)));
1055 m_tabBar
->blockSignals(true); // signals get unblocked after at least 2 tabs are open
1057 QWidget
* centralWidget
= new QWidget(this);
1058 m_centralWidgetLayout
= new QVBoxLayout(centralWidget
);
1059 m_centralWidgetLayout
->setSpacing(0);
1060 m_centralWidgetLayout
->setMargin(0);
1061 m_centralWidgetLayout
->addWidget(m_searchOptionsConfigurator
);
1062 m_centralWidgetLayout
->addWidget(m_tabBar
);
1063 m_centralWidgetLayout
->addWidget(m_viewTab
[m_tabIndex
].splitter
, 1);
1065 setCentralWidget(centralWidget
);
1067 emit
urlChanged(homeUrl
);
1069 setupGUI(Keys
| Save
| Create
| ToolBar
);
1071 m_searchBox
->setParent(toolBar("searchToolBar"));
1072 m_searchBox
->show();
1073 connect(m_searchBox
, SIGNAL(textChanged(const QString
&)),
1074 this, SLOT(slotSearchBoxTextChanged(const QString
&)));
1076 stateChanged("new_file");
1078 QClipboard
* clipboard
= QApplication::clipboard();
1079 connect(clipboard
, SIGNAL(dataChanged()),
1080 this, SLOT(updatePasteAction()));
1081 updatePasteAction();
1084 if (generalSettings
->splitView()) {
1087 updateViewActions();
1089 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1090 showFilterBarAction
->setChecked(generalSettings
->filterBar());
1093 // assure a proper default size if Dolphin runs the first time
1097 m_showMenuBar
->setChecked(!menuBar()->isHidden()); // workaround for bug #171080
1100 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer
* viewContainer
)
1102 Q_ASSERT(viewContainer
!= 0);
1103 Q_ASSERT((viewContainer
== m_viewTab
[m_tabIndex
].primaryView
) ||
1104 (viewContainer
== m_viewTab
[m_tabIndex
].secondaryView
));
1105 if (m_activeViewContainer
== viewContainer
) {
1109 m_activeViewContainer
->setActive(false);
1110 m_activeViewContainer
= viewContainer
;
1112 // Activating the view container might trigger a recursive setActiveViewContainer() call
1113 // inside DolphinMainWindow::toggleActiveView() when having a split view. Temporary
1114 // disconnect the activated() signal in this case:
1115 disconnect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1116 m_activeViewContainer
->setActive(true);
1117 connect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1119 m_actionHandler
->setCurrentView(viewContainer
->view());
1122 updateEditActions();
1123 updateViewActions();
1126 const KUrl
& url
= m_activeViewContainer
->url();
1127 setUrlAsCaption(url
);
1128 if (m_viewTab
.count() > 1 && m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
1129 m_tabBar
->setTabText(m_tabIndex
, tabName(url
));
1130 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(KMimeType::iconNameForUrl(url
)));
1133 emit
urlChanged(url
);
1136 void DolphinMainWindow::setupActions()
1138 // setup 'File' menu
1139 m_newMenu
= new DolphinNewMenu(this, this);
1140 KMenu
* menu
= m_newMenu
->menu();
1141 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1142 menu
->setIcon(KIcon("document-new"));
1143 connect(menu
, SIGNAL(aboutToShow()),
1144 this, SLOT(updateNewMenu()));
1146 KAction
* newWindow
= actionCollection()->addAction("new_window");
1147 newWindow
->setIcon(KIcon("window-new"));
1148 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1149 newWindow
->setShortcut(Qt::CTRL
| Qt::Key_N
);
1150 connect(newWindow
, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1152 KAction
* newTab
= actionCollection()->addAction("new_tab");
1153 newTab
->setIcon(KIcon("tab-new"));
1154 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1155 newTab
->setShortcut(KShortcut(Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
));
1156 connect(newTab
, SIGNAL(triggered()), this, SLOT(openNewTab()));
1158 KAction
* closeTab
= actionCollection()->addAction("close_tab");
1159 closeTab
->setIcon(KIcon("tab-close"));
1160 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1161 closeTab
->setShortcut(Qt::CTRL
| Qt::Key_W
);
1162 closeTab
->setEnabled(false);
1163 connect(closeTab
, SIGNAL(triggered()), this, SLOT(closeTab()));
1165 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1167 // setup 'Edit' menu
1168 KStandardAction::undo(this,
1170 actionCollection());
1172 // need to remove shift+del from cut action, else the shortcut for deletejob
1174 KAction
* cut
= KStandardAction::cut(this, SLOT(cut()), actionCollection());
1175 KShortcut cutShortcut
= cut
->shortcut();
1176 cutShortcut
.remove(Qt::SHIFT
+ Qt::Key_Delete
, KShortcut::KeepEmpty
);
1177 cut
->setShortcut(cutShortcut
);
1178 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1179 KAction
* paste
= KStandardAction::paste(this, SLOT(paste()), actionCollection());
1180 // The text of the paste-action is modified dynamically by Dolphin
1181 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1182 // due to the long text, the text "Paste" is used:
1183 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1185 KAction
* selectAll
= actionCollection()->addAction("select_all");
1186 selectAll
->setText(i18nc("@action:inmenu Edit", "Select All"));
1187 selectAll
->setShortcut(Qt::CTRL
+ Qt::Key_A
);
1188 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
1190 KAction
* invertSelection
= actionCollection()->addAction("invert_selection");
1191 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1192 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1193 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
1195 // setup 'View' menu
1196 // (note that most of it is set up in DolphinViewActionHandler)
1198 KAction
* split
= actionCollection()->addAction("split_view");
1199 split
->setShortcut(Qt::Key_F3
);
1200 updateSplitAction();
1201 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1203 KAction
* reload
= actionCollection()->addAction("reload");
1204 reload
->setText(i18nc("@action:inmenu View", "Reload"));
1205 reload
->setShortcut(Qt::Key_F5
);
1206 reload
->setIcon(KIcon("view-refresh"));
1207 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
1209 KAction
* stop
= actionCollection()->addAction("stop");
1210 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1211 stop
->setIcon(KIcon("process-stop"));
1212 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
1214 KToggleAction
* showFullLocation
= actionCollection()->add
<KToggleAction
>("editable_location");
1215 showFullLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1216 showFullLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
1217 connect(showFullLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1219 KAction
* replaceLocation
= actionCollection()->addAction("replace_location");
1220 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1221 replaceLocation
->setShortcut(Qt::Key_F6
);
1222 connect(replaceLocation
, SIGNAL(triggered()), this, SLOT(replaceLocation()));
1225 KAction
* backAction
= KStandardAction::back(this, SLOT(goBack()), actionCollection());
1226 KShortcut backShortcut
= backAction
->shortcut();
1227 backShortcut
.setAlternate(Qt::Key_Backspace
);
1228 backAction
->setShortcut(backShortcut
);
1230 m_recentTabsMenu
= new KActionMenu(i18n("Recently Closed Tabs"), this);
1231 m_recentTabsMenu
->setIcon(KIcon("edit-undo"));
1232 actionCollection()->addAction("closed_tabs", m_recentTabsMenu
);
1233 connect(m_recentTabsMenu
->menu(), SIGNAL(triggered(QAction
*)),
1234 this, SLOT(restoreClosedTab(QAction
*)));
1236 QAction
* action
= new QAction("Empty Recently Closed Tabs", m_recentTabsMenu
);
1237 action
->setIcon(KIcon("edit-clear-list"));
1238 action
->setData(QVariant::fromValue(true));
1239 m_recentTabsMenu
->addAction(action
);
1240 m_recentTabsMenu
->addSeparator();
1241 m_recentTabsMenu
->setEnabled(false);
1243 KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1244 KStandardAction::up(this, SLOT(goUp()), actionCollection());
1245 KStandardAction::home(this, SLOT(goHome()), actionCollection());
1247 // setup 'Tools' menu
1248 KToggleAction
* showSearchBar
= actionCollection()->add
<KToggleAction
>("show_search_bar");
1249 showSearchBar
->setText(i18nc("@action:inmenu Tools", "Show Search Bar"));
1250 showSearchBar
->setShortcut(Qt::CTRL
| Qt::Key_S
);
1251 connect(showSearchBar
, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
1253 KToggleAction
* showFilterBar
= actionCollection()->add
<KToggleAction
>("show_filter_bar");
1254 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1255 showFilterBar
->setIcon(KIcon("view-filter"));
1256 showFilterBar
->setShortcut(Qt::CTRL
| Qt::Key_I
);
1257 connect(showFilterBar
, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
1259 KAction
* compareFiles
= actionCollection()->addAction("compare_files");
1260 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1261 compareFiles
->setIcon(KIcon("kompare"));
1262 compareFiles
->setEnabled(false);
1263 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
1265 KAction
* openTerminal
= actionCollection()->addAction("open_terminal");
1266 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1267 openTerminal
->setIcon(KIcon("utilities-terminal"));
1268 openTerminal
->setShortcut(Qt::SHIFT
| Qt::Key_F4
);
1269 connect(openTerminal
, SIGNAL(triggered()), this, SLOT(openTerminal()));
1271 // setup 'Settings' menu
1272 m_showMenuBar
= KStandardAction::showMenubar(this, SLOT(toggleShowMenuBar()), actionCollection());
1273 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1275 // not in menu actions
1276 KAction
* activateNextTab
= actionCollection()->addAction("activate_next_tab");
1277 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1278 connect(activateNextTab
, SIGNAL(triggered()), SLOT(activateNextTab()));
1279 activateNextTab
->setShortcuts(QApplication::isRightToLeft() ? KStandardShortcut::tabPrev() :
1280 KStandardShortcut::tabNext());
1282 KAction
* activatePrevTab
= actionCollection()->addAction("activate_prev_tab");
1283 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1284 connect(activatePrevTab
, SIGNAL(triggered()), SLOT(activatePrevTab()));
1285 activatePrevTab
->setShortcuts(QApplication::isRightToLeft() ? KStandardShortcut::tabNext() :
1286 KStandardShortcut::tabPrev());
1289 KAction
* openInNewTab
= actionCollection()->addAction("open_in_new_tab");
1290 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1291 openInNewTab
->setIcon(KIcon("tab-new"));
1292 connect(openInNewTab
, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1294 KAction
* openInNewWindow
= actionCollection()->addAction("open_in_new_window");
1295 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1296 openInNewWindow
->setIcon(KIcon("window-new"));
1297 connect(openInNewWindow
, SIGNAL(triggered()), this, SLOT(openInNewWindow()));
1300 m_searchBox
= new DolphinSearchBox(this);
1301 connect(m_searchBox
, SIGNAL(search(KUrl
)), this, SLOT(searchItems(KUrl
)));
1303 KAction
* search
= new KAction(this);
1304 actionCollection()->addAction("search_bar", search
);
1305 search
->setText(i18nc("@action:inmenu", "Search Bar"));
1306 search
->setDefaultWidget(m_searchBox
);
1307 search
->setShortcutConfigurable(false);
1310 void DolphinMainWindow::setupDockWidgets()
1312 // setup "Information"
1313 QDockWidget
* infoDock
= new QDockWidget(i18nc("@title:window", "Information"));
1314 infoDock
->setObjectName("infoDock");
1315 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1316 Panel
* infoPanel
= new InformationPanel(infoDock
);
1317 infoDock
->setWidget(infoPanel
);
1319 QAction
* infoAction
= infoDock
->toggleViewAction();
1320 infoAction
->setText(i18nc("@title:window", "Information"));
1321 infoAction
->setShortcut(Qt::Key_F11
);
1322 infoAction
->setIcon(KIcon("dialog-information"));
1323 actionCollection()->addAction("show_info_panel", infoDock
->toggleViewAction());
1325 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1326 connect(this, SIGNAL(urlChanged(KUrl
)),
1327 infoPanel
, SLOT(setUrl(KUrl
)));
1328 connect(this, SIGNAL(selectionChanged(KFileItemList
)),
1329 infoPanel
, SLOT(setSelection(KFileItemList
)));
1330 connect(this, SIGNAL(requestItemInfo(KFileItem
)),
1331 infoPanel
, SLOT(requestDelayedItemInfo(KFileItem
)));
1334 QDockWidget
* foldersDock
= new QDockWidget(i18nc("@title:window", "Folders"));
1335 foldersDock
->setObjectName("foldersDock");
1336 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1337 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1338 foldersDock
->setWidget(foldersPanel
);
1340 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1341 foldersAction
->setText(i18nc("@title:window", "Folders"));
1342 foldersAction
->setShortcut(Qt::Key_F7
);
1343 foldersAction
->setIcon(KIcon("folder"));
1344 actionCollection()->addAction("show_folders_panel", foldersDock
->toggleViewAction());
1346 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1347 connect(this, SIGNAL(urlChanged(KUrl
)),
1348 foldersPanel
, SLOT(setUrl(KUrl
)));
1349 connect(foldersPanel
, SIGNAL(changeUrl(KUrl
, Qt::MouseButtons
)),
1350 this, SLOT(handlePlacesClick(KUrl
, Qt::MouseButtons
)));
1351 connect(foldersPanel
, SIGNAL(changeSelection(KFileItemList
)),
1352 this, SLOT(changeSelection(KFileItemList
)));
1356 QDockWidget
* terminalDock
= new QDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1357 terminalDock
->setObjectName("terminalDock");
1358 terminalDock
->setAllowedAreas(Qt::TopDockWidgetArea
| Qt::BottomDockWidgetArea
);
1359 Panel
* terminalPanel
= new TerminalPanel(terminalDock
);
1360 terminalDock
->setWidget(terminalPanel
);
1362 connect(terminalPanel
, SIGNAL(hideTerminalPanel()), terminalDock
, SLOT(hide()));
1364 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1365 terminalAction
->setText(i18nc("@title:window Shell terminal", "Terminal"));
1366 terminalAction
->setShortcut(Qt::Key_F4
);
1367 terminalAction
->setIcon(KIcon("utilities-terminal"));
1368 actionCollection()->addAction("show_terminal_panel", terminalDock
->toggleViewAction());
1370 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1371 connect(this, SIGNAL(urlChanged(KUrl
)),
1372 terminalPanel
, SLOT(setUrl(KUrl
)));
1375 const bool firstRun
= DolphinSettings::instance().generalSettings()->firstRun();
1377 foldersDock
->hide();
1379 terminalDock
->hide();
1383 QDockWidget
* placesDock
= new QDockWidget(i18nc("@title:window", "Places"));
1384 placesDock
->setObjectName("placesDock");
1385 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1387 PlacesPanel
* placesPanel
= new PlacesPanel(placesDock
);
1388 placesDock
->setWidget(placesPanel
);
1389 placesPanel
->setModel(DolphinSettings::instance().placesModel());
1390 placesPanel
->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff
);
1392 QAction
* placesAction
= placesDock
->toggleViewAction();
1393 placesAction
->setText(i18nc("@title:window", "Places"));
1394 placesAction
->setShortcut(Qt::Key_F9
);
1395 placesAction
->setIcon(KIcon("bookmarks"));
1396 actionCollection()->addAction("show_places_panel", placesDock
->toggleViewAction());
1398 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1399 connect(placesPanel
, SIGNAL(urlChanged(KUrl
, Qt::MouseButtons
)),
1400 this, SLOT(handlePlacesClick(KUrl
, Qt::MouseButtons
)));
1401 connect(this, SIGNAL(urlChanged(KUrl
)),
1402 placesPanel
, SLOT(setUrl(KUrl
)));
1405 void DolphinMainWindow::updateEditActions()
1407 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1408 if (list
.isEmpty()) {
1409 stateChanged("has_no_selection");
1411 stateChanged("has_selection");
1413 KActionCollection
* col
= actionCollection();
1414 QAction
* renameAction
= col
->action("rename");
1415 QAction
* moveToTrashAction
= col
->action("move_to_trash");
1416 QAction
* deleteAction
= col
->action("delete");
1417 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
1418 QAction
* deleteWithTrashShortcut
= col
->action("delete_shortcut"); // see DolphinViewActionHandler
1420 KFileItemListProperties
capabilities(list
);
1421 const bool enableMoveToTrash
= capabilities
.isLocal() && capabilities
.supportsMoving();
1423 renameAction
->setEnabled(capabilities
.supportsMoving());
1424 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1425 deleteAction
->setEnabled(capabilities
.supportsDeleting());
1426 deleteWithTrashShortcut
->setEnabled(capabilities
.supportsDeleting() && !enableMoveToTrash
);
1427 cutAction
->setEnabled(capabilities
.supportsMoving());
1429 updatePasteAction();
1432 void DolphinMainWindow::updateViewActions()
1434 m_actionHandler
->updateViewActions();
1436 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1437 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
1439 updateSplitAction();
1441 QAction
* editableLocactionAction
= actionCollection()->action("editable_location");
1442 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
1443 editableLocactionAction
->setChecked(urlNavigator
->isUrlEditable());
1446 void DolphinMainWindow::updateGoActions()
1448 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
1449 const KUrl
& currentUrl
= m_activeViewContainer
->url();
1450 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
1453 void DolphinMainWindow::rememberClosedTab(int index
)
1455 KMenu
* tabsMenu
= m_recentTabsMenu
->menu();
1457 const QString primaryPath
= m_viewTab
[index
].primaryView
->url().path();
1458 const QString iconName
= KMimeType::iconNameForUrl(primaryPath
);
1460 QAction
* action
= new QAction(squeezedText(primaryPath
), tabsMenu
);
1462 ClosedTab closedTab
;
1463 closedTab
.primaryUrl
= m_viewTab
[index
].primaryView
->url();
1465 if (m_viewTab
[index
].secondaryView
!= 0) {
1466 closedTab
.secondaryUrl
= m_viewTab
[index
].secondaryView
->url();
1467 closedTab
.isSplit
= true;
1469 closedTab
.isSplit
= false;
1472 action
->setData(QVariant::fromValue(closedTab
));
1473 action
->setIcon(KIcon(iconName
));
1475 // add the closed tab menu entry after the separator and
1476 // "Empty Recently Closed Tabs" entry
1477 if (tabsMenu
->actions().size() == 2) {
1478 tabsMenu
->addAction(action
);
1480 tabsMenu
->insertAction(tabsMenu
->actions().at(2), action
);
1483 // assure that only up to 8 closed tabs are shown in the menu
1484 if (tabsMenu
->actions().size() > 8) {
1485 tabsMenu
->removeAction(tabsMenu
->actions().last());
1487 actionCollection()->action("closed_tabs")->setEnabled(true);
1488 KAcceleratorManager::manage(tabsMenu
);
1491 void DolphinMainWindow::clearStatusBar()
1493 m_activeViewContainer
->statusBar()->clear();
1496 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
1498 connect(container
, SIGNAL(showFilterBarChanged(bool)),
1499 this, SLOT(updateFilterBarAction(bool)));
1501 DolphinView
* view
= container
->view();
1502 connect(view
, SIGNAL(selectionChanged(KFileItemList
)),
1503 this, SLOT(slotSelectionChanged(KFileItemList
)));
1504 connect(view
, SIGNAL(requestItemInfo(KFileItem
)),
1505 this, SLOT(slotRequestItemInfo(KFileItem
)));
1506 connect(view
, SIGNAL(activated()),
1507 this, SLOT(toggleActiveView()));
1508 connect(view
, SIGNAL(tabRequested(const KUrl
&)),
1509 this, SLOT(openNewTab(const KUrl
&)));
1511 const KUrlNavigator
* navigator
= container
->urlNavigator();
1512 connect(navigator
, SIGNAL(urlChanged(const KUrl
&)),
1513 this, SLOT(changeUrl(const KUrl
&)));
1514 connect(navigator
, SIGNAL(historyChanged()),
1515 this, SLOT(updateHistory()));
1516 connect(navigator
, SIGNAL(editableStateChanged(bool)),
1517 this, SLOT(slotEditableStateChanged(bool)));
1520 void DolphinMainWindow::updateSplitAction()
1522 QAction
* splitAction
= actionCollection()->action("split_view");
1523 if (m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
1524 if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
1525 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
1526 splitAction
->setIcon(KIcon("view-right-close"));
1528 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
1529 splitAction
->setIcon(KIcon("view-left-close"));
1532 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
1533 splitAction
->setIcon(KIcon("view-right-new"));
1537 QString
DolphinMainWindow::tabName(const KUrl
& url
) const
1540 if (url
.equals(KUrl("file:///"))) {
1543 name
= url
.fileName();
1544 if (name
.isEmpty()) {
1545 name
= url
.protocol();
1547 // Make sure that a '&' inside the directory name is displayed correctly
1548 // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
1549 name
.replace('&', "&&");
1555 bool DolphinMainWindow::isKompareInstalled() const
1557 static bool initialized
= false;
1558 static bool installed
= false;
1560 // TODO: maybe replace this approach later by using a menu
1561 // plugin like kdiff3plugin.cpp
1562 installed
= !KGlobal::dirs()->findExe("kompare").isEmpty();
1568 void DolphinMainWindow::createSecondaryView(int tabIndex
)
1570 QSplitter
* splitter
= m_viewTab
[tabIndex
].splitter
;
1571 const int newWidth
= (m_viewTab
[tabIndex
].primaryView
->width() - splitter
->handleWidth()) / 2;
1573 const DolphinView
* view
= m_viewTab
[tabIndex
].primaryView
->view();
1574 m_viewTab
[tabIndex
].secondaryView
= new DolphinViewContainer(this, 0, view
->rootUrl());
1575 splitter
->addWidget(m_viewTab
[tabIndex
].secondaryView
);
1576 splitter
->setSizes(QList
<int>() << newWidth
<< newWidth
);
1577 connectViewSignals(m_viewTab
[tabIndex
].secondaryView
);
1578 m_viewTab
[tabIndex
].secondaryView
->view()->reload();
1579 m_viewTab
[tabIndex
].secondaryView
->setActive(false);
1580 m_viewTab
[tabIndex
].secondaryView
->show();
1583 QString
DolphinMainWindow::tabProperty(const QString
& property
, int tabIndex
) const
1585 return "Tab " + QString::number(tabIndex
) + ' ' + property
;
1588 void DolphinMainWindow::setUrlAsCaption(const KUrl
& url
)
1591 if (url
.equals(KUrl("file:///"))) {
1594 caption
= url
.fileName();
1595 if (caption
.isEmpty()) {
1596 caption
= url
.protocol();
1600 setCaption(caption
);
1603 QString
DolphinMainWindow::squeezedText(const QString
& text
) const
1605 const QFontMetrics fm
= fontMetrics();
1606 return fm
.elidedText(text
, Qt::ElideMiddle
, fm
.maxWidth() * 10);
1609 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
1610 KIO::FileUndoManager::UiInterface()
1614 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
1618 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
1620 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
1622 DolphinStatusBar
* statusBar
= mainWin
->activeViewContainer()->statusBar();
1623 statusBar
->setMessage(job
->errorString(), DolphinStatusBar::Error
);
1625 KIO::FileUndoManager::UiInterface::jobError(job
);
1629 #include "dolphinmainwindow.moc"