summaryrefslogtreecommitdiffstats
path: root/control-center
blob: b36876612e79d708e8356f9c1336f5b5973b7586 (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
#!/usr/bin/perl
# $Id$

# Copyright (C) 1999-2001 MandrakeSoft
#                         Damien Krotkine (damien@mandrakesoft.com)
#
# 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.

my $_xbindir = "/usr/X11R6/bin";
my $_bindir = "/usr/bin";
my $_sbindir = "/usr/sbin";
my $mcc_dir = "/usr/share/mcc";
my $themes_dir = "$mcc_dir/themes/";
my $_wizdir = "/usr/share/wizards";

BEGIN { !$ENV{DISPLAY} and exec ("/usr/sbin/drakxconf; reset") }

use Gtk;
use lib qw(/usr/lib/libDrakX);
use standalone;
use common;
use interactive;
use detect_devices;
use my_gtk qw(:helpers :wrappers);
#use strict;

# set the locale, needed for proper fontset and charset selection
Gtk->set_locale;
use Config;
use POSIX qw(uname);

my $in = 'interactive'->vnew('su', 'default');

my ($_version, $conffile, $class_install) = ("9.0", "/etc/mcc.conf","/etc/sysconfig/system");

#we'll show log only once and don't restart it with new embedded process
my $show_log = 1;

my %h = getVarsFromSh($conffile);
my %class = getVarsFromSh($class_install);
defined $h{THEME} or $h{THEME} = 'default';
defined $h{EMBEDDED} or $h{EMBEDDED} = bool2text(1);
defined $h{LOGS} or do { if ($class{CLASS} eq 'expert') {$h{LOGS} = bool2text(0)} else {$h{LOGS} = bool2text(1)}};
my ($embedded, $logs) = (text2bool($h{EMBEDDED}), text2bool($h{LOGS}));
my $theme = $h{THEME};
if ("@ARGV" =~ /--theme (\w+)/) { $theme = $1 }
-d "$themes_dir/$theme" or $theme = 'default';
#"@ARGV" =~ /--safe/ and $theme = 'default';
ugtk::add_icon_path("$themes_dir/$theme");
($theme ne 'default') and ugtk::add_icon_path("$themes_dir/default");
my $window_splash = new Gtk::Window -popup;
$window_splash->signal_connect (delete_event => \&quit_global);
$window_splash->set_title(_("Mandrake Control Center"));
$window_splash->set_policy(0, 0, 1);
$window_splash->set_position(1);
$window_splash->add(
		    gtkadd(gtkset_shadow_type(new Gtk::Frame(), 'etched_out'),
			   -r "$themes_dir/$theme/splash_screen.png" ? gtkpng("splash_screen") : new Gtk::Label(_("Loading... Please wait")))
		   );
$window_splash->show_all;
Gtk->main_iteration while Gtk->events_pending;
my $timer_splash = Gtk->timeout_add(200, sub { Gtk->main_iteration while Gtk->events_pending });

# timeout to avoid refresh problem
Gtk->timeout_add(100, sub{ 1 });

my $rc = "$mcc_dir/$theme/gtkrc";
-r $rc and Gtk::Rc->parse($rc);

my ($log_check_box, $embedded_check_box);

$::isWiz = -e "/usr/sbin/drakwizard";
$::isRpmDrake = -e "/usr/sbin/rpmdrake";

# { key => [log_exp, binary, gtkplug?, alternate] }
my $exec_hash = 
  {
   _("Boot Disk") => [ "drakfloppy", "$_sbindir/drakfloppy", 1],
   _("Boot Config") => [ "drakboot", "$_sbindir/drakboot", 1 ],
   _("Auto Install") => [ "drakautoinst", "$_sbindir/drakautoinst", 1 ],
   _("Monitor") => [ "XFdrake", "$_sbindir/XFdrake monitor", 1 ],
   _("Resolution") => [ "XFdrake", "$_sbindir/XFdrake resolution", 1 ],
   _("Display") => [ "XFdrake", "$_sbindir/XFdrake", 1 ],
   _("Hardware List") => [ "harddrake", "$_sbindir/harddrake2", 1 ],
   _("Mouse") => [ "mousedrake", "$_sbindir/mousedrake", 1 ],
   _("Printer") => [ "printerdrake", "$_sbindir/printerdrake", 1, "$_sbindir/printerdrake" ],
   _("Scanner") => [ "scannerdrake", "$_sbindir/scannerdrake", 1 ],
   _("Users") => [ "userdrake", "$_bindir/userdrake", 1 ],
   _("Keyboard") => [ "keyboarddrake", "$_sbindir/keyboarddrake", 1 ],
   _("Hard Drives") => [ "diskdrake", "$_sbindir/diskdrake --hd", 1 ],
   _("NFS mount points") => [ "diskdrake", "$_sbindir/diskdrake --nfs", 1 ],
   _("Samba mount points") => [ "diskdrake", "$_sbindir/diskdrake --smb", 1 ],
   _("WebDAV mount points") => [ "diskdrake", "$_sbindir/diskdrake --dav", 1 ],
   _("Partition Sharing") => [ "diskdrake", "$_sbindir/diskdrake --fileshare", 1 ],
   _("Connection") => [ "drakconnect", "$_sbindir/drakconnect", 1 ],
   _("Connection Sharing") => [ "drakgw", "$_sbindir/drakgw", 1 ],
   _("Proxy Configuration") => [ "drakproxy", "$_sbindir/drakproxy", 1 ],
   _("Security Level") => [ "draksec", "$_sbindir/draksec", 1 ],
   _("Programs scheduling") => [ "drakcronat", "/usr/X11R6/bin/drakcronat", -1 ],
   _("Firewall") => [ "tinyfirewall", "$_sbindir/tinyfirewall", 1 ],
   _("Backups") => [ "drakbackup", "$_sbindir/drakbackup", -1 ],
   _("Menus") => [ "menudrake", "$_sbindir/menus_launcher.pl", 1, "$_bindir/menudrake" ],
   _("Services") => [ "drakxservices", "$_sbindir/drakxservices", 1 ],
   _("Fonts") => [ "drakfont", "$_sbindir/drakfont", 1 ],
   _("Date & Time") => [ "clock", "$_sbindir/clock.pl", 1 ],
   _("Logs") => [ "logdrake", "$_sbindir/logdrake", 1 ],
   # little workaround to avoid drakconf freeze
   _("Console") => [ "rxvt", "", 0, ["$_xbindir/rxvt", "rxvt", 1] ],
#   _("Console") => [ "rxvt", "$_xbindir/rxvt", -1 ],
   _("Install Software") => [ "rpmdrake", "$_sbindir/rpmdrake", -1 ],
   _("Remove Software") => [ "rpmdrake", "$_sbindir/rpmdrake-remove", -1 ],
   _("Mandrake Update") => [ "rpmdrake", "$_sbindir/MandrakeUpdate", -1 ],
   _("Software Sources Manager") => [ "rpmdrake", "$_sbindir/edit-urpm-sources.pl", -1 ],

   
   _("TV Cards") => [ "drakxtv", "$_sbindir/drakxtv", 1 ],

   _("DNS Client") => ["Client wizard", "drakwizard $_wizdir/client_wizard/client.wiz", -1 ],
   _("DHCP") => ["DHCP wizard", "drakwizard $_wizdir/dhcp_wizard/dhcp.wiz",  -1 ],
   _("DNS") => ["DNS wizard", "drakwizard $_wizdir/dns_wizard/dns.wiz", -1 ],
   _("FTP") => ["FTP wizard", "drakwizard $_wizdir/ftp_wizard/ftp.wiz", -1 ],
   _("News") => ["News wizard", "drakwizard $_wizdir/news_wizard/news.wiz", -1 ],
   _("Postfix") => ["Postfix wizard", "drakwizard $_wizdir/postfix_wizard/postfix.wiz", -1 ],
   _("Proxy") => ["Squid wizard", "drakwizard $_wizdir/proxy_wizard/proxy.wiz", -1 ],
   _("Samba") => ["Samba wizard", "drakwizard $_wizdir/samba_wizard/samba.wiz", -1 ],
   _("Server") => ["Server wizard", "drakwizard $_wizdir/server_wizard/server.wiz", -1 ],
   _("Time") => ["Time wizard", "drakwizard $_wizdir/time_wizard/time.wiz", -1 ],
   _("Web") => ["Web wizard", "drakwizard $_wizdir/web_wizard/web.wiz", -1 ],
  };

# { name => [ label, icon core ] }
my %wizard = ("client" => [ _("DNS Client"), 'server-mdk'],
 	       "dhcp" => [ _("DHCP"), 'server-mdk'],
 	       "dns" => [ _("DNS"), 'server-mdk'],
 	       "ftp" => [ _("FTP"), 'server-mdk'],
 	       "news" => [ _("News"), 'server-mdk'],
 	       "postfix" => [ _("Postfix"), 'server-mdk'],
 	       "proxy" => [ _("Proxy"), 'server-mdk'],
 	       "samba" => [ _("Samba"), 'server-mdk'],
 	       "server" => [ _("Server"), 'server-mdk'],
 	       "time" => [ _("Time"), 'server-mdk'],
 	       "web" => [ _("Web"), 'server-mdk'],
 	     );

# { class_name => [
#                  [ label, icon core ]
#                 ]
# }
my @tree =
  ([_("Boot"), 'boot-mdk',  
     [
      [_("Boot Disk"), 'drakfloppy-mdk'],
      [_("Boot Config"),'drakboot-mdk'],
      [_("Auto Install"), 'drakfloppy-mdk'],
     ]
    ],
    [_("Hardware"), 'drakhard-mdk',
     [
      [_("Hardware List"),'harddrake-mdk'],
      [_("Monitor"),'XFdrake-mdk'],
      [_("Resolution"),'XFdrake-mdk'],
      [_("Display"),'XFdrake-mdk'],
      [_("TV Cards"),'XFdrake-mdk'],
      [_("Keyboard"), 'keyboard-mdk'],
      [_("Mouse"), 'mousedrake-mdk'],
      [_("Printer"),'printer-mdk'],
      [_("Scanner"),'scanner-mdk'],
     ]
    ],
    [_("Mount Points"),'partition-mdk',
     [
      [_("Hard Drives"), 'diskdrake_hd'],
      (map {
	  my ($type, $name, $scan) = @$_;
	  map_index { 
	      my $full_name = $name . ($::i ? $::i + 1 : '');
	      $exec_hash->{$full_name} = [ "diskdrake", "$_sbindir/diskdrake --removable=$_->{device}", 1 ];
	      [ $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', _("CD-ROM"), sub { @{$cdroms_by_type{cdrom} || []} } ],
	   [ 'dvd', _("DVD"), sub { @{$cdroms_by_type{DVD} || []} } ],
	   [ 'cdwriter', _("CD Burner"), sub { @{$cdroms_by_type{burner} || []} } ],
	   [ 'floppy', _("Floppy"), \&detect_devices::floppies ],
	   [ 'zip', _("Zip"), \&detect_devices::zips ],
	  ),
      }),
      [_("NFS mount points"), 'diskdrake_nfs'],
      [_("Samba mount points"), 'diskdrake_samba'],
      [_("WebDAV mount points"), 'drakgw-mdk'],
      [_("Partition Sharing"), 'diskdrake_fileshare'],
     ]
    ],
    [_("Network & Internet"),'net-mdk',
     [
      [_("Connection"), 'drakconnect-mdk'],
      [_("Proxy Configuration"),'drakconnect-mdk'],
      [_("Connection Sharing"),'drakgw-mdk'],
     ],
    ],
    [_("Security"),'security-mdk',
     [
      [_("Security Level"), 'draksec-mdk'],
      [_("Firewall"), 'firewall-mdk'],
     ]
    ],
    [_("System"),'system-mdk',
     [
      [_("Menus") , 'menudrake-mdk'],
      [_("Services") , 'service-mdk'],
      [_("Fonts"), 'drakfont-mdk'],
      [_("Date & Time") , 'time-mdk'],
      [_("Logs"), 'logdrake-mdk'],
      [_("Console"), 'console-mdk'],
      [_("Users"), 'user-mdk'],
      [_("Programs scheduling"), 'drakboot-mdk'],
      [_("Backups"), 'drakboot-mdk'],
#      [_("RFBDrake"), 'unknown-mdk'],
     ]
    ],
   if_($::isRpmDrake,
       [_("Software Management"),'software',
	[
	 [_("Install Software"), 'rpmdrake'],
	 [_("Remove Software"), 'rpmdrake-remove'],
	 [_("Mandrake Update"), 'MandrakeUpdate'],
	 [_("Software Sources Manager"), 'source-manager'],
	]
       ]),
   if_($::isWiz,
       [_("Server Configuration"), 'wizard-mdk',
	[
	 (map {
	     if_(-e '/usr/share/wizards/'.$_.'_wizard/'.$_.'.wiz', $wizard{$_})
	 } keys %wizard)
	]
       ]),
  );

#-------------------------------------------------------------

my $nb_pages = 0;
my $window_global = new Gtk::Window -toplevel;
$window_global->signal_connect (delete_event => \&quit_global);
$window_global->set_title(_("Mandrake Control Center %s", $_version));
$window_global->set_policy(0, 1, 1);
my $notebook_global;

my ($pixmap_back_left, undef) = gtkcreate_png_('mcc-left-back');
my @darea_left_list;
my $cursor_hand = new Gtk::Gdk::Cursor 60;
my $cursor_normal = new Gtk::Gdk::Cursor 68;
my @back;
($back[0], undef) = gtkcreate_png_('mcc-left-back');
$back[1] = $back[0];
($back[2], undef) = gtkcreate_png_('mcc-left-back2');
my ($index, $left_locked, $pending_app) = (0, 0, 0);
my $darea_left_sav;
foreach (@tree) {
    $index++;
    my $index = $index;
    my $text = $_->[0];
    my @icon;
    ($icon[0], undef) = gtkcreate_png_($_->[1]);
    ($icon[1], undef) = gtkcreate_png_("$_->[1]_highlight");
    ($icon[2], undef) = gtkcreate_png_("$_->[1]2");
    my $darea_left = gtkset_usize(new Gtk::DrawingArea, 160, 45);
    $darea_left->{state} = 0;
    my $dbl_area_left;
    $darea_left->set_events(['exposure_mask', 'enter_notify_mask', 'leave_notify_mask', 'button_press_mask', 'button_release_mask' ]);
    $darea_left->signal_connect(size_allocate => sub { $dbl_area_left = undef });
    $darea_left->signal_connect(expose_event => sub {
	   my ($dx, $dy) = ($darea_left->allocation->[2], $darea_left->allocation->[3]);
	   if (!defined($dbl_area_left) || $darea_left->{state} != $dbl_area_left->{state}) {
		  my $state = $darea_left->{state};
		  my ($pix, $width, $height) = create_pix_text($darea_left, $text, "#0#0#0",
											  $darea_left->style->font,
											  max($dx-40, 0), $dy, 0, 0, $back[$state], 160, 45, 0, 1, $state); 
		  $dbl_area_left = new Gtk::Gdk::Pixmap($darea_left->window, $dx, $dy);
		  $dbl_area_left->{state} = $darea_left->{state};
		  $darea_left->{dbl} = $dbl_area_left;
		  fill_tiled($darea_left, $dbl_area_left, $back[$state], 40, $dy, 40, 45);
		  $dbl_area_left->draw_pixmap($darea_left->style->bg_gc('normal'),
								$icon[$state], 0, 0, 4, int(($dy-35)/2/5)*5, 35, 35);
		  $dbl_area_left->draw_pixmap($darea_left->style->bg_gc('normal'),
								$pix, 0, 0, 40, 0, $width, $height);
	   }
	   $darea_left->window->draw_pixmap($darea_left->style->bg_gc('normal'),
								 $dbl_area_left, 0, 0, 0, 0, ($dx, $dy));
    });
    $darea_left->signal_connect(realize => sub { $darea_left->window->set_cursor($cursor_hand) });
    $darea_left->signal_connect(enter_notify_event => sub {
	   if ($darea_left->{state} == 0) {
		  $darea_left->{state} = 1;
		  $darea_left->draw(undef);
	   }
    });
    $darea_left->signal_connect(leave_notify_event => sub {
	   if ($darea_left->{state} == 1) {
		  $darea_left->{state} = 0;
		  $darea_left->draw(undef);
	   }
    });
    $darea_left->signal_connect(button_release_event => sub {
	   $left_locked and return;
	   $pending_app && !splash_warning(_("The modifications done in the current module won't be saved."), 1) and return;
	   clean_socket();
	   $notebook_global->show;
	   $darea_left->{state} == 2 and $notebook_global->set_page($index), return;
	   foreach (@darea_left_list) {
		  $_->[1]->window->set_cursor($cursor_hand);
		  if($_->[1]->{state} != 0) {
			 $_->[1]->{state} = 0;
			 $_->[1]->draw(undef);
		  }
	   }
	   $darea_left->window->set_cursor($cursor_normal);
	   $darea_left->{state} = 2, $darea_left->draw(undef);
	   $notebook_global->set_page($index);
	   $darea_left_sav = $darea_left;
    });
    
    push @darea_left_list, [ ($index-1)*45, $darea_left ];
}

my $exp_frame;

my $emb_box;
my $emb_wait;
my $emb_socket;

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

# logdrake pid are stocked here
my @pid_exp;

my ($rootheight, undef) = my_gtk::gtkroot()->get_size;

$window_global->add(
    gtkpack_(new Gtk::VBox(0, 0),
	     0, my $title_w = get_main_menu($window_global),
	     0, my $fixed_title = gtkset_usize(new Gtk::Fixed, 400, 55),
	     0, new Gtk::HSeparator,
	     1, gtkpack_(new Gtk::HBox(0, 0),
			 0, my $fixed_left = new Gtk::Fixed,
			 1, gtkpack_(my $right_box = new Gtk::VBox(0, 0), 
				     1, gtkpack_($emb_box = new Gtk::VBox(0, 0),
					 1, $emb_wait = gtkpack_(new Gtk::VBox(0, 0),
						 1, new Gtk::HBox(0, 0),
						 0, gtkpack_(new Gtk::HBox(0, 0),
							     1, new Gtk::VBox(0, 0),
							     0, gtkadd(gtkset_shadow_type(new Gtk::Frame, 'etched_out'),
								       gtkpng_('hourglass'),
								      ),
							     1, new Gtk::VBox(0, 0),
							    ),
						 0, new Gtk::Label(_("Please wait...")),
						 1, new Gtk::HBox(0, 0),
						 0, gtkadd(gtkset_layout(gtkset_border_width(new Gtk::HButtonBox, 10), 'end'),
							   gtksignal_connect(new Gtk::Button(_("Cancel")), clicked => sub { kill('USR1', $$) }),
							  )
								)
					),
			     1, $notebook_global = new Gtk::Widget ('Gtk::Notebook',
								    show_border => 0,
								    show_tabs => 0),
			    )
			)
	    )
   );

sub update_exp {
    if($logs && !$exp_frame) {
	gtkpack__($right_box,
		gtkadd($exp_frame = gtkset_shadow_type(gtkset_usize(gtkset_border_width(new Gtk::Frame(_("Logs")), 5), 0, 120), 'etched_out'),
		      )
	       );
	$rootheight <= 600 and $fixed_title->hide; $show_log = 1;
	$exp_frame->show_all; 
    }
    if (!$logs && $exp_frame) {
	$exp_frame->destroy();
	undef $exp_frame;
	$fixed_title->show;
    }
}

#540, 420
$notebook_global->set_usize(40, $index * 45);
$emb_box->set_usize(40, $index * 45);
$log_check_box->set_active($logs);
$embedded_check_box->set_active($embedded);

update_exp();
res_socket();

foreach (@darea_left_list) { $fixed_left->put($_->[1], 0, $_->[0]) }

$fixed_left->signal_connect(realize => sub { $fixed_left->window->set_back_pixmap($pixmap_back_left, 0) });

my $dbl_area;
my ($pixmap_back, undef) = gtkcreate_png_('mcc-title-back');
my ($pixmap_icon, undef) = gtkcreate_png_('mcc-title-icon');

$fixed_title->put(my $darea_title = gtkset_usize(new Gtk::DrawingArea, 335, 55), 0, 0); # 335 -> 450

$fixed_title->signal_connect(realize => sub { $fixed_title->window->set_back_pixmap($pixmap_back, 0) });
$darea_title->signal_connect(realize => sub { $darea_title->window->set_cursor($cursor_hand) });
$darea_title->set_events([ 'button_release_mask' ]);
$darea_title->signal_connect(button_release_event => sub {
    clean_socket();
    $notebook_global->show;
    $notebook_global->set_page(0);
    foreach (@darea_left_list) {
	   $_->[1]->window->set_cursor($cursor_normal);
	   $_->[1]->{state} = 0;
	   $_->[1]->draw(undef);
    }
});
$darea_title->signal_connect(configure_event => sub { $dbl_area = undef });

$darea_title->signal_connect(expose_event => sub {
    my @dim = @{$_[1]->{area}};
    my ($dx, $dy) = ($darea_title->allocation->[2], $darea_title->allocation->[3]);
    if (!defined($dbl_area)) {
	   $dbl_area = new Gtk::Gdk::Pixmap($darea_title->window, $dx, $dy);
	   fill_tiled($darea_title, $dbl_area, $pixmap_back, 110, 55, $dx, $dy);
	   $dbl_area->draw_pixmap($darea_title->style->bg_gc('normal'),
						 $pixmap_icon, 0, 0, 0, 0, 325, 55);
    }
    $darea_title->window->draw_pixmap($darea_title->style->bg_gc('normal'),
							   $dbl_area, $dim[0], $dim[1], $dim[0], $dim[1], $dim[2], $dim[3]);
});

my ($pixmap_back_right, undef) = gtkcreate_png_('mcc-core-back');

my $pix_dbl;
$notebook_global->append_page(my $darea1 = new Gtk::DrawingArea);#my $fixed_about = new Gtk::Fixed);
$darea1->signal_connect(size_allocate => sub { $pix_dbl = undef });
$darea1->signal_connect(expose_event => sub {
     my ($dx, $dy) = ($darea1->allocation->[2], $darea1->allocation->[3]);
     if (!defined($pix_dbl)) {
	 $pix_dbl = new Gtk::Gdk::Pixmap($darea1->window, $dx, $dy);

	 fill_tiled($darea1, $pix_dbl, $pixmap_back_right, 540, 460, $dx, $dy);
	 my $style = $darea1->style->copy();
	 $style->font(Gtk::Gdk::Font->fontset_load(_("-*-helvetica-medium-r-normal-*-20-*-100-100-p-*-iso8859-1,*-r-*")));
	 $pix_dbl->draw_string($style->font, $darea1->style->black_gc, 80, 115, _("Welcome to the Mandrake Control Center"));
	 open VERS,  "/etc/mandrake-release" or die _("cannot open this file for read: %s", $!);
	 my ($sysname, $nodename, $release, undef, $machine) = uname();
	 my $i = 0;
	 foreach(
		 [_("System:"), substr(<VERS>, 0, -1)],
		 [_("Hostname:"), $nodename],
		 [_("Kernel Version:"), "$release"],
		 [_("Machine:"), $machine]) {
	     $pix_dbl->draw_string($darea1->style->font, $darea1->style->black_gc, 80, 150+$i, $_->[0]);
	     $pix_dbl->draw_string($darea1->style->font, $darea1->style->black_gc, 81, 150+$i, $_->[0]);
	     $pix_dbl->draw_string($darea1->style->font, $darea1->style->black_gc, 200, 150+$i, $_->[1]);
	     $i+=20;
	 }
     }
     $darea1->window->draw_pixmap ($darea1->style->white_gc,
				   $pix_dbl, 0, 0,
				   0, 0, $dx, $dy);
     0;
 });


foreach (@tree) {
    $notebook_global->append_page(gtkicons_labels_widget($_->[2], $window_global, "#0#0#0", $darea1,
				   $pixmap_back_right, 540, 460, 55, 50, 50, 50, 50, 50, \&compute_exec_string, $exec_hash));
}
Gtk->main_iteration while Gtk->events_pending;
$notebook_global->signal_connect(switch_page => sub {
    my (undef, $tab_widget, $tab_number) = @_;
    $tab_number > 0 or return;
    $tab_widget->child->child->child->{redraw_function}->();
});
$window_global->show_all;
$window_global->window->move(-715, -515);
Gtk->main_iteration while Gtk->events_pending;
$emb_box->hide;
my $p = $#tree + ($::isWiz ? 1 : 0);
foreach (0..$p) {
    $notebook_global->set_page($_);
    Gtk->main_iteration while Gtk->events_pending;
}
Gtk->timeout_remove($timer_splash);
$notebook_global->set_page(0);

$window_global->set_default_size(715, 515);
$window_splash->destroy();
$window_global->set_position(1);

$SIG{USR1} = \&sig_usr1;
$SIG{USR2} = \&sig_usr2;
$SIG{TERM} = \&quit_global;
#$SIG{CHLD} = sub { wait() };
Gtk->main;

sub gtkpng_ {
    my $gtkpix;
    eval { $gtkpix = gtkpng(@_) };
#    $@ and $theme ne 'default' ? exec "$0 --safe" : die "$@";
    $gtkpix
}

sub gtkcreate_png_ {
    my ($gdkpix, $gdkmap);
    eval { ($gdkpix, $gdkmap) = gtkcreate_png(@_) };
#    $@ and $theme ne 'default' ? exec "$0 --safe" : die "$@";
    ($gdkpix, $gdkmap);
}

sub sig_usr1 {
    $left_locked = 0;
    clean_socket();
    $darea_left_sav and $darea_left_sav->{state} = 2, $darea_left_sav->draw(undef);
    $notebook_global->show;
}

my $timer;
sub sig_usr2 {
    $left_locked = 0;
    $emb_wait->hide;
    $emb_socket->show;
}

#---
# i18n routines
# IMPORTANT: next two routines have to be redefined here to
#         get correct namespace (drakconf instead of libDrakX)
#         (This version is now UTF8 compliant - Sg 2001-08-18)
#---

{
    no warnings;
    sub _ {
	my $s = shift @_; my $t = translate($s);
	sprintf $t, @_;
    }

    no warnings;
    sub translate {
	my ($s) = @_;
	$s ? c::dgettext('drakconf', $s) : '';
    }
}

sub compute_exec_string {
    my ($log_exp, $exec, $gtkplug, $alternate) = @{$_[0]};
    if ($embedded) {
	if ($gtkplug != -1) {
	    $notebook_global->hide;
	    res_socket();
	    $emb_box->show;
	    $emb_socket->realize;
	    $exec = $exec . " --embedded " . $emb_socket->window->XWINDOW . " " . $$;
	}
	if ($gtkplug > 0) {
	    $emb_wait->show;
	    $left_locked = 1;
	    $pending_app = 1;
	    my $pid;
	    unless ($pid = fork) {
		splash_warning(_("cannot fork: %s", $~)) unless defined $pid;
		exec("$exec");
	    }
	    push @pid_launched, $pid;
	} elsif ($gtkplug == -1) {
	    system($exec . " &");
	} else {
	    $emb_socket->show;
	    $emb_socket->steal(launch_xapp($alternate));
	}
    } else {
	system(($gtkplug == 0 ? $alternate->[0] : $alternate || $exec) . " &");
    }
    if ($embedded && $gtkplug != -1) {
	foreach (@darea_left_list) {
	    $_->[1]->window->set_cursor($cursor_hand);
	    if ($_->[1]->{state} != 0) {
		$_->[1]->{state} = 0;
		$_->[1]->draw(undef);
	    }
	}
    }
    if ($logs && $show_log) {
	my $pid;
	gtkadd($exp_frame, my $exp_socket = new Gtk::Socket);
	$exp_socket->realize;
	$exec_log = "logdrake --explain=$log_exp --embedded " . $exp_socket->window->XWINDOW . " " . $$;
	$show_log = 0;
	unless ($pid = fork) {
	    splash_warning(_("cannot fork: %s", $~)) unless defined $pid;
	    print "explain : $log_exp \n ";
	    exec("$exec_log");
	} 
	push @pid_exp, $pid;
    }
}

sub launch_xapp {
    my $b = "xwininfo -root -tree -int | grep '" . $_[0]->[1] . "'";
    my @before = split ('\n', `$b`);
    my $pid;
    my $mcc_pid = $$;
    unless ($pid = fork) {
	splash_warning(_("cannot fork: %s", $~)) unless defined $pid;
	exec($_[0]->[0] . "; kill -USR1 $mcc_pid");
    }
    push @pid_launched, $pid;
    my $res = 0;
    while (!$res) {
	my @after = split ('\n', `$b`);
	while (@after ne ($_[0]->[2]+@before)) {
	    @after = split ('\n', `$b`);
	}
	my $i = 0;
	my $c;
	foreach (@after) {
	    $c = $after[$i] if !member($after[$i], @before);
	    $i++;
	}
	$c =~ /\s*([0-9]*)\s*/;
 	$res = $1;
    }
    $res;
}

sub clean_socket {
    $emb_box->hide;
    foreach (@pid_launched) {
	kill 'TERM', $_ if (defined $_);
    }
    @pid_launched = ();
    $emb_socket and $emb_socket->destroy();
    $pending_app = 0;
}

sub res_socket {
    clean_socket();
    gtkpack($emb_box, $emb_socket = new Gtk::Socket);
    $emb_socket->hide;
    $emb_wait->hide;
}

sub quit_global {
    foreach((@pid_launched,@pid_exp)) { kill 'TERM', $_ if (defined $_) }
    setVarsInSh($conffile, {
			    EMBEDDED => bool2text($embedded),
			    LOGS => bool2text($logs),
			    THEME => $theme,
			   });
    Gtk->exit(0);
}

sub splash_warning {
    my ($label, $cancel_button) = @_;
    my $ret;
    my $win_about = new Gtk::Dialog();
    $win_about->set_position(1);
    $win_about->set_border_width(10);

    gtkpack__($win_about->action_area,
      gtkadd(new Gtk::HButtonBox,
	     gtksignal_connect(new Gtk::Button($cancel_button ? _("OK") : _("Close")), "clicked" => sub { $ret = 1; Gtk->main_quit }),
	     if_($cancel_button, gtksignal_connect(new Gtk::Button(_("Cancel")), "clicked" => sub { Gtk->main_quit })),
	    )
	     );
    gtkpack($win_about->vbox,
	    gtkpng_("warning"),
	    new Gtk::Label($label),
	   );
    $win_about->show_all();
    $win_about->set_modal(1);
    Gtk->main;
    $win_about->destroy();
    $ret;
}

sub more_themes {
    my $window_about = new Gtk::Dialog();
    $window_about->set_position(1);
    $window_about->set_border_width(10);
    $window_about->set_title(_("More themes"));
    $window_about->action_area->pack_start(gtkadd(new Gtk::HButtonBox, 
				  gtksignal_connect(new Gtk::Button(_("Close")), "clicked" => sub { $window_about->destroy() })),0,0,0);
    my $style1 = $window_about->style->copy();
    $style1->font(Gtk::Gdk::Font->fontset_load(_("-*-helvetica-medium-r-normal-*-20-*-100-100-p-*-iso8859-1,*-r-*")));
    gtkpack_($window_about->vbox,
	     0, gtksetstyle(new Gtk::Label(_("Getting new themes")), $style1),
	     0, gtkadd(gtkset_shadow_type(gtkset_border_width(new Gtk::Frame(_("Additional themes")), 10), 'etched_out'),
		       gtkpack(new Gtk::HBox(0, 5),
			       _("Get additional themes on www.damz.net"),
			      )
		      )
	    );
    $window_about->set_policy(0, 0, 1);
    $window_about->show_all();
    $window_about->set_modal(1);
}

sub about_mdk_cc {
    my $window_about = new Gtk::Dialog();
    $window_about->set_position(1);
    $window_about->set_border_width(10);
    $window_about->set_title(_("About - Mandrake Control Center"));
    $window_about->action_area->pack_start(gtkadd(new Gtk::HButtonBox, 
				  gtksignal_connect(new Gtk::Button(_("Close")), "clicked" => sub { $window_about->destroy() })),0,0,0);

    my $label = new Gtk::Label();
    my $style1 = $label->style->copy();
    $style1->font(Gtk::Gdk::Font->fontset_load(_("-*-helvetica-medium-r-normal-*-20-*-100-100-p-*-iso8859-1,*-r-*")));
    my $clist = new Gtk::CList(3);
    my $i = -1;
    $i++, $clist->append(@$_) foreach ([ _("Author: "), 'Damien "dams" Krotkine', 'damien@mandrakesoft.com'],
				       [ '', 'Yves Duret', 'yduret@mandrakesoft.com'],
				       [ '', ''],
				       [ _("Artwork: "), 
#-PO If your language allows it, use eacute for first "e" and egrave for 2nd. 
					 _("Helene Durosini"), 'ln@mandrakesoft.com'],
				       [ '', 'Anh-Van Nguyen' ,'avnguyen@mandrakesoft.com'],
				       [ '', 'Tigert', 'tigert@ximian.com'],
				       [ '', 'Jakub "Jimmac" Steiner ', 'jimmac@linux.com.nospam'],
				      );
    $clist->set_selectable($_, 0) foreach (0..$i);
    $clist->columns_autosize();
    $clist->set_column_justification(0, "right");

    gtkpack_($window_about->vbox,
	     -r "$themes_dir/$theme/splash_screen_about.png" ?
	 (0, gtkpng("splash_screen_about")) : (1, gtksetstyle(new Gtk::Label(_("Mandrake Control Center %s\n", $_version)), $style1),),
	     0, new Gtk::Label(''),
	     0, new Gtk::Label(_("Copyright (C) 2001 Mandrakesoft SA")),
	     0, new Gtk::Label(''),
	     1, $clist,
	    );
    $clist->columns_autosize();
    $window_about->set_policy(0, 0, 1);
    $window_about->show_all();
    $window_about->set_modal(1);
}

sub connect_to_site {
    my ($link,$help)=@_;
    my $browser = $ENV{BROWSER};
    my $initial_user = $ENV{INITIAL_USER};

    if (!$browser) { splash_warning(" ". _("Warning: No browser specified") ." "); return }

    if ($help)  {
    	system("$browser $link &");
    } else  {
	if ($initial_user ne "root" && $initial_user ne undef) {
	    system("su -m -l $initial_user -c \"$browser $link &\"");
	} else {
	    splash_warning(" "._("Security Warning: I'm not allowed to connect to the internet as root user")." ");
	}	    
    }
}

sub get_main_menu {
    my ($window) = @_;
    my $accel_group = new Gtk::AccelGroup();
    my $item_factory = new Gtk::ItemFactory('Gtk::MenuBar', '<main>', $accel_group);
    my @theme_list = grep { -d "$themes_dir/$_" } all($themes_dir);
    $item_factory->create_items(
				(
				 { path => _("/_File"),
				   type => '<Branch>' },
				 { path => _("/File")._("/_Quit"),
				   accelerator => _("<control>Q"),
				   callback => \&quit_global },
				 { path => _("/_Options"),
				   type => '<Branch>' },
				 { path => _("/Options")._("/Display _Logs"),
				   callback => sub  {
					  $logs = $log_check_box->active;
					  update_exp() },
				   type => '<CheckItem>' },
				 { path => _("/Options")._("/_Embedded Mode"),
				   callback => sub { $embedded = $embedded_check_box->active },
				   type => '<ToggleItem>'},
				 if_(all($themes_dir) > 1,
				     { path => _("/_Themes"),
				       type => '<Branch>' },
				     (map { my $l = $_;
					    my %h = (
						     path => _("/Themes"). "/" .  ($l eq $theme ? " O  " : "      ") . "_$l",
						     callback => sub {
							 $theme eq $l and return;
							 !$pending_app || splash_warning(
     _("This action will restart the control center.\nAny change not applied will be lost."), 1) and sig_usr1(), exec "$0 --theme $l";
						     },
						    );
					    \%h;
					} @theme_list),
				     { path => _("/_Themes")._("/_More themes"),
				       callback => \&more_themes },
				    ),
				 { path => _("/_Help"),
				   type => '<Branch>' },
				 { path => _("/Help")._("/_Report Bug"),
				   callback => sub { system("drakbug --report drakconf &") } },
				 { path => _("/Help")._("/_About..."),
				   callback => \&about_mdk_cc }
				)
			       );
    $window->add_accel_group($accel_group);
    $log_check_box = $item_factory->get_widget("<main>"._("/Options")._("/Display Logs"));
    $embedded_check_box = $item_factory->get_widget("<main>"._("/Options")._("/Embedded Mode"));
    return ($item_factory->get_widget('<main>'));
}