1 /* 2 * Copyright 2003, Jérôme Duval. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 7 #include <map> 8 9 #include <Entry.h> 10 #include <File.h> 11 #include <Locker.h> 12 #include <MessageRunner.h> 13 #include <String.h> 14 15 #include <DataExchange.h> 16 17 18 #define MEDIA_FILES_MANAGER_SAVE_TIMER 'mmst' 19 20 21 class MediaFilesManager : BLocker { 22 public: 23 MediaFilesManager(); 24 ~MediaFilesManager(); 25 26 status_t SaveState(); 27 28 void Dump(); 29 30 area_id GetTypesArea(int32& count); 31 area_id GetItemsArea(const char* type, int32& count); 32 33 status_t GetRefFor(const char* type, const char* item, 34 entry_ref** _ref); 35 status_t GetAudioGainFor(const char* type, 36 const char* item, float* _gain); 37 status_t SetRefFor(const char* type, const char* item, 38 const entry_ref& ref); 39 status_t SetAudioGainFor(const char* type, 40 const char* item, float gain); 41 status_t InvalidateItem(const char* type, 42 const char* item); 43 status_t RemoveItem(const char* type, const char* item); 44 45 void TimerMessage(); 46 47 void HandleAddSystemBeepEvent(BMessage* message); 48 49 private: 50 struct item_info { 51 item_info() : gain(1.0f) {} 52 53 entry_ref ref; 54 float gain; 55 }; 56 57 void _LaunchTimer(); 58 status_t _GetItem(const char* type, const char* item, 59 item_info*& info); 60 status_t _SetItem(const char* type, const char* item, 61 const entry_ref* ref = NULL, 62 const float* gain = NULL); 63 status_t _OpenSettingsFile(BFile& file, int mode); 64 status_t _LoadState(); 65 66 private: 67 typedef std::map<BString, item_info> ItemMap; 68 typedef std::map<BString, ItemMap> TypeMap; 69 70 TypeMap fMap; 71 BMessageRunner* fSaveTimerRunner; 72 }; 73