当前位置: 首页>>代码示例>>C++>>正文


C++ BPath类代码示例

本文整理汇总了C++中BPath的典型用法代码示例。如果您正苦于以下问题:C++ BPath类的具体用法?C++ BPath怎么用?C++ BPath使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了BPath类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: DispatchMessage

	void DispatchMessage(BMessage *msg, BHandler *target)
	{
		switch(msg->what)
		{
			case M_TEMPLATE_SAVE:
			{
				EditView *ev;
				entry_ref dir; 
				const char *filespec;
				int32 DocID;
				
				if ((msg->FindInt32("DocID", &DocID) == B_OK) &&
				   (msg->FindRef("directory", &dir) == B_OK) &&
				   (msg->FindString("name", &filespec) == B_OK) &&
				   (ev = FindEVByDocID(DocID)))
				{
					BEntry entry(&dir, true);
					BPath path;
					
					entry.GetPath(&path);
					path.Append(filespec);
					const char *filename = path.Path();
					
					if (ev->Save(filename))
					{
						(new BAlert("", "The save operation failed: the file could not be written to the destination.", "Damned!"))->Go();
					}
				}
				else
				{
					(new BAlert("", "The save operation failed.", "Damned!"))->Go();
				}
				
				if (TemplatePanel)
				{
					delete TemplatePanel;
					TemplatePanel = NULL;
				}
				
				Quit();
			}
			break;
			
			case M_TEMPLATE_LOAD:
			{
				int i;
				uint32 type;
				int32 count;
				entry_ref ref;
				EditView *ev = NULL, *firstev = NULL;
				
				LockWindow();
				
				msg->GetInfo("refs", &type, &count);
				for(i=0;i<count;i++)
				{
					if (msg->FindRef("refs", i, &ref) == B_OK)
					{
						BEntry entry(&ref, true);
						BPath path;
						entry.GetPath(&path);
						
						// open the template
						if (ev = CreateEditView((char *)path.Path()))
						{
							// take away the template filename: make the file untitled
							ev->MakeUntitled();
							
							if (!firstev)
								firstev = ev;
						}
					}
				}
				
				// switch to the first template opened
				if (firstev)
					TabBar->SetActiveTab(firstev);
				TabBar->redraw();
				
				UnlockWindow();
				
				if (TemplatePanel)
				{
					delete TemplatePanel;
					TemplatePanel = NULL;
				}
				
				Quit();
			}
			break;
			
			case M_TEMPLATE_SELECT:
			{
				entry_ref ref;
				
				if (msg->FindRef("refs", &ref) == B_OK)
				{
					BEntry entry(&ref, true);
					BPath path;
					entry.GetPath(&path);
//.........这里部分代码省略.........
开发者ID:HaikuArchives,项目名称:Sisong,代码行数:101,代码来源:Templates.cpp

示例2: ParseArgvFromString

bool
ShortcutsSpec::_AttemptTabCompletion()
{
	bool result = false;

	int32 argc;
	char** argv = ParseArgvFromString(fCommand, argc);
	if (argc > 0) {
		// Try to complete the path partially expressed in the last argument!
		char* arg = argv[argc - 1];
		char* fileFragment = strrchr(arg, '/');
		if (fileFragment != NULL) {
			const char* directoryName = (fileFragment == arg) ? "/" : arg;
			*fileFragment = '\0';
			fileFragment++;
			int fragmentLength = strlen(fileFragment);

			BDirectory dir(directoryName);
			if (dir.InitCheck() == B_NO_ERROR) {
				BEntry nextEnt;
				BPath nextPath;
				BList matchList;
				int maxEntryLen = 0;

				// Read in all the files in the directory whose names start
				// with our fragment.
				while (dir.GetNextEntry(&nextEnt) == B_NO_ERROR) {
					if (nextEnt.GetPath(&nextPath) == B_NO_ERROR) {
						char* filePath = strrchr(nextPath.Path(), '/') + 1;
						if (strncmp(filePath, fileFragment, fragmentLength) == 0) {
							int len = strlen(filePath);
							if (len > maxEntryLen)
								maxEntryLen = len;
							char* newStr = new char[len + 1];
							strcpy(newStr, filePath);
							matchList.AddItem(newStr);
						}
					}
				}

				// Now slowly extend our keyword to its full length, counting
				// numbers of matches at each step. If the match list length
				// is 1, we can use that whole entry. If it's greater than one,
				// we can use just the match length.
				int matchLen = matchList.CountItems();
				if (matchLen > 0) {
					int i;
					BString result(fileFragment);
					for (i = fragmentLength; i < maxEntryLen; i++) {
						// See if all the matching entries have the same letter
						// in the next position... if so, we can go farther.
						char commonLetter = '\0';
						for (int j = 0; j < matchLen; j++) {
							char nextLetter = GetLetterAt(
								(char*)matchList.ItemAt(j), i);
							if (commonLetter == '\0')
								commonLetter = nextLetter;

							if ((commonLetter != '\0')
								&& (commonLetter != nextLetter)) {
								commonLetter = '\0';// failed;
								beep();
								break;
							}
						}
						if (commonLetter == '\0')
							break;
						else
							result.Append(commonLetter, 1);
					}

					// free all the strings we allocated
					for (int k = 0; k < matchLen; k++)
						delete [] ((char*)matchList.ItemAt(k));

					DoStandardEscapes(result);

					BString wholeLine;
					for (int l = 0; l < argc - 1; l++) {
						wholeLine += argv[l];
						wholeLine += " ";
					}

					BString file(directoryName);
					DoStandardEscapes(file);

					if (directoryName[strlen(directoryName) - 1] != '/')
						file += "/";

					file += result;

					// Remove any trailing slash...
					const char* fileStr = file.String();
					if (fileStr[strlen(fileStr) - 1] == '/')
						file.RemoveLast("/");

					// and re-append it iff the file is a dir.
					BDirectory testFileAsDir(file.String());
					if ((strcmp(file.String(), "/") != 0)
						&& (testFileAsDir.InitCheck() == B_NO_ERROR))
//.........这里部分代码省略.........
开发者ID:AmirAbrams,项目名称:haiku,代码行数:101,代码来源:ShortcutsSpec.cpp

示例3: switch

void
DeskbarView::MessageReceived(BMessage* message)
{
	switch (message->what) {
		case MD_CHECK_SEND_NOW:
			// also happens in DeskbarView::MouseUp() with
			// B_TERTIARY_MOUSE_BUTTON pressed
			BMailDaemon().CheckAndSendQueuedMail();
			break;
		case MD_CHECK_FOR_MAILS:
			BMailDaemon().CheckMail(message->FindInt32("account"));
			break;
		case MD_SEND_MAILS:
			BMailDaemon().SendQueuedMail();
			break;

		case MD_OPEN_NEW:
		{
			char* argv[] = {(char *)"New Message", (char *)"mailto:"};
			be_roster->Launch("text/x-email", 2, argv);
			break;
		}
		case MD_OPEN_PREFS:
			be_roster->Launch("application/x-vnd.Haiku-Mail");
			break;

		case MD_REFRESH_QUERY:
			_RefreshMailQuery();
			break;

		case B_QUERY_UPDATE:
		{
			int32 what;
			dev_t device;
			ino_t directory;
			const char *name;
			entry_ref ref;
			message->FindInt32("opcode", &what);
			message->FindInt32("device", &device);
			message->FindInt64("directory", &directory);
			switch (what) {
				case B_ENTRY_CREATED:
					if (message->FindString("name", &name) == B_OK) {
						ref.device = device;
						ref.directory = directory;
						ref.set_name(name);
						if (!_EntryInTrash(&ref))
							fNewMessages++;
					}
					break;
				case B_ENTRY_REMOVED:
					node_ref node;
					node.device = device;
					node.node = directory;
					BDirectory dir(&node);
					BEntry entry(&dir, NULL);
					entry.GetRef(&ref);
					if (!_EntryInTrash(&ref))
						fNewMessages--;
					break;
			}
			fStatus = fNewMessages > 0 ? kStatusNewMail : kStatusNoMail;
			Invalidate();
			break;
		}
		case B_QUIT_REQUESTED:
			BMailDaemon().Quit();
			break;

		// open received files in the standard mail application
		case B_REFS_RECEIVED:
		{
			BMessage argv(B_ARGV_RECEIVED);
			argv.AddString("argv", "E-mail");

			entry_ref ref;
			BPath path;
			int i = 0;

			while (message->FindRef("refs", i++, &ref) == B_OK
				&& path.SetTo(&ref) == B_OK) {
				//fprintf(stderr,"got %s\n", path.Path());
				argv.AddString("argv", path.Path());
			}

			if (i > 1) {
				argv.AddInt32("argc", i);
				be_roster->Launch("text/x-email", &argv);
			}
			break;
		}
		default:
			BView::MessageReceived(message);
	}
}
开发者ID:kodybrown,项目名称:haiku,代码行数:95,代码来源:DeskbarView.cpp

示例4: CheckCopiable

status_t CheckCopiable(BEntry *src,BEntry *dest)
{
	// Checks to see if we can copy the src to dest.
	if(!src || !dest)
		return B_ERROR;
	
	if(!src->Exists())
		return B_FILE_NOT_FOUND;

	// Ensure that when we want the destination directory, that is exactly
	// what we're working with. If we've been given an entry which is a file,
	// extract the destination directory.
	BEntry destdir;		
	if(dest->IsDirectory())
		destdir=*dest;
	else
		dest->GetParent(&destdir);
	
	// check existence of target directory
	if(!destdir.Exists())
		return B_NAME_NOT_FOUND;
		
	// check space
	entry_ref ref;
	off_t src_bytes;


	dest->GetRef(&ref);
	BVolume dvolume(ref.device);
	src->GetSize(&src_bytes);

	if(src_bytes>dvolume.FreeBytes())
		return B_DEVICE_FULL;
	
	// check permissions
	if(dvolume.IsReadOnly())
		return B_READ_ONLY;

	// check existing name
	BPath path;
	destdir.GetPath(&path);
	

	char name[B_FILE_NAME_LENGTH];
	src->GetName(name);
	
	BString newpath=path.Path();
	newpath+=name;

	BFile file;
	if(file.SetTo(newpath.String(),B_READ_WRITE | B_FAIL_IF_EXISTS)==B_FILE_EXISTS)
	{
		// We have an existing file, so query the user what to do.
		status_t returncode;

		newpath="The file ";
		newpath+=name;
		newpath+=" exists. Do you want to replace it?";
		
		BAlert *alert=new BAlert("Error",newpath.String(),"Replace File",
		 "Skip File", "Stop");
		returncode=alert->Go();
		switch(returncode)
		{
			case 0:
				return FS_CLOBBER;
			case 1:
				return FS_SKIP;
			default:
				return B_CANCELED;
		}
	}
	return B_OK;
}
开发者ID:puckipedia,项目名称:Filer,代码行数:74,代码来源:FSUtils.cpp

示例5: switch


//.........这里部分代码省略.........
				float mbHeight = fMenuBar->Bounds().Height() + 1;
				fMenuBar->Show();

				for (int32 i = fTabView->CountTabs() - 1; i >= 0 ; i--)
					_TermViewAt(i)->ScrollBar()->ResizeBy(0,
						-(B_H_SCROLL_BAR_HEIGHT - 1));

				ResizeTo(fSavedFrame.Width(), fSavedFrame.Height());
				MoveTo(fSavedFrame.left, fSavedFrame.top);
				fTabView->ResizeBy(0, -mbHeight);
				fTabView->MoveBy(0, mbHeight);
				SetLook(fSavedLook);
				fSavedFrame = BRect(0, 0, -1, -1);
				SetFlags(Flags() & ~(B_NOT_RESIZABLE | B_NOT_MOVABLE));
				fFullScreen = false;
			}
			break;

		case MSG_FONT_CHANGED:
			PostMessage(MSG_HALF_FONT_CHANGED);
			break;

		case MSG_COLOR_CHANGED:
		case MSG_COLOR_SCHEME_CHANGED:
		{
			_SetTermColors(_ActiveTermViewContainerView());
			_ActiveTermViewContainerView()->Invalidate();
			_ActiveTermView()->Invalidate();
			break;
		}

		case SAVE_AS_DEFAULT:
		{
			BPath path;
			if (PrefHandler::GetDefaultPath(path) == B_OK)
				PrefHandler::Default()->SaveAsText(path.Path(),
					PREFFILE_MIMETYPE);
			break;
		}
		case MENU_PAGE_SETUP:
			_DoPageSetup();
			break;

		case MENU_PRINT:
			_DoPrint();
			break;

		case MSG_CHECK_CHILDREN:
			_CheckChildren();
			break;

		case MSG_MOVE_TAB_LEFT:
		case MSG_MOVE_TAB_RIGHT:
			_NavigateTab(_IndexOfTermView(_ActiveTermView()),
				message->what == MSG_MOVE_TAB_LEFT ? -1 : 1, true);
			break;

		case kTabTitleChanged:
		{
			// tab title changed message from SetTitleDialog
			SessionID sessionID(*message, "session");
			if (Session* session = _SessionForID(sessionID)) {
				BString title;
				if (message->FindString("title", &title) == B_OK) {
					session->title.pattern = title;
					session->title.patternUserDefined = true;
开发者ID:DonCN,项目名称:haiku,代码行数:67,代码来源:TermWindow.cpp

示例6: CALLED

status_t
WorkerThread::_PerformInstall(partition_id sourcePartitionID,
	partition_id targetPartitionID)
{
	CALLED();

	BPath targetDirectory;
	BPath srcDirectory;
	BPath trashPath;
	BPath testPath;
	BDirectory targetDir;
	BDiskDevice device;
	BPartition* partition;
	BVolume targetVolume;
	status_t err = B_OK;
	int32 entries = 0;
	entry_ref testRef;
	const char* mountError = B_TRANSLATE("The disk can't be mounted. Please "
		"choose a different disk.");

	if (sourcePartitionID < 0 || targetPartitionID < 0) {
		ERR("bad source or target partition ID\n");
		return _InstallationError(err);
	}

	// check if target is initialized
	// ask if init or mount as is
	if (fDDRoster.GetPartitionWithID(targetPartitionID, &device,
			&partition) == B_OK) {
		if (!partition->IsMounted()) {
			if ((err = partition->Mount()) < B_OK) {
				_SetStatusMessage(mountError);
				ERR("BPartition::Mount");
				return _InstallationError(err);
			}
		}
		if ((err = partition->GetVolume(&targetVolume)) != B_OK) {
			ERR("BPartition::GetVolume");
			return _InstallationError(err);
		}
		if ((err = partition->GetMountPoint(&targetDirectory)) != B_OK) {
			ERR("BPartition::GetMountPoint");
			return _InstallationError(err);
		}
	} else if (fDDRoster.GetDeviceWithID(targetPartitionID, &device) == B_OK) {
		if (!device.IsMounted()) {
			if ((err = device.Mount()) < B_OK) {
				_SetStatusMessage(mountError);
				ERR("BDiskDevice::Mount");
				return _InstallationError(err);
			}
		}
		if ((err = device.GetVolume(&targetVolume)) != B_OK) {
			ERR("BDiskDevice::GetVolume");
			return _InstallationError(err);
		}
		if ((err = device.GetMountPoint(&targetDirectory)) != B_OK) {
			ERR("BDiskDevice::GetMountPoint");
			return _InstallationError(err);
		}
	} else
		return _InstallationError(err);  // shouldn't happen

	// check if target has enough space
	if (fSpaceRequired > 0 && targetVolume.FreeBytes() < fSpaceRequired) {
		BAlert* alert = new BAlert("", B_TRANSLATE("The destination disk may "
			"not have enough space. Try choosing a different disk or choose "
			"to not install optional items."),
			B_TRANSLATE("Try installing anyway"), B_TRANSLATE("Cancel"), 0,
			B_WIDTH_AS_USUAL, B_STOP_ALERT);
		alert->SetShortcut(1, B_ESCAPE);
		if (alert->Go() != 0)
			return _InstallationError(err);
	}

	if (fDDRoster.GetPartitionWithID(sourcePartitionID, &device, &partition)
			== B_OK) {
		if ((err = partition->GetMountPoint(&srcDirectory)) != B_OK) {
			ERR("BPartition::GetMountPoint");
			return _InstallationError(err);
		}
	} else if (fDDRoster.GetDeviceWithID(sourcePartitionID, &device) == B_OK) {
		if ((err = device.GetMountPoint(&srcDirectory)) != B_OK) {
			ERR("BDiskDevice::GetMountPoint");
			return _InstallationError(err);
		}
	} else
		return _InstallationError(err); // shouldn't happen

	// check not installing on itself
	if (strcmp(srcDirectory.Path(), targetDirectory.Path()) == 0) {
		_SetStatusMessage(B_TRANSLATE("You can't install the contents of a "
			"disk onto itself. Please choose a different disk."));
		return _InstallationError(err);
	}

	// check not installing on boot volume
	if (strncmp(BOOT_PATH, targetDirectory.Path(), strlen(BOOT_PATH)) == 0) {
		BAlert* alert = new BAlert("", B_TRANSLATE("Are you sure you want to "
			"install onto the current boot disk? The Installer will have to "
//.........这里部分代码省略.........
开发者ID:looncraz,项目名称:haiku,代码行数:101,代码来源:WorkerThread.cpp

示例7: BWindow


//.........这里部分代码省略.........
	sb << fCategory.categoryName;
	fBackground->SetToolTip( sb.String() );
	
	// Create Event's name view
	fTitle = new BStringView( BRect( 0, 0, 1, 1 ),
									  "Event name",
									  fEventName.String(),
									  B_FOLLOW_H_CENTER | B_FOLLOW_V_CENTER );
	if ( !fTitle ) {
		/* Panic! */
		fLastError = B_NO_MEMORY;
		return;
	}
		// Use big bold font for Event's name
	fTitle->SetFont( be_bold_font );
	fTitle->GetFont( &font );
	font.SetSize( font.Size() + 2 );
	fTitle->SetFont( &font, B_FONT_SIZE );
	
		// Add the title and set its tooltip
	fTitle->ResizeToPreferred();
	fTitle->SetToolTip( sb.String() );
	bgLayout->AddView( fTitle );
	fTitle->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
	fTitle->SetToolTip( fEventName.String() );
	
	int	nextLineInLayout = 2;
	
	/*================================================================
	 * If the notification was set by the user, display it.
	 *================================================================*/

	BString 	tempString;
	BPath		path;
	float rectHeight = fh.leading + fh.ascent + fh.descent;
	float rectWidth = this->Bounds().Width() - 10;		// Layout insets
	BSize size( rectWidth, rectHeight );
	
	if ( fData->GetNotification( &tempString ) )
	{
		/*-----------------------------------------------------------------
	 	 * Line of explanation
	 	 *----------------------------------------------------------------*/
		exp = new BStringView( BRect( 0, 0, 1, 1 ),
									  "Text view explanation",
									  "You set the following notification:" );
		if ( !exp ) {
			/* Panic! */
			fLastError = B_NO_MEMORY;
			return;
		}
		exp->ResizeToPreferred();
		layoutItem = gridLayout->AddView( exp, 0, nextLineInLayout++, numberOfColumnsInLayout, 1 );

		/*-----------------------------------------------------------------
	 	 * Text view with notification text
	 	 *----------------------------------------------------------------*/
		BRect tempRect( BPoint( 0, 0 ), size );
		tempRect.right -= B_V_SCROLL_BAR_WIDTH;
		fNoteText = new BTextView( tempRect,
											"Notification text container",
											tempRect.InsetByCopy( 1, 1 ),
											B_FOLLOW_ALL_SIDES,
											B_WILL_DRAW );
		if ( !fNoteText ) {
			/* Panic! */
开发者ID:BackupTheBerlios,项目名称:haiku-pim-svn,代码行数:67,代码来源:ActivityWindow.cpp

示例8: path

void
Snapshot::ProcessRefs	(BMessage * msg)
{
//	init
	BString command			=	"/bin/zip -ry ";
	BString snapshot_name	=	m_snapshot_dir_path.Path();
	BString file_list;
	
	status_t	status	=	B_OK;
	entry_ref	ref;
	entry_ref	last_ref;
	bool		same_folder	=	true;
	
/*
	entry_ref	dir_ref;

	status	=	msg->FindRef("dir_ref", &dir_ref);
	if (status == B_OK)
	{
		BPath path (& dir_ref);		// when used as Tracker addon
		chdir(path.Path());			// telling zip where to work
	}							
*/	
	type_code	ref_type	=	B_REF_TYPE;
	int32		ref_count	=	0;
	
	status	=	msg->GetInfo("refs", & ref_type, & ref_count);
	if (status != B_OK)
		return;


	if (ref_count < 1)
		return;

	for (int index = 0;	index < ref_count ;	index++)
	{
		msg->FindRef("refs", index, & ref);
		
		if (index > 0)
		{
			if (last_ref.directory != ref.directory)
			{
				same_folder	=	false;
				break;
			}
		}
		
		last_ref =	ref;
	}	

	// change dir to avoid full paths in zip archive
	if (same_folder)
	{
		BEntry	entry	(& ref);
		entry.GetParent(& entry);
		BPath	path	(& entry);
		chdir (path.Path());
	}

	// snapshost_name
	if (ref_count == 1)
	{
		snapshot_name	+=	"/";
		snapshot_name	+=	ref.name;
		snapshot_name	+=	".zip";			
	}
	
	if (ref_count > 1)
		snapshot_name	+=	"/multiple_files.zip";	

	// create timestamp
	time_t	current_time	=	time(NULL);
	char * timestamp = new char [100];
	strftime(timestamp, 99, "%Y.%m.%d_%H:%M:%S", localtime(& current_time));

	snapshot_name	+=	" (";
	snapshot_name	+=	timestamp;	
	snapshot_name	+=	")";

	MakeShellSafe(& snapshot_name);

	// files to zip
	for (int index = 0;	index < ref_count ;	index++)
	{
		msg->FindRef("refs", index, & ref);
		// BPath path (& ref);
	
		if (same_folder)				// just the file name
		{
			BString file = ref.name;
			MakeShellSafe (& file);
		
			file_list += " ";
			file_list += file;
		}
		else							// full path
		{
			BString file;
			BPath	path	(& ref);
			file	=	path.Path();
//.........这里部分代码省略.........
开发者ID:HaikuArchives,项目名称:Snapshot,代码行数:101,代码来源:Snapshot.cpp

示例9: BWindow


//.........这里部分代码省略.........
	box->AddChild(fIntervalUnitField);

	rect.OffsetBy(0,height + 9);
	rect.bottom -= 2;
	fPPPActiveCheckBox = new BCheckBox(rect, "ppp active",
		B_TRANSLATE("Only when dial-up is connected"), NULL);
	box->AddChild(fPPPActiveCheckBox);

	rect.OffsetBy(0,height + 9);
	rect.bottom -= 2;
	fPPPActiveSendCheckBox = new BCheckBox(rect, "ppp activesend",
		B_TRANSLATE("Schedule outgoing mail when dial-up is disconnected"),
		NULL);
	box->AddChild(fPPPActiveSendCheckBox);

	// Miscellaneous settings box

	rect = box->Frame();  rect.bottom = rect.top + 3 * height + 33;
	box = new BBox(rect);
	box->SetLabel(B_TRANSLATE("Miscellaneous"));
	view->AddChild(box);

	BPopUpMenu *statusPopUp = new BPopUpMenu(B_EMPTY_STRING);
	const char *statusModes[] = {
		B_TRANSLATE_COMMENT("Never", "show status window"),
		B_TRANSLATE("While sending"),
		B_TRANSLATE("While sending and receiving"),
		B_TRANSLATE("Always")};
	for (int32 i = 0; i < 4; i++) {
		BMessage* msg = new BMessage(kMsgShowStatusWindowChanged);
		BMenuItem* item = new BMenuItem(statusModes[i], msg);
		statusPopUp->AddItem(item);
		msg->AddInt32("ShowStatusWindow", i);
	}
	rect = box->Bounds().InsetByCopy(10, 10);
	rect.top += 7;
	rect.bottom = rect.top + height + 5;
	labelWidth = (int32)view->StringWidth(
		B_TRANSLATE("Show connection status window:"))	+ 8;
	fStatusModeField = new BMenuField(rect, "show status",
		B_TRANSLATE("Show connection status window:"), statusPopUp);
	fStatusModeField->SetDivider(labelWidth);
	box->AddChild(fStatusModeField);

	rect = fStatusModeField->Frame();;
	rect.OffsetBy(0, rect.Height() + 10);
	BMessage* msg = new BMessage(B_REFS_RECEIVED);
	BButton *button = new BButton(rect, B_EMPTY_STRING,
		B_TRANSLATE("Edit mailbox menu…"), msg);
	button->ResizeToPreferred();
	box->AddChild(button);
	button->SetTarget(BMessenger("application/x-vnd.Be-TRAK"));

	BPath path;
	find_directory(B_USER_SETTINGS_DIRECTORY, &path);
	path.Append("Mail/Menu Links");
	BEntry entry(path.Path());
	if (entry.InitCheck() == B_OK && entry.Exists()) {
		entry_ref ref;
		entry.GetRef(&ref);
		msg->AddRef("refs", &ref);
	}
	else
		button->SetEnabled(false);

	rect = button->Frame();
	rect.OffsetBy(rect.Width() + 30,0);
	fAutoStartCheckBox = new BCheckBox(rect, "start daemon",
		B_TRANSLATE("Start mail services on startup"), NULL);
	fAutoStartCheckBox->ResizeToPreferred();
	box->AddChild(fAutoStartCheckBox);

	// save/revert buttons

	top->AddChild(tabView);

	rect = tabView->Frame();
	rect.top = rect.bottom + 10;
	rect.bottom = rect.top + height + 5;
	BButton *saveButton = new BButton(rect, "apply", B_TRANSLATE("Apply"),
		new BMessage(kMsgSaveSettings));
	float w,h;
	saveButton->GetPreferredSize(&w, &h);
	saveButton->ResizeTo(w, h);
	saveButton->MoveTo(rect.right - w, rect.top);
	top->AddChild(saveButton);

	BButton *revertButton = new BButton(rect, "revert", B_TRANSLATE("Revert"),
		new BMessage(kMsgRevertSettings));
	revertButton->GetPreferredSize(&w, &h);
	revertButton->ResizeTo(w, h);
	revertButton->MoveTo(rect.left, rect.top);
	top->AddChild(revertButton);

	_LoadSettings();
		// this will also move our window to the stored position

	fAccountsListView->SetSelectionMessage(new BMessage(kMsgAccountSelected));
	fAccountsListView->MakeFocus(true);
}
开发者ID:mylegacy,项目名称:haiku,代码行数:101,代码来源:ConfigWindow.cpp

示例10: path

void
HWindow::_SetupMenuField()
{
	BMenuField* menufield = dynamic_cast<BMenuField*>(FindView("filemenu"));
	if (menufield == NULL)
		return;
	BMenu* menu = menufield->Menu();
	int32 count = fEventList->CountRows();
	for (int32 i = 0; i < count; i++) {
		HEventRow* row = (HEventRow*)fEventList->RowAt(i);
		if (row == NULL)
			continue;

		BPath path(row->Path());
		if (path.InitCheck() != B_OK)
			continue;
		if (menu->FindItem(path.Leaf()))
			continue;

		BMessage* msg = new BMessage(M_ITEM_MESSAGE);
		entry_ref ref;
		::get_ref_for_path(path.Path(), &ref);
		msg->AddRef("refs", &ref);
		menu->AddItem(new BMenuItem(path.Leaf(), msg), 0);
	}

	directory_which whichDirectories[] = {
		B_SYSTEM_SOUNDS_DIRECTORY,
		B_SYSTEM_NONPACKAGED_SOUNDS_DIRECTORY,
		B_USER_SOUNDS_DIRECTORY,
		B_USER_NONPACKAGED_SOUNDS_DIRECTORY,
	};

	for (size_t i = 0;
		i < sizeof(whichDirectories) / sizeof(whichDirectories[0]); i++) {
		BPath path;
		BDirectory dir;
		BEntry entry;
		BPath item_path;

		status_t err = find_directory(whichDirectories[i], &path);
		if (err == B_OK)
			err = dir.SetTo(path.Path());
		while (err == B_OK) {
			err = dir.GetNextEntry(&entry, true);
			if (entry.InitCheck() != B_NO_ERROR)
				break;

			entry.GetPath(&item_path);

			if (menu->FindItem(item_path.Leaf()))
				continue;

			BMessage* msg = new BMessage(M_ITEM_MESSAGE);
			entry_ref ref;
			::get_ref_for_path(item_path.Path(), &ref);
			msg->AddRef("refs", &ref);
			menu->AddItem(new BMenuItem(item_path.Leaf(), msg), 0);
		}
	}
}
开发者ID:AmirAbrams,项目名称:haiku,代码行数:61,代码来源:HWindow.cpp

示例11: entry

void
DataTranslationsApplication::RefsReceived(BMessage* message)
{
	BTranslatorRoster* roster = BTranslatorRoster::Default();

	BPath path;
	status_t status = find_directory(B_USER_ADDONS_DIRECTORY, &path, true);
	if (status != B_OK) {
		_InstallError("translator", status);
		return;
	}

	BDirectory target;
	status = target.SetTo(path.Path());
	if (status == B_OK) {
		if (!target.Contains("Translators"))
			status = target.CreateDirectory("Translators", &target);
		else
			status = target.SetTo(&target, "Translators");
	}
	if (status != B_OK) {
		_InstallError("translator", status);
		return;
	}

	int32 i = 0;
	entry_ref ref;
	while (message->FindRef("refs", i++, &ref) == B_OK) {
		if (!roster->IsTranslator(&ref)) {
			_NoTranslatorError(ref.name);
			continue;
		}

		BEntry entry(&ref, true);
		status = entry.InitCheck();
		if (status != B_OK) {
			_InstallError(ref.name, status);
			continue;
		}

		if (target.Contains(ref.name)) {
			BString string(
				B_TRANSLATE("An item named '%name' already exists in the "
				"Translators folder! Shall the existing translator be "
				"overwritten?"));
			string.ReplaceAll("%name", ref.name);

			BAlert* alert = new BAlert(B_TRANSLATE("DataTranslations - Note"),
				string.String(), B_TRANSLATE("Cancel"),
				B_TRANSLATE("Overwrite"));
			alert->SetShortcut(0, B_ESCAPE);
			if (alert->Go() != 1)
				continue;

			// the original file will be replaced
		}

		// find out whether we need to copy it or not

		status = _Install(target, entry);
		if (status == B_OK) {
			BAlert* alert = new BAlert(B_TRANSLATE("DataTranslations - Note"),
				B_TRANSLATE("The new translator has been installed "
					"successfully."), B_TRANSLATE("OK"));
			alert->Go(NULL);
		} else
			_InstallError(ref.name, status);
	}
}
开发者ID:mmadia,项目名称:Haiku-services-branch,代码行数:69,代码来源:DataTranslations.cpp

示例12: BPoint

void
TBarApp::InitSettings()
{
	desk_settings settings;
	settings.vertical = fDefaultSettings.vertical = true;
	settings.left = fDefaultSettings.left = false;
	settings.top = fDefaultSettings.top = true;
	settings.state = fDefaultSettings.state = kExpandoState;
	settings.width = fDefaultSettings.width = 0;
	settings.switcherLoc = fDefaultSettings.switcherLoc = BPoint(5000, 5000);
	settings.showClock = fDefaultSettings.showClock = true;
	// applications
	settings.trackerAlwaysFirst = fDefaultSettings.trackerAlwaysFirst = false;
	settings.sortRunningApps = fDefaultSettings.sortRunningApps = false;
	settings.superExpando = fDefaultSettings.superExpando = false;
	settings.expandNewTeams = fDefaultSettings.expandNewTeams = false;
	settings.hideLabels = fDefaultSettings.hideLabels = false;
	settings.iconSize = fDefaultSettings.iconSize = kMinimumIconSize;
	// recent items
	settings.recentDocsEnabled = fDefaultSettings.recentDocsEnabled = true;
	settings.recentFoldersEnabled
		= fDefaultSettings.recentFoldersEnabled = true;
	settings.recentAppsEnabled = fDefaultSettings.recentAppsEnabled = true;
	settings.recentDocsCount = fDefaultSettings.recentDocsCount = 10;
	settings.recentFoldersCount = fDefaultSettings.recentFoldersCount = 10;
	settings.recentAppsCount = fDefaultSettings.recentAppsCount = 10;
	// window
	settings.alwaysOnTop = fDefaultSettings.alwaysOnTop = false;
	settings.autoRaise = fDefaultSettings.autoRaise = false;
	settings.autoHide = fDefaultSettings.autoHide = false;

	clock_settings clock;
	clock.showSeconds = false;
	clock.showDayOfWeek = false;
	clock.showTimeZone = false;

	BPath dirPath;
	const char* settingsFileName = "settings";
	const char* clockSettingsFileName = "clock_settings";

	find_directory(B_USER_DESKBAR_DIRECTORY, &dirPath, true);
		// just make it

	if (GetDeskbarSettingsDirectory(dirPath, true) == B_OK) {
		BPath filePath = dirPath;
		filePath.Append(settingsFileName);
		fSettingsFile = new BFile(filePath.Path(), O_RDWR);
		if (fSettingsFile->InitCheck() != B_OK) {
			BDirectory theDir(dirPath.Path());
			if (theDir.InitCheck() == B_OK)
				theDir.CreateFile(settingsFileName, fSettingsFile);
		}

		BMessage prefs;
		if (fSettingsFile->InitCheck() == B_OK
			&& prefs.Unflatten(fSettingsFile) == B_OK) {
			settings.vertical = prefs.GetBool("vertical",
				fDefaultSettings.vertical);
			settings.left = prefs.GetBool("left",
				fDefaultSettings.left);
			settings.top = prefs.GetBool("top",
				fDefaultSettings.top);
			settings.state = prefs.GetInt32("state",
				fDefaultSettings.state);
			settings.width = prefs.GetFloat("width",
				fDefaultSettings.width);
			settings.switcherLoc = prefs.GetPoint("switcherLoc",
				fDefaultSettings.switcherLoc);
			settings.showClock = prefs.GetBool("showClock",
				fDefaultSettings.showClock);
			// applications
			settings.trackerAlwaysFirst = prefs.GetBool("trackerAlwaysFirst",
				fDefaultSettings.trackerAlwaysFirst);
			settings.sortRunningApps = prefs.GetBool("sortRunningApps",
				fDefaultSettings.sortRunningApps);
			settings.superExpando = prefs.GetBool("superExpando",
				fDefaultSettings.superExpando);
			settings.expandNewTeams = prefs.GetBool("expandNewTeams",
				fDefaultSettings.expandNewTeams);
			settings.hideLabels = prefs.GetBool("hideLabels",
				fDefaultSettings.hideLabels);
			settings.iconSize = prefs.GetInt32("iconSize",
				fDefaultSettings.iconSize);
			// recent items
			settings.recentDocsEnabled = prefs.GetBool("recentDocsEnabled",
				fDefaultSettings.recentDocsEnabled);
			settings.recentFoldersEnabled
				= prefs.GetBool("recentFoldersEnabled",
					fDefaultSettings.recentFoldersEnabled);
			settings.recentAppsEnabled = prefs.GetBool("recentAppsEnabled",
				fDefaultSettings.recentAppsEnabled);
			settings.recentDocsCount = prefs.GetInt32("recentDocsCount",
				fDefaultSettings.recentDocsCount);
			settings.recentFoldersCount = prefs.GetInt32("recentFoldersCount",
				fDefaultSettings.recentFoldersCount);
			settings.recentAppsCount = prefs.GetInt32("recentAppsCount",
				fDefaultSettings.recentAppsCount);
			// window
			settings.alwaysOnTop = prefs.GetBool("alwaysOnTop",
				fDefaultSettings.alwaysOnTop);
//.........这里部分代码省略.........
开发者ID:kbjava,项目名称:haiku,代码行数:101,代码来源:BarApp.cpp

示例13: printf

status_t
AGMSBayesianSpamFilter::ProcessMailMessage (
	BPositionIO** io_message,
	BEntry* io_entry,
	BMessage* io_headers,
	BPath* io_folder,
	const char* io_uid)
{
	ssize_t		 amountRead;
	attr_info	 attributeInfo;
	const char	*classificationString;
	off_t		 dataSize;
	BPositionIO	*dataStreamPntr = *io_message;
	status_t	 errorCode = B_OK;
	int32        headerLength;
	BString      headerString;
	BString		 newSubjectString;
	BNode        nodeForOutputFile;
	bool		 nodeForOutputFileInitialised = false;
	const char	*oldSubjectStringPntr;
	char         percentageString [30];
	BMessage	 replyMessage;
	BMessage	 scriptingMessage;
	team_id		 serverTeam;
	float		 spamRatio;
	char		*stringBuffer = NULL;
	char         tempChar;
	status_t     tempErrorCode;
	const char  *tokenizeModeStringPntr;

	// Set up a BNode to the final output file so that we can write custom
	// attributes to it.  Non-custom attributes are stored separately in
	// io_headers.

	if (io_entry != NULL && B_OK == nodeForOutputFile.SetTo (io_entry))
		nodeForOutputFileInitialised = true;

	// Get a connection to the spam database server.  Launch if needed, should
	// only need it once, unless another e-mail thread shuts down the server
	// inbetween messages.  This code used to be in InitCheck, but apparently
	// that isn't called.

	printf("Checking for Spam Server.\n");
	if (fLaunchAttemptCount == 0 || !fMessengerToServer.IsValid ()) {
		if (fLaunchAttemptCount > 3)
			goto ErrorExit; // Don't try to start the server too many times.
		fLaunchAttemptCount++;

		// Make sure the server is running.
		if (!be_roster->IsRunning (kServerSignature)) {
			errorCode = be_roster->Launch (kServerSignature);
			if (errorCode != B_OK) {
				BPath path;
				entry_ref ref;
				directory_which places[] = {B_COMMON_BIN_DIRECTORY,B_BEOS_BIN_DIRECTORY};
				for (int32 i = 0; i < 2; i++) {
					find_directory(places[i],&path);
					path.Append("spamdbm");
					if (!BEntry(path.Path()).Exists())
						continue;
					get_ref_for_path(path.Path(),&ref);
					if ((errorCode =  be_roster->Launch (&ref)) == B_OK)
						break;
				}
				if (errorCode != B_OK)
					goto ErrorExit;
			}
		}

		// Set up the messenger to the database server.
		serverTeam = be_roster->TeamFor (kServerSignature);
		if (serverTeam < 0)
			goto ErrorExit;
		fMessengerToServer =
			BMessenger (kServerSignature, serverTeam, &errorCode);
		if (!fMessengerToServer.IsValid ())
			goto ErrorExit;

		// Check if the server is running in headers only mode.  If so, we only
		// need to download the header rather than the entire message.
		scriptingMessage.MakeEmpty ();
		scriptingMessage.what = B_GET_PROPERTY;
		scriptingMessage.AddSpecifier ("TokenizeMode");
		replyMessage.MakeEmpty ();
		if ((errorCode = fMessengerToServer.SendMessage (&scriptingMessage,
			&replyMessage)) != B_OK)
			goto ErrorExit;
		if ((errorCode = replyMessage.FindInt32 ("error", &tempErrorCode))
			!= B_OK)
			goto ErrorExit;
		if ((errorCode = tempErrorCode) != B_OK)
			goto ErrorExit;
		if ((errorCode = replyMessage.FindString ("result",
			&tokenizeModeStringPntr)) != B_OK)
			goto ErrorExit;
		fHeaderOnly = (tokenizeModeStringPntr != NULL
			&& strcmp (tokenizeModeStringPntr, "JustHeader") == 0);
	}

	// See if the message has already been classified.  Happens for messages
//.........这里部分代码省略.........
开发者ID:luciang,项目名称:haiku,代码行数:101,代码来源:SpamFilter.cpp

示例14: DeleteAllLanguageFilesAndList

bool
MSHLanguageMgr::LoadLanguageFiles(const char * pathToFileStub)
{
	if (NULL != fTransFiles) {
		DeleteAllLanguageFilesAndList();
	}

	fTransFiles = new BList();

	// Sanity check.
	if (NULL == fTransFiles) {
		return false;
	}

	bool loadedAtLeastOne = false;

	// Create a list of MSHLanguageFiles, one for each file found at
	// the passed-in location, using the included stub file prefix.
	fFileNameStub = "";
	BString pathAndStub(pathToFileStub);
	BString pathOnly = "";

	// Obtain the path component separately from the file name stub.
	const int32 posOfLastFolderSlash = pathAndStub.FindLast('/');
	if (B_ERROR == posOfLastFolderSlash) {
		// Must be just a filename.
		fFileNameStub = pathAndStub;
	} else {
		pathAndStub.CopyInto(pathOnly, 0 /*sourceOffset*/, posOfLastFolderSlash);
		if (pathAndStub.Length() >= (posOfLastFolderSlash + 1)) {
			pathAndStub.CopyInto(fFileNameStub, (posOfLastFolderSlash + 1), (pathAndStub.Length() - 1));
		}
	}

	if (fFileNameStub.Length() > 0) {

		// Check for a relative path. If relative, then add the app directory to the start.
		if ((pathOnly == "") || (pathOnly.FindFirst('/') > 0)) {
			app_info ai;
			be_app->GetAppInfo(&ai);
			BEntry appEntry(&ai.ref);
			BPath appPathWithLeafName;
			appEntry.GetPath(&appPathWithLeafName);
			BPath appPathOnly;
			appPathWithLeafName.GetParent(&appPathOnly);
			appPathWithLeafName.Unset();

			if (pathOnly.FindLast('/') != (pathOnly.Length() - 1)) {
				pathOnly.Prepend("/");
			}
			pathOnly.Prepend(appPathOnly.Path());
			appPathOnly.Unset();
			appEntry.Unset();			
		}

		if (pathOnly.Length() > 0) {
			// Find all files in the specified directory that have a name beginning
			// with the specified stub.
			char nameBuffer[B_FILE_NAME_LENGTH];
			BDirectory langDir(pathOnly.String());
			BEntry nextEntry;
			while (langDir.GetNextEntry(&nextEntry) == B_OK) {
				if (B_OK == nextEntry.GetName(nameBuffer)) {
					BString nameStr(nameBuffer);
					if (nameStr.FindFirst(fFileNameStub) == 0) {
						// We have a winner! Matching stub on filename (after adding on path)
						nameStr.Prepend("/");
						nameStr.Prepend(pathOnly);
						MSHLanguageFile* newLangFile = new MSHLanguageFile(nameStr.String());
						fTransFiles->AddItem(newLangFile);
						loadedAtLeastOne = true;
					}
				}
				nextEntry.Unset();
			}
		}
	}

	if (!loadedAtLeastOne) {
		DeleteAllLanguageFilesAndList();
	}

	return loadedAtLeastOne;
}
开发者ID:carriercomm,项目名称:Helios,代码行数:84,代码来源:MSHLanguageMgr.cpp

示例15: entry

bool
FavoritesMenu::AddNextItem()
{
	// run the next chunk of code for a given item adding state

	if (fState == kStart) {
		fState = kAddingFavorites;
		fSectionItemCount = 0;
		fAddedSeparatorForSection = false;
		// set up adding the GoTo menu items

		try {
			BPath path;
			ThrowOnError(find_directory(B_USER_SETTINGS_DIRECTORY,
				&path, true));
			path.Append(kGoDirectory);
			mkdir(path.Path(), 0777);

			BEntry entry(path.Path());
			Model startModel(&entry, true);
			ThrowOnInitCheckError(&startModel);

			if (!startModel.IsContainer())
				throw B_ERROR;

			if (startModel.IsQuery())
				fContainer = new QueryEntryListCollection(&startModel);
			else if (startModel.IsVirtualDirectory())
				fContainer = new VirtualDirectoryEntryList(&startModel);
			else {
				fContainer = new DirectoryEntryList(*dynamic_cast<BDirectory*>
					(startModel.Node()));
			}

			ThrowOnInitCheckError(fContainer);
			ThrowOnError( fContainer->Rewind() );
		} catch (...) {
			delete fContainer;
			fContainer = NULL;
		}
	}

	if (fState == kAddingFavorites) {
		entry_ref ref;
		if (fContainer != NULL && fContainer->GetNextRef(&ref) == B_OK) {
			Model model(&ref, true);
			if (model.InitCheck() != B_OK)
				return true;

			if (!ShouldShowModel(&model))
				return true;

			BMenuItem* item = BNavMenu::NewModelItem(&model,
				model.IsDirectory() ? fOpenFolderMessage : fOpenFileMessage,
				fTarget);

			if (item == NULL)
				return true;

			item->SetLabel(ref.name);
				// this is the name of the link in the Go dir

			if (!fAddedSeparatorForSection) {
				fAddedSeparatorForSection = true;
				AddItem(new TitledSeparatorItem(B_TRANSLATE("Favorites")));
			}
			fUniqueRefCheck.push_back(*model.EntryRef());
			AddItem(item);
			fSectionItemCount++;

			return true;
		}

		// done with favorites, set up for adding recent files
		fState = kAddingFiles;

		fAddedSeparatorForSection = false;

		app_info info;
		be_app->GetAppInfo(&info);
		fItems.MakeEmpty();

		int32 apps, docs, folders;
		TrackerSettings().RecentCounts(&apps, &docs, &folders);

		BRoster().GetRecentDocuments(&fItems, docs, NULL, info.signature);
		fIndex = 0;
		fSectionItemCount = 0;
	}

	if (fState == kAddingFiles) {
		//	if this is a Save panel, not an Open panel
		//	then don't add the recent documents
		if (!fIsSavePanel) {
			for (;;) {
				entry_ref ref;
				if (fItems.FindRef("refs", fIndex++, &ref) != B_OK)
					break;

				Model model(&ref, true);
//.........这里部分代码省略.........
开发者ID:mylegacy,项目名称:haiku,代码行数:101,代码来源:FavoritesMenu.cpp


注:本文中的BPath类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。