use
5.006;
BEGIN {
$VERSION
=
'1.08'
;
}
sub
new {
my
$proto
=
shift
();
my
$class
=
ref
(
$proto
) ||
$proto
;
my
$self
= {};
bless
(
$self
,
$class
);
return
(
$self
);
}
sub
_debug {
my
$self
=
shift
();
my
$mesg
=
shift
() ||
'unknown msg'
;
my
$logfile
=
'/tmp/nautilus_debug.tmp'
;
if
(
open
(NAUTILUSLOGFILE,
">>"
.
$logfile
)) {
print
NAUTILUSLOGFILE
$mesg
.
"\n"
;
close
(NAUTILUSLOGFILE);
}
}
sub
_is_env {
my
$self
=
shift
();
return
(1)
unless
not
$ENV
{
'NAUTILUS_SCRIPT_SELECTED_FILE_PATHS'
}
and not
$ENV
{
'NAUTILUS_SCRIPT_SELECTED_URIS'
}
and not
$ENV
{
'NAUTILUS_SCRIPT_CURRENT_URI'
}
and not
$ENV
{
'NAUTILUS_SCRIPT_WINDOW_GEOMETRY'
};
return
(0);
}
sub
uri_unescape {
my
$self
=
shift
();
my
$str
=
shift
();
if
(
@_
&&
wantarray
) {
my
@str
= (
$str
,
@_
);
foreach
(
@str
) {
s/%([0-9A-Fa-f]{2})/
chr
(
hex
($1))/eg;
s!^\w+\://!!;
}
return
(
@str
);
}
$str
=~ s/%([0-9A-Fa-f]{2})/
chr
(
hex
($1))/eg
if
defined
$str
;
$str
=~ s!^\w+\://!!;
return
(
$str
);
}
sub
paths {
my
$self
=
shift
();
if
(
$self
->_is_env()) {
return
(
split
(/\n/,
$ENV
{
'NAUTILUS_SCRIPT_SELECTED_FILE_PATHS'
}))
unless
not
$ENV
{
'NAUTILUS_SCRIPT_SELECTED_FILE_PATHS'
};
my
@paths
= ();
foreach
my
$uri
(
$self
->uris()) {
my
$path
=
$uri
;
my
$desktop
=
$self
->_get_desktop_dir();
$path
=~ s!^x\-nautilus\-desktop\:///trash!
$ENV
{
'HOME'
}/.Trash!;
$path
=~ s!^x\-nautilus\-desktop\://!
$desktop
!;
push
(
@paths
,
$self
->uri_unescape(
$path
));
}
return
(
@paths
);
}
else
{
return
(0); }
}
sub
uris {
my
$self
=
shift
();
if
(
$self
->_is_env()) {
return
(
split
(/\n/,
$ENV
{
'NAUTILUS_SCRIPT_SELECTED_URIS'
}));
}
else
{
return
(0); }
}
sub
path {
my
$self
=
shift
();
return
(
'error'
)
unless
$self
->_is_env();
my
$URI
=
$ENV
{
'NAUTILUS_SCRIPT_CURRENT_URI'
} ||
''
;
my
$desktop
=
$self
->_get_desktop_dir();
$URI
=~ s!^x\-nautilus\-desktop\:///trash!
$ENV
{
'HOME'
}/.Trash!;
$URI
=~ s!^x\-nautilus\-desktop\://!
$desktop
!;
return
((
$self
->uri_unescape(
$URI
)||
$URI
));
}
sub
uri {
my
$self
=
shift
();
return
(
$ENV
{
'NAUTILUS_SCRIPT_CURRENT_URI'
})
if
$self
->_is_env();
return
(0);
}
sub
geometry {
my
$self
=
shift
();
if
(
$self
->_is_env()) {
return
($1,$2,$3,$4)
if
$ENV
{
'NAUTILUS_SCRIPT_WINDOW_GEOMETRY'
} =~ /(\d+)x(\d+)\+(\d+)\+(\d+)/;
}
else
{
return
(0,0,0,0); }
}
sub
_get_desktop_dir {
my
$self
=
shift
();
my
$desktop_dir
=
$ENV
{
'HOME'
} .
"/Desktop"
;
my
$gconf
= Gnome2::GConf::Client->get_default();
$desktop_dir
=
$ENV
{
'HOME'
}
if
$gconf
->get_bool(
'/apps/nautilus/preferences/desktop_is_home_dir'
);
}
else
{
my
$gconf_xml
=
$ENV
{
'HOME'
} .
'/.gconf/apps/nautilus/preferences/%gconf.xml'
;
if
( -r
$gconf_xml
) {
if
(
open
( GCONF,
"<"
.
$gconf_xml
) ) {
my
$RAW
=
undef
;
{
local
$/;
$RAW
= <GCONF>;
}
close
( GCONF );
if
(
$RAW
=~ m!\s+[^
"]+\"desktop_is_home_dir\"[^"
]+\
"\d*\"[^"
]+\"bool\"\svalue=\"false\"\>! ) {
$desktop_dir
=
$ENV
{
'HOME'
};
}
}
}
}
return
(
$desktop_dir
);
}
1;