LCOV - code coverage report
Current view: top level - dbaccess/source/ui/dlg - dbfindex.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 2 240 0.8 %
Date: 2012-08-25 Functions: 2 28 7.1 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 2 598 0.3 %

           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 "dbfindex.hxx"
      21                 :            : #include <tools/config.hxx>
      22                 :            : #include <sfx2/app.hxx>
      23                 :            : #include "moduledbu.hxx"
      24                 :            : #include "dbu_dlg.hrc"
      25                 :            : #include "dbfindex.hrc"
      26                 :            : #include <osl/diagnose.h>
      27                 :            : #include <unotools/localfilehelper.hxx>
      28                 :            : #include <tools/urlobj.hxx>
      29                 :            : #include <unotools/pathoptions.hxx>
      30                 :            : #include <ucbhelper/content.hxx>
      31                 :            : #include <svl/filenotation.hxx>
      32                 :            : #include <rtl/strbuf.hxx>
      33                 :            : 
      34                 :            : namespace dbaui
      35                 :            : {
      36                 :            : using namespace ::com::sun::star::uno;
      37                 :            : using namespace ::com::sun::star::ucb;
      38                 :            : using namespace ::svt;
      39                 :            : 
      40                 :         14 : const rtl::OString aGroupIdent(RTL_CONSTASCII_STRINGPARAM("dBase III"));
      41                 :            : 
      42                 :            : // ODbaseIndexDialog ----------------------------------------------------------
      43                 :            : DBG_NAME(ODbaseIndexDialog)
      44                 :            : 
      45                 :          0 : ODbaseIndexDialog::ODbaseIndexDialog( Window * pParent, String aDataSrcName )
      46                 :            :     : ModalDialog( pParent, ModuleRes(DLG_DBASE_INDEXES) ),
      47                 :            :     aPB_OK(             this, ModuleRes( PB_OK ) ),
      48                 :            :     aPB_CANCEL(         this, ModuleRes( PB_CANCEL ) ),
      49                 :            :     aPB_HELP(           this, ModuleRes( PB_HELP ) ),
      50                 :            :     m_FT_Tables(        this, ModuleRes( FT_TABLES ) ),
      51                 :            :     aCB_Tables(         this, ModuleRes( CB_TABLES ) ),
      52                 :            :     m_FL_Indexes(       this, ModuleRes( FL_INDEXES ) ),
      53                 :            :     m_FT_TableIndexes(  this, ModuleRes( FT_TABLEINDEXES ) ),
      54                 :            :     aLB_TableIndexes(   this, ModuleRes( LB_TABLEINDEXES ) ),
      55                 :            :     m_FT_AllIndexes(    this, ModuleRes( FT_ALLINDEXES ) ),
      56                 :            :     aLB_FreeIndexes(    this, ModuleRes( LB_FREEINDEXES ) ),
      57                 :            :     aIB_Add(            this, ModuleRes( IB_ADD ) ),
      58                 :            :     aIB_Remove(         this, ModuleRes( IB_REMOVE ) ),
      59                 :            :     aIB_AddAll(         this, ModuleRes( IB_ADDALL ) ),
      60                 :            :     aIB_RemoveAll(      this, ModuleRes( IB_REMOVEALL ) ),
      61                 :            :     m_aDSN(aDataSrcName),
      62 [ #  # ][ #  # ]:          0 :     m_bCaseSensitiv(sal_True)
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      63                 :            : {
      64                 :            :     DBG_CTOR(ODbaseIndexDialog,NULL);
      65                 :            : 
      66         [ #  # ]:          0 :     aCB_Tables.SetSelectHdl( LINK(this, ODbaseIndexDialog, TableSelectHdl) );
      67         [ #  # ]:          0 :     aIB_Add.SetClickHdl( LINK(this, ODbaseIndexDialog, AddClickHdl) );
      68         [ #  # ]:          0 :     aIB_Remove.SetClickHdl( LINK(this, ODbaseIndexDialog, RemoveClickHdl) );
      69         [ #  # ]:          0 :     aIB_AddAll.SetClickHdl( LINK(this, ODbaseIndexDialog, AddAllClickHdl) );
      70         [ #  # ]:          0 :     aIB_RemoveAll.SetClickHdl( LINK(this, ODbaseIndexDialog, RemoveAllClickHdl) );
      71         [ #  # ]:          0 :     aPB_OK.SetClickHdl( LINK(this, ODbaseIndexDialog, OKClickHdl) );
      72                 :            : 
      73         [ #  # ]:          0 :     aLB_FreeIndexes.SetSelectHdl( LINK(this, ODbaseIndexDialog, OnListEntrySelected) );
      74         [ #  # ]:          0 :     aLB_TableIndexes.SetSelectHdl( LINK(this, ODbaseIndexDialog, OnListEntrySelected) );
      75                 :            : 
      76         [ #  # ]:          0 :     aCB_Tables.SetDropDownLineCount(8);
      77         [ #  # ]:          0 :     Init();
      78         [ #  # ]:          0 :     SetCtrls();
      79         [ #  # ]:          0 :     FreeResource();
      80                 :          0 : }
      81                 :            : 
      82 [ #  # ][ #  # ]:          0 : ODbaseIndexDialog::~ODbaseIndexDialog()
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      83                 :            : {
      84                 :            : 
      85                 :            :     DBG_DTOR(ODbaseIndexDialog,NULL);
      86         [ #  # ]:          0 : }
      87                 :            : 
      88                 :          0 : sal_Bool ODbaseIndexDialog::GetTable(const String& _rName, TableInfoListIterator& _rPosition)
      89                 :            : {
      90         [ #  # ]:          0 :     for (   _rPosition = m_aTableInfoList.begin();
      91                 :          0 :             _rPosition != m_aTableInfoList.end();
      92                 :            :             ++_rPosition
      93                 :            :         )
      94                 :            :     {
      95         [ #  # ]:          0 :         if (m_bCaseSensitiv)
      96                 :            :         {
      97         [ #  # ]:          0 :             if (_rPosition->aTableName.Equals(_rName))
      98                 :          0 :                 return sal_True;
      99                 :            :         }
     100                 :            :         else
     101                 :            :         {
     102         [ #  # ]:          0 :             if (_rPosition->aTableName.EqualsIgnoreCaseAscii(_rName))
     103                 :          0 :                 return sal_True;
     104                 :            :         }
     105                 :            :     }
     106                 :          0 :     return sal_False;
     107                 :            : }
     108                 :            : 
     109                 :          0 : void ODbaseIndexDialog::checkButtons()
     110                 :            : {
     111                 :          0 :     aIB_Add.Enable(0 != aLB_FreeIndexes.GetSelectEntryCount());
     112                 :          0 :     aIB_AddAll.Enable(0 != aLB_FreeIndexes.GetEntryCount());
     113                 :            : 
     114                 :          0 :     aIB_Remove.Enable(0 != aLB_TableIndexes.GetSelectEntryCount());
     115                 :          0 :     aIB_RemoveAll.Enable(0 != aLB_TableIndexes.GetEntryCount());
     116                 :          0 : }
     117                 :            : 
     118                 :          0 : OTableIndex ODbaseIndexDialog::implRemoveIndex(const String& _rName, TableIndexList& _rList, ListBox& _rDisplay, sal_Bool _bMustExist)
     119                 :            : {
     120         [ #  # ]:          0 :     OTableIndex aReturn;
     121                 :            : 
     122                 :          0 :     sal_Int32 nPos = 0;
     123                 :            : 
     124                 :          0 :     TableIndexListIterator aSearch;
     125         [ #  # ]:          0 :     for (   aSearch = _rList.begin();
     126                 :          0 :             aSearch != _rList.end();
     127                 :            :             ++aSearch, ++nPos
     128                 :            :         )
     129                 :            :     {
     130 [ #  # ][ #  # ]:          0 :         if ( m_bCaseSensitiv ? aSearch->GetIndexFileName().Equals(_rName) : aSearch->GetIndexFileName().EqualsIgnoreCaseAscii(_rName) )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  #  
             #  #  #  # ]
     131                 :            :         {
     132         [ #  # ]:          0 :             aReturn = *aSearch;
     133                 :            : 
     134         [ #  # ]:          0 :             _rList.erase(aSearch);
     135         [ #  # ]:          0 :             _rDisplay.RemoveEntry( _rName );
     136                 :            : 
     137                 :            :             // adjust selection if necessary
     138         [ #  # ]:          0 :             if ((sal_uInt32)nPos == _rList.size())
     139         [ #  # ]:          0 :                 _rDisplay.SelectEntryPos((sal_uInt16)nPos-1);
     140                 :            :             else
     141         [ #  # ]:          0 :                 _rDisplay.SelectEntryPos((sal_uInt16)nPos);
     142                 :            : 
     143                 :          0 :             break;
     144                 :            :         }
     145                 :            :     }
     146                 :            : 
     147                 :            :     (void)_bMustExist;
     148                 :            :     OSL_ENSURE(!_bMustExist || (aSearch != _rList.end()), "ODbaseIndexDialog::implRemoveIndex : did not find the index!");
     149                 :          0 :     return aReturn;
     150                 :            : }
     151                 :            : 
     152                 :          0 : void ODbaseIndexDialog::implInsertIndex(const OTableIndex& _rIndex, TableIndexList& _rList, ListBox& _rDisplay)
     153                 :            : {
     154                 :          0 :     _rList.push_front( _rIndex );
     155         [ #  # ]:          0 :     _rDisplay.InsertEntry( _rIndex.GetIndexFileName() );
     156                 :          0 :     _rDisplay.SelectEntryPos(0);
     157                 :          0 : }
     158                 :            : 
     159                 :          0 : OTableIndex ODbaseIndexDialog::RemoveTableIndex( const String& _rTableName, const String& _rIndexName, sal_Bool _bMustExist )
     160                 :            : {
     161         [ #  # ]:          0 :     OTableIndex aReturn;
     162                 :            : 
     163                 :            :     // does the table exist ?
     164                 :          0 :     TableInfoListIterator aTablePos;
     165 [ #  # ][ #  # ]:          0 :     if (!GetTable(_rTableName, aTablePos))
     166         [ #  # ]:          0 :         return aReturn;
     167                 :            : 
     168 [ #  # ][ #  # ]:          0 :     return implRemoveIndex(_rIndexName, aTablePos->aIndexList, aLB_TableIndexes, _bMustExist);
     169                 :            : }
     170                 :            : 
     171                 :          0 : void ODbaseIndexDialog::InsertTableIndex( const String& _rTableName, const OTableIndex& _rIndex)
     172                 :            : {
     173                 :          0 :     TableInfoListIterator aTablePos;
     174 [ #  # ][ #  # ]:          0 :     if (!GetTable(_rTableName, aTablePos))
     175                 :          0 :         return;
     176                 :            : 
     177         [ #  # ]:          0 :     implInsertIndex(_rIndex, aTablePos->aIndexList, aLB_TableIndexes);
     178                 :            : }
     179                 :            : 
     180                 :          0 : IMPL_LINK( ODbaseIndexDialog, OKClickHdl, PushButton*, /*pButton*/ )
     181                 :            : {
     182                 :            :     // let all tables write their INF file
     183                 :            : 
     184         [ #  # ]:          0 :     for (   ConstTableInfoListIterator aLoop = m_aTableInfoList.begin();
     185                 :          0 :             aLoop != m_aTableInfoList.end();
     186                 :            :             ++aLoop
     187                 :            :         )
     188         [ #  # ]:          0 :         aLoop->WriteInfFile(m_aDSN);
     189                 :            : 
     190                 :          0 :     EndDialog();
     191                 :          0 :     return 0;
     192                 :            : }
     193                 :            : 
     194                 :          0 : IMPL_LINK( ODbaseIndexDialog, AddClickHdl, PushButton*, /*pButton*/ )
     195                 :            : {
     196         [ #  # ]:          0 :     String aSelection = aLB_FreeIndexes.GetSelectEntry();
     197         [ #  # ]:          0 :     String aTableName = aCB_Tables.GetText();
     198         [ #  # ]:          0 :     OTableIndex aIndex = RemoveFreeIndex( aSelection, sal_True );
     199         [ #  # ]:          0 :     InsertTableIndex( aTableName, aIndex );
     200                 :            : 
     201         [ #  # ]:          0 :     checkButtons();
     202 [ #  # ][ #  # ]:          0 :     return 0;
                 [ #  # ]
     203                 :            : }
     204                 :            : 
     205                 :          0 : IMPL_LINK( ODbaseIndexDialog, RemoveClickHdl, PushButton*, /*pButton*/ )
     206                 :            : {
     207         [ #  # ]:          0 :     String aSelection = aLB_TableIndexes.GetSelectEntry();
     208         [ #  # ]:          0 :     String aTableName = aCB_Tables.GetText();
     209         [ #  # ]:          0 :     OTableIndex aIndex = RemoveTableIndex( aTableName, aSelection, sal_True );
     210         [ #  # ]:          0 :     InsertFreeIndex( aIndex );
     211                 :            : 
     212         [ #  # ]:          0 :     checkButtons();
     213 [ #  # ][ #  # ]:          0 :     return 0;
                 [ #  # ]
     214                 :            : }
     215                 :            : 
     216                 :          0 : IMPL_LINK( ODbaseIndexDialog, AddAllClickHdl, PushButton*, /*pButton*/ )
     217                 :            : {
     218         [ #  # ]:          0 :     sal_uInt16 nCnt = aLB_FreeIndexes.GetEntryCount();
     219         [ #  # ]:          0 :     String aTableName = aCB_Tables.GetText();
     220                 :            : 
     221         [ #  # ]:          0 :     for( sal_uInt16 nPos = 0; nPos < nCnt; ++nPos )
     222 [ #  # ][ #  # ]:          0 :         InsertTableIndex( aTableName, RemoveFreeIndex( aLB_FreeIndexes.GetEntry(0), sal_True ) );
         [ #  # ][ #  # ]
                 [ #  # ]
     223                 :            : 
     224         [ #  # ]:          0 :     checkButtons();
     225         [ #  # ]:          0 :     return 0;
     226                 :            : }
     227                 :            : 
     228                 :          0 : IMPL_LINK( ODbaseIndexDialog, RemoveAllClickHdl, PushButton*, /*pButton*/ )
     229                 :            : {
     230         [ #  # ]:          0 :     sal_uInt16 nCnt = aLB_TableIndexes.GetEntryCount();
     231         [ #  # ]:          0 :     String aTableName = aCB_Tables.GetText();
     232                 :            : 
     233         [ #  # ]:          0 :     for( sal_uInt16 nPos = 0; nPos < nCnt; ++nPos )
     234 [ #  # ][ #  # ]:          0 :         InsertFreeIndex( RemoveTableIndex( aTableName, aLB_TableIndexes.GetEntry(0), sal_True ) );
         [ #  # ][ #  # ]
                 [ #  # ]
     235                 :            : 
     236         [ #  # ]:          0 :     checkButtons();
     237         [ #  # ]:          0 :     return 0;
     238                 :            : }
     239                 :            : 
     240                 :          0 : IMPL_LINK( ODbaseIndexDialog, OnListEntrySelected, ListBox*, /*NOTINTERESTEDIN*/ )
     241                 :            : {
     242                 :          0 :     checkButtons();
     243                 :          0 :     return 0;
     244                 :            : }
     245                 :            : 
     246                 :          0 : IMPL_LINK( ODbaseIndexDialog, TableSelectHdl, ComboBox*, pComboBox )
     247                 :            : {
     248                 :            :     // search the table
     249                 :          0 :     TableInfoListIterator aTablePos;
     250 [ #  # ][ #  # ]:          0 :     if (!GetTable(pComboBox->GetText(), aTablePos))
         [ #  # ][ #  # ]
     251                 :          0 :         return 0L;
     252                 :            : 
     253                 :            :     // fill the listbox for the indexes
     254         [ #  # ]:          0 :     aLB_TableIndexes.Clear();
     255         [ #  # ]:          0 :     for (   ConstTableIndexListIterator aLoop = aTablePos->aIndexList.begin();
     256                 :          0 :             aLoop != aTablePos->aIndexList.end();
     257                 :            :             ++aLoop
     258                 :            :         )
     259 [ #  # ][ #  # ]:          0 :         aLB_TableIndexes.InsertEntry( aLoop->GetIndexFileName() );
                 [ #  # ]
     260                 :            : 
     261         [ #  # ]:          0 :     if ( aTablePos->aIndexList.size() )
     262         [ #  # ]:          0 :         aLB_TableIndexes.SelectEntryPos(0);
     263                 :            : 
     264         [ #  # ]:          0 :     checkButtons();
     265                 :          0 :     return 0;
     266                 :            : }
     267                 :            : 
     268                 :          0 : void ODbaseIndexDialog::Init()
     269                 :            : {
     270         [ #  # ]:          0 :     aPB_OK.Disable();
     271         [ #  # ]:          0 :     m_FL_Indexes.Disable();
     272         [ #  # ]:          0 :     m_FT_TableIndexes.Disable();
     273         [ #  # ]:          0 :     aLB_TableIndexes.Disable();
     274         [ #  # ]:          0 :     m_FT_AllIndexes.Disable();
     275         [ #  # ]:          0 :     aLB_FreeIndexes.Disable();
     276         [ #  # ]:          0 :     aIB_Add.Disable();
     277         [ #  # ]:          0 :     aIB_Remove.Disable();
     278         [ #  # ]:          0 :     aIB_AddAll.Disable();
     279         [ #  # ]:          0 :     aIB_RemoveAll.Disable();
     280                 :            : 
     281                 :            :     // All indizes are first added to a list of free indizes.
     282                 :            :     // Afterwards, check the index of each table in the Inf-file.
     283                 :            :     // These indizes are removed from the list of free indizes and
     284                 :            :     // entered in the indexlist of the the table.
     285                 :            : 
     286                 :            :     // if the string does not contain a path, cut the string
     287         [ #  # ]:          0 :     INetURLObject aURL;
     288                 :          0 :     aURL.SetSmartProtocol(INET_PROT_FILE);
     289                 :            :     {
     290         [ #  # ]:          0 :         SvtPathOptions aPathOptions;
     291 [ #  # ][ #  # ]:          0 :         m_aDSN = aPathOptions.SubstituteVariable(m_aDSN);
         [ #  # ][ #  # ]
     292                 :            :     }
     293 [ #  # ][ #  # ]:          0 :     aURL.SetSmartURL(m_aDSN);
     294                 :            : 
     295                 :            :     //  String aFileName = aURL.PathToFileName();
     296 [ #  # ][ #  # ]:          0 :     m_aDSN = aURL.GetMainURL(INetURLObject::NO_DECODE);
     297         [ #  # ]:          0 :     ::ucbhelper::Content aFile;
     298                 :          0 :     sal_Bool bFolder=sal_True;
     299                 :            :     try
     300                 :            :     {
     301 [ #  # ][ #  # ]:          0 :         aFile = ::ucbhelper::Content(m_aDSN,Reference< ::com::sun::star::ucb::XCommandEnvironment >());
         [ #  # ][ #  # ]
                 [ #  # ]
     302         [ #  # ]:          0 :         bFolder = aFile.isFolder();
     303                 :            :     }
     304         [ #  # ]:          0 :     catch(Exception&)
     305                 :            :     {
     306                 :          0 :         return;
     307                 :            :     }
     308                 :            : 
     309                 :            :     // first assume for all indexes they're free
     310                 :            : 
     311 [ #  # ][ #  # ]:          0 :     Sequence< ::rtl::OUString> aFolderContent( ::utl::LocalFileHelper::GetFolderContents(m_aDSN,bFolder));
     312                 :            : 
     313         [ #  # ]:          0 :     ::rtl::OUString aIndexExt(RTL_CONSTASCII_USTRINGPARAM("ndx"));
     314         [ #  # ]:          0 :     ::rtl::OUString aTableExt(RTL_CONSTASCII_USTRINGPARAM("dbf"));
     315                 :            : 
     316         [ #  # ]:          0 :     ::std::vector< String > aUsedIndexes;
     317                 :            : 
     318                 :          0 :     const ::rtl::OUString *pBegin = aFolderContent.getConstArray();
     319                 :          0 :     const ::rtl::OUString *pEnd   = pBegin + aFolderContent.getLength();
     320                 :          0 :     aURL.SetSmartProtocol(INET_PROT_FILE);
     321         [ #  # ]:          0 :     for(;pBegin != pEnd;++pBegin)
     322                 :            :     {
     323                 :          0 :         rtl::OUString aName;
     324         [ #  # ]:          0 :         ::utl::LocalFileHelper::ConvertURLToPhysicalName(pBegin->getStr(),aName);
     325         [ #  # ]:          0 :         aURL.SetSmartURL(aName);
     326         [ #  # ]:          0 :         rtl::OUString aExt = aURL.getExtension();
     327         [ #  # ]:          0 :         if (aExt == aIndexExt)
     328                 :            :         {
     329 [ #  # ][ #  # ]:          0 :             m_aFreeIndexList.push_back( OTableIndex(aURL.getName()) );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     330                 :            :         }
     331         [ #  # ]:          0 :         else if (aExt == aTableExt)
     332                 :            :         {
     333 [ #  # ][ #  # ]:          0 :             m_aTableInfoList.push_back( OTableInfo(aURL.getName()) );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     334         [ #  # ]:          0 :             OTableInfo& rTabInfo = m_aTableInfoList.back();
     335                 :            : 
     336                 :            :             // open the INF file
     337         [ #  # ]:          0 :             aURL.setExtension(rtl::OUString::createFromAscii("inf"));
     338 [ #  # ][ #  # ]:          0 :             OFileNotation aTransformer(aURL.GetURLNoPass(), OFileNotation::N_URL);
     339 [ #  # ][ #  # ]:          0 :             Config aInfFile( aTransformer.get(OFileNotation::N_SYSTEM) );
     340         [ #  # ]:          0 :             aInfFile.SetGroup( aGroupIdent );
     341                 :            : 
     342                 :            :             // fill the indexes list
     343                 :          0 :             rtl::OString aNDX;
     344         [ #  # ]:          0 :             sal_uInt16 nKeyCnt = aInfFile.GetKeyCount();
     345                 :          0 :             rtl::OString aKeyName;
     346         [ #  # ]:          0 :             String aEntry;
     347                 :            : 
     348         [ #  # ]:          0 :             for( sal_uInt16 nKey = 0; nKey < nKeyCnt; nKey++ )
     349                 :            :             {
     350                 :            :                 // does the key point to an index file ?
     351         [ #  # ]:          0 :                 aKeyName = aInfFile.GetKeyName( nKey );
     352                 :          0 :                 aNDX = aKeyName.copy(0,3);
     353                 :            : 
     354                 :            :                 // yes -> add to the tables index list
     355         [ #  # ]:          0 :                 if (aNDX.equalsL(RTL_CONSTASCII_STRINGPARAM("NDX")))
     356                 :            :                 {
     357 [ #  # ][ #  # ]:          0 :                     aEntry = rtl::OStringToOUString(aInfFile.ReadKey(aKeyName), osl_getThreadTextEncoding());
         [ #  # ][ #  # ]
     358 [ #  # ][ #  # ]:          0 :                     rTabInfo.aIndexList.push_back( OTableIndex( aEntry ) );
                 [ #  # ]
     359                 :            : 
     360                 :            :                     // and remove it from the free index list
     361         [ #  # ]:          0 :                     aUsedIndexes.push_back(aEntry);
     362                 :            :                         // do this later below. We may not have encountered the index file, yet, thus we may not
     363                 :            :                         // know the index as beeing free, yet
     364                 :            :                 }
     365 [ #  # ][ #  # ]:          0 :             }
                 [ #  # ]
     366                 :            :         }
     367                 :          0 :     }
     368                 :            : 
     369         [ #  # ]:          0 :     for (   ::std::vector< String >::const_iterator aUsedIndex = aUsedIndexes.begin();
           [ #  #  #  # ]
                 [ #  # ]
     370                 :          0 :             aUsedIndex != aUsedIndexes.end();
     371                 :            :             ++aUsedIndex
     372                 :            :         )
     373 [ #  # ][ #  # ]:          0 :         RemoveFreeIndex( *aUsedIndex, sal_False );
                 [ #  # ]
     374                 :            : 
     375         [ #  # ]:          0 :     if (m_aTableInfoList.size())
     376                 :            :     {
     377         [ #  # ]:          0 :         aPB_OK.Enable();
     378         [ #  # ]:          0 :         m_FL_Indexes.Enable();
     379         [ #  # ]:          0 :         m_FT_TableIndexes.Enable();
     380         [ #  # ]:          0 :         aLB_TableIndexes.Enable();
     381         [ #  # ]:          0 :         m_FT_AllIndexes.Enable();
     382         [ #  # ]:          0 :         aLB_FreeIndexes.Enable();
     383                 :            :     }
     384                 :            : 
     385 [ #  # ][ #  # ]:          0 :     checkButtons();
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     386                 :            : }
     387                 :            : 
     388                 :          0 : void ODbaseIndexDialog::SetCtrls()
     389                 :            : {
     390                 :            :     // ComboBox tables
     391         [ #  # ]:          0 :     for (   ConstTableInfoListIterator aLoop = m_aTableInfoList.begin();
     392                 :          0 :             aLoop != m_aTableInfoList.end();
     393                 :            :             ++aLoop
     394                 :            :         )
     395         [ #  # ]:          0 :         aCB_Tables.InsertEntry( aLoop->aTableName );
     396                 :            : 
     397                 :            :     // put the first dataset into Edit
     398         [ #  # ]:          0 :     if( m_aTableInfoList.size() )
     399                 :            :     {
     400                 :          0 :         const OTableInfo& rTabInfo = m_aTableInfoList.front();
     401                 :          0 :         aCB_Tables.SetText( rTabInfo.aTableName );
     402                 :            : 
     403                 :            :         // build ListBox of the table indizes
     404         [ #  # ]:          0 :         for (   ConstTableIndexListIterator aIndex = rTabInfo.aIndexList.begin();
     405                 :          0 :                 aIndex != rTabInfo.aIndexList.end();
     406                 :            :                 ++aIndex
     407                 :            :             )
     408 [ #  # ][ #  # ]:          0 :             aLB_TableIndexes.InsertEntry( aIndex->GetIndexFileName() );
                 [ #  # ]
     409                 :            : 
     410         [ #  # ]:          0 :         if( rTabInfo.aIndexList.size() )
     411                 :          0 :             aLB_TableIndexes.SelectEntryPos( 0 );
     412                 :            :     }
     413                 :            : 
     414                 :            :     // ListBox of the free indizes
     415         [ #  # ]:          0 :     for (   ConstTableIndexListIterator aFree = m_aFreeIndexList.begin();
     416                 :          0 :             aFree != m_aFreeIndexList.end();
     417                 :            :             ++aFree
     418                 :            :         )
     419 [ #  # ][ #  # ]:          0 :         aLB_FreeIndexes.InsertEntry( aFree->GetIndexFileName() );
                 [ #  # ]
     420                 :            : 
     421         [ #  # ]:          0 :     if( m_aFreeIndexList.size() )
     422                 :          0 :         aLB_FreeIndexes.SelectEntryPos( 0 );
     423                 :            : 
     424                 :          0 :     TableSelectHdl(&aCB_Tables);
     425                 :          0 :     checkButtons();
     426                 :          0 : }
     427                 :            : 
     428                 :            : // OTableInfo ------------------------------------------------------------------
     429                 :          0 : void OTableInfo::WriteInfFile( const String& rDSN ) const
     430                 :            : {
     431                 :            :     // open INF file
     432         [ #  # ]:          0 :     INetURLObject aURL;
     433                 :          0 :     aURL.SetSmartProtocol(INET_PROT_FILE);
     434         [ #  # ]:          0 :     String aDsn = rDSN;
     435                 :            :     {
     436         [ #  # ]:          0 :         SvtPathOptions aPathOptions;
     437 [ #  # ][ #  # ]:          0 :         aDsn = aPathOptions.SubstituteVariable(aDsn);
         [ #  # ][ #  # ]
     438                 :            :     }
     439 [ #  # ][ #  # ]:          0 :     aURL.SetSmartURL(aDsn);
     440 [ #  # ][ #  # ]:          0 :     aURL.Append(aTableName);
     441         [ #  # ]:          0 :     aURL.setExtension(rtl::OUString::createFromAscii("inf"));
     442                 :            : 
     443 [ #  # ][ #  # ]:          0 :     OFileNotation aTransformer(aURL.GetURLNoPass(), OFileNotation::N_URL);
     444 [ #  # ][ #  # ]:          0 :     Config aInfFile( aTransformer.get(OFileNotation::N_SYSTEM) );
     445         [ #  # ]:          0 :     aInfFile.SetGroup( aGroupIdent );
     446                 :            : 
     447                 :            :     // first, delete all table indizes
     448                 :          0 :     rtl::OString aNDX;
     449         [ #  # ]:          0 :     sal_uInt16 nKeyCnt = aInfFile.GetKeyCount();
     450                 :          0 :     sal_uInt16 nKey = 0;
     451                 :            : 
     452         [ #  # ]:          0 :     while( nKey < nKeyCnt )
     453                 :            :     {
     454                 :            :         // Does the key point to an index file?...
     455         [ #  # ]:          0 :         rtl::OString aKeyName = aInfFile.GetKeyName( nKey );
     456                 :          0 :         aNDX = aKeyName.copy(0,3);
     457                 :            : 
     458                 :            :         //...if yes, delete index file, nKey is at subsequent key
     459         [ #  # ]:          0 :         if (aNDX.equalsL(RTL_CONSTASCII_STRINGPARAM("NDX")))
     460                 :            :         {
     461         [ #  # ]:          0 :             aInfFile.DeleteKey(aKeyName);
     462                 :          0 :             nKeyCnt--;
     463                 :            :         }
     464                 :            :         else
     465                 :          0 :             nKey++;
     466                 :            : 
     467                 :          0 :     }
     468                 :            : 
     469                 :            :     // now add all saved indizes
     470                 :          0 :     sal_uInt16 nPos = 0;
     471         [ #  # ]:          0 :     for (   ConstTableIndexListIterator aIndex = aIndexList.begin();
     472                 :          0 :             aIndex != aIndexList.end();
     473                 :            :             ++aIndex, ++nPos
     474                 :            :         )
     475                 :            :     {
     476         [ #  # ]:          0 :         rtl::OStringBuffer aKeyName(RTL_CONSTASCII_STRINGPARAM("NDX"));
     477         [ #  # ]:          0 :         if( nPos > 0 )  // first index contains no number
     478         [ #  # ]:          0 :             aKeyName.append(static_cast<sal_Int32>(nPos));
     479                 :            :         aInfFile.WriteKey(
     480                 :            :             aKeyName.makeStringAndClear(),
     481                 :            :             rtl::OUStringToOString(aIndex->GetIndexFileName(),
     482 [ #  # ][ #  # ]:          0 :                 osl_getThreadTextEncoding()));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     483                 :          0 :     }
     484                 :            : 
     485         [ #  # ]:          0 :     aInfFile.Flush();
     486                 :            : 
     487                 :            :     // if only [dbase] is left in INF-file, delete file
     488         [ #  # ]:          0 :     if(!nPos)
     489                 :            :     {
     490                 :            :         try
     491                 :            :         {
     492 [ #  # ][ #  # ]:          0 :             ::ucbhelper::Content aContent(aURL.GetURLNoPass(),Reference<XCommandEnvironment>());
     493 [ #  # ][ #  # ]:          0 :             aContent.executeCommand( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("delete")),makeAny( sal_Bool( sal_True ) ) );
         [ #  # ][ #  # ]
                 [ #  # ]
     494                 :            :         }
     495         [ #  # ]:          0 :         catch (const Exception& e )
     496                 :            :         {
     497                 :            :             (void)e;  // make compiler happy
     498                 :            :             // simply silent this. The strange algorithm here does a lot of
     499                 :            :             // things even if no files at all were created or accessed, so it's
     500                 :            :             // possible that the file we're trying to delete does not even
     501                 :            :             // exist, and this is a valid condition.
     502                 :            :         }
     503 [ #  # ][ #  # ]:          0 :     }
         [ #  # ][ #  # ]
     504                 :          0 : }
     505                 :            : 
     506 [ +  - ][ +  - ]:         42 : } // namespace
     507                 :            : 
     508                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10