specify max tag depth (default: 15)
[id3fs.git] / lib / ID3FS / Path.pm
index 0455375..cd8b5ac 100644 (file)
@@ -31,6 +31,8 @@ sub new
     $self->{db}=shift;
     $self->{path}=shift;
     $self->{verbose}=shift;
+    $self->{maxtagdepth}=shift;
+    $self->{curtagdepth}=0;
     $self->{path} =~ s/\/\//\//g; # drop doubled slashes
 
     $self->parse();
@@ -95,7 +97,11 @@ sub dirents
        }
        else
        {
-           @dents=(qw(AND OR), $PATH_ALLTRACKS, $PATH_NOARTIST, $self->artists());
+           if($self->{maxtagdepth} && ($self->{curtagdepth} < $self->{maxtagdepth}))
+           {
+               @dents=qw(AND OR);
+           }
+           push(@dents, $PATH_ALLTRACKS, $PATH_NOARTIST, $self->artists());
        }
     }
     elsif($state==$STATE_BOOLEAN)
@@ -372,7 +378,11 @@ sub parse
 sub state
 {
     my($self, $newstate)=@_;
-    $self->{state}=$newstate if(defined($newstate));
+    if(defined($newstate))
+    {
+       $self->{state}=$newstate;
+       $self->{curtagdepth}++ if($newstate == $STATE_TAG);
+    }
     return $self->{state};
 }
 
@@ -863,7 +873,7 @@ sub empty
     my($self, $dir, $maxdepth)=@_;
     return 0 unless($maxdepth);
 #    print "testing($maxdepth): $dir\n";
-    my $path=ID3FS::Path->new($self->{db}, $dir, $self->{verbose});
+    my $path=ID3FS::Path->new($self->{db}, $dir, $self->{verbose}, $self->{tagdepth});
 #    print "PATH INVALID\n" unless($path->isvalid());
     return 1 unless($path->isvalid());
     my($subdirs,$subfiles)=$path->dirents();