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