diff --git a/data/camera.css b/data/camera.css index 68dd90d..34573eb 100644 --- a/data/camera.css +++ b/data/camera.css @@ -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; } diff --git a/data/camera.ui b/data/camera.ui index 5686f81..d21eb1b 100644 --- a/data/camera.ui +++ b/data/camera.ui @@ -110,6 +110,61 @@ + + + vertical + fill + center + 5 + 0 + 0 + + + Error happened + 1 + 1 + start + 5 + 5 + 5 + 5 + 0 + + + + + 0 + start + 5 + 5 + 5 + 5 + + + horizontal + 10 + + + Error + + + + + dialog-warning-symbolic + + + + + + + + + + horizontal diff --git a/src/main.c b/src/main.c index a38f0d8..97df943 100644 --- a/src/main.c +++ b/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); - mp_io_pipeline_start(); + 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);