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