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