1/* 2 * Copyright 2006, 2011, 2013 Stephan A��mus <superstippi@gmx.de> 3 * All rights reserved. Distributed under the terms of the MIT License. 4 */ 5 6#include "support.h" 7 8#include <algorithm> 9#include <stdio.h> 10#include <string.h> 11 12#include <Application.h> 13#include <Directory.h> 14#include <File.h> 15#include <FindDirectory.h> 16#include <Font.h> 17#include <Path.h> 18#include <Resources.h> 19#include <Roster.h> 20#include <Screen.h> 21#include <View.h> 22 23 24status_t 25load_settings(BMessage* message, const char* fileName, const char* folder) 26{ 27 if (message == NULL || fileName == NULL || fileName[0] == '\0') 28 return B_BAD_VALUE; 29 30 BPath path; 31 status_t ret = find_directory(B_USER_SETTINGS_DIRECTORY, &path); 32 if (ret != B_OK) 33 return ret; 34 35 // passing folder is optional 36 if (folder != NULL) 37 ret = path.Append(folder); 38 39 if (ret == B_OK && (ret = path.Append(fileName)) == B_OK ) { 40 BFile file(path.Path(), B_READ_ONLY); 41 ret = file.InitCheck(); 42 if (ret == B_OK) 43 ret = message->Unflatten(&file); 44 } 45 46 return ret; 47} 48 49 50status_t 51save_settings(const BMessage* message, const char* fileName, const char* folder) 52{ 53 if (message == NULL || fileName == NULL || fileName[0] == '\0') 54 return B_BAD_VALUE; 55 56 BPath path; 57 status_t ret = find_directory(B_USER_SETTINGS_DIRECTORY, &path); 58 if (ret != B_OK) 59 return ret; 60 61 // passing folder is optional 62 if (folder != NULL) 63 ret = path.Append(folder); 64 65 if (ret == B_OK) 66 ret = create_directory(path.Path(), 0777); 67 68 if (ret == B_OK) 69 ret = path.Append(fileName); 70 71 if (ret == B_OK) { 72 BFile file(path.Path(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE); 73 ret = file.InitCheck(); 74 if (ret == B_OK) 75 ret = message->Flatten(&file); 76 } 77 78 return ret; 79} 80 81 82status_t 83get_app_resources(BResources& resources) 84{ 85 app_info info; 86 status_t status = be_app->GetAppInfo(&info); 87 if (status != B_OK) 88 return status; 89 90 return resources.SetTo(&info.ref); 91} 92 93 94void 95set_small_font(BView* view) 96{ 97 BFont font; 98 view->GetFont(&font); 99 font.SetSize(ceilf(font.Size() * 0.8)); 100 view->SetFont(&font); 101} 102 103 104 105 106