oopapidocs
2.0
|
00001 #include "metadatavalue.h" 00002 #include <QDebug> 00003 #include <QTextStream> 00004 00005 QString MetaDataValue::fileName() const { 00006 return m_Url.toLocalFile(); 00007 } 00008 00009 MetaDataValue::MetaDataValue(const MetaDataValue &other) { 00010 *this = other; 00011 00012 } 00013 00014 MetaDataValue& MetaDataValue::operator=(const MetaDataValue& other) { 00015 if (this == &other) return *this; 00016 m_isNull = other.isNull(); 00017 if (m_isNull) return *this; 00018 setImage(other.image()); 00019 setUrl(other.url()); 00020 setTrackTitle(other.trackTitle()); 00021 setArtist(other.artist()); 00022 setAlbumTitle(other.albumTitle()); 00023 setTrackNumber(other.trackNumber()); 00024 setTrackTime(other.trackTime()); 00025 setComment(other.comment()); 00026 setGenre(other.genre()); 00027 setPreference(other.preference()); 00028 return *this; 00029 } 00030 const QImage& MetaDataValue::image() const { 00031 return m_Image; 00032 } 00033 00034 void MetaDataValue::setFileName(QString newFileName) { 00035 m_Url = QUrl::fromLocalFile(newFileName); 00036 m_isNull=false; 00037 } 00038 00039 QString MetaDataValue::genre() const { 00040 return m_Genre; 00041 } 00042 QString MetaDataValue::artist() const { 00043 return m_Artist; 00044 } 00045 QString MetaDataValue::albumTitle() const { 00046 return m_AlbumTitle; 00047 } 00048 QString MetaDataValue::trackTitle() const { 00049 if (m_TrackTitle == QString()) { 00050 return fileName(); 00051 } 00052 return m_TrackTitle; 00053 } 00054 QString MetaDataValue::trackNumber() const { 00055 return m_TrackNumber; 00056 } 00057 QTime MetaDataValue::trackTime() const { 00058 return m_TrackTime; 00059 } 00060 QString MetaDataValue::trackTimeString() const { 00061 QTime t=m_TrackTime; 00062 if (t.hour() > 0) { 00063 return t.toString("hh:mm:ss"); 00064 } 00065 else { 00066 return t.toString("m:ss"); 00067 } 00068 } 00069 00070 QString MetaDataValue::comment() const { 00071 return m_Comment; 00072 } 00073 00074 Preference MetaDataValue::preference() const { 00075 return m_Preference; 00076 } 00077 00078 void MetaDataValue::setPreference(const Preference & newPref) { 00079 m_Preference = newPref; 00080 } 00081 00082 void MetaDataValue::setGenre(const QString & newGenre) { 00083 m_Genre=newGenre; 00084 } 00085 00086 void MetaDataValue::setArtist(const QString & newArtist) { 00087 m_Artist = newArtist; 00088 } 00089 00090 void MetaDataValue::setTrackNumber( 00091 const QString& newTrackNumber) { 00092 m_TrackNumber = newTrackNumber; 00093 } 00094 00095 void MetaDataValue::setTrackTitle(const QString &newTitle) { 00096 m_isNull = false; 00097 m_TrackTitle = newTitle; 00098 } 00099 void MetaDataValue::setAlbumTitle(const QString &newAlbumTitle) { 00100 m_AlbumTitle = newAlbumTitle; 00101 } 00102 void MetaDataValue::setComment(const QString &newComment) { 00103 m_Comment = newComment; 00104 if (m_Comment.contains("\n")) m_Comment.replace("\n", " "); 00105 } 00106 bool operator==(const MetaDataValue& l, const MetaDataValue& other) { 00107 if (l.url() != other.url()) return false; 00108 if (l.trackTitle() != other.trackTitle()) return false; 00109 if (l.trackTimeString() != other.trackTimeString()) return false; 00110 if (l.albumTitle() != other.albumTitle()) return false; 00111 if (l.preference() != other.preference()) return false; 00112 if (l.comment() != other.comment()) return false; 00113 if (l.trackNumber() != other.trackNumber()) return false; 00114 if (l.artist() != other.artist()) return false; 00115 if (l.genre() != other.genre()) return false; 00116 if (l.isNull() != other.isNull()) return false; 00117 return true; 00118 } 00119 00120 //start id="textstream" 00121 00122 QTextStream& operator<< (QTextStream& os, const MetaDataValue& mdv) { 00123 QStringList sl; 00124 sl << mdv.url().toString() << mdv.trackTitle() << mdv.artist() 00125 << mdv.albumTitle() << mdv.trackNumber() 00126 << mdv.trackTime().toString("m:ss") << mdv.genre() 00127 << mdv.preference().toString() << mdv.comment(); 00128 00129 os << sl.join("\t") << "\n"; /* Output to TSV (tab-separated-values) */ 00130 return os; 00131 } 00132 00133 QTextStream& operator>> (QTextStream& is, MetaDataValue& mdv) { 00134 QString line = is.readLine(); 00135 QStringList fields = line.split("\t"); /* Read as TSV */ 00136 while (fields.size() < 9) { 00137 fields << ""; 00138 } 00139 mdv.m_isNull = false; 00140 mdv.setUrl(QUrl::fromUserInput(fields[0])); 00141 mdv.setTrackTitle(fields[1]); 00142 mdv.setArtist(fields[2]); 00143 mdv.setAlbumTitle(fields[3]); 00144 mdv.setTrackNumber(fields[4]); 00145 QTime t = QTime::fromString(fields[5], "m:ss"); 00146 mdv.setTrackTime(t); 00147 mdv.setGenre(fields[6]); 00148 Preference p(fields[7]); 00149 mdv.setPreference(p); 00150 mdv.setComment(fields[8]); 00151 return is; 00152 } 00153 //end 00154 //start id="datastream" 00155 QDataStream& operator<< (QDataStream& os, const MetaDataValue& mdv) { 00156 os << mdv.m_Url << mdv.trackTitle() << mdv.artist() 00157 << mdv.albumTitle() << mdv.trackNumber() << mdv.trackTime() 00158 << mdv.genre() << mdv.preference() << mdv.comment() 00159 << mdv.image(); 00160 return os; 00161 } 00162 00163 QDataStream& operator>> (QDataStream& is, MetaDataValue& mdv) { 00164 is >> mdv.m_Url >> mdv.m_TrackTitle >> mdv.m_Artist 00165 >> mdv.m_AlbumTitle >> mdv.m_TrackNumber >> mdv.m_TrackTime 00166 >> mdv.m_Genre >> mdv.m_Preference >> mdv.m_Comment 00167 >> mdv.m_Image; 00168 mdv.m_isNull= false; 00169 return is; 00170 } 00171 //end 00172 00173 bool MetaDataValue::isNull() const { 00174 return m_isNull; 00175 } 00176 void MetaDataValue::setNull(bool n) { 00177 m_isNull = n; 00178 } 00179 QUrl MetaDataValue::url() const { 00180 return m_Url; 00181 } 00182 void MetaDataValue::setUrl(QUrl url) { 00183 m_Url = url; 00184 }