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