From 4d3ebacc42d0f103b79c134a0f6ce2fdcd9a0ba8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Tue, 1 Apr 2008 08:06:39 +0000 Subject: [PATCH] Argh! Forgot to svn add these files. Should have been part of last commit. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24716 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/mediaplayer/settings/Settings.cpp | 107 ++++++++++ src/apps/mediaplayer/settings/Settings.h | 38 ++++ .../mediaplayer/settings/SettingsWindow.cpp | 182 ++++++++++++++++++ .../mediaplayer/settings/SettingsWindow.h | 39 ++++ 4 files changed, 366 insertions(+) create mode 100644 src/apps/mediaplayer/settings/Settings.cpp create mode 100644 src/apps/mediaplayer/settings/Settings.h create mode 100644 src/apps/mediaplayer/settings/SettingsWindow.cpp create mode 100644 src/apps/mediaplayer/settings/SettingsWindow.h diff --git a/src/apps/mediaplayer/settings/Settings.cpp b/src/apps/mediaplayer/settings/Settings.cpp new file mode 100644 index 0000000000..307e94e276 --- /dev/null +++ b/src/apps/mediaplayer/settings/Settings.cpp @@ -0,0 +1,107 @@ +/* + * Copyright 2008, Haiku. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Fredrik Modéen + */ + +#include "Settings.h" + +#include + +#include +#include +#include + +#include "TPreferences.h" + +Settings::Settings(const char *filename) + : fTPreferences(TPreferences(B_USER_CONFIG_DIRECTORY, filename)) +{ +} + + +void +Settings::LoadSettings(mpSettings &settings) +{ + BPath path; + + if (find_directory(B_USER_SETTINGS_DIRECTORY, &path, true) != B_OK) + return; + + path.Append(SETTINGSFILENAME); + + BFile settingsFile(path.Path(), B_READ_ONLY); + + if (settingsFile.InitCheck() != B_OK) { + _SetDefault(settings); + return; + } + + fTPreferences.Unflatten(&settingsFile); + memset(&settings, 0, sizeof(settings)); + + fTPreferences.FindInt8("autostart", (int8 *)&settings.autostart); + fTPreferences.FindInt8("closeWhenDonePlayingMovie", + (int8 *)&settings.closeWhenDonePlayingMovie); + fTPreferences.FindInt8("closeWhenDonePlayingSound", + (int8 *)&settings.closeWhenDonePlayingSound); + fTPreferences.FindInt8("loopMovie", (int8 *)&settings.loopMovie); + fTPreferences.FindInt8("loopSound", (int8 *)&settings.loopSound); + fTPreferences.FindInt8("fullVolume", (int8 *)&settings.fullVolume); + fTPreferences.FindInt8("halfVolume", (int8 *)&settings.halfVolume); + fTPreferences.FindInt8("mute", (int8 *)&settings.mute); + + fTPreferences.Flatten(&settingsFile); +} + + +void +Settings::SaveSettings(const mpSettings &settings) +{ + BPath path; + + if (find_directory(B_USER_SETTINGS_DIRECTORY, &path, true) != B_OK) + return; + + path.Append(SETTINGSFILENAME); + + BFile settingsFile(path.Path(), B_READ_WRITE | B_CREATE_FILE); + + fTPreferences.Unflatten(&settingsFile); + + fTPreferences.SetInt8("autostart", settings.autostart); + fTPreferences.SetInt8("closeWhenDonePlayingMovie", + settings.closeWhenDonePlayingMovie); + fTPreferences.SetInt8("closeWhenDonePlayingSound", + settings.closeWhenDonePlayingSound); + fTPreferences.SetInt8("loopMovie", settings.loopMovie); + fTPreferences.SetInt8("loopSound", settings.loopSound); + fTPreferences.SetInt8("fullVolume", settings.fullVolume); + fTPreferences.SetInt8("halfVolume", settings.halfVolume); + fTPreferences.SetInt8("mute", settings.mute); + + settingsFile.SetSize(0); + settingsFile.Seek(0, SEEK_SET); + + fTPreferences.Flatten(&settingsFile); +} + + +void +Settings::_SetDefault(mpSettings &settings) +{ + memset(&settings, 0, sizeof(settings)); + + settings.autostart = 0; + settings.closeWhenDonePlayingMovie = 0; + settings.closeWhenDonePlayingSound = 0; + settings.loopMovie = 0; + settings.loopSound = 0; + settings.fullVolume = 0; + settings.halfVolume = 0; + settings.mute = 1; +} + + diff --git a/src/apps/mediaplayer/settings/Settings.h b/src/apps/mediaplayer/settings/Settings.h new file mode 100644 index 0000000000..b12245ab63 --- /dev/null +++ b/src/apps/mediaplayer/settings/Settings.h @@ -0,0 +1,38 @@ +/* + * Copyright 2008, Haiku. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Fredrik Modéen + */ + +#ifndef __SETTINGS_H__ +#define __SETTINGS_H__ + +#include +#include + +#include "TPreferences.h" + +struct mpSettings { + int8 + autostart, closeWhenDonePlayingMovie, closeWhenDonePlayingSound, + loopMovie, loopSound, fullVolume, halfVolume, mute; +}; + +#define SETTINGSFILENAME "MediaPlayerSettings" + +class Settings { + public: + Settings(const char *filename = SETTINGSFILENAME); + + void LoadSettings(mpSettings &settings); + void SaveSettings(const mpSettings &settings); + + private: + void _SetDefault(mpSettings &settings); + + TPreferences fTPreferences; +}; + +#endif // __SETTINGS_H__ diff --git a/src/apps/mediaplayer/settings/SettingsWindow.cpp b/src/apps/mediaplayer/settings/SettingsWindow.cpp new file mode 100644 index 0000000000..acf4643301 --- /dev/null +++ b/src/apps/mediaplayer/settings/SettingsWindow.cpp @@ -0,0 +1,182 @@ +/* + * Copyright 2008, Haiku. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Fredrik Modéen + */ + +#include "SettingsWindow.h" + +#include + +#include +#include +#include +#include +#include +#include +#include + +enum { + M_AUTOSTART = 0x3000, + M_CLOSE_WINDOW_MOVIE, + M_CLOSE_WINDOW_SOUNDS, + M_LOOP_MOVIE, + M_LOOP_SOUND, + M_START_FULL_VOLUME, + M_START_HALF_VOLUME, + M_START_MUTE_VOLUME, + M_SETTINGS_SAVE, + M_SETTINGS_CANCEL, +}; + +#define SPACE 10 +#define SPACEING 7 +#define BUTTONHEIGHT 20 + +SettingsWindow::SettingsWindow(BRect frame) + : BWindow(frame, "Settings", B_MODAL_WINDOW, B_NOT_CLOSABLE | B_NOT_ZOOMABLE + | B_NOT_RESIZABLE) +{ + fSettingsObj = new Settings(); + fSettingsObj->LoadSettings(fSettings); + + frame = Bounds(); + BView* view = new BView(frame,"SettingsView",B_FOLLOW_ALL_SIDES,B_WILL_DRAW); + view->SetViewColor(216, 216, 216); + + BRect btnRect(140.00, frame.bottom - (SPACE + BUTTONHEIGHT), 205.00, + frame.bottom-SPACE); + BButton* btn = new BButton(btnRect, "btnCancel", "Cancel", + new BMessage(M_SETTINGS_CANCEL)); + view->AddChild(btn); + + btnRect.OffsetBy(btnRect.Width() + SPACE, 0); + btn = new BButton(btnRect, "btnOK", "OK", new BMessage(M_SETTINGS_SAVE)); + view->AddChild(btn); + + BRect rectBox(frame.left + SPACE, frame.top + SPACE, frame.right - SPACE, + btnRect.top- SPACE); + BBox* bbox = new BBox(rectBox, "box1", B_FOLLOW_ALL_SIDES,B_WILL_DRAW | B_NAVIGABLE, + B_FANCY_BORDER); + bbox->SetLabel("MediaPlayer Settings"); + + BFont font; + font_height fh1; + font.GetHeight(&fh1); + + BString str("Play Mode:"); + BRect rect(rectBox.left, rectBox.top + SPACE, rectBox.right - (12*2), + rectBox.top + fh1.leading + fh1.ascent + 10); + bbox->AddChild(new BStringView(rect, "stringViewPlayMode", str.String())); + + rect.OffsetBy(0, rect.Height()); + bbox->AddChild(fChkboxAutostart = new BCheckBox(rect, "chkboxAutostart", + "Automatically start playing", new BMessage(M_AUTOSTART))); + + rect.OffsetBy(SPACE, rect.Height() + SPACEING); + bbox->AddChild(fChkBoxCloseWindowMovies = new BCheckBox(rect, "chkBoxCloseWindowMovies", + "Close window when done playing movies", new BMessage(M_CLOSE_WINDOW_MOVIE))); + + rect.OffsetBy(0, rect.Height() + SPACEING); + bbox->AddChild(fChkBoxCloseWindowSounds = new BCheckBox(rect, "chkBoxCloseWindowSounds", + "Close window when done playing sounds", new BMessage(M_CLOSE_WINDOW_SOUNDS))); + + rect.OffsetBy(-SPACE, rect.Height() + SPACEING); + bbox->AddChild(fChkBoxLoopMovie = new BCheckBox(rect, "chkBoxLoopMovie", "Loop movies by default", + new BMessage(M_LOOP_MOVIE))); + + rect.OffsetBy(0, rect.Height() + SPACEING); + bbox->AddChild(fChkBoxLoopSounds = new BCheckBox(rect, "chkBoxLoopSounds", "Loop sounds by default", + new BMessage(M_LOOP_SOUND))); + + rect.OffsetBy(0, rect.Height() + SPACE + SPACEING); + bbox->AddChild(new BStringView(rect, "stringViewPlayBackg", + "Play backgrounds movies at:")); + + rect.OffsetBy(SPACE, rect.Height() + SPACEING); + fRdbtnfullvolume = new BRadioButton(rect, "rdbtnfullvolume", + "Full Volume", new BMessage(M_START_FULL_VOLUME)); + bbox->AddChild(fRdbtnfullvolume); + + rect.OffsetBy(0, rect.Height() + SPACEING); + fRdbtnhalfvolume = new BRadioButton(rect, "rdbtnhalfvolume", + "Half Volume", new BMessage(M_START_HALF_VOLUME)); + bbox->AddChild(fRdbtnhalfvolume); + + rect.OffsetBy(0, rect.Height() + SPACEING); + fRdbtnmutevolume = new BRadioButton(rect, "rdbtnfullvolume", "Muted", + new BMessage(M_START_MUTE_VOLUME)); + bbox->AddChild(fRdbtnmutevolume); + + SetSettings(); + + view->AddChild(bbox); + AddChild(view); +} + + +SettingsWindow::~SettingsWindow() +{ +} + + +void +SettingsWindow::SetSettings() +{ + fChkboxAutostart->SetValue(fSettings.autostart); + fChkBoxCloseWindowMovies->SetValue(fSettings.closeWhenDonePlayingMovie); + fChkBoxCloseWindowSounds->SetValue(fSettings.closeWhenDonePlayingSound); + fChkBoxLoopMovie->SetValue(fSettings.loopMovie); + fChkBoxLoopSounds->SetValue(fSettings.loopSound); + fRdbtnfullvolume->SetValue(fSettings.fullVolume); + fRdbtnhalfvolume->SetValue(fSettings.halfVolume); + fRdbtnmutevolume->SetValue(fSettings.mute); +} + + +bool +SettingsWindow::QuitRequested() +{ + Hide(); + return false; +} + + +void +SettingsWindow::MessageReceived(BMessage* message) +{ + switch (message->what) { + case M_AUTOSTART: + case M_CLOSE_WINDOW_MOVIE: + case M_CLOSE_WINDOW_SOUNDS: + case M_LOOP_MOVIE: + case M_LOOP_SOUND: + case M_START_FULL_VOLUME: + case M_START_HALF_VOLUME: + case M_START_MUTE_VOLUME: + fSettings.autostart = fChkboxAutostart->Value(); + fSettings.closeWhenDonePlayingMovie = fChkBoxCloseWindowMovies->Value(); + fSettings.closeWhenDonePlayingSound = fChkBoxCloseWindowSounds->Value(); + fSettings.loopMovie = fChkBoxLoopMovie->Value(); + fSettings.loopSound = fChkBoxLoopSounds->Value(); + fSettings.fullVolume = fRdbtnfullvolume->Value(); + fSettings.halfVolume = fRdbtnhalfvolume->Value(); + fSettings.mute = fRdbtnmutevolume->Value(); + case B_KEY_DOWN: + int32 index; + if(message->FindInt32("key", &index) == B_NO_ERROR) + if(index == 1) + PostMessage(B_QUIT_REQUESTED); + break; + case M_SETTINGS_SAVE: + fSettingsObj->SaveSettings(fSettings); + case M_SETTINGS_CANCEL: + PostMessage(B_QUIT_REQUESTED); + break; + default: + BWindow::MessageReceived(message); + break; + } +} diff --git a/src/apps/mediaplayer/settings/SettingsWindow.h b/src/apps/mediaplayer/settings/SettingsWindow.h new file mode 100644 index 0000000000..b2faaaaf7f --- /dev/null +++ b/src/apps/mediaplayer/settings/SettingsWindow.h @@ -0,0 +1,39 @@ +/* + * Copyright 2008, Haiku. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Fredrik Modéen + */ + +#ifndef _SETTINGS_WINDOW_H +#define _SETTINGS_WINDOW_H + +#include +#include +#include + +#include "Settings.h" + +class SettingsWindow : public BWindow { + public: + SettingsWindow(BRect frame); + virtual ~SettingsWindow(); + void SetSettings(); + virtual bool QuitRequested(); + virtual void MessageReceived(BMessage* message); + private: + Settings* fSettingsObj; + mpSettings fSettings; + + BCheckBox* fChkboxAutostart; + BCheckBox* fChkBoxCloseWindowMovies; + BCheckBox* fChkBoxCloseWindowSounds; + BCheckBox* fChkBoxLoopMovie; + BCheckBox* fChkBoxLoopSounds; + BRadioButton* fRdbtnfullvolume; + BRadioButton* fRdbtnhalfvolume; + BRadioButton* fRdbtnmutevolume; +}; + +#endif