Commit ab31fcea authored by Daniel P. Berrange's avatar Daniel P. Berrange

Ensure every event is emitted in main thread

Ensure that the pixbuf loader emits events in the main
thread, allowing all calls to gdk threads enter/leave
to be removed
Signed-off-by: default avatarDaniel P. Berrange <dan@berrange.com>
parent 80fcebc6
......@@ -71,6 +71,36 @@ enum {
};
struct idle_emit_data {
EntangleImage *image;
EntanglePixbufLoader *loader;
const char *name;
};
static gboolean do_idle_emit_func(gpointer opaque)
{
struct idle_emit_data *data = opaque;
g_signal_emit_by_name(data->loader, data->name, data->image);
g_object_unref(data->image);
g_object_unref(data->loader);
g_free(data);
return FALSE;
}
static void do_idle_emit(EntanglePixbufLoader *loader,
const char *name,
EntangleImage *image)
{
struct idle_emit_data *data = g_new0(struct idle_emit_data, 1);
data->loader = g_object_ref(loader);
data->image = g_object_ref(image);
data->name = name;
g_idle_add(do_idle_emit_func, data);
}
static void entangle_pixbuf_loader_get_property(GObject *object,
guint prop_id,
GValue *value,
......@@ -211,9 +241,9 @@ static gboolean entangle_pixbuf_loader_result(gpointer data)
if (entry->refs) {
g_mutex_unlock(priv->lock);
ENTANGLE_DEBUG("Emit loaded %p %p %p", result->image, result->pixbuf, result->metadata);
g_signal_emit_by_name(loader, "pixbuf-loaded", result->image);
do_idle_emit(loader, "pixbuf-loaded", result->image);
if (result->metadata)
g_signal_emit_by_name(loader, "metadata-loaded", result->image);
do_idle_emit(loader, "metadata-loaded", result->image);
g_mutex_lock(priv->lock);
} else if (!entry->pending) {
g_hash_table_remove(priv->pixbufs, entangle_image_get_filename(result->image));
......@@ -478,35 +508,6 @@ GExiv2Metadata *entangle_pixbuf_loader_get_metadata(EntanglePixbufLoader *loader
}
struct idle_emit_data {
EntangleImage *image;
EntanglePixbufLoader *loader;
const char *name;
};
static gboolean do_idle_emit_func(gpointer opaque)
{
struct idle_emit_data *data = opaque;
g_signal_emit_by_name(data->loader, data->name, data->image);
g_object_unref(data->image);
g_object_unref(data->loader);
g_free(data);
return FALSE;
}
static void do_idle_emit(EntanglePixbufLoader *loader,
const char *name,
EntangleImage *image)
{
struct idle_emit_data *data = g_new0(struct idle_emit_data, 1);
data->loader = g_object_ref(loader);
data->image = g_object_ref(image);
data->name = name;
g_idle_add(do_idle_emit_func, data);
}
gboolean entangle_pixbuf_loader_load(EntanglePixbufLoader *loader,
EntangleImage *image)
{
......
......@@ -57,9 +57,6 @@ int main(int argc, char **argv)
g_set_application_name("Entangle");
g_thread_init(NULL);
gdk_threads_init();
group = g_option_group_new("entangle",
"Entangle application options",
"Show Entangle options",
......
......@@ -161,7 +161,6 @@ static void entangle_application_startup(GApplication *gapp)
EntangleApplicationPrivate *priv = app->priv;
GList *cameras = NULL, *tmp;
gdk_threads_enter();
if (entangle_preferences_interface_get_auto_connect(priv->preferences))
cameras = tmp = entangle_camera_list_get_cameras(priv->cameras);
......@@ -185,8 +184,6 @@ static void entangle_application_startup(GApplication *gapp)
g_list_free(cameras);
}
gdk_threads_leave();
(*G_APPLICATION_CLASS(entangle_application_parent_class)->startup)(gapp);
}
......
This diff is collapsed.
......@@ -98,14 +98,13 @@ static void do_refresh_control_entry(GObject *object,
{
GtkWidget *widget = GTK_WIDGET(data);
gchar *text;
gdk_threads_enter();
g_object_get(object, "value", &text, NULL);
if (GTK_IS_LABEL(widget))
gtk_label_set_text(GTK_LABEL(widget), text);
else
gtk_entry_set_text(GTK_ENTRY(widget), text);
g_free(text);
gdk_threads_leave();
}
......@@ -123,9 +122,7 @@ static void do_update_control_entry(GtkWidget *widget,
text = gtk_entry_get_text(GTK_ENTRY(widget));
ENTANGLE_DEBUG("entry [%s]", text);
gdk_threads_leave();
g_object_set(control, "value", text, NULL);
gdk_threads_enter();
entangle_camera_save_controls_async(priv->camera,
NULL,
......@@ -141,7 +138,6 @@ static void do_refresh_control_range(GObject *object,
GtkWidget *widget = GTK_WIDGET(data);
gfloat val;
gdk_threads_enter();
g_object_get(object, "value", &val, NULL);
if (GTK_IS_LABEL(widget)) {
gchar *text = g_strdup_printf("%0.02f", val);
......@@ -150,7 +146,6 @@ static void do_refresh_control_range(GObject *object,
} else {
gtk_range_set_value(GTK_RANGE(widget), val);
}
gdk_threads_leave();
}
......@@ -166,9 +161,7 @@ static void do_update_control_range(GtkRange *widget G_GNUC_UNUSED,
EntangleControlPanelPrivate *priv = panel->priv;
ENTANGLE_DEBUG("range [%lf]", value);
gdk_threads_leave();
g_object_set(control, "value", (float)value, NULL);
gdk_threads_enter();
entangle_camera_save_controls_async(priv->camera,
NULL,
......@@ -184,7 +177,6 @@ static void do_refresh_control_combo(GObject *object,
GtkWidget *widget = GTK_WIDGET(data);
gchar *text;
gdk_threads_enter();
g_object_get(object, "value", &text, NULL);
if (GTK_IS_LABEL(widget)) {
......@@ -198,7 +190,6 @@ static void do_refresh_control_combo(GObject *object,
gtk_combo_box_set_active(GTK_COMBO_BOX(widget), active);
}
g_free(text);
gdk_threads_leave();
}
......@@ -218,9 +209,7 @@ static void do_update_control_combo(GtkComboBox *widget,
gtk_tree_model_get(model, &iter, 0, &text, -1);
ENTANGLE_DEBUG("combo [%s]", text);
gdk_threads_leave();
g_object_set(control, "value", text, NULL);
gdk_threads_enter();
g_free(text);
......@@ -238,14 +227,12 @@ static void do_refresh_control_toggle(GObject *object,
GtkWidget *widget = GTK_WIDGET(data);
gboolean state;
gdk_threads_enter();
g_object_get(object, "value", &state, NULL);
if (GTK_IS_LABEL(widget))
gtk_label_set_text(GTK_LABEL(widget), state ? _("On") : _("Off"));
else
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget),
state);
gdk_threads_leave();
}
......@@ -261,9 +248,7 @@ static void do_update_control_toggle(GtkToggleButton *widget,
active = gtk_toggle_button_get_active(widget);
ENTANGLE_DEBUG("toggle [%d]", active);
gdk_threads_leave();
g_object_set(control, "value", active, NULL);
gdk_threads_enter();
entangle_camera_save_controls_async(priv->camera,
NULL,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment