Esempio n. 1
0
static void
save_catalogs (GthOrganizeTask *self)
{
	GtkTreeIter iter;

	if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (self->priv->results_liststore), &iter)) {
		do {
			char     *key;
			char     *name;
			gboolean  create;

			gtk_tree_model_get (GTK_TREE_MODEL (self->priv->results_liststore), &iter,
					    KEY_COLUMN, &key,
					    NAME_COLUMN, &name,
					    CREATE_CATALOG_COLUMN, &create,
					    -1);
			if (create) {
				GthCatalog *catalog;
				char       *original_name;

				catalog = g_hash_table_lookup (self->priv->catalogs, key);

				/* remove the name if it is equal to the date
				 * to avoid a duplication in the display-name
				 * attribute. */
				original_name = gth_datetime_strftime (gth_catalog_get_date (catalog), "%x");
				if (g_strcmp0 (original_name, name) != 0)
					gth_catalog_set_name (catalog, name);
				else
					gth_catalog_set_name (catalog, NULL);

				g_free (original_name);
			}
			else
				g_hash_table_remove (self->priv->catalogs, key);

			g_free (name);
			g_free (key);
		}
		while (gtk_tree_model_iter_next (GTK_TREE_MODEL (self->priv->results_liststore), &iter));
	}
	g_hash_table_foreach (self->priv->catalogs, save_catalog, NULL);

	gth_task_completed (GTH_TASK (self), NULL);
}
Esempio n. 2
0
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);
}
Esempio n. 3
0
void
gth_organize_task_set_singletons_catalog (GthOrganizeTask *self,
					  const char      *catalog_name)
{
	GFile *file;

	_g_object_unref (self->priv->singletons_catalog);
	self->priv->singletons_catalog = NULL;
	if (catalog_name == NULL)
		return;

	self->priv->singletons_catalog = gth_catalog_new ();
	file = _g_file_new_for_display_name ("catalog:///", catalog_name, ".catalog");
	gth_catalog_set_file (self->priv->singletons_catalog, file);
	gth_catalog_set_name (self->priv->singletons_catalog, catalog_name);

	g_object_unref (file);
}
Esempio n. 4
0
GFile *
catalogs__command_line_files_cb (GList *files)
{
	GFile      *file;
	GthCatalog *catalog;
	GList      *scan;

	if (g_list_length (files) <= 1)
		return NULL;

	file = _g_file_new_for_display_name ("catalog:///", _("Command Line"), ".catalog");
	catalog = gth_catalog_new ();
	gth_catalog_set_file (catalog, file);
	gth_catalog_set_name (catalog, _("Command Line"));
	for (scan = files; scan; scan = scan->next)
		gth_catalog_insert_file (catalog, (GFile *) scan->data, -1);
	gth_catalog_save (catalog);

	g_object_unref (catalog);

	return file;
}