11 #include "bclistbox.h"
13 #include "channeldb.h"
14 #include "filesystem.h"
17 #include "recordbatches.h"
18 #include "timeentry.h"
20 const char * RecordBatches::
21 default_batch_titles[] = {
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 batch_titles[i] = _(default_batch_titles[i]);
41 sprintf(string, "BATCH_COLUMNWIDTH_%d", i);
42 column_widths[i] = defaults->get(string, xS(default_columnwidth[i]));
44 int total_batches = defaults->get("TOTAL_BATCHES", 1);
45 if(total_batches < 1) total_batches = 1;
46 for(int i = 0; i < total_batches; ++i) {
47 Batch *batch = new Batch(mwindow, record);
48 batch->create_objects();
49 batches.append(batch);
50 Asset *asset = batch->asset;
51 sprintf(string, "RECORD_PATH_%d", i);
52 defaults->get(string, asset->path);
53 sprintf(string, "RECORD_CHANNEL_%d", i);
54 int chan_no = channeldb->number_of(batch->channel);
55 chan_no = defaults->get(string, chan_no);
56 batch->channel = channeldb->get(chan_no);
57 sprintf(string, "RECORD_STARTDAY_%d", i);
58 batch->start_day = defaults->get(string, batch->start_day);
59 sprintf(string, "RECORD_STARTTIME_%d", i);
60 batch->start_time = defaults->get(string, batch->start_time);
61 sprintf(string, "RECORD_DURATION_%d", i);
62 batch->duration = defaults->get(string, batch->duration);
63 sprintf(string, "RECORD_MODE_%d", i);
64 batch->record_mode = defaults->get(string, batch->record_mode);
65 sprintf(string, "BATCH_ENABLED_%d", i);
66 batch->enabled = defaults->get(string, batch->enabled);
67 batch->update_times();
70 current_item = editing_item = 0;
74 save_defaults(ChannelDB * channeldb)
76 char string[BCTEXTLEN];
77 BC_Hash *defaults = mwindow->defaults;
78 defaults->update("RECORD_DEFAULT_DIRECTORY", default_directory);
79 defaults->update("RECORD_EARLY_MARGIN", early_margin);
80 defaults->update("RECORD_LATE_MARGIN", late_margin);
81 for(int i = 0; i < BATCH_COLUMNS; i++) {
82 sprintf(string, "BATCH_COLUMNWIDTH_%d", i);
83 defaults->update(string, column_widths[i]);
86 defaults->update("TOTAL_BATCHES", batches.total);
87 for(int i = 0; i < batches.total; ++i) {
88 Batch *batch = batches.values[i];
89 Asset *asset = batch->asset;
90 sprintf(string, "RECORD_PATH_%d", i);
91 defaults->update(string, asset->path);
92 sprintf(string, "RECORD_CHANNEL_%d", i);
93 int chan_no = channeldb->number_of(batch->channel);
94 defaults->update(string, chan_no);
95 sprintf(string, "RECORD_STARTDAY_%d", i);
96 defaults->update(string, batch->start_day);
97 sprintf(string, "RECORD_STARTTIME_%d", i);
98 defaults->update(string, batch->start_time);
99 sprintf(string, "RECORD_DURATION_%d", i);
100 defaults->update(string, batch->duration);
101 sprintf(string, "RECORD_MODE_%d", i);
102 defaults->update(string, batch->record_mode);
103 sprintf(string, "BATCH_ENABLED_%d", i);
104 defaults->update(string, batch->enabled);
109 save_default_channel(ChannelDB * channeldb)
111 BC_Hash *defaults = mwindow->defaults;
112 Batch *batch = get_editing_batch();
114 int chan_no = channeldb->number_of(batch->channel);
115 if( chan_no < 0 ) return;
116 defaults->update("RECORD_CURRENT_CHANNEL", chan_no);
120 RecordBatches(MWindow * mwindow)
122 this->mwindow = mwindow;
123 editing_item = current_item = -1;
125 early_margin = late_margin = 0.;
126 default_directory[0] = 0;
137 batches.remove(batch);
138 int total_batches = total();
139 if( current_item == editing_item ) {
140 if(current_item >= total_batches)
141 current_item = total_batches - 1;
142 editing_item = current_item;
145 if(current_item > editing_item)
147 if( editing_item >= total_batches )
148 editing_item = total_batches - 1;
155 batches.remove_all_objects();
156 for(int j = 0; j < BATCH_COLUMNS; j++) {
157 data[j].remove_all_objects();
159 current_item = editing_item = -1;
163 RecordBatchesGUI(RecordBatches &batches,
164 int x, int y, int w, int h)
165 : BC_ListBox(x, y, w, h, LISTBOX_TEXT, // Display text list or icons
166 batches.data, // Each column has an ArrayList of BC_ListBoxItems.
167 batches.batch_titles, // Titles for columns. Set to 0 for no titles
168 batches.column_widths, // width of each column
169 BATCH_COLUMNS, // Total columns.
170 0, // Pixel of top of window.
171 0, // If this listbox is a popup window
172 LISTBOX_SINGLE, // Select one item or multiple items
173 ICON_LEFT, // Position of icon relative to text of each item
174 1), // Allow dragging
180 // Do nothing for double clicks to protect active batch
181 int RecordBatchesGUI::
187 int RecordBatchesGUI::
188 update(int highlighted_item, int recalc_positions)
190 return BC_ListBox::update(batches.data, batches.batch_titles,
191 batches.column_widths, BATCH_COLUMNS,
192 get_xposition(), get_yposition(),
193 highlighted_item, recalc_positions);
196 int RecordBatchesGUI::
197 column_resize_event()
199 for(int i = 0; i < BATCH_COLUMNS; i++) {
200 batches.column_widths[i] = get_column_width(i);
205 int RecordBatchesGUI::
208 if(!BC_ListBox::drag_start_event()) return 0;
213 int RecordBatchesGUI::
216 if(!BC_ListBox::drag_motion_event()) return 0;
220 int RecordBatchesGUI::
223 int n = get_selection_number(0, 0);
225 set_editing_batch(n);
226 if(get_cursor_x() < batches.column_widths[0]) {
227 Batch *batch = batches[n];
228 batch->enabled = !batch->enabled;
235 int RecordBatchesGUI::
239 int total_batches = batches.total();
240 int src_item = editing_batch();
241 Batch *src_batch = batches[src_item];
242 int dst_item = get_highlighted_item();
243 if(dst_item < 0) dst_item = total_batches;
244 if(dst_item > src_item) --dst_item;
246 for(int i = src_item; i < total_batches - 1; i++)
247 batches[i] = batches[i + 1];
248 for(int i = total_batches - 1; i > dst_item; --i)
249 batches[i] = batches[i - 1];
250 batches[dst_item] = src_batch;
252 BC_ListBox::drag_stop_event();
254 set_editing_batch(dst_item);
255 update_batches(dst_item);
260 void RecordBatchesGUI::
261 update_batch_news(int item)
263 Batch *batch = batches[item];
264 batch->calculate_news();
265 batches.data[2].values[item]->set_text(batch->news);
269 void RecordBatchesGUI::
270 update_batches(int selection_item)
273 char string[BCTEXTLEN], string2[BCTEXTLEN];
275 for(int j = 0; j < BATCH_COLUMNS; j++) {
276 batches.data[j].remove_all_objects();
278 int total_batches = batches.total();
279 for(int i = 0; i < total_batches; i++) {
280 Batch *batch = batches[i];
281 batch->update_times();
282 batch->calculate_news();
285 if( i != batches.current_item ) {
286 if( batch->time_start < t )
288 else if( i > 0 && batches[i-1]->time_end > batch->time_start )
290 else if( batch->time_start - t > 2*24*3600 )
296 batches.data[0].append(
297 new BC_ListBoxItem((char *)(batch->enabled ? "X" : " "), color));
298 batches.data[1].append(
299 new BC_ListBoxItem(batch->asset->path, color));
300 batches.data[2].append(
301 new BC_ListBoxItem(batch->news, RED));
302 Units::totext(string2, batch->start_time, TIME_HMS3);
303 sprintf(string, "%s %s", TimeEntry::day_table[batch->start_day], string2);
304 batches.data[3].append(
305 new BC_ListBoxItem(string, color));
306 Units::totext(string, batch->duration, TIME_HMS3);
307 batches.data[4].append(
308 new BC_ListBoxItem(string, color));
309 sprintf(string, "%s", batch->channel ? batch->channel->title : _("None"));
310 batches.data[5].append(
311 new BC_ListBoxItem(string, color));
312 sprintf(string, "%s", Batch::mode_to_text(batch->record_mode));
313 batches.data[6].append(
314 new BC_ListBoxItem(string, color));
316 if(i == selection_item) {
317 for(int j = 0; j < BATCH_COLUMNS; j++) {
318 batches.data[j].values[i]->set_selected(1);
322 update(batches.editing_item, 1);
326 void RecordBatchesGUI::
327 set_row_color(int row, int color)
329 for(int i = 0; i < BATCH_COLUMNS; i++) {
330 BC_ListBoxItem *batch = batches.data[i].values[row];
331 batch->set_color(color);
336 RecordBatchesGUI::Dir::
337 Dir(RecordBatches &batches, const char *dir, int x, int y)
338 : BC_TextBox(x, y, xS(200), 1, dir),
340 directory(batches.default_directory)
342 strncpy(directory, dir, sizeof(directory));
343 dir_entries = new ArrayList<BC_ListBoxItem*>;
348 RecordBatchesGUI::Dir::
351 dir_entries->remove_all_objects();
355 int RecordBatchesGUI::Dir::
358 char *path = FileSystem::basepath(get_text());
359 strcpy(directory, path);
361 calculate_suggestions(dir_entries);
366 void RecordBatchesGUI::Dir::
367 load_dirs(const char *dir)
369 if( !strncmp(dir, entries_dir, sizeof(entries_dir)) ) return;
370 strncpy(entries_dir, dir, sizeof(entries_dir));
371 dir_entries->remove_all_objects();
372 FileSystem fs; fs.update(dir);
373 int total_files = fs.total_files();
374 for(int i = 0; i < total_files; i++) {
375 if( !fs.get_entry(i)->get_is_dir() ) continue;
376 const char *name = fs.get_entry(i)->get_name();
377 dir_entries->append(new BC_ListBoxItem(name));
381 RecordBatchesGUI::Path::
382 Path(RecordBatches &batches, int x, int y)
383 : BC_TextBox(x, y, xS(200), 1, batches.get_editing_batch()->asset->path),
388 RecordBatchesGUI::Path::
393 int RecordBatchesGUI::Path::
396 calculate_suggestions();
397 Batch *batch = batches.gui->get_editing_batch();
398 strcpy(batch->asset->path, get_text());
399 batches.gui->update_batches();
403 RecordBatchesGUI::StartTime::
404 StartTime(BC_Window *win, RecordBatches &batches, int x, int y, int w)
405 : TimeEntry(win, x, y,
406 &batches.get_editing_batch()->start_day,
407 &batches.get_editing_batch()->start_time, TIME_HMS3, w),
412 int RecordBatchesGUI::StartTime::
415 batches.gui->update_batches();
420 RecordBatchesGUI::Duration::
421 Duration(BC_Window *win, RecordBatches &batches, int x, int y, int w)
422 : TimeEntry(win, x, y, 0,
423 &batches.get_editing_batch()->duration, TIME_HMS2, w),
428 int RecordBatchesGUI::Duration::
431 batches.gui->update_batches();
436 RecordBatchesGUI::Source::
437 Source(BC_Window *win, RecordBatches &batches, int x, int y)
438 : BC_PopupTextBox(win, &sources,
439 batches.get_editing_batch()->get_source_text(),
440 x, y, xS(200), yS(200)),
445 int RecordBatchesGUI::Source::
448 batches.gui->update_batches();
453 RecordBatchesGUI::News::
454 News(RecordBatches &batches, int x, int y)
455 : BC_TextBox(x, y, xS(200), 1, batches.get_editing_batch()->news),
460 int RecordBatchesGUI::News::
467 RecordBatchesGUI::NewBatch::
468 NewBatch(RecordBatches &batches, int x, int y)
469 : BC_GenericButton(x, y, _("New")),
472 set_tooltip(_("Create new clip."));
475 int RecordBatchesGUI::NewBatch::
478 int new_item = batches.total()-1;
479 batches.editing_item = new_item;
480 batches.gui->update_batches(new_item);
485 RecordBatchesGUI::DeleteBatch::
486 DeleteBatch(RecordBatches &batches, int x, int y)
487 : BC_GenericButton(x, y, _("Delete")),
490 set_tooltip(_("Delete clip."));
493 int RecordBatchesGUI::DeleteBatch::
496 batches.gui->update_batches();
501 RecordBatchesGUI::StartBatches::
502 StartBatches(RecordBatches &batches, int x, int y)
503 : BC_GenericButton(x, y, _("Start")), batches(batches)
505 set_tooltip(_("Start batch recording\nfrom the current position."));
508 int RecordBatchesGUI::StartBatches::
511 batches.batch_active = 1;
516 RecordBatchesGUI::StopBatches::
517 StopBatches(RecordBatches &batches, int x, int y)
518 : BC_GenericButton(x, y, _("Stop")), batches(batches)
522 int RecordBatchesGUI::StopBatches::
525 batches.batch_active = 0;
530 RecordBatchesGUI::ActivateBatch::
531 ActivateBatch(RecordBatches &batches, int x, int y)
532 : BC_GenericButton(x, y, _("Activate")), batches(batches)
534 set_tooltip(_("Make the highlighted\nclip active."));
537 int RecordBatchesGUI::ActivateBatch::
544 RecordBatchesGUI::ClearBatch::
545 ClearBatch(RecordBatches &batches, int x, int y)
546 : BC_GenericButton(x, y, _("Clear")), batches(batches)
548 set_tooltip(_("Delete all clips."));
551 int RecordBatchesGUI::ClearBatch::
554 batches.gui->update_batches();