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