Skip to content

Commit

Permalink
playback-history-qt: Use printf format string
Browse files Browse the repository at this point in the history
It is more consistent, can be better reused (without Qt)
and does not introduce yet another format for translators.
  • Loading branch information
radioactiveman committed Jan 11, 2025
1 parent c7448c7 commit ee2ff7d
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions src/playback-history-qt/playback-history.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <QMetaObject>
#include <QPointer>

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

static QString toQString(const String & str)
{
// The explicit cast to const char * is necessary to compile with Qt 6,
// because otherwise two implicit conversions would be necessary: from
// String to const char * and from const char * to QByteArrayView.
return QString::fromUtf8(static_cast<const char *>(str));
}

class PlaybackHistory : public GeneralPlugin
{
private:
Expand Down Expand Up @@ -525,17 +518,19 @@ QVariant HistoryModel::data(const QModelIndex & index, int role) const
switch (role)
{
case Qt::DisplayRole:
return toQString(m_entries[pos].text());
return QString(m_entries[pos].text());
case Qt::ToolTipRole:
{
const auto & entry = m_entries[pos];
// The playlist title and entry number are rarely interesting and
// therefore shown only in the tooltip.
return QString::fromUtf8(_("<b>%1:</b> %2<br><b>Playlist:</b> %3"
"<br><b>Entry Number:</b> %4"))
.arg(QString::fromUtf8(entry.translatedTextDesignation()),
toQString(entry.text()), toQString(entry.playlistTitle()),
QString::number(entry.entryNumber()));
return QString(
str_printf(_("<b>%s:</b> %s<br><b>Playlist:</b> %s<br>"
"<b>Entry Number:</b> %d"),
entry.translatedTextDesignation(),
static_cast<const char *>(entry.text()),
static_cast<const char *>(entry.playlistTitle()),
entry.entryNumber()));
}
case Qt::FontRole:
if (pos == m_playingPosition)
Expand Down

0 comments on commit ee2ff7d

Please sign in to comment.