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, G_TYPE_STRING); 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, (gchar *)0); 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, NULL); 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, (gchar *)0); g_object_set(fav_renderer, "width", gdk_pixbuf_get_width(((dt_lib_modulelist_t *)self->data)->fav_pixbuf), (gchar *)0); text_renderer = gtk_cell_renderer_text_new(); g_object_set(text_renderer, "cell-background-rgba", &color, (gchar *)0); gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), FALSE); gtk_tree_view_set_headers_clickable(GTK_TREE_VIEW(view), FALSE); gtk_tree_view_set_tooltip_column(GTK_TREE_VIEW(view), COL_DESCRIPTION); 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); gtk_tree_view_set_search_column(GTK_TREE_VIEW(view), 2); /* 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, COL_DESCRIPTION, module->description ? module->description() : module->name(), -1); g_object_unref(pixbuf); } modules = g_list_previous(modules); } }
static gboolean changed_callback (GtkEntry *entry, dt_lib_collect_rule_t *dr) { // update related list dt_lib_collect_t *d = get_collect(dr); sqlite3_stmt *stmt; GtkTreeIter iter; GtkTreeView *view = d->view; GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(view)); g_object_ref(model); gtk_tree_view_set_model(GTK_TREE_VIEW(view), NULL); gtk_list_store_clear(GTK_LIST_STORE(model)); char query[1024]; int property = gtk_combo_box_get_active(dr->combo); const gchar *text = gtk_entry_get_text(GTK_ENTRY(dr->text)); gchar *escaped_text = dt_util_str_replace(text, "'", "''"); char confname[200]; snprintf(confname, 200, "plugins/lighttable/collect/string%1ld", dr->num); dt_conf_set_string (confname, text); snprintf(confname, 200, "plugins/lighttable/collect/item%1ld", dr->num); dt_conf_set_int (confname, property); switch(property) { case 0: // film roll snprintf(query, 1024, "select distinct folder, id from film_rolls where folder like '%%%s%%' order by folder desc", escaped_text); break; case 1: // camera snprintf(query, 1024, "select distinct maker || ' ' || model as model, 1 from images where maker || ' ' || model like '%%%s%%' order by model", escaped_text); break; case 2: // tag snprintf(query, 1024, "SELECT distinct name, id FROM tags WHERE name LIKE '%%%s%%' ORDER BY UPPER(name)", escaped_text); break; case 4: // History, 2 hardcoded alternatives gtk_list_store_append(GTK_LIST_STORE(model), &iter); gtk_list_store_set (GTK_LIST_STORE(model), &iter, DT_LIB_COLLECT_COL_TEXT,_("altered"), DT_LIB_COLLECT_COL_ID, 0, DT_LIB_COLLECT_COL_TOOLTIP,_("altered"), -1); gtk_list_store_append(GTK_LIST_STORE(model), &iter); gtk_list_store_set (GTK_LIST_STORE(model), &iter, DT_LIB_COLLECT_COL_TEXT,_("not altered"), DT_LIB_COLLECT_COL_ID, 1, DT_LIB_COLLECT_COL_TOOLTIP,_("not altered"), -1); goto entry_key_press_exit; break; case 5: // colorlabels gtk_list_store_append(GTK_LIST_STORE(model), &iter); gtk_list_store_set (GTK_LIST_STORE(model), &iter, DT_LIB_COLLECT_COL_TEXT,_("red"), DT_LIB_COLLECT_COL_ID, 0, DT_LIB_COLLECT_COL_TOOLTIP, _("red"), -1); gtk_list_store_append(GTK_LIST_STORE(model), &iter); gtk_list_store_set (GTK_LIST_STORE(model), &iter, DT_LIB_COLLECT_COL_TEXT,_("yellow"), DT_LIB_COLLECT_COL_ID, 1, DT_LIB_COLLECT_COL_TOOLTIP, _("yellow"), -1); gtk_list_store_append(GTK_LIST_STORE(model), &iter); gtk_list_store_set (GTK_LIST_STORE(model), &iter, DT_LIB_COLLECT_COL_TEXT,_("green"), DT_LIB_COLLECT_COL_ID, 2, DT_LIB_COLLECT_COL_TOOLTIP, _("green"), -1); gtk_list_store_append(GTK_LIST_STORE(model), &iter); gtk_list_store_set (GTK_LIST_STORE(model), &iter, DT_LIB_COLLECT_COL_TEXT,_("blue"), DT_LIB_COLLECT_COL_ID, 3, DT_LIB_COLLECT_COL_TOOLTIP, _("blue"), -1); gtk_list_store_append(GTK_LIST_STORE(model), &iter); gtk_list_store_set (GTK_LIST_STORE(model), &iter, DT_LIB_COLLECT_COL_TEXT,_("purple"), DT_LIB_COLLECT_COL_ID, 4, DT_LIB_COLLECT_COL_TOOLTIP, _("purple"), -1); goto entry_key_press_exit; break; // TODO: Add empty string for metadata? // TODO: Autogenerate this code? case 6: // title snprintf(query, 1024, "select distinct value, 1 from meta_data where key = %d and value like '%%%s%%' order by value", DT_METADATA_XMP_DC_TITLE, escaped_text); break; case 7: // description snprintf(query, 1024, "select distinct value, 1 from meta_data where key = %d and value like '%%%s%%' order by value", DT_METADATA_XMP_DC_DESCRIPTION, escaped_text); break; case 8: // creator snprintf(query, 1024, "select distinct value, 1 from meta_data where key = %d and value like '%%%s%%' order by value", DT_METADATA_XMP_DC_CREATOR, escaped_text); break; case 9: // publisher snprintf(query, 1024, "select distinct value, 1 from meta_data where key = %d and value like '%%%s%%' order by value", DT_METADATA_XMP_DC_PUBLISHER, escaped_text); break; case 10: // rights snprintf(query, 1024, "select distinct value, 1 from meta_data where key = %d and value like '%%%s%%'order by value ", DT_METADATA_XMP_DC_RIGHTS, escaped_text); break; case 11: // lens snprintf(query, 1024, "select distinct lens, 1 from images where lens like '%%%s%%' order by lens", escaped_text); break; case 12: // iso snprintf(query, 1024, "select distinct cast(iso as integer) as iso, 1 from images where iso like '%%%s%%' order by iso", escaped_text); break; case 13: // aperature snprintf(query, 1024, "select distinct round(aperture,1) as aperture, 1 from images where aperture like '%%%s%%' order by aperture", escaped_text); break; case 14: // filename snprintf(query, 1024, "select distinct filename, 1 from images where filename like '%%%s%%' order by filename", escaped_text); break; default: // case 3: // day snprintf(query, 1024, "SELECT DISTINCT datetime_taken, 1 FROM images WHERE datetime_taken LIKE '%%%s%%' ORDER BY datetime_taken DESC", escaped_text); break; } g_free(escaped_text); DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), query, -1, &stmt, NULL); while(sqlite3_step(stmt) == SQLITE_ROW) { gtk_list_store_append(GTK_LIST_STORE(model), &iter); const char *folder = (const char*)sqlite3_column_text(stmt, 0); if(property == 0) // film roll { folder = dt_image_film_roll_name(folder); } gchar *value = (gchar *)sqlite3_column_text(stmt, 0); gchar *escaped_text = g_markup_escape_text(value, strlen(value)); gtk_list_store_set (GTK_LIST_STORE(model), &iter, DT_LIB_COLLECT_COL_TEXT, folder, DT_LIB_COLLECT_COL_ID, sqlite3_column_int(stmt, 1), DT_LIB_COLLECT_COL_TOOLTIP, escaped_text, DT_LIB_COLLECT_COL_PATH, value, -1); } sqlite3_finalize(stmt); entry_key_press_exit: gtk_tree_view_set_tooltip_column(GTK_TREE_VIEW(view), DT_LIB_COLLECT_COL_TOOLTIP); gtk_tree_view_set_model(GTK_TREE_VIEW(view), model); g_object_unref(model); return FALSE; }
static void dev_set_options(GtkAction *action, GtkWindow *parent) { (void)action; struct sr_device *device = g_object_get_data(G_OBJECT(parent), "device"); if (!device) return; GtkWidget *dialog = gtk_dialog_new_with_buttons("Device Properties", parent, GTK_DIALOG_MODAL, GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, NULL); GtkWidget *sw = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_widget_set_size_request(sw, 300, 200); GtkWidget *tv = gtk_tree_view_new(); gtk_container_add(GTK_CONTAINER(sw), tv); gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), sw, TRUE, TRUE, 0); /* Populate list store with config options */ GtkListStore *props = gtk_list_store_new(MAX_DEV_PROP, G_TYPE_INT, G_TYPE_INT, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_STRING, G_TYPE_BOOLEAN); gtk_tree_view_set_model(GTK_TREE_VIEW(tv), GTK_TREE_MODEL(props)); int *capabilities = device->plugin->get_capabilities(); int cap; GtkTreeIter iter; for (cap = 0; capabilities[cap]; cap++) { struct sr_hwcap_option *hwo; if (!(hwo = sr_find_hwcap_option(capabilities[cap]))) continue; gtk_list_store_append(props, &iter); gtk_list_store_set(props, &iter, DEV_PROP_CAPABILITY, capabilities[cap], DEV_PROP_TYPE, hwo->type, DEV_PROP_SHORTNAME, hwo->shortname, DEV_PROP_DESCRIPTION, hwo->description, DEV_PROP_IS_TEXT, hwo->type != SR_T_BOOL, -1); } /* Popup tooltop containing description if mouse hovers */ gtk_tree_view_set_tooltip_column(GTK_TREE_VIEW(tv), DEV_PROP_DESCRIPTION); /* Save device with list so that property can be set by edited * handler. */ g_object_set_data(G_OBJECT(props), "device", device); /* Add columns to the tree view */ GtkTreeViewColumn *col; col = gtk_tree_view_column_new_with_attributes("Property", gtk_cell_renderer_text_new(), "text", DEV_PROP_SHORTNAME, NULL); gtk_tree_view_append_column(GTK_TREE_VIEW(tv), col); /* We pack both a text and toggle renderer. Only one will be visible. * depending on type. */ GtkCellRenderer *cel = gtk_cell_renderer_text_new(); g_object_set(cel, "editable", TRUE, NULL); g_signal_connect(cel, "edited", G_CALLBACK(prop_edited), props); col = gtk_tree_view_column_new_with_attributes("Value", cel, "text", DEV_PROP_TEXTVALUE, "visible", DEV_PROP_IS_TEXT, NULL); cel = gtk_cell_renderer_toggle_new(); g_signal_connect(cel, "toggled", G_CALLBACK(prop_toggled), props); gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(col), cel, TRUE); gtk_cell_layout_set_cell_data_func(GTK_CELL_LAYOUT(col), cel, dev_prop_bool_data_func, NULL, NULL); gtk_tree_view_append_column(GTK_TREE_VIEW(tv), col); gtk_widget_show_all(dialog); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); }