[gedit/zbrown/deteplification-src: 179/633] Remove network monitor, buggy implementation with the GtkInfoBar




commit c905868e5f4c85a9cb061daafc63fd46598c5a73
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sat Mar 14 11:08:11 2020 +0100

    Remove network monitor, buggy implementation with the GtkInfoBar
    
    The feature was:
    When having remote files opened in gedit, an infobar was shown when the
    network was no longer available. When the network was again available,
    the infobar was hidden.
    
    Problem:
    With the way GeditTab is implemented, there can be maximum *one* infobar
    shown at a time! So if there is already another infobar shown, it gets
    destroyed by the network infobar. Or it gets destroyed when the network
    is again available. The problem is that the *other* infobar may be
    important in order to bring back the tab in the desired state (editable
    text, being able to save the document, etc).
    
    An easy way to reproduce the problem (before this commit):
    1. Open an https:// URL.
    2. Open a second gedit window and open in it the same https:// URL -> it
    shows an infobar to choose whether to keep the document read-only or to
    edit anyway.
    3. Disconnect the network.
    -> the network connectivity infobar has overwritten the infobar to
    choose whether to edit the second document.
    
    There are many other situations where this is problematic (see how many
    different infobars there are in the gedit codebase).
    
    When GeditTab will be ported to TeplTab, it will be possible to bring
    back the feature because with TeplTab it's possible to show several
    infobars.

 gedit/gedit-app.c               | 45 ---------------------------
 gedit/gedit-io-error-info-bar.c | 69 -----------------------------------------
 gedit/gedit-io-error-info-bar.h |  2 --
 gedit/gedit-tab-private.h       |  3 --
 gedit/gedit-tab.c               | 47 ----------------------------
 5 files changed, 166 deletions(-)
---
diff --git a/gedit/gedit-app.c b/gedit/gedit-app.c
index a76cd900d..2570206f2 100644
--- a/gedit/gedit-app.c
+++ b/gedit/gedit-app.c
@@ -48,7 +48,6 @@
 #include "gedit-commands.h"
 #include "gedit-preferences-dialog.h"
 #include "gedit-tab.h"
-#include "gedit-tab-private.h"
 
 #ifndef ENABLE_GVFS_METADATA
 #include "gedit-metadata-manager.h"
@@ -82,7 +81,6 @@ typedef struct
        GMenuModel        *line_col_menu;
 
        PeasExtensionSet  *extensions;
-       GNetworkMonitor   *monitor;
 
        /* command line parsing */
        gboolean new_window;
@@ -1395,55 +1393,12 @@ 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)
 {
-       GeditAppPrivate *priv;
-
-       priv = gedit_app_get_instance_private (app);
-
        g_set_application_name ("gedit");
        gtk_window_set_default_icon_name ("gedit");
 
-       priv->monitor = g_network_monitor_get_default ();
-       g_signal_connect (priv->monitor,
-                         "network-changed",
-                         G_CALLBACK (get_network_available),
-                         app);
-
        g_application_add_main_option_entries (G_APPLICATION (app), options);
 
 #ifdef ENABLE_INTROSPECTION
diff --git a/gedit/gedit-io-error-info-bar.c b/gedit/gedit-io-error-info-bar.c
index e11d77454..1539e3b7b 100644
--- a/gedit/gedit-io-error-info-bar.c
+++ b/gedit/gedit-io-error-info-bar.c
@@ -402,75 +402,6 @@ 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 *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);
-
-       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 44b9b8b4c..9784652c7 100644
--- a/gedit/gedit-io-error-info-bar.h
+++ b/gedit/gedit-io-error-info-bar.h
@@ -55,8 +55,6 @@ 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-private.h b/gedit/gedit-tab-private.h
index 7559bf1f6..1b84f13d1 100644
--- a/gedit/gedit-tab-private.h
+++ b/gedit/gedit-tab-private.h
@@ -74,9 +74,6 @@ gboolean       _gedit_tab_get_can_close               (GeditTab                 *tab);
 
 GeditViewFrame *_gedit_tab_get_view_frame              (GeditTab                 *tab);
 
-void            _gedit_tab_set_network_available       (GeditTab            *tab,
-                                                        gboolean            enable);
-
 G_END_DECLS
 
 #endif  /* GEDIT_TAB_PRIVATE_H */
diff --git a/gedit/gedit-tab.c b/gedit/gedit-tab.c
index 02d243714..fe8908d66 100644
--- a/gedit/gedit-tab.c
+++ b/gedit/gedit-tab.c
@@ -1299,53 +1299,6 @@ on_drop_uris (GeditView  *view,
        g_signal_emit (G_OBJECT (tab), signals[DROP_URIS], 0, uri_list);
 }
 
-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;
-       GtkSourceFile *file;
-       GFile *location;
-
-       g_return_if_fail (GEDIT_IS_TAB (tab));
-
-       doc = gedit_tab_get_document (tab);
-       file = gedit_document_get_file (doc);
-       location = gtk_source_file_get_location (file);
-
-       if (gtk_source_file_is_local (file) || location == NULL)
-       {
-               return;
-       }
-
-       if (enable)
-       {
-               set_info_bar (tab, NULL, GTK_RESPONSE_NONE);
-       }
-       else
-       {
-               GtkWidget *info_bar = gedit_network_unavailable_info_bar_new (location);
-
-               g_signal_connect (info_bar,
-                                 "response",
-                                 G_CALLBACK (network_available_warning_info_bar_response),
-                                 tab);
-
-               set_info_bar (tab, info_bar, GTK_RESPONSE_CLOSE);
-       }
-}
-
 static void
 gedit_tab_init (GeditTab *tab)
 {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]