+ preview_player->play_clip(fake_clip, 0, stream_idx);
+}
+
+void MainWindow::playlist_selection_changed()
+{
+ QItemSelectionModel *selected = ui->playlist->selectionModel();
+ bool any_selected = selected->hasSelection();
+ ui->playlist_duplicate_btn->setEnabled(any_selected);
+ ui->playlist_remove_btn->setEnabled(any_selected);
+ ui->playlist_move_up_btn->setEnabled(
+ any_selected && selected->selectedRows().front().row() > 0);
+ ui->playlist_move_down_btn->setEnabled(
+ any_selected && selected->selectedRows().back().row() < int(playlist_clips->size()) - 1);
+ ui->play_btn->setEnabled(!playlist_clips->empty());
+
+ if (!any_selected) {
+ set_output_status("paused");
+ } else {
+ double remaining = 0.0;
+ for (int row = selected->selectedRows().front().row(); row < int(playlist_clips->size()); ++row) {
+ const Clip clip = *playlist_clips->clip(row);
+ remaining += double(clip.pts_out - clip.pts_in) / TIMEBASE / 0.5; // FIXME: stop hardcoding speed.
+ }
+ set_output_status(format_duration(remaining) + " ready");
+ }
+}
+
+void MainWindow::clip_list_selection_changed(const QModelIndex ¤t, const QModelIndex &)
+{
+ int camera_selected = -1;
+ if (current.column() >= int(ClipList::Column::CAMERA_1) &&
+ current.column() <= int(ClipList::Column::CAMERA_4)) {
+ camera_selected = current.column() - int(ClipList::Column::CAMERA_1);
+ }
+ highlight_camera_input(camera_selected);
+}
+
+void MainWindow::report_disk_space(off_t free_bytes, double estimated_seconds_left)
+{
+ char time_str[256];
+ if (estimated_seconds_left < 60.0) {
+ strcpy(time_str, "<font color=\"red\">Less than a minute</font>");
+ } else if (estimated_seconds_left < 1800.0) { // Less than half an hour: Xm Ys (red).
+ int s = lrintf(estimated_seconds_left);
+ int m = s / 60;
+ s %= 60;
+ snprintf(time_str, sizeof(time_str), "<font color=\"red\">%dm %ds</font>", m, s);
+ } else if (estimated_seconds_left < 3600.0) { // Less than an hour: Xm.
+ int m = lrintf(estimated_seconds_left / 60.0);
+ snprintf(time_str, sizeof(time_str), "%dm", m);
+ } else if (estimated_seconds_left < 36000.0) { // Less than ten hours: Xh Ym.
+ int m = lrintf(estimated_seconds_left / 60.0);
+ int h = m / 60;
+ m %= 60;
+ snprintf(time_str, sizeof(time_str), "%dh %dm", h, m);
+ } else { // More than ten hours: Xh.
+ int h = lrintf(estimated_seconds_left / 3600.0);
+ snprintf(time_str, sizeof(time_str), "%dh", h);
+ }
+ char buf[256];
+ snprintf(buf, sizeof(buf), "Disk free: %'.0f MB (approx. %s)", free_bytes / 1048576.0, time_str);
+
+ std::string label = buf;
+
+ post_to_main_thread([this, label] {
+ disk_free_label->setText(QString::fromStdString(label));
+ ui->menuBar->setCornerWidget(disk_free_label); // Need to set this again for the sizing to get right.
+ });
+}
+
+void MainWindow::exit_triggered()
+{
+ close();
+}
+
+void MainWindow::highlight_camera_input(int stream_idx)
+{
+ if (stream_idx == 0) {
+ ui->input1_frame->setStyleSheet("background: rgb(0,255,0)");
+ } else {
+ ui->input1_frame->setStyleSheet("");
+ }
+ if (stream_idx == 1) {
+ ui->input2_frame->setStyleSheet("background: rgb(0,255,0)");
+ } else {
+ ui->input2_frame->setStyleSheet("");
+ }
+ if (stream_idx == 2) {
+ ui->input3_frame->setStyleSheet("background: rgb(0,255,0)");
+ } else {
+ ui->input3_frame->setStyleSheet("");
+ }
+ if (stream_idx == 3) {
+ ui->input4_frame->setStyleSheet("background: rgb(0,255,0)");
+ } else {
+ ui->input4_frame->setStyleSheet("");
+ }
+}
+
+void MainWindow::set_output_status(const string &status)
+{
+ ui->live_label->setText(QString::fromStdString("Current output (" + status + ")"));
+
+ lock_guard<mutex> lock(queue_status_mu);
+ queue_status = status;
+}
+
+pair<string, string> MainWindow::get_queue_status() const {
+ lock_guard<mutex> lock(queue_status_mu);
+ return {queue_status, "text/plain"};