const QStringList& searchDirectories)
{
const QString filename = name + QLatin1Char ('_') + localeName;
- foreach (const QString& directory, searchDirectories)
+ for (const QString& directory: searchDirectories)
{
if (translator.load (filename, directory))
return true;
{
QList<int> sizes;
sizes << 16 << 22 << 24 << 32 << 48 << 64 << 72 << 96 << 128 << 192 << 256;
- foreach (int size, sizes)
+ for (const int size: sizes)
icon.addPixmap (QPixmap (QString::fromLatin1 (":/icons/transmission-%1.png").arg (size)));
}
setWindowIcon (icon);
if (bus.isConnected ())
{
bool delegated = false;
- for (int i=0, n=filenames.size (); i<n; ++i)
+ for (const QString& filename: filenames)
{
QDBusMessage request = QDBusMessage::createMethodCall (DBUS_SERVICE,
DBUS_OBJECT_PATH,
DBUS_INTERFACE,
QString::fromUtf8 ("AddMetainfo"));
QList<QVariant> arguments;
- AddData a (filenames[i]);
+ AddData a (filename);
switch (a.type)
{
case AddData::URL: arguments.push_back (a.url.toString ()); break;
// init from preferences
QList<int> initKeys;
initKeys << Prefs::DIR_WATCH;
- foreach (int key, initKeys)
+ for (const int key: initKeys)
refreshPref (key);
connect (myPrefs, SIGNAL (changed (int)), this, SLOT (refreshPref (const int)));
dialog->show ();
}
- for (QStringList::const_iterator it=filenames.begin (), end=filenames.end (); it!=end; ++it)
- addTorrent (*it);
+ for (const QString& filename: filenames)
+ addTorrent (filename);
// register as the dbus handler for Transmission
if (bus.isConnected ())
if (!myPrefs->getBool (Prefs::SHOW_NOTIFICATION_ON_ADD))
return;
- foreach (int id, torrents)
+ for (const int id: torrents)
{
Torrent * tor = myModel->getTorrentFromId (id);
namespace
{
int
- itemColumnSpan (QGridLayout * layout, const QLayoutItem * item)
+ itemColumnSpan (const QGridLayout * layout, const QLayoutItem * item)
{
for (int i = 0, count = layout->count (); i < count; ++i)
{
ColumnResizer::update ()
{
int maxWidth = 0;
- foreach (QGridLayout * layout, myLayouts)
+ for (const QGridLayout * const layout: myLayouts)
{
for (int i = 0, count = layout->rowCount (); i < count; ++i)
{
}
}
- foreach (QGridLayout * layout, myLayouts)
+ for (QGridLayout * const layout: myLayouts)
layout->setColumnMinimumWidth (0, maxWidth);
}
QList<int> initKeys;
initKeys << Prefs::SHOW_TRACKER_SCRAPES
<< Prefs::SHOW_BACKUP_TRACKERS;
- foreach (int key, initKeys)
+ for (const int key: initKeys)
refreshPref (key);
connect (&myTimer, SIGNAL (timeout ()), this, SLOT (onTimer ()));
myChangedTorrents = true;
// stop listening to the old torrents
- foreach (int id, myIds)
+ for (const int id: myIds)
{
const Torrent * tor = myModel.getTorrentFromId (id);
if (tor)
myTrackerModel->refresh (myModel, myIds);
// listen to the new torrents
- foreach (int id, myIds)
+ for (const int id: myIds)
{
const Torrent * tor = myModel.getTorrentFromId (id);
if (tor)
if (!myIds.empty ())
{
QSet<int> infos;
- foreach (int id, myIds)
+ for (const int id: myIds)
{
const Torrent * tor = myModel.getTorrentFromId (id);
if (tor->isMagnet ())
const QString unknown = tr ("Unknown");
// build a list of torrents
- foreach (int id, myIds)
+ for (const int id: myIds)
{
const Torrent * tor = myModel.getTorrentFromId (id);
if (tor)
bool allPaused = true;
bool allFinished = true;
const tr_torrent_activity baseline = torrents[0]->getActivity ();
- foreach (const Torrent * t, torrents)
+ for (const Torrent * const t: torrents)
{
const tr_torrent_activity activity = t->getActivity ();
if (activity != baseline)
int64_t haveUnverified = 0;
int64_t verifiedPieces = 0;
- foreach (const Torrent * t, torrents)
+ for (const Torrent * const t: torrents)
{
if (t->hasMetadata ())
{
{
uint64_t d = 0;
uint64_t f = 0;
- foreach (const Torrent * t, torrents)
+ for (const Torrent * const t: torrents)
{
d += t->downloadedEver ();
f += t->failedEver ();
{
uint64_t u = 0;
uint64_t d = 0;
- foreach (const Torrent * t, torrents)
+ for (const Torrent * const t: torrents)
{
u += t->uploadedEver ();
d += t->downloadedEver ();
{
bool allPaused = true;
QDateTime baseline = torrents[0]->lastStarted ();
- foreach (const Torrent * t, torrents)
+ for (const Torrent * const t: torrents)
{
if (baseline != t->lastStarted ())
baseline = QDateTime ();
else
{
int baseline = torrents[0]->getETA ();
- foreach (const Torrent * t, torrents)
+ for (const Torrent * const t: torrents)
{
if (baseline != t->getETA ())
{
else
{
QDateTime latest = torrents[0]->lastActivity ();
- foreach (const Torrent * t, torrents)
+ for (const Torrent * const t: torrents)
{
const QDateTime dt = t->lastActivity ();
if (latest < dt)
else
{
string = torrents[0]->getError ();
- foreach (const Torrent * t, torrents)
+ for (const Torrent * const t: torrents)
{
if (string != t->getError ())
{
int pieces = 0;
uint64_t size = 0;
uint32_t pieceSize = torrents[0]->pieceSize ();
- foreach (const Torrent * t, torrents)
+ for (const Torrent * const t: torrents)
{
pieces += t->pieceCount ();
size += t->totalSize ();
if (!torrents.empty ())
{
string = torrents[0]->hashString ();
- foreach (const Torrent * t, torrents)
+ for (const Torrent * const t: torrents)
{
if (string != t->hashString ())
{
bool b = torrents[0]->isPrivate ();
string = b ? tr ("Private to this tracker -- DHT and PEX disabled")
: tr ("Public torrent");
- foreach (const Torrent * t, torrents)
+ for (const Torrent * const t: torrents)
{
if (b != t->isPrivate ())
{
if (!torrents.empty ())
{
string = torrents[0]->comment ();
- foreach (const Torrent * t, torrents)
+ for (const Torrent * const t: torrents)
{
if (string != t->comment ())
{
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)
+ for (const Torrent * const t: torrents)
{
mixed_creator |= (creator != t->creator ());
mixed_date |= (date != t->dateCreated ().toString ());
if (!torrents.empty ())
{
string = torrents[0]->getPath ();
- foreach (const Torrent * t, torrents)
+ for (const Torrent * const t: torrents)
{
if (string != t->getPath ())
{
bool uniform;
bool baselineFlag;
int baselineInt;
- const Torrent * tor;
- const Torrent * baseline = *torrents.begin ();
+ const Torrent& baseline = *torrents.front ();
// mySessionLimitCheck
uniform = true;
- baselineFlag = baseline->honorsSessionLimits ();
- foreach (tor, torrents) if (baselineFlag != tor->honorsSessionLimits ()) { uniform = false; break; }
+ baselineFlag = baseline.honorsSessionLimits ();
+ for (const Torrent * const tor: torrents) if (baselineFlag != tor->honorsSessionLimits ()) { uniform = false; break; }
ui.sessionLimitCheck->setChecked (uniform && baselineFlag);
// mySingleDownCheck
uniform = true;
- baselineFlag = baseline->downloadIsLimited ();
- foreach (tor, torrents) if (baselineFlag != tor->downloadIsLimited ()) { uniform = false; break; }
+ baselineFlag = baseline.downloadIsLimited ();
+ for (const Torrent * const tor: torrents) if (baselineFlag != tor->downloadIsLimited ()) { uniform = false; break; }
ui.singleDownCheck->setChecked (uniform && baselineFlag);
// mySingleUpCheck
uniform = true;
- baselineFlag = baseline->uploadIsLimited ();
- foreach (tor, torrents) if (baselineFlag != tor->uploadIsLimited ()) { uniform = false; break; }
+ baselineFlag = baseline.uploadIsLimited ();
+ for (const Torrent * const tor: torrents) if (baselineFlag != tor->uploadIsLimited ()) { uniform = false; break; }
ui.singleUpCheck->setChecked (uniform && baselineFlag);
// myBandwidthPriorityCombo
uniform = true;
- baselineInt = baseline->getBandwidthPriority ();
- foreach (tor, torrents) if (baselineInt != tor->getBandwidthPriority ()) { uniform = false; break; }
+ baselineInt = baseline.getBandwidthPriority ();
+ for (const Torrent * const tor: torrents) if (baselineInt != tor->getBandwidthPriority ()) { uniform = false; break; }
if (uniform)
i = ui.bandwidthPriorityCombo->findData (baselineInt);
else
i = -1;
setIfIdle (ui.bandwidthPriorityCombo, i);
- setIfIdle (ui.singleDownSpin, int (tor->downloadLimit ().KBps ()));
- setIfIdle (ui.singleUpSpin, int (tor->uploadLimit ().KBps ()));
- setIfIdle (ui.peerLimitSpin, tor->peerLimit ());
+ setIfIdle (ui.singleDownSpin, int (baseline.downloadLimit ().KBps ()));
+ setIfIdle (ui.singleUpSpin, int (baseline.uploadLimit ().KBps ()));
+ setIfIdle (ui.peerLimitSpin, baseline.peerLimit ());
}
if (!torrents.empty ())
{
- const Torrent * tor;
+ const Torrent& baseline = *torrents.front ();
// ratio
bool uniform = true;
- int baselineInt = torrents[0]->seedRatioMode ();
- foreach (tor, torrents) if (baselineInt != tor->seedRatioMode ()) { uniform = false; break; }
+ int baselineInt = baseline.seedRatioMode ();
+ for (const Torrent * const tor: torrents) if (baselineInt != tor->seedRatioMode ()) { uniform = false; break; }
setIfIdle (ui.ratioCombo, uniform ? ui.ratioCombo->findData (baselineInt) : -1);
ui.ratioSpin->setVisible (uniform && (baselineInt == TR_RATIOLIMIT_SINGLE));
- setIfIdle (ui.ratioSpin, tor->seedRatioLimit ());
+ setIfIdle (ui.ratioSpin, baseline.seedRatioLimit ());
// idle
uniform = true;
- baselineInt = torrents[0]->seedIdleMode ();
- foreach (tor, torrents) if (baselineInt != tor->seedIdleMode ()) { uniform = false; break; }
+ baselineInt = baseline.seedIdleMode ();
+ for (const Torrent * const tor: torrents) if (baselineInt != tor->seedIdleMode ()) { uniform = false; break; }
setIfIdle (ui.idleCombo, uniform ? ui.idleCombo->findData (baselineInt) : -1);
ui.idleSpin->setVisible (uniform && (baselineInt == TR_RATIOLIMIT_SINGLE));
- setIfIdle (ui.idleSpin, tor->seedIdleLimit ());
+ setIfIdle (ui.idleSpin, baseline.seedIdleLimit ());
onIdleLimitChanged ();
}
QMap<QString,QTreeWidgetItem*> peers2;
QList<QTreeWidgetItem*> newItems;
- foreach (const Torrent * t, torrents)
+ for (const Torrent * const t: torrents)
{
const QString idStr (QString::number (t->id ()));
PeerList peers = t->peers ();
- foreach (const Peer& peer, peers)
+ for (const Peer& peer: peers)
{
const QString key = idStr + QLatin1Char (':') + peer.address;
PeerItem * item = static_cast<PeerItem*> (myPeers.value (key, 0));
item->refresh (peer);
QString codeTip;
- foreach (QChar ch, code)
+ for (const QChar ch: code)
{
QString txt;
switch (ch.unicode ())
}
ui.peersView->addTopLevelItems (newItems);
- foreach (QString key, myPeers.keys ())
+ for (const QString& key: myPeers.keys ())
{
if (!peers2.contains (key)) // old peer has disconnected
{
{
QSet<int> ids;
- foreach (int id, myIds)
+ for (const int id: myIds)
if (myTrackerModel->find (id,url) == -1)
ids.insert (id);
QItemSelectionModel * selectionModel = ui.trackersView->selectionModel ();
QModelIndexList selectedRows = selectionModel->selectedRows ();
QMap<int,int> torrentId_to_trackerIds;
- foreach (QModelIndex i, selectedRows)
+ for (const QModelIndex& i: selectedRows)
{
const TrackerInfo inf = ui.trackersView->model ()->data (i, TrackerModel::TrackerRole).value<TrackerInfo> ();
torrentId_to_trackerIds.insertMulti (inf.torrentId, inf.st.id);
}
// batch all of a tracker's torrents into one command
- foreach (int id, torrentId_to_trackerIds.uniqueKeys ())
+ for (const int id: torrentId_to_trackerIds.uniqueKeys ())
{
QSet<int> ids;
ids << id;
if (!mySession.isLocal ())
return;
- foreach (const int id, myIds)
+ for (const int id: myIds)
{
const Torrent * const tor = myModel.getTorrentFromId (id);
if (tor == NULL)
cacheDir.mkpath (cacheDir.absolutePath ());
QStringList files = cacheDir.entryList (QDir::Files|QDir::Readable);
- foreach (QString file, files)
+ for (const QString& file: files)
{
QPixmap pixmap;
pixmap.load (cacheDir.absoluteFilePath (file));
const QString path = QLatin1String ("http://") + host + QLatin1String ("/favicon.");
QStringList suffixes;
suffixes << QLatin1String ("ico") << QLatin1String ("png") << QLatin1String ("gif") << QLatin1String ("jpg");
- foreach (QString suffix, suffixes)
+ for (const QString& suffix: suffixes)
myNAM->get (QNetworkRequest (path + suffix));
}
}
total += myTotalSize;
}
- foreach(const FileTreeItem * i, myChildren)
+ for (const FileTreeItem * const i: myChildren)
i->getSubtreeWantedSize(have, total);
}
}
}
- foreach (const FileTreeItem * child, myChildren)
+ for (const FileTreeItem * const child: myChildren)
i |= child->priority();
return i;
ids.insert (myFileIndex);
}
- foreach (FileTreeItem * child, myChildren)
+ for (FileTreeItem * const child: myChildren)
child->setSubtreePriority (i, ids);
}
return myIsWanted ? Qt::Checked : Qt::Unchecked;
int wanted(-1);
- foreach (const FileTreeItem * child, myChildren)
+ for (const FileTreeItem * const child: myChildren)
{
const int childWanted = child->isSubtreeWanted();
ids.insert(myFileIndex);
}
- foreach (FileTreeItem * child, myChildren)
+ for (FileTreeItem * const child: myChildren)
child->setSubtreeWanted (b, ids);
}
switch (static_cast<QKeyEvent*> (event)->key ())
{
case Qt::Key_Space:
- foreach (const QModelIndex& i, selectionModel ()->selectedRows (COL_WANTED))
+ for (const QModelIndex& i: selectionModel ()->selectedRows (COL_WANTED))
clicked (i);
break;
case Qt::Key_Enter:
case Qt::Key_Return:
- foreach (const QModelIndex& i, selectionModel ()->selectedRows (COL_PRIORITY))
+ for (const QModelIndex& i: selectionModel ()->selectedRows (COL_PRIORITY))
clicked (i);
break;
}
void
FileTreeView::update (const FileList& files, bool updateFields)
{
- foreach (const TrFile file, files)
+ for (const TrFile& file: files)
{
QList<QModelIndex> added;
myModel.addFile (file.index, file.filename, file.wanted, file.priority, file.size, file.have, added, updateFields);
- foreach (QModelIndex i, added)
+ for (const QModelIndex& i: added)
expand (myProxy->mapFromSource(i));
}
}
break;
const Torrent * tor = index.data (TorrentModel::TorrentRole).value<const Torrent*> ();
QSet<QString> torrentNames;
- foreach (QString host, tor->hosts ())
+ for (const QString& host: tor->hosts ())
{
newHosts.insert (host);
torrentNames.insert (readableHostName (host));
}
- foreach (QString name, torrentNames)
+ for (const QString& name: torrentNames)
++torrentsPerHost[name];
}
myTrackerModel->setData (myTrackerModel->index (0,0), getCountString (myTorrents.rowCount ()), TorrentCountStringRole);
// rows to update
- foreach (QString host, oldHosts & newHosts)
+ for (const QString& host: oldHosts & newHosts)
{
const QString name = readableHostName (host);
QStandardItem * row = myTrackerModel->findItems (name).front ();
}
// rows to remove
- foreach (QString host, oldHosts - newHosts)
+ for (const QString& host: oldHosts - newHosts)
{
const QString name = readableHostName (host);
QStandardItem * item = myTrackerModel->findItems (name).front ();
// rows to add
bool anyAdded = false;
- foreach (QString host, newHosts - oldHosts)
+ for (const QString& host: newHosts - oldHosts)
{
const QString name = readableHostName (host);
QList<int> initKeys;
initKeys << Prefs::FILTER_MODE
<< Prefs::FILTER_TRACKERS;
- foreach (int key, initKeys)
+ for (const int key: initKeys)
refreshPref (key);
}
<< Prefs::USPEED_ENABLED
<< Prefs::RATIO
<< Prefs::RATIO_ENABLED;
- foreach (int key, initKeys)
+ for (const int key: initKeys)
refreshPref (key);
connect (&mySession, SIGNAL (sourceChanged ()), this, SLOT (onSessionSourceChanged ()));
g->addAction (a);
connect (a, SIGNAL (triggered (bool)), this, SLOT (onSetPrefs (bool)));
sub->addSeparator ();
- foreach (int i, stockSpeeds)
+ for (const int i: stockSpeeds)
{
a = sub->addAction (Formatter::speedToString (Speed::fromKBps (i)));
a->setProperty (PREF_VARIANTS_KEY, QVariantList () << Prefs::DSPEED << i << Prefs::DSPEED_ENABLED << true);
g->addAction (a);
connect (a, SIGNAL (triggered (bool)), this, SLOT (onSetPrefs (bool)));
sub->addSeparator ();
- foreach (int i, stockSpeeds)
+ for (const int i: stockSpeeds)
{
a = sub->addAction (Formatter::speedToString (Speed::fromKBps (i)));
a->setProperty (PREF_VARIANTS_KEY, QVariantList () << Prefs::USPEED << i << Prefs::USPEED_ENABLED << true);
g->addAction (a);
connect (a, SIGNAL (triggered (bool)), this, SLOT (onSetPrefs (bool)));
sub->addSeparator ();
- foreach (double i, stockRatios)
+ for (const double i: stockRatios)
{
a = sub->addAction (Formatter::ratioToString (i));
a->setProperty (PREF_VARIANTS_KEY, QVariantList () << Prefs::RATIO << i << Prefs::RATIO_ENABLED << true);
{
QSet<int> ids;
- foreach (QModelIndex index, ui.listView->selectionModel ()->selectedRows ())
+ for (const QModelIndex& index: ui.listView->selectionModel ()->selectedRows ())
{
const Torrent * tor (index.data (TorrentModel::TorrentRole).value<const Torrent*> ());
ids.insert (tor->id ());
showOptions = b->isChecked ();
}
- foreach (const QString& filename, filenames)
+ for (const QString& filename: filenames)
addTorrent (filename, showOptions);
}
int connected = 0;
int count;
- foreach (QModelIndex index, ui.listView->selectionModel ()->selectedRows ())
+ for (const QModelIndex& index: ui.listView->selectionModel ()->selectedRows ())
{
const Torrent * tor (index.data (TorrentModel::TorrentRole).value<const Torrent*> ());
ids.insert (tor->id ());
}
else if (event->mimeData()->hasUrls())
{
- foreach (QUrl url, event->mimeData()->urls())
+ for (const QUrl& url: event->mimeData()->urls())
list.append(url.toLocalFile());
}
- foreach (QString entry, list)
+ for (const QString& entry: list)
{
QString key = entry.trimmed();
// get the tiers
int tier = 0;
QVector<tr_tracker_info> trackers;
- foreach (QString line, ui.trackersEdit->toPlainText ().split (QLatin1Char ('\n')))
+ for (const QString& line: ui.trackersEdit->toPlainText ().split (QLatin1Char ('\n')))
{
- line = line.trimmed ();
- if (line.isEmpty ())
+ const QString announceUrl = line.trimmed ();
+ if (announceUrl.isEmpty ())
{
++tier;
}
else
{
tr_tracker_info tmp;
- tmp.announce = tr_strdup (line.toUtf8 ().constData ());
+ tmp.announce = tr_strdup (announceUrl.toUtf8 ().constData ());
tmp.tier = tier;
trackers.append (tmp);
}
void
OptionsDialog::onPriorityChanged (const QSet<int>& fileIndices, int priority)
{
- foreach (int i, fileIndices)
+ for (const int i: fileIndices)
myPriorities[i] = priority;
}
void
OptionsDialog::onWantedChanged (const QSet<int>& fileIndices, bool isWanted)
{
- foreach (int i, fileIndices)
+ for (const int i: fileIndices)
myWanted[i] = isWanted;
}
myVerifyPiecePos = 0;
myVerifyTimer.stop ();
- for (int i = 0, n = myFiles.size (); i < n; ++i)
- myFiles[i].have = 0;
+ for (TrFile& f: myFiles)
+ f.have = 0;
ui.filesView->update (myFiles);
}
if (done)
{
uint64_t have = 0;
- foreach (const TrFile& f, myFiles)
+ for (const TrFile& f: myFiles)
have += f.have;
if (!have) // everything failed
<< Prefs::INCOMPLETE_DIR
<< Prefs::INCOMPLETE_DIR_ENABLED
<< Prefs::SCRIPT_TORRENT_DONE_FILENAME;
- foreach (int key, keys)
+ for (const int key: keys)
refreshPref (key);
// if it's a remote session, disable the preferences
// that don't work in remote sessions
if (!myIsServer)
{
- foreach (QWidget * w, myUnsupportedWhenRemote)
+ for (QWidget * const w: myUnsupportedWhenRemote)
{
w->setToolTip (tr ("Not supported by remote sessions"));
w->setEnabled (false);
const bool enabled (myPrefs.getBool (Prefs::RPC_ENABLED));
const bool whitelist (myPrefs.getBool (Prefs::RPC_WHITELIST_ENABLED));
const bool auth (myPrefs.getBool (Prefs::RPC_AUTH_REQUIRED));
- foreach (QWidget * w, myWebWhitelistWidgets)
+ for (QWidget * const w: myWebWhitelistWidgets)
w->setEnabled (enabled && whitelist);
- foreach (QWidget * w, myWebAuthWidgets)
+ for (QWidget * const w: myWebAuthWidgets)
w->setEnabled (enabled && auth);
- foreach (QWidget * w, myWebWidgets)
+ for (QWidget * const w: myWebWidgets)
w->setEnabled (enabled);
break;
}
case Prefs::ALT_SPEED_LIMIT_TIME_ENABLED:
{
const bool enabled = myPrefs.getBool (key);
- foreach (QWidget * w, mySchedWidgets)
+ for (QWidget * const w: mySchedWidgets)
w->setEnabled (enabled);
break;
}
case Prefs::BLOCKLIST_ENABLED:
{
const bool enabled = myPrefs.getBool (key);
- foreach (QWidget * w, myBlockWidgets)
+ for (QWidget * const w: myBlockWidgets)
w->setEnabled (enabled);
break;
}
ui.setupUi (this);
QString path;
- foreach (int id, myIds)
+ for (const int id: myIds)
{
const Torrent * tor = model.getTorrentFromId (id);
#ifdef DEBUG_HTTP
std::cerr << "sending " << "POST " << qPrintable (myUrl.path ()) << std::endl;
- foreach (const QByteArray& b, request.rawHeaderList ())
+ for (const QByteArray& b: request.rawHeaderList ())
std::cerr << b.constData ()
<< ": "
<< request.rawHeader (b).constData ()
{
#ifdef DEBUG_HTTP
std::cerr << "http response header: " << std::endl;
- foreach (const QByteArray& b, reply->rawHeaderList ())
+ for (const QByteArray& b: reply->rawHeaderList ())
std::cerr << b.constData ()
<< ": "
<< reply->rawHeader (b).constData ()
const bool isRemote = ui.remoteSessionRadio->isChecked ();
const bool useAuth = ui.authCheck->isChecked ();
- foreach (QWidget * w, myRemoteWidgets)
+ for (QWidget * const w: myRemoteWidgets)
w->setEnabled (isRemote);
- foreach (QWidget * w, myAuthWidgets)
+ for (QWidget * const w: myAuthWidgets)
w->setEnabled (isRemote && useAuth);
}
addList (tr_variant * list, const KeyList& keys)
{
tr_variantListReserve (list, keys.size ());
- foreach (tr_quark key, keys)
+ for (const tr_quark key: keys)
tr_variantListAddQuark (list, key);
}
}
if (!ids.isEmpty ())
{
tr_variant * idList (tr_variantDictAddList (args, TR_KEY_ids, ids.size ()));
- foreach (int i, ids)
+ for (const int i: ids)
tr_variantListAddInt (idList, i);
}
}
tr_variantInitDict (&args, 2);
addOptionalIds (&args, ids);
tr_variant * list (tr_variantDictAddList (&args, key, value.size ()));
- foreach (const QString& str, value)
+ for (const QString& str: value)
tr_variantListAddStr (list, str.toUtf8 ().constData ());
exec(TR_KEY_torrent_set, &args);
tr_variantInitDict (&args, 2);
addOptionalIds (&args, ids);
tr_variant * list (tr_variantDictAddList (&args, key, value.size ()));
- foreach (int i, value)
+ for (const int i: value)
tr_variantListAddInt (list, i);
exec (TR_KEY_torrent_set, &args);
<< Prefs::FILTER_MODE
<< Prefs::FILTER_TRACKERS
<< Prefs::FILTER_TEXT;
- foreach (int key, initKeys)
+ for (const int key: initKeys)
refreshPref (key);
}
myIdToRow.clear ();
myIdToTorrent.clear ();
- foreach (Torrent * tor, myTorrents) delete tor;
+ qDeleteAll (myTorrents);
myTorrents.clear ();
endResetModel ();
beginInsertRows (QModelIndex(), oldCount, newCount - 1);
- foreach (Torrent * tor, newTorrents)
+ for (Torrent * const tor: newTorrents)
{
addTorrent (tor);
addIds.insert (tor->id ());
{
QSet<int> removedIds (oldIds);
removedIds -= newIds;
- foreach (int id, removedIds)
+ for (const int id: removedIds)
removeTorrent (id);
}
}
beginRemoveRows (QModelIndex(), row, row);
// make the myIdToRow map consistent with list view/model
- for (QMap<int,int>::iterator i = myIdToRow.begin(); i != myIdToRow.end(); ++i)
+ for (auto i = myIdToRow.begin(); i != myIdToRow.end(); ++i)
if (i.value() > row)
--i.value();
myIdToRow.remove (id);
Speed upSpeed, downSpeed;
size_t upCount=0, downCount=0;
- foreach (const Torrent * const tor, myTorrents)
+ for (const Torrent * const tor: myTorrents)
{
upSpeed += tor->uploadSpeed ();
upCount += tor->peersWeAreUploadingTo ();
QSet<int> ids;
ids.reserve (myTorrents.size());
- foreach (const Torrent * tor, myTorrents)
+ for (const Torrent * const tor: myTorrents)
ids.insert (tor->id());
return ids;
bool
TorrentModel::hasTorrent (const QString& hashString) const
{
- foreach (const Torrent * tor, myTorrents)
+ for (const Torrent * const tor: myTorrents)
if (tor->hashString () == hashString)
return true;
bool
Torrent::hasFileSubstring (const QString& substr) const
{
- foreach (const TrFile file, myFiles)
+ for (const TrFile& file: myFiles)
if (file.filename.contains (substr, Qt::CaseInsensitive))
return true;
bool
Torrent::hasTrackerSubstring (const QString& substr) const
{
- foreach (QString s, myValues[TRACKERS].toStringList())
+ for (const QString& s: myValues[TRACKERS].toStringList())
if (s.contains (substr, Qt::CaseInsensitive))
return true;
if (myValues[TRACKERS] != list)
{
QStringList hosts;
- foreach (QString tracker, list)
+ for (const QString& tracker: list)
{
const QString host = Favicons::getHost (QUrl (tracker));
if (!host.isEmpty())
{
// build a list of the TrackerInfos
QVector<TrackerInfo> trackers;
- foreach (int id, ids)
+ for (const int id: ids)
{
const Torrent * tor = torrentModel.getTorrentFromId (id);
if (tor != 0)
{
const TrackerStatsList trackerList = tor->trackerStats ();
- foreach (const TrackerStat& st, trackerList)
+ for (const TrackerStat& st: trackerList)
{
TrackerInfo trackerInfo;
trackerInfo.st = st;
const char * doc_types[] = {
"abw", "csv", "doc", "dvi", "htm", "html", "ini", "log", "odp",
"ods", "odt", "pdf", "ppt", "ps", "rtf", "tex", "txt", "xml" };
- for (int i=0, n=sizeof(doc_types)/sizeof(doc_types[0]); i<n; ++i)
- suffixes[DOCUMENT] << QString::fromLatin1(doc_types[i]);
+ for (const char * t: doc_types)
+ suffixes[DOCUMENT] << QString::fromLatin1(t);
fileIcons[DOCUMENT] = QIcon::fromTheme (QString::fromLatin1("text-x-generic"), fallback);
const char * pic_types[] = {
"bmp", "gif", "jpg", "jpeg", "pcx", "png", "psd", "ras", "tga", "tiff" };
- for (int i=0, n=sizeof(pic_types)/sizeof(pic_types[0]); i<n; ++i)
- suffixes[PICTURE] << QString::fromLatin1(pic_types[i]);
+ for (const char * t: pic_types)
+ suffixes[PICTURE] << QString::fromLatin1(t);
fileIcons[PICTURE] = QIcon::fromTheme (QString::fromLatin1("image-x-generic"), fallback);
const char * vid_types[] = {
"3gp", "asf", "avi", "mkv", "mov", "mpeg", "mpg", "mp4",
"ogm", "ogv", "qt", "rm", "wmv" };
- for (int i=0, n=sizeof(vid_types)/sizeof(vid_types[0]); i<n; ++i)
- suffixes[VIDEO] << QString::fromLatin1(vid_types[i]);
+ for (const char * t: vid_types)
+ suffixes[VIDEO] << QString::fromLatin1(t);
fileIcons[VIDEO] = QIcon::fromTheme (QString::fromLatin1("video-x-generic"), fallback);
const char * arc_types[] = {
"7z", "ace", "bz2", "cbz", "gz", "gzip", "lzma", "rar", "sft", "tar", "zip" };
- for (int i=0, n=sizeof(arc_types)/sizeof(arc_types[0]); i<n; ++i)
- suffixes[ARCHIVE] << QString::fromLatin1(arc_types[i]);
+ for (const char * t: arc_types)
+ suffixes[ARCHIVE] << QString::fromLatin1(t);
fileIcons[ARCHIVE] = QIcon::fromTheme (QString::fromLatin1("package-x-generic"), fallback);
const char * aud_types[] = {
"aac", "ac3", "aiff", "ape", "au", "flac", "m3u", "m4a", "mid", "midi", "mp2",
"mp3", "mpc", "nsf", "oga", "ogg", "ra", "ram", "shn", "voc", "wav", "wma" };
- for (int i=0, n=sizeof(aud_types)/sizeof(aud_types[0]); i<n; ++i)
- suffixes[AUDIO] << QString::fromLatin1(aud_types[i]);
+ for (const char * t: aud_types)
+ suffixes[AUDIO] << QString::fromLatin1(t);
fileIcons[AUDIO] = QIcon::fromTheme (QString::fromLatin1("audio-x-generic"), fallback);
const char * exe_types[] = { "bat", "cmd", "com", "exe" };
- for (int i=0, n=sizeof(exe_types)/sizeof(exe_types[0]); i<n; ++i)
- suffixes[APP] << QString::fromLatin1(exe_types[i]);
+ for (const char * t: exe_types)
+ suffixes[APP] << QString::fromLatin1(t);
fileIcons[APP] = QIcon::fromTheme (QString::fromLatin1("application-x-executable"), fallback);
}
{
if (s.length() != 40)
return false;
- foreach (QChar ch, s) if (!isxdigit (ch.unicode())) return false;
+ for (const QChar ch: s) if (!isxdigit (ch.unicode())) return false;
return true;
}
// get the list of files currently in the watch directory
QSet<QString> files;
- foreach (QString str, dir.entryList (QDir::Readable|QDir::Files))
+ for (const QString& str: dir.entryList (QDir::Readable|QDir::Files))
files.insert (str);
// try to add any new files which end in .torrent
const QSet<QString> newFiles (files - myWatchDirFiles);
const QString torrentSuffix = QString::fromUtf8 (".torrent");
- foreach (QString name, newFiles)
+ for (const QString& name: newFiles)
{
if (name.endsWith (torrentSuffix, Qt::CaseInsensitive))
{
if (myWatcher == nullptr)
return;
- foreach (const QString& path, myWatcher->directories ())
+ for (const QString& path: myWatcher->directories ())
watcherActivated (path);
}