1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-03-03 18:25:35 +00:00

(qt) copyediting: whitespace/indentation

This commit is contained in:
Jordan Lee 2013-02-03 19:13:04 +00:00
parent 95541c4ebe
commit 7f8415d59e

View file

@ -96,8 +96,11 @@ class PeerItem: public QTreeWidgetItem
QString status;
public:
virtual ~PeerItem () { }
PeerItem (const 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)
@ -105,14 +108,20 @@ class PeerItem: public QTreeWidgetItem
else
collatedAddress = p.address;
}
public:
void refresh (const Peer& p) { peer = p; }
void setStatus (const QString& s) { status = s; }
virtual bool operator< (const QTreeWidgetItem & other) const {
virtual bool operator< (const QTreeWidgetItem & other) const
{
const PeerItem * i = dynamic_cast<const PeerItem*> (&other);
QTreeWidget * tw (treeWidget ());
const int column = tw ? tw->sortColumn () : 0;
switch (column) {
switch (column)
{
case COL_UP: return peer.rateToPeer < i->peer.rateToPeer;
case COL_DOWN: return peer.rateToClient < i->peer.rateToClient;
case COL_PERCENT: return peer.progress < i->peer.progress;
@ -139,7 +148,10 @@ Details :: getStockIcon (const QString& freedesktop_name, int fallback)
return icon;
}
Details :: Details (Session& session, Prefs& prefs, TorrentModel& model, QWidget * parent):
Details :: Details (Session & session,
Prefs & prefs,
TorrentModel & model,
QWidget * parent):
QDialog (parent, Qt::Dialog),
mySession (session),
myPrefs (prefs),
@ -200,7 +212,8 @@ Details :: setIds (const QSet<int>& ids)
myChangedTorrents = true;
// stop listening to the old torrents
foreach (int id, myIds) {
foreach (int id, myIds)
{
const Torrent * tor = myModel.getTorrentFromId (id);
if (tor)
disconnect (tor, SIGNAL (torrentChanged (int)), this, SLOT (onTorrentChanged ()));
@ -211,7 +224,8 @@ Details :: setIds (const QSet<int>& ids)
myTrackerModel->refresh (myModel, myIds);
// listen to the new torrents
foreach (int id, myIds) {
foreach (int id, myIds)
{
const Torrent * tor = myModel.getTorrentFromId (id);
if (tor)
connect (tor, SIGNAL (torrentChanged (int)), this, SLOT (onTorrentChanged ()));
@ -230,7 +244,8 @@ Details :: refreshPref (int key)
switch (key)
{
case Prefs :: SHOW_TRACKER_SCRAPES: {
case Prefs :: SHOW_TRACKER_SCRAPES:
{
QItemSelectionModel * selectionModel (myTrackerView->selectionModel ());
const QItemSelection selection (selectionModel->selection ());
const QModelIndex currentIndex (selectionModel->currentIndex ());
@ -259,7 +274,9 @@ Details :: refreshPref (int key)
QString
Details :: timeToStringRounded (int seconds)
{
if (seconds > 60) seconds -= (seconds % 60);
if (seconds > 60)
seconds -= (seconds % 60);
return Formatter::timeToString (seconds);
}
@ -275,11 +292,13 @@ Details :: getNewData ()
if (!myIds.empty ())
{
QSet<int> infos;
foreach (int id, myIds) {
foreach (int id, myIds)
{
const Torrent * tor = myModel.getTorrentFromId (id);
if (tor->isMagnet ())
infos.insert (tor->id ());
}
if (!infos.isEmpty ())
mySession.initTorrents (infos);
mySession.refreshExtraStats (myIds);
@ -289,7 +308,8 @@ Details :: getNewData ()
void
Details :: onTorrentChanged ()
{
if (!myHavePendingRefresh) {
if (!myHavePendingRefresh)
{
myHavePendingRefresh = true;
QTimer::singleShot (100, this, SLOT (refresh ()));
}
@ -342,7 +362,8 @@ Details :: refresh ()
const QString unknown = tr ("Unknown");
// build a list of torrents
foreach (int id, myIds) {
foreach (int id, myIds)
{
const Torrent * tor = myModel.getTorrentFromId (id);
if (tor)
torrents << tor;
@ -354,13 +375,17 @@ Details :: refresh ()
// myStateLabel
if (torrents.empty ())
{
string = none;
else {
}
else
{
bool isMixed = false;
bool allPaused = true;
bool allFinished = true;
const tr_torrent_activity baseline = torrents[0]->getActivity ();
foreach (const Torrent * t, torrents) {
foreach (const Torrent * t, torrents)
{
const tr_torrent_activity activity = t->getActivity ();
if (activity != baseline)
isMixed = true;
@ -369,6 +394,7 @@ Details :: refresh ()
if (!t->isFinished ())
allFinished = false;
}
if (isMixed)
string = mixed;
else if (allFinished)
@ -390,10 +416,15 @@ Details :: refresh ()
int64_t haveUnverified = 0;
int64_t verifiedPieces = 0;
if (torrents.empty ())
{
string = none;
else {
foreach (const Torrent * t, torrents) {
if (t->hasMetadata ()) {
}
else
{
foreach (const Torrent * t, torrents)
{
if (t->hasMetadata ())
{
haveTotal += t->haveTotal ();
haveUnverified += t->haveUnverified ();
const uint64_t v = t->haveVerified ();
@ -405,7 +436,7 @@ Details :: refresh ()
available += t->sizeWhenDone () - t->leftUntilDone () + t->desiredAvailable ();
}
}
{
const double d = 100.0 * (sizeWhenDone ? (sizeWhenDone - leftUntilDone) / sizeWhenDone : 1);
QString pct = Formatter::percentToString (d);
@ -430,27 +461,28 @@ Details :: refresh ()
.arg (Formatter::sizeToString (haveUnverified));
}
}
}
myHaveLabel->setText (string);
// myAvailabilityLabel
if (torrents.empty ())
string = none;
else {
if (sizeWhenDone == 0)
else if (sizeWhenDone == 0)
string = none;
else
string = QString ("%1%").arg (Formatter::percentToString ( (100.0 * available) / sizeWhenDone));
}
myAvailabilityLabel->setText (string);
// myDownloadedLabel
if (torrents.empty ())
{
string = none;
else {
}
else
{
uint64_t d = 0;
uint64_t f = 0;
foreach (const Torrent * t, torrents) {
foreach (const Torrent * t, torrents)
{
d += t->downloadedEver ();
f += t->failedEver ();
}
@ -463,12 +495,17 @@ Details :: refresh ()
}
myDownloadedLabel->setText (string);
// myUploadedLabel
if (torrents.empty ())
{
string = none;
else {
}
else
{
uint64_t u = 0;
uint64_t d = 0;
foreach (const Torrent * t, torrents) {
foreach (const Torrent * t, torrents)
{
u += t->uploadedEver ();
d += t->downloadedEver ();
}
@ -482,16 +519,21 @@ Details :: refresh ()
// myRunTimeLabel
if (torrents.empty ())
{
string = none;
else {
}
else
{
bool allPaused = true;
QDateTime baseline = torrents[0]->lastStarted ();
foreach (const Torrent * t, torrents) {
foreach (const Torrent * t, torrents)
{
if (baseline != t->lastStarted ())
baseline = QDateTime ();
if (!t->isPaused ())
allPaused = false;
}
if (allPaused)
string = stateString; // paused || finished
else if (baseline.isNull ())
@ -505,16 +547,23 @@ Details :: refresh ()
// myETALabel
string.clear ();
if (torrents.empty ())
{
string = none;
else {
}
else
{
int baseline = torrents[0]->getETA ();
foreach (const Torrent * t, torrents) {
if (baseline != t->getETA ()) {
foreach (const Torrent * t, torrents)
{
if (baseline != t->getETA ())
{
string = mixed;
break;
}
}
if (string.isEmpty ()) {
if (string.isEmpty ())
{
if (baseline < 0)
string = tr ("Unknown");
else
@ -526,14 +575,19 @@ Details :: refresh ()
// myLastActivityLabel
if (torrents.empty ())
{
string = none;
else {
}
else
{
QDateTime latest = torrents[0]->lastActivity ();
foreach (const Torrent * t, torrents) {
foreach (const Torrent * t, torrents)
{
const QDateTime dt = t->lastActivity ();
if (latest < dt)
latest = dt;
}
const int seconds = latest.isValid () ? latest.secsTo (qdt_now) : -1;
if (seconds < 0)
string = none;
@ -546,11 +600,16 @@ Details :: refresh ()
if (torrents.empty ())
{
string = none;
else {
}
else
{
string = torrents[0]->getError ();
foreach (const Torrent * t, torrents) {
if (string != t->getError ()) {
foreach (const Torrent * t, torrents)
{
if (string != t->getError ())
{
string = mixed;
break;
}
@ -567,17 +626,22 @@ Details :: refresh ()
// mySizeLabel
if (torrents.empty ())
{
string = none;
else {
}
else
{
int pieces = 0;
uint64_t size = 0;
uint32_t pieceSize = torrents[0]->pieceSize ();
foreach (const Torrent * t, torrents) {
foreach (const Torrent * t, torrents)
{
pieces += t->pieceCount ();
size += t->totalSize ();
if (pieceSize != t->pieceSize ())
pieceSize = 0;
}
if (!size)
string = none;
else if (pieceSize > 0)
@ -591,12 +655,14 @@ Details :: refresh ()
mySizeLabel->setText (string);
// myHashLabel
if (torrents.empty ())
string = none;
else {
if (!torrents.empty ())
{
string = torrents[0]->hashString ();
foreach (const Torrent * t, torrents) {
if (string != t->hashString ()) {
foreach (const Torrent * t, torrents)
{
if (string != t->hashString ())
{
string = mixed;
break;
}
@ -605,14 +671,16 @@ Details :: refresh ()
myHashLabel->setText (string);
// myPrivacyLabel
if (torrents.empty ())
string = none;
else {
if (!torrents.empty ())
{
bool b = torrents[0]->isPrivate ();
string = b ? tr ("Private to this tracker -- DHT and PEX disabled")
: tr ("Public torrent");
foreach (const Torrent * t, torrents) {
if (b != t->isPrivate ()) {
foreach (const Torrent * t, torrents)
{
if (b != t->isPrivate ())
{
string = mixed;
break;
}
@ -621,33 +689,38 @@ Details :: refresh ()
myPrivacyLabel->setText (string);
// myCommentBrowser
if (torrents.empty ())
string = none;
else {
if (!torrents.empty ())
{
string = torrents[0]->comment ();
foreach (const Torrent * t, torrents) {
if (string != t->comment ()) {
foreach (const Torrent * t, torrents)
{
if (string != t->comment ())
{
string = mixed;
break;
}
}
}
if (myCommentBrowser->toPlainText() != string) {
if (myCommentBrowser->toPlainText() != string)
{
myCommentBrowser->setText (string);
myCommentBrowser->setMaximumHeight (QWIDGETSIZE_MAX);
}
// myOriginLabel
if (torrents.empty ())
string = none;
else {
if (!torrents.empty ())
{
bool mixed_creator=false, mixed_date=false;
const QString creator = torrents[0]->creator ();
const QString date = torrents[0]->dateCreated ().toString ();
foreach (const Torrent * t, torrents) {
foreach (const Torrent * t, torrents)
{
mixed_creator |= (creator != t->creator ());
mixed_date |= (date != t->dateCreated ().toString ());
}
if (mixed_creator && mixed_date)
string = mixed;
else if (mixed_date && !creator.isEmpty ())
@ -662,12 +735,14 @@ Details :: refresh ()
myOriginLabel->setText (string);
// myLocationLabel
if (torrents.empty ())
string = none;
else {
if (!torrents.empty ())
{
string = torrents[0]->getPath ();
foreach (const Torrent * t, torrents) {
if (string != t->getPath ()) {
foreach (const Torrent * t, torrents)
{
if (string != t->getPath ())
{
string = mixed;
break;
}
@ -683,11 +758,11 @@ Details :: refresh ()
if (myChangedTorrents && !torrents.empty ())
{
int i;
const Torrent * baseline = *torrents.begin ();
const Torrent * tor;
bool uniform;
bool baselineFlag;
int baselineInt;
const Torrent * tor;
const Torrent * baseline = *torrents.begin ();
// mySessionLimitCheck
uniform = true;
@ -789,9 +864,11 @@ Details :: refresh ()
item->refresh (peer);
QString codeTip;
foreach (QChar ch, code) {
foreach (QChar ch, code)
{
QString txt;
switch (ch.toAscii ()) {
switch (ch.toAscii ())
{
case 'O': txt = tr ("Optimistic unchoke"); break;
case 'D': txt = tr ("Downloading from this peer"); break;
case 'd': txt = tr ("We would download from this peer if they would let us"); break;
@ -805,6 +882,7 @@ Details :: refresh ()
case 'I': txt = tr ("Peer is an incoming connection"); break;
case 'T': txt = tr ("Peer is connected over uTP"); break;
}
if (!txt.isEmpty ())
codeTip += QString ("%1: %2\n").arg (ch).arg (txt);
}
@ -821,9 +899,12 @@ Details :: refresh ()
peers2.insert (key, item);
}
}
myPeerTree->addTopLevelItems (newItems);
foreach (QString key, myPeers.keys ()) {
if (!peers2.contains (key)) { // old peer has disconnected
foreach (QString key, myPeers.keys ())
{
if (!peers2.contains (key)) // old peer has disconnected
{
QTreeWidgetItem * item = myPeers.value (key, 0);
myPeerTree->takeTopLevelItem (myPeerTree->indexOfTopLevelItem (item));
delete item;