LCOV - code coverage report
Current view: top level - svtools/source/uno - fpicker.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 29 66 43.9 %
Date: 2015-06-13 12:38:46 Functions: 5 8 62.5 %
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           1 : OUString SAL_CALL FilePicker_getImplementationName()
     103             : {
     104           1 :     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] = "com.sun.star.ui.dialogs.FilePicker";
     111           0 :     return aServiceNames;
     112             : }
     113             : 
     114             : /*
     115             :  * FolderPicker implementation.
     116             :  */
     117           1 : static OUString FolderPicker_getSystemPickerServiceName()
     118             : {
     119           1 :     OUString aDesktopEnvironment (Application::GetDesktopEnvironment());
     120             : #ifdef UNX
     121           1 :     if (aDesktopEnvironment.equalsIgnoreAsciiCase("tde"))
     122           0 :         return OUString("com.sun.star.ui.dialogs.TDEFolderPicker");
     123           1 :     else if (aDesktopEnvironment.equalsIgnoreAsciiCase("kde"))
     124           0 :         return OUString("com.sun.star.ui.dialogs.KDEFolderPicker");
     125           1 :     else if (aDesktopEnvironment.equalsIgnoreAsciiCase("macosx"))
     126           0 :         return OUString("com.sun.star.ui.dialogs.AquaFolderPicker");
     127             : #endif
     128           1 :     return OUString("com.sun.star.ui.dialogs.SystemFolderPicker");
     129             : }
     130             : 
     131           1 : Reference< css::uno::XInterface > FolderPicker_CreateInstance (
     132             :     Reference< css::uno::XComponentContext > const & context)
     133             : {
     134           1 :     Reference< css::uno::XInterface > xResult;
     135             : 
     136           1 :     if (!context.is())
     137           0 :         return xResult;
     138             : 
     139           2 :     Reference< css::lang::XMultiComponentFactory > xFactory (context->getServiceManager());
     140           1 :     if (xFactory.is() && SvtMiscOptions().UseSystemFileDialog())
     141             :     {
     142           1 :         xResult = Reference< css::uno::XInterface >( Application::createFolderPicker( context ) );
     143           1 :         if (!xResult.is())
     144             :         {
     145             :             try
     146             :             {
     147           3 :                 xResult = xFactory->createInstanceWithContext (
     148             :                                 FolderPicker_getSystemPickerServiceName(),
     149           2 :                                 context);
     150             :             }
     151           0 :             catch (css::uno::Exception const &)
     152             :             {
     153             :                 // Handled below (see @ fallback).
     154             :             }
     155             :         }
     156             :     }
     157           1 :     if (!xResult.is() && xFactory.is() )
     158             :     {
     159             :         // Always fall back to OfficeFolderPicker.
     160           3 :         xResult = xFactory->createInstanceWithContext (
     161             :                 OUString( "com.sun.star.ui.dialogs.OfficeFolderPicker"),
     162           2 :                 context);
     163             :     }
     164           1 :     if (xResult.is())
     165             :     {
     166             :         // Add to FolderPicker history.
     167           1 :         svt::addFolderPicker (xResult);
     168             :     }
     169           1 :     return xResult;
     170             : }
     171             : 
     172           1 : OUString SAL_CALL FolderPicker_getImplementationName()
     173             : {
     174           1 :     return OUString("com.sun.star.comp.svt.FolderPicker");
     175             : }
     176             : 
     177           1 : Sequence< OUString > FolderPicker_getSupportedServiceNames()
     178             : {
     179           1 :     Sequence< OUString > aServiceNames(1);
     180           1 :     aServiceNames.getArray()[0] = "com.sun.star.ui.dialogs.FolderPicker";
     181           1 :     return aServiceNames;
     182             : }
     183             : 
     184             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11