Commit 1068e256 authored by Paolo Bacchilega's avatar Paolo Bacchilega
Browse files

added the name property to the catalogs

new logic for the standard::display-name attribute
parent 675bd823
......@@ -633,24 +633,9 @@ catalogs__gth_browser_update_extra_widget_cb (GthBrowser *browser)
&& ! _g_content_type_is_a (g_file_info_get_content_type (location_data->info), "gthumb/library"))
{
GtkWidget *extra_widget;
GString *name;
GObject *metadata;
extra_widget = gth_browser_get_list_extra_widget (browser);
name = g_string_new ("");
if (g_file_info_get_display_name (location_data->info) != NULL)
g_string_append (name, g_file_info_get_display_name (location_data->info));
metadata = g_file_info_get_attribute_object (location_data->info, "general::event-date");
if (metadata != NULL) {
if (g_strcmp0 (name->str, "") != 0)
g_string_append (name, " - ");
g_string_append (name, gth_metadata_get_formatted (GTH_METADATA (metadata)));
}
gth_embedded_dialog_set_primary_text (GTH_EMBEDDED_DIALOG (extra_widget), name->str);
g_string_free (name, TRUE);
if (data->properties_button == NULL) {
data->properties_button = gtk_button_new ();
gtk_container_add (GTK_CONTAINER (data->properties_button), gtk_image_new_from_stock (GTK_STOCK_PROPERTIES, GTK_ICON_SIZE_BUTTON));
......
......@@ -78,6 +78,7 @@
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">&#x25CF;</property>
<property name="activates_default">True</property>
</object>
<packing>
<property name="left_attach">1</property>
......@@ -142,6 +143,8 @@
<property name="label">gtk-save</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="has_default">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
</object>
......
......@@ -85,30 +85,45 @@ catalog_saved_cb (void *buffer,
}
static char *
clear_name_for_file (const char *display_name)
{
return _g_utf8_replace (display_name, "/", "_");
}
static void
save_button_clicked_cb (GtkButton *button,
DialogData *data)
{
GFile *parent;
char *uri;
char *display_name;
GFile *new_file;
GthDateTime *date_time;
GFile *gio_file;
char *buffer;
gsize buffer_size;
parent = g_file_get_parent (data->original_file);
uri = g_file_get_uri (data->original_file);
display_name = g_strconcat (gtk_entry_get_text (GTK_ENTRY (GET_WIDGET ("name_entry"))), _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);
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 = clear_name_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);
}
g_free (display_name);
g_free (uri);
_g_object_unref (new_file);
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);
......@@ -155,7 +170,9 @@ catalog_ready_cb (GObject *object,
}
data->catalog = g_object_ref (object);
gtk_entry_set_text (GTK_ENTRY (GET_WIDGET ("name_entry")), gth_catalog_get_display_name (data->file_data->file));
if (gth_catalog_get_name (data->catalog) != NULL)
gtk_entry_set_text (GTK_ENTRY (GET_WIDGET ("name_entry")), gth_catalog_get_name (data->catalog));
gth_time_selector_set_value (GTH_TIME_SELECTOR (data->time_selector), gth_catalog_get_date (data->catalog));
gth_hook_invoke ("dlg-catalog-properties", data->builder, data->file_data, data->catalog);
gtk_widget_show (data->dialog);
......
......@@ -110,8 +110,6 @@ dlg_organize_files (GthBrowser *browser,
data->builder = _gtk_builder_new_from_file ("organize-files.ui", "catalogs");
data->dialog = GET_WIDGET ("organize_files_dialog");
/*gtk_file_chooser_set_current_folder_file (GTK_FILE_CHOOSER (GET_WIDGET ("start_at_filechooserbutton")), data->folder, NULL); FIXME */
/* Set the signals handlers. */
g_signal_connect (G_OBJECT (data->dialog),
......
......@@ -35,6 +35,7 @@ struct _GthCatalogPrivate {
GthCatalogType type;
GFile *file;
GList *file_list;
char *name;
GthDateTime *date_time;
gboolean active;
char *order;
......@@ -54,6 +55,7 @@ gth_catalog_finalize (GObject *object)
if (catalog->priv != NULL) {
if (catalog->priv->file != NULL)
g_object_unref (catalog->priv->file);
g_free (catalog->priv->name);
_g_object_list_unref (catalog->priv->file_list);
gth_datetime_free (catalog->priv->date_time);
g_free (catalog->priv->order);
......@@ -100,7 +102,9 @@ base_read_from_doc (GthCatalog *catalog,
dom_element_get_attribute (child, "type"),
g_strcmp0 (dom_element_get_attribute (child, "inverse"), "1") == 0);
if (g_strcmp0 (child->tag_name, "date") == 0)
gth_datetime_from_exif_date (catalog->priv->date_time, dom_element_get_attribute (child, "value"));
gth_datetime_from_exif_date (catalog->priv->date_time, dom_element_get_inner_text (child));
if (g_strcmp0 (child->tag_name, "name") == 0)
gth_catalog_set_name (catalog, dom_element_get_inner_text (child));
}
catalog->priv->file_list = g_list_reverse (catalog->priv->file_list);
}
......@@ -176,22 +180,23 @@ base_write_to_doc (GthCatalog *catalog,
DomDocument *doc,
DomElement *root)
{
if (catalog->priv->order != NULL)
dom_element_append_child (root, dom_document_create_element (doc, "order",
"type", catalog->priv->order,
"inverse", (catalog->priv->order_inverse ? "1" : "0"),
NULL));
if (catalog->priv->name != NULL)
dom_element_append_child (root, dom_document_create_element_with_text (doc, catalog->priv->name, "name", NULL));
if (gth_datetime_valid (catalog->priv->date_time)) {
char *s;
s = gth_datetime_to_exif_date (catalog->priv->date_time);
dom_element_append_child (root, dom_document_create_element (doc, "date",
"value", s,
NULL));
dom_element_append_child (root, dom_document_create_element_with_text (doc, s, "date", NULL));
g_free (s);
}
if (catalog->priv->order != NULL)
dom_element_append_child (root, dom_document_create_element (doc, "order",
"type", catalog->priv->order,
"inverse", (catalog->priv->order_inverse ? "1" : "0"),
NULL));
if (catalog->priv->file_list != NULL) {
DomElement *node;
GList *scan;
......@@ -294,6 +299,46 @@ gth_catalog_get_file (GthCatalog *catalog)
}
void
gth_catalog_set_name (GthCatalog *catalog,
const char *name)
{
g_free (catalog->priv->name);
catalog->priv->name = NULL;
if ((name != NULL) && (strcmp (name, "") != 0))
catalog->priv->name = g_strdup (name);;
}
const char *
gth_catalog_get_name (GthCatalog *catalog)
{
return catalog->priv->name;
}
void
gth_catalog_set_date (GthCatalog *catalog,
GthDateTime *date_time)
{
if (gth_datetime_valid (date_time))
g_date_set_dmy (catalog->priv->date_time->date,
g_date_get_day (date_time->date),
g_date_get_month (date_time->date),
g_date_get_year (date_time->date));
else
g_date_clear (catalog->priv->date_time->date, 1);
gth_time_set_hms (catalog->priv->date_time->time, 0, 0, 0, 0);
}
GthDateTime *
gth_catalog_get_date (GthCatalog *catalog)
{
return catalog->priv->date_time;
}
void
gth_catalog_set_order (GthCatalog *catalog,
const char *order,
......@@ -424,28 +469,6 @@ gth_catalog_remove_file (GthCatalog *catalog,
}
void
gth_catalog_set_date (GthCatalog *catalog,
GthDateTime *date_time)
{
if (gth_datetime_valid (date_time))
g_date_set_dmy (catalog->priv->date_time->date,
g_date_get_day (date_time->date),
g_date_get_month (date_time->date),
g_date_get_year (date_time->date));
else
g_date_clear (catalog->priv->date_time->date, 1);
gth_time_set_hms (catalog->priv->date_time->time, 0, 0, 0, 0);
}
GthDateTime *
gth_catalog_get_date (GthCatalog *catalog)
{
return catalog->priv->date_time;
}
/* -- gth_catalog_list_async -- */
......@@ -745,25 +768,138 @@ gth_catalog_get_icon (GFile *file)
}
char *
gth_catalog_get_display_name (GFile *file)
static char *
get_tag_value (const char *buffer,
const char *tag_start,
const char *tag_end)
{
char *begin_tag;
char *end_tag;
char *value;
value = NULL;
begin_tag = strstr (buffer, tag_start);
if (begin_tag != NULL) {
begin_tag += strlen (tag_start);
end_tag = strstr (begin_tag, tag_end);
value = g_strndup (begin_tag, end_tag - begin_tag);
}
return value;
}
static char *
get_display_name (GFile *file,
const char *name,
GthDateTime *date_time)
{
GString *display_name;
char *basename;
display_name = g_string_new ("");
basename = g_file_get_basename (file);
if ((basename == NULL) || (strcmp (basename, "/") == 0)) {
g_string_append (display_name, _("Catalogs"));
}
else {
if ((name == NULL) && ! gth_datetime_valid (date_time)) {
char *name;
char *utf8_name;
name = _g_uri_remove_extension (basename);
utf8_name = g_filename_to_utf8 (name, -1, NULL, NULL, NULL);
g_string_append (display_name, utf8_name);
g_free (utf8_name);
g_free (name);
}
else {
if (name != NULL)
g_string_append (display_name, name);
if (gth_datetime_valid (date_time)) {
char *formatted;
if (name != NULL)
g_string_append (display_name, " (");
formatted = gth_datetime_strftime (date_time, "%x");
g_string_append (display_name, formatted);
if (name != NULL)
g_string_append (display_name, ")");
g_free (formatted);
}
}
}
return g_string_free (display_name, FALSE);
}
void
gth_catalog_update_standard_attributes (GFile *file,
GFileInfo *info)
{
char *display_name = NULL;
char *basename;
basename = g_file_get_basename (file);
if ((basename != NULL) && (strcmp (basename, "/") != 0)) {
char *name;
char *name;
GthDateTime *date_time;
name = NULL;
date_time = gth_datetime_new ();
{
GFile *gio_file;
GFileInputStream *istream;
const int buffer_size = 256;
char buffer[buffer_size];
gio_file = gth_catalog_file_to_gio_file (file);
istream = g_file_read (gio_file, NULL, NULL);
if (istream != NULL) {
gssize n;
n = g_input_stream_read (G_INPUT_STREAM (istream), buffer, buffer_size - 1, NULL, NULL);
if (n > 0) {
char *exif_date;
buffer[n] = '\0';
name = get_tag_value (buffer, "<name>", "</name>");
exif_date = get_tag_value (buffer, "<date>", "</date>");
if (exif_date != NULL)
gth_datetime_from_exif_date (date_time, exif_date);
g_free (exif_date);
}
g_object_unref (istream);
}
g_object_unref (gio_file);
}
display_name = get_display_name (file, name, date_time);
name = _g_uri_remove_extension (basename);
display_name = g_filename_to_utf8 (name, -1, NULL, NULL, NULL);
if (gth_datetime_valid (date_time)) {
char *sort_order_s;
int sort_order;
sort_order_s = gth_datetime_strftime (date_time, "%Y%m%d");
sort_order = atoi (sort_order_s);
g_file_info_set_sort_order (info, sort_order);
}
gth_datetime_free (date_time);
g_free (name);
}
else
display_name = g_strdup (_("Catalogs"));
return display_name;
if (display_name != NULL)
g_file_info_set_display_name (info, display_name);
g_free (display_name);
g_free (basename);
}
......@@ -828,16 +964,26 @@ gth_catalog_update_metadata (GthCatalog *catalog,
const char *sort_type;
gboolean sort_inverse;
/* sort::type,sort::inverse */
sort_type = gth_catalog_get_order (catalog, &sort_inverse);
if (sort_type != NULL) {
g_file_info_set_attribute_string (file_data->info, "sort::type", sort_type);
g_file_info_set_attribute_boolean (file_data->info, "sort::inverse", sort_inverse);
}
else {
g_file_info_remove_attribute (file_data->info, "sort::type");
g_file_info_remove_attribute (file_data->info, "sort::inverse");
}
/* general::event-date */
if (gth_datetime_valid (gth_catalog_get_date (catalog))) {
GObject *metadata;
char *raw;
char *formatted;
char *sort_order_s;
int sort_order;
metadata = (GObject *) gth_metadata_new ();
raw = gth_datetime_to_exif_date (gth_catalog_get_date (catalog));
......@@ -849,10 +995,18 @@ gth_catalog_update_metadata (GthCatalog *catalog,
NULL);
g_file_info_set_attribute_object (file_data->info, "general::event-date", metadata);
sort_order_s = gth_datetime_strftime (gth_catalog_get_date (catalog), "%Y%m%d");
sort_order = atoi (sort_order_s);
g_file_info_set_sort_order (file_data->info, sort_order);
g_free (formatted);
g_free (raw);
g_object_unref (metadata);
}
else
g_file_info_remove_attribute (file_data->info, "general::event-date");
/* standard::display-name,standard::sort-order */
gth_catalog_update_standard_attributes (file_data->file, file_data->info);
}
......@@ -76,6 +76,12 @@ GthCatalog * gth_catalog_new (void);
void gth_catalog_set_file (GthCatalog *catalog,
GFile *file);
GFile * gth_catalog_get_file (GthCatalog *catalog);
void gth_catalog_set_name (GthCatalog *catalog,
const char *name);
const char * gth_catalog_get_name (GthCatalog *catalog);
void gth_catalog_set_date (GthCatalog *catalog,
GthDateTime *date_time);
GthDateTime * gth_catalog_get_date (GthCatalog *catalog);
void gth_catalog_set_order (GthCatalog *catalog,
const char *order,
gboolean inverse);
......@@ -97,9 +103,6 @@ void gth_catalog_append_file (GthCatalog *catalog,
GFile *file);
int gth_catalog_remove_file (GthCatalog *catalog,
GFile *file);
void gth_catalog_set_date (GthCatalog *catalog,
GthDateTime *date_time);
GthDateTime * gth_catalog_get_date (GthCatalog *catalog);
void gth_catalog_list_async (GthCatalog *catalog,
const char *attributes,
GCancellable *cancellable,
......@@ -111,18 +114,19 @@ void gth_catalog_update_metadata (GthCatalog *catalog,
/* utils */
GFile * gth_catalog_get_base (void);
GFile * gth_catalog_file_to_gio_file (GFile *file);
GFile * gth_catalog_file_from_gio_file (GFile *file,
GFile *catalog);
GFile * gth_catalog_file_from_relative_path (const char *name,
const char *file_extension);
char * gth_catalog_get_relative_path (GFile *file);
GIcon * gth_catalog_get_icon (GFile *file);
char * gth_catalog_get_display_name (GFile *file);
void gth_catalog_load_from_file (GFile *file,
GCancellable *cancellable,
ReadyCallback ready_func,
gpointer user_data);
GFile * gth_catalog_get_base (void);
GFile * gth_catalog_file_to_gio_file (GFile *file);
GFile * gth_catalog_file_from_gio_file (GFile *file,
GFile *catalog);
GFile * gth_catalog_file_from_relative_path (const char *name,
const char *file_extension);
char * gth_catalog_get_relative_path (GFile *file);
GIcon * gth_catalog_get_icon (GFile *file);
void gth_catalog_update_standard_attributes (GFile *file,
GFileInfo *info);
void gth_catalog_load_from_file (GFile *file,
GCancellable *cancellable,
ReadyCallback ready_func,
gpointer user_data);
#endif /*GTH_CATALOG_H*/
......@@ -73,7 +73,6 @@ update_file_info (GthFileSource *file_source,
GFileInfo *info)
{
char *uri;
char *name;
uri = g_file_get_uri (catalog_file);
......@@ -83,10 +82,7 @@ update_file_info (GthFileSource *file_source,
g_file_info_set_icon (info, g_themed_icon_new ("image-catalog"));
g_file_info_set_sort_order (info, 1);
g_file_info_set_attribute_boolean (info, "gthumb::no-child", TRUE);
name = gth_catalog_get_display_name (catalog_file);
g_file_info_set_display_name (info, name);
g_free (name);
gth_catalog_update_standard_attributes (catalog_file, info);
}
else if (g_str_has_suffix (uri, ".search")) {
g_file_info_set_file_type (info, G_FILE_TYPE_DIRECTORY);
......@@ -94,10 +90,7 @@ update_file_info (GthFileSource *file_source,
g_file_info_set_icon (info, g_themed_icon_new ("image-search"));
g_file_info_set_sort_order (info, 1);
g_file_info_set_attribute_boolean (info, "gthumb::no-child", TRUE);
name = gth_catalog_get_display_name (catalog_file);
g_file_info_set_display_name (info, name);
g_free (name);
gth_catalog_update_standard_attributes (catalog_file, info);
}
else {
g_file_info_set_file_type (info, G_FILE_TYPE_DIRECTORY);
......@@ -105,10 +98,7 @@ update_file_info (GthFileSource *file_source,
g_file_info_set_icon (info, g_themed_icon_new ("image-library"));
g_file_info_set_sort_order (info, 0);
g_file_info_set_attribute_boolean (info, "gthumb::no-child", FALSE);
name = gth_catalog_get_display_name (catalog_file);
g_file_info_set_display_name (info, name);
g_free (name);
gth_catalog_update_standard_attributes (catalog_file, info);
}
g_free (uri);
......
......@@ -764,10 +764,10 @@ _gth_folder_tree_set_file_data (GthFolderTree *folder_tree,
GtkTreeIter *iter,
GthFileData *file_data)
{
GIcon *icon;
GdkPixbuf *pixbuf;
const char *name;
char *sort_key;
GIcon *icon;
GdkPixbuf *pixbuf;
const char *name;
char *sort_key;
icon = g_file_info_get_icon (file_data->info);
pixbuf = gth_icon_cache_get_pixbuf (folder_tree->priv->icon_cache, icon);
......
......@@ -128,7 +128,9 @@ gth_datetime_from_exif_date (GthDateTime *dt,
GDateDay day;
long val;
g_return_val_if_fail (exif_date != NULL, FALSE);
if (exif_date == NULL)
return FALSE;
g_return_val_if_fail (dt != NULL, FALSE);
while (g_ascii_isspace (*exif_date))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment