]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.cpp
another i18n TODO done: better description of this special action, for "configure...
[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 <kpropertiesdialog.h>
67 #include <kprotocolinfo.h>
68 #include <krun.h>
69 #include <kshell.h>
70 #include <kstandarddirs.h>
71 #include <kstatusbar.h>
72 #include <kstandardaction.h>
73 #include <ktabbar.h>
74 #include <ktoggleaction.h>
75 #include <kurlnavigator.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 KPropertiesDialog* dialog = 0;
359 const KFileItemList list = m_activeViewContainer->view()->selectedItems();
360 if (list.isEmpty()) {
361 const KUrl url = activeViewContainer()->url();
362 dialog = new KPropertiesDialog(url, this);
363 } else {
364 dialog = new KPropertiesDialog(list, this);
365 }
366
367 dialog->setAttribute(Qt::WA_DeleteOnClose);
368 dialog->show();
369 dialog->raise();
370 dialog->activateWindow();
371 }
372
373 void DolphinMainWindow::quit()
374 {
375 close();
376 }
377
378 void DolphinMainWindow::slotHandlePlacesError(const QString &message)
379 {
380 if (!message.isEmpty()) {
381 DolphinStatusBar* statusBar = m_activeViewContainer->statusBar();
382 statusBar->setMessage(message, DolphinStatusBar::Error);
383 }
384 }
385
386 void DolphinMainWindow::slotUndoAvailable(bool available)
387 {
388 QAction* undoAction = actionCollection()->action(KStandardAction::name(KStandardAction::Undo));
389 if (undoAction != 0) {
390 undoAction->setEnabled(available);
391 }
392
393 if (available && (m_undoCommandTypes.count() > 0)) {
394 const KIO::FileUndoManager::CommandType command = m_undoCommandTypes.takeFirst();
395 DolphinStatusBar* statusBar = m_activeViewContainer->statusBar();
396 switch (command) {
397 case KIO::FileUndoManager::Copy:
398 statusBar->setMessage(i18nc("@info:status", "Copy operation completed."),
399 DolphinStatusBar::OperationCompleted);
400 break;
401 case KIO::FileUndoManager::Move:
402 statusBar->setMessage(i18nc("@info:status", "Move operation completed."),
403 DolphinStatusBar::OperationCompleted);
404 break;
405 case KIO::FileUndoManager::Link:
406 statusBar->setMessage(i18nc("@info:status", "Link operation completed."),
407 DolphinStatusBar::OperationCompleted);
408 break;
409 case KIO::FileUndoManager::Trash:
410 statusBar->setMessage(i18nc("@info:status", "Move to trash operation completed."),
411 DolphinStatusBar::OperationCompleted);
412 break;
413 case KIO::FileUndoManager::Rename:
414 statusBar->setMessage(i18nc("@info:status", "Renaming operation completed."),
415 DolphinStatusBar::OperationCompleted);
416 break;
417
418 case KIO::FileUndoManager::Mkdir:
419 statusBar->setMessage(i18nc("@info:status", "Created folder."),
420 DolphinStatusBar::OperationCompleted);
421 break;
422
423 default:
424 break;
425 }
426
427 }
428 }
429
430 void DolphinMainWindow::slotUndoTextChanged(const QString& text)
431 {
432 QAction* undoAction = actionCollection()->action(KStandardAction::name(KStandardAction::Undo));
433 if (undoAction != 0) {
434 undoAction->setText(text);
435 }
436 }
437
438 void DolphinMainWindow::undo()
439 {
440 clearStatusBar();
441 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
442 KIO::FileUndoManager::self()->undo();
443 }
444
445 void DolphinMainWindow::cut()
446 {
447 m_activeViewContainer->view()->cutSelectedItems();
448 }
449
450 void DolphinMainWindow::copy()
451 {
452 m_activeViewContainer->view()->copySelectedItems();
453 }
454
455 void DolphinMainWindow::paste()
456 {
457 m_activeViewContainer->view()->paste();
458 }
459
460 void DolphinMainWindow::updatePasteAction()
461 {
462 QAction* pasteAction = actionCollection()->action(KStandardAction::name(KStandardAction::Paste));
463 QPair<bool, QString> pasteInfo = m_activeViewContainer->view()->pasteInfo();
464 pasteAction->setEnabled(pasteInfo.first);
465 pasteAction->setText(pasteInfo.second);
466 }
467
468 void DolphinMainWindow::selectAll()
469 {
470 clearStatusBar();
471
472 // if the URL navigator is editable and focused, select the whole
473 // URL instead of all items of the view
474
475 KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
476 QLineEdit* lineEdit = urlNavigator->editor()->lineEdit();
477 const bool selectUrl = urlNavigator->isUrlEditable() &&
478 lineEdit->hasFocus();
479 if (selectUrl) {
480 lineEdit->selectAll();
481 } else {
482 m_activeViewContainer->view()->selectAll();
483 }
484 }
485
486 void DolphinMainWindow::invertSelection()
487 {
488 clearStatusBar();
489 m_activeViewContainer->view()->invertSelection();
490 }
491
492 void DolphinMainWindow::toggleSplitView()
493 {
494 if (m_viewTab[m_tabIndex].secondaryView == 0) {
495 // create a secondary view
496 QSplitter* splitter = m_viewTab[m_tabIndex].splitter;
497 const int newWidth = (m_viewTab[m_tabIndex].primaryView->width() - splitter->handleWidth()) / 2;
498
499 const DolphinView* view = m_viewTab[m_tabIndex].primaryView->view();
500 m_viewTab[m_tabIndex].secondaryView = new DolphinViewContainer(this, 0, view->rootUrl());
501 connectViewSignals(m_viewTab[m_tabIndex].secondaryView);
502 splitter->addWidget(m_viewTab[m_tabIndex].secondaryView);
503 splitter->setSizes(QList<int>() << newWidth << newWidth);
504 m_viewTab[m_tabIndex].secondaryView->view()->reload();
505 m_viewTab[m_tabIndex].secondaryView->setActive(false);
506 m_viewTab[m_tabIndex].secondaryView->show();
507
508 setActiveViewContainer(m_viewTab[m_tabIndex].secondaryView);
509 } else if (m_activeViewContainer == m_viewTab[m_tabIndex].primaryView) {
510 // remove secondary view
511 m_viewTab[m_tabIndex].secondaryView->close();
512 m_viewTab[m_tabIndex].secondaryView->deleteLater();
513 m_viewTab[m_tabIndex].secondaryView = 0;
514
515 setActiveViewContainer(m_viewTab[m_tabIndex].primaryView);
516 } else {
517 // The secondary view is active, hence from a users point of view
518 // the content of the secondary view should be moved to the primary view.
519 // From an implementation point of view it is more efficient to close
520 // the primary view and exchange the internal pointers afterwards.
521
522 m_viewTab[m_tabIndex].primaryView->close();
523 m_viewTab[m_tabIndex].primaryView->deleteLater();
524 m_viewTab[m_tabIndex].primaryView = m_viewTab[m_tabIndex].secondaryView;
525 m_viewTab[m_tabIndex].secondaryView = 0;
526
527 setActiveViewContainer(m_viewTab[m_tabIndex].primaryView);
528 }
529
530 updateViewActions();
531 }
532
533 void DolphinMainWindow::reloadView()
534 {
535 clearStatusBar();
536 m_activeViewContainer->view()->reload();
537 }
538
539 void DolphinMainWindow::stopLoading()
540 {
541 }
542
543 void DolphinMainWindow::toggleFilterBarVisibility(bool show)
544 {
545 m_activeViewContainer->showFilterBar(show);
546 }
547
548 void DolphinMainWindow::toggleEditLocation()
549 {
550 clearStatusBar();
551
552 QAction* action = actionCollection()->action("editable_location");
553 KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
554 urlNavigator->setUrlEditable(action->isChecked());
555 }
556
557 void DolphinMainWindow::editLocation()
558 {
559 KUrlNavigator* navigator = m_activeViewContainer->urlNavigator();
560 navigator->setUrlEditable(true);
561 navigator->setFocus();
562
563 // select the whole text of the combo box editor
564 QLineEdit* lineEdit = navigator->editor()->lineEdit();
565 const QString text = lineEdit->text();
566 lineEdit->setSelection(0, text.length());
567 }
568
569 void DolphinMainWindow::goBack()
570 {
571 clearStatusBar();
572 m_activeViewContainer->urlNavigator()->goBack();
573 }
574
575 void DolphinMainWindow::goForward()
576 {
577 clearStatusBar();
578 m_activeViewContainer->urlNavigator()->goForward();
579 }
580
581 void DolphinMainWindow::goUp()
582 {
583 clearStatusBar();
584 m_activeViewContainer->urlNavigator()->goUp();
585 }
586
587 void DolphinMainWindow::goHome()
588 {
589 clearStatusBar();
590 m_activeViewContainer->urlNavigator()->goHome();
591 }
592
593 void DolphinMainWindow::compareFiles()
594 {
595 // The method is only invoked if exactly 2 files have
596 // been selected. The selected files may be:
597 // - both in the primary view
598 // - both in the secondary view
599 // - one in the primary view and the other in the secondary
600 // view
601 Q_ASSERT(m_viewTab[m_tabIndex].primaryView != 0);
602
603 KUrl urlA;
604 KUrl urlB;
605 KUrl::List urls = m_viewTab[m_tabIndex].primaryView->view()->selectedUrls();
606
607 switch (urls.count()) {
608 case 0: {
609 Q_ASSERT(m_viewTab[m_tabIndex].secondaryView != 0);
610 urls = m_viewTab[m_tabIndex].secondaryView->view()->selectedUrls();
611 Q_ASSERT(urls.count() == 2);
612 urlA = urls[0];
613 urlB = urls[1];
614 break;
615 }
616
617 case 1: {
618 urlA = urls[0];
619 Q_ASSERT(m_viewTab[m_tabIndex].secondaryView != 0);
620 urls = m_viewTab[m_tabIndex].secondaryView->view()->selectedUrls();
621 Q_ASSERT(urls.count() == 1);
622 urlB = urls[0];
623 break;
624 }
625
626 case 2: {
627 urlA = urls[0];
628 urlB = urls[1];
629 break;
630 }
631
632 default: {
633 // may not happen: compareFiles may only get invoked if 2
634 // files are selected
635 Q_ASSERT(false);
636 }
637 }
638
639 QString command("kompare -c \"");
640 command.append(urlA.pathOrUrl());
641 command.append("\" \"");
642 command.append(urlB.pathOrUrl());
643 command.append('\"');
644 KRun::runCommand(command, "Kompare", "kompare", this);
645 }
646
647 void DolphinMainWindow::toggleShowMenuBar()
648 {
649 const bool visible = menuBar()->isVisible();
650 menuBar()->setVisible(!visible);
651 }
652
653 void DolphinMainWindow::editSettings()
654 {
655 DolphinSettingsDialog dialog(this);
656 dialog.exec();
657 }
658
659 void DolphinMainWindow::setActiveTab(int index)
660 {
661 Q_ASSERT(index >= 0);
662 Q_ASSERT(index < m_viewTab.count());
663 if (index == m_tabIndex) {
664 return;
665 }
666
667 // hide current tab content
668 m_viewTab[m_tabIndex].isPrimaryViewActive = m_viewTab[m_tabIndex].primaryView->isActive();
669 QSplitter* splitter = m_viewTab[m_tabIndex].splitter;
670 splitter->hide();
671 m_centralWidgetLayout->removeWidget(splitter);
672
673 // show active tab content
674 m_tabIndex = index;
675
676 ViewTab& viewTab = m_viewTab[index];
677 m_centralWidgetLayout->addWidget(viewTab.splitter);
678 viewTab.primaryView->show();
679 if (viewTab.secondaryView != 0) {
680 viewTab.secondaryView->show();
681 }
682 viewTab.splitter->show();
683
684 setActiveViewContainer(viewTab.isPrimaryViewActive ? viewTab.primaryView :
685 viewTab.secondaryView);
686 }
687
688 void DolphinMainWindow::closeTab()
689 {
690 closeTab(m_tabBar->currentIndex());
691 }
692
693 void DolphinMainWindow::closeTab(int index)
694 {
695 Q_ASSERT(index >= 0);
696 Q_ASSERT(index < m_viewTab.count());
697 if (m_viewTab.count() == 1) {
698 // the last tab may never get closed
699 return;
700 }
701
702 if (index == m_tabIndex) {
703 // The tab that should be closed is the active tab. Activate the
704 // previous tab before closing the tab.
705 setActiveTab((index > 0) ? index - 1 : 1);
706 }
707
708 // delete tab
709 m_viewTab[index].primaryView->deleteLater();
710 if (m_viewTab[index].secondaryView != 0) {
711 m_viewTab[index].secondaryView->deleteLater();
712 }
713 m_viewTab[index].splitter->deleteLater();
714 m_viewTab.erase(m_viewTab.begin() + index);
715
716 m_tabBar->blockSignals(true);
717 m_tabBar->removeTab(index);
718
719 if (m_tabIndex > index) {
720 m_tabIndex--;
721 Q_ASSERT(m_tabIndex >= 0);
722 }
723
724 // if only one tab is left, also remove the tab entry so that
725 // closing the last tab is not possible
726 if (m_viewTab.count() == 1) {
727 m_tabBar->removeTab(0);
728 } else {
729 m_tabBar->blockSignals(false);
730 }
731 }
732
733 void DolphinMainWindow::openTabContextMenu(int index, const QPoint& pos)
734 {
735 KMenu menu(this);
736
737 QAction* newTabAction = menu.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab"));
738 newTabAction->setShortcut(actionCollection()->action("new_tab")->shortcut());
739
740 QAction* closeOtherTabsAction = menu.addAction(KIcon("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs"));
741
742 QAction* closeTabAction = menu.addAction(KIcon("tab-close"), i18nc("@action:inmenu", "Close Tab"));
743 closeTabAction->setShortcut(actionCollection()->action("close_tab")->shortcut());
744
745 QAction* selectedAction = menu.exec(pos);
746 if (selectedAction == newTabAction) {
747 const ViewTab& tab = m_viewTab[index];
748 Q_ASSERT(tab.primaryView != 0);
749 const KUrl url = (tab.secondaryView != 0) && tab.secondaryView->isActive() ?
750 tab.secondaryView->url() : tab.primaryView->url();
751 openNewTab(url);
752 m_tabBar->setCurrentIndex(m_viewTab.count() - 1);
753 } else if (selectedAction == closeOtherTabsAction) {
754 const int count = m_tabBar->count();
755 for (int i = 0; i < index; ++i) {
756 closeTab(0);
757 }
758 for (int i = index + 1; i < count; ++i) {
759 closeTab(1);
760 }
761 } else if (selectedAction == closeTabAction) {
762 closeTab(index);
763 }
764 }
765
766 void DolphinMainWindow::handlePlacesClick(const KUrl& url, Qt::MouseButtons buttons)
767 {
768 if (buttons & Qt::MidButton) {
769 openNewTab(url);
770 m_tabBar->setCurrentIndex(m_viewTab.count() - 1);
771 } else {
772 changeUrl(url);
773 }
774 }
775
776 void DolphinMainWindow::init()
777 {
778 DolphinSettings& settings = DolphinSettings::instance();
779
780 // Check whether Dolphin runs the first time. If yes then
781 // a proper default window size is given at the end of DolphinMainWindow::init().
782 GeneralSettings* generalSettings = settings.generalSettings();
783 const bool firstRun = generalSettings->firstRun();
784 if (firstRun) {
785 generalSettings->setViewPropsTimestamp(QDateTime::currentDateTime());
786 }
787
788 setAcceptDrops(true);
789
790 m_viewTab[m_tabIndex].splitter = new QSplitter(this);
791
792 setupActions();
793
794 const KUrl& homeUrl = generalSettings->homeUrl();
795 setCaption(homeUrl.fileName());
796 m_actionHandler = new DolphinViewActionHandler(actionCollection(), this);
797 connect(m_actionHandler, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
798 ViewProperties props(homeUrl);
799 m_viewTab[m_tabIndex].primaryView = new DolphinViewContainer(this,
800 m_viewTab[m_tabIndex].splitter,
801 homeUrl);
802
803 m_activeViewContainer = m_viewTab[m_tabIndex].primaryView;
804 connectViewSignals(m_activeViewContainer);
805 DolphinView* view = m_activeViewContainer->view();
806 view->reload();
807 m_activeViewContainer->show();
808 m_actionHandler->setCurrentView(view);
809
810 m_tabBar = new KTabBar(this);
811 m_tabBar->setCloseButtonEnabled(true);
812 connect(m_tabBar, SIGNAL(currentChanged(int)),
813 this, SLOT(setActiveTab(int)));
814 connect(m_tabBar, SIGNAL(closeRequest(int)),
815 this, SLOT(closeTab(int)));
816 connect(m_tabBar, SIGNAL(contextMenu(int, const QPoint&)),
817 this, SLOT(openTabContextMenu(int, const QPoint&)));
818 connect(m_tabBar, SIGNAL(newTabRequest()),
819 this, SLOT(openNewTab()));
820 m_tabBar->blockSignals(true); // signals get unblocked after at least 2 tabs are open
821
822 QWidget* centralWidget = new QWidget(this);
823 m_centralWidgetLayout = new QVBoxLayout(centralWidget);
824 m_centralWidgetLayout->setSpacing(0);
825 m_centralWidgetLayout->setMargin(0);
826 m_centralWidgetLayout->addWidget(m_tabBar);
827 m_centralWidgetLayout->addWidget(m_viewTab[m_tabIndex].splitter);
828
829
830 setCentralWidget(centralWidget);
831 setupDockWidgets();
832
833 setupGUI(Keys | Save | Create | ToolBar);
834 createGUI();
835
836 stateChanged("new_file");
837 setAutoSaveSettings();
838
839 QClipboard* clipboard = QApplication::clipboard();
840 connect(clipboard, SIGNAL(dataChanged()),
841 this, SLOT(updatePasteAction()));
842 updatePasteAction();
843 updateGoActions();
844
845 if (generalSettings->splitView()) {
846 toggleSplitView();
847 }
848 updateViewActions();
849
850 if (firstRun) {
851 // assure a proper default size if Dolphin runs the first time
852 resize(750, 500);
853 }
854
855 emit urlChanged(homeUrl);
856 }
857
858 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer* viewContainer)
859 {
860 Q_ASSERT(viewContainer != 0);
861 Q_ASSERT((viewContainer == m_viewTab[m_tabIndex].primaryView) ||
862 (viewContainer == m_viewTab[m_tabIndex].secondaryView));
863 if (m_activeViewContainer == viewContainer) {
864 return;
865 }
866
867 m_activeViewContainer->setActive(false);
868 m_activeViewContainer = viewContainer;
869
870 // Activating the view container might trigger a recursive setActiveViewContainer() call
871 // inside DolphinMainWindow::toggleActiveView() when having a split view. Temporary
872 // disconnect the activated() signal in this case:
873 disconnect(m_activeViewContainer->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
874 m_activeViewContainer->setActive(true);
875 connect(m_activeViewContainer->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
876
877 m_actionHandler->setCurrentView(viewContainer->view());
878
879 updateHistory();
880 updateEditActions();
881 updateViewActions();
882 updateGoActions();
883
884 const KUrl& url = m_activeViewContainer->url();
885 setCaption(url.fileName());
886 if (m_viewTab.count() > 1) {
887 m_tabBar->setTabText(m_tabIndex, tabName(url));
888 }
889
890 emit urlChanged(url);
891 }
892
893 void DolphinMainWindow::setupActions()
894 {
895 // setup 'File' menu
896 m_newMenu = new DolphinNewMenu(this);
897 KMenu* menu = m_newMenu->menu();
898 menu->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
899 menu->setIcon(KIcon("document-new"));
900 connect(menu, SIGNAL(aboutToShow()),
901 this, SLOT(updateNewMenu()));
902
903 KAction* newWindow = actionCollection()->addAction("new_window");
904 newWindow->setIcon(KIcon("window-new"));
905 newWindow->setText(i18nc("@action:inmenu File", "New &Window"));
906 newWindow->setShortcut(Qt::CTRL | Qt::Key_N);
907 connect(newWindow, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
908
909 KAction* newTab = actionCollection()->addAction("new_tab");
910 newTab->setIcon(KIcon("tab-new"));
911 newTab->setText(i18nc("@action:inmenu File", "New Tab"));
912 newTab->setShortcut(KShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_N, Qt::CTRL | Qt::Key_T));
913 connect(newTab, SIGNAL(triggered()), this, SLOT(openNewTab()));
914
915 QAction* closeTab = new QAction(KIcon("tab-close"), i18nc("@action:inmenu File", "Close Tab"), this);
916 closeTab->setShortcut(Qt::CTRL | Qt::Key_W);
917 connect(closeTab, SIGNAL(triggered()), this, SLOT(closeTab()));
918 actionCollection()->addAction("close_tab", closeTab);
919
920 KAction* properties = actionCollection()->addAction("properties");
921 properties->setText(i18nc("@action:inmenu File", "Properties"));
922 properties->setShortcut(Qt::ALT | Qt::Key_Return);
923 connect(properties, SIGNAL(triggered()), this, SLOT(properties()));
924
925 KStandardAction::quit(this, SLOT(quit()), actionCollection());
926
927 // setup 'Edit' menu
928 KStandardAction::undo(this,
929 SLOT(undo()),
930 actionCollection());
931
932 // need to remove shift+del from cut action, else the shortcut for deletejob
933 // doesn't work
934 KAction* cut = KStandardAction::cut(this, SLOT(cut()), actionCollection());
935 KShortcut cutShortcut = cut->shortcut();
936 cutShortcut.remove(Qt::SHIFT + Qt::Key_Delete, KShortcut::KeepEmpty);
937 cut->setShortcut(cutShortcut);
938 KStandardAction::copy(this, SLOT(copy()), actionCollection());
939 KStandardAction::paste(this, SLOT(paste()), actionCollection());
940
941 KAction* selectAll = actionCollection()->addAction("select_all");
942 selectAll->setText(i18nc("@action:inmenu Edit", "Select All"));
943 selectAll->setShortcut(Qt::CTRL + Qt::Key_A);
944 connect(selectAll, SIGNAL(triggered()), this, SLOT(selectAll()));
945
946 KAction* invertSelection = actionCollection()->addAction("invert_selection");
947 invertSelection->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
948 invertSelection->setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_A);
949 connect(invertSelection, SIGNAL(triggered()), this, SLOT(invertSelection()));
950
951 // setup 'View' menu
952 // (note that most of it is set up in DolphinViewActionHandler)
953
954 KAction* split = actionCollection()->addAction("split_view");
955 split->setShortcut(Qt::Key_F3);
956 updateSplitAction();
957 connect(split, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
958
959 KAction* reload = actionCollection()->addAction("reload");
960 reload->setText(i18nc("@action:inmenu View", "Reload"));
961 reload->setShortcut(Qt::Key_F5);
962 reload->setIcon(KIcon("view-refresh"));
963 connect(reload, SIGNAL(triggered()), this, SLOT(reloadView()));
964
965 KAction* stop = actionCollection()->addAction("stop");
966 stop->setText(i18nc("@action:inmenu View", "Stop"));
967 stop->setIcon(KIcon("process-stop"));
968 connect(stop, SIGNAL(triggered()), this, SLOT(stopLoading()));
969
970 // TODO: the naming "Show full Location" is currently confusing...
971 KToggleAction* showFullLocation = actionCollection()->add<KToggleAction>("editable_location");
972 showFullLocation->setText(i18nc("@action:inmenu Navigation Bar", "Show Full Location"));
973 showFullLocation->setShortcut(Qt::CTRL | Qt::Key_L);
974 connect(showFullLocation, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
975
976 KAction* editLocation = actionCollection()->addAction("edit_location");
977 editLocation->setText(i18nc("@action:inmenu Navigation Bar", "Edit Location"));
978 editLocation->setShortcut(Qt::Key_F6);
979 connect(editLocation, SIGNAL(triggered()), this, SLOT(editLocation()));
980
981 // setup 'Go' menu
982 KAction* backAction = KStandardAction::back(this, SLOT(goBack()), actionCollection());
983 KShortcut backShortcut = backAction->shortcut();
984 backShortcut.setAlternate(Qt::Key_Backspace);
985 backAction->setShortcut(backShortcut);
986
987 KStandardAction::forward(this, SLOT(goForward()), actionCollection());
988 KStandardAction::up(this, SLOT(goUp()), actionCollection());
989 KStandardAction::home(this, SLOT(goHome()), actionCollection());
990
991 // setup 'Tools' menu
992 KToggleAction* showFilterBar = actionCollection()->add<KToggleAction>("show_filter_bar");
993 showFilterBar->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
994 showFilterBar->setShortcut(Qt::CTRL | Qt::Key_I);
995 connect(showFilterBar, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
996
997 KAction* compareFiles = actionCollection()->addAction("compare_files");
998 compareFiles->setText(i18nc("@action:inmenu Tools", "Compare Files"));
999 compareFiles->setIcon(KIcon("kompare"));
1000 compareFiles->setEnabled(false);
1001 connect(compareFiles, SIGNAL(triggered()), this, SLOT(compareFiles()));
1002
1003 // setup 'Settings' menu
1004 m_showMenuBar = KStandardAction::showMenubar(this, SLOT(toggleShowMenuBar()), actionCollection());
1005 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1006 }
1007
1008 void DolphinMainWindow::setupDockWidgets()
1009 {
1010 // setup "Information"
1011 QDockWidget* infoDock = new QDockWidget(i18nc("@title:window", "Information"));
1012 infoDock->setObjectName("infoDock");
1013 infoDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1014 SidebarPage* infoWidget = new InfoSidebarPage(infoDock);
1015 infoDock->setWidget(infoWidget);
1016
1017 infoDock->toggleViewAction()->setText(i18nc("@title:window", "Information"));
1018 infoDock->toggleViewAction()->setShortcut(Qt::Key_F11);
1019 actionCollection()->addAction("show_info_panel", infoDock->toggleViewAction());
1020
1021 addDockWidget(Qt::RightDockWidgetArea, infoDock);
1022 connect(this, SIGNAL(urlChanged(KUrl)),
1023 infoWidget, SLOT(setUrl(KUrl)));
1024 connect(this, SIGNAL(selectionChanged(KFileItemList)),
1025 infoWidget, SLOT(setSelection(KFileItemList)));
1026 connect(this, SIGNAL(requestItemInfo(KFileItem)),
1027 infoWidget, SLOT(requestDelayedItemInfo(KFileItem)));
1028
1029 // setup "Tree View"
1030 QDockWidget* treeViewDock = new QDockWidget(i18nc("@title:window", "Folders"));
1031 treeViewDock->setObjectName("treeViewDock");
1032 treeViewDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1033 TreeViewSidebarPage* treeWidget = new TreeViewSidebarPage(treeViewDock);
1034 treeViewDock->setWidget(treeWidget);
1035
1036 treeViewDock->toggleViewAction()->setText(i18nc("@title:window", "Folders"));
1037 treeViewDock->toggleViewAction()->setShortcut(Qt::Key_F7);
1038 actionCollection()->addAction("show_folders_panel", treeViewDock->toggleViewAction());
1039
1040 addDockWidget(Qt::LeftDockWidgetArea, treeViewDock);
1041 connect(this, SIGNAL(urlChanged(KUrl)),
1042 treeWidget, SLOT(setUrl(KUrl)));
1043 connect(treeWidget, SIGNAL(changeUrl(KUrl, Qt::MouseButtons)),
1044 this, SLOT(handlePlacesClick(KUrl, Qt::MouseButtons)));
1045 connect(treeWidget, SIGNAL(changeSelection(KFileItemList)),
1046 this, SLOT(changeSelection(KFileItemList)));
1047 connect(treeWidget, SIGNAL(urlsDropped(KUrl::List, KUrl)),
1048 this, SLOT(dropUrls(KUrl::List, KUrl)));
1049
1050 // setup "Terminal"
1051 #ifndef Q_OS_WIN
1052 QDockWidget* terminalDock = new QDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1053 terminalDock->setObjectName("terminalDock");
1054 terminalDock->setAllowedAreas(Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea);
1055 SidebarPage* terminalWidget = new TerminalSidebarPage(terminalDock);
1056 terminalDock->setWidget(terminalWidget);
1057
1058 connect(terminalWidget, SIGNAL(hideTerminalSidebarPage()), terminalDock, SLOT(hide()));
1059
1060 terminalDock->toggleViewAction()->setText(i18nc("@title:window Shell terminal", "Terminal"));
1061 terminalDock->toggleViewAction()->setShortcut(Qt::Key_F4);
1062 actionCollection()->addAction("show_terminal_panel", terminalDock->toggleViewAction());
1063
1064 addDockWidget(Qt::BottomDockWidgetArea, terminalDock);
1065 connect(this, SIGNAL(urlChanged(KUrl)),
1066 terminalWidget, SLOT(setUrl(KUrl)));
1067 #endif
1068
1069 const bool firstRun = DolphinSettings::instance().generalSettings()->firstRun();
1070 if (firstRun) {
1071 treeViewDock->hide();
1072 #ifndef Q_OS_WIN
1073 terminalDock->hide();
1074 #endif
1075 }
1076
1077 QDockWidget* placesDock = new QDockWidget(i18nc("@title:window", "Places"));
1078 placesDock->setObjectName("placesDock");
1079 placesDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1080
1081 DolphinFilePlacesView* placesView = new DolphinFilePlacesView(placesDock);
1082 placesDock->setWidget(placesView);
1083 placesView->setModel(DolphinSettings::instance().placesModel());
1084 placesView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
1085
1086 placesDock->toggleViewAction()->setText(i18nc("@title:window", "Places"));
1087 placesDock->toggleViewAction()->setShortcut(Qt::Key_F9);
1088 actionCollection()->addAction("show_places_panel", placesDock->toggleViewAction());
1089
1090 addDockWidget(Qt::LeftDockWidgetArea, placesDock);
1091 connect(placesView, SIGNAL(urlChanged(KUrl, Qt::MouseButtons)),
1092 this, SLOT(handlePlacesClick(KUrl, Qt::MouseButtons)));
1093 connect(this, SIGNAL(urlChanged(KUrl)),
1094 placesView, SLOT(setUrl(KUrl)));
1095 }
1096
1097 void DolphinMainWindow::updateEditActions()
1098 {
1099 const KFileItemList list = m_activeViewContainer->view()->selectedItems();
1100 if (list.isEmpty()) {
1101 stateChanged("has_no_selection");
1102 } else {
1103 stateChanged("has_selection");
1104
1105 KActionCollection* col = actionCollection();
1106 QAction* renameAction = col->action("rename");
1107 QAction* moveToTrashAction = col->action("move_to_trash");
1108 QAction* deleteAction = col->action("delete");
1109 QAction* cutAction = col->action(KStandardAction::name(KStandardAction::Cut));
1110 QAction* deleteWithTrashShortcut = col->action("delete_shortcut"); // see DolphinViewActionHandler
1111
1112 KonqFileItemCapabilities capabilities(list);
1113 const bool enableMoveToTrash = capabilities.isLocal() && capabilities.supportsMoving();
1114
1115 renameAction->setEnabled(capabilities.supportsMoving());
1116 moveToTrashAction->setEnabled(enableMoveToTrash);
1117 deleteAction->setEnabled(capabilities.supportsDeleting());
1118 deleteWithTrashShortcut->setEnabled(capabilities.supportsDeleting() && !enableMoveToTrash);
1119 cutAction->setEnabled(capabilities.supportsMoving());
1120 }
1121 updatePasteAction();
1122 }
1123
1124 void DolphinMainWindow::updateViewActions()
1125 {
1126 m_actionHandler->updateViewActions();
1127
1128 QAction* showFilterBarAction = actionCollection()->action("show_filter_bar");
1129 showFilterBarAction->setChecked(m_activeViewContainer->isFilterBarVisible());
1130
1131 updateSplitAction();
1132
1133 QAction* editableLocactionAction = actionCollection()->action("editable_location");
1134 const KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
1135 editableLocactionAction->setChecked(urlNavigator->isUrlEditable());
1136 }
1137
1138 void DolphinMainWindow::updateGoActions()
1139 {
1140 QAction* goUpAction = actionCollection()->action(KStandardAction::name(KStandardAction::Up));
1141 const KUrl& currentUrl = m_activeViewContainer->url();
1142 goUpAction->setEnabled(currentUrl.upUrl() != currentUrl);
1143 }
1144
1145 void DolphinMainWindow::clearStatusBar()
1146 {
1147 m_activeViewContainer->statusBar()->clear();
1148 }
1149
1150 void DolphinMainWindow::connectViewSignals(DolphinViewContainer* container)
1151 {
1152 connect(container, SIGNAL(showFilterBarChanged(bool)),
1153 this, SLOT(updateFilterBarAction(bool)));
1154
1155 DolphinView* view = container->view();
1156 connect(view, SIGNAL(selectionChanged(KFileItemList)),
1157 this, SLOT(slotSelectionChanged(KFileItemList)));
1158 connect(view, SIGNAL(requestItemInfo(KFileItem)),
1159 this, SLOT(slotRequestItemInfo(KFileItem)));
1160 connect(view, SIGNAL(activated()),
1161 this, SLOT(toggleActiveView()));
1162 connect(view, SIGNAL(doingOperation(KIO::FileUndoManager::CommandType)),
1163 this, SLOT(slotDoingOperation(KIO::FileUndoManager::CommandType)));
1164 connect(view, SIGNAL(tabRequested(const KUrl&)),
1165 this, SLOT(openNewTab(const KUrl&)));
1166
1167 const KUrlNavigator* navigator = container->urlNavigator();
1168 connect(navigator, SIGNAL(urlChanged(const KUrl&)),
1169 this, SLOT(changeUrl(const KUrl&)));
1170 connect(navigator, SIGNAL(historyChanged()),
1171 this, SLOT(updateHistory()));
1172 connect(navigator, SIGNAL(editableStateChanged(bool)),
1173 this, SLOT(slotEditableStateChanged(bool)));
1174 }
1175
1176 void DolphinMainWindow::updateSplitAction()
1177 {
1178 QAction* splitAction = actionCollection()->action("split_view");
1179 if (m_viewTab[m_tabIndex].secondaryView != 0) {
1180 if (m_activeViewContainer == m_viewTab[m_tabIndex].primaryView) {
1181 splitAction->setText(i18nc("@action:intoolbar Close right view", "Close"));
1182 splitAction->setIcon(KIcon("view-right-close"));
1183 } else {
1184 splitAction->setText(i18nc("@action:intoolbar Close left view", "Close"));
1185 splitAction->setIcon(KIcon("view-left-close"));
1186 }
1187 } else {
1188 splitAction->setText(i18nc("@action:intoolbar Split view", "Split"));
1189 splitAction->setIcon(KIcon("view-right-new"));
1190 }
1191 }
1192
1193 QString DolphinMainWindow::tabName(const KUrl& url) const
1194 {
1195 QString name;
1196 if (url.equals(KUrl("file:///"))) {
1197 name = "/";
1198 } else {
1199 name = url.fileName();
1200 if (name.isEmpty()) {
1201 name = url.protocol();
1202 }
1203 }
1204 return name;
1205 }
1206
1207 bool DolphinMainWindow::isKompareInstalled() const
1208 {
1209 static bool initialized = false;
1210 static bool installed = false;
1211 if (!initialized) {
1212 // TODO: maybe replace this approach later by using a menu
1213 // plugin like kdiff3plugin.cpp
1214 installed = !KGlobal::dirs()->findExe("kompare").isEmpty();
1215 initialized = true;
1216 }
1217 return installed;
1218 }
1219
1220 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
1221 KIO::FileUndoManager::UiInterface()
1222 {
1223 }
1224
1225 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
1226 {
1227 }
1228
1229 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job* job)
1230 {
1231 DolphinMainWindow* mainWin= qobject_cast<DolphinMainWindow *>(parentWidget());
1232 if (mainWin) {
1233 DolphinStatusBar* statusBar = mainWin->activeViewContainer()->statusBar();
1234 statusBar->setMessage(job->errorString(), DolphinStatusBar::Error);
1235 } else {
1236 KIO::FileUndoManager::UiInterface::jobError(job);
1237 }
1238 }
1239
1240 #include "dolphinmainwindow.moc"