office-gobmx/wizards/source/euro/AutoPilotRun.xba

395 lines
13 KiB
Text
Raw Normal View History

2001-04-23 04:46:42 -05:00
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="AutoPilotRun" script:language="StarBasic">Option Explicit
2001-04-23 04:46:42 -05:00
Public SourceDir as String
Public TargetDir as String
Public TargetStemDir as String
Public SourceFile as String
Public TargetFile as String
Public Source as String
Public SubstFile as String
Public SubstDir as String
Public NoArgs()
Public FilterList(6) as String
2001-04-23 04:46:42 -05:00
Public GoOn as Boolean
Public DoUnprotect as Integer
Public Password as String
Public DocIndex as Integer
Public oPathSettings as Object
2001-04-23 04:46:42 -05:00
Public oDocInfo as Object
Public oUcb as Object
Public TotDocCount as Integer
Public sTotDocCount as String
Public OpenProperties(1) as New com.sun.star.beans.PropertyValue
2001-04-23 04:46:42 -05:00
Sub StartAutoPilot()
Dim i As Integer
2001-05-04 09:11:48 -05:00
BasicLibraries.LoadLibrary(&quot;Tools&quot;)
BasicLibraries.LoadLibrary(&quot;ImportWizard&quot;)
2001-04-23 04:46:42 -05:00
If InitResources(&quot;Euro Converter&quot;, &quot;eur&quot;) Then
oDocInfo = CreateUnoService(&quot;com.sun.star.document.DocumentProperties&quot;)
2001-04-23 04:46:42 -05:00
oUcb = createUnoService(&quot;com.sun.star.ucb.SimpleFileAccess&quot;)
oLocale = GetStarOfficeLocale()
InitializeConverter(oLocale, 2)
2001-05-04 09:11:48 -05:00
ToggleGoOnButton()
DialogModel.cmdGoOn.DefaultButton = True
DialogConvert.GetControl(&quot;optWholeDir&quot;).SetFocus()
DialogConvert.Execute()
2001-12-07 04:15:28 -06:00
DialogConvert.Dispose()
2001-04-23 04:46:42 -05:00
End If
End Sub
Sub ConvertDocuments()
2001-04-23 04:46:42 -05:00
Dim FilesList()
2001-11-19 09:24:29 -06:00
Dim bDisposable as Boolean
2001-04-23 04:46:42 -05:00
If Source &lt;&gt; &quot;&quot; And TargetDir &lt;&gt; &quot;&quot; Then
If DialogModel.optSingleFile.State = 1 Then
SourceFile = Source
TotDocCount = 1
Else
SourceDir = Source
TargetStemDir = TargetDir
2001-06-25 13:03:49 -05:00
FilterList(0) = &quot;application/x-starcalc&quot;
FilterList(1) = &quot;application/vnd.stardivision.calc&quot;
FilterList(2) = &quot;application/vnd.sun.xml.calc&quot;
If DialogModel.chkTextDocuments.State = 1 Then
ReDim Preserve FilterList(6) as String
FilterList(3) = &quot;application/x-starwriter&quot;
FilterList(4) = &quot;application/vnd.stardivision.writer&quot;
FilterList(5) = &quot;application/vnd.stardivision.writer/web&quot;
FilterList(6) = &quot;application/vnd.sun.xml.writer&quot;
End If
2001-04-23 04:46:42 -05:00
FilesList() = ReadDirectories(SourceDir, bRecursive, True, False, FilterList())
TotDocCount = Ubound(FilesList(),1) + 1
2001-04-23 04:46:42 -05:00
End If
InitializeProgressPage(DialogModel)
&apos; ChangeToNextProgressStep()
sTotDocCount = CStr(TotDocCount)
OpenProperties(0).Name = &quot;Hidden&quot;
2001-11-19 09:24:29 -06:00
OpenProperties(0).Value = True
OpenProperties(1).Name = &quot;AsTemplate&quot;
2001-11-19 09:24:29 -06:00
OpenProperties(1).Value = False
For DocIndex = 0 To TotDocCount - 1
2001-11-19 09:24:29 -06:00
If InitializeDocument(FilesList(), bDisposable) Then
2001-09-12 06:30:01 -05:00
If StoreDocument() Then
ConvertDocument()
oDocument.Store
End If
If bDisposable Then
oDocument.Dispose()
End If
2001-04-23 04:46:42 -05:00
End If
Next DocIndex
DialogModel.cmdBack.Enabled = True
DialogModel.cmdGoOn.Enabled = True
DialogModel.cmdGoOn.Label = sReady
2001-09-12 06:30:01 -05:00
DialogModel.cmdCancel.Label = sEnd
2001-04-23 04:46:42 -05:00
End If
End Sub
2001-11-19 09:24:29 -06:00
Function InitializeDocument(FilesList(), bDisposable as Boolean) as Boolean
2001-05-04 09:11:48 -05:00
&apos; The Autopilot is started from step No. 2
2001-04-23 04:46:42 -05:00
Dim sViewPath as String
2001-05-04 09:11:48 -05:00
Dim bIsReadOnly as Boolean
Dim sExtension as String
2001-05-04 09:11:48 -05:00
On Local Error Goto NEXTFILE
2001-09-12 06:30:01 -05:00
If Not bCancelTask Then
If DialogModel.optWholeDir.State = 1 Then
SourceFile = FilesList(DocIndex,0)
TargetFile = ReplaceString(SourceFile,TargetStemDir,SourceDir)
TargetDir = DirectorynameoutofPath(TargetFile, &quot;/&quot;)
Else
SourceFile = Source
TargetFile = TargetDir &amp; &quot;/&quot; &amp; FileNameoutofPath(SourceFile, &quot;/&quot;)
End If
If CreateFolder(TargetDir) Then
sExtension = GetFileNameExtension(SourceFile, &quot;/&quot;)
oDocument = OpenDocument(SourceFile, OpenProperties(), bDisposable)
If (oDocument.IsReadOnly) AND (UCase(SourceFile) = UCase(TargetFile)) Then
bIsReadOnly = True
Msgbox(sMsgDOCISREADONLY, 16, GetProductName())
Else
bIsReadOnly = False
RetrieveDocumentObjects()
sViewPath = CutPathView(SourceFile, 60)
DialogModel.lblCurDocument.Label = Str(DocIndex+1) &amp; &quot;/&quot; &amp; sTotDocCount &amp; &quot; (&quot; &amp; sViewPath &amp; &quot;)&quot;
End If
InitializeDocument() = Not bIsReadOnly
2001-09-12 06:30:01 -05:00
Else
InitializeDocument() = False
2001-09-12 06:30:01 -05:00
End If
2001-04-23 04:46:42 -05:00
Else
InitializeDocument() = False
2001-04-23 04:46:42 -05:00
End If
2001-05-04 09:11:48 -05:00
NEXTFILE:
If Err &lt;&gt; 0 Then
InitializeDocument() = False
Resume LETSGO
LETSGO:
End If
2001-04-23 04:46:42 -05:00
End Function
Sub ChangeToNextProgressStep()
2001-05-04 09:11:48 -05:00
DialogModel.lblCurProgress.FontWeight = com.sun.star.awt.FontWeight.NORMAL
DialogConvert.GetControl(&quot;lblCurProgress&quot;).Visible = True
2001-04-23 04:46:42 -05:00
End Sub
2001-09-12 06:30:01 -05:00
Function StoreDocument() as Boolean
Dim sCurFileExists as String
Dim iOverWrite as Integer
If (TargetFile &lt;&gt; &quot;&quot;) And (Not bCancelTask) Then
2001-04-23 04:46:42 -05:00
On Local Error Goto NOSAVING
2001-09-12 06:30:01 -05:00
If oUcb.Exists(TargetFile) Then
sCurFileExists = ReplaceString(sMsgFileExists, ConvertFromUrl(TargetFile), &quot;&lt;1&gt;&quot;)
sCurFileExists = ReplaceString(sCurFileExists, chr(13), &quot;&lt;CR&gt;&quot;)
iOverWrite = Msgbox (sCurFileExists, 32 + 3, sMsgDLGTITLE)
Select Case iOverWrite
Case 1 &apos; OK
Case 2 &apos; Abort
bCancelTask = True
StoreDocument() = False
Exit Function
Case 7 &apos; No
StoreDocument() = False
Exit Function
End Select
End If
2001-04-23 04:46:42 -05:00
If TargetFile &lt;&gt; SourceFile Then
2001-09-12 06:30:01 -05:00
oDocument.StoreAsUrl(TargetFile,NoArgs)
2001-04-23 04:46:42 -05:00
Else
oDocument.Store
End If
StoreDocument() = True
NOSAVING:
If Err &lt;&gt; 0 Then
StoreDocument() = False
Resume CLERROR
End If
CLERROR:
End If
End Function
Sub SwapExtent()
DialogModel.chkRecursive.Enabled = DialogModel.optWholeDir.State = 1
If DialogModel.optWholeDir.State = 1 Then
DialogModel.lblSource.Label = sSOURCEDIR &apos;&quot;Quellverzeichnis:&quot;
If Not IsNull(SubstFile) Then
SubstFile = DialogModel.txtSource.Text
DialogModel.txtSource.Text = SubstDir
2001-04-23 04:46:42 -05:00
End If
Else
DialogModel.LblSource.Label = sSOURCEFILE &apos;&quot;Quelldatei:&quot;
If Not IsNull(SubstDir) Then
SubstDir = DialogModel.txtSource.Text
DialogModel.txtSource.Text = SubstFile
2001-04-23 04:46:42 -05:00
End If
End If
2001-05-04 09:11:48 -05:00
ToggleGoOnButton()
2001-04-23 04:46:42 -05:00
End Sub
Function InitializeThirdStep() as Boolean
2001-04-23 04:46:42 -05:00
Dim TextBoxText as String
2001-06-25 13:03:49 -05:00
Source = AssignFileName(DialogModel.txtSource.Text, DialogModel.lblSource.Label, True)
If CheckTextBoxPath(DialogModel.txtTarget, True, True, sMsgDLGTITLE, True) Then
TargetDir = AssignFileName(DialogModel.txtTarget.Text, DialogModel.lblTarget.Label, False)
Else
TargetDir = &quot;&quot;
End If
If Source &lt;&gt; &quot;&quot; And TargetDir &lt;&gt; &quot;&quot; Then
bRecursive = DialogModel.chkRecursive.State = 1
bDoUnprotect = DialogModel.chkProtect.State = 1
DialogModel.lblRetrieval.FontWeight = com.sun.star.awt.FontWeight.BOLD
DialogModel.lblRetrieval.Label = sPrgsRETRIEVAL
DialogModel.lblCurProgress.Label = sPrgsCONVERTING
If DialogModel.optWholeDir.State = 1 Then
2001-09-12 06:30:01 -05:00
TextBoxText = sSOURCEDIR &amp; &quot; &quot; &amp; ConvertFromUrl(Source) &amp; chr(13) &apos;&amp; &quot; &quot;
If DialogModel.chkRecursive.State = 1 Then
TextBoxText = TextBoxText &amp; DeleteStr(sInclusiveSubDir,&quot;~&quot;) &amp; chr(13)
End If
Else
2001-09-12 06:30:01 -05:00
TextBoxText = sSOURCEFILE &amp; &quot; &quot; &amp; ConvertFromUrl(Source) &amp; chr(13)
2001-04-23 04:46:42 -05:00
End If
2001-09-12 06:30:01 -05:00
TextBoxText = TextBoxText &amp; sTARGETDIR &amp; &quot; &quot; &amp; ConvertFromUrl(TargetDir) &amp; chr(13)
If DialogModel.chkProtect.State = 1 Then
TextBoxText = TextboxText &amp; sPrgsUNPROTECT
End If
DialogModel.txtConfig.Text = TextBoxText
ToggleProgressStep()
DialogModel.cmdGoOn.Enabled = False
InitializeThirdStep() = True
Else
InitializeThirdStep() = False
End If
End Function
2001-04-23 04:46:42 -05:00
2001-05-04 09:11:48 -05:00
Sub ToggleProgressStep(Optional aEvent as Object)
Dim bMakeVisible as Boolean
Dim LocStep as Integer
2001-06-25 13:03:49 -05:00
&apos; If the Sub is call by the &apos;cmdBack&apos; Button then set the &apos;bMakeVisible&apos; variable accordingly
2001-05-04 09:11:48 -05:00
bMakeVisible = IsMissing(aEvent)
If bMakeVisible Then
DialogModel.Step = 3
2001-05-04 09:11:48 -05:00
Else
DialogModel.Step = 2
End If
DialogConvert.GetControl(&quot;lblCurrencies&quot;).Visible = Not bMakeVisible
DialogConvert.GetControl(&quot;lstCurrencies&quot;).Visible = Not bMakeVisible
DialogConvert.GetControl(&quot;cmdBack&quot;).Visible = bMakeVisible
DialogConvert.GetControl(&quot;cmdGoOn&quot;).Visible = bMakeVisible
2001-05-04 09:11:48 -05:00
DialogModel.imgPreview.ImageUrl = BitmapDir &amp; &quot;euro_&quot; &amp; DialogModel.Step &amp; &quot;.bmp&quot;
2001-04-23 04:46:42 -05:00
End Sub
Sub EnableStep2DialogControls(OnValue as Boolean)
With DialogModel
.hlnExtent.Enabled = OnValue
.optWholeDir.Enabled = OnValue
.optSingleFile.Enabled = OnValue
.chkProtect.Enabled = OnValue
.cmdCallSourceDialog.Enabled = OnValue
.cmdCallTargetDialog.Enabled = OnValue
.lblSource.Enabled = OnValue
.lblTarget.Enabled = OnValue
.txtSource.Enabled = OnValue
.txtTarget.Enabled = OnValue
.imgPreview.Enabled = OnValue
.lstCurrencies.Enabled = OnValue
.lblCurrencies.Enabled = OnValue
If OnValue Then
ToggleGoOnButton()
.chkRecursive.Enabled = .optWholeDir.State = 1
Else
.cmdGoOn.Enabled = False
.chkRecursive.Enabled = False
End If
End With
2001-04-23 04:46:42 -05:00
End Sub
Sub InitializeProgressPage()
2001-05-04 09:11:48 -05:00
DialogConvert.GetControl(&quot;lblRetrieval&quot;).Visible = False
DialogConvert.GetControl(&quot;lblCurProgress&quot;).Visible = False
DialogModel.lblRetrieval.FontWeight = com.sun.star.awt.FontWeight.NORMAL
DialogModel.lblCurProgress.FontWeight = com.sun.star.awt.FontWeight.BOLD
DialogConvert.GetControl(&quot;lblRetrieval&quot;).Visible = True
DialogConvert.GetControl(&quot;lblCurProgress&quot;).Visible = True
End Sub
Function AssignFileName(sPath as String, ByVal HeaderString, bCheckFileType as Boolean) as String
Dim bIsValid as Boolean
Dim sLocMimeType as String
Dim sNoDirMessage as String
HeaderString = DeleteStr(HeaderString, &quot;:&quot;)
sPath = ConvertToUrl(Trim(sPath))
bIsValid = oUcb.Exists(sPath)
If bIsValid Then
If DialogModel.optSingleFile.State = 1 Then
If bCheckFileType Then
sLocMimeType = GetRealFileContent(oDocInfo, sPath)
If DialogModel.chkTextDocuments.State = 1 Then
If (Instr(1, sLocMimeType, &quot;writer&quot;) = 0) And (Instr(1, sLocMimeType, &quot;calc&quot;) = 0) Then
Msgbox(sMsgFileInvalid, 48, sMsgDLGTITLE)
bIsValid = False
End If
Else
If Instr(1, sLocMimeType, &quot;calc&quot;) = 0 Then
Msgbox(sMsgFileInvalid, 48, sMsgDLGTITLE)
bIsValid = False
End If
2001-05-04 09:11:48 -05:00
End If
End If
Else
If Not oUcb.IsFolder(sPath) Then
sNoDirMessage = ReplaceString(sMsgNODIRECTORY,sPath,&quot;&lt;1&gt;&quot;)
Msgbox(sNoDirMessage,48, sMsgDLGTITLE)
bIsValid = False
Else
sPath = RTrimStr(sPath,&quot;/&quot;)
sPath = sPath &amp; &quot;/&quot;
End If
End if
Else
Msgbox(HeaderString &amp; &quot; &apos;&quot; &amp; ConvertFromUrl(sPath) &amp; &quot;&apos; &quot; &amp; sMsgNOTTHERE,48, sMsgDLGTITLE)
End If
If bIsValid Then
AssignFileName() = sPath
Else
AssignFilename() = &quot;&quot;
End If
End Function
Sub ToggleGoOnButton()
Dim bDoEnable as Boolean
Dim sLocMimeType as String
Dim sPath as String
bDoEnable = Ubound(DialogModel.lstCurrencies.SelectedItems()) &gt; -1
If bDoEnable Then
&apos; Check if Source is set correctly
sPath = ConvertToUrl(Trim(DialogModel.txtSource.Text))
bDoEnable = oUcb.Exists(sPath)
End If
DialogModel.cmdGoOn.Enabled = bDoEnable
End Sub
Sub CallFolderPicker()
GetFolderName(DialogModel.txtTarget)
2001-09-12 06:30:01 -05:00
ToggleGoOnButton()
End Sub
Sub CallFilePicker()
If DialogModel.optSingleFile.State = 1 Then
2001-06-25 13:03:49 -05:00
Dim oMasterKey as Object
2001-11-19 09:24:29 -06:00
Dim oTypes() as Object
Dim oUIKey() as Object
2001-06-25 13:03:49 -05:00
oMasterKey = GetRegistryKeyContent(&quot;org.openoffice.Office.TypeDetection/&quot;)
2001-11-19 09:24:29 -06:00
oTypes() = oMasterKey.Types
oUIKey = GetRegistryKeyContent(&quot;org.openoffice.Office.UI/FilterClassification/LocalFilters&quot;)
2001-06-25 13:03:49 -05:00
If DialogModel.chkTextDocuments.State = 1 Then
2001-11-19 09:24:29 -06:00
Dim FilterNames(7,1) as String
FilterNames(4,0) = oTypes.GetByName(&quot;writer_StarOffice_XML_Writer&quot;).UIName
FilterNames(4,1) = &quot;*.sxw&quot;
FilterNames(5,0) = oTypes.GetByName(&quot;writer_StarOffice_XML_Writer_Template&quot;).UIName
FilterNames(5,1) = &quot;*.stw&quot;
FilterNames(6,0) = oUIKey.Classes.GetByName(&quot;sw3to5&quot;).DisplayName
FilterNames(6,1) = &quot;*.sdw&quot;
FilterNames(7,0) = oUIKey.Classes.GetByName(&quot;sw3to5templ&quot;).DisplayName
Filternames(7,1) = &quot;*.vor&quot;
2001-06-25 13:03:49 -05:00
Else
2001-11-19 09:24:29 -06:00
ReDim FilterNames(3,1) as String
2001-06-25 13:03:49 -05:00
End If
2001-11-19 09:24:29 -06:00
FilterNames(0,0) = oTypes.GetByName(&quot;calc_StarOffice_XML_Calc&quot;).UIName
2001-06-25 13:03:49 -05:00
Filternames(0,1) = &quot;*.sxc&quot;
2001-11-19 09:24:29 -06:00
FilterNames(1,0) = oTypes.GetByName(&quot;calc_StarOffice_XML_Calc_Template&quot;).UIName
Filternames(1,1) = &quot;*.stc&quot;
FilterNames(2,0) = oUIKey.Classes.GetByName(&quot;sc345&quot;).DisplayName
FilterNames(2,1) = &quot;*.sdc&quot;
FilterNames(3,0) = oUIKey.Classes.GetByName(&quot;sc345templ&quot;).DisplayName
Filternames(3,1) = &quot;*.vor&quot;
GetFileName(DialogModel.txtSource, Filternames())
Else
GetFolderName(DialogModel.txtSource)
End If
2001-09-12 06:30:01 -05:00
ToggleGoOnButton()
End Sub
Sub PreviousStep()
DialogModel.Step = 2
DialogModel.cmdGoOn.Label = sGOON
DialogModel.cmdCancel.Label = sCANCEL
2001-05-04 09:11:48 -05:00
End Sub</script:module>