Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
Radio Telescope Control
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Armin Luntzer
Radio Telescope Control
Commits
2c7a89d9
Commit
2c7a89d9
authored
Jul 4, 2019
by
Armin Luntzer
Browse files
Options
Downloads
Patches
Plain Diff
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
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/client/widgets/xyplot/xyplot.c
+83
-10
83 additions, 10 deletions
src/client/widgets/xyplot/xyplot.c
with
83 additions
and
10 deletions
src/client/widgets/xyplot/xyplot.c
+
83
−
10
View file @
2c7a89d9
...
@@ -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
));
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment