diff options
Diffstat (limited to 'gtk-gui.c')
-rw-r--r-- | gtk-gui.c | 44 |
1 files changed, 34 insertions, 10 deletions
@@ -1437,7 +1437,11 @@ static GtkComboBox *dc_device_selector(GtkWidget *vbox) renderer = gtk_cell_renderer_text_new(); gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo_box), renderer, TRUE); - gtk_combo_box_set_active(GTK_COMBO_BOX(combo_box), default_index); + if (default_index != -1) + gtk_combo_box_set_active(GTK_COMBO_BOX(combo_box), default_index); + else + gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(combo_box))), + default_dive_computer_device); return GTK_COMBO_BOX(combo_box); } @@ -1551,9 +1555,16 @@ static GtkWidget *import_dive_computer(device_data_t *data, GtkDialog *dialog) return info; } +/* this prevents clicking the [x] button, while the import thread is still running */ +static void download_dialog_delete(GtkWidget *w, gpointer data) +{ + /* a no-op */ +} + void download_dialog(GtkWidget *w, gpointer data) { int result; + char *devname, *ns, *ne; GtkWidget *dialog, *button, *hbox, *vbox, *label, *info = NULL; GtkComboBox *computer, *device; GtkTreeIter iter; @@ -1567,6 +1578,7 @@ void download_dialog(GtkWidget *w, gpointer data) GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, NULL); + g_signal_connect(dialog, "delete-event", G_CALLBACK(download_dialog_delete), NULL); vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog)); label = gtk_label_new(_(" Please select dive computer and device. ")); @@ -1590,6 +1602,9 @@ repeat: GtkTreeModel *model; case GTK_RESPONSE_ACCEPT: + /* once the accept event is triggered the dialog becomes non-modal. + * lets re-set that */ + gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); if (info) gtk_widget_destroy(info); const char *vendor, *product; @@ -1608,17 +1623,26 @@ repeat: devicedata.descriptor = descriptor; devicedata.vendor = vendor; devicedata.product = product; - - if (!gtk_combo_box_get_active_iter(device, &iter)) - break; - - model = gtk_combo_box_get_model(device); - gtk_tree_model_get(model, &iter, - 0, &devicedata.devname, - -1); set_default_dive_computer(vendor, product); - set_default_dive_computer_device(devicedata.devname); + + /* get the device name from the combo box entry and set as default */ + devname = strdup(gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(device))))); + set_default_dive_computer_device(devname); + /* clear leading and trailing white space from the device name and also + * everything after (and including) the first '(' char. */ + ns = devname; + while (*ns == ' ' || *ns == '\t') + ns++; + ne = ns; + while (*ne && *ne != '(') + ne++; + *ne = '\0'; + if (ne > ns) + while (*(--ne) == ' ' || *ne == '\t') + *ne = '\0'; + devicedata.devname = ns; info = import_dive_computer(&devicedata, GTK_DIALOG(dialog)); + free((void *)devname); if (info) goto repeat; report_dives(TRUE); |