]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.cpp
Revert 818910 and do it properly (patch by dfaure).
[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 <kurlnavigator.h>
65 #include <konq_fileitemcapabilities.h>
66 #include <konqmimedata.h>
67 #include <kpropertiesdialog.h>
68 #include <kprotocolinfo.h>
69 #include <ktoggleaction.h>
70 #include <krun.h>
71 #include <kshell.h>
72 #include <kstandarddirs.h>
73 #include <kstatusbar.h>
74 #include <kstandardaction.h>
75 #include <ktabbar.h>
76 #include <kurl.h>
77 #include <kurlcombobox.h>
78
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()->selectedUrls().count();
206 if (m_viewTab[m_tabIndex].secondaryView != 0) {
207 selectedUrlsCount += m_viewTab[m_tabIndex].secondaryView->view()->selectedUrls().count();
208 }
209
210 QAction* compareFilesAction = actionCollection()->action("compare_files");
211 if (selectedUrlsCount == 2) {
212 const bool kompareInstalled = !KGlobal::dirs()->findExe("kompare").isEmpty();
213 compareFilesAction->setEnabled(selectedUrlsCount == 2 && kompareInstalled);
214 } else {
215 compareFilesAction->setEnabled(false);
216 }
217
218 m_activeViewContainer->updateStatusBar();
219
220 emit selectionChanged(selection);
221 }
222
223 void DolphinMainWindow::slotRequestItemInfo(const KFileItem& item)
224 {
225 emit requestItemInfo(item);
226 }
227
228 void DolphinMainWindow::updateHistory()
229 {
230 const KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
231 const int index = urlNavigator->historyIndex();
232
233 QAction* backAction = actionCollection()->action("go_back");
234 if (backAction != 0) {
235 backAction->setEnabled(index < urlNavigator->historySize() - 1);
236 }
237
238 QAction* forwardAction = actionCollection()->action("go_forward");
239 if (forwardAction != 0) {
240 forwardAction->setEnabled(index > 0);
241 }
242 }
243
244 void DolphinMainWindow::updateFilterBarAction(bool show)
245 {
246 QAction* showFilterBarAction = actionCollection()->action("show_filter_bar");
247 showFilterBarAction->setChecked(show);
248 }
249
250 void DolphinMainWindow::openNewMainWindow()
251 {
252 DolphinApplication::app()->createMainWindow()->show();
253 }
254
255 void DolphinMainWindow::openNewTab()
256 {
257 openNewTab(m_activeViewContainer->url());
258 m_tabBar->setCurrentIndex(m_viewTab.count() - 1);
259 }
260
261 void DolphinMainWindow::openNewTab(const KUrl& url)
262 {
263 if (m_viewTab.count() == 1) {
264 // Only one view is open currently and hence no tab is shown at
265 // all. Before creating a tab for 'url', provide a tab for the current URL.
266 m_tabBar->addTab(KIcon("folder"), tabName(m_activeViewContainer->url()));
267 m_tabBar->blockSignals(false);
268 }
269
270 m_tabBar->addTab(KIcon("folder"), tabName(url));
271
272 ViewTab viewTab;
273 viewTab.splitter = new QSplitter(this);
274 viewTab.primaryView = new DolphinViewContainer(this, viewTab.splitter, url);
275 connectViewSignals(viewTab.primaryView);
276 viewTab.primaryView->view()->reload();
277
278 m_viewTab.append(viewTab);
279 }
280
281 void DolphinMainWindow::toggleActiveView()
282 {
283 if (m_viewTab[m_tabIndex].secondaryView == 0) {
284 // only one view is available
285 return;
286 }
287
288 Q_ASSERT(m_activeViewContainer != 0);
289 Q_ASSERT(m_viewTab[m_tabIndex].primaryView != 0);
290
291 DolphinViewContainer* left = m_viewTab[m_tabIndex].primaryView;
292 DolphinViewContainer* right = m_viewTab[m_tabIndex].secondaryView;
293 setActiveViewContainer(m_activeViewContainer == right ? left : right);
294 }
295
296 void DolphinMainWindow::closeEvent(QCloseEvent* event)
297 {
298 DolphinSettings& settings = DolphinSettings::instance();
299 GeneralSettings* generalSettings = settings.generalSettings();
300 generalSettings->setFirstRun(false);
301
302 settings.save();
303
304 KXmlGuiWindow::closeEvent(event);
305 }
306
307 void DolphinMainWindow::saveProperties(KConfigGroup& group)
308 {
309 // TODO: remember tabs
310 DolphinViewContainer* cont = m_viewTab[m_tabIndex].primaryView;
311 group.writeEntry("Primary Url", cont->url().url());
312 group.writeEntry("Primary Editable Url", cont->isUrlEditable());
313
314 cont = m_viewTab[m_tabIndex].secondaryView;
315 if (cont != 0) {
316 group.writeEntry("Secondary Url", cont->url().url());
317 group.writeEntry("Secondary Editable Url", cont->isUrlEditable());
318 }
319 }
320
321 void DolphinMainWindow::readProperties(const KConfigGroup& group)
322 {
323 // TODO: read tabs
324 DolphinViewContainer* cont = m_viewTab[m_tabIndex].primaryView;
325
326 cont->setUrl(group.readEntry("Primary Url"));
327 bool editable = group.readEntry("Primary Editable Url", false);
328 cont->urlNavigator()->setUrlEditable(editable);
329
330 cont = m_viewTab[m_tabIndex].secondaryView;
331 const QString secondaryUrl = group.readEntry("Secondary Url");
332 if (!secondaryUrl.isEmpty()) {
333 if (cont == 0) {
334 // a secondary view should be shown, but no one is available
335 // currently -> create a new view
336 toggleSplitView();
337 cont = m_viewTab[m_tabIndex].secondaryView;
338 Q_ASSERT(cont != 0);
339 }
340
341 cont->setUrl(secondaryUrl);
342 bool editable = group.readEntry("Secondary Editable Url", false);
343 cont->urlNavigator()->setUrlEditable(editable);
344 } else if (cont != 0) {
345 // no secondary view should be shown, but the default setting shows
346 // one already -> close the view
347 toggleSplitView();
348 }
349 }
350
351 void DolphinMainWindow::updateNewMenu()
352 {
353 m_newMenu->slotCheckUpToDate();
354 m_newMenu->setPopupFiles(activeViewContainer()->url());
355 }
356
357 void DolphinMainWindow::properties()
358 {
359 const KFileItemList list = m_activeViewContainer->view()->selectedItems();
360
361 KPropertiesDialog *dialog = new KPropertiesDialog(list, this);
362 dialog->setAttribute(Qt::WA_DeleteOnClose);
363 dialog->show();
364 dialog->raise();
365 dialog->activateWindow();
366 }
367
368 void DolphinMainWindow::quit()
369 {
370 close();
371 }
372
373 void DolphinMainWindow::slotHandlePlacesError(const QString &message)
374 {
375 if (!message.isEmpty()) {
376 DolphinStatusBar* statusBar = m_activeViewContainer->statusBar();
377 statusBar->setMessage(message, DolphinStatusBar::Error);
378 }
379 }
380
381 void DolphinMainWindow::slotUndoAvailable(bool available)
382 {
383 QAction* undoAction = actionCollection()->action(KStandardAction::name(KStandardAction::Undo));
384 if (undoAction != 0) {
385 undoAction->setEnabled(available);
386 }
387
388 if (available && (m_undoCommandTypes.count() > 0)) {
389 const KIO::FileUndoManager::CommandType command = m_undoCommandTypes.takeFirst();
390 DolphinStatusBar* statusBar = m_activeViewContainer->statusBar();
391 switch (command) {
392 case KIO::FileUndoManager::Copy:
393 statusBar->setMessage(i18nc("@info:status", "Copy operation completed."),
394 DolphinStatusBar::OperationCompleted);
395 break;
396 case KIO::FileUndoManager::Move:
397 statusBar->setMessage(i18nc("@info:status", "Move operation completed."),
398 DolphinStatusBar::OperationCompleted);
399 break;
400 case KIO::FileUndoManager::Link:
401 statusBar->setMessage(i18nc("@info:status", "Link operation completed."),
402 DolphinStatusBar::OperationCompleted);
403 break;
404 case KIO::FileUndoManager::Trash:
405 statusBar->setMessage(i18nc("@info:status", "Move to trash operation completed."),
406 DolphinStatusBar::OperationCompleted);
407 break;
408 case KIO::FileUndoManager::Rename:
409 statusBar->setMessage(i18nc("@info:status", "Renaming operation completed."),
410 DolphinStatusBar::OperationCompleted);
411 break;
412
413 case KIO::FileUndoManager::Mkdir:
414 statusBar->setMessage(i18nc("@info:status", "Created folder."),
415 DolphinStatusBar::OperationCompleted);
416 break;
417
418 default:
419 break;
420 }
421
422 }
423 }
424
425 void DolphinMainWindow::slotUndoTextChanged(const QString& text)
426 {
427 QAction* undoAction = actionCollection()->action(KStandardAction::name(KStandardAction::Undo));
428 if (undoAction != 0) {
429 undoAction->setText(text);
430 }
431 }
432
433 void DolphinMainWindow::undo()
434 {
435 clearStatusBar();
436 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
437 KIO::FileUndoManager::self()->undo();
438 }
439
440 void DolphinMainWindow::cut()
441 {
442 m_activeViewContainer->view()->cutSelectedItems();
443 }
444
445 void DolphinMainWindow::copy()
446 {
447 m_activeViewContainer->view()->copySelectedItems();
448 }
449
450 void DolphinMainWindow::paste()
451 {
452 m_activeViewContainer->view()->paste();
453 }
454
455 void DolphinMainWindow::updatePasteAction()
456 {
457 QAction* pasteAction = actionCollection()->action(KStandardAction::name(KStandardAction::Paste));
458 QPair<bool, QString> pasteInfo = m_activeViewContainer->view()->pasteInfo();
459 pasteAction->setEnabled(pasteInfo.first);
460 pasteAction->setText(pasteInfo.second);
461
462 if (pasteAction->isEnabled()) {
463 // disable the paste action if no writing is supported
464 const KUrl& url = m_activeViewContainer->view()->url();
465 KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url);
466 KFileItemList list;
467 list.append(item);
468 KonqFileItemCapabilities capabilities(list);
469 pasteAction->setEnabled(capabilities.supportsWriting());
470 }
471 }
472
473 void DolphinMainWindow::selectAll()
474 {
475 clearStatusBar();
476
477 // if the URL navigator is editable and focused, select the whole
478 // URL instead of all items of the view
479
480 KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
481 QLineEdit* lineEdit = urlNavigator->editor()->lineEdit();
482 const bool selectUrl = urlNavigator->isUrlEditable() &&
483 lineEdit->hasFocus();
484 if (selectUrl) {
485 lineEdit->selectAll();
486 } else {
487 m_activeViewContainer->view()->selectAll();
488 }
489 }
490
491 void DolphinMainWindow::invertSelection()
492 {
493 clearStatusBar();
494 m_activeViewContainer->view()->invertSelection();
495 }
496
497 void DolphinMainWindow::toggleSplitView()
498 {
499 if (m_viewTab[m_tabIndex].secondaryView == 0) {
500 // create a secondary view
501 QSplitter* splitter = m_viewTab[m_tabIndex].splitter;
502 const int newWidth = (m_viewTab[m_tabIndex].primaryView->width() - splitter->handleWidth()) / 2;
503
504 const DolphinView* view = m_viewTab[m_tabIndex].primaryView->view();
505 m_viewTab[m_tabIndex].secondaryView = new DolphinViewContainer(this, 0, view->rootUrl());
506 connectViewSignals(m_viewTab[m_tabIndex].secondaryView);
507 splitter->addWidget(m_viewTab[m_tabIndex].secondaryView);
508 splitter->setSizes(QList<int>() << newWidth << newWidth);
509 m_viewTab[m_tabIndex].secondaryView->view()->reload();
510 m_viewTab[m_tabIndex].secondaryView->setActive(false);
511 m_viewTab[m_tabIndex].secondaryView->show();
512
513 setActiveViewContainer(m_viewTab[m_tabIndex].secondaryView);
514 } else if (m_activeViewContainer == m_viewTab[m_tabIndex].primaryView) {
515 // remove secondary view
516 m_viewTab[m_tabIndex].secondaryView->close();
517 m_viewTab[m_tabIndex].secondaryView->deleteLater();
518 m_viewTab[m_tabIndex].secondaryView = 0;
519
520 setActiveViewContainer(m_viewTab[m_tabIndex].primaryView);
521 } else {
522 // The secondary view is active, hence from a users point of view
523 // the content of the secondary view should be moved to the primary view.
524 // From an implementation point of view it is more efficient to close
525 // the primary view and exchange the internal pointers afterwards.
526
527 m_viewTab[m_tabIndex].primaryView->close();
528 m_viewTab[m_tabIndex].primaryView->deleteLater();
529 m_viewTab[m_tabIndex].primaryView = m_viewTab[m_tabIndex].secondaryView;
530 m_viewTab[m_tabIndex].secondaryView = 0;
531
532 setActiveViewContainer(m_viewTab[m_tabIndex].primaryView);
533 }
534
535 updateViewActions();
536 }
537
538 void DolphinMainWindow::reloadView()
539 {
540 clearStatusBar();
541 m_activeViewContainer->view()->reload();
542 }
543
544 void DolphinMainWindow::stopLoading()
545 {
546 }
547
548 void DolphinMainWindow::toggleFilterBarVisibility(bool show)
549 {
550 m_activeViewContainer->showFilterBar(show);
551 }
552
553 void DolphinMainWindow::toggleEditLocation()
554 {
555 clearStatusBar();
556
557 QAction* action = actionCollection()->action("editable_location");
558 KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
559 urlNavigator->setUrlEditable(action->isChecked());
560 }
561
562 void DolphinMainWindow::editLocation()
563 {
564 KUrlNavigator* navigator = m_activeViewContainer->urlNavigator();
565 navigator->setUrlEditable(true);
566 navigator->setFocus();
567
568 // select the whole text of the combo box editor
569 QLineEdit* lineEdit = navigator->editor()->lineEdit();
570 const QString text = lineEdit->text();
571 lineEdit->setSelection(0, text.length());
572 }
573
574 void DolphinMainWindow::goBack()
575 {
576 clearStatusBar();
577 m_activeViewContainer->urlNavigator()->goBack();
578 }
579
580 void DolphinMainWindow::goForward()
581 {
582 clearStatusBar();
583 m_activeViewContainer->urlNavigator()->goForward();
584 }
585
586 void DolphinMainWindow::goUp()
587 {
588 clearStatusBar();
589 m_activeViewContainer->urlNavigator()->goUp();
590 }
591
592 void DolphinMainWindow::goHome()
593 {
594 clearStatusBar();
595 m_activeViewContainer->urlNavigator()->goHome();
596 }
597
598 void DolphinMainWindow::findFile()
599 {
600 KRun::run("kfind", m_activeViewContainer->url(), this);
601 }
602
603 void DolphinMainWindow::compareFiles()
604 {
605 // The method is only invoked if exactly 2 files have
606 // been selected. The selected files may be:
607 // - both in the primary view
608 // - both in the secondary view
609 // - one in the primary view and the other in the secondary
610 // view
611 Q_ASSERT(m_viewTab[m_tabIndex].primaryView != 0);
612
613 KUrl urlA;
614 KUrl urlB;
615 KUrl::List urls = m_viewTab[m_tabIndex].primaryView->view()->selectedUrls();
616
617 switch (urls.count()) {
618 case 0: {
619 Q_ASSERT(m_viewTab[m_tabIndex].secondaryView != 0);
620 urls = m_viewTab[m_tabIndex].secondaryView->view()->selectedUrls();
621 Q_ASSERT(urls.count() == 2);
622 urlA = urls[0];
623 urlB = urls[1];
624 break;
625 }
626
627 case 1: {
628 urlA = urls[0];
629 Q_ASSERT(m_viewTab[m_tabIndex].secondaryView != 0);
630 urls = m_viewTab[m_tabIndex].secondaryView->view()->selectedUrls();
631 Q_ASSERT(urls.count() == 1);
632 urlB = urls[0];
633 break;
634 }
635
636 case 2: {
637 urlA = urls[0];
638 urlB = urls[1];
639 break;
640 }
641
642 default: {
643 // may not happen: compareFiles may only get invoked if 2
644 // files are selected
645 Q_ASSERT(false);
646 }
647 }
648
649 QString command("kompare -c \"");
650 command.append(urlA.pathOrUrl());
651 command.append("\" \"");
652 command.append(urlB.pathOrUrl());
653 command.append('\"');
654 KRun::runCommand(command, "Kompare", "kompare", this);
655 }
656
657 void DolphinMainWindow::toggleShowMenuBar()
658 {
659 const bool visible = menuBar()->isVisible();
660 menuBar()->setVisible(!visible);
661 }
662
663 void DolphinMainWindow::editSettings()
664 {
665 DolphinSettingsDialog dialog(this);
666 dialog.exec();
667 }
668
669 void DolphinMainWindow::setActiveTab(int index)
670 {
671 Q_ASSERT(index >= 0);
672 Q_ASSERT(index < m_viewTab.count());
673 if (index == m_tabIndex) {
674 return;
675 }
676
677 // hide current tab content
678 m_viewTab[m_tabIndex].isPrimaryViewActive = m_viewTab[m_tabIndex].primaryView->isActive();
679 QSplitter* splitter = m_viewTab[m_tabIndex].splitter;
680 splitter->hide();
681 m_centralWidgetLayout->removeWidget(splitter);
682
683 // show active tab content
684 m_tabIndex = index;
685
686 ViewTab& viewTab = m_viewTab[index];
687 m_centralWidgetLayout->addWidget(viewTab.splitter);
688 viewTab.primaryView->show();
689 if (viewTab.secondaryView != 0) {
690 viewTab.secondaryView->show();
691 }
692 viewTab.splitter->show();
693
694 setActiveViewContainer(viewTab.isPrimaryViewActive ? viewTab.primaryView :
695 viewTab.secondaryView);
696 }
697
698 void DolphinMainWindow::closeTab()
699 {
700 closeTab(m_tabBar->currentIndex());
701 }
702
703 void DolphinMainWindow::closeTab(int index)
704 {
705 Q_ASSERT(index >= 0);
706 Q_ASSERT(index < m_viewTab.count());
707 if (m_viewTab.count() == 1) {
708 // the last tab may never get closed
709 return;
710 }
711
712 if (index == m_tabIndex) {
713 // The tab that should be closed is the active tab. Activate the
714 // previous tab before closing the tab.
715 setActiveTab((index > 0) ? index - 1 : 1);
716 }
717
718 // delete tab
719 m_viewTab[index].primaryView->deleteLater();
720 if (m_viewTab[index].secondaryView != 0) {
721 m_viewTab[index].secondaryView->deleteLater();
722 }
723 m_viewTab[index].splitter->deleteLater();
724 m_viewTab.erase(m_viewTab.begin() + index);
725
726 m_tabBar->blockSignals(true);
727 m_tabBar->removeTab(index);
728
729 if (m_tabIndex > index) {
730 m_tabIndex--;
731 Q_ASSERT(m_tabIndex >= 0);
732 }
733
734 // if only one tab is left, also remove the tab entry so that
735 // closing the last tab is not possible
736 if (m_viewTab.count() == 1) {
737 m_tabBar->removeTab(0);
738 } else {
739 m_tabBar->blockSignals(false);
740 }
741 }
742
743 void DolphinMainWindow::openTabContextMenu(int index, const QPoint& pos)
744 {
745 KMenu menu(this);
746
747 QAction* newTabAction = menu.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab"));
748 newTabAction->setShortcut(actionCollection()->action("new_tab")->shortcut());
749
750 QAction* closeOtherTabsAction = menu.addAction(KIcon("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs"));
751
752 QAction* closeTabAction = menu.addAction(KIcon("tab-close"), i18nc("@action:inmenu", "Close Tab"));
753 closeTabAction->setShortcut(actionCollection()->action("close_tab")->shortcut());
754
755 QAction* selectedAction = menu.exec(pos);
756 if (selectedAction == newTabAction) {
757 const ViewTab& tab = m_viewTab[index];
758 Q_ASSERT(tab.primaryView != 0);
759 const KUrl url = (tab.secondaryView != 0) && tab.secondaryView->isActive() ?
760 tab.secondaryView->url() : tab.primaryView->url();
761 openNewTab(url);
762 m_tabBar->setCurrentIndex(m_viewTab.count() - 1);
763 } else if (selectedAction == closeOtherTabsAction) {
764 const int count = m_tabBar->count();
765 for (int i = 0; i < index; ++i) {
766 closeTab(0);
767 }
768 for (int i = index + 1; i < count; ++i) {
769 closeTab(1);
770 }
771 } else if (selectedAction == closeTabAction) {
772 closeTab(index);
773 }
774 }
775
776 void DolphinMainWindow::handlePlacesClick(const KUrl& url, Qt::MouseButtons buttons)
777 {
778 if (buttons & Qt::MidButton) {
779 openNewTab(url);
780 m_tabBar->setCurrentIndex(m_viewTab.count() - 1);
781 } else {
782 changeUrl(url);
783 }
784 }
785
786 void DolphinMainWindow::init()
787 {
788 DolphinSettings& settings = DolphinSettings::instance();
789
790 // Check whether Dolphin runs the first time. If yes then
791 // a proper default window size is given at the end of DolphinMainWindow::init().
792 GeneralSettings* generalSettings = settings.generalSettings();
793 const bool firstRun = generalSettings->firstRun();
794 if (firstRun) {
795 generalSettings->setViewPropsTimestamp(QDateTime::currentDateTime());
796 }
797
798 setAcceptDrops(true);
799
800 m_viewTab[m_tabIndex].splitter = new QSplitter(this);
801
802 setupActions();
803
804 const KUrl& homeUrl = generalSettings->homeUrl();
805 setCaption(homeUrl.fileName());
806 m_actionHandler = new DolphinViewActionHandler(actionCollection(), this);
807 connect(m_actionHandler, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
808 ViewProperties props(homeUrl);
809 m_viewTab[m_tabIndex].primaryView = new DolphinViewContainer(this,
810 m_viewTab[m_tabIndex].splitter,
811 homeUrl);
812
813 m_activeViewContainer = m_viewTab[m_tabIndex].primaryView;
814 connectViewSignals(m_activeViewContainer);
815 DolphinView* view = m_activeViewContainer->view();
816 view->reload();
817 m_activeViewContainer->show();
818 m_actionHandler->setCurrentView(view);
819
820 m_tabBar = new KTabBar(this);
821 m_tabBar->setCloseButtonEnabled(true);
822 connect(m_tabBar, SIGNAL(currentChanged(int)),
823 this, SLOT(setActiveTab(int)));
824 connect(m_tabBar, SIGNAL(closeRequest(int)),
825 this, SLOT(closeTab(int)));
826 connect(m_tabBar, SIGNAL(contextMenu(int, const QPoint&)),
827 this, SLOT(openTabContextMenu(int, const QPoint&)));
828 connect(m_tabBar, SIGNAL(newTabRequest()),
829 this, SLOT(openNewTab()));
830 m_tabBar->blockSignals(true); // signals get unblocked after at least 2 tabs are open
831
832 QWidget* centralWidget = new QWidget(this);
833 m_centralWidgetLayout = new QVBoxLayout(centralWidget);
834 m_centralWidgetLayout->setSpacing(0);
835 m_centralWidgetLayout->setMargin(0);
836 m_centralWidgetLayout->addWidget(m_tabBar);
837 m_centralWidgetLayout->addWidget(m_viewTab[m_tabIndex].splitter);
838
839
840 setCentralWidget(centralWidget);
841 setupDockWidgets();
842
843 setupGUI(Keys | Save | Create | ToolBar);
844 createGUI();
845
846 stateChanged("new_file");
847 setAutoSaveSettings();
848
849 QClipboard* clipboard = QApplication::clipboard();
850 connect(clipboard, SIGNAL(dataChanged()),
851 this, SLOT(updatePasteAction()));
852 updatePasteAction();
853 updateGoActions();
854
855 if (generalSettings->splitView()) {
856 toggleSplitView();
857 }
858 updateViewActions();
859
860 if (firstRun) {
861 // assure a proper default size if Dolphin runs the first time
862 resize(750, 500);
863 }
864
865 emit urlChanged(homeUrl);
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(Qt::CTRL | Qt::SHIFT | Qt::Key_N);
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 connect(closeTab, SIGNAL(triggered()), this, SLOT(closeTab()));
928 actionCollection()->addAction("close_tab", closeTab);
929
930 KAction* properties = actionCollection()->addAction("properties");
931 properties->setText(i18nc("@action:inmenu File", "Properties"));
932 properties->setShortcut(Qt::ALT | Qt::Key_Return);
933 connect(properties, SIGNAL(triggered()), this, SLOT(properties()));
934
935 KStandardAction::quit(this, SLOT(quit()), actionCollection());
936
937 // setup 'Edit' menu
938 KStandardAction::undo(this,
939 SLOT(undo()),
940 actionCollection());
941
942 // need to remove shift+del from cut action, else the shortcut for deletejob
943 // doesn't work
944 KAction* cut = KStandardAction::cut(this, SLOT(cut()), actionCollection());
945 KShortcut cutShortcut = cut->shortcut();
946 cutShortcut.remove(Qt::SHIFT + Qt::Key_Delete, KShortcut::KeepEmpty);
947 cut->setShortcut(cutShortcut);
948 KStandardAction::copy(this, SLOT(copy()), actionCollection());
949 KStandardAction::paste(this, SLOT(paste()), actionCollection());
950
951 KAction* selectAll = actionCollection()->addAction("select_all");
952 selectAll->setText(i18nc("@action:inmenu Edit", "Select All"));
953 selectAll->setShortcut(Qt::CTRL + Qt::Key_A);
954 connect(selectAll, SIGNAL(triggered()), this, SLOT(selectAll()));
955
956 KAction* invertSelection = actionCollection()->addAction("invert_selection");
957 invertSelection->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
958 invertSelection->setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_A);
959 connect(invertSelection, SIGNAL(triggered()), this, SLOT(invertSelection()));
960
961 // setup 'View' menu
962 // (note that most of it is set up in DolphinViewActionHandler)
963
964 KAction* split = actionCollection()->addAction("split_view");
965 split->setShortcut(Qt::Key_F3);
966 updateSplitAction();
967 connect(split, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
968
969 KAction* reload = actionCollection()->addAction("reload");
970 reload->setText(i18nc("@action:inmenu View", "Reload"));
971 reload->setShortcut(Qt::Key_F5);
972 reload->setIcon(KIcon("view-refresh"));
973 connect(reload, SIGNAL(triggered()), this, SLOT(reloadView()));
974
975 KAction* stop = actionCollection()->addAction("stop");
976 stop->setText(i18nc("@action:inmenu View", "Stop"));
977 stop->setIcon(KIcon("process-stop"));
978 connect(stop, SIGNAL(triggered()), this, SLOT(stopLoading()));
979
980 // TODO: the naming "Show full Location" is currently confusing...
981 KToggleAction* showFullLocation = actionCollection()->add<KToggleAction>("editable_location");
982 showFullLocation->setText(i18nc("@action:inmenu Navigation Bar", "Show Full Location"));
983 showFullLocation->setShortcut(Qt::CTRL | Qt::Key_L);
984 connect(showFullLocation, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
985
986 KAction* editLocation = actionCollection()->addAction("edit_location");
987 editLocation->setText(i18nc("@action:inmenu Navigation Bar", "Edit Location"));
988 editLocation->setShortcut(Qt::Key_F6);
989 connect(editLocation, SIGNAL(triggered()), this, SLOT(editLocation()));
990
991 // setup 'Go' menu
992 KAction* backAction = KStandardAction::back(this, SLOT(goBack()), actionCollection());
993 KShortcut backShortcut = backAction->shortcut();
994 backShortcut.setAlternate(Qt::Key_Backspace);
995 backAction->setShortcut(backShortcut);
996
997 KStandardAction::forward(this, SLOT(goForward()), actionCollection());
998 KStandardAction::up(this, SLOT(goUp()), actionCollection());
999 KStandardAction::home(this, SLOT(goHome()), actionCollection());
1000
1001 // setup 'Tools' menu
1002 QAction* findFile = actionCollection()->addAction("find_file");
1003 findFile->setText(i18nc("@action:inmenu Tools", "Find File..."));
1004 findFile->setShortcut(Qt::CTRL | Qt::Key_F);
1005 findFile->setIcon(KIcon("edit-find"));
1006 connect(findFile, SIGNAL(triggered()), this, SLOT(findFile()));
1007
1008 KToggleAction* showFilterBar = actionCollection()->add<KToggleAction>("show_filter_bar");
1009 showFilterBar->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1010 showFilterBar->setShortcut(Qt::CTRL | Qt::Key_I);
1011 connect(showFilterBar, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
1012
1013 KAction* compareFiles = actionCollection()->addAction("compare_files");
1014 compareFiles->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1015 compareFiles->setIcon(KIcon("kompare"));
1016 compareFiles->setEnabled(false);
1017 connect(compareFiles, SIGNAL(triggered()), this, SLOT(compareFiles()));
1018
1019 // setup 'Settings' menu
1020 m_showMenuBar = KStandardAction::showMenubar(this, SLOT(toggleShowMenuBar()), actionCollection());
1021 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1022 }
1023
1024 void DolphinMainWindow::setupDockWidgets()
1025 {
1026 // setup "Information"
1027 QDockWidget* infoDock = new QDockWidget(i18nc("@title:window", "Information"));
1028 infoDock->setObjectName("infoDock");
1029 infoDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1030 SidebarPage* infoWidget = new InfoSidebarPage(infoDock);
1031 infoDock->setWidget(infoWidget);
1032
1033 infoDock->toggleViewAction()->setText(i18nc("@title:window", "Information"));
1034 infoDock->toggleViewAction()->setShortcut(Qt::Key_F11);
1035 actionCollection()->addAction("show_info_panel", infoDock->toggleViewAction());
1036
1037 addDockWidget(Qt::RightDockWidgetArea, infoDock);
1038 connect(this, SIGNAL(urlChanged(KUrl)),
1039 infoWidget, SLOT(setUrl(KUrl)));
1040 connect(this, SIGNAL(selectionChanged(KFileItemList)),
1041 infoWidget, SLOT(setSelection(KFileItemList)));
1042 connect(this, SIGNAL(requestItemInfo(KFileItem)),
1043 infoWidget, SLOT(requestDelayedItemInfo(KFileItem)));
1044
1045 // setup "Tree View"
1046 QDockWidget* treeViewDock = new QDockWidget(i18nc("@title:window", "Folders"));
1047 treeViewDock->setObjectName("treeViewDock");
1048 treeViewDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1049 TreeViewSidebarPage* treeWidget = new TreeViewSidebarPage(treeViewDock);
1050 treeViewDock->setWidget(treeWidget);
1051
1052 treeViewDock->toggleViewAction()->setText(i18nc("@title:window", "Folders"));
1053 treeViewDock->toggleViewAction()->setShortcut(Qt::Key_F7);
1054 actionCollection()->addAction("show_folders_panel", treeViewDock->toggleViewAction());
1055
1056 addDockWidget(Qt::LeftDockWidgetArea, treeViewDock);
1057 connect(this, SIGNAL(urlChanged(KUrl)),
1058 treeWidget, SLOT(setUrl(KUrl)));
1059 connect(treeWidget, SIGNAL(changeUrl(KUrl, Qt::MouseButtons)),
1060 this, SLOT(handlePlacesClick(KUrl, Qt::MouseButtons)));
1061 connect(treeWidget, SIGNAL(changeSelection(KFileItemList)),
1062 this, SLOT(changeSelection(KFileItemList)));
1063 connect(treeWidget, SIGNAL(urlsDropped(KUrl::List, KUrl)),
1064 this, SLOT(dropUrls(KUrl::List, KUrl)));
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].primaryView) {
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 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
1224 KIO::FileUndoManager::UiInterface()
1225 {
1226 }
1227
1228 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
1229 {
1230 }
1231
1232 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job* job)
1233 {
1234 DolphinMainWindow* mainWin= qobject_cast<DolphinMainWindow *>(parentWidget());
1235 if (mainWin) {
1236 DolphinStatusBar* statusBar = mainWin->activeViewContainer()->statusBar();
1237 statusBar->setMessage(job->errorString(), DolphinStatusBar::Error);
1238 } else {
1239 KIO::FileUndoManager::UiInterface::jobError(job);
1240 }
1241 }
1242
1243 #include "dolphinmainwindow.moc"