3
# desktop2menu: This program generates a skeleton menu file from a
4
# freedesktop.org desktop file
6
# Written by Sune Vuorela <debian@pusling.com>
7
# Modifications by Adam D. Barratt <adam@adam-barratt.org.uk>
8
# Copyright 2007 Sune Vuorela <debian@pusling.com>
9
# Modifications Copyright 2007 Adam D. Barratt <adam@adam-barratt.org.uk>
10
# This program is free software; you can redistribute it and/or modify
11
# it under the terms of the GNU General Public License as published by
12
# the Free Software Foundation; either version 2 of the License, or
13
# (at your option) any later version.
15
# This program is distributed in the hope that it will be useful,
16
# but WITHOUT ANY WARRANTY; without even the implied warranty of
17
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
# GNU General Public License for more details.
20
# You should have received a copy of the GNU General Public License along
21
# with this program; if not, write to the Free Software Foundation, Inc.,
22
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26
desktop2menu - create a menu file skeleton from a desktop file
30
B<desktop2menu> B<--help|--version>
32
B<desktop2menu> I<desktop file> [I<package name>]
36
B<desktop2menu> generates a skeleton menu file from the supplied
37
freedesktop.org desktop file.
39
The package name to be used in the menu file may be passed as an additional
40
argument. If it is not supplied then B<desktop2menu> will attempt to derive
41
the package name from the data in the desktop file.
45
This program is Copyright (C) 2007 by Sune Vuorela <debian@pusling.com>. It
46
was modified by Adam D. Barratt <adam@adam-barratt.org.uk> for the devscripts
48
This program comes with ABSOLUTELY NO WARRANTY.
49
You are free to redistribute this code under the terms of the GNU
50
General Public License, version 2 or later.
54
Sune Vuorela <debian@pusling.com> with modifications by Adam D. Barratt
55
<adam@adam-barratt.org.uk>
64
my $progname = basename($0);
67
# Load the File::DesktopEntry module safely
68
eval { require File::DesktopEntry; };
70
my $progname = basename $0;
71
if ($@ =~ /^Can\'t locate File\/DesktopEntry\.pm/) {
72
die "$progname: you must have the libfile-desktopentry-perl package installed\nto use this script\n";
74
die "$progname: problem loading the File::DesktopEntry module:\n $@\nHave you installed the libfile-desktopentry-perl package?\n";
76
import File::DesktopEntry;
79
use File::DesktopEntry;
81
# Big generic mapping between fdo sections and menu sections
83
"AudioVideo" => "Applications/Video",
84
"Audio" => "Applications/Sound",
85
"Video" => "Applications/Video",
86
"Development" => "Applications/Programming",
87
"Education" => "Applications/Education",
88
"Game" => "Games!WARN",
89
"Graphics" => "Applications/Graphics!WARN",
90
"Network" => "Applications/Network!WARN",
91
"Office" => "Applications/Office",
92
"System" => "Applications/System/Administration",
93
"Utility" => "Applications!WARN",
94
"Building" => "Applications/Programming",
95
"Debugger" => "Applications/Programming",
96
"IDE" => "Applications/Programming",
97
"Profiling" => "Applications/Programming",
98
"RevisionControl" => "Applications/Programming",
99
"Translation" => "Applications/Programming",
100
"Calendar" => "Applications/Data Management",
101
"ContactManagement" => "Applications/Data Management",
102
"Database" => "Applications/Data Management",
103
"Dictionary" => "Applications/Text",
104
"Chart" => "Applications/Office",
105
"Email" => "Applications/Network/Communication",
106
"Finance" => "Applications/Office",
107
"FlowChart" => "Applications/Office",
108
"PDA" => "Applications/Mobile Devices",
109
"ProjectManagement" => "Applications/Project Management",
110
"Presentation" => "Applications/Office",
111
"Spreadsheet" => "Applications/Office",
112
"Wordprocessor" => "Applications/Office",
113
"2DGraphics" => "Applications/Graphics",
114
"VectorGraphics" => "Applications/Graphics",
115
"RasterGraphics" => "Applications/Graphics",
116
"3DGraphics" => "Applications/Graphics",
117
"Scanning" => "Applications/Graphics",
118
"OCR" => "Applications/Text",
119
"Photography" => "Applications/Graphics",
120
"Publishing" => "Applications/Office",
121
"Viewer" => "Applications/Viewers",
122
"TextTools" => "Applications/Text",
123
"DesktopSettings" => "Applications/System/Administration",
124
"HardwareSettings" => "Applications/System/Hardware",
125
"Printing" => "Applications/System/Administration",
126
"PackageManager" => "Applications/System/Package Management",
127
"Dialup" => "Applications/System/Administration",
128
"InstantMesasging" => "Applications/Network/Communication",
129
"Chat" => "Applications/Network/Communication",
130
"IRCClient" => "Applications/Nework/Communication",
131
"FileTransfer" => "Applications/Network/File Transfer",
132
"HamRadio" => "Applications/Amateur Radio",
133
"News" => "Applicatiosn/Network/Web News",
134
"P2P" => "Applications/File Transfer",
135
"RemoteAccess" => "Applications/System/Administration",
136
"Telephony" => "Applications/Network/Communication",
137
"TelephonyTools" => "Applications/Network/Communication",
138
"VideoConference" => "Applications/Network/Communication",
139
"Midi" => "Applications/Sound",
140
"Mixer" => "Applications/Sound",
141
"Sequencer" => "Applications/Sound",
142
"Tuner" => "Applications/TV and Radio",
143
"TV" => "Applications/TV and Radio",
144
"AudioVideoEditing" => "Applications/Video!WARN",
145
"Player" => "Applications/Video!WARN",
146
"Recorder" => "Applications/Video!WARN",
147
"DiscBurning" => "Applications/File Management",
148
"ActionGame" => "Games/Action",
149
"AdventureGame" => "Games/Adventure",
150
"ArcadeGame" => "Games/Action",
151
"BoardGame" => "Games/Board",
152
"BlocksGame" => "Games/Blocks",
153
"CardGame" => "Games/Card",
154
"KidsGames" => "Games/Toys!WARN",
155
"LogicGames" => "Games/Puzzles",
156
"RolePlaying" => "Games/Adventure",
157
"Simulation" => "Games/Simulation",
158
"SportsGame" => "Games/Action",
159
"StrategyGame" => "Games/Strategy",
160
"Art" => "Applications/Education",
161
"Construction" => "Applications/Education",
162
"Music" => "Applications/Education",
163
"Languages" => "Applications/Education",
164
"Science" => "Applications/Science!WARN",
165
"ArtificialIntelligence" => "Applications/Science!WARN",
166
"Astronomy" => "Applications/Science/Astronomy",
167
"Biology" => "Applications/Science/Biology",
168
"Chemistry" => "Applications/Science/Chemistry",
169
"ComputerScience" => "Applications/Science/Electronics!WARN",
170
"DataVisualization" => "Applications/Science/Data Analysis",
171
"Economy" => "Applications/Office",
172
"Electricity" => "Applications/Science/Engineering",
173
"Geography" => "Applications/Science/Geoscience",
174
"Geology" => "Applications/Science/Geoscience",
175
"Geoscience" => "Applications/Science/Geoscience",
176
"History" => "Applications/Science/Social",
177
"ImageProcessing" => "Applications/Graphics",
178
"Literature" => "Applications/Data Management",
179
"Math" => "Applications/Science/Mathematics",
180
"NumericalAnalyzisis" => "Applications/Science/Mathematics",
181
"MedicalSoftware" => "Applications/Science/Medicine",
182
"Physics" => "Applications/Science/Physics",
183
"Robotics" => "Applications/Science/Engineering",
184
"Sports" => "Games/Tools!WARN",
185
"ParallelComputing" => "Applications/Science/Electronics!WARN",
186
"Amusement" => "Games/Toys",
187
"Archiving" => "Applications/File Management",
188
"Compression" => "Applications/File Management",
189
"Electronics" => "Applications/Science/Electronics",
190
"Emulator" => "Applications/Emulators",
191
"Engineering" => "Applications/Science/Engineering",
192
"FileTools" => "Applications/File Management",
193
"FileManager" => "Applications/File Management",
194
"TerminalEmulator" => "Applications/Shells",
195
"Filesystem" => "Applications/System/Administration",
196
"Monitor" => "Applications/System/Monitoring",
197
"Security" => "Applications/System/Security",
198
"Accessibility" => "Applications/Accessibility",
199
"Calculator" => "Applications/Science/Mathematics",
200
"Clock" => "Games/Toys",
201
"TextEditor" => "Applications/Editors",
204
#values mentioned in Categories we accept as valid hints.
205
my %hintscategories = (
212
my ($opt_help, $opt_version);
214
GetOptions("help|h" => \$opt_help,
215
"version" => \$opt_version,
217
or die "Usage: $progname desktopfile packagename\nRun $progname --help for more details\n";
219
if ($opt_help) { help(); exit 0; }
220
if ($opt_version) { version(); exit 0; }
232
my $filename = shift @ARGV;
233
my $file = File::DesktopEntry->new_from_file("$filename") ;
235
# do menu files for non-applications make sense?
236
die $file->get_value('Name') . " isn't an application\n"
237
unless $file->get_value('Type') eq 'Application';
239
my $package = join(' ', @ARGV);
241
# Bad guess, but... maybe icon name could be better?
242
$package = $file->get_value('Name');
243
print STDERR "WARNING: Package not specified. Guessing package as: $package\n";
247
my $category = $file->get_value('Categories');
249
my @categories = reverse split(";", $category);
250
foreach (@categories ) {
251
if ($mappings{$_} && ! $section) {
252
$section = $mappings{$_};
254
if ($hintscategories{$_}) {
259
die "Desktop file has invalid categories" unless $section;
261
# Not all mappings are completely accurate. Most are, but...
262
if ($section =~ /!WARN/) {
263
print STDERR "WARNING: Section is highly inaccurate. Please check it manually\n";
267
# Let's just pretend that the wm and the vc needs don't exist.
268
if ($category =~ /ConsoleOnly/) {
274
print "\n" if $warnings > 0;
275
print "?package(" . $package . "): \\\n";
276
print "\tneeds=\"" . $needs . "\" \\\n";
277
print "\tsection=\"" . $section . "\" \\\n";
278
print "\ttitle=\"" . $file->get_value('Name') . "\" \\\n";
279
print "\thints=\"" . join(",", @hints) . "\" \\\n" if @hints;
280
print "\tcommand=\"" . $file->get_value('Exec') . "\" \\\n";
281
print "\ticon=\"/usr/share/pixmaps/" . $file->get_value('Icon') . ".xpm\" \\\n";
284
# Unnecessary. but for clarity
289
Usage: $progname [options] filename packagename
292
--help, -h Display this message
293
--version, -v Display version and copyright info
299
This is $progname, from the Debian devscripts package, version ###VERSION###
300
Copyright (C) 2007 by Sune Vuorela <debian\@pusling.com>.
301
Modifications copyright (C) 2007 by Adam D. Barratt <adam\@adam-barratt.org.uk>
303
This program comes with ABSOLUTELY NO WARRANTY.
304
You are free to redistribute this code under the terms of the
305
GNU General Public License, version 2, or (at your option) any