00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "gamesmodel.h"
00021
00022 #include <core/gluon_global.h>
00023 #include <engine/gameproject.h>
00024
00025 #include <QDir>
00026 #include <QCoreApplication>
00027 #include <QDebug>
00028
00029 using namespace GluonPlayer;
00030
00031 GamesModel::GamesModel (QObject* parent)
00032 : QAbstractTableModel (parent)
00033 {
00034 m_dir.cd (GluonCore::Global::dataDirectory() + "/gluon/games");
00035 }
00036
00037 QVariant GamesModel::data (const QModelIndex& index, int role) const
00038 {
00039 if (role == Qt::DisplayRole) {
00040 QString gameDirName = m_dir.entryList (QDir::Dirs | QDir::NoDotAndDotDot).at (index.row());
00041 QDir gameDir = m_dir;
00042 gameDir.cd (gameDirName);
00043 QStringList gluonProjectFiles = gameDir.entryList (QStringList ("*.gluon"));
00044 QString projectFileName = gameDir.absoluteFilePath (gluonProjectFiles.at (0));
00045
00046 if (!gluonProjectFiles.isEmpty()) {
00047 if (index.column() == PathColumn) {
00048 return projectFileName;
00049 } else {
00050 GluonEngine::GameProject project;
00051 project.loadFromFile (projectFileName);
00052
00053 switch (index.column()) {
00054
00055 case NameColumn:
00056 return project.name();
00057 break;
00058
00059 case DescriptionColumn:
00060 return project.description();
00061 break;
00062
00063 case IdColumn:
00064 qDebug() << "IDDDDDDDDDDDD " << project.property ("id");
00065 return project.property ("id");
00066 break;
00067 }
00068 }
00069 } else {
00070 return QVariant();
00071 }
00072 }
00073
00074 return QVariant();
00075 }
00076
00077 int GamesModel::columnCount (const QModelIndex& parent) const
00078 {
00079 Q_UNUSED (parent);
00080 return 4;
00081 }
00082
00083 int GamesModel::rowCount (const QModelIndex& parent) const
00084 {
00085 Q_UNUSED (parent);
00086 return m_dir.entryList (QDir::Dirs | QDir::NoDotAndDotDot).count();
00087 }
00088
00089 QVariant GamesModel::headerData (int section, Qt::Orientation orientation, int role) const
00090 {
00091 if (section == 0) {
00092 return QString ("Game");
00093 }
00094
00095 return QAbstractItemModel::headerData (section, orientation, role);
00096 }