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