Main.xba 9.2 KB

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