1
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2
* Mupen64plus - rommodel.cpp *
3
* Mupen64Plus homepage: http://code.google.com/p/mupen64plus/ *
4
* Copyright (C) 2008 Slougi *
6
* This program is free software; you can redistribute it and/or modify *
7
* it under the terms of the GNU General Public License as published by *
8
* the Free Software Foundation; either version 2 of the License, or *
9
* (at your option) any later version. *
11
* This program is distributed in the hope that it will be useful, *
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
* GNU General Public License for more details. *
16
* You should have received a copy of the GNU General Public License *
17
* along with this program; if not, write to the *
18
* Free Software Foundation, Inc., *
19
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
20
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
22
#include <QStringList>
38
#include "../romcache.h"
40
#include "../config.h"
45
RomModel::RomModel(QObject* parent)
46
: QAbstractItemModel(parent)
47
, m_showFullPath(core::config_get_bool("RomBrowserShowFullPaths", FALSE))
48
, m_romDirectories(romDirectories())
51
char* iconpath = core::get_iconspath();
52
QPixmap paustralia(file.sprintf("%s%s", iconpath, "australia.png"));
53
QPixmap peurope(file.sprintf("%s%s", iconpath, "europe.png"));
54
QPixmap pfrance(file.sprintf("%s%s", iconpath, "france.png"));
55
QPixmap pgermany(file.sprintf("%s%s", iconpath, "germany.png"));
56
QPixmap pitaly(file.sprintf("%s%s", iconpath, "italy.png"));
57
QPixmap pjapan(file.sprintf("%s%s", iconpath, "japan.png"));
58
QPixmap pspain(file.sprintf("%s%s", iconpath, "spain.png"));
59
QPixmap pusa(file.sprintf("%s%s", iconpath, "usa.png"));
60
QPixmap pjapanusa(file.sprintf("%s%s", iconpath, "japanusa.png"));
61
QPixmap pn64cart(file.sprintf("%s%s", iconpath, "mupen64cart.png"));
63
QPair<QString, QPixmap> demo(tr("Demo"), pn64cart);
64
QPair<QString, QPixmap> beta(tr("Beta"), pn64cart);
65
QPair<QString, QPixmap> japanusa(tr("Japan/USA"), pjapanusa);
66
QPair<QString, QPixmap> usa(tr("USA"), pusa);
67
QPair<QString, QPixmap> germany(tr("Germany"), pgermany);
68
QPair<QString, QPixmap> france(tr("France"), pfrance);
69
QPair<QString, QPixmap> italy(tr("Italy"), pitaly);
70
QPair<QString, QPixmap> japan(tr("Japan"), pjapan);
71
QPair<QString, QPixmap> spain(tr("Spain"), pspain);
72
QPair<QString, QPixmap> australia(tr("Australia"), paustralia);
73
QPair<QString, QPixmap> europe(tr("Europe"), peurope);
74
QPair<QString, QPixmap> unknown(tr("Unknown"), pn64cart);
76
m_countryInfo[char(0)] = demo;
77
m_countryInfo['7'] = beta;
78
m_countryInfo[char(0x41)] = japanusa;
79
m_countryInfo[char(0x44)] = germany;
80
m_countryInfo[char(0x45)] = usa;
81
m_countryInfo[char(0x46)] = france;
82
m_countryInfo['I'] = italy;
83
m_countryInfo[char(0x4A)] = japan;
84
m_countryInfo['S'] = spain;
85
m_countryInfo[char(0x55)] = australia;
86
m_countryInfo[char(0x59)] = australia;
87
m_countryInfo[char(0x50)] = europe;
88
m_countryInfo[char(0x58)] = europe;
89
m_countryInfo[char(0x20)] = europe;
90
m_countryInfo[char(0x21)] = europe;
91
m_countryInfo[char(0x38)] = europe;
92
m_countryInfo[char(0x70)] = europe;
93
m_countryInfo['?'] = unknown;
96
RomModel* RomModel::self()
98
static RomModel* instance = new RomModel;
102
void RomModel::update(unsigned int roms, unsigned short clear)
104
//If clear flag is set, clear the GUI rombrowser.
110
unsigned int arrayroms = static_cast<unsigned int>(m_romList.count());
112
//If there are currently more ROMs in cache than GUI rombrowser, add them.
113
if (roms > arrayroms) {
114
core::cache_entry *entry;
115
entry = core::g_romcache.top;
117
//Advance cache pointer.
118
for (unsigned i = 0; i < arrayroms; i++) {
125
for (unsigned i = 0; (i < roms) && (entry != NULL); i++) {
126
//Actually add entries to RomModel
128
//printf("Added: %s\n", entry->inientry->goodname);
135
QModelIndex RomModel::index(int row, int column,
136
const QModelIndex& parent) const
139
return createIndex(row, column, m_romList.at(row));
142
QModelIndex RomModel::parent(const QModelIndex& index) const
145
return QModelIndex();
148
int RomModel::rowCount(const QModelIndex& parent) const
152
if (!parent.isValid()) {
153
retval = m_romList.count();
159
int RomModel::columnCount(const QModelIndex& parent) const
165
QVariant RomModel::data(const QModelIndex& index, int role) const
169
if (index.isValid() && (index.row() < m_romList.size())) {
170
const core::cache_entry* entry = m_romList[index.row()];
172
if (role == Qt::DisplayRole || role == Sort) {
174
switch(index.column()) {
176
data = countryName(entry->countrycode);
179
data = QString(entry->inientry->goodname);
182
data = entry->inientry->status;
185
data = QString(entry->usercomments);
188
if (core::config_get_bool("RomBrowserShowFullPaths", FALSE)) {
189
data = entry->filename;
191
data = QFileInfo(entry->filename).fileName();
196
buffer = (char*)calloc(33,sizeof(char));
197
for ( counter = 0; counter < 16; ++counter )
198
std::sprintf(buffer+counter*2, "%02X", entry->md5[counter]);
199
data = QString(buffer);
203
data = QString(entry->internalname);
206
data = QString().sprintf("%08X", entry->crc1);
209
data = QString().sprintf("%08X", entry->crc2);
212
buffer = (char*)calloc(16,sizeof(char));
213
core::savestring(entry->inientry->savetype, buffer);
214
data = QString(buffer);
218
buffer = (char*)calloc(16,sizeof(char));
219
core::playersstring(entry->inientry->players, buffer);
220
data = QString(buffer);
224
data = tr("%0 Mbit").arg((entry->romsize*8) / 1024 / 1024);
226
case CompressionType:
227
buffer = (char*)calloc(16,sizeof(char));
228
core::compressionstring(entry->compressiontype, buffer);
229
data = QString(buffer);
233
buffer = (char*)calloc(32,sizeof(char));
234
core::imagestring(entry->imagetype, buffer);
235
data = QString(buffer);
239
buffer = (char*)calloc(16,sizeof(char));
240
core::cicstring(entry->cic, buffer);
241
data = QString(buffer);
245
buffer = (char*)calloc(16,sizeof(char));
246
core::rumblestring(entry->inientry->rumble, buffer);
247
data = QString(buffer);
251
data = tr("Internal error");
254
} else if (role == Qt::FontRole) {
255
switch(index.column()) {
261
data = QFont("monospace");
264
} else if (role == Qt::TextAlignmentRole) {
265
switch(index.column()) {
270
data = Qt::AlignRight;
273
} else if (role == Qt::DecorationRole) {
274
switch(index.column()) {
276
data = countryFlag(entry->countrycode);
279
//Assign Role enums here to retrive information.
280
} else if (role == FullPath) {
281
data = entry->filename;
282
} else if (role == ArchiveFile) {
283
data = entry->archivefile;
290
bool RomModel::setData(const QModelIndex& index, const QVariant& value,
294
if (index.isValid() &&
296
index.row() < m_romList.count() &&
297
role == Qt::EditRole) {
298
switch (index.column()) {
301
qstrncpy(m_romList.at(index.row())->usercomments,
302
qPrintable(value.toString()),
304
core::g_romcache.rcstask = core::RCS_WRITE_CACHE;
305
emit dataChanged(index, index);
312
QVariant RomModel::headerData(int section, Qt::Orientation orientation,
316
if (role != Qt::DisplayRole || orientation != Qt::Horizontal)
320
case Country: return tr("Country");
321
case GoodName: return tr("Good Name");
322
case Status: return tr("Status");
323
case UserComments: return tr("User Comments");
324
case FileName: return tr("File Name");
325
case MD5Hash: return tr("MD5 Hash");
326
case InternalName: return tr("Internal Name");
327
case CRC1: return tr("CRC1");
328
case CRC2: return tr("CRC2");
329
case SaveType: return tr("Save Type");
330
case Players: return tr("Players");
331
case Size: return tr("Size");
332
case CompressionType: return tr("Compression Type");
333
case ImageType: return tr("Image Type");
334
case CICChip: return tr("CIC Chip");
335
case Rumble: return tr("Rumble");
336
default: return QVariant();
340
void RomModel::settingsChanged()
342
if (romDirectories() != m_romDirectories) {
343
m_romDirectories = romDirectories();
344
core::g_romcache.rcstask = core::RCS_RESCAN;
346
if (m_showFullPath != core::config_get_bool("RomBrowserShowFullPaths", FALSE)) {
347
m_showFullPath = core::config_get_bool("RomBrowserShowFullPaths", FALSE);
350
index(columnCount() - 1, FileName)
355
QPixmap RomModel::countryFlag(QChar c) const
357
if (!m_countryInfo.contains(c)) {
360
return m_countryInfo[c].second;
363
QString RomModel::countryName(QChar c) const
365
if (!m_countryInfo.contains(c)) {
368
return m_countryInfo[c].first;