void *get_params(dt_lib_module_t *self, int *size) { int len = 0; char *params = NULL; for(GList *iter = g_list_first(darktable.iop); iter; iter = g_list_next(iter)) { dt_iop_module_so_t *module = (dt_iop_module_so_t *)iter->data; // skip modules not in the list if(dt_iop_so_is_hidden(module) || (module->flags() & IOP_FLAGS_DEPRECATED)) continue; int op_len = strlen(module->op) + 1; int new_len = len + 1 + op_len; char *tmp = realloc(params, new_len); if(!tmp) { free(params); params = NULL; len = 0; break; } else { params = tmp; } memcpy(params + len, module->op, op_len); params[new_len - 1] = (char)module->state; len = new_len; } *size = len; return params; }
static char *gen_params(char state, int *size, char *names) { int len = 0; char *params = NULL; for(GList *iter = g_list_first(darktable.iop); iter; iter = g_list_next(iter)) { dt_iop_module_so_t *module = (dt_iop_module_so_t *)iter->data; // skip modules not in the list if(dt_iop_so_is_hidden(module) || (module->flags() & IOP_FLAGS_DEPRECATED)) continue; int op_len = strlen(module->op) + 1; int new_len = len + 1 + op_len; char *tmp = realloc(params, new_len); if(!tmp) { free(params); params = NULL; len = 0; break; } else { params = tmp; } memcpy(params + len, module->op, op_len); char *pattern = g_strdup_printf("|%s|", module->op); params[new_len - 1] = (names==NULL ? state : strstr(names, module->op)!=NULL); g_free(pattern); len = new_len; } *size = len; return params; }
static void _lib_modulelist_populate_callback(gpointer instance, gpointer user_data) { dt_lib_module_t *self = (dt_lib_module_t *)user_data; if(!self || !(self->data)) return; GtkListStore *store; GtkTreeIter iter; GtkWidget *view = GTK_WIDGET(((dt_lib_modulelist_t *)self->data)->tree); GtkCellRenderer *pix_renderer, *fav_renderer, *text_renderer; GdkRGBA color; GtkStyleContext *context = gtk_widget_get_style_context(view); gboolean color_found = gtk_style_context_lookup_color (context, "selected_bg_color", &color); if(!color_found) { color.red = 1.0; color.green = 0.0; color.blue = 0.0; color.alpha = 1.0; } store = gtk_list_store_new(NUM_COLS, GDK_TYPE_PIXBUF, G_TYPE_POINTER); gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(store)); g_object_unref(store); gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(store), COL_MODULE, _lib_modulelist_gui_sort, NULL, NULL); gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(store), COL_MODULE, GTK_SORT_ASCENDING); pix_renderer = gtk_cell_renderer_pixbuf_new(); g_object_set(pix_renderer, "cell-background-rgba", &color, NULL); fav_renderer = gtk_cell_renderer_pixbuf_new(); cairo_surface_t *fav_cst = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, ICON_SIZE, ICON_SIZE); cairo_t *fav_cr = cairo_create(fav_cst); cairo_set_source_rgb(fav_cr, 0.7, 0.7, 0.7); dtgtk_cairo_paint_modulegroup_favorites(fav_cr, 0, 0, ICON_SIZE, ICON_SIZE, 0); cairo_destroy(fav_cr); guchar *data = cairo_image_surface_get_data(fav_cst); dt_draw_cairo_to_gdk_pixbuf(data, ICON_SIZE, ICON_SIZE); ((dt_lib_modulelist_t *)self->data)->fav_pixbuf = gdk_pixbuf_new_from_data(data, GDK_COLORSPACE_RGB, TRUE, 8, ICON_SIZE, ICON_SIZE, cairo_image_surface_get_stride(fav_cst), NULL, NULL); g_object_set(fav_renderer, "cell-background-rgba", &color, NULL); g_object_set(fav_renderer, "width", gdk_pixbuf_get_width(((dt_lib_modulelist_t *)self->data)->fav_pixbuf), NULL); text_renderer = gtk_cell_renderer_text_new(); g_object_set(text_renderer, "cell-background-rgba", &color, NULL); gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), FALSE); gtk_tree_view_set_headers_clickable(GTK_TREE_VIEW(view), FALSE); GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view)); gtk_tree_selection_set_mode(selection, GTK_SELECTION_NONE); GtkTreeViewColumn *col; col = gtk_tree_view_get_column(GTK_TREE_VIEW(view), 0); if(col) gtk_tree_view_remove_column(GTK_TREE_VIEW(view), col); gtk_tree_view_insert_column_with_data_func(GTK_TREE_VIEW(view), 0, "favorite", fav_renderer, favorite_renderer_function, NULL, NULL); col = gtk_tree_view_get_column(GTK_TREE_VIEW(view), 1); if(col) gtk_tree_view_remove_column(GTK_TREE_VIEW(view), col); gtk_tree_view_insert_column_with_data_func(GTK_TREE_VIEW(view), 1, "image", pix_renderer, image_renderer_function, NULL, NULL); col = gtk_tree_view_get_column(GTK_TREE_VIEW(view), 2); if(col) gtk_tree_view_remove_column(GTK_TREE_VIEW(view), col); gtk_tree_view_insert_column_with_data_func(GTK_TREE_VIEW(view), 2, "name", text_renderer, text_renderer_function, NULL, NULL); /* go thru list of iop modules and add them to the list */ GList *modules = g_list_last(darktable.iop); char datadir[PATH_MAX] = { 0 }; dt_loc_get_datadir(datadir, sizeof(datadir)); while(modules) { dt_iop_module_so_t *module = (dt_iop_module_so_t *)(modules->data); if(!dt_iop_so_is_hidden(module) && !(module->flags() & IOP_FLAGS_DEPRECATED)) { GdkPixbuf *pixbuf; char filename[PATH_MAX] = { 0 }; snprintf(filename, sizeof(filename), "%s/pixmaps/plugins/darkroom/%s.svg", datadir, module->op); pixbuf = load_image(filename); if(pixbuf) goto end; snprintf(filename, sizeof(filename), "%s/pixmaps/plugins/darkroom/%s.png", datadir, module->op); pixbuf = load_image(filename); if(pixbuf) goto end; snprintf(filename, sizeof(filename), "%s/pixmaps/plugins/darkroom/template.svg", datadir); pixbuf = load_image(filename); if(pixbuf) goto end; snprintf(filename, sizeof(filename), "%s/pixmaps/plugins/darkroom/template.png", datadir); pixbuf = load_image(filename); if(pixbuf) goto end; // wow, we could neither load the SVG nor the PNG files. something is f****d up. pixbuf = gdk_pixbuf_new_from_data(fallback_pixel, GDK_COLORSPACE_RGB, TRUE, 8, 1, 1, 4, NULL, NULL); end: gtk_list_store_append(store, &iter); gtk_list_store_set(store, &iter, COL_IMAGE, pixbuf, COL_MODULE, module, -1); g_object_unref(pixbuf); } modules = g_list_previous(modules); } }