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