Exemple #1
0
void
ScreenshotWindow::_DownloadThread()
{
	printf("_DownloadThread()\n");
	if (!Lock()) {
		printf("  failed to lock screenshot window\n");
		return;
	}

	fScreenshotView->UnsetBitmap();

	ScreenshotInfoList screenshotInfos;
	if (fPackage.Get() != NULL)
		screenshotInfos = fPackage->ScreenshotInfos();

	Unlock();

	if (screenshotInfos.CountItems() == 0) {
		printf("  package has no screenshots\n");
		return;
	}

	// Obtain the correct code for the screenshot to display
	// TODO: Once navigation buttons are added, we could use the
	// ScreenshotInfo at the "current" index.
	const ScreenshotInfo& info = screenshotInfos.ItemAtFast(
		atomic_get(&fCurrentScreenshotIndex));

	BMallocIO buffer;
	WebAppInterface interface;

	// Only indicate being busy with the download if it takes a little while
	BMessenger messenger(this);
	BMessageRunner delayedMessenger(messenger,
		new BMessage(MSG_DOWNLOAD_START),
		kProgressIndicatorDelay, 1);

	// Retrieve screenshot from web-app
	status_t status = interface.RetrieveScreenshot(info.Code(),
		info.Width(), info.Height(), &buffer);

	delayedMessenger.SetCount(0);
	messenger.SendMessage(MSG_DOWNLOAD_STOP);

	if (status == B_OK && Lock()) {
		printf("got screenshot");
		fScreenshot = BitmapRef(new(std::nothrow)SharedBitmap(buffer), true);
		fScreenshotView->SetBitmap(fScreenshot);
		_ResizeToFitAndCenter();
		Unlock();
	} else {
		printf("  failed to download screenshot\n");
	}
}
void
ScreenshotWindow::_DownloadThread()
{
	printf("_DownloadThread()\n");
	if (!Lock()) {
		printf("  failed to lock screenshot window\n");
		return;
	}

	fScreenshotView->UnsetBitmap();

	ScreenshotInfoList screenshotInfos;
	if (fPackage.Get() != NULL)
		screenshotInfos = fPackage->ScreenshotInfos();

	Unlock();

	if (screenshotInfos.CountItems() == 0) {
		printf("  package has no screenshots\n");
		return;
	}

	// Obtain the correct code for the screenshot to display
	// TODO: Once navigation buttons are added, we could use the
	// ScreenshotInfo at the "current" index.
	const ScreenshotInfo& info = screenshotInfos.ItemAtFast(0);

	BMallocIO buffer;
	WebAppInterface interface;

	// Retrieve screenshot from web-app
	status_t status = interface.RetrieveScreenshot(info.Code(),
		info.Width(), info.Height(), &buffer);
	if (status == B_OK && Lock()) {
		printf("got screenshot");
		fScreenshot = BitmapRef(new(std::nothrow)SharedBitmap(buffer), true);
		fScreenshotView->SetBitmap(fScreenshot);
		_ResizeToFitAndCenter();
		Unlock();
	} else {
		printf("  failed to download screenshot\n");
	}
}