| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package CPANPLUS::Shell::Wx::util; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1974
|
use Wx::Event qw(EVT_MENU EVT_TOOL EVT_WINDOW_CREATE EVT_BUTTON); |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
use Wx::ArtProvider qw/:artid :clientid/; |
|
5
|
|
|
|
|
|
|
use Wx; |
|
6
|
|
|
|
|
|
|
use CPANPLUS; |
|
7
|
|
|
|
|
|
|
use Cwd; |
|
8
|
|
|
|
|
|
|
use Data::Dumper; |
|
9
|
|
|
|
|
|
|
use CPANPLUS::Error; |
|
10
|
|
|
|
|
|
|
use File::Spec; |
|
11
|
|
|
|
|
|
|
use File::HomeDir; |
|
12
|
|
|
|
|
|
|
use Class::Struct qw(struct); |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
#enable gettext support |
|
15
|
|
|
|
|
|
|
use Wx::Locale gettext => '_T'; |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
use base qw(Exporter); |
|
18
|
|
|
|
|
|
|
our @EXPORT = qw(_uPopulateTree _uGetTimed _uGetInstallPath |
|
19
|
|
|
|
|
|
|
_uShowErr _u_t_ShowErr _uGetImageData _uGetPath); |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
#returns the path for the specified item |
|
22
|
|
|
|
|
|
|
#call: _uGetPath($cpp_config,$item) |
|
23
|
|
|
|
|
|
|
#$item can be one of : |
|
24
|
|
|
|
|
|
|
# 'app_config' wxCPAN config file |
|
25
|
|
|
|
|
|
|
# 'cpp_mod_dir' path to $cpp_home/authors/id/, where cpanplus stores modules |
|
26
|
|
|
|
|
|
|
# 'cpp_stat_file' path to the cpp status.store file |
|
27
|
|
|
|
|
|
|
# 'cpp_modlist' path to the 03modlist.data.gz file |
|
28
|
|
|
|
|
|
|
sub _uGetPath{ |
|
29
|
|
|
|
|
|
|
my $conf=shift; #a CPANPLUS::Config object |
|
30
|
|
|
|
|
|
|
my $path=shift; #the value we want. |
|
31
|
|
|
|
|
|
|
my $op1=shift; #the optional subdir |
|
32
|
|
|
|
|
|
|
my $ret=undef; #return value |
|
33
|
|
|
|
|
|
|
my $home = File::HomeDir->my_home; #user's home directory |
|
34
|
|
|
|
|
|
|
my $cpp_home= $conf->get_conf('base'); |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
if ($path eq 'app_config'){ |
|
37
|
|
|
|
|
|
|
$ret=File::Spec->catfile($cpp_home,'wxcpan.conf') |
|
38
|
|
|
|
|
|
|
}elsif($path eq 'cpp_mod_dir'){ |
|
39
|
|
|
|
|
|
|
$ret=File::Spec->catdir($cpp_home,"authors","id"); |
|
40
|
|
|
|
|
|
|
}elsif($path eq 'cpp_stat_file'){ |
|
41
|
|
|
|
|
|
|
$ret=File::Spec->catdir($cpp_home,'status.stored'); |
|
42
|
|
|
|
|
|
|
}elsif($path eq 'cpp_modlist'){ |
|
43
|
|
|
|
|
|
|
$ret=File::Spec->catdir($cpp_home,'03modlist.data.gz'); |
|
44
|
|
|
|
|
|
|
}else{ |
|
45
|
|
|
|
|
|
|
print "Usage: CPANPLUS::Shell::Wx::util::_uGetPath('app_config')"; |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
return $ret; |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
#TODO this method populates a tree with the correct status icon |
|
51
|
|
|
|
|
|
|
sub _uPopulateModulesWithIcons{ |
|
52
|
|
|
|
|
|
|
my $max_pval=10000; #the maximum value of the progress bar |
|
53
|
|
|
|
|
|
|
my $tree=shift; |
|
54
|
|
|
|
|
|
|
my $parent=shift; |
|
55
|
|
|
|
|
|
|
my $aref=shift; |
|
56
|
|
|
|
|
|
|
my $progress = shift; |
|
57
|
|
|
|
|
|
|
my $percent=shift || $max_pval/(@{%$tree}/2); |
|
58
|
|
|
|
|
|
|
my $cnt=shift || 0; |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
$progress=Wx::ProgressDialog->new(_T("Inserting Items..."), |
|
61
|
|
|
|
|
|
|
_T("Inserting Items Into List..."), |
|
62
|
|
|
|
|
|
|
$max_pval, |
|
63
|
|
|
|
|
|
|
$self, |
|
64
|
|
|
|
|
|
|
wxPD_APP_MODAL) unless $progress; |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
#remove all items if we are stating anew |
|
67
|
|
|
|
|
|
|
$tree->DeleteChildren($tree->GetRootItem()) unless $cnt; |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
foreach $items ( sort {lc $a cmp lc $b} keys(%$tree) ){ |
|
70
|
|
|
|
|
|
|
my $curParent=$tree->AppendItem( |
|
71
|
|
|
|
|
|
|
$self->GetRootItem(), |
|
72
|
|
|
|
|
|
|
$top_level,_uGetStatusIcon($top_level)); |
|
73
|
|
|
|
|
|
|
$progress->Update($cnt*$percent); #,"[Step 2 of 2] Iserting ".keys(%tree)." Authors Into Tree...#$cnt : $top_level"); |
|
74
|
|
|
|
|
|
|
foreach $item (sort(@{$tree{$top_level}})){ |
|
75
|
|
|
|
|
|
|
if (keys(%$item)){ |
|
76
|
|
|
|
|
|
|
my $new_parent=$self->AppendItem($curParent,(keys(%$item))[0],$self->_get_status_icon($item)) if ($curParent && $item); |
|
77
|
|
|
|
|
|
|
$cnt++; |
|
78
|
|
|
|
|
|
|
$progress->Update($cnt*$percent); |
|
79
|
|
|
|
|
|
|
$cnt=_uPopulateModulesWithIcons($tree,$new_parent,$item,$progress,$percent,$cnt); |
|
80
|
|
|
|
|
|
|
}else{ |
|
81
|
|
|
|
|
|
|
my $new_parent=$self->AppendItem($curParent,$item,$self->_get_status_icon($item)) if ($curParent && $item); |
|
82
|
|
|
|
|
|
|
$progress->Update($cnt*$percent); |
|
83
|
|
|
|
|
|
|
$cnt++; |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
} |
|
87
|
|
|
|
|
|
|
return $cnt; |
|
88
|
|
|
|
|
|
|
#$progress->Destroy(); |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub _uGetInstallPath{ |
|
92
|
|
|
|
|
|
|
my $file=shift; |
|
93
|
|
|
|
|
|
|
#$file=~s|::|/|g; |
|
94
|
|
|
|
|
|
|
my @path=split('::',$file); |
|
95
|
|
|
|
|
|
|
foreach $p (@INC){ |
|
96
|
|
|
|
|
|
|
my $file=File::Spec->catfile($p,@path); |
|
97
|
|
|
|
|
|
|
#print "$p/$file\n"; |
|
98
|
|
|
|
|
|
|
return $file if(-e $file) ; |
|
99
|
|
|
|
|
|
|
} |
|
100
|
|
|
|
|
|
|
} |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
#it checks the stack in CPANPLUS::Error, |
|
103
|
|
|
|
|
|
|
# and logs it to wherever Wx::LogMessage is sent to |
|
104
|
|
|
|
|
|
|
sub _uShowErr{ |
|
105
|
|
|
|
|
|
|
foreach $msg (CPANPLUS::Error::stack()){ |
|
106
|
|
|
|
|
|
|
my $lvl=$msg->level; |
|
107
|
|
|
|
|
|
|
$lvl=~s/cp_//; |
|
108
|
|
|
|
|
|
|
Wx::LogMessage("[CPANPLUS ".(uc($lvl||''))."@".$msg->when."]".$msg->message); |
|
109
|
|
|
|
|
|
|
CPANPLUS::Error::flush(); |
|
110
|
|
|
|
|
|
|
} |
|
111
|
|
|
|
|
|
|
} |
|
112
|
|
|
|
|
|
|
#this method retrieves the local directory where CPANPLUS |
|
113
|
|
|
|
|
|
|
#stores its information regarding each module |
|
114
|
|
|
|
|
|
|
sub _uGetModDir{ |
|
115
|
|
|
|
|
|
|
my $mod=shift; |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
} |
|
118
|
|
|
|
|
|
|
#TODO this method populates a tree with the given array ref |
|
119
|
|
|
|
|
|
|
sub _uPopulateModules($$){ |
|
120
|
|
|
|
|
|
|
my $tree=shift; |
|
121
|
|
|
|
|
|
|
my $aref=shift; |
|
122
|
|
|
|
|
|
|
} |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
#@return the time in readable - mm:ss - format |
|
125
|
|
|
|
|
|
|
#@params: |
|
126
|
|
|
|
|
|
|
# $begin: the time we are comparing to |
|
127
|
|
|
|
|
|
|
#@usage: |
|
128
|
|
|
|
|
|
|
# use util qw/_uGetTimed/; |
|
129
|
|
|
|
|
|
|
# my $begin=time(); |
|
130
|
|
|
|
|
|
|
# {... code to be timed ...} |
|
131
|
|
|
|
|
|
|
# my $totalTime=_uGetTimed($begin); |
|
132
|
|
|
|
|
|
|
sub _uGetTimed($){ |
|
133
|
|
|
|
|
|
|
my $begin=shift; |
|
134
|
|
|
|
|
|
|
mu $end=time(); |
|
135
|
|
|
|
|
|
|
return sprintf("%2d",(($end-$begin)/60)).":".sprintf("%2d",(($end-$begin) % 60)); |
|
136
|
|
|
|
|
|
|
} |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
#the following two structs are used to hold the image data |
|
140
|
|
|
|
|
|
|
#for the image lists for the various treectrl's. |
|
141
|
|
|
|
|
|
|
# idx is the value from imglist->Add($img) |
|
142
|
|
|
|
|
|
|
# icon is the actual icon data |
|
143
|
|
|
|
|
|
|
struct ('CPANPLUS::Shell::Wx::util::imagedata' => { |
|
144
|
|
|
|
|
|
|
idx => '$', |
|
145
|
|
|
|
|
|
|
icon => '$' |
|
146
|
|
|
|
|
|
|
}); |
|
147
|
|
|
|
|
|
|
struct 'CPANPLUS::Shell::Wx::util::images' => { |
|
148
|
|
|
|
|
|
|
installed => 'CPANPLUS::Shell::Wx::util::imagedata', |
|
149
|
|
|
|
|
|
|
update => 'CPANPLUS::Shell::Wx::util::imagedata', |
|
150
|
|
|
|
|
|
|
remove => 'CPANPLUS::Shell::Wx::util::imagedata', |
|
151
|
|
|
|
|
|
|
not_installed => 'CPANPLUS::Shell::Wx::util::imagedata', |
|
152
|
|
|
|
|
|
|
unknown => 'CPANPLUS::Shell::Wx::util::imagedata', |
|
153
|
|
|
|
|
|
|
imageList => 'Wx::ImageList' |
|
154
|
|
|
|
|
|
|
}; |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
#this method returns a images struct with appropriate data |
|
157
|
|
|
|
|
|
|
sub _uGetImageData{ |
|
158
|
|
|
|
|
|
|
my $imgList=Wx::ImageList->new(16,16,1); |
|
159
|
|
|
|
|
|
|
$icon_installed=Wx::ArtProvider::GetBitmap(wxART_TICK_MARK,wxART_BUTTON_C); |
|
160
|
|
|
|
|
|
|
$icon_update=Wx::ArtProvider::GetBitmap(wxART_ADD_BOOKMARK,wxART_BUTTON_C); |
|
161
|
|
|
|
|
|
|
$icon_remove=Wx::ArtProvider::GetBitmap(wxART_DEL_BOOKMARK,wxART_BUTTON_C); |
|
162
|
|
|
|
|
|
|
$icon_not_installed=Wx::ArtProvider::GetBitmap(wxART_NEW_DIR,wxART_BUTTON_C); |
|
163
|
|
|
|
|
|
|
$icon_unknown=Wx::ArtProvider::GetBitmap(wxART_QUESTION,wxART_BUTTON_C); |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
$images=CPANPLUS::Shell::Wx::util::images->new( |
|
166
|
|
|
|
|
|
|
installed => CPANPLUS::Shell::Wx::util::imagedata->new( |
|
167
|
|
|
|
|
|
|
idx => $imgList->Add($icon_installed), |
|
168
|
|
|
|
|
|
|
icon => $icon_installed |
|
169
|
|
|
|
|
|
|
), |
|
170
|
|
|
|
|
|
|
update => CPANPLUS::Shell::Wx::util::imagedata->new( |
|
171
|
|
|
|
|
|
|
idx => $imgList->Add($icon_update), |
|
172
|
|
|
|
|
|
|
icon => $icon_update |
|
173
|
|
|
|
|
|
|
), |
|
174
|
|
|
|
|
|
|
remove => CPANPLUS::Shell::Wx::util::imagedata->new( |
|
175
|
|
|
|
|
|
|
idx => $imgList->Add($icon_remove), |
|
176
|
|
|
|
|
|
|
icon => $icon_remove |
|
177
|
|
|
|
|
|
|
), |
|
178
|
|
|
|
|
|
|
not_installed => CPANPLUS::Shell::Wx::util::imagedata->new( |
|
179
|
|
|
|
|
|
|
idx => $imgList->Add($icon_not_installed), |
|
180
|
|
|
|
|
|
|
icon => $icon_not_installed |
|
181
|
|
|
|
|
|
|
), |
|
182
|
|
|
|
|
|
|
unknown => CPANPLUS::Shell::Wx::util::imagedata->new( |
|
183
|
|
|
|
|
|
|
idx => $imgList->Add($icon_unknown), |
|
184
|
|
|
|
|
|
|
icon => $icon_unknown |
|
185
|
|
|
|
|
|
|
), |
|
186
|
|
|
|
|
|
|
imageList=>$imgList |
|
187
|
|
|
|
|
|
|
); |
|
188
|
|
|
|
|
|
|
return $images; |
|
189
|
|
|
|
|
|
|
} |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
1; |