xref: /haiku/src/apps/cortex/addons/common/MediaNodeControlApp.cpp (revision 2cba2d5642ee902f1ac72ec6ce2fa383516a3f35)
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 #include <Catalog.h>
44 
45 #include <cstdlib>
46 #include <cstring>
47 #include <cstdio>
48 
49 
50 #undef B_TRANSLATION_CONTEXT
51 #define B_TRANSLATION_CONTEXT "CortexAddOnsCommonMediaNodeControlApp"
52 
53 
54 // -------------------------------------------------------- //
55 // ctor/dtor
56 // -------------------------------------------------------- //
57 
58 class PanelWindow :
59 	public		BWindow {
60 	typedef	BWindow _inherited;
61 public:
PanelWindow()62 	PanelWindow() :
63 		BWindow(BRect(50, 50, 100, 100), "MediaNodeControlApp",
64 			B_TITLED_WINDOW,
65 			B_ASYNCHRONOUS_CONTROLS |
66 			B_WILL_ACCEPT_FIRST_CLICK) {}
67 
QuitRequested()68 	bool QuitRequested() {
69 		be_app->PostMessage(B_QUIT_REQUESTED);
70 		return true;
71 	}
72 };
73 
~MediaNodeControlApp()74 MediaNodeControlApp::~MediaNodeControlApp() {
75 	BMediaRoster* r = BMediaRoster::Roster();
76 	r->ReleaseNode(m_node);
77 }
78 
MediaNodeControlApp(const char * pAppSignature,media_node_id nodeID)79 MediaNodeControlApp::MediaNodeControlApp(
80 	const char* pAppSignature,
81 	media_node_id nodeID) :
82 	BApplication(pAppSignature) {
83 
84 	BMediaRoster* r = BMediaRoster::Roster();
85 
86 	// get the node
87 	status_t err = r->GetNodeFor(nodeID, &m_node);
88 	if(err < B_OK) {
89 		char buffer[512];
90 		sprintf(buffer,
91 			B_TRANSLATE("MediaNodeControlApp: couldn't find node (%"
92 				B_PRId32 "):\n%s\n"),
93 			nodeID, strerror(err));
94 		BAlert* alert = new BAlert("error", buffer, B_TRANSLATE("OK"));
95 		alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
96 		alert->Go();
97 		return;
98 	}
99 
100 	// fetch info (name)
101 	live_node_info nInfo;
102 	err = r->GetLiveNodeInfo(m_node, &nInfo);
103 	if(err < B_OK) {
104 		char buffer[512];
105 		sprintf(buffer,
106 			B_TRANSLATE("MediaNodeControlApp: couldn't get node info (%"
107 				B_PRId32 "):\n%s\n"), nodeID, strerror(err));
108 		BAlert* alert = new BAlert("error", buffer, B_TRANSLATE("OK"));
109 		alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
110 		alert->Go();
111 		return;
112 	}
113 
114 	BString windowTitle;
115 	windowTitle << nInfo.name << '(' << nodeID << ") "
116 		<< B_TRANSLATE("controls");
117 
118 	// get parameter web
119 	BParameterWeb* pWeb;
120 	err = r->GetParameterWebFor(m_node, &pWeb);
121 	if(err < B_OK) {
122 		char buffer[512];
123 		sprintf(buffer,
124 			B_TRANSLATE("MediaNodeControlApp: no parameters for node (%"
125 				B_PRId32 "):\n%s\n"), nodeID, strerror(err));
126 		BAlert* alert = new BAlert("error", buffer, B_TRANSLATE("OK"));
127 		alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
128 		alert->Go();
129 		return;
130 	}
131 
132 	// build & show control window
133 	BView* pView = BMediaTheme::ViewFor(pWeb);
134 	BWindow* pWnd = new PanelWindow();
135 	pWnd->AddChild(pView);
136 	pWnd->ResizeTo(pView->Bounds().Width(), pView->Bounds().Height());
137 	pWnd->SetTitle(windowTitle.String());
138 	pWnd->Show();
139 
140 	// release the node
141 	//r->ReleaseNode(m_node);
142 }
143 
144 // END -- MediaNodeControlApp.cpp --
145