[gedit] Use GTimeVal instead of time_t.
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gedit] Use GTimeVal instead of time_t.
- Date: Wed, 25 Nov 2009 23:43:02 +0000 (UTC)
commit c09638a5b73d4d7903cc9c38c773ccd0e5eb64ca
Author: Ignacio Casal Quinteiro <icq gnome org>
Date: Thu Nov 26 00:41:11 2009 +0100
Use GTimeVal instead of time_t.
gedit/gedit-document-saver.c | 2 +-
gedit/gedit-document-saver.h | 4 ++--
gedit/gedit-document.c | 22 +++++++++++++---------
gedit/gedit-gio-document-saver.c | 14 ++++++++------
gedit/gedit-local-document-saver.c | 34 +++++++++++++++++++++-------------
5 files changed, 45 insertions(+), 31 deletions(-)
---
diff --git a/gedit/gedit-document-saver.c b/gedit/gedit-document-saver.c
index 783d161..1e58479 100644
--- a/gedit/gedit-document-saver.c
+++ b/gedit/gedit-document-saver.c
@@ -456,7 +456,7 @@ gedit_document_saver_saving (GeditDocumentSaver *saver,
void
gedit_document_saver_save (GeditDocumentSaver *saver,
- time_t old_mtime)
+ GTimeVal *old_mtime)
{
gedit_debug (DEBUG_SAVER);
diff --git a/gedit/gedit-document-saver.h b/gedit/gedit-document-saver.h
index a83a818..1e4d979 100644
--- a/gedit/gedit-document-saver.h
+++ b/gedit/gedit-document-saver.h
@@ -86,7 +86,7 @@ struct _GeditDocumentSaverClass
/* VTable */
void (* save) (GeditDocumentSaver *saver,
- time_t old_mtime);
+ GTimeVal *old_mtime);
goffset (* get_file_size) (GeditDocumentSaver *saver);
goffset (* get_bytes_written) (GeditDocumentSaver *saver);
};
@@ -119,7 +119,7 @@ void gedit_document_saver_saving (GeditDocumentSaver *saver,
gboolean completed,
GError *error);
void gedit_document_saver_save (GeditDocumentSaver *saver,
- time_t old_mtime);
+ GTimeVal *old_mtime);
#if 0
void gedit_document_saver_cancel (GeditDocumentSaver *saver);
diff --git a/gedit/gedit-document.c b/gedit/gedit-document.c
index 7be1e80..13729ed 100644
--- a/gedit/gedit-document.c
+++ b/gedit/gedit-document.c
@@ -111,7 +111,7 @@ struct _GeditDocumentPrivate
gchar *content_type;
- time_t mtime;
+ GTimeVal mtime;
GTimeVal time_of_last_save_or_load;
@@ -775,7 +775,8 @@ gedit_document_init (GeditDocument *doc)
doc->priv->dispose_has_run = FALSE;
- doc->priv->mtime = 0;
+ doc->priv->mtime.tv_sec = 0;
+ doc->priv->mtime.tv_usec = 0;
g_get_current_time (&doc->priv->time_of_last_save_or_load);
@@ -1016,7 +1017,9 @@ _gedit_document_check_externally_modified (GeditDocument *doc)
g_file_info_get_modification_time (info, &timeval);
g_object_unref (info);
- return timeval.tv_sec > doc->priv->mtime;
+ return (timeval.tv_sec > doc->priv->mtime.tv_sec) ||
+ (timeval.tv_sec == doc->priv->mtime.tv_sec &&
+ timeval.tv_usec > doc->priv->mtime.tv_usec);
}
static void
@@ -1042,6 +1045,7 @@ document_loader_loaded (GeditDocumentLoader *loader,
GFileInfo *info;
const gchar *content_type = NULL;
gboolean read_only = FALSE;
+ GTimeVal mtime = {0, 0};
info = gedit_document_loader_get_info (loader);
@@ -1052,14 +1056,15 @@ document_loader_loaded (GeditDocumentLoader *loader,
G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE);
if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_TIME_MODIFIED))
- doc->priv->mtime = g_file_info_get_attribute_uint64 (info,
- G_FILE_ATTRIBUTE_TIME_MODIFIED);
+ g_file_info_get_modification_time (info, &mtime);
if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE))
read_only = !g_file_info_get_attribute_boolean (info,
G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE);
}
+ doc->priv->mtime = mtime;
+
set_readonly (doc, read_only);
g_get_current_time (&doc->priv->time_of_last_save_or_load);
@@ -1253,7 +1258,7 @@ document_saver_saving (GeditDocumentSaver *saver,
{
const gchar *uri;
const gchar *content_type = NULL;
- goffset mtime = 0;
+ GTimeVal mtime = {0, 0};
GFileInfo *info;
uri = gedit_document_saver_get_uri (saver);
@@ -1268,8 +1273,7 @@ document_saver_saving (GeditDocumentSaver *saver,
G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE);
if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_TIME_MODIFIED))
- mtime = g_file_info_get_attribute_uint64 (info,
- G_FILE_ATTRIBUTE_TIME_MODIFIED);
+ g_file_info_get_modification_time (info, &mtime);
}
set_content_type (doc, content_type);
@@ -1333,7 +1337,7 @@ gedit_document_save_real (GeditDocument *doc,
doc->priv->requested_encoding = encoding;
gedit_document_saver_save (doc->priv->saver,
- doc->priv->mtime);
+ &doc->priv->mtime);
}
/**
diff --git a/gedit/gedit-gio-document-saver.c b/gedit/gedit-gio-document-saver.c
index 180cce3..fbd1256 100644
--- a/gedit/gedit-gio-document-saver.c
+++ b/gedit/gedit-gio-document-saver.c
@@ -58,7 +58,7 @@ typedef struct
GeditGioDocumentSaverPrivate))
static void gedit_gio_document_saver_save (GeditDocumentSaver *saver,
- time_t old_mtime);
+ GTimeVal *old_mtime);
static goffset gedit_gio_document_saver_get_file_size (GeditDocumentSaver *saver);
static goffset gedit_gio_document_saver_get_bytes_written (GeditDocumentSaver *saver);
@@ -67,7 +67,7 @@ static void check_modified_async (AsyncData *async);
struct _GeditGioDocumentSaverPrivate
{
- time_t old_mtime;
+ GTimeVal old_mtime;
goffset size;
goffset bytes_written;
@@ -627,11 +627,13 @@ check_modification_callback (GFile *source,
G_FILE_ATTRIBUTE_TIME_MODIFIED))
{
GTimeVal mtime;
+ GTimeVal old_mtime;
g_file_info_get_modification_time (info, &mtime);
+ old_mtime = gvsaver->priv->old_mtime;
- if (gvsaver->priv->old_mtime > 0 &&
- mtime.tv_sec != gvsaver->priv->old_mtime &&
+ if ((old_mtime.tv_sec > 0 || old_mtime.tv_usec > 0) &&
+ (mtime.tv_sec != old_mtime.tv_sec || mtime.tv_usec != old_mtime.tv_usec) &&
(GEDIT_DOCUMENT_SAVER (gvsaver)->flags & GEDIT_DOCUMENT_SAVE_IGNORE_MTIME) == 0)
{
gedit_debug_message (DEBUG_SAVER, "File is externally modified");
@@ -688,11 +690,11 @@ save_remote_file_real (GeditGioDocumentSaver *gvsaver)
static void
gedit_gio_document_saver_save (GeditDocumentSaver *saver,
- time_t old_mtime)
+ GTimeVal *old_mtime)
{
GeditGioDocumentSaver *gvsaver = GEDIT_GIO_DOCUMENT_SAVER (saver);
- gvsaver->priv->old_mtime = old_mtime;
+ gvsaver->priv->old_mtime = *old_mtime;
gvsaver->priv->gfile = g_file_new_for_uri (saver->uri);
/* saving start */
diff --git a/gedit/gedit-local-document-saver.c b/gedit/gedit-local-document-saver.c
index 0411be5..5547aa8 100644
--- a/gedit/gedit-local-document-saver.c
+++ b/gedit/gedit-local-document-saver.c
@@ -58,7 +58,7 @@
GeditLocalDocumentSaverPrivate))
static void gedit_local_document_saver_save (GeditDocumentSaver *saver,
- time_t old_mtime);
+ GTimeVal *old_mtime);
static goffset gedit_local_document_saver_get_file_size (GeditDocumentSaver *saver);
static goffset gedit_local_document_saver_get_bytes_written (GeditDocumentSaver *saver);
@@ -71,7 +71,7 @@ struct _GeditLocalDocumentSaverPrivate
gint fd;
gchar *local_path;
gchar *content_type;
- time_t doc_mtime;
+ GTimeVal doc_mtime;
GError *error;
};
@@ -301,10 +301,15 @@ set_saver_info (GeditLocalDocumentSaver *lsaver)
g_object_unref (saver->info);
saver->info = g_file_info_new ();
- g_file_info_set_content_type (saver->info, lsaver->priv->content_type);
- g_file_info_set_attribute_uint64 (saver->info,
- G_FILE_ATTRIBUTE_TIME_MODIFIED,
- lsaver->priv->doc_mtime);
+
+ if (lsaver->priv->content_type != NULL)
+ {
+ g_file_info_set_content_type (saver->info,
+ lsaver->priv->content_type);
+ }
+
+ g_file_info_set_modification_time (saver->info,
+ &lsaver->priv->doc_mtime);
}
static gboolean
@@ -365,8 +370,8 @@ save_existing_local_file (GeditLocalDocumentSaver *lsaver)
* except when "saving as", when saving a new doc (mtime = 0)
* or when the mtime check is explicitely disabled
*/
- if (lsaver->priv->doc_mtime > 0 &&
- statbuf.st_mtime != lsaver->priv->doc_mtime &&
+ if (lsaver->priv->doc_mtime.tv_sec > 0 &&
+ statbuf.st_mtime != lsaver->priv->doc_mtime.tv_sec &&
((saver->flags & GEDIT_DOCUMENT_SAVE_IGNORE_MTIME) == 0))
{
g_set_error (&lsaver->priv->error,
@@ -538,7 +543,8 @@ save_existing_local_file (GeditLocalDocumentSaver *lsaver)
goto out;
}
- lsaver->priv->doc_mtime = new_statbuf.st_mtime;
+ lsaver->priv->doc_mtime.tv_sec = new_statbuf.st_mtime;
+ lsaver->priv->doc_mtime.tv_usec = 0;
lsaver->priv->content_type = get_slow_content_type (saver->uri);
@@ -723,7 +729,8 @@ save_existing_local_file (GeditLocalDocumentSaver *lsaver)
goto out;
}
- lsaver->priv->doc_mtime = new_statbuf.st_mtime;
+ lsaver->priv->doc_mtime.tv_sec = new_statbuf.st_mtime;
+ lsaver->priv->doc_mtime.tv_usec = 0;
g_free (lsaver->priv->content_type);
lsaver->priv->content_type = get_slow_content_type (saver->uri);
@@ -771,7 +778,8 @@ save_new_local_file (GeditLocalDocumentSaver *lsaver)
goto out;
}
- lsaver->priv->doc_mtime = statbuf.st_mtime;
+ lsaver->priv->doc_mtime.tv_sec = statbuf.st_mtime;
+ lsaver->priv->doc_mtime.tv_usec = 0;
g_free (lsaver->priv->content_type);
lsaver->priv->content_type = get_slow_content_type (GEDIT_DOCUMENT_SAVER (lsaver)->uri);
@@ -865,12 +873,12 @@ save_file (GeditLocalDocumentSaver *lsaver)
static void
gedit_local_document_saver_save (GeditDocumentSaver *saver,
- time_t old_mtime)
+ GTimeVal *old_mtime)
{
GeditLocalDocumentSaver *lsaver = GEDIT_LOCAL_DOCUMENT_SAVER (saver);
GFile *gfile;
- lsaver->priv->doc_mtime = old_mtime;
+ lsaver->priv->doc_mtime = *old_mtime;
gfile = g_file_new_for_uri (saver->uri);
lsaver->priv->local_path = g_file_get_path (gfile);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]