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