use more concrete UNO in extensions
[LibreOffice.git] / wizards / source / importwizard / Main.xba
blobb8cc8211edfbcf1be32800f1f8b3e55eacb21c65
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
21 REM ***** 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 is 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
80 Sub NextStep()
81 Dim iCurStep as Integer
82 If Not bDebugWizard Then
83 On Error Goto RTError
84 End If
85 bConversionIsRunning = False
86 iCurStep = ImportDialog.Step
87 Select Case iCurStep
88 Case 1
89 FillStep_InputPaths(0, True)
90 Case 2
91 If CheckInputPaths Then
92 SaveStep_InputPath
93 If CurOffice &lt; ApplCount - 1 Then
94 CurOffice = CurOffice + 1
95 TakeOverPathSettings()
96 FillStep_InputPaths(CurOffice, False)
97 Else
98 FillStep_Summary()
99 End If
100 End If
101 Case 3
102 FillStep_Progress()
103 Select Case WizardMode
104 Case SBMICROSOFTMODE
105 Call ConvertAllDocuments(MSFilterName())
106 End Select
107 Case 4
108 CancelTask(True)
109 End Select
111 If ((ImportDialog.chkLogfile.State &lt;&gt; 1) OR (iCurStep &lt;&gt; 3)) Then
112 ImportDialog.cmdGoOn.DefaultButton = True
113 End If
115 RepaintHeaderPreview()
116 Exit Sub
117 RTError:
118 Msgbox sRTErrorDesc, 16, sRTErrorHeader
119 End Sub
122 Sub PrevStep()
123 Dim iCurStep as Integer
124 If Not bDebugWizard Then
125 On Error Goto RTError
126 End If
127 bConversionIsRunning = False
128 iCurStep = ImportDialog.Step
129 Select Case iCurStep
130 Case 4
131 ImportDialog.cmdCancel.Label = sCancelButton
132 FillStep_Summary()
133 Case 3
134 FillStep_InputPaths(Applcount-1, False)
135 Case 2
136 SaveStep_InputPath
137 If CurOffice &gt; 0 Then
138 CurOffice = CurOffice - 1
139 FillStep_InputPaths(CurOffice, False)
140 Else
141 FillStep_Welcome()
142 ToggleCheckboxesWithBoolean(True)
143 bDoKeepApplValues = True
144 End If
145 End Select
146 ImportDialog.cmdGoOn.DefaultButton = True
147 RepaintHeaderPreview()
148 Exit Sub
149 RTError:
150 Msgbox sRTErrorDesc, 16, sRTErrorHeader
151 End Sub
154 Sub CancelTask()
155 If bConversionIsRunning Then
156 If Msgbox(sConvertError1, 36, sConvertError2) = 6 Then
157 bCancelTask = True
158 bInterruptSearch = True
159 Else
160 bCancelTask = False
161 ImportDialog.cmdCancel.Enabled = True
162 End If
163 Else
164 ImportDialogArea.EndExecute()
165 End If
166 End Sub
169 Sub TemplateDirSearchDialog()
170 CallDirSearchDialog(ImportDialog.TemplateImportPath)
171 End Sub
174 Sub RepaintHeaderPreview()
175 Dim Bitmap As Object
176 Dim CurStep as Integer
177 Dim sBitmapPath as String
178 Dim LocPrefix as String
179 CurStep = ImportDialog.Step
180 LocPrefix = WizardMode
181 LocPrefix = ReplaceString(LocPrefix,&quot;XML&quot;, &quot;SO&quot;)
182 If CurStep = 2 Then
183 sBitmapPath = SOBitmapPath &amp; LocPrefix &amp; &quot;-Import_&quot; &amp; CurStep &amp; &quot;-&quot; &amp; Applications(CurOffice,SBAPPLKEY) + 1 &amp; &quot;.png&quot;
184 Else
185 sBitmapPath = SOBitmapPath &amp; &quot;Import_&quot; &amp; CurStep &amp; &quot;.png&quot;
186 End If
187 ImportDialog.ImportPreview.ImageURL = sBitmapPath
188 End Sub
191 Sub CheckModuleInstallation()
192 Dim i as Integer
193 For i = 1 To MaxApplCount
194 ImportDialogArea.GetControl(&quot;chk&quot; &amp; WizardMode &amp; &quot;Application&quot; &amp; i).Model.Enabled = Abs(CheckInstalledModule(i-1))
195 Next i
196 End Sub
199 Function CheckInstalledModule(Index as Integer) as Boolean
200 Dim ModuleName as String
201 Dim NameList() as String
202 Dim MaxIndex as Integer
203 Dim i as Integer
204 ModuleName = ModuleList(Index)
205 If Instr(1,ModuleName,&quot;/&quot;) &lt;&gt; 0 Then
206 CheckInstalledModule() = False
207 NameList() = ArrayoutOfString(ModuleName,&quot;/&quot;, MaxIndex)
208 For i = 0 To MaxIndex
209 If oFactoryKey.HasByName(NameList(i)) Then
210 CheckInstalledModule() = True
211 End If
212 Next i
213 Else
214 CheckInstalledModule() = oFactoryKey.HasByName(ModuleName)
215 End If
216 End Function
219 Sub ToggleCheckboxes(oEvent as Object)
220 Dim bMSEnable as Boolean
221 WizardMode = oEvent.Source.Model.Tag
222 bMSEnable = WizardMode = &quot;MS&quot;
223 ToggleCheckboxesWithBoolean(bMSEnable)
224 End Sub
227 Sub ToggleCheckboxesWithBoolean(bMSEnable as Boolean)
228 If bMSEnable = True Then
229 WizardMode = SBMICROSOFTMODE
230 MaxApplCount = 3
231 Else
232 &apos;Not supposed to happen - is there an assert in BASIC...
233 End If
234 With ImportDialogArea
235 .GetControl(&quot;chkMSApplication1&quot;).Model.Enabled = bMSEnable
236 .GetControl(&quot;chkMSApplication2&quot;).Model.Enabled = bMSEnable
237 .GetControl(&quot;chkMSApplication3&quot;).Model.Enabled = bMSEnable
238 End With
239 CheckModuleInstallation()
240 bDoKeepApplValues = False
241 ToggleNextButton()
242 End Sub
245 Sub ToggleNextButton()
246 Dim iCurStep as Integer
247 Dim bDoEnable as Boolean
248 Dim i as Integer
249 iCurStep = ImportDialog.Step
250 Select Case iCurStep
251 Case 1
252 With ImportDialog
253 If .optMSDocuments.State = 1 Then
254 bDoEnable = .chkMSApplication1.State = 1 Or .chkMSApplication2.State = 1 Or .chkMSApplication3.State = 1
255 End If
256 End With
257 bDoKeepApplValues = False
258 Case 2
259 bDoEnable = CheckControlPath(ImportDialog.chkTemplatePath, ImportDialog.txtTemplateImportPath, True)
260 bDoEnable = CheckControlPath(ImportDialog.chkDocumentPath, ImportDialog.txtDocumentImportPath, bDoEnable)
261 End Select
262 ImportDialog.cmdGoOn.Enabled = bDoEnable
263 End Sub
266 Sub TakeOverPathSettings()
267 &apos;Takes over the Pathsettings from the first selected application to the next applications
268 If Applications(CurOffice,SBDOCSOURCE) = &quot;&quot; Then
269 Applications(CurOffice,SBDOCSOURCE) = Applications(0,SBDOCSOURCE)
270 Applications(CurOffice,SBDOCTARGET) = Applications(0,SBDOCTARGET)
271 Applications(CurOffice,SBTEMPLSOURCE) = Applications(0,SBTEMPLSOURCE)
272 Applications(CurOffice,SBTEMPLTARGET) = Applications(0,SBTEMPLTARGET)
273 End If
274 End Sub
277 Function GetImportWizardPaths() as Boolean
278 SOBitmapPath = GetOfficeSubPath(&quot;Template&quot;, &quot;../wizard/bitmap&quot;)
279 If SOBitmapPath &lt;&gt; &quot;&quot; Then
280 SOWorkPath = GetPathSettings(&quot;Work&quot;, False)
281 If SOWorkPath &lt;&gt; &quot;&quot; Then
282 SOTemplatePath = GetPathSettings(&quot;Template_writable&quot;,False,0)
283 If SOTemplatePath &lt;&gt; &quot;&quot; Then
284 GetImportWizardPaths() = True
285 Exit Function
286 End If
287 End If
288 End If
289 GetImportWizardPaths() = False
290 End Function
291 </script:module>