diff --git a/qt/details.cc b/qt/details.cc index a15522292..cd3a15d83 100644 --- a/qt/details.cc +++ b/qt/details.cc @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -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; + } }; /*** diff --git a/qt/file-tree.cc b/qt/file-tree.cc index cd6bf6953..ff1d777d0 100644 --- a/qt/file-tree.cc +++ b/qt/file-tree.cc @@ -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) diff --git a/qt/mainwin.cc b/qt/mainwin.cc index 7add920e1..899921ef7 100644 --- a/qt/mainwin.cc +++ b/qt/mainwin.cc @@ -19,7 +19,6 @@ #include #include -#include #include #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 diff --git a/qt/torrent-delegate-min.cc b/qt/torrent-delegate-min.cc index a1318dbfe..59aeebd27 100644 --- a/qt/torrent-delegate-min.cc +++ b/qt/torrent-delegate-min.cc @@ -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 (tr_truncd (100.0 * tor.percentDone (), 0))); myProgressBarStyle->textVisible = true; myProgressBarStyle->textAlignment = Qt::AlignCenter; setProgressBarPercentDone (option, tor);