File indexing completed on 2024-04-28 04:43:21

0001 /*  This file is part of the KDE project
0002     Copyright (C) 2011 Jakub Spiewak <jmspiewak@gmail.com>
0003 
0004     This library is free software; you can redistribute it and/or
0005     modify it under the terms of the GNU Lesser General Public
0006     License as published by the Free Software Foundation; either
0007     version 2.1 of the License, or (at your option) version 3, or any
0008     later version accepted by the membership of KDE e.V. (or its
0009     successor approved by the membership of KDE e.V.), Nokia Corporation
0010     (or its successors, if any) and the KDE Free Qt Foundation, which shall
0011     act as a proxy defined in Section 6 of version 3 of the license.
0012 
0013     This library is distributed in the hope that it will be useful,
0014     but WITHOUT ANY WARRANTY; without even the implied warranty of
0015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0016     Lesser General Public License for more details.
0017 
0018     You should have received a copy of the GNU Lesser General Public
0019     License along with this library.  If not, see <http://www.gnu.org/licenses/>.
0020 */
0021 
0022 #include "metadatareader.h"
0023 
0024 #include <phonon/MediaObject>
0025 
0026 
0027 MetaDataReader::MetaDataReader(QString &file, QTextStream &out):
0028     textStream(out)
0029 {
0030     mediaObj = new Phonon::MediaObject(this);
0031 
0032     connect(mediaObj, SIGNAL(metaDataChanged()), this, SLOT(printMetaData()));
0033     connect(mediaObj, SIGNAL(stateChanged(Phonon::State,Phonon::State)), SLOT(checkForError(Phonon::State,Phonon::State)));
0034 
0035     mediaObj->setCurrentSource(QUrl::fromLocalFile(file));
0036 }
0037 
0038 
0039 MetaDataReader::~MetaDataReader()
0040 {
0041 }
0042 
0043 
0044 void MetaDataReader::printMetaData()
0045 {
0046     textStream << "Meta data of file " << mediaObj->currentSource().fileName() << ":\n";
0047 
0048     typedef QMultiMap<QString, QString> MetaDataMap;
0049     MetaDataMap metaData = mediaObj->metaData();
0050 
0051     for(MetaDataMap::iterator it=metaData.begin(); it!=metaData.end(); ++it)
0052     {
0053         textStream << it.key() << ": " << it.value() << '\n';
0054     }
0055 
0056     textStream.flush();
0057     quit();
0058 }
0059 
0060 
0061 void MetaDataReader::checkForError(Phonon::State state, Phonon::State)
0062 {
0063     if(state == Phonon::ErrorState)
0064     {
0065         textStream << "Error: unable to read meta data of " << mediaObj->currentSource().fileName() << Qt::endl;
0066         quit();
0067     }
0068 }