File indexing completed on 2024-04-14 14:32:49

0001 /***************************************************************************
0002  *   Copyright (C) 2012-2016 by Daniel Nicoletti <dantti12@gmail.com>      *
0003  *                                                                         *
0004  *   This program is free software; you can redistribute it and/or modify  *
0005  *   it under the terms of the GNU General Public License as published by  *
0006  *   the Free Software Foundation; either version 2 of the License, or     *
0007  *   (at your option) any later version.                                   *
0008  *                                                                         *
0009  *   This program is distributed in the hope that it will be useful,       *
0010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0012  *   GNU General Public License for more details.                          *
0013  *                                                                         *
0014  *   You should have received a copy of the GNU General Public License     *
0015  *   along with this program; see the file COPYING. If not, write to       *
0016  *   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,  *
0017  *   Boston, MA 02110-1301, USA.                                           *
0018  ***************************************************************************/
0019 
0020 #include "ProfileMetaDataModel.h"
0021 
0022 #include <QDebug>
0023 #include <klocalizedstring.h>
0024 /* defined in metadata-spec.txt */
0025 #define CD_PROFILE_METADATA_STANDARD_SPACE QStringLiteral("STANDARD_space")
0026 #define CD_PROFILE_METADATA_EDID_MD5 QStringLiteral("EDID_md5")
0027 #define CD_PROFILE_METADATA_EDID_MODEL QStringLiteral("EDID_model")
0028 #define CD_PROFILE_METADATA_EDID_SERIAL QStringLiteral("EDID_serial")
0029 #define CD_PROFILE_METADATA_EDID_MNFT QStringLiteral("EDID_mnft")
0030 #define CD_PROFILE_METADATA_EDID_VENDOR QStringLiteral("EDID_manufacturer")
0031 #define CD_PROFILE_METADATA_FILE_CHECKSUM QStringLiteral("FILE_checksum")
0032 #define CD_PROFILE_METADATA_CMF_PRODUCT QStringLiteral("CMF_product")
0033 #define CD_PROFILE_METADATA_CMF_BINARY QStringLiteral("CMF_binary")
0034 #define CD_PROFILE_METADATA_CMF_VERSION QStringLiteral("CMF_version")
0035 #define CD_PROFILE_METADATA_DATA_SOURCE QStringLiteral("DATA_source")
0036 #define CD_PROFILE_METADATA_MAPPING_FORMAT QStringLiteral("MAPPING_format")
0037 #define CD_PROFILE_METADATA_MAPPING_QUALIFIER QStringLiteral("MAPPING_qualifier")
0038 
0039 ProfileMetaDataModel::ProfileMetaDataModel(QObject *parent)
0040     : QAbstractListModel(parent)
0041 {
0042 }
0043 
0044 void ProfileMetaDataModel::setMetadata(const CdStringMap &metadata)
0045 {
0046     beginResetModel();
0047     m_data = metadata;
0048     m_keys = m_data.keys();
0049     endResetModel();
0050     qDebug() << "set metadata" << m_data;
0051 }
0052 
0053 int ProfileMetaDataModel::rowCount(const QModelIndex &index) const
0054 {
0055     Q_UNUSED(index);
0056     return m_keys.count();
0057 }
0058 QVariant ProfileMetaDataModel::data(const QModelIndex &index, int role) const
0059 {
0060     if (index.row() < 0 || index.row() >= m_keys.count()) {
0061         return QVariant();
0062     }
0063 
0064     switch (role) {
0065     case TitleRole:
0066         return metadataLabel(m_keys[index.row()]);
0067     case ValueRole:
0068         return m_data[m_keys[index.row()]];
0069     }
0070     return QVariant();
0071 }
0072 QHash<int, QByteArray> ProfileMetaDataModel::roleNames() const
0073 {
0074     return {{TitleRole, "title"}, {ValueRole, "textValue"}};
0075 }
0076 
0077 QString ProfileMetaDataModel::metadataLabel(const QString &key) const
0078 {
0079     if (key == CD_PROFILE_METADATA_STANDARD_SPACE) {
0080         return i18n("Standard space");
0081     }
0082     if (key == CD_PROFILE_METADATA_EDID_MD5) {
0083         return i18n("Display checksum");
0084     }
0085     if (key == CD_PROFILE_METADATA_EDID_MODEL) {
0086         return i18n("Display model");
0087     }
0088     if (key == CD_PROFILE_METADATA_EDID_SERIAL) {
0089         return i18n("Display serial number");
0090     }
0091     if (key == CD_PROFILE_METADATA_EDID_MNFT) {
0092         return i18n("Display PNPID");
0093     }
0094     if (key == CD_PROFILE_METADATA_EDID_VENDOR) {
0095         return i18n("Display vendor");
0096     }
0097     if (key == CD_PROFILE_METADATA_FILE_CHECKSUM) {
0098         return i18n("File checksum");
0099     }
0100     if (key == CD_PROFILE_METADATA_CMF_PRODUCT) {
0101         return i18n("Framework product");
0102     }
0103     if (key == CD_PROFILE_METADATA_CMF_BINARY) {
0104         return i18n("Framework program");
0105     }
0106     if (key == CD_PROFILE_METADATA_CMF_VERSION) {
0107         return i18n("Framework version");
0108     }
0109     if (key == CD_PROFILE_METADATA_DATA_SOURCE) {
0110         return i18n("Data source type");
0111     }
0112     if (key == CD_PROFILE_METADATA_MAPPING_FORMAT) {
0113         return i18n("Mapping format");
0114     }
0115     if (key == CD_PROFILE_METADATA_MAPPING_QUALIFIER) {
0116         return i18n("Mapping qualifier");
0117     }
0118     return key;
0119 }
0120 
0121 #include "moc_ProfileMetaDataModel.cpp"