1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz19@gmail.com> *
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"
24 #include <config-nepomuk.h>
26 #include "dolphinapplication.h"
27 #include "dolphindockwidget.h"
28 #include "dolphincontextmenu.h"
29 #include "dolphinnewfilemenu.h"
30 #include "dolphinviewcontainer.h"
32 #include "panels/search/searchpanel.h"
33 #include <Nepomuk/ResourceManager>
35 #include "panels/folders/folderspanel.h"
36 #include "panels/places/placespanel.h"
37 #include "panels/information/informationpanel.h"
38 #include "search/dolphinsearchbox.h"
39 #include "search/dolphinsearchinformation.h"
40 #include "settings/dolphinsettings.h"
41 #include "settings/dolphinsettingsdialog.h"
42 #include "statusbar/dolphinstatusbar.h"
43 #include "views/dolphinviewactionhandler.h"
44 #include "views/dolphinremoteencoding.h"
45 #include "views/viewproperties.h"
48 #include "panels/terminal/terminalpanel.h"
51 #include "dolphin_generalsettings.h"
52 #include "dolphin_iconsmodesettings.h"
53 #include "dolphin_searchsettings.h"
55 #include <KAcceleratorManager>
57 #include <KActionCollection>
58 #include <KActionMenu>
60 #include <KDesktopFile>
61 #include <kdeversion.h>
62 #include <kdualaction.h>
63 #include <KFileDialog>
64 #include <KFilePlacesModel>
69 #include <KIconLoader>
70 #include <KIO/NetAccess>
71 #include <KInputDialog>
73 #include <KProtocolManager>
76 #include <KMessageBox>
77 #include <KFileItemListProperties>
78 #include <konqmimedata.h>
79 #include <KProtocolInfo>
82 #include <KStandardDirs>
83 #include <kstatusbar.h>
84 #include <KStandardAction>
86 #include <KToggleAction>
87 #include <KUrlNavigator>
89 #include <KUrlComboBox>
90 #include <KToolInvocation>
92 #include <QDesktopWidget>
93 #include <QDBusMessage>
96 #include <QToolButton>
100 // Used for GeneralSettings::version() to determine whether
101 // an updated version of Dolphin is running.
102 const int CurrentDolphinVersion
= 200;
106 * Menu shown when pressing the configure-button in the toolbar.
108 class ToolBarMenu
: public KMenu
111 ToolBarMenu(QWidget
* parent
);
112 virtual ~ToolBarMenu();
114 virtual void showEvent(QShowEvent
* event
);
118 * Remembers the tab configuration if a tab has been closed.
119 * Each closed tab can be restored by the menu
120 * "Go -> Recently Closed Tabs".
128 Q_DECLARE_METATYPE(ClosedTab
)
130 DolphinMainWindow::DolphinMainWindow() :
134 m_activeViewContainer(0),
135 m_centralWidgetLayout(0),
142 m_openToolBarMenuButton(0),
143 m_updateToolBarTimer(0),
144 m_lastHandleUrlStatJob(0),
145 m_searchDockIsTemporaryVisible(false)
147 // Workaround for a X11-issue in combination with KModifierInfo
148 // (see DolphinContextMenu::initializeModifierKeyInfo() for
149 // more information):
150 DolphinContextMenu::initializeModifierKeyInfo();
152 setObjectName("Dolphin#");
154 m_viewTab
.append(ViewTab());
156 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
157 undoManager
->setUiInterface(new UndoUiInterface());
159 connect(undoManager
, SIGNAL(undoAvailable(bool)),
160 this, SLOT(slotUndoAvailable(bool)));
161 connect(undoManager
, SIGNAL(undoTextChanged(QString
)),
162 this, SLOT(slotUndoTextChanged(QString
)));
163 connect(undoManager
, SIGNAL(jobRecordingStarted(CommandType
)),
164 this, SLOT(clearStatusBar()));
165 connect(undoManager
, SIGNAL(jobRecordingFinished(CommandType
)),
166 this, SLOT(showCommand(CommandType
)));
167 connect(DolphinSettings::instance().placesModel(), SIGNAL(errorMessage(QString
)),
168 this, SLOT(showErrorMessage(QString
)));
169 //connect(&DragAndDropHelper::instance(), SIGNAL(errorMessage(QString)),
170 // this, SLOT(showErrorMessage(QString)));
172 const DolphinSettings
& settings
= DolphinSettings::instance();
174 GeneralSettings
* generalSettings
= settings
.generalSettings();
175 const bool firstRun
= (generalSettings
->version() < 200);
177 generalSettings
->setViewPropsTimestamp(QDateTime::currentDateTime());
180 setAcceptDrops(true);
182 m_viewTab
[m_tabIndex
].splitter
= new QSplitter(this);
183 m_viewTab
[m_tabIndex
].splitter
->setChildrenCollapsible(false);
187 const KUrl
homeUrl(generalSettings
->homeUrl());
188 setUrlAsCaption(homeUrl
);
189 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
190 connect(m_actionHandler
, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
191 connect(m_actionHandler
, SIGNAL(createDirectory()), SLOT(createDirectory()));
193 m_viewTab
[m_tabIndex
].primaryView
= createViewContainer(homeUrl
, m_viewTab
[m_tabIndex
].splitter
);
195 m_activeViewContainer
= m_viewTab
[m_tabIndex
].primaryView
;
196 connectViewSignals(m_activeViewContainer
);
197 DolphinView
* view
= m_activeViewContainer
->view();
198 m_activeViewContainer
->show();
199 m_actionHandler
->setCurrentView(view
);
201 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
202 connect(this, SIGNAL(urlChanged(KUrl
)),
203 m_remoteEncoding
, SLOT(slotAboutToOpenUrl()));
205 m_tabBar
= new KTabBar(this);
206 m_tabBar
->setMovable(true);
207 m_tabBar
->setTabsClosable(true);
208 connect(m_tabBar
, SIGNAL(currentChanged(int)),
209 this, SLOT(setActiveTab(int)));
210 connect(m_tabBar
, SIGNAL(tabCloseRequested(int)),
211 this, SLOT(closeTab(int)));
212 connect(m_tabBar
, SIGNAL(contextMenu(int,QPoint
)),
213 this, SLOT(openTabContextMenu(int,QPoint
)));
214 connect(m_tabBar
, SIGNAL(newTabRequest()),
215 this, SLOT(openNewTab()));
216 connect(m_tabBar
, SIGNAL(testCanDecode(const QDragMoveEvent
*,bool&)),
217 this, SLOT(slotTestCanDecode(const QDragMoveEvent
*,bool&)));
218 connect(m_tabBar
, SIGNAL(mouseMiddleClick(int)),
219 this, SLOT(closeTab(int)));
220 connect(m_tabBar
, SIGNAL(tabMoved(int,int)),
221 this, SLOT(slotTabMoved(int,int)));
222 connect(m_tabBar
, SIGNAL(receivedDropEvent(int,QDropEvent
*)),
223 this, SLOT(tabDropEvent(int,QDropEvent
*)));
225 m_tabBar
->blockSignals(true); // signals get unblocked after at least 2 tabs are open
227 QWidget
* centralWidget
= new QWidget(this);
228 m_centralWidgetLayout
= new QVBoxLayout(centralWidget
);
229 m_centralWidgetLayout
->setSpacing(0);
230 m_centralWidgetLayout
->setMargin(0);
231 m_centralWidgetLayout
->addWidget(m_tabBar
);
232 m_centralWidgetLayout
->addWidget(m_viewTab
[m_tabIndex
].splitter
, 1);
234 setCentralWidget(centralWidget
);
236 emit
urlChanged(homeUrl
);
238 setupGUI(Keys
| Save
| Create
| ToolBar
);
239 stateChanged("new_file");
241 QClipboard
* clipboard
= QApplication::clipboard();
242 connect(clipboard
, SIGNAL(dataChanged()),
243 this, SLOT(updatePasteAction()));
245 if (generalSettings
->splitView()) {
252 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
253 showFilterBarAction
->setChecked(generalSettings
->filterBar());
256 menuBar()->setVisible(false);
257 // Assure a proper default size if Dolphin runs the first time
261 const bool showMenu
= !menuBar()->isHidden();
262 QAction
* showMenuBarAction
= actionCollection()->action(KStandardAction::name(KStandardAction::ShowMenubar
));
263 showMenuBarAction
->setChecked(showMenu
); // workaround for bug #171080
265 createToolBarMenuButton();
269 DolphinMainWindow::~DolphinMainWindow()
273 void DolphinMainWindow::openDirectories(const QList
<KUrl
>& dirs
)
275 if (dirs
.isEmpty()) {
279 if (dirs
.count() == 1) {
280 m_activeViewContainer
->setUrl(dirs
.first());
284 const int oldOpenTabsCount
= m_viewTab
.count();
286 const GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
287 const bool hasSplitView
= generalSettings
->splitView();
289 // Open each directory inside a new tab. If the "split view" option has been enabled,
290 // always show two directories within one tab.
291 QList
<KUrl
>::const_iterator it
= dirs
.begin();
292 while (it
!= dirs
.end()) {
296 if (hasSplitView
&& (it
!= dirs
.end())) {
297 const int tabIndex
= m_viewTab
.count() - 1;
298 m_viewTab
[tabIndex
].secondaryView
->setUrl(*it
);
303 // Remove the previously opened tabs
304 for (int i
= 0; i
< oldOpenTabsCount
; ++i
) {
309 void DolphinMainWindow::openFiles(const QList
<KUrl
>& files
)
311 if (files
.isEmpty()) {
315 // Get all distinct directories from 'files' and open a tab
316 // for each directory. If the "split view" option is enabled, two
317 // directories are shown inside one tab (see openDirectories()).
319 foreach (const KUrl
& url
, files
) {
320 const KUrl
dir(url
.directory());
321 if (!dirs
.contains(dir
)) {
326 openDirectories(dirs
);
328 // Select the files. Although the files can be split between several
329 // tabs, there is no need to split 'files' accordingly, as
330 // the DolphinView will just ignore invalid selections.
331 const int tabCount
= m_viewTab
.count();
332 for (int i
= 0; i
< tabCount
; ++i
) {
333 m_viewTab
[i
].primaryView
->view()->markUrlsAsSelected(files
);
334 if (m_viewTab
[i
].secondaryView
) {
335 m_viewTab
[i
].secondaryView
->view()->markUrlsAsSelected(files
);
340 void DolphinMainWindow::showCommand(CommandType command
)
342 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
344 case KIO::FileUndoManager::Copy
:
345 statusBar
->setMessage(i18nc("@info:status", "Successfully copied."),
346 DolphinStatusBar::OperationCompleted
);
348 case KIO::FileUndoManager::Move
:
349 statusBar
->setMessage(i18nc("@info:status", "Successfully moved."),
350 DolphinStatusBar::OperationCompleted
);
352 case KIO::FileUndoManager::Link
:
353 statusBar
->setMessage(i18nc("@info:status", "Successfully linked."),
354 DolphinStatusBar::OperationCompleted
);
356 case KIO::FileUndoManager::Trash
:
357 statusBar
->setMessage(i18nc("@info:status", "Successfully moved to trash."),
358 DolphinStatusBar::OperationCompleted
);
360 case KIO::FileUndoManager::Rename
:
361 statusBar
->setMessage(i18nc("@info:status", "Successfully renamed."),
362 DolphinStatusBar::OperationCompleted
);
365 case KIO::FileUndoManager::Mkdir
:
366 statusBar
->setMessage(i18nc("@info:status", "Created folder."),
367 DolphinStatusBar::OperationCompleted
);
375 void DolphinMainWindow::pasteIntoFolder()
377 m_activeViewContainer
->view()->pasteIntoFolder();
380 void DolphinMainWindow::changeUrl(const KUrl
& url
)
382 if (!KProtocolManager::supportsListing(url
)) {
383 // The URL navigator only checks for validity, not
384 // if the URL can be listed. An error message is
385 // shown due to DolphinViewContainer::restoreView().
389 DolphinViewContainer
* view
= activeViewContainer();
395 setUrlAsCaption(url
);
396 if (m_viewTab
.count() > 1) {
397 m_tabBar
->setTabText(m_tabIndex
, squeezedText(tabName(m_activeViewContainer
->url())));
399 const QString iconName
= KMimeType::iconNameForUrl(url
);
400 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(iconName
));
401 emit
urlChanged(url
);
405 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
407 KToggleAction
* editableLocationAction
=
408 static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
409 editableLocationAction
->setChecked(editable
);
412 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
416 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
417 int selectedUrlsCount
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedItemsCount();
418 if (m_viewTab
[m_tabIndex
].secondaryView
) {
419 selectedUrlsCount
+= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItemsCount();
422 QAction
* compareFilesAction
= actionCollection()->action("compare_files");
423 if (selectedUrlsCount
== 2) {
424 compareFilesAction
->setEnabled(isKompareInstalled());
426 compareFilesAction
->setEnabled(false);
429 emit
selectionChanged(selection
);
432 void DolphinMainWindow::slotRequestItemInfo(const KFileItem
& item
)
434 emit
requestItemInfo(item
);
437 void DolphinMainWindow::updateHistory()
439 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
440 const int index
= urlNavigator
->historyIndex();
442 QAction
* backAction
= actionCollection()->action("go_back");
443 backAction
->setToolTip(i18nc("@info", "Go back"));
445 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
448 QAction
* forwardAction
= actionCollection()->action("go_forward");
449 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
451 forwardAction
->setEnabled(index
> 0);
455 void DolphinMainWindow::updateFilterBarAction(bool show
)
457 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
458 showFilterBarAction
->setChecked(show
);
461 void DolphinMainWindow::openNewMainWindow()
463 KRun::run("dolphin", KUrl::List(), this);
466 void DolphinMainWindow::openNewTab()
468 const bool isUrlEditable
= m_activeViewContainer
->urlNavigator()->isUrlEditable();
470 openNewTab(m_activeViewContainer
->url());
471 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
473 // The URL navigator of the new tab should have the same editable state
474 // as the current tab
475 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
476 navigator
->setUrlEditable(isUrlEditable
);
479 // If a new tab is opened and the URL is editable, assure that
480 // the user can edit the URL without manually setting the focus
481 navigator
->setFocus();
485 void DolphinMainWindow::openNewTab(const KUrl
& url
)
487 QWidget
* focusWidget
= QApplication::focusWidget();
489 if (m_viewTab
.count() == 1) {
490 // Only one view is open currently and hence no tab is shown at
491 // all. Before creating a tab for 'url', provide a tab for the current URL.
492 const KUrl currentUrl
= m_activeViewContainer
->url();
493 m_tabBar
->addTab(KIcon(KMimeType::iconNameForUrl(currentUrl
)),
494 squeezedText(tabName(currentUrl
)));
495 m_tabBar
->blockSignals(false);
498 m_tabBar
->addTab(KIcon(KMimeType::iconNameForUrl(url
)),
499 squeezedText(tabName(url
)));
502 viewTab
.splitter
= new QSplitter(this);
503 viewTab
.splitter
->setChildrenCollapsible(false);
504 viewTab
.primaryView
= createViewContainer(url
, viewTab
.splitter
);
505 viewTab
.primaryView
->setActive(false);
506 connectViewSignals(viewTab
.primaryView
);
508 m_viewTab
.append(viewTab
);
510 actionCollection()->action("close_tab")->setEnabled(true);
512 // provide a split view, if the startup settings are set this way
513 const GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
514 if (generalSettings
->splitView()) {
515 const int tabIndex
= m_viewTab
.count() - 1;
516 createSecondaryView(tabIndex
);
517 m_viewTab
[tabIndex
].secondaryView
->setActive(true);
518 m_viewTab
[tabIndex
].isPrimaryViewActive
= false;
522 // The DolphinViewContainer grabbed the keyboard focus. As the tab is opened
523 // in background, assure that the previous focused widget gets the focus back.
524 focusWidget
->setFocus();
528 void DolphinMainWindow::activateNextTab()
530 if ((m_viewTab
.count() == 1) || (m_tabBar
->count() < 2)) {
534 const int tabIndex
= (m_tabBar
->currentIndex() + 1) % m_tabBar
->count();
535 m_tabBar
->setCurrentIndex(tabIndex
);
538 void DolphinMainWindow::activatePrevTab()
540 if ((m_viewTab
.count() == 1) || (m_tabBar
->count() < 2)) {
544 int tabIndex
= m_tabBar
->currentIndex() - 1;
545 if (tabIndex
== -1) {
546 tabIndex
= m_tabBar
->count() - 1;
548 m_tabBar
->setCurrentIndex(tabIndex
);
551 void DolphinMainWindow::openInNewTab()
553 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
554 if (list
.isEmpty()) {
555 openNewTab(m_activeViewContainer
->url());
556 } else if ((list
.count() == 1) && list
[0].isDir()) {
557 openNewTab(list
[0].url());
561 void DolphinMainWindow::openInNewWindow()
565 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
566 if (list
.isEmpty()) {
567 newWindowUrl
= m_activeViewContainer
->url();
568 } else if ((list
.count() == 1) && list
[0].isDir()) {
569 newWindowUrl
= list
[0].url();
572 if (!newWindowUrl
.isEmpty()) {
573 KRun::run("dolphin", KUrl::List() << newWindowUrl
, this);
577 void DolphinMainWindow::toggleActiveView()
579 if (!m_viewTab
[m_tabIndex
].secondaryView
) {
580 // only one view is available
584 Q_ASSERT(m_activeViewContainer
);
585 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
587 DolphinViewContainer
* left
= m_viewTab
[m_tabIndex
].primaryView
;
588 DolphinViewContainer
* right
= m_viewTab
[m_tabIndex
].secondaryView
;
589 setActiveViewContainer(m_activeViewContainer
== right
? left
: right
);
592 void DolphinMainWindow::showEvent(QShowEvent
* event
)
594 KXmlGuiWindow::showEvent(event
);
595 if (!event
->spontaneous()) {
596 m_activeViewContainer
->view()->setFocus();
600 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
602 DolphinSettings
& settings
= DolphinSettings::instance();
603 GeneralSettings
* generalSettings
= settings
.generalSettings();
605 // Find out if Dolphin is closed directly by the user or
606 // by the session manager because the session is closed
607 bool closedByUser
= true;
608 DolphinApplication
*application
= qobject_cast
<DolphinApplication
*>(qApp
);
609 if (application
&& application
->sessionSaving()) {
610 closedByUser
= false;
613 if ((m_viewTab
.count() > 1) && generalSettings
->confirmClosingMultipleTabs() && closedByUser
) {
614 // Ask the user if he really wants to quit and close all tabs.
615 // Open a confirmation dialog with 3 buttons:
616 // KDialog::Yes -> Quit
617 // KDialog::No -> Close only the current tab
618 // KDialog::Cancel -> do nothing
619 KDialog
*dialog
= new KDialog(this, Qt::Dialog
);
620 dialog
->setCaption(i18nc("@title:window", "Confirmation"));
621 dialog
->setButtons(KDialog::Yes
| KDialog::No
| KDialog::Cancel
);
622 dialog
->setModal(true);
623 dialog
->setButtonGuiItem(KDialog::Yes
, KStandardGuiItem::quit());
624 dialog
->setButtonGuiItem(KDialog::No
, KGuiItem(i18n("C&lose Current Tab"), KIcon("tab-close")));
625 dialog
->setButtonGuiItem(KDialog::Cancel
, KStandardGuiItem::cancel());
626 dialog
->setDefaultButton(KDialog::Yes
);
628 bool doNotAskAgainCheckboxResult
= false;
630 const int result
= KMessageBox::createKMessageBox(dialog
,
631 QMessageBox::Warning
,
632 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
634 i18n("Do not ask again"),
635 &doNotAskAgainCheckboxResult
,
636 KMessageBox::Notify
);
638 if (doNotAskAgainCheckboxResult
) {
639 generalSettings
->setConfirmClosingMultipleTabs(false);
647 // Close only the current tab
655 generalSettings
->setVersion(CurrentDolphinVersion
);
658 if (m_searchDockIsTemporaryVisible
) {
659 QDockWidget
* searchDock
= findChild
<QDockWidget
*>("searchDock");
663 m_searchDockIsTemporaryVisible
= false;
666 KXmlGuiWindow::closeEvent(event
);
669 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
671 const int tabCount
= m_viewTab
.count();
672 group
.writeEntry("Tab Count", tabCount
);
673 group
.writeEntry("Active Tab Index", m_tabBar
->currentIndex());
675 for (int i
= 0; i
< tabCount
; ++i
) {
676 const DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
677 group
.writeEntry(tabProperty("Primary URL", i
), cont
->url().url());
678 group
.writeEntry(tabProperty("Primary Editable", i
),
679 cont
->urlNavigator()->isUrlEditable());
681 cont
= m_viewTab
[i
].secondaryView
;
683 group
.writeEntry(tabProperty("Secondary URL", i
), cont
->url().url());
684 group
.writeEntry(tabProperty("Secondary Editable", i
),
685 cont
->urlNavigator()->isUrlEditable());
690 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
692 const int tabCount
= group
.readEntry("Tab Count", 1);
693 for (int i
= 0; i
< tabCount
; ++i
) {
694 DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
696 cont
->setUrl(group
.readEntry(tabProperty("Primary URL", i
)));
697 const bool editable
= group
.readEntry(tabProperty("Primary Editable", i
), false);
698 cont
->urlNavigator()->setUrlEditable(editable
);
700 cont
= m_viewTab
[i
].secondaryView
;
701 const QString secondaryUrl
= group
.readEntry(tabProperty("Secondary URL", i
));
702 if (!secondaryUrl
.isEmpty()) {
704 // a secondary view should be shown, but no one is available
705 // currently -> create a new view
707 cont
= m_viewTab
[i
].secondaryView
;
711 cont
->setUrl(secondaryUrl
);
712 const bool editable
= group
.readEntry(tabProperty("Secondary Editable", i
), false);
713 cont
->urlNavigator()->setUrlEditable(editable
);
715 // no secondary view should be shown, but the default setting shows
716 // one already -> close the view
720 // openNewTab() needs to be called only tabCount - 1 times
721 if (i
!= tabCount
- 1) {
726 const int index
= group
.readEntry("Active Tab Index", 0);
727 m_tabBar
->setCurrentIndex(index
);
730 void DolphinMainWindow::updateNewMenu()
732 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
733 m_newFileMenu
->checkUpToDate();
734 m_newFileMenu
->setPopupFiles(activeViewContainer()->url());
737 void DolphinMainWindow::createDirectory()
739 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
740 m_newFileMenu
->setPopupFiles(activeViewContainer()->url());
741 m_newFileMenu
->createDirectory();
744 void DolphinMainWindow::quit()
749 void DolphinMainWindow::showErrorMessage(const QString
& message
)
751 if (!message
.isEmpty()) {
752 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
753 statusBar
->setMessage(message
, DolphinStatusBar::Error
);
757 void DolphinMainWindow::slotUndoAvailable(bool available
)
759 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
761 undoAction
->setEnabled(available
);
765 void DolphinMainWindow::restoreClosedTab(QAction
* action
)
767 if (action
->data().toBool()) {
768 // clear all actions except the "Empty Recently Closed Tabs"
769 // action and the separator
770 QList
<QAction
*> actions
= m_recentTabsMenu
->menu()->actions();
771 const int count
= actions
.size();
772 for (int i
= 2; i
< count
; ++i
) {
773 m_recentTabsMenu
->menu()->removeAction(actions
.at(i
));
776 const ClosedTab closedTab
= action
->data().value
<ClosedTab
>();
777 openNewTab(closedTab
.primaryUrl
);
778 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
780 if (closedTab
.isSplit
) {
781 // create secondary view
783 m_viewTab
[m_tabIndex
].secondaryView
->setUrl(closedTab
.secondaryUrl
);
786 m_recentTabsMenu
->removeAction(action
);
789 if (m_recentTabsMenu
->menu()->actions().count() == 2) {
790 m_recentTabsMenu
->setEnabled(false);
794 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
796 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
798 undoAction
->setText(text
);
802 void DolphinMainWindow::undo()
805 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
806 KIO::FileUndoManager::self()->undo();
809 void DolphinMainWindow::cut()
811 m_activeViewContainer
->view()->cutSelectedItems();
814 void DolphinMainWindow::copy()
816 m_activeViewContainer
->view()->copySelectedItems();
819 void DolphinMainWindow::paste()
821 m_activeViewContainer
->view()->paste();
824 void DolphinMainWindow::find()
826 m_activeViewContainer
->setSearchModeEnabled(true);
829 void DolphinMainWindow::slotSearchLocationChanged()
832 QDockWidget
* searchDock
= findChild
<QDockWidget
*>("searchDock");
837 SearchPanel
* searchPanel
= qobject_cast
<SearchPanel
*>(searchDock
->widget());
839 searchPanel
->setSearchLocation(SearchSettings::location() == QLatin1String("FromHere")
840 ? SearchPanel::FromCurrentDir
841 : SearchPanel::Everywhere
);
846 void DolphinMainWindow::updatePasteAction()
848 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
849 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
850 pasteAction
->setEnabled(pasteInfo
.first
);
851 pasteAction
->setText(pasteInfo
.second
);
854 void DolphinMainWindow::selectAll()
858 // if the URL navigator is editable and focused, select the whole
859 // URL instead of all items of the view
861 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
862 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit(); // krazy:exclude=qclasses
863 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
864 lineEdit
->hasFocus();
866 lineEdit
->selectAll();
868 m_activeViewContainer
->view()->selectAll();
872 void DolphinMainWindow::invertSelection()
875 m_activeViewContainer
->view()->invertSelection();
878 void DolphinMainWindow::toggleSplitView()
880 if (!m_viewTab
[m_tabIndex
].secondaryView
) {
881 createSecondaryView(m_tabIndex
);
882 setActiveViewContainer(m_viewTab
[m_tabIndex
].secondaryView
);
883 } else if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
884 // remove secondary view
885 m_viewTab
[m_tabIndex
].secondaryView
->close();
886 m_viewTab
[m_tabIndex
].secondaryView
->deleteLater();
887 m_viewTab
[m_tabIndex
].secondaryView
= 0;
889 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
891 // The primary view is active and should be closed. Hence from a users point of view
892 // the content of the secondary view should be moved to the primary view.
893 // From an implementation point of view it is more efficient to close
894 // the primary view and exchange the internal pointers afterwards.
896 m_viewTab
[m_tabIndex
].primaryView
->close();
897 m_viewTab
[m_tabIndex
].primaryView
->deleteLater();
898 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
899 m_viewTab
[m_tabIndex
].secondaryView
= 0;
901 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
907 void DolphinMainWindow::reloadView()
910 m_activeViewContainer
->view()->reload();
913 void DolphinMainWindow::stopLoading()
915 m_activeViewContainer
->view()->stopLoading();
918 void DolphinMainWindow::enableStopAction()
920 actionCollection()->action("stop")->setEnabled(true);
923 void DolphinMainWindow::disableStopAction()
925 actionCollection()->action("stop")->setEnabled(false);
928 void DolphinMainWindow::showFilterBar()
930 m_activeViewContainer
->setFilterBarVisible(true);
933 void DolphinMainWindow::toggleEditLocation()
937 QAction
* action
= actionCollection()->action("editable_location");
938 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
939 urlNavigator
->setUrlEditable(action
->isChecked());
942 void DolphinMainWindow::replaceLocation()
944 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
945 navigator
->setUrlEditable(true);
946 navigator
->setFocus();
948 // select the whole text of the combo box editor
949 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit(); // krazy:exclude=qclasses
950 lineEdit
->selectAll();
953 void DolphinMainWindow::togglePanelLockState()
955 GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
957 const bool newLockState
= !generalSettings
->lockPanels();
958 foreach (QObject
* child
, children()) {
959 DolphinDockWidget
* dock
= qobject_cast
<DolphinDockWidget
*>(child
);
961 dock
->setLocked(newLockState
);
965 generalSettings
->setLockPanels(newLockState
);
968 void DolphinMainWindow::slotPlacesPanelVisibilityChanged(bool visible
)
970 const int tabCount
= m_viewTab
.count();
971 for (int i
= 0; i
< tabCount
; ++i
) {
972 ViewTab
& tab
= m_viewTab
[i
];
973 Q_ASSERT(tab
.primaryView
);
974 tab
.primaryView
->urlNavigator()->setPlacesSelectorVisible(!visible
);
975 if (tab
.secondaryView
) {
976 tab
.secondaryView
->urlNavigator()->setPlacesSelectorVisible(!visible
);
981 void DolphinMainWindow::goBack()
983 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
984 urlNavigator
->goBack();
986 if (urlNavigator
->locationState().isEmpty()) {
987 // An empty location state indicates a redirection URL,
988 // which must be skipped too
989 urlNavigator
->goBack();
993 void DolphinMainWindow::goForward()
995 m_activeViewContainer
->urlNavigator()->goForward();
998 void DolphinMainWindow::goUp()
1000 m_activeViewContainer
->urlNavigator()->goUp();
1003 void DolphinMainWindow::goHome()
1005 m_activeViewContainer
->urlNavigator()->goHome();
1008 void DolphinMainWindow::goBack(Qt::MouseButtons buttons
)
1010 // The default case (left button pressed) is handled in goBack().
1011 if (buttons
== Qt::MidButton
) {
1012 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
1013 const int index
= urlNavigator
->historyIndex() + 1;
1014 openNewTab(urlNavigator
->locationUrl(index
));
1018 void DolphinMainWindow::goForward(Qt::MouseButtons buttons
)
1020 // The default case (left button pressed) is handled in goForward().
1021 if (buttons
== Qt::MidButton
) {
1022 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
1023 const int index
= urlNavigator
->historyIndex() - 1;
1024 openNewTab(urlNavigator
->locationUrl(index
));
1028 void DolphinMainWindow::goUp(Qt::MouseButtons buttons
)
1030 // The default case (left button pressed) is handled in goUp().
1031 if (buttons
== Qt::MidButton
) {
1032 openNewTab(activeViewContainer()->url().upUrl());
1036 void DolphinMainWindow::compareFiles()
1038 // The method is only invoked if exactly 2 files have
1039 // been selected. The selected files may be:
1040 // - both in the primary view
1041 // - both in the secondary view
1042 // - one in the primary view and the other in the secondary
1044 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
1049 KFileItemList items
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedItems();
1051 switch (items
.count()) {
1053 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
);
1054 items
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItems();
1055 Q_ASSERT(items
.count() == 2);
1056 urlA
= items
[0].url();
1057 urlB
= items
[1].url();
1062 urlA
= items
[0].url();
1063 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
);
1064 items
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItems();
1065 Q_ASSERT(items
.count() == 1);
1066 urlB
= items
[0].url();
1071 urlA
= items
[0].url();
1072 urlB
= items
[1].url();
1077 // may not happen: compareFiles may only get invoked if 2
1078 // files are selected
1083 QString
command("kompare -c \"");
1084 command
.append(urlA
.pathOrUrl());
1085 command
.append("\" \"");
1086 command
.append(urlB
.pathOrUrl());
1087 command
.append('\"');
1088 KRun::runCommand(command
, "Kompare", "kompare", this);
1091 void DolphinMainWindow::toggleShowMenuBar()
1093 const bool visible
= menuBar()->isVisible();
1094 menuBar()->setVisible(!visible
);
1096 createToolBarMenuButton();
1098 deleteToolBarMenuButton();
1102 void DolphinMainWindow::openTerminal()
1104 QString
dir(QDir::homePath());
1106 // If the given directory is not local, it can still be the URL of an
1107 // ioslave using UDS_LOCAL_PATH which to be converted first.
1108 KUrl url
= KIO::NetAccess::mostLocalUrl(m_activeViewContainer
->url(), this);
1110 //If the URL is local after the above conversion, set the directory.
1111 if (url
.isLocalFile()) {
1112 dir
= url
.toLocalFile();
1115 KToolInvocation::invokeTerminal(QString(), dir
);
1118 void DolphinMainWindow::editSettings()
1120 if (!m_settingsDialog
) {
1121 const KUrl url
= activeViewContainer()->url();
1122 DolphinSettingsDialog
* settingsDialog
= new DolphinSettingsDialog(url
, this);
1123 connect(settingsDialog
, SIGNAL(settingsChanged()), this, SLOT(refreshViews()));
1124 settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1125 settingsDialog
->show();
1126 m_settingsDialog
= settingsDialog
;
1128 m_settingsDialog
.data()->raise();
1132 void DolphinMainWindow::setActiveTab(int index
)
1134 Q_ASSERT(index
>= 0);
1135 Q_ASSERT(index
< m_viewTab
.count());
1136 if (index
== m_tabIndex
) {
1140 // hide current tab content
1141 ViewTab
& hiddenTab
= m_viewTab
[m_tabIndex
];
1142 hiddenTab
.isPrimaryViewActive
= hiddenTab
.primaryView
->isActive();
1143 hiddenTab
.primaryView
->setActive(false);
1144 if (hiddenTab
.secondaryView
) {
1145 hiddenTab
.secondaryView
->setActive(false);
1147 QSplitter
* splitter
= m_viewTab
[m_tabIndex
].splitter
;
1149 m_centralWidgetLayout
->removeWidget(splitter
);
1151 // show active tab content
1154 ViewTab
& viewTab
= m_viewTab
[index
];
1155 m_centralWidgetLayout
->addWidget(viewTab
.splitter
, 1);
1156 viewTab
.primaryView
->show();
1157 if (viewTab
.secondaryView
) {
1158 viewTab
.secondaryView
->show();
1160 viewTab
.splitter
->show();
1162 setActiveViewContainer(viewTab
.isPrimaryViewActive
? viewTab
.primaryView
:
1163 viewTab
.secondaryView
);
1166 void DolphinMainWindow::closeTab()
1168 closeTab(m_tabBar
->currentIndex());
1171 void DolphinMainWindow::closeTab(int index
)
1173 Q_ASSERT(index
>= 0);
1174 Q_ASSERT(index
< m_viewTab
.count());
1175 if (m_viewTab
.count() == 1) {
1176 // the last tab may never get closed
1180 if (index
== m_tabIndex
) {
1181 // The tab that should be closed is the active tab. Activate the
1182 // previous tab before closing the tab.
1183 m_tabBar
->setCurrentIndex((index
> 0) ? index
- 1 : 1);
1185 rememberClosedTab(index
);
1188 m_viewTab
[index
].primaryView
->deleteLater();
1189 if (m_viewTab
[index
].secondaryView
) {
1190 m_viewTab
[index
].secondaryView
->deleteLater();
1192 m_viewTab
[index
].splitter
->deleteLater();
1193 m_viewTab
.erase(m_viewTab
.begin() + index
);
1195 m_tabBar
->blockSignals(true);
1196 m_tabBar
->removeTab(index
);
1198 if (m_tabIndex
> index
) {
1200 Q_ASSERT(m_tabIndex
>= 0);
1203 // if only one tab is left, also remove the tab entry so that
1204 // closing the last tab is not possible
1205 if (m_viewTab
.count() == 1) {
1206 m_tabBar
->removeTab(0);
1207 actionCollection()->action("close_tab")->setEnabled(false);
1209 m_tabBar
->blockSignals(false);
1213 void DolphinMainWindow::openTabContextMenu(int index
, const QPoint
& pos
)
1217 QAction
* newTabAction
= menu
.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab"));
1218 newTabAction
->setShortcut(actionCollection()->action("new_tab")->shortcut());
1220 QAction
* detachTabAction
= menu
.addAction(KIcon("tab-detach"), i18nc("@action:inmenu", "Detach Tab"));
1222 QAction
* closeOtherTabsAction
= menu
.addAction(KIcon("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs"));
1224 QAction
* closeTabAction
= menu
.addAction(KIcon("tab-close"), i18nc("@action:inmenu", "Close Tab"));
1225 closeTabAction
->setShortcut(actionCollection()->action("close_tab")->shortcut());
1226 QAction
* selectedAction
= menu
.exec(pos
);
1227 if (selectedAction
== newTabAction
) {
1228 const ViewTab
& tab
= m_viewTab
[index
];
1229 Q_ASSERT(tab
.primaryView
);
1230 const KUrl url
= tab
.secondaryView
&& tab
.secondaryView
->isActive() ?
1231 tab
.secondaryView
->url() : tab
.primaryView
->url();
1233 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
1234 } else if (selectedAction
== detachTabAction
) {
1235 const QString
separator(QLatin1Char(' '));
1236 QString command
= QLatin1String("dolphin");
1238 const ViewTab
& tab
= m_viewTab
[index
];
1239 Q_ASSERT(tab
.primaryView
);
1241 command
+= separator
+ tab
.primaryView
->url().url();
1242 if (tab
.secondaryView
) {
1243 command
+= separator
+ tab
.secondaryView
->url().url();
1244 command
+= separator
+ QLatin1String("-split");
1247 KRun::runCommand(command
, this);
1250 } else if (selectedAction
== closeOtherTabsAction
) {
1251 const int count
= m_tabBar
->count();
1252 for (int i
= 0; i
< index
; ++i
) {
1255 for (int i
= index
+ 1; i
< count
; ++i
) {
1258 } else if (selectedAction
== closeTabAction
) {
1263 void DolphinMainWindow::slotTabMoved(int from
, int to
)
1265 m_viewTab
.move(from
, to
);
1266 m_tabIndex
= m_tabBar
->currentIndex();
1269 void DolphinMainWindow::handlePlacesClick(const KUrl
& url
, Qt::MouseButtons buttons
)
1271 if (buttons
& Qt::MidButton
) {
1273 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
1279 void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent
* event
, bool& canDecode
)
1281 canDecode
= KUrl::List::canDecode(event
->mimeData());
1284 void DolphinMainWindow::handleUrl(const KUrl
& url
)
1286 delete m_lastHandleUrlStatJob
;
1287 m_lastHandleUrlStatJob
= 0;
1289 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1290 activeViewContainer()->setUrl(url
);
1291 } else if (KProtocolManager::supportsListing(url
)) {
1292 // stat the URL to see if it is a dir or not
1293 m_lastHandleUrlStatJob
= KIO::stat(url
, KIO::HideProgressInfo
);
1294 connect(m_lastHandleUrlStatJob
, SIGNAL(result(KJob
*)),
1295 this, SLOT(slotHandleUrlStatFinished(KJob
*)));
1298 new KRun(url
, this);
1302 void DolphinMainWindow::slotHandleUrlStatFinished(KJob
* job
)
1304 m_lastHandleUrlStatJob
= 0;
1305 const KIO::UDSEntry entry
= static_cast<KIO::StatJob
*>(job
)->statResult();
1306 const KUrl url
= static_cast<KIO::StatJob
*>(job
)->url();
1307 if (entry
.isDir()) {
1308 activeViewContainer()->setUrl(url
);
1310 new KRun(url
, this);
1314 void DolphinMainWindow::tabDropEvent(int tab
, QDropEvent
* event
)
1316 const KUrl::List urls
= KUrl::List::fromMimeData(event
->mimeData());
1317 if (!urls
.isEmpty() && tab
!= -1) {
1318 const ViewTab
& viewTab
= m_viewTab
[tab
];
1319 const KUrl destPath
= viewTab
.isPrimaryViewActive
? viewTab
.primaryView
->url() : viewTab
.secondaryView
->url();
1321 //DragAndDropHelper::instance().dropUrls(KFileItem(), destPath, event, m_tabBar);
1325 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1327 newFileMenu()->setEnabled(isFolderWritable
);
1330 void DolphinMainWindow::slotSearchModeChanged(bool enabled
)
1333 const DolphinSearchInformation
& searchInfo
= DolphinSearchInformation::instance();
1334 if (!searchInfo
.isIndexingEnabled()) {
1338 QDockWidget
* searchDock
= findChild
<QDockWidget
*>("searchDock");
1344 if (!searchDock
->isVisible()) {
1345 m_searchDockIsTemporaryVisible
= true;
1349 if (searchDock
->isVisible() && m_searchDockIsTemporaryVisible
) {
1352 m_searchDockIsTemporaryVisible
= false;
1355 SearchPanel
* searchPanel
= qobject_cast
<SearchPanel
*>(searchDock
->widget());
1361 SearchPanel::SearchLocation searchLocation
= SearchPanel::Everywhere
;
1362 const KUrl url
= m_activeViewContainer
->url();
1363 const bool isSearchUrl
= (url
.protocol() == QLatin1String("nepomuksearch"));
1364 if ((SearchSettings::location() == QLatin1String("FromHere") && !isSearchUrl
)) {
1365 searchLocation
= SearchPanel::FromCurrentDir
;
1367 searchPanel
->setSearchLocation(searchLocation
);
1369 searchPanel
->setSearchLocation(SearchPanel::Everywhere
);
1376 void DolphinMainWindow::openContextMenu(const KFileItem
& item
,
1378 const QList
<QAction
*>& customActions
)
1380 QPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, item
, url
);
1381 contextMenu
->setCustomActions(customActions
);
1382 const DolphinContextMenu::Command command
= contextMenu
->open();
1385 case DolphinContextMenu::OpenParentFolderInNewWindow
: {
1386 KRun::run("dolphin", KUrl::List() << item
.url().upUrl(), this);
1390 case DolphinContextMenu::OpenParentFolderInNewTab
:
1391 openNewTab(item
.url().upUrl());
1394 case DolphinContextMenu::None
:
1402 void DolphinMainWindow::updateToolBarMenu()
1404 KMenu
* menu
= qobject_cast
<KMenu
*>(sender());
1407 // All actions get cleared by KMenu::clear(). The sub-menus are deleted
1408 // by connecting to the aboutToHide() signal from the parent-menu.
1411 const GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
1413 KActionCollection
* ac
= actionCollection();
1415 // Add "Edit" actions
1416 bool added
= addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Undo
)), menu
) |
1417 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Find
)), menu
) |
1418 addActionToMenu(ac
->action("select_all"), menu
) |
1419 addActionToMenu(ac
->action("invert_selection"), menu
);
1422 menu
->addSeparator();
1425 // Add "View" actions
1426 if (!generalSettings
->showZoomSlider()) {
1427 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomIn
)), menu
);
1428 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomOut
)), menu
);
1429 menu
->addSeparator();
1432 added
= addActionToMenu(ac
->action("view_mode"), menu
) |
1433 addActionToMenu(ac
->action("sort"), menu
) |
1434 addActionToMenu(ac
->action("additional_info"), menu
) |
1435 addActionToMenu(ac
->action("show_preview"), menu
) |
1436 addActionToMenu(ac
->action("show_in_groups"), menu
) |
1437 addActionToMenu(ac
->action("show_hidden_files"), menu
);
1440 menu
->addSeparator();
1443 added
= addActionToMenu(ac
->action("split_view"), menu
) |
1444 addActionToMenu(ac
->action("reload"), menu
) |
1445 addActionToMenu(ac
->action("view_properties"), menu
);
1447 menu
->addSeparator();
1450 addActionToMenu(ac
->action("panels"), menu
);
1451 KMenu
* locationBarMenu
= new KMenu(i18nc("@action:inmenu", "Location Bar"), menu
);
1452 locationBarMenu
->addAction(ac
->action("editable_location"));
1453 locationBarMenu
->addAction(ac
->action("replace_location"));
1454 menu
->addMenu(locationBarMenu
);
1456 menu
->addSeparator();
1459 KMenu
* goMenu
= new KMenu(i18nc("@action:inmenu", "Go"), menu
);
1460 connect(menu
, SIGNAL(aboutToHide()), goMenu
, SLOT(deleteLater()));
1461 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Back
)));
1462 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Forward
)));
1463 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Up
)));
1464 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Home
)));
1465 goMenu
->addAction(ac
->action("closed_tabs"));
1466 menu
->addMenu(goMenu
);
1469 KMenu
* toolsMenu
= new KMenu(i18nc("@action:inmenu", "Tools"), menu
);
1470 connect(menu
, SIGNAL(aboutToHide()), toolsMenu
, SLOT(deleteLater()));
1471 toolsMenu
->addAction(ac
->action("show_filter_bar"));
1472 toolsMenu
->addAction(ac
->action("compare_files"));
1473 toolsMenu
->addAction(ac
->action("open_terminal"));
1474 toolsMenu
->addAction(ac
->action("change_remote_encoding"));
1475 menu
->addMenu(toolsMenu
);
1477 // Add "Settings" menu entries
1478 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::KeyBindings
)), menu
);
1479 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ConfigureToolbars
)), menu
);
1480 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Preferences
)), menu
);
1483 KMenu
* helpMenu
= new KMenu(i18nc("@action:inmenu", "Help"), menu
);
1484 connect(menu
, SIGNAL(aboutToHide()), helpMenu
, SLOT(deleteLater()));
1485 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::HelpContents
)));
1486 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::WhatsThis
)));
1487 helpMenu
->addSeparator();
1488 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ReportBug
)));
1489 helpMenu
->addSeparator();
1490 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
)));
1491 helpMenu
->addSeparator();
1492 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::AboutApp
)));
1493 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::AboutKDE
)));
1494 menu
->addMenu(helpMenu
);
1496 menu
->addSeparator();
1497 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ShowMenubar
)), menu
);
1500 void DolphinMainWindow::updateToolBar()
1502 if (!menuBar()->isVisible()) {
1503 createToolBarMenuButton();
1507 void DolphinMainWindow::slotToolBarSpacerDeleted()
1509 m_toolBarSpacer
= 0;
1510 m_updateToolBarTimer
->start();
1513 void DolphinMainWindow::slotToolBarMenuButtonDeleted()
1515 m_openToolBarMenuButton
= 0;
1516 m_updateToolBarTimer
->start();
1519 void DolphinMainWindow::slotToolBarIconSizeChanged(const QSize
& iconSize
)
1521 if (m_openToolBarMenuButton
) {
1522 m_openToolBarMenuButton
->setIconSize(iconSize
);
1526 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer
* viewContainer
)
1528 Q_ASSERT(viewContainer
);
1529 Q_ASSERT((viewContainer
== m_viewTab
[m_tabIndex
].primaryView
) ||
1530 (viewContainer
== m_viewTab
[m_tabIndex
].secondaryView
));
1531 if (m_activeViewContainer
== viewContainer
) {
1535 m_activeViewContainer
->setActive(false);
1536 m_activeViewContainer
= viewContainer
;
1538 // Activating the view container might trigger a recursive setActiveViewContainer() call
1539 // inside DolphinMainWindow::toggleActiveView() when having a split view. Temporary
1540 // disconnect the activated() signal in this case:
1541 disconnect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1542 m_activeViewContainer
->setActive(true);
1543 connect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1545 m_actionHandler
->setCurrentView(viewContainer
->view());
1548 updateEditActions();
1549 updateViewActions();
1552 const KUrl url
= m_activeViewContainer
->url();
1553 setUrlAsCaption(url
);
1554 if (m_viewTab
.count() > 1) {
1555 m_tabBar
->setTabText(m_tabIndex
, tabName(url
));
1556 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(KMimeType::iconNameForUrl(url
)));
1559 emit
urlChanged(url
);
1562 DolphinViewContainer
* DolphinMainWindow::createViewContainer(const KUrl
& url
, QWidget
* parent
)
1564 DolphinViewContainer
* container
= new DolphinViewContainer(url
, parent
);
1566 // The places-selector from the URL navigator should only be shown
1567 // if the places dock is invisible
1568 QDockWidget
* placesDock
= findChild
<QDockWidget
*>("placesDock");
1569 container
->urlNavigator()->setPlacesSelectorVisible(!placesDock
|| !placesDock
->isVisible());
1574 void DolphinMainWindow::setupActions()
1576 // setup 'File' menu
1577 m_newFileMenu
= new DolphinNewFileMenu(this);
1578 KMenu
* menu
= m_newFileMenu
->menu();
1579 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1580 menu
->setIcon(KIcon("document-new"));
1581 connect(menu
, SIGNAL(aboutToShow()),
1582 this, SLOT(updateNewMenu()));
1584 KAction
* newWindow
= actionCollection()->addAction("new_window");
1585 newWindow
->setIcon(KIcon("window-new"));
1586 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1587 newWindow
->setShortcut(Qt::CTRL
| Qt::Key_N
);
1588 connect(newWindow
, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1590 KAction
* newTab
= actionCollection()->addAction("new_tab");
1591 newTab
->setIcon(KIcon("tab-new"));
1592 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1593 newTab
->setShortcut(KShortcut(Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
));
1594 connect(newTab
, SIGNAL(triggered()), this, SLOT(openNewTab()));
1596 KAction
* closeTab
= actionCollection()->addAction("close_tab");
1597 closeTab
->setIcon(KIcon("tab-close"));
1598 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1599 closeTab
->setShortcut(Qt::CTRL
| Qt::Key_W
);
1600 closeTab
->setEnabled(false);
1601 connect(closeTab
, SIGNAL(triggered()), this, SLOT(closeTab()));
1603 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1605 // setup 'Edit' menu
1606 KStandardAction::undo(this,
1608 actionCollection());
1610 // need to remove shift+del from cut action, else the shortcut for deletejob
1612 KAction
* cut
= KStandardAction::cut(this, SLOT(cut()), actionCollection());
1613 KShortcut cutShortcut
= cut
->shortcut();
1614 cutShortcut
.remove(Qt::SHIFT
| Qt::Key_Delete
, KShortcut::KeepEmpty
);
1615 cut
->setShortcut(cutShortcut
);
1616 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1617 KAction
* paste
= KStandardAction::paste(this, SLOT(paste()), actionCollection());
1618 // The text of the paste-action is modified dynamically by Dolphin
1619 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1620 // due to the long text, the text "Paste" is used:
1621 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1623 KStandardAction::find(this, SLOT(find()), actionCollection());
1625 KAction
* selectAll
= actionCollection()->addAction("select_all");
1626 selectAll
->setText(i18nc("@action:inmenu Edit", "Select All"));
1627 selectAll
->setShortcut(Qt::CTRL
| Qt::Key_A
);
1628 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
1630 KAction
* invertSelection
= actionCollection()->addAction("invert_selection");
1631 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1632 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1633 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
1635 // setup 'View' menu
1636 // (note that most of it is set up in DolphinViewActionHandler)
1638 KAction
* split
= actionCollection()->addAction("split_view");
1639 split
->setShortcut(Qt::Key_F3
);
1640 updateSplitAction();
1641 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1643 KAction
* reload
= actionCollection()->addAction("reload");
1644 reload
->setText(i18nc("@action:inmenu View", "Reload"));
1645 reload
->setShortcut(Qt::Key_F5
);
1646 reload
->setIcon(KIcon("view-refresh"));
1647 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
1649 KAction
* stop
= actionCollection()->addAction("stop");
1650 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1651 stop
->setToolTip(i18nc("@info", "Stop loading"));
1652 stop
->setIcon(KIcon("process-stop"));
1653 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
1655 KToggleAction
* editableLocation
= actionCollection()->add
<KToggleAction
>("editable_location");
1656 editableLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1657 editableLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
1658 connect(editableLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1660 KAction
* replaceLocation
= actionCollection()->addAction("replace_location");
1661 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1662 replaceLocation
->setShortcut(Qt::Key_F6
);
1663 connect(replaceLocation
, SIGNAL(triggered()), this, SLOT(replaceLocation()));
1666 KAction
* backAction
= KStandardAction::back(this, SLOT(goBack()), actionCollection());
1667 connect(backAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goBack(Qt::MouseButtons
)));
1668 KShortcut backShortcut
= backAction
->shortcut();
1669 backShortcut
.setAlternate(Qt::Key_Backspace
);
1670 backAction
->setShortcut(backShortcut
);
1672 m_recentTabsMenu
= new KActionMenu(i18n("Recently Closed Tabs"), this);
1673 m_recentTabsMenu
->setIcon(KIcon("edit-undo"));
1674 actionCollection()->addAction("closed_tabs", m_recentTabsMenu
);
1675 connect(m_recentTabsMenu
->menu(), SIGNAL(triggered(QAction
*)),
1676 this, SLOT(restoreClosedTab(QAction
*)));
1678 QAction
* action
= new QAction(i18n("Empty Recently Closed Tabs"), m_recentTabsMenu
);
1679 action
->setIcon(KIcon("edit-clear-list"));
1680 action
->setData(QVariant::fromValue(true));
1681 m_recentTabsMenu
->addAction(action
);
1682 m_recentTabsMenu
->addSeparator();
1683 m_recentTabsMenu
->setEnabled(false);
1685 KAction
* forwardAction
= KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1686 connect(forwardAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goForward(Qt::MouseButtons
)));
1688 KAction
* upAction
= KStandardAction::up(this, SLOT(goUp()), actionCollection());
1689 connect(upAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goUp(Qt::MouseButtons
)));
1691 KStandardAction::home(this, SLOT(goHome()), actionCollection());
1693 // setup 'Tools' menu
1694 KAction
* showFilterBar
= actionCollection()->addAction("show_filter_bar");
1695 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1696 showFilterBar
->setIcon(KIcon("view-filter"));
1697 showFilterBar
->setShortcut(Qt::CTRL
| Qt::Key_I
);
1698 connect(showFilterBar
, SIGNAL(triggered()), this, SLOT(showFilterBar()));
1700 KAction
* compareFiles
= actionCollection()->addAction("compare_files");
1701 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1702 compareFiles
->setIcon(KIcon("kompare"));
1703 compareFiles
->setEnabled(false);
1704 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
1706 KAction
* openTerminal
= actionCollection()->addAction("open_terminal");
1707 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1708 openTerminal
->setIcon(KIcon("utilities-terminal"));
1709 openTerminal
->setShortcut(Qt::SHIFT
| Qt::Key_F4
);
1710 connect(openTerminal
, SIGNAL(triggered()), this, SLOT(openTerminal()));
1712 // setup 'Settings' menu
1713 KStandardAction::showMenubar(this, SLOT(toggleShowMenuBar()), actionCollection());
1714 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1716 // not in menu actions
1717 QList
<QKeySequence
> nextTabKeys
;
1718 nextTabKeys
.append(KStandardShortcut::tabNext().primary());
1719 nextTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::Key_Tab
));
1721 QList
<QKeySequence
> prevTabKeys
;
1722 prevTabKeys
.append(KStandardShortcut::tabPrev().primary());
1723 prevTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::SHIFT
| Qt::Key_Tab
));
1725 KAction
* activateNextTab
= actionCollection()->addAction("activate_next_tab");
1726 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1727 connect(activateNextTab
, SIGNAL(triggered()), SLOT(activateNextTab()));
1728 activateNextTab
->setShortcuts(QApplication::isRightToLeft() ? prevTabKeys
: nextTabKeys
);
1730 KAction
* activatePrevTab
= actionCollection()->addAction("activate_prev_tab");
1731 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1732 connect(activatePrevTab
, SIGNAL(triggered()), SLOT(activatePrevTab()));
1733 activatePrevTab
->setShortcuts(QApplication::isRightToLeft() ? nextTabKeys
: prevTabKeys
);
1736 KAction
* openInNewTab
= actionCollection()->addAction("open_in_new_tab");
1737 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1738 openInNewTab
->setIcon(KIcon("tab-new"));
1739 connect(openInNewTab
, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1741 KAction
* openInNewWindow
= actionCollection()->addAction("open_in_new_window");
1742 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1743 openInNewWindow
->setIcon(KIcon("window-new"));
1744 connect(openInNewWindow
, SIGNAL(triggered()), this, SLOT(openInNewWindow()));
1747 void DolphinMainWindow::setupDockWidgets()
1749 const bool lock
= DolphinSettings::instance().generalSettings()->lockPanels();
1751 KDualAction
* lockLayoutAction
= actionCollection()->add
<KDualAction
>("lock_panels");
1752 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
1753 lockLayoutAction
->setActiveIcon(KIcon("object-unlocked"));
1754 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
1755 lockLayoutAction
->setInactiveIcon(KIcon("object-locked"));
1756 lockLayoutAction
->setActive(lock
);
1757 connect(lockLayoutAction
, SIGNAL(triggered()), this, SLOT(togglePanelLockState()));
1759 // Setup "Information"
1760 DolphinDockWidget
* infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
1761 infoDock
->setLocked(lock
);
1762 infoDock
->setObjectName("infoDock");
1763 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1764 Panel
* infoPanel
= new InformationPanel(infoDock
);
1765 infoPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1766 connect(infoPanel
, SIGNAL(urlActivated(KUrl
)), this, SLOT(handleUrl(KUrl
)));
1767 infoDock
->setWidget(infoPanel
);
1769 QAction
* infoAction
= infoDock
->toggleViewAction();
1770 infoAction
->setIcon(KIcon("dialog-information"));
1771 infoAction
->setShortcut(Qt::Key_F11
);
1772 addActionCloneToCollection(infoAction
, "show_information_panel");
1774 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1775 connect(this, SIGNAL(urlChanged(KUrl
)),
1776 infoPanel
, SLOT(setUrl(KUrl
)));
1777 connect(this, SIGNAL(selectionChanged(KFileItemList
)),
1778 infoPanel
, SLOT(setSelection(KFileItemList
)));
1779 connect(this, SIGNAL(requestItemInfo(KFileItem
)),
1780 infoPanel
, SLOT(requestDelayedItemInfo(KFileItem
)));
1783 DolphinDockWidget
* foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
1784 foldersDock
->setLocked(lock
);
1785 foldersDock
->setObjectName("foldersDock");
1786 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1787 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1788 foldersPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1789 foldersDock
->setWidget(foldersPanel
);
1791 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1792 foldersAction
->setShortcut(Qt::Key_F7
);
1793 foldersAction
->setIcon(KIcon("folder"));
1794 addActionCloneToCollection(foldersAction
, "show_folders_panel");
1796 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1797 connect(this, SIGNAL(urlChanged(KUrl
)),
1798 foldersPanel
, SLOT(setUrl(KUrl
)));
1799 connect(foldersPanel
, SIGNAL(changeUrl(KUrl
,Qt::MouseButtons
)),
1800 this, SLOT(handlePlacesClick(KUrl
,Qt::MouseButtons
)));
1804 DolphinDockWidget
* terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1805 terminalDock
->setLocked(lock
);
1806 terminalDock
->setObjectName("terminalDock");
1807 terminalDock
->setAllowedAreas(Qt::TopDockWidgetArea
| Qt::BottomDockWidgetArea
);
1808 Panel
* terminalPanel
= new TerminalPanel(terminalDock
);
1809 terminalPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1810 terminalDock
->setWidget(terminalPanel
);
1812 connect(terminalPanel
, SIGNAL(hideTerminalPanel()), terminalDock
, SLOT(hide()));
1813 connect(terminalDock
, SIGNAL(visibilityChanged(bool)),
1814 terminalPanel
, SLOT(dockVisibilityChanged()));
1816 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1817 terminalAction
->setShortcut(Qt::Key_F4
);
1818 terminalAction
->setIcon(KIcon("utilities-terminal"));
1819 addActionCloneToCollection(terminalAction
, "show_terminal_panel");
1821 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1822 connect(this, SIGNAL(urlChanged(KUrl
)),
1823 terminalPanel
, SLOT(setUrl(KUrl
)));
1828 DolphinDockWidget
* searchDock
= new DolphinDockWidget(i18nc("@title:window", "Search"));
1829 searchDock
->setLocked(lock
);
1830 searchDock
->setObjectName("searchDock");
1831 searchDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1832 Panel
* searchPanel
= new SearchPanel(searchDock
);
1833 searchPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1834 connect(searchPanel
, SIGNAL(urlActivated(KUrl
)), this, SLOT(handleUrl(KUrl
)));
1835 searchDock
->setWidget(searchPanel
);
1837 QAction
* searchAction
= searchDock
->toggleViewAction();
1838 searchAction
->setShortcut(Qt::Key_F12
);
1839 searchAction
->setIcon(KIcon("system-search"));
1840 addActionCloneToCollection(searchAction
, "show_search_panel");
1841 addDockWidget(Qt::RightDockWidgetArea
, searchDock
);
1842 connect(this, SIGNAL(urlChanged(KUrl
)),
1843 searchPanel
, SLOT(setUrl(KUrl
)));
1846 if (DolphinSettings::instance().generalSettings()->version() < 200) {
1848 foldersDock
->hide();
1850 terminalDock
->hide();
1858 DolphinDockWidget
* placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
1859 placesDock
->setLocked(lock
);
1860 placesDock
->setObjectName("placesDock");
1861 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1863 PlacesPanel
* placesPanel
= new PlacesPanel(placesDock
);
1864 QAction
* separator
= new QAction(placesPanel
);
1865 separator
->setSeparator(true);
1866 QList
<QAction
*> placesActions
;
1867 placesActions
.append(separator
);
1868 placesActions
.append(lockLayoutAction
);
1869 placesPanel
->addActions(placesActions
);
1870 placesPanel
->setModel(DolphinSettings::instance().placesModel());
1871 placesPanel
->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff
);
1872 placesDock
->setWidget(placesPanel
);
1874 QAction
* placesAction
= placesDock
->toggleViewAction();
1875 placesAction
->setShortcut(Qt::Key_F9
);
1876 placesAction
->setIcon(KIcon("bookmarks"));
1877 addActionCloneToCollection(placesAction
, "show_places_panel");
1879 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1880 connect(placesPanel
, SIGNAL(urlChanged(KUrl
,Qt::MouseButtons
)),
1881 this, SLOT(handlePlacesClick(KUrl
,Qt::MouseButtons
)));
1882 connect(this, SIGNAL(urlChanged(KUrl
)),
1883 placesPanel
, SLOT(setUrl(KUrl
)));
1884 connect(placesDock
, SIGNAL(visibilityChanged(bool)),
1885 this, SLOT(slotPlacesPanelVisibilityChanged(bool)));
1887 // Add actions into the "Panels" menu
1888 KActionMenu
* panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Panels"), this);
1889 actionCollection()->addAction("panels", panelsMenu
);
1890 panelsMenu
->setDelayed(false);
1891 panelsMenu
->addAction(placesAction
);
1892 panelsMenu
->addAction(infoAction
);
1893 panelsMenu
->addAction(foldersAction
);
1895 panelsMenu
->addAction(terminalAction
);
1898 panelsMenu
->addAction(searchAction
);
1900 panelsMenu
->addSeparator();
1901 panelsMenu
->addAction(lockLayoutAction
);
1904 void DolphinMainWindow::updateEditActions()
1906 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1907 if (list
.isEmpty()) {
1908 stateChanged("has_no_selection");
1910 stateChanged("has_selection");
1912 KActionCollection
* col
= actionCollection();
1913 QAction
* renameAction
= col
->action("rename");
1914 QAction
* moveToTrashAction
= col
->action("move_to_trash");
1915 QAction
* deleteAction
= col
->action("delete");
1916 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
1917 QAction
* deleteWithTrashShortcut
= col
->action("delete_shortcut"); // see DolphinViewActionHandler
1919 KFileItemListProperties
capabilities(list
);
1920 const bool enableMoveToTrash
= capabilities
.isLocal() && capabilities
.supportsMoving();
1922 renameAction
->setEnabled(capabilities
.supportsMoving());
1923 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1924 deleteAction
->setEnabled(capabilities
.supportsDeleting());
1925 deleteWithTrashShortcut
->setEnabled(capabilities
.supportsDeleting() && !enableMoveToTrash
);
1926 cutAction
->setEnabled(capabilities
.supportsMoving());
1928 updatePasteAction();
1931 void DolphinMainWindow::updateViewActions()
1933 m_actionHandler
->updateViewActions();
1935 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1936 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
1938 updateSplitAction();
1940 QAction
* editableLocactionAction
= actionCollection()->action("editable_location");
1941 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
1942 editableLocactionAction
->setChecked(urlNavigator
->isUrlEditable());
1945 void DolphinMainWindow::updateGoActions()
1947 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
1948 const KUrl currentUrl
= m_activeViewContainer
->url();
1949 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
1952 void DolphinMainWindow::createToolBarMenuButton()
1954 if (m_toolBarSpacer
&& m_openToolBarMenuButton
) {
1957 Q_ASSERT(!m_toolBarSpacer
);
1958 Q_ASSERT(!m_openToolBarMenuButton
);
1960 m_toolBarSpacer
= new QWidget(this);
1961 m_toolBarSpacer
->setSizePolicy(QSizePolicy::MinimumExpanding
, QSizePolicy::MinimumExpanding
);
1963 m_openToolBarMenuButton
= new QToolButton(this);
1964 m_openToolBarMenuButton
->setIcon(KIcon("configure"));
1965 m_openToolBarMenuButton
->setPopupMode(QToolButton::InstantPopup
);
1966 m_openToolBarMenuButton
->setToolTip(i18nc("@info:tooltip", "Configure and control Dolphin"));
1968 KMenu
* toolBarMenu
= new ToolBarMenu(m_openToolBarMenuButton
);
1969 connect(toolBarMenu
, SIGNAL(aboutToShow()), this, SLOT(updateToolBarMenu()));
1971 m_openToolBarMenuButton
->setMenu(toolBarMenu
);
1973 toolBar()->addWidget(m_toolBarSpacer
);
1974 toolBar()->addWidget(m_openToolBarMenuButton
);
1975 connect(toolBar(), SIGNAL(iconSizeChanged(QSize
)), this, SLOT(slotToolBarIconSizeChanged(QSize
)));
1977 // The added widgets are owned by the toolbar and may get deleted when e.g. the toolbar
1978 // gets edited. In this case we must add them again. The adding is done asynchronously by
1979 // m_updateToolBarTimer.
1980 connect(m_toolBarSpacer
, SIGNAL(destroyed()), this, SLOT(slotToolBarSpacerDeleted()));
1981 connect(m_openToolBarMenuButton
, SIGNAL(destroyed()), this, SLOT(slotToolBarMenuButtonDeleted()));
1982 m_updateToolBarTimer
= new QTimer(this);
1983 m_updateToolBarTimer
->setInterval(500);
1984 connect(m_updateToolBarTimer
, SIGNAL(timeout()), this, SLOT(updateToolBar()));
1987 void DolphinMainWindow::deleteToolBarMenuButton()
1989 delete m_toolBarSpacer
;
1990 m_toolBarSpacer
= 0;
1992 delete m_openToolBarMenuButton
;
1993 m_openToolBarMenuButton
= 0;
1995 delete m_updateToolBarTimer
;
1996 m_updateToolBarTimer
= 0;
1999 bool DolphinMainWindow::addActionToMenu(QAction
* action
, KMenu
* menu
)
2004 const KToolBar
* toolBarWidget
= toolBar();
2005 foreach (const QWidget
* widget
, action
->associatedWidgets()) {
2006 if (widget
== toolBarWidget
) {
2011 menu
->addAction(action
);
2015 void DolphinMainWindow::rememberClosedTab(int index
)
2017 KMenu
* tabsMenu
= m_recentTabsMenu
->menu();
2019 const QString primaryPath
= m_viewTab
[index
].primaryView
->url().path();
2020 const QString iconName
= KMimeType::iconNameForUrl(primaryPath
);
2022 QAction
* action
= new QAction(squeezedText(primaryPath
), tabsMenu
);
2024 ClosedTab closedTab
;
2025 closedTab
.primaryUrl
= m_viewTab
[index
].primaryView
->url();
2027 if (m_viewTab
[index
].secondaryView
) {
2028 closedTab
.secondaryUrl
= m_viewTab
[index
].secondaryView
->url();
2029 closedTab
.isSplit
= true;
2031 closedTab
.isSplit
= false;
2034 action
->setData(QVariant::fromValue(closedTab
));
2035 action
->setIcon(KIcon(iconName
));
2037 // add the closed tab menu entry after the separator and
2038 // "Empty Recently Closed Tabs" entry
2039 if (tabsMenu
->actions().size() == 2) {
2040 tabsMenu
->addAction(action
);
2042 tabsMenu
->insertAction(tabsMenu
->actions().at(2), action
);
2045 // assure that only up to 8 closed tabs are shown in the menu
2046 if (tabsMenu
->actions().size() > 8) {
2047 tabsMenu
->removeAction(tabsMenu
->actions().last());
2049 actionCollection()->action("closed_tabs")->setEnabled(true);
2050 KAcceleratorManager::manage(tabsMenu
);
2053 void DolphinMainWindow::refreshViews()
2055 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
2057 // remember the current active view, as because of
2058 // the refreshing the active view might change to
2059 // the secondary view
2060 DolphinViewContainer
* activeViewContainer
= m_activeViewContainer
;
2062 const int tabCount
= m_viewTab
.count();
2063 for (int i
= 0; i
< tabCount
; ++i
) {
2064 m_viewTab
[i
].primaryView
->refresh();
2065 if (m_viewTab
[i
].secondaryView
) {
2066 m_viewTab
[i
].secondaryView
->refresh();
2070 setActiveViewContainer(activeViewContainer
);
2072 const GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
2073 if (generalSettings
->modifiedStartupSettings()) {
2074 // The startup settings have been changed by the user (see bug #254947).
2075 // Synchronize the split-view setting with the active view:
2076 const bool splitView
= generalSettings
->splitView();
2077 const ViewTab
& activeTab
= m_viewTab
[m_tabIndex
];
2078 const bool toggle
= ( splitView
&& !activeTab
.secondaryView
)
2079 || (!splitView
&& activeTab
.secondaryView
);
2086 void DolphinMainWindow::clearStatusBar()
2088 m_activeViewContainer
->statusBar()->clear();
2091 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
2093 connect(container
, SIGNAL(showFilterBarChanged(bool)),
2094 this, SLOT(updateFilterBarAction(bool)));
2095 connect(container
, SIGNAL(writeStateChanged(bool)),
2096 this, SLOT(slotWriteStateChanged(bool)));
2097 connect(container
, SIGNAL(searchModeChanged(bool)),
2098 this, SLOT(slotSearchModeChanged(bool)));
2100 const DolphinSearchBox
* searchBox
= container
->searchBox();
2101 connect(searchBox
, SIGNAL(searchLocationChanged(SearchLocation
)),
2102 this, SLOT(slotSearchLocationChanged()));
2104 DolphinView
* view
= container
->view();
2105 connect(view
, SIGNAL(selectionChanged(KFileItemList
)),
2106 this, SLOT(slotSelectionChanged(KFileItemList
)));
2107 connect(view
, SIGNAL(requestItemInfo(KFileItem
)),
2108 this, SLOT(slotRequestItemInfo(KFileItem
)));
2109 connect(view
, SIGNAL(activated()),
2110 this, SLOT(toggleActiveView()));
2111 connect(view
, SIGNAL(tabRequested(KUrl
)),
2112 this, SLOT(openNewTab(KUrl
)));
2113 connect(view
, SIGNAL(requestContextMenu(KFileItem
,KUrl
,QList
<QAction
*>)),
2114 this, SLOT(openContextMenu(KFileItem
,KUrl
,QList
<QAction
*>)));
2115 connect(view
, SIGNAL(startedPathLoading(KUrl
)),
2116 this, SLOT(enableStopAction()));
2117 connect(view
, SIGNAL(finishedPathLoading(KUrl
)),
2118 this, SLOT(disableStopAction()));
2120 const KUrlNavigator
* navigator
= container
->urlNavigator();
2121 connect(navigator
, SIGNAL(urlChanged(KUrl
)),
2122 this, SLOT(changeUrl(KUrl
)));
2123 connect(navigator
, SIGNAL(historyChanged()),
2124 this, SLOT(updateHistory()));
2125 connect(navigator
, SIGNAL(editableStateChanged(bool)),
2126 this, SLOT(slotEditableStateChanged(bool)));
2127 connect(navigator
, SIGNAL(tabRequested(KUrl
)),
2128 this, SLOT(openNewTab(KUrl
)));
2131 void DolphinMainWindow::updateSplitAction()
2133 QAction
* splitAction
= actionCollection()->action("split_view");
2134 if (m_viewTab
[m_tabIndex
].secondaryView
) {
2135 if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
2136 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
2137 splitAction
->setToolTip(i18nc("@info", "Close right view"));
2138 splitAction
->setIcon(KIcon("view-right-close"));
2140 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
2141 splitAction
->setToolTip(i18nc("@info", "Close left view"));
2142 splitAction
->setIcon(KIcon("view-left-close"));
2145 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
2146 splitAction
->setToolTip(i18nc("@info", "Split view"));
2147 splitAction
->setIcon(KIcon("view-right-new"));
2151 QString
DolphinMainWindow::tabName(const KUrl
& url
) const
2154 if (url
.equals(KUrl("file:///"))) {
2157 name
= url
.fileName();
2158 if (name
.isEmpty()) {
2159 name
= url
.protocol();
2161 // Make sure that a '&' inside the directory name is displayed correctly
2162 // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
2163 name
.replace('&', "&&");
2169 bool DolphinMainWindow::isKompareInstalled() const
2171 static bool initialized
= false;
2172 static bool installed
= false;
2174 // TODO: maybe replace this approach later by using a menu
2175 // plugin like kdiff3plugin.cpp
2176 installed
= !KGlobal::dirs()->findExe("kompare").isEmpty();
2182 void DolphinMainWindow::createSecondaryView(int tabIndex
)
2184 QSplitter
* splitter
= m_viewTab
[tabIndex
].splitter
;
2185 const int newWidth
= (m_viewTab
[tabIndex
].primaryView
->width() - splitter
->handleWidth()) / 2;
2187 const DolphinView
* view
= m_viewTab
[tabIndex
].primaryView
->view();
2188 m_viewTab
[tabIndex
].secondaryView
= createViewContainer(view
->url(), 0);
2189 splitter
->addWidget(m_viewTab
[tabIndex
].secondaryView
);
2190 splitter
->setSizes(QList
<int>() << newWidth
<< newWidth
);
2191 connectViewSignals(m_viewTab
[tabIndex
].secondaryView
);
2192 m_viewTab
[tabIndex
].secondaryView
->setActive(false);
2193 m_viewTab
[tabIndex
].secondaryView
->show();
2196 QString
DolphinMainWindow::tabProperty(const QString
& property
, int tabIndex
) const
2198 return "Tab " + QString::number(tabIndex
) + ' ' + property
;
2201 void DolphinMainWindow::setUrlAsCaption(const KUrl
& url
)
2204 if (!url
.isLocalFile()) {
2205 caption
.append(url
.protocol() + " - ");
2206 if (url
.hasHost()) {
2207 caption
.append(url
.host() + " - ");
2211 const QString fileName
= url
.fileName().isEmpty() ? "/" : url
.fileName();
2212 caption
.append(fileName
);
2214 setCaption(caption
);
2217 QString
DolphinMainWindow::squeezedText(const QString
& text
) const
2219 const QFontMetrics fm
= fontMetrics();
2220 return fm
.elidedText(text
, Qt::ElideMiddle
, fm
.maxWidth() * 10);
2223 void DolphinMainWindow::addActionCloneToCollection(QAction
* action
, const QString
& actionName
)
2225 KAction
* actionClone
= actionCollection()->addAction(actionName
);
2226 actionClone
->setText(action
->text());
2227 actionClone
->setIcon(action
->icon());
2228 connect(actionClone
, SIGNAL(triggered()), action
, SLOT(trigger()));
2231 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
2232 KIO::FileUndoManager::UiInterface()
2236 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2240 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
2242 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
2244 DolphinStatusBar
* statusBar
= mainWin
->activeViewContainer()->statusBar();
2245 statusBar
->setMessage(job
->errorString(), DolphinStatusBar::Error
);
2247 KIO::FileUndoManager::UiInterface::jobError(job
);
2251 ToolBarMenu::ToolBarMenu(QWidget
* parent
) :
2256 ToolBarMenu::~ToolBarMenu()
2260 void ToolBarMenu::showEvent(QShowEvent
* event
)
2262 KMenu::showEvent(event
);
2264 // Adjust the position of the menu to be shown within the
2265 // Dolphin window to reduce the cases that sub-menus might overlap
2266 // the right screen border.
2268 QWidget
* button
= parentWidget();
2269 if (layoutDirection() == Qt::RightToLeft
) {
2270 pos
= button
->mapToGlobal(QPoint(0, button
->height()));
2272 pos
= button
->mapToGlobal(QPoint(button
->width(), button
->height()));
2273 pos
.rx() -= width();
2276 // Assure that the menu is not shown outside the screen boundaries and
2277 // that it does not overlap with the parent button.
2278 const QRect screen
= QApplication::desktop()->screenGeometry(QCursor::pos());
2279 if (pos
.x() < screen
.x()) {
2280 pos
.rx() = screen
.x();
2281 } else if (pos
.x() + width() > screen
.x() + screen
.width()) {
2282 pos
.rx() = screen
.x() + screen
.width() - width();
2285 if (pos
.y() < screen
.y()) {
2286 pos
.ry() = screen
.y();
2287 } else if (pos
.y() + height() > screen
.y() + screen
.height()) {
2288 pos
.ry() = button
->mapToGlobal(QPoint(0, 0)).y() - height();
2294 #include "dolphinmainwindow.moc"