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 strncpy(directory, get_text(),sizeof(directory));
358 char *bp, *cp, *dp = &directory[0];
360 if( dp[0] != '~' || dp[1] != 0 ) {
361 for( cp=dp; *cp; ++cp ) {
362 if( *cp != '/' ) continue;
363 for( bp=cp; *bp=='/'; ++bp );
366 if( *--cp != '/' ) return 1;
367 while( cp>dp && *cp=='/' ) *cp-- = 0;
369 load_dirs(directory);
370 calculate_suggestions(dir_entries);
375 void RecordBatchesGUI::Dir::
376 load_dirs(const char *dir)
378 if( !strncmp(dir, entries_dir, sizeof(entries_dir)) ) return;
379 strncpy(entries_dir, dir, sizeof(entries_dir));
380 dir_entries->remove_all_objects();
381 FileSystem fs; fs.update(dir);
382 int total_files = fs.total_files();
383 for(int i = 0; i < total_files; i++) {
384 if( !fs.get_entry(i)->get_is_dir() ) continue;
385 const char *name = fs.get_entry(i)->get_name();
386 dir_entries->append(new BC_ListBoxItem(name));
390 RecordBatchesGUI::Path::
391 Path(RecordBatches &batches, int x, int y)
392 : BC_TextBox(x, y, 200, 1, batches.get_editing_batch()->asset->path),
395 file_entries = new ArrayList<BC_ListBoxItem*>;
396 FileSystem fs; char string[BCTEXTLEN];
397 // Load current directory
398 fs.update(getcwd(string, BCTEXTLEN));
399 int total_files = fs.total_files();
400 for(int i = 0; i < total_files; i++) {
401 const char *name = fs.get_entry(i)->get_name();
402 file_entries->append(new BC_ListBoxItem(name));
406 RecordBatchesGUI::Path::
409 file_entries->remove_all_objects();
413 int RecordBatchesGUI::Path::
416 calculate_suggestions(file_entries);
417 Batch *batch = batches.gui->get_editing_batch();
418 strcpy(batch->asset->path, get_text());
419 batches.gui->update_batches();
423 RecordBatchesGUI::StartTime::
424 StartTime(BC_Window *win, RecordBatches &batches, int x, int y, int w)
425 : TimeEntry(win, x, y,
426 &batches.get_editing_batch()->start_day,
427 &batches.get_editing_batch()->start_time, TIME_HMS3, w),
432 int RecordBatchesGUI::StartTime::
435 batches.gui->update_batches();
440 RecordBatchesGUI::Duration::
441 Duration(BC_Window *win, RecordBatches &batches, int x, int y, int w)
442 : TimeEntry(win, x, y, 0,
443 &batches.get_editing_batch()->duration, TIME_HMS2, w),
448 int RecordBatchesGUI::Duration::
451 batches.gui->update_batches();
456 RecordBatchesGUI::Source::
457 Source(BC_Window *win, RecordBatches &batches, int x, int y)
458 : BC_PopupTextBox(win, &sources,
459 batches.get_editing_batch()->get_source_text(),
465 int RecordBatchesGUI::Source::
468 batches.gui->update_batches();
473 RecordBatchesGUI::News::
474 News(RecordBatches &batches, int x, int y)
475 : BC_TextBox(x, y, 200, 1, batches.get_editing_batch()->news),
480 int RecordBatchesGUI::News::
487 RecordBatchesGUI::NewBatch::
488 NewBatch(RecordBatches &batches, int x, int y)
489 : BC_GenericButton(x, y, _("New")),
492 set_tooltip(_("Create new clip."));
495 int RecordBatchesGUI::NewBatch::
498 int new_item = batches.total()-1;
499 batches.editing_item = new_item;
500 batches.gui->update_batches(new_item);
505 RecordBatchesGUI::DeleteBatch::
506 DeleteBatch(RecordBatches &batches, int x, int y)
507 : BC_GenericButton(x, y, _("Delete")),
510 set_tooltip(_("Delete clip."));
513 int RecordBatchesGUI::DeleteBatch::
516 batches.gui->update_batches();
521 RecordBatchesGUI::StartBatches::
522 StartBatches(RecordBatches &batches, int x, int y)
523 : BC_GenericButton(x, y, _("Start")), batches(batches)
525 set_tooltip(_("Start batch recording\nfrom the current position."));
528 int RecordBatchesGUI::StartBatches::
531 batches.batch_active = 1;
536 RecordBatchesGUI::StopBatches::
537 StopBatches(RecordBatches &batches, int x, int y)
538 : BC_GenericButton(x, y, _("Stop")), batches(batches)
542 int RecordBatchesGUI::StopBatches::
545 batches.batch_active = 0;
550 RecordBatchesGUI::ActivateBatch::
551 ActivateBatch(RecordBatches &batches, int x, int y)
552 : BC_GenericButton(x, y, _("Activate")), batches(batches)
554 set_tooltip(_("Make the highlighted\nclip active."));
557 int RecordBatchesGUI::ActivateBatch::
564 RecordBatchesGUI::ClearBatch::
565 ClearBatch(RecordBatches &batches, int x, int y)
566 : BC_GenericButton(x, y, _("Clear")), batches(batches)
568 set_tooltip(_("Delete all clips."));
571 int RecordBatchesGUI::ClearBatch::
574 batches.gui->update_batches();