]> www.infradead.org Git - users/dwmw2/ews-sync.git/commitdiff
Write combined all.ics file on completion
authorDavid Woodhouse <dwmw2@infradead.org>
Thu, 22 Jul 2010 16:31:17 +0000 (17:31 +0100)
committerDavid Woodhouse <dwmw2@infradead.org>
Thu, 22 Jul 2010 16:31:17 +0000 (17:31 +0100)
ews_syncfolder.c

index b359ecce29fc0afd862e412cc0112d8f28a3dc7a..4df4f9a4e3c2afc8c4232975c966d7b259013ec2 100644 (file)
@@ -22,6 +22,8 @@ struct item_change {
        char itemid[0];
 };
 
+void combine_ical_files(void);
+
 int process_changes(xmlNode *node, struct item_change **changes);
 icalcomponent *fetch_xml_item(SoupSession *sess, char *url, const char *itemid,
                              const char *xml_filename, const char *parent_id,
@@ -271,6 +273,8 @@ int main(int argc, char **argv)
        }
        g_free(syncstate);
        g_free(statefilename);
+
+       combine_ical_files();
        return 0;
 }
 
@@ -472,3 +476,48 @@ int process_changes(xmlNode *node, struct item_change **changes)
        }
        return 0;
 }
+
+void combine_ical_files(void)
+{
+       icalcomponent *merged, *this;
+       const gchar *name;
+       gchar *dirname;
+       gchar *filename;
+       gchar *contents;
+       GDir *d;
+
+       merged = icalcomponent_new_vcalendar();
+
+       dirname = g_build_filename (g_get_home_dir() , "ews-sync", NULL);
+
+       d = g_dir_open (dirname, 0, NULL);
+       if (!d)
+               return;
+
+       while ((name = g_dir_read_name(d))) {
+               if (!strcmp(name, "all.ics"))
+                       continue;
+               if (strlen(name) < 4)
+                       continue;
+               if (strcmp(name + strlen(name) - 4, ".ics"))
+                       continue;
+
+               filename = g_build_filename(dirname, name, NULL);
+               if (!g_file_get_contents(filename, &contents, NULL, NULL))
+                       continue;
+
+               this = icalcomponent_new_from_string(contents);
+               if (!this)
+                       continue;
+               
+               icalcomponent_merge_component(merged, this);
+               g_free(contents);
+       }
+       filename = g_build_filename(dirname, "all.ics", NULL);
+       contents = icalcomponent_as_ical_string_r(merged);
+
+       g_file_set_contents(filename, contents, strlen(contents), NULL);
+       printf("Write all.ics file\n");
+       g_free(contents);
+       icalcomponent_free(merged);
+}