LCOV - code coverage report
Current view: top level - libreoffice/fpicker/source/generic - fpicker.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 66 0.0 %
Date: 2012-12-27 Functions: 0 9 0.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 "cppuhelper/implementationentry.hxx"
      24             : #include "com/sun/star/lang/XMultiComponentFactory.hpp"
      25             : 
      26             : #include "svtools/miscopt.hxx"
      27             : #include "svl/pickerhistoryaccess.hxx"
      28             : 
      29             : #include "vcl/svapp.hxx"
      30             : 
      31             : #ifdef WNT
      32             : #define GradientStyle_RECT BLA_GradientStyle_RECT
      33             : #include <windows.h>
      34             : #undef GradientStyle_RECT
      35             : #endif
      36             : 
      37             : using css::uno::Reference;
      38             : using css::uno::Sequence;
      39             : 
      40             : /*
      41             :  * FilePicker implementation.
      42             :  */
      43           0 : static OUString FilePicker_getSystemPickerServiceName()
      44             : {
      45             : #ifdef UNX
      46           0 :     OUString aDesktopEnvironment (Application::GetDesktopEnvironment());
      47           0 :     if (aDesktopEnvironment.equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM("tde")))
      48           0 :         return OUString ("com.sun.star.ui.dialogs.TDEFilePicker");
      49           0 :     else if (aDesktopEnvironment.equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM("kde")))
      50           0 :         return OUString ("com.sun.star.ui.dialogs.KDEFilePicker");
      51           0 :     else if (aDesktopEnvironment.equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM("kde4")))
      52           0 :         return OUString ("com.sun.star.ui.dialogs.KDE4FilePicker");
      53           0 :     else if (aDesktopEnvironment.equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM("macosx")))
      54           0 :         return OUString ("com.sun.star.ui.dialogs.AquaFilePicker");
      55             :     else
      56           0 :         return OUString ("com.sun.star.ui.dialogs.SystemFilePicker");
      57             : #endif
      58             : #ifdef WNT
      59             :     return OUString ("com.sun.star.ui.dialogs.Win32FilePicker");
      60             : #endif
      61             : }
      62             : 
      63           0 : static Reference< css::uno::XInterface > FilePicker_createInstance (
      64             :     Reference< css::uno::XComponentContext > const & rxContext)
      65             : {
      66           0 :     Reference< css::uno::XInterface > xResult;
      67             : 
      68           0 :     if (!rxContext.is())
      69             :         return xResult;
      70             : 
      71           0 :     Reference< css::lang::XMultiComponentFactory > xFactory (rxContext->getServiceManager());
      72           0 :     if (xFactory.is() && SvtMiscOptions().UseSystemFileDialog())
      73             :     {
      74           0 :         xResult = Reference< css::uno::XInterface >( Application::createFilePicker( rxContext ) );
      75             : 
      76           0 :         if (!xResult.is())
      77             :         {
      78             :             try
      79             :             {
      80           0 :                 xResult = xFactory->createInstanceWithContext (
      81             :                         FilePicker_getSystemPickerServiceName(),
      82           0 :                         rxContext);
      83             :             }
      84           0 :             catch (css::uno::Exception const &)
      85             :             {
      86             :                 // Handled below (see @ fallback).
      87             :             }
      88             :         }
      89             :     }
      90             : 
      91             : 
      92           0 :     if (!xResult.is() && xFactory.is())
      93             :     {
      94             :         // Always fall back to OfficeFilePicker.
      95           0 :         xResult = xFactory->createInstanceWithContext (
      96             :                 OUString (RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.OfficeFilePicker")),
      97           0 :                 rxContext);
      98             :     }
      99           0 :     if (xResult.is())
     100             :     {
     101             :         // Add to FilePicker history.
     102           0 :         svt::addFilePicker (xResult);
     103             :     }
     104           0 :     return xResult;
     105             : }
     106             : 
     107           0 : static OUString FilePicker_getImplementationName()
     108             : {
     109           0 :     return OUString (RTL_CONSTASCII_USTRINGPARAM ("com.sun.star.comp.fpicker.FilePicker"));
     110             : }
     111             : 
     112           0 : static Sequence< OUString > FilePicker_getSupportedServiceNames()
     113             : {
     114           0 :     Sequence< OUString > aServiceNames(1);
     115             :     aServiceNames.getArray()[0] =
     116           0 :         OUString (RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.FilePicker"));
     117           0 :     return aServiceNames;
     118             : }
     119             : 
     120             : /*
     121             :  * FolderPicker implementation.
     122             :  */
     123           0 : static OUString FolderPicker_getSystemPickerServiceName()
     124             : {
     125           0 :     OUString aDesktopEnvironment (Application::GetDesktopEnvironment());
     126             : #ifdef UNX
     127           0 :     if (aDesktopEnvironment.equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM("tde")))
     128           0 :         return OUString (RTL_CONSTASCII_USTRINGPARAM ("com.sun.star.ui.dialogs.TDEFolderPicker"));
     129           0 :     else if (aDesktopEnvironment.equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM("kde")))
     130           0 :         return OUString (RTL_CONSTASCII_USTRINGPARAM ("com.sun.star.ui.dialogs.KDEFolderPicker"));
     131           0 :     else if (aDesktopEnvironment.equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM("macosx")))
     132           0 :         return OUString (RTL_CONSTASCII_USTRINGPARAM ("com.sun.star.ui.dialogs.AquaFolderPicker"));
     133             : #endif
     134           0 :     return OUString (RTL_CONSTASCII_USTRINGPARAM ("com.sun.star.ui.dialogs.SystemFolderPicker"));
     135             : }
     136             : 
     137           0 : static Reference< css::uno::XInterface > FolderPicker_createInstance (
     138             :     Reference< css::uno::XComponentContext > const & rxContext)
     139             : {
     140           0 :     Reference< css::uno::XInterface > xResult;
     141             : 
     142           0 :     if (!rxContext.is())
     143             :         return xResult;
     144             : 
     145           0 :     Reference< css::lang::XMultiComponentFactory > xFactory (rxContext->getServiceManager());
     146           0 :     if (xFactory.is() && SvtMiscOptions().UseSystemFileDialog())
     147             :     {
     148           0 :         xResult = Reference< css::uno::XInterface >( Application::createFolderPicker( rxContext ) );
     149           0 :         if (!xResult.is())
     150             :         {
     151             :             try
     152             :             {
     153           0 :                 xResult = xFactory->createInstanceWithContext (
     154             :                                 FolderPicker_getSystemPickerServiceName(),
     155           0 :                                 rxContext);
     156             :             }
     157           0 :             catch (css::uno::Exception const &)
     158             :             {
     159             :                 // Handled below (see @ fallback).
     160             :             }
     161             :         }
     162             :     }
     163           0 :     if (!xResult.is() && xFactory.is() )
     164             :     {
     165             :         // Always fall back to OfficeFolderPicker.
     166           0 :         xResult = xFactory->createInstanceWithContext (
     167             :                 OUString (RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.OfficeFolderPicker")),
     168           0 :                 rxContext);
     169             :     }
     170           0 :     if (xResult.is())
     171             :     {
     172             :         // Add to FolderPicker history.
     173           0 :         svt::addFolderPicker (xResult);
     174             :     }
     175           0 :     return xResult;
     176             : }
     177             : 
     178           0 : static OUString FolderPicker_getImplementationName()
     179             : {
     180           0 :     return OUString (RTL_CONSTASCII_USTRINGPARAM ("com.sun.star.comp.fpicker.FolderPicker"));
     181             : }
     182             : 
     183           0 : static Sequence< OUString > FolderPicker_getSupportedServiceNames()
     184             : {
     185           0 :     Sequence< OUString > aServiceNames(1);
     186             :     aServiceNames.getArray()[0] =
     187           0 :         OUString (RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.FolderPicker"));
     188           0 :     return aServiceNames;
     189             : }
     190             : 
     191             : /*
     192             :  * Implementation entries.
     193             :  */
     194             : static cppu::ImplementationEntry g_entries[] =
     195             : {
     196             :     {
     197             :         FilePicker_createInstance,
     198             :         FilePicker_getImplementationName,
     199             :         FilePicker_getSupportedServiceNames,
     200             :         cppu::createSingleComponentFactory, 0, 0
     201             :     },
     202             :     {
     203             :         FolderPicker_createInstance,
     204             :         FolderPicker_getImplementationName,
     205             :         FolderPicker_getSupportedServiceNames,
     206             :         cppu::createSingleComponentFactory, 0, 0
     207             :     },
     208             :     { 0, 0, 0, 0, 0, 0 }
     209             : };
     210             : 
     211             : /*
     212             :  * Public (exported) interface.
     213             :  */
     214             : extern "C"
     215             : {
     216           0 : SAL_DLLPUBLIC_EXPORT void * SAL_CALL fpicker_component_getFactory (
     217             :     const sal_Char * pImplementationName, void * pServiceManager, void * pRegistryKey)
     218             : {
     219             :     return cppu::component_getFactoryHelper (
     220           0 :         pImplementationName, pServiceManager, pRegistryKey, g_entries);
     221             : }
     222             : 
     223             : } // extern "C"
     224             : 
     225             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10