1 <?xml version=
"1.0" encoding=
"UTF-8"?>
2 <!DOCTYPE script:module PUBLIC
"-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
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 .
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
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
38 Public TotDocCount as Integer
39 Public sTotDocCount as String
40 Public OpenProperties(
1) as New com.sun.star.beans.PropertyValue
45 Dim oFactoryKey as Object
46 BasicLibraries.LoadLibrary(
"Tools
")
47 BasicLibraries.LoadLibrary(
"ImportWizard
")
48 If InitResources(
"Euro Converter
",
"eur
") Then
49 oUcb = createUnoService(
"com.sun.star.ucb.SimpleFileAccess
")
50 oLocale = GetStarOfficeLocale()
51 InitializeConverter(oLocale,
2)
53 oFactoryKey = GetRegistryKeyContent(
"org.openoffice.Setup/Office/Factories
")
54 DialogModel.chkTextDocuments.Enabled = oFactoryKey.hasbyName(
"com.sun.star.text.TextDocument
")
55 DialogModel.cmdGoOn.DefaultButton = True
56 DialogModel.lstCurrencies.TabIndex =
12
57 DialogConvert.GetControl(
"optWholeDir
").SetFocus()
58 DialogConvert.Execute()
59 DialogConvert.Dispose()
64 Sub ConvertDocuments()
66 Dim bDisposable as Boolean
68 If Source
<> "" And TargetDir
<> "" Then
69 If DialogModel.optSingleFile.State =
1 Then
74 TargetStemDir = TargetDir
75 TypeList(
0) =
"calc8
"
76 TypeList(
1) =
"calc_StarOffice_XML_Calc
"
77 If DialogModel.chkTextDocuments.State =
1 Then
78 ReDim Preserve TypeList(
5) as String
80 TypeList(
2) =
"writer8
"
81 TypeList(
3) =
"writerglobal8
"
82 TypeList(
4) =
"writer_StarOffice_XML_Writer
"
83 TypeList(
5) =
"writer_globaldocument_StarOffice_XML_Writer_GlobalDocument
"
85 FilesList() = ReadDirectories(SourceDir, bRecursive, True, False, TypeList())
86 TotDocCount = Ubound(FilesList(),
1) +
1
88 InitializeProgressPage(DialogModel)
89 ' ChangeToNextProgressStep()
90 sTotDocCount = CStr(TotDocCount)
91 OpenProperties(
0).Name =
"Hidden
"
92 OpenProperties(
0).Value = True
93 OpenProperties(
1).Name =
"AsTemplate
"
94 OpenProperties(
1).Value = False
95 For DocIndex =
0 To TotDocCount -
1
96 If InitializeDocument(FilesList(), bDisposable) Then
97 If StoreDocument() Then
106 DialogModel.cmdBack.Enabled = True
107 DialogModel.cmdGoOn.Enabled = True
108 DialogModel.cmdGoOn.Label = sReady
109 DialogModel.cmdCancel.Label = sEnd
114 Function InitializeDocument(FilesList(), bDisposable as Boolean) as Boolean
115 ' 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,
"/
")
127 TargetFile = TargetDir
& "/
" & FileNameoutofPath(SourceFile,
"/
")
129 If CreateFolder(TargetDir) Then
130 sExtension = GetFileNameExtension(SourceFile,
"/
")
131 oDocument = OpenDocument(SourceFile, OpenProperties(), bDisposable)
132 If (oDocument.IsReadOnly) AND (UCase(SourceFile) = UCase(TargetFile)) Then
134 Msgbox(sMsgDOCISREADONLY,
16, GetProductName())
137 RetrieveDocumentObjects()
138 sViewPath = CutPathView(SourceFile,
60)
139 DialogModel.lblCurDocument.Label = Str(DocIndex+
1)
& "/
" & sTotDocCount
& " (
" & sViewPath
& ")
"
141 InitializeDocument() = Not bIsReadOnly
143 InitializeDocument() = False
146 InitializeDocument() = False
149 If Err
<> 0 Then
150 InitializeDocument() = False
157 Sub ChangeToNextProgressStep()
158 DialogModel.lblCurProgress.FontWeight = com.sun.star.awt.FontWeight.NORMAL
159 DialogConvert.GetControl(
"lblCurProgress
").Visible = True
163 Function StoreDocument() as Boolean
164 Dim sCurFileExists as String
165 Dim iOverWrite as Integer
166 If (TargetFile
<> "") And (Not bCancelTask) Then
167 On Local Error Goto NOSAVING
168 If oUcb.Exists(TargetFile) Then
169 sCurFileExists = ReplaceString(sMsgFileExists, ConvertFromUrl(TargetFile),
"<1>")
170 sCurFileExists = ReplaceString(sCurFileExists, chr(
13),
"<CR
>")
171 iOverWrite = Msgbox (sCurFileExists,
32 +
3, sMsgDLGTITLE)
172 Select Case iOverWrite
176 StoreDocument() = False
179 StoreDocument() = False
183 If TargetFile
<> SourceFile Then
184 oDocument.StoreAsUrl(TargetFile,NoArgs)
188 StoreDocument() = True
190 If Err
<> 0 Then
191 StoreDocument() = False
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
208 DialogModel.LblSource.Label = sSOURCEFILE
209 If Not IsNull(SubstDir) Then
210 SubstDir = DialogModel.txtSource.Text
211 DialogModel.txtSource.Text = SubstFile
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)
224 TargetDir =
""
226 If Source
<> "" And TargetDir
<> "" 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
& " " & ConvertFromUrl(Source)
& chr(
13)
234 If DialogModel.chkRecursive.State =
1 Then
235 TextBoxText = TextBoxText
& DeleteStr(sInclusiveSubDir,
"~
")
& chr(
13)
238 TextBoxText = sSOURCEFILE
& " " & ConvertFromUrl(Source)
& chr(
13)
240 TextBoxText = TextBoxText
& sTARGETDIR
& " " & ConvertFromUrl(TargetDir)
& chr(
13)
241 If DialogModel.chkProtect.State =
1 Then
242 TextBoxText = TextboxText
& sPrgsUNPROTECT
244 DialogModel.txtConfig.Text = TextBoxText
246 DialogModel.cmdGoOn.Enabled = False
247 InitializeThirdStep() = True
249 InitializeThirdStep() = False
254 Sub ToggleProgressStep(Optional aEvent as Object)
255 Dim bMakeVisible as Boolean
256 Dim LocStep as Integer
257 ' If the Sub is call by the
'cmdBack
' Button then set the
'bMakeVisible
' variable accordingly
258 bMakeVisible = IsMissing(aEvent)
264 DialogConvert.GetControl(
"lblCurrencies
").Visible = Not bMakeVisible
265 DialogConvert.GetControl(
"lstCurrencies
").Visible = Not bMakeVisible
266 DialogConvert.GetControl(
"cmdBack
").Visible = bMakeVisible
267 DialogConvert.GetControl(
"cmdGoOn
").Visible = bMakeVisible
268 DialogModel.imgPreview.ImageUrl = BitmapDir
& "euro_
" & DialogModel.Step
& ".bmp
"
272 Sub EnableStep2DialogControls(OnValue as Boolean)
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
289 .chkRecursive.Enabled = .optWholeDir.State =
1
291 .cmdGoOn.Enabled = False
292 .chkRecursive.Enabled = False
298 Sub InitializeProgressPage()
299 DialogConvert.GetControl(
"lblRetrieval
").Visible = False
300 DialogConvert.GetControl(
"lblCurProgress
").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(
"lblRetrieval
").Visible = True
304 DialogConvert.GetControl(
"lblCurProgress
").Visible = True
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,
":
")
313 sPath = ConvertToUrl(Trim(sPath))
314 bIsValid = oUcb.Exists(sPath)
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,
"text
") =
0) And (Instr(
1, sLocMimeType,
"calc
") =
0) Then
321 Msgbox(sMsgFileInvalid,
48, sMsgDLGTITLE)
325 If (Instr(
1, sLocMimeType,
"spreadsheet
") =
0) And (Instr(
1, sLocMimeType,
"calc
")) =
0 Then
326 Msgbox(sMsgFileInvalid,
48, sMsgDLGTITLE)
332 If Not oUcb.IsFolder(sPath) Then
333 sNoDirMessage = ReplaceString(sMsgNODIRECTORY,sPath,
"<1>")
334 Msgbox(sNoDirMessage,
48, sMsgDLGTITLE)
337 sPath = RTrimStr(sPath,
"/
")
338 sPath = sPath
& "/
"
342 Msgbox(HeaderString
& " '" & ConvertFromUrl(sPath)
& "' " & sMsgNOTTHERE,
48, sMsgDLGTITLE)
345 AssignFileName() = sPath
347 AssignFilename() =
""
352 Sub ToggleGoOnButton()
353 Dim bDoEnable as Boolean
354 Dim sLocMimeType as String
356 bDoEnable = Ubound(DialogModel.lstCurrencies.SelectedItems())
> -
1
358 ' Check if Source is set correctly
359 sPath = ConvertToUrl(Trim(DialogModel.txtSource.Text))
360 bDoEnable = oUcb.Exists(sPath)
362 DialogModel.cmdGoOn.Enabled = bDoEnable
366 Sub CallFolderPicker()
367 GetFolderName(DialogModel.txtTarget)
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(
"org.openoffice.TypeDetection.Types
")
379 oTypes() = oMasterKey.Types
380 oUIKey = GetRegistryKeyContent(
"org.openoffice.Office.UI/FilterClassification/LocalFilters
")
381 If DialogModel.chkTextDocuments.State =
1 Then
382 Dim FilterNames(
7,
1) as String
383 FilterNames(
4,
0) = oTypes.GetByName(
"writer_StarOffice_XML_Writer
").UIName
384 FilterNames(
4,
1) =
"*.sxw
"
385 FilterNames(
5,
0) = oTypes.GetByName(
"writer_StarOffice_XML_Writer_Template
").UIName
386 FilterNames(
5,
1) =
"*.stw
"
387 FilterNames(
6,
0) = oTypes.GetByName(
"writer8
").UIName
388 FilterNames(
6,
1) =
"*.odt
"
389 FilterNames(
7,
0) = oTypes.GetByName(
"writer8_template
").UIName
390 FilterNames(
7,
1) =
"*.ott
"
392 ReDim FilterNames(
3,
1) as String
394 FilterNames(
0,
0) = oTypes.GetByName(
"calc_StarOffice_XML_Calc
").UIName
395 Filternames(
0,
1) =
"*.sxc
"
396 FilterNames(
1,
0) = oTypes.GetByName(
"calc_StarOffice_XML_Calc_Template
").UIName
397 Filternames(
1,
1) =
"*.stc
"
398 FilterNames(
2,
0) = oTypes.GetByName(
"calc8
").UIName
399 Filternames(
2,
1) =
"*.ods
"
400 FilterNames(
3,
0) = oTypes.GetByName(
"calc8_template
").UIName
401 Filternames(
3,
1) =
"*.ots
"
402 GetFileName(DialogModel.txtSource, Filternames())
404 GetFolderName(DialogModel.txtSource)
412 DialogModel.cmdGoOn.Label = sGOON
413 DialogModel.cmdCancel.Label = sCANCEL