Commit ba685fa9ff8b15829de4af61b604785cc209ff80
1 parent
f6d29955
Exists in
master
and in
1 other branch
Still refactoring the host properties dialog widget.
Showing
1 changed file
with
221 additions
and
125 deletions
Show diff stats
src/dialogs/hostselect.c
| ... | ... | @@ -191,6 +191,7 @@ |
| 191 | 191 | GtkEntry * entry[G_N_ELEMENTS(entryfields)]; ///< @brief Entry fields for host & service name |
| 192 | 192 | GtkToggleButton * ssl; ///< @brief SSL Connection? |
| 193 | 193 | GtkComboBox * combos[G_N_ELEMENTS(combos)]; ///< @brief Combo-boxes |
| 194 | + GtkComboBox * charset; ///< @brief Charset combo box | |
| 194 | 195 | |
| 195 | 196 | } input; |
| 196 | 197 | |
| ... | ... | @@ -201,130 +202,13 @@ |
| 201 | 202 | V3270SettingsClass parent_class; |
| 202 | 203 | }; |
| 203 | 204 | |
| 205 | + static void load(GtkWidget *w, GtkWidget *terminal); | |
| 206 | + static void apply(GtkWidget *w, GtkWidget *terminal); | |
| 204 | 207 | |
| 205 | 208 | G_DEFINE_TYPE(V3270HostSelectWidget, V3270HostSelectWidget, GTK_TYPE_V3270_SETTINGS); |
| 206 | 209 | |
| 207 | 210 | /*--[ Implement ]------------------------------------------------------------------------------------*/ |
| 208 | 211 | |
| 209 | -static void apply(GtkWidget *w, GtkWidget *terminal) | |
| 210 | -{ | |
| 211 | - debug("V3270HostSelectWidget::%s",__FUNCTION__); | |
| 212 | - | |
| 213 | - V3270HostSelectWidget *widget = GTK_V3270HostSelectWidget(w); | |
| 214 | - H3270 *hSession = v3270_get_session(terminal); | |
| 215 | - | |
| 216 | - // Apply URL | |
| 217 | - { | |
| 218 | - g_autofree gchar * url = | |
| 219 | - g_strconcat( | |
| 220 | - (gtk_toggle_button_get_active(widget->input.ssl) ? "tn3270s://" : "tn3270://"), | |
| 221 | - gtk_entry_get_text(widget->input.entry[ENTRY_HOSTNAME]), | |
| 222 | - ":", | |
| 223 | - gtk_entry_get_text(widget->input.entry[ENTRY_SRVCNAME]), | |
| 224 | - NULL | |
| 225 | - ); | |
| 226 | - | |
| 227 | - debug("URL=[%s]",url); | |
| 228 | - lib3270_set_url(hSession,url); | |
| 229 | - | |
| 230 | - } | |
| 231 | - | |
| 232 | - // Apply combos. | |
| 233 | - size_t combo; | |
| 234 | - for(combo = 0; combo < G_N_ELEMENTS(combos); combo++) | |
| 235 | - { | |
| 236 | - GtkTreeIter iter; | |
| 237 | - | |
| 238 | - if(gtk_combo_box_get_active_iter(GTK_COMBO_BOX(widget->input.combos[combo]), &iter)) | |
| 239 | - { | |
| 240 | - GValue value = { 0, }; | |
| 241 | - gtk_tree_model_get_value(gtk_combo_box_get_model(GTK_COMBO_BOX(widget->input.combos[combo])),&iter,1,&value); | |
| 242 | - | |
| 243 | - combos[combo].set(hSession,g_value_get_uint(&value)); | |
| 244 | - | |
| 245 | - g_value_unset(&value); | |
| 246 | - | |
| 247 | - } | |
| 248 | - } | |
| 249 | - | |
| 250 | -} | |
| 251 | - | |
| 252 | -static void load(GtkWidget *w, GtkWidget *terminal) | |
| 253 | -{ | |
| 254 | - debug("V3270HostSelectWidget::%s",__FUNCTION__); | |
| 255 | - | |
| 256 | - H3270 *hSession = v3270_get_session(terminal); | |
| 257 | - V3270HostSelectWidget *widget = GTK_V3270HostSelectWidget(w); | |
| 258 | - | |
| 259 | - const gchar * u = lib3270_get_url(hSession); | |
| 260 | - | |
| 261 | - if(u) | |
| 262 | - { | |
| 263 | - | |
| 264 | - g_autofree gchar * url = g_strdup(u); | |
| 265 | - debug("URL=[%s]",url); | |
| 266 | - | |
| 267 | - gtk_toggle_button_set_active(widget->input.ssl,g_str_has_prefix(u,"tn3270s")); | |
| 268 | - | |
| 269 | - gchar *hostname = strstr(url,"://"); | |
| 270 | - if(!hostname) | |
| 271 | - { | |
| 272 | - g_message("Invalid URL: \"%s\" (no scheme)",url); | |
| 273 | - } | |
| 274 | - else | |
| 275 | - { | |
| 276 | - hostname += 3; | |
| 277 | - | |
| 278 | - gchar *srvcname = strchr(hostname,':'); | |
| 279 | - | |
| 280 | - if(srvcname) | |
| 281 | - { | |
| 282 | - *(srvcname++) = 0; | |
| 283 | - } | |
| 284 | - else | |
| 285 | - { | |
| 286 | - srvcname = "telnet"; | |
| 287 | - } | |
| 288 | - | |
| 289 | - gtk_entry_set_text(widget->input.entry[ENTRY_HOSTNAME],hostname); | |
| 290 | - gtk_entry_set_text(widget->input.entry[ENTRY_SRVCNAME],srvcname); | |
| 291 | - | |
| 292 | - } | |
| 293 | - | |
| 294 | - } | |
| 295 | - | |
| 296 | - size_t combo; | |
| 297 | - for(combo = 0; combo < G_N_ELEMENTS(combos); combo++) | |
| 298 | - { | |
| 299 | - | |
| 300 | - GtkTreeModel * model = gtk_combo_box_get_model(widget->input.combos[combo]); | |
| 301 | - GtkTreeIter iter; | |
| 302 | - unsigned int value = combos[combo].get(hSession); | |
| 303 | - | |
| 304 | - if(gtk_tree_model_get_iter_first(model,&iter)) | |
| 305 | - { | |
| 306 | - do | |
| 307 | - { | |
| 308 | - GValue gVal = { 0, }; | |
| 309 | - gtk_tree_model_get_value(model,&iter,1,&gVal); | |
| 310 | - guint iVal = g_value_get_uint(&gVal); | |
| 311 | - g_value_unset(&gVal); | |
| 312 | - | |
| 313 | - if(iVal == value) | |
| 314 | - { | |
| 315 | - gtk_combo_box_set_active_iter(widget->input.combos[combo],&iter); | |
| 316 | - break; | |
| 317 | - } | |
| 318 | - | |
| 319 | - } while(gtk_tree_model_iter_next(model,&iter)); | |
| 320 | - | |
| 321 | - | |
| 322 | - } | |
| 323 | - | |
| 324 | - } | |
| 325 | - | |
| 326 | -} | |
| 327 | - | |
| 328 | 212 | static void update_message(GtkWidget *widget, GtkWidget *terminal) |
| 329 | 213 | { |
| 330 | 214 | gtk_widget_set_sensitive(widget, lib3270_is_disconnected(v3270_get_session(terminal))); |
| ... | ... | @@ -342,6 +226,9 @@ static void V3270HostSelectWidget_class_init(G_GNUC_UNUSED V3270HostSelectWidget |
| 342 | 226 | |
| 343 | 227 | static void V3270HostSelectWidget_init(V3270HostSelectWidget *widget) |
| 344 | 228 | { |
| 229 | + // Cell renderer | |
| 230 | + GtkCellRenderer * text_renderer = gtk_cell_renderer_text_new(); | |
| 231 | + | |
| 345 | 232 | // Connection properties |
| 346 | 233 | GtkWidget * connection = gtk_grid_new(); |
| 347 | 234 | gtk_grid_set_row_spacing(GTK_GRID(connection),6); |
| ... | ... | @@ -398,8 +285,6 @@ static void V3270HostSelectWidget_init(V3270HostSelectWidget *widget) |
| 398 | 285 | |
| 399 | 286 | // Create combo boxes |
| 400 | 287 | { |
| 401 | - GtkCellRenderer * renderer = gtk_cell_renderer_text_new(); | |
| 402 | - | |
| 403 | 288 | size_t combo, item; |
| 404 | 289 | |
| 405 | 290 | for(combo = 0; combo < G_N_ELEMENTS(combos); combo++) { |
| ... | ... | @@ -411,8 +296,8 @@ static void V3270HostSelectWidget_init(V3270HostSelectWidget *widget) |
| 411 | 296 | if(combos[combo].tooltip) |
| 412 | 297 | gtk_widget_set_tooltip_markup(GTK_WIDGET(widget->input.combos[combo]),combos[combo].tooltip); |
| 413 | 298 | |
| 414 | - gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(widget->input.combos[combo]), renderer, TRUE); | |
| 415 | - gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(widget->input.combos[combo]), renderer, "text", 0, NULL); | |
| 299 | + gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(widget->input.combos[combo]), text_renderer, TRUE); | |
| 300 | + gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(widget->input.combos[combo]), text_renderer, "text", 0, NULL); | |
| 416 | 301 | |
| 417 | 302 | for(item = 0; combos[combo].labels[item]; item++) |
| 418 | 303 | { |
| ... | ... | @@ -427,6 +312,46 @@ static void V3270HostSelectWidget_init(V3270HostSelectWidget *widget) |
| 427 | 312 | |
| 428 | 313 | } |
| 429 | 314 | |
| 315 | + // Create Charset Combo | |
| 316 | + { | |
| 317 | + GtkTreeModel * model = (GtkTreeModel *) gtk_list_store_new(1,G_TYPE_STRING); | |
| 318 | + | |
| 319 | + widget->input.charset = GTK_COMBO_BOX(gtk_combo_box_new_with_model(model)); | |
| 320 | + | |
| 321 | + gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(widget->input.charset), text_renderer, TRUE); | |
| 322 | + gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(widget->input.charset), text_renderer, "text", 0, NULL); | |
| 323 | + | |
| 324 | + static const gchar * charsets[] = | |
| 325 | + { | |
| 326 | + "us", | |
| 327 | + "bracket", | |
| 328 | + "cp500" | |
| 329 | + }; | |
| 330 | + | |
| 331 | + size_t charset; | |
| 332 | + for(charset = 0; charset < G_N_ELEMENTS(charsets); charset++) | |
| 333 | + { | |
| 334 | + GtkTreeIter iter; | |
| 335 | + gtk_list_store_append((GtkListStore *) model, &iter); | |
| 336 | + gtk_list_store_set((GtkListStore *) model, &iter, 0, charsets[charset], -1); | |
| 337 | + }; | |
| 338 | + | |
| 339 | + static const struct v3270_entry_field descriptor = | |
| 340 | + { | |
| 341 | + .top = 1, | |
| 342 | + .left = 0, | |
| 343 | + .width = 2, | |
| 344 | + .height = 1, | |
| 345 | + | |
| 346 | + .label = N_("_Charset"), | |
| 347 | + .tooltip = N_("The EBCDIC host character set. "), | |
| 348 | + | |
| 349 | + }; | |
| 350 | + | |
| 351 | + v3270_grid_attach(GTK_GRID(emulation), &descriptor, GTK_WIDGET(widget->input.charset)); | |
| 352 | + | |
| 353 | + } | |
| 354 | + | |
| 430 | 355 | gtk_widget_show_all(GTK_WIDGET(widget)); |
| 431 | 356 | |
| 432 | 357 | } |
| ... | ... | @@ -446,9 +371,10 @@ LIB3270_EXPORT void v3270_select_host(GtkWidget *widget) |
| 446 | 371 | g_return_if_fail(GTK_IS_V3270(widget)); |
| 447 | 372 | |
| 448 | 373 | GtkWidget * dialog = v3270_settings_dialog_new(); |
| 374 | + GtkWidget * settings = v3270_host_select_new(); | |
| 449 | 375 | |
| 450 | - gtk_window_set_title(GTK_WINDOW(dialog), _("Host definition")); | |
| 451 | - gtk_container_add(GTK_CONTAINER(dialog), v3270_host_select_new()); | |
| 376 | + gtk_window_set_title(GTK_WINDOW(dialog), v3270_settings_get_title(settings)); | |
| 377 | + gtk_container_add(GTK_CONTAINER(dialog), settings); | |
| 452 | 378 | |
| 453 | 379 | gtk_window_set_transient_for(GTK_WINDOW(dialog),GTK_WINDOW(gtk_widget_get_toplevel(widget))); |
| 454 | 380 | gtk_window_set_modal(GTK_WINDOW(dialog),TRUE); |
| ... | ... | @@ -483,3 +409,173 @@ LIB3270_EXPORT void v3270_select_host(GtkWidget *widget) |
| 483 | 409 | gtk_widget_destroy(dialog); |
| 484 | 410 | |
| 485 | 411 | } |
| 412 | + | |
| 413 | +static void apply(GtkWidget *w, GtkWidget *terminal) | |
| 414 | +{ | |
| 415 | + debug("V3270HostSelectWidget::%s",__FUNCTION__); | |
| 416 | + | |
| 417 | + V3270HostSelectWidget *widget = GTK_V3270HostSelectWidget(w); | |
| 418 | + H3270 *hSession = v3270_get_session(terminal); | |
| 419 | + | |
| 420 | + // Apply URL | |
| 421 | + { | |
| 422 | + g_autofree gchar * url = | |
| 423 | + g_strconcat( | |
| 424 | + (gtk_toggle_button_get_active(widget->input.ssl) ? "tn3270s://" : "tn3270://"), | |
| 425 | + gtk_entry_get_text(widget->input.entry[ENTRY_HOSTNAME]), | |
| 426 | + ":", | |
| 427 | + gtk_entry_get_text(widget->input.entry[ENTRY_SRVCNAME]), | |
| 428 | + NULL | |
| 429 | + ); | |
| 430 | + | |
| 431 | + debug("URL=[%s]",url); | |
| 432 | + lib3270_set_url(hSession,url); | |
| 433 | + | |
| 434 | + } | |
| 435 | + | |
| 436 | + // Apply combos. | |
| 437 | + size_t combo; | |
| 438 | + for(combo = 0; combo < G_N_ELEMENTS(combos); combo++) | |
| 439 | + { | |
| 440 | + GtkTreeIter iter; | |
| 441 | + | |
| 442 | + if(gtk_combo_box_get_active_iter(GTK_COMBO_BOX(widget->input.combos[combo]), &iter)) | |
| 443 | + { | |
| 444 | + GValue value = { 0, }; | |
| 445 | + gtk_tree_model_get_value(gtk_combo_box_get_model(GTK_COMBO_BOX(widget->input.combos[combo])),&iter,1,&value); | |
| 446 | + | |
| 447 | + combos[combo].set(hSession,g_value_get_uint(&value)); | |
| 448 | + | |
| 449 | + g_value_unset(&value); | |
| 450 | + | |
| 451 | + } | |
| 452 | + } | |
| 453 | + | |
| 454 | + // Apply charset | |
| 455 | + { | |
| 456 | + GtkTreeIter iter; | |
| 457 | + | |
| 458 | + if(gtk_combo_box_get_active_iter(GTK_COMBO_BOX(widget->input.charset), &iter)) | |
| 459 | + { | |
| 460 | + GValue value = { 0, }; | |
| 461 | + gtk_tree_model_get_value(gtk_combo_box_get_model(GTK_COMBO_BOX(widget->input.charset)),&iter,0,&value); | |
| 462 | + | |
| 463 | + lib3270_set_host_charset(hSession,g_value_get_string(&value)); | |
| 464 | + | |
| 465 | + g_value_unset(&value); | |
| 466 | + | |
| 467 | + } | |
| 468 | + } | |
| 469 | + | |
| 470 | +} | |
| 471 | + | |
| 472 | +static void load(GtkWidget *w, GtkWidget *terminal) | |
| 473 | +{ | |
| 474 | + debug("V3270HostSelectWidget::%s",__FUNCTION__); | |
| 475 | + | |
| 476 | + H3270 *hSession = v3270_get_session(terminal); | |
| 477 | + V3270HostSelectWidget *widget = GTK_V3270HostSelectWidget(w); | |
| 478 | + | |
| 479 | + const gchar * u = lib3270_get_url(hSession); | |
| 480 | + | |
| 481 | + if(u) | |
| 482 | + { | |
| 483 | + | |
| 484 | + g_autofree gchar * url = g_strdup(u); | |
| 485 | + debug("URL=[%s]",url); | |
| 486 | + | |
| 487 | + gtk_toggle_button_set_active(widget->input.ssl,g_str_has_prefix(u,"tn3270s")); | |
| 488 | + | |
| 489 | + gchar *hostname = strstr(url,"://"); | |
| 490 | + if(!hostname) | |
| 491 | + { | |
| 492 | + g_message("Invalid URL: \"%s\" (no scheme)",url); | |
| 493 | + } | |
| 494 | + else | |
| 495 | + { | |
| 496 | + hostname += 3; | |
| 497 | + | |
| 498 | + gchar *srvcname = strchr(hostname,':'); | |
| 499 | + | |
| 500 | + if(srvcname) | |
| 501 | + { | |
| 502 | + *(srvcname++) = 0; | |
| 503 | + } | |
| 504 | + else | |
| 505 | + { | |
| 506 | + srvcname = "telnet"; | |
| 507 | + } | |
| 508 | + | |
| 509 | + gtk_entry_set_text(widget->input.entry[ENTRY_HOSTNAME],hostname); | |
| 510 | + gtk_entry_set_text(widget->input.entry[ENTRY_SRVCNAME],srvcname); | |
| 511 | + | |
| 512 | + } | |
| 513 | + | |
| 514 | + } | |
| 515 | + | |
| 516 | + // Load unsigned int combos | |
| 517 | + size_t combo; | |
| 518 | + for(combo = 0; combo < G_N_ELEMENTS(combos); combo++) | |
| 519 | + { | |
| 520 | + | |
| 521 | + GtkTreeModel * model = gtk_combo_box_get_model(widget->input.combos[combo]); | |
| 522 | + GtkTreeIter iter; | |
| 523 | + unsigned int value = combos[combo].get(hSession); | |
| 524 | + | |
| 525 | + if(gtk_tree_model_get_iter_first(model,&iter)) | |
| 526 | + { | |
| 527 | + do | |
| 528 | + { | |
| 529 | + GValue gVal = { 0, }; | |
| 530 | + gtk_tree_model_get_value(model,&iter,1,&gVal); | |
| 531 | + guint iVal = g_value_get_uint(&gVal); | |
| 532 | + g_value_unset(&gVal); | |
| 533 | + | |
| 534 | + if(iVal == value) | |
| 535 | + { | |
| 536 | + gtk_combo_box_set_active_iter(widget->input.combos[combo],&iter); | |
| 537 | + break; | |
| 538 | + } | |
| 539 | + | |
| 540 | + } while(gtk_tree_model_iter_next(model,&iter)); | |
| 541 | + | |
| 542 | + | |
| 543 | + } | |
| 544 | + | |
| 545 | + } | |
| 546 | + | |
| 547 | + // Load charset | |
| 548 | + { | |
| 549 | + const char * charset = lib3270_get_host_charset(hSession); | |
| 550 | + | |
| 551 | + if(charset) | |
| 552 | + { | |
| 553 | + GtkTreeModel * model = gtk_combo_box_get_model(widget->input.charset); | |
| 554 | + GtkTreeIter iter; | |
| 555 | + | |
| 556 | + if(gtk_tree_model_get_iter_first(model,&iter)) | |
| 557 | + { | |
| 558 | + do | |
| 559 | + { | |
| 560 | + GValue gVal = { 0, }; | |
| 561 | + gtk_tree_model_get_value(model,&iter,0,&gVal); | |
| 562 | + | |
| 563 | + if(!g_ascii_strcasecmp(charset,g_value_get_string(&gVal))) | |
| 564 | + { | |
| 565 | + gtk_combo_box_set_active_iter(widget->input.charset,&iter); | |
| 566 | + g_value_unset(&gVal); | |
| 567 | + break; | |
| 568 | + } | |
| 569 | + | |
| 570 | + g_value_unset(&gVal); | |
| 571 | + | |
| 572 | + } while(gtk_tree_model_iter_next(model,&iter)); | |
| 573 | + | |
| 574 | + } | |
| 575 | + | |
| 576 | + } | |
| 577 | + | |
| 578 | + } | |
| 579 | + | |
| 580 | +} | |
| 581 | + | ... | ... |