xref: /haiku/src/preferences/media/Media.cpp (revision de18d919e7c940b402a6e213f7deb21e2f187e22)
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 <Roster.h>
18 #include <StorageKit.h>
19 #include <String.h>
20 
21 
22 Media::Media()
23 	:
24 	BApplication("application/x-vnd.Haiku-Media"),
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 	fWindow = new MediaWindow(rect);
60 
61 	be_roster->StartWatching(BMessenger(this));
62 }
63 
64 
65 Media::~Media()
66 {
67 	be_roster->StopWatching(BMessenger(this));
68 }
69 
70 
71 status_t
72 Media::InitCheck()
73 {
74 	if (fWindow)
75 		return fWindow->InitCheck();
76 	return B_OK;
77 }
78 
79 
80 void
81 Media::MessageReceived(BMessage* message)
82 {
83 	switch (message->what) {
84 		case B_SOME_APP_LAUNCHED:
85 		case B_SOME_APP_QUIT:
86 			fWindow->PostMessage(message);
87 			break;
88 
89 		default:
90 			BApplication::MessageReceived(message);
91 			break;
92 	}
93 }
94 
95 
96 //	#pragma mark -
97 
98 
99 int
100 main(int, char**)
101 {
102 	Media app;
103 	if (app.InitCheck() == B_OK)
104 		app.Run();
105 
106 	return 0;
107 }
108 
109