summaryrefslogtreecommitdiffstats
path: root/wizards/source/importwizard/Main.xba
blob: b8cc8211edfbcf1be32800f1f8b3e55eacb21c65 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
<!--
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
-->
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Main" script:language="StarBasic">Option Explicit
REM ***** BASIC *****

Public HeaderPreviews(4) as Object
Public ImportDialog as Object
Public ImportDialogArea as Object
Public oFactoryKey as Object
Public bShowLogFile as Boolean

&apos; If the ProgressPage is already on Top The Dialog will be immediately closed when this flag is
&apos; set to False
Public bConversionIsRunning as Boolean
Public RetValue as Integer

Sub Main()
	Dim NoArgs() as New com.sun.star.beans.PropertyValue
	bShowLogFile=FALSE
	If Not bDebugWizard Then
		On Local Error Goto RTError
	End If
	BasicLibraries.LoadLibrary(&quot;Tools&quot;)
	RetValue = 10
	bIsFirstLogTable = True
	bConversionIsRunning = False
	sCRLF = CHR(13) &amp; CHR(10)
	oUcb = createUnoService(&quot;com.sun.star.ucb.SimpleFileAccess&quot;)
	oFactoryKey = GetRegistryKeyContent(&quot;org.openoffice.Setup/Office/Factories&quot;)
	If GetImportWizardPaths() = False Then
		Exit Sub
	End If
	bCancelTask = False
	bDoKeepApplValues = False
	CurOffice = 0
	ImportDialogArea = LoadDialog(&quot;ImportWizard&quot;,&quot;ImportDialog&quot;)
	ImportDialog = ImportDialogArea.Model
	LoadLanguage()
	WizardMode = SBMICROSOFTMODE
	MaxApplCount = 3
	FillStep_Welcome()
	RepaintHeaderPreview()
	ImportDialog.ImportPreview.BackGroundColor = RGB(0,60,126)
	ImportDialog.cmdGoOn.DefaultButton = True
	ImportDialogArea.GetControl(&quot;optMSDocuments&quot;).SetFocus()
	ToggleCheckboxesWithBoolean(True)

	RetValue = ImportDialogArea.Execute()
	If bShowLogFile=TRUE Then
		OpenDocument(sLogUrl, NoArgs())
	End if
	If RetValue = 0 Then
		CancelTask()
	End If
	ImportDialogArea.Dispose()
	End
	Exit Sub
RTError:
	Msgbox sRTErrorDesc, 16, sRTErrorHeader
End Sub


Sub NextStep()
Dim iCurStep as Integer
	If Not bDebugWizard Then
		On Error Goto RTError
	End If
	bConversionIsRunning = False
	iCurStep = ImportDialog.Step
	Select Case iCurStep
		Case 1
			FillStep_InputPaths(0, True)
		Case 2
			If CheckInputPaths Then
				SaveStep_InputPath
				If CurOffice &lt; ApplCount - 1 Then
					CurOffice = CurOffice + 1
					TakeOverPathSettings()
					FillStep_InputPaths(CurOffice, False)
				Else
					FillStep_Summary()
				End If
			End If
		Case 3
			FillStep_Progress()
			Select Case WizardMode
				Case SBMICROSOFTMODE
					Call ConvertAllDocuments(MSFilterName())
			End Select
		Case 4
			CancelTask(True)
	End Select

	If ((ImportDialog.chkLogfile.State &lt;&gt; 1) OR (iCurStep &lt;&gt; 3)) Then
		ImportDialog.cmdGoOn.DefaultButton = True
	End If

	RepaintHeaderPreview()
	Exit Sub
RTError:
	Msgbox sRTErrorDesc, 16, sRTErrorHeader
End Sub


Sub PrevStep()
Dim iCurStep as Integer
	If Not bDebugWizard Then
		On Error Goto RTError
	End If
	bConversionIsRunning = False
	iCurStep = ImportDialog.Step
	Select Case iCurStep
		Case 4
			ImportDialog.cmdCancel.Label = sCancelButton
			FillStep_Summary()
		Case 3
			FillStep_InputPaths(Applcount-1, False)
		Case 2
			SaveStep_InputPath
			If CurOffice &gt; 0 Then
				CurOffice = CurOffice - 1
				FillStep_InputPaths(CurOffice, False)
			Else
				FillStep_Welcome()
			        ToggleCheckboxesWithBoolean(True)
				bDoKeepApplValues = True
			End If
	End Select
	ImportDialog.cmdGoOn.DefaultButton = True
	RepaintHeaderPreview()
	Exit Sub
RTError:
	Msgbox sRTErrorDesc, 16, sRTErrorHeader
End Sub


Sub CancelTask()
	If bConversionIsRunning Then
		If Msgbox(sConvertError1, 36, sConvertError2) = 6 Then
			bCancelTask = True
			bInterruptSearch = True
		Else
			bCancelTask = False
			ImportDialog.cmdCancel.Enabled = True
		End If
	Else
		ImportDialogArea.EndExecute()
	End If
End Sub


Sub TemplateDirSearchDialog()
	CallDirSearchDialog(ImportDialog.TemplateImportPath)
End Sub


Sub RepaintHeaderPreview()
Dim Bitmap As Object
Dim CurStep as Integer
Dim sBitmapPath as String
Dim LocPrefix as String
	CurStep = ImportDialog.Step
	LocPrefix = WizardMode
	LocPrefix = ReplaceString(LocPrefix,&quot;XML&quot;, &quot;SO&quot;)
	If CurStep = 2 Then
		sBitmapPath = SOBitmapPath &amp; LocPrefix &amp; &quot;-Import_&quot; &amp; CurStep &amp; &quot;-&quot; &amp; Applications(CurOffice,SBAPPLKEY) + 1 &amp; &quot;.png&quot;
	Else
		sBitmapPath = SOBitmapPath &amp; &quot;Import_&quot; &amp; CurStep &amp; &quot;.png&quot;
	End If
	ImportDialog.ImportPreview.ImageURL = sBitmapPath
End Sub


Sub CheckModuleInstallation()
Dim i as Integer
	For i = 1 To MaxApplCount
		ImportDialogArea.GetControl(&quot;chk&quot; &amp; WizardMode &amp; &quot;Application&quot; &amp; i).Model.Enabled = Abs(CheckInstalledModule(i-1))
	Next i
End Sub


Function CheckInstalledModule(Index as Integer) as Boolean
Dim ModuleName as String
Dim NameList() as String
Dim MaxIndex as Integer
Dim i as Integer
	ModuleName = ModuleList(Index)
	If Instr(1,ModuleName,&quot;/&quot;) &lt;&gt; 0 Then
		CheckInstalledModule() = False
		NameList() = ArrayoutOfString(ModuleName,&quot;/&quot;, MaxIndex)
		For i = 0 To MaxIndex
			If oFactoryKey.HasByName(NameList(i)) Then
				CheckInstalledModule() = True
			End If
		Next i
	Else
		CheckInstalledModule() = oFactoryKey.HasByName(ModuleName)
	End If
End Function


Sub ToggleCheckboxes(oEvent as Object)
Dim bMSEnable as Boolean
	WizardMode = oEvent.Source.Model.Tag
	bMSEnable = WizardMode = &quot;MS&quot;
	ToggleCheckboxesWithBoolean(bMSEnable)
End Sub


Sub ToggleCheckboxesWithBoolean(bMSEnable as Boolean)
	If bMSEnable = True Then
		WizardMode = SBMICROSOFTMODE
		MaxApplCount = 3
	Else
		&apos;Not supposed to happen - is there an assert in BASIC...
	End If
	With ImportDialogArea
		.GetControl(&quot;chkMSApplication1&quot;).Model.Enabled = bMSEnable
		.GetControl(&quot;chkMSApplication2&quot;).Model.Enabled = bMSEnable
		.GetControl(&quot;chkMSApplication3&quot;).Model.Enabled = bMSEnable
	End With
	CheckModuleInstallation()
	bDoKeepApplValues = False
	ToggleNextButton()
End Sub


Sub ToggleNextButton()
Dim iCurStep as Integer
Dim bDoEnable as Boolean
Dim i as Integer
	iCurStep = ImportDialog.Step
	Select Case iCurStep
		Case 1
			With ImportDialog
				If .optMSDocuments.State = 1 Then
          			bDoEnable = .chkMSApplication1.State = 1 Or .chkMSApplication2.State = 1 Or .chkMSApplication3.State = 1
				End If
			End With
			bDoKeepApplValues = False
		Case 2
			bDoEnable = CheckControlPath(ImportDialog.chkTemplatePath, ImportDialog.txtTemplateImportPath, True)
			bDoEnable = CheckControlPath(ImportDialog.chkDocumentPath, ImportDialog.txtDocumentImportPath, bDoEnable)
	End Select
	ImportDialog.cmdGoOn.Enabled = bDoEnable
End Sub


Sub TakeOverPathSettings()
&apos;Takes over the Pathsettings from the first selected application to the next applications
	If Applications(CurOffice,SBDOCSOURCE) = &quot;&quot; Then
		Applications(CurOffice,SBDOCSOURCE) = Applications(0,SBDOCSOURCE)
		Applications(CurOffice,SBDOCTARGET) = Applications(0,SBDOCTARGET)
		Applications(CurOffice,SBTEMPLSOURCE) = Applications(0,SBTEMPLSOURCE)
		Applications(CurOffice,SBTEMPLTARGET) = Applications(0,SBTEMPLTARGET)
	End If
End Sub


Function GetImportWizardPaths() as Boolean
	SOBitmapPath = GetOfficeSubPath(&quot;Template&quot;, &quot;../wizard/bitmap&quot;)
	If SOBitmapPath &lt;&gt; &quot;&quot; Then
		SOWorkPath = GetPathSettings(&quot;Work&quot;, False)
		If SOWorkPath &lt;&gt; &quot;&quot; Then
			SOTemplatePath = GetPathSettings(&quot;Template_writable&quot;,False,0)
			If SOTemplatePath &lt;&gt; &quot;&quot; Then
				GetImportWizardPaths() = True
				Exit Function
			End If
		End If
	End If
	GetImportWizardPaths() = False
End Function
</script:module>