9ab07a49abe3b8c688f4a81c287fb3c885a5284c
[someplayer] / src / tagresolver.cpp
1 /*
2  * SomePlayer - An alternate music player for Maemo 5
3  * Copyright (C) 2010 Nikolay (somebody) Tischenko <niktischenko@gmail.com>
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18  */
19
20 #include "tagresolver.h"
21 #include <QDebug>
22 #include <QFile>
23 #include <tag.h>
24 #include <fileref.h>
25
26 using namespace SomePlayer::DataObjects;
27
28 TagResolver::TagResolver(QObject *parent) :
29     QObject(parent)
30 {
31 }
32
33 void TagResolver::decode(QStringList files) {
34         foreach (QString filename, files) {
35                 TagLib::FileRef file_ref(QFile::encodeName(filename).data());
36                 if (!file_ref.isNull()) {
37                         TagLib::Tag *tag = file_ref.tag();
38                         if (NULL != tag) {
39                                 TagLib::AudioProperties *properties = file_ref.audioProperties();
40                                 if (NULL != properties) {
41                                         TrackMetadata meta(QString::fromStdWString(tag->title().toWString()),
42                                                            QString::fromStdWString(tag->artist().toWString()),
43                                                            QString::fromStdWString(tag->album().toWString()),
44                                                            properties->length());
45                                         Track track(0, meta, filename);
46                                         emit decoded(track);
47                                 }
48                         }
49                 }
50         }
51         emit done();
52 }