예제 #1
0
파일: MrPeeps.cpp 프로젝트: slubman/MrPeeps
// This handles the filetypes being installed with all the extra attributes over the
// regular R5 types
void MrPeeps::InitFileTypes(void)
{
    BEntry entry("/boot/home/config/settings/MrPeeps");
    BFile file;

    // Check for settings directory
    if(!entry.Exists())
        create_directory("/boot/home/config/settings/MrPeeps",0777);

    entry.SetTo("/boot/home/config/settings/MrPeeps/MrPeeps");
    if(!entry.Exists())
    {
        file.SetTo("/boot/home/config/settings/MrPeeps/MrPeeps",B_READ_WRITE|B_CREATE_FILE);
        file.Unset();
    }


    entry.SetTo("/boot/home/config/settings/MrPeeps/filetypes_installed");
    if(!entry.Exists())
    {
        BFile file("/boot/home/config/settings/MrPeeps/filetypes_installed",B_CREATE_FILE);
        BMimeType mime;
        BString string;
        BMessage msg,info;
        uint8 installtype=2;
        int32 index=0;
        BBitmap	large_icon(BRect(0, 0, B_LARGE_ICON-1, B_LARGE_ICON-1), B_COLOR_8_BIT);
        BBitmap	mini_icon(BRect(0, 0, B_MINI_ICON-1, B_MINI_ICON-1), B_COLOR_8_BIT);

        // install person mime type
        mime.SetType(PERSON_FILE_TYPE);
        if(mime.IsInstalled())
        {
            if (mime.GetAttrInfo(&info) == B_OK)
            {
                while (info.FindString("attr:name", index++, &string) == B_OK)
                {
                    if (string.Compare(PERSON_EMAIL5)==0)
                        installtype=1;

                    if (string.Compare(PERSON_BIRTHDAY)==0)
                    {
                        installtype=0;
                        break;
                    }
                }
                if (installtype>0)
                    mime.Delete();
            }
        }
        if(installtype>0)
        {
            mime.Install();
            large_icon.SetBits(kLargePersonIcon, large_icon.BitsLength(), 0, B_COLOR_8_BIT);
            mini_icon.SetBits(kSmallPersonIcon, mini_icon.BitsLength(), 0, B_COLOR_8_BIT);
            mime.SetShortDescription("Person");
            mime.SetLongDescription("Information about a person");
            mime.SetIcon(&large_icon, B_LARGE_ICON);
            mime.SetIcon(&mini_icon, B_MINI_ICON);

            BAlert *alert=new BAlert("Mr. Peeps!", "Would you like to make Mr. Peeps! the "
                                     "default application for People files? If not sure, choose 'No'.","Yes","No");

            if(alert->Go()==0)
                mime.SetPreferredApp(APP_SIGNATURE);
            else
                mime.SetPreferredApp("application/x-vnd.Be-PEPL");

            // General Person data
            msg.AddString("attr:public_name", "First Name");
            msg.AddString("attr:name", PERSON_FIRSTNAME);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 120);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);

            msg.AddString("attr:public_name", "Last Name");
            msg.AddString("attr:name", PERSON_LASTNAME);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 120);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);

            msg.AddString("attr:public_name", "Nickname");
            msg.AddString("attr:name", PERSON_NICKNAME);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 120);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);

            msg.AddString("attr:public_name", "Title");
            msg.AddString("attr:name", PERSON_TITLE);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 120);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);

            msg.AddString("attr:public_name", "Group");
            msg.AddString("attr:name", PERSON_GROUP);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 120);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);


            // Personal data
            msg.AddString("attr:public_name", "Home Address");
            msg.AddString("attr:name", PERSON_ADDRESS);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 120);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);

            msg.AddString("attr:public_name", "Home Address(2)");
            msg.AddString("attr:name", PERSON_ADDRESS2);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 120);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);

            msg.AddString("attr:public_name", "City");
            msg.AddString("attr:name", PERSON_CITY);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 90);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);

            msg.AddString("attr:public_name", "State");
            msg.AddString("attr:name", PERSON_STATE);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 50);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);

            msg.AddString("attr:public_name", "Postal Code");
            msg.AddString("attr:name", PERSON_ZIP);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 50);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);

            msg.AddString("attr:public_name", "Country");
            msg.AddString("attr:name", PERSON_COUNTRY);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 120);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);

            msg.AddString("attr:public_name", "Home Phone");
            msg.AddString("attr:name", PERSON_HOME_PHONE);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 90);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);


            msg.AddString("attr:public_name", "Home Fax");
            msg.AddString("attr:name", PERSON_FAX);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 90);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);

            msg.AddString("attr:public_name", "Cell phone");
            msg.AddString("attr:name", PERSON_CELL_PHONE);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 90);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);

            msg.AddString("attr:public_name", "E-mail");
            msg.AddString("attr:name", PERSON_EMAIL);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 120);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);

            msg.AddString("attr:public_name", "Web Page");
            msg.AddString("attr:name", PERSON_URL);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 120);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);

            // Work data
            msg.AddString("attr:public_name", "Company");
            msg.AddString("attr:name", PERSON_COMPANY);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 120);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);

            msg.AddString("attr:public_name", "Work Address");
            msg.AddString("attr:name", PERSON_WORK_ADDRESS);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 120);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);

            msg.AddString("attr:public_name", "Work Address (2)");
            msg.AddString("attr:name", PERSON_WORK_ADDRESS2);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 120);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);

            msg.AddString("attr:public_name", "Work City");
            msg.AddString("attr:name", PERSON_WORK_CITY);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 90);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);

            msg.AddString("attr:public_name", "Work State");
            msg.AddString("attr:name", PERSON_WORK_STATE);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 50);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);

            msg.AddString("attr:public_name", "Work Postal Code");
            msg.AddString("attr:name", PERSON_WORK_ZIP);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 50);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);

            msg.AddString("attr:public_name", "Work Country");
            msg.AddString("attr:name", PERSON_WORK_COUNTRY);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 120);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);

            msg.AddString("attr:public_name", "Work Phone");
            msg.AddString("attr:name", PERSON_WORK_PHONE);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 90);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);


            msg.AddString("attr:public_name", "Work Fax");
            msg.AddString("attr:name", PERSON_WORK_FAX);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 90);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);

            msg.AddString("attr:public_name", "Work Cell Phone");
            msg.AddString("attr:name", PERSON_WORK_CELL);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 90);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);

            msg.AddString("attr:public_name", "Work E-mail");
            msg.AddString("attr:name", PERSON_WORK_EMAIL);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 120);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);

            msg.AddString("attr:public_name", "Work Web Address");
            msg.AddString("attr:name", PERSON_WORK_URL);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 120);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);

            msg.AddString("attr:public_name", "Pager");
            msg.AddString("attr:name", PERSON_PAGER);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 90);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);


            // Internet stuff
            msg.AddString("attr:public_name", "E-mail 3");
            msg.AddString("attr:name", PERSON_EMAIL3);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 120);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);

            msg.AddString("attr:public_name", "E-mail 4");
            msg.AddString("attr:name", PERSON_EMAIL4);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 120);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);

            msg.AddString("attr:public_name", "E-mail 5");
            msg.AddString("attr:name", PERSON_EMAIL4);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 120);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);

            msg.AddString("attr:public_name", "ICQ number");
            msg.AddString("attr:name", PERSON_ICQ);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 120);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);

            msg.AddString("attr:public_name", "AIM number");
            msg.AddString("attr:name", PERSON_AIM);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 120);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);

            msg.AddString("attr:public_name", "Jabber name");
            msg.AddString("attr:name", PERSON_JABBER);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 120);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);

            msg.AddString("attr:public_name", "Yahoo messenger");
            msg.AddString("attr:name", PERSON_YAHOO);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 120);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);

            msg.AddString("attr:public_name", "Other Web Address");
            msg.AddString("attr:name", PERSON_OTHER_URL);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 120);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);

            if(installtype==2)
            {
                // Attributes used only by Mr. Peeps!
                msg.AddString("attr:public_name", "Birthday");
                msg.AddString("attr:name", PERSON_BIRTHDAY);
                msg.AddInt32("attr:type", B_STRING_TYPE);
                msg.AddBool("attr:viewable", true);
                msg.AddBool("attr:editable", true);
                msg.AddInt32("attr:width", 50);
                msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
                msg.AddBool("attr:extra", false);

                msg.AddString("attr:public_name", "Anniversary");
                msg.AddString("attr:name", PERSON_ANNIVERSARY);
                msg.AddInt32("attr:type", B_STRING_TYPE);
                msg.AddBool("attr:viewable", true);
                msg.AddBool("attr:editable", true);
                msg.AddInt32("attr:width", 50);
                msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
                msg.AddBool("attr:extra", false);

                msg.AddString("attr:public_name", "Spouse");
                msg.AddString("attr:name", PERSON_SPOUSE);
                msg.AddInt32("attr:type", B_STRING_TYPE);
                msg.AddBool("attr:viewable", true);
                msg.AddBool("attr:editable", true);
                msg.AddInt32("attr:width", 50);
                msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
                msg.AddBool("attr:extra", false);

                msg.AddString("attr:public_name", "Children");
                msg.AddString("attr:name", PERSON_CHILDREN);
                msg.AddInt32("attr:type", B_STRING_TYPE);
                msg.AddBool("attr:viewable", true);
                msg.AddBool("attr:editable", true);
                msg.AddInt32("attr:width", 50);
                msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
                msg.AddBool("attr:extra", false);
            }

            mime.SetAttrInfo(&msg);
        }
    }
}
예제 #2
0
void
TestView::SetupTestMenu(void)
{
	// These ones will always exist. Type is the default because it's probably
	// going to be the one most used
	BMessage *msg;
	BPopUpMenu *menu = new BPopUpMenu("Test");
	
	
	// Read in the types in the MIME database which have extra attributes
	// associated with them
	
	BMimeType mime;
	BMessage types, info, attr;
	BString string;
	
	BMimeType::GetInstalledTypes(&types);
	
	int32 index = 0;
	while (types.FindString("types",index,&string) == B_OK)
	{
		index++;
		mime.SetTo(string.String());
		if (mime.GetAttrInfo(&info) != B_OK)
			continue;
		
		int32 infoindex = 0;
		BString attrName;
		BString attrPublicName;
		int32 attrType;
		
		char attrTypeName[B_MIME_TYPE_LENGTH];
		mime.GetShortDescription(attrTypeName);
		
		while (info.FindString("attr:name",infoindex,&attrName) == B_OK)
		{
			// This is where we create tests based on a particular type's "special" attributes
			
			// Just string attributes are supported for now
			if (info.FindInt32("attr:type",infoindex,&attrType) != B_OK ||
				attrType != B_STRING_TYPE ||
				info.FindString("attr:public_name",infoindex,&attrPublicName) != B_OK)
			{
				infoindex++;
				continue;
			}
			
			BMenu *submenu = GetMenu(menu,attrTypeName);
			if (!submenu)
				submenu = AddMenuSorted(menu,attrTypeName);
			
			msg = new BMessage(M_TEST_CHOSEN);
			msg->AddString("name","Attribute");
			msg->AddString("attrtype",attrName);
			msg->AddString("attrname",attrPublicName);
			msg->AddString("mimetype",string);
			msg->AddString("typename",attrTypeName);
			submenu->AddItem(new BMenuItem(attrPublicName.String(),msg));
			
			infoindex++;
		}
	}
	
	menu->AddItem(new BSeparatorItem(),0);
	
	
	// All this weirdness is to have the "standard"	tests at the top and
	// the attribute tests at the bottom with a separator in between
	BString testtype;
	int32 i = 0;
	while (fTestTypes.FindString("tests",i,&testtype) == B_OK)
		i++;
	
	i--;
	
	while (i >= 0)
	{
		fTestTypes.FindString("tests",i,&testtype);
		msg = new BMessage(M_TEST_CHOSEN);
		msg->AddString("name",testtype);
		menu->AddItem(new BMenuItem(testtype.String(),msg),0);
		i--;
	}
	
	
	menu->Archive(&fArchivedTestMenu);
	delete menu;
}