Skip to content

Commit 9afc875

Browse files
playback-history-qt: Use printf format string
It is more consistent, can be better reused (without Qt) and does not introduce yet another format for translators.
1 parent 020cf68 commit 9afc875

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

src/playback-history-qt/playback-history.cc

+9-14
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <QMetaObject>
2727
#include <QPointer>
2828

29+
#include <libaudcore/audstrings.h>
2930
#include <libaudcore/hook.h>
3031
#include <libaudcore/i18n.h>
3132
#include <libaudcore/playlist.h>
@@ -44,14 +45,6 @@ static const char * printable(const String & str)
4445
return str ? str : "";
4546
}
4647

47-
static QString toQString(const String & str)
48-
{
49-
// The explicit cast to const char * is necessary to compile with Qt 6,
50-
// because otherwise two implicit conversions would be necessary: from
51-
// String to const char * and from const char * to QByteArrayView.
52-
return QString::fromUtf8(static_cast<const char *>(str));
53-
}
54-
5548
class PlaybackHistory : public GeneralPlugin
5649
{
5750
private:
@@ -525,17 +518,19 @@ QVariant HistoryModel::data(const QModelIndex & index, int role) const
525518
switch (role)
526519
{
527520
case Qt::DisplayRole:
528-
return toQString(m_entries[pos].text());
521+
return QString(m_entries[pos].text());
529522
case Qt::ToolTipRole:
530523
{
531524
const auto & entry = m_entries[pos];
532525
// The playlist title and entry number are rarely interesting and
533526
// therefore shown only in the tooltip.
534-
return QString::fromUtf8(_("<b>%1:</b> %2<br><b>Playlist:</b> %3"
535-
"<br><b>Entry Number:</b> %4"))
536-
.arg(QString::fromUtf8(entry.translatedTextDesignation()),
537-
toQString(entry.text()), toQString(entry.playlistTitle()),
538-
QString::number(entry.entryNumber()));
527+
return QString(
528+
str_printf(_("<b>%s:</b> %s<br><b>Playlist:</b> %s<br>"
529+
"<b>Entry Number:</b> %d"),
530+
entry.translatedTextDesignation(),
531+
static_cast<const char *>(entry.text()),
532+
static_cast<const char *>(entry.playlistTitle()),
533+
entry.entryNumber()));
539534
}
540535
case Qt::FontRole:
541536
if (pos == m_playingPosition)

0 commit comments

Comments
 (0)