void TorrentModel::populate() { // Load the torrents std::vector<Transfer> torrents = Session::instance()->getTransfers(); std::vector<Transfer>::const_iterator it; for (it = torrents.begin(); it != torrents.end(); it++) { addTorrent(*it); } // Refresh timer connect(&m_refreshTimer, SIGNAL(timeout()), SLOT(forceModelRefresh())); m_refreshTimer.start(m_refreshInterval); // Listen for torrent changes connect(Session::instance(), SIGNAL(addedTransfer(Transfer)), SLOT(addTorrent(Transfer))); connect(Session::instance(), SIGNAL(transferAboutToBeRemoved(Transfer, bool)), SLOT(handleTorrentAboutToBeRemoved(Transfer, bool))); connect(Session::instance(), SIGNAL(deletedTransfer(QString)), SLOT(removeTorrent(QString))); connect(Session::instance(), SIGNAL(finishedTransfer(Transfer)), SLOT(handleTorrentUpdate(Transfer))); connect(Session::instance(), SIGNAL(metadataReceived(Transfer)), SLOT(handleTorrentUpdate(Transfer))); connect(Session::instance(), SIGNAL(resumedTransfer(Transfer)), SLOT(handleTorrentUpdate(Transfer))); connect(Session::instance(), SIGNAL(pausedTransfer(Transfer)), SLOT(handleTorrentUpdate(Transfer))); connect(Session::instance(), SIGNAL(transferFinishedChecking(Transfer)), SLOT(handleTorrentUpdate(Transfer))); }
void SeedManager::findTorrents() { QDir dir(settingsPath); QFileInfoList list = dir.entryInfoList(); for (int i = 0; i < list.size(); i++) if (!s.contains(list[i].fileName())) if (list[i].fileName().right(16) == QString(".qlivebittorrent")) { qDebug() << "loading" << list[i].fileName(); addTorrent(list[i].fileName()); s.insert(list[i].fileName()); } }
MainWindow::MainWindow(QString torrent, QString downloadPath, QString mountPath, QString rate, bool gui, QObject *parent): QObject(parent) { initSession(rate); initscr(); nodelay(stdscr, true); noecho(); main = NULL; if (!gui) realAddTorrent(torrent, downloadPath, mountPath); else { fake = new QMainWindow; if (QFile(torrent).exists() || isMagnet(torrent)) findPaths(torrent); else addTorrent(); } }
void TorrentModel::populate() { // Load the torrents foreach (BitTorrent::TorrentHandle *const torrent, BitTorrent::Session::instance()->torrents()) addTorrent(torrent); // Listen for torrent changes connect(BitTorrent::Session::instance(), SIGNAL(torrentAdded(BitTorrent::TorrentHandle *const)), SLOT(addTorrent(BitTorrent::TorrentHandle *const))); connect(BitTorrent::Session::instance(), SIGNAL(torrentAboutToBeRemoved(BitTorrent::TorrentHandle *const)), SLOT(handleTorrentAboutToBeRemoved(BitTorrent::TorrentHandle *const))); connect(BitTorrent::Session::instance(), SIGNAL(torrentStatusUpdated(BitTorrent::TorrentHandle *const)), this, SLOT(handleTorrentStatusUpdated(BitTorrent::TorrentHandle *const))); connect(BitTorrent::Session::instance(), SIGNAL(torrentFinished(BitTorrent::TorrentHandle *const)), SLOT(handleTorrentStatusUpdated(BitTorrent::TorrentHandle *const))); connect(BitTorrent::Session::instance(), SIGNAL(torrentMetadataLoaded(BitTorrent::TorrentHandle *const)), SLOT(handleTorrentStatusUpdated(BitTorrent::TorrentHandle *const))); connect(BitTorrent::Session::instance(), SIGNAL(torrentResumed(BitTorrent::TorrentHandle *const)), SLOT(handleTorrentStatusUpdated(BitTorrent::TorrentHandle *const))); connect(BitTorrent::Session::instance(), SIGNAL(torrentPaused(BitTorrent::TorrentHandle *const)), SLOT(handleTorrentStatusUpdated(BitTorrent::TorrentHandle *const))); connect(BitTorrent::Session::instance(), SIGNAL(torrentFinishedChecking(BitTorrent::TorrentHandle *const)), SLOT(handleTorrentStatusUpdated(BitTorrent::TorrentHandle *const))); }
void TorrentModel::processPendingTransfers() { for(QList<Transfer>::iterator i = m_pendingTransfers.begin(); i != m_pendingTransfers.end();) { TransferState state = i->state(); if (state != qt_checking_resume_data) { // now we know whether transfer finished or not // do not show finished transfers if (state != qt_seeding) addTorrent(*i); i = m_pendingTransfers.erase(i); } else ++i; } }
bool SQLite3Driver::updatePeer(uint8_t peer_id[20], uint8_t info_hash[20], uint32_t ip, uint16_t port, int64_t downloaded, int64_t left, int64_t uploaded, enum TrackerEvents event) { char xHash [50]; // we just need 40 + \0 = 41. sqlite3_stmt *stmt; string sql; int r; char *hash = xHash; to_hex_str(info_hash, hash); addTorrent (info_hash); sql = "REPLACE INTO 't"; sql += hash; sql += "' (peer_id,ip,port,uploaded,downloaded,left,last_seen) VALUES (?,?,?,?,?,?,?)"; // printf("IP->%x::%u\n", pE->ip, pE->port); sqlite3_prepare(this->db, sql.c_str(), sql.length(), &stmt, NULL); sqlite3_bind_blob(stmt, 1, (void*)peer_id, 20, NULL); sqlite3_bind_blob(stmt, 2, (void*)&ip, 4, NULL); sqlite3_bind_blob(stmt, 3, (void*)&port, 2, NULL); sqlite3_bind_blob(stmt, 4, (void*)&uploaded, 8, NULL); sqlite3_bind_blob(stmt, 5, (void*)&downloaded, 8, NULL); sqlite3_bind_blob(stmt, 6, (void*)&left, 8, NULL); sqlite3_bind_int(stmt, 7, time(NULL)); r = sqlite3_step(stmt); sqlite3_finalize(stmt); sql = "REPLACE INTO stats (info_hash,last_mod) VALUES (?,?)"; sqlite3_prepare (this->db, sql.c_str(), sql.length(), &stmt, NULL); sqlite3_bind_blob (stmt, 1, hash, 20, NULL); sqlite3_bind_int (stmt, 2, time(NULL)); sqlite3_step (stmt); sqlite3_finalize (stmt); return r; }