void DataStore::addSongToLibrary(const Phonon::MediaSource& song, QSqlQuery &addQuery){ QString fileName = song.fileName(); QString songName; QString artistName; QString albumName; QString genre; int track; int duration; TagLib::FileRef f(fileName.toStdString().c_str()); if(!f.isNull() && f.tag() && f.audioProperties()){ TagLib::Tag *tag = f.tag(); songName = TStringToQString(tag->title()); artistName = TStringToQString(tag->artist()); albumName = TStringToQString(tag->album()); genre = TStringToQString(tag->genre()); duration = f.audioProperties()->length(); track = tag->track(); } else{ //TODO throw error return; } if(songName == ""){ songName = unknownSongTitle(); } if(artistName == ""){ artistName = unknownSongArtist(); } if(albumName == ""){ albumName = unknownSongAlbum(); } if(genre == ""){ genre = unknownGenre(); } Logger::instance()->log("adding song with title: " + songName + " to database"); library_song_id_t hostId =-1; addQuery.bindValue(":song", songName); addQuery.bindValue(":artist", artistName); addQuery.bindValue(":album", albumName); addQuery.bindValue(":genre", genre); addQuery.bindValue(":track", track); addQuery.bindValue(":file", fileName); addQuery.bindValue(":duration", duration); EXEC_INSERT( "Failed to add song library" << songName.toStdString(), addQuery, hostId, library_song_id_t) }
void MediaObject::setSource(const Phonon::MediaSource &source) { if (m_state == Phonon::PlayingState) { setError(Phonon::NormalError, QLatin1String("source changed while playing")); stop(); } m_source = source; m_hasSource = true; m_sourceIsValid = false; emit currentSourceChanged(source); if (source.type() == Phonon::MediaSource::LocalFile) { if (!openWaveFile(source.fileName())) { setError(Phonon::FatalError, QLatin1String("cannot open media file")); return ; } } else if (source.type() == Phonon::MediaSource::Stream) { if (m_stream) delete m_stream; m_stream = new IOWrapper(this, source); m_mediaSize = m_stream->size(); } else if (source.type() == Phonon::MediaSource::Url) { if (!openWaveFile(source.url().toLocalFile())) { setError(Phonon::FatalError, QLatin1String("cannot open media file")); return ; } } else { setError(Phonon::FatalError, QLatin1String("type of source not supported")); return ; } setState(Phonon::LoadingState); if (!readHeader()) setError(Phonon::FatalError, QLatin1String("invalid header")); else if (!getWaveOutDevice()) setError(Phonon::FatalError, QLatin1String("No waveOut device available")); else if (!fillBuffers()) setError(Phonon::FatalError, QLatin1String("no data for buffering")); else if (!prepareBuffers()) setError(Phonon::FatalError, QLatin1String("cannot prepare buffers")); else m_sourceIsValid = true; if (m_sourceIsValid) setState(Phonon::StoppedState); }
void FindSubtitles::findSubtitles() { Phonon::MediaObject * mediaObject = quarkPlayer().currentMediaObject(); if (mediaObject) { Phonon::MediaSource source = mediaObject->currentSource(); QString fileName(source.fileName()); static FindSubtitlesWindow * findSubtitlesWindow = NULL; if (!findSubtitlesWindow) { findSubtitlesWindow = new FindSubtitlesWindow(MainWindowFactory::mainWindow()); connect(findSubtitlesWindow, SIGNAL(subtitleDownloaded(const QString &)), SLOT(loadSubtitle(const QString &))); } findSubtitlesWindow->setMovieFileName(fileName); findSubtitlesWindow->setLanguage(Config::instance().language()); findSubtitlesWindow->show(); } }
void MusicPlayer::addFileRow(const Phonon::MediaSource &mediaSource) { QMap<QString, QString> metaData = metaInformationResolver->metaData(); QString title = ""; //Use meta data for title if it exists, else create title from file name if(metaData.value("TITLE") != NULL) title = metaData.value("TITLE") + " - " + metaData.value("ARTIST"); else { //Split off dirs from the title QStringList titleParts = mediaSource.fileName().split("/", QString::SkipEmptyParts); if(titleParts.length() > 0) { title = titleParts.last(); //Split off the file extension from the title titleParts = title.split(".", QString::SkipEmptyParts); if(titleParts.length() > 0) { title = titleParts[0]; } //Turn underscores to spaces in title title.replace("_", " "); title.replace("-", " - "); // Get rid of extra spaces and make first letter of every word uppercase titleParts = title.split(" ", QString::SkipEmptyParts); title = ""; foreach(QString part, titleParts) { part = part.toLower(); part[0] = part[0].toUpper(); title += part + " "; } }