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