127
127
g_slice_free(struct GoogleSourceActionCtxt, ctxt);
130
static gchar* google_source_edit_get_cachefile (GoogleSourcePtr gsource)
132
return common_create_cache_filename ("cache" G_DIR_SEPARATOR_S "plugins", gsource->root->id, "savedactions.xml");
136
google_source_edit_export_helper (GoogleSourceActionPtr action, xmlTextWriterPtr writer)
138
xmlTextWriterStartElement (writer, BAD_CAST "action");
140
gchar* actionType = g_strdup_printf ("%d", action->actionType);
141
xmlTextWriterWriteElement (writer, BAD_CAST "action", actionType);
144
xmlTextWriterWriteElement (writer, BAD_CAST "feedUrl", action->feedUrl);
146
xmlTextWriterWriteElement (writer, BAD_CAST "guid", action->guid);
147
xmlTextWriterEndElement (writer);
151
google_source_edit_export (GoogleSourcePtr gsource)
153
xmlTextWriterPtr writer;
154
gchar *file = google_source_edit_get_cachefile (gsource);
155
writer = xmlNewTextWriterFilename (file, 0);
158
if (writer == NULL) {
159
g_warning ("Could not create edit cache file\n");
163
xmlTextWriterStartDocument (writer, NULL, "UTF-8", NULL);
165
xmlTextWriterStartElement (writer, BAD_CAST "actions");
166
xmlTextWriterWriteAttribute (writer, BAD_CAST "version", BAD_CAST PACKAGE_VERSION);
168
while (!g_queue_is_empty(gsource->actionQueue)) {
169
GoogleSourceActionPtr action = g_queue_pop_head (gsource->actionQueue);
170
google_source_edit_export_helper (action, writer);
173
xmlTextWriterEndElement (writer);
174
xmlTextWriterEndDocument (writer);
175
xmlFreeTextWriter (writer);
179
google_source_edit_import_helper (xmlNodePtr match, gpointer userdata)
181
GoogleSourcePtr gsource = (GoogleSourcePtr) userdata ;
182
GoogleSourceActionPtr action;
185
action = google_source_action_new () ;
187
cur = match->children ;
189
xmlChar *content = xmlNodeGetContent (cur);
190
if (g_str_equal ((gchar*) cur->name, "action")) {
191
action->actionType = atoi (content) ;
192
} else if (g_str_equal ((gchar*) cur->name, "guid")){
193
action->guid = g_strdup ((gchar*) content);
194
} else if (g_str_equal ((gchar*) cur->name, "feedUrl")) {
195
action->feedUrl = g_strdup ((gchar*) content);
197
if (content) xmlFree (content);
201
debug3 (DEBUG_CACHE, "Found edit request: %d %s %s \n", action->actionType, action->feedUrl, action->guid);
202
google_source_edit_push (gsource, action, FALSE);
206
google_source_edit_import (GoogleSourcePtr gsource)
208
gchar* file = google_source_edit_get_cachefile (gsource);
210
if (!g_file_test(file, G_FILE_TEST_IS_REGULAR)) {
211
debug0 (DEBUG_UPDATE, "GoogleSource: saved actions file not found.");
216
xmlDocPtr doc = xmlReadFile (file, NULL, 0);
222
xmlNodePtr root = xmlDocGetRootElement (doc);
224
xpath_foreach_match (root, "/actions/action", google_source_edit_import_helper, gsource);
232
131
google_source_edit_action_complete (const struct updateResult* const result, gpointer userdata, updateFlags flags)