aboutsummaryrefslogtreecommitdiffstats
path: root/userdrake
diff options
context:
space:
mode:
authorThierry Vignaud <tv@mandriva.org>2010-02-02 08:43:58 +0000
committerThierry Vignaud <tv@mandriva.org>2010-02-02 08:43:58 +0000
commit3af45b340a3b95cd4aa89925edd1b95910b32885 (patch)
treed4dd7050a820d3e4c6acadc0011c50bdebddbbbd /userdrake
parent028ee3a215820a792f1cb829c8dfce38d9665110 (diff)
downloaduserdrake-3af45b340a3b95cd4aa89925edd1b95910b32885.tar
userdrake-3af45b340a3b95cd4aa89925edd1b95910b32885.tar.gz
userdrake-3af45b340a3b95cd4aa89925edd1b95910b32885.tar.bz2
userdrake-3af45b340a3b95cd4aa89925edd1b95910b32885.tar.xz
userdrake-3af45b340a3b95cd4aa89925edd1b95910b32885.zip
more code reindentation for readability
Diffstat (limited to 'userdrake')
-rwxr-xr-xuserdrake421
1 files changed, 255 insertions, 166 deletions
diff --git a/userdrake b/userdrake
index a0760f7..28407d6 100755
--- a/userdrake
+++ b/userdrake
@@ -2,8 +2,8 @@
################################################################################
# #
# #
-# Copyright (C) 2003-2009 Mandriva #
-#
+# Copyright (C) 2003-2009 Mandriva #
+# #
# Daouda Lo #
# Thierry Vignaud <tvignaud@mandriva.com> #
# #
@@ -85,7 +85,8 @@ $::main_window = $us->{wnd}{real_window};
gtkset_size_request($us->{wnd}{rwindow}, 660, 460);
$us->{wnd}{rwindow}->set_position('center') if !$::isEmbedded;
$us->{wnd}{window}->signal_connect(delete_event => \&QuitGlobal);
-my $utree_model = Gtk2::ListStore->new("Glib::String", "Glib::Int", "Glib::String", "Glib::String", "Glib::String", "Glib::String", "Glib::String");
+my $utree_model = Gtk2::ListStore->new("Glib::String", "Glib::Int", "Glib::String",
+ "Glib::String", "Glib::String", "Glib::String", "Glib::String");
my $gtree_model = Gtk2::ListStore->new("Glib::String", "Glib::Int", "Glib::String");
my ($usertree, $grouptree);
$usertree = CreateTree($utree_model); $grouptree = CreateTree($gtree_model);
@@ -103,28 +104,36 @@ my %options = (
'filter' => [ N("/_Options"), N("/_Filter system users") ]
);
my %buttorcheck;
-my ($menu, $factory) = create_factory_menu($::isEmbedded ? $::Plug : $us->{wnd}{rwindow},
- ([ N("/_File"), undef, undef, undef, '<Branch>' ],
- [ N("/_File") . N("/_Refresh"), undef, sub { Refresh($sysfilter, $stringsearch) }, undef, '<Item>' ],
- [ N("/_File") . N("/_Quit"), N("<control>Q"), \&QuitGlobal, undef, '<Item>' ],
- [ N("/_Actions"), undef, undef, undef, '<Branch>' ],
- [ N("/_Actions") . N("/_Add User"), undef, \&AddUser, undef, '<Item>' ],
- [ N("/_Actions") . N("/Add _Group"), undef, \&AddGroup, undef, '<Item>' ],
- [ join('', @{$options{edit}}), undef, \&Edit, undef, '<Item>' ],
- [ join('', @{$options{delete}}), undef, \&Delete, undef, '<Item>' ],
- [ join('', @{$options{xguest}}), undef, \&Xguest, undef, '<Item>' ],
- [ N("/_Options"), undef, undef, undef, '<Branch>' ],
- [ join('', @{$options{filter}}), undef, sub {
- $sysfilter = $buttorcheck{filter}->get_active;
- Refresh($sysfilter, $stringsearch);
- }, undef, '<CheckItem>' ],
- [ N("/_Help"), undef, undef, undef, '<Branch>' ],
- [ N("/_Help") . N("/_Help"), undef, sub { HelpSystem() }, undef, '<Item>' ],
- [ N("/_Help") . N("/_Report Bug"), undef, sub { run_program::raw({ detach => 1 }, 'drakbug', '--report', 'userdrake') }, undef, '<Item>' ],
- [ N("/_Help") . N("/_About..."), undef, \&About, undef, '<Item>' ]
- )
- );
-%buttorcheck = map { $_ => $factory->get_widget("<main>" . join '', map { s/_//; $_ } @{$options{$_}}) }('edit', 'delete', 'filter', 'xguest');
+my ($menu, $factory) = create_factory_menu(
+ $::isEmbedded ? $::Plug : $us->{wnd}{rwindow},
+ ([ N("/_File"), undef, undef, undef, '<Branch>' ],
+ [ N("/_File") . N("/_Refresh"), undef,
+ sub { Refresh($sysfilter, $stringsearch) },
+ undef, '<Item>' ],
+ [ N("/_File") . N("/_Quit"), N("<control>Q"), \&QuitGlobal, undef, '<Item>' ],
+ [ N("/_Actions"), undef, undef, undef, '<Branch>' ],
+ [ N("/_Actions") . N("/_Add User"), undef, \&AddUser, undef, '<Item>' ],
+ [ N("/_Actions") . N("/Add _Group"), undef, \&AddGroup, undef, '<Item>' ],
+ [ join('', @{$options{edit}}), undef, \&Edit, undef, '<Item>' ],
+ [ join('', @{$options{delete}}), undef, \&Delete, undef, '<Item>' ],
+ [ join('', @{$options{xguest}}), undef, \&Xguest, undef, '<Item>' ],
+ [ N("/_Options"), undef, undef, undef, '<Branch>' ],
+ [ join('', @{$options{filter}}), undef, sub {
+ $sysfilter = $buttorcheck{filter}->get_active;
+ Refresh($sysfilter, $stringsearch);
+ }, undef, '<CheckItem>' ],
+ [ N("/_Help"), undef, undef, undef, '<Branch>' ],
+ [ N("/_Help") . N("/_Help"), undef, sub { HelpSystem() }, undef, '<Item>' ],
+ [ N("/_Help") . N("/_Report Bug"), undef,
+ sub { run_program::raw({ detach => 1 }, 'drakbug', '--report', 'userdrake') },
+ undef, '<Item>' ],
+ [ N("/_Help") . N("/_About..."), undef, \&About, undef, '<Item>' ]
+ )
+);
+%buttorcheck = map {
+ $_ => $factory->get_widget("<main>" . join '',
+ map { s/_//; $_ } @{$options{$_}}) }
+ ('edit', 'delete', 'filter', 'xguest');
if (defined $buttorcheck{filter}) {
$buttorcheck{filter}->set_active($sysfilter);
@@ -138,12 +147,19 @@ my $searchBox = gtkpack_(Gtk2::HBox->new(0,5),
1, Gtk2::Label->new(""),
0, Gtk2::Label->new(N("Search:")),
0, gtksignal_connect($filter = Gtk2::Entry->new,
- key_press_event => sub { $_[1]->keyval == $Gtk2::Gdk::Keysyms{Return} and Refresh($sysfilter, $filter->get_text) }),
+ key_press_event => sub {
+ $_[1]->keyval == $Gtk2::Gdk::Keysyms{Return}
+ and Refresh($sysfilter, $filter->get_text);
+ }),
0, my $fbut = Gtk2::Button->new(N("Apply filter")),
);
-gtkappend_page(my $nb = Gtk2::Notebook->new, gtkpack(create_scrolled_window($usertree)), gtkshow(Gtk2::Label->new(N("Users"))));
+gtkappend_page(my $nb = Gtk2::Notebook->new,
+ gtkpack(create_scrolled_window($usertree)),
+ gtkshow(Gtk2::Label->new(N("Users"))));
#PO: list of users belonging to that group
-gtkappend_page($nb, gtkpack(create_scrolled_window($grouptree)), gtkshow(Gtk2::Label->new(N("Groups"))));
+gtkappend_page($nb,
+ gtkpack(create_scrolled_window($grouptree)),
+ gtkshow(Gtk2::Label->new(N("Groups"))));
$nb->set_show_border(0);
my @extra_widgets;
if ($::isEmbedded) {
@@ -158,13 +174,17 @@ $us->{wnd}{window}->add(gtkpack_(Gtk2::VBox->new(0, 0),
0, $searchBox,
0, Gtk2::HSeparator->new,
1, $nb));
-my @ucolsize = (60, 45, 40, 120, 80, 120, 50, -1); my @gcolsize = (100, 80, 160, -1);
+my @ucolsize = (60, 45, 40, 120, 80, 120, 50, -1);
+my @gcolsize = (100, 80, 160, -1);
each_index {
- my $col = Gtk2::TreeViewColumn->new_with_attributes($_, Gtk2::CellRendererText->new, 'text' => $::i);
+ my $col = Gtk2::TreeViewColumn->new_with_attributes($_,
+ Gtk2::CellRendererText->new,
+ 'text' => $::i);
$col->set_sort_column_id($::i);
$col->set_min_width($ucolsize[$::i]);
$usertree->append_column($col);
-} (N("User Name"), N("User ID"), N("Primary Group"), N("Full Name"), N("Login Shell"), N("Home Directory"), N("Status"));
+} (N("User Name"), N("User ID"), N("Primary Group"),
+ N("Full Name"), N("Login Shell"), N("Home Directory"), N("Status"));
each_index {
my $col = Gtk2::TreeViewColumn->new_with_attributes($_, Gtk2::CellRendererText->new, 'text' => $::i);
@@ -177,8 +197,11 @@ foreach ([ N("Add User"), N("Add a user to the system"), 'user_add', \&AddUser ]
[ N("Add Group"), N("Add a group to the system"), 'group_add', \&AddGroup ],
[ N("Edit"), N("Edit selected row"), 'user_conf', \&Edit ],
[ N("Delete"), N("Delete selected row"), 'user_del', \&Delete ],
- [ N("Refresh"), N("Refresh the list"), 'refresh', sub { Refresh($sysfilter, $stringsearch) } ]) {
- my $t = $toolb->append_item($_->[0], $_->[1], $_->[2], Gtk2::Image->new_from_file($pixdir . $_->[2] . '.png'), $_->[3], $toolb);
+ [ N("Refresh"), N("Refresh the list"), 'refresh',
+ sub { Refresh($sysfilter, $stringsearch) } ]) {
+ my $t = $toolb->append_item($_->[0], $_->[1], $_->[2],
+ Gtk2::Image->new_from_file($pixdir . $_->[2] . '.png'),
+ $_->[3], $toolb);
push(@toolbwg, $t);
# $toolb->append_space;
}
@@ -188,7 +211,10 @@ GrayDelEdit();
RefreshXguest();
my $ctx = USER::ADMIN->new;
-$fbut->signal_connect('clicked', sub { $stringsearch = $filter->get_text; Refresh($sysfilter, $stringsearch) });
+$fbut->signal_connect('clicked', sub {
+ $stringsearch = $filter->get_text;
+ Refresh($sysfilter, $stringsearch);
+ });
Refresh($sysfilter, $stringsearch);
$nb->signal_connect('switch-page' => sub { NotebookSwitch() });
$us->{wnd}{rwindow}->show_all;
@@ -204,7 +230,9 @@ sub is_xguest_installed() {
}
sub GrayDelEdit() {
- foreach ($tbedit, $tbdel, $buttorcheck{edit}, $buttorcheck{delete}) { defined $_ and $_->set_sensitive(0) }
+ foreach ($tbedit, $tbdel, $buttorcheck{edit}, $buttorcheck{delete}) {
+ defined $_ and $_->set_sensitive(0);
+ }
}
sub RefreshXguest {
@@ -242,7 +270,10 @@ sub RefreshUsersFull {
defined $ctx and $users = $ctx->UsersEnumerateFull;
$utree_model->clear;
my @UserReal;
- LOOP: foreach my $l (@$users) { next LOOP if $filterusers && $l->Uid($GetValue) <= 499 || $l->Uid($GetValue) == 65534; push(@UserReal, $l) if $l->UserName($GetValue) =~ /^\Q$strfilt/ }
+ LOOP: foreach my $l (@$users) {
+ next LOOP if $filterusers && $l->Uid($GetValue) <= 499 || $l->Uid($GetValue) == 65534;
+ push @UserReal, $l if $l->UserName($GetValue) =~ /^\Q$strfilt/;
+ }
my $i;
foreach my $l (@UserReal) {
$i++;
@@ -251,11 +282,20 @@ sub RefreshUsersFull {
warn "bogus user at line $i\n";
next;
}
- my $a = $l->Gid($GetValue); $group = $ctx->LookupGroupById($a); $groupnm = ''; $expr = ComputeLockExpire($l);
+ my $a = $l->Gid($GetValue);
+ $group = $ctx->LookupGroupById($a);
+ $groupnm = '';
+ $expr = ComputeLockExpire($l);
$group and $groupnm = $group->GroupName($GetValue);
my $s = $l->Gecos($GetValue);
c::set_tagged_utf8($s);
- $utree_model->append_set([ 0 => $l->UserName($GetValue), 1 => $l->Uid($GetValue), 2 => $groupnm, 3 => $s, 4 => $l->LoginShell($GetValue), 5 => $l->HomeDir($GetValue), 6 => $expr ]);
+ $utree_model->append_set([ 0 => $l->UserName($GetValue),
+ 1 => $l->Uid($GetValue),
+ 2 => $groupnm,
+ 3 => $s,
+ 4 => $l->LoginShell($GetValue),
+ 5 => $l->HomeDir($GetValue),
+ 6 => $expr ]);
}
}
@@ -265,14 +305,19 @@ sub RefreshGroupsFull {
defined $ctx and $groups = $ctx->GroupsEnumerateFull;
$gtree_model->clear;
my @GroupReal;
- LOOP: foreach my $g (@$groups) { next LOOP if $filtergroups && $g->Gid($GetValue) <= 499 || $g->Gid($GetValue) == 65534; push(@GroupReal, $g) if $g->GroupName($GetValue) =~ /^\Q$strfilt/ }
+ LOOP: foreach my $g (@$groups) {
+ next LOOP if $filtergroups && $g->Gid($GetValue) <= 499 || $g->Gid($GetValue) == 65534;
+ push @GroupReal, $g if $g->GroupName($GetValue) =~ /^\Q$strfilt/;
+ }
foreach my $g (@GroupReal) {
my $a = $g->GroupName($GetValue);
#my $group = $ctx->LookupGroupById($a);
my $u_b_g = $a && $ctx->EnumerateUsersByGroup($a);
my $listUbyG = join(',', @$u_b_g);
my $group_id = $g->Gid($GetValue);
- $gtree_model->append_set([ 0 => $g->GroupName($GetValue), if_($group_id, 1 => $group_id), if_($listUbyG, 2 => $listUbyG) ]);
+ $gtree_model->append_set([ 0 => $g->GroupName($GetValue),
+ if_($group_id, 1 => $group_id),
+ if_($listUbyG, 2 => $listUbyG) ]);
}
}
@@ -355,84 +400,98 @@ sub AddUser() {
0, GetFaceIcon()
);
gtkadd($w->action_area,
- map {
- my $r = $_->[1];
- gtksignal_connect(Gtk2::Button->new($_->[0]), clicked => sub {
- if (!$r) {
- $u{username} = $us->{o}{login}->get_text; $error = 0;
- $u{gecos} = $us->{o}{fullname}->get_text;
- if (!valid_username($u{username})) { RaiseError($us->{error}) }
- my $nm = !$error && $ctx->LookupUserByName($u{username});
- if ($nm) { RaiseError(N("User already exists, please choose another User Name")); $us->{o}{login}->set_text('') }
- $u{passwd} = $us->{o}{passwd}->get_text;
- if ($u{passwd} ne $us->{o}{confpasswd}->get_text) { RaiseError(N("Password Mismatch")) }
- if ($sec{SECURE_LEVEL} > 3 && length($u{passwd}) < 6) { RaiseError(N("This password is too simple. \n Good passwords should be > 6 characters")) }
- my $userEnt = !$error && $ctx->InitUser($u{username}, $is_system);
- if (!$error && $us->{o}{createhomedir}->get_active) {
- $dontcreatehomedir = 0;
- $u{homedir} = $us->{o}{homedir}->get_text;
- $userEnt and $userEnt->HomeDir($u{homedir});
- } else {
- $dontcreatehomedir = 1;
- }
- if (!$error && $us->{o}{userid}->get_active) {
- if (($u{uid} = $us->{o}{uid}->get_value) < 500) {
- my $uidchoice = GimmeChoice(N("User Uid is < 500"), N("Creating a user with a UID less than 500 is not recommended.\n Are you sure you want to do this?\n\n"));
- $uidchoice and $userEnt->Uid($u{uid});
- } else { $userEnt->Uid($u{uid}) }
- }
- if ($us->{o}{privategroup}->get_active) {
- if (!$error) {
- #Check if group exist
- my $gr = $ctx->LookupGroupByName($u{username});
- if ($gr) {
- my $groupchoice = ChooseGroup();
- if ($groupchoice == 0 && !$error) {
- #You choose to put it in the existing group
- $u{gid} = $gr->Gid($GetValue);
- } elsif ($groupchoice == 1) {
- # Put it in 'users' group
- log::explanations(N("Putting %s to 'users' group", $u{username}));
- $u{gid} = Add2UsersGroup($u{username});
- }
- } else {
- #it's a new group: Add it
- my $newgroup = $ctx->InitGroup($u{username},$is_system);
- log::explanations(N("Creating new group: %s", $u{username}));
- $u{gid} = $newgroup->Gid($GetValue);
- $ctx->GroupAdd($newgroup);
- }
- }
- } else {
- !$error and $u{gid} = Add2UsersGroup($u{username});
- }
- if (!$error) {
- log::explanations(N("Adding user: %s", $u{username}));
- $u{loginshell} = $us->{o}{shells}->entry->get_text;
- $userEnt->Gecos($u{gecos}); $userEnt->LoginShell($u{loginshell}); $userEnt->Gid($u{gid});
- $userEnt->ShadowMin(-1); $userEnt->ShadowMax(99999);
- $userEnt->ShadowWarn(-1); $userEnt->ShadowInact(-1);
- $ctx->UserAdd($userEnt, $is_system, $dontcreatehomedir);
- $ctx->UserSetPass($userEnt, $u{passwd});
- defined $us->{o}{iconval} and any::addKdmIcon($u{username}, $us->{o}{iconval});
- Refresh($sysfilter, $stringsearch);
- transfugdrake::get_windows_disk()
- and $in->ask_yesorno(N("Migration wizard"),
- N("Do you want to run the migration wizard in order to import Windows documents and settings in your Mandriva Linux distribution?"))
- and run_program::raw({ detach => 1 }, 'transfugdrake');
- }
- }
- !$error and $w->destroy; $error = 0 });
- } ([ N("Cancel"), 1 ], [ N("Ok"), 0 ]),
- );
+ map {
+ my $r = $_->[1];
+ gtksignal_connect(
+ Gtk2::Button->new($_->[0]),
+ clicked => sub {
+ if (!$r) {
+ $u{username} = $us->{o}{login}->get_text; $error = 0;
+ $u{gecos} = $us->{o}{fullname}->get_text;
+ if (!valid_username($u{username})) { RaiseError($us->{error}) }
+ my $nm = !$error && $ctx->LookupUserByName($u{username});
+ if ($nm) {
+ RaiseError(N("User already exists, please choose another User Name"));
+ $us->{o}{login}->set_text('');
+ }
+ $u{passwd} = $us->{o}{passwd}->get_text;
+ if ($u{passwd} ne $us->{o}{confpasswd}->get_text) {
+ RaiseError(N("Password Mismatch"));
+ }
+ if ($sec{SECURE_LEVEL} > 3 && length($u{passwd}) < 6) {
+ RaiseError(N("This password is too simple. \n Good passwords should be > 6 characters"));
+ }
+ my $userEnt = !$error && $ctx->InitUser($u{username}, $is_system);
+ if (!$error && $us->{o}{createhomedir}->get_active) {
+ $dontcreatehomedir = 0;
+ $u{homedir} = $us->{o}{homedir}->get_text;
+ $userEnt and $userEnt->HomeDir($u{homedir});
+ } else {
+ $dontcreatehomedir = 1;
+ }
+ if (!$error && $us->{o}{userid}->get_active) {
+ if (($u{uid} = $us->{o}{uid}->get_value) < 500) {
+ my $uidchoice = GimmeChoice(N("User Uid is < 500"),
+ N("Creating a user with a UID less than 500 is not recommended.\n Are you sure you want to do this?\n\n"));
+ $uidchoice and $userEnt->Uid($u{uid});
+ } else { $userEnt->Uid($u{uid}) }
+ }
+ if ($us->{o}{privategroup}->get_active) {
+ if (!$error) {
+ #Check if group exist
+ my $gr = $ctx->LookupGroupByName($u{username});
+ if ($gr) {
+ my $groupchoice = ChooseGroup();
+ if ($groupchoice == 0 && !$error) {
+ #You choose to put it in the existing group
+ $u{gid} = $gr->Gid($GetValue);
+ } elsif ($groupchoice == 1) {
+ # Put it in 'users' group
+ log::explanations(N("Putting %s to 'users' group",
+ $u{username}));
+ $u{gid} = Add2UsersGroup($u{username});
+ }
+ } else {
+ #it's a new group: Add it
+ my $newgroup = $ctx->InitGroup($u{username},$is_system);
+ log::explanations(N("Creating new group: %s", $u{username}));
+ $u{gid} = $newgroup->Gid($GetValue);
+ $ctx->GroupAdd($newgroup);
+ }
+ }
+ } else {
+ !$error and $u{gid} = Add2UsersGroup($u{username});
+ }
+ if (!$error) {
+ log::explanations(N("Adding user: %s", $u{username}));
+ $u{loginshell} = $us->{o}{shells}->entry->get_text;
+ $userEnt->Gecos($u{gecos}); $userEnt->LoginShell($u{loginshell});
+ $userEnt->Gid($u{gid});
+ $userEnt->ShadowMin(-1); $userEnt->ShadowMax(99999);
+ $userEnt->ShadowWarn(-1); $userEnt->ShadowInact(-1);
+ $ctx->UserAdd($userEnt, $is_system, $dontcreatehomedir);
+ $ctx->UserSetPass($userEnt, $u{passwd});
+ defined $us->{o}{iconval} and
+ any::addKdmIcon($u{username}, $us->{o}{iconval});
+ Refresh($sysfilter, $stringsearch);
+ transfugdrake::get_windows_disk()
+ and $in->ask_yesorno(N("Migration wizard"),
+ N("Do you want to run the migration wizard in order to import Windows documents and settings in your Mandriva Linux distribution?"))
+ and run_program::raw({ detach => 1 }, 'transfugdrake');
+ }
+ }
+ !$error and $w->destroy; $error = 0 });
+ } ([ N("Cancel"), 1 ], [ N("Ok"), 0 ]),
+ );
foreach (qw(privategroup createhomedir)) { $us->{o}{$_}->set_active(1) }
GrayBox($us->{o}{createhomedir}, $vv, 1);
- $us->{o}{login}->signal_connect('focus_out_event' => sub {
- my $fullname = $us->{o}{fullname}->get_text;
- $us->{o}{homedir}->set_text("/home/" . $us->{o}{login}->get_text);
- $fullname or $us->{o}{fullname}->set_text($us->{o}{login}->get_text);
- 0; # Gdk expect focus event handlers to return false
- });
+ $us->{o}{login}->signal_connect(
+ 'focus_out_event' => sub {
+ my $fullname = $us->{o}{fullname}->get_text;
+ $us->{o}{homedir}->set_text("/home/" . $us->{o}{login}->get_text);
+ $fullname or $us->{o}{fullname}->set_text($us->{o}{login}->get_text);
+ 0; # Gdk expect focus event handlers to return false
+ });
$us->{o}{uid} = Gtk2::SpinButton->new(Gtk2::Adjustment->new(500, 1, 65000, 1, 10, 10), 1, 0);
$h->pack_end($us->{o}{uid}, 0, 0, 4);
$h->pack_end(Gtk2::Label->new(N("UID: ")), 0, 0, 4);
@@ -450,18 +509,28 @@ sub Add2UsersGroup {
sub ChooseGroup() {
my $w = NewWindow(N("Choose group"));
my $choice;
- my @radio = gtkradio(N("Add to the existing group"), (N("Add to the existing group"), N("Add to the 'users' group")));
+ my @radio = gtkradio(N("Add to the existing group"),
+ (N("Add to the existing group"),
+ N("Add to the 'users' group")));
gtkadd($w->vbox,
- Gtk2::Label->new(N("A group with this name already exists. What would you like to do?")),
- gtkpack(Gtk2::VBox->new(0,0), @radio),
- );
+ Gtk2::Label->new(N("A group with this name already exists. What would you like to do?")),
+ gtkpack(Gtk2::VBox->new(0,0), @radio),
+ );
gtkadd($w->action_area,
- gtksignal_connect(Gtk2::Button->new(N("Ok")), clicked => sub {
- each_index { $_->get_active and $choice = $::i } @radio;
- $w->destroy;
- Gtk2->main_quit;
- }),
- gtksignal_connect(Gtk2::Button->new(N("Cancel")), clicked => sub { $error = 1; $w->destroy; Gtk2->main_quit }));
+ gtksignal_connect(
+ Gtk2::Button->new(N("Ok")),
+ clicked => sub {
+ each_index { $_->get_active and $choice = $::i } @radio;
+ $w->destroy;
+ Gtk2->main_quit;
+ }),
+ gtksignal_connect(
+ Gtk2::Button->new(N("Cancel")),
+ clicked => sub {
+ $error = 1;
+ $w->destroy;
+ Gtk2->main_quit;
+ }));
$w->show_all;
Gtk2->main;
$choice;
@@ -483,30 +552,40 @@ sub AddGroup() {
0, gtkset_sensitive(my $h = Gtk2::HBox->new(0, 4), 0),
);
gtkadd($w->action_area,
- map {
- my $r = $_->[1];
- gtksignal_connect(Gtk2::Button->new($_->[0]), clicked => sub {
- if (!$r) {
- $g{groupname} = $us->{o}{groupname}->get_text; $error = 0;
- if (!valid_groupname($g{groupname})) { RaiseError($us->{error}) }
- my $nm = $ctx->LookupGroupByName($g{groupname});
- if ($nm) { RaiseError(N("Group already exists, please choose another Group Name")); $us->{o}{groupname}->set_text('') }
- my $groupEnt = $ctx->InitGroup($g{groupname}, $is_system);
- if ($us->{o}{groupid}->get_active) {
- if (($g{gid} = $us->{o}{gid}->get_value) < 500) {
- my $gidchoice = GimmeChoice(N(" Group Gid is < 500"), N("Creating a group with a GID less than 500 is not recommended.\n Are you sure you want to do this?\n\n"));
- $gidchoice and $groupEnt->Gid($g{gid});
- } else { $groupEnt->Gid($g{gid}) }
- }
- if (!$error) {
- log::explanations(N("Adding group: %s ", $g{groupname}));
- $ctx->GroupAdd($groupEnt);
- Refresh($sysfilter, $stringsearch);
- }
- }
- !$error and $w->destroy; $error = 0 });
- } ([ N("Cancel"), 1 ], [ N("Ok"), 0 ])
- );
+ map {
+ my $r = $_->[1];
+ gtksignal_connect(
+ Gtk2::Button->new($_->[0]),
+ clicked => sub {
+ if (!$r) {
+ $g{groupname} = $us->{o}{groupname}->get_text; $error = 0;
+ if (!valid_groupname($g{groupname})) {
+ RaiseError($us->{error});
+ }
+ my $nm = $ctx->LookupGroupByName($g{groupname});
+ if ($nm) {
+ RaiseError(N("Group already exists, please choose another Group Name"));
+ $us->{o}{groupname}->set_text('');
+ }
+ my $groupEnt = $ctx->InitGroup($g{groupname}, $is_system);
+ if ($us->{o}{groupid}->get_active) {
+ if (($g{gid} = $us->{o}{gid}->get_value) < 500) {
+ my $gidchoice = GimmeChoice(N(" Group Gid is < 500"),
+ N("Creating a group with a GID less than 500 is not recommended.\n Are you sure you want to do this?\n\n"));
+ $gidchoice and $groupEnt->Gid($g{gid});
+ } else {
+ $groupEnt->Gid($g{gid});
+ }
+ }
+ if (!$error) {
+ log::explanations(N("Adding group: %s ", $g{groupname}));
+ $ctx->GroupAdd($groupEnt);
+ Refresh($sysfilter, $stringsearch);
+ }
+ }
+ !$error and $w->destroy; $error = 0 });
+ } ([ N("Cancel"), 1 ], [ N("Ok"), 0 ])
+ );
$us->{o}{gid} = Gtk2::SpinButton->new(Gtk2::Adjustment->new(500, 1, 65000, 1, 10, 10), 1, 0);
$h->pack_end($us->{o}{gid}, 0, 0, 4);
$h->pack_end(Gtk2::Label->new(N("GID: ")), 0, 0, 4);
@@ -557,9 +636,11 @@ sub UserDelete() {
my $w = NewWindow(N("Delete files or not?"));
my $hd = $userEnt->HomeDir($GetValue);
gtkpack_($w->vbox,
- 0, Gtk2::Label->new(N("Deleting user %s\n Also perform the following actions\n", $username)),
+ 0, Gtk2::Label->new(N("Deleting user %s\n Also perform the following actions\n",
+ $username)),
0, $checkhome = Gtk2::CheckButton->new(N("Delete Home Directory: %s", $hd)),
- 0, $checkspool = Gtk2::CheckButton->new(N("Delete Mailbox: /var/spool/mail/%s", $username)),
+ 0, $checkspool = Gtk2::CheckButton->new(N("Delete Mailbox: /var/spool/mail/%s",
+ $username)),
);
gtkadd($w->action_area,
map {
@@ -744,8 +825,9 @@ sub BuildGui() {
sub NewWindow {
my ($title) = @_;
- my $dialog = gtkset_border_width(_create_dialog($title, { transient_for => $us->{wnd}{real_window} }),
- 5);
+ my $dialog = gtkset_border_width(
+ _create_dialog($title, { transient_for => $us->{wnd}{real_window} }),
+ 5);
$dialog->signal_connect(delete_event => sub { $dialog->destroy });
my $prev_main_window = $::main_window;
$::main_window = $dialog;
@@ -1148,7 +1230,10 @@ sub TimeOfArray {
my ($reltime, $cm) = @_;
my $h; my %mth = (Jan => 1, Feb => 2, Mar => 3, Apr => 4, May => 5, Jun => 6, Jul => 7, Aug => 8, Sep => 9, Oct => 10, Nov => 11, Dec => 12);
my $_t = localtime($reltime * 24 * 60 * 60) =~ /(\S+)\s+(\S+)\s+(\d+)\s+(\S+)\s+(\d+)/;
- $h->{daystr} = $1; $h->{month} = $2; $h->{dayint} = $3; $h->{year} = $5;
+ $h->{daystr} = $1;
+ $h->{month} = $2;
+ $h->{dayint} = $3;
+ $h->{year} = $5;
$cm and $h->{month} = $mth{$2};
$h;
}
@@ -1172,10 +1257,12 @@ sub GrayBox {
sub NewDialog {
my ($title) = @_;
- my $dialog = gtkset_border_width(_create_dialog($title, { transient_for => $us->{wnd}{real_window} }),
- 5);
- $dialog->action_area->pack_start(gtksignal_connect(Gtk2::Button->new(N("Close")), clicked => sub { $dialog->destroy }),
- 0,0,0);
+ my $dialog = gtkset_border_width(
+ _create_dialog($title, { transient_for => $us->{wnd}{real_window} }),
+ 5);
+ $dialog->action_area->pack_start(
+ gtksignal_connect(Gtk2::Button->new(N("Close")), clicked => sub { $dialog->destroy }),
+ 0,0,0);
$dialog;
}
@@ -1203,27 +1290,29 @@ Thierry Vignaud <tvignaud@mandriva.com>',
sub valid {
$_[0] or $us->{error} = N("Name field is empty please provide a name"), return 0;
- $_[0] =~ /^[a-z]+?[a-z0-9_-]*?$/ or $us->{error} = N("The name must contain only lower cased latin letters, numbers, `-' and `_'"), return 0;
+ $_[0] =~ /^[a-z]+?[a-z0-9_-]*?$/ or do {
+ $us->{error} = N("The name must contain only lower cased latin letters, numbers, `-' and `_'");
+ return 0;
+ };
length($_[0]) <= $_[1] or $us->{error} = N("Name is too long"), return 0;
return 1;
}
sub valid_username {
- return valid($_[0], 32);
+ return valid($_[0], 32);
}
sub valid_groupname {
- return valid($_[0], 16);
+ return valid($_[0], 16);
}
sub RaiseError {
my $w = NewWindow(N("Error"));
$error = 1;
- gtkpack($w->vbox,
- Gtk2::Label->new($_[0]),
- );
+ gtkpack($w->vbox, Gtk2::Label->new($_[0]));
gtkadd($w->action_area,
- gtksignal_connect(Gtk2::Button->new(N("Ok")), clicked => sub { $w->destroy })
+ gtksignal_connect(Gtk2::Button->new(N("Ok")),
+ clicked => sub { $w->destroy })
);
$w->show_all;
}