[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug-sourceinstall] PATCH [1/1] (dialog_configure): activate checkbox on
From: |
Claudio Fontana |
Subject: |
[bug-sourceinstall] PATCH [1/1] (dialog_configure): activate checkbox on entry change, and fix --prefix handling |
Date: |
Wed, 25 Jun 2008 21:51:45 +0200 |
User-agent: |
Thunderbird 2.0.0.12 (X11/20080213) |
Hello Nicola,
can you read and test this resulting changeset?
Thanks,
Claudio
ChangeLogs (sourceinstall-gtk)
2008-06-25 Claudio Fontana <address@hidden>
* dialog.c (in_old_configured): new function.
It checks whether an option key is contained in an old
"configured as" string.
* dialog.c (dialog_configure): use the new in_old_configured
function.
2008-06-25 Nicola Fontana <address@hidden> (tiny change)
automatically activate the check button
of an option on entering some data in its entry widget.
For packages which already have a configuration, prioritize
the old configure string, rather than the global --prefix
setting.
* dialog.c (dialog_configure): connect signal "changed" of text
entries. Check old_configure string before the global --prefix
setting. Some tiny esthetic changes.
* dialog.c (autocheck): new function, activates the checkbox
if its corresponding text entry contains non-empty text.
--- sourceinstall-gtk/dialog.c 23 Jun 2008 18:52:07 -0000 1.28
+++ sourceinstall-gtk/dialog.c 25 Jun 2008 19:31:04 -0000
@@ -478,6 +478,49 @@ int dialog_input_package2(const char *ti
return rv;
}
+/* Autocheck feature:
+ activates the check button of an option if its value is not empty. */
+static void autocheck(GtkWidget *entry, GtkWidget *check_button)
+{
+ const gchar *text;
+
+ text = gtk_entry_get_text(GTK_ENTRY(entry));
+
+ if (text[0] != '\0')
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_button), TRUE);
+}
+
+/* check whether a KEY is contained in an old configured string
+ (START), and set PARAM to contain the allocated parameter if any,
+ or (void *)0 otherwise. */
+static int in_old_configured(char *key, char *start, char **param)
+{
+ char *mark; size_t len;
+ len = strlen(key);
+ *param = 0;
+
+ while ((mark = strstr(start + 1, key))) {
+ /* an option string must always be preceded by a space,
+ and end with a space, a '=' or be the last (prefix) */
+ if (mark[-1] == ' ' && strlen(mark) >= len) {
+ if (mark[len] == '=') {
+ char *end;
+ *param = srcinst_strdup(mark + len + 1);
+ if ((end = strchr(*param, ' ')))
+ *end = '\0';
+ return 1;
+ }
+
+ if (mark[len] == ' ' || mark[len] == '\0') {
+ return 1;
+ }
+ }
+ start = mark;
+ }
+
+ return 0;
+}
+
/* show configuration dialog, return choices in the passed string list.
Return 0 if the user cancelled the operation.
Writes the chosen configuration strings to S, and if non-zero
@@ -562,73 +605,52 @@ int dialog_configure(struct srcinst_conf
for (j = 0; j < columns[i].set->count; j++) {
GtkWidget *horizontal, *label;
+ GtkWidget *entry, *check;
char *text;
char *key, *param, *comment;
horizontal = gtk_hbox_new(FALSE, 0);
- gtk_box_pack_start(GTK_BOX(vertical), horizontal, FALSE, FALSE,
- 0);
+ gtk_box_pack_start(GTK_BOX(vertical), horizontal, FALSE, FALSE, 0);
- columns[i].check_buttons[j] = gtk_check_button_new();
- columns[i].entries[j] = gtk_entry_new();
- gtk_box_pack_end(GTK_BOX(horizontal), columns[i].entries[j],
- FALSE, FALSE, 0);
+ columns[i].check_buttons[j] = check = gtk_check_button_new();
+ columns[i].entries[j] = entry = gtk_entry_new();
- gtk_entry_set_width_chars(GTK_ENTRY(columns[i].entries[j]),
+ gtk_box_pack_end(GTK_BOX(horizontal), entry, FALSE, FALSE, 0);
+
+ gtk_entry_set_width_chars(GTK_ENTRY(entry),
i == 5 ? 20 : i == 2 ? 15 : 10);
- gtk_box_pack_start(GTK_BOX(horizontal),
- columns[i].check_buttons[j], FALSE, FALSE,
- 0);
+ g_signal_connect(entry, "changed", G_CALLBACK(autocheck), check);
+ gtk_box_pack_start(GTK_BOX(horizontal), check, FALSE, FALSE, 0);
label = gtk_label_new(columns[i].set->options[j].key);
- gtk_container_add(GTK_CONTAINER(columns[i].check_buttons[j]),
- label);
+ gtk_container_add(GTK_CONTAINER(check), label);
key = columns[i].set->options[j].key;
param = columns[i].set->options[j].param;
comment = columns[i].set->options[j].comment;
- if (i == 5 && j == 0 && state.o.prefix) {
- /* pre set prefix option value */
- gtk_entry_set_text(GTK_ENTRY(columns[i].entries[j]),
- state.o.prefix);
-
- } else if (old_configured) {
- /* an option string (non-prefix) must always be preceded
- by a space, and end with a space or = */
-
- char *start; size_t len;
- start = strstr(old_configured, key);
- len = strlen(key);
-
- if (start && start > old_configured && start[-1] == ' ' &&
- strlen(start) > len &&
- (start[len] == ' ' || start[len] == '=')) {
-
- gtk_toggle_button_set_active(
- GTK_TOGGLE_BUTTON(columns[i].check_buttons[j]), TRUE);
-
- if (start[len] == '=') {
- char *end;
- start = srcinst_strdup(start + len + 1);
- if ((end = strchr(start, ' '))) {
- *end = 0;
- gtk_entry_set_text(GTK_ENTRY(columns[i].entries[j]),
- start);
- }
- free(start);
+ if (old_configured) {
+ char *param = 0;
+ if (in_old_configured(key, old_configured, ¶m)) {
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check),
+ TRUE);
+ if (param) {
+ gtk_entry_set_text(GTK_ENTRY(entry), param);
+ free(param);
}
}
+ } else if (i == 5 && j == 0 && state.o.prefix) {
+ /* pre set prefix option value */
+ gtk_entry_set_text(GTK_ENTRY(entry), state.o.prefix);
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check), FALSE);
}
- text =
- srcinst_strjoin(key, param ? " [" : "",
- param ? param : "", param ? "]\n" : "\n",
- comment ? comment : "", NULL);
+ text = srcinst_strjoin(key, param ? " [" : "",
+ param ? param : "", param ? "]\n" : "\n",
+ comment ? comment : "", NULL);
- gtk_tooltips_set_tip(GTK_TOOLTIPS(tips),
- columns[i].check_buttons[j], text, 0);
+ gtk_tooltips_set_tip(GTK_TOOLTIPS(tips), check, text, 0);
free(text);
}
- [bug-sourceinstall] PATCH [1/1] (dialog_configure): activate checkbox on entry change, and fix --prefix handling,
Claudio Fontana <=