1 #include "mainwindow.h"
4 #include "disk_space_estimator.h"
6 #include "post_to_main_thread.h"
8 #include "ui_mainwindow.h"
10 #include <QMouseEvent>
13 #include <QWheelEvent>
20 using namespace std::placeholders;
22 MainWindow *global_mainwindow = nullptr;
23 static ClipList *cliplist_clips;
24 static PlayList *playlist_clips;
26 extern int64_t current_pts;
27 extern mutex frame_mu;
28 extern vector<int64_t> frames[MAX_STREAMS];
30 MainWindow::MainWindow()
31 : ui(new Ui::MainWindow),
34 global_mainwindow = this;
38 connect(ui->exit_action, &QAction::triggered, this, &MainWindow::exit_triggered);
40 global_disk_space_estimator = new DiskSpaceEstimator(bind(&MainWindow::report_disk_space, this, _1, _2));
41 disk_free_label = new QLabel(this);
42 disk_free_label->setStyleSheet("QLabel {padding-right: 5px;}");
43 ui->menuBar->setCornerWidget(disk_free_label);
45 StateProto state = db.get_state();
47 cliplist_clips = new ClipList(state.clip_list());
48 ui->clip_list->setModel(cliplist_clips);
49 connect(cliplist_clips, &ClipList::any_content_changed, this, &MainWindow::content_changed);
51 playlist_clips = new PlayList(state.play_list());
52 ui->playlist->setModel(playlist_clips);
53 connect(playlist_clips, &PlayList::any_content_changed, this, &MainWindow::content_changed);
55 // For un-highlighting when we lose focus.
56 ui->clip_list->installEventFilter(this);
58 // For scrubbing in the pts columns.
59 ui->clip_list->viewport()->installEventFilter(this);
60 ui->playlist->viewport()->installEventFilter(this);
62 QShortcut *cue_in = new QShortcut(QKeySequence(Qt::Key_A), this);
63 connect(cue_in, &QShortcut::activated, ui->cue_in_btn, &QPushButton::click);
64 connect(ui->cue_in_btn, &QPushButton::clicked, this, &MainWindow::cue_in_clicked);
66 QShortcut *cue_out = new QShortcut(QKeySequence(Qt::Key_S), this);
67 connect(cue_out, &QShortcut::activated, ui->cue_out_btn, &QPushButton::click);
68 connect(ui->cue_out_btn, &QPushButton::clicked, this, &MainWindow::cue_out_clicked);
70 QShortcut *queue = new QShortcut(QKeySequence(Qt::Key_Q), this);
71 connect(queue, &QShortcut::activated, ui->queue_btn, &QPushButton::click);
72 connect(ui->queue_btn, &QPushButton::clicked, this, &MainWindow::queue_clicked);
74 QShortcut *preview = new QShortcut(QKeySequence(Qt::Key_W), this);
75 connect(preview, &QShortcut::activated, ui->preview_btn, &QPushButton::click);
76 connect(ui->preview_btn, &QPushButton::clicked, this, &MainWindow::preview_clicked);
78 QShortcut *play = new QShortcut(QKeySequence(Qt::Key_Space), this);
79 connect(play, &QShortcut::activated, ui->play_btn, &QPushButton::click);
80 connect(ui->play_btn, &QPushButton::clicked, this, &MainWindow::play_clicked);
82 QShortcut *preview_1 = new QShortcut(QKeySequence(Qt::Key_1), this);
83 connect(preview_1, &QShortcut::activated, ui->preview_1_btn, &QPushButton::click);
84 connect(ui->input1_display, &JPEGFrameView::clicked, ui->preview_1_btn, &QPushButton::click);
85 connect(ui->preview_1_btn, &QPushButton::clicked, [this]{ preview_angle_clicked(0); });
86 ui->input1_display->set_overlay("1");
88 QShortcut *preview_2 = new QShortcut(QKeySequence(Qt::Key_2), this);
89 connect(preview_2, &QShortcut::activated, ui->preview_2_btn, &QPushButton::click);
90 connect(ui->input2_display, &JPEGFrameView::clicked, ui->preview_2_btn, &QPushButton::click);
91 connect(ui->preview_2_btn, &QPushButton::clicked, [this]{ preview_angle_clicked(1); });
92 ui->input2_display->set_overlay("2");
94 QShortcut *preview_3 = new QShortcut(QKeySequence(Qt::Key_3), this);
95 connect(preview_3, &QShortcut::activated, ui->preview_3_btn, &QPushButton::click);
96 connect(ui->input3_display, &JPEGFrameView::clicked, ui->preview_3_btn, &QPushButton::click);
97 connect(ui->preview_3_btn, &QPushButton::clicked, [this]{ preview_angle_clicked(2); });
98 ui->input3_display->set_overlay("3");
100 QShortcut *preview_4 = new QShortcut(QKeySequence(Qt::Key_4), this);
101 connect(preview_4, &QShortcut::activated, ui->preview_4_btn, &QPushButton::click);
102 connect(ui->input4_display, &JPEGFrameView::clicked, ui->preview_4_btn, &QPushButton::click);
103 connect(ui->preview_4_btn, &QPushButton::clicked, [this]{ preview_angle_clicked(3); });
104 ui->input4_display->set_overlay("4");
106 connect(ui->playlist_duplicate_btn, &QPushButton::clicked, this, &MainWindow::playlist_duplicate);
108 connect(ui->playlist_remove_btn, &QPushButton::clicked, this, &MainWindow::playlist_remove);
109 QShortcut *delete_key = new QShortcut(QKeySequence(Qt::Key_Delete), ui->playlist);
110 connect(delete_key, &QShortcut::activated, [this] {
111 if (ui->playlist->hasFocus()) {
116 // TODO: support drag-and-drop.
117 connect(ui->playlist_move_up_btn, &QPushButton::clicked, [this]{ playlist_move(-1); });
118 connect(ui->playlist_move_down_btn, &QPushButton::clicked, [this]{ playlist_move(1); });
120 connect(ui->playlist->selectionModel(), &QItemSelectionModel::selectionChanged,
121 this, &MainWindow::playlist_selection_changed);
122 playlist_selection_changed(); // First time set-up.
124 preview_player = new Player(ui->preview_display, /*also_output_to_stream=*/false);
125 live_player = new Player(ui->live_display, /*also_output_to_stream=*/true);
126 live_player->set_done_callback([this]{
127 post_to_main_thread([this]{
128 live_player_clip_done();
131 live_player->set_next_clip_callback(bind(&MainWindow::live_player_get_next_clip, this));
132 live_player->set_progress_callback([this](double played_this_clip, double total_length) {
133 post_to_main_thread([this, played_this_clip, total_length] {
134 live_player_clip_progress(played_this_clip, total_length);
138 defer_timeout = new QTimer(this);
139 defer_timeout->setSingleShot(true);
140 connect(defer_timeout, &QTimer::timeout, this, &MainWindow::defer_timer_expired);
142 connect(ui->clip_list->selectionModel(), &QItemSelectionModel::currentChanged,
143 this, &MainWindow::clip_list_selection_changed);
146 void MainWindow::cue_in_clicked()
148 if (!cliplist_clips->empty() && cliplist_clips->back()->pts_out < 0) {
149 cliplist_clips->mutable_back()->pts_in = current_pts;
153 clip.pts_in = current_pts;
154 cliplist_clips->add_clip(clip);
155 playlist_selection_changed();
158 void MainWindow::cue_out_clicked()
160 if (!cliplist_clips->empty()) {
161 cliplist_clips->mutable_back()->pts_out = current_pts;
162 // TODO: select the row in the clip list?
166 void MainWindow::queue_clicked()
168 if (cliplist_clips->empty()) {
172 QItemSelectionModel *selected = ui->clip_list->selectionModel();
173 if (!selected->hasSelection()) {
174 Clip clip = *cliplist_clips->back();
176 if (clip.pts_out != -1) {
177 playlist_clips->add_clip(clip);
178 playlist_selection_changed();
183 QModelIndex index = selected->currentIndex();
184 Clip clip = *cliplist_clips->clip(index.row());
185 if (index.column() >= int(ClipList::Column::CAMERA_1) &&
186 index.column() <= int(ClipList::Column::CAMERA_4)) {
187 clip.stream_idx = index.column() - int(ClipList::Column::CAMERA_1);
189 clip.stream_idx = ui->preview_display->get_stream_idx();
192 if (clip.pts_out != -1) {
193 playlist_clips->add_clip(clip);
194 playlist_selection_changed();
198 void MainWindow::preview_clicked()
200 if (cliplist_clips->empty())
203 QItemSelectionModel *selected = ui->clip_list->selectionModel();
204 if (!selected->hasSelection()) {
205 preview_player->play_clip(*cliplist_clips->back(), 0);
209 QModelIndex index = selected->currentIndex();
211 if (index.column() >= int(ClipList::Column::CAMERA_1) &&
212 index.column() <= int(ClipList::Column::CAMERA_4)) {
213 stream_idx = index.column() - int(ClipList::Column::CAMERA_1);
215 stream_idx = ui->preview_display->get_stream_idx();
217 preview_player->play_clip(*cliplist_clips->clip(index.row()), stream_idx);
220 void MainWindow::preview_angle_clicked(unsigned stream_idx)
222 preview_player->override_angle(stream_idx);
224 // Change the selection if we were previewing a clip from the clip list.
225 // (The only other thing we could be showing is a pts scrub, and if so,
226 // that would be selected.)
227 QItemSelectionModel *selected = ui->clip_list->selectionModel();
228 if (selected->hasSelection()) {
229 QModelIndex cell = selected->selectedIndexes()[0];
230 int column = int(ClipList::Column::CAMERA_1) + stream_idx;
231 selected->setCurrentIndex(cell.sibling(cell.row(), column), QItemSelectionModel::ClearAndSelect);
235 void MainWindow::playlist_duplicate()
237 QItemSelectionModel *selected = ui->playlist->selectionModel();
238 if (!selected->hasSelection()) {
239 // Should have been grayed out, but OK.
242 QModelIndexList rows = selected->selectedRows();
243 int first = rows.front().row(), last = rows.back().row();
244 playlist_clips->duplicate_clips(first, last);
245 playlist_selection_changed();
248 void MainWindow::playlist_remove()
250 QItemSelectionModel *selected = ui->playlist->selectionModel();
251 if (!selected->hasSelection()) {
252 // Should have been grayed out, but OK.
255 QModelIndexList rows = selected->selectedRows();
256 int first = rows.front().row(), last = rows.back().row();
257 playlist_clips->erase_clips(first, last);
259 // TODO: select the next one in the list?
261 playlist_selection_changed();
264 void MainWindow::playlist_move(int delta)
266 QItemSelectionModel *selected = ui->playlist->selectionModel();
267 if (!selected->hasSelection()) {
268 // Should have been grayed out, but OK.
272 QModelIndexList rows = selected->selectedRows();
273 int first = rows.front().row(), last = rows.back().row();
274 if ((delta == -1 && first == 0) ||
275 (delta == 1 && size_t(last) == playlist_clips->size() - 1)) {
276 // Should have been grayed out, but OK.
280 playlist_clips->move_clips(first, last, delta);
281 playlist_selection_changed();
284 void MainWindow::defer_timer_expired()
286 state_changed(deferred_state);
289 void MainWindow::content_changed()
291 if (defer_timeout->isActive() &&
292 (!currently_deferring_model_changes || deferred_change_id != current_change_id)) {
293 // There's some deferred event waiting, but this event is unrelated.
294 // So it's time to short-circuit that timer and do the work it wanted to do.
295 defer_timeout->stop();
296 state_changed(deferred_state);
299 *state.mutable_clip_list() = cliplist_clips->serialize();
300 *state.mutable_play_list() = playlist_clips->serialize();
301 if (currently_deferring_model_changes) {
302 deferred_change_id = current_change_id;
303 deferred_state = std::move(state);
304 defer_timeout->start(200);
307 state_changed(state);
310 void MainWindow::state_changed(const StateProto &state)
312 db.store_state(state);
315 void MainWindow::play_clicked()
317 if (playlist_clips->empty())
320 QItemSelectionModel *selected = ui->playlist->selectionModel();
322 if (!selected->hasSelection()) {
325 row = selected->selectedRows(0)[0].row();
328 const Clip &clip = *playlist_clips->clip(row);
329 live_player->play_clip(clip, clip.stream_idx);
330 playlist_clips->set_currently_playing(row, 0.0f);
331 playlist_selection_changed();
334 void MainWindow::live_player_clip_done()
336 int row = playlist_clips->get_currently_playing();
337 if (row == -1 || row == int(playlist_clips->size()) - 1) {
338 ui->live_label->setText("Current output (paused)");
339 playlist_clips->set_currently_playing(-1, 0.0f);
341 playlist_clips->set_currently_playing(row + 1, 0.0f);
345 Clip MainWindow::live_player_get_next_clip()
347 // playlist_clips can only be accessed on the main thread.
348 // Hopefully, we won't have to wait too long for this to come back.
349 promise<Clip> clip_promise;
350 future<Clip> clip = clip_promise.get_future();
351 post_to_main_thread([this, &clip_promise] {
352 int row = playlist_clips->get_currently_playing();
353 if (row != -1 && row < int(playlist_clips->size()) - 1) {
354 clip_promise.set_value(*playlist_clips->clip(row + 1));
356 clip_promise.set_value(Clip());
362 void MainWindow::live_player_clip_progress(double played_this_clip, double total_length)
364 playlist_clips->set_currently_playing(playlist_clips->get_currently_playing(), played_this_clip / total_length);
366 double remaining = total_length - played_this_clip;
367 for (int row = playlist_clips->get_currently_playing() + 1; row < int(playlist_clips->size()); ++row) {
368 const Clip clip = *playlist_clips->clip(row);
369 remaining += double(clip.pts_out - clip.pts_in) / TIMEBASE / 0.5; // FIXME: stop hardcoding speed.
371 int remaining_ms = lrint(remaining * 1e3);
373 int ms = remaining_ms % 1000;
374 remaining_ms /= 1000;
375 int s = remaining_ms % 60;
377 int m = remaining_ms;
380 snprintf(buf, sizeof(buf), "Current output (%d:%02d.%03d left)", m, s, ms);
381 ui->live_label->setText(buf);
384 void MainWindow::resizeEvent(QResizeEvent *event)
386 QMainWindow::resizeEvent(event);
388 // Ask for a relayout, but only after the event loop is done doing relayout
389 // on everything else.
390 QMetaObject::invokeMethod(this, "relayout", Qt::QueuedConnection);
393 void MainWindow::relayout()
395 ui->live_display->setMinimumWidth(ui->live_display->height() * 16 / 9);
396 ui->preview_display->setMinimumWidth(ui->preview_display->height() * 16 / 9);
399 void set_pts_in(int64_t pts, int64_t current_pts, ClipProxy &clip)
401 pts = std::max<int64_t>(pts, 0);
402 if (clip->pts_out == -1) {
403 pts = std::min(pts, current_pts);
405 pts = std::min(pts, clip->pts_out);
410 bool MainWindow::eventFilter(QObject *watched, QEvent *event)
412 constexpr int dead_zone_pixels = 3; // To avoid that simple clicks get misinterpreted.
413 constexpr int scrub_sensitivity = 100; // pts units per pixel.
414 constexpr int wheel_sensitivity = 100; // pts units per degree.
415 constexpr int camera_degrees_per_pixel = 15; // One click of most mice.
417 unsigned stream_idx = ui->preview_display->get_stream_idx();
419 if (watched == ui->clip_list) {
420 if (event->type() == QEvent::FocusOut) {
421 highlight_camera_input(-1);
426 if (event->type() != QEvent::Wheel) {
427 last_mousewheel_camera_row = -1;
430 if (event->type() == QEvent::MouseButtonPress) {
431 QMouseEvent *mouse = (QMouseEvent *)event;
433 QTableView *destination;
436 if (watched == ui->clip_list->viewport()) {
437 destination = ui->clip_list;
438 type = SCRUBBING_CLIP_LIST;
439 } else if (watched == ui->playlist->viewport()) {
440 destination = ui->playlist;
441 type = SCRUBBING_PLAYLIST;
445 int column = destination->columnAt(mouse->x());
446 int row = destination->rowAt(mouse->y());
447 if (column == -1 || row == -1)
450 if (type == SCRUBBING_CLIP_LIST) {
451 if (ClipList::Column(column) == ClipList::Column::IN) {
452 scrub_pts_origin = cliplist_clips->clip(row)->pts_in;
453 preview_single_frame(scrub_pts_origin, stream_idx, FIRST_AT_OR_AFTER);
454 } else if (ClipList::Column(column) == ClipList::Column::OUT) {
455 scrub_pts_origin = cliplist_clips->clip(row)->pts_out;
456 preview_single_frame(scrub_pts_origin, stream_idx, LAST_BEFORE);
461 if (PlayList::Column(column) == PlayList::Column::IN) {
462 scrub_pts_origin = playlist_clips->clip(row)->pts_in;
463 preview_single_frame(scrub_pts_origin, stream_idx, FIRST_AT_OR_AFTER);
464 } else if (PlayList::Column(column) == PlayList::Column::OUT) {
465 scrub_pts_origin = playlist_clips->clip(row)->pts_out;
466 preview_single_frame(scrub_pts_origin, stream_idx, LAST_BEFORE);
474 scrub_column = column;
475 scrub_x_origin = mouse->x();
477 } else if (event->type() == QEvent::MouseMove) {
479 QMouseEvent *mouse = (QMouseEvent *)event;
480 int offset = mouse->x() - scrub_x_origin;
482 if (offset >= dead_zone_pixels) {
483 adjusted_offset = offset - dead_zone_pixels;
484 } else if (offset < -dead_zone_pixels) {
485 adjusted_offset = offset + dead_zone_pixels;
490 int64_t pts = scrub_pts_origin + adjusted_offset * scrub_sensitivity;
491 currently_deferring_model_changes = true;
492 if (scrub_type == SCRUBBING_CLIP_LIST) {
493 ClipProxy clip = cliplist_clips->mutable_clip(scrub_row);
494 if (scrub_column == int(ClipList::Column::IN)) {
495 current_change_id = "cliplist:in:" + to_string(scrub_row);
496 set_pts_in(pts, current_pts, clip);
497 preview_single_frame(pts, stream_idx, FIRST_AT_OR_AFTER);
499 current_change_id = "cliplist:out" + to_string(scrub_row);
500 pts = std::max(pts, clip->pts_in);
501 pts = std::min(pts, current_pts);
503 preview_single_frame(pts, stream_idx, LAST_BEFORE);
506 ClipProxy clip = playlist_clips->mutable_clip(scrub_row);
507 if (scrub_column == int(PlayList::Column::IN)) {
508 current_change_id = "playlist:in:" + to_string(scrub_row);
509 set_pts_in(pts, current_pts, clip);
510 preview_single_frame(pts, clip->stream_idx, FIRST_AT_OR_AFTER);
512 current_change_id = "playlist:out:" + to_string(scrub_row);
513 pts = std::max(pts, clip->pts_in);
514 pts = std::min(pts, current_pts);
516 preview_single_frame(pts, clip->stream_idx, LAST_BEFORE);
519 currently_deferring_model_changes = false;
521 return true; // Don't use this mouse movement for selecting things.
523 } else if (event->type() == QEvent::Wheel) {
524 QWheelEvent *wheel = (QWheelEvent *)event;
526 QTableView *destination;
527 int in_column, out_column, camera_column;
528 if (watched == ui->clip_list->viewport()) {
529 destination = ui->clip_list;
530 in_column = int(ClipList::Column::IN);
531 out_column = int(ClipList::Column::OUT);
533 last_mousewheel_camera_row = -1;
534 } else if (watched == ui->playlist->viewport()) {
535 destination = ui->playlist;
536 in_column = int(PlayList::Column::IN);
537 out_column = int(PlayList::Column::OUT);
538 camera_column = int(PlayList::Column::CAMERA);
540 last_mousewheel_camera_row = -1;
543 int column = destination->columnAt(wheel->x());
544 int row = destination->rowAt(wheel->y());
545 if (column == -1 || row == -1) return false;
547 currently_deferring_model_changes = true;
549 current_change_id = (watched == ui->clip_list->viewport()) ? "cliplist:" : "playlist:";
550 ClipProxy clip = (watched == ui->clip_list->viewport()) ?
551 cliplist_clips->mutable_clip(row) : playlist_clips->mutable_clip(row);
552 if (watched == ui->playlist->viewport()) {
553 stream_idx = clip->stream_idx;
556 if (column != camera_column) {
557 last_mousewheel_camera_row = -1;
559 if (column == in_column) {
560 current_change_id += "in:" + to_string(row);
561 int64_t pts = clip->pts_in + wheel->angleDelta().y() * wheel_sensitivity;
562 set_pts_in(pts, current_pts, clip);
563 preview_single_frame(pts, stream_idx, FIRST_AT_OR_AFTER);
564 } else if (column == out_column) {
565 current_change_id += "out:" + to_string(row);
566 int64_t pts = clip->pts_out + wheel->angleDelta().y() * wheel_sensitivity;
567 pts = std::max(pts, clip->pts_in);
568 pts = std::min(pts, current_pts);
570 preview_single_frame(pts, stream_idx, LAST_BEFORE);
571 } else if (column == camera_column) {
572 current_change_id += "camera:" + to_string(row);
573 int angle_degrees = wheel->angleDelta().y();
574 if (last_mousewheel_camera_row == row) {
575 angle_degrees += leftover_angle_degrees;
578 int stream_idx = clip->stream_idx + angle_degrees / camera_degrees_per_pixel;
579 stream_idx = std::max(stream_idx, 0);
580 stream_idx = std::min(stream_idx, NUM_CAMERAS - 1);
581 clip->stream_idx = stream_idx;
583 last_mousewheel_camera_row = row;
584 leftover_angle_degrees = angle_degrees % camera_degrees_per_pixel;
586 // Don't update the live view, that's rarely what the operator wants.
589 currently_deferring_model_changes = false;
590 } else if (event->type() == QEvent::MouseButtonRelease) {
596 void MainWindow::preview_single_frame(int64_t pts, unsigned stream_idx, MainWindow::Rounding rounding)
598 if (rounding == LAST_BEFORE) {
599 lock_guard<mutex> lock(frame_mu);
600 if (frames[stream_idx].empty())
602 auto it = lower_bound(frames[stream_idx].begin(), frames[stream_idx].end(), pts);
603 if (it != frames[stream_idx].end()) {
607 assert(rounding == FIRST_AT_OR_AFTER);
608 lock_guard<mutex> lock(frame_mu);
609 if (frames[stream_idx].empty())
611 auto it = upper_bound(frames[stream_idx].begin(), frames[stream_idx].end(), pts - 1);
612 if (it != frames[stream_idx].end()) {
618 fake_clip.pts_in = pts;
619 fake_clip.pts_out = pts + 1;
620 preview_player->play_clip(fake_clip, stream_idx);
623 void MainWindow::playlist_selection_changed()
625 QItemSelectionModel *selected = ui->playlist->selectionModel();
626 bool any_selected = selected->hasSelection();
627 ui->playlist_duplicate_btn->setEnabled(any_selected);
628 ui->playlist_remove_btn->setEnabled(any_selected);
629 ui->playlist_move_up_btn->setEnabled(
630 any_selected && selected->selectedRows().front().row() > 0);
631 ui->playlist_move_down_btn->setEnabled(
632 any_selected && selected->selectedRows().back().row() < int(playlist_clips->size()) - 1);
633 ui->play_btn->setEnabled(!playlist_clips->empty());
636 void MainWindow::clip_list_selection_changed(const QModelIndex ¤t, const QModelIndex &)
638 int camera_selected = -1;
639 if (current.column() >= int(ClipList::Column::CAMERA_1) &&
640 current.column() <= int(ClipList::Column::CAMERA_4)) {
641 camera_selected = current.column() - int(ClipList::Column::CAMERA_1);
643 highlight_camera_input(camera_selected);
646 void MainWindow::report_disk_space(off_t free_bytes, double estimated_seconds_left)
649 if (estimated_seconds_left < 60.0) {
650 strcpy(time_str, "<font color=\"red\">Less than a minute</font>");
651 } else if (estimated_seconds_left < 1800.0) { // Less than half an hour: Xm Ys (red).
652 int s = lrintf(estimated_seconds_left);
655 snprintf(time_str, sizeof(time_str), "<font color=\"red\">%dm %ds</font>", m, s);
656 } else if (estimated_seconds_left < 3600.0) { // Less than an hour: Xm.
657 int m = lrintf(estimated_seconds_left / 60.0);
658 snprintf(time_str, sizeof(time_str), "%dm", m);
659 } else if (estimated_seconds_left < 36000.0) { // Less than ten hours: Xh Ym.
660 int m = lrintf(estimated_seconds_left / 60.0);
663 snprintf(time_str, sizeof(time_str), "%dh %dm", h, m);
664 } else { // More than ten hours: Xh.
665 int h = lrintf(estimated_seconds_left / 3600.0);
666 snprintf(time_str, sizeof(time_str), "%dh", h);
669 snprintf(buf, sizeof(buf), "Disk free: %'.0f MB (approx. %s)", free_bytes / 1048576.0, time_str);
671 std::string label = buf;
673 post_to_main_thread([this, label] {
674 disk_free_label->setText(QString::fromStdString(label));
675 ui->menuBar->setCornerWidget(disk_free_label); // Need to set this again for the sizing to get right.
679 void MainWindow::exit_triggered()
684 void MainWindow::highlight_camera_input(int stream_idx)
686 if (stream_idx == 0) {
687 ui->input1_frame->setStyleSheet("background: rgb(0,255,0)");
689 ui->input1_frame->setStyleSheet("");
691 if (stream_idx == 1) {
692 ui->input2_frame->setStyleSheet("background: rgb(0,255,0)");
694 ui->input2_frame->setStyleSheet("");
696 if (stream_idx == 2) {
697 ui->input3_frame->setStyleSheet("background: rgb(0,255,0)");
699 ui->input3_frame->setStyleSheet("");
701 if (stream_idx == 3) {
702 ui->input4_frame->setStyleSheet("background: rgb(0,255,0)");
704 ui->input4_frame->setStyleSheet("");