Skip to content

Commit fc15060

Browse files
authored
Add ellipsis on truncated text description (#227)
* add ellipsis on truncated text (longer than maxLength) * apply maxLength on description also for ES and derivates
1 parent 18b21fe commit fc15060

9 files changed

Lines changed: 31 additions & 8 deletions

File tree

docs/CLIHELP.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ Skyscraper -p snes -i "/path/to/your/snes/roms"
130130

131131
### -l <0-10000>
132132

133-
Sets the maximum length of returned game descriptions. This is a convenience option if you feel like game descriptions are too long. By default it is set to 2500 (which is approx. two-thirds of a typewriter page). Consider setting this in [`config.ini`](CONFIGINI.md#maxlength) instead.
133+
Sets the maximum length of returned game descriptions. This is a convenience option if you feel like game descriptions are too long. By default it is set to 2500 (approx. two-thirds of a typewriter page). Consider setting this in [`config.ini`](CONFIGINI.md#maxlength) instead.
134134

135135
**Example(s)**
136136

docs/CONFIGINI.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ Allowed in sections: `[main]`, `[<PLATFORM>]`
638638

639639
#### maxLength
640640

641-
Sets the maximum length of returned game descriptions. This is a convenience option if you feel like game descriptions are too long. By default it is set to 2500.
641+
Sets the maximum length of returned game descriptions. This is a convenience option if you feel like game descriptions are too long. By default it is set to 2500 (approx. two-thirds of a typewriter page). Allowed range is 0 to 10000 characters. A truncated text will end with [...] (Ellipsis). The text is only truncated in the gamelist/frontend output. The cache will hold the full text.
642642

643643
Default value: `2500`
644644
Allowed in sections: `[main]`, `[<PLATFORM>]`, `[<FRONTEND>]`, `[<SCRAPER>]`

src/attractmode.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,10 @@ void AttractMode::assembleList(QString &finalOutput,
196196
QFile descFile(descDir.absolutePath() % "/" % entry.baseName %
197197
".txt");
198198
if (descFile.open(QIODevice::WriteOnly)) {
199-
descFile.write(entry.description.trimmed().toUtf8().left(
200-
config->maxLength));
199+
descFile.write(
200+
StrTools::shortenText(entry.description.trimmed(),
201+
config->maxLength)
202+
.toUtf8());
201203
descFile.close();
202204
}
203205
}

src/emulationstation.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,8 @@ QString EmulationStation::createXml(GameEntry &entry) {
344344
l.append(elem(GameEntry::getTag(GameEntry::Elem::RATING), entry.rating,
345345
addEmptyElem));
346346
l.append(elem(GameEntry::getTag(GameEntry::Elem::DESCRIPTION),
347-
entry.description, addEmptyElem));
347+
StrTools::shortenText(entry.description, config->maxLength),
348+
addEmptyElem));
348349

349350
QString released = entry.releaseDate;
350351
QRegularExpressionMatch m = isoTimeRe().match(released);

src/esgamelist.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,15 @@ void ESGameList::getGameData(GameEntry &game) {
8787
game.rating = getElementText(GameEntry::Elem::RATING);
8888
game.tags = getElementText(GameEntry::Elem::TAGS);
8989
game.description = getElementText(GameEntry::Elem::DESCRIPTION);
90-
90+
if (game.description.endsWith("[...]")) {
91+
qWarning()
92+
<< QString(
93+
"Game title '%1' has shortened description '[...]' at %2 "
94+
"chars. Consider using a different source than esgamelist "
95+
"when the current maxLength setting is higher than %2.")
96+
.arg(game.title)
97+
.arg(game.description.length());
98+
}
9199
if (config->cacheWheels) {
92100
// ES uses XML "marquee" but content is wheel (logo)
93101
game.wheelData =

src/pegasus.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,8 @@ void Pegasus::assembleList(QString &finalOutput,
284284
QString::number((int)(entry.rating.toDouble() * 100)) % "%"));
285285
}
286286
if (!entry.description.isEmpty()) {
287-
QString desc = entry.description.left(config->maxLength);
287+
QString desc =
288+
StrTools::shortenText(entry.description, config->maxLength);
288289
replaceColon(desc, entry.title);
289290
out.append(toPegasusFormat("description", desc));
290291
}

src/settings.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,11 @@ void RuntimeCfg::applyConfigIni(CfgType type, QSettings *settings,
546546
continue;
547547
}
548548
if (k == "maxLength") {
549-
config->maxLength = v;
549+
if (0 < v && v <= 10000) {
550+
config->maxLength = v;
551+
} else {
552+
outOfRange(k, v);
553+
}
550554
continue;
551555
}
552556
if (k == "maxFails") {

src/strtools.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,3 +401,9 @@ QString StrTools::tidyText(QString text, bool ignoreBangs) {
401401
}
402402
return po.join("\n");
403403
}
404+
405+
QString StrTools::shortenText(QString text, int maxLength) {
406+
if (text.length() > maxLength && maxLength > 4)
407+
return text.left(maxLength - 5) % "[...]";
408+
return text;
409+
}

src/strtools.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class StrTools : public QObject {
4444
static QString stripHtmlTags(QString str);
4545
static QString getMd5Sum(const QByteArray &data);
4646
static QString tidyText(QString text, bool ignoreBangs);
47+
static QString shortenText(QString text, int maxLength);
4748
};
4849

4950
#endif // STRTOOLS_H

0 commit comments

Comments
 (0)