Пример #1
0
	void TransferApi::loadTransfers() noexcept {
		// add the existing connections
		{
			auto cm = ConnectionManager::getInstance();
			RLock l(cm->getCS());
			for (const auto& d : cm->getTransferConnections(true)) {
				auto info = addTransfer(d, "Inactive, waiting for status updates");
				updateQueueInfo(info);
			}

			for (const auto& u : cm->getTransferConnections(false)) {
				addTransfer(u, "Inactive, waiting for status updates");
			}
		}

		{
			auto um = UploadManager::getInstance();
			RLock l(um->getCS());
			for (const auto& u : um->getUploads()) {
				if (u->getUserConnection().getState() == UserConnection::STATE_RUNNING) {
					on(UploadManagerListener::Starting(), u);
				}
			}
		}

		{
			auto dm = DownloadManager::getInstance();
			RLock l(dm->getCS());
			for (const auto& d : dm->getDownloads()) {
				if (d->getUserConnection().getState() == UserConnection::STATE_RUNNING) {
					starting(d, "Downloading", true);
				}
			}
		}
	}
Пример #2
0
int DroidStoreAPI::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QObject::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        if (_id < 34)
            qt_static_metacall(this, _c, _id, _a);
        _id -= 34;
    }
#ifndef QT_NO_PROPERTIES
      else if (_c == QMetaObject::ReadProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: *reinterpret_cast< QVariantList*>(_v) = getResults(); break;
        case 1: *reinterpret_cast< QVariantList*>(_v) = getTopApps(); break;
        case 2: *reinterpret_cast< QVariantList*>(_v) = getScreenshots(); break;
        case 3: *reinterpret_cast< QVariantList*>(_v) = getPopularAll(); break;
        case 4: *reinterpret_cast< QVariantList*>(_v) = getTrendingAll(); break;
        case 5: *reinterpret_cast< QVariantList*>(_v) = getPopularApps(); break;
        case 6: *reinterpret_cast< QVariantList*>(_v) = getTrendingApps(); break;
        case 7: *reinterpret_cast< QVariantList*>(_v) = getPopularGames(); break;
        case 8: *reinterpret_cast< QVariantList*>(_v) = getTrendingGames(); break;
        case 9: *reinterpret_cast< QVariantList*>(_v) = getDownloads(); break;
        case 10: *reinterpret_cast< bool*>(_v) = getLoading(); break;
        case 11: *reinterpret_cast< bb::cascades::ArrayDataModel**>(_v) = getResultsDataModel(); break;
        case 12: *reinterpret_cast< bb::cascades::ArrayDataModel**>(_v) = getTopAppsDataModel(); break;
        case 13: *reinterpret_cast< bb::cascades::ArrayDataModel**>(_v) = getScreenshotsDataModel(); break;
        case 14: *reinterpret_cast< bb::cascades::ArrayDataModel**>(_v) = getPopularAllDataModel(); break;
        case 15: *reinterpret_cast< bb::cascades::ArrayDataModel**>(_v) = getTrendingAllDataModel(); break;
        case 16: *reinterpret_cast< bb::cascades::ArrayDataModel**>(_v) = getPopularAppsDataModel(); break;
        case 17: *reinterpret_cast< bb::cascades::ArrayDataModel**>(_v) = getTrendingAppsDataModel(); break;
        case 18: *reinterpret_cast< bb::cascades::ArrayDataModel**>(_v) = getPopularGamesDataModel(); break;
        case 19: *reinterpret_cast< bb::cascades::ArrayDataModel**>(_v) = getTrendingGamesDataModel(); break;
        case 20: *reinterpret_cast< bb::cascades::ArrayDataModel**>(_v) = getDownloadsDataModel(); break;
        }
        _id -= 21;
    } else if (_c == QMetaObject::WriteProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 10: setLoading(*reinterpret_cast< bool*>(_v)); break;
        }
        _id -= 21;
    } else if (_c == QMetaObject::ResetProperty) {
        _id -= 21;
    } else if (_c == QMetaObject::QueryPropertyDesignable) {
        _id -= 21;
    } else if (_c == QMetaObject::QueryPropertyScriptable) {
        _id -= 21;
    } else if (_c == QMetaObject::QueryPropertyStored) {
        _id -= 21;
    } else if (_c == QMetaObject::QueryPropertyEditable) {
        _id -= 21;
    } else if (_c == QMetaObject::QueryPropertyUser) {
        _id -= 21;
    }
#endif // QT_NO_PROPERTIES
    return _id;
}
void DownloadManager::checkDownloads(UserConnection* aConn) {

	Download* d = aConn->getDownload();

	bool firstTry = false;
	if(d == NULL) {
		firstTry = true;

		bool slotsFull = (SETTING(DOWNLOAD_SLOTS) != 0) && (getDownloads() >= (size_t)SETTING(DOWNLOAD_SLOTS));
		bool speedFull = (SETTING(MAX_DOWNLOAD_SPEED) != 0) && (getAverageSpeed() >= (SETTING(MAX_DOWNLOAD_SPEED)*1024));

		if( slotsFull || speedFull ) {
			bool extraFull = (SETTING(DOWNLOAD_SLOTS) != 0) && (getDownloads() >= (size_t)(SETTING(DOWNLOAD_SLOTS)+3));
			if(extraFull || !QueueManager::getInstance()->hasDownload(aConn->getUser(), QueueItem::HIGHEST)) {
				removeConnection(aConn);
				return;
			}
		}

		d = QueueManager::getInstance()->getDownload(aConn->getUser());

		if(d == NULL) {
			removeConnection(aConn, true);
			return;
		}

		{
			Lock l(cs);
			downloads.push_back(d);
		}

		d->setUserConnection(aConn);
		aConn->setDownload(d);
	}

	if(firstTry && !d->getTreeValid() && 
		!d->isSet(Download::FLAG_USER_LIST) && d->getTTH() != NULL)
	{
		if(HashManager::getInstance()->getTree(d->getTarget(), d->getTTH(), d->getTigerTree())) {
			d->setTreeValid(true);
		} else if(!d->isSet(Download::FLAG_TREE_TRIED) && 
			aConn->isSet(UserConnection::FLAG_SUPPORTS_TTHL)) 
		{
			// So, we need to download the tree...
			Download* tthd = new Download();
			tthd->setOldDownload(d);
			tthd->setFlag(Download::FLAG_TREE_DOWNLOAD);
			tthd->setTarget(d->getTarget());
			tthd->setSource(d->getSource());

			tthd->setUserConnection(aConn);
			aConn->setDownload(tthd);

			aConn->setState(UserConnection::STATE_TREE);
			// Hack to get by TTH if possible
			tthd->setTTH(d->getTTH());
			aConn->send(tthd->getCommand(false, aConn->isSet(UserConnection::FLAG_SUPPORTS_TTHF)));
			tthd->setTTH(NULL);
			return;
		}
	}

	aConn->setState(UserConnection::STATE_FILELENGTH);
	
	if(d->isSet(Download::FLAG_RESUME)) {
		dcassert(d->getSize() != -1);

		const string& target = (d->getTempTarget().empty() ? d->getTarget() : d->getTempTarget());
		int64_t start = File::getSize(target);

		// Only use antifrag if we don't have a previous non-antifrag part
		if( BOOLSETTING(ANTI_FRAG) && (start == -1) && (d->getSize() != -1) ) {
			int64_t aSize = File::getSize(target + Download::ANTI_FRAG_EXT);

			if(aSize == d->getSize())
				start = d->getPos();
			else
				start = 0;

			d->setFlag(Download::FLAG_ANTI_FRAG);
		}
		
		int rollback = SETTING(ROLLBACK);
		if(rollback > start) {
			d->setStartPos(0);
		} else {
			d->setStartPos(start - rollback);
			d->setFlag(Download::FLAG_ROLLBACK);
		}
	} else {
		d->setStartPos(0);
	}

	if(d->isSet(Download::FLAG_USER_LIST)) {
		if(aConn->isSet(UserConnection::FLAG_SUPPORTS_XML_BZLIST)) {
			d->setSource("files.xml.bz2");
		}
	}

	if(aConn->isSet(UserConnection::FLAG_SUPPORTS_ADCGET) && d->isSet(Download::FLAG_UTF8)) {
		aConn->send(d->getCommand(
			aConn->isSet(UserConnection::FLAG_SUPPORTS_ZLIB_GET),
			aConn->isSet(UserConnection::FLAG_SUPPORTS_TTHF)
			));
	} else {
		if(BOOLSETTING(COMPRESS_TRANSFERS) && aConn->isSet(UserConnection::FLAG_SUPPORTS_GETZBLOCK) && d->getSize() != -1 ) {
			// This one, we'll download with a zblock download instead...
			d->setFlag(Download::FLAG_ZDOWNLOAD);
			aConn->getZBlock(d->getSource(), d->getPos(), d->getBytesLeft(), d->isSet(Download::FLAG_UTF8));
		} else if(d->isSet(Download::FLAG_UTF8)) {
			aConn->getBlock(d->getSource(), d->getPos(), d->getBytesLeft(), true);
		} else {
			aConn->get(d->getSource(), d->getPos());
		}
	}
}