summaryrefslogtreecommitdiff
path: root/debian/patches/fix_options_handling_fix.patch
blob: 49084fe0d81bf417bd52b48556f1aa887fe14a1a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
Description: Fixup options handling
 Duplicate string values for options with constraint type of
 SANE_CONSTRAINT_STRING_LIST. The string list is not guaranteed to
 be stable, and actually isn't stable when the net backend is used.
Author: Julien BLACHE <jblache@debian.org>

Index: xsane-0.998/src/xsane-back-gtk.c
===================================================================
--- xsane-0.998.orig/src/xsane-back-gtk.c	2010-11-16 21:24:59.000000000 +0100
+++ xsane-0.998/src/xsane-back-gtk.c	2011-02-04 19:50:46.389016001 +0100
@@ -2225,11 +2225,13 @@
 /* ----------------------------------------------------------------------------------------------------------------- */
 
 void xsane_back_gtk_option_menu_new(GtkWidget *parent, const char *name, char *str_list[],
-		 const char *val, DialogElement *elem,
+		 const char *val, SANE_Constraint_Type constraint_type, DialogElement *elem,
 		 GtkTooltips *tooltips, const char *desc, SANE_Int settable)
 {
  GtkWidget *hbox, *label, *option_menu, *menu, *item;
  MenuItem *menu_items;
+ int dup_string;
+ char *strval;
  int i, num_items;
 
   DBG(DBG_proc, "xsane_back_gtk_option_menu_new(%s)\n", name);
@@ -2247,16 +2249,23 @@
 
   menu_items = malloc((num_items + 1) * sizeof(menu_items[0]));
 
+  dup_string = (constraint_type == SANE_CONSTRAINT_STRING_LIST);
+
   menu = gtk_menu_new();
   for (i = 0; i < num_items; ++i)
   {
-    item = gtk_menu_item_new_with_label(_BGT(str_list[i]));
+    if (dup_string)
+      strval = strdup(str_list[i]);
+    else
+      strval = str_list[i];
+
+    item = gtk_menu_item_new_with_label(_BGT(strval));
     gtk_container_add(GTK_CONTAINER(menu), item);
     g_signal_connect(GTK_OBJECT(item), "activate", (GtkSignalFunc) xsane_back_gtk_option_menu_callback, menu_items + i);
 
     gtk_widget_show(item);
 
-    menu_items[i].label = str_list[i];
+    menu_items[i].label = strval;
     menu_items[i].elem = elem;
     menu_items[i].index = i;
   }
@@ -2402,14 +2411,15 @@
   xsane.standard_hbox = NULL;
   xsane.advanced_hbox = NULL;
 
-  /* free the menu labels of integer/fix-point word-lists: */
+  /* free the menu labels */
   for (i = 0; i < xsane.num_elements; ++i)
   {
     if (xsane.element[i].menu)
     {
       opt = xsane_get_option_descriptor(xsane.dev, i);
       elem = xsane.element + i;
-      if (opt->type != SANE_TYPE_STRING)
+      if ((opt->type != SANE_TYPE_STRING)
+	  || (opt->constraint_type == SANE_CONSTRAINT_STRING_LIST))
       {
         for (j = 0; j < elem->menu_size; ++j)
         {
Index: xsane-0.998/src/xsane-back-gtk.h
===================================================================
--- xsane-0.998.orig/src/xsane-back-gtk.h	2007-02-24 01:56:54.000000000 +0100
+++ xsane-0.998/src/xsane-back-gtk.h	2011-02-04 19:50:46.389016001 +0100
@@ -117,7 +117,7 @@
 	   gfloat quant, int automatic,
 	   DialogElement *elem, GtkTooltips *tooltips, const char *desc, SANE_Int settable);
 extern void xsane_back_gtk_option_menu_new(GtkWidget *parent, const char *name, char *str_list[],
-           const char *val, DialogElement *elem, GtkTooltips *tooltips, const char *desc, SANE_Int settable);
+           const char *val, SANE_Constraint_Type constraint_type, DialogElement *elem, GtkTooltips *tooltips, const char *desc, SANE_Int settable);
 extern void xsane_back_gtk_text_entry_new(GtkWidget *parent, const char *name, const char *val,
                 DialogElement *elem, GtkTooltips *tooltips, const char *desc, SANE_Int settable);
 extern void xsane_back_gtk_push_button_callback(GtkWidget *widget, gpointer data);
Index: xsane-0.998/src/xsane-front-gtk.c
===================================================================
--- xsane-0.998.orig/src/xsane-front-gtk.c	2010-11-16 21:25:33.000000000 +0100
+++ xsane-0.998/src/xsane-front-gtk.c	2011-02-04 19:50:46.393016001 +0100
@@ -64,10 +64,10 @@
                                          int *state, void *xsane_toggle_button_callback);
 GtkWidget *xsane_button_new_with_pixmap(GdkWindow *window, GtkWidget *parent, const char *xpm_d[], const char *desc,
                                         void *xsane_button_callback, gpointer data);
-void xsane_option_menu_new(GtkWidget *parent, char *str_list[], const char *val, int option_number, const char *desc,
+void xsane_option_menu_new(GtkWidget *parent, char *str_list[], const char *val, SANE_Constraint_Type constraint_type, int option_number, const char *desc,
                            void *option_menu_callback, SANE_Int settable, const gchar *widget_name);
 void xsane_option_menu_new_with_pixmap(GdkWindow *window, GtkBox *parent, const char *xpm_d[], const char *desc,
-                                       char *str_list[], const char *val,
+                                       char *str_list[], const char *val, SANE_Constraint_Type constraint_type,
                                        GtkWidget **data, int option,
                                        void *option_menu_callback, SANE_Int settable, const gchar *widget_name);
 void xsane_range_new(GtkBox *parent, char *labeltext, const char *desc,
@@ -1011,12 +1011,14 @@
 
 /* ---------------------------------------------------------------------------------------------------------------------- */
 
-void xsane_option_menu_new(GtkWidget *parent, char *str_list[], const char *val, int option_number, const char *desc,
+void xsane_option_menu_new(GtkWidget *parent, char *str_list[], const char *val, SANE_Constraint_Type constraint_type, int option_number, const char *desc,
                            void *option_menu_callback, SANE_Int settable, const gchar *widget_name)
 {
  GtkWidget *option_menu, *menu, *item;
  MenuItem *menu_items;
  DialogElement *elem;
+ int dup_string;
+ char *strval;
  int i, num_items;
 
   DBG(DBG_proc, "xsane_option_menu_new\n");
@@ -1035,9 +1037,16 @@
     gtk_widget_set_name(menu, widget_name);
   }
 
+  dup_string = (constraint_type == SANE_CONSTRAINT_STRING_LIST);
+
   for (i = 0; i < num_items; ++i)
   {
-    item = gtk_menu_item_new_with_label(_BGT(str_list[i]));
+    if (dup_string)
+      strval = strdup(str_list[i]);
+    else
+      strval = str_list[i];
+
+    item = gtk_menu_item_new_with_label(_BGT(strval));
     gtk_container_add(GTK_CONTAINER(menu), item);
 
     if (option_menu_callback)
@@ -1051,7 +1060,7 @@
 
     gtk_widget_show(item);
 
-    menu_items[i].label = str_list[i];
+    menu_items[i].label = strval;
     menu_items[i].elem  = elem;
     menu_items[i].index = i;
   }
@@ -1079,7 +1088,7 @@
 /* ---------------------------------------------------------------------------------------------------------------------- */
 
 void xsane_option_menu_new_with_pixmap(GdkWindow *window, GtkBox *parent, const char *xpm_d[], const char *desc,
-                                       char *str_list[], const char *val,
+                                       char *str_list[], const char *val, SANE_Constraint_Type constraint_type,
                                        GtkWidget **data, int option,
                                        void *option_menu_callback, SANE_Int settable, const gchar *widget_name)
 {
@@ -1098,7 +1107,7 @@
   gtk_box_pack_start(GTK_BOX(hbox), pixmapwidget, FALSE, FALSE, 2);
   gtk_widget_show(pixmapwidget);
 
-  xsane_option_menu_new(hbox, str_list, val, option, desc, option_menu_callback, settable, widget_name);
+  xsane_option_menu_new(hbox, str_list, val, constraint_type, option, desc, option_menu_callback, settable, widget_name);
   gtk_widget_show(hbox);
 }
 
Index: xsane-0.998/src/xsane-front-gtk.h
===================================================================
--- xsane-0.998.orig/src/xsane-front-gtk.h	2007-05-17 14:45:19.000000000 +0200
+++ xsane-0.998/src/xsane-front-gtk.h	2011-02-04 19:50:46.453016001 +0100
@@ -54,10 +54,10 @@
 extern GtkWidget *xsane_button_new_with_pixmap(GdkWindow *window, GtkWidget *parent, const char *xpm_d[], const char *desc, 
                                                void *xsane_button_callback, gpointer data);
 extern void xsane_pixmap_new(GtkWidget *parent, char *title, int width, int height, XsanePixmap *hist);
-extern void xsane_option_menu_new(GtkWidget *parent, char *str_list[], const char *val, int option_number, const char *desc,
+extern void xsane_option_menu_new(GtkWidget *parent, char *str_list[], const char *val, SANE_Constraint_Type constraint_type, int option_number, const char *desc,
                                   void *option_menu_callback, SANE_Int settable, const gchar *widget_name);
 extern void xsane_option_menu_new_with_pixmap(GdkWindow *window, GtkBox *parent, const char *xpm_d[], const char *desc,
-                                              char *str_list[], const char *val,
+                                              char *str_list[], const char *val, SANE_Constraint_Type constraint_type,
                                               GtkWidget **data, int option,
                                               void *option_menu_callback, SANE_Int settable, const gchar *widget_name);
 extern void xsane_range_new(GtkBox *parent, char *labeltext, const char *desc,
Index: xsane-0.998/src/xsane.c
===================================================================
--- xsane-0.998.orig/src/xsane.c	2011-02-04 19:50:40.957016002 +0100
+++ xsane-0.998/src/xsane.c	2011-02-04 19:50:46.457016001 +0100
@@ -876,7 +876,7 @@
             str_list[j] = 0;
             sprintf(str, "%d", (int) val);
 
-            xsane_option_menu_new_with_pixmap(xsane.xsane_window->window, GTK_BOX(parent), image_xpm, desc, str_list, str, &resolution_widget, well_known_option,
+            xsane_option_menu_new_with_pixmap(xsane.xsane_window->window, GTK_BOX(parent), image_xpm, desc, str_list, str, opt->constraint_type, &resolution_widget, well_known_option,
                                               xsane_resolution_list_callback, SANE_OPTION_IS_SETTABLE(opt->cap), widget_name);
 
             free(str_list);
@@ -931,7 +931,7 @@
 
 
           xsane_option_menu_new_with_pixmap(xsane.xsane_window->window, GTK_BOX(parent), image_xpm, desc,
-                                            str_list, str, &resolution_widget, well_known_option,
+                                            str_list, str, opt->constraint_type, &resolution_widget, well_known_option,
                                             xsane_resolution_list_callback, SANE_OPTION_IS_SETTABLE(opt->cap), widget_name);
           free(str_list);
         }
@@ -1496,7 +1496,7 @@
           set = malloc(opt->size);
           status = xsane_control_option(xsane.dev, xsane.well_known.scansource, SANE_ACTION_GET_VALUE, set, 0);
 
-          xsane_option_menu_new(hbox, (char **) opt->constraint.string_list, set, xsane.well_known.scansource,
+          xsane_option_menu_new(hbox, (char **) opt->constraint.string_list, set, opt->constraint_type, xsane.well_known.scansource,
                                 _BGT(opt->desc), 0, SANE_OPTION_IS_SETTABLE(opt->cap), 0);
          }
          break;
@@ -1536,7 +1536,7 @@
           set = malloc(opt->size);
           status = xsane_control_option(xsane.dev, xsane.well_known.scanmode, SANE_ACTION_GET_VALUE, set, 0);
 
-          xsane_option_menu_new(hbox, (char **) opt->constraint.string_list, set, xsane.well_known.scanmode,
+          xsane_option_menu_new(hbox, (char **) opt->constraint.string_list, set, opt->constraint_type, xsane.well_known.scanmode,
                                 _BGT(opt->desc), xsane_scanmode_menu_callback, SANE_OPTION_IS_SETTABLE(opt->cap), 0);
         }
          break;
@@ -4646,7 +4646,7 @@
               }
               str_list[j] = 0;
               sprintf(str, "%d", val);
-              xsane_back_gtk_option_menu_new(parent, title, str_list, str, elem, xsane.tooltips, _BGT(opt->desc),
+              xsane_back_gtk_option_menu_new(parent, title, str_list, str, opt->constraint_type, elem, xsane.tooltips, _BGT(opt->desc),
                                   SANE_OPTION_IS_SETTABLE(opt->cap));
               free(str_list);
               gtk_widget_show(parent->parent);
@@ -4744,7 +4744,7 @@
               }
               str_list[j] = 0;
               sprintf(str, "%g", SANE_UNFIX(val));
-              xsane_back_gtk_option_menu_new(parent, title, str_list, str, elem, xsane.tooltips, _BGT(opt->desc), SANE_OPTION_IS_SETTABLE(opt->cap));
+              xsane_back_gtk_option_menu_new(parent, title, str_list, str, opt->constraint_type, elem, xsane.tooltips, _BGT(opt->desc), SANE_OPTION_IS_SETTABLE(opt->cap));
               free (str_list);
               gtk_widget_show(parent->parent);
             }
@@ -4789,7 +4789,7 @@
                  (strcmp (opt->name, SANE_NAME_SCAN_SOURCE) != 0) ) /* do not show scansource */
             {
               /* use a "list-selection" widget */
-              xsane_back_gtk_option_menu_new(parent, title, (char **) opt->constraint.string_list, buf,
+              xsane_back_gtk_option_menu_new(parent, title, (char **) opt->constraint.string_list, buf, opt->constraint_type,
                                   elem, xsane.tooltips, _BGT(opt->desc), SANE_OPTION_IS_SETTABLE(opt->cap));
               gtk_widget_show (parent->parent);
             }