xref: /haiku/src/kits/media/MediaTheme.cpp (revision 51978af14a173e7fae0563b562be5603bc652aeb)
1 /* Author: Marcus Overhagen
2 **         Axel Dörfler, axeld@pinc-software.de
3 **
4 ** This file may be used under the terms of the OpenBeOS License.
5 */
6 
7 #include <MediaTheme.h>
8 #include <StringView.h>
9 #include <Locker.h>
10 #include <Autolock.h>
11 
12 #include <string.h>
13 
14 #include "DefaultMediaTheme.h"
15 #include "debug.h"
16 
17 
18 static BLocker sLock;
19 
20 /*************************************************************
21  * static BMediaTheme variables
22  *************************************************************/
23 
24 BMediaTheme * BMediaTheme::_mDefaultTheme;
25 
26 
27 /*************************************************************
28  * public BMediaTheme
29  *************************************************************/
30 
31 BMediaTheme::~BMediaTheme()
32 {
33 	CALLED();
34 
35 	free(_mName);
36 	free(_mInfo);
37 }
38 
39 
40 const char *
41 BMediaTheme::Name()
42 {
43 	return _mName;
44 }
45 
46 
47 const char *
48 BMediaTheme::Info()
49 {
50 	return _mInfo;
51 }
52 
53 
54 int32
55 BMediaTheme::ID()
56 {
57 	return _mID;
58 }
59 
60 
61 bool
62 BMediaTheme::GetRef(entry_ref *out_ref)
63 {
64 	UNIMPLEMENTED();
65 
66 	return false;
67 }
68 
69 
70 BView *
71 BMediaTheme::ViewFor(BParameterWeb *web, const BRect *hintRect, BMediaTheme *usingTheme)
72 {
73 	CALLED();
74 
75 	// use default theme if none was specified
76 
77 	if (usingTheme == NULL) {
78 		BAutolock locker(sLock);
79 
80 		if (_mDefaultTheme == NULL)
81 			_mDefaultTheme = new BPrivate::DefaultMediaTheme();
82 
83 		usingTheme = _mDefaultTheme;
84 	}
85 
86 	if (usingTheme == NULL)
87 		return new BStringView(BRect(0, 0, 200, 30), "", "No BMediaTheme available, sorry!");
88 
89 	return usingTheme->MakeViewFor(web, hintRect);
90 }
91 
92 
93 status_t
94 BMediaTheme::SetPreferredTheme(BMediaTheme *defaultTheme)
95 {
96 	CALLED();
97 
98 	// ToDo: this method should probably set some global settings file
99 	//	to make the new preferred theme available to all applications
100 
101 	BAutolock locker(sLock);
102 
103 	if (defaultTheme == NULL) {
104 		// if the current preferred theme is not the default media theme,
105 		// delete it, and set it back to the default
106 		if (dynamic_cast<BPrivate::DefaultMediaTheme *>(_mDefaultTheme) == NULL)
107 			_mDefaultTheme = new BPrivate::DefaultMediaTheme();
108 
109 		return B_OK;
110 	}
111 
112 	// this method takes possession of the BMediaTheme passed, even
113 	// if it fails, so it has to delete it
114 	if (defaultTheme != _mDefaultTheme)
115 		delete _mDefaultTheme;
116 
117 	_mDefaultTheme = defaultTheme;
118 
119 	return B_OK;
120 }
121 
122 
123 BMediaTheme *
124 BMediaTheme::PreferredTheme()
125 {
126 	CALLED();
127 
128 	BAutolock locker(sLock);
129 
130 	// ToDo: should look in the global prefs file for the preferred
131 	//	add-on and load this from disk - in the meantime, just use
132 	//	the default theme
133 
134 	if (_mDefaultTheme == NULL)
135 		_mDefaultTheme = new BPrivate::DefaultMediaTheme();
136 
137 	return _mDefaultTheme;
138 }
139 
140 
141 BBitmap *
142 BMediaTheme::BackgroundBitmapFor(bg_kind bg)
143 {
144 	UNIMPLEMENTED();
145 	return NULL;
146 }
147 
148 
149 rgb_color
150 BMediaTheme::BackgroundColorFor(bg_kind bg)
151 {
152 	UNIMPLEMENTED();
153 	rgb_color dummy = {0, 0, 0};
154 
155 	return dummy;
156 }
157 
158 
159 rgb_color
160 BMediaTheme::ForegroundColorFor(fg_kind fg)
161 {
162 	UNIMPLEMENTED();
163 	rgb_color dummy = {255, 255, 255};
164 
165 	return dummy;
166 }
167 
168 
169 /*************************************************************
170  * protected BMediaTheme
171  *************************************************************/
172 
173 
174 BMediaTheme::BMediaTheme(const char *name, const char *info, const entry_ref *ref, int32 id)
175 	:
176 	_mID(id)
177 {
178 	_mName = strdup(name);
179 	_mInfo = strdup(info);
180 
181 	// ToDo: is there something else here, which has to be done?
182 
183 	if (ref) {
184 		_mAddOn = true;
185 		_mAddOnRef = *ref;
186 	} else
187 		_mAddOn = false;
188 }
189 
190 
191 BControl *
192 BMediaTheme::MakeFallbackViewFor(BParameter *parameter)
193 {
194 	if (parameter == NULL)
195 		return NULL;
196 
197 	return BPrivate::DefaultMediaTheme::MakeViewFor(parameter);
198 }
199 
200 
201 /*************************************************************
202  * private BMediaTheme
203  *************************************************************/
204 
205 /*
206 private unimplemented
207 BMediaTheme::BMediaTheme()
208 BMediaTheme::BMediaTheme(const BMediaTheme &clone)
209 BMediaTheme & BMediaTheme::operator=(const BMediaTheme &clone)
210 */
211 
212 status_t BMediaTheme::_Reserved_ControlTheme_0(void *) { return B_ERROR; }
213 status_t BMediaTheme::_Reserved_ControlTheme_1(void *) { return B_ERROR; }
214 status_t BMediaTheme::_Reserved_ControlTheme_2(void *) { return B_ERROR; }
215 status_t BMediaTheme::_Reserved_ControlTheme_3(void *) { return B_ERROR; }
216 status_t BMediaTheme::_Reserved_ControlTheme_4(void *) { return B_ERROR; }
217 status_t BMediaTheme::_Reserved_ControlTheme_5(void *) { return B_ERROR; }
218 status_t BMediaTheme::_Reserved_ControlTheme_6(void *) { return B_ERROR; }
219 status_t BMediaTheme::_Reserved_ControlTheme_7(void *) { return B_ERROR; }
220 
221