xref: /haiku/src/apps/cortex/addons/common/MediaNodeControlApp.cpp (revision 9760dcae2038d47442f4658c2575844c6cf92c40)
1 // MediaNodeControlApp.cpp
2 // e.moon 8jun99
3 
4 #include "MediaNodeControlApp.h"
5 #include <Window.h>
6 #include <View.h>
7 #include <MediaRoster.h>
8 #include <MediaTheme.h>
9 #include <ParameterWeb.h>
10 #include <String.h>
11 #include <Alert.h>
12 
13 #include <cstdlib>
14 #include <cstring>
15 #include <cstdio>
16 
17 // -------------------------------------------------------- //
18 // ctor/dtor
19 // -------------------------------------------------------- //
20 
21 class PanelWindow :
22 	public		BWindow {
23 	typedef	BWindow _inherited;
24 public:
25 	PanelWindow() :
26 		BWindow(BRect(50, 50, 100, 100), "MediaNodeControlApp",
27 			B_TITLED_WINDOW,
28 			B_ASYNCHRONOUS_CONTROLS |
29 			B_WILL_ACCEPT_FIRST_CLICK) {}
30 
31 	bool QuitRequested() {
32 		be_app->PostMessage(B_QUIT_REQUESTED);
33 		return true;
34 	}
35 };
36 
37 MediaNodeControlApp::~MediaNodeControlApp() {
38 	BMediaRoster* r = BMediaRoster::Roster();
39 	r->ReleaseNode(m_node);
40 }
41 
42 MediaNodeControlApp::MediaNodeControlApp(
43 	const char* pAppSignature,
44 	media_node_id nodeID) :
45 	BApplication(pAppSignature) {
46 
47 	BMediaRoster* r = BMediaRoster::Roster();
48 
49 	// get the node
50 	status_t err = r->GetNodeFor(nodeID, &m_node);
51 	if(err < B_OK) {
52 		char buffer[512];
53 		sprintf(buffer,
54 			"MediaNodeControlApp: couldn't find node (%ld):\n%s\n",
55 			nodeID, strerror(err));
56 		(new BAlert("error", buffer, "OK"))->Go();
57 		return;
58 	}
59 
60 	// fetch info (name)
61 	live_node_info nInfo;
62 	err = r->GetLiveNodeInfo(m_node, &nInfo);
63 	if(err < B_OK) {
64 		char buffer[512];
65 		sprintf(buffer,
66 			"MediaNodeControlApp: couldn't get node info (%ld):\n%s\n",
67 			nodeID, strerror(err));
68 		(new BAlert("error", buffer, "OK"))->Go();
69 		return;
70 	}
71 
72 	BString windowTitle;
73 	windowTitle << nInfo.name << '(' << nodeID << ") controls";
74 
75 	// get parameter web
76 	BParameterWeb* pWeb;
77 	err = r->GetParameterWebFor(m_node, &pWeb);
78 	if(err < B_OK) {
79 		char buffer[512];
80 		sprintf(buffer,
81 			"MediaNodeControlApp: no parameters for node (%ld):\n%s\n",
82 			nodeID, strerror(err));
83 		(new BAlert("error", buffer, "OK"))->Go();
84 		return;
85 	}
86 
87 	// build & show control window
88 	BView* pView = BMediaTheme::ViewFor(pWeb);
89 	BWindow* pWnd = new PanelWindow();
90 	pWnd->AddChild(pView);
91 	pWnd->ResizeTo(pView->Bounds().Width(), pView->Bounds().Height());
92 	pWnd->SetTitle(windowTitle.String());
93 	pWnd->Show();
94 
95 	// release the node
96 	//r->ReleaseNode(m_node);
97 }
98 
99 // END -- MediaNodeControlApp.cpp --
100