1 #include "category_store.h"
2 
download_store_write_xml(DownloadStore * store,FILE * file,int level)3 void download_store_write_xml (DownloadStore* store,
4                                FILE* file, int level)
5 {
6 	DownloadSetting* ds;
7 	GtkTreeIter iter;
8 	gboolean valid;
9 
10 	download_store_lock (store);
11 
12 	valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store->list_store),
13 	                                       &iter);
14 	while (valid) {
15 		gtk_tree_model_get (GTK_TREE_MODEL (store->list_store), &iter,
16 		                    DOWNLOAD_COL_DATA, &ds, -1);
17 
18 		download_setting_write_xml (ds, file, level+1);
19 
20 		valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (store->list_store),
21 		                                  &iter);
22 	}
23 
24 	download_store_unlock (store);
25 }
26 
category_write_xml(Category * category,FILE * file,int level)27 void category_write_xml (Category* category,
28                          FILE* file, int level)
29 {
30 
31 	if (level)
32 		fprintf (file, "%*c", level, ' ');
33 	fputs ("<" CATEGORY_TAG ">\n", file);
34 
35 	category_setting_write_xml (CATEGORY_SETTING (category), file, level+1);
36 
37 	// waiting store
38 	fprintf (file,
39 	         "%*c"
40 	         "<" CATEGORY_WAITING_STORE_TAG ">\n",
41 	         level+1, ' ');
42 	download_store_write_xml (&category->waiting_store, file, level+1);
43 	fprintf (file,
44 	         "%*c"
45 	         "</" CATEGORY_WAITING_STORE_TAG ">\n",
46 	         level+1, ' ');
47 
48 	// completed store
49 	fprintf (file,
50 	         "%*c"
51 	         "<" CATEGORY_COMPLETED_STORE_TAG ">\n",
52 	         level+1, ' ');
53 	download_store_write_xml (&category->completed_store, file, level+1);
54 	fprintf (file,
55 	         "%*c"
56 	         "</" CATEGORY_COMPLETED_STORE_TAG ">\n",
57 	         level+1, ' ');
58 
59 	// recycled store
60 	fprintf (file,
61 	         "%*c"
62 	         "<" CATEGORY_RECYCLED_STORE_TAG ">\n",
63 	         level+1, ' ');
64 	download_store_write_xml (&category->recycled_store, file, level+1);
65 	fprintf (file,
66 	         "%*c"
67 	         "</" CATEGORY_RECYCLED_STORE_TAG ">\n",
68 	         level+1, ' ');
69 
70 	if (level)
71 		fprintf (file, "%*c", level, ' ');
72 	fputs ("</" CATEGORY_TAG ">\n", file);
73 }
74 
category_store_write_xml(CategoryStore * store,FILE * file,int level)75 void category_store_write_xml (CategoryStore* store,
76                                FILE* file, int level)
77 {
78 	Category* cate;
79 	GtkTreeIter iter;
80 	gboolean valid;
81 
82 	if (level)
83 		fprintf (file, "%*c", level, ' ');
84 	fputs ("<" CATEGORY_STORE_TAG ">\n", file);
85 
86 	valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store->list_store),
87 	                                       &iter);
88 
89 	while (valid) {
90 		gtk_tree_model_get (GTK_TREE_MODEL (store->list_store), &iter,
91 		                    CATEGORY_COL_DATA, &cate, -1);
92 
93 		category_write_xml (cate, file, level+1);
94 
95 		valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (store->list_store),
96 		                                  &iter);
97 	}
98 
99 	if (level)
100 		fprintf (file, "%*c", level, ' ');
101 	fputs ("</" CATEGORY_STORE_TAG ">\n", file);
102 }
103 
104