summaryrefslogtreecommitdiffstats
path: root/control-center2
blob: 1b4b974de8d053d7b2d31f131f014b8ddaaee7c2 (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
#!/usr/bin/perl

# Control-center

# Copyright (C) 1999 MandrakeSoft (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.


use Gtk;
init Gtk;
use Data::Dumper;
#local $_ = join '', @ARGV;
#if ($ARGV[1]=  )
#/-h/ and die "usage: draknet[--xf3] [--beginner] [--expert] [--auto] [--noauto] [--skiptest] [--testing]\n";

my %pixmaps_global;
my $xpm_path="pixmaps";

my $window_global = new Gtk::Window -toplevel;
$window_global->set_usize(640, 480);
$window_global->signal_connect ( delete_event => sub { Gtk->exit(0); });
$window_global->set_position(1);
$window_global->set_title("Control Center");
$window_global->border_width(0);

$vbox_global = new Gtk::VBox(0, 0);
$window_global->add($vbox_global);

######### menus
my @item_factory_entries = (
			    ["/_File",	undef,	0,	"<Branch>"],
			    ["/File/tearoff1",	undef,	0,	"<Tearoff>"],
			    ["/File/_New",	"<control>N",	1],
			    ["/File/_Open",	"<control>O",	2],
			    ["/File/_Save", "<control>S",	3],
			    ["/File/Save _As...",	undef,	4],
			    ["/File/sep1",	undef,	0,	"<Separator>"],
			    #["/File/_Quit",	"<control>Q",	5],
			    {
			     'path' => "/File/_Quit", 
			     'accelerator' => "<control>Q",	
			     'action' => 5,
			     'type' => '<Item>'
			    },

			    ["/_Preferences",	undef,	0,	"<Branch>"],
			    ["/_Preferences/_Color",	undef,	0,	"<Branch>"],
			    ["/_Preferences/Color/_Red",	undef,	10,	"<RadioItem>"],
			    ["/_Preferences/Color/_Green",	undef,	11,	"<RadioItem>"],
			    ["/_Preferences/Color/_Blue",	undef,	12,	"<RadioItem>"],
			    ["/_Preferences/_Shape",	undef,	0,	"<Branch>"],
			    ["/_Preferences/Shape/_Square",	undef,	20,	"<RadioItem>"],
			    ["/_Preferences/Shape/_Rectangle",	undef,	21,	"<RadioItem>"],
			    ["/_Preferences/Shape/_Oval",	undef,	22,	"<RadioItem>"],

			    ["/_Help",	undef,	0,	"<LastBranch>"],
			    ["/Help/_About",	undef,	30]
			   );

my ($accel_group, $item_factory, $box1, $label, $box2);
my ($separator, $button, $dummy);

$accel_group = new Gtk::AccelGroup;
$item_factory = new Gtk::ItemFactory('Gtk::MenuBar', "<main>", $accel_group);

$accel_group->attach($window_global);
foreach (@item_factory_entries) {
    $item_factory->create_item($_, \&item_factory_cb);
}

$vbox_global->pack_start($item_factory->get_widget('<main>'), 0, 0, 0);
$hseparator_global = new Gtk::HSeparator;
$vbox_global->pack_start($hseparator_global, 0, 1, 0);
######### menus end


my $hbox_global = new Gtk::HBox(0,0);
$vbox_global->pack_start($hbox_global, 1, 1, 0);
$hbox_global->border_width(5);
my $scrolled_global = new Gtk::ScrolledWindow;
$scrolled_global->set_policy('automatic','automatic');
$scrolled_global->set_usize(100, 0);
$scrolled_global->set_name("icons_back");
#$scrolled_global->window->draw_rectangle(nil,1, 0, 0, 70, 70); #$scrolled_global->window->style->bg_gc('normal')
$hbox_global->pack_start($scrolled_global,0,1,0);
my $vseparator_global = new Gtk::VSeparator;
$hbox_global->pack_start($vseparator_global,0,1,0);

my $notebook_global = new Gtk::Notebook;
$notebook_global->set_show_border(0);
$notebook_global->set_show_tabs(0);
$hbox_global->pack_start($notebook_global,1,1,0);

my ($pix_about_map, $pix_about_mask) = Gtk::Gdk::Pixmap->create_from_xpm(NULL, Gtk::Widget->get_default_style->bg('normal'),  "$xpm_path/logo1.xpm");
my $pix_about = new Gtk::Pixmap ($pix_about_map, $pix_about_mask);
my $vbox_about = new Gtk::VBox(1,0);
$vbox_about->pack_start($pix_about, 1, 1, 0);
my $text_about = new Gtk::Text ();
$text_about->set_editable(0);
$text_about->insert ( undef, undef, undef, "About, help, click on that button...");
$vbox_about->pack_start($text_about, 1, 1, 0);
my $label_about2 = new Gtk::Label ("");
$vbox_about->pack_start($label_about2, 1, 1, 0);
$notebook_global->append_page($vbox_about, "$arg");

my $vbox_global_left = new Gtk::VBox(0,0);
$scrolled_global->add_with_viewport($vbox_global_left);

$window_global->realize;
map {
    $pixmaps_global{$_ . '_pixmap'} =
      Gtk::Gdk::Pixmap->create_from_xpm($window_global->window, Gtk::Widget->get_default_style->bg('normal'),  "$xpm_path/$_.xpm");
} ('item1', 'item2', 'item3', 'item4', 'item5','draknet1','draknet2','draknet3','draknet4', 'draknet5', 'drakgw');

my %tree;
$tree{nb_groups}=2;
$tree[0]{name}="groupe1";
$tree[0]{nb_applis}=2;
$tree[0]{applis}[0]{name}='DrakFont';
$tree[0]{applis}[0]{exec}='drakfont';
$tree[0]{applis}[1]{name}='DrakFloppy';
$tree[0]{applis}[1]{exec}='drakfloppy';
$tree[1]{name}="groupe2";
$tree[1]{nb_applis}=2;
$tree[1]{applis}[0]{name}='DrakFont';#'drakxservices';
$tree[1]{applis}[0]{exec}='drakfont';#'drakxservices';
$tree[1]{applis}[1]{name}='DrakFloppy';#'drakboot';
$tree[1]{applis}[1]{exec}='drakfloppy';#'drakboot';
#print Data::Dumper->Dump([%tree], ['tree']) . "\n";
print "nb gr : " . $tree{nb_groups} . "\n";
my $num=0;
my $group;
for ( $group=0; $group<$tree{nb_groups}; $group++) {
    print "group : $group\n";
    draw_icon(56, 36, 'item', 0, "", $tree[$group]{name}, $group);
    for ($item=0; $item<$tree[$group]{nb_applis}; $item++) {
	print "item : $item\n";
	draw_icon(56, 36, 'item', 1, $tree[$group]{applis}[$item]{exec}, $tree[$group]{applis}[$item]{name}, $num);
	$num++;
    }
}
print Data::Dumper->Dump([$tree[0]{applis}[0]], ['tree-applis->0-->']) . "\n";

  #########


my $area_global = new Gtk::DrawingArea;
$vbox_global_left->pack_start($area_global,1,1,0);
my $rc = "control-center.rc";
Gtk::Rc->parse($rc);
$window_global->show_all;
for (my $i=0; $i<$tree{nb_groups}; $i++) {
    for (my $j=0; $j<$tree[$i]{nb_applis}; $j++) {
	$tree[$i]{applis}[$j]{darea}->hide;
	$tree[$i]{applis}[$j]{label}->hide;
    }
}
print "num : " . $notebook_global->page_num($vbox_about) . "\n";
$notebook_global->set_page(0);
Gtk->main;




sub draw_icon {
    my ($width, $height, $icon_name, $decalage, $exec_string, $name, $number ) = @_;
    my %hash;
    if ($exec_string) {
	my $socket = new Gtk::Socket;
	$socket->show;
	$notebook_global->append_page($socket, "");
	$socket->realize;
	print ("The XID of the sockets window n°$arg is [" . $socket->window->XWINDOW . "]\n");
 	system ( $exec_string . " --embedded " . $socket->window->XWINDOW . "&");
    }
    $hash{PIX_W} = $width;
    $hash{PIX_H} = $height;
    $hash{actual_pixmap}=1;
    $hash{save_pixmap}=0;
    $hash{anim_idle}=undef;
    $hash{timeout}=undef;
    $hash{darea} = new Gtk::DrawingArea;
    $hash{label} = new Gtk::DrawingArea;
    $hash{label}->set_usize(50, 12);
    $hash{label}->signal_connect(expose_event => sub {
				      my $font = $hash{label}->style->font;
				      my $w = $font->string_width($name);
				      $hash{label}->window->draw_string($font, $hash{label}->style->fg_gc('normal'), ($hash{label}->allocation->[2] - $w) / 2 * 0 + $decalage*20, 9, $name ); #($hash{label}->allocation->[3]-40)/2
#				      $hash{label}->window->draw_string($font, $hash{label}->style->bg_gc('normal'), 0, 10, "QQWWylt"); #($hash{label}->allocation->[3]-40)/2
});

    if ($exec_string) {
	$tree[$group]{applis}[$item]{darea} = $hash{darea};
	$tree[$group]{applis}[$item]{label} = $hash{label};
    }
    $hash{darea}->set_usize($width,$height);
    $hash{darea}->set_events(['exposure_mask', 'enter_notify_mask', 'leave_notify_mask', 'button_press_mask', 'button_release_mask' ]);
    $hash{darea}->signal_connect
      (expose_event => sub {
	   $hash{darea}->window->draw_pixmap
	     ($hash{darea}->style->bg_gc('normal'),
	      $pixmaps_global{ $icon_name . $hash{actual_pixmap} . '_pixmap'}, 0, 0,
	      ($hash{darea}->allocation->[2]-$hash{PIX_W})/2*0+($decalage * 20),
	      ($hash{darea}->allocation->[3]-$hash{PIX_H})/2,
	      $hash{PIX_W} , $hash{PIX_H} );
       });


    $hash{darea}->signal_connect
      (enter_notify_event => sub {
	   $hash{anim_idle} ||= Gtk->idle_add
	     ( sub {
		   $hash{actual_pixmap}==$hash{save_pixmap} and return 1;
		   $hash{darea}->window->draw_pixmap 
		     ($hash{darea}->style->bg_gc('normal'),
		      $pixmaps_global{ $icon_name . $hash{actual_pixmap} . '_pixmap'},
		      0, 0,
		      ($hash{darea}->allocation->[2]-$hash{PIX_W})/2*0+($decalage * 20),
		      ($hash{darea}->allocation->[3]-$hash{PIX_H})/2,
		      $hash{PIX_W} , $hash{PIX_H} );
		   $hash{save_pixmap}=$hash{actual_pixmap};
		   return 1;
	       });

	   $hash{timeout} ||= Gtk->timeout_add
	     ( 50, sub {
		   $hash{actual_pixmap}++;
		   $hash{actual_pixmap}>5 and $hash{actual_pixmap}=1;
		   return 1;
	       });
       });


    $hash{darea}->signal_connect
      (leave_notify_event => sub {
	   Gtk->main_iteration() while ($hash{save_pixmap}!=1);
	   Gtk->idle_remove($hash{anim_idle});
	   Gtk->timeout_remove($hash{timeout});
	   undef $hash{anim_idle};
	   undef $hash{timeout};
       });
    #    $hash{darea}->signal_connect(button_press_event => sub { });
    if ($exec_string) {
	$hash{darea}->signal_connect(button_release_event => sub { $notebook_global->set_page($number+1); });
    } else {
	$hash{darea}->signal_connect(button_release_event => sub {
					 print "group : $number\n";
					 for (my $i=0; $i<$tree{nb_groups}; $i++) {
					     for (my $j=0; $j<$tree[$i]{nb_applis}; $j++) {
						 if ($i==$number) {
						     #print "yep i : $i ; j : $j\n";
						     #print Data::Dumper->Dump([$tree[$i]{applis}[$j]{darea}], ['darea-->']) . "\n";
						     $tree[$i]{applis}[$j]{darea}->show;
						     $tree[$i]{applis}[$j]{label}->show;
						 } else {
						     #print "nope i : $i ; j : $j\n";
						     $tree[$i]{applis}[$j]{darea}->hide;
						     $tree[$i]{applis}[$j]{label}->hide;
						 }
					     }
					 }
				     });
    }
    $vbox_global_left->pack_start($hash{darea},0,1,0);
    $vbox_global_left->pack_start($hash{label},0,1,0);
}

sub item_factory_cb {
	my ($widget, $action, @data) = @_;

	print "ItemFactory: activated ", $widget->item_factory_path(), " -> ", $action, "\n";
	$action == 5 and Gtk->exit(0);
}


sub create_item_factory {
	if (!defined $item_factory_window) {
		my ($accel_group, $item_factory, $box1, $label, $box2);
		my ($separator, $button, $dummy);

		
		$item_factory_window = new Gtk::Window('toplevel');
		signal_connect $item_factory_window destroy => \&destroy_window, \$item_factory_window;
		signal_connect $item_factory_window "delete-event" => \&destroy_window, \$item_factory_window;

		$accel_group = new Gtk::AccelGroup;
		$item_factory = new Gtk::ItemFactory('Gtk::MenuBar', "<main>", $accel_group);
		
		#$item_factory_window->set_data('<main>', $item_factory);
		$accel_group->attach($item_factory_window);
		# $item_factory->create_items();
		foreach (@item_factory_entries) {
			$item_factory->create_item($_, \&item_factory_cb);
		}
		
		$item_factory_window->set_title("Item Factory");
		$item_factory_window->set_border_width(0);
		
		$box1 = new Gtk::VBox(0, 0);
		$item_factory_window->add($box1);
		$box1->pack_start($item_factory->get_widget('<main>'), 0, 0, 0);

		$label = new Gtk::Label "Type\n<alt>\nto start";

		$label->set_usize(200, 200);
		$label->set_alignment(0.5, 0.5);
		$box1->pack_start($label, 1, 1, 0);

		$separator = new Gtk::HSeparator;
		$box1->pack_start($separator, 0, 1, 0);

		$box2 = new Gtk::VBox(0, 10);
		$box2->set_border_width(10);
		$box1->pack_start($box2, 0, 1, 0);

		$button = new Gtk::Button("close");
		$button->signal_connect('clicked', sub {$item_factory_window->destroy;});
		$box2->pack_start($button, 1, 1, 0);
		$button->can_default(1);
		$button->grab_default;

	}
	if (!visible $item_factory_window) {
		show_all $item_factory_window;
	} else {
		destroy $item_factory_window;
	}
}