Esempio n. 1
0
RatePackageWindow::RatePackageWindow(BWindow* parent, BRect frame)
	:
	BWindow(frame, B_TRANSLATE_SYSTEM_NAME("Your rating"),
		B_FLOATING_WINDOW_LOOK, B_FLOATING_SUBSET_WINDOW_FEEL,
		B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS),
	fRatingText()
{
	AddToSubset(parent);
	CenterIn(parent->Frame());

	TextDocumentView* textView = new TextDocumentView();
	ScrollView* textScrollView = new ScrollView(
		"rating scroll view", textView);

	MarkupParser parser;
	fRatingText = parser.CreateDocumentFromMarkup(
		"Here is where you ''could'' type your awesome rating comment, "
		"if only this were already implemented.");

	textView->SetInsets(10.0f);
	textView->SetTextDocument(fRatingText);
	textView->SetTextEditor(TextEditorRef(new TextEditor(), true));

	fSendButton = new BButton("send", B_TRANSLATE("Send"),
		new BMessage(MSG_SEND));

	// Build layout
	BLayoutBuilder::Group<>(this, B_VERTICAL)
		.Add(textScrollView)
		.AddGroup(B_HORIZONTAL)
			.AddGlue()
			.Add(fSendButton)
		.End()
		.SetInsets(B_USE_DEFAULT_SPACING)
	;
}
Esempio n. 2
0
void
RatePackageWindow::_QueryRatingThread()
{
	if (!Lock()) {
		fprintf(stderr, "rating query: Failed to lock window\n");
		return;
	}

	PackageInfoRef package(fPackage);

	Unlock();

	BAutolock locker(fModel.Lock());
	BString username = fModel.Username();
	locker.Unlock();

	if (package.Get() == NULL) {
		fprintf(stderr, "rating query: No package\n");
		_SetWorkerThread(-1);
		return;
	}

	WebAppInterface interface;
	BMessage info;
	const DepotInfo* depot = fModel.DepotForName(package->DepotName());
	BString repositoryCode;

	if (depot != NULL)
		repositoryCode = depot->WebAppRepositoryCode();

	if (repositoryCode.Length() == 0) {
		printf("unable to obtain the repository code for depot; %s\n",
			package->DepotName().String());
	} else {
		status_t status = interface.RetrieveUserRating(
			package->Name(), package->Version(), package->Architecture(),
			repositoryCode, username, info);

	//	info.PrintToStream();

		BMessage result;
		if (status == B_OK && info.FindMessage("result", &result) == B_OK
			&& Lock()) {

			result.FindString("code", &fRatingID);
			result.FindBool("active", &fRatingActive);
			BString comment;
			if (result.FindString("comment", &comment) == B_OK) {
				MarkupParser parser;
				fRatingText = parser.CreateDocumentFromMarkup(comment);
				fTextView->SetTextDocument(fRatingText);
			}
			if (result.FindString("userRatingStabilityCode",
				&fStability) == B_OK) {
				int32 index = 0;
				for (int32 i = fStabilityCodes.CountItems() - 1; i >= 0; i--) {
					const StabilityRating& stability
						= fStabilityCodes.ItemAtFast(i);
					if (stability.Name() == fStability) {
						index = i;
						break;
					}
				}
				BMenuItem* item = fStabilityField->Menu()->ItemAt(index);
				if (item != NULL)
					item->SetMarked(true);
			}
			if (result.FindString("naturalLanguageCode",
				&fCommentLanguage) == B_OK) {
				BMenuItem* item = fCommentLanguageField->Menu()->ItemAt(
					fModel.SupportedLanguages().IndexOf(fCommentLanguage));
				if (item != NULL)
					item->SetMarked(true);
			}
			double rating;
			if (result.FindDouble("rating", &rating) == B_OK) {
				fRating = (float)rating;
				fSetRatingView->SetPermanentRating(fRating);
			}

			fRatingActiveCheckBox->SetValue(fRatingActive);
			fRatingActiveCheckBox->Show();

			fSendButton->SetLabel(B_TRANSLATE("Update"));

			Unlock();
		} else {
			fprintf(stderr, "rating query: Failed response: %s\n",
				strerror(status));
			if (!info.IsEmpty())
				info.PrintToStream();
		}
	}

	_SetWorkerThread(-1);
}
Esempio n. 3
0
RatePackageWindow::RatePackageWindow(BWindow* parent, BRect frame,
	Model& model)
	:
	BWindow(frame, B_TRANSLATE("Rate package"),
		B_FLOATING_WINDOW_LOOK, B_FLOATING_SUBSET_WINDOW_FEEL,
		B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS),
	fModel(model),
	fRatingText(),
	fTextEditor(new TextEditor(), true),
	fRating(-1.0f),
	fCommentLanguage(fModel.PreferredLanguage()),
	fWorkerThread(-1)
{
	AddToSubset(parent);

	BStringView* ratingLabel = new BStringView("rating label",
		B_TRANSLATE("Your rating:"));

	fSetRatingView = new SetRatingView();

	fTextView = new TextDocumentView();
	ScrollView* textScrollView = new ScrollView(
		"rating scroll view", fTextView);

	// Get a TextDocument with default paragraph and character style
	MarkupParser parser;
	fRatingText = parser.CreateDocumentFromMarkup("");

	fTextView->SetInsets(10.0f);
	fTextView->SetTextDocument(fRatingText);
	fTextView->SetTextEditor(fTextEditor);

	// Construct stability rating popup
	BPopUpMenu* stabilityMenu = new BPopUpMenu(B_TRANSLATE("Stability"));
	fStabilityField = new BMenuField("stability",
		B_TRANSLATE("Stability:"), stabilityMenu);

	fStabilityCodes.Add(StabilityRating(
		B_TRANSLATE("Not specified"), "unspecified"));
	fStabilityCodes.Add(StabilityRating(
		B_TRANSLATE("Stable"), "stable"));
	fStabilityCodes.Add(StabilityRating(
		B_TRANSLATE("Mostly stable"), "mostlystable"));
	fStabilityCodes.Add(StabilityRating(
		B_TRANSLATE("Unstable but usable"), "unstablebutusable"));
	fStabilityCodes.Add(StabilityRating(
		B_TRANSLATE("Very unstable"), "veryunstable"));
	fStabilityCodes.Add(StabilityRating(
		B_TRANSLATE("Does not start"), "nostart"));

	add_stabilities_to_menu(fStabilityCodes, stabilityMenu);
	stabilityMenu->SetTargetForItems(this);

	fStability = fStabilityCodes.ItemAt(0).Name();
	stabilityMenu->ItemAt(0)->SetMarked(true);

	// Construct languages popup
	BPopUpMenu* languagesMenu = new BPopUpMenu(B_TRANSLATE("Language"));
	fCommentLanguageField = new BMenuField("language",
		B_TRANSLATE("Comment language:"), languagesMenu);

	add_languages_to_menu(fModel.SupportedLanguages(), languagesMenu);
	languagesMenu->SetTargetForItems(this);

	BMenuItem* defaultItem = languagesMenu->ItemAt(
		fModel.SupportedLanguages().IndexOf(fCommentLanguage));
	if (defaultItem != NULL)
		defaultItem->SetMarked(true);

	fRatingActiveCheckBox = new BCheckBox("rating active",
		B_TRANSLATE("Other users can see this rating"),
		new BMessage(MSG_RATING_ACTIVE_CHANGED));
	// Hide the check mark by default, it will be made visible when
	// the user already made a rating and it is loaded
	fRatingActiveCheckBox->Hide();

	// Construct buttons
	fCancelButton = new BButton("cancel", B_TRANSLATE("Cancel"),
		new BMessage(B_QUIT_REQUESTED));

	fSendButton = new BButton("send", B_TRANSLATE("Send"),
		new BMessage(MSG_SEND));

	// Build layout
	BLayoutBuilder::Group<>(this, B_VERTICAL)
		.AddGrid()
			.Add(ratingLabel, 0, 0)
			.Add(fSetRatingView, 1, 0)
			.AddMenuField(fStabilityField, 0, 1)
			.AddMenuField(fCommentLanguageField, 0, 2)
		.End()
		.Add(textScrollView)
		.AddGroup(B_HORIZONTAL)
			.Add(fRatingActiveCheckBox)
			.AddGlue()
			.Add(fCancelButton)
			.Add(fSendButton)
		.End()
		.SetInsets(B_USE_WINDOW_INSETS)
	;

	// NOTE: Do not make Send the default button. The user might want
	// to type line-breaks instead of sending when hitting RETURN.

	CenterIn(parent->Frame());
}