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