mirror of
https://github.com/transmission/transmission
synced 2025-03-03 18:25:35 +00:00
Do not use printf-style formatting in C++ code
This commit is contained in:
parent
737fdab775
commit
6c02008280
4 changed files with 45 additions and 26 deletions
|
@ -23,6 +23,7 @@
|
|||
#include <QHBoxLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QHeaderView>
|
||||
#include <QHostAddress>
|
||||
#include <QInputDialog>
|
||||
#include <QItemSelectionModel>
|
||||
#include <QLabel>
|
||||
|
@ -91,26 +92,20 @@ namespace
|
|||
class PeerItem: public QTreeWidgetItem
|
||||
{
|
||||
Peer peer;
|
||||
QString collatedAddress;
|
||||
mutable QString collatedAddress;
|
||||
QString status;
|
||||
|
||||
public:
|
||||
|
||||
PeerItem (const Peer& p): peer(p) {}
|
||||
virtual ~PeerItem () {}
|
||||
|
||||
PeerItem (const Peer& p):
|
||||
peer(p)
|
||||
{
|
||||
int q[4];
|
||||
if (sscanf (p.address.toUtf8 ().constData (), "%d.%d.%d.%d", q+0, q+1, q+2, q+3) == 4)
|
||||
collatedAddress.sprintf ("%03d.%03d.%03d.%03d", q[0], q[1], q[2], q[3]);
|
||||
else
|
||||
collatedAddress = p.address;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
void refresh (const Peer& p) { peer = p; }
|
||||
void refresh (const Peer& p)
|
||||
{
|
||||
if (p.address != peer.address)
|
||||
collatedAddress.clear ();
|
||||
peer = p;
|
||||
}
|
||||
|
||||
void setStatus (const QString& s) { status = s; }
|
||||
|
||||
|
@ -127,9 +122,40 @@ class PeerItem: public QTreeWidgetItem
|
|||
case COL_STATUS: return status < i->status;
|
||||
case COL_CLIENT: return peer.clientName < i->peer.clientName;
|
||||
case COL_LOCK: return peer.isEncrypted && !i->peer.isEncrypted;
|
||||
default: return collatedAddress < i->collatedAddress;
|
||||
default: return address () < i->address ();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
const QString& address () const
|
||||
{
|
||||
if (collatedAddress.isEmpty ())
|
||||
{
|
||||
QHostAddress ipAddress;
|
||||
if (ipAddress.setAddress (peer.address))
|
||||
{
|
||||
if (ipAddress.protocol () == QAbstractSocket::IPv4Protocol)
|
||||
{
|
||||
const quint32 ipv4Address = ipAddress.toIPv4Address ();
|
||||
collatedAddress = QLatin1String ("1-") +
|
||||
QString::fromLatin1 (QByteArray::number (ipv4Address, 16).rightJustified (8, '0'));
|
||||
}
|
||||
else if (ipAddress.protocol () == QAbstractSocket::IPv6Protocol)
|
||||
{
|
||||
const Q_IPV6ADDR ipv6Address = ipAddress.toIPv6Address ();
|
||||
QByteArray tmp (16, '\0');
|
||||
for (int i = 0; i < 16; ++i)
|
||||
tmp[i] = ipv6Address[i];
|
||||
collatedAddress = QLatin1String ("2-") + QString::fromLatin1 (tmp.toHex ());
|
||||
}
|
||||
}
|
||||
|
||||
if (collatedAddress.isEmpty ())
|
||||
collatedAddress = QLatin1String ("3-") + peer.address.toLower ();
|
||||
}
|
||||
|
||||
return collatedAddress;
|
||||
}
|
||||
};
|
||||
|
||||
/***
|
||||
|
|
|
@ -834,7 +834,7 @@ FileTreeDelegate::paint (QPainter * painter,
|
|||
p.textAlignment = Qt::AlignCenter;
|
||||
p.textVisible = true;
|
||||
p.progress = (int)(100.0*index.data().toDouble());
|
||||
p.text = QString().sprintf("%d%%", p.progress);
|
||||
p.text = QString::fromLatin1 ("%1%").arg (p.progress);
|
||||
style->drawControl(QStyle::CE_ProgressBar, &p, painter);
|
||||
}
|
||||
else if(column == COL_WANTED)
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
#include <QMessageBox>
|
||||
|
||||
#include <libtransmission/transmission.h>
|
||||
#include <libtransmission/utils.h>
|
||||
#include <libtransmission/version.h>
|
||||
|
||||
#include "about.h"
|
||||
|
@ -672,12 +671,8 @@ TrMainWindow::openDonate ()
|
|||
void
|
||||
TrMainWindow::openHelp ()
|
||||
{
|
||||
const char * fmt = "http://www.transmissionbt.com/help/gtk/%d.%dx";
|
||||
int major, minor;
|
||||
sscanf (SHORT_VERSION_STRING, "%d.%d", &major, &minor);
|
||||
char url[128];
|
||||
tr_snprintf (url, sizeof (url), fmt, major, minor/10);
|
||||
QDesktopServices::openUrl (QUrl (url));
|
||||
QDesktopServices::openUrl (QUrl (QString::fromLatin1 ("http://www.transmissionbt.com/help/gtk/%1.%2x").
|
||||
arg (MAJOR_VERSION).arg (MINOR_VERSION / 10)));
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -184,9 +184,7 @@ TorrentDelegateMin::drawTorrent (QPainter * painter,
|
|||
myProgressBarStyle->palette.setColor (QPalette::Window, silverBack);
|
||||
}
|
||||
myProgressBarStyle->state = progressBarState;
|
||||
char buf[32];
|
||||
tr_snprintf (buf, sizeof (buf), "%d%%", (int)tr_truncd (100.0 * tor.percentDone(), 0));
|
||||
myProgressBarStyle->text = buf;
|
||||
myProgressBarStyle->text = QString::fromLatin1 ("%1%").arg (static_cast<int> (tr_truncd (100.0 * tor.percentDone (), 0)));
|
||||
myProgressBarStyle->textVisible = true;
|
||||
myProgressBarStyle->textAlignment = Qt::AlignCenter;
|
||||
setProgressBarPercentDone (option, tor);
|
||||
|
|
Loading…
Reference in a new issue