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
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* 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 .
*/
#include "updatehdl.hxx"
#include <helpids.h>
#include <osl/diagnose.h>
#include <osl/file.hxx>
#include <rtl/ustring.hxx>
#include <com/sun/star/uno/Sequence.h>
#include <com/sun/star/awt/ActionEvent.hpp>
#include <com/sun/star/awt/PushButtonType.hpp>
#include <com/sun/star/awt/UnoControlDialog.hpp>
#include <com/sun/star/awt/VclWindowPeerAttribute.hpp>
#include <com/sun/star/awt/WindowAttribute.hpp>
#include <com/sun/star/awt/XButton.hpp>
#include <com/sun/star/awt/XControl.hpp>
#include <com/sun/star/awt/XControlContainer.hpp>
#include <com/sun/star/awt/XMessageBox.hpp>
#include <com/sun/star/awt/XAnimation.hpp>
#include <com/sun/star/awt/XTopWindow.hpp>
#include <com/sun/star/awt/XVclWindowPeer.hpp>
#include <com/sun/star/awt/XVclContainer.hpp>
#include <com/sun/star/awt/XWindow.hpp>
#include <com/sun/star/awt/XWindow2.hpp>
#include <com/sun/star/beans/PropertyValue.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/configuration/theDefaultProvider.hpp>
#include <com/sun/star/container/XNameContainer.hpp>
#include <com/sun/star/frame/Desktop.hpp>
#include <com/sun/star/frame/TerminationVetoException.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/task/InteractionHandler.hpp>
#include <com/sun/star/task/InteractionRequestStringResolver.hpp>
#include <strings.hrc>
#include <unotools/resmgr.hxx>
#include <tools/urlobj.hxx>
#include <tools/diagnose_ex.h>
#define COMMAND_CLOSE "close"
#define CTRL_THROBBER "throbber"
#define CTRL_PROGRESS "progress"
#define TEXT_STATUS "text_status"
#define TEXT_PERCENT "text_percent"
#define TEXT_DESCRIPTION "text_description"
#define FIXED_LINE_MODEL "com.sun.star.awt.UnoControlFixedLineModel"
#define FIXED_TEXT_MODEL "com.sun.star.awt.UnoControlFixedTextModel"
#define EDIT_FIELD_MODEL "com.sun.star.awt.UnoControlEditModel"
#define BUTTON_MODEL "com.sun.star.awt.UnoControlButtonModel"
#define GROUP_BOX_MODEL "com.sun.star.awt.UnoControlGroupBoxModel"
using namespace com::sun::star;
UpdateHandler::UpdateHandler( const uno::Reference< uno::XComponentContext > & rxContext,
const rtl::Reference< IActionListener > & rxActionListener ) :
mxContext( rxContext ),
mxActionListener( rxActionListener ),
meCurState( UPDATESTATES_COUNT ),
meLastState( UPDATESTATES_COUNT ),
mnPercent( 0 ),
mnLastCtrlState( -1 ),
mbDownloadBtnHasDots( false ),
mbVisible( false ),
mbStringsLoaded( false ),
mbMinimized( false ),
mbListenerAdded(false),
mbShowsMessageBox(false)
{
}
UpdateHandler::~UpdateHandler()
{
mxContext = nullptr;
mxUpdDlg = nullptr;
mxInteractionHdl = nullptr;
mxActionListener = nullptr;
}
void UpdateHandler::enableControls( short nCtrlState )
{
osl::MutexGuard aGuard( maMutex );
if ( nCtrlState == mnLastCtrlState )
return;
// the help button should always be the last button in the
// enum list and must never be disabled
for ( int i=0; i<HELP_BUTTON; i++ )
{
short nCurStateVal = static_cast<short>(nCtrlState >> i);
short nOldStateVal = static_cast<short>(mnLastCtrlState >> i);
if ( ( nCurStateVal & 0x01 ) != ( nOldStateVal & 0x01 ) )
{
bool bEnableControl = ( ( nCurStateVal & 0x01 ) == 0x01 );
setControlProperty( msButtonIDs[i], "Enabled", uno::Any( bEnableControl ) );
}
}
mnLastCtrlState = nCtrlState;
}
void UpdateHandler::setDownloadBtnLabel( bool bAppendDots )
{
osl::MutexGuard aGuard( maMutex );
if ( mbDownloadBtnHasDots != bAppendDots )
{
OUString aLabel( msDownload );
if ( bAppendDots )
aLabel += "...";
setControlProperty( msButtonIDs[DOWNLOAD_BUTTON], "Label", uno::Any( aLabel ) );
setControlProperty( msButtonIDs[DOWNLOAD_BUTTON], "HelpURL", uno::makeAny<OUString>( INET_HID_SCHEME HID_CHECK_FOR_UPD_DOWNLOAD2 ) );
mbDownloadBtnHasDots = bAppendDots;
}
}
void UpdateHandler::setState( UpdateState eState )
{
osl::MutexGuard aGuard( maMutex );
meCurState = eState;
if ( mxUpdDlg.is() && mbVisible )
updateState( meCurState );
}
bool UpdateHandler::isVisible() const
{
if ( !mxUpdDlg.is() ) return false;
uno::Reference< awt::XWindow2 > xWindow( mxUpdDlg, uno::UNO_QUERY );
if ( xWindow.is() )
return xWindow->isVisible();
else
return false;
}
void UpdateHandler::setVisible( bool bVisible )
{
osl::MutexGuard aGuard( maMutex );
mbVisible = bVisible;
if ( bVisible )
{
if ( !mxUpdDlg.is() )
createDialog();
// this should never happen, but if it happens we better return here
if ( !mxUpdDlg.is() )
return;
updateState( meCurState );
uno::Reference< awt::XWindow > xWindow( mxUpdDlg, uno::UNO_QUERY );
if ( xWindow.is() )
xWindow->setVisible( bVisible );
uno::Reference< awt::XTopWindow > xTopWindow( mxUpdDlg, uno::UNO_QUERY );
if ( xTopWindow.is() )
{
xTopWindow->toFront();
if ( !mbListenerAdded )
{
xTopWindow->addTopWindowListener( this );
mbListenerAdded = true;
}
}
}
else if ( mxUpdDlg.is() )
{
uno::Reference< awt::XWindow > xWindow( mxUpdDlg, uno::UNO_QUERY );
if ( xWindow.is() )
xWindow->setVisible( bVisible );
}
}
void UpdateHandler::setProgress( sal_Int32 nPercent )
{
if ( nPercent > 100 )
nPercent = 100;
else if ( nPercent < 0 )
nPercent = 0;
if ( nPercent != mnPercent )
{
osl::MutexGuard aGuard( maMutex );
mnPercent = nPercent;
setControlProperty( CTRL_PROGRESS, "ProgressValue", uno::Any( nPercent ) );
setControlProperty( TEXT_PERCENT, "Text", uno::Any( substVariables(msPercent) ) );
}
}
void UpdateHandler::setErrorMessage( const OUString& rErrorMsg )<--- The function 'setErrorMessage' is never used.
{
setControlProperty( TEXT_DESCRIPTION, "Text", uno::Any( rErrorMsg ) );
}
void UpdateHandler::setDownloadFile( const OUString& rFilePath )<--- The function 'setDownloadFile' is never used.
{
sal_Int32 nLast = rFilePath.lastIndexOf( '/' );
if ( nLast != -1 )
{
msDownloadFile = rFilePath.copy( nLast+1 );
const OUString aDownloadURL = rFilePath.copy( 0, nLast );
osl::FileBase::getSystemPathFromFileURL( aDownloadURL, msDownloadPath );
}
}
OUString UpdateHandler::getBubbleText( UpdateState eState )<--- The function 'getBubbleText' is never used.
{
osl::MutexGuard aGuard( maMutex );
OUString sText;
sal_Int32 nIndex = static_cast<sal_Int32>(eState);
loadStrings();
if ( ( UPDATESTATE_UPDATE_AVAIL <= nIndex ) && ( nIndex < UPDATESTATES_COUNT ) )
sText = substVariables( msBubbleTexts[ nIndex - UPDATESTATE_UPDATE_AVAIL ] );
return sText;
}
OUString UpdateHandler::getBubbleTitle( UpdateState eState )<--- The function 'getBubbleTitle' is never used.
{
osl::MutexGuard aGuard( maMutex );
OUString sText;
sal_Int32 nIndex = static_cast<sal_Int32>(eState);
loadStrings();
if ( ( UPDATESTATE_UPDATE_AVAIL <= nIndex ) && ( nIndex < UPDATESTATES_COUNT ) )
sText = substVariables( msBubbleTitles[ nIndex - UPDATESTATE_UPDATE_AVAIL] );
return sText;
}
OUString UpdateHandler::getDefaultInstErrMsg()<--- The function 'getDefaultInstErrMsg' is never used.
{
osl::MutexGuard aGuard( maMutex );
loadStrings();
return substVariables( msInstallError );
}
// XActionListener
void SAL_CALL UpdateHandler::disposing( const lang::EventObject& rEvt )
{
if ( rEvt.Source == mxUpdDlg )
mxUpdDlg.clear();
}
void SAL_CALL UpdateHandler::actionPerformed( awt::ActionEvent const & rEvent )
{
DialogControls eButton = BUTTON_COUNT;
for ( int i = 0; i < BUTTON_COUNT; i++ )
{
if ( rEvent.ActionCommand == msButtonIDs[i] )
{
eButton = static_cast<DialogControls>(i);
break;
}
}
if ( rEvent.ActionCommand == COMMAND_CLOSE )
{
if ( ( mnLastCtrlState & ( 1 << CLOSE_BUTTON ) ) == ( 1 << CLOSE_BUTTON ) )
eButton = CLOSE_BUTTON;
else
eButton = CANCEL_BUTTON;
}
switch ( eButton ) {
case CANCEL_BUTTON:
{
bool bCancel = true;
if ( ( meCurState == UPDATESTATE_DOWNLOADING ) ||
( meCurState == UPDATESTATE_DOWNLOAD_PAUSED ) ||
( meCurState == UPDATESTATE_ERROR_DOWNLOADING ) )
bCancel = showWarning( msCancelMessage );
if ( bCancel )
{
mxActionListener->cancel();
setVisible( false );
}
break;
}
case CLOSE_BUTTON:
setVisible( false );
if ( meCurState == UPDATESTATE_ERROR_CHECKING )
mxActionListener->closeAfterFailure();
break;
case DOWNLOAD_BUTTON:
mxActionListener->download();
break;
case INSTALL_BUTTON:
if ( showWarning( msInstallMessage ) )
mxActionListener->install();
break;
case PAUSE_BUTTON:
mxActionListener->pause();
break;
case RESUME_BUTTON:
mxActionListener->resume();
break;
case HELP_BUTTON:
break;
default:
OSL_FAIL( "UpdateHandler::actionPerformed: unknown command!" );
}
}
// XTopWindowListener
void SAL_CALL UpdateHandler::windowOpened( const lang::EventObject& )
{
}
void SAL_CALL UpdateHandler::windowClosing( const lang::EventObject& e )
{
awt::ActionEvent aActionEvt;
aActionEvt.ActionCommand = COMMAND_CLOSE;
aActionEvt.Source = e.Source;
actionPerformed( aActionEvt );
}
void SAL_CALL UpdateHandler::windowClosed( const lang::EventObject& )
{
}
void SAL_CALL UpdateHandler::windowMinimized( const lang::EventObject& )
{
mbMinimized = true;
}
void SAL_CALL UpdateHandler::windowNormalized( const lang::EventObject& )
{
mbMinimized = false;
}
void SAL_CALL UpdateHandler::windowActivated( const lang::EventObject& )
{
}
void SAL_CALL UpdateHandler::windowDeactivated( const lang::EventObject& )
{
}
// XInteractionHandler
void SAL_CALL UpdateHandler::handle( uno::Reference< task::XInteractionRequest > const & rRequest)
{
if ( !mxInteractionHdl.is() )
{
if( !mxContext.is() )
throw uno::RuntimeException( "UpdateHandler:: empty component context", *this );
uno::Reference< lang::XMultiComponentFactory > xServiceManager(mxContext->getServiceManager());
if( !xServiceManager.is() )
throw uno::RuntimeException( "UpdateHandler: unable to obtain service manager from component context", *this );
mxInteractionHdl.set(
task::InteractionHandler::createWithParent(mxContext, nullptr),
uno::UNO_QUERY_THROW);
}
uno::Reference< task::XInteractionRequestStringResolver > xStrResolver =
task::InteractionRequestStringResolver::create( mxContext );
beans::Optional< OUString > aErrorText = xStrResolver->getStringFromInformationalRequest( rRequest );
if ( aErrorText.IsPresent )
{
setControlProperty( TEXT_DESCRIPTION, "Text", uno::Any( aErrorText.Value ) );
uno::Sequence< uno::Reference< task::XInteractionContinuation > > xContinuations = rRequest->getContinuations();
if ( xContinuations.getLength() == 1 )
{
if ( meCurState == UPDATESTATE_CHECKING )
setState( UPDATESTATE_ERROR_CHECKING );
else if ( meCurState == UPDATESTATE_DOWNLOADING )
setState( UPDATESTATE_ERROR_DOWNLOADING );
xContinuations[0]->select();
}
else
mxInteractionHdl->handle( rRequest );
}
else
mxInteractionHdl->handle( rRequest );
}
// XTerminateListener
void SAL_CALL UpdateHandler::queryTermination( const lang::EventObject& )
{
if ( mbShowsMessageBox )
{
uno::Reference< awt::XTopWindow > xTopWindow( mxUpdDlg, uno::UNO_QUERY );
if ( xTopWindow.is() )
xTopWindow->toFront();
throw frame::TerminationVetoException(
"The office cannot be closed while displaying a warning!",
static_cast<frame::XTerminateListener*>(this));
}
else
setVisible( false );
}
void SAL_CALL UpdateHandler::notifyTermination( const lang::EventObject& )
{
osl::MutexGuard aGuard( maMutex );
if ( mxUpdDlg.is() )
{
uno::Reference< awt::XTopWindow > xTopWindow( mxUpdDlg, uno::UNO_QUERY );
if ( xTopWindow.is() )
xTopWindow->removeTopWindowListener( this );
uno::Reference< lang::XComponent > xComponent( mxUpdDlg, uno::UNO_QUERY );
if ( xComponent.is() )
xComponent->dispose();
mxUpdDlg.clear();
}
}
void UpdateHandler::updateState( UpdateState eState )
{
if ( meLastState == eState )
return;
OUString sText;
switch ( eState )
{
case UPDATESTATE_CHECKING:
showControls( (1<<CANCEL_BUTTON) + (1<<THROBBER_CTRL) );
enableControls( 1<<CANCEL_BUTTON );
setControlProperty( TEXT_STATUS, "Text", uno::Any( substVariables(msChecking) ) );
setControlProperty( TEXT_DESCRIPTION, "Text", uno::Any( OUString() ) );
focusControl( CANCEL_BUTTON );
break;
case UPDATESTATE_ERROR_CHECKING:
showControls( 0 );
enableControls( 1 << CLOSE_BUTTON );
setControlProperty( TEXT_STATUS, "Text", uno::Any( substVariables(msCheckingError) ) );
focusControl( CLOSE_BUTTON );
break;
case UPDATESTATE_UPDATE_AVAIL:
showControls( 0 );
enableControls( ( 1 << CLOSE_BUTTON ) + ( 1 << DOWNLOAD_BUTTON ) );
setControlProperty( TEXT_STATUS, "Text", uno::Any( substVariables(msUpdFound) ) );
sText = substVariables(msDownloadWarning);
if ( !msDescriptionMsg.isEmpty() )
sText += "\n\n" + msDescriptionMsg;
setControlProperty( TEXT_DESCRIPTION, "Text", uno::Any( sText ) );
setDownloadBtnLabel( false );
focusControl( DOWNLOAD_BUTTON );
break;
case UPDATESTATE_UPDATE_NO_DOWNLOAD:
showControls( 0 );
enableControls( ( 1 << CLOSE_BUTTON ) + ( 1 << DOWNLOAD_BUTTON ) );
setControlProperty( TEXT_STATUS, "Text", uno::Any( substVariables(msUpdFound) ) );
sText = substVariables(msDownloadNotAvail);
if ( !msDescriptionMsg.isEmpty() )
sText += "\n\n" + msDescriptionMsg;
setControlProperty( TEXT_DESCRIPTION, "Text", uno::Any( sText ) );
setDownloadBtnLabel( true );
focusControl( DOWNLOAD_BUTTON );
break;
case UPDATESTATE_NO_UPDATE_AVAIL:
case UPDATESTATE_EXT_UPD_AVAIL: // will only be set, when there are no office updates avail
showControls( 0 );
enableControls( 1 << CLOSE_BUTTON );
setControlProperty( TEXT_STATUS, "Text", uno::Any( substVariables(msNoUpdFound) ) );
setControlProperty( TEXT_DESCRIPTION, "Text", uno::Any( OUString() ) );
focusControl( CLOSE_BUTTON );
break;
case UPDATESTATE_DOWNLOADING:
showControls( (1<<PROGRESS_CTRL) + (1<<CANCEL_BUTTON) + (1<<PAUSE_BUTTON) + (1<<RESUME_BUTTON) );
enableControls( (1<<CLOSE_BUTTON) + (1<<CANCEL_BUTTON) + (1<<PAUSE_BUTTON) );
setControlProperty( TEXT_STATUS, "Text", uno::Any( substVariables(msDownloading) ) );
setControlProperty( TEXT_PERCENT, "Text", uno::Any( substVariables(msPercent) ) );
setControlProperty( TEXT_DESCRIPTION, "Text", uno::Any( substVariables(msDownloadWarning) ) );
setControlProperty( CTRL_PROGRESS, "ProgressValue", uno::Any( mnPercent ) );
focusControl( CLOSE_BUTTON );
break;
case UPDATESTATE_DOWNLOAD_PAUSED:
showControls( (1<<PROGRESS_CTRL) + (1<<CANCEL_BUTTON) + (1<<PAUSE_BUTTON) + (1<<RESUME_BUTTON) );
enableControls( (1<<CLOSE_BUTTON) + (1<<CANCEL_BUTTON) + (1<<RESUME_BUTTON) );
setControlProperty( TEXT_STATUS, "Text", uno::Any( substVariables(msDownloadPause) ) );
setControlProperty( TEXT_PERCENT, "Text", uno::Any( substVariables(msPercent) ) );
setControlProperty( TEXT_DESCRIPTION, "Text", uno::Any( substVariables(msDownloadWarning) ) );
setControlProperty( CTRL_PROGRESS, "ProgressValue", uno::Any( mnPercent ) );
focusControl( CLOSE_BUTTON );
break;
case UPDATESTATE_ERROR_DOWNLOADING:
showControls( (1<<PROGRESS_CTRL) + (1<<CANCEL_BUTTON) + (1<<PAUSE_BUTTON) + (1<<RESUME_BUTTON) );
enableControls( (1<<CLOSE_BUTTON) + (1<<CANCEL_BUTTON) );
setControlProperty( TEXT_STATUS, "Text", uno::Any( substVariables(msDownloadError) ) );
focusControl( CLOSE_BUTTON );
break;
case UPDATESTATE_DOWNLOAD_AVAIL:
showControls( 0 );
enableControls( (1<<CLOSE_BUTTON) + (1<<INSTALL_BUTTON) );
setControlProperty( TEXT_STATUS, "Text", uno::Any( substVariables(msReady2Install) ) );
setControlProperty( TEXT_DESCRIPTION, "Text", uno::Any( substVariables(msDownloadDescr) ) );
focusControl( INSTALL_BUTTON );
break;
case UPDATESTATE_AUTO_START:
case UPDATESTATES_COUNT:
//do nothing, only count!
break;
}
meLastState = eState;
}
OUString UpdateHandler::loadString(const std::locale& rLocale,
const char* pResourceId)
{
return Translate::get(pResourceId, rLocale);
}
OUString UpdateHandler::substVariables( const OUString &rSource ) const
{
return rSource
.replaceAll( "%NEXTVERSION", msNextVersion )
.replaceAll( "%DOWNLOAD_PATH", msDownloadPath )
.replaceAll( "%FILE_NAME", msDownloadFile )
.replaceAll( "%PERCENT", OUString::number( mnPercent ) );
}
void UpdateHandler::loadStrings()
{
if ( mbStringsLoaded )
return;
else
mbStringsLoaded = true;
std::locale loc = Translate::Create("pcr");
msChecking = loadString( loc, RID_UPDATE_STR_CHECKING );
msCheckingError = loadString( loc, RID_UPDATE_STR_CHECKING_ERR );
msNoUpdFound = loadString( loc, RID_UPDATE_STR_NO_UPD_FOUND );
msUpdFound = loadString( loc, RID_UPDATE_STR_UPD_FOUND );
setFullVersion( msUpdFound );
msDlgTitle = loadString( loc, RID_UPDATE_STR_DLG_TITLE );
msDownloadPause = loadString( loc, RID_UPDATE_STR_DOWNLOAD_PAUSE );
msDownloadError = loadString( loc, RID_UPDATE_STR_DOWNLOAD_ERR );
msDownloadWarning = loadString( loc, RID_UPDATE_STR_DOWNLOAD_WARN );
msDownloadDescr = loadString( loc, RID_UPDATE_STR_DOWNLOAD_DESCR );
msDownloadNotAvail = loadString( loc, RID_UPDATE_STR_DOWNLOAD_UNAVAIL );
msDownloading = loadString( loc, RID_UPDATE_STR_DOWNLOADING );
msReady2Install = loadString( loc, RID_UPDATE_STR_READY_INSTALL );
msCancelMessage = loadString( loc, RID_UPDATE_STR_CANCEL_DOWNLOAD );
msInstallMessage = loadString( loc, RID_UPDATE_STR_BEGIN_INSTALL );
msInstallError = loadString( loc, RID_UPDATE_STR_INSTALL_ERROR );
msOverwriteWarning = loadString( loc, RID_UPDATE_STR_OVERWRITE_WARNING );
msPercent = loadString( loc, RID_UPDATE_STR_PERCENT );
msReloadWarning = loadString( loc, RID_UPDATE_STR_RELOAD_WARNING );
msReloadReload = loadString( loc, RID_UPDATE_STR_RELOAD_RELOAD );
msReloadContinue = loadString( loc, RID_UPDATE_STR_RELOAD_CONTINUE );
msStatusFL = loadString( loc, RID_UPDATE_FT_STATUS );
msDescription = loadString( loc, RID_UPDATE_FT_DESCRIPTION );
msClose = loadString( loc, RID_UPDATE_BTN_CLOSE );
msDownload = loadString( loc, RID_UPDATE_BTN_DOWNLOAD );
msInstall = loadString( loc, RID_UPDATE_BTN_INSTALL );
msPauseBtn = loadString( loc, RID_UPDATE_BTN_PAUSE );
msResumeBtn = loadString( loc, RID_UPDATE_BTN_RESUME );
msCancelBtn = loadString( loc, RID_UPDATE_BTN_CANCEL );
std::pair<const char*, const char*> RID_UPDATE_BUBBLE[] =
{
{ RID_UPDATE_BUBBLE_UPDATE_AVAIL, RID_UPDATE_BUBBLE_T_UPDATE_AVAIL },
{ RID_UPDATE_BUBBLE_UPDATE_NO_DOWN, RID_UPDATE_BUBBLE_T_UPDATE_NO_DOWN },
{ RID_UPDATE_BUBBLE_AUTO_START, RID_UPDATE_BUBBLE_T_AUTO_START },
{ RID_UPDATE_BUBBLE_DOWNLOADING, RID_UPDATE_BUBBLE_T_DOWNLOADING },
{ RID_UPDATE_BUBBLE_DOWNLOAD_PAUSED, RID_UPDATE_BUBBLE_T_DOWNLOAD_PAUSED },
{ RID_UPDATE_BUBBLE_ERROR_DOWNLOADING, RID_UPDATE_BUBBLE_T_ERROR_DOWNLOADING },
{ RID_UPDATE_BUBBLE_DOWNLOAD_AVAIL, RID_UPDATE_BUBBLE_T_DOWNLOAD_AVAIL },
{ RID_UPDATE_BUBBLE_EXT_UPD_AVAIL, RID_UPDATE_BUBBLE_T_EXT_UPD_AVAIL }
};
static_assert(SAL_N_ELEMENTS(RID_UPDATE_BUBBLE) == UPDATESTATES_COUNT - UPDATESTATE_UPDATE_AVAIL, "mismatch");
// all update states before UPDATESTATE_UPDATE_AVAIL don't have a bubble
// so we can ignore them
for (size_t i = 0; i < SAL_N_ELEMENTS(RID_UPDATE_BUBBLE); ++i)
{
msBubbleTexts[i] = loadString(loc, RID_UPDATE_BUBBLE[i].first);
msBubbleTitles[i] = loadString(loc, RID_UPDATE_BUBBLE[i].second);
}
for ( int i=0; i < BUTTON_COUNT; i++ )
{
msButtonIDs[ i ] = "BUTTON_" + OUString::number( i );
}
}
void UpdateHandler::startThrobber( bool bStart )
{
uno::Reference< awt::XControlContainer > xContainer( mxUpdDlg, uno::UNO_QUERY );
uno::Reference< awt::XAnimation > xThrobber( xContainer->getControl( CTRL_THROBBER ), uno::UNO_QUERY );
if ( xThrobber.is() )
{
if ( bStart )
xThrobber->startAnimation();
else
xThrobber->stopAnimation();
}
uno::Reference< awt::XWindow > xWindow( xContainer->getControl( CTRL_THROBBER ), uno::UNO_QUERY );
if (xWindow.is() )
xWindow->setVisible( bStart );
}
void UpdateHandler::setControlProperty( const OUString &rCtrlName,
const OUString &rPropName,
const uno::Any &rPropValue )
{
if ( !mxUpdDlg.is() ) return;
uno::Reference< awt::XControlContainer > xContainer( mxUpdDlg, uno::UNO_QUERY );
uno::Reference< awt::XControl > xControl( xContainer->getControl( rCtrlName ), uno::UNO_SET_THROW );
uno::Reference< awt::XControlModel > xControlModel( xControl->getModel(), uno::UNO_SET_THROW );
uno::Reference< beans::XPropertySet > xPropSet( xControlModel, uno::UNO_QUERY_THROW );
try {
xPropSet->setPropertyValue( rPropName, rPropValue );
}
catch( const beans::UnknownPropertyException& )
{
TOOLS_WARN_EXCEPTION( "extensions.update", "UpdateHandler::setControlProperty" );
}
}
void UpdateHandler::showControl( const OUString &rCtrlName, bool bShow )
{
uno::Reference< awt::XControlContainer > xContainer( mxUpdDlg, uno::UNO_QUERY );
if ( !xContainer.is() )
{
OSL_FAIL( "UpdateHandler::showControl: could not get control container!" );
return;
}
uno::Reference< awt::XWindow > xWindow( xContainer->getControl( rCtrlName ), uno::UNO_QUERY );
if ( xWindow.is() )
xWindow->setVisible( bShow );
}
void UpdateHandler::focusControl( DialogControls eID )
{
uno::Reference< awt::XControlContainer > xContainer( mxUpdDlg, uno::UNO_QUERY );
if ( !xContainer.is() )
{
OSL_FAIL( "UpdateHandler::focusControl: could not get control container!" );
return;
}
OSL_ENSURE( (eID < BUTTON_COUNT), "UpdateHandler::focusControl: id too big!" );
uno::Reference< awt::XWindow > xWindow( xContainer->getControl( msButtonIDs[static_cast<short>(eID)] ), uno::UNO_QUERY );
if ( xWindow.is() )
xWindow->setFocus();
}
void UpdateHandler::insertControlModel( uno::Reference< awt::XControlModel > const & rxDialogModel,
OUString const & rServiceName,
OUString const & rControlName,
awt::Rectangle const & rPosSize,
uno::Sequence< beans::NamedValue > const & rProps )
{
uno::Reference< lang::XMultiServiceFactory > xFactory (rxDialogModel, uno::UNO_QUERY_THROW);
uno::Reference< awt::XControlModel > xModel (xFactory->createInstance (rServiceName), uno::UNO_QUERY_THROW);
uno::Reference< beans::XPropertySet > xPropSet (xModel, uno::UNO_QUERY_THROW);
for (beans::NamedValue const & prop : rProps)
{
xPropSet->setPropertyValue (prop.Name, prop.Value);
}
// @see awt/UnoControlDialogElement.idl
xPropSet->setPropertyValue( "Name", uno::Any (rControlName) );
xPropSet->setPropertyValue( "PositionX", uno::Any (rPosSize.X) );
xPropSet->setPropertyValue( "PositionY", uno::Any (rPosSize.Y) );
xPropSet->setPropertyValue( "Height", uno::Any (rPosSize.Height) );
xPropSet->setPropertyValue( "Width", uno::Any (rPosSize.Width) );
// insert by Name into DialogModel container
uno::Reference< container::XNameContainer > xContainer (rxDialogModel, uno::UNO_QUERY_THROW);
xContainer->insertByName( rControlName, uno::Any (uno::Reference< uno::XInterface >(xModel, uno::UNO_QUERY)));
}
void UpdateHandler::setFullVersion( OUString& rString )
{
uno::Reference< lang::XMultiServiceFactory > xConfigurationProvider(
css::configuration::theDefaultProvider::get( mxContext ) );
beans::PropertyValue aProperty;
aProperty.Name = "nodepath";
aProperty.Value <<= OUString("org.openoffice.Setup/Product");
uno::Sequence< uno::Any > aArgumentList( 1 );
aArgumentList[0] <<= aProperty;
uno::Reference< uno::XInterface > xConfigAccess = xConfigurationProvider->createInstanceWithArguments( "com.sun.star.configuration.ConfigurationAccess",
aArgumentList );
uno::Reference< container::XNameAccess > xNameAccess( xConfigAccess, uno::UNO_QUERY_THROW );
OUString aProductVersion;
xNameAccess->getByName("ooSetupVersion") >>= aProductVersion;
OUString aProductFullVersion;
xNameAccess->getByName("ooSetupVersionAboutBox") >>= aProductFullVersion;
rString = rString.replaceFirst( aProductVersion, aProductFullVersion );
}
bool UpdateHandler::showWarning( const OUString &rWarningText ) const
{
bool bRet = false;
uno::Reference< awt::XControl > xControl( mxUpdDlg, uno::UNO_QUERY );
if ( !xControl.is() ) return bRet;
uno::Reference< awt::XWindowPeer > xPeer = xControl->getPeer();
if ( !xPeer.is() ) return bRet;
uno::Reference< awt::XToolkit > xToolkit = xPeer->getToolkit();
if ( !xToolkit.is() ) return bRet;
awt::WindowDescriptor aDescriptor;
sal_Int32 nWindowAttributes = awt::WindowAttribute::BORDER | awt::WindowAttribute::MOVEABLE | awt::WindowAttribute::CLOSEABLE;
nWindowAttributes |= awt::VclWindowPeerAttribute::YES_NO;
nWindowAttributes |= awt::VclWindowPeerAttribute::DEF_NO;
aDescriptor.Type = awt::WindowClass_MODALTOP;
aDescriptor.WindowServiceName = "warningbox";
aDescriptor.ParentIndex = -1;
aDescriptor.Parent = xPeer;
aDescriptor.Bounds = awt::Rectangle( 10, 10, 250, 150 );
aDescriptor.WindowAttributes = nWindowAttributes;
uno::Reference< awt::XMessageBox > xMsgBox( xToolkit->createWindow( aDescriptor ), uno::UNO_QUERY );
if ( xMsgBox.is() )
{
mbShowsMessageBox = true;
sal_Int16 nRet;
// xMsgBox->setCaptionText( msCancelTitle );
xMsgBox->setMessageText( rWarningText );
nRet = xMsgBox->execute();
if ( nRet == 2 ) // RET_YES == 2
bRet = true;
mbShowsMessageBox = false;
}
uno::Reference< lang::XComponent > xComponent( xMsgBox, uno::UNO_QUERY );
if ( xComponent.is() )
xComponent->dispose();
return bRet;
}
bool UpdateHandler::showWarning( const OUString &rWarningText,
const OUString &rBtnText_1,
const OUString &rBtnText_2 ) const
{
bool bRet = false;
uno::Reference< awt::XControl > xControl( mxUpdDlg, uno::UNO_QUERY );
if ( !xControl.is() ) return bRet;
uno::Reference< awt::XWindowPeer > xPeer = xControl->getPeer();
if ( !xPeer.is() ) return bRet;
uno::Reference< awt::XToolkit > xToolkit = xPeer->getToolkit();
if ( !xToolkit.is() ) return bRet;
awt::WindowDescriptor aDescriptor;
sal_Int32 nWindowAttributes = awt::WindowAttribute::BORDER | awt::WindowAttribute::MOVEABLE | awt::WindowAttribute::CLOSEABLE;
nWindowAttributes |= awt::VclWindowPeerAttribute::YES_NO;
nWindowAttributes |= awt::VclWindowPeerAttribute::DEF_NO;
aDescriptor.Type = awt::WindowClass_MODALTOP;
aDescriptor.WindowServiceName = "warningbox";
aDescriptor.ParentIndex = -1;
aDescriptor.Parent = xPeer;
aDescriptor.Bounds = awt::Rectangle( 10, 10, 250, 150 );
aDescriptor.WindowAttributes = nWindowAttributes;
uno::Reference< awt::XMessageBox > xMsgBox( xToolkit->createWindow( aDescriptor ), uno::UNO_QUERY );
if ( xMsgBox.is() )
{
uno::Reference< awt::XVclContainer > xMsgBoxCtrls( xMsgBox, uno::UNO_QUERY );
if ( xMsgBoxCtrls.is() )
{
uno::Sequence< uno::Reference< awt::XWindow > > xChildren = xMsgBoxCtrls->getWindows();
for ( uno::Reference< awt::XWindow > const & child : std::as_const(xChildren) )
{
uno::Reference< awt::XVclWindowPeer > xMsgBoxCtrl( child, uno::UNO_QUERY );
if ( xMsgBoxCtrl.is() )
{
bool bIsDefault = true;<--- Assignment 'bIsDefault=true', assigned value is 1
uno::Any aValue = xMsgBoxCtrl->getProperty( "DefaultButton" );
aValue >>= bIsDefault;
if ( bIsDefault )<--- Condition 'bIsDefault' is always true
xMsgBoxCtrl->setProperty( "Text", uno::Any( rBtnText_1 ) );
else
xMsgBoxCtrl->setProperty( "Text", uno::Any( rBtnText_2 ) );
}
}
}
sal_Int16 nRet;
// xMsgBox->setCaptionText( msCancelTitle );
mbShowsMessageBox = true;
xMsgBox->setMessageText( rWarningText );
nRet = xMsgBox->execute();
if ( nRet == 2 ) // RET_YES == 2
bRet = true;
mbShowsMessageBox = false;
}
uno::Reference< lang::XComponent > xComponent( xMsgBox, uno::UNO_QUERY );
if ( xComponent.is() )
xComponent->dispose();
return bRet;
}
bool UpdateHandler::showOverwriteWarning( const OUString& rFileName ) const<--- The function 'showOverwriteWarning' is never used.
{
return showWarning(
(msReloadWarning
.replaceAll( "%FILENAME", rFileName )
.replaceAll( "%DOWNLOAD_PATH", msDownloadPath )),
msReloadContinue, msReloadReload );
}
bool UpdateHandler::showOverwriteWarning() const
{
return showWarning( msOverwriteWarning );
}
#define BUTTON_HEIGHT 14
#define BUTTON_WIDTH 50
#define BUTTON_X_OFFSET 7
#define BUTTON_Y_OFFSET 3
#define LABEL_HEIGHT 10
#define DIALOG_WIDTH 300
#define DIALOG_BORDER 5
#define INNER_BORDER 3
#define TEXT_OFFSET 1
#define BOX_HEIGHT1 ( LABEL_HEIGHT + 3*BUTTON_HEIGHT + 2*BUTTON_Y_OFFSET + 2*INNER_BORDER )
#define BOX_HEIGHT2 50
#define EDIT_WIDTH ( DIALOG_WIDTH - 2 * DIALOG_BORDER )
#define BOX1_BTN_X ( DIALOG_BORDER + EDIT_WIDTH - BUTTON_WIDTH - INNER_BORDER )
#define BOX1_BTN_Y ( DIALOG_BORDER + LABEL_HEIGHT + INNER_BORDER)
#define THROBBER_WIDTH 16
#define THROBBER_HEIGHT 16
#define THROBBER_X_POS ( DIALOG_BORDER + 8 )
#define THROBBER_Y_POS ( DIALOG_BORDER + 23 )
#define BUTTON_BAR_HEIGHT 24
#define LABEL_OFFSET ( LABEL_HEIGHT + 4 )
#define DIALOG_HEIGHT ( BOX_HEIGHT1 + BOX_HEIGHT2 + LABEL_OFFSET + BUTTON_BAR_HEIGHT + 3 * DIALOG_BORDER )
#define LABEL_Y_POS ( 2 * DIALOG_BORDER + BOX_HEIGHT1 )
#define EDIT2_Y_POS ( LABEL_Y_POS + LABEL_HEIGHT )
#define BUTTON_BAR_Y_POS ( EDIT2_Y_POS + DIALOG_BORDER + BOX_HEIGHT2 )
#define BUTTON_Y_POS ( BUTTON_BAR_Y_POS + 8 )
#define CLOSE_BTN_X ( DIALOG_WIDTH - DIALOG_BORDER - BUTTON_WIDTH )
#define INSTALL_BTN_X ( CLOSE_BTN_X - 2 * BUTTON_X_OFFSET - BUTTON_WIDTH )
#define DOWNLOAD_BTN_X ( INSTALL_BTN_X - BUTTON_X_OFFSET - BUTTON_WIDTH )
#define PROGRESS_WIDTH 80
#define PROGRESS_HEIGHT 10
#define PROGRESS_X_POS ( DIALOG_BORDER + 8 )
#define PROGRESS_Y_POS ( DIALOG_BORDER + 2*LABEL_OFFSET )
void UpdateHandler::showControls( short nControls )
{
// The buttons from CANCEL_BUTTON to RESUME_BUTTON will be shown or
// hidden on demand
short nShiftMe;
for ( int i = 0; i <= int(RESUME_BUTTON); i++ )
{
nShiftMe = static_cast<short>(nControls >> i);
showControl( msButtonIDs[i], static_cast<bool>(nShiftMe & 0x01) );
}
nShiftMe = static_cast<short>(nControls >> THROBBER_CTRL);
startThrobber( static_cast<bool>(nShiftMe & 0x01) );
nShiftMe = static_cast<short>(nControls >> PROGRESS_CTRL);
showControl( CTRL_PROGRESS, static_cast<bool>(nShiftMe & 0x01) );
showControl( TEXT_PERCENT, static_cast<bool>(nShiftMe & 0x01) );
// Status text needs to be smaller, when there are buttons at the right side of the dialog
if ( ( nControls & ( (1<<CANCEL_BUTTON) + (1<<PAUSE_BUTTON) + (1<<RESUME_BUTTON) ) ) != 0 )
setControlProperty( TEXT_STATUS, "Width", uno::Any( sal_Int32(EDIT_WIDTH - BUTTON_WIDTH - 2*INNER_BORDER - TEXT_OFFSET ) ) );
else
setControlProperty( TEXT_STATUS, "Width", uno::Any( sal_Int32(EDIT_WIDTH - 2*TEXT_OFFSET ) ) );
// Status text needs to be taller, when we show the progress bar
if ( ( nControls & ( 1<<PROGRESS_CTRL ) ) != 0 )
setControlProperty( TEXT_STATUS, "Height", uno::Any( sal_Int32(LABEL_HEIGHT) ) );
else
setControlProperty( TEXT_STATUS, "Height", uno::Any( sal_Int32(BOX_HEIGHT1 - 4*TEXT_OFFSET - LABEL_HEIGHT ) ) );
}
void UpdateHandler::createDialog()
{
if ( !mxContext.is() )
{
OSL_ASSERT( false );
return;
}
if( mxContext.is() )
{
uno::Reference< frame::XDesktop2 > xDesktop = frame::Desktop::create( mxContext );
xDesktop->addTerminateListener( this );
}
loadStrings();
uno::Reference< lang::XMultiComponentFactory > xFactory( mxContext->getServiceManager(), uno::UNO_SET_THROW );
uno::Reference< awt::XControlModel > xControlModel( xFactory->createInstanceWithContext(
"com.sun.star.awt.UnoControlDialogModel",
mxContext), uno::UNO_QUERY_THROW );
{
// @see awt/UnoControlDialogModel.idl
uno::Reference< beans::XPropertySet > xPropSet( xControlModel, uno::UNO_QUERY_THROW );
xPropSet->setPropertyValue( "Title", uno::Any( msDlgTitle ) );
xPropSet->setPropertyValue( "Closeable", uno::Any( true ) );
xPropSet->setPropertyValue( "Enabled", uno::Any( true ) );
xPropSet->setPropertyValue( "Moveable", uno::Any( true ) );
xPropSet->setPropertyValue( "Sizeable", uno::Any( true ) );
xPropSet->setPropertyValue( "DesktopAsParent", uno::Any( true ) );
xPropSet->setPropertyValue( "PositionX", uno::Any(sal_Int32( 100 )) );
xPropSet->setPropertyValue( "PositionY", uno::Any(sal_Int32( 100 )) );
xPropSet->setPropertyValue( "Width", uno::Any(sal_Int32( DIALOG_WIDTH )) );
xPropSet->setPropertyValue( "Height", uno::Any(sal_Int32( DIALOG_HEIGHT )) );
xPropSet->setPropertyValue( "HelpURL", uno::makeAny<OUString>( INET_HID_SCHEME HID_CHECK_FOR_UPD_DLG ) );
}
{ // Label (fixed text) <status>
uno::Sequence< beans::NamedValue > aProps { { "Label", uno::Any( msStatusFL ) } };
insertControlModel( xControlModel, FIXED_TEXT_MODEL, "fixedLineStatus",
awt::Rectangle( DIALOG_BORDER+1, DIALOG_BORDER, EDIT_WIDTH-2, LABEL_HEIGHT ),
aProps );
}
{ // box around <status> text
uno::Sequence< beans::NamedValue > aProps;
insertControlModel( xControlModel, GROUP_BOX_MODEL, "StatusBox",
awt::Rectangle( DIALOG_BORDER, DIALOG_BORDER + LABEL_HEIGHT, EDIT_WIDTH, BOX_HEIGHT1 - LABEL_HEIGHT ),
aProps );
}
{ // Text (multiline edit) <status>
uno::Sequence< beans::NamedValue > aProps
{
{ "Text", uno::Any( substVariables(msChecking) ) },
{ "Border", uno::Any( sal_Int16( 0 ) ) },
{ "PaintTransparent", uno::Any( true ) },
{ "MultiLine", uno::Any( true ) },
{ "ReadOnly", uno::Any( true ) },
{ "AutoVScroll", uno::Any( true ) },
{ "HelpURL", uno::makeAny<OUString>( INET_HID_SCHEME HID_CHECK_FOR_UPD_STATUS ) }
};
insertControlModel( xControlModel, EDIT_FIELD_MODEL, TEXT_STATUS,
awt::Rectangle( DIALOG_BORDER + TEXT_OFFSET,
DIALOG_BORDER + LABEL_HEIGHT + TEXT_OFFSET,
EDIT_WIDTH - 2*TEXT_OFFSET,
BOX_HEIGHT1 - 4*TEXT_OFFSET - LABEL_HEIGHT ),
aProps );
}
{ // Text (edit) <percent>
uno::Sequence< beans::NamedValue > aProps
{
{ "Text", uno::Any( msPercent ) },
{ "Border", uno::Any( sal_Int16( 0 ) ) },
{ "PaintTransparent", uno::Any( true ) },
{ "ReadOnly", uno::Any( true ) },
};
insertControlModel( xControlModel, EDIT_FIELD_MODEL, TEXT_PERCENT,
awt::Rectangle( PROGRESS_X_POS + PROGRESS_WIDTH + DIALOG_BORDER,
PROGRESS_Y_POS,
EDIT_WIDTH - PROGRESS_WIDTH - BUTTON_WIDTH - 2*DIALOG_BORDER,
LABEL_HEIGHT ),
aProps );
}
{ // pause button
uno::Sequence< beans::NamedValue > aProps
{
{ "DefaultButton", uno::Any( false ) },
{ "Enabled", uno::Any( true ) },
{ "PushButtonType", uno::Any( sal_Int16(awt::PushButtonType_STANDARD) ) },
{ "Label", uno::Any( msPauseBtn ) },
{ "HelpURL", uno::makeAny<OUString>( INET_HID_SCHEME HID_CHECK_FOR_UPD_PAUSE ) }
};
insertControlModel ( xControlModel, BUTTON_MODEL, msButtonIDs[PAUSE_BUTTON],
awt::Rectangle( BOX1_BTN_X, BOX1_BTN_Y, BUTTON_WIDTH, BUTTON_HEIGHT ),
aProps );
}
{ // resume button
uno::Sequence< beans::NamedValue > aProps
{
{ "DefaultButton", uno::Any( false ) },
{ "Enabled", uno::Any( true ) },
{ "PushButtonType", uno::Any( sal_Int16(awt::PushButtonType_STANDARD) ) },
{ "Label", uno::Any( msResumeBtn ) },
{ "HelpURL", uno::makeAny<OUString>( INET_HID_SCHEME HID_CHECK_FOR_UPD_RESUME ) }
};
insertControlModel ( xControlModel, BUTTON_MODEL, msButtonIDs[RESUME_BUTTON],
awt::Rectangle( BOX1_BTN_X,
BOX1_BTN_Y + BUTTON_Y_OFFSET + BUTTON_HEIGHT,
BUTTON_WIDTH,
BUTTON_HEIGHT ),
aProps );
}
{ // abort button
uno::Sequence< beans::NamedValue > aProps
{
{ "DefaultButton", uno::Any( false ) },
{ "Enabled", uno::Any( true ) },
{ "PushButtonType", uno::Any( sal_Int16(awt::PushButtonType_STANDARD) ) },
{ "Label", uno::Any( msCancelBtn ) },
{ "HelpURL", uno::makeAny<OUString>( INET_HID_SCHEME HID_CHECK_FOR_UPD_CANCEL ) }
};
insertControlModel ( xControlModel, BUTTON_MODEL, msButtonIDs[CANCEL_BUTTON],
awt::Rectangle( BOX1_BTN_X,
BOX1_BTN_Y + (2*(BUTTON_HEIGHT+BUTTON_Y_OFFSET)),
BUTTON_WIDTH,
BUTTON_HEIGHT ),
aProps );
}
{ // Label (FixedText) <description>
uno::Sequence< beans::NamedValue > aProps { { "Label", uno::Any( msDescription ) } };
insertControlModel( xControlModel, FIXED_TEXT_MODEL, "fixedTextDescription",
awt::Rectangle( DIALOG_BORDER+1, LABEL_Y_POS, EDIT_WIDTH-2, LABEL_HEIGHT ),
aProps );
}
{ // box around <description> text
uno::Sequence< beans::NamedValue > aProps;
insertControlModel( xControlModel, GROUP_BOX_MODEL, "DescriptionBox",
awt::Rectangle( DIALOG_BORDER, EDIT2_Y_POS, EDIT_WIDTH, BOX_HEIGHT2 ),
aProps );
}
{ // Text (MultiLineEdit) <description>
uno::Sequence< beans::NamedValue > aProps
{
{ "Text", uno::Any( OUString() ) },
{ "Border", uno::Any( sal_Int16( 0 ) ) },
{ "PaintTransparent", uno::Any( true ) },
{ "MultiLine", uno::Any( true ) },
{ "ReadOnly", uno::Any( true ) },
{ "AutoVScroll", uno::Any( true ) },
{ "HelpURL", uno::makeAny<OUString>( INET_HID_SCHEME HID_CHECK_FOR_UPD_DESCRIPTION ) }
};
insertControlModel( xControlModel, EDIT_FIELD_MODEL, TEXT_DESCRIPTION,
awt::Rectangle( DIALOG_BORDER + TEXT_OFFSET,
EDIT2_Y_POS + 2*TEXT_OFFSET,
EDIT_WIDTH - 3*TEXT_OFFSET,
BOX_HEIGHT2 - 3*TEXT_OFFSET ),
aProps );
}
{ // @see awt/UnoControlFixedLineModel.idl
uno::Sequence< beans::NamedValue > aProps { { "Orientation", uno::Any( sal_Int32( 0 ) ) } };
insertControlModel( xControlModel, FIXED_LINE_MODEL, "fixedLine",
awt::Rectangle( 0, BUTTON_BAR_Y_POS, DIALOG_WIDTH, 5 ),
aProps );
}
{ // close button // @see awt/UnoControlButtonModel.idl
uno::Sequence< beans::NamedValue > aProps
{
{ "DefaultButton", uno::Any( false ) },
{ "Enabled", uno::Any( true ) },
// [property] short PushButtonType
// with own "ButtonActionListener"
{ "PushButtonType", uno::Any( sal_Int16(awt::PushButtonType_STANDARD) ) },
// with default ActionListener => endDialog().
// setProperty( aProps, 2, "PushButtonType", uno::Any( sal_Int16(awt::PushButtonType_CANCEL) ) );
// [property] string Label // only if PushButtonType_STANDARD
{ "Label", uno::Any( msClose ) },
{ "HelpURL", uno::makeAny<OUString>( INET_HID_SCHEME HID_CHECK_FOR_UPD_CLOSE ) }
};
insertControlModel ( xControlModel, BUTTON_MODEL, msButtonIDs[ CLOSE_BUTTON ],
awt::Rectangle( CLOSE_BTN_X, BUTTON_Y_POS, BUTTON_WIDTH, BUTTON_HEIGHT ),
aProps );
}
{ // install button
uno::Sequence< beans::NamedValue > aProps
{
{ "DefaultButton", uno::Any( false ) },
{ "Enabled", uno::Any( true ) },
{ "PushButtonType", uno::Any( sal_Int16(awt::PushButtonType_STANDARD) ) },
{ "Label", uno::Any( msInstall ) },
{ "HelpURL", uno::makeAny<OUString>( INET_HID_SCHEME HID_CHECK_FOR_UPD_INSTALL ) }
};
insertControlModel ( xControlModel, BUTTON_MODEL, msButtonIDs[INSTALL_BUTTON],
awt::Rectangle( INSTALL_BTN_X, BUTTON_Y_POS, BUTTON_WIDTH, BUTTON_HEIGHT ),
aProps );
}
{ // download button
uno::Sequence< beans::NamedValue > aProps
{
{ "DefaultButton", uno::Any( false ) },
{ "Enabled", uno::Any( true ) },
{ "PushButtonType", uno::Any( sal_Int16(awt::PushButtonType_STANDARD) ) },
{ "Label", uno::Any( msDownload ) },
{ "HelpURL", uno::makeAny<OUString>( INET_HID_SCHEME HID_CHECK_FOR_UPD_DOWNLOAD ) }
};
insertControlModel ( xControlModel, BUTTON_MODEL, msButtonIDs[DOWNLOAD_BUTTON],
awt::Rectangle( DOWNLOAD_BTN_X, BUTTON_Y_POS, BUTTON_WIDTH, BUTTON_HEIGHT ),
aProps );
}
{ // help button
uno::Sequence< beans::NamedValue > aProps
{
{ "DefaultButton", uno::Any( false ) },
{ "Enabled", uno::Any( true ) },
{ "PushButtonType", uno::Any( sal_Int16(awt::PushButtonType_HELP) ) }
};
insertControlModel( xControlModel, BUTTON_MODEL, msButtonIDs[HELP_BUTTON],
awt::Rectangle( DIALOG_BORDER, BUTTON_Y_POS, BUTTON_WIDTH, BUTTON_HEIGHT ),
aProps );
}
{ // @see awt/UnoControlThrobberModel.idl
uno::Sequence< beans::NamedValue > aProps;
insertControlModel( xControlModel, "com.sun.star.awt.SpinningProgressControlModel", CTRL_THROBBER,
awt::Rectangle( THROBBER_X_POS, THROBBER_Y_POS, THROBBER_WIDTH, THROBBER_HEIGHT),
aProps );
}
{ // @see awt/UnoControlProgressBarModel.idl
uno::Sequence< beans::NamedValue > aProps
{
{ "Enabled", uno::Any( true ) },
{ "ProgressValue", uno::Any( sal_Int32( 0 ) ) },
{ "ProgressValueMax", uno::Any( sal_Int32( 100 ) ) },
{ "ProgressValueMin", uno::Any( sal_Int32( 0 ) ) },
};
insertControlModel( xControlModel, "com.sun.star.awt.UnoControlProgressBarModel", CTRL_PROGRESS,
awt::Rectangle( PROGRESS_X_POS, PROGRESS_Y_POS, PROGRESS_WIDTH, PROGRESS_HEIGHT ),
aProps);
}
uno::Reference< awt::XUnoControlDialog > xControl = awt::UnoControlDialog::create( mxContext );
xControl->setModel( xControlModel );
if ( !mbVisible )
{
xControl->setVisible( false );
}
xControl->createPeer( nullptr, nullptr );
{
for ( int i = 0; i < HELP_BUTTON; i++ )
{
uno::Reference< awt::XButton > xButton ( xControl->getControl( msButtonIDs[i] ), uno::UNO_QUERY);
if (xButton.is())
{
xButton->setActionCommand( msButtonIDs[i] );
xButton->addActionListener( this );
}
}
}
mxUpdDlg.set( xControl, uno::UNO_QUERY_THROW );
mnLastCtrlState = -1;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|