partially implement tagvals
[id3fs.git] / lib / ID3FS / Path.pm
index 076b6ca..68d94f1 100644 (file)
@@ -71,8 +71,19 @@ sub dirents
     {
        when($STATE_TAG)
        {
-           @dents=(qw(AND ALLTRACKS), # FIXME: NOT and OR
-                   $self->{db}->artists(@{$self->{elements}}));
+           my $tag=$self->{elements}->[$#{$self->{elements}}];
+           if(defined($tag) && (ref($tag) eq "ID3FS::PathElement::Tag") &&
+              $self->{db}->tag_has_values($tag->{id}))
+           {
+               print "DIRENTS: TAG: TAGVALUES\n";
+               @dents=$self->{db}->tag_values($tag->{id});
+           }
+           else
+           {
+               print "DIRENTS: TAG: ARTISTS\n";
+               @dents=(qw(AND ALLTRACKS), # FIXME: NOT and OR
+                       $self->{db}->artists(@{$self->{elements}}));
+           }
        }
        when($STATE_BOOLEAN)
        {
@@ -81,7 +92,6 @@ sub dirents
        when($STATE_ROOT)
        {
            @dents=("ALL", $self->{db}->tags(@{$self->{elements}}));
-           print "\nDIRENTS: DENTS: ", join(", ", @dents),"\n\n";
        }
        when($STATE_ALBUMS)
        {
@@ -145,36 +155,55 @@ sub parse
            when($STATE_TAG)
            {
                print "SM: TAG: $name\n";
-               given($name)
+               my $tag=$self->{elements}->[$#{$self->{elements}}];
+               if(defined($tag) &&
+                  ref($tag) eq "ID3FS::PathElement::Tag" &&
+                  $self->{db}->tag_has_values($tag->{id}))
                {
-                   when("AND")
+                   my $tagval=ID3FS::PathElement::Tagval->new($name);
+                   if(defined($tagval))
                    {
                        $self->state($STATE_BOOLEAN);
-#                      push(@{$self->{elements}}, ID3FS::PathElement::Boolean->new($name));
+                       push(@{$self->{elements}}, $tagval);
                    }
-                   when("ALLTRACKS")
-                   {
-                       $self->state($STATE_TRACKLIST);
-                   }
-                   when("OR")
+                   else
                    {
-                       $self->state($STATE_BOOLEAN);
-#                      push(@{$self->{elements}}, ID3FS::PathElement::Boolean->new($name));
+                       $self->state($STATE_INVALID);
                    }
-                   when("NOT")
+               }
+               else
+               {
+                   given($name)
                    {
-                       $self->state($STATE_TAG);
+                       when("AND")
+                       {
+                           $self->state($STATE_BOOLEAN);
+#                          push(@{$self->{elements}}, ID3FS::PathElement::Boolean->new($name));
+                       }
+                       when("ALLTRACKS")
+                       {
+                           $self->state($STATE_TRACKLIST);
+                       }
+                       when("OR")
+                       {
+                           $self->state($STATE_BOOLEAN);
+#                          push(@{$self->{elements}}, ID3FS::PathElement::Boolean->new($name));
+                       }
+                       when("NOT")
+                       {
+                           $self->state($STATE_TAG);
 #                      push(@{$self->{elements}}, ID3FS::PathElement::Boolean->new($name));
-                   }
-                   my $artist=ID3FS::PathElement::Artist->new($self->{db}, $name);
-                   if($artist)
-                   {
-                       push(@{$self->{elements}}, $artist);
-                       $self->state($STATE_ALBUMS);
-                   }
-                   else
-                   {
-                       $self->state($STATE_INVALID);
+                       }
+                       my $artist=ID3FS::PathElement::Artist->new($self->{db}, $name);
+                       if($artist)
+                       {
+                           push(@{$self->{elements}}, $artist);
+                           $self->state($STATE_ALBUMS);
+                       }
+                       else
+                       {
+                           $self->state($STATE_INVALID);
+                       }
                    }
                }
            }