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 || subtitleSize != other.subtitleSize 30 || subtitlePlacement != other.subtitlePlacement 31 || backgroundMovieVolumeMode != other.backgroundMovieVolumeMode 32 || filePanelFolder != other.filePanelFolder 33 || audioPlayerWindowFrame != other.audioPlayerWindowFrame; 34 } 35 36 37 Settings::Settings(const char* filename) 38 : 39 BLocker("settings lock"), 40 fSettingsMessage(B_USER_SETTINGS_DIRECTORY, filename) 41 { 42 // The settings are loaded from disk in the SettingsMessage constructor. 43 } 44 45 46 void 47 Settings::Get(mpSettings& settings) const 48 { 49 BAutolock _(const_cast<Settings*>(this)); 50 51 settings.autostart = fSettingsMessage.GetValue("autostart", true); 52 settings.closeWhenDonePlayingMovie 53 = fSettingsMessage.GetValue("closeWhenDonePlayingMovie", false); 54 settings.closeWhenDonePlayingSound 55 = fSettingsMessage.GetValue("closeWhenDonePlayingSound", false); 56 settings.loopMovie = fSettingsMessage.GetValue("loopMovie", false); 57 settings.loopSound = fSettingsMessage.GetValue("loopSound", false); 58 59 settings.useOverlays = fSettingsMessage.GetValue("useOverlays", true); 60 settings.scaleBilinear = fSettingsMessage.GetValue("scaleBilinear", true); 61 settings.scaleFullscreenControls 62 = fSettingsMessage.GetValue("scaleFullscreenControls", true); 63 64 settings.subtitleSize 65 = fSettingsMessage.GetValue("subtitleSize", 66 (uint32)mpSettings::SUBTITLE_SIZE_MEDIUM); 67 settings.subtitlePlacement 68 = fSettingsMessage.GetValue("subtitlePlacement", 69 (uint32)mpSettings::SUBTITLE_PLACEMENT_BOTTOM_OF_VIDEO); 70 71 settings.backgroundMovieVolumeMode 72 = fSettingsMessage.GetValue("bgMovieVolumeMode", 73 (uint32)mpSettings::BG_MOVIES_FULL_VOLUME); 74 75 settings.filePanelFolder = FilePanelFolder(); 76 settings.audioPlayerWindowFrame = AudioPlayerWindowFrame(); 77 } 78 79 80 void 81 Settings::Update(const mpSettings& settings) 82 { 83 BAutolock _(this); 84 85 fSettingsMessage.SetValue("autostart", settings.autostart); 86 fSettingsMessage.SetValue("closeWhenDonePlayingMovie", 87 settings.closeWhenDonePlayingMovie); 88 fSettingsMessage.SetValue("closeWhenDonePlayingSound", 89 settings.closeWhenDonePlayingSound); 90 fSettingsMessage.SetValue("loopMovie", settings.loopMovie); 91 fSettingsMessage.SetValue("loopSound", settings.loopSound); 92 93 fSettingsMessage.SetValue("useOverlays", settings.useOverlays); 94 fSettingsMessage.SetValue("scaleBilinear", settings.scaleBilinear); 95 fSettingsMessage.SetValue("scaleFullscreenControls", 96 settings.scaleFullscreenControls); 97 98 fSettingsMessage.SetValue("subtitleSize", settings.subtitleSize); 99 fSettingsMessage.SetValue("subtitlePlacement", settings.subtitlePlacement); 100 101 fSettingsMessage.SetValue("bgMovieVolumeMode", 102 settings.backgroundMovieVolumeMode); 103 104 fSettingsMessage.SetValue("filePanelDirectory", 105 settings.filePanelFolder); 106 107 SetAudioPlayerWindowFrame(settings.audioPlayerWindowFrame); 108 109 Notify(); 110 } 111 112 113 entry_ref 114 Settings::FilePanelFolder() const 115 { 116 BAutolock locker(const_cast<Settings*>(this)); 117 return fSettingsMessage.GetValue("filePanelDirectory", entry_ref()); 118 } 119 120 121 void 122 Settings::SetFilePanelFolder(const entry_ref& ref) 123 { 124 BAutolock locker(this); 125 fSettingsMessage.SetValue("filePanelDirectory", ref); 126 } 127 128 129 BRect 130 Settings::AudioPlayerWindowFrame() const 131 { 132 BAutolock locker(const_cast<Settings*>(this)); 133 return fSettingsMessage.GetValue("audioPlayerWindowFrame", BRect()); 134 } 135 136 137 void 138 Settings::SetAudioPlayerWindowFrame(BRect frame) 139 { 140 BAutolock locker(this); 141 fSettingsMessage.SetValue("audioPlayerWindowFrame", frame); 142 } 143 144 145 // #pragma mark - static 146 147 148 /*static*/ Settings* 149 Settings::Default() 150 { 151 return &sGlobalInstance; 152 } 153 154 155 156