]>
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 "terminalsidebarpage.h"
39 #include "treeviewsidebarpage.h"
40 #include "viewpropertiesdialog.h"
41 #include "viewproperties.h"
43 #include "dolphin_generalsettings.h"
44 #include "dolphin_iconsmodesettings.h"
47 #include <kactioncollection.h>
49 #include <kdesktopfile.h>
50 #include <kdeversion.h>
51 #include <kfiledialog.h>
52 #include <kfileplacesmodel.h>
55 #include <kiconloader.h>
56 #include <kio/netaccess.h>
57 #include <kinputdialog.h>
61 #include <kmessagebox.h>
62 #include <kurlnavigator.h>
63 #include <konqmimedata.h>
64 #include <kpropertiesdialog.h>
65 #include <kprotocolinfo.h>
66 #include <ktoggleaction.h>
69 #include <kstandarddirs.h>
70 #include <kstatusbar.h>
71 #include <kstandardaction.h>
73 #include <kurlcombobox.h>
79 #include <QDockWidget>
81 DolphinMainWindow::DolphinMainWindow(int id
) :
86 m_activeViewContainer(0),
89 setObjectName("Dolphin");
90 m_viewContainer
[PrimaryView
] = 0;
91 m_viewContainer
[SecondaryView
] = 0;
93 new MainWindowAdaptor(this);
94 QDBusConnection::sessionBus().registerObject(QString("/dolphin/MainWindow%1").arg(m_id
), this);
96 KonqFileUndoManager::incRef();
98 KonqFileUndoManager
* undoManager
= KonqFileUndoManager::self();
99 undoManager
->setUiInterface(new UndoUiInterface(this));
101 connect(undoManager
, SIGNAL(undoAvailable(bool)),
102 this, SLOT(slotUndoAvailable(bool)));
103 connect(undoManager
, SIGNAL(undoTextChanged(const QString
&)),
104 this, SLOT(slotUndoTextChanged(const QString
&)));
105 connect(DolphinSettings::instance().placesModel(), SIGNAL(errorMessage(const QString
&)),
106 this, SLOT(slotHandlePlacesError(const QString
&)));
109 DolphinMainWindow::~DolphinMainWindow()
111 KonqFileUndoManager::decRef();
112 DolphinApplication::app()->removeMainWindow(this);
115 void DolphinMainWindow::toggleViews()
117 if (m_viewContainer
[SecondaryView
] == 0) {
121 // move secondary view from the last position of the splitter
122 // to the first position
123 m_splitter
->insertWidget(0, m_viewContainer
[SecondaryView
]);
125 DolphinViewContainer
* container
= m_viewContainer
[PrimaryView
];
126 m_viewContainer
[PrimaryView
] = m_viewContainer
[SecondaryView
];
127 m_viewContainer
[SecondaryView
] = container
;
130 void DolphinMainWindow::slotDoingOperation(KonqFileUndoManager::CommandType commandType
)
133 m_undoCommandTypes
.append(commandType
);
136 void DolphinMainWindow::refreshViews()
138 Q_ASSERT(m_viewContainer
[PrimaryView
] != 0);
140 // remember the current active view, as because of
141 // the refreshing the active view might change to
142 // the secondary view
143 DolphinViewContainer
* activeViewContainer
= m_activeViewContainer
;
145 m_viewContainer
[PrimaryView
]->view()->refresh();
146 if (m_viewContainer
[SecondaryView
] != 0) {
147 m_viewContainer
[SecondaryView
]->view()->refresh();
150 setActiveViewContainer(activeViewContainer
);
153 void DolphinMainWindow::dropUrls(const KUrl::List
& urls
,
154 const KUrl
& destination
)
156 DolphinDropController
dropController(this);
157 connect(&dropController
, SIGNAL(doingOperation(KonqFileUndoManager::CommandType
)),
158 this, SLOT(slotDoingOperation(KonqFileUndoManager::CommandType
)));
159 dropController
.dropUrls(urls
, destination
);
162 void DolphinMainWindow::changeUrl(const KUrl
& url
)
164 DolphinViewContainer
* view
= activeViewContainer();
170 setCaption(url
.fileName());
171 emit
urlChanged(url
);
175 void DolphinMainWindow::changeSelection(const KFileItemList
& selection
)
177 activeViewContainer()->view()->changeSelection(selection
);
180 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
182 KToggleAction
* editableLocationAction
=
183 static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
184 editableLocationAction
->setChecked(editable
);
187 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
191 Q_ASSERT(m_viewContainer
[PrimaryView
] != 0);
192 int selectedUrlsCount
= m_viewContainer
[PrimaryView
]->view()->selectedUrls().count();
193 if (m_viewContainer
[SecondaryView
] != 0) {
194 selectedUrlsCount
+= m_viewContainer
[SecondaryView
]->view()->selectedUrls().count();
197 QAction
* compareFilesAction
= actionCollection()->action("compare_files");
198 if (selectedUrlsCount
== 2) {
199 const bool kompareInstalled
= !KGlobal::dirs()->findExe("kompare").isEmpty();
200 compareFilesAction
->setEnabled(selectedUrlsCount
== 2 && kompareInstalled
);
202 compareFilesAction
->setEnabled(false);
205 m_activeViewContainer
->updateStatusBar();
207 emit
selectionChanged(selection
);
210 void DolphinMainWindow::slotRequestItemInfo(const KFileItem
& item
)
212 emit
requestItemInfo(item
);
215 void DolphinMainWindow::slotHistoryChanged()
220 void DolphinMainWindow::updateFilterBarAction(bool show
)
222 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
223 showFilterBarAction
->setChecked(show
);
226 void DolphinMainWindow::openNewMainWindow()
228 DolphinApplication::app()->createMainWindow()->show();
231 void DolphinMainWindow::toggleActiveView()
233 if (m_viewContainer
[SecondaryView
] == 0) {
234 // only one view is available
238 Q_ASSERT(m_activeViewContainer
!= 0);
239 Q_ASSERT(m_viewContainer
[PrimaryView
] != 0);
241 DolphinViewContainer
* left
= m_viewContainer
[PrimaryView
];
242 DolphinViewContainer
* right
= m_viewContainer
[SecondaryView
];
243 setActiveViewContainer(m_activeViewContainer
== right
? left
: right
);
246 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
248 DolphinSettings
& settings
= DolphinSettings::instance();
249 GeneralSettings
* generalSettings
= settings
.generalSettings();
250 generalSettings
->setFirstRun(false);
254 KXmlGuiWindow::closeEvent(event
);
257 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
259 DolphinViewContainer
* cont
= m_viewContainer
[PrimaryView
];
260 group
.writeEntry("Primary Url", cont
->url().url());
261 group
.writeEntry("Primary Editable Url", cont
->isUrlEditable());
263 cont
= m_viewContainer
[SecondaryView
];
265 group
.writeEntry("Secondary Url", cont
->url().url());
266 group
.writeEntry("Secondary Editable Url", cont
->isUrlEditable());
270 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
272 DolphinViewContainer
* cont
= m_viewContainer
[PrimaryView
];
274 cont
->setUrl(group
.readEntry("Primary Url"));
275 bool editable
= group
.readEntry("Primary Editable Url", false);
276 cont
->urlNavigator()->setUrlEditable(editable
);
278 cont
= m_viewContainer
[SecondaryView
];
279 const QString secondaryUrl
= group
.readEntry("Secondary Url");
280 if (!secondaryUrl
.isEmpty()) {
282 // a secondary view should be shown, but no one is available
283 // currently -> create a new view
285 cont
= m_viewContainer
[SecondaryView
];
289 cont
->setUrl(secondaryUrl
);
290 bool editable
= group
.readEntry("Secondary Editable Url", false);
291 cont
->urlNavigator()->setUrlEditable(editable
);
292 } else if (cont
!= 0) {
293 // no secondary view should be shown, but the default setting shows
294 // one already -> close the view
299 void DolphinMainWindow::updateNewMenu()
301 m_newMenu
->slotCheckUpToDate();
302 m_newMenu
->setPopupFiles(activeViewContainer()->url());
305 void DolphinMainWindow::properties()
307 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
309 KPropertiesDialog
*dialog
= new KPropertiesDialog(list
, this);
310 dialog
->setAttribute(Qt::WA_DeleteOnClose
);
313 dialog
->activateWindow();
316 void DolphinMainWindow::quit()
321 void DolphinMainWindow::slotHandlePlacesError(const QString
&message
)
323 if (!message
.isEmpty()) {
324 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
325 statusBar
->setMessage(message
, DolphinStatusBar::Error
);
329 void DolphinMainWindow::slotUndoAvailable(bool available
)
331 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
332 if (undoAction
!= 0) {
333 undoAction
->setEnabled(available
);
336 if (available
&& (m_undoCommandTypes
.count() > 0)) {
337 const KonqFileUndoManager::CommandType command
= m_undoCommandTypes
.takeFirst();
338 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
340 case KonqFileUndoManager::COPY
:
341 statusBar
->setMessage(i18nc("@info:status", "Copy operation completed."),
342 DolphinStatusBar::OperationCompleted
);
344 case KonqFileUndoManager::MOVE
:
345 statusBar
->setMessage(i18nc("@info:status", "Move operation completed."),
346 DolphinStatusBar::OperationCompleted
);
348 case KonqFileUndoManager::LINK
:
349 statusBar
->setMessage(i18nc("@info:status", "Link operation completed."),
350 DolphinStatusBar::OperationCompleted
);
352 case KonqFileUndoManager::TRASH
:
353 statusBar
->setMessage(i18nc("@info:status", "Move to trash operation completed."),
354 DolphinStatusBar::OperationCompleted
);
356 case KonqFileUndoManager::RENAME
:
357 statusBar
->setMessage(i18nc("@info:status", "Renaming operation completed."),
358 DolphinStatusBar::OperationCompleted
);
361 case KonqFileUndoManager::MKDIR
:
362 statusBar
->setMessage(i18nc("@info:status", "Created folder."),
363 DolphinStatusBar::OperationCompleted
);
373 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
375 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
376 if (undoAction
!= 0) {
377 undoAction
->setText(text
);
381 void DolphinMainWindow::undo()
384 KonqFileUndoManager::self()->undo();
387 void DolphinMainWindow::cut()
389 m_activeViewContainer
->view()->cutSelectedItems();
392 void DolphinMainWindow::copy()
394 m_activeViewContainer
->view()->copySelectedItems();
397 void DolphinMainWindow::paste()
399 m_activeViewContainer
->view()->paste();
402 void DolphinMainWindow::updatePasteAction()
404 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
405 if (pasteAction
== 0) {
409 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
410 pasteAction
->setEnabled(pasteInfo
.first
);
411 pasteAction
->setText(pasteInfo
.second
);
414 void DolphinMainWindow::selectAll()
418 // if the URL navigator is editable and focused, select the whole
419 // URL instead of all items of the view
421 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
422 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit();
423 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
424 lineEdit
->hasFocus();
426 lineEdit
->selectAll();
428 m_activeViewContainer
->view()->selectAll();
432 void DolphinMainWindow::invertSelection()
435 m_activeViewContainer
->view()->invertSelection();
438 void DolphinMainWindow::toggleSplitView()
440 if (m_viewContainer
[SecondaryView
] == 0) {
441 // create a secondary view
442 const int newWidth
= (m_viewContainer
[PrimaryView
]->width() - m_splitter
->handleWidth()) / 2;
444 const DolphinView
* view
= m_viewContainer
[PrimaryView
]->view();
445 m_viewContainer
[SecondaryView
] = new DolphinViewContainer(this, 0, view
->rootUrl());
446 connectViewSignals(SecondaryView
);
447 m_splitter
->addWidget(m_viewContainer
[SecondaryView
]);
448 m_splitter
->setSizes(QList
<int>() << newWidth
<< newWidth
);
449 m_viewContainer
[SecondaryView
]->view()->reload();
450 m_viewContainer
[SecondaryView
]->setActive(false);
451 m_viewContainer
[SecondaryView
]->show();
452 } else if (m_activeViewContainer
== m_viewContainer
[PrimaryView
]) {
453 // remove secondary view
454 m_viewContainer
[SecondaryView
]->close();
455 m_viewContainer
[SecondaryView
]->deleteLater();
456 m_viewContainer
[SecondaryView
] = 0;
458 // The secondary view is active, hence from a users point of view
459 // the content of the secondary view should be moved to the primary view.
460 // From an implementation point of view it is more efficient to close
461 // the primary view and exchange the internal pointers afterwards.
462 m_viewContainer
[PrimaryView
]->close();
463 m_viewContainer
[PrimaryView
]->deleteLater();
464 m_viewContainer
[PrimaryView
] = m_viewContainer
[SecondaryView
];
465 m_viewContainer
[SecondaryView
] = 0;
468 setActiveViewContainer(m_viewContainer
[PrimaryView
]);
470 emit
activeViewChanged(); // TODO unused; remove?
473 void DolphinMainWindow::reloadView()
476 m_activeViewContainer
->view()->reload();
479 void DolphinMainWindow::stopLoading()
483 void DolphinMainWindow::toggleFilterBarVisibility(bool show
)
485 m_activeViewContainer
->showFilterBar(show
);
488 void DolphinMainWindow::toggleEditLocation()
492 QAction
* action
= actionCollection()->action("editable_location");
493 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
494 urlNavigator
->setUrlEditable(action
->isChecked());
497 void DolphinMainWindow::editLocation()
499 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
500 navigator
->setUrlEditable(true);
501 navigator
->setFocus();
503 // select the whole text of the combo box editor
504 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit();
505 const QString text
= lineEdit
->text();
506 lineEdit
->setSelection(0, text
.length());
509 void DolphinMainWindow::adjustViewProperties()
512 ViewPropertiesDialog
dlg(m_activeViewContainer
->view());
516 void DolphinMainWindow::goBack()
519 m_activeViewContainer
->urlNavigator()->goBack();
522 void DolphinMainWindow::goForward()
525 m_activeViewContainer
->urlNavigator()->goForward();
528 void DolphinMainWindow::goUp()
531 m_activeViewContainer
->urlNavigator()->goUp();
534 void DolphinMainWindow::goHome()
537 m_activeViewContainer
->urlNavigator()->goHome();
540 void DolphinMainWindow::findFile()
542 KRun::run("kfind", m_activeViewContainer
->url(), this);
545 void DolphinMainWindow::compareFiles()
547 // The method is only invoked if exactly 2 files have
548 // been selected. The selected files may be:
549 // - both in the primary view
550 // - both in the secondary view
551 // - one in the primary view and the other in the secondary
553 Q_ASSERT(m_viewContainer
[PrimaryView
] != 0);
557 KUrl::List urls
= m_viewContainer
[PrimaryView
]->view()->selectedUrls();
559 switch (urls
.count()) {
561 Q_ASSERT(m_viewContainer
[SecondaryView
] != 0);
562 urls
= m_viewContainer
[SecondaryView
]->view()->selectedUrls();
563 Q_ASSERT(urls
.count() == 2);
571 Q_ASSERT(m_viewContainer
[SecondaryView
] != 0);
572 urls
= m_viewContainer
[SecondaryView
]->view()->selectedUrls();
573 Q_ASSERT(urls
.count() == 1);
585 // may not happen: compareFiles may only get invoked if 2
586 // files are selected
591 QString
command("kompare -c \"");
592 command
.append(urlA
.pathOrUrl());
593 command
.append("\" \"");
594 command
.append(urlB
.pathOrUrl());
595 command
.append('\"');
596 KRun::runCommand(command
, "Kompare", "kompare", this);
600 void DolphinMainWindow::toggleShowMenuBar()
602 const bool visible
= menuBar()->isVisible();
603 menuBar()->setVisible(!visible
);
606 void DolphinMainWindow::editSettings()
608 DolphinSettingsDialog
dialog(this);
612 void DolphinMainWindow::init()
614 DolphinSettings
& settings
= DolphinSettings::instance();
616 // Check whether Dolphin runs the first time. If yes then
617 // a proper default window size is given at the end of DolphinMainWindow::init().
618 GeneralSettings
* generalSettings
= settings
.generalSettings();
619 const bool firstRun
= generalSettings
->firstRun();
621 generalSettings
->setViewPropsTimestamp(QDateTime::currentDateTime());
624 setAcceptDrops(true);
626 m_splitter
= new QSplitter(this);
630 const KUrl
& homeUrl
= generalSettings
->homeUrl();
631 setCaption(homeUrl
.fileName());
632 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
633 connect(m_actionHandler
, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
634 ViewProperties
props(homeUrl
);
635 m_viewContainer
[PrimaryView
] = new DolphinViewContainer(this,
639 m_activeViewContainer
= m_viewContainer
[PrimaryView
];
640 connectViewSignals(PrimaryView
);
641 DolphinView
* view
= m_viewContainer
[PrimaryView
]->view();
643 m_viewContainer
[PrimaryView
]->show();
644 m_actionHandler
->setCurrentView(view
);
646 setCentralWidget(m_splitter
);
649 setupGUI(Keys
| Save
| Create
| ToolBar
);
652 stateChanged("new_file");
653 setAutoSaveSettings();
655 QClipboard
* clipboard
= QApplication::clipboard();
656 connect(clipboard
, SIGNAL(dataChanged()),
657 this, SLOT(updatePasteAction()));
661 if (generalSettings
->splitView()) {
667 // assure a proper default size if Dolphin runs the first time
671 emit
urlChanged(homeUrl
);
674 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer
* viewContainer
)
676 Q_ASSERT(viewContainer
!= 0);
677 Q_ASSERT((viewContainer
== m_viewContainer
[PrimaryView
]) || (viewContainer
== m_viewContainer
[SecondaryView
]));
678 if (m_activeViewContainer
== viewContainer
) {
682 m_activeViewContainer
->setActive(false);
683 m_activeViewContainer
= viewContainer
;
684 m_activeViewContainer
->setActive(true);
691 const KUrl
& url
= m_activeViewContainer
->url();
692 setCaption(url
.fileName());
694 m_actionHandler
->setCurrentView(viewContainer
->view());
696 emit
activeViewChanged(); // TODO unused; remove?
697 emit
urlChanged(url
);
700 void DolphinMainWindow::setupActions()
703 m_newMenu
= new DolphinNewMenu(this);
704 KMenu
* menu
= m_newMenu
->menu();
705 menu
->setTitle(i18nc("@title:menu", "Create New"));
706 menu
->setIcon(KIcon("document-new"));
707 connect(menu
, SIGNAL(aboutToShow()),
708 this, SLOT(updateNewMenu()));
710 KAction
* newWindow
= actionCollection()->addAction("new_window");
711 newWindow
->setIcon(KIcon("window-new"));
712 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
713 newWindow
->setShortcut(Qt::CTRL
| Qt::Key_N
);
714 connect(newWindow
, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
716 KAction
* properties
= actionCollection()->addAction("properties");
717 properties
->setText(i18nc("@action:inmenu File", "Properties"));
718 properties
->setShortcut(Qt::ALT
| Qt::Key_Return
);
719 connect(properties
, SIGNAL(triggered()), this, SLOT(properties()));
721 KStandardAction::quit(this, SLOT(quit()), actionCollection());
724 KStandardAction::undo(this,
728 // need to remove shift+del from cut action, else the shortcut for deletejob
730 KAction
* cut
= KStandardAction::cut(this, SLOT(cut()), actionCollection());
731 KShortcut cutShortcut
= cut
->shortcut();
732 cutShortcut
.remove(Qt::SHIFT
+ Qt::Key_Delete
, KShortcut::KeepEmpty
);
733 cut
->setShortcut(cutShortcut
);
734 KStandardAction::copy(this, SLOT(copy()), actionCollection());
735 KStandardAction::paste(this, SLOT(paste()), actionCollection());
737 KAction
* selectAll
= actionCollection()->addAction("select_all");
738 selectAll
->setText(i18nc("@action:inmenu Edit", "Select All"));
739 selectAll
->setShortcut(Qt::CTRL
+ Qt::Key_A
);
740 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
742 KAction
* invertSelection
= actionCollection()->addAction("invert_selection");
743 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
744 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
745 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
748 // (note that most of it is set up in DolphinViewActionHandler)
750 KAction
* split
= actionCollection()->addAction("split_view");
751 split
->setShortcut(Qt::Key_F3
);
753 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
755 KAction
* reload
= actionCollection()->addAction("reload");
756 reload
->setText(i18nc("@action:inmenu View", "Reload"));
757 reload
->setShortcut(Qt::Key_F5
);
758 reload
->setIcon(KIcon("view-refresh"));
759 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
761 KAction
* stop
= actionCollection()->addAction("stop");
762 stop
->setText(i18nc("@action:inmenu View", "Stop"));
763 stop
->setIcon(KIcon("process-stop"));
764 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
766 // TODO: the naming "Show full Location" is currently confusing...
767 KToggleAction
* showFullLocation
= actionCollection()->add
<KToggleAction
>("editable_location");
768 showFullLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Show Full Location"));
769 showFullLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
770 connect(showFullLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
772 KAction
* editLocation
= actionCollection()->addAction("edit_location");
773 editLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Edit Location"));
774 editLocation
->setShortcut(Qt::Key_F6
);
775 connect(editLocation
, SIGNAL(triggered()), this, SLOT(editLocation()));
777 KAction
* adjustViewProps
= actionCollection()->addAction("view_properties");
778 adjustViewProps
->setText(i18nc("@action:inmenu View", "Adjust View Properties..."));
779 connect(adjustViewProps
, SIGNAL(triggered()), this, SLOT(adjustViewProperties()));
782 KAction
* backAction
= KStandardAction::back(this, SLOT(goBack()), actionCollection());
783 KShortcut backShortcut
= backAction
->shortcut();
784 backShortcut
.setAlternate(Qt::Key_Backspace
);
785 backAction
->setShortcut(backShortcut
);
787 KStandardAction::forward(this, SLOT(goForward()), actionCollection());
788 KStandardAction::up(this, SLOT(goUp()), actionCollection());
789 KStandardAction::home(this, SLOT(goHome()), actionCollection());
791 // setup 'Tools' menu
792 QAction
* findFile
= actionCollection()->addAction("find_file");
793 findFile
->setText(i18nc("@action:inmenu Tools", "Find File..."));
794 findFile
->setShortcut(Qt::CTRL
| Qt::Key_F
);
795 findFile
->setIcon(KIcon("edit-find"));
796 connect(findFile
, SIGNAL(triggered()), this, SLOT(findFile()));
798 KToggleAction
* showFilterBar
= actionCollection()->add
<KToggleAction
>("show_filter_bar");
799 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
800 showFilterBar
->setShortcut(Qt::CTRL
| Qt::Key_I
);
801 connect(showFilterBar
, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
803 KAction
* compareFiles
= actionCollection()->addAction("compare_files");
804 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
805 compareFiles
->setIcon(KIcon("kompare"));
806 compareFiles
->setEnabled(false);
807 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
809 // setup 'Settings' menu
810 m_showMenuBar
= KStandardAction::showMenubar(this, SLOT(toggleShowMenuBar()), actionCollection());
811 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
814 void DolphinMainWindow::setupDockWidgets()
816 // setup "Information"
817 QDockWidget
* infoDock
= new QDockWidget(i18nc("@title:window", "Information"));
818 infoDock
->setObjectName("infoDock");
819 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
820 SidebarPage
* infoWidget
= new InfoSidebarPage(infoDock
);
821 infoDock
->setWidget(infoWidget
);
823 infoDock
->toggleViewAction()->setText(i18nc("@title:window", "Information"));
824 infoDock
->toggleViewAction()->setShortcut(Qt::Key_F11
);
825 actionCollection()->addAction("show_info_panel", infoDock
->toggleViewAction());
827 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
828 connect(this, SIGNAL(urlChanged(KUrl
)),
829 infoWidget
, SLOT(setUrl(KUrl
)));
830 connect(this, SIGNAL(selectionChanged(KFileItemList
)),
831 infoWidget
, SLOT(setSelection(KFileItemList
)));
832 connect(this, SIGNAL(requestItemInfo(KFileItem
)),
833 infoWidget
, SLOT(requestDelayedItemInfo(KFileItem
)));
836 QDockWidget
* treeViewDock
= new QDockWidget(i18nc("@title:window", "Folders"));
837 treeViewDock
->setObjectName("treeViewDock");
838 treeViewDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
839 TreeViewSidebarPage
* treeWidget
= new TreeViewSidebarPage(treeViewDock
);
840 treeViewDock
->setWidget(treeWidget
);
842 treeViewDock
->toggleViewAction()->setText(i18nc("@title:window", "Folders"));
843 treeViewDock
->toggleViewAction()->setShortcut(Qt::Key_F7
);
844 actionCollection()->addAction("show_folders_panel", treeViewDock
->toggleViewAction());
846 addDockWidget(Qt::LeftDockWidgetArea
, treeViewDock
);
847 connect(this, SIGNAL(urlChanged(KUrl
)),
848 treeWidget
, SLOT(setUrl(KUrl
)));
849 connect(treeWidget
, SIGNAL(changeUrl(KUrl
)),
850 this, SLOT(changeUrl(KUrl
)));
851 connect(treeWidget
, SIGNAL(changeSelection(KFileItemList
)),
852 this, SLOT(changeSelection(KFileItemList
)));
853 connect(treeWidget
, SIGNAL(urlsDropped(KUrl::List
, KUrl
)),
854 this, SLOT(dropUrls(KUrl::List
, KUrl
)));
857 QDockWidget
* terminalDock
= new QDockWidget(i18nc("@title:window", "Terminal"));
858 terminalDock
->setObjectName("terminalDock");
859 terminalDock
->setAllowedAreas(Qt::TopDockWidgetArea
| Qt::BottomDockWidgetArea
);
860 SidebarPage
* terminalWidget
= new TerminalSidebarPage(terminalDock
);
861 terminalDock
->setWidget(terminalWidget
);
863 connect(terminalWidget
, SIGNAL(hideTerminalSidebarPage()), terminalDock
, SLOT(hide()));
865 terminalDock
->toggleViewAction()->setText(i18nc("@title:window", "Terminal"));
866 terminalDock
->toggleViewAction()->setShortcut(Qt::Key_F4
);
867 actionCollection()->addAction("show_terminal_panel", terminalDock
->toggleViewAction());
869 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
870 connect(this, SIGNAL(urlChanged(KUrl
)),
871 terminalWidget
, SLOT(setUrl(KUrl
)));
873 const bool firstRun
= DolphinSettings::instance().generalSettings()->firstRun();
876 treeViewDock
->hide();
877 terminalDock
->hide();
880 QDockWidget
* placesDock
= new QDockWidget(i18nc("@title:window", "Places"));
881 placesDock
->setObjectName("placesDock");
882 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
884 DolphinFilePlacesView
* placesView
= new DolphinFilePlacesView(placesDock
);
885 placesDock
->setWidget(placesView
);
886 placesView
->setModel(DolphinSettings::instance().placesModel());
887 placesView
->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff
);
889 placesDock
->toggleViewAction()->setText(i18nc("@title:window", "Places"));
890 placesDock
->toggleViewAction()->setShortcut(Qt::Key_F9
);
891 actionCollection()->addAction("show_places_panel", placesDock
->toggleViewAction());
893 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
894 connect(placesView
, SIGNAL(urlChanged(KUrl
)),
895 this, SLOT(changeUrl(KUrl
)));
896 connect(this, SIGNAL(urlChanged(KUrl
)),
897 placesView
, SLOT(setUrl(KUrl
)));
900 void DolphinMainWindow::updateHistory()
902 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
903 const int index
= urlNavigator
->historyIndex();
905 QAction
* backAction
= actionCollection()->action("go_back");
906 if (backAction
!= 0) {
907 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
910 QAction
* forwardAction
= actionCollection()->action("go_forward");
911 if (forwardAction
!= 0) {
912 forwardAction
->setEnabled(index
> 0);
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(slotHistoryChanged()));
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"