summaryrefslogtreecommitdiffstats
path: root/perl-install/wizards.pm
blob: 9a262a2160997fe39e51a48aa05ecdf2b8695f90 (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
package wizards;
# $Id$

use strict;
use c;
use common;

=head1 NAME

wizards - a layer on top of interactive that ensure proper stepping

=head1 SYNOPSIS

    use wizards;
    use interactive;

    my $wiz = wizards->new({

               allow_user => "", # do we need root
               defaultimage => "", # wizard icon
               init => sub { },    # code run on wizard startup
               name => "logdrake", # wizard title
               needed_rpm => "packages list", # packages to install before running the wizard
               pages => {
                         {
                             name => "welcome", # first step
                             next => "step1",   # which step should be displayed after the current one
                             pre =>  sub { },   # code executing when stepping backward
                             post => sub { },   # code executing when stepping forward;
                                                # returned value is next step name (it overrides "next" field)
                             end => ,       # is it the last step ?
                             default => ,       # default answer for yes/no or when data does not conatains any fields
                             no_cancel => , # do not display the cancel button (eg for first step)
                             no_back => ,   # do not display the back button (eg for first step)
                             ignore => ,    # do not stack this step for back stepping (eg for warnings and the like steps)
                             interactive_help_id => , # help id  (for installer only)
                             data => [],    # the actual data passed to interactive
                         },
                         {
                          name => "step1",
                          data => [
                                   {
                                       # usual interactive fields:
                                       label => N("Banner:"),
                                       val => \$o->{var}{wiz_banner},
                                       list => [] ,
                                       # wizard layer variables:
                                       boolean_list => "", # provide default status for booleans list
                                   },
                                   ],
                      },
                     },
           });
    my $in = 'interactive'->vnew;
    $wiz->process($in);

=head1 DESCRIPTION

wizards is a layer built on top of the interactive layer that do proper
backward/forward stepping for us.

A step is made up of a name/description, a list of interactive fields (see
interactive documentation), a "complete", "pre" and "post" callbacks, an help
id, ...

The "pre" callback is run first. Its only argument is the actual step hash.

Then, if the "name" fiels is a code reference, that callback is run and its
actual result is used as the description of the step.

At this stage, the interactive layer is used to display the actual step.

The "post" callback is only run if the user has steped forward.


Alternatively, you can call safe_process() rather than process().
safe_process() will handle for you the "wizcancel" exception while running the
wizard.  Actually, it should be used everywhere but where the wizard is not the
main path (eg "mail alert wizard" in logdrake, ...), ie when you may need to do
extra exception managment such as destroying the wizard window and the like.

=cut


sub new {
    my ($class, $o) = @_;
    bless $o, $class;
}


sub check_rpm {
    my ($in, $rpms) = @_;
    foreach my $rpm (@$rpms) {
        next if $in->do_pkgs->is_installed($rpm);
        if ($in->ask_okcancel(N("Error"), N("%s is not installed\nClick \"Next\" to install or \"Cancel\" to quit", $rpm))) {
            $::testing and next;
            if (!$in->do_pkgs->install($rpm)) {
                local $::Wizard_finished = 1;
                $in->ask_okcancel(N("Error"), N("Installation failed"));
                $in->exit;
            }
        } else { $in->exit }
    }
}


# sync me with interactive::ask_from_normalize() if needed:
my %default_callback = (complete => sub { 0 });


sub process {
    my ($o, $in) = @_;
    local $::isWizard = 1;
    local $::Wizard_title = $o->{name} || $::Wizard_title;
    local $::Wizard_pix_up = $o->{defaultimage} || $::Wizard_pix_up;
    #require_root_capability() if $> && !$o->{allow_user} && !$::testing;
    check_rpm($in, $o->{needed_rpm}) if ref($o->{needed_rpm});
    if (defined $o->{init}) {
        my ($res, $msg) = &{$o->{init}};
        if (!$res) {
            $in->ask_okcancel(N("Error"), $msg);
            die "wizard failed" if !$::testing;
        }
    }
    
    my @steps;             # steps stack

    # initial step:
    my $next = 'welcome';  
    my $page = $o->{pages}{welcome};
    while ($next) {
        local $::Wizard_no_previous = $page->{no_back};
        local $::Wizard_no_cancel = $page->{no_cancel} || $page->{end};
        local $::Wizard_finished = $page->{end};
        defined $page->{pre} and $page->{pre}($page);
        die qq(inexistant "$next" wizard step) if is_empty_hash_ref($page);
        
        # FIXME or the displaying fails
        my $data = defined $page->{data} ? (ref($page->{data}) eq 'CODE' ? $page->{data}->() : $page->{data}) : [];
        my $data2;
        foreach my $d (@$data) {
            $d->{val} = ${$d->{val_ref}} if $d->{val_ref};
            $d->{list} = $d->{list_ref} if $d->{list_ref};
            #$d->{val} = ref($d->{val}) eq 'CODE' ? $d->{val}->() : $d->{val};
            if ($d->{boolean_list}) { 
                my $i;
                foreach (@{$d->{boolean_list}}) { 
                    push @$data2, { text => $_, type => 'bool', val => \${$d->{val}}->[$i], disabled => $d->{disabled} };
                    $i++;
                }
            } else {
                push @$data2, $d;
            }
        }
        my $name = ref($page->{name}) ? $page->{name}->() : $page->{name};
        my %yesno = (yes => N("Yes"), no => N("No"));
        my $yes = ref($page->{default}) eq 'CODE' ? $page->{default}->() : $page->{default};
        $data2 = [ { val => \$yes, type => 'list', list => [ keys %yesno ], format => sub { $yesno{$_[0]} }, 
                     gtk => { use_boxradio => 1 } } ] if $page->{type} eq "yesorno";
        my $a;
        if (ref $data2 eq 'ARRAY' && @$data2) {
            $a = $in->ask_from_({ title => $o->{name}, 
                                 messages => $name, 
                                 (map { $_ => $page->{$_} || $default_callback{$_} } qw(complete)),
                                 if_($page->{interactive_help_id}, interactive_help_id => $page->{interactive_help_id}),
                               }, $data2);
        } else {
            $a = $in->ask_okcancel($o->{name}, $name, $yes || 'ok');
        }
        # interactive->ask_yesorno does not support stepping forward or backward:
        $a = $yes if $a && $page->{type} eq "yesorno";
        if ($a) {
            # step forward:
            push @steps, $next if !$page->{ignore} && $steps[-1] ne $next;
            my $current = $next;
            $next = defined $page->{post} ? $page->{post}($page->{type} eq "yesorno" ? $yes eq 'yes' : $a) : 0;
            return if $page->{end};
            if (!$next) {
                if (!defined $o->{pages}{$next}) {
                    $next = $page->{next};
                } else {
                    die qq(the "$next" page (from previous wizard step) is undefined) if !$next;
                }
            }
            die qq(Step "$current": inexistant "$next" page) if !exists $o->{pages}{$next};
        } else {
            # step back:
            $next = pop @steps;
        }
        $page = $o->{pages}{$next};
    }
}


sub safe_process {
    my ($o, $in) = @_;
    eval { $o->process($in) };
    my $err = $@;
    if ($err =~ /wizcancel/) {
        $in->exit(0);
    } else { 
        die $err if $err;
    }
}

1;
" --raw - dodaje nośnik, ale go nie aktualizuje.\n"
-#: ../urpmi.addmedia:80 ../urpmi.removemedia:42 ../urpmi.update:49
-#, c-format
-msgid " -c - clean headers cache directory.\n"
-msgstr " -c - czyści katalog nagłówków pamięci podręcznej.\n"
-
-#: ../urpmi.addmedia:81 ../urpmi.removemedia:44 ../urpmi.update:52
+#: ../urpmi.addmedia:80 ../urpmi.removemedia:43 ../urpmi.update:51
#, c-format
msgid " -q - quiet mode.\n"
msgstr " -q - tryb cichy.\n"
@@ -2543,7 +2536,8 @@ msgstr "Utworzenie pliku konfiguracyjnego było niemożliwe [%s]"
#: ../urpmi.addmedia:134
#, c-format
msgid "no need to give <relative path of synthesis> with --distrib"
-msgstr "nie ma potrzeby podawania <ścieżki względnej do syntezy> z opcją --distrib"
+msgstr ""
+"nie ma potrzeby podawania <ścieżki względnej do syntezy> z opcją --distrib"
#: ../urpmi.addmedia:142
#, c-format
@@ -2600,7 +2594,8 @@ msgstr ""
#: ../urpmi.recover:37
#, c-format
-msgid " --list - list transactions since provided date/duration argument\n"
+msgid ""
+" --list - list transactions since provided date/duration argument\n"
msgstr ""
" --list - pokazuje listę zdarzeń wykonanych od wskazanej daty/przez "
"określony okres\n"
@@ -2608,7 +2603,8 @@ msgstr ""
#: ../urpmi.recover:38
#, c-format
msgid " --list-all - list all transactions in rpmdb (long)\n"
-msgstr " --list-all - wyświetla listę wszystkich zdarzeń w rpmdb (długie)\n"
+msgstr ""
+" --list-all - wyświetla listę wszystkich zdarzeń w rpmdb (długie)\n"
#: ../urpmi.recover:39
#, c-format
@@ -2811,7 +2807,8 @@ msgstr "Tylko administrator ma prawo aktualizować nośniki"
#: ../urpmi.update:76
#, c-format
msgid "nothing to update (use urpmi.addmedia to add a media)\n"
-msgstr "brak elementów do aktualizacji (użyj urpmi.addmedia aby dodać nośnik)\n"
+msgstr ""
+"brak elementów do aktualizacji (użyj urpmi.addmedia aby dodać nośnik)\n"
#: ../urpmi.update:94
#, c-format
@@ -2897,17 +2894,21 @@ msgstr " --list-aliases - wypisuje dostępne równoległe aliasy.\n"
#: ../urpmq:62
#, c-format
-msgid " --dump-config - dump the config in form of urpmi.addmedia argument.\n"
-msgstr " --dump-config - zrzuca konfigurację w postaci urpmi.addmedia argument.\n"
+msgid ""
+" --dump-config - dump the config in form of urpmi.addmedia argument.\n"
+msgstr ""
+" --dump-config - zrzuca konfigurację w postaci urpmi.addmedia argument.\n"
#: ../urpmq:63
#, c-format
msgid " --src - next package is a source package (same as -s).\n"
-msgstr " --src - następny pakiet jest pakietem źródłowym (tak jak -s).\n"
+msgstr ""
+" --src - następny pakiet jest pakietem źródłowym (tak jak -s).\n"
#: ../urpmq:64
#, c-format
-msgid " --sources - give all source packages before downloading (root only).\n"
+msgid ""
+" --sources - give all source packages before downloading (root only).\n"
msgstr ""
" --sources - wypisuje wszystkie pakiety źródłowe przed pobraniem\n"
" (tylko root).\n"
@@ -2934,21 +2935,31 @@ msgid " --changelog - print changelog.\n"
msgstr " --changelog - wyświetla dziennik zmian.\n"
#: ../urpmq:81
+#, fuzzy, c-format
+msgid " --conflicts - print conflicts.\n"
+msgstr " --conflicts - znaczniki konfliktów.\n"
+
+#: ../urpmq:82
#, c-format
msgid " --provides - print provides.\n"
msgstr " --provides - wyświetla listę dostarczanych pakietów.\n"
-#: ../urpmq:82
+#: ../urpmq:83
+#, fuzzy, c-format
+msgid " --requires - print requires.\n"
+msgstr " --requires - wszystkie zależności.\n"
+
+#: ../urpmq:84
#, c-format
msgid " --sourcerpm - print sourcerpm.\n"
msgstr " --sourcerpm - nazwa pakietu rpm ze źródłami\n"
-#: ../urpmq:83
+#: ../urpmq:85
#, c-format
msgid " --summary, -S - print summary.\n"
msgstr " --summary, -S - wyświetla podsumowanie.\n"
-#: ../urpmq:85
+#: ../urpmq:87
#, c-format
msgid ""
" --requires-recursive, -d\n"
@@ -2994,7 +3005,8 @@ msgstr " -g - wyświetla grupy wraz z ich nazwami.\n"
#: ../urpmq:96
#, c-format
msgid " -i - print useful information in human readable form.\n"
-msgstr " -i - wyświetla użyteczne informacje w czytelnej formie.\n"
+msgstr ""
+" -i - wyświetla użyteczne informacje w czytelnej formie.\n"
#: ../urpmq:97
#, c-format
@@ -3014,19 +3026,22 @@ msgstr " -r - wyświetla wersję i wydanie wraz z nazwą.\n"
#: ../urpmq:100
#, c-format
msgid " -s - next package is a source package (same as --src).\n"
-msgstr " -s - następny pakiet jest pakietem źródłowym (tak jak --src).\n"
+msgstr ""
+" -s - następny pakiet jest pakietem źródłowym (tak jak --src).\n"
#: ../urpmq:101
#, c-format
msgid ""
" -u - remove package if a more recent version is already "
"installed.\n"
-msgstr " -u - usuwa pakiet jeśli jest już zainstalowana lepsza wersja.\n"
+msgstr ""
+" -u - usuwa pakiet jeśli jest już zainstalowana lepsza wersja.\n"
#: ../urpmq:102
#, c-format
msgid " -y - impose fuzzy search (same as --fuzzy).\n"
-msgstr " -y - wymusza wyszukiwanie niespójności (tak jak --fuzzy).\n"
+msgstr ""
+" -y - wymusza wyszukiwanie niespójności (tak jak --fuzzy).\n"
#: ../urpmq:103
#, c-format
@@ -3045,26 +3060,37 @@ msgstr " żądanie dotyczące nazw lub plików podanych w wierszu poleceń.\n"
msgid "--list-nodes can only be used with --parallel"
msgstr "--list-nodes może być użyta tylko z opcją --parallel"
-#: ../urpmq:360
+#: ../urpmq:206
+#, c-format
+msgid "use -l to list files"
+msgstr ""
+
+#: ../urpmq:363
#, c-format
msgid "no xml info for medium \"%s\", only partial result for package %s"
-msgstr "brak informacji xml dla nośnika \"%s\", uzyskano częściowe wyniki dla pakietu %s"
+msgstr ""
+"brak informacji xml dla nośnika \"%s\", uzyskano częściowe wyniki dla "
+"pakietu %s"
#: ../urpmq:361
#, c-format
msgid "no xml info for medium \"%s\", only partial result for packages %s"
-msgstr "brak informacji xml dla nośnika %s, uzyskano częściowe wyniki dla pakietów %s"
+msgstr ""
+"brak informacji xml dla nośnika %s, uzyskano częściowe wyniki dla pakietów "
+"%s"
#: ../urpmq:364
#, c-format
-msgid "no xml info for medium \"%s\", unable to return any result for package %s"
+msgid ""
+"no xml info for medium \"%s\", unable to return any result for package %s"
msgstr ""
"brak informacji xml dla nośnika %s, uzyskanie wyników dla pakietu %s było "
"niemożliwe"
#: ../urpmq:365
#, c-format
-msgid "no xml info for medium \"%s\", unable to return any result for packages %s"
+msgid ""
+"no xml info for medium \"%s\", unable to return any result for packages %s"
msgstr ""
"brak informacji xml dla nośnika %s, uzyskanie wyników dla pakietów %s było "
"niemożliwe"
@@ -3074,3 +3100,41 @@ msgstr ""
msgid "No changelog found\n"
msgstr "Nie znaleziono dziennika zmian\n"
+#~ msgid "Unknown option %s"
+#~ msgstr "Nieznane opcja %s"
+
+#~ msgid "too many mount points for removable medium \"%s\""
+#~ msgstr "zbyt dużo punktów montowania dla wymiennego nośnika \"%s\""
+
+#~ msgid "taking removable device as \"%s\""
+#~ msgstr "traktowanie napędu wymiennego jako \"%s\""
+
+#~ msgid "Medium \"%s\" is an ISO image, will be mounted on-the-fly"
+#~ msgstr "Nośnik \"%s\" jest obrazem ISO. Zostanie zamontowany w locie"
+
+#~ msgid "using different removable device [%s] for \"%s\""
+#~ msgstr "używanie innego urządzenia wymiennego [%s] dla \"%s\""
+
+#~ msgid "unable to retrieve pathname for removable medium \"%s\""
+#~ msgstr "nie można pobrać ścieżki dla nośnika wymiennego \"%s\""
+
+#~ msgid "unable to mount the distribution medium"
+#~ msgstr "zamontowanie nośnika dystrybucji było niemożliwe"
+
+#~ msgid ""
+#~ "unable to access medium \"%s\",\n"
+#~ "this could happen if you mounted manually the directory when creating the "
+#~ "medium."
+#~ msgstr ""
+#~ "Nie można uzyskać dostępu do nośnika \"%s\",\n"
+#~ "To może się zdarzyć jeśli podczas tworzenia nośnika katalog został "
+#~ "zamontowany ręcznie."
+
+#~ msgid "inconsistent medium \"%s\" marked removable but not really"
+#~ msgstr "niespójny nośnik \"%s\" zaznaczony jako wymienny ale niekoniecznie"
+
+#~ msgid "Press Enter when ready..."
+#~ msgstr "Naciśnij enter jeśli jesteś gotowy(-a)..."
+
+#~ msgid " -c - clean headers cache directory.\n"
+#~ msgstr " -c - czyści katalog nagłówków pamięci podręcznej.\n"