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
|
package mgaapplet_gui;
################################################################################
# Mandriva Online #
# #
# Copyright (C) 2003-2010 Mandriva #
# #
# Daouda Lo #
# Thierry Vignaud <tvignaud at mandriva dot com> #
# #
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License Version 2 as #
# published by the Free Software Foundation. #
# #
# 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 feature 'state';
use lib qw(/usr/lib/libDrakX);
use common;
our @ISA = qw(Exporter);
our @EXPORT = qw(
@common
%local_config
$localdir
$localfile
$width
fill_n_run_portable_dialog
iso8601_date_to_locale
new_link_button
new_portable_dialog
setVar
);
our @EXPORT_OK = qw(
run_ask_credentials_dialog
run_no_rights_dialog
);
use mygtk3 qw(gtknew); #- do not import gtkadd which conflicts with ugtk2 version
use ugtk3 qw(:all);
use mgaonline qw(); # you don't want to polute the namespace
use interactive;
use interactive::gtk;
use lib qw(/usr/lib/libDrakX/drakfirsttime);
ugtk3::add_icon_path("/usr/share/mgaonline/pixmaps/");
our $localdir = "$ENV{HOME}/.MgaOnline";
our $localfile = "$localdir/mgaonline";
#compatibility
mkdir_p($localdir) if !-d $localdir;
-e "$ENV{HOME}/.mgaonline" and system("mv", "$ENV{HOME}/.mgaonline", $localfile);
interactive::gtk::add_padding(Gtk2::Label->new);
our %local_config;
read_local_config();
our $width = 500;
our @common = (
# explicitely wrap (for 2008.1):
line_wrap => 1,
# workaround infamous 6 years old gnome bug #101968:
width => $width - 50,
);
sub new_portable_dialog {
my ($title) = @_;
ugtk3->new($title, width => $width + 20);
}
sub fill_n_run_portable_dialog {
my ($w, $widgets) = @_;
# use wizard button order (for both 2008.1 & 2009.0):
{
local $::isWizard = 1;
local $w->{pop_it} = 0;
local $::isInstall = 1;
my %children;
if ($::isEmbedded) {
my (@children_tight, $child);
@children_tight = @$widgets;
$child = pop @children_tight;
%children = (
children => [
(map { (0, $_) } @children_tight),
1, gtknew('Label'),
0, $child,
]
);
} else {
%children = (children_tight => $widgets);
}
gtkadd($w->{window}, gtknew('VBox', %children));
}
$w->{ok}->grab_focus;
$w->main;
}
sub new_link_button {
my ($url, $text) = @_;
my $link = Gtk2::LinkButton->new($url, $text);
$link->set_uri_hook(sub {
my (undef, $url) = @_;
run_program::raw({ detach => 1, setuid => get_parent_uid() }, 'www-browser', $url);
});
$link;
}
sub read_local_config() {
%local_config = getVarsFromSh($localfile);
}
sub setVar {
my ($var, $st) = @_;
my %s = getVarsFromSh($localfile);
$s{$var} = $st;
setVarsInSh($localfile, \%s);
read_local_config();
}
sub iso8601_date_to_locale {
my ($date) = @_;
return $date if $date !~ /(\d\d\d\d)-?(\d\d)-?(\d\d)/;
require POSIX;
POSIX::strftime("%x", 0, 0, 0, $3, $2-1, $1-1900);
}
# %options keys:
#
# 'top_extra': reference to a list of widgets to shown on top of dialog.
#
sub run_ask_credentials_dialog {
my ($title, $description, $callback, %options) = @_;
my $w = new_portable_dialog($title);
my $password_text;
state $email_text;
my $password_w = gtknew('Entry');
my $email_w = gtknew('Entry', text => $email_text);
my $ok_clicked;
$password_w->set_visibility(0);
$w->{ok_clicked} = sub {
$password_text = $password_w->get_text;
$email_text = $email_w->get_text;
$ok_clicked = 1;
Gtk2->main_quit;
};
my @widgets = (
if_(!$::isEmbedded, mgaonline::get_banner($title)),
if_($options{top_extra},
@{ $options{top_extra} },
gtknew('HSeparator'),
),
gtknew('Label_Left',
text => $description,
@common),
gtknew('HButtonBox',
layout => 'start',
children_tight => [
interactive::gtk::add_padding(
new_link_button(
'http://www.mageia.org/', # FIXME: URL!
N("More information on your user account")
)
)
]),
gtknew('Table',
col_spacings => 5,
row_spacings => 5,
children => [ [ N("Your email"), $email_w ],
[ N("Your password"), $password_w ] ]),
gtknew('HButtonBox',
layout => 'start',
children_tight => [
interactive::gtk::add_padding(
new_link_button(
'http://www.mageia.org/', # FIXME: URL!
N("Forgotten password")
)
)
]),
ugtk3::create_okcancel($w, N("Next"), N("Cancel")),
);
fill_n_run_portable_dialog($w, \@widgets);
if ($ok_clicked) {
$ok_clicked = 0;
if ($email_text && $password_text) {
$callback->($email_text, $password_text);
}
else {
interactive->vnew->ask_warn(
N("Error"),
N("Password and email cannot be empty.")
);
goto &run_ask_credentials_dialog;
}
}
}
sub run_no_rights_dialog {
my ($title, $info, $info_url) = @_;
my $w = new_portable_dialog($title);
my @widgets = (
mgaonline::get_banner($title),
gtknew('Label_Left',
text => $info,
@mgaapplet_gui::common),
gtknew('HButtonBox',
layout => 'start',
children_tight => [
interactive::gtk::add_padding(
new_link_button($info_url, N("More Information"))
)
]),
create_okcancel($w, N("Close"), undef)
);
fill_n_run_portable_dialog($w, \@widgets);
}
|