/src/plugins/PlaylistFormats/

hes' selected='selected'>patches Qmmp with Jyrki's patchesJyrki
aboutsummaryrefslogblamecommitdiff
path: root/src/plugins/Input/mad/detailsdialog.cpp
blob: c2e55e5cb74bcaccf42cd010d97efebd88f9d784 (plain) (tree)
1
2
                                                                            
                                                                            

















































                                                                               
                                                                                

                                                  
                                                                          

                                                  
                                                             

















































































































                                                                         
                
                                                       











































                                                                          
 

                                          







                                                        
                                                       
                                                                                           
                                                  
                                             
                                        






































































                                                                                                      
/***************************************************************************
 *   Copyright (C) 2006-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.             *
 ***************************************************************************/
#include <QTextCodec>
#include <QSettings>
#include <QDir>
#include <QFile>
#include <QFileInfo>

#include <taglib/tag.h>
#include <taglib/fileref.h>
#include <taglib/id3v1tag.h>
#include <taglib/id3v2tag.h>
#include <taglib/apetag.h>
#include <taglib/tfile.h>
#include <taglib/mpegfile.h>
#include <taglib/mpegheader.h>
#include <taglib/mpegproperties.h>

#include "detailsdialog.h"

DetailsDialog::DetailsDialog(QWidget *parent, const QString &path)
        : QDialog(parent)
{
    ui.setupUi(this);
    setAttribute(Qt::WA_DeleteOnClose);
    m_path = path;
    setWindowTitle (path.section('/',-1));
    ui.pathLineEdit->setText(m_path);

    if (!QFile::exists(m_path))
        return;

    QSettings settings(QDir::homePath()+"/.qmmp/qmmprc", QSettings::IniFormat);
    settings.beginGroup("MAD");
    m_codec_v1 =
        QTextCodec::codecForName(settings.value("ID3v1_encoding", "ISO-8859-1" )
                                 .toByteArray ());
    m_codec_v2 =
        QTextCodec::codecForName(settings.value("ID3v2_encoding","UTF-8" )
                                 .toByteArray ());
    if (!m_codec_v1)
        m_codec_v1 = QTextCodec::codecForName ("ISO-8859-1");
    if (!m_codec_v2)
        m_codec_v2 = QTextCodec::codecForName ("UTF-8");

    QString tag_name = settings.value("current_tag","ID3v2").toString ();

    if (tag_name == "ID3v1")
        ui.id3v1RadioButton->setChecked(TRUE);
    else if (tag_name == "ID3v2")
        ui.id3v2RadioButton->setChecked(TRUE);
    else if (tag_name == "APE")
        ui.apeRadioButton->setChecked(TRUE);
    else
        ui.id3v2RadioButton->setChecked(TRUE);

    settings.endGroup();

    loadMPEGInfo();
    QFileInfo info(m_path);
    m_rw = info.isWritable();
    loadTag();
    connect(ui.saveButton, SIGNAL(clicked()), SLOT(save()));
    connect(ui.createButton, SIGNAL(clicked()), SLOT(create()));
    connect(ui.deleteButton, SIGNAL(clicked()), SLOT(deleteTag()));
    connect(ui.id3v1RadioButton, SIGNAL(clicked()), SLOT(loadTag()));
    connect(ui.id3v2RadioButton, SIGNAL(clicked()), SLOT(loadTag()));
    connect(ui.apeRadioButton, SIGNAL(clicked()), SLOT(loadTag()));
}


DetailsDialog::~DetailsDialog()
{}

void DetailsDialog::loadMPEGInfo()
{
    TagLib::MPEG::File f (m_path.toLocal8Bit());
    //l.label
    //ui. f.audioProperties()->level();
    QString text;
    text = QString("%1").arg(f.audioProperties()->layer());
    ui.levelLabel->setText("MPEG layer "+text); //TODO: add MPEG version
    text = QString("%1").arg(f.audioProperties()->bitrate());
    ui.bitRateLabel->setText(text+" "+tr("kbps"));
    text = QString("%1").arg(f.audioProperties()->sampleRate());
    ui.sampleRateLabel->setText(text+" "+tr("Hz"));
    switch (f.audioProperties()->channelMode())
    {
    case TagLib::MPEG::Header::Stereo:
        ui.modeLabel->setText("Stereo");
        break;
    case TagLib::MPEG::Header::JointStereo:
        ui.modeLabel->setText("Joint stereo");
        break;
    case TagLib::MPEG::Header::DualChannel:
        ui.modeLabel->setText("Dual channel");
        break;
    case TagLib::MPEG::Header::SingleChannel:
        ui.modeLabel->setText("Single channel");
        break;
    }
    text = QString("%1 "+tr("KB")).arg(f.length()/1024);
    ui.fileSizeLabel->setText(text);
    /*if (f.audioProperties()->protectionEnabled())
        ui.errProtectionLabel->setText(tr("Yes"));
    else
        ui.errProtectionLabel->setText(tr("No"));*/
    if (f.audioProperties()->isCopyrighted())
        ui.copyrightLabel->setText(tr("Yes"));
    else
        ui.copyrightLabel->setText(tr("No"));
    if (f.audioProperties()->isOriginal())
        ui.originalLabel->setText(tr("Yes"));
    else
        ui.originalLabel->setText(tr("No"));
}

void DetailsDialog::loadTag()
{
    TagLib::MPEG::File f (m_path.toLocal8Bit());
    QTextCodec *codec = QTextCodec::codecForName ("UTF-8");
    TagLib::Tag *tag = 0;

    if (selectedTag() == TagLib::MPEG::File::ID3v1)
    {
        tag = f.ID3v1Tag();
        codec = m_codec_v1;
        ui.tagGroupBox->setTitle(tr("ID3v1 Tag"));
    }
    else if (selectedTag() == TagLib::MPEG::File::ID3v2)
    {
        tag = f.ID3v2Tag();
        codec = m_codec_v2;