Skip to content
Snippets Groups Projects
Commit 2c7a89d9 authored by Armin Luntzer's avatar Armin Luntzer
Browse files

XYPlot: * add dialog feedback if file cannot be opened

	* set default path to Documents directory
parent 4f5697d0
No related branches found
No related tags found
No related merge requests found
...@@ -272,10 +272,12 @@ static void xyplot_export_pdf(GtkWidget *w, XYPlot *p) ...@@ -272,10 +272,12 @@ static void xyplot_export_pdf(GtkWidget *w, XYPlot *p)
chooser = GTK_FILE_CHOOSER(dia); chooser = GTK_FILE_CHOOSER(dia);
gtk_file_chooser_set_do_overwrite_confirmation(chooser, TRUE); gtk_file_chooser_set_do_overwrite_confirmation(chooser, TRUE);
gtk_file_chooser_set_current_name(chooser, "plot.pdf"); gtk_file_chooser_set_current_name(chooser, "plot.pdf");
gtk_file_chooser_set_current_folder(chooser,g_get_user_special_dir(G_USER_DIRECTORY_DOCUMENTS));
res = gtk_dialog_run(GTK_DIALOG(dia)); res = gtk_dialog_run(GTK_DIALOG(dia));
...@@ -285,6 +287,24 @@ static void xyplot_export_pdf(GtkWidget *w, XYPlot *p) ...@@ -285,6 +287,24 @@ static void xyplot_export_pdf(GtkWidget *w, XYPlot *p)
fname = gtk_file_chooser_get_filename(chooser); fname = gtk_file_chooser_get_filename(chooser);
cs = cairo_pdf_surface_create(fname, 1280, 720); cs = cairo_pdf_surface_create(fname, 1280, 720);
if (cairo_surface_status(cs) != CAIRO_STATUS_SUCCESS) {
GtkWidget *d;
d = gtk_message_dialog_new(GTK_WINDOW(win),
GTK_DIALOG_MODAL,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE,
"Could not open file %s",
fname);
gtk_dialog_run(GTK_DIALOG(d));
gtk_widget_destroy(d);
}
cr = cairo_create(cs); cr = cairo_create(cs);
xyplot_plot_render(p, cr, 1280, 720); xyplot_plot_render(p, cr, 1280, 720);
...@@ -323,7 +343,21 @@ static void xyplot_import_graph_xy_asc(const gchar *fname, XYPlot *p) ...@@ -323,7 +343,21 @@ static void xyplot_import_graph_xy_asc(const gchar *fname, XYPlot *p)
f = g_fopen(fname, "r"); f = g_fopen(fname, "r");
if (!f) { if (!f) {
g_warning("%s: error opening file %s", __func__, fname);
GtkWidget *dia;
GtkWindow * win;
win = GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(p)));
dia = gtk_message_dialog_new(win,
GTK_DIALOG_MODAL,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE,
"Could not open file %s",
fname);
gtk_dialog_run(GTK_DIALOG(dia));
gtk_widget_destroy(dia);
return; return;
} }
...@@ -419,7 +453,7 @@ static void xyplot_import_graph_xy_asc(const gchar *fname, XYPlot *p) ...@@ -419,7 +453,7 @@ static void xyplot_import_graph_xy_asc(const gchar *fname, XYPlot *p)
g_array_free(gc, FALSE); g_array_free(gc, FALSE);
} }
static void xyplot_export_graph_xy_asc(const gchar *fname, struct graph *g, static gboolean xyplot_export_graph_xy_asc(const gchar *fname, struct graph *g,
const gchar *mode) const gchar *mode)
{ {
FILE *f; FILE *f;
...@@ -429,10 +463,9 @@ static void xyplot_export_graph_xy_asc(const gchar *fname, struct graph *g, ...@@ -429,10 +463,9 @@ static void xyplot_export_graph_xy_asc(const gchar *fname, struct graph *g,
f = g_fopen(fname, mode); f = g_fopen(fname, mode);
if (!f) { if (!f)
g_message("%s: error opening file %s", __func__, fname); return FALSE;
return;
}
setlocale(LC_ALL, "C"); setlocale(LC_ALL, "C");
...@@ -463,6 +496,8 @@ static void xyplot_export_graph_xy_asc(const gchar *fname, struct graph *g, ...@@ -463,6 +496,8 @@ static void xyplot_export_graph_xy_asc(const gchar *fname, struct graph *g,
setlocale(LC_ALL, ""); setlocale(LC_ALL, "");
fclose(f); fclose(f);
return TRUE;
} }
...@@ -506,6 +541,7 @@ static void xyplot_export_xy_graph_cb(GtkWidget *w, struct graph *g) ...@@ -506,6 +541,7 @@ static void xyplot_export_xy_graph_cb(GtkWidget *w, struct graph *g)
gtk_file_chooser_set_current_name(chooser, fname); gtk_file_chooser_set_current_name(chooser, fname);
gtk_file_chooser_set_current_folder(chooser,g_get_user_special_dir(G_USER_DIRECTORY_DOCUMENTS));
res = gtk_dialog_run(GTK_DIALOG(dia)); res = gtk_dialog_run(GTK_DIALOG(dia));
...@@ -516,7 +552,20 @@ static void xyplot_export_xy_graph_cb(GtkWidget *w, struct graph *g) ...@@ -516,7 +552,20 @@ static void xyplot_export_xy_graph_cb(GtkWidget *w, struct graph *g)
fname = gtk_file_chooser_get_filename(chooser); fname = gtk_file_chooser_get_filename(chooser);
xyplot_export_graph_xy_asc(fname, g, "w"); if (!xyplot_export_graph_xy_asc(fname, g, "w")) {
GtkWidget *d;
d = gtk_message_dialog_new(GTK_WINDOW(win),
GTK_DIALOG_MODAL,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE,
"Could not open file %s",
fname);
gtk_dialog_run(GTK_DIALOG(d));
gtk_widget_destroy(d);
}
g_free(fname); g_free(fname);
} }
...@@ -535,6 +584,8 @@ static void xyplot_export_xy_plot_cb(GtkWidget *w, XYPlot *p) ...@@ -535,6 +584,8 @@ static void xyplot_export_xy_plot_cb(GtkWidget *w, XYPlot *p)
GtkWidget *win; GtkWidget *win;
FILE *f;
gchar *fname; gchar *fname;
GList *elem; GList *elem;
...@@ -567,6 +618,7 @@ static void xyplot_export_xy_plot_cb(GtkWidget *w, XYPlot *p) ...@@ -567,6 +618,7 @@ static void xyplot_export_xy_plot_cb(GtkWidget *w, XYPlot *p)
gtk_file_chooser_set_current_name(chooser, fname); gtk_file_chooser_set_current_name(chooser, fname);
gtk_file_chooser_set_current_folder(chooser,g_get_user_special_dir(G_USER_DIRECTORY_DOCUMENTS));
res = gtk_dialog_run(GTK_DIALOG(dia)); res = gtk_dialog_run(GTK_DIALOG(dia));
...@@ -577,11 +629,30 @@ static void xyplot_export_xy_plot_cb(GtkWidget *w, XYPlot *p) ...@@ -577,11 +629,30 @@ static void xyplot_export_xy_plot_cb(GtkWidget *w, XYPlot *p)
fname = gtk_file_chooser_get_filename(chooser); fname = gtk_file_chooser_get_filename(chooser);
/* clear file */ /* clear file */
fclose(g_fopen(fname, "w")); f = g_fopen(fname, "w");
if (!f) {
GtkWidget *d;
d = gtk_message_dialog_new(GTK_WINDOW(win),
GTK_DIALOG_MODAL,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE,
"Could not open file %s",
fname);
gtk_dialog_run(GTK_DIALOG(d));
gtk_widget_destroy(d);
} else {
fclose(f);
}
for (elem = p->graphs; elem; elem = elem->next) { for (elem = p->graphs; elem; elem = elem->next) {
g = (struct graph *) elem->data; g = (struct graph *) elem->data;
xyplot_export_graph_xy_asc(fname, g, "a");
if (!xyplot_export_graph_xy_asc(fname, g, "a"))
break;
} }
g_free(fname); g_free(fname);
...@@ -621,6 +692,8 @@ static void xyplot_import_xy_graph_cb(GtkWidget *w, XYPlot *p) ...@@ -621,6 +692,8 @@ static void xyplot_import_xy_graph_cb(GtkWidget *w, XYPlot *p)
chooser = GTK_FILE_CHOOSER(dia); chooser = GTK_FILE_CHOOSER(dia);
gtk_file_chooser_set_current_folder(chooser,g_get_user_special_dir(G_USER_DIRECTORY_DOCUMENTS));
res = gtk_dialog_run(GTK_DIALOG(dia)); res = gtk_dialog_run(GTK_DIALOG(dia));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment