PlaylistManager::PlaylistManager(QWidget* parent)
: parentWidget (parent), lastMetaRead (-1)
{
- allowedExtensions << "mp3" << "ogg" << "wav" << "wmv" << "wma";
-// qDebug () << Phonon::BackendCapabilities::availableMimeTypes();
+ allowedExtensions << "mp3" << "ogg" << "wav" << "wmv" << "wma" << "flac";
metaInformationResolver = new Phonon::MediaObject(parent);
connect(metaInformationResolver, SIGNAL(stateChanged(Phonon::State,Phonon::State)),
this, SLOT(metaStateChanged(Phonon::State,Phonon::State)));
void PlaylistManager::parseAndAddFolder(const QString &dir, bool recursive)
{
QStringList filters;
-// filters << "*.mp3";
QStringList files = QDir (dir).entryList(filters);
if (files.isEmpty())
return;
- qDebug () << "Parsing folder " << dir;
- //settings.setValue("LastFolder", dir);
int index = items.size();
foreach (QString string, files)
{
items.append(PlaylistItem (PlaylistItem (fname)));
}
}
-// if (!items.isEmpty())
if (items.size () > index)
{
metaInformationResolver->setCurrentSource(items.at(index).source);
lastMetaRead = index;
}
- qDebug () << " SIZE: " << items.size ();
emit playlistChanged (index);
}
{
if (fileSupported(string) || string.toLower().startsWith("http"))
{
- qDebug () << "Adding " << string;
items.append(PlaylistItem (string));
}
}
-// if (!items.isEmpty())
if (items.size () > index)
{
metaInformationResolver->setCurrentSource(items.at(index).source);
void PlaylistManager::metaStateChanged(Phonon::State newState, Phonon::State oldState)
{
- qDebug () << "Meta state now " << newState << " old state " << oldState;
- // This is an ugly hack, since the metaInformationResolver doesn't properly load the assigned source when it's in the error state
+ // NOTE: This is an ugly hack, since the metaInformationResolver doesn't properly load the assigned source when it's in the error state
// In order to properly read the next file we have to set it as current source again when the resolver entered the stopped state after the error
static bool wasError = false;
if (wasError && newState == Phonon::StoppedState)
}
int index = lastMetaRead;
- qDebug () << "Reading meta info of " << metaInformationResolver->currentSource().fileName() << " => " << index;
QMap<QString, QString> metaData = metaInformationResolver->metaData();
- if (index >= 0 && newState != Phonon::ErrorState)
+ if (index >= 0 && newState != Phonon::ErrorState && index < items.size ())
{
items[index].artist = metaData.value("ARTIST");
items[index].title = metaData.value("TITLE");
items[index].genre = metaData.value("GENRE");
qDebug () << "Meta " << metaData;
qDebug () << "Info is: " << items[index].year << " - " << items[index].genre;*/
- if (metaData.isEmpty())
- qDebug () << "Detected to be empty: " << items[index].uri;
- else
+ if (!metaData.isEmpty())
items[index].playable = true;
emit itemUpdated (index);
}
}
}
-void PlaylistManager::savePlaylist(const QString& filenam)
+bool PlaylistManager::savePlaylist(const QString& filenam)
{
QString filename = filenam;
if (filename.isEmpty())
- return;
+ return false;
bool writepls = false;
if (filename.length() < 4 || (filename.right(4).toLower() != ".m3u" && filename.right(4).toLower() != ".pls"))
{
if (writepls)
f.write ("Version=2\n");
f.close ();
+ return true;
}
catch (...)
{
-// QMessageBox::critical(this, "Write error", "Could not write playlist file", QMessageBox::Ok);
}
+ return false;
}
void PlaylistManager::loadPlaylist(const QString& filename)
void PlaylistManager::appendPlaylist(const QString& filename)
{
- qDebug () << "Attempting to load playlist: " << filename;
QFile f(filename);
if (!f.open (QFile::ReadOnly))
return;
{
continue;
}
- qDebug () << "Load " << l;
items.append(PlaylistItem (l));
}
}
void PlaylistManager::appendPlaylistPLS(const QString& filename)
{
- qDebug () << "Attempting to load playlist: " << filename;
QFile f(filename);
if (!f.open (QFile::ReadOnly))
return;
{
continue;
}
- qDebug () << "PLS " << l;
if (l.trimmed().toLower().left(4) == "file")
{
QStringList tokens = l.split('=');
continue;
tokens[0] = tokens[0].mid (4);
filemap.insert(tokens[0].toInt (), items.size ());
- qDebug () << tokens;
items.append(PlaylistItem (tokens[1]));
}
else if (l.trimmed().toLower().left(5) == "title")
continue;
tokens[0] = tokens[0].mid (5);
int toupdate = filemap[tokens[0].toInt()];
- qDebug () << "Need to update " << toupdate << " for " << l;
QStringList metatok = tokens[1].split (" - ");
- qDebug () << metatok;
if (metatok.size() > 2 && toupdate >= 0 && toupdate < items.size ())
{
items[toupdate].artist = metatok[0];
{
items.clear();
emit playlistChanged(0);
-/* while (musicTable->rowCount())
- musicTable->removeRow(0);
- mediaObject->clear();*/
}
QStringList PlaylistManager::playlistStrings() const
QStringList ret;
for (int i = 0; i < items.size (); ++i)
ret << items[i].uri;
- qDebug () << "Returning playlist " << ret << " SIZE: " << items.size ();
return ret;
}
bool PlaylistManager::fileSupported (const QString& fname) const
{
- QString ext = fname.right(3).toLower();
+ if (fname.lastIndexOf('.') < 0)
+ return false;
+ QString ext = fname.right(fname.size() - fname.lastIndexOf('.') - 1).toLower();
foreach (QString e, allowedExtensions)
{
if (ext == e)
items[i - 1] = items[i];
items[i] = tmp;
return true;
-// emit playlistChanged(i - 1);
}
return false;
}
items[i + 1] = items[i];
items[i] = tmp;
return true;
-// emit playlistChanged(i - 1);
}
return false;
}