repository_infos: Enable automatic updates on the main Haiku repostiory.
[haiku.git] / src / apps / cortex / addons / common / MediaNodeControlApp.cpp
blob4e6bd813238814cba6185fb8a49d3c5a98bed1dc
1 /*
2 * Copyright (c) 1999-2000, Eric Moon.
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions, and the following disclaimer.
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.
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.
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.
32 // MediaNodeControlApp.cpp
33 // e.moon 8jun99
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>
44 #include <cstdlib>
45 #include <cstring>
46 #include <cstdio>
48 // -------------------------------------------------------- //
49 // ctor/dtor
50 // -------------------------------------------------------- //
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) {}
62 bool QuitRequested() {
63 be_app->PostMessage(B_QUIT_REQUESTED);
64 return true;
68 MediaNodeControlApp::~MediaNodeControlApp() {
69 BMediaRoster* r = BMediaRoster::Roster();
70 r->ReleaseNode(m_node);
73 MediaNodeControlApp::MediaNodeControlApp(
74 const char* pAppSignature,
75 media_node_id nodeID) :
76 BApplication(pAppSignature) {
78 BMediaRoster* r = BMediaRoster::Roster();
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 (%" B_PRId32 "):\n%s\n",
86 nodeID, strerror(err));
87 BAlert* alert = new BAlert("error", buffer, "OK");
88 alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
89 alert->Go();
90 return;
93 // fetch info (name)
94 live_node_info nInfo;
95 err = r->GetLiveNodeInfo(m_node, &nInfo);
96 if(err < B_OK) {
97 char buffer[512];
98 sprintf(buffer,
99 "MediaNodeControlApp: couldn't get node info (%" B_PRId32
100 "):\n%s\n", nodeID, strerror(err));
101 BAlert* alert = new BAlert("error", buffer, "OK");
102 alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
103 alert->Go();
104 return;
107 BString windowTitle;
108 windowTitle << nInfo.name << '(' << nodeID << ") controls";
110 // get parameter web
111 BParameterWeb* pWeb;
112 err = r->GetParameterWebFor(m_node, &pWeb);
113 if(err < B_OK) {
114 char buffer[512];
115 sprintf(buffer,
116 "MediaNodeControlApp: no parameters for node (%" B_PRId32
117 "):\n%s\n", nodeID, strerror(err));
118 BAlert* alert = new BAlert("error", buffer, "OK");
119 alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
120 alert->Go();
121 return;
124 // build & show control window
125 BView* pView = BMediaTheme::ViewFor(pWeb);
126 BWindow* pWnd = new PanelWindow();
127 pWnd->AddChild(pView);
128 pWnd->ResizeTo(pView->Bounds().Width(), pView->Bounds().Height());
129 pWnd->SetTitle(windowTitle.String());
130 pWnd->Show();
132 // release the node
133 //r->ReleaseNode(m_node);
136 // END -- MediaNodeControlApp.cpp --