xref: /haiku/src/apps/mediaplayer/settings/Settings.cpp (revision 21258e2674226d6aa732321b6f8494841895af5f)
1 /*
2  * Copyright 2008-2011, Haiku. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Fredrik Modéen <fredrik@modeen.se>
7  */
8 
9 
10 #include "Settings.h"
11 
12 #include <Autolock.h>
13 
14 
15 /*static*/ Settings Settings::sGlobalInstance;
16 
17 
18 bool
19 mpSettings::operator!=(const mpSettings& other) const
20 {
21 	return autostart != other.autostart
22 		|| closeWhenDonePlayingMovie != other.closeWhenDonePlayingMovie
23 		|| closeWhenDonePlayingSound != other.closeWhenDonePlayingSound
24 		|| loopMovie != other.loopMovie
25 		|| loopSound != other.loopSound
26 		|| useOverlays != other.useOverlays
27 		|| scaleBilinear != other.scaleBilinear
28 		|| scaleFullscreenControls != other.scaleFullscreenControls
29 		|| resume != other.resume
30 		|| subtitleSize != other.subtitleSize
31 		|| subtitlePlacement != other.subtitlePlacement
32 		|| backgroundMovieVolumeMode != other.backgroundMovieVolumeMode
33 		|| filePanelFolder != other.filePanelFolder
34 		|| audioPlayerWindowFrame != other.audioPlayerWindowFrame;
35 }
36 
37 
38 Settings::Settings(const char* filename)
39 	:
40 	BLocker("settings lock"),
41 	fSettingsMessage(B_USER_SETTINGS_DIRECTORY, filename)
42 {
43 	// The settings are loaded from disk in the SettingsMessage constructor.
44 }
45 
46 
47 void
48 Settings::Get(mpSettings& settings) const
49 {
50 	BAutolock _(const_cast<Settings*>(this));
51 
52 	settings.autostart = fSettingsMessage.GetValue("autostart", true);
53 	settings.closeWhenDonePlayingMovie
54 		= fSettingsMessage.GetValue("closeWhenDonePlayingMovie", false);
55 	settings.closeWhenDonePlayingSound
56 		= fSettingsMessage.GetValue("closeWhenDonePlayingSound", false);
57 	settings.loopMovie = fSettingsMessage.GetValue("loopMovie", false);
58 	settings.loopSound = fSettingsMessage.GetValue("loopSound", false);
59 
60 	settings.useOverlays = fSettingsMessage.GetValue("useOverlays", true);
61 	settings.scaleBilinear = fSettingsMessage.GetValue("scaleBilinear", true);
62 	settings.scaleFullscreenControls
63 		= fSettingsMessage.GetValue("scaleFullscreenControls", true);
64 
65 	settings.resume
66 		= fSettingsMessage.GetValue("resume",
67 			(uint32)mpSettings::RESUME_ALWAYS);
68 	settings.subtitleSize
69 		= fSettingsMessage.GetValue("subtitleSize",
70 			(uint32)mpSettings::SUBTITLE_SIZE_MEDIUM);
71 	settings.subtitlePlacement
72 		= fSettingsMessage.GetValue("subtitlePlacement",
73 			(uint32)mpSettings::SUBTITLE_PLACEMENT_BOTTOM_OF_VIDEO);
74 
75 	settings.backgroundMovieVolumeMode
76 		= fSettingsMessage.GetValue("bgMovieVolumeMode",
77 			(uint32)mpSettings::BG_MOVIES_FULL_VOLUME);
78 
79 	settings.filePanelFolder = FilePanelFolder();
80 	settings.audioPlayerWindowFrame = AudioPlayerWindowFrame();
81 }
82 
83 
84 void
85 Settings::Update(const mpSettings& settings)
86 {
87 	BAutolock _(this);
88 
89 	fSettingsMessage.SetValue("autostart", settings.autostart);
90 	fSettingsMessage.SetValue("closeWhenDonePlayingMovie",
91 		settings.closeWhenDonePlayingMovie);
92 	fSettingsMessage.SetValue("closeWhenDonePlayingSound",
93 		settings.closeWhenDonePlayingSound);
94 	fSettingsMessage.SetValue("loopMovie", settings.loopMovie);
95 	fSettingsMessage.SetValue("loopSound", settings.loopSound);
96 
97 	fSettingsMessage.SetValue("useOverlays", settings.useOverlays);
98 	fSettingsMessage.SetValue("scaleBilinear", settings.scaleBilinear);
99 	fSettingsMessage.SetValue("scaleFullscreenControls",
100 		settings.scaleFullscreenControls);
101 
102 	fSettingsMessage.SetValue("resume", settings.resume);
103 	fSettingsMessage.SetValue("subtitleSize", settings.subtitleSize);
104 	fSettingsMessage.SetValue("subtitlePlacement", settings.subtitlePlacement);
105 
106 	fSettingsMessage.SetValue("bgMovieVolumeMode",
107 		settings.backgroundMovieVolumeMode);
108 
109 	fSettingsMessage.SetValue("filePanelDirectory",
110 		settings.filePanelFolder);
111 
112 	SetAudioPlayerWindowFrame(settings.audioPlayerWindowFrame);
113 
114 	Notify();
115 }
116 
117 
118 entry_ref
119 Settings::FilePanelFolder() const
120 {
121 	BAutolock locker(const_cast<Settings*>(this));
122 	return fSettingsMessage.GetValue("filePanelDirectory", entry_ref());
123 }
124 
125 
126 void
127 Settings::SetFilePanelFolder(const entry_ref& ref)
128 {
129 	BAutolock locker(this);
130 	fSettingsMessage.SetValue("filePanelDirectory", ref);
131 }
132 
133 
134 BRect
135 Settings::AudioPlayerWindowFrame() const
136 {
137 	BAutolock locker(const_cast<Settings*>(this));
138 	return fSettingsMessage.GetValue("audioPlayerWindowFrame", BRect());
139 }
140 
141 
142 void
143 Settings::SetAudioPlayerWindowFrame(BRect frame)
144 {
145 	BAutolock locker(this);
146 	fSettingsMessage.SetValue("audioPlayerWindowFrame", frame);
147 }
148 
149 
150 // #pragma mark - static
151 
152 
153 /*static*/ Settings*
154 Settings::Default()
155 {
156 	return &sGlobalInstance;
157 }
158 
159 
160 
161