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