Exemple #1
0
TReplicantTray::TReplicantTray(TBarView* parent, bool vertical)
	:
	BView(BRect(0, 0, 1, 1), "Status", B_FOLLOW_LEFT | B_FOLLOW_TOP,
		B_WILL_DRAW | B_FRAME_EVENTS),
	fTime(NULL),
	fBarView(parent),
	fShelf(new TReplicantShelf(this)),
	fMultiRowMode(vertical),
	fMinimumTrayWidth(kMinimumTrayWidth),
	fAlignmentSupport(false)
{
	// init the minimum window width according to the logo.
	const BBitmap* logoBitmap = AppResSet()->FindBitmap(B_MESSAGE_TYPE,
		R_LeafLogoBitmap);
	if (logoBitmap != NULL) {
		sMinimumWindowWidth = max_c(sMinimumWindowWidth,
			2 * (logoBitmap->Bounds().Width() + 8));
		fMinimumTrayWidth = sMinimumWindowWidth - kGutter - kDragRegionWidth;
	}

	BFormattingConventions conventions;
	BLocale::Default()->GetFormattingConventions(&conventions);
	bool use24HourClock = conventions.Use24HourClock();
	desk_settings* settings = ((TBarApp*)be_app)->Settings();

	// Create the time view
	fTime = new TTimeView(fMinimumTrayWidth, kMaxReplicantHeight - 1.0,
		use24HourClock, settings->showSeconds, settings->showDayOfWeek);
}
Exemple #2
0
void
TReplicantTray::MessageReceived(BMessage* message)
{
	switch (message->what) {
		case B_LOCALE_CHANGED:
		{
			if (fTime == NULL)
				return;

			// Locale may have updated 12/24 hour clock
			BFormattingConventions conventions;
			BLocale::Default()->GetFormattingConventions(&conventions);
			fTime->SetUse24HourClock(conventions.Use24HourClock());

			// time string reformat -> realign
			RealignReplicants();
			AdjustPlacement();
			break;
		}

		case kShowHideTime:
			// from context menu in clock and in this view
			ShowHideTime();
			break;

		case kShowSeconds:
			if (fTime == NULL)
				return;

			fTime->SetShowSeconds(!fTime->ShowSeconds());

			// time string reformat -> realign
			RealignReplicants();
			AdjustPlacement();
			break;

		case kShowDayOfWeek:
			if (fTime == NULL)
				return;

			fTime->SetShowDayOfWeek(!fTime->ShowDayOfWeek());

			// time string reformat -> realign
			RealignReplicants();
			AdjustPlacement();
			break;

#ifdef DB_ADDONS
		case B_NODE_MONITOR:
			HandleEntryUpdate(message);
			break;
#endif

		default:
			BView::MessageReceived(message);
			break;
	}
}
status_t
LocaleRosterData::_AddDefaultFormattingConventionsToMessage(
	BMessage* message) const
{
	BFormattingConventions conventions;
	fDefaultLocale.GetFormattingConventions(&conventions);

	return conventions.Archive(message);
}
Exemple #4
0
void
print_formatting_conventions()
{
	BFormattingConventions conventions;
	BLocale::Default()->GetFormattingConventions(&conventions);
	if (conventions.CountryCode() != NULL) {
		printf("%s_%s.UTF-8\n", conventions.LanguageCode(),
			conventions.CountryCode());
	} else {
		printf("%s.UTF-8\n", conventions.LanguageCode());
	}
}
void
FormatSettingsView::Refresh(bool setInitial)
{
	BFormattingConventions conventions;
	BLocale::Default()->GetFormattingConventions(&conventions);
	if (setInitial)
		fInitialConventions = conventions;

	if (!conventions.Use24HourClock()) {
		f12HourRadioButton->SetValue(B_CONTROL_ON);
		fLocaleIs24Hour = false;
	} else {
		f24HourRadioButton->SetValue(B_CONTROL_ON);
		fLocaleIs24Hour = true;
	}

	fUseLanguageStringsCheckBox->SetValue(
		conventions.UseStringsFromPreferredLanguage()
			? B_CONTROL_ON : B_CONTROL_OFF);

	_UpdateExamples();
}
void
FormatSettingsView::MessageReceived(BMessage* message)
{
	switch (message->what) {
		case kClockFormatChange:
		{
			BFormattingConventions conventions;
			BLocale::Default()->GetFormattingConventions(&conventions);
			conventions.SetExplicitUse24HourClock(
				f24HourRadioButton->Value() ? true : false);
			MutableLocaleRoster::Default()->SetDefaultFormattingConventions(
				conventions);

			_UpdateExamples();
			Window()->PostMessage(kMsgSettingsChanged);
			break;
		}

		case kStringsLanguageChange:
		{
			BFormattingConventions conventions;
			BLocale::Default()->GetFormattingConventions(&conventions);
			conventions.SetUseStringsFromPreferredLanguage(
				fUseLanguageStringsCheckBox->Value() ? true : false);
			MutableLocaleRoster::Default()->SetDefaultFormattingConventions(
				conventions);

			_UpdateExamples();

			Window()->PostMessage(kMsgSettingsChanged);
			break;
		}

		default:
			BView::MessageReceived(message);
	}
}
status_t
LocaleRosterData::_SetDefaultFormattingConventions(
	const BFormattingConventions& newFormattingConventions)
{
	fDefaultLocale.SetFormattingConventions(newFormattingConventions);

	UErrorCode icuError = U_ZERO_ERROR;
	Locale icuLocale = Locale::createCanonical(newFormattingConventions.ID());
	if (icuLocale.isBogus())
		return B_ERROR;

	Locale::setDefault(icuLocale, icuError);
	if (!U_SUCCESS(icuError))
		return B_ERROR;

	return B_OK;
}
Exemple #8
0
void
print_time_conventions()
{
	BFormattingConventions conventions;
	BLocale::Default()->GetFormattingConventions(&conventions);
	if (conventions.CountryCode() != NULL) {
		printf("%s_%s.UTF-8%s\n", conventions.LanguageCode(),
			conventions.CountryCode(),
			conventions.UseStringsFromPreferredLanguage()
				? "@strings=messages" : "");
	} else {
		printf("%s.UTF-8%s\n", conventions.LanguageCode(),
			conventions.UseStringsFromPreferredLanguage()
				? "@strings=messages" : "");
	}
}
Exemple #9
0
LocaleWindow::LocaleWindow()
	:
	BWindow(BRect(0, 0, 0, 0), B_TRANSLATE_SYSTEM_NAME("Locale"), B_TITLED_WINDOW,
		B_QUIT_ON_WINDOW_CLOSE | B_ASYNCHRONOUS_CONTROLS
			| B_AUTO_UPDATE_SIZE_LIMITS),
	fInitialConventionsItem(NULL),
	fDefaultConventionsItem(NULL),
	fFilesystemTranslationCheckbox(NULL)
{
	SetLayout(new BGroupLayout(B_HORIZONTAL));

	float spacing = be_control_look->DefaultItemSpacing();

	BTabView* tabView = new BTabView("tabview");
	BGroupView* languageTab = new BGroupView(B_TRANSLATE("Language"),
		B_HORIZONTAL, spacing);

	// first list: available languages
	fLanguageListView = new LanguageListView("available",
		B_MULTIPLE_SELECTION_LIST);
	BScrollView* scrollView = new BScrollView("scroller", fLanguageListView,
		B_WILL_DRAW | B_FRAME_EVENTS, true, true);

	fLanguageListView->SetInvocationMessage(new BMessage(kMsgLanguageInvoked));
	fLanguageListView->SetDragMessage(new BMessage(kMsgLanguageDragged));

	BFont font;
	fLanguageListView->GetFont(&font);

	// Fill the language list from the LocaleRoster data
	BMessage availableLanguages;
	if (BLocaleRoster::Default()->GetAvailableLanguages(&availableLanguages)
			== B_OK) {
		BString currentID;
		LanguageListItem* lastAddedCountryItem = NULL;

		for (int i = 0; availableLanguages.FindString("language", i, &currentID)
				== B_OK; i++) {
			// Now get the human-readable, native name for each language
			BString name;
			BLanguage currentLanguage(currentID.String());
			currentLanguage.GetNativeName(name);

			// TODO: the following block fails to detect a couple of language
			// names as containing glyphs we can't render. Why's that?
			bool hasGlyphs[name.CountChars()];
			font.GetHasGlyphs(name.String(), name.CountChars(), hasGlyphs);
			for (int32 i = 0; i < name.CountChars(); ++i) {
				if (!hasGlyphs[i]) {
					// replace by name translated to current language
					currentLanguage.GetName(name);
					break;
				}
			}

			LanguageListItem* item = new LanguageListItem(name,
				currentID.String(), currentLanguage.Code(),
				currentLanguage.CountryCode());
			if (currentLanguage.IsCountrySpecific()
				&& lastAddedCountryItem != NULL
				&& lastAddedCountryItem->Code() == item->Code()) {
				fLanguageListView->AddUnder(item, lastAddedCountryItem);
			} else {
				// This is a language variant, add it at top-level
				fLanguageListView->AddItem(item);
				if (!currentLanguage.IsCountrySpecific()) {
					item->SetExpanded(false);
					lastAddedCountryItem = item;
				}
			}
		}

		fLanguageListView->FullListSortItems(compare_typed_list_items);
	} else {
		BAlert* alert = new BAlert("Error",
			B_TRANSLATE("Unable to find the available languages! You can't "
				"use this preflet!"),
			B_TRANSLATE("OK"), NULL, NULL,
			B_WIDTH_AS_USUAL, B_OFFSET_SPACING, B_STOP_ALERT);
		alert->Go();
	}

	// Second list: active languages
	fPreferredListView = new LanguageListView("preferred",
		B_MULTIPLE_SELECTION_LIST);
	BScrollView* scrollViewEnabled = new BScrollView("scroller",
		fPreferredListView, B_WILL_DRAW | B_FRAME_EVENTS, true, true);

	fPreferredListView->SetInvocationMessage(
		new BMessage(kMsgPreferredLanguageInvoked));
	fPreferredListView->SetDeleteMessage(
		new BMessage(kMsgPreferredLanguageDeleted));
	fPreferredListView->SetDragMessage(
		new BMessage(kMsgPreferredLanguageDragged));

	BLayoutBuilder::Group<>(languageTab)
		.AddGroup(B_VERTICAL, spacing)
			.Add(new BStringView("", B_TRANSLATE("Available languages")))
			.Add(scrollView)
			.End()
		.AddGroup(B_VERTICAL, spacing)
			.Add(new BStringView("", B_TRANSLATE("Preferred languages")))
			.Add(scrollViewEnabled)
			.End()
		.SetInsets(spacing, spacing, spacing, spacing);

	BView* countryTab = new BView(B_TRANSLATE("Formatting"), B_WILL_DRAW);
	countryTab->SetLayout(new BGroupLayout(B_VERTICAL, 0));

	fConventionsListView = new LanguageListView("formatting",
		B_SINGLE_SELECTION_LIST);
	scrollView = new BScrollView("scroller", fConventionsListView,
		B_WILL_DRAW | B_FRAME_EVENTS, true, true);
	fConventionsListView->SetSelectionMessage(
		new BMessage(kMsgConventionsSelection));

	// get all available formatting conventions (by language)
	BFormattingConventions defaultConventions;
	BLocale::Default()->GetFormattingConventions(&defaultConventions);
	BString conventionID;
	fInitialConventionsItem = NULL;
	LanguageListItem* lastAddedConventionsItem = NULL;
	for (int i = 0;
		availableLanguages.FindString("language", i, &conventionID) == B_OK;
		i++) {
		BFormattingConventions convention(conventionID);
		BString conventionName;
		convention.GetName(conventionName);

		LanguageListItem* item = new LanguageListItem(conventionName,
			conventionID, convention.LanguageCode(), convention.CountryCode());
		if (!strcmp(conventionID, "en_US"))
			fDefaultConventionsItem = item;
		if (conventionID.FindFirst('_') >= 0
			&& lastAddedConventionsItem != NULL
			&& lastAddedConventionsItem->Code() == item->Code()) {
			if (!strcmp(conventionID, defaultConventions.ID())) {
				fConventionsListView->Expand(lastAddedConventionsItem);
				fInitialConventionsItem = item;
			}
			fConventionsListView->AddUnder(item, lastAddedConventionsItem);
		} else {
			// This conventions-item isn't country-specific, add it at top-level
			fConventionsListView->AddItem(item);
			if (conventionID.FindFirst('_') < 0) {
				item->SetExpanded(false);
				lastAddedConventionsItem = item;
			}
			if (!strcmp(conventionID, defaultConventions.ID()))
				fInitialConventionsItem = item;
		}
	}

	fConventionsListView->FullListSortItems(compare_typed_list_items);
	if (fInitialConventionsItem != NULL) {
		fConventionsListView->Select(fConventionsListView->IndexOf(
			fInitialConventionsItem));
	}

	fConventionsListView->SetExplicitMinSize(BSize(20 * be_plain_font->Size(),
		B_SIZE_UNSET));

	fFormatView = new FormatSettingsView();

	countryTab->AddChild(BLayoutBuilder::Group<>(B_HORIZONTAL, spacing)
		.AddGroup(B_VERTICAL, 3)
			.Add(scrollView)
			.End()
		.Add(fFormatView)
		.SetInsets(spacing, spacing, spacing, spacing));

	BView* optionsTab = new BView(B_TRANSLATE("Options"), B_WILL_DRAW);
	optionsTab->SetLayout(new BGroupLayout(B_VERTICAL, 0));

	fFilesystemTranslationCheckbox = new BCheckBox("filesystemTranslation",
		B_TRANSLATE("Translate application and folder names in Deskbar and Tracker."),
		new BMessage(kMsgFilesystemTranslationChanged));

	fFilesystemTranslationCheckbox->SetValue(
		BLocaleRoster::Default()->IsFilesystemTranslationPreferred());

	optionsTab->AddChild(BLayoutBuilder::Group<>(B_VERTICAL, spacing)
		.Add(fFilesystemTranslationCheckbox)
		.AddGlue()
		.SetInsets(spacing, spacing, spacing, spacing));

	tabView->AddTab(languageTab);
	tabView->AddTab(countryTab);
	tabView->AddTab(optionsTab);

	BButton* button
		= new BButton(B_TRANSLATE("Defaults"), new BMessage(kMsgDefaults));

	fRevertButton
		= new BButton(B_TRANSLATE("Revert"), new BMessage(kMsgRevert));
	fRevertButton->SetEnabled(false);

	BLayoutBuilder::Group<>(this, B_VERTICAL, spacing)
		.Add(tabView)
		.AddGroup(B_HORIZONTAL, spacing)
			.Add(button)
			.Add(fRevertButton)
			.AddGlue()
			.End()
		.SetInsets(spacing, spacing, spacing, spacing)
		.End();

	_Refresh(true);
	_SettingsReverted();
	CenterOnScreen();
}