specify max tag depth (default: 15)
[id3fs.git] / lib / ID3FS / Path.pm
index 4ef3a54..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();
@@ -81,7 +83,7 @@ sub dirents
 #    print "DIRENTS: FILE: $self->{path}\n";
     if($state==$STATE_ALL)
     {
-       @dents=($self->artists(), $PATH_ALLTRACKS, $PATH_NOARTIST);
+       @dents=($PATH_ALLTRACKS, $PATH_NOARTIST, $self->artists());
     }
     elsif($state==$STATE_TAG || $state==$STATE_TAGVAL)
     {
@@ -95,27 +97,31 @@ sub dirents
        }
        else
        {
-           @dents=($self->artists(), qw(AND OR), $PATH_ALLTRACKS, $PATH_NOARTIST);
+           if($self->{maxtagdepth} && ($self->{curtagdepth} < $self->{maxtagdepth}))
+           {
+               @dents=qw(AND OR);
+           }
+           push(@dents, $PATH_ALLTRACKS, $PATH_NOARTIST, $self->artists());
        }
     }
     elsif($state==$STATE_BOOLEAN)
     {
-       @dents=$self->tags();
        my $parent=$self->tail();
        unless(defined($parent) &&
               ref($parent) eq "ID3FS::PathElement::Boolean" &&
               $parent->{name} eq "NOT")
        {
-           push(@dents, "NOT");
+           @dents=("NOT");
        }
+       push(@dents,$self->tags());
     }
     elsif($state==$STATE_ROOT)
     {
-       @dents=($self->tags(), qw(ALL NOT));
+       @dents=(qw(ALL NOT), $self->tags());
     }
     elsif($state==$STATE_ALBUMS)
     {
-       @dents=($self->albums(), $PATH_ALLTRACKS, $PATH_NOALBUM);
+       @dents=($PATH_ALLTRACKS, $PATH_NOALBUM, $self->albums());
     }
     elsif($state==$STATE_TRACKLIST)
     {
@@ -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();