summaryrefslogtreecommitdiff
path: root/gui_app_window.c
diff options
context:
space:
mode:
Diffstat (limited to 'gui_app_window.c')
-rw-r--r--gui_app_window.c60
1 files changed, 40 insertions, 20 deletions
diff --git a/gui_app_window.c b/gui_app_window.c
index 7c2bedd..b7c0d84 100644
--- a/gui_app_window.c
+++ b/gui_app_window.c
@@ -20,16 +20,11 @@
* Web: http://ni.fr.eu.org/
* Email: <nico at ni.fr.eu.org>
*/
-#include <gtk/gtk.h>
#include <stdbool.h>
-#include <assert.h>
#include <math.h>
-#include "device.h"
-#include "utils.h"
-
-#include "gui_app.h"
#include "gui_app_window.h"
+#include "utils.h"
struct _GuiAppWindow {
GtkApplicationWindow parent;
@@ -38,6 +33,7 @@ struct _GuiAppWindow {
typedef struct _GuiAppWindowPrivate GuiAppWindowPrivate;
struct _GuiAppWindowPrivate {
+ GuiAppWindow *win;
GuiApp *app;
GtkDrawingArea *video;
GtkButton *start_stop_button;
@@ -107,8 +103,17 @@ video_ready_cb(GuiApp *app, gpointer user_data)
{
GuiAppWindowPrivate *priv = user_data;
if (priv->started) {
- struct image *image = device_read(priv->device);
- if (image) {
+ GError *error = NULL;
+ struct image *image = device_read(priv->device, &error);
+ if (!image) {
+ if (error) {
+ utils_dialog_error(GTK_WINDOW(priv->win),
+ "error reading image: %s",
+ error->message);
+ g_error_free(error);
+ gtk_widget_destroy(GTK_WIDGET(priv->win));
+ }
+ } else {
/* Release old data. */
if (priv->surface) {
cairo_surface_destroy(priv->surface);
@@ -165,23 +170,29 @@ video_ready_cb(GuiApp *app, gpointer user_data)
static void
video_start(GuiAppWindowPrivate *priv)
{
- assert(!priv->started);
- priv->started = true;
+ g_assert(!priv->started);
int stride = cairo_format_stride_for_width(CAIRO_FORMAT_RGB24,
priv->width);
device_set_resolution(priv->device, priv->width, priv->height, stride);
video_size_update(priv);
- device_start(priv->device);
- priv->video_ready_handler_id = g_signal_connect(priv->app, "video-ready",
- G_CALLBACK(video_ready_cb), priv);
- gtk_button_set_label(priv->start_stop_button, "Stop");
+ GError *error = NULL;
+ if (!device_start(priv->device, &error)) {
+ utils_dialog_error(GTK_WINDOW(priv->win), "can not start: %s",
+ error->message);
+ g_error_free(error);
+ } else {
+ priv->video_ready_handler_id = g_signal_connect(priv->app, "video-ready",
+ G_CALLBACK(video_ready_cb), priv);
+ gtk_button_set_label(priv->start_stop_button, "Stop");
+ priv->started = true;
+ }
}
/* Stop video. */
static void
video_stop(GuiAppWindowPrivate *priv)
{
- assert(priv->started);
+ g_assert(priv->started);
if (priv->surface) {
cairo_surface_destroy(priv->surface);
priv->surface = NULL;
@@ -195,7 +206,11 @@ video_stop(GuiAppWindowPrivate *priv)
priv->image_converted = NULL;
}
g_signal_handler_disconnect(priv->app, priv->video_ready_handler_id);
- device_stop(priv->device);
+ GError *error = NULL;
+ if (!device_stop(priv->device, &error)) {
+ g_warning("device_stop: %s", error->message);
+ g_error_free(error);
+ }
priv->started = false;
gtk_widget_queue_draw(GTK_WIDGET(priv->video));
gtk_button_set_label(priv->start_stop_button, "Start");
@@ -238,7 +253,11 @@ destroy_cb(GtkWidget *widget, gpointer user_data)
if (priv->started)
video_stop(priv);
if (priv->device) {
- device_close(priv->device);
+ GError *error = NULL;
+ if (!device_close(priv->device, &error)) {
+ g_warning("device_close: %s", error->message);
+ g_error_free(error);
+ }
priv->device = NULL;
}
}
@@ -263,7 +282,7 @@ resolution_combo_box_changed_cb(GtkComboBox *combo, gpointer user_data)
GuiAppWindowPrivate *priv = gui_app_window_get_instance_private(win);
int sel = gtk_combo_box_get_active(combo);
const struct device_info *info = device_get_info(priv->device);
- assert(sel >= 0 && sel < info->resolutions);
+ g_assert(sel >= 0 && sel < info->resolutions);
priv->width = info->resolution[sel].width;
priv->height = info->resolution[sel].height;
if (priv->started) {
@@ -389,6 +408,7 @@ gui_app_window_init(GuiAppWindow *win)
{
gtk_widget_init_template(GTK_WIDGET(win));
GuiAppWindowPrivate *priv = gui_app_window_get_instance_private(win);
+ priv->win = win;
priv->app = NULL;
priv->allocation.width = -1;
cairo_matrix_init_identity(&priv->transform);
@@ -462,7 +482,7 @@ void
gui_app_window_open(GuiAppWindow *win, struct device *device)
{
GuiAppWindowPrivate *priv = gui_app_window_get_instance_private(win);
- assert(!priv->device);
+ g_assert(!priv->device);
priv->app = GUI_APP(gtk_window_get_application(GTK_WINDOW(win)));
const struct device_info *info = device_get_info(device);
priv->width = info->resolution[0].width;
@@ -485,7 +505,7 @@ gui_app_window_open(GuiAppWindow *win, struct device *device)
const struct device_info_resolution *ir = &info->resolution[i];
char buf[32];
int r = snprintf(buf, sizeof(buf), "%dx%d", ir->width, ir->height);
- assert(r < sizeof(buf));
+ g_assert(r < sizeof(buf));
gtk_combo_box_text_append_text(priv->resolution_combo_box, buf);
}
gtk_combo_box_set_active(GTK_COMBO_BOX(priv->resolution_combo_box), 0);