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; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20 static char *aoview_file_dir;
22 #define ALTOS_DIR_PATH "/apps/aoview/log_dir"
23 #define DEFAULT_DIR "AltOS"
35 aoview_file_save_conf(void)
37 GConfClient *gconf_client;
39 gconf_client = gconf_client_get_default();
42 gconf_client_set_string(gconf_client,
46 g_object_unref(G_OBJECT(gconf_client));
51 aoview_file_configure(GtkWidget *widget, gpointer data)
53 GtkFileChooser *chooser = data;
54 aoview_file_dir = gtk_file_chooser_get_filename(chooser);
55 aoview_file_save_conf();
56 gtk_widget_hide(GTK_WIDGET(chooser));
60 aoview_file_finish(struct aoview_file *file)
71 static GtkMessageDialog *file_fail_dialog;
74 aoview_file_open_failed(char *name)
77 utf8_file = g_filename_to_utf8(name, -1, NULL, NULL, NULL);
80 gtk_message_dialog_format_secondary_text(file_fail_dialog,
82 if (utf8_file != name)
84 gtk_widget_show(GTK_WIDGET(file_fail_dialog));
88 aoview_file_start(struct aoview_file *file)
103 (void) localtime_r(&now, &tm);
104 aoview_mkdir(aoview_file_dir);
106 snprintf(base, sizeof (base), "%04d-%02d-%02d-serial-%03d-flight-%03d.%s",
113 full = aoview_fullname(aoview_file_dir, base);
114 r = access(full, F_OK);
116 file->file = fopen(full, "w");
118 aoview_file_open_failed(full);
123 setlinebuf(file->file);
134 aoview_file_vprintf(struct aoview_file *file, char *format, va_list ap)
136 if (!aoview_file_start(file))
138 vfprintf(file->file, format, ap);
142 aoview_file_printf(struct aoview_file *file, char *format, ...)
146 va_start(ap, format);
147 aoview_file_vprintf(file, format, ap);
152 aoview_file_new(char *ext)
154 struct aoview_file *file;
156 file = calloc (1, sizeof (struct aoview_file));
159 file->ext = strdup(ext);
168 aoview_file_destroy(struct aoview_file *file)
179 aoview_file_set_serial(struct aoview_file *file, int serial)
181 if (serial != file->serial)
182 aoview_file_finish(file);
183 file->serial = serial;
187 aoview_file_get_serial(struct aoview_file *file)
193 aoview_file_init(GladeXML *xml)
195 GConfClient *gconf_client;
196 char *file_dir = NULL;
197 GtkFileChooser *file_chooser_dialog;
198 GtkWidget *file_configure_ok;
201 gconf_client = gconf_client_get_default();
204 file_dir = gconf_client_get_string(gconf_client,
207 g_object_unref(G_OBJECT(gconf_client));
210 aoview_file_dir = aoview_fullname(getenv("HOME"), DEFAULT_DIR);
211 aoview_file_save_conf();
213 aoview_file_dir = strdup(file_dir);
216 file_chooser_dialog = GTK_FILE_CHOOSER(glade_xml_get_widget(xml, "file_chooser_dialog"));
217 assert(file_chooser_dialog);
218 gtk_file_chooser_set_filename(file_chooser_dialog, aoview_file_dir);
220 file_configure_ok = glade_xml_get_widget(xml, "file_configure_ok");
221 assert(file_configure_ok);
223 g_signal_connect(G_OBJECT(file_configure_ok), "clicked",
224 G_CALLBACK(aoview_file_configure),
225 file_chooser_dialog);
228 file_fail_dialog = GTK_MESSAGE_DIALOG(glade_xml_get_widget(xml, "file_fail_dialog"));
229 assert(file_fail_dialog);