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