2 * This file is a part of BeOS USBVision driver project.
3 * Copyright (c) 2003 by Siarzuk Zharski <imker@gmx.li>
5 * This file may be used under the terms of the BSD License
11 #include <FindDirectory.h>
14 #include "TunerLocale.h"
16 using namespace Locale
;
18 const char *kLocalesSettings
= "media/usb_vision/Locales";
20 Channel::Channel(string
&str
, uint32 frequency
):
21 fName(str
), fFrequency(frequency
)
25 const string
&Channel::Name() const
29 const uint32
Channel::Frequency()
34 TunerLocale::TunerLocale(BEntry
&entry
)
39 if((fStatus
= entry
.GetPath(&path
)) == B_OK
){
40 char name
[B_FILE_NAME_LENGTH
];
41 if((fStatus
= entry
.GetName(name
)) == B_OK
){
43 fStatus
= LoadLocale(path
.Path());
49 TunerLocale::~TunerLocale()
53 status_t
TunerLocale::InitCheck()
58 status_t
TunerLocale::LoadLocale(const char *name
)
60 status_t status
= B_OK
;
62 while(ifs
.good() && !ifs
.eof()){
65 //TODO : validity check and parse strings ...
66 str
.erase(0, str
.find_first_not_of(" \t"));
67 str
.erase(str
.find_last_not_of(" \t") + 1);
74 default: //TODO parse ...
75 Channel
channel(str
, 0);
76 fChannels
.push_back(channel
);
83 status_t
TunerLocale::LoadLocales(vector
<TunerLocale
*> &vector
)
85 status_t status
= B_ERROR
;
87 if((status
= find_directory(B_USER_SETTINGS_DIRECTORY
, &path
)) != B_OK
)
89 if((status
= path
.Append(kLocalesSettings
)) != B_OK
)
91 BDirectory
directory(path
.Path());
92 if((status
= directory
.InitCheck()) != B_OK
)
96 while((status
= directory
.GetNextEntry(&entry
)) == B_OK
){
98 TunerLocale
*locale
= new TunerLocale(entry
);
99 if((status
= locale
->InitCheck()) == B_OK
){
100 vector
.push_back(locale
);
106 if(status
== B_ENTRY_NOT_FOUND
) //we reached the end of entries list ...
111 status_t
TunerLocale::ReleaseLocales(vector
<TunerLocale
*> &vector
)
113 for(LocalesIterator locale
= vector
.begin();
114 locale
!= vector
.end(); locale
++){
120 const string
&TunerLocale::Name()
125 const Channel
&TunerLocale::GetChannel(int idx
)
128 if(idx
>= (int)fChannels
.size()) idx
= (int)(fChannels
.size() - 1);
129 return fChannels
[idx
];
132 uint32
TunerLocale::ChannelsCount()
134 return fChannels
.size();