aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/CommandLineOptions/StatusOption/CMakeLists.txt
Commit message (Collapse)AuthorAgeFilesLines
* feature to change application nametrialuser022018-07-011-2/+2
| | | | git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@8077 90c681e8-e032-0410-971d-27865f9a5e38
* changed plugin path (cmake)trialuser022018-06-231-1/+1
| | | | git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@8054 90c681e8-e032-0410-971d-27865f9a5e38
* copy 1.2 branch to trunktrialuser022017-11-251-15/+2
| | | | git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@7772 90c681e8-e032-0410-971d-27865f9a5e38
* cmake: removed CMP0003 policytrialuser022017-09-231-6/+0
| | | | git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@7466 90c681e8-e032-0410-971d-27865f9a5e38
* cmake: cleanuptrialuser022016-06-031-1/+0
| | | | git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@6427 90c681e8-e032-0410-971d-27865f9a5e38
* building of .app package for MacOS X with CMake (patch by Ivan Ponomarev)trialuser022015-12-041-1/+1
| | | | git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@5807 90c681e8-e032-0410-971d-27865f9a5e38
* renaming experimental branchtrialuser022015-01-091-7/+1
| | | | git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@4675 90c681e8-e032-0410-971d-27865f9a5e38
* added --status and --nowplaying command line option (Closes issue 266)trialuser022010-09-181-0/+52
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@1893 90c681e8-e032-0410-971d-27865f9a5e38
tadatamodel.cpp?id=e6cdd7a53803f700e7edaa5dea2b0876ada17114'>e6cdd7a53
362d4e2b4







d460e7652

3a2ef3199













d460e7652








362d4e2b4

e6cdd7a53












362d4e2b4



e6cdd7a53



362d4e2b4



































































013ee07b5
362d4e2b4









013ee07b5
362d4e2b4




e6cdd7a53



362d4e2b4
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
                                                                            
                                                                            

















                                                                             
                  


                           
                     
                                 


                                                                                            
                                                                              


                                                                                                  












                                                              










                                                            
















                                                                         
                  














                                                                                             







                                           

                                  













                                                                                    








                                                             

                                                                                      












                                                                                 



                                         



                          



































































                                                                                     
                                               









                                         
                                                 




                               



                           
 
/***************************************************************************
 *   Copyright (C) 2009-2010 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.             *
 ***************************************************************************/

#include <QPixmap>
#include <taglib/tag.h>
#include <taglib/fileref.h>
#include <taglib/tmap.h>
#include <FLAC/all.h>
#include <qmmp/metadatamanager.h>
#include "flacmetadatamodel.h"

#define QStringToTString_qt4(s) TagLib::String(s.toUtf8().constData(), TagLib::String::UTF8)
#define TStringToQString_qt4(s) QString::fromUtf8(s.toCString(true)).trimmed()

FLACMetaDataModel::FLACMetaDataModel(const QString &path, QObject *parent) : MetaDataModel(parent)
{
    if(path.startsWith("flac://"))
    {
        QString p = QUrl(path).path();
        p.replace(QString(QUrl::toPercentEncoding("#")), "#");
        p.replace(QString(QUrl::toPercentEncoding("?")), "?");
        p.replace(QString(QUrl::toPercentEncoding("%")), "%");
        m_path = p;
    }
    else
    {
        m_path = path;
        m_tags << new VorbisCommentModel(path);
    }
}

FLACMetaDataModel::~FLACMetaDataModel()
{
    while(!m_tags.isEmpty())
        delete m_tags.takeFirst();
}

QHash<QString, QString> FLACMetaDataModel::audioProperties()
{
    QHash<QString, QString> ap;
    TagLib::FLAC::File *flacFile = 0;
    TagLib::Ogg::FLAC::File *oggFlacFile = 0;
    TagLib::FLAC::Properties *taglib_ap = 0;
    qint64 size = 0;
    if(m_path.endsWith(".flac"))
    {
        flacFile = new TagLib::FLAC::File(m_path.toLocal8Bit ());
        taglib_ap = flacFile->audioProperties();
        size = flacFile->length();
    }
    else if(m_path.endsWith(".oga"))
    {
        oggFlacFile = new TagLib::Ogg::FLAC::File(m_path.toLocal8Bit ());
        taglib_ap = oggFlacFile->audioProperties();
        size = oggFlacFile->length();
    }
    else
        return ap;

    if(taglib_ap)
    {
        QString text = QString("%1").arg(taglib_ap->length()/60);
        text +=":"+QString("%1").arg(taglib_ap->length()%60,2,10,QChar('0'));
        ap.insert(tr("Length"), text);
        ap.insert(tr("Sample rate"), QString("%1 " + tr("Hz")).arg(taglib_ap->sampleRate()));
        ap.insert(tr("Channels"), QString("%1").arg(taglib_ap->channels()));
        ap.insert(tr("Bitrate"), QString("%1 " + tr("kbps")).arg(taglib_ap->bitrate()));
    }
    ap.insert(tr("File size"), QString("%1 "+tr("KB")).arg(size/1024));
    if(flacFile)
        delete flacFile;
    if(oggFlacFile)
        delete oggFlacFile;
    return ap;
}

QList<TagModel* > FLACMetaDataModel::tags()
{
    return m_tags;
}

QPixmap FLACMetaDataModel::cover()
{
    //embedded cover
    FLAC__StreamMetadata *metadata;
    FLAC__metadata_get_picture (qPrintable(m_path),
                                &metadata,
                                FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER,
                                0,0, -1,-1,-1,-1);
    if(metadata)
    {
        FLAC__StreamMetadata_Picture *pict = &metadata->data.picture;
        QPixmap cover;
        cover.loadFromData(QByteArray((char *)pict->data, (int) pict->data_length));
        FLAC__metadata_object_delete(metadata);
        return cover;
    }
    QString cPath = coverPath();
    return cPath.isEmpty() ? QPixmap() : QPixmap(cPath);
}

QString FLACMetaDataModel::coverPath()
{
    return MetaDataManager::instance()->getCoverPath(m_path);
}

VorbisCommentModel::VorbisCommentModel(const QString &path) : TagModel(TagModel::Save)
{
    m_file = 0;
    m_ogg_file = 0;
    m_tag = 0;
    if(path.endsWith(".flac"))
    {
        m_file = new TagLib::FLAC::File (path.toLocal8Bit().constData());
        m_tag = m_file->xiphComment();
    }
    else if (path.endsWith(".oga"))
    {
        m_ogg_file = new TagLib::Ogg::FLAC::File(path.toLocal8Bit().constData());
        m_tag = m_ogg_file->tag();
    }
}

VorbisCommentModel::~VorbisCommentModel()
{
    if(m_file)
        delete m_file;
    if(m_ogg_file)
        delete m_ogg_file;
}

const QString VorbisCommentModel::name()
{
    return "Vorbis Comment";
}

const QString VorbisCommentModel::value(Qmmp::MetaData key)
{
    if(!m_tag)
        return QString();
    switch((int) key)
    {
    case Qmmp::TITLE:
        return TStringToQString_qt4(m_tag->title());
    case Qmmp::ARTIST:
        return TStringToQString_qt4(m_tag->artist());
    case Qmmp::ALBUM:
        return TStringToQString_qt4(m_tag->album());
    case Qmmp::COMMENT:
        return TStringToQString_qt4(m_tag->comment());
    case Qmmp::GENRE:
        return TStringToQString_qt4(m_tag->genre());
    case Qmmp::COMPOSER:
        if(m_tag->fieldListMap()["COMPOSER"].isEmpty())
            return QString();
        else
            return TStringToQString_qt4(m_tag->fieldListMap()["COMPOSER"].front());
    case Qmmp::YEAR:
        return QString::number(m_tag->year());
    case Qmmp::TRACK:
        return QString::number(m_tag->track());
    case  Qmmp::DISCNUMBER:
        if(m_tag->fieldListMap()["DISCNUMBER"].isEmpty())
            return QString();
        else
            return TStringToQString_qt4(m_tag->fieldListMap()["DISCNUMBER"].front());
    }
    return QString();
}

void VorbisCommentModel::setValue(Qmmp::MetaData key, const QString &value)
{
    if(!m_tag)
        return;

    TagLib::String str = QStringToTString_qt4(value);

    switch((int) key)
    {
    case Qmmp::TITLE:
        m_tag->setTitle(str);
        return;
    case Qmmp::ARTIST:
        m_tag->setArtist(str);
        return;
    case Qmmp::ALBUM:
        m_tag->setAlbum(str);
        return;
    case Qmmp::COMMENT:
        m_tag->setComment(str);
        return;
    case Qmmp::GENRE:
        m_tag->setGenre(str);
        return;
    case Qmmp::COMPOSER:
        value.isEmpty() ?
        m_tag->removeField("COMPOSER"):
        m_tag->addField("COMPOSER", str, true);
        return;
    case Qmmp::TRACK:
        m_tag->setTrack(value.toInt());
        return;
    case Qmmp::YEAR:
        m_tag->setYear(value.toInt());
        return;
    case Qmmp::DISCNUMBER:
        value == "0" ?
        m_tag->removeField("DISCNUMBER"):
        m_tag->addField("DISCNUMBER", str, true);
    }
}

void VorbisCommentModel::save()
{
    if(m_file)
        m_file->save();
    else if(m_ogg_file)
        m_ogg_file->save();
}