1 #include <string.h>
2 #include <stdlib.h>
3 #include "urlgfe.h"
4 #include "utility.h"
5 #include "category_setting.h"
6
category_setting_init(CategorySetting * cd)7 CategorySetting* category_setting_init (CategorySetting* cd)
8 {
9 download_setting_init(&cd->download);
10
11 cd->download.multiple = 1; // TRUE
12 cd->multiple = 0; // FALSE
13 cd->name = NULL;
14 cd->state = CATEGORY_STATE_WAITING;
15 cd->n_active_download = 1;
16 cd->completed_capacity = 1000;
17 cd->recycled_capacity = 1000;
18
19 // column visible
20 cd->col_completed = 1;
21 cd->col_total = 1;
22 cd->col_speed = 1;
23 cd->col_retry = 1;
24 cd->col_url = 1;
25
26 // text
27 cd->text_filename = 1;
28 cd->text_directory = 1;
29 cd->text_url = 1;
30 cd->text_start_mode = 1;
31 cd->text_message = 1;
32
33 return cd;
34 }
35
category_setting_clear(CategorySetting * cd)36 void category_setting_clear(CategorySetting* cd)
37 {
38 g_free (cd->name);
39 download_setting_clear (&cd->download);
40 }
41
category_setting_destroy(CategorySetting * cd)42 void category_setting_destroy (CategorySetting* cd)
43 {
44 category_setting_clear (cd);
45 g_free (cd);
46 }
47
category_setting_assign(CategorySetting * cd,CategorySetting * src)48 void category_setting_assign (CategorySetting* cd, CategorySetting* src)
49 {
50 download_setting_assign (&cd->download, &src->download);
51
52 if (cd->multiple==0 && src->multiple==0)
53 category_setting_set_name (cd, src->name);
54 cd->state = src->state;
55 cd->n_active_download = src->n_active_download;
56 cd->completed_capacity = src->completed_capacity;
57 cd->recycled_capacity = src->recycled_capacity;
58
59 cd->col_completed = src->col_completed;
60 cd->col_total = src->col_total;
61 cd->col_speed = src->col_speed;
62 cd->col_retry = src->col_retry;
63 cd->col_url = src->col_url;
64
65 cd->text_filename = src->text_filename;
66 cd->text_directory = src->text_directory;
67 cd->text_url = src->text_url;
68 cd->text_start_mode = src->text_start_mode;
69 cd->text_message = src->text_message;
70 }
71
category_setting_write_xml(CategorySetting * setting,FILE * file,int level)72 void category_setting_write_xml (CategorySetting* setting,
73 FILE* file, int level)
74 {
75 gchar* name;
76 guint state = setting->state;
77
78 if (state == CATEGORY_STATE_EXECUTING)
79 state = DOWNLOAD_STATE_WAITING;
80
81 name = str_to_xml_str (STR_N2E (setting->name));
82
83 fprintf (file,
84 "%*c<" CATEGORY_SETTING_TAG " " // Start of format string
85 "name=\"%s\" "
86 "state=\"%d\" "
87 "multiple=\"%d\" "
88 "n_active_download=\"%d\" "
89 "completed_capacity=\"%d\" "
90 "recycled_capacity=\"%d\" "
91 "col_completed=\"%d\" "
92 "col_total=\"%d\" "
93 "col_speed=\"%d\" "
94 "col_retry=\"%d\" "
95 "col_url=\"%d\" "
96 "text_filename=\"%d\" "
97 "text_directory=\"%d\" "
98 "text_url=\"%d\" "
99 "text_start_mode=\"%d\" "
100 "text_message=\"%d\">\n", // End of format string
101 level, ' ',
102 name,
103 state,
104 setting->multiple,
105 setting->n_active_download,
106 setting->completed_capacity,
107 setting->recycled_capacity,
108 setting->col_completed,
109 setting->col_total,
110 setting->col_speed,
111 setting->col_retry,
112 setting->col_url,
113 setting->text_filename,
114 setting->text_directory,
115 setting->text_url,
116 setting->text_start_mode,
117 setting->text_message
118 );
119 /*
120 fprintf (file, "%*c<column name=\"completed\" visible=\"%d\">\n",
121 level+1, ' ', setting->col_completed);
122 fprintf (file, "%*c<column name=\"total\" visible=\"%d\">\n",
123 level+1, ' ', setting->col_total);
124 fprintf (file, "%*c<column name=\"speed\" visible=\"%d\">\n",
125 level+1, ' ', setting->col_speed);
126 */
127 download_setting_write_xml (DOWNLOAD_SETTING (setting), file, level+1);
128 fprintf (file, "%*c</" CATEGORY_SETTING_TAG ">\n", level, ' ');
129
130 g_free (name);
131 }
132
133