summaryrefslogtreecommitdiff
path: root/logolist.c
blob: 2491f7f462d0c5e9b44548f8e5d813a3f92318b9 (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/**
 *  GraphLCD plugin for the Video Disk Recorder
 *
 *  logolist.c  -  logo list class
 *
 *  (c) 2001-2004 Carsten Siebholz <c.siebholz AT t-online de>
 **/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program;                                              *
 *   if not, write to the Free Software Foundation, Inc.,                  *
 *   59 Temple Place, Suite 330, Boston, MA  02111-1307  USA               *
 *                                                                         *
 ***************************************************************************/

#include <fstream>

#include <glcdgraphics/bitmap.h>
#include <glcdgraphics/image.h>
#include <glcdgraphics/glcd.h>

#include "logolist.h"
#include "strfct.h"

#include <vdr/tools.h>

const char * kGLCDFileExtension = ".glcd";
const char * kAliasFileName = "logonames.alias";

cGraphLCDLogoList::cGraphLCDLogoList(const std::string & logodir, const std::string & cfgdir)
{
    std::fstream file;
    char readLine[1000];
    std::string line;
    std::string aliasFileName;
    std::string::size_type pos;
    tAliasListElement * newAlias;

    logoDir = logodir;
    aliasFileName = AddDirectory(cfgdir.c_str(), kAliasFileName);

#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())
        return;

    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;
        newAlias = new tAliasListElement;
        if (newAlias)
        {
            newAlias->channelID = trim(line.substr(0, pos));
            newAlias->fileName = trim(line.substr(pos + 1));
            aliasList.push_back(newAlias);
        }
    }
    file.close();
/*
     std::list <tAliasListElement *>::iterator it;
     for (it = aliasList.begin(); it != aliasList.end(); it++)
     {
      newAlias = *it;
      printf(">>>>>> AliasList:  >%s< : >%s<\n", newAlias->channelID.c_str(), newAlias->fileName.c_str());
     }
*/
}

cGraphLCDLogoList::~cGraphLCDLogoList()
{
    std::list <tAliasListElement *>::iterator itAlias;
    std::list <cGraphLCDLogo *>::iterator itLogo;

    for (itAlias = aliasList.begin(); itAlias != aliasList.end(); itAlias++)
    {
        delete *itAlias;
    }
    aliasList.empty();

    for (itLogo = logoList.begin(); itLogo != logoList.end(); itLogo++)
    {
        delete *itLogo;
    }
    logoList.empty();
}

std::string cGraphLCDLogoList::CreateFullFileName(const std::string & baseName, ePicType type)
{
    std::string tmp;

    tmp = AddDirectory(logoDir.c_str(), baseName.c_str());

    switch (type)
    {
        case ptPictureFixed:  // do not attach anything
            break;
        case ptLogoSmall:
            tmp += "_s";
            break;
        case ptLogoMedium:
            tmp += "_m";
            break;
        case ptLogoLarge:
            tmp += "_l";
            break;
    }
    tmp += kGLCDFileExtension;

    return tmp;
}

cGraphLCDLogo * cGraphLCDLogoList::GetLogo(const std::string & chID, ePicType type)
{
    std::list <cGraphLCDLogo *>::iterator itLogo;
    std::list <tAliasListElement *>::iterator itAlias;
    std::string logoFileName = "";
    cGraphLCDLogo * newLogo;
    GLCD::cGLCDFile glcd;

    for (itLogo = logoList.begin(); itLogo != logoList.end(); itLogo++)
    {
        if ((*itLogo)->ID() == chID)
        {
            return *itLogo;
        }
    }

    for (itAlias = aliasList.begin(); itAlias != aliasList.end(); itAlias++)
    {
        if ((*itAlias)->channelID == chID)
        {
            logoFileName = CreateFullFileName((*itAlias)->fileName, type);
            break;
        }
    }
    if (itAlias == aliasList.end())
        logoFileName = CreateFullFileName(chID, type);

    // try to load logo
    newLogo = new cGraphLCDLogo(chID);
    if (glcd.Load(*newLogo, logoFileName))
    {
        logoList.push_back(newLogo);
        return newLogo;
    }
    else
    {
        delete newLogo;
        return NULL;
    }
    return NULL;
}