本文整理汇总了C++中BEntry::Unset方法的典型用法代码示例。如果您正苦于以下问题:C++ BEntry::Unset方法的具体用法?C++ BEntry::Unset怎么用?C++ BEntry::Unset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BEntry
的用法示例。
在下文中一共展示了BEntry::Unset方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: file
/*! \brief Perform the desired activity
* \details This function is the central function of the activity mechanism.
* However, it does not display the notification message - mainly because
* it has no idea about the Event it belongs to, therefore it doesn't know
* the Event's name, category, and can't handle the "Snooze" message.
* \param[in] in Pointer to the \c Activity to be performed.
*/
void ActivityData::PerformActivity( ActivityData* in )
{
if ( !in ) { return; }
BEntry entry;
entry_ref fileRef, appRef;
BPath path;
BString tempString, anotherTempString;
int thread_id;
// The notification will be displayed separately
// Run a program
if ( in->GetProgram( &path, &tempString ) )
{
entry.SetTo( path.Path(), true ); // Find the application to run
if ( ( entry.InitCheck() == B_OK ) && // The initialization passed
( entry.Exists() ) && // The entry exists
( entry.GetPath( &path ) == B_OK ) ) // Got path to file (which may be not what the user entered)
{
entry.Unset(); // Don't need the entry anymore
anotherTempString.SetTo( path.Path() );
anotherTempString << ' ';
tempString.Prepend( anotherTempString );
// Launch the program!
thread_id = fork();
if ( thread_id == 0 ) {
system( tempString.String() );
}
}
}
// Play a sound file
if ( in->GetSound( &path ) ) {
entry.SetTo( path.Path(), true ); // Find the file to play
if ( ( entry.InitCheck() == B_OK ) && // The initialization passed
( entry.Exists() ) && // The file exists
( entry.GetRef( &fileRef ) == B_OK ) && // Got the reference to the file
( be_roster->Launch( &fileRef ) == B_OK ) ) // Launched the file!
{
entry.Unset(); // Close the file descriptor
// Launch was already performed
}
}
} // <-- end of function ActivityData::PerformActivity
示例2:
static void
close_output_file()
{
if (rdef_err == B_OK || (flags & RDEF_MERGE_RESOURCES) != 0)
rsrc.Sync();
else
entry.Remove(); // throw away output file
file.Unset();
entry.Unset();
}
示例3: MountImage
// Mounts the specified image file (filename) assuming it contains the
// specified file system.
int app::MountImage(const char *filename, const char *filesystem) {
int timeout=3;
int retvalue;
BString mountpoint;
BEntry entry;
int mountpoint_counter=0;
do {
mountpoint="/";
mountpoint.Append(FindMountPointName(filename));
while (mountpoint[mountpoint.Length()-1]==0x20)
mountpoint.RemoveLast(" ");
if (mountpoint_counter>0)
mountpoint << " " << mountpoint_counter;
entry.SetTo(mountpoint.String());
mountpoint_counter++;
} while(entry.Exists());
CreateDirectory(mountpoint.String());
while ((retvalue=mount(filesystem,mountpoint.String(),filename,2,NULL,0))<0) {
snooze(100000); // omg! ;)
timeout--;
if (timeout==0) {
entry.Remove();
mountpoint_counter--;
entry.Unset();
return -1;
}
};
printf("mounted.\nfilename:\t%s\nfilesystem:\t%s\nmountpoint:\t%s\n", filename, filesystem, mountpoint.String());
if (retvalue<0) {
entry.Remove();
mountpoint_counter--;
}
entry.Unset();
return retvalue;
}
示例4: MessageReceived
/*! \brief Main function of the class.
* \param[in] in BMessage to respond to.
*/
void EventEditorMainWindow::MessageReceived( BMessage *in )
{
BView* view;
BEntry entry;
BFile file;
BString tempString;
BDirectory directory;
BMessage saveMessage( kSaveRequested );
entry_ref ref;
switch( in->what )
{
case B_SELECT_ALL:
case B_COPY:
case B_CUT:
case B_PASTE:
case B_UNDO:
view = CurrentFocus();
if ( view )
view->MessageReceived( in );
break;
case kFileOpen:
fOpenFile->Show();
break;
case kFileSaveAs:
fSaveFile->Show();
break;
case kFileRevert: // Intentional fall-through
case kFileOpenConfirmed:
if ( in->what == kFileRevert ) {
if ( fData.GetRef() != NULL )
{
// ...Prepare it for usage
ref = *( fData.GetRef() );
} else {
// Ask the user what to do
fOpenFile->Show();
break;
}
} else {
if ( B_OK != in->FindRef( "refs", &ref ) ||
B_OK != entry.SetTo( &ref, true ) ||
B_OK != entry.GetRef( &ref ) )
{
entry.Unset();
break;
}
}
fData.InitFromFile( ref );
if ( Looper()->Lock() ) {
// fData.Revert();
MainView->RemoveSelf();
delete MainView;
InitUI();
Looper()->Unlock();
}
entry.Unset();
break;
case kFileSave: // Intentional fall-through
case kFileSaveConfirmed:
// Save user's changes
if ( genView ) genView->MessageReceived( &saveMessage );
if ( remView ) remView->MessageReceived( &saveMessage );
if ( actView ) actView->SaveData();
if ( noteView ) noteView->SaveText();
fData.SetEventActivityFired( false );
fData.SetReminderActivityFired( false );
// If we have the reference to file...
if ( in->what == kFileSave ) {
if ( fData.GetRef() != NULL )
{
// ...Prepare it for usage
ref = *( fData.GetRef() );
} else {
// Ask the user what to do
fSaveFile->Show();
break;
}
} else {
if ( B_OK != in->FindRef( "directory", &ref ) ||
B_OK != in->FindString( "name", &tempString ) ||
B_OK != directory.SetTo( &ref ) ||
B_OK != directory.CreateFile( tempString.String(), NULL, false ) ||
B_OK != directory.FindEntry( tempString.String(), &entry, true ) ||
B_OK != entry.GetRef( &ref ) )
{
break;
}
//.........这里部分代码省略.........
示例5: BMessenger
/*! \brief Creates and initializes the file panels.
*
*/
void EventEditorMainWindow::InitializeFilePanels( BString path )
{
BPath eventualDirectoryPath;
BPath pathToFile;
bool initToDefaults = false;
BDirectory parentDirectory, eventualDirectory;
status_t status;
// Initializing from a submitted path
do {
if ( path != BString("") ) {
pathToFile.SetTo( path.String() );
if ( ( pathToFile.InitCheck() != B_OK ) ||
( pathToFile.GetParent( &eventualDirectoryPath ) != B_OK ) ||
( eventualDirectory.SetTo( eventualDirectoryPath.Path() ) != B_OK ) )
{
initToDefaults = true;
break; // Go to after "while"
}
}
else
{
initToDefaults = true;
}
} while ( false );
// Else, initialize to defaults
if ( initToDefaults )
{
find_directory( B_USER_DIRECTORY,
&eventualDirectoryPath,
true ); // Useless flag - system can't boot without "home"
parentDirectory.SetTo( eventualDirectoryPath.Path() );
status = parentDirectory.CreateDirectory( "events", &eventualDirectory );
if ( status == B_FILE_EXISTS ) {
eventualDirectory.SetTo( &parentDirectory, "events" );
status = eventualDirectory.InitCheck();
}
if ( status != B_OK )
{
global_toReturn = ( uint32 )status;
be_app->PostMessage( B_QUIT_REQUESTED );
}
} // <-- end of setting default directories
// At this point, eventualDirectory is set to the directory where files
// should be stored.
BEntry entry;
entry_ref ref;
eventualDirectory.GetEntry( &entry );
entry.GetRef( &ref );
// Construct file panels
fOpenFile = new BFilePanel( B_OPEN_PANEL,
new BMessenger( Looper(), this ),
&ref,
B_FILE_NODE,
false,
new BMessage( kFileOpenConfirmed ),
fRefFilter );
fSaveFile = new BFilePanel( B_SAVE_PANEL,
new BMessenger( Looper(), this ),
&ref,
B_FILE_NODE,
false,
new BMessage( kFileSaveConfirmed ),
fRefFilter );
entry.Unset();
if ( !fOpenFile || !fSaveFile ) {
global_toReturn = ( uint32 )B_NO_MEMORY;
be_app->PostMessage( B_QUIT_REQUESTED );
}
} // <-- end of function EventEditorMainWindow::InitializeFilePanels
示例6: MessageReceived
void FileChooser::MessageReceived(BMessage* msg)
{
switch (msg->what) {
case SELECTION_MESSAGE: {
if (listView->CurrentSelection() == NULL)
okB->SetEnabled(false);
else
okB->SetEnabled(true);
break;
}
case B_REFS_RECEIVED:
case B_SIMPLE_DATA: {
uint32 type;
int32 count;
BEntry* entry = new BEntry();
entry_ref ref;
msg->GetInfo("refs", &type, &count);
if (type != B_REF_TYPE) {
delete entry;
break;
}
if (msg->FindRef("refs", 0, &ref) == B_OK)
if (entry->SetTo(&ref, true) == B_OK) this->AddFile(entry);
entry->Unset();
delete entry;
break;
}
case OK_BUTTON_MSG: {
filename = ((FolderRow*)listView->CurrentSelection())->GetFilename();
release_sem(sem);
Quit();
break;
}
case CANCEL_BUTTON_MSG: {
filename = "";
release_sem(sem);
Quit();
break;
}
case B_QUIT_REQUESTED: {
filename = "";
release_sem(sem);
break;
}
case B_CANCEL: {
delete filepanel;
break;
}
case BROWSE_BUTTON_MSG: {
FileDialog::fmainWindow = NULL;
FileDialog::fSourceWindow = this;
BEntry* entry = FileDialog::OpenDialog(NULL, "/boot/home/config/bin/");
this->AddFile(entry);
entry->Unset();
delete entry;
break;
}
default: {
BWindow::MessageReceived(msg);
break;
}
}
}
示例7: HandleRequest
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
//.........这里部分代码省略.........
示例8: pathAndStub
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;
}
示例9: YabFilePanelLooper
BEntry *YabFilePanel::MyFilePanel(const char *name, const char *directory, const char* filename, int mode)
{
BEntry *myEntry = NULL;
entry_ref ref;
sem_id semaphore = create_sem(0, "yabfilepanel");
YabFilePanelLooper *myLooper = new YabFilePanelLooper(semaphore);
myLooper->Run();
if(directory)
{
myEntry=new BEntry(directory);
if(myEntry->GetRef(&ref)!=B_OK)
{
myEntry->Unset();
myEntry->SetTo("/boot/home/");
myEntry->GetRef(&ref);
}
myEntry->Unset();
delete myEntry;
}
BFilePanel *myFilePanel = NULL;
switch(mode)
{
case 0:
myFilePanel = new BFilePanel(B_OPEN_PANEL, new BMessenger(myLooper, myLooper), &ref, B_FILE_NODE, false, NULL, NULL, true, true);
break;
case 1:
myFilePanel = new BFilePanel(B_SAVE_PANEL, new BMessenger(myLooper, myLooper), &ref, B_FILE_NODE, false, NULL, NULL, true, true);
if (filename) myFilePanel->SetSaveText(filename);
break;
case 2:
myFilePanel = new BFilePanel(B_OPEN_PANEL, new BMessenger(myLooper, myLooper), &ref, B_DIRECTORY_NODE, false, NULL, NULL, true, true);
break;
case 3:
myFilePanel = new BFilePanel(B_OPEN_PANEL, new BMessenger(myLooper, myLooper), &ref, B_FILE_NODE|B_DIRECTORY_NODE, false, NULL, NULL, true, true);
break;
}
if(name) myFilePanel->Window()->SetTitle(name);
myFilePanel->Show();
bool inloop = true;
while(inloop)
{
while(acquire_sem_etc(semaphore, 1, B_RELATIVE_TIMEOUT, 10000)==B_TIMED_OUT) ;
myEntry = myLooper->GetChosenFile();
inloop = false;
/*
if(mode!=2)
inloop = false;
else
{
if(myEntry->IsDirectory())
inloop = false;
else
{
myFilePanel->Show();
}
}
*/
}
myLooper->Lock();
myLooper->Quit();
delete_sem(semaphore);
delete myFilePanel;
return myEntry;
}
示例10: equals
// MakeLinkedPathTest
void
SymLinkTest::MakeLinkedPathTest()
{
const char *dirLink = dirLinkname;
const char *fileLink = fileLinkname;
const char *relDirLink = relDirLinkname;
const char *relFileLink = relFileLinkname;
const char *cyclicLink1 = cyclicLinkname1;
const char *cyclicLink2 = cyclicLinkname2;
const char *existingDir = existingDirname;
const char *existingSuperDir = existingSuperDirname;
const char *existingFile = existingFilename;
const char *existingSuperFile = existingSuperFilename;
const char *nonExisting = nonExistingDirname;
BSymLink link;
BPath path;
// 1. MakeLinkedPath(const char*, BPath*)
// uninitialized
NextSubTest();
CPPUNIT_ASSERT( link.InitCheck() == B_NO_INIT );
CPPUNIT_ASSERT( equals(link.MakeLinkedPath("/boot", &path), B_BAD_ADDRESS,
B_FILE_ERROR) );
link.Unset();
path.Unset();
// existing absolute dir link
NextSubTest();
CPPUNIT_ASSERT( link.SetTo(dirLink) == B_OK );
CPPUNIT_ASSERT( link.MakeLinkedPath("/boot", &path)
== (ssize_t)strlen(existingDir) );
CPPUNIT_ASSERT( path.InitCheck() == B_OK );
CPPUNIT_ASSERT( string(existingDir) == path.Path() );
link.Unset();
path.Unset();
// existing absolute file link
NextSubTest();
CPPUNIT_ASSERT( link.SetTo(fileLink) == B_OK );
CPPUNIT_ASSERT( link.MakeLinkedPath("/boot", &path)
== (ssize_t)strlen(existingFile) );
CPPUNIT_ASSERT( path.InitCheck() == B_OK );
CPPUNIT_ASSERT( string(existingFile) == path.Path() );
link.Unset();
path.Unset();
// existing absolute cyclic link
NextSubTest();
CPPUNIT_ASSERT( link.SetTo(cyclicLink1) == B_OK );
CPPUNIT_ASSERT( link.MakeLinkedPath("/boot", &path)
== (ssize_t)strlen(cyclicLink2) );
CPPUNIT_ASSERT( path.InitCheck() == B_OK );
CPPUNIT_ASSERT( string(cyclicLink2) == path.Path() );
link.Unset();
path.Unset();
// existing relative dir link
NextSubTest();
BEntry entry;
BPath entryPath;
CPPUNIT_ASSERT( entry.SetTo(existingDir) == B_OK );
CPPUNIT_ASSERT( entry.GetPath(&entryPath) == B_OK );
CPPUNIT_ASSERT( link.SetTo(relDirLink) == B_OK );
CPPUNIT_ASSERT( link.MakeLinkedPath(existingSuperDir, &path)
== (ssize_t)strlen(entryPath.Path()) );
CPPUNIT_ASSERT( path.InitCheck() == B_OK );
CPPUNIT_ASSERT( entryPath == path );
link.Unset();
path.Unset();
entry.Unset();
entryPath.Unset();
// existing relative file link
NextSubTest();
CPPUNIT_ASSERT( entry.SetTo(existingFile) == B_OK );
CPPUNIT_ASSERT( entry.GetPath(&entryPath) == B_OK );
CPPUNIT_ASSERT( link.SetTo(relFileLink) == B_OK );
CPPUNIT_ASSERT( link.MakeLinkedPath(existingSuperFile, &path)
== (ssize_t)strlen(entryPath.Path()) );
CPPUNIT_ASSERT( path.InitCheck() == B_OK );
CPPUNIT_ASSERT( entryPath == path );
link.Unset();
path.Unset();
entry.Unset();
entryPath.Unset();
// bad args
NextSubTest();
CPPUNIT_ASSERT( link.SetTo(dirLink) == B_OK );
// R5: crashs, when passing a NULL path
#if !TEST_R5
CPPUNIT_ASSERT( link.MakeLinkedPath("/boot", NULL) == B_BAD_VALUE );
#endif
CPPUNIT_ASSERT( link.MakeLinkedPath((const char*)NULL, &path)
== B_BAD_VALUE );
// R5: crashs, when passing a NULL path
#if !TEST_R5
CPPUNIT_ASSERT( link.MakeLinkedPath((const char*)NULL, NULL)
== B_BAD_VALUE );
#endif
link.Unset();
path.Unset();
// 2. MakeLinkedPath(const BDirectory*, BPath*)
// uninitialized
NextSubTest();
//.........这里部分代码省略.........