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