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