]>
cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.cpp
0bc6e569c2ad27b1ff38792aa55413857086dfee
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> *
3 * Copyright (C) 2006 by Stefan Monov <logixoul@gmail.com> *
4 * Copyright (C) 2006 by Cvetoslav Ludmiloff <ludmiloff@gmail.com> *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20 ***************************************************************************/
22 #include "dolphinmainwindow.h"
23 #include "dolphinviewactionhandler.h"
24 #include "dolphindropcontroller.h"
26 #include <config-nepomuk.h>
28 #include "dolphinapplication.h"
29 #include "dolphinfileplacesview.h"
30 #include "dolphinnewmenu.h"
31 #include "dolphinsettings.h"
32 #include "dolphinsettingsdialog.h"
33 #include "dolphinstatusbar.h"
34 #include "dolphinviewcontainer.h"
35 #include "infosidebarpage.h"
36 #include "metadatawidget.h"
37 #include "mainwindowadaptor.h"
38 #include "treeviewsidebarpage.h"
39 #include "viewpropertiesdialog.h"
40 #include "viewproperties.h"
43 #include "terminalsidebarpage.h"
46 #include "dolphin_generalsettings.h"
47 #include "dolphin_iconsmodesettings.h"
50 #include <kactioncollection.h>
52 #include <kdesktopfile.h>
53 #include <kdeversion.h>
54 #include <kfiledialog.h>
55 #include <kfileplacesmodel.h>
58 #include <kiconloader.h>
59 #include <kio/netaccess.h>
60 #include <kinputdialog.h>
64 #include <kmessagebox.h>
65 #include <kurlnavigator.h>
66 #include <konqmimedata.h>
67 #include <kpropertiesdialog.h>
68 #include <kprotocolinfo.h>
69 #include <ktoggleaction.h>
72 #include <kstandarddirs.h>
73 #include <kstatusbar.h>
74 #include <kstandardaction.h>
76 #include <kurlcombobox.h>
82 #include <QDockWidget>
84 DolphinMainWindow::DolphinMainWindow(int id
) :
89 m_activeViewContainer(0),
92 setObjectName("Dolphin");
93 m_viewContainer
[PrimaryView
] = 0;
94 m_viewContainer
[SecondaryView
] = 0;
96 new MainWindowAdaptor(this);
97 QDBusConnection::sessionBus().registerObject(QString("/dolphin/MainWindow%1").arg(m_id
), this);
99 KonqFileUndoManager::incRef();
101 KonqFileUndoManager
* undoManager
= KonqFileUndoManager::self();
102 undoManager
->setUiInterface(new UndoUiInterface(this));
104 connect(undoManager
, SIGNAL(undoAvailable(bool)),
105 this, SLOT(slotUndoAvailable(bool)));
106 connect(undoManager
, SIGNAL(undoTextChanged(const QString
&)),
107 this, SLOT(slotUndoTextChanged(const QString
&)));
108 connect(DolphinSettings::instance().placesModel(), SIGNAL(errorMessage(const QString
&)),
109 this, SLOT(slotHandlePlacesError(const QString
&)));
112 DolphinMainWindow::~DolphinMainWindow()
114 KonqFileUndoManager::decRef();
115 DolphinApplication::app()->removeMainWindow(this);
118 void DolphinMainWindow::toggleViews()
120 if (m_viewContainer
[SecondaryView
] == 0) {
124 // move secondary view from the last position of the splitter
125 // to the first position
126 m_splitter
->insertWidget(0, m_viewContainer
[SecondaryView
]);
128 DolphinViewContainer
* container
= m_viewContainer
[PrimaryView
];
129 m_viewContainer
[PrimaryView
] = m_viewContainer
[SecondaryView
];
130 m_viewContainer
[SecondaryView
] = container
;
133 void DolphinMainWindow::slotDoingOperation(KonqFileUndoManager::CommandType commandType
)
136 m_undoCommandTypes
.append(commandType
);
139 void DolphinMainWindow::refreshViews()
141 Q_ASSERT(m_viewContainer
[PrimaryView
] != 0);
143 // remember the current active view, as because of
144 // the refreshing the active view might change to
145 // the secondary view
146 DolphinViewContainer
* activeViewContainer
= m_activeViewContainer
;
148 m_viewContainer
[PrimaryView
]->view()->refresh();
149 if (m_viewContainer
[SecondaryView
] != 0) {
150 m_viewContainer
[SecondaryView
]->view()->refresh();
153 setActiveViewContainer(activeViewContainer
);
156 void DolphinMainWindow::dropUrls(const KUrl::List
& urls
,
157 const KUrl
& destination
)
159 DolphinDropController
dropController(this);
160 connect(&dropController
, SIGNAL(doingOperation(KonqFileUndoManager::CommandType
)),
161 this, SLOT(slotDoingOperation(KonqFileUndoManager::CommandType
)));
162 dropController
.dropUrls(urls
, destination
);
165 void DolphinMainWindow::changeUrl(const KUrl
& url
)
167 DolphinViewContainer
* view
= activeViewContainer();
173 setCaption(url
.fileName());
174 emit
urlChanged(url
);
178 void DolphinMainWindow::changeSelection(const KFileItemList
& selection
)
180 activeViewContainer()->view()->changeSelection(selection
);
183 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
185 KToggleAction
* editableLocationAction
=
186 static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
187 editableLocationAction
->setChecked(editable
);
190 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
194 Q_ASSERT(m_viewContainer
[PrimaryView
] != 0);
195 int selectedUrlsCount
= m_viewContainer
[PrimaryView
]->view()->selectedUrls().count();
196 if (m_viewContainer
[SecondaryView
] != 0) {
197 selectedUrlsCount
+= m_viewContainer
[SecondaryView
]->view()->selectedUrls().count();
200 QAction
* compareFilesAction
= actionCollection()->action("compare_files");
201 if (selectedUrlsCount
== 2) {
202 const bool kompareInstalled
= !KGlobal::dirs()->findExe("kompare").isEmpty();
203 compareFilesAction
->setEnabled(selectedUrlsCount
== 2 && kompareInstalled
);
205 compareFilesAction
->setEnabled(false);
208 m_activeViewContainer
->updateStatusBar();
210 emit
selectionChanged(selection
);
213 void DolphinMainWindow::slotRequestItemInfo(const KFileItem
& item
)
215 emit
requestItemInfo(item
);
218 void DolphinMainWindow::updateHistory()
220 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
221 const int index
= urlNavigator
->historyIndex();
223 QAction
* backAction
= actionCollection()->action("go_back");
224 if (backAction
!= 0) {
225 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
228 QAction
* forwardAction
= actionCollection()->action("go_forward");
229 if (forwardAction
!= 0) {
230 forwardAction
->setEnabled(index
> 0);
234 void DolphinMainWindow::updateFilterBarAction(bool show
)
236 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
237 showFilterBarAction
->setChecked(show
);
240 void DolphinMainWindow::openNewMainWindow()
242 DolphinApplication::app()->createMainWindow()->show();
245 void DolphinMainWindow::toggleActiveView()
247 if (m_viewContainer
[SecondaryView
] == 0) {
248 // only one view is available
252 Q_ASSERT(m_activeViewContainer
!= 0);
253 Q_ASSERT(m_viewContainer
[PrimaryView
] != 0);
255 DolphinViewContainer
* left
= m_viewContainer
[PrimaryView
];
256 DolphinViewContainer
* right
= m_viewContainer
[SecondaryView
];
257 setActiveViewContainer(m_activeViewContainer
== right
? left
: right
);
260 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
262 DolphinSettings
& settings
= DolphinSettings::instance();
263 GeneralSettings
* generalSettings
= settings
.generalSettings();
264 generalSettings
->setFirstRun(false);
268 KXmlGuiWindow::closeEvent(event
);
271 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
273 DolphinViewContainer
* cont
= m_viewContainer
[PrimaryView
];
274 group
.writeEntry("Primary Url", cont
->url().url());
275 group
.writeEntry("Primary Editable Url", cont
->isUrlEditable());
277 cont
= m_viewContainer
[SecondaryView
];
279 group
.writeEntry("Secondary Url", cont
->url().url());
280 group
.writeEntry("Secondary Editable Url", cont
->isUrlEditable());
284 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
286 DolphinViewContainer
* cont
= m_viewContainer
[PrimaryView
];
288 cont
->setUrl(group
.readEntry("Primary Url"));
289 bool editable
= group
.readEntry("Primary Editable Url", false);
290 cont
->urlNavigator()->setUrlEditable(editable
);
292 cont
= m_viewContainer
[SecondaryView
];
293 const QString secondaryUrl
= group
.readEntry("Secondary Url");
294 if (!secondaryUrl
.isEmpty()) {
296 // a secondary view should be shown, but no one is available
297 // currently -> create a new view
299 cont
= m_viewContainer
[SecondaryView
];
303 cont
->setUrl(secondaryUrl
);
304 bool editable
= group
.readEntry("Secondary Editable Url", false);
305 cont
->urlNavigator()->setUrlEditable(editable
);
306 } else if (cont
!= 0) {
307 // no secondary view should be shown, but the default setting shows
308 // one already -> close the view
313 void DolphinMainWindow::updateNewMenu()
315 m_newMenu
->slotCheckUpToDate();
316 m_newMenu
->setPopupFiles(activeViewContainer()->url());
319 void DolphinMainWindow::properties()
321 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
323 KPropertiesDialog
*dialog
= new KPropertiesDialog(list
, this);
324 dialog
->setAttribute(Qt::WA_DeleteOnClose
);
327 dialog
->activateWindow();
330 void DolphinMainWindow::quit()
335 void DolphinMainWindow::slotHandlePlacesError(const QString
&message
)
337 if (!message
.isEmpty()) {
338 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
339 statusBar
->setMessage(message
, DolphinStatusBar::Error
);
343 void DolphinMainWindow::slotUndoAvailable(bool available
)
345 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
346 if (undoAction
!= 0) {
347 undoAction
->setEnabled(available
);
350 if (available
&& (m_undoCommandTypes
.count() > 0)) {
351 const KonqFileUndoManager::CommandType command
= m_undoCommandTypes
.takeFirst();
352 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
354 case KonqFileUndoManager::COPY
:
355 statusBar
->setMessage(i18nc("@info:status", "Copy operation completed."),
356 DolphinStatusBar::OperationCompleted
);
358 case KonqFileUndoManager::MOVE
:
359 statusBar
->setMessage(i18nc("@info:status", "Move operation completed."),
360 DolphinStatusBar::OperationCompleted
);
362 case KonqFileUndoManager::LINK
:
363 statusBar
->setMessage(i18nc("@info:status", "Link operation completed."),
364 DolphinStatusBar::OperationCompleted
);
366 case KonqFileUndoManager::TRASH
:
367 statusBar
->setMessage(i18nc("@info:status", "Move to trash operation completed."),
368 DolphinStatusBar::OperationCompleted
);
370 case KonqFileUndoManager::RENAME
:
371 statusBar
->setMessage(i18nc("@info:status", "Renaming operation completed."),
372 DolphinStatusBar::OperationCompleted
);
375 case KonqFileUndoManager::MKDIR
:
376 statusBar
->setMessage(i18nc("@info:status", "Created folder."),
377 DolphinStatusBar::OperationCompleted
);
387 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
389 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
390 if (undoAction
!= 0) {
391 undoAction
->setText(text
);
395 void DolphinMainWindow::undo()
398 KonqFileUndoManager::self()->undo();
401 void DolphinMainWindow::cut()
403 m_activeViewContainer
->view()->cutSelectedItems();
406 void DolphinMainWindow::copy()
408 m_activeViewContainer
->view()->copySelectedItems();
411 void DolphinMainWindow::paste()
413 m_activeViewContainer
->view()->paste();
416 void DolphinMainWindow::updatePasteAction()
418 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
419 if (pasteAction
== 0) {
423 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
424 pasteAction
->setEnabled(pasteInfo
.first
);
425 pasteAction
->setText(pasteInfo
.second
);
428 void DolphinMainWindow::selectAll()
432 // if the URL navigator is editable and focused, select the whole
433 // URL instead of all items of the view
435 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
436 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit();
437 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
438 lineEdit
->hasFocus();
440 lineEdit
->selectAll();
442 m_activeViewContainer
->view()->selectAll();
446 void DolphinMainWindow::invertSelection()
449 m_activeViewContainer
->view()->invertSelection();
452 void DolphinMainWindow::toggleSplitView()
454 if (m_viewContainer
[SecondaryView
] == 0) {
455 // create a secondary view
456 const int newWidth
= (m_viewContainer
[PrimaryView
]->width() - m_splitter
->handleWidth()) / 2;
458 const DolphinView
* view
= m_viewContainer
[PrimaryView
]->view();
459 m_viewContainer
[SecondaryView
] = new DolphinViewContainer(this, 0, view
->rootUrl());
460 connectViewSignals(SecondaryView
);
461 m_splitter
->addWidget(m_viewContainer
[SecondaryView
]);
462 m_splitter
->setSizes(QList
<int>() << newWidth
<< newWidth
);
463 m_viewContainer
[SecondaryView
]->view()->reload();
464 m_viewContainer
[SecondaryView
]->setActive(false);
465 m_viewContainer
[SecondaryView
]->show();
466 } else if (m_activeViewContainer
== m_viewContainer
[PrimaryView
]) {
467 // remove secondary view
468 m_viewContainer
[SecondaryView
]->close();
469 m_viewContainer
[SecondaryView
]->deleteLater();
470 m_viewContainer
[SecondaryView
] = 0;
472 // The secondary view is active, hence from a users point of view
473 // the content of the secondary view should be moved to the primary view.
474 // From an implementation point of view it is more efficient to close
475 // the primary view and exchange the internal pointers afterwards.
476 m_viewContainer
[PrimaryView
]->close();
477 m_viewContainer
[PrimaryView
]->deleteLater();
478 m_viewContainer
[PrimaryView
] = m_viewContainer
[SecondaryView
];
479 m_viewContainer
[SecondaryView
] = 0;
482 setActiveViewContainer(m_viewContainer
[PrimaryView
]);
484 emit
activeViewChanged(); // TODO unused; remove?
487 void DolphinMainWindow::reloadView()
490 m_activeViewContainer
->view()->reload();
493 void DolphinMainWindow::stopLoading()
497 void DolphinMainWindow::toggleFilterBarVisibility(bool show
)
499 m_activeViewContainer
->showFilterBar(show
);
502 void DolphinMainWindow::toggleEditLocation()
506 QAction
* action
= actionCollection()->action("editable_location");
507 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
508 urlNavigator
->setUrlEditable(action
->isChecked());
511 void DolphinMainWindow::editLocation()
513 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
514 navigator
->setUrlEditable(true);
515 navigator
->setFocus();
517 // select the whole text of the combo box editor
518 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit();
519 const QString text
= lineEdit
->text();
520 lineEdit
->setSelection(0, text
.length());
523 void DolphinMainWindow::adjustViewProperties()
526 ViewPropertiesDialog
dlg(m_activeViewContainer
->view());
530 void DolphinMainWindow::goBack()
533 m_activeViewContainer
->urlNavigator()->goBack();
536 void DolphinMainWindow::goForward()
539 m_activeViewContainer
->urlNavigator()->goForward();
542 void DolphinMainWindow::goUp()
545 m_activeViewContainer
->urlNavigator()->goUp();
548 void DolphinMainWindow::goHome()
551 m_activeViewContainer
->urlNavigator()->goHome();
554 void DolphinMainWindow::findFile()
556 KRun::run("kfind", m_activeViewContainer
->url(), this);
559 void DolphinMainWindow::compareFiles()
561 // The method is only invoked if exactly 2 files have
562 // been selected. The selected files may be:
563 // - both in the primary view
564 // - both in the secondary view
565 // - one in the primary view and the other in the secondary
567 Q_ASSERT(m_viewContainer
[PrimaryView
] != 0);
571 KUrl::List urls
= m_viewContainer
[PrimaryView
]->view()->selectedUrls();
573 switch (urls
.count()) {
575 Q_ASSERT(m_viewContainer
[SecondaryView
] != 0);
576 urls
= m_viewContainer
[SecondaryView
]->view()->selectedUrls();
577 Q_ASSERT(urls
.count() == 2);
585 Q_ASSERT(m_viewContainer
[SecondaryView
] != 0);
586 urls
= m_viewContainer
[SecondaryView
]->view()->selectedUrls();
587 Q_ASSERT(urls
.count() == 1);
599 // may not happen: compareFiles may only get invoked if 2
600 // files are selected
605 QString
command("kompare -c \"");
606 command
.append(urlA
.pathOrUrl());
607 command
.append("\" \"");
608 command
.append(urlB
.pathOrUrl());
609 command
.append('\"');
610 KRun::runCommand(command
, "Kompare", "kompare", this);
614 void DolphinMainWindow::toggleShowMenuBar()
616 const bool visible
= menuBar()->isVisible();
617 menuBar()->setVisible(!visible
);
620 void DolphinMainWindow::editSettings()
622 DolphinSettingsDialog
dialog(this);
626 void DolphinMainWindow::init()
628 DolphinSettings
& settings
= DolphinSettings::instance();
630 // Check whether Dolphin runs the first time. If yes then
631 // a proper default window size is given at the end of DolphinMainWindow::init().
632 GeneralSettings
* generalSettings
= settings
.generalSettings();
633 const bool firstRun
= generalSettings
->firstRun();
635 generalSettings
->setViewPropsTimestamp(QDateTime::currentDateTime());
638 setAcceptDrops(true);
640 m_splitter
= new QSplitter(this);
644 const KUrl
& homeUrl
= generalSettings
->homeUrl();
645 setCaption(homeUrl
.fileName());
646 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
647 connect(m_actionHandler
, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
648 ViewProperties
props(homeUrl
);
649 m_viewContainer
[PrimaryView
] = new DolphinViewContainer(this,
653 m_activeViewContainer
= m_viewContainer
[PrimaryView
];
654 connectViewSignals(PrimaryView
);
655 DolphinView
* view
= m_viewContainer
[PrimaryView
]->view();
657 m_viewContainer
[PrimaryView
]->show();
658 m_actionHandler
->setCurrentView(view
);
660 setCentralWidget(m_splitter
);
663 setupGUI(Keys
| Save
| Create
| ToolBar
);
666 stateChanged("new_file");
667 setAutoSaveSettings();
669 QClipboard
* clipboard
= QApplication::clipboard();
670 connect(clipboard
, SIGNAL(dataChanged()),
671 this, SLOT(updatePasteAction()));
675 if (generalSettings
->splitView()) {
681 // assure a proper default size if Dolphin runs the first time
685 emit
urlChanged(homeUrl
);
688 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer
* viewContainer
)
690 Q_ASSERT(viewContainer
!= 0);
691 Q_ASSERT((viewContainer
== m_viewContainer
[PrimaryView
]) || (viewContainer
== m_viewContainer
[SecondaryView
]));
692 if (m_activeViewContainer
== viewContainer
) {
696 m_activeViewContainer
->setActive(false);
697 m_activeViewContainer
= viewContainer
;
698 m_activeViewContainer
->setActive(true);
700 m_actionHandler
->setCurrentView(viewContainer
->view());
707 const KUrl
& url
= m_activeViewContainer
->url();
708 setCaption(url
.fileName());
710 emit
activeViewChanged(); // TODO unused; remove?
711 emit
urlChanged(url
);
714 void DolphinMainWindow::setupActions()
717 m_newMenu
= new DolphinNewMenu(this);
718 KMenu
* menu
= m_newMenu
->menu();
719 menu
->setTitle(i18nc("@title:menu", "Create New"));
720 menu
->setIcon(KIcon("document-new"));
721 connect(menu
, SIGNAL(aboutToShow()),
722 this, SLOT(updateNewMenu()));
724 KAction
* newWindow
= actionCollection()->addAction("new_window");
725 newWindow
->setIcon(KIcon("window-new"));
726 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
727 newWindow
->setShortcut(Qt::CTRL
| Qt::Key_N
);
728 connect(newWindow
, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
730 KAction
* properties
= actionCollection()->addAction("properties");
731 properties
->setText(i18nc("@action:inmenu File", "Properties"));
732 properties
->setShortcut(Qt::ALT
| Qt::Key_Return
);
733 connect(properties
, SIGNAL(triggered()), this, SLOT(properties()));
735 KStandardAction::quit(this, SLOT(quit()), actionCollection());
738 KStandardAction::undo(this,
742 // need to remove shift+del from cut action, else the shortcut for deletejob
744 KAction
* cut
= KStandardAction::cut(this, SLOT(cut()), actionCollection());
745 KShortcut cutShortcut
= cut
->shortcut();
746 cutShortcut
.remove(Qt::SHIFT
+ Qt::Key_Delete
, KShortcut::KeepEmpty
);
747 cut
->setShortcut(cutShortcut
);
748 KStandardAction::copy(this, SLOT(copy()), actionCollection());
749 KStandardAction::paste(this, SLOT(paste()), actionCollection());
751 KAction
* selectAll
= actionCollection()->addAction("select_all");
752 selectAll
->setText(i18nc("@action:inmenu Edit", "Select All"));
753 selectAll
->setShortcut(Qt::CTRL
+ Qt::Key_A
);
754 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
756 KAction
* invertSelection
= actionCollection()->addAction("invert_selection");
757 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
758 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
759 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
762 // (note that most of it is set up in DolphinViewActionHandler)
764 KAction
* split
= actionCollection()->addAction("split_view");
765 split
->setShortcut(Qt::Key_F3
);
767 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
769 KAction
* reload
= actionCollection()->addAction("reload");
770 reload
->setText(i18nc("@action:inmenu View", "Reload"));
771 reload
->setShortcut(Qt::Key_F5
);
772 reload
->setIcon(KIcon("view-refresh"));
773 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
775 KAction
* stop
= actionCollection()->addAction("stop");
776 stop
->setText(i18nc("@action:inmenu View", "Stop"));
777 stop
->setIcon(KIcon("process-stop"));
778 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
780 // TODO: the naming "Show full Location" is currently confusing...
781 KToggleAction
* showFullLocation
= actionCollection()->add
<KToggleAction
>("editable_location");
782 showFullLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Show Full Location"));
783 showFullLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
784 connect(showFullLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
786 KAction
* editLocation
= actionCollection()->addAction("edit_location");
787 editLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Edit Location"));
788 editLocation
->setShortcut(Qt::Key_F6
);
789 connect(editLocation
, SIGNAL(triggered()), this, SLOT(editLocation()));
791 KAction
* adjustViewProps
= actionCollection()->addAction("view_properties");
792 adjustViewProps
->setText(i18nc("@action:inmenu View", "Adjust View Properties..."));
793 connect(adjustViewProps
, SIGNAL(triggered()), this, SLOT(adjustViewProperties()));
796 KAction
* backAction
= KStandardAction::back(this, SLOT(goBack()), actionCollection());
797 KShortcut backShortcut
= backAction
->shortcut();
798 backShortcut
.setAlternate(Qt::Key_Backspace
);
799 backAction
->setShortcut(backShortcut
);
801 KStandardAction::forward(this, SLOT(goForward()), actionCollection());
802 KStandardAction::up(this, SLOT(goUp()), actionCollection());
803 KStandardAction::home(this, SLOT(goHome()), actionCollection());
805 // setup 'Tools' menu
806 QAction
* findFile
= actionCollection()->addAction("find_file");
807 findFile
->setText(i18nc("@action:inmenu Tools", "Find File..."));
808 findFile
->setShortcut(Qt::CTRL
| Qt::Key_F
);
809 findFile
->setIcon(KIcon("edit-find"));
810 connect(findFile
, SIGNAL(triggered()), this, SLOT(findFile()));
812 KToggleAction
* showFilterBar
= actionCollection()->add
<KToggleAction
>("show_filter_bar");
813 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
814 showFilterBar
->setShortcut(Qt::CTRL
| Qt::Key_I
);
815 connect(showFilterBar
, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
817 KAction
* compareFiles
= actionCollection()->addAction("compare_files");
818 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
819 compareFiles
->setIcon(KIcon("kompare"));
820 compareFiles
->setEnabled(false);
821 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
823 // setup 'Settings' menu
824 m_showMenuBar
= KStandardAction::showMenubar(this, SLOT(toggleShowMenuBar()), actionCollection());
825 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
828 void DolphinMainWindow::setupDockWidgets()
830 // setup "Information"
831 QDockWidget
* infoDock
= new QDockWidget(i18nc("@title:window", "Information"));
832 infoDock
->setObjectName("infoDock");
833 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
834 SidebarPage
* infoWidget
= new InfoSidebarPage(infoDock
);
835 infoDock
->setWidget(infoWidget
);
837 infoDock
->toggleViewAction()->setText(i18nc("@title:window", "Information"));
838 infoDock
->toggleViewAction()->setShortcut(Qt::Key_F11
);
839 actionCollection()->addAction("show_info_panel", infoDock
->toggleViewAction());
841 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
842 connect(this, SIGNAL(urlChanged(KUrl
)),
843 infoWidget
, SLOT(setUrl(KUrl
)));
844 connect(this, SIGNAL(selectionChanged(KFileItemList
)),
845 infoWidget
, SLOT(setSelection(KFileItemList
)));
846 connect(this, SIGNAL(requestItemInfo(KFileItem
)),
847 infoWidget
, SLOT(requestDelayedItemInfo(KFileItem
)));
850 QDockWidget
* treeViewDock
= new QDockWidget(i18nc("@title:window", "Folders"));
851 treeViewDock
->setObjectName("treeViewDock");
852 treeViewDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
853 TreeViewSidebarPage
* treeWidget
= new TreeViewSidebarPage(treeViewDock
);
854 treeViewDock
->setWidget(treeWidget
);
856 treeViewDock
->toggleViewAction()->setText(i18nc("@title:window", "Folders"));
857 treeViewDock
->toggleViewAction()->setShortcut(Qt::Key_F7
);
858 actionCollection()->addAction("show_folders_panel", treeViewDock
->toggleViewAction());
860 addDockWidget(Qt::LeftDockWidgetArea
, treeViewDock
);
861 connect(this, SIGNAL(urlChanged(KUrl
)),
862 treeWidget
, SLOT(setUrl(KUrl
)));
863 connect(treeWidget
, SIGNAL(changeUrl(KUrl
)),
864 this, SLOT(changeUrl(KUrl
)));
865 connect(treeWidget
, SIGNAL(changeSelection(KFileItemList
)),
866 this, SLOT(changeSelection(KFileItemList
)));
867 connect(treeWidget
, SIGNAL(urlsDropped(KUrl::List
, KUrl
)),
868 this, SLOT(dropUrls(KUrl::List
, KUrl
)));
872 QDockWidget
* terminalDock
= new QDockWidget(i18nc("@title:window", "Terminal"));
873 terminalDock
->setObjectName("terminalDock");
874 terminalDock
->setAllowedAreas(Qt::TopDockWidgetArea
| Qt::BottomDockWidgetArea
);
875 SidebarPage
* terminalWidget
= new TerminalSidebarPage(terminalDock
);
876 terminalDock
->setWidget(terminalWidget
);
878 connect(terminalWidget
, SIGNAL(hideTerminalSidebarPage()), terminalDock
, SLOT(hide()));
880 terminalDock
->toggleViewAction()->setText(i18nc("@title:window", "Terminal"));
881 terminalDock
->toggleViewAction()->setShortcut(Qt::Key_F4
);
882 actionCollection()->addAction("show_terminal_panel", terminalDock
->toggleViewAction());
884 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
885 connect(this, SIGNAL(urlChanged(KUrl
)),
886 terminalWidget
, SLOT(setUrl(KUrl
)));
889 const bool firstRun
= DolphinSettings::instance().generalSettings()->firstRun();
892 treeViewDock
->hide();
894 terminalDock
->hide();
898 QDockWidget
* placesDock
= new QDockWidget(i18nc("@title:window", "Places"));
899 placesDock
->setObjectName("placesDock");
900 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
902 DolphinFilePlacesView
* placesView
= new DolphinFilePlacesView(placesDock
);
903 placesDock
->setWidget(placesView
);
904 placesView
->setModel(DolphinSettings::instance().placesModel());
905 placesView
->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff
);
907 placesDock
->toggleViewAction()->setText(i18nc("@title:window", "Places"));
908 placesDock
->toggleViewAction()->setShortcut(Qt::Key_F9
);
909 actionCollection()->addAction("show_places_panel", placesDock
->toggleViewAction());
911 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
912 connect(placesView
, SIGNAL(urlChanged(KUrl
)),
913 this, SLOT(changeUrl(KUrl
)));
914 connect(this, SIGNAL(urlChanged(KUrl
)),
915 placesView
, SLOT(setUrl(KUrl
)));
918 void DolphinMainWindow::updateEditActions()
920 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
921 if (list
.isEmpty()) {
922 stateChanged("has_no_selection");
924 stateChanged("has_selection");
926 QAction
* renameAction
= actionCollection()->action("rename");
927 if (renameAction
!= 0) {
928 renameAction
->setEnabled(true);
931 bool enableMoveToTrash
= true;
933 KFileItemList::const_iterator it
= list
.begin();
934 const KFileItemList::const_iterator end
= list
.end();
936 const KUrl
& url
= (*it
).url();
937 // only enable the 'Move to Trash' action for local files
938 if (!url
.isLocalFile()) {
939 enableMoveToTrash
= false;
944 QAction
* moveToTrashAction
= actionCollection()->action("move_to_trash");
945 moveToTrashAction
->setEnabled(enableMoveToTrash
);
950 void DolphinMainWindow::updateViewActions()
952 m_actionHandler
->updateViewActions();
954 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
955 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
959 QAction
* editableLocactionAction
= actionCollection()->action("editable_location");
960 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
961 editableLocactionAction
->setChecked(urlNavigator
->isUrlEditable());
964 void DolphinMainWindow::updateGoActions()
966 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
967 const KUrl
& currentUrl
= m_activeViewContainer
->url();
968 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
971 void DolphinMainWindow::clearStatusBar()
973 m_activeViewContainer
->statusBar()->clear();
976 void DolphinMainWindow::connectViewSignals(int viewIndex
)
978 DolphinViewContainer
* container
= m_viewContainer
[viewIndex
];
979 connect(container
, SIGNAL(showFilterBarChanged(bool)),
980 this, SLOT(updateFilterBarAction(bool)));
982 DolphinView
* view
= container
->view();
983 connect(view
, SIGNAL(selectionChanged(KFileItemList
)),
984 this, SLOT(slotSelectionChanged(KFileItemList
)));
985 connect(view
, SIGNAL(requestItemInfo(KFileItem
)),
986 this, SLOT(slotRequestItemInfo(KFileItem
)));
987 connect(view
, SIGNAL(activated()),
988 this, SLOT(toggleActiveView()));
989 connect(view
, SIGNAL(doingOperation(KonqFileUndoManager::CommandType
)),
990 this, SLOT(slotDoingOperation(KonqFileUndoManager::CommandType
)));
992 const KUrlNavigator
* navigator
= container
->urlNavigator();
993 connect(navigator
, SIGNAL(urlChanged(const KUrl
&)),
994 this, SLOT(changeUrl(const KUrl
&)));
995 connect(navigator
, SIGNAL(historyChanged()),
996 this, SLOT(updateHistory()));
997 connect(navigator
, SIGNAL(editableStateChanged(bool)),
998 this, SLOT(slotEditableStateChanged(bool)));
1001 void DolphinMainWindow::updateSplitAction()
1003 QAction
* splitAction
= actionCollection()->action("split_view");
1004 if (m_viewContainer
[SecondaryView
] != 0) {
1005 if (m_activeViewContainer
== m_viewContainer
[PrimaryView
]) {
1006 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
1007 splitAction
->setIcon(KIcon("view-right-close"));
1009 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
1010 splitAction
->setIcon(KIcon("view-left-close"));
1013 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
1014 splitAction
->setIcon(KIcon("view-right-new"));
1018 DolphinMainWindow::UndoUiInterface::UndoUiInterface(DolphinMainWindow
* mainWin
) :
1019 KonqFileUndoManager::UiInterface(mainWin
),
1022 Q_ASSERT(m_mainWin
!= 0);
1025 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
1029 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
1031 DolphinStatusBar
* statusBar
= m_mainWin
->activeViewContainer()->statusBar();
1032 statusBar
->setMessage(job
->errorString(), DolphinStatusBar::Error
);
1035 #include "dolphinmainwindow.moc"