4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
6 * This program 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.
11 * This program 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.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include "channeldb.h"
27 #include "filesystem.h"
29 #include "recordlabel.h"
32 Batch::Batch(MWindow *mwindow, Record *record)
34 this->mwindow = mwindow;
35 this->record = record;
37 labels = new RecordLabels;
38 record_mode = RECORD_UNTIMED;
43 start_time = last_start_time = 0.;
44 duration = record_duration = 0.;
45 start_day = 0; last_start_day = -1;
54 asset->Garbage::remove_user();
58 void Batch::create_objects()
62 void Batch::clear_labels()
64 while(labels->last) delete labels->last;
67 void Batch::start_over()
72 void Batch::copy_from(Batch *batch)
74 record_mode = batch->record_mode;
75 channel = batch->channel;
76 enabled = batch->enabled;
77 start_time = batch->start_time;
78 duration = batch->duration;
79 record_duration = batch->record_duration;
80 start_day = batch->start_day;
85 void Batch::calculate_news()
87 if( notice ) sprintf(news, "%s", notice);
88 else if( record && record->get_current_batch() == this ) {
89 FileSystem fs; char text[BCTEXTLEN];
90 int64_t bytes = fs.get_size(asset->path);
92 Units::size_totext(bytes, text);
93 const char *stat = record->file ? _("Open") :
94 !this->enabled ? _("Done") : _("Ok");
95 sprintf(news,"%s %s", text, stat);
98 sprintf(news,"%s", _("New file"));
101 sprintf(news, "%s", !access(asset->path, F_OK) ?
102 _("Exists") : _("New file"));
106 void Batch::create_default_path()
108 char string[BCTEXTLEN];
109 strcpy(string, record->default_asset->path);
110 char *path = asset->path;
111 strcpy(path, record->default_asset->path);
115 if( ch == '/' ) k = i;
118 while( path[i] && (path[i]<'0' || path[i]>'9') ) ++i;
120 while( path[i] && (path[i]>='0' || path[i]<='9') ) ++i;
123 sprintf(&path[j], "%d", record->record_batches.total());
124 strcat(path, &string[l]);
128 int Batch::text_to_mode(const char *text)
130 if(!strcasecmp(mode_to_text(RECORD_UNTIMED), text)) return RECORD_UNTIMED;
131 if(!strcasecmp(mode_to_text(RECORD_TIMED), text)) return RECORD_TIMED;
132 return RECORD_UNTIMED;
135 const char* Batch::mode_to_text(int record_mode)
137 switch( record_mode ) {
138 case RECORD_UNTIMED: return _("Untimed");
139 case RECORD_TIMED: return _("Timed");
144 Channel* Batch::get_current_channel()
150 const char* Batch::get_source_text()
152 Channel *channel = get_current_channel();
153 return channel ? channel->title : "";
156 void Batch::toggle_label(double position)
158 labels->toggle_label(position);
161 void Batch::update_times()
163 if( start_time != last_start_time ||
164 start_day != last_start_day ) {
165 last_start_day = start_day;
166 last_start_time = start_time;
167 int64_t seconds = start_time;
168 int hour = seconds/3600;
169 int minute = seconds/60 - hour*60;
170 int second = seconds - (hour*3600 + minute*60);
171 struct timeval tv; struct timezone tz;
172 gettimeofday(&tv, &tz); time_t t = tv.tv_sec;
173 if( !strcmp(tzname[0],"UTC") ) t -= tz.tz_minuteswest*60;
174 struct tm tm; localtime_r(&t, &tm);
175 if( start_day < 7 && start_day != tm.tm_wday ) {
176 int days = start_day - tm.tm_wday;
177 if( days < 0 ) days += 7;
178 t += days * 7*24*3600;
179 localtime_r(&t, &tm);
184 time_start = mktime(&tm);
186 time_end = time_start + (int)duration;