1 /* 2 * MainApp.cpp - Media Player for the Haiku Operating System 3 * 4 * Copyright (C) 2006 Marcus Overhagen <marcus@overhagen.de> 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License 8 * version 2 as published by the Free Software Foundation. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 * 19 */ 20 #include <Path.h> 21 #include <Entry.h> 22 #include <Alert.h> 23 #include <Autolock.h> 24 #include <unistd.h> 25 #include <stdio.h> 26 27 #include "MainApp.h" 28 29 MainApp *gMainApp; 30 31 MainApp::MainApp() 32 : BApplication("application/x-vnd.Haiku-MediaPlayer"), 33 fFirstWindow(NewWindow()), 34 fPlayerCount(1) 35 { 36 } 37 38 39 MainApp::~MainApp() 40 { 41 } 42 43 44 BWindow * 45 MainApp::NewWindow() 46 { 47 BAutolock _(this); 48 fPlayerCount++; 49 return new MainWin(); 50 } 51 52 53 void 54 MainApp::RefsReceived(BMessage *msg) 55 { 56 // The user dropped a file (or files) on this app's icon, 57 // or double clicked a file that's handled by this app. 58 // Command line arguments are also redirected to here by 59 // ArgvReceived() but without MIME type check. 60 // For each file we create a new window and send it a 61 // B_REFS_RECEIVED message with a single file. 62 // If IsLaunching() is true, we use fFirstWindow as first 63 // window. 64 printf("MainApp::RefsReceived\n"); 65 66 entry_ref ref; 67 for (int i = 0; B_OK == msg->FindRef("refs", i, &ref); i++) { 68 BWindow *win; 69 win = (i == 0 && IsLaunching()) ? fFirstWindow : NewWindow(); 70 BMessage m(B_REFS_RECEIVED); 71 m.AddRef("refs", &ref); 72 win->PostMessage(&m); 73 } 74 } 75 76 77 void 78 MainApp::ArgvReceived(int32 argc, char **argv) 79 { 80 char cwd[B_PATH_NAME_LENGTH]; 81 getcwd(cwd, sizeof(cwd)); 82 83 BMessage m(B_REFS_RECEIVED); 84 85 for (int i = 1; i < argc; i++) { 86 printf("MainApp::ArgvReceived %s\n", argv[i]); 87 BPath path; 88 if (argv[i][0] != '/') 89 path.SetTo(cwd, argv[i]); 90 else 91 path.SetTo(argv[i]); 92 BEntry entry(path.Path(), true); 93 if (!entry.Exists() || !entry.IsFile()) 94 continue; 95 96 entry_ref ref; 97 if (B_OK == entry.GetRef(&ref)) 98 m.AddRef("refs", &ref); 99 } 100 101 if (m.HasRef("refs")) { 102 printf("MainApp::ArgvReceived calling RefsReceived\n"); 103 RefsReceived(&m); 104 } 105 } 106 107 108 void 109 MainApp::MessageReceived(BMessage *msg) 110 { 111 switch (msg->what) { 112 case M_PLAYER_QUIT: 113 fPlayerCount--; 114 if (fPlayerCount == 0) 115 PostMessage(B_QUIT_REQUESTED); 116 break; 117 118 default: 119 BApplication::MessageReceived(msg); 120 break; 121 } 122 } 123 124 125 int 126 main() 127 { 128 gMainApp = new MainApp; 129 gMainApp->Run(); 130 return 0; 131 } 132