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