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