summaryrefslogtreecommitdiffstats
path: root/bin/drak3d
blob: 14abbe07627a9c2f7ac507dabd16cefab6eee146 (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
#!/usr/bin/perl

# Copyright (C) 2006 Mandriva
#                    Olivier Blin <blino@mandriva.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 strict;

use lib qw(/usr/lib/libDrakX);

# i18n: IMPORTANT: to get correct namespace (drak3d instead of libDrakX)
BEGIN { unshift @::textdomains, 'drak3d' }

use standalone;
use common;
use interactive;
use do_pkgs;
use Xconfig::glx;
use any;
use Getopt::Long;

my $in = eval { interactive->vnew('su') };
$in || $::auto or die $@;
my $do_pkgs = $in ? $in->do_pkgs : do_pkgs_standalone->new;

sub exit_program { $in ? $in->exit(@_) : exit(@_) }

my $glx = Xconfig::glx::detect_may_install($do_pkgs) or exit_program();
my $running_wm = any::running_window_manager();

my $o_method;
my $o_wm;
my $force;
GetOptions(
    "method=s" => \$o_method,
    "wm=s" => \$o_wm,
    "force" => \$force,
) or warn "invalid options";

my $use_arguments = $force || !$o_method || $glx->{capabilities}{$o_method};
$glx->{method} = $use_arguments && $o_method if $o_method;
$glx->{wm} = $use_arguments && $o_wm if $o_wm;

my @advanced_settings = (
    [ N_("A graphical server supporting OpenGL compositing should be selected."), 'methods', 'method', \@Xconfig::glx::gl_compositing_servers, 1 ],
    [ N_("An OpenGL compositing window manager should be selected. It provides 3D desktop and compositing effects in window management, such as translucent windows and moving effects."), 'wms', 'wm', \@Xconfig::glx::gl_compositing_wms, 0 ],
);

sub choose_gtk {
    my ($glx) = @_;
    require mygtk2;
    import mygtk2 qw(gtknew);
    require ugtk2;
    import ugtk2 qw(:create :helpers :wrappers :dialogs);

    $ugtk2::wm_icon = 'drak3d-16';
    my $title = N("3D Desktop effects");
    my $w = ugtk2->new($title, no_Window_Manager => !$running_wm);

    $::main_window = $w->{real_window}; #- so that transient_for is defined for wait messages and dialogs

    my $types_group;
    my %state;
    (my $available_types, $state{type}) = Xconfig::glx::detect_types($glx);
    $state{type} and $state{$state{type}{type}}{$_} = $glx->{$_} foreach map { $_->[2] } @advanced_settings;
    foreach my $type (@Xconfig::glx::gl_compositing_types) {
        foreach (@advanced_settings) {
            my (undef, $available, $field, $list, $check_capabilities) = @$_;
            my @available = @{$type->{$available} || []};
            my $default = find {
                member($_->{$field}, @available) && (!$check_capabilities || $glx->{capabilities}{$_->{$field}});
            } @$list;
            $state{$type->{type}}{$field} ||= $default && $default->{$field};
        }
    }

    gtkadd($w->{window},
           gtknew('VBox', spacing => 5, children => [
               $::isEmbedded ? () : (0, Gtk2::Banner->new('drak3d', $title)),
               0, gtknew('Title2', label => N("This tool allows you to configure 3D desktop effects.")),
               if_(!$glx->{supported}, 0, N("Your system does not support 3D desktop effects.")),
               1, gtknew('VBox', spacing => 5, children_tight => [
                   (map {
                       my $type = $_;
                       my @advanced = map {
                           my ($text, $available, $field, $list, $check_capabilities) = @$_;
                           my $radio_group;
                           @{$type->{$available} || []} > 1 ? (
                               gtknew('WrappedLabel', text => translate($text),
                                      alignment => [ 0, 0 ], padding => [ 10, 0 ]),
                               gtknew('HBox', children => [
                                   0, gtknew('Label', text => ' ' x 10),
                                   1, gtknew('VBox', children_tight => [
                                       map {
                                           my $val = $_;
                                           my $match = find { $_->{$field} eq $val } @$list;
                                           $radio_group = gtknew('RadioButton', text => translate($match->{name}),
                                                                 $radio_group ? (group => $radio_group->get_group) : (),
                                                                 if_($check_capabilities, sensitive => $glx->{capabilities}{$val}),
                                                                 active => $state{$type->{type}}{$field} eq $match->{$field},
                                                                 toggled => sub { $state{$type->{type}}{$field} = $match->{$field} if $_[0]->get_active },
                                                             );
                                       } @{$type->{$available}}
                                   ]),
                               ]),
                           ) : ();
                       } @advanced_settings;
                       gtknew('HBox', children_tight => [
                           gtknew('VBox', children => [
                               0, gtknew('Image', file => "IC-3D-" . $type->{type} . "-64.png"),
                               1, gtknew('Label'),
                           ]),
                           gtknew('VBox', children_tight => [
                               gtknew('Label'),
                               $types_group = gtknew('RadioButton', text => translate($type->{name}),
                                                       $types_group ? (group => $types_group->get_group) : (),
                                                       sensitive => member($type, @$available_types),
                                                       active => $state{type} eq $type,
                                                       toggled => sub {
                                                           $state{type} = $type if $_[0]->get_active;
                                                           $state{advanced}{$_}->set_sensitive($state{type}{type} eq $_) foreach keys %{$state{advanced}};
                                                       },
                                                   ),
                               @advanced ?
                                 gtknew('HBox', children_tight => [
                                     gtknew('Label', text => ' ' x 5),
                                     $state{advanced}{$type->{type}} =  gtknew('Expander', text => N("Advanced settings"),
                                            sensitive => $state{type} eq $type,
                                            child => gtknew('VBox', children_tight => \@advanced)),
                                 ]) : (),
                           ]),
                       ]);
                   } @Xconfig::glx::gl_compositing_types),
               ]),
               0, $w->create_okcancel(undef, undef, undef, [ N("Help"), sub { run_program::raw({ detach => 1 }, 'drakhelp', '--id', 'drak3d') } ]),
           ]),
       );

    $w->main;
    $glx->{method} = $state{$state{type}{type}}{method} || find { $glx->{capabilities}{$_} } @{$state{type}{methods}};
    $glx->{wm} = $state{$state{type}{type}}{wm} || first(@{$state{type}{wms}});
    $w->{retval};
}

my $res;
if ($::auto) {
    $res = 1;
} elsif ($in->isa('interactive::gtk')) {
    $res = choose_gtk($glx);
} else {
    $res = Xconfig::glx::choose_interactive($in, $glx);
}
if ($res && Xconfig::glx::install($do_pkgs, $glx)) {
    Xconfig::glx::write($glx);
    any::ask_for_X_restart($in) if $in;
}

exit_program();