From 0e8146cb77a2891a228d61fc5cfbca9d715e69fb Mon Sep 17 00:00:00 2001 From: jstebbins Date: Sat, 4 Apr 2009 21:13:29 +0000 Subject: LinGui: preview and picture window changes - split picture settings into it's own window - create overlay for preview window (like the mac ui, but not a pretty) - save window positions and preview display status between sessions git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@2297 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- gtk/src/callbacks.c | 2 +- gtk/src/ghb.ui | 468 +++++++++++++++++++++++------------------- gtk/src/internal_defaults.xml | 10 + gtk/src/main.c | 13 ++ gtk/src/presets.c | 43 +++- gtk/src/presets.h | 2 + gtk/src/preview.c | 293 ++++++++++++++++++++++++-- gtk/src/values.c | 4 + 8 files changed, 605 insertions(+), 230 deletions(-) (limited to 'gtk') diff --git a/gtk/src/callbacks.c b/gtk/src/callbacks.c index ad36f6fa7..36f78f76c 100644 --- a/gtk/src/callbacks.c +++ b/gtk/src/callbacks.c @@ -1120,7 +1120,7 @@ title_changed_cb(GtkWidget *widget, signal_user_data_t *ud) gint preview_count; preview_count = ghb_settings_get_int(ud->settings, "preview_count"); widget = GHB_WIDGET(ud->builder, "preview_frame"); - gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 1, preview_count); + gtk_range_set_range (GTK_RANGE(widget), 1, preview_count); ghb_ui_update(ud, "preview_frame", ghb_int64_value(2)); ghb_set_preview_image (ud); diff --git a/gtk/src/ghb.ui b/gtk/src/ghb.ui index 39964c750..7496d641d 100644 --- a/gtk/src/ghb.ui +++ b/gtk/src/ghb.ui @@ -325,7 +325,7 @@ hb-picture show_preview_menu _Picture Settings - + @@ -503,7 +503,7 @@ Open Picture Settings Picture Settings hb-picture - + False @@ -3091,7 +3091,6 @@ no-dct-decimate=0:cabac=1 False GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - 3 0 out @@ -4086,233 +4085,39 @@ location as the movie. - - Preview - GTK_WIN_POS_CENTER + + Picture Settings + GTK_WIN_POS_NONE GDK_WINDOW_TYPE_HINT_DIALOG True True - + False + preview_window + GDK_STRUCTURE_MASK + + - + True - 4 - - - True - 5 - - - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - 0 - 0 - 2 - 2 - 2 - 2 - - - True - True - - - - - 0 - - - - - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - 10 - 10 - - - True - 5 - - - 30 - True - True - True - none - - - - True - gtk-media-play - - - - - False - 0 - - - - - True - preview_progress_adj - False - right - - - - 1 - - - - - True - - - 1 - True - - - 0 - - - - - 16 - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - - - False - 1 - - - - - 1 - True - - - 2 - - - - - 2 - - - - - - - False - 1 - - - - - True - 4 - 10 - 10 - - - True - 10 - - - True - 2 - - - True - <b>Preview Frame:</b> - True - - - 0 - - - - - True - True - 2 - none - adjustment19 - True - - - - 1 - - - - - False - 0 - - - - - True - 2 - - - True - <b>Duration:</b> - True - - - False - 0 - - - - - True - True - adjustment21 - True - - - - False - 1 - - - - - 1 - - - - - - - False - 2 - - - - - 0 - - + 5 - + True + True + Open Preview Window + Show Preview + False - 1 + 0 - True True + True @@ -5036,11 +4841,246 @@ location as the movie. + + True + 1 + + + + + + + + Preview + GTK_WIN_POS_CENTER + True + True + False + GDK_STRUCTURE_MASK + + + + + True + 4 + + + True + 5 + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 0 + 0 + 2 + 2 + 2 + 2 + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_LEAVE_NOTIFY_MASK + True + + + + + + + 0 + + + + + 0 + + + + + True + False 1 + + + + + + 500 + False + .50 + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_ENTER_NOTIFY_MASK + + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 10 + 10 + 5 + 5 + + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + + + True + True + adjustment19 + 0 + bottom + + + + False + 0 + + + + + True + 5 + + + 30 + True + True + True + none + + + + True + gtk-media-play + + + + + False + 0 + + + + + True + preview_progress_adj + False + right + + + + 1 + + + + + True + + + 1 + True + + + 0 + + + + + 16 + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + + + False + 1 + + + + + 1 + True + + + 2 + + + + + 2 + + + + + 1 + + + + + True + 10 + + + True + 2 + + + True + <b>Duration:</b> + True + + + False + 0 + + + + + True + True + adjustment21 + True + + + + False + 1 + + + + + 0 + + + + + True + True + Open Picture Settings + Settings + + + + False + 1 + + + + + False + 2 + + + + + diff --git a/gtk/src/internal_defaults.xml b/gtk/src/internal_defaults.xml index 5b8106590..65201e89c 100644 --- a/gtk/src/internal_defaults.xml +++ b/gtk/src/internal_defaults.xml @@ -120,8 +120,18 @@ preview_count 10 + preview_x + -1 + preview_y + -1 + settings_x + -1 + settings_y + -1 show_presets + show_preview + use_source_name update_skip_version diff --git a/gtk/src/main.c b/gtk/src/main.c index 559d9799e..370086fdd 100644 --- a/gtk/src/main.c +++ b/gtk/src/main.c @@ -631,6 +631,19 @@ main (int argc, char *argv[]) // Start timer for monitoring libhb status, 500ms g_timeout_add (500, ghb_timer_cb, (gpointer)ud); // Everything should be go-to-go. Lets rock! + + // Create floating window over preview image + GtkWidget *widget; + GdkWindow *parent, *win; + + widget = GHB_WIDGET(ud->builder, "preview_image"); + gtk_widget_realize(widget); + parent = gtk_widget_get_window(widget); + widget = GHB_WIDGET(ud->builder, "preview_hud"); + gtk_widget_realize(widget); + win = gtk_widget_get_window(widget); + gdk_window_reparent(win, parent, 0, 0); + gtk_main (); ghb_backend_close(); if (ud->queue) diff --git a/gtk/src/presets.c b/gtk/src/presets.c index cbe539345..aafff05d1 100644 --- a/gtk/src/presets.c +++ b/gtk/src/presets.c @@ -38,6 +38,7 @@ enum static GValue *presetsPlist = NULL; static GValue *internalPlist = NULL; static GValue *prefsPlist = NULL; +static gboolean prefs_modified = FALSE; static const GValue* preset_dict_get_value(GValue *dict, const gchar *key); static void store_plist(GValue *plist, const gchar *name); @@ -1196,12 +1197,35 @@ ghb_prefs_save(GValue *settings) } } store_plist(prefsPlist, "preferences"); + prefs_modified = FALSE; +} + +void +ghb_pref_set(GValue *settings, const gchar *key) +{ + const GValue *value, *value2; + + if (prefs_initializing) return; + value = ghb_settings_get_value(settings, key); + if (value != NULL) + { + GValue *dict; + dict = plist_get_dict(prefsPlist, "Preferences"); + if (dict == NULL) return; + value2 = ghb_dict_lookup(dict, key); + if (ghb_value_cmp(value, value2) != 0) + { + ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(value)); + store_plist(prefsPlist, "preferences"); + prefs_modified = TRUE; + } + } } void ghb_pref_save(GValue *settings, const gchar *key) { - const GValue *value; + const GValue *value, *value2; if (prefs_initializing) return; value = ghb_settings_get_value(settings, key); @@ -1210,8 +1234,23 @@ ghb_pref_save(GValue *settings, const gchar *key) GValue *dict; dict = plist_get_dict(prefsPlist, "Preferences"); if (dict == NULL) return; - ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(value)); + value2 = ghb_dict_lookup(dict, key); + if (ghb_value_cmp(value, value2) != 0) + { + ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(value)); + store_plist(prefsPlist, "preferences"); + prefs_modified = FALSE; + } + } +} + +void +ghb_prefs_store(void) +{ + if (prefs_modified) + { store_plist(prefsPlist, "preferences"); + prefs_modified = FALSE; } } diff --git a/gtk/src/presets.h b/gtk/src/presets.h index c5a870d3d..6bcd14a54 100644 --- a/gtk/src/presets.h +++ b/gtk/src/presets.h @@ -38,5 +38,7 @@ void ghb_presets_list_init(signal_user_data_t *ud, gint *indices, gint len); GValue* ghb_parse_preset_path(const gchar *path); gchar* ghb_preset_path_string(const GValue *path); gboolean ghb_preset_is_custom(void); +void ghb_prefs_store(void); +void ghb_pref_set(GValue *settings, const gchar *key); #endif // _GHB_PRESETS_H_ diff --git a/gtk/src/preview.c b/gtk/src/preview.c index d9abf248f..d3bd475da 100644 --- a/gtk/src/preview.c +++ b/gtk/src/preview.c @@ -713,9 +713,12 @@ preview_expose_cb( return TRUE; } - gdk_draw_pixbuf( - widget->window, NULL, ud->preview->pix, 0, 0, 0, 0, - -1, -1, GDK_RGB_DITHER_NONE, 0, 0); + if (ud->preview->pix != NULL) + { + gdk_draw_pixbuf( + widget->window, NULL, ud->preview->pix, 0, 0, 0, 0, + -1, -1, GDK_RGB_DITHER_NONE, 0, 0); + } return TRUE; } @@ -750,21 +753,113 @@ set_visible(GtkWidget *widget, gboolean visible) } } -void +G_MODULE_EXPORT void preview_button_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud) { - GtkWidget *widget = GHB_WIDGET (ud->builder, "preview_window"); - set_visible(widget, gtk_toggle_tool_button_get_active( - GTK_TOGGLE_TOOL_BUTTON(xwidget))); + gint titleindex; + + g_debug("preview_button_clicked_cb()"); + titleindex = ghb_settings_combo_int(ud->settings, "title"); + if (titleindex >= 0) + { + gint x, y; + GtkWidget *widget = GHB_WIDGET (ud->builder, "preview_window"); + x = ghb_settings_get_int(ud->settings, "preview_x"); + y = ghb_settings_get_int(ud->settings, "preview_y"); + if (x >= 0 && y >= 0) + gtk_window_move(GTK_WINDOW(widget), x, y); + set_visible(widget, gtk_toggle_button_get_active( + GTK_TOGGLE_BUTTON(xwidget))); + } + ghb_widget_to_setting (ud->settings, xwidget); + ghb_check_dependency(ud, xwidget); + const gchar *name = gtk_widget_get_name(xwidget); + ghb_pref_save(ud->settings, name); } -void -preview_menu_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud) +G_MODULE_EXPORT void +picture_settings_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud) { - GtkWidget *widget = GHB_WIDGET (ud->builder, "preview_window"); - set_visible(widget, TRUE); - widget = GHB_WIDGET (ud->builder, "show_picture"); - gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(widget), TRUE); + GtkWidget *widget; + gboolean active; + gint x, y; + + g_debug("picture_settings_clicked_cb()"); + widget = GHB_WIDGET (ud->builder, "settings_window"); + active = gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(xwidget)); + x = ghb_settings_get_int(ud->settings, "settings_x"); + y = ghb_settings_get_int(ud->settings, "settings_y"); + if (x >= 0 && y >= 0) + gtk_window_move(GTK_WINDOW(widget), x, y); + set_visible(widget, active); + if (ghb_settings_get_boolean(ud->settings, "show_preview")) + { + widget = GHB_WIDGET (ud->builder, "preview_window"); + x = ghb_settings_get_int(ud->settings, "preview_x"); + y = ghb_settings_get_int(ud->settings, "preview_y"); + if (x >= 0 && y >= 0) + gtk_window_move(GTK_WINDOW(widget), x, y); + set_visible(widget, active); + } +} + +G_MODULE_EXPORT void +picture_settings_alt_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud) +{ + GtkWidget *toggle; + gboolean active; + + g_debug("picture_settings_alt_clicked_cb()"); + toggle = GHB_WIDGET (ud->builder, "show_picture"); + active = gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(toggle)); + gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(toggle), !active); +} + +G_MODULE_EXPORT void +picture_settings_alt2_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud) +{ + GtkWidget *toggle; + gboolean active; + gint signal_id; + gint handler_id = 0; + + g_debug("picture_settings_alt2_clicked_cb()"); + toggle = GHB_WIDGET (ud->builder, "show_picture"); + active = gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(toggle)); + if (active) + { + // I don't want deleting the settings window to also remove the + // preview window, but changing the toggle will do this, so temporarily + // ignore the toggled signal + signal_id = g_signal_lookup("toggled", GTK_TYPE_TOGGLE_TOOL_BUTTON); + if (signal_id > 0) + { + // Valid signal id found. This should always succeed. + handler_id = g_signal_handler_find((gpointer)toggle, + G_SIGNAL_MATCH_ID, + signal_id, 0, 0, 0, 0); + if (handler_id > 0) + { + // This should also always succeed + g_signal_handler_block ((gpointer)toggle, handler_id); + } + } + } + + GtkWidget *widget = GHB_WIDGET (ud->builder, "settings_window"); + gint x, y; + + x = ghb_settings_get_int(ud->settings, "settings_x"); + y = ghb_settings_get_int(ud->settings, "settings_y"); + if (x >= 0 && y >= 0) + gtk_window_move(GTK_WINDOW(widget), x, y); + set_visible(widget, !active); + gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(toggle), !active); + + if (handler_id > 0) + { + g_signal_handler_unblock ((gpointer)toggle, handler_id); + } } void @@ -786,9 +881,44 @@ preview_window_delete_cb( signal_user_data_t *ud) { live_preview_stop(ud); + gtk_widget_hide(widget); + return TRUE; +} + +gboolean +settings_window_delete_cb( + GtkWidget *widget, + GdkEvent *event, + signal_user_data_t *ud) +{ + gint signal_id; + gint handler_id = 0; + gtk_widget_hide(widget); widget = GHB_WIDGET (ud->builder, "show_picture"); + + // I don't want deleting the settings window to also remove the + // preview window, but changing the toggle will do this, so temporarily + // ignore the toggled signal + signal_id = g_signal_lookup("toggled", GTK_TYPE_TOGGLE_TOOL_BUTTON); + if (signal_id > 0) + { + // Valid signal id found. This should always succeed. + handler_id = g_signal_handler_find((gpointer)widget, G_SIGNAL_MATCH_ID, + signal_id, 0, 0, 0, 0); + if (handler_id > 0) + { + // This should also always succeed + g_signal_handler_block ((gpointer)widget, handler_id); + } + } + gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(widget), FALSE); + + if (handler_id > 0) + { + g_signal_handler_unblock ((gpointer)widget, handler_id); + } return TRUE; } @@ -803,3 +933,140 @@ preview_duration_changed_cb(GtkWidget *widget, signal_user_data_t *ud) ghb_pref_save(ud->settings, name); } +static guint hud_timeout_id = 0; + +static gboolean +hud_timeout(signal_user_data_t *ud) +{ + GtkWidget *widget; + + widget = GHB_WIDGET(ud->builder, "preview_hud"); + gtk_widget_hide(widget); + hud_timeout_id = 0; + return FALSE; +} + +G_MODULE_EXPORT gboolean +hud_enter_cb( + GtkWidget *widget, + GdkEventCrossing *event, + signal_user_data_t *ud) +{ + if (hud_timeout_id != 0) + { + GMainContext *mc; + GSource *source; + + mc = g_main_context_default(); + source = g_main_context_find_source_by_id(mc, hud_timeout_id); + if (source != NULL) + g_source_destroy(source); + } + widget = GHB_WIDGET(ud->builder, "preview_hud"); + gtk_widget_show(widget); + hud_timeout_id = 0; + return FALSE; +} + +G_MODULE_EXPORT gboolean +preview_leave_cb( + GtkWidget *widget, + GdkEventCrossing *event, + signal_user_data_t *ud) +{ + if (hud_timeout_id != 0) + { + GMainContext *mc; + GSource *source; + + mc = g_main_context_default(); + source = g_main_context_find_source_by_id(mc, hud_timeout_id); + if (source != NULL) + g_source_destroy(source); + } + hud_timeout_id = g_timeout_add(300, (GSourceFunc)hud_timeout, ud); + return FALSE; +} + +G_MODULE_EXPORT gboolean +preview_motion_cb( + GtkWidget *widget, + GdkEventMotion *event, + signal_user_data_t *ud) +{ + if (hud_timeout_id != 0) + { + GMainContext *mc; + GSource *source; + + mc = g_main_context_default(); + source = g_main_context_find_source_by_id(mc, hud_timeout_id); + if (source != NULL) + g_source_destroy(source); + } + else + { + GtkWidget *widget; + GdkWindow *parent, *win; + gint pw, ph, w, h, x, y; + + widget = GHB_WIDGET(ud->builder, "preview_image"); + parent = gtk_widget_get_window(widget); + widget = GHB_WIDGET(ud->builder, "preview_hud"); + win = gtk_widget_get_window(widget); + gtk_widget_show(widget); + gdk_drawable_get_size(GDK_DRAWABLE(parent), &pw, &ph); + gdk_drawable_get_size(GDK_DRAWABLE(win), &w, &h); + x = pw/2 - w/2; + if (ph/4 > h/2) + y = ph - ph/4 - h/2; + else + y = ph - h; + gdk_window_move(win, x, y); + } + hud_timeout_id = g_timeout_add_seconds(10, (GSourceFunc)hud_timeout, ud); + return FALSE; +} + +G_MODULE_EXPORT gboolean +preview_configure_cb( + GtkWidget *widget, + GdkEventConfigure *event, + signal_user_data_t *ud) +{ + gint x, y; + + g_debug("preview_configure_cb()"); + if (GTK_WIDGET_VISIBLE(widget)) + { + gtk_window_get_position(GTK_WINDOW(widget), &x, &y); + ghb_settings_set_int(ud->settings, "preview_x", x); + ghb_settings_set_int(ud->settings, "preview_y", y); + ghb_pref_set(ud->settings, "preview_x"); + ghb_pref_set(ud->settings, "preview_y"); + ghb_prefs_store(); + } + return FALSE; +} + +G_MODULE_EXPORT gboolean +settings_configure_cb( + GtkWidget *widget, + GdkEventConfigure *event, + signal_user_data_t *ud) +{ + gint x, y; + + g_debug("settings_configure_cb()"); + if (GTK_WIDGET_VISIBLE(widget)) + { + gtk_window_get_position(GTK_WINDOW(widget), &x, &y); + ghb_settings_set_int(ud->settings, "settings_x", x); + ghb_settings_set_int(ud->settings, "settings_y", y); + ghb_pref_set(ud->settings, "settings_x"); + ghb_pref_set(ud->settings, "settings_y"); + ghb_prefs_store(); + } + return FALSE; +} + diff --git a/gtk/src/values.c b/gtk/src/values.c index a888d0a50..a2096e008 100644 --- a/gtk/src/values.c +++ b/gtk/src/values.c @@ -252,6 +252,10 @@ ghb_value_cmp(const GValue *vala, const GValue *valb) GType typa; GType typb; + if ((vala == NULL && valb != NULL) || (vala != NULL && valb == NULL)) + { + return 1; + } typa = G_VALUE_TYPE(vala); typb = G_VALUE_TYPE(valb); if (typa != typb) -- cgit v1.2.3