aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/Input/wildmidi/decoderwildmidifactory.h
blob: eeb11b54432b66683e841fdc342b9f7ed8193a10 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/***************************************************************************
 *   Copyright (C) 2008 by Ilya Kotov                                      *
 *   forkotov02@hotmail.ru                                                 *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#ifndef DECODERWILDMIDIFACTORY_H
#define DECODERWILDMIDIFACTORY_H

#include <QObject>
#include <QString>
#include <QIODevice>
#include <QWidget>

#include <qmmp/decoder.h>
#include <qmmp/output.h>
#include <qmmp/decoderfactory.h>
#include <qmmp/fileinfo.h>


class DecoderWildMidiFactory : public QObject, DecoderFactory
{
    Q_OBJECT
    Q_INTERFACES(DecoderFactory);

public:
    bool supports(const QString &source) const;
    bool canDecode(QIODevice *input) const;
    const DecoderProperties properties() const;
    Decoder *create(const QString &path, QIODevice *input);
    QList<FileInfo *> createPlayList(const QString &fileName, bool useMetaData);
    MetaDataModel* createMetaDataModel(const QString &path, QObject *parent = 0);
    void showSettings(QWidget *parent);
    void showAbout(QWidget *parent);
    QTranslator *createTranslator(QObject *parent);
};

#endif
ugins' href='/qmmp/commit/src/plugins/PlaylistFormats/xspf/xspfplaylistformat.cpp?id=a4da0eb5e46e178d34a848b5fdb76dd8453510cd'>a4da0eb5e
7ff6e6a4f








60b4d7b8d
7ff6e6a4f

baf97dd40
7ff6e6a4f












dfdae5853
7ff6e6a4f
a4f568b7d
7ff6e6a4f



baf97dd40
60b4d7b8d
7ff6e6a4f




a4da0eb5e




245d0ac0c
a4da0eb5e
7ff6e6a4f









a4da0eb5e

245d0ac0c
a4da0eb5e
7ff6e6a4f
a4da0eb5e
7ff6e6a4f
1ecf10481
7ff6e6a4f
1ecf10481
7ff6e6a4f















a4da0eb5e

7ff6e6a4f



60b4d7b8d
a4da0eb5e

72d49c830
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
                                                                            
                                                                            














                                                                            
                                                                            

                                                                             

                           


                    
                      



                                                                         




                                                                                         
                                             


             
                                                                

                    

                                     
 








                                                 
 

                                        
     












                                                                                 
                                                                                                 
                    
                                                                               



                                         
     
 




                                                                                    




                                                                         
                                                                       
 









                                                                  

                    
                                   
     
                                       
 
                    
                                     
                                                          
                               















                                                                                        

                   



                                      
 

 
                                                       
/***************************************************************************
 *   Copyright (C) 2008-2014 by Ilya Kotov                                 *
 *   forkotov02@hotmail.ru                                                 *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
 ***************************************************************************/

#include <QXmlStreamReader>
#include <QXmlStreamWriter>
#include <QFileInfo>
#include <QUrl>
#include <QtPlugin>
#include <qmmp/qmmp.h>
#include "xspfplaylistformat.h"

// Needs more work - it's better use libSpiff there and put it as plugin.

const PlayListFormatProperties XSPFPlaylistFormat::XSPFPlaylistFormat::properties() const
{
    PlayListFormatProperties p;
    p.filters << "*.xspf";
    p.shortName = "xspf";
    p.contentTypes << "application/xspf+xml";
    return p;
}

QStringList XSPFPlaylistFormat::decode(const QString & contents)
{
    QStringList out;
    QString currentTag;
    QString contents_copy = contents;

    //remove control symbols to avoid xml errors
    for(int i = 0; i < contents_copy.size(); ++i)
    {
        if(contents_copy[i] <= 0x1F)
        {
            contents_copy.replace(i, 1, "");
            i--;
        }
    }

    QXmlStreamReader xml(contents_copy);
    while(!xml.atEnd())
    {
        xml.readNext();
        if (xml.isStartElement())
        {
            currentTag = xml.name().toString();

        }
        else if (xml.isCharacters() && !xml.isWhitespace())
        {
            if (currentTag == "location")
            {

                QUrl url(xml.text().toString());
                if (url.scheme() == "file")  //remove scheme for local files only
                    out << QUrl::fromPercentEncoding(url.toString().toAscii()).remove("file://");
                else
                    out << QUrl::fromPercentEncoding(url.toString().toAscii());
            }
            else
                xml.skipCurrentElement();
        }
    }

    if(xml.hasError())
    {
        qDebug("XSPFPlaylistFormat: parse error: %s (row:%lld, col:%lld",
               qPrintable(xml.errorString()), xml.lineNumber(), xml.columnNumber());
    }
    return out;
}

// Needs more work - it's better use libSpiff there and put it as plugin.

QString XSPFPlaylistFormat::encode(const QList<PlayListTrack*> & files)
{
    QString out;
    QXmlStreamWriter xml(&out);
    xml.setCodec("UTF-8");
    xml.setAutoFormatting(true);
    xml.writeStartDocument();
    xml.writeStartElement("playlist");
    xml.writeAttribute("version", "1");
    xml.writeAttribute("xmlns", "http://xspf.org/ns/0/");
    xml.writeTextElement("creator", "qmmp-" + Qmmp::strVersion());
    xml.writeStartElement("trackList");

    int counter = 1;
    foreach(PlayListTrack* f,files)
    {
        xml.writeStartElement("track");

        QString url;
        if (f->url().contains("://"))
            url = QUrl::toPercentEncoding(f->url(), ":/");
        else  //append protocol
            url = QUrl::toPercentEncoding(QString("file://") +
                                          QFileInfo(f->url()).absoluteFilePath(), ":/");

        xml.writeTextElement("location", url);
        xml.writeTextElement("title", f->value(Qmmp::TITLE));
        xml.writeTextElement("creator", f->value(Qmmp::ARTIST));
        xml.writeTextElement("annotation", f->value(Qmmp::COMMENT));
        xml.writeTextElement("album", f->value(Qmmp::ALBUM));
        xml.writeTextElement("trackNum", QString::number(counter));

        xml.writeStartElement("meta");
        xml.writeAttribute("rel", "year");
        xml.writeCharacters(f->value(Qmmp::YEAR));
        xml.writeEndElement(); // meta
        xml.writeEndElement(); // track

        counter ++;
    }
    xml.writeEndElement(); //trackList
    xml.writeEndElement(); //playlist
    xml.writeEndDocument();
    return out;

}

Q_EXPORT_PLUGIN2(xspfplaylistformat,XSPFPlaylistFormat)