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 be_locale->GetAppCatalog(&fCatalog); 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 if (sscanf(&buffer[i], " rect = %li,%li,%li,%li", &a, &b, &c, &d) > 0) { 45 if (c - a >= rect.IntegerWidth()) { 46 rect.left = a; 47 rect.right = c; 48 } 49 if (d - b >= rect.IntegerHeight()) { 50 rect.top = b; 51 rect.bottom = d; 52 } 53 } 54 } 55 } 56 } 57 58 fWindow = new MediaWindow(rect); 59 60 be_roster->StartWatching(BMessenger(this)); 61 } 62 63 64 Media::~Media() 65 { 66 be_roster->StopWatching(BMessenger(this)); 67 } 68 69 70 status_t 71 Media::InitCheck() 72 { 73 if (fWindow) 74 return fWindow->InitCheck(); 75 return B_OK; 76 } 77 78 79 void 80 Media::MessageReceived(BMessage *message) 81 { 82 switch (message->what) { 83 case B_SOME_APP_LAUNCHED: 84 case B_SOME_APP_QUIT: 85 fWindow->PostMessage(message); 86 break; 87 88 default: 89 BApplication::MessageReceived(message); 90 break; 91 } 92 } 93 94 95 // #pragma mark - 96 97 98 int 99 main(int, char**) 100 { 101 Media app; 102 if (app.InitCheck() == B_OK) 103 app.Run(); 104 105 return 0; 106 } 107 108