]> granicus.if.org Git - transmission/commitdiff
Use C++11 range-based `for` loops (Qt client)
authorMike Gelfand <mikedld@mikedld.com>
Sat, 18 Apr 2015 14:41:06 +0000 (14:41 +0000)
committerMike Gelfand <mikedld@mikedld.com>
Sat, 18 Apr 2015 14:41:06 +0000 (14:41 +0000)
21 files changed:
qt/app.cc
qt/column-resizer.cc
qt/details.cc
qt/favicon.cc
qt/file-tree.cc
qt/filterbar.cc
qt/mainwin.cc
qt/make-dialog.cc
qt/options.cc
qt/prefs-dialog.cc
qt/relocate.cc
qt/rpc-client.cc
qt/session-dialog.cc
qt/session.cc
qt/torrent-filter.cc
qt/torrent-model.cc
qt/torrent.cc
qt/tracker-model.cc
qt/utils.cc
qt/utils.h
qt/watchdir.cc

index 405d2bb689959dd0d5c30845de0dd03b49894a73..7372aa60dd9e8bb956ac6ab9ef1ef75413f648ce 100644 (file)
--- a/qt/app.cc
+++ b/qt/app.cc
@@ -77,7 +77,7 @@ namespace
                    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;
@@ -134,7 +134,7 @@ MyApp::MyApp (int& argc, char ** argv):
     {
       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);
@@ -180,14 +180,14 @@ MyApp::MyApp (int& argc, char ** argv):
   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;
@@ -267,7 +267,7 @@ MyApp::MyApp (int& argc, char ** argv):
   // 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)));
 
@@ -318,8 +318,8 @@ MyApp::MyApp (int& argc, char ** argv):
       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 ())
@@ -346,7 +346,7 @@ MyApp::onTorrentsAdded (const QSet<int>& torrents)
   if (!myPrefs->getBool (Prefs::SHOW_NOTIFICATION_ON_ADD))
     return;
 
-  foreach (int id, torrents)
+  for (const int id: torrents)
     {
       Torrent * tor = myModel->getTorrentFromId (id);
 
index b227a4b8b2ce807c85232246befb03ed3fcc7b10..0661615e5758cba49d7e58926d9810746ca8b3db 100644 (file)
@@ -16,7 +16,7 @@
 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)
       {
@@ -60,7 +60,7 @@ void
 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)
         {
@@ -71,7 +71,7 @@ ColumnResizer::update ()
         }
     }
 
-  foreach (QGridLayout * layout, myLayouts)
+  for (QGridLayout * const layout: myLayouts)
     layout->setColumnMinimumWidth (0, maxWidth);
 }
 
index 979df6f41b850a24235249f17ed4d41829695e54..cd30f2ee4b7b81da33fbecfeb73645fa6c5337f0 100644 (file)
@@ -198,7 +198,7 @@ Details::Details (Session       & session,
   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 ()));
@@ -225,7 +225,7 @@ Details::setIds (const QSet<int>& ids)
   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)
@@ -237,7 +237,7 @@ Details::setIds (const QSet<int>& ids)
   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)
@@ -305,7 +305,7 @@ Details::getNewData ()
   if (!myIds.empty ())
     {
       QSet<int> infos;
-      foreach (int id, myIds)
+      for (const int id: myIds)
         {
           const Torrent * tor = myModel.getTorrentFromId (id);
           if (tor->isMagnet ())
@@ -375,7 +375,7 @@ Details::refresh ()
   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)
@@ -397,7 +397,7 @@ Details::refresh ()
       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)
@@ -435,7 +435,7 @@ Details::refresh ()
       int64_t haveUnverified = 0;
       int64_t verifiedPieces = 0;
 
-      foreach (const Torrent * t, torrents)
+      for (const Torrent * const t: torrents)
         {
           if (t->hasMetadata ())
             {
@@ -506,7 +506,7 @@ Details::refresh ()
     {
       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 ();
@@ -529,7 +529,7 @@ Details::refresh ()
     {
       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 ();
@@ -551,7 +551,7 @@ Details::refresh ()
     {
       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 ();
@@ -578,7 +578,7 @@ Details::refresh ()
   else
     {
       int baseline = torrents[0]->getETA ();
-      foreach (const Torrent * t, torrents)
+      for (const Torrent * const t: torrents)
         {
           if (baseline != t->getETA ())
             {
@@ -606,7 +606,7 @@ Details::refresh ()
   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)
@@ -631,7 +631,7 @@ Details::refresh ()
   else
     {
       string = torrents[0]->getError ();
-      foreach (const Torrent * t, torrents)
+      for (const Torrent * const t: torrents)
         {
           if (string != t->getError ())
             {
@@ -659,7 +659,7 @@ Details::refresh ()
       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 ();
@@ -684,7 +684,7 @@ Details::refresh ()
   if (!torrents.empty ())
     {
       string = torrents[0]->hashString ();
-      foreach (const Torrent * t, torrents)
+      for (const Torrent * const t: torrents)
         {
           if (string != t->hashString ())
             {
@@ -702,7 +702,7 @@ Details::refresh ()
       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 ())
             {
@@ -719,7 +719,7 @@ Details::refresh ()
   if (!torrents.empty ())
     {
       string = torrents[0]->comment ();
-      foreach (const Torrent * t, torrents)
+      for (const Torrent * const t: torrents)
         {
           if (string != t->comment ())
             {
@@ -742,7 +742,7 @@ Details::refresh ()
       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 ());
@@ -766,7 +766,7 @@ Details::refresh ()
   if (!torrents.empty ())
     {
       string = torrents[0]->getPath ();
-      foreach (const Torrent * t, torrents)
+      for (const Torrent * const t: torrents)
         {
           if (string != t->getPath ())
             {
@@ -788,65 +788,64 @@ Details::refresh ()
       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 ();
     }
 
@@ -862,12 +861,12 @@ Details::refresh ()
 
   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));
@@ -892,7 +891,7 @@ Details::refresh ()
           item->refresh (peer);
 
           QString codeTip;
-          foreach (QChar ch, code)
+          for (const QChar ch: code)
             {
               QString txt;
               switch (ch.unicode ())
@@ -929,7 +928,7 @@ Details::refresh ()
     }
 
   ui.peersView->addTopLevelItems (newItems);
-  foreach (QString key, myPeers.keys ())
+  for (const QString& key: myPeers.keys ())
     {
       if (!peers2.contains (key)) // old peer has disconnected
         {
@@ -1078,7 +1077,7 @@ Details::onAddTrackerClicked ()
     {
       QSet<int> ids;
 
-      foreach (int id, myIds)
+      for (const int id: myIds)
         if (myTrackerModel->find (id,url) == -1)
           ids.insert (id);
 
@@ -1139,14 +1138,14 @@ Details::onRemoveTrackerClicked ()
   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;
@@ -1315,7 +1314,7 @@ Details::onOpenRequested (const QString& path)
   if (!mySession.isLocal ())
     return;
 
-  foreach (const int id, myIds)
+  for (const int id: myIds)
     {
       const Torrent * const tor = myModel.getTorrentFromId (id);
       if (tor == NULL)
index ff4fbc79c5f5661597a6e3ea45e845a1b815a60e..30a3771b21388727c8fc6dfa26667095b13336c8 100644 (file)
@@ -65,7 +65,7 @@ Favicons::ensureCacheDirHasBeenScanned ()
       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));
@@ -126,7 +126,7 @@ Favicons::add (const QUrl& url)
       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));
     }
 }
index 49d934e872dd9f609860f6685bd3cd68aed13090..74d93ccfe2aa9ad946faf423d7198f4425f64ada 100644 (file)
@@ -175,7 +175,7 @@ FileTreeItem::getSubtreeWantedSize (uint64_t& have, uint64_t& total) const
       total += myTotalSize;
     }
 
-  foreach(const FileTreeItem * i, myChildren)
+  for (const FileTreeItem * const i: myChildren)
     i->getSubtreeWantedSize(have, total);
 }
 
@@ -302,7 +302,7 @@ FileTreeItem::priority () const
         }
     }
 
-  foreach (const FileTreeItem * child, myChildren)
+  for (const FileTreeItem * const child: myChildren)
     i |= child->priority();
 
   return i;
@@ -319,7 +319,7 @@ FileTreeItem::setSubtreePriority (int i, QSet<int>& ids)
         ids.insert (myFileIndex);
     }
 
-  foreach (FileTreeItem * child, myChildren)
+  for (FileTreeItem * const child: myChildren)
     child->setSubtreePriority (i, ids);
 }
 
@@ -345,7 +345,7 @@ FileTreeItem::isSubtreeWanted () const
     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();
 
@@ -373,7 +373,7 @@ FileTreeItem::setSubtreeWanted (bool b, QSet<int>& ids)
         ids.insert(myFileIndex);
     }
 
-  foreach (FileTreeItem * child, myChildren)
+  for (FileTreeItem * const child: myChildren)
     child->setSubtreeWanted (b, ids);
 }
 
@@ -985,13 +985,13 @@ FileTreeView::eventFilter (QObject * o, QEvent * event)
       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;
         }
@@ -1003,11 +1003,11 @@ FileTreeView::eventFilter (QObject * o, QEvent * event)
 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));
     }
 }
index 7f8139d0b97a2cf3584ae5018966223753042615..b73b258287d3dd7e1c2dc26a56c3f1c5b81bd296 100644 (file)
@@ -442,12 +442,12 @@ FilterBar::refreshTrackers ()
         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];
     }
 
@@ -456,7 +456,7 @@ FilterBar::refreshTrackers ()
   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 ();
@@ -467,7 +467,7 @@ FilterBar::refreshTrackers ()
     }
 
   // 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 ();
@@ -477,7 +477,7 @@ FilterBar::refreshTrackers ()
 
   // rows to add
   bool anyAdded = false;
-  foreach (QString host, newHosts - oldHosts)
+  for (const QString& host: newHosts - oldHosts)
     {
       const QString name = readableHostName (host);
 
@@ -583,7 +583,7 @@ FilterBar::FilterBar (Prefs& prefs, const TorrentModel& torrents, const TorrentF
   QList<int> initKeys;
   initKeys << Prefs::FILTER_MODE
            << Prefs::FILTER_TRACKERS;
-  foreach (int key, initKeys)
+  for (const int key: initKeys)
       refreshPref (key);
 }
 
index dff87748d5d1d6c1b0d410b5664d31a8bb802d78..1ee503c2e504a585b9728c6511e05899a2db35bd 100644 (file)
@@ -260,7 +260,7 @@ TrMainWindow::TrMainWindow (Session& session, Prefs& prefs, TorrentModel& model,
            << 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 ()));
@@ -381,7 +381,7 @@ TrMainWindow::createOptionsMenu ()
     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);
@@ -403,7 +403,7 @@ TrMainWindow::createOptionsMenu ()
     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);
@@ -426,7 +426,7 @@ TrMainWindow::createOptionsMenu ()
     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);
@@ -811,7 +811,7 @@ TrMainWindow::getSelectedTorrents () const
 {
   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 ());
@@ -1164,7 +1164,7 @@ TrMainWindow::addTorrents (const QStringList& filenames)
         showOptions = b->isChecked ();
     }
 
-  foreach (const QString& filename, filenames)
+  for (const QString& filename: filenames)
     addTorrent (filename, showOptions);
 }
 
@@ -1194,7 +1194,7 @@ TrMainWindow::removeTorrents (const bool deleteFiles)
   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 ());
@@ -1408,11 +1408,11 @@ TrMainWindow::dropEvent (QDropEvent * event)
     }
   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();
 
index 22f766c7c82e229bf61f65ea0f15227ced108f60..ca3765614ad1fd19ead3f27c0404e17646e73bac 100644 (file)
@@ -132,17 +132,17 @@ MakeDialog::makeTorrent ()
   // 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);
         }
index 314b9a57efaedf25edda8cfb6efd77cf1318435a..619c057abb182cdbbbde14bec2f8b2e60d1a0534 100644 (file)
@@ -214,14 +214,14 @@ OptionsDialog::reload ()
 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;
 }
 
@@ -334,8 +334,8 @@ OptionsDialog::clearVerify ()
   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);
 }
@@ -432,7 +432,7 @@ OptionsDialog::onTimeout ()
   if (done)
     {
       uint64_t have = 0;
-      foreach (const TrFile& f, myFiles)
+      for (const TrFile& f: myFiles)
         have += f.have;
 
       if (!have) // everything failed
index 9c5baee0f33c515616a560d7ffd71c3bac9d1220..2a7f3f1227d46e736238ed406e077081d6014f28 100644 (file)
@@ -560,14 +560,14 @@ PrefsDialog::PrefsDialog (Session& session, Prefs& prefs, QWidget * parent):
        << 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);
@@ -617,11 +617,11 @@ PrefsDialog::refreshPref (int key)
           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;
         }
@@ -629,7 +629,7 @@ PrefsDialog::refreshPref (int key)
       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;
         }
@@ -637,7 +637,7 @@ PrefsDialog::refreshPref (int key)
       case Prefs::BLOCKLIST_ENABLED:
         {
           const bool enabled = myPrefs.getBool (key);
-          foreach (QWidget * w, myBlockWidgets)
+          for (QWidget * const w: myBlockWidgets)
             w->setEnabled (enabled);
           break;
         }
index fd5ab75d74ec9a9544163987e7ff49564cb56c85..c91d8e39a4da39174faecba4e8d84282888b69cc 100644 (file)
@@ -40,7 +40,7 @@ RelocateDialog::RelocateDialog (Session            & session,
   ui.setupUi (this);
 
   QString path;
-  foreach (int id, myIds)
+  for (const int id: myIds)
     {
       const Torrent * tor = model.getTorrentFromId (id);
 
index c28800e1a6304f59cc094a071d524d2636938beb..180078843e78945c4afdc56b511edbf879e8570c 100644 (file)
@@ -137,7 +137,7 @@ RpcClient::sendRequest (const QByteArray& json)
 
 #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 ()
@@ -182,7 +182,7 @@ RpcClient::onFinished (QNetworkReply * reply)
 {
 #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 ()
index 214fe9621a3f2847c1162ef6ae7a46702ccd05ce..308d738c7a46de22de86a46f135d117f4eca5523 100644 (file)
@@ -34,10 +34,10 @@ SessionDialog::resensitize ()
   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);
 }
 
index 863a141f87c68a583b87c470aec641b593270cd7..440c89e9e1526ef2f7910c3809d2b21764f7a3f7 100644 (file)
@@ -66,7 +66,7 @@ namespace
   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);
   }
 }
@@ -390,7 +390,7 @@ namespace
     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);
       }
   }
@@ -436,7 +436,7 @@ Session::torrentSet (const QSet<int>& ids, const tr_quark key, const QStringList
   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);
@@ -449,7 +449,7 @@ Session::torrentSet (const QSet<int>& ids, const tr_quark key, const QList<int>&
   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);
index 1d4ce8854f61ec9cf96f53c143f0305aaf352749..6d50fc74d3182a79348e1d51ea730e790b5f5ee3 100644 (file)
@@ -32,7 +32,7 @@ TorrentFilter::TorrentFilter (const Prefs& prefs):
            << Prefs::FILTER_MODE
            << Prefs::FILTER_TRACKERS
            << Prefs::FILTER_TEXT;
-  foreach (int key, initKeys)
+  for (const int key: initKeys)
     refreshPref (key);
 }
 
index cff5be0864cd517a6e190a8ab2426d1f9bbf22b1..1f5f9a9310e641d7a3dfa20e7b47b49da2fc2e6f 100644 (file)
@@ -23,7 +23,7 @@ TorrentModel::clear ()
 
   myIdToRow.clear ();
   myIdToTorrent.clear ();
-  foreach (Torrent * tor, myTorrents) delete tor;
+  qDeleteAll (myTorrents);
   myTorrents.clear ();
 
   endResetModel ();
@@ -189,7 +189,7 @@ TorrentModel::updateTorrents (tr_variant * torrents, bool isCompleteList)
 
       beginInsertRows (QModelIndex(), oldCount, newCount - 1);
 
-      foreach (Torrent * tor, newTorrents)
+      for (Torrent * const tor: newTorrents)
         {
           addTorrent (tor);
           addIds.insert (tor->id ());
@@ -205,7 +205,7 @@ TorrentModel::updateTorrents (tr_variant * torrents, bool isCompleteList)
     {
       QSet<int> removedIds (oldIds);
       removedIds -= newIds;
-      foreach (int id, removedIds)
+      for (const int id: removedIds)
         removeTorrent (id);
     }
 }
@@ -220,7 +220,7 @@ TorrentModel::removeTorrent (int 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);
@@ -241,7 +241,7 @@ TorrentModel::getTransferSpeed (Speed   & uploadSpeed,
   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 ();
@@ -262,7 +262,7 @@ TorrentModel::getIds () const
   QSet<int> ids;
 
   ids.reserve (myTorrents.size());
-  foreach (const Torrent * tor, myTorrents)
+  for (const Torrent * const tor: myTorrents)
     ids.insert (tor->id());
 
   return ids;
@@ -271,7 +271,7 @@ TorrentModel::getIds () const
 bool
 TorrentModel::hasTorrent (const QString& hashString) const
 {
-  foreach (const Torrent * tor, myTorrents)
+  for (const Torrent * const tor: myTorrents)
     if (tor->hashString () == hashString)
       return true;
 
index 630f87f3f6cad7b8b9f5ae136fb368c7a9b473f6..bc3463c6956eebdef1b5d7fef39742c55d47c94e 100644 (file)
@@ -357,7 +357,7 @@ Torrent::getSeedRatio (double& ratio) const
 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;
 
@@ -367,7 +367,7 @@ Torrent::hasFileSubstring (const QString& substr) const
 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;
 
@@ -613,7 +613,7 @@ Torrent::update (tr_variant * d)
       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())
index e1b8738d15e5519a57ae6cb6ccb8bfb798cf11c4..95d5b7fcdaf9426925dfaeb11735b5f4a40a370f 100644 (file)
@@ -81,13 +81,13 @@ TrackerModel::refresh (const TorrentModel& torrentModel, const QSet<int>& ids)
 {
   // 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;
index 66c0b170a1b07e8d2416615d81ac64bd2bc69248..99c1569881ece155ab533253590397f7cd84af50 100644 (file)
@@ -125,39 +125,39 @@ Utils::guessMimeIcon (const QString& filename)
       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);
     }
 
index 2ead0e6416809c0d767c165770340dbf43451f1e..0b64a354919509d3caa8f4dfec7bc4264a2e8c7e 100644 (file)
@@ -54,7 +54,7 @@ class Utils: public QObject
     {
       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;
     }
 
index cf65157636c25512fdc2c9e928b628ea7333088a..9da7d9ceeade9448e8d267f5f4314fa84823da2e 100644 (file)
@@ -103,13 +103,13 @@ WatchDir::watcherActivated (const QString& path)
 
   // 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))
         {
@@ -147,6 +147,6 @@ WatchDir::rescanAllWatchedDirectories ()
   if (myWatcher == nullptr)
     return;
 
-  foreach (const QString& path, myWatcher->directories ())
+  for (const QString& path: myWatcher->directories ())
     watcherActivated (path);
 }