11 #include "bclistbox.h"
13 #include "channeldb.h"
14 #include "filesystem.h"
17 #include "recordbatches.h"
18 #include "timeentry.h"
20 const char * RecordBatches::
22 N_("On"), N_("Path"), N_("News"), N_("Start time"),
23 N_("Duration"), N_("Source"), N_("Mode")
26 const int RecordBatches::
27 default_columnwidth[] = {
28 30, 200, 100, 100, 100, 100, 70
32 load_defaults(ChannelDB * channeldb, Record * record)
34 char string[BCTEXTLEN];
35 BC_Hash *defaults = mwindow->defaults;
36 defaults->get("RECORD_DEFAULT_DIRECTORY", default_directory);
37 early_margin = defaults->get("RECORD_EARLY_MARGIN", early_margin);
38 late_margin = defaults->get("RECORD_LATE_MARGIN", late_margin);
39 for(int i = 0; i < BATCH_COLUMNS; i++) {
40 sprintf(string, "BATCH_COLUMNWIDTH_%d", i);
41 column_widths[i] = defaults->get(string, default_columnwidth[i]);
43 int total_batches = defaults->get("TOTAL_BATCHES", 1);
44 if(total_batches < 1) total_batches = 1;
45 for(int i = 0; i < total_batches; ++i) {
46 Batch *batch = new Batch(mwindow, record);
47 batch->create_objects();
48 batches.append(batch);
49 Asset *asset = batch->asset;
50 sprintf(string, "RECORD_PATH_%d", i);
51 defaults->get(string, asset->path);
52 sprintf(string, "RECORD_CHANNEL_%d", i);
53 int chan_no = channeldb->number_of(batch->channel);
54 chan_no = defaults->get(string, chan_no);
55 batch->channel = channeldb->get(chan_no);
56 sprintf(string, "RECORD_STARTDAY_%d", i);
57 batch->start_day = defaults->get(string, batch->start_day);
58 sprintf(string, "RECORD_STARTTIME_%d", i);
59 batch->start_time = defaults->get(string, batch->start_time);
60 sprintf(string, "RECORD_DURATION_%d", i);
61 batch->duration = defaults->get(string, batch->duration);
62 sprintf(string, "RECORD_MODE_%d", i);
63 batch->record_mode = defaults->get(string, batch->record_mode);
64 sprintf(string, "BATCH_ENABLED_%d", i);
65 batch->enabled = defaults->get(string, batch->enabled);
66 batch->update_times();
69 current_item = editing_item = 0;
73 save_defaults(ChannelDB * channeldb)
75 char string[BCTEXTLEN];
76 BC_Hash *defaults = mwindow->defaults;
77 defaults->update("RECORD_DEFAULT_DIRECTORY", default_directory);
78 defaults->update("RECORD_EARLY_MARGIN", early_margin);
79 defaults->update("RECORD_LATE_MARGIN", late_margin);
80 for(int i = 0; i < BATCH_COLUMNS; i++) {
81 sprintf(string, "BATCH_COLUMNWIDTH_%d", i);
82 defaults->update(string, column_widths[i]);
85 defaults->update("TOTAL_BATCHES", batches.total);
86 for(int i = 0; i < batches.total; ++i) {
87 Batch *batch = batches.values[i];
88 Asset *asset = batch->asset;
89 sprintf(string, "RECORD_PATH_%d", i);
90 defaults->update(string, asset->path);
91 sprintf(string, "RECORD_CHANNEL_%d", i);
92 int chan_no = channeldb->number_of(batch->channel);
93 defaults->update(string, chan_no);
94 sprintf(string, "RECORD_STARTDAY_%d", i);
95 defaults->update(string, batch->start_day);
96 sprintf(string, "RECORD_STARTTIME_%d", i);
97 defaults->update(string, batch->start_time);
98 sprintf(string, "RECORD_DURATION_%d", i);
99 defaults->update(string, batch->duration);
100 sprintf(string, "RECORD_MODE_%d", i);
101 defaults->update(string, batch->record_mode);
102 sprintf(string, "BATCH_ENABLED_%d", i);
103 defaults->update(string, batch->enabled);
108 save_default_channel(ChannelDB * channeldb)
110 BC_Hash *defaults = mwindow->defaults;
111 Batch *batch = get_editing_batch();
113 int chan_no = channeldb->number_of(batch->channel);
114 if( chan_no < 0 ) return;
115 defaults->update("RECORD_CURRENT_CHANNEL", chan_no);
119 RecordBatches(MWindow * mwindow)
121 this->mwindow = mwindow;
122 editing_item = current_item = -1;
124 early_margin = late_margin = 0.;
125 default_directory[0] = 0;
136 batches.remove(batch);
137 int total_batches = total();
138 if( current_item == editing_item ) {
139 if(current_item >= total_batches)
140 current_item = total_batches - 1;
141 editing_item = current_item;
144 if(current_item > editing_item)
146 if( editing_item >= total_batches )
147 editing_item = total_batches - 1;
154 batches.remove_all_objects();
155 for(int j = 0; j < BATCH_COLUMNS; j++) {
156 data[j].remove_all_objects();
158 current_item = editing_item = -1;
162 RecordBatchesGUI(RecordBatches &batches,
163 int x, int y, int w, int h)
164 : BC_ListBox(x, y, w, h, LISTBOX_TEXT, // Display text list or icons
165 batches.data, // Each column has an ArrayList of BC_ListBoxItems.
166 batches.batch_titles, // Titles for columns. Set to 0 for no titles
167 batches.column_widths, // width of each column
168 BATCH_COLUMNS, // Total columns.
169 0, // Pixel of top of window.
170 0, // If this listbox is a popup window
171 LISTBOX_SINGLE, // Select one item or multiple items
172 ICON_LEFT, // Position of icon relative to text of each item
173 1), // Allow dragging
179 // Do nothing for double clicks to protect active batch
180 int RecordBatchesGUI::
186 int RecordBatchesGUI::
187 update(int highlighted_item, int recalc_positions)
189 return BC_ListBox::update(batches.data, batches.batch_titles,
190 batches.column_widths, BATCH_COLUMNS,
191 get_xposition(), get_yposition(),
192 highlighted_item, recalc_positions);
195 int RecordBatchesGUI::
196 column_resize_event()
198 for(int i = 0; i < BATCH_COLUMNS; i++) {
199 batches.column_widths[i] = get_column_width(i);
204 int RecordBatchesGUI::
207 if(!BC_ListBox::drag_start_event()) return 0;
212 int RecordBatchesGUI::
215 if(!BC_ListBox::drag_motion_event()) return 0;
219 int RecordBatchesGUI::
222 int n = get_selection_number(0, 0);
224 set_editing_batch(n);
225 if(get_cursor_x() < batches.column_widths[0]) {
226 Batch *batch = batches[n];
227 batch->enabled = !batch->enabled;
234 int RecordBatchesGUI::
238 int total_batches = batches.total();
239 int src_item = editing_batch();
240 Batch *src_batch = batches[src_item];
241 int dst_item = get_highlighted_item();
242 if(dst_item < 0) dst_item = total_batches;
243 if(dst_item > src_item) --dst_item;
245 for(int i = src_item; i < total_batches - 1; i++)
246 batches[i] = batches[i + 1];
247 for(int i = total_batches - 1; i > dst_item; --i)
248 batches[i] = batches[i - 1];
249 batches[dst_item] = src_batch;
251 BC_ListBox::drag_stop_event();
253 set_editing_batch(dst_item);
254 update_batches(dst_item);
259 void RecordBatchesGUI::
260 update_batch_news(int item)
262 Batch *batch = batches[item];
263 batch->calculate_news();
264 batches.data[2].values[item]->set_text(batch->news);
268 void RecordBatchesGUI::
269 update_batches(int selection_item)
272 char string[BCTEXTLEN], string2[BCTEXTLEN];
274 for(int j = 0; j < BATCH_COLUMNS; j++) {
275 batches.data[j].remove_all_objects();
277 int total_batches = batches.total();
278 for(int i = 0; i < total_batches; i++) {
279 Batch *batch = batches[i];
280 batch->update_times();
281 batch->calculate_news();
284 if( i != batches.current_item ) {
285 if( batch->time_start < t )
287 else if( i > 0 && batches[i-1]->time_end > batch->time_start )
289 else if( batch->time_start - t > 2*24*3600 )
295 batches.data[0].append(
296 new BC_ListBoxItem((char *)(batch->enabled ? "X" : " "), color));
297 batches.data[1].append(
298 new BC_ListBoxItem(batch->asset->path, color));
299 batches.data[2].append(
300 new BC_ListBoxItem(batch->news, RED));
301 Units::totext(string2, batch->start_time, TIME_HMS3);
302 sprintf(string, "%s %s", TimeEntry::day_table[batch->start_day], string2);
303 batches.data[3].append(
304 new BC_ListBoxItem(string, color));
305 Units::totext(string, batch->duration, TIME_HMS3);
306 batches.data[4].append(
307 new BC_ListBoxItem(string, color));
308 sprintf(string, "%s", batch->channel ? batch->channel->title : _("None"));
309 batches.data[5].append(
310 new BC_ListBoxItem(string, color));
311 sprintf(string, "%s", Batch::mode_to_text(batch->record_mode));
312 batches.data[6].append(
313 new BC_ListBoxItem(string, color));
315 if(i == selection_item) {
316 for(int j = 0; j < BATCH_COLUMNS; j++) {
317 batches.data[j].values[i]->set_selected(1);
321 update(batches.editing_item, 1);
325 void RecordBatchesGUI::
326 set_row_color(int row, int color)
328 for(int i = 0; i < BATCH_COLUMNS; i++) {
329 BC_ListBoxItem *batch = batches.data[i].values[row];
330 batch->set_color(color);
335 RecordBatchesGUI::Dir::
336 Dir(RecordBatches &batches, const char *dir, int x, int y)
337 : BC_TextBox(x, y, 200, 1, dir),
339 directory(batches.default_directory)
341 strncpy(directory, dir, sizeof(directory));
342 dir_entries = new ArrayList<BC_ListBoxItem*>;
347 RecordBatchesGUI::Dir::
350 dir_entries->remove_all_objects();
354 int RecordBatchesGUI::Dir::
357 char *path = FileSystem::basepath(directory);
359 calculate_suggestions(dir_entries);
364 void RecordBatchesGUI::Dir::
365 load_dirs(const char *dir)
367 if( !strncmp(dir, entries_dir, sizeof(entries_dir)) ) return;
368 strncpy(entries_dir, dir, sizeof(entries_dir));
369 dir_entries->remove_all_objects();
370 FileSystem fs; fs.update(dir);
371 int total_files = fs.total_files();
372 for(int i = 0; i < total_files; i++) {
373 if( !fs.get_entry(i)->get_is_dir() ) continue;
374 const char *name = fs.get_entry(i)->get_name();
375 dir_entries->append(new BC_ListBoxItem(name));
379 RecordBatchesGUI::Path::
380 Path(RecordBatches &batches, int x, int y)
381 : BC_TextBox(x, y, 200, 1, batches.get_editing_batch()->asset->path),
386 RecordBatchesGUI::Path::
391 int RecordBatchesGUI::Path::
394 calculate_suggestions();
395 Batch *batch = batches.gui->get_editing_batch();
396 strcpy(batch->asset->path, get_text());
397 batches.gui->update_batches();
401 RecordBatchesGUI::StartTime::
402 StartTime(BC_Window *win, RecordBatches &batches, int x, int y, int w)
403 : TimeEntry(win, x, y,
404 &batches.get_editing_batch()->start_day,
405 &batches.get_editing_batch()->start_time, TIME_HMS3, w),
410 int RecordBatchesGUI::StartTime::
413 batches.gui->update_batches();
418 RecordBatchesGUI::Duration::
419 Duration(BC_Window *win, RecordBatches &batches, int x, int y, int w)
420 : TimeEntry(win, x, y, 0,
421 &batches.get_editing_batch()->duration, TIME_HMS2, w),
426 int RecordBatchesGUI::Duration::
429 batches.gui->update_batches();
434 RecordBatchesGUI::Source::
435 Source(BC_Window *win, RecordBatches &batches, int x, int y)
436 : BC_PopupTextBox(win, &sources,
437 batches.get_editing_batch()->get_source_text(),
443 int RecordBatchesGUI::Source::
446 batches.gui->update_batches();
451 RecordBatchesGUI::News::
452 News(RecordBatches &batches, int x, int y)
453 : BC_TextBox(x, y, 200, 1, batches.get_editing_batch()->news),
458 int RecordBatchesGUI::News::
465 RecordBatchesGUI::NewBatch::
466 NewBatch(RecordBatches &batches, int x, int y)
467 : BC_GenericButton(x, y, _("New")),
470 set_tooltip(_("Create new clip."));
473 int RecordBatchesGUI::NewBatch::
476 int new_item = batches.total()-1;
477 batches.editing_item = new_item;
478 batches.gui->update_batches(new_item);
483 RecordBatchesGUI::DeleteBatch::
484 DeleteBatch(RecordBatches &batches, int x, int y)
485 : BC_GenericButton(x, y, _("Delete")),
488 set_tooltip(_("Delete clip."));
491 int RecordBatchesGUI::DeleteBatch::
494 batches.gui->update_batches();
499 RecordBatchesGUI::StartBatches::
500 StartBatches(RecordBatches &batches, int x, int y)
501 : BC_GenericButton(x, y, _("Start")), batches(batches)
503 set_tooltip(_("Start batch recording\nfrom the current position."));
506 int RecordBatchesGUI::StartBatches::
509 batches.batch_active = 1;
514 RecordBatchesGUI::StopBatches::
515 StopBatches(RecordBatches &batches, int x, int y)
516 : BC_GenericButton(x, y, _("Stop")), batches(batches)
520 int RecordBatchesGUI::StopBatches::
523 batches.batch_active = 0;
528 RecordBatchesGUI::ActivateBatch::
529 ActivateBatch(RecordBatches &batches, int x, int y)
530 : BC_GenericButton(x, y, _("Activate")), batches(batches)
532 set_tooltip(_("Make the highlighted\nclip active."));
535 int RecordBatchesGUI::ActivateBatch::
542 RecordBatchesGUI::ClearBatch::
543 ClearBatch(RecordBatches &batches, int x, int y)
544 : BC_GenericButton(x, y, _("Clear")), batches(batches)
546 set_tooltip(_("Delete all clips."));
549 int RecordBatchesGUI::ClearBatch::
552 batches.gui->update_batches();