Example #1
0
// _BindExtraMedia() searches additional videos and audios
// and addes them as extra medias.
/*static*/ void
Playlist::_BindExtraMedia(PlaylistItem* item)
{
	FilePlaylistItem* fileItem = dynamic_cast<FilePlaylistItem*>(item);
	if (!fileItem)
		return;
	
	// If the media file is foo.mp3, _BindExtraMedia() searches foo.avi.
	BPath mediaFilePath(&fileItem->Ref());
	BString mediaFilePathString = mediaFilePath.Path();
	BPath dirPath;
	mediaFilePath.GetParent(&dirPath);
	BDirectory dir(dirPath.Path());
	if (dir.InitCheck() != B_OK)
		return;
	
	BEntry entry;
	BString entryPathString;
	while (dir.GetNextEntry(&entry, true) == B_OK) {
		if (!entry.IsFile())
			continue;
		entryPathString = BPath(&entry).Path();
		if (entryPathString != mediaFilePathString
				&& _GetExceptExtension(entryPathString) == _GetExceptExtension(mediaFilePathString)) {
			_BindExtraMedia(fileItem, entry);
		}
	}
}
Example #2
0
/***********************************************************
 * SetFrom
 ***********************************************************/
void
HAddressView::SetFrom(const char* in_address)
{
	if( ::strlen(in_address) == 0)
		return;
	BString address(in_address);
	
	// Compare existing accounts	
	char name[B_FILE_NAME_LENGTH];
	BPath path;
	::find_directory(B_USER_SETTINGS_DIRECTORY,&path);
	path.Append(APP_NAME);
	path.Append("Accounts");
	BDirectory dir(path.Path());
	status_t err = B_OK;
	BEntry entry;
	bool changed = false;
	
	while(err == B_OK)
	{
		if( (err = dir.GetNextEntry(&entry)) != B_OK  )
			break;
		BFile file(&entry,B_READ_ONLY);
		if(file.InitCheck() == B_OK && entry.IsFile())
		{
			BMessage msg;
			msg.Unflatten(&file);
			BString myAddress;
			PRINT(("%s\n",in_address));
			if(msg.FindString("address",&myAddress) != B_OK)
				myAddress = "";
			// Change account
			if(address.FindFirst(myAddress) != B_ERROR)
			{
				entry.GetName(name);	
				ChangeAccount(name);
				// Set From menu
				BMenuField *field = cast_as(FindView("FromMenu"),BMenuField);
				BMenu *menu = field->Menu();
				BMenuItem *item = menu->FindItem(name);
				if(item)
					item->SetMarked(true);
				changed=true;
				break;
			}
		}
	}
	
	if(!changed && cast_as(Window()->FindView("HMailView"),BTextView))
	{
		BMenuField *field = cast_as(FindView("FromMenu"),BMenuField);
		BMenuItem *item(NULL);
		item = field->Menu()->FindMarked();
		if(item)
		{
			ChangeAccount(item->Label());
			item->SetMarked(true);	
		}
	}
}
Example #3
0
void
LiveQuery::_PerformQuery(BQuery& query)
{
	status_t status = query.Fetch();
	if (status != B_OK) {
		fprintf(stderr, "%s: bad query expression\n", kProgramName);
		return;
	}

	int32 count = 0;

	BEntry entry;
	BPath path;
	while (query.GetNextEntry(&entry) == B_OK) {
		if (sFilesOnly && !entry.IsFile())
			continue;

		if (entry.GetPath(&path) != B_OK) {
			fprintf(stderr, "%s: could not get path for entry\n", kProgramName);
			continue;
		}

		printf("%s\n", sEscapeMetaChars ? BString().CharacterEscape(
				path.Path(), " ()?*&\"'[]^\\~|;!<>*$\t", '\\').String()
			: path.Path());

		count++;
	}

	printf("FOUND %ld entries\n", count);
}
Example #4
0
void
ModuleManager::_FindModules(BDirectory &dir, const char *moduleDir,
	const char *suffix, module_name_list *list)
{
	BEntry entry;
	while (dir.GetNextEntry(&entry) == B_OK) {
		if (entry.IsFile()) {
			ModuleAddOn addon;
			BPath path;
			if (entry.GetPath(&path) == B_OK
				&& addon.Load(path.Path(), moduleDir) == B_OK) {
				module_info **infos = addon.ModuleInfos();
				for (int32 i = 0; infos[i]; i++) {
					if (infos[i]->name
						&& _MatchSuffix(infos[i]->name, suffix))
						list->names.insert(infos[i]->name);
				}
			}
		} else if (entry.IsDirectory()) {
			BDirectory subdir;
			if (subdir.SetTo(&entry) == B_OK)
				_FindModules(subdir, moduleDir, suffix, list);
		}
	}
}
Example #5
0
void InfoStrView::SetPath (const char *path)
{
	/* Store the given directory path in "itemPath". If the path is that of a file, it normalizes the path
		and gets its parent folder path and stores it in "itemPath"
		TODO: Accept a bool parameter "isFolder" to overcome the problem specified in the "else" part */
	DeAllocPath();
		
	BEntry entry (path, false);				/* Question: Must we traverse the link here ?? */
	if (entry.Exists() == true)
	{
		if (entry.IsFile() || entry.IsSymLink())
		{
			BEntry parentDir;
			entry.GetParent (&parentDir);
			
			BPath dirPath;
			parentDir.GetPath (&dirPath);
			AllocPath (dirPath.Path());
		}
		else								/* Means it's a directory */
		{
			AllocPath (path);
		}
	}
	else									/* Problem: Assume its a file NOT a directory */
	{
		BPath parentPath;
		BPath dirPath (path);
		dirPath.GetParent (&parentPath);
		
		AllocPath (parentPath.Path());
	}
}
void BMailRemoteStorageProtocol::SyncMailbox(const char *mailbox) {
	BPath path(runner->Chain()->MetaData()->FindString("path"));
	path.Append(mailbox);
	
	BDirectory folder(path.Path());
	
	BEntry entry;
	BFile snoodle;
	BString string;
	uint32 chain;
	bool append;
	
	while (folder.GetNextEntry(&entry) == B_OK) {
		if (!entry.IsFile())
			continue;
		while (snoodle.SetTo(&entry,B_READ_WRITE) == B_BUSY) snooze(100);
		append = false;
		
		while (snoodle.Lock() != B_OK) snooze(100);
		snoodle.Unlock();
		
		if (snoodle.ReadAttr("MAIL:chain",B_INT32_TYPE,0,&chain,sizeof(chain)) < B_OK)
			append = true;
		if (chain != runner->Chain()->ID())
			append = true;
		if (snoodle.ReadAttrString("MAIL:unique_id",&string) < B_OK)
			append = true;

		BString folder(string), id("");
		int32 j = string.FindLast('/');
		if ((!append) && (j >= 0)) {
			folder.Truncate(j);
			string.CopyInto(id,j + 1,string.Length());
			if (folder == mailbox)
				continue;
		} else {
			append = true;
		}
		
		if (append)
			AddMessage(mailbox,&snoodle,&id); //---We should check for partial messages here
		else
			CopyMessage(folder.String(),mailbox,&id);
			
		string = mailbox;
		string << '/' << id;
		/*snoodle.RemoveAttr("MAIL:unique_id");
		snoodle.RemoveAttr("MAIL:chain");*/
		chain = runner->Chain()->ID();
		snoodle.WriteAttr("MAIL:chain",B_INT32_TYPE,0,&chain,sizeof(chain));
		snoodle.WriteAttrString("MAIL:unique_id",&string);
		(*manifest) += string.String();
		(*unique_ids) += string.String();
		string = runner->Chain()->Name();
		snoodle.WriteAttrString("MAIL:account",&string);
	}
}
Example #7
0
// --------------------------------------------------
status_t
Fonts::LookupFontFiles(BPath path)
{
	BDirectory 	dir(path.Path());
	BEntry 		entry;

	if (dir.InitCheck() != B_OK)
		return B_ERROR;

	dir.Rewind();
	while (dir.GetNextEntry(&entry) >= 0) {
		BPath 		name;
		char 		fn[512];
		font_type	ft = unknown_type; // to keep the compiler silent.
		off_t 		size;
		status_t	status;
		
		entry.GetPath(&name);
		if (entry.IsDirectory())
			// recursivly lookup in sub-directories...
			LookupFontFiles(name);

		if (! entry.IsFile())
			continue;

		fn[0] = 0;
		ft = unknown_type;
				
		// is it a truetype file?
		status = ttf_get_fontname(name.Path(), fn, sizeof(fn));
		if (status == B_OK ) {
			ft = true_type_type;
		} else {
			// okay, maybe it's a postscript type file?
			status = psf_get_fontname(name.Path(), fn, sizeof(fn));
			if (status == B_OK) {
				ft = type1_type;
			}
		} 

		if (ft == unknown_type)
			// not a font file...
			continue;
										
		if (entry.GetSize(&size) != B_OK)
			size = 1024*1024*1024;
		
		REPORT(kDebug, -1, "Installed font %s -> %s", fn, name.Path());			
		fFontFiles.AddItem(new FontFile(fn, name.Path(), size, ft, size < 100*1024));
	}	// while dir.GetNextEntry()...	

	return B_OK;
}
Example #8
0
FileInfo*
Scanner::_GetFileInfo(BDirectory* dir, FileInfo* parent)
{
	FileInfo* thisDir = new FileInfo;
	BEntry entry;
	dir->GetEntry(&entry);
	entry.GetRef(&thisDir->ref);
	thisDir->parent = parent;
	thisDir->count = 0;

	while (true) {
		if (fQuitRequested) {
			delete thisDir;
			return NULL;
		}

		if (dir->GetNextEntry(&entry) == B_ENTRY_NOT_FOUND)
			break;
		if (entry.IsSymLink())
			continue;

		if (entry.IsFile()) {
			FileInfo *child = new FileInfo;
			entry.GetRef(&child->ref);
			entry.GetSize(&child->size);
			child->parent = thisDir;
			child->color = -1;
			thisDir->children.push_back(child);

			// Send a progress report periodically.
			fVolumeBytesScanned += child->size;
			fProgress = (float)fVolumeBytesScanned / fVolumeBytesInUse;
			if (fProgress - fLastReport > kReportInterval) {
				fLastReport = fProgress;
				fListener.SendMessage(&fProgressMessage);
			}
		}
		else if (entry.IsDirectory()) {
			BDirectory childDir(&entry);
			thisDir->children.push_back(_GetFileInfo(&childDir, thisDir));
		}
		thisDir->count++;
	}

	vector<FileInfo *>::iterator i = thisDir->children.begin();
	while (i != thisDir->children.end()) {
		thisDir->size += (*i)->size;
		thisDir->count += (*i)->count;
		i++;
	}

	return thisDir;
}
Example #9
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);
}
Example #10
0
status_t
ModuleManager::_GetAddOn(const char *name, ModuleAddOn **_addon)
{
	// search list first
	for (int32 i = 0; ModuleAddOn *addon = fAddOns.ItemAt(i); i++) {
		BString addonName(addon->Name());
		addonName << "/";
		if (!strcmp(name, addon->Name())
			|| !strncmp(addonName.String(), name, addonName.Length())) {
			addon->Get();
			*_addon = addon;
			return B_OK;
		}
	}
	// not in list yet, load from disk
	// iterate through module dirs
	for (int32 i = 0; gModuleDirs[i]; i++) {
		BPath path;
		if (path.SetTo(gModuleDirs[i]) == B_OK
			&& path.SetTo(path.Path(), name) == B_OK) {
			BEntry entry;
			for (;;) {
				if (entry.SetTo(path.Path()) == B_OK && entry.Exists()) {
					// found an entry: if it is a file, try to load it
					if (entry.IsFile()) {
						ModuleAddOn *addon = new ModuleAddOn;
						if (addon->Load(path.Path(), gModuleDirs[i]) == B_OK) {
							status_t status = addon->Get();
							if (status < B_OK) {
								delete addon;
								return status;
							}

							fAddOns.AddItem(addon);
							*_addon = addon;
							return B_OK;
						}
						delete addon;
					}
					break;
				}
				// chop off last path component
				if (path.GetParent(&path) != B_OK)
					break;
			}
		}
	}
	return B_ENTRY_NOT_FOUND;
}
Example #11
0
/*!
	In lazy mode, the entry is marked to be rescanned on next use of any
	translation method (that could make use of it).
	In non-lazy mode, the translators for this entry are created directly
	and listeners notified.

	Called by the node monitor handling.
*/
void
BTranslatorRoster::Private::_EntryAdded(const entry_ref& ref)
{
	BEntry entry;
	if (entry.SetTo(&ref) != B_OK || !entry.IsFile())
		return;

	if (fLazyScanning) {
		fRescanEntries.insert(ref);
		return;
	}

	BMessage update(B_TRANSLATOR_ADDED);
	int32 count = 0;
	CreateTranslators(ref, count, &update);

	_NotifyListeners(update);
}
Example #12
0
/***********************************************************
 * Build
 ***********************************************************/
void
AddOnMenu::Build()
{
	// Build add addons menus
	if(!fPath.Path())
		return;
	BDirectory 	dir(fPath.Path());
	entry_ref 	ref;
	BEntry 		entry;
	BList		itemList;
	itemList.MakeEmpty();
	char 		name[B_FILE_NAME_LENGTH];
	char		shortcut = 0;
	BBitmap 	*bitmap(NULL);
	
	while(dir.GetNextEntry(&entry,true) == B_OK)
	{
		if(entry.IsFile() && entry.GetRef(&ref) == B_OK)
		{	
			shortcut = 0;
			bitmap = NULL;
			BMessage *msg = new BMessage(fWhat);
			msg->AddRef("refs",&ref);
			// make name and shortcut
			int32 nameLen = ::strlen(ref.name);
			::strcpy(name,ref.name);
			if(name[nameLen-2] == '-')
			{
				shortcut = name[nameLen-1];
				name[nameLen-2] = '\0';
			}
			if(fUseIcon)
				bitmap = GetIcon(ref);
			itemList.AddItem(new IconMenuItem(name,msg,shortcut,0,bitmap));
		}
	}
	
	// sort items
	itemList.SortItems(SortItems);
	
	int32 count = itemList.CountItems();
	for(int32 i = 0;i < count;i++)
		AddItem((IconMenuItem*)itemList.ItemAt(i));
}
void
AddPrinterDialog::_FillMenu(BMenu* menu, const char* path, uint32 what)
{
	for (uint32 i = 0; i < sizeof(gAddonDirs) / sizeof(directory_which); i++) {
		BPath addonPath;
		if (find_directory(gAddonDirs[i], &addonPath) != B_OK)
			continue;

		if (addonPath.Append(path) != B_OK)
			continue;

		BDirectory dir(addonPath.Path());
		if (dir.InitCheck() != B_OK)
			continue;

		BEntry entry;
		while (dir.GetNextEntry(&entry, true) == B_OK) {
			if (!entry.IsFile())
				continue;

			BNode node(&entry);
			if (node.InitCheck() != B_OK)
				continue;

			BNodeInfo info(&node);
			if (info.InitCheck() != B_OK)
				continue;

			char type[B_MIME_TYPE_LENGTH + 1];
			info.GetType(type);
			BMimeType entryType(type);
			// filter non executable entries (like "transport" subfolder...)
			if (entryType == B_APP_MIME_TYPE) {
				BPath transportPath;
				if (entry.GetPath(&transportPath) != B_OK)
					continue;

				BMessage* msg = new BMessage(what);
				msg->AddString("name", transportPath.Leaf());
				menu->AddItem(new BMenuItem(transportPath.Leaf(), msg));
			}
		}
	}
}
status_t
GLRendererRoster::AddPath(const char* path)
{
	BDirectory directory(path);
	status_t status = directory.InitCheck();
	if (status < B_OK)
		return status;

	// if a subdirectory for our ABI exists, use that instead
	if (fABISubDirectory != NULL) {
		BEntry entry(&directory, fABISubDirectory);
		if (entry.IsDirectory()) {
			status = directory.SetTo(&entry);
			if (status != B_OK)
				return status;
		}
	}

	node_ref nodeRef;
	status = directory.GetNodeRef(&nodeRef);
	if (status < B_OK)
		return status;

	int32 count = 0;
	int32 files = 0;

	entry_ref ref;
	BEntry entry;
	while (directory.GetNextRef(&ref) == B_OK) {
		entry.SetTo(&ref, true);
		if (entry.InitCheck() == B_OK && !entry.IsFile())
			continue;

		if (CreateRenderer(ref) == B_OK)
			count++;

		files++;
	}

	if (files != 0 && count == 0)
		return B_BAD_VALUE;

	return B_OK;
}
Example #15
0
void ProtocolHandler::LoadPasswords()
{
	//find settings dir
	BPath passwordPath;
	find_directory(B_USER_SETTINGS_DIRECTORY, &passwordPath);
	//append Bme path and Cache path
	passwordPath.Append(K_BME_SETTINGS_PATH);
	passwordPath.Append(K_CACHE_PATH);
	//loop through Bme Cache path and find all login names with saved passwords
	BDirectory cacheDir(passwordPath.Path());
		
	int32 entryNum = cacheDir.CountEntries();
	//compose list of loginNames with passwords
	for (int32 i = 0; i < entryNum;i++)
	{
		BEntry entry;
		cacheDir.GetNextEntry(&entry);
		//only open if it is a file!!!
		if (entry.IsFile())
		{
			BFile settingsFile(&entry, B_READ_ONLY);
			//data is stored as BMessages
			BMessage message;
			message.Unflatten(&settingsFile);
			//see if password is stored in message
			BString password;
			BMessage userMessage;
			if (message.FindMessage("user",&userMessage) == B_OK)
			{				
				if (userMessage.FindString("User::password",&password) == B_OK)
				{					
					BString loginName;
					if (userMessage.FindString("Contact::passport" ,&loginName) == B_OK)
					{						
						Login login = {loginName,password};
						m_passwords.push_back(login);
					}
				}
			}
		}
	}
}
Example #16
0
void
DialUpView::LoadInterfaces()
{
	fInterfaceMenu->AddSeparatorItem();
	fInterfaceMenu->AddItem(new BMenuItem(kLabelCreateNewInterface,
		new BMessage(kMsgCreateNew)));
	fDeleterItem = new BMenuItem(kLabelDeleteCurrent,
		new BMessage(kMsgDeleteCurrent));
	fInterfaceMenu->AddItem(fDeleterItem);
	
	BDirectory settingsDirectory;
	BEntry entry;
	BPath path;
	GetPPPDirectories(&settingsDirectory, NULL);
	while(settingsDirectory.GetNextEntry(&entry) == B_OK) {
		if(entry.IsFile()) {
			entry.GetPath(&path);
			AddInterface(path.Leaf(), true);
		}
	}
}
Example #17
0
void
TMailApp::_CheckForSpamFilterExistence()
{
	// Looks at the filter settings to see if the user is using a spam filter.
	// If there is one there, set fShowSpamGUI to TRUE, otherwise to FALSE.

	int32 addonNameIndex;
	const char *addonNamePntr;
	BDirectory inChainDir;
	BPath path;
	BEntry settingsEntry;
	BFile settingsFile;
	BMessage settingsMessage;

	fShowSpamGUI = false;

	if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
		return;
	// TODO use new settings
	path.Append("Mail/chains/inbound");
	if (inChainDir.SetTo(path.Path()) != B_OK)
		return;

	while (inChainDir.GetNextEntry (&settingsEntry, true /* traverse */) == B_OK) {
		if (!settingsEntry.IsFile())
			continue;
		if (settingsFile.SetTo (&settingsEntry, B_READ_ONLY) != B_OK)
			continue;
		if (settingsMessage.Unflatten (&settingsFile) != B_OK)
			continue;
		for (addonNameIndex = 0; B_OK == settingsMessage.FindString (
			"filter_addons", addonNameIndex, &addonNamePntr);
			addonNameIndex++) {
			if (strstr (addonNamePntr, "Spam Filter") != NULL) {
				fShowSpamGUI = true; // Found it!
				return;
			}
		}
	}
}
Example #18
0
/*------------------------------------------------------------------------------*\
	LoadAddons()
		-	loads all available filter-addons
\*------------------------------------------------------------------------------*/
void BmFilterList::LoadAddons() {
	BDirectory addonDir;
	BPath path;
	BEntry entry;
	status_t err;

	BM_LOG2( BM_LogFilter, BmString("Start of LoadAddons() for FilterList"));

	// determine the path to the user-config-directory:
	if (find_directory( B_USER_ADDONS_DIRECTORY, &path) != B_OK)
		BM_THROW_RUNTIME( "Sorry, could not determine user's addon-dir !?!");
	BmString addonPath = BmString(BeamRoster->AppPath()) + "/add-ons/Filters";
	SetupFolder( addonPath.String(), &addonDir);

	// ...and scan through all its entries for filter-add-ons:
	while ( addonDir.GetNextEntry( &entry, true) == B_OK) {
		if (entry.IsFile()) {
			char nameBuf[B_FILE_NAME_LENGTH];
			entry.GetName( nameBuf);
			// try to load addon:
			const char** filterKinds;
			const char** defaultFilterName;
			BmFilterAddonDescr ao;
			ao.name = nameBuf;
			ao.name.CapitalizeEachWord();
			entry.GetPath( &path);
			if ((ao.image = load_add_on( path.Path())) < 0) {
				BM_SHOWERR( BmString("Unable to load filter-addon\n\t")
									<<ao.name<<"\n\nError:\n\t"<<strerror( ao.image));
				continue;
			}
			if ((err = get_image_symbol( 
				ao.image, "InstantiateFilter", B_SYMBOL_TYPE_ANY, 
				(void**)&ao.instantiateFilterFunc
			)) != B_OK) {
				BM_SHOWERR( BmString("Unable to load filter-addon\n\t")
								<<ao.name<<"\n\nMissing symbol 'InstantiateFilter'");
				continue;
			}
			if ((err = get_image_symbol( 
				ao.image, "InstantiateFilterPrefs", B_SYMBOL_TYPE_ANY, 
				(void**)&ao.instantiateFilterPrefsFunc
			)) != B_OK) {
				BM_SHOWERR( BmString("Unable to load filter-addon\n\t")
								<<ao.name
								<<"\n\nMissing symbol 'InstantiateFilterPrefs'");
				continue;
			}
			if ((err = get_image_symbol( 
				ao.image, "FilterKinds", B_SYMBOL_TYPE_ANY, 
				(void**)&filterKinds
			)) != B_OK) {
				BM_SHOWERR( BmString("Unable to load filter-addon\n\t")
								<<ao.name<<"\n\nMissing symbol 'FilterKinds'");
				continue;
			}
			if ((err = get_image_symbol( 
				ao.image, "DefaultFilterName", B_SYMBOL_TYPE_ANY, 
				(void**)&defaultFilterName
			)) == B_OK)
				ao.defaultFilterName = *defaultFilterName;
			else
				ao.defaultFilterName = "new filter";
#if 0
			// we try to set TheBubbleHelper and TheLogHandler globals inside 
			// the addon to our current values:
			BubbleHelper** bhPtr;
			if (get_image_symbol( ao.image, "TheBubbleHelper", B_SYMBOL_TYPE_ANY, 
										 (void**)&bhPtr) == B_OK) {
				*bhPtr = TheBubbleHelper;
			}
			BmLogHandler** lhPtr;
			if (get_image_symbol( ao.image, "TheLogHandler", B_SYMBOL_TYPE_ANY, 
										 (void**)&lhPtr) == B_OK) {
				*lhPtr = TheLogHandler;
			}
#endif
			// now we add the addon to our map (one entry per filter-kind):
			while( *filterKinds) {
				BmString kind(*filterKinds);
				FilterAddonMap[*filterKinds++] = ao;
				if (kind.ICompare("Spam") == 0) {
					// a spam-filter requires two internal filters (learnAsSpam
					// and learnAsTofu) which don't appear as part of filter-list:
					mLearnAsSpamFilter 
						= new BmFilter( LEARN_AS_SPAM_NAME, "Spam", NULL);
					BMessage learnAsSpamJob;
					learnAsSpamJob.AddString("jobSpecifier", "LearnAsSpam");
					mLearnAsSpamFilter->JobSpecifier(learnAsSpamJob);
					mLearnAsTofuFilter 
						= new BmFilter( LEARN_AS_TOFU_NAME, "Spam", NULL);
					BMessage learnAsTofuJob;
					learnAsTofuJob.AddString("jobSpecifier", "LearnAsTofu");
					mLearnAsTofuFilter->JobSpecifier(learnAsTofuJob);
				}
			}
			BM_LOG( BM_LogFilter, BmString("Successfully loaded addon ") 
						<< ao.name);

		}
	}
	BM_LOG2( BM_LogFilter, BmString("End of LoadAddons() for FilterList"));
}
Example #19
0
void PApp::FindAndOpen(const char *file, const char* fromSource)
{
	char *bi = NULL;
	bool found = false;

	try
	{
		BEntry e;
		entry_ref doc;
		BDirectory d;

		if (!found && fromSource)
		{
			BPath path;
			entry_ref eref;
			if (get_ref_for_path(fromSource, &eref) == B_OK) {
				vector<BString> inclPathVect;
				if (!ProjectRoster->GetIncludePathsForFile(&eref, inclPathVect))
					ProjectRoster->GetAllIncludePaths(inclPathVect);

				for(uint32 i=0; !found && i<inclPathVect.size(); ++i)
				{
					if (path.SetTo(inclPathVect[i].String(), file) != B_OK)
						continue;
					if (e.SetTo(path.Path(), true) != B_OK)
						continue;
					if (e.Exists() && e.IsFile()) {
						FailOSErr(e.GetRef(&doc));
						found = true;
					}
				}
			}
		}

		if (!found && gPrefs->GetPrefInt(prf_I_BeIncludes))
		{
			bi = strdup(getenv("BEINCLUDES"));
			char *ip = bi;
			char *p = ip;

			while (p && !found)
			{
				char *pe = strchr(p, ';');
				if (pe) *pe = 0;

				FailOSErr(d.SetTo(p));
				if (d.Contains(file, B_FILE_NODE | B_SYMLINK_NODE))
				{
					FailOSErr(d.FindEntry(file, &e, true));
					if (!e.IsFile()) THROW((0));
					FailOSErr(e.GetRef(&doc));
					found = true;
				}

				p = (pe && pe[1]) ? pe + 1 : NULL;
			}
		}

		if (!found)
		{
			const char *p;
			int i = 0;

			while ((p = gPrefs->GetIxPrefString(prf_X_IncludePath, i++))!= NULL && !found)
			{
				if (e.SetTo(p) != B_OK || !e.Exists())
					continue;

				FailOSErr(d.SetTo(p));
				if (d.Contains(file, B_FILE_NODE | B_SYMLINK_NODE))
				{
					FailOSErr(d.FindEntry(file, &e, true));
					if (!e.IsFile()) THROW((0));
					FailOSErr(e.GetRef(&doc));
					found = true;
				}
			}
		}

		if (found)
			OpenWindow(doc);
		else
			beep();
	}
	catch (HErr& e)
	{
		beep();
	}

	if (bi)
		free(bi);
} // PApp::FindAndOpen
Example #20
0
// main
int
main(int argc, const char *const *argv)
{
	kArgc = argc;
	kArgv = argv;

	// parameters
	const char **files = new const char*[argc];
	int fileCount = 0;
	const char *type = NULL;
	const char *signature = NULL;
	const char *preferredApp = NULL;
	
	// parse the arguments
	for (int argi = 1; argi < argc; ) {
		const char *arg = argv[argi++];
		if (arg[0] == '-') {
			if (strcmp(arg, "-h") == 0 || strcmp(arg, "--help") == 0) {
				print_usage_and_exit(false);

			} else if (strcmp(arg, "-preferredAppSig") == 0) {
				preferredApp = next_arg(argi);

			} else if (strcmp(arg, "-s") == 0) {
				signature = next_arg(argi);

			} else if (strcmp(arg, "-t") == 0) {
				type = next_arg(argi);

			} else {
				fprintf(stderr, "Error: Invalid option: \"%s\"\n", arg);
				print_usage_and_exit(true);
			}
		} else {
			// file
			files[fileCount++] = arg;
		}
	}

	// check parameters
	if (!preferredApp && !signature && !type) {
		fprintf(stderr, "Error: At least one option of \"-preferredAppSig\", "
			"\"-s\", and \"-t\" must be given.\n");
		print_usage_and_exit(true);
	}

	if (fileCount == 0) {
		fprintf(stderr, "Error: No file specified.\n");
		print_usage_and_exit(true);
	}	

	// check for valid MIME types
	check_mime_type(preferredApp);
	check_mime_type(type);
	check_mime_type(signature);

	// iterate through the files
	for (int i = 0; i < fileCount; i++) {
		const char *fileName = files[i];

		// check, whether the file exists
		BEntry entry;
		status_t error = entry.SetTo(fileName, false);
		if (error != B_OK) {
			fprintf(stderr, "Error: Can't access file \"%s\": %s\n",
				fileName, strerror(error));

			exit(1);
		}

		if (!entry.Exists()) {
			fprintf(stderr, "Error: \"%s\": No such file or directory.\n",
				fileName);

			exit(1);
		}

		// ... and has the right type
		if (signature && !entry.IsFile()) {
			fprintf(stderr, "Error: \"%s\" is not a file. Signatures can only "
				"be set for executable files.\n", fileName);

			exit(1);
		}

		// open the file
		BFile file;
		BNode _node;
		BNode &node = (signature ? file : _node);
		error = (signature ? file.SetTo(fileName, B_READ_WRITE)
			: node.SetTo(fileName));
		if (error != B_OK) {
			fprintf(stderr, "Error: Failed to open file \"%s\": %s\n",
				fileName, strerror(error));

			exit(1);
		}

		// prepare an node/app info object
		BAppFileInfo appInfo;
		BNodeInfo _nodeInfo;
		BNodeInfo &nodeInfo = (signature ? appInfo : _nodeInfo);
		error = (signature ? appInfo.SetTo(&file) : nodeInfo.SetTo(&node));
		if (error != B_OK) {
			fprintf(stderr, "Error: Failed to open file \"%s\": %s\n",
				fileName, strerror(error));

			exit(1);
		}

		// set preferred app
		if (preferredApp) {
			error = nodeInfo.SetPreferredApp(preferredApp);
			if (error != B_OK) {
				fprintf(stderr, "Error: Failed to set the preferred "
					"application of file \"%s\": %s\n", fileName,
					strerror(error));

				exit(1);
			}
		}

		// set type
		if (type) {
			error = nodeInfo.SetType(type);
			if (error != B_OK) {
				fprintf(stderr, "Error: Failed to set the MIME type of file "
					"\"%s\": %s\n", fileName, strerror(error));

				exit(1);
			}
		}

		// set signature
		if (signature) {
			error = appInfo.SetSignature(signature);
			if (error != B_OK) {
				fprintf(stderr, "Error: Failed to set the signature of file "
					"\"%s\": %s\n", fileName, strerror(error));

				exit(1);
			}
		}
	}

	return 0;
}
Example #21
0
void nsbeos_gui_view_source(struct hlcache_handle *content)
{
	char *temp_name;
	bool done = false;
	BPath path;
	status_t err;
	size_t size;
	const char *source = content_get_source_data(content, &size);

	if (!content || !source) {
		warn_user("MiscError", "No document source");
		return;
	}

	/* try to load local files directly. */
	temp_name = url_to_path(nsurl_access(hlcache_handle_get_url(content)));
	if (temp_name) {
		path.SetTo(temp_name);
		BEntry entry;
		if (entry.SetTo(path.Path()) >= B_OK 
			&& entry.Exists() && entry.IsFile())
			done = true;
	}
	if (!done) {
		/* We cannot release the requested filename until after it
		 * has finished being used. As we can't easily find out when
		 * this is, we simply don't bother releasing it and simply
		 * allow it to be re-used next time NetSurf is started. The
		 * memory overhead from doing this is under 1 byte per
		 * filename. */
		const char *filename = filename_request();
		if (!filename) {
			warn_user("NoMemory", 0);
			return;
		}
		path.SetTo(TEMP_FILENAME_PREFIX);
		path.Append(filename);
		BFile file(path.Path(), B_WRITE_ONLY | B_CREATE_FILE);
		err = file.InitCheck();
		if (err < B_OK) {
			warn_user("IOError", strerror(err));
			return;
		}
		err = file.Write(source, size);
		if (err < B_OK) {
			warn_user("IOError", strerror(err));
			return;
		}
		lwc_string *mime = content_get_mime_type(content);
		if (mime) {
			file.WriteAttr("BEOS:TYPE", B_MIME_STRING_TYPE, 0LL, 
				lwc_string_data(mime), lwc_string_length(mime) + 1);
			lwc_string_unref(mime);
		}
		
	}

	entry_ref ref;
	if (get_ref_for_path(path.Path(), &ref) < B_OK)
		return;

	BMessage m(B_REFS_RECEIVED);
	m.AddRef("refs", &ref);


	// apps to try
	const char *editorSigs[] = {
		"application/x-vnd.beunited.pe",
		"application/x-vnd.XEmacs",
		"application/x-vnd.Haiku-StyledEdit",
		"application/x-vnd.Be-STEE",
		"application/x-vnd.yT-STEE",
		NULL
	};
	int i;
	for (i = 0; editorSigs[i]; i++) {
		team_id team = -1;
		{
			BMessenger msgr(editorSigs[i], team);
			if (msgr.SendMessage(&m) >= B_OK)
				break;
		}
		
		err = be_roster->Launch(editorSigs[i], (BMessage *)&m, &team);
		if (err >= B_OK)
			break;
	}
}
Example #22
0
void PecoApp::RefsReceived ( BMessage* msg ) {

	entry_ref	ref;
	BPath		aPath;
	BEntry		aEntry;
	off_t		size;
	time_t		timer;
	
	fWindow->Lock();
	BTextControl* 	pfadView 	= (BTextControl *)fWindow->FindView("pfadView");
	fWindow->Unlock();
	
	//Pfad finden
	for ( int i=0; msg->FindRef("refs", i, &ref) == B_OK; i++ ) if ( ref.device > 1 ) break;
	
	if ( ref.device > 1 ) {
		New();

		fWindow->Lock();
		((PecoApp *)be_app)->fStatusBar->SetText(STATUS_IMPORT);
		fWindow->Unlock();
	
		aEntry = BEntry(&ref);
		BPath( &aEntry ).GetParent(&fPfad);
				
		fWindow->Lock();
		pfadView->SetText( fPfad.Path() );
		fWindow->Unlock();
		
		//zählen
		type_code	typeFound;
		long		total = 0;
		msg->GetInfo("refs", &typeFound, &total);
		
		fWindow->Lock();
		fStatusBar->SetMaxValue( total );
		fWindow->Unlock();
		
		BPath	newPath;
		
		bool	didntshow_msgmultidir = true;
		
		for ( int i=0; msg->FindRef("refs", i, &ref) == B_OK; i++ ) {
			
			fWindow->Lock();
			fStatusBar->Update(1);
			fWindow->Unlock();
			
			// Laufwerke ausfiltern
			if ( ref.device == 1 ) continue;
 			
			// Dateien mit falschem Pfad ausfiltern
			aEntry = BEntry(&ref);
			aPath = BPath(&aEntry);
			
			BPath( &aEntry ).GetParent(&newPath);
			
			if ( (strcmp( fPfad.Path(), newPath.Path() ) != 0 ) ) {
				if ( didntshow_msgmultidir ) {
					BAlert*	myAlert = new BAlert(NULL, MESSAGE_MULTIDIR, STR_OK);
					myAlert->Go();
					didntshow_msgmultidir = false;
				}
				continue;
			}
			
			// Werte auslesen
			if (aEntry.IsFile()) aEntry.GetSize(&size); 
			else
				if (aEntry.IsSymLink()) size = -1;
				else
					if (aEntry.IsDirectory()) size = -2;
					else continue;
			
			aEntry.GetModificationTime(&timer);
			
			fList->AddItem(new FileListItem(aPath.Leaf(), size, timer, &ref));
			
		}
		
		fWindow->Lock();
		fListView->AddList(fList);
		float Hoehe = be_plain_font->Size() + 2;
		if (Hoehe < 18) {
			BListItem*	myListItem;
			for (int i=0; (myListItem = fListView->ItemAt(i)); i++) myListItem->SetHeight(18);
			// Zum Updaten:
			fListView->AddItem(myListItem = new BStringItem(""));
			fListView->RemoveItem(myListItem);
		}
		fStatusBar->Reset(STATUS_STATUS);
		fStatusBar->SetMaxValue(fList->CountItems());
		fWindow->Unlock();
		
		MakeList();
	}
	fWindow->Activate();
	UpdateWindowStatus();
}