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 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)
72 aoview_file_name(struct aoview_file *file)
77 static GtkMessageDialog *file_fail_dialog;
80 aoview_file_open_failed(char *name)
83 utf8_file = g_filename_to_utf8(name, -1, NULL, NULL, NULL);
86 gtk_message_dialog_format_secondary_text(file_fail_dialog,
88 if (utf8_file != name)
90 gtk_widget_show(GTK_WIDGET(file_fail_dialog));
94 aoview_file_start(struct aoview_file *file)
109 (void) localtime_r(&now, &tm);
110 aoview_mkdir(aoview_file_dir);
112 snprintf(base, sizeof (base), "%04d-%02d-%02d-serial-%03d-flight-%03d.%s",
119 full = aoview_fullname(aoview_file_dir, base);
120 r = access(full, F_OK);
122 file->file = fopen(full, "w");
124 aoview_file_open_failed(full);
129 setlinebuf(file->file);
140 aoview_file_vprintf(struct aoview_file *file, char *format, va_list ap)
142 if (!aoview_file_start(file))
144 vfprintf(file->file, format, ap);
148 aoview_file_printf(struct aoview_file *file, char *format, ...)
152 va_start(ap, format);
153 aoview_file_vprintf(file, format, ap);
158 aoview_file_new(char *ext)
160 struct aoview_file *file;
162 file = calloc (1, sizeof (struct aoview_file));
165 file->ext = strdup(ext);
174 aoview_file_destroy(struct aoview_file *file)
185 aoview_file_set_serial(struct aoview_file *file, int serial)
187 if (serial != file->serial)
188 aoview_file_finish(file);
189 file->serial = serial;
193 aoview_file_get_serial(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);