repository_infos: Enable automatic updates on the main Haiku repostiory.
[haiku.git] / src / apps / haikudepot / ui_generic / support.cpp
blob5d2e25ecd7cc91157d6add2589a262a0c10ad18e
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 */
6 #include "support.h"
8 #include <algorithm>
9 #include <stdio.h>
10 #include <string.h>
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>
24 status_t
25 load_settings(BMessage* message, const char* fileName, const char* folder)
27 if (message == NULL || fileName == NULL || fileName[0] == '\0')
28 return B_BAD_VALUE;
30 BPath path;
31 status_t ret = find_directory(B_USER_SETTINGS_DIRECTORY, &path);
32 if (ret != B_OK)
33 return ret;
35 // passing folder is optional
36 if (folder != NULL)
37 ret = path.Append(folder);
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);
46 return ret;
50 status_t
51 save_settings(const BMessage* message, const char* fileName, const char* folder)
53 if (message == NULL || fileName == NULL || fileName[0] == '\0')
54 return B_BAD_VALUE;
56 BPath path;
57 status_t ret = find_directory(B_USER_SETTINGS_DIRECTORY, &path);
58 if (ret != B_OK)
59 return ret;
61 // passing folder is optional
62 if (folder != NULL)
63 ret = path.Append(folder);
65 if (ret == B_OK)
66 ret = create_directory(path.Path(), 0777);
68 if (ret == B_OK)
69 ret = path.Append(fileName);
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);
78 return ret;
82 status_t
83 get_app_resources(BResources& resources)
85 app_info info;
86 status_t status = be_app->GetAppInfo(&info);
87 if (status != B_OK)
88 return status;
90 return resources.SetTo(&info.ref);
94 void
95 set_small_font(BView* view)
97 BFont font;
98 view->GetFont(&font);
99 font.SetSize(ceilf(font.Size() * 0.8));
100 view->SetFont(&font);