LCOV - code coverage report
Current view: top level - libreoffice/filter/source/xsltdialog - xmlfiltertabdialog.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 150 0.0 %
Date: 2012-12-17 Functions: 0 13 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 <com/sun/star/container/XNameAccess.hpp>
      21             : #include <com/sun/star/beans/PropertyValue.hpp>
      22             : #include <tools/resid.hxx>
      23             : #include <vcl/msgbox.hxx>
      24             : #include <osl/file.hxx>
      25             : 
      26             : #include "xmlfilterdialogstrings.hrc"
      27             : #include "xmlfiltertabdialog.hxx"
      28             : #include "xmlfiltertabdialog.hrc"
      29             : #include "xmlfiltertabpagebasic.hrc"
      30             : #include "xmlfiltertabpagexslt.hrc"
      31             : #include "xmlfiltertabpagebasic.hxx"
      32             : #include "xmlfiltertabpagexslt.hxx"
      33             : #include "xmlfiltersettingsdialog.hxx"
      34             : #include "xmlfilterhelpids.hrc"
      35             : 
      36             : using namespace com::sun::star::uno;
      37             : using namespace com::sun::star::container;
      38             : using namespace com::sun::star::beans;
      39             : using namespace com::sun::star::lang;
      40             : 
      41           0 : XMLFilterTabDialog::XMLFilterTabDialog( Window *pParent, ResMgr& rResMgr, const Reference< XMultiServiceFactory >& rxMSF, const filter_info_impl* pInfo ) :
      42             :     TabDialog( pParent, ResId( DLG_XML_FILTER_TABDIALOG, rResMgr ) ),
      43             :     mxMSF( rxMSF ),
      44             :     mrResMgr( rResMgr ),
      45             :     maTabCtrl( this, ResId( 1, rResMgr ) ),
      46             :     maOKBtn( this ),
      47             :     maCancelBtn( this ),
      48           0 :     maHelpBtn( this )
      49             : {
      50           0 :     FreeResource();
      51             : 
      52           0 :     maTabCtrl.SetHelpId( HID_XML_FILTER_TABPAGE_CTRL );
      53             : 
      54           0 :     mpOldInfo = pInfo;
      55           0 :     mpNewInfo = new filter_info_impl( *mpOldInfo );
      56             : 
      57           0 :     OUString aTitle( GetText() );
      58           0 :     aTitle = aTitle.replaceAll("%s", mpNewInfo->maFilterName);
      59           0 :     SetText( aTitle );
      60             : 
      61           0 :     maTabCtrl.Show();
      62           0 :     maOKBtn.Show();
      63           0 :     maCancelBtn.Show();
      64           0 :     maHelpBtn.Show();
      65             : 
      66           0 :     maOKBtn.SetClickHdl( LINK( this, XMLFilterTabDialog, OkHdl ) );
      67             : 
      68           0 :     maTabCtrl.SetActivatePageHdl( LINK( this, XMLFilterTabDialog, ActivatePageHdl ) );
      69           0 :     maTabCtrl.SetDeactivatePageHdl( LINK( this, XMLFilterTabDialog, DeactivatePageHdl ) );
      70             : 
      71           0 :     mpBasicPage = new XMLFilterTabPageBasic( &maTabCtrl, mrResMgr );
      72           0 :     mpBasicPage->SetInfo( mpNewInfo );
      73             : 
      74           0 :     maTabCtrl.SetTabPage( RID_XML_FILTER_TABPAGE_BASIC, mpBasicPage );
      75             : 
      76           0 :     Size aSiz = mpBasicPage->GetSizePixel();
      77           0 :     Size aCtrlSiz = maTabCtrl.GetTabPageSizePixel();
      78             :     // set size on TabControl only if smaller than TabPage
      79           0 :     if ( aCtrlSiz.Width() < aSiz.Width() || aCtrlSiz.Height() < aSiz.Height() )
      80             :     {
      81           0 :         maTabCtrl.SetTabPageSizePixel( aSiz );
      82           0 :         aCtrlSiz = aSiz;
      83             :     }
      84             : 
      85           0 :     mpXSLTPage = new XMLFilterTabPageXSLT( &maTabCtrl, mrResMgr, mxMSF );
      86           0 :     mpXSLTPage->SetInfo( mpNewInfo );
      87             : 
      88           0 :     maTabCtrl.SetTabPage( RID_XML_FILTER_TABPAGE_XSLT, mpXSLTPage );
      89             : 
      90           0 :     aSiz = mpXSLTPage->GetSizePixel();
      91           0 :     if ( aCtrlSiz.Width() < aSiz.Width() || aCtrlSiz.Height() < aSiz.Height() )
      92             :     {
      93           0 :         maTabCtrl.SetTabPageSizePixel( aSiz );
      94           0 :         aCtrlSiz = aSiz;
      95             :     }
      96             : 
      97           0 :     ActivatePageHdl( &maTabCtrl );
      98             : 
      99           0 :     AdjustLayout();
     100           0 : }
     101             : 
     102             : // -----------------------------------------------------------------------
     103             : 
     104           0 : XMLFilterTabDialog::~XMLFilterTabDialog()
     105             : {
     106           0 :     delete mpBasicPage;
     107           0 :     delete mpXSLTPage;
     108           0 :     delete mpNewInfo;
     109           0 : }
     110             : 
     111             : // -----------------------------------------------------------------------
     112             : 
     113           0 : bool XMLFilterTabDialog::onOk()
     114             : {
     115           0 :     mpXSLTPage->FillInfo( mpNewInfo );
     116           0 :     mpBasicPage->FillInfo( mpNewInfo );
     117             : 
     118           0 :     sal_uInt16 nErrorPage = 0;
     119           0 :     sal_uInt16 nErrorId = 0;
     120           0 :     Window* pFocusWindow = NULL;
     121           0 :     OUString aReplace1;
     122           0 :     OUString aReplace2;
     123             : 
     124             :     // 1. see if the filter name is ok
     125           0 :     if( (mpNewInfo->maFilterName.isEmpty()) || (mpNewInfo->maFilterName != mpOldInfo->maFilterName) )
     126             :     {
     127             :         // if the user deleted the filter name, we reset the original filter name
     128           0 :         if( mpNewInfo->maFilterName.isEmpty() )
     129             :         {
     130           0 :             mpNewInfo->maFilterName = mpOldInfo->maFilterName;
     131             :         }
     132             :         else
     133             :         {
     134             :             try
     135             :             {
     136           0 :                 Reference< XNameAccess > xFilterContainer( mxMSF->createInstance( "com.sun.star.document.FilterFactory" ), UNO_QUERY );
     137           0 :                 if( xFilterContainer.is() )
     138             :                 {
     139           0 :                     if( xFilterContainer->hasByName( mpNewInfo->maFilterName ) )
     140             :                     {
     141           0 :                         nErrorPage = RID_XML_FILTER_TABPAGE_BASIC;
     142           0 :                         nErrorId = STR_ERROR_FILTER_NAME_EXISTS;
     143           0 :                         pFocusWindow = &(mpBasicPage->maEDFilterName);
     144           0 :                         aReplace1 = mpNewInfo->maFilterName;
     145             :                     }
     146             : 
     147           0 :                 }
     148             :             }
     149           0 :             catch( const Exception& )
     150             :             {
     151             :                 OSL_FAIL( "XMLFilterTabDialog::onOk exception catched!" );
     152             :             }
     153             :         }
     154             :     }
     155             : 
     156             :     // 2. see if the interface name is ok
     157           0 :     if( (mpNewInfo->maInterfaceName.isEmpty()) || (mpNewInfo->maInterfaceName != mpOldInfo->maInterfaceName) )
     158             :     {
     159             :         // if the user deleted the interface name, we reset the original filter name
     160           0 :         if( mpNewInfo->maInterfaceName.isEmpty() )
     161             :         {
     162           0 :             mpNewInfo->maInterfaceName = mpOldInfo->maInterfaceName;
     163             :         }
     164             :         else
     165             :         {
     166             :             try
     167             :             {
     168           0 :                 Reference< XNameAccess > xFilterContainer( mxMSF->createInstance( "com.sun.star.document.FilterFactory" ), UNO_QUERY );
     169           0 :                 if( xFilterContainer.is() )
     170             :                 {
     171           0 :                     Sequence< OUString > aFilterNames( xFilterContainer->getElementNames() );
     172           0 :                     OUString* pFilterName = aFilterNames.getArray();
     173             : 
     174           0 :                     const sal_Int32 nCount = aFilterNames.getLength();
     175             :                     sal_Int32 nFilter;
     176             : 
     177           0 :                     Sequence< PropertyValue > aValues;
     178           0 :                     for( nFilter = 0; (nFilter < nCount) && (nErrorId == 0); nFilter++, pFilterName++ )
     179             :                     {
     180           0 :                         Any aAny( xFilterContainer->getByName( *pFilterName ) );
     181           0 :                         if( !(aAny >>= aValues) )
     182           0 :                             continue;
     183             : 
     184           0 :                         const sal_Int32 nValueCount( aValues.getLength() );
     185           0 :                         PropertyValue* pValues = aValues.getArray();
     186             :                         sal_Int32 nValue;
     187             : 
     188           0 :                         for( nValue = 0; (nValue < nValueCount) && (nErrorId == 0); nValue++, pValues++ )
     189             :                         {
     190           0 :                             if ( pValues->Name == "UIName" )
     191             :                             {
     192           0 :                                 OUString aInterfaceName;
     193           0 :                                 pValues->Value >>= aInterfaceName;
     194           0 :                                 if( aInterfaceName == mpNewInfo->maInterfaceName )
     195             :                                 {
     196           0 :                                     nErrorPage = RID_XML_FILTER_TABPAGE_BASIC;
     197           0 :                                     nErrorId = STR_ERROR_TYPE_NAME_EXISTS;
     198           0 :                                     pFocusWindow = &(mpBasicPage->maEDInterfaceName);
     199           0 :                                     aReplace1 = mpNewInfo->maInterfaceName;
     200           0 :                                     aReplace2 = *pFilterName;
     201           0 :                                 }
     202             :                             }
     203             :                         }
     204           0 :                     }
     205           0 :                 }
     206             :             }
     207           0 :             catch( const Exception& )
     208             :             {
     209             :                 OSL_FAIL( "XMLFilterTabDialog::onOk exception catched!" );
     210             :             }
     211             :         }
     212             :     }
     213             : 
     214           0 :     if( 0 == nErrorId )
     215             :     {
     216             :         // 4. see if the export xslt is valid
     217           0 :         if( (mpNewInfo->maExportXSLT != mpOldInfo->maExportXSLT) && isFileURL( mpNewInfo->maExportXSLT ) )
     218             :         {
     219           0 :             osl::File aFile( mpNewInfo->maExportXSLT );
     220           0 :             osl::File::RC aRC = aFile.open( osl_File_OpenFlag_Read );
     221           0 :             if( aRC != osl::File::E_None )
     222             :             {
     223           0 :                 nErrorId = STR_ERROR_EXPORT_XSLT_NOT_FOUND;
     224           0 :                 nErrorPage = RID_XML_FILTER_TABPAGE_XSLT;
     225           0 :                 pFocusWindow = &(mpXSLTPage->maEDExportXSLT);
     226           0 :             }
     227             :         }
     228             :     }
     229             : 
     230           0 :     if( 0 == nErrorId )
     231             :     {
     232             :         // 5. see if the import xslt is valid
     233           0 :         if( (mpNewInfo->maImportXSLT != mpOldInfo->maImportXSLT) && isFileURL( mpNewInfo->maImportXSLT ) )
     234             :         {
     235           0 :             osl::File aFile( mpNewInfo->maImportXSLT );
     236           0 :             osl::File::RC aRC = aFile.open( osl_File_OpenFlag_Read );
     237           0 :             if( aRC != osl::File::E_None )
     238             :             {
     239           0 :                 nErrorId = STR_ERROR_IMPORT_XSLT_NOT_FOUND;
     240           0 :                 nErrorPage = RID_XML_FILTER_TABPAGE_XSLT;
     241           0 :                 pFocusWindow = &(mpXSLTPage->maEDImportTemplate);
     242           0 :             }
     243             :         }
     244             :     }
     245             : 
     246             :     // see if we have at least an import or an export xslt
     247           0 :     if((mpNewInfo->maImportXSLT.isEmpty()) && (mpNewInfo->maExportXSLT.isEmpty()) )
     248             :     {
     249           0 :         nErrorId = STR_ERROR_EXPORT_XSLT_NOT_FOUND;
     250           0 :         nErrorPage = RID_XML_FILTER_TABPAGE_XSLT;
     251           0 :         pFocusWindow = &(mpXSLTPage->maEDExportXSLT);
     252             :     }
     253             : 
     254           0 :     if( 0 == nErrorId )
     255             :     {
     256             :         // 6. see if the import template is valid
     257           0 :         if( (mpNewInfo->maImportTemplate != mpOldInfo->maImportTemplate) && isFileURL( mpNewInfo->maImportTemplate ) )
     258             :         {
     259           0 :             osl::File aFile( mpNewInfo->maImportTemplate );
     260           0 :             osl::File::RC aRC = aFile.open( osl_File_OpenFlag_Read );
     261           0 :             if( aRC != osl::File::E_None )
     262             :             {
     263           0 :                 nErrorId = STR_ERROR_IMPORT_TEMPLATE_NOT_FOUND;
     264           0 :                 nErrorPage = RID_XML_FILTER_TABPAGE_XSLT;
     265           0 :                 pFocusWindow = &(mpXSLTPage->maEDImportTemplate);
     266           0 :             }
     267             :         }
     268             :     }
     269             : 
     270           0 :     if( 0 != nErrorId )
     271             :     {
     272           0 :         maTabCtrl.SetCurPageId( (sal_uInt16)nErrorPage );
     273           0 :         ActivatePageHdl( &maTabCtrl );
     274             : 
     275           0 :         ResId aResId( nErrorId, mrResMgr );
     276           0 :         OUString aMessage( aResId );
     277             : 
     278           0 :         if( aReplace2.getLength() )
     279             :         {
     280           0 :             aMessage = aMessage.replaceAll( "%s1", aReplace1 );
     281           0 :             aMessage = aMessage.replaceAll( "%s2", aReplace2 );
     282             :         }
     283           0 :         else if( aReplace1.getLength() )
     284             :         {
     285           0 :             aMessage = aMessage.replaceAll( "%s", aReplace1 );
     286             :         }
     287             : 
     288           0 :         ErrorBox aBox(this, (WinBits)(WB_OK), aMessage );
     289           0 :         aBox.Execute();
     290             : 
     291           0 :         if( pFocusWindow )
     292           0 :             pFocusWindow->GrabFocus();
     293             : 
     294           0 :         return false;
     295             :     }
     296             :     else
     297             :     {
     298           0 :         return true;
     299           0 :     }
     300             : }
     301             : 
     302             : // -----------------------------------------------------------------------
     303             : 
     304           0 : filter_info_impl* XMLFilterTabDialog::getNewFilterInfo() const
     305             : {
     306           0 :     return mpNewInfo;
     307             : }
     308             : 
     309             : // -----------------------------------------------------------------------
     310             : 
     311           0 : IMPL_LINK_NOARG(XMLFilterTabDialog, OkHdl)
     312             : {
     313           0 :     if( onOk() )
     314           0 :         EndDialog(1);
     315             : 
     316           0 :     return 0;
     317             : }
     318             : 
     319             : // -----------------------------------------------------------------------
     320             : 
     321           0 : IMPL_LINK( XMLFilterTabDialog, ActivatePageHdl, TabControl *, pTabCtrl )
     322             : {
     323           0 :     const sal_uInt16 nId = pTabCtrl->GetCurPageId();
     324           0 :     TabPage* pTabPage = pTabCtrl->GetTabPage( nId );
     325           0 :     pTabPage->Show();
     326             : 
     327           0 :     return 0;
     328             : }
     329             : 
     330             : // -----------------------------------------------------------------------
     331             : 
     332           0 : IMPL_LINK( XMLFilterTabDialog, DeactivatePageHdl, TabControl *, /* pTabCtrl */ )
     333             : {
     334           0 :     return sal_True;
     335           0 : }
     336             : 
     337             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10