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