#!/usr/bin/perl # Kyle Kienapfel (mage@shadowmage.org) # v0.5 # uhh uhh case insensitive sorting needs to be done some time, but not right now. # ^^^ Not Done Yet ^^^ # v0.4 # instead of .directory files gnome2 has /usr/share/gnome/vfolders/ # iconset support would be great, try to pull icons from a certain directory # instead of just checking absolute and /usr/share/pixmaps # after pissing around, the feature is in, kinda works, but practically useless for now. # it was a good idea! # note: Icon for Network Servers is in /usr/share/icons/gnome/48x48 not sure if i want to make this script # look in that pile too # v0.3 # something simple needs to be done about icons, not everything has an icon in # /usr/share/pixmaps # oh, OpenOffice specifies an absolute dir for its icons ;) # now all thats left is sub sub dirs like /usr/share/gnome/apps/Settings/Desktop # and maybe .directory icon support <--- Todo # v0.2 # separating this part into versions because I posted this on my website # /usr/share/applications is only part of the gnome apps, the rest are in # /usr/share/gnome/apps I haven't looked up/asked about these directories, # but I don't think looking in both will be of any issue # To do gnome/apps loop through the dir, loop through subdirs, maybe make the directory loop a function.. # * now uses $0 instead of icewm-menu-gnome2 to reference itself # # v0.1: the plan # script will be like icewm-menu-gnome1 but will take categories into consideration # course icewm-menu-gnome1 is in C/C++ and not by me $dir = "/usr/share/applications"; $gnome1dir = "/usr/share/gnome/apps"; $icondir = "/usr/share/pixmaps"; $vfolders = "/usr/share/gnome/vfolders"; $iconset = "/home/mage/temp/Aqua/16x16/apps"; #$iconset = ""; sub programs { my $folder = shift; #$folder = $_; #print "$folder\n"; my @programs = sort keys %{$progs{$folder}}; foreach (@programs) { #print $progs{$folder}{$_}[0] . "\n"; if($progs{$folder}{$_}[0] eq "folder") { print $progs{$folder}{$_}[1]; } else{ # this first one is for trying to make more things use the icon set, but since I'm testing a KDE iconset I dont think # thats gunna happen ;) if(-e ("$iconset/".$progs{$folder}{$_}[2].".png")) { $icon="$iconset/".$progs{$folder}{$_}[2].".png"; } elsif(-e $progs{$folder}{$_}[1]) { $icon = $progs{$folder}{$_}[1]; } elsif(-e ("$iconset/".$progs{$folder}{$_}[1])) { $icon="$iconset/".$progs{$folder}{$_}[1]; } else { $icon= "$icondir/" . $progs{$folder}{$_}[1]; } print "prog \"$_\" $icon $0 --open \"" . $progs{$folder}{$_}[0] . "\"\n"; } } } sub dodir ($subdir) { #print "$subdir\n"; # gotta do a dir yayfun! undef @SUBFILES; opendir(DIR, $subdir); # || die ("$dir: $!\n"); my @SUBFILES = readdir(DIR); closedir(DIR); @SUBFILES = sort(@SUBFILES); foreach(@SUBFILES) { my $phile=$_; # if (-d "$subdir/$phile") { #print "$subdir/$phile is \n"; # } if(!/^\./ && !-d "$subdir/$phile") { #print "$_\n"; open(PROG, "$subdir/$phile"); @phyl = ; close(PROG); $name=""; $cats=""; $icon=""; $cat="beer"; # Grab information from the file foreach (@phyl) { #print $_; if($_=~/Name=(.*)/) { $name=$1; } if($_=~/Categories=(.*)/) { $cats=$1; } if($_=~/Icon=(.*)/) { $icon=$1; } if($_=~/^Exec=(.*)/) { $exec=$1; } } # end foreach @phyl #print "$name $icon"; $folders{$subcat} = $name; $progs{$subcat}{$name} = [ $subdir . "/" . $phile, $icon,$exec]; } # end if no dot nor a dir if(!/^\./ && -d "$subdir/$phile") { #print "$subdir $phile $subcat\n"; dosubdir($subdir,$phile,$subcat); } } # end subfiles loop } # end dodir function sub dosubdir (@_) { my ($dir,$sub,$cat) = @_; #print "$dir $sub $cat\n"; my $subdir = "$dir/$sub"; my %stuff; #print "$subdir\n"; # gotta do a dir yayfun! #undef @SUBFILES; opendir(DIR, $subdir); # || die ("$dir: $!\n"); my @SUBFILES = readdir(DIR); closedir(DIR); @SUBFILES = sort(@SUBFILES); foreach(@SUBFILES) { my $phile=$_; # if (-d "$subdir/$phile") { #print "$subdir/$phile is dir"; # } if(!/^\./ && !-d "$subdir/$phile") { #print "$_\n"; open(PROG, "$subdir/$phile"); @phyl = ; close(PROG); $name=""; $cats=""; $icon=""; # Grab information from the file foreach (@phyl) { #print $_; if($_=~/Name=(.*)/) { $name=$1; } if($_=~/Categories=(.*)/) { $cats=$1; } if($_=~/Icon=(.*)/) { $icon=$1; } if($_=~/^Exec=(.*)/) { $exec=$1; } } # end foreach @phyl #print "$name $icon"; # $folders{$subcat} = $name; # $progs{$subcat}{$name} = [ $subdir . "/" . $phile, $icon]; $stuff{$name} = [ $subdir . "/" . $phile, $icon,$exec]; } # end if no dot nor a dir if(!/^\./ && -d "$subdir/$phile") { dosubdir($subdir,$phile,$subcat); } } # end subfiles loop my @keys = sort keys %stuff; if (-e "$subdir/.directory") { open(PROG, "$subdir/.directory"); my @phyl = ; close(PROG); foreach (@phyl) { if($_=~/Name=(.*)/) { $name=$1; } # if($_=~/Categories=(.*)/) { $cats=$1; } if($_=~/Icon=(.*)/) { $icon=$1; } } # end foreach @phyl if(-e $icon) {} elsif(-e "$icondir/$icon") { $icon = "$icondir/$icon"; } else { $icon="folder"; } } else { $name = $sub; $icon = "folder"; } my $temp = "menu \"$name\" \"$icon\" {\n"; foreach (@keys) { if (-e $stuff{$_}[1]) { $icon = $stuff{$_}[1]; } else { $icon = "$icondir/" . $stuff{$_}[1]; } $temp .= "prog \"$_\" \"$icon\" $0 --open " . $stuff{$_}[0]. "\n"; } $temp .= "}\n"; #print $cat.$sub.$temp; $progs{$cat}{$sub} = ["folder",$temp,"plx"]; #print $prog{$cat}{$sub}[0]; } #end dosubdir function #print $ARGV[0];exit; #$opening = "/usr/share/applications/gedit.desktop"; if ($ARGV[0] eq "--open") { $opening = $ARGV[1]; } if ($ARGV[0] eq "--list") { $dir = $ARGV[1]; } if ($opening ne "") { open(PROG, "$opening"); @file = ; close (PROG); foreach (@file) { if($_=~/^Exec=(.*)/) { $exec=$1; } #if($_=~/Categories=(.*)/) { $cats=$1; } #if($_=~/Icon=(.*)/) { $icon=$1; } } #print "$exec\n"; exec("$exec\&"); exit; } else { %folders = (); # sub blah($dir) opendir(DIR, $dir) || die ("$dir: $!\n"); my @FILES = readdir(DIR); closedir(DIR); @FILES = sort(@FILES); foreach(@FILES) { $phile = $_; if(!/^\./) { open(PROG, "$dir/$phile"); @phyl = ; close(PROG); $name=""; $cats=""; $icon=""; $cat="beer"; # Grab information from the file foreach (@phyl) { if($_=~/Name=(.*)/) { $name=$1; } if($_=~/Categories=(.*)/) { $cats=$1; } if($_=~/Icon=(.*)/) { $icon=$1; } if($_=~/^Exec=(.*)/) { $exec=$1; } } # Process categories @categories = split/\;/,$cats; foreach(@categories) { if ((/Application/) || (/GNOME/)) {} elsif ($cat eq "beer") { $cat = $_; } #else { print "$_"; } } $folders{$cat} = $name; $progs{$cat}{$name} = [ $dir . "/" . $phile, $icon,$exec]; # to act like icewm-menu-gnome1 :) #print "prog \"$name\" $icondir/$icon icewm-menu-gnome1 --open \"$dir/$phile\n"; } # if(!/^\./) { } # for loop for files # end sub marker for directory processing # dir process gnome, do the translation below, then process the gnome/apps subdirs # Question: what if theres like gnome/apps/Internet/IRC/Xchat? hmm? # if everything was in gnome/apps the script could be a simple recursive loop :) # Category name translation foreach my $key (keys %folders) { if ($key eq "AudioVideo") { delete $folders{AudioVideo}; $folders{"Multimedia"} = "touch me"; $data = delete $progs{AudioVideo}; $progs{Multimedia} = $data; } if ($key eq "Game") { delete $folders{Game}; $folders{"Games"} = "1"; $progs{Games} = delete $progs{Game}; } if ($key eq "Utility") { delete $folders{Utility}; $folders{Accessories} = "1"; $progs{Accessories} = delete $progs{Utility}; } # For some stupid reason X-Chat 2 is stuck under Network in its .desktop file # This is a better way of moving things around if ($key eq "Network") { delete $folders{Network}; $folders{"Internet"} = "1"; my @trogdor = sort keys %{$progs{Network}}; foreach (@trogdor) {$progs{Internet}{$_} = $progs{Network}{$_};} } if ($key eq "Development") { delete $folders{Development}; $folders{Programming} = "1"; my @trogdor = sort keys %{$progs{Development}}; foreach (@trogdor) {$progs{Programming}{$_} = $progs{Development}{$_};} } } if(-e $gnome1dir) { opendir(DIR, "$gnome1dir"); # || die ("$dir: $!\n"); my @FILES = readdir(DIR); closedir(DIR); @FILES = sort(@FILES); foreach(@FILES) { $subdir = "$gnome1dir/$_"; $subcat=$_; if(!/^\./) { if (-d $subdir) { &dodir($subdir); } # end if a dir } # end if no dot in subdir } # end foreach FILES #exit; } # end if $gnome1dir exists # start printing it out @foldars = sort keys %folders; foreach (@foldars) { my $folder = $_; # "Core" stuff goes at the bottom of all this, just so it looks like gnome-panel's menu if($folder eq "Core") { next; } $dotdir = "sex"; if (-e "$vfolders/$folder.directory") { $dotdir = "$vfolders/$folder.directory"; } elsif(-e "$gnome1dir/$folder/.directory") { $dotdir = "$gnome1dir/$folder/.directory"; } if ($dotdir ne "sex") { open(PROG, "$dotdir"); my @phyl = ; close(PROG); foreach (@phyl) { if($_=~/Name=(.*)/) { $name=$1; } if($_=~/Categories=(.*)/) { $cats=$1; } if($_=~/Icon=(.*)/) { $icon=$1; } } # end foreach @phyl if(-e $icon) {} elsif(-e "$icondir/$icon") { $icon = "$icondir/$icon"; } else { $icon="folder"; } } else { $name = $folder; $icon = "folder"; } #print "menu $folder folder {\n"; print "menu \"$folder\" $icon {\n"; programs($folder); #programs("OpenOffice.org"); print "}\n"; } programs("Core"); } # end if for doing a list