vfmg (DEVEL): vfmg - use new options sheme - rewritten icons scali...

sparky sparky at pld-linux.org
Tue Nov 1 03:13:58 CET 2005


Author: sparky                       Date: Tue Nov  1 02:13:58 2005 GMT
Module: vfmg                          Tag: DEVEL
---- Log message:
- use new options sheme
- rewritten icons scaling (now icons can be scaled for any WM using them)
- few minor changes

---- Files affected:
vfmg:
   vfmg (1.73.2.17 -> 1.73.2.18) 

---- Diffs:

================================================================
Index: vfmg/vfmg
diff -u vfmg/vfmg:1.73.2.17 vfmg/vfmg:1.73.2.18
--- vfmg/vfmg:1.73.2.17	Tue Nov  1 01:16:21 2005
+++ vfmg/vfmg	Tue Nov  1 03:13:53 2005
@@ -18,6 +18,7 @@
 	icons_full	=> 0,
 	icons_scale	=> 0,
 	icons_dir	=> "",
+	icons_ext	=> "png",
 	
 	utf			=> 0,
 	encoding	=> "",
@@ -27,7 +28,7 @@
 	strip		=> 0,
 	nomenu		=> 0,
 	xterm		=> "xterm -name xterm-%1 -e %2",
-	convert		=> "convert \%in \%out -geometry 18x18",
+	convert		=> "convert -geometry 16x16 \%in \%out",
 );
 my %opt;
 my $o_output;
@@ -46,6 +47,7 @@
 	'icons-full|I!'	=>	\$opt{icons_full},
 	'icons-scale|S!'=>	\$opt{icons_scale},
 	'icons-dir|d=s'	=>	\$opt{icons_dir},
+	'icons-ext|T=s'	=>	\$opt{icons_ext},
 
 	'utf8|u!'		=>	\$opt{utf},
 	'encoding|E=s'	=>	\$opt{encoding},
@@ -81,6 +83,7 @@
     -I, --icons-full  - check for icons existence and extend to full path
     -S, --icons-scale - scale (shrink) icons (implies -i -I)
     -d, --icons-dir=  - output dir for icons
+    -T, --icons-ext=  - output icons extension (default: png)
 
   Output encoding:
     -u, --utf8        - output in utf8 (default is locale setting)
@@ -141,7 +144,6 @@
 	$opt{$opt} = $rcopt{$opt} unless defined $opt{$opt};
 	$opt{$opt} = $defopt{$opt} unless defined $opt{$opt};
 	$opt{$opt} =~ s/\${HOME}/$ENV{'HOME'}/go;
-	print "$opt => $opt{$opt}\n";
 }
 
 # check dependencies
@@ -162,12 +164,6 @@
 	}
 }
 $opt{encoding}="utf8" if $opt{utf};
-
-print "After checking:\n";
-foreach my $opt (keys %opt) {
-	print "$opt => $opt{$opt}\n";
-}
-exit;
 # header }}}
 
 # search dirs {{{
@@ -203,20 +199,24 @@
 );
 
 my @path;
-if($opt{exec}) {
+if ( $opt{exec} ) {
 	@path=(grep (-d, split(/:+/,$ENV{'PATH'})), "");
-	if($opt{xterm}) {
+	if( length $opt{xterm} ) {
 		my $exists=0;
 		my $bin=$opt{xterm};
 		$bin=~s/(\S+).*/$1/;  #v---------v
 		foreach my $dir(@path) {	 # would be "//dir/.../file" correct?
-			if(-x "$dir/$bin") {#----^
+			if (-x "$dir/$bin") {#----^
 				$exists=1;
-				$opt{xterm}="$dir/$opt{xterm}" if $opt{full};
+				$opt{xterm}="$dir/$opt{xterm}" if $opt{exec_full};
 				last;
 			}
 		}
-		$opt{xterm}="" unless $exists;
+		unless ($exists) {
+			$opt{xterm}="";
+			warn "Can't find $bin.",
+				" Terminal applications will not be included.\n";
+		}
 	}
 }
 # search dirs }}}
@@ -290,12 +290,12 @@
 	return if $tags{term} and not $opt{xterm};
 
 	my($bin) = ($tags{Exec} =~ /(\S+)/);    #v---------v
-	if ($opt{exec}) {
+	if ( $opt{exec} ) {
 		my $exists;
 		foreach my $dir (@path) {    # would be "//dir/.../file" correct?
 			if (-x "$dir/$bin") {    #----^
 				$exists++;
-				$tags{Exec} = "$dir/$tags{Exec}" if $opt{full};
+				$tags{Exec} = "$dir/$tags{Exec}" if $opt{exec_full};
 				last;
 			}
 		}
@@ -308,23 +308,20 @@
 		s/%2/$tags{Exec}/;
 		$tags{Exec} = $_;
 	}
-	if ($opt{icons}) {
+	if ( $opt{icons_full} ) {
 		my $exists=0;
 		my @idirs;
 		push @idirs, '' if $tags{Icon} =~ m|^/|;
 		push @idirs, @icondirs;
 		foreach my $dir (@idirs) {
 			foreach my $ext ('', qw(.svg .xpm .png)) {
-				if (-f "$dir$tags{Icon}$ext") {
-					$tags{Icon} .= $ext;
-					$exists++;
+				if (-f $dir . $tags{Icon} . $ext) {
+					$tags{Icon} = $dir . $tags{Icon} .$ext;
+					$exists=1;
 					last;
 				}
 			}
-			if ($exists) {
-				$tags{Icon} = "$dir$tags{Icon}" if $opt{full};
-				last;
-			}
+			last if ($exists);
 		}
 		$tags{Icon} = '' unless $exists;
 	}
@@ -340,8 +337,7 @@
 				warn "$File::Find::name: cannot get encoding name for"
 				  . " `$tags{lang}'. Assuming iso-8859-1\n";
 				$tags{enc} = "iso-8859-1";
-			}
-			else {
+			} else {
 				require POSIX;
 				my $old_locale = setlocale(POSIX::LC_ALL());
 				eval {
@@ -636,22 +632,17 @@
 			last;
 		}
 		if ($ok) {
-			if($opt{icons}) {
+			if($opt{icons_full}) {
 				my $exists=0;
 				foreach my $dir(@icondirs) {
-					if(-f "$dir$icon") {
-					} elsif(-f "$dir$icon.svg") {
-						$icon.=".svg";
-					} elsif(-f "$dir$icon.xpm") {
-						$icon.=".xpm";
-					} elsif(-f "$dir$icon.png") {
-						$icon.=".png";
-					} else {
-						next;
+					foreach my $ext ('', qw(.svg .xpm .png)) {
+						if (-f $dir . $icon . $ext) {
+							$exists=1;
+							$icon = $dir . $icon . $ext;
+							last;
+						}
 					}
-					$exists=1;
-					$icon="$dir$icon" if $opt{full};
-					last;
+					last if $exists;
 				}
 				$icon="" unless $exists;
 			}
@@ -705,7 +696,7 @@
 warn "Omitted ending: $file\n" if(($file ne "")&& $o_end);
 # parse menu file }}}
 
-if(($opt{clear})&&(!$opt{promote})) { # {{{
+if( $opt{clear} and not $opt{promote} ) { # {{{
 	my @empty;
 	for(my $i=$#menu; $i>=0; $i--) {
 		$empty[$i]=1;
@@ -724,7 +715,7 @@
 	}
 } #}}}
 
-if($opt{promote}) { # {{{
+if( $opt{promote} ) { # {{{
 	my @count;
 	for(my $i=$#menu; $i>=0; $i--) {
 		$count[$i]=0;
@@ -754,21 +745,21 @@
 	}
 } # }}}
 
-my $DoConvert = `which convert`;
 sub scale_icon {
-	my $icon_in = shift;
-
-	return $icon_in unless $DoConvert;
-
-	my $icon_out = $icon_in;
-	my $icon_ext = shift;
-	my @convert_options = @_;
-
-	$icon_out =~ s/^.*\///;
+	my $icon_in = $_[0];
+	return $icon_in unless $opt{icons_scale};
+	return $icon_in unless -r $icon_in;
+	
+	(my $icon_out = $icon_in ) =~ s/^.*\///;
 	$icon_out =~ s/\..*$//;
-	$icon_out = "$icon_dir/$icon_out.$icon_ext";
-	if( ! -f "$icon_out") {
-		system("convert", at convert_options,$icon_in,$icon_out);
+	$icon_out = "$opt{icons_dir}/$icon_out.$opt{icons_ext}";
+	
+	unless (-f $icon_out) {
+		$_ = $opt{convert};
+		s/\%in/$icon_in/g;
+		s/\%out/$icon_out/g;
+		
+		system($_);
 	}
 	return $icon_out;
 }
@@ -785,11 +776,12 @@
 		my $d = $desktop{$entry};
 		$name = $$d[1];
 		$name =~ s/\"/\\\"/g;
+		my $icon = "";
+		$icon = scale_icon($$d[2]) if $opt{icons};
 		if($menu[$no]{$entry} < 0) {
-			$apps .= qq(${level}prog "$name" "$$d[2]" $$d[3]\n);
+			$apps .= qq(${level}prog "$name" "$icon" $$d[3]\n);
 		} else {
-			my $icon = $$d[2];
-			$icon = "folder" unless length $icon;
+			$icon = "folder" if not length $icon and $opt{icons};
 			print qq(${level}menu "$name" "$icon" {\n);
 			$level.="	";
 			icewm($menu[$no]{$entry});
@@ -876,12 +868,14 @@
 	foreach my $entry (sort cmpdname keys %{$menu[$no]}) {
 		my $d = $desktop{$entry};
 		$name = ($$d[1] =~ /["&<>]/) ? xmlname($$d[1]) : $$d[1];
+		my $icon = "";
+		$icon = scale_icon($$d[2]) if $opt{icons};
 		if($menu[$no]{$entry} < 0) {
 			$apps .= qq($level<app name="$name" cmd=");
 			$apps .= ($$d[3] =~ /["&<>]/) ? xmlname($$d[3]) : $$d[3];
-			$apps .= qq(" icon="$$d[2]"/>\n);
+			$apps .= qq(" icon="$icon"/>\n);
 		} else {
-			print qq($level<menu name="$name" icon="$$d[2]" visible="yes">\n);
+			print qq($level<menu name="$name" icon="$icon" visible="yes">\n);
 			$level.="	";
 			xfce4($menu[$no]{$entry});
 			$level=substr($level,1);
@@ -896,13 +890,15 @@
 	
 	foreach my $entry(keys %{$menu[$no]}) {
 		my $d = $desktop{$entry};
-		$name = encode($opt{enc},$$d[1]);
+		$name = encode($opt{encoding},$$d[1]);
 		if($menu[$no]{$entry} < 0) {
 			$name=~s/\"/\\\"/g;
+			my $icon = "";
+			$icon = scale_icon($$d[2]) if $opt{icons};
 			my $F_OUT;
 			open $F_OUT, ">> $dir/$$d[0]" or warn "$dir/$$d[0]: $!\n";
 			print $F_OUT qq(Exec "$name" exec $$d[3]\n);
-			print $F_OUT qq(MiniPixmap "$$d[2]"\n) if length $$d[2];
+			print $F_OUT qq(MiniPixmap "$icon"\n) if length $icon;
 			close $F_OUT;
 		} else {
 			$name =~ s|/||g;
@@ -942,8 +938,10 @@
 		my $d = $desktop{$entry};
 		( my $name = $$d[1] ) =~ s/\"/\\\"/g;
 		if($menu[$no]{$entry}<0) {
+			my $icon = "";
+			$icon = scale_icon($$d[2]) if $opt{icons};
 			$apps .= qq(AddToMenu $level	"$name"	Exec $$d[3] &\n);
-			$apps .= qq(Style "$name"	Icon $$d[2]\n) if length $$d[2];
+			$apps .= qq(Style "$name"	Icon $icon\n) if length $icon;
 		} else {
 			my $file = $$d[0];
 			$file =~ s/\s+/_/g;
@@ -968,9 +966,8 @@
 	foreach my $entry (sort cmpdname keys %{$menu[$no]}) {
 		my $d = $desktop{$entry};
 		my $icon = "";
-		$icon = $$d[2] if $opt{icons};
-		$icon = scale_icon($$d[2],"png","-geometry","21x18") if $icon;
-		$icon = "\%$icon\%" if $icon;
+		$icon = scale_icon($$d[2]) if $opt{icons};
+		$icon = "\%$icon\%" if length $icon;
 		
 		if($menu[$no]{$entry} < 0) {
 			( my $name = $$d[1] ) =~ s/\"/\\\"/g;
@@ -1009,11 +1006,13 @@
 	foreach my $entry (sort cmpdname keys %{$menu[$no]}) {
 		my $d = $desktop{$entry};
 		( my $name = $$d[1] ) =~ s/\"/\\\"/g;
+		my $icon = "";
+		$icon = scale_icon($$d[2]) if $opt{icons};
 		if($menu[$no]{$entry} < 0) {
 			( my $exec = $$d[3] ) =~ s/\"/\\\"/g;
-			$apps .= qq($level"$name" "$$d[2]" "$exec"\n);
+			$apps .= qq($level"$name" "$icon" "$exec"\n);
 		} else {
-			print qq($level"$name" "$$d[2]"\n),
+			print qq($level"$name" "$icon"\n),
 				"$level+\n";
 			$level.="	";
 			qvwm($menu[$no]{$entry});
@@ -1031,7 +1030,7 @@
 	foreach my $entry (sort cmpdname keys %{$menu[$no]}) {
 		my $d = $desktop{$entry};
 		( my $name = $$d[1] ) =~ s/\"/\\\"/g;
-		if($menu[$no]{$entry}<0) {
+		if($menu[$no]{$entry} < 0) {
 			( my $exec = $$d[3] ) =~ s/\"/\\\"/g;
 			$apps .= qq(${level}cmd "$name" "$exec"\n);
 		} else {
@@ -1053,11 +1052,10 @@
 	my $apps="";
 	foreach my $entry (sort cmpdname keys %{$menu[$no]}) {
 		my $d = $desktop{$entry};
-		$name=encode($opt{enc},$$d[1]);
+		$name=encode($opt{encoding},$$d[1]);
 		$name=~s/\"/\'/g;
 		my $icon="";
-		$icon=$$d[2] if $opt{icons};
-		$icon=scale_icon($icon,"png","-geometry","18x18") if length $icon;
+		$icon = scale_icon($$d[2]) if $opt{icons};
 		if($menu[$no]{$entry}<0) {
 			$apps .= qq("$name" "$icon" exec "$$d[3]"\n);
 		} else {
@@ -1073,14 +1071,16 @@
 	my ($no, $dir)=@_;
 	foreach my $entry (keys %{$menu[$no]}) {
 		my $d = $desktop{$entry};
-		$name = encode($opt{enc},$$d[1]);
+		$name = encode($opt{encoding},$$d[1]);
 		if($menu[$no]{$entry} < 0) {
 			$name =~ s/\"/\\\"/g;
+			my $icon = "";
+			$icon = scale_icon($$d[2]) if $opt{icons};
 			open F_OUT, ">> $dir/$$d[0].lnk" or warn "$dir/$$d[0].lnk: $!\n";
 			print F_OUT "[Shortcut]\n",
 						"Caption=$name\n",
 						"Command=$$d[3]\n";
-			print F_OUT "Icon=$$d[2]\n" if length $$d[2];
+			print F_OUT "Icon=$icon\n" if length $icon;
 			close F_OUT;
 		} else {
 			$name =~ s|/||g;
@@ -1095,17 +1095,19 @@
 	my $apps="";
 	foreach my $entry (sort cmpdname keys %{$menu[$no]}) {
 		my $d = $desktop{$entry};
+		my $icon = "";
+		$icon = scale_icon($$d[2]) if $opt{icons};
 		if($menu[$no]{$entry}<0) {
 			$apps .=
 				"${level}item {\n".
 				"${level}	name = $$d[1]\n".
 				"${level}	action = $$d[3]\n".
-				"${level}	image = $$d[2]\n".
+				"${level}	image = $icon\n".
 				"${level}}\n";
 		} else {
 			print "${level}menu {\n";
 			print "${level}	name = $$d[1]\n";
-			print "${level}	image = $$d[2]\n";
+			print "${level}	image = $icon\n";
 			$level.="	";
 			fbpanel($menu[$no]{$entry});
 			$level=substr($level,1);
@@ -1139,15 +1141,21 @@
 } # }}}
 # WM functions }}}
 
-$opt{enc}||="utf-8" if $opt{utf};
-#use open OUT => ':utf8';
-#eval "use open OUT => ':locale'" unless $opt{enc};	# $o_enc always set
-unless (length $opt{enc}) {
+unless (length $opt{encoding}) {
 	require I18N::Langinfo;
 	I18N::Langinfo->import(qw(langinfo CODESET));
-	$opt{enc}=langinfo(CODESET());
+	$opt{encoding} = langinfo(CODESET());
+}
+binmode STDOUT, ":encoding($opt{encoding})";
+
+if ($opt{icons_scale}) {
+	unless (-d $opt{icons_dir}) { # must be set
+		require File::Path;
+		import File::Path qw(mkpath);
+		rename($opt{icons_dir},$opt{icons_dir}.".old") if -f $opt{icons_dir};
+		mkpath($opt{icons_dir},0,0700);
+	}
 }
-binmode STDOUT, ":encoding($opt{enc})";
 
 # WM case {{{
 if($o_output eq "icewm") {
@@ -1182,7 +1190,8 @@
 	exit;
 }
 if($o_output eq "afterstep") { # {{{
-	use File::Path;
+	require File::Path;
+	import File::Path qw(mkpath);
 	my $dir="$ENV{'HOME'}/GNUstep/Library/AfterStep/start";
 	if((-d "$dir")||(-f "$dir")) {
 		rmtree("$dir.old",0,0);
@@ -1213,13 +1222,6 @@
 	exit;
 }
 if($o_output eq "metisse") {
-	$icon_dir="$ENV{'HOME'}/.fvwm-metisse/icons";
-	if(! -d "$icon_dir") {
-		if(-f "$icon_dir") {
-			rename("$icon_dir","$icon_dir.old");
-		}
-		mkpath("$icon_dir",0,0700);
-	}
 	metisse($opt{strip},"", "metisse");
 	exit;
 }
@@ -1236,32 +1238,27 @@
 	aewm($opt{strip});
 	exit;
 }
-if($o_output eq "enlightenment") { # {{{
-	use File::Path;
+if($o_output eq "enlightenment") {
+	require File::Path;
+	import File::Path qw(mkpath);
 	$dir="$ENV{'HOME'}/.enlightenment/menus";
 	if((-d "$dir")||(-f "$dir")) {
 		rmtree("$dir.old",0,0);
 		rename("$dir","$dir.old");
 	}
 	mkpath("$dir",0,0700);	# or die
-	$icon_dir="$ENV{'HOME'}/.enlightenment/icons";
-	if(! -d "$icon_dir") {
-		if(-f "$icon_dir") {
-			rename("$icon_dir","$icon_dir.old");
-		}
-		mkpath("$icon_dir",0,0700);
-	}
 	enlightenment($opt{strip},"index","Enlightenment");
 	exit;
-} # }}}
+}
 if($o_output eq "xpde") { # {{{
-	use File::Path;
+	require File::Path;
+	import File::Path qw(mkpath);
 	my $dir="$ENV{'HOME'}/.xpde/Start Menu/Programs";
-	if((-d "$dir")||(-f "$dir")) {
+	if ( (-d $dir) or (-f $dir) ) {
 		rmtree("$dir.old",0,0);
-		rename("$dir","$dir.old");
+		rename($dir,"$dir.old");
 	}
-	mkpath("$dir",0,0700);
+	mkpath($dir,0,0700);
 	xpde($opt{strip},$dir);
 	exit;
 } # }}}
================================================================

---- CVS-web:
    http://cvs.pld-linux.org/vfmg/vfmg?r1=1.73.2.17&r2=1.73.2.18&f=u




More information about the pld-cvs-commit mailing list