2 * Copyright © 2009 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21 char *aoview_file_dir;
23 #define ALTOS_DIR_PATH "/apps/aoview/log_dir"
24 #define DEFAULT_DIR "AltOS"
37 aoview_file_save_conf(void)
39 GConfClient *gconf_client;
41 gconf_client = gconf_client_get_default();
44 gconf_client_set_string(gconf_client,
48 g_object_unref(G_OBJECT(gconf_client));
53 aoview_file_configure(GtkWidget *widget, gpointer data)
55 GtkFileChooser *chooser = data;
56 aoview_file_dir = gtk_file_chooser_get_filename(chooser);
57 aoview_file_save_conf();
58 gtk_widget_hide(GTK_WIDGET(chooser));
62 aoview_file_finish(struct aoview_file *file)
74 aoview_file_name(struct aoview_file *file)
79 static GtkMessageDialog *file_fail_dialog;
82 aoview_file_open_failed(char *name)
85 utf8_file = g_filename_to_utf8(name, -1, NULL, NULL, NULL);
88 gtk_message_dialog_format_secondary_text(file_fail_dialog,
90 if (utf8_file != name)
92 gtk_widget_show(GTK_WIDGET(file_fail_dialog));
96 aoview_file_start(struct aoview_file *file)
111 full = cc_make_filename(file->serial, file->flight, file->ext);
112 file->file = fopen(full, "w");
114 aoview_file_open_failed(full);
119 setlinebuf(file->file);
126 aoview_file_vprintf(struct aoview_file *file, char *format, va_list ap)
128 if (!aoview_file_start(file))
130 vfprintf(file->file, format, ap);
134 aoview_file_printf(struct aoview_file *file, char *format, ...)
138 va_start(ap, format);
139 aoview_file_vprintf(file, format, ap);
144 aoview_file_new(char *ext)
146 struct aoview_file *file;
148 file = calloc (1, sizeof (struct aoview_file));
151 file->ext = strdup(ext);
160 aoview_file_destroy(struct aoview_file *file)
171 aoview_file_set_serial(struct aoview_file *file, int serial)
173 if (serial != file->serial)
174 aoview_file_finish(file);
175 file->serial = serial;
179 aoview_file_get_serial(struct aoview_file *file)
185 aoview_file_set_flight(struct aoview_file *file, int flight)
187 if (flight != file->flight)
188 aoview_file_finish(file);
189 file->flight = flight;
193 aoview_file_get_flight(struct aoview_file *file)
199 aoview_file_init(GladeXML *xml)
201 GConfClient *gconf_client;
202 char *file_dir = NULL;
203 GtkFileChooser *file_chooser_dialog;
204 GtkWidget *file_configure_ok;
207 gconf_client = gconf_client_get_default();
210 file_dir = gconf_client_get_string(gconf_client,
213 g_object_unref(G_OBJECT(gconf_client));
216 aoview_file_dir = aoview_fullname(getenv("HOME"), DEFAULT_DIR);
217 aoview_file_save_conf();
219 aoview_file_dir = strdup(file_dir);
222 file_chooser_dialog = GTK_FILE_CHOOSER(glade_xml_get_widget(xml, "file_chooser_dialog"));
223 assert(file_chooser_dialog);
224 gtk_file_chooser_set_filename(file_chooser_dialog, aoview_file_dir);
226 file_configure_ok = glade_xml_get_widget(xml, "file_configure_ok");
227 assert(file_configure_ok);
229 g_signal_connect(G_OBJECT(file_configure_ok), "clicked",
230 G_CALLBACK(aoview_file_configure),
231 file_chooser_dialog);
234 file_fail_dialog = GTK_MESSAGE_DIALOG(glade_xml_get_widget(xml, "file_fail_dialog"));
235 assert(file_fail_dialog);