summaryrefslogtreecommitdiff
path: root/alias.c
blob: 4ec626505eafbcd59d743ef99c0bfcedde5fcea9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
 * GraphLCD plugin for the Video Disk Recorder
 *
 * alias.c - alias class for converting channel id to its alias name
 *
 * This file is released under the GNU General Public License. Refer
 * to the COPYING file distributed with this package.
 *
 * (c) 2001-2004 Carsten Siebholz <c.siebholz AT t-online.de>
 * (c) 2004 Andreas Regel <andreas.regel AT powarman.de>
 */

#include <fstream>

#include "alias.h"
#include "strfct.h"

#include <vdr/tools.h>

const char * kChannelAliasFileName = "channels.alias";

bool cChannelAliasList::Load(const std::string & CfgPath)
{
    std::fstream file;
    char readLine[1000];
    std::string line;
    std::string aliasFileName;
    std::string::size_type pos;
    std::string id;
    std::string alias;

    aliasFileName = CfgPath + "/" + kChannelAliasFileName;

#if (__GNUC__ < 3)
    file.open(aliasFileName.c_str(), std::ios::in);
#else
    file.open(aliasFileName.c_str(), std::ios_base::in);
#endif
    if (!file.is_open())
    {
        esyslog("graphlcd: Error opening channel alias file %s!", aliasFileName.c_str());
        return false;
    }

    while (!file.eof())
    {
        file.getline(readLine, 1000);
        line = trim(readLine);
        if (line.length() == 0)
            continue;
        if (line[0] == '#')
            continue;
        pos = line.find(":");
        if (pos == std::string::npos)
            continue;
        id = trim(line.substr(0, pos));
        alias = trim(line.substr(pos + 1));
        mAliases.insert(std::make_pair(id, alias));
    }
    file.close();

    return true;
}

std::string cChannelAliasList::GetAlias(const std::string & ChannelID) const
{
    std::map<std::string, std::string>::const_iterator pos;

    pos = mAliases.find(ChannelID);
    if (pos != mAliases.end())
        return pos->second;
    return "";
}