/usr/bin/perlpanel-item-edit is in perlpanel 1:0.9.1+cvs20051225-2ubuntu1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 | #!/usr/bin/perl
# $Id: perlpanel-item-edit,v 1.8 2005/04/12 13:43:43 jodrell Exp $
# This file is part of PerlPanel.
#
# PerlPanel is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# PerlPanel is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with PerlPanel; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# Copyright: (C) 2005 Gavin Brown <gavin.brown@uk.com>
#
use Gtk2 -init;
use Gtk2::GladeXML;
use X11::FreeDesktop::DesktopEntry;
use Gnome2::VFS;
use File::Basename qw(basename);
use XML::Simple;
use POSIX qw(setlocale);
use Locale::gettext;
use strict;
my $REQUIRED_VERSION = 0.04;
die("X11::FreeDesktop::DesktopEntry must be at least $REQUIRED_VERSION") unless ($X11::FreeDesktop::DesktopEntry::VERSION >= $REQUIRED_VERSION);
my $PREFIX = (-e '/usr' ? '/usr' : $ENV{PWD});
my $GLADE = sprintf('%s/share/perlpanel/glade/item-editor.glade', $PREFIX);
$XML::Simple::PREFERRED_PARSER = 'XML::Parser';
my $RCFILE = sprintf('%s/.perlpanelrc', $ENV{HOME});
my $LOCALE = (defined($ENV{LC_MESSAGES}) ? $ENV{LC_MESSAGES} : $ENV{LANG});
setlocale(LC_ALL, $LOCALE);
bindtextdomain('perlpanel', sprintf('%s/share/locale', $PREFIX));
textdomain('perlpanel');
my $ICON_THEME;
if (-r $RCFILE) {
$ICON_THEME = XMLin($RCFILE)->{panel}->{icon_theme};
}
$ICON_THEME = 'gnome' if ($ICON_THEME eq '');
my ($ICON);
Gnome2::VFS->init;
my $theme = Gtk2::IconTheme->new;
$theme->append_search_path(sprintf('%s/share/icons', $PREFIX));
$theme->set_custom_theme($ICON_THEME);
my $uri = Gnome2::VFS->make_uri_canonical($ARGV[0]);
my ($result, undef) = Gnome2::VFS->get_file_info($uri, 'default');
error_dialog(_("Error opening '{uri}': {result}", uri => $uri, result => $result)) if ($result ne 'ok');
my ($result, $size, $data) = Gnome2::VFS->read_entire_file($uri);
error_dialog(_("Error reading '{uri}': {result}", uri => $uri, result => $result)) if ($result ne 'ok');
my $entry = X11::FreeDesktop::DesktopEntry->new_from_data($data);
error_dialog(_("Error parsing '{uri}'", uri => $uri)) if (!defined($entry));
my $glade = Gtk2::GladeXML->new($GLADE);
$glade->get_widget('launcher_name')->set_text($entry->Name($LOCALE));
$glade->get_widget('launcher_comment')->set_text($entry->Comment($LOCALE));
$glade->get_widget('launcher_exec')->set_text($entry->Exec);
$ICON = $entry->Icon;
if (-r $ICON) {
$glade->get_widget('launcher_icon')->set_from_pixbuf(Gtk2::Gdk::Pixbuf->new_from_file_at_size($ICON, 48, 48));
} else {
my $icon;
if ($ICON ne '' && -r $ICON) {
$icon = $theme->load_icon($ICON, 48, 'force-svg');
}
if (defined($icon)) {
$glade->get_widget('launcher_icon')->set_from_pixbuf($icon);
} else {
$glade->get_widget('launcher_icon')->set_from_pixbuf($glade->get_widget('item_edit_dialog')->render_icon('gtk-missing-image', 'dialog'));
}
}
$glade->get_widget('launcher_feedback')->set_active($entry->StartupNotify);
$glade->signal_autoconnect_from_package('main');
my $window_icon = $theme->load_icon('perlpanel', 48, 'force-svg');
$glade->get_widget('item_edit_dialog')->set_icon($window_icon);
$glade->get_widget('item_edit_dialog')->show_all;
Gtk2->main;
### Begin auto-generated signal handlers
# Widgets calling the 'on_icon_button_clicked' callback:
#
# Widget ID: icon_button
# Widget Type: GtkButton
# Signal: clicked
#
sub on_icon_button_clicked {
my $selector = Gtk2::FileChooserDialog->new(
_('Choose File'),
undef,
'open',
'gtk-cancel' => 'cancel',
'gtk-ok' => 'ok'
);
$selector->set_preview_widget(Gtk2::Image->new);
$selector->signal_connect('selection-changed', sub {
my $file = $selector->get_filename;
if (-f $file) {
my $pbf = Gtk2::Gdk::Pixbuf->new_from_file_at_size($file, 48, 48);
$selector->get_preview_widget->set_from_pixbuf($pbf) if (defined($pbf));
}
});
if (-r $ICON) {
$selector->set_filename($ICON);
} else {
my $icon;
if ($ICON ne '') {
$icon = $theme->lookup_icon($ICON, 48, 'force-svg');
}
if (defined($icon)) {
$selector->set_filename($icon->get_filename);
} else {
$selector->set_current_folder('/usr/share/icons/hicolor/48x48/apps');
}
}
$selector->signal_connect('response', sub {
if ($_[1] eq 'ok') {
$ICON = $selector->get_filename;
$glade->get_widget('launcher_icon')->set_from_pixbuf(Gtk2::Gdk::Pixbuf->new_from_file_at_size($ICON, 48, 48));
}
$selector->destroy;
});
$selector->set_icon($glade->get_widget('item_edit_dialog')->get_icon);
$selector->show_all;
return 1;
}
# Widgets calling the 'on_item_edit_dialog_response' callback:
#
# Widget ID: item_edit_dialog
# Widget Type: GtkDialog
# Signal: response
#
sub on_item_edit_dialog_response {
if ($_[1] eq 'ok') {
$entry->set_value('Name', $glade->get_widget('launcher_name')->get_text, $LOCALE);
$entry->set_value('Comment', $glade->get_widget('launcher_comment')->get_text, $LOCALE);
$entry->set_value('Exec', $glade->get_widget('launcher_exec')->get_text);
$entry->set_value('Icon', $ICON);
$entry->set_value('StartupNotify', ($glade->get_widget('launcher_feedback')->get_active ? 'true' : 'false'));
my $data = $entry->as_string;
$glade->get_widget('item_edit_dialog')->set_sensitive(0);
Gtk2->main_iteration while (Gtk2->events_pending);
my ($result, $handle) = Gnome2::VFS->open($uri, 'write');
error_dialog(_("Error writing to '{uri}': {error}", uri => $uri, error => $result)) if ($result ne 'ok');
$handle->write($data, length($data));
$handle->close;
}
Gtk2->main_quit;
exit 0;
}
sub error_dialog {
my $error = shift;
my $dialog = Gtk2::MessageDialog->new(
undef,
'modal',
'error',
'ok',
$error,
);
$dialog->signal_connect('response', sub { exit 1 });
$dialog->signal_connect('delete_event', sub { exit 1 });
$dialog->run;
}
# copied from PerlPanel.pm:
sub _ {
my $str = shift;
my %params = @_;
my $translated = gettext($str);
if (scalar(keys(%params)) > 0) {
foreach my $key (keys %params) {
$translated =~ s/\{$key\}/$params{$key}/g;
}
}
return $translated;
}
|