1 // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ 2 // 3 // Copyright (c) 2003, OpenBeOS 4 // 5 // This software is part of the OpenBeOS distribution and is covered 6 // by the OpenBeOS license. 7 // 8 // 9 // File: Media.cpp 10 // Author: Sikosis, Jérôme Duval 11 // Description: Media Preferences 12 // Created : June 25, 2003 13 // 14 // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ 15 16 17 // Includes -------------------------------------------------------------------------------------------------- // 18 #include <StorageKit.h> 19 #include <Roster.h> 20 #include <String.h> 21 #include <stdio.h> 22 #include "Media.h" 23 24 // Media -- constructor 25 Media::Media() 26 : BApplication (APP_SIGNATURE) 27 { 28 BRect rect(32,64,637,442); 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 if (sscanf(&buffer[i], " rect = %li,%li,%li,%li", &a, &b, &c, &d) > 0) { 46 if (c-a >= rect.IntegerWidth()) { 47 rect.left = a; 48 rect.right = c; 49 } 50 if (d-b >= rect.IntegerHeight()) { 51 rect.top = b; 52 rect.bottom = d; 53 } 54 } 55 } 56 } 57 } 58 59 fWindow = new MediaWindow(rect); 60 fWindow->SetSizeLimits(605.0, 10000.0, 378.0, 10000.0); 61 62 be_roster->StartWatching(BMessenger(this)); 63 } 64 // ---------------------------------------------------------------------------------------------------------- // 65 66 Media::~Media() 67 { 68 be_roster->StopWatching(BMessenger(this)); 69 } 70 71 72 status_t 73 Media::InitCheck() 74 { 75 if (fWindow) 76 return fWindow->InitCheck(); 77 return B_OK; 78 } 79 80 81 // Media::MessageReceived -- handles incoming messages 82 void Media::MessageReceived (BMessage *message) 83 { 84 switch(message->what) 85 { 86 case B_SOME_APP_LAUNCHED: 87 case B_SOME_APP_QUIT: 88 fWindow->PostMessage(message); 89 break; 90 default: 91 BApplication::MessageReceived(message); // pass it along ... 92 break; 93 } 94 } 95 // ---------------------------------------------------------------------------------------------------------- // 96 97 // Media Main 98 int main(void) 99 { 100 Media theApp; 101 if (theApp.InitCheck() == B_OK) 102 theApp.Run(); 103 return 0; 104 } 105 // end ------------------------------------------------------------------------------------------------------ // 106