Skip to content

Commit 5ef538a

Browse files
committed
add ellipsis on truncated text (longer than maxLength)
1 parent 19899c5 commit 5ef538a

6 files changed

Lines changed: 19 additions & 5 deletions

File tree

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. Allowed range is 0 to 10000 characters. A truncated text will end with [...] (Ellipsis).
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/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)