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