196de5490SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
396de5490SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
496de5490SAndrew Rist * or more contributor license agreements. See the NOTICE file
596de5490SAndrew Rist * distributed with this work for additional information
696de5490SAndrew Rist * regarding copyright ownership. The ASF licenses this file
796de5490SAndrew Rist * to you under the Apache License, Version 2.0 (the
896de5490SAndrew Rist * "License"); you may not use this file except in compliance
996de5490SAndrew Rist * with the License. You may obtain a copy of the License at
1096de5490SAndrew Rist *
1196de5490SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
1296de5490SAndrew Rist *
1396de5490SAndrew Rist * Unless required by applicable law or agreed to in writing,
1496de5490SAndrew Rist * software distributed under the License is distributed on an
1596de5490SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1696de5490SAndrew Rist * KIND, either express or implied. See the License for the
1796de5490SAndrew Rist * specific language governing permissions and limitations
1896de5490SAndrew Rist * under the License.
1996de5490SAndrew Rist *
2096de5490SAndrew Rist *************************************************************/
2196de5490SAndrew Rist
2296de5490SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25*b63233d8Sdamjan #include "precompiled_dbui.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #ifndef _DBAUI_DBFINDEX_HXX_
28cdf0e10cSrcweir #include "dbfindex.hxx"
29cdf0e10cSrcweir #endif
30cdf0e10cSrcweir
31cdf0e10cSrcweir #ifndef _CONFIG_HXX
32cdf0e10cSrcweir #include <tools/config.hxx>
33cdf0e10cSrcweir #endif
34cdf0e10cSrcweir #ifndef _SFXAPP_HXX //autogen
35cdf0e10cSrcweir #include <sfx2/app.hxx>
36cdf0e10cSrcweir #endif
37cdf0e10cSrcweir #ifndef _DBAUI_MODULE_DBU_HXX_
38cdf0e10cSrcweir #include "moduledbu.hxx"
39cdf0e10cSrcweir #endif
40cdf0e10cSrcweir #ifndef _DBU_DLG_HRC_
41cdf0e10cSrcweir #include "dbu_dlg.hrc"
42cdf0e10cSrcweir #endif
43cdf0e10cSrcweir #ifndef _DBAUI_DBF_INDEXES_HRC_
44cdf0e10cSrcweir #include "dbfindex.hrc"
45cdf0e10cSrcweir #endif
46cdf0e10cSrcweir #ifndef _TOOLS_DEBUG_HXX
47cdf0e10cSrcweir #include <tools/debug.hxx>
48cdf0e10cSrcweir #endif
49cdf0e10cSrcweir #ifndef _UNOTOOLS_LOCALFILEHELPER_HXX
50cdf0e10cSrcweir #include <unotools/localfilehelper.hxx>
51cdf0e10cSrcweir #endif
52cdf0e10cSrcweir #ifndef _URLOBJ_HXX
53cdf0e10cSrcweir #include <tools/urlobj.hxx>
54cdf0e10cSrcweir #endif
55cdf0e10cSrcweir #ifndef INCLUDED_SVTOOLS_PATHOPTIONS_HXX
56cdf0e10cSrcweir #include <unotools/pathoptions.hxx>
57cdf0e10cSrcweir #endif
58cdf0e10cSrcweir #ifndef _UCBHELPER_CONTENT_HXX
59cdf0e10cSrcweir #include <ucbhelper/content.hxx>
60cdf0e10cSrcweir #endif
61cdf0e10cSrcweir #ifndef SVTOOLS_FILENOTATION_HXX_
62cdf0e10cSrcweir #include <svl/filenotation.hxx>
63cdf0e10cSrcweir #endif
64cdf0e10cSrcweir
65cdf0e10cSrcweir
66cdf0e10cSrcweir //.........................................................................
67cdf0e10cSrcweir namespace dbaui
68cdf0e10cSrcweir {
69cdf0e10cSrcweir //.........................................................................
70cdf0e10cSrcweir
71cdf0e10cSrcweir using namespace ::com::sun::star::uno;
72cdf0e10cSrcweir using namespace ::com::sun::star::ucb;
73cdf0e10cSrcweir using namespace ::svt;
74cdf0e10cSrcweir
75cdf0e10cSrcweir const ByteString aGroupIdent("dBase III");
76cdf0e10cSrcweir
77cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////
78cdf0e10cSrcweir // Klasse ODbaseIndexDialog
DBG_NAME(ODbaseIndexDialog)79cdf0e10cSrcweir DBG_NAME(ODbaseIndexDialog)
80cdf0e10cSrcweir //-------------------------------------------------------------------------
81cdf0e10cSrcweir ODbaseIndexDialog::ODbaseIndexDialog( Window * pParent, String aDataSrcName )
82cdf0e10cSrcweir : ModalDialog( pParent, ModuleRes(DLG_DBASE_INDEXES) ),
83cdf0e10cSrcweir aPB_OK( this, ModuleRes( PB_OK ) ),
84cdf0e10cSrcweir aPB_CANCEL( this, ModuleRes( PB_CANCEL ) ),
85cdf0e10cSrcweir aPB_HELP( this, ModuleRes( PB_HELP ) ),
86cdf0e10cSrcweir m_FT_Tables( this, ModuleRes( FT_TABLES ) ),
87cdf0e10cSrcweir aCB_Tables( this, ModuleRes( CB_TABLES ) ),
88cdf0e10cSrcweir m_FL_Indexes( this, ModuleRes( FL_INDEXES ) ),
89cdf0e10cSrcweir m_FT_TableIndexes( this, ModuleRes( FT_TABLEINDEXES ) ),
90cdf0e10cSrcweir aLB_TableIndexes( this, ModuleRes( LB_TABLEINDEXES ) ),
91cdf0e10cSrcweir m_FT_AllIndexes( this, ModuleRes( FT_ALLINDEXES ) ),
92cdf0e10cSrcweir aLB_FreeIndexes( this, ModuleRes( LB_FREEINDEXES ) ),
93cdf0e10cSrcweir aIB_Add( this, ModuleRes( IB_ADD ) ),
94cdf0e10cSrcweir aIB_Remove( this, ModuleRes( IB_REMOVE ) ),
95cdf0e10cSrcweir aIB_AddAll( this, ModuleRes( IB_ADDALL ) ),
96cdf0e10cSrcweir aIB_RemoveAll( this, ModuleRes( IB_REMOVEALL ) ),
97cdf0e10cSrcweir m_aDSN(aDataSrcName),
98cdf0e10cSrcweir m_bCaseSensitiv(sal_True)
99cdf0e10cSrcweir {
100cdf0e10cSrcweir DBG_CTOR(ODbaseIndexDialog,NULL);
101cdf0e10cSrcweir
102cdf0e10cSrcweir aCB_Tables.SetSelectHdl( LINK(this, ODbaseIndexDialog, TableSelectHdl) );
103cdf0e10cSrcweir aIB_Add.SetClickHdl( LINK(this, ODbaseIndexDialog, AddClickHdl) );
104cdf0e10cSrcweir aIB_Remove.SetClickHdl( LINK(this, ODbaseIndexDialog, RemoveClickHdl) );
105cdf0e10cSrcweir aIB_AddAll.SetClickHdl( LINK(this, ODbaseIndexDialog, AddAllClickHdl) );
106cdf0e10cSrcweir aIB_RemoveAll.SetClickHdl( LINK(this, ODbaseIndexDialog, RemoveAllClickHdl) );
107cdf0e10cSrcweir aPB_OK.SetClickHdl( LINK(this, ODbaseIndexDialog, OKClickHdl) );
108cdf0e10cSrcweir
109cdf0e10cSrcweir aLB_FreeIndexes.SetSelectHdl( LINK(this, ODbaseIndexDialog, OnListEntrySelected) );
110cdf0e10cSrcweir aLB_TableIndexes.SetSelectHdl( LINK(this, ODbaseIndexDialog, OnListEntrySelected) );
111cdf0e10cSrcweir
112cdf0e10cSrcweir aCB_Tables.SetDropDownLineCount(8);
113cdf0e10cSrcweir Init();
114cdf0e10cSrcweir SetCtrls();
115cdf0e10cSrcweir FreeResource();
116cdf0e10cSrcweir
117cdf0e10cSrcweir // set Hi contrast bitmaps
118cdf0e10cSrcweir aIB_Add.SetModeImage( ModuleRes(IMG_ONE_LEFT_H),BMP_COLOR_HIGHCONTRAST);
119cdf0e10cSrcweir aIB_AddAll.SetModeImage( ModuleRes(IMG_ALL_LEFT_H),BMP_COLOR_HIGHCONTRAST);
120cdf0e10cSrcweir aIB_Remove.SetModeImage( ModuleRes(IMG_ONE_RIGHT_H),BMP_COLOR_HIGHCONTRAST);
121cdf0e10cSrcweir aIB_RemoveAll.SetModeImage( ModuleRes(IMG_ALL_RIGHT_H),BMP_COLOR_HIGHCONTRAST);
122cdf0e10cSrcweir }
123cdf0e10cSrcweir
124cdf0e10cSrcweir //-------------------------------------------------------------------------
~ODbaseIndexDialog()125cdf0e10cSrcweir ODbaseIndexDialog::~ODbaseIndexDialog()
126cdf0e10cSrcweir {
127cdf0e10cSrcweir
128cdf0e10cSrcweir DBG_DTOR(ODbaseIndexDialog,NULL);
129cdf0e10cSrcweir }
130cdf0e10cSrcweir
131cdf0e10cSrcweir //-------------------------------------------------------------------------
GetTable(const String & _rName,TableInfoListIterator & _rPosition)132cdf0e10cSrcweir sal_Bool ODbaseIndexDialog::GetTable(const String& _rName, TableInfoListIterator& _rPosition)
133cdf0e10cSrcweir {
134cdf0e10cSrcweir for ( _rPosition = m_aTableInfoList.begin();
135cdf0e10cSrcweir _rPosition != m_aTableInfoList.end();
136cdf0e10cSrcweir ++_rPosition
137cdf0e10cSrcweir )
138cdf0e10cSrcweir {
139cdf0e10cSrcweir if (m_bCaseSensitiv)
140cdf0e10cSrcweir {
141cdf0e10cSrcweir if (_rPosition->aTableName.Equals(_rName))
142cdf0e10cSrcweir return sal_True;
143cdf0e10cSrcweir }
144cdf0e10cSrcweir else
145cdf0e10cSrcweir {
146cdf0e10cSrcweir if (_rPosition->aTableName.EqualsIgnoreCaseAscii(_rName))
147cdf0e10cSrcweir return sal_True;
148cdf0e10cSrcweir }
149cdf0e10cSrcweir }
150cdf0e10cSrcweir return sal_False;
151cdf0e10cSrcweir }
152cdf0e10cSrcweir
153cdf0e10cSrcweir //-------------------------------------------------------------------------
checkButtons()154cdf0e10cSrcweir void ODbaseIndexDialog::checkButtons()
155cdf0e10cSrcweir {
156cdf0e10cSrcweir aIB_Add.Enable(0 != aLB_FreeIndexes.GetSelectEntryCount());
157cdf0e10cSrcweir aIB_AddAll.Enable(0 != aLB_FreeIndexes.GetEntryCount());
158cdf0e10cSrcweir
159cdf0e10cSrcweir aIB_Remove.Enable(0 != aLB_TableIndexes.GetSelectEntryCount());
160cdf0e10cSrcweir aIB_RemoveAll.Enable(0 != aLB_TableIndexes.GetEntryCount());
161cdf0e10cSrcweir }
162cdf0e10cSrcweir
163cdf0e10cSrcweir //-------------------------------------------------------------------------
implRemoveIndex(const String & _rName,TableIndexList & _rList,ListBox & _rDisplay,sal_Bool _bMustExist)164cdf0e10cSrcweir OTableIndex ODbaseIndexDialog::implRemoveIndex(const String& _rName, TableIndexList& _rList, ListBox& _rDisplay, sal_Bool _bMustExist)
165cdf0e10cSrcweir {
166cdf0e10cSrcweir OTableIndex aReturn;
167cdf0e10cSrcweir
168cdf0e10cSrcweir sal_Int32 nPos = 0;
169cdf0e10cSrcweir
170cdf0e10cSrcweir TableIndexListIterator aSearch;
171cdf0e10cSrcweir for ( aSearch = _rList.begin();
172cdf0e10cSrcweir aSearch != _rList.end();
173cdf0e10cSrcweir ++aSearch, ++nPos
174cdf0e10cSrcweir )
175cdf0e10cSrcweir {
176cdf0e10cSrcweir if ( m_bCaseSensitiv ? aSearch->GetIndexFileName().Equals(_rName) : aSearch->GetIndexFileName().EqualsIgnoreCaseAscii(_rName) )
177cdf0e10cSrcweir {
178cdf0e10cSrcweir aReturn = *aSearch;
179cdf0e10cSrcweir
180cdf0e10cSrcweir _rList.erase(aSearch);
181cdf0e10cSrcweir _rDisplay.RemoveEntry( _rName );
182cdf0e10cSrcweir
183cdf0e10cSrcweir // adjust selection if necessary
184cdf0e10cSrcweir if ((sal_uInt32)nPos == _rList.size())
185cdf0e10cSrcweir _rDisplay.SelectEntryPos((sal_uInt16)nPos-1);
186cdf0e10cSrcweir else
187cdf0e10cSrcweir _rDisplay.SelectEntryPos((sal_uInt16)nPos);
188cdf0e10cSrcweir
189cdf0e10cSrcweir break;
190cdf0e10cSrcweir }
191cdf0e10cSrcweir }
192cdf0e10cSrcweir
193cdf0e10cSrcweir (void)_bMustExist;
194cdf0e10cSrcweir DBG_ASSERT(!_bMustExist || (aSearch != _rList.end()), "ODbaseIndexDialog::implRemoveIndex : did not find the index!");
195cdf0e10cSrcweir return aReturn;
196cdf0e10cSrcweir }
197cdf0e10cSrcweir
198cdf0e10cSrcweir //-------------------------------------------------------------------------
implInsertIndex(const OTableIndex & _rIndex,TableIndexList & _rList,ListBox & _rDisplay)199cdf0e10cSrcweir void ODbaseIndexDialog::implInsertIndex(const OTableIndex& _rIndex, TableIndexList& _rList, ListBox& _rDisplay)
200cdf0e10cSrcweir {
201cdf0e10cSrcweir _rList.push_front( _rIndex );
202cdf0e10cSrcweir _rDisplay.InsertEntry( _rIndex.GetIndexFileName() );
203cdf0e10cSrcweir _rDisplay.SelectEntryPos(0);
204cdf0e10cSrcweir }
205cdf0e10cSrcweir
206cdf0e10cSrcweir //-------------------------------------------------------------------------
RemoveTableIndex(const String & _rTableName,const String & _rIndexName,sal_Bool _bMustExist)207cdf0e10cSrcweir OTableIndex ODbaseIndexDialog::RemoveTableIndex( const String& _rTableName, const String& _rIndexName, sal_Bool _bMustExist )
208cdf0e10cSrcweir {
209cdf0e10cSrcweir OTableIndex aReturn;
210cdf0e10cSrcweir
211cdf0e10cSrcweir // does the table exist ?
212cdf0e10cSrcweir TableInfoListIterator aTablePos;
213cdf0e10cSrcweir if (!GetTable(_rTableName, aTablePos))
214cdf0e10cSrcweir return aReturn;
215cdf0e10cSrcweir
216cdf0e10cSrcweir return implRemoveIndex(_rIndexName, aTablePos->aIndexList, aLB_TableIndexes, _bMustExist);
217cdf0e10cSrcweir }
218cdf0e10cSrcweir
219cdf0e10cSrcweir //-------------------------------------------------------------------------
InsertTableIndex(const String & _rTableName,const OTableIndex & _rIndex)220cdf0e10cSrcweir void ODbaseIndexDialog::InsertTableIndex( const String& _rTableName, const OTableIndex& _rIndex)
221cdf0e10cSrcweir {
222cdf0e10cSrcweir TableInfoListIterator aTablePos;
223cdf0e10cSrcweir if (!GetTable(_rTableName, aTablePos))
224cdf0e10cSrcweir return;
225cdf0e10cSrcweir
226cdf0e10cSrcweir implInsertIndex(_rIndex, aTablePos->aIndexList, aLB_TableIndexes);
227cdf0e10cSrcweir }
228cdf0e10cSrcweir
229cdf0e10cSrcweir //-------------------------------------------------------------------------
230cdf0e10cSrcweir IMPL_LINK( ODbaseIndexDialog, OKClickHdl, PushButton*, /*pButton*/ )
231cdf0e10cSrcweir {
232cdf0e10cSrcweir // let all tables write their INF file
233cdf0e10cSrcweir
234cdf0e10cSrcweir for ( ConstTableInfoListIterator aLoop = m_aTableInfoList.begin();
235cdf0e10cSrcweir aLoop != m_aTableInfoList.end();
236cdf0e10cSrcweir ++aLoop
237cdf0e10cSrcweir )
238cdf0e10cSrcweir aLoop->WriteInfFile(m_aDSN);
239cdf0e10cSrcweir
240cdf0e10cSrcweir EndDialog();
241cdf0e10cSrcweir return 0;
242cdf0e10cSrcweir }
243cdf0e10cSrcweir
244cdf0e10cSrcweir //-------------------------------------------------------------------------
245cdf0e10cSrcweir IMPL_LINK( ODbaseIndexDialog, AddClickHdl, PushButton*, /*pButton*/ )
246cdf0e10cSrcweir {
247cdf0e10cSrcweir String aSelection = aLB_FreeIndexes.GetSelectEntry();
248cdf0e10cSrcweir String aTableName = aCB_Tables.GetText();
249cdf0e10cSrcweir OTableIndex aIndex = RemoveFreeIndex( aSelection, sal_True );
250cdf0e10cSrcweir InsertTableIndex( aTableName, aIndex );
251cdf0e10cSrcweir
252cdf0e10cSrcweir checkButtons();
253cdf0e10cSrcweir return 0;
254cdf0e10cSrcweir }
255cdf0e10cSrcweir
256cdf0e10cSrcweir //-------------------------------------------------------------------------
257cdf0e10cSrcweir IMPL_LINK( ODbaseIndexDialog, RemoveClickHdl, PushButton*, /*pButton*/ )
258cdf0e10cSrcweir {
259cdf0e10cSrcweir String aSelection = aLB_TableIndexes.GetSelectEntry();
260cdf0e10cSrcweir String aTableName = aCB_Tables.GetText();
261cdf0e10cSrcweir OTableIndex aIndex = RemoveTableIndex( aTableName, aSelection, sal_True );
262cdf0e10cSrcweir InsertFreeIndex( aIndex );
263cdf0e10cSrcweir
264cdf0e10cSrcweir checkButtons();
265cdf0e10cSrcweir return 0;
266cdf0e10cSrcweir }
267cdf0e10cSrcweir
268cdf0e10cSrcweir //-------------------------------------------------------------------------
269cdf0e10cSrcweir IMPL_LINK( ODbaseIndexDialog, AddAllClickHdl, PushButton*, /*pButton*/ )
270cdf0e10cSrcweir {
271cdf0e10cSrcweir sal_uInt16 nCnt = aLB_FreeIndexes.GetEntryCount();
272cdf0e10cSrcweir String aTableName = aCB_Tables.GetText();
273cdf0e10cSrcweir String aEntry;
274cdf0e10cSrcweir
275cdf0e10cSrcweir for( sal_uInt16 nPos = 0; nPos < nCnt; ++nPos )
276cdf0e10cSrcweir InsertTableIndex( aTableName, RemoveFreeIndex( aLB_FreeIndexes.GetEntry(0), sal_True ) );
277cdf0e10cSrcweir
278cdf0e10cSrcweir checkButtons();
279cdf0e10cSrcweir return 0;
280cdf0e10cSrcweir }
281cdf0e10cSrcweir
282cdf0e10cSrcweir //-------------------------------------------------------------------------
283cdf0e10cSrcweir IMPL_LINK( ODbaseIndexDialog, RemoveAllClickHdl, PushButton*, /*pButton*/ )
284cdf0e10cSrcweir {
285cdf0e10cSrcweir sal_uInt16 nCnt = aLB_TableIndexes.GetEntryCount();
286cdf0e10cSrcweir String aTableName = aCB_Tables.GetText();
287cdf0e10cSrcweir String aEntry;
288cdf0e10cSrcweir
289cdf0e10cSrcweir for( sal_uInt16 nPos = 0; nPos < nCnt; ++nPos )
290cdf0e10cSrcweir InsertFreeIndex( RemoveTableIndex( aTableName, aLB_TableIndexes.GetEntry(0), sal_True ) );
291cdf0e10cSrcweir
292cdf0e10cSrcweir checkButtons();
293cdf0e10cSrcweir return 0;
294cdf0e10cSrcweir }
295cdf0e10cSrcweir
296cdf0e10cSrcweir //-------------------------------------------------------------------------
297cdf0e10cSrcweir IMPL_LINK( ODbaseIndexDialog, OnListEntrySelected, ListBox*, /*NOTINTERESTEDIN*/ )
298cdf0e10cSrcweir {
299cdf0e10cSrcweir checkButtons();
300cdf0e10cSrcweir return 0;
301cdf0e10cSrcweir }
302cdf0e10cSrcweir
303cdf0e10cSrcweir //-------------------------------------------------------------------------
IMPL_LINK(ODbaseIndexDialog,TableSelectHdl,ComboBox *,pComboBox)304cdf0e10cSrcweir IMPL_LINK( ODbaseIndexDialog, TableSelectHdl, ComboBox*, pComboBox )
305cdf0e10cSrcweir {
306cdf0e10cSrcweir // search the table
307cdf0e10cSrcweir TableInfoListIterator aTablePos;
308cdf0e10cSrcweir if (!GetTable(pComboBox->GetText(), aTablePos))
309cdf0e10cSrcweir return 0L;
310cdf0e10cSrcweir
311cdf0e10cSrcweir // fill the listbox for the indexes
312cdf0e10cSrcweir aLB_TableIndexes.Clear();
313cdf0e10cSrcweir for ( ConstTableIndexListIterator aLoop = aTablePos->aIndexList.begin();
314cdf0e10cSrcweir aLoop != aTablePos->aIndexList.end();
315cdf0e10cSrcweir ++aLoop
316cdf0e10cSrcweir )
317cdf0e10cSrcweir aLB_TableIndexes.InsertEntry( aLoop->GetIndexFileName() );
318cdf0e10cSrcweir
319cdf0e10cSrcweir if ( aTablePos->aIndexList.size() )
320cdf0e10cSrcweir aLB_TableIndexes.SelectEntryPos(0);
321cdf0e10cSrcweir
322cdf0e10cSrcweir checkButtons();
323cdf0e10cSrcweir return 0;
324cdf0e10cSrcweir }
325cdf0e10cSrcweir
326cdf0e10cSrcweir //-------------------------------------------------------------------------
Init()327cdf0e10cSrcweir void ODbaseIndexDialog::Init()
328cdf0e10cSrcweir {
329cdf0e10cSrcweir aPB_OK.Disable();
330cdf0e10cSrcweir m_FL_Indexes.Disable();
331cdf0e10cSrcweir m_FT_TableIndexes.Disable();
332cdf0e10cSrcweir aLB_TableIndexes.Disable();
333cdf0e10cSrcweir m_FT_AllIndexes.Disable();
334cdf0e10cSrcweir aLB_FreeIndexes.Disable();
335cdf0e10cSrcweir aIB_Add.Disable();
336cdf0e10cSrcweir aIB_Remove.Disable();
337cdf0e10cSrcweir aIB_AddAll.Disable();
338cdf0e10cSrcweir aIB_RemoveAll.Disable();
339cdf0e10cSrcweir
340cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////
341cdf0e10cSrcweir // Alle Indizes werden erst einmal zur Liste der freien Indizes hinzugefuegt.
342cdf0e10cSrcweir // Dann wird fuer jede Tabelle in der Inf-Datei nachgeschaut, welche Indizes sie besitzt.
343cdf0e10cSrcweir // Diese Indizes werden aus der Liste der freien Indizes entfernt
344cdf0e10cSrcweir // und in die Indexliste der Tabelle eingetragen
345cdf0e10cSrcweir
346cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////
347cdf0e10cSrcweir // if the string does not contain a path, cut the string
348cdf0e10cSrcweir INetURLObject aURL;
349cdf0e10cSrcweir aURL.SetSmartProtocol(INET_PROT_FILE);
350cdf0e10cSrcweir {
351cdf0e10cSrcweir SvtPathOptions aPathOptions;
352cdf0e10cSrcweir m_aDSN = aPathOptions.SubstituteVariable(m_aDSN);
353cdf0e10cSrcweir }
354cdf0e10cSrcweir aURL.SetSmartURL(m_aDSN);
355cdf0e10cSrcweir
356cdf0e10cSrcweir
357cdf0e10cSrcweir // String aFileName = aURL.PathToFileName();
358cdf0e10cSrcweir m_aDSN = aURL.GetMainURL(INetURLObject::NO_DECODE);
359cdf0e10cSrcweir ::ucbhelper::Content aFile;
360cdf0e10cSrcweir sal_Bool bFolder=sal_True;
361cdf0e10cSrcweir try
362cdf0e10cSrcweir {
363cdf0e10cSrcweir aFile = ::ucbhelper::Content(m_aDSN,Reference< ::com::sun::star::ucb::XCommandEnvironment >());
364cdf0e10cSrcweir bFolder = aFile.isFolder();
365cdf0e10cSrcweir }
366cdf0e10cSrcweir catch(Exception&)
367cdf0e10cSrcweir {
368cdf0e10cSrcweir return;
369cdf0e10cSrcweir }
370cdf0e10cSrcweir
371cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////
372cdf0e10cSrcweir // first assume for all indexes they're free
373cdf0e10cSrcweir
374cdf0e10cSrcweir Sequence< ::rtl::OUString> aFolderContent( ::utl::LocalFileHelper::GetFolderContents(m_aDSN,bFolder));
375cdf0e10cSrcweir
376cdf0e10cSrcweir ::rtl::OUString aIndexExt = ::rtl::OUString::createFromAscii("ndx");
377cdf0e10cSrcweir ::rtl::OUString aTableExt = ::rtl::OUString::createFromAscii("dbf");
378cdf0e10cSrcweir
379cdf0e10cSrcweir ::std::vector< String > aUsedIndexes;
380cdf0e10cSrcweir
381cdf0e10cSrcweir String aExt;
382cdf0e10cSrcweir const ::rtl::OUString *pBegin = aFolderContent.getConstArray();
383cdf0e10cSrcweir const ::rtl::OUString *pEnd = pBegin + aFolderContent.getLength();
384cdf0e10cSrcweir aURL.SetSmartProtocol(INET_PROT_FILE);
385cdf0e10cSrcweir for(;pBegin != pEnd;++pBegin)
386cdf0e10cSrcweir {
387cdf0e10cSrcweir String aName;
388cdf0e10cSrcweir ::utl::LocalFileHelper::ConvertURLToPhysicalName(pBegin->getStr(),aName);
389cdf0e10cSrcweir aURL.SetSmartURL(aName);
390cdf0e10cSrcweir aExt = aURL.getExtension();
391cdf0e10cSrcweir if(aExt == aIndexExt.getStr())
392cdf0e10cSrcweir {
393cdf0e10cSrcweir m_aFreeIndexList.push_back( OTableIndex(aURL.getName()) );
394cdf0e10cSrcweir }
395cdf0e10cSrcweir else if(aExt == aTableExt.getStr())
396cdf0e10cSrcweir {
397cdf0e10cSrcweir m_aTableInfoList.push_back( OTableInfo(aURL.getName()) );
398cdf0e10cSrcweir OTableInfo& rTabInfo = m_aTableInfoList.back();
399cdf0e10cSrcweir
400cdf0e10cSrcweir // open the INF file
401cdf0e10cSrcweir aURL.setExtension(String::CreateFromAscii("inf"));
402cdf0e10cSrcweir OFileNotation aTransformer(aURL.GetURLNoPass(), OFileNotation::N_URL);
403cdf0e10cSrcweir Config aInfFile( aTransformer.get(OFileNotation::N_SYSTEM) );
404cdf0e10cSrcweir aInfFile.SetGroup( aGroupIdent );
405cdf0e10cSrcweir
406cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////
407cdf0e10cSrcweir // fill the indexes list
408cdf0e10cSrcweir ByteString aNDX;
409cdf0e10cSrcweir sal_uInt16 nKeyCnt = aInfFile.GetKeyCount();
410cdf0e10cSrcweir ByteString aKeyName;
411cdf0e10cSrcweir String aEntry;
412cdf0e10cSrcweir
413cdf0e10cSrcweir for( sal_uInt16 nKey = 0; nKey < nKeyCnt; nKey++ )
414cdf0e10cSrcweir {
415cdf0e10cSrcweir // does the key point to an index file ?
416cdf0e10cSrcweir aKeyName = aInfFile.GetKeyName( nKey );
417cdf0e10cSrcweir aNDX = aKeyName.Copy(0,3);
418cdf0e10cSrcweir
419cdf0e10cSrcweir // yes -> add to the tables index list
420cdf0e10cSrcweir if (aNDX == "NDX" )
421cdf0e10cSrcweir {
422cdf0e10cSrcweir aEntry = String(aInfFile.ReadKey(aKeyName), gsl_getSystemTextEncoding());
423cdf0e10cSrcweir rTabInfo.aIndexList.push_back( OTableIndex( aEntry ) );
424cdf0e10cSrcweir
425cdf0e10cSrcweir // and remove it from the free index list
426cdf0e10cSrcweir aUsedIndexes.push_back(aEntry);
427cdf0e10cSrcweir // do this later below. We may not have encountered the index file, yet, thus we may not
42830acf5e8Spfg // know the index as being free, yet
429cdf0e10cSrcweir }
430cdf0e10cSrcweir
431cdf0e10cSrcweir }
432cdf0e10cSrcweir }
433cdf0e10cSrcweir }
434cdf0e10cSrcweir
435cdf0e10cSrcweir for ( ::std::vector< String >::const_iterator aUsedIndex = aUsedIndexes.begin();
436cdf0e10cSrcweir aUsedIndex != aUsedIndexes.end();
437cdf0e10cSrcweir ++aUsedIndex
438cdf0e10cSrcweir )
439cdf0e10cSrcweir RemoveFreeIndex( *aUsedIndex, sal_False );
440cdf0e10cSrcweir
441cdf0e10cSrcweir if (m_aTableInfoList.size())
442cdf0e10cSrcweir {
443cdf0e10cSrcweir aPB_OK.Enable();
444cdf0e10cSrcweir m_FL_Indexes.Enable();
445cdf0e10cSrcweir m_FT_TableIndexes.Enable();
446cdf0e10cSrcweir aLB_TableIndexes.Enable();
447cdf0e10cSrcweir m_FT_AllIndexes.Enable();
448cdf0e10cSrcweir aLB_FreeIndexes.Enable();
449cdf0e10cSrcweir }
450cdf0e10cSrcweir
451cdf0e10cSrcweir checkButtons();
452cdf0e10cSrcweir }
453cdf0e10cSrcweir
454cdf0e10cSrcweir //-------------------------------------------------------------------------
SetCtrls()455cdf0e10cSrcweir void ODbaseIndexDialog::SetCtrls()
456cdf0e10cSrcweir {
457cdf0e10cSrcweir // ComboBox Tabellen
458cdf0e10cSrcweir for ( ConstTableInfoListIterator aLoop = m_aTableInfoList.begin();
459cdf0e10cSrcweir aLoop != m_aTableInfoList.end();
460cdf0e10cSrcweir ++aLoop
461cdf0e10cSrcweir )
462cdf0e10cSrcweir aCB_Tables.InsertEntry( aLoop->aTableName );
463cdf0e10cSrcweir
464cdf0e10cSrcweir // Den ersten Datensatz ins Edit stellen
465cdf0e10cSrcweir if( m_aTableInfoList.size() )
466cdf0e10cSrcweir {
467cdf0e10cSrcweir const OTableInfo& rTabInfo = m_aTableInfoList.front();
468cdf0e10cSrcweir aCB_Tables.SetText( rTabInfo.aTableName );
469cdf0e10cSrcweir
470cdf0e10cSrcweir // ListBox der Tabellenindizes aufbauen
471cdf0e10cSrcweir for ( ConstTableIndexListIterator aIndex = rTabInfo.aIndexList.begin();
472cdf0e10cSrcweir aIndex != rTabInfo.aIndexList.end();
473cdf0e10cSrcweir ++aIndex
474cdf0e10cSrcweir )
475cdf0e10cSrcweir aLB_TableIndexes.InsertEntry( aIndex->GetIndexFileName() );
476cdf0e10cSrcweir
477cdf0e10cSrcweir if( rTabInfo.aIndexList.size() )
478cdf0e10cSrcweir aLB_TableIndexes.SelectEntryPos( 0 );
479cdf0e10cSrcweir
480cdf0e10cSrcweir }
481cdf0e10cSrcweir
482cdf0e10cSrcweir // ListBox freie Indizes
483cdf0e10cSrcweir for ( ConstTableIndexListIterator aFree = m_aFreeIndexList.begin();
484cdf0e10cSrcweir aFree != m_aFreeIndexList.end();
485cdf0e10cSrcweir ++aFree
486cdf0e10cSrcweir )
487cdf0e10cSrcweir aLB_FreeIndexes.InsertEntry( aFree->GetIndexFileName() );
488cdf0e10cSrcweir
489cdf0e10cSrcweir if( m_aFreeIndexList.size() )
490cdf0e10cSrcweir aLB_FreeIndexes.SelectEntryPos( 0 );
491cdf0e10cSrcweir
492cdf0e10cSrcweir
493cdf0e10cSrcweir TableSelectHdl(&aCB_Tables);
494cdf0e10cSrcweir checkButtons();
495cdf0e10cSrcweir }
496cdf0e10cSrcweir
497cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////
498cdf0e10cSrcweir // Klasse OTableInfo
499cdf0e10cSrcweir //-------------------------------------------------------------------------
WriteInfFile(const String & rDSN) const500cdf0e10cSrcweir void OTableInfo::WriteInfFile( const String& rDSN ) const
501cdf0e10cSrcweir {
502cdf0e10cSrcweir // INF-Datei oeffnen
503cdf0e10cSrcweir INetURLObject aURL;
504cdf0e10cSrcweir aURL.SetSmartProtocol(INET_PROT_FILE);
505cdf0e10cSrcweir String aDsn = rDSN;
506cdf0e10cSrcweir {
507cdf0e10cSrcweir SvtPathOptions aPathOptions;
508cdf0e10cSrcweir aDsn = aPathOptions.SubstituteVariable(aDsn);
509cdf0e10cSrcweir }
510cdf0e10cSrcweir aURL.SetSmartURL(aDsn);
511cdf0e10cSrcweir aURL.Append(aTableName);
512cdf0e10cSrcweir aURL.setExtension(String::CreateFromAscii("inf"));
513cdf0e10cSrcweir
514cdf0e10cSrcweir OFileNotation aTransformer(aURL.GetURLNoPass(), OFileNotation::N_URL);
515cdf0e10cSrcweir Config aInfFile( aTransformer.get(OFileNotation::N_SYSTEM) );
516cdf0e10cSrcweir aInfFile.SetGroup( aGroupIdent );
517cdf0e10cSrcweir
518cdf0e10cSrcweir // Erst einmal alle Tabellenindizes loeschen
519cdf0e10cSrcweir ByteString aNDX;
520cdf0e10cSrcweir sal_uInt16 nKeyCnt = aInfFile.GetKeyCount();
521cdf0e10cSrcweir ByteString aKeyName;
522cdf0e10cSrcweir ByteString aEntry;
523cdf0e10cSrcweir sal_uInt16 nKey = 0;
524cdf0e10cSrcweir
525cdf0e10cSrcweir while( nKey < nKeyCnt )
526cdf0e10cSrcweir {
527cdf0e10cSrcweir // Verweist der Key auf ein Indexfile?...
528cdf0e10cSrcweir aKeyName = aInfFile.GetKeyName( nKey );
529cdf0e10cSrcweir aNDX = aKeyName.Copy(0,3);
530cdf0e10cSrcweir
531cdf0e10cSrcweir //...wenn ja, Indexfile loeschen, nKey steht dann auf nachfolgendem Key
532cdf0e10cSrcweir if( aNDX == "NDX" )
533cdf0e10cSrcweir {
534cdf0e10cSrcweir aInfFile.DeleteKey(aKeyName);
535cdf0e10cSrcweir nKeyCnt--;
536cdf0e10cSrcweir }
537cdf0e10cSrcweir else
538cdf0e10cSrcweir nKey++;
539cdf0e10cSrcweir
540cdf0e10cSrcweir }
541cdf0e10cSrcweir
542cdf0e10cSrcweir // Jetzt alle gespeicherten Indizes hinzufuegen
543cdf0e10cSrcweir sal_uInt16 nPos = 0;
544cdf0e10cSrcweir for ( ConstTableIndexListIterator aIndex = aIndexList.begin();
545cdf0e10cSrcweir aIndex != aIndexList.end();
546cdf0e10cSrcweir ++aIndex, ++nPos
547cdf0e10cSrcweir )
548cdf0e10cSrcweir {
549cdf0e10cSrcweir aKeyName = "NDX";
550cdf0e10cSrcweir if( nPos > 0 ) // Erster Index erhaelt keine Ziffer
551cdf0e10cSrcweir aKeyName += ByteString::CreateFromInt32( nPos );
552cdf0e10cSrcweir aInfFile.WriteKey( aKeyName, ByteString(aIndex->GetIndexFileName(), gsl_getSystemTextEncoding()) );
553cdf0e10cSrcweir }
554cdf0e10cSrcweir
555cdf0e10cSrcweir aInfFile.Flush();
556cdf0e10cSrcweir
557cdf0e10cSrcweir // Falls nur noch [dbase] in INF-File steht, Datei loeschen
558cdf0e10cSrcweir if(!nPos)
559cdf0e10cSrcweir {
560cdf0e10cSrcweir try
561cdf0e10cSrcweir {
562cdf0e10cSrcweir ::ucbhelper::Content aContent(aURL.GetURLNoPass(),Reference<XCommandEnvironment>());
563cdf0e10cSrcweir aContent.executeCommand( rtl::OUString::createFromAscii( "delete" ),makeAny( sal_Bool( sal_True ) ) );
564cdf0e10cSrcweir }
565cdf0e10cSrcweir catch (const Exception& e )
566cdf0e10cSrcweir {
567cdf0e10cSrcweir (void)e; // make compiler happy
568cdf0e10cSrcweir // simply silent this. The strange algorithm here does a lot of things even if no files at all were
569cdf0e10cSrcweir // created or accessed, so it's possible that the file we're trying to delete does not even exist,
570cdf0e10cSrcweir // and this is a valid condition.
571cdf0e10cSrcweir // 2003-05-15 - #109677# - fs@openoffice.org
572cdf0e10cSrcweir }
573cdf0e10cSrcweir }
574cdf0e10cSrcweir }
575cdf0e10cSrcweir
576cdf0e10cSrcweir //.........................................................................
577cdf0e10cSrcweir } // namespace dbaui
578cdf0e10cSrcweir //.........................................................................
579cdf0e10cSrcweir
580