xref: /haiku/src/preferences/media/Media.cpp (revision b671e9bbdbd10268a042b4f4cc4317ccd03d105e)
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 <StorageKit.h>
14 #include <Roster.h>
15 #include <String.h>
16 #include <stdio.h>
17 
18 
19 Media::Media()
20 	: BApplication("application/x-vnd.Haiku-Media")
21 {
22 	BRect rect(32,64,637,462);
23 
24 	BPath path;
25 	if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) == B_OK) {
26 		path.Append(SETTINGS_FILE);
27 		BFile file(path.Path(),B_READ_ONLY);
28 		if (file.InitCheck()==B_OK) {
29 			char buffer[255];
30 			ssize_t size = 0;
31 			while ((size = file.Read(buffer, 255)) > 0) {
32 				int32 i = 0;
33 				while (buffer[i] == '#') {
34 					while (i < size && buffer[i] != '\n')
35 						i++;
36 					i++;
37 				}
38 				int32 a, b, c, d;
39 				if (sscanf(&buffer[i], " rect = %li,%li,%li,%li", &a, &b, &c, &d) > 0) {
40 					if (c - a >= rect.IntegerWidth()) {
41 						rect.left = a;
42 						rect.right = c;
43 					}
44 					if (d - b >= rect.IntegerHeight()) {
45 						rect.top = b;
46 						rect.bottom = d;
47 					}
48 				}
49 			}
50 		}
51 	}
52 
53 	fWindow = new MediaWindow(rect);
54 
55 	be_roster->StartWatching(BMessenger(this));
56 }
57 
58 
59 Media::~Media()
60 {
61 	be_roster->StopWatching(BMessenger(this));
62 }
63 
64 
65 status_t
66 Media::InitCheck()
67 {
68 	if (fWindow)
69 		return fWindow->InitCheck();
70 	return B_OK;
71 }
72 
73 
74 void
75 Media::MessageReceived(BMessage *message)
76 {
77 	switch (message->what) {
78 		case B_SOME_APP_LAUNCHED:
79 		case B_SOME_APP_QUIT:
80 			fWindow->PostMessage(message);
81 			break;
82 
83 		default:
84 			BApplication::MessageReceived(message);
85 			break;
86 	}
87 }
88 
89 
90 //	#pragma mark -
91 
92 
93 int
94 main(int, char**)
95 {
96 	Media app;
97 	if (app.InitCheck() == B_OK)
98 		app.Run();
99 
100 	return 0;
101 }
102 
103