LCOV - code coverage report
Current view: top level - sc/source/ui/vba - vbafiledialog.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 63 0.0 %
Date: 2012-08-25 Functions: 0 7 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 154 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright IBM Corporation 2009, 2010.
       7                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       8                 :            :  *
       9                 :            :  * OpenOffice.org - a multi-platform office productivity suite
      10                 :            :  *
      11                 :            :  * This file is part of OpenOffice.org.
      12                 :            :  *
      13                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      14                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      15                 :            :  * only, as published by the Free Software Foundation.
      16                 :            :  *
      17                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      18                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      19                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      20                 :            :  * GNU Lesser General Public License version 3 for more details
      21                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      22                 :            :  *
      23                 :            :  * You should have received a copy of the GNU Lesser General Public License
      24                 :            :  * version 3 along with OpenOffice.org.  If not, see
      25                 :            :  * <http://www.openoffice.org/license.html>
      26                 :            :  * for a copy of the LGPLv3 License.
      27                 :            :  *
      28                 :            :  ************************************************************************/
      29                 :            : 
      30                 :            : #include "vbafiledialog.hxx"
      31                 :            : #include "comphelper/processfactory.hxx"
      32                 :            : #include <com/sun/star/lang/XServiceInfo.hpp>
      33                 :            : #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
      34                 :            : #include <com/sun/star/ui/dialogs/XFilePicker2.hpp>
      35                 :            : #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
      36                 :            : #include "tools/urlobj.hxx"
      37                 :            : 
      38                 :            : 
      39                 :            : using namespace ::com::sun::star;
      40                 :            : using namespace ::com::sun::star::uno;
      41                 :            : 
      42                 :            : 
      43                 :          0 : ScVbaFileDialog::ScVbaFileDialog( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, const css::uno::Reference< css::frame::XModel >& xModel )
      44 [ #  # ][ #  # ]:          0 : :   ScVbaFileDialog_BASE( xParent, xContext, xModel )
      45                 :            : {
      46 [ #  # ][ #  # ]:          0 :     m_pFileDialogSelectedItems = new VbaFileDialogSelectedItems(xParent, xContext, (com::sun::star::container::XIndexAccess *)&m_FileDialogSelectedObj);
      47                 :          0 : }
      48                 :            : 
      49 [ #  # ][ #  # ]:          0 : ScVbaFileDialog::~ScVbaFileDialog()
      50                 :            : {
      51         [ #  # ]:          0 :     if (m_pFileDialogSelectedItems != NULL)
      52                 :            :     {
      53 [ #  # ][ #  # ]:          0 :         delete m_pFileDialogSelectedItems;
      54                 :            :     }
      55         [ #  # ]:          0 : }
      56                 :            : 
      57                 :            : rtl::OUString
      58                 :          0 : ScVbaFileDialog::getServiceImplName()
      59                 :            : {
      60                 :          0 :     return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ScVbaFileDialog"));
      61                 :            : }
      62                 :            : 
      63                 :            : css::uno::Sequence<rtl::OUString>
      64                 :          0 : ScVbaFileDialog::getServiceNames()
      65                 :            : {
      66 [ #  # ][ #  # ]:          0 :     static Sequence< rtl::OUString > aServiceNames;
         [ #  # ][ #  # ]
      67         [ #  # ]:          0 :     if ( aServiceNames.getLength() == 0 )
      68                 :            :     {
      69                 :          0 :         aServiceNames.realloc( 1 );
      70         [ #  # ]:          0 :         aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.FileDialog" ) );
      71                 :            :     }
      72                 :          0 :     return aServiceNames;
      73                 :            : 
      74                 :            : }
      75                 :            : 
      76                 :            : css::uno::Reference< ov::XFileDialogSelectedItems > SAL_CALL
      77                 :          0 : ScVbaFileDialog::getSelectedItems() throw (css::uno::RuntimeException)
      78                 :            : {
      79         [ #  # ]:          0 :     css::uno::Reference< ov::XFileDialogSelectedItems > xFileDlgSlc = (ov::XFileDialogSelectedItems *)m_pFileDialogSelectedItems;
      80                 :          0 :     return xFileDlgSlc;
      81                 :            : }
      82                 :            : 
      83                 :            : ::sal_Int32 SAL_CALL
      84                 :          0 : ScVbaFileDialog::Show( ) throw (::com::sun::star::uno::RuntimeException)
      85                 :            : {
      86                 :            :     // Returns an Integer indicating if user pressed "Open" button(-1) or "Cancel" button(0).
      87                 :          0 :     sal_Int32 nResult = -1;
      88                 :            :     try
      89                 :            :     {
      90         [ #  # ]:          0 :         m_sSelectedItems.realloc(0);
      91                 :            : 
      92         [ #  # ]:          0 :         const ::rtl::OUString sServiceName(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.FilePicker" ));
      93                 :            : 
      94 [ #  # ][ #  # ]:          0 :         Reference< lang::XMultiServiceFactory > xMSF( comphelper::getProcessServiceFactory(), uno::UNO_QUERY );
      95                 :            :         // Set the type of File Picker Dialog: TemplateDescription::FILEOPEN_SIMPLE.
      96         [ #  # ]:          0 :         Sequence< uno::Any > aDialogType( 1 );
      97 [ #  # ][ #  # ]:          0 :         aDialogType[0] <<= ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE;
      98 [ #  # ][ #  # ]:          0 :         Reference < ui::dialogs::XFilePicker > xFilePicker( xMSF->createInstanceWithArguments( sServiceName, aDialogType ), UNO_QUERY );
                 [ #  # ]
      99         [ #  # ]:          0 :         Reference < ui::dialogs::XFilePicker2 > xFilePicker2( xFilePicker, UNO_QUERY );
     100         [ #  # ]:          0 :         if ( xFilePicker.is() )
     101                 :            :         {
     102 [ #  # ][ #  # ]:          0 :             xFilePicker->setMultiSelectionMode(sal_True);
     103 [ #  # ][ #  # ]:          0 :             if ( xFilePicker->execute() )
                 [ #  # ]
     104                 :            :             {
     105         [ #  # ]:          0 :                 if ( xFilePicker2.is() )
     106                 :            :                 {
     107                 :            :                     // On Linux, XFilePicker->getFiles() always return one selected file although we select
     108                 :            :                     // more than one file, also on Vista XFilePicker->getFiles() does not work well too,
     109                 :            :                     // so we call XFilePicker2->getSelectedFiles() to get selected files.
     110 [ #  # ][ #  # ]:          0 :                     m_sSelectedItems = xFilePicker2->getSelectedFiles();
         [ #  # ][ #  # ]
     111                 :            :                 }
     112                 :            :                 else
     113                 :            :                 {
     114                 :            :                     // If only one file is selected, the first entry of the sequence contains the complete path/filename in
     115                 :            :                     // URL format. If multiple files are selected, the first entry of the sequence contains the path in URL
     116                 :            :                     // format, and the other entries contains the names of the selected files without path information.
     117 [ #  # ][ #  # ]:          0 :                     Sequence< rtl::OUString > aSelectedFiles = xFilePicker->getFiles();
     118                 :          0 :                     sal_Int32 iFileCount = aSelectedFiles.getLength();
     119         [ #  # ]:          0 :                     if ( iFileCount > 1 )
     120                 :            :                     {
     121         [ #  # ]:          0 :                         m_sSelectedItems.realloc( iFileCount - 1 );
     122 [ #  # ][ #  # ]:          0 :                         INetURLObject aPath( aSelectedFiles[0] );
     123         [ #  # ]:          0 :                         aPath.setFinalSlash();
     124         [ #  # ]:          0 :                         for ( sal_Int32 i = 1; i < iFileCount; i++ )
     125                 :            :                         {
     126 [ #  # ][ #  # ]:          0 :                             if ( aSelectedFiles[i].indexOf ('/') > 0 || aSelectedFiles[i].indexOf ('\\') > 0 )
         [ #  # ][ #  # ]
                 [ #  # ]
     127                 :            :                             {
     128 [ #  # ][ #  # ]:          0 :                                 m_sSelectedItems[i - 1] = aSelectedFiles[i];
     129                 :            :                             }
     130                 :            :                             else
     131                 :            :                             {
     132         [ #  # ]:          0 :                                 if ( i == 1 )
     133 [ #  # ][ #  # ]:          0 :                                     aPath.Append( aSelectedFiles[i] );
     134                 :            :                                 else
     135 [ #  # ][ #  # ]:          0 :                                     aPath.setName( aSelectedFiles[i] );
     136 [ #  # ][ #  # ]:          0 :                                 m_sSelectedItems[i - 1] = aPath.GetMainURL(INetURLObject::NO_DECODE);
     137                 :            :                             }
     138         [ #  # ]:          0 :                         }
     139                 :            :                     }
     140         [ #  # ]:          0 :                     else if ( iFileCount == 1 )
     141                 :            :                     {
     142         [ #  # ]:          0 :                         m_sSelectedItems = aSelectedFiles;
     143         [ #  # ]:          0 :                     }
     144                 :            :                 }
     145                 :            : 
     146                 :          0 :                 sal_Int32 iFileCount = m_sSelectedItems.getLength();
     147                 :          0 :                 rtl::OUString aTemp;
     148         [ #  # ]:          0 :                 for ( sal_Int32 i = 0; i < iFileCount; i++ )
     149                 :            :                 {
     150 [ #  # ][ #  # ]:          0 :                     INetURLObject aObj( m_sSelectedItems[i] );
     151         [ #  # ]:          0 :                     if ( aObj.GetProtocol() == INET_PROT_FILE )
     152                 :            :                     {
     153         [ #  # ]:          0 :                         aTemp = aObj.PathToFileName();
     154 [ #  # ][ #  # ]:          0 :                         m_sSelectedItems[i] = aTemp.isEmpty() ? m_sSelectedItems[i] : aTemp;
                 [ #  # ]
     155                 :            :                     }
     156         [ #  # ]:          0 :                 }
     157                 :            :             }
     158                 :            :             else
     159                 :            :             {
     160                 :          0 :                 nResult = 0;
     161                 :            :             }
     162                 :            :         }
     163                 :            : 
     164 [ #  # ][ #  # ]:          0 :         m_FileDialogSelectedObj.SetSelectedFile(m_sSelectedItems);
                 [ #  # ]
     165                 :            :     }
     166                 :          0 :     catch( const uno::Exception& )
     167                 :            :     {
     168                 :          0 :         return 0;
     169                 :            :     }
     170                 :            : 
     171                 :          0 :     return nResult;
     172                 :            : }
     173                 :            : 
     174                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10