home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / lib / openoffice / share / basic / Euro / AutoPilotRun.xba next >
Encoding:
Extensible Markup Language  |  2006-08-01  |  14.0 KB  |  411 lines

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