]>
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),
94 setObjectName("Dolphin#");
95 m_viewContainer
[PrimaryView
] = 0;
96 m_viewContainer
[SecondaryView
] = 0;
98 new MainWindowAdaptor(this);
99 QDBusConnection::sessionBus().registerObject(QString("/dolphin/MainWindow%1").arg(m_id
), this);
101 KonqFileUndoManager::incRef();
103 KonqFileUndoManager
* undoManager
= KonqFileUndoManager::self();
104 undoManager
->setUiInterface(new UndoUiInterface(this));
106 connect(undoManager
, SIGNAL(undoAvailable(bool)),
107 this, SLOT(slotUndoAvailable(bool)));
108 connect(undoManager
, SIGNAL(undoTextChanged(const QString
&)),
109 this, SLOT(slotUndoTextChanged(const QString
&)));
110 connect(DolphinSettings::instance().placesModel(), SIGNAL(errorMessage(const QString
&)),
111 this, SLOT(slotHandlePlacesError(const QString
&)));
114 DolphinMainWindow::~DolphinMainWindow()
116 KonqFileUndoManager::decRef();
117 DolphinApplication::app()->removeMainWindow(this);
120 void DolphinMainWindow::toggleViews()
122 if (m_viewContainer
[SecondaryView
] == 0) {
126 // move secondary view from the last position of the splitter
127 // to the first position
128 m_splitter
->insertWidget(0, m_viewContainer
[SecondaryView
]);
130 DolphinViewContainer
* container
= m_viewContainer
[PrimaryView
];
131 m_viewContainer
[PrimaryView
] = m_viewContainer
[SecondaryView
];
132 m_viewContainer
[SecondaryView
] = container
;
135 void DolphinMainWindow::slotDoingOperation(KonqFileUndoManager::CommandType commandType
)
138 m_undoCommandTypes
.append(commandType
);
141 void DolphinMainWindow::refreshViews()
143 Q_ASSERT(m_viewContainer
[PrimaryView
] != 0);
145 // remember the current active view, as because of
146 // the refreshing the active view might change to
147 // the secondary view
148 DolphinViewContainer
* activeViewContainer
= m_activeViewContainer
;
150 m_viewContainer
[PrimaryView
]->view()->refresh();
151 if (m_viewContainer
[SecondaryView
] != 0) {
152 m_viewContainer
[SecondaryView
]->view()->refresh();
155 setActiveViewContainer(activeViewContainer
);
158 void DolphinMainWindow::dropUrls(const KUrl::List
& urls
,
159 const KUrl
& destination
)
161 DolphinDropController
dropController(this);
162 connect(&dropController
, SIGNAL(doingOperation(KonqFileUndoManager::CommandType
)),
163 this, SLOT(slotDoingOperation(KonqFileUndoManager::CommandType
)));
164 dropController
.dropUrls(urls
, destination
);
167 void DolphinMainWindow::pasteIntoFolder()
169 m_activeViewContainer
->view()->pasteIntoFolder();
172 void DolphinMainWindow::changeUrl(const KUrl
& url
)
174 DolphinViewContainer
* view
= activeViewContainer();
180 setCaption(url
.fileName());
181 emit
urlChanged(url
);
185 void DolphinMainWindow::changeSelection(const KFileItemList
& selection
)
187 activeViewContainer()->view()->changeSelection(selection
);
190 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
192 KToggleAction
* editableLocationAction
=
193 static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
194 editableLocationAction
->setChecked(editable
);
197 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
201 Q_ASSERT(m_viewContainer
[PrimaryView
] != 0);
202 int selectedUrlsCount
= m_viewContainer
[PrimaryView
]->view()->selectedUrls().count();
203 if (m_viewContainer
[SecondaryView
] != 0) {
204 selectedUrlsCount
+= m_viewContainer
[SecondaryView
]->view()->selectedUrls().count();
207 QAction
* compareFilesAction
= actionCollection()->action("compare_files");
208 if (selectedUrlsCount
== 2) {
209 const bool kompareInstalled
= !KGlobal::dirs()->findExe("kompare").isEmpty();
210 compareFilesAction
->setEnabled(selectedUrlsCount
== 2 && kompareInstalled
);
212 compareFilesAction
->setEnabled(false);
215 m_activeViewContainer
->updateStatusBar();
217 emit
selectionChanged(selection
);
220 void DolphinMainWindow::slotRequestItemInfo(const KFileItem
& item
)
222 emit
requestItemInfo(item
);
225 void DolphinMainWindow::updateHistory()
227 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
228 const int index
= urlNavigator
->historyIndex();
230 QAction
* backAction
= actionCollection()->action("go_back");
231 if (backAction
!= 0) {
232 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
235 QAction
* forwardAction
= actionCollection()->action("go_forward");
236 if (forwardAction
!= 0) {
237 forwardAction
->setEnabled(index
> 0);
241 void DolphinMainWindow::updateFilterBarAction(bool show
)
243 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
244 showFilterBarAction
->setChecked(show
);
247 void DolphinMainWindow::openNewMainWindow()
249 DolphinApplication::app()->createMainWindow()->show();
252 void DolphinMainWindow::toggleActiveView()
254 if (m_viewContainer
[SecondaryView
] == 0) {
255 // only one view is available
259 Q_ASSERT(m_activeViewContainer
!= 0);
260 Q_ASSERT(m_viewContainer
[PrimaryView
] != 0);
262 DolphinViewContainer
* left
= m_viewContainer
[PrimaryView
];
263 DolphinViewContainer
* right
= m_viewContainer
[SecondaryView
];
264 setActiveViewContainer(m_activeViewContainer
== right
? left
: right
);
267 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
269 DolphinSettings
& settings
= DolphinSettings::instance();
270 GeneralSettings
* generalSettings
= settings
.generalSettings();
271 generalSettings
->setFirstRun(false);
275 KXmlGuiWindow::closeEvent(event
);
278 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
280 DolphinViewContainer
* cont
= m_viewContainer
[PrimaryView
];
281 group
.writeEntry("Primary Url", cont
->url().url());
282 group
.writeEntry("Primary Editable Url", cont
->isUrlEditable());
284 cont
= m_viewContainer
[SecondaryView
];
286 group
.writeEntry("Secondary Url", cont
->url().url());
287 group
.writeEntry("Secondary Editable Url", cont
->isUrlEditable());
291 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
293 DolphinViewContainer
* cont
= m_viewContainer
[PrimaryView
];
295 cont
->setUrl(group
.readEntry("Primary Url"));
296 bool editable
= group
.readEntry("Primary Editable Url", false);
297 cont
->urlNavigator()->setUrlEditable(editable
);
299 cont
= m_viewContainer
[SecondaryView
];
300 const QString secondaryUrl
= group
.readEntry("Secondary Url");
301 if (!secondaryUrl
.isEmpty()) {
303 // a secondary view should be shown, but no one is available
304 // currently -> create a new view
306 cont
= m_viewContainer
[SecondaryView
];
310 cont
->setUrl(secondaryUrl
);
311 bool editable
= group
.readEntry("Secondary Editable Url", false);
312 cont
->urlNavigator()->setUrlEditable(editable
);
313 } else if (cont
!= 0) {
314 // no secondary view should be shown, but the default setting shows
315 // one already -> close the view
320 void DolphinMainWindow::updateNewMenu()
322 m_newMenu
->slotCheckUpToDate();
323 m_newMenu
->setPopupFiles(activeViewContainer()->url());
326 void DolphinMainWindow::properties()
328 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
330 KPropertiesDialog
*dialog
= new KPropertiesDialog(list
, this);
331 dialog
->setAttribute(Qt::WA_DeleteOnClose
);
334 dialog
->activateWindow();
337 void DolphinMainWindow::quit()
342 void DolphinMainWindow::slotHandlePlacesError(const QString
&message
)
344 if (!message
.isEmpty()) {
345 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
346 statusBar
->setMessage(message
, DolphinStatusBar::Error
);
350 void DolphinMainWindow::slotUndoAvailable(bool available
)
352 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
353 if (undoAction
!= 0) {
354 undoAction
->setEnabled(available
);
357 if (available
&& (m_undoCommandTypes
.count() > 0)) {
358 const KonqFileUndoManager::CommandType command
= m_undoCommandTypes
.takeFirst();
359 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
361 case KonqFileUndoManager::COPY
:
362 statusBar
->setMessage(i18nc("@info:status", "Copy operation completed."),
363 DolphinStatusBar::OperationCompleted
);
365 case KonqFileUndoManager::MOVE
:
366 statusBar
->setMessage(i18nc("@info:status", "Move operation completed."),
367 DolphinStatusBar::OperationCompleted
);
369 case KonqFileUndoManager::LINK
:
370 statusBar
->setMessage(i18nc("@info:status", "Link operation completed."),
371 DolphinStatusBar::OperationCompleted
);
373 case KonqFileUndoManager::TRASH
:
374 statusBar
->setMessage(i18nc("@info:status", "Move to trash operation completed."),
375 DolphinStatusBar::OperationCompleted
);
377 case KonqFileUndoManager::RENAME
:
378 statusBar
->setMessage(i18nc("@info:status", "Renaming operation completed."),
379 DolphinStatusBar::OperationCompleted
);
382 case KonqFileUndoManager::MKDIR
:
383 statusBar
->setMessage(i18nc("@info:status", "Created folder."),
384 DolphinStatusBar::OperationCompleted
);
394 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
396 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
397 if (undoAction
!= 0) {
398 undoAction
->setText(text
);
402 void DolphinMainWindow::undo()
405 KonqFileUndoManager::self()->undo();
408 void DolphinMainWindow::cut()
410 m_activeViewContainer
->view()->cutSelectedItems();
413 void DolphinMainWindow::copy()
415 m_activeViewContainer
->view()->copySelectedItems();
418 void DolphinMainWindow::paste()
420 m_activeViewContainer
->view()->paste();
423 void DolphinMainWindow::updatePasteAction()
425 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
426 if (pasteAction
== 0) {
430 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
431 pasteAction
->setEnabled(pasteInfo
.first
);
432 pasteAction
->setText(pasteInfo
.second
);
435 void DolphinMainWindow::selectAll()
439 // if the URL navigator is editable and focused, select the whole
440 // URL instead of all items of the view
442 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
443 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit();
444 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
445 lineEdit
->hasFocus();
447 lineEdit
->selectAll();
449 m_activeViewContainer
->view()->selectAll();
453 void DolphinMainWindow::invertSelection()
456 m_activeViewContainer
->view()->invertSelection();
459 void DolphinMainWindow::toggleSplitView()
461 if (m_viewContainer
[SecondaryView
] == 0) {
462 // create a secondary view
463 const int newWidth
= (m_viewContainer
[PrimaryView
]->width() - m_splitter
->handleWidth()) / 2;
465 const DolphinView
* view
= m_viewContainer
[PrimaryView
]->view();
466 m_viewContainer
[SecondaryView
] = new DolphinViewContainer(this, 0, view
->rootUrl());
467 connectViewSignals(SecondaryView
);
468 m_splitter
->addWidget(m_viewContainer
[SecondaryView
]);
469 m_splitter
->setSizes(QList
<int>() << newWidth
<< newWidth
);
470 m_viewContainer
[SecondaryView
]->view()->reload();
471 m_viewContainer
[SecondaryView
]->setActive(false);
472 m_viewContainer
[SecondaryView
]->show();
473 } else if (m_activeViewContainer
== m_viewContainer
[PrimaryView
]) {
474 // remove secondary view
475 m_viewContainer
[SecondaryView
]->close();
476 m_viewContainer
[SecondaryView
]->deleteLater();
477 m_viewContainer
[SecondaryView
] = 0;
479 // The secondary view is active, hence from a users point of view
480 // the content of the secondary view should be moved to the primary view.
481 // From an implementation point of view it is more efficient to close
482 // the primary view and exchange the internal pointers afterwards.
483 m_viewContainer
[PrimaryView
]->close();
484 m_viewContainer
[PrimaryView
]->deleteLater();
485 m_viewContainer
[PrimaryView
] = m_viewContainer
[SecondaryView
];
486 m_viewContainer
[SecondaryView
] = 0;
489 setActiveViewContainer(m_viewContainer
[PrimaryView
]);
493 void DolphinMainWindow::reloadView()
496 m_activeViewContainer
->view()->reload();
499 void DolphinMainWindow::stopLoading()
503 void DolphinMainWindow::toggleFilterBarVisibility(bool show
)
505 m_activeViewContainer
->showFilterBar(show
);
508 void DolphinMainWindow::toggleEditLocation()
512 QAction
* action
= actionCollection()->action("editable_location");
513 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
514 urlNavigator
->setUrlEditable(action
->isChecked());
517 void DolphinMainWindow::editLocation()
519 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
520 navigator
->setUrlEditable(true);
521 navigator
->setFocus();
523 // select the whole text of the combo box editor
524 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit();
525 const QString text
= lineEdit
->text();
526 lineEdit
->setSelection(0, text
.length());
529 void DolphinMainWindow::adjustViewProperties()
532 ViewPropertiesDialog
dlg(m_activeViewContainer
->view());
536 void DolphinMainWindow::goBack()
539 m_activeViewContainer
->urlNavigator()->goBack();
542 void DolphinMainWindow::goForward()
545 m_activeViewContainer
->urlNavigator()->goForward();
548 void DolphinMainWindow::goUp()
551 m_activeViewContainer
->urlNavigator()->goUp();
554 void DolphinMainWindow::goHome()
557 m_activeViewContainer
->urlNavigator()->goHome();
560 void DolphinMainWindow::findFile()
562 KRun::run("kfind", m_activeViewContainer
->url(), this);
565 void DolphinMainWindow::compareFiles()
567 // The method is only invoked if exactly 2 files have
568 // been selected. The selected files may be:
569 // - both in the primary view
570 // - both in the secondary view
571 // - one in the primary view and the other in the secondary
573 Q_ASSERT(m_viewContainer
[PrimaryView
] != 0);
577 KUrl::List urls
= m_viewContainer
[PrimaryView
]->view()->selectedUrls();
579 switch (urls
.count()) {
581 Q_ASSERT(m_viewContainer
[SecondaryView
] != 0);
582 urls
= m_viewContainer
[SecondaryView
]->view()->selectedUrls();
583 Q_ASSERT(urls
.count() == 2);
591 Q_ASSERT(m_viewContainer
[SecondaryView
] != 0);
592 urls
= m_viewContainer
[SecondaryView
]->view()->selectedUrls();
593 Q_ASSERT(urls
.count() == 1);
605 // may not happen: compareFiles may only get invoked if 2
606 // files are selected
611 QString
command("kompare -c \"");
612 command
.append(urlA
.pathOrUrl());
613 command
.append("\" \"");
614 command
.append(urlB
.pathOrUrl());
615 command
.append('\"');
616 KRun::runCommand(command
, "Kompare", "kompare", this);
620 void DolphinMainWindow::toggleShowMenuBar()
622 const bool visible
= menuBar()->isVisible();
623 menuBar()->setVisible(!visible
);
626 void DolphinMainWindow::editSettings()
628 DolphinSettingsDialog
dialog(this);
632 void DolphinMainWindow::init()
634 DolphinSettings
& settings
= DolphinSettings::instance();
636 // Check whether Dolphin runs the first time. If yes then
637 // a proper default window size is given at the end of DolphinMainWindow::init().
638 GeneralSettings
* generalSettings
= settings
.generalSettings();
639 const bool firstRun
= generalSettings
->firstRun();
641 generalSettings
->setViewPropsTimestamp(QDateTime::currentDateTime());
644 setAcceptDrops(true);
646 m_splitter
= new QSplitter(this);
650 const KUrl
& homeUrl
= generalSettings
->homeUrl();
651 setCaption(homeUrl
.fileName());
652 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
653 connect(m_actionHandler
, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
654 ViewProperties
props(homeUrl
);
655 m_viewContainer
[PrimaryView
] = new DolphinViewContainer(this,
659 m_activeViewContainer
= m_viewContainer
[PrimaryView
];
660 connectViewSignals(PrimaryView
);
661 DolphinView
* view
= m_viewContainer
[PrimaryView
]->view();
663 m_viewContainer
[PrimaryView
]->show();
664 m_actionHandler
->setCurrentView(view
);
666 setCentralWidget(m_splitter
);
669 setupGUI(Keys
| Save
| Create
| ToolBar
);
672 stateChanged("new_file");
673 setAutoSaveSettings();
675 QClipboard
* clipboard
= QApplication::clipboard();
676 connect(clipboard
, SIGNAL(dataChanged()),
677 this, SLOT(updatePasteAction()));
681 if (generalSettings
->splitView()) {
687 // assure a proper default size if Dolphin runs the first time
691 emit
urlChanged(homeUrl
);
694 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer
* viewContainer
)
696 Q_ASSERT(viewContainer
!= 0);
697 Q_ASSERT((viewContainer
== m_viewContainer
[PrimaryView
]) || (viewContainer
== m_viewContainer
[SecondaryView
]));
698 if (m_activeViewContainer
== viewContainer
) {
702 m_activeViewContainer
->setActive(false);
703 m_activeViewContainer
= viewContainer
;
704 m_activeViewContainer
->setActive(true);
706 m_actionHandler
->setCurrentView(viewContainer
->view());
713 const KUrl
& url
= m_activeViewContainer
->url();
714 setCaption(url
.fileName());
716 emit
urlChanged(url
);
719 void DolphinMainWindow::setupActions()
722 m_newMenu
= new DolphinNewMenu(this);
723 KMenu
* menu
= m_newMenu
->menu();
724 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
725 menu
->setIcon(KIcon("document-new"));
726 connect(menu
, SIGNAL(aboutToShow()),
727 this, SLOT(updateNewMenu()));
729 KAction
* newWindow
= actionCollection()->addAction("new_window");
730 newWindow
->setIcon(KIcon("window-new"));
731 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
732 newWindow
->setShortcut(Qt::CTRL
| Qt::Key_N
);
733 connect(newWindow
, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
735 KAction
* properties
= actionCollection()->addAction("properties");
736 properties
->setText(i18nc("@action:inmenu File", "Properties"));
737 properties
->setShortcut(Qt::ALT
| Qt::Key_Return
);
738 connect(properties
, SIGNAL(triggered()), this, SLOT(properties()));
740 KStandardAction::quit(this, SLOT(quit()), actionCollection());
743 KStandardAction::undo(this,
747 // need to remove shift+del from cut action, else the shortcut for deletejob
749 KAction
* cut
= KStandardAction::cut(this, SLOT(cut()), actionCollection());
750 KShortcut cutShortcut
= cut
->shortcut();
751 cutShortcut
.remove(Qt::SHIFT
+ Qt::Key_Delete
, KShortcut::KeepEmpty
);
752 cut
->setShortcut(cutShortcut
);
753 KStandardAction::copy(this, SLOT(copy()), actionCollection());
754 KStandardAction::paste(this, SLOT(paste()), actionCollection());
756 KAction
* selectAll
= actionCollection()->addAction("select_all");
757 selectAll
->setText(i18nc("@action:inmenu Edit", "Select All"));
758 selectAll
->setShortcut(Qt::CTRL
+ Qt::Key_A
);
759 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
761 KAction
* invertSelection
= actionCollection()->addAction("invert_selection");
762 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
763 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
764 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
767 // (note that most of it is set up in DolphinViewActionHandler)
769 KAction
* split
= actionCollection()->addAction("split_view");
770 split
->setShortcut(Qt::Key_F3
);
772 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
774 KAction
* reload
= actionCollection()->addAction("reload");
775 reload
->setText(i18nc("@action:inmenu View", "Reload"));
776 reload
->setShortcut(Qt::Key_F5
);
777 reload
->setIcon(KIcon("view-refresh"));
778 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
780 KAction
* stop
= actionCollection()->addAction("stop");
781 stop
->setText(i18nc("@action:inmenu View", "Stop"));
782 stop
->setIcon(KIcon("process-stop"));
783 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
785 // TODO: the naming "Show full Location" is currently confusing...
786 KToggleAction
* showFullLocation
= actionCollection()->add
<KToggleAction
>("editable_location");
787 showFullLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Show Full Location"));
788 showFullLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
789 connect(showFullLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
791 KAction
* editLocation
= actionCollection()->addAction("edit_location");
792 editLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Edit Location"));
793 editLocation
->setShortcut(Qt::Key_F6
);
794 connect(editLocation
, SIGNAL(triggered()), this, SLOT(editLocation()));
796 KAction
* adjustViewProps
= actionCollection()->addAction("view_properties");
797 adjustViewProps
->setText(i18nc("@action:inmenu View", "Adjust View Properties..."));
798 connect(adjustViewProps
, SIGNAL(triggered()), this, SLOT(adjustViewProperties()));
801 KAction
* backAction
= KStandardAction::back(this, SLOT(goBack()), actionCollection());
802 KShortcut backShortcut
= backAction
->shortcut();
803 backShortcut
.setAlternate(Qt::Key_Backspace
);
804 backAction
->setShortcut(backShortcut
);
806 KStandardAction::forward(this, SLOT(goForward()), actionCollection());
807 KStandardAction::up(this, SLOT(goUp()), actionCollection());
808 KStandardAction::home(this, SLOT(goHome()), actionCollection());
810 // setup 'Tools' menu
811 QAction
* findFile
= actionCollection()->addAction("find_file");
812 findFile
->setText(i18nc("@action:inmenu Tools", "Find File..."));
813 findFile
->setShortcut(Qt::CTRL
| Qt::Key_F
);
814 findFile
->setIcon(KIcon("edit-find"));
815 connect(findFile
, SIGNAL(triggered()), this, SLOT(findFile()));
817 KToggleAction
* showFilterBar
= actionCollection()->add
<KToggleAction
>("show_filter_bar");
818 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
819 showFilterBar
->setShortcut(Qt::CTRL
| Qt::Key_I
);
820 connect(showFilterBar
, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
822 KAction
* compareFiles
= actionCollection()->addAction("compare_files");
823 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
824 compareFiles
->setIcon(KIcon("kompare"));
825 compareFiles
->setEnabled(false);
826 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
828 // setup 'Settings' menu
829 m_showMenuBar
= KStandardAction::showMenubar(this, SLOT(toggleShowMenuBar()), actionCollection());
830 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
833 void DolphinMainWindow::setupDockWidgets()
835 // setup "Information"
836 QDockWidget
* infoDock
= new QDockWidget(i18nc("@title:window", "Information"));
837 infoDock
->setObjectName("infoDock");
838 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
839 SidebarPage
* infoWidget
= new InfoSidebarPage(infoDock
);
840 infoDock
->setWidget(infoWidget
);
842 infoDock
->toggleViewAction()->setText(i18nc("@title:window", "Information"));
843 infoDock
->toggleViewAction()->setShortcut(Qt::Key_F11
);
844 actionCollection()->addAction("show_info_panel", infoDock
->toggleViewAction());
846 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
847 connect(this, SIGNAL(urlChanged(KUrl
)),
848 infoWidget
, SLOT(setUrl(KUrl
)));
849 connect(this, SIGNAL(selectionChanged(KFileItemList
)),
850 infoWidget
, SLOT(setSelection(KFileItemList
)));
851 connect(this, SIGNAL(requestItemInfo(KFileItem
)),
852 infoWidget
, SLOT(requestDelayedItemInfo(KFileItem
)));
855 QDockWidget
* treeViewDock
= new QDockWidget(i18nc("@title:window", "Folders"));
856 treeViewDock
->setObjectName("treeViewDock");
857 treeViewDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
858 TreeViewSidebarPage
* treeWidget
= new TreeViewSidebarPage(treeViewDock
);
859 treeViewDock
->setWidget(treeWidget
);
861 treeViewDock
->toggleViewAction()->setText(i18nc("@title:window", "Folders"));
862 treeViewDock
->toggleViewAction()->setShortcut(Qt::Key_F7
);
863 actionCollection()->addAction("show_folders_panel", treeViewDock
->toggleViewAction());
865 addDockWidget(Qt::LeftDockWidgetArea
, treeViewDock
);
866 connect(this, SIGNAL(urlChanged(KUrl
)),
867 treeWidget
, SLOT(setUrl(KUrl
)));
868 connect(treeWidget
, SIGNAL(changeUrl(KUrl
)),
869 this, SLOT(changeUrl(KUrl
)));
870 connect(treeWidget
, SIGNAL(changeSelection(KFileItemList
)),
871 this, SLOT(changeSelection(KFileItemList
)));
872 connect(treeWidget
, SIGNAL(urlsDropped(KUrl::List
, KUrl
)),
873 this, SLOT(dropUrls(KUrl::List
, KUrl
)));
877 QDockWidget
* terminalDock
= new QDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
878 terminalDock
->setObjectName("terminalDock");
879 terminalDock
->setAllowedAreas(Qt::TopDockWidgetArea
| Qt::BottomDockWidgetArea
);
880 SidebarPage
* terminalWidget
= new TerminalSidebarPage(terminalDock
);
881 terminalDock
->setWidget(terminalWidget
);
883 connect(terminalWidget
, SIGNAL(hideTerminalSidebarPage()), terminalDock
, SLOT(hide()));
885 terminalDock
->toggleViewAction()->setText(i18nc("@title:window Shell terminal", "Terminal"));
886 terminalDock
->toggleViewAction()->setShortcut(Qt::Key_F4
);
887 actionCollection()->addAction("show_terminal_panel", terminalDock
->toggleViewAction());
889 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
890 connect(this, SIGNAL(urlChanged(KUrl
)),
891 terminalWidget
, SLOT(setUrl(KUrl
)));
894 const bool firstRun
= DolphinSettings::instance().generalSettings()->firstRun();
896 treeViewDock
->hide();
898 terminalDock
->hide();
902 QDockWidget
* placesDock
= new QDockWidget(i18nc("@title:window", "Places"));
903 placesDock
->setObjectName("placesDock");
904 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
906 DolphinFilePlacesView
* placesView
= new DolphinFilePlacesView(placesDock
);
907 placesDock
->setWidget(placesView
);
908 placesView
->setModel(DolphinSettings::instance().placesModel());
909 placesView
->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff
);
911 placesDock
->toggleViewAction()->setText(i18nc("@title:window", "Places"));
912 placesDock
->toggleViewAction()->setShortcut(Qt::Key_F9
);
913 actionCollection()->addAction("show_places_panel", placesDock
->toggleViewAction());
915 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
916 connect(placesView
, SIGNAL(urlChanged(KUrl
)),
917 this, SLOT(changeUrl(KUrl
)));
918 connect(this, SIGNAL(urlChanged(KUrl
)),
919 placesView
, SLOT(setUrl(KUrl
)));
922 void DolphinMainWindow::updateEditActions()
924 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
925 if (list
.isEmpty()) {
926 stateChanged("has_no_selection");
928 stateChanged("has_selection");
930 QAction
* renameAction
= actionCollection()->action("rename");
931 if (renameAction
!= 0) {
932 renameAction
->setEnabled(true);
935 bool enableMoveToTrash
= true;
937 KFileItemList::const_iterator it
= list
.begin();
938 const KFileItemList::const_iterator end
= list
.end();
940 const KUrl
& url
= (*it
).url();
941 // only enable the 'Move to Trash' action for local files
942 if (!url
.isLocalFile()) {
943 enableMoveToTrash
= false;
948 QAction
* moveToTrashAction
= actionCollection()->action("move_to_trash");
949 moveToTrashAction
->setEnabled(enableMoveToTrash
);
954 void DolphinMainWindow::updateViewActions()
956 m_actionHandler
->updateViewActions();
958 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
959 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
963 QAction
* editableLocactionAction
= actionCollection()->action("editable_location");
964 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
965 editableLocactionAction
->setChecked(urlNavigator
->isUrlEditable());
968 void DolphinMainWindow::updateGoActions()
970 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
971 const KUrl
& currentUrl
= m_activeViewContainer
->url();
972 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
975 void DolphinMainWindow::clearStatusBar()
977 m_activeViewContainer
->statusBar()->clear();
980 void DolphinMainWindow::connectViewSignals(int viewIndex
)
982 DolphinViewContainer
* container
= m_viewContainer
[viewIndex
];
983 connect(container
, SIGNAL(showFilterBarChanged(bool)),
984 this, SLOT(updateFilterBarAction(bool)));
986 DolphinView
* view
= container
->view();
987 connect(view
, SIGNAL(selectionChanged(KFileItemList
)),
988 this, SLOT(slotSelectionChanged(KFileItemList
)));
989 connect(view
, SIGNAL(requestItemInfo(KFileItem
)),
990 this, SLOT(slotRequestItemInfo(KFileItem
)));
991 connect(view
, SIGNAL(activated()),
992 this, SLOT(toggleActiveView()));
993 connect(view
, SIGNAL(doingOperation(KonqFileUndoManager::CommandType
)),
994 this, SLOT(slotDoingOperation(KonqFileUndoManager::CommandType
)));
996 const KUrlNavigator
* navigator
= container
->urlNavigator();
997 connect(navigator
, SIGNAL(urlChanged(const KUrl
&)),
998 this, SLOT(changeUrl(const KUrl
&)));
999 connect(navigator
, SIGNAL(historyChanged()),
1000 this, SLOT(updateHistory()));
1001 connect(navigator
, SIGNAL(editableStateChanged(bool)),
1002 this, SLOT(slotEditableStateChanged(bool)));
1005 void DolphinMainWindow::updateSplitAction()
1007 QAction
* splitAction
= actionCollection()->action("split_view");
1008 if (m_viewContainer
[SecondaryView
] != 0) {
1009 if (m_activeViewContainer
== m_viewContainer
[PrimaryView
]) {
1010 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
1011 splitAction
->setIcon(KIcon("view-right-close"));
1013 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
1014 splitAction
->setIcon(KIcon("view-left-close"));
1017 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
1018 splitAction
->setIcon(KIcon("view-right-new"));
1022 DolphinMainWindow::UndoUiInterface::UndoUiInterface(DolphinMainWindow
* mainWin
) :
1023 KonqFileUndoManager::UiInterface(mainWin
),
1026 Q_ASSERT(m_mainWin
!= 0);
1029 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
1033 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
1035 DolphinStatusBar
* statusBar
= m_mainWin
->activeViewContainer()->statusBar();
1036 statusBar
->setMessage(job
->errorString(), DolphinStatusBar::Error
);
1039 #include "dolphinmainwindow.moc"