Beispiel #1
0
int FileSystem::deleteFile(fs_fileno fileHandle) {
	bool mustReleaseLock = getLock();

	fs_pageno firstPage = getFirstPage(fileHandle);
	assert(firstPage >= 0);

	// remove the file from the file->page mappings
	setFirstPage(fileHandle, UNUSED_PAGE);
	setPageCount(fileHandle, UNUSED_PAGE);

	// mark all pages occupied by the file as free
	fs_pageno page = firstPage;
	while (page > 0) {
		fs_pageno nextPage = getPageStatus(page);
		setPageStatus(page, UNUSED_PAGE);
		page = nextPage;
	}

	// check if it is appropriate to reduce the size of the file->page table
	if ((freeFileNumbers[fileMappingSize - 1] == doubleIntsPerPage) &&
			(freeFileNumbers[fileMappingSize - 2] == doubleIntsPerPage))
		decreaseFileMappingSize();

	if (mustReleaseLock)
		releaseLock();
	return FILESYSTEM_SUCCESS;
} // end of deleteFile(fs_fileno)
Beispiel #2
0
void CaseInModel::updatePageCount()
{
	QSqlQuery query( SqlConnectionController::qSqlDb() );

	query.exec("SELECT COUNT(1) as count FROM sprawy_wejscie");
	query.next();

	qDebug() << query.value(0).toDouble() << (qreal)onPage();

	setPageCount( qCeil(query.value(0).toDouble() / (qreal)onPage()) );
}
Beispiel #3
0
void PageApi::setImageCount(int count, bool sure)
{
	if (m_imagesCount <= 0 || (!m_imagesCountSafe && sure))
	{
		m_imagesCount = count;
		m_imagesCountSafe = sure;

		if (sure)
		{
			int forcedLimit = m_api->forcedLimit();
			int perPage = forcedLimit > 0 ? forcedLimit : m_imagesPerPage;
			setPageCount(qCeil(static_cast<qreal>(count) / perPage), true);
		}
	}
}
Beispiel #4
0
int FileSystem::createFile(fs_fileno fileHandle) {
	bool mustReleaseLock = getLock();
	int result = FILESYSTEM_ERROR;

	// Claim free page (first of file), then claim file number.
	fs_pageno firstPage = claimFreePage(-1, -1);
	assert(firstPage >= 0);

	while (fileHandle >= doubleIntsPerPage * fileMappingSize)
		increaseFileMappingSize();

	if (fileHandle >= 0) {
		// create a file with a specific file number
		if (getFirstPage(fileHandle) >= 0) {
			setPageStatus(firstPage, UNUSED_PAGE);
			goto endOfCreateFile;
		}
	}
	else {
		// create a file with an arbitrary file number
		fileHandle = claimFreeFileNumber();
		assert(fileHandle >= 0);
		setPageStatus(firstPage, UNUSED_PAGE);
	}

	// Set length to zero. Write first page to the file mappings table.
	setPageStatus(firstPage, 0);
	setFirstPage(fileHandle, firstPage);
	setPageCount(fileHandle, 1);

	result = fileHandle;

endOfCreateFile:
	if (mustReleaseLock)
		releaseLock();
	return result;
} // end of createFile(fs_fileno)
Beispiel #5
0
void PageApi::parseActual()
{
	// Try to read the reply
	m_source = m_reply->readAll();
	if (m_source.isEmpty() || m_reply->error() != QNetworkReply::NoError)
	{
		if (m_reply->error() != QNetworkReply::OperationCanceledError)
		{ log(QStringLiteral("[%1][%2] Loading error: %3 (%4)").arg(m_site->url(), m_format, m_reply->errorString()).arg(m_reply->error()), Logger::Error); }
		m_reply->deleteLater();
		m_reply = nullptr;
		emit finishedLoading(this, LoadResult::Error);
		return;
	}

	int first = m_smart && m_blim > 0 ? ((m_page - 1) * m_imagesPerPage) % m_blim : 0;

	// Parse source
	ParsedPage page = m_api->parsePage(m_parentPage, m_source, first, m_imagesPerPage);
	if (!page.error.isEmpty())
	{
		m_errors.append(page.error);
		log(QStringLiteral("[%1][%2] %3").arg(m_site->url(), m_format, page.error), Logger::Warning);
		m_reply->deleteLater();
		m_reply = nullptr;
		emit finishedLoading(this, LoadResult::Error);
		return;
	}

	// Fill data from parsing result
	if (page.imageCount >= 0)
	{ setImageCount(page.imageCount, true); }
	if (page.pageCount >= 0)
	{ setPageCount(page.pageCount, true); }
	for (const Tag &tag : qAsConst(page.tags))
	{ m_tags.append(tag); }
	for (const QSharedPointer<Image> &img : qAsConst(page.images))
	{ addImage(img); }
	if (page.urlNextPage.isValid())
	{ m_urlNextPage = page.urlNextPage; }
	if (page.urlPrevPage.isValid())
	{ m_urlPrevPage = page.urlPrevPage; }
	if (!page.wiki.isEmpty())
	{ m_wiki = page.wiki; }

	// Complete missing tag information from images' tags if necessary
	if (m_tags.isEmpty())
	{
		QStringList tagsGot;
		for (int i = 0; i < m_images.count(); i++)
		{
			QList<Tag> tags = m_images.at(i)->tags();
			for (int t = 0; t < tags.count(); t++)
			{
				if (tagsGot.contains(tags[t].text()))
				{ m_tags[tagsGot.indexOf(tags[t].text())].setCount(m_tags[tagsGot.indexOf(tags[t].text())].count()+1); }
				else
				{
					m_tags.append(tags[t]);
					tagsGot.append(tags[t].text());
				}
			}
		}
	}

	// Complete image count information from tag count information
	if (m_imagesCount < 1)
	{
		for (const Tag &tag : qAsConst(m_tags))
		{
			if (tag.text() == m_search.join(" "))
			{ setImageCount(tag.count(), false); }
		}
	}

	// Remove first n images (according to site settings)
	int skip = m_site->setting("ignore/always", 0).toInt();
	if (false && m_isAltPage) // FIXME(Bionus): broken since move to Api class
	{ skip = m_site->setting("ignore/alt", 0).toInt(); }
	if (m_page == 1)
	{ skip = m_site->setting("ignore/1", 0).toInt(); }
	if (m_api->getName() == QLatin1String("Html"))
	{
		if (m_images.size() >= skip)
		{
			for (int i = 0; i < skip; ++i)
				m_images.removeFirst();
		}
		else
		{ log(QStringLiteral("Wanting to skip %1 images but only %2 returned").arg(skip).arg(m_images.size()), Logger::Warning); }
	}

	// Virtual paging
	int firstImage = 0;
	int lastImage = m_smart ? m_imagesPerPage : m_images.size();
	if (false && !m_originalUrl.contains("{page}") && !m_originalUrl.contains("{cpage}") && !m_originalUrl.contains("{pagepart}") && !m_originalUrl.contains("{pid}")) // TODO(Bionus): add real virtual paging
	{
		firstImage = m_imagesPerPage * (m_page - 1);
		lastImage = m_imagesPerPage;
	}
	while (firstImage > 0 && !m_images.isEmpty())
	{
		m_images.removeFirst();
		firstImage--;
	}
	while (m_images.size() > lastImage)
	{ m_images.removeLast(); }

	log(QStringLiteral("[%1][%2] Parsed page <a href=\"%3\">%3</a>: %4 images, %5 tags (%6), %7 total (%8), %9 pages (%10)").arg(m_site->url(), m_format, m_reply->url().toString().toHtmlEscaped()).arg(m_images.count()).arg(page.tags.count()).arg(m_tags.count()).arg(imagesCount(false)).arg(imagesCount(true)).arg(pagesCount(false)).arg(pagesCount(true)), Logger::Info);

	m_reply->deleteLater();
	m_reply = nullptr;
	m_loaded = true;

	emit finishedLoading(this, LoadResult::Ok);
}