xref: /haiku/src/apps/mediaplayer/settings/Settings.cpp (revision 0562493379cd52eb7103531f895f10bb8e77c085)
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 		|| filePanelFolder != other.filePanelFolder;
26 }
27 
28 
29 Settings::Settings(const char* filename)
30 	: BLocker("settings lock"),
31 	  fSettingsMessage(B_USER_SETTINGS_DIRECTORY, filename)
32 {
33 	// The settings are loaded from disk in the SettingsMessage constructor.
34 }
35 
36 
37 void
38 Settings::LoadSettings(mpSettings& settings) const
39 {
40 	BAutolock _(const_cast<Settings*>(this));
41 
42 	settings.autostart = fSettingsMessage.GetValue("autostart", true);
43 	settings.closeWhenDonePlayingMovie
44 		= fSettingsMessage.GetValue("closeWhenDonePlayingMovie", false);
45 	settings.closeWhenDonePlayingSound
46 		= fSettingsMessage.GetValue("closeWhenDonePlayingSound", false);
47 	settings.loopMovie = fSettingsMessage.GetValue("loopMovie", false);
48 	settings.loopSound = fSettingsMessage.GetValue("loopSound", false);
49 
50 	settings.useOverlays = fSettingsMessage.GetValue("useOverlays", true);
51 	settings.scaleBilinear = fSettingsMessage.GetValue("scaleBilinear", false);
52 
53 	settings.backgroundMovieVolumeMode
54 		= fSettingsMessage.GetValue("bgMovieVolumeMode",
55 			(uint32)mpSettings::BG_MOVIES_FULL_VOLUME);
56 
57 	entry_ref defaultFilePanelFolder;
58 		// an "unset" entry_ref
59 	settings.filePanelFolder = fSettingsMessage.GetValue(
60 		"filePanelDirectory", defaultFilePanelFolder);
61 }
62 
63 
64 void
65 Settings::SaveSettings(const mpSettings& settings)
66 {
67 	BAutolock _(this);
68 
69 	fSettingsMessage.SetValue("autostart", settings.autostart);
70 	fSettingsMessage.SetValue("closeWhenDonePlayingMovie",
71 		settings.closeWhenDonePlayingMovie);
72 	fSettingsMessage.SetValue("closeWhenDonePlayingSound",
73 		settings.closeWhenDonePlayingSound);
74 	fSettingsMessage.SetValue("loopMovie", settings.loopMovie);
75 	fSettingsMessage.SetValue("loopSound", settings.loopSound);
76 
77 	fSettingsMessage.SetValue("useOverlays", settings.useOverlays);
78 	fSettingsMessage.SetValue("scaleBilinear", settings.scaleBilinear);
79 
80 	fSettingsMessage.SetValue("bgMovieVolumeMode",
81 		settings.backgroundMovieVolumeMode);
82 
83 	fSettingsMessage.SetValue("filePanelDirectory",
84 		settings.filePanelFolder);
85 
86 	// Save at this point, although saving is also done on destruction,
87 	// this will make sure the settings are saved even when the player
88 	// crashes.
89 	fSettingsMessage.Save();
90 
91 	Notify();
92 }
93 
94 
95 // #pragma mark - static
96 
97 /*static*/ Settings
98 Settings::sGlobalInstance;
99 
100 
101 /*static*/ mpSettings
102 Settings::CurrentSettings()
103 {
104 	mpSettings settings;
105 	sGlobalInstance.LoadSettings(settings);
106 	return settings;
107 }
108 
109 
110 /*static*/ Settings*
111 Settings::Default()
112 {
113 	return &sGlobalInstance;
114 }
115 
116 
117 
118