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