~ubuntu-branches/ubuntu/intrepid/devscripts/intrepid-proposed

« back to all changes in this revision

Viewing changes to scripts/desktop2menu.pl

  • Committer: Bazaar Package Importer
  • Author(s): James Westby
  • Date: 2008-08-26 12:37:27 UTC
  • Revision ID: james.westby@ubuntu.com-20080826123727-n5598wuevitegu44
Tags: 2.10.26ubuntu11
* scripts/debcommit.pl:
  - Parse out the bug numbers and turn them into --fixes arguments
    for bzr commit. (LP: #261445)
    - http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=496643

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#! /usr/bin/perl -w
2
 
 
3
 
# desktop2menu: This program generates a skeleton menu file from a
4
 
# freedesktop.org desktop file
5
 
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.
14
 
#
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.
19
 
#
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.
23
 
 
24
 
=head1 NAME
25
 
 
26
 
desktop2menu - create a menu file skeleton from a desktop file
27
 
 
28
 
=head1 SYNOPSIS
29
 
 
30
 
B<desktop2menu> B<--help|--version>
31
 
 
32
 
B<desktop2menu> I<desktop file> [I<package name>]
33
 
 
34
 
=head1 DESCRIPTION
35
 
 
36
 
B<desktop2menu> generates a skeleton menu file from the supplied 
37
 
freedesktop.org desktop file.
38
 
 
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.
42
 
 
43
 
=head1 LICENSE
44
 
 
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 
47
 
package.
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.
51
 
 
52
 
=head1 AUTHOR
53
 
 
54
 
Sune Vuorela <debian@pusling.com> with modifications by Adam D. Barratt 
55
 
<adam@adam-barratt.org.uk>
56
 
 
57
 
=cut
58
 
 
59
 
use warnings;
60
 
use strict;
61
 
use Getopt::Long;
62
 
use File::Basename;
63
 
 
64
 
my $progname = basename($0);
65
 
 
66
 
BEGIN {
67
 
    # Load the File::DesktopEntry module safely
68
 
    eval { require File::DesktopEntry; };
69
 
    if ($@) {
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";
73
 
        }
74
 
        die "$progname: problem loading the File::DesktopEntry module:\n  $@\nHave you installed the libfile-desktopentry-perl package?\n";
75
 
    }
76
 
    import File::DesktopEntry;
77
 
}
78
 
 
79
 
use File::DesktopEntry;
80
 
 
81
 
# Big generic mapping between fdo sections and menu sections
82
 
my %mappings = (
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",
202
 
);
203
 
 
204
 
#values mentioned in Categories we accept as valid hints.
205
 
my %hintscategories = (
206
 
    "KDE" => "true",
207
 
    "Qt" => "true",
208
 
    "GNOME" => "true",
209
 
    "GTK" => "true",
210
 
);
211
 
 
212
 
my ($opt_help, $opt_version);
213
 
 
214
 
GetOptions("help|h" => \$opt_help,
215
 
           "version" => \$opt_version,
216
 
          )
217
 
    or die "Usage: $progname desktopfile packagename\nRun $progname --help for more details\n";
218
 
 
219
 
if ($opt_help) { help(); exit 0; }
220
 
if ($opt_version) { version(); exit 0; }
221
 
 
222
 
if (@ARGV == 0) {
223
 
    help();
224
 
    exit 0;
225
 
}
226
 
 
227
 
my $section;
228
 
my @hints;
229
 
my $needs;
230
 
my $warnings = 0;
231
 
 
232
 
my $filename = shift @ARGV;
233
 
my $file = File::DesktopEntry->new_from_file("$filename") ;
234
 
 
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';
238
 
 
239
 
my $package = join(' ', @ARGV);
240
 
if (!$package) {
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";
244
 
    $warnings++;
245
 
}
246
 
 
247
 
my $category = $file->get_value('Categories');
248
 
 
249
 
my @categories = reverse split(";", $category);
250
 
foreach (@categories ) {
251
 
    if ($mappings{$_} && ! $section) {
252
 
        $section = $mappings{$_};
253
 
    }
254
 
    if ($hintscategories{$_}) {
255
 
        push(@hints,$_);
256
 
    }   
257
 
}
258
 
 
259
 
die "Desktop file has invalid categories" unless $section;
260
 
 
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";
264
 
    $warnings++;
265
 
}
266
 
 
267
 
# Let's just pretend that the wm and the vc needs don't exist. 
268
 
if ($category =~ /ConsoleOnly/) {
269
 
    $needs = "text";
270
 
} else {
271
 
    $needs = "X11";
272
 
}
273
 
 
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";
282
 
print "\n";
283
 
 
284
 
# Unnecessary. but for clarity
285
 
exit 0;
286
 
 
287
 
sub help {
288
 
    print <<"EOF";
289
 
Usage: $progname [options] filename packagename
290
 
 
291
 
Valid options are:
292
 
   --help, -h             Display this message
293
 
   --version, -v          Display version and copyright info
294
 
EOF
295
 
}
296
 
 
297
 
sub version {
298
 
    print <<"EOF";
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>
302
 
 
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
306
 
later version.
307
 
EOF
308
 
}