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