xref: /haiku/src/preferences/media/Media.cpp (revision ca8ed5ea660fb6275799a3b7f138b201c41a667b)
1 /*
2  * Copyright 2003-2006, Haiku. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors in chronological order:
6  *		Sikosis
7  *		Jérôme Duval
8  */
9 
10 
11 #include "Media.h"
12 
13 #include <stdio.h>
14 
15 #include <Catalog.h>
16 #include <Locale.h>
17 #include <StorageKit.h>
18 #include <String.h>
19 
20 
21 Media::Media()
22 	:
23 	BApplication(kApplicationSignature),
24 	fIcons(),
25 	fWindow(NULL)
26 {
27 	BRect rect(32, 64, 637, 462);
28 
29 	BPath path;
30 	if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) == B_OK) {
31 		path.Append(SETTINGS_FILE);
32 		BFile file(path.Path(),B_READ_ONLY);
33 		if (file.InitCheck()==B_OK) {
34 			char buffer[255];
35 			ssize_t size = 0;
36 			while ((size = file.Read(buffer, 255)) > 0) {
37 				int32 i = 0;
38 				while (buffer[i] == '#') {
39 					while (i < size && buffer[i] != '\n')
40 						i++;
41 					i++;
42 				}
43 				int32 a, b, c, d;
44 				const char* scanString = " rect = %li,%li,%li,%li";
45 				if (sscanf(&buffer[i], scanString, &a, &b, &c, &d) == 4) {
46 					if (c - a >= rect.IntegerWidth()) {
47 						rect.left = a;
48 						rect.right = c;
49 					}
50 					if (d - b >= rect.IntegerHeight()) {
51 						rect.top = b;
52 						rect.bottom = d;
53 					}
54 				}
55 			}
56 		}
57 	}
58 
59 	MediaListItem::SetIcons(&fIcons);
60 	fWindow = new MediaWindow(rect);
61 }
62 
63 
64 status_t
65 Media::InitCheck()
66 {
67 	if (fWindow)
68 		return fWindow->InitCheck();
69 	return B_OK;
70 }
71 
72 
73 //	#pragma mark -
74 
75 
76 int
77 main(int, char**)
78 {
79 	Media app;
80 	if (app.InitCheck() == B_OK)
81 		app.Run();
82 
83 	return 0;
84 }
85 
86