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 FilterList(9) 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 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 64 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" 70 End If 71 FilesList() = ReadDirectories(SourceDir, bRecursive, True, False, FilterList()) 72 TotDocCount = Ubound(FilesList(),1) + 1 73 End If 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 84 ConvertDocument() 85 oDocument.Store 86 End If 87 If bDisposable Then 88 oDocument.Dispose() 89 End If 90 End If 91 Next DocIndex 92 DialogModel.cmdBack.Enabled = True 93 DialogModel.cmdGoOn.Enabled = True 94 DialogModel.cmdGoOn.Label = sReady 95 DialogModel.cmdCancel.Label = sEnd 96 End If 97End Sub 98 99 100Function InitializeDocument(FilesList(), bDisposable as Boolean) as Boolean 101' The Autopilot is started from step No. 2 102Dim sViewPath as String 103Dim bIsReadOnly as Boolean 104Dim 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, "/") 111 Else 112 SourceFile = Source 113 TargetFile = TargetDir & "/" & FileNameoutofPath(SourceFile, "/") 114 End If 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 119 bIsReadOnly = True 120 Msgbox(sMsgDOCISREADONLY, 16, GetProductName()) 121 Else 122 bIsReadOnly = False 123 RetrieveDocumentObjects() 124 sViewPath = CutPathView(SourceFile, 60) 125 DialogModel.lblCurDocument.Label = Str(DocIndex+1) & "/" & sTotDocCount & " (" & sViewPath & ")" 126 End If 127 InitializeDocument() = Not bIsReadOnly 128 Else 129 InitializeDocument() = False 130 End If 131 Else 132 InitializeDocument() = False 133 End If 134NEXTFILE: 135 If Err <> 0 Then 136 InitializeDocument() = False 137 Resume LETSGO 138LETSGO: 139 End If 140End Function 141 142 143Sub ChangeToNextProgressStep() 144 DialogModel.lblCurProgress.FontWeight = com.sun.star.awt.FontWeight.NORMAL 145 DialogConvert.GetControl("lblCurProgress").Visible = True 146End Sub 147 148 149Function StoreDocument() as Boolean 150Dim sCurFileExists as String 151Dim 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 159 Case 1 ' OK 160 Case 2 ' Abort 161 bCancelTask = True 162 StoreDocument() = False 163 Exit Function 164 Case 7 ' No 165 StoreDocument() = False 166 Exit Function 167 End Select 168 End If 169 If TargetFile <> SourceFile Then 170 oDocument.StoreAsUrl(TargetFile,NoArgs) 171 Else 172 oDocument.Store 173 End If 174 StoreDocument() = True 175 NOSAVING: 176 If Err <> 0 Then 177 StoreDocument() = False 178 Resume CLERROR 179 End If 180 CLERROR: 181 End If 182End Function 183 184 185Sub SwapExtent() 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 192 End If 193 Else 194 DialogModel.LblSource.Label = sSOURCEFILE 195 If Not IsNull(SubstDir) Then 196 SubstDir = DialogModel.txtSource.Text 197 DialogModel.txtSource.Text = SubstFile 198 End If 199 End If 200 ToggleGoOnButton() 201End Sub 202 203 204Function InitializeThirdStep() as Boolean 205Dim 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) 209 Else 210 TargetDir = "" 211 End If 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) 222 End If 223 Else 224 TextBoxText = sSOURCEFILE & " " & ConvertFromUrl(Source) & chr(13) 225 End If 226 TextBoxText = TextBoxText & sTARGETDIR & " " & ConvertFromUrl(TargetDir) & chr(13) 227 If DialogModel.chkProtect.State = 1 Then 228 TextBoxText = TextboxText & sPrgsUNPROTECT 229 End If 230 DialogModel.txtConfig.Text = TextBoxText 231 ToggleProgressStep() 232 DialogModel.cmdGoOn.Enabled = False 233 InitializeThirdStep() = True 234 Else 235 InitializeThirdStep() = False 236 End If 237End Function 238 239 240Sub ToggleProgressStep(Optional aEvent as Object) 241Dim bMakeVisible as Boolean 242Dim LocStep as Integer 243 ' If the Sub is call by the 'cmdBack' Button then set the 'bMakeVisible' variable accordingly 244 bMakeVisible = IsMissing(aEvent) 245 If bMakeVisible Then 246 DialogModel.Step = 3 247 Else 248 DialogModel.Step = 2 249 End If 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" 255End Sub 256 257 258Sub EnableStep2DialogControls(OnValue as Boolean) 259 With DialogModel 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 273 If OnValue Then 274 ToggleGoOnButton() 275 .chkRecursive.Enabled = .optWholeDir.State = 1 276 Else 277 .cmdGoOn.Enabled = False 278 .chkRecursive.Enabled = False 279 End If 280 End With 281End Sub 282 283 284Sub 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 291End Sub 292 293 294Function AssignFileName(sPath as String, ByVal HeaderString, bCheckFileType as Boolean) as String 295Dim bIsValid as Boolean 296Dim sLocMimeType as String 297Dim sNoDirMessage as String 298 HeaderString = DeleteStr(HeaderString, ":") 299 sPath = ConvertToUrl(Trim(sPath)) 300 bIsValid = oUcb.Exists(sPath) 301 If bIsValid Then 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) 308 bIsValid = False 309 End If 310 Else 311 If (Instr(1, sLocMimeType, "spreadsheet") = 0) And (Instr(1, sLocMimeType, "calc")) = 0 Then 312 Msgbox(sMsgFileInvalid, 48, sMsgDLGTITLE) 313 bIsValid = False 314 End If 315 End If 316 End If 317 Else 318 If Not oUcb.IsFolder(sPath) Then 319 sNoDirMessage = ReplaceString(sMsgNODIRECTORY,sPath,"<1>") 320 Msgbox(sNoDirMessage,48, sMsgDLGTITLE) 321 bIsValid = False 322 Else 323 sPath = RTrimStr(sPath,"/") 324 sPath = sPath & "/" 325 End If 326 End if 327 Else 328 Msgbox(HeaderString & " '" & ConvertFromUrl(sPath) & "' " & sMsgNOTTHERE,48, sMsgDLGTITLE) 329 End If 330 If bIsValid Then 331 AssignFileName() = sPath 332 Else 333 AssignFilename() = "" 334 End If 335End Function 336 337 338Sub ToggleGoOnButton() 339Dim bDoEnable as Boolean 340Dim sLocMimeType as String 341Dim sPath as String 342 bDoEnable = Ubound(DialogModel.lstCurrencies.SelectedItems()) > -1 343 If bDoEnable Then 344 ' Check if Source is set correctly 345 sPath = ConvertToUrl(Trim(DialogModel.txtSource.Text)) 346 bDoEnable = oUcb.Exists(sPath) 347 End If 348 DialogModel.cmdGoOn.Enabled = bDoEnable 349End Sub 350 351 352Sub CallFolderPicker() 353 GetFolderName(DialogModel.txtTarget) 354 ToggleGoOnButton() 355End Sub 356 357 358Sub CallFilePicker() 359 If DialogModel.optSingleFile.State = 1 Then 360 Dim oMasterKey as Object 361 Dim oTypes() as Object 362 Dim oUIKey() as Object 363 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" 381 Else 382 ReDim FilterNames(5,1) as String 383 End If 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()) 397 Else 398 GetFolderName(DialogModel.txtSource) 399 End If 400 ToggleGoOnButton() 401End Sub 402 403 404Sub PreviousStep() 405 DialogModel.Step = 2 406 DialogModel.cmdGoOn.Label = sGOON 407 DialogModel.cmdCancel.Label = sCANCEL 408End Sub 409</script:module> 410