3rdparty/licenseReport: Add seperate LGPL checks
[haiku.git] / src / add-ons / media / media-add-ons / usb_vision / TunerLocale.cpp
blobb60e1327ccfd3e9828325713a55a40a63a274f7b
1 /*
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
7 */
8 #include <Path.h>
9 #include <Directory.h>
10 #include <Entry.h>
11 #include <FindDirectory.h>
12 #include <fstream.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
27 return fName;
29 const uint32 Channel::Frequency()
31 return fFrequency;
34 TunerLocale::TunerLocale(BEntry &entry)
36 fStatus = B_NO_INIT;
37 if(entry.IsFile()){
38 BPath path;
39 if((fStatus = entry.GetPath(&path)) == B_OK){
40 char name[B_FILE_NAME_LENGTH];
41 if((fStatus = entry.GetName(name)) == B_OK){
42 fName = name;
43 fStatus = LoadLocale(path.Path());
49 TunerLocale::~TunerLocale()
53 status_t TunerLocale::InitCheck()
55 return fStatus;
58 status_t TunerLocale::LoadLocale(const char *name)
60 status_t status = B_OK;
61 ifstream ifs(name);
62 while(ifs.good() && !ifs.eof()){
63 string str;
64 getline(ifs, str);
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);
68 switch(str[0]){
69 case ';': continue;
70 case '@':
71 str.erase(0, 1);
72 fName = str;
73 break;
74 default: //TODO parse ...
75 Channel channel(str, 0);
76 fChannels.push_back(channel);
77 break;
80 return status;
83 status_t TunerLocale::LoadLocales(vector<TunerLocale *> &vector)
85 status_t status = B_ERROR;
86 BPath path;
87 if((status = find_directory(B_USER_SETTINGS_DIRECTORY, &path)) != B_OK)
88 return status;
89 if((status = path.Append(kLocalesSettings)) != B_OK)
90 return status;
91 BDirectory directory(path.Path());
92 if((status = directory.InitCheck()) != B_OK)
93 return status;
94 vector.clear();
95 BEntry entry;
96 while((status = directory.GetNextEntry(&entry)) == B_OK){
97 if(entry.IsFile()){
98 TunerLocale *locale = new TunerLocale(entry);
99 if((status = locale->InitCheck()) == B_OK){
100 vector.push_back(locale);
102 else
103 delete locale;
106 if(status == B_ENTRY_NOT_FOUND) //we reached the end of entries list ...
107 status = B_OK;
108 return status;
111 status_t TunerLocale::ReleaseLocales(vector<TunerLocale *> &vector)
113 for(LocalesIterator locale = vector.begin();
114 locale != vector.end(); locale ++){
115 delete *locale;
117 return B_OK;
120 const string &TunerLocale::Name()
122 return fName;
125 const Channel &TunerLocale::GetChannel(int idx)
127 if(idx < 0) idx = 0;
128 if(idx >= (int)fChannels.size()) idx = (int)(fChannels.size() - 1);
129 return fChannels[idx];
132 uint32 TunerLocale::ChannelsCount()
134 return fChannels.size();