summaryrefslogtreecommitdiffstats
path: root/control-center
blob: 1da3b75f70fe4eb2889dff04e5abab8af90de44d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
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
#!/usr/bin/perl
# $Id$

# Copyright (C) 1999-2003 MandrakeSoft
#                         Daouda Lo <daouda@mandrakesoft.com>
#                         Damien Krotkine
#                         Thierry Vignaud <tvignaud@mandrakesoft.com>
#                         Yves Duret
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.


use strict;
use diagnostics;
use lib qw(/usr/lib/libDrakX);
use standalone;
use common;
use detect_devices;
use lang;
use network::netconnect; # for profiles

# i18n: IMPORTANT: to get correct namespace (drakconf instead of libDrakX)
BEGIN { unshift @::textdomains, 'drakconf' }
use ugtk2 qw(:create :dialogs :helpers :wrappers);


#-------------------------------------------------------------
# paths
my ($bindir, $sbindir, $xbindir)  = ("/usr/bin", "/usr/sbin", "/usr/X11R6/bin");
my $mcc_dir = "/usr/share/mcc";
my $themes_dir = "$mcc_dir/themes/";

my (%tool_pids, %tool_feedback);

my ($version, $conffile, $class_install) = ("9.2", "/etc/mcc.conf", "/etc/sysconfig/system");
my ($default_heigth, $default_width) = (523, 720);


require_root_capability(); # just to get root capabilities


#-------------------------------------------------------------
# read configuration, set themes, ...
my %h = getVarsFromSh($conffile);
my %class = getVarsFromSh($class_install);
$h{THEME} ||= 'default';
$h{LOGS} ||= bool2text($class{CLASS} eq 'expert' ? 1 : 0);
$h{EXPERT_WIZARD} ||= 0;
$h{HEIGTH} ||= $default_heigth;
$h{WIDTH}  ||= $default_width;

my %option_values;
$option_values{show_log} = text2bool($h{LOGS});
my $theme = $h{THEME};
$theme = $1 if "@ARGV" =~ /--theme (\w+)/;
-d "$themes_dir/$theme" or $theme = 'default';
add_icon_path("$themes_dir/$theme/");
add_icon_path("$themes_dir/default") if $theme ne 'default'; # fall back if theme miss some icons

my $rc = find { -r $_ } ("$themes_dir/$theme/gtkrc", if_($theme ne 'default', "$themes_dir/default/gtkrc"));
Gtk2::Rc->parse($rc) if -r $rc;

#-------------------------------------------------------------
# Splash window:   please wait ...
my $window_splash = Gtk2::Window->new('popup');
$window_splash->signal_connect(delete_event => \&quit_global);
$window_splash->set_title(N("Mandrake Control Center") . $version);
$window_splash->set_position('center_always');
$window_splash->add(gtkadd(gtkset_shadow_type(Gtk2::Frame->new, 'etched_out'),
                           gtkpack(Gtk2::VBox->new(0, 0),
                                   if_(-r "$themes_dir/$theme/splash_screen.png", gtkcreate_img("splash_screen")),
                                   Gtk2::Label->new(N("Loading... Please wait"))
                                   )
                           )
                    );
$window_splash->show_all;
gtkflush();



#-------------------------------------------------------------
# Data structures

my $isWiz = -e "/usr/sbin/drakwizard";
my $isRpmDrake = -e "/usr/sbin/rpmdrake";
my $isWebAdmin = -e "/usr/bin/mdkwebadmin";

# { key => [ log_exp, binary, gtkplug?, description ] }
# { key => [ log_exp, [ binary, win_nb ], gtkplug?, description ] }
# gtkplug meaning: -1 => not embedded, 0 => external x11 app, 1 => proper embedding
my $exec_hash =
{
    "Auto Install" => [ "drakautoinst", "$sbindir/drakautoinst", 1, N("Auto Install floppy") ],
    "Auto login Config" => [ "drakboot", "$sbindir/drakboot", 1, N("Autologin") ],
    "Backups" => [ "drakbackup", "$sbindir/drakbackup", 1, N("Backups") ],
    "Boot Config" => [ "drakboot", "$sbindir/drakboot --boot", 1, N("Bootstrapping") ],
    "Boot Theme" => [ "drakboot", "$sbindir/drakboot --splash", 1, N("Boot theme") ],
    "Boot Disk" => [ "drakfloppy", "$sbindir/drakfloppy", 1, N("Boot floppy") ],
    "Connection Sharing" => [ "drakgw", "$sbindir/drakgw", 1, N("Internet connection sharing") ],
    "Add Connection" => [ "drakconnect", "$sbindir/drakconnect --wizard", 1, N("New connection") ],
    "Manage Connection" => [ "drakconnect", "$sbindir/drakconnect --skip-wizard", 1, N("Manage connections") ],
    "Monitor Connection" => [ "net_monitor", "$sbindir/net_monitor", 1, N("Monitor connections") ],
    "Configure Internet" => [ "drakconnect", "$sbindir/drakconnect --internet", 1, N("Internet access") ],
    # little workaround to avoid drakconf freeze
    "Console" => [ "rxvt", "$xbindir/rxvt", -1, N("Console") ], #The Console will help you to solve issues
#    "Console" => [ "rxvt", [ "$xbindir/rxvt", "rxvt", 1 ], 0, N("Console") ], #The Console will help you to solve issues
    "Date & Time" => [ "clock", "$sbindir/clock.pl", 1, N("Date and time") ],
    "Display Manager chooser" =>  [ "drakedm",  "$sbindir/drakedm", 1, N("Display manager") ],
    "Firewall" => [ "drakfirewall", "$sbindir/drakfirewall", 1, N("Firewall") ],
    "Fonts" => [ "drakfont", "$sbindir/drakfont", 1, N("Fonts") ],
    "Graphical server configuration" => [ "XFdrake", "$sbindir/XFdrake", 1, N("Graphical server") ],
    "Hard Drives" => [ "diskdrake", "$sbindir/diskdrake --hd", 1, N("Partitions") ],
    "Hardware List" => [ "harddrake", "$sbindir/harddrake2", 1, N("Hardware") ],
    "Install Software" => [ "rpmdrake", "$sbindir/rpmdrake", -1, N("Install") ],
    "Keyboard" => [ "keyboarddrake", "$sbindir/keyboarddrake", 1, N("Keyboard") ],
    "Logs" => [ "logdrake", "$sbindir/logdrake", 1, N("Logs") ],
    "Mandrake Update" => [ "rpmdrake", "$sbindir/MandrakeUpdate", -1, N("Updates") ],
    "Menus" => [ "menudrake", "$bindir/menudrake", -1,  N("Menus"), "$bindir/menudrake" ],
    "Monitor" => [ "XFdrake", "$sbindir/XFdrake monitor", 1, N("Monitor") ],
    "Mouse" => [ "mousedrake", "$sbindir/mousedrake", 1, N("Mouse") ],
    "NFS mount points" => [ "diskdrake", "$sbindir/diskdrake --nfs", 1, N("NFS mount points") ],
    "Partition Sharing" => [ "diskdrake", "$sbindir/diskdrake --fileshare", 1, N("Local disk sharing") ],
    "Printer" => [ "printerdrake", "$sbindir/printerdrake", -1, N("Printers"), "$sbindir/printerdrake" ],
    "Programs scheduling" => [ "drakcronat", "/usr/X11R6/bin/drakcronat", 1, N("Scheduled tasks") ], #DrakCronAt enables to schedule Programs execution through crond and atd daemons
    "Proxy Configuration" => [ "drakproxy", "$sbindir/drakproxy", 1, N("Proxy") ], #for files and web browsing
    "Remove Interface" => [ "drakconnect", "$sbindir/drakconnect --del", 1, N("Remove a connection") ],
    "Remove Software" => [ "rpmdrake", "$sbindir/rpmdrake-remove", -1, N("Remove") ],
    "Resolution" => [ "XFdrake", "$sbindir/XFdrake resolution", 1, N("Screen resolution") ],
    "Samba mount points" => [ "diskdrake", "$sbindir/diskdrake --smb", 1, N("Samba mount points") ],
    "Scanner" => [ "scannerdrake", "$sbindir/scannerdrake", 1, N("Scanners") ],
    "Security Level" => [ "draksec", "$sbindir/draksec", 1, N("Level and checks") ],
    "Security Permissions" => [ "drakperm",  "$sbindir/drakperm", 1, N("Permissions") ],
    "Services" => [ "drakxservices", "$sbindir/drakxservices", 1, N("Services") ],
    "Software Media Manager" => [ "rpmdrake", "$sbindir/edit-urpm-sources.pl", -1, N("Media Manager") ],
    "TV Cards" => [ "drakxtv", "$sbindir/drakxtv", 1, N("TV card") ],
    "Users" => [ "userdrake", "$bindir/userdrake", -1, N("Users and groups") ], # too big
    "WebDAV mount points" => [ "diskdrake", "$sbindir/diskdrake --dav", 1, N("WebDAV mount points") ],
};

# [ [ class_label, class icon name, [ [ program_label, program icon name ] ... ] ] ]
my @tree =
    ([ N("Boot"), 'boot-mdk',
       [
        if_(detect_devices::floppies, [ "Boot Disk", 'drakfloppy-mdk',  ]),
        [ "Auto login Config", 'drakboot-mdk',  ],
        [ "Boot Config", 'drakboot-mdk',  ],
        [ "Auto Install", 'drakautoinst-mdk',  ],
        ]
       ],
     [ N("Hardware"), 'drakhard-mdk',
       [
        [ "Hardware List", 'harddrake-mdk',  ],
        [ "Monitor", 'configure-monitor-mdk',  ],
        [ "Resolution", 'resolution-mdk',  ],
        [ "Graphical server configuration", 'XFdrake-mdk',  ],
        [ "TV Cards", 'tv-mdk',  ],
        [ "Keyboard", 'keyboard-mdk',  ],
        [ "Mouse", 'mousedrake-mdk',  ],
        [ "Printer", 'printer-mcc-mdk',  ],
        [ "Scanner", 'scanner-mdk',  ],
        ]
       ],
     [ N("Mount Points"), 'partition-mdk',
       [
        [ "Hard Drives", 'diskdrake_hd',  ],
        (map {
            my ($type, $name, $scan, $text) = @$_;
            map_index {
                my $full_name = $name . ($::i ? $::i + 1 : '');
                $exec_hash->{$full_name} = [ "diskdrake", "$sbindir/diskdrake --removable=$_->{device}", 1, $text ];
                [ $full_name, "diskdrake_$type" ];
            } $scan->();
        } do {
            my %cdroms_by_type;
            foreach (detect_devices::cdroms()) {
                my $type = detect_devices::isBurner($_) ? 'burner' : detect_devices::isDvdDrive($_) ? 'DVD' : 'cdrom';
                push @{$cdroms_by_type{$type}}, $_;
            } ([ 'cdrom', N("CD-ROM"), sub { @{$cdroms_by_type{cdrom} || []} }, N("CD-ROM") ],
               [ 'dvd', N("DVD"), sub { @{$cdroms_by_type{DVD} || []} }, N("DVD-ROM") ],
               [ 'cdwriter', N("CD Burner"), sub { @{$cdroms_by_type{burner} || []} }, N("CD/DVD") ],
               [ 'floppy', N("Floppy"), \&detect_devices::floppies, N("Floppy drive") ],
               [ 'zip', N("Zip"), \&detect_devices::zips, N("ZIP drive") ],
               ),
        }),
        [ "NFS mount points", 'diskdrake_nfs',  ],
        [ "Samba mount points", 'diskdrake_samba',  ],
        [ "WebDAV mount points", 'webdav-mdk',  ],
        [ "Partition Sharing", 'diskdrake_fileshare',  ],
        ]
       ],
     [ N("Network & Internet"), 'net-mdk',
       [
        [ "Add Connection", 'drakconnect-mdk',  ],
        [ "Configure Internet", 'drakconnect-mdk',  ],
        [ "Manage Connection", 'drakconnect-mdk',  ],
        [ "Monitor Connection", 'drakconnect-mdk',  ],
        [ "Remove Interface", 'drakconnect-mdk',  ],
        [ "Proxy Configuration", 'drakproxy-mdk',  ],
        [ "Connection Sharing", 'drakgw-mdk',  ],
        ],
       ],
     [ N("Security"), 'security-mdk',
       [
        [ "Security Level", 'draksec-mdk',  ],
        [ "Security Permissions", 'drakperm-mdk',  ],
        [ "Firewall", 'firewall-mdk',  ],
        ]
       ],
     [ N("System"), 'system-mdk',
       [
        [ "Menus" , 'menudrake-mdk',  ],
        [ "Display Manager chooser", 'drakedm-mdk',  ],
        [ "Services" , 'service-mdk',  ],
        [ "Fonts", 'drakfont-mdk',  ],
        [ "Date & Time" , 'time-mdk',  ],
        [ "Logs", 'logdrake-mdk',  ],
        if_($ENV{LANGUAGE} !~ /^zh/, [ "Console", 'console-mdk',  ]),
        [ "Users", 'user-mdk',  ],
#        [ "Programs scheduling", 'drakcronat-mdk',  ],
        [ "Backups", 'backup-mdk',  ],
#      [ "RFBDrake", 'unknown-mdk' ],
        ]
       ],
     if_($isRpmDrake,
         [ N("Software Management"), 'software',
           [
            [ "Install Software", 'rpmdrake' ],
            [ "Remove Software", 'rpmdrake-remove' ],
            [ "Mandrake Update", 'MandrakeUpdate' ],
            [ "Software Media Manager", 'source-manager' ],
            ]
           ]),
     if_($isWiz,
         [ N("Server wizards"), 'wizard-mdk',
           [
            (map {
                my ($id, $wizard, $icon, $description) = @$_;
                $exec_hash->{$id} = [ "drakwizard", "$sbindir/drakwizard $wizard", 1, $description ];
                [ $id, $icon ];
            } (# [ id, wizard file name, icon, description ]
               [ "DHCP wizard",       "dhcp", 'dhcp_server-mdk', N("Configure DHCP") ],
               [ "DNS Client wizard", "bind_client", 'dns_client-mdk', N("Add a DNS client") ],
               [ "DNS wizard",        "bind", 'dns_server-mdk', N("Configure DNS") ],
               [ "FTP wizard",        "proftpd", 'ftp-mdk', N("Configure FTP") ],
               [ "News wizard",       "inn", 'news-mdk', N("Configure news") ],
               [ "Postfix wizard",    "postfix", 'postfix-mdk', N("Configure mail") ],
               [ "Squid wizard",      "squid", 'drakproxy-mdk', N("Configure proxy") ],
               [ "Samba wizard",      "samba", 'samba_server-mdk', N("Configure Samba") ],
               [ "Time wizard",       "ntp", 'ntp_server-mdk', N("Configure time") ],
               [ "Web wizard",        "apache2", 'web_server-mdk', N("Configure web") ])
            )
           ]
         ]),
     if_($isWebAdmin,
         [ N("Online Administration"), 'net-mdk',
           [
            (map {
                my ($id, $icon, $op, $description) = @$_;
                $exec_hash->{$id} = [ "mdkwebadmin", "$bindir/mdkwebadmin.pl $op", -1, $description ];
                [ $id, $icon ];
         } (# [ id, wizard file name, icon, description ]
            [ "Local Admin", 'XFdrake-mdk', '--direct', N("Local administration") ],
            [ "Remote Admin", 'drakconnect-mdk', '--link', N("Remote administration") ])
          )
            ]
           ]),
     );


#-------------------------------------------------------------
# let build the GUI

# main window :

my ($timeout, %check_boxes, $emb_socket, $page_id);

my $window_global = gtkset_size_request(Gtk2::Window->new('toplevel'), $default_width, $default_heigth);
$window_global->resize($h{WIDTH}, $h{HEIGTH});
$window_global->set_icon(gtkcreate_pixbuf("/usr/share/icons/drakconf.png"));

my $pending_app = 0;

my $help_on_context = 'drakconf-intro';
#Please replace with correct contextual help page
my @ctx = qw(drakconf-intro mcc-boot mcc-hardware mcc-mountpoints mcc-network mcc-security mcc-system software-management wiz-client);

my @themes = grep { -d "$themes_dir/$_" } all($themes_dir);

#-PO Translators, please keep all "/" charaters !!!
my %options = (
    'show_log' => [ N("/_Options"), N("/Display _Logs")  ],
    'embedded_mode' => [ N("/_Options"), N("/_Embedded Mode") ],
    'wiz_expert' => [ N("/_Options"), N("/Expert mode in _wizards") ],
);

my %shared_translations = (
                           "profiles" => N("/_Profiles"),
                           "delete" => N("/_Delete"),
                           "new" => N("/_New"),
                          );

# for profiles:
my ($netcnx, $netc, $intf)  = ({}, {}, {});
my @profiles;

my $mdk_rel = common::mandrake_release();


my @menu_items = (
                  [ N("/_File"), undef, undef, undef, '<Branch>' ],
                  [ N("/_File") . N("/_Quit"), N("<control>Q"), \&quit_global, undef, '<StockItem>', N("Quit") ],
                  [ N("/_Options"), undef, undef, undef, '<Branch>' ],
                  [ join('', @{$options{show_log}}), undef,
                    sub  {
                        $option_values{show_log} = $check_boxes{show_log}->get_active;
                        start_logdrake();
                    },
                    undef, '<CheckItem>'
                  ],
                  if_(0 && $isWiz,
                      [ join('', @{$options{wiz_expert}}), undef,
                        sub { $option_values{expert_wizard} = $check_boxes{wiz_expert}->get_active },
                        undef, '<CheckItem>',
                      ],
                     ),
                  if_(@themes > 1,
                      [ N("/_Themes"), undef, undef, undef, '<Branch>' ],
                      (map {
                          my $name = $_;
                          [ N("/_Themes") . "/" .  ($name eq $theme ? " O  " : "      ") . "_$_", undef,
                            sub {
                                return if $theme eq $name;
                                !$pending_app || splash_warning(N("This action will restart the control center.\nAny change not applied will be lost."), 1) and do {
                                    # embedded app must be killed
                                    kill_children();
                                    kill_logdrake();
                                    child_just_exited();
                                    exec "$0 --theme $name";
                                };
                            }, undef, '<CheckItem>'
                          ]
                      } @themes),
                      [ N("/_Themes").N("/_More themes"), undef, \&more_themes, undef, '<Item>' ]
                     ),
                  [ $shared_translations{profiles}, undef, undef, undef, '<Branch>' ],
                  [ $shared_translations{profiles} . $shared_translations{new}, undef, sub {
                        my $dialog = _create_dialog(N("New profile..."), { small => 1, transient => $window_global });
                        my $entry_dialog = Gtk2::Entry->new;
                        gtkpack($dialog->vbox,
                                Gtk2::WrappedLabel->new(N("Name of the profile to create (the new profile is created as a copy of the current one):")),
                                $entry_dialog,
                               );
                        gtkpack($dialog->action_area,
                                gtksignal_connect(Gtk2::Button->new(N("Cancel")), 
                                                  clicked => sub { $dialog->destroy }),
                                gtksignal_connect(my $bok = Gtk2::Button->new(N("Ok")), clicked => sub {
                                                      my $prof = $entry_dialog->get_text;
                                                      # netprofile does not like spaces in profile names...
                                                      $prof =~ s/ /_/g;
                                                      # warn if already existing:
                                                      if (member($prof, @profiles)) {
                                                          err_dialog(N("Error"), N("The \"%s\" profile already exists!", $prof),
                                                                    { transient => $dialog });
                                                          return 1;
                                                      }
                                                      network::netconnect::add_profile($netcnx, $prof);
                                                      update_profiles();
                                                      $dialog->destroy;
                                                  }),
                               );
                        $bok->can_default(1);
                        $bok->grab_default;
                        $dialog->show_all;
                        $dialog->run;
                        update_profiles();
                    }, undef, '<Item>' ],
                  
                  [ $shared_translations{profiles} . $shared_translations{delete}, undef, sub {
                        return if !$window_global->realized && $netcnx->{PROFILE} ne "default";
                        my $dialog = _create_dialog(N("Delete profile"), { stock => 'gtk-dialog-warning' });
                        gtkpack($dialog->vbox,
                                Gtk2::Label->new(N("Profile to delete:")),
                                my $combo_dialog = Gtk2::OptionMenu->new,
                               );
                        $combo_dialog->set_popdown_strings(grep { ! /default/ } network::netconnect::get_profiles());
                        gtkpack($dialog->action_area,
                                gtksignal_connect(Gtk2::Button->new(N("Cancel")), clicked => sub { $dialog->destroy }),
                                gtksignal_connect(Gtk2::Button->new(N("Ok")), clicked => sub {
                                                      my $profile2delete = $combo_dialog->entry->get_text;
                                                      if ($profile2delete eq $netcnx->{PROFILE}) {
                                                          err_dialog(N("Warning"), N("You can not delete the current profile"));
                                                          return 1;
                                                      }
                                                      $dialog->destroy;
                                                      Gtk2->main_quit;
                                                      network::netconnect::del_profile($profile2delete);
                                                      update_profiles(1);
                                                  }),
                               );
                        $dialog->show_all;
                        $dialog->run;
                        return;
                    }, undef, '<Item>' ],

                  [ join('/', $shared_translations{profiles}, ""), undef, undef, undef, '<Separator>' ],
                  [ N("/_Help"), undef, undef, undef, '<Branch>' ],
                  [ N("/_Help").N("/_Help"), undef,  sub { fork_("drakhelp --id $help_on_context") }, undef, '<StockItem>', N("Help") ],
                  [ N("/_Help").N("/_Report Bug"), undef, sub { fork_("drakbug --report drakconf &") }, undef, '<Item>' ],
                  [ N("/_Help").N("/_About..."), undef, \&about_mdk_cc, undef, '<Item>' ]
                 );

my ($menu, $factory) = create_factory_menu($window_global, @menu_items);

network::netconnect::read_net_conf('', $netcnx, $netc);

# to retrieve a path, one must prevent "accelerators completion":
sub get_path { join('', map { my $i = $_; $i =~ s/_//; $i } @_) }

# menus do not like "_" from profiles (whereas netprofile does not like spaces in profile names...)
sub profile2menu {
    my ($profile) = @_;
    $profile =~ s/_/ /g;
    "/$profile";
}
    
sub enable_profile_entry {
    my ($profile, $value) = @_;
    eval {
        $factory->get_widget(get_path("<main>", $shared_translations{profiles} . profile2menu($profile)))->set_active($value);
    };
    print "error: $@\n" if $@;
}


# update profiles list
sub update_profiles {
    my ($removing) = @_;
    my $done;
    $factory->delete_item(get_path("<main>", $shared_translations{profiles} . profile2menu($_))) foreach @profiles;
    network::netconnect::load_conf($netcnx, $netc, $intf);    #reread_net_conf();
    @profiles = network::netconnect::get_profiles();
    foreach my $prof (@profiles) {
        $factory->create_item([ $shared_translations{profiles} . profile2menu($prof), undef, sub {
                                    return unless $done;
                                    if ($netcnx->{PROFILE} eq $prof) {
                                        $done = 0;
                                        enable_profile_entry($prof, 1);
                                        $done = 1;
                                        return 0;
                                    }
                                    if (!warn_dialog(N("Warning"), 
                                                     N("We are about to switch from the \"%s\" profile to the \"%s\" profile.

Are you sure you want to do the switch?", $netcnx->{PROFILE}, $prof), { transient => $window_global })) {
                                        $done = 0;
                                        enable_profile_entry($prof, 0);
                                        $done = 1;
                                        return;
                                    }
                                    # wait message is needed
                                    $done = 0;
                                    enable_profile_entry($netcnx->{PROFILE}, 0);
                                    $netcnx->{PROFILE} = $prof;
                                    network::netconnect::save_profile($netcnx);
                                    network::netconnect::set_profile($netcnx);
                                    enable_profile_entry($prof, 1) if !$removing;
                                    $done = 1;
                            }, undef, '<CheckItem>' ]); # Radio
    }
    $factory->get_widget(get_path("<main>", $shared_translations{profiles}, $shared_translations{delete}))->set_sensitive(@profiles > 1);
    eval { $factory->get_widget(get_path("<main>", $shared_translations{profiles} . profile2menu($netcnx->{PROFILE})))->set_active(1) };
    print "error is «$@»\n" if $@;
    $done = 1;
}

update_profiles();

%check_boxes = map {
    $_ => $factory->get_widget("<main>" . get_path(@{$options{$_}}))
} ("show_log", if_(0 && $isWiz, "wiz_expert"));


gtkadd($window_global,
       gtkpack_(Gtk2::VBox->new(0, 0),
                0, $menu,
                # 0, gtkset_size_request(Gtk2::VBox->new(10, 10), -1, 2),
                1, gtkpack_(Gtk2::VBox->new(0, 0),
                            0, my $banner_notebook = gtkset_size_request(Gtk2::Notebook->new, -1, 75),
                            0, Gtk2::HSeparator->new,
                            1, my $notebook_global = gtkset_name(Gtk2::Notebook->new, 'mcc'),
                            1, gtkset_name(
                                           # FIXME: move emb_frame as a notebook page instead
                                           gtkadd(my $emb_frame = Gtk2::EventBox->new,
                                                         gtkpack_(my $emb_box = Gtk2::VBox->new(0, 0),
                                                                  1, gtkpack_(my $emb_wait = Gtk2::VBox->new(0, 0),
                                                                              1, Gtk2::HBox->new(0, 0),
                                                                              0, gtkpack_(Gtk2::HBox->new(0, 0),
                                                                                          1, Gtk2::VBox->new(0, 0),
                                                                                          0, my $run_darea = gtkset_size_request(Gtk2::DrawingArea->new, 128, 128),
                                                                                          1, Gtk2::VBox->new(0, 0),
                                                                                         ),
                                                                              0, Gtk2::Label->new(N("Please wait...")),
                                                                              1, Gtk2::HBox->new(0, 0),
                                                                             ),
                                                                 ),
                                                 ),
                                           'mcc'),
                            0, Gtk2::HSeparator->new,
                           ),
                0, my $buttons = gtkadd(gtkset_layout(Gtk2::HButtonBox->new, 'end'),
                                        map { gtkset_border_width($_, 3) }
                                        gtkset_sensitive(gtkset_relief(Gtk2::Button->new(""), 'none'), 0),
                                        gtksignal_connect(my $cancel = Gtk2::Button->new(N("Cancel")), 
                                                          clicked => sub { 
                                                              Glib::Source->remove($timeout) if $timeout; kill_children(); 
                                                              child_just_exited();
                                                          }),
                                        gtksignal_connect(my $previous = Gtk2::Button->new(N("Previous")),
                                                          clicked => sub {
                                                              $page_id = 0;
                                                              warn_on_startup();
                                                          },
                                                         ),
                                       ),
               )
      );


$window_global->signal_connect(delete_event => \&quit_global);

use POSIX qw(:sys_utsname_h :math_h :sys_wait_h :unistd_h);
my (undef, $nodename) = POSIX::uname();
$window_global->set_title(N("Mandrake Control Center %s [on %s]", $version, $nodename));
$window_global->set_position('center');

foreach my $notebook ($notebook_global, $banner_notebook) {
    $notebook->set_property('show-border', 0);
    $notebook->set_property('show-tabs', 0);
}


# banner :

my $font = N("_banner font:\nSans 15");
add2notebook($banner_notebook, "", Gtk2::Banner->new("title-back", "/usr/share/icons/large/drakconf.png", 
                                                     N("Welcome to the Mandrake Control Center"), $font));


# main page (summary) :

add2notebook($notebook_global, "", create_scrolled_window(gtkset_size_request(my $main_page = Gtk2::HBox->new,
                                                                              50, 50),
                                                          [ 'never', 'automatic' ], 'none',
                                                     ),
            );



my ($hand_cursor, $normal_cursor, $wait_cursor) = map { Gtk2::Gdk::Cursor->new($_) } qw(hand2 left-ptr watch);

my ($index, $left_locked) = (0, 0);

my $spacing = 25;

my @main_icons;
             
foreach (@tree) {
    my ($text, $icon, $subtree) = @$_;

    my @subtree;
    foreach my $stuff (@$subtree) {
        my $exec = first(split /\s+/, $exec_hash->{$stuff->[0]}[1]);
        # do not complain about missing entries in move:
        if (-x $exec) {
            push @subtree, $stuff;
        } else {
            warn qq("$exec" is not executable) if $mdk_rel !~ /Move/;
        }
    }
    # Skip empty classes:
    next if !@subtree;

    my $my_index = $index++;

    my $box;
    $box = Gtk2::WebIcon->new($text, $icon,
                              {
                               button_release_event => sub { 
                                   # FIXME: the following code is currently useless: 
                                   #        should we provide a way to kill buggy embedded programs ?
                                   return if $left_locked;
                                   $page_id = $my_index + 1;
                                   warn_on_startup();
                               },
                              }
                             );


    # Create right notebook pages :

    my $tbl = create_packtable({ col_spacings => $spacing, row_spacings => $spacing, homogeneous => 1, mcc => 1 },
                      group_by3(map {
                       my ($label, $tag) = @$_;
                       my $text = $exec_hash->{$label}[3];
                       die "$label 's icon is missing" if !$exec_hash->{$label} && $::testing;
                       my $event_box;
                       $event_box = Gtk2::WebIcon->new($text, $tag,
                                                       {
                                                        button_release_event => sub { compute_exec_string($label, $event_box, $tag, @{$exec_hash->{$label}}) },
                                                       }
                                                      );
                       $event_box->set_events([ 'enter_notify_mask', 'leave_notify_mask', 'button_press_mask', 'button_release_mask' ]);
                       $tool_feedback{$label} = sub { $event_box->window->set_cursor($normal_cursor) };
                       $event_box;
                   } @subtree));

    add2notebook($notebook_global, "",
                 my $_w_ret = create_scrolled_window(gtkset_border_width($tbl, 5),
                                                     [ 'never', 'automatic' ], 'none',
                                                    ),
                );
#    $w_ret->vscrollbar->set_size_request(19, undef);
    push @main_icons, $box;

    add2notebook($banner_notebook, "", Gtk2::Banner->new("title-back", "/usr/share/icons/large/drakconf.png", $text, $font));
}

gtkadd($main_page, create_packtable({ col_spacings => $spacing, row_spacings => $spacing, homogeneous => 1, mcc => 1 }, group_by3(@main_icons)));


#$emb_frame->set_size_request(-1, $index * 50);

foreach (keys %check_boxes) {
    my $widget = $check_boxes{$_};
    if (defined $widget) {
        $widget->set_active($option_values{$_});
    } else {
        print STDERR qq(BUG with LANGUAGE "$ENV{LANGUAGE}" for "$_"\n);
    }
};

# "wait while launching a program" area :

my ($run_pixbuf, $run_counter, $run_counter_add);

$run_darea->signal_connect(expose_event => sub {
    return unless $run_pixbuf; # some people got an expose event before we start an embedded tool
    my $pixbuf = render_alpha($run_pixbuf, $run_counter);
    my ($window, $gc, $width, $height) = ($run_darea->window, $run_darea->style->fg_gc('normal'), $pixbuf->get_width, $pixbuf->get_height);
    $pixbuf->render_to_drawable($window, $gc, 0, 0, 0, 0, $width, $height, 'normal', 0, 0);
    $run_counter += $run_counter_add;
    $run_counter_add = -$run_counter_add if $run_counter < 100 || 245 < $run_counter;
});

gtkflush();

set_page_raw(0);
$notebook_global->signal_connect(switch_page => sub {
    my $tab_number = $_[2];
    return unless $tab_number > 0;
});

$window_global->show_all;
show_hide_previous(0);
$emb_frame->hide;

$SIG{USR1} = 'IGNORE';
$SIG{USR2} = 'IGNORE';
$SIG{TERM} = \&quit_global;
$SIG{CHLD} = \&sig_child;
#$SIG{CONT}  = sub { Gtk2->main };

$window_splash->destroy;
undef $window_splash;

Gtk2->main;


sub group_by3 {
    my @l;
    for (my $i = 0; $i < @_; $i += 3) {
	push @l, [ $_[$i], $_[$i+1], $_[$i+2] ];
    }
    @l;
}

sub warn_on_startup {
    if ($pending_app) {
        return if !splash_warning(N("The modifications done in the current module won't be saved."), 1);
        kill_children();
        child_just_exited();
    }
    
    set_page($page_id);
}



#-------------------------------------------------------------
# socket/plug managment

# called once embedded tool has exited
sub child_just_exited() {
    $pending_app = 0;
    $left_locked = 0;
    if ($emb_socket) {
        $emb_socket->destroy;
        undef $emb_socket;
    }
    $emb_frame->hide;
    $emb_wait->hide;
    show_hide_previous(1);
    $cancel->hide;
    gtkset_mousecursor_normal();
    foreach my $notebook ($previous, $notebook_global, $banner_notebook) {
        $notebook->show;
    }
    
    Glib::Source->remove($timeout) if $timeout;
}

sub hide_socket_and_clean() {
    $emb_frame->hide;
    $pending_app = 0;
}

sub create_hidden_socket() {
    gtkpack_($emb_box, 1, gtksignal_connect($emb_socket = Gtk2::Socket->new, 'plug-removed' => \&child_just_exited));
    # signal emitted when embedded apps begin to draw:
    $emb_socket->signal_connect('plug-added' => sub {
                                    $left_locked = 0;
                                    $emb_wait->hide;
                                    show_hide_previous(0);
                                    $buttons->hide;
                                    return if !$emb_socket;
                                    $emb_socket->show;
                                    $emb_socket->can_focus(1);
                                    $emb_socket->grab_focus;
                                    #$emb_socket->window->XSetInputFocus; #only need by console (no more embedded until we've vte/zvt binding)
                                });
    $emb_box->set_focus_child($emb_socket);
    $emb_socket->hide;
    $emb_wait->hide;
}


#-------------------------------------------------------------
# processes managment

# embedded processes pid will be stocked there
my @pid_launched;

# logdrake pid are stocked here
my $pid_exp;

sub fork_ {
    my ($prog, $o_pid_table) = @_;
    $o_pid_table ||= \@pid_launched;
    my $pid = fork();
    if (defined $pid) {
        !$pid and do { exec($prog) or POSIX::_exit(1) };   # immediate exit, else forked gtk+ object destructors will badly catch up parent mcc
        push @$o_pid_table, $pid;
        return $pid;
    } else {
        splash_warning(N("cannot fork: %s", "$!"));
        child_just_exited();
    }
}

sub compute_exec_string {
    my ($label, $box, $icon, $_log_exp, $exec_, $gtkplug, undef, $alternate) = @_; #($_[0], @{$_[1]});
    return if $tool_pids{$label};
    my $exec = ref($exec_) ? $exec_->[0] : $exec_;
    if (! -x first(split /\s+/, $exec)) {
        splash_warning(N("cannot fork and exec \"%s\" since it is not executable", $exec));
        return;
    }
    $exec .=  " --summary" if $option_values{expert_wizard} && $exec_ =~ /drakwizard/;
    my $embedded = $gtkplug != -1; # not "explicitely not embedded"
    if ($embedded) {
        foreach my $notebook ($notebook_global) {
            $notebook->hide;
        }
        create_hidden_socket();
        $emb_frame->show;
        $emb_socket->realize;
        $pending_app = 1;
        if ($gtkplug > 0) {
            $exec .= " --embedded " . $emb_socket->get_id;
            $emb_wait->show;
            $cancel->show;
            $previous->hide;
            $run_pixbuf = gtkcreate_pixbuf($icon . "_128");
            $run_counter = 255;
            $run_counter_add = -10;
            $timeout = Glib::Timeout->add(70, sub { $run_darea->queue_draw; 1 });
            $left_locked = 1;
            $tool_pids{$label} = fork_($exec);
        } else { # gtkplug == 0
            $emb_box->grab_focus;
            $emb_socket->grab_focus;
            $emb_socket->show;
            $exec_->[0] = $exec;
            $SIG{CHLD} = undef;
            $emb_socket->add_id(launch_xapp(@$exec_));
            $SIG{CHLD} = \&sig_child;
        }
    } else { # not embedded
        # fix #3415 when $gtkplug eq -1
        my $old = $option_values{embedded};
        $option_values{embedded} = 0;
        $tool_pids{$label} = fork_($gtkplug == 0 ? $exec_->[0] : $alternate || $exec);
        $option_values{embedded} = $old;
    }
    start_logdrake();
    $box->window->set_cursor($wait_cursor);
}

sub start_logdrake {
    # (re)start logdrake if needed
    if ($option_values{show_log} && !$pid_exp) {
        my $exec_log = "logdrake --explain=drakxtools";
        $pid_exp = fork_($exec_log, []);
    }

}

sub launch_xapp {
    my ($exec, $name, $xx) = @_;
    my $find_windows = sub { 
        local *X;
        open(X, "-|", "xwininfo -root -tree -int");
        grep { /$name/ } <X>;
    };
    my @before = &$find_windows();
    fork_($exec);
    my @after = &$find_windows();
    require Time::HiRes;
    while (@after != $xx + @before) {
        Time::HiRes::usleep(50);
        @after = &$find_windows() 
    }
    my $c = top(difference2(\@after, \@before));
    return $1 if $c =~ /\s*([0-9]*)\s*/;
}

sub kill_them_all {
    map { if__($_, kill 'TERM', $_) } @_;
}

sub kill_children() {
    kill_them_all(@pid_launched);
    @pid_launched = ();
}

sub kill_logdrake() {
    kill_them_all($pid_exp) if $pid_exp;
}

sub quit_global() {
    &kill_children();
    &kill_logdrake();
    my ($x, $y) = $window_global->get_size;
    setVarsInSh($conffile, {
        LOGS          => bool2text($option_values{show_log}),
        EXPERT_WIZARD => bool2text($option_values{expert_wizard}),
        HEIGTH => $y,
        WIDTH => $x,
        THEME         => $theme,
    });
    gtkset_mousecursor_normal();
    Gtk2::exit(0);
}


#-------------------------------------------------------------
# signals managment

# got when child died and gone in zombie state
sub sig_child() {
    my $child_pid;
    do { 
        $child_pid = waitpid(-1, POSIX::WNOHANG);
        if (my $tool = find { $tool_pids{$_} eq $child_pid } keys %tool_pids) {
            $tool_feedback{$tool}->();
            delete $tool_pids{$tool};
        }
        undef $pid_exp if $pid_exp eq $child_pid;
    } while $child_pid > 0;
    # child unexpectedly died (cleanup since child_just_exited won't be called by plug-removed since plug never was added)
    return unless $left_locked;
    child_just_exited();
    splash_warning(N("This program has exited abnormally"));
}


#-------------------------------------------------------------
# mcc dialog specific functions

sub splash_warning {
    my ($label, $o_cancel_button) = @_;
    warn_dialog(N("Warning"), $label, { cancel => $o_cancel_button });
}

sub new_dialog {
    my ($title, $o_no_button) = @_;
    my $dialog = gtkset_border_width(Gtk2::Dialog->new, 10);
    $dialog->set_transient_for($window_global);
    $dialog->set_position('center-on-parent');
    $dialog->set_title($title);
    $dialog->action_area->pack_start(gtkadd(Gtk2::HButtonBox->new,
                                            gtksignal_connect(Gtk2::Button->new(N("Close")), clicked => sub { $dialog->destroy })
                                            ),
                                     0,0,0) unless $o_no_button;
    gtkset_modal($dialog, 1);
}

sub more_themes() {
    my $window_about = new_dialog(N("More themes"));
    gtkpack_($window_about->vbox,
             0, Gtk2::Label->new(N("Getting new themes")),
             0, gtkadd(gtkset_shadow_type(gtkset_border_width(Gtk2::Frame->new(N("Additional themes")), 10), 'etched_out'),
                       gtkpack(Gtk2::HBox->new(0, 5),
                               N("Get additional themes on www.damz.net"),
                               )
                       )
             );
    $window_about->show_all;
}

sub about_mdk_cc() {
    my $window_about = new_dialog(N("About - Mandrake Control Center"));

    my $tree_model = Gtk2::TreeStore->new("Glib::String", "Glib::String", "Glib::String");
    my $credits_model = Gtk2::TreeStore->new("Glib::String", "Glib::String");
    my ($list, $clist) = (Gtk2::TreeView->new_with_model($tree_model), Gtk2::TreeView->new_with_model($credits_model));
    $_->can_focus(0) foreach $list, $clist;
    each_index {  $list->append_column(Gtk2::TreeViewColumn->new_with_attributes(undef, Gtk2::CellRendererText->new, 'text' => $::i)) } 0..2;
    each_index { $clist->append_column(Gtk2::TreeViewColumn->new_with_attributes(undef, Gtk2::CellRendererText->new, 'text' => $::i)) } 0..1;
    $_->set_headers_visible(0) foreach $list, $clist;

    foreach my $row ([ N("Authors: "), '', '' ],
                     [ '', 'Chmouel Boudjnah', N("(original C version)") ],
#-PO "perl" here is the programming language
                     [ '', 'Damien "dam\'s" Krotkine', N("(perl version)") ],
                     [ '', 'Daouda Lo', '<daouda@mandrakesoft.com>' ],
                     [ '', 'Thierry Vignaud', '<tvignaud@mandrakesoft.com>' ],
                     [ '', 'Yves Duret', N("(perl version)") ],
                     [ '', '' ],
                     [ N("Artwork: "), '', '' ],
                     [ '', 'Anh-Van Nguyen', N("(design)") ],
#-PO If your language allows it, use eacute for first "e" and egrave for 2nd one.
                     [ '', N("Helene Durosini"), '<ln@mandrakesoft.com>' ],
                     ) {
        $tree_model->append_set(undef, [ map_index { $::i => $_ } @$row ]);
    }

    foreach my $line (sort(cat_(top(glob("/usr/share/doc/mandrake-release-*/CREDITS"))))) {
        $credits_model->append_set(undef, map_index { $::i => $_ } map { translate(common::sprintf_fixutf8($_)) } split(', ', chomp_($line), 2));
    }


    # Give our translators the ability to show their family and
    # friends that thez participated ...

#-PO Add your Name here to find it in the About section in your language.
    my $translator_name = N("~ * ~");
#-PO Add your E-Mail address here if you want to show it in the about doialog.
    my $translator_email = N("~ @ ~");
    if ($translator_name ne "~ * ~ " && 0) {
        $list->append_set(undef, [ 0 => $_->[0],  1 => $_->[1] ]) foreach [ '', '' ], [ N("Translator: "), $translator_name, $translator_email ];
    }
    $list->get_selection->set_mode('none');

    gtkpack_($window_about->vbox,
             -r "$themes_dir/$theme/splash_screen_about.png" ?
             (0, gtkcreate_img("splash_screen_about")) : (1, gtkmodify_font(Gtk2::Label->new(N("Mandrake Control Center %s\n", $version)), 'Bold 24'),),
             0, Gtk2::Label->new("\n" . N("Copyright (C) 1999-2003 Mandrakesoft SA") . "\n"),
             1, my $n = Gtk2::Notebook->new,
             );

    add2notebook($n, N("Authors"), $list);
    add2notebook($n, N("Mandrake Linux Contributors"), create_scrolled_window(gtkset_size_request($clist, 50, 50)));

    $window_about->show_all;
}


#-------------------------------------------------------------
# mcc specific graphic functions:

sub set_page_raw {
    my ($bool) = @_;
    foreach my $notebook ($notebook_global, $banner_notebook) {
        $notebook->set_current_page($bool);
    }
}

sub set_page {
    my ($index) = @_;
    start_logdrake();
    set_page_raw($index);
    $help_on_context = $ctx[$index];
    show_hide_previous($index);
}

sub show_hide_previous {
    my ($bool) = @_;
    if ($bool) {
        $previous->show;
        $buttons->show;
    } else { $previous->hide }
    $cancel->hide;
}


#-------------------------------------------------------------
# mcc specific graphic functions:

sub rtl_gtkcreate_pixbuf {
    my ($icon) = @_;
    my $pixbuf;
    eval { $pixbuf = ugtk2::gtkcreate_pixbuf($icon . "_rtl") } if lang::text_direction_rtl();
    $pixbuf ||= ugtk2::gtkcreate_pixbuf($icon);
}

sub rtl_gtkcreate_img {
    my ($icon) = @_;
    lang::text_direction_rtl() ? ugtk2::gtkcreate_img($icon . "_rtl") : ugtk2::gtkcreate_img($icon);
}

sub new_pixbuf {
    my ($pixbuf) = @_;
    my ($height, $width) = ($pixbuf->get_height, $pixbuf->get_width);
    my $new_pixbuf = Gtk2::Gdk::Pixbuf->new('rgb', 1, 8, $height, $width);
    $new_pixbuf->fill(0x00000000); # transparent white
    $width, $height, $new_pixbuf;
}

sub render_alpha {
    my ($pixbuf, $alpha_threshold) = @_;
    my ($width, $height, $new_pixbuf) = new_pixbuf($pixbuf);
    $pixbuf->composite($new_pixbuf, 0, 0, $width, $height, 0, 0, 1, 1, 'nearest', $alpha_threshold);
    $new_pixbuf;
}

sub render_shiner {
    my ($pixbuf, $shine_value) = @_;
    my $new_pixbuf = (new_pixbuf($pixbuf))[2];
    $pixbuf->saturate_and_pixelate($new_pixbuf, $shine_value, 0);
    $new_pixbuf;
}

sub scale {
    my ($pixbuf, $gain) = @_;
    my ($width, $height) = ($pixbuf->get_height, $pixbuf->get_width);
    $pixbuf->scale_simple($height+$gain, $width+$gain, 'hyper');
}



package Gtk2::Banner;

use ugtk2 qw(:helpers :wrappers);
#use common;

sub new {
    my ($_class, $background, $icon, $text, $font) = @_;
    my $fixed = gtkput(gtksignal_connect(Gtk2::Fixed->new,
                                         "configure-event" => sub {},
                                        ),
                       gtkpack_(Gtk2::HBox->new,
                                0, gtkset_size_request(Gtk2::Label->new, 10, -1),
                                0, my $img = gtkcreate_img($icon),
                                1, gtkmodify_font(gtkset_size_request(Gtk2::WrappedLabel->new($text), $h{WIDTH} - 100, 75), $font)
                               ),
                      );

    $img->{pixbuf} = gtkcreate_pixbuf($icon);
    $img->signal_connect("configure-event" => sub { set_back_pixbuf($img, $img->{pixbuf}) });
    
    return $fixed;
}

package Gtk2::WebIcon;

use ugtk2 qw(:helpers :wrappers);
use common;

sub new {
    my ($_class, $text, $icon, $callbacks) = @_;
    my $hbox_spacing = 10; 
                                                            # FIXME: do ->set_pixbuf() on {enter,leave}_events
    my $box = gtkadd(gtksignal_connect(Gtk2::EventBox->new, realize => sub { $_[0]->window->set_cursor($hand_cursor) }),
                     gtkpack_(
                              # better VBox of StockButtons there (with IconFactory)
                              Gtk2::VBox->new(0, $hbox_spacing),
                              0, gtkcreate_img($icon),
                              1, gtktext_insert(
                                                # disable selecting text and popping the contextual menu
                                                # (GUI team says it's *horrible* to be able to do select text!)
                                                gtksignal_connect(my $tv = Gtk2::TextView->new,
                                                                  button_press_event => sub { 1 }),
                                                [ [ $text, {'background_set' => 0, justification => "center",
                                                            'background_stipple_set' => 0 } ] ])
                             ),
                    );
    $tv->set_events([]);
    # FIXME : resize sig: ->foreach; set_size_request
    while (my ($signal, $handler) = each %$callbacks) {
        $box->signal_connect($signal => $handler);
    }

    gtkset_size_request($box, 50, -1);
    $box->set_events([ 'enter_notify_mask', 'leave_notify_mask', 'button_press_mask', 'button_release_mask' ]);
    return  gtkset_border_width($box, 10);
}

1;