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
|
#!/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 $_wizdir = "/usr/share/wizards";
!$ENV{DISPLAY} and exec ("$_sbindir/drakxconf; reset");
require Gtk;
use lib qw(/usr/lib/libDrakX);
use lib qw(/usr/lib/libDrakX);
use common;
use interactive;
use detect_devices;
use standalone;
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;
my $in = 'interactive'->vnew('su', 'default');
my $_version = "0.95";
my $conffile = "/root/.mcc";
my %h = getVarsFromSh($conffile);
my $embedded;
my $logs;
my $theme;
defined $h{THEME} or $h{THEME} = 'default';
defined $h{EMBEDDED} or $h{EMBEDDED} = bool2text(1);
defined $h{LOGS} or $h{LOGS} = bool2text(0);
($embedded, $logs) = (text2bool($h{EMBEDDED}), text2bool($h{LOGS}));
$theme = $h{THEME};
if ("@ARGV" =~ /--theme (\w+)/) { $theme = $1 }
-d "$mcc_dir/$theme" or $theme = 'default';
"@ARGV" =~ /--safe/ and $theme = 'default';
my_gtk::add_icon_path("$mcc_dir/$theme");
my $rc = "$mcc_dir/$theme/gtkrc";
-r $rc and Gtk::Rc->parse($rc);
my ($log_check_box, $embedded_check_box);
$::isWiz = -e "/usr/sbin/wizdrake"; #- $in->do_pkgs->is_installed(q(wizard));
my $exec_hash =
{
#- ("label") => [ "search exp", "exec", gtk_plug? if not, then xplug, "exec_alternative" for when not embedded, or [ args for xplug ] ],
_("Boot Disk") => [ "drakfloppy", "$_xbindir/drakfloppy.real", 1],
_("Boot Config") => [ "drakboot", "$_sbindir/drakboot", 1 ],
_("Auto Install") => [ "drakautoinst", "$_sbindir/drakautoinst", 1 ],
_("Display") => [ "XFdrake", "$_sbindir/XFdrake", 1 ],
_("Hardware List") => [ "harddrake", "$_sbindir/harddrake", 1 ],
_("Mouse") => [ "mousedrake", "$_sbindir/mousedrake", 1 ],
_("Printer") => [ "printerdrake", "$_sbindir/printerdrake", 1, "$_sbindir/printerdrake" ],
_("Scanner") => [ "scannerdrake", "$_sbindir/scannerdrake", 1 ],
_("Keyboard") => [ "keyboarddrake", "$_sbindir/keyboarddrake", 1 ],
_("Hard Drives") => [ "diskdrake", "$_sbindir/diskdrake --hd", 1 ],
# _("Removable disks") => [ "diskdrake", "$_sbindir/diskdrake --removable", 1 ],
_("NFS mount points") => [ "diskdrake", "$_sbindir/diskdrake --nfs", 1 ],
_("Samba mount points") => [ "diskdrake", "$_sbindir/diskdrake --smb", 1 ],
_("Partition Sharing") => [ "diskdrake", "$_sbindir/diskdrake --fileshare", 1 ],
_("Connection") => [ "draknet", "$_sbindir/draknet", 1 ],
_("Connection Sharing") => [ "drakgw", "$_sbindir/drakgw", 1 ],
_("Security Level") => [ "draksec", "$_sbindir/draksec", 1 ],
_("Firewalling") => [ "tinyfirewall", "$_sbindir/tinyfirewall", 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 ],
_("Software Manager") => [ "rpmdrake", "$_bindir/rpmdrake", -1 ],
_("Logs") => [ "logdrake", "$_sbindir/logdrake", 1 ],
_("Console") => [ "rxvt", "", 0, ["$_xbindir/rxvt", "rxvt", 1] ],
_("Users") => [ "userdrake", "$_bindir/userdrake", 1 ],
_("DNS Client") => ["Client wizard", "wiz $_wizdir/client_wizard/client.wiz", -1 ],
_("DHCP") => ["DHCP wizard", "wiz $_wizdir/dhcp_wizard/dhcp.wiz", -1 ],
_("DNS") => ["DNS wizard", "wiz $_wizdir/dns_wizard/dns.wiz", -1 ],
_("Firewall") => ["Firewall wizard", "wiz $_wizdir/firewall_wizard/firewall.wiz", -1 ],
_("FTP") => ["FTP wizard", "wiz $_wizdir/ftp_wizard/ftp.wiz", -1 ],
_("News") => ["News wizard", "wiz $_wizdir/news_wizard/news.wiz", -1 ],
_("Postfix") => ["Postfix wizard", "wiz $_wizdir/postfix_wizard/postfix.wiz", -1 ],
_("Proxy") => ["Squid wizard", "wiz $_wizdir/proxy_wizard/proxy.wiz", -1 ],
_("Samba") => ["Samba wizard", "wiz $_wizdir/samba_wizard/samba.wiz", -1 ],
_("Server") => ["Server wizard", "wiz $_wizdir/server_wizard/server.wiz", -1 ],
_("Time") => ["Time wizard", "wiz $_wizdir/time_wizard/time.wiz", -1 ],
_("Web") => ["Web wizard", "wiz $_wizdir/web_wizard/web.wiz", -1 ],
};
my %wizard = ( "client" => [ _("DNS Client"), 'server-mdk'],
"dhcp" => [ _("DHCP"), 'server-mdk'],
"dns" => [ _("DNS"), 'server-mdk'],
"firewall" => [ _("Firewall"), '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'],
);
my @tree =
( [_("Boot"), 'boot-mdk',
[
[_("Boot Disk"), 'drakfloppy-mdk'],
[_("Boot Config"),'drakboot-mdk'],
[_("Auto Install"), 'drakfloppy-mdk'],
]
],
[_("Hardware"), 'drakhard-mdk',
[
[_("Hardware List"),'harddrake-mdk'],
[_("Display"),'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'],
[_("Partition Sharing"), 'diskdrake_fileshare'],
]
],
[_("Network & Internet"),'net-mdk',
[
[_("Connection"), 'draknet-mdk'],
[_("Connection Sharing"),'drakgw-mdk'],
],
],
[_("Security"),'security-mdk',
[
[_("Security Level"), 'draksec-mdk'],
[_("Firewalling"), 'firewall-mdk'],
]
],
[_("System"),'system-mdk',
[
[_("Menus") , 'menudrake-mdk'],
[_("Services") , 'service-mdk'],
[_("Fonts"), 'drakfont-mdk'],
[_("Date & Time") , 'time-mdk'],
[_("Software Manager"), 'rpmdrake-mdk'],
[_("Logs"), 'logdrake-mdk'],
[_("Console"), 'console-mdk'],
[_("Users"), 'user-mdk'],
]
],
if_($::isWiz,
[_("Server Configuration"), 'wizard-mdk',
[
( map { if_(/wizards_lib-(\w+)-\d+.*/ && member($1, keys %wizard), $wizard{$1}) }
split('\n', `rpm -qa | grep wizards_lib-`)
)
]
]),
);
#-------------------------------------------------------------
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", 'beta' )); #$_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 $cursor_busy = new Gtk::Gdk::Cursor 150;
my @back;
($back[0], undef) = gtkcreate_png_('mcc-left-back');
($back[2], undef) = gtkcreate_png_('mcc-left-back2');
$back[1] = $back[0];
#my $style_dflt = Gtk::Widget->get_default_style;
# fontsets *must* be used in order to allow proper font selection for non
# latin1 languages; never use a simple font, *always* load a fontset
# $style_dflt->font(Gtk::Gdk::Font->fontset_load(_("-*-times-bold-r-normal-*-14-*-*-*-p-*-iso8859-1,*-r-*")));
my $index = 0;
my $darea_left_sav;
my $left_locked = 0;
my $pending_app = 0;
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;
#FIXME
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 $exp_socket;
my $emb_box;
my $emb_wait;
my $emb_socket;
my @pid_launched;
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),
)
),
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'),
$exp_socket = new Gtk::Socket,
)
);
$rootheight <= 600 and $fixed_title->hide;
$exp_frame->show_all;
}
if (!$logs && $exp_frame) {
$exp_frame->destroy();
undef $exp_frame;
defined($exp_socket) and $exp_socket->destroy();
$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_splash_map, undef) = gtkcreate_png_('mcc-splash');
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-*")));
#_("-adobe-times-bold-r-normal--17-*-100-100-p-*-iso8859-*,*-r-*")));
$pix_dbl->draw_string($style->font, $darea1->style->black_gc, 80, 115, _("Welcome to the Mandrake Control Center") );
my @revtree;
open VERS, "/etc/mandrake-release" or die _("cannot open this file for read: %s", $!);
while (<VERS>) { push (@revtree,$_) }
my @info_tree = split / /, $revtree[0];
my ($sysname, $nodename, $release, $version, $machine) = POSIX::uname();
my $i=0;
foreach(
[_("System:"), "$info_tree[0] $info_tree[1] $info_tree[3] $info_tree[4]"],
[_("Hostname:"), $nodename],
[_("Kernel Version:"), "$release"],# $version"],
[_("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;
});
my $cursor = new Gtk::Gdk::Cursor 15;
foreach (@tree) {
my $w = gtkicons_labels_widget($_->[2], $window_global, "#0#0#0", $window_global->style->font,
#"-urw-times-bold-r-normal-*-*-100-*-*-p-*-iso8859-1"),
$pixmap_back_right, 540, 460, 55, 50, 50, 50, 50, 50, \&compute_exec_string, $exec_hash);
$notebook_global->append_page($w);
}
#$window_global->show_all;
#$emb_box->hide;
#$window_global->realize;
my %tree_launched;
#$window_global->hide;
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;
$emb_box->hide;
#my $p = $#tree + $::isWiz ? 1 : 0;
#foreach (0..) {
# $notebook_global->set_page($_);
# Gtk->main_iteration while Gtk->events_pending;
#}
$notebook_global->set_page(0);
$window_global->set_default_size(715, 515);
$window_global->set_position(1);
$SIG{USR1} = \&sig_usr1;
$SIG{USR2} = \&sig_usr2;
$SIG{TERM} = \&quit_global; # embedded applications will send me that signal in order to quit the cc.
Gtk->main;
#---
# icon handling
#---
# my @icon_cache;
sub gtkpng_ {
my $gtkpix;
eval { $gtkpix = gtkpng(@_) };
$@ and $theme ne 'default' ? exec "$0 --safe" : die "$@";
# push @icon_cache, { type => 'gtkpng', name => $_[0], data => $gtkpix };
$gtkpix;
}
sub gtkcreate_png_ {
my ($gdkpix, $gdkmap);
eval { ($gdkpix, $gdkmap) = gtkcreate_png(@_) };
$@ and $theme ne 'default' ? exec "$0 --safe" : die "$@";
# push @icon_cache, { type => 'gdkpng', name => $_[0], data => [$gdkpix, $gdkmap] };
($gdkpix, $gdkmap);
}
#---
# signal handlers
#---
sub sig_usr1 { # embedded applications will send me that signal in order to "kill/hide" them}
$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;
Gtk->timeout_remove($timer);
$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) : '';
}
}
#---
# launching applications
#---
sub compute_exec_string {
my ($arg) = @_;
my ($log_exp, $exec, $gtkplug, $alternate) = @$arg;
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;
$timer = Gtk->timeout_add(15000, sub { splash_warning(_("This tool seems to be broken, as it didn't show up.\n Try to reinstall it")); sig_usr1(); });
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(($alternate ? $alternate : $exec) . " &");
}
if($logs) {
$exp_socket->realize;
my $pid;
unless ($pid = fork) {
splash_warning(_("cannot fork: %s", $~)) unless defined $pid;
exec("logdrake --explain=$log_exp --embedded " . $exp_socket->window->XWINDOW . " " . $$);
}
push @pid_launched, $pid;
}
if ($embedded && $gtkplug != -1) {
foreach (@darea_left_list) {
$_->[1]->window->set_cursor($cursor_hand);
if($_->[1]->{state} != 0) {
$_->[1]->{state} = 0;
$_->[1]->draw(undef);
}
}
}
}
sub launch_xapp {
# my ($exec, $grep, $num) = @_;
my $b = "xwininfo -root -tree -int | grep '" . $_[0]->[1] . "'";
my @before = split ('\n', `$b`);
my $pid;
unless ($pid = fork) {
splash_warning(_("cannot fork: %s", $~)) unless defined $pid;
exec($_[0]->[0]);
}
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;
}
#---
# socket handling
#---
sub clean_socket {
$emb_box->hide;
$logs and $exp_frame->hide;
foreach (@pid_launched) {
kill 'TERM', $_ if (defined $_);
}
@pid_launched = ();
$emb_socket and $emb_socket->destroy();
$exp_socket and $exp_socket->destroy();
$logs and $exp_frame->show;
$pending_app = 0;
}
sub res_socket {
clean_socket();
gtkpack($emb_box, $emb_socket = new Gtk::Socket);
$emb_socket->hide;
$emb_wait->hide;
$logs and gtkadd($exp_frame, $exp_socket = new Gtk::Socket);
}
#---
# exit
#---
sub quit_global {
foreach(@pid_launched) {
kill 'TERM', $_ if (defined $_);
}
setVarsInSh($conffile, {
EMBEDDED => bool2text($embedded),
LOGS => bool2text($logs),
THEME => $theme,
});
Gtk->exit(0);
}
#---
# additional / info
#---
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 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"));
my $bbox1 = new Gtk::HButtonBox;
$window_about->action_area->pack_start($bbox1,0,0,0);
my $button = new Gtk::Button(_("Close"));
$button->signal_connect_object("clicked", $window_about => 'destroy');
$bbox1->add($button);
my $label = new Gtk::Label( _("Mandrake Control Center %s\n", $_version) );
my $style1 = $label->style;
$style1->font(Gtk::Gdk::Font->fontset_load(_("-*-helvetica-medium-r-normal-*-20-*-100-100-p-*-iso8859-1,*-r-*")));
$label->set_style($style1);
$window_about->vbox->pack_start( $label, 1, 1, 0 );
$window_about->vbox->pack_start( new Gtk::Label( _("Copyright (C) 2001 Mandrakesoft SA")), 1, 1, 0);
$window_about->vbox->pack_start( new Gtk::Label( ''), 1, 1, 0 );
$window_about->vbox->pack_start( new Gtk::Label( _("Author: ") . "Damien Krotkine <damien\@mandrakesoft.com>\n"), 1, 1, 0 );
$window_about->vbox->pack_start( new Gtk::Label( _("Technology Contributor: ") . "Yves Duret <yduret\@mandrakesoft.com>"), 1, 1, 0 );
$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'};
my $user_current=$ENV{'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")." ");
}
}
}
#---
# menu related functions
#---
sub display_logs {
$logs = $log_check_box->active;
update_exp();
}
sub embedded_mode {
$embedded = $embedded_check_box->active;
}
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 "$mcc_dir/$_" } all($mcc_dir);
my $ignore_active;
$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 => \&display_logs,
type => '<CheckItem>' },
{ path => _("/Options")._("/_Embedded Mode"),
callback => \&embedded_mode,
type => '<ToggleItem>'},
{ 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 => _("/_Help"),
type => '<Branch>' },
# { path => _("/Help")._("/_Help on line"), callback => sub { Gtk->exit(0) } },
# { path => _("/Help")._("/_Report Bug"),
# callback => \&connect_to_site("https://qa.mandrakesoft.com/")},
# { path => _("/Help/-"),
# type => '<Separator>' },
# { path => _("/Help")._("/Mandrake_Campus"),
# callback => \&connect_to_site("http://www.mandrakecampus.com/") },
# { path => _("/Help")._("/Mandrake_Expert"),
# callback => \&connect_to_site("http://www.mandrakeexpert.com/") },
# { path => _("/Help/-"),
# type => '<Separator>' },
{ 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>'));
}
|