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