static void catalog_ready_cb (GObject *catalog, GError *error, gpointer user_data) { AddData *add_data = user_data; GList *scan; char *buffer; gsize length; GFile *gio_file; if (error != NULL) { _gtk_error_dialog_from_gerror_show (GTK_WINDOW (add_data->parent_window), _("Could not add the files to the catalog"), &error); return; } add_data->catalog = (GthCatalog *) catalog; for (scan = add_data->files; scan; scan = scan->next) gth_catalog_insert_file (add_data->catalog, (GFile *) scan->data, -1); buffer = gth_catalog_to_data (add_data->catalog, &length); gio_file = gth_catalog_file_to_gio_file (add_data->catalog_file); g_write_file_async (gio_file, buffer, length, TRUE, G_PRIORITY_DEFAULT, NULL, catalog_save_done_cb, add_data); g_object_unref (gio_file); }
static void catalog_saved_cb (void **buffer, gsize count, GError *error, gpointer user_data) { DialogData *data = user_data; if (error == NULL) { if (! g_file_equal (data->original_file, data->file_data->file)) { GFile *gio_file; gio_file = gth_catalog_file_to_gio_file (data->original_file); g_file_delete (gio_file, NULL, NULL); g_object_unref (gio_file); gth_monitor_file_renamed (gth_main_get_default_monitor (), data->original_file, data->file_data->file); } gth_catalog_update_metadata (data->catalog, data->file_data); gth_monitor_metadata_changed (gth_main_get_default_monitor (), data->file_data); gth_hook_invoke ("dlg-catalog-properties-saved", data->browser, data->file_data, data->catalog); } else _gtk_error_dialog_from_gerror_show (GTK_WINDOW (data->browser), _("Could not save the catalog"), error); gtk_widget_destroy (data->dialog); }
static gboolean process_rename_data_list (gpointer user_data) { BrowserData *data = user_data; GList *scan; g_source_remove (data->update_renamed_files_id); data->update_renamed_files_id = 0; for (scan = data->rename_data_list; scan; scan = scan->next) { RenameData *rename_data = scan->data; GthCatalog *catalog; GList *scan_files; GList *scan_new_files; GFile *gio_file; char *catalog_data; gsize catalog_data_size; GError *error = NULL; catalog = gth_catalog_load_from_file (rename_data->location); for (scan_files = rename_data->files, scan_new_files = rename_data->new_files; scan_files && scan_new_files; scan_files = scan_files->next, scan_new_files = scan_new_files->next) { GFile *file = scan_files->data; GFile *new_file = scan_new_files->data; int pos; pos = gth_catalog_remove_file (catalog, file); gth_catalog_insert_file (catalog, new_file, pos); } gio_file = gth_catalog_file_to_gio_file (rename_data->location); catalog_data = gth_catalog_to_data (catalog, &catalog_data_size); if (! _g_file_write (gio_file, FALSE, G_FILE_CREATE_NONE, catalog_data, catalog_data_size, NULL, &error)) { g_warning ("%s", error->message); g_clear_error (&error); } g_free (catalog_data); g_object_unref (gio_file); g_object_unref (catalog); } rename_data_list_free (data); return FALSE; }
static void save_button_clicked_cb (GtkButton *button, DialogData *data) { GthDateTime *date_time; GFile *gio_file; char *buffer; gsize size; if (strcmp (gtk_entry_get_text (GTK_ENTRY (GET_WIDGET ("name_entry"))), "") != 0) { GFile *parent; char *uri; char *clean_name; char *display_name; GFile *new_file; parent = g_file_get_parent (data->original_file); uri = g_file_get_uri (data->original_file); clean_name = _g_filename_clear_for_file (gtk_entry_get_text (GTK_ENTRY (GET_WIDGET ("name_entry")))); display_name = g_strconcat (clean_name, _g_uri_get_file_extension (uri), NULL); new_file = g_file_get_child_for_display_name (parent, display_name, NULL); if ((new_file != NULL) && ! g_file_equal (new_file, data->original_file)) gth_file_data_set_file (data->file_data, new_file); _g_object_unref (new_file); g_free (display_name); g_free (clean_name); g_free (uri); g_object_unref (parent); } gth_catalog_set_name (data->catalog, gtk_entry_get_text (GTK_ENTRY (GET_WIDGET ("name_entry")))); date_time = gth_datetime_new (); gth_time_selector_get_value (GTH_TIME_SELECTOR (data->time_selector), date_time); gth_catalog_set_date (data->catalog, date_time); gth_datetime_free (date_time); /* invoke the hook to save derived catalogs such as searches */ gth_hook_invoke ("dlg-catalog-properties-save", data->builder, data->file_data, data->catalog); gio_file = gth_catalog_file_to_gio_file (data->file_data->file); buffer = gth_catalog_to_data (data->catalog, &size); _g_file_write_async (gio_file, buffer, size, TRUE, G_PRIORITY_DEFAULT, NULL, catalog_saved_cb, data); g_object_unref (gio_file); }