[gnome-logs] Allow users to ignore insufficient permission warning



commit 5a73d390d6bc86fe6cf9fea2a05cafa211157582
Author: Jonathan Kang <jonathan121537 gmail com>
Date:   Wed Jul 12 17:35:50 2017 +0800

    Allow users to ignore insufficient permission warning
    
    Currently, if an user don't have sufficient permission to view logs,
    a GtkInfoBar will show up to warn the user about it. And it shows up
    every time the user opens Logs until the user has sufficient
    permission. This can be quite annoying.
    
    Fix this by adding an "ignore" button to GtkInfoBar to give users the
    option to ignore the warning.

 data/gl-window.ui               |   10 +++++++++-
 data/org.gnome.Logs.gschema.xml |    5 +++++
 src/gl-window.c                 |   36 ++++++++++++++++++++++++++++++++++++
 3 files changed, 50 insertions(+), 1 deletions(-)
---
diff --git a/data/gl-window.ui b/data/gl-window.ui
index ac55eaa..7c5c919 100644
--- a/data/gl-window.ui
+++ b/data/gl-window.ui
@@ -22,7 +22,7 @@
                         <child>
                             <object class="GtkButtonBox" id="action_area">
                                 <property name="visible">True</property>
-                                <property name="orientation">vertical</property>
+                                <property name="orientation">horizontal</property>
                                 <property name="layout_style">center</property>
                                 <child>
                                     <object class="GtkButton" id="help_button">
@@ -32,6 +32,14 @@
                                         <signal name="clicked" handler="on_help_button_clicked" 
object="GlWindow"/>
                                     </object>
                                 </child>
+                                <child>
+                                    <object class="GtkButton" id="ignore_button">
+                                        <property name="visible">True</property>
+                                        <property name="halign">center</property>
+                                        <property name="label" translatable="yes">Ignore</property>
+                                        <signal name="clicked" handler="on_ignore_button_clicked" 
object="GlWindow"/>
+                                    </object>
+                                </child>
                             </object>
                             <packing>
                                 <property name="expand">False</property>
diff --git a/data/org.gnome.Logs.gschema.xml b/data/org.gnome.Logs.gschema.xml
index 8a18cb8..477aaef 100644
--- a/data/org.gnome.Logs.gschema.xml
+++ b/data/org.gnome.Logs.gschema.xml
@@ -1,6 +1,11 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <schemalist gettext-domain="gnome-logs">
   <schema id="org.gnome.Logs" path="/org/gnome/logs/">
+    <key name="ignore-warning" type="b">
+      <summary>Ignore warning</summary>
+      <description>Whether to ignore the warning that says you don't have sufficient permission to view 
logs. If ignored, the warning won't show up again.</description>
+      <default>false</default>
+    </key>
     <key name="sort-order" enum="org.gnome.Logs.GlSortOrder">
       <summary>How to sort list rows in the event view list</summary>
       <description>Sort list rows in ascending or descending order for the selected type</description>
diff --git a/src/gl-window.c b/src/gl-window.c
index 3f303aa..dc0ef5a 100644
--- a/src/gl-window.c
+++ b/src/gl-window.c
@@ -41,6 +41,9 @@ typedef struct
 
 G_DEFINE_TYPE_WITH_PRIVATE (GlWindow, gl_window, GTK_TYPE_APPLICATION_WINDOW)
 
+static const gchar SETTINGS_SCHEMA[] = "org.gnome.Logs";
+static const gchar IGNORE_WARNING[] = "ignore-warning";
+
 static void
 on_action_radio (GSimpleAction *action,
                  GVariant *variant,
@@ -259,6 +262,24 @@ on_help_button_clicked (GlWindow *window,
     gtk_widget_hide (priv->info_bar);
 }
 
+static void
+on_ignore_button_clicked (GlWindow *window,
+                          gint response_id,
+                          gpointer user_data)
+{
+    GlWindowPrivate *priv;
+    GSettings *settings;
+
+    priv = gl_window_get_instance_private (GL_WINDOW (window));
+
+    settings = g_settings_new (SETTINGS_SCHEMA);
+    g_settings_set_boolean (settings, IGNORE_WARNING, TRUE);
+
+    gtk_widget_hide (priv->info_bar);
+
+    g_object_unref (settings);
+}
+
 void
 gl_window_set_sort_order (GlWindow *window,
                           GlSortOrder sort_order)
@@ -299,6 +320,8 @@ gl_window_class_init (GlWindowClass *klass)
                                              on_gl_window_key_press_event);
     gtk_widget_class_bind_template_callback (widget_class,
                                              on_help_button_clicked);
+    gtk_widget_class_bind_template_callback (widget_class,
+                                             on_ignore_button_clicked);
 }
 
 static void
@@ -315,6 +338,8 @@ gl_window_init (GlWindow *window)
     GlJournalBootID *boot_id;
     gchar *boot_match;
     GVariant *variant;
+    GSettings *settings;
+    gboolean ignore;
 
     gtk_widget_init_template (GTK_WIDGET (window));
 
@@ -353,6 +378,16 @@ gl_window_init (GlWindow *window)
                                                GTK_STYLE_PROVIDER (provider),
                                                GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
 
+    settings = g_settings_new (SETTINGS_SCHEMA);
+    ignore = g_settings_get_boolean (settings, IGNORE_WARNING);
+    /* Don't show info_bar again if users have ever ignored the warning. */
+    if (ignore)
+    {
+        g_object_unref (provider);
+        g_object_unref (settings);
+        return;
+    }
+
     /* Show warnings based on storage type. */
     storage_type = gl_util_journal_storage_type ();
     switch (storage_type)
@@ -424,6 +459,7 @@ gl_window_init (GlWindow *window)
     }
 
     g_object_unref (provider);
+    g_object_unref (settings);
 }
 
 GtkWidget *


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