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