1/*****************************************************************************/ 2// BeUtils.cpp 3// 4// Version: 1.0.0d1 5// 6// Several utilities for writing applications for the BeOS. It are small 7// very specific functions, but generally useful (could be here because of a 8// lack in the APIs, or just sheer lazyness :)) 9// 10// Author 11// Ithamar R. Adema 12// Michael Pfeiffer 13// 14// This application and all source files used in its construction, except 15// where noted, are licensed under the MIT License, and have been written 16// and are: 17// 18// Copyright (c) 2001, 2002 Haiku Project 19// 20// Permission is hereby granted, free of charge, to any person obtaining a 21// copy of this software and associated documentation files (the "Software"), 22// to deal in the Software without restriction, including without limitation 23// the rights to use, copy, modify, merge, publish, distribute, sublicense, 24// and/or sell copies of the Software, and to permit persons to whom the 25// Software is furnished to do so, subject to the following conditions: 26// 27// The above copyright notice and this permission notice shall be included 28// in all copies or substantial portions of the Software. 29// 30// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 31// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 32// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 33// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 34// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 35// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 36// DEALINGS IN THE SOFTWARE. 37/*****************************************************************************/ 38 39#include <Application.h> 40#include <Bitmap.h> 41#include <Messenger.h> 42#include <Resources.h> 43#include <Roster.h> 44#include <String.h> 45 46#include "BeUtils.h" 47 48 49// --------------------------------------------------------------- 50// TestForAddonExistence 51// 52// [Method Description] 53// 54// Parameters: 55// 56// Returns: 57// --------------------------------------------------------------- 58status_t TestForAddonExistence(const char* name, directory_which which, const char* section, BPath& outPath) 59{ 60 status_t err = B_OK; 61 62 if ((err=find_directory(which, &outPath)) == B_OK && 63 (err=outPath.Append(section)) == B_OK && 64 (err=outPath.Append(name)) == B_OK) 65 { 66 struct stat buf; 67 err = stat(outPath.Path(), &buf); 68 } 69 70 return err; 71} 72 73// Implementation of Object 74 75Object::~Object() { 76} 77 78// Implementation of AutoReply 79 80AutoReply::AutoReply(BMessage* sender, uint32 what) 81 : fSender(sender) 82 , fReply(what) 83{ 84} 85 86AutoReply::~AutoReply() { 87 fSender->SendReply(&fReply); 88 delete fSender; 89} 90 91bool MimeTypeForSender(BMessage* sender, BString& mime) { 92 BMessenger msgr = sender->ReturnAddress(); 93 team_id team = msgr.Team(); 94 app_info info; 95 if (be_roster->GetRunningAppInfo(team, &info) == B_OK) { 96 mime = info.signature; 97 return true; 98 } 99 return false; 100} 101