[gnome-usage] storage: Add loading notification



commit cb7e915ea908a78628084fc9f67d31e4d81eeeb3
Author: Petr Štětka <pstetka redhat com>
Date:   Thu May 2 11:39:46 2019 +0000

    storage: Add loading notification

 data/org.gnome.Usage.gresource.xml |   1 +
 data/ui/loading-notification.ui    |  36 ++++++++++++
 data/ui/storage-view.ui            | 111 +++++++++++++++++++++----------------
 src/loading-notification.vala      |  49 ++++++++++++++++
 src/meson.build                    |   2 +
 src/notification-bar.vala          |  45 +++++++++++++++
 src/storage/storage-view.vala      |  11 ++++
 7 files changed, 208 insertions(+), 47 deletions(-)
---
diff --git a/data/org.gnome.Usage.gresource.xml b/data/org.gnome.Usage.gresource.xml
index e793a36..4df94b8 100644
--- a/data/org.gnome.Usage.gresource.xml
+++ b/data/org.gnome.Usage.gresource.xml
@@ -4,6 +4,7 @@
         <file compressed="true">interface/adwaita.css</file>
         <file preprocess="xml-stripblanks">ui/primary-menu.ui</file>
         <file preprocess="xml-stripblanks">ui/header-bar.ui</file>
+        <file preprocess="xml-stripblanks">ui/loading-notification.ui</file>
         <file preprocess="xml-stripblanks">ui/memory-speedometer.ui</file>
         <file preprocess="xml-stripblanks">ui/no-results-found-view.ui</file>
         <file preprocess="xml-stripblanks">ui/performance-view.ui</file>
diff --git a/data/ui/loading-notification.ui b/data/ui/loading-notification.ui
new file mode 100644
index 0000000..6895bb3
--- /dev/null
+++ b/data/ui/loading-notification.ui
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <requires lib="gtk+" version="3.10"/>
+  <template class="UsageLoadingNotification" parent="GtkRevealer">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <property name="valign">start</property>
+    <child>
+      <object class="GtkGrid" id="grid">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="halign">center</property>
+        <property name="valign">center</property>
+        <property name="margin_start">12</property>
+        <property name="margin_end">12</property>
+        <property name="column_spacing">12</property>
+        <child>
+          <object class="GtkLabel" id="message_label">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkSpinner" id="spinner">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="active">True</property>
+          </object>
+        </child>
+        <style>
+          <class name="app-notification"/>
+        </style>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/data/ui/storage-view.ui b/data/ui/storage-view.ui
index 92a0dab..8ebc2b0 100644
--- a/data/ui/storage-view.ui
+++ b/data/ui/storage-view.ui
@@ -4,64 +4,81 @@
   <template class="UsageStorageView" parent="UsageView">
     <property name="visible">True</property>
     <child>
-      <object class="GtkPaned">
+      <object class="GtkOverlay" id="notification_overlay">
         <property name="visible">True</property>
-        <property name="orientation">horizontal</property>
-        <property name="position">360</property>
-        <child>
-          <object class="GtkBox">
+        <child type="overlay">
+          <object class="UsageNotificationBar" id="notificationbar">
             <property name="visible">True</property>
+            <property name="valign">start</property>
+            <property name="halign">center</property>
             <property name="orientation">vertical</property>
-            <style><class name="view"/></style>
-            <child>
-              <object class="GtkLabel" id="header_label">
-                <property name="visible">True</property>
-                <property name="halign">start</property>
-                <property name="margin">10</property>
-                <property name="label" translatable="yes">Home Partition</property>
-                <attributes>
-                  <attribute name="weight" value="bold"/>
-                </attributes>
-              </object>
-            </child>
-            <child>
-              <object class="UsageStorageViewRow" id="used_row">
-                <property name="visible">True</property>
-                <property name="label" translatable="yes">Used</property>
-                <property name="tag_size">1</property>
-              </object>
-            </child>
-            <child>
-              <object class="UsageStorageViewRow" id="available_row">
-                <property name="visible">True</property>
-                <property name="label" translatable="yes">Available</property>
-                <property name="tag_size">1</property>
-              </object>
-            </child>
+            <style>
+              <class name="transparent-bg" />
+            </style>
+          </object>
+        </child>
+        <child>
+          <object class="GtkPaned">
+            <property name="visible">True</property>
+            <property name="orientation">horizontal</property>
+            <property name="position">360</property>
             <child>
-              <object class="DzlStackList" id="listbox">
+              <object class="GtkBox">
                 <property name="visible">True</property>
-                <property name="vexpand">True</property>
-                <signal name="row-activated" handler="on_row_activated"/>
+                <property name="orientation">vertical</property>
                 <style>
-                  <class name="storage-list"/>
+                  <class name="view" />
                 </style>
+                <child>
+                  <object class="GtkLabel" id="header_label">
+                    <property name="visible">True</property>
+                    <property name="halign">start</property>
+                    <property name="margin">10</property>
+                    <property name="label" translatable="yes">Home Partition</property>
+                    <attributes>
+                      <attribute name="weight" value="bold" />
+                    </attributes>
+                  </object>
+                </child>
+                <child>
+                  <object class="UsageStorageViewRow" id="used_row">
+                    <property name="visible">True</property>
+                    <property name="label" translatable="yes">Used</property>
+                    <property name="tag_size">1</property>
+                  </object>
+                </child>
+                <child>
+                  <object class="UsageStorageViewRow" id="available_row">
+                    <property name="visible">True</property>
+                    <property name="label" translatable="yes">Available</property>
+                    <property name="tag_size">1</property>
+                  </object>
+                </child>
+                <child>
+                  <object class="DzlStackList" id="listbox">
+                    <property name="visible">True</property>
+                    <property name="vexpand">True</property>
+                    <signal name="row-activated" handler="on_row_activated" />
+                    <style>
+                      <class name="storage-list" />
+                    </style>
+                  </object>
+                </child>
+                <child>
+                  <object class="UsageStorageActionBar" id="actionbar" />
+                </child>
               </object>
             </child>
             <child>
-              <object class="UsageStorageActionBar" id="actionbar">
-              </object>
-            </child>
-          </object>
-        </child>
-        <child>
-          <object class="GtkBox">
-            <property name="visible">True</property>
-            <property name="vexpand">True</property>
-            <child>
-              <object class="UsageStorageGraph" id="graph">
+              <object class="GtkBox">
                 <property name="visible">True</property>
-                <property name="expand">True</property>
+                <property name="vexpand">True</property>
+                <child>
+                  <object class="UsageStorageGraph" id="graph">
+                    <property name="visible">True</property>
+                    <property name="expand">True</property>
+                  </object>
+                </child>
               </object>
             </child>
           </object>
diff --git a/src/loading-notification.vala b/src/loading-notification.vala
new file mode 100644
index 0000000..99d3c6c
--- /dev/null
+++ b/src/loading-notification.vala
@@ -0,0 +1,49 @@
+/* loading-notification.vala
+ *
+ * Copyright (C) 2019 Red Hat, 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 3 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, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Petr Štětka <pstetka redhat com>
+ */
+
+using Gtk;
+
+namespace Usage {
+
+    [GtkTemplate (ui = "/org/gnome/Usage/ui/loading-notification.ui")]
+    private class LoadingNotification: Gtk.Revealer {
+        public signal void dismissed ();
+        public delegate void DismissFunc ();
+
+        [GtkChild]
+        private Gtk.Label message_label;
+
+        public LoadingNotification (string message, owned DismissFunc? dismiss_func) {
+            set_reveal_child (true);
+
+            message_label.label = message;
+
+            dismissed.connect ( () => {
+                if (dismiss_func != null)
+                    dismiss_func ();
+                set_reveal_child(false);
+            });
+        }
+
+        public void dismiss() {
+            dismissed();
+        }
+    }
+}
diff --git a/src/meson.build b/src/meson.build
index e31625f..404a467 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -13,6 +13,7 @@ vala_sources = [
   'graph-stack-switcher.vala',
   'graph-switcher-button.vala',
   'header-bar.vala',
+  'loading-notification.vala',
   'memory-graph-model.vala',
   'memory-graph.vala',
   'memory-monitor.vala',
@@ -20,6 +21,7 @@ vala_sources = [
   'memory-sub-view.vala',
   'monitor.vala',
   'no-results-found-view.vala',
+  'notification-bar.vala',
   'performance-view.vala',
   'pie-chart.vala',
   'primary-menu.vala',
diff --git a/src/notification-bar.vala b/src/notification-bar.vala
new file mode 100644
index 0000000..5d560a5
--- /dev/null
+++ b/src/notification-bar.vala
@@ -0,0 +1,45 @@
+/* loading-notification.vala
+ *
+ * Copyright (C) 2019 Red Hat, 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 3 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, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Petr Štětka <pstetka redhat com>
+ */
+
+using Gtk;
+
+namespace Usage {
+    private class NotificationBar: Gtk.Grid {
+        public const int DEFAULT_TIMEOUT = 6;
+        private const int MAX_NOTIFICATIONS = 5;
+        private GLib.List<Widget> active_notifications = new GLib.List<Widget> ();
+
+        public LoadingNotification display_loading (string message, owned LoadingNotification.DismissFunc? 
dismiss_func) {
+            var notification = new LoadingNotification (message, (owned) dismiss_func);
+            active_notifications.prepend (notification);
+
+            notification.dismissed.connect ( () => {
+                active_notifications.remove (notification);
+            });
+
+            add_notification (notification);
+            return notification;
+        }
+
+        private void add_notification (Widget widget) {
+            add (widget);
+        }
+    }
+}
diff --git a/src/storage/storage-view.vala b/src/storage/storage-view.vala
index 3d0e1eb..6449c1a 100644
--- a/src/storage/storage-view.vala
+++ b/src/storage/storage-view.vala
@@ -44,6 +44,9 @@ public class Usage.StorageView : Usage.View {
     [GtkChild]
     private StorageActionBar actionbar;
 
+    [GtkChild]
+    private NotificationBar notificationbar;
+
     private Sparql.Connection connection;
     private TrackerController controller;
     private StorageQueryBuilder query_builder;
@@ -265,12 +268,16 @@ public class Usage.StorageView : Usage.View {
     }
 
     private async void populate_view () {
+        var loading_notification = notificationbar.display_loading (_("Scanning directories"), null);
+
         if (connection == null)
             return;
 
         var model = new GLib.ListStore (typeof (StorageViewItem));
         model.append(os_item);
 
+        var items_loaded = 0;
+
         foreach (var dir in xdg_folders) {
             var file = File.new_for_uri (get_user_special_dir_path (dir));
             var item = StorageViewItem.from_file (file);
@@ -282,6 +289,10 @@ public class Usage.StorageView : Usage.View {
                     item.percentage = item.size * 100 / (double) total_size;
                     item.custom_type = StorageViewType.ROOT_ITEM;
                     model.insert (1, item);
+
+                    items_loaded++;
+                    if(items_loaded == xdg_folders.length)
+                        loading_notification.dismiss();
                 } catch (GLib.Error error) {
                     warning (error.message);
                 }


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