1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> *
3 * Copyright (C) 2006 by Stefan Monov <logixoul@gmail.com> *
4 * Copyright (C) 2006 by Cvetoslav Ludmiloff <ludmiloff@gmail.com> *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20 ***************************************************************************/
22 #include "dolphinmainwindow.h"
23 #include "dolphinviewactionhandler.h"
24 #include "dolphinremoteencoding.h"
26 #include <config-nepomuk.h>
28 #include "dolphinapplication.h"
29 #include "dolphinnewmenu.h"
30 #include "search/dolphinsearchbox.h"
31 #include "search/dolphinsearchoptionsconfigurator.h"
32 #include "settings/dolphinsettings.h"
33 #include "settings/dolphinsettingsdialog.h"
34 #include "dolphinviewcontainer.h"
35 #include "panels/folders/folderspanel.h"
36 #include "panels/places/placespanel.h"
37 #include "panels/information/informationpanel.h"
38 #include "mainwindowadaptor.h"
39 #include "statusbar/dolphinstatusbar.h"
40 #include "viewproperties.h"
43 #include "panels/terminal/terminalpanel.h"
46 #include "dolphin_generalsettings.h"
47 #include "dolphin_iconsmodesettings.h"
48 #include "draganddrophelper.h"
51 #include <kactioncollection.h>
53 #include <kdesktopfile.h>
54 #include <kdeversion.h>
55 #include <kfiledialog.h>
56 #include <kfileplacesmodel.h>
58 #include <klineedit.h>
61 #include <kiconloader.h>
62 #include <kio/netaccess.h>
63 #include <kinputdialog.h>
65 #include <kprotocolmanager.h>
68 #include <kmessagebox.h>
69 #include <kfileitemlistproperties.h>
70 #include <konqmimedata.h>
71 #include <kprotocolinfo.h>
74 #include <kstandarddirs.h>
75 #include <kstatusbar.h>
76 #include <kstandardaction.h>
78 #include <ktoggleaction.h>
79 #include <kurlnavigator.h>
81 #include <kurlcombobox.h>
82 #include <ktoolinvocation.h>
84 #include <QDBusMessage>
88 #include <QDockWidget>
89 #include <kacceleratormanager.h>
92 * Remembers the tab configuration if a tab has been closed.
93 * Each closed tab can be restored by the menu
94 * "Go -> Recently Closed Tabs".
102 Q_DECLARE_METATYPE(ClosedTab
)
104 DolphinMainWindow::DolphinMainWindow(int id
) :
109 m_activeViewContainer(0),
110 m_centralWidgetLayout(0),
112 m_searchOptionsConfigurator(0),
120 setObjectName("Dolphin#");
122 m_viewTab
.append(ViewTab());
124 new MainWindowAdaptor(this);
125 QDBusConnection::sessionBus().registerObject(QString("/dolphin/MainWindow%1").arg(m_id
), this);
127 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
128 undoManager
->setUiInterface(new UndoUiInterface());
130 connect(undoManager
, SIGNAL(undoAvailable(bool)),
131 this, SLOT(slotUndoAvailable(bool)));
132 connect(undoManager
, SIGNAL(undoTextChanged(const QString
&)),
133 this, SLOT(slotUndoTextChanged(const QString
&)));
134 connect(undoManager
, SIGNAL(jobRecordingStarted(CommandType
)),
135 this, SLOT(clearStatusBar()));
136 connect(undoManager
, SIGNAL(jobRecordingFinished(CommandType
)),
137 this, SLOT(showCommand(CommandType
)));
138 connect(DolphinSettings::instance().placesModel(), SIGNAL(errorMessage(const QString
&)),
139 this, SLOT(showErrorMessage(const QString
&)));
140 connect(&DragAndDropHelper::instance(), SIGNAL(errorMessage(const QString
&)),
141 this, SLOT(showErrorMessage(const QString
&)));
144 DolphinMainWindow::~DolphinMainWindow()
146 DolphinApplication::app()->removeMainWindow(this);
149 void DolphinMainWindow::toggleViews()
151 if (m_viewTab
[m_tabIndex
].primaryView
== 0) {
155 // move secondary view from the last position of the splitter
156 // to the first position
157 m_viewTab
[m_tabIndex
].splitter
->insertWidget(0, m_viewTab
[m_tabIndex
].secondaryView
);
159 DolphinViewContainer
* container
= m_viewTab
[m_tabIndex
].primaryView
;
160 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
161 m_viewTab
[m_tabIndex
].secondaryView
= container
;
164 void DolphinMainWindow::showCommand(CommandType command
)
166 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
168 case KIO::FileUndoManager::Copy
:
169 statusBar
->setMessage(i18nc("@info:status", "Successfully copied."),
170 DolphinStatusBar::OperationCompleted
);
172 case KIO::FileUndoManager::Move
:
173 statusBar
->setMessage(i18nc("@info:status", "Successfully moved."),
174 DolphinStatusBar::OperationCompleted
);
176 case KIO::FileUndoManager::Link
:
177 statusBar
->setMessage(i18nc("@info:status", "Successfully linked."),
178 DolphinStatusBar::OperationCompleted
);
180 case KIO::FileUndoManager::Trash
:
181 statusBar
->setMessage(i18nc("@info:status", "Successfully moved to trash."),
182 DolphinStatusBar::OperationCompleted
);
184 case KIO::FileUndoManager::Rename
:
185 statusBar
->setMessage(i18nc("@info:status", "Successfully renamed."),
186 DolphinStatusBar::OperationCompleted
);
189 case KIO::FileUndoManager::Mkdir
:
190 statusBar
->setMessage(i18nc("@info:status", "Created folder."),
191 DolphinStatusBar::OperationCompleted
);
199 void DolphinMainWindow::refreshViews()
201 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
203 // remember the current active view, as because of
204 // the refreshing the active view might change to
205 // the secondary view
206 DolphinViewContainer
* activeViewContainer
= m_activeViewContainer
;
208 const int tabCount
= m_viewTab
.count();
209 for (int i
= 0; i
< tabCount
; ++i
) {
210 m_viewTab
[i
].primaryView
->refresh();
211 if (m_viewTab
[i
].secondaryView
!= 0) {
212 m_viewTab
[i
].secondaryView
->refresh();
216 setActiveViewContainer(activeViewContainer
);
219 void DolphinMainWindow::pasteIntoFolder()
221 m_activeViewContainer
->view()->pasteIntoFolder();
224 void DolphinMainWindow::changeUrl(const KUrl
& url
)
226 if (!KProtocolManager::supportsListing(url
)) {
227 // The URL navigator only checks for validity, not
228 // if the URL can be listed. An error message is
229 // shown due to DolphinViewContainer::restoreView().
233 DolphinViewContainer
* view
= activeViewContainer();
239 setUrlAsCaption(url
);
240 if (m_viewTab
.count() > 1) {
241 m_tabBar
->setTabText(m_tabIndex
, squeezedText(tabName(m_activeViewContainer
->url())));
243 const QString iconName
= KMimeType::iconNameForUrl(url
);
244 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(iconName
));
245 emit
urlChanged(url
);
249 void DolphinMainWindow::changeSelection(const KFileItemList
& selection
)
251 activeViewContainer()->view()->changeSelection(selection
);
254 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
256 KToggleAction
* editableLocationAction
=
257 static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
258 editableLocationAction
->setChecked(editable
);
261 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
265 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
266 int selectedUrlsCount
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedItemsCount();
267 if (m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
268 selectedUrlsCount
+= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItemsCount();
271 QAction
* compareFilesAction
= actionCollection()->action("compare_files");
272 if (selectedUrlsCount
== 2) {
273 compareFilesAction
->setEnabled(isKompareInstalled());
275 compareFilesAction
->setEnabled(false);
278 emit
selectionChanged(selection
);
281 void DolphinMainWindow::slotWheelMoved(int wheelDelta
)
283 if (wheelDelta
> 0) {
290 void DolphinMainWindow::slotRequestItemInfo(const KFileItem
& item
)
292 emit
requestItemInfo(item
);
295 void DolphinMainWindow::updateHistory()
297 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
298 const int index
= urlNavigator
->historyIndex();
300 QAction
* backAction
= actionCollection()->action("go_back");
301 backAction
->setToolTip(i18nc("@info", "Go back"));
302 if (backAction
!= 0) {
303 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
306 QAction
* forwardAction
= actionCollection()->action("go_forward");
307 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
308 if (forwardAction
!= 0) {
309 forwardAction
->setEnabled(index
> 0);
313 void DolphinMainWindow::updateFilterBarAction(bool show
)
315 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
316 showFilterBarAction
->setChecked(show
);
319 void DolphinMainWindow::openNewMainWindow()
321 DolphinApplication::app()->createMainWindow()->show();
324 void DolphinMainWindow::openNewTab()
326 openNewTab(m_activeViewContainer
->url());
327 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
329 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
330 if (navigator
->isUrlEditable()) {
331 // if a new tab is opened and the URL is editable, assure that
332 // the user can edit the URL without manually setting the focus
333 navigator
->setFocus();
337 void DolphinMainWindow::openNewTab(const KUrl
& url
)
339 const KIcon icon
= KIcon(KMimeType::iconNameForUrl(m_activeViewContainer
->url()));
340 if (m_viewTab
.count() == 1) {
341 // Only one view is open currently and hence no tab is shown at
342 // all. Before creating a tab for 'url', provide a tab for the current URL.
343 m_tabBar
->addTab(icon
, squeezedText(tabName(m_activeViewContainer
->url())));
344 m_tabBar
->blockSignals(false);
347 m_tabBar
->addTab(icon
, squeezedText(tabName(url
)));
350 viewTab
.splitter
= new QSplitter(this);
351 viewTab
.splitter
->setChildrenCollapsible(false);
352 viewTab
.primaryView
= new DolphinViewContainer(this, viewTab
.splitter
, url
);
353 viewTab
.primaryView
->setActive(false);
354 connectViewSignals(viewTab
.primaryView
);
355 viewTab
.primaryView
->view()->reload();
357 m_viewTab
.append(viewTab
);
359 actionCollection()->action("close_tab")->setEnabled(true);
361 // provide a split view, if the startup settings are set this way
362 const GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
363 if (generalSettings
->splitView()) {
364 const int tabIndex
= m_viewTab
.count() - 1;
365 createSecondaryView(tabIndex
);
366 m_viewTab
[tabIndex
].secondaryView
->setActive(true);
367 m_viewTab
[tabIndex
].isPrimaryViewActive
= false;
371 void DolphinMainWindow::activateNextTab()
373 if ((m_viewTab
.count() == 1) || (m_tabBar
->count() < 2)) {
377 const int tabIndex
= (m_tabBar
->currentIndex() + 1) % m_tabBar
->count();
378 m_tabBar
->setCurrentIndex(tabIndex
);
381 void DolphinMainWindow::activatePrevTab()
383 if ((m_viewTab
.count() == 1) || (m_tabBar
->count() < 2)) {
387 int tabIndex
= m_tabBar
->currentIndex() - 1;
388 if (tabIndex
== -1) {
389 tabIndex
= m_tabBar
->count() - 1;
391 m_tabBar
->setCurrentIndex(tabIndex
);
394 void DolphinMainWindow::openInNewTab()
396 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
397 if ((list
.count() == 1) && list
[0].isDir()) {
398 openNewTab(m_activeViewContainer
->view()->selectedUrls()[0]);
402 void DolphinMainWindow::openInNewWindow()
404 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
405 if ((list
.count() == 1) && list
[0].isDir()) {
406 DolphinMainWindow
* window
= DolphinApplication::app()->createMainWindow();
407 window
->changeUrl(m_activeViewContainer
->view()->selectedUrls()[0]);
412 void DolphinMainWindow::toggleActiveView()
414 if (m_viewTab
[m_tabIndex
].secondaryView
== 0) {
415 // only one view is available
419 Q_ASSERT(m_activeViewContainer
!= 0);
420 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
422 DolphinViewContainer
* left
= m_viewTab
[m_tabIndex
].primaryView
;
423 DolphinViewContainer
* right
= m_viewTab
[m_tabIndex
].secondaryView
;
424 setActiveViewContainer(m_activeViewContainer
== right
? left
: right
);
427 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
429 DolphinSettings
& settings
= DolphinSettings::instance();
430 GeneralSettings
* generalSettings
= settings
.generalSettings();
432 // Find out if Dolphin is closed directly by the user or
433 // by the session manager because the session is closed
434 bool closedByUser
= true;
435 DolphinApplication
*application
= qobject_cast
<DolphinApplication
*>(qApp
);
436 if (application
&& application
->sessionSaving()) {
437 closedByUser
= false;
440 if ((m_viewTab
.count() > 1) && generalSettings
->confirmClosingMultipleTabs() && closedByUser
) {
441 // Ask the user if he really wants to quit and close all tabs.
442 // Open a confirmation dialog with 3 buttons:
443 // KDialog::Yes -> Quit
444 // KDialog::No -> Close only the current tab
445 // KDialog::Cancel -> do nothing
446 KDialog
*dialog
= new KDialog(this, Qt::Dialog
);
447 dialog
->setCaption(i18nc("@title:window", "Confirmation"));
448 dialog
->setButtons(KDialog::Yes
| KDialog::No
| KDialog::Cancel
);
449 dialog
->setModal(true);
450 dialog
->showButtonSeparator(true);
451 dialog
->setButtonGuiItem(KDialog::Yes
, KStandardGuiItem::quit());
452 dialog
->setButtonGuiItem(KDialog::No
, KGuiItem(i18n("C&lose Current Tab"), KIcon("tab-close")));
453 dialog
->setButtonGuiItem(KDialog::Cancel
, KStandardGuiItem::cancel());
454 dialog
->setDefaultButton(KDialog::Yes
);
456 bool doNotAskAgainCheckboxResult
= false;
458 const int result
= KMessageBox::createKMessageBox(dialog
,
459 QMessageBox::Warning
,
460 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
462 i18n("Do not ask again"),
463 &doNotAskAgainCheckboxResult
,
464 KMessageBox::Notify
);
466 if (doNotAskAgainCheckboxResult
) {
467 generalSettings
->setConfirmClosingMultipleTabs(false);
475 // Close only the current tab
483 generalSettings
->setFirstRun(false);
487 KXmlGuiWindow::closeEvent(event
);
490 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
492 const int tabCount
= m_viewTab
.count();
493 group
.writeEntry("Tab Count", tabCount
);
494 group
.writeEntry("Active Tab Index", m_tabBar
->currentIndex());
496 for (int i
= 0; i
< tabCount
; ++i
) {
497 const DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
498 group
.writeEntry(tabProperty("Primary URL", i
), cont
->url().url());
499 group
.writeEntry(tabProperty("Primary Editable", i
), cont
->isUrlEditable());
501 cont
= m_viewTab
[i
].secondaryView
;
503 group
.writeEntry(tabProperty("Secondary URL", i
), cont
->url().url());
504 group
.writeEntry(tabProperty("Secondary Editable", i
), cont
->isUrlEditable());
509 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
511 const int tabCount
= group
.readEntry("Tab Count", 1);
512 for (int i
= 0; i
< tabCount
; ++i
) {
513 DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
515 cont
->setUrl(group
.readEntry(tabProperty("Primary URL", i
)));
516 const bool editable
= group
.readEntry(tabProperty("Primary Editable", i
), false);
517 cont
->urlNavigator()->setUrlEditable(editable
);
519 cont
= m_viewTab
[i
].secondaryView
;
520 const QString secondaryUrl
= group
.readEntry(tabProperty("Secondary URL", i
));
521 if (!secondaryUrl
.isEmpty()) {
523 // a secondary view should be shown, but no one is available
524 // currently -> create a new view
526 cont
= m_viewTab
[i
].secondaryView
;
530 cont
->setUrl(secondaryUrl
);
531 const bool editable
= group
.readEntry(tabProperty("Secondary Editable", i
), false);
532 cont
->urlNavigator()->setUrlEditable(editable
);
533 } else if (cont
!= 0) {
534 // no secondary view should be shown, but the default setting shows
535 // one already -> close the view
539 // openNewTab() needs to be called only tabCount - 1 times
540 if (i
!= tabCount
- 1) {
545 const int index
= group
.readEntry("Active Tab Index", 0);
546 m_tabBar
->setCurrentIndex(index
);
549 void DolphinMainWindow::updateNewMenu()
551 m_newMenu
->slotCheckUpToDate();
552 m_newMenu
->setPopupFiles(activeViewContainer()->url());
555 void DolphinMainWindow::createDirectory()
557 m_newMenu
->setPopupFiles(activeViewContainer()->url());
558 m_newMenu
->createDirectory();
561 void DolphinMainWindow::quit()
566 void DolphinMainWindow::showErrorMessage(const QString
& message
)
568 if (!message
.isEmpty()) {
569 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
570 statusBar
->setMessage(message
, DolphinStatusBar::Error
);
574 void DolphinMainWindow::slotUndoAvailable(bool available
)
576 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
577 if (undoAction
!= 0) {
578 undoAction
->setEnabled(available
);
582 void DolphinMainWindow::restoreClosedTab(QAction
* action
)
584 if (action
->data().toBool()) {
585 // clear all actions except the "Empty Recently Closed Tabs"
586 // action and the separator
587 QList
<QAction
*> actions
= m_recentTabsMenu
->menu()->actions();
588 const int count
= actions
.size();
589 for (int i
= 2; i
< count
; ++i
) {
590 m_recentTabsMenu
->menu()->removeAction(actions
.at(i
));
593 const ClosedTab closedTab
= action
->data().value
<ClosedTab
>();
594 openNewTab(closedTab
.primaryUrl
);
595 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
597 if (closedTab
.isSplit
) {
598 // create secondary view
600 m_viewTab
[m_tabIndex
].secondaryView
->setUrl(closedTab
.secondaryUrl
);
603 m_recentTabsMenu
->removeAction(action
);
606 if (m_recentTabsMenu
->menu()->actions().count() == 2) {
607 m_recentTabsMenu
->setEnabled(false);
611 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
613 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
614 if (undoAction
!= 0) {
615 undoAction
->setText(text
);
619 void DolphinMainWindow::undo()
622 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
623 KIO::FileUndoManager::self()->undo();
626 void DolphinMainWindow::cut()
628 m_activeViewContainer
->view()->cutSelectedItems();
631 void DolphinMainWindow::copy()
633 m_activeViewContainer
->view()->copySelectedItems();
636 void DolphinMainWindow::paste()
638 m_activeViewContainer
->view()->paste();
641 void DolphinMainWindow::updatePasteAction()
643 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
644 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
645 pasteAction
->setEnabled(pasteInfo
.first
);
646 pasteAction
->setText(pasteInfo
.second
);
649 void DolphinMainWindow::selectAll()
653 // if the URL navigator is editable and focused, select the whole
654 // URL instead of all items of the view
656 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
657 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit(); // krazy:exclude=qclasses
658 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
659 lineEdit
->hasFocus();
661 lineEdit
->selectAll();
663 m_activeViewContainer
->view()->selectAll();
667 void DolphinMainWindow::invertSelection()
670 m_activeViewContainer
->view()->invertSelection();
673 void DolphinMainWindow::toggleSplitView()
675 if (m_viewTab
[m_tabIndex
].secondaryView
== 0) {
676 createSecondaryView(m_tabIndex
);
677 setActiveViewContainer(m_viewTab
[m_tabIndex
].secondaryView
);
678 } else if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
679 // remove secondary view
680 m_viewTab
[m_tabIndex
].secondaryView
->close();
681 m_viewTab
[m_tabIndex
].secondaryView
->deleteLater();
682 m_viewTab
[m_tabIndex
].secondaryView
= 0;
684 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
686 // The primary view is active and should be closed. Hence from a users point of view
687 // the content of the secondary view should be moved to the primary view.
688 // From an implementation point of view it is more efficient to close
689 // the primary view and exchange the internal pointers afterwards.
691 m_viewTab
[m_tabIndex
].primaryView
->close();
692 m_viewTab
[m_tabIndex
].primaryView
->deleteLater();
693 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
694 m_viewTab
[m_tabIndex
].secondaryView
= 0;
696 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
702 void DolphinMainWindow::reloadView()
705 m_activeViewContainer
->view()->reload();
708 void DolphinMainWindow::stopLoading()
712 void DolphinMainWindow::toggleFilterBarVisibility(bool show
)
714 m_activeViewContainer
->showFilterBar(show
);
717 void DolphinMainWindow::toggleEditLocation()
721 QAction
* action
= actionCollection()->action("editable_location");
722 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
723 urlNavigator
->setUrlEditable(action
->isChecked());
726 void DolphinMainWindow::replaceLocation()
728 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
729 navigator
->setUrlEditable(true);
730 navigator
->setFocus();
732 // select the whole text of the combo box editor
733 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit(); // krazy:exclude=qclasses
734 const QString text
= lineEdit
->text();
735 lineEdit
->setSelection(0, text
.length());
738 void DolphinMainWindow::goBack()
741 m_activeViewContainer
->urlNavigator()->goBack();
744 void DolphinMainWindow::goForward()
747 m_activeViewContainer
->urlNavigator()->goForward();
750 void DolphinMainWindow::goUp()
753 m_activeViewContainer
->urlNavigator()->goUp();
756 void DolphinMainWindow::goHome()
759 m_activeViewContainer
->urlNavigator()->goHome();
762 void DolphinMainWindow::compareFiles()
764 // The method is only invoked if exactly 2 files have
765 // been selected. The selected files may be:
766 // - both in the primary view
767 // - both in the secondary view
768 // - one in the primary view and the other in the secondary
770 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
774 KUrl::List urls
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedUrls();
776 switch (urls
.count()) {
778 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
!= 0);
779 urls
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedUrls();
780 Q_ASSERT(urls
.count() == 2);
788 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
!= 0);
789 urls
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedUrls();
790 Q_ASSERT(urls
.count() == 1);
802 // may not happen: compareFiles may only get invoked if 2
803 // files are selected
808 QString
command("kompare -c \"");
809 command
.append(urlA
.pathOrUrl());
810 command
.append("\" \"");
811 command
.append(urlB
.pathOrUrl());
812 command
.append('\"');
813 KRun::runCommand(command
, "Kompare", "kompare", this);
816 void DolphinMainWindow::toggleShowMenuBar()
818 const bool visible
= menuBar()->isVisible();
819 menuBar()->setVisible(!visible
);
822 void DolphinMainWindow::openTerminal()
824 QString
dir(QDir::homePath());
826 // If the given directory is not local, it can still be the URL of an
827 // ioslave using UDS_LOCAL_PATH which to be converted first.
828 KUrl url
= KIO::NetAccess::mostLocalUrl(m_activeViewContainer
->url(), this);
830 //If the URL is local after the above conversion, set the directory.
831 if (url
.isLocalFile()) {
832 dir
= url
.toLocalFile();
835 KToolInvocation::invokeTerminal(QString(), dir
);
838 void DolphinMainWindow::editSettings()
840 if (m_settingsDialog
== 0) {
841 const KUrl
& url
= activeViewContainer()->url();
842 m_settingsDialog
= new DolphinSettingsDialog(url
, this);
843 m_settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
844 m_settingsDialog
->show();
846 m_settingsDialog
->raise();
850 void DolphinMainWindow::setActiveTab(int index
)
852 Q_ASSERT(index
>= 0);
853 Q_ASSERT(index
< m_viewTab
.count());
854 if (index
== m_tabIndex
) {
858 // hide current tab content
859 ViewTab
& hiddenTab
= m_viewTab
[m_tabIndex
];
860 hiddenTab
.isPrimaryViewActive
= hiddenTab
.primaryView
->isActive();
861 hiddenTab
.primaryView
->setActive(false);
862 if (hiddenTab
.secondaryView
!= 0) {
863 hiddenTab
.secondaryView
->setActive(false);
865 QSplitter
* splitter
= m_viewTab
[m_tabIndex
].splitter
;
867 m_centralWidgetLayout
->removeWidget(splitter
);
869 // show active tab content
872 ViewTab
& viewTab
= m_viewTab
[index
];
873 m_centralWidgetLayout
->addWidget(viewTab
.splitter
, 1);
874 viewTab
.primaryView
->show();
875 if (viewTab
.secondaryView
!= 0) {
876 viewTab
.secondaryView
->show();
878 viewTab
.splitter
->show();
880 setActiveViewContainer(viewTab
.isPrimaryViewActive
? viewTab
.primaryView
:
881 viewTab
.secondaryView
);
884 void DolphinMainWindow::closeTab()
886 closeTab(m_tabBar
->currentIndex());
889 void DolphinMainWindow::closeTab(int index
)
891 Q_ASSERT(index
>= 0);
892 Q_ASSERT(index
< m_viewTab
.count());
893 if (m_viewTab
.count() == 1) {
894 // the last tab may never get closed
898 if (index
== m_tabIndex
) {
899 // The tab that should be closed is the active tab. Activate the
900 // previous tab before closing the tab.
901 m_tabBar
->setCurrentIndex((index
> 0) ? index
- 1 : 1);
903 rememberClosedTab(index
);
906 m_viewTab
[index
].primaryView
->deleteLater();
907 if (m_viewTab
[index
].secondaryView
!= 0) {
908 m_viewTab
[index
].secondaryView
->deleteLater();
910 m_viewTab
[index
].splitter
->deleteLater();
911 m_viewTab
.erase(m_viewTab
.begin() + index
);
913 m_tabBar
->blockSignals(true);
914 m_tabBar
->removeTab(index
);
916 if (m_tabIndex
> index
) {
918 Q_ASSERT(m_tabIndex
>= 0);
921 // if only one tab is left, also remove the tab entry so that
922 // closing the last tab is not possible
923 if (m_viewTab
.count() == 1) {
924 m_tabBar
->removeTab(0);
925 actionCollection()->action("close_tab")->setEnabled(false);
927 m_tabBar
->blockSignals(false);
931 void DolphinMainWindow::openTabContextMenu(int index
, const QPoint
& pos
)
935 QAction
* newTabAction
= menu
.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab"));
936 newTabAction
->setShortcut(actionCollection()->action("new_tab")->shortcut());
938 QAction
* closeOtherTabsAction
= menu
.addAction(KIcon("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs"));
940 QAction
* closeTabAction
= menu
.addAction(KIcon("tab-close"), i18nc("@action:inmenu", "Close Tab"));
941 closeTabAction
->setShortcut(actionCollection()->action("close_tab")->shortcut());
942 QAction
* selectedAction
= menu
.exec(pos
);
943 if (selectedAction
== newTabAction
) {
944 const ViewTab
& tab
= m_viewTab
[index
];
945 Q_ASSERT(tab
.primaryView
!= 0);
946 const KUrl url
= (tab
.secondaryView
!= 0) && tab
.secondaryView
->isActive() ?
947 tab
.secondaryView
->url() : tab
.primaryView
->url();
949 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
950 } else if (selectedAction
== closeOtherTabsAction
) {
951 const int count
= m_tabBar
->count();
952 for (int i
= 0; i
< index
; ++i
) {
955 for (int i
= index
+ 1; i
< count
; ++i
) {
958 } else if (selectedAction
== closeTabAction
) {
963 void DolphinMainWindow::handlePlacesClick(const KUrl
& url
, Qt::MouseButtons buttons
)
965 if (buttons
& Qt::MidButton
) {
967 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
973 void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent
* event
, bool& canDecode
)
975 canDecode
= KUrl::List::canDecode(event
->mimeData());
978 void DolphinMainWindow::searchItems(const KUrl
& url
)
980 m_activeViewContainer
->setUrl(url
);
983 void DolphinMainWindow::slotTabMoved(int from
, int to
)
985 m_viewTab
.move(from
, to
);
986 m_tabIndex
= m_tabBar
->currentIndex();
989 void DolphinMainWindow::slotSearchBoxTextChanged(const QString
& text
)
991 m_searchOptionsConfigurator
->setVisible(!text
.isEmpty());
994 void DolphinMainWindow::init()
996 DolphinSettings
& settings
= DolphinSettings::instance();
998 // Check whether Dolphin runs the first time. If yes then
999 // a proper default window size is given at the end of DolphinMainWindow::init().
1000 GeneralSettings
* generalSettings
= settings
.generalSettings();
1001 const bool firstRun
= generalSettings
->firstRun();
1003 generalSettings
->setViewPropsTimestamp(QDateTime::currentDateTime());
1006 setAcceptDrops(true);
1008 m_viewTab
[m_tabIndex
].splitter
= new QSplitter(this);
1009 m_viewTab
[m_tabIndex
].splitter
->setChildrenCollapsible(false);
1013 const KUrl
& homeUrl
= generalSettings
->homeUrl();
1014 setUrlAsCaption(homeUrl
);
1015 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
1016 connect(m_actionHandler
, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
1017 connect(m_actionHandler
, SIGNAL(createDirectory()), SLOT(createDirectory()));
1018 ViewProperties
props(homeUrl
);
1019 m_viewTab
[m_tabIndex
].primaryView
= new DolphinViewContainer(this,
1020 m_viewTab
[m_tabIndex
].splitter
,
1023 m_activeViewContainer
= m_viewTab
[m_tabIndex
].primaryView
;
1024 connectViewSignals(m_activeViewContainer
);
1025 DolphinView
* view
= m_activeViewContainer
->view();
1027 m_activeViewContainer
->show();
1028 m_actionHandler
->setCurrentView(view
);
1030 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
1031 connect(this, SIGNAL(urlChanged(const KUrl
&)),
1032 m_remoteEncoding
, SLOT(slotAboutToOpenUrl()));
1034 m_searchOptionsConfigurator
= new DolphinSearchOptionsConfigurator(this);
1035 m_searchOptionsConfigurator
->hide();
1037 m_tabBar
= new KTabBar(this);
1038 m_tabBar
->setMovable(true);
1039 m_tabBar
->setTabsClosable(true);
1040 connect(m_tabBar
, SIGNAL(currentChanged(int)),
1041 this, SLOT(setActiveTab(int)));
1042 connect(m_tabBar
, SIGNAL(tabCloseRequested(int)),
1043 this, SLOT(closeTab(int)));
1044 connect(m_tabBar
, SIGNAL(contextMenu(int, const QPoint
&)),
1045 this, SLOT(openTabContextMenu(int, const QPoint
&)));
1046 connect(m_tabBar
, SIGNAL(newTabRequest()),
1047 this, SLOT(openNewTab()));
1048 connect(m_tabBar
, SIGNAL(testCanDecode(const QDragMoveEvent
*, bool&)),
1049 this, SLOT(slotTestCanDecode(const QDragMoveEvent
*, bool&)));
1050 connect(m_tabBar
, SIGNAL(wheelDelta(int)),
1051 this, SLOT(slotWheelMoved(int)));
1052 connect(m_tabBar
, SIGNAL(mouseMiddleClick(int)),
1053 this, SLOT(closeTab(int)));
1054 connect(m_tabBar
, SIGNAL(tabMoved(int, int)),
1055 this, SLOT(slotTabMoved(int, int)));
1057 m_tabBar
->blockSignals(true); // signals get unblocked after at least 2 tabs are open
1059 QWidget
* centralWidget
= new QWidget(this);
1060 m_centralWidgetLayout
= new QVBoxLayout(centralWidget
);
1061 m_centralWidgetLayout
->setSpacing(0);
1062 m_centralWidgetLayout
->setMargin(0);
1063 m_centralWidgetLayout
->addWidget(m_searchOptionsConfigurator
);
1064 m_centralWidgetLayout
->addWidget(m_tabBar
);
1065 m_centralWidgetLayout
->addWidget(m_viewTab
[m_tabIndex
].splitter
, 1);
1067 setCentralWidget(centralWidget
);
1069 emit
urlChanged(homeUrl
);
1071 setupGUI(Keys
| Save
| Create
| ToolBar
);
1073 m_searchBox
->setParent(toolBar("searchToolBar"));
1074 m_searchBox
->show();
1075 connect(m_searchBox
, SIGNAL(textChanged(const QString
&)),
1076 this, SLOT(slotSearchBoxTextChanged(const QString
&)));
1078 stateChanged("new_file");
1080 QClipboard
* clipboard
= QApplication::clipboard();
1081 connect(clipboard
, SIGNAL(dataChanged()),
1082 this, SLOT(updatePasteAction()));
1083 updatePasteAction();
1086 if (generalSettings
->splitView()) {
1089 updateViewActions();
1091 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1092 showFilterBarAction
->setChecked(generalSettings
->filterBar());
1095 // assure a proper default size if Dolphin runs the first time
1099 m_showMenuBar
->setChecked(!menuBar()->isHidden()); // workaround for bug #171080
1102 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer
* viewContainer
)
1104 Q_ASSERT(viewContainer
!= 0);
1105 Q_ASSERT((viewContainer
== m_viewTab
[m_tabIndex
].primaryView
) ||
1106 (viewContainer
== m_viewTab
[m_tabIndex
].secondaryView
));
1107 if (m_activeViewContainer
== viewContainer
) {
1111 m_activeViewContainer
->setActive(false);
1112 m_activeViewContainer
= viewContainer
;
1114 // Activating the view container might trigger a recursive setActiveViewContainer() call
1115 // inside DolphinMainWindow::toggleActiveView() when having a split view. Temporary
1116 // disconnect the activated() signal in this case:
1117 disconnect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1118 m_activeViewContainer
->setActive(true);
1119 connect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1121 m_actionHandler
->setCurrentView(viewContainer
->view());
1124 updateEditActions();
1125 updateViewActions();
1128 const KUrl
& url
= m_activeViewContainer
->url();
1129 setUrlAsCaption(url
);
1130 if (m_viewTab
.count() > 1 && m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
1131 m_tabBar
->setTabText(m_tabIndex
, tabName(url
));
1132 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(KMimeType::iconNameForUrl(url
)));
1135 emit
urlChanged(url
);
1138 void DolphinMainWindow::setupActions()
1140 // setup 'File' menu
1141 m_newMenu
= new DolphinNewMenu(this, this);
1142 KMenu
* menu
= m_newMenu
->menu();
1143 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1144 menu
->setIcon(KIcon("document-new"));
1145 connect(menu
, SIGNAL(aboutToShow()),
1146 this, SLOT(updateNewMenu()));
1148 KAction
* newWindow
= actionCollection()->addAction("new_window");
1149 newWindow
->setIcon(KIcon("window-new"));
1150 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1151 newWindow
->setShortcut(Qt::CTRL
| Qt::Key_N
);
1152 connect(newWindow
, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1154 KAction
* newTab
= actionCollection()->addAction("new_tab");
1155 newTab
->setIcon(KIcon("tab-new"));
1156 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1157 newTab
->setShortcut(KShortcut(Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
));
1158 connect(newTab
, SIGNAL(triggered()), this, SLOT(openNewTab()));
1160 KAction
* closeTab
= actionCollection()->addAction("close_tab");
1161 closeTab
->setIcon(KIcon("tab-close"));
1162 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1163 closeTab
->setShortcut(Qt::CTRL
| Qt::Key_W
);
1164 closeTab
->setEnabled(false);
1165 connect(closeTab
, SIGNAL(triggered()), this, SLOT(closeTab()));
1167 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1169 // setup 'Edit' menu
1170 KStandardAction::undo(this,
1172 actionCollection());
1174 // need to remove shift+del from cut action, else the shortcut for deletejob
1176 KAction
* cut
= KStandardAction::cut(this, SLOT(cut()), actionCollection());
1177 KShortcut cutShortcut
= cut
->shortcut();
1178 cutShortcut
.remove(Qt::SHIFT
+ Qt::Key_Delete
, KShortcut::KeepEmpty
);
1179 cut
->setShortcut(cutShortcut
);
1180 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1181 KAction
* paste
= KStandardAction::paste(this, SLOT(paste()), actionCollection());
1182 // The text of the paste-action is modified dynamically by Dolphin
1183 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1184 // due to the long text, the text "Paste" is used:
1185 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1187 KAction
* selectAll
= actionCollection()->addAction("select_all");
1188 selectAll
->setText(i18nc("@action:inmenu Edit", "Select All"));
1189 selectAll
->setShortcut(Qt::CTRL
+ Qt::Key_A
);
1190 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
1192 KAction
* invertSelection
= actionCollection()->addAction("invert_selection");
1193 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1194 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1195 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
1197 // setup 'View' menu
1198 // (note that most of it is set up in DolphinViewActionHandler)
1200 KAction
* split
= actionCollection()->addAction("split_view");
1201 split
->setShortcut(Qt::Key_F3
);
1202 updateSplitAction();
1203 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1205 KAction
* reload
= actionCollection()->addAction("reload");
1206 reload
->setText(i18nc("@action:inmenu View", "Reload"));
1207 reload
->setShortcut(Qt::Key_F5
);
1208 reload
->setIcon(KIcon("view-refresh"));
1209 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
1211 KAction
* stop
= actionCollection()->addAction("stop");
1212 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1213 stop
->setToolTip(i18nc("@info", "Stop loading"));
1214 stop
->setIcon(KIcon("process-stop"));
1215 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
1217 KToggleAction
* showFullLocation
= actionCollection()->add
<KToggleAction
>("editable_location");
1218 showFullLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1219 showFullLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
1220 connect(showFullLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1222 KAction
* replaceLocation
= actionCollection()->addAction("replace_location");
1223 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1224 replaceLocation
->setShortcut(Qt::Key_F6
);
1225 connect(replaceLocation
, SIGNAL(triggered()), this, SLOT(replaceLocation()));
1228 KAction
* backAction
= KStandardAction::back(this, SLOT(goBack()), actionCollection());
1229 KShortcut backShortcut
= backAction
->shortcut();
1230 backShortcut
.setAlternate(Qt::Key_Backspace
);
1231 backAction
->setShortcut(backShortcut
);
1233 m_recentTabsMenu
= new KActionMenu(i18n("Recently Closed Tabs"), this);
1234 m_recentTabsMenu
->setIcon(KIcon("edit-undo"));
1235 actionCollection()->addAction("closed_tabs", m_recentTabsMenu
);
1236 connect(m_recentTabsMenu
->menu(), SIGNAL(triggered(QAction
*)),
1237 this, SLOT(restoreClosedTab(QAction
*)));
1239 QAction
* action
= new QAction("Empty Recently Closed Tabs", m_recentTabsMenu
);
1240 action
->setIcon(KIcon("edit-clear-list"));
1241 action
->setData(QVariant::fromValue(true));
1242 m_recentTabsMenu
->addAction(action
);
1243 m_recentTabsMenu
->addSeparator();
1244 m_recentTabsMenu
->setEnabled(false);
1246 KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1247 KStandardAction::up(this, SLOT(goUp()), actionCollection());
1248 KStandardAction::home(this, SLOT(goHome()), actionCollection());
1250 // setup 'Tools' menu
1251 KToggleAction
* showSearchBar
= actionCollection()->add
<KToggleAction
>("show_search_bar");
1252 showSearchBar
->setText(i18nc("@action:inmenu Tools", "Show Search Bar"));
1253 showSearchBar
->setShortcut(Qt::CTRL
| Qt::Key_S
);
1254 connect(showSearchBar
, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
1256 KToggleAction
* showFilterBar
= actionCollection()->add
<KToggleAction
>("show_filter_bar");
1257 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1258 showFilterBar
->setIcon(KIcon("view-filter"));
1259 showFilterBar
->setShortcut(Qt::CTRL
| Qt::Key_I
);
1260 connect(showFilterBar
, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
1262 KAction
* compareFiles
= actionCollection()->addAction("compare_files");
1263 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1264 compareFiles
->setIcon(KIcon("kompare"));
1265 compareFiles
->setEnabled(false);
1266 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
1268 KAction
* openTerminal
= actionCollection()->addAction("open_terminal");
1269 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1270 openTerminal
->setIcon(KIcon("utilities-terminal"));
1271 openTerminal
->setShortcut(Qt::SHIFT
| Qt::Key_F4
);
1272 connect(openTerminal
, SIGNAL(triggered()), this, SLOT(openTerminal()));
1274 // setup 'Settings' menu
1275 m_showMenuBar
= KStandardAction::showMenubar(this, SLOT(toggleShowMenuBar()), actionCollection());
1276 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1278 // not in menu actions
1279 KAction
* activateNextTab
= actionCollection()->addAction("activate_next_tab");
1280 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1281 connect(activateNextTab
, SIGNAL(triggered()), SLOT(activateNextTab()));
1282 activateNextTab
->setShortcuts(QApplication::isRightToLeft() ? KStandardShortcut::tabPrev() :
1283 KStandardShortcut::tabNext());
1285 KAction
* activatePrevTab
= actionCollection()->addAction("activate_prev_tab");
1286 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1287 connect(activatePrevTab
, SIGNAL(triggered()), SLOT(activatePrevTab()));
1288 activatePrevTab
->setShortcuts(QApplication::isRightToLeft() ? KStandardShortcut::tabNext() :
1289 KStandardShortcut::tabPrev());
1292 KAction
* openInNewTab
= actionCollection()->addAction("open_in_new_tab");
1293 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1294 openInNewTab
->setIcon(KIcon("tab-new"));
1295 connect(openInNewTab
, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1297 KAction
* openInNewWindow
= actionCollection()->addAction("open_in_new_window");
1298 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1299 openInNewWindow
->setIcon(KIcon("window-new"));
1300 connect(openInNewWindow
, SIGNAL(triggered()), this, SLOT(openInNewWindow()));
1303 m_searchBox
= new DolphinSearchBox(this);
1304 connect(m_searchBox
, SIGNAL(search(KUrl
)), this, SLOT(searchItems(KUrl
)));
1306 KAction
* search
= new KAction(this);
1307 actionCollection()->addAction("search_bar", search
);
1308 search
->setText(i18nc("@action:inmenu", "Search Bar"));
1309 search
->setDefaultWidget(m_searchBox
);
1310 search
->setShortcutConfigurable(false);
1313 void DolphinMainWindow::setupDockWidgets()
1315 // setup "Information"
1316 QDockWidget
* infoDock
= new QDockWidget(i18nc("@title:window", "Information"));
1317 infoDock
->setObjectName("infoDock");
1318 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1319 Panel
* infoPanel
= new InformationPanel(infoDock
);
1320 infoDock
->setWidget(infoPanel
);
1322 QAction
* infoAction
= infoDock
->toggleViewAction();
1323 infoAction
->setText(i18nc("@title:window", "Information"));
1324 infoAction
->setShortcut(Qt::Key_F11
);
1325 infoAction
->setIcon(KIcon("dialog-information"));
1326 actionCollection()->addAction("show_info_panel", infoDock
->toggleViewAction());
1328 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1329 connect(this, SIGNAL(urlChanged(KUrl
)),
1330 infoPanel
, SLOT(setUrl(KUrl
)));
1331 connect(this, SIGNAL(selectionChanged(KFileItemList
)),
1332 infoPanel
, SLOT(setSelection(KFileItemList
)));
1333 connect(this, SIGNAL(requestItemInfo(KFileItem
)),
1334 infoPanel
, SLOT(requestDelayedItemInfo(KFileItem
)));
1337 QDockWidget
* foldersDock
= new QDockWidget(i18nc("@title:window", "Folders"));
1338 foldersDock
->setObjectName("foldersDock");
1339 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1340 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1341 foldersDock
->setWidget(foldersPanel
);
1343 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1344 foldersAction
->setText(i18nc("@title:window", "Folders"));
1345 foldersAction
->setShortcut(Qt::Key_F7
);
1346 foldersAction
->setIcon(KIcon("folder"));
1347 actionCollection()->addAction("show_folders_panel", foldersDock
->toggleViewAction());
1349 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1350 connect(this, SIGNAL(urlChanged(KUrl
)),
1351 foldersPanel
, SLOT(setUrl(KUrl
)));
1352 connect(foldersPanel
, SIGNAL(changeUrl(KUrl
, Qt::MouseButtons
)),
1353 this, SLOT(handlePlacesClick(KUrl
, Qt::MouseButtons
)));
1354 connect(foldersPanel
, SIGNAL(changeSelection(KFileItemList
)),
1355 this, SLOT(changeSelection(KFileItemList
)));
1359 QDockWidget
* terminalDock
= new QDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1360 terminalDock
->setObjectName("terminalDock");
1361 terminalDock
->setAllowedAreas(Qt::TopDockWidgetArea
| Qt::BottomDockWidgetArea
);
1362 Panel
* terminalPanel
= new TerminalPanel(terminalDock
);
1363 terminalDock
->setWidget(terminalPanel
);
1365 connect(terminalPanel
, SIGNAL(hideTerminalPanel()), terminalDock
, SLOT(hide()));
1367 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1368 terminalAction
->setText(i18nc("@title:window Shell terminal", "Terminal"));
1369 terminalAction
->setShortcut(Qt::Key_F4
);
1370 terminalAction
->setIcon(KIcon("utilities-terminal"));
1371 actionCollection()->addAction("show_terminal_panel", terminalDock
->toggleViewAction());
1373 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1374 connect(this, SIGNAL(urlChanged(KUrl
)),
1375 terminalPanel
, SLOT(setUrl(KUrl
)));
1378 const bool firstRun
= DolphinSettings::instance().generalSettings()->firstRun();
1380 foldersDock
->hide();
1382 terminalDock
->hide();
1386 QDockWidget
* placesDock
= new QDockWidget(i18nc("@title:window", "Places"));
1387 placesDock
->setObjectName("placesDock");
1388 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1390 PlacesPanel
* placesPanel
= new PlacesPanel(placesDock
);
1391 placesDock
->setWidget(placesPanel
);
1392 placesPanel
->setModel(DolphinSettings::instance().placesModel());
1393 placesPanel
->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff
);
1395 QAction
* placesAction
= placesDock
->toggleViewAction();
1396 placesAction
->setText(i18nc("@title:window", "Places"));
1397 placesAction
->setShortcut(Qt::Key_F9
);
1398 placesAction
->setIcon(KIcon("bookmarks"));
1399 actionCollection()->addAction("show_places_panel", placesDock
->toggleViewAction());
1401 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1402 connect(placesPanel
, SIGNAL(urlChanged(KUrl
, Qt::MouseButtons
)),
1403 this, SLOT(handlePlacesClick(KUrl
, Qt::MouseButtons
)));
1404 connect(this, SIGNAL(urlChanged(KUrl
)),
1405 placesPanel
, SLOT(setUrl(KUrl
)));
1408 void DolphinMainWindow::updateEditActions()
1410 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1411 if (list
.isEmpty()) {
1412 stateChanged("has_no_selection");
1414 stateChanged("has_selection");
1416 KActionCollection
* col
= actionCollection();
1417 QAction
* renameAction
= col
->action("rename");
1418 QAction
* moveToTrashAction
= col
->action("move_to_trash");
1419 QAction
* deleteAction
= col
->action("delete");
1420 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
1421 QAction
* deleteWithTrashShortcut
= col
->action("delete_shortcut"); // see DolphinViewActionHandler
1423 KFileItemListProperties
capabilities(list
);
1424 const bool enableMoveToTrash
= capabilities
.isLocal() && capabilities
.supportsMoving();
1426 renameAction
->setEnabled(capabilities
.supportsMoving());
1427 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1428 deleteAction
->setEnabled(capabilities
.supportsDeleting());
1429 deleteWithTrashShortcut
->setEnabled(capabilities
.supportsDeleting() && !enableMoveToTrash
);
1430 cutAction
->setEnabled(capabilities
.supportsMoving());
1432 updatePasteAction();
1435 void DolphinMainWindow::updateViewActions()
1437 m_actionHandler
->updateViewActions();
1439 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1440 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
1442 updateSplitAction();
1444 QAction
* editableLocactionAction
= actionCollection()->action("editable_location");
1445 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
1446 editableLocactionAction
->setChecked(urlNavigator
->isUrlEditable());
1449 void DolphinMainWindow::updateGoActions()
1451 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
1452 const KUrl
& currentUrl
= m_activeViewContainer
->url();
1453 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
1456 void DolphinMainWindow::rememberClosedTab(int index
)
1458 KMenu
* tabsMenu
= m_recentTabsMenu
->menu();
1460 const QString primaryPath
= m_viewTab
[index
].primaryView
->url().path();
1461 const QString iconName
= KMimeType::iconNameForUrl(primaryPath
);
1463 QAction
* action
= new QAction(squeezedText(primaryPath
), tabsMenu
);
1465 ClosedTab closedTab
;
1466 closedTab
.primaryUrl
= m_viewTab
[index
].primaryView
->url();
1468 if (m_viewTab
[index
].secondaryView
!= 0) {
1469 closedTab
.secondaryUrl
= m_viewTab
[index
].secondaryView
->url();
1470 closedTab
.isSplit
= true;
1472 closedTab
.isSplit
= false;
1475 action
->setData(QVariant::fromValue(closedTab
));
1476 action
->setIcon(KIcon(iconName
));
1478 // add the closed tab menu entry after the separator and
1479 // "Empty Recently Closed Tabs" entry
1480 if (tabsMenu
->actions().size() == 2) {
1481 tabsMenu
->addAction(action
);
1483 tabsMenu
->insertAction(tabsMenu
->actions().at(2), action
);
1486 // assure that only up to 8 closed tabs are shown in the menu
1487 if (tabsMenu
->actions().size() > 8) {
1488 tabsMenu
->removeAction(tabsMenu
->actions().last());
1490 actionCollection()->action("closed_tabs")->setEnabled(true);
1491 KAcceleratorManager::manage(tabsMenu
);
1494 void DolphinMainWindow::clearStatusBar()
1496 m_activeViewContainer
->statusBar()->clear();
1499 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
1501 connect(container
, SIGNAL(showFilterBarChanged(bool)),
1502 this, SLOT(updateFilterBarAction(bool)));
1504 DolphinView
* view
= container
->view();
1505 connect(view
, SIGNAL(selectionChanged(KFileItemList
)),
1506 this, SLOT(slotSelectionChanged(KFileItemList
)));
1507 connect(view
, SIGNAL(requestItemInfo(KFileItem
)),
1508 this, SLOT(slotRequestItemInfo(KFileItem
)));
1509 connect(view
, SIGNAL(activated()),
1510 this, SLOT(toggleActiveView()));
1511 connect(view
, SIGNAL(tabRequested(const KUrl
&)),
1512 this, SLOT(openNewTab(const KUrl
&)));
1514 const KUrlNavigator
* navigator
= container
->urlNavigator();
1515 connect(navigator
, SIGNAL(urlChanged(const KUrl
&)),
1516 this, SLOT(changeUrl(const KUrl
&)));
1517 connect(navigator
, SIGNAL(historyChanged()),
1518 this, SLOT(updateHistory()));
1519 connect(navigator
, SIGNAL(editableStateChanged(bool)),
1520 this, SLOT(slotEditableStateChanged(bool)));
1523 void DolphinMainWindow::updateSplitAction()
1525 QAction
* splitAction
= actionCollection()->action("split_view");
1526 if (m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
1527 if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
1528 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
1529 splitAction
->setToolTip(i18nc("@info", "Close right view"));
1530 splitAction
->setIcon(KIcon("view-right-close"));
1532 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
1533 splitAction
->setToolTip(i18nc("@info", "Close left view"));
1534 splitAction
->setIcon(KIcon("view-left-close"));
1537 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
1538 splitAction
->setToolTip(i18nc("@info", "Split view"));
1539 splitAction
->setIcon(KIcon("view-right-new"));
1543 QString
DolphinMainWindow::tabName(const KUrl
& url
) const
1546 if (url
.equals(KUrl("file:///"))) {
1549 name
= url
.fileName();
1550 if (name
.isEmpty()) {
1551 name
= url
.protocol();
1553 // Make sure that a '&' inside the directory name is displayed correctly
1554 // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
1555 name
.replace('&', "&&");
1561 bool DolphinMainWindow::isKompareInstalled() const
1563 static bool initialized
= false;
1564 static bool installed
= false;
1566 // TODO: maybe replace this approach later by using a menu
1567 // plugin like kdiff3plugin.cpp
1568 installed
= !KGlobal::dirs()->findExe("kompare").isEmpty();
1574 void DolphinMainWindow::createSecondaryView(int tabIndex
)
1576 QSplitter
* splitter
= m_viewTab
[tabIndex
].splitter
;
1577 const int newWidth
= (m_viewTab
[tabIndex
].primaryView
->width() - splitter
->handleWidth()) / 2;
1579 const DolphinView
* view
= m_viewTab
[tabIndex
].primaryView
->view();
1580 m_viewTab
[tabIndex
].secondaryView
= new DolphinViewContainer(this, 0, view
->rootUrl());
1581 splitter
->addWidget(m_viewTab
[tabIndex
].secondaryView
);
1582 splitter
->setSizes(QList
<int>() << newWidth
<< newWidth
);
1583 connectViewSignals(m_viewTab
[tabIndex
].secondaryView
);
1584 m_viewTab
[tabIndex
].secondaryView
->view()->reload();
1585 m_viewTab
[tabIndex
].secondaryView
->setActive(false);
1586 m_viewTab
[tabIndex
].secondaryView
->show();
1589 QString
DolphinMainWindow::tabProperty(const QString
& property
, int tabIndex
) const
1591 return "Tab " + QString::number(tabIndex
) + ' ' + property
;
1594 void DolphinMainWindow::setUrlAsCaption(const KUrl
& url
)
1597 if (url
.equals(KUrl("file:///"))) {
1600 caption
= url
.fileName();
1601 if (caption
.isEmpty()) {
1602 caption
= url
.protocol();
1606 setCaption(caption
);
1609 QString
DolphinMainWindow::squeezedText(const QString
& text
) const
1611 const QFontMetrics fm
= fontMetrics();
1612 return fm
.elidedText(text
, Qt::ElideMiddle
, fm
.maxWidth() * 10);
1615 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
1616 KIO::FileUndoManager::UiInterface()
1620 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
1624 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
1626 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
1628 DolphinStatusBar
* statusBar
= mainWin
->activeViewContainer()->statusBar();
1629 statusBar
->setMessage(job
->errorString(), DolphinStatusBar::Error
);
1631 KIO::FileUndoManager::UiInterface::jobError(job
);
1635 #include "dolphinmainwindow.moc"