***************************************************************************/
#include <tbytevectorlist.h>
+#include <id3v2tag.h>
#include "textidentificationframe.h"
};
////////////////////////////////////////////////////////////////////////////////
-// public members
+// TextIdentificationFrame public members
////////////////////////////////////////////////////////////////////////////////
TextIdentificationFrame::TextIdentificationFrame(const ByteVector &type, String::Type encoding) :
}
////////////////////////////////////////////////////////////////////////////////
-// protected members
+// TextIdentificationFrame protected members
////////////////////////////////////////////////////////////////////////////////
void TextIdentificationFrame::parseFields(const ByteVector &data)
}
////////////////////////////////////////////////////////////////////////////////
-// private members
+// TextIdentificationFrame private members
////////////////////////////////////////////////////////////////////////////////
TextIdentificationFrame::TextIdentificationFrame(const ByteVector &data, Header *h) : Frame(h)
d = new TextIdentificationFramePrivate;
parseFields(fieldData(data));
}
+
+////////////////////////////////////////////////////////////////////////////////
+// UserTextIdentificationFrame public members
+////////////////////////////////////////////////////////////////////////////////
+
+UserTextIdentificationFrame::UserTextIdentificationFrame(String::Type encoding) :
+ TextIdentificationFrame("TXXX", encoding),
+ d(0)
+{
+ StringList l;
+ l.append(String::null);
+ l.append(String::null);
+ setText(l);
+}
+
+
+UserTextIdentificationFrame::UserTextIdentificationFrame(const ByteVector &data) :
+ TextIdentificationFrame(data)
+{
+
+}
+
+String UserTextIdentificationFrame::toString() const
+{
+ return "[" + description() + "] " + fieldList().toString();
+}
+
+String UserTextIdentificationFrame::description() const
+{
+ return !TextIdentificationFrame::fieldList().isEmpty()
+ ? TextIdentificationFrame::fieldList().front()
+ : String::null;
+}
+
+StringList UserTextIdentificationFrame::fieldList() const
+{
+ StringList l = TextIdentificationFrame::fieldList();
+
+ if(!l.isEmpty()) {
+ StringList::Iterator it = l.begin();
+ l.erase(it);
+ }
+
+ return l;
+}
+
+void UserTextIdentificationFrame::setText(const String &text)
+{
+ if(description().isEmpty())
+ setDescription(String::null);
+
+ TextIdentificationFrame::setText(StringList(description()).append(text));
+}
+
+void UserTextIdentificationFrame::setText(const StringList &fields)
+{
+ if(description().isEmpty())
+ setDescription(String::null);
+
+ TextIdentificationFrame::setText(StringList(description()).append(fields));
+}
+
+void UserTextIdentificationFrame::setDescription(const String &s)
+{
+ StringList l = fieldList();
+
+ if(l.isEmpty())
+ l.append(s);
+ else
+ l[0] = s;
+
+ TextIdentificationFrame::setText(l);
+}
+
+UserTextIdentificationFrame *find(ID3v2::Tag *tag, const String &description) // static
+{
+ FrameList l = tag->frameList("TXXX");
+ for(FrameList::Iterator it = l.begin(); it != l.end(); ++it) {
+ UserTextIdentificationFrame *f = dynamic_cast<UserTextIdentificationFrame *>(*it);
+ if(f && f->description() == description)
+ return f;
+ }
+ return 0;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// UserTextIdentificationFrame private members
+////////////////////////////////////////////////////////////////////////////////
+
+UserTextIdentificationFrame::UserTextIdentificationFrame(const ByteVector &data, Header *h) :
+ TextIdentificationFrame(data, h)
+{
+
+}
namespace ID3v2 {
+ class Tag;
+
//! An ID3v2 text identification frame implementation
/*!
virtual void parseFields(const ByteVector &data);
virtual ByteVector renderFields() const;
- private:
/*!
* The constructor used by the FrameFactory.
*/
TextIdentificationFrame(const ByteVector &data, Header *h);
+
+ private:
TextIdentificationFrame(const TextIdentificationFrame &);
TextIdentificationFrame &operator=(const TextIdentificationFrame &);
TextIdentificationFramePrivate *d;
};
+ /*!
+ * This is a specialization of text identification frames that allows for
+ * user defined entries. Each entry has a description in addition to the
+ * normal list of fields that a text identification frame has.
+ *
+ * This description identifies the frame and must be unique.
+ */
+
+ class UserTextIdentificationFrame : public TextIdentificationFrame
+ {
+ friend class FrameFactory;
+
+ public:
+ /*!
+ * Constructs an empty user defined text identification frame. For this to be
+ * a useful frame both a description and text must be set.
+ */
+ explicit UserTextIdentificationFrame(String::Type encoding = String::Latin1);
+
+ /*!
+ * Creates a frame based on \a data.
+ */
+ explicit UserTextIdentificationFrame(const ByteVector &data);
+
+ virtual String toString() const;
+
+ /*!
+ * Returns the description for this frame.
+ */
+ String description() const;
+
+ /*!
+ * Sets the description of the frame to \a s. \a s must be unique. You can
+ * check for the presense of another user defined text frame of the same type
+ * using find() and testing for null.
+ */
+ void setDescription(const String &s);
+
+ StringList fieldList() const;
+ void setText(const String &text);
+ void setText(const StringList &fields);
+
+ /*!
+ * Searches for the user defined text frame with the description \a description
+ * in \a tag. This returns null if no matching frames were found.
+ */
+ static UserTextIdentificationFrame *find(Tag *tag, const String &description);
+
+ private:
+ UserTextIdentificationFrame(const ByteVector &data, Header *h);
+ UserTextIdentificationFrame(const TextIdentificationFrame &);
+ UserTextIdentificationFrame &operator=(const UserTextIdentificationFrame &);
+
+ class UserTextIdentificationFramePrivate;
+ UserTextIdentificationFramePrivate *d;
+ };
+
}
}
#endif