Show user-visible error when no camera is available.
This commit is contained in:
@@ -1,8 +1,3 @@
|
||||
.errorbox {
|
||||
background: #dd0000;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.controlbox {
|
||||
background: rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
@@ -12,6 +7,11 @@
|
||||
background-color: rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
.error-overlay {
|
||||
opacity: 0.9;
|
||||
background-color: rgba(255, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
.flash {
|
||||
background-color: #ffffff;
|
||||
}
|
||||
|
@@ -110,6 +110,61 @@
|
||||
</style>
|
||||
</object>
|
||||
</child>
|
||||
<child type="overlay">
|
||||
<object class="GtkBox" id="message-box">
|
||||
<property name="orientation">vertical</property>
|
||||
<property name="halign">fill</property>
|
||||
<property name="valign">center</property>
|
||||
<property name="spacing">5</property>
|
||||
<property name="can-focus">0</property>
|
||||
<property name="visible">0</property>
|
||||
<child>
|
||||
<object class="GtkLabel" id="message-label">
|
||||
<property name="label">Error happened</property>
|
||||
<property name="vexpand">1</property>
|
||||
<property name="hexpand">1</property>
|
||||
<property name="valign">start</property>
|
||||
<property name="margin-start">5</property>
|
||||
<property name="margin-end">5</property>
|
||||
<property name="margin-top">5</property>
|
||||
<property name="margin-bottom">5</property>
|
||||
<property name="can-focus">0</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton">
|
||||
<property name="visible">0</property>
|
||||
<property name="halign">start</property>
|
||||
<property name="margin-start">5</property>
|
||||
<property name="margin-end">5</property>
|
||||
<property name="margin-top">5</property>
|
||||
<property name="margin-bottom">5</property>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<property name="orientation">horizontal</property>
|
||||
<property name="spacing">10</property>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="label">Error</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkImage">
|
||||
<property name="icon-name">dialog-warning-symbolic</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<style>
|
||||
<class name="destructive-action"/>
|
||||
</style>
|
||||
</object>
|
||||
</child>
|
||||
<style>
|
||||
<class name="error-overlay"/>
|
||||
</style>
|
||||
</object>
|
||||
</child>
|
||||
<child type="overlay">
|
||||
<object class="GtkBox" id="bottom-box">
|
||||
<property name="orientation">horizontal</property>
|
||||
|
42
src/main.c
42
src/main.c
@@ -63,6 +63,9 @@ GtkWidget *scanned_codes;
|
||||
GtkWidget *preview_top_box;
|
||||
GtkWidget *preview_bottom_box;
|
||||
|
||||
GtkWidget *message_box;
|
||||
GtkWidget *message_label;
|
||||
|
||||
GtkWidget *flash_button;
|
||||
GtkWidget *iso_button;
|
||||
GtkWidget *shutter_button;
|
||||
@@ -89,6 +92,13 @@ remap(int value, int input_min, int input_max, int output_min, int output_max)
|
||||
return (int)result;
|
||||
}
|
||||
|
||||
static void
|
||||
display_error(const char *message)
|
||||
{
|
||||
gtk_label_set_label(GTK_LABEL(message_label), message);
|
||||
gtk_widget_set_visible(message_box, true);
|
||||
}
|
||||
|
||||
bool
|
||||
check_window_active()
|
||||
{
|
||||
@@ -162,8 +172,7 @@ update_state(const mp_state_main *new_state)
|
||||
state.focus.max = new_state->focus.max;
|
||||
state.focus.manual = new_state->focus.manual;
|
||||
|
||||
state.has_auto_focus_continuous =
|
||||
new_state->has_auto_focus_continuous;
|
||||
state.has_auto_focus_continuous = new_state->has_auto_focus_continuous;
|
||||
state.has_auto_focus_start = new_state->has_auto_focus_start;
|
||||
|
||||
state.preview_buffer_width = new_state->preview_buffer_width;
|
||||
@@ -357,10 +366,8 @@ position_preview(float *offset_x, float *offset_y, float *size_x, float *size_y)
|
||||
}
|
||||
|
||||
int scale_factor = gtk_widget_get_scale_factor(preview);
|
||||
int top_height =
|
||||
gtk_widget_get_height(preview_top_box) * scale_factor;
|
||||
int bottom_height =
|
||||
gtk_widget_get_height(preview_bottom_box) * scale_factor;
|
||||
int top_height = gtk_widget_get_height(preview_top_box) * scale_factor;
|
||||
int bottom_height = gtk_widget_get_height(preview_bottom_box) * scale_factor;
|
||||
int inner_height = state.preview_height - top_height - bottom_height;
|
||||
|
||||
float scale = (float)MIN(state.preview_width / (float)buffer_width,
|
||||
@@ -519,6 +526,8 @@ preview_resize(GtkWidget *widget, int width, int height, gpointer data)
|
||||
if (state.preview_width != width || state.preview_height != height) {
|
||||
state.preview_width = width;
|
||||
state.preview_height = height;
|
||||
if (state.configuration->count == 0)
|
||||
return TRUE;
|
||||
update_io_pipeline();
|
||||
}
|
||||
|
||||
@@ -898,9 +907,11 @@ flash_button_clicked(GtkWidget *button, gpointer user_data)
|
||||
static void
|
||||
on_realize(GtkWidget *window, gpointer *data)
|
||||
{
|
||||
if (state.configuration->count == 0) {
|
||||
return;
|
||||
}
|
||||
GtkNative *native = gtk_widget_get_native(window);
|
||||
mp_process_pipeline_init_gl(gtk_native_get_surface(native));
|
||||
|
||||
state.camera = state.configuration->cameras[0];
|
||||
update_io_pipeline();
|
||||
}
|
||||
@@ -988,14 +999,14 @@ static gboolean
|
||||
fb_profile_to_state(GValue *value, GVariant *variant, gpointer user_data)
|
||||
{
|
||||
const gchar *name;
|
||||
gboolean state = FALSE;
|
||||
gboolean fb_state = FALSE;
|
||||
|
||||
name = g_variant_get_string(variant, NULL);
|
||||
|
||||
if (g_strcmp0(name, "full") == 0)
|
||||
state = TRUE;
|
||||
fb_state = TRUE;
|
||||
|
||||
g_value_set_boolean(value, state);
|
||||
g_value_set_boolean(value, fb_state);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@@ -1005,9 +1016,9 @@ state_to_fb_profile(const GValue *value,
|
||||
const GVariantType *expected_type,
|
||||
gpointer user_data)
|
||||
{
|
||||
gboolean state = g_value_get_boolean(value);
|
||||
gboolean fb_state = g_value_get_boolean(value);
|
||||
|
||||
return g_variant_new_string(state ? "full" : "silent");
|
||||
return g_variant_new_string(fb_state ? "full" : "silent");
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -1194,6 +1205,9 @@ activate(GtkApplication *app, gpointer data)
|
||||
preview_bottom_box =
|
||||
GTK_WIDGET(gtk_builder_get_object(builder, "bottom-box"));
|
||||
|
||||
message_box = GTK_WIDGET(gtk_builder_get_object(builder, "message-box"));
|
||||
message_label = GTK_WIDGET(gtk_builder_get_object(builder, "message-label"));
|
||||
|
||||
g_signal_connect(window, "realize", G_CALLBACK(on_realize), NULL);
|
||||
|
||||
g_signal_connect(preview, "realize", G_CALLBACK(preview_realize), NULL);
|
||||
@@ -1317,7 +1331,11 @@ activate(GtkApplication *app, gpointer data)
|
||||
g_application_get_dbus_connection(G_APPLICATION(app));
|
||||
mp_flash_gtk_init(conn);
|
||||
|
||||
if (state.configuration->count > 0) {
|
||||
mp_io_pipeline_start();
|
||||
} else {
|
||||
display_error("No camera found");
|
||||
}
|
||||
|
||||
gtk_application_add_window(app, GTK_WINDOW(window));
|
||||
gtk_widget_set_visible(window, true);
|
||||
|
Reference in New Issue
Block a user