Commit 7a3d3d21 authored by Paolo Bacchilega's avatar Paolo Bacchilega
Browse files

make the shrink wrap command work for the video viewer as well

parent 92dd8891
......@@ -238,7 +238,7 @@
<long> Possible values are: list, thumbnails.
</long>
</locale>
</schema>
</schema>
<!-- Viewer -->
......@@ -334,6 +334,19 @@
</locale>
</schema>
<schema>
<key>/schemas/apps/gthumb/viewer/shrink_wrap</key>
<applyto>/apps/gthumb/viewer/shrink_wrap</applyto>
<owner>gthumb</owner>
<type>bool</type>
<default>false</default>
<locale name="C">
<short></short>
<long> Whether to resize the window to fit the size of the image
</long>
</locale>
</schema>
<!-- UI -->
<schema>
......
......@@ -321,6 +321,16 @@ gth_file_viewer_page_real_update_info (GthViewerPage *base,
}
static void
gth_file_viewer_page_real_shrink_wrap (GthViewerPage *base,
gboolean value,
int *other_width,
int *other_height)
{
/* void */
}
static void
gth_file_viewer_page_finalize (GObject *obj)
{
......@@ -358,6 +368,7 @@ gth_viewer_page_interface_init (GthViewerPageInterface *iface)
iface->update_sensitivity = gth_file_viewer_page_real_update_sensitivity;
iface->can_save = gth_file_viewer_page_real_can_save;
iface->update_info = gth_file_viewer_page_real_update_info;
iface->shrink_wrap = gth_file_viewer_page_real_shrink_wrap;
}
......
......@@ -1281,6 +1281,20 @@ gth_media_viewer_page_real_update_info (GthViewerPage *base,
}
static void
gth_media_viewer_page_real_shrink_wrap (GthViewerPage *base,
gboolean value,
int *other_width,
int *other_height)
{
GthMediaViewerPage *self = GTH_MEDIA_VIEWER_PAGE (base);
if (! value || (other_width == NULL) || (other_height == NULL))
return;
*other_height += _gtk_widget_get_allocated_height (self->priv->mediabar);
}
static void
gth_media_viewer_page_finalize (GObject *obj)
{
......@@ -1336,6 +1350,7 @@ gth_viewer_page_interface_init (GthViewerPageInterface *iface)
iface->save_as = gth_media_viewer_page_real_save_as;
iface->revert = gth_media_viewer_page_real_revert;
iface->update_info = gth_media_viewer_page_real_update_info;
iface->shrink_wrap = gth_media_viewer_page_real_shrink_wrap;
}
......
......@@ -93,18 +93,5 @@
</locale>
</schema>
<schema>
<key>/schemas/apps/gthumb/viewer/shrink_wrap</key>
<applyto>/apps/gthumb/viewer/shrink_wrap</applyto>
<owner>gthumb</owner>
<type>bool</type>
<default>false</default>
<locale name="C">
<short></short>
<long> Whether to resize the window to fit the size of the image
</long>
</locale>
</schema>
</schemalist>
</gconfschemafile>
......@@ -27,7 +27,7 @@
#include "preferences.h"
#define GCONF_NOTIFICATIONS 8
#define GCONF_NOTIFICATIONS 7
static void gth_viewer_page_interface_init (GthViewerPageInterface *iface);
......@@ -55,7 +55,6 @@ struct _GthImageViewerPagePrivate {
guint hide_mouse_timeout;
guint motion_signal;
gboolean image_changed;
gboolean shrink_wrap;
GFile *last_loaded;
gboolean can_paste;
};
......@@ -73,11 +72,6 @@ static const char *image_viewer_ui_info =
" <menuitem action='ImageViewer_Edit_Paste_Image'/>"
" </placeholder>"
" </menu>"
" <menu name='View' action='ViewMenu'>"
" <placeholder name='View_Actions'>"
" <menuitem action='ImageViewer_View_ShrinkWrap'/>"
" </placeholder>"
" </menu>"
" </menubar>"
" <toolbar name='ViewerToolBar'>"
" <placeholder name='ViewerCommands'>"
......@@ -178,14 +172,6 @@ image_viewer_activate_action_edit_paste_image (GtkAction *action,
}
static void
image_viewer_activate_action_view_shrink_wrap (GtkAction *action,
GthImageViewerPage *self)
{
eel_gconf_set_boolean (PREF_VIEWER_SHRINK_WRAP, gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)));
}
static GtkActionEntry image_viewer_action_entries[] = {
{ "ImageViewer_Edit_Undo", GTK_STOCK_UNDO,
NULL, "<control>z",
......@@ -234,15 +220,6 @@ static GtkActionEntry image_viewer_action_entries[] = {
};
static GtkToggleActionEntry image_viewer_toggle_action_entries[] = {
{ "ImageViewer_View_ShrinkWrap", NULL,
N_("_Fit Window to Image"), "<control>e",
N_("Resize the window to the size of the image"),
G_CALLBACK (image_viewer_activate_action_view_shrink_wrap),
FALSE }
};
static void
gth_image_viewer_page_file_loaded (GthImageViewerPage *self,
gboolean success)
......@@ -435,8 +412,6 @@ image_preloader_requested_ready_cb (GthImagePreloader *preloader,
original_width,
original_height);
if (self->priv->shrink_wrap)
gth_image_viewer_page_shrink_wrap (self, TRUE);
gth_image_history_clear (self->priv->history);
gth_image_history_add_image (self->priv->history,
gth_image_viewer_get_current_image (GTH_IMAGE_VIEWER (self->priv->viewer)),
......@@ -561,18 +536,6 @@ pref_reset_scrollbars_changed (GConfClient *client,
}
static void
pref_viewer_shrink_wrap_changed (GConfClient *client,
guint cnxn_id,
GConfEntry *entry,
gpointer user_data)
{
GthImageViewerPage *self = user_data;
gth_image_viewer_page_shrink_wrap (self, eel_gconf_get_boolean (PREF_VIEWER_SHRINK_WRAP, FALSE));
}
static void
paint_comment_over_image_func (GthImageViewer *image_viewer,
cairo_t *cr,
......@@ -724,7 +687,6 @@ gth_image_viewer_page_real_activate (GthViewerPage *base,
GthBrowser *browser)
{
GthImageViewerPage *self;
GtkAction *action;
int i;
self = (GthImageViewerPage*) base;
......@@ -737,10 +699,6 @@ gth_image_viewer_page_real_activate (GthViewerPage *base,
image_viewer_action_entries,
G_N_ELEMENTS (image_viewer_action_entries),
self);
gtk_action_group_add_toggle_actions (self->priv->actions,
image_viewer_toggle_action_entries,
G_N_ELEMENTS (image_viewer_toggle_action_entries),
self);
gtk_ui_manager_insert_action_group (gth_browser_get_ui_manager (browser), self->priv->actions, 0);
self->priv->preloader = gth_browser_get_image_preloader (browser);
......@@ -762,11 +720,6 @@ gth_image_viewer_page_real_activate (GthViewerPage *base,
gth_image_viewer_set_black_background (GTH_IMAGE_VIEWER (self->priv->viewer), eel_gconf_get_boolean (PREF_BLACK_BACKGROUND, FALSE));
gth_image_viewer_set_reset_scrollbars (GTH_IMAGE_VIEWER (self->priv->viewer), eel_gconf_get_boolean (PREF_RESET_SCROLLBARS, TRUE));
self->priv->shrink_wrap = eel_gconf_get_boolean (PREF_VIEWER_SHRINK_WRAP, FALSE);
action = gtk_action_group_get_action (self->priv->actions, "ImageViewer_View_ShrinkWrap");
if (action != NULL)
g_object_set (action, "active", self->priv->shrink_wrap, NULL);
gtk_widget_show (self->priv->viewer);
g_signal_connect (G_OBJECT (self->priv->viewer),
......@@ -848,11 +801,6 @@ gth_image_viewer_page_real_activate (GthViewerPage *base,
PREF_RESET_SCROLLBARS,
pref_reset_scrollbars_changed,
self);
self->priv->cnxn_id[i++] = eel_gconf_notification_add (
PREF_VIEWER_SHRINK_WRAP,
pref_viewer_shrink_wrap_changed,
self);
}
......@@ -1374,6 +1322,17 @@ gth_image_viewer_page_real_show_properties (GthViewerPage *base,
}
static void
gth_image_viewer_page_real_shrink_wrap (GthViewerPage *base,
gboolean activate,
int *other_width,
int *other_height)
{
GthImageViewerPage *self = GTH_IMAGE_VIEWER_PAGE (base);
gth_image_viewer_set_fit_mode (GTH_IMAGE_VIEWER (self->priv->viewer), GTH_FIT_SIZE_IF_LARGER);
}
static void
gth_image_viewer_page_finalize (GObject *obj)
{
......@@ -1417,6 +1376,7 @@ gth_viewer_page_interface_init (GthViewerPageInterface *iface)
iface->revert = gth_image_viewer_page_real_revert;
iface->update_info = gth_image_viewer_page_real_update_info;
iface->show_properties = gth_image_viewer_page_real_show_properties;
iface->shrink_wrap = gth_image_viewer_page_real_shrink_wrap;
}
......@@ -1425,7 +1385,6 @@ gth_image_viewer_page_init (GthImageViewerPage *self)
{
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GTH_TYPE_IMAGE_VIEWER_PAGE, GthImageViewerPagePrivate);
self->priv->history = gth_image_history_new ();
self->priv->shrink_wrap = FALSE;
self->priv->last_loaded = NULL;
self->priv->image_changed = FALSE;
self->priv->can_paste = FALSE;
......@@ -1523,122 +1482,6 @@ gth_image_viewer_page_reset (GthImageViewerPage *self)
}
static int
add_non_content_width (GthImageViewerPage *self,
GtkWidget *non_content)
{
int width = 0;
if ((non_content != NULL) && gtk_widget_get_mapped (non_content)) {
GtkAllocation allocation;
gtk_widget_get_allocation (non_content, &allocation);
width = allocation.width;
}
return width;
}
static int
add_non_content_height (GthImageViewerPage *self,
GtkWidget *non_content)
{
int height = 0;
if ((non_content != NULL) && gtk_widget_get_mapped (non_content)) {
GtkAllocation allocation;
gtk_widget_get_allocation (non_content, &allocation);
height = allocation.height;
}
return height;
}
void
gth_image_viewer_page_shrink_wrap (GthImageViewerPage *self,
gboolean activate)
{
GthFileData *file_data;
int width;
int height;
double ratio;
int other_width;
int other_height;
GdkScreen *screen;
int max_width;
int max_height;
self->priv->shrink_wrap = activate;
if (! self->priv->shrink_wrap) {
int width;
int height;
if (gth_window_get_page_size (GTH_WINDOW (self->priv->browser),
GTH_BROWSER_PAGE_BROWSER,
&width,
&height))
{
gth_window_save_page_size (GTH_WINDOW (self->priv->browser), GTH_BROWSER_PAGE_VIEWER, width, height);
gth_window_apply_saved_size (GTH_WINDOW (self->priv->browser), GTH_BROWSER_PAGE_VIEWER);
}
else
gth_window_clear_saved_size (GTH_WINDOW (self->priv->browser), GTH_BROWSER_PAGE_VIEWER);
gth_image_viewer_set_fit_mode (GTH_IMAGE_VIEWER (self->priv->viewer), GTH_FIT_SIZE_IF_LARGER);
return;
}
file_data = gth_browser_get_current_file (self->priv->browser);
if (file_data == NULL)
return;
gth_image_viewer_get_original_size (GTH_IMAGE_VIEWER (self->priv->viewer), &width, &height);
if ((width <= 0) || (height <= 0))
return;
ratio = (double) width / height;
other_width = 0;
other_height = 0;
other_height += add_non_content_height (self, gth_window_get_area (GTH_WINDOW (self->priv->browser), GTH_WINDOW_MENUBAR));
other_height += add_non_content_height (self, gth_window_get_area (GTH_WINDOW (self->priv->browser), GTH_WINDOW_TOOLBAR));
other_height += add_non_content_height (self, gth_window_get_area (GTH_WINDOW (self->priv->browser), GTH_WINDOW_STATUSBAR));
other_height += add_non_content_height (self, gth_browser_get_viewer_toolbar (self->priv->browser));
if (eel_gconf_get_enum (PREF_UI_VIEWER_THUMBNAILS_ORIENT, GTK_TYPE_ORIENTATION, GTK_ORIENTATION_HORIZONTAL) == GTK_ORIENTATION_HORIZONTAL)
other_height += add_non_content_height (self, gth_browser_get_thumbnail_list (self->priv->browser));
else
other_width += add_non_content_width (self, gth_browser_get_thumbnail_list (self->priv->browser));
other_width += add_non_content_width (self, gth_browser_get_viewer_sidebar (self->priv->browser));
other_width += 2;
other_height += 2;
screen = gtk_widget_get_screen (GTK_WIDGET (self->priv->browser));
max_width = round ((double) gdk_screen_get_width (screen) * 8.5 / 10.0);
max_height = round ((double) gdk_screen_get_height (screen) * 8.5 / 10.0);
if (width + other_width > max_width) {
width = max_width - other_width;
height = width / ratio;
}
if (height + other_height > max_height) {
height = max_height - other_height;
width = height * ratio;
}
gth_window_save_page_size (GTH_WINDOW (self->priv->browser),
GTH_BROWSER_PAGE_VIEWER,
width + other_width,
height + other_height);
if (gth_window_get_current_page (GTH_WINDOW (self->priv->browser)) == GTH_BROWSER_PAGE_VIEWER)
gth_window_apply_saved_size (GTH_WINDOW (self->priv->browser), GTH_BROWSER_PAGE_VIEWER);
gth_image_viewer_set_fit_mode (GTH_IMAGE_VIEWER (self->priv->viewer), GTH_FIT_SIZE_IF_LARGER);
}
void
gth_image_viewer_page_copy_image (GthImageViewerPage *self)
{
......
......@@ -60,8 +60,6 @@ void gth_image_viewer_page_undo (GthImageViewerPage *
void gth_image_viewer_page_redo (GthImageViewerPage *page);
GthImageHistory * gth_image_viewer_page_get_history (GthImageViewerPage *self);
void gth_image_viewer_page_reset (GthImageViewerPage *self);
void gth_image_viewer_page_shrink_wrap (GthImageViewerPage *self,
gboolean activate);
void gth_image_viewer_page_copy_image (GthImageViewerPage *self);
void gth_image_viewer_page_paste_image (GthImageViewerPage *self);
......
......@@ -332,6 +332,14 @@ gth_browser_activate_action_viewer_tools (GtkAction *action,
}
void
gth_browser_activate_action_view_shrink_wrap (GtkAction *action,
GthBrowser *browser)
{
gth_browser_set_shrink_wrap_viewer (GTH_BROWSER (browser), gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)));
}
void
gth_browser_activate_action_edit_select_all (GtkAction *action,
GthBrowser *browser)
......
......@@ -64,5 +64,6 @@ DEFINE_ACTION(gth_browser_activate_action_view_next)
DEFINE_ACTION(gth_browser_activate_action_view_prev)
DEFINE_ACTION(gth_browser_activate_action_viewer_properties)
DEFINE_ACTION(gth_browser_activate_action_viewer_tools)
DEFINE_ACTION(gth_browser_activate_action_view_shrink_wrap)
#endif /* GTH_BROWSER_ACTIONS_CALLBACK_H */
......@@ -241,6 +241,11 @@ static GtkToggleActionEntry gth_browser_action_toggle_entries[] = {
N_("Edit file"),
G_CALLBACK (gth_browser_activate_action_viewer_tools),
FALSE },
{ "View_ShrinkWrap", NULL,
N_("_Fit Window to Image"), "<control>e",
N_("Resize the window to the size of the image"),
G_CALLBACK (gth_browser_activate_action_view_shrink_wrap),
FALSE },
};
#endif /* GTH_BROWSER_ACTION_ENTRIES_H */
......@@ -242,6 +242,9 @@ static const char *viewer_ui_info =
" <placeholder name='View_Bars'>"
" <menuitem action='View_Thumbnail_List'/>"
" </placeholder>"
" <placeholder name='View_Actions'>"
" <menuitem action='View_ShrinkWrap'/>"
" </placeholder>"
" <placeholder name='Folder_Actions'>"
" <menuitem action='View_BrowserMode'/>"
" </placeholder>"
......
......@@ -20,6 +20,7 @@
*/
#include <config.h>
#include <math.h>
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include "dlg-personalize-filters.h"
......@@ -166,6 +167,7 @@ struct _GthBrowserPrivate {
gboolean properties_on_screen;
char *location_free_space;
gboolean recalc_location_free_space;
gboolean shrink_wrap_viewer;
/* fulscreen */
......@@ -4115,6 +4117,7 @@ gth_browser_init (GthBrowser *browser)
browser->priv->back_history_menu = NULL;
browser->priv->forward_history_menu = NULL;
browser->priv->go_parent_menu = NULL;
browser->priv->shrink_wrap_viewer = FALSE;
{
int width;
......@@ -4530,6 +4533,9 @@ gth_browser_init (GthBrowser *browser)
browser->priv->show_hidden_files = eel_gconf_get_boolean (PREF_SHOW_HIDDEN_FILES, FALSE);
_gth_browser_set_action_active (browser, "View_ShowHiddenFiles", browser->priv->show_hidden_files);
browser->priv->shrink_wrap_viewer = eel_gconf_get_boolean (PREF_SHRINK_WRAP_VIEWER, FALSE);
_gth_browser_set_action_active (browser, "View_ShrinkWrap", browser->priv->shrink_wrap_viewer);
browser->priv->fast_file_type = eel_gconf_get_boolean (PREF_FAST_FILE_TYPE, TRUE);
gth_hook_invoke ("gth-browser-construct", browser);
......@@ -5453,6 +5459,9 @@ file_metadata_ready_cb (GList *files,
g_file_info_copy_into (file_data->info, browser->priv->current_file->info);
g_file_info_set_attribute_boolean (browser->priv->current_file->info, "gth::file::is-modified", FALSE);
if (browser->priv->shrink_wrap_viewer)
gth_browser_set_shrink_wrap_viewer (browser, TRUE);
if ((gth_window_get_current_page (GTH_WINDOW (browser)) == GTH_BROWSER_PAGE_BROWSER)
&& ! gtk_widget_get_visible (browser->priv->file_properties))
{
......@@ -5729,6 +5738,90 @@ gth_browser_show_viewer_tools (GthBrowser *browser,
}
void
gth_browser_set_shrink_wrap_viewer (GthBrowser *browser,
gboolean value)
{
int width;
int height;
double ratio;
int other_width;
int other_height;
GdkScreen *screen;
int max_width;
int max_height;
browser->priv->shrink_wrap_viewer = value;
eel_gconf_set_boolean (PREF_SHRINK_WRAP_VIEWER, browser->priv->shrink_wrap_viewer);
if (browser->priv->viewer_page == NULL)
return;
if (! browser->priv->shrink_wrap_viewer) {
if (gth_window_get_page_size (GTH_WINDOW (browser),
GTH_BROWSER_PAGE_BROWSER,
&width,
&height))
{
gth_window_save_page_size (GTH_WINDOW (browser), GTH_BROWSER_PAGE_VIEWER, width, height);
gth_window_apply_saved_size (GTH_WINDOW (browser), GTH_BROWSER_PAGE_VIEWER);
}
else
gth_window_clear_saved_size (GTH_WINDOW (browser), GTH_BROWSER_PAGE_VIEWER);
gth_viewer_page_shrink_wrap (browser->priv->viewer_page, FALSE, NULL, NULL);
return;
}
if (browser->priv->current_file == NULL)
return;
width = g_file_info_get_attribute_int32 (browser->priv->current_file->info, "frame::width");
height = g_file_info_get_attribute_int32 (browser->priv->current_file->info, "frame::height");
if ((width <= 0) || (height <= 0))
return;
ratio = (double) width / height;
other_width = 0;
other_height = 0;
other_height += _gtk_widget_get_allocated_height (gth_window_get_area (GTH_WINDOW (browser), GTH_WINDOW_MENUBAR));
other_height += _gtk_widget_get_allocated_height (gth_window_get_area (GTH_WINDOW (browser), GTH_WINDOW_TOOLBAR));
other_height += _gtk_widget_get_allocated_height (gth_window_get_area (GTH_WINDOW (browser), GTH_WINDOW_STATUSBAR));
other_height += _gtk_widget_get_allocated_height (gth_browser_get_viewer_toolbar (browser));
if (eel_gconf_get_enum (PREF_UI_VIEWER_THUMBNAILS_ORIENT, GTK_TYPE_ORIENTATION, GTK_ORIENTATION_HORIZONTAL) == GTK_ORIENTATION_HORIZONTAL)
other_height += _gtk_widget_get_allocated_height (gth_browser_get_thumbnail_list (browser));
else
other_width += _gtk_widget_get_allocated_width (gth_browser_get_thumbnail_list (browser));
other_width += _gtk_widget_get_allocated_width (gth_browser_get_viewer_sidebar (browser));
other_width += 2;
other_height += 2;
gth_viewer_page_shrink_wrap (browser->priv->viewer_page, TRUE, &other_width, &other_height);
screen = gtk_widget_get_screen (GTK_WIDGET (browser));
max_width = round ((double) gdk_screen_get_width (screen) * 8.5 / 10.0);
max_height = round ((double) gdk_screen_get_height (screen) * 8.5 / 10.0);
if (width + other_width > max_width) {
width = max_width - other_width;
height = width / ratio;
}
if (height + other_height > max_height) {
height = max_height - other_height;
width = height * ratio;
}
gth_window_save_page_size (GTH_WINDOW (browser),
GTH_BROWSER_PAGE_VIEWER,
width + other_width,
height + other_height);
if (gth_window_get_current_page (GTH_WINDOW (browser)) == GTH_BROWSER_PAGE_VIEWER)
gth_window_apply_saved_size (GTH_WINDOW (browser), GTH_BROWSER_PAGE_VIEWER);
}
/* -- gth_browser_load_location -- */
......
......@@ -163,6 +163,8 @@ void gth_browser_show_viewer_properties (GthBrowser *browser,
gboolean show);
void gth_browser_show_viewer_tools (GthBrowser *browser,
gboolean show);
void gth_browser_set_shrink_wrap_viewer (GthBrowser *browser,
gboolean value);
void gth_browser_load_location (GthBrowser *browser,
GFile *location);
void gth_browser_enable_thumbnails (GthBrowser *browser,
......
......@@ -59,6 +59,7 @@ G_BEGIN_DECLS
#define PREF_CHECK_TYPE "/apps/gthumb/viewer/check_type"
#define PREF_CHECK_SIZE "/apps/gthumb/viewer/check_size"
#define PREF_BLACK_BACKGROUND "/apps/gthumb/viewer/black_background"
#define PREF_SHRINK_WRAP_VIEWER "/apps/gthumb/viewer/shrink_wrap"
#define PREF_UI_TOOLBAR_STYLE "/apps/gthumb/ui/toolbar_style"
#define PREF_UI_WINDOW_WIDTH "/apps/gthumb/ui/window_width"
......
......@@ -190,6 +190,17 @@ gth_viewer_page_show_properties (GthViewerPage *self,
}
void
gth_viewer_page_shrink_wrap (GthViewerPage *self,
gboolean value,
int *other_width,
int *other_height)
{
if (GTH_VIEWER_PAGE_GET_INTERFACE (self)->shrink_wrap != NULL)
GTH_VIEWER_PAGE_GET_INTERFACE (self)->shrink_wrap (self, value, other_width, other_height);
}