]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.cpp
fdf3947229db9047a20b0f329696f9b93804802b
[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 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()->selectedItemsCount();
206 if (m_viewTab[m_tabIndex].secondaryView != 0) {
207 selectedUrlsCount += m_viewTab[m_tabIndex].secondaryView->view()->selectedItemsCount();
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 const bool activeViewHasSelection = (activeViewContainer()->view()->selectedItemsCount() > 0);
218 actionCollection()->action("quick_view")->setEnabled(activeViewHasSelection);
219
220 m_activeViewContainer->updateStatusBar();
221
222 emit selectionChanged(selection);
223 }
224
225 void DolphinMainWindow::slotRequestItemInfo(const KFileItem& item)
226 {
227 emit requestItemInfo(item);
228 }
229
230 void DolphinMainWindow::updateHistory()
231 {
232 const KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
233 const int index = urlNavigator->historyIndex();
234
235 QAction* backAction = actionCollection()->action("go_back");
236 if (backAction != 0) {
237 backAction->setEnabled(index < urlNavigator->historySize() - 1);
238 }
239
240 QAction* forwardAction = actionCollection()->action("go_forward");
241 if (forwardAction != 0) {
242 forwardAction->setEnabled(index > 0);
243 }
244 }
245
246 void DolphinMainWindow::updateFilterBarAction(bool show)
247 {
248 QAction* showFilterBarAction = actionCollection()->action("show_filter_bar");
249 showFilterBarAction->setChecked(show);
250 }
251
252 void DolphinMainWindow::openNewMainWindow()
253 {
254 DolphinApplication::app()->createMainWindow()->show();
255 }
256
257 void DolphinMainWindow::openNewTab()
258 {
259 openNewTab(m_activeViewContainer->url());
260 m_tabBar->setCurrentIndex(m_viewTab.count() - 1);
261 }
262
263 void DolphinMainWindow::openNewTab(const KUrl& url)
264 {
265 if (m_viewTab.count() == 1) {
266 // Only one view is open currently and hence no tab is shown at
267 // all. Before creating a tab for 'url', provide a tab for the current URL.
268 m_tabBar->addTab(KIcon("folder"), tabName(m_activeViewContainer->url()));
269 m_tabBar->blockSignals(false);
270 }
271
272 m_tabBar->addTab(KIcon("folder"), tabName(url));
273
274 ViewTab viewTab;
275 viewTab.splitter = new QSplitter(this);
276 viewTab.primaryView = new DolphinViewContainer(this, viewTab.splitter, url);
277 connectViewSignals(viewTab.primaryView);
278 viewTab.primaryView->view()->reload();
279
280 m_viewTab.append(viewTab);
281
282 actionCollection()->action("close_tab")->setEnabled(true);
283 }
284
285 void DolphinMainWindow::toggleActiveView()
286 {
287 if (m_viewTab[m_tabIndex].secondaryView == 0) {
288 // only one view is available
289 return;
290 }
291
292 Q_ASSERT(m_activeViewContainer != 0);
293 Q_ASSERT(m_viewTab[m_tabIndex].primaryView != 0);
294
295 DolphinViewContainer* left = m_viewTab[m_tabIndex].primaryView;
296 DolphinViewContainer* right = m_viewTab[m_tabIndex].secondaryView;
297 setActiveViewContainer(m_activeViewContainer == right ? left : right);
298 }
299
300 void DolphinMainWindow::closeEvent(QCloseEvent* event)
301 {
302 DolphinSettings& settings = DolphinSettings::instance();
303 GeneralSettings* generalSettings = settings.generalSettings();
304 generalSettings->setFirstRun(false);
305
306 settings.save();
307
308 KXmlGuiWindow::closeEvent(event);
309 }
310
311 void DolphinMainWindow::saveProperties(KConfigGroup& group)
312 {
313 // TODO: remember tabs
314 DolphinViewContainer* cont = m_viewTab[m_tabIndex].primaryView;
315 group.writeEntry("Primary Url", cont->url().url());
316 group.writeEntry("Primary Editable Url", cont->isUrlEditable());
317
318 cont = m_viewTab[m_tabIndex].secondaryView;
319 if (cont != 0) {
320 group.writeEntry("Secondary Url", cont->url().url());
321 group.writeEntry("Secondary Editable Url", cont->isUrlEditable());
322 }
323 }
324
325 void DolphinMainWindow::readProperties(const KConfigGroup& group)
326 {
327 // TODO: read tabs
328 DolphinViewContainer* cont = m_viewTab[m_tabIndex].primaryView;
329
330 cont->setUrl(group.readEntry("Primary Url"));
331 bool editable = group.readEntry("Primary Editable Url", false);
332 cont->urlNavigator()->setUrlEditable(editable);
333
334 cont = m_viewTab[m_tabIndex].secondaryView;
335 const QString secondaryUrl = group.readEntry("Secondary Url");
336 if (!secondaryUrl.isEmpty()) {
337 if (cont == 0) {
338 // a secondary view should be shown, but no one is available
339 // currently -> create a new view
340 toggleSplitView();
341 cont = m_viewTab[m_tabIndex].secondaryView;
342 Q_ASSERT(cont != 0);
343 }
344
345 cont->setUrl(secondaryUrl);
346 bool editable = group.readEntry("Secondary Editable Url", false);
347 cont->urlNavigator()->setUrlEditable(editable);
348 } else if (cont != 0) {
349 // no secondary view should be shown, but the default setting shows
350 // one already -> close the view
351 toggleSplitView();
352 }
353 }
354
355 void DolphinMainWindow::updateNewMenu()
356 {
357 m_newMenu->slotCheckUpToDate();
358 m_newMenu->setPopupFiles(activeViewContainer()->url());
359 }
360
361 void DolphinMainWindow::quit()
362 {
363 close();
364 }
365
366 void DolphinMainWindow::slotHandlePlacesError(const QString &message)
367 {
368 if (!message.isEmpty()) {
369 DolphinStatusBar* statusBar = m_activeViewContainer->statusBar();
370 statusBar->setMessage(message, DolphinStatusBar::Error);
371 }
372 }
373
374 void DolphinMainWindow::slotUndoAvailable(bool available)
375 {
376 QAction* undoAction = actionCollection()->action(KStandardAction::name(KStandardAction::Undo));
377 if (undoAction != 0) {
378 undoAction->setEnabled(available);
379 }
380
381 if (available && (m_undoCommandTypes.count() > 0)) {
382 const KIO::FileUndoManager::CommandType command = m_undoCommandTypes.takeFirst();
383 DolphinStatusBar* statusBar = m_activeViewContainer->statusBar();
384 switch (command) {
385 case KIO::FileUndoManager::Copy:
386 statusBar->setMessage(i18nc("@info:status", "Copy operation completed."),
387 DolphinStatusBar::OperationCompleted);
388 break;
389 case KIO::FileUndoManager::Move:
390 statusBar->setMessage(i18nc("@info:status", "Move operation completed."),
391 DolphinStatusBar::OperationCompleted);
392 break;
393 case KIO::FileUndoManager::Link:
394 statusBar->setMessage(i18nc("@info:status", "Link operation completed."),
395 DolphinStatusBar::OperationCompleted);
396 break;
397 case KIO::FileUndoManager::Trash:
398 statusBar->setMessage(i18nc("@info:status", "Move to trash operation completed."),
399 DolphinStatusBar::OperationCompleted);
400 break;
401 case KIO::FileUndoManager::Rename:
402 statusBar->setMessage(i18nc("@info:status", "Renaming operation completed."),
403 DolphinStatusBar::OperationCompleted);
404 break;
405
406 case KIO::FileUndoManager::Mkdir:
407 statusBar->setMessage(i18nc("@info:status", "Created folder."),
408 DolphinStatusBar::OperationCompleted);
409 break;
410
411 default:
412 break;
413 }
414
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::init()
778 {
779 DolphinSettings& settings = DolphinSettings::instance();
780
781 // Check whether Dolphin runs the first time. If yes then
782 // a proper default window size is given at the end of DolphinMainWindow::init().
783 GeneralSettings* generalSettings = settings.generalSettings();
784 const bool firstRun = generalSettings->firstRun();
785 if (firstRun) {
786 generalSettings->setViewPropsTimestamp(QDateTime::currentDateTime());
787 }
788
789 setAcceptDrops(true);
790
791 m_viewTab[m_tabIndex].splitter = new QSplitter(this);
792
793 setupActions();
794
795 const KUrl& homeUrl = generalSettings->homeUrl();
796 setCaption(homeUrl.fileName());
797 m_actionHandler = new DolphinViewActionHandler(actionCollection(), this);
798 connect(m_actionHandler, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
799 ViewProperties props(homeUrl);
800 m_viewTab[m_tabIndex].primaryView = new DolphinViewContainer(this,
801 m_viewTab[m_tabIndex].splitter,
802 homeUrl);
803
804 m_activeViewContainer = m_viewTab[m_tabIndex].primaryView;
805 connectViewSignals(m_activeViewContainer);
806 DolphinView* view = m_activeViewContainer->view();
807 view->reload();
808 m_activeViewContainer->show();
809 m_actionHandler->setCurrentView(view);
810
811 m_tabBar = new KTabBar(this);
812 m_tabBar->setCloseButtonEnabled(true);
813 connect(m_tabBar, SIGNAL(currentChanged(int)),
814 this, SLOT(setActiveTab(int)));
815 connect(m_tabBar, SIGNAL(closeRequest(int)),
816 this, SLOT(closeTab(int)));
817 connect(m_tabBar, SIGNAL(contextMenu(int, const QPoint&)),
818 this, SLOT(openTabContextMenu(int, const QPoint&)));
819 connect(m_tabBar, SIGNAL(newTabRequest()),
820 this, SLOT(openNewTab()));
821 m_tabBar->blockSignals(true); // signals get unblocked after at least 2 tabs are open
822
823 QWidget* centralWidget = new QWidget(this);
824 m_centralWidgetLayout = new QVBoxLayout(centralWidget);
825 m_centralWidgetLayout->setSpacing(0);
826 m_centralWidgetLayout->setMargin(0);
827 m_centralWidgetLayout->addWidget(m_tabBar);
828 m_centralWidgetLayout->addWidget(m_viewTab[m_tabIndex].splitter);
829
830
831 setCentralWidget(centralWidget);
832 setupDockWidgets();
833
834 setupGUI(Keys | Save | Create | ToolBar);
835 createGUI();
836
837 stateChanged("new_file");
838 setAutoSaveSettings();
839
840 QClipboard* clipboard = QApplication::clipboard();
841 connect(clipboard, SIGNAL(dataChanged()),
842 this, SLOT(updatePasteAction()));
843 updatePasteAction();
844 updateGoActions();
845
846 if (generalSettings->splitView()) {
847 toggleSplitView();
848 }
849 updateViewActions();
850
851 if (firstRun) {
852 // assure a proper default size if Dolphin runs the first time
853 resize(750, 500);
854 }
855
856 emit urlChanged(homeUrl);
857 }
858
859 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer* viewContainer)
860 {
861 Q_ASSERT(viewContainer != 0);
862 Q_ASSERT((viewContainer == m_viewTab[m_tabIndex].primaryView) ||
863 (viewContainer == m_viewTab[m_tabIndex].secondaryView));
864 if (m_activeViewContainer == viewContainer) {
865 return;
866 }
867
868 m_activeViewContainer->setActive(false);
869 m_activeViewContainer = viewContainer;
870
871 // Activating the view container might trigger a recursive setActiveViewContainer() call
872 // inside DolphinMainWindow::toggleActiveView() when having a split view. Temporary
873 // disconnect the activated() signal in this case:
874 disconnect(m_activeViewContainer->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
875 m_activeViewContainer->setActive(true);
876 connect(m_activeViewContainer->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
877
878 m_actionHandler->setCurrentView(viewContainer->view());
879
880 updateHistory();
881 updateEditActions();
882 updateViewActions();
883 updateGoActions();
884
885 const KUrl& url = m_activeViewContainer->url();
886 setCaption(url.fileName());
887 if (m_viewTab.count() > 1) {
888 m_tabBar->setTabText(m_tabIndex, tabName(url));
889 }
890
891 emit urlChanged(url);
892 }
893
894 void DolphinMainWindow::setupActions()
895 {
896 // setup 'File' menu
897 m_newMenu = new DolphinNewMenu(this);
898 KMenu* menu = m_newMenu->menu();
899 menu->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
900 menu->setIcon(KIcon("document-new"));
901 connect(menu, SIGNAL(aboutToShow()),
902 this, SLOT(updateNewMenu()));
903
904 KAction* newWindow = actionCollection()->addAction("new_window");
905 newWindow->setIcon(KIcon("window-new"));
906 newWindow->setText(i18nc("@action:inmenu File", "New &Window"));
907 newWindow->setShortcut(Qt::CTRL | Qt::Key_N);
908 connect(newWindow, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
909
910 KAction* newTab = actionCollection()->addAction("new_tab");
911 newTab->setIcon(KIcon("tab-new"));
912 newTab->setText(i18nc("@action:inmenu File", "New Tab"));
913 newTab->setShortcut(KShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_N, Qt::CTRL | Qt::Key_T));
914 connect(newTab, SIGNAL(triggered()), this, SLOT(openNewTab()));
915
916 QAction* closeTab = new QAction(KIcon("tab-close"), i18nc("@action:inmenu File", "Close Tab"), this);
917 closeTab->setShortcut(Qt::CTRL | Qt::Key_W);
918 closeTab->setEnabled(false);
919 connect(closeTab, SIGNAL(triggered()), this, SLOT(closeTab()));
920 actionCollection()->addAction("close_tab", closeTab);
921
922 KStandardAction::quit(this, SLOT(quit()), actionCollection());
923
924 // setup 'Edit' menu
925 KStandardAction::undo(this,
926 SLOT(undo()),
927 actionCollection());
928
929 // need to remove shift+del from cut action, else the shortcut for deletejob
930 // doesn't work
931 KAction* cut = KStandardAction::cut(this, SLOT(cut()), actionCollection());
932 KShortcut cutShortcut = cut->shortcut();
933 cutShortcut.remove(Qt::SHIFT + Qt::Key_Delete, KShortcut::KeepEmpty);
934 cut->setShortcut(cutShortcut);
935 KStandardAction::copy(this, SLOT(copy()), actionCollection());
936 KStandardAction::paste(this, SLOT(paste()), actionCollection());
937
938 KAction* selectAll = actionCollection()->addAction("select_all");
939 selectAll->setText(i18nc("@action:inmenu Edit", "Select All"));
940 selectAll->setShortcut(Qt::CTRL + Qt::Key_A);
941 connect(selectAll, SIGNAL(triggered()), this, SLOT(selectAll()));
942
943 KAction* invertSelection = actionCollection()->addAction("invert_selection");
944 invertSelection->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
945 invertSelection->setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_A);
946 connect(invertSelection, SIGNAL(triggered()), this, SLOT(invertSelection()));
947
948 // setup 'View' menu
949 // (note that most of it is set up in DolphinViewActionHandler)
950
951 KAction* split = actionCollection()->addAction("split_view");
952 split->setShortcut(Qt::Key_F3);
953 updateSplitAction();
954 connect(split, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
955
956 KAction* reload = actionCollection()->addAction("reload");
957 reload->setText(i18nc("@action:inmenu View", "Reload"));
958 reload->setShortcut(Qt::Key_F5);
959 reload->setIcon(KIcon("view-refresh"));
960 connect(reload, SIGNAL(triggered()), this, SLOT(reloadView()));
961
962 KAction* stop = actionCollection()->addAction("stop");
963 stop->setText(i18nc("@action:inmenu View", "Stop"));
964 stop->setIcon(KIcon("process-stop"));
965 connect(stop, SIGNAL(triggered()), this, SLOT(stopLoading()));
966
967 // TODO: the naming "Show full Location" is currently confusing...
968 KToggleAction* showFullLocation = actionCollection()->add<KToggleAction>("editable_location");
969 showFullLocation->setText(i18nc("@action:inmenu Navigation Bar", "Show Full Location"));
970 showFullLocation->setShortcut(Qt::CTRL | Qt::Key_L);
971 connect(showFullLocation, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
972
973 KAction* editLocation = actionCollection()->addAction("edit_location");
974 editLocation->setText(i18nc("@action:inmenu Navigation Bar", "Edit Location"));
975 editLocation->setShortcut(Qt::Key_F6);
976 connect(editLocation, SIGNAL(triggered()), this, SLOT(editLocation()));
977
978 // setup 'Go' menu
979 KAction* backAction = KStandardAction::back(this, SLOT(goBack()), actionCollection());
980 KShortcut backShortcut = backAction->shortcut();
981 backShortcut.setAlternate(Qt::Key_Backspace);
982 backAction->setShortcut(backShortcut);
983
984 KStandardAction::forward(this, SLOT(goForward()), actionCollection());
985 KStandardAction::up(this, SLOT(goUp()), actionCollection());
986 KStandardAction::home(this, SLOT(goHome()), actionCollection());
987
988 // setup 'Tools' menu
989 KToggleAction* showFilterBar = actionCollection()->add<KToggleAction>("show_filter_bar");
990 showFilterBar->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
991 showFilterBar->setShortcut(Qt::CTRL | Qt::Key_I);
992 connect(showFilterBar, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
993
994 KAction* compareFiles = actionCollection()->addAction("compare_files");
995 compareFiles->setText(i18nc("@action:inmenu Tools", "Compare Files"));
996 compareFiles->setIcon(KIcon("kompare"));
997 compareFiles->setEnabled(false);
998 connect(compareFiles, SIGNAL(triggered()), this, SLOT(compareFiles()));
999
1000 KAction* quickView = actionCollection()->addAction("quick_view");
1001 quickView->setText(i18nc("@action:inmenu Tools", "Quick View"));
1002 quickView->setIcon(KIcon("view-preview"));
1003 quickView->setShortcut(Qt::Key_Space);
1004 quickView->setEnabled(false);
1005 connect(quickView, SIGNAL(triggered()), this, SLOT(quickView()));
1006
1007 // setup 'Settings' menu
1008 m_showMenuBar = KStandardAction::showMenubar(this, SLOT(toggleShowMenuBar()), actionCollection());
1009 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1010 }
1011
1012 void DolphinMainWindow::setupDockWidgets()
1013 {
1014 // setup "Information"
1015 QDockWidget* infoDock = new QDockWidget(i18nc("@title:window", "Information"));
1016 infoDock->setObjectName("infoDock");
1017 infoDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1018 SidebarPage* infoWidget = new InfoSidebarPage(infoDock);
1019 infoDock->setWidget(infoWidget);
1020
1021 infoDock->toggleViewAction()->setText(i18nc("@title:window", "Information"));
1022 infoDock->toggleViewAction()->setShortcut(Qt::Key_F11);
1023 actionCollection()->addAction("show_info_panel", infoDock->toggleViewAction());
1024
1025 addDockWidget(Qt::RightDockWidgetArea, infoDock);
1026 connect(this, SIGNAL(urlChanged(KUrl)),
1027 infoWidget, SLOT(setUrl(KUrl)));
1028 connect(this, SIGNAL(selectionChanged(KFileItemList)),
1029 infoWidget, SLOT(setSelection(KFileItemList)));
1030 connect(this, SIGNAL(requestItemInfo(KFileItem)),
1031 infoWidget, SLOT(requestDelayedItemInfo(KFileItem)));
1032
1033 // setup "Tree View"
1034 QDockWidget* treeViewDock = new QDockWidget(i18nc("@title:window", "Folders"));
1035 treeViewDock->setObjectName("treeViewDock");
1036 treeViewDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1037 TreeViewSidebarPage* treeWidget = new TreeViewSidebarPage(treeViewDock);
1038 treeViewDock->setWidget(treeWidget);
1039
1040 treeViewDock->toggleViewAction()->setText(i18nc("@title:window", "Folders"));
1041 treeViewDock->toggleViewAction()->setShortcut(Qt::Key_F7);
1042 actionCollection()->addAction("show_folders_panel", treeViewDock->toggleViewAction());
1043
1044 addDockWidget(Qt::LeftDockWidgetArea, treeViewDock);
1045 connect(this, SIGNAL(urlChanged(KUrl)),
1046 treeWidget, SLOT(setUrl(KUrl)));
1047 connect(treeWidget, SIGNAL(changeUrl(KUrl, Qt::MouseButtons)),
1048 this, SLOT(handlePlacesClick(KUrl, Qt::MouseButtons)));
1049 connect(treeWidget, SIGNAL(changeSelection(KFileItemList)),
1050 this, SLOT(changeSelection(KFileItemList)));
1051 connect(treeWidget, SIGNAL(urlsDropped(KUrl::List, KUrl)),
1052 this, SLOT(dropUrls(KUrl::List, KUrl)));
1053
1054 // setup "Terminal"
1055 #ifndef Q_OS_WIN
1056 QDockWidget* terminalDock = new QDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1057 terminalDock->setObjectName("terminalDock");
1058 terminalDock->setAllowedAreas(Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea);
1059 SidebarPage* terminalWidget = new TerminalSidebarPage(terminalDock);
1060 terminalDock->setWidget(terminalWidget);
1061
1062 connect(terminalWidget, SIGNAL(hideTerminalSidebarPage()), terminalDock, SLOT(hide()));
1063
1064 terminalDock->toggleViewAction()->setText(i18nc("@title:window Shell terminal", "Terminal"));
1065 terminalDock->toggleViewAction()->setShortcut(Qt::Key_F4);
1066 actionCollection()->addAction("show_terminal_panel", terminalDock->toggleViewAction());
1067
1068 addDockWidget(Qt::BottomDockWidgetArea, terminalDock);
1069 connect(this, SIGNAL(urlChanged(KUrl)),
1070 terminalWidget, SLOT(setUrl(KUrl)));
1071 #endif
1072
1073 const bool firstRun = DolphinSettings::instance().generalSettings()->firstRun();
1074 if (firstRun) {
1075 treeViewDock->hide();
1076 #ifndef Q_OS_WIN
1077 terminalDock->hide();
1078 #endif
1079 }
1080
1081 QDockWidget* placesDock = new QDockWidget(i18nc("@title:window", "Places"));
1082 placesDock->setObjectName("placesDock");
1083 placesDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1084
1085 DolphinFilePlacesView* placesView = new DolphinFilePlacesView(placesDock);
1086 placesDock->setWidget(placesView);
1087 placesView->setModel(DolphinSettings::instance().placesModel());
1088 placesView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
1089
1090 placesDock->toggleViewAction()->setText(i18nc("@title:window", "Places"));
1091 placesDock->toggleViewAction()->setShortcut(Qt::Key_F9);
1092 actionCollection()->addAction("show_places_panel", placesDock->toggleViewAction());
1093
1094 addDockWidget(Qt::LeftDockWidgetArea, placesDock);
1095 connect(placesView, SIGNAL(urlChanged(KUrl, Qt::MouseButtons)),
1096 this, SLOT(handlePlacesClick(KUrl, Qt::MouseButtons)));
1097 connect(this, SIGNAL(urlChanged(KUrl)),
1098 placesView, SLOT(setUrl(KUrl)));
1099 }
1100
1101 void DolphinMainWindow::updateEditActions()
1102 {
1103 const KFileItemList list = m_activeViewContainer->view()->selectedItems();
1104 if (list.isEmpty()) {
1105 stateChanged("has_no_selection");
1106 } else {
1107 stateChanged("has_selection");
1108
1109 KActionCollection* col = actionCollection();
1110 QAction* renameAction = col->action("rename");
1111 QAction* moveToTrashAction = col->action("move_to_trash");
1112 QAction* deleteAction = col->action("delete");
1113 QAction* cutAction = col->action(KStandardAction::name(KStandardAction::Cut));
1114 QAction* deleteWithTrashShortcut = col->action("delete_shortcut"); // see DolphinViewActionHandler
1115
1116 KonqFileItemCapabilities capabilities(list);
1117 const bool enableMoveToTrash = capabilities.isLocal() && capabilities.supportsMoving();
1118
1119 renameAction->setEnabled(capabilities.supportsMoving());
1120 moveToTrashAction->setEnabled(enableMoveToTrash);
1121 deleteAction->setEnabled(capabilities.supportsDeleting());
1122 deleteWithTrashShortcut->setEnabled(capabilities.supportsDeleting() && !enableMoveToTrash);
1123 cutAction->setEnabled(capabilities.supportsMoving());
1124 }
1125 updatePasteAction();
1126 }
1127
1128 void DolphinMainWindow::updateViewActions()
1129 {
1130 m_actionHandler->updateViewActions();
1131
1132 QAction* showFilterBarAction = actionCollection()->action("show_filter_bar");
1133 showFilterBarAction->setChecked(m_activeViewContainer->isFilterBarVisible());
1134
1135 updateSplitAction();
1136
1137 QAction* editableLocactionAction = actionCollection()->action("editable_location");
1138 const KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
1139 editableLocactionAction->setChecked(urlNavigator->isUrlEditable());
1140 }
1141
1142 void DolphinMainWindow::updateGoActions()
1143 {
1144 QAction* goUpAction = actionCollection()->action(KStandardAction::name(KStandardAction::Up));
1145 const KUrl& currentUrl = m_activeViewContainer->url();
1146 goUpAction->setEnabled(currentUrl.upUrl() != currentUrl);
1147 }
1148
1149 void DolphinMainWindow::clearStatusBar()
1150 {
1151 m_activeViewContainer->statusBar()->clear();
1152 }
1153
1154 void DolphinMainWindow::connectViewSignals(DolphinViewContainer* container)
1155 {
1156 connect(container, SIGNAL(showFilterBarChanged(bool)),
1157 this, SLOT(updateFilterBarAction(bool)));
1158
1159 DolphinView* view = container->view();
1160 connect(view, SIGNAL(selectionChanged(KFileItemList)),
1161 this, SLOT(slotSelectionChanged(KFileItemList)));
1162 connect(view, SIGNAL(requestItemInfo(KFileItem)),
1163 this, SLOT(slotRequestItemInfo(KFileItem)));
1164 connect(view, SIGNAL(activated()),
1165 this, SLOT(toggleActiveView()));
1166 connect(view, SIGNAL(doingOperation(KIO::FileUndoManager::CommandType)),
1167 this, SLOT(slotDoingOperation(KIO::FileUndoManager::CommandType)));
1168 connect(view, SIGNAL(tabRequested(const KUrl&)),
1169 this, SLOT(openNewTab(const KUrl&)));
1170
1171 const KUrlNavigator* navigator = container->urlNavigator();
1172 connect(navigator, SIGNAL(urlChanged(const KUrl&)),
1173 this, SLOT(changeUrl(const KUrl&)));
1174 connect(navigator, SIGNAL(historyChanged()),
1175 this, SLOT(updateHistory()));
1176 connect(navigator, SIGNAL(editableStateChanged(bool)),
1177 this, SLOT(slotEditableStateChanged(bool)));
1178 }
1179
1180 void DolphinMainWindow::updateSplitAction()
1181 {
1182 QAction* splitAction = actionCollection()->action("split_view");
1183 if (m_viewTab[m_tabIndex].secondaryView != 0) {
1184 if (m_activeViewContainer == m_viewTab[m_tabIndex].secondaryView) {
1185 splitAction->setText(i18nc("@action:intoolbar Close right view", "Close"));
1186 splitAction->setIcon(KIcon("view-right-close"));
1187 } else {
1188 splitAction->setText(i18nc("@action:intoolbar Close left view", "Close"));
1189 splitAction->setIcon(KIcon("view-left-close"));
1190 }
1191 } else {
1192 splitAction->setText(i18nc("@action:intoolbar Split view", "Split"));
1193 splitAction->setIcon(KIcon("view-right-new"));
1194 }
1195 }
1196
1197 QString DolphinMainWindow::tabName(const KUrl& url) const
1198 {
1199 QString name;
1200 if (url.equals(KUrl("file:///"))) {
1201 name = "/";
1202 } else {
1203 name = url.fileName();
1204 if (name.isEmpty()) {
1205 name = url.protocol();
1206 }
1207 }
1208 return name;
1209 }
1210
1211 bool DolphinMainWindow::isKompareInstalled() const
1212 {
1213 static bool initialized = false;
1214 static bool installed = false;
1215 if (!initialized) {
1216 // TODO: maybe replace this approach later by using a menu
1217 // plugin like kdiff3plugin.cpp
1218 installed = !KGlobal::dirs()->findExe("kompare").isEmpty();
1219 initialized = true;
1220 }
1221 return installed;
1222 }
1223
1224 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
1225 KIO::FileUndoManager::UiInterface()
1226 {
1227 }
1228
1229 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
1230 {
1231 }
1232
1233 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job* job)
1234 {
1235 DolphinMainWindow* mainWin= qobject_cast<DolphinMainWindow *>(parentWidget());
1236 if (mainWin) {
1237 DolphinStatusBar* statusBar = mainWin->activeViewContainer()->statusBar();
1238 statusBar->setMessage(job->errorString(), DolphinStatusBar::Error);
1239 } else {
1240 KIO::FileUndoManager::UiInterface::jobError(job);
1241 }
1242 }
1243
1244 #include "dolphinmainwindow.moc"