X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;f=shell%2Fev-utils.c;h=8c9bae5501617027009d9be62379e668bc136ad4;hb=d3bc7b9497f6205eaa0c6dece068caff6411ce8c;hp=90217262f3dbc2a16041d07346affbfd4fa5ee21;hpb=13a06349251874bd35d2f03c3fc93217cee749a2;p=evince.git diff --git a/shell/ev-utils.c b/shell/ev-utils.c index 90217262..8c9bae55 100644 --- a/shell/ev-utils.c +++ b/shell/ev-utils.c @@ -14,7 +14,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * */ @@ -25,8 +25,7 @@ #include #include - -#define PRINT_CONFIG_FILENAME "ev-print-config.xml" +#include typedef struct { @@ -188,9 +187,8 @@ ev_pixbuf_add_shadow (GdkPixbuf *src, int size, * the region code. */ void -ev_print_region_contents (GdkRegion *region) +ev_print_region_contents (cairo_region_t *region) { - GdkRectangle *rectangles = NULL; gint n_rectangles, i; if (region == NULL) { @@ -199,111 +197,21 @@ ev_print_region_contents (GdkRegion *region) } g_print ("\n", region); - gdk_region_get_rectangles (region, &rectangles, &n_rectangles); + n_rectangles = cairo_region_num_rectangles (region); 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); -} - -#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"); + GdkRectangle rect; - 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; - else if (!strcmp ((const gchar *)transport, "PAPI")) - 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 (); + cairo_region_get_rectangle (region, i, &rect); + g_print ("\t(%d %d, %d %d) [%dx%d]\n", + rect.x, + rect.y, + rect.x + rect.width, + rect.y + rect.height, + rect.width, + rect.height); } - - 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); - - g_file_set_contents (file_name, str, -1, NULL); - - g_free (file_name); - g_free (str); -} -#endif /* WITH_GNOME_PRINT */ - static void ev_gui_sanitise_popup_position (GtkMenu *menu, GtkWidget *widget, @@ -317,7 +225,7 @@ ev_gui_sanitise_popup_position (GtkMenu *menu, g_return_if_fail (widget != NULL); - gtk_widget_size_request (GTK_WIDGET (menu), &req); + gtk_widget_get_preferred_size (GTK_WIDGET (menu), &req, NULL); monitor_num = gdk_screen_get_monitor_at_point (screen, *x, *y); gtk_menu_set_monitor (menu, monitor_num); @@ -340,16 +248,18 @@ ev_gui_menu_position_tree_selection (GtkMenu *menu, GtkTreeView *tree_view = GTK_TREE_VIEW (user_data); GtkWidget *widget = GTK_WIDGET (user_data); GtkRequisition req; + GtkAllocation allocation; GdkRectangle visible; - gtk_widget_size_request (GTK_WIDGET (menu), &req); - gdk_window_get_origin (widget->window, x, y); + gtk_widget_get_preferred_size (GTK_WIDGET (menu), &req, NULL); + gdk_window_get_origin (gtk_widget_get_window (widget), x, y); + gtk_widget_get_allocation (widget, &allocation); - *x += (widget->allocation.width - req.width) / 2; + *x += (allocation.width - req.width) / 2; /* Add on height for the treeview title */ gtk_tree_view_get_visible_rect (tree_view, &visible); - *y += widget->allocation.height - visible.height; + *y += allocation.height - visible.height; selection = gtk_tree_view_get_selection (tree_view); selected_rows = gtk_tree_selection_get_selected_rows (selection, &model); @@ -369,3 +279,111 @@ ev_gui_menu_position_tree_selection (GtkMenu *menu, ev_gui_sanitise_popup_position (menu, widget, x, y); } +/** + * get_num_monitors: Get the number of user monitors. + * @window: optional GtkWindow to look at. + * + * Returns: Number of monitors, -1 if uncertain situation (like multiple screens) + */ +gint +get_num_monitors (GtkWindow *window) +{ + GdkDisplay *display; + GdkScreen *screen; + gint num_screen; + + display = gdk_display_get_default (); + num_screen = gdk_display_get_n_screens (display); + + if (num_screen != 1) + return -1; + + if (window) + screen = gtk_window_get_screen (window); + else + screen = gdk_display_get_screen (display, 0); + + return gdk_screen_get_n_monitors (screen); +} + +void +file_chooser_dialog_add_writable_pixbuf_formats (GtkFileChooser *chooser) +{ + GSList *pixbuf_formats = NULL; + GSList *iter; + GtkFileFilter *filter; + int i; + + filter = gtk_file_filter_new(); + gtk_file_filter_set_name (filter, _("By extension")); + g_object_set_data (G_OBJECT(filter), "pixbuf-format", NULL); + gtk_file_chooser_add_filter (chooser, filter); + + pixbuf_formats = gdk_pixbuf_get_formats (); + + for (iter = pixbuf_formats; iter; iter = iter->next) { + GdkPixbufFormat *format = iter->data; + + gchar *description, *name, *extensions; + gchar **extension_list, **mime_types; + + if (gdk_pixbuf_format_is_disabled (format) || + !gdk_pixbuf_format_is_writable (format)) + continue; + + name = gdk_pixbuf_format_get_description (format); + extension_list = gdk_pixbuf_format_get_extensions (format); + extensions = g_strjoinv (", ", extension_list); + g_strfreev (extension_list); + description = g_strdup_printf ("%s (%s)", name, extensions); + + filter = gtk_file_filter_new (); + gtk_file_filter_set_name (filter, description); + g_object_set_data (G_OBJECT (filter), "pixbuf-format", format); + gtk_file_chooser_add_filter (chooser, filter); + + g_free (description); + g_free (extensions); + g_free (name); + + mime_types = gdk_pixbuf_format_get_mime_types (format); + for (i = 0; mime_types[i] != 0; i++) + gtk_file_filter_add_mime_type (filter, mime_types[i]); + g_strfreev (mime_types); + } + + g_slist_free (pixbuf_formats); +} + +GdkPixbufFormat* +get_gdk_pixbuf_format_by_extension (gchar *uri) +{ + GSList *pixbuf_formats = NULL; + GSList *iter; + int i; + + pixbuf_formats = gdk_pixbuf_get_formats (); + + for (iter = pixbuf_formats; iter; iter = iter->next) { + gchar **extension_list; + GdkPixbufFormat *format = iter->data; + + if (gdk_pixbuf_format_is_disabled (format) || + !gdk_pixbuf_format_is_writable (format)) + continue; + + extension_list = gdk_pixbuf_format_get_extensions (format); + + for (i = 0; extension_list[i] != 0; i++) { + if (g_str_has_suffix (uri, extension_list[i])) { + g_slist_free (pixbuf_formats); + g_strfreev (extension_list); + return format; + } + } + g_strfreev (extension_list); + } + + g_slist_free (pixbuf_formats); + return NULL; +}