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