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