Discussion:
[LIBREPORT PATCH] show warning if the network is not available - rhbz#876849
Jiri Moskovcak
2013-08-30 11:23:05 UTC
Permalink
Signed-off-by: Jiri Moskovcak <jmoskovc-H+wXaHxf7aLQT0dZR+***@public.gmane.org>
---
src/gtk-helpers/Makefile.am | 3 ++-
src/gtk-helpers/internal_libreport_gtk.h | 3 +++
src/gtk-helpers/network_monitor.c | 32 ++++++++++++++++++++++++++++++++
src/gui-wizard-gtk/wizard.c | 24 +++++++++++++++++++++++-
4 files changed, 60 insertions(+), 2 deletions(-)
create mode 100644 src/gtk-helpers/network_monitor.c

diff --git a/src/gtk-helpers/Makefile.am b/src/gtk-helpers/Makefile.am
index b67186f..7c66d1f 100644
--- a/src/gtk-helpers/Makefile.am
+++ b/src/gtk-helpers/Makefile.am
@@ -15,7 +15,8 @@ libreport_gtk_la_SOURCES = \
autowrapped_label.c \
workflow_config_dialog.c \
config_dialog.c \
- ask_dialogs.c
+ ask_dialogs.c \
+ network_monitor.c

libreport_gtk_la_CPPFLAGS = \
-I$(srcdir)/../include \
diff --git a/src/gtk-helpers/internal_libreport_gtk.h b/src/gtk-helpers/internal_libreport_gtk.h
index dc1ef31..fbd49b0 100644
--- a/src/gtk-helpers/internal_libreport_gtk.h
+++ b/src/gtk-helpers/internal_libreport_gtk.h
@@ -136,6 +136,9 @@ int run_ask_yes_no_yesforever_dialog(const char *key, const char *message, GtkWi
#define run_ask_yes_no_save_result_dialog libreport_run_ask_yes_no_save_result_dialog
int run_ask_yes_no_save_result_dialog(const char *key, const char *message, GtkWindow *parent);

+#define is_network_available libreport_is_network_available
+bool is_network_available();
+
#ifdef __cplusplus
}
#endif
diff --git a/src/gtk-helpers/network_monitor.c b/src/gtk-helpers/network_monitor.c
new file mode 100644
index 0000000..193f7dc
--- /dev/null
+++ b/src/gtk-helpers/network_monitor.c
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2012 ABRT Team
+ * Copyright (C) 2012 RedHat inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <internal_libreport_gtk.h>
+
+static void on_network_change_wrap(GNetworkMonitor *g, gboolean available, void(*on_change_cb)(gboolean available))
+{
+ on_change_cb(available);
+}
+
+bool is_network_available(void(*on_change_cb)(gboolean available))
+{
+ GNetworkMonitor* net_monitor = g_network_monitor_get_default();
+ g_signal_connect(G_OBJECT(net_monitor), "network-changed", G_CALLBACK(on_network_change_wrap), on_change_cb);
+ return g_network_monitor_get_network_available(net_monitor);
+}
\ No newline at end of file
diff --git a/src/gui-wizard-gtk/wizard.c b/src/gui-wizard-gtk/wizard.c
index 36ad3fa..b72dbcf 100644
--- a/src/gui-wizard-gtk/wizard.c
+++ b/src/gui-wizard-gtk/wizard.c
@@ -109,6 +109,7 @@ static GtkButton *g_btn_startcast;
static GtkExpander *g_exp_report_log;

static GtkWidget *g_top_most_window;
+static GtkWidget *g_statusbar;

static void add_workflow_buttons(GtkBox *box, GHashTable *workflows, GCallback func);
static void set_auto_event_chain(GtkButton *button, gpointer user_data);
@@ -2995,6 +2996,18 @@ static void on_next_btn_cb(GtkWidget *btn, gpointer user_data)
gtk_notebook_set_current_page(g_assistant, next_page_no);
}

+static void on_network_change(gboolean available)
+{
+ VERB1 log("The network is available: %i", available);
+ if (available)
+ {
+ gtk_statusbar_remove_all(GTK_STATUSBAR(g_statusbar), 0);
+ return;
+ }
+
+ gtk_statusbar_push(GTK_STATUSBAR(g_statusbar), 0, _("Network is not available, reporting to remote servers won't work!"));
+}
+
static void add_pages(void)
{
GError *error = NULL;
@@ -3083,6 +3096,8 @@ static void add_pages(void)
gtk_widget_override_color(GTK_WIDGET(g_eb_comment), GTK_STATE_FLAG_NORMAL, &color);

g_signal_connect(g_tv_details, "key-press-event", G_CALLBACK(on_key_press_event_in_item_list), NULL);
+ /* check the network state and hook up the callback to watch the changes */
+ on_network_change(is_network_available(&on_network_change));
}

static void create_details_treeview(void)
@@ -3299,8 +3314,15 @@ void create_assistant(bool expert_mode)
gtk_widget_hide(g_btn_onfail);
gtk_widget_show(g_btn_next);

+ /* the box which holds the main g_box_assistant and the status bar */
+ GtkWidget *main_hbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
+ g_statusbar = gtk_statusbar_new();
+
+ gtk_box_pack_start(GTK_BOX(main_hbox), GTK_WIDGET(g_box_assistant), true, true, 0);
+ gtk_box_pack_start(GTK_BOX(main_hbox), GTK_WIDGET(g_statusbar), false, false, 5);
+
g_wnd_assistant = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
- gtk_container_add(GTK_CONTAINER(g_wnd_assistant), GTK_WIDGET(g_box_assistant));
+ gtk_container_add(GTK_CONTAINER(g_wnd_assistant), GTK_WIDGET(main_hbox));

gtk_window_set_default_size(g_wnd_assistant, DEFAULT_WIDTH, DEFAULT_HEIGHT);
/* set_default sets icon for every windows used in this app, so we don't
--
1.8.3.1
Jiri Moskovcak
2013-08-30 11:39:29 UTC
Permalink
I'm not quite satisfied with this solution (it looks a bit ugly) so if
someone has a better idea, don't be shy and speak up..

--Jirka
Post by Jiri Moskovcak
---
src/gtk-helpers/Makefile.am | 3 ++-
src/gtk-helpers/internal_libreport_gtk.h | 3 +++
src/gtk-helpers/network_monitor.c | 32 ++++++++++++++++++++++++++++++++
src/gui-wizard-gtk/wizard.c | 24 +++++++++++++++++++++++-
4 files changed, 60 insertions(+), 2 deletions(-)
create mode 100644 src/gtk-helpers/network_monitor.c
diff --git a/src/gtk-helpers/Makefile.am b/src/gtk-helpers/Makefile.am
index b67186f..7c66d1f 100644
--- a/src/gtk-helpers/Makefile.am
+++ b/src/gtk-helpers/Makefile.am
@@ -15,7 +15,8 @@ libreport_gtk_la_SOURCES = \
autowrapped_label.c \
workflow_config_dialog.c \
config_dialog.c \
- ask_dialogs.c
+ ask_dialogs.c \
+ network_monitor.c
libreport_gtk_la_CPPFLAGS = \
-I$(srcdir)/../include \
diff --git a/src/gtk-helpers/internal_libreport_gtk.h b/src/gtk-helpers/internal_libreport_gtk.h
index dc1ef31..fbd49b0 100644
--- a/src/gtk-helpers/internal_libreport_gtk.h
+++ b/src/gtk-helpers/internal_libreport_gtk.h
@@ -136,6 +136,9 @@ int run_ask_yes_no_yesforever_dialog(const char *key, const char *message, GtkWi
#define run_ask_yes_no_save_result_dialog libreport_run_ask_yes_no_save_result_dialog
int run_ask_yes_no_save_result_dialog(const char *key, const char *message, GtkWindow *parent);
+#define is_network_available libreport_is_network_available
+bool is_network_available();
+
#ifdef __cplusplus
}
#endif
diff --git a/src/gtk-helpers/network_monitor.c b/src/gtk-helpers/network_monitor.c
new file mode 100644
index 0000000..193f7dc
--- /dev/null
+++ b/src/gtk-helpers/network_monitor.c
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2012 ABRT Team
+ * Copyright (C) 2012 RedHat inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <internal_libreport_gtk.h>
+
+static void on_network_change_wrap(GNetworkMonitor *g, gboolean available, void(*on_change_cb)(gboolean available))
+{
+ on_change_cb(available);
+}
+
+bool is_network_available(void(*on_change_cb)(gboolean available))
+{
+ GNetworkMonitor* net_monitor = g_network_monitor_get_default();
+ g_signal_connect(G_OBJECT(net_monitor), "network-changed", G_CALLBACK(on_network_change_wrap), on_change_cb);
+ return g_network_monitor_get_network_available(net_monitor);
+}
\ No newline at end of file
diff --git a/src/gui-wizard-gtk/wizard.c b/src/gui-wizard-gtk/wizard.c
index 36ad3fa..b72dbcf 100644
--- a/src/gui-wizard-gtk/wizard.c
+++ b/src/gui-wizard-gtk/wizard.c
@@ -109,6 +109,7 @@ static GtkButton *g_btn_startcast;
static GtkExpander *g_exp_report_log;
static GtkWidget *g_top_most_window;
+static GtkWidget *g_statusbar;
static void add_workflow_buttons(GtkBox *box, GHashTable *workflows, GCallback func);
static void set_auto_event_chain(GtkButton *button, gpointer user_data);
@@ -2995,6 +2996,18 @@ static void on_next_btn_cb(GtkWidget *btn, gpointer user_data)
gtk_notebook_set_current_page(g_assistant, next_page_no);
}
+static void on_network_change(gboolean available)
+{
+ VERB1 log("The network is available: %i", available);
+ if (available)
+ {
+ gtk_statusbar_remove_all(GTK_STATUSBAR(g_statusbar), 0);
+ return;
+ }
+
+ gtk_statusbar_push(GTK_STATUSBAR(g_statusbar), 0, _("Network is not available, reporting to remote servers won't work!"));
+}
+
static void add_pages(void)
{
GError *error = NULL;
@@ -3083,6 +3096,8 @@ static void add_pages(void)
gtk_widget_override_color(GTK_WIDGET(g_eb_comment), GTK_STATE_FLAG_NORMAL, &color);
g_signal_connect(g_tv_details, "key-press-event", G_CALLBACK(on_key_press_event_in_item_list), NULL);
+ /* check the network state and hook up the callback to watch the changes */
+ on_network_change(is_network_available(&on_network_change));
}
static void create_details_treeview(void)
@@ -3299,8 +3314,15 @@ void create_assistant(bool expert_mode)
gtk_widget_hide(g_btn_onfail);
gtk_widget_show(g_btn_next);
+ /* the box which holds the main g_box_assistant and the status bar */
+ GtkWidget *main_hbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
+ g_statusbar = gtk_statusbar_new();
+
+ gtk_box_pack_start(GTK_BOX(main_hbox), GTK_WIDGET(g_box_assistant), true, true, 0);
+ gtk_box_pack_start(GTK_BOX(main_hbox), GTK_WIDGET(g_statusbar), false, false, 5);
+
g_wnd_assistant = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
- gtk_container_add(GTK_CONTAINER(g_wnd_assistant), GTK_WIDGET(g_box_assistant));
+ gtk_container_add(GTK_CONTAINER(g_wnd_assistant), GTK_WIDGET(main_hbox));
gtk_window_set_default_size(g_wnd_assistant, DEFAULT_WIDTH, DEFAULT_HEIGHT);
/* set_default sets icon for every windows used in this app, so we don't
Loading...