LCOV - code coverage report
Current view: top level - svtools/source/uno - fpicker.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 31 69 44.9 %
Date: 2014-11-03 Functions: 7 10 70.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <sal/types.h>
      21             : #include <rtl/ustring.hxx>
      22             : 
      23             : #include <com/sun/star/lang/XMultiComponentFactory.hpp>
      24             : 
      25             : #include <svtools/miscopt.hxx>
      26             : #include <svl/pickerhistoryaccess.hxx>
      27             : 
      28             : #include <vcl/svapp.hxx>
      29             : 
      30             : #include "fpicker.hxx"
      31             : 
      32             : using css::uno::Reference;
      33             : using css::uno::Sequence;
      34             : 
      35             : /*
      36             :  * FilePicker implementation.
      37             :  */
      38           0 : static OUString FilePicker_getSystemPickerServiceName()
      39             : {
      40             : #ifdef UNX
      41           0 :     OUString aDesktopEnvironment (Application::GetDesktopEnvironment());
      42           0 :     if (aDesktopEnvironment.equalsIgnoreAsciiCase("tde"))
      43           0 :         return OUString ("com.sun.star.ui.dialogs.TDEFilePicker");
      44           0 :     else if (aDesktopEnvironment.equalsIgnoreAsciiCase("kde"))
      45           0 :         return OUString ("com.sun.star.ui.dialogs.KDEFilePicker");
      46           0 :     else if (aDesktopEnvironment.equalsIgnoreAsciiCase("kde4"))
      47           0 :         return OUString ("com.sun.star.ui.dialogs.KDE4FilePicker");
      48           0 :     else if (aDesktopEnvironment.equalsIgnoreAsciiCase("macosx"))
      49           0 :         return OUString ("com.sun.star.ui.dialogs.AquaFilePicker");
      50             :     else
      51           0 :         return OUString ("com.sun.star.ui.dialogs.SystemFilePicker");
      52             : #endif
      53             : #ifdef WNT
      54             :     return OUString ("com.sun.star.ui.dialogs.Win32FilePicker");
      55             : #endif
      56             : }
      57             : 
      58           0 : Reference< css::uno::XInterface > FilePicker_CreateInstance (
      59             :     Reference< css::uno::XComponentContext > const & context)
      60             : {
      61           0 :     Reference< css::uno::XInterface > xResult;
      62             : 
      63           0 :     if (!context.is())
      64           0 :         return xResult;
      65             : 
      66           0 :     Reference< css::lang::XMultiComponentFactory > xFactory (context->getServiceManager());
      67           0 :     if (xFactory.is() && SvtMiscOptions().UseSystemFileDialog())
      68             :     {
      69           0 :         xResult = Reference< css::uno::XInterface >( Application::createFilePicker( context ) );
      70             : 
      71           0 :         if (!xResult.is())
      72             :         {
      73             :             try
      74             :             {
      75           0 :                 xResult = xFactory->createInstanceWithContext (
      76             :                         FilePicker_getSystemPickerServiceName(),
      77           0 :                         context);
      78             :             }
      79           0 :             catch (css::uno::Exception const &)
      80             :             {
      81             :                 // Handled below (see @ fallback).
      82             :             }
      83             :         }
      84             :     }
      85             : 
      86             : 
      87           0 :     if (!xResult.is() && xFactory.is())
      88             :     {
      89             :         // Always fall back to OfficeFilePicker.
      90           0 :         xResult = xFactory->createInstanceWithContext (
      91             :                 OUString( "com.sun.star.ui.dialogs.OfficeFilePicker"),
      92           0 :                 context);
      93             :     }
      94           0 :     if (xResult.is())
      95             :     {
      96             :         // Add to FilePicker history.
      97           0 :         svt::addFilePicker (xResult);
      98             :     }
      99           0 :     return xResult;
     100             : }
     101             : 
     102           2 : OUString SAL_CALL FilePicker_getImplementationName()
     103             : {
     104           2 :     return OUString("com.sun.star.comp.svt.FilePicker");
     105             : }
     106             : 
     107           0 : Sequence< OUString > FilePicker_getSupportedServiceNames()
     108             : {
     109           0 :     Sequence< OUString > aServiceNames(1);
     110           0 :     aServiceNames.getArray()[0] =
     111           0 :         OUString( "com.sun.star.ui.dialogs.FilePicker");
     112           0 :     return aServiceNames;
     113             : }
     114             : 
     115             : /*
     116             :  * FolderPicker implementation.
     117             :  */
     118           2 : static OUString FolderPicker_getSystemPickerServiceName()
     119             : {
     120           2 :     OUString aDesktopEnvironment (Application::GetDesktopEnvironment());
     121             : #ifdef UNX
     122           2 :     if (aDesktopEnvironment.equalsIgnoreAsciiCase("tde"))
     123           0 :         return OUString("com.sun.star.ui.dialogs.TDEFolderPicker");
     124           2 :     else if (aDesktopEnvironment.equalsIgnoreAsciiCase("kde"))
     125           0 :         return OUString("com.sun.star.ui.dialogs.KDEFolderPicker");
     126           2 :     else if (aDesktopEnvironment.equalsIgnoreAsciiCase("macosx"))
     127           0 :         return OUString("com.sun.star.ui.dialogs.AquaFolderPicker");
     128             : #endif
     129           2 :     return OUString("com.sun.star.ui.dialogs.SystemFolderPicker");
     130             : }
     131             : 
     132           2 : Reference< css::uno::XInterface > FolderPicker_CreateInstance (
     133             :     Reference< css::uno::XComponentContext > const & context)
     134             : {
     135           2 :     Reference< css::uno::XInterface > xResult;
     136             : 
     137           2 :     if (!context.is())
     138           0 :         return xResult;
     139             : 
     140           4 :     Reference< css::lang::XMultiComponentFactory > xFactory (context->getServiceManager());
     141           2 :     if (xFactory.is() && SvtMiscOptions().UseSystemFileDialog())
     142             :     {
     143           2 :         xResult = Reference< css::uno::XInterface >( Application::createFolderPicker( context ) );
     144           2 :         if (!xResult.is())
     145             :         {
     146             :             try
     147             :             {
     148           6 :                 xResult = xFactory->createInstanceWithContext (
     149             :                                 FolderPicker_getSystemPickerServiceName(),
     150           4 :                                 context);
     151             :             }
     152           0 :             catch (css::uno::Exception const &)
     153             :             {
     154             :                 // Handled below (see @ fallback).
     155             :             }
     156             :         }
     157             :     }
     158           2 :     if (!xResult.is() && xFactory.is() )
     159             :     {
     160             :         // Always fall back to OfficeFolderPicker.
     161           6 :         xResult = xFactory->createInstanceWithContext (
     162             :                 OUString( "com.sun.star.ui.dialogs.OfficeFolderPicker"),
     163           4 :                 context);
     164             :     }
     165           2 :     if (xResult.is())
     166             :     {
     167             :         // Add to FolderPicker history.
     168           2 :         svt::addFolderPicker (xResult);
     169             :     }
     170           2 :     return xResult;
     171             : }
     172             : 
     173           2 : OUString SAL_CALL FolderPicker_getImplementationName()
     174             : {
     175           2 :     return OUString("com.sun.star.comp.svt.FolderPicker");
     176             : }
     177             : 
     178           2 : Sequence< OUString > FolderPicker_getSupportedServiceNames()
     179             : {
     180           2 :     Sequence< OUString > aServiceNames(1);
     181           4 :     aServiceNames.getArray()[0] =
     182           2 :         OUString( "com.sun.star.ui.dialogs.FolderPicker");
     183           2 :     return aServiceNames;
     184        1227 : }
     185             : 
     186             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10