From 8e956baea7ce6c3af8e50ea229914e87d63fbeed Mon Sep 17 00:00:00 2001 From: urnenfeld Date: Sat, 22 May 2010 14:17:02 +0000 Subject: [PATCH] Remove ignored typedef warning for GCC4 --- application/preferences/CayaPreferences.h | 6 +- .../preferences/PreferencesContainer.h | 57 +++++++++++++++++-- 2 files changed, 55 insertions(+), 8 deletions(-) diff --git a/application/preferences/CayaPreferences.h b/application/preferences/CayaPreferences.h index 8be989a..6ab7442 100644 --- a/application/preferences/CayaPreferences.h +++ b/application/preferences/CayaPreferences.h @@ -7,20 +7,20 @@ #include "PreferencesContainer.h" -typedef struct CayaPreferencesData +typedef struct _CayaPreferencesData { bool MoveToCurrentWorkspace; bool ActivateWindow; bool IgnoreEmoticons; - CayaPreferencesData() + _CayaPreferencesData() : MoveToCurrentWorkspace(true), ActivateWindow(true), IgnoreEmoticons(false) { } -}; +} CayaPreferencesData; typedef PreferencesContainer CayaPreferences; diff --git a/application/preferences/PreferencesContainer.h b/application/preferences/PreferencesContainer.h index 99cd6cf..58abf2f 100644 --- a/application/preferences/PreferencesContainer.h +++ b/application/preferences/PreferencesContainer.h @@ -7,6 +7,11 @@ #include +#include +#include +#include +#include + // TODO: added to main singleton class? template T* Singleton::fInstance = 0; @@ -15,7 +20,6 @@ template class PreferencesContainer : public Singleton > { public: - static const char* fFilename; static SettingsType* Item() @@ -23,13 +27,56 @@ public: return &(Singleton >::Get()->fSettings); } - // TODO: - // status_t Save(); - // status_t Load(); + + status_t Load() + { + if (fPreferencesFile.SetTo(&fDirectory, fFilename, + B_READ_WRITE | B_FAIL_IF_EXISTS) == B_OK) { + + // reset the file pointer + fPreferencesFile.Seek(0, SEEK_SET); + + if (fPreferencesFile.Read(&fSettings, sizeof(SettingsType)) > 0) + return B_OK; + } + + return B_ERROR; + } + + + status_t Save() + { + if (fPreferencesFile.SetTo(&fDirectory, fFilename, + B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE) == B_OK) { + + if (fPreferencesFile.Write(&fSettings, sizeof(SettingsType)) > 0) + return B_OK; + } + + return B_ERROR; + } private: - SettingsType fSettings; + PreferencesContainer() + : Singleton >() + { + BPath path; + find_directory(B_USER_SETTINGS_DIRECTORY, &path); + path.Append(fFolder); + fDirectory.SetTo(path.Path()); + + Load(); + } + + friend class Singleton >; + + SettingsType fSettings; + BFile fPreferencesFile; + BDirectory fDirectory; + + static const char* fFilename; + static const char* fFolder; };