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
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
|
/*****************************************************************
ksmserver - the KDE session management server
Copyright (C) 2012 Serghei Amelian <serghei.amelian@gmail.com>
Copyright (C) 2010 Timothy Pearson <kb9vqf@pearsoncomputing.net>
Copyright (C) 2000 Matthias Ettrich <ettrich@kde.org>
******************************************************************/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "shutdowndlg.h"
#include <tqapplication.h>
#include <tqlayout.h>
#include <tqgroupbox.h>
#include <tqvbuttongroup.h>
#include <tqlabel.h>
#include <tqvbox.h>
#include <tqtimer.h>
#include <tqstyle.h>
#include <tqcombobox.h>
#include <tqcursor.h>
#include <tqmessagebox.h>
#include <tqbuttongroup.h>
#include <tqiconset.h>
#include <tqpixmap.h>
#include <tqpopupmenu.h>
#include <tqtooltip.h>
#include <tqimage.h>
#include <tqpainter.h>
#include <tqfontmetrics.h>
#include <tqregexp.h>
#include <tqeventloop.h>
#include <tdelocale.h>
#include <tdeconfig.h>
#include <tdeapplication.h>
#ifdef WITH_TDEHWLIB
#include <tdehardwaredevices.h>
#endif
#include <kdebug.h>
#include <kpushbutton.h>
#include <kstdguiitem.h>
#include <kguiitem.h>
#include <kiconloader.h>
#include <tdeglobalsettings.h>
#include <twin.h>
#include <kuser.h>
#include <kpixmap.h>
#include <kimageeffect.h>
#include <kdialog.h>
#include <kseparator.h>
#include <tdeconfig.h>
#include <dcopclient.h>
#include <dcopref.h>
#include <sys/types.h>
#include <sys/utsname.h>
#include <unistd.h>
#include <stdlib.h>
#include <math.h>
#include <dmctl.h>
#include <tdeaction.h>
#include <netwm.h>
#include <X11/Xlib.h>
#include "shutdowndlg.moc"
KSMShutdownFeedback * KSMShutdownFeedback::s_pSelf = 0L;
KSMShutdownFeedback::KSMShutdownFeedback()
: TQWidget( 0L, "feedbackwidget", WType_Popup ),
m_currentY( 0 ),
m_grayOpacity( 0.0f ),
m_compensation( 0.0f ),
m_fadeBackwards( FALSE ),
m_unfadedImage(),
m_grayImage(),
m_fadeTime(),
m_pmio(),
m_greyImageCreated( FALSE )
{
if (kapp->isX11CompositionAvailable()) {
m_grayImage = TQImage( TQApplication::desktop()->width(), TQApplication::desktop()->height(), 32 );
m_grayImage = m_grayImage.convertDepth(32);
m_grayImage.setAlphaBuffer(false);
m_grayImage.fill(0); // Set the alpha buffer to 0 (fully transparent)
m_grayImage.setAlphaBuffer(true);
// Signal that we want a greyscale filter on the transparency
Atom kde_wm_transparent_greyscale_filter;
kde_wm_transparent_greyscale_filter = XInternAtom(tqt_xdisplay(), "_TDE_TRANSPARENCY_FILTER_GREYSCALE_BLEND", False);
XChangeProperty(tqt_xdisplay(), winId(), kde_wm_transparent_greyscale_filter, XA_INTEGER, 32, PropModeReplace, (unsigned char *) "TRUE", 1L);
}
else {
// The hacks below aren't needed any more because Qt3 supports true transparency for the fading logout screen when composition is available
DCOPRef("kicker", "KMenu").call("hideMenu"); // Make sure the TDE Menu is completely removed from the screen before taking a snapshot...
m_grayImage = TQPixmap(TQPixmap::grabWindow(tqt_xrootwin(), 0, 0, TQApplication::desktop()->width(), TQApplication::desktop()->height())).convertToImage();
}
m_unfadedImage = m_grayImage;
resize(0, 0);
setShown(true);
TQTimer::singleShot( 500, this, TQ_SLOT( slotPaintEffect() ) );
}
// called after stopping shutdown-feedback -> smooth fade-back to color-mode
void KSMShutdownFeedback::fadeBack( void )
{
m_fadeTime.restart();
m_fadeBackwards = TRUE;
// its possible that we have to fade back, before all is completely gray, so we cannot start
// with completely gray when fading back...
m_compensation = 1.0f - m_grayOpacity;
// wait until we're completely back in color-mode...
while ( m_grayOpacity > 0.0f )
slotPaintEffect();
}
void KSMShutdownFeedback::slotPaintEffect()
{
// determine which fade to use
if ( (TDEConfigGroup(TDEGlobal::config(), "Logout").readBoolEntry("doFadeaway", true)) &&
(TDEConfigGroup(TDEGlobal::config(), "Logout").readBoolEntry("doFancyLogout", true)) ) {
// fancy logout fade
float doFancyLogoutAdditionalDarkness = (float)TDEConfigGroup(TDEGlobal::config(), "Logout").readDoubleNumEntry("doFancyLogoutAdditionalDarkness", 0.6);
float doFancyLogoutFadeTime = (float)TDEConfigGroup(TDEGlobal::config(), "Logout").readDoubleNumEntry("doFancyLogoutFadeTime", 4000);
float doFancyLogoutFadeBackTime = (float)TDEConfigGroup(TDEGlobal::config(), "Logout").readDoubleNumEntry("doFancyLogoutFadeBackTime", 1000);
if (kapp->isX11CompositionAvailable()) {
// We can do this in a different (simpler) manner because we have compositing support!
// if slotPaintEffect() is called first time, we have to initialize the gray image
// we also could do that in the constructor, but then the displaying of the
// logout-UI would be too much delayed...
if ( m_greyImageCreated == false )
{
m_greyImageCreated = true;
// eliminate nasty flicker on first show
m_root.resize( width(), height() );
TQImage blendedImage = m_grayImage;
TQPainter p;
p.begin( &m_root );
blendedImage.setAlphaBuffer(false);
p.drawImage( 0, 0, blendedImage );
p.end();
setBackgroundPixmap( m_root );
setGeometry( TQApplication::desktop()->geometry() );
setBackgroundMode( TQWidget::NoBackground );
m_unfadedImage = m_grayImage.copy();
uchar * r = m_grayImage.bits();
uchar * end = m_grayImage.bits() + m_grayImage.numBytes();
while ( r != end ) {
*reinterpret_cast<TQRgb*>(r) = tqRgba(0, 0, 0, 255);
r += 4;
}
// start timer which is used for cpu-speed-independent fading
m_fadeTime.start();
m_rowsDone = 0;
}
// return if fading is completely done...
if ( ( m_grayOpacity >= 1.0f && m_fadeBackwards == FALSE ) || ( m_grayOpacity <= 0.0f && m_fadeBackwards == TRUE ) )
return;
if ( m_fadeBackwards == FALSE )
{
m_grayOpacity = m_fadeTime.elapsed() / doFancyLogoutFadeTime;
if ( m_grayOpacity > 1.0f )
m_grayOpacity = 1.0f;
}
else
{
m_grayOpacity = 1.0f - m_fadeTime.elapsed() / doFancyLogoutFadeBackTime - m_compensation;
if ( m_grayOpacity < 0.0f )
m_grayOpacity = 0.0f;
}
const int imgWidth = m_unfadedImage.width();
int imgHeight = m_unfadedImage.height();
int heightUnit = imgHeight / 3;
if( heightUnit < 1 )
heightUnit = 1;
int y1 = static_cast<int>( imgHeight*m_grayOpacity - heightUnit + m_grayOpacity*heightUnit*2.0f );
if( y1 > imgHeight )
y1 = imgHeight;
int y2 = y1+heightUnit;
if( y2 > imgHeight )
y2 = imgHeight;
if( m_fadeBackwards == FALSE )
{
if( y1 > 0 && y1 < imgHeight && y1-m_rowsDone > 0 && m_rowsDone < imgHeight )
{
TQImage img( imgWidth, y1-m_rowsDone, 32 );
memcpy( img.bits(), m_grayImage.scanLine( m_rowsDone ), imgWidth*(y1-m_rowsDone)*4 );
bitBlt( this, 0, m_rowsDone, &img );
m_rowsDone = y1;
}
}
else
{
// when fading back we have to blit area which isnt gray anymore to unfaded image
if( y2 > 0 && y2 < imgHeight && m_rowsDone > y2 )
{
TQImage img( imgWidth, m_rowsDone-y2, 32 );
memcpy( img.bits(), m_unfadedImage.scanLine( y2 ), imgWidth*(m_rowsDone-y2)*4 );
bitBlt( this, 0, y2, &img );
m_rowsDone = y2;
}
}
int start_y1 = y1;
if( start_y1 < 0 )
start_y1 = 0;
if( y2 > start_y1 )
{
TQImage img( imgWidth, y2-start_y1, 32 );
memcpy( img.bits(), m_grayImage.scanLine( start_y1 ), ( y2-start_y1 ) * imgWidth * 4 );
uchar * rd = img.bits();
for( int y = start_y1; y < y2; ++y )
{
// linear gradients look bad, so use cos-function
short int opac = static_cast<short int>( 128 - cosf( M_PI*(y-y1)/heightUnit )*128.0f );
for( short int x = 0; x < imgWidth; ++x )
{
*reinterpret_cast<TQRgb*>(rd) = tqRgba(0, 0, 0, ((255.0-opac)));
rd += 4;
}
}
bitBlt( this, 0, start_y1, &img );
}
TQTimer::singleShot( 5, this, TQ_SLOT( slotPaintEffect() ) );
}
else {
// if slotPaintEffect() is called first time, we have to initialize the gray image
// we also could do that in the constructor, but then the displaying of the
// logout-UI would be too much delayed...
if ( m_greyImageCreated == false )
{
m_greyImageCreated = true;
setBackgroundMode( TQWidget::NoBackground );
setGeometry( TQApplication::desktop()->geometry() );
m_root.resize( width(), height() ); // for the default logout
m_unfadedImage = m_grayImage.copy();
uchar * r = m_grayImage.bits();
uchar * g = m_grayImage.bits() + 1;
uchar * b = m_grayImage.bits() + 2;
uchar * end = m_grayImage.bits() + m_grayImage.numBytes();
while ( r != end ) {
*r = *g = *b = (uchar) ( ( (*r)*11 + ((*g)<<4) + (*b)*5 ) * doFancyLogoutAdditionalDarkness / 32.0f );
r += 4;
g += 4;
b += 4;
}
// start timer which is used for cpu-speed-independent fading
m_fadeTime.start();
m_rowsDone = 0;
}
// return if fading is completely done...
if ( ( m_grayOpacity >= 1.0f && m_fadeBackwards == FALSE ) || ( m_grayOpacity <= 0.0f && m_fadeBackwards == TRUE ) )
return;
if ( m_fadeBackwards == FALSE )
{
m_grayOpacity = m_fadeTime.elapsed() / doFancyLogoutFadeTime;
if ( m_grayOpacity > 1.0f )
m_grayOpacity = 1.0f;
}
else
{
m_grayOpacity = 1.0f - m_fadeTime.elapsed() / doFancyLogoutFadeBackTime - m_compensation;
if ( m_grayOpacity < 0.0f )
m_grayOpacity = 0.0f;
}
const int imgWidth = m_unfadedImage.width();
int imgHeight = m_unfadedImage.height();
int heightUnit = imgHeight / 3;
if( heightUnit < 1 )
heightUnit = 1;
int y1 = static_cast<int>( imgHeight*m_grayOpacity - heightUnit + m_grayOpacity*heightUnit*2.0f );
if( y1 > imgHeight )
y1 = imgHeight;
int y2 = y1+heightUnit;
if( y2 > imgHeight )
y2 = imgHeight;
if( m_fadeBackwards == FALSE )
{
if( y1 > 0 && y1 < imgHeight && y1-m_rowsDone > 0 && m_rowsDone < imgHeight )
{
TQImage img( imgWidth, y1-m_rowsDone, 32 );
memcpy( img.bits(), m_grayImage.scanLine( m_rowsDone ), imgWidth*(y1-m_rowsDone)*4 );
// conversion is slow as hell if desktop-depth != 24bpp...
//Pixmap pm = m_pmio.convertToPixmap( img );
//bitBlt( this, 0, m_rowsDone, &pm );
//TQImage pm = m_pmio.convertToImage( img );
bitBlt( this, 0, m_rowsDone, &img );
m_rowsDone = y1;
}
}
else
{
// when fading back we have to blit area which isnt gray anymore to unfaded image
if( y2 > 0 && y2 < imgHeight && m_rowsDone > y2 )
{
TQImage img( imgWidth, m_rowsDone-y2, 32 );
memcpy( img.bits(), m_unfadedImage.scanLine( y2 ), imgWidth*(m_rowsDone-y2)*4 );
// conversion is slow as hell if desktop-depth != 24bpp...
//TQPixmap pm = m_pmio.convertToPixmap( img );
//bitBlt( this, 0, y2, &pm );
bitBlt( this, 0, y2, &img );
m_rowsDone = y2;
}
}
int start_y1 = y1;
if( start_y1 < 0 )
start_y1 = 0;
if( y2 > start_y1 )
{
TQImage img( imgWidth, y2-start_y1, 32 );
memcpy( img.bits(), m_grayImage.scanLine( start_y1 ), ( y2-start_y1 ) * imgWidth * 4 );
uchar * rs = m_unfadedImage.scanLine( start_y1 );
uchar * gs = rs + 1;
uchar * bs = gs + 1;
uchar * rd = img.bits();
uchar * gd = rd + 1;
uchar * bd = gd + 1;
for( int y = start_y1; y < y2; ++y )
{
// linear gradients look bad, so use cos-function
short int opac = static_cast<short int>( 128 - cosf( M_PI*(y-y1)/heightUnit )*128.0f );
for( short int x = 0; x < imgWidth; ++x )
{
*rd += ( ( ( *rs - *rd ) * opac ) >> 8 );
rs += 4; rd += 4;
*gd += ( ( ( *gs - *gd ) * opac ) >> 8 );
gs += 4; gd += 4;
*bd += ( ( ( *bs - *bd ) * opac ) >> 8 );
bs += 4; bd += 4;
}
}
// conversion is slow as hell if desktop-depth != 24bpp...
//TQPixmap pm = m_pmio.convertToPixmap( img );
//bitBlt( this, 0, start_y1, &pm );
bitBlt( this, 0, start_y1, &img );
}
TQTimer::singleShot( 5, this, TQ_SLOT( slotPaintEffect() ) );
}
}
else {
if (TDEConfigGroup(TDEGlobal::config(), "Logout").readBoolEntry("doFadeaway", true)) {
// standard logout fade
if (kapp->isX11CompositionAvailable()) {
// We can do this in a different (simpler) manner because we have compositing support!
// The end effect will be very similar to the old style logout
float doFancyLogoutFadeTime = 1000;
float doFancyLogoutFadeBackTime = 0;
if ( m_greyImageCreated == false ) {
m_greyImageCreated = true;
// eliminate nasty flicker on first show
m_root.resize( width(), height() );
TQImage blendedImage = m_grayImage;
TQPainter p;
p.begin( &m_root );
blendedImage.setAlphaBuffer(false);
p.drawImage( 0, 0, blendedImage );
p.end();
setBackgroundPixmap( m_root );
setGeometry( TQApplication::desktop()->geometry() );
setBackgroundMode( TQWidget::NoBackground );
m_unfadedImage = m_grayImage.copy();
uchar * r = m_grayImage.bits();
uchar * end = m_grayImage.bits() + m_grayImage.numBytes();
while ( r != end ) {
*reinterpret_cast<TQRgb*>(r) = tqRgba(0, 0, 0, 107);
r += 4;
}
// start timer which is used for cpu-speed-independent fading
m_fadeTime.start();
m_rowsDone = 0;
}
// return if fading is completely done...
if ( ( m_grayOpacity >= 1.0f && m_fadeBackwards == FALSE ) || ( m_grayOpacity <= 0.0f && m_fadeBackwards == TRUE ) ) {
return;
}
if ( m_fadeBackwards == FALSE ) {
m_grayOpacity = m_fadeTime.elapsed() / doFancyLogoutFadeTime;
if ( m_grayOpacity > 1.0f )
m_grayOpacity = 1.0f;
}
else {
m_grayOpacity = 1.0f - m_fadeTime.elapsed() / doFancyLogoutFadeBackTime - m_compensation;
if ( m_grayOpacity < 0.0f )
m_grayOpacity = 0.0f;
}
const int imgWidth = m_unfadedImage.width();
int imgHeight = m_unfadedImage.height();
int heightUnit = imgHeight / 3;
if( heightUnit < 1 )
heightUnit = 1;
int y1 = static_cast<int>( imgHeight*m_grayOpacity - heightUnit + m_grayOpacity*heightUnit*2.0f );
if( y1 > imgHeight ) {
y1 = imgHeight;
}
int y2 = y1+heightUnit;
if( y2 > imgHeight ) {
y2 = imgHeight;
}
if( m_fadeBackwards == FALSE )
{
if( y1 > 0 && y1 < imgHeight && y1-m_rowsDone > 0 && m_rowsDone < imgHeight )
{
TQImage img( imgWidth, y1-m_rowsDone, 32 );
memcpy( img.bits(), m_grayImage.scanLine( m_rowsDone ), imgWidth*(y1-m_rowsDone)*4 );
bitBlt( this, 0, m_rowsDone, &img );
m_rowsDone = y1;
}
}
else {
// when fading back we have to blit area which isnt gray anymore to unfaded image
if( y2 > 0 && y2 < imgHeight && m_rowsDone > y2 )
{
TQImage img( imgWidth, m_rowsDone-y2, 32 );
memcpy( img.bits(), m_unfadedImage.scanLine( y2 ), imgWidth*(m_rowsDone-y2)*4 );
bitBlt( this, 0, y2, &img );
m_rowsDone = y2;
}
}
int start_y1 = y1;
if( start_y1 < 0 ) {
start_y1 = 0;
}
if( y2 > start_y1 ) {
TQImage img( imgWidth, y2-start_y1, 32 );
memcpy( img.bits(), m_grayImage.scanLine( start_y1 ), ( y2-start_y1 ) * imgWidth * 4 );
uchar * rs = m_unfadedImage.scanLine( start_y1 );
uchar * rd = img.bits();
for( int y = start_y1; y < y2; ++y )
{
// linear gradients look bad, so use cos-function
for( short int x = 0; x < imgWidth; ++x )
{
*reinterpret_cast<TQRgb*>(rd) = tqRgba(0, 0, 0, 107);
rs += 4; rd += 4;
}
}
bitBlt( this, 0, start_y1, &img );
}
TQTimer::singleShot( 1, this, TQ_SLOT( slotPaintEffect() ) );
}
else {
if ( m_currentY >= height() ) {
if ( backgroundMode() == TQWidget::NoBackground ) {
setBackgroundMode( TQWidget::NoBackground );
setBackgroundPixmap( m_root );
}
return;
}
if ( m_currentY == 0 ) {
setBackgroundMode( TQWidget::NoBackground );
setGeometry( TQApplication::desktop()->geometry() );
m_root.resize( width(), height() ); // for the default logout
KPixmap pixmap;
pixmap = TQPixmap(TQPixmap::grabWindow( tqt_xrootwin(), 0, 0, width(), height() ));
bitBlt( this, 0, 0, &pixmap );
bitBlt( &m_root, 0, 0, &pixmap );
}
KPixmap pixmap;
pixmap = TQPixmap(TQPixmap::grabWindow( tqt_xrootwin(), 0, m_currentY, width(), 10 ));
TQImage image = pixmap.convertToImage();
KImageEffect::blend( TQt::black, image, 0.4 );
KImageEffect::toGray( image, true );
pixmap.convertFromImage( image );
bitBlt( this, 0, m_currentY, &pixmap );
bitBlt( &m_root, 0, m_currentY, &pixmap );
m_currentY += 10;
TQTimer::singleShot( 1, this, TQ_SLOT( slotPaintEffect() ) );
}
}
}
}
//////
KSMShutdownIPFeedback * KSMShutdownIPFeedback::s_pSelf = 0L;
KSMShutdownIPFeedback::KSMShutdownIPFeedback()
: TQWidget( 0L, "systemmodaldialogclass", TQt::WStyle_Customize | TQt::WStyle_NoBorder | TQt::WStyle_StaysOnTop ), m_timeout(0), m_isPainted(false), m_paintedFromSharedRootPixmap(false), m_sharedRootPixmap(NULL), mPixmapTimeout(0)
{
setShown(false);
hide();
enableExports();
m_sharedRootPixmap = new KRootPixmap(this);
m_sharedRootPixmap->setCustomPainting(true);
connect(m_sharedRootPixmap, TQ_SIGNAL(backgroundUpdated(const TQPixmap &)), this, TQ_SLOT(slotSetBackgroundPixmap(const TQPixmap &)));
if (TQPaintDevice::x11AppDepth() == 32) {
// The shared pixmap is 24 bits, but we are 32 bits
// Therefore our only option is to use a 24-bit Xorg application to dump the shared pixmap in a common (png) format for loading later
TQString filename = getenv("USER");
filename.prepend("/tmp/tde-");
filename.append("/krootbacking.png");
remove(filename.ascii());
system("krootbacking &");
}
m_screenGeometry = TQApplication::desktop()->geometry();
// eliminate nasty flicker on first show
m_root.resize(m_screenGeometry.width(), m_screenGeometry.height());
TQPainter p;
p.begin( &m_root );
p.fillRect( 0, 0, m_root.width(), m_root.height(), TQBrush(tqRgba(0, 0, 0, 0)) );
p.end();
setBackgroundPixmap( m_root );
setGeometry( m_screenGeometry );
setBackgroundMode( TQWidget::NoBackground );
}
void KSMShutdownIPFeedback::showNow()
{
setShown(true);
if (!m_isPainted) {
setGeometry( TQApplication::desktop()->geometry() );
TQTimer::singleShot( 0, this, TQ_SLOT(slotPaintEffect()) );
}
}
void KSMShutdownIPFeedback::enableExports()
{
#ifdef Q_WS_X11
kdDebug(270) << k_lineinfo << "activating background exports.\n";
DCOPClient *client = kapp->dcopClient();
if (!client->isAttached()) {
client->attach();
}
TQByteArray data;
TQDataStream args( data, IO_WriteOnly );
args << 1;
TQCString appname( "kdesktop" );
int screen_number = DefaultScreen(tqt_xdisplay());
if ( screen_number )
appname.sprintf("kdesktop-screen-%d", screen_number );
client->send( appname, "KBackgroundIface", "setExport(int)", data );
#endif
}
KSMShutdownIPFeedback::~KSMShutdownIPFeedback()
{
if (m_sharedRootPixmap) {
m_sharedRootPixmap->stop();
delete m_sharedRootPixmap;
m_sharedRootPixmap = NULL;
}
}
void KSMShutdownIPFeedback::fadeBack( void ) {
//
}
void KSMShutdownIPFeedback::resizeEvent(TQResizeEvent* re) {
if (m_isPainted) {
// Resist all attempts to change size
setGeometry( m_screenGeometry );
}
}
void KSMShutdownIPFeedback::slotSetBackgroundPixmap(const TQPixmap &rpm) {
m_rootPixmap = rpm;
}
void KSMShutdownIPFeedback::slotPaintEffect()
{
if (m_isPainted && m_paintedFromSharedRootPixmap) {
return;
}
TQPixmap pm = m_rootPixmap;
if (mPixmapTimeout == 0) {
if (TQPaintDevice::x11AppDepth() != 32) {
m_sharedRootPixmap->start();
}
TQTimer::singleShot( 100, this, TQ_SLOT(slotPaintEffect()) );
mPixmapTimeout++;
return;
}
if (TQPaintDevice::x11AppDepth() == 32) {
TQString filename = getenv("USER");
filename.prepend("/tmp/tde-");
filename.append("/krootbacking.png");
bool success = pm.load(filename, "PNG");
if (!success) {
pm = TQPixmap();
}
}
if ((pm.isNull()) || (pm.width() != kapp->desktop()->width()) || (pm.height() != kapp->desktop()->height())) {
if (mPixmapTimeout < 10) {
TQTimer::singleShot( 100, this, TQ_SLOT(slotPaintEffect()) );
mPixmapTimeout++;
return;
}
else {
pm = TQPixmap(kapp->desktop()->width(), kapp->desktop()->height());
pm.fill(TQt::black);
m_paintedFromSharedRootPixmap = false;
}
}
else {
m_paintedFromSharedRootPixmap = true;
if (m_sharedRootPixmap) {
m_sharedRootPixmap->stop();
delete m_sharedRootPixmap;
m_sharedRootPixmap = NULL;
}
}
if (TQPaintDevice::x11AppDepth() == 32) {
// Remove the alpha components from the image
TQImage correctedImage = pm.convertToImage();
correctedImage = correctedImage.convertDepth(32);
correctedImage.setAlphaBuffer(true);
int w = correctedImage.width();
int h = correctedImage.height();
for (int y = 0; y < h; ++y) {
TQRgb *ls = (TQRgb *)correctedImage.scanLine( y );
for (int x = 0; x < w; ++x) {
TQRgb l = ls[x];
int r = int( tqRed( l ) );
int g = int( tqGreen( l ) );
int b = int( tqBlue( l ) );
int a = int( 255 );
ls[x] = tqRgba( r, g, b, a );
}
}
pm.convertFromImage(correctedImage);
}
setBackgroundPixmap( pm );
move(0,0);
setWindowState(WindowFullScreen);
m_screenGeometry = TQApplication::desktop()->geometry();
setGeometry( m_screenGeometry );
repaint(true);
tqApp->flushX();
m_isPainted = true;
}
//////
KSMShutdownDlg::KSMShutdownDlg( TQWidget* parent,
bool maysd, bool mayrb, TDEApplication::ShutdownType sdtype, int* selection )
: TQDialog( parent, 0, TRUE, (WFlags)WType_Popup ), targets(0), m_selection(selection)
// this is a WType_Popup on purpose. Do not change that! Not
// having a popup here has severe side effects.
{
TQVBoxLayout* vbox = new TQVBoxLayout( this );
if (m_selection) {
*m_selection = SuspendType::NotSpecified;
}
TQFrame* frame = new TQFrame( this );
frame->setFrameStyle( TQFrame::StyledPanel | TQFrame::Raised );
frame->setLineWidth( style().pixelMetric( TQStyle::PM_DefaultFrameWidth, frame ) );
// we need to set the minimum size for the logout box, since it
// gets too small if there isn't all options available
frame->setMinimumWidth(400);
vbox->addWidget( frame );
vbox = new TQVBoxLayout( frame, 2 * KDialog::marginHint(),
2 * KDialog::spacingHint() );
// default factor
bool doUbuntuLogout = TDEConfigGroup(TDEGlobal::config(), "Logout").readBoolEntry("doUbuntuLogout", false);
// slighty more space for the new logout
int factor = 2;
if(doUbuntuLogout)
{
factor = 8;
}
else {
TQLabel* label = new TQLabel( i18n("End Session for \"%1\"").arg(KUser().loginName()), frame );
TQFont fnt = label->font();
fnt.setBold( true );
fnt.setPointSize( fnt.pointSize() * 3 / 2 );
label->setFont( fnt );
vbox->addWidget( label, 0, AlignHCenter );
}
// for the basic layout, within this box either the ubuntu dialog or
// standard konqy+buttons will be placed.
TQHBoxLayout* hbox = new TQHBoxLayout( vbox, factor * KDialog::spacingHint() );
// from here on we have to adapt to the two different dialogs
TQFrame* lfrm;
TQVBoxLayout* buttonlay;
TQHBoxLayout* hbuttonbox;
TQFont btnFont;
if(doUbuntuLogout)
{
// first line of buttons
hbuttonbox = new TQHBoxLayout( hbox, factor * KDialog::spacingHint() );
hbuttonbox->setAlignment( TQt::AlignHCenter );
// End session
FlatButton* btnLogout = new FlatButton( frame );
btnLogout->setTextLabel( TQString("&") + i18n("Log out"), false );
btnLogout->setPixmap( DesktopIcon( "back") );
TQToolTip::add( btnLogout, i18n( "<qt><p>Log out of the current session to login as a different user.</p></qt>" ) );
int i = btnLogout->textLabel().find( TQRegExp("\\&"), 0 ); // i == 1
btnLogout->setAccel( "ALT+" + btnLogout->textLabel().lower()[i+1] ) ;
hbuttonbox->addWidget ( btnLogout );
connect(btnLogout, TQ_SIGNAL(clicked()), TQ_SLOT(slotLogout()));
}
else
{
// konqy
lfrm = new TQFrame( frame );
lfrm->setFrameStyle( TQFrame::Panel | TQFrame::Sunken );
hbox->addWidget( lfrm, AlignCenter );
buttonlay = new TQVBoxLayout( hbox, factor * KDialog::spacingHint() );
buttonlay->setAlignment( TQt::AlignHCenter );
TQLabel* icon = new TQLabel( lfrm );
if (TDEConfigGroup(TDEGlobal::config(), "Logout").readBoolEntry("doNotUseKonqyPicture", false)) {
icon->setPixmap( UserIcon( "shutdown" ) );
}
else {
icon->setPixmap( UserIcon( "shutdownkonq" ) );
}
lfrm->setFixedSize( icon->sizeHint());
icon->setFixedSize( icon->sizeHint());
buttonlay->addStretch( 1 );
// End session
KPushButton* btnLogout = new KPushButton( KGuiItem( i18n("&Log out"), "edit-undo"), frame );
TQToolTip::add( btnLogout, i18n( "<qt><p>Log out of the current session to login as a different user.</p></qt>" ) );
btnFont = btnLogout->font();
buttonlay->addWidget( btnLogout );
connect(btnLogout, TQ_SIGNAL(clicked()), TQ_SLOT(slotLogout()));
}
if ((maysd) || (mayrb)) {
// respect lock on resume & disable suspend/hibernate settings
// from power-manager
TDEConfig config("power-managerrc");
bool disableSuspend = config.readBoolEntry("disableSuspend", false);
bool disableHibernate = config.readBoolEntry("disableHibernate", false);
m_lockOnResume = config.readBoolEntry("lockOnResume", true);
bool canFreeze = false;
bool canSuspend = false;
bool canHibernate = false;
bool canHybridSuspend = false;
#if defined(WITH_TDEHWLIB)
TDERootSystemDevice* rootDevice = TDEGlobal::hardwareDevices()->rootSystemDevice();
if (rootDevice) {
canFreeze = rootDevice->canFreeze();
canSuspend = rootDevice->canSuspend();
canHibernate = rootDevice->canHibernate();
canHybridSuspend = rootDevice->canHybridSuspend();
}
else {
canFreeze = false;
canSuspend = false;
canHibernate = false;
canHybridSuspend = false;
}
#endif
if(doUbuntuLogout) {
// Ubuntu style logout window
if (canFreeze && !disableSuspend)
{
// Freeze
FlatButton* btnFreeze = new FlatButton( frame );
btnFreeze->setTextLabel( i18n("&Freeze"), false );
btnFreeze->setPixmap( DesktopIcon( "suspend") );
TQToolTip::add(btnFreeze, i18n("<qt><p>Put the computer in software idle mode,"
" allowing for some powersaving. The system can be reactivated in a really short time,"
" almost instantly.</p><p>This correspond to ACPI S0 mode.</p></qt>"));
int i = btnFreeze->textLabel().find( TQRegExp("\\&"), 0 ); // i == 1
btnFreeze->setAccel( "ALT+" + btnFreeze->textLabel().lower()[i+1] ) ;
hbuttonbox->addWidget ( btnFreeze );
connect(btnFreeze, TQ_SIGNAL(clicked()), TQ_SLOT(slotFreeze()));
}
if (canSuspend && !disableSuspend)
{
// Suspend
FlatButton* btnSuspend = new FlatButton( frame );
btnSuspend->setTextLabel( i18n("&Suspend"), false );
btnSuspend->setPixmap( DesktopIcon( "suspend") );
TQToolTip::add(btnSuspend, i18n("<qt><p>Put the computer in suspend-to-memory mode."
" The system is stopped and its state saved to memory.</p><p> This allows more powersaving than 'Freeze'"
" but requires longer time to reactivate the system.</p><p>This correspond to ACPI S3 mode.</p>"
"<p>Also known as Suspend-to-RAM mode.</p></qt>"));
int i = btnSuspend->textLabel().find( TQRegExp("\\&"), 0 ); // i == 1
btnSuspend->setAccel( "ALT+" + btnSuspend->textLabel().lower()[i+1] ) ;
hbuttonbox->addWidget ( btnSuspend );
connect(btnSuspend, TQ_SIGNAL(clicked()), TQ_SLOT(slotSuspend()));
}
if (canHibernate && !disableHibernate)
{
// Hibernate
FlatButton* btnHibernate = new FlatButton( frame );
btnHibernate->setTextLabel( i18n("&Hibernate"), false );
btnHibernate->setPixmap( DesktopIcon( "hibernate") );
TQToolTip::add(btnHibernate, i18n("<qt><p>Put the computer in suspend-to-disk mode."
" The system is stopped and its state saved to disk.</p><p>This offers the greatest powersaving but"
" considerable time is required to reactivate the system again.</p><p>This correspond to ACPI S4 mode.</p><p>Also known as Suspend-to-Disk mode.</p></qt>"));
int i = btnHibernate->textLabel().find( TQRegExp("\\&"), 0 ); // i == 1
btnHibernate->setAccel( "ALT+" + btnHibernate->textLabel().lower()[i+1] ) ;
hbuttonbox->addWidget ( btnHibernate );
connect(btnHibernate, TQ_SIGNAL(clicked()), TQ_SLOT(slotHibernate()));
}
if (canHybridSuspend && !disableSuspend && !disableHibernate)
{
// Hybrid suspend
FlatButton* btnHybridSuspend = new FlatButton( frame );
btnHybridSuspend->setTextLabel( i18n("H&ybrid Suspend"), false );
btnHybridSuspend->setPixmap( DesktopIcon( "hibernate") );
TQToolTip::add(btnHybridSuspend, i18n("<qt><p>Put the computer in both suspend-to-memory and"
" suspend-to-disk mode. The system is stopped and its state saved to memory and to disk.</p>"
"<p>This offers the best of both 'Suspend' and 'Hibernate' modes combined together. The system is"
" de facto in 'Suspend' mode but if power is lost, work can still be resumed as if the system"
" had been hibernated, preventing any data loss.</p><p>This correspond to ACPI S3+S4 mode.</p>"
"<p>Also known as Suspend-to-RAM + Suspend-to-Disk mode.</p></qt>"));
int i = btnHybridSuspend->textLabel().find( TQRegExp("\\&"), 0 ); // i == 1
btnHybridSuspend->setAccel( "ALT+" + btnHybridSuspend->textLabel().lower()[i+1] ) ;
hbuttonbox->addWidget ( btnHybridSuspend );
connect(btnHybridSuspend, TQ_SIGNAL(clicked()), TQ_SLOT(slotHybridSuspend()));
}
// Separator (within buttonlay)
vbox->addWidget( new KSeparator( frame ) );
// bottom buttons
TQHBoxLayout* hbuttonbox2 = new TQHBoxLayout( vbox, factor * KDialog::spacingHint() );
hbuttonbox2->setAlignment( TQt::AlignHCenter );
if (mayrb) {
// Reboot
FlatButton* btnReboot = new FlatButton( frame );
btnReboot->setTextLabel( i18n("&Restart"), false );
btnReboot->setPixmap( DesktopIcon( "reload") );
TQToolTip::add( btnReboot, i18n( "<qt><p>Log out of the current session and restart the computer.</p></qt>" ) );
int i = btnReboot->textLabel().find( TQRegExp("\\&"), 0 ); // i == 1
btnReboot->setAccel( "ALT+" + btnReboot->textLabel().lower()[i+1] ) ;
hbuttonbox2->addWidget ( btnReboot);
connect(btnReboot, TQ_SIGNAL(clicked()), TQ_SLOT(slotReboot()));
if ( sdtype == TDEApplication::ShutdownTypeReboot ) {
btnReboot->setFocus();
}
// BAD KARMA .. this code is copied line by line from standard konqy dialog
int def, cur;
if ( DM().bootOptions( rebootOptions, def, cur ) ) {
btnReboot->setPopupDelay(300); // visually add dropdown
targets = new TQPopupMenu( frame );
if ( cur == -1 ) {
cur = def;
}
int index = 0;
for (TQStringList::ConstIterator it = rebootOptions.begin(); it != rebootOptions.end(); ++it, ++index) {
TQString label = (*it);
label=label.replace('&',"&&");
if (index == cur) {
targets->insertItem( label + i18n("current option in boot loader", " (current)"), index);
}
else {
targets->insertItem( label, index );
}
}
btnReboot->setPopup(targets);
connect( targets, TQ_SIGNAL(activated(int)), TQ_SLOT(slotReboot(int)) );
}
// BAD KARMA .. this code is copied line by line from standard konqy dialog [EOF]
}
if (maysd) {
// Shutdown
FlatButton* btnHalt = new FlatButton( frame );
btnHalt->setTextLabel( i18n("&Shutdown"), false );
btnHalt->setPixmap( DesktopIcon( "system-log-out") );
TQToolTip::add( btnHalt, i18n( "<qt><p>Log out of the current session and turn off the computer.</p></qt>" ) );
int i = btnHalt->textLabel().find( TQRegExp("\\&"), 0 ); // i == 1
btnHalt->setAccel( "ALT+" + btnHalt->textLabel().lower()[i+1] ) ;
hbuttonbox2->addWidget ( btnHalt );
connect(btnHalt, TQ_SIGNAL(clicked()), TQ_SLOT(slotHalt()));
if ( sdtype == TDEApplication::ShutdownTypeHalt ) {
btnHalt->setFocus();
}
}
// cancel buttonbox
TQHBoxLayout* hbuttonbox3 = new TQHBoxLayout( vbox, factor * KDialog::spacingHint() );
hbuttonbox3->setAlignment( TQt::AlignRight );
// Back to Desktop
KSMPushButton* btnBack = new KSMPushButton( KStdGuiItem::cancel(), frame );
hbuttonbox3->addWidget( btnBack );
connect(btnBack, TQ_SIGNAL(clicked()), TQ_SLOT(reject()));
}
else
{
// Standard style logout window
if (maysd) {
// Shutdown
KPushButton* btnHalt = new KPushButton( KGuiItem( i18n("&Shutdown"), "system-log-out"), frame );
TQToolTip::add( btnHalt, i18n( "<qt><p>Log out of the current session and turn off the computer.</p></qt>" ) );
btnHalt->setFont( btnFont );
buttonlay->addWidget( btnHalt );
connect(btnHalt, TQ_SIGNAL(clicked()), TQ_SLOT(slotHalt()));
if ( sdtype == TDEApplication::ShutdownTypeHalt || getenv("TDM_AUTOLOGIN") ) {
btnHalt->setFocus();
}
}
if (mayrb) {
// Reboot
KSMDelayedPushButton* btnReboot = new KSMDelayedPushButton( KGuiItem( i18n("&Restart"), "reload"), frame );
TQToolTip::add( btnReboot, i18n( "<qt><p>Log out of the current session and restart the computer.</p></qt>" ) );
btnReboot->setFont( btnFont );
buttonlay->addWidget( btnReboot );
connect(btnReboot, TQ_SIGNAL(clicked()), TQ_SLOT(slotReboot()));
if ( sdtype == TDEApplication::ShutdownTypeReboot ) {
btnReboot->setFocus();
}
// this section is copied as-is into ubuntulogout as well
int def, cur;
if ( DM().bootOptions( rebootOptions, def, cur ) ) {
targets = new TQPopupMenu( frame );
if ( cur == -1 ) {
cur = def;
}
int index = 0;
for (TQStringList::ConstIterator it = rebootOptions.begin(); it != rebootOptions.end(); ++it, ++index) {
TQString label = (*it);
label=label.replace('&',"&&");
if (index == cur) {
targets->insertItem( label + i18n("current option in boot loader", " (current)"), index);
}
else {
targets->insertItem( label, index );
}
}
btnReboot->setPopup(targets);
connect( targets, TQ_SIGNAL(activated(int)), TQ_SLOT(slotReboot(int)) );
}
}
if (canFreeze && !disableSuspend)
{
KPushButton* btnFreeze = new KPushButton( KGuiItem( i18n("&Freeze"), "suspend"), frame );
TQToolTip::add(btnFreeze, i18n("<qt><p>Put the computer in software idle mode,"
" allowing for some powersaving. The system can be reactivated in a really short time,"
" almost instantly.</p><p>This correspond to ACPI S0 mode.</p></qt>"));
btnFreeze->setFont( btnFont );
buttonlay->addWidget( btnFreeze );
connect(btnFreeze, TQ_SIGNAL(clicked()), TQ_SLOT(slotFreeze()));
}
if (canSuspend && !disableSuspend)
{
KPushButton* btnSuspend = new KPushButton( KGuiItem( i18n("&Suspend"), "suspend"), frame );
TQToolTip::add(btnSuspend, i18n("<qt><p>Put the computer in suspend-to-memory mode."
" The system is stopped and its state saved to memory.</p><p> This allows more powersaving than 'Freeze'"
" but requires longer time to reactivate the system.</p><p>This correspond to ACPI S3 mode.</p>"
"<p>Also known as Suspend-to-RAM mode.</p></qt>"));
btnSuspend->setFont( btnFont );
buttonlay->addWidget( btnSuspend );
connect(btnSuspend, TQ_SIGNAL(clicked()), TQ_SLOT(slotSuspend()));
}
if (canHibernate && !disableHibernate)
{
KPushButton* btnHibernate = new KPushButton( KGuiItem( i18n("&Hibernate"), "hibernate"), frame );
TQToolTip::add(btnHibernate, i18n("<qt><p>Put the computer in suspend-to-disk mode."
" The system is stopped and its state saved to disk.</p><p>This offers the greatest powersaving but"
" considerable time is required to reactivate the system again.</p><p>This correspond to ACPI S4 mode.</p><p>Also known as Suspend-to-Disk mode.</p></qt>"));
btnHibernate->setFont( btnFont );
buttonlay->addWidget( btnHibernate );
connect(btnHibernate, TQ_SIGNAL(clicked()), TQ_SLOT(slotHibernate()));
}
if (canHybridSuspend && !disableSuspend && !disableHibernate)
{
KPushButton* btnHybridSuspend = new KPushButton( KGuiItem( i18n("H&ybrid Suspend"), "hibernate"), frame );
TQToolTip::add(btnHybridSuspend, i18n("<qt><p>Put the computer in both suspend-to-memory and"
" suspend-to-disk mode. The system is stopped and its state saved to memory and to disk.</p>"
"<p>This offers the best of both 'Suspend' and 'Hibernate' modes combined together. The system is"
" de facto in 'Suspend' mode but if power is lost, work can still be resumed as if the system"
" had been hibernated, preventing any data loss.</p><p>This correspond to ACPI S3+S4 mode.</p>"
"<p>Also known as Suspend-to-RAM + Suspend-to-Disk mode.</p></qt>"));
btnHybridSuspend->setFont( btnFont );
buttonlay->addWidget( btnHybridSuspend );
connect(btnHybridSuspend, TQ_SIGNAL(clicked()), TQ_SLOT(slotHybridSuspend()));
}
buttonlay->addStretch( 1 );
// Separator
buttonlay->addWidget( new KSeparator( frame ) );
// Back to Desktop
KPushButton* btnBack = new KPushButton( KStdGuiItem::cancel(), frame );
buttonlay->addWidget( btnBack );
connect(btnBack, TQ_SIGNAL(clicked()), TQ_SLOT(reject()));
}
}
else {
// finish the dialog correctly
if(doUbuntuLogout)
{
// cancel buttonbox
TQHBoxLayout* hbuttonbox3 = new TQHBoxLayout( vbox, factor * KDialog::spacingHint() );
hbuttonbox3->setAlignment( TQt::AlignRight );
// Back to Desktop
KSMPushButton* btnBack = new KSMPushButton( KStdGuiItem::cancel(), frame );
hbuttonbox3->addWidget( btnBack );
connect(btnBack, TQ_SIGNAL(clicked()), TQ_SLOT(reject()));
}
else
{
// Separator
buttonlay->addWidget( new KSeparator( frame ) );
// Back to Desktop
KPushButton* btnBack = new KPushButton( KStdGuiItem::cancel(), frame );
buttonlay->addWidget( btnBack );
connect(btnBack, TQ_SIGNAL(clicked()), TQ_SLOT(reject()));
}
}
}
KSMShutdownDlg::~KSMShutdownDlg()
{
}
void KSMShutdownDlg::slotLogout()
{
m_shutdownType = TDEApplication::ShutdownTypeNone;
accept();
}
void KSMShutdownDlg::slotReboot()
{
// no boot option selected -> current
m_bootOption = TQString::null;
m_shutdownType = TDEApplication::ShutdownTypeReboot;
accept();
}
void KSMShutdownDlg::slotReboot(int opt)
{
if (int(rebootOptions.size()) > opt)
m_bootOption = rebootOptions[opt];
m_shutdownType = TDEApplication::ShutdownTypeReboot;
accept();
}
void KSMShutdownDlg::slotHalt()
{
m_bootOption = TQString::null;
m_shutdownType = TDEApplication::ShutdownTypeHalt;
accept();
}
void KSMShutdownDlg::slotSuspend()
{
*m_selection = SuspendType::Suspend;
reject(); // continue on resume
}
void KSMShutdownDlg::slotHibernate()
{
*m_selection = SuspendType::Hibernate;
reject(); // continue on resume
}
void KSMShutdownDlg::slotFreeze()
{
*m_selection = SuspendType::Freeze;
reject(); // continue on resume
}
void KSMShutdownDlg::slotHybridSuspend()
{
*m_selection = SuspendType::HybridSuspend;
reject(); // continue on resume
}
bool KSMShutdownDlg::confirmShutdown( bool maysd, bool mayrb, TDEApplication::ShutdownType& sdtype, TQString& bootOption, int* selection )
{
kapp->enableStyles();
KSMShutdownDlg* l = new KSMShutdownDlg( 0 /*KSMShutdownFeedback::self()*/, maysd, mayrb, sdtype, selection );
// Show dialog (will save the background in showEvent)
TQSize sh = l->sizeHint();
TQRect rect = TDEGlobalSettings::desktopGeometry(TQCursor::pos());
l->move(rect.x() + (rect.width() - sh.width())/2, rect.y() + (rect.height() - sh.height())/2);
bool result = l->exec();
sdtype = l->m_shutdownType;
bootOption = l->m_bootOption;
delete l;
kapp->disableStyles();
return result;
}
TQWidget* KSMShutdownIPDlg::showShutdownIP()
{
kapp->enableStyles();
KSMShutdownIPDlg* l = new KSMShutdownIPDlg( 0 );
kapp->disableStyles();
return l;
}
void KSMShutdownIPDlg::showNotificationActionButtons()
{
m_button1->show();
m_button2->show();
m_buttonframe->show();
m_gridlayout->invalidate();
}
void KSMShutdownIPDlg::hideNotificationActionButtons()
{
m_button1->hide();
m_button2->hide();
m_buttonframe->hide();
m_gridlayout->invalidate();
}
void KSMShutdownIPDlg::setNotificationActionButtonsSkipText(TQString text)
{
m_button1->setText(text);
}
void KSMShutdownIPDlg::setProgressBarTotalSteps(int total_steps)
{
m_progressbar->setTotalSteps(total_steps);
}
void KSMShutdownIPDlg::setProgressBarProgress(int step)
{
m_progressbar->setProgress(step);
}
KSMShutdownIPDlg::KSMShutdownIPDlg(TQWidget* parent)
: KSMModalDialog( parent )
{
m_progressbar = new TQProgressBar(this);
m_progressbar->show();
m_gridlayout->expand(4,3);
m_gridlayout->remove(m_buttonframe);
m_gridlayout->addMultiCellWidget( m_progressbar, 3, 3, 0, 2);
m_gridlayout->addMultiCellWidget( m_buttonframe, 4, 4, 0, 2, 0 );
m_gridlayout->invalidate();
setFixedSize(sizeHint());
setStatusMessage(i18n("Saving your settings..."));
setNotificationActionButtonsSkipText(i18n("Skip Notification"));
m_button2->setText(i18n("Abort Logout"));
connect(m_button1, TQ_SIGNAL(clicked()), this, TQ_SIGNAL(skipNotificationClicked()));
connect(m_button2, TQ_SIGNAL(clicked()), this, TQ_SIGNAL(abortLogoutClicked()));
show();
setActiveWindow();
// KWin::setOnAllDesktops( winId(), true );
}
KSMShutdownIPDlg::~KSMShutdownIPDlg()
{
}
KSMDelayedPushButton::KSMDelayedPushButton( const KGuiItem &item,
TQWidget *parent,
const char *name)
: KPushButton( item, parent, name), pop(0), popt(0)
{
connect(this, TQ_SIGNAL(pressed()), TQ_SLOT(slotPressed()));
connect(this, TQ_SIGNAL(released()), TQ_SLOT(slotReleased()));
popt = new TQTimer(this);
connect(popt, TQ_SIGNAL(timeout()), TQ_SLOT(slotTimeout()));
}
void KSMDelayedPushButton::setPopup(TQPopupMenu *p)
{
pop = p;
setIsMenuButton(p != 0);
}
void KSMDelayedPushButton::slotPressed()
{
if (pop)
popt->start(TQApplication::startDragTime());
}
void KSMDelayedPushButton::slotReleased()
{
popt->stop();
}
void KSMDelayedPushButton::slotTimeout()
{
TQPoint bl = mapToGlobal(rect().bottomLeft());
pop->popup( bl );
popt->stop();
setDown(false);
}
KSMDelayedMessageBox::KSMDelayedMessageBox( TDEApplication::ShutdownType sdtype, const TQString &bootOption, int confirmDelay )
: TimedLogoutDlg( 0, 0, true, (WFlags)WType_Popup ), m_remaining(confirmDelay)
{
if ( sdtype == TDEApplication::ShutdownTypeHalt )
{
m_title->setText( i18n( "Would you like to turn off your computer?" ) );
m_template = i18n( "This computer will turn off automatically\n"
"after %1 seconds." );
m_logo->setPixmap( BarIcon( "system-log-out", 48 ) );
} else if ( sdtype == TDEApplication::ShutdownTypeReboot )
{
if (bootOption.isEmpty())
m_title->setText( i18n( "Would you like to reboot your computer?" ) );
else
m_title->setText( i18n( "Would you like to reboot to \"%1\"?" ).arg(bootOption) );
m_template = i18n( "This computer will reboot automatically\n"
"after %1 seconds." );
m_logo->setPixmap( BarIcon( "reload", 48 ) );
} else {
m_title->setText( i18n( "Would you like to end your current session?" ) );
m_template = i18n( "This session will end\n"
"after %1 seconds automatically." );
m_logo->setPixmap( BarIcon( "go-previous", 48 ) );
}
updateText();
adjustSize();
if ( double( height() ) / width() < 0.25 )
{
setFixedHeight( tqRound( width() * 0.3 ) );
adjustSize();
}
TQTimer *timer = new TQTimer( this );
timer->start( 1000 );
connect( timer, TQ_SIGNAL( timeout() ), TQ_SLOT( updateText() ) );
KDialog::centerOnScreen(this);
}
void KSMDelayedMessageBox::updateText()
{
m_remaining--;
if ( m_remaining == 0 )
{
accept();
return;
}
m_text->setText( m_template.arg( m_remaining ) );
}
bool KSMDelayedMessageBox::showTicker( TDEApplication::ShutdownType sdtype, const TQString &bootOption, int confirmDelay )
{
kapp->enableStyles();
KSMDelayedMessageBox msg( sdtype, bootOption, confirmDelay );
TQSize sh = msg.sizeHint();
TQRect rect = TDEGlobalSettings::desktopGeometry(TQCursor::pos());
msg.move(rect.x() + (rect.width() - sh.width())/2,
rect.y() + (rect.height() - sh.height())/2);
bool result = msg.exec();
kapp->disableStyles();
return result;
}
KSMPushButton::KSMPushButton( const KGuiItem &item,
TQWidget *parent,
const char *name)
: KPushButton( item, parent, name),
m_pressed(false)
{
setDefault( false );
setAutoDefault ( false );
}
void KSMPushButton::keyPressEvent( TQKeyEvent* e )
{
switch ( e->key() )
{
case Key_Enter:
case Key_Return:
case Key_Space:
m_pressed = TRUE;
setDown(true);
emit pressed();
break;
case Key_Escape:
e->ignore();
break;
default:
e->ignore();
}
TQPushButton::keyPressEvent(e);
}
void KSMPushButton::keyReleaseEvent( TQKeyEvent* e )
{
switch ( e->key() )
{
case Key_Space:
case Key_Enter:
case Key_Return:
if ( m_pressed )
{
setDown(false);
m_pressed = FALSE;
emit released();
emit clicked();
}
break;
case Key_Escape:
e->ignore();
break;
default:
e->ignore();
}
}
FlatButton::FlatButton( TQWidget *parent, const char *name )
: TQToolButton( parent, name/*, TQt::WNoAutoErase*/ ),
m_pressed(false)
{
init();
}
FlatButton::~FlatButton() {}
void FlatButton::init()
{
setUsesTextLabel(true);
setUsesBigPixmap(true);
setAutoRaise(true);
setTextPosition( TQToolButton::Under );
setFocusPolicy(TQWidget::StrongFocus);
}
void FlatButton::keyPressEvent( TQKeyEvent* e )
{
switch ( e->key() )
{
case Key_Enter:
case Key_Return:
case Key_Space:
m_pressed = TRUE;
setDown(true);
emit pressed();
break;
case Key_Escape:
e->ignore();
break;
default:
e->ignore();
}
TQToolButton::keyPressEvent(e);
}
void FlatButton::keyReleaseEvent( TQKeyEvent* e )
{
switch ( e->key() )
{
case Key_Space:
case Key_Enter:
case Key_Return:
if ( m_pressed )
{
setDown(false);
m_pressed = FALSE;
emit released();
emit clicked();
}
break;
case Key_Escape:
e->ignore();
break;
default:
e->ignore();
}
}
|