libsaria: Return default track values in error case

If we can't find the inode, I return some default values to the UI to
keep it happy (and clear out the information from the previous song).
This commit is contained in:
Bryan Schumaker 2011-10-29 16:18:15 -04:00
parent c894815dad
commit 049f91e514
3 changed files with 29 additions and 8 deletions

View File

@ -11,6 +11,7 @@ class Track
TrackTag *tags;
public:
Track();
Track(ino_t, TrackTag *);
~Track();

View File

@ -18,9 +18,11 @@ namespace libsaria
void current_track(void (*func)(Track &))
{
ino_t inode;
/* TODO: Set to blank in error cases */
if (current_inode(inode) < 0)
if (current_inode(inode) < 0) {
Track blank;
func(blank);
return;
}
library::get_info(inode, func);
}

View File

@ -2,6 +2,12 @@
#include <libsaria/track.h>
#include <libsaria/tags.h>
Track::Track()
{
inode = 0;
tags = NULL;
}
Track::Track(ino_t ino, TrackTag *tag)
{
inode = ino;
@ -19,30 +25,42 @@ ino_t Track::get_inode()
unsigned int Track::get_track()
{
return tags->get_track();
if (tags)
return tags->get_track();
return 0;
}
string Track::get_title()
{
return tags->get_title();
if (tags)
return tags->get_title();
return "";
}
string Track::get_lenstr()
{
return tags->get_lenstr();
if (tags)
return tags->get_lenstr();
return "";
}
string Track::get_artist()
{
return tags->get_artist();
if (tags)
return tags->get_artist();
return "";
}
string Track::get_album()
{
return tags->get_album();
if (tags)
return tags->get_album();
return "";
}
unsigned int Track::get_year()
{
return tags->get_year();
if (tags)
return tags->get_year();
return 0;
}