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_searchsettings.h"
54 #include <KAcceleratorManager>
56 #include <KActionCollection>
57 #include <KActionMenu>
59 #include <KDesktopFile>
60 #include <kdeversion.h>
61 #include <kdualaction.h>
62 #include <KFileDialog>
63 #include <KFilePlacesModel>
68 #include <KIconLoader>
69 #include <KIO/NetAccess>
70 #include <KInputDialog>
72 #include <KProtocolManager>
75 #include <KMessageBox>
76 #include <KFileItemListProperties>
77 #include <konqmimedata.h>
78 #include <KProtocolInfo>
81 #include <KStandardDirs>
82 #include <kstatusbar.h>
83 #include <KStandardAction>
85 #include <KToggleAction>
86 #include <KUrlNavigator>
88 #include <KUrlComboBox>
89 #include <KToolInvocation>
91 #include <QDesktopWidget>
92 #include <QDBusMessage>
95 #include <QToolButton>
99 // Used for GeneralSettings::version() to determine whether
100 // an updated version of Dolphin is running.
101 const int CurrentDolphinVersion
= 200;
105 * Menu shown when pressing the configure-button in the toolbar.
107 class ToolBarMenu
: public KMenu
110 ToolBarMenu(QWidget
* parent
);
111 virtual ~ToolBarMenu();
113 virtual void showEvent(QShowEvent
* event
);
117 * Remembers the tab configuration if a tab has been closed.
118 * Each closed tab can be restored by the menu
119 * "Go -> Recently Closed Tabs".
127 Q_DECLARE_METATYPE(ClosedTab
)
129 DolphinMainWindow::DolphinMainWindow() :
133 m_activeViewContainer(0),
134 m_centralWidgetLayout(0),
141 m_openToolBarMenuButton(0),
142 m_updateToolBarTimer(0),
143 m_lastHandleUrlStatJob(0),
144 m_searchDockIsTemporaryVisible(false)
146 // Workaround for a X11-issue in combination with KModifierInfo
147 // (see DolphinContextMenu::initializeModifierKeyInfo() for
148 // more information):
149 DolphinContextMenu::initializeModifierKeyInfo();
151 setObjectName("Dolphin#");
153 m_viewTab
.append(ViewTab());
155 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
156 undoManager
->setUiInterface(new UndoUiInterface());
158 connect(undoManager
, SIGNAL(undoAvailable(bool)),
159 this, SLOT(slotUndoAvailable(bool)));
160 connect(undoManager
, SIGNAL(undoTextChanged(QString
)),
161 this, SLOT(slotUndoTextChanged(QString
)));
162 connect(undoManager
, SIGNAL(jobRecordingStarted(CommandType
)),
163 this, SLOT(clearStatusBar()));
164 connect(undoManager
, SIGNAL(jobRecordingFinished(CommandType
)),
165 this, SLOT(showCommand(CommandType
)));
166 connect(DolphinSettings::instance().placesModel(), SIGNAL(errorMessage(QString
)),
167 this, SLOT(showErrorMessage(QString
)));
168 //connect(&DragAndDropHelper::instance(), SIGNAL(errorMessage(QString)),
169 // this, SLOT(showErrorMessage(QString)));
171 const DolphinSettings
& settings
= DolphinSettings::instance();
173 GeneralSettings
* generalSettings
= settings
.generalSettings();
174 const bool firstRun
= (generalSettings
->version() < 200);
176 generalSettings
->setViewPropsTimestamp(QDateTime::currentDateTime());
179 setAcceptDrops(true);
181 m_viewTab
[m_tabIndex
].splitter
= new QSplitter(this);
182 m_viewTab
[m_tabIndex
].splitter
->setChildrenCollapsible(false);
186 const KUrl
homeUrl(generalSettings
->homeUrl());
187 setUrlAsCaption(homeUrl
);
188 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
189 connect(m_actionHandler
, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
190 connect(m_actionHandler
, SIGNAL(createDirectory()), SLOT(createDirectory()));
192 m_viewTab
[m_tabIndex
].primaryView
= createViewContainer(homeUrl
, m_viewTab
[m_tabIndex
].splitter
);
194 m_activeViewContainer
= m_viewTab
[m_tabIndex
].primaryView
;
195 connectViewSignals(m_activeViewContainer
);
196 DolphinView
* view
= m_activeViewContainer
->view();
197 m_activeViewContainer
->show();
198 m_actionHandler
->setCurrentView(view
);
200 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
201 connect(this, SIGNAL(urlChanged(KUrl
)),
202 m_remoteEncoding
, SLOT(slotAboutToOpenUrl()));
204 m_tabBar
= new KTabBar(this);
205 m_tabBar
->setMovable(true);
206 m_tabBar
->setTabsClosable(true);
207 connect(m_tabBar
, SIGNAL(currentChanged(int)),
208 this, SLOT(setActiveTab(int)));
209 connect(m_tabBar
, SIGNAL(tabCloseRequested(int)),
210 this, SLOT(closeTab(int)));
211 connect(m_tabBar
, SIGNAL(contextMenu(int,QPoint
)),
212 this, SLOT(openTabContextMenu(int,QPoint
)));
213 connect(m_tabBar
, SIGNAL(newTabRequest()),
214 this, SLOT(openNewTab()));
215 connect(m_tabBar
, SIGNAL(testCanDecode(const QDragMoveEvent
*,bool&)),
216 this, SLOT(slotTestCanDecode(const QDragMoveEvent
*,bool&)));
217 connect(m_tabBar
, SIGNAL(mouseMiddleClick(int)),
218 this, SLOT(closeTab(int)));
219 connect(m_tabBar
, SIGNAL(tabMoved(int,int)),
220 this, SLOT(slotTabMoved(int,int)));
221 connect(m_tabBar
, SIGNAL(receivedDropEvent(int,QDropEvent
*)),
222 this, SLOT(tabDropEvent(int,QDropEvent
*)));
224 m_tabBar
->blockSignals(true); // signals get unblocked after at least 2 tabs are open
226 QWidget
* centralWidget
= new QWidget(this);
227 m_centralWidgetLayout
= new QVBoxLayout(centralWidget
);
228 m_centralWidgetLayout
->setSpacing(0);
229 m_centralWidgetLayout
->setMargin(0);
230 m_centralWidgetLayout
->addWidget(m_tabBar
);
231 m_centralWidgetLayout
->addWidget(m_viewTab
[m_tabIndex
].splitter
, 1);
233 setCentralWidget(centralWidget
);
235 emit
urlChanged(homeUrl
);
237 setupGUI(Keys
| Save
| Create
| ToolBar
);
238 stateChanged("new_file");
240 QClipboard
* clipboard
= QApplication::clipboard();
241 connect(clipboard
, SIGNAL(dataChanged()),
242 this, SLOT(updatePasteAction()));
244 if (generalSettings
->splitView()) {
251 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
252 showFilterBarAction
->setChecked(generalSettings
->filterBar());
255 menuBar()->setVisible(false);
256 // Assure a proper default size if Dolphin runs the first time
260 const bool showMenu
= !menuBar()->isHidden();
261 QAction
* showMenuBarAction
= actionCollection()->action(KStandardAction::name(KStandardAction::ShowMenubar
));
262 showMenuBarAction
->setChecked(showMenu
); // workaround for bug #171080
264 createToolBarMenuButton();
268 DolphinMainWindow::~DolphinMainWindow()
272 void DolphinMainWindow::openDirectories(const QList
<KUrl
>& dirs
)
274 if (dirs
.isEmpty()) {
278 if (dirs
.count() == 1) {
279 m_activeViewContainer
->setUrl(dirs
.first());
283 const int oldOpenTabsCount
= m_viewTab
.count();
285 const GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
286 const bool hasSplitView
= generalSettings
->splitView();
288 // Open each directory inside a new tab. If the "split view" option has been enabled,
289 // always show two directories within one tab.
290 QList
<KUrl
>::const_iterator it
= dirs
.begin();
291 while (it
!= dirs
.end()) {
295 if (hasSplitView
&& (it
!= dirs
.end())) {
296 const int tabIndex
= m_viewTab
.count() - 1;
297 m_viewTab
[tabIndex
].secondaryView
->setUrl(*it
);
302 // Remove the previously opened tabs
303 for (int i
= 0; i
< oldOpenTabsCount
; ++i
) {
308 void DolphinMainWindow::openFiles(const QList
<KUrl
>& files
)
310 if (files
.isEmpty()) {
314 // Get all distinct directories from 'files' and open a tab
315 // for each directory. If the "split view" option is enabled, two
316 // directories are shown inside one tab (see openDirectories()).
318 foreach (const KUrl
& url
, files
) {
319 const KUrl
dir(url
.directory());
320 if (!dirs
.contains(dir
)) {
325 openDirectories(dirs
);
327 // Select the files. Although the files can be split between several
328 // tabs, there is no need to split 'files' accordingly, as
329 // the DolphinView will just ignore invalid selections.
330 const int tabCount
= m_viewTab
.count();
331 for (int i
= 0; i
< tabCount
; ++i
) {
332 m_viewTab
[i
].primaryView
->view()->markUrlsAsSelected(files
);
333 if (m_viewTab
[i
].secondaryView
) {
334 m_viewTab
[i
].secondaryView
->view()->markUrlsAsSelected(files
);
339 void DolphinMainWindow::showCommand(CommandType command
)
341 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
343 case KIO::FileUndoManager::Copy
:
344 statusBar
->setMessage(i18nc("@info:status", "Successfully copied."),
345 DolphinStatusBar::OperationCompleted
);
347 case KIO::FileUndoManager::Move
:
348 statusBar
->setMessage(i18nc("@info:status", "Successfully moved."),
349 DolphinStatusBar::OperationCompleted
);
351 case KIO::FileUndoManager::Link
:
352 statusBar
->setMessage(i18nc("@info:status", "Successfully linked."),
353 DolphinStatusBar::OperationCompleted
);
355 case KIO::FileUndoManager::Trash
:
356 statusBar
->setMessage(i18nc("@info:status", "Successfully moved to trash."),
357 DolphinStatusBar::OperationCompleted
);
359 case KIO::FileUndoManager::Rename
:
360 statusBar
->setMessage(i18nc("@info:status", "Successfully renamed."),
361 DolphinStatusBar::OperationCompleted
);
364 case KIO::FileUndoManager::Mkdir
:
365 statusBar
->setMessage(i18nc("@info:status", "Created folder."),
366 DolphinStatusBar::OperationCompleted
);
374 void DolphinMainWindow::pasteIntoFolder()
376 m_activeViewContainer
->view()->pasteIntoFolder();
379 void DolphinMainWindow::changeUrl(const KUrl
& url
)
381 if (!KProtocolManager::supportsListing(url
)) {
382 // The URL navigator only checks for validity, not
383 // if the URL can be listed. An error message is
384 // shown due to DolphinViewContainer::restoreView().
388 DolphinViewContainer
* view
= activeViewContainer();
394 setUrlAsCaption(url
);
395 if (m_viewTab
.count() > 1) {
396 m_tabBar
->setTabText(m_tabIndex
, squeezedText(tabName(m_activeViewContainer
->url())));
398 const QString iconName
= KMimeType::iconNameForUrl(url
);
399 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(iconName
));
400 emit
urlChanged(url
);
404 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
406 KToggleAction
* editableLocationAction
=
407 static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
408 editableLocationAction
->setChecked(editable
);
411 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
415 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
416 int selectedUrlsCount
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedItemsCount();
417 if (m_viewTab
[m_tabIndex
].secondaryView
) {
418 selectedUrlsCount
+= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItemsCount();
421 QAction
* compareFilesAction
= actionCollection()->action("compare_files");
422 if (selectedUrlsCount
== 2) {
423 compareFilesAction
->setEnabled(isKompareInstalled());
425 compareFilesAction
->setEnabled(false);
428 emit
selectionChanged(selection
);
431 void DolphinMainWindow::slotRequestItemInfo(const KFileItem
& item
)
433 emit
requestItemInfo(item
);
436 void DolphinMainWindow::updateHistory()
438 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
439 const int index
= urlNavigator
->historyIndex();
441 QAction
* backAction
= actionCollection()->action("go_back");
442 backAction
->setToolTip(i18nc("@info", "Go back"));
444 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
447 QAction
* forwardAction
= actionCollection()->action("go_forward");
448 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
450 forwardAction
->setEnabled(index
> 0);
454 void DolphinMainWindow::updateFilterBarAction(bool show
)
456 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
457 showFilterBarAction
->setChecked(show
);
460 void DolphinMainWindow::openNewMainWindow()
462 KRun::run("dolphin", KUrl::List(), this);
465 void DolphinMainWindow::openNewTab()
467 const bool isUrlEditable
= m_activeViewContainer
->urlNavigator()->isUrlEditable();
469 openNewTab(m_activeViewContainer
->url());
470 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
472 // The URL navigator of the new tab should have the same editable state
473 // as the current tab
474 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
475 navigator
->setUrlEditable(isUrlEditable
);
478 // If a new tab is opened and the URL is editable, assure that
479 // the user can edit the URL without manually setting the focus
480 navigator
->setFocus();
484 void DolphinMainWindow::openNewTab(const KUrl
& url
)
486 QWidget
* focusWidget
= QApplication::focusWidget();
488 if (m_viewTab
.count() == 1) {
489 // Only one view is open currently and hence no tab is shown at
490 // all. Before creating a tab for 'url', provide a tab for the current URL.
491 const KUrl currentUrl
= m_activeViewContainer
->url();
492 m_tabBar
->addTab(KIcon(KMimeType::iconNameForUrl(currentUrl
)),
493 squeezedText(tabName(currentUrl
)));
494 m_tabBar
->blockSignals(false);
497 m_tabBar
->addTab(KIcon(KMimeType::iconNameForUrl(url
)),
498 squeezedText(tabName(url
)));
501 viewTab
.splitter
= new QSplitter(this);
502 viewTab
.splitter
->setChildrenCollapsible(false);
503 viewTab
.primaryView
= createViewContainer(url
, viewTab
.splitter
);
504 viewTab
.primaryView
->setActive(false);
505 connectViewSignals(viewTab
.primaryView
);
507 m_viewTab
.append(viewTab
);
509 actionCollection()->action("close_tab")->setEnabled(true);
511 // provide a split view, if the startup settings are set this way
512 const GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
513 if (generalSettings
->splitView()) {
514 const int tabIndex
= m_viewTab
.count() - 1;
515 createSecondaryView(tabIndex
);
516 m_viewTab
[tabIndex
].secondaryView
->setActive(true);
517 m_viewTab
[tabIndex
].isPrimaryViewActive
= false;
521 // The DolphinViewContainer grabbed the keyboard focus. As the tab is opened
522 // in background, assure that the previous focused widget gets the focus back.
523 focusWidget
->setFocus();
527 void DolphinMainWindow::activateNextTab()
529 if ((m_viewTab
.count() == 1) || (m_tabBar
->count() < 2)) {
533 const int tabIndex
= (m_tabBar
->currentIndex() + 1) % m_tabBar
->count();
534 m_tabBar
->setCurrentIndex(tabIndex
);
537 void DolphinMainWindow::activatePrevTab()
539 if ((m_viewTab
.count() == 1) || (m_tabBar
->count() < 2)) {
543 int tabIndex
= m_tabBar
->currentIndex() - 1;
544 if (tabIndex
== -1) {
545 tabIndex
= m_tabBar
->count() - 1;
547 m_tabBar
->setCurrentIndex(tabIndex
);
550 void DolphinMainWindow::openInNewTab()
552 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
553 if (list
.isEmpty()) {
554 openNewTab(m_activeViewContainer
->url());
555 } else if ((list
.count() == 1) && list
[0].isDir()) {
556 openNewTab(list
[0].url());
560 void DolphinMainWindow::openInNewWindow()
564 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
565 if (list
.isEmpty()) {
566 newWindowUrl
= m_activeViewContainer
->url();
567 } else if ((list
.count() == 1) && list
[0].isDir()) {
568 newWindowUrl
= list
[0].url();
571 if (!newWindowUrl
.isEmpty()) {
572 KRun::run("dolphin", KUrl::List() << newWindowUrl
, this);
576 void DolphinMainWindow::toggleActiveView()
578 if (!m_viewTab
[m_tabIndex
].secondaryView
) {
579 // only one view is available
583 Q_ASSERT(m_activeViewContainer
);
584 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
586 DolphinViewContainer
* left
= m_viewTab
[m_tabIndex
].primaryView
;
587 DolphinViewContainer
* right
= m_viewTab
[m_tabIndex
].secondaryView
;
588 setActiveViewContainer(m_activeViewContainer
== right
? left
: right
);
591 void DolphinMainWindow::showEvent(QShowEvent
* event
)
593 KXmlGuiWindow::showEvent(event
);
594 if (!event
->spontaneous()) {
595 m_activeViewContainer
->view()->setFocus();
599 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
601 DolphinSettings
& settings
= DolphinSettings::instance();
602 GeneralSettings
* generalSettings
= settings
.generalSettings();
604 // Find out if Dolphin is closed directly by the user or
605 // by the session manager because the session is closed
606 bool closedByUser
= true;
607 DolphinApplication
*application
= qobject_cast
<DolphinApplication
*>(qApp
);
608 if (application
&& application
->sessionSaving()) {
609 closedByUser
= false;
612 if ((m_viewTab
.count() > 1) && generalSettings
->confirmClosingMultipleTabs() && closedByUser
) {
613 // Ask the user if he really wants to quit and close all tabs.
614 // Open a confirmation dialog with 3 buttons:
615 // KDialog::Yes -> Quit
616 // KDialog::No -> Close only the current tab
617 // KDialog::Cancel -> do nothing
618 KDialog
*dialog
= new KDialog(this, Qt::Dialog
);
619 dialog
->setCaption(i18nc("@title:window", "Confirmation"));
620 dialog
->setButtons(KDialog::Yes
| KDialog::No
| KDialog::Cancel
);
621 dialog
->setModal(true);
622 dialog
->setButtonGuiItem(KDialog::Yes
, KStandardGuiItem::quit());
623 dialog
->setButtonGuiItem(KDialog::No
, KGuiItem(i18n("C&lose Current Tab"), KIcon("tab-close")));
624 dialog
->setButtonGuiItem(KDialog::Cancel
, KStandardGuiItem::cancel());
625 dialog
->setDefaultButton(KDialog::Yes
);
627 bool doNotAskAgainCheckboxResult
= false;
629 const int result
= KMessageBox::createKMessageBox(dialog
,
630 QMessageBox::Warning
,
631 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
633 i18n("Do not ask again"),
634 &doNotAskAgainCheckboxResult
,
635 KMessageBox::Notify
);
637 if (doNotAskAgainCheckboxResult
) {
638 generalSettings
->setConfirmClosingMultipleTabs(false);
646 // Close only the current tab
654 generalSettings
->setVersion(CurrentDolphinVersion
);
657 if (m_searchDockIsTemporaryVisible
) {
658 QDockWidget
* searchDock
= findChild
<QDockWidget
*>("searchDock");
662 m_searchDockIsTemporaryVisible
= false;
665 KXmlGuiWindow::closeEvent(event
);
668 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
670 const int tabCount
= m_viewTab
.count();
671 group
.writeEntry("Tab Count", tabCount
);
672 group
.writeEntry("Active Tab Index", m_tabBar
->currentIndex());
674 for (int i
= 0; i
< tabCount
; ++i
) {
675 const DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
676 group
.writeEntry(tabProperty("Primary URL", i
), cont
->url().url());
677 group
.writeEntry(tabProperty("Primary Editable", i
),
678 cont
->urlNavigator()->isUrlEditable());
680 cont
= m_viewTab
[i
].secondaryView
;
682 group
.writeEntry(tabProperty("Secondary URL", i
), cont
->url().url());
683 group
.writeEntry(tabProperty("Secondary Editable", i
),
684 cont
->urlNavigator()->isUrlEditable());
689 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
691 const int tabCount
= group
.readEntry("Tab Count", 1);
692 for (int i
= 0; i
< tabCount
; ++i
) {
693 DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
695 cont
->setUrl(group
.readEntry(tabProperty("Primary URL", i
)));
696 const bool editable
= group
.readEntry(tabProperty("Primary Editable", i
), false);
697 cont
->urlNavigator()->setUrlEditable(editable
);
699 cont
= m_viewTab
[i
].secondaryView
;
700 const QString secondaryUrl
= group
.readEntry(tabProperty("Secondary URL", i
));
701 if (!secondaryUrl
.isEmpty()) {
703 // a secondary view should be shown, but no one is available
704 // currently -> create a new view
706 cont
= m_viewTab
[i
].secondaryView
;
710 cont
->setUrl(secondaryUrl
);
711 const bool editable
= group
.readEntry(tabProperty("Secondary Editable", i
), false);
712 cont
->urlNavigator()->setUrlEditable(editable
);
714 // no secondary view should be shown, but the default setting shows
715 // one already -> close the view
719 // openNewTab() needs to be called only tabCount - 1 times
720 if (i
!= tabCount
- 1) {
725 const int index
= group
.readEntry("Active Tab Index", 0);
726 m_tabBar
->setCurrentIndex(index
);
729 void DolphinMainWindow::updateNewMenu()
731 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
732 m_newFileMenu
->checkUpToDate();
733 m_newFileMenu
->setPopupFiles(activeViewContainer()->url());
736 void DolphinMainWindow::createDirectory()
738 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
739 m_newFileMenu
->setPopupFiles(activeViewContainer()->url());
740 m_newFileMenu
->createDirectory();
743 void DolphinMainWindow::quit()
748 void DolphinMainWindow::showErrorMessage(const QString
& message
)
750 if (!message
.isEmpty()) {
751 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
752 statusBar
->setMessage(message
, DolphinStatusBar::Error
);
756 void DolphinMainWindow::slotUndoAvailable(bool available
)
758 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
760 undoAction
->setEnabled(available
);
764 void DolphinMainWindow::restoreClosedTab(QAction
* action
)
766 if (action
->data().toBool()) {
767 // clear all actions except the "Empty Recently Closed Tabs"
768 // action and the separator
769 QList
<QAction
*> actions
= m_recentTabsMenu
->menu()->actions();
770 const int count
= actions
.size();
771 for (int i
= 2; i
< count
; ++i
) {
772 m_recentTabsMenu
->menu()->removeAction(actions
.at(i
));
775 const ClosedTab closedTab
= action
->data().value
<ClosedTab
>();
776 openNewTab(closedTab
.primaryUrl
);
777 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
779 if (closedTab
.isSplit
) {
780 // create secondary view
782 m_viewTab
[m_tabIndex
].secondaryView
->setUrl(closedTab
.secondaryUrl
);
785 m_recentTabsMenu
->removeAction(action
);
788 if (m_recentTabsMenu
->menu()->actions().count() == 2) {
789 m_recentTabsMenu
->setEnabled(false);
793 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
795 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
797 undoAction
->setText(text
);
801 void DolphinMainWindow::undo()
804 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
805 KIO::FileUndoManager::self()->undo();
808 void DolphinMainWindow::cut()
810 m_activeViewContainer
->view()->cutSelectedItems();
813 void DolphinMainWindow::copy()
815 m_activeViewContainer
->view()->copySelectedItems();
818 void DolphinMainWindow::paste()
820 m_activeViewContainer
->view()->paste();
823 void DolphinMainWindow::find()
825 m_activeViewContainer
->setSearchModeEnabled(true);
828 void DolphinMainWindow::slotSearchLocationChanged()
831 QDockWidget
* searchDock
= findChild
<QDockWidget
*>("searchDock");
836 SearchPanel
* searchPanel
= qobject_cast
<SearchPanel
*>(searchDock
->widget());
838 searchPanel
->setSearchLocation(SearchSettings::location() == QLatin1String("FromHere")
839 ? SearchPanel::FromCurrentDir
840 : SearchPanel::Everywhere
);
845 void DolphinMainWindow::updatePasteAction()
847 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
848 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
849 pasteAction
->setEnabled(pasteInfo
.first
);
850 pasteAction
->setText(pasteInfo
.second
);
853 void DolphinMainWindow::selectAll()
857 // if the URL navigator is editable and focused, select the whole
858 // URL instead of all items of the view
860 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
861 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit(); // krazy:exclude=qclasses
862 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
863 lineEdit
->hasFocus();
865 lineEdit
->selectAll();
867 m_activeViewContainer
->view()->selectAll();
871 void DolphinMainWindow::invertSelection()
874 m_activeViewContainer
->view()->invertSelection();
877 void DolphinMainWindow::toggleSplitView()
879 if (!m_viewTab
[m_tabIndex
].secondaryView
) {
880 createSecondaryView(m_tabIndex
);
881 setActiveViewContainer(m_viewTab
[m_tabIndex
].secondaryView
);
882 } else if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
883 // remove secondary view
884 m_viewTab
[m_tabIndex
].secondaryView
->close();
885 m_viewTab
[m_tabIndex
].secondaryView
->deleteLater();
886 m_viewTab
[m_tabIndex
].secondaryView
= 0;
888 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
890 // The primary view is active and should be closed. Hence from a users point of view
891 // the content of the secondary view should be moved to the primary view.
892 // From an implementation point of view it is more efficient to close
893 // the primary view and exchange the internal pointers afterwards.
895 m_viewTab
[m_tabIndex
].primaryView
->close();
896 m_viewTab
[m_tabIndex
].primaryView
->deleteLater();
897 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
898 m_viewTab
[m_tabIndex
].secondaryView
= 0;
900 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
906 void DolphinMainWindow::reloadView()
909 m_activeViewContainer
->view()->reload();
912 void DolphinMainWindow::stopLoading()
914 m_activeViewContainer
->view()->stopLoading();
917 void DolphinMainWindow::enableStopAction()
919 actionCollection()->action("stop")->setEnabled(true);
922 void DolphinMainWindow::disableStopAction()
924 actionCollection()->action("stop")->setEnabled(false);
927 void DolphinMainWindow::showFilterBar()
929 m_activeViewContainer
->setFilterBarVisible(true);
932 void DolphinMainWindow::toggleEditLocation()
936 QAction
* action
= actionCollection()->action("editable_location");
937 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
938 urlNavigator
->setUrlEditable(action
->isChecked());
941 void DolphinMainWindow::replaceLocation()
943 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
944 navigator
->setUrlEditable(true);
945 navigator
->setFocus();
947 // select the whole text of the combo box editor
948 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit(); // krazy:exclude=qclasses
949 lineEdit
->selectAll();
952 void DolphinMainWindow::togglePanelLockState()
954 GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
956 const bool newLockState
= !generalSettings
->lockPanels();
957 foreach (QObject
* child
, children()) {
958 DolphinDockWidget
* dock
= qobject_cast
<DolphinDockWidget
*>(child
);
960 dock
->setLocked(newLockState
);
964 generalSettings
->setLockPanels(newLockState
);
967 void DolphinMainWindow::slotPlacesPanelVisibilityChanged(bool visible
)
969 const int tabCount
= m_viewTab
.count();
970 for (int i
= 0; i
< tabCount
; ++i
) {
971 ViewTab
& tab
= m_viewTab
[i
];
972 Q_ASSERT(tab
.primaryView
);
973 tab
.primaryView
->urlNavigator()->setPlacesSelectorVisible(!visible
);
974 if (tab
.secondaryView
) {
975 tab
.secondaryView
->urlNavigator()->setPlacesSelectorVisible(!visible
);
980 void DolphinMainWindow::goBack()
982 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
983 urlNavigator
->goBack();
985 if (urlNavigator
->locationState().isEmpty()) {
986 // An empty location state indicates a redirection URL,
987 // which must be skipped too
988 urlNavigator
->goBack();
992 void DolphinMainWindow::goForward()
994 m_activeViewContainer
->urlNavigator()->goForward();
997 void DolphinMainWindow::goUp()
999 m_activeViewContainer
->urlNavigator()->goUp();
1002 void DolphinMainWindow::goHome()
1004 m_activeViewContainer
->urlNavigator()->goHome();
1007 void DolphinMainWindow::goBack(Qt::MouseButtons buttons
)
1009 // The default case (left button pressed) is handled in goBack().
1010 if (buttons
== Qt::MidButton
) {
1011 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
1012 const int index
= urlNavigator
->historyIndex() + 1;
1013 openNewTab(urlNavigator
->locationUrl(index
));
1017 void DolphinMainWindow::goForward(Qt::MouseButtons buttons
)
1019 // The default case (left button pressed) is handled in goForward().
1020 if (buttons
== Qt::MidButton
) {
1021 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
1022 const int index
= urlNavigator
->historyIndex() - 1;
1023 openNewTab(urlNavigator
->locationUrl(index
));
1027 void DolphinMainWindow::goUp(Qt::MouseButtons buttons
)
1029 // The default case (left button pressed) is handled in goUp().
1030 if (buttons
== Qt::MidButton
) {
1031 openNewTab(activeViewContainer()->url().upUrl());
1035 void DolphinMainWindow::compareFiles()
1037 // The method is only invoked if exactly 2 files have
1038 // been selected. The selected files may be:
1039 // - both in the primary view
1040 // - both in the secondary view
1041 // - one in the primary view and the other in the secondary
1043 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
1048 KFileItemList items
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedItems();
1050 switch (items
.count()) {
1052 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
);
1053 items
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItems();
1054 Q_ASSERT(items
.count() == 2);
1055 urlA
= items
[0].url();
1056 urlB
= items
[1].url();
1061 urlA
= items
[0].url();
1062 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
);
1063 items
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItems();
1064 Q_ASSERT(items
.count() == 1);
1065 urlB
= items
[0].url();
1070 urlA
= items
[0].url();
1071 urlB
= items
[1].url();
1076 // may not happen: compareFiles may only get invoked if 2
1077 // files are selected
1082 QString
command("kompare -c \"");
1083 command
.append(urlA
.pathOrUrl());
1084 command
.append("\" \"");
1085 command
.append(urlB
.pathOrUrl());
1086 command
.append('\"');
1087 KRun::runCommand(command
, "Kompare", "kompare", this);
1090 void DolphinMainWindow::toggleShowMenuBar()
1092 const bool visible
= menuBar()->isVisible();
1093 menuBar()->setVisible(!visible
);
1095 createToolBarMenuButton();
1097 deleteToolBarMenuButton();
1101 void DolphinMainWindow::openTerminal()
1103 QString
dir(QDir::homePath());
1105 // If the given directory is not local, it can still be the URL of an
1106 // ioslave using UDS_LOCAL_PATH which to be converted first.
1107 KUrl url
= KIO::NetAccess::mostLocalUrl(m_activeViewContainer
->url(), this);
1109 //If the URL is local after the above conversion, set the directory.
1110 if (url
.isLocalFile()) {
1111 dir
= url
.toLocalFile();
1114 KToolInvocation::invokeTerminal(QString(), dir
);
1117 void DolphinMainWindow::editSettings()
1119 if (!m_settingsDialog
) {
1120 const KUrl url
= activeViewContainer()->url();
1121 DolphinSettingsDialog
* settingsDialog
= new DolphinSettingsDialog(url
, this);
1122 connect(settingsDialog
, SIGNAL(settingsChanged()), this, SLOT(refreshViews()));
1123 settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1124 settingsDialog
->show();
1125 m_settingsDialog
= settingsDialog
;
1127 m_settingsDialog
.data()->raise();
1131 void DolphinMainWindow::setActiveTab(int index
)
1133 Q_ASSERT(index
>= 0);
1134 Q_ASSERT(index
< m_viewTab
.count());
1135 if (index
== m_tabIndex
) {
1139 // hide current tab content
1140 ViewTab
& hiddenTab
= m_viewTab
[m_tabIndex
];
1141 hiddenTab
.isPrimaryViewActive
= hiddenTab
.primaryView
->isActive();
1142 hiddenTab
.primaryView
->setActive(false);
1143 if (hiddenTab
.secondaryView
) {
1144 hiddenTab
.secondaryView
->setActive(false);
1146 QSplitter
* splitter
= m_viewTab
[m_tabIndex
].splitter
;
1148 m_centralWidgetLayout
->removeWidget(splitter
);
1150 // show active tab content
1153 ViewTab
& viewTab
= m_viewTab
[index
];
1154 m_centralWidgetLayout
->addWidget(viewTab
.splitter
, 1);
1155 viewTab
.primaryView
->show();
1156 if (viewTab
.secondaryView
) {
1157 viewTab
.secondaryView
->show();
1159 viewTab
.splitter
->show();
1161 setActiveViewContainer(viewTab
.isPrimaryViewActive
? viewTab
.primaryView
:
1162 viewTab
.secondaryView
);
1165 void DolphinMainWindow::closeTab()
1167 closeTab(m_tabBar
->currentIndex());
1170 void DolphinMainWindow::closeTab(int index
)
1172 Q_ASSERT(index
>= 0);
1173 Q_ASSERT(index
< m_viewTab
.count());
1174 if (m_viewTab
.count() == 1) {
1175 // the last tab may never get closed
1179 if (index
== m_tabIndex
) {
1180 // The tab that should be closed is the active tab. Activate the
1181 // previous tab before closing the tab.
1182 m_tabBar
->setCurrentIndex((index
> 0) ? index
- 1 : 1);
1184 rememberClosedTab(index
);
1187 m_viewTab
[index
].primaryView
->deleteLater();
1188 if (m_viewTab
[index
].secondaryView
) {
1189 m_viewTab
[index
].secondaryView
->deleteLater();
1191 m_viewTab
[index
].splitter
->deleteLater();
1192 m_viewTab
.erase(m_viewTab
.begin() + index
);
1194 m_tabBar
->blockSignals(true);
1195 m_tabBar
->removeTab(index
);
1197 if (m_tabIndex
> index
) {
1199 Q_ASSERT(m_tabIndex
>= 0);
1202 // if only one tab is left, also remove the tab entry so that
1203 // closing the last tab is not possible
1204 if (m_viewTab
.count() == 1) {
1205 m_tabBar
->removeTab(0);
1206 actionCollection()->action("close_tab")->setEnabled(false);
1208 m_tabBar
->blockSignals(false);
1212 void DolphinMainWindow::openTabContextMenu(int index
, const QPoint
& pos
)
1216 QAction
* newTabAction
= menu
.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab"));
1217 newTabAction
->setShortcut(actionCollection()->action("new_tab")->shortcut());
1219 QAction
* detachTabAction
= menu
.addAction(KIcon("tab-detach"), i18nc("@action:inmenu", "Detach Tab"));
1221 QAction
* closeOtherTabsAction
= menu
.addAction(KIcon("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs"));
1223 QAction
* closeTabAction
= menu
.addAction(KIcon("tab-close"), i18nc("@action:inmenu", "Close Tab"));
1224 closeTabAction
->setShortcut(actionCollection()->action("close_tab")->shortcut());
1225 QAction
* selectedAction
= menu
.exec(pos
);
1226 if (selectedAction
== newTabAction
) {
1227 const ViewTab
& tab
= m_viewTab
[index
];
1228 Q_ASSERT(tab
.primaryView
);
1229 const KUrl url
= tab
.secondaryView
&& tab
.secondaryView
->isActive() ?
1230 tab
.secondaryView
->url() : tab
.primaryView
->url();
1232 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
1233 } else if (selectedAction
== detachTabAction
) {
1234 const QString
separator(QLatin1Char(' '));
1235 QString command
= QLatin1String("dolphin");
1237 const ViewTab
& tab
= m_viewTab
[index
];
1238 Q_ASSERT(tab
.primaryView
);
1240 command
+= separator
+ tab
.primaryView
->url().url();
1241 if (tab
.secondaryView
) {
1242 command
+= separator
+ tab
.secondaryView
->url().url();
1243 command
+= separator
+ QLatin1String("-split");
1246 KRun::runCommand(command
, this);
1249 } else if (selectedAction
== closeOtherTabsAction
) {
1250 const int count
= m_tabBar
->count();
1251 for (int i
= 0; i
< index
; ++i
) {
1254 for (int i
= index
+ 1; i
< count
; ++i
) {
1257 } else if (selectedAction
== closeTabAction
) {
1262 void DolphinMainWindow::slotTabMoved(int from
, int to
)
1264 m_viewTab
.move(from
, to
);
1265 m_tabIndex
= m_tabBar
->currentIndex();
1268 void DolphinMainWindow::handlePlacesClick(const KUrl
& url
, Qt::MouseButtons buttons
)
1270 if (buttons
& Qt::MidButton
) {
1272 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
1278 void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent
* event
, bool& canDecode
)
1280 canDecode
= KUrl::List::canDecode(event
->mimeData());
1283 void DolphinMainWindow::handleUrl(const KUrl
& url
)
1285 delete m_lastHandleUrlStatJob
;
1286 m_lastHandleUrlStatJob
= 0;
1288 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1289 activeViewContainer()->setUrl(url
);
1290 } else if (KProtocolManager::supportsListing(url
)) {
1291 // stat the URL to see if it is a dir or not
1292 m_lastHandleUrlStatJob
= KIO::stat(url
, KIO::HideProgressInfo
);
1293 connect(m_lastHandleUrlStatJob
, SIGNAL(result(KJob
*)),
1294 this, SLOT(slotHandleUrlStatFinished(KJob
*)));
1297 new KRun(url
, this);
1301 void DolphinMainWindow::slotHandleUrlStatFinished(KJob
* job
)
1303 m_lastHandleUrlStatJob
= 0;
1304 const KIO::UDSEntry entry
= static_cast<KIO::StatJob
*>(job
)->statResult();
1305 const KUrl url
= static_cast<KIO::StatJob
*>(job
)->url();
1306 if (entry
.isDir()) {
1307 activeViewContainer()->setUrl(url
);
1309 new KRun(url
, this);
1313 void DolphinMainWindow::tabDropEvent(int tab
, QDropEvent
* event
)
1315 const KUrl::List urls
= KUrl::List::fromMimeData(event
->mimeData());
1316 if (!urls
.isEmpty() && tab
!= -1) {
1317 const ViewTab
& viewTab
= m_viewTab
[tab
];
1318 const KUrl destPath
= viewTab
.isPrimaryViewActive
? viewTab
.primaryView
->url() : viewTab
.secondaryView
->url();
1320 //DragAndDropHelper::instance().dropUrls(KFileItem(), destPath, event, m_tabBar);
1324 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1326 newFileMenu()->setEnabled(isFolderWritable
);
1329 void DolphinMainWindow::slotSearchModeChanged(bool enabled
)
1332 const DolphinSearchInformation
& searchInfo
= DolphinSearchInformation::instance();
1333 if (!searchInfo
.isIndexingEnabled()) {
1337 QDockWidget
* searchDock
= findChild
<QDockWidget
*>("searchDock");
1343 if (!searchDock
->isVisible()) {
1344 m_searchDockIsTemporaryVisible
= true;
1348 if (searchDock
->isVisible() && m_searchDockIsTemporaryVisible
) {
1351 m_searchDockIsTemporaryVisible
= false;
1354 SearchPanel
* searchPanel
= qobject_cast
<SearchPanel
*>(searchDock
->widget());
1360 SearchPanel::SearchLocation searchLocation
= SearchPanel::Everywhere
;
1361 const KUrl url
= m_activeViewContainer
->url();
1362 const bool isSearchUrl
= (url
.protocol() == QLatin1String("nepomuksearch"));
1363 if ((SearchSettings::location() == QLatin1String("FromHere") && !isSearchUrl
)) {
1364 searchLocation
= SearchPanel::FromCurrentDir
;
1366 searchPanel
->setSearchLocation(searchLocation
);
1368 searchPanel
->setSearchLocation(SearchPanel::Everywhere
);
1375 void DolphinMainWindow::openContextMenu(const KFileItem
& item
,
1377 const QList
<QAction
*>& customActions
)
1379 QPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, item
, url
);
1380 contextMenu
->setCustomActions(customActions
);
1381 const DolphinContextMenu::Command command
= contextMenu
->open();
1384 case DolphinContextMenu::OpenParentFolderInNewWindow
: {
1385 KRun::run("dolphin", KUrl::List() << item
.url().upUrl(), this);
1389 case DolphinContextMenu::OpenParentFolderInNewTab
:
1390 openNewTab(item
.url().upUrl());
1393 case DolphinContextMenu::None
:
1401 void DolphinMainWindow::updateToolBarMenu()
1403 KMenu
* menu
= qobject_cast
<KMenu
*>(sender());
1406 // All actions get cleared by KMenu::clear(). The sub-menus are deleted
1407 // by connecting to the aboutToHide() signal from the parent-menu.
1410 const GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
1412 KActionCollection
* ac
= actionCollection();
1414 // Add "Edit" actions
1415 bool added
= addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Undo
)), menu
) |
1416 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Find
)), menu
) |
1417 addActionToMenu(ac
->action("select_all"), menu
) |
1418 addActionToMenu(ac
->action("invert_selection"), menu
);
1421 menu
->addSeparator();
1424 // Add "View" actions
1425 if (!generalSettings
->showZoomSlider()) {
1426 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomIn
)), menu
);
1427 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomOut
)), menu
);
1428 menu
->addSeparator();
1431 added
= addActionToMenu(ac
->action("view_mode"), menu
) |
1432 addActionToMenu(ac
->action("sort"), menu
) |
1433 addActionToMenu(ac
->action("additional_info"), menu
) |
1434 addActionToMenu(ac
->action("show_preview"), menu
) |
1435 addActionToMenu(ac
->action("show_in_groups"), menu
) |
1436 addActionToMenu(ac
->action("show_hidden_files"), menu
);
1439 menu
->addSeparator();
1442 added
= addActionToMenu(ac
->action("split_view"), menu
) |
1443 addActionToMenu(ac
->action("reload"), menu
) |
1444 addActionToMenu(ac
->action("view_properties"), menu
);
1446 menu
->addSeparator();
1449 addActionToMenu(ac
->action("panels"), menu
);
1450 KMenu
* locationBarMenu
= new KMenu(i18nc("@action:inmenu", "Location Bar"), menu
);
1451 locationBarMenu
->addAction(ac
->action("editable_location"));
1452 locationBarMenu
->addAction(ac
->action("replace_location"));
1453 menu
->addMenu(locationBarMenu
);
1455 menu
->addSeparator();
1458 KMenu
* goMenu
= new KMenu(i18nc("@action:inmenu", "Go"), menu
);
1459 connect(menu
, SIGNAL(aboutToHide()), goMenu
, SLOT(deleteLater()));
1460 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Back
)));
1461 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Forward
)));
1462 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Up
)));
1463 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Home
)));
1464 goMenu
->addAction(ac
->action("closed_tabs"));
1465 menu
->addMenu(goMenu
);
1468 KMenu
* toolsMenu
= new KMenu(i18nc("@action:inmenu", "Tools"), menu
);
1469 connect(menu
, SIGNAL(aboutToHide()), toolsMenu
, SLOT(deleteLater()));
1470 toolsMenu
->addAction(ac
->action("show_filter_bar"));
1471 toolsMenu
->addAction(ac
->action("compare_files"));
1472 toolsMenu
->addAction(ac
->action("open_terminal"));
1473 toolsMenu
->addAction(ac
->action("change_remote_encoding"));
1474 menu
->addMenu(toolsMenu
);
1476 // Add "Settings" menu entries
1477 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::KeyBindings
)), menu
);
1478 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ConfigureToolbars
)), menu
);
1479 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Preferences
)), menu
);
1482 KMenu
* helpMenu
= new KMenu(i18nc("@action:inmenu", "Help"), menu
);
1483 connect(menu
, SIGNAL(aboutToHide()), helpMenu
, SLOT(deleteLater()));
1484 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::HelpContents
)));
1485 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::WhatsThis
)));
1486 helpMenu
->addSeparator();
1487 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ReportBug
)));
1488 helpMenu
->addSeparator();
1489 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
)));
1490 helpMenu
->addSeparator();
1491 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::AboutApp
)));
1492 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::AboutKDE
)));
1493 menu
->addMenu(helpMenu
);
1495 menu
->addSeparator();
1496 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ShowMenubar
)), menu
);
1499 void DolphinMainWindow::updateToolBar()
1501 if (!menuBar()->isVisible()) {
1502 createToolBarMenuButton();
1506 void DolphinMainWindow::slotToolBarSpacerDeleted()
1508 m_toolBarSpacer
= 0;
1509 m_updateToolBarTimer
->start();
1512 void DolphinMainWindow::slotToolBarMenuButtonDeleted()
1514 m_openToolBarMenuButton
= 0;
1515 m_updateToolBarTimer
->start();
1518 void DolphinMainWindow::slotToolBarIconSizeChanged(const QSize
& iconSize
)
1520 if (m_openToolBarMenuButton
) {
1521 m_openToolBarMenuButton
->setIconSize(iconSize
);
1525 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer
* viewContainer
)
1527 Q_ASSERT(viewContainer
);
1528 Q_ASSERT((viewContainer
== m_viewTab
[m_tabIndex
].primaryView
) ||
1529 (viewContainer
== m_viewTab
[m_tabIndex
].secondaryView
));
1530 if (m_activeViewContainer
== viewContainer
) {
1534 m_activeViewContainer
->setActive(false);
1535 m_activeViewContainer
= viewContainer
;
1537 // Activating the view container might trigger a recursive setActiveViewContainer() call
1538 // inside DolphinMainWindow::toggleActiveView() when having a split view. Temporary
1539 // disconnect the activated() signal in this case:
1540 disconnect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1541 m_activeViewContainer
->setActive(true);
1542 connect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1544 m_actionHandler
->setCurrentView(viewContainer
->view());
1547 updateEditActions();
1548 updateViewActions();
1551 const KUrl url
= m_activeViewContainer
->url();
1552 setUrlAsCaption(url
);
1553 if (m_viewTab
.count() > 1) {
1554 m_tabBar
->setTabText(m_tabIndex
, tabName(url
));
1555 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(KMimeType::iconNameForUrl(url
)));
1558 emit
urlChanged(url
);
1561 DolphinViewContainer
* DolphinMainWindow::createViewContainer(const KUrl
& url
, QWidget
* parent
)
1563 DolphinViewContainer
* container
= new DolphinViewContainer(url
, parent
);
1565 // The places-selector from the URL navigator should only be shown
1566 // if the places dock is invisible
1567 QDockWidget
* placesDock
= findChild
<QDockWidget
*>("placesDock");
1568 container
->urlNavigator()->setPlacesSelectorVisible(!placesDock
|| !placesDock
->isVisible());
1573 void DolphinMainWindow::setupActions()
1575 // setup 'File' menu
1576 m_newFileMenu
= new DolphinNewFileMenu(this);
1577 KMenu
* menu
= m_newFileMenu
->menu();
1578 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1579 menu
->setIcon(KIcon("document-new"));
1580 connect(menu
, SIGNAL(aboutToShow()),
1581 this, SLOT(updateNewMenu()));
1583 KAction
* newWindow
= actionCollection()->addAction("new_window");
1584 newWindow
->setIcon(KIcon("window-new"));
1585 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1586 newWindow
->setShortcut(Qt::CTRL
| Qt::Key_N
);
1587 connect(newWindow
, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1589 KAction
* newTab
= actionCollection()->addAction("new_tab");
1590 newTab
->setIcon(KIcon("tab-new"));
1591 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1592 newTab
->setShortcut(KShortcut(Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
));
1593 connect(newTab
, SIGNAL(triggered()), this, SLOT(openNewTab()));
1595 KAction
* closeTab
= actionCollection()->addAction("close_tab");
1596 closeTab
->setIcon(KIcon("tab-close"));
1597 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1598 closeTab
->setShortcut(Qt::CTRL
| Qt::Key_W
);
1599 closeTab
->setEnabled(false);
1600 connect(closeTab
, SIGNAL(triggered()), this, SLOT(closeTab()));
1602 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1604 // setup 'Edit' menu
1605 KStandardAction::undo(this,
1607 actionCollection());
1609 // need to remove shift+del from cut action, else the shortcut for deletejob
1611 KAction
* cut
= KStandardAction::cut(this, SLOT(cut()), actionCollection());
1612 KShortcut cutShortcut
= cut
->shortcut();
1613 cutShortcut
.remove(Qt::SHIFT
| Qt::Key_Delete
, KShortcut::KeepEmpty
);
1614 cut
->setShortcut(cutShortcut
);
1615 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1616 KAction
* paste
= KStandardAction::paste(this, SLOT(paste()), actionCollection());
1617 // The text of the paste-action is modified dynamically by Dolphin
1618 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1619 // due to the long text, the text "Paste" is used:
1620 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1622 KStandardAction::find(this, SLOT(find()), actionCollection());
1624 KAction
* selectAll
= actionCollection()->addAction("select_all");
1625 selectAll
->setText(i18nc("@action:inmenu Edit", "Select All"));
1626 selectAll
->setShortcut(Qt::CTRL
| Qt::Key_A
);
1627 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
1629 KAction
* invertSelection
= actionCollection()->addAction("invert_selection");
1630 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1631 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1632 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
1634 // setup 'View' menu
1635 // (note that most of it is set up in DolphinViewActionHandler)
1637 KAction
* split
= actionCollection()->addAction("split_view");
1638 split
->setShortcut(Qt::Key_F3
);
1639 updateSplitAction();
1640 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1642 KAction
* reload
= actionCollection()->addAction("reload");
1643 reload
->setText(i18nc("@action:inmenu View", "Reload"));
1644 reload
->setShortcut(Qt::Key_F5
);
1645 reload
->setIcon(KIcon("view-refresh"));
1646 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
1648 KAction
* stop
= actionCollection()->addAction("stop");
1649 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1650 stop
->setToolTip(i18nc("@info", "Stop loading"));
1651 stop
->setIcon(KIcon("process-stop"));
1652 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
1654 KToggleAction
* editableLocation
= actionCollection()->add
<KToggleAction
>("editable_location");
1655 editableLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1656 editableLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
1657 connect(editableLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1659 KAction
* replaceLocation
= actionCollection()->addAction("replace_location");
1660 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1661 replaceLocation
->setShortcut(Qt::Key_F6
);
1662 connect(replaceLocation
, SIGNAL(triggered()), this, SLOT(replaceLocation()));
1665 KAction
* backAction
= KStandardAction::back(this, SLOT(goBack()), actionCollection());
1666 connect(backAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goBack(Qt::MouseButtons
)));
1667 KShortcut backShortcut
= backAction
->shortcut();
1668 backShortcut
.setAlternate(Qt::Key_Backspace
);
1669 backAction
->setShortcut(backShortcut
);
1671 m_recentTabsMenu
= new KActionMenu(i18n("Recently Closed Tabs"), this);
1672 m_recentTabsMenu
->setIcon(KIcon("edit-undo"));
1673 actionCollection()->addAction("closed_tabs", m_recentTabsMenu
);
1674 connect(m_recentTabsMenu
->menu(), SIGNAL(triggered(QAction
*)),
1675 this, SLOT(restoreClosedTab(QAction
*)));
1677 QAction
* action
= new QAction(i18n("Empty Recently Closed Tabs"), m_recentTabsMenu
);
1678 action
->setIcon(KIcon("edit-clear-list"));
1679 action
->setData(QVariant::fromValue(true));
1680 m_recentTabsMenu
->addAction(action
);
1681 m_recentTabsMenu
->addSeparator();
1682 m_recentTabsMenu
->setEnabled(false);
1684 KAction
* forwardAction
= KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1685 connect(forwardAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goForward(Qt::MouseButtons
)));
1687 KAction
* upAction
= KStandardAction::up(this, SLOT(goUp()), actionCollection());
1688 connect(upAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goUp(Qt::MouseButtons
)));
1690 KStandardAction::home(this, SLOT(goHome()), actionCollection());
1692 // setup 'Tools' menu
1693 KAction
* showFilterBar
= actionCollection()->addAction("show_filter_bar");
1694 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1695 showFilterBar
->setIcon(KIcon("view-filter"));
1696 showFilterBar
->setShortcut(Qt::CTRL
| Qt::Key_I
);
1697 connect(showFilterBar
, SIGNAL(triggered()), this, SLOT(showFilterBar()));
1699 KAction
* compareFiles
= actionCollection()->addAction("compare_files");
1700 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1701 compareFiles
->setIcon(KIcon("kompare"));
1702 compareFiles
->setEnabled(false);
1703 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
1705 KAction
* openTerminal
= actionCollection()->addAction("open_terminal");
1706 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1707 openTerminal
->setIcon(KIcon("utilities-terminal"));
1708 openTerminal
->setShortcut(Qt::SHIFT
| Qt::Key_F4
);
1709 connect(openTerminal
, SIGNAL(triggered()), this, SLOT(openTerminal()));
1711 // setup 'Settings' menu
1712 KStandardAction::showMenubar(this, SLOT(toggleShowMenuBar()), actionCollection());
1713 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1715 // not in menu actions
1716 QList
<QKeySequence
> nextTabKeys
;
1717 nextTabKeys
.append(KStandardShortcut::tabNext().primary());
1718 nextTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::Key_Tab
));
1720 QList
<QKeySequence
> prevTabKeys
;
1721 prevTabKeys
.append(KStandardShortcut::tabPrev().primary());
1722 prevTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::SHIFT
| Qt::Key_Tab
));
1724 KAction
* activateNextTab
= actionCollection()->addAction("activate_next_tab");
1725 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1726 connect(activateNextTab
, SIGNAL(triggered()), SLOT(activateNextTab()));
1727 activateNextTab
->setShortcuts(QApplication::isRightToLeft() ? prevTabKeys
: nextTabKeys
);
1729 KAction
* activatePrevTab
= actionCollection()->addAction("activate_prev_tab");
1730 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1731 connect(activatePrevTab
, SIGNAL(triggered()), SLOT(activatePrevTab()));
1732 activatePrevTab
->setShortcuts(QApplication::isRightToLeft() ? nextTabKeys
: prevTabKeys
);
1735 KAction
* openInNewTab
= actionCollection()->addAction("open_in_new_tab");
1736 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1737 openInNewTab
->setIcon(KIcon("tab-new"));
1738 connect(openInNewTab
, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1740 KAction
* openInNewWindow
= actionCollection()->addAction("open_in_new_window");
1741 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1742 openInNewWindow
->setIcon(KIcon("window-new"));
1743 connect(openInNewWindow
, SIGNAL(triggered()), this, SLOT(openInNewWindow()));
1746 void DolphinMainWindow::setupDockWidgets()
1748 const bool lock
= DolphinSettings::instance().generalSettings()->lockPanels();
1750 KDualAction
* lockLayoutAction
= actionCollection()->add
<KDualAction
>("lock_panels");
1751 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
1752 lockLayoutAction
->setActiveIcon(KIcon("object-unlocked"));
1753 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
1754 lockLayoutAction
->setInactiveIcon(KIcon("object-locked"));
1755 lockLayoutAction
->setActive(lock
);
1756 connect(lockLayoutAction
, SIGNAL(triggered()), this, SLOT(togglePanelLockState()));
1758 // Setup "Information"
1759 DolphinDockWidget
* infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
1760 infoDock
->setLocked(lock
);
1761 infoDock
->setObjectName("infoDock");
1762 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1763 Panel
* infoPanel
= new InformationPanel(infoDock
);
1764 infoPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1765 connect(infoPanel
, SIGNAL(urlActivated(KUrl
)), this, SLOT(handleUrl(KUrl
)));
1766 infoDock
->setWidget(infoPanel
);
1768 QAction
* infoAction
= infoDock
->toggleViewAction();
1769 infoAction
->setIcon(KIcon("dialog-information"));
1770 infoAction
->setShortcut(Qt::Key_F11
);
1771 addActionCloneToCollection(infoAction
, "show_information_panel");
1773 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1774 connect(this, SIGNAL(urlChanged(KUrl
)),
1775 infoPanel
, SLOT(setUrl(KUrl
)));
1776 connect(this, SIGNAL(selectionChanged(KFileItemList
)),
1777 infoPanel
, SLOT(setSelection(KFileItemList
)));
1778 connect(this, SIGNAL(requestItemInfo(KFileItem
)),
1779 infoPanel
, SLOT(requestDelayedItemInfo(KFileItem
)));
1782 DolphinDockWidget
* foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
1783 foldersDock
->setLocked(lock
);
1784 foldersDock
->setObjectName("foldersDock");
1785 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1786 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1787 foldersPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1788 foldersDock
->setWidget(foldersPanel
);
1790 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1791 foldersAction
->setShortcut(Qt::Key_F7
);
1792 foldersAction
->setIcon(KIcon("folder"));
1793 addActionCloneToCollection(foldersAction
, "show_folders_panel");
1795 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1796 connect(this, SIGNAL(urlChanged(KUrl
)),
1797 foldersPanel
, SLOT(setUrl(KUrl
)));
1798 connect(foldersPanel
, SIGNAL(changeUrl(KUrl
,Qt::MouseButtons
)),
1799 this, SLOT(handlePlacesClick(KUrl
,Qt::MouseButtons
)));
1803 DolphinDockWidget
* terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1804 terminalDock
->setLocked(lock
);
1805 terminalDock
->setObjectName("terminalDock");
1806 terminalDock
->setAllowedAreas(Qt::TopDockWidgetArea
| Qt::BottomDockWidgetArea
);
1807 Panel
* terminalPanel
= new TerminalPanel(terminalDock
);
1808 terminalPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1809 terminalDock
->setWidget(terminalPanel
);
1811 connect(terminalPanel
, SIGNAL(hideTerminalPanel()), terminalDock
, SLOT(hide()));
1812 connect(terminalDock
, SIGNAL(visibilityChanged(bool)),
1813 terminalPanel
, SLOT(dockVisibilityChanged()));
1815 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1816 terminalAction
->setShortcut(Qt::Key_F4
);
1817 terminalAction
->setIcon(KIcon("utilities-terminal"));
1818 addActionCloneToCollection(terminalAction
, "show_terminal_panel");
1820 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1821 connect(this, SIGNAL(urlChanged(KUrl
)),
1822 terminalPanel
, SLOT(setUrl(KUrl
)));
1827 DolphinDockWidget
* searchDock
= new DolphinDockWidget(i18nc("@title:window", "Search"));
1828 searchDock
->setLocked(lock
);
1829 searchDock
->setObjectName("searchDock");
1830 searchDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1831 Panel
* searchPanel
= new SearchPanel(searchDock
);
1832 searchPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1833 connect(searchPanel
, SIGNAL(urlActivated(KUrl
)), this, SLOT(handleUrl(KUrl
)));
1834 searchDock
->setWidget(searchPanel
);
1836 QAction
* searchAction
= searchDock
->toggleViewAction();
1837 searchAction
->setShortcut(Qt::Key_F12
);
1838 searchAction
->setIcon(KIcon("system-search"));
1839 addActionCloneToCollection(searchAction
, "show_search_panel");
1840 addDockWidget(Qt::RightDockWidgetArea
, searchDock
);
1841 connect(this, SIGNAL(urlChanged(KUrl
)),
1842 searchPanel
, SLOT(setUrl(KUrl
)));
1845 if (DolphinSettings::instance().generalSettings()->version() < 200) {
1847 foldersDock
->hide();
1849 terminalDock
->hide();
1857 DolphinDockWidget
* placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
1858 placesDock
->setLocked(lock
);
1859 placesDock
->setObjectName("placesDock");
1860 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1862 PlacesPanel
* placesPanel
= new PlacesPanel(placesDock
);
1863 QAction
* separator
= new QAction(placesPanel
);
1864 separator
->setSeparator(true);
1865 QList
<QAction
*> placesActions
;
1866 placesActions
.append(separator
);
1867 placesActions
.append(lockLayoutAction
);
1868 placesPanel
->addActions(placesActions
);
1869 placesPanel
->setModel(DolphinSettings::instance().placesModel());
1870 placesPanel
->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff
);
1871 placesDock
->setWidget(placesPanel
);
1873 QAction
* placesAction
= placesDock
->toggleViewAction();
1874 placesAction
->setShortcut(Qt::Key_F9
);
1875 placesAction
->setIcon(KIcon("bookmarks"));
1876 addActionCloneToCollection(placesAction
, "show_places_panel");
1878 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1879 connect(placesPanel
, SIGNAL(urlChanged(KUrl
,Qt::MouseButtons
)),
1880 this, SLOT(handlePlacesClick(KUrl
,Qt::MouseButtons
)));
1881 connect(this, SIGNAL(urlChanged(KUrl
)),
1882 placesPanel
, SLOT(setUrl(KUrl
)));
1883 connect(placesDock
, SIGNAL(visibilityChanged(bool)),
1884 this, SLOT(slotPlacesPanelVisibilityChanged(bool)));
1886 // Add actions into the "Panels" menu
1887 KActionMenu
* panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Panels"), this);
1888 actionCollection()->addAction("panels", panelsMenu
);
1889 panelsMenu
->setDelayed(false);
1890 panelsMenu
->addAction(placesAction
);
1891 panelsMenu
->addAction(infoAction
);
1892 panelsMenu
->addAction(foldersAction
);
1894 panelsMenu
->addAction(terminalAction
);
1897 panelsMenu
->addAction(searchAction
);
1899 panelsMenu
->addSeparator();
1900 panelsMenu
->addAction(lockLayoutAction
);
1903 void DolphinMainWindow::updateEditActions()
1905 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1906 if (list
.isEmpty()) {
1907 stateChanged("has_no_selection");
1909 stateChanged("has_selection");
1911 KActionCollection
* col
= actionCollection();
1912 QAction
* renameAction
= col
->action("rename");
1913 QAction
* moveToTrashAction
= col
->action("move_to_trash");
1914 QAction
* deleteAction
= col
->action("delete");
1915 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
1916 QAction
* deleteWithTrashShortcut
= col
->action("delete_shortcut"); // see DolphinViewActionHandler
1918 KFileItemListProperties
capabilities(list
);
1919 const bool enableMoveToTrash
= capabilities
.isLocal() && capabilities
.supportsMoving();
1921 renameAction
->setEnabled(capabilities
.supportsMoving());
1922 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1923 deleteAction
->setEnabled(capabilities
.supportsDeleting());
1924 deleteWithTrashShortcut
->setEnabled(capabilities
.supportsDeleting() && !enableMoveToTrash
);
1925 cutAction
->setEnabled(capabilities
.supportsMoving());
1927 updatePasteAction();
1930 void DolphinMainWindow::updateViewActions()
1932 m_actionHandler
->updateViewActions();
1934 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1935 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
1937 updateSplitAction();
1939 QAction
* editableLocactionAction
= actionCollection()->action("editable_location");
1940 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
1941 editableLocactionAction
->setChecked(urlNavigator
->isUrlEditable());
1944 void DolphinMainWindow::updateGoActions()
1946 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
1947 const KUrl currentUrl
= m_activeViewContainer
->url();
1948 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
1951 void DolphinMainWindow::createToolBarMenuButton()
1953 if (m_toolBarSpacer
&& m_openToolBarMenuButton
) {
1956 Q_ASSERT(!m_toolBarSpacer
);
1957 Q_ASSERT(!m_openToolBarMenuButton
);
1959 m_toolBarSpacer
= new QWidget(this);
1960 m_toolBarSpacer
->setSizePolicy(QSizePolicy::MinimumExpanding
, QSizePolicy::MinimumExpanding
);
1962 m_openToolBarMenuButton
= new QToolButton(this);
1963 m_openToolBarMenuButton
->setIcon(KIcon("configure"));
1964 m_openToolBarMenuButton
->setPopupMode(QToolButton::InstantPopup
);
1965 m_openToolBarMenuButton
->setToolTip(i18nc("@info:tooltip", "Configure and control Dolphin"));
1967 KMenu
* toolBarMenu
= new ToolBarMenu(m_openToolBarMenuButton
);
1968 connect(toolBarMenu
, SIGNAL(aboutToShow()), this, SLOT(updateToolBarMenu()));
1970 m_openToolBarMenuButton
->setMenu(toolBarMenu
);
1972 toolBar()->addWidget(m_toolBarSpacer
);
1973 toolBar()->addWidget(m_openToolBarMenuButton
);
1974 connect(toolBar(), SIGNAL(iconSizeChanged(QSize
)), this, SLOT(slotToolBarIconSizeChanged(QSize
)));
1976 // The added widgets are owned by the toolbar and may get deleted when e.g. the toolbar
1977 // gets edited. In this case we must add them again. The adding is done asynchronously by
1978 // m_updateToolBarTimer.
1979 connect(m_toolBarSpacer
, SIGNAL(destroyed()), this, SLOT(slotToolBarSpacerDeleted()));
1980 connect(m_openToolBarMenuButton
, SIGNAL(destroyed()), this, SLOT(slotToolBarMenuButtonDeleted()));
1981 m_updateToolBarTimer
= new QTimer(this);
1982 m_updateToolBarTimer
->setInterval(500);
1983 connect(m_updateToolBarTimer
, SIGNAL(timeout()), this, SLOT(updateToolBar()));
1986 void DolphinMainWindow::deleteToolBarMenuButton()
1988 delete m_toolBarSpacer
;
1989 m_toolBarSpacer
= 0;
1991 delete m_openToolBarMenuButton
;
1992 m_openToolBarMenuButton
= 0;
1994 delete m_updateToolBarTimer
;
1995 m_updateToolBarTimer
= 0;
1998 bool DolphinMainWindow::addActionToMenu(QAction
* action
, KMenu
* menu
)
2003 const KToolBar
* toolBarWidget
= toolBar();
2004 foreach (const QWidget
* widget
, action
->associatedWidgets()) {
2005 if (widget
== toolBarWidget
) {
2010 menu
->addAction(action
);
2014 void DolphinMainWindow::rememberClosedTab(int index
)
2016 KMenu
* tabsMenu
= m_recentTabsMenu
->menu();
2018 const QString primaryPath
= m_viewTab
[index
].primaryView
->url().path();
2019 const QString iconName
= KMimeType::iconNameForUrl(primaryPath
);
2021 QAction
* action
= new QAction(squeezedText(primaryPath
), tabsMenu
);
2023 ClosedTab closedTab
;
2024 closedTab
.primaryUrl
= m_viewTab
[index
].primaryView
->url();
2026 if (m_viewTab
[index
].secondaryView
) {
2027 closedTab
.secondaryUrl
= m_viewTab
[index
].secondaryView
->url();
2028 closedTab
.isSplit
= true;
2030 closedTab
.isSplit
= false;
2033 action
->setData(QVariant::fromValue(closedTab
));
2034 action
->setIcon(KIcon(iconName
));
2036 // add the closed tab menu entry after the separator and
2037 // "Empty Recently Closed Tabs" entry
2038 if (tabsMenu
->actions().size() == 2) {
2039 tabsMenu
->addAction(action
);
2041 tabsMenu
->insertAction(tabsMenu
->actions().at(2), action
);
2044 // assure that only up to 8 closed tabs are shown in the menu
2045 if (tabsMenu
->actions().size() > 8) {
2046 tabsMenu
->removeAction(tabsMenu
->actions().last());
2048 actionCollection()->action("closed_tabs")->setEnabled(true);
2049 KAcceleratorManager::manage(tabsMenu
);
2052 void DolphinMainWindow::refreshViews()
2054 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
2056 // remember the current active view, as because of
2057 // the refreshing the active view might change to
2058 // the secondary view
2059 DolphinViewContainer
* activeViewContainer
= m_activeViewContainer
;
2061 const int tabCount
= m_viewTab
.count();
2062 for (int i
= 0; i
< tabCount
; ++i
) {
2063 m_viewTab
[i
].primaryView
->refresh();
2064 if (m_viewTab
[i
].secondaryView
) {
2065 m_viewTab
[i
].secondaryView
->refresh();
2069 setActiveViewContainer(activeViewContainer
);
2071 const GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
2072 if (generalSettings
->modifiedStartupSettings()) {
2073 // The startup settings have been changed by the user (see bug #254947).
2074 // Synchronize the split-view setting with the active view:
2075 const bool splitView
= generalSettings
->splitView();
2076 const ViewTab
& activeTab
= m_viewTab
[m_tabIndex
];
2077 const bool toggle
= ( splitView
&& !activeTab
.secondaryView
)
2078 || (!splitView
&& activeTab
.secondaryView
);
2085 void DolphinMainWindow::clearStatusBar()
2087 m_activeViewContainer
->statusBar()->clear();
2090 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
2092 connect(container
, SIGNAL(showFilterBarChanged(bool)),
2093 this, SLOT(updateFilterBarAction(bool)));
2094 connect(container
, SIGNAL(writeStateChanged(bool)),
2095 this, SLOT(slotWriteStateChanged(bool)));
2096 connect(container
, SIGNAL(searchModeChanged(bool)),
2097 this, SLOT(slotSearchModeChanged(bool)));
2099 const DolphinSearchBox
* searchBox
= container
->searchBox();
2100 connect(searchBox
, SIGNAL(searchLocationChanged(SearchLocation
)),
2101 this, SLOT(slotSearchLocationChanged()));
2103 DolphinView
* view
= container
->view();
2104 connect(view
, SIGNAL(selectionChanged(KFileItemList
)),
2105 this, SLOT(slotSelectionChanged(KFileItemList
)));
2106 connect(view
, SIGNAL(requestItemInfo(KFileItem
)),
2107 this, SLOT(slotRequestItemInfo(KFileItem
)));
2108 connect(view
, SIGNAL(activated()),
2109 this, SLOT(toggleActiveView()));
2110 connect(view
, SIGNAL(tabRequested(KUrl
)),
2111 this, SLOT(openNewTab(KUrl
)));
2112 connect(view
, SIGNAL(requestContextMenu(KFileItem
,KUrl
,QList
<QAction
*>)),
2113 this, SLOT(openContextMenu(KFileItem
,KUrl
,QList
<QAction
*>)));
2114 connect(view
, SIGNAL(startedPathLoading(KUrl
)),
2115 this, SLOT(enableStopAction()));
2116 connect(view
, SIGNAL(finishedPathLoading(KUrl
)),
2117 this, SLOT(disableStopAction()));
2119 const KUrlNavigator
* navigator
= container
->urlNavigator();
2120 connect(navigator
, SIGNAL(urlChanged(KUrl
)),
2121 this, SLOT(changeUrl(KUrl
)));
2122 connect(navigator
, SIGNAL(historyChanged()),
2123 this, SLOT(updateHistory()));
2124 connect(navigator
, SIGNAL(editableStateChanged(bool)),
2125 this, SLOT(slotEditableStateChanged(bool)));
2126 connect(navigator
, SIGNAL(tabRequested(KUrl
)),
2127 this, SLOT(openNewTab(KUrl
)));
2130 void DolphinMainWindow::updateSplitAction()
2132 QAction
* splitAction
= actionCollection()->action("split_view");
2133 if (m_viewTab
[m_tabIndex
].secondaryView
) {
2134 if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
2135 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
2136 splitAction
->setToolTip(i18nc("@info", "Close right view"));
2137 splitAction
->setIcon(KIcon("view-right-close"));
2139 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
2140 splitAction
->setToolTip(i18nc("@info", "Close left view"));
2141 splitAction
->setIcon(KIcon("view-left-close"));
2144 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
2145 splitAction
->setToolTip(i18nc("@info", "Split view"));
2146 splitAction
->setIcon(KIcon("view-right-new"));
2150 QString
DolphinMainWindow::tabName(const KUrl
& url
) const
2153 if (url
.equals(KUrl("file:///"))) {
2156 name
= url
.fileName();
2157 if (name
.isEmpty()) {
2158 name
= url
.protocol();
2160 // Make sure that a '&' inside the directory name is displayed correctly
2161 // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
2162 name
.replace('&', "&&");
2168 bool DolphinMainWindow::isKompareInstalled() const
2170 static bool initialized
= false;
2171 static bool installed
= false;
2173 // TODO: maybe replace this approach later by using a menu
2174 // plugin like kdiff3plugin.cpp
2175 installed
= !KGlobal::dirs()->findExe("kompare").isEmpty();
2181 void DolphinMainWindow::createSecondaryView(int tabIndex
)
2183 QSplitter
* splitter
= m_viewTab
[tabIndex
].splitter
;
2184 const int newWidth
= (m_viewTab
[tabIndex
].primaryView
->width() - splitter
->handleWidth()) / 2;
2186 const DolphinView
* view
= m_viewTab
[tabIndex
].primaryView
->view();
2187 m_viewTab
[tabIndex
].secondaryView
= createViewContainer(view
->url(), 0);
2188 splitter
->addWidget(m_viewTab
[tabIndex
].secondaryView
);
2189 splitter
->setSizes(QList
<int>() << newWidth
<< newWidth
);
2190 connectViewSignals(m_viewTab
[tabIndex
].secondaryView
);
2191 m_viewTab
[tabIndex
].secondaryView
->setActive(false);
2192 m_viewTab
[tabIndex
].secondaryView
->show();
2195 QString
DolphinMainWindow::tabProperty(const QString
& property
, int tabIndex
) const
2197 return "Tab " + QString::number(tabIndex
) + ' ' + property
;
2200 void DolphinMainWindow::setUrlAsCaption(const KUrl
& url
)
2203 if (!url
.isLocalFile()) {
2204 caption
.append(url
.protocol() + " - ");
2205 if (url
.hasHost()) {
2206 caption
.append(url
.host() + " - ");
2210 const QString fileName
= url
.fileName().isEmpty() ? "/" : url
.fileName();
2211 caption
.append(fileName
);
2213 setCaption(caption
);
2216 QString
DolphinMainWindow::squeezedText(const QString
& text
) const
2218 const QFontMetrics fm
= fontMetrics();
2219 return fm
.elidedText(text
, Qt::ElideMiddle
, fm
.maxWidth() * 10);
2222 void DolphinMainWindow::addActionCloneToCollection(QAction
* action
, const QString
& actionName
)
2224 KAction
* actionClone
= actionCollection()->addAction(actionName
);
2225 actionClone
->setText(action
->text());
2226 actionClone
->setIcon(action
->icon());
2227 connect(actionClone
, SIGNAL(triggered()), action
, SLOT(trigger()));
2230 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
2231 KIO::FileUndoManager::UiInterface()
2235 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2239 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
2241 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
2243 DolphinStatusBar
* statusBar
= mainWin
->activeViewContainer()->statusBar();
2244 statusBar
->setMessage(job
->errorString(), DolphinStatusBar::Error
);
2246 KIO::FileUndoManager::UiInterface::jobError(job
);
2250 ToolBarMenu::ToolBarMenu(QWidget
* parent
) :
2255 ToolBarMenu::~ToolBarMenu()
2259 void ToolBarMenu::showEvent(QShowEvent
* event
)
2261 KMenu::showEvent(event
);
2263 // Adjust the position of the menu to be shown within the
2264 // Dolphin window to reduce the cases that sub-menus might overlap
2265 // the right screen border.
2267 QWidget
* button
= parentWidget();
2268 if (layoutDirection() == Qt::RightToLeft
) {
2269 pos
= button
->mapToGlobal(QPoint(0, button
->height()));
2271 pos
= button
->mapToGlobal(QPoint(button
->width(), button
->height()));
2272 pos
.rx() -= width();
2275 // Assure that the menu is not shown outside the screen boundaries and
2276 // that it does not overlap with the parent button.
2277 const QRect screen
= QApplication::desktop()->screenGeometry(QCursor::pos());
2278 if (pos
.x() < screen
.x()) {
2279 pos
.rx() = screen
.x();
2280 } else if (pos
.x() + width() > screen
.x() + screen
.width()) {
2281 pos
.rx() = screen
.x() + screen
.width() - width();
2284 if (pos
.y() < screen
.y()) {
2285 pos
.ry() = screen
.y();
2286 } else if (pos
.y() + height() > screen
.y() + screen
.height()) {
2287 pos
.ry() = button
->mapToGlobal(QPoint(0, 0)).y() - height();
2293 #include "dolphinmainwindow.moc"