/*
 * this method is not currently being used, but it may be useful in the future...
 */
status_t
DefaultCatalog::ReadFromAttribute(const entry_ref &appOrAddOnRef)
{
	BNode node;
	status_t res = node.SetTo(&appOrAddOnRef);
	if (res != B_OK)
		return B_ENTRY_NOT_FOUND;

	attr_info attrInfo;
	res = node.GetAttrInfo(BLocaleRoster::kEmbeddedCatAttr, &attrInfo);
	if (res != B_OK)
		return B_NAME_NOT_FOUND;
	if (attrInfo.type != B_MESSAGE_TYPE)
		return B_BAD_TYPE;

	size_t size = attrInfo.size;
	auto_ptr<char> buf(new(std::nothrow) char [size]);
	if (buf.get() == NULL)
		return B_NO_MEMORY;
	res = node.ReadAttr(BLocaleRoster::kEmbeddedCatAttr, B_MESSAGE_TYPE, 0,
		buf.get(), size);
	if (res < (ssize_t)size)
		return res < B_OK ? res : B_BAD_DATA;

	BMemoryIO memIO(buf.get(), size);
	res = Unflatten(&memIO);

	return res;
}
Ejemplo n.º 2
0
Archivo: CDoc.cpp Proyecto: diversys/pe
CDoc::CDoc(const char* mimetype, BLooper *target, const entry_ref *doc)
	: fDocIO(NULL)
	, fSavePanel(NULL)
	, fMimeType(mimetype ? mimetype : "")
	, fDirty(false)
	, fReadOnly(false)
	, fEncoding(B_UNICODE_UTF8)
	, fLineEndType(kle_LF)
{
	fDocIO = new CLocalDocIO(this, doc, target);
	FailNil(fDocIO);
	if (doc)
	{
		BEntry e;
		FailOSErr(e.SetTo(doc, true));
		FailOSErr(e.GetParent(&gCWD));

		BNode node;
		FailOSErr(node.SetTo(doc));

		struct stat st;
		FailOSErr(node.GetStat(&st));

		fReadOnly = !((gUid == st.st_uid && (S_IWUSR & st.st_mode))
						||	(gGid == st.st_gid && (S_IWGRP & st.st_mode))
						||	(S_IWOTH & st.st_mode));

		char s[NAME_MAX];
		if (BNodeInfo(&node).GetType(s) == B_OK)
			fMimeType = s;
	}
	sfDocList.push_back(this);
}
Ejemplo n.º 3
0
TListItem::TListItem(BEntry *entry, bool source)
	:	BListItem()
{
	BNode		node;
	BNodeInfo	node_info;
	is_source = source;

	// try to get node info for this entry
	if ((node.SetTo(entry) == B_NO_ERROR) && (node_info.SetTo(&node) == B_NO_ERROR)) 
	{
		// cache name
		entry->GetName(fName);
		// create bitmap large enough for icon
		fIcon = new BBitmap(BRect(0, 0, B_MINI_ICON - 1, B_MINI_ICON -1 ), B_COLOR_8_BIT);
		// cache the icon
		node_info.GetTrackerIcon(fIcon, B_MINI_ICON);
		// adjust size of item to fit icon
		SetHeight(fIcon->Bounds().Height() + kITEM_MARGIN);
		// cache ref
		entry->GetRef(&fRef);
		//save = true;
	}
	else 
	{
		// no icon
		fIcon = NULL; 
		// make dummy for seperators
		strcpy(fName, " "); 
		SetHeight(kDEFAULT_ITEM_HEIGHT);
		save = true;
	}
	
	super = false;
}
Ejemplo n.º 4
0
/*!	Synchronizes the message flags/state from the server with the local
	one.
*/
void
IMAPFolder::SyncMessageFlags(uint32 uid, uint32 mailboxFlags)
{
	if (uid > LastUID())
		return;

	entry_ref ref;
	BNode node;

	while (true) {
		status_t status = GetMessageEntryRef(uid, ref);
		if (status == B_ENTRY_NOT_FOUND) {
			// The message does not exist anymore locally, delete it on the
			// server
			// TODO: copy it to the trash directory first!
			fProtocol.UpdateMessageFlags(*this, uid, IMAP::kDeleted);
			return;
		}
		if (status == B_OK)
			status = node.SetTo(&ref);
		if (status == B_TIMED_OUT) {
			// We don't know the message state yet
			fPendingFlagsMap.insert(std::make_pair(uid, mailboxFlags));
		}
		if (status != B_OK)
			return;

		break;
	}
	fSynchronizedUIDsSet.insert(uid);

	uint32 previousFlags = MessageFlags(uid);
	uint32 currentFlags = previousFlags;
	if (_MailToIMAPFlags(node, currentFlags) != B_OK)
		return;

	// Compare flags to previous/current flags, and update either the
	// message on the server, or the message locally (or even both)

	uint32 nextFlags = mailboxFlags;
	_TestMessageFlags(previousFlags, mailboxFlags, currentFlags,
		IMAP::kSeen, nextFlags);
	_TestMessageFlags(previousFlags, mailboxFlags, currentFlags,
		IMAP::kAnswered, nextFlags);

	if (nextFlags != previousFlags)
		_WriteFlags(node, nextFlags);
	if (currentFlags != nextFlags) {
		// Update mail message attributes
		BMessage attributes;
		_IMAPToMailFlags(nextFlags, attributes);
		node << attributes;

		fFlagsMap[uid] = nextFlags;
	}
	if (mailboxFlags != nextFlags) {
		// Update server flags
		fProtocol.UpdateMessageFlags(*this, uid, nextFlags);
	}
}
Ejemplo n.º 5
0
int
main(int argc, char **argv)
{
	if (argc != 2) {
		fprintf(stderr, "usage: lock_node <file>\n");
		return 1;
	}

	BNode node;
	status_t status = node.SetTo(argv[1]);
	if (status != B_OK) {
		fprintf(stderr, "lock_node: could not open \"%s\": %s\n", argv[1], strerror(status));
		return 1;
	}

	status = node.Lock();
	if (status != B_OK) {
		fprintf(stderr, "lock_node: could not lock \"%s\": %s\n", argv[1], strerror(status));
		return 1;
	}

	puts("press <enter> to continue...");
	char a[5];
	fgets(a, 5, stdin);

	node.Unlock();
	node.Unset();
	return 0;
}
Ejemplo n.º 6
0
Archivo: CDoc.cpp Proyecto: diversys/pe
void CDoc::SetMimeType(const char *type, bool updateOnDisk)
{
	fMimeType = type;

	if (updateOnDisk && EntryRef())
	{
		BNode node;
		FailOSErr(node.SetTo(EntryRef()));
		FailOSErr(BNodeInfo(&node).SetType(type));
	}
}
Ejemplo n.º 7
0
void
THeaderView::InitEmailCompletion()
{
	// get boot volume
	BVolume volume;
	BVolumeRoster().GetBootVolume(&volume);

	BQuery query;
	query.SetVolume(&volume);
	query.SetPredicate("META:email=**");
		// Due to R5 BFS bugs, you need two stars, META:email=** for the query.
		// META:email="*" will just return one entry and stop, same with
		// META:email=* and a few other variations.  Grumble.
	query.Fetch();
	entry_ref ref;

	while (query.GetNextRef (&ref) == B_OK) {
		BNode file;
		if (file.SetTo(&ref) == B_OK) {
			// Add the e-mail address as an auto-complete string.
			BString email;
			if (file.ReadAttrString("META:email", &email) >= B_OK)
				fEmailList.AddChoice(email.String());

			// Also add the quoted full name as an auto-complete string.  Can't
			// do unquoted since auto-complete isn't that smart, so the user
			// will have to type a quote mark if he wants to select someone by
			// name.
			BString fullName;
			if (file.ReadAttrString("META:name", &fullName) >= B_OK) {
				if (email.FindFirst('<') < 0) {
					email.ReplaceAll('>', '_');
					email.Prepend("<");
					email.Append(">");
				}
				fullName.ReplaceAll('\"', '_');
				fullName.Prepend("\"");
				fullName << "\" " << email;
				fEmailList.AddChoice(fullName.String());
			}

			// support for 3rd-party People apps.  Looks like a job for
			// multiple keyword (so you can have several e-mail addresses in
			// one attribute, perhaps comma separated) indices!  Which aren't
			// yet in BFS.
			for (int16 i = 2; i < 6; i++) {
				char attr[16];
				sprintf(attr, "META:email%d", i);
				if (file.ReadAttrString(attr, &email) >= B_OK)
					fEmailList.AddChoice(email.String());
			}
		}
	}
}
Ejemplo n.º 8
0
/*	WriteSetting
*	this method writes a setting to the settings file (boolean)
*/
void IOSettings::WriteSetting(const char* Setting, bool SettCont)
{
	if(!SettingsFileExists())
		CreateSettingsFile();

	BNode objNode;
	objNode.SetTo(fSettingsFile.String());
	
	if(objNode.WriteAttr(Setting, B_BOOL_TYPE, 0, (void*)&SettCont, sizeof(SettCont)) == B_FILE_ERROR)
		throw new IOSettingsException(new BString("can't write attr. to settings file (IOSettings::WriteSetting(const char* Setting, bool SettCont))"));

}
Ejemplo n.º 9
0
/*	WriteSetting
*	this method writes a setting to the settings file (strings(BString))
*/
void IOSettings::WriteSetting(const char* Setting, BString SettCont)
{
	if(!SettingsFileExists())
		CreateSettingsFile();

	BNode objNode;
	objNode.SetTo(fSettingsFile.String());
	
	if(objNode.WriteAttr(Setting, B_STRING_TYPE, 0, SettCont.String(), SettCont.Length()) == B_FILE_ERROR)
		throw new IOSettingsException(new BString("can't write attr. to settings file (IOSettings::WriteSetting(const char* Setting, BString SettCont))"));

}
Ejemplo n.º 10
0
void
IMAPFolder::_ReadFolderState()
{
	BDirectory directory(&fRef);
	BEntry entry;
	while (directory.GetNextEntry(&entry) == B_OK) {
		entry_ref ref;
		BNode node;
		if (!entry.IsFile() || entry.GetRef(&ref) != B_OK
			|| node.SetTo(&entry) != B_OK)
			continue;

		uint32 uidValidity = _ReadUniqueIDValidity(node);
		if (uidValidity != fUIDValidity) {
			// TODO: add file to mailbox
			continue;
		}
		uint32 uid = _ReadUniqueID(node);
		uint32 flags = _ReadFlags(node);

		MutexLocker locker(fLock);
		if (fQuitFolderState)
			return;

		fRefMap.insert(std::make_pair(uid, ref));
		fFlagsMap.insert(std::make_pair(uid, flags));

//		// TODO: make sure a listener exists at this point!
//		std::set<uint32>::iterator found = lastUIDs.find(uid);
//		if (found != lastUIDs.end()) {
//			// The message is still around
//			lastUIDs.erase(found);
//
//			uint32 flagsFound = MessageFlags(uid);
//			if (flagsFound != flags) {
//				// Its flags have changed locally, and need to be updated
//				fListener->MessageFlagsChanged(_Token(uid), ref,
//					flagsFound, flags);
//			}
//		} else {
//			// This is a new message
//			// TODO: the token must be the originating token!
//			uid = fListener->MessageAdded(_Token(uid), ref);
//			_WriteUniqueID(node, uid);
//		}
//
	}

	fFolderStateInitialized = true;
	mutex_unlock(&fFolderStateLock);
}
Ejemplo n.º 11
0
entry_ref* TaskFS::FileForId(Task *theTask)
{
	//**scan through all files for the ID or shell we do a querry??
	BString		fileID;
	entry_ref	*ref;
	BNode		theNode;
	
	while (tasksDir.GetNextRef(ref) == B_OK){
		theNode.SetTo(ref);
		if (theNode.ReadAttrString("META:task_id", &fileID) == B_OK)
			if (fileID==theTask->ID() && fileID.Length() != 0)
				return ref;
	}
	return NULL;
}
Ejemplo n.º 12
0
char *add_printer(char *printerName)
{
	BPath path;
	BNode folder;
	BNode* spoolFolder = NULL;
	// get spool folder
	if (find_directory(B_USER_PRINTERS_DIRECTORY, &path) == B_OK &&
		path.Append(printerName) == B_OK &&
		folder.SetTo(path.Path()) == B_OK) {
		spoolFolder = &folder;
	}

	PrinterDriverInstance instance(spoolFolder);
	return instance.GetPrinterDriver()->AddPrinter(printerName);
}
Ejemplo n.º 13
0
/*
 * this method is not currently being used, but it may be useful in the future...
 */
status_t
DefaultCatalog::ReadFromAttribute(entry_ref *appOrAddOnRef)
{
	BNode node;
	status_t res = node.SetTo(appOrAddOnRef);
	if (res != B_OK) {
		log_team(LOG_ERR,
			"couldn't find app or add-on (dev=%lu, dir=%Lu, name=%s)",
			appOrAddOnRef->device, appOrAddOnRef->directory,
			appOrAddOnRef->name);
		return B_ENTRY_NOT_FOUND;
	}

	log_team(LOG_DEBUG,
		"looking for embedded catalog-attribute in app/add-on"
		"(dev=%lu, dir=%Lu, name=%s)", appOrAddOnRef->device,
		appOrAddOnRef->directory, appOrAddOnRef->name);

	attr_info attrInfo;
	res = node.GetAttrInfo(BLocaleRoster::kEmbeddedCatAttr, &attrInfo);
	if (res != B_OK) {
		log_team(LOG_DEBUG, "no embedded catalog found");
		return B_NAME_NOT_FOUND;
	}
	if (attrInfo.type != B_MESSAGE_TYPE) {
		log_team(LOG_ERR, "attribute %s has incorrect type and is ignored!",
			BLocaleRoster::kEmbeddedCatAttr);
		return B_BAD_TYPE;
	}

	size_t size = attrInfo.size;
	auto_ptr<char> buf(new(std::nothrow) char [size]);
	if (buf.get() == NULL) {
		log_team(LOG_ERR, "couldn't allocate array of %d chars", size);
		return B_NO_MEMORY;
	}
	res = node.ReadAttr(BLocaleRoster::kEmbeddedCatAttr, B_MESSAGE_TYPE, 0,
		buf.get(), size);
	if (res < (ssize_t)size) {
		log_team(LOG_ERR, "unable to read embedded catalog from attribute");
		return res < B_OK ? res : B_BAD_DATA;
	}

	BMemoryIO memIO(buf.get(), size);
	res = Unflatten(&memIO);

	return res;
}
Ejemplo n.º 14
0
/*	isProject
* checks if an selected folder is a lava project folder.
*/
bool
ProjectTypeSelector::isProject()
{
	BNode objNode;
	BString *Project = (BString*)FileList->FirstItem();
	objNode.SetTo(Project->String());
	
	char buffer[500];
	memset(buffer, 0, sizeof(buffer));

	if(objNode.ReadAttr("LAVA:Type", B_STRING_TYPE, 0, buffer, sizeof(buffer)) == B_ENTRY_NOT_FOUND)
		return false;
	else {
		BDirectory objDir;
		objDir.SetTo(Project->String());
		if(objDir.InitCheck() != B_OK)
			return false;
		else
			return true;
	}
}
Ejemplo n.º 15
0
void
ResView::OpenFile(const entry_ref &ref)
{
	// Add all the 133t resources and attributes of the file
	BFile file(&ref, B_READ_ONLY);
	BResources resources;
	if (resources.SetTo(&file) != B_OK)
		return;
	file.Unset();
	
	resources.PreloadResourceType();
	
	int32 index = 0;
	ResDataRow *row;
	ResourceData *resData = new ResourceData();
	while (resData->SetFromResource(index, resources)) {
		row = new ResDataRow(resData);
		fListView->AddRow(row);
		fDataList.AddItem(resData);
		resData = new ResourceData();
		index++;
	}
	delete resData;

	BNode node;
	if (node.SetTo(&ref) == B_OK) {
		char attrName[B_ATTR_NAME_LENGTH];
		node.RewindAttrs();
		resData = new ResourceData();
		while (node.GetNextAttrName(attrName) == B_OK) {
			if (resData->SetFromAttribute(attrName, node)) {
				row = new ResDataRow(resData);
				fListView->AddRow(row);
				fDataList.AddItem(resData);
				resData = new ResourceData();
			}
		}
		delete resData;
	}
}
Ejemplo n.º 16
0
void PProjectWindow::OpenItem()
{
	PEntryItem *gi;
	gi = dynamic_cast<PEntryItem*>(fList->ItemAt(fList->CurrentSelection()));
	if (gi)
	{
		try
		{
			BNode node;
			FailOSErr(node.SetTo(&gi->Ref()));
			BNodeInfo info;
			FailOSErr(info.SetTo(&node));

			char mime[B_MIME_TYPE_LENGTH];

			CProjectFile* subProject
				= dynamic_cast<CProjectFile*>(gi->ModelItem());
			if (subProject) {
				if (!subProject->HasBeenParsed()) {
					subProject->Read();
					if (subProject->HasBeenParsed()) {
						list<CProjectItem*>::const_iterator iter;
						for( iter = subProject->begin();
							  iter != subProject->end(); ++iter) {
							AddItemsToList( *iter, gi);
						}
					}
				}
			} else if (info.GetType(mime) || strncmp(mime, "text/", 5))
				OpenInTracker(gi->Ref());
			else
				gApp->OpenWindow(gi->Ref());
		}
		catch (HErr& e)
		{
			e.DoError();
			gApp->OpenWindow(gi->Ref());
		}
	}
} /* PProjectWindow::OpenItem */
Ejemplo n.º 17
0
status_t HModuleRoster::LoadModule( BPath *modulePath )
{
	BNode		node;
		
	if( node.SetTo( modulePath->Path() ) == B_OK )
	{
		HModule		*module = new HModule;
		if( module->LoadModule( modulePath ) == B_OK )
		{
			moduleList.AddItem( module );
			return B_OK;
		}
		else
		{
			delete module;
			return B_ERROR;
		}
	}
	else
		return B_ERROR;
	return B_OK;
}
Ejemplo n.º 18
0
void PanelView::RescanForNewEntries()
////////////////////////////////////////////////////////////////////////
{
	BDirectory dir(m_Path.String());
	BNode node;
	node_ref noderef;

	if (dir.InitCheck()==B_OK)
	{
		BEntry entry;
		
		if (dir.GetEntry(&entry)==B_OK)
		{
			while (dir.GetNextEntry(&entry)==B_OK)
			{
				node.SetTo(&entry);	
				node.GetNodeRef(&noderef);				
				if (m_CustomListView->FindItemByNodeRef(noderef)==NULL)
					AddDirectoryEntry(&entry);
			}
		}
	}
}
Ejemplo n.º 19
0
// Add or Remove OpenTracker's Restore attribute
void SFileWorker::ModifyRestoreAttribute(const SFileList *fileList, bool add)
{
	SFile *file;
	BNode node;
	
	for(int32 i=0; i<fileList->CountItems();i++)
	{
		file=(SFile*)fileList->ItemAt(i);
		if(!file)
			continue;

		if(node.SetTo(file->Ref())!=B_OK)
			continue;
		
		if(add)
		{
			node.WriteAttr("_trk/original_path",B_STRING_TYPE,0,
				file->PathDesc(),strlen(file->PathDesc())+1);
		}
		else
			node.RemoveAttr("_trk/original_path");
	}
}
Ejemplo n.º 20
0
/*
 * this method is not currently being used, but it may be useful in the
 * future...
 */
status_t
DefaultCatalog::WriteToAttribute(entry_ref *appOrAddOnRef)
{
	BNode node;
	status_t res = node.SetTo(appOrAddOnRef);
	if (res != B_OK)
		return res;

	BMallocIO mallocIO;
	mallocIO.SetBlockSize(max(fCatMap.Size() * 20, 256L));
		// set a largish block-size in order to avoid reallocs
	res = Flatten(&mallocIO);

	if (res == B_OK) {
		ssize_t wsz;
		wsz = node.WriteAttr(BLocaleRoster::kEmbeddedCatAttr, B_MESSAGE_TYPE, 0,
			mallocIO.Buffer(), mallocIO.BufferLength());
		if (wsz < B_OK)
			res = wsz;
		else if (wsz != (ssize_t)mallocIO.BufferLength())
			res = B_ERROR;
	}
	return res;
}
bool EventFileRefFilter::Filter( const entry_ref* ref,
											BNode* node,
											struct stat_beos* st,
											const char* filetype )
{
	BString 		fileType( filetype );
	BDirectory 	testDir( ref );
	BEntry		tempEntry;
	BNode			tempNode;
	char			buffer[ B_MIME_TYPE_LENGTH ];

	// All directories are allowed - else the user won't be able to travel
	if ( testDir.InitCheck() == B_OK ) {
		return true;
	}
	
	// All Event files are allowed
	if ( fileType.IFindFirst( kEventFileMIMEType ) == 0 ) {
		return true;
	}
	
	// Symlinks are traversed and allowed only if they point to audio file
	while ( fileType.IFindFirst( "application/x-vnd.Be-symlink" ) == 0 )
	{
		if ( ( B_OK == tempEntry.SetTo( ref, true ) ) &&	// Find the entry referenced by symlink
		     ( B_OK == tempNode.SetTo( &tempEntry ) ) &&	// Access the attributes (needed to read file type)
		     ( 0 != tempNode.ReadAttr( "BEOS:TYPE", B_STRING_TYPE, 0, buffer, 255 ) ) &&
		     ( NULL != fileType.SetTo( buffer ) ) &&		// This check is really unnecessary
		     ( fileType.IFindFirst( kEventFileMIMEType ) == 0 ) )
	   {
			return true;
	   }
	}
	
	return false;	
}	// <-- end of function EventFileRefFilter::Filter
Ejemplo n.º 22
0
/*
iterate over add-on-folders and collect information about each
catalog-add-ons (types of catalogs) into fCatalogAddOnInfos.
*/
status_t
LocaleRosterData::_InitializeCatalogAddOns()
{
	BAutolock lock(fLock);
	if (!lock.IsLocked())
		return B_ERROR;

	// add info about embedded default catalog:
	CatalogAddOnInfo* defaultCatalogAddOnInfo
		= new(std::nothrow) CatalogAddOnInfo("Default", "",
			DefaultCatalog::kDefaultCatalogAddOnPriority);
	if (!defaultCatalogAddOnInfo)
		return B_NO_MEMORY;

	defaultCatalogAddOnInfo->fInstantiateFunc = DefaultCatalog::Instantiate;
	defaultCatalogAddOnInfo->fCreateFunc = DefaultCatalog::Create;
	fCatalogAddOnInfos.AddItem((void*)defaultCatalogAddOnInfo);

	BStringList folders;
	BPathFinder::FindPaths(B_FIND_PATH_ADD_ONS_DIRECTORY, "locale/catalogs/",
		B_FIND_PATH_EXISTING_ONLY, folders);

	BPath addOnPath;
	BDirectory addOnFolder;
	char buf[4096];
	status_t err;
	for (int32 f = 0; f < folders.CountStrings(); f++) {
		BString addOnFolderName = folders.StringAt(f);
		err = addOnFolder.SetTo(addOnFolderName.String());
		if (err != B_OK)
			continue;

		// scan through all the folder's entries for catalog add-ons:
		int32 count;
		int8 priority;
		entry_ref eref;
		BNode node;
		BEntry entry;
		dirent* dent;
		while ((count = addOnFolder.GetNextDirents((dirent*)buf, sizeof(buf)))
				> 0) {
			dent = (dirent*)buf;
			while (count-- > 0) {
				if (strcmp(dent->d_name, ".") != 0
						&& strcmp(dent->d_name, "..") != 0
						&& strcmp(dent->d_name, "x86") != 0
						&& strcmp(dent->d_name, "x86_gcc2") != 0) {
					// we have found (what should be) a catalog-add-on:
					eref.device = dent->d_pdev;
					eref.directory = dent->d_pino;
					eref.set_name(dent->d_name);
					entry.SetTo(&eref, true);
						// traverse through any links to get to the real thang!
					node.SetTo(&entry);
					priority = -1;
					if (node.ReadAttr(kPriorityAttr, B_INT8_TYPE, 0,
						&priority, sizeof(int8)) <= 0) {
						// add-on has no priority-attribute yet, so we load it
						// to fetch the priority from the corresponding
						// symbol...
						BString fullAddOnPath(addOnFolderName);
						fullAddOnPath << "/" << dent->d_name;
						image_id image = load_add_on(fullAddOnPath.String());
						if (image >= B_OK) {
							uint8* prioPtr;
							if (get_image_symbol(image, "gCatalogAddOnPriority",
								B_SYMBOL_TYPE_DATA,
								(void**)&prioPtr) == B_OK) {
								priority = *prioPtr;
								node.WriteAttr(kPriorityAttr, B_INT8_TYPE, 0,
									&priority, sizeof(int8));
							}
							unload_add_on(image);
						}
					}

					if (priority >= 0) {
						// add-ons with priority < 0 will be ignored
						CatalogAddOnInfo* addOnInfo
							= new(std::nothrow) CatalogAddOnInfo(dent->d_name,
								addOnFolderName, priority);
						if (addOnInfo)
							fCatalogAddOnInfos.AddItem((void*)addOnInfo);
					}
				}
				// Bump the dirent-pointer by length of the dirent just handled:
				dent = (dirent*)((char*)dent + dent->d_reclen);
			}
		}
	}
	fCatalogAddOnInfos.SortItems(CompareInfos);

	return B_OK;
}
Ejemplo n.º 23
0
void
THeaderView::InitGroupCompletion()
{
	// get boot volume
	BVolume volume;
	BVolumeRoster().GetBootVolume(&volume);

	// Build a list of all unique groups and the addresses they expand to.
	BQuery query;
	query.SetVolume(&volume);
	query.SetPredicate("META:group=**");
	query.Fetch();

	map<BString *, BString *, CompareBStrings> groupMap;
	entry_ref ref;
	BNode file;
	while (query.GetNextRef(&ref) == B_OK) {
		if (file.SetTo(&ref) != B_OK)
			continue;

		BString groups;
		if (file.ReadAttrString("META:group", &groups) < B_OK || groups.Length() == 0)
			continue;

		BString address;
		file.ReadAttrString("META:email", &address);

		// avoid adding an empty address
		if (address.Length() == 0)
			continue;

		char *group = groups.LockBuffer(groups.Length());
		char *next = strchr(group, ',');

		for (;;) {
			if (next)
				*next = 0;

			while (*group && *group == ' ')
				group++;

			BString *groupString = new BString(group);
			BString *addressListString = NULL;

			// nobody is in this group yet, start it off
			if (groupMap[groupString] == NULL) {
				addressListString = new BString(*groupString);
				addressListString->Append(" ");
				groupMap[groupString] = addressListString;
			} else {
				addressListString = groupMap[groupString];
				addressListString->Append(", ");
				delete groupString;
			}

			// Append the user's address to the end of the string with the
			// comma separated list of addresses.  If not present, add the
			// < and > brackets around the address.

			if (address.FindFirst ('<') < 0) {
				address.ReplaceAll ('>', '_');
				address.Prepend ("<");
				address.Append(">");
			}
			addressListString->Append(address);

			if (!next)
				break;

			group = next + 1;
			next = strchr(group, ',');
		}
	}

	map<BString *, BString *, CompareBStrings>::iterator iter;
	for (iter = groupMap.begin(); iter != groupMap.end();) {
		BString *group = iter->first;
		BString *addr = iter->second;
		fEmailList.AddChoice(addr->String());
		++iter;
		groupMap.erase(group);
		delete group;
		delete addr;
	}
}
/*
iterate over add-on-folders and collect information about each
catalog-add-ons (types of catalogs) into fCatalogAddOnInfos.
*/
status_t
LocaleRosterData::_InitializeCatalogAddOns()
{
	BAutolock lock(fLock);
	if (!lock.IsLocked())
		return B_ERROR;

	// add info about embedded default catalog:
	CatalogAddOnInfo* defaultCatalogAddOnInfo
		= new(std::nothrow) CatalogAddOnInfo("Default", "",
			DefaultCatalog::kDefaultCatalogAddOnPriority);
	if (!defaultCatalogAddOnInfo)
		return B_NO_MEMORY;

	defaultCatalogAddOnInfo->fInstantiateFunc = DefaultCatalog::Instantiate;
	defaultCatalogAddOnInfo->fCreateFunc = DefaultCatalog::Create;
	fCatalogAddOnInfos.AddItem((void*)defaultCatalogAddOnInfo);

	directory_which folders[] = {
		B_USER_ADDONS_DIRECTORY,
		B_COMMON_ADDONS_DIRECTORY,
		B_SYSTEM_ADDONS_DIRECTORY,
	};
	BPath addOnPath;
	BDirectory addOnFolder;
	char buf[4096];
	status_t err;
	for (uint32 f = 0; f < sizeof(folders) / sizeof(directory_which); ++f) {
		find_directory(folders[f], &addOnPath);
		BString addOnFolderName(addOnPath.Path());
		addOnFolderName << "/locale/catalogs";

		system_info info;
		if (get_system_info(&info) == B_OK
				&& (info.abi & B_HAIKU_ABI_MAJOR)
				!= (B_HAIKU_ABI & B_HAIKU_ABI_MAJOR)) {
			switch (B_HAIKU_ABI & B_HAIKU_ABI_MAJOR) {
				case B_HAIKU_ABI_GCC_2:
					addOnFolderName << "/gcc2";
					break;
				case B_HAIKU_ABI_GCC_4:
					addOnFolderName << "/gcc4";
					break;
			}
		}


		err = addOnFolder.SetTo(addOnFolderName.String());
		if (err != B_OK)
			continue;

		// scan through all the folder's entries for catalog add-ons:
		int32 count;
		int8 priority;
		entry_ref eref;
		BNode node;
		BEntry entry;
		dirent* dent;
		while ((count = addOnFolder.GetNextDirents((dirent*)buf, 4096)) > 0) {
			dent = (dirent*)buf;
			while (count-- > 0) {
				if (strcmp(dent->d_name, ".") && strcmp(dent->d_name, "..")
						&& strcmp(dent->d_name, "gcc2")
						&& strcmp(dent->d_name, "gcc4")) {
					// we have found (what should be) a catalog-add-on:
					eref.device = dent->d_pdev;
					eref.directory = dent->d_pino;
					eref.set_name(dent->d_name);
					entry.SetTo(&eref, true);
						// traverse through any links to get to the real thang!
					node.SetTo(&entry);
					priority = -1;
					if (node.ReadAttr(kPriorityAttr, B_INT8_TYPE, 0,
						&priority, sizeof(int8)) <= 0) {
						// add-on has no priority-attribute yet, so we load it
						// to fetch the priority from the corresponding
						// symbol...
						BString fullAddOnPath(addOnFolderName);
						fullAddOnPath << "/" << dent->d_name;
						image_id image = load_add_on(fullAddOnPath.String());
						if (image >= B_OK) {
							uint8* prioPtr;
							if (get_image_symbol(image, "gCatalogAddOnPriority",
								B_SYMBOL_TYPE_DATA,
								(void**)&prioPtr) == B_OK) {
								priority = *prioPtr;
								node.WriteAttr(kPriorityAttr, B_INT8_TYPE, 0,
									&priority, sizeof(int8));
							}
							unload_add_on(image);
						}
					}

					if (priority >= 0) {
						// add-ons with priority < 0 will be ignored
						CatalogAddOnInfo* addOnInfo
							= new(std::nothrow) CatalogAddOnInfo(dent->d_name,
								addOnFolderName, priority);
						if (addOnInfo)
							fCatalogAddOnInfos.AddItem((void*)addOnInfo);
					}
				}
				// Bump the dirent-pointer by length of the dirent just handled:
				dent = (dirent*)((char*)dent + dent->d_reclen);
			}
		}
	}
	fCatalogAddOnInfos.SortItems(CompareInfos);

	return B_OK;
}
Ejemplo n.º 25
0
CInfoDialog::CInfoDialog(BRect frame, const char *name, window_type type, int flags,
			BWindow *owner, BPositionIO* data)
	: HDialog(frame, name, type, flags, owner, data)
{
	fDoc = dynamic_cast<PDoc*>(owner);
	FailNil(fDoc);

	SetText("name", owner->Title());

	char s[32];
	sprintf(s, "%d", fDoc->TextView()->Size());
	SetText("docsize", s);

	sprintf(s, "%d", fDoc->TextView()->LineCount());
	SetText("lines", s);

	BMenuField *mf = dynamic_cast<BMenuField*>(FindView("mime"));
	FailNil(mf);
	fTypes = mf->Menu();

	const char *p;
	int i = 0;
	while ((p = gPrefs->GetIxPrefString(prf_X_Mimetype, i++)) != NULL)
		fTypes->AddItem(new BMenuItem(p, new BMessage(msg_FieldChanged)));

	if (i == 1)
		fTypes->AddItem(new BMenuItem("text/plain", new BMessage(msg_FieldChanged)));

	const char *mime = fDoc->MimeType();

	if (mime && mime[0])
	{
		for (i = 0; i < fTypes->CountItems(); i++)
		{
			BMenuItem *item = fTypes->ItemAt(i);
			if (strcmp(item->Label(), mime) == 0)
			{
				item->SetMarked(true);
				break;
			}
		}

		if (i == fTypes->CountItems())
		{
			fTypes->AddSeparatorItem();
			fTypes->AddItem(new BMenuItem(mime, new BMessage(msg_FieldChanged)));
			fTypes->ItemAt(fTypes->CountItems() - 1)->SetMarked(true);
		}
	}
	else
	{
		BMenuItem *item;
		fTypes->AddSeparatorItem();
		fTypes->AddItem(item = new BMenuItem("<undefined>", new BMessage(msg_FieldChanged)));
		item->SetMarked(true);
	}

	if (fDoc->EntryRef())
	{
		BNode node;
		FailOSErr(node.SetTo(fDoc->EntryRef()));

		time_t t;
		node.GetModificationTime(&t);

		char time[256];
		strcpy(time, ctime(&t));
		time[strlen(time) - 1] = 0;

		SetText("time", time);
	}
	else
	{
		//SetEnabled("mime", false);
		SetText("time", "Not Saved");
	}

	mf = dynamic_cast<BMenuField*>(FindView("font"));
	FailNil(mf);

	fMenu = mf->Menu();
	FailNil(fMenu);

	font_family ff;
	font_style fs;

	for (int i = 0; i < count_font_families(); i++)
	{
		get_font_family(i, &ff);
		BMenu *fontItem = new BMenu(ff);
		FailNil(fontItem);
		fMenu->AddItem(new BMenuItem(fontItem, new BMessage(msg_FieldChanged)));
		fontItem->SetFont(be_plain_font);

		for (int j = 0; j < count_font_styles(ff); j++)
		{
			get_font_style(ff, j, &fs);

			BMessage *msg = new BMessage(msg_FieldChanged);
			msg->AddString("family", ff);
			msg->AddString("style", fs);
			fontItem->AddItem(new BMenuItem(fs, msg));
		}
	}

	fMenu->SetRadioMode(true);

	mf = dynamic_cast<BMenuField*>(FindView("encoding"));
	FailNil(mf);
	fEncoding = mf->Menu();
	FailNil(fEncoding);
	fEncoding->SetRadioMode(true);

	mf = dynamic_cast<BMenuField*>(FindView("source encoding"));
	FailNil(mf);
	fSourceEncoding = mf->Menu();
	FailNil(fSourceEncoding);
	fSourceEncoding->SetRadioMode(true);

	mf = dynamic_cast<BMenuField*>(FindView("linebreaks"));
	FailNil(mf);
	fLineBreaks = mf->Menu();
	FailNil(fLineBreaks);
	fLineBreaks->SetRadioMode(true);

	BTextControl *tc = dynamic_cast<BTextControl*>(FindView("tabs"));
	if (tc) tc->SetDivider(be_plain_font->StringWidth(tc->Label()) + 4);

	BMenu *lang;
	mf = dynamic_cast<BMenuField*>(FindView("language"));
	FailNil(mf);
	lang = mf->Menu();

	CLanguageInterface *intf;
	int cookie = 0;
	while ((intf = CLanguageInterface::NextIntf(cookie)) != NULL)
		lang->AddItem(new BMenuItem(intf->Name(), new BMessage(msg_FieldChanged)));

	lang->SetRadioMode(true);
	int curLang = fDoc->TextView()->Language();
	SetValue("language", curLang >= 0 ? curLang + 3 : 1);

	CancelClicked();
} /* CInfoDialog::CInfoDialog */
Ejemplo n.º 26
0
status_t
RunPopUpMenu(BPoint where, BString &header, BString &fileName, 
	CLanguageInterface *languageInterface)
{
	status_t err;
	BPath path;
	BDirectory dir;
	err = GetSettingsDir(dir, path);
	err = B_ERROR;
	BPopUpMenu *menu = BuildPopUp(dir);
	if (menu == NULL)
		return B_ERROR;
	
	BMenuItem *item = menu->Go(where, false, true);
	//if (item && item->Message())
	//	item->Message()->PrintToStream();

	switch ((item && item->Message()) ? item->Message()->what : 0)
	{
		case 'head':
		{
			if (item->Message()->FindString("template", &header) < B_OK)
				break;
			BString tmp;
			time_t now = time(NULL);
			struct tm *tim = localtime(&now);
			// date
			char *p;
			p = tmp.LockBuffer(100);
			memset(p, 0, 100);
			strftime(p, 100, "%Y-%m-%d", tim);
			tmp.UnlockBuffer();
			header.ReplaceAll("%DATE%", tmp.String());
			tmp.Truncate(0);
			
			p = tmp.LockBuffer(100);
			memset(p, 0, 100);
			strftime(p, 100, "%T", tim);
			tmp.UnlockBuffer();
			header.ReplaceAll("%TIME%", tmp.String());
			tmp.Truncate(0);

			// year
			p = tmp.LockBuffer(10);
			memset(p, 0, 10);
			strftime(p, 10, "%Y", tim);
			tmp.UnlockBuffer();
			header.ReplaceAll("%YEAR%", tmp.String());
			tmp.Truncate(0);

			// fetch from query on META:email==** ?
			p = tmp.LockBuffer(B_PATH_NAME_LENGTH);
			memset(p, 0, B_PATH_NAME_LENGTH);
			err = dir.ReadAttr("pe:author_people", B_STRING_TYPE, 0LL, p, 
				B_PATH_NAME_LENGTH);
			tmp.UnlockBuffer();
			//printf("ppl:%s\n", tmp.String());
			BNode people;
			if (err > 0)
				people.SetTo(tmp.String());
			tmp.Truncate(0);
			
			BString attr;

			static struct {
				const char *tmplName;
				const char *attrName;
			} attrMap[] = {
				{ "%AUTHOR%", "META:name" },
				{ "%AUTHORMAIL%", "META:email" },
				{ "%COMPANY%", "META:company" },
				{ "%AUTHORURL%", "META:url" },
				{ NULL, NULL }
			};
			int i;

			for (i = 0; attrMap[i].tmplName; i++)
			{
				p = attr.LockBuffer(256);
				memset(p, 0, 256);
				err = people.ReadAttr(attrMap[i].attrName, B_ANY_TYPE, 
					0LL, p, 256);
				//printf("ReadAttr: %d, %s\n", err, attr.String());
				attr.UnlockBuffer();

				tmp << attr;
				header.ReplaceAll(attrMap[i].tmplName, tmp.String());
				tmp.Truncate(0);
				attr.Truncate(0);
			}

			BString fileNameNoExt(fileName);
			if (fileNameNoExt.FindLast('.') > -1)
				fileNameNoExt.Truncate(fileNameNoExt.FindLast('.'));
			header.ReplaceAll("%FILENAMENOEXT%", fileNameNoExt.String());
			header.ReplaceAll("%FILENAME%", fileName.String());
			/*
			tmp << "Haiku";
			header.ReplaceAll("%PROJECT%", tmp.String());
			tmp.Truncate(0);
			*/

			// better values for C++
			BString language("C/C++");
			BString commentLineStart("/*");
			BString commentLineEnd("");
			BString commentBlockStart("/*");
			BString commentBlockCont(" *");
			BString commentBlockLazy("");
			BString commentBlockLineEnd("");
			BString commentBlockEnd(" */");
			if (languageInterface)
			{
				// if not C++
				if (language != languageInterface->Name())
				{
					language = languageInterface->Name();
					commentLineStart = languageInterface->LineCommentStart();
					commentLineEnd = languageInterface->LineCommentEnd();
					// I'd miss a CommentCanSpanLines()
					// let's assume line end means can span
					if (commentLineEnd.Length())
					{
						commentBlockStart = commentLineStart;
						commentBlockCont = "";
						commentBlockLazy = "";
						commentBlockLineEnd = "";
						commentBlockEnd = commentLineEnd;
					}
					else
					{
						commentBlockStart = commentLineStart;
						commentBlockCont = commentLineStart;
						commentBlockLazy = commentLineStart;
						commentBlockLineEnd = commentLineEnd;
						commentBlockEnd = commentLineStart;
					}
					/*
					printf("LANG:'%s' CS:'%s' CE:'%s'\n", 
						language.String(), 
						commentLineStart.String(), 
						commentLineEnd.String());
					*/
				}
			}
			// comment start
			header.ReplaceAll("%COMMS%", commentBlockStart.String());
			// comment cont'd
			header.ReplaceAll("%COMMC%", commentBlockCont.String());
			// comment cont'd lazy (blank if possible)
			header.ReplaceAll("%COMML%", commentBlockLazy.String());
			// comment end
			header.ReplaceAll("%COMME%", commentBlockEnd.String());
			// comment line end
			commentBlockLineEnd << "\n";
			header.ReplaceAll("\n", commentBlockLineEnd.String());


			err = B_OK;
			break;
		}
		case 'optf':
		{
			const char *args[] = {path.Path(), NULL};
			err = be_roster->Launch(sTrackerSig, 1, (char **)args);
			//printf("err %s\n", strerror(err));
			err = B_CANCELED;
			break;
		}
		case 'seta':
		{
			MimeRefFilter filter("application/x-person");
			BPath path;
			entry_ref people;

			if (find_directory(B_USER_DIRECTORY, &path) == B_OK)
			{
				path.Append("people");
				get_ref_for_path(path.Path(), &people);
			}

			BFilePanel *panel;
			panel = new BFilePanel(B_OPEN_PANEL, NULL, &people,
				B_FILE_NODE, false, NULL, &filter);
			// trick to synchronously use BFilePanel
			PanelHandler *handler = new PanelHandler;
			if (panel->Window()->Lock())
			{
				panel->Window()->AddHandler(handler);
				panel->Window()->Unlock();
			}
			panel->SetTarget(BMessenger(handler));
			panel->Show();
			if (handler->Wait() < B_OK)
				break;
			if (!handler->Message())
				break;
			if (handler->Message()->what == B_CANCEL)
				break;
			entry_ref ref;
			//panel->Message()->PrintToStream();
			if (panel->GetNextSelectedRef(&ref) == B_OK)
			{
				//printf("ref:%s\n", ref.name);
				path.SetTo(&ref);
				dir.WriteAttr("pe:author_people", B_STRING_TYPE, 0LL, 
					path.Path(), strlen(path.Path()));
			}
			delete panel;
			delete handler;
			err = B_CANCELED;
			break;
		}
		case B_ABOUT_REQUESTED:
		{
			BString tmpPath("/tmp/Pe-HeaderHeader-About-");
			tmpPath << system_time() << "-" << getpid() << ".txt";
			entry_ref ref;
			get_ref_for_path(tmpPath.String(), &ref);
			{
				BFile f(&ref, B_CREATE_FILE | B_WRITE_ONLY);
				err = f.InitCheck();
				if (err < 0)
					break;
				f.Write(sAboutText, strlen(sAboutText));
				f.SetPermissions(0444);
			}
			BMessage msg(B_REFS_RECEIVED);
			msg.AddRef("refs", &ref);
			err = be_app_messenger.SendMessage(&msg);
			err = B_CANCELED;
			break;
		}
		case 0:
			err = B_CANCELED;
			break;
		default:
			break;
	}
	delete menu;
	return err;
}
Ejemplo n.º 27
0
status_t HModuleRoster::HandleRequest( RequestPB *pb )
{
	BEntry		entry;
	BNode		node;
	BNodeInfo	info;
	char		mimeType[128], vmimeType[128];
	status_t 	status = B_OK;
	int32		parentCount = 0;
	BPath 		absPath, resourcePath( "/" );
	resourcePath.Append( pb->brURI->path );
	pb->resourcePath = &resourcePath;
	pb->mimeType = mimeType;
	
	
	// fix for "hostname//" request crash
	// wade majors <[email protected] - Mar-09-2001
    if (resourcePath.Path() == NULL)
    {
      resourcePath.SetTo("null");
      pb->resourcePath = &resourcePath;
    }
    //
	
	
	VResource	*vres = NULL;
		
	// *****
	// Look for "real" resource
	// *****
	do
	{
		// Small optimization... if not done, the path normalizer will 
		// be tickled when a resource does not exit
		if( (resourcePath.Path())[1] == 0 )
		{
			status = B_ERROR;
			break;
		}
		absPath.SetTo( pb->webDirectory->Path(), resourcePath.Path()+1 );

		if( (entry.SetTo( absPath.Path(), true ) == B_OK)&&(node.SetTo( &entry ) == B_OK)
		&&(info.SetTo( &node ) == B_OK) )
		{
			const char *resMIME;
			
			// Cheap hack for directories without a MIME type
			if(info.GetType( mimeType ) != B_OK)
				strcpy( mimeType, "application/x-vnd.Be-directory" );
				
			if( (resMIME = pb->vresources->MatchVRes( pb->brURI->path, true, &vres )) )
				strcpy( vmimeType, resMIME );
			else
				strcpy( vmimeType, mimeType );
			break;
		}
		parentCount++;
		
	}while( (status = resourcePath.GetParent( &resourcePath )) == B_OK );
	entry.Unset();
	if( node.InitCheck() )
		node.Unset();
	// *****
	// Look for Virtual Resource if no "real" resource was found.
	// *****
	
	if( (status != B_OK)||((parentCount != 0)&&(strcmp(mimeType, "application/x-vnd.Be-directory") == 0)) )
	{
		const char *resMIME;
		if( (resMIME = pb->vresources->MatchVRes( pb->brURI->path, false, &vres )) )
		{
			strcpy( vmimeType, resMIME );
			strcpy( mimeType, resMIME );
		}
		else
		{
			HTTPResponse	response;
			response.SetHTMLMessage( 404 ); // Not Found
			pb->request->SendReply( &response );
			return B_ERROR;
		}
	}
	
	// *****
	// Find handler module for resource
	// *****
	
	HModule		*module, *prefModule = NULL;
	int32		priority, highestPriority = 0;
	for( int32 i=0; (module = (HModule *)moduleList.ItemAt(i)); i++ )
	{
		if( module->CanHandleResource( vmimeType, pb->request->GetMethod(), &priority )&&
			(priority > highestPriority) )
		{
			highestPriority = priority;
			prefModule = module;
		}
	}
	
	// *****
	// Setup PB
	// *****
	pb->HandleRequest = HModuleRoster::HandleRequest;
	pb->Logprintf = log_printf;
	pb->moduleList = &moduleList;
	if( vres )
	{
		pb->authenticate = vres->Authenticate();
		pb->extras = &vres->extras;
	}
	else
		pb->extras = NULL;
	
	// *****
	// Invoke Handler Module to handle the request
	// *****
	if( highestPriority > 0 )
	{
		status = prefModule->HandleRequest( pb );
		return status;
	}
	else // No handler found... send error
	{
		HTTPResponse	response;
		response.SetHTMLMessage( 501 ); // Not Implemented
		pb->request->SendReply( &response );
		return B_ERROR;
	}
	return B_OK;
}
Ejemplo n.º 28
0
/*	ReadSetting
*	this method can read attributes from a File, just give the name of the
*	attribute to the method (const char) and it returns a pointer to the content of the attribute.
*	It's importent that you know the type of the content because the method returns
* 	a void pointer and you have to make a typ caste to the return value to the expected
*	type of the attribute.
*	If there are errors the method throws exceptions
*/
void
*IOSettings::ReadSetting(const char* Setting)
{
	if(!SettingsFileExists())
		CreateSettingsFile();

	BNode objNode;
	char buffer[500];
	attr_info info;
	memset(buffer, 0, sizeof(buffer));

	//content pointer
	BString *strCont;
	int32 *int32Cont;
	int64 *int64Cont;
	double *dbCont;
	bool *blCont;
	
	objNode.SetTo(fSettingsFile.String());
	objNode.GetAttrInfo(Setting, &info);	
	switch(info.type)
	{
		case B_STRING_TYPE:
		{
			if(objNode.ReadAttr(Setting, info.type, 0, buffer, sizeof(buffer)) == B_ENTRY_NOT_FOUND)
				throw new IOSettingsException(new BString("an Attr. doesn't exsist by some folder (LavaProjectManager::_readPorject)"));
			
			strCont = new BString(buffer);
			return strCont;
		}
		break;
		case B_INT32_TYPE:
		{
			int32Cont = new int32();
			if(objNode.ReadAttr(Setting, info.type, 0, int32Cont, sizeof(int32Cont)) == B_ENTRY_NOT_FOUND)
				throw new IOSettingsException(new BString("an Attr. doesn't exsist by some folder (LavaProjectManager::_readPorject)"));
				
			return int32Cont;
		}
		break;
		case B_INT64_TYPE:
		{
			int64Cont = new int64();
			if(objNode.ReadAttr(Setting, info.type, 0, int64Cont, sizeof(int64Cont)) == B_ENTRY_NOT_FOUND)
				throw new IOSettingsException(new BString("an Attr. doesn't exsist by some folder (LavaProjectManager::_readPorject)"));
			
			return int64Cont;
		}
		break;
		case B_DOUBLE_TYPE:
		{
			dbCont = new double();
			if(objNode.ReadAttr(Setting, info.type, 0, dbCont, sizeof(dbCont)) == B_ENTRY_NOT_FOUND)
				throw new IOSettingsException(new BString("an Attr. doesn't exsist by some folder (LavaProjectManager::_readPorject)"));

			return dbCont;
		}
		break;
		case B_BOOL_TYPE:
		{
			blCont = new bool();
			if(objNode.ReadAttr(Setting, info.type, 0, blCont, sizeof(blCont)) == B_ENTRY_NOT_FOUND)
				throw new IOSettingsException(new BString("an Attr. doesn't exsist by some folder (LavaProjectManager::_readPorject)"));

			return blCont;
		}
		break;
		default:
			throw new IOSettingsException(new BString("not supported attribute type was read"));
		break;
	}
}
Ejemplo n.º 29
0
void
MailDaemonApp::SendPendingMessages(BMessage* msg)
{
	BVolumeRoster roster;
	BVolume volume;

	map<int32, send_mails_info> messages;


	int32 account = -1;
	if (msg->FindInt32("account", &account) != B_OK)
		account = -1;

	if (!msg->HasString("message_path")) {
		while (roster.GetNextVolume(&volume) == B_OK) {
			BQuery query;
			query.SetVolume(&volume);
			query.PushAttr(B_MAIL_ATTR_FLAGS);
			query.PushInt32(B_MAIL_PENDING);
			query.PushOp(B_EQ);

			query.PushAttr(B_MAIL_ATTR_FLAGS);
			query.PushInt32(B_MAIL_PENDING | B_MAIL_SAVE);
			query.PushOp(B_EQ);

			if (account >= 0) {
				query.PushAttr(B_MAIL_ATTR_ACCOUNT_ID);
				query.PushInt32(account);
				query.PushOp(B_EQ);
				query.PushOp(B_AND);
			}

			query.PushOp(B_OR);
			query.Fetch();
			BEntry entry;
			while (query.GetNextEntry(&entry) == B_OK) {
				if (_IsEntryInTrash(entry))
					continue;

				BNode node;
				while (node.SetTo(&entry) == B_BUSY)
					snooze(1000);
				if (!_IsPending(node))
					continue;

				int32 messageAccount;
				if (node.ReadAttr(B_MAIL_ATTR_ACCOUNT_ID, B_INT32_TYPE, 0,
					&messageAccount, sizeof(int32)) < 0)
					messageAccount = -1;

				off_t size = 0;
				node.GetSize(&size);
				entry_ref ref;
				entry.GetRef(&ref);

				messages[messageAccount].files.push_back(ref);
				messages[messageAccount].totalSize += size;
			}
		}
	} else {
		const char* path;
		if (msg->FindString("message_path", &path) != B_OK)
			return;

		off_t size = 0;
		if (BNode(path).GetSize(&size) != B_OK)
			return;
		BEntry entry(path);
		entry_ref ref;
		entry.GetRef(&ref);

		messages[account].files.push_back(ref);
		messages[account].totalSize += size;
	}

	map<int32, send_mails_info>::iterator iter = messages.begin();
	for (; iter != messages.end(); iter++) {
		OutboundProtocolThread* protocolThread = _FindOutboundProtocol(
			iter->first);
		if (!protocolThread)
			continue;

		send_mails_info& info = iter->second;
		if (info.files.size() == 0)
			continue;

		MailProtocol* protocol = protocolThread->Protocol();

		protocolThread->Lock();
		protocol->SetTotalItems(info.files.size());
		protocol->SetTotalItemsSize(info.totalSize);
		protocolThread->Unlock();

		protocolThread->SendMessages(iter->second.files, info.totalSize);
	}
}
Ejemplo n.º 30
0
void
QPopupMenu::EntryCreated(const entry_ref &ref, ino_t node)
{
	BNode file;
	if (file.SetTo(&ref) < B_OK)
		return;

	// Make sure the pop-up menu is ready for additions.  Need a bunch of
	// groups at the top, a divider line, and miscellaneous people added below
	// the line.

	int32 items = CountItems();
	if (!items)
		AddSeparatorItem();

	// Does the file have a group attribute?  OK to have none.
	BString groups;
	const char *kNoGroup = "NoGroup!";
	file.ReadAttrString("META:group", &groups);
	if (groups.Length() <= 0)
		groups = kNoGroup;

	// Add the e-mail address to the all people group.  Then add it to all the
	// group menus that it exists in (based on the comma separated list of
	// groups from the People file), optionally making the group menu if it
	// doesn't exist.  If it's in the special NoGroup!  list, then add it below
	// the groups.

	bool allPeopleGroupDone = false;
	BMenu *groupMenu;
	do {
		BString group;

		if (!allPeopleGroupDone) {
			// Create the default group for all people, if it doesn't exist yet.
			group = "All People";
			allPeopleGroupDone = true;
		} else {
			// Break out the next group from the comma separated string.
			int32 comma;
			if ((comma = groups.FindFirst(',')) > 0) {
				groups.MoveInto(group, 0, comma);
				groups.Remove(0, 1);
			} else
				group.Adopt(groups);
		}

		// trim white spaces
		int32 i = 0;
		for (i = 0; isspace(group.ByteAt(i)); i++) {}
		if (i)
			group.Remove(0, i);
		for (i = group.Length() - 1; isspace(group.ByteAt(i)); i--) {}
		group.Truncate(i + 1);

		groupMenu = NULL;
		BMenuItem *superItem = NULL; // Corresponding item for group menu.

		if (group.Length() > 0 && group != kNoGroup) {
			BMenu *sub;

			// Look for submenu with label == group name
			for (int32 i = 0; i < items; i++) {
				if ((sub = SubmenuAt(i)) != NULL) {
					superItem = sub->Superitem();
					if (!strcmp(superItem->Label(), group.String())) {
						groupMenu = sub;
						i++;
						break;
					}
				}
			}

			// If no submenu, create one
			if (!groupMenu) {
				// Find where it should go (alphabetical)
				int32 mindex = 0;
				for (; mindex < fGroups; mindex++) {
					if (strcmp(ItemAt(mindex)->Label(), group.String()) > 0)
						break;
				}

				groupMenu = new BMenu(group.String());
				groupMenu->SetFont(be_plain_font);
				AddItem(groupMenu, mindex);

				superItem = groupMenu->Superitem();
				superItem->SetMessage(new BMessage(B_SIMPLE_DATA));
				if (fTargetHandler)
					superItem->SetTarget(fTargetHandler);

				fGroups++;
			}
		}

		BString	name;
		file.ReadAttrString("META:name", &name);

		BString email;
		file.ReadAttrString("META:email", &email);

		if (email.Length() != 0 || name.Length() != 0)
			AddPersonItem(&ref, node, name, email, NULL, groupMenu, superItem);

		// support for 3rd-party People apps
		for (int16 i = 2; i < 6; i++) {
			char attr[16];
			sprintf(attr, "META:email%d", i);
			if (file.ReadAttrString(attr, &email) >= B_OK && email.Length() > 0)
				AddPersonItem(&ref, node, name, email, attr, groupMenu, superItem);
		}
	} while (groups.Length() > 0);
}