1*cdf0e10cSrcweir<?xml version="1.0" encoding="UTF-8"?>
2*cdf0e10cSrcweir<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3*cdf0e10cSrcweir<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Main" script:language="StarBasic">Option Explicit
4*cdf0e10cSrcweir
5*cdf0e10cSrcweir&apos;  *****  BASIC  *****
6*cdf0e10cSrcweirPublic HeaderPreviews(4) as Object
7*cdf0e10cSrcweirPublic ImportDialog as Object
8*cdf0e10cSrcweirPublic ImportDialogArea as Object
9*cdf0e10cSrcweirPublic oFactoryKey as Object
10*cdf0e10cSrcweirPublic bShowLogFile as Boolean
11*cdf0e10cSrcweir
12*cdf0e10cSrcweir&apos; If the ProgressPage ist already on Top The Dialog will be immediately closed when this flag is
13*cdf0e10cSrcweir&apos; set to False
14*cdf0e10cSrcweirPublic bConversionIsRunning as Boolean
15*cdf0e10cSrcweirPublic RetValue as Integer
16*cdf0e10cSrcweir
17*cdf0e10cSrcweirSub Main()
18*cdf0e10cSrcweir	Dim NoArgs() as New com.sun.star.beans.PropertyValue
19*cdf0e10cSrcweir	bShowLogFile=FALSE
20*cdf0e10cSrcweir	If Not bDebugWizard Then
21*cdf0e10cSrcweir		On Local Error Goto RTError
22*cdf0e10cSrcweir	End If
23*cdf0e10cSrcweir	BasicLibraries.LoadLibrary(&quot;Tools&quot;)
24*cdf0e10cSrcweir	RetValue = 10
25*cdf0e10cSrcweir	bIsFirstLogTable = True
26*cdf0e10cSrcweir	bConversionIsRunning = False
27*cdf0e10cSrcweir	sCRLF = CHR(13) &amp; CHR(10)
28*cdf0e10cSrcweir	oUcb = createUnoService(&quot;com.sun.star.ucb.SimpleFileAccess&quot;)
29*cdf0e10cSrcweir	oFactoryKey = GetRegistryKeyContent(&quot;org.openoffice.Setup/Office/Factories&quot;)
30*cdf0e10cSrcweir	If GetImportWizardPaths() = False Then
31*cdf0e10cSrcweir		Exit Sub
32*cdf0e10cSrcweir	End If
33*cdf0e10cSrcweir  	bCancelTask = False
34*cdf0e10cSrcweir  	bDoKeepApplValues = False
35*cdf0e10cSrcweir	CurOffice = 0
36*cdf0e10cSrcweir	ImportDialogArea = LoadDialog(&quot;ImportWizard&quot;,&quot;ImportDialog&quot;)
37*cdf0e10cSrcweir	ImportDialog = ImportDialogArea.Model
38*cdf0e10cSrcweir	LoadLanguage()
39*cdf0e10cSrcweir	WizardMode = SBXMLMODE
40*cdf0e10cSrcweir	MaxApplCount = 4
41*cdf0e10cSrcweir	FillStep_Welcome()
42*cdf0e10cSrcweir	RepaintHeaderPreview()
43*cdf0e10cSrcweir	ImportDialog.ImportPreview.BackGroundColor = RGB(0,60,126)
44*cdf0e10cSrcweir	ImportDialog.cmdGoOn.DefaultButton = True
45*cdf0e10cSrcweir	ImportDialogArea.GetControl(&quot;optSODocuments&quot;).SetFocus()
46*cdf0e10cSrcweir	ToggleCheckboxesWithBoolean(False)
47*cdf0e10cSrcweir	RetValue = ImportDialogArea.Execute()
48*cdf0e10cSrcweir	If bShowLogFile=TRUE Then
49*cdf0e10cSrcweir		OpenDocument(sLogUrl, NoArgs())
50*cdf0e10cSrcweir	End if
51*cdf0e10cSrcweir	If RetValue = 0 Then
52*cdf0e10cSrcweir		CancelTask()
53*cdf0e10cSrcweir	End If
54*cdf0e10cSrcweir	ImportDialogArea.Dispose()
55*cdf0e10cSrcweir	End
56*cdf0e10cSrcweir	Exit Sub
57*cdf0e10cSrcweirRTError:
58*cdf0e10cSrcweir	Msgbox sRTErrorDesc, 16, sRTErrorHeader
59*cdf0e10cSrcweirEnd Sub
60*cdf0e10cSrcweir
61*cdf0e10cSrcweir
62*cdf0e10cSrcweir
63*cdf0e10cSrcweirSub NextStep()
64*cdf0e10cSrcweirDim iCurStep as Integer
65*cdf0e10cSrcweir	If Not bDebugWizard Then
66*cdf0e10cSrcweir		On Error Goto RTError
67*cdf0e10cSrcweir	End If
68*cdf0e10cSrcweir	bConversionIsRunning = False
69*cdf0e10cSrcweir	iCurStep = ImportDialog.Step
70*cdf0e10cSrcweir	Select Case iCurStep
71*cdf0e10cSrcweir		Case 1
72*cdf0e10cSrcweir			FillStep_InputPaths(0, True)
73*cdf0e10cSrcweir		Case 2
74*cdf0e10cSrcweir			If CheckInputPaths Then
75*cdf0e10cSrcweir				SaveStep_InputPath
76*cdf0e10cSrcweir				If CurOffice &lt; ApplCount - 1 Then
77*cdf0e10cSrcweir					CurOffice = CurOffice + 1
78*cdf0e10cSrcweir					TakeOverPathSettings()
79*cdf0e10cSrcweir					FillStep_InputPaths(CurOffice, False)
80*cdf0e10cSrcweir				Else
81*cdf0e10cSrcweir					FillStep_Summary()
82*cdf0e10cSrcweir				End If
83*cdf0e10cSrcweir			End If
84*cdf0e10cSrcweir		Case 3
85*cdf0e10cSrcweir			FillStep_Progress()
86*cdf0e10cSrcweir			Select Case WizardMode
87*cdf0e10cSrcweir				Case SBMICROSOFTMODE
88*cdf0e10cSrcweir					Call ConvertAllDocuments(MSFilterName())
89*cdf0e10cSrcweir				CASE SBXMLMODE
90*cdf0e10cSrcweir					Call ConvertAllDocuments(XMLFilterName())
91*cdf0e10cSrcweir			End Select
92*cdf0e10cSrcweir		Case 4
93*cdf0e10cSrcweir			CancelTask(True)
94*cdf0e10cSrcweir	End Select
95*cdf0e10cSrcweir
96*cdf0e10cSrcweir	If ((ImportDialog.chkLogfile.State &lt;&gt; 1) OR (iCurStep &lt;&gt; 3)) Then
97*cdf0e10cSrcweir		ImportDialog.cmdGoOn.DefaultButton = True
98*cdf0e10cSrcweir	End If
99*cdf0e10cSrcweir
100*cdf0e10cSrcweir	RepaintHeaderPreview()
101*cdf0e10cSrcweir	Exit Sub
102*cdf0e10cSrcweirRTError:
103*cdf0e10cSrcweir	Msgbox sRTErrorDesc, 16, sRTErrorHeader
104*cdf0e10cSrcweirEnd Sub
105*cdf0e10cSrcweir
106*cdf0e10cSrcweir
107*cdf0e10cSrcweir
108*cdf0e10cSrcweirSub PrevStep()
109*cdf0e10cSrcweirDim iCurStep as Integer
110*cdf0e10cSrcweir	If Not bDebugWizard Then
111*cdf0e10cSrcweir		On Error Goto RTError
112*cdf0e10cSrcweir	End If
113*cdf0e10cSrcweir	bConversionIsRunning = False
114*cdf0e10cSrcweir	iCurStep = ImportDialog.Step
115*cdf0e10cSrcweir	Select Case iCurStep
116*cdf0e10cSrcweir		Case 4
117*cdf0e10cSrcweir			ImportDialog.cmdCancel.Label = sCancelButton
118*cdf0e10cSrcweir			FillStep_Summary()
119*cdf0e10cSrcweir		Case 3
120*cdf0e10cSrcweir			FillStep_InputPaths(Applcount-1, False)
121*cdf0e10cSrcweir		Case 2
122*cdf0e10cSrcweir			SaveStep_InputPath
123*cdf0e10cSrcweir			If CurOffice &gt; 0 Then
124*cdf0e10cSrcweir				CurOffice = CurOffice - 1
125*cdf0e10cSrcweir				FillStep_InputPaths(CurOffice, False)
126*cdf0e10cSrcweir			Else
127*cdf0e10cSrcweir				FillStep_Welcome()
128*cdf0e10cSrcweir				bDoKeepApplValues = True
129*cdf0e10cSrcweir			End If
130*cdf0e10cSrcweir	End Select
131*cdf0e10cSrcweir	ImportDialog.cmdGoOn.DefaultButton = True
132*cdf0e10cSrcweir	RepaintHeaderPreview()
133*cdf0e10cSrcweir	Exit Sub
134*cdf0e10cSrcweirRTError:
135*cdf0e10cSrcweir	Msgbox sRTErrorDesc, 16, sRTErrorHeader
136*cdf0e10cSrcweirEnd Sub
137*cdf0e10cSrcweir
138*cdf0e10cSrcweir
139*cdf0e10cSrcweir
140*cdf0e10cSrcweirSub CancelTask()
141*cdf0e10cSrcweir	If bConversionIsRunning Then
142*cdf0e10cSrcweir		If Msgbox(sConvertError1, 36, sConvertError2) = 6 Then
143*cdf0e10cSrcweir			bCancelTask = True
144*cdf0e10cSrcweir			bInterruptSearch = True
145*cdf0e10cSrcweir		Else
146*cdf0e10cSrcweir			bCancelTask = False
147*cdf0e10cSrcweir			ImportDialog.cmdCancel.Enabled = True
148*cdf0e10cSrcweir		End If
149*cdf0e10cSrcweir	Else
150*cdf0e10cSrcweir		ImportDialogArea.EndExecute()
151*cdf0e10cSrcweir	End If
152*cdf0e10cSrcweirEnd Sub
153*cdf0e10cSrcweir
154*cdf0e10cSrcweir
155*cdf0e10cSrcweirSub TemplateDirSearchDialog()
156*cdf0e10cSrcweir	CallDirSearchDialog(ImportDialog.TemplateImportPath)
157*cdf0e10cSrcweirEnd Sub
158*cdf0e10cSrcweir
159*cdf0e10cSrcweir
160*cdf0e10cSrcweirSub RepaintHeaderPreview()
161*cdf0e10cSrcweirDim Bitmap As Object
162*cdf0e10cSrcweirDim CurStep as Integer
163*cdf0e10cSrcweirDim sBitmapPath as String
164*cdf0e10cSrcweirDim LocPrefix as String
165*cdf0e10cSrcweir	CurStep = ImportDialog.Step
166*cdf0e10cSrcweir	LocPrefix = WizardMode
167*cdf0e10cSrcweir	LocPrefix = ReplaceString(LocPrefix,&quot;XML&quot;, &quot;SO&quot;)
168*cdf0e10cSrcweir	If CurStep = 2 Then
169*cdf0e10cSrcweir		sBitmapPath = SOBitmapPath &amp; LocPrefix &amp; &quot;-Import_&quot; &amp; CurStep &amp; &quot;-&quot; &amp; Applications(CurOffice,SBAPPLKEY) + 1 &amp; &quot;.bmp&quot;
170*cdf0e10cSrcweir	Else
171*cdf0e10cSrcweir		sBitmapPath = SOBitmapPath &amp; &quot;Import_&quot; &amp; CurStep &amp; &quot;.bmp&quot;
172*cdf0e10cSrcweir	End If
173*cdf0e10cSrcweir	ImportDialog.ImportPreview.ImageURL = sBitmapPath
174*cdf0e10cSrcweirEnd Sub
175*cdf0e10cSrcweir
176*cdf0e10cSrcweir
177*cdf0e10cSrcweirSub CheckModuleInstallation()
178*cdf0e10cSrcweirDim i as Integer
179*cdf0e10cSrcweir	For i = 1 To MaxApplCount
180*cdf0e10cSrcweir		ImportDialogArea.GetControl(&quot;chk&quot; &amp; WizardMode &amp; &quot;Application&quot; &amp; i).Model.Enabled = Abs(CheckInstalledModule(i-1))
181*cdf0e10cSrcweir	Next i
182*cdf0e10cSrcweirEnd Sub
183*cdf0e10cSrcweir
184*cdf0e10cSrcweir
185*cdf0e10cSrcweirFunction CheckInstalledModule(Index as Integer) as Boolean
186*cdf0e10cSrcweirDim ModuleName as String
187*cdf0e10cSrcweirDim NameList() as String
188*cdf0e10cSrcweirDim MaxIndex as Integer
189*cdf0e10cSrcweirDim i as Integer
190*cdf0e10cSrcweir	ModuleName = ModuleList(Index)
191*cdf0e10cSrcweir	If Instr(1,ModuleName,&quot;/&quot;) &lt;&gt; 0 Then
192*cdf0e10cSrcweir		CheckInstalledModule() = False
193*cdf0e10cSrcweir		NameList() = ArrayoutOfString(ModuleName,&quot;/&quot;, MaxIndex)
194*cdf0e10cSrcweir		For i = 0 To MaxIndex
195*cdf0e10cSrcweir			If oFactoryKey.HasByName(NameList(i)) Then
196*cdf0e10cSrcweir				CheckInstalledModule() = True
197*cdf0e10cSrcweir			End If
198*cdf0e10cSrcweir		Next i
199*cdf0e10cSrcweir	Else
200*cdf0e10cSrcweir		CheckInstalledModule() = oFactoryKey.HasByName(ModuleName)
201*cdf0e10cSrcweir	End If
202*cdf0e10cSrcweirEnd Function
203*cdf0e10cSrcweir
204*cdf0e10cSrcweir
205*cdf0e10cSrcweirSub ToggleCheckboxes(oEvent as Object)
206*cdf0e10cSrcweirDim bMSEnable as Boolean
207*cdf0e10cSrcweir	WizardMode = oEvent.Source.Model.Tag
208*cdf0e10cSrcweir	bMSEnable = WizardMode = &quot;MS&quot;
209*cdf0e10cSrcweir	ToggleCheckBoxesWithBoolean(bMSEnable)
210*cdf0e10cSrcweirEnd Sub
211*cdf0e10cSrcweir
212*cdf0e10cSrcweir
213*cdf0e10cSrcweirSub ToggleCheckboxesWithBoolean(bMSEnable as Boolean)
214*cdf0e10cSrcweir	If bMSEnable = True Then
215*cdf0e10cSrcweir		WizardMode = SBMICROSOFTMODE
216*cdf0e10cSrcweir		MaxApplCount = 3
217*cdf0e10cSrcweir	Else
218*cdf0e10cSrcweir		WizardMode = SBXMLMODE
219*cdf0e10cSrcweir		MaxApplCount = 4
220*cdf0e10cSrcweir	End If
221*cdf0e10cSrcweir	With ImportDialogArea
222*cdf0e10cSrcweir		.GetControl(&quot;chkSOApplication1&quot;).Model.Enabled = Not bMSEnable
223*cdf0e10cSrcweir		.GetControl(&quot;chkSOApplication2&quot;).Model.Enabled = Not bMSEnable
224*cdf0e10cSrcweir		.GetControl(&quot;chkSOApplication3&quot;).Model.Enabled = Not bMSEnable
225*cdf0e10cSrcweir		.GetControl(&quot;chkSOApplication4&quot;).Model.Enabled = Not bMSEnable
226*cdf0e10cSrcweir		.GetControl(&quot;chkMSApplication1&quot;).Model.Enabled = bMSEnable
227*cdf0e10cSrcweir		.GetControl(&quot;chkMSApplication2&quot;).Model.Enabled = bMSEnable
228*cdf0e10cSrcweir		.GetControl(&quot;chkMSApplication3&quot;).Model.Enabled = bMSEnable
229*cdf0e10cSrcweir	End With
230*cdf0e10cSrcweir	CheckModuleInstallation()
231*cdf0e10cSrcweir	ImportDialog.WelcomeTextLabel2.Enabled = bMSEnable
232*cdf0e10cSrcweir	bDoKeepApplValues = False
233*cdf0e10cSrcweir	ToggleNextButton()
234*cdf0e10cSrcweirEnd Sub
235*cdf0e10cSrcweir
236*cdf0e10cSrcweir
237*cdf0e10cSrcweirSub ToggleNextButton()
238*cdf0e10cSrcweirDim iCurStep as Integer
239*cdf0e10cSrcweirDim bDoEnable as Boolean
240*cdf0e10cSrcweirDim i as Integer
241*cdf0e10cSrcweir	iCurStep = ImportDialog.Step
242*cdf0e10cSrcweir	Select Case iCurStep
243*cdf0e10cSrcweir		Case 1
244*cdf0e10cSrcweir			With ImportDialog
245*cdf0e10cSrcweir				If .optMSDocuments.State = 1 Then
246*cdf0e10cSrcweir          			bDoEnable = .chkMSApplication1.State = 1 Or .chkMSApplication2.State = 1 Or .chkMSApplication3.State = 1
247*cdf0e10cSrcweir				Else
248*cdf0e10cSrcweir          			bDoEnable = .chkSOApplication1.State = 1 Or .chkSOApplication2.State = 1 Or .chkSOApplication3.State = 1 Or .chkSOApplication4.State = 1
249*cdf0e10cSrcweir				End If
250*cdf0e10cSrcweir			End With
251*cdf0e10cSrcweir			bDoKeepApplValues = False
252*cdf0e10cSrcweir		Case 2
253*cdf0e10cSrcweir			bDoEnable = CheckControlPath(ImportDialog.chkTemplatePath, ImportDialog.txtTemplateImportPath, True)
254*cdf0e10cSrcweir			bDoEnable = CheckControlPath(ImportDialog.chkDocumentPath, ImportDialog.txtDocumentImportPath, bDoEnable)
255*cdf0e10cSrcweir	End Select
256*cdf0e10cSrcweir	ImportDialog.cmdGoOn.Enabled = bDoEnable
257*cdf0e10cSrcweirEnd Sub
258*cdf0e10cSrcweir
259*cdf0e10cSrcweir
260*cdf0e10cSrcweirSub TakeOverPathSettings()
261*cdf0e10cSrcweir&apos;Takes over the Pathsettings from the first selected application to the next applications
262*cdf0e10cSrcweir	If Applications(CurOffice,SBDOCSOURCE) = &quot;&quot; Then
263*cdf0e10cSrcweir		Applications(CurOffice,SBDOCSOURCE) = Applications(0,SBDOCSOURCE)
264*cdf0e10cSrcweir		Applications(CurOffice,SBDOCTARGET) = Applications(0,SBDOCTARGET)
265*cdf0e10cSrcweir		If WizardMode = SBXMLMODE AND Applications(CurOffice,SBAPPLKEY) = 3 Then
266*cdf0e10cSrcweir			Applications(CurOffice,SBTEMPLSOURCE) = Applications(CurOffice,SBDOCSOURCE)
267*cdf0e10cSrcweir			Applications(CurOffice,SBTEMPLTARGET) = Applications(CurOffice,SBDOCTARGET)
268*cdf0e10cSrcweir		Else
269*cdf0e10cSrcweir			Applications(CurOffice,SBTEMPLSOURCE) = Applications(0,SBTEMPLSOURCE)
270*cdf0e10cSrcweir			Applications(CurOffice,SBTEMPLTARGET) = Applications(0,SBTEMPLTARGET)
271*cdf0e10cSrcweir		End If
272*cdf0e10cSrcweir	End If
273*cdf0e10cSrcweirEnd Sub
274*cdf0e10cSrcweir
275*cdf0e10cSrcweir
276*cdf0e10cSrcweirFunction GetImportWizardPaths() as Boolean
277*cdf0e10cSrcweir	SOBitmapPath = GetOfficeSubPath(&quot;Template&quot;, &quot;../wizard/bitmap&quot;)
278*cdf0e10cSrcweir	If SOBitmapPath &lt;&gt; &quot;&quot; Then
279*cdf0e10cSrcweir		SOWorkPath = GetPathSettings(&quot;Work&quot;, False)
280*cdf0e10cSrcweir		If SOWorkPath &lt;&gt; &quot;&quot; Then
281*cdf0e10cSrcweir			SOTemplatePath = GetPathSettings(&quot;Template_writable&quot;,False,0)
282*cdf0e10cSrcweir			If SOTemplatePath &lt;&gt; &quot;&quot; Then
283*cdf0e10cSrcweir				GetImportWizardPaths() = True
284*cdf0e10cSrcweir				Exit Function
285*cdf0e10cSrcweir			End If
286*cdf0e10cSrcweir		End If
287*cdf0e10cSrcweir	End  If
288*cdf0e10cSrcweir	GetImportWizardPaths() = False
289*cdf0e10cSrcweirEnd Function
290*cdf0e10cSrcweir</script:module>