aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiguel de Icaza <miguel@nuclecu.unam.mx>1999-01-28 04:26:10 +0800
committerArturo Espinosa <unammx@src.gnome.org>1999-01-28 04:26:10 +0800
commitc970e7ace5de19acdb9cf664435cbec8264ee89e (patch)
tree9aa8a570c2ce45f48b2ee7dfafbf90970820fec3
parent6d97fa0fe88d5511cbefe38c0251bcce8d5d1575 (diff)
downloadgsoc2013-evolution-c970e7ace5de19acdb9cf664435cbec8264ee89e.tar
gsoc2013-evolution-c970e7ace5de19acdb9cf664435cbec8264ee89e.tar.gz
gsoc2013-evolution-c970e7ace5de19acdb9cf664435cbec8264ee89e.tar.bz2
gsoc2013-evolution-c970e7ace5de19acdb9cf664435cbec8264ee89e.tar.lz
gsoc2013-evolution-c970e7ace5de19acdb9cf664435cbec8264ee89e.tar.xz
gsoc2013-evolution-c970e7ace5de19acdb9cf664435cbec8264ee89e.tar.zst
gsoc2013-evolution-c970e7ace5de19acdb9cf664435cbec8264ee89e.zip
Warn if the calendar file has changed.
1999-01-27 Miguel de Icaza <miguel@nuclecu.unam.mx> * main.c (save_calendar_cmd): Warn if the calendar file has changed. * calendar.c (calendar_load, calendar_save): Keep track of the modification time for the calendar file. svn path=/trunk/; revision=632
-rw-r--r--calendar/ChangeLog8
-rw-r--r--calendar/calendar.c8
-rw-r--r--calendar/calendar.h3
-rw-r--r--calendar/gui/calendar.c8
-rw-r--r--calendar/gui/calendar.h3
-rw-r--r--calendar/gui/main.c62
-rw-r--r--calendar/main.c62
7 files changed, 118 insertions, 36 deletions
diff --git a/calendar/ChangeLog b/calendar/ChangeLog
index 05753e6020..9b94106c55 100644
--- a/calendar/ChangeLog
+++ b/calendar/ChangeLog
@@ -1,3 +1,11 @@
+1999-01-27 Miguel de Icaza <miguel@nuclecu.unam.mx>
+
+ * main.c (save_calendar_cmd): Warn if the calendar file has
+ changed.
+
+ * calendar.c (calendar_load, calendar_save): Keep track of the
+ modification time for the calendar file.
+
1999-01-20 Nat Friedman <nat@nat.org>
* gncal-full-day.c (gncal_full_day_key_press): Only trap printable
diff --git a/calendar/calendar.c b/calendar/calendar.c
index 5fa7035f3a..e5b050620e 100644
--- a/calendar/calendar.c
+++ b/calendar/calendar.c
@@ -14,6 +14,7 @@
#include <config.h>
#include <unistd.h>
+#include <sys/stat.h>
#include "calendar.h"
#include "alarm.h"
#include "timeutil.h"
@@ -280,6 +281,7 @@ calendar_load (Calendar *cal, char *fname)
{
VObject *vcal;
time_t calendar_today;
+ struct stat s;
if (cal->filename){
g_warning ("Calendar load called again\n");
@@ -291,6 +293,8 @@ calendar_load (Calendar *cal, char *fname)
if (!vcal)
return "Could not load the calendar";
+ stat (fname, &s);
+ cal->file_time = s.st_mtime;
calendar_today = time (NULL);
calendar_day_begin = time_day_begin (calendar_today);
calendar_day_end = time_day_end (calendar_today);
@@ -307,6 +311,7 @@ calendar_save (Calendar *cal, char *fname)
VObject *vcal;
GList *l;
time_t now = time (NULL);
+ struct stat s;
if (fname == NULL)
fname = cal->filename;
@@ -348,6 +353,9 @@ calendar_save (Calendar *cal, char *fname)
g_free (backup_name);
}
writeVObjectToFile (fname, vcal);
+
+ stat (fname, &s);
+ cal->file_time = s.st_mtime;
cleanVObject (vcal);
cleanStrTbl ();
diff --git a/calendar/calendar.h b/calendar/calendar.h
index bd0bf84b90..8dc0c517c3 100644
--- a/calendar/calendar.h
+++ b/calendar/calendar.h
@@ -20,6 +20,9 @@ typedef struct {
/* Time at which the calendar was created */
time_t created;
+ /* Timestamp in the filename */
+ time_t file_time;
+
/* If the calendar was last modified */
int modified;
void *temp;
diff --git a/calendar/gui/calendar.c b/calendar/gui/calendar.c
index 5fa7035f3a..e5b050620e 100644
--- a/calendar/gui/calendar.c
+++ b/calendar/gui/calendar.c
@@ -14,6 +14,7 @@
#include <config.h>
#include <unistd.h>
+#include <sys/stat.h>
#include "calendar.h"
#include "alarm.h"
#include "timeutil.h"
@@ -280,6 +281,7 @@ calendar_load (Calendar *cal, char *fname)
{
VObject *vcal;
time_t calendar_today;
+ struct stat s;
if (cal->filename){
g_warning ("Calendar load called again\n");
@@ -291,6 +293,8 @@ calendar_load (Calendar *cal, char *fname)
if (!vcal)
return "Could not load the calendar";
+ stat (fname, &s);
+ cal->file_time = s.st_mtime;
calendar_today = time (NULL);
calendar_day_begin = time_day_begin (calendar_today);
calendar_day_end = time_day_end (calendar_today);
@@ -307,6 +311,7 @@ calendar_save (Calendar *cal, char *fname)
VObject *vcal;
GList *l;
time_t now = time (NULL);
+ struct stat s;
if (fname == NULL)
fname = cal->filename;
@@ -348,6 +353,9 @@ calendar_save (Calendar *cal, char *fname)
g_free (backup_name);
}
writeVObjectToFile (fname, vcal);
+
+ stat (fname, &s);
+ cal->file_time = s.st_mtime;
cleanVObject (vcal);
cleanStrTbl ();
diff --git a/calendar/gui/calendar.h b/calendar/gui/calendar.h
index bd0bf84b90..8dc0c517c3 100644
--- a/calendar/gui/calendar.h
+++ b/calendar/gui/calendar.h
@@ -20,6 +20,9 @@ typedef struct {
/* Time at which the calendar was created */
time_t created;
+ /* Timestamp in the filename */
+ time_t file_time;
+
/* If the calendar was last modified */
int modified;
void *temp;
diff --git a/calendar/gui/main.c b/calendar/gui/main.c
index 9d03fecd61..16072c221c 100644
--- a/calendar/gui/main.c
+++ b/calendar/gui/main.c
@@ -11,6 +11,7 @@
#include <gnome.h>
#include <pwd.h>
#include <sys/types.h>
+#include <sys/stat.h>
#include <string.h>
#include <ctype.h>
#include "calendar.h"
@@ -391,9 +392,34 @@ save_calendar_cmd (GtkWidget *widget, void *data)
{
GnomeCalendar *gcal = data;
- if (gcal->cal->filename)
+ if (gcal->cal->filename){
+ struct stat s;
+
+ stat (gcal->cal->filename, &s);
+
+ if (s.st_mtime != gcal->cal->file_time){
+ GtkWidget *box;
+ char *str;
+ int b;
+
+ str = g_strdup_printf (
+ _("File %s has changed since it was loaded\nContinue?"),
+ gcal->cal->filename);
+ box = gnome_message_box_new (str, GNOME_MESSAGE_BOX_INFO,
+ GNOME_STOCK_BUTTON_YES,
+ GNOME_STOCK_BUTTON_NO,
+ NULL);
+ g_free (str);
+ gnome_dialog_set_default (GNOME_DIALOG (box), 1);
+ b = gnome_dialog_run (GNOME_DIALOG (box));
+ gtk_object_destroy (GTK_OBJECT (box));
+
+ if (b != 0)
+ return;
+ }
+
calendar_save (gcal->cal, gcal->cal->filename);
- else
+ } else
save_as_calendar_cmd (widget, data);
}
@@ -650,17 +676,17 @@ parse_an_arg (poptContext ctx,
}
}
-static const struct poptOption options[] = {
- {NULL, '\0', POPT_ARG_CALLBACK, parse_an_arg, 0, NULL, NULL},
- {"events", 'e', POPT_ARG_NONE, NULL, 'e', N_("Show events and quit"),
- NULL},
- {"from", 'f', POPT_ARG_STRING, NULL, 'f', N_("Specifies start date [for --events]"), N_("DATE")},
- {"file", 'F', POPT_ARG_STRING, NULL, 'F', N_("File to load calendar from"), N_("FILE")},
- {"userfile", '\0', POPT_ARG_NONE, NULL, USERFILE_KEY, N_("Load the user calendar"), NULL},
- {"geometry", '\0', POPT_ARG_STRING, NULL, GEOMETRY_KEY, N_("Geometry for starting up"), N_("GEOMETRY")},
- {"view", '\0', POPT_ARG_STRING, NULL, VIEW_KEY, N_("The startup view mode"), N_("VIEW")},
- {"to", 't', POPT_ARG_STRING, NULL, 't', N_("Specifies ending date [for --events]"), N_("DATE")},
- {NULL, '\0', 0, NULL, 0}
+static const struct poptOption options [] = {
+ { NULL, '\0', POPT_ARG_CALLBACK, parse_an_arg, 0, NULL, NULL },
+ { "events", 'e', POPT_ARG_NONE, NULL, 'e', N_("Show events and quit"),
+ NULL },
+ { "from", 'f', POPT_ARG_STRING, NULL, 'f', N_("Specifies start date [for --events]"), N_("DATE") },
+ { "file", 'F', POPT_ARG_STRING, NULL, 'F', N_("File to load calendar from"), N_("FILE") },
+ { "userfile", '\0', POPT_ARG_NONE, NULL, USERFILE_KEY, N_("Load the user calendar"), NULL },
+ { "geometry", '\0', POPT_ARG_STRING, NULL, GEOMETRY_KEY, N_("Geometry for starting up"), N_("GEOMETRY") },
+ { "view", '\0', POPT_ARG_STRING, NULL, VIEW_KEY, N_("The startup view mode"), N_("VIEW") },
+ { "to", 't', POPT_ARG_STRING, NULL, 't', N_("Specifies ending date [for --events]"), N_("DATE") },
+ { NULL, '\0', 0, NULL, 0}
};
static void
@@ -719,14 +745,14 @@ main(int argc, char *argv[])
{
GnomeClient *client;
- bindtextdomain(PACKAGE, GNOMELOCALEDIR);
- textdomain(PACKAGE);
+ bindtextdomain (PACKAGE, GNOMELOCALEDIR);
+ textdomain (PACKAGE);
- gnome_init_with_popt_table("calendar", VERSION, argc, argv,
- options, 0, NULL);
+ gnome_init_with_popt_table ("calendar", VERSION, argc, argv,
+ options, 0, NULL);
if (show_events)
- dump_events ();
+ dump_events ();
client = gnome_master_client ();
if (client){
diff --git a/calendar/main.c b/calendar/main.c
index 9d03fecd61..16072c221c 100644
--- a/calendar/main.c
+++ b/calendar/main.c
@@ -11,6 +11,7 @@
#include <gnome.h>
#include <pwd.h>
#include <sys/types.h>
+#include <sys/stat.h>
#include <string.h>
#include <ctype.h>
#include "calendar.h"
@@ -391,9 +392,34 @@ save_calendar_cmd (GtkWidget *widget, void *data)
{
GnomeCalendar *gcal = data;
- if (gcal->cal->filename)
+ if (gcal->cal->filename){
+ struct stat s;
+
+ stat (gcal->cal->filename, &s);
+
+ if (s.st_mtime != gcal->cal->file_time){
+ GtkWidget *box;
+ char *str;
+ int b;
+
+ str = g_strdup_printf (
+ _("File %s has changed since it was loaded\nContinue?"),
+ gcal->cal->filename);
+ box = gnome_message_box_new (str, GNOME_MESSAGE_BOX_INFO,
+ GNOME_STOCK_BUTTON_YES,
+ GNOME_STOCK_BUTTON_NO,
+ NULL);
+ g_free (str);
+ gnome_dialog_set_default (GNOME_DIALOG (box), 1);
+ b = gnome_dialog_run (GNOME_DIALOG (box));
+ gtk_object_destroy (GTK_OBJECT (box));
+
+ if (b != 0)
+ return;
+ }
+
calendar_save (gcal->cal, gcal->cal->filename);
- else
+ } else
save_as_calendar_cmd (widget, data);
}
@@ -650,17 +676,17 @@ parse_an_arg (poptContext ctx,
}
}
-static const struct poptOption options[] = {
- {NULL, '\0', POPT_ARG_CALLBACK, parse_an_arg, 0, NULL, NULL},
- {"events", 'e', POPT_ARG_NONE, NULL, 'e', N_("Show events and quit"),
- NULL},
- {"from", 'f', POPT_ARG_STRING, NULL, 'f', N_("Specifies start date [for --events]"), N_("DATE")},
- {"file", 'F', POPT_ARG_STRING, NULL, 'F', N_("File to load calendar from"), N_("FILE")},
- {"userfile", '\0', POPT_ARG_NONE, NULL, USERFILE_KEY, N_("Load the user calendar"), NULL},
- {"geometry", '\0', POPT_ARG_STRING, NULL, GEOMETRY_KEY, N_("Geometry for starting up"), N_("GEOMETRY")},
- {"view", '\0', POPT_ARG_STRING, NULL, VIEW_KEY, N_("The startup view mode"), N_("VIEW")},
- {"to", 't', POPT_ARG_STRING, NULL, 't', N_("Specifies ending date [for --events]"), N_("DATE")},
- {NULL, '\0', 0, NULL, 0}
+static const struct poptOption options [] = {
+ { NULL, '\0', POPT_ARG_CALLBACK, parse_an_arg, 0, NULL, NULL },
+ { "events", 'e', POPT_ARG_NONE, NULL, 'e', N_("Show events and quit"),
+ NULL },
+ { "from", 'f', POPT_ARG_STRING, NULL, 'f', N_("Specifies start date [for --events]"), N_("DATE") },
+ { "file", 'F', POPT_ARG_STRING, NULL, 'F', N_("File to load calendar from"), N_("FILE") },
+ { "userfile", '\0', POPT_ARG_NONE, NULL, USERFILE_KEY, N_("Load the user calendar"), NULL },
+ { "geometry", '\0', POPT_ARG_STRING, NULL, GEOMETRY_KEY, N_("Geometry for starting up"), N_("GEOMETRY") },
+ { "view", '\0', POPT_ARG_STRING, NULL, VIEW_KEY, N_("The startup view mode"), N_("VIEW") },
+ { "to", 't', POPT_ARG_STRING, NULL, 't', N_("Specifies ending date [for --events]"), N_("DATE") },
+ { NULL, '\0', 0, NULL, 0}
};
static void
@@ -719,14 +745,14 @@ main(int argc, char *argv[])
{
GnomeClient *client;
- bindtextdomain(PACKAGE, GNOMELOCALEDIR);
- textdomain(PACKAGE);
+ bindtextdomain (PACKAGE, GNOMELOCALEDIR);
+ textdomain (PACKAGE);
- gnome_init_with_popt_table("calendar", VERSION, argc, argv,
- options, 0, NULL);
+ gnome_init_with_popt_table ("calendar", VERSION, argc, argv,
+ options, 0, NULL);
if (show_events)
- dump_events ();
+ dump_events ();
client = gnome_master_client ();
if (client){