xref: /haiku/src/apps/mediaplayer/settings/Settings.cpp (revision 959ff00ddee8411dabb09211f3bfbd52d87229da)
1 /*
2  * Copyright 2008, 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 #include "Settings.h"
10 
11 #include <Autolock.h>
12 
13 
14 bool
15 mpSettings::operator!=(const mpSettings& other) const
16 {
17 	return autostart != other.autostart
18 		|| closeWhenDonePlayingMovie != other.closeWhenDonePlayingMovie
19 		|| closeWhenDonePlayingSound != other.closeWhenDonePlayingSound
20 		|| loopMovie != other.loopMovie
21 		|| loopSound != other.loopSound
22 		|| useOverlays != other.useOverlays
23 		|| scaleBilinear != other.scaleBilinear
24 		|| backgroundMovieVolumeMode != other.backgroundMovieVolumeMode;
25 }
26 
27 
28 Settings::Settings(const char* filename)
29 	: BLocker("settings lock"),
30 	  fSettingsMessage(B_USER_CONFIG_DIRECTORY, filename)
31 {
32 }
33 
34 
35 void
36 Settings::LoadSettings(mpSettings& settings) const
37 {
38 	BAutolock _(const_cast<Settings*>(this));
39 
40 	settings.autostart = fSettingsMessage.GetValue("autostart", true);
41 	settings.closeWhenDonePlayingMovie
42 		= fSettingsMessage.GetValue("closeWhenDonePlayingMovie", false);
43 	settings.closeWhenDonePlayingSound
44 		= fSettingsMessage.GetValue("closeWhenDonePlayingSound", false);
45 	settings.loopMovie = fSettingsMessage.GetValue("loopMovie", false);
46 	settings.loopSound = fSettingsMessage.GetValue("loopSound", false);
47 
48 	settings.useOverlays = fSettingsMessage.GetValue("useOverlays", true);
49 	settings.scaleBilinear = fSettingsMessage.GetValue("scaleBilinear", false);
50 
51 	settings.backgroundMovieVolumeMode
52 		= fSettingsMessage.GetValue("bgMovieVolumeMode",
53 			(uint32)mpSettings::BG_MOVIES_FULL_VOLUME);
54 }
55 
56 
57 void
58 Settings::SaveSettings(const mpSettings& settings)
59 {
60 	BAutolock _(this);
61 
62 	fSettingsMessage.SetValue("autostart", settings.autostart);
63 	fSettingsMessage.SetValue("closeWhenDonePlayingMovie",
64 		settings.closeWhenDonePlayingMovie);
65 	fSettingsMessage.SetValue("closeWhenDonePlayingSound",
66 		settings.closeWhenDonePlayingSound);
67 	fSettingsMessage.SetValue("loopMovie", settings.loopMovie);
68 	fSettingsMessage.SetValue("loopSound", settings.loopSound);
69 
70 	fSettingsMessage.SetValue("useOverlays", settings.useOverlays);
71 	fSettingsMessage.SetValue("scaleBilinear", settings.scaleBilinear);
72 
73 	fSettingsMessage.SetValue("bgMovieVolumeMode",
74 		settings.backgroundMovieVolumeMode);
75 
76 	// Save at this point, although saving is also done on destruction,
77 	// this will make sure the settings are saved even when the player
78 	// crashes.
79 	fSettingsMessage.Save();
80 
81 	Notify();
82 }
83 
84 
85 // #pragma mark - static
86 
87 /*static*/ Settings
88 Settings::sGlobalInstance;
89 
90 
91 /*static*/ mpSettings
92 Settings::CurrentSettings()
93 {
94 	mpSettings settings;
95 	sGlobalInstance.LoadSettings(settings);
96 	return settings;
97 }
98 
99 
100 /*static*/ Settings*
101 Settings::Default()
102 {
103 	return &sGlobalInstance;
104 }
105 
106 
107 
108