1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> *
3 * Copyright (C) 2006 by Stefan Monov <logixoul@gmail.com> *
4 * Copyright (C) 2006 by Cvetoslav Ludmiloff <ludmiloff@gmail.com> *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20 ***************************************************************************/
22 #include "dolphinmainwindow.h"
23 #include "dolphinviewactionhandler.h"
24 #include "dolphinremoteencoding.h"
26 #include <config-nepomuk.h>
28 #include "search/dolphinsearchoptionsconfigurator.h"
31 #include "dolphinapplication.h"
32 #include "dolphinnewmenu.h"
33 #include "search/dolphinsearchbox.h"
34 #include "search/dolphinsearchoptionsconfigurator.h"
35 #include "settings/dolphinsettings.h"
36 #include "settings/dolphinsettingsdialog.h"
37 #include "dolphinviewcontainer.h"
38 #include "panels/folders/folderspanel.h"
39 #include "panels/places/placespanel.h"
40 #include "panels/information/informationpanel.h"
41 #include "mainwindowadaptor.h"
42 #include "statusbar/dolphinstatusbar.h"
43 #include "viewproperties.h"
46 #include "panels/terminal/terminalpanel.h"
49 #include "dolphin_generalsettings.h"
50 #include "dolphin_iconsmodesettings.h"
51 #include "draganddrophelper.h"
54 #include <kactioncollection.h>
56 #include <kdesktopfile.h>
57 #include <kdeversion.h>
58 #include <kfiledialog.h>
59 #include <kfileplacesmodel.h>
61 #include <klineedit.h>
64 #include <kiconloader.h>
65 #include <kio/netaccess.h>
66 #include <kinputdialog.h>
68 #include <kprotocolmanager.h>
71 #include <kmessagebox.h>
72 #include <kfileitemlistproperties.h>
73 #include <konqmimedata.h>
74 #include <kprotocolinfo.h>
77 #include <kstandarddirs.h>
78 #include <kstatusbar.h>
79 #include <kstandardaction.h>
81 #include <ktoggleaction.h>
82 #include <kurlnavigator.h>
84 #include <kurlcombobox.h>
85 #include <ktoolinvocation.h>
87 #include <QDBusMessage>
91 #include <QDockWidget>
92 #include <kacceleratormanager.h>
95 * Remembers the tab configuration if a tab has been closed.
96 * Each closed tab can be restored by the menu
97 * "Go -> Recently Closed Tabs".
105 Q_DECLARE_METATYPE(ClosedTab
)
107 DolphinMainWindow::DolphinMainWindow(int id
) :
112 m_activeViewContainer(0),
113 m_centralWidgetLayout(0),
116 m_searchOptionsConfigurator(0),
125 setObjectName("Dolphin#");
127 m_viewTab
.append(ViewTab());
129 new MainWindowAdaptor(this);
130 QDBusConnection::sessionBus().registerObject(QString("/dolphin/MainWindow%1").arg(m_id
), this);
132 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
133 undoManager
->setUiInterface(new UndoUiInterface());
135 connect(undoManager
, SIGNAL(undoAvailable(bool)),
136 this, SLOT(slotUndoAvailable(bool)));
137 connect(undoManager
, SIGNAL(undoTextChanged(const QString
&)),
138 this, SLOT(slotUndoTextChanged(const QString
&)));
139 connect(undoManager
, SIGNAL(jobRecordingStarted(CommandType
)),
140 this, SLOT(clearStatusBar()));
141 connect(undoManager
, SIGNAL(jobRecordingFinished(CommandType
)),
142 this, SLOT(showCommand(CommandType
)));
143 connect(DolphinSettings::instance().placesModel(), SIGNAL(errorMessage(const QString
&)),
144 this, SLOT(showErrorMessage(const QString
&)));
145 connect(&DragAndDropHelper::instance(), SIGNAL(errorMessage(const QString
&)),
146 this, SLOT(showErrorMessage(const QString
&)));
149 DolphinMainWindow::~DolphinMainWindow()
151 DolphinApplication::app()->removeMainWindow(this);
154 void DolphinMainWindow::toggleViews()
156 if (m_viewTab
[m_tabIndex
].primaryView
== 0) {
160 // move secondary view from the last position of the splitter
161 // to the first position
162 m_viewTab
[m_tabIndex
].splitter
->insertWidget(0, m_viewTab
[m_tabIndex
].secondaryView
);
164 DolphinViewContainer
* container
= m_viewTab
[m_tabIndex
].primaryView
;
165 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
166 m_viewTab
[m_tabIndex
].secondaryView
= container
;
169 void DolphinMainWindow::showCommand(CommandType command
)
171 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
173 case KIO::FileUndoManager::Copy
:
174 statusBar
->setMessage(i18nc("@info:status", "Successfully copied."),
175 DolphinStatusBar::OperationCompleted
);
177 case KIO::FileUndoManager::Move
:
178 statusBar
->setMessage(i18nc("@info:status", "Successfully moved."),
179 DolphinStatusBar::OperationCompleted
);
181 case KIO::FileUndoManager::Link
:
182 statusBar
->setMessage(i18nc("@info:status", "Successfully linked."),
183 DolphinStatusBar::OperationCompleted
);
185 case KIO::FileUndoManager::Trash
:
186 statusBar
->setMessage(i18nc("@info:status", "Successfully moved to trash."),
187 DolphinStatusBar::OperationCompleted
);
189 case KIO::FileUndoManager::Rename
:
190 statusBar
->setMessage(i18nc("@info:status", "Successfully renamed."),
191 DolphinStatusBar::OperationCompleted
);
194 case KIO::FileUndoManager::Mkdir
:
195 statusBar
->setMessage(i18nc("@info:status", "Created folder."),
196 DolphinStatusBar::OperationCompleted
);
204 void DolphinMainWindow::refreshViews()
206 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
208 // remember the current active view, as because of
209 // the refreshing the active view might change to
210 // the secondary view
211 DolphinViewContainer
* activeViewContainer
= m_activeViewContainer
;
213 const int tabCount
= m_viewTab
.count();
214 for (int i
= 0; i
< tabCount
; ++i
) {
215 m_viewTab
[i
].primaryView
->refresh();
216 if (m_viewTab
[i
].secondaryView
!= 0) {
217 m_viewTab
[i
].secondaryView
->refresh();
221 setActiveViewContainer(activeViewContainer
);
224 void DolphinMainWindow::pasteIntoFolder()
226 m_activeViewContainer
->view()->pasteIntoFolder();
229 void DolphinMainWindow::changeUrl(const KUrl
& url
)
231 if (!KProtocolManager::supportsListing(url
)) {
232 // The URL navigator only checks for validity, not
233 // if the URL can be listed. An error message is
234 // shown due to DolphinViewContainer::restoreView().
238 DolphinViewContainer
* view
= activeViewContainer();
244 setUrlAsCaption(url
);
245 if (m_viewTab
.count() > 1) {
246 m_tabBar
->setTabText(m_tabIndex
, squeezedText(tabName(m_activeViewContainer
->url())));
248 const QString iconName
= KMimeType::iconNameForUrl(url
);
249 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(iconName
));
250 emit
urlChanged(url
);
254 void DolphinMainWindow::changeSelection(const KFileItemList
& selection
)
256 activeViewContainer()->view()->changeSelection(selection
);
259 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
261 KToggleAction
* editableLocationAction
=
262 static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
263 editableLocationAction
->setChecked(editable
);
266 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
270 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
271 int selectedUrlsCount
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedItemsCount();
272 if (m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
273 selectedUrlsCount
+= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItemsCount();
276 QAction
* compareFilesAction
= actionCollection()->action("compare_files");
277 if (selectedUrlsCount
== 2) {
278 compareFilesAction
->setEnabled(isKompareInstalled());
280 compareFilesAction
->setEnabled(false);
283 emit
selectionChanged(selection
);
286 void DolphinMainWindow::slotWheelMoved(int wheelDelta
)
288 if (wheelDelta
> 0) {
295 void DolphinMainWindow::slotRequestItemInfo(const KFileItem
& item
)
297 emit
requestItemInfo(item
);
300 void DolphinMainWindow::updateHistory()
302 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
303 const int index
= urlNavigator
->historyIndex();
305 QAction
* backAction
= actionCollection()->action("go_back");
306 backAction
->setToolTip(i18nc("@info", "Go back"));
307 if (backAction
!= 0) {
308 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
311 QAction
* forwardAction
= actionCollection()->action("go_forward");
312 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
313 if (forwardAction
!= 0) {
314 forwardAction
->setEnabled(index
> 0);
318 void DolphinMainWindow::updateFilterBarAction(bool show
)
320 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
321 showFilterBarAction
->setChecked(show
);
324 void DolphinMainWindow::openNewMainWindow()
326 DolphinApplication::app()->createMainWindow()->show();
329 void DolphinMainWindow::openNewTab()
331 openNewTab(m_activeViewContainer
->url());
332 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
334 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
335 if (navigator
->isUrlEditable()) {
336 // if a new tab is opened and the URL is editable, assure that
337 // the user can edit the URL without manually setting the focus
338 navigator
->setFocus();
342 void DolphinMainWindow::openNewTab(const KUrl
& url
)
344 const KIcon icon
= KIcon(KMimeType::iconNameForUrl(m_activeViewContainer
->url()));
345 if (m_viewTab
.count() == 1) {
346 // Only one view is open currently and hence no tab is shown at
347 // all. Before creating a tab for 'url', provide a tab for the current URL.
348 m_tabBar
->addTab(icon
, squeezedText(tabName(m_activeViewContainer
->url())));
349 m_tabBar
->blockSignals(false);
352 m_tabBar
->addTab(icon
, squeezedText(tabName(url
)));
355 viewTab
.splitter
= new QSplitter(this);
356 viewTab
.splitter
->setChildrenCollapsible(false);
357 viewTab
.primaryView
= new DolphinViewContainer(this, viewTab
.splitter
, url
);
358 viewTab
.primaryView
->setActive(false);
359 connectViewSignals(viewTab
.primaryView
);
360 viewTab
.primaryView
->view()->reload();
362 m_viewTab
.append(viewTab
);
364 actionCollection()->action("close_tab")->setEnabled(true);
366 // provide a split view, if the startup settings are set this way
367 const GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
368 if (generalSettings
->splitView()) {
369 const int tabIndex
= m_viewTab
.count() - 1;
370 createSecondaryView(tabIndex
);
371 m_viewTab
[tabIndex
].secondaryView
->setActive(true);
372 m_viewTab
[tabIndex
].isPrimaryViewActive
= false;
376 void DolphinMainWindow::activateNextTab()
378 if ((m_viewTab
.count() == 1) || (m_tabBar
->count() < 2)) {
382 const int tabIndex
= (m_tabBar
->currentIndex() + 1) % m_tabBar
->count();
383 m_tabBar
->setCurrentIndex(tabIndex
);
386 void DolphinMainWindow::activatePrevTab()
388 if ((m_viewTab
.count() == 1) || (m_tabBar
->count() < 2)) {
392 int tabIndex
= m_tabBar
->currentIndex() - 1;
393 if (tabIndex
== -1) {
394 tabIndex
= m_tabBar
->count() - 1;
396 m_tabBar
->setCurrentIndex(tabIndex
);
399 void DolphinMainWindow::openInNewTab()
401 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
402 if ((list
.count() == 1) && list
[0].isDir()) {
403 openNewTab(m_activeViewContainer
->view()->selectedUrls()[0]);
407 void DolphinMainWindow::openInNewWindow()
409 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
410 if ((list
.count() == 1) && list
[0].isDir()) {
411 DolphinMainWindow
* window
= DolphinApplication::app()->createMainWindow();
412 window
->changeUrl(m_activeViewContainer
->view()->selectedUrls()[0]);
417 void DolphinMainWindow::toggleActiveView()
419 if (m_viewTab
[m_tabIndex
].secondaryView
== 0) {
420 // only one view is available
424 Q_ASSERT(m_activeViewContainer
!= 0);
425 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
427 DolphinViewContainer
* left
= m_viewTab
[m_tabIndex
].primaryView
;
428 DolphinViewContainer
* right
= m_viewTab
[m_tabIndex
].secondaryView
;
429 setActiveViewContainer(m_activeViewContainer
== right
? left
: right
);
432 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
434 DolphinSettings
& settings
= DolphinSettings::instance();
435 GeneralSettings
* generalSettings
= settings
.generalSettings();
437 // Find out if Dolphin is closed directly by the user or
438 // by the session manager because the session is closed
439 bool closedByUser
= true;
440 DolphinApplication
*application
= qobject_cast
<DolphinApplication
*>(qApp
);
441 if (application
&& application
->sessionSaving()) {
442 closedByUser
= false;
445 if ((m_viewTab
.count() > 1) && generalSettings
->confirmClosingMultipleTabs() && closedByUser
) {
446 // Ask the user if he really wants to quit and close all tabs.
447 // Open a confirmation dialog with 3 buttons:
448 // KDialog::Yes -> Quit
449 // KDialog::No -> Close only the current tab
450 // KDialog::Cancel -> do nothing
451 KDialog
*dialog
= new KDialog(this, Qt::Dialog
);
452 dialog
->setCaption(i18nc("@title:window", "Confirmation"));
453 dialog
->setButtons(KDialog::Yes
| KDialog::No
| KDialog::Cancel
);
454 dialog
->setModal(true);
455 dialog
->showButtonSeparator(true);
456 dialog
->setButtonGuiItem(KDialog::Yes
, KStandardGuiItem::quit());
457 dialog
->setButtonGuiItem(KDialog::No
, KGuiItem(i18n("C&lose Current Tab"), KIcon("tab-close")));
458 dialog
->setButtonGuiItem(KDialog::Cancel
, KStandardGuiItem::cancel());
459 dialog
->setDefaultButton(KDialog::Yes
);
461 bool doNotAskAgainCheckboxResult
= false;
463 const int result
= KMessageBox::createKMessageBox(dialog
,
464 QMessageBox::Warning
,
465 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
467 i18n("Do not ask again"),
468 &doNotAskAgainCheckboxResult
,
469 KMessageBox::Notify
);
471 if (doNotAskAgainCheckboxResult
) {
472 generalSettings
->setConfirmClosingMultipleTabs(false);
480 // Close only the current tab
488 generalSettings
->setFirstRun(false);
492 KXmlGuiWindow::closeEvent(event
);
495 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
497 const int tabCount
= m_viewTab
.count();
498 group
.writeEntry("Tab Count", tabCount
);
499 group
.writeEntry("Active Tab Index", m_tabBar
->currentIndex());
501 for (int i
= 0; i
< tabCount
; ++i
) {
502 const DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
503 group
.writeEntry(tabProperty("Primary URL", i
), cont
->url().url());
504 group
.writeEntry(tabProperty("Primary Editable", i
), cont
->isUrlEditable());
506 cont
= m_viewTab
[i
].secondaryView
;
508 group
.writeEntry(tabProperty("Secondary URL", i
), cont
->url().url());
509 group
.writeEntry(tabProperty("Secondary Editable", i
), cont
->isUrlEditable());
514 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
516 const int tabCount
= group
.readEntry("Tab Count", 1);
517 for (int i
= 0; i
< tabCount
; ++i
) {
518 DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
520 cont
->setUrl(group
.readEntry(tabProperty("Primary URL", i
)));
521 const bool editable
= group
.readEntry(tabProperty("Primary Editable", i
), false);
522 cont
->urlNavigator()->setUrlEditable(editable
);
524 cont
= m_viewTab
[i
].secondaryView
;
525 const QString secondaryUrl
= group
.readEntry(tabProperty("Secondary URL", i
));
526 if (!secondaryUrl
.isEmpty()) {
528 // a secondary view should be shown, but no one is available
529 // currently -> create a new view
531 cont
= m_viewTab
[i
].secondaryView
;
535 cont
->setUrl(secondaryUrl
);
536 const bool editable
= group
.readEntry(tabProperty("Secondary Editable", i
), false);
537 cont
->urlNavigator()->setUrlEditable(editable
);
538 } else if (cont
!= 0) {
539 // no secondary view should be shown, but the default setting shows
540 // one already -> close the view
544 // openNewTab() needs to be called only tabCount - 1 times
545 if (i
!= tabCount
- 1) {
550 const int index
= group
.readEntry("Active Tab Index", 0);
551 m_tabBar
->setCurrentIndex(index
);
554 void DolphinMainWindow::updateNewMenu()
556 m_newMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->showHiddenFiles());
557 m_newMenu
->slotCheckUpToDate();
558 m_newMenu
->setPopupFiles(activeViewContainer()->url());
561 void DolphinMainWindow::createDirectory()
563 m_newMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->showHiddenFiles());
564 m_newMenu
->setPopupFiles(activeViewContainer()->url());
565 m_newMenu
->createDirectory();
568 void DolphinMainWindow::quit()
573 void DolphinMainWindow::showErrorMessage(const QString
& message
)
575 if (!message
.isEmpty()) {
576 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
577 statusBar
->setMessage(message
, DolphinStatusBar::Error
);
581 void DolphinMainWindow::slotUndoAvailable(bool available
)
583 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
584 if (undoAction
!= 0) {
585 undoAction
->setEnabled(available
);
589 void DolphinMainWindow::restoreClosedTab(QAction
* action
)
591 if (action
->data().toBool()) {
592 // clear all actions except the "Empty Recently Closed Tabs"
593 // action and the separator
594 QList
<QAction
*> actions
= m_recentTabsMenu
->menu()->actions();
595 const int count
= actions
.size();
596 for (int i
= 2; i
< count
; ++i
) {
597 m_recentTabsMenu
->menu()->removeAction(actions
.at(i
));
600 const ClosedTab closedTab
= action
->data().value
<ClosedTab
>();
601 openNewTab(closedTab
.primaryUrl
);
602 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
604 if (closedTab
.isSplit
) {
605 // create secondary view
607 m_viewTab
[m_tabIndex
].secondaryView
->setUrl(closedTab
.secondaryUrl
);
610 m_recentTabsMenu
->removeAction(action
);
613 if (m_recentTabsMenu
->menu()->actions().count() == 2) {
614 m_recentTabsMenu
->setEnabled(false);
618 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
620 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
621 if (undoAction
!= 0) {
622 undoAction
->setText(text
);
626 void DolphinMainWindow::undo()
629 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
630 KIO::FileUndoManager::self()->undo();
633 void DolphinMainWindow::cut()
635 m_activeViewContainer
->view()->cutSelectedItems();
638 void DolphinMainWindow::copy()
640 m_activeViewContainer
->view()->copySelectedItems();
643 void DolphinMainWindow::paste()
645 m_activeViewContainer
->view()->paste();
648 void DolphinMainWindow::updatePasteAction()
650 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
651 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
652 pasteAction
->setEnabled(pasteInfo
.first
);
653 pasteAction
->setText(pasteInfo
.second
);
656 void DolphinMainWindow::selectAll()
660 // if the URL navigator is editable and focused, select the whole
661 // URL instead of all items of the view
663 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
664 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit(); // krazy:exclude=qclasses
665 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
666 lineEdit
->hasFocus();
668 lineEdit
->selectAll();
670 m_activeViewContainer
->view()->selectAll();
674 void DolphinMainWindow::invertSelection()
677 m_activeViewContainer
->view()->invertSelection();
680 void DolphinMainWindow::toggleSplitView()
682 if (m_viewTab
[m_tabIndex
].secondaryView
== 0) {
683 createSecondaryView(m_tabIndex
);
684 setActiveViewContainer(m_viewTab
[m_tabIndex
].secondaryView
);
685 } else if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
686 // remove secondary view
687 m_viewTab
[m_tabIndex
].secondaryView
->close();
688 m_viewTab
[m_tabIndex
].secondaryView
->deleteLater();
689 m_viewTab
[m_tabIndex
].secondaryView
= 0;
691 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
693 // The primary view is active and should be closed. Hence from a users point of view
694 // the content of the secondary view should be moved to the primary view.
695 // From an implementation point of view it is more efficient to close
696 // the primary view and exchange the internal pointers afterwards.
698 m_viewTab
[m_tabIndex
].primaryView
->close();
699 m_viewTab
[m_tabIndex
].primaryView
->deleteLater();
700 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
701 m_viewTab
[m_tabIndex
].secondaryView
= 0;
703 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
709 void DolphinMainWindow::reloadView()
712 m_activeViewContainer
->view()->reload();
715 void DolphinMainWindow::stopLoading()
719 void DolphinMainWindow::toggleFilterBarVisibility(bool show
)
721 m_activeViewContainer
->showFilterBar(show
);
724 void DolphinMainWindow::toggleEditLocation()
728 QAction
* action
= actionCollection()->action("editable_location");
729 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
730 urlNavigator
->setUrlEditable(action
->isChecked());
733 void DolphinMainWindow::replaceLocation()
735 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
736 navigator
->setUrlEditable(true);
737 navigator
->setFocus();
739 // select the whole text of the combo box editor
740 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit(); // krazy:exclude=qclasses
741 const QString text
= lineEdit
->text();
742 lineEdit
->setSelection(0, text
.length());
745 void DolphinMainWindow::goBack()
748 m_activeViewContainer
->urlNavigator()->goBack();
751 void DolphinMainWindow::goForward()
754 m_activeViewContainer
->urlNavigator()->goForward();
757 void DolphinMainWindow::goUp()
760 m_activeViewContainer
->urlNavigator()->goUp();
763 void DolphinMainWindow::goBack(Qt::MouseButtons buttons
)
765 // The default case (left button pressed) is handled in goBack().
766 if (buttons
== Qt::MidButton
) {
767 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
768 openNewTab(urlNavigator
->historyUrl(urlNavigator
->historyIndex() + 1));
772 void DolphinMainWindow::goForward(Qt::MouseButtons buttons
)
774 // The default case (left button pressed) is handled in goForward().
775 if (buttons
== Qt::MidButton
) {
776 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
777 openNewTab(urlNavigator
->historyUrl(urlNavigator
->historyIndex() - 1));
781 void DolphinMainWindow::goUp(Qt::MouseButtons buttons
)
783 // The default case (left button pressed) is handled in goUp().
784 if (buttons
== Qt::MidButton
) {
785 openNewTab(activeViewContainer()->url().upUrl());
789 void DolphinMainWindow::goHome()
792 m_activeViewContainer
->urlNavigator()->goHome();
795 void DolphinMainWindow::compareFiles()
797 // The method is only invoked if exactly 2 files have
798 // been selected. The selected files may be:
799 // - both in the primary view
800 // - both in the secondary view
801 // - one in the primary view and the other in the secondary
803 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
807 KUrl::List urls
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedUrls();
809 switch (urls
.count()) {
811 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
!= 0);
812 urls
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedUrls();
813 Q_ASSERT(urls
.count() == 2);
821 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
!= 0);
822 urls
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedUrls();
823 Q_ASSERT(urls
.count() == 1);
835 // may not happen: compareFiles may only get invoked if 2
836 // files are selected
841 QString
command("kompare -c \"");
842 command
.append(urlA
.pathOrUrl());
843 command
.append("\" \"");
844 command
.append(urlB
.pathOrUrl());
845 command
.append('\"');
846 KRun::runCommand(command
, "Kompare", "kompare", this);
849 void DolphinMainWindow::toggleShowMenuBar()
851 const bool visible
= menuBar()->isVisible();
852 menuBar()->setVisible(!visible
);
855 void DolphinMainWindow::openTerminal()
857 QString
dir(QDir::homePath());
859 // If the given directory is not local, it can still be the URL of an
860 // ioslave using UDS_LOCAL_PATH which to be converted first.
861 KUrl url
= KIO::NetAccess::mostLocalUrl(m_activeViewContainer
->url(), this);
863 //If the URL is local after the above conversion, set the directory.
864 if (url
.isLocalFile()) {
865 dir
= url
.toLocalFile();
868 KToolInvocation::invokeTerminal(QString(), dir
);
871 void DolphinMainWindow::editSettings()
873 if (m_settingsDialog
== 0) {
874 const KUrl
& url
= activeViewContainer()->url();
875 m_settingsDialog
= new DolphinSettingsDialog(url
, this);
876 m_settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
877 m_settingsDialog
->show();
879 m_settingsDialog
->raise();
883 void DolphinMainWindow::setActiveTab(int index
)
885 Q_ASSERT(index
>= 0);
886 Q_ASSERT(index
< m_viewTab
.count());
887 if (index
== m_tabIndex
) {
891 // hide current tab content
892 ViewTab
& hiddenTab
= m_viewTab
[m_tabIndex
];
893 hiddenTab
.isPrimaryViewActive
= hiddenTab
.primaryView
->isActive();
894 hiddenTab
.primaryView
->setActive(false);
895 if (hiddenTab
.secondaryView
!= 0) {
896 hiddenTab
.secondaryView
->setActive(false);
898 QSplitter
* splitter
= m_viewTab
[m_tabIndex
].splitter
;
900 m_centralWidgetLayout
->removeWidget(splitter
);
902 // show active tab content
905 ViewTab
& viewTab
= m_viewTab
[index
];
906 m_centralWidgetLayout
->addWidget(viewTab
.splitter
, 1);
907 viewTab
.primaryView
->show();
908 if (viewTab
.secondaryView
!= 0) {
909 viewTab
.secondaryView
->show();
911 viewTab
.splitter
->show();
913 setActiveViewContainer(viewTab
.isPrimaryViewActive
? viewTab
.primaryView
:
914 viewTab
.secondaryView
);
917 void DolphinMainWindow::closeTab()
919 closeTab(m_tabBar
->currentIndex());
922 void DolphinMainWindow::closeTab(int index
)
924 Q_ASSERT(index
>= 0);
925 Q_ASSERT(index
< m_viewTab
.count());
926 if (m_viewTab
.count() == 1) {
927 // the last tab may never get closed
931 if (index
== m_tabIndex
) {
932 // The tab that should be closed is the active tab. Activate the
933 // previous tab before closing the tab.
934 m_tabBar
->setCurrentIndex((index
> 0) ? index
- 1 : 1);
936 rememberClosedTab(index
);
939 m_viewTab
[index
].primaryView
->deleteLater();
940 if (m_viewTab
[index
].secondaryView
!= 0) {
941 m_viewTab
[index
].secondaryView
->deleteLater();
943 m_viewTab
[index
].splitter
->deleteLater();
944 m_viewTab
.erase(m_viewTab
.begin() + index
);
946 m_tabBar
->blockSignals(true);
947 m_tabBar
->removeTab(index
);
949 if (m_tabIndex
> index
) {
951 Q_ASSERT(m_tabIndex
>= 0);
954 // if only one tab is left, also remove the tab entry so that
955 // closing the last tab is not possible
956 if (m_viewTab
.count() == 1) {
957 m_tabBar
->removeTab(0);
958 actionCollection()->action("close_tab")->setEnabled(false);
960 m_tabBar
->blockSignals(false);
964 void DolphinMainWindow::openTabContextMenu(int index
, const QPoint
& pos
)
968 QAction
* newTabAction
= menu
.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab"));
969 newTabAction
->setShortcut(actionCollection()->action("new_tab")->shortcut());
971 QAction
* closeOtherTabsAction
= menu
.addAction(KIcon("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs"));
973 QAction
* closeTabAction
= menu
.addAction(KIcon("tab-close"), i18nc("@action:inmenu", "Close Tab"));
974 closeTabAction
->setShortcut(actionCollection()->action("close_tab")->shortcut());
975 QAction
* selectedAction
= menu
.exec(pos
);
976 if (selectedAction
== newTabAction
) {
977 const ViewTab
& tab
= m_viewTab
[index
];
978 Q_ASSERT(tab
.primaryView
!= 0);
979 const KUrl url
= (tab
.secondaryView
!= 0) && tab
.secondaryView
->isActive() ?
980 tab
.secondaryView
->url() : tab
.primaryView
->url();
982 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
983 } else if (selectedAction
== closeOtherTabsAction
) {
984 const int count
= m_tabBar
->count();
985 for (int i
= 0; i
< index
; ++i
) {
988 for (int i
= index
+ 1; i
< count
; ++i
) {
991 } else if (selectedAction
== closeTabAction
) {
996 void DolphinMainWindow::handlePlacesClick(const KUrl
& url
, Qt::MouseButtons buttons
)
998 if (buttons
& Qt::MidButton
) {
1000 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
1006 void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent
* event
, bool& canDecode
)
1008 canDecode
= KUrl::List::canDecode(event
->mimeData());
1011 void DolphinMainWindow::searchItems()
1014 const KUrl nepomukSearchUrl
= m_searchOptionsConfigurator
->nepomukSearchUrl();
1015 m_activeViewContainer
->setUrl(nepomukSearchUrl
);
1019 void DolphinMainWindow::slotTabMoved(int from
, int to
)
1021 m_viewTab
.move(from
, to
);
1022 m_tabIndex
= m_tabBar
->currentIndex();
1025 void DolphinMainWindow::showSearchOptions()
1028 m_searchOptionsConfigurator
->show();
1032 void DolphinMainWindow::init()
1034 DolphinSettings
& settings
= DolphinSettings::instance();
1036 // Check whether Dolphin runs the first time. If yes then
1037 // a proper default window size is given at the end of DolphinMainWindow::init().
1038 GeneralSettings
* generalSettings
= settings
.generalSettings();
1039 const bool firstRun
= generalSettings
->firstRun();
1041 generalSettings
->setViewPropsTimestamp(QDateTime::currentDateTime());
1044 setAcceptDrops(true);
1046 m_viewTab
[m_tabIndex
].splitter
= new QSplitter(this);
1047 m_viewTab
[m_tabIndex
].splitter
->setChildrenCollapsible(false);
1051 const KUrl
& homeUrl
= generalSettings
->homeUrl();
1052 setUrlAsCaption(homeUrl
);
1053 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
1054 connect(m_actionHandler
, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
1055 connect(m_actionHandler
, SIGNAL(createDirectory()), SLOT(createDirectory()));
1056 ViewProperties
props(homeUrl
);
1057 m_viewTab
[m_tabIndex
].primaryView
= new DolphinViewContainer(this,
1058 m_viewTab
[m_tabIndex
].splitter
,
1061 m_activeViewContainer
= m_viewTab
[m_tabIndex
].primaryView
;
1062 connectViewSignals(m_activeViewContainer
);
1063 DolphinView
* view
= m_activeViewContainer
->view();
1065 m_activeViewContainer
->show();
1066 m_actionHandler
->setCurrentView(view
);
1068 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
1069 connect(this, SIGNAL(urlChanged(const KUrl
&)),
1070 m_remoteEncoding
, SLOT(slotAboutToOpenUrl()));
1073 m_searchOptionsConfigurator
= new DolphinSearchOptionsConfigurator(this);
1074 m_searchOptionsConfigurator
->hide();
1075 connect(m_searchOptionsConfigurator
, SIGNAL(searchOptionsChanged()),
1076 this, SLOT(searchItems()));
1077 connect(this, SIGNAL(urlChanged(KUrl
)), m_searchOptionsConfigurator
, SLOT(setDirectory(KUrl
)));
1080 m_tabBar
= new KTabBar(this);
1081 m_tabBar
->setMovable(true);
1082 m_tabBar
->setTabsClosable(true);
1083 connect(m_tabBar
, SIGNAL(currentChanged(int)),
1084 this, SLOT(setActiveTab(int)));
1085 connect(m_tabBar
, SIGNAL(tabCloseRequested(int)),
1086 this, SLOT(closeTab(int)));
1087 connect(m_tabBar
, SIGNAL(contextMenu(int, const QPoint
&)),
1088 this, SLOT(openTabContextMenu(int, const QPoint
&)));
1089 connect(m_tabBar
, SIGNAL(newTabRequest()),
1090 this, SLOT(openNewTab()));
1091 connect(m_tabBar
, SIGNAL(testCanDecode(const QDragMoveEvent
*, bool&)),
1092 this, SLOT(slotTestCanDecode(const QDragMoveEvent
*, bool&)));
1093 connect(m_tabBar
, SIGNAL(wheelDelta(int)),
1094 this, SLOT(slotWheelMoved(int)));
1095 connect(m_tabBar
, SIGNAL(mouseMiddleClick(int)),
1096 this, SLOT(closeTab(int)));
1097 connect(m_tabBar
, SIGNAL(tabMoved(int, int)),
1098 this, SLOT(slotTabMoved(int, int)));
1100 m_tabBar
->blockSignals(true); // signals get unblocked after at least 2 tabs are open
1102 QWidget
* centralWidget
= new QWidget(this);
1103 m_centralWidgetLayout
= new QVBoxLayout(centralWidget
);
1104 m_centralWidgetLayout
->setSpacing(0);
1105 m_centralWidgetLayout
->setMargin(0);
1107 m_centralWidgetLayout
->addWidget(m_searchOptionsConfigurator
);
1109 m_centralWidgetLayout
->addWidget(m_tabBar
);
1110 m_centralWidgetLayout
->addWidget(m_viewTab
[m_tabIndex
].splitter
, 1);
1112 setCentralWidget(centralWidget
);
1114 emit
urlChanged(homeUrl
);
1116 setupGUI(Keys
| Save
| Create
| ToolBar
);
1118 m_searchBox
->setParent(toolBar("searchToolBar"));
1119 m_searchBox
->show();
1120 connect(m_searchBox
, SIGNAL(requestSearchOptions()),
1121 this, SLOT(showSearchOptions()));
1123 connect(m_searchBox
, SIGNAL(searchTextChanged(QString
)),
1124 m_searchOptionsConfigurator
, SLOT(setCustomSearchQuery(QString
)));
1127 stateChanged("new_file");
1129 QClipboard
* clipboard
= QApplication::clipboard();
1130 connect(clipboard
, SIGNAL(dataChanged()),
1131 this, SLOT(updatePasteAction()));
1132 updatePasteAction();
1135 if (generalSettings
->splitView()) {
1138 updateViewActions();
1140 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1141 showFilterBarAction
->setChecked(generalSettings
->filterBar());
1144 // assure a proper default size if Dolphin runs the first time
1148 m_showMenuBar
->setChecked(!menuBar()->isHidden()); // workaround for bug #171080
1151 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer
* viewContainer
)
1153 Q_ASSERT(viewContainer
!= 0);
1154 Q_ASSERT((viewContainer
== m_viewTab
[m_tabIndex
].primaryView
) ||
1155 (viewContainer
== m_viewTab
[m_tabIndex
].secondaryView
));
1156 if (m_activeViewContainer
== viewContainer
) {
1160 m_activeViewContainer
->setActive(false);
1161 m_activeViewContainer
= viewContainer
;
1163 // Activating the view container might trigger a recursive setActiveViewContainer() call
1164 // inside DolphinMainWindow::toggleActiveView() when having a split view. Temporary
1165 // disconnect the activated() signal in this case:
1166 disconnect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1167 m_activeViewContainer
->setActive(true);
1168 connect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1170 m_actionHandler
->setCurrentView(viewContainer
->view());
1173 updateEditActions();
1174 updateViewActions();
1177 const KUrl
& url
= m_activeViewContainer
->url();
1178 setUrlAsCaption(url
);
1179 if (m_viewTab
.count() > 1 && m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
1180 m_tabBar
->setTabText(m_tabIndex
, tabName(url
));
1181 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(KMimeType::iconNameForUrl(url
)));
1184 emit
urlChanged(url
);
1187 void DolphinMainWindow::setupActions()
1189 // setup 'File' menu
1190 m_newMenu
= new DolphinNewMenu(this, this);
1191 KMenu
* menu
= m_newMenu
->menu();
1192 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1193 menu
->setIcon(KIcon("document-new"));
1194 connect(menu
, SIGNAL(aboutToShow()),
1195 this, SLOT(updateNewMenu()));
1197 KAction
* newWindow
= actionCollection()->addAction("new_window");
1198 newWindow
->setIcon(KIcon("window-new"));
1199 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1200 newWindow
->setShortcut(Qt::CTRL
| Qt::Key_N
);
1201 connect(newWindow
, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1203 KAction
* newTab
= actionCollection()->addAction("new_tab");
1204 newTab
->setIcon(KIcon("tab-new"));
1205 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1206 newTab
->setShortcut(KShortcut(Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
));
1207 connect(newTab
, SIGNAL(triggered()), this, SLOT(openNewTab()));
1209 KAction
* closeTab
= actionCollection()->addAction("close_tab");
1210 closeTab
->setIcon(KIcon("tab-close"));
1211 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1212 closeTab
->setShortcut(Qt::CTRL
| Qt::Key_W
);
1213 closeTab
->setEnabled(false);
1214 connect(closeTab
, SIGNAL(triggered()), this, SLOT(closeTab()));
1216 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1218 // setup 'Edit' menu
1219 KStandardAction::undo(this,
1221 actionCollection());
1223 // need to remove shift+del from cut action, else the shortcut for deletejob
1225 KAction
* cut
= KStandardAction::cut(this, SLOT(cut()), actionCollection());
1226 KShortcut cutShortcut
= cut
->shortcut();
1227 cutShortcut
.remove(Qt::SHIFT
+ Qt::Key_Delete
, KShortcut::KeepEmpty
);
1228 cut
->setShortcut(cutShortcut
);
1229 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1230 KAction
* paste
= KStandardAction::paste(this, SLOT(paste()), actionCollection());
1231 // The text of the paste-action is modified dynamically by Dolphin
1232 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1233 // due to the long text, the text "Paste" is used:
1234 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1236 KAction
* selectAll
= actionCollection()->addAction("select_all");
1237 selectAll
->setText(i18nc("@action:inmenu Edit", "Select All"));
1238 selectAll
->setShortcut(Qt::CTRL
+ Qt::Key_A
);
1239 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
1241 KAction
* invertSelection
= actionCollection()->addAction("invert_selection");
1242 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1243 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1244 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
1246 // setup 'View' menu
1247 // (note that most of it is set up in DolphinViewActionHandler)
1249 KAction
* split
= actionCollection()->addAction("split_view");
1250 split
->setShortcut(Qt::Key_F3
);
1251 updateSplitAction();
1252 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1254 KAction
* reload
= actionCollection()->addAction("reload");
1255 reload
->setText(i18nc("@action:inmenu View", "Reload"));
1256 reload
->setShortcut(Qt::Key_F5
);
1257 reload
->setIcon(KIcon("view-refresh"));
1258 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
1260 KAction
* stop
= actionCollection()->addAction("stop");
1261 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1262 stop
->setToolTip(i18nc("@info", "Stop loading"));
1263 stop
->setIcon(KIcon("process-stop"));
1264 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
1266 KToggleAction
* showFullLocation
= actionCollection()->add
<KToggleAction
>("editable_location");
1267 showFullLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1268 showFullLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
1269 connect(showFullLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1271 KAction
* replaceLocation
= actionCollection()->addAction("replace_location");
1272 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1273 replaceLocation
->setShortcut(Qt::Key_F6
);
1274 connect(replaceLocation
, SIGNAL(triggered()), this, SLOT(replaceLocation()));
1277 KAction
* backAction
= KStandardAction::back(this, SLOT(goBack()), actionCollection());
1278 connect(backAction
, SIGNAL(triggered(Qt::MouseButtons
, Qt::KeyboardModifiers
)), this, SLOT(goBack(Qt::MouseButtons
)));
1279 KShortcut backShortcut
= backAction
->shortcut();
1280 backShortcut
.setAlternate(Qt::Key_Backspace
);
1281 backAction
->setShortcut(backShortcut
);
1283 m_recentTabsMenu
= new KActionMenu(i18n("Recently Closed Tabs"), this);
1284 m_recentTabsMenu
->setIcon(KIcon("edit-undo"));
1285 actionCollection()->addAction("closed_tabs", m_recentTabsMenu
);
1286 connect(m_recentTabsMenu
->menu(), SIGNAL(triggered(QAction
*)),
1287 this, SLOT(restoreClosedTab(QAction
*)));
1289 QAction
* action
= new QAction("Empty Recently Closed Tabs", m_recentTabsMenu
);
1290 action
->setIcon(KIcon("edit-clear-list"));
1291 action
->setData(QVariant::fromValue(true));
1292 m_recentTabsMenu
->addAction(action
);
1293 m_recentTabsMenu
->addSeparator();
1294 m_recentTabsMenu
->setEnabled(false);
1296 KAction
* forwardAction
= KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1297 connect(forwardAction
, SIGNAL(triggered(Qt::MouseButtons
, Qt::KeyboardModifiers
)), this, SLOT(goForward(Qt::MouseButtons
)));
1299 KAction
* upAction
= KStandardAction::up(this, SLOT(goUp()), actionCollection());
1300 connect(upAction
, SIGNAL(triggered(Qt::MouseButtons
, Qt::KeyboardModifiers
)), this, SLOT(goUp(Qt::MouseButtons
)));
1302 KStandardAction::home(this, SLOT(goHome()), actionCollection());
1304 // setup 'Tools' menu
1305 KToggleAction
* showSearchBar
= actionCollection()->add
<KToggleAction
>("show_search_bar");
1306 showSearchBar
->setText(i18nc("@action:inmenu Tools", "Show Search Bar"));
1307 showSearchBar
->setShortcut(Qt::CTRL
| Qt::Key_S
);
1308 connect(showSearchBar
, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
1310 KToggleAction
* showFilterBar
= actionCollection()->add
<KToggleAction
>("show_filter_bar");
1311 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1312 showFilterBar
->setIcon(KIcon("view-filter"));
1313 showFilterBar
->setShortcut(Qt::CTRL
| Qt::Key_I
);
1314 connect(showFilterBar
, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
1316 KAction
* compareFiles
= actionCollection()->addAction("compare_files");
1317 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1318 compareFiles
->setIcon(KIcon("kompare"));
1319 compareFiles
->setEnabled(false);
1320 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
1322 KAction
* openTerminal
= actionCollection()->addAction("open_terminal");
1323 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1324 openTerminal
->setIcon(KIcon("utilities-terminal"));
1325 openTerminal
->setShortcut(Qt::SHIFT
| Qt::Key_F4
);
1326 connect(openTerminal
, SIGNAL(triggered()), this, SLOT(openTerminal()));
1328 // setup 'Settings' menu
1329 m_showMenuBar
= KStandardAction::showMenubar(this, SLOT(toggleShowMenuBar()), actionCollection());
1330 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1332 // not in menu actions
1333 KAction
* activateNextTab
= actionCollection()->addAction("activate_next_tab");
1334 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1335 connect(activateNextTab
, SIGNAL(triggered()), SLOT(activateNextTab()));
1336 activateNextTab
->setShortcuts(QApplication::isRightToLeft() ? KStandardShortcut::tabPrev() :
1337 KStandardShortcut::tabNext());
1339 KAction
* activatePrevTab
= actionCollection()->addAction("activate_prev_tab");
1340 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1341 connect(activatePrevTab
, SIGNAL(triggered()), SLOT(activatePrevTab()));
1342 activatePrevTab
->setShortcuts(QApplication::isRightToLeft() ? KStandardShortcut::tabNext() :
1343 KStandardShortcut::tabPrev());
1346 KAction
* openInNewTab
= actionCollection()->addAction("open_in_new_tab");
1347 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1348 openInNewTab
->setIcon(KIcon("tab-new"));
1349 connect(openInNewTab
, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1351 KAction
* openInNewWindow
= actionCollection()->addAction("open_in_new_window");
1352 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1353 openInNewWindow
->setIcon(KIcon("window-new"));
1354 connect(openInNewWindow
, SIGNAL(triggered()), this, SLOT(openInNewWindow()));
1357 m_searchBox
= new DolphinSearchBox(this);
1358 connect(m_searchBox
, SIGNAL(search(QString
)), this, SLOT(searchItems()));
1360 KAction
* search
= new KAction(this);
1361 actionCollection()->addAction("search_bar", search
);
1362 search
->setText(i18nc("@action:inmenu", "Search Bar"));
1363 search
->setDefaultWidget(m_searchBox
);
1364 search
->setShortcutConfigurable(false);
1367 void DolphinMainWindow::setupDockWidgets()
1369 // setup "Information"
1370 QDockWidget
* infoDock
= new QDockWidget(i18nc("@title:window", "Information"));
1371 infoDock
->setObjectName("infoDock");
1372 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1373 Panel
* infoPanel
= new InformationPanel(infoDock
);
1374 connect(infoPanel
, SIGNAL(urlActivated(KUrl
)), this, SLOT(handleUrl(KUrl
)));
1375 infoDock
->setWidget(infoPanel
);
1377 QAction
* infoAction
= infoDock
->toggleViewAction();
1378 infoAction
->setText(i18nc("@title:window", "Information"));
1379 infoAction
->setShortcut(Qt::Key_F11
);
1380 infoAction
->setIcon(KIcon("dialog-information"));
1381 actionCollection()->addAction("show_info_panel", infoDock
->toggleViewAction());
1383 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1384 connect(this, SIGNAL(urlChanged(KUrl
)),
1385 infoPanel
, SLOT(setUrl(KUrl
)));
1386 connect(this, SIGNAL(selectionChanged(KFileItemList
)),
1387 infoPanel
, SLOT(setSelection(KFileItemList
)));
1388 connect(this, SIGNAL(requestItemInfo(KFileItem
)),
1389 infoPanel
, SLOT(requestDelayedItemInfo(KFileItem
)));
1392 QDockWidget
* foldersDock
= new QDockWidget(i18nc("@title:window", "Folders"));
1393 foldersDock
->setObjectName("foldersDock");
1394 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1395 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1396 foldersDock
->setWidget(foldersPanel
);
1398 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1399 foldersAction
->setText(i18nc("@title:window", "Folders"));
1400 foldersAction
->setShortcut(Qt::Key_F7
);
1401 foldersAction
->setIcon(KIcon("folder"));
1402 actionCollection()->addAction("show_folders_panel", foldersDock
->toggleViewAction());
1404 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1405 connect(this, SIGNAL(urlChanged(KUrl
)),
1406 foldersPanel
, SLOT(setUrl(KUrl
)));
1407 connect(foldersPanel
, SIGNAL(changeUrl(KUrl
, Qt::MouseButtons
)),
1408 this, SLOT(handlePlacesClick(KUrl
, Qt::MouseButtons
)));
1409 connect(foldersPanel
, SIGNAL(changeSelection(KFileItemList
)),
1410 this, SLOT(changeSelection(KFileItemList
)));
1414 QDockWidget
* terminalDock
= new QDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1415 terminalDock
->setObjectName("terminalDock");
1416 terminalDock
->setAllowedAreas(Qt::TopDockWidgetArea
| Qt::BottomDockWidgetArea
);
1417 Panel
* terminalPanel
= new TerminalPanel(terminalDock
);
1418 terminalDock
->setWidget(terminalPanel
);
1420 connect(terminalPanel
, SIGNAL(hideTerminalPanel()), terminalDock
, SLOT(hide()));
1422 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1423 terminalAction
->setText(i18nc("@title:window Shell terminal", "Terminal"));
1424 terminalAction
->setShortcut(Qt::Key_F4
);
1425 terminalAction
->setIcon(KIcon("utilities-terminal"));
1426 actionCollection()->addAction("show_terminal_panel", terminalDock
->toggleViewAction());
1428 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1429 connect(this, SIGNAL(urlChanged(KUrl
)),
1430 terminalPanel
, SLOT(setUrl(KUrl
)));
1433 const bool firstRun
= DolphinSettings::instance().generalSettings()->firstRun();
1435 foldersDock
->hide();
1437 terminalDock
->hide();
1441 QDockWidget
* placesDock
= new QDockWidget(i18nc("@title:window", "Places"));
1442 placesDock
->setObjectName("placesDock");
1443 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1445 PlacesPanel
* placesPanel
= new PlacesPanel(placesDock
);
1446 placesDock
->setWidget(placesPanel
);
1447 placesPanel
->setModel(DolphinSettings::instance().placesModel());
1448 placesPanel
->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff
);
1450 QAction
* placesAction
= placesDock
->toggleViewAction();
1451 placesAction
->setText(i18nc("@title:window", "Places"));
1452 placesAction
->setShortcut(Qt::Key_F9
);
1453 placesAction
->setIcon(KIcon("bookmarks"));
1454 actionCollection()->addAction("show_places_panel", placesDock
->toggleViewAction());
1456 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1457 connect(placesPanel
, SIGNAL(urlChanged(KUrl
, Qt::MouseButtons
)),
1458 this, SLOT(handlePlacesClick(KUrl
, Qt::MouseButtons
)));
1459 connect(this, SIGNAL(urlChanged(KUrl
)),
1460 placesPanel
, SLOT(setUrl(KUrl
)));
1463 void DolphinMainWindow::updateEditActions()
1465 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1466 if (list
.isEmpty()) {
1467 stateChanged("has_no_selection");
1469 stateChanged("has_selection");
1471 KActionCollection
* col
= actionCollection();
1472 QAction
* renameAction
= col
->action("rename");
1473 QAction
* moveToTrashAction
= col
->action("move_to_trash");
1474 QAction
* deleteAction
= col
->action("delete");
1475 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
1476 QAction
* deleteWithTrashShortcut
= col
->action("delete_shortcut"); // see DolphinViewActionHandler
1478 KFileItemListProperties
capabilities(list
);
1479 const bool enableMoveToTrash
= capabilities
.isLocal() && capabilities
.supportsMoving();
1481 renameAction
->setEnabled(capabilities
.supportsMoving());
1482 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1483 deleteAction
->setEnabled(capabilities
.supportsDeleting());
1484 deleteWithTrashShortcut
->setEnabled(capabilities
.supportsDeleting() && !enableMoveToTrash
);
1485 cutAction
->setEnabled(capabilities
.supportsMoving());
1487 updatePasteAction();
1490 void DolphinMainWindow::updateViewActions()
1492 m_actionHandler
->updateViewActions();
1494 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1495 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
1497 updateSplitAction();
1499 QAction
* editableLocactionAction
= actionCollection()->action("editable_location");
1500 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
1501 editableLocactionAction
->setChecked(urlNavigator
->isUrlEditable());
1504 void DolphinMainWindow::updateGoActions()
1506 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
1507 const KUrl
& currentUrl
= m_activeViewContainer
->url();
1508 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
1511 void DolphinMainWindow::rememberClosedTab(int index
)
1513 KMenu
* tabsMenu
= m_recentTabsMenu
->menu();
1515 const QString primaryPath
= m_viewTab
[index
].primaryView
->url().path();
1516 const QString iconName
= KMimeType::iconNameForUrl(primaryPath
);
1518 QAction
* action
= new QAction(squeezedText(primaryPath
), tabsMenu
);
1520 ClosedTab closedTab
;
1521 closedTab
.primaryUrl
= m_viewTab
[index
].primaryView
->url();
1523 if (m_viewTab
[index
].secondaryView
!= 0) {
1524 closedTab
.secondaryUrl
= m_viewTab
[index
].secondaryView
->url();
1525 closedTab
.isSplit
= true;
1527 closedTab
.isSplit
= false;
1530 action
->setData(QVariant::fromValue(closedTab
));
1531 action
->setIcon(KIcon(iconName
));
1533 // add the closed tab menu entry after the separator and
1534 // "Empty Recently Closed Tabs" entry
1535 if (tabsMenu
->actions().size() == 2) {
1536 tabsMenu
->addAction(action
);
1538 tabsMenu
->insertAction(tabsMenu
->actions().at(2), action
);
1541 // assure that only up to 8 closed tabs are shown in the menu
1542 if (tabsMenu
->actions().size() > 8) {
1543 tabsMenu
->removeAction(tabsMenu
->actions().last());
1545 actionCollection()->action("closed_tabs")->setEnabled(true);
1546 KAcceleratorManager::manage(tabsMenu
);
1549 void DolphinMainWindow::clearStatusBar()
1551 m_activeViewContainer
->statusBar()->clear();
1554 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
1556 connect(container
, SIGNAL(showFilterBarChanged(bool)),
1557 this, SLOT(updateFilterBarAction(bool)));
1559 DolphinView
* view
= container
->view();
1560 connect(view
, SIGNAL(selectionChanged(KFileItemList
)),
1561 this, SLOT(slotSelectionChanged(KFileItemList
)));
1562 connect(view
, SIGNAL(requestItemInfo(KFileItem
)),
1563 this, SLOT(slotRequestItemInfo(KFileItem
)));
1564 connect(view
, SIGNAL(activated()),
1565 this, SLOT(toggleActiveView()));
1566 connect(view
, SIGNAL(tabRequested(const KUrl
&)),
1567 this, SLOT(openNewTab(const KUrl
&)));
1569 const KUrlNavigator
* navigator
= container
->urlNavigator();
1570 connect(navigator
, SIGNAL(urlChanged(const KUrl
&)),
1571 this, SLOT(changeUrl(const KUrl
&)));
1572 connect(navigator
, SIGNAL(historyChanged()),
1573 this, SLOT(updateHistory()));
1574 connect(navigator
, SIGNAL(editableStateChanged(bool)),
1575 this, SLOT(slotEditableStateChanged(bool)));
1578 void DolphinMainWindow::updateSplitAction()
1580 QAction
* splitAction
= actionCollection()->action("split_view");
1581 if (m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
1582 if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
1583 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
1584 splitAction
->setToolTip(i18nc("@info", "Close right view"));
1585 splitAction
->setIcon(KIcon("view-right-close"));
1587 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
1588 splitAction
->setToolTip(i18nc("@info", "Close left view"));
1589 splitAction
->setIcon(KIcon("view-left-close"));
1592 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
1593 splitAction
->setToolTip(i18nc("@info", "Split view"));
1594 splitAction
->setIcon(KIcon("view-right-new"));
1598 QString
DolphinMainWindow::tabName(const KUrl
& url
) const
1601 if (url
.equals(KUrl("file:///"))) {
1604 name
= url
.fileName();
1605 if (name
.isEmpty()) {
1606 name
= url
.protocol();
1608 // Make sure that a '&' inside the directory name is displayed correctly
1609 // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
1610 name
.replace('&', "&&");
1616 bool DolphinMainWindow::isKompareInstalled() const
1618 static bool initialized
= false;
1619 static bool installed
= false;
1621 // TODO: maybe replace this approach later by using a menu
1622 // plugin like kdiff3plugin.cpp
1623 installed
= !KGlobal::dirs()->findExe("kompare").isEmpty();
1629 void DolphinMainWindow::createSecondaryView(int tabIndex
)
1631 QSplitter
* splitter
= m_viewTab
[tabIndex
].splitter
;
1632 const int newWidth
= (m_viewTab
[tabIndex
].primaryView
->width() - splitter
->handleWidth()) / 2;
1634 const DolphinView
* view
= m_viewTab
[tabIndex
].primaryView
->view();
1635 m_viewTab
[tabIndex
].secondaryView
= new DolphinViewContainer(this, 0, view
->rootUrl());
1636 splitter
->addWidget(m_viewTab
[tabIndex
].secondaryView
);
1637 splitter
->setSizes(QList
<int>() << newWidth
<< newWidth
);
1638 connectViewSignals(m_viewTab
[tabIndex
].secondaryView
);
1639 m_viewTab
[tabIndex
].secondaryView
->view()->reload();
1640 m_viewTab
[tabIndex
].secondaryView
->setActive(false);
1641 m_viewTab
[tabIndex
].secondaryView
->show();
1644 QString
DolphinMainWindow::tabProperty(const QString
& property
, int tabIndex
) const
1646 return "Tab " + QString::number(tabIndex
) + ' ' + property
;
1649 void DolphinMainWindow::setUrlAsCaption(const KUrl
& url
)
1652 if (url
.equals(KUrl("file:///"))) {
1655 caption
= url
.fileName();
1656 if (caption
.isEmpty()) {
1657 caption
= url
.protocol();
1661 setCaption(caption
);
1664 void DolphinMainWindow::handleUrl(const KUrl
& url
)
1666 if (KProtocolManager::supportsListing(url
)) {
1667 activeViewContainer()->setUrl(url
);
1670 new KRun(url
, this);
1674 QString
DolphinMainWindow::squeezedText(const QString
& text
) const
1676 const QFontMetrics fm
= fontMetrics();
1677 return fm
.elidedText(text
, Qt::ElideMiddle
, fm
.maxWidth() * 10);
1680 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
1681 KIO::FileUndoManager::UiInterface()
1685 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
1689 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
1691 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
1693 DolphinStatusBar
* statusBar
= mainWin
->activeViewContainer()->statusBar();
1694 statusBar
->setMessage(job
->errorString(), DolphinStatusBar::Error
);
1696 KIO::FileUndoManager::UiInterface::jobError(job
);
1700 #include "dolphinmainwindow.moc"