Ejemplo n.º 1
0
void TransferListWidget::torrentDoubleClicked(const QModelIndex& index) {
  const int row = mapToSource(index).row();
  const QString hash = getHashFromRow(row);
  QTorrentHandle h = BTSession->getTorrentHandle(hash);
  if (!h.is_valid()) return;
  int action;
  if (h.is_seed()) {
    action = Preferences().getActionOnDblClOnTorrentFn();
  } else {
    action = Preferences().getActionOnDblClOnTorrentDl();
  }

  switch(action) {
  case TOGGLE_PAUSE:
    if (h.is_paused()) {
      h.resume();
    } else {
      h.pause();
    }
    break;
  case OPEN_DEST:
    const QString path = h.root_path();
    openUrl(path);
  }
}
Ejemplo n.º 2
0
void TorrentPersistentData::saveTorrentPersistentData(const QTorrentHandle &h, const QString &save_path, const bool is_magnet) {
  Q_ASSERT(h.is_valid());
  qDebug("Saving persistent data for %s", qPrintable(h.hash()));
  // Save persistent data
  QHash<QString, QVariant> data = all_data.value(h.hash()).toHash();
  data["is_magnet"] = is_magnet;
  if (is_magnet) {
    data["magnet_uri"] = misc::toQString(make_magnet_uri(h));
  }
  data["seed"] = h.is_seed();
  data["priority"] = h.queue_position();
  if (save_path.isEmpty()) {
    qDebug("TorrentPersistantData: save path is %s", qPrintable(h.save_path()));
    data["save_path"] = h.save_path();
  } else {
    qDebug("TorrentPersistantData: overriding save path is %s", qPrintable(save_path));
    data["save_path"] = save_path; // Override torrent save path (e.g. because it is a temp dir)
  }
  // Label
  data["label"] = TorrentTempData::getLabel(h.hash());
  // Save data
  all_data[h.hash()] = data;
  markDirty();
  qDebug("TorrentPersistentData: Saving save_path %s, hash: %s", qPrintable(h.save_path()), qPrintable(h.hash()));
  // Set Added date
  setAddedDate(h.hash(), QDateTime::currentDateTime());
  // Finally, remove temp data
  TorrentTempData::deleteTempData(h.hash());
}
Ejemplo n.º 3
0
void HttpServer::onTimer() {
  std::vector<torrent_handle> torrents = QBtSession::instance()->getTorrents();
  std::vector<torrent_handle>::iterator torrentIT;
  for (torrentIT = torrents.begin(); torrentIT != torrents.end(); torrentIT++) {
    QTorrentHandle h = QTorrentHandle(*torrentIT);
    if (h.is_valid())
      m_eventManager->modifiedTorrent(h);
  }
}
Ejemplo n.º 4
0
QByteArray btjson::getTorrentsRatesLimits(QStringList &hashes, bool downloadLimits)
{
    QVariantMap map;

    foreach (const QString &hash, hashes) {
        int limit = -1;
        QTorrentHandle h = QBtSession::instance()->getTorrentHandle(hash);
        if (h.is_valid())
            limit = downloadLimits ? h.download_limit() : h.upload_limit();
        map[hash] = limit;
    }
Ejemplo n.º 5
0
void PeerListWidget::showPeerListMenu(const QPoint&)
{
  QMenu menu;
  bool empty_menu = true;
  QTorrentHandle h = m_properties->getCurrentTorrent();
  if (!h.is_valid()) return;
  QModelIndexList selectedIndexes = selectionModel()->selectedRows();
  QStringList selectedPeerIPs;
  foreach (const QModelIndex &index, selectedIndexes) {
    int row = m_proxyModel->mapToSource(index).row();
    QString myip = m_listModel->data(m_listModel->index(row, PeerListDelegate::IP_HIDDEN)).toString();
    selectedPeerIPs << myip;
  }
Ejemplo n.º 6
0
void TrackerList::moveSelectionUp() {
  QTorrentHandle h = properties->getCurrentTorrent();
  if (!h.is_valid()) {
    clear();
    return;
  }
  QList<QTreeWidgetItem *> selected_items = getSelectedTrackerItems();
  if (selected_items.isEmpty()) return;
  bool change = false;
  foreach (QTreeWidgetItem *item, selected_items) {
    int index = indexOfTopLevelItem(item);
    if (index > NB_STICKY_ITEM) {
      insertTopLevelItem(index-1, takeTopLevelItem(index));
      change = true;
    }
  }
Ejemplo n.º 7
0
/**
 * Returns the web seeds for a torrent in JSON format.
 *
 * The return value is a JSON-formatted list of dictionaries.
 * The dictionary keys are:
 *   - "url": Web seed URL
 */
QByteArray btjson::getWebSeedsForTorrent(const QString& hash)
{
    CACHED_VARIABLE_FOR_HASH(QVariantList, webSeedList, CACHE_DURATION_MS, hash);
    QTorrentHandle torrent = QBtSession::instance()->getTorrentHandle(hash);
    if (!torrent.is_valid()) {
        qWarning() << Q_FUNC_INFO << "Invalid torrent " << qPrintable(hash);
        return QByteArray();
    }

    foreach (const QString &webseed, torrent.url_seeds()) {
        QVariantMap webSeedDict;
        webSeedDict[KEY_WEBSEED_URL] = webseed;
        webSeedList.append(webSeedDict);
    }

    return json::toJson(webSeedList);
}
Ejemplo n.º 8
0
HttpServer::HttpServer(int msec, QObject* parent) : QTcpServer(parent),
  m_eventManager(new EventManager(this)) {

  const Preferences pref;

  m_username = pref.getWebUiUsername().toLocal8Bit();
  m_passwordSha1 = pref.getWebUiPassword().toLocal8Bit();
  m_localAuthEnabled = pref.isWebUiLocalAuthEnabled();
  m_needsTranslation = !Preferences().getLocale().startsWith("en");
  connect(m_eventManager, SIGNAL(localeChanged(QString)), SLOT(onLocaleChanged(QString)));

  // HTTPS-related
#ifndef QT_NO_OPENSSL
  m_https = pref.isWebUiHttpsEnabled();
  if (m_https) {
    m_certificate = QSslCertificate(pref.getWebUiHttpsCertificate());
    m_key = QSslKey(pref.getWebUiHttpsKey(), QSsl::Rsa);
  }
#endif

  // Add torrents
  std::vector<torrent_handle> torrents = QBtSession::instance()->getTorrents();
  std::vector<torrent_handle>::iterator torrentIT;
  for (torrentIT = torrents.begin(); torrentIT != torrents.end(); torrentIT++) {
    QTorrentHandle h = QTorrentHandle(*torrentIT);
    if (h.is_valid())
      m_eventManager->addedTorrent(h);
  }

  //connect QBtSession::instance() to manager
  connect(QBtSession::instance(), SIGNAL(addedTorrent(QTorrentHandle)), m_eventManager, SLOT(addedTorrent(QTorrentHandle)));
  connect(QBtSession::instance(), SIGNAL(deletedTorrent(QString)), m_eventManager, SLOT(deletedTorrent(QString)));

  //set timer
  connect(&m_timer, SIGNAL(timeout()), SLOT(onTimer()));
  m_timer.start(msec);

  // Additional translations for Web UI
  QString a = tr("File");
  a = tr("Edit");
  a = tr("Help");
  a = tr("Download Torrents from their URL or Magnet link");
  a = tr("Only one link per line");
  a = tr("Download local torrent");
  a = tr("Torrent files were correctly added to download list.");
  a = tr("Point to torrent file");
  a = tr("Download");
  a = tr("Are you sure you want to delete the selected torrents from the transfer list and hard disk?");
  a = tr("Download rate limit must be greater than 0 or disabled.");
  a = tr("Upload rate limit must be greater than 0 or disabled.");
  a = tr("Maximum number of connections limit must be greater than 0 or disabled.");
  a = tr("Maximum number of connections per torrent limit must be greater than 0 or disabled.");
  a = tr("Maximum number of upload slots per torrent limit must be greater than 0 or disabled.");
  a = tr("Unable to save program preferences, qBittorrent is probably unreachable.");
  a = tr("Language");
  a = tr("Downloaded", "Is the file downloaded or not?");
  a = tr("The port used for incoming connections must be greater than 1024 and less than 65535.");
  a = tr("The port used for the Web UI must be greater than 1024 and less than 65535.");
  a = tr("The Web UI username must be at least 3 characters long.");
  a = tr("The Web UI password must be at least 3 characters long.");
  a = tr("Save");
  a = tr("qBittorrent client is not reachable");
  a = tr("HTTP Server");
  a = tr("The following parameters are supported:");
  a = tr("Torrent path");
  a = tr("Torrent name");
}