Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
openSUSE:13.2:Update
viewnior
viewnior-1.4-print.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File viewnior-1.4-print.patch of Package viewnior
Index: viewnior-1.4/configure.ac =================================================================== --- viewnior-1.4.orig/configure.ac +++ viewnior-1.4/configure.ac @@ -54,6 +54,7 @@ EXIV2_REQUIRED=0.21 VNR_MODULES="gtk+-2.0 >= $GTK_REQUIRED \ + gtk+-unix-print-2.0 >= $GTK_REQUIRED \ glib-2.0 >= $GLIB_REQUIRED \ gio-2.0 >= $GLIB_REQUIRED \ shared-mime-info >= $SHARED_MIME_INFO_REQUIRED \ Index: viewnior-1.4/src/vnr-prefs.c =================================================================== --- viewnior-1.4.orig/src/vnr-prefs.c +++ viewnior-1.4/src/vnr-prefs.c @@ -168,6 +168,8 @@ vnr_prefs_set_default(VnrPrefs *prefs) prefs->start_slideshow = FALSE; prefs->start_fullscreen = FALSE; prefs->auto_resize = FALSE; + prefs->page_setup = NULL; + prefs->print_settings = NULL; } static GtkWidget * @@ -368,6 +370,9 @@ vnr_prefs_load (VnrPrefs *prefs) prefs->jpeg_quality = g_key_file_get_integer (conf, "prefs", "jpeg-quality", &error); prefs->png_compression = g_key_file_get_integer (conf, "prefs", "png-compression", &error); + prefs->page_setup = gtk_page_setup_new_from_key_file (conf, NULL, NULL); + prefs->print_settings = gtk_print_settings_new_from_key_file (conf, NULL, NULL); + if(error != NULL) { g_warning("Parsing config file: %s. All preferences are set to their default values.", error->message); @@ -457,6 +462,11 @@ vnr_prefs_save (VnrPrefs *prefs) g_key_file_set_integer (conf, "prefs", "jpeg-quality", prefs->jpeg_quality); g_key_file_set_integer (conf, "prefs", "png-compression", prefs->png_compression); + if (prefs->page_setup) + gtk_page_setup_to_key_file (prefs->page_setup, conf, NULL); + if (prefs->print_settings) + gtk_print_settings_to_key_file (prefs->print_settings, conf, NULL); + if(g_mkdir_with_parents (dir, 0700) != 0) g_warning("Error creating config file's parent directory (%s)\n", dir); Index: viewnior-1.4/src/vnr-prefs.h =================================================================== --- viewnior-1.4.orig/src/vnr-prefs.h +++ viewnior-1.4/src/vnr-prefs.h @@ -98,6 +98,9 @@ struct _VnrPrefs { GtkWidget *vnr_win; GtkSpinButton *slideshow_timeout_widget; + + GtkPrintSettings *print_settings; + GtkPageSetup *page_setup; }; struct _VnrPrefsClass { Index: viewnior-1.4/src/vnr-window.c =================================================================== --- viewnior-1.4.orig/src/vnr-window.c +++ viewnior-1.4/src/vnr-window.c @@ -25,6 +25,7 @@ #include <glib/gstdio.h> #include <gtk/gtk.h> #include <gdk/gdkkeysyms.h> +#include <gtk/gtkunixprint.h> #include <errno.h> #include <sys/wait.h> #include "vnr-window.h" @@ -125,6 +126,9 @@ const gchar *ui_definition = "<ui>" "<menuitem action=\"FileReload\"/>" "<menuitem action=\"FileProperties\"/>" "<separator/>" + "<menuitem action=\"FilePageSetup\"/>" + "<menuitem action=\"FilePrint\"/>" + "<separator/>" "<menu action=\"Edit\">" "<menuitem action=\"FileDelete\"/>" "<separator/>" @@ -169,6 +173,8 @@ const gchar *ui_definition = "<ui>" "<separator/>" "<toolitem action=\"ImageRotateCCW\"/>" "<toolitem action=\"ImageRotateCW\"/>" + "<separator/>" + "<toolitem action=\"FilePrint\"/>" "<separator expand=\"true\"/>" "<toolitem action=\"Properties\"/>" "</toolbar>" @@ -190,6 +196,8 @@ const gchar *ui_definition = "<ui>" "<menuitem name=\"Fullscreen\" action=\"ViewFullscreen\"/>" "<separator/>" "<menuitem action=\"FileProperties\"/>" + "<separator/>" + "<menuitem action=\"FilePrint\"/>" "</popup>" "<accelerator name=\"ControlEqualAccel\" action=\"ControlEqual\"/>" "<accelerator name=\"ControlKPAddAccel\" action=\"ControlKpAdd\"/>" @@ -1021,6 +1029,51 @@ vnr_window_cmd_main_menu_hidden (GtkWidg } static void +draw_page_cb (GtkPrintOperation * oper, + GtkPrintContext * context, + gint nr, VnrWindow *window) +{ + cairo_t *cr; + GdkPixbuf *source_pixbuf; + + cr = gtk_print_context_get_cairo_context (context); + + source_pixbuf = UNI_IMAGE_VIEW (window->view)->pixbuf; + + if (source_pixbuf) + { + GdkPixbuf *pixbuf; + guint iw, ih; + gdouble pw, ph; + gdouble factor; + + /* scale image to page size */ + pw = gtk_page_setup_get_paper_width (window->prefs->page_setup, GTK_UNIT_POINTS) + - gtk_page_setup_get_left_margin (window->prefs->page_setup, GTK_UNIT_POINTS) + - gtk_page_setup_get_right_margin (window->prefs->page_setup, GTK_UNIT_POINTS); + ph = gtk_page_setup_get_paper_height (window->prefs->page_setup, GTK_UNIT_POINTS) + - gtk_page_setup_get_top_margin (window->prefs->page_setup, GTK_UNIT_POINTS) + - gtk_page_setup_get_bottom_margin (window->prefs->page_setup, GTK_UNIT_POINTS); + + iw = gdk_pixbuf_get_width (source_pixbuf); + ih = gdk_pixbuf_get_height (source_pixbuf); + + factor = MIN (pw / iw, ph / ih); + factor = (factor > 1.0) ? 1.0 : factor; + + pixbuf = gdk_pixbuf_scale_simple (source_pixbuf, + iw * factor, ih * factor, + GDK_INTERP_HYPER); + + /* add image to surface */ + gdk_cairo_set_source_pixbuf (cr, pixbuf, 0.0, 0.0); + cairo_paint (cr); + + g_object_unref (pixbuf); + } +} + +static void leave_fs_cb (GtkButton *button, VnrWindow *window) { vnr_window_unfullscreen (window); @@ -1380,6 +1433,65 @@ vnr_window_cmd_about (GtkAction *action, } static void +vnr_window_cmd_page_setup (GtkAction *action, VnrWindow *window) +{ + GtkWidget *dlg; + + dlg = gtk_page_setup_unix_dialog_new(_("Page settings"), GTK_WINDOW(window)); + if (window->prefs->page_setup) + gtk_page_setup_unix_dialog_set_page_setup(GTK_PAGE_SETUP_UNIX_DIALOG(dlg), + window->prefs->page_setup); + if (window->prefs->print_settings) + gtk_page_setup_unix_dialog_set_print_settings(GTK_PAGE_SETUP_UNIX_DIALOG(dlg), + window->prefs->print_settings); + if (gtk_dialog_run (GTK_DIALOG (dlg)) == 0) + { + window->prefs->page_setup = gtk_page_setup_unix_dialog_get_page_setup + (GTK_PAGE_SETUP_UNIX_DIALOG (dlg)); + window->prefs->print_settings = gtk_page_setup_unix_dialog_get_print_settings + (GTK_PAGE_SETUP_UNIX_DIALOG (dlg)); + } + gtk_widget_destroy (dlg); +} + +static void +vnr_window_cmd_print (GtkAction *action, VnrWindow *window) +{ + GtkPrintOperation *op; + + op = gtk_print_operation_new (); + + if (!window->prefs->page_setup) + { + GtkPaperSize *size = gtk_paper_size_new (GTK_PAPER_NAME_A4); + + window->prefs->page_setup = gtk_page_setup_new (); + + gtk_page_setup_set_paper_size (window->prefs->page_setup, size); + gtk_page_setup_set_top_margin (window->prefs->page_setup, 0.5, GTK_UNIT_INCH); + gtk_page_setup_set_bottom_margin (window->prefs->page_setup, 0.5, GTK_UNIT_INCH); + gtk_page_setup_set_left_margin (window->prefs->page_setup, 0.5, GTK_UNIT_INCH); + gtk_page_setup_set_right_margin (window->prefs->page_setup, 0.5, GTK_UNIT_INCH); + gtk_page_setup_set_orientation (window->prefs->page_setup, GTK_PAGE_ORIENTATION_LANDSCAPE); + + gtk_paper_size_free (size); + } + if (!window->prefs->print_settings) + window->prefs->print_settings = gtk_print_settings_new (); + + gtk_print_operation_set_n_pages (op, 1); + gtk_print_operation_set_default_page_setup (op, window->prefs->page_setup); + gtk_print_operation_set_print_settings (op, window->prefs->print_settings); + + g_signal_connect (G_OBJECT (op), "draw-page", G_CALLBACK (draw_page_cb), window); + + gtk_print_operation_run (op, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, + GTK_WINDOW (window), NULL); + + g_object_unref (op); +} + +static void vnr_set_wallpaper(GtkAction *action, VnrWindow *win) { pid_t pid; @@ -1742,6 +1854,15 @@ static const GtkActionEntry action_entri G_CALLBACK (vnr_window_cmd_preferences) } }; +static const GtkActionEntry action_entries_print[] = { + { "FilePageSetup", GTK_STOCK_PAGE_SETUP, N_("Page Setup"), NULL, + N_("Set printer page settings"), + G_CALLBACK (vnr_window_cmd_page_setup) }, + { "FilePrint", GTK_STOCK_PRINT, N_("_Print"), "<control>P", + N_("Print current image"), + G_CALLBACK (vnr_window_cmd_print) } +}; + static const GtkActionEntry action_entry_save[] = { { "FileSave", GTK_STOCK_SAVE, N_("_Save"), "<control>S", N_("Save changes"), @@ -2065,6 +2186,20 @@ vnr_window_init (VnrWindow * window) gtk_ui_manager_insert_action_group (window->ui_mngr, window->action_properties, 0); + window->actions_print = gtk_action_group_new("MenuActionPrint"); + + + gtk_action_group_set_translation_domain (window->actions_print, + GETTEXT_PACKAGE); + + gtk_action_group_add_actions (window->actions_print, + action_entries_print, + G_N_ELEMENTS (action_entries_print), + window); + + gtk_ui_manager_insert_action_group (window->ui_mngr, + window->actions_print, 0); + window->actions_static_image = gtk_action_group_new("MenuActionsStaticImage"); @@ -2163,6 +2298,7 @@ vnr_window_init (VnrWindow * window) gtk_action_group_set_sensitive(window->actions_image, FALSE); gtk_action_group_set_sensitive(window->actions_static_image, FALSE); gtk_action_group_set_sensitive(window->action_save, FALSE); + gtk_action_group_set_sensitive(window->actions_print, FALSE); gtk_action_group_set_sensitive(window->actions_bars, TRUE); /* Continue with layout */ @@ -2342,9 +2478,15 @@ vnr_window_open (VnrWindow * window, gbo /* Return TRUE if the image is static */ if ( uni_anim_view_set_anim (UNI_ANIM_VIEW (window->view), pixbuf) ) + { + gtk_action_group_set_sensitive(window->actions_print, TRUE); gtk_action_group_set_sensitive(window->actions_static_image, TRUE); + } else + { + gtk_action_group_set_sensitive(window->actions_print, FALSE); gtk_action_group_set_sensitive(window->actions_static_image, FALSE); + } if(window->mode != VNR_WINDOW_MODE_NORMAL && window->prefs->fit_on_fullscreen) { @@ -2436,6 +2578,7 @@ vnr_window_close(VnrWindow *window) { gtk_window_set_title (GTK_WINDOW (window), "Viewnior"); uni_anim_view_set_anim (UNI_ANIM_VIEW (window->view), NULL); + gtk_action_group_set_sensitive(window->actions_print, FALSE); gtk_action_group_set_sensitive(window->actions_image, FALSE); gtk_action_group_set_sensitive(window->action_wallpaper, FALSE); gtk_action_group_set_sensitive(window->actions_static_image, FALSE); Index: viewnior-1.4/src/vnr-window.h =================================================================== --- viewnior-1.4.orig/src/vnr-window.h +++ viewnior-1.4/src/vnr-window.h @@ -53,6 +53,7 @@ struct _VnrWindow { GtkActionGroup *actions_static_image; GtkActionGroup *actions_collection; GtkActionGroup *action_save; + GtkActionGroup *actions_print; GtkActionGroup *action_properties; GtkActionGroup *actions_bars; GtkActionGroup *actions_open_with;
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor