xref: /haiku/src/apps/cortex/InfoView/DormantNodeInfoView.cpp (revision 579f1dbca962a2a03df54f69fdc6e9423f91f20e)
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 // DormantNodeInfoView.cpp
33 
34 #include "DormantNodeInfoView.h"
35 // InfoView
36 #include "InfoWindowManager.h"
37 // Support
38 #include "MediaIcon.h"
39 #include "MediaString.h"
40 
41 // Media Kit
42 #include <MediaAddOn.h>
43 #include <MediaRoster.h>
44 
45 __USE_CORTEX_NAMESPACE
46 
47 #include <Debug.h>
48 #define D_METHOD(x) //PRINT (x)
49 
50 // -------------------------------------------------------- //
51 // *** ctor/dtor (public)
52 // -------------------------------------------------------- //
53 
54 DormantNodeInfoView::DormantNodeInfoView(
55 	const dormant_node_info &info)
56 	: InfoView(info.name, "Dormant media node",
57 			   new MediaIcon(info, B_LARGE_ICON)),
58 	  m_addOnID(info.addon),
59 	  m_flavorID(info.flavor_id)
60 {
61 	D_METHOD(("DormantNodeInfoView::DormantNodeInfoView()\n"));
62 
63 	// adjust view properties
64 	setSideBarWidth(be_plain_font->StringWidth(" Output Formats ") + 2 * InfoView::M_H_MARGIN);
65 
66 	BString s;
67 
68 	// add the "AddOn ID" field
69 	s = "";
70 	s << info.addon;
71 	addField("AddOn ID", s);
72 
73 	// add the "Flavor ID" field
74 	s = "";
75 	s << info.flavor_id;
76 	addField("Flavor ID", s);
77 
78 	// add separator field
79 	addField("", "");
80 
81 	dormant_flavor_info flavorInfo;
82 	BMediaRoster *roster = BMediaRoster::Roster();
83 	if (roster && (roster->GetDormantFlavorInfoFor(info, &flavorInfo) == B_OK))
84 	{
85 		// add the "Description" field
86 		s = flavorInfo.info;
87 		addField("Description", s);
88 
89 		// add "Kinds" field
90 		addField("Kinds", MediaString::getStringFor(static_cast<node_kind>(flavorInfo.kinds)));
91 
92 		// add "Flavor Flags" field
93 		addField("Flavor flags", "?");
94 
95 		// add "Max. instances" field
96 		if (flavorInfo.possible_count > 0)
97 		{
98 			s = "";
99 			s << flavorInfo.possible_count;
100 		}
101 		else
102 		{
103 			s = "Any number";
104 		}
105 		addField("Max. instances", s);
106 
107 		// add "Input Formats" field
108 		if (flavorInfo.in_format_count > 0)
109 		{
110 			if (flavorInfo.in_format_count == 1)
111 			{
112 				addField("Input format", MediaString::getStringFor(flavorInfo.in_formats[0], false));
113 			}
114 			else
115 			{
116 				addField("Input formats", "");
117 				for (int32 i = 0; i < flavorInfo.in_format_count; i++)
118 				{
119 					s = "";
120 					s << "(" << i + 1 << ")";
121 					addField(s, MediaString::getStringFor(flavorInfo.in_formats[i], false));
122 				}
123 			}
124 		}
125 
126 		// add "Output Formats" field
127 		if (flavorInfo.out_format_count > 0)
128 		{
129 			if (flavorInfo.out_format_count == 1)
130 			{
131 				addField("Output format", MediaString::getStringFor(flavorInfo.out_formats[0], false));
132 			}
133 			else
134 			{
135 				addField("Output formats", "");
136 				for (int32 i = 0; i < flavorInfo.out_format_count; i++)
137 				{
138 					s = "";
139 					s << "(" << i + 1 << ")";
140 					addField(s, MediaString::getStringFor(flavorInfo.out_formats[i], false));
141 				}
142 			}
143 		}
144 	}
145 }
146 
147 DormantNodeInfoView::~DormantNodeInfoView()
148 {
149 	D_METHOD(("DormantNodeInfoView::~DormantNodeInfoView()\n"));
150 }
151 
152 // -------------------------------------------------------- //
153 // *** BView implementation (public)
154 // -------------------------------------------------------- //
155 
156 void DormantNodeInfoView::DetachedFromWindow() {
157 	D_METHOD(("DormantNodeInfoView::DetachedFromWindow()\n"));
158 
159 	InfoWindowManager *manager = InfoWindowManager::Instance();
160 	if (manager) {
161 		BMessage message(InfoWindowManager::M_DORMANT_NODE_WINDOW_CLOSED);
162 		message.AddInt32("addOnID", m_addOnID);
163 		message.AddInt32("flavorID", m_flavorID);
164 		manager->PostMessage(&message);
165 	}
166 }
167 
168 // END -- DormantNodeInfoView.cpp --
169