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