Bump version to 4.1-6
[LibreOffice.git] / wizards / source / euro / AutoPilotRun.xba
blobfe2bed7a7d550b3d83b0fc562fffe3f9f6fd117a
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="AutoPilotRun" script:language="StarBasic">Option Explicit
22 Public SourceDir as String
23 Public TargetDir as String
24 Public TargetStemDir as String
25 Public SourceFile as String
26 Public TargetFile as String
27 Public Source as String
28 Public SubstFile as String
29 Public SubstDir as String
30 Public NoArgs()
31 Public TypeList(6) as String
32 Public GoOn as Boolean
33 Public DoUnprotect as Integer
34 Public Password as String
35 Public DocIndex as Integer
36 Public oPathSettings as Object
37 Public oUcb as Object
38 Public TotDocCount as Integer
39 Public sTotDocCount as String
40 Public OpenProperties(1) as New com.sun.star.beans.PropertyValue
43 Sub StartAutoPilot()
44 Dim i As Integer
45 Dim oFactoryKey as Object
46 BasicLibraries.LoadLibrary(&quot;Tools&quot;)
47 BasicLibraries.LoadLibrary(&quot;ImportWizard&quot;)
48 If InitResources(&quot;Euro Converter&quot;, &quot;eur&quot;) Then
49 oUcb = createUnoService(&quot;com.sun.star.ucb.SimpleFileAccess&quot;)
50 oLocale = GetStarOfficeLocale()
51 InitializeConverter(oLocale, 2)
52 ToggleGoOnButton()
53 oFactoryKey = GetRegistryKeyContent(&quot;org.openoffice.Setup/Office/Factories&quot;)
54 DialogModel.chkTextDocuments.Enabled = oFactoryKey.hasbyName(&quot;com.sun.star.text.TextDocument&quot;)
55 DialogModel.cmdGoOn.DefaultButton = True
56 DialogModel.lstCurrencies.TabIndex = 12
57 DialogConvert.GetControl(&quot;optWholeDir&quot;).SetFocus()
58 DialogConvert.Execute()
59 DialogConvert.Dispose()
60 End If
61 End Sub
64 Sub ConvertDocuments()
65 Dim FilesList()
66 Dim bDisposable as Boolean
68 If Source &lt;&gt; &quot;&quot; And TargetDir &lt;&gt; &quot;&quot; Then
69 If DialogModel.optSingleFile.State = 1 Then
70 SourceFile = Source
71 TotDocCount = 1
72 Else
73 SourceDir = Source
74 TargetStemDir = TargetDir
75 TypeList(0) = &quot;calc8&quot;
76 TypeList(1) = &quot;calc_StarOffice_XML_Calc&quot;
77 If DialogModel.chkTextDocuments.State = 1 Then
78 ReDim Preserve TypeList(5) as String
80 TypeList(2) = &quot;writer8&quot;
81 TypeList(3) = &quot;writerglobal8&quot;
82 TypeList(4) = &quot;writer_StarOffice_XML_Writer&quot;
83 TypeList(5) = &quot;writer_globaldocument_StarOffice_XML_Writer_GlobalDocument&quot;
84 End If
85 FilesList() = ReadDirectories(SourceDir, bRecursive, True, False, TypeList())
86 TotDocCount = Ubound(FilesList(),1) + 1
87 End If
88 InitializeProgressPage(DialogModel)
89 &apos; ChangeToNextProgressStep()
90 sTotDocCount = CStr(TotDocCount)
91 OpenProperties(0).Name = &quot;Hidden&quot;
92 OpenProperties(0).Value = True
93 OpenProperties(1).Name = &quot;AsTemplate&quot;
94 OpenProperties(1).Value = False
95 For DocIndex = 0 To TotDocCount - 1
96 If InitializeDocument(FilesList(), bDisposable) Then
97 If StoreDocument() Then
98 ConvertDocument()
99 oDocument.Store
100 End If
101 If bDisposable Then
102 oDocument.Dispose()
103 End If
104 End If
105 Next DocIndex
106 DialogModel.cmdBack.Enabled = True
107 DialogModel.cmdGoOn.Enabled = True
108 DialogModel.cmdGoOn.Label = sReady
109 DialogModel.cmdCancel.Label = sEnd
110 End If
111 End Sub
114 Function InitializeDocument(FilesList(), bDisposable as Boolean) as Boolean
115 &apos; The Autopilot is started from step No. 2
116 Dim sViewPath as String
117 Dim bIsReadOnly as Boolean
118 Dim sExtension as String
119 On Local Error Goto NEXTFILE
120 If Not bCancelTask Then
121 If DialogModel.optWholeDir.State = 1 Then
122 SourceFile = FilesList(DocIndex,0)
123 TargetFile = ReplaceString(SourceFile,TargetStemDir,SourceDir)
124 TargetDir = DirectorynameoutofPath(TargetFile, &quot;/&quot;)
125 Else
126 SourceFile = Source
127 TargetFile = TargetDir &amp; &quot;/&quot; &amp; FileNameoutofPath(SourceFile, &quot;/&quot;)
128 End If
129 If CreateFolder(TargetDir) Then
130 sExtension = GetFileNameExtension(SourceFile, &quot;/&quot;)
131 oDocument = OpenDocument(SourceFile, OpenProperties(), bDisposable)
132 If (oDocument.IsReadOnly) AND (UCase(SourceFile) = UCase(TargetFile)) Then
133 bIsReadOnly = True
134 Msgbox(sMsgDOCISREADONLY, 16, GetProductName())
135 Else
136 bIsReadOnly = False
137 RetrieveDocumentObjects()
138 sViewPath = CutPathView(SourceFile, 60)
139 DialogModel.lblCurDocument.Label = Str(DocIndex+1) &amp; &quot;/&quot; &amp; sTotDocCount &amp; &quot; (&quot; &amp; sViewPath &amp; &quot;)&quot;
140 End If
141 InitializeDocument() = Not bIsReadOnly
142 Else
143 InitializeDocument() = False
144 End If
145 Else
146 InitializeDocument() = False
147 End If
148 NEXTFILE:
149 If Err &lt;&gt; 0 Then
150 InitializeDocument() = False
151 Resume LETSGO
152 LETSGO:
153 End If
154 End Function
157 Sub ChangeToNextProgressStep()
158 DialogModel.lblCurProgress.FontWeight = com.sun.star.awt.FontWeight.NORMAL
159 DialogConvert.GetControl(&quot;lblCurProgress&quot;).Visible = True
160 End Sub
163 Function StoreDocument() as Boolean
164 Dim sCurFileExists as String
165 Dim iOverWrite as Integer
166 If (TargetFile &lt;&gt; &quot;&quot;) And (Not bCancelTask) Then
167 On Local Error Goto NOSAVING
168 If oUcb.Exists(TargetFile) Then
169 sCurFileExists = ReplaceString(sMsgFileExists, ConvertFromUrl(TargetFile), &quot;&lt;1&gt;&quot;)
170 sCurFileExists = ReplaceString(sCurFileExists, chr(13), &quot;&lt;CR&gt;&quot;)
171 iOverWrite = Msgbox (sCurFileExists, 32 + 3, sMsgDLGTITLE)
172 Select Case iOverWrite
173 Case 1 &apos; OK
174 Case 2 &apos; Abort
175 bCancelTask = True
176 StoreDocument() = False
177 Exit Function
178 Case 7 &apos; No
179 StoreDocument() = False
180 Exit Function
181 End Select
182 End If
183 If TargetFile &lt;&gt; SourceFile Then
184 oDocument.StoreAsUrl(TargetFile,NoArgs)
185 Else
186 oDocument.Store
187 End If
188 StoreDocument() = True
189 NOSAVING:
190 If Err &lt;&gt; 0 Then
191 StoreDocument() = False
192 Resume CLERROR
193 End If
194 CLERROR:
195 End If
196 End Function
199 Sub SwapExtent()
200 DialogModel.chkRecursive.Enabled = DialogModel.optWholeDir.State = 1
201 If DialogModel.optWholeDir.State = 1 Then
202 DialogModel.lblSource.Label = sSOURCEDIR
203 If Not IsNull(SubstFile) Then
204 SubstFile = DialogModel.txtSource.Text
205 DialogModel.txtSource.Text = SubstDir
206 End If
207 Else
208 DialogModel.LblSource.Label = sSOURCEFILE
209 If Not IsNull(SubstDir) Then
210 SubstDir = DialogModel.txtSource.Text
211 DialogModel.txtSource.Text = SubstFile
212 End If
213 End If
214 ToggleGoOnButton()
215 End Sub
218 Function InitializeThirdStep() as Boolean
219 Dim TextBoxText as String
220 Source = AssignFileName(DialogModel.txtSource.Text, DialogModel.lblSource.Label, True)
221 If CheckTextBoxPath(DialogModel.txtTarget, True, True, sMsgDLGTITLE, True) Then
222 TargetDir = AssignFileName(DialogModel.txtTarget.Text, DialogModel.lblTarget.Label, False)
223 Else
224 TargetDir = &quot;&quot;
225 End If
226 If Source &lt;&gt; &quot;&quot; And TargetDir &lt;&gt; &quot;&quot; Then
227 bRecursive = DialogModel.chkRecursive.State = 1
228 bDoUnprotect = DialogModel.chkProtect.State = 1
229 DialogModel.lblRetrieval.FontWeight = com.sun.star.awt.FontWeight.BOLD
230 DialogModel.lblRetrieval.Label = sPrgsRETRIEVAL
231 DialogModel.lblCurProgress.Label = sPrgsCONVERTING
232 If DialogModel.optWholeDir.State = 1 Then
233 TextBoxText = sSOURCEDIR &amp; &quot; &quot; &amp; ConvertFromUrl(Source) &amp; chr(13)
234 If DialogModel.chkRecursive.State = 1 Then
235 TextBoxText = TextBoxText &amp; DeleteStr(sInclusiveSubDir,&quot;~&quot;) &amp; chr(13)
236 End If
237 Else
238 TextBoxText = sSOURCEFILE &amp; &quot; &quot; &amp; ConvertFromUrl(Source) &amp; chr(13)
239 End If
240 TextBoxText = TextBoxText &amp; sTARGETDIR &amp; &quot; &quot; &amp; ConvertFromUrl(TargetDir) &amp; chr(13)
241 If DialogModel.chkProtect.State = 1 Then
242 TextBoxText = TextboxText &amp; sPrgsUNPROTECT
243 End If
244 DialogModel.txtConfig.Text = TextBoxText
245 ToggleProgressStep()
246 DialogModel.cmdGoOn.Enabled = False
247 InitializeThirdStep() = True
248 Else
249 InitializeThirdStep() = False
250 End If
251 End Function
254 Sub ToggleProgressStep(Optional aEvent as Object)
255 Dim bMakeVisible as Boolean
256 Dim LocStep as Integer
257 &apos; If the Sub is call by the &apos;cmdBack&apos; Button then set the &apos;bMakeVisible&apos; variable accordingly
258 bMakeVisible = IsMissing(aEvent)
259 If bMakeVisible Then
260 DialogModel.Step = 3
261 Else
262 DialogModel.Step = 2
263 End If
264 DialogConvert.GetControl(&quot;lblCurrencies&quot;).Visible = Not bMakeVisible
265 DialogConvert.GetControl(&quot;lstCurrencies&quot;).Visible = Not bMakeVisible
266 DialogConvert.GetControl(&quot;cmdBack&quot;).Visible = bMakeVisible
267 DialogConvert.GetControl(&quot;cmdGoOn&quot;).Visible = bMakeVisible
268 DialogModel.imgPreview.ImageUrl = BitmapDir &amp; &quot;euro_&quot; &amp; DialogModel.Step &amp; &quot;.bmp&quot;
269 End Sub
272 Sub EnableStep2DialogControls(OnValue as Boolean)
273 With DialogModel
274 .hlnExtent.Enabled = OnValue
275 .optWholeDir.Enabled = OnValue
276 .optSingleFile.Enabled = OnValue
277 .chkProtect.Enabled = OnValue
278 .cmdCallSourceDialog.Enabled = OnValue
279 .cmdCallTargetDialog.Enabled = OnValue
280 .lblSource.Enabled = OnValue
281 .lblTarget.Enabled = OnValue
282 .txtSource.Enabled = OnValue
283 .txtTarget.Enabled = OnValue
284 .imgPreview.Enabled = OnValue
285 .lstCurrencies.Enabled = OnValue
286 .lblCurrencies.Enabled = OnValue
287 If OnValue Then
288 ToggleGoOnButton()
289 .chkRecursive.Enabled = .optWholeDir.State = 1
290 Else
291 .cmdGoOn.Enabled = False
292 .chkRecursive.Enabled = False
293 End If
294 End With
295 End Sub
298 Sub InitializeProgressPage()
299 DialogConvert.GetControl(&quot;lblRetrieval&quot;).Visible = False
300 DialogConvert.GetControl(&quot;lblCurProgress&quot;).Visible = False
301 DialogModel.lblRetrieval.FontWeight = com.sun.star.awt.FontWeight.NORMAL
302 DialogModel.lblCurProgress.FontWeight = com.sun.star.awt.FontWeight.BOLD
303 DialogConvert.GetControl(&quot;lblRetrieval&quot;).Visible = True
304 DialogConvert.GetControl(&quot;lblCurProgress&quot;).Visible = True
305 End Sub
308 Function AssignFileName(sPath as String, ByVal HeaderString, bCheckFileType as Boolean) as String
309 Dim bIsValid as Boolean
310 Dim sLocMimeType as String
311 Dim sNoDirMessage as String
312 HeaderString = DeleteStr(HeaderString, &quot;:&quot;)
313 sPath = ConvertToUrl(Trim(sPath))
314 bIsValid = oUcb.Exists(sPath)
315 If bIsValid Then
316 If DialogModel.optSingleFile.State = 1 Then
317 If bCheckFileType Then
318 sLocMimeType = GetRealFileContent(sPath)
319 If DialogModel.chkTextDocuments.State = 1 Then
320 If (Instr(1, sLocMimeType, &quot;text&quot;) = 0) And (Instr(1, sLocMimeType, &quot;calc&quot;) = 0) Then
321 Msgbox(sMsgFileInvalid, 48, sMsgDLGTITLE)
322 bIsValid = False
323 End If
324 Else
325 If (Instr(1, sLocMimeType, &quot;spreadsheet&quot;) = 0) And (Instr(1, sLocMimeType, &quot;calc&quot;)) = 0 Then
326 Msgbox(sMsgFileInvalid, 48, sMsgDLGTITLE)
327 bIsValid = False
328 End If
329 End If
330 End If
331 Else
332 If Not oUcb.IsFolder(sPath) Then
333 sNoDirMessage = ReplaceString(sMsgNODIRECTORY,sPath,&quot;&lt;1&gt;&quot;)
334 Msgbox(sNoDirMessage,48, sMsgDLGTITLE)
335 bIsValid = False
336 Else
337 sPath = RTrimStr(sPath,&quot;/&quot;)
338 sPath = sPath &amp; &quot;/&quot;
339 End If
340 End if
341 Else
342 Msgbox(HeaderString &amp; &quot; &apos;&quot; &amp; ConvertFromUrl(sPath) &amp; &quot;&apos; &quot; &amp; sMsgNOTTHERE,48, sMsgDLGTITLE)
343 End If
344 If bIsValid Then
345 AssignFileName() = sPath
346 Else
347 AssignFilename() = &quot;&quot;
348 End If
349 End Function
352 Sub ToggleGoOnButton()
353 Dim bDoEnable as Boolean
354 Dim sLocMimeType as String
355 Dim sPath as String
356 bDoEnable = Ubound(DialogModel.lstCurrencies.SelectedItems()) &gt; -1
357 If bDoEnable Then
358 &apos; Check if Source is set correctly
359 sPath = ConvertToUrl(Trim(DialogModel.txtSource.Text))
360 bDoEnable = oUcb.Exists(sPath)
361 End If
362 DialogModel.cmdGoOn.Enabled = bDoEnable
363 End Sub
366 Sub CallFolderPicker()
367 GetFolderName(DialogModel.txtTarget)
368 ToggleGoOnButton()
369 End Sub
372 Sub CallFilePicker()
373 If DialogModel.optSingleFile.State = 1 Then
374 Dim oMasterKey as Object
375 Dim oTypes() as Object
376 Dim oUIKey() as Object
378 oMasterKey = GetRegistryKeyContent(&quot;org.openoffice.TypeDetection.Types&quot;)
379 oTypes() = oMasterKey.Types
380 oUIKey = GetRegistryKeyContent(&quot;org.openoffice.Office.UI/FilterClassification/LocalFilters&quot;)
381 If DialogModel.chkTextDocuments.State = 1 Then
382 Dim FilterNames(7,1) as String
383 FilterNames(4,0) = oTypes.GetByName(&quot;writer_StarOffice_XML_Writer&quot;).UIName
384 FilterNames(4,1) = &quot;*.sxw&quot;
385 FilterNames(5,0) = oTypes.GetByName(&quot;writer_StarOffice_XML_Writer_Template&quot;).UIName
386 FilterNames(5,1) = &quot;*.stw&quot;
387 FilterNames(6,0) = oTypes.GetByName(&quot;writer8&quot;).UIName
388 FilterNames(6,1) = &quot;*.odt&quot;
389 FilterNames(7,0) = oTypes.GetByName(&quot;writer8_template&quot;).UIName
390 FilterNames(7,1) = &quot;*.ott&quot;
391 Else
392 ReDim FilterNames(3,1) as String
393 End If
394 FilterNames(0,0) = oTypes.GetByName(&quot;calc_StarOffice_XML_Calc&quot;).UIName
395 Filternames(0,1) = &quot;*.sxc&quot;
396 FilterNames(1,0) = oTypes.GetByName(&quot;calc_StarOffice_XML_Calc_Template&quot;).UIName
397 Filternames(1,1) = &quot;*.stc&quot;
398 FilterNames(2,0) = oTypes.GetByName(&quot;calc8&quot;).UIName
399 Filternames(2,1) = &quot;*.ods&quot;
400 FilterNames(3,0) = oTypes.GetByName(&quot;calc8_template&quot;).UIName
401 Filternames(3,1) = &quot;*.ots&quot;
402 GetFileName(DialogModel.txtSource, Filternames())
403 Else
404 GetFolderName(DialogModel.txtSource)
405 End If
406 ToggleGoOnButton()
407 End Sub
410 Sub PreviousStep()
411 DialogModel.Step = 2
412 DialogModel.cmdGoOn.Label = sGOON
413 DialogModel.cmdCancel.Label = sCANCEL
414 End Sub
415 </script:module>