static void widget_table_input_by_items(variable *var) { GList *element; gchar *text; list_t *sliced; #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Entering.\n", __func__); #endif #if !GTK_CHECK_VERSION(3,0,0) /* gtk3: Deprecated in gtk2 and now gone */ g_assert(var->Attributes != NULL && var->Widget != NULL); text = attributeset_get_first(&element, var->Attributes, ATTR_ITEM); while (text != NULL) { sliced = linecutter(g_strdup(text), '|'); gtk_clist_append(GTK_CLIST(var->Widget), sliced->line); if (sliced) list_t_free(sliced); /* Free linecutter memory */ text = attributeset_get_next(&element, var->Attributes, ATTR_ITEM); } #endif #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Exiting.\n", __func__); #endif }
GtkWidget *widget_progressbar_create( AttributeSet *Attr, tag_attr *attr, gint Type) { GList *element; GtkWidget *widget; gchar *text; #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Entering.\n", __func__); #endif /* Thunor: This is all original code moved across when refactoring */ widget = gtk_progress_bar_new(); /* Thunor: This is all original code moved across when refactoring */ if (attributeset_is_avail(Attr, ATTR_LABEL)) { text = attributeset_get_first(&element, Attr, ATTR_LABEL); gtk_progress_bar_set_text(GTK_PROGRESS_BAR(widget), text); } #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Exiting.\n", __func__); #endif return widget; }
/*********************************************************************** * Refresh * ***********************************************************************/ void widget_menubar_refresh(variable *var) { GList *element; gchar *act; gint initialised = FALSE; #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Entering.\n", __func__); #endif /* Get initialised state of widget */ if (g_object_get_data(G_OBJECT(var->Widget), "_initialised") != NULL) initialised = (gint)g_object_get_data(G_OBJECT(var->Widget), "_initialised"); /* The <input> tag... */ act = attributeset_get_first(&element, var->Attributes, ATTR_INPUT); while (act) { if (input_is_shell_command(act)) widget_menubar_input_by_command(var, act + 8); /* input file stock = "File:", input file = "File:/path/to/file" */ if (strncasecmp(act, "file:", 5) == 0 && strlen(act) > 5) widget_menubar_input_by_file(var, act + 5); act = attributeset_get_next(&element, var->Attributes, ATTR_INPUT); } /* The <item> tags... */ if (attributeset_is_avail(var->Attributes, ATTR_ITEM)) widget_menubar_input_by_items(var); /* Initialise these only once at start-up */ if (!initialised) { /* Apply directives */ if (attributeset_is_avail(var->Attributes, ATTR_LABEL)) fprintf(stderr, "%s(): <label> not implemented for this widget.\n", __func__); if (attributeset_is_avail(var->Attributes, ATTR_DEFAULT)) fprintf(stderr, "%s(): <default> not implemented for this widget.\n", __func__); if (attributeset_is_avail(var->Attributes, ATTR_HEIGHT)) fprintf(stderr, "%s(): <height> not implemented for this widget.\n", __func__); if (attributeset_is_avail(var->Attributes, ATTR_WIDTH)) fprintf(stderr, "%s(): <width> not implemented for this widget.\n", __func__); if ((attributeset_cmp_left(var->Attributes, ATTR_SENSITIVE, "false")) || (attributeset_cmp_left(var->Attributes, ATTR_SENSITIVE, "disabled")) || /* Deprecated */ (attributeset_cmp_left(var->Attributes, ATTR_SENSITIVE, "no")) || (attributeset_cmp_left(var->Attributes, ATTR_SENSITIVE, "0"))) gtk_widget_set_sensitive(var->Widget, FALSE); /* Connect signals */ } #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Exiting.\n", __func__); #endif }
void widget_colorbutton_save(variable *var) { FILE *outfile; GdkColor color; GList *element; gchar *act; gchar *filename = NULL; #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Entering.\n", __func__); #endif /* We'll use the output file filename if available */ act = attributeset_get_first(&element, var->Attributes, ATTR_OUTPUT); while (act) { if (strncasecmp(act, "file:", 5) == 0 && strlen(act) > 5) { filename = act + 5; break; } act = attributeset_get_next(&element, var->Attributes, ATTR_OUTPUT); } /* If we have a valid filename then open it and dump the * widget's data to it */ if (filename) { if ((outfile = fopen(filename, "w"))) { gtk_color_button_get_color(GTK_COLOR_BUTTON(var->Widget), &color); if (gtk_color_button_get_use_alpha(GTK_COLOR_BUTTON(var->Widget))) { fprintf(outfile, "#%02x%02x%02x|%u", (color.red + 257 / 2) / 257, (color.green + 257 / 2) / 257, (color.blue + 257 / 2) / 257, gtk_color_button_get_alpha(GTK_COLOR_BUTTON(var->Widget))); } else { fprintf(outfile, "#%02x%02x%02x", (color.red + 257 / 2) / 257, (color.green + 257 / 2) / 257, (color.blue + 257 / 2) / 257); } /* Close the file */ fclose(outfile); } else { fprintf(stderr, "%s(): Couldn't open '%s' for writing.\n", __func__, filename); } } else { fprintf(stderr, "%s(): No <output file> directive found.\n", __func__); } #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Exiting.\n", __func__); #endif }
static void widget_pixmap_input_by_file(variable *var, char *filename) { GdkPixbuf *pixbuf; GList *element; gint width = -1, height = -1; #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Entering.\n", __func__); #endif if (attributeset_is_avail(var->Attributes, ATTR_WIDTH)) width = atoi(attributeset_get_first(&element, var->Attributes, ATTR_WIDTH)); if (attributeset_is_avail(var->Attributes, ATTR_HEIGHT)) height = atoi(attributeset_get_first(&element, var->Attributes, ATTR_HEIGHT)); if (width == -1 && height == -1) { /* Handle unscaled images */ gtk_image_set_from_file(GTK_IMAGE(var->Widget), find_pixmap(filename)); } else { /* Handle scaled images */ pixbuf = gdk_pixbuf_new_from_file_at_size( find_pixmap(filename), width, height, NULL); if (pixbuf) { gtk_image_set_from_pixbuf(GTK_IMAGE(var->Widget), pixbuf); /* pixbuf is no longer required and should be unreferenced */ g_object_unref(pixbuf); } else { /* pixbuf is null (file not found) so by using this * function gtk will substitute a broken image icon */ gtk_image_set_from_file(GTK_IMAGE(var->Widget), ""); } } #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Exiting.\n", __func__); #endif }
void widget_entry_save(variable *var) { FILE *outfile; GList *element; gchar *act; gchar *filename = NULL; const gchar *text; #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Entering.\n", __func__); #endif /* We'll use the output file filename if available */ act = attributeset_get_first(&element, var->Attributes, ATTR_OUTPUT); while (act) { if (strncasecmp(act, "file:", 5) == 0 && strlen(act) > 5) { filename = act + 5; break; } act = attributeset_get_next(&element, var->Attributes, ATTR_OUTPUT); } /* If we have a valid filename then open it and dump the * widget's data to it */ if (filename) { if ((outfile = fopen(filename, "w"))) { /* Thunor: This is all original code moved across when refactoring */ text = gtk_entry_get_text(GTK_ENTRY(var->Widget)); fprintf(outfile, "%s", text); /* Close the file */ fclose(outfile); } else { fprintf(stderr, "%s(): Couldn't open '%s' for writing.\n", __func__, filename); } } else { fprintf(stderr, "%s(): No <output file> directive found.\n", __func__); } #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Exiting.\n", __func__); #endif }
void widget_statusbar_save(variable *var) { FILE *outfile; GList *element; gchar *act; gchar *filename = NULL; gchar *last_push; #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Entering.\n", __func__); #endif /* We'll use the output file filename if available */ act = attributeset_get_first(&element, var->Attributes, ATTR_OUTPUT); while (act) { if (strncasecmp(act, "file:", 5) == 0 && strlen(act) > 5) { filename = act + 5; break; } act = attributeset_get_next(&element, var->Attributes, ATTR_OUTPUT); } /* If we have a valid filename then open it and dump the * widget's data to it */ if (filename) { if ((outfile = fopen(filename, "w"))) { last_push = g_object_get_data(G_OBJECT(var->Widget), "_last_push"); fprintf(outfile, "%s", last_push); fclose(outfile); } else { fprintf(stderr, "%s(): Couldn't open '%s' for writing.\n", __func__, filename); } } else { fprintf(stderr, "%s(): No <output file> directive found.\n", __func__); } #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Exiting.\n", __func__); #endif }
void widget_fontbutton_save(variable *var) { FILE *outfile; GList *element; gchar *act; gchar *filename = NULL; #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Entering.\n", __func__); #endif /* We'll use the output file filename if available */ act = attributeset_get_first(&element, var->Attributes, ATTR_OUTPUT); while (act) { if (strncasecmp(act, "file:", 5) == 0 && strlen(act) > 5) { filename = act + 5; break; } act = attributeset_get_next(&element, var->Attributes, ATTR_OUTPUT); } /* If we have a valid filename then open it and dump the * widget's data to it */ if (filename) { if ((outfile = fopen(filename, "w"))) { fprintf(outfile, "%s", gtk_font_button_get_font_name(GTK_FONT_BUTTON(var->Widget))); /* Close the file */ fclose(outfile); } else { fprintf(stderr, "%s(): Couldn't open '%s' for writing.\n", __func__, filename); } } else { fprintf(stderr, "%s(): No <output file> directive found.\n", __func__); } #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Exiting.\n", __func__); #endif }
gboolean widget_timer_timer_callback(gpointer data) { gchar retval = TRUE; GList *element; variable *var = (variable*)data; #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Entering.\n", __func__); #endif if (var && var->Widget) { #ifdef DEBUG_CONTENT /* ATTR_VARIABLE and "timer_id" will definitely exist */ fprintf(stderr, "%s(): ATTR_VARIABLE=%s timer-id=%u\n", __func__, attributeset_get_first(&element, var->Attributes, ATTR_VARIABLE), (guint)g_object_get_data(G_OBJECT(var->Widget), "_timer-id")); #endif /* Generate a custom signal if sensitive is true */ #if GTK_CHECK_VERSION(2,18,0) if (gtk_widget_get_sensitive(var->Widget)) #else if (GTK_WIDGET_SENSITIVE(var->Widget)) #endif { widget_signal_executor(var->Widget, var->Attributes, "tick"); } } else { /* The widget has been dropped/destroyed so kill the callback */ retval = FALSE; } #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Exiting.\n", __func__); #endif return retval; }
static void widget_hscale_input_by_items(variable *var) { GList *element; gchar *text; gdouble value; gint position, count; #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Entering.\n", __func__); #endif #if GTK_CHECK_VERSION(2,16,0) g_assert(var->Attributes != NULL && var->Widget != NULL); text = attributeset_get_first(&element, var->Attributes, ATTR_ITEM); while (text) { /* sscanf is good for the first two values */ if (sscanf(text, "%lf | %d", &value, &position) == 2) { /* Now we'll position on the markup or the terminating zero */ count = 0; while (*text != 0 && count < 2) { if (*text == '|') count++; text++; } #ifdef DEBUG_CONTENT printf("%s: value=%.16f position=%i markup='%s'\n", __func__, value, position, text); #endif gtk_scale_add_mark(GTK_SCALE(var->Widget), value, position, text); } text = attributeset_get_next(&element, var->Attributes, ATTR_ITEM); } #endif #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Exiting.\n", __func__); #endif }
void widget_progressbar_realized_callback(GtkWidget *widget, AttributeSet *Attr) { GList *element; progr_descr *descr; gchar *input; #ifdef DEBUG g_message("%s(%p, %p);", __func__, widget, Attr); #endif g_assert(GTK_IS_WIDGET(widget) && Attr != NULL); /* * If there is no input, we can return. */ if (!attributeset_is_avail(Attr, ATTR_INPUT)) return; /* * Creating the descriptor from the first input. */ input = attributeset_get_first(&element, Attr, ATTR_INPUT); descr = g_new0(progr_descr, 1); descr->Attr = Attr; descr->widget = widget; descr->shell_command = input_get_shell_command(input); descr->pipe = widget_opencommand(descr->shell_command); /* * When the widget gets destroyed we call this function to prevent * further reading the pipe and setting the destroyed progress bar. */ g_object_set_data_full(G_OBJECT(widget), "descriptor", descr, (GDestroyNotify)widget_progressbar_descriptor_destroy_notify); /* * Now we can fire up the reader thread. */ descr->thread = g_thread_create( (GThreadFunc) widget_progressbar_thread_entry, descr, FALSE, NULL); }
void widget_hscale_save(variable *var) { FILE *outfile; GList *element; gchar *act; gchar *filename = NULL; gdouble value; guint digits; #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Entering.\n", __func__); #endif /* We'll use the output file filename if available */ act = attributeset_get_first(&element, var->Attributes, ATTR_OUTPUT); while (act) { if (strncasecmp(act, "file:", 5) == 0 && strlen(act) > 5) { filename = act + 5; break; } act = attributeset_get_next(&element, var->Attributes, ATTR_OUTPUT); } /* If we have a valid filename then open it and dump the * widget's data to it */ if (filename) { if ((outfile = fopen(filename, "w"))) { digits = gtk_scale_get_digits(GTK_SCALE(var->Widget)); value = gtk_range_get_value(GTK_RANGE(var->Widget)); switch (digits) { case 0: fprintf(outfile, "%.0f", value); break; case 1: fprintf(outfile, "%.1f", value); break; case 2: fprintf(outfile, "%.2f", value); break; case 3: fprintf(outfile, "%.3f", value); break; case 4: fprintf(outfile, "%.4f", value); break; case 5: fprintf(outfile, "%.5f", value); break; case 6: fprintf(outfile, "%.6f", value); break; case 7: fprintf(outfile, "%.7f", value); break; case 8: fprintf(outfile, "%.8f", value); break; case 9: fprintf(outfile, "%.9f", value); break; case 10: fprintf(outfile, "%.10f", value); break; case 11: fprintf(outfile, "%.11f", value); break; case 12: fprintf(outfile, "%.12f", value); break; case 13: fprintf(outfile, "%.13f", value); break; case 14: fprintf(outfile, "%.14f", value); break; case 15: fprintf(outfile, "%.15f", value); break; case 16: fprintf(outfile, "%.16f", value); break; /* Is there much point going beyond 16? */ default: fprintf(outfile, "%f", value); break; } fclose(outfile); } else { fprintf(stderr, "%s(): Couldn't open '%s' for writing.\n", __func__, filename); } } else { fprintf(stderr, "%s(): No <output file> directive found.\n", __func__); } #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Exiting.\n", __func__); #endif }
void widget_hscale_refresh(variable *var) { GList *element; gchar *act; gint initialised = FALSE; #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Entering.\n", __func__); #endif /* Get initialised state of widget */ if (g_object_get_data(G_OBJECT(var->Widget), "_initialised") != NULL) initialised = (gint)g_object_get_data(G_OBJECT(var->Widget), "_initialised"); /* The <input> tag... */ act = attributeset_get_first(&element, var->Attributes, ATTR_INPUT); while (act) { if (input_is_shell_command(act)) widget_hscale_input_by_command(var, act + 8); /* input file stock = "File:", input file = "File:/path/to/file" */ if (strncasecmp(act, "file:", 5) == 0 && strlen(act) > 5) { if (!initialised) { /* Check for file-monitor and create if requested */ widget_file_monitor_try_create(var, act + 5); } widget_hscale_input_by_file(var, act + 5); } act = attributeset_get_next(&element, var->Attributes, ATTR_INPUT); } /* The <item> tags... */ if (attributeset_is_avail(var->Attributes, ATTR_ITEM)) { #if GTK_CHECK_VERSION(2,16,0) gtk_scale_clear_marks(GTK_SCALE(var->Widget)); #endif widget_hscale_input_by_items(var); } /* Initialise these only once at start-up */ if (!initialised) { /* Apply directives */ if (attributeset_is_avail(var->Attributes, ATTR_LABEL)) fprintf(stderr, "%s(): <label> not implemented for this widget.\n", __func__); if (attributeset_is_avail(var->Attributes, ATTR_DEFAULT)) { gtk_range_set_value(GTK_RANGE(var->Widget), atof(attributeset_get_first(&element, var->Attributes, ATTR_DEFAULT))); } if (attributeset_is_avail(var->Attributes, ATTR_HEIGHT)) fprintf(stderr, "%s(): <height> not implemented for this widget.\n", __func__); if (attributeset_is_avail(var->Attributes, ATTR_WIDTH)) fprintf(stderr, "%s(): <width> not implemented for this widget.\n", __func__); if ((attributeset_cmp_left(var->Attributes, ATTR_SENSITIVE, "false")) || (attributeset_cmp_left(var->Attributes, ATTR_SENSITIVE, "disabled")) || /* Deprecated */ (attributeset_cmp_left(var->Attributes, ATTR_SENSITIVE, "no")) || (attributeset_cmp_left(var->Attributes, ATTR_SENSITIVE, "0"))) gtk_widget_set_sensitive(var->Widget, FALSE); /* Connect signals */ g_signal_connect(G_OBJECT(var->Widget), "value-changed", G_CALLBACK(on_any_widget_value_changed_event), (gpointer)var->Attributes); } #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Exiting.\n", __func__); #endif }
/*********************************************************************** * Refresh * ***********************************************************************/ void widget_timer_refresh(variable *var) { GList *element; gchar *act; gchar text[256]; gchar *value; gint initialised = FALSE; gint milliseconds = FALSE; guint interval = 1; guint timer_id; #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Entering.\n", __func__); #endif /* Get initialised state of widget */ if (g_object_get_data(G_OBJECT(var->Widget), "_initialised") != NULL) initialised = (gint)g_object_get_data(G_OBJECT(var->Widget), "_initialised"); /* The <input> tag... */ act = attributeset_get_first(&element, var->Attributes, ATTR_INPUT); while (act) { if (input_is_shell_command(act)) widget_timer_input_by_command(var, act + 8); /* input file stock = "File:", input file = "File:/path/to/file" */ if (strncasecmp(act, "file:", 5) == 0 && strlen(act) > 5) { if (!initialised) { /* Check for file-monitor and create if requested */ widget_file_monitor_try_create(var, act + 5); } widget_timer_input_by_file(var, act + 5); } act = attributeset_get_next(&element, var->Attributes, ATTR_INPUT); } /* The <item> tags... */ if (attributeset_is_avail(var->Attributes, ATTR_ITEM)) widget_timer_input_by_items(var); /* Initialise these only once at start-up */ if (!initialised) { /* Create the timer */ if (var->widget_tag_attr && (value = get_tag_attribute(var->widget_tag_attr, "milliseconds")) && ((strcasecmp(value, "true") == 0) || (strcasecmp(value, "yes") == 0) || (atoi(value) == 1))) { milliseconds = TRUE; interval = 1000; /* Set default of 1000ms */ } if (var->widget_tag_attr && (value = get_tag_attribute(var->widget_tag_attr, "interval"))) { interval = atoi(value); } if (milliseconds) { /* Precision in milliseconds */ timer_id = g_timeout_add( interval, widget_timer_timer_callback, (gpointer)var); } else { /* Precision in seconds (default) */ timer_id = g_timeout_add_seconds( interval, widget_timer_timer_callback, (gpointer)var); } /* Store the timer_id as a piece of widget data */ g_object_set_data(G_OBJECT(var->Widget), "_timer-id", (gpointer)timer_id); /* Set the text of the label to its variable name */ sprintf(text, "<span fgcolor='white' bgcolor='darkred'> %s </span>", attributeset_get_first(&element, var->Attributes, ATTR_VARIABLE)); gtk_label_set_markup(GTK_LABEL(var->Widget), text); /* Apply directives */ if (attributeset_is_avail(var->Attributes, ATTR_LABEL)) fprintf(stderr, "%s(): <label> not implemented for this widget.\n", __func__); if (attributeset_is_avail(var->Attributes, ATTR_DEFAULT)) fprintf(stderr, "%s(): <default> not implemented for this widget.\n", __func__); if (attributeset_is_avail(var->Attributes, ATTR_HEIGHT)) fprintf(stderr, "%s(): <height> not implemented for this widget.\n", __func__); if (attributeset_is_avail(var->Attributes, ATTR_WIDTH)) fprintf(stderr, "%s(): <width> not implemented for this widget.\n", __func__); if ((attributeset_cmp_left(var->Attributes, ATTR_SENSITIVE, "false")) || (attributeset_cmp_left(var->Attributes, ATTR_SENSITIVE, "disabled")) || /* Deprecated */ (attributeset_cmp_left(var->Attributes, ATTR_SENSITIVE, "no")) || (attributeset_cmp_left(var->Attributes, ATTR_SENSITIVE, "0"))) gtk_widget_set_sensitive(var->Widget, FALSE); /* Connect signals */ } #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Exiting.\n", __func__); #endif }
/*********************************************************************** * Create * ***********************************************************************/ GtkWidget *widget_table_create( AttributeSet *Attr, tag_attr *attr, gint Type) { GList *element; GtkWidget *widget; gchar *value; gint column; gint sort_function; list_t *sliced; #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Entering.\n", __func__); #endif #if !GTK_CHECK_VERSION(3,0,0) /* gtk3: Deprecated in gtk2 and now gone */ if (attributeset_is_avail(Attr, ATTR_LABEL)) { sliced = linecutter(g_strdup(attributeset_get_first( &element, Attr, ATTR_LABEL)), '|'); widget = gtk_clist_new_with_titles(sliced->n_lines, sliced->line); if (sliced) list_t_free(sliced); /* Free linecutter memory */ } else { widget = gtk_clist_new(1); /* 1 column */ } if (attr) { /* Get sort-function (custom) */ if ((value = get_tag_attribute(attr, "sort-function"))) { sort_function = atoi(value); if (sort_function == 1) { gtk_clist_set_compare_func(GTK_CLIST(widget), widget_table_natcmp); } else if (sort_function == 2) { gtk_clist_set_compare_func(GTK_CLIST(widget), widget_table_natcasecmp); } } /* Get sort-type (auto-sort will require this preset) */ if ((value = get_tag_attribute(attr, "sort-type"))) { gtk_clist_set_sort_type(GTK_CLIST(widget), atoi(value)); } /* Get sort-column (custom) */ if ((value = get_tag_attribute(attr, "sort-column"))) { gtk_clist_set_sort_column(GTK_CLIST(widget), atoi(value)); } /* Get auto-sort (custom) */ if ((value = get_tag_attribute(attr, "auto-sort")) && ((strcasecmp(value, "true") == 0) || (strcasecmp(value, "yes") == 0) || (atoi(value) == 1))) { gtk_clist_set_auto_sort(GTK_CLIST(widget), TRUE); } else { gtk_clist_set_auto_sort(GTK_CLIST(widget), FALSE); } /* Get column-header-active (custom) */ if ((value = get_tag_attribute(attr, "column-header-active"))) { sliced = linecutter(g_strdup(value), '|'); for (column = 0; column < sliced->n_lines; column++) { if ((strcasecmp(sliced->line[column], "true") == 0) || (strcasecmp(sliced->line[column], "yes") == 0) || (atoi(sliced->line[column]) == 1)) { gtk_clist_column_title_active(GTK_CLIST(widget), column); } else { gtk_clist_column_title_passive(GTK_CLIST(widget), column); } } if (sliced) list_t_free(sliced); /* Free linecutter memory */ } /* Get column-visible (custom) */ if ((value = get_tag_attribute(attr, "column-visible"))) { sliced = linecutter(g_strdup(value), '|'); for (column = 0; column < sliced->n_lines; column++) { if ((strcasecmp(sliced->line[column], "true") == 0) || (strcasecmp(sliced->line[column], "yes") == 0) || (atoi(sliced->line[column]) == 1)) { gtk_clist_set_column_visibility(GTK_CLIST(widget), column, TRUE); } else { gtk_clist_set_column_visibility(GTK_CLIST(widget), column, FALSE); } } if (sliced) list_t_free(sliced); /* Free linecutter memory */ } } #else fprintf(stderr, "%s(): The table (GtkCList) widget has been removed from GTK+ 3 and tree is recommended as a replacement.\n", __func__); exit(EXIT_FAILURE); #endif #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Exiting.\n", __func__); #endif return widget; }
GtkWidget *widget_pixmap_create( AttributeSet *Attr, tag_attr *attr, gint Type) { GError *error = NULL; GList *element; GtkIconTheme *icon_theme; GtkWidget *widget = NULL; GdkPixbuf *pixbuf; gchar *act; gchar *file_name; gchar *icon_name = NULL; gchar *stock_name = NULL; gchar *value; gint width = -1, height = -1; gint theme_icon_size = 32; gint stock_icon_size = GTK_ICON_SIZE_DND; #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Entering.\n", __func__); #endif if (attributeset_is_avail(Attr, ATTR_HEIGHT)) height = atoi(attributeset_get_first(&element, Attr, ATTR_HEIGHT)); if (attributeset_is_avail(Attr, ATTR_WIDTH)) width = atoi(attributeset_get_first(&element, Attr, ATTR_WIDTH)); /* The <input> tag... */ act = attributeset_get_first(&element, Attr, ATTR_INPUT); while (act) { #ifdef DEBUG_CONTENT fprintf(stderr, "%s(): act=%s\n", __func__, act); #endif /* input file stock = "File:", input file = "File:/path/to/file" */ if (strncasecmp(act, "file:", 5) == 0) { if ((stock_name = attributeset_get_this_tagattr(&element, Attr, ATTR_INPUT, "stock")) != NULL) { /* Get stock-icon-size (custom) */ if (attr && (value = get_tag_attribute(attr, "stock-icon-size"))) stock_icon_size = atoi(value); widget = gtk_image_new_from_stock(stock_name, stock_icon_size); break; /* Only one image is required */ } if ((icon_name = attributeset_get_this_tagattr(&element, Attr, ATTR_INPUT, "icon")) != NULL) { icon_theme = gtk_icon_theme_get_default(); /* Use the height or width dimension to override the default size */ if (height > -1) theme_icon_size = height; else if (width > -1) theme_icon_size = width; /* Get theme-icon-size (custom) */ if (attr && (value = get_tag_attribute(attr, "theme-icon-size"))) theme_icon_size = atoi(value); pixbuf = gtk_icon_theme_load_icon(icon_theme, icon_name, theme_icon_size, 0, &error); if (pixbuf) { widget = gtk_image_new_from_pixbuf(pixbuf); /* pixbuf is no longer required and should be unreferenced */ g_object_unref(pixbuf); } else { /* pixbuf is null (file not found) so by using this * function gtk will substitute a broken image icon */ widget = gtk_image_new_from_file(""); } break; /* Only one image is required */ } if (strlen(act) > 5) { file_name = act + 5; if (width == -1 && height == -1) { /* Handle unscaled images */ widget = gtk_image_new_from_file(find_pixmap(file_name)); } else { /* Handle scaled images */ pixbuf = gdk_pixbuf_new_from_file_at_size( find_pixmap(file_name), width, height, NULL); if (pixbuf) { widget = gtk_image_new_from_pixbuf(pixbuf); /* pixbuf is no longer required and should be unreferenced */ g_object_unref(pixbuf); } else { /* pixbuf is null (file not found) so by using this * function gtk will substitute a broken image icon */ widget = gtk_image_new_from_file(""); } } break; /* Only one image is required */ } } act = attributeset_get_next(&element, Attr, ATTR_INPUT); } if (widget == NULL) { /* No input file directive found so by using this * function gtk will substitute a broken image icon */ widget = gtk_image_new_from_file(""); } #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Exiting.\n", __func__); #endif return widget; }
void widget_table_save(variable *var) { FILE *outfile; GList *element; gchar *act; gchar *filename = NULL; gchar *line; gchar *string; gchar *text; gint column, columnmax; gint retval; gint row = 0; #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Entering.\n", __func__); #endif #if !GTK_CHECK_VERSION(3,0,0) /* gtk3: Deprecated in gtk2 and now gone */ /* We'll use the output file filename if available */ act = attributeset_get_first(&element, var->Attributes, ATTR_OUTPUT); while (act) { if (strncasecmp(act, "file:", 5) == 0 && strlen(act) > 5) { filename = act + 5; break; } act = attributeset_get_next(&element, var->Attributes, ATTR_OUTPUT); } /* If we have a valid filename then open it and dump the * widget's data to it */ if (filename) { if ((outfile = fopen(filename, "w"))) { g_object_get(G_OBJECT(var->Widget), "n-columns", &columnmax, NULL); /* Where's the GtkCList row count? It's not such a problem as * gtk_clist_get_text() returns 0 if it's not available at which * point we'll stop */ retval = gtk_clist_get_text(GTK_CLIST(var->Widget), row, 0, &string); while (retval) { line = g_strdup(""); for (column = 0; column < columnmax; column++) { /* Do not free string, it is not newly allocated */ gtk_clist_get_text(GTK_CLIST(var->Widget), row, column, &string); if (column == 0) { text = g_strconcat(line, string, NULL); } else { text = g_strconcat(line, "|", string, NULL); } g_free(line); line = text; } if (row == 0) { fprintf(outfile, "%s", text); } else { fprintf(outfile, "\n%s", text); } g_free(text); row++; retval = gtk_clist_get_text(GTK_CLIST(var->Widget), row, 0, &string); } fclose(outfile); } else { fprintf(stderr, "%s(): Couldn't open '%s' for writing.\n", __func__, filename); } } else { fprintf(stderr, "%s(): No <output file> directive found.\n", __func__); } #endif #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Exiting.\n", __func__); #endif }
/*********************************************************************** * Refresh * ***********************************************************************/ void widget_table_refresh(variable *var) { GList *element; gchar *act; gchar *value; gint freeze_thaw = FALSE; gint initialised = FALSE; gint selected_row; #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Entering.\n", __func__); #endif #if !GTK_CHECK_VERSION(3,0,0) /* gtk3: Deprecated in gtk2 and now gone */ /* Get initialised state of widget */ if (g_object_get_data(G_OBJECT(var->Widget), "_initialised") != NULL) initialised = (gint)g_object_get_data(G_OBJECT(var->Widget), "_initialised"); if (var->widget_tag_attr) { /* Get freeze-thaw (custom) */ if ((value = get_tag_attribute(var->widget_tag_attr, "freeze-thaw")) && ((strcasecmp(value, "true") == 0) || (strcasecmp(value, "yes") == 0) || (atoi(value) == 1))) { freeze_thaw = TRUE; gtk_clist_freeze(GTK_CLIST(var->Widget)); } } /* The <input> tag... */ act = attributeset_get_first(&element, var->Attributes, ATTR_INPUT); while (act) { if (input_is_shell_command(act)) widget_table_input_by_command(var, act + 8, TRUE); /* input file stock = "File:", input file = "File:/path/to/file" */ if (strncasecmp(act, "file:", 5) == 0 && strlen(act) > 5) { if (!initialised) { /* Check for file-monitor and create if requested */ widget_file_monitor_try_create(var, act + 5); } widget_table_input_by_file(var, act + 5); } act = attributeset_get_next(&element, var->Attributes, ATTR_INPUT); } /* The <item> tags... */ if (attributeset_is_avail(var->Attributes, ATTR_ITEM)) widget_table_input_by_items(var); /* Initialise these only once at start-up */ if (!initialised) { /* Apply directives */ if (attributeset_is_avail(var->Attributes, ATTR_DEFAULT)) fprintf(stderr, "%s(): <default> not implemented for this widget.\n", __func__); if ((attributeset_cmp_left(var->Attributes, ATTR_SENSITIVE, "false")) || (attributeset_cmp_left(var->Attributes, ATTR_SENSITIVE, "disabled")) || /* Deprecated */ (attributeset_cmp_left(var->Attributes, ATTR_SENSITIVE, "no")) || (attributeset_cmp_left(var->Attributes, ATTR_SENSITIVE, "0"))) gtk_widget_set_sensitive(var->Widget, FALSE); /* Connect signals */ g_signal_connect(G_OBJECT(var->Widget), "select-row", G_CALLBACK(on_any_widget_select_row_event), (gpointer)var->Attributes); g_signal_connect(G_OBJECT(var->Widget), "click-column", G_CALLBACK(widget_table_click_column_callback), (gpointer)var); } /* Thaw a freeze? */ if (freeze_thaw) gtk_clist_thaw(GTK_CLIST(var->Widget)); if (var->widget_tag_attr) { /* Get columns-autosize (custom) Redundant: Works weirdly on initialisation. if ((value = get_tag_attribute(var->widget_tag_attr, "columns-autosize")) && ((strcasecmp(value, "true") == 0) || (strcasecmp(value, "yes") == 0) || (atoi(value) == 1))) { gtk_clist_columns_autosize(GTK_CLIST(var->Widget)); } */ /* Get selected-row (custom) */ if ((value = get_tag_attribute(var->widget_tag_attr, "selected-row"))) { selected_row = atoi(value); if (selected_row >= 0) gtk_clist_select_row(GTK_CLIST(var->Widget), selected_row, 0); } } #endif #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Exiting.\n", __func__); #endif }
/*********************************************************************** * Create * ***********************************************************************/ GtkWidget *widget_window_create( AttributeSet *Attr, tag_attr *attr, gint Type) { gchar *value; GError *error = NULL; GList *accel_group = NULL; GList *element; gint border_width; GtkWidget *widget; stackelement s; #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Entering.\n", __func__); #endif /* Create the window widget */ widget = gtk_window_new(GTK_WINDOW_TOPLEVEL); /* Set a default window title */ attributeset_set_if_unset(Attr, ATTR_LABEL, PACKAGE); gtk_window_set_title(GTK_WINDOW(widget), attributeset_get_first(&element, Attr, ATTR_LABEL)); /* Set a default title bar theme icon */ gtk_window_set_icon_name(GTK_WINDOW(widget), PACKAGE); /* If requested set a title bar image by filename */ if (attr) { if ((value = get_tag_attribute(attr, "image-name"))) gtk_window_set_icon_from_file(GTK_WINDOW(widget), find_pixmap(value), &error); } /* Set a default border width */ border_width = 5; if (attr && (value = get_tag_attribute(attr, "margin"))) /* Deprecated */ border_width = atoi(value); gtk_container_set_border_width(GTK_CONTAINER(widget), border_width); /* If we have geometry given in the command line, we set that */ if (have_geometry_dxdy) gtk_widget_set_usize(widget, geometry_dx, geometry_dy); if (have_geometry_xy) gtk_widget_set_uposition(widget, geometry_x, geometry_y); if (option_centering) gtk_window_set_position(GTK_WINDOW(widget), GTK_WIN_POS_CENTER_ALWAYS); /* Pop the widgets that the window will contain and add them */ s = pop(); gtk_container_add(GTK_CONTAINER(widget), s.widgets[0]); /* Thunor: Each menu created will have an accelerator group * for its menuitems which will require adding to the window */ if (accel_groups) { accel_group = g_list_first(accel_groups); while (accel_group) { gtk_window_add_accel_group(GTK_WINDOW(widget), GTK_ACCEL_GROUP(accel_group->data)); #ifdef DEBUG fprintf(stderr, "%s: Adding accel_group=%p to window\n", __func__, accel_group->data); #endif accel_group = accel_group->next; } g_list_free(accel_groups); accel_groups = NULL; } #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Exiting.\n", __func__); #endif return widget; }
/*********************************************************************** * Refresh * ***********************************************************************/ void widget_colorbutton_refresh(variable *var) { GdkColor color; GList *element; gchar *act; gint initialised = FALSE; guint alpha; list_t *values = NULL; #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Entering.\n", __func__); #endif /* Get initialised state of widget */ if (g_object_get_data(G_OBJECT(var->Widget), "_initialised") != NULL) initialised = (gint)g_object_get_data(G_OBJECT(var->Widget), "_initialised"); /* The <input> tag... */ act = attributeset_get_first(&element, var->Attributes, ATTR_INPUT); while (act) { if (input_is_shell_command(act)) widget_colorbutton_input_by_command(var, act + 8); /* input file stock = "File:", input file = "File:/path/to/file" */ if (strncasecmp(act, "file:", 5) == 0 && strlen(act) > 5) { if (!initialised) { /* Check for file-monitor and create if requested */ widget_file_monitor_try_create(var, act + 5); } widget_colorbutton_input_by_file(var, act + 5); } act = attributeset_get_next(&element, var->Attributes, ATTR_INPUT); } /* The <item> tags... */ if (attributeset_is_avail(var->Attributes, ATTR_ITEM)) widget_colorbutton_input_by_items(var); /* Initialise these only once at start-up */ if (!initialised) { /* Apply directives */ if (attributeset_is_avail(var->Attributes, ATTR_LABEL)) fprintf(stderr, "%s(): <label> not implemented for this widget.\n", __func__); if (attributeset_is_avail(var->Attributes, ATTR_DEFAULT)) { values = linecutter(g_strdup(attributeset_get_first(&element, var->Attributes, ATTR_DEFAULT)), '|'); if (values->n_lines > 0) { /* Parse the RGB value to create the necessary GdkColor. * This function doesn't like trailing whitespace so it * needs to be stripped first with g_strstrip() */ if (gdk_color_parse(g_strstrip(values->line[0]), &color)) { #ifdef DEBUG_CONTENT fprintf(stderr, "%s:() valid colour found\n", __func__); #endif gtk_color_button_set_color(GTK_COLOR_BUTTON(var->Widget), &color); } } if (values->n_lines > 1) { /* Read alpha as an unsigned decimal integer */ if (sscanf(values->line[1], "%u", &alpha) == 1) { #ifdef DEBUG_CONTENT fprintf(stderr, "%s:() valid alpha=%u found\n", __func__, alpha); #endif /* This requires use-alpha="true" */ gtk_color_button_set_alpha(GTK_COLOR_BUTTON(var->Widget), alpha); } } /* Free linecutter memory */ if (values) list_t_free(values); } if (attributeset_is_avail(var->Attributes, ATTR_HEIGHT)) fprintf(stderr, "%s(): <height> not implemented for this widget.\n", __func__); if (attributeset_is_avail(var->Attributes, ATTR_WIDTH)) fprintf(stderr, "%s(): <width> not implemented for this widget.\n", __func__); if ((attributeset_cmp_left(var->Attributes, ATTR_SENSITIVE, "false")) || (attributeset_cmp_left(var->Attributes, ATTR_SENSITIVE, "disabled")) || /* Deprecated */ (attributeset_cmp_left(var->Attributes, ATTR_SENSITIVE, "no")) || (attributeset_cmp_left(var->Attributes, ATTR_SENSITIVE, "0"))) gtk_widget_set_sensitive(var->Widget, FALSE); /* Connect signals */ g_signal_connect(G_OBJECT(var->Widget), "color-set", G_CALLBACK(on_any_widget_color_set_event), (gpointer)var->Attributes); } #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Exiting.\n", __func__); #endif }
void widget_entry_refresh(variable *var) { GList *element; gchar *act; gint initialised = FALSE; #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Entering.\n", __func__); #endif /* Get initialised state of widget */ if (g_object_get_data(G_OBJECT(var->Widget), "_initialised") != NULL) initialised = (gint)g_object_get_data(G_OBJECT(var->Widget), "_initialised"); /* The <input> tag... */ act = attributeset_get_first(&element, var->Attributes, ATTR_INPUT); while (act) { if (input_is_shell_command(act)) widget_entry_input_by_command(var, act + 8); /* input file stock = "File:", input file = "File:/path/to/file" */ if (strncasecmp(act, "file:", 5) == 0 && strlen(act) > 5) { if (!initialised) { /* Check for file-monitor and create if requested */ widget_file_monitor_try_create(var, act + 5); } widget_entry_input_by_file(var, act + 5); } act = attributeset_get_next(&element, var->Attributes, ATTR_INPUT); } /* The <item> tags... */ if (attributeset_is_avail(var->Attributes, ATTR_ITEM)) widget_entry_input_by_items(var); /* Initialise these only once at start-up */ if (!initialised) { /* Apply directives */ if (attributeset_is_avail(var->Attributes, ATTR_LABEL)) fprintf(stderr, "%s(): <label> not implemented for this widget.\n", __func__); if (attributeset_is_avail(var->Attributes, ATTR_DEFAULT)) { /* Thunor: This is all original code moved across when refactoring */ gtk_entry_set_text(GTK_ENTRY(var->Widget), attributeset_get_first( &element, var->Attributes, ATTR_DEFAULT)); } if (attributeset_is_avail(var->Attributes, ATTR_HEIGHT) && attributeset_is_avail(var->Attributes, ATTR_WIDTH)) { /* Thunor: This is all original code moved across when refactoring */ gtk_widget_set_usize(var->Widget, atoi(attributeset_get_first(&element, var->Attributes, ATTR_WIDTH)), atoi(attributeset_get_first(&element, var->Attributes, ATTR_HEIGHT))); } if ((attributeset_cmp_left(var->Attributes, ATTR_SENSITIVE, "false")) || (attributeset_cmp_left(var->Attributes, ATTR_SENSITIVE, "disabled")) || /* Deprecated */ (attributeset_cmp_left(var->Attributes, ATTR_SENSITIVE, "no")) || (attributeset_cmp_left(var->Attributes, ATTR_SENSITIVE, "0"))) gtk_widget_set_sensitive(var->Widget, FALSE); if (attributeset_cmp_left(var->Attributes, ATTR_SENSITIVE, "password")) { /* Thunor: This is all original code moved across when refactoring */ gtk_entry_set_visibility(GTK_ENTRY(var->Widget), FALSE); } /* Connect signals */ /* Thunor: This is all original code moved across when refactoring */ g_signal_connect(G_OBJECT(var->Widget), "changed", G_CALLBACK(on_any_widget_changed_event), (gpointer)var->Attributes); g_signal_connect(G_OBJECT(var->Widget), "activate", G_CALLBACK(on_any_widget_activate_event), (gpointer)var->Attributes); #if GTK_CHECK_VERSION(2,16,0) /* Despite what the GTK+ 2 Reference Manual says, I found * these to be activatable by default. They will actually * be prefixed with either primary- or secondary- for use * within action directives */ g_signal_connect(G_OBJECT(var->Widget), "icon-press", G_CALLBACK(on_any_widget_icon_press_event), (gpointer)var->Attributes); g_signal_connect(G_OBJECT(var->Widget), "icon-release", G_CALLBACK(on_any_widget_icon_release_event), (gpointer)var->Attributes); #endif } #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Exiting.\n", __func__); #endif }
void widget_progressbar_refresh(variable *var) { GList *element; gchar *act; gint initialised = FALSE; #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Entering.\n", __func__); #endif /* Get initialised state of widget */ if (g_object_get_data(G_OBJECT(var->Widget), "_initialised") != NULL) initialised = (gint)g_object_get_data(G_OBJECT(var->Widget), "_initialised"); /* The <input> tag... */ act = attributeset_get_first(&element, var->Attributes, ATTR_INPUT); while (act) { if (input_is_shell_command(act)) widget_progressbar_input_by_command(var, act + 8); /* input file stock = "File:", input file = "File:/path/to/file" */ if (strncasecmp(act, "file:", 5) == 0 && strlen(act) > 5) { widget_progressbar_input_by_file(var, act + 5); } act = attributeset_get_next(&element, var->Attributes, ATTR_INPUT); } /* The <item> tags... */ if (attributeset_is_avail(var->Attributes, ATTR_ITEM)) widget_progressbar_input_by_items(var); /* Initialise these only once at start-up */ if (!initialised) { /* Apply directives */ if (attributeset_is_avail(var->Attributes, ATTR_DEFAULT)) fprintf(stderr, "%s(): <default> not implemented for this widget.\n", __func__); if (attributeset_is_avail(var->Attributes, ATTR_HEIGHT)) fprintf(stderr, "%s(): <height> not implemented for this widget.\n", __func__); if (attributeset_is_avail(var->Attributes, ATTR_WIDTH)) fprintf(stderr, "%s(): <width> not implemented for this widget.\n", __func__); if ((attributeset_cmp_left(var->Attributes, ATTR_SENSITIVE, "false")) || (attributeset_cmp_left(var->Attributes, ATTR_SENSITIVE, "disabled")) || /* Deprecated */ (attributeset_cmp_left(var->Attributes, ATTR_SENSITIVE, "no")) || (attributeset_cmp_left(var->Attributes, ATTR_SENSITIVE, "0"))) gtk_widget_set_sensitive(var->Widget, FALSE); /* Connect signals */ /* Thunor: This is all original code moved across when refactoring */ /* We start the input command in a separate thread when the * widget gets realized */ g_signal_connect(G_OBJECT(var->Widget), "realize", G_CALLBACK(widget_progressbar_realized_callback), (gpointer)var->Attributes); } #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Exiting.\n", __func__); #endif }