diff options
author | Thierry Vignaud <tv@mandriva.org> | 2010-02-02 08:43:49 +0000 |
---|---|---|
committer | Thierry Vignaud <tv@mandriva.org> | 2010-02-02 08:43:49 +0000 |
commit | fa32ad8185c964121c0024290bcea09ab54edea4 (patch) | |
tree | b24d78481ee976d84cb6a28f63d5e08202d5aa4e | |
parent | 77ce41c13500604fc16e659eaaea04b0a8289570 (diff) | |
download | userdrake-fa32ad8185c964121c0024290bcea09ab54edea4.tar userdrake-fa32ad8185c964121c0024290bcea09ab54edea4.tar.gz userdrake-fa32ad8185c964121c0024290bcea09ab54edea4.tar.bz2 userdrake-fa32ad8185c964121c0024290bcea09ab54edea4.tar.xz userdrake-fa32ad8185c964121c0024290bcea09ab54edea4.zip |
(UserEdit_widget) split it out of Edit()
-rwxr-xr-x | userdrake | 200 |
1 files changed, 118 insertions, 82 deletions
@@ -881,11 +881,127 @@ sub GroupEdit_valid { } } +sub UserEdit_widget { + my ($nbU, $tree, $model, $Gent) = @_; + my ($vald, $mo, $ye) = (localtime())[3, 4, 5]; + my $valy = $ye+1900; + my $valm = $mo+1; + gtkappend_page($nbU, + BuildUui([ gtknew('Label_Left', text => N("Home:")), + $us->{o}{homedir} = Gtk2::Entry->new ]), + gtkshow(Gtk2::Label->new(N("User Data")))); + gtkappend_page( + $nbU, + gtkpack_(Gtk2::VBox->new(0, 2), + 0, $us->{o}{acheckexpire} = Gtk2::CheckButton->new(N("Enable account expiration")), + 0, gtkpack__(my $h = Gtk2::HBox->new(0, 10), + Gtk2::Label->new(N("Account expires (YYYY-MM-DD):")), + map { my ($s, $value, $minv, $maxv) = @$_; #my $spc = $_->[4]; + $us->{o}{$s} = Gtk2::SpinButton->new(Gtk2::Adjustment->new($value, $minv , $maxv, 1, 10, 10), 1, 0); + } (['expy', $valy, 1970, 10000], + ['expm', $valm, 1, 12], + ['expd', $vald, 1, 31]), + ), + 0, Gtk2::HSeparator->new, + 0, $us->{o}{lockuser} = Gtk2::CheckButton->new(N("Lock User Account")), + 0, Gtk2::HSeparator->new, + 0, GetFaceIcon(GetNameEntFromIter($usertree, $utree_model,0)) + ), gtkshow(Gtk2::Label->new(N("Account Info")))); + GrayBox($us->{o}{acheckexpire}, $h, 0); + gtkappend_page($nbU, + gtkpack_(Gtk2::VBox->new(0, 2), + 0, gtkpack_(Gtk2::HBox->new(0,5), + 0, Gtk2::Label->new(N("User last changed password on: ")), + 0, my $dayStr = Gtk2::Label->new(""), + 0, my $month = Gtk2::Label->new(""), + 0, my $dayInt = Gtk2::Label->new(""), + 0, my $year = Gtk2::Label->new("") + ), + 0, Gtk2::HSeparator->new, + 0, $us->{o}{pcheckexpire} = Gtk2::CheckButton->new(N("Enable Password Expiration")), + 1, gtkpack_( + my $v = Gtk2::VBox->new(0,1), + 1, create_packtable( + { homogeneous => 1, col_spacings => 5, row_spacings => 5 }, + [ N("Days before change allowed:"), + $us->{o}{dbca} = Gtk2::Entry->new_with_text(0) ], + [ N("Days before change required:"), + $us->{o}{dbcr} = Gtk2::Entry->new_with_text(0) ], + [ N("Days warning before change:"), + $us->{o}{bwbc} = Gtk2::Entry->new_with_text(0) ], + [ N("Days before account inactive:"), + $us->{o}{dbai} = Gtk2::Entry->new_with_text(0) ] + ) + )), gtkshow(Gtk2::Label->new(N("Password Info")))); + GrayBox($us->{o}{pcheckexpire}, $v, 0); + gtkappend_page($nbU, + gtkpack_(Gtk2::VBox->new(0, 2), + 0, Gtk2::Label->new(N("Select the groups that the user will be a member of:")), + 1, create_scrolled_window($tree), + 0, gtkpack_(Gtk2::HBox->new(0, 1), + 0, Gtk2::Label->new(N("Primary Group")), + 1, $us->{o}{primgroup} = Gtk2::OptionMenu->new, + ) + ), gtkshow(Gtk2::Label->new(N("Groups")))); + my $username = GetNameEntFromIter($usertree, $utree_model,0); + $us->{o}{login}->set_text($username); + my $userEnt = $ctx->LookupUserByName($username); FillUserInfo($userEnt); + my $Uid = $userEnt->Uid($GetValue); + my $expire = $userEnt->ShadowExpire($GetValue); + if ($expire && $expire != -1) { + $us->{o}{acheckexpire}->set_active(1); + $h->set_sensitive(1); + my $times = TimeOfArray($expire, 1); + $us->{o}{expd}->set_value($times->{dayint}); + $us->{o}{expm}->set_value($times->{month}); + $us->{o}{expy}->set_value($times->{year}); + } + #root account should never be locked + !$Uid and $us->{o}{lockuser}->set_sensitive(0); + # Check if user account is locked + $ctx->IsLocked($userEnt) and $us->{o}{lockuser}->set_active(1); + my $lastchg = $userEnt->ShadowLastChange($GetValue); + if ($lastchg) { + my $times = TimeOfArray($lastchg, 0); + $dayStr->set_text($times->{daystr}); + $month->set_text($times->{month}); + $dayInt->set_text($times->{dayint}); + $year->set_text($times->{year}); + } + my $min = $userEnt->ShadowMin($GetValue); + my $max = $userEnt->ShadowMax($GetValue); + my $warn = $userEnt->ShadowWarn($GetValue); + my $inact = $userEnt->ShadowInact($GetValue); + if ($min && $min != -1 || $max && $max != 99999 || $warn && $warn != 7 && $warn != -1 || $inact && $inact != -1) { + $us->{o}{pcheckexpire}->set_active(1); + $v->set_sensitive(1); + } + $min && $min != -1 and $us->{o}{dbca}->set_text($min); + $max && $max != -1 and $us->{o}{dbcr}->set_text($max); + $warn && $warn != -1 and $us->{o}{bwbc}->set_text($warn); + $inact && $inact != -1 and $us->{o}{dbai}->set_text($inact); + my $grps = $ctx->GroupsEnumerate; + my @sgroups = sort @$grps; + my $members = $ctx->EnumerateGroupsByUser($username); + my $primgid = $userEnt->Gid($GetValue); + $Gent = $ctx->LookupGroupById($primgid); + my @primgroup; + foreach my $group (@sgroups) { + if (member($group, @$members)) { + $model->append_set([ 0 => gtkcreate_pixbuf($pix[0]), 1 => $group, 2 => 1 ]); + push @primgroup, $group; + } else { $model->append_set([ 0 => gtkcreate_pixbuf($pix[1]), 1 => $group, 2 => 0 ]) } + } + $us->{o}{primgroup}->set_popdown_strings(@primgroup); + $Gent and $us->{o}{primgroup}->entry->set_text($Gent->GroupName($GetValue)); + ($userEnt, $primgid, @primgroup); +} + sub Edit() { my $w = NewWindow(N("Edit Groups / Users")); my $model = Gtk2::ListStore->new("Gtk2::Gdk::Pixbuf", "Glib::String", "Glib::Int"); my $tree = Gtk2::TreeView->new_with_model($model); - my ($groupname, $groupEnt, $userEnt, $times, $min, $max, $warn, $inact, $primgid, $Gent); + my ($groupname, $groupEnt, $userEnt, $primgid, $Gent); my @primgroup; $tree->get_selection->set_mode('browse'); $tree->append_column(my $check = Gtk2::TreeViewColumn->new_with_attributes(undef, Gtk2::CellRendererPixbuf->new, 'pixbuf' => 0)); @@ -895,87 +1011,7 @@ sub Edit() { my $p = $nb->get_current_page; my $nbU = Gtk2::Notebook->new; my $nbG = Gtk2::Notebook->new; if ($p <= 0) { - my ($vald, $mo, $ye) = (localtime())[3, 4, 5]; my $valy = $ye+1900; my $valm = $mo+1; - gtkappend_page($nbU, - BuildUui([ gtknew('Label_Left', text => N("Home:")), $us->{o}{homedir} = Gtk2::Entry->new ]), - gtkshow(Gtk2::Label->new(N("User Data")))); - gtkappend_page($nbU, - gtkpack_(Gtk2::VBox->new(0, 2), - 0, $us->{o}{acheckexpire} = Gtk2::CheckButton->new(N("Enable account expiration")), - 0, gtkpack__(my $h = Gtk2::HBox->new(0, 10), - Gtk2::Label->new(N("Account expires (YYYY-MM-DD):")), - map { my ($s, $value, $minv, $maxv) = @$_; #my $spc = $_->[4]; - $us->{o}{$s} = Gtk2::SpinButton->new(Gtk2::Adjustment->new($value, $minv , $maxv, 1, 10, 10), 1, 0); - } (['expy', $valy, 1970, 10000], ['expm', $valm, 1, 12], ['expd', $vald, 1, 31]), - ), - 0, Gtk2::HSeparator->new, - 0, $us->{o}{lockuser} = Gtk2::CheckButton->new(N("Lock User Account")), - 0, Gtk2::HSeparator->new, - 0, GetFaceIcon(GetNameEntFromIter($usertree, $utree_model,0)) - ), gtkshow(Gtk2::Label->new(N("Account Info")))); - GrayBox($us->{o}{acheckexpire}, $h, 0); - gtkappend_page($nbU, - gtkpack_(Gtk2::VBox->new(0, 2), - 0, gtkpack_(Gtk2::HBox->new(0,5), - 0, Gtk2::Label->new(N("User last changed password on: ")), - 0, my $dayStr = Gtk2::Label->new(""), 0, my $month = Gtk2::Label->new(""), 0, my $dayInt = Gtk2::Label->new(""), 0, my $year = Gtk2::Label->new("") - ), - 0, Gtk2::HSeparator->new, - 0, $us->{o}{pcheckexpire} = Gtk2::CheckButton->new(N("Enable Password Expiration")), - 1, gtkpack_(my $v = Gtk2::VBox->new(0,1), - 1, create_packtable({ homogeneous => 1, col_spacings => 5, row_spacings => 5 }, - [ N("Days before change allowed:"), $us->{o}{dbca} = Gtk2::Entry->new_with_text(0) ], - [ N("Days before change required:"), $us->{o}{dbcr} = Gtk2::Entry->new_with_text(0) ], - [ N("Days warning before change:"), $us->{o}{bwbc} = Gtk2::Entry->new_with_text(0) ], - [ N("Days before account inactive:"), $us->{o}{dbai} = Gtk2::Entry->new_with_text(0) ] - ) - )), gtkshow(Gtk2::Label->new(N("Password Info")))); - GrayBox($us->{o}{pcheckexpire}, $v, 0); - gtkappend_page($nbU, - gtkpack_(Gtk2::VBox->new(0, 2), - 0, Gtk2::Label->new(N("Select the groups that the user will be a member of:")), - 1, create_scrolled_window($tree), - 0, gtkpack_(Gtk2::HBox->new(0, 1), - 0, Gtk2::Label->new(N("Primary Group")), - 1, $us->{o}{primgroup} = Gtk2::OptionMenu->new, - ) - ), gtkshow(Gtk2::Label->new(N("Groups")))); - my $username = GetNameEntFromIter($usertree, $utree_model,0); $us->{o}{login}->set_text($username); - $userEnt = $ctx->LookupUserByName($username); FillUserInfo($userEnt); - my $Uid = $userEnt->Uid($GetValue); - my $expire = $userEnt->ShadowExpire($GetValue); - if ($expire && $expire != -1) { - $us->{o}{acheckexpire}->set_active(1); $h->set_sensitive(1); - $times = TimeOfArray($expire, 1); - $us->{o}{expd}->set_value($times->{dayint}); $us->{o}{expm}->set_value($times->{month}); - $us->{o}{expy}->set_value($times->{year}); - } - #root account should never be locked - !$Uid and $us->{o}{lockuser}->set_sensitive(0); - # Check if user account is locked - $ctx->IsLocked($userEnt) and $us->{o}{lockuser}->set_active(1); - my $lastchg = $userEnt->ShadowLastChange($GetValue); - if ($lastchg) { $times = TimeOfArray($lastchg, 0); - $dayStr->set_text($times->{daystr}); $month->set_text($times->{month}); $dayInt->set_text($times->{dayint}); $year->set_text($times->{year}); - } - $min = $userEnt->ShadowMin($GetValue); $max = $userEnt->ShadowMax($GetValue); $warn = $userEnt->ShadowWarn($GetValue); $inact = $userEnt->ShadowInact($GetValue); - if ($min && $min != -1 || $max && $max != 99999 || $warn && $warn != 7 && $warn != -1 || $inact && $inact != -1) { - $us->{o}{pcheckexpire}->set_active(1); $v->set_sensitive(1); - } - $min && $min != -1 and $us->{o}{dbca}->set_text($min); $max && $max != -1 and $us->{o}{dbcr}->set_text($max); - $warn && $warn != -1 and $us->{o}{bwbc}->set_text($warn); $inact && $inact != -1 and $us->{o}{dbai}->set_text($inact); - my $grps = $ctx->GroupsEnumerate; my @sgroups = sort(@$grps); - my $members = $ctx->EnumerateGroupsByUser($username); - $primgid = $userEnt->Gid($GetValue); - $Gent = $ctx->LookupGroupById($primgid); - foreach my $group (@sgroups) { - if (member($group, @$members)) { - $model->append_set([ 0 => gtkcreate_pixbuf($pix[0]), 1 => $group, 2 => 1 ]); push(@primgroup, $group); - } else { $model->append_set([ 0 => gtkcreate_pixbuf($pix[1]), 1 => $group, 2 => 0 ]) } - } - $us->{o}{primgroup}->set_popdown_strings(@primgroup); - $Gent and $us->{o}{primgroup}->entry->set_text($Gent->GroupName($GetValue)); - + ($userEnt, $primgid, @primgroup) = UserEdit_widget($nbU, $tree, $model, $Gent); } elsif ($p == 1) { $nbG->set_size_request(300, 200); gtkappend_page($nbG, gtkpack_(Gtk2::VBox->new(0, 2), 1, BuildGui()), gtkshow(Gtk2::Label->new(N("Group Data")))); |