void magnatune_db_load_data(const char *data, const goffset length) { gchar *error = NULL; gchar *path; // const gchar *final = g_get_user_cache_dir(); path = gmpc_get_cache_directory("magnatune.sqlite3");//g_build_filename(final, "gmpc", "magnatune.sqlite3", NULL); if(magnatune_sqlhandle) { int status = sqlite3_close(magnatune_sqlhandle); if(status != 0) { gchar *temp =g_strdup_printf("Failed to close magnatune db: %i\n", status); playlist3_show_error_message(temp, ERROR_WARNING); g_free(temp); } magnatune_sqlhandle = NULL; } if(data){ GError *error = NULL; gssize size= (gssize)length; g_file_set_contents(path, data, size, &error); if(error) { gchar *temp =g_strdup_printf("Failed to store magnatune db: %s\n", error->message); playlist3_show_error_message(temp, ERROR_WARNING); g_free(temp); g_error_free(error); } } /* open the db if it is closed */ if(!magnatune_sqlhandle) { int retv = sqlite3_open(path, &(magnatune_sqlhandle)); if(retv != SQLITE_OK) { g_free(path); playlist3_show_error_message("Failed to open the new magnatune database", ERROR_WARNING); /* Cleanup */ return; } } sqlite3_exec(magnatune_sqlhandle, "CREATE INDEX songsAlbumname ON songs(albumname);", NULL, NULL, &error); if(error)printf("%i: %s",__LINE__, error); sqlite3_exec(magnatune_sqlhandle, "CREATE INDEX genresAlbumname ON genres(albumname);", NULL, NULL, &error); if(error)printf("%i: %s",__LINE__, error); sqlite3_exec(magnatune_sqlhandle, "CREATE INDEX genresGenrename ON genres(genre);", NULL, NULL, &error); if(error)printf("%i: %s",__LINE__, error); sqlite3_exec(magnatune_sqlhandle, "CREATE INDEX albumsAlbumname ON albums(albumname);", NULL, NULL, &error); if(error)printf("%i: %s",__LINE__, error); g_free(path); }
static void serverstats_combo_changed(GtkComboBox * box, GtkWidget * pb) { ss_str *s; int hits, total; gulong max_i; MpdData *node, *data; GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(serverstats_tree)); int tag = gtk_combo_box_get_active(box); if (!mpd_check_connected(connection)) return; if (!mpd_server_check_version(connection, 0, 13, 0)) { playlist3_show_error_message("This feature is not supported in mpd older then version 0.13.0.", ERROR_WARNING); return; } /* reset the cancel flag */ cancel_query = FALSE; /* show progress bar */ gtk_widget_show_all(gtk_widget_get_parent(pb)); /** make the combo box insensitive and remove the model from the treeview */ gtk_tree_view_set_model(GTK_TREE_VIEW(serverstats_tree), NULL); gtk_widget_set_sensitive(GTK_WIDGET(box), FALSE); gtk_list_store_clear(GTK_LIST_STORE(model)); mpd_database_search_field_start(connection, tag); data = mpd_database_search_commit(connection); max_i = 0; hits = 0; total = 0; for (node = mpd_data_get_first(data); node != NULL; node = (MpdData *) mpd_data_get_next_real(node, FALSE)) total++; s = g_malloc0(sizeof(*s)); s->total = total; s->model = model; s->data = data; s->hits = 0; s->tag = tag; s->pb = pb; s->box = GTK_WIDGET(box); g_idle_add((GSourceFunc) serverstats_idle_handler, s); }