X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;ds=sidebyside;f=shell%2Fev-utils.c;h=3dc849c733a030c32ee6d76620238c2cba8ed46e;hb=edd02df64f3999aeddeb2d526df0caf546ebdc87;hp=587dd73664e914392582d1fc5c479beced82f1f0;hpb=5cc8e92ad9fb04792682b474a670aaa803666f78;p=evince.git diff --git a/shell/ev-utils.c b/shell/ev-utils.c index 587dd736..3dc849c7 100644 --- a/shell/ev-utils.c +++ b/shell/ev-utils.c @@ -18,9 +18,14 @@ * */ +#include + #include "ev-utils.h" +#include "ev-file-helpers.h" #include +#define PRINT_CONFIG_FILENAME "ev-print-config.xml" + typedef struct { int size; @@ -177,6 +182,35 @@ ev_pixbuf_add_shadow (GdkPixbuf *src, int size, } +/* Simple function to output the contents of a region. Used solely for testing + * the region code. + */ +void +ev_print_region_contents (GdkRegion *region) +{ + GdkRectangle *rectangles = NULL; + gint n_rectangles, i; + + if (region == NULL) { + g_print ("\n"); + return; + } + + g_print ("\n", region); + gdk_region_get_rectangles (region, &rectangles, &n_rectangles); + for (i = 0; i < n_rectangles; i++) { + g_print ("\t(%d %d, %d %d) [%dx%d]\n", + rectangles[i].x, + rectangles[i].y, + rectangles[i].x + rectangles[i].width, + rectangles[i].y + rectangles[i].height, + rectangles[i].width, + rectangles[i].height); + } + g_free (rectangles); +} + + #ifndef HAVE_G_FILE_SET_CONTENTS #include @@ -184,6 +218,7 @@ ev_pixbuf_add_shadow (GdkPixbuf *src, int size, #include #include #include +#include static gboolean rename_file (const char *old_name, @@ -211,8 +246,6 @@ set_umask_permissions (int fd, * the umask in between the getting and the setting of the umask. * So we have to do the whole thing in a child process. */ - - int save_errno; pid_t pid; pid = fork (); @@ -247,9 +280,7 @@ set_umask_permissions (int fd, if (WIFEXITED (status)) { - save_errno = WEXITSTATUS (status); - - if (save_errno == 0) + if (WEXITSTATUS (status) == 0) { return TRUE; } @@ -280,7 +311,6 @@ write_to_temp_file (const gchar *contents, gchar *retval; FILE *file; gint fd; - int save_errno; retval = NULL; @@ -347,7 +377,7 @@ write_to_temp_file (const gchar *contents, return retval; } -gboolean +static gboolean ev_file_set_contents (const gchar *filename, const gchar *contents, gssize length, @@ -390,3 +420,98 @@ ev_file_set_contents (const gchar *filename, #endif /* HAVE_G_FILE_SET_CONTENTS */ +#ifdef WITH_GNOME_PRINT +gboolean +using_pdf_printer (GnomePrintConfig *config) +{ + const guchar *driver; + + driver = gnome_print_config_get ( + config, (const guchar *)"Settings.Engine.Backend.Driver"); + + if (driver) { + if (!strcmp ((const gchar *)driver, "gnome-print-pdf")) + return TRUE; + else + return FALSE; + } + + return FALSE; +} + +gboolean +using_postscript_printer (GnomePrintConfig *config) +{ + const guchar *driver; + const guchar *transport; + + driver = gnome_print_config_get ( + config, (const guchar *)"Settings.Engine.Backend.Driver"); + + transport = gnome_print_config_get ( + config, (const guchar *)"Settings.Transport.Backend"); + + if (driver) { + if (!strcmp ((const gchar *)driver, "gnome-print-ps")) + return TRUE; + else + return FALSE; + } else if (transport) { /* these transports default to PostScript */ + if (!strcmp ((const gchar *)transport, "CUPS")) + return TRUE; + else if (!strcmp ((const gchar *)transport, "LPD")) + return TRUE; + } + + return FALSE; +} + +GnomePrintConfig * +load_print_config_from_file (void) +{ + GnomePrintConfig *print_config = NULL; + char *file_name, *contents = NULL; + + file_name = g_build_filename (ev_dot_dir (), PRINT_CONFIG_FILENAME, + NULL); + + if (g_file_get_contents (file_name, &contents, NULL, NULL)) { + print_config = gnome_print_config_from_string (contents, 0); + g_free (contents); + } + + if (print_config == NULL) { + print_config = gnome_print_config_default (); + } + + g_free (file_name); + + return print_config; +} + +void +save_print_config_to_file (GnomePrintConfig *config) +{ + char *file_name, *str; + + g_return_if_fail (config != NULL); + + str = gnome_print_config_to_string (config, 0); + if (str == NULL) return; + + file_name = g_build_filename (ev_dot_dir (), + PRINT_CONFIG_FILENAME, + NULL); + +#ifdef HAVE_G_FILE_SET_CONTENTS + g_file_set_contents (file_name, str, -1, NULL); +#else + ev_file_set_contents (file_name, str, -1, NULL); +#endif + + g_free (file_name); + g_free (str); +} +#endif /* WITH_GNOME_PRINT */ + +