[gedit] Show a warning on remote docs if network goes down
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit] Show a warning on remote docs if network goes down
- Date: Sun, 2 Feb 2014 21:21:12 +0000 (UTC)
commit fd6334ec790f79d400cf5f0b0b995bd675c72ff1
Author: ghugesagar <ghugesss gmail com>
Date: Wed Jan 29 16:10:19 2014 +0530
Show a warning on remote docs if network goes down
Used GNetworkMonitor to show an info bar warning if using a remote
doc and network is down
gedit/gedit-app.c | 42 ++++++++++++++++++++++
gedit/gedit-io-error-info-bar.c | 74 +++++++++++++++++++++++++++++++++++++++
gedit/gedit-io-error-info-bar.h | 2 +
gedit/gedit-tab.c | 46 ++++++++++++++++++++++++
gedit/gedit-tab.h | 5 ++-
5 files changed, 168 insertions(+), 1 deletions(-)
---
diff --git a/gedit/gedit-app.c b/gedit/gedit-app.c
index 5330da3..2684bab 100644
--- a/gedit/gedit-app.c
+++ b/gedit/gedit-app.c
@@ -36,6 +36,7 @@
#include <locale.h>
#include <glib/gi18n.h>
+#include <gio/gio.h>
#include <libpeas/peas-extension-set.h>
#include <gtksourceview/gtksource.h>
@@ -55,6 +56,7 @@
#include "gedit-plugins-engine.h"
#include "gedit-commands.h"
#include "gedit-preferences-dialog.h"
+#include "gedit-tab.h"
#ifndef ENABLE_GVFS_METADATA
#include "gedit-metadata-manager.h"
@@ -85,6 +87,7 @@ struct _GeditAppPrivate
GSettings *window_settings;
PeasExtensionSet *extensions;
+ GNetworkMonitor *monitor;
};
static gboolean help = FALSE;
@@ -1328,12 +1331,51 @@ load_print_settings (GeditApp *app)
}
static void
+get_network_available (GNetworkMonitor *monitor,
+ gboolean available,
+ GeditApp *app)
+{
+ gboolean enable;
+ GList *windows, *w;
+
+ enable = g_network_monitor_get_network_available (monitor);
+
+ windows = gtk_application_get_windows (GTK_APPLICATION (app));
+
+ for (w = windows; w != NULL; w = w->next)
+ {
+ GeditWindow *window = GEDIT_WINDOW (w->data);
+
+ if (GEDIT_IS_WINDOW (window))
+ {
+ GList *tabs, *t;
+
+ tabs = _gedit_window_get_all_tabs (window);
+
+ for (t = tabs; t != NULL; t = t->next)
+ {
+ _gedit_tab_set_network_available (GEDIT_TAB (t->data),
+ enable);
+ }
+
+ g_list_free (tabs);
+ }
+ }
+}
+
+static void
gedit_app_init (GeditApp *app)
{
app->priv = gedit_app_get_instance_private (app);
g_set_application_name ("gedit");
gtk_window_set_default_icon_name ("accessories-text-editor");
+
+ app->priv->monitor = g_network_monitor_get_default ();
+ g_signal_connect (app->priv->monitor,
+ "network-changed",
+ G_CALLBACK (get_network_available),
+ app);
}
/* Generates a unique string for a window role */
diff --git a/gedit/gedit-io-error-info-bar.c b/gedit/gedit-io-error-info-bar.c
index eeaa438..54a641f 100644
--- a/gedit/gedit-io-error-info-bar.c
+++ b/gedit/gedit-io-error-info-bar.c
@@ -450,6 +450,80 @@ create_combo_box (GtkWidget *info_bar,
gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
}
+GtkWidget *
+gedit_network_unavailable_info_bar_new (GFile *location)
+{
+ GtkWidget *info_bar;
+ GtkWidget *hbox_content;
+ GtkWidget *image;
+ GtkWidget *vbox;
+ gchar *primary_markup;
+ gchar *secondary_markup;
+ GtkWidget *primary_label;
+ GtkWidget *secondary_label;
+ gchar *primary_text;
+ const gchar *secondary_text;
+ gchar *full_formatted_uri;
+ gchar *uri_for_display;
+ gchar *temp_uri_for_display;
+
+ g_return_val_if_fail (G_IS_FILE (location), NULL);
+
+ full_formatted_uri = g_file_get_parse_name (location);
+
+ temp_uri_for_display = gedit_utils_str_middle_truncate (full_formatted_uri,
+ MAX_URI_IN_DIALOG_LENGTH);
+ g_free (full_formatted_uri);
+ uri_for_display = g_markup_printf_escaped ("<i>%s</i>", temp_uri_for_display);
+ g_free (temp_uri_for_display);
+
+ info_bar = gtk_info_bar_new ();
+ gtk_info_bar_set_show_close_button (GTK_INFO_BAR (info_bar), TRUE);
+ gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar),
+ GTK_MESSAGE_WARNING);
+ hbox_content = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 8);
+
+ image = gtk_image_new_from_stock ("gtk-dialog-warning", GTK_ICON_SIZE_DIALOG);
+ gtk_box_pack_start (GTK_BOX (hbox_content), image, FALSE, FALSE, 0);
+ gtk_widget_set_halign (image, GTK_ALIGN_START);
+
+ vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
+ gtk_box_pack_start (GTK_BOX (hbox_content), vbox, TRUE, TRUE, 0);
+
+ primary_text = g_strdup_printf (_("The location ā%sā is not currently reachable."),
+ uri_for_display);
+ g_free (uri_for_display);
+
+ primary_markup = g_strdup_printf ("<b>%s</b>", primary_text);
+ g_free (primary_text);
+ primary_label = gtk_label_new (primary_markup);
+ g_free (primary_markup);
+ gtk_box_pack_start (GTK_BOX (vbox), primary_label, TRUE, TRUE, 0);
+ gtk_label_set_use_markup (GTK_LABEL (primary_label), TRUE);
+ gtk_label_set_line_wrap (GTK_LABEL (primary_label), TRUE);
+ gtk_widget_set_halign (primary_label, GTK_ALIGN_START);
+ gtk_widget_set_can_focus (primary_label, TRUE);
+ gtk_label_set_selectable (GTK_LABEL (primary_label), TRUE);
+
+ secondary_text = _("Your system is offline. Check your network.");
+ secondary_markup = g_strdup_printf ("<small>%s</small>",
+ secondary_text);
+ secondary_label = gtk_label_new (secondary_markup);
+ g_free (secondary_markup);
+
+ gtk_box_pack_start (GTK_BOX (vbox), secondary_label, TRUE, TRUE, 0);
+ gtk_widget_set_can_focus (secondary_label, TRUE);
+ gtk_label_set_use_markup (GTK_LABEL (secondary_label), TRUE);
+ gtk_label_set_line_wrap (GTK_LABEL (secondary_label), TRUE);
+ gtk_label_set_selectable (GTK_LABEL (secondary_label), TRUE);
+ gtk_widget_set_halign (secondary_label, GTK_ALIGN_START);
+
+ gtk_widget_show_all (hbox_content);
+ set_contents (info_bar, hbox_content);
+
+ return info_bar;
+}
+
static GtkWidget *
create_conversion_error_info_bar (const gchar *primary_text,
const gchar *secondary_text,
diff --git a/gedit/gedit-io-error-info-bar.h b/gedit/gedit-io-error-info-bar.h
index 8dfa590..e8de7d8 100644
--- a/gedit/gedit-io-error-info-bar.h
+++ b/gedit/gedit-io-error-info-bar.h
@@ -63,6 +63,8 @@ GtkWidget *gedit_externally_modified_info_bar_new (GFile
*locat
GtkWidget *gedit_invalid_character_info_bar_new (GFile *location);
+GtkWidget *gedit_network_unavailable_info_bar_new (GFile *location);
+
G_END_DECLS
#endif /* __GEDIT_IO_ERROR_INFO_BAR_H__ */
diff --git a/gedit/gedit-tab.c b/gedit/gedit-tab.c
index 60a3d90..bd68ebb 100644
--- a/gedit/gedit-tab.c
+++ b/gedit/gedit-tab.c
@@ -1638,6 +1638,52 @@ on_drop_uris (GeditView *view,
}
static void
+network_available_warning_info_bar_response (GtkWidget *info_bar,
+ gint response_id,
+ GeditTab *tab)
+{
+ if (response_id == GTK_RESPONSE_CLOSE)
+ {
+ gtk_widget_hide (info_bar);
+ }
+}
+
+void
+_gedit_tab_set_network_available (GeditTab *tab,
+ gboolean enable)
+{
+ GeditDocument *doc;
+ GFile *location;
+
+ g_return_if_fail (GEDIT_IS_TAB (tab));
+
+ doc = gedit_tab_get_document (tab);
+ g_return_if_fail (GEDIT_IS_DOCUMENT (doc));
+
+ location = gedit_document_get_location (doc);
+
+ if (!gedit_document_is_local (doc))
+ {
+ if (enable)
+ {
+ set_info_bar (tab, NULL);
+ }
+ else
+ {
+ GtkWidget *bar = gedit_network_unavailable_info_bar_new (location);
+ gtk_info_bar_set_default_response (GTK_INFO_BAR (bar),
+ GTK_RESPONSE_CLOSE);
+ g_signal_connect (bar,
+ "response",
+ G_CALLBACK (network_available_warning_info_bar_response),
+ tab);
+
+ set_info_bar (tab, bar);
+ }
+ }
+}
+
+static void
gedit_tab_init (GeditTab *tab)
{
GeditLockdownMask lockdown;
diff --git a/gedit/gedit-tab.h b/gedit/gedit-tab.h
index 5c06749..2076199 100644
--- a/gedit/gedit-tab.h
+++ b/gedit/gedit-tab.h
@@ -30,7 +30,6 @@
#define __GEDIT_TAB_H__
#include <gtk/gtk.h>
-
#include <gedit/gedit-view.h>
#include <gedit/gedit-document.h>
@@ -175,6 +174,10 @@ gboolean _gedit_tab_get_can_close (GeditTab *tab);
GtkWidget *_gedit_tab_get_view_frame (GeditTab *tab);
+void _gedit_tab_set_network_available
+ (GeditTab *tab,
+ gboolean enable);
+
G_END_DECLS
#endif /* __GEDIT_TAB_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]