From 8dd57b77ba63b2255026d8170fb663c5a7ca79a4 Mon Sep 17 00:00:00 2001 From: Eric Koegel Date: Thu, 1 Dec 2011 13:50:47 +0300 Subject: [PATCH] Created a statusbar update function and extended code for the statusbar to show image dimensions as well as the percentage the image is scaled at. --- src/image_viewer.c | 20 ++++++++++ src/image_viewer.h | 6 +++ src/main_window.c | 98 +++++++++++++++++++++++++++++++++++++++------------ 3 files changed, 101 insertions(+), 23 deletions(-) diff --git a/src/image_viewer.c b/src/image_viewer.c index ff20e3d..8c01cd2 100644 --- a/src/image_viewer.c +++ b/src/image_viewer.c @@ -1559,6 +1559,26 @@ rstto_image_viewer_get_orientation (RsttoImageViewer *viewer) return viewer->priv->orientation; } +gint +rstto_image_viewer_get_width (RsttoImageViewer *viewer) +{ + if (viewer && viewer->priv->pixbuf) + { + return gdk_pixbuf_get_width (viewer->priv->pixbuf); + } + return 0; +} + +gint +rstto_image_viewer_get_height (RsttoImageViewer *viewer) +{ + if (viewer && viewer->priv->pixbuf) + { + return gdk_pixbuf_get_height (viewer->priv->pixbuf); + } + return 0; +} + void rstto_image_viewer_set_menu ( RsttoImageViewer *viewer, diff --git a/src/image_viewer.h b/src/image_viewer.h index 9f93097..dd2a465 100644 --- a/src/image_viewer.h +++ b/src/image_viewer.h @@ -96,6 +96,12 @@ rstto_image_viewer_set_orientation ( RsttoImageOrientation rstto_image_viewer_get_orientation (RsttoImageViewer *viewer); +gint +rstto_image_viewer_get_width (RsttoImageViewer *viewer); + +gint +rstto_image_viewer_get_height (RsttoImageViewer *viewer); + void rstto_image_viewer_set_menu ( RsttoImageViewer *viewer, diff --git a/src/main_window.c b/src/main_window.c index 2a25027..21c2698 100644 --- a/src/main_window.c +++ b/src/main_window.c @@ -154,6 +154,8 @@ static gboolean cb_rstto_main_window_show_fs_toolbar_timeout (RsttoMainWindow *window); static void cb_rstto_main_window_image_list_iter_changed (RsttoImageListIter *iter, RsttoMainWindow *window); +static void +rstto_main_window_update_statusbar (RsttoMainWindow *window); static void cb_rstto_main_window_zoom_100 (GtkWidget *widget, RsttoMainWindow *window); @@ -852,15 +854,11 @@ rstto_main_window_image_list_iter_changed (RsttoMainWindow *window) { const gchar *file_basename = NULL; gchar *title = NULL; - gchar *status = NULL; - gchar *tmp_status = NULL; RsttoFile *cur_file = NULL; gint position, count; RsttoImageList *image_list = window->priv->image_list; GList *app_list, *iter; const gchar *content_type; - ExifEntry *exif_entry = NULL; - gchar exif_data[20]; GtkWidget *open_with_menu = gtk_menu_new(); GtkWidget *open_with_window_menu = gtk_menu_new(); gtk_menu_item_set_submenu (GTK_MENU_ITEM (gtk_ui_manager_get_widget ( window->priv->ui_manager, "/image-viewer-menu/open-with-menu")), open_with_menu); @@ -911,6 +909,56 @@ rstto_main_window_image_list_iter_changed (RsttoMainWindow *window) title = g_strdup_printf ("%s - %s", RISTRETTO_APP_TITLE, file_basename); } + } + else + { + GtkWidget *menu_item = gtk_image_menu_item_new_with_label (_("Empty")); + gtk_menu_shell_append (GTK_MENU_SHELL (open_with_menu), menu_item); + gtk_widget_set_sensitive (menu_item, FALSE); + + rstto_image_viewer_set_file (RSTTO_IMAGE_VIEWER(window->priv->image_viewer), NULL, -1, 0); + + menu_item = gtk_image_menu_item_new_with_label (_("Empty")); + gtk_menu_shell_append (GTK_MENU_SHELL (open_with_window_menu), menu_item); + gtk_widget_set_sensitive (menu_item, FALSE); + + gtk_widget_show_all (open_with_menu); + gtk_widget_show_all (open_with_window_menu); + + title = g_strdup (RISTRETTO_APP_TITLE); + } + + rstto_main_window_update_buttons (window); + gtk_window_set_title (GTK_WINDOW (window), title); + g_free (title); + + rstto_main_window_update_statusbar(window); + } +} + +/** + * rstto_main_window_update_statusbar: + * @window: + * + */ +static void +rstto_main_window_update_statusbar (RsttoMainWindow *window) +{ + const gchar *file_basename = NULL; + gchar *status = NULL; + gchar *tmp_status = NULL; + RsttoFile *cur_file = NULL; + RsttoImageViewer *viewer = RSTTO_IMAGE_VIEWER(window->priv->image_viewer); + ExifEntry *exif_entry = NULL; + gchar exif_data[20]; + + if (window->priv->image_list) + { + cur_file = rstto_image_list_iter_get_file (window->priv->iter); + if (NULL != cur_file) + { + file_basename = rstto_file_get_display_name (cur_file); + status = g_strdup(file_basename); if (TRUE == rstto_file_has_exif (cur_file)) @@ -929,7 +977,7 @@ rstto_main_window_image_list_iter_changed (RsttoMainWindow *window) g_free (status); status = tmp_status; - exif_entry_free (exif_entry); + /*exif_entry_free (exif_entry);*/ } exif_entry = rstto_file_get_exif ( cur_file, @@ -943,31 +991,26 @@ rstto_main_window_image_list_iter_changed (RsttoMainWindow *window) g_free (status); status = tmp_status; - exif_entry_free (exif_entry); + /*exif_entry_free (exif_entry);*/ } } + + if(rstto_image_viewer_get_width(viewer) != 0 && rstto_image_viewer_get_height(viewer) != 0) + { + tmp_status = g_strdup_printf ("%s\t%d x %d\t%.1f%%", status, + rstto_image_viewer_get_width(viewer), + rstto_image_viewer_get_height(viewer), + (100 * rstto_image_viewer_get_scale(viewer))); + + g_free (status); + status = tmp_status; + } } else { - GtkWidget *menu_item = gtk_image_menu_item_new_with_label (_("Empty")); - gtk_menu_shell_append (GTK_MENU_SHELL (open_with_menu), menu_item); - gtk_widget_set_sensitive (menu_item, FALSE); - - rstto_image_viewer_set_file (RSTTO_IMAGE_VIEWER(window->priv->image_viewer), NULL, -1, 0); - - menu_item = gtk_image_menu_item_new_with_label (_("Empty")); - gtk_menu_shell_append (GTK_MENU_SHELL (open_with_window_menu), menu_item); - gtk_widget_set_sensitive (menu_item, FALSE); - - gtk_widget_show_all (open_with_menu); - gtk_widget_show_all (open_with_window_menu); - - title = g_strdup (RISTRETTO_APP_TITLE); status = g_strdup (_("Press open to select an image")); } - rstto_main_window_update_buttons (window); - gtk_window_set_title (GTK_WINDOW (window), title); gtk_statusbar_pop (GTK_STATUSBAR (window->priv->statusbar), window->priv->statusbar_context_id); if (status) @@ -977,7 +1020,6 @@ rstto_main_window_image_list_iter_changed (RsttoMainWindow *window) status = NULL; } - g_free (title); } } @@ -2424,6 +2466,7 @@ static void cb_rstto_main_window_zoom_fit (GtkWidget *widget, RsttoMainWindow *window) { rstto_image_viewer_set_scale (RSTTO_IMAGE_VIEWER(window->priv->image_viewer), 0); + rstto_main_window_update_statusbar(window); } /** @@ -2437,6 +2480,7 @@ static void cb_rstto_main_window_zoom_100 (GtkWidget *widget, RsttoMainWindow *window) { rstto_image_viewer_set_scale (RSTTO_IMAGE_VIEWER(window->priv->image_viewer), 1); + rstto_main_window_update_statusbar(window); } /** @@ -2451,6 +2495,7 @@ cb_rstto_main_window_zoom_in (GtkWidget *widget, RsttoMainWindow *window) { gdouble scale = rstto_image_viewer_get_scale (RSTTO_IMAGE_VIEWER(window->priv->image_viewer)); rstto_image_viewer_set_scale (RSTTO_IMAGE_VIEWER(window->priv->image_viewer), scale*1.2); + rstto_main_window_update_statusbar(window); } /** @@ -2465,6 +2510,7 @@ cb_rstto_main_window_zoom_out (GtkWidget *widget, RsttoMainWindow *window) { gdouble scale = rstto_image_viewer_get_scale (RSTTO_IMAGE_VIEWER(window->priv->image_viewer)); rstto_image_viewer_set_scale (RSTTO_IMAGE_VIEWER(window->priv->image_viewer), scale/1.2); + rstto_main_window_update_statusbar(window); } /**********************/ @@ -2498,6 +2544,7 @@ cb_rstto_main_window_rotate_cw (GtkWidget *widget, RsttoMainWindow *window) rstto_image_viewer_set_orientation (viewer, RSTTO_IMAGE_ORIENT_NONE); break; } + rstto_main_window_update_statusbar(window); } /** @@ -2527,6 +2574,7 @@ cb_rstto_main_window_rotate_ccw (GtkWidget *widget, RsttoMainWindow *window) rstto_image_viewer_set_orientation (viewer, RSTTO_IMAGE_ORIENT_180); break; } + rstto_main_window_update_statusbar(window); } @@ -2546,6 +2594,7 @@ static void cb_rstto_main_window_first_image (GtkWidget *widget, RsttoMainWindow *window) { rstto_image_list_iter_set_position (window->priv->iter, 0); + rstto_main_window_update_statusbar(window); } @@ -2562,6 +2611,7 @@ cb_rstto_main_window_last_image (GtkWidget *widget, RsttoMainWindow *window) { guint n_images = rstto_image_list_get_n_images (window->priv->image_list); rstto_image_list_iter_set_position (window->priv->iter, n_images-1); + rstto_main_window_update_statusbar(window); } /** @@ -2576,6 +2626,7 @@ static void cb_rstto_main_window_next_image (GtkWidget *widget, RsttoMainWindow *window) { rstto_image_list_iter_next (window->priv->iter); + rstto_main_window_update_statusbar(window); } /** @@ -2590,6 +2641,7 @@ static void cb_rstto_main_window_previous_image (GtkWidget *widget, RsttoMainWindow *window) { rstto_image_list_iter_previous (window->priv->iter); + rstto_main_window_update_statusbar(window); } /**********************/ -- 1.7.5.4