xref: /haiku/src/apps/cortex/addons/common/MediaNodeControlApp.cpp (revision 040a81419dda83d1014e9dc94936a4cb3f027303)
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 (%" 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;
91 	}
92 
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;
105 	}
106 
107 	BString windowTitle;
108 	windowTitle << nInfo.name << '(' << nodeID << ") controls";
109 
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;
122 	}
123 
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();
131 
132 	// release the node
133 	//r->ReleaseNode(m_node);
134 }
135 
136 // END -- MediaNodeControlApp.cpp --
137