]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.cpp
Do not create with Save flag. OMG, this is a very bad problem of XMLGUI... if you...
[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::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
838 setCentralWidget(centralWidget);
839 setupDockWidgets();
840
841 setupGUI(Keys | Create | ToolBar);
842 createGUI();
843
844 stateChanged("new_file");
845 setAutoSaveSettings();
846
847 QClipboard* clipboard = QApplication::clipboard();
848 connect(clipboard, SIGNAL(dataChanged()),
849 this, SLOT(updatePasteAction()));
850 updatePasteAction();
851 updateGoActions();
852
853 if (generalSettings->splitView()) {
854 toggleSplitView();
855 }
856 updateViewActions();
857
858 QAction* showFilterBarAction = actionCollection()->action("show_filter_bar");
859 showFilterBarAction->setChecked(generalSettings->filterBar());
860
861 if (firstRun) {
862 // assure a proper default size if Dolphin runs the first time
863 resize(750, 500);
864 }
865
866 emit urlChanged(homeUrl);
867 }
868
869 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer* viewContainer)
870 {
871 Q_ASSERT(viewContainer != 0);
872 Q_ASSERT((viewContainer == m_viewTab[m_tabIndex].primaryView) ||
873 (viewContainer == m_viewTab[m_tabIndex].secondaryView));
874 if (m_activeViewContainer == viewContainer) {
875 return;
876 }
877
878 m_activeViewContainer->setActive(false);
879 m_activeViewContainer = viewContainer;
880
881 // Activating the view container might trigger a recursive setActiveViewContainer() call
882 // inside DolphinMainWindow::toggleActiveView() when having a split view. Temporary
883 // disconnect the activated() signal in this case:
884 disconnect(m_activeViewContainer->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
885 m_activeViewContainer->setActive(true);
886 connect(m_activeViewContainer->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
887
888 m_actionHandler->setCurrentView(viewContainer->view());
889
890 updateHistory();
891 updateEditActions();
892 updateViewActions();
893 updateGoActions();
894
895 const KUrl& url = m_activeViewContainer->url();
896 setCaption(url.fileName());
897 if (m_viewTab.count() > 1) {
898 m_tabBar->setTabText(m_tabIndex, tabName(url));
899 }
900
901 emit urlChanged(url);
902 }
903
904 void DolphinMainWindow::setupActions()
905 {
906 // setup 'File' menu
907 m_newMenu = new DolphinNewMenu(this);
908 KMenu* menu = m_newMenu->menu();
909 menu->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
910 menu->setIcon(KIcon("document-new"));
911 connect(menu, SIGNAL(aboutToShow()),
912 this, SLOT(updateNewMenu()));
913
914 KAction* newWindow = actionCollection()->addAction("new_window");
915 newWindow->setIcon(KIcon("window-new"));
916 newWindow->setText(i18nc("@action:inmenu File", "New &Window"));
917 newWindow->setShortcut(Qt::CTRL | Qt::Key_N);
918 connect(newWindow, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
919
920 KAction* newTab = actionCollection()->addAction("new_tab");
921 newTab->setIcon(KIcon("tab-new"));
922 newTab->setText(i18nc("@action:inmenu File", "New Tab"));
923 newTab->setShortcut(KShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_N, Qt::CTRL | Qt::Key_T));
924 connect(newTab, SIGNAL(triggered()), this, SLOT(openNewTab()));
925
926 QAction* closeTab = new QAction(KIcon("tab-close"), i18nc("@action:inmenu File", "Close Tab"), this);
927 closeTab->setShortcut(Qt::CTRL | Qt::Key_W);
928 closeTab->setEnabled(false);
929 connect(closeTab, SIGNAL(triggered()), this, SLOT(closeTab()));
930 actionCollection()->addAction("close_tab", closeTab);
931
932 KStandardAction::quit(this, SLOT(quit()), actionCollection());
933
934 // setup 'Edit' menu
935 KStandardAction::undo(this,
936 SLOT(undo()),
937 actionCollection());
938
939 // need to remove shift+del from cut action, else the shortcut for deletejob
940 // doesn't work
941 KAction* cut = KStandardAction::cut(this, SLOT(cut()), actionCollection());
942 KShortcut cutShortcut = cut->shortcut();
943 cutShortcut.remove(Qt::SHIFT + Qt::Key_Delete, KShortcut::KeepEmpty);
944 cut->setShortcut(cutShortcut);
945 KStandardAction::copy(this, SLOT(copy()), actionCollection());
946 KStandardAction::paste(this, SLOT(paste()), actionCollection());
947
948 KAction* selectAll = actionCollection()->addAction("select_all");
949 selectAll->setText(i18nc("@action:inmenu Edit", "Select All"));
950 selectAll->setShortcut(Qt::CTRL + Qt::Key_A);
951 connect(selectAll, SIGNAL(triggered()), this, SLOT(selectAll()));
952
953 KAction* invertSelection = actionCollection()->addAction("invert_selection");
954 invertSelection->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
955 invertSelection->setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_A);
956 connect(invertSelection, SIGNAL(triggered()), this, SLOT(invertSelection()));
957
958 // setup 'View' menu
959 // (note that most of it is set up in DolphinViewActionHandler)
960
961 KAction* split = actionCollection()->addAction("split_view");
962 split->setShortcut(Qt::Key_F3);
963 updateSplitAction();
964 connect(split, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
965
966 KAction* reload = actionCollection()->addAction("reload");
967 reload->setText(i18nc("@action:inmenu View", "Reload"));
968 reload->setShortcut(Qt::Key_F5);
969 reload->setIcon(KIcon("view-refresh"));
970 connect(reload, SIGNAL(triggered()), this, SLOT(reloadView()));
971
972 KAction* stop = actionCollection()->addAction("stop");
973 stop->setText(i18nc("@action:inmenu View", "Stop"));
974 stop->setIcon(KIcon("process-stop"));
975 connect(stop, SIGNAL(triggered()), this, SLOT(stopLoading()));
976
977 // TODO: the naming "Show full Location" is currently confusing...
978 KToggleAction* showFullLocation = actionCollection()->add<KToggleAction>("editable_location");
979 showFullLocation->setText(i18nc("@action:inmenu Navigation Bar", "Show Full Location"));
980 showFullLocation->setShortcut(Qt::CTRL | Qt::Key_L);
981 connect(showFullLocation, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
982
983 KAction* editLocation = actionCollection()->addAction("edit_location");
984 editLocation->setText(i18nc("@action:inmenu Navigation Bar", "Edit Location"));
985 editLocation->setShortcut(Qt::Key_F6);
986 connect(editLocation, SIGNAL(triggered()), this, SLOT(editLocation()));
987
988 // setup 'Go' menu
989 KAction* backAction = KStandardAction::back(this, SLOT(goBack()), actionCollection());
990 KShortcut backShortcut = backAction->shortcut();
991 backShortcut.setAlternate(Qt::Key_Backspace);
992 backAction->setShortcut(backShortcut);
993
994 KStandardAction::forward(this, SLOT(goForward()), actionCollection());
995 KStandardAction::up(this, SLOT(goUp()), actionCollection());
996 KStandardAction::home(this, SLOT(goHome()), actionCollection());
997
998 // setup 'Tools' menu
999 KToggleAction* showFilterBar = actionCollection()->add<KToggleAction>("show_filter_bar");
1000 showFilterBar->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1001 showFilterBar->setShortcut(Qt::CTRL | Qt::Key_I);
1002 connect(showFilterBar, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
1003
1004 KAction* compareFiles = actionCollection()->addAction("compare_files");
1005 compareFiles->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1006 compareFiles->setIcon(KIcon("kompare"));
1007 compareFiles->setEnabled(false);
1008 connect(compareFiles, SIGNAL(triggered()), this, SLOT(compareFiles()));
1009
1010 KAction* quickView = actionCollection()->addAction("quick_view");
1011 quickView->setText(i18nc("@action:inmenu Tools", "Quick View"));
1012 quickView->setIcon(KIcon("view-preview"));
1013 quickView->setShortcut(Qt::Key_Space);
1014 quickView->setEnabled(false);
1015 connect(quickView, SIGNAL(triggered()), this, SLOT(quickView()));
1016
1017 // setup 'Settings' menu
1018 m_showMenuBar = KStandardAction::showMenubar(this, SLOT(toggleShowMenuBar()), actionCollection());
1019 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1020 }
1021
1022 void DolphinMainWindow::setupDockWidgets()
1023 {
1024 // setup "Information"
1025 QDockWidget* infoDock = new QDockWidget(i18nc("@title:window", "Information"));
1026 infoDock->setObjectName("infoDock");
1027 infoDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1028 SidebarPage* infoWidget = new InfoSidebarPage(infoDock);
1029 infoDock->setWidget(infoWidget);
1030
1031 infoDock->toggleViewAction()->setText(i18nc("@title:window", "Information"));
1032 infoDock->toggleViewAction()->setShortcut(Qt::Key_F11);
1033 actionCollection()->addAction("show_info_panel", infoDock->toggleViewAction());
1034
1035 addDockWidget(Qt::RightDockWidgetArea, infoDock);
1036 connect(this, SIGNAL(urlChanged(KUrl)),
1037 infoWidget, SLOT(setUrl(KUrl)));
1038 connect(this, SIGNAL(selectionChanged(KFileItemList)),
1039 infoWidget, SLOT(setSelection(KFileItemList)));
1040 connect(this, SIGNAL(requestItemInfo(KFileItem)),
1041 infoWidget, SLOT(requestDelayedItemInfo(KFileItem)));
1042
1043 // setup "Tree View"
1044 QDockWidget* treeViewDock = new QDockWidget(i18nc("@title:window", "Folders"));
1045 treeViewDock->setObjectName("treeViewDock");
1046 treeViewDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1047 TreeViewSidebarPage* treeWidget = new TreeViewSidebarPage(treeViewDock);
1048 treeViewDock->setWidget(treeWidget);
1049
1050 treeViewDock->toggleViewAction()->setText(i18nc("@title:window", "Folders"));
1051 treeViewDock->toggleViewAction()->setShortcut(Qt::Key_F7);
1052 actionCollection()->addAction("show_folders_panel", treeViewDock->toggleViewAction());
1053
1054 addDockWidget(Qt::LeftDockWidgetArea, treeViewDock);
1055 connect(this, SIGNAL(urlChanged(KUrl)),
1056 treeWidget, SLOT(setUrl(KUrl)));
1057 connect(treeWidget, SIGNAL(changeUrl(KUrl, Qt::MouseButtons)),
1058 this, SLOT(handlePlacesClick(KUrl, Qt::MouseButtons)));
1059 connect(treeWidget, SIGNAL(changeSelection(KFileItemList)),
1060 this, SLOT(changeSelection(KFileItemList)));
1061 connect(treeWidget, SIGNAL(urlsDropped(KUrl::List, KUrl)),
1062 this, SLOT(dropUrls(KUrl::List, KUrl)));
1063
1064 // setup "Terminal"
1065 #ifndef Q_OS_WIN
1066 QDockWidget* terminalDock = new QDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1067 terminalDock->setObjectName("terminalDock");
1068 terminalDock->setAllowedAreas(Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea);
1069 SidebarPage* terminalWidget = new TerminalSidebarPage(terminalDock);
1070 terminalDock->setWidget(terminalWidget);
1071
1072 connect(terminalWidget, SIGNAL(hideTerminalSidebarPage()), terminalDock, SLOT(hide()));
1073
1074 terminalDock->toggleViewAction()->setText(i18nc("@title:window Shell terminal", "Terminal"));
1075 terminalDock->toggleViewAction()->setShortcut(Qt::Key_F4);
1076 actionCollection()->addAction("show_terminal_panel", terminalDock->toggleViewAction());
1077
1078 addDockWidget(Qt::BottomDockWidgetArea, terminalDock);
1079 connect(this, SIGNAL(urlChanged(KUrl)),
1080 terminalWidget, SLOT(setUrl(KUrl)));
1081 #endif
1082
1083 const bool firstRun = DolphinSettings::instance().generalSettings()->firstRun();
1084 if (firstRun) {
1085 treeViewDock->hide();
1086 #ifndef Q_OS_WIN
1087 terminalDock->hide();
1088 #endif
1089 }
1090
1091 QDockWidget* placesDock = new QDockWidget(i18nc("@title:window", "Places"));
1092 placesDock->setObjectName("placesDock");
1093 placesDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1094
1095 DolphinFilePlacesView* placesView = new DolphinFilePlacesView(placesDock);
1096 placesDock->setWidget(placesView);
1097 placesView->setModel(DolphinSettings::instance().placesModel());
1098 placesView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
1099
1100 placesDock->toggleViewAction()->setText(i18nc("@title:window", "Places"));
1101 placesDock->toggleViewAction()->setShortcut(Qt::Key_F9);
1102 actionCollection()->addAction("show_places_panel", placesDock->toggleViewAction());
1103
1104 addDockWidget(Qt::LeftDockWidgetArea, placesDock);
1105 connect(placesView, SIGNAL(urlChanged(KUrl, Qt::MouseButtons)),
1106 this, SLOT(handlePlacesClick(KUrl, Qt::MouseButtons)));
1107 connect(this, SIGNAL(urlChanged(KUrl)),
1108 placesView, SLOT(setUrl(KUrl)));
1109 }
1110
1111 void DolphinMainWindow::updateEditActions()
1112 {
1113 const KFileItemList list = m_activeViewContainer->view()->selectedItems();
1114 if (list.isEmpty()) {
1115 stateChanged("has_no_selection");
1116 } else {
1117 stateChanged("has_selection");
1118
1119 KActionCollection* col = actionCollection();
1120 QAction* renameAction = col->action("rename");
1121 QAction* moveToTrashAction = col->action("move_to_trash");
1122 QAction* deleteAction = col->action("delete");
1123 QAction* cutAction = col->action(KStandardAction::name(KStandardAction::Cut));
1124 QAction* deleteWithTrashShortcut = col->action("delete_shortcut"); // see DolphinViewActionHandler
1125
1126 KonqFileItemCapabilities capabilities(list);
1127 const bool enableMoveToTrash = capabilities.isLocal() && capabilities.supportsMoving();
1128
1129 renameAction->setEnabled(capabilities.supportsMoving());
1130 moveToTrashAction->setEnabled(enableMoveToTrash);
1131 deleteAction->setEnabled(capabilities.supportsDeleting());
1132 deleteWithTrashShortcut->setEnabled(capabilities.supportsDeleting() && !enableMoveToTrash);
1133 cutAction->setEnabled(capabilities.supportsMoving());
1134 }
1135 updatePasteAction();
1136 }
1137
1138 void DolphinMainWindow::updateViewActions()
1139 {
1140 m_actionHandler->updateViewActions();
1141
1142 QAction* showFilterBarAction = actionCollection()->action("show_filter_bar");
1143 showFilterBarAction->setChecked(m_activeViewContainer->isFilterBarVisible());
1144
1145 updateSplitAction();
1146
1147 QAction* editableLocactionAction = actionCollection()->action("editable_location");
1148 const KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
1149 editableLocactionAction->setChecked(urlNavigator->isUrlEditable());
1150 }
1151
1152 void DolphinMainWindow::updateGoActions()
1153 {
1154 QAction* goUpAction = actionCollection()->action(KStandardAction::name(KStandardAction::Up));
1155 const KUrl& currentUrl = m_activeViewContainer->url();
1156 goUpAction->setEnabled(currentUrl.upUrl() != currentUrl);
1157 }
1158
1159 void DolphinMainWindow::clearStatusBar()
1160 {
1161 m_activeViewContainer->statusBar()->clear();
1162 }
1163
1164 void DolphinMainWindow::connectViewSignals(DolphinViewContainer* container)
1165 {
1166 connect(container, SIGNAL(showFilterBarChanged(bool)),
1167 this, SLOT(updateFilterBarAction(bool)));
1168
1169 DolphinView* view = container->view();
1170 connect(view, SIGNAL(selectionChanged(KFileItemList)),
1171 this, SLOT(slotSelectionChanged(KFileItemList)));
1172 connect(view, SIGNAL(requestItemInfo(KFileItem)),
1173 this, SLOT(slotRequestItemInfo(KFileItem)));
1174 connect(view, SIGNAL(activated()),
1175 this, SLOT(toggleActiveView()));
1176 connect(view, SIGNAL(doingOperation(KIO::FileUndoManager::CommandType)),
1177 this, SLOT(slotDoingOperation(KIO::FileUndoManager::CommandType)));
1178 connect(view, SIGNAL(tabRequested(const KUrl&)),
1179 this, SLOT(openNewTab(const KUrl&)));
1180
1181 const KUrlNavigator* navigator = container->urlNavigator();
1182 connect(navigator, SIGNAL(urlChanged(const KUrl&)),
1183 this, SLOT(changeUrl(const KUrl&)));
1184 connect(navigator, SIGNAL(historyChanged()),
1185 this, SLOT(updateHistory()));
1186 connect(navigator, SIGNAL(editableStateChanged(bool)),
1187 this, SLOT(slotEditableStateChanged(bool)));
1188 }
1189
1190 void DolphinMainWindow::updateSplitAction()
1191 {
1192 QAction* splitAction = actionCollection()->action("split_view");
1193 if (m_viewTab[m_tabIndex].secondaryView != 0) {
1194 if (m_activeViewContainer == m_viewTab[m_tabIndex].secondaryView) {
1195 splitAction->setText(i18nc("@action:intoolbar Close right view", "Close"));
1196 splitAction->setIcon(KIcon("view-right-close"));
1197 } else {
1198 splitAction->setText(i18nc("@action:intoolbar Close left view", "Close"));
1199 splitAction->setIcon(KIcon("view-left-close"));
1200 }
1201 } else {
1202 splitAction->setText(i18nc("@action:intoolbar Split view", "Split"));
1203 splitAction->setIcon(KIcon("view-right-new"));
1204 }
1205 }
1206
1207 QString DolphinMainWindow::tabName(const KUrl& url) const
1208 {
1209 QString name;
1210 if (url.equals(KUrl("file:///"))) {
1211 name = "/";
1212 } else {
1213 name = url.fileName();
1214 if (name.isEmpty()) {
1215 name = url.protocol();
1216 }
1217 }
1218 return name;
1219 }
1220
1221 bool DolphinMainWindow::isKompareInstalled() const
1222 {
1223 static bool initialized = false;
1224 static bool installed = false;
1225 if (!initialized) {
1226 // TODO: maybe replace this approach later by using a menu
1227 // plugin like kdiff3plugin.cpp
1228 installed = !KGlobal::dirs()->findExe("kompare").isEmpty();
1229 initialized = true;
1230 }
1231 return installed;
1232 }
1233
1234 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
1235 KIO::FileUndoManager::UiInterface()
1236 {
1237 }
1238
1239 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
1240 {
1241 }
1242
1243 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job* job)
1244 {
1245 DolphinMainWindow* mainWin= qobject_cast<DolphinMainWindow *>(parentWidget());
1246 if (mainWin) {
1247 DolphinStatusBar* statusBar = mainWin->activeViewContainer()->statusBar();
1248 statusBar->setMessage(job->errorString(), DolphinStatusBar::Error);
1249 } else {
1250 KIO::FileUndoManager::UiInterface::jobError(job);
1251 }
1252 }
1253
1254 #include "dolphinmainwindow.moc"