LCOV - code coverage report
Current view: top level - sfx2/source/view - orgmgr.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 210 0.0 %
Date: 2012-08-25 Functions: 0 23 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 360 0.0 %

           Branch data     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/embed/XStorage.hpp>
      21                 :            : #include <com/sun/star/embed/XTransactedObject.hpp>
      22                 :            : #include <com/sun/star/embed/ElementModes.hpp>
      23                 :            : 
      24                 :            : #include <vcl/msgbox.hxx>
      25                 :            : #include <tools/urlobj.hxx>
      26                 :            : 
      27                 :            : #include <comphelper/processfactory.hxx>
      28                 :            : #include <unotools/intlwrapper.hxx>
      29                 :            : 
      30                 :            : #include <comphelper/storagehelper.hxx>
      31                 :            : 
      32                 :            : #include <sfx2/app.hxx>
      33                 :            : #include <sfx2/objsh.hxx>
      34                 :            : #include <sfx2/docfile.hxx>
      35                 :            : #include <sfx2/docfac.hxx>
      36                 :            : #include <sfx2/doctempl.hxx>
      37                 :            : #include "docvor.hxx"
      38                 :            : #include "orgmgr.hxx"
      39                 :            : #include "sfxtypes.hxx"
      40                 :            : #include "sfx2/sfxresid.hxx"
      41                 :            : #include "view.hrc"
      42                 :            : #include <sfx2/docfilt.hxx>
      43                 :            : #include "fltfnc.hxx"
      44                 :            : 
      45                 :            : using namespace ::com::sun::star;
      46                 :            : 
      47                 :            : //=========================================================================
      48                 :            : 
      49                 :            : /*  [Description]
      50                 :            : 
      51                 :            :     Implementation class, single entry in the file view.
      52                 :            : */
      53                 :            : 
      54                 :            : struct _FileListEntry
      55                 :            : {
      56                 :            :     String aFileName;           // File Name with complete path
      57                 :            :     String aBaseName;           // File Name
      58                 :            :     const CollatorWrapper* pCollator;
      59                 :            :     SfxObjectShellLock aDocShell; // ObjectShell as reference class
      60                 :            : 
      61                 :            :     sal_Bool bFile;                 // As File on disk
      62                 :            :                                 // (!= not processed, not loaded as document
      63                 :            :                                 // these are not saved!)
      64                 :            :     sal_Bool bOwner;                // self-generated
      65                 :            :     sal_Bool bNoName;
      66                 :            :     sal_Bool bOwnFormat;
      67                 :            : 
      68                 :            :     _FileListEntry( const String& rFileName,
      69                 :            :                     const CollatorWrapper* pColl, const String* pTitle = NULL );
      70                 :            :     ~_FileListEntry();
      71                 :            : 
      72                 :            :     int operator==( const _FileListEntry &rCmp) const;
      73                 :            :     int operator< ( const _FileListEntry &rCmp) const;
      74                 :            :     sal_Bool DeleteObjectShell();
      75                 :            : };
      76                 :            : 
      77                 :            : //-------------------------------------------------------------------------
      78                 :            : 
      79                 :            : inline int _FileListEntry::operator==(const _FileListEntry &rCmp) const
      80                 :            : {
      81                 :            :     DBG_ASSERT( pCollator, "invalid CollatorWrapper" );
      82                 :            :     return COMPARE_EQUAL == pCollator->compareString(aBaseName, rCmp.aBaseName);
      83                 :            : }
      84                 :            : 
      85                 :            : //-------------------------------------------------------------------------
      86                 :            : 
      87                 :          0 : inline int _FileListEntry::operator< (const _FileListEntry &rCmp) const
      88                 :            : {
      89                 :            :     DBG_ASSERT( pCollator, "invalid CollatorWrapper" );
      90 [ #  # ][ #  # ]:          0 :     return COMPARE_LESS == pCollator->compareString(aBaseName, rCmp.aBaseName);
      91                 :            : }
      92                 :            : 
      93                 :            : //-------------------------------------------------------------------------
      94                 :            : 
      95                 :          0 : _FileListEntry::_FileListEntry( const String& rFileName,
      96                 :            :                                 const CollatorWrapper* pColl, const String* pTitle ) :
      97                 :            : 
      98                 :            :     aFileName   ( rFileName ),
      99                 :            :     pCollator   ( pColl ),
     100                 :            :     bFile       ( sal_False ),
     101                 :            :     bOwner      ( sal_False ),
     102                 :            :     bNoName     ( sal_True ),
     103         [ #  # ]:          0 :     bOwnFormat  ( sal_True )
     104                 :            : {
     105         [ #  # ]:          0 :     if ( pTitle )
     106         [ #  # ]:          0 :         aBaseName = *pTitle;
     107                 :            :     else
     108                 :            :     {
     109 [ #  # ][ #  # ]:          0 :         INetURLObject aObj( rFileName, INET_PROT_FILE );
     110                 :            :         aBaseName = aObj.getName( INetURLObject::LAST_SEGMENT, true,
     111 [ #  # ][ #  # ]:          0 :                                   INetURLObject::DECODE_WITH_CHARSET );
                 [ #  # ]
     112                 :            :     }
     113                 :          0 : }
     114                 :            : 
     115                 :            : //-------------------------------------------------------------------------
     116                 :            : 
     117 [ #  # ][ #  # ]:          0 : _FileListEntry::~_FileListEntry()
     118                 :            : {
     119         [ #  # ]:          0 :     DeleteObjectShell();
     120                 :          0 : }
     121                 :            : 
     122                 :            : //=========================================================================
     123                 :            : 
     124                 :          0 : sal_Bool _FileListEntry::DeleteObjectShell()
     125                 :            : 
     126                 :            : /*  [Description]
     127                 :            : 
     128                 :            :     Release of ther DocumentShell
     129                 :            : 
     130                 :            :     [Return value]          TRUE: Everything is ok
     131                 :            :                             FALSE: An error occured
     132                 :            :                             (the document could not be saved)
     133                 :            : */
     134                 :            : 
     135                 :            : {
     136                 :          0 :     sal_Bool bRet = sal_True;
     137                 :            : 
     138 [ #  # ][ #  # ]:          0 :     if(bOwner && aDocShell.Is() && aDocShell->IsModified())
         [ #  # ][ #  # ]
     139                 :            :     {
     140                 :            :         // Converted?
     141         [ #  # ]:          0 :         if( bOwnFormat )
     142                 :            :         {
     143         [ #  # ]:          0 :             if(!aDocShell->Save() )
     144                 :          0 :                 bRet = sal_False;
     145                 :            :             else
     146                 :            :             {
     147                 :            :                 try {
     148 [ #  # ][ #  # ]:          0 :                     uno::Reference< embed::XTransactedObject > xTransact( aDocShell->GetStorage(), uno::UNO_QUERY );
     149                 :            :                     OSL_ENSURE( xTransact.is(), "Storage must implement XTransactedObject!\n" );
     150         [ #  # ]:          0 :                     if ( !xTransact.is() )
     151         [ #  # ]:          0 :                         throw uno::RuntimeException();
     152                 :            : 
     153 [ #  # ][ #  # ]:          0 :                     xTransact->commit();
                 [ #  # ]
     154                 :            :                 }
     155                 :          0 :                 catch( uno::Exception& )
     156                 :            :                 {
     157                 :            :                 }
     158                 :            : 
     159                 :            :             }
     160                 :            :         }
     161                 :            :         else
     162                 :            :         {
     163                 :            :             // If converted save in native format
     164 [ #  # ][ #  # ]:          0 :             INetURLObject aObj( aFileName );
     165                 :            :             String aTitle = aObj.getName( INetURLObject::LAST_SEGMENT, true,
     166 [ #  # ][ #  # ]:          0 :                                           INetURLObject::DECODE_WITH_CHARSET );
     167                 :            :             bRet = aDocShell->PreDoSaveAs_Impl(
     168 [ #  # ][ #  # ]:          0 :                         aTitle, aDocShell->GetFactory().GetFilterContainer()->GetAnyFilter( SFX_FILTER_IMPORT | SFX_FILTER_EXPORT )->GetFilterName(), 0 );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     169                 :            :         }
     170                 :            :     }
     171                 :            : 
     172         [ #  # ]:          0 :     if( bOwner)
     173                 :            :     {
     174                 :          0 :         aDocShell.Clear();
     175                 :            :     }
     176                 :            : 
     177                 :          0 :     return bRet;
     178                 :            : }
     179                 :            : 
     180                 :            : //-------------------------------------------------------------------------
     181                 :            : 
     182                 :          0 : SfxObjectList::SfxObjectList()
     183                 :            : {
     184                 :          0 : }
     185                 :            : 
     186                 :            : //-------------------------------------------------------------------------
     187                 :            : 
     188                 :          0 : SfxObjectList::~SfxObjectList()
     189                 :            : {
     190 [ #  # ][ #  # ]:          0 :     for( const_iterator it = begin(); it != end(); ++it )
     191 [ #  # ][ #  # ]:          0 :         delete *it;
     192                 :          0 :     clear();
     193                 :          0 : }
     194                 :            : 
     195                 :            : //-------------------------------------------------------------------------
     196                 :            : 
     197                 :          0 : const String &SfxObjectList::GetBaseName(const _FileListEntry* p) const
     198                 :            : {
     199                 :          0 :     return p->aBaseName;
     200                 :            : }
     201                 :            : 
     202                 :            : //-------------------------------------------------------------------------
     203                 :            : 
     204                 :          0 : SfxOrganizeMgr::SfxOrganizeMgr( SfxOrganizeListBox_Impl *pLeft,
     205                 :            :                                 SfxOrganizeListBox_Impl *pRight,
     206                 :            :                                 SfxDocumentTemplates *pTempl) :
     207                 :          0 :     pImpl(new SfxOrganizeMgr_Impl),
     208         [ #  # ]:          0 :     pTemplates(pTempl? pTempl: new SfxDocumentTemplates),
     209                 :            :     pLeftBox(pLeft),
     210                 :            :     pRightBox(pRight),
     211                 :            :     bDeleteTemplates(pTempl == 0),
     212         [ #  # ]:          0 :     bModified(0)
     213                 :            : 
     214                 :            : /*  [Description]
     215                 :            : 
     216                 :            :     Constructor. The current document is added to the list of documents.
     217                 :            : */
     218                 :            : {
     219         [ #  # ]:          0 :     pImpl->pDocList = new SfxObjectList;
     220 [ #  # ][ #  # ]:          0 :     pImpl->pIntlWrapper = new IntlWrapper( ::comphelper::getProcessServiceFactory(), Application::GetSettings().GetLocale() );
         [ #  # ][ #  # ]
     221                 :          0 :     const CollatorWrapper* pCollator = pImpl->pIntlWrapper->getCaseCollator();
     222         [ #  # ]:          0 :     for ( SfxObjectShell* pTmp = SfxObjectShell::GetFirst(); pTmp; pTmp = SfxObjectShell::GetNext(*pTmp) )
     223                 :            :     {
     224 [ #  # ][ #  # ]:          0 :         if ( pTmp->GetCreateMode() != SFX_CREATE_MODE_STANDARD ||
         [ #  # ][ #  # ]
     225 [ #  # ][ #  # ]:          0 :              !( pTmp->GetFlags() & SFXOBJECTSHELL_HASOPENDOC ) || !pTmp->GetStyleSheetPool() )
     226                 :          0 :             continue;
     227                 :          0 :         _FileListEntry* pNewEntry = NULL;
     228         [ #  # ]:          0 :         String aTitle = pTmp->GetTitle( SFX_TITLE_TITLE );
     229 [ #  # ][ #  # ]:          0 :         pNewEntry = new _FileListEntry( pTmp->GetMedium()->GetName(), pCollator, &aTitle );
         [ #  # ][ #  # ]
                 [ #  # ]
     230         [ #  # ]:          0 :         pNewEntry->aDocShell = pTmp;
     231         [ #  # ]:          0 :         pImpl->pDocList->insert( pNewEntry );
     232         [ #  # ]:          0 :     }
     233                 :          0 : }
     234                 :            : 
     235                 :            : //-------------------------------------------------------------------------
     236                 :            : 
     237                 :          0 : SfxOrganizeMgr::~SfxOrganizeMgr()
     238                 :            : {
     239         [ #  # ]:          0 :     if ( bDeleteTemplates )
     240         [ #  # ]:          0 :         delete pTemplates;
     241         [ #  # ]:          0 :     delete pImpl->pDocList;
     242         [ #  # ]:          0 :     delete pImpl->pIntlWrapper;
     243                 :          0 :     delete pImpl;
     244                 :          0 :     pLeftBox = pRightBox = NULL;
     245                 :          0 : }
     246                 :            : 
     247                 :            : //-------------------------------------------------------------------------
     248                 :            : 
     249                 :          0 : SfxObjectShellRef SfxOrganizeMgr::CreateObjectShell( sal_uInt16 nIdx )
     250                 :            : 
     251                 :            : /*  [Description]
     252                 :            : 
     253                 :            :     Access to the DocumentShell at the position nIdx.
     254                 :            : 
     255                 :            :     [Return value]                      Reference to the DocumentShell
     256                 :            : 
     257                 :            : */
     258                 :            : 
     259                 :            : {
     260                 :          0 :     _FileListEntry* pEntry = (*pImpl->pDocList)[nIdx];
     261                 :            :     // otherwise create Doc-Shell
     262         [ #  # ]:          0 :     if ( !pEntry->aDocShell.Is() )
     263                 :            :     {
     264 [ #  # ][ #  # ]:          0 :         INetURLObject aFileObj( pEntry->aFileName );
     265                 :          0 :         sal_Bool bDum = sal_False;
     266         [ #  # ]:          0 :         SfxApplication* pSfxApp = SFX_APP();
     267 [ #  # ][ #  # ]:          0 :         String aFilePath = aFileObj.GetMainURL( INetURLObject::NO_DECODE );
     268 [ #  # ][ #  # ]:          0 :         pEntry->aDocShell = pSfxApp->DocAlreadyLoaded( aFilePath, sal_False, bDum );
                 [ #  # ]
     269         [ #  # ]:          0 :         if ( !pEntry->aDocShell.Is() )
     270                 :            :         {
     271                 :          0 :             pEntry->bOwner = sal_True;
     272                 :            :             SfxMedium* pMed = new SfxMedium(
     273 [ #  # ][ #  # ]:          0 :                 aFilePath, ( STREAM_READ | STREAM_SHARE_DENYWRITE ) );
     274                 :          0 :             const SfxFilter* pFilter = NULL;
     275         [ #  # ]:          0 :             pMed->UseInteractionHandler(sal_True);
     276         [ #  # ]:          0 :             if (
           [ #  #  #  # ]
           [ #  #  #  # ]
                 [ #  # ]
     277 [ #  # ][ #  # ]:          0 :                 pSfxApp->GetFilterMatcher().GuessFilter(*pMed, &pFilter, SFX_FILTER_TEMPLATE, 0) ||
     278                 :          0 :                 (pFilter && !pFilter->IsOwnFormat()) ||
     279                 :          0 :                 (pFilter && !pFilter->UsesStorage())
     280                 :            :                )
     281                 :            :             {
     282         [ #  # ]:          0 :                 pSfxApp->LoadTemplate( pEntry->aDocShell, aFilePath );
     283                 :          0 :                 pEntry->bOwnFormat = sal_False;
     284 [ #  # ][ #  # ]:          0 :                 delete pMed;
     285         [ #  # ]:          0 :                 if ( pEntry->aDocShell.Is() )
     286                 :          0 :                     return (SfxObjectShellRef)(SfxObjectShell*)(pEntry->aDocShell);
     287                 :            :             }
     288                 :            :             else
     289                 :            :             {
     290         [ #  # ]:          0 :                 if ( pFilter )
     291                 :            :                 {
     292                 :          0 :                     pEntry->bOwnFormat = sal_True;
     293 [ #  # ][ #  # ]:          0 :                     pEntry->aDocShell = SfxObjectShell::CreateObject( pFilter->GetServiceName(), SFX_CREATE_MODE_ORGANIZER );
         [ #  # ][ #  # ]
     294         [ #  # ]:          0 :                     if ( pEntry->aDocShell.Is() )
     295                 :            :                     {
     296         [ #  # ]:          0 :                         pEntry->aDocShell->DoInitNew(0);
     297         [ #  # ]:          0 :                         pEntry->aDocShell->LoadFrom( *pMed );
     298                 :            :                         // Medium is now owned by DocShell
     299         [ #  # ]:          0 :                         pEntry->aDocShell->DoSaveCompleted( pMed );
     300                 :            :                     }
     301                 :            :                 }
     302                 :            :             }
     303 [ #  # ][ #  # ]:          0 :         }
         [ #  # ][ #  # ]
     304                 :            :     }
     305                 :          0 :     return ( SfxObjectShellRef )(SfxObjectShell*)(pEntry->aDocShell);
     306                 :            : }
     307                 :            : 
     308                 :            : //-------------------------------------------------------------------------
     309                 :            : 
     310                 :          0 : sal_Bool SfxOrganizeMgr::DeleteObjectShell(sal_uInt16 nIdx)
     311                 :            : 
     312                 :            : /*  [Description]
     313                 :            : 
     314                 :            :     Release DocumentShell at position nIdx
     315                 :            : 
     316                 :            :     [Return value]          TRUE: Everything is ok
     317                 :            :                             FALSE: An error occured
     318                 :            :                             (the document could not be saved)
     319                 :            : */
     320                 :            : {
     321                 :          0 :     return (*pImpl->pDocList)[nIdx]->DeleteObjectShell();
     322                 :            : }
     323                 :            : 
     324                 :            : //-------------------------------------------------------------------------
     325                 :            : 
     326                 :          0 : SfxObjectShellRef SfxOrganizeMgr::CreateObjectShell(sal_uInt16 nRegion,
     327                 :            :                                                         sal_uInt16 nIdx)
     328                 :            : /*  [Description]
     329                 :            : 
     330                 :            :     Access to the  DocumentShell at Position nIdx in Region
     331                 :            :     nRegion (Document template)
     332                 :            : 
     333                 :            :     [Return value]                      Reference to the DocumentShell
     334                 :            : 
     335                 :            : */
     336                 :            : {
     337                 :          0 :     return pTemplates->CreateObjectShell(nRegion, nIdx);
     338                 :            : }
     339                 :            : 
     340                 :            : //-------------------------------------------------------------------------
     341                 :            : 
     342                 :          0 : sal_Bool SfxOrganizeMgr::DeleteObjectShell(sal_uInt16 nRegion, sal_uInt16 nIdx)
     343                 :            : 
     344                 :            : /*  [Description]
     345                 :            : 
     346                 :            :     Release of the DocumentShell at Position nIdx in Region
     347                 :            :     nRegion (Document template)
     348                 :            : 
     349                 :            :     [Return value]          TRUE: Everything is ok
     350                 :            :                             FALSE: An error occured
     351                 :            :                             (the document could not be saved)
     352                 :            : */
     353                 :            : 
     354                 :            : {
     355                 :          0 :     return pTemplates->DeleteObjectShell(nRegion, nIdx);
     356                 :            : }
     357                 :            : 
     358                 :            : //-------------------------------------------------------------------------
     359                 :            : 
     360                 :          0 : sal_Bool    SfxOrganizeMgr::Copy(sal_uInt16 nTargetRegion,
     361                 :            :                             sal_uInt16 nTargetIdx,
     362                 :            :                             sal_uInt16 nSourceRegion,
     363                 :            :                             sal_uInt16 nSourceIdx)
     364                 :            : 
     365                 :            : /*  [Description]
     366                 :            : 
     367                 :            :     Copy of a Document Template
     368                 :            : 
     369                 :            :     [Parameter]
     370                 :            : 
     371                 :            :     sal_uInt16 nTargetRegion                Index of the Target Region
     372                 :            :     sal_uInt16 nTargetIdx                   Index of the Target Position
     373                 :            :     sal_uInt16 nSourceRegion                Index of the Source Region
     374                 :            :     sal_uInt16 nSourceIdx                   Index of the template to be
     375                 :            :                                         copied/moved.
     376                 :            : 
     377                 :            :     [Return value]                      Success (TRUE) or Failure (FALSE)
     378                 :            : 
     379                 :            : 
     380                 :            :     [Cross-reference]
     381                 :            : 
     382                 :            :     <SfxDocumentTemplates::Copy(sal_uInt16 nTargetRegion,
     383                 :            :                                 sal_uInt16 nTargetIdx,
     384                 :            :                                 sal_uInt16 nSourceRegion,
     385                 :            :                                 sal_uInt16 nSourceIdx)>
     386                 :            : 
     387                 :            : */
     388                 :            : 
     389                 :            : {
     390         [ #  # ]:          0 :     if(nSourceIdx == USHRT_MAX) // No directories copied
     391                 :          0 :         return sal_False ;
     392                 :            :     const sal_Bool bOk = pTemplates->Copy(nTargetRegion, nTargetIdx,
     393                 :          0 :                                         nSourceRegion, nSourceIdx);
     394         [ #  # ]:          0 :     if(bOk)
     395                 :          0 :         bModified = 1;
     396                 :          0 :     return bOk;
     397                 :            : }
     398                 :            : 
     399                 :            : //-------------------------------------------------------------------------
     400                 :            : 
     401                 :          0 : sal_Bool    SfxOrganizeMgr::Move(sal_uInt16 nTargetRegion,
     402                 :            :                             sal_uInt16 nTargetIdx,
     403                 :            :                             sal_uInt16 nSourceRegion,
     404                 :            :                             sal_uInt16 nSourceIdx)
     405                 :            : 
     406                 :            : /*  [Description]
     407                 :            : 
     408                 :            :     Moving a template
     409                 :            : 
     410                 :            :     [Parameter]
     411                 :            : 
     412                 :            :     sal_uInt16 nTargetRegion                Index of the Target Region
     413                 :            :     sal_uInt16 nTargetIdx                   Index of the Target Position
     414                 :            :     sal_uInt16 nSourceRegion                Index of the Source Region
     415                 :            :     sal_uInt16 nSourceIdx                   Index of the template to be
     416                 :            :                                         copied/moved.
     417                 :            : 
     418                 :            :     [Return value]                      Success (TRUE) or Failure (FALSE)
     419                 :            : 
     420                 :            :     [Cross-reference]
     421                 :            : 
     422                 :            :     <SfxDocumentTemplates::Move(sal_uInt16 nTargetRegion,
     423                 :            :                                 sal_uInt16 nTargetIdx,
     424                 :            :                                 sal_uInt16 nSourceRegion,
     425                 :            :                                 sal_uInt16 nSourceIdx)>
     426                 :            : */
     427                 :            : 
     428                 :            : {
     429         [ #  # ]:          0 :     if(nSourceIdx == USHRT_MAX) // No directory moved
     430                 :          0 :         return sal_False ;
     431                 :            :     const sal_Bool bOk = pTemplates->Move(nTargetRegion, nTargetIdx,
     432                 :          0 :                                         nSourceRegion, nSourceIdx);
     433         [ #  # ]:          0 :     if(bOk)
     434                 :          0 :         bModified = 1;
     435                 :          0 :     return bOk;
     436                 :            : }
     437                 :            : 
     438                 :            : //-------------------------------------------------------------------------
     439                 :            : 
     440                 :          0 : sal_Bool    SfxOrganizeMgr::Delete(SfxOrganizeListBox_Impl *pCaller,
     441                 :            :                                 sal_uInt16 nRegion, sal_uInt16 nIdx)
     442                 :            : 
     443                 :            : /*  [Description]
     444                 :            : 
     445                 :            :     Delete  a Document Template
     446                 :            : 
     447                 :            :     [Parameter]
     448                 :            : 
     449                 :            :     SfxOrganizeListBox *pCaller     calling ListBox, since this event
     450                 :            :                                     is triggered by the menu or the
     451                 :            :                                     keyboard, the ListBox must be updated.
     452                 :            :     sal_uInt16 nRegion                  Index for Region
     453                 :            :     sal_uInt16 nIdx                     Index of Document template
     454                 :            : 
     455                 :            :     [Return value]                  Success (TRUE) or Failure (FALSE)
     456                 :            : 
     457                 :            :     [Cross-reference]
     458                 :            : 
     459                 :            :     <SfxDocumentTemplates::Delete(sal_uInt16 nRegion, sal_uInt16 nIdx)>
     460                 :            : 
     461                 :            : */
     462                 :            : 
     463                 :            : {
     464                 :          0 :     sal_Bool bOk = sal_False;
     465                 :            : 
     466         [ #  # ]:          0 :     if ( USHRT_MAX == nIdx )
     467                 :            :     {
     468                 :            :         // deleting of a group
     469                 :            : 
     470                 :          0 :         SvLBoxEntry *pGroupToDelete = pCaller->SvLBox::GetEntry(nRegion);
     471         [ #  # ]:          0 :         if ( pGroupToDelete )
     472                 :            :         {
     473         [ #  # ]:          0 :             sal_uInt16 nItemNum = (sal_uInt16)( pCaller->GetModel()->GetChildCount( pGroupToDelete ) );
     474                 :            :             typedef std::deque<SvLBoxEntry*> BoxEntries;
     475         [ #  # ]:          0 :             BoxEntries pEntriesToDelete;
     476                 :            : 
     477                 :          0 :             sal_uInt16 nInd = 0;
     478         [ #  # ]:          0 :             for ( nInd = 0; nInd < nItemNum; nInd++ )
     479                 :            :             {
     480                 :            :                 // TODO/LATER: check that nInd is the same index that is used in pTemplates
     481 [ #  # ][ #  # ]:          0 :                 if ( pTemplates->Delete( nRegion, nInd ) )
     482                 :            :                 {
     483                 :          0 :                     bModified = 1;
     484 [ #  # ][ #  # ]:          0 :                     pEntriesToDelete.push_back( pCaller->SvLBox::GetEntry( pGroupToDelete, nInd ) );
     485                 :            :                 }
     486                 :            :             }
     487                 :            : 
     488 [ #  # ][ #  # ]:          0 :             for ( BoxEntries::const_iterator aIt( pEntriesToDelete.begin() ), aEnd( pEntriesToDelete.end() ); aIt != aEnd; ++aIt )
         [ #  # ][ #  # ]
                 [ #  # ]
     489 [ #  # ][ #  # ]:          0 :                 pCaller->GetModel()->Remove( *aIt );
     490                 :            : 
     491 [ #  # ][ #  # ]:          0 :             if ( !pCaller->GetModel()->GetChildCount( pGroupToDelete ) )
     492                 :            :             {
     493         [ #  # ]:          0 :                 bOk = pTemplates->Delete( nRegion, nIdx );
     494         [ #  # ]:          0 :                 if ( bOk )
     495         [ #  # ]:          0 :                     pCaller->GetModel()->Remove( pGroupToDelete );
     496                 :          0 :             }
     497                 :            :         }
     498                 :            :     }
     499                 :            :     else
     500                 :            :     {
     501                 :            :         // deleting of a template
     502                 :          0 :         bOk = pTemplates->Delete(nRegion, nIdx);
     503         [ #  # ]:          0 :         if(bOk)
     504                 :            :         {
     505                 :          0 :             bModified = 1;
     506                 :            :                 // Entry to be deleted.
     507                 :          0 :             SvLBoxEntry *pEntryToDelete = pCaller->SvLBox::GetEntry(pCaller->SvLBox::GetEntry(nRegion), nIdx);
     508                 :            : 
     509                 :          0 :             pCaller->GetModel()->Remove(pEntryToDelete);
     510                 :            :         }
     511                 :            :     }
     512                 :            : 
     513                 :          0 :     return bOk;
     514                 :            : }
     515                 :            : 
     516                 :            : //-------------------------------------------------------------------------
     517                 :            : 
     518                 :          0 : sal_Bool    SfxOrganizeMgr::InsertDir
     519                 :            : (
     520                 :            :     SfxOrganizeListBox_Impl* pCaller, /* calling ListBox, since this event
     521                 :            :                                          is triggered by the menu or the
     522                 :            :                                          keyboard, the ListBox must be updated. */
     523                 :            :     const String&            rText,   // logical Name of Region
     524                 :            :     sal_uInt16                   nRegion  // Index of Region
     525                 :            : )
     526                 :            : 
     527                 :            : /*  [Description]
     528                 :            : 
     529                 :            :     Insert Region.
     530                 :            : 
     531                 :            :     [Return value]                  Success (TRUE) or Failure (FALSE)
     532                 :            : 
     533                 :            :     [Cross-reference]
     534                 :            : 
     535                 :            :     <SfxDocumentTemplates::InsertDir(const String &, sal_uInt16 nRegion)>
     536                 :            : */
     537                 :            : 
     538                 :            : {
     539                 :          0 :     const sal_Bool bOk = pTemplates->InsertDir(rText, nRegion);
     540         [ #  # ]:          0 :     if(bOk)
     541                 :            :     {
     542                 :          0 :         bModified = 1;
     543                 :            :         SvLBoxEntry *pEntry = pCaller->InsertEntry(rText,
     544                 :          0 :                                                    pCaller->GetOpenedBmp(0),
     545                 :          0 :                                                    pCaller->GetClosedBmp(0),
     546                 :          0 :                                                    0, sal_True, nRegion);
     547                 :          0 :         pCaller->Update();
     548                 :          0 :         pCaller->EditEntry(pEntry);
     549                 :            :     }
     550                 :          0 :     return bOk;
     551                 :            : }
     552                 :            : 
     553                 :            : //-------------------------------------------------------------------------
     554                 :            : 
     555                 :          0 : sal_Bool SfxOrganizeMgr::SetName(const String &rName,
     556                 :            :                              sal_uInt16 nRegion, sal_uInt16 nIdx)
     557                 :            : 
     558                 :            : /*  [Description]
     559                 :            : 
     560                 :            :     Set (logical) Name
     561                 :            : 
     562                 :            :     [Parameter]
     563                 :            : 
     564                 :            :     const String &rName             The new Name
     565                 :            :     sal_uInt16 nRegion                  Index of Region
     566                 :            :     sal_uInt16 nIdx                     Index of Document template
     567                 :            : 
     568                 :            :     [Return value]                  Success (TRUE) or Failure (FALSE)
     569                 :            : 
     570                 :            :     [Cross-reference]
     571                 :            : 
     572                 :            :     <SfxDocumentTemplates::SetName(const String &, sal_uInt16 nRegion, sal_uInt16 nIdx)>
     573                 :            : */
     574                 :            : 
     575                 :            : {
     576                 :          0 :     const sal_Bool bOk = pTemplates->SetName(rName, nRegion, nIdx);
     577         [ #  # ]:          0 :     if(bOk)
     578                 :          0 :         bModified = 1;
     579                 :          0 :     return bOk;
     580                 :            : }
     581                 :            : 
     582                 :            : //-------------------------------------------------------------------------
     583                 :            : 
     584                 :          0 : sal_Bool SfxOrganizeMgr::CopyTo(sal_uInt16 nRegion, sal_uInt16 nIdx, const String &rName) const
     585                 :            : 
     586                 :            : /*  [Description]
     587                 :            : 
     588                 :            :     Export of a Template
     589                 :            : 
     590                 :            :     [Parameter]
     591                 :            : 
     592                 :            :     sal_uInt16 nRegion                  Index of Region
     593                 :            :     sal_uInt16 nIdx                     Index of Document Template
     594                 :            :     const String &rName             File name
     595                 :            : 
     596                 :            :     [Return value]                  Success (TRUE) or Failure (FALSE)
     597                 :            : 
     598                 :            :     [Cross-reference]
     599                 :            : 
     600                 :            :     <SfxDocumentTemplates::CopyTo( sal_uInt16 nRegion, sal_uInt16 nIdx, const String &)>
     601                 :            : */
     602                 :            : 
     603                 :            : {
     604                 :          0 :     return pTemplates->CopyTo(nRegion, nIdx, rName);
     605                 :            : }
     606                 :            : 
     607                 :            : //-------------------------------------------------------------------------
     608                 :            : 
     609                 :          0 : sal_Bool SfxOrganizeMgr::CopyFrom(SfxOrganizeListBox_Impl *pCaller,
     610                 :            :                               sal_uInt16 nRegion, sal_uInt16 nIdx, String &rName)
     611                 :            : 
     612                 :            : /*  [Description]
     613                 :            : 
     614                 :            :     Import of Document Template
     615                 :            : 
     616                 :            :     [Parameter]
     617                 :            : 
     618                 :            :     SfxOrganizeListBox *pCaller     calling ListBox, since this event
     619                 :            :                                     is triggered by the menu or the
     620                 :            :                                     keyboard, the ListBox must be updated.
     621                 :            : 
     622                 :            :     sal_uInt16 nRegion                  Index of Region
     623                 :            :     sal_uInt16 nIdx                     Index of Document Template
     624                 :            :     String &rName                   File name
     625                 :            : 
     626                 :            :     [Return value]                  Success (TRUE) or Failure (FALSE)
     627                 :            : 
     628                 :            :     [Cross-reference]
     629                 :            : 
     630                 :            :     <SfxDocumentTemplates::CopyFrom( sal_uInt16 nRegion, sal_uInt16 nIdx, const String &)>
     631                 :            : */
     632                 :            : 
     633                 :            : {
     634                 :          0 :     SvLBoxEntry *pParent = pCaller->FirstSelected();
     635         [ #  # ]:          0 :     if( nIdx!=USHRT_MAX )
     636                 :          0 :         pParent = pCaller->GetParent(pParent);
     637         [ #  # ]:          0 :     if( pTemplates->CopyFrom( nRegion, nIdx, rName ) )
     638                 :            :     {
     639                 :            :         // Update pCaller
     640         [ #  # ]:          0 :         if( nIdx == USHRT_MAX )
     641                 :          0 :             nIdx = 0;
     642                 :          0 :         else nIdx++;
     643                 :            : 
     644                 :            :         pCaller->InsertEntry( rName,
     645                 :          0 :                               pCaller->GetOpenedBmp(1),
     646                 :          0 :                               pCaller->GetClosedBmp(1),
     647                 :            :                               pParent,
     648                 :            :                               sal_True,
     649                 :          0 :                               nIdx);
     650                 :          0 :         pCaller->Update();
     651                 :          0 :         pCaller->Expand( pParent );
     652                 :          0 :         bModified = sal_True;
     653                 :          0 :         return sal_True;
     654                 :            :     }
     655                 :          0 :     return sal_False;
     656                 :            : }
     657                 :            : 
     658                 :            : //-------------------------------------------------------------------------
     659                 :            : 
     660                 :          0 : sal_Bool SfxOrganizeMgr::InsertFile( SfxOrganizeListBox_Impl* pCaller, const String& rFileName )
     661                 :            : 
     662                 :            : /*  [Description]
     663                 :            : 
     664                 :            :     Insert a file in the file view.
     665                 :            : 
     666                 :            :     [Parameter]
     667                 :            : 
     668                 :            :     SfxOrganizeListBox *pCaller     calling ListBox, since this event
     669                 :            :                                     is triggered by the menu or the
     670                 :            :                                     keyboard, the ListBox must be updated.
     671                 :            : 
     672                 :            :     const String &rFileName         Name of inserted File.
     673                 :            : 
     674                 :            :     [Return value]                  Success (TRUE) or Failure (FALSE)
     675                 :            : */
     676                 :            : 
     677                 :            : {
     678         [ #  # ]:          0 :     const CollatorWrapper* pCollator = pImpl->pIntlWrapper->getCaseCollator();
     679 [ #  # ][ #  # ]:          0 :     _FileListEntry* pEntry = new _FileListEntry( rFileName, pCollator );
     680         [ #  # ]:          0 :     std::pair<SfxObjectList::const_iterator, bool> aRes = pImpl->pDocList->insert( pEntry );
     681         [ #  # ]:          0 :     if ( aRes.second )
     682                 :            :     {
     683         [ #  # ]:          0 :         sal_uInt16 nPos = aRes.first - pImpl->pDocList->begin();
     684         [ #  # ]:          0 :         pCaller->InsertEntry( pEntry->aBaseName, pCaller->GetOpenedBmp(1),
     685 [ #  # ][ #  # ]:          0 :                               pCaller->GetClosedBmp(1), 0, sal_True, nPos );
     686                 :          0 :         return sal_True;
     687                 :            :     }
     688                 :            :     else
     689 [ #  # ][ #  # ]:          0 :         delete pEntry;
     690                 :          0 :     return sal_False;
     691                 :            : }
     692                 :            : 
     693                 :            : //-------------------------------------------------------------------------
     694                 :            : 
     695                 :          0 : sal_Bool SfxOrganizeMgr::Rescan()
     696                 :            : 
     697                 :            : /*  [Description]
     698                 :            : 
     699                 :            :     Updating the database.
     700                 :            : 
     701                 :            :     [Return value]
     702                 :            : 
     703                 :            :     TRUE                                        Changes were made
     704                 :            :     FALSE                                       No changes
     705                 :            : 
     706                 :            :     [Cross-reference]
     707                 :            : 
     708                 :            :     <SfxDocumentTemplates::Rescan()>
     709                 :            : */
     710                 :            : 
     711                 :            : {
     712         [ #  # ]:          0 :     if(pTemplates->Rescan())
     713                 :            :     {
     714                 :          0 :         bModified = sal_True;
     715                 :          0 :         return sal_True;
     716                 :            :     }
     717                 :          0 :     return sal_False;
     718                 :            : }
     719                 :            : 
     720                 :            : //-------------------------------------------------------------------------
     721                 :            : 
     722                 :          0 : void SfxOrganizeMgr::SaveAll(Window *pParent)
     723                 :            : 
     724                 :            : /*  [Description]
     725                 :            : 
     726                 :            :     Save all Documents that have been modified
     727                 :            : 
     728                 :            :     [Parameter]
     729                 :            : 
     730                 :            :     Window *pParent            Parent of the Error message Box
     731                 :            : */
     732                 :            : 
     733                 :            : {
     734                 :          0 :     sal_uInt16 nRangeCount = pTemplates->GetRegionCount();
     735                 :            :     sal_uInt16 i;
     736         [ #  # ]:          0 :     for(i = 0; i < nRangeCount; ++i)
     737                 :            :     {
     738         [ #  # ]:          0 :         if( pTemplates->IsRegionLoaded( i ))
     739                 :            :         {
     740                 :          0 :             const sal_uInt16 nCount = pTemplates->GetCount(i);
     741         [ #  # ]:          0 :             for(sal_uInt16 j = 0; j < nCount; ++j)
     742                 :            :             {
     743         [ #  # ]:          0 :                 if(!pTemplates->DeleteObjectShell(i, j))
     744                 :            :                 {
     745 [ #  # ][ #  # ]:          0 :                     String aText = SfxResId(STR_ERROR_SAVE_TEMPLATE).toString();
                 [ #  # ]
     746 [ #  # ][ #  # ]:          0 :                     aText += pTemplates->GetName(i, j);
     747                 :            :                     ErrorBox aBox(pParent,
     748                 :            :                                   WinBits(WB_OK_CANCEL | WB_DEF_CANCEL),
     749         [ #  # ]:          0 :                                   aText);
     750 [ #  # ][ #  # ]:          0 :                     if(RET_CANCEL == aBox.Execute())
     751 [ #  # ][ #  # ]:          0 :                         break;
         [ #  # ][ #  # ]
     752                 :            :                 }
     753                 :            :             }
     754                 :            :         }
     755                 :            :     }
     756 [ #  # ][ #  # ]:          0 :     for( SfxObjectList::const_iterator it = pImpl->pDocList->begin(); it != pImpl->pDocList->end(); ++it )
     757                 :            :     {
     758                 :          0 :         _FileListEntry *pEntry = *it;
     759 [ #  # ][ #  # ]:          0 :         if(!pEntry->DeleteObjectShell())
     760                 :            :         {
     761 [ #  # ][ #  # ]:          0 :             String aText(SfxResId(STR_ERROR_SAVE_TEMPLATE).toString());
                 [ #  # ]
     762         [ #  # ]:          0 :             aText += pEntry->aBaseName;
     763         [ #  # ]:          0 :             ErrorBox aBox(pParent, WinBits(WB_OK_CANCEL | WB_DEF_CANCEL), aText);
     764 [ #  # ][ #  # ]:          0 :             if(RET_CANCEL == aBox.Execute())
     765 [ #  # ][ #  # ]:          0 :                 break;
         [ #  # ][ #  # ]
     766                 :            :         }
     767                 :            :     }
     768                 :          0 : }
     769                 :            : 
     770                 :            : 
     771                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10