LCOV - code coverage report
Current view: top level - libreoffice/cui/source/dialogs - multifil.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 61 0.0 %
Date: 2012-12-27 Functions: 0 7 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/config.h"
      21             : 
      22             : #include <comphelper/processfactory.hxx>
      23             : #include <tools/shl.hxx>
      24             : #include <vcl/msgbox.hxx>
      25             : #include <sfx2/filedlghelper.hxx>
      26             : 
      27             : #include <tools/urlobj.hxx>
      28             : 
      29             : #include "multipat.hxx"
      30             : #include "multifil.hxx"
      31             : #include <dialmgr.hxx>
      32             : 
      33             : #include "multipat.hrc"
      34             : #include <cuires.hrc>
      35             : 
      36             : // #97807# -------------
      37             : #include <com/sun/star/ucb/UniversalContentBroker.hpp>
      38             : 
      39             : #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
      40             : 
      41             : using namespace com::sun::star::ucb;
      42             : using namespace com::sun::star::uno;
      43             : 
      44             : // class SvxMultiFileDialog ----------------------------------------------
      45             : 
      46           0 : IMPL_LINK( SvxMultiFileDialog, AddHdl_Impl, PushButton *, pBtn )
      47             : {
      48             :     sfx2::FileDialogHelper aDlg(
      49           0 :         com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, 0 );
      50             : 
      51           0 :     if ( IsClassPathMode() )
      52             :     {
      53           0 :         aDlg.SetTitle( CUI_RES( RID_SVXSTR_ARCHIVE_TITLE ) );
      54           0 :         aDlg.AddFilter( CUI_RES( RID_SVXSTR_ARCHIVE_HEADLINE ), rtl::OUString("*.jar;*.zip") );
      55             :     }
      56             : 
      57           0 :     if ( aDlg.Execute() == ERRCODE_NONE )
      58             :     {
      59             :         // #97807# URL content comparison of entries -----------
      60           0 :         INetURLObject aFile( aDlg.GetPath() );
      61           0 :         String sInsFile = aFile.getFSysPath( INetURLObject::FSYS_DETECT );
      62           0 :         ::ucbhelper::Content aContent( aFile.GetMainURL( INetURLObject::NO_DECODE ), Reference< XCommandEnvironment >(), comphelper::getProcessComponentContext() );
      63           0 :         Reference< XContent > xContent = aContent.get();
      64             :         OSL_ENSURE( xContent.is(), "AddHdl_Impl: invalid content interface!" );
      65           0 :         Reference< XContentIdentifier > xID = xContent->getIdentifier();
      66             :         OSL_ENSURE( xID.is(), "AddHdl_Impl: invalid ID interface!" );
      67             :         // ensure the content of files are valid
      68             : 
      69           0 :         sal_uInt16 nCount = aPathLB.GetEntryCount();
      70           0 :         sal_Bool bDuplicated = sal_False;
      71             :         try
      72             :         {
      73           0 :             if( nCount > 0 ) // start comparison
      74             :             {
      75             :                 sal_uInt16 i;
      76           0 :                 ::ucbhelper::Content & VContent = aContent; // temporary Content reference
      77           0 :                 Reference< XContent > xVContent;
      78           0 :                 Reference< XContentIdentifier > xVID;
      79           0 :                 for( i = 0; i < nCount; i++ )
      80             :                 {
      81           0 :                     String sVFile = aPathLB.GetEntry( i );
      82           0 :                     std::map< String, ::ucbhelper::Content >::iterator aCur = aFileContentMap.find( sVFile );
      83           0 :                     if( aCur == aFileContentMap.end() ) // look for File Content in aFileContentMap, but not find it.
      84             :                     {
      85           0 :                         INetURLObject aVFile( sVFile, INetURLObject::FSYS_DETECT );
      86           0 :                         aFileContentMap[sVFile] = ::ucbhelper::Content( aVFile.GetMainURL( INetURLObject::NO_DECODE ), Reference< XCommandEnvironment >(), comphelper::getProcessComponentContext() );
      87           0 :                         VContent = aFileContentMap.find( sVFile )->second;
      88             :                     }
      89             :                     else
      90           0 :                         VContent = aCur->second;
      91           0 :                     xVContent = VContent.get();
      92             :                     OSL_ENSURE( xVContent.is(), "AddHdl_Impl: invalid content interface!" );
      93           0 :                     xVID = xVContent->getIdentifier();
      94             :                     OSL_ENSURE( xVID.is(), "AddHdl_Impl: invalid ID interface!" );
      95           0 :                     if ( xID.is() && xVID.is()
      96             :                          && ( UniversalContentBroker::create(
      97           0 :                                   comphelper::getProcessComponentContext() )->
      98           0 :                               compareContentIds( xID, xVID ) == 0 ) )
      99             :                     {
     100           0 :                         bDuplicated = sal_True;
     101             :                         break;
     102             :                     }
     103           0 :                 }
     104             :             } // end of if the entries are more than zero.
     105             :         } // end of try(}
     106           0 :         catch( const Exception& ) // catch every exception of comparison
     107             :            {
     108             :             OSL_FAIL( "AddHdl_Impl: caught an unexpected exception!" );
     109             :            }
     110             : 
     111           0 :         if ( bDuplicated ) // #97807# --------------------
     112             :         {
     113           0 :             String sMsg( CUI_RES( RID_SVXSTR_MULTIFILE_DBL_ERR ) );
     114           0 :             sMsg.SearchAndReplaceAscii( "%1", sInsFile );
     115           0 :             InfoBox( pBtn, sMsg ).Execute();
     116             :         }
     117             :         else
     118             :         {
     119           0 :             sal_uInt16 nPos = aPathLB.InsertEntry( sInsFile, LISTBOX_APPEND );
     120           0 :             aPathLB.SetEntryData( nPos, (void*) new String( sInsFile ) );
     121           0 :         }
     122             : 
     123             :     } // end of if ( aDlg.Execute() == ERRCODE_NONE )
     124           0 :     return 0;
     125             : }
     126             : 
     127             : // -----------------------------------------------------------------------
     128             : 
     129           0 : IMPL_LINK_NOARG(SvxMultiFileDialog, DelHdl_Impl)
     130             : {
     131           0 :     sal_uInt16 nPos = aPathLB.GetSelectEntryPos();
     132           0 :     aPathLB.RemoveEntry( nPos );
     133           0 :     sal_uInt16 nCnt = aPathLB.GetEntryCount();
     134             : 
     135           0 :     if ( nCnt )
     136             :     {
     137           0 :         nCnt--;
     138             : 
     139           0 :         if ( nPos > nCnt )
     140           0 :             nPos = nCnt;
     141           0 :         aPathLB.SelectEntryPos( nPos );
     142             :     }
     143           0 :     return 0;
     144             : }
     145             : 
     146             : // -----------------------------------------------------------------------
     147             : 
     148           0 : SvxMultiFileDialog::SvxMultiFileDialog( Window* pParent, sal_Bool bEmptyAllowed ) :
     149             : 
     150           0 :     SvxMultiPathDialog( pParent, bEmptyAllowed )
     151             : 
     152             : {
     153           0 :     aAddBtn.SetClickHdl( LINK( this, SvxMultiFileDialog, AddHdl_Impl ) );
     154           0 :     aDelBtn.SetClickHdl( LINK( this, SvxMultiFileDialog, DelHdl_Impl ) );
     155           0 :     SetText( CUI_RES( RID_SVXSTR_FILE_TITLE ) );
     156           0 :     aPathFL.SetText( CUI_RES( RID_SVXSTR_FILE_HEADLINE ) );
     157           0 :     aDelBtn.Enable();
     158           0 : }
     159             : 
     160             : // -----------------------------------------------------------------------
     161             : 
     162           0 : SvxMultiFileDialog::~SvxMultiFileDialog()
     163             : {
     164           0 : }
     165             : 
     166             : 
     167             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10