Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / wizards / source / importwizard / Main.xba
blob875fd36b62d0d6137d468e0a69fac64ea8c67e12
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
28 Public oBinFilterComp as Object
30 &apos; If the ProgressPage ist already on Top The Dialog will be immediately closed when this flag is
31 &apos; set to False
32 Public bConversionIsRunning as Boolean
33 Public RetValue as Integer
35 Sub Main()
36 Dim NoArgs() as New com.sun.star.beans.PropertyValue
37 bShowLogFile=FALSE
38 If Not bDebugWizard Then
39 On Local Error Goto RTError
40 End If
41 BasicLibraries.LoadLibrary(&quot;Tools&quot;)
42 RetValue = 10
43 bIsFirstLogTable = True
44 bConversionIsRunning = False
45 sCRLF = CHR(13) &amp; CHR(10)
46 oUcb = createUnoService(&quot;com.sun.star.ucb.SimpleFileAccess&quot;)
47 oFactoryKey = GetRegistryKeyContent(&quot;org.openoffice.Setup/Office/Factories&quot;)
48 If GetImportWizardPaths() = False Then
49 Exit Sub
50 End If
51 bCancelTask = False
52 bDoKeepApplValues = False
53 CurOffice = 0
54 ImportDialogArea = LoadDialog(&quot;ImportWizard&quot;,&quot;ImportDialog&quot;)
55 ImportDialog = ImportDialogArea.Model
56 LoadLanguage()
57 WizardMode = SBXMLMODE
58 MaxApplCount = 4
59 FillStep_Welcome()
60 RepaintHeaderPreview()
61 ImportDialog.ImportPreview.BackGroundColor = RGB(0,60,126)
62 ImportDialog.cmdGoOn.DefaultButton = True
63 ImportDialogArea.GetControl(&quot;optMSDocuments&quot;).SetFocus()
64 oBinFilterComp = createBF_MigrateFilterIfPossible()
65 ToggleCheckboxesWithBoolean(True)
67 RetValue = ImportDialogArea.Execute()
68 If bShowLogFile=TRUE Then
69 OpenDocument(sLogUrl, NoArgs())
70 End if
71 If RetValue = 0 Then
72 CancelTask()
73 End If
74 ImportDialogArea.Dispose()
75 End
76 Exit Sub
77 RTError:
78 Msgbox sRTErrorDesc, 16, sRTErrorHeader
79 End Sub
83 Sub NextStep()
84 Dim iCurStep as Integer
85 If Not bDebugWizard Then
86 On Error Goto RTError
87 End If
88 bConversionIsRunning = False
89 iCurStep = ImportDialog.Step
90 Select Case iCurStep
91 Case 1
92 FillStep_InputPaths(0, True)
93 Case 2
94 If CheckInputPaths Then
95 SaveStep_InputPath
96 If CurOffice &lt; ApplCount - 1 Then
97 CurOffice = CurOffice + 1
98 TakeOverPathSettings()
99 FillStep_InputPaths(CurOffice, False)
100 Else
101 FillStep_Summary()
102 End If
103 End If
104 Case 3
105 FillStep_Progress()
106 Select Case WizardMode
107 Case SBMICROSOFTMODE
108 Call ConvertAllDocuments(MSFilterName())
109 CASE SBXMLMODE
110 Call ConvertAllDocuments(XMLFilterName())
111 End Select
112 Case 4
113 CancelTask(True)
114 End Select
116 If ((ImportDialog.chkLogfile.State &lt;&gt; 1) OR (iCurStep &lt;&gt; 3)) Then
117 ImportDialog.cmdGoOn.DefaultButton = True
118 End If
120 RepaintHeaderPreview()
121 Exit Sub
122 RTError:
123 Msgbox sRTErrorDesc, 16, sRTErrorHeader
124 End Sub
128 Sub PrevStep()
129 Dim iCurStep as Integer
130 If Not bDebugWizard Then
131 On Error Goto RTError
132 End If
133 bConversionIsRunning = False
134 iCurStep = ImportDialog.Step
135 Select Case iCurStep
136 Case 4
137 ImportDialog.cmdCancel.Label = sCancelButton
138 FillStep_Summary()
139 Case 3
140 FillStep_InputPaths(Applcount-1, False)
141 Case 2
142 SaveStep_InputPath
143 If CurOffice &gt; 0 Then
144 CurOffice = CurOffice - 1
145 FillStep_InputPaths(CurOffice, False)
146 Else
147 FillStep_Welcome()
148 ToggleCheckboxesWithBoolean(True)
149 bDoKeepApplValues = True
150 End If
151 End Select
152 ImportDialog.cmdGoOn.DefaultButton = True
153 RepaintHeaderPreview()
154 Exit Sub
155 RTError:
156 Msgbox sRTErrorDesc, 16, sRTErrorHeader
157 End Sub
161 Sub CancelTask()
162 If bConversionIsRunning Then
163 If Msgbox(sConvertError1, 36, sConvertError2) = 6 Then
164 bCancelTask = True
165 bInterruptSearch = True
166 Else
167 bCancelTask = False
168 ImportDialog.cmdCancel.Enabled = True
169 End If
170 Else
171 ImportDialogArea.EndExecute()
172 End If
173 End Sub
176 Sub TemplateDirSearchDialog()
177 CallDirSearchDialog(ImportDialog.TemplateImportPath)
178 End Sub
181 Sub RepaintHeaderPreview()
182 Dim Bitmap As Object
183 Dim CurStep as Integer
184 Dim sBitmapPath as String
185 Dim LocPrefix as String
186 CurStep = ImportDialog.Step
187 LocPrefix = WizardMode
188 LocPrefix = ReplaceString(LocPrefix,&quot;XML&quot;, &quot;SO&quot;)
189 If CurStep = 2 Then
190 sBitmapPath = SOBitmapPath &amp; LocPrefix &amp; &quot;-Import_&quot; &amp; CurStep &amp; &quot;-&quot; &amp; Applications(CurOffice,SBAPPLKEY) + 1 &amp; &quot;.bmp&quot;
191 Else
192 sBitmapPath = SOBitmapPath &amp; &quot;Import_&quot; &amp; CurStep &amp; &quot;.bmp&quot;
193 End If
194 ImportDialog.ImportPreview.ImageURL = sBitmapPath
195 End Sub
198 Sub CheckModuleInstallation()
199 Dim i as Integer
200 For i = 1 To MaxApplCount
201 ImportDialogArea.GetControl(&quot;chk&quot; &amp; WizardMode &amp; &quot;Application&quot; &amp; i).Model.Enabled = Abs(CheckInstalledModule(i-1))
202 Next i
203 End Sub
206 Function createBF_MigrateFilterIfPossible()
207 Dim oService
208 On Error Goto RTError
209 oService = createUnoService(&quot;com.sun.star.comp.office.BF_MigrateFilter&quot;)
210 getBinFilterCompIfItExists = oService
211 Exit Function
212 RTError:
213 createBF_MigrateFilterIfPossible = Nothing
214 End Function
217 Function CheckInstalledModule(Index as Integer) as Boolean
218 Dim ModuleName as String
219 Dim NameList() as String
220 Dim MaxIndex as Integer
221 Dim i as Integer
222 ModuleName = ModuleList(Index)
223 If Instr(1,ModuleName,&quot;/&quot;) &lt;&gt; 0 Then
224 CheckInstalledModule() = False
225 NameList() = ArrayoutOfString(ModuleName,&quot;/&quot;, MaxIndex)
226 For i = 0 To MaxIndex
227 If oFactoryKey.HasByName(NameList(i)) Then
228 CheckInstalledModule() = True
229 End If
230 Next i
231 Else
232 CheckInstalledModule() = oFactoryKey.HasByName(ModuleName)
233 End If
234 End Function
237 Sub ToggleCheckboxes(oEvent as Object)
238 Dim bMSEnable as Boolean
239 WizardMode = oEvent.Source.Model.Tag
240 bMSEnable = WizardMode = &quot;MS&quot;
241 ToggleCheckboxesWithBoolean(bMSEnable)
242 End Sub
245 Sub ToggleCheckboxesWithBoolean(bMSEnable as Boolean)
246 If bMSEnable = True Then
247 WizardMode = SBMICROSOFTMODE
248 MaxApplCount = 3
249 Else
250 WizardMode = SBXMLMODE
251 MaxApplCount = 4
252 End If
253 With ImportDialogArea
254 If (isNull(oBinFilterComp)) Then
255 .GetControl(&quot;optSODocuments&quot;).Visible = False
256 .GetControl(&quot;chkSOApplication1&quot;).Visible = False
257 .GetControl(&quot;chkSOApplication2&quot;).Visible = False
258 .GetControl(&quot;chkSOApplication3&quot;).Visible = False
259 .GetControl(&quot;chkSOApplication4&quot;).Visible = False
260 Else
261 .GetControl(&quot;chkSOApplication1&quot;).Model.Enabled = Not bMSEnable
262 .GetControl(&quot;chkSOApplication2&quot;).Model.Enabled = Not bMSEnable
263 .GetControl(&quot;chkSOApplication3&quot;).Model.Enabled = Not bMSEnable
264 .GetControl(&quot;chkSOApplication4&quot;).Model.Enabled = Not bMSEnable
265 End if
266 .GetControl(&quot;chkMSApplication1&quot;).Model.Enabled = bMSEnable
267 .GetControl(&quot;chkMSApplication2&quot;).Model.Enabled = bMSEnable
268 .GetControl(&quot;chkMSApplication3&quot;).Model.Enabled = bMSEnable
269 End With
270 CheckModuleInstallation()
271 bDoKeepApplValues = False
272 ToggleNextButton()
273 End Sub
276 Sub ToggleNextButton()
277 Dim iCurStep as Integer
278 Dim bDoEnable as Boolean
279 Dim i as Integer
280 iCurStep = ImportDialog.Step
281 Select Case iCurStep
282 Case 1
283 With ImportDialog
284 If .optMSDocuments.State = 1 Then
285 bDoEnable = .chkMSApplication1.State = 1 Or .chkMSApplication2.State = 1 Or .chkMSApplication3.State = 1
286 Else
287 bDoEnable = .chkSOApplication1.State = 1 Or .chkSOApplication2.State = 1 Or .chkSOApplication3.State = 1 Or .chkSOApplication4.State = 1
288 End If
289 End With
290 bDoKeepApplValues = False
291 Case 2
292 bDoEnable = CheckControlPath(ImportDialog.chkTemplatePath, ImportDialog.txtTemplateImportPath, True)
293 bDoEnable = CheckControlPath(ImportDialog.chkDocumentPath, ImportDialog.txtDocumentImportPath, bDoEnable)
294 End Select
295 ImportDialog.cmdGoOn.Enabled = bDoEnable
296 End Sub
299 Sub TakeOverPathSettings()
300 &apos;Takes over the Pathsettings from the first selected application to the next applications
301 If Applications(CurOffice,SBDOCSOURCE) = &quot;&quot; Then
302 Applications(CurOffice,SBDOCSOURCE) = Applications(0,SBDOCSOURCE)
303 Applications(CurOffice,SBDOCTARGET) = Applications(0,SBDOCTARGET)
304 If WizardMode = SBXMLMODE AND Applications(CurOffice,SBAPPLKEY) = 3 Then
305 Applications(CurOffice,SBTEMPLSOURCE) = Applications(CurOffice,SBDOCSOURCE)
306 Applications(CurOffice,SBTEMPLTARGET) = Applications(CurOffice,SBDOCTARGET)
307 Else
308 Applications(CurOffice,SBTEMPLSOURCE) = Applications(0,SBTEMPLSOURCE)
309 Applications(CurOffice,SBTEMPLTARGET) = Applications(0,SBTEMPLTARGET)
310 End If
311 End If
312 End Sub
315 Function GetImportWizardPaths() as Boolean
316 SOBitmapPath = GetOfficeSubPath(&quot;Template&quot;, &quot;../wizard/bitmap&quot;)
317 If SOBitmapPath &lt;&gt; &quot;&quot; Then
318 SOWorkPath = GetPathSettings(&quot;Work&quot;, False)
319 If SOWorkPath &lt;&gt; &quot;&quot; Then
320 SOTemplatePath = GetPathSettings(&quot;Template_writable&quot;,False,0)
321 If SOTemplatePath &lt;&gt; &quot;&quot; Then
322 GetImportWizardPaths() = True
323 Exit Function
324 End If
325 End If
326 End If
327 GetImportWizardPaths() = False
328 End Function
329 </script:module>