Main.xba 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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.
  5. *
  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/.
  9. *
  10. * This file incorporates work covered by the following license notice:
  11. *
  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 *****
  22. Public HeaderPreviews(4) as Object
  23. Public ImportDialog as Object
  24. Public ImportDialogArea as Object
  25. Public oFactoryKey as Object
  26. Public bShowLogFile as Boolean
  27. &apos; If the ProgressPage is already on Top The Dialog will be immediately closed when this flag is
  28. &apos; set to False
  29. Public bConversionIsRunning as Boolean
  30. Public RetValue as Integer
  31. Sub Main()
  32. Dim NoArgs() as New com.sun.star.beans.PropertyValue
  33. bShowLogFile=FALSE
  34. If Not bDebugWizard Then
  35. On Local Error Goto RTError
  36. End If
  37. BasicLibraries.LoadLibrary(&quot;Tools&quot;)
  38. RetValue = 10
  39. bIsFirstLogTable = True
  40. bConversionIsRunning = False
  41. sCRLF = CHR(13) &amp; CHR(10)
  42. oUcb = createUnoService(&quot;com.sun.star.ucb.SimpleFileAccess&quot;)
  43. oFactoryKey = GetRegistryKeyContent(&quot;org.openoffice.Setup/Office/Factories&quot;)
  44. If GetImportWizardPaths() = False Then
  45. Exit Sub
  46. End If
  47. bCancelTask = False
  48. bDoKeepApplValues = False
  49. CurOffice = 0
  50. ImportDialogArea = LoadDialog(&quot;ImportWizard&quot;,&quot;ImportDialog&quot;)
  51. ImportDialog = ImportDialogArea.Model
  52. LoadLanguage()
  53. WizardMode = SBMICROSOFTMODE
  54. MaxApplCount = 3
  55. FillStep_Welcome()
  56. RepaintHeaderPreview()
  57. ImportDialog.ImportPreview.BackGroundColor = RGB(0,60,126)
  58. ImportDialog.cmdGoOn.DefaultButton = True
  59. ImportDialogArea.GetControl(&quot;optMSDocuments&quot;).SetFocus()
  60. ToggleCheckboxesWithBoolean(True)
  61. RetValue = ImportDialogArea.Execute()
  62. If bShowLogFile=TRUE Then
  63. OpenDocument(sLogUrl, NoArgs())
  64. End if
  65. If RetValue = 0 Then
  66. CancelTask()
  67. End If
  68. ImportDialogArea.Dispose()
  69. End
  70. Exit Sub
  71. RTError:
  72. Msgbox sRTErrorDesc, 16, sRTErrorHeader
  73. End Sub
  74. Sub NextStep()
  75. Dim iCurStep as Integer
  76. If Not bDebugWizard Then
  77. On Error Goto RTError
  78. End If
  79. bConversionIsRunning = False
  80. iCurStep = ImportDialog.Step
  81. Select Case iCurStep
  82. Case 1
  83. FillStep_InputPaths(0, True)
  84. Case 2
  85. If CheckInputPaths Then
  86. SaveStep_InputPath
  87. If CurOffice &lt; ApplCount - 1 Then
  88. CurOffice = CurOffice + 1
  89. TakeOverPathSettings()
  90. FillStep_InputPaths(CurOffice, False)
  91. Else
  92. FillStep_Summary()
  93. End If
  94. End If
  95. Case 3
  96. FillStep_Progress()
  97. Select Case WizardMode
  98. Case SBMICROSOFTMODE
  99. Call ConvertAllDocuments(MSFilterName())
  100. End Select
  101. Case 4
  102. CancelTask(True)
  103. End Select
  104. If ((ImportDialog.chkLogfile.State &lt;&gt; 1) OR (iCurStep &lt;&gt; 3)) Then
  105. ImportDialog.cmdGoOn.DefaultButton = True
  106. End If
  107. RepaintHeaderPreview()
  108. Exit Sub
  109. RTError:
  110. Msgbox sRTErrorDesc, 16, sRTErrorHeader
  111. End Sub
  112. Sub PrevStep()
  113. Dim iCurStep as Integer
  114. If Not bDebugWizard Then
  115. On Error Goto RTError
  116. End If
  117. bConversionIsRunning = False
  118. iCurStep = ImportDialog.Step
  119. Select Case iCurStep
  120. Case 4
  121. ImportDialog.cmdCancel.Label = sCancelButton
  122. FillStep_Summary()
  123. Case 3
  124. FillStep_InputPaths(Applcount-1, False)
  125. Case 2
  126. SaveStep_InputPath
  127. If CurOffice &gt; 0 Then
  128. CurOffice = CurOffice - 1
  129. FillStep_InputPaths(CurOffice, False)
  130. Else
  131. FillStep_Welcome()
  132. ToggleCheckboxesWithBoolean(True)
  133. bDoKeepApplValues = True
  134. End If
  135. End Select
  136. ImportDialog.cmdGoOn.DefaultButton = True
  137. RepaintHeaderPreview()
  138. Exit Sub
  139. RTError:
  140. Msgbox sRTErrorDesc, 16, sRTErrorHeader
  141. End Sub
  142. Sub CancelTask()
  143. If bConversionIsRunning Then
  144. If Msgbox(sConvertError1, 36, sConvertError2) = 6 Then
  145. bCancelTask = True
  146. bInterruptSearch = True
  147. Else
  148. bCancelTask = False
  149. ImportDialog.cmdCancel.Enabled = True
  150. End If
  151. Else
  152. ImportDialogArea.EndExecute()
  153. End If
  154. End Sub
  155. Sub TemplateDirSearchDialog()
  156. CallDirSearchDialog(ImportDialog.TemplateImportPath)
  157. End Sub
  158. Sub RepaintHeaderPreview()
  159. Dim Bitmap As Object
  160. Dim CurStep as Integer
  161. Dim sBitmapPath as String
  162. Dim LocPrefix as String
  163. CurStep = ImportDialog.Step
  164. LocPrefix = WizardMode
  165. LocPrefix = ReplaceString(LocPrefix,&quot;XML&quot;, &quot;SO&quot;)
  166. If CurStep = 2 Then
  167. sBitmapPath = SOBitmapPath &amp; LocPrefix &amp; &quot;-Import_&quot; &amp; CurStep &amp; &quot;-&quot; &amp; Applications(CurOffice,SBAPPLKEY) + 1 &amp; &quot;.png&quot;
  168. Else
  169. sBitmapPath = SOBitmapPath &amp; &quot;Import_&quot; &amp; CurStep &amp; &quot;.png&quot;
  170. End If
  171. ImportDialog.ImportPreview.ImageURL = sBitmapPath
  172. End Sub
  173. Sub CheckModuleInstallation()
  174. Dim i as Integer
  175. For i = 1 To MaxApplCount
  176. ImportDialogArea.GetControl(&quot;chk&quot; &amp; WizardMode &amp; &quot;Application&quot; &amp; i).Model.Enabled = Abs(CheckInstalledModule(i-1))
  177. Next i
  178. End Sub
  179. Function CheckInstalledModule(Index as Integer) as Boolean
  180. Dim ModuleName as String
  181. Dim NameList() as String
  182. Dim MaxIndex as Integer
  183. Dim i as Integer
  184. ModuleName = ModuleList(Index)
  185. If Instr(1,ModuleName,&quot;/&quot;) &lt;&gt; 0 Then
  186. CheckInstalledModule() = False
  187. NameList() = ArrayoutOfString(ModuleName,&quot;/&quot;, MaxIndex)
  188. For i = 0 To MaxIndex
  189. If oFactoryKey.HasByName(NameList(i)) Then
  190. CheckInstalledModule() = True
  191. End If
  192. Next i
  193. Else
  194. CheckInstalledModule() = oFactoryKey.HasByName(ModuleName)
  195. End If
  196. End Function
  197. Sub ToggleCheckboxes(oEvent as Object)
  198. Dim bMSEnable as Boolean
  199. WizardMode = oEvent.Source.Model.Tag
  200. bMSEnable = WizardMode = &quot;MS&quot;
  201. ToggleCheckboxesWithBoolean(bMSEnable)
  202. End Sub
  203. Sub ToggleCheckboxesWithBoolean(bMSEnable as Boolean)
  204. If bMSEnable = True Then
  205. WizardMode = SBMICROSOFTMODE
  206. MaxApplCount = 3
  207. Else
  208. &apos;Not supposed to happen - is there an assert in BASIC...
  209. End If
  210. With ImportDialogArea
  211. .GetControl(&quot;chkMSApplication1&quot;).Model.Enabled = bMSEnable
  212. .GetControl(&quot;chkMSApplication2&quot;).Model.Enabled = bMSEnable
  213. .GetControl(&quot;chkMSApplication3&quot;).Model.Enabled = bMSEnable
  214. End With
  215. CheckModuleInstallation()
  216. bDoKeepApplValues = False
  217. ToggleNextButton()
  218. End Sub
  219. Sub ToggleNextButton()
  220. Dim iCurStep as Integer
  221. Dim bDoEnable as Boolean
  222. Dim i as Integer
  223. iCurStep = ImportDialog.Step
  224. Select Case iCurStep
  225. Case 1
  226. With ImportDialog
  227. If .optMSDocuments.State = 1 Then
  228. bDoEnable = .chkMSApplication1.State = 1 Or .chkMSApplication2.State = 1 Or .chkMSApplication3.State = 1
  229. End If
  230. End With
  231. bDoKeepApplValues = False
  232. Case 2
  233. bDoEnable = CheckControlPath(ImportDialog.chkTemplatePath, ImportDialog.txtTemplateImportPath, True)
  234. bDoEnable = CheckControlPath(ImportDialog.chkDocumentPath, ImportDialog.txtDocumentImportPath, bDoEnable)
  235. End Select
  236. ImportDialog.cmdGoOn.Enabled = bDoEnable
  237. End Sub
  238. Sub TakeOverPathSettings()
  239. &apos;Takes over the Pathsettings from the first selected application to the next applications
  240. If Applications(CurOffice,SBDOCSOURCE) = &quot;&quot; Then
  241. Applications(CurOffice,SBDOCSOURCE) = Applications(0,SBDOCSOURCE)
  242. Applications(CurOffice,SBDOCTARGET) = Applications(0,SBDOCTARGET)
  243. Applications(CurOffice,SBTEMPLSOURCE) = Applications(0,SBTEMPLSOURCE)
  244. Applications(CurOffice,SBTEMPLTARGET) = Applications(0,SBTEMPLTARGET)
  245. End If
  246. End Sub
  247. Function GetImportWizardPaths() as Boolean
  248. SOBitmapPath = GetOfficeSubPath(&quot;Template&quot;, &quot;../wizard/bitmap&quot;)
  249. If SOBitmapPath &lt;&gt; &quot;&quot; Then
  250. SOWorkPath = GetPathSettings(&quot;Work&quot;, False)
  251. If SOWorkPath &lt;&gt; &quot;&quot; Then
  252. SOTemplatePath = GetPathSettings(&quot;Template_writable&quot;,False,0)
  253. If SOTemplatePath &lt;&gt; &quot;&quot; Then
  254. GetImportWizardPaths() = True
  255. Exit Function
  256. End If
  257. End If
  258. End If
  259. GetImportWizardPaths() = False
  260. End Function
  261. </script:module>