summaryrefslogtreecommitdiff
blob: 53dab52405bf9bd7b4538280b46cbc4c53bd09cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
Index: src/dates_callbacks.c
===================================================================
--- src/dates_callbacks.c	(revision 355)
+++ src/dates_callbacks.c	(working copy)
@@ -21,6 +21,10 @@
 
 #include <gdk/gdkkeysyms.h>
 #include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <stdio.h>
 
 #include <libecal/e-cal-time-util.h>
 #include <libical/icaltime.h>
@@ -627,6 +631,7 @@ dates_ical_drop_cb (DatesView *view, con
     icalcomponent *icalcomp, *icalcomp2;
     gint events;
 
+	g_warning("DFG d: %p", d);
     if (!d->cal_loaded) {
 	/* TODO: Toggle the default calendar here maybe? */
 	g_warning ("No calendars selected to add new event to");
@@ -673,6 +678,44 @@ dates_ical_drop_cb (DatesView *view, con
     icalcomponent_free (icalcomp);
 }
 
+gboolean
+dates_ical_option_cb (void *userdata)
+{
+	FILE *f;
+	struct stat st;
+	gchar *ical;
+	size_t size;
+	struct ical_open *open = userdata;
+
+	if (stat(open->ical_file, &st)) {
+		g_error ("Could not stat ical file %s", open->ical_file);
+		return (FALSE);
+	}
+
+	ical = g_malloc0(st.st_size + 1);
+	if (!ical) {
+		g_error ("Could not allocate buffer for ical file (%z)", st.st_size + 1);
+		return (FALSE);
+	}
+
+	f = fopen(open->ical_file, "r");
+	if (!f) {
+		g_error ("Could not open ical file %s for importing", open->ical_file);
+		return (FALSE);
+	}
+
+	size = fread(ical, sizeof(char), st.st_size, f);
+	if (size != st.st_size) {
+		g_error ("Error importing ical file: Not enough read: got %z expected %u", size, st.st_size);
+		return (FALSE);
+	}
+
+	g_warning("ical: %s", ical);
+	dates_ical_drop_cb(open->data->view, ical, open->data);
+	g_free(ical);
+	return (FALSE);
+}
+
 void
 dates_details_time_entry_changed (GtkEditable *entry, gchar *new_text,
 				  gint new_text_length,
Index: src/dates_main.c
===================================================================
--- src/dates_main.c	(revision 355)
+++ src/dates_main.c	(working copy)
@@ -325,6 +325,7 @@ main (int argc, char **argv)
 	GConfBridge *bridge;
 	GOptionContext *context;
 	static gint plug = 0;
+	static gchar *ical = NULL;
 #ifdef DEBUG
 	const gchar *debug;
 #endif
@@ -332,6 +333,8 @@ main (int argc, char **argv)
 	static GOptionEntry entries[] = {
 		{ "plug", 'p', 0, G_OPTION_ARG_INT, &plug,
 			"Socket ID of an XEmbed socket to plug into", NULL },
+		{ "ical", 'i', 0, G_OPTION_ARG_STRING, &ical,
+			"ICal file to import", NULL },
 		{ NULL }
 	};
 
@@ -501,6 +504,26 @@ main (int argc, char **argv)
 		gtk_widget_show (data.main_window);
 	}
 
+	if (ical) {
+		struct ical_open *open = g_malloc0(sizeof(struct ical_open));
+		if (!open) {
+			g_error ("Failed to malloc ical_open!");
+			exit(1);
+		}
+		open->ical_file = g_strdup(ical);
+		if (!open->ical_file) {
+			g_error ("Failed to malloc ical_open!");
+			g_free(open);
+			exit(1);
+		}
+		open->data = &data;
+
+#ifdef DEBUG
+		g_debug ("Loading ical file %s", open->ical_file);
+#endif
+		g_idle_add (dates_ical_option_cb, open);
+	}
+
 	gtk_main ();
 
 	/* clean up */
Index: src/dates_callbacks.h
===================================================================
--- src/dates_callbacks.h	(revision 355)
+++ src/dates_callbacks.h	(working copy)
@@ -65,6 +65,9 @@ dates_event_sized_cb (DatesView *view, E
 void
 dates_ical_drop_cb (DatesView *view, const gchar *ical, DatesData *d);
 
+gboolean
+dates_ical_option_cb (void *userdata);
+
 void
 dates_details_time_entry_changed (GtkEditable *entry, gchar *new_text,
 				  gint new_text_length,
Index: src/dates_types.h
===================================================================
--- src/dates_types.h	(revision 355)
+++ src/dates_types.h	(working copy)
@@ -155,5 +155,11 @@ typedef struct {
 #endif
 } DatesData;
 
+/* Hack for open of ical */
+struct ical_open {
+	DatesData *data;
+	gchar *ical_file;
+};
+
 
 #endif /* DATES_TYPES_H */