]> git.vomp.tv Git - vompclient.git/blob - media.cc
German updates
[vompclient.git] / media.cc
1 /*
2     Copyright 2004-2005 Chris Tallon, Andreas Vogel
3
4     This file is part of VOMP.
5
6     VOMP is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     VOMP is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with VOMP; if not, write to the Free Software
18     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 */
20
21 #include "media.h"
22 #include "vdr.h"
23 #include <time.h>
24
25 Media* Media::recInfoFor = NULL;
26
27
28 Media::Media()
29 {
30   start = 0;
31   displayName = NULL;
32   fileName = NULL;
33   index = -1;
34   markList = NULL;
35   mediaType=MEDIA_TYPE_UNKNOWN;
36 }
37
38 Media::~Media()
39 {
40   if (displayName) { delete[] displayName; displayName = NULL; }
41   if (fileName) { delete[] fileName; fileName = NULL; }
42   index = -1; // just in case
43
44   if (markList && markList->size())
45   {
46     for(UINT i = 0; i < markList->size(); i++)
47     {
48       delete (*markList)[i];
49     }
50     markList->clear();
51     Log::getInstance()->log("Media", Log::DEBUG, "Media destructor, marks list deleted");
52   }
53
54   if (markList) delete markList;
55 }
56
57 ULONG Media::getTime() const
58 {
59   return start;
60 }
61
62 const char* Media::getDisplayName() const
63 {
64   if (displayName) return displayName;
65   return fileName;
66 }
67
68 const char* Media::getFileName() const
69 {
70   return fileName;
71 }
72
73 void Media::setTime(ULONG tstartTime)
74 {
75   start = tstartTime;
76 }
77
78 void Media::setMediaType(int mtype)
79 {
80   mediaType=mtype;
81 }
82
83 int Media::getMediaType() const
84 {
85   return mediaType;
86 }
87
88 void Media::setDisplayName(char* tDisplayName)
89 {
90   if (displayName) delete[] displayName;
91
92   displayName = new char[strlen(tDisplayName) + 1];
93   if (displayName) strcpy(displayName, tDisplayName);
94 }
95
96 void Media::setFileName(char* tFileName)
97 {
98   if (fileName) delete[] fileName;
99
100   fileName = new char[strlen(tFileName) + 1];
101   if (fileName) strcpy(fileName, tFileName);
102 }
103
104 char * Media::getTimeString(char * buffer) const {
105   if (! buffer) buffer=new char[TIMEBUFLEN];
106   struct tm ltime;
107   time_t recStartTime = (time_t)getTime();
108   struct tm *btime = localtime(&recStartTime);
109   memcpy(&ltime,btime, sizeof(struct tm));
110   btime=&ltime;
111   if (btime && recStartTime != 0) {
112 #ifndef _MSC_VER
113   strftime(buffer,TIMEBUFLEN, "%0g/%0m/%0d %0H:%0M ", btime);
114 #else
115   strftime(buffer, TIMEBUFLEN, "%g/%m/%d %H:%M ", btime);
116 #endif
117   }
118   else {
119     SNPRINTF(buffer,TIMEBUFLEN,"00/00/00 00:00 ");
120     }
121   return buffer;
122 }
123
124 void Media::loadMarks()
125 {
126   markList = VDR::getInstance()->getMarks(fileName);
127 }
128
129
130
131 int Media::getPrevMark(int currentFrame)
132 {
133   MarkList::reverse_iterator i;
134   Mark* loopMark = NULL;
135
136   if (!markList || !markList->size()) return 0;
137
138   for(i = markList->rbegin(); i != markList->rend(); i++)
139   {
140     loopMark = *i;
141     Log::getInstance()->log("Media", Log::NOTICE, "findprev:comparing Frame %i with current Frame %i",loopMark->pos,currentFrame);
142
143     if (loopMark->pos < currentFrame)
144     {
145       Log::getInstance()->log("Media", Log::NOTICE, "findprev:setting pos %i to jumpframe_target",loopMark->pos);
146       return loopMark->pos;
147     }
148   }
149
150   // No previous mark
151   return 0;
152 }
153
154 int Media::getNextMark(int currentFrame)
155 {
156   MarkList::iterator i;
157   Mark* loopMark = NULL;
158
159   if (!markList || !markList->size()) return 0;
160
161   for(i = markList->begin(); i != markList->end(); i++)
162   {
163     loopMark = *i;
164     Log::getInstance()->log("Media", Log::NOTICE, "findnext:comparing Frame %i with current Frame %i",loopMark->pos,currentFrame);
165
166     if (loopMark->pos > currentFrame)
167     {
168       Log::getInstance()->log("Media", Log::NOTICE, "findnext:setting pos %i to jumpframe_target",loopMark->pos);
169       return loopMark->pos;
170     }
171   }
172
173   // No next mark
174   return 0;
175 }
176
177 bool Media::hasMarks()
178 {
179   return (markList && markList->size());
180 }
181
182 MarkList* Media::getMarkList()
183 {
184   return markList;
185 }