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