bool BeAIMApplication::SetDeskbarVisibility( bool vis ) { app_info appInfo; BFile file; BAppFileInfo appFileInfo; uint32 appFlags; // get the BAppFileInfo object for this application be_app->GetAppInfo(&appInfo); file.SetTo(&appInfo.ref, B_READ_WRITE); appFileInfo.SetTo(&file); // get the app flags appFileInfo.GetAppFlags(&appFlags); // make the app visible (or not) in the deskbar if( vis ) appFlags &= ~B_BACKGROUND_APP; else appFlags |= B_BACKGROUND_APP; // now set them! appFileInfo.SetAppFlags(appFlags); }
void BApplication::_InitData(const char* signature, bool initGUI, status_t* _error) { DBG(OUT("BApplication::InitData(`%s', %p)\n", signature, _error)); // check whether there exists already an application if (be_app) debugger("2 BApplication objects were created. Only one is allowed."); fServerLink = new BPrivate::PortLink(-1, -1); fServerAllocator = NULL; fInitialWorkspace = 0; //fDraggedMessage = NULL; fReadyToRunCalled = false; // initially, there is no pulse fPulseRunner = NULL; fPulseRate = 0; // check signature fInitError = check_app_signature(signature); fAppName = signature; #ifndef RUN_WITHOUT_REGISTRAR bool isRegistrar = signature && strcasecmp(signature, kRegistrarSignature) == 0; // get team and thread team_id team = Team(); thread_id thread = BPrivate::main_thread_for(team); #endif // get app executable ref entry_ref ref; if (fInitError == B_OK) { fInitError = BPrivate::get_app_ref(&ref); if (fInitError != B_OK) { DBG(OUT("BApplication::InitData(): Failed to get app ref: %s\n", strerror(fInitError))); } } // get the BAppFileInfo and extract the information we need uint32 appFlags = B_REG_DEFAULT_APP_FLAGS; if (fInitError == B_OK) { BAppFileInfo fileInfo; BFile file(&ref, B_READ_ONLY); fInitError = fileInfo.SetTo(&file); if (fInitError == B_OK) { fileInfo.GetAppFlags(&appFlags); char appFileSignature[B_MIME_TYPE_LENGTH]; // compare the file signature and the supplied signature if (fileInfo.GetSignature(appFileSignature) == B_OK && strcasecmp(appFileSignature, signature) != 0) { printf("Signature in rsrc doesn't match constructor arg. (%s, %s)\n", signature, appFileSignature); } } else { DBG(OUT("BApplication::InitData(): Failed to get info from: " "BAppFileInfo: %s\n", strerror(fInitError))); } } #ifndef RUN_WITHOUT_REGISTRAR // check whether be_roster is valid if (fInitError == B_OK && !isRegistrar && !BRoster::Private().IsMessengerValid(false)) { printf("FATAL: be_roster is not valid. Is the registrar running?\n"); fInitError = B_NO_INIT; } // check whether or not we are pre-registered bool preRegistered = false; app_info appInfo; if (fInitError == B_OK && !isRegistrar) { if (BRoster::Private().IsAppRegistered(&ref, team, 0, &preRegistered, &appInfo) != B_OK) { preRegistered = false; } } if (preRegistered) { // we are pre-registered => the app info has been filled in // Check whether we need to replace the looper port with a port // created by the roster. if (appInfo.port >= 0 && appInfo.port != fMsgPort) { delete_port(fMsgPort); fMsgPort = appInfo.port; } else appInfo.port = fMsgPort; // check the signature and correct it, if necessary, also the case if (strcmp(appInfo.signature, fAppName)) BRoster::Private().SetSignature(team, fAppName); // complete the registration fInitError = BRoster::Private().CompleteRegistration(team, thread, appInfo.port); } else if (fInitError == B_OK) { // not pre-registered -- try to register the application team_id otherTeam = -1; // the registrar must not register if (!isRegistrar) { fInitError = BRoster::Private().AddApplication(signature, &ref, appFlags, team, thread, fMsgPort, true, NULL, &otherTeam); if (fInitError != B_OK) { DBG(OUT("BApplication::InitData(): Failed to add app: %s\n", strerror(fInitError))); } } if (fInitError == B_ALREADY_RUNNING) { // An instance is already running and we asked for // single/exclusive launch. Send our argv to the running app. // Do that only, if the app is NOT B_ARGV_ONLY. if (otherTeam >= 0) { BMessenger otherApp(NULL, otherTeam); app_info otherAppInfo; bool argvOnly = be_roster->GetRunningAppInfo(otherTeam, &otherAppInfo) == B_OK && (otherAppInfo.flags & B_ARGV_ONLY) != 0; if (__libc_argc > 1 && !argvOnly) { // create an B_ARGV_RECEIVED message BMessage argvMessage(B_ARGV_RECEIVED); fill_argv_message(argvMessage); // replace the first argv string with the path of the // other application BPath path; if (path.SetTo(&otherAppInfo.ref) == B_OK) argvMessage.ReplaceString("argv", 0, path.Path()); // send the message otherApp.SendMessage(&argvMessage); } else if (!argvOnly) otherApp.SendMessage(B_SILENT_RELAUNCH); } } else if (fInitError == B_OK) { // the registrations was successful // Create a B_ARGV_RECEIVED message and send it to ourselves. // Do that even, if we are B_ARGV_ONLY. // TODO: When BLooper::AddMessage() is done, use that instead of // PostMessage(). DBG(OUT("info: BApplication successfully registered.\n")); if (__libc_argc > 1) { BMessage argvMessage(B_ARGV_RECEIVED); fill_argv_message(argvMessage); PostMessage(&argvMessage, this); } // send a B_READY_TO_RUN message as well PostMessage(B_READY_TO_RUN, this); } else if (fInitError > B_ERRORS_END) { // Registrar internal errors shouldn't fall into the user's hands. fInitError = B_ERROR; } } #else // We need to have ReadyToRun called even when we're not using the registrar PostMessage(B_READY_TO_RUN, this); #endif // ifndef RUN_WITHOUT_REGISTRAR if (fInitError == B_OK) { // TODO: Not completely sure about the order, but this should be close. // init be_app and be_app_messenger be_app = this; be_app_messenger = BMessenger(NULL, this); // set the BHandler's name SetName(ref.name); // create meta MIME BPath path; if (path.SetTo(&ref) == B_OK) create_app_meta_mime(path.Path(), false, true, false); #ifndef RUN_WITHOUT_APP_SERVER // app server connection and IK initialization if (initGUI) fInitError = _InitGUIContext(); #endif // RUN_WITHOUT_APP_SERVER } // Return the error or exit, if there was an error and no error variable // has been supplied. if (_error) { *_error = fInitError; } else if (fInitError != B_OK) { DBG(OUT("BApplication::InitData() failed: %s\n", strerror(fInitError))); exit(0); } DBG(OUT("BApplication::InitData() done\n")); }