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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
|
'encoding UTF-8 Do not remove or change this line!
'*******************************************************************************
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
'/******************************************************************************
'*
'* Owner : thorsten.bosbach@sun.com
'*
'* short description : Global routines for loading, saving, printing, export
'*
'\******************************************************************************
private const VERBOSE = FALSE ' set to TRUE for debugging
function hGrafikEinfuegen ( Grafik$ ) as Boolean
'/// hGrafikEinfuegen hGraphicInsert
'/// A graphic will be inserted (not linked).
'/// <u>Input</u>: Filename with complete path
'/// <u>Return</u>: TRUE or FALSE if the graphic could be inserted or not.
Dim DieDatei as String
Dim IsActive as Boolean
DieDatei = ConvertPath ( Grafik$ )
InsertGraphicsFromFile
WaitSlot()
Kontext
If Active.Exists(1) then
warnlog " Hinweis: " & Active.GetText
Active.Ok
End If
Kontext "GrafikEinfuegenDlg"
if ( GrafikEinfuegenDlg.exists( 2 ) ) then
Vorschau.Uncheck
if gApplication <> "HTML" then
Verknuepfen.UnCheck
end if
Dateiname.SetText DieDatei
DateiTyp.Select 1 ' set the filter to 'all formats'
Oeffnen.Click
Kontext "Active"
if Active.Exists(2) then
Warnlog " Hinweis: " & Active.GetText
try
Active.OK
catch
try
Active.Yes
catch
Active.Cancel
endcatch
endcatch
Kontext "GrafikEinfuegenDlg"
if GrafikEinfuegenDlg.Exists then
GrafikEinfuegenDlg.Cancel
GarfikEinfuegenDlg.notExists( 4 )
endif
else
hGrafikEinfuegen = IsImageLoaded
end if
else
warnlog( "Insert graphics dialog not open" )
endif
end function
'
'-------------------------------------------------------------------------------
'
function hGrafikVerknuepftEinfuegen ( Grafik$ ) as Boolean
'/// hGrafikEinfuegenEinfuegen hGraphicInsertLinked
'/// A graphic will be inserted <b>LINKED</b>
'/// <u>Input</u>: Filename with complete path
'/// <u>Return</u>: TRUE or FALSE if the graphic could be inserted or not.
Dim DieDatei as String
Dim IsActive as Boolean
DieDatei = ConvertPath ( Grafik$ )
InsertGraphicsFromFile
WaitSlot()
Kontext
If Active.Exists(1) then
warnlog " Hinweis: " & Active.GetText
Active.Ok
End If
Kontext "GrafikEinfuegenDlg"
if ( GrafikEinfuegenDlg.exists( 1 ) ) then
Vorschau.UnCheck
if gApplication <> "HTML" AND gApplication <> "HTML" then
Verknuepfen.Check
end if
Dateiname.SetText DieDatei
DateiTyp.Select 1 ' set the filter to 'all formats'
Oeffnen.Click
Kontext "Active"
if Active.Exists(2) then
Warnlog " Hinweis: " + Active.GetText
try
Active.OK
catch
Active.Yes
endcatch
Kontext "GrafikEinfuegenDlg"
if GrafikEinfuegenDlg.Exists then
GrafikEinfuegenDlg.Cancel
endif
else
hGrafikVerknuepftEinfuegen = IsImageLoaded
end if
else
'GrafikEinfuegenDlg not open
endif
end function
'
'-------------------------------------------------------------------------------
'
function IsItSaved as boolean
'/// IsItSaved
'/// Wait until document is saved.
Dim iLoop as integer
IsItSaved = FALSE
sleep(3)
for iLoop =1 to 20
try
'Calling slot 'IsDocSaving'
IsItSaved = IsDocSaving
catch
IsItSaved = FALSE
endcatch
if IsItSaved = TRUE then
exit for
end if
sleep(1)
next iLoop
sleep(2)
end function
'
'-------------------------------------------------------------------------------
'
function IsItLoaded as boolean
'/// IsItLoaded
'/// Wait until document is loaded
Dim iLoop as integer
IsItLoaded = FALSE
sleep(3)
for iLoop =1 to 20
try
'Calling slot 'IsDocLoading'
IsItLoaded = IsDocLoading
catch
IsItLoaded = FALSE
endcatch
if IsItLoaded = TRUE then
exit for
end if
sleep(1)
next iLoop
sleep(2)
end function
'
'-------------------------------------------------------------------------------
'
function hIsNamedDocLoaded (ShouldFile as String, optional bSilent as boolean) as Boolean
dim sTemp as string
'/// hIsNamedDocLoaded ///'
'/// !fails always if a template is loaded, because you have to set a new filename in the save-dialog -> not usable in this case ! ///'
'/// Input: name of loaded file; Output: True/False ///'
'///+' if a doc got loaded, the filename in a 'SaveAs' Dlg is different from "" ///
'///+' usually the file name of the loaded document with an changed extension chosen from SO ///
if (isMissing(bSilent)) then
bSilent = False
endif
hIsNamedDocLoaded = FALSE ' Let's start WorstCase :-(
FileSaveAs
Kontext "SpeichernDlg"
If DateiOhneExt(DateiExtract(Dateiname.GetSelText)) = DateiOhneExt(DateiExtract(ShouldFile)) Then
hIsNamedDocLoaded = True
Else
sTemp = left(right(ShouldFile,2),1) ' get the 2nd last character ' vor;dot;sti;pot;std;xlt
if (((sTemp="o") or (sTemp="t") or (sTemp="l")) and ((left(right(ShouldFile,4),1)=".") or (left(right(ShouldFile,5),1)="."))) then
hIsNamedDocLoaded = TRUE ' exception! for linux! and MS-Office Templates
else
if ((Dateiname.GetSeltext = "") and not bSilent) then
Warnlog "Default filename is empty!"+left(right(ShouldFile,3),1)
endif
endif
End If
SpeichernDlg.Cancel
end function
'
'-------------------------------------------------------------------------------
'
function IsImageLoaded
'/// IsImageLoaded
'/// Wait until images in document are loaded
Dim i% : Dim Herbert as Boolean
Sleep 3
for i%=1 to 20
try
Herbert = IsDocImageLoading
catch
Herbert = FALSE
endcatch
if Herbert = TRUE then
i%=100
endif
Sleep (1)
next i%
if i<100 then
IsImageLoaded = FALSE
else
IsImageLoaded = TRUE
end if
end function
'
'-------------------------------------------------------------------------------
'
sub hIsWebPageLoaded as boolean
'Author: Joerg Sievers
'/// If a document in StarOffice Writer is loaded all 9 items in the
'///+ statusbar are visible otherwise not.
'///+ This sub checks the state of these items.
Dim i as integer
Dim iGibtdenStatusraus as integer
printlog "- global::tools::inc::tfiles.inc::hIsWebPageLoaded"
hIsWebPageLoaded = FALSE
for i = 1 to 20
Kontext "DocumentWriter"
if DocumentWriter.Exists(3) then
'Count the items on the status bar.
iGibtdenStatusraus = DocumentWriter.StatusGetItemCount
'There are nine items on the status bar if the web page has been loaded.
if iGibtdenStatusraus = 9 then
hIsWebPageLoaded = TRUE
exit for
end If
end if
WaitSlot( 3000 )
next i
end sub
'
'-------------------------------------------------------------------------------
'
sub hSys2IntDlg
'/// Change from system to StarOffice-internal file-dialog (only for Win32)
if gPlatgroup <> "unx" then
Call hhSysToInt ( TRUE )
endif
gUseSysDlg = FALSE
end sub
'
'-------------------------------------------------------------------------------
'
sub hInt2SysDlg
'/// Change from StarOffice-internal to system file-dialog (only for Win32)
if gPlatgroup <> "unx" then
Call hhSysToInt ( FALSE )
endif
gUseSysDlg = TRUE
end sub
'
'-------------------------------------------------------------------------------
'
sub hhSysToInt ( bwhats as Boolean )
'/// subroutine for <i>hSys2IntDlg</i> and </i>hInt2SysDlg</i>
ToolsOptions
hToolsOptions ( "StarOffice", "General" )
if bwhats = TRUE then
StarOfficeDialogeBenutzen.Check
else
StarOfficeDialogeBenutzen.Uncheck
end if
Sleep 1
Kontext "OptionenDlg"
OptionenDlg.OK
WaitSlot( 3000 )
end sub
'
'-------------------------------------------------------------------------------
'
function hGetUsedFilter () as string
'/// Get used filter for loaded file.
try
FileSaveAs
Kontext "SpeichernDlg"
hGetUsedFilter = dateityp.getseltext
SpeichernDlg.Cancel
catch
hGetUsedFilter = "Not possible; try/catch fail in function"
endcatch
end function
'
'-------------------------------------------------------------------------------
'
function hFileExport (sName as string, sFilter as string) as boolean
'/// Wrapper function to simplify the use of the export functions, just give a filename and export format.
'///+ INPUT:<ul><li>sName: filename</li><li>sFilter: "PDF": call export for PDF</li></ul>
'///+ RETURN: execution success?
select case sFilter
case "PDF" : '/// use the function 'hExportAsPDF' with RECOMMENDED values /// '
hFileExport = hExportAsPDFmulti (3, TRUE, sName, FALSE, TRUE, 1, 1)
end select
kontext
if active.exists(5) then
try
printlog active.getText
active.ok
warnLog "i26820 - errormessage about saving"
catch
printlog "pdf unexpected error in hFileExport()"
endcatch
endif
end function
'
'-------------------------------------------------------------------------------
'
function hExportAsPDFmulti (iTypeOfCall as integer, bExecute as boolean, sFileName as string, bAutoExtension as boolean, bOverwriteFile as boolean, iRange as integer, iConpression as integer, optional sRange as string) as boolean
'/// Export a document to PDF with various options.
'///+ INPUT
'///+<ul><li>iTypeOfCall</li><ul><li>1: via the icon in the functionbar (no options selectable, since only file dialog comes up!)</li>
'///+<li>2: via File->Send->Document As PDF Attachment... (makes no sense either, because after the mail window comes up... (you can't handle by the testtool))</li>
'///+<li>3 via File->Export As PDF... (RECOMMENDED)</li></ul>
'///+<li>bExecute: Shall all dialogs left with OK? TRUE (RECOMMENDED) / FALSE</li>
'///+<li>sFileName: Filename to use</li>
'///+<li>bAutoExtension: Shall the file extension be chosen by StarOffice? TRUE / FALSE (RECOMMENDED)</li>
'///+<li>bOverwriteFile: If filename already exists should it be overwritten? TRUE (RECOMMENDED) / FALSE</li>
'///+<li>iRange:</li><ol><li>1: All (RECOMMENDED)</li>
'///+<li>2: Pages: The range is set in the optional parameter 'sRange' at the end</li>
'///+<li>3: Selection</li></ol>
'///+<li>iConpression:</li><ol><li>1: JpegCompression check and ReduceImageResolution check</li>
'///+<li>2: JpegCompression check and ReduceImageResolution uncheck</li>
'///+<li>3: LosslessCompression check and ReduceImageResolution uncheck</li></ol>
'///+<li>sRange: Optional parameter only used for iRange=2; takes the page range as text</li>
'///+<li>RETURN: Any Errors? TRUE / FALSE</li></ul>
dim sPDF as string
dim sTemp as string
dim iTemp as integer
dim sTFileName as string
dim iCount as integer
sPDF = "PDF - Portable Document Format (.pdf)"
hExportAsPDFmulti = TRUE ' optimistic
iTemp = 0
select case (iTypeOfCall)
case 1 : '/// click the button 'Export Directly as PDF' on the Functionbar ///'
kontext "Standardbar"
try
ExportAsPDF.click
catch
Warnlog "Button 'Export directly as PDF' not accessible!"
hExportAsPDFmulti = FALSE
exit function
endcatch
case 2 : '/// File->Send->Document As PDF Attachment... ///'
try
FileSendDocumentAsPDF
catch
Warnlog "'Export as PDF' not accessible!"
hExportAsPDFmulti = FALSE
exit function
endcatch
case 3 : '/// File->Export As PDF... ///'
try
FileExportAsPDF ' works in draw/impress, too but is not 'legal' in the UI :-)
catch
Warnlog "Button 'Export as PDF' not accessible!"
hExportAsPDFmulti = FALSE
exit function
endcatch
end select
' only if the type is 1 OR 3 then the File Save dialog appear
' just kept here for compatibility reasons - has to get removed around july 2007
if (iTypeOfCall = 1 OR iTypeOfCall = 3) then
kontext "ExportierenDlg"
if ExportierenDlg.exists(5) then
try
Dateityp.Select sPDF
catch
Warnlog "Unable to select filter: '" + sPDF + "'"
ExportierenDlg.Cancel
hExportAsPDFmulti = FALSE
exit function
endcatch
sTemp = Dateityp.GetSelText
if (sTemp <> sPDF) then
Warnlog "filter for PDF export is missing :-( '" + sPDF + "'"
end if
'/// set Textbox 'File name' ///'
Dateiname.SetText sFileName
'if the file has no pdf extension then add the extension
if (lCase(right(sFileName, 4))=".pdf") then
sTFileName = sFileName
else
sTFileName = sFileName + ".pdf"
endif
'/// click on the button 'Export...' ///'
if (bExecute) then
speichern.Click
kontext "AlienWarning"
if AlienWarning.exists(5) then
warnlog "#i41983# Alien Warning on export not allowed."
AlienWarning.OK
endif
if (iTypeOfCall = 1) then
''Export Directly as PDF'
endif
iCount = 0
' wait until file exists for max 5 minutes
while ((dir(sTFileName)="") AND (iCount < 30))
sleep 10
inc iCount
wEnd
endif
else
'ExportierenDlg.Cancel
end if
' if file exists, there is a message...
kontext "PDFOptions"
if NOT PDFOptions.exists then
Kontext
if messagebox.exists (5) then
if (bOverwriteFile) then
messagebox.Yes
else
messagebox.No
kontext "ExportierenDlg"
ExportierenDlg.Cancel
hExportAsPDFmulti = FALSE
end if
end if
end if
end if
' only if the type is 2 OR 3 then the PDF option dialog appear
if (iTypeOfCall = 2 OR iTypeOfCall = 3) then
kontext "PDFOptions"
select case (iRange)
case 1 : '/// check radiobutton 'All' ///'
try
RangeAll.Check
catch
Warnlog "Radiobutton 'All' not accessible!"
PDFOptions.Cancel
hExportAsPDFmulti = FALSE
exit function
endcatch
case 2 : '/// check radiobutton 'Pages' ///'
try
RangePages.Check
catch
Warnlog "Radiobutton 'Range' not accessible!"
PDFOptions.Cancel
hExportAsPDFmulti = FALSE
exit function
endcatch
if isMissing(sRange) then
Warnlog "parameter 'sRange' in function 'hExportAsPDFmulti' is not optional if 'iRange' = 2"
hExportAsPDFmulti = FALSE
else
'/// set range textbox the given value ///'
RangePagesEdit.SetText sRange
end if
case 3 : '/// check radiobutton 'Selection' (not enabled in math!) ///'
try
if (RangeSelection.IsEnabled <> TRUE)then
Warnlog "RangeSelection is disabled :-("
else
RangeSelection.Check
end if
catch
Warnlog "Radiobutton 'Selection' not accessible!"
PDFOptions.Cancel
hExportAsPDFmulti = FALSE
exit function
endcatch
end select
select case (iConpression)
case 1 : '/// JpegCompression check and ReduceImageResolution check///'
try
JpegCompression.Check
ReduceImageResolution.Check
catch
Warnlog "Radiobutton 'Reduce Image Resolution' not accessible!"
PDFOptions.Cancel
hExportAsPDFmulti = FALSE
exit function
endcatch
case 2 : '/// JpegCompression check and ReduceImageResolution uncheck ///'
try
JpegCompression.Check
ReduceImageResolution.UnCheck
catch
Warnlog "Radiobutton 'Jpeg Compression' not accessible!"
PDFOptions.Cancel
hExportAsPDFmulti = FALSE
exit function
endcatch
case 3 : '/// LosslessCompression check and ReduceImageResolution uncheck ///'
try
LosslessCompression.Check
ReduceImageResolution.UnCheck
catch
Warnlog "Radiobutton 'Lossless Compression' not accessible!"
PDFOptions.Cancel
hExportAsPDFmulti = FALSE
exit function
endcatch
end select
if (bExecute) then
try
PDFOptions.OK
catch
qaErrorlog "ImprovementOfSave: PDF export loops?"
endcatch
else
PDFOptions.Cancel
end if
end if
' only if the type is 1 OR 3 then the File Save dialog appear
kontext "ExportierenDLG"
if (iTypeOfCall = 1 OR iTypeOfCall = 3) then
if ExportierenDLG.exists(5) then
try
Dateityp.Select sPDF
catch
Warnlog "Unable to select filter: '" + sPDF + "'"
ExportierenDLG.Cancel
hExportAsPDFmulti = FALSE
exit function
endcatch
sTemp = Dateityp.GetSelText
if (sTemp <> sPDF) then
Warnlog "filter for PDF export is missing :-( '" + sPDF + "'"
end if
'/// set Textbox 'File name' ///'
Dateiname.SetText sFileName
'if the file has no pdf extension then add the extension
if (lCase(right(sFileName, 4))=".pdf") then
sTFileName = sFileName
else
sTFileName = sFileName + ".pdf"
endif
'/// click on the button 'Export...' ///'
if (bExecute) then
Speichern.Click
kontext "AlienWarning"
if AlienWarning.exists(5) then
warnlog "#i41983# Alien Warning on export not allowed."
AlienWarning.OK
endif
if (iTypeOfCall = 1) then
''Export Directly as PDF'
endif
iCount = 0
' wait until file exists for max 5 minutes
while ((dir(sTFileName)="") AND (iCount < 30))
sleep 10
inc iCount
wEnd
endif
else
try
ExportierenDLG.Cancel
catch
printlog "export not there"
endcatch
end if
' if file exists, there is a message...
kontext "PDFOptions"
if NOT PDFOptions.exists then
Kontext
if messagebox.exists (5) then
if (bOverwriteFile) then
messagebox.Yes
else
messagebox.No
kontext "ExportierenDLG"
ExportierenDLG.Cancel
hExportAsPDFmulti = FALSE
end if
end if
end if
end if
end function
'
'-------------------------------------------------------------------------------
'
function hDeleteFile( cFileOrig as string ) as boolean
const CFN = "global::tools::includes::required::t_files.inc::hDeleteFile():"
dim cHome as string : cHome = convertpath( gOfficePath & "user" )
dim cFile as string : cFile = convertpath( cFileOrig )
' This function tries to delete a file and does some very basic error-
' handling. Returns 'true' on success, only error while deleting returns
' 'false', if the file does not exist, it is considered to be successfully
' deleted.
' I introduced this function due to a number of cases where deleting files
' actually failed because of weird code or situations where the user lacks
' accessrights to files are not handled at all.
if ( instr( cFile , cHome ) = 0 ) then
qaerrorlog( CFN & "Trying to delete file outside (default)homedir -> forbidden" )
qaerrorlog( CFN & "Home: " & cHome )
qaerrorlog( CFN & "File: " & cFile )
hDeleteFile() = false
exit function
endif
cFile = convertpath( cFile )
if ( FileExists( cFile ) ) then
try
kill( cFile )
if ( FileExists( cFile ) ) then
warnlog( CFN & "File was not deleted: " & cFile )
hDeleteFile() = false
else
if ( VERBOSE ) then printlog( CFN & "File successfully deleted: " & cFile )
hDeleteFile() = true
endif
catch
qaerrorlog( CFN & "Deleting file failed: " & cFile )
hDeleteFile() = false
endcatch
else
printlog( CFN & "Nothing to do." )
hDeleteFile() = true
endif
end function
'
'-------------------------------------------------------------------------------
'
function hFileCloseAll() as integer
dim iDocumentCount as integer : iDocumentCount = 0
Do Until GetDocumentCount = 0
Call hCloseDocument()
iDocumentCount = iDocumentCount + 1
Loop
hFileCloseAll() = iDocumentCount
end function
'
'-------------------------------------------------------------------------------
'
function hFileOpen( cFile as string ) as boolean
dim sFile as string : sFile = convertToURL( convertpath( cFile ) )
hFileOpen() = FALSE
const CFN = "global::tools::inc::t_files.inc::hFileOpen():"
if ( VERBOSE ) then printlog( CFN & "Load: " & sFile )
FileOpen( "URL", sFile, "FrameName", "_default" )
if ( hFileWait( FALSE ) >= 0 ) then hFileOpen() = TRUE
end function
'
'-------------------------------------------------------------------------------
'
function hFileOpenSpecial( cFile as string, cFlag as string ) as boolean
' Open a file with some special options
' cFlag = "ReadOnly" opens file read-onlx
' cFlag = "AsTemplate" opens file as templat
' cFlag = <Any other string> treats string as password
dim sFile as string : sFile = convertToURL( convertpath( cFile ) )
const CFN = "global::tools::inc::t_files.inc::hFileOpenSpecial():"
hFileOpenSpecial() = FALSE
if ( VERBOSE ) then printlog( "Load (Flag): " & sFile & " (" & cFlag & ")" )
select case( lcase( cFlag ) )
case "readonly"
printlog( CFN & "Load file read-only: " & sFile )
FileOpen( "URL", sFile, "FrameName", "_default", "ReadOnly", TRUE)
case "astemplate"
printlog( CFN & "Load file as template: " & sFile )
FileOpen( "URL", sFile, "FrameName", "_default", "AsTemplate" , TRUE )
case else
printlog( CFN & "Load file with password: " & sFile )
FileOpen( "URL", sFile, "FrameName", "_default", "Password" , cFlag )
end select
if ( hFileWait( FALSE ) >= 0 ) then hFileOpenSpecial() = TRUE
end function
'
'-------------------------------------------------------------------------------
'
function hFileOpenWithFilter( cFile as string, cFilter as string )
dim sFile as string : sFile = convertToURL( convertpath( cFile ) )
const CFN = "global::tools::inc::t_files.inc::hFileOpenWithFilter():"
hFileOpenWithFilter() = FALSE
if ( VERBOSE ) then printlog( CFN & "Load (Filter): " & sFile & " (" & cFilter & ")" )
FileOpen( "URL", sFile, "FrameName", "_default", "FilterName", cFilter )
if ( hFileWait( FALSE ) >= 0 ) then hFileOpenWithFilter() = TRUE
end function
'
'-------------------------------------------------------------------------------
'
function hFileSave() as boolean
const CFN = "global::tools::inc::t_files.inc::hFileSave():"
hFileSave() = FALSE
if ( VERBOSE ) then printlog( CFN & "Save file." )
FileSave( "SynchronMode", TRUE )
if ( hFileWait( TRUE ) >= 0 ) then hFileSave() = TRUE
end function
'
'-------------------------------------------------------------------------------
'
function hFileSaveAs( cFile as string ) as boolean
dim sFile as string : sFile = convertToURL( convertpath( cFile ) )
const CFN = "global::tools::inc::t_files.inc::hFileSaveAs():"
hFileSaveAs() = FALSE
if ( VERBOSE ) then printlog( CFN & "Save: " & sFile )
FileSaveAs( "URL", sFile, "Overwrite", FALSE )
if ( hFileWait( TRUE ) >= 0 ) then hFileSaveAs() = TRUE
end function
'
'-------------------------------------------------------------------------------
'
function hFileSaveAsKill( cFile as string ) as boolean
dim sFile as string : sFile = convertToURL( convertpath( cFile ) )
const CFN = "global::tools::inc::t_files.inc::hFileSaveAsKill():"
hFileSaveAsKill() = FALSE
if ( VERBOSE ) then printlog( CFN & "Save, replacing: " & sFile )
FileSaveAs( "URL", sFile, "Overwrite", TRUE )
if ( hFileWait( TRUE ) >= 0 ) then hFileSaveAsKill() = TRUE
end function
'
'-------------------------------------------------------------------------------
'
function hFileSaveAsKillWithPassword( cFile as string, cPassword as string ) as boolean
dim sFile as string : sFile = convertToURL( convertpath( cFile ) )
const CFN = "global::tools::inc::t_files.inc::hFileSaveAsKillWithPassword():"
hFileSaveAsKillWithPassword() = FALSE
if ( VERBOSE ) then printlog( CFN & "Save with password, replacing: " & sFile & "::" & cPassword )
FileSaveAs( "URL", sFile, "Overwrite", TRUE, "Password", cPassword )
if ( hFileWait( TRUE ) >= 0 ) then hFileSaveAsKillWithPassword() = TRUE
end function
'
'-------------------------------------------------------------------------------
'
function hFileSaveAsWithFilter( cFile as string, cFilter as string ) as boolean
dim sFile as string : sFile = convertToURL( convertpath( cFile ) )
const CFN = "global::tools::inc::t_files.inc::hFileSaveAsWithFilter():"
hFileSaveAsWithFilter() = FALSE
if ( VERBOSE ) then printlog( CFN & "Save with filter: " & sFile & "::" & cFilter )
FileSaveAs( "URL", sFile, "FilterName", cFilter, "Overwrite", FALSE )
if ( hFileWait( TRUE ) >= 0 ) then hFileSaveAsWithFilter() = TRUE
end function
'
'-------------------------------------------------------------------------------
'
function hFileSaveAsWithFilterKill( cFile as string, cFilter as string ) as boolean
dim sFile as string : sFile = convertToURL( convertpath( cFile ) )
const CFN = "global::tools::inc::t_files.inc::hFileSaveAsWithFilterKill():"
hFileSaveAsWithFilterKill() = FALSE
if ( VERBOSE ) then printlog( CFN & "Save with filter, replacing: " & sFile & "::" & cFilter )
FileSaveAs( "URL", sFile, "FilterName", cFilter, "Overwrite", TRUE )
if ( hFileWait( TRUE ) >= 0 ) then hFileSaveAsWithFilterKill() = TRUE
end function
'
'-------------------------------------------------------------------------------
'
function hFileWait( optional bWarn as boolean ) as integer
' Wait max 10 seconds for the FileOpen/FileSave slot to finish
' Returns the time it took the slot to finish
' Negative returnvalues are given on timeout or any blocking dialog
const CFN = "global::tools::inc::t_files.inc::hFileWait():"
const MAX_WAIT = 10
dim iWait as integer : iWait = 0
dim bWarnlog as boolean
if ( IsMissing( bWarn ) ) then
bWarnlog = TRUE
else
bWarnlog = bWarn
endif
do while( WaitSlot() <> WSFinished )
iWait = iWait + 1
' This is the timeout
if ( iWait = MAX_WAIT ) then
iWait = -1
exit do
endif
' LOAD: Security warning prevents slot from finishing
kontext "SecurityWarning"
if ( SecurityWarning.exists() ) then
iWait = -2
exit do
endif
' LOAD: Password dialog
kontext "PasswordFileOpen"
if ( PasswordFileOpen.exists() ) then
iWait = -3
exit do
endif
' SAVE: Password dialog
kontext "PasswordDlg"
if ( PasswordDlg.exists() ) then
iWait = -4
exit do
endif
' LOAD: Master Password Dialog
kontext "MasterPasswordEnter"
if ( MasterPasswordEnter.exists() ) then
iWait = -10
warnlog( CFN & "Master Password dialog displayed. Tests are likely to fail" )
exit do
endif
' LOAD: Filter selection dialog
Kontext "Filterauswahl"
if ( FilterAuswahl.exists() ) then
iWait = -5
exit do
endif
' LOAD: ASCII Filter Options dialog
kontext "ASCIIFilterOptionen"
if AsciiFilterOptionen.Exists() then
iWait = -6
exit do
end if
' LOAD/SAVE: Some other dialogs that may interrupt file I/O
kontext "Active"
if ( Active.exists() ) then
printlog( Active.getText() )
' This is most likely a warning
if ( Active.getButtonCount() = 1 ) then
iWait = -7
exit do
endif
' This is probably the update links dialog
if ( Active.getButtonCount() = 2 ) then
iWait = -8
exit do
endif
' This is probably the styles not matching dialog
if ( Active.getButtonCount() = 3 ) then
iWait = -9
exit do
endif
endif
loop
if ( VERBOSE ) then
select case iWait
case -1 : printlog( CFN & "Timeout reached, rc = " & iWait )
case -2 : printlog( CFN & "Macro security warning displayed, rc = " & iWait )
case -3 : printlog( CFN & "Password dialog (load) displayed, rc = " & iWait )
case -4 : printlog( CFN & "Password dialog (save) displayed, rc = " & iWait )
case -5 : printlog( CFN & "Filter Selection dialog displayed, rc = " & iWait )
case -6 : printlog( CFN & "ASCII filter options dialog displayed, rc = " & iWait )
case -7 : printlog( CFN & "A dialog box is in the way (1 button), rc = " & iWait )
case -8 : printlog( CFN & "A dialog box is in the way (2 buttons), rc = " & iWait )
case -9 : printlog( CFN & "A dialog box is in the way (3 buttons), rc = " & iWait )
case -10 : printlog( CFN & "Master Password Dialog displayed, rc = " & iWait )
case else : printlog( CFN & "File I/O completed in " & iWait & " seconds" )
end select
endif
if ( bWarnlog and ( iWait < 0 ) ) then
warnlog( CFN & "The messagebox was not expected at this point" )
endif
hFileWait() = iWait
end function
|