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,442); 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 fWindow->SetSizeLimits(605.0, 10000.0, 378.0, 10000.0); 55 56 be_roster->StartWatching(BMessenger(this)); 57 } 58 59 60 Media::~Media() 61 { 62 be_roster->StopWatching(BMessenger(this)); 63 } 64 65 66 status_t 67 Media::InitCheck() 68 { 69 if (fWindow) 70 return fWindow->InitCheck(); 71 return B_OK; 72 } 73 74 75 void 76 Media::MessageReceived(BMessage *message) 77 { 78 switch (message->what) { 79 case B_SOME_APP_LAUNCHED: 80 case B_SOME_APP_QUIT: 81 fWindow->PostMessage(message); 82 break; 83 84 default: 85 BApplication::MessageReceived(message); 86 break; 87 } 88 } 89 90 91 // #pragma mark - 92 93 94 int 95 main(int, char**) 96 { 97 Media app; 98 if (app.InitCheck() == B_OK) 99 app.Run(); 100 101 return 0; 102 } 103 104