CPANPLUS-Shell-Wx
view release on metacpan or search on metacpan
lib/CPANPLUS/Shell/Wx/ModuleTree.pm view on Meta::CPAN
$self->{statusBar}->SetStatusText(_T('Preparing ').$mod->name);
my $path=$mod->prepare();
return 0 unless $path;
_uShowErr;
return 1;
}
sub _create_module{
my $self=shift;
my $mod=shift || $self->{thisMod};
$mod = $self->{cpan}->parse_module(module=>$mod) unless ($mod->isa('CPANPLUS::Module') || $mod->isa('CPANPLUS::Module::Fake'));
return unless $mod;
$self->{statusBar}->SetStatusText(_T('Building ').$mod->name);
my $path=$mod->create();
return 0 unless $path;
_uShowErr;
return 1;
}
sub _test_module{
my $self=shift;
my $mod=shift || $self->{thisMod};
$mod = $self->{cpan}->parse_module(module=>$mod) unless ($mod->isa('CPANPLUS::Module') || $mod->isa('CPANPLUS::Module::Fake'));
return unless $mod;
$self->{statusBar}->SetStatusText(_T('Testing ').$mod->name);
my $path=$mod->test();
return 0 unless $path;
_uShowErr;
return 1;
}
#populates the list with the tree items
#This function takes a tree hash, and optionally a progressdialog or bar
# and the max value of the progress bar
#return 1 on success, or 0 if the user cancelled
# call like:
#$user_has_cancelled = $self->PopulateWithHash(\%tree,[$progress],[$max_pval]);
sub PopulateWithHash{
#get parameters
my $self=shift;
my $tree=shift;
my $progress=shift;
my $max_progress=shift;
#print "Window Height: ".$self->GetClientSize()->GetWidth." , ".$self->GetClientSize()->GetHeight."\n";
#set defaults.
#Use half the number of items in the hash as a total items count, if none given
my $numFound=$tree->{'_items_in_tree_'} || %$tree/2;
$max_progress=($numFound || 10000) unless $max_progress;
#create a progressdialog if none specified in params
$progress=Wx::ProgressDialog->new(_T("Setting Up List..."),
_T("Inserting ").$numFound._T(" Items Into Tree..."),
$numFound,$self,wxPD_APP_MODAL|wxPD_CAN_ABORT|wxPD_ESTIMATED_TIME|wxPD_REMAINING_TIME
) unless $progress;
#start timing
$begin=time();
#restart count if another progressdialog is passeed in
$progress->Update(0,_T("Inserting ").$numFound._T(" Items Into Tree..."));
my $percent=$max_progress/$numFound;
$cnt=0;
foreach $top_level ( sort( keys(%$tree) ) ){
next if $top_level eq '_items_in_tree_';
my $display=$top_level;
my $curParent=$self->AppendItem(
$self->GetRootItem(),
$top_level,$self->_get_status_icon($top_level));
foreach $item (sort(@{$tree->{$top_level}})){
$self->AppendItem($curParent,$top_level."::".$item,$self->_get_status_icon($item)) if ($curParent && $item);
last unless $progress->Update($cnt*$percent);
$cnt++;
}
}
# my $dummy=$self->AppendItem($self->GetRootItem(),'end');
# my $subDummy=$self->AppendItem($dummy,'end');
# $progress->Update($numFound+1);
$progress->Destroy();
my $inserted_time=time()-$begin;
Wx::LogMessage _T("Finished Inserting in ").sprintf("%d",($inserted_time/60)).":".($inserted_time % 60)."\n";
# print "Window Height: ".$self->GetClientSize()->GetWidth." , ".$self->GetClientSize()->GetHeight."\n";
_uShowErr;
return 1;
}
###############################
######## New By Name ##########
###############################
sub _show_new_by_name{
my $self=shift;
if ($self->{'tree_NewByName'}){
return 0 unless $self->PopulateWithHash($self->{'tree_NewByName'});
Wx::LogMessage _T("[Done]");
return 1;
}
my %tree=();
my $max_pval=10000; #the maximum value of the progress bar
my $progress=Wx::ProgressDialog->new(_T("Setting Up List..."),
_T("CPANPLUS is getting information..."),
$max_pval,
$self,
wxPD_APP_MODAL|wxPD_CAN_ABORT|wxPD_ESTIMATED_TIME|wxPD_REMAINING_TIME);
my %allMods=%{$self->{cpan}->module_tree()}; #get all modules
my $total=keys(%allMods);
my $percent=$max_pval/($total||1); #number to increment progress by
my $begin=time(); #for timing loops
my $cnt=0; #the count of current index of @allMods - for progressbar
my $numFound=0;
$progress->Update(0,_T("Step 1 of 2: Sorting All ").$total._T(" Modules...")); #start actual progress
#search through installed modules and insert them into the correct category
foreach $thisName (keys(%allMods)){
my $i=$allMods{$thisName};
if (!($i->is_uptodate || $i->installed_version)){
my ($top_level)=split('::',$thisName);
push (@{$tree{$top_level}}, ($thisName eq $top_level)?():$thisName); #add the item to the tree
$numFound++;
}
unless ($progress->Update($cnt*$percent)){
$progress->Destroy();
return 0;
}
$cnt++; #increment current index in @installed
}
#end timing method
my $end=time();
Wx::LogMessage _T("Finished Sorting in ").sprintf("%d",(($end-$begin)/60)).":".(($end-$begin) % 60)."\n";
#store tree for later use
$tree{'_items_in_tree_'}=$numFound;
$self->{'tree_NewByName'}=\%tree;
#populate the TreeCtrl
return 0 unless $self->PopulateWithHash(\%tree,$progress,$max_pval);
Wx::LogMessage _T("[Done]");
_uShowErr;
return 1;
}
###############################
######## New By Author ########
###############################
sub _show_new_by_author{
my $self=shift;
if ($self->{'tree_NewByAuthor'}){
return 0 unless $self->PopulateWithHash($self->{'tree_NewByAuthor'});
Wx::LogMessage _T("[Done]");
return 1;
}
my %tree=();
my $max_pval=10000; #the maximum value of the progress bar
my $progress=Wx::ProgressDialog->new(_T("Setting Up List..."),
_T("CPANPLUS is getting information..."),
$max_pval,
$self,
wxPD_APP_MODAL|wxPD_CAN_ABORT|wxPD_ESTIMATED_TIME|wxPD_REMAINING_TIME);
my %allMods=%{$self->{cpan}->module_tree()}; #get all modules
my $total=keys(%allMods);
my $percent=$max_pval/($total||1); #number to increment progress by
my $begin=time(); #for timing loops
my $cnt=0; #the count of current index of @allMods - for progressbar
$numFound=0;
$progress->Update(0,_T("Step 1 of 2: Categorizing All ").$total._T(" Modules...")); #start actual progress
#search through installed modules and insert them into the correct category
foreach $thisName (keys(%allMods)){
my $i=$allMods{$thisName};
if (!($i->is_uptodate || $i->installed_version)){
my $thisAuthor=$i->author()->cpanid." [".$i->author()->author."]";
my $cat_num=$self->{category_list}->{$thisName};
push (@{$tree{$thisAuthor}}, $thisName); #add the item to the tree
$numFound++;
}
unless ($progress->Update($cnt*$percent)){
$progress->Destroy();
return 0;
}
$cnt++; #increment current index in @installed
}
#end timing method
my $end=time();
Wx::LogMessage _T("Finished Sorting in ").sprintf("%d",(($end-$begin)/60)).":".(($end-$begin) % 60)."\n";
#store tree for later use
$tree{'_items_in_tree_'}=$numFound;
$self->{'tree_NewByAuthor'}=\%tree;
#populate the TreeCtrl
return 0 unless $self->PopulateWithHash(\%tree,$progress,$max_pval);
Wx::LogMessage _T("[Done]");
_uShowErr;
return 1;
}
###############################
######## New By Category ######
###############################
sub _show_new_by_category{
my $self=shift;
if ($self->{'tree_NewByCategory'}){
return 0 unless $self->PopulateWithHash($self->{'tree_NewByCategory'});
Wx::LogMessage _T("[Done]");
return 1;
}
my $max_pval=10000; #the maximum value of the progress bar
my $progress=Wx::ProgressDialog->new(_T("Setting Up List..."),
_T("CPANPLUS is getting information..."),$max_pval,$self,
wxPD_APP_MODAL|wxPD_CAN_ABORT|wxPD_ESTIMATED_TIME|wxPD_REMAINING_TIME);
my %allMods=%{$self->{cpan}->module_tree()}; #get all modules
my $total=keys(%allMods);
my $percent=$max_pval/($total||1); #number to increment progress by
my $begin=time(); #for timing loops
my $cnt=0; #the count of current index of @allMods - for progressbar
$numFound=0;
$progress->Update(0,_T("Step 1 of 2: Categorizing All ").$total.(" Modules...")); #start actual progress
#search through installed modules and insert them into the correct category
foreach $thisName (keys(%allMods)){
my $i=$allMods{$thisName};
my $cat_num=$self->{category_list}->{$thisName};
if (defined($cat_num) && !($i->is_uptodate || $i->installed_version)){
$cat_num=0 if ($cat_num==99); #don't use index 99, it make array too large
$cat_num=1 if ($i->module_is_supplied_with_perl_core() && $cat_num==2);
push (@{$tree{$self->{catNames}->[$cat_num]}}, $thisName); #add the item to the tree
$numFound++;
}
unless ($progress->Update($cnt*$percent)){
$progress->Destroy();
return 0;
}
$cnt++; #increment current index in @installed
}
#end timing method
my $end=time();
Wx::LogMessage _T("Finished Sorting in ").sprintf("%d",(($end-$begin)/60)).":".(($end-$begin) % 60)."\n";
#store tree for later use
$tree{'_items_in_tree_'}=$numFound;
$self->{'tree_NewByCategory'}=\%tree;
#populate the TreeCtrl
return 0 unless $self->PopulateWithHash(\%tree,$progress,$max_pval);
Wx::LogMessage _T("[Done]");
_uShowErr;
return 1;
}
###############################
######## All By Name ##########
###############################
sub _show_all_by_name{
my $self=shift;
if ($self->{'tree_AllByName'}){
return 0 unless $self->PopulateWithHash($self->{'tree_AllByName'});
Wx::LogMessage _T("[Done]");
return 1;
}
my %tree=();
my $max_pval=10000; #the maximum value of the progress bar
my $progress=Wx::ProgressDialog->new(_T("Setting Up List..."),
_T("CPANPLUS is getting information..."),
$max_pval,
$self,
wxPD_APP_MODAL|wxPD_CAN_ABORT|wxPD_ESTIMATED_TIME|wxPD_REMAINING_TIME);
my %allMods=%{$self->{cpan}->module_tree()}; #get all modules
my $total=keys(%allMods);
my $percent=$max_pval/($total||1); #number to increment progress by
my $begin=time(); #for timing loops
my $cnt=0; #the count of current index of @allMods - for progressbar
$progress->Update(0,_T("Step 1 of 2: Sorting All ").$total._T(" Modules...")); #start actual progress
#search through installed modules and insert them into the correct category
foreach $thisName (keys(%allMods)){
my $i=$allMods{$thisName};
my ($top_level)=split('::',$thisName);
push (@{$tree{$top_level}}, ($thisName eq $top_level)?():$thisName); #add the item to the tree
unless ($progress->Update($cnt*$percent)){
$progress->Destroy();
return 0;
}
$cnt++; #increment current index in @installed
}
#end timing method
my $end=time();
Wx::LogMessage _T("Finished Sorting in ").sprintf("%d",(($end-$begin)/60)).":".(($end-$begin) % 60)."\n";
#store tree for later use
$tree{'_items_in_tree_'}=$total;
$self->{'tree_AllByName'}=\%tree;
#populate the TreeCtrl
return 0 unless $self->PopulateWithHash(\%tree,$progress,$max_pval);
Wx::LogMessage _T("[Done]");
_uShowErr;
return 1;
}
###############################
######## All By Author ########
###############################
sub _show_all_by_author{
my $self=shift;
if ($self->{'tree_AllByAuthor'}){
return 0 unless $self->PopulateWithHash($self->{'tree_AllByAuthor'});
Wx::LogMessage _T("[Done]");
return 1;
}
my %tree=();
my $max_pval=10000; #the maximum value of the progress bar
my $progress=Wx::ProgressDialog->new(_T("Setting Up List..."),
_T("CPANPLUS is getting information..."),
$max_pval,
$self,
wxPD_APP_MODAL|wxPD_CAN_ABORT|wxPD_ESTIMATED_TIME|wxPD_REMAINING_TIME);
my %allMods=%{$self->{cpan}->module_tree()}; #get all modules
my $total=keys(%allMods);
my $percent=$max_pval/($total||1); #number to increment progress by
my $begin=time(); #for timing loops
my $cnt=0; #the count of current index of @allMods - for progressbar
$progress->Update(0,_T("Step 1 of 2: Categorizing All ").$total._T(" Modules...")); #start actual progress
#search through installed modules and insert them into the correct category
foreach $thisName (keys(%allMods)){
my $i=$allMods{$thisName};
my $thisAuthor=$i->author()->cpanid." [".$i->author()->author."]";
my $cat_num=$self->{category_list}->{$thisName};
push (@{$tree{$thisAuthor}}, $thisName); #add the item to the tree
unless ($progress->Update($cnt*$percent)){
$progress->Destroy();
return 0;
}
$cnt++; #increment current index in @installed
}
#end timing method
my $end=time();
Wx::LogMessage _T("Finished Sorting in ").sprintf("%d",(($end-$begin)/60)).":".(($end-$begin) % 60)."\n";
#store tree for later use
$tree{'_items_in_tree_'}=$total;
$self->{'tree_AllByAuthor'}=\%tree;
#populate the TreeCtrl
return 0 unless $self->PopulateWithHash(\%tree,$progress,$max_pval);
Wx::LogMessage _T("[Done]");
_uShowErr;
return 1;
}
###############################
###### All By Category ########
###############################
sub _show_all_by_category{
my $self=shift;
if ($self->{'tree_AllByCategory'}){
return 0 unless $self->PopulateWithHash($self->{'tree_AllByCategory'});
Wx::LogMessage _T("[Done]");
return 1;
}
my $max_pval=10000; #the maximum value of the progress bar
my $progress=Wx::ProgressDialog->new(_T("Setting Up List..."),
_T("CPANPLUS is getting information..."),$max_pval,$self,
wxPD_APP_MODAL|wxPD_CAN_ABORT|wxPD_ESTIMATED_TIME|wxPD_REMAINING_TIME);
my %allMods=%{$self->{cpan}->module_tree()}; #get all modules
my $total=keys(%allMods);
my $percent=$max_pval/($total||1); #number to increment progress by
my $begin=time(); #for timing loops
my $cnt=0; #the count of current index of @allMods - for progressbar
$progress->Update(0,_T("Step 1 of 2: Categorizing All ").$total._T(" Modules...")); #start actual progress
#search through installed modules and insert them into the correct category
foreach $thisName (keys(%allMods)){
my $i=$allMods{$thisName};
my $cat_num=$self->{category_list}->{$thisName};
if (defined($cat_num)){
$cat_num=0 if ($cat_num==99); #don't use index 99, it make array too large
$cat_num=1 if ($i->module_is_supplied_with_perl_core() && $cat_num==2);
push (@{$tree{$self->{catNames}->[$cat_num]}}, $thisName); #add the item to the tree
}
unless ($progress->Update($cnt*$percent)){
$progress->Destroy();
return 0;
}
$cnt++; #increment current index in @installed
}
#end timing method
my $end=time();
Wx::LogMessage _T("Finished Sorting in ").sprintf("%d",(($end-$begin)/60)).":".(($end-$begin) % 60)."\n";
#store tree for later use
$tree{'_items_in_tree_'}=$total;
$self->{'tree_AllByCategory'}=\%tree;
#populate the TreeCtrl
return 0 unless $self->PopulateWithHash(\%tree,$progress,$max_pval);
Wx::LogMessage _T("[Done]");
$progress->Destroy();
_uShowErr;
return 1;
}
sub _show_updates_by_category{
my $self=shift;
if ($self->{'tree_UpdatesByCategory'}){
return 0 unless $self->PopulateWithHash($self->{'tree_UpdatesByCategory'});
Wx::LogMessage _T("[Done]");
return 1;
}
my $max_pval=10000; #the maximum value of the progress bar
my $progress=Wx::ProgressDialog->new(_T("Setting Up List..."),
_T("CPANPLUS is getting information..."),$max_pval,$self,
wxPD_APP_MODAL|wxPD_CAN_ABORT|wxPD_ESTIMATED_TIME|wxPD_REMAINING_TIME);
my @installed=$self->{cpan}->installed(); #get installed modules
my $percent=$max_pval/@installed; #number to increment progress by
my $begin=time(); #for timing loops
my $cnt=0; #the count of current index of @installed - for progressbar
my $numFound=0; #the number of modules that match CPAN to CPANPLUS::Installed
$progress->Update(0,_T("Step 1 of 2: Categorizing ").@installed._T(" Installed Modules...")); #start actual progress
#search through installed modules and insert them into the correct category
foreach $i (@installed){
unless ($i->is_uptodate()){
my $thisName=$i->name;
my $cat_num=$self->{category_list}->{$thisName};
if (defined($cat_num)){
$cat_num=0 if ($cat_num==99); #don't use index 99, it make array too large
$cat_num=1 if ($i->module_is_supplied_with_perl_core() && $cat_num==2);
push (@{$tree{$self->{catNames}->[$cat_num]}}, $thisName); #add the item to the tree
$numFound++; #increment the number of items that matched
}
}
unless ($progress->Update($cnt*$percent)){
$progress->Destroy();
return 0;
}
$cnt++; #increment current index in @installed
}
#end timing method
my $end=time();
Wx::LogMessage _T("Finished Sorting in ").sprintf("%d",(($end-$begin)/60)).":".(($end-$begin) % 60)."\n";
#store tree for later use
$tree{'_items_in_tree_'}=$numFound;
$self->{'tree_UpdatesByCategory'}=\%tree;
#populate the TreeCtrl
return 0 unless $self->PopulateWithHash(\%tree,$progress,$max_pval);
Wx::LogMessage _T("[Done]");
$progress->Destroy();
_uShowErr;
return 1;
}
sub _show_updates_by_author{
my $self=shift;
if ($self->{'tree_UpdatesByAuthor'}){
return 0 unless $self->PopulateWithHash($self->{'tree_UpdatesByAuthor'});
Wx::LogMessage _T("[Done]");
return 1;
}
my %tree=();
my $max_pval=10000; #the maximum value of the progress bar
my $progress=Wx::ProgressDialog->new(_T("Setting Up List..."),
_T("CPANPLUS is getting information..."),
$max_pval,
$self,
wxPD_APP_MODAL|wxPD_CAN_ABORT|wxPD_ESTIMATED_TIME|wxPD_REMAINING_TIME);
my @installed=$self->{cpan}->installed(); #get installed modules
my $percent=$max_pval/@installed; #number to increment progress by
my $begin=time(); #for timing loops
my $cnt=0; #the count of current index of @installed - for progressbar
my $numFound=0; #the number of modules that match CPAN to CPANPLUS::Installed
$progress->Update(0,_T("Step 1 of 2: Sorting ").@installed." Installed Modules..."); #start actual progress
#search through installed modules and insert them into the correct category
foreach $i (@installed){
unless ($i->is_uptodate()){
my $thisName=$i->name;
my $thisAuthor=$i->author()->cpanid." [".$i->author()->author."]";
my $cat_num=$self->{category_list}->{$thisName};
push (@{$tree{$thisAuthor}}, $thisName); #add the item to the tree
}
unless ($progress->Update($cnt*$percent)){
$progress->Destroy();
return 0;
}
$cnt++; #increment current index in @installed
}
#end timing method
my $end=time();
Wx::LogMessage _T("Finished Sorting in ").sprintf("%d",(($end-$begin)/60)).":".(($end-$begin) % 60)."\n";
#store tree for later use
$tree{'_items_in_tree_'}=$numFound;
$self->{'tree_UpdatesByAuthor'}=\%tree;
#populate the TreeCtrl
return 0 unless $self->PopulateWithHash(\%tree,$progress,$max_pval);
Wx::LogMessage _T("[Done]");
$progress->Destroy();
_uShowErr;
return 1;
}
sub _show_updates_by_name{
my $self=shift;
if ($self->{'tree_UpdatesByName'}){
return 0 unless $self->PopulateWithHash($self->{'tree_UpdatesByName'});
Wx::LogMessage _T("[Done]");
return 1;
}
my %tree=();
my $max_pval=10000; #the maximum value of the progress bar
my $progress=Wx::ProgressDialog->new(_T("Setting Up List..."),
_T("CPANPLUS is getting information..."),
$max_pval,
$self,
wxPD_APP_MODAL|wxPD_CAN_ABORT|wxPD_ESTIMATED_TIME|wxPD_REMAINING_TIME);
my @installed=$self->{cpan}->installed(); #get installed modules
my $percent=$max_pval/@installed; #number to increment progress by
my $begin=time(); #for timing loops
my $cnt=0; #the count of current index of @installed - for progressbar
my $numFound=0; #the number of modules that match CPAN to CPANPLUS::Installed
$progress->Update(0,_T("Step 1 of 2: Sorting ").@installed." Installed Modules..."); #start actual progress
#search through installed modules and insert them into the correct category
foreach $i (@installed){
unless ($i->is_uptodate()){
my $thisName=$i->name;
my ($top_level)=split('::',$thisName);
push (@{$tree{$top_level}}, ($thisName eq $top_level)?():$thisName); #add the item to the tree
}
unless ($progress->Update($cnt*$percent)){
$progress->Destroy();
return 0;
}
$cnt++; #increment current index in @installed
}
#end timing method
my $end=time();
Wx::LogMessage _T("Finished Sorting in ").sprintf("%d",(($end-$begin)/60)).":".(($end-$begin) % 60)."\n";
#store tree for later use
$tree{'_items_in_tree_'}=$numFound;
$self->{'tree_UpdatesByName'}=\%tree;
#populate the TreeCtrl
return 0 unless $self->PopulateWithHash(\%tree,$progress,$max_pval);
Wx::LogMessage _T("[Done]");
$progress->Destroy();
_uShowErr;
return 1;
}
sub _show_installed_by_name{
my $self=shift;
if ($self->{'tree_InstalledByName'}){
return 0 unless $self->PopulateWithHash($self->{'tree_InstalledByName'});
Wx::LogMessage _T("[Done]");
return 1;
}
my %tree=();
my $max_pval=10000; #the maximum value of the progress bar
my $progress=Wx::ProgressDialog->new(_T("Setting Up List..."),
_T("CPANPLUS is getting information..."),
$max_pval,
$self,
wxPD_APP_MODAL|wxPD_CAN_ABORT|wxPD_ESTIMATED_TIME|wxPD_REMAINING_TIME);
my @installed=$self->{cpan}->installed(); #get installed modules
my $percent=$max_pval/@installed; #number to increment progress by
my $begin=time(); #for timing loops
my $cnt=0; #the count of current index of @installed - for progressbar
my $numFound=0; #the number of modules that match CPAN to CPANPLUS::Installed
$progress->Update(0,_T("Step 1 of 2: Sorting ").@installed._T(" Installed Modules...")); #start actual progress
#search through installed modules and insert them into the correct category
foreach $i (@installed){
my $thisName=$i->name;
my ($top_level)=split('::',$thisName);
push (@{$tree{$top_level}}, ($thisName eq $top_level)?():$thisName); #add the item to the tree
unless ($progress->Update($cnt*$percent)){
$progress->Destroy();
return 0;
}
$cnt++; #increment current index in @installed
}
#end timing method
my $end=time();
Wx::LogMessage _T("Finished Sorting in ").sprintf("%d",(($end-$begin)/60)).":".(($end-$begin) % 60)."\n";
#store tree for later use
$tree{'_items_in_tree_'}=keys(%tree); #@installed; #$numFound;
$self->{'tree_InstalledByName'}=\%tree;
#populate the TreeCtrl
return 0 unless $self->PopulateWithHash(\%tree,$progress,$max_pval);
Wx::LogMessage _T("[Done]");
$progress->Destroy();
_uShowErr;
return 1;
}
#populate tree with installed modules sorted by author id
sub _show_installed_by_author{
my $self=shift;
if ($self->{'tree_InstalledByAuthor'}){
return 0 unless $self->PopulateWithHash($self->{'tree_InstalledByAuthor'});
Wx::LogMessage _T("[Done]");
return 1;
}
my %tree=();
my $max_pval=10000; #the maximum value of the progress bar
my $progress=Wx::ProgressDialog->new("Setting Up List...",
"CPANPLUS is getting information...",
$max_pval,
$self,
wxPD_APP_MODAL|wxPD_CAN_ABORT|wxPD_ESTIMATED_TIME|wxPD_REMAINING_TIME);
my @installed=$self->{cpan}->installed(); #get installed modules
my $percent=$max_pval/@installed; #number to increment progress by
my $begin=time(); #for timing loops
my $cnt=0; #the count of current index of @installed - for progressbar
my $numFound=0; #the number of modules that match CPAN to CPANPLUS::Installed
$progress->Update(0,_T("Step 1 of 2: Sorting ").@installed._T(" Installed Modules...")); #start actual progress
#search through installed modules and insert them into the correct category
foreach $i (@installed){
my $thisName=$i->name;
my $thisAuthor=$i->author()->cpanid." [".$i->author()->author."]";
my $cat_num=$self->{category_list}->{$thisName};
push (@{$tree{$thisAuthor}}, $thisName); #add the item to the tree
unless ($progress->Update($cnt*$percent)){
$progress->Destroy();
return 0;
}
$cnt++; #increment current index in @installed
}
#end timing method
my $end=time();
Wx::LogMessage _T("Finished Sorting in ").sprintf("%d",(($end-$begin)/60)).":".(($end-$begin) % 60)."\n";
#store tree for later use
$tree{'_items_in_tree_'}=$numFound;
$self->{'tree_InstalledByAuthor'}=\%tree;
#populate the TreeCtrl
return 0 unless $self->PopulateWithHash(\%tree,$progress,$max_pval);
Wx::LogMessage _T("[Done]");
$progress->Destroy();
_uShowErr;
return 1;
}
#populate tree with installed modules sorted by category
sub _show_installed_by_category{
my $self=shift;
if ($self->{'tree_InstalledByCategory'}){
return 0 unless $self->PopulateWithHash($self->{'tree_InstalledByCategory'});
Wx::LogMessage _T("[Done]");
return 1;
}
my %tree=();
my $max_pval=10000; #the maximum value of the progress bar
my $progress=Wx::ProgressDialog->new(_T("Setting Up List..."),
_T("CPANPLUS is getting information..."),
10000,
$self,
wxPD_APP_MODAL|wxPD_CAN_ABORT|wxPD_ESTIMATED_TIME|wxPD_REMAINING_TIME);
my @installed=$self->{cpan}->installed(); #get installed modules
my $percent=$max_pval/@installed; #number to increment progress by
my $begin=time(); #for timing loops
my $cnt=0; #the count of current index of @installed - for progressbar
my $numFound=0; #the number of modules that match CPAN to CPANPLUS::Installed
$progress->Update(0,_T("Step 1 of 2: Categorizing ").@installed._T(" Installed Modules...")); #start actual progress
#search through installed modules and insert them into the correct category
foreach $i (@installed){
my $thisName=$i->name;
my $cat_num=$self->{category_list}->{$thisName};
$progress->Update($cnt*$percent);
# "Step 1 of 2: Categorizing ".@installed." Installed Modules...#$cnt : ".$i->name);
if (defined($cat_num)){
$cat_num=0 if ($cat_num==99); #don't use index 99, it make array too large
$cat_num=1 if ($i->module_is_supplied_with_perl_core() && $cat_num==2);
push (@{$tree{$self->{catNames}->[$cat_num]}}, $thisName); #add the item to the tree
$numFound++; #increment the number of items that matched
}
unless ($progress->Update($cnt*$percent)){
$progress->Destroy();
return 0;
}
$cnt++; #increment current index in @installed
}
#end timing method
my $end=time();
Wx::LogMessage _T("Finished Sorting in ").sprintf("%d",(($end-$begin)/60)).":".(($end-$begin) % 60)."\n";
#store tree for later use
$tree{'_items_in_tree_'}=$numFound;
$self->{'tree_InstalledByCategory'}=\%tree;
#populate the TreeCtrl
return 0 unless $self->PopulateWithHash(\%tree,$progress,$max_pval);
Wx::LogMessage _T("[Done]");
$progress->Destroy();
_uShowErr;
return 1;
}
#this returns a referece to a hash, (module_name=>category_number), of all modules
sub _get_categories{
my $self = shift;
my $moduleFile= _uGetPath($self->{config},'cpp_modlist');
my $modlistEval; #the string to evaluate == 03modlist.data.gz
#inflate file into $modlistEval
Wx::LogMessage _T("Getting Category List...Inflating...");
use IO::Uncompress::AnyInflate qw(anyinflate $AnyInflateError) ;
anyinflate $moduleFile => \$modlistEval
or Wx::LogMessage _T("anyinflate failed: ").$AnyInflateError."\n";
return unless $modlistEval;
Wx::LogMessage _T("Successfully Inflated Module Info File!");
#get rid of file info in header
$modlistEval=~s/(.*)package CPAN\:\:Modulelist/package CPAN\:\:Modulelist/si ;#get rid of file info
#create List of Categories
my $cat_hash=(); #the hash that is stored in the file
my %categories=(); #the return value of this function
eval $modlistEval.'$cat_hash=(CPAN::Modulelist->data)[0];';Wx::LogMessage($@) if $@;
$categories{$_}=$cat_hash->{$_}->{'chapterid'} foreach (keys(%$cat_hash));
#return list
Wx::LogMessage _T("Successfully read Category List!");
return \%categories;
_uShowErr;
}
#this method displays the search results.
#use: $self->search($type,@list_of_searches)
#TODO add support for multiple searches, using ',' as delimiter
#TODO show scrollbars
sub search{
my $self=shift;
my ($type,@search)=@_;
$self->{statusBar}->SetStatusText(_T("Searching. Please Wait..."));
my $progress=Wx::ProgressDialog->new(_T("Setting Up List..."),
_T("CPANPLUS is getting information..."),
MAX_PROGRESS_VALUE,
$self,
wxPD_APP_MODAL|wxPD_CAN_ABORT|wxPD_ESTIMATED_TIME|wxPD_REMAINING_TIME);
$self->DeleteChildren($self->GetRootItem());
foreach $s (@search){
Wx::LogMessage _T("Searching for: ").$search[0]._T(" by $type\n");
if ($s=~m|/(.*)/(.*)|){
#print "Matching Regex...\n";
eval "\$s=qr/$1/".($2||'');
}else{
$s=qr/$s/i;
}
}
$type= lc($type);
my $mparent=$self->GetRootItem();
my @names=();
my $numFound=0;
my $tmpCnt=1;
$modules={};
if ($type eq 'any' || $type eq 'all'){
my @modterms=CPANPLUS::Module::accessors(); #('name','version','path','comment','package','description','dslip','status');
my @authterms=CPANPLUS::Module::Author::accessors(); #('author','cpanid','email');
my $percent = MAX_PROGRESS_VALUE/(@modterms+@authterms);
my $count=0;
foreach $term (@modterms){
if ($progress->Update($percent*($count++),_T("Searching in $term: Found ").keys(%$modules)._T(" items"))){
foreach $m ($self->{cpan}->search(type => $term, allow => \@search)){
if ($m->isa(CPANPLUS::Module)){
#print "module: ".$m->name." [".($percent*($count++)/MAX_PROGRESS_VALUE)."]\n";
$modules->{$m->name} = $m;
}
if ($m->isa(CPANPLUS::Module::Author)){
foreach $amod ($m->modules()){
#print "amodule: ".$m->name." [".($percent*($count++)/MAX_PROGRESS_VALUE)."]\n";
$modules->{$amod->name} = $amod;
}
}
}
}else{$progress->Destroy();return;}
}
}else{
foreach $m ($self->{cpan}->search(type => $type, allow => \@search)){
return unless $progress->Update(MAX_PROGRESS_VALUE-1,_T("Found ").keys(%$modules)._T(" items"));
$modules->{$m->name}=$m;
}
}
$self->PopulateWithModuleHash($progress,$modules);
$progress->Destroy;
#Wx::Window::FindWindowByName('module_splitter')->FitInside();
#Wx::Window::FindWindowByName('module_splitter')->UpdateWindowUI(wxUPDATE_UI_RECURSE );
_uShowErr;
print "Window Height: ".$self->GetClientSize()->GetWidth." , ".$self->GetClientSize()->GetHeight."\n";
# print Dumper $self->GetClientSize();
$self->{statusBar}->SetStatusText('');
my $curStyle=$self->GetWindowStyleFlag();
$self->SetWindowStyleFlag($self->GetWindowStyleFlag()|wxVSCROLL);
$self->GetParent()->SetWindowStyleFlag($self->GetParent()->GetWindowStyleFlag()|wxVSCROLL);
}
sub PopulateWithModuleHash{
my $self=shift;
my $progress=shift || Wx::ProgressDialog->new(_T("Please Wait..."),
_T("Displaying List..."),
MAX_PROGRESS_VALUE,
$self,
wxPD_APP_MODAL|wxPD_CAN_ABORT|wxPD_ESTIMATED_TIME|wxPD_REMAINING_TIME);
my $modules=shift;
my @names=();
my $count=0;
my $numFound=keys(%$modules);
return unless $numFound>0;
my $percent=MAX_PROGRESS_VALUE / $numFound;
return unless $progress->Update(0,_T("Getting info for $numFound items."));
my $newTree={};
#get information from modules
foreach $modname (keys(%$modules)){
last unless $progress->Update($percent*$count);
if ($modules->{$modname}->isa('CPANPLUS::Module')){
my @names=split('::',$modname);
my $ref=$newTree;
foreach $n (@names){
$ref=$ref->{$n}='';
# push(@names,$modname);
}
}
if ($modules->{$modname}->isa('CPANPLUS::Module::Author')){
foreach $m ($modules->{$modname}->modules()){
my @names=split('::',$m->name);
my $ref=$newTree;
foreach $n (@names){
$ref=$ref->{$n}='';
# push(@names,$m->name);
}
}
}
$count++;
}
#populate the tree ctrl
return unless $progress->Update(0,_T("Populating tree with ").$numFound._T(" items.") );
$count=0;
# my $dummy=$self->AppendItem($self->GetRootItem(),'Modules');
# foreach $item (sort {lc($a) cmp lc($b)} @names){
# $self->AppendItem($dummy,$item,$self->_get_status_icon($item));
# $count++;
# }
foreach $k (sort(keys(%$newTree))){
return unless $progress->Update($percent*$count);
my $parent=$self->AppendItem($self->GetRootItem(),$item,$self->_get_status_icon($item));
my $ref=$newTree->{$k};
while($ref){
}
$count++;
}
# my $dummy=$self->AppendItem($self->GetRootItem(),'end');
# my $subDummy=$self->AppendItem($dummy,'end');
# $self->EnsureVisible($dummy);
return 1;
}
#this method populates the list with the given module objects.
#if the object is an Author, then get the module names he/she has written
sub PopulateWithModuleList{
my $self=shift;
my $progress=shift || Wx::ProgressDialog->new(_T("Please Wait..."),
_T("Displaying List..."),
MAX_PROGRESS_VALUE,
$self,
wxPD_APP_MODAL|wxPD_CAN_ABORT|wxPD_ESTIMATED_TIME|wxPD_REMAINING_TIME);
my $totalFound=shift;
return unless $totalFound;
my $numFound=$totalFound;
my @modules=@_;
my @names=();
my $count=0;
my $percent=MAX_PROGRESS_VALUE/$totalFound;
return unless $progress->Update(0,_T("Getting info for $numFound items."));
#get information from modules
foreach $mod (@modules){
last unless $progress->Update($percent*$count);
if ($mod->isa('CPANPLUS::Module')){
push(@names,$mod->name);
}
if ($mod->isa('CPANPLUS::Module::Author')){
foreach $m ($mod->modules()){
push(@names,$m->name);
}
}
$count++;
}
#populate the tree ctrl
return unless $progress->Update(0,_T("Populating tree with").$totalFound._T(" items.") );
$count=0;
foreach $item (sort {lc($a) cmp lc($b)} @names){
return unless $progress->Update($percent*$count);
$self->AppendItem($self->GetRootItem(),$item,$self->_get_status_icon($item));
$count++;
}
return 1;
}
#this method returns the index in the imageList for the status of the passed name
sub _get_status_icon{
my $self=shift;
my ($name)=@_;
my $mod=$self->_get_mod($name);
return $self->{iconList}->unknown->idx unless $mod;
return $self->{iconList}->installed->idx if $mod->is_uptodate();
return $self->{iconList}->not_installed->idx if !$mod->installed_version();
return $self->{iconList}->update->idx;
_uShowErr;
}
sub SetImageList{ #must be a Wx::ImageList
my ($self,$list)=@_;
$self->{iconList}=$list;
$self->AssignImageList($list->imageList);
}
########################################
########### Context Menu ##############
########################################
package CPANPLUS::Shell::Wx::ModuleTree::Menu;
use base 'Wx::Menu';
use Wx::Event qw/EVT_WINDOW_CREATE EVT_MENU/;
use Data::Dumper;
use Wx::Locale gettext => '_T';
sub new {
my $class = shift;
my $parent=shift;
my $item=shift;
my $self = $class->SUPER::new(); # create an 'empty' menu object
#get image so we can determine what the status is
$img=$parent->GetItemImage($item);
$actions=new Wx::Menu();
$install=$actions->Append(1000,_T("Install")) if $img == 3;
$update=$actions->Append(1001,_T("Update")) if $img == 1;
$uninstall=$actions->Append(1002,_T("Uninstall")) if ($img==0 or $img==1);
$actions->AppendSeparator();
$fetch=$actions->Append(1003,_T("Fetch"));
$extract=$actions->Append(1004,_T("Extract"));
$prepare=$actions->Append(1005,_T("Prepare"));
$build=$actions->Append(1006,_T("Build"));
$test=$actions->Append(1007,_T("Test"));
$self->AppendSubMenu($actions,_T("Actions"));
$info=$self->Append(1008,_T("Get All Information"));
my $modName=$parent->GetItemText($item);
( run in 1.504 second using v1.01-cache-2.11-cpan-39bf76dae61 )