Commit 51b1179e660996ef53becdbb65fb8451d8e6b463
1 parent
0813b634
Exists in
master
and in
5 other branches
Implementando paste com conversao de charset
Showing
4 changed files
with
52 additions
and
78 deletions
Show diff stats
src/gtk/v3270/clipboard.c
... | ... | @@ -109,21 +109,23 @@ void v3270_copy_clipboard(v3270 *widget) |
109 | 109 | } |
110 | 110 | } |
111 | 111 | |
112 | -static void paste_text(GtkWidget *widget, const gchar *text, const gchar *encoding) | |
112 | +void v3270_paste_string(GtkWidget *widget, const gchar *text, const gchar *encoding) | |
113 | 113 | { |
114 | - gchar *buffer = NULL; | |
115 | - gchar *ptr; | |
116 | - GError *error = NULL; | |
117 | - H3270 *session = v3270_get_session(widget); | |
114 | + gchar * buffer = NULL; | |
115 | + H3270 * session = v3270_get_session(widget); | |
116 | + const gchar * charset = lib3270_get_charset(session); | |
117 | + gboolean next; | |
118 | 118 | |
119 | 119 | if(!text) |
120 | 120 | return; |
121 | - | |
122 | - buffer = g_convert(text, -1, lib3270_get_charset(session), encoding, NULL, NULL, &error); | |
121 | + else if(g_strcasecmp(encoding,charset)) | |
122 | + buffer = g_convert(text, -1, charset, encoding, NULL, NULL, NULL); | |
123 | + else | |
124 | + buffer = g_strdup(text); | |
123 | 125 | |
124 | 126 | if(!buffer) |
125 | 127 | { |
126 | - /* Falhou ao converter - Reajusta e tenta de novo */ | |
128 | + /* Conversion failed, update special chars and try again */ | |
127 | 129 | int f; |
128 | 130 | |
129 | 131 | static const struct _xlat |
... | ... | @@ -150,12 +152,6 @@ static void paste_text(GtkWidget *widget, const gchar *text, const gchar *encodi |
150 | 152 | |
151 | 153 | gchar *string = g_strdup(text); |
152 | 154 | |
153 | - if(error) | |
154 | - { | |
155 | - g_error_free(error); | |
156 | - error = NULL; | |
157 | - } | |
158 | - | |
159 | 155 | // FIXME (perry#1#): Is there any better way for a "sed" here? |
160 | 156 | for(f=0;f<G_N_ELEMENTS(xlat);f++) |
161 | 157 | { |
... | ... | @@ -171,21 +167,17 @@ static void paste_text(GtkWidget *widget, const gchar *text, const gchar *encodi |
171 | 167 | } |
172 | 168 | } |
173 | 169 | |
174 | - buffer = g_convert(string, -1, lib3270_get_charset(session), encoding, NULL, NULL, &error); | |
170 | + buffer = g_convert(string, -1, charset, encoding, NULL, NULL, NULL); | |
175 | 171 | |
176 | 172 | if(!buffer) |
177 | 173 | { |
174 | + // Still failing, convert line by line | |
178 | 175 | gchar **ln = g_strsplit(string,"\n",-1); |
179 | 176 | |
180 | 177 | for(f=0;ln[f];f++) |
181 | 178 | { |
182 | - gchar *str = g_convert(ln[f], -1, lib3270_get_charset(session), encoding, NULL, NULL, &error); | |
183 | - | |
184 | - if(error) | |
185 | - { | |
186 | - g_error_free(error); | |
187 | - error = 0; | |
188 | - } | |
179 | + GError *error = NULL; | |
180 | + gchar *str = g_convert(ln[f], -1, charset, encoding, NULL, NULL, &error); | |
189 | 181 | |
190 | 182 | if(!str) |
191 | 183 | { |
... | ... | @@ -193,86 +185,57 @@ static void paste_text(GtkWidget *widget, const gchar *text, const gchar *encodi |
193 | 185 | GTK_DIALOG_DESTROY_WITH_PARENT, |
194 | 186 | GTK_MESSAGE_ERROR, |
195 | 187 | GTK_BUTTONS_OK, |
196 | - _( "Can't convert line %d from %s to %s" ),f+1, encoding, lib3270_get_charset(session)); | |
188 | + _( "Can't convert line %d from %s to %s" ),f+1, encoding, charset); | |
197 | 189 | |
198 | 190 | gtk_window_set_title(GTK_WINDOW(dialog), _( "Charset error" ) ); |
199 | - if(error) | |
200 | - { | |
201 | - gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),"%s\n%s", error->message ? error->message : N_( "Unexpected error" ), ln[f]); | |
202 | - g_error_free(error); | |
203 | - error = 0; | |
204 | - } | |
205 | - else | |
206 | - { | |
207 | - gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),"%s", ln[f]); | |
208 | - } | |
191 | + gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),"%s\n%s",error->message, ln[f]); | |
192 | + | |
209 | 193 | gtk_dialog_run(GTK_DIALOG (dialog)); |
210 | 194 | gtk_widget_destroy(dialog); |
211 | - return; | |
212 | 195 | |
196 | + break; | |
213 | 197 | } |
214 | 198 | else |
215 | 199 | { |
216 | 200 | g_free(str); |
217 | 201 | } |
218 | - } | |
219 | 202 | |
203 | + } | |
220 | 204 | g_strfreev(ln); |
221 | - g_free(string); | |
222 | - } | |
223 | - | |
224 | - g_free(string); | |
225 | 205 | |
226 | - if(error) | |
227 | - { | |
228 | - g_error_free(error); | |
229 | - error = 0; | |
230 | 206 | } |
231 | 207 | |
232 | - | |
233 | - if(!buffer) | |
234 | - { | |
235 | - GtkWidget *dialog = gtk_message_dialog_new( GTK_WINDOW( gtk_widget_get_toplevel(widget)), | |
236 | - GTK_DIALOG_DESTROY_WITH_PARENT, | |
237 | - GTK_MESSAGE_ERROR, | |
238 | - GTK_BUTTONS_OK, | |
239 | - _( "Can't convert text from %s to %s" ), encoding, lib3270_get_charset(session)); | |
240 | - | |
241 | - gtk_window_set_title(GTK_WINDOW(dialog), _( "Charset error" ) ); | |
242 | - if(error) | |
243 | - { | |
244 | - gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),"%s", error->message ? error->message : N_( "Unexpected error" )); | |
245 | - g_error_free(error); | |
246 | - error = 0; | |
247 | - } | |
248 | - gtk_dialog_run(GTK_DIALOG (dialog)); | |
249 | - gtk_widget_destroy(dialog); | |
250 | - | |
251 | - return; | |
252 | - } | |
208 | + g_free(string); | |
253 | 209 | } |
254 | 210 | |
255 | - if(error) | |
256 | - g_error_free(error); | |
257 | - | |
258 | - /* Remove TABS */ | |
259 | - for(ptr = buffer;*ptr;ptr++) | |
260 | - { | |
261 | - if(*ptr == '\t') | |
262 | - *ptr = ' '; | |
263 | - } | |
211 | + if(buffer) | |
212 | + { | |
213 | + /* Remove TABS */ | |
214 | + gchar *ptr; | |
264 | 215 | |
265 | - trace("Received text:%p (%d bytes)",buffer,(int) strlen(buffer)); | |
216 | + for(ptr = buffer;*ptr;ptr++) | |
217 | + { | |
218 | + if(*ptr == '\t') | |
219 | + *ptr = ' '; | |
220 | + } | |
221 | + } | |
222 | + else | |
223 | + { | |
224 | + g_signal_emit(widget,v3270_widget_signal[SIGNAL_PASTENEXT], 0, FALSE); | |
225 | + return; | |
226 | + } | |
266 | 227 | |
267 | -// paste_string(buffer); | |
228 | + next = lib3270_paste(session,buffer) ? TRUE : FALSE; | |
268 | 229 | |
269 | 230 | g_free(buffer); |
270 | 231 | |
232 | + g_signal_emit(widget,v3270_widget_signal[SIGNAL_PASTENEXT], 0, next); | |
233 | + | |
271 | 234 | } |
272 | 235 | |
273 | 236 | static void text_received(GtkClipboard *clipboard, const gchar *text, GtkWidget *widget) |
274 | 237 | { |
275 | - paste_text(widget,text,"UTF-8"); | |
238 | + v3270_paste_string(widget,text,"UTF-8"); | |
276 | 239 | } |
277 | 240 | |
278 | 241 | void v3270_paste_clipboard(v3270 *widget) | ... | ... |
src/gtk/v3270/private.h
src/gtk/v3270/v3270.h
... | ... | @@ -202,9 +202,9 @@ |
202 | 202 | |
203 | 203 | // Clipboard |
204 | 204 | void v3270_copy_clipboard(v3270 *widget); |
205 | + void v3270_paste_string(GtkWidget *widget, const gchar *text, const gchar *encoding); | |
205 | 206 | void v3270_paste_clipboard(v3270 *widget); |
206 | 207 | |
207 | - | |
208 | 208 | G_END_DECLS |
209 | 209 | |
210 | 210 | #endif // V3270_H_INCLUDED | ... | ... |
src/gtk/v3270/widget.c
... | ... | @@ -291,6 +291,16 @@ static void v3270_class_init(v3270Class *klass) |
291 | 291 | NULL, NULL, |
292 | 292 | pw3270_BOOL__VOID_BOOL_BOOL_POINTER, |
293 | 293 | G_TYPE_BOOLEAN, 3, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN, G_TYPE_POINTER); |
294 | + | |
295 | + v3270_widget_signal[SIGNAL_PASTENEXT] = | |
296 | + g_signal_new( "pastenext", | |
297 | + G_OBJECT_CLASS_TYPE (gobject_class), | |
298 | + G_SIGNAL_RUN_FIRST, | |
299 | + 0, | |
300 | + NULL, NULL, | |
301 | + pw3270_VOID__VOID_BOOL, | |
302 | + G_TYPE_NONE, 1, G_TYPE_BOOLEAN); | |
303 | + | |
294 | 304 | } |
295 | 305 | |
296 | 306 | void v3270_update_font_metrics(v3270 *terminal, cairo_t *cr, int width, int height) |
... | ... | @@ -456,7 +466,7 @@ static void v3270_init(v3270 *widget) |
456 | 466 | |
457 | 467 | if(widget->host->sz != sizeof(H3270)) |
458 | 468 | { |
459 | - g_error(N_( "Unexpected signature in H3270 object, possible version mismatch in lib3270") ); | |
469 | + g_error( _( "Unexpected signature in H3270 object, possible version mismatch in lib3270") ); | |
460 | 470 | return; |
461 | 471 | } |
462 | 472 | ... | ... |