strdup to the rescue!

This commit is contained in:
David Sansome 2010-08-08 17:45:57 +00:00
parent a228e2b806
commit 58506b0469
4 changed files with 8 additions and 22 deletions

View File

@ -444,19 +444,17 @@ void Song::InitFromLastFM(const lastfm::Track& track) {
}
void Song::ToItdb(Itdb_Track *track) const {
using Utilities::CopyStr;
CopyStr(d->title_, &track->title);
CopyStr(d->album_, &track->album);
CopyStr(d->artist_, &track->artist);
CopyStr(d->albumartist_, &track->albumartist);
CopyStr(d->composer_, &track->composer);
track->title = strdup(d->title_.toUtf8().constData());
track->album = strdup(d->album_.toUtf8().constData());
track->artist = strdup(d->artist_.toUtf8().constData());
track->albumartist = strdup(d->albumartist_.toUtf8().constData());
track->composer = strdup(d->composer_.toUtf8().constData());
track->track_nr = d->track_;
track->cd_nr = d->disc_;
track->BPM = d->bpm_;
track->year = d->year_;
CopyStr(d->genre_, &track->genre);
CopyStr(d->comment_, &track->comment);
track->genre = strdup(d->genre_.toUtf8().constData());
track->comment = strdup(d->comment_.toUtf8().constData());
track->compilation = d->compilation_;
track->tracklen = d->length_ * 1000;
track->bitrate = d->bitrate_;

View File

@ -135,14 +135,4 @@ void RemoveRecursive(const QString& path) {
dir.rmdir(path);
}
void CopyStr(const QString& str, char** dest_p) {
Q_ASSERT(*dest_p == NULL);
const QByteArray data = str.toUtf8();
const int size = data.size() + 1;
char* dest = new char[size];
std::copy(data.constData(), data.constData() + size, dest);
*dest_p = dest;
}
} // namespace

View File

@ -29,8 +29,6 @@ namespace Utilities {
QString MakeTempDir();
void RemoveRecursive(const QString& path);
void CopyStr(const QString& str, char** dest_p);
}
#endif // UTILITIES_H

View File

@ -107,7 +107,7 @@ bool AfcDevice::CopyToStorage(
qDebug() << track->filetype_marker;
// Set the filename
Utilities::CopyStr(dest, &track->ipod_path);
track->ipod_path = strdup(dest.toUtf8().constData());
itdb_filename_fs2ipod(track->ipod_path);
qDebug() << track->ipod_path;