1 # id3fs - a FUSE-based filesystem for browsing audio metadata
2 # Copyright (C) 2010 Ian Beckwith <ianb@erislabs.net>
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package ID3FS::Path::Node;
23 use vars qw(@ISA @EXPORT $TYPE_BOOL $TYPE_TAG $TYPE_ARTIST $TYPE_ALBUM $TYPE_FILE);
25 @EXPORT=qw($TYPE_BOOL $TYPE_TAG $TYPE_ARTIST $TYPE_ALBUM $TYPE_FILE);
26 ($TYPE_BOOL, $TYPE_TAG, $TYPE_ARTIST, $TYPE_ALBUM, $TYPE_FILE)=(1..5);
31 my $class=ref($proto) || $proto;
38 $self->{parents_id}=shift;
40 $self->{hasvals}=undef;
41 if($self->{type} != $TYPE_BOOL)
44 if ($self->{type} == $TYPE_TAG) { $table="tags"; }
45 elsif($self->{type} == $TYPE_ARTIST) { $table="artists"; }
46 elsif($self->{type} == $TYPE_ALBUM) { $table="albums"; }
47 elsif($self->{type} == $TYPE_FILE) { $table="files"; }
48 $self->{id}=$db->lookup_id($table, $self->{name}, $self->{parents_id});
49 return undef unless(defined($self->{id}));
56 my($self, $name, $val)=@_;
61 return $self->{$name};
64 sub left { return shift->set("left", shift); }
65 sub right { return shift->set("right", shift); }
66 sub name { return shift->set("name", shift); }
67 sub type { return shift->set("type", shift); }
68 sub id { return shift->set("id", shift); }
69 sub parents_id { return shift->set("parents_id", shift); }
70 sub table { return shift->set("table", shift); }
71 sub hasvals { return shift->set("hasvals", shift); }
76 $not=0 unless(defined($not));
79 if($self->type() != $TYPE_BOOL)
81 $str .= "t" . $self->table() . ".id='" . $self->{id} . "'";
82 if($not && !$self->hasvals())
84 $str = "(" . $str . " AND fxt" . $self->table() . ".files_id IS NULL)";
89 my $left=$self->left();
90 my $right=$self->right();
91 return ("") unless($left || $right);
93 my $leftstr = $left->to_sql($not) if($left);
95 $not=1 if(defined($op) && ($op eq "NOT"));
96 my $rightstr = $right->to_sql($not) if($right);
98 $str .= " $op " if($op && !$not);
100 $str=("(" . $str . ")") if($op && $left && $right);
107 if($self->type() == $TYPE_BOOL)
110 push(@used, $self->left()->used_tags()) if($self->left());
111 push(@used, $self->right()->used_tags()) if($self->right());
112 return(grep { defined; } @used);
117 # does the bottom right-most expression end in a NOT?
118 sub right_ends_in_not
121 return 0 unless($node);
122 my $right=$node->right();
123 if($right && $right->type() == $TYPE_BOOL)
125 return $self->right_ends_in_not($right);
127 my $op=$node->name();
128 return 0 unless($op);
129 return 1 if($op eq "NOT");