]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.cpp
* assure that the keyboard focus is in the view when switching between tabs
[dolphin.git] / 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> *
5 * *
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. *
10 * *
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. *
15 * *
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 ***************************************************************************/
21
22 #include "dolphinmainwindow.h"
23 #include "dolphinviewactionhandler.h"
24
25 #include <config-nepomuk.h>
26
27 #include "dolphinapplication.h"
28 #include "dolphinfileplacesview.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 "treeviewsidebarpage.h"
38 #include "viewproperties.h"
39
40 #ifndef Q_OS_WIN
41 #include "terminalsidebarpage.h"
42 #endif
43
44 #include "dolphin_generalsettings.h"
45 #include "dolphin_iconsmodesettings.h"
46 #include "draganddrophelper.h"
47
48 #include <kaction.h>
49 #include <kactioncollection.h>
50 #include <kconfig.h>
51 #include <kdesktopfile.h>
52 #include <kdeversion.h>
53 #include <kfiledialog.h>
54 #include <kfileplacesmodel.h>
55 #include <kglobal.h>
56 #include <kicon.h>
57 #include <kiconloader.h>
58 #include <kio/netaccess.h>
59 #include <kinputdialog.h>
60 #include <klocale.h>
61 #include <kprotocolmanager.h>
62 #include <kmenu.h>
63 #include <kmenubar.h>
64 #include <kmessagebox.h>
65 #include <konq_fileitemcapabilities.h>
66 #include <konqmimedata.h>
67 #include <kprotocolinfo.h>
68 #include <krun.h>
69 #include <kshell.h>
70 #include <kstandarddirs.h>
71 #include <kstatusbar.h>
72 #include <kstandardaction.h>
73 #include <ktabbar.h>
74 #include <ktoggleaction.h>
75 #include <kurlnavigator.h>
76 #include <kurl.h>
77 #include <kurlcombobox.h>
78
79 #include <QDBusMessage>
80 #include <QKeyEvent>
81 #include <QClipboard>
82 #include <QLineEdit>
83 #include <QSplitter>
84 #include <QDockWidget>
85
86 DolphinMainWindow::DolphinMainWindow(int id) :
87 KXmlGuiWindow(0),
88 m_newMenu(0),
89 m_showMenuBar(0),
90 m_tabBar(0),
91 m_activeViewContainer(0),
92 m_centralWidgetLayout(0),
93 m_id(id),
94 m_tabIndex(0),
95 m_viewTab(),
96 m_actionHandler(0)
97 {
98 setObjectName("Dolphin#");
99
100 m_viewTab.append(ViewTab());
101
102 new MainWindowAdaptor(this);
103 QDBusConnection::sessionBus().registerObject(QString("/dolphin/MainWindow%1").arg(m_id), this);
104
105 KIO::FileUndoManager* undoManager = KIO::FileUndoManager::self();
106 undoManager->setUiInterface(new UndoUiInterface());
107
108 connect(undoManager, SIGNAL(undoAvailable(bool)),
109 this, SLOT(slotUndoAvailable(bool)));
110 connect(undoManager, SIGNAL(undoTextChanged(const QString&)),
111 this, SLOT(slotUndoTextChanged(const QString&)));
112 connect(undoManager, SIGNAL(jobRecordingStarted(CommandType)),
113 this, SLOT(clearStatusBar()));
114 connect(undoManager, SIGNAL(jobRecordingFinished(CommandType)),
115 this, SLOT(showCommand(CommandType)));
116 connect(DolphinSettings::instance().placesModel(), SIGNAL(errorMessage(const QString&)),
117 this, SLOT(showErrorMessage(const QString&)));
118 connect(&DragAndDropHelper::instance(), SIGNAL(errorMessage(const QString&)),
119 this, SLOT(showErrorMessage(const QString&)));
120 }
121
122 DolphinMainWindow::~DolphinMainWindow()
123 {
124 DolphinApplication::app()->removeMainWindow(this);
125 }
126
127 void DolphinMainWindow::toggleViews()
128 {
129 if (m_viewTab[m_tabIndex].primaryView == 0) {
130 return;
131 }
132
133 // move secondary view from the last position of the splitter
134 // to the first position
135 m_viewTab[m_tabIndex].splitter->insertWidget(0, m_viewTab[m_tabIndex].secondaryView);
136
137 DolphinViewContainer* container = m_viewTab[m_tabIndex].primaryView;
138 m_viewTab[m_tabIndex].primaryView = m_viewTab[m_tabIndex].secondaryView;
139 m_viewTab[m_tabIndex].secondaryView = container;
140 }
141
142 void DolphinMainWindow::showCommand(CommandType command)
143 {
144 DolphinStatusBar* statusBar = m_activeViewContainer->statusBar();
145 switch (command) {
146 case KIO::FileUndoManager::Copy:
147 statusBar->setMessage(i18nc("@info:status", "Copy operation completed."),
148 DolphinStatusBar::OperationCompleted);
149 break;
150 case KIO::FileUndoManager::Move:
151 statusBar->setMessage(i18nc("@info:status", "Move operation completed."),
152 DolphinStatusBar::OperationCompleted);
153 break;
154 case KIO::FileUndoManager::Link:
155 statusBar->setMessage(i18nc("@info:status", "Link operation completed."),
156 DolphinStatusBar::OperationCompleted);
157 break;
158 case KIO::FileUndoManager::Trash:
159 statusBar->setMessage(i18nc("@info:status", "Move to trash operation completed."),
160 DolphinStatusBar::OperationCompleted);
161 break;
162 case KIO::FileUndoManager::Rename:
163 statusBar->setMessage(i18nc("@info:status", "Renaming operation completed."),
164 DolphinStatusBar::OperationCompleted);
165 break;
166
167 case KIO::FileUndoManager::Mkdir:
168 statusBar->setMessage(i18nc("@info:status", "Created folder."),
169 DolphinStatusBar::OperationCompleted);
170 break;
171
172 default:
173 break;
174 }
175 }
176
177 void DolphinMainWindow::refreshViews()
178 {
179 Q_ASSERT(m_viewTab[m_tabIndex].primaryView != 0);
180
181 // remember the current active view, as because of
182 // the refreshing the active view might change to
183 // the secondary view
184 DolphinViewContainer* activeViewContainer = m_activeViewContainer;
185
186 const int tabCount = m_viewTab.count();
187 for (int i = 0; i < tabCount; ++i) {
188 m_viewTab[i].primaryView->refresh();
189 if (m_viewTab[i].secondaryView != 0) {
190 m_viewTab[i].secondaryView->refresh();
191 }
192 }
193
194 setActiveViewContainer(activeViewContainer);
195 }
196
197 void DolphinMainWindow::pasteIntoFolder()
198 {
199 m_activeViewContainer->view()->pasteIntoFolder();
200 }
201
202 void DolphinMainWindow::changeUrl(const KUrl& url)
203 {
204 if (!KProtocolManager::supportsListing(url)) {
205 // The URL navigator only checks for validity, not
206 // if the URL can be listed. An error message is
207 // shown due to DolphinViewContainer::restoreView().
208 return;
209 }
210
211 DolphinViewContainer* view = activeViewContainer();
212 if (view != 0) {
213 view->setUrl(url);
214 updateEditActions();
215 updateViewActions();
216 updateGoActions();
217 setCaption(url.fileName());
218 if (m_viewTab.count() > 1) {
219 m_tabBar->setTabText(m_tabIndex, tabName(url));
220 }
221 emit urlChanged(url);
222 }
223 }
224
225 void DolphinMainWindow::changeSelection(const KFileItemList& selection)
226 {
227 activeViewContainer()->view()->changeSelection(selection);
228 }
229
230 void DolphinMainWindow::slotEditableStateChanged(bool editable)
231 {
232 KToggleAction* editableLocationAction =
233 static_cast<KToggleAction*>(actionCollection()->action("editable_location"));
234 editableLocationAction->setChecked(editable);
235 }
236
237 void DolphinMainWindow::slotSelectionChanged(const KFileItemList& selection)
238 {
239 updateEditActions();
240
241 Q_ASSERT(m_viewTab[m_tabIndex].primaryView != 0);
242 int selectedUrlsCount = m_viewTab[m_tabIndex].primaryView->view()->selectedItemsCount();
243 if (m_viewTab[m_tabIndex].secondaryView != 0) {
244 selectedUrlsCount += m_viewTab[m_tabIndex].secondaryView->view()->selectedItemsCount();
245 }
246
247 QAction* compareFilesAction = actionCollection()->action("compare_files");
248 if (selectedUrlsCount == 2) {
249 compareFilesAction->setEnabled(isKompareInstalled());
250 } else {
251 compareFilesAction->setEnabled(false);
252 }
253
254 #if defined(QUICK_VIEW)
255 const bool activeViewHasSelection = (activeViewContainer()->view()->selectedItemsCount() > 0);
256 actionCollection()->action("quick_view")->setEnabled(activeViewHasSelection);
257 #endif
258
259 m_activeViewContainer->updateStatusBar();
260
261 emit selectionChanged(selection);
262 }
263
264 void DolphinMainWindow::slotRequestItemInfo(const KFileItem& item)
265 {
266 emit requestItemInfo(item);
267 }
268
269 void DolphinMainWindow::updateHistory()
270 {
271 const KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
272 const int index = urlNavigator->historyIndex();
273
274 QAction* backAction = actionCollection()->action("go_back");
275 if (backAction != 0) {
276 backAction->setEnabled(index < urlNavigator->historySize() - 1);
277 }
278
279 QAction* forwardAction = actionCollection()->action("go_forward");
280 if (forwardAction != 0) {
281 forwardAction->setEnabled(index > 0);
282 }
283 }
284
285 void DolphinMainWindow::updateFilterBarAction(bool show)
286 {
287 QAction* showFilterBarAction = actionCollection()->action("show_filter_bar");
288 showFilterBarAction->setChecked(show);
289 }
290
291 void DolphinMainWindow::openNewMainWindow()
292 {
293 DolphinApplication::app()->createMainWindow()->show();
294 }
295
296 void DolphinMainWindow::openNewTab()
297 {
298 openNewTab(m_activeViewContainer->url());
299 m_tabBar->setCurrentIndex(m_viewTab.count() - 1);
300
301 KUrlNavigator* navigator = m_activeViewContainer->urlNavigator();
302 if (navigator->isUrlEditable()) {
303 // if a new tab is opened and the URL is editable, assure that
304 // the user can edit the URL without manually setting the focus
305 navigator->setFocus();
306 }
307 }
308
309 void DolphinMainWindow::openNewTab(const KUrl& url)
310 {
311 if (m_viewTab.count() == 1) {
312 // Only one view is open currently and hence no tab is shown at
313 // all. Before creating a tab for 'url', provide a tab for the current URL.
314 m_tabBar->addTab(KIcon("folder"), tabName(m_activeViewContainer->url()));
315 m_tabBar->blockSignals(false);
316 }
317
318 m_tabBar->addTab(KIcon("folder"), tabName(url));
319
320 ViewTab viewTab;
321 viewTab.splitter = new QSplitter(this);
322 viewTab.primaryView = new DolphinViewContainer(this, viewTab.splitter, url);
323 viewTab.primaryView->setActive(false);
324 connectViewSignals(viewTab.primaryView);
325 viewTab.primaryView->view()->reload();
326
327 m_viewTab.append(viewTab);
328
329 actionCollection()->action("close_tab")->setEnabled(true);
330 }
331
332 void DolphinMainWindow::activateNextTab()
333 {
334 if (m_viewTab.count() == 1 || m_tabBar->count() < 2) {
335 return;
336 }
337
338 const int tabIndex = (m_tabBar->currentIndex() + 1) % m_tabBar->count();
339 m_tabBar->setCurrentIndex(tabIndex);
340 }
341
342 void DolphinMainWindow::activatePrevTab()
343 {
344 if (m_viewTab.count() == 1 || m_tabBar->count() < 2) {
345 return;
346 }
347
348 int tabIndex = m_tabBar->currentIndex() - 1;
349 if (tabIndex == -1) {
350 tabIndex = m_tabBar->count() - 1;
351 }
352 m_tabBar->setCurrentIndex(tabIndex);
353 }
354
355 void DolphinMainWindow::openInNewTab()
356 {
357 const KFileItemList list = m_activeViewContainer->view()->selectedItems();
358 if ((list.count() == 1) && list[0].isDir()) {
359 openNewTab(m_activeViewContainer->view()->selectedUrls()[0]);
360 m_tabBar->setCurrentIndex(m_viewTab.count() - 1);
361 }
362 }
363
364 void DolphinMainWindow::openInNewWindow()
365 {
366 const KFileItemList list = m_activeViewContainer->view()->selectedItems();
367 if ((list.count() == 1) && list[0].isDir()) {
368 DolphinMainWindow* window = DolphinApplication::app()->createMainWindow();
369 window->changeUrl(m_activeViewContainer->view()->selectedUrls()[0]);
370 window->show();
371 }
372 }
373
374 void DolphinMainWindow::toggleActiveView()
375 {
376 if (m_viewTab[m_tabIndex].secondaryView == 0) {
377 // only one view is available
378 return;
379 }
380
381 Q_ASSERT(m_activeViewContainer != 0);
382 Q_ASSERT(m_viewTab[m_tabIndex].primaryView != 0);
383
384 DolphinViewContainer* left = m_viewTab[m_tabIndex].primaryView;
385 DolphinViewContainer* right = m_viewTab[m_tabIndex].secondaryView;
386 setActiveViewContainer(m_activeViewContainer == right ? left : right);
387 }
388
389 void DolphinMainWindow::closeEvent(QCloseEvent* event)
390 {
391 DolphinSettings& settings = DolphinSettings::instance();
392 GeneralSettings* generalSettings = settings.generalSettings();
393 generalSettings->setFirstRun(false);
394
395 settings.save();
396
397 KXmlGuiWindow::closeEvent(event);
398 }
399
400 void DolphinMainWindow::saveProperties(KConfigGroup& group)
401 {
402 // TODO: remember tabs
403 DolphinViewContainer* cont = m_viewTab[m_tabIndex].primaryView;
404 group.writeEntry("Primary Url", cont->url().url());
405 group.writeEntry("Primary Editable Url", cont->isUrlEditable());
406
407 cont = m_viewTab[m_tabIndex].secondaryView;
408 if (cont != 0) {
409 group.writeEntry("Secondary Url", cont->url().url());
410 group.writeEntry("Secondary Editable Url", cont->isUrlEditable());
411 }
412 }
413
414 void DolphinMainWindow::readProperties(const KConfigGroup& group)
415 {
416 // TODO: read tabs
417 DolphinViewContainer* cont = m_viewTab[m_tabIndex].primaryView;
418
419 cont->setUrl(group.readEntry("Primary Url"));
420 bool editable = group.readEntry("Primary Editable Url", false);
421 cont->urlNavigator()->setUrlEditable(editable);
422
423 cont = m_viewTab[m_tabIndex].secondaryView;
424 const QString secondaryUrl = group.readEntry("Secondary Url");
425 if (!secondaryUrl.isEmpty()) {
426 if (cont == 0) {
427 // a secondary view should be shown, but no one is available
428 // currently -> create a new view
429 toggleSplitView();
430 cont = m_viewTab[m_tabIndex].secondaryView;
431 Q_ASSERT(cont != 0);
432 }
433
434 cont->setUrl(secondaryUrl);
435 bool editable = group.readEntry("Secondary Editable Url", false);
436 cont->urlNavigator()->setUrlEditable(editable);
437 } else if (cont != 0) {
438 // no secondary view should be shown, but the default setting shows
439 // one already -> close the view
440 toggleSplitView();
441 }
442 }
443
444 void DolphinMainWindow::updateNewMenu()
445 {
446 m_newMenu->slotCheckUpToDate();
447 m_newMenu->setPopupFiles(activeViewContainer()->url());
448 }
449
450 void DolphinMainWindow::quit()
451 {
452 close();
453 }
454
455 void DolphinMainWindow::showErrorMessage(const QString& message)
456 {
457 if (!message.isEmpty()) {
458 DolphinStatusBar* statusBar = m_activeViewContainer->statusBar();
459 statusBar->setMessage(message, DolphinStatusBar::Error);
460 }
461 }
462
463 void DolphinMainWindow::slotUndoAvailable(bool available)
464 {
465 QAction* undoAction = actionCollection()->action(KStandardAction::name(KStandardAction::Undo));
466 if (undoAction != 0) {
467 undoAction->setEnabled(available);
468 }
469 }
470
471 void DolphinMainWindow::slotUndoTextChanged(const QString& text)
472 {
473 QAction* undoAction = actionCollection()->action(KStandardAction::name(KStandardAction::Undo));
474 if (undoAction != 0) {
475 undoAction->setText(text);
476 }
477 }
478
479 void DolphinMainWindow::undo()
480 {
481 clearStatusBar();
482 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
483 KIO::FileUndoManager::self()->undo();
484 }
485
486 void DolphinMainWindow::cut()
487 {
488 m_activeViewContainer->view()->cutSelectedItems();
489 }
490
491 void DolphinMainWindow::copy()
492 {
493 m_activeViewContainer->view()->copySelectedItems();
494 }
495
496 void DolphinMainWindow::paste()
497 {
498 m_activeViewContainer->view()->paste();
499 }
500
501 void DolphinMainWindow::updatePasteAction()
502 {
503 QAction* pasteAction = actionCollection()->action(KStandardAction::name(KStandardAction::Paste));
504 QPair<bool, QString> pasteInfo = m_activeViewContainer->view()->pasteInfo();
505 pasteAction->setEnabled(pasteInfo.first);
506 pasteAction->setText(pasteInfo.second);
507 }
508
509 void DolphinMainWindow::selectAll()
510 {
511 clearStatusBar();
512
513 // if the URL navigator is editable and focused, select the whole
514 // URL instead of all items of the view
515
516 KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
517 QLineEdit* lineEdit = urlNavigator->editor()->lineEdit();
518 const bool selectUrl = urlNavigator->isUrlEditable() &&
519 lineEdit->hasFocus();
520 if (selectUrl) {
521 lineEdit->selectAll();
522 } else {
523 m_activeViewContainer->view()->selectAll();
524 }
525 }
526
527 void DolphinMainWindow::invertSelection()
528 {
529 clearStatusBar();
530 m_activeViewContainer->view()->invertSelection();
531 }
532
533 void DolphinMainWindow::toggleSplitView()
534 {
535 if (m_viewTab[m_tabIndex].secondaryView == 0) {
536 // create a secondary view
537 QSplitter* splitter = m_viewTab[m_tabIndex].splitter;
538 const int newWidth = (m_viewTab[m_tabIndex].primaryView->width() - splitter->handleWidth()) / 2;
539
540 const DolphinView* view = m_viewTab[m_tabIndex].primaryView->view();
541 m_viewTab[m_tabIndex].secondaryView = new DolphinViewContainer(this, 0, view->rootUrl());
542 connectViewSignals(m_viewTab[m_tabIndex].secondaryView);
543 splitter->addWidget(m_viewTab[m_tabIndex].secondaryView);
544 splitter->setSizes(QList<int>() << newWidth << newWidth);
545 m_viewTab[m_tabIndex].secondaryView->view()->reload();
546 m_viewTab[m_tabIndex].secondaryView->setActive(false);
547 m_viewTab[m_tabIndex].secondaryView->show();
548
549 setActiveViewContainer(m_viewTab[m_tabIndex].secondaryView);
550 } else if (m_activeViewContainer == m_viewTab[m_tabIndex].secondaryView) {
551 // remove secondary view
552 m_viewTab[m_tabIndex].secondaryView->close();
553 m_viewTab[m_tabIndex].secondaryView->deleteLater();
554 m_viewTab[m_tabIndex].secondaryView = 0;
555
556 setActiveViewContainer(m_viewTab[m_tabIndex].primaryView);
557 } else {
558 // The primary view is active and should be closed. Hence from a users point of view
559 // the content of the secondary view should be moved to the primary view.
560 // From an implementation point of view it is more efficient to close
561 // the primary view and exchange the internal pointers afterwards.
562
563 m_viewTab[m_tabIndex].primaryView->close();
564 m_viewTab[m_tabIndex].primaryView->deleteLater();
565 m_viewTab[m_tabIndex].primaryView = m_viewTab[m_tabIndex].secondaryView;
566 m_viewTab[m_tabIndex].secondaryView = 0;
567
568 setActiveViewContainer(m_viewTab[m_tabIndex].primaryView);
569 }
570
571 updateViewActions();
572 }
573
574 void DolphinMainWindow::reloadView()
575 {
576 clearStatusBar();
577 m_activeViewContainer->view()->reload();
578 }
579
580 void DolphinMainWindow::stopLoading()
581 {
582 }
583
584 void DolphinMainWindow::toggleFilterBarVisibility(bool show)
585 {
586 m_activeViewContainer->showFilterBar(show);
587 }
588
589 void DolphinMainWindow::toggleEditLocation()
590 {
591 clearStatusBar();
592
593 QAction* action = actionCollection()->action("editable_location");
594 KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
595 urlNavigator->setUrlEditable(action->isChecked());
596 }
597
598 void DolphinMainWindow::replaceLocation()
599 {
600 KUrlNavigator* navigator = m_activeViewContainer->urlNavigator();
601 navigator->setUrlEditable(true);
602 navigator->setFocus();
603
604 // select the whole text of the combo box editor
605 QLineEdit* lineEdit = navigator->editor()->lineEdit();
606 const QString text = lineEdit->text();
607 lineEdit->setSelection(0, text.length());
608 }
609
610 void DolphinMainWindow::goBack()
611 {
612 clearStatusBar();
613 m_activeViewContainer->urlNavigator()->goBack();
614 }
615
616 void DolphinMainWindow::goForward()
617 {
618 clearStatusBar();
619 m_activeViewContainer->urlNavigator()->goForward();
620 }
621
622 void DolphinMainWindow::goUp()
623 {
624 clearStatusBar();
625 m_activeViewContainer->urlNavigator()->goUp();
626 }
627
628 void DolphinMainWindow::goHome()
629 {
630 clearStatusBar();
631 m_activeViewContainer->urlNavigator()->goHome();
632 }
633
634 void DolphinMainWindow::compareFiles()
635 {
636 // The method is only invoked if exactly 2 files have
637 // been selected. The selected files may be:
638 // - both in the primary view
639 // - both in the secondary view
640 // - one in the primary view and the other in the secondary
641 // view
642 Q_ASSERT(m_viewTab[m_tabIndex].primaryView != 0);
643
644 KUrl urlA;
645 KUrl urlB;
646 KUrl::List urls = m_viewTab[m_tabIndex].primaryView->view()->selectedUrls();
647
648 switch (urls.count()) {
649 case 0: {
650 Q_ASSERT(m_viewTab[m_tabIndex].secondaryView != 0);
651 urls = m_viewTab[m_tabIndex].secondaryView->view()->selectedUrls();
652 Q_ASSERT(urls.count() == 2);
653 urlA = urls[0];
654 urlB = urls[1];
655 break;
656 }
657
658 case 1: {
659 urlA = urls[0];
660 Q_ASSERT(m_viewTab[m_tabIndex].secondaryView != 0);
661 urls = m_viewTab[m_tabIndex].secondaryView->view()->selectedUrls();
662 Q_ASSERT(urls.count() == 1);
663 urlB = urls[0];
664 break;
665 }
666
667 case 2: {
668 urlA = urls[0];
669 urlB = urls[1];
670 break;
671 }
672
673 default: {
674 // may not happen: compareFiles may only get invoked if 2
675 // files are selected
676 Q_ASSERT(false);
677 }
678 }
679
680 QString command("kompare -c \"");
681 command.append(urlA.pathOrUrl());
682 command.append("\" \"");
683 command.append(urlB.pathOrUrl());
684 command.append('\"');
685 KRun::runCommand(command, "Kompare", "kompare", this);
686 }
687
688 void DolphinMainWindow::quickView()
689 {
690 const KUrl::List urls = activeViewContainer()->view()->selectedUrls();
691 Q_ASSERT(urls.count() > 0);
692
693 QDBusMessage msg = QDBusMessage::createMethodCall("org.kde.plasma", "/Previewer", "", "openFile");
694 foreach (const KUrl& url, urls) {
695 msg.setArguments(QList<QVariant>() << url.prettyUrl());
696 QDBusConnection::sessionBus().send(msg);
697 }
698 }
699
700 void DolphinMainWindow::toggleShowMenuBar()
701 {
702 const bool visible = menuBar()->isVisible();
703 menuBar()->setVisible(!visible);
704 }
705
706 void DolphinMainWindow::editSettings()
707 {
708 DolphinSettingsDialog dialog(this);
709 dialog.exec();
710 }
711
712 void DolphinMainWindow::setActiveTab(int index)
713 {
714 Q_ASSERT(index >= 0);
715 Q_ASSERT(index < m_viewTab.count());
716 if (index == m_tabIndex) {
717 return;
718 }
719
720 // hide current tab content
721 ViewTab& hiddenTab = m_viewTab[m_tabIndex];
722 hiddenTab.isPrimaryViewActive = hiddenTab.primaryView->isActive();
723 hiddenTab.primaryView->setActive(false);
724 if (hiddenTab.secondaryView != 0) {
725 hiddenTab.secondaryView->setActive(false);
726 }
727 QSplitter* splitter = m_viewTab[m_tabIndex].splitter;
728 splitter->hide();
729 m_centralWidgetLayout->removeWidget(splitter);
730
731 // show active tab content
732 m_tabIndex = index;
733
734 ViewTab& viewTab = m_viewTab[index];
735 m_centralWidgetLayout->addWidget(viewTab.splitter);
736 viewTab.primaryView->show();
737 if (viewTab.secondaryView != 0) {
738 viewTab.secondaryView->show();
739 }
740 viewTab.splitter->show();
741
742 setActiveViewContainer(viewTab.isPrimaryViewActive ? viewTab.primaryView :
743 viewTab.secondaryView);
744 }
745
746 void DolphinMainWindow::closeTab()
747 {
748 closeTab(m_tabBar->currentIndex());
749 }
750
751 void DolphinMainWindow::closeTab(int index)
752 {
753 Q_ASSERT(index >= 0);
754 Q_ASSERT(index < m_viewTab.count());
755 if (m_viewTab.count() == 1) {
756 // the last tab may never get closed
757 return;
758 }
759
760 if (index == m_tabIndex) {
761 // The tab that should be closed is the active tab. Activate the
762 // previous tab before closing the tab.
763 m_tabBar->setCurrentIndex((index > 0) ? index - 1 : 1);
764 }
765
766 // delete tab
767 m_viewTab[index].primaryView->deleteLater();
768 if (m_viewTab[index].secondaryView != 0) {
769 m_viewTab[index].secondaryView->deleteLater();
770 }
771 m_viewTab[index].splitter->deleteLater();
772 m_viewTab.erase(m_viewTab.begin() + index);
773
774 m_tabBar->blockSignals(true);
775 m_tabBar->removeTab(index);
776
777 if (m_tabIndex > index) {
778 m_tabIndex--;
779 Q_ASSERT(m_tabIndex >= 0);
780 }
781
782 // if only one tab is left, also remove the tab entry so that
783 // closing the last tab is not possible
784 if (m_viewTab.count() == 1) {
785 m_tabBar->removeTab(0);
786 actionCollection()->action("close_tab")->setEnabled(false);
787 } else {
788 m_tabBar->blockSignals(false);
789 }
790 }
791
792 void DolphinMainWindow::openTabContextMenu(int index, const QPoint& pos)
793 {
794 KMenu menu(this);
795
796 QAction* newTabAction = menu.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab"));
797 newTabAction->setShortcut(actionCollection()->action("new_tab")->shortcut());
798
799 QAction* closeOtherTabsAction = menu.addAction(KIcon("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs"));
800
801 QAction* closeTabAction = menu.addAction(KIcon("tab-close"), i18nc("@action:inmenu", "Close Tab"));
802 closeTabAction->setShortcut(actionCollection()->action("close_tab")->shortcut());
803
804 QAction* selectedAction = menu.exec(pos);
805 if (selectedAction == newTabAction) {
806 const ViewTab& tab = m_viewTab[index];
807 Q_ASSERT(tab.primaryView != 0);
808 const KUrl url = (tab.secondaryView != 0) && tab.secondaryView->isActive() ?
809 tab.secondaryView->url() : tab.primaryView->url();
810 openNewTab(url);
811 m_tabBar->setCurrentIndex(m_viewTab.count() - 1);
812 } else if (selectedAction == closeOtherTabsAction) {
813 const int count = m_tabBar->count();
814 for (int i = 0; i < index; ++i) {
815 closeTab(0);
816 }
817 for (int i = index + 1; i < count; ++i) {
818 closeTab(1);
819 }
820 } else if (selectedAction == closeTabAction) {
821 closeTab(index);
822 }
823 }
824
825 void DolphinMainWindow::handlePlacesClick(const KUrl& url, Qt::MouseButtons buttons)
826 {
827 if (buttons & Qt::MidButton) {
828 openNewTab(url);
829 m_tabBar->setCurrentIndex(m_viewTab.count() - 1);
830 } else {
831 changeUrl(url);
832 }
833 }
834
835 void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent* event, bool& canDecode)
836 {
837 canDecode = KUrl::List::canDecode(event->mimeData());
838 }
839
840 void DolphinMainWindow::init()
841 {
842 DolphinSettings& settings = DolphinSettings::instance();
843
844 // Check whether Dolphin runs the first time. If yes then
845 // a proper default window size is given at the end of DolphinMainWindow::init().
846 GeneralSettings* generalSettings = settings.generalSettings();
847 const bool firstRun = generalSettings->firstRun();
848 if (firstRun) {
849 generalSettings->setViewPropsTimestamp(QDateTime::currentDateTime());
850 }
851
852 setAcceptDrops(true);
853
854 m_viewTab[m_tabIndex].splitter = new QSplitter(this);
855
856 setupActions();
857
858 const KUrl& homeUrl = generalSettings->homeUrl();
859 setCaption(homeUrl.fileName());
860 m_actionHandler = new DolphinViewActionHandler(actionCollection(), this);
861 connect(m_actionHandler, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
862 ViewProperties props(homeUrl);
863 m_viewTab[m_tabIndex].primaryView = new DolphinViewContainer(this,
864 m_viewTab[m_tabIndex].splitter,
865 homeUrl);
866
867 m_activeViewContainer = m_viewTab[m_tabIndex].primaryView;
868 connectViewSignals(m_activeViewContainer);
869 DolphinView* view = m_activeViewContainer->view();
870 view->reload();
871 m_activeViewContainer->show();
872 m_actionHandler->setCurrentView(view);
873
874 m_tabBar = new KTabBar(this);
875 m_tabBar->setCloseButtonEnabled(true);
876 connect(m_tabBar, SIGNAL(currentChanged(int)),
877 this, SLOT(setActiveTab(int)));
878 connect(m_tabBar, SIGNAL(closeRequest(int)),
879 this, SLOT(closeTab(int)));
880 connect(m_tabBar, SIGNAL(contextMenu(int, const QPoint&)),
881 this, SLOT(openTabContextMenu(int, const QPoint&)));
882 connect(m_tabBar, SIGNAL(newTabRequest()),
883 this, SLOT(openNewTab()));
884 connect(m_tabBar, SIGNAL(testCanDecode(const QDragMoveEvent*, bool&)),
885 this, SLOT(slotTestCanDecode(const QDragMoveEvent*, bool&)));
886 m_tabBar->blockSignals(true); // signals get unblocked after at least 2 tabs are open
887
888 QWidget* centralWidget = new QWidget(this);
889 m_centralWidgetLayout = new QVBoxLayout(centralWidget);
890 m_centralWidgetLayout->setSpacing(0);
891 m_centralWidgetLayout->setMargin(0);
892 m_centralWidgetLayout->addWidget(m_tabBar);
893 m_centralWidgetLayout->addWidget(m_viewTab[m_tabIndex].splitter);
894
895 setCentralWidget(centralWidget);
896 setupDockWidgets();
897 emit urlChanged(homeUrl);
898
899 setupGUI(Keys | Save | Create | ToolBar);
900
901 stateChanged("new_file");
902
903 QClipboard* clipboard = QApplication::clipboard();
904 connect(clipboard, SIGNAL(dataChanged()),
905 this, SLOT(updatePasteAction()));
906 updatePasteAction();
907 updateGoActions();
908
909 if (generalSettings->splitView()) {
910 toggleSplitView();
911 }
912 updateViewActions();
913
914 QAction* showFilterBarAction = actionCollection()->action("show_filter_bar");
915 showFilterBarAction->setChecked(generalSettings->filterBar());
916
917 if (firstRun) {
918 // assure a proper default size if Dolphin runs the first time
919 resize(750, 500);
920 }
921
922 m_showMenuBar->setChecked(!menuBar()->isHidden()); // workaround for bug #171080
923 }
924
925 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer* viewContainer)
926 {
927 Q_ASSERT(viewContainer != 0);
928 Q_ASSERT((viewContainer == m_viewTab[m_tabIndex].primaryView) ||
929 (viewContainer == m_viewTab[m_tabIndex].secondaryView));
930 if (m_activeViewContainer == viewContainer) {
931 return;
932 }
933
934 m_activeViewContainer->setActive(false);
935 m_activeViewContainer = viewContainer;
936
937 // Activating the view container might trigger a recursive setActiveViewContainer() call
938 // inside DolphinMainWindow::toggleActiveView() when having a split view. Temporary
939 // disconnect the activated() signal in this case:
940 disconnect(m_activeViewContainer->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
941 m_activeViewContainer->setActive(true);
942 connect(m_activeViewContainer->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
943
944 m_actionHandler->setCurrentView(viewContainer->view());
945
946 updateHistory();
947 updateEditActions();
948 updateViewActions();
949 updateGoActions();
950
951 const KUrl& url = m_activeViewContainer->url();
952 setCaption(url.fileName());
953 if (m_viewTab.count() > 1) {
954 m_tabBar->setTabText(m_tabIndex, tabName(url));
955 }
956
957 emit urlChanged(url);
958 }
959
960 void DolphinMainWindow::setupActions()
961 {
962 // setup 'File' menu
963 m_newMenu = new DolphinNewMenu(this, this);
964 KMenu* menu = m_newMenu->menu();
965 menu->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
966 menu->setIcon(KIcon("document-new"));
967 connect(menu, SIGNAL(aboutToShow()),
968 this, SLOT(updateNewMenu()));
969
970 KAction* newWindow = actionCollection()->addAction("new_window");
971 newWindow->setIcon(KIcon("window-new"));
972 newWindow->setText(i18nc("@action:inmenu File", "New &Window"));
973 newWindow->setShortcut(Qt::CTRL | Qt::Key_N);
974 connect(newWindow, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
975
976 KAction* newTab = actionCollection()->addAction("new_tab");
977 newTab->setIcon(KIcon("tab-new"));
978 newTab->setText(i18nc("@action:inmenu File", "New Tab"));
979 newTab->setShortcut(KShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_N, Qt::CTRL | Qt::Key_T));
980 connect(newTab, SIGNAL(triggered()), this, SLOT(openNewTab()));
981
982 QAction* closeTab = new QAction(KIcon("tab-close"), i18nc("@action:inmenu File", "Close Tab"), this);
983 closeTab->setShortcut(Qt::CTRL | Qt::Key_W);
984 closeTab->setEnabled(false);
985 connect(closeTab, SIGNAL(triggered()), this, SLOT(closeTab()));
986 actionCollection()->addAction("close_tab", closeTab);
987
988 KStandardAction::quit(this, SLOT(quit()), actionCollection());
989
990 // setup 'Edit' menu
991 KStandardAction::undo(this,
992 SLOT(undo()),
993 actionCollection());
994
995 // need to remove shift+del from cut action, else the shortcut for deletejob
996 // doesn't work
997 KAction* cut = KStandardAction::cut(this, SLOT(cut()), actionCollection());
998 KShortcut cutShortcut = cut->shortcut();
999 cutShortcut.remove(Qt::SHIFT + Qt::Key_Delete, KShortcut::KeepEmpty);
1000 cut->setShortcut(cutShortcut);
1001 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1002 KStandardAction::paste(this, SLOT(paste()), actionCollection());
1003
1004 KAction* selectAll = actionCollection()->addAction("select_all");
1005 selectAll->setText(i18nc("@action:inmenu Edit", "Select All"));
1006 selectAll->setShortcut(Qt::CTRL + Qt::Key_A);
1007 connect(selectAll, SIGNAL(triggered()), this, SLOT(selectAll()));
1008
1009 KAction* invertSelection = actionCollection()->addAction("invert_selection");
1010 invertSelection->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1011 invertSelection->setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_A);
1012 connect(invertSelection, SIGNAL(triggered()), this, SLOT(invertSelection()));
1013
1014 // setup 'View' menu
1015 // (note that most of it is set up in DolphinViewActionHandler)
1016
1017 KAction* split = actionCollection()->addAction("split_view");
1018 split->setShortcut(Qt::Key_F3);
1019 updateSplitAction();
1020 connect(split, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1021
1022 KAction* reload = actionCollection()->addAction("reload");
1023 reload->setText(i18nc("@action:inmenu View", "Reload"));
1024 reload->setShortcut(Qt::Key_F5);
1025 reload->setIcon(KIcon("view-refresh"));
1026 connect(reload, SIGNAL(triggered()), this, SLOT(reloadView()));
1027
1028 KAction* stop = actionCollection()->addAction("stop");
1029 stop->setText(i18nc("@action:inmenu View", "Stop"));
1030 stop->setIcon(KIcon("process-stop"));
1031 connect(stop, SIGNAL(triggered()), this, SLOT(stopLoading()));
1032
1033 KToggleAction* showFullLocation = actionCollection()->add<KToggleAction>("editable_location");
1034 showFullLocation->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1035 showFullLocation->setShortcut(Qt::CTRL | Qt::Key_L);
1036 connect(showFullLocation, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1037
1038 KAction* replaceLocation = actionCollection()->addAction("replace_location");
1039 replaceLocation->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1040 replaceLocation->setShortcut(Qt::Key_F6);
1041 connect(replaceLocation, SIGNAL(triggered()), this, SLOT(replaceLocation()));
1042
1043 // setup 'Go' menu
1044 KAction* backAction = KStandardAction::back(this, SLOT(goBack()), actionCollection());
1045 KShortcut backShortcut = backAction->shortcut();
1046 backShortcut.setAlternate(Qt::Key_Backspace);
1047 backAction->setShortcut(backShortcut);
1048
1049 KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1050 KStandardAction::up(this, SLOT(goUp()), actionCollection());
1051 KStandardAction::home(this, SLOT(goHome()), actionCollection());
1052
1053 // setup 'Tools' menu
1054 KToggleAction* showFilterBar = actionCollection()->add<KToggleAction>("show_filter_bar");
1055 showFilterBar->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1056 showFilterBar->setShortcut(Qt::CTRL | Qt::Key_I);
1057 connect(showFilterBar, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
1058
1059 KAction* compareFiles = actionCollection()->addAction("compare_files");
1060 compareFiles->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1061 compareFiles->setIcon(KIcon("kompare"));
1062 compareFiles->setEnabled(false);
1063 connect(compareFiles, SIGNAL(triggered()), this, SLOT(compareFiles()));
1064
1065 // disabled Quick View
1066 #if defined(QUICK_VIEW)
1067 KAction* quickView = actionCollection()->addAction("quick_view");
1068 quickView->setText(i18nc("@action:inmenu Tools", "Quick View"));
1069 quickView->setIcon(KIcon("view-preview"));
1070 quickView->setShortcut(Qt::CTRL + Qt::Key_Return);
1071 quickView->setEnabled(false);
1072 connect(quickView, SIGNAL(triggered()), this, SLOT(quickView()));
1073 #endif
1074
1075 // setup 'Settings' menu
1076 m_showMenuBar = KStandardAction::showMenubar(this, SLOT(toggleShowMenuBar()), actionCollection());
1077 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1078
1079 // not in menu actions
1080 KAction* activateNextTab = actionCollection()->addAction("activatenexttab");
1081 activateNextTab->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1082 connect(activateNextTab, SIGNAL(triggered()), SLOT(activateNextTab()));
1083 activateNextTab->setShortcuts(QApplication::isRightToLeft() ? KStandardShortcut::tabPrev() :
1084 KStandardShortcut::tabNext());
1085
1086 KAction* activatePrevTab = actionCollection()->addAction("activateprevtab");
1087 activatePrevTab->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1088 connect(activatePrevTab, SIGNAL(triggered()), SLOT(activatePrevTab()));
1089 activatePrevTab->setShortcuts(QApplication::isRightToLeft() ? KStandardShortcut::tabNext() :
1090 KStandardShortcut::tabPrev());
1091
1092 // for context menu
1093 KAction* openInNewTab = actionCollection()->addAction("open_in_new_tab");
1094 openInNewTab->setText(i18nc("@action:inmenu", "Open in New Tab"));
1095 openInNewTab->setIcon(KIcon("tab-new"));
1096 connect(openInNewTab, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1097
1098 KAction* openInNewWindow = actionCollection()->addAction("open_in_new_window");
1099 openInNewWindow->setText(i18nc("@action:inmenu", "Open in New Window"));
1100 openInNewWindow->setIcon(KIcon("window-new"));
1101 connect(openInNewWindow, SIGNAL(triggered()), this, SLOT(openInNewWindow()));
1102 }
1103
1104 void DolphinMainWindow::setupDockWidgets()
1105 {
1106 // setup "Information"
1107 QDockWidget* infoDock = new QDockWidget(i18nc("@title:window", "Information"));
1108 infoDock->setObjectName("infoDock");
1109 infoDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1110 SidebarPage* infoWidget = new InfoSidebarPage(infoDock);
1111 infoDock->setWidget(infoWidget);
1112
1113 infoDock->toggleViewAction()->setText(i18nc("@title:window", "Information"));
1114 infoDock->toggleViewAction()->setShortcut(Qt::Key_F11);
1115 actionCollection()->addAction("show_info_panel", infoDock->toggleViewAction());
1116
1117 addDockWidget(Qt::RightDockWidgetArea, infoDock);
1118 connect(this, SIGNAL(urlChanged(KUrl)),
1119 infoWidget, SLOT(setUrl(KUrl)));
1120 connect(this, SIGNAL(selectionChanged(KFileItemList)),
1121 infoWidget, SLOT(setSelection(KFileItemList)));
1122 connect(this, SIGNAL(requestItemInfo(KFileItem)),
1123 infoWidget, SLOT(requestDelayedItemInfo(KFileItem)));
1124
1125 // setup "Tree View"
1126 QDockWidget* treeViewDock = new QDockWidget(i18nc("@title:window", "Folders"));
1127 treeViewDock->setObjectName("treeViewDock");
1128 treeViewDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1129 TreeViewSidebarPage* treeWidget = new TreeViewSidebarPage(treeViewDock);
1130 treeViewDock->setWidget(treeWidget);
1131
1132 treeViewDock->toggleViewAction()->setText(i18nc("@title:window", "Folders"));
1133 treeViewDock->toggleViewAction()->setShortcut(Qt::Key_F7);
1134 actionCollection()->addAction("show_folders_panel", treeViewDock->toggleViewAction());
1135
1136 addDockWidget(Qt::LeftDockWidgetArea, treeViewDock);
1137 connect(this, SIGNAL(urlChanged(KUrl)),
1138 treeWidget, SLOT(setUrl(KUrl)));
1139 connect(treeWidget, SIGNAL(changeUrl(KUrl, Qt::MouseButtons)),
1140 this, SLOT(handlePlacesClick(KUrl, Qt::MouseButtons)));
1141 connect(treeWidget, SIGNAL(changeSelection(KFileItemList)),
1142 this, SLOT(changeSelection(KFileItemList)));
1143
1144 // setup "Terminal"
1145 #ifndef Q_OS_WIN
1146 QDockWidget* terminalDock = new QDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1147 terminalDock->setObjectName("terminalDock");
1148 terminalDock->setAllowedAreas(Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea);
1149 SidebarPage* terminalWidget = new TerminalSidebarPage(terminalDock);
1150 terminalDock->setWidget(terminalWidget);
1151
1152 connect(terminalWidget, SIGNAL(hideTerminalSidebarPage()), terminalDock, SLOT(hide()));
1153
1154 terminalDock->toggleViewAction()->setText(i18nc("@title:window Shell terminal", "Terminal"));
1155 terminalDock->toggleViewAction()->setShortcut(Qt::Key_F4);
1156 actionCollection()->addAction("show_terminal_panel", terminalDock->toggleViewAction());
1157
1158 addDockWidget(Qt::BottomDockWidgetArea, terminalDock);
1159 connect(this, SIGNAL(urlChanged(KUrl)),
1160 terminalWidget, SLOT(setUrl(KUrl)));
1161 #endif
1162
1163 const bool firstRun = DolphinSettings::instance().generalSettings()->firstRun();
1164 if (firstRun) {
1165 treeViewDock->hide();
1166 #ifndef Q_OS_WIN
1167 terminalDock->hide();
1168 #endif
1169 }
1170
1171 QDockWidget* placesDock = new QDockWidget(i18nc("@title:window", "Places"));
1172 placesDock->setObjectName("placesDock");
1173 placesDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1174
1175 DolphinFilePlacesView* placesView = new DolphinFilePlacesView(placesDock);
1176 placesDock->setWidget(placesView);
1177 placesView->setModel(DolphinSettings::instance().placesModel());
1178 placesView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
1179
1180 placesDock->toggleViewAction()->setText(i18nc("@title:window", "Places"));
1181 placesDock->toggleViewAction()->setShortcut(Qt::Key_F9);
1182 actionCollection()->addAction("show_places_panel", placesDock->toggleViewAction());
1183
1184 addDockWidget(Qt::LeftDockWidgetArea, placesDock);
1185 connect(placesView, SIGNAL(urlChanged(KUrl, Qt::MouseButtons)),
1186 this, SLOT(handlePlacesClick(KUrl, Qt::MouseButtons)));
1187 connect(this, SIGNAL(urlChanged(KUrl)),
1188 placesView, SLOT(setUrl(KUrl)));
1189 }
1190
1191 void DolphinMainWindow::updateEditActions()
1192 {
1193 const KFileItemList list = m_activeViewContainer->view()->selectedItems();
1194 if (list.isEmpty()) {
1195 stateChanged("has_no_selection");
1196 } else {
1197 stateChanged("has_selection");
1198
1199 KActionCollection* col = actionCollection();
1200 QAction* renameAction = col->action("rename");
1201 QAction* moveToTrashAction = col->action("move_to_trash");
1202 QAction* deleteAction = col->action("delete");
1203 QAction* cutAction = col->action(KStandardAction::name(KStandardAction::Cut));
1204 QAction* deleteWithTrashShortcut = col->action("delete_shortcut"); // see DolphinViewActionHandler
1205
1206 KonqFileItemCapabilities capabilities(list);
1207 const bool enableMoveToTrash = capabilities.isLocal() && capabilities.supportsMoving();
1208
1209 renameAction->setEnabled(capabilities.supportsMoving());
1210 moveToTrashAction->setEnabled(enableMoveToTrash);
1211 deleteAction->setEnabled(capabilities.supportsDeleting());
1212 deleteWithTrashShortcut->setEnabled(capabilities.supportsDeleting() && !enableMoveToTrash);
1213 cutAction->setEnabled(capabilities.supportsMoving());
1214 }
1215 updatePasteAction();
1216 }
1217
1218 void DolphinMainWindow::updateViewActions()
1219 {
1220 m_actionHandler->updateViewActions();
1221
1222 QAction* showFilterBarAction = actionCollection()->action("show_filter_bar");
1223 showFilterBarAction->setChecked(m_activeViewContainer->isFilterBarVisible());
1224
1225 updateSplitAction();
1226
1227 QAction* editableLocactionAction = actionCollection()->action("editable_location");
1228 const KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
1229 editableLocactionAction->setChecked(urlNavigator->isUrlEditable());
1230 }
1231
1232 void DolphinMainWindow::updateGoActions()
1233 {
1234 QAction* goUpAction = actionCollection()->action(KStandardAction::name(KStandardAction::Up));
1235 const KUrl& currentUrl = m_activeViewContainer->url();
1236 goUpAction->setEnabled(currentUrl.upUrl() != currentUrl);
1237 }
1238
1239 void DolphinMainWindow::clearStatusBar()
1240 {
1241 m_activeViewContainer->statusBar()->clear();
1242 }
1243
1244 void DolphinMainWindow::connectViewSignals(DolphinViewContainer* container)
1245 {
1246 connect(container, SIGNAL(showFilterBarChanged(bool)),
1247 this, SLOT(updateFilterBarAction(bool)));
1248
1249 DolphinView* view = container->view();
1250 connect(view, SIGNAL(selectionChanged(KFileItemList)),
1251 this, SLOT(slotSelectionChanged(KFileItemList)));
1252 connect(view, SIGNAL(requestItemInfo(KFileItem)),
1253 this, SLOT(slotRequestItemInfo(KFileItem)));
1254 connect(view, SIGNAL(activated()),
1255 this, SLOT(toggleActiveView()));
1256 connect(view, SIGNAL(tabRequested(const KUrl&)),
1257 this, SLOT(openNewTab(const KUrl&)));
1258
1259 const KUrlNavigator* navigator = container->urlNavigator();
1260 connect(navigator, SIGNAL(urlChanged(const KUrl&)),
1261 this, SLOT(changeUrl(const KUrl&)));
1262 connect(navigator, SIGNAL(historyChanged()),
1263 this, SLOT(updateHistory()));
1264 connect(navigator, SIGNAL(editableStateChanged(bool)),
1265 this, SLOT(slotEditableStateChanged(bool)));
1266 }
1267
1268 void DolphinMainWindow::updateSplitAction()
1269 {
1270 QAction* splitAction = actionCollection()->action("split_view");
1271 if (m_viewTab[m_tabIndex].secondaryView != 0) {
1272 if (m_activeViewContainer == m_viewTab[m_tabIndex].secondaryView) {
1273 splitAction->setText(i18nc("@action:intoolbar Close right view", "Close"));
1274 splitAction->setIcon(KIcon("view-right-close"));
1275 } else {
1276 splitAction->setText(i18nc("@action:intoolbar Close left view", "Close"));
1277 splitAction->setIcon(KIcon("view-left-close"));
1278 }
1279 } else {
1280 splitAction->setText(i18nc("@action:intoolbar Split view", "Split"));
1281 splitAction->setIcon(KIcon("view-right-new"));
1282 }
1283 }
1284
1285 QString DolphinMainWindow::tabName(const KUrl& url) const
1286 {
1287 QString name;
1288 if (url.equals(KUrl("file:///"))) {
1289 name = "/";
1290 } else {
1291 name = url.fileName();
1292 if (name.isEmpty()) {
1293 name = url.protocol();
1294 }
1295 }
1296 return name;
1297 }
1298
1299 bool DolphinMainWindow::isKompareInstalled() const
1300 {
1301 static bool initialized = false;
1302 static bool installed = false;
1303 if (!initialized) {
1304 // TODO: maybe replace this approach later by using a menu
1305 // plugin like kdiff3plugin.cpp
1306 installed = !KGlobal::dirs()->findExe("kompare").isEmpty();
1307 initialized = true;
1308 }
1309 return installed;
1310 }
1311
1312 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
1313 KIO::FileUndoManager::UiInterface()
1314 {
1315 }
1316
1317 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
1318 {
1319 }
1320
1321 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job* job)
1322 {
1323 DolphinMainWindow* mainWin= qobject_cast<DolphinMainWindow *>(parentWidget());
1324 if (mainWin) {
1325 DolphinStatusBar* statusBar = mainWin->activeViewContainer()->statusBar();
1326 statusBar->setMessage(job->errorString(), DolphinStatusBar::Error);
1327 } else {
1328 KIO::FileUndoManager::UiInterface::jobError(job);
1329 }
1330 }
1331
1332 #include "dolphinmainwindow.moc"