From bf633168e504e4e3c4ca7d7f3c9ee24d8d1d5781 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Wed, 22 Dec 2004 19:36:46 +0000 Subject: Remove unused utils 2004-12-22 Marco Pesenti Gritti * ps/ggvutils.c: (ggv_file_readable): * ps/ggvutils.h: * ps/gtkgs.c: (check_filecompressed), (check_pdf), (gtk_gs_get_postscript): Remove unused utils --- (limited to 'ps') diff --git a/ps/ggvutils.c b/ps/ggvutils.c index c79ec04..bea0412 100644 --- a/ps/ggvutils.c +++ b/ps/ggvutils.c @@ -21,23 +21,12 @@ */ #include "config.h" -#include -#include -#include - -#include -#include -#include +#include #include #include "ggvutils.h" -typedef struct { - char *stock_id; - char *name; -} GgvStockIcon; - GtkGSPaperSize ggv_paper_sizes[] = { {N_("BBox"), 0, 0}, {N_("Letter"), 612, 792,}, @@ -60,13 +49,6 @@ GtkGSPaperSize ggv_paper_sizes[] = { {NULL, 0, 0} }; -const gfloat ggv_unit_factors[] = { - 1.0, - 25.4, - 2.54, - 72.0 -}; - const gchar *ggv_orientation_labels[] = { N_("Portrait"), N_("Landscape"), @@ -75,20 +57,6 @@ const gchar *ggv_orientation_labels[] = { NULL, }; -const gint ggv_max_orientation_labels = - (sizeof(ggv_orientation_labels) / sizeof(gchar *)) - 2; - -const gchar *ggv_unit_labels[] = { - N_("inch"), - N_("mm"), - N_("cm"), - N_("point"), - NULL -}; - -const gint ggv_max_unit_labels = - (sizeof(ggv_unit_labels) / sizeof(gchar *)) - 2; - gfloat ggv_zoom_levels[] = { 1.0 / 6.0, 1.0 / 5.0, 1.0 / 4.0, 1.0 / 3.0, 1.0 / 2.0, 3.0 / 4.0, 1.0, 3.0 / 2.0, 2.0, 3.0, 4.0, 5.0, 6.0 @@ -103,136 +71,6 @@ const gchar *ggv_zoom_level_names[] = { const gint ggv_max_zoom_levels = (sizeof(ggv_zoom_levels) / sizeof(gfloat)) - 1; -const gchar *ggv_auto_fit_modes[] = { - N_("None"), N_("Fit to page width"), N_("Fit to page size") -}; - -const gint ggv_max_auto_fit_modes = - (sizeof(ggv_auto_fit_modes) / sizeof(gchar *)) - 1; - -gint -ggv_zoom_index_from_float(gfloat zoom_level) -{ - int i; - - for(i = 0; i <= ggv_max_zoom_levels; i++) { - float this, epsilon; - - /* if we're close to a zoom level */ - this = ggv_zoom_levels[i]; - epsilon = this * 0.01; - - if(zoom_level < this + epsilon) - return i; - } - - return ggv_max_zoom_levels; -} - -gfloat -ggv_zoom_level_from_index(gint index) -{ - if(index > ggv_max_zoom_levels) - index = ggv_max_zoom_levels; - - return ggv_zoom_levels[index]; -} - -GSList * -ggv_split_string(const gchar * string, const gchar * delimiter) -{ - const gchar *ptr = string; - int pos = 0, escape = 0; - char buffer[BUFSIZ]; - GSList *list = NULL; - - g_return_val_if_fail(string != NULL, NULL); - g_return_val_if_fail(delimiter != NULL, NULL); - - while(*ptr) { - char c = *ptr++; - const gchar *d; - int found = 0; - - if(pos >= BUFSIZ) { - g_warning("string too long, aborting"); - return list; - } - - if(escape) { - buffer[pos++] = c; - escape = 0; - continue; - } - - if(c == '\\') { - escape = 1; - continue; - } - - for(d = delimiter; *d; d++) { - if(c == *d) { - buffer[pos++] = 0; - list = g_slist_prepend(list, g_strdup(buffer)); - pos = 0; - found = 1; - break; - } - } - - if(!found) - buffer[pos++] = c; - } - - buffer[pos++] = 0; - list = g_slist_prepend(list, g_strdup(buffer)); - - return list; -} - -gint -ggv_get_index_of_string(gchar * string, gchar ** strings) -{ - guint idx = 0; - - while(strings[idx] != NULL) { - if(strcmp(strings[idx], string) == 0) - return idx; - idx++; - } - - return -1; -} - -/* Quote filename for system call */ -gchar * -ggv_quote_filename(const gchar * str) -{ - return g_shell_quote(str); -} - -/* escapes filename to form a proper URI: works conservatively - anything - except [a-zA-Z0-9_] will be escaped with a %XX escape sequence where - XX is the hex value of the char. */ -gchar * -ggv_filename_to_uri(const gchar * fname) -{ - gchar *full_path, *ret_val; - - if(*fname != '/') { - gchar *cwd; - /* relative file name - we will have to absolutize it */ - cwd = g_get_current_dir(); - full_path = g_strconcat(cwd, "/", fname, NULL); - } - else - full_path = NULL; - ret_val = gnome_vfs_get_uri_from_local_path(full_path ? full_path : fname); - if(full_path) - g_free(full_path); - return ret_val; -} - /* If file exists and is a regular file then return its length, else -1 */ gint ggv_file_length(const gchar * filename) @@ -252,97 +90,3 @@ ggv_file_readable(const char *filename) { return (ggv_file_length(filename) > 0); } - -/* Set a tooltip for a widget */ -void -ggv_set_tooltip(GtkWidget * w, const gchar * tip) -{ - GtkTooltips *t = gtk_tooltips_new(); - - gtk_tooltips_set_tip(t, w, tip, NULL); -} - -gfloat -ggv_compute_zoom(gint zoom_spec) -{ - return pow(1.2, zoom_spec); /* The Knuth magstep formula rules */ -} - -gint -ggv_compute_spec(gfloat zoom) -{ - zoom = MAX(0.02, zoom); - zoom = MIN(10.0, zoom); - - zoom = log(zoom) / log(1.2); - return (gint) rint(zoom); -} - -void -ggv_raise_and_focus_widget(GtkWidget * widget) -{ - g_assert(GTK_WIDGET_REALIZED(widget)); - gdk_window_raise(widget->window); - gtk_widget_grab_focus(widget); -} - -void -ggv_get_window_size(GtkWidget * widget, gint * width, gint * height) -{ - *width = widget->allocation.width; - *height = widget->allocation.height; -} - -static GgvStockIcon items[] = { - {GGV_CLEAR_ALL, GNOMEICONDIR "/ggv/clearall.xpm"}, - {GGV_TOGGLE_ALL, GNOMEICONDIR "/ggv/toggleall.xpm"}, - {GGV_TOGGLE_EVEN, GNOMEICONDIR "/ggv/toggleeven.xpm"}, - {GGV_TOGGLE_ODD, GNOMEICONDIR "/ggv/toggleodd.xpm"}, - {GGV_FIT_WIDTH, GNOMEICONDIR "/ggv/fitwidth.png"}, - {GGV_ZOOM, GNOMEICONDIR "/ggv/zoom.xpm"} -}; - -static void -ggv_register_stock_icons(GtkIconFactory * factory) -{ - gint i; - GtkIconSource *source; - - source = gtk_icon_source_new(); - - for(i = 0; i < G_N_ELEMENTS(items); ++i) { - GtkIconSet *icon_set; - - if(!g_file_test(items[i].name, G_FILE_TEST_EXISTS)) { - g_warning(_("Unable to load ggv stock icon '%s'\n"), items[i].name); - icon_set = gtk_icon_factory_lookup_default(GTK_STOCK_MISSING_IMAGE); - gtk_icon_factory_add(factory, items[i].stock_id, icon_set); - continue; - } - - gtk_icon_source_set_filename(source, items[i].name); - - icon_set = gtk_icon_set_new(); - gtk_icon_set_add_source(icon_set, source); - gtk_icon_factory_add(factory, items[i].stock_id, icon_set); - gtk_icon_set_unref(icon_set); - } - gtk_icon_source_free(source); -} - -void -ggv_init_stock_icons(void) -{ - GtkIconFactory *factory; - static gboolean initialized = FALSE; - - if(initialized) - return; - initialized = TRUE; - - factory = gtk_icon_factory_new(); - gtk_icon_factory_add_default(factory); - ggv_register_stock_icons(factory); - - g_object_unref(factory); -} diff --git a/ps/ggvutils.h b/ps/ggvutils.h index 92aecf8..093b4c1 100644 --- a/ps/ggvutils.h +++ b/ps/ggvutils.h @@ -23,45 +23,12 @@ #ifndef __GGV_UTILS_H__ #define __GGV_UTILS_H__ -#include - -#include - -/*Define StockIds*/ -#define GGV_CLEAR_ALL "ggv-clear-all" -#define GGV_TOGGLE_ALL "ggv-toggle-all" -#define GGV_TOGGLE_EVEN "ggv-toggle-even" -#define GGV_TOGGLE_ODD "ggv-toggle-odd" -#define GGV_FIT_WIDTH "ggv-fit-width" -#define GGV_ZOOM "ggv-zoom" +#include "gtkgs.h" extern GtkGSPaperSize ggv_paper_sizes[]; -extern const gchar *ggv_orientation_labels[]; -extern const gint ggv_max_orientation_labels; -extern const gfloat ggv_unit_factors[]; -extern const gchar *ggv_unit_labels[]; -extern const gint ggv_max_unit_labels; extern gfloat ggv_zoom_levels[]; extern const gchar *ggv_zoom_level_names[]; extern const gint ggv_max_zoom_levels; -extern const gchar *ggv_auto_fit_modes[]; -extern const gint ggv_max_auto_fit_modes; - -/* zoom level index <-> zoom factor */ -gint ggv_zoom_index_from_float(gfloat zoom_level); -gfloat ggv_zoom_level_from_index(gint index); - -/* Split delimited string into a list of strings. */ -GSList *ggv_split_string(const gchar * string, const gchar * delimiter); - -/* Get index of a string from a list of them. */ -gint ggv_get_index_of_string(gchar * string, gchar ** strings); - -/* Quote filename for system call */ -gchar *ggv_quote_filename(const gchar * str); - -/* escape filename to conform to URI specification */ -gchar *ggv_filename_to_uri(const gchar * fname); /* If file exists and is a regular file then return its length, else -1 */ gint ggv_file_length(const gchar * filename); @@ -69,17 +36,4 @@ gint ggv_file_length(const gchar * filename); /* Test if file exists, is a regular file and its length is > 0 */ gboolean ggv_file_readable(const char *filename); -/* Set a tooltip for a widget */ -void ggv_set_tooltip(GtkWidget * w, const gchar * tip); - -/* zoom <-> magstep (currently not used...) */ -gfloat ggv_compute_zoom(gint zoom_spec); -gint ggv_compute_spec(gfloat zoom); - -void ggv_raise_and_focus_widget(GtkWidget * widget); - -void ggv_get_window_size(GtkWidget * widget, gint * width, gint * height); - -void ggv_init_stock_icons(void); - #endif /* __GGV_UTILS_H__ */ diff --git a/ps/gtkgs.c b/ps/gtkgs.c index 0e824db..3c8ce19 100644 --- a/ps/gtkgs.c +++ b/ps/gtkgs.c @@ -959,7 +959,7 @@ check_filecompressed(GtkGS * gs) return gs->gs_filename; /* do the decompression */ - filename = ggv_quote_filename(gs->gs_filename); + filename = g_shell_quote(gs->gs_filename); filename_unc = g_strconcat(g_get_tmp_dir(), "/ggvXXXXXX", NULL); if((fd = mkstemp(filename_unc)) < 0) { g_free(filename_unc); @@ -1040,7 +1040,7 @@ check_pdf(GtkGS * gs) return NULL; } close(fd); - fname = ggv_quote_filename(filename); + fname = g_shell_quote(filename); cmd = g_strdup_printf(gtk_gs_defaults_get_dsc_cmd(), filename_dsc, fname); g_free(fname); /* this command (sometimes?) prints error messages to stdout! */ @@ -1999,8 +1999,8 @@ gtk_gs_get_postscript(GtkGS * gs, gint * pages) return NULL; } close(tmpfd); - fname = ggv_quote_filename(gs->gs_filename_unc ? - gs->gs_filename_unc : gs->gs_filename); + fname = g_shell_quote (gs->gs_filename_unc ? + gs->gs_filename_unc : gs->gs_filename); cmd = g_strdup_printf(gtk_gs_defaults_get_convert_pdf_cmd(), tmpn, fname); g_free(fname); if((system(cmd) == 0) && ggv_file_readable(tmpn)) { -- cgit v0.9.1