Exemplo n.º 1
0
SongList PlaylistParser::LoadFromDevice(QIODevice* device,
                                        const QString& path_hint,
                                        const QDir& dir_hint) const {
  // Find a parser that supports this data
  ParserBase* parser = ParserForMagic(device->peek(kMagicSize));
  if (!parser) {
    return SongList();
  }

  return parser->Load(device, path_hint, dir_hint);
}
Exemplo n.º 2
0
void SongLoader::LoadLocalAsync(const QString& filename) {
  // First check to see if it's a directory - if so we will load all the songs
  // inside right away.
  if (QFileInfo(filename).isDir()) {
    LoadLocalDirectory(filename);
    return;
  }

  // It's a local file, so check if it looks like a playlist.
  // Read the first few bytes.
  QFile file(filename);
  if (!file.open(QIODevice::ReadOnly)) return;
  QByteArray data(file.read(PlaylistParser::kMagicSize));

  ParserBase* parser = playlist_parser_->ParserForMagic(data);
  if (!parser) {
    // Check the file extension as well, maybe the magic failed, or it was a
    // basic M3U file which is just a plain list of filenames.
    parser = playlist_parser_->ParserForExtension(
        QFileInfo(filename).suffix().toLower());
  }

  if (parser) {
    qLog(Debug) << "Parsing using" << parser->name();

    // It's a playlist!
    LoadPlaylist(parser, filename);
    return;
  }

  // Check if it's a cue file
  QString matching_cue = filename.section('.', 0, -2) + ".cue";
  if (QFile::exists(matching_cue)) {
    // it's a cue - create virtual tracks
    QFile cue(matching_cue);
    cue.open(QIODevice::ReadOnly);

    SongList song_list = cue_parser_->Load(&cue, matching_cue,
                                           QDir(filename.section('/', 0, -2)));
    for (Song song : song_list) {
      if (song.is_valid()) songs_ << song;
    }
    return;
  }

  // Assume it's just a normal file
  Song song;
  song.InitFromFilePartial(filename);
  if (song.is_valid()) {
    songs_ << song;
  }
}
Exemplo n.º 3
0
SongList PlaylistParser::LoadFromFile(const QString& filename) const {
  QFileInfo info(filename);

  // Find a parser that supports this file extension
  ParserBase* parser = ParserForExtension(info.suffix());
  if (!parser) {
    qLog(Warning) << "Unknown filetype:" << filename;
    return SongList();
  }

  // Open the file
  QFile file(filename);
  file.open(QIODevice::ReadOnly);

  return parser->Load(&file, filename, info.absolutePath());
}
Exemplo n.º 4
0
DiffModelList* Parser::parse( QStringList& diffLines, bool* malformed )
{
	/* Basically determine the generator then call the parse method */
	ParserBase* parser;

	m_generator = determineGenerator( diffLines );

	int nol = cleanUpCrap( diffLines );
	qCDebug(LIBKOMPAREDIFF2) << "Cleaned up " << nol << " line(s) of crap from the diff...";

	switch( m_generator )
	{
	case Kompare::CVSDiff :
		qCDebug(LIBKOMPAREDIFF2) << "It is a CVS generated diff...";
		parser = new CVSDiffParser( m_list, diffLines );
		break;
	case Kompare::Diff :
		qCDebug(LIBKOMPAREDIFF2) << "It is a diff generated diff...";
		parser = new DiffParser( m_list, diffLines );
		break;
	case Kompare::Perforce :
		qCDebug(LIBKOMPAREDIFF2) << "It is a Perforce generated diff...";
		parser = new PerforceParser( m_list, diffLines );
		break;
	default:
		// Nothing to delete, just leave...
		return 0L;
	}

	m_format = parser->format();
	DiffModelList* modelList = parser->parse( malformed );
	if ( modelList )
	{
		qCDebug(LIBKOMPAREDIFF2) << "Modelcount: " << modelList->count();
		DiffModelListIterator modelIt = modelList->begin();
		DiffModelListIterator mEnd    = modelList->end();
		for ( ; modelIt != mEnd; ++modelIt )
		{
			qCDebug(LIBKOMPAREDIFF2) << "Hunkcount:  " << (*modelIt)->hunkCount();
			qCDebug(LIBKOMPAREDIFF2) << "Diffcount:  " << (*modelIt)->differenceCount();
		}
	}

	delete parser;

	return modelList;
}
Exemplo n.º 5
0
void PlaylistParser::Save(const SongList& songs, const QString& filename,
                          Playlist::Path path_type) const {
  QFileInfo info(filename);

  // Find a parser that supports this file extension
  ParserBase* parser = ParserForExtension(info.suffix());
  if (!parser) {
    qLog(Warning) << "Unknown filetype:" << filename;
    return;
  }

  // Open the file
  QFile file(filename);
  file.open(QIODevice::WriteOnly);

  return parser->Save(songs, &file, info.absolutePath(), path_type);
}
Exemplo n.º 6
0
SongLoader::Result SongLoader::LoadLocal(const QString& filename) {
  qLog(Debug) << "Loading local file" << filename;

  // First check to see if it's a directory - if so we can load all the songs
  // inside right away.
  if (QFileInfo(filename).isDir()) {
    ConcurrentRun::Run<void>(
        &thread_pool_,
        std::bind(&SongLoader::LoadLocalDirectoryAndEmit, this, filename));
    return WillLoadAsync;
  }

  // It's a local file, so check if it looks like a playlist.
  // Read the first few bytes.
  QFile file(filename);
  if (!file.open(QIODevice::ReadOnly)) return Error;
  QByteArray data(file.read(PlaylistParser::kMagicSize));

  ParserBase* parser = playlist_parser_->ParserForMagic(data);
  if (!parser) {
    // Check the file extension as well, maybe the magic failed, or it was a
    // basic M3U file which is just a plain list of filenames.
    parser = playlist_parser_->ParserForExtension(QFileInfo(filename).suffix());
  }

  if (parser) {
    qLog(Debug) << "Parsing using" << parser->name();

    // It's a playlist!
    ConcurrentRun::Run<void>(
        &thread_pool_,
        std::bind(&SongLoader::LoadPlaylistAndEmit, this, parser, filename));
    return WillLoadAsync;
  }

  // Not a playlist, so just assume it's a song
  QUrl url = QUrl::fromLocalFile(filename);

  LibraryQuery query;
  query.SetColumnSpec("%songs_table.ROWID, " + Song::kColumnSpec);
  query.AddWhere("filename", url.toEncoded());

  SongList song_list;

  if (library_->ExecQuery(&query) && query.Next()) {
    // we may have many results when the file has many sections
    do {
      Song song;
      song.InitFromQuery(query, true);

      song_list << song;
    } while (query.Next());
  } else {
    QString matching_cue = filename.section('.', 0, -2) + ".cue";

    if (QFile::exists(matching_cue)) {
      // it's a cue - create virtual tracks
      QFile cue(matching_cue);
      cue.open(QIODevice::ReadOnly);

      song_list = cue_parser_->Load(&cue, matching_cue,
                                    QDir(filename.section('/', 0, -2)));
    } else {
      // it's a normal media file, load it asynchronously.
      TagReaderReply* reply = TagReaderClient::Instance()->ReadFile(filename);
      NewClosure(reply, SIGNAL(Finished(bool)), this,
                 SLOT(LocalFileLoaded(TagReaderReply*)), reply);

      return WillLoadAsync;
    }
  }

  for (const Song& song : song_list) {
    if (song.is_valid()) {
      songs_ << song;
    }
  }

  return Success;
}