File indexing completed on 2024-05-05 04:34:55
0001 /* SPDX-FileCopyrightText: 2022 Noah Davis <noahadvs@gmail.com> 0002 * SPDX-License-Identifier: LGPL-2.0-or-later 0003 */ 0004 0005 #include "VideoFormatModel.h" 0006 #include "Platforms/VideoPlatform.h" 0007 0008 #include <KLocalizedString> 0009 0010 using namespace Qt::StringLiterals; 0011 0012 VideoFormatModel::VideoFormatModel(VideoPlatform::Formats formats, QObject *parent) 0013 : QAbstractListModel(parent) 0014 { 0015 m_roleNames[Qt::DisplayRole] = "display"_ba; 0016 m_roleNames[FormatRole] = "format"_ba; 0017 m_roleNames[ExtensionRole] = "extension"_ba; 0018 0019 QStringList extensions; 0020 if (formats.testFlag(VideoPlatform::WebM_VP9)) { 0021 m_data.append({ 0022 i18nc("@item:inlistbox Container/encoder", "WebM/VP9"), 0023 VideoPlatform::WebM_VP9, 0024 VideoPlatform::extensionForFormat(VideoPlatform::WebM_VP9), 0025 }); 0026 } 0027 if (formats.testFlag(VideoPlatform::MP4_H264)) { 0028 m_data.append({ 0029 i18nc("@item:inlistbox Container/encoder", "MP4/H.264"), 0030 VideoPlatform::MP4_H264, 0031 VideoPlatform::extensionForFormat(VideoPlatform::MP4_H264), 0032 }); 0033 } 0034 } 0035 0036 int VideoFormatModel::indexOfFormat(VideoPlatform::Format format) const 0037 { 0038 int finalIndex = -1; 0039 for (int i = 0; i < m_data.length(); ++i) { 0040 if (m_data[i].format == format) { 0041 finalIndex = i; 0042 break; 0043 } 0044 } 0045 return finalIndex; 0046 } 0047 0048 QHash<int, QByteArray> VideoFormatModel::roleNames() const 0049 { 0050 return m_roleNames; 0051 } 0052 0053 QVariant VideoFormatModel::data(const QModelIndex &index, int role) const 0054 { 0055 int row = index.row(); 0056 QVariant ret; 0057 if (!checkIndex(index, CheckIndexOption::IndexIsValid)) { 0058 return ret; 0059 } 0060 if (role == Qt::DisplayRole) { 0061 ret = m_data.at(row).label; 0062 } else if (role == FormatRole) { 0063 ret = m_data.at(row).format; 0064 } else if (role == ExtensionRole) { 0065 ret = m_data.at(row).extension; 0066 } 0067 return ret; 0068 } 0069 0070 int VideoFormatModel::rowCount(const QModelIndex &parent) const 0071 { 0072 Q_UNUSED(parent) 0073 return m_data.size(); 0074 } 0075 0076 #include "moc_VideoFormatModel.cpp"