📄 qmsongitem.cpp
字号:
QmMarkManager::instance()->insert(filePath()); else QmMarkManager::instance()->remove(filePath()); repaint();}/*! Sets the bitrate to \a bitrate.*/voidQmSongItem::setBitrate( int bitrate){ m_Bitrate = bitrate;}/*! Sets the rating to \a rating. */voidQmSongItem::setRating( int rating){ m_Rating = rating; }/*! Increases the rating by one and returns the new value. \sa decRating()*/intQmSongItem::incRating(){ return ++m_Rating;}/*! Decreases the rating by one and returns the new value. \sa incRating()*/intQmSongItem::decRating(){ return --m_Rating;}/*! \sa resetPlayed() */intQmSongItem::played() const{ return m_Played;}/*! \sa played() */voidQmSongItem::resetPlayed(){ m_Played = 0;}/*! */voidQmSongItem::setVariableBitrate( bool vbr){ m_VariableBitrate = vbr;}/*!*/voidQmSongItem::setDisplayFormat( const QString &format, const QString &multiFormat){ setDisplayFormat(format.latin1(), multiFormat.latin1());}/*! Sets the format of the name displayed in the playlist to \a format. Code licensed from Espen Skoglund <esk@ira.uka.de>, and H鍁ard Kv錶en <havardk@xmms.org> of http://www.xmms.org.*/voidQmSongItem::setDisplayFormat( const char* singleFormat, const char* multiFormat){ char c, *p, outbuf[256], convert[16], *string; int numdigits, numpr, val, size, i; int width, precision; bool f_left, f_space, f_zero, more_flags; bool did_output = false; char digits[] = "0123456789"; QString tmp; const char *format = m_MultiArtistAlbum ? multiFormat : singleFormat; #define PUTCH(ch) \ do { \ if ( size-- <= 0 ) \ goto Done; \ *p++ = (ch); \ } while (0)#define LEFTPAD(num) \ do { \ int cnt = (num); \ if ( ! f_left && cnt > 0 ) \ while ( cnt-- > 0 ) \ PUTCH(f_zero ? '0' : ' '); \ } while (0)#define RIGHTPAD(num) \ do { \ int cnt = (num); \ if ( f_left && cnt > 0 ) \ while ( cnt-- > 0 ) \ PUTCH( ' ' ); \ } while (0) size = sizeof (outbuf) - 1; p = outbuf; if ( format == 0 ) return; while (size > 0) { /* Copy characters until we encounter '%'. */ while ((c = *format++) != '%') { if (size-- <= 0 || c == '\0') goto Done; *p++ = c; } f_left = f_space = f_zero = false; more_flags = true; /* Parse flags. */ while (more_flags) { switch (*format) { case '-': f_left = true; format++; break; case ' ': f_space = true; format++; break; case '0': f_zero = true; format++; break; default: more_flags = false; break; } } /* Parse field width. */ if ((c = *format) >= '0' && c <= '9') { width = 0; while ((c = *format++) >= '0' && c <= '9') { width *= 10; width += c - '0'; } format--; } else width = -1; /* Parse precision. */ if (*format == '.') { if ((c = *++format) >= '0' && c <= '9') { precision = 0; while ((c = *format++) >= '0' && c <= '9') { precision *= 10; precision += c - '0'; } format--; } else precision = -1; } else precision = -1; /* Parse format conversion. */ switch (c = *format++) { case 'a': string = m_Album.isEmpty() ? 0 : const_cast<char *>(m_Album.latin1()); goto Print_string; case 'c': string = m_Comment.isEmpty() ? 0 : const_cast<char *>(m_Comment.latin1()); goto Print_string;// case 'd':// string = VS(date);// goto Print_string; case 'e': tmp = m_File.extension(false); string = tmp.isEmpty() ? 0 : const_cast<char *>(tmp.latin1()); goto Print_string; case 'f': tmp = m_File.fileName(); string = tmp.isEmpty() ? 0 : const_cast<char *>(tmp.latin1()); goto Print_string; case 'F': tmp = m_File.filePath(); string = tmp.isEmpty() ? 0 : const_cast<char *>(tmp.latin1()); goto Print_string;// case 'g':// string = VS(genre);// goto Print_string; case 'n': bool ok; val = m_CdPosition.toInt(&ok); if (!ok) val = 0; goto Print_number; case 'b': val = m_Bitrate; goto Print_number; case 'p': string = m_Artist.isEmpty() ? 0 : const_cast<char *>(m_Artist.latin1()); goto Print_string; case 't': string = m_Title.isEmpty() ? 0 : const_cast<char *>(m_Title.latin1()); Print_string: if ( string == NULL ) break; did_output = true; numpr = 0; if (width > 0) { /* Calculate printed size. */ numpr = strlen(string); if (precision >= 0 && precision < numpr) numpr = precision; LEFTPAD(width - numpr); } /* Insert string. */ if (precision >= 0) { while (precision-- > 0 && (c = *string++) != '\0') PUTCH(c); } else { while ((c = *string++) != '\0') PUTCH(c); } RIGHTPAD(width - numpr); break; case 'y': val = m_Year; Print_number: if ( val == 0 ) break; if ( c != 'N' ) did_output = true; /* Create reversed number string. */ numdigits = 0; do { convert[numdigits++] = digits[val % 10]; val /= 10; } while (val > 0); numpr = numdigits > precision ? numdigits : precision; /* Insert left padding. */ if (!f_left && width > numpr) { if (f_zero) numpr = width; else for (i = width - numpr; i-- > 0;) PUTCH(' '); } /* Insert zero padding. */ for (i = numpr - numdigits; i-- > 0;) PUTCH('0'); /* Insert number. */ while (numdigits > 0) PUTCH(convert[--numdigits]); RIGHTPAD(width - numpr); break; case '%': PUTCH('%'); break; default: PUTCH('%'); PUTCH(c); break; } } Done: *p = '\0'; if (did_output) m_DisplayString = static_cast<const char *>(outbuf);}/*! Sets the display string to \a display. \sa displayString() */voidQmSongItem::setDisplayString( const QString& display){ m_DisplayString = display;}/*! \return The display string. \sa setDisplayString(const QString&) */QStringQmSongItem::displayString() const{ return text(0);}/*! Sets the title of this song to \a title. This used instead of the filename if non-empty.*/voidQmSongItem::setSongTitle( const QString &title){ m_Title = title;}/*! Creates and returns a songinfo object based on this song. \return The songinfo object. Will never be null. \warning The caller is responsible for deleting the returned object.*/QmSongInfo*QmSongItem::info() const{ return QmSongInfo::create(m_File.filePath());}/*! \return True if this song is bad, false otherwise. \todo Cache flag?*/boolQmSongItem::isBad() const{ return QmMarkManager::instance()->isBad(filePath());}/*! Saves the song to \a out as XML. */voidQmSongItem::writeXml( QTextStream &out) const{ out << "<song>\n"; out << "<path><![CDATA[" << m_File.filePath() << "]]></path>\n"; if ( ! m_CdPosition.isEmpty()) out << "<cd-position>" << m_CdPosition << "</cd-position>\n"; if (m_LengthSeconds != 0) out << "<length>" << m_LengthSeconds << "</length>\n"; if ( ! m_Artist.isEmpty()) out << "<artist><![CDATA[" << m_Artist << "]]></artist>\n"; if ( ! m_Title.isEmpty()) out << "<title><![CDATA[" << m_Title << "]]></title>\n"; if ( ! m_Album.isEmpty()) out << "<album><![CDATA[" << m_Album << "]]></album>\n"; if (m_Bitrate > 0) out << "<bitrate>" << m_Bitrate << "</bitrate>\n"; if (m_VariableBitrate) out << "<vbr>true</vbr>\n"; if (m_MultiArtistAlbum) out << "<multi-artist>true</multi-artist>\n"; if ( ! m_Comment.isEmpty()) out << "<comment>" << m_Comment << "</comment>\n"; if ( ! m_DisplayString.isEmpty()) out << "<display-string><![CDATA[" << m_DisplayString << "]]></display-string>\n"; if (m_Year > 0) out << "<year>" << m_Year << "</year>\n"; out << "</song>\n"; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -