]>
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::updateHistory()
217 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
218 const int index
= urlNavigator
->historyIndex();
220 QAction
* backAction
= actionCollection()->action("go_back");
221 if (backAction
!= 0) {
222 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
225 QAction
* forwardAction
= actionCollection()->action("go_forward");
226 if (forwardAction
!= 0) {
227 forwardAction
->setEnabled(index
> 0);
231 void DolphinMainWindow::updateFilterBarAction(bool show
)
233 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
234 showFilterBarAction
->setChecked(show
);
237 void DolphinMainWindow::openNewMainWindow()
239 DolphinApplication::app()->createMainWindow()->show();
242 void DolphinMainWindow::toggleActiveView()
244 if (m_viewContainer
[SecondaryView
] == 0) {
245 // only one view is available
249 Q_ASSERT(m_activeViewContainer
!= 0);
250 Q_ASSERT(m_viewContainer
[PrimaryView
] != 0);
252 DolphinViewContainer
* left
= m_viewContainer
[PrimaryView
];
253 DolphinViewContainer
* right
= m_viewContainer
[SecondaryView
];
254 setActiveViewContainer(m_activeViewContainer
== right
? left
: right
);
257 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
259 DolphinSettings
& settings
= DolphinSettings::instance();
260 GeneralSettings
* generalSettings
= settings
.generalSettings();
261 generalSettings
->setFirstRun(false);
265 KXmlGuiWindow::closeEvent(event
);
268 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
270 DolphinViewContainer
* cont
= m_viewContainer
[PrimaryView
];
271 group
.writeEntry("Primary Url", cont
->url().url());
272 group
.writeEntry("Primary Editable Url", cont
->isUrlEditable());
274 cont
= m_viewContainer
[SecondaryView
];
276 group
.writeEntry("Secondary Url", cont
->url().url());
277 group
.writeEntry("Secondary Editable Url", cont
->isUrlEditable());
281 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
283 DolphinViewContainer
* cont
= m_viewContainer
[PrimaryView
];
285 cont
->setUrl(group
.readEntry("Primary Url"));
286 bool editable
= group
.readEntry("Primary Editable Url", false);
287 cont
->urlNavigator()->setUrlEditable(editable
);
289 cont
= m_viewContainer
[SecondaryView
];
290 const QString secondaryUrl
= group
.readEntry("Secondary Url");
291 if (!secondaryUrl
.isEmpty()) {
293 // a secondary view should be shown, but no one is available
294 // currently -> create a new view
296 cont
= m_viewContainer
[SecondaryView
];
300 cont
->setUrl(secondaryUrl
);
301 bool editable
= group
.readEntry("Secondary Editable Url", false);
302 cont
->urlNavigator()->setUrlEditable(editable
);
303 } else if (cont
!= 0) {
304 // no secondary view should be shown, but the default setting shows
305 // one already -> close the view
310 void DolphinMainWindow::updateNewMenu()
312 m_newMenu
->slotCheckUpToDate();
313 m_newMenu
->setPopupFiles(activeViewContainer()->url());
316 void DolphinMainWindow::properties()
318 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
320 KPropertiesDialog
*dialog
= new KPropertiesDialog(list
, this);
321 dialog
->setAttribute(Qt::WA_DeleteOnClose
);
324 dialog
->activateWindow();
327 void DolphinMainWindow::quit()
332 void DolphinMainWindow::slotHandlePlacesError(const QString
&message
)
334 if (!message
.isEmpty()) {
335 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
336 statusBar
->setMessage(message
, DolphinStatusBar::Error
);
340 void DolphinMainWindow::slotUndoAvailable(bool available
)
342 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
343 if (undoAction
!= 0) {
344 undoAction
->setEnabled(available
);
347 if (available
&& (m_undoCommandTypes
.count() > 0)) {
348 const KonqFileUndoManager::CommandType command
= m_undoCommandTypes
.takeFirst();
349 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
351 case KonqFileUndoManager::COPY
:
352 statusBar
->setMessage(i18nc("@info:status", "Copy operation completed."),
353 DolphinStatusBar::OperationCompleted
);
355 case KonqFileUndoManager::MOVE
:
356 statusBar
->setMessage(i18nc("@info:status", "Move operation completed."),
357 DolphinStatusBar::OperationCompleted
);
359 case KonqFileUndoManager::LINK
:
360 statusBar
->setMessage(i18nc("@info:status", "Link operation completed."),
361 DolphinStatusBar::OperationCompleted
);
363 case KonqFileUndoManager::TRASH
:
364 statusBar
->setMessage(i18nc("@info:status", "Move to trash operation completed."),
365 DolphinStatusBar::OperationCompleted
);
367 case KonqFileUndoManager::RENAME
:
368 statusBar
->setMessage(i18nc("@info:status", "Renaming operation completed."),
369 DolphinStatusBar::OperationCompleted
);
372 case KonqFileUndoManager::MKDIR
:
373 statusBar
->setMessage(i18nc("@info:status", "Created folder."),
374 DolphinStatusBar::OperationCompleted
);
384 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
386 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
387 if (undoAction
!= 0) {
388 undoAction
->setText(text
);
392 void DolphinMainWindow::undo()
395 KonqFileUndoManager::self()->undo();
398 void DolphinMainWindow::cut()
400 m_activeViewContainer
->view()->cutSelectedItems();
403 void DolphinMainWindow::copy()
405 m_activeViewContainer
->view()->copySelectedItems();
408 void DolphinMainWindow::paste()
410 m_activeViewContainer
->view()->paste();
413 void DolphinMainWindow::updatePasteAction()
415 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
416 if (pasteAction
== 0) {
420 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
421 pasteAction
->setEnabled(pasteInfo
.first
);
422 pasteAction
->setText(pasteInfo
.second
);
425 void DolphinMainWindow::selectAll()
429 // if the URL navigator is editable and focused, select the whole
430 // URL instead of all items of the view
432 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
433 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit();
434 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
435 lineEdit
->hasFocus();
437 lineEdit
->selectAll();
439 m_activeViewContainer
->view()->selectAll();
443 void DolphinMainWindow::invertSelection()
446 m_activeViewContainer
->view()->invertSelection();
449 void DolphinMainWindow::toggleSplitView()
451 if (m_viewContainer
[SecondaryView
] == 0) {
452 // create a secondary view
453 const int newWidth
= (m_viewContainer
[PrimaryView
]->width() - m_splitter
->handleWidth()) / 2;
455 const DolphinView
* view
= m_viewContainer
[PrimaryView
]->view();
456 m_viewContainer
[SecondaryView
] = new DolphinViewContainer(this, 0, view
->rootUrl());
457 connectViewSignals(SecondaryView
);
458 m_splitter
->addWidget(m_viewContainer
[SecondaryView
]);
459 m_splitter
->setSizes(QList
<int>() << newWidth
<< newWidth
);
460 m_viewContainer
[SecondaryView
]->view()->reload();
461 m_viewContainer
[SecondaryView
]->setActive(false);
462 m_viewContainer
[SecondaryView
]->show();
463 } else if (m_activeViewContainer
== m_viewContainer
[PrimaryView
]) {
464 // remove secondary view
465 m_viewContainer
[SecondaryView
]->close();
466 m_viewContainer
[SecondaryView
]->deleteLater();
467 m_viewContainer
[SecondaryView
] = 0;
469 // The secondary view is active, hence from a users point of view
470 // the content of the secondary view should be moved to the primary view.
471 // From an implementation point of view it is more efficient to close
472 // the primary view and exchange the internal pointers afterwards.
473 m_viewContainer
[PrimaryView
]->close();
474 m_viewContainer
[PrimaryView
]->deleteLater();
475 m_viewContainer
[PrimaryView
] = m_viewContainer
[SecondaryView
];
476 m_viewContainer
[SecondaryView
] = 0;
479 setActiveViewContainer(m_viewContainer
[PrimaryView
]);
481 emit
activeViewChanged(); // TODO unused; remove?
484 void DolphinMainWindow::reloadView()
487 m_activeViewContainer
->view()->reload();
490 void DolphinMainWindow::stopLoading()
494 void DolphinMainWindow::toggleFilterBarVisibility(bool show
)
496 m_activeViewContainer
->showFilterBar(show
);
499 void DolphinMainWindow::toggleEditLocation()
503 QAction
* action
= actionCollection()->action("editable_location");
504 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
505 urlNavigator
->setUrlEditable(action
->isChecked());
508 void DolphinMainWindow::editLocation()
510 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
511 navigator
->setUrlEditable(true);
512 navigator
->setFocus();
514 // select the whole text of the combo box editor
515 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit();
516 const QString text
= lineEdit
->text();
517 lineEdit
->setSelection(0, text
.length());
520 void DolphinMainWindow::adjustViewProperties()
523 ViewPropertiesDialog
dlg(m_activeViewContainer
->view());
527 void DolphinMainWindow::goBack()
530 m_activeViewContainer
->urlNavigator()->goBack();
533 void DolphinMainWindow::goForward()
536 m_activeViewContainer
->urlNavigator()->goForward();
539 void DolphinMainWindow::goUp()
542 m_activeViewContainer
->urlNavigator()->goUp();
545 void DolphinMainWindow::goHome()
548 m_activeViewContainer
->urlNavigator()->goHome();
551 void DolphinMainWindow::findFile()
553 KRun::run("kfind", m_activeViewContainer
->url(), this);
556 void DolphinMainWindow::compareFiles()
558 // The method is only invoked if exactly 2 files have
559 // been selected. The selected files may be:
560 // - both in the primary view
561 // - both in the secondary view
562 // - one in the primary view and the other in the secondary
564 Q_ASSERT(m_viewContainer
[PrimaryView
] != 0);
568 KUrl::List urls
= m_viewContainer
[PrimaryView
]->view()->selectedUrls();
570 switch (urls
.count()) {
572 Q_ASSERT(m_viewContainer
[SecondaryView
] != 0);
573 urls
= m_viewContainer
[SecondaryView
]->view()->selectedUrls();
574 Q_ASSERT(urls
.count() == 2);
582 Q_ASSERT(m_viewContainer
[SecondaryView
] != 0);
583 urls
= m_viewContainer
[SecondaryView
]->view()->selectedUrls();
584 Q_ASSERT(urls
.count() == 1);
596 // may not happen: compareFiles may only get invoked if 2
597 // files are selected
602 QString
command("kompare -c \"");
603 command
.append(urlA
.pathOrUrl());
604 command
.append("\" \"");
605 command
.append(urlB
.pathOrUrl());
606 command
.append('\"');
607 KRun::runCommand(command
, "Kompare", "kompare", this);
611 void DolphinMainWindow::toggleShowMenuBar()
613 const bool visible
= menuBar()->isVisible();
614 menuBar()->setVisible(!visible
);
617 void DolphinMainWindow::editSettings()
619 DolphinSettingsDialog
dialog(this);
623 void DolphinMainWindow::init()
625 DolphinSettings
& settings
= DolphinSettings::instance();
627 // Check whether Dolphin runs the first time. If yes then
628 // a proper default window size is given at the end of DolphinMainWindow::init().
629 GeneralSettings
* generalSettings
= settings
.generalSettings();
630 const bool firstRun
= generalSettings
->firstRun();
632 generalSettings
->setViewPropsTimestamp(QDateTime::currentDateTime());
635 setAcceptDrops(true);
637 m_splitter
= new QSplitter(this);
641 const KUrl
& homeUrl
= generalSettings
->homeUrl();
642 setCaption(homeUrl
.fileName());
643 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
644 connect(m_actionHandler
, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
645 ViewProperties
props(homeUrl
);
646 m_viewContainer
[PrimaryView
] = new DolphinViewContainer(this,
650 m_activeViewContainer
= m_viewContainer
[PrimaryView
];
651 connectViewSignals(PrimaryView
);
652 DolphinView
* view
= m_viewContainer
[PrimaryView
]->view();
654 m_viewContainer
[PrimaryView
]->show();
655 m_actionHandler
->setCurrentView(view
);
657 setCentralWidget(m_splitter
);
660 setupGUI(Keys
| Save
| Create
| ToolBar
);
663 stateChanged("new_file");
664 setAutoSaveSettings();
666 QClipboard
* clipboard
= QApplication::clipboard();
667 connect(clipboard
, SIGNAL(dataChanged()),
668 this, SLOT(updatePasteAction()));
672 if (generalSettings
->splitView()) {
678 // assure a proper default size if Dolphin runs the first time
682 emit
urlChanged(homeUrl
);
685 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer
* viewContainer
)
687 Q_ASSERT(viewContainer
!= 0);
688 Q_ASSERT((viewContainer
== m_viewContainer
[PrimaryView
]) || (viewContainer
== m_viewContainer
[SecondaryView
]));
689 if (m_activeViewContainer
== viewContainer
) {
693 m_activeViewContainer
->setActive(false);
694 m_activeViewContainer
= viewContainer
;
695 m_activeViewContainer
->setActive(true);
702 const KUrl
& url
= m_activeViewContainer
->url();
703 setCaption(url
.fileName());
705 m_actionHandler
->setCurrentView(viewContainer
->view());
707 emit
activeViewChanged(); // TODO unused; remove?
708 emit
urlChanged(url
);
711 void DolphinMainWindow::setupActions()
714 m_newMenu
= new DolphinNewMenu(this);
715 KMenu
* menu
= m_newMenu
->menu();
716 menu
->setTitle(i18nc("@title:menu", "Create New"));
717 menu
->setIcon(KIcon("document-new"));
718 connect(menu
, SIGNAL(aboutToShow()),
719 this, SLOT(updateNewMenu()));
721 KAction
* newWindow
= actionCollection()->addAction("new_window");
722 newWindow
->setIcon(KIcon("window-new"));
723 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
724 newWindow
->setShortcut(Qt::CTRL
| Qt::Key_N
);
725 connect(newWindow
, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
727 KAction
* properties
= actionCollection()->addAction("properties");
728 properties
->setText(i18nc("@action:inmenu File", "Properties"));
729 properties
->setShortcut(Qt::ALT
| Qt::Key_Return
);
730 connect(properties
, SIGNAL(triggered()), this, SLOT(properties()));
732 KStandardAction::quit(this, SLOT(quit()), actionCollection());
735 KStandardAction::undo(this,
739 // need to remove shift+del from cut action, else the shortcut for deletejob
741 KAction
* cut
= KStandardAction::cut(this, SLOT(cut()), actionCollection());
742 KShortcut cutShortcut
= cut
->shortcut();
743 cutShortcut
.remove(Qt::SHIFT
+ Qt::Key_Delete
, KShortcut::KeepEmpty
);
744 cut
->setShortcut(cutShortcut
);
745 KStandardAction::copy(this, SLOT(copy()), actionCollection());
746 KStandardAction::paste(this, SLOT(paste()), actionCollection());
748 KAction
* selectAll
= actionCollection()->addAction("select_all");
749 selectAll
->setText(i18nc("@action:inmenu Edit", "Select All"));
750 selectAll
->setShortcut(Qt::CTRL
+ Qt::Key_A
);
751 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
753 KAction
* invertSelection
= actionCollection()->addAction("invert_selection");
754 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
755 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
756 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
759 // (note that most of it is set up in DolphinViewActionHandler)
761 KAction
* split
= actionCollection()->addAction("split_view");
762 split
->setShortcut(Qt::Key_F3
);
764 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
766 KAction
* reload
= actionCollection()->addAction("reload");
767 reload
->setText(i18nc("@action:inmenu View", "Reload"));
768 reload
->setShortcut(Qt::Key_F5
);
769 reload
->setIcon(KIcon("view-refresh"));
770 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
772 KAction
* stop
= actionCollection()->addAction("stop");
773 stop
->setText(i18nc("@action:inmenu View", "Stop"));
774 stop
->setIcon(KIcon("process-stop"));
775 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
777 // TODO: the naming "Show full Location" is currently confusing...
778 KToggleAction
* showFullLocation
= actionCollection()->add
<KToggleAction
>("editable_location");
779 showFullLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Show Full Location"));
780 showFullLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
781 connect(showFullLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
783 KAction
* editLocation
= actionCollection()->addAction("edit_location");
784 editLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Edit Location"));
785 editLocation
->setShortcut(Qt::Key_F6
);
786 connect(editLocation
, SIGNAL(triggered()), this, SLOT(editLocation()));
788 KAction
* adjustViewProps
= actionCollection()->addAction("view_properties");
789 adjustViewProps
->setText(i18nc("@action:inmenu View", "Adjust View Properties..."));
790 connect(adjustViewProps
, SIGNAL(triggered()), this, SLOT(adjustViewProperties()));
793 KAction
* backAction
= KStandardAction::back(this, SLOT(goBack()), actionCollection());
794 KShortcut backShortcut
= backAction
->shortcut();
795 backShortcut
.setAlternate(Qt::Key_Backspace
);
796 backAction
->setShortcut(backShortcut
);
798 KStandardAction::forward(this, SLOT(goForward()), actionCollection());
799 KStandardAction::up(this, SLOT(goUp()), actionCollection());
800 KStandardAction::home(this, SLOT(goHome()), actionCollection());
802 // setup 'Tools' menu
803 QAction
* findFile
= actionCollection()->addAction("find_file");
804 findFile
->setText(i18nc("@action:inmenu Tools", "Find File..."));
805 findFile
->setShortcut(Qt::CTRL
| Qt::Key_F
);
806 findFile
->setIcon(KIcon("edit-find"));
807 connect(findFile
, SIGNAL(triggered()), this, SLOT(findFile()));
809 KToggleAction
* showFilterBar
= actionCollection()->add
<KToggleAction
>("show_filter_bar");
810 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
811 showFilterBar
->setShortcut(Qt::CTRL
| Qt::Key_I
);
812 connect(showFilterBar
, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
814 KAction
* compareFiles
= actionCollection()->addAction("compare_files");
815 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
816 compareFiles
->setIcon(KIcon("kompare"));
817 compareFiles
->setEnabled(false);
818 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
820 // setup 'Settings' menu
821 m_showMenuBar
= KStandardAction::showMenubar(this, SLOT(toggleShowMenuBar()), actionCollection());
822 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
825 void DolphinMainWindow::setupDockWidgets()
827 // setup "Information"
828 QDockWidget
* infoDock
= new QDockWidget(i18nc("@title:window", "Information"));
829 infoDock
->setObjectName("infoDock");
830 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
831 SidebarPage
* infoWidget
= new InfoSidebarPage(infoDock
);
832 infoDock
->setWidget(infoWidget
);
834 infoDock
->toggleViewAction()->setText(i18nc("@title:window", "Information"));
835 infoDock
->toggleViewAction()->setShortcut(Qt::Key_F11
);
836 actionCollection()->addAction("show_info_panel", infoDock
->toggleViewAction());
838 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
839 connect(this, SIGNAL(urlChanged(KUrl
)),
840 infoWidget
, SLOT(setUrl(KUrl
)));
841 connect(this, SIGNAL(selectionChanged(KFileItemList
)),
842 infoWidget
, SLOT(setSelection(KFileItemList
)));
843 connect(this, SIGNAL(requestItemInfo(KFileItem
)),
844 infoWidget
, SLOT(requestDelayedItemInfo(KFileItem
)));
847 QDockWidget
* treeViewDock
= new QDockWidget(i18nc("@title:window", "Folders"));
848 treeViewDock
->setObjectName("treeViewDock");
849 treeViewDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
850 TreeViewSidebarPage
* treeWidget
= new TreeViewSidebarPage(treeViewDock
);
851 treeViewDock
->setWidget(treeWidget
);
853 treeViewDock
->toggleViewAction()->setText(i18nc("@title:window", "Folders"));
854 treeViewDock
->toggleViewAction()->setShortcut(Qt::Key_F7
);
855 actionCollection()->addAction("show_folders_panel", treeViewDock
->toggleViewAction());
857 addDockWidget(Qt::LeftDockWidgetArea
, treeViewDock
);
858 connect(this, SIGNAL(urlChanged(KUrl
)),
859 treeWidget
, SLOT(setUrl(KUrl
)));
860 connect(treeWidget
, SIGNAL(changeUrl(KUrl
)),
861 this, SLOT(changeUrl(KUrl
)));
862 connect(treeWidget
, SIGNAL(changeSelection(KFileItemList
)),
863 this, SLOT(changeSelection(KFileItemList
)));
864 connect(treeWidget
, SIGNAL(urlsDropped(KUrl::List
, KUrl
)),
865 this, SLOT(dropUrls(KUrl::List
, KUrl
)));
868 QDockWidget
* terminalDock
= new QDockWidget(i18nc("@title:window", "Terminal"));
869 terminalDock
->setObjectName("terminalDock");
870 terminalDock
->setAllowedAreas(Qt::TopDockWidgetArea
| Qt::BottomDockWidgetArea
);
871 SidebarPage
* terminalWidget
= new TerminalSidebarPage(terminalDock
);
872 terminalDock
->setWidget(terminalWidget
);
874 connect(terminalWidget
, SIGNAL(hideTerminalSidebarPage()), terminalDock
, SLOT(hide()));
876 terminalDock
->toggleViewAction()->setText(i18nc("@title:window", "Terminal"));
877 terminalDock
->toggleViewAction()->setShortcut(Qt::Key_F4
);
878 actionCollection()->addAction("show_terminal_panel", terminalDock
->toggleViewAction());
880 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
881 connect(this, SIGNAL(urlChanged(KUrl
)),
882 terminalWidget
, SLOT(setUrl(KUrl
)));
884 const bool firstRun
= DolphinSettings::instance().generalSettings()->firstRun();
887 treeViewDock
->hide();
888 terminalDock
->hide();
891 QDockWidget
* placesDock
= new QDockWidget(i18nc("@title:window", "Places"));
892 placesDock
->setObjectName("placesDock");
893 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
895 DolphinFilePlacesView
* placesView
= new DolphinFilePlacesView(placesDock
);
896 placesDock
->setWidget(placesView
);
897 placesView
->setModel(DolphinSettings::instance().placesModel());
898 placesView
->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff
);
900 placesDock
->toggleViewAction()->setText(i18nc("@title:window", "Places"));
901 placesDock
->toggleViewAction()->setShortcut(Qt::Key_F9
);
902 actionCollection()->addAction("show_places_panel", placesDock
->toggleViewAction());
904 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
905 connect(placesView
, SIGNAL(urlChanged(KUrl
)),
906 this, SLOT(changeUrl(KUrl
)));
907 connect(this, SIGNAL(urlChanged(KUrl
)),
908 placesView
, SLOT(setUrl(KUrl
)));
911 void DolphinMainWindow::updateEditActions()
913 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
914 if (list
.isEmpty()) {
915 stateChanged("has_no_selection");
917 stateChanged("has_selection");
919 QAction
* renameAction
= actionCollection()->action("rename");
920 if (renameAction
!= 0) {
921 renameAction
->setEnabled(true);
924 bool enableMoveToTrash
= true;
926 KFileItemList::const_iterator it
= list
.begin();
927 const KFileItemList::const_iterator end
= list
.end();
929 const KUrl
& url
= (*it
).url();
930 // only enable the 'Move to Trash' action for local files
931 if (!url
.isLocalFile()) {
932 enableMoveToTrash
= false;
937 QAction
* moveToTrashAction
= actionCollection()->action("move_to_trash");
938 moveToTrashAction
->setEnabled(enableMoveToTrash
);
943 void DolphinMainWindow::updateViewActions()
945 m_actionHandler
->updateViewActions();
947 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
948 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
952 QAction
* editableLocactionAction
= actionCollection()->action("editable_location");
953 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
954 editableLocactionAction
->setChecked(urlNavigator
->isUrlEditable());
957 void DolphinMainWindow::updateGoActions()
959 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
960 const KUrl
& currentUrl
= m_activeViewContainer
->url();
961 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
964 void DolphinMainWindow::clearStatusBar()
966 m_activeViewContainer
->statusBar()->clear();
969 void DolphinMainWindow::connectViewSignals(int viewIndex
)
971 DolphinViewContainer
* container
= m_viewContainer
[viewIndex
];
972 connect(container
, SIGNAL(showFilterBarChanged(bool)),
973 this, SLOT(updateFilterBarAction(bool)));
975 DolphinView
* view
= container
->view();
976 connect(view
, SIGNAL(selectionChanged(KFileItemList
)),
977 this, SLOT(slotSelectionChanged(KFileItemList
)));
978 connect(view
, SIGNAL(requestItemInfo(KFileItem
)),
979 this, SLOT(slotRequestItemInfo(KFileItem
)));
980 connect(view
, SIGNAL(activated()),
981 this, SLOT(toggleActiveView()));
982 connect(view
, SIGNAL(doingOperation(KonqFileUndoManager::CommandType
)),
983 this, SLOT(slotDoingOperation(KonqFileUndoManager::CommandType
)));
985 const KUrlNavigator
* navigator
= container
->urlNavigator();
986 connect(navigator
, SIGNAL(urlChanged(const KUrl
&)),
987 this, SLOT(changeUrl(const KUrl
&)));
988 connect(navigator
, SIGNAL(historyChanged()),
989 this, SLOT(updateHistory()));
990 connect(navigator
, SIGNAL(editableStateChanged(bool)),
991 this, SLOT(slotEditableStateChanged(bool)));
994 void DolphinMainWindow::updateSplitAction()
996 QAction
* splitAction
= actionCollection()->action("split_view");
997 if (m_viewContainer
[SecondaryView
] != 0) {
998 if (m_activeViewContainer
== m_viewContainer
[PrimaryView
]) {
999 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
1000 splitAction
->setIcon(KIcon("view-right-close"));
1002 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
1003 splitAction
->setIcon(KIcon("view-left-close"));
1006 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
1007 splitAction
->setIcon(KIcon("view-right-new"));
1011 DolphinMainWindow::UndoUiInterface::UndoUiInterface(DolphinMainWindow
* mainWin
) :
1012 KonqFileUndoManager::UiInterface(mainWin
),
1015 Q_ASSERT(m_mainWin
!= 0);
1018 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
1022 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
1024 DolphinStatusBar
* statusBar
= m_mainWin
->activeViewContainer()->statusBar();
1025 statusBar
->setMessage(job
->errorString(), DolphinStatusBar::Error
);
1028 #include "dolphinmainwindow.moc"