Commit ef59e7fd authored by Marc Pavot's avatar Marc Pavot Committed by Michael J. Chudobiak
Browse files

Fix display on multiple edit of tags and improve gth-monitor

The gth-monitor files have moved from src/ to libgthumb/.
parent 69c84004
......@@ -50,6 +50,7 @@ HEADER_FILES = \
gth-pixbuf-op.h \
gth-sort-utils.h \
gth-utils.h \
gth-monitor.h \
gthumb-error.h \
gthumb-histogram.h \
gthumb-init.h \
......@@ -110,6 +111,7 @@ libgthumb_la_SOURCES = \
gth-nav-window.c \
gth-sort-utils.c \
gth-utils.c \
gth-monitor.c \
gthumb-error.c \
gthumb-histogram.c \
gthumb-init.c \
......
......@@ -29,7 +29,6 @@
#include <dirent.h>
#include <string.h>
#include <strings.h>
#include <ctype.h>
#include <time.h>
#include <glib/gi18n.h>
......@@ -44,6 +43,7 @@
#include "glib-utils.h"
#include "gtk-utils.h"
#include "gth-exif-utils.h"
#include "gth-monitor.h"
#define COMMENT_TAG ((xmlChar *)"Comment")
#define PLACE_TAG ((xmlChar *)"Place")
......@@ -394,20 +394,6 @@ load_comment_from_metadata (const char *uri)
return data;
}
static char*
get_keywords_str (CommentData *data)
{
GString *keywords_str;
GSList *tmp;
keywords_str = g_string_new (NULL);
for (tmp = data->keywords; tmp; tmp = g_slist_next (tmp)) {
keywords_str = g_string_append (keywords_str, g_strdup (tmp->data));
if (g_slist_next (tmp))
keywords_str = g_string_append_c (keywords_str, ',');
}
return g_string_free (keywords_str, FALSE);
}
static void
save_comment_to_metadata (const char *uri,
......@@ -436,7 +422,7 @@ save_comment_to_metadata (const char *uri,
add_metadata = simple_add_metadata (add_metadata, TAG_NAME_SETS[COMMENT_DATE_TAG_NAMES][0], buf);
add_metadata = clear_metadata_tagset (add_metadata, TAG_NAME_SETS[KEYWORD_TAG_NAMES]);
keywords_str = get_keywords_str (data);
keywords_str = comments_get_tags_as_string (data, ",");
add_metadata = simple_add_metadata (add_metadata, TAG_NAME_SETS[KEYWORD_TAG_NAMES][0], keywords_str);
g_free (keywords_str);
......@@ -537,7 +523,7 @@ save_comment (const char *uri,
/* Convert data to strings. */
time_str = g_strdup_printf ("%ld", data->time);
keywords_str = get_keywords_str (data);
keywords_str = comments_get_tags_as_string (data, ",");
/* Escape text */
......@@ -659,6 +645,7 @@ comments_save_comment (const char *uri,
save_comment (uri, new_data, TRUE);
comment_data_free (new_data);
gth_monitor_notify_update_metadata (uri);
}
......@@ -730,6 +717,7 @@ comments_save_tags (const char *uri,
save_comment (uri, new_data, TRUE);
comment_data_free (new_data);
gth_monitor_notify_update_metadata (uri);
}
......@@ -813,113 +801,10 @@ comment_text_is_void (CommentData *data)
}
/* based on glib/glib/gmarkup.c (Copyright 2000, 2003 Red Hat, Inc.)
* This version does not escape ' and ''. Needed because IE does not recognize
* &apos; and &quot; */
static void
_append_escaped_text_for_html (GString *str,
const gchar *text,
gssize length)
{
const gchar *p;
const gchar *end;
gunichar ch;
int state = 0;
p = text;
end = text + length;
while (p != end) {
const gchar *next;
next = g_utf8_next_char (p);
ch = g_utf8_get_char (p);
switch (state) {
case 1: /* escaped */
if ((ch > 127) || !isprint((char)ch))
g_string_append_printf (str, "\\&#%d;", ch);
else
g_string_append_unichar (str, ch);
state = 0;
break;
default: /* not escaped */
switch (*p) {
case '\\':
state = 1; /* next character is escaped */
break;
case '&':
g_string_append (str, "&amp;");
break;
case '<':
g_string_append (str, "&lt;");
break;
case '>':
g_string_append (str, "&gt;");
break;
case '\n':
g_string_append (str, "<br />");
break;
default:
if ((ch > 127) || !isprint((char)ch))
g_string_append_printf (str, "&#%d;", ch);
else
g_string_append_unichar (str, ch);
state = 0;
break;
}
}
p = next;
}
}
char*
_g_escape_text_for_html (const gchar *text,
gssize length)
{
GString *str;
g_return_val_if_fail (text != NULL, NULL);
if (length < 0)
length = strlen (text);
/* prealloc at least as long as original text */
str = g_string_sized_new (length);
_append_escaped_text_for_html (str, text, length);
return g_string_free (str, FALSE);
}
static void
_string_append (GString *str,
const char *a,
gboolean markup_escape)
{
if (a == NULL)
return;
if (markup_escape)
_append_escaped_text_for_html (str, a, strlen (a));
else
g_string_append (str, a);
}
/* Note: separators are not escaped */
static char *
_get_comment_as_string_common (CommentData *data,
char *sep1,
char *sep2,
gboolean markup_escape)
char *
comments_get_comment_as_string (CommentData *data,
char *sep1,
char *sep2)
{
char *as_string = NULL;
char time_txt[50] = "";
......@@ -943,8 +828,6 @@ _get_comment_as_string_common (CommentData *data,
&& (data->time == 0)) {
if (data->keywords)
as_string = NULL;
else if (markup_escape)
as_string = g_markup_escape_text (_("(No Comment)"), -1);
else
as_string = g_strdup (_("(No Comment)"));
......@@ -954,20 +837,20 @@ _get_comment_as_string_common (CommentData *data,
comment = g_string_new ("");
if (data->comment != NULL)
_string_append (comment, data->comment, markup_escape);
g_string_append (comment, data->comment);
if ((data->comment != NULL)
&& ((data->place != NULL) || (*time_txt != 0)))
g_string_append (comment, sep1);
if (data->place != NULL)
_string_append (comment, data->place, markup_escape);
g_string_append (comment, data->place);
if ((data->place != NULL) && (*time_txt != 0))
g_string_append (comment, sep2);
if (utf8_time_txt != NULL)
_string_append (comment, utf8_time_txt, markup_escape);
g_string_append (comment, utf8_time_txt);
as_string = comment->str;
g_string_free (comment, FALSE);
......@@ -976,13 +859,13 @@ _get_comment_as_string_common (CommentData *data,
g_free (utf8_time_txt);
return as_string;
}
/* Note: separators are not escaped */
static char *
_get_tags_as_string_common (CommentData *data,
char *sep)
char *
comments_get_tags_as_string (CommentData *data,
char *sep)
{
GString *tags;
GSList *tmp;
......@@ -1003,20 +886,3 @@ _get_tags_as_string_common (CommentData *data,
return g_string_free (tags, FALSE);
}
char *
comments_get_comment_as_string (CommentData *data,
char *sep1,
char *sep2)
{
return _get_comment_as_string_common (data, sep1, sep2, FALSE);
}
char *
comments_get_tags_as_string (CommentData *data,
char *sep)
{
return _get_tags_as_string_common (data, sep);
}
......@@ -75,8 +75,6 @@ char * comments_get_comment_as_string (CommentData *data,
char *sep2);
char * comments_get_tags_as_string (CommentData *data,
char *sep);
char* _g_escape_text_for_html (const gchar *text,
gssize length);
#endif /* COMMENTS_H */
......@@ -270,15 +270,6 @@ file_data_set_path (FileData *fd,
file_data_update (fd);
}
void
file_data_load_comment_data (FileData *fd)
{
g_return_if_fail (fd != NULL);
if (fd->comment_data != NULL)
return;
fd->comment_data = comments_load_comment (fd->path, FALSE);
}
void
file_data_update_comment (FileData *fd)
......@@ -402,3 +393,15 @@ file_data_has_local_path (FileData *fd,
return TRUE;
}
}
CommentData *
file_data_get_comment (FileData *fd)
{
g_return_val_if_fail (fd != NULL, NULL);
if (!fd->comment_data)
fd->comment_data = comments_load_comment (fd->path, FALSE);
return fd->comment_data;
}
......@@ -57,7 +57,8 @@ typedef struct {
char *comment;
char *tags;
CommentData *comment_data;
CommentData *comment_data; /* Do not access this directly. Use
file_data_get_comment (fd) instead. */
GList *metadata;
} FileData;
......@@ -76,8 +77,8 @@ void file_data_update_mime_type (FileData *fd,
gboolean fast_mime_type);
void file_data_update_all (FileData *fd,
gboolean fast_mime_type);
void file_data_load_comment_data (FileData *fd);
void file_data_update_comment (FileData *fd);
CommentData* file_data_get_comment (FileData *fd);
GList* file_data_list_from_uri_list (GList *list);
GList* uri_list_from_file_data_list (GList *list);
......
......@@ -310,6 +310,7 @@ gth_test_match (GthTest *test,
FileData *fdata)
{
gboolean result = FALSE;
CommentData *cdata;
switch (test->scope) {
case GTH_TEST_SCOPE_FILENAME:
......@@ -317,27 +318,27 @@ gth_test_match (GthTest *test,
break;
case GTH_TEST_SCOPE_COMMENT:
file_data_load_comment_data (fdata);
if (fdata->comment_data != NULL)
result = test_string (test, fdata->comment_data->comment);
cdata = file_data_get_comment (fdata);
if (cdata)
result = test_string (test, cdata->comment);
else
result = test->negative;
break;
case GTH_TEST_SCOPE_PLACE:
file_data_load_comment_data (fdata);
if (fdata->comment_data != NULL)
result = test_string (test, fdata->comment_data->place);
cdata = file_data_get_comment (fdata);
if (cdata != NULL)
result = test_string (test, cdata->place);
break;
case GTH_TEST_SCOPE_ALL:
file_data_load_comment_data (fdata);
if (fdata->comment_data != NULL) {
cdata = file_data_get_comment (fdata);
if (cdata != NULL) {
result = (test_string (test, fdata->utf8_name)
|| test_string (test, fdata->comment_data->comment)
|| test_string (test, fdata->comment_data->place));
if (! result && (fdata->comment_data != NULL))
result = test_keywords (test, fdata->comment_data->keywords);
|| test_string (test, cdata->comment)
|| test_string (test, cdata->place));
if (! result && (cdata != NULL))
result = test_keywords (test, cdata->keywords);
} else
result = test->negative;
break;
......@@ -347,9 +348,9 @@ gth_test_match (GthTest *test,
break;
case GTH_TEST_SCOPE_KEYWORDS:
file_data_load_comment_data (fdata);
if (fdata->comment_data != NULL)
result = test_keywords (test, fdata->comment_data->keywords);
cdata = file_data_get_comment (fdata);
if (cdata != NULL)
result = test_keywords (test, cdata->keywords);
else
result = test->negative;
break;
......
......@@ -30,7 +30,6 @@
#include "gstringlist.h"
#include "gthumb-marshal.h"
#include "gth-monitor.h"
#include "main.h"
#define UPDATE_DIR_DELAY 500
......@@ -64,6 +63,7 @@ typedef struct {
int ref;
} MonitorHandle;
static GthMonitor *instance = NULL;
MonitorHandle *
monitor_handle_new (GFileMonitor *monitor_handle,
......@@ -236,7 +236,7 @@ proc_monitor_events (gpointer data)
if (name[0] == '.')
continue;
all_windows_notify_directory_new (path);
gth_monitor_notify_update_directory (path, GTH_MONITOR_EVENT_CREATED);
}
path_list_free (dir_created_list);
......@@ -244,24 +244,24 @@ proc_monitor_events (gpointer data)
for (scan = dir_deleted_list; scan; scan = scan->next) {
char *path = scan->data;
all_windows_notify_directory_delete (path);
gth_monitor_notify_update_directory (path, GTH_MONITOR_EVENT_DELETED);
}
path_list_free (dir_deleted_list);
/**/
if (file_created_list != NULL) {
all_windows_notify_files_created (file_created_list);
gth_monitor_notify_update_files (GTH_MONITOR_EVENT_CREATED, file_created_list);
path_list_free (file_created_list);
}
if (file_deleted_list != NULL) {
all_windows_notify_files_deleted (file_deleted_list);
gth_monitor_notify_update_files (GTH_MONITOR_EVENT_DELETED, file_deleted_list);
path_list_free (file_deleted_list);
}
if (file_changed_list != NULL) {
all_windows_notify_files_changed (file_changed_list);
gth_monitor_notify_update_files (GTH_MONITOR_EVENT_CHANGED, file_changed_list);
path_list_free (file_changed_list);
}
......@@ -386,10 +386,9 @@ directory_changed (GFileMonitor *handle,
void
gth_monitor_add_uri (GthMonitor *monitor,
const char *uri)
gth_monitor_add_uri (const char *uri)
{
GthMonitorPrivateData *priv = monitor->priv;
GthMonitorPrivateData *priv = instance->priv;
GFileMonitor *monitor_handle;
GList *item;
GFile *gfile;
......@@ -417,7 +416,7 @@ gth_monitor_add_uri (GthMonitor *monitor,
g_signal_connect (G_OBJECT (monitor_handle),
"changed",
G_CALLBACK (directory_changed),
monitor);
instance);
}
priv->monitor_enabled = TRUE;
......@@ -425,10 +424,9 @@ gth_monitor_add_uri (GthMonitor *monitor,
void
gth_monitor_remove_uri (GthMonitor *monitor,
const char *uri)
gth_monitor_remove_uri (const char *uri)
{
GthMonitorPrivateData *priv = monitor->priv;
GthMonitorPrivateData *priv = instance->priv;
GList *item;
MonitorHandle *mh;
......@@ -447,60 +445,61 @@ gth_monitor_remove_uri (GthMonitor *monitor,
monitor_handle_unref (mh);
}
GthMonitor *
gth_monitor_new (void)
gth_monitor_get_instance (void)
{
return (GthMonitor*) g_object_new (GTH_TYPE_MONITOR, NULL);
if (!instance) {
instance = GTH_MONITOR (g_object_new (GTH_TYPE_MONITOR, NULL));
}
return instance;
}
void
gth_monitor_pause (GthMonitor *monitor)
gth_monitor_pause (void)
{
monitor->priv->monitor_enabled = FALSE;
instance->priv->monitor_enabled = FALSE;
}
void
gth_monitor_resume (GthMonitor *monitor)
gth_monitor_resume (void)
{
monitor->priv->monitor_enabled = TRUE;
instance->priv->monitor_enabled = TRUE;
}
void
gth_monitor_notify_update_icon_theme (GthMonitor *monitor)
gth_monitor_notify_update_icon_theme (void)
{
g_return_if_fail (GTH_IS_MONITOR (monitor));
g_signal_emit (G_OBJECT (monitor),
g_return_if_fail (GTH_IS_MONITOR (instance));
g_signal_emit (G_OBJECT (instance),
monitor_signals[UPDATE_ICON_THEME],
0);
}
void
gth_monitor_notify_update_bookmarks (GthMonitor *monitor)
gth_monitor_notify_update_bookmarks (void)
{
g_return_if_fail (GTH_IS_MONITOR (monitor));
g_signal_emit (G_OBJECT (monitor),
g_return_if_fail (GTH_IS_MONITOR (instance));
g_signal_emit (G_OBJECT (instance),
monitor_signals[UPDATE_BOOKMARKS],
0);
}
void
gth_monitor_notify_update_cat_files (GthMonitor *monitor,
const char *catalog_path,
gth_monitor_notify_update_cat_files (const char *catalog_path,
GthMonitorEvent event,
GList *list)
{
g_return_if_fail (GTH_IS_MONITOR (monitor));
g_return_if_fail (GTH_IS_MONITOR (instance));
if (list == NULL)
return;
g_signal_emit (G_OBJECT (monitor),
g_signal_emit (G_OBJECT (instance),
monitor_signals[UPDATE_CAT_FILES],
0,
catalog_path,
......@@ -510,16 +509,15 @@ gth_monitor_notify_update_cat_files (GthMonitor *monitor,
void
gth_monitor_notify_update_files (GthMonitor *monitor,
GthMonitorEvent event,
gth_monitor_notify_update_files (GthMonitorEvent event,
GList *list)
{
g_return_if_fail (GTH_IS_MONITOR (monitor));
g_return_if_fail (GTH_IS_MONITOR (instance));
if (list == NULL)
return;
g_signal_emit (G_OBJECT (monitor),
g_signal_emit (G_OBJECT (instance),
monitor_signals[UPDATE_FILES],
0,
event,
......@@ -528,12 +526,11 @@ gth_monitor_notify_update_files (GthMonitor *monitor,
void
gth_monitor_notify_update_directory (GthMonitor *monitor,
const char *dir_path,
gth_monitor_notify_update_directory (const char *dir_path,
GthMonitorEvent event)
{
g_return_if_fail (GTH_IS_MONITOR (monitor));
g_signal_emit (G_OBJECT (monitor),
g_return_if_fail (GTH_IS_MONITOR (instance));
g_signal_emit (G_OBJECT (instance),
monitor_signals[UPDATE_DIRECTORY],
0,
dir_path,
......@@ -542,12 +539,11 @@ gth_monitor_notify_update_directory (GthMonitor *monitor,
void
gth_monitor_notify_update_catalog (GthMonitor *monitor,
const char *catalog_path,
gth_monitor_notify_update_catalog (const char *catalog_path,
GthMonitorEvent event)
{
g_return_if_fail (GTH_IS_MONITOR (monitor));
g_signal_emit (G_OBJECT (monitor),
g_return_if_fail (GTH_IS_MONITOR (instance));
g_signal_emit (G_OBJECT (instance),
monitor_signals[UPDATE_CATALOG],
0,
catalog_path,
......@@ -556,11 +552,10 @@ gth_monitor_notify_update_catalog (GthMonitor *monitor,
void
gth_monitor_notify_update_metadata (GthMonitor *monitor,
const char *path)
gth_monitor_notify_update_metadata (const char *path)
{
g_return_if_fail (GTH_IS_MONITOR (monitor));
g_signal_emit (G_OBJECT (monitor),