aboutsummaryrefslogtreecommitdiff
path: root/src/qmmpui/detailsdialog.cpp
blob: 5bb6b2be58d7393c4799b4219e349d9036389ba8 (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
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) 2009 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 <qmmp/metadatamanager.h>
#include <qmmp/metadatamodel.h>
#include <qmmp/tagmodel.h>
#include "ui_detailsdialog.h"
#include "playlistitem.h"
#include "tageditor.h"
#include "detailsdialog.h"

DetailsDialog::DetailsDialog(PlayListItem *item, QWidget *parent)
        : QDialog(parent)
{
    m_ui = new Ui::DetailsDialog;
    setAttribute(Qt::WA_QuitOnClose, false);
    setAttribute(Qt::WA_DeleteOnClose, false);
    m_metaDataModel = 0;
    m_item = item;
    m_ui->setupUi(this);
    setAttribute(Qt::WA_DeleteOnClose);
    m_path = item->url();
    setWindowTitle (m_path.section('/',-1));
    m_ui->pathEdit->setText(m_path);

    m_metaDataModel = MetaDataManager::instance()->createMetaDataModel(item->url(), this);

    if(m_metaDataModel)
    {
        foreach(TagModel *tagModel, m_metaDataModel->tags())
            m_ui->tabWidget->addTab(new TagEditor(tagModel, this), tagModel->name());

        foreach(QString title, m_metaDataModel->descriptions().keys())
        {
            QTextEdit *textEdit = new QTextEdit(this);
            textEdit->setReadOnly(true);
            textEdit->setPlainText(m_metaDataModel->descriptions().value(title));
            m_ui->tabWidget->addTab(textEdit, title);
        }
    }
    printInfo();
}

DetailsDialog::~DetailsDialog()
{
    delete m_ui;
}

void DetailsDialog::printInfo()
{
    QList <FileInfo *> flist = MetaDataManager::instance()->createPlayList(m_path, true);
    QMap <Qmmp::MetaData, QString> metaData;
    if(!flist.isEmpty() && QFile::exists(m_item->url()))
        metaData = flist.at(0)->metaData();
    else
        metaData = *m_item;
    QString formattedText;
    formattedText.append("<TABLE>");
    //tags
    formattedText += formatRow(tr("Title"), metaData[Qmmp::TITLE]);
    formattedText += formatRow(tr("Artist"), metaData[Qmmp::ARTIST]);
    formattedText += formatRow(tr("Album"), metaData[Qmmp::ALBUM]);
    formattedText += formatRow(tr("Comment"), metaData[Qmmp::COMMENT]);
    formattedText += formatRow(tr("Genre"), metaData[Qmmp::GENRE]);
    formattedText += formatRow(tr("Composer"), metaData[Qmmp::COMPOSER]);
    if(metaData[Qmmp::YEAR] != "0")
        formattedText += formatRow(tr("Year"), metaData[Qmmp::YEAR]);
    if(metaData[Qmmp::TRACK] != "0")
        formattedText += formatRow(tr("Track"), metaData[Qmmp::TRACK]);
    if(metaData[Qmmp::DISCNUMBER] != "0")
        formattedText += formatRow(tr("Disc number"), metaData[Qmmp::DISCNUMBER]);
    //audio info
    if(!m_metaDataModel)
    {
        formattedText.append("</TABLE>");
        m_ui->textEdit->setHtml(formattedText);
        return;
    }
    QHash <QString, QString> ap = m_metaDataModel->audioProperties();
    //line
    if(formattedText.trimmed() != "<TABLE>")
    {
        formattedText.append("<tr>");
        formattedText.append("<td colspan=2>");
        formattedText.append("<hr>");
        formattedText.append("</td>");
        formattedText.append("</tr>");
    }

    foreach(QString key, ap.keys())
        formattedText += formatRow(key, ap.value(key));

    formattedText.append("</TABLE>");
    m_ui->textEdit->setHtml(formattedText);
}

QString DetailsDialog::formatRow(const QString key, const QString value)
{
    if(value.isEmpty())
        return QString();
    QString str("<tr>");
    str.append("<td><b>" + key + "</b></td> <td style=\"padding-left: 15px;\">" + value + "</td>");
    str.append("</tr>");
    return str;
}

void DetailsDialog::on_buttonBox_clicked(QAbstractButton *button)
{
    if(m_ui->buttonBox->standardButton(button) == QDialogButtonBox::Save)
    {
        TagEditor *tab = qobject_cast<TagEditor *> (m_ui->tabWidget->currentWidget());
        if(tab)
            tab->save();
    }
    else
        reject();
}