"Fossies" - the Fresh Open Source Software Archive 
Member "namefix.pl/libs/gui/manual.pm" (30 Jan 2010, 10321 Bytes) of package /linux/privat/old/namefix.pl_4.0.2.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "manual.pm" see the
Fossies "Dox" file reference documentation.
1 use strict;
2 use warnings;
3
4 # routines for manual renaming etc
5
6 sub manual_edit
7 {
8 ($main::hlist_file, $main::hlist_cwd) = $main::hlist2->info("data", $main::hlist_selection);
9 my $file = $main::hlist_file;
10 my $file_original = $file;
11 my $row = 1;
12 my $EXT = 0;
13 my $new_fn;
14 my $old_fn;
15 my $new_ext;
16 my $old_ext;
17 my $ent_max_l = 50;
18 my $ent_min_l = 2;
19 my $ent_l;
20 my $l = length $file;
21
22 &plog(3, "sub manual_edit: \"$file\"");
23
24 if($ent_min_l <= $l && $l <= $ent_max_l)
25 {
26 $ent_l = $l;
27 }
28 elsif($ent_min_l > $l)
29 {
30 $ent_l = $ent_min_l;
31 }
32 else
33 {
34 $ent_l = $ent_max_l;
35 }
36
37 if(-f $file && $file =~ /^(.*)\.(.{3,4})$/)
38 {
39 $new_fn = $1;
40 $old_fn = $new_fn;
41 $new_ext = $2;
42 $old_ext = $new_ext;
43 $EXT = 1;
44 }
45
46 if(!$file) {
47 &plog(0, "sub manual_edit: \$file isnt defined.");
48 return;
49 }
50
51 my $tag = "";
52 my $art = "";
53 my $tit = "";
54 my $tra = "";
55 my $alb = "";
56 my $com = "";
57 my $gen = "";
58 my $year = "";
59
60 &plog(4, "sub manual_edit: chdir to \$main::hlist_cwd = \"$main::hlist_cwd\" ");
61 chdir $main::hlist_cwd; # shift to correct dir (needed for recursive mode).
62
63 my $newfile = $file;
64
65 my $w = $main::mw->Toplevel();
66 $w->title("Manual Rename");
67
68 $w->Label(
69 -text=>"Manual Rename",
70 -font=>$main::dialog_title_font
71 )
72 -> grid(
73 -row=>1,
74 -column=>1,
75 -columnspan=>1
76 );
77
78 my $frame1 = $w->Frame(
79 -borderwidth=>1
80 )
81 ->grid(
82 -row=>2,
83 -column=>1,
84 -columnspan=>1
85 );
86
87 my $button_frame = $w->Frame(
88 -borderwidth=>1
89 )
90 ->grid(
91 -row=>3,
92 -column=>1,
93 -columnspan=>1
94 );
95
96 $frame1->Label(
97 -text=>"Old Filename: "
98 )
99 ->grid(
100 -row=>1,
101 -column=>1
102 );
103
104 if($EXT)
105 {
106 $frame1->Entry
107 (
108 -textvariable=>\$old_fn,
109 -width=>$ent_l,
110 -state=>"readonly",
111 )
112 ->grid
113 (
114 -row=>1,
115 -column=>2
116 );
117
118 $frame1->Label(
119 -text=>" . "
120 )
121 ->grid(
122 -row=>1,
123 -column=>3
124 );
125
126 $frame1->Entry
127 (
128 -textvariable=>\$old_ext,
129 -width=>5,
130 -state=>"readonly",
131 )
132 ->grid
133 (
134 -row=>1,
135 -column=>4
136 );
137 }
138 else
139 {
140 $frame1->Entry
141 (
142 -textvariable=>\$file,
143 -width=>$ent_l,
144 -state=>"readonly",
145 )
146 ->grid
147 (
148 -row=>1,
149 -column=>2
150 );
151 }
152
153 $frame1->Label(
154 -text=>"New Filename: "
155 )
156 ->grid(
157 -row=>2,
158 -column=>1
159 );
160
161 if($EXT)
162 {
163 $frame1->Entry
164 (
165 -textvariable=>\$new_fn,
166 -width=>$ent_l
167 )
168 ->grid(
169 -row=>2,
170 -column=>2
171 );
172 $frame1->Label(
173 -text=>" . "
174 )
175 ->grid(
176 -row=>2,
177 -column=>3
178 );
179 $frame1->Entry
180 (
181 -textvariable=>\$new_ext,
182 -width=>5
183 )
184 ->grid(
185 -row=>2,
186 -column=>4
187 );
188 }
189 else
190 {
191 $frame1->Entry(
192 -textvariable=>\$newfile,
193 -width=>$ent_l
194 )
195 ->grid(
196 -row=>2,
197 -column=>2
198 );
199 }
200 if($file =~ /.*\.mp3$/i) {
201 &plog(4, "sub manual_edit: \"$file\" is a mp3, using mp3 rename gui ");
202 ($tag, $art, $tit, $tra, $alb, $com, $gen, $year) = &get_tags($file);
203 $frame1->Label(
204 -text=>"Artist: "
205 )
206 ->grid(
207 -row=>3,
208 -column=>1
209 );
210
211 $frame1->Entry(
212 -textvariable=>\$art,
213 -width=>30
214 )
215 ->grid(
216 -row=>3,
217 -column=>2,
218 -sticky=>"nw",
219 -columnspan=>3
220 );
221
222 $frame1->Label(
223 -text=>"Track: "
224 )
225 ->grid(
226 -row=>4,
227 -column=>1
228 );
229
230 $frame1->Entry(
231 -textvariable=>\$tra,
232 -width=>2
233 )
234 ->grid(
235 -row=>4,
236 -column=>2,
237 -sticky=>"nw",
238 -columnspan=>3
239 );
240
241 $frame1->Label(
242 -text=>"Title: "
243 )
244 ->grid(
245 -row=>5,
246 -column=>1
247 );
248
249 $frame1->Entry(
250 -textvariable=>\$tit,
251 -width=>30
252 )
253 ->grid(
254 -row=>5,
255 -column=>2,
256 -sticky=>"nw",
257 -columnspan=>3
258 );
259
260 $frame1->Label(
261 -text=>"Album: "
262 )
263 ->grid(
264 -row=>6,
265 -column=>1
266 );
267
268 $frame1->Entry
269 (
270 -textvariable=>\$alb,
271 -width=>30,
272 )
273 ->grid(
274 -row=>6,
275 -column=>2,
276 -sticky=>"nw",
277 -columnspan=>3
278 );
279
280 $frame1->Label
281 (
282 -text=>"Genre: "
283 )
284 ->grid
285 (
286 -row=>7,
287 -column=>1
288 );
289
290 $frame1->JComboBox
291 (
292 -mode=>'readonly',
293 -relief=>'groove',
294 -textvariable =>\$gen,
295 -choices=>\@main::genres,
296 -entrywidth=>16,
297 )
298 -> grid
299 (
300 -row=>7,
301 -column=>2,
302 -sticky=>"nw",
303 -columnspan=>3
304 );
305
306 $frame1->Label(
307 -text=>"Year: "
308 )
309 ->grid(
310 -row=>8,
311 -column=>1
312 );
313
314 $frame1->Entry
315 (
316 -textvariable=>\$year,
317 -width=>30
318 )
319 ->grid
320 (
321 -row=>8,
322 -column=>2,
323 -sticky=>"nw",
324 -columnspan=>3
325 );
326
327 $frame1->Label(
328 -text=>"comment: "
329 )
330 ->grid(
331 -row=>9,
332 -column=>1
333 );
334
335 $frame1->Entry
336 (
337 -textvariable=>\$com,
338 -width=>30
339 )
340 ->grid
341 (
342 -row=>9,
343 -column=>2,
344 -sticky=>"nw",
345 -columnspan=>3
346 );
347
348 }
349 my $but_reset = $button_frame -> Button(
350 -text=>"Reset",
351 -activebackground=>'white',
352 -command => sub {
353 $newfile = $file = $file_original;
354 $new_fn = $old_fn;
355 $new_ext = $old_ext;
356
357 if(
358 $main::id3_mode == 1 &&
359 $file =~ /.*\.mp3/i
360 ) {
361 ($tag, $art, $tit, $tra, $alb, $com, $gen, $year) = &get_tags($file);
362 }
363 }
364 )
365 -> grid(
366 -row => 4,
367 -column => 1,
368 -columnspan => 1
369 );
370
371 if(
372 $main::id3_mode == 1 &&
373 $file =~ /.*\.mp3$/i
374 ) {
375 $button_frame -> Button(
376 -text=>"Guess Tag",
377 -activebackground=>'white',
378 -command => sub {
379 ($art, $tra, $tit, $alb) = &guess_tags($file);
380 print "button\n";
381 }
382 )
383 -> grid(
384 -row => 4,
385 -column => 2,
386 -columnspan => 1
387 );
388 }
389
390 my $but_apply = $button_frame -> Button(
391 -text=>"Apply",
392 -activebackground=>'white',
393 -command => sub {
394 if($EXT)
395 {
396 &me_rename($file, "$new_fn.$new_ext");
397 $old_fn = $new_fn;
398 $old_ext = $new_ext;
399 }
400 else
401 {
402 &me_rename($file, $newfile);
403 $file = $newfile;
404 }
405 if(
406 $main::id3_mode == 1 &&
407 $file =~ /.*\.mp3$/i
408 ) {
409 &write_tags($file, $art, $tit, $tra, $alb, $com, $gen, $year);
410 }
411 }
412 )
413 -> grid(
414 -row => 4,
415 -column => 3,
416 -columnspan => 1
417 );
418
419 my $but_close = $button_frame -> Button(
420 -text=>"Close",
421 -activebackground=>'white',
422 -command => sub
423 {
424 destroy $w;
425 if($main::MR_DONE)
426 {
427 $main::MR_DONE = 0;
428 &ls_dir;
429 }
430 }
431 )
432 -> grid(
433 -row=>4,
434 -column=>4,
435 -columnspan=>1
436 );
437
438 $w->update();
439 $w->resizable(0,0);
440
441 return;
442 }
443
444 sub me_rename
445 {
446 my $file = shift;
447 my $newfile = shift;
448 $main::MR_DONE = 1;
449
450 if($file eq $newfile)
451 {
452 return;
453 }
454
455 if($main::fat32fix)
456 {
457 my $tmpfile = $file."tmp";
458
459 if(-f $tmpfile)
460 {
461 &plog(0, "sub me_rename: tmpfile: $tmpfile exists.");
462 return 0;
463 }
464 rename $file, $tmpfile;
465 rename $tmpfile, $newfile;
466 }
467 else
468 {
469 if(-f $newfile)
470 {
471 &plog(0, "sub me_rename: newfile: $newfile exists");
472 return 0;
473 }
474 rename $file, $newfile;
475 }
476 }
477
478 1;