Dialog/Backend/Nautilus.pm

filter: Statementstmt 29.8% 31 / 104 Branchbran 2.7% 1 / 36 Conditioncond 6.5% 3 / 46 MC/DCmcdc 0.0% 0 / 27 Subroutinesub 50.0% 9 / 18 Podpod 100% 7 / 7 totaltotal 21.4% 51 / 238 CC 39 SCAR 43.2
CC
39
Cov
19%
_get_desktop_dir
240.0
_is_env
30.0
uri_unescape
30.0
CRAP 74.9
« Dialog/Backend/KDialog.pm ↑ Summary Dialog/Screen/Menu.pm »
1 package UI::Dialog::Backend::Nautilus;
2 ###############################################################################
3 # Copyright (C) 2004-2016 Kevin C. Krinke <kevin@krinke.ca>
4 #
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License, or (at your option) any later version.
9 #
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 ###############################################################################
19 1 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 ▶use UI::Dialog::Backend;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 1 ▶use FileHandle;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 BEGIN {
27 1 ▶ use vars qw( $VERSION @ISA );
Subroutine BEGIN: called CC=1 SCAR=0.0
28 1 ▶ @ISA = qw( UI::Dialog::Backend );
Subroutine BEGIN: called CC=1 SCAR=0.0
29 1 $VERSION = '1.20';
30 }
31  
32 sub new {
33 1 ▶ my $proto = shift();
Subroutine new: called CC=5 SCAR=18.9
Pod documented
34 1 ▶ my $class = ref($proto) || $proto;
Condition33%1/3
ref $proto || $proto
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
35 1 my $self = {};
36 1 bless($self, $class);
37 1 ▶ $self->{'_opts'}->{'bin'} ||= $self->_find_bin('nautilus');
Condition33%1/3
$self->{"_opts"}{"bin"} ||= $self->_find_bin("nautilus")
l!l&&r!l&&!r
001
MC/DC0%0/2
$self->{"_opts"}{"bin"} ||= $self->_find_bin("nautilus")
$self->{"_opts"}{"bin"} $self->_find_bin("nautilus")
Truth table33%1/3
A ||= B
A= $self->{"_opts"}{"bin"}B= $self->_find_bin("nautilus")
ABresult
1X1
011
000
38 1 ▶ $self->{'_opts'}->{'bin'} ||= $self->_find_bin('caja');
Condition33%1/3
$self->{"_opts"}{"bin"} ||= $self->_find_bin("caja")
l!l&&r!l&&!r
001
MC/DC0%0/2
$self->{"_opts"}{"bin"} ||= $self->_find_bin("caja")
$self->{"_opts"}{"bin"} $self->_find_bin("caja")
Truth table33%1/3
A ||= B
A= $self->{"_opts"}{"bin"}B= $self->_find_bin("caja")
ABresult
1X1
011
000
39 1 ▶ unless (-x $self->{'_opts'}->{'bin'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-x $self->{"_opts"}{"bin"}) 1 0 1
40 1 croak("the nautilus binary could not be found at: ".$self->{'_opts'}->{'bin'});
41 }
42 0 return($self);
43 }
44  
45 #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
46 #: Internal Methods
47 #:
48  
49 sub _debug {
50 0 ▶ my $self = shift();
Subroutine _debug: not called CC=3 SCAR=24.8
51 0 ▶ my $mesg = shift() || 'unknown msg';
Condition0%0/2
shift() || 'unknown msg'
l!l
00
MC/DC0%0/1
shift() || 'unknown msg'
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
52 0 my $logfile = '/tmp/nautilus_debug.tmp';
53 0 ▶ if (open(NAUTILUSLOGFILE,">>".$logfile)) {
Branch: 1 branch
BranchTrueFalseTotal
if (open NAUTILUSLOGFILE, '>>' . $logfile) 0 0 0
54 0 print NAUTILUSLOGFILE $mesg."\n";
55 0 close(NAUTILUSLOGFILE);
56 }
57 }
58 sub _is_env {
59 0 ▶ my $self = shift();
Subroutine _is_env: not called CC=5 SCAR=34.0
60 return(1)
61 unless not $ENV{'NAUTILUS_SCRIPT_SELECTED_FILE_PATHS'}
62 and not $ENV{'NAUTILUS_SCRIPT_SELECTED_URIS'}
63 and not $ENV{'NAUTILUS_SCRIPT_CURRENT_URI'}
64 0 ▶ and not $ENV{'NAUTILUS_SCRIPT_WINDOW_GEOMETRY'};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"NAUTILUS_SCRIPT_SELECTED_FILE_PATHS"} or $ENV{"NAUTILUS_SCRIPT_SELECTED_URIS"} or $ENV{"NAUTILUS_SCRIPT_CURRENT_URI"} or $ENV{"NAUTILUS_SCRIPT_WINDOW_GEOMETRY"} 0 0 0
Condition0%0/9
$ENV{"NAUTILUS_SCRIPT_SELECTED_FILE_PATHS"} or $ENV{"NAUTILUS_SCRIPT_SELECTED_URIS"} or $ENV{"NAUTILUS_SCRIPT_CURRENT_URI"} or $ENV{"NAUTILUS_SCRIPT_WINDOW_GEOMETRY"}
l!l&&r!l&&!r
000
$ENV{"NAUTILUS_SCRIPT_SELECTED_FILE_PATHS"} or $ENV{"NAUTILUS_SCRIPT_SELECTED_URIS"} or $ENV{"NAUTILUS_SCRIPT_CURRENT_URI"}
l!l&&r!l&&!r
000
$ENV{"NAUTILUS_SCRIPT_SELECTED_FILE_PATHS"} or $ENV{"NAUTILUS_SCRIPT_SELECTED_URIS"}
l!l&&r!l&&!r
000
MC/DC0%0/4
$ENV{"NAUTILUS_SCRIPT_SELECTED_FILE_PATHS"} or $ENV{"NAUTILUS_SCRIPT_SELECTED_URIS"} or $ENV{"NAUTILUS_SCRIPT_CURRENT_URI"} or $ENV{"NAUTILUS_SCRIPT_WINDOW_GEOMETRY"}
$ENV{"NAUTILUS_SCRIPT_SELECTED_FILE_PATHS"} $ENV{"NAUTILUS_SCRIPT_SELECTED_URIS"} $ENV{"NAUTILUS_SCRIPT_CURRENT_URI"} $ENV{"NAUTILUS_SCRIPT_WINDOW_GEOMETRY"}
Truth table0%0/5
A or B or C or D
A= $ENV{"NAUTILUS_SCRIPT_SELECTED_FILE_PATHS"}B= $ENV{"NAUTILUS_SCRIPT_SELECTED_URIS"}C= $ENV{"NAUTILUS_SCRIPT_CURRENT_URI"}D= $ENV{"NAUTILUS_SCRIPT_WINDOW_GEOMETRY"}
ABCDresult
1XXX1
01XX1
001X1
00011
00000
65 0 return(0);
66 }
67  
68 #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
69 #: Public (Nautilus Shell Script) Methods
70 #:
71  
72 #: Thanks to URI::Escape. Because it's not part of the core Perl, we need to
73 #: include it here. UI::Dialog shouldn't force other dependancies. This version
74 #: is modified to strip the prefixing protocol indicator.
75 sub uri_unescape {
76 # Note from RFC1630: "Sequences which start with a percent sign
77 # but are not followed by two hexadecimal characters are reserved
78 # for future extension"
79 0 ▶ my $self = shift();
Subroutine uri_unescape: not called CC=5 SCAR=34.0
Pod documented
80 0 my $str = shift();
81 0 ▶ if (@_ && wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ and wantarray) 0 0 0
Condition0%0/3
@_ and wantarray
!ll&&!rl&&r
000
MC/DC0%0/2
@_ and wantarray
@_ wantarray
Truth table0%0/3
A and B
A= @_B= wantarray
ABresult
0X0
100
111
82 # not executed for the common case of a single argument
83 0 my @str = ($str, @_); # need to copy
84 0 foreach (@str) {
85 0 s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg;
86 0 s!^\w+\://!!;
87 }
88 0 return(@str);
89 }
90 0 ▶ $str =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg if defined $str;
Branch: 1 branch
BranchTrueFalseTotal
if defined $str 0 0 0
91 0 $str =~ s!^\w+\://!!;
92 0 return($str);
93 }
94  
95 #NAUTILUS_SCRIPT_SELECTED_FILE_PATHS: newline-delimited paths for selected files (only if local)
96 sub paths {
97 0 ▶ my $self = shift();
Subroutine paths: not called CC=4 SCAR=30.0
Pod documented
98 0 ▶ if ($self->_is_env()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_env) { } 0 0 0
99 return(split(/\n/,$ENV{'NAUTILUS_SCRIPT_SELECTED_FILE_PATHS'}))
100 0 ▶ unless not $ENV{'NAUTILUS_SCRIPT_SELECTED_FILE_PATHS'};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"NAUTILUS_SCRIPT_SELECTED_FILE_PATHS"} 0 0 0
101 0 my @paths = ();
102 0 foreach my $uri ($self->uris()) {
103 0 my $path = $uri;
104 0 my $desktop = $self->_get_desktop_dir();
105 0 $path =~ s!^x\-nautilus\-desktop\:///trash!$ENV{'HOME'}/.Trash!;
106 0 $path =~ s!^x\-nautilus\-desktop\://!$desktop!;
107 0 push(@paths,$self->uri_unescape($path));
108 }
109 0 return(@paths);
110 0 } else { return(0); }
111 }
112  
113 #NAUTILUS_SCRIPT_SELECTED_URIS: newline-delimited URIs for selected files
114 sub uris {
115 0 ▶ my $self = shift();
Subroutine uris: not called CC=2 SCAR=17.9
Pod documented
116 0 ▶ if ($self->_is_env()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_env) { } 0 0 0
117 0 return(split(/\n/,$ENV{'NAUTILUS_SCRIPT_SELECTED_URIS'}));
118 0 } else { return(0); }
119 }
120  
121 #NAUTILUS_SCRIPT_CURRENT_URI: URI for current location
122 sub path {
123 0 ▶ my $self = shift();
Subroutine path: not called CC=4 SCAR=30.0
Pod documented
124 0 ▶ return('error') unless $self->_is_env();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_env 0 0 0
125 0 ▶ my $URI = $ENV{'NAUTILUS_SCRIPT_CURRENT_URI'} || '';
Condition0%0/2
$ENV{'NAUTILUS_SCRIPT_CURRENT_URI'} || ''
l!l
00
MC/DC0%0/1
$ENV{'NAUTILUS_SCRIPT_CURRENT_URI'} || ''
$ENV{'NAUTILUS_SCRIPT_CURRENT_URI'}
Truth table0%0/2
A
A= $ENV{'NAUTILUS_SCRIPT_CURRENT_URI'}
Aresult
11
00
126 0 my $desktop = $self->_get_desktop_dir();
127 0 $URI =~ s!^x\-nautilus\-desktop\:///trash!$ENV{'HOME'}/.Trash!;
128 0 $URI =~ s!^x\-nautilus\-desktop\://!$desktop!;
129 0 ▶ return(($self->uri_unescape($URI)||$URI));
Condition0%0/3
$self->uri_unescape($URI) || $URI
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->uri_unescape($URI) || $URI
$self->uri_unescape($URI) $URI
Truth table0%0/3
A || B
A= $self->uri_unescape($URI)B= $URI
ABresult
1X1
011
000
130 }
131  
132 #NAUTILUS_SCRIPT_CURRENT_URI: URI for current location
133 sub uri {
134 0 ▶ my $self = shift();
Subroutine uri: not called CC=2 SCAR=17.9
Pod documented
135 0 ▶ return($ENV{'NAUTILUS_SCRIPT_CURRENT_URI'}) if $self->_is_env();
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_env 0 0 0
136 0 return(0);
137 }
138  
139 #NAUTILUS_SCRIPT_WINDOW_GEOMETRY: position and size of current window
140 sub geometry {
141 0 ▶ my $self = shift();
Subroutine geometry: not called CC=3 SCAR=24.8
Pod documented
142 0 ▶ if ($self->_is_env()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_env) { } 0 0 0
143 #: Width, Height, X, Y
144 0 ▶ return($1,$2,$3,$4) if $ENV{'NAUTILUS_SCRIPT_WINDOW_GEOMETRY'} =~ /(\d+)x(\d+)\+(\d+)\+(\d+)/;
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"NAUTILUS_SCRIPT_WINDOW_GEOMETRY"} =~ /(\d+)x(\d+)\+(\d+)\+(\d+)/ 0 0 0
145 0 } else { return(0,0,0,0); }
146 }
147  
148 sub _get_desktop_dir {
149 0 ▶ my $self = shift();
Subroutine _get_desktop_dir: not called CC=15 SCAR=54.8
150 # Figure out the user's home directory
151 0 my @user = getpwuid($>);
152 0 my $home = undef;
153 0 ▶ if (@user > 7 && -d $user[7]) {
Branch: 1 branch
BranchTrueFalseTotal
if (@user > 7 and -d $user[7]) 0 0 0
Condition0%0/3
@user > 7 and -d $user[7]
!ll&&!rl&&r
000
MC/DC0%0/2
@user > 7 and -d $user[7]
@user > 7 -d $user[7]
Truth table0%0/3
A and B
A= @user > 7B= -d $user[7]
ABresult
0X0
100
111
154 0 $home = $user[7];
155 }
156 # check for XDG paths to home directory
157 0 ▶ my $xdg_desktop_dir = $ENV{XDG_DESKTOP_DIR} || undef;
Condition0%0/2
$ENV{'XDG_DESKTOP_DIR'} || undef
l!l
00
MC/DC0%0/1
$ENV{'XDG_DESKTOP_DIR'} || undef
$ENV{'XDG_DESKTOP_DIR'}
Truth table0%0/2
A
A= $ENV{'XDG_DESKTOP_DIR'}
Aresult
11
00
158 0 ▶ if (defined $xdg_desktop_dir && -d $xdg_desktop_dir) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $xdg_desktop_dir and -d $xdg_desktop_dir) 0 0 0
Condition0%0/3
defined $xdg_desktop_dir and -d $xdg_desktop_dir
!ll&&!rl&&r
000
MC/DC0%0/2
defined $xdg_desktop_dir and -d $xdg_desktop_dir
defined $xdg_desktop_dir -d $xdg_desktop_dir
Truth table0%0/3
A and B
A= defined $xdg_desktop_dirB= -d $xdg_desktop_dir
ABresult
0X0
100
111
159 0 return $xdg_desktop_dir;
160 }
161 0 ▶ my $xdg_config_home = $ENV{XDG_CONFIG_HOME} || $home.'/.config';
Condition0%0/2
$ENV{'XDG_CONFIG_HOME'} || $home . '/.config'
l!l
00
MC/DC0%0/1
$ENV{'XDG_CONFIG_HOME'} || $home . '/.config'
$ENV{'XDG_CONFIG_HOME'}
Truth table0%0/2
A
A= $ENV{'XDG_CONFIG_HOME'}
Aresult
11
00
162 0 ▶ if (-d $xdg_config_home && -f $xdg_config_home.'/user-dirs.dirs') {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $xdg_config_home and -f $xdg_config_home . '/user-dirs.dirs') 0 0 0
Condition0%0/3
-d $xdg_config_home and -f $xdg_config_home . '/user-dirs.dirs'
!ll&&!rl&&r
000
MC/DC0%0/2
-d $xdg_config_home and -f $xdg_config_home . '/user-dirs.dirs'
-d $xdg_config_home -f $xdg_config_home . '/user-dirs.dirs'
Truth table0%0/3
A and B
A= -d $xdg_config_homeB= -f $xdg_config_home . '/user-dirs.dirs'
ABresult
0X0
100
111
163 0 foreach (`. "${xdg_config_home}/user-dirs.dirs"; env`) {
164 0 chomp;
165 0 ▶ next unless /=/;
Branch: 1 branch
BranchTrueFalseTotal
unless /=/ 0 0 0
166 0 my ($var, $value) = split(/=/, $_);
167 0 $ENV{$var} = $value;
168 }
169 }
170 0 ▶ $xdg_desktop_dir = $ENV{XDG_DESKTOP_DIR} || undef;
Condition0%0/2
$ENV{'XDG_DESKTOP_DIR'} || undef
l!l
00
MC/DC0%0/1
$ENV{'XDG_DESKTOP_DIR'} || undef
$ENV{'XDG_DESKTOP_DIR'}
Truth table0%0/2
A
A= $ENV{'XDG_DESKTOP_DIR'}
Aresult
11
00
171 0 ▶ if (defined $xdg_desktop_dir && -d $xdg_desktop_dir) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $xdg_desktop_dir and -d $xdg_desktop_dir) 0 0 0
Condition0%0/3
defined $xdg_desktop_dir and -d $xdg_desktop_dir
!ll&&!rl&&r
000
MC/DC0%0/2
defined $xdg_desktop_dir and -d $xdg_desktop_dir
defined $xdg_desktop_dir -d $xdg_desktop_dir
Truth table0%0/3
A and B
A= defined $xdg_desktop_dirB= -d $xdg_desktop_dir
ABresult
0X0
100
111
172 0 return $xdg_desktop_dir;
173 }
174 0 ▶ return $home."/Desktop" if -d $home."/Desktop";
Branch: 1 branch
BranchTrueFalseTotal
if -d $home . '/Desktop' 0 0 0
175 # finally defaulting to just home
176 0 return $home;
177 }
178  
179 1 1;
« Dialog/Backend/KDialog.pm ↑ Summary Dialog/Screen/Menu.pm »