Opened 6 years ago

Last modified 6 years ago

#5932 new Enhancement

Add multiple trackers at once

Reported by: fulalas Owned by: jordan
Priority: Normal Milestone: None Set
Component: Qt Client Version: 2.84
Severity: Normal Keywords:
Cc:

Description

Considering uTorrent pattern (i.e. one URL per line; although we can further improve by considering space as a separator too), like this: https://torrentz.eu/announcelist_95514573

Class 'details.cc'.

Code highlighting:

void
Details :: onAddTrackerClicked ()
{
  bool ok = false;
  const QString url = QInputDialog::getText (this,
                                             tr ("Add URL "),
                                             tr ("Add tracker announce URL:"),
                                             QLineEdit::Normal, QString (), &ok);

  if (!ok)
    {
      // user pressed "cancel" -- noop
      return;
    }

    if(url.trimmed().isEmpty())
    {
        QMessageBox::information (this, tr ("Empty tracker"), tr ("The tracker can't be empty."));
        return;
    }

    bool invalidTrackerFound = false;
    QStringList urlList;
    if(url.contains("\n"))
    {
        while(url.contains("\n\n"))
            url.replace("\n\n", "\n");

        urlList = url.split("\n", QString::SkipEmptyParts);
        urlList.removeDuplicates();
    }
    else
        urlList.append(url);

  foreach(QString currentUrl, urlList)
  {
      if (!QUrl (currentUrl).isValid ())
      {
          invalidTrackerFound = true;
          continue;
      }

      QSet<int> ids;

      foreach (int id, myIds)
        if (myTrackerModel->find (id, currentUrl) == -1)
          ids.insert (id);

      if (ids.empty ()) // all the torrents already have this tracker
      {
          invalidTrackerFound = true;
          continue;
      }

      QStringList urls;
      urls << currentUrl;
      mySession.torrentSet (ids, TR_KEY_trackerAdd, urls);
      getNewData ();
  }

    if(invalidTrackerFound)
    {
        if(urlList.length() == 1 )
            QMessageBox::information (this, tr ("Invalid tracker"), tr ("The tracker already exists or is invalid."));
        else
            QMessageBox::information (this, tr ("Invalid trackers"), tr ("Not all trackers were added because some of them already exist or are invalid."));
    }
}

Change History (1)

comment:1 Changed 6 years ago by mike.dld

  • Component changed from Transmission to Qt Client
  • Owner set to jordan
Note: See TracTickets for help on using tickets.