1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef adabasui_ADABAS_CREATEDB_HXX
25 #include "AdabasNewDb.hxx"
26 #endif
27 #ifndef adabasui_ADABASNEWDB_HRC
28 #include "AdabasNewDb.hrc"
29 #endif
30 
31 #ifndef _VOS_PROCESS_HXX_
32 #include <vos/process.hxx>
33 #endif
34 #ifndef _OSL_PROCESS_H_
35 #include <osl/process.h>
36 #endif
37 #ifndef _MSGBOX_HXX //autogen
38 #include <vcl/msgbox.hxx>
39 #endif
40 #ifndef _PASSWD_HXX //autogen
41 #include <sfx2/passwd.hxx>
42 #endif
43 #ifndef _URLOBJ_HXX
44 #include <tools/urlobj.hxx>
45 #endif
46 #ifndef _STREAM_HXX
47 #include <tools/stream.hxx>
48 #endif
49 #ifndef _BIGINT_HXX
50 #include <tools/bigint.hxx>
51 #endif
52 #ifndef _TOOLS_DEBUG_HXX
53 #include <tools/debug.hxx>
54 #endif
55 #ifndef _EXTENSIONS_COMPONENT_MODULE_HXX_
56 #include "Acomponentmodule.hxx"
57 #endif
58 #ifndef _UNOTOOLS_TEMPFILE_HXX
59 #include <unotools/tempfile.hxx>
60 #endif
61 #ifndef _ADABASUI_RESOURCE_HRC_
62 #include "adabasui_resource.hrc"
63 #endif
64 #ifndef _UCBHELPER_CONTENT_HXX
65 #include <ucbhelper/content.hxx>
66 #endif
67 #ifndef _SV_WAITOBJ_HXX
68 #include <vcl/waitobj.hxx>
69 #endif
70 #ifndef INCLUDED_SVTOOLS_PATHOPTIONS_HXX
71 #include <unotools/pathoptions.hxx>
72 #endif
73 #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
74 #include <toolkit/helper/vclunohelper.hxx>
75 #endif
76 #ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP_
77 #include <com/sun/star/beans/PropertyValue.hpp>
78 #endif
79 #ifndef _COMPHELPER_EXTRACT_HXX_
80 #include <comphelper/extract.hxx>
81 #endif
82 #ifndef _UNOTOOLS_TEMPFILE_HXX
83 #include <unotools/tempfile.hxx>
84 #endif
85 #ifndef _UNOTOOLS_LOCALFILEHELPER_HXX
86 #include <unotools/localfilehelper.hxx>
87 #endif
88 #ifndef _COM_SUN_STAR_SDBC_SQLEXCEPTION_HPP_
89 #include <com/sun/star/sdbc/SQLException.hpp>
90 #endif
91 #ifndef _UNOTOOLS_UCBHELPER_HXX
92 #include <unotools/ucbhelper.hxx>
93 #endif
94 #ifndef _CONNECTIVITY_DBTOOLS_HXX_
95 #include <connectivity/dbtools.hxx>
96 #endif
97 #ifndef _DBHELPER_DBEXCEPTION_HXX_
98 #include <connectivity/dbexception.hxx>
99 #endif
100 #include "adabasuistrings.hrc"
101 #ifndef _THREAD_HXX_
102 #include <osl/thread.hxx>
103 #endif
104 #ifndef _OSL_FILE_HXX_
105 #include <osl/file.hxx>
106 #endif
107 
108 
109 using namespace adabasui;
110 using namespace ucbhelper;
111 using namespace utl;
112 using namespace vos;
113 using namespace ::com::sun::star::uno;
114 using namespace ::com::sun::star::beans;
115 using namespace ::com::sun::star::sdbcx;
116 using namespace ::com::sun::star::sdbc;
117 using namespace ::com::sun::star::ucb;
118 using namespace ::com::sun::star::lang;
119 namespace adabasui
120 {
121 	class ODatabaseCreator : public ::osl::Thread
122 	{
123 		Link								m_aTerminateHandler;
124 		Sequence< PropertyValue>			m_aValues;
125 		Reference<XCreateCatalog>			m_xCreateCatalog;
126 		Reference< XMultiServiceFactory >	m_xORB;
127 		Window*								m_pErrorWindow;
128 	public:
ODatabaseCreator(const Reference<XCreateCatalog> & _rxCreateCatalog,Window * _pErrorWindow,const Reference<XMultiServiceFactory> & _xORB,const Sequence<PropertyValue> & _rValues)129 		ODatabaseCreator(const Reference<XCreateCatalog>& _rxCreateCatalog
130 						,Window* _pErrorWindow
131 						,const Reference< XMultiServiceFactory >& _xORB
132 						,const Sequence< PropertyValue>& _rValues)
133             : m_aValues(_rValues)
134 			, m_xCreateCatalog(_rxCreateCatalog)
135 			, m_xORB(_xORB)
136 			, m_pErrorWindow(_pErrorWindow)
137 		{}
138 
setTerminateHandler(const Link & _aTerminateHandler)139 		void setTerminateHandler(const Link& _aTerminateHandler) { m_aTerminateHandler = _aTerminateHandler; }
140 
141 	protected:
142 
143 		/// Working method which should be overridden.
144 		virtual void SAL_CALL run();
145 		virtual void SAL_CALL onTerminated();
146 	};
147 
run()148 	void SAL_CALL ODatabaseCreator::run()
149 	{
150 		try
151 		{
152 			m_xCreateCatalog->createCatalog(m_aValues);
153 		}
154 		catch(SQLException& e)
155 		{
156 			::dbtools::showError(::dbtools::SQLExceptionInfo(e),VCLUnoHelper::GetInterface(m_pErrorWindow),m_xORB);
157 		}
158 		catch(Exception&)
159 		{
160 			OSL_ASSERT(0);
161 			//	showError(::dbtools::SQLExceptionInfo(e),this,);
162 		}
163 	}
onTerminated()164 	void SAL_CALL ODatabaseCreator::onTerminated()
165 	{
166 		if ( m_aTerminateHandler.IsSet() )
167 			m_aTerminateHandler.Call(NULL);
168 	}
169 }
DBG_NAME(OAdabasNewDbDlg)170 DBG_NAME( OAdabasNewDbDlg )
171 //========================================================================
172 OAdabasNewDbDlg::OAdabasNewDbDlg( Window* pParent,
173 								 const Reference<XCreateCatalog>& _rxCreateCatalog,
174 								 const Reference< XMultiServiceFactory >&	_rxORB,
175 								 sal_Bool _bRestore)
176     :ModalDialog( pParent, ModuleRes( DLG_ADABAS_NEWDB ))
177     ,m_FT_DATABASENAME(         this, ModuleRes( FT_DATABASENAME        ) )
178     ,m_ET_DATABASENAME(         this, ModuleRes( ET_DATABASENAME        ) )
179     ,m_FL_USER(                 this, ModuleRes( FL_USER                ) )
180     ,m_FT_SYSUSR(               this, ModuleRes( FT_SYSUSR              ) )
181     ,m_FT_CONUSR(               this, ModuleRes( FT_CONUSR              ) )
182     ,m_FT_DOMAIN_USR(           this, ModuleRes( FT_DOMAIN_USR          ) )
183     ,m_ET_SYSUSR(               this, ModuleRes( ET_SYSUSR              ) )
184     ,m_PB_SYSPWD(               this, ModuleRes( PB_SYSPWD              ) )
185     ,m_ET_CONUSR(               this, ModuleRes( ET_CONUSR              ) )
186     ,m_PB_CONPWD(               this, ModuleRes( PB_CONPWD              ) )
187     ,m_ET_DOMAIN_USR(           this, ModuleRes( ET_DOMAIN_USR          ) )
188     ,m_PB_DOMAINPWD(            this, ModuleRes( PB_DOMAINPWD           ) )
189     ,m_BMP_CON(                 this, ModuleRes( BMP_CON                ) )
190     ,m_BMP_SYS(                 this, ModuleRes( BMP_SYS                ) )
191     ,m_BMP_DOMAIN(              this, ModuleRes( BMP_DOMAIN             ) )
192     ,m_FT_RESTORE(              this, ModuleRes( FT_RESTORE             ) )
193     ,m_ET_RESTORE(              this, ModuleRes( ET_RESTORE             ) )
194     ,m_PB_RESTORE(              this, ModuleRes( PB_RESTORE             ) )
195     ,m_FL_DBSETTINGS(           this, ModuleRes( FL_DBSETTINGS          ) )
196     ,m_FT_SYSDEVSPACE(          this, ModuleRes( FT_SYSDEVSPACE         ) )
197     ,m_FT_TRANSACTIONLOG(       this, ModuleRes( FT_TRANSACTIONLOG      ) )
198     ,m_FT_DATADEVSPACE(         this, ModuleRes( FT_DATADEVSPACE        ) )
199     ,m_ET_SYSDEVSPACE(          this, ModuleRes( ET_SYSDEVSPACE         ) )
200     ,m_PB_SYSDEVSPACE(          this, ModuleRes( PB_SYSDEVSPACE         ) )
201     ,m_ET_TRANSACTIONLOG(       this, ModuleRes( ET_TRANSACTIONLOG      ) )
202     ,m_PB_TRANSACTIONLOG(       this, ModuleRes( PB_TRANSACTIONLOG      ) )
203     ,m_ET_DATADEVSPACE(         this, ModuleRes( ET_DATADEVSPACE        ) )
204     ,m_PB_DATADEVSPACE(         this, ModuleRes( PB_DATADEVSPACE        ) )
205     ,m_FT_TRANSACTIONLOG_SIZE(  this, ModuleRes( FT_TRANSACTIONLOG_SIZE ) )
206     ,m_NF_TRANSACTIONLOG_SIZE(  this, ModuleRes( NF_TRANSACTIONLOG_SIZE ) )
207     ,m_FT_DATADEVSPACE_SIZE(    this, ModuleRes( FT_DATADEVSPACE_SIZE   ) )
208     ,m_NF_DATADEVSPACE_SIZE(    this, ModuleRes( NF_DATADEVSPACE_SIZE   ) )
209     ,m_FT_CACHE_SIZE(           this, ModuleRes( FT_CACHE_SIZE          ) )
210     ,m_NF_CACHE_SIZE(           this, ModuleRes( NF_CACHE_SIZE          ) )
211     ,m_FL_END(                  this, ModuleRes( FL_END                 ) )
212     ,m_PB_OK(                   this, ModuleRes( PB_OK                  ) )
213     ,m_PB_CANCEL(               this, ModuleRes( PB_CANCEL              ) )
214     ,m_xCreateCatalog(_rxCreateCatalog)
215     ,m_xORB(_rxORB)
216     ,m_bRestore(_bRestore)
217     ,m_nSetBitmap(0)
218 {
219 	DBG_CTOR( OAdabasNewDbDlg, NULL );
220 	FreeResource();
221 	if(m_bRestore)
222 	{
223         m_FL_DBSETTINGS.SetPosPixel(m_FL_DBSETTINGS.GetPosPixel()-LogicToPixel( Point(0,14), MAP_APPFONT ));
224 		m_FT_SYSDEVSPACE.SetPosPixel(m_FT_SYSDEVSPACE.GetPosPixel()-LogicToPixel( Point(0,14), MAP_APPFONT ));
225 		m_FT_TRANSACTIONLOG.SetPosPixel(m_FT_TRANSACTIONLOG.GetPosPixel()-LogicToPixel( Point(0,14), MAP_APPFONT ));
226 		m_FT_DATADEVSPACE.SetPosPixel(m_FT_DATADEVSPACE.GetPosPixel()-LogicToPixel( Point(0,14), MAP_APPFONT ));
227 		m_ET_SYSDEVSPACE.SetPosPixel(m_ET_SYSDEVSPACE.GetPosPixel()-LogicToPixel( Point(0,14), MAP_APPFONT ));
228 		m_PB_SYSDEVSPACE.SetPosPixel(m_PB_SYSDEVSPACE.GetPosPixel()-LogicToPixel( Point(0,14), MAP_APPFONT ));
229 		m_ET_TRANSACTIONLOG.SetPosPixel(m_ET_TRANSACTIONLOG.GetPosPixel()-LogicToPixel( Point(0,14), MAP_APPFONT ));
230 		m_PB_TRANSACTIONLOG.SetPosPixel(m_PB_TRANSACTIONLOG.GetPosPixel()-LogicToPixel( Point(0,14), MAP_APPFONT ));
231 		m_ET_DATADEVSPACE.SetPosPixel(m_ET_DATADEVSPACE.GetPosPixel()-LogicToPixel( Point(0,14), MAP_APPFONT ));
232 		m_PB_DATADEVSPACE.SetPosPixel(m_PB_DATADEVSPACE.GetPosPixel()-LogicToPixel( Point(0,14), MAP_APPFONT ));
233 		m_FT_TRANSACTIONLOG_SIZE.SetPosPixel(m_FT_TRANSACTIONLOG_SIZE.GetPosPixel()-LogicToPixel( Point(0,14), MAP_APPFONT ));
234 		m_NF_TRANSACTIONLOG_SIZE.SetPosPixel(m_NF_TRANSACTIONLOG_SIZE.GetPosPixel()-LogicToPixel( Point(0,14), MAP_APPFONT ));
235 		m_FT_DATADEVSPACE_SIZE.SetPosPixel(m_FT_DATADEVSPACE_SIZE.GetPosPixel()-LogicToPixel( Point(0,14), MAP_APPFONT ));
236 		m_NF_DATADEVSPACE_SIZE.SetPosPixel(m_NF_DATADEVSPACE_SIZE.GetPosPixel()-LogicToPixel( Point(0,14), MAP_APPFONT ));
237 		m_FT_CACHE_SIZE.SetPosPixel(m_FT_CACHE_SIZE.GetPosPixel()-LogicToPixel( Point(0,14), MAP_APPFONT ));
238 		m_NF_CACHE_SIZE.SetPosPixel(m_NF_CACHE_SIZE.GetPosPixel()-LogicToPixel( Point(0,14), MAP_APPFONT ));
239 		m_PB_OK.SetPosPixel(m_PB_OK.GetPosPixel()-LogicToPixel( Point(0,14), MAP_APPFONT ));
240 		m_PB_CANCEL.SetPosPixel(m_PB_CANCEL.GetPosPixel()-LogicToPixel( Point(0,14), MAP_APPFONT ));
241 
242 		Size aSize(GetSizePixel().Width(),GetSizePixel().Height()-LogicToPixel( Size(0,14), MAP_APPFONT ).Height());
243 		SetSizePixel(aSize);
244 
245 		m_FT_SYSUSR.Hide();
246 		m_FT_DOMAIN_USR.Hide();
247         m_FL_USER.SetText(ModuleRes(STR_BACKUPFILE_LOAD));
248 		m_PB_SYSPWD.Hide();
249 		m_PB_DOMAINPWD.Hide();
250 		m_ET_SYSUSR.Hide();
251 		m_ET_DOMAIN_USR.Hide();
252 
253 		m_ET_SYSUSR.SetText(String::CreateFromAscii("DUMMY"));
254 		m_BMP_SYS.Hide();
255 		m_BMP_DOMAIN.Hide();
256 		m_ET_RESTORE.SetModifyHdl(				LINK(this,OAdabasNewDbDlg,LoseFocusHdl));
257 		m_ET_RESTORE.SetLoseFocusHdl(			LINK(this,OAdabasNewDbDlg,LoseFocusHdl));
258 		m_ET_RESTORE.SetMaxTextLen(40);
259 	}
260 	else
261 	{
262 		m_FT_RESTORE.Hide();
263 		m_ET_RESTORE.Hide();
264 		m_PB_RESTORE.Hide();
265 
266 		m_ET_SYSUSR.SetModifyHdl(				LINK(this,OAdabasNewDbDlg,LoseFocusHdl));
267 		m_ET_CONUSR.SetModifyHdl(				LINK(this,OAdabasNewDbDlg,LoseFocusHdl));
268 		m_ET_DOMAIN_USR.Enable(sal_False);
269 
270 		//	m_ET_SYSUSR.setUpperCase();
271 		//	m_ET_CONUSR.setUpperCase();
272 	}
273 
274 
275 	m_ET_SYSDEVSPACE.SetLoseFocusHdl(		LINK(this,OAdabasNewDbDlg,LoseFocusHdl));
276 	m_ET_TRANSACTIONLOG.SetLoseFocusHdl(	LINK(this,OAdabasNewDbDlg,LoseFocusHdl));
277 	m_ET_DATADEVSPACE.SetLoseFocusHdl(		LINK(this,OAdabasNewDbDlg,LoseFocusHdl));
278 
279 	m_ET_SYSDEVSPACE.SetMaxTextLen(40);
280 	m_ET_TRANSACTIONLOG.SetMaxTextLen(40);
281 	m_ET_DATADEVSPACE.SetMaxTextLen(40);
282 
283 	m_NF_TRANSACTIONLOG_SIZE.SetModifyHdl(	LINK(this,OAdabasNewDbDlg,LoseFocusHdl));
284 	m_NF_DATADEVSPACE_SIZE.SetModifyHdl(	LINK(this,OAdabasNewDbDlg,LoseFocusHdl));
285 	m_NF_CACHE_SIZE.SetModifyHdl(			LINK(this,OAdabasNewDbDlg,LoseFocusHdl));
286 
287 	m_NF_TRANSACTIONLOG_SIZE.SetMin(10);
288 	m_NF_DATADEVSPACE_SIZE.SetMin(10);
289 	m_NF_CACHE_SIZE.SetMin(4);
290 
291 	m_NF_TRANSACTIONLOG_SIZE.SetMax(LONG_MAX);
292 	m_NF_DATADEVSPACE_SIZE.SetMax(LONG_MAX);
293 	m_NF_CACHE_SIZE.SetMax(LONG_MAX);
294 
295 	m_NF_TRANSACTIONLOG_SIZE.SetValue(20);
296 	m_NF_DATADEVSPACE_SIZE.SetValue(20);
297 	m_NF_CACHE_SIZE.SetValue(4);
298 
299 	m_NF_TRANSACTIONLOG_SIZE.SetDecimalDigits(0);
300 	m_NF_DATADEVSPACE_SIZE.SetDecimalDigits(0);
301 	m_NF_CACHE_SIZE.SetDecimalDigits(0);
302 
303 	m_ET_DATABASENAME.SetMaxTextLen( 8 ); //98292
304 
305 	m_PB_CONPWD.SetClickHdl(			LINK(this,OAdabasNewDbDlg,PwdClickHdl));
306 	m_PB_SYSPWD.SetClickHdl(			LINK(this,OAdabasNewDbDlg,PwdClickHdl));
307 	m_PB_DOMAINPWD.SetClickHdl(			LINK(this,OAdabasNewDbDlg,PwdClickHdl));
308 
309 	m_PB_RESTORE.SetClickHdl(			LINK(this,OAdabasNewDbDlg,LoadButtonClickHdl));
310 
311 	m_PB_SYSDEVSPACE.SetClickHdl(		LINK(this,OAdabasNewDbDlg,ButtonClickHdl));
312 	m_PB_TRANSACTIONLOG.SetClickHdl(	LINK(this,OAdabasNewDbDlg,ButtonClickHdl));
313 	m_PB_DATADEVSPACE.SetClickHdl(		LINK(this,OAdabasNewDbDlg,ButtonClickHdl));
314 
315 	m_BMP_CON.SetImage(		ModuleRes(UNCHECK_RED) );
316 	m_BMP_SYS.SetImage(		ModuleRes(UNCHECK_RED) );
317 	m_BMP_DOMAIN.SetImage(	ModuleRes(UNCHECK_RED) );
318 
319 	static String s_sRoot(RTL_CONSTASCII_USTRINGPARAM("DBROOT"));
320 	static String s_sConfig(RTL_CONSTASCII_USTRINGPARAM("DBCONFIG"));
321 	static String s_sWork(RTL_CONSTASCII_USTRINGPARAM("DBWORK"));
322 
323 	sal_Bool bError = fillEnvironmentVariable(s_sWork,m_sDbWork);
324 	if ( bError || !m_sDbWork.Len() )
325 		bError = fillEnvironmentVariable(s_sRoot,m_sDbWork);
326 
327     bError = fillEnvironmentVariable(s_sConfig,m_sDbConfig);
328 	if ( bError || !m_sDbConfig.Len() )
329 		bError = fillEnvironmentVariable(s_sRoot,m_sDbConfig);
330 
331 	if ( m_sDbConfig.Len() && m_sDbWork.Len() )
332 	{
333 		m_sDbConfig.AppendAscii("/");
334 		m_sDbWork.AppendAscii("/");
335 
336 		String sDefaultName,sExt;
337 		sDefaultName.AssignAscii("MYDB");
338 		String sConfig = m_sDbConfig;
339 		sConfig.AppendAscii("config");
340 		TempFile aDefaultDatabase(sDefaultName,&sExt,&sConfig);
341 		aDefaultDatabase.EnableKillingFile();
342 		INetURLObject aURL(aDefaultDatabase.GetURL());
343 
344 		m_ET_DATABASENAME.SetText(aURL.GetName());
345 		m_DBName = m_ET_DATABASENAME.GetText();
346 
347 		// create temp names for my files
348 		// here we need only a name the creation is done by the driver
349 		// so we delete the files after we get a valid name
350 		// with this we avoiding to mention anything when the user presses cancel
351 
352 		String aSysExt;
353 		sal_Bool bValid = sal_True;
354 		{
355 			aSysExt.AssignAscii(".sys");
356 			::utl::TempFile aTmpFile(m_ET_DATABASENAME.GetText(),&aSysExt,&m_sDbWork);
357 			aTmpFile.EnableKillingFile();
358 			bValid = aTmpFile.IsValid();
359 			if(bValid)
360 				LocalFileHelper::ConvertURLToPhysicalName(aTmpFile.GetURL(),m_SYSDEV_File);
361 		}
362 		{
363 			aSysExt.AssignAscii(".trs");
364 			::utl::TempFile aTmpFile(m_ET_DATABASENAME.GetText(),&aSysExt,&m_sDbWork);
365 			aTmpFile.EnableKillingFile();
366 			bValid = !bValid || aTmpFile.IsValid();
367 			if(aTmpFile.IsValid())
368 				LocalFileHelper::ConvertURLToPhysicalName(aTmpFile.GetURL(),m_TRANSDEV_File);
369 		}
370 		{
371 			aSysExt.AssignAscii(".dat");
372 			::utl::TempFile aTmpFile(m_ET_DATABASENAME.GetText(),&aSysExt,&m_sDbWork);
373 			aTmpFile.EnableKillingFile();
374 			bValid = !bValid || aTmpFile.IsValid();
375 			if(aTmpFile.IsValid())
376 				LocalFileHelper::ConvertURLToPhysicalName(aTmpFile.GetURL(),m_DATADEV_File);
377 		}
378 		if(!bValid) // we found a file which isn't valid so we report an error message
379 			PostUserEvent(LINK(this, OAdabasNewDbDlg, OnNoAccessRights));
380 
381 	}
382 
383 	if(m_SYSDEV_File.Len() < 41 && m_TRANSDEV_File.Len() < 41 && m_DATADEV_File.Len() < 41)
384 	{
385 		m_ET_SYSDEVSPACE.SetText(m_SYSDEV_File );
386 		m_ET_TRANSACTIONLOG.SetText(m_TRANSDEV_File);
387 		m_ET_DATADEVSPACE.SetText(m_DATADEV_File);
388 	}
389 	else
390 	{
391 		m_SYSDEV_File = m_TRANSDEV_File = m_DATADEV_File = String();
392 		PostUserEvent(LINK(this, OAdabasNewDbDlg, OnNoDefaultPath));
393 	}
394 
395 	m_ET_CONUSR.SetText(String::CreateFromAscii("CONTROL"));
396 
397 	m_PB_OK.SetClickHdl(LINK(this,OAdabasNewDbDlg,ImplOKHdl));
398 	m_PB_OK.Enable(sal_False);
399 
400 	m_ET_DATABASENAME.SetModifyHdl(	LINK(this,OAdabasNewDbDlg,LoseFocusHdl));
401 
402 }
403 // -----------------------------------------------------------------------
~OAdabasNewDbDlg()404 OAdabasNewDbDlg::~OAdabasNewDbDlg()
405 {
406 	DBG_DTOR( OAdabasNewDbDlg, NULL );
407 }
408 //------------------------------------------------------------------
409 IMPL_LINK(OAdabasNewDbDlg, OnError, void*, /*_pArg*/)
410 {
411 	String sErrorMsg(ModuleRes(STR_ERROR_IN_ADABAS_INSTALLATION));
412 	ErrorBox(this, WB_OK, sErrorMsg).Execute();
413 	EndDialog(RET_CANCEL);
414 	return 0L;
415 }
416 //------------------------------------------------------------------
417 IMPL_LINK(OAdabasNewDbDlg, OnNoDefaultPath, void*, /*_pArg*/)
418 {
419 	String sErrorMsg(ModuleRes(STR_ADABAS_NO_DEFAULTNAME));
420 	ErrorBox(this, WB_OK, sErrorMsg).Execute();
421 	return 0L;
422 }
423 //------------------------------------------------------------------
424 IMPL_LINK(OAdabasNewDbDlg, OnNoAccessRights, void*, /*_pArg*/)
425 {
426 	String sErrorMsg(ModuleRes(STR_ADABAS_NO_ACCESSRIGHTS));
427 	ErrorBox(this, WB_OK, sErrorMsg).Execute();
428 	return 0L;
429 }
430 
431 // -----------------------------------------------------------------------
432 IMPL_LINK( OAdabasNewDbDlg, ImplOKHdl, OKButton*, /*EMPTYARG*/ )
433 {
434 	m_SYSDEV_File 	= m_ET_SYSDEVSPACE.GetText();
435 	m_TRANSDEV_File = m_ET_TRANSACTIONLOG.GetText();
436 	m_DATADEV_File	= m_ET_DATADEVSPACE.GetText();
437 
438 	m_Backup_File	= m_ET_RESTORE.GetText();
439 	if(m_bRestore)
440 	{
441 		INetURLObject aURL;
442 		aURL.SetSmartProtocol(INET_PROT_FILE);
443 		aURL.SetURL(m_Backup_File);
444 		Content aContent(aURL.GetURLNoPass(),Reference<XCommandEnvironment>());
445 		try
446 		{
447 			if(!aContent.isDocument())
448 			{
449 				String aString1 = String(ModuleRes(STR_ADABAS_NO_BACKUP_FILE));
450 				String aString2 = String(ModuleRes(STR_STAT_WARNING));
451 				SQLException aSql(aString1,NULL,aString2,1000,Any());
452 				return 0;
453 			}
454 
455 		}
456 		catch(Exception&)
457 		{
458 			String aString1 = String(ModuleRes(STR_ADABAS_NO_BACKUP_FILE));
459 			String aString2 = String(ModuleRes(STR_STAT_WARNING));
460 			SQLException aSql(aString1,NULL,aString2,1000,Any());
461 			throw aSql;
462 		}
463 		if(m_Backup_File.Len() > 40)
464 		{
465 			InfoBox aInfo(this,ModuleRes(INFO_STR_MAX_FILE_LENGTH));
466 			String aMsg(aInfo.GetMessText());
467 			aMsg.SearchAndReplace(String::CreateFromAscii("\'#\'"),String::CreateFromAscii("40"));
468 			aInfo.SetMessText(aMsg);
469 			aInfo.Execute();
470 			return 0;
471 		}
472 	}
473 	else if(m_SYSDEV_File.Len() > 40 || m_TRANSDEV_File.Len() > 40 || m_DATADEV_File.Len() > 40)
474 	{
475 		InfoBox aInfo(this,ModuleRes(INFO_STR_MAX_FILE_LENGTH));
476 		String aMsg(aInfo.GetMessText());
477 		aMsg.SearchAndReplace(String::CreateFromAscii("\'#\'"),String::CreateFromAscii("40"));
478 		aInfo.SetMessText(aMsg);
479 		aInfo.Execute();
480 		return 0;
481 	}
482 
483 
484 	sal_Bool bOk = sal_False;
485 
486 	{
487 		// we need url
488 		String sTemp;
489 		bOk = LocalFileHelper::ConvertPhysicalNameToURL(m_DATADEV_File,sTemp);
490 		m_DATADEV_File = sTemp;
491 		sTemp = String();
492 		bOk = LocalFileHelper::ConvertPhysicalNameToURL(m_SYSDEV_File,sTemp);
493 		m_SYSDEV_File = sTemp;
494 		sTemp = String();
495 		bOk = LocalFileHelper::ConvertPhysicalNameToURL(m_TRANSDEV_File,sTemp);
496 		m_TRANSDEV_File = sTemp;
497 	}
498 	String aErrorMessage = String(ModuleRes(STR_DEVSPACE_NO_FILE));
499 	if(!m_SYSDEV_File.Len())
500 		aErrorMessage.SearchAndReplace(String::CreateFromAscii("$name$"),String::CreateFromAscii("SYSDEVSPACE"));
501 	else if(!m_TRANSDEV_File.Len())
502 		aErrorMessage.SearchAndReplace(String::CreateFromAscii("$name$"),String::CreateFromAscii("TRANSACTIONLOG"));
503 	else if(!m_DATADEV_File.Len())
504 		aErrorMessage.SearchAndReplace(String::CreateFromAscii("$name$"),String::CreateFromAscii("DATDEVSPACE"));
505 	else if(m_ET_SYSUSR.GetText() == m_ET_CONUSR.GetText())
506 		aErrorMessage = String(ModuleRes(STR_NO_SAME_USER));
507 	else
508 		bOk = sal_True;
509 
510 
511 	if (!bOk)
512 	{
513 		ErrorBox(this, WB_OK, aErrorMessage).Execute();
514 		return sal_False;
515 	}
516 
517 	sal_Int32 nPos = 0;
518 	Sequence< PropertyValue> aCreateArgs(m_bRestore ? 14 : 12);
519 	aCreateArgs[nPos].Name		= PROPERTY_CONTROL_USER;
520 	aCreateArgs[nPos++].Value  <<= ::rtl::OUString(m_ET_CONUSR.GetText().ToUpperAscii());
521 	aCreateArgs[nPos].Name		= PROPERTY_CONTROL_PASSWORD;
522 	aCreateArgs[nPos++].Value  <<= ::rtl::OUString(m_ConPwd);
523 	aCreateArgs[nPos].Name		= PROPERTY_USER;
524 	aCreateArgs[nPos++].Value  <<= ::rtl::OUString(m_ET_SYSUSR.GetText().ToUpperAscii());
525 	aCreateArgs[nPos].Name		= PROPERTY_PASSWORD;
526 	aCreateArgs[nPos++].Value  <<= ::rtl::OUString(m_SysPwd);
527 	aCreateArgs[nPos].Name		= PROPERTY_DOMAINPASSWORD;
528 	aCreateArgs[nPos++].Value  <<= ::rtl::OUString(m_DomainPwd);
529 	aCreateArgs[nPos].Name		= PROPERTY_CACHESIZE;
530 	aCreateArgs[nPos++].Value  <<= ::rtl::OUString::valueOf(sal_Int32(m_NF_CACHE_SIZE.GetValue()*256));
531 	aCreateArgs[nPos].Name		= PROPERTY_DATABASENAME;
532 	aCreateArgs[nPos++].Value  <<= ::rtl::OUString(m_ET_DATABASENAME.GetText().ToUpperAscii());
533 	aCreateArgs[nPos].Name		= PROPERTY_DATADEVSPACE;
534 	aCreateArgs[nPos++].Value  <<= ::rtl::OUString(m_DATADEV_File);
535 	aCreateArgs[nPos].Name		= PROPERTY_SYSDEVSPACE;
536 	aCreateArgs[nPos++].Value  <<= ::rtl::OUString(m_SYSDEV_File);
537 	aCreateArgs[nPos].Name		= PROPERTY_TRANSACTION_LOG;
538 	aCreateArgs[nPos++].Value  <<= ::rtl::OUString(m_TRANSDEV_File);
539 	aCreateArgs[nPos].Name		= PROPERTY_DATADEVSIZE;
540 	aCreateArgs[nPos++].Value  <<= sal_Int32(m_NF_DATADEVSPACE_SIZE.GetValue()*256);
541 	aCreateArgs[nPos].Name		= PROPERTY_LOGDEVSIZE;
542 	aCreateArgs[nPos++].Value  <<= 	sal_Int32(m_NF_TRANSACTIONLOG_SIZE.GetValue()*256);
543 
544 	if(m_bRestore)
545 	{
546 		aCreateArgs[nPos].Name		= PROPERTY_RESTOREDATABASE;
547 		aCreateArgs[nPos++].Value  <<= ::cppu::bool2any(sal_True);
548 		aCreateArgs[nPos].Name		= PROPERTY_BACKUPNAME;
549 		aCreateArgs[nPos++].Value  <<= ::rtl::OUString(m_Backup_File);
550 	}
551 
552 	Disable();
553 
554 	m_aCreatorWait = ::std::auto_ptr<WaitObject>(new WaitObject(this));
555 	m_aCreatorThread = ::std::auto_ptr<ODatabaseCreator>(new ODatabaseCreator(m_xCreateCatalog,this,m_xORB,aCreateArgs));
556 	m_aCreatorThread->setTerminateHandler(LINK(this,OAdabasNewDbDlg,TerminateHdl));
557 	m_aCreatorThread->create();
558 
559 	return sal_True;
560 }
561 //-------------------------------------------------------------------------
562 IMPL_LINK( OAdabasNewDbDlg, TerminateHdl, void*, /*NOTUSABLE*/ )
563 {
564 	EndDialog(RET_OK);
565 	return 0;
566 }
567 //------------------------------------------------------------------------
IMPL_LINK(OAdabasNewDbDlg,LoseFocusHdl,Edit *,pEdit)568 IMPL_LINK( OAdabasNewDbDlg, LoseFocusHdl, Edit *, pEdit )
569 {
570 	if(&m_ET_SYSDEVSPACE == pEdit)
571 		m_SYSDEV_File = pEdit->GetText();
572 	else if(&m_ET_TRANSACTIONLOG == pEdit)
573 		m_TRANSDEV_File = pEdit->GetText();
574 	else if(&m_ET_DATADEVSPACE == pEdit)
575 		m_DATADEV_File = pEdit->GetText();
576 	else if(&m_ET_RESTORE == pEdit)
577 		m_Backup_File = pEdit->GetText();
578 	else if(&m_ET_DATABASENAME == pEdit)
579 	{// check if the new dbname already exists
580 		String sNewDbName = pEdit->GetText();
581 		String sConfig = m_sDbConfig;
582 		sConfig.AppendAscii("config/");
583 		sConfig += sNewDbName;
584 		if(UCBContentHelper::IsDocument(sConfig))
585 		{
586 			String sErrorMessage = String(ModuleRes(STR_ADABAS_DB_EXISTS));
587 			ErrorBox(this, WB_OK, sErrorMessage).Execute();
588 			m_DBName.Erase();
589 		}
590 		else if ( m_DBName.SearchAscii(" ") != STRING_NOTFOUND )
591 		{
592 			String sErrorMessage = String(ModuleRes(STR_ADABAS_DB_EXISTS));
593 			ErrorBox(this, WB_OK, sErrorMessage).Execute();
594 			m_DBName = m_DBName.GetToken(0,' ');
595 		}
596 		else
597 			m_DBName = sNewDbName;
598 	}
599 
600 	CheckBitmaps();
601 	return 0;
602 }
603 //------------------------------------------------------------------------
604 IMPL_LINK( OAdabasNewDbDlg, LoadButtonClickHdl, Button *, /*pButton*/ )
605 {
606 	::sfx2::FileDialogHelper aLoad(WB_3DLOOK | WB_STDMODAL | WB_OPEN);
607 	if(!m_Backup_File.Len())
608 		aLoad.SetDisplayDirectory(SvtPathOptions().GetWorkPath());
609 	else
610 		aLoad.SetDisplayDirectory(m_Backup_File);
611 	if (aLoad.Execute())
612 	{
613 		INetURLObject aUrl(aLoad.GetPath());
614 		m_Backup_File = aUrl.PathToFileName();
615 		if(m_Backup_File.Len() > 40)
616 		{
617 			InfoBox aInfo(this,ModuleRes(INFO_STR_MAX_FILE_LENGTH));
618 			String aMsg(aInfo.GetMessText());
619 			aMsg.SearchAndReplace(String::CreateFromAscii("\'#\'"),String::CreateFromAscii("40"));
620 			aInfo.SetMessText(aMsg);
621 		}
622 		m_ET_RESTORE.SetText(m_Backup_File);
623 	}
624 	CheckBitmaps();
625 	return 0;
626 }
627 //------------------------------------------------------------------------
IMPL_LINK(OAdabasNewDbDlg,ButtonClickHdl,Button *,pButton)628 IMPL_LINK( OAdabasNewDbDlg, ButtonClickHdl, Button *, pButton )
629 {
630 	WinBits	nBits(WB_3DLOOK|WB_STDMODAL|WB_SAVEAS);
631 	::sfx2::FileDialogHelper aFileDlg( static_cast<sal_uInt32>(nBits) ); //	new FileDialog( this, nBits );
632 
633 	String aPath;
634 	if(pButton == &m_PB_SYSDEVSPACE)
635 		aPath = m_SYSDEV_File;
636 	else if(pButton == &m_PB_TRANSACTIONLOG)
637 		aPath = m_TRANSDEV_File;
638 	else if(pButton == &m_PB_DATADEVSPACE)
639 		aPath = m_DATADEV_File;
640 
641 	String sUrl;
642 	::utl::LocalFileHelper::ConvertPhysicalNameToURL(aPath,sUrl);
643 	aFileDlg.SetDisplayDirectory(sUrl);
644 
645 
646 
647 	if (aFileDlg.Execute() == ERRCODE_NONE)
648 	{
649 		INetURLObject aUrl(aFileDlg.GetPath());
650 		if(pButton == &m_PB_SYSDEVSPACE)
651 		{
652 			m_SYSDEV_File = aUrl.PathToFileName();
653 			if(m_SYSDEV_File.Len() > 40)
654 			{
655 				InfoBox aInfo(this,ModuleRes(INFO_STR_MAX_FILE_LENGTH));
656 				String aMsg(aInfo.GetMessText());
657 				aMsg.SearchAndReplace(String::CreateFromAscii("\'#\'"),String::CreateFromAscii("40"));
658 				aInfo.SetMessText(aMsg);
659 				aInfo.Execute();
660 				return 0;
661 			}
662 			m_ET_SYSDEVSPACE.SetText(aUrl.PathToFileName());
663 		}
664 		else if(pButton == &m_PB_TRANSACTIONLOG)
665 		{
666 			m_TRANSDEV_File = aUrl.PathToFileName();
667 			if(m_TRANSDEV_File.Len() > 40)
668 			{
669 				InfoBox aInfo(this,ModuleRes(INFO_STR_MAX_FILE_LENGTH));
670 				String aMsg(aInfo.GetMessText());
671 				aMsg.SearchAndReplace(String::CreateFromAscii("\'#\'"),String::CreateFromAscii("40"));
672 				aInfo.SetMessText(aMsg);
673 				aInfo.Execute();
674 				return 0;
675 			}
676 			m_ET_TRANSACTIONLOG.SetText(aUrl.PathToFileName());
677 		}
678 		else if(pButton == &m_PB_DATADEVSPACE)
679 		{
680 			m_DATADEV_File = aUrl.PathToFileName();
681 			if(m_DATADEV_File.Len() > 40)
682 			{
683 				InfoBox aInfo(this,ModuleRes(INFO_STR_MAX_FILE_LENGTH));
684 				String aMsg(aInfo.GetMessText());
685 				aMsg.SearchAndReplace(String::CreateFromAscii("\'#\'"),String::CreateFromAscii("40"));
686 				aInfo.SetMessText(aMsg);
687 				aInfo.Execute();
688 				return 0;
689 			}
690 			m_ET_DATADEVSPACE.SetText(aUrl.PathToFileName());
691 		}
692 	}
693 
694 	CheckBitmaps();
695 	return 0;
696 }
697 //------------------------------------------------------------------------
IMPL_LINK(OAdabasNewDbDlg,PwdClickHdl,Button *,pButton)698 IMPL_LINK( OAdabasNewDbDlg, PwdClickHdl, Button *, pButton )
699 {
700 	SfxPasswordDialog aDlg(this);
701 	aDlg.ShowExtras(SHOWEXTRAS_CONFIRM);
702 	if(aDlg.Execute())
703 	{
704 		String sPwd = aDlg.GetPassword().ToUpperAscii();
705 		// no space in password allowed
706 		if ( sPwd.GetTokenCount(' ') == 1 )
707 		{
708 			if(pButton == &m_PB_CONPWD)
709 			{
710 				m_ConPwd = sPwd;
711 				m_nSetBitmap &=~2;
712 			}
713 			else if(pButton == &m_PB_SYSPWD)
714 			{
715 				m_SysPwd = sPwd;
716 				if(!m_DomainPwd.Len())
717 				{
718 					m_nSetBitmap = 1;
719 					m_DomainPwd = m_SysPwd;
720 				}
721 				if(!m_ConPwd.Len())
722 				{
723 					m_nSetBitmap |= 2;
724 					m_ConPwd = m_SysPwd;
725 				}
726 
727 			}
728 			else if(pButton == &m_PB_DOMAINPWD)
729 			{
730 				m_DomainPwd = sPwd;
731 				m_nSetBitmap &=~1;
732 			}
733 		}
734 		else
735 		{
736 			String sErrorMsg(ModuleRes(STR_ADABAS_PASSWORD_ILLEGAL));
737 			ErrorBox(this, WB_OK, sErrorMsg).Execute();
738 		}
739 	}
740 	CheckBitmaps();
741 	return 0;
742 }
743 //------------------------------------------------------------------------
CheckBitmaps()744 void OAdabasNewDbDlg::CheckBitmaps()
745 {
746 	sal_Int16 i=0;
747 	if(m_ConPwd.Len() && m_ET_CONUSR.GetText().Len())
748 			i++,m_BMP_CON.SetImage(ModuleRes(((m_nSetBitmap & 2) == 2) ? DEFAULT_BLUE : CHECK_GREEN));
749 	else
750 		m_BMP_CON.SetImage(ModuleRes(UNCHECK_RED));
751 
752 	if(!m_bRestore)
753 	{
754 		if(m_SysPwd.Len() && m_ET_SYSUSR.GetText().Len())
755 			i++,m_BMP_SYS.SetImage(ModuleRes(CHECK_GREEN));
756 		else
757 			m_BMP_SYS.SetImage(ModuleRes(UNCHECK_RED));
758 
759 		if(m_DomainPwd.Len() )
760 			i++,m_BMP_DOMAIN.SetImage(ModuleRes(((m_nSetBitmap & 1) == 1) ? DEFAULT_BLUE : CHECK_GREEN));
761 		else
762 			m_BMP_DOMAIN.SetImage(ModuleRes(UNCHECK_RED));
763 	}
764 	else if(m_Backup_File.Len())
765 		i+=2;
766 
767 	if(m_ET_SYSDEVSPACE.GetText().Len() && m_ET_TRANSACTIONLOG.GetText().Len() && m_ET_DATADEVSPACE.GetText().Len() &&
768 		m_ET_SYSDEVSPACE.GetText() != m_ET_TRANSACTIONLOG.GetText() && m_ET_SYSDEVSPACE.GetText() != m_ET_DATADEVSPACE.GetText() &&
769 		m_ET_DATADEVSPACE.GetText() != m_ET_TRANSACTIONLOG.GetText())
770 		i++;
771 
772 	if(m_DBName.Len())
773 		i++;
774 
775 	m_PB_OK.Enable(i == 5);
776 }
777 // -----------------------------------------------------------------------------
fillEnvironmentVariable(const::rtl::OUString & _sVariableName,String & _rsValue)778 sal_Bool OAdabasNewDbDlg::fillEnvironmentVariable(const ::rtl::OUString& _sVariableName,String& _rsValue)
779 {
780 	rtl_uString* pDbVar = NULL;
781 	sal_Bool bError = sal_False;
782 	if(osl_getEnvironment(_sVariableName.pData,&pDbVar) == osl_Process_E_None && pDbVar)
783 	{
784 		_rsValue = pDbVar;
785 		String sTemp;
786 		LocalFileHelper::ConvertPhysicalNameToURL(_rsValue,sTemp);
787 		_rsValue = sTemp;
788 		rtl_uString_release(pDbVar);
789 		pDbVar = NULL;
790 
791 		// ensure dir exists
792 		osl::FileBase::RC rc = osl::Directory::createPath(_rsValue);
793 		if(rc != osl::FileBase::E_None && rc != osl::FileBase::E_EXIST)
794 		{
795 			bError = sal_True;
796 			PostUserEvent(LINK(this, OAdabasNewDbDlg, OnError));
797 		}
798 	}
799 	return bError;
800 }
801 // -----------------------------------------------------------------------------
802