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