1 <?xml version=
"1.0" encoding=
"UTF-8"?>
2 <!DOCTYPE script:module PUBLIC
"-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
4 * This file is part of the LibreOffice project.
6 * This Source Code Form is subject to the terms of the Mozilla Public
7 * License, v. 2.0. If a copy of the MPL was not distributed with this
8 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 * This file incorporates work covered by the following license notice:
12 * Licensed to the Apache Software Foundation (ASF) under one or more
13 * contributor license agreements. See the NOTICE file distributed
14 * with this work for additional information regarding copyright
15 * ownership. The ASF licenses this file to you under the Apache
16 * License, Version 2.0 (the "License"); you may not use this file
17 * except in compliance with the License. You may obtain a copy of
18 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 <script:module xmlns:
script=
"http://openoffice.org/2000/script" script:
name=
"DialogModul" script:
language=
"StarBasic">Option Explicit
22 Public Const bDebugWizard = True
24 Public Const SBFIRSTAPPLCHECKED =
0
25 Public Const SBSECONDAPPLCHECKED =
1
26 Public Const SBTHIRDAPPLCHECKED =
2
27 Public Const SBFOURTHAPPLCHECKED =
3
28 Public WizardMode as String
29 Public Const SBMICROSOFTMODE =
"MS
"
30 ' The absolute maximal Number of possible Applications
31 Public Const SBMAXAPPLCOUNT =
4
32 Public Const Twip =
425
33 Public MaxApplCount as Integer
34 Public CurOffice As Integer
35 Public SOBitmapPath As String
36 Public SOWorkPath As String
37 Public SOTemplatePath as String
38 Public bCancelTask As Boolean
39 Public bDoKeepApplValues as Boolean
41 Public PathSeparator as String
43 Public ApplCount as Integer
44 Public sKeyName(SBMAXAPPLCOUNT-
1) as String
45 Public sValueName(SBMAXAPPLCOUNT-
1) as String
46 Public sCRLF as String
47 Public MSFilterName(
5,
4) as String
49 Public Applications(SBMAXAPPLCOUNT-
1,
9)
51 Public Const SBAPPLCONVERT =
0
52 Public Const SBDOCCONVERT =
1
53 Public Const SBDOCRECURSIVE =
2
54 Public Const SBDOCSOURCE =
3
55 Public Const SBDOCTARGET =
4
56 Public Const SBTEMPLCONVERT =
5
57 Public Const SBTEMPLRECURSIVE =
6
58 Public Const SBTEMPLSOURCE =
7
59 Public Const SBTEMPLTARGET =
8
60 Public Const SBAPPLKEY =
9
61 Public XMLTemplateList()
63 ' Application-relating Data are stored in this Array
64 ' according to the following structure:
65 ' Applications(X,
0) = True/False (Application is to be converted)
66 ' Applications(X,
1) = True/False (Documents are to be converted)
67 ' Applications(X,
2) = True/False (Including Subdirectories)
68 ' Applications(X,
3) =
"File:///...
" (SourceUrl of the documents)
69 ' Applications(X,
4) =
"File///:...
" (TargetUrl of the documents)
70 ' Applications(X,
5) = True/False (Templates are to be converted)
71 ' Applications(X,
6) = True/False (Including Subdirectories)
72 ' Applications(X,
7) =
"File:///...
" (SourceUrl of the templates)
73 ' Applications(X,
8) =
"File:///...
" (TargetUrl of the templates)
74 ' Applications(X,
9) =
0 (Key to the original Index of the Applications)
77 Sub FillStep_Welcome()
79 ' bDoKeepApplValues = False
80 ImportDialogArea.Title = sTitle
82 .cmdHelp.Label = sHelpButton
83 .cmdCancel.Label = sCancelButton
84 .cmdBack.Label = sBackButton
85 .cmdGoOn.Label = sNextButton
86 .WelcomeTextLabel.Label = sWelcomeTextLabel1
87 .WelcomeTextLabel3.Label = sWelcomeTextLabel3
89 .optMSDocuments.Label = sContainerName(
0)
90 .chkMSApplication1.Label = sMsDocumentCheckbox(
0)
91 .chkMSApplication2.Label = sMsDocumentCheckbox(
1)
92 .chkMSApplication3.Label = sMsDocumentCheckbox(
2)
94 .cmdBack.Enabled = False
97 If Not oFactoryKey.hasbyName(
"com.sun.star.text.TextDocument
") Then
99 .chkLogfile.Enabled = False
102 CheckModuleInstallation()
107 Sub FillStep_InputPaths(OfficeIndex as Integer, bStartup as Boolean)
109 Dim oNullObject as Object
110 If bStartup And Not bDoKeepApplValues Then
111 If ImportDialog.optMSDocuments.State =
1 Then
112 SetupMSConfiguration()
114 'Not supposed to happen - is there an assert in BASIC...
116 FillUpApplicationList()
118 CurOffice = OfficeIndex
119 Index = Applications(CurOffice,SBAPPLKEY)
120 InitializePathsforCurrentApplication(Index)
122 .chkTemplatePath.Label = sTemplateCheckbox(Index)
123 .chkDocumentPath.State = Abs(Applications(CurOffice,SBDOCCONVERT))
124 .chkDocumentSearchSubDir.State = Abs(Applications(CurOffice,SBDOCRECURSIVE))
125 .txtDocumentImportPath.Text = ConvertFromUrl(Applications(CurOffice,SBDOCSOURCE))
126 .txtDocumentExportPath.Text = ConvertFromUrl(Applications(CurOffice,SBDOCTARGET))
127 .hlnDocuments.Label = sProgressMoreDocs
128 If WizardMode = SBMICROSOFTMODE Then
129 ImportDialogArea.Title = sTitle
& " -
" & sMSDocumentCheckBox(Index)
131 .chkTemplatePath.Enabled = True
132 .chkDocumentPath.Enabled = True
133 .chkTemplatePath.Label = sTemplateCheckbox(Index)
134 .chkDocumentPath.Label = sDocumentCheckbox(Index)
135 .hlnTemplates.Label = sProgressMoreTemplates
136 .chkTemplatePath.State = Abs(Applications(CurOffice,SBTEMPLCONVERT))
137 ToggleInputPaths(oNullObject,
"Template
")
138 ToggleInputPaths(oNullObject,
"Document
")
139 .chkTemplateSearchSubDir.State = Abs(Applications(CurOffice,SBTEMPLRECURSIVE))
140 .txtTemplateImportPath.Text = ConvertFromUrl(Applications(CurOffice,SBTEMPLSOURCE))
141 .txtTemplateExportPath.Text = ConvertFromUrl(Applications(CurOffice,SBTEMPLTARGET))
142 .cmdGoOn.Label = sNextButton
143 .cmdBack.Enabled = True
144 ImportDialog.Step =
2
146 ImportDialogArea.GetControl(
"chkTemplatePath
").SetFocus()
151 Sub FillUpApplicationList()
154 Dim BoolValue as Boolean
155 If Not bDoKeepApplValues Then
157 For i =
1 To ApplCount
158 If ImportDialog.optMSDocuments.State =
1 Then
159 BoolValue = ImportDialogArea.GetControl(
"chkMSApplication
" & i).Model.State =
1
161 Applications(a,SBAPPLCONVERT) = BoolValue
162 Applications(a,SBDOCCONVERT) = BoolValue
163 Applications(a,SBDOCRECURSIVE) = BoolValue
164 Applications(a,SBDOCSOURCE) =
"" ' GetDefaultPath(i)
165 Applications(a,SBDOCTARGET) =
"" ' SOWorkPath
166 Applications(a,SBTEMPLCONVERT) = BoolValue
167 Applications(a,SBTEMPLRECURSIVE) = BoolValue
168 Applications(a,SBTEMPLSOURCE) =
"" ' GetTemplateDefaultPath(i)
169 Applications(a,SBTEMPLTARGET) =
"" ' GetTargetTemplatePath(i)
170 Applications(a,SBAPPLKEY) = i-
1
180 Sub InitializePathsforCurrentApplication(i as Integer)
181 AssignPathToCurrentApplication(SBDOCSOURCE, GetDefaultPath(i))
182 AssignPathToCurrentApplication(SBDOCTARGET, SOWorkPath)
183 AssignPathToCurrentApplication(SBTEMPLSOURCE, GetTemplateDefaultPath(i))
184 AssignPathToCurrentApplication(SBTEMPLTARGET, GetTargetTemplatePath(i))
188 Sub AssignPathToCurrentApplication(Index as Integer, NewPath as String)
189 If Applications(CurOffice,Index) =
"" Then
190 If CurOffice
> 0 Then
191 Applications(CurOffice,Index) = Applications(CurOffice-
1,Index)
193 Applications(CurOffice,Index) = NewPath
199 Sub SaveStep_InputPath()
200 Applications(CurOffice,SBDOCCONVERT) = ImportDialog.chkDocumentPath.State =
1
201 Applications(CurOffice,SBDOCRECURSIVE) = ImportDialog.chkDocumentSearchSubDir.State =
1
202 Applications(CurOffice,SBDOCSOURCE) = ConvertToURL(ImportDialog.txtDocumentImportPath.Text)
203 Applications(CurOffice,SBDOCTARGET) = ConvertToUrl(ImportDialog.txtDocumentExportPath.Text)
204 Applications(CurOffice,SBTEMPLCONVERT) = ImportDialog.chkTemplatePath.State =
1
205 Applications(CurOffice,SBTEMPLRECURSIVE) = ImportDialog.chkTemplateSearchSubDir.State =
1
206 Applications(CurOffice,SBTEMPLSOURCE) = ConvertToURL(ImportDialog.txtTemplateImportPath.Text)
207 Applications(CurOffice,SBTEMPLTARGET) = ConvertToURL(ImportDialog.txtTemplateExportPath.Text)
211 Sub ToggleInputPaths(aEvent as Object, Optional sDocType)
212 Dim bDoEnable as Boolean
213 Dim sLocDocType as String
214 Dim oCheckBox as Object
215 If Not IsNull(aEvent) Then
216 sLocDocType = aEvent.Source.Model.Tag
218 sLocDocType = sDocType
220 With ImportDialogArea
221 oCheckBox = .GetControl(
"chk
" & sLocDocType
& "Path
").Model
222 bDoEnable = oCheckBox.State =
1 And oCheckBox.Enabled
223 .GetControl(
"lbl
" & sLocDocType
& "Import
").Model.Enabled = bDoEnable
224 .GetControl(
"lbl
" & sLocDocType
& "Export
").Model.Enabled = bDoEnable
225 .GetControl(
"txt
" & sLocDocType
& "ImportPath
").Model.Enabled = bDoEnable
226 .GetControl(
"txt
" & sLocDocType
& "ExportPath
").Model.Enabled = bDoEnable
227 .GetControl(
"chk
" & sLocDocType
& "SearchSubDir
").Model.Enabled = bDoEnable
228 .GetControl(
"cmd
" & sLocDocType
& "Import
").Model.Enabled = bDoEnable
229 .GetControl(
"cmd
" & sLocDocType
& "Export
").Model.Enabled = bDoEnable
235 Function MakeSummaryString()
236 Dim sTmpText As String
239 Dim sAddText as String
240 For i =
0 To ApplCount -
1
241 Index = Applications(i,SBAPPLKEY)
242 If Applications(i,SBTEMPLCONVERT) Then
243 ' Templates are to be converted
244 sAddText =
""
245 If WizardMode = SBMICROSOFTMODE Then
246 sAddText = sSumMSTemplates(Index)
& sCRLF
248 sTmpText = sTmpText
& sAddText
& ConvertFromUrl(Applications(i,SBTEMPLSOURCE))
& sCRLF
249 If Applications(i,SBTEMPLRECURSIVE) Then
250 ' Including Subdirectories
251 sTmpText = sTmpText
& sSumInclusiveSubDir
& sCRLF
253 sTmpText = sTmpText
& sSumSaveDocuments
& sCRLF
254 sTmpText = sTmpText
& ConvertFromUrl(Applications(i,SBTEMPLTARGET))
& sCRLF
255 sTmpText = sTmpText
& sCRLF
258 If Applications(i,SBDOCCONVERT) Then
259 ' Documents are to be converted
260 If WizardMode = SBMICROSOFTMODE Then
261 sAddText = sSumMSDocuments(Index)
& sCRLF
263 sTmpText = sTmpText
& sAddText
& ConvertFromUrl(Applications(i,SBDOCSOURCE))
& sCRLF
265 If Applications(i,SBDOCRECURSIVE) Then
266 ' Including Subdirectories
267 sTmpText = sTmpText
& sSumInclusiveSubDir
& sCRLF
270 sTmpText = sTmpText
& sSumSaveDocuments
& sCRLF
271 sTmpText = sTmpText
& ConvertFromUrl(Applications(i,SBDOCTARGET))
& sCRLF
272 sTmpText = sTmpText
& sCRLF
275 MakeSummaryString = sTmpText
279 Sub FillStep_Summary()
280 ImportDialogArea.Title = sTitle
282 .SummaryTextbox.Text = MakeSummaryString()
283 .cmdGoOn.Enabled = .SummaryTextbox.Text
<> ""
284 .cmdGoOn.Label = sBeginButton
285 .SummaryHeaderLabel.Label = sSummaryHeader
288 ImportDialogArea.GetControl(
"SummaryHeaderLabel
").SetFocus()
292 Sub FillStep_Progress()
294 .cmdBack.Enabled = False
295 .cmdGoOn.Enabled = False
296 .hlnProgress.Label = sProgressPage_1
297 .LabelRetrieval.FontWeight = com.sun.star.awt.FontWeight.BOLD
298 .LabelRetrieval.Label = sProgressPage_2
299 .LabelCurProgress.Label = sProgressPage_3
300 .LabelCurDocumentRetrieval.Label =
""
301 .LabelCurTemplateRetrieval.Label =
""
302 .LabelCurDocument.Label =
""
305 ImportDialogArea.GetControl(
"LabelRetrieval
").SetFocus()
306 If ImportDialog.chkLogfile.State =
1 Then
307 ImportDialog.cmdShowLogFile.DefaultButton = True
312 Sub SetupMSConfiguration()
313 Wizardmode = SBMICROSOFTMODE
316 ' chkTemplatePath-Captions
317 sTemplateCheckBox(
0) = GetResText(
"MSTemplateCheckbox_1_
")
318 sTemplateCheckBox(
1) = GetResText(
"MSTemplateCheckbox_2_
")
319 sTemplateCheckBox(
2) = GetResText(
"MSTemplateCheckbox_3_
")
320 ' DocumentCheckbox- Captions
321 sDocumentCheckBox(
0) = GetResText(
"MSDocumentCheckbox_1_
")
322 sDocumentCheckBox(
1) = GetResText(
"MSDocumentCheckbox_2_
")
323 sDocumentCheckBox(
2) = GetResText(
"MSDocumentCheckbox_3_
")
325 sKeyName(
0) =
"Software\Microsoft\Office\
8.0\Word\Options
"
326 sKeyName(
1) =
"Software\Microsoft\Office\
8.0\Excel\Microsoft Excel
"
327 sKeyName(
2) =
"Software\Microsoft\Office\
8.0\PowerPoint\Recent Folder List\Default
"
329 sValueName(
0) =
"DOC-PATH
"
330 sValueName(
1) =
"DefaultPath
"
331 sValueName(
2) =
""
333 ' See definition of Filtername-Array about meaning of fields
334 MSFilterName(
0,
0) =
"doc|docx|docm
"
335 MSFilterName(
0,
1) =
"writer8|writer8|writer8
"
336 MSFilterName(
0,
2) =
"odt|odt|odt
"
337 MSFilterName(
0,
3) = sMSDocumentCheckBox(
0)
338 MSFilterName(
0,
4) =
"Word
"
341 MSFilterName(
1,
0) =
"xls|xlsx|xlsm
"
342 MSFilterName(
1,
1) =
"calc8|calc8|calc8
"
343 MSFilterName(
1,
2) =
"ods|ods|ods
"
344 MSFilterName(
1,
3) = sMSDocumentCheckBox(
1)
345 MSFilterName(
1,
4) =
"Excel
"
347 MSFilterName(
2,
0) =
"ppt|pps|pptx|pub|pptm|ppsx|ppsm
"
348 MSFilterName(
2,
1) =
"impress8|impress8|impress8|impress8|impress8|impress8|impress8
"
349 MSFilterName(
2,
2) =
"odp|odp|odp|odp|odp|odp|odp
"
350 MSFilterName(
2,
3) = sMSDocumentCheckBox(
2)
351 MSFilterName(
2,
4) =
"PowerPoint/Publisher
"
353 MSFilterName(
3,
0) =
"dot|dotx|dotm
"
354 MSFilterName(
3,
1) =
"writer8_template|writer8_template|writer8_template
"
355 MSFilterName(
3,
2) =
"ott|ott|ott
"
356 MSFilterName(
3,
3) = sMSTemplateCheckBox(
0)
357 MSFilterName(
3,
4) =
"Word
"
359 MSFilterName(
4,
0) =
"xlt|xltx|xltm
"
360 MSFilterName(
4,
1) =
"calc8_template|calc8_template|calc8_template
"
361 MSFilterName(
4,
2) =
"ots|ots|ots
"
362 MSFilterName(
4,
3) = sMSTemplateCheckBox(
1)
363 MSFilterName(
4,
4) =
"Excel
"
365 MSFilterName(
5,
0) =
"pot|potx|potm
"
366 MSFilterName(
5,
1) =
"impress8_template|impress8_template|impress8_template
"
367 MSFilterName(
5,
2) =
"otp|otp|otp
"
368 MSFilterName(
5,
3) = sMSTemplateCheckBox(
2)
369 MSFilterName(
5,
4) =
"PowerPoint
"
373 Function CheckControlPath(oCheckbox as Object, oTextBox as Object, ByVal bDoEnable as Boolean)
375 If Not bDoEnable Then
376 CheckControlPath = False
377 ElseIf oCheckbox.State =
0 Then
378 CheckControlPath = True
380 sPath = ConvertToUrl(Trim(oTextBox.Text))
381 CheckControlPath = oUcb.Exists(sPath)
386 Function CheckInputPaths() as Boolean
387 Dim bChangePage as Boolean
388 bChangePage = CheckTextBoxPath(ImportDialog.txtTemplateImportPath, True, False, sTitle, False)
389 bChangePage = CheckTextBoxPath(ImportDialog.txtTemplateExportPath, bChangePage, True, sTitle, False)
390 bChangePage = CheckTextBoxPath(ImportDialog.txtDocumentImportPath, bChangePage, False, sTitle, False)
391 bChangePage = CheckTextBoxPath(ImportDialog.txtDocumentExportPath, bChangePage, True, sTitle, False)
392 CheckInputPaths = bChangePage
396 Function CheckTextBoxPath(oTextBox as Object, ByVal bCheck as Boolean, bCreateNew as Boolean, sTitle as String, bgetResources as Boolean) as Boolean
397 Dim iCreate as Integer
398 Dim sQueryMessage as String
399 Dim sUrlPath as String
400 Dim sMessageNoDir as String
401 Dim sShowPath as String
402 Dim oLocUcb as Object
403 oLocUcb = createUnoService(
"com.sun.star.ucb.SimpleFileAccess
")
404 If bGetResources Then
405 If InitResources(
"ImportWizard
") then
406 sNoDirCreation = GetResText(
"NoDirCreation
")
407 sMsgDirNotThere = GetResText(
"MsgDirNotThere
")
408 sQueryForNewCreation = GetResText(
"QueryfornewCreation
")
410 CheckTextBoxPath() = False
414 If oTextBox.Enabled Then
416 sShowPath = oTextBox.Text
417 sUrlPath = ConvertToUrl(sShowPath)
418 If Not oLocUcb.Exists(sUrlPath) Then
419 If Not bCreateNew Then
420 ' Sourcedirectories must be existing, Targetdirectories may be created new
421 sQueryMessage = ReplaceString(sMsgDirNotThere, sShowPath,
"%
1")
422 Msgbox(sQueryMessage,
16,sTitle)
423 CheckTextBoxPath() = False
426 sQueryMessage = ReplaceString(sMsgDirNotThere, sShowPath,
"%
1")
427 sQueryMessage = sQueryMessage
& Chr(
13)
& sQueryForNewCreation
428 iCreate = Msgbox (sQueryMessage,
36, sTitle)
430 On Local Error Goto NOVALIDPATH
431 CreateFolder(sUrlPath)
432 If Not oLocUcb.Exists(sUrlPath) Then
436 CheckTextBoxPath() = False
441 CheckTextBoxPath() = True
443 CheckTextBoxPath() = False
446 CheckTextBoxPath() = True
450 sMessageNoDir = ReplaceString(sNoDirCreation, sShowPath,
"%
1")
451 Msgbox(sMessageNoDir,
16, sTitle)
452 CheckTextBoxPath() = False
456 Sub InitializeProgressPage(oDialog as Object)
457 oDialog.LabelRetrieval.FontWeight = com.sun.star.awt.FontWeight.NORMAL
458 oDialog.LabelCurProgress.FontWeight = com.sun.star.awt.FontWeight.BOLD
462 Sub SetProgressDisplay(AbsFound as Integer)
463 ImportDialog.LabelRetrieval.Label = sProgressPage_2
& " " & ReplaceString(sProgressPage_5, Str(AbsFound)
& " ",
"%
1")
464 ImportDialog.LabelCurDocumentRetrieval.Label = sProgressFound
& " " & CStr(AbsDocuFound)
& " " & sProgressMoreDocs
465 ImportDialog.LabelCurTemplateRetrieval.Label = sProgressFound
& " " & CStr(AbsTemplateFound)
& " " & sProgressMoreTemplates
468 Sub TakoverFolderName(aEvent as Object)
469 Dim RefControlName as String
471 RefControlName = aEvent.Source.Model.Tag
472 oRefControl = ImportDialogArea.GetControl(RefControlName)
473 GetFolderName(oRefControl.Model)
478 Sub FinalizeDialogButtons()
479 ImportDialog.cmdShowLogFile.Enabled = ((Isnull(oLogDocument) = False) And (ImportDialog.chkLogfile.State =
1))
480 ImportDialog.cmdCancel.Enabled = False
481 ImportDialog.cmdGoOn.Label = sCloseButton
482 ImportDialog.cmdGoOn.Enabled = True