Updated Spanish translation
[anjuta-git-plugin.git] / plugins / gtodo / export.c
blobaa5cdfc3a3019b5755cf380d6bcf8bdac7511947
1 #include <gtk/gtk.h>
2 #include <sys/stat.h>
3 #include <sys/types.h>
4 #include <gconf/gconf.h>
5 #include <gconf/gconf-client.h>
6 #include <string.h>
7 #include <libxslt/xslt.h>
8 #include <libxslt/xsltInternals.h>
9 #include <libxslt/transform.h>
10 #include <libxslt/xsltutils.h>
11 #include <gdk/gdkkeysyms.h>
12 #include "main.h"
17 static
18 void file_open(GtkWidget *button, GtkEntry *entry)
20 GtkWidget *selection = NULL;
21 selection = gtk_file_selection_new(_("Export to"));
22 gtk_file_selection_set_filename(GTK_FILE_SELECTION(selection), gtk_entry_get_text(entry));
23 switch(gtk_dialog_run(GTK_DIALOG(selection)))
25 case GTK_RESPONSE_OK:
26 gtk_entry_set_text(entry, gtk_file_selection_get_filename(GTK_FILE_SELECTION(selection)));
27 default:
28 gtk_widget_destroy(selection);
34 void export_backup_xml(void)
36 GtkWidget *dialog;
37 GtkWidget *entry;
38 GtkWidget *label;
39 GtkWidget *hbox;
40 GtkWidget *browse;
41 char *temp;
42 GError *error = NULL;
44 /* setup the dialog */
45 dialog = gtk_dialog_new_with_buttons("Export Task List",
46 GTK_WINDOW(mw.window),
47 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
48 GTK_STOCK_CANCEL,
49 GTK_RESPONSE_REJECT,
50 GTK_STOCK_OK,
51 GTK_RESPONSE_ACCEPT,
52 NULL);
53 /* the widgets in the dialog */
54 hbox = gtk_hbox_new(FALSE, 6);
55 label = gtk_label_new("Save Location:");
56 entry = gtk_entry_new();
57 temp = g_strdup_printf("%s/backup.tasks", g_getenv("HOME"));
58 gtk_entry_set_text(GTK_ENTRY(entry), temp);
59 g_free(temp);
61 browse = gtk_button_new_from_stock(GTK_STOCK_SAVE);
62 /* pack the log */
63 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, TRUE, 0);
64 gtk_box_pack_start(GTK_BOX(hbox), entry, TRUE, TRUE, 0);
65 gtk_box_pack_start(GTK_BOX(hbox), browse, FALSE, TRUE, 0);
66 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), hbox);
67 gtk_container_set_border_width(GTK_CONTAINER(hbox), 12);
69 g_signal_connect(G_OBJECT(browse), "clicked", G_CALLBACK(file_open), entry);
70 gtk_widget_show_all(dialog);
71 switch(gtk_dialog_run(GTK_DIALOG(dialog)))
73 case GTK_RESPONSE_ACCEPT:
74 g_print("saving to: %s\n", gtk_entry_get_text(GTK_ENTRY(entry)));
75 if(gtodo_client_save_xml_to_file(cl, (char *)gtk_entry_get_text(GTK_ENTRY(entry)), &error))
77 g_print("Other error\n");
79 if(error != NULL)
81 g_print("Error: %s\n", error->message);
83 default:
84 gtk_widget_destroy(dialog);
93 static
94 void cust_cb_clicked(GtkToggleButton *but, GtkWidget *entry)
96 gtk_widget_set_sensitive(entry, gtk_toggle_button_get_active(but));
99 static
100 void emb_cb_clicked(GtkToggleButton *but, GtkWidget *entry)
102 gtk_widget_set_sensitive(entry, !gtk_toggle_button_get_active(but));
106 static
107 void export_xslt()
109 GtkWidget *dialog;
110 xmlDocPtr res;
111 xsltStylesheetPtr cur;
112 GtkWidget *label, *hbox;
113 GtkWidget *loc_entry, *loc_browser;
114 GtkWidget *emb_cb, *cust_cb, *cust_browser, *cb_curcat;;
115 GtkWidget *box, *but;
116 GnomeVFSHandle *handle;
117 GnomeVFSResult result;
118 char *tmp_string;
119 xmlChar *string;
120 int length;
121 char **param_string= NULL;
123 /* setup the dialog */
124 dialog = gtk_dialog_new_with_buttons("Export to html",
125 GTK_WINDOW(mw.window),
126 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, NULL);
127 /* GTK_STOCK_CANCEL,
128 GTK_RESPONSE_REJECT,
129 GTK_STOCK_OK,
130 GTK_RESPONSE_ACCEPT,
131 NULL);
132 */ but = gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT);
133 gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_OK, GTK_RESPONSE_ACCEPT);
134 // gtk_widget_add_accelerator(but, "clicked", NULL, GDK_Escape,0 , GTK_ACCEL_VISIBLE);
135 box = gtk_vbox_new(FALSE, 6);
136 /* I can't use the vbox of the dialog, somehow it wont set a border that way */
137 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), box);
138 gtk_container_set_border_width(GTK_CONTAINER(box), 12);
140 /* the location */
141 hbox = gtk_hbox_new(FALSE, 6);
142 label = gtk_label_new("Save location:");
143 loc_entry = gtk_entry_new();
144 loc_browser = gtk_button_new_from_stock(GTK_STOCK_OPEN);
145 /* add them to the hor. box */
146 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, TRUE, 0);
147 gtk_box_pack_start(GTK_BOX(hbox), loc_entry, TRUE, TRUE, 0);
148 gtk_box_pack_start(GTK_BOX(hbox), loc_browser, FALSE, TRUE, 0);
149 /* add to vbox */
150 gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, TRUE, 0);
151 /* signals */
152 g_signal_connect(G_OBJECT(loc_browser), "clicked",G_CALLBACK(file_open), loc_entry);
153 tmp_string = g_strdup_printf("%s/output.html", g_getenv("HOME"));
154 gtk_entry_set_text(GTK_ENTRY(loc_entry), tmp_string);
155 g_free(tmp_string);
157 /* add the embed css style sheet tb */
158 emb_cb = gtk_check_button_new_with_label("Embed default (CSS) style sheet");
159 gtk_box_pack_start(GTK_BOX(box), emb_cb, FALSE, TRUE, 0);
160 /* add the custom stylesheet stuff */
161 hbox = gtk_hbox_new(FALSE, 6);
162 cust_cb = gtk_check_button_new_with_label("Custom (CSS) style sheet");
163 cust_browser = gtk_entry_new();
164 gtk_entry_set_text(GTK_ENTRY(cust_browser),"gtodo.css");
165 gtk_widget_set_sensitive(cust_browser, FALSE);
166 /* add them to the hor. box */
167 gtk_box_pack_start(GTK_BOX(hbox), cust_cb, FALSE, TRUE, 0);
168 gtk_box_pack_start(GTK_BOX(hbox), cust_browser, FALSE, TRUE, 0);
169 /* add to vbox */
170 gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, FALSE, 0);
171 g_signal_connect(G_OBJECT(cust_cb), "toggled",G_CALLBACK(cust_cb_clicked), cust_browser);
172 g_signal_connect(G_OBJECT(emb_cb), "toggled",G_CALLBACK(emb_cb_clicked), hbox);
175 /* add the embed css style sheet tb */
176 cb_curcat = gtk_check_button_new_with_label("Export current category only");
177 gtk_box_pack_start(GTK_BOX(box), cb_curcat, FALSE, TRUE, 0);
179 gtk_widget_show_all(dialog);
180 switch(gtk_dialog_run(GTK_DIALOG(dialog)))
182 case GTK_RESPONSE_ACCEPT:
183 break;
184 default:
185 gtk_widget_destroy(dialog);
186 return;
190 cur= xsltParseStylesheetFile((xmlChar *)DATADIR"/gtodo/gtodo.xsl");
191 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(emb_cb)))
193 param_string = g_realloc(param_string, 3*sizeof(gchar *));
194 param_string[0] = g_strdup("css");
195 param_string[1] = g_strdup_printf("\"embed\"");
196 param_string[2] = NULL;
198 else if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(cust_cb)))
200 param_string = g_realloc(param_string, 3*sizeof(gchar *));
201 param_string[0] = g_strdup("css");
202 param_string[1] = g_strdup_printf("\"%s\"", gtk_entry_get_text(GTK_ENTRY(cust_browser)));
203 param_string[2] = NULL;
206 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(cb_curcat)))
208 int i= 0, cat = 0;
209 for(i=0;param_string[i] != NULL;i++);
210 cat = gtk_option_menu_get_history (GTK_OPTION_MENU (mw.option));
212 if(cat != 0)
214 param_string = g_realloc(param_string, (i+3)*sizeof(gchar *));
215 param_string[i]= g_strdup("category");
216 param_string[i+1] = g_strdup_printf("\"%s\"",mw.mitems[cat-2]->date);
217 param_string[i+2] = NULL;
221 if(param_string == NULL)
223 res = xsltApplyStylesheet(cur, cl->gtodo_doc, NULL);
225 else
227 int i;
228 res = xsltApplyStylesheet(cur, cl->gtodo_doc, (const char **)param_string);
229 /* free info */
230 for(i=0; param_string[i] != NULL; i++)
232 g_free(param_string[i]);
234 g_free(param_string);
236 xsltSaveResultToString(&string,&length , res, cur);
238 result = gnome_vfs_create(&handle,
239 gtk_entry_get_text(GTK_ENTRY(loc_entry)),
240 GNOME_VFS_OPEN_WRITE,
241 0, 0644);
242 if(result == GNOME_VFS_OK)
244 gnome_vfs_write(handle,(char*)string, length, NULL);
245 xmlFree(string);
248 /* clean up some junk*/
249 xsltFreeStylesheet(cur);
250 xmlFreeDoc(res);
251 xsltCleanupGlobals();
252 gtk_widget_destroy(dialog);
255 void export_gui(void)
257 export_xslt();