~ubuntu-branches/ubuntu/saucy/clementine/saucy

« back to all changes in this revision

Viewing changes to src/playlistparsers/parserbase.cpp

  • Committer: Package Import Robot
  • Author(s): Thomas PIERSON
  • Date: 2012-01-01 20:43:39 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20120101204339-lsb6nndwhfy05sde
Tags: 1.0.1+dfsg-1
New upstream release. (Closes: #653926, #651611, #657391)

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
{
29
29
}
30
30
 
31
 
bool ParserBase::ParseTrackLocation(const QString& filename_or_url,
32
 
                                    const QDir& dir, Song* song) const {
 
31
void ParserBase::LoadSong(const QString& filename_or_url, qint64 beginning,
 
32
                          const QDir& dir, Song* song) const {
 
33
  if (filename_or_url.isEmpty()) {
 
34
    return;
 
35
  }
 
36
 
 
37
  QString filename = filename_or_url;
 
38
 
33
39
  if (filename_or_url.contains(QRegExp("^[a-z]+://"))) {
34
 
    // Looks like a url.
35
 
    QUrl temp(filename_or_url);
36
 
    if (temp.isValid()) {
37
 
      song->set_filename(temp.toString());
 
40
    QUrl url(filename_or_url);
 
41
    if (url.scheme() == "file") {
 
42
      filename = url.toLocalFile();
 
43
    } else {
 
44
      song->set_url(QUrl(filename_or_url));
38
45
      song->set_filetype(Song::Type_Stream);
39
46
      song->set_valid(true);
40
 
      return true;
41
 
    } else {
42
 
      return false;
 
47
      return;
43
48
    }
44
49
  }
45
50
 
46
 
  // Should be a local path.
47
 
  if (QDir::isAbsolutePath(filename_or_url)) {
48
 
    // Absolute path.
49
 
    // Fix windows \, eg. C:\foo -> C:/foo.
50
 
    song->set_filename(QDir::fromNativeSeparators(filename_or_url));
 
51
  // Convert native separators for Windows paths
 
52
  filename = QDir::fromNativeSeparators(filename);
 
53
 
 
54
  // Make the path absolute
 
55
  if (!QDir::isAbsolutePath(filename)) {
 
56
    filename = dir.absoluteFilePath(filename);
 
57
  }
 
58
 
 
59
  // Use the canonical path
 
60
  if (QFile::exists(filename)) {
 
61
    filename = QFileInfo(filename).canonicalFilePath();
 
62
  }
 
63
 
 
64
  const QUrl url = QUrl::fromLocalFile(filename);
 
65
 
 
66
  // Search in the library
 
67
  Song library_song;
 
68
  if (library_) {
 
69
    library_song = library_->GetSongByUrl(url, beginning);
 
70
  }
 
71
 
 
72
  // If it was found in the library then use it, otherwise load metadata from
 
73
  // disk.
 
74
  if (library_song.is_valid()) {
 
75
    *song = library_song;
51
76
  } else {
52
 
    // Relative path.
53
 
    QString proper_path = QDir::fromNativeSeparators(filename_or_url);
54
 
    QString absolute_path = dir.absoluteFilePath(proper_path);
55
 
    song->set_filename(absolute_path);
 
77
    song->InitFromFile(filename, -1);
56
78
  }
57
 
  return true;
58
 
}
59
 
 
60
 
QString ParserBase::MakeRelativeTo(const QString& filename_or_url,
61
 
                                   const QDir& dir) const {
62
 
  if (filename_or_url.contains(QRegExp("^[a-z]+://")))
63
 
    return filename_or_url;
64
 
 
65
 
  if (QDir::isAbsolutePath(filename_or_url)) {
66
 
    QString relative = dir.relativeFilePath(filename_or_url);
 
79
}
 
80
 
 
81
Song ParserBase::LoadSong(const QString& filename_or_url, qint64 beginning, const QDir& dir) const {
 
82
  Song song;
 
83
  LoadSong(filename_or_url, beginning, dir, &song);
 
84
  return song;
 
85
}
 
86
 
 
87
QString ParserBase::URLOrRelativeFilename(const QUrl& url, const QDir& dir) const {
 
88
  if (url.scheme() != "file")
 
89
    return url.toString();
 
90
 
 
91
  const QString filename = url.toLocalFile();
 
92
  if (QDir::isAbsolutePath(filename)) {
 
93
    const QString relative = dir.relativeFilePath(filename);
67
94
 
68
95
    if (!relative.contains(".."))
69
96
      return relative;
70
97
  }
71
 
  return filename_or_url;
72
 
}
73
 
 
74
 
QString ParserBase::MakeUrl(const QString& filename_or_url) const {
75
 
  if (filename_or_url.contains(QRegExp("^[a-z]+://"))) {
76
 
    return filename_or_url;
77
 
  }
78
 
 
79
 
  return QUrl::fromLocalFile(filename_or_url).toString();
80
 
}
81
 
 
82
 
Song ParserBase::LoadLibrarySong(const QString& filename_or_url, qint64 beginning) const {
83
 
  if (!library_)
84
 
    return Song();
85
 
 
86
 
  QFileInfo info;
87
 
 
88
 
  if (filename_or_url.contains("://"))
89
 
    info.setFile(QUrl(filename_or_url).path());
90
 
  else
91
 
    info.setFile(filename_or_url);
92
 
 
93
 
  return library_->GetSongByFilename(info.canonicalFilePath(), beginning);
 
98
  return filename;
94
99
}