1 /* 2 * Copyright (c) 1999-2000, Eric Moon. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions, and the following disclaimer. 11 * 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions, and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * 3. The name of the author may not be used to endorse or promote products 17 * derived from this software without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 21 * OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 26 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 27 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31 32 // MediaNodeControlApp.cpp 33 // e.moon 8jun99 34 35 #include "MediaNodeControlApp.h" 36 #include <Window.h> 37 #include <View.h> 38 #include <MediaRoster.h> 39 #include <MediaTheme.h> 40 #include <ParameterWeb.h> 41 #include <String.h> 42 #include <Alert.h> 43 44 #include <cstdlib> 45 #include <cstring> 46 #include <cstdio> 47 48 // -------------------------------------------------------- // 49 // ctor/dtor 50 // -------------------------------------------------------- // 51 52 class PanelWindow : 53 public BWindow { 54 typedef BWindow _inherited; 55 public: 56 PanelWindow() : 57 BWindow(BRect(50, 50, 100, 100), "MediaNodeControlApp", 58 B_TITLED_WINDOW, 59 B_ASYNCHRONOUS_CONTROLS | 60 B_WILL_ACCEPT_FIRST_CLICK) {} 61 62 bool QuitRequested() { 63 be_app->PostMessage(B_QUIT_REQUESTED); 64 return true; 65 } 66 }; 67 68 MediaNodeControlApp::~MediaNodeControlApp() { 69 BMediaRoster* r = BMediaRoster::Roster(); 70 r->ReleaseNode(m_node); 71 } 72 73 MediaNodeControlApp::MediaNodeControlApp( 74 const char* pAppSignature, 75 media_node_id nodeID) : 76 BApplication(pAppSignature) { 77 78 BMediaRoster* r = BMediaRoster::Roster(); 79 80 // get the node 81 status_t err = r->GetNodeFor(nodeID, &m_node); 82 if(err < B_OK) { 83 char buffer[512]; 84 sprintf(buffer, 85 "MediaNodeControlApp: couldn't find node (%ld):\n%s\n", 86 nodeID, strerror(err)); 87 (new BAlert("error", buffer, "OK"))->Go(); 88 return; 89 } 90 91 // fetch info (name) 92 live_node_info nInfo; 93 err = r->GetLiveNodeInfo(m_node, &nInfo); 94 if(err < B_OK) { 95 char buffer[512]; 96 sprintf(buffer, 97 "MediaNodeControlApp: couldn't get node info (%ld):\n%s\n", 98 nodeID, strerror(err)); 99 (new BAlert("error", buffer, "OK"))->Go(); 100 return; 101 } 102 103 BString windowTitle; 104 windowTitle << nInfo.name << '(' << nodeID << ") controls"; 105 106 // get parameter web 107 BParameterWeb* pWeb; 108 err = r->GetParameterWebFor(m_node, &pWeb); 109 if(err < B_OK) { 110 char buffer[512]; 111 sprintf(buffer, 112 "MediaNodeControlApp: no parameters for node (%ld):\n%s\n", 113 nodeID, strerror(err)); 114 (new BAlert("error", buffer, "OK"))->Go(); 115 return; 116 } 117 118 // build & show control window 119 BView* pView = BMediaTheme::ViewFor(pWeb); 120 BWindow* pWnd = new PanelWindow(); 121 pWnd->AddChild(pView); 122 pWnd->ResizeTo(pView->Bounds().Width(), pView->Bounds().Height()); 123 pWnd->SetTitle(windowTitle.String()); 124 pWnd->Show(); 125 126 // release the node 127 //r->ReleaseNode(m_node); 128 } 129 130 // END -- MediaNodeControlApp.cpp -- 131