xref: /haiku/src/apps/cortex/InfoView/DormantNodeInfoView.cpp (revision 508f54795f39c3e7552d87c95aae9dd8ec6f505b)
1 // DormantNodeInfoView.cpp
2 
3 #include "DormantNodeInfoView.h"
4 // InfoView
5 #include "InfoWindowManager.h"
6 // Support
7 #include "MediaIcon.h"
8 #include "MediaString.h"
9 
10 // Media Kit
11 #include <MediaAddOn.h>
12 #include <MediaRoster.h>
13 
14 __USE_CORTEX_NAMESPACE
15 
16 #include <Debug.h>
17 #define D_METHOD(x) //PRINT (x)
18 
19 // -------------------------------------------------------- //
20 // *** ctor/dtor (public)
21 // -------------------------------------------------------- //
22 
23 DormantNodeInfoView::DormantNodeInfoView(
24 	const dormant_node_info &info)
25 	: InfoView(info.name, "Dormant media node",
26 			   new MediaIcon(info, B_LARGE_ICON)),
27 	  m_addOnID(info.addon),
28 	  m_flavorID(info.flavor_id)
29 {
30 	D_METHOD(("DormantNodeInfoView::DormantNodeInfoView()\n"));
31 
32 	// adjust view properties
33 	setSideBarWidth(be_plain_font->StringWidth(" Output Formats ") + 2 * InfoView::M_H_MARGIN);
34 
35 	BString s;
36 
37 	// add the "AddOn ID" field
38 	s = "";
39 	s << info.addon;
40 	addField("AddOn ID", s);
41 
42 	// add the "Flavor ID" field
43 	s = "";
44 	s << info.flavor_id;
45 	addField("Flavor ID", s);
46 
47 	// add separator field
48 	addField("", "");
49 
50 	dormant_flavor_info flavorInfo;
51 	BMediaRoster *roster = BMediaRoster::Roster();
52 	if (roster && (roster->GetDormantFlavorInfoFor(info, &flavorInfo) == B_OK))
53 	{
54 		// add the "Description" field
55 		s = flavorInfo.info;
56 		addField("Description", s);
57 
58 		// add "Kinds" field
59 		addField("Kinds", MediaString::getStringFor(static_cast<node_kind>(flavorInfo.kinds)));
60 
61 		// add "Flavor Flags" field
62 		addField("Flavor flags", "?");
63 
64 		// add "Max. instances" field
65 		if (flavorInfo.possible_count > 0)
66 		{
67 			s = "";
68 			s << flavorInfo.possible_count;
69 		}
70 		else
71 		{
72 			s = "Any number";
73 		}
74 		addField("Max. instances", s);
75 
76 		// add "Input Formats" field
77 		if (flavorInfo.in_format_count > 0)
78 		{
79 			if (flavorInfo.in_format_count == 1)
80 			{
81 				addField("Input format", MediaString::getStringFor(flavorInfo.in_formats[0], false));
82 			}
83 			else
84 			{
85 				addField("Input formats", "");
86 				for (int32 i = 0; i < flavorInfo.in_format_count; i++)
87 				{
88 					s = "";
89 					s << "(" << i + 1 << ")";
90 					addField(s, MediaString::getStringFor(flavorInfo.in_formats[i], false));
91 				}
92 			}
93 		}
94 
95 		// add "Output Formats" field
96 		if (flavorInfo.out_format_count > 0)
97 		{
98 			if (flavorInfo.out_format_count == 1)
99 			{
100 				addField("Output format", MediaString::getStringFor(flavorInfo.out_formats[0], false));
101 			}
102 			else
103 			{
104 				addField("Output formats", "");
105 				for (int32 i = 0; i < flavorInfo.out_format_count; i++)
106 				{
107 					s = "";
108 					s << "(" << i + 1 << ")";
109 					addField(s, MediaString::getStringFor(flavorInfo.out_formats[i], false));
110 				}
111 			}
112 		}
113 	}
114 }
115 
116 DormantNodeInfoView::~DormantNodeInfoView()
117 {
118 	D_METHOD(("DormantNodeInfoView::~DormantNodeInfoView()\n"));
119 }
120 
121 // -------------------------------------------------------- //
122 // *** BView implementation (public)
123 // -------------------------------------------------------- //
124 
125 void DormantNodeInfoView::DetachedFromWindow() {
126 	D_METHOD(("DormantNodeInfoView::DetachedFromWindow()\n"));
127 
128 	InfoWindowManager *manager = InfoWindowManager::Instance();
129 	if (manager) {
130 		BMessage message(InfoWindowManager::M_DORMANT_NODE_WINDOW_CLOSED);
131 		message.AddInt32("addOnID", m_addOnID);
132 		message.AddInt32("flavorID", m_flavorID);
133 		manager->PostMessage(&message);
134 	}
135 }
136 
137 // END -- DormantNodeInfoView.cpp --
138