RCombineArea* will detect the intersec geometry.
[wmaker-crm.git] / util / wkdemenu.pl
blobcd85f62087654521283a0f8b7bc436e55eb1fbc6
1 #!/usr/bin/perl
4 # kde2wmaker.pl:
7 # This script, made for users of Window Maker (http://windowmaker.org) is to
8 # be used along with KDE (http://www.kde.org).
11 # The default directory, ~/.kde/share/applnk/apps, will contain various
12 # sub-directories such as Development, Editors, Internet, etc. If for some
13 # reason, you wish to use an alternate (parent) directory that contains the
14 # various AppName.kdelnk files, it can be specified on the command line.
16 # The directory, if an alternate is specified, MUST be a parent directory to
17 # any/all sub-directories.
19 # Command line usage:
20 # -d <KDE App.kdelnk dir> -f <output menufile> -s yes (print to STDOUT)
22 # Example command with args:
23 # -d ~/.kde/share/applnk -f ~/.kde2wmaker.menu -s yes
25 # When the script is run, it will write out a proper Window Maker "External
26 # Menu" entry, that can be included in the menu. When the External Menu has
27 # been correctly configured, the root menu will display a sub-menu containing
28 # all of the KDE related items found. The script only needs to be run when/if
29 # KDE is updated.
32 # Installation and Configuration:
34 # 1) If /usr/bin/perl is not the location of the perl binary on your system,
35 # the first line should be changed to reflect upon it's location.
36 # 2) Run the script.
37 # 3) Configure Window Maker's menu by editing ~/GNUstep/Defaults/WMRootMenu
38 # This could be done with any text editor, or by using WPrefs. Insert
39 # the following line (if done with a text editor) into the WMRootMenu file.
40 # ("External Menu", OPEN_MENU, "$HOME/.kde2wmaker.menu"),
41 # If done using WPrefs, simply "Add External Menu" from the drop down menu,
42 # then type: $HOME/.kde2wmaker.menu into the "Menu Path/Directory List"
43 # textbox.
44 # 4) Some KDE entries, such as "Pine" will require a terminal to execute it.
45 # There is a terminal varable below. You may use any terminal, XTerm is the
46 # default. Any command line options such as: -fg -bg, etc. can be
47 # specified in this variable as well.
50 # Michael Hokenson - logan@dct.com
53 ###
54 ### Variables
55 ###
57 ### The External Menu file, this should NEVER point to the root menu file
58 $menufile = "$ENV{'HOME'}/.kde2wmaker.menu";
60 ### Base directory, location of all the KDE AppName.kdelnk files
61 $basedir = "$ENV{'HOME'}/.kde/share/applnk/apps";
63 ### Terminal to use
64 $term = "xterm";
66 ### Print to STDOUT, default is YES, a filename is specified
67 $stdout = 1;
70 ###
71 ### Begin work
72 ###
74 ### Process command line arguments
75 foreach $arg(@ARGV) {
76 if($last) {
77 if($last eq "-d") {
78 $basedir = $arg;
79 } elsif($last eq "-f") {
80 $menufile = $arg;
81 $stdout = 0;
83 undef($last);
84 } elsif($arg =~ /^-/) {
85 if($arg =~ /^-[dfs]$/) {
86 $last = $arg;
87 } else {
88 die("Unknown option: $arg\n\nUsage: kde2wmaker.pl\n\t-d <KDE App.kdelnk dir> [-f <output menufile>]\n");
89 &Usage;
94 ### Make sure we actually exist
95 if(-d $basedir) {
97 ### Start some error checking
98 $errors = 0;
100 ### See if there is an old menu file. If there is, rename it
101 unless($stdout) {
102 if(-e $menufile) {
103 print "\tFound $menufile, renaming\n\n";
104 rename $menufile, "$menufile.old";
108 ### Read in the directories
109 opendir(KDE,$basedir);
110 @dirs = readdir(KDE);
111 closedir(KDE);
113 ### Make sure there is actually something in $basedir
114 if($#dirs <= 1) {
115 print "ERROR:\n\tNothing found in $basedir\n\n";
116 exit(0);
119 ### Begin writing the menu
120 unless($stdout) {
121 open(MENUFILE,"> $menufile");
124 ### Start the main menu entry
125 if($stdout) {
126 print "\t\"KDE Applications\" MENU\n";
127 } else {
128 print MENUFILE "\t\"KDE Applications\" MENU\n";
131 ### Begin processing the directories
132 foreach $dir(@dirs) {
134 ### Handle each directory unless if its hidden (starts with .)
135 unless($dir =~ /^\./) {
136 ### Print out the sub directories
137 if($stdout) {
138 print "\t\t\"$dir\" MENU\n";
139 } else {
140 print MENUFILE "\t\t\"$dir\" MENU\n";
143 ### Look in each directory and process individual files
144 opendir(SUB,"$basedir/$dir");
145 @subdirs = readdir(SUB);
146 closedir(SUB);
148 ### Process files in each sub directory
149 foreach $sub(@subdirs) {
151 ### Once again, process all files but those that are hidden
152 unless($sub =~ /^\./) {
154 ### Open the files
155 open(SUB,"$basedir/$dir/$sub");
157 ### Search through the contents of the file
158 while($line = <SUB>) {
159 chop($line);
160 ### Grab the name
161 if($line =~ /^Name=/) {
162 $pname = $line;
163 $pname =~ s/Name=//;
165 ### Grab the command
166 if($line =~ /^Exec=/) {
167 $pargs = $line;
168 $pargs =~ s/Exec=//;
170 ### If Terminal=1, then we need to execute a term
171 if($line =~ /^Terminal=1$/) {
172 $pargs = "$term -T \"$pname\" -e $pargs";
176 close(SUB);
178 ### Some error checking on the Name and Exec
179 if($pname eq "") {
180 $pname = $sub;
181 $pname =~ s/\.kdelnk//;
183 if($pargs eq "") {
184 $error = 1;
185 $pargs = $sub;
186 $pargs =~ s/\.kdelnk//;
187 print "WARNING:\n\tNo Exec for $pname, using $pargs\n";
190 ### Begin printing menu items
191 if($stdout) {
192 print "\t\t\t\"$pname\" EXEC $pargs\n";
193 } else {
194 print MENUFILE "\t\t\t\"$pname\" EXEC $pargs\n";
199 ### Print the end of the sub menu
200 if($stdout) {
201 print "\t\t\"$dir\" END\n";
202 } else {
203 print MENUFILE "\t\t\"$dir\" END\n";
208 ### Finish off the main menu entry
209 if($stdout) {
210 print "\t\"KDE Applications\" END\n";
211 } else {
212 print MENUFILE "\t\"KDE Applications\" END\n";
215 unless($stdout) {
216 close(MENUFILE);
219 ### Yaya!
220 if($errors) {
221 print "\n.. Finished. There were errors.\n";
223 # else {
224 # print "\n.. Finished.\n";
227 exit(0);
228 } else {
229 ### Error out :/
230 print "ERROR:\n\t$basedir not found\n\tTry another directory.\n";
231 exit(0);
235 ### End work :))