File indexing completed on 2024-05-19 07:50:58

0001 // SPDX-FileCopyrightText: (C) 2020 Carl Schwan <carl@carlschwan.eu>
0002 //
0003 // SPDX-License-Identifier: GPL-3.0-or-later
0004 
0005 #include "gamesmodel.h"
0006 
0007 #include <QtQml>
0008 #include <QDebug>
0009 
0010 #include <KPackage/PackageLoader>
0011 #include <KLocalizedString>
0012 #include <KPluginMetaData>
0013 
0014 GamesModel::GamesModel(QObject *parent)
0015     : QStandardItemModel(parent)
0016 {
0017     reload();
0018 }
0019 
0020 void GamesModel::reload()
0021 {
0022     clear();
0023 
0024     auto list = KPackage::PackageLoader::self()->listPackages(QStringLiteral("Arkade/Game"));
0025 
0026     for (auto plugin : list) {
0027         qDebug() << plugin.name();
0028         auto item = new QStandardItem(plugin.name());
0029         item->setData(plugin.pluginId(), GamesModel::PluginIdRole);
0030         appendRow(item);
0031     }
0032 }
0033 
0034 QString GamesModel::pluginId(int row)
0035 {
0036     return data(index(row, 0), PluginIdRole).toString();
0037 }
0038 
0039 QHash<int, QByteArray> GamesModel::roleNames() const
0040 {
0041     QHash<int, QByteArray> roles = QAbstractItemModel::roleNames();
0042  
0043     roles[PluginIdRole] = "pluginId";
0044     return roles;
0045 }
0046 
0047 #include "moc_gamesmodel.cpp"