]>
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 "dolphinnewmenu.h"
30 #include "dolphinsettings.h"
31 #include "dolphinsettingsdialog.h"
32 #include "dolphinstatusbar.h"
33 #include "dolphinviewcontainer.h"
34 #include "infosidebarpage.h"
35 #include "metadatawidget.h"
36 #include "mainwindowadaptor.h"
37 #include "terminalsidebarpage.h"
38 #include "treeviewsidebarpage.h"
39 #include "kurlnavigator.h"
40 #include "viewpropertiesdialog.h"
41 #include "viewproperties.h"
42 #include "kfileplacesmodel.h"
43 #include "kfileplacesview.h"
45 #include "dolphin_generalsettings.h"
46 #include "dolphin_iconsmodesettings.h"
49 #include <kactioncollection.h>
51 #include <kdesktopfile.h>
52 #include <kdeversion.h>
53 #include <kfiledialog.h>
56 #include <kiconloader.h>
57 #include <kio/netaccess.h>
58 #include <kinputdialog.h>
62 #include <kmessagebox.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::slotSelectionChanged(const KFileItemList
& selection
)
184 Q_ASSERT(m_viewContainer
[PrimaryView
] != 0);
185 int selectedUrlsCount
= m_viewContainer
[PrimaryView
]->view()->selectedUrls().count();
186 if (m_viewContainer
[SecondaryView
] != 0) {
187 selectedUrlsCount
+= m_viewContainer
[SecondaryView
]->view()->selectedUrls().count();
190 QAction
* compareFilesAction
= actionCollection()->action("compare_files");
191 if (selectedUrlsCount
== 2) {
192 const bool kompareInstalled
= !KGlobal::dirs()->findExe("kompare").isEmpty();
193 compareFilesAction
->setEnabled(selectedUrlsCount
== 2 && kompareInstalled
);
195 compareFilesAction
->setEnabled(false);
198 m_activeViewContainer
->updateStatusBar();
200 emit
selectionChanged(selection
);
203 void DolphinMainWindow::slotRequestItemInfo(const KFileItem
& item
)
205 emit
requestItemInfo(item
);
208 void DolphinMainWindow::slotHistoryChanged()
213 void DolphinMainWindow::updateFilterBarAction(bool show
)
215 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
216 showFilterBarAction
->setChecked(show
);
219 void DolphinMainWindow::openNewMainWindow()
221 DolphinApplication::app()->createMainWindow()->show();
224 void DolphinMainWindow::toggleActiveView()
226 if (m_viewContainer
[SecondaryView
] == 0) {
227 // only one view is available
231 Q_ASSERT(m_activeViewContainer
!= 0);
232 Q_ASSERT(m_viewContainer
[PrimaryView
] != 0);
234 DolphinViewContainer
* left
= m_viewContainer
[PrimaryView
];
235 DolphinViewContainer
* right
= m_viewContainer
[SecondaryView
];
236 setActiveViewContainer(m_activeViewContainer
== right
? left
: right
);
239 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
241 DolphinSettings
& settings
= DolphinSettings::instance();
242 GeneralSettings
* generalSettings
= settings
.generalSettings();
243 generalSettings
->setFirstRun(false);
247 KXmlGuiWindow::closeEvent(event
);
250 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
252 DolphinViewContainer
* cont
= m_viewContainer
[PrimaryView
];
253 group
.writeEntry("Primary Url", cont
->url().url());
254 group
.writeEntry("Primary Editable Url", cont
->isUrlEditable());
256 cont
= m_viewContainer
[SecondaryView
];
258 group
.writeEntry("Secondary Url", cont
->url().url());
259 group
.writeEntry("Secondary Editable Url", cont
->isUrlEditable());
263 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
265 DolphinViewContainer
* cont
= m_viewContainer
[PrimaryView
];
267 cont
->setUrl(group
.readEntry("Primary Url"));
268 bool editable
= group
.readEntry("Primary Editable Url", false);
269 cont
->urlNavigator()->setUrlEditable(editable
);
271 cont
= m_viewContainer
[SecondaryView
];
272 const QString secondaryUrl
= group
.readEntry("Secondary Url");
273 if (!secondaryUrl
.isEmpty()) {
275 // a secondary view should be shown, but no one is available
276 // currently -> create a new view
278 cont
= m_viewContainer
[SecondaryView
];
282 cont
->setUrl(secondaryUrl
);
283 bool editable
= group
.readEntry("Secondary Editable Url", false);
284 cont
->urlNavigator()->setUrlEditable(editable
);
285 } else if (cont
!= 0) {
286 // no secondary view should be shown, but the default setting shows
287 // one already -> close the view
292 void DolphinMainWindow::updateNewMenu()
294 m_newMenu
->slotCheckUpToDate();
295 m_newMenu
->setPopupFiles(activeViewContainer()->url());
298 void DolphinMainWindow::properties()
300 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
302 KPropertiesDialog
*dialog
= new KPropertiesDialog(list
, this);
303 dialog
->setAttribute(Qt::WA_DeleteOnClose
);
306 dialog
->activateWindow();
309 void DolphinMainWindow::quit()
314 void DolphinMainWindow::slotHandlePlacesError(const QString
&message
)
316 if (!message
.isEmpty()) {
317 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
318 statusBar
->setMessage(message
, DolphinStatusBar::Error
);
322 void DolphinMainWindow::slotUndoAvailable(bool available
)
324 QAction
* undoAction
= actionCollection()->action(KStandardAction::stdName(KStandardAction::Undo
));
325 if (undoAction
!= 0) {
326 undoAction
->setEnabled(available
);
329 if (available
&& (m_undoCommandTypes
.count() > 0)) {
330 const KonqFileUndoManager::CommandType command
= m_undoCommandTypes
.takeFirst();
331 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
333 case KonqFileUndoManager::COPY
:
334 statusBar
->setMessage(i18nc("@info:status", "Copy operation completed."),
335 DolphinStatusBar::OperationCompleted
);
337 case KonqFileUndoManager::MOVE
:
338 statusBar
->setMessage(i18nc("@info:status", "Move operation completed."),
339 DolphinStatusBar::OperationCompleted
);
341 case KonqFileUndoManager::LINK
:
342 statusBar
->setMessage(i18nc("@info:status", "Link operation completed."),
343 DolphinStatusBar::OperationCompleted
);
345 case KonqFileUndoManager::TRASH
:
346 statusBar
->setMessage(i18nc("@info:status", "Move to trash operation completed."),
347 DolphinStatusBar::OperationCompleted
);
349 case KonqFileUndoManager::RENAME
:
350 statusBar
->setMessage(i18nc("@info:status", "Renaming operation completed."),
351 DolphinStatusBar::OperationCompleted
);
354 case KonqFileUndoManager::MKDIR
:
355 statusBar
->setMessage(i18nc("@info:status", "Created folder."),
356 DolphinStatusBar::OperationCompleted
);
366 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
368 QAction
* undoAction
= actionCollection()->action(KStandardAction::stdName(KStandardAction::Undo
));
369 if (undoAction
!= 0) {
370 undoAction
->setText(text
);
374 void DolphinMainWindow::undo()
377 KonqFileUndoManager::self()->undo();
380 void DolphinMainWindow::cut()
382 m_activeViewContainer
->view()->cutSelectedItems();
385 void DolphinMainWindow::copy()
387 m_activeViewContainer
->view()->copySelectedItems();
390 void DolphinMainWindow::paste()
392 m_activeViewContainer
->view()->paste();
395 void DolphinMainWindow::updatePasteAction()
397 QAction
* pasteAction
= actionCollection()->action(KStandardAction::stdName(KStandardAction::Paste
));
398 if (pasteAction
== 0) {
402 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
403 pasteAction
->setEnabled(pasteInfo
.first
);
404 pasteAction
->setText(pasteInfo
.second
);
407 void DolphinMainWindow::selectAll()
411 // if the URL navigator is editable and focused, select the whole
412 // URL instead of all items of the view
414 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
415 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit();
416 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
417 lineEdit
->hasFocus();
419 lineEdit
->selectAll();
421 m_activeViewContainer
->view()->selectAll();
425 void DolphinMainWindow::invertSelection()
428 m_activeViewContainer
->view()->invertSelection();
431 void DolphinMainWindow::toggleSplitView()
433 if (m_viewContainer
[SecondaryView
] == 0) {
434 // create a secondary view
435 const int newWidth
= (m_viewContainer
[PrimaryView
]->width() - m_splitter
->handleWidth()) / 2;
437 const DolphinView
* view
= m_viewContainer
[PrimaryView
]->view();
438 m_viewContainer
[SecondaryView
] = new DolphinViewContainer(this, 0, view
->rootUrl());
439 connectViewSignals(SecondaryView
);
440 m_splitter
->addWidget(m_viewContainer
[SecondaryView
]);
441 m_splitter
->setSizes(QList
<int>() << newWidth
<< newWidth
);
442 m_viewContainer
[SecondaryView
]->view()->reload();
443 m_viewContainer
[SecondaryView
]->setActive(false);
444 m_viewContainer
[SecondaryView
]->show();
445 } else if (m_activeViewContainer
== m_viewContainer
[PrimaryView
]) {
446 // remove secondary view
447 m_viewContainer
[SecondaryView
]->close();
448 m_viewContainer
[SecondaryView
]->deleteLater();
449 m_viewContainer
[SecondaryView
] = 0;
451 // The secondary view is active, hence from a users point of view
452 // the content of the secondary view should be moved to the primary view.
453 // From an implementation point of view it is more efficient to close
454 // the primary view and exchange the internal pointers afterwards.
455 m_viewContainer
[PrimaryView
]->close();
456 m_viewContainer
[PrimaryView
]->deleteLater();
457 m_viewContainer
[PrimaryView
] = m_viewContainer
[SecondaryView
];
458 m_viewContainer
[SecondaryView
] = 0;
461 setActiveViewContainer(m_viewContainer
[PrimaryView
]);
463 emit
activeViewChanged(); // TODO unused; remove?
466 void DolphinMainWindow::reloadView()
469 m_activeViewContainer
->view()->reload();
472 void DolphinMainWindow::stopLoading()
476 void DolphinMainWindow::toggleFilterBarVisibility(bool show
)
478 m_activeViewContainer
->showFilterBar(show
);
481 void DolphinMainWindow::toggleEditLocation()
485 QAction
* action
= actionCollection()->action("editable_location");
486 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
487 urlNavigator
->setUrlEditable(action
->isChecked());
490 void DolphinMainWindow::editLocation()
492 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
493 navigator
->setUrlEditable(true);
494 navigator
->setFocus();
497 void DolphinMainWindow::adjustViewProperties()
500 ViewPropertiesDialog
dlg(m_activeViewContainer
->view());
504 void DolphinMainWindow::goBack()
507 m_activeViewContainer
->urlNavigator()->goBack();
510 void DolphinMainWindow::goForward()
513 m_activeViewContainer
->urlNavigator()->goForward();
516 void DolphinMainWindow::goUp()
519 m_activeViewContainer
->urlNavigator()->goUp();
522 void DolphinMainWindow::goHome()
525 m_activeViewContainer
->urlNavigator()->goHome();
528 void DolphinMainWindow::findFile()
530 KRun::run("kfind", m_activeViewContainer
->url(), this);
533 void DolphinMainWindow::compareFiles()
535 // The method is only invoked if exactly 2 files have
536 // been selected. The selected files may be:
537 // - both in the primary view
538 // - both in the secondary view
539 // - one in the primary view and the other in the secondary
541 Q_ASSERT(m_viewContainer
[PrimaryView
] != 0);
545 KUrl::List urls
= m_viewContainer
[PrimaryView
]->view()->selectedUrls();
547 switch (urls
.count()) {
549 Q_ASSERT(m_viewContainer
[SecondaryView
] != 0);
550 urls
= m_viewContainer
[SecondaryView
]->view()->selectedUrls();
551 Q_ASSERT(urls
.count() == 2);
559 Q_ASSERT(m_viewContainer
[SecondaryView
] != 0);
560 urls
= m_viewContainer
[SecondaryView
]->view()->selectedUrls();
561 Q_ASSERT(urls
.count() == 1);
573 // may not happen: compareFiles may only get invoked if 2
574 // files are selected
579 QString
command("kompare -c \"");
580 command
.append(urlA
.pathOrUrl());
581 command
.append("\" \"");
582 command
.append(urlB
.pathOrUrl());
583 command
.append('\"');
584 KRun::runCommand(command
, "Kompare", "kompare", this);
588 void DolphinMainWindow::toggleShowMenuBar()
590 const bool visible
= menuBar()->isVisible();
591 menuBar()->setVisible(!visible
);
594 void DolphinMainWindow::editSettings()
596 DolphinSettingsDialog
dialog(this);
600 void DolphinMainWindow::init()
602 // Check whether Dolphin runs the first time. If yes then
603 // a proper default window size is given at the end of DolphinMainWindow::init().
604 GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
605 const bool firstRun
= generalSettings
->firstRun();
607 generalSettings
->setViewPropsTimestamp(QDateTime::currentDateTime());
610 setAcceptDrops(true);
612 m_splitter
= new QSplitter(this);
614 DolphinSettings
& settings
= DolphinSettings::instance();
618 const KUrl
& homeUrl
= settings
.generalSettings()->homeUrl();
619 setCaption(homeUrl
.fileName());
620 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
621 connect(m_actionHandler
, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
622 ViewProperties
props(homeUrl
);
623 m_viewContainer
[PrimaryView
] = new DolphinViewContainer(this,
627 m_activeViewContainer
= m_viewContainer
[PrimaryView
];
628 connectViewSignals(PrimaryView
);
629 DolphinView
* view
= m_viewContainer
[PrimaryView
]->view();
631 m_viewContainer
[PrimaryView
]->show();
632 m_actionHandler
->setCurrentView(view
);
634 setCentralWidget(m_splitter
);
637 setupGUI(Keys
| Save
| Create
| ToolBar
);
640 stateChanged("new_file");
641 setAutoSaveSettings();
643 QClipboard
* clipboard
= QApplication::clipboard();
644 connect(clipboard
, SIGNAL(dataChanged()),
645 this, SLOT(updatePasteAction()));
649 if (generalSettings
->splitView()) {
655 // assure a proper default size if Dolphin runs the first time
659 emit
urlChanged(homeUrl
);
662 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer
* viewContainer
)
664 Q_ASSERT(viewContainer
!= 0);
665 Q_ASSERT((viewContainer
== m_viewContainer
[PrimaryView
]) || (viewContainer
== m_viewContainer
[SecondaryView
]));
666 if (m_activeViewContainer
== viewContainer
) {
670 m_activeViewContainer
->setActive(false);
671 m_activeViewContainer
= viewContainer
;
672 m_activeViewContainer
->setActive(true);
679 const KUrl
& url
= m_activeViewContainer
->url();
680 setCaption(url
.fileName());
682 m_actionHandler
->setCurrentView(viewContainer
->view());
684 emit
activeViewChanged(); // TODO unused; remove?
685 emit
urlChanged(url
);
688 void DolphinMainWindow::setupActions()
691 m_newMenu
= new DolphinNewMenu(this);
692 KMenu
* menu
= m_newMenu
->menu();
693 menu
->setTitle(i18nc("@title:menu", "Create New"));
694 menu
->setIcon(KIcon("document-new"));
695 connect(menu
, SIGNAL(aboutToShow()),
696 this, SLOT(updateNewMenu()));
698 KAction
* newWindow
= actionCollection()->addAction("new_window");
699 newWindow
->setIcon(KIcon("window-new"));
700 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
701 newWindow
->setShortcut(Qt::CTRL
| Qt::Key_N
);
702 connect(newWindow
, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
704 KAction
* properties
= actionCollection()->addAction("properties");
705 properties
->setText(i18nc("@action:inmenu File", "Properties"));
706 properties
->setShortcut(Qt::ALT
| Qt::Key_Return
);
707 connect(properties
, SIGNAL(triggered()), this, SLOT(properties()));
709 KStandardAction::quit(this, SLOT(quit()), actionCollection());
712 KStandardAction::undo(this,
716 //Need to remove shift+del from cut action, else the shortcut for deletejob
718 KAction
* cut
= KStandardAction::cut(this, SLOT(cut()), actionCollection());
719 KShortcut cutShortcut
= cut
->shortcut();
720 cutShortcut
.remove(Qt::SHIFT
+ Qt::Key_Delete
, KShortcut::KeepEmpty
);
721 cut
->setShortcut(cutShortcut
);
722 KStandardAction::copy(this, SLOT(copy()), actionCollection());
723 KStandardAction::paste(this, SLOT(paste()), actionCollection());
725 KAction
* selectAll
= actionCollection()->addAction("select_all");
726 selectAll
->setText(i18nc("@action:inmenu Edit", "Select All"));
727 selectAll
->setShortcut(Qt::CTRL
+ Qt::Key_A
);
728 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
730 KAction
* invertSelection
= actionCollection()->addAction("invert_selection");
731 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
732 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
733 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
736 // (note that most of it is set up in DolphinViewActionHandler)
738 KAction
* split
= actionCollection()->addAction("split_view");
739 split
->setShortcut(Qt::Key_F3
);
741 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
743 KAction
* reload
= actionCollection()->addAction("reload");
744 reload
->setText(i18nc("@action:inmenu View", "Reload"));
745 reload
->setShortcut(Qt::Key_F5
);
746 reload
->setIcon(KIcon("view-refresh"));
747 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
749 KAction
* stop
= actionCollection()->addAction("stop");
750 stop
->setText(i18nc("@action:inmenu View", "Stop"));
751 stop
->setIcon(KIcon("process-stop"));
752 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
754 // TODO: the URL navigator must emit a signal if the editable state has been
755 // changed, so that the corresponding showFullLocation action is updated. Also
756 // the naming "Show full Location" is currently confusing...
757 KToggleAction
* showFullLocation
= actionCollection()->add
<KToggleAction
>("editable_location");
758 showFullLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Show Full Location"));
759 showFullLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
760 connect(showFullLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
762 KAction
* editLocation
= actionCollection()->addAction("edit_location");
763 editLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Edit Location"));
764 editLocation
->setShortcut(Qt::Key_F6
);
765 connect(editLocation
, SIGNAL(triggered()), this, SLOT(editLocation()));
767 KAction
* adjustViewProps
= actionCollection()->addAction("view_properties");
768 adjustViewProps
->setText(i18nc("@action:inmenu View", "Adjust View Properties..."));
769 connect(adjustViewProps
, SIGNAL(triggered()), this, SLOT(adjustViewProperties()));
772 KAction
* backAction
= KStandardAction::back(this, SLOT(goBack()), actionCollection());
773 KShortcut backShortcut
= backAction
->shortcut();
774 backShortcut
.setAlternate(Qt::Key_Backspace
);
775 backAction
->setShortcut(backShortcut
);
777 KStandardAction::forward(this, SLOT(goForward()), actionCollection());
778 KStandardAction::up(this, SLOT(goUp()), actionCollection());
779 KStandardAction::home(this, SLOT(goHome()), actionCollection());
781 // setup 'Tools' menu
782 QAction
* findFile
= actionCollection()->addAction("find_file");
783 findFile
->setText(i18nc("@action:inmenu Tools", "Find File..."));
784 findFile
->setShortcut(Qt::CTRL
| Qt::Key_F
);
785 findFile
->setIcon(KIcon("edit-find"));
786 connect(findFile
, SIGNAL(triggered()), this, SLOT(findFile()));
788 KToggleAction
* showFilterBar
= actionCollection()->add
<KToggleAction
>("show_filter_bar");
789 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
790 showFilterBar
->setShortcut(Qt::CTRL
| Qt::Key_I
);
791 connect(showFilterBar
, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
793 KAction
* compareFiles
= actionCollection()->addAction("compare_files");
794 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
795 compareFiles
->setIcon(KIcon("kompare"));
796 compareFiles
->setEnabled(false);
797 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
799 // setup 'Settings' menu
800 m_showMenuBar
= KStandardAction::showMenubar(this, SLOT(toggleShowMenuBar()), actionCollection());
801 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
804 void DolphinMainWindow::setupDockWidgets()
806 // setup "Information"
807 QDockWidget
* infoDock
= new QDockWidget(i18nc("@title:window", "Information"));
808 infoDock
->setObjectName("infoDock");
809 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
810 SidebarPage
* infoWidget
= new InfoSidebarPage(infoDock
);
811 infoDock
->setWidget(infoWidget
);
813 infoDock
->toggleViewAction()->setText(i18nc("@title:window", "Information"));
814 infoDock
->toggleViewAction()->setShortcut(Qt::Key_F11
);
815 actionCollection()->addAction("show_info_panel", infoDock
->toggleViewAction());
817 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
818 connect(this, SIGNAL(urlChanged(KUrl
)),
819 infoWidget
, SLOT(setUrl(KUrl
)));
820 connect(this, SIGNAL(selectionChanged(KFileItemList
)),
821 infoWidget
, SLOT(setSelection(KFileItemList
)));
822 connect(this, SIGNAL(requestItemInfo(KFileItem
)),
823 infoWidget
, SLOT(requestDelayedItemInfo(KFileItem
)));
826 QDockWidget
* treeViewDock
= new QDockWidget(i18nc("@title:window", "Folders"));
827 treeViewDock
->setObjectName("treeViewDock");
828 treeViewDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
829 TreeViewSidebarPage
* treeWidget
= new TreeViewSidebarPage(treeViewDock
);
830 treeViewDock
->setWidget(treeWidget
);
832 treeViewDock
->toggleViewAction()->setText(i18nc("@title:window", "Folders"));
833 treeViewDock
->toggleViewAction()->setShortcut(Qt::Key_F7
);
834 actionCollection()->addAction("show_folders_panel", treeViewDock
->toggleViewAction());
836 addDockWidget(Qt::LeftDockWidgetArea
, treeViewDock
);
837 connect(this, SIGNAL(urlChanged(KUrl
)),
838 treeWidget
, SLOT(setUrl(KUrl
)));
839 connect(treeWidget
, SIGNAL(changeUrl(KUrl
)),
840 this, SLOT(changeUrl(KUrl
)));
841 connect(treeWidget
, SIGNAL(changeSelection(KFileItemList
)),
842 this, SLOT(changeSelection(KFileItemList
)));
843 connect(treeWidget
, SIGNAL(urlsDropped(KUrl::List
, KUrl
)),
844 this, SLOT(dropUrls(KUrl::List
, KUrl
)));
847 QDockWidget
* terminalDock
= new QDockWidget(i18nc("@title:window", "Terminal"));
848 terminalDock
->setObjectName("terminalDock");
849 terminalDock
->setAllowedAreas(Qt::TopDockWidgetArea
| Qt::BottomDockWidgetArea
);
850 SidebarPage
* terminalWidget
= new TerminalSidebarPage(terminalDock
);
851 terminalDock
->setWidget(terminalWidget
);
853 connect(terminalWidget
, SIGNAL(hideTerminalSidebarPage()), terminalDock
, SLOT(hide()));
855 terminalDock
->toggleViewAction()->setText(i18nc("@title:window", "Terminal"));
856 terminalDock
->toggleViewAction()->setShortcut(Qt::Key_F4
);
857 actionCollection()->addAction("show_terminal_panel", terminalDock
->toggleViewAction());
859 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
860 connect(this, SIGNAL(urlChanged(KUrl
)),
861 terminalWidget
, SLOT(setUrl(KUrl
)));
863 const bool firstRun
= DolphinSettings::instance().generalSettings()->firstRun();
866 treeViewDock
->hide();
867 terminalDock
->hide();
870 QDockWidget
* placesDock
= new QDockWidget(i18nc("@title:window", "Places"));
871 placesDock
->setObjectName("placesDock");
872 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
873 KFilePlacesView
* placesView
= new KFilePlacesView(placesDock
);
874 placesDock
->setWidget(placesView
);
875 placesView
->setModel(DolphinSettings::instance().placesModel());
876 placesView
->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff
);
878 placesDock
->toggleViewAction()->setText(i18nc("@title:window", "Places"));
879 placesDock
->toggleViewAction()->setShortcut(Qt::Key_F9
);
880 actionCollection()->addAction("show_places_panel", placesDock
->toggleViewAction());
882 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
883 connect(placesView
, SIGNAL(urlChanged(KUrl
)),
884 this, SLOT(changeUrl(KUrl
)));
885 connect(this, SIGNAL(urlChanged(KUrl
)),
886 placesView
, SLOT(setUrl(KUrl
)));
889 void DolphinMainWindow::updateHistory()
891 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
892 const int index
= urlNavigator
->historyIndex();
894 QAction
* backAction
= actionCollection()->action("go_back");
895 if (backAction
!= 0) {
896 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
899 QAction
* forwardAction
= actionCollection()->action("go_forward");
900 if (forwardAction
!= 0) {
901 forwardAction
->setEnabled(index
> 0);
905 void DolphinMainWindow::updateEditActions()
907 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
908 if (list
.isEmpty()) {
909 stateChanged("has_no_selection");
911 stateChanged("has_selection");
913 QAction
* renameAction
= actionCollection()->action("rename");
914 if (renameAction
!= 0) {
915 renameAction
->setEnabled(true);
918 bool enableMoveToTrash
= true;
920 KFileItemList::const_iterator it
= list
.begin();
921 const KFileItemList::const_iterator end
= list
.end();
923 const KUrl
& url
= (*it
).url();
924 // only enable the 'Move to Trash' action for local files
925 if (!url
.isLocalFile()) {
926 enableMoveToTrash
= false;
931 QAction
* moveToTrashAction
= actionCollection()->action("move_to_trash");
932 moveToTrashAction
->setEnabled(enableMoveToTrash
);
937 void DolphinMainWindow::updateViewActions()
939 m_actionHandler
->updateViewActions();
941 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
942 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
946 QAction
* editableLocactionAction
= actionCollection()->action("editable_location");
947 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
948 editableLocactionAction
->setChecked(urlNavigator
->isUrlEditable());
951 void DolphinMainWindow::updateGoActions()
953 QAction
* goUpAction
= actionCollection()->action(KStandardAction::stdName(KStandardAction::Up
));
954 const KUrl
& currentUrl
= m_activeViewContainer
->url();
955 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
958 void DolphinMainWindow::clearStatusBar()
960 m_activeViewContainer
->statusBar()->clear();
963 void DolphinMainWindow::connectViewSignals(int viewIndex
)
965 DolphinViewContainer
* container
= m_viewContainer
[viewIndex
];
966 connect(container
, SIGNAL(showFilterBarChanged(bool)),
967 this, SLOT(updateFilterBarAction(bool)));
969 DolphinView
* view
= container
->view();
970 connect(view
, SIGNAL(selectionChanged(KFileItemList
)),
971 this, SLOT(slotSelectionChanged(KFileItemList
)));
972 connect(view
, SIGNAL(requestItemInfo(KFileItem
)),
973 this, SLOT(slotRequestItemInfo(KFileItem
)));
974 connect(view
, SIGNAL(activated()),
975 this, SLOT(toggleActiveView()));
976 connect(view
, SIGNAL(doingOperation(KonqFileUndoManager::CommandType
)),
977 this, SLOT(slotDoingOperation(KonqFileUndoManager::CommandType
)));
979 const KUrlNavigator
* navigator
= container
->urlNavigator();
980 connect(navigator
, SIGNAL(urlChanged(const KUrl
&)),
981 this, SLOT(changeUrl(const KUrl
&)));
982 connect(navigator
, SIGNAL(historyChanged()),
983 this, SLOT(slotHistoryChanged()));
986 void DolphinMainWindow::updateSplitAction()
988 QAction
* splitAction
= actionCollection()->action("split_view");
989 if (m_viewContainer
[SecondaryView
] != 0) {
990 if (m_activeViewContainer
== m_viewContainer
[PrimaryView
]) {
991 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
992 splitAction
->setIcon(KIcon("view-right-close"));
994 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
995 splitAction
->setIcon(KIcon("view-left-close"));
998 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
999 splitAction
->setIcon(KIcon("view-right-new"));
1003 DolphinMainWindow::UndoUiInterface::UndoUiInterface(DolphinMainWindow
* mainWin
) :
1004 KonqFileUndoManager::UiInterface(mainWin
),
1007 Q_ASSERT(m_mainWin
!= 0);
1010 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
1014 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
1016 DolphinStatusBar
* statusBar
= m_mainWin
->activeViewContainer()->statusBar();
1017 statusBar
->setMessage(job
->errorString(), DolphinStatusBar::Error
);
1020 #include "dolphinmainwindow.moc"