Merge branch 'windows' of https://github.com/bvanassche/fio
[fio.git] / gerror.c
CommitLineData
41666588 1#include <locale.h>
2ef39e09 2#include <stdlib.h>
41666588
JA
3#include <string.h>
4#include <stdarg.h>
5
6#include <gtk/gtk.h>
7
8#include "gfio.h"
9#include "gerror.h"
10
11static void on_info_bar_response(GtkWidget *widget, gint response,
3c3ed070 12 gpointer data)
41666588
JA
13{
14 struct gui *ui = (struct gui *) data;
15
16 if (response == GTK_RESPONSE_OK) {
17 gtk_widget_destroy(widget);
18 ui->error_info_bar = NULL;
19 }
20}
21
22static void report_error(struct gui_entry *ge, GError *error)
23{
24 struct gui *ui = ge->ui;
25
26 if (ui->error_info_bar == NULL) {
cab2440c
JA
27 GtkWidget *container;
28
41666588 29 ui->error_info_bar = gtk_info_bar_new_with_buttons(GTK_STOCK_OK,
3c3ed070 30 GTK_RESPONSE_OK, NULL);
41666588
JA
31 g_signal_connect(ui->error_info_bar, "response", G_CALLBACK(on_info_bar_response), ui);
32 gtk_info_bar_set_message_type(GTK_INFO_BAR(ui->error_info_bar),
3c3ed070
JA
33 GTK_MESSAGE_ERROR);
34
41666588 35 ui->error_label = gtk_label_new(error->message);
cab2440c 36 container = gtk_info_bar_get_content_area(GTK_INFO_BAR(ui->error_info_bar));
41666588 37 gtk_container_add(GTK_CONTAINER(container), ui->error_label);
3c3ed070 38
41666588
JA
39 gtk_box_pack_start(GTK_BOX(ui->vbox), ui->error_info_bar, FALSE, FALSE, 0);
40 gtk_widget_show_all(ui->vbox);
41 } else {
42 char buffer[256];
43 snprintf(buffer, sizeof(buffer), "Failed to open file.");
f762cef9 44 gtk_label_set_text(GTK_LABEL(ui->error_label), buffer);
41666588
JA
45 }
46}
47
48void gfio_report_error(struct gui_entry *ge, const char *format, ...)
49{
50 va_list args;
51 GError *error;
52
53 va_start(args, format);
54 error = g_error_new_valist(g_quark_from_string("fio"), 1, format, args);
55 va_end(args);
56
57 report_error(ge, error);
58 g_error_free(error);
59}
60
1252d8f2
JA
61void gfio_report_info(struct gui *ui, const char *title, const char *message)
62{
63 GtkWidget *dialog, *content, *label;
64
65 dialog = gtk_dialog_new_with_buttons(title, GTK_WINDOW(ui->window),
66 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
67 GTK_STOCK_OK, GTK_RESPONSE_OK, NULL);
41666588 68
1252d8f2
JA
69 content = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
70 label = gtk_label_new(message);
71 gtk_container_add(GTK_CONTAINER(content), label);
72 gtk_widget_show_all(dialog);
73 gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
74 gtk_dialog_run(GTK_DIALOG(dialog));
75 gtk_widget_destroy(dialog);
76}