void mysql__add_row_to_model(MYSQL_ROW row, unsigned long* lengths) { GdkPixbuf* iconbuf = NULL; char length[64]; char keywords[256]; char name[256]; float samplerate; char samplerate_s[32]; unsigned channels, colour; gboolean online = FALSE; GtkTreeIter iter; //db__iter_to_result(result); //deserialise the pixbuf field: GdkPixdata pixdata; GdkPixbuf* pixbuf = NULL; if(row[MYSQL_PIXBUF]){ if(gdk_pixdata_deserialize(&pixdata, lengths[MYSQL_PIXBUF], (guint8*)row[MYSQL_PIXBUF], NULL)){ pixbuf = gdk_pixbuf_from_pixdata(&pixdata, TRUE, NULL); } } format_time(length, row[MYSQL_LENGTH]); if(row[MYSQL_KEYWORDS]) snprintf(keywords, 256, "%s", row[MYSQL_KEYWORDS]); else keywords[0] = 0; if(!row[MYSQL_SAMPLERATE]) samplerate = 0; else samplerate = atoi(row[MYSQL_SAMPLERATE]); samplerate_format(samplerate_s, samplerate); if(row[7]==NULL) channels = 0; else channels = atoi(row[7]); if(row[MYSQL_ONLINE]==NULL) online = 0; else online = atoi(row[MYSQL_ONLINE]); if(row[MYSQL_COLOUR]==NULL) colour = 0; else colour = atoi(row[MYSQL_COLOUR]); strncpy(name, row[MYSQL_NAME], 255); //TODO markup should be set in cellrenderer, not model! #if 0 if(GTK_WIDGET_REALIZED(app.view)){ //check colours dont clash: long c_num = strtol(app.config.colour[colour], NULL, 16); dbg(2, "rowcolour=%s", app.config.colour[colour]); GdkColor row_colour; color_rgba_to_gdk(&row_colour, c_num << 8); if(is_similar(&row_colour, &app.fg_colour, 0x60)){ snprintf(name, 255, "%s%s%s", "<span foreground=\"blue\">", row[MYSQL_NAME], "</span>"); } } #endif #ifdef USE_AYYI //is the file loaded in the current Ayyi song? if(ayyi.got_song){ gchar* fullpath = g_build_filename(row[MYSQL_DIR], name, NULL); if(pool__file_exists(fullpath)) dbg(0, "exists"); else dbg(0, "doesnt exist"); g_free(fullpath); } #endif //icon (only shown if the sound file is currently available): if(online){ MIME_type* mime_type = mime_type_lookup(row[MYSQL_MIMETYPE]); type_to_icon(mime_type); if ( ! mime_type->image ) dbg(0, "no icon."); iconbuf = mime_type->image->sm_pixbuf; } else iconbuf = NULL; #if 0 //strip the homedir from the dir string: char* path = strstr(row[MYSQL_DIR], g_get_home_dir()); path = path ? path + strlen(g_get_home_dir()) + 1 : row[MYSQL_DIR]; #endif gtk_list_store_append(app.store, &iter); gtk_list_store_set(app.store, &iter, COL_ICON, iconbuf, #ifdef USE_AYYI COL_AYYI_ICON, ayyi_icon, #endif COL_IDX, atoi(row[MYSQL_ID]), COL_NAME, name, COL_FNAME, row[MYSQL_DIR], COL_KEYWORDS, keywords, COL_OVERVIEW, pixbuf, COL_LENGTH, length, COL_SAMPLERATE, samplerate_s, COL_CHANNELS, channels, COL_MIMETYPE, row[MYSQL_MIMETYPE], COL_NOTES, row[MYSQL_NOTES], COL_COLOUR, colour, -1); if(pixbuf) g_object_unref(pixbuf); #if 0 if(app.no_gui){ printf(" %s\n", name); } #endif }
void samplecat_list_store_on_sample_changed (SamplecatListStore* self, Sample* sample, gint prop, void* val) { g_return_if_fail (self != NULL); g_return_if_fail (sample->row_ref); GtkTreePath* path = gtk_tree_row_reference_get_path(sample->row_ref); if(!path) return; GtkTreeIter iter; gtk_tree_model_get_iter(GTK_TREE_MODEL(samplecat.store), &iter, path); gtk_tree_path_free(path); dbg(1, "prop=%i %s", prop, samplecat_model_print_col_name(prop)); switch(prop){ case COL_ICON: // online/offline, mtime { GdkPixbuf* iconbuf = NULL; if (sample->online) { MIME_type* mime_type = mime_type_lookup(sample->mimetype); type_to_icon(mime_type); if (!mime_type->image) dbg(0, "no icon."); iconbuf = mime_type->image->sm_pixbuf; } gtk_list_store_set(samplecat.store, &iter, COL_ICON, iconbuf, -1); } break; case COL_KEYWORDS: gtk_list_store_set(samplecat.store, &iter, COL_KEYWORDS, (char*)val, -1); break; case COL_OVERVIEW: gtk_list_store_set((GtkListStore*)self, &iter, COL_OVERVIEW, sample->overview, -1); break; case COL_COLOUR: gtk_list_store_set(samplecat.store, &iter, prop, *((guint*)val), -1); break; case COL_PEAKLEVEL: gtk_list_store_set((GtkListStore*)self, &iter, COL_PEAKLEVEL, sample->peaklevel, -1); break; case COL_FNAME: gtk_list_store_set(samplecat.store, &iter, COL_FNAME, sample->sample_dir, -1); break; case COL_X_EBUR: case COL_X_NOTES: // nothing to do. break; case COL_ALL: case -1: // deprecated { //char* metadata = sample_get_metadata_str(s); char samplerate_s[32]; samplerate_format(samplerate_s, sample->sample_rate); char length_s[64]; format_smpte(length_s, sample->length); gtk_list_store_set((GtkListStore*)samplecat.store, &iter, COL_CHANNELS, sample->channels, COL_SAMPLERATE, samplerate_s, COL_LENGTH, length_s, COL_PEAKLEVEL, sample->peaklevel, COL_OVERVIEW, sample->overview, -1); dbg(1, "file info updated."); //if(metadata) g_free(metadata); } break; default: dbg(0, "property not handled %i", prop); break; } }