1 <?xml version=
"1.0" encoding=
"UTF-8"?>
2 <!DOCTYPE script:module PUBLIC
"-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3 <script:module xmlns:
script=
"http://openoffice.org/2000/script" script:
name=
"AutoPilotRun" script:
language=
"StarBasic">Option Explicit
5 Public SourceDir as String
6 Public TargetDir as String
7 Public TargetStemDir as String
8 Public SourceFile as String
9 Public TargetFile as String
10 Public Source as String
11 Public SubstFile as String
12 Public SubstDir as String
14 Public FilterList(
9) as String
15 Public GoOn as Boolean
16 Public DoUnprotect as Integer
17 Public Password as String
18 Public DocIndex as Integer
19 Public oPathSettings as Object
21 Public TotDocCount as Integer
22 Public sTotDocCount as String
23 Public OpenProperties(
1) as New com.sun.star.beans.PropertyValue
28 Dim oFactoryKey as Object
29 BasicLibraries.LoadLibrary(
"Tools
")
30 BasicLibraries.LoadLibrary(
"ImportWizard
")
31 If InitResources(
"Euro Converter
",
"eur
") Then
32 oUcb = createUnoService(
"com.sun.star.ucb.SimpleFileAccess
")
33 oLocale = GetStarOfficeLocale()
34 InitializeConverter(oLocale,
2)
36 oFactoryKey = GetRegistryKeyContent(
"org.openoffice.Setup/Office/Factories
")
37 DialogModel.chkTextDocuments.Enabled = oFactoryKey.hasbyName(
"com.sun.star.text.TextDocument
")
38 DialogModel.cmdGoOn.DefaultButton = True
39 DialogModel.lstCurrencies.TabIndex =
12
40 DialogConvert.GetControl(
"optWholeDir
").SetFocus()
41 DialogConvert.Execute()
42 DialogConvert.Dispose()
47 Sub ConvertDocuments()
49 Dim bDisposable as Boolean
51 If Source
<> "" And TargetDir
<> "" Then
52 If DialogModel.optSingleFile.State =
1 Then
57 TargetStemDir = TargetDir
58 FilterList(
0) =
"application/x-starcalc
"
59 FilterList(
1) =
"application/vnd.stardivision.calc
"
60 FilterList(
2) =
"application/vnd.sun.xml.calc
"
61 FilterList(
3) =
"application/vnd.oasis.opendocument.spreadsheet
"
62 If DialogModel.chkTextDocuments.State =
1 Then
63 ReDim Preserve FilterList(
8) as String
65 FilterList(
4) =
"application/x-starwriter
"
66 FilterList(
5) =
"application/vnd.stardivision.writer
"
67 FilterList(
6) =
"application/vnd.stardivision.writer/web
"
68 FilterList(
7) =
"application/vnd.sun.xml.writer
"
69 FilterList(
8) =
"application/vnd.oasis.opendocument.text
"
71 FilesList() = ReadDirectories(SourceDir, bRecursive, True, False, FilterList())
72 TotDocCount = Ubound(FilesList(),
1) +
1
74 InitializeProgressPage(DialogModel)
75 ' ChangeToNextProgressStep()
76 sTotDocCount = CStr(TotDocCount)
77 OpenProperties(
0).Name =
"Hidden
"
78 OpenProperties(
0).Value = True
79 OpenProperties(
1).Name =
"AsTemplate
"
80 OpenProperties(
1).Value = False
81 For DocIndex =
0 To TotDocCount -
1
82 If InitializeDocument(FilesList(), bDisposable) Then
83 If StoreDocument() Then
92 DialogModel.cmdBack.Enabled = True
93 DialogModel.cmdGoOn.Enabled = True
94 DialogModel.cmdGoOn.Label = sReady
95 DialogModel.cmdCancel.Label = sEnd
100 Function InitializeDocument(FilesList(), bDisposable as Boolean) as Boolean
101 ' The Autopilot is started from step No.
2
102 Dim sViewPath as String
103 Dim bIsReadOnly as Boolean
104 Dim sExtension as String
105 On Local Error Goto NEXTFILE
106 If Not bCancelTask Then
107 If DialogModel.optWholeDir.State =
1 Then
108 SourceFile = FilesList(DocIndex,
0)
109 TargetFile = ReplaceString(SourceFile,TargetStemDir,SourceDir)
110 TargetDir = DirectorynameoutofPath(TargetFile,
"/
")
113 TargetFile = TargetDir
& "/
" & FileNameoutofPath(SourceFile,
"/
")
115 If CreateFolder(TargetDir) Then
116 sExtension = GetFileNameExtension(SourceFile,
"/
")
117 oDocument = OpenDocument(SourceFile, OpenProperties(), bDisposable)
118 If (oDocument.IsReadOnly) AND (UCase(SourceFile) = UCase(TargetFile)) Then
120 Msgbox(sMsgDOCISREADONLY,
16, GetProductName())
123 RetrieveDocumentObjects()
124 sViewPath = CutPathView(SourceFile,
60)
125 DialogModel.lblCurDocument.Label = Str(DocIndex+
1)
& "/
" & sTotDocCount
& " (
" & sViewPath
& ")
"
127 InitializeDocument() = Not bIsReadOnly
129 InitializeDocument() = False
132 InitializeDocument() = False
135 If Err
<> 0 Then
136 InitializeDocument() = False
143 Sub ChangeToNextProgressStep()
144 DialogModel.lblCurProgress.FontWeight = com.sun.star.awt.FontWeight.NORMAL
145 DialogConvert.GetControl(
"lblCurProgress
").Visible = True
149 Function StoreDocument() as Boolean
150 Dim sCurFileExists as String
151 Dim iOverWrite as Integer
152 If (TargetFile
<> "") And (Not bCancelTask) Then
153 On Local Error Goto NOSAVING
154 If oUcb.Exists(TargetFile) Then
155 sCurFileExists = ReplaceString(sMsgFileExists, ConvertFromUrl(TargetFile),
"<1>")
156 sCurFileExists = ReplaceString(sCurFileExists, chr(
13),
"<CR
>")
157 iOverWrite = Msgbox (sCurFileExists,
32 +
3, sMsgDLGTITLE)
158 Select Case iOverWrite
162 StoreDocument() = False
165 StoreDocument() = False
169 If TargetFile
<> SourceFile Then
170 oDocument.StoreAsUrl(TargetFile,NoArgs)
174 StoreDocument() = True
176 If Err
<> 0 Then
177 StoreDocument() = False
186 DialogModel.chkRecursive.Enabled = DialogModel.optWholeDir.State =
1
187 If DialogModel.optWholeDir.State =
1 Then
188 DialogModel.lblSource.Label = sSOURCEDIR
189 If Not IsNull(SubstFile) Then
190 SubstFile = DialogModel.txtSource.Text
191 DialogModel.txtSource.Text = SubstDir
194 DialogModel.LblSource.Label = sSOURCEFILE
195 If Not IsNull(SubstDir) Then
196 SubstDir = DialogModel.txtSource.Text
197 DialogModel.txtSource.Text = SubstFile
204 Function InitializeThirdStep() as Boolean
205 Dim TextBoxText as String
206 Source = AssignFileName(DialogModel.txtSource.Text, DialogModel.lblSource.Label, True)
207 If CheckTextBoxPath(DialogModel.txtTarget, True, True, sMsgDLGTITLE, True) Then
208 TargetDir = AssignFileName(DialogModel.txtTarget.Text, DialogModel.lblTarget.Label, False)
210 TargetDir =
""
212 If Source
<> "" And TargetDir
<> "" Then
213 bRecursive = DialogModel.chkRecursive.State =
1
214 bDoUnprotect = DialogModel.chkProtect.State =
1
215 DialogModel.lblRetrieval.FontWeight = com.sun.star.awt.FontWeight.BOLD
216 DialogModel.lblRetrieval.Label = sPrgsRETRIEVAL
217 DialogModel.lblCurProgress.Label = sPrgsCONVERTING
218 If DialogModel.optWholeDir.State =
1 Then
219 TextBoxText = sSOURCEDIR
& " " & ConvertFromUrl(Source)
& chr(
13)
220 If DialogModel.chkRecursive.State =
1 Then
221 TextBoxText = TextBoxText
& DeleteStr(sInclusiveSubDir,
"~
")
& chr(
13)
224 TextBoxText = sSOURCEFILE
& " " & ConvertFromUrl(Source)
& chr(
13)
226 TextBoxText = TextBoxText
& sTARGETDIR
& " " & ConvertFromUrl(TargetDir)
& chr(
13)
227 If DialogModel.chkProtect.State =
1 Then
228 TextBoxText = TextboxText
& sPrgsUNPROTECT
230 DialogModel.txtConfig.Text = TextBoxText
232 DialogModel.cmdGoOn.Enabled = False
233 InitializeThirdStep() = True
235 InitializeThirdStep() = False
240 Sub ToggleProgressStep(Optional aEvent as Object)
241 Dim bMakeVisible as Boolean
242 Dim LocStep as Integer
243 ' If the Sub is call by the
'cmdBack
' Button then set the
'bMakeVisible
' variable accordingly
244 bMakeVisible = IsMissing(aEvent)
250 DialogConvert.GetControl(
"lblCurrencies
").Visible = Not bMakeVisible
251 DialogConvert.GetControl(
"lstCurrencies
").Visible = Not bMakeVisible
252 DialogConvert.GetControl(
"cmdBack
").Visible = bMakeVisible
253 DialogConvert.GetControl(
"cmdGoOn
").Visible = bMakeVisible
254 DialogModel.imgPreview.ImageUrl = BitmapDir
& "euro_
" & DialogModel.Step
& ".bmp
"
258 Sub EnableStep2DialogControls(OnValue as Boolean)
260 .hlnExtent.Enabled = OnValue
261 .optWholeDir.Enabled = OnValue
262 .optSingleFile.Enabled = OnValue
263 .chkProtect.Enabled = OnValue
264 .cmdCallSourceDialog.Enabled = OnValue
265 .cmdCallTargetDialog.Enabled = OnValue
266 .lblSource.Enabled = OnValue
267 .lblTarget.Enabled = OnValue
268 .txtSource.Enabled = OnValue
269 .txtTarget.Enabled = OnValue
270 .imgPreview.Enabled = OnValue
271 .lstCurrencies.Enabled = OnValue
272 .lblCurrencies.Enabled = OnValue
275 .chkRecursive.Enabled = .optWholeDir.State =
1
277 .cmdGoOn.Enabled = False
278 .chkRecursive.Enabled = False
284 Sub InitializeProgressPage()
285 DialogConvert.GetControl(
"lblRetrieval
").Visible = False
286 DialogConvert.GetControl(
"lblCurProgress
").Visible = False
287 DialogModel.lblRetrieval.FontWeight = com.sun.star.awt.FontWeight.NORMAL
288 DialogModel.lblCurProgress.FontWeight = com.sun.star.awt.FontWeight.BOLD
289 DialogConvert.GetControl(
"lblRetrieval
").Visible = True
290 DialogConvert.GetControl(
"lblCurProgress
").Visible = True
294 Function AssignFileName(sPath as String, ByVal HeaderString, bCheckFileType as Boolean) as String
295 Dim bIsValid as Boolean
296 Dim sLocMimeType as String
297 Dim sNoDirMessage as String
298 HeaderString = DeleteStr(HeaderString,
":
")
299 sPath = ConvertToUrl(Trim(sPath))
300 bIsValid = oUcb.Exists(sPath)
302 If DialogModel.optSingleFile.State =
1 Then
303 If bCheckFileType Then
304 sLocMimeType = GetRealFileContent(sPath)
305 If DialogModel.chkTextDocuments.State =
1 Then
306 If (Instr(
1, sLocMimeType,
"text
") =
0) And (Instr(
1, sLocMimeType,
"calc
") =
0) Then
307 Msgbox(sMsgFileInvalid,
48, sMsgDLGTITLE)
311 If (Instr(
1, sLocMimeType,
"spreadsheet
") =
0) And (Instr(
1, sLocMimeType,
"calc
")) =
0 Then
312 Msgbox(sMsgFileInvalid,
48, sMsgDLGTITLE)
318 If Not oUcb.IsFolder(sPath) Then
319 sNoDirMessage = ReplaceString(sMsgNODIRECTORY,sPath,
"<1>")
320 Msgbox(sNoDirMessage,
48, sMsgDLGTITLE)
323 sPath = RTrimStr(sPath,
"/
")
324 sPath = sPath
& "/
"
328 Msgbox(HeaderString
& " '" & ConvertFromUrl(sPath)
& "' " & sMsgNOTTHERE,
48, sMsgDLGTITLE)
331 AssignFileName() = sPath
333 AssignFilename() =
""
338 Sub ToggleGoOnButton()
339 Dim bDoEnable as Boolean
340 Dim sLocMimeType as String
342 bDoEnable = Ubound(DialogModel.lstCurrencies.SelectedItems())
> -
1
344 ' Check if Source is set correctly
345 sPath = ConvertToUrl(Trim(DialogModel.txtSource.Text))
346 bDoEnable = oUcb.Exists(sPath)
348 DialogModel.cmdGoOn.Enabled = bDoEnable
352 Sub CallFolderPicker()
353 GetFolderName(DialogModel.txtTarget)
359 If DialogModel.optSingleFile.State =
1 Then
360 Dim oMasterKey as Object
361 Dim oTypes() as Object
362 Dim oUIKey() as Object
364 oMasterKey = GetRegistryKeyContent(
"org.openoffice.TypeDetection.Types
")
365 oTypes() = oMasterKey.Types
366 oUIKey = GetRegistryKeyContent(
"org.openoffice.Office.UI/FilterClassification/LocalFilters
")
367 If DialogModel.chkTextDocuments.State =
1 Then
368 Dim FilterNames(
11,
1) as String
369 FilterNames(
6,
0) = oTypes.GetByName(
"writer_StarOffice_XML_Writer
").UIName
370 FilterNames(
6,
1) =
"*.sxw
"
371 FilterNames(
7,
0) = oTypes.GetByName(
"writer_StarOffice_XML_Writer_Template
").UIName
372 FilterNames(
7,
1) =
"*.stw
"
373 FilterNames(
8,
0) = oUIKey.Classes.GetByName(
"sw3to5
").DisplayName
374 FilterNames(
8,
1) =
"*.sdw
"
375 FilterNames(
9,
0) = oUIKey.Classes.GetByName(
"sw3to5templ
").DisplayName
376 Filternames(
9,
1) =
"*.vor
"
377 FilterNames(
10,
0) = oTypes.GetByName(
"writer8
").UIName
378 FilterNames(
10,
1) =
"*.odt
"
379 FilterNames(
11,
0) = oTypes.GetByName(
"writer8_template
").UIName
380 FilterNames(
11,
1) =
"*.ott
"
382 ReDim FilterNames(
5,
1) as String
384 FilterNames(
0,
0) = oTypes.GetByName(
"calc_StarOffice_XML_Calc
").UIName
385 Filternames(
0,
1) =
"*.sxc
"
386 FilterNames(
1,
0) = oTypes.GetByName(
"calc_StarOffice_XML_Calc_Template
").UIName
387 Filternames(
1,
1) =
"*.stc
"
388 FilterNames(
2,
0) = oUIKey.Classes.GetByName(
"sc345
").DisplayName
389 FilterNames(
2,
1) =
"*.sdc
"
390 FilterNames(
3,
0) = oUIKey.Classes.GetByName(
"sc345templ
").DisplayName
391 Filternames(
3,
1) =
"*.vor
"
392 FilterNames(
4,
0) = oTypes.GetByName(
"calc8
").UIName
393 Filternames(
4,
1) =
"*.ods
"
394 FilterNames(
5,
0) = oTypes.GetByName(
"calc8_template
").UIName
395 Filternames(
5,
1) =
"*.ots
"
396 GetFileName(DialogModel.txtSource, Filternames())
398 GetFolderName(DialogModel.txtSource)
406 DialogModel.cmdGoOn.Label = sGOON
407 DialogModel.cmdCancel.Label = sCANCEL