Various cleanups and small fixes in several places.

- RomFields: Use a ternary operator in a few places when checking for
  a NULL string.

- RomData:
  - loadInternalImage(): Return -ENOTSUP, not -ENOSYS.
  - bcd_to_unix_time(): Check for invalid BCD values.

- [kde] RomDataView: Use QLabel::clear() instead of setText(QString()).
This commit is contained in:
David Korth 2020-09-15 18:40:26 -04:00
parent 244281ccdf
commit 43f27f0964
7 changed files with 49 additions and 47 deletions

View File

@ -2002,8 +2002,8 @@ rom_data_view_update_display(RomDataView *page)
const char *const desc_label_fmt = C_("RomDataView", "%s:");
// Create the data widgets.
const auto pFields_cend = pFields->cend();
int fieldIdx = 0;
const auto pFields_cend = pFields->cend();
for (auto iter = pFields->cbegin(); iter != pFields_cend; ++iter, fieldIdx++) {
const RomFields::Field &field = *iter;
if (!field.isValid)

View File

@ -956,21 +956,24 @@ void RomDataViewPrivate::adjustListData(int tabIdx)
}
QTreeWidget *const treeWidget = qobject_cast<QTreeWidget*>(liField->widget());
if (treeWidget) {
// Move the treeWidget to the QVBoxLayout.
int newRow = tab.vbox->count();
if (tab.lblCredits) {
newRow--;
}
assert(newRow >= 0);
tab.form->removeItem(liField);
tab.vbox->insertWidget(newRow, treeWidget, 999, Qt::Alignment());
delete liField;
// Unset this property to prevent the event filter from
// setting a fixed height.
treeWidget->setProperty("RFT_LISTDATA_rows_visible", 0);
if (!treeWidget) {
// Not a QTreeWidget.
return;
}
// Move the treeWidget to the QVBoxLayout.
int newRow = tab.vbox->count();
if (tab.lblCredits) {
newRow--;
}
assert(newRow >= 0);
tab.form->removeItem(liField);
tab.vbox->insertWidget(newRow, treeWidget, 999, Qt::Alignment());
delete liField;
// Unset this property to prevent the event filter from
// setting a fixed height.
treeWidget->setProperty("RFT_LISTDATA_rows_visible", QVariant());
}
/**
@ -1057,14 +1060,11 @@ void RomDataViewPrivate::initAgeRatings(QLabel *lblDesc,
// Age ratings.
const RomFields::age_ratings_t *age_ratings = field.data.age_ratings;
assert(age_ratings != nullptr);
if (!age_ratings) {
// tr: No age ratings data.
initString(lblDesc, field, fieldIdx, U82Q(C_("RomDataView", "ERROR")));
return;
}
// Convert the age ratings field to a string.
const QString str = U82Q(RomFields::ageRatingsDecode(age_ratings));
const QString str = (age_ratings
? U82Q(RomFields::ageRatingsDecode(age_ratings))
: U82Q(C_("RomDataView", "ERROR")));
initString(lblDesc, field, fieldIdx, str);
}
@ -1153,11 +1153,7 @@ void RomDataViewPrivate::updateMulti(uint32_t user_lc)
// Get the string and update the text.
const string *const pStr = RomFields::getFromStringMulti(pStr_multi, def_lc, user_lc);
assert(pStr != nullptr);
if (pStr) {
lblString->setText(U82Q(*pStr));
} else {
lblString->setText(QString());
}
lblString->setText(pStr ? U82Q(*pStr) : QString());
}
// RFT_LISTDATA_MULTI
@ -1338,9 +1334,11 @@ int RomDataViewPrivate::updateField(int fieldIdx)
break;
}
label->setText(field->data.str
? U82Q(*(field->data.str))
: QString());
if (field->data.str) {
label->setText(U82Q(*(field->data.str)));
} else {
label->clear();
}
ret = 0;
break;
}
@ -1441,7 +1439,7 @@ void RomDataViewPrivate::initDisplayWidgets(void)
return;
}
// Create the QTabWidget.
// Initialize the QTabWidget.
Q_Q(RomDataView);
const int tabCount = pFields->tabCount();
if (tabCount > 1) {
@ -1470,7 +1468,7 @@ void RomDataViewPrivate::initDisplayWidgets(void)
}
} else {
// No tabs.
// Don't create a QTabWidget, but simulate a single
// Don't initialize the QTabWidget, but simulate a single
// tab in tabs[] to make it easier to work with.
tabs.resize(1);
auto &tab = tabs[0];
@ -1493,8 +1491,8 @@ void RomDataViewPrivate::initDisplayWidgets(void)
// Create the data widgets.
int prevTabIdx = 0;
const auto pFields_cend = pFields->cend();
int fieldIdx = 0;
const auto pFields_cend = pFields->cend();
for (auto iter = pFields->cbegin(); iter != pFields_cend; ++iter, fieldIdx++) {
const RomFields::Field &field = *iter;
if (!field.isValid)

View File

@ -107,7 +107,7 @@ class MegaDrivePrivate final : public RomDataPrivate
* Discs don't have a vector table.
* @return True if this is a disc; false if not.
*/
inline bool isDisc(void)
inline bool isDisc(void) const
{
int rfmt = romType & ROM_FORMAT_MASK;
return (rfmt == ROM_FORMAT_DISC_2048 ||

View File

@ -40,7 +40,7 @@ ROMDATA_IMPL_IMG_SIZES(Xbox360_XDBF)
class Xbox360_XDBF_Private final : public RomDataPrivate
{
public:
Xbox360_XDBF_Private(Xbox360_XDBF *q, IRpFile *file, bool cia);
Xbox360_XDBF_Private(Xbox360_XDBF *q, IRpFile *file, bool xex);
virtual ~Xbox360_XDBF_Private();
private:

View File

@ -315,7 +315,14 @@ time_t RomDataPrivate::bcd_to_unix_time(const uint8_t *bcd_tm, size_t size)
// - tm_mon: 0 == January
struct tm bcdtime;
// TODO: Check for invalid BCD values.
// Check for invalid BCD values.
for (unsigned int i = 0; i < size; i++) {
if ((bcd_tm[i] & 0x0F) > 9 || (bcd_tm[i] & 0xF0) > 0x90) {
// Invalid BCD value.
return -1;
}
}
if (size >= 4) {
bcdtime.tm_year = ((bcd_tm[0] >> 4) * 1000) +
((bcd_tm[0] & 0x0F) * 100) +
@ -544,6 +551,7 @@ const char *RomData::className(void) const
RomData::FileType RomData::fileType(void) const
{
RP_D(const RomData);
assert(d->fileType != FileType::Unknown);
return d->fileType;
}
@ -723,7 +731,7 @@ int RomData::loadInternalImage(ImageType imageType, const rp_image **pImage)
int RomData::loadMetaData(void)
{
// Not implemented for the base class.
return -ENOSYS;
return -ENOTSUP;
}
/**

View File

@ -531,6 +531,7 @@ void RomFields::setTabName(int tabIdx, const char *name)
// Need to resize tabNames.
d->tabNames.resize(tabIdx+1);
}
d->tabNames[tabIdx] = (name ? name : "");
}
@ -626,11 +627,8 @@ vector<string> *RomFields::strArrayToVector(const char *const *strArray, size_t
for (; count > 0; strArray++, count--) {
// nullptr will be handled as empty strings.
if (*strArray) {
pVec->emplace_back(*strArray);
} else {
pVec->emplace_back("");
}
const char* const str = *strArray;
pVec->emplace_back(str ? str : "");
}
return pVec;
@ -659,11 +657,10 @@ vector<string> *RomFields::strArrayToVector_i18n(const char *msgctxt, const char
for (; count > 0; strArray++, count--) {
// nullptr will be handled as empty strings.
if (*strArray) {
pVec->emplace_back(dpgettext_expr(RP_I18N_DOMAIN, msgctxt, *strArray));
} else {
pVec->emplace_back("");
}
const char* const str = *strArray;
pVec->emplace_back(str
? dpgettext_expr(RP_I18N_DOMAIN, msgctxt, str)
: "");
}
return pVec;

View File

@ -471,7 +471,6 @@ public:
linePos[col] = (unsigned int)string::npos;
} else {
// Found a newline.
// TODO: Update SafeString to take a length parameter instead of creating a temporary string.
str = SafeString(jt->c_str() + linePos[col], nl_pos - linePos[col], false);
linePos[col] = (unsigned int)(nl_pos + 1);
if (linePos[col] > (unsigned int)jt->size()) {