Ejemplo n.º 1
0
void
LookAndFeelSettingsView::_BuildDecorMenu()
{
	fDecorMenu = new BPopUpMenu(B_TRANSLATE("Choose Decorator"));

	// collect the current system decor settings
	int32 count = fDecorUtility.CountDecorators();
	for (int32 i = 0; i < count; ++i) {
		DecorInfo* decorator = fDecorUtility.DecoratorAt(i);
		if (decorator == NULL) {
			fprintf(stderr, "Decorator : error NULL entry @ %" B_PRId32
				" / %" B_PRId32 "\n", i, count);
			continue;
		}

		BString decorName = decorator->Name();

		BMessage* message = new BMessage(kMsgSetDecor);
		message->AddString("decor", decorName);

		BMenuItem* item = new BMenuItem(decorName, message);

		fDecorMenu->AddItem(item);
	}

	_AdoptToCurrentDecor();
}
Ejemplo n.º 2
0
DecorInfo*
DecorInfoUtility::_FindDecor(const BString& pathString)
{
	// find decor by path and path alone!
	if (!fLock.IsLocked()) {
		fprintf(stderr, "DecorInfoUtility::_find_decor()\tfailure to lock! - "
			"BUG BUG BUG\n");
		return NULL;
	}

	if (pathString == "Default")
		return fList.ItemAt(0);

	for (int i = 1; i < fList.CountItems(); ++i) {
		DecorInfo* decor = fList.ItemAt(i);
		// Find the DecoratorInfo either by its true current location or by
		// what we still think the location is (before we had a chance to
		// update). NOTE: This will only catch the case when the user moved the
		// folder in which the add-on file lives. It will not work when the user
		// moves the add-on file itself or renames it.
		BPath path(decor->Ref());
		if (path.Path() == pathString || decor->Path() == pathString)
			return decor;
	}

	return NULL;
}
Ejemplo n.º 3
0
DecorInfo*
DecorInfoUtility::FindDecorator(const BString& string)
{
	if (string.Length() == 0)
		return CurrentDecorator();

	if (string.ICompare("default") == 0)
		return DefaultDecorator();

	BAutolock _(fLock);
	if (!fHasScanned)
		ScanDecorators();

	// search by path
	DecorInfo* decor = _FindDecor(string);
	if (decor != NULL)
		return decor;

	// search by name or short cut name
	for (int i = 1; i < fList.CountItems(); ++i) {
		decor = fList.ItemAt(i);
		if (string.ICompare(decor->ShortcutName()) == 0
			|| string.ICompare(decor->Name()) == 0) {
			return decor;
		}
	}

	return NULL;
}
Ejemplo n.º 4
0
const char *
DecorManager::GetDecoratorName(int32 index)
{
	DecorInfo *info = fDecorList.ItemAt(index);
	if (info)
		return info->Name();

	return NULL;
}
Ejemplo n.º 5
0
DecorInfo*
DecorManager::_FindDecor(const char *name)
{
	if (!name)
		return NULL;

	for (int32 i = 0; i < fDecorList.CountItems(); i++) {
		DecorInfo* info = fDecorList.ItemAt(i);

		if (strcmp(name, info->Name()) == 0)
			return info;
	}

	return NULL;
}
Ejemplo n.º 6
0
status_t
DecorInfoUtility::_ScanDecorators(BDirectory decoratorDirectory)
{
	BAutolock _(fLock);

	// First, run through our list and DecorInfos CheckForChanges()
	if (fHasScanned) {
		for (int i = fList.CountItems() - 1; i > 0; --i) {
			DecorInfo* decorInfo = fList.ItemAt(i);

			bool deleted = false;
			decorInfo->CheckForChanges(deleted);

			if (deleted) {
				fList.RemoveItem(decorInfo);
				delete decorInfo;
			}
		}
	}

	entry_ref ref;
	// Now, look at file system, skip the entries for which we already have
	// a DecorInfo in the list.
	while (decoratorDirectory.GetNextRef(&ref) == B_OK) {
		BPath path(&decoratorDirectory);
		status_t result = path.Append(ref.name);
		if (result != B_OK) {
			fprintf(stderr, "DecorInfoUtility::_ScanDecorators()\tFailed to"
				"append decorator file to path, skipping: %s.\n", strerror(result));
			continue;
		}
		if (_FindDecor(path.Path()) != NULL)
			continue;

		DecorInfo* decorInfo = new(std::nothrow) DecorInfo(ref);
		if (decorInfo == NULL || decorInfo->InitCheck() != B_OK) {
			fprintf(stderr, "DecorInfoUtility::_ScanDecorators()\tInitCheck() "
				"failure on decorator, skipping.\n");
			delete decorInfo;
			continue;
		}

		fList.AddItem(decorInfo);
	}

	return B_OK;
}
Ejemplo n.º 7
0
DecorInfoUtility::DecorInfoUtility(bool scanNow)
	:
	fHasScanned(false)
{
	// get default decorator from app_server
	DecorInfo* info = new(std::nothrow) DecorInfo("Default");
	if (info == NULL || info->InitCheck() != B_OK)	{
		delete info;
		fprintf(stderr, "DecorInfoUtility::constructor\tdefault decorator's "
			"DecorInfo failed InitCheck()\n");
		return;
	}

	fList.AddItem(info);

	if (scanNow)
		ScanDecorators();
}
Ejemplo n.º 8
0
void
LookAndFeelSettingsView::MessageReceived(BMessage *msg)
{
	switch (msg->what) {
		case kMsgSetDecor:
		{
			BString newDecor;
			if (msg->FindString("decor", &newDecor) == B_OK)
				_SetDecor(newDecor);
			break;
		}

		case kMsgDecorInfo:
		{
			DecorInfo* decor = fDecorUtility.FindDecorator(fCurrentDecor);
			if (decor == NULL)
				break;

			BString authorsText(decor->Authors().String());
			authorsText.ReplaceAll(", ", "\n\t");

			BString infoText(B_TRANSLATE("%decorName\n\n"
				"Authors:\n\t%decorAuthors\n\n"
				"URL: %decorURL\n"
				"License: %decorLic\n\n"
				"%decorDesc\n"));


			infoText.ReplaceFirst("%decorName", decor->Name().String());
			infoText.ReplaceFirst("%decorAuthors", authorsText.String());
			infoText.ReplaceFirst("%decorLic", decor->LicenseName().String());
			infoText.ReplaceFirst("%decorURL", decor->SupportURL().String());
			infoText.ReplaceFirst("%decorDesc", decor->ShortDescription().String());

			BAlert *infoAlert = new BAlert(B_TRANSLATE("About decorator"),
				infoText.String(), B_TRANSLATE("OK"));
			infoAlert->SetFlags(infoAlert->Flags() | B_CLOSE_ON_ESCAPE);
			infoAlert->Go();

			break;
		}

		case kMsgArrowStyleSingle:
			_SetDoubleScrollBarArrows(false);
			break;

		case kMsgArrowStyleDouble:
			_SetDoubleScrollBarArrows(true);
			break;

		default:
			BView::MessageReceived(msg);
			break;
	}
}
Ejemplo n.º 9
0
void
DecorSettingsView::MessageReceived(BMessage *msg)
{
	switch (msg->what) {
		case kMsgSetDecor:
		{
			BString newDecor;
			if (msg->FindString("decor", &newDecor) == B_OK)
				_SetDecor(newDecor);
			break;
		}
		case kMsgDecorInfo:
		{
			DecorInfo* decor = fDecorUtility.FindDecorator(fCurrentDecor);
			if (decor == NULL)
				break;

			BString authorsText(decor->Authors().String());
			authorsText.ReplaceAll(", ", "\n    ");

			BString infoText("Name: %decorName\n"
				"Authors:\n    %decorAuthors\n"
				"URL: %decorURL\n"
				"License: %decorLic\n"
				"Description:\n    %decorDesc\n");

			infoText.ReplaceFirst("%decorName", decor->Name().String());
			infoText.ReplaceFirst("%decorAuthors", authorsText.String());
			infoText.ReplaceFirst("%decorLic", decor->LicenseName().String());
			infoText.ReplaceFirst("%decorURL", decor->SupportURL().String());
			infoText.ReplaceFirst("%decorDesc", decor->ShortDescription().String());

			BAlert *infoAlert = new BAlert(B_TRANSLATE("About Decorator"),
				infoText.String(), B_TRANSLATE("OK"));
			infoAlert->SetShortcut(0, B_ESCAPE); 
			infoAlert->Go(); 

			break;
		}

		default:
			BView::MessageReceived(msg);
			break;
	}
}
Ejemplo n.º 10
0
APRView::APRView(const char* name)
	:
	BView(name, B_WILL_DRAW)
{
	SetViewUIColor(B_PANEL_BACKGROUND_COLOR);

#if 0
	fDecorMenu = new BMenu("Window Style");
	int32 decorCount = fDecorUtil->CountDecorators();
	DecorInfo* decor = NULL;
	if (decorCount > 1) {
		for (int32 i = 0; i < decorCount; i++) {
			decor = fDecorUtil->GetDecorator(i);
			if (!decor)
				continue;
			fDecorMenu->AddItem(new BMenuItem(decor->Name().String(),
				new BMessage(DECORATOR_CHANGED)));
		}

		BMenuField* field = new BMenuField("Window Style", fDecorMenu);
		// TODO: use this menu field.
	}
	BMenuItem* marked = fDecorMenu->ItemAt(fDecorUtil->IndexOfCurrentDecorator());
	if (marked)
		marked->SetMarked(true);
	else {
		marked = fDecorMenu->FindItem("Default");
		if (marked)
			marked->SetMarked(true);
	}
#endif

	LoadSettings();

	// Set up list of color attributes
	fAttrList = new BListView("AttributeList", B_SINGLE_SELECTION_LIST);

	fScrollView = new BScrollView("ScrollView", fAttrList, 0, false, true);
	fScrollView->SetViewUIColor(B_PANEL_BACKGROUND_COLOR);

	int32 count = color_description_count();
	for (int32 i = 0; i < count; i++) {
		const ColorDescription& description = *get_color_description(i);
		const char* text = B_TRANSLATE_NOCOLLECT(description.text);
		color_which which = description.which;
		fAttrList->AddItem(new ColorWhichItem(text, which, ui_color(which)));
	}

	BRect wellrect(0, 0, 50, 50);
	fColorPreview = new ColorPreview(wellrect, new BMessage(COLOR_DROPPED), 0);
	fColorPreview->SetExplicitAlignment(BAlignment(B_ALIGN_HORIZONTAL_CENTER,
		B_ALIGN_BOTTOM));

	fPicker = new BColorControl(B_ORIGIN, B_CELLS_32x8, 8.0,
		"picker", new BMessage(UPDATE_COLOR));

	BLayoutBuilder::Group<>(this, B_VERTICAL)
		.Add(fScrollView, 10.0)
		.AddGroup(B_HORIZONTAL, B_USE_DEFAULT_SPACING)
			.Add(fColorPreview)
			.Add(fPicker)
			.End()
		.SetInsets(B_USE_WINDOW_SPACING);

	fColorPreview->Parent()->SetExplicitMaxSize(
		BSize(B_SIZE_UNSET, fPicker->Bounds().Height()));
	fAttrList->SetSelectionMessage(new BMessage(ATTRIBUTE_CHOSEN));
}
Ejemplo n.º 11
0
int
main(int argc, char** argv)
{
	if (argc < 2) {
		printf("usage: %s [-l|-c|decorname]\n", argv[0]);
		printf("\t-l: list available decors\n");
		printf("\t-s: list shortcut names for available decors\n");
		printf("\t-c: give current decor name\n");
		printf("\t-i: detailed information about decor\n");
		printf("\t-p: see preview window\n");
		return 1;
	}

	// combine remaining args into one string:
	BString decoratorName;
	for (int i = 2; i < argc; ++i)
		decoratorName << argv[i] << " ";
	decoratorName.RemoveLast(" ");

	BApplication app("application/x-vnd.Haiku-setdecor");

	DecorInfoUtility* util = new DecorInfoUtility();
	DecorInfo* decor = NULL;

	if (util == NULL) {
		fprintf(stderr, "error instantiating DecoratorInfoUtility (out of"
			" memory?)\n");
		return 1;
	}

	// we want the list
	if (!strcmp(argv[1], "-l")) {
		// Print default decorator:
		print_decor_info_header();
		int32 count = util->CountDecorators();
		for (int32 i = 0; i < count; ++i) {
			decor = util->DecoratorAt(i);
			if (decor == NULL) {
				fprintf(stderr, "error NULL entry @ %li / %li - BUG BUG BUG\n",
					i, count);
				// return 2 to track DecorInfoUtility errors
				return 2;
			}
			print_decor_summary(decor, util->IsCurrentDecorator(decor));
		}

		return 0;
	}

	// we want the current decorator
	if (!strcmp(argv[1], "-c")) {
		decor = util->CurrentDecorator();

		if (decor == NULL) {
			fprintf(stderr, "Unable to determine current decorator, sorry! - "
				"BUG BUG BUG\n");
			return 2;
		}

		print_decor_info_header();
		print_decor_summary(decor, true);
		return 0;
	}


	if (!strcmp(argv[1], "-s")) {

		printf("  Shortcut        Name\n");
		printf("------------------------------------\n");

		int32 count = util->CountDecorators();
		for (int32 i = 0; i < count; ++i) {
			decor = util->DecoratorAt(i);
			if (decor == NULL) {
				fprintf(stderr, "error NULL entry @ %li / %li - BUG BUG BUG\n",
					i, count);
				// return 2 to track DecorInfoUtility errors
				return 2;
			}
			print_decor_shortcut(decor, util->IsCurrentDecorator(decor));
		}

		return 0;
	}

	// we want detailed information for a specific decorator ( by name or path )
	if (!strcmp(argv[1], "-i")) {
		if (argc < 3) {
			fprintf(stderr, "not enough arguments\n");
			return 1;
		}

		decor = util->FindDecorator(decoratorName.String());

		if (decor == NULL) {
			fprintf(stderr, "Can't find decor named \"%s\", try again\n",
				decoratorName.String());
			return 1;
		}

		print_decor_info_verbose(decor, util->IsCurrentDecorator(decor));
		return 0;
	}


	if (!strcmp(argv[1], "-p")) {
		if (argc < 3) {
			fprintf(stderr, "not enough arguments\n");
			return 1;
		}

		decor = util->FindDecorator(decoratorName.String());

		if (decor == NULL) {
			fprintf(stderr, "Can't find decor named \"%s\", try again\n",
				decoratorName.String());
			return 1;
		}

		printf("Preparing preview...\n");

		BWindow* previewWindow = new BWindow(BRect(150, 150, 390, 490),
			decor->Name().String(), B_TITLED_WINDOW, B_NOT_ZOOMABLE
				| B_QUIT_ON_WINDOW_CLOSE | B_NOT_RESIZABLE );

		previewWindow->AddChild(new BView(previewWindow->Bounds(), "",
			B_FOLLOW_ALL, 0));

		if (util->Preview(decor, previewWindow) != B_OK) {
			fprintf(stderr, "Unable to preview decorator, sorry!\n");
			// TODO: more detailed error...
			return 1;
		}

		previewWindow->Show();

		app.Run();
		return 0;
	}

	// we want to change it
	decoratorName = "";
	for (int i = 1; i < argc; ++i)
		decoratorName << argv[i] << " ";
	decoratorName.RemoveLast(" ");

	decor = util->FindDecorator(decoratorName.String());

	if (decor == NULL) {
		fprintf(stderr, "no such decorator \"%s\"\n", decoratorName.String());
		return 1;
	}

	if (util->IsCurrentDecorator(decor)) {
		printf("\"%s\" is already the current decorator\n",
			decor->Name().String());
		return 0;
	}

	printf("Setting %s as the current decorator...\n", decor->Name().String());
	if (util->SetDecorator(decor) != B_OK ) {
		fprintf(stderr, "Unable to set decorator, sorry\n\n");
		return 1;	// todo more detailed error...
	}

	return 0;
}
Ejemplo n.º 12
0
status_t
DecorInfoUtility::ScanDecorators()
{
    BPath decorPath;
    status_t ret = find_directory(B_USER_ADDONS_DIRECTORY, &decorPath);
    if (ret != B_OK)
        return ret;
    ret = decorPath.Append("decorators");
    if (ret != B_OK)
        return ret;

    BDirectory dir(decorPath.Path());
    ret = dir.InitCheck();
    if (ret != B_OK) {
        fprintf(stderr, "DecorInfoUtility::ScanDecorators:\tERROR: "
                "DECORATORS_DIR not found!\n");
        return ret;
    }

    BAutolock _(fLock);
    // First, run through our list and DecorInfos CheckForChanges()

    if (fHasScanned) {
        for (int i = fList.CountItems() - 1; i > 0; --i) {
            DecorInfo* decorInfo = fList.ItemAt(i);

            bool deleted = false;
            decorInfo->CheckForChanges(deleted);

            if (deleted) {
                fList.RemoveItem(decorInfo);
                delete decorInfo;
            }
        }
    }

    BPath path;
    entry_ref ref;
    // Now, look at file system, skip the entries for which we already have
    // a DecorInfo in the list.
    while (dir.GetNextRef(&ref) == B_OK) {
        path.SetTo(decorPath.Path());
        path.Append(ref.name);
        if (_FindDecor(path.Path()) != NULL)
            continue;

        DecorInfo* decorInfo = new(std::nothrow) DecorInfo(ref);
        if (decorInfo == NULL || decorInfo->InitCheck() != B_OK) {
            fprintf(stderr, "DecorInfoUtility::ScanDecorators()\tInitCheck() "
                    "failure on decorator, skipping\n");
            delete decorInfo;
            continue;
        }

        fList.AddItem(decorInfo);
    }

    fHasScanned = true;

    return B_OK;
}