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