Index: apps/metadata.c
===================================================================
RCS file: /cvsroot/rockbox/apps/metadata.c,v
retrieving revision 1.62
diff -u -r1.62 metadata.c
--- apps/metadata.c	7 Dec 2006 16:15:23 -0000	1.62
+++ apps/metadata.c	9 Dec 2006 14:40:35 -0000
@@ -30,6 +30,7 @@
 #include "replaygain.h"
 #include "debug.h"
 #include "system.h"
+#include "dircache.h"
 
 enum tagtype { TAGTYPE_APE = 1, TAGTYPE_VORBIS };
 
@@ -115,6 +116,96 @@
     32000, 44100, 48000, 64000, 88200, 96000, 192000 
 };
 
+/* checks for existence of file if possible using dircache */
+bool exists(const char* pathname) {
+
+  bool found = false;
+  int fd;
+
+/* debugf("EXISTS %s?\n", pathname);*/
+
+#ifdef HAVE_DIRCACHE
+  if(dircache_is_enabled()) 
+    found = (NULL != dircache_get_entry_ptr(pathname));
+  else 
+#endif
+
+  { 
+    fd=open(pathname, O_RDONLY);
+    if(fd>-1) {     
+       close(fd);   	
+       found = true;
+    }   
+  }  
+  return found;
+ 
+}
+
+unsigned char aa_strings[4][6] = {"NONE", "FILE", "ALBUM", "DIR"};
+
+
+void has_albumart(struct mp3entry* id3) {
+
+  int found = 0;
+  unsigned char *path, *dot, *slash;
+  int length, alength; 
+  
+  /* is valid id3 ? */
+  if(!(id3 && (path=id3->path) && (dot=strrchr(path,'.')))) 
+    return;
+
+  length=dot-path; 
+  
+  /* try <filename>.jpg */
+  memcpy(path+length,".jpg",5);
+  if(exists(path)) found = 1;
+  
+  /* try <album>.jpg */
+  if((!found) && (id3->album != NULL)){
+    slash=strrchr(path,'/');
+    length = slash ? slash-path+1 : 0; 
+
+    alength = strlen(id3->album);
+    memcpy(path+length,id3->album,alength);
+  
+    memcpy(path+length+alength,".jpg",5);
+    if(exists(path)) found = 2;
+  }
+  
+  /* try folder.jpg  */
+  if(!found){
+    memcpy(path+length,"folder.jpg",11);
+    if(exists(path)) found = 3;
+  }
+  
+  id3->albumart = found;
+  
+}
+
+unsigned char lyr_strings[5][5] = {"NONE", "LRC8", "LRC", "SNC", "TXT"};
+
+void has_lyrics(struct mp3entry* id3) {
+
+
+  int found = 0;   
+  unsigned char *path, *dot;
+  int length, i; 
+  
+  /* is valid id3 ? */
+  if(!(id3 && (path=id3->path) && (dot=strrchr(path,'.')))) 
+    return;
+
+  length=dot-path+1; 
+
+  for(i=1; (i<5) && (found==0); i++) {
+    memcpy(path+length,lyr_strings[i],strlen(lyr_strings[i])+1);
+    if(exists(path)) found = i;
+  }    
+
+  id3->lyrics = found;
+
+}
+
 /* Read a string from the file. Read up to size bytes, or, if eos != -1, 
  * until the eos character is found (eos is not stored in buf, unless it is
  * nil). Writes up to buf_size chars to buf, always terminating with a nil.
@@ -316,6 +407,10 @@
     {
         p = &(id3->composer);
     }
+    else if (strcasecmp(name, "comment") == 0)
+    {
+        p = &(id3->comment);
+    }
     else
     {
         len = parse_replaygain(name, value, id3, buf, buf_remaining);
@@ -2079,9 +2174,16 @@
     }
 
     /* We have successfully read the metadata from the file */
-
     lseek(fd, 0, SEEK_SET);
     strncpy(track->id3.path, trackname, sizeof(track->id3.path));
+
+    has_lyrics(&track->id3);    
+/*  only changes extensions - no need to restore path */
+/*  strncpy(track->id3.path, trackname, sizeof(track->id3.path)); */
+
+    has_albumart(&track->id3);
+    strncpy(track->id3.path, trackname, sizeof(track->id3.path));
+
     track->taginfo_ready = true;
 
     return true;
Index: apps/tagcache.c
===================================================================
RCS file: /cvsroot/rockbox/apps/tagcache.c,v
retrieving revision 1.79
diff -u -r1.79 tagcache.c
--- apps/tagcache.c	5 Dec 2006 20:01:39 -0000	1.79
+++ apps/tagcache.c	9 Dec 2006 19:45:45 -0000
@@ -102,18 +102,27 @@
 static long tempbuf_pos;
 
 /* Tags we want to get sorted (loaded to the tempbuf). */
-static const int sorted_tags[] = { tag_artist, tag_album, tag_genre, tag_composer, tag_title };
+static const int sorted_tags[] = { tag_artist, tag_album, tag_genre, tag_composer, tag_comment, tag_title };
 
 /* Uniqued tags (we can use these tags with filters and conditional clauses). */
-static const int unique_tags[] = { tag_artist, tag_album, tag_genre, tag_composer };
+static const int unique_tags[] = { tag_artist, tag_album, tag_genre, tag_composer, tag_comment };
 
 /* Numeric tags (we can use these tags with conditional clauses). */
-static const int numeric_tags[] = { tag_year, tag_tracknumber, tag_length, tag_bitrate,
-    tag_playcount, tag_playtime, tag_lastplayed, tag_virt_autoscore };
+static const int numeric_tags[] = { tag_year, tag_lyrics, tag_albumart, tag_tracknumber, tag_length, tag_bitrate,
+    tag_playcount, tag_rating, tag_playtime, tag_lastplayed, 
+#ifdef CONFIG_RTC
+    tag_timeadded, tag_timeplayed, 
+    tag_virt_dayssinceadded, tag_virt_dayssinceplayed, 
+#endif
+    tag_virt_autoscore, tag_virt_relplay };
 
 static const char *tags_str[] = { "artist", "album", "genre", "title", 
-    "filename", "composer", "year", "tracknumber", "bitrate", "length",
-    "playcount", "playtime", "lastplayed" };
+    "filename", "composer", "comment", "year", "lyrics", "albumart", "tracknumber", "bitrate", "length",
+    "playcount", "rating", "playtime", "lastplayed", 
+#ifdef CONFIG_RTC
+    "timeadded", "timeplayed" 
+#endif
+    };
 
 /* Status information of the tagcache. */
 static struct tagcache_stat tc_stat;
@@ -156,6 +165,9 @@
 };
 
 static long current_serial;
+#ifdef CONFIG_RTC
+static long current_time;
+#endif
 
 #ifdef HAVE_TC_RAMCACHE
 /* Header is created when loading database to ram. */
@@ -646,6 +658,20 @@
     
     switch (tag) 
     {
+#ifdef CONFIG_RTC
+
+
+
+
+        case tag_virt_dayssinceadded:
+            data = current_time - idx->tag_seek[tag_timeadded];
+            break;
+        case tag_virt_dayssinceplayed:
+            data = idx->tag_seek[tag_timeplayed];
+            data = data ? (current_time - data) : -1;
+            break;
+#endif
+        case tag_virt_relplay:
         case tag_virt_autoscore:
             if (idx->tag_seek[tag_length] == 0 
                 || idx->tag_seek[tag_playcount] == 0)
@@ -655,8 +681,10 @@
             else
             {
                 data = 100 * idx->tag_seek[tag_playtime]
-                    / idx->tag_seek[tag_length]
-                    / idx->tag_seek[tag_playcount];
+                    / idx->tag_seek[tag_length];
+
+                if(tag == tag_virt_autoscore) 
+                    data /= idx->tag_seek[tag_playcount];
             }
             break;
         
@@ -1041,6 +1069,11 @@
     struct master_header   master_hdr;
     int i;
 
+#ifdef CONFIG_RTC
+    current_time = mktime(get_time())/86400-13490;
+    logf("ROOLKU: current_time updated");
+#endif
+
     if (tcs->initialized)
         tagcache_search_finish(tcs);
     
@@ -1539,9 +1572,14 @@
     
     /* Numeric tags */
     entry.tag_offset[tag_year] = track.id3.year;
+    entry.tag_offset[tag_lyrics] = track.id3.lyrics;
+    entry.tag_offset[tag_albumart] = track.id3.albumart;
     entry.tag_offset[tag_tracknumber] = track.id3.tracknum;
     entry.tag_offset[tag_length] = track.id3.length;
     entry.tag_offset[tag_bitrate] = track.id3.bitrate;
+#ifdef CONFIG_RTC
+    entry.tag_offset[tag_timeadded] = current_time;
+#endif
     
     /* String tags. */
     ADD_TAG(entry, tag_filename, &path);
@@ -1550,6 +1588,7 @@
     ADD_TAG(entry, tag_album, &track.id3.album);
     ADD_TAG(entry, tag_genre, &genrestr);
     ADD_TAG(entry, tag_composer, &track.id3.composer);
+    ADD_TAG(entry, tag_comment, &track.id3.comment);
     entry.data_length = offset;
     
     /* Write the header */
@@ -1562,6 +1601,7 @@
     write_item(track.id3.album);
     write_item(genrestr);
     write_item(track.id3.composer);
+    write_item(track.id3.comment);
     total_entry_count++;    
 }
 
@@ -2724,7 +2764,11 @@
     char tag_data[TAG_MAXLEN+32];
     int idx_id;
     long masterfd = (long)parameters;
-    const int import_tags[] = { tag_playcount, tag_playtime, tag_lastplayed };
+    const int import_tags[] = { tag_playcount, tag_rating, tag_playtime, tag_lastplayed
+#ifdef CONFIG_RTC
+                              , tag_timeadded, tag_timeplayed 
+#endif
+                              };
     int i;
     (void)line_n;
     
@@ -3509,7 +3553,9 @@
     data_size = 0;
     total_entry_count = 0;
     processed_dir_count = 0;
-    
+#ifdef CONFIG_RTC    
+    current_time = mktime(get_time())/86400-13490;
+#endif
 #ifdef HAVE_DIRCACHE
     while (dircache_is_initializing())
         sleep(1);
Index: apps/tagcache.h
===================================================================
RCS file: /cvsroot/rockbox/apps/tagcache.h,v
retrieving revision 1.32
diff -u -r1.32 tagcache.h
--- apps/tagcache.h	25 Nov 2006 09:42:05 -0000	1.32
+++ apps/tagcache.h	9 Dec 2006 17:41:00 -0000
@@ -20,15 +20,24 @@
 #ifndef _TAGCACHE_H
 #define _TAGCACHE_H
 
+#include "system.h"
 #include "id3.h"
 
 enum tag_type { tag_artist = 0, tag_album, tag_genre, tag_title,
-    tag_filename, tag_composer, tag_year, tag_tracknumber,
-    tag_bitrate, tag_length, tag_playcount, tag_playtime, tag_lastplayed,
+    tag_filename, tag_composer, tag_comment, tag_year, tag_lyrics, tag_albumart, tag_tracknumber,
+    tag_bitrate, tag_length, tag_playcount, tag_rating, tag_playtime, tag_lastplayed, 
+#ifdef CONFIG_RTC
+    tag_timeadded, tag_timeplayed,
+    tag_virt_dayssinceadded, tag_virt_dayssinceplayed, 
+#endif
     /* Virtual tags */
-    tag_virt_autoscore };
+    tag_virt_autoscore, tag_virt_relplay };
 
-#define TAG_COUNT 13
+#ifdef CONFIG_RTC
+#define TAG_COUNT 19
+#else
+#define TAG_COUNT 17
+#endif
 
 /* Maximum length of a single tag. */
 #define TAG_MAXLEN (MAX_PATH*2)
@@ -40,7 +49,7 @@
 #define IDX_BUF_DEPTH 64
 
 /* Tag Cache Header version 'TCHxx'. Increment when changing internal structures. */
-#define TAGCACHE_MAGIC  0x54434806
+#define TAGCACHE_MAGIC  0x5443480b
 
 /* How much to allocate extra space for ramcache. */
 #define TAGCACHE_RESERVE 32768
Index: apps/tagtree.c
===================================================================
RCS file: /cvsroot/rockbox/apps/tagtree.c,v
retrieving revision 1.57
diff -u -r1.57 tagtree.c
--- apps/tagtree.c	5 Dec 2006 20:01:40 -0000	1.57
+++ apps/tagtree.c	9 Dec 2006 15:15:03 -0000
@@ -195,15 +195,26 @@
     MATCH(tag, buf, "artist", tag_artist);
     MATCH(tag, buf, "bitrate", tag_bitrate);
     MATCH(tag, buf, "composer", tag_composer);
+    MATCH(tag, buf, "comment", tag_comment);
     MATCH(tag, buf, "genre", tag_genre);
     MATCH(tag, buf, "length", tag_length);
     MATCH(tag, buf, "title", tag_title);
     MATCH(tag, buf, "filename", tag_filename);
     MATCH(tag, buf, "tracknum", tag_tracknumber);
     MATCH(tag, buf, "year", tag_year);
+    MATCH(tag, buf, "lyrics", tag_lyrics);
+    MATCH(tag, buf, "albumart", tag_albumart);
     MATCH(tag, buf, "playcount", tag_playcount);
+    MATCH(tag, buf, "rating", tag_rating);
     MATCH(tag, buf, "lastplayed", tag_lastplayed);
+#ifdef CONFIG_RTC
+    MATCH(tag, buf, "timeadded", tag_timeadded);
+    MATCH(tag, buf, "timeplayed", tag_timeplayed);
+    MATCH(tag, buf, "dayssinceadded", tag_virt_dayssinceadded);
+    MATCH(tag, buf, "dayssinceplayed", tag_virt_dayssinceplayed);
+#endif    
     MATCH(tag, buf, "autoscore", tag_virt_autoscore);
+    MATCH(tag, buf, "relplay", tag_virt_relplay);
     MATCH(tag, buf, "%sort", var_sorttype);
     MATCH(tag, buf, "%limit", var_limit);
     MATCH(tag, buf, "%strip", var_strip);
@@ -598,9 +609,10 @@
     }
     
     id3->playcount  = tagcache_get_numeric(&tcs, tag_playcount);
+    if(!id3->rating) id3->rating = tagcache_get_numeric(&tcs, tag_rating);
     id3->lastplayed = tagcache_get_numeric(&tcs, tag_lastplayed);
-    id3->rating     = tagcache_get_numeric(&tcs, tag_virt_autoscore) / 10;
-    
+    id3->score      = tagcache_get_numeric(&tcs, tag_virt_autoscore) / 10;
+
     tagcache_search_finish(&tcs);
 }
 
@@ -608,9 +620,15 @@
 {
     (void)last_track;
     long playcount;
+    long lyrics;
+    long albumart;
+    long rating;
     long playtime;
     long lastplayed;
-    
+#ifdef CONFIG_RTC
+    long timeplayed;
+#endif
+        
     /* Do not gather data unless proper setting has been enabled. */
     if (!global_settings.runtimedb)
     {
@@ -634,9 +652,15 @@
     playcount  = tagcache_get_numeric(&tcs, tag_playcount);
     playtime   = tagcache_get_numeric(&tcs, tag_playtime);
     lastplayed = tagcache_get_numeric(&tcs, tag_lastplayed);
-    
+#ifdef CONFIG_RTC
+    timeplayed = mktime(get_time())/86400-13490; /* more correctly unbuffer time */
+#endif    
     playcount++;
     
+    lyrics   = (long) id3->lyrics;
+    albumart = (long) id3->albumart;
+    rating   = (long) id3->rating;
+    
     lastplayed = tagcache_increase_serial();
     if (lastplayed < 0)
     {
@@ -649,14 +673,21 @@
     playtime += MIN(id3->length, id3->elapsed + 15 * 1000);
     
     logf("ube:%s", id3->path);
-    logf("-> %d/%d/%d", last_track, playcount, playtime);
+    logf("-> %d/%d/%d/%d/%d/%d", last_track, playcount, lyrics, albumart, rating, playtime);
     logf("-> %d/%d/%d", id3->elapsed, id3->length, MIN(id3->length, id3->elapsed + 15 * 1000));
     
     /* lastplayed not yet supported. */
     
     if (!tagcache_modify_numeric_entry(&tcs, tag_playcount, playcount)
+        || !tagcache_modify_numeric_entry(&tcs, tag_lyrics, lyrics)
+        || !tagcache_modify_numeric_entry(&tcs, tag_albumart, albumart)
+        || !tagcache_modify_numeric_entry(&tcs, tag_rating, rating)
         || !tagcache_modify_numeric_entry(&tcs, tag_playtime, playtime)
-        || !tagcache_modify_numeric_entry(&tcs, tag_lastplayed, lastplayed))
+        || !tagcache_modify_numeric_entry(&tcs, tag_lastplayed, lastplayed)
+#ifdef CONFIG_RTC
+        || !tagcache_modify_numeric_entry(&tcs, tag_timeplayed, timeplayed)
+#endif
+        )
     {
         logf("tc stat: modify failed!");
         tagcache_search_finish(&tcs);
@@ -1148,6 +1179,11 @@
         }
         else
             dptr->name = tcs->result;
+            
+        if(tcs->type == tag_lyrics)    
+            dptr->name = lyr_strings[atoi(tcs->result)];    
+        else if(tcs->type == tag_albumart)    
+            dptr->name = aa_strings[atoi(tcs->result)];    
         
         dptr++;
         current_entry_count++;
Index: apps/gui/gwps-common.c
===================================================================
RCS file: /cvsroot/rockbox/apps/gui/gwps-common.c,v
retrieving revision 1.67
diff -u -r1.67 gwps-common.c
--- apps/gui/gwps-common.c	15 Nov 2006 20:26:33 -0000	1.67
+++ apps/gui/gwps-common.c	9 Dec 2006 14:40:35 -0000
@@ -504,6 +504,9 @@
                 case 'c':  /* ID3 Composer */
                     return id3->composer;
 
+                case 'C':  /* ID3 Comment */
+                    return id3->comment;
+
                 case 'y':  /* year */
                     if( id3->year_string )
                         return id3->year_string;
@@ -551,6 +554,16 @@
             *flags |= WPS_REFRESH_STATIC;
             switch(tag[1])
             {
+                case 'a':  
+                    *flags |= WPS_REFRESH_DYNAMIC;
+                    *intval = id3->albumart;
+                    return aa_strings[(*intval)++];
+
+                case 'l':
+                    *flags |= WPS_REFRESH_DYNAMIC;
+                    *intval = id3->lyrics;
+                    return lyr_strings[(*intval)++];
+
                 case 'v':  /* VBR file? */
                     return id3->vbr ? "(avg)" : NULL;
 
@@ -927,6 +940,7 @@
             {
                 case 'p':  /* Playcount */
                     *flags |= WPS_REFRESH_STATIC;
+                    *intval = cid3->playcount+1;
                     snprintf(buf, buf_size, "%ld", cid3->playcount);
                     return buf;
                 case 'r':  /* Rating */
Index: firmware/id3.c
===================================================================
RCS file: /cvsroot/rockbox/firmware/id3.c,v
retrieving revision 1.140
diff -u -r1.140 id3.c
--- firmware/id3.c	8 Dec 2006 13:55:14 -0000	1.140
+++ firmware/id3.c	9 Dec 2006 14:40:35 -0000
@@ -345,6 +345,14 @@
     return bufferpos;
 }
 
+/* parse comment */
+static int parsecomment( struct mp3entry* entry, char* tag, int bufferpos )
+{
+    
+    entry->comment = tag + 4;       // simplistic
+    return bufferpos;
+}
+
 /* parse numeric genre from string, version 2.2 and 2.3 */
 static int parsegenre( struct mp3entry* entry, char* tag, int bufferpos )
 {
@@ -442,6 +450,7 @@
     { "TYER", 4, offsetof(struct mp3entry, year_string), &parseyearnum, false },
     { "TYE",  3, offsetof(struct mp3entry, year_string), &parseyearnum, false },
     { "TCOM", 4, offsetof(struct mp3entry, composer), NULL, false },
+    { "COMM", 4, offsetof(struct mp3entry, comment), &parsecomment, false },
     { "TCON", 4, offsetof(struct mp3entry, genre_string), &parsegenre, false },
     { "TCO",  3, offsetof(struct mp3entry, genre_string), &parsegenre, false },
 #if CONFIG_CODEC == SWCODEC
@@ -1145,6 +1154,8 @@
         entry->year_string += offset;
     if (entry->composer)
         entry->composer += offset;
+    if (entry->comment)
+        entry->comment += offset;
 #if CONFIG_CODEC == SWCODEC
     if (entry->track_gain_string)
         entry->track_gain_string += offset;
Index: firmware/export/id3.h
===================================================================
RCS file: /cvsroot/rockbox/firmware/export/id3.h,v
retrieving revision 1.36
diff -u -r1.36 id3.h
--- firmware/export/id3.h	24 Nov 2006 20:10:32 -0000	1.36
+++ firmware/export/id3.h	9 Dec 2006 14:40:35 -0000
@@ -23,6 +23,9 @@
 #include "config.h"
 #include "file.h"
 
+extern unsigned char aa_strings[4][6];
+extern unsigned char lyr_strings[5][5];
+
 /* Audio file types. */
 enum
 {
@@ -140,6 +143,7 @@
     char* track_string;
     char* year_string;
     char* composer;
+    char* comment;
     int tracknum;
     int version;
     int layer;
@@ -190,8 +194,13 @@
     long songentryoffset;
     long rundbentryoffset;
 
+    /* associated file indicators */
+    short lyrics;
+    short albumart;
+
     /* runtime database fields */
     short rating;
+    short score;
     long playcount;
     long lastplayed;
     
