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