]>
cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.cpp
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
]);
486 void DolphinMainWindow::reloadView()
489 m_activeViewContainer
->view()->reload();
492 void DolphinMainWindow::stopLoading()
496 void DolphinMainWindow::toggleFilterBarVisibility(bool show
)
498 m_activeViewContainer
->showFilterBar(show
);
501 void DolphinMainWindow::toggleEditLocation()
505 QAction
* action
= actionCollection()->action("editable_location");
506 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
507 urlNavigator
->setUrlEditable(action
->isChecked());
510 void DolphinMainWindow::editLocation()
512 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
513 navigator
->setUrlEditable(true);
514 navigator
->setFocus();
516 // select the whole text of the combo box editor
517 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit();
518 const QString text
= lineEdit
->text();
519 lineEdit
->setSelection(0, text
.length());
522 void DolphinMainWindow::adjustViewProperties()
525 ViewPropertiesDialog
dlg(m_activeViewContainer
->view());
529 void DolphinMainWindow::goBack()
532 m_activeViewContainer
->urlNavigator()->goBack();
535 void DolphinMainWindow::goForward()
538 m_activeViewContainer
->urlNavigator()->goForward();
541 void DolphinMainWindow::goUp()
544 m_activeViewContainer
->urlNavigator()->goUp();
547 void DolphinMainWindow::goHome()
550 m_activeViewContainer
->urlNavigator()->goHome();
553 void DolphinMainWindow::findFile()
555 KRun::run("kfind", m_activeViewContainer
->url(), this);
558 void DolphinMainWindow::compareFiles()
560 // The method is only invoked if exactly 2 files have
561 // been selected. The selected files may be:
562 // - both in the primary view
563 // - both in the secondary view
564 // - one in the primary view and the other in the secondary
566 Q_ASSERT(m_viewContainer
[PrimaryView
] != 0);
570 KUrl::List urls
= m_viewContainer
[PrimaryView
]->view()->selectedUrls();
572 switch (urls
.count()) {
574 Q_ASSERT(m_viewContainer
[SecondaryView
] != 0);
575 urls
= m_viewContainer
[SecondaryView
]->view()->selectedUrls();
576 Q_ASSERT(urls
.count() == 2);
584 Q_ASSERT(m_viewContainer
[SecondaryView
] != 0);
585 urls
= m_viewContainer
[SecondaryView
]->view()->selectedUrls();
586 Q_ASSERT(urls
.count() == 1);
598 // may not happen: compareFiles may only get invoked if 2
599 // files are selected
604 QString
command("kompare -c \"");
605 command
.append(urlA
.pathOrUrl());
606 command
.append("\" \"");
607 command
.append(urlB
.pathOrUrl());
608 command
.append('\"');
609 KRun::runCommand(command
, "Kompare", "kompare", this);
613 void DolphinMainWindow::toggleShowMenuBar()
615 const bool visible
= menuBar()->isVisible();
616 menuBar()->setVisible(!visible
);
619 void DolphinMainWindow::editSettings()
621 DolphinSettingsDialog
dialog(this);
625 void DolphinMainWindow::init()
627 DolphinSettings
& settings
= DolphinSettings::instance();
629 // Check whether Dolphin runs the first time. If yes then
630 // a proper default window size is given at the end of DolphinMainWindow::init().
631 GeneralSettings
* generalSettings
= settings
.generalSettings();
632 const bool firstRun
= generalSettings
->firstRun();
634 generalSettings
->setViewPropsTimestamp(QDateTime::currentDateTime());
637 setAcceptDrops(true);
639 m_splitter
= new QSplitter(this);
643 const KUrl
& homeUrl
= generalSettings
->homeUrl();
644 setCaption(homeUrl
.fileName());
645 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
646 connect(m_actionHandler
, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
647 ViewProperties
props(homeUrl
);
648 m_viewContainer
[PrimaryView
] = new DolphinViewContainer(this,
652 m_activeViewContainer
= m_viewContainer
[PrimaryView
];
653 connectViewSignals(PrimaryView
);
654 DolphinView
* view
= m_viewContainer
[PrimaryView
]->view();
656 m_viewContainer
[PrimaryView
]->show();
657 m_actionHandler
->setCurrentView(view
);
659 setCentralWidget(m_splitter
);
662 setupGUI(Keys
| Save
| Create
| ToolBar
);
665 stateChanged("new_file");
666 setAutoSaveSettings();
668 QClipboard
* clipboard
= QApplication::clipboard();
669 connect(clipboard
, SIGNAL(dataChanged()),
670 this, SLOT(updatePasteAction()));
674 if (generalSettings
->splitView()) {
680 // assure a proper default size if Dolphin runs the first time
684 emit
urlChanged(homeUrl
);
687 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer
* viewContainer
)
689 Q_ASSERT(viewContainer
!= 0);
690 Q_ASSERT((viewContainer
== m_viewContainer
[PrimaryView
]) || (viewContainer
== m_viewContainer
[SecondaryView
]));
691 if (m_activeViewContainer
== viewContainer
) {
695 m_activeViewContainer
->setActive(false);
696 m_activeViewContainer
= viewContainer
;
697 m_activeViewContainer
->setActive(true);
699 m_actionHandler
->setCurrentView(viewContainer
->view());
706 const KUrl
& url
= m_activeViewContainer
->url();
707 setCaption(url
.fileName());
709 emit
urlChanged(url
);
712 void DolphinMainWindow::setupActions()
715 m_newMenu
= new DolphinNewMenu(this);
716 KMenu
* menu
= m_newMenu
->menu();
717 menu
->setTitle(i18nc("@title:menu", "Create New"));
718 menu
->setIcon(KIcon("document-new"));
719 connect(menu
, SIGNAL(aboutToShow()),
720 this, SLOT(updateNewMenu()));
722 KAction
* newWindow
= actionCollection()->addAction("new_window");
723 newWindow
->setIcon(KIcon("window-new"));
724 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
725 newWindow
->setShortcut(Qt::CTRL
| Qt::Key_N
);
726 connect(newWindow
, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
728 KAction
* properties
= actionCollection()->addAction("properties");
729 properties
->setText(i18nc("@action:inmenu File", "Properties"));
730 properties
->setShortcut(Qt::ALT
| Qt::Key_Return
);
731 connect(properties
, SIGNAL(triggered()), this, SLOT(properties()));
733 KStandardAction::quit(this, SLOT(quit()), actionCollection());
736 KStandardAction::undo(this,
740 // need to remove shift+del from cut action, else the shortcut for deletejob
742 KAction
* cut
= KStandardAction::cut(this, SLOT(cut()), actionCollection());
743 KShortcut cutShortcut
= cut
->shortcut();
744 cutShortcut
.remove(Qt::SHIFT
+ Qt::Key_Delete
, KShortcut::KeepEmpty
);
745 cut
->setShortcut(cutShortcut
);
746 KStandardAction::copy(this, SLOT(copy()), actionCollection());
747 KStandardAction::paste(this, SLOT(paste()), actionCollection());
749 KAction
* selectAll
= actionCollection()->addAction("select_all");
750 selectAll
->setText(i18nc("@action:inmenu Edit", "Select All"));
751 selectAll
->setShortcut(Qt::CTRL
+ Qt::Key_A
);
752 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
754 KAction
* invertSelection
= actionCollection()->addAction("invert_selection");
755 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
756 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
757 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
760 // (note that most of it is set up in DolphinViewActionHandler)
762 KAction
* split
= actionCollection()->addAction("split_view");
763 split
->setShortcut(Qt::Key_F3
);
765 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
767 KAction
* reload
= actionCollection()->addAction("reload");
768 reload
->setText(i18nc("@action:inmenu View", "Reload"));
769 reload
->setShortcut(Qt::Key_F5
);
770 reload
->setIcon(KIcon("view-refresh"));
771 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
773 KAction
* stop
= actionCollection()->addAction("stop");
774 stop
->setText(i18nc("@action:inmenu View", "Stop"));
775 stop
->setIcon(KIcon("process-stop"));
776 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
778 // TODO: the naming "Show full Location" is currently confusing...
779 KToggleAction
* showFullLocation
= actionCollection()->add
<KToggleAction
>("editable_location");
780 showFullLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Show Full Location"));
781 showFullLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
782 connect(showFullLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
784 KAction
* editLocation
= actionCollection()->addAction("edit_location");
785 editLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Edit Location"));
786 editLocation
->setShortcut(Qt::Key_F6
);
787 connect(editLocation
, SIGNAL(triggered()), this, SLOT(editLocation()));
789 KAction
* adjustViewProps
= actionCollection()->addAction("view_properties");
790 adjustViewProps
->setText(i18nc("@action:inmenu View", "Adjust View Properties..."));
791 connect(adjustViewProps
, SIGNAL(triggered()), this, SLOT(adjustViewProperties()));
794 KAction
* backAction
= KStandardAction::back(this, SLOT(goBack()), actionCollection());
795 KShortcut backShortcut
= backAction
->shortcut();
796 backShortcut
.setAlternate(Qt::Key_Backspace
);
797 backAction
->setShortcut(backShortcut
);
799 KStandardAction::forward(this, SLOT(goForward()), actionCollection());
800 KStandardAction::up(this, SLOT(goUp()), actionCollection());
801 KStandardAction::home(this, SLOT(goHome()), actionCollection());
803 // setup 'Tools' menu
804 QAction
* findFile
= actionCollection()->addAction("find_file");
805 findFile
->setText(i18nc("@action:inmenu Tools", "Find File..."));
806 findFile
->setShortcut(Qt::CTRL
| Qt::Key_F
);
807 findFile
->setIcon(KIcon("edit-find"));
808 connect(findFile
, SIGNAL(triggered()), this, SLOT(findFile()));
810 KToggleAction
* showFilterBar
= actionCollection()->add
<KToggleAction
>("show_filter_bar");
811 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
812 showFilterBar
->setShortcut(Qt::CTRL
| Qt::Key_I
);
813 connect(showFilterBar
, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
815 KAction
* compareFiles
= actionCollection()->addAction("compare_files");
816 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
817 compareFiles
->setIcon(KIcon("kompare"));
818 compareFiles
->setEnabled(false);
819 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
821 // setup 'Settings' menu
822 m_showMenuBar
= KStandardAction::showMenubar(this, SLOT(toggleShowMenuBar()), actionCollection());
823 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
826 void DolphinMainWindow::setupDockWidgets()
828 // setup "Information"
829 QDockWidget
* infoDock
= new QDockWidget(i18nc("@title:window", "Information"));
830 infoDock
->setObjectName("infoDock");
831 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
832 SidebarPage
* infoWidget
= new InfoSidebarPage(infoDock
);
833 infoDock
->setWidget(infoWidget
);
835 infoDock
->toggleViewAction()->setText(i18nc("@title:window", "Information"));
836 infoDock
->toggleViewAction()->setShortcut(Qt::Key_F11
);
837 actionCollection()->addAction("show_info_panel", infoDock
->toggleViewAction());
839 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
840 connect(this, SIGNAL(urlChanged(KUrl
)),
841 infoWidget
, SLOT(setUrl(KUrl
)));
842 connect(this, SIGNAL(selectionChanged(KFileItemList
)),
843 infoWidget
, SLOT(setSelection(KFileItemList
)));
844 connect(this, SIGNAL(requestItemInfo(KFileItem
)),
845 infoWidget
, SLOT(requestDelayedItemInfo(KFileItem
)));
848 QDockWidget
* treeViewDock
= new QDockWidget(i18nc("@title:window", "Folders"));
849 treeViewDock
->setObjectName("treeViewDock");
850 treeViewDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
851 TreeViewSidebarPage
* treeWidget
= new TreeViewSidebarPage(treeViewDock
);
852 treeViewDock
->setWidget(treeWidget
);
854 treeViewDock
->toggleViewAction()->setText(i18nc("@title:window", "Folders"));
855 treeViewDock
->toggleViewAction()->setShortcut(Qt::Key_F7
);
856 actionCollection()->addAction("show_folders_panel", treeViewDock
->toggleViewAction());
858 addDockWidget(Qt::LeftDockWidgetArea
, treeViewDock
);
859 connect(this, SIGNAL(urlChanged(KUrl
)),
860 treeWidget
, SLOT(setUrl(KUrl
)));
861 connect(treeWidget
, SIGNAL(changeUrl(KUrl
)),
862 this, SLOT(changeUrl(KUrl
)));
863 connect(treeWidget
, SIGNAL(changeSelection(KFileItemList
)),
864 this, SLOT(changeSelection(KFileItemList
)));
865 connect(treeWidget
, SIGNAL(urlsDropped(KUrl::List
, KUrl
)),
866 this, SLOT(dropUrls(KUrl::List
, KUrl
)));
870 QDockWidget
* terminalDock
= new QDockWidget(i18nc("@title:window", "Terminal"));
871 terminalDock
->setObjectName("terminalDock");
872 terminalDock
->setAllowedAreas(Qt::TopDockWidgetArea
| Qt::BottomDockWidgetArea
);
873 SidebarPage
* terminalWidget
= new TerminalSidebarPage(terminalDock
);
874 terminalDock
->setWidget(terminalWidget
);
876 connect(terminalWidget
, SIGNAL(hideTerminalSidebarPage()), terminalDock
, SLOT(hide()));
878 terminalDock
->toggleViewAction()->setText(i18nc("@title:window", "Terminal"));
879 terminalDock
->toggleViewAction()->setShortcut(Qt::Key_F4
);
880 actionCollection()->addAction("show_terminal_panel", terminalDock
->toggleViewAction());
882 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
883 connect(this, SIGNAL(urlChanged(KUrl
)),
884 terminalWidget
, SLOT(setUrl(KUrl
)));
887 const bool firstRun
= DolphinSettings::instance().generalSettings()->firstRun();
890 treeViewDock
->hide();
892 terminalDock
->hide();
896 QDockWidget
* placesDock
= new QDockWidget(i18nc("@title:window", "Places"));
897 placesDock
->setObjectName("placesDock");
898 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
900 DolphinFilePlacesView
* placesView
= new DolphinFilePlacesView(placesDock
);
901 placesDock
->setWidget(placesView
);
902 placesView
->setModel(DolphinSettings::instance().placesModel());
903 placesView
->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff
);
905 placesDock
->toggleViewAction()->setText(i18nc("@title:window", "Places"));
906 placesDock
->toggleViewAction()->setShortcut(Qt::Key_F9
);
907 actionCollection()->addAction("show_places_panel", placesDock
->toggleViewAction());
909 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
910 connect(placesView
, SIGNAL(urlChanged(KUrl
)),
911 this, SLOT(changeUrl(KUrl
)));
912 connect(this, SIGNAL(urlChanged(KUrl
)),
913 placesView
, SLOT(setUrl(KUrl
)));
916 void DolphinMainWindow::updateEditActions()
918 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
919 if (list
.isEmpty()) {
920 stateChanged("has_no_selection");
922 stateChanged("has_selection");
924 QAction
* renameAction
= actionCollection()->action("rename");
925 if (renameAction
!= 0) {
926 renameAction
->setEnabled(true);
929 bool enableMoveToTrash
= true;
931 KFileItemList::const_iterator it
= list
.begin();
932 const KFileItemList::const_iterator end
= list
.end();
934 const KUrl
& url
= (*it
).url();
935 // only enable the 'Move to Trash' action for local files
936 if (!url
.isLocalFile()) {
937 enableMoveToTrash
= false;
942 QAction
* moveToTrashAction
= actionCollection()->action("move_to_trash");
943 moveToTrashAction
->setEnabled(enableMoveToTrash
);
948 void DolphinMainWindow::updateViewActions()
950 m_actionHandler
->updateViewActions();
952 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
953 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
957 QAction
* editableLocactionAction
= actionCollection()->action("editable_location");
958 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
959 editableLocactionAction
->setChecked(urlNavigator
->isUrlEditable());
962 void DolphinMainWindow::updateGoActions()
964 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
965 const KUrl
& currentUrl
= m_activeViewContainer
->url();
966 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
969 void DolphinMainWindow::clearStatusBar()
971 m_activeViewContainer
->statusBar()->clear();
974 void DolphinMainWindow::connectViewSignals(int viewIndex
)
976 DolphinViewContainer
* container
= m_viewContainer
[viewIndex
];
977 connect(container
, SIGNAL(showFilterBarChanged(bool)),
978 this, SLOT(updateFilterBarAction(bool)));
980 DolphinView
* view
= container
->view();
981 connect(view
, SIGNAL(selectionChanged(KFileItemList
)),
982 this, SLOT(slotSelectionChanged(KFileItemList
)));
983 connect(view
, SIGNAL(requestItemInfo(KFileItem
)),
984 this, SLOT(slotRequestItemInfo(KFileItem
)));
985 connect(view
, SIGNAL(activated()),
986 this, SLOT(toggleActiveView()));
987 connect(view
, SIGNAL(doingOperation(KonqFileUndoManager::CommandType
)),
988 this, SLOT(slotDoingOperation(KonqFileUndoManager::CommandType
)));
990 const KUrlNavigator
* navigator
= container
->urlNavigator();
991 connect(navigator
, SIGNAL(urlChanged(const KUrl
&)),
992 this, SLOT(changeUrl(const KUrl
&)));
993 connect(navigator
, SIGNAL(historyChanged()),
994 this, SLOT(updateHistory()));
995 connect(navigator
, SIGNAL(editableStateChanged(bool)),
996 this, SLOT(slotEditableStateChanged(bool)));
999 void DolphinMainWindow::updateSplitAction()
1001 QAction
* splitAction
= actionCollection()->action("split_view");
1002 if (m_viewContainer
[SecondaryView
] != 0) {
1003 if (m_activeViewContainer
== m_viewContainer
[PrimaryView
]) {
1004 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
1005 splitAction
->setIcon(KIcon("view-right-close"));
1007 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
1008 splitAction
->setIcon(KIcon("view-left-close"));
1011 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
1012 splitAction
->setIcon(KIcon("view-right-new"));
1016 DolphinMainWindow::UndoUiInterface::UndoUiInterface(DolphinMainWindow
* mainWin
) :
1017 KonqFileUndoManager::UiInterface(mainWin
),
1020 Q_ASSERT(m_mainWin
!= 0);
1023 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
1027 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
1029 DolphinStatusBar
* statusBar
= m_mainWin
->activeViewContainer()->statusBar();
1030 statusBar
->setMessage(job
->errorString(), DolphinStatusBar::Error
);
1033 #include "dolphinmainwindow.moc"