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, 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, 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(directory);
360 calculate_suggestions(dir_entries);
365 void RecordBatchesGUI::Dir::
366 load_dirs(const char *dir)
368 if( !strncmp(dir, entries_dir, sizeof(entries_dir)) ) return;
369 strncpy(entries_dir, dir, sizeof(entries_dir));
370 dir_entries->remove_all_objects();
371 FileSystem fs; fs.update(dir);
372 int total_files = fs.total_files();
373 for(int i = 0; i < total_files; i++) {
374 if( !fs.get_entry(i)->get_is_dir() ) continue;
375 const char *name = fs.get_entry(i)->get_name();
376 dir_entries->append(new BC_ListBoxItem(name));
380 RecordBatchesGUI::Path::
381 Path(RecordBatches &batches, int x, int y)
382 : BC_TextBox(x, y, 200, 1, batches.get_editing_batch()->asset->path),
387 RecordBatchesGUI::Path::
392 int RecordBatchesGUI::Path::
395 calculate_suggestions();
396 Batch *batch = batches.gui->get_editing_batch();
397 strcpy(batch->asset->path, get_text());
398 batches.gui->update_batches();
402 RecordBatchesGUI::StartTime::
403 StartTime(BC_Window *win, RecordBatches &batches, int x, int y, int w)
404 : TimeEntry(win, x, y,
405 &batches.get_editing_batch()->start_day,
406 &batches.get_editing_batch()->start_time, TIME_HMS3, w),
411 int RecordBatchesGUI::StartTime::
414 batches.gui->update_batches();
419 RecordBatchesGUI::Duration::
420 Duration(BC_Window *win, RecordBatches &batches, int x, int y, int w)
421 : TimeEntry(win, x, y, 0,
422 &batches.get_editing_batch()->duration, TIME_HMS2, w),
427 int RecordBatchesGUI::Duration::
430 batches.gui->update_batches();
435 RecordBatchesGUI::Source::
436 Source(BC_Window *win, RecordBatches &batches, int x, int y)
437 : BC_PopupTextBox(win, &sources,
438 batches.get_editing_batch()->get_source_text(),
444 int RecordBatchesGUI::Source::
447 batches.gui->update_batches();
452 RecordBatchesGUI::News::
453 News(RecordBatches &batches, int x, int y)
454 : BC_TextBox(x, y, 200, 1, batches.get_editing_batch()->news),
459 int RecordBatchesGUI::News::
466 RecordBatchesGUI::NewBatch::
467 NewBatch(RecordBatches &batches, int x, int y)
468 : BC_GenericButton(x, y, _("New")),
471 set_tooltip(_("Create new clip."));
474 int RecordBatchesGUI::NewBatch::
477 int new_item = batches.total()-1;
478 batches.editing_item = new_item;
479 batches.gui->update_batches(new_item);
484 RecordBatchesGUI::DeleteBatch::
485 DeleteBatch(RecordBatches &batches, int x, int y)
486 : BC_GenericButton(x, y, _("Delete")),
489 set_tooltip(_("Delete clip."));
492 int RecordBatchesGUI::DeleteBatch::
495 batches.gui->update_batches();
500 RecordBatchesGUI::StartBatches::
501 StartBatches(RecordBatches &batches, int x, int y)
502 : BC_GenericButton(x, y, _("Start")), batches(batches)
504 set_tooltip(_("Start batch recording\nfrom the current position."));
507 int RecordBatchesGUI::StartBatches::
510 batches.batch_active = 1;
515 RecordBatchesGUI::StopBatches::
516 StopBatches(RecordBatches &batches, int x, int y)
517 : BC_GenericButton(x, y, _("Stop")), batches(batches)
521 int RecordBatchesGUI::StopBatches::
524 batches.batch_active = 0;
529 RecordBatchesGUI::ActivateBatch::
530 ActivateBatch(RecordBatches &batches, int x, int y)
531 : BC_GenericButton(x, y, _("Activate")), batches(batches)
533 set_tooltip(_("Make the highlighted\nclip active."));
536 int RecordBatchesGUI::ActivateBatch::
543 RecordBatchesGUI::ClearBatch::
544 ClearBatch(RecordBatches &batches, int x, int y)
545 : BC_GenericButton(x, y, _("Clear")), batches(batches)
547 set_tooltip(_("Delete all clips."));
550 int RecordBatchesGUI::ClearBatch::
553 batches.gui->update_batches();