#!/usr/bin/perl -w # kde2wm.pl v15.06.1999, written by Gernot Tenchio # http://jusa.telco-tech.de/kde2wm.html - # # Some improvements by Matthew Gabeler-Lee... # f.e. Apps running in Terminals # # # kde2wm.pl is licensed under the GPL version 2. # kde2wm.pl is Copyright (C) 1999 by Gernot Tenchio # use strict; my $menuname='KDE Menu'; ## the menuname my $terminalprog = 'wterm'; ## the preferred terminalprogram ## (to run apps in terminal) my ($kderoot); my $DEBUG=0; if (defined $ARGV[0]) { -d "$ARGV[0]/share/applnk" || die "Usage: $0 kdedir"; $kderoot=$ARGV[0]; } else { $kderoot=($ENV{KDEDIR} or "/usr"); } $DEBUG && print "using $kderoot as kderoot"; my $kdedir = "/usr/share/applnk"; ## where the kdefiles reside my $lang=($ENV{LANG} or "C"); my $style='wmaker_gen'; # $home=$ENV{HOME}; if ($lang=~/^([^_]+)_.*/) { $lang=$1 } ## in case of de_DE ## kde variables # %a - complete name # %f - filename # %d - parent directory # %c - translated name of the application # %u - url sub write_item { my ($kdelnk,$name,$cnt) = @_; my $command=""; my $locale=""; my $interm=0; my $termopts=""; open F,$kdelnk or die "Arrgh! Can\'t open $kdelnk"; my @contents = ; foreach my $i(@contents) { if ($i=~/(^[Nn]ame)=(.*)/) { $name=$2 } if ($i=~/(^[Ee]xec)=(.*)/) { $command=$2 } if ($i=~/(^[Nn]ame\[$lang\])=(.*)/) { $locale=$2 } if ($i=~/(^[Tt]erminal)=(.*)/) { $interm=$2 } if ($i=~/(^[Tt]erminal[Oo]ptions)=(.*)/) { $termopts=$2 } } if ($locale ne "") { $name = $locale } $command=~s/\%c/$name/; $command=~s/\%[^\s]+\s*//g; # remove unused variables if ($interm eq "1") { $command=$terminalprog . " " . $termopts . " -e " . $command } if ($style eq "wmaker_gen") { print "\n$cnt\"$name\" EXEC $command"; } elsif ($style eq "wmaker_root") { print ",\n$cnt(\"$name\", EXEC,\"$command\")"; } else { die "unsupportet menuformat!"; } close F; } sub open_menu { my ($name,$cnt) = @_; if ($style eq "wmaker_gen") { print "\n$cnt\"$name\" MENU"; } elsif ($style eq "wmaker_root") { if ($cnt eq "") { print "(\"$name\""; } else { print ",\n$cnt(\"$name\""; } } else { die "unsupportet Fileformat !"; } } sub close_menu { my ($name,$cnt) = @_; if ($style eq "wmaker_gen") { print "\n$cnt\"$name\" END"; } elsif ($style eq "wmaker_root") { print "\n$cnt)"; } else { die "unsupportet Fileformat !"; } } sub read_dir { my ($dir,$cnt) = @_; my $locale = ""; opendir D,$dir or die "$dir not found"; my @contents = grep !/^\.+?$/,readdir D; closedir D; foreach my $item (sort @contents) { my $fullitem = "$dir/$item"; -d $fullitem or next; if (open DD, "$fullitem/.directory") { my @contents=(
); $locale=""; foreach my $i(@contents) { if ($i=~/(^[Nn]ame)=(.*)/) { $item=$2 } if ($i=~/(^[Nn]ame\[$lang\])=(.*)/) { $locale=$2 } } if ($locale ne "") { $item = $locale } close DD; } open_menu($item,$cnt); read_dir($fullitem,$cnt." "); close_menu($item,$cnt); } foreach my $item (sort @contents) { my $fullitem = "$dir/$item"; $fullitem=~/\.desktop$/ or next; write_item($fullitem,$item,$cnt); } } open_menu("$menuname",""); read_dir($kdedir," "); close_menu("$menuname",""); print "\n";