bool LgiExecute(const char *File, const char *Args, const char *Dir, GAutoString *ErrorMsg) { if (File) { char f[256]; if (ValidStr(Dir)) { sprintf(f, "%s/%s", Dir, File); } else { strcpy(f, File); } BRoster Roster; BEntry Entry(f); entry_ref Ref; if (Entry.GetRef(&Ref) == B_OK) { status_t s = B_ERROR; if (stricmp(f, "/BeOS") == 0 || stricmp(f, "/") == 0 || Entry.IsDirectory()) { char *DirMimeType = "application/x-vnd.Be-directory"; if (Roster.FindApp(DirMimeType, &Ref) == B_OK) { char *Arg[1] = {File}; s = Roster.Launch(&Ref, 1, Arg); } } else { s = Roster.Launch(&Ref); } return s == B_OK || s == B_ALREADY_RUNNING; } else { if (strnicmp(File, "http://", 7) == 0) { if (Roster.FindApp("text/html", &Ref) == B_OK) { /* char *Arg[2] = {Ref.name, File}; return Roster.Launch(&Ref, 2, Arg) == B_OK; */ char *Arg[1] = {File}; status_t s = Roster.Launch(&Ref, 1, Arg); return s == B_OK || s == B_ALREADY_RUNNING; } } } } return false; }
/*! \brief Looks up a localized filename from a catalog. \param localizedFileName A pre-allocated BString object for the result of the lookup. \param ref An entry_ref with an attribute holding data for catalog lookup. \param traverse A boolean to decide if symlinks are to be traversed. \return - \c B_OK: success - \c B_ENTRY_NOT_FOUND: failure. Attribute not found, entry not found in catalog, etc - other error codes: failure Attribute format: "signature:context:string" (no colon in any of signature, context and string) Lookup is done for the top preferred language, only. Lookup fails if a comment is present in the catalog entry. */ status_t BLocaleRoster::GetLocalizedFileName(BString& localizedFileName, const entry_ref& ref, bool traverse) { BString signature; BString context; BString string; status_t status = _PrepareCatalogEntry(ref, signature, context, string, traverse); if (status != B_OK) return status; // Try to get entry_ref for signature from above BRoster roster; entry_ref catalogRef; // The signature is missing application/ signature.Prepend("application/"); status = roster.FindApp(signature, &catalogRef); if (status != B_OK) return status; BCatalog catalog(catalogRef); const char* temp = catalog.GetString(string, context); if (temp == NULL) return B_ENTRY_NOT_FOUND; localizedFileName = temp; return B_OK; }
/*********************************************************** * InstallDeskbarIcon ***********************************************************/ void HDaemonApp::InstallDeskbarIcon() { BDeskbar deskbar; if(deskbar.HasItem( "scooby_daemon" ) == false) { BRoster roster; entry_ref ref; roster.FindApp( APP_SIG , &ref); int32 id; deskbar.AddItem(&ref, &id); } }
void BeGadu::AddDeskbarIcon() { DEBUG_TRACE( "BeGadu::AddDeskbarIcon()\n" ); BDeskbar deskbar; if( !deskbar.HasItem( "BGDeskbar" ) ) { BRoster roster; entry_ref ref; status_t status = roster.FindApp( APP_MIME, &ref ); if( status != B_OK ) { fprintf( stderr, _T("Can't find BeGadu running: %s\n"), strerror( status ) ); return; } status = deskbar.AddItem( &ref ); if( status != B_OK ) { fprintf( stderr, _T("Can't put BeGadu into Deskbar: %s\n"), strerror( status ) ); return; } } }
void MailDaemonApp::InstallDeskbarIcon() { BDeskbar deskbar; if (!deskbar.HasItem("mail_daemon")) { BRoster roster; entry_ref ref; status_t status = roster.FindApp(B_MAIL_DAEMON_SIGNATURE, &ref); if (status < B_OK) { fprintf(stderr, "Can't find application to tell deskbar: %s\n", strerror(status)); return; } status = deskbar.AddItem(&ref); if (status < B_OK) { fprintf(stderr, "Can't add deskbar replicant: %s\n", strerror(status)); return; } } }
/*! Message must contain an archivable view for later rehydration. This function takes over ownership of the provided message on success only. Returns the current replicant ID. */ status_t TReplicantTray::AddIcon(BMessage* archive, int32* id, const entry_ref* addOn) { if (archive == NULL || id == NULL) return B_ERROR; // find entry_ref entry_ref ref; if (addOn) { // Use it if we got it ref = *addOn; } else { const char* signature; status_t status = archive->FindString("add_on", &signature); if (status == B_OK) { BRoster roster; status = roster.FindApp(signature, &ref); } if (status < B_OK) return status; } BFile file; status_t status = file.SetTo(&ref, B_READ_ONLY); if (status < B_OK) return status; node_ref nodeRef; status = file.GetNodeRef(&nodeRef); if (status < B_OK) return status; BEntry entry(&ref, true); // TODO: this resolves an eventual link for the item being added - this // is okay for now, but in multi-user environments, one might want to // have links that carry the be:deskbar_item_status attribute status = entry.InitCheck(); if (status != B_OK) return status; *id = 999; if (archive->what == B_ARCHIVED_OBJECT) archive->what = 0; BRect originalBounds = archive->FindRect("_frame"); // this is a work-around for buggy replicants that change their size in // AttachedToWindow() (such as "SVM") // TODO: check for name collisions? status = fShelf->AddReplicant(archive, BPoint(1, 1)); if (status != B_OK) return status; int32 count = fShelf->CountReplicants(); BView* view; fShelf->ReplicantAt(count - 1, &view, (uint32*)id, NULL); if (originalBounds != view->Bounds()) { // The replicant changed its size when added to the window, so we need // to recompute all over again (it's already done once via // BShelf::AddReplicant() and TReplicantShelf::CanAcceptReplicantView()) RealignReplicants(); } float oldWidth = Bounds().Width(); float oldHeight = Bounds().Height(); float width, height; GetPreferredSize(&width, &height); if (oldWidth != width || oldHeight != height) AdjustPlacement(); // add the item to the add-on list AddItem(*id, nodeRef, entry, addOn != NULL); return B_OK; }
BArchivable* instantiate_object(BMessage* archive, image_id* _id) { status_t statusBuffer; status_t* status = &statusBuffer; if (_id != NULL) status = _id; // Check our params if (archive == NULL) { syslog(LOG_ERR, "instantiate_object failed: NULL BMessage argument"); *status = B_BAD_VALUE; return NULL; } // Get class name from archive const char* className = NULL; status_t err = archive->FindString(B_CLASS_FIELD, &className); if (err) { syslog(LOG_ERR, "instantiate_object failed: Failed to find an entry " "defining the class name (%s).", strerror(err)); *status = B_BAD_VALUE; return NULL; } // Get sig from archive const char* signature = NULL; bool hasSignature = archive->FindString(B_ADD_ON_FIELD, &signature) == B_OK; instantiation_func instantiationFunc = find_instantiation_func(className, signature); // if find_instantiation_func() can't locate Class::Instantiate() // and a signature was specified if (!instantiationFunc && hasSignature) { // use BRoster::FindApp() to locate an app or add-on with the symbol BRoster Roster; entry_ref ref; err = Roster.FindApp(signature, &ref); // if an entry_ref is obtained BEntry entry; if (err == B_OK) err = entry.SetTo(&ref); BPath path; if (err == B_OK) err = entry.GetPath(&path); if (err != B_OK) { syslog(LOG_ERR, "instantiate_object failed: Error finding app " "with signature \"%s\" (%s)", signature, strerror(err)); *status = err; return NULL; } // load the app/add-on image_id addOn = load_add_on(path.Path()); if (addOn < B_OK) { syslog(LOG_ERR, "instantiate_object failed: Could not load " "add-on %s: %s.", path.Path(), strerror(addOn)); *status = addOn; return NULL; } // Save the image_id if (_id != NULL) *_id = addOn; BString name = className; for (int32 pass = 0; pass < 2; pass++) { BString funcName; build_function_name(name, funcName); instantiationFunc = find_function_in_image(funcName, addOn, err); if (instantiationFunc != NULL) break; // Check if we have a private class, and add the BPrivate namespace // (for backwards compatibility) if (!add_private_namespace(name)) break; } if (instantiationFunc == NULL) { syslog(LOG_ERR, "instantiate_object failed: Failed to find exported " "Instantiate static function for class %s.", className); *status = B_NAME_NOT_FOUND; return NULL; } } else if (instantiationFunc == NULL) { syslog(LOG_ERR, "instantiate_object failed: No signature specified " "in archive, looking for class \"%s\".", className); *status = B_NAME_NOT_FOUND; return NULL; } // if Class::Instantiate(BMessage*) was found if (instantiationFunc != NULL) { // use to create and return an object instance return instantiationFunc(archive); } return NULL; }
void BeGadu::MessageReceived( BMessage *aMessage ) { switch( aMessage->what ) { /* sending mesgs from libgadu to network */ case GOT_MESSAGE: case ADD_HANDLER: case DEL_HANDLER: BMessenger( iWindow->GetNetwork() ).SendMessage( aMessage ); break; case ADD_MESSENGER: DEBUG_TRACE( "BeGadu::MessageReceived( ADD_MESSENGER )\n" ); aMessage->FindMessenger( "messenger", &iMessenger ); if( iWindow ) { iWindow->SetMessenger( iMessenger ); BMessenger( iMessenger ).SendMessage( PROFILE_SELECTED ); } break; case SET_AVAIL: case SET_BRB: case SET_INVIS: case SET_NOT_AVAIL: case SET_DESCRIPTION: case BEGG_ABOUT: case SHOW_MAIN_WINDOW: case CHANGE_DESCRIPTION: case PREFERENCES_SWITCH: if( iWindow ) BMessenger( iWindow ).SendMessage( aMessage ); break; case OPEN_PROFILE_WIZARD: { DEBUG_TRACE( "BeGadu::MessageReceived( OPEN_PROFILE_WIZARD )\n" ); // if( iProfileSelector ) // iProfileSelector = NULL; if( iWindow ) { BMessenger( iWindow ).SendMessage( new BMessage( CLOSE_MAIN_WINDOW ) ); if( iWindow->Lock() ) iWindow->Quit(); iWindow = NULL; } ProfileWizard *pw = new ProfileWizard(); pw->Show(); break; } case CONFIG_OK: { DEBUG_TRACE( "BeGadu::MessageReceived( CONFIG_OK )\n" ); iReadyToRun = true; AddDeskbarIcon(); Profile *profile = new Profile(); int ret = profile->Load( iLastProfile ); if( ret != 0 ) { delete profile; BMessenger( be_app ).SendMessage( new BMessage( PROFILE_SELECT ) ); break; } if( strcmp( profile->GetProfilePassword(), "" ) != 0 ) { BResources res; BRoster roster; entry_ref ref; BFile resfile; roster.FindApp( APP_MIME, &ref ); resfile.SetTo( &ref, B_READ_ONLY ); res.SetTo( &resfile ); BScreen *screen = new BScreen( B_MAIN_SCREEN_ID ); display_mode mode; screen->GetMode( &mode ); // int32 width = 250; // int32 height = 110; // 70 // int32 x_wind = mode.timing.h_display / 2 - ( width / 2); // int32 y_wind = mode.timing.v_display / 2 - ( height / 2 ); // int32 new_width = x_wind + width; // x 2 // int32 new_height = y_wind + height; // x 2 BMessenger( iMessenger ).SendMessage( new BMessage( PROFILE_NOT_SELECTED ) ); // iProfileSelector = new ProfileSelector( iLastProfile, BRect( x_wind, y_wind, new_width, new_height ), &res ); // if( iProfileSelector->LockLooper() ) { // iProfileSelector->Show(); // iProfileSelector->UnlockLooper(); // } } else { BMessenger( iMessenger ).SendMessage( new BMessage( PROFILE_SELECTED ) ); iWindow = new MainWindow( iLastProfile ); if( !iHideAtStart ) { if( iWindow->LockLooper() ) { iWindow->Show(); iWindow->UnlockLooper(); } } else { if( iWindow->LockLooper() ) { iWindow->Show(); iWindow->Hide(); iWindow->UnlockLooper(); } } } break; } case PROFILE_CREATED: DEBUG_TRACE( "BeGadu::MessageReceived( PROFILE_CREATED )\n" ); iReadyToRun = true; AddDeskbarIcon(); aMessage->FindString( "ProfileName", iLastProfile ); fprintf( stderr, _T("Setting last profile to %s\n"), iLastProfile->String() ); iFirstRun = false; BMessenger( iMessenger ).SendMessage( new BMessage( PROFILE_SELECTED ) ); iWindow = new MainWindow( iLastProfile ); if( iWindow->LockLooper() ) { if( iWindow->IsHidden() ) iWindow->Show(); else iWindow->Activate(); iWindow->UnlockLooper(); } break; case PROFILE_SELECT: DEBUG_TRACE( "BeGadu::MessageReceived( PROFILE_SELECT )\n" ); // if( iProfileSelector ) // iProfileSelector->Activate(); // else { BResources res; BRoster roster; entry_ref ref; BFile resfile; roster.FindApp( APP_MIME, &ref ); resfile.SetTo( &ref, B_READ_ONLY ); res.SetTo( &resfile ); BScreen *screen = new BScreen( B_MAIN_SCREEN_ID ); display_mode mode; screen->GetMode( &mode ); // int32 width = 250; // int32 height = 110; // 70 // int32 x_wind = mode.timing.h_display / 2 - ( width / 2); // int32 y_wind = mode.timing.v_display / 2 - ( height / 2 ); // int32 new_width = x_wind + width; // x 2 // int32 new_height = y_wind + height; // x 2 BMessenger( iMessenger ).SendMessage( new BMessage( PROFILE_NOT_SELECTED ) ); // iProfileSelector = new ProfileSelector( iLastProfile, BRect( x_wind, y_wind, new_width, new_height ), &res ); // if( iProfileSelector->LockLooper() ) { // iProfileSelector->Show(); // iProfileSelector->UnlockLooper(); // } } break; case PROFILE_SWITCH: { DEBUG_TRACE( "BeGadu::MessageReceived( PROFILE_SWITCH )\n" ); if( iWindow ) { BMessenger( iWindow ).SendMessage( new BMessage( CLOSE_MAIN_WINDOW ) ); if( iWindow->Lock() ) iWindow->Quit(); iWindow = NULL; } Profile* profile = new Profile(); BString* name = new BString( "" ); aMessage->FindString( "iProfileName", name ); int ret = profile->Load( name ); if( ret != 0 ) { delete profile; BMessenger( this ).SendMessage( new BMessage( PROFILE_SELECT ) ); break; } // XXX loaded profile password empty? if( strcmp( profile->GetProfilePassword(), "" ) == 0 ) { BMessenger( iMessenger ).SendMessage( new BMessage( PROFILE_SELECTED ) ); iWindow = new MainWindow( iLastProfile ); // iWindow = new MainWindow( name ); if( iWindow->LockLooper() ) { iWindow->Show(); iWindow->UnlockLooper(); } } else { // XXX what's that for? BResources res; BRoster roster; entry_ref ref; BFile resfile; roster.FindApp( APP_MIME, &ref ); resfile.SetTo( &ref, B_READ_ONLY ); res.SetTo( &resfile ); BScreen *screen = new BScreen( B_MAIN_SCREEN_ID ); display_mode mode; screen->GetMode( &mode ); // int32 width = 250; // int32 height = 110; // 70 // int32 x_wind = mode.timing.h_display / 2 - ( width / 2); // int32 y_wind = mode.timing.v_display / 2 - ( height / 2 ); // int32 new_width = x_wind + width; // x 2 // int32 new_height = y_wind + height; // x 2 BMessenger( iMessenger ).SendMessage( new BMessage( PROFILE_NOT_SELECTED ) ); // iProfileSelector = new ProfileSelector( name, BRect( x_wind, y_wind, new_width, new_height ), &res ); // if( iProfileSelector->LockLooper() ) { // iProfileSelector->Show(); // iProfileSelector->UnlockLooper(); // } } break; } case PROFILE_SELECTED: { DEBUG_TRACE( "BeGadu::MessageReceived( PROFILE_SELECTED )\n" ); // if( iProfileSelector ) // iProfileSelector = NULL; BString *profile = new BString( "" ); aMessage->FindString( "iProfileName", profile ); BMessenger( iMessenger ).SendMessage( new BMessage( PROFILE_SELECTED ) ); iWindow = new MainWindow( profile ); if( !iHideAtStart ) { if( iWindow->LockLooper() ) { iWindow->Show(); iWindow->UnlockLooper(); } } else { if( iWindow->LockLooper() ) { iWindow->Show(); iWindow->Hide(); iWindow->UnlockLooper(); } } break; } case PROFILE_NOT_SELECTED: DEBUG_TRACE( "BeGadu::MessageReceived( PROFILE_NOT_SELECTED )\n" ); // if( iProfileSelector ) // iProfileSelector = NULL; BMessenger( iMessenger ).SendMessage( new BMessage( PROFILE_NOT_SELECTED ) ); break; case BEGG_QUIT: DEBUG_TRACE( "BeGadu::MessageReceived( BEGG_QUIT )\n" ); if( iWindow ) BMessenger( iWindow ).SendMessage( aMessage ); else BMessenger( be_app ).SendMessage( B_QUIT_REQUESTED ); break; default: BApplication::MessageReceived( aMessage ); break; } }