[gnome-usage: 1/3] Fix building on Fedora 26.



commit 7373d28d1f57f1620ba254ce32d1073762683d8f
Author: Petr Štětka <pstetka redhat com>
Date:   Fri Apr 7 15:02:16 2017 +0200

    Fix building on Fedora 26.

 src/process-list-box.vala     |   41 ++++++++++++++---------------
 src/storage-item.vala         |   56 +++++++++++++++++++++++++++++++++++-----
 src/sub-process-list-box.vala |   35 ++++++++++++-------------
 3 files changed, 86 insertions(+), 46 deletions(-)
---
diff --git a/src/process-list-box.vala b/src/process-list-box.vala
index 70654c2..f531761 100644
--- a/src/process-list-box.vala
+++ b/src/process-list-box.vala
@@ -71,6 +71,22 @@ namespace Usage
 
         public bool update()
         {
+               CompareDataFunc<Process> processcmp = (a, b) => {
+               Process p_a = (Process) a;
+               Process p_b = (Process) b;
+
+               switch(type)
+               {
+                       default:
+                       case ProcessListBoxType.PROCESSOR:
+                       return (int) ((uint64) (p_a.get_cpu_load() < p_b.get_cpu_load()) - (uint64) 
(p_a.get_cpu_load() > p_b.get_cpu_load()));
+                       case ProcessListBoxType.MEMORY:
+                       return (int) ((uint64) (p_a.get_mem_usage() < p_b.get_mem_usage()) - (uint64) 
(p_a.get_mem_usage() > p_b.get_mem_usage()));
+                       case ProcessListBoxType.NETWORK:
+                       return (int) ((uint64) (p_a.get_net_all() < p_b.get_net_all()) - (uint64) 
(p_a.get_net_all() > p_b.get_net_all()));
+               }
+            };
+
             bind_model(null, null);
             model.remove_all();
 
@@ -81,15 +97,15 @@ namespace Usage
                     default:
                     case ProcessListBoxType.PROCESSOR:
                         foreach(unowned Process process in (GLib.Application.get_default() as 
Application).get_system_monitor().get_cpu_processes())
-                            model.insert_sorted(process, sort);
+                            model.insert_sorted(process, processcmp);
                         break;
                     case ProcessListBoxType.MEMORY:
                         foreach(unowned Process process in (GLib.Application.get_default() as 
Application).get_system_monitor().get_ram_processes())
-                            model.insert_sorted(process, sort);
+                            model.insert_sorted(process, processcmp);
                         break;
                     case ProcessListBoxType.NETWORK:
                         foreach(unowned Process process in (GLib.Application.get_default() as 
Application).get_system_monitor().get_net_processes())
-                            model.insert_sorted(process, sort);
+                            model.insert_sorted(process, processcmp);
                         break;
                 }
             }
@@ -98,7 +114,7 @@ namespace Usage
                 foreach(unowned Process process in (GLib.Application.get_default() as 
Application).get_system_monitor().get_ram_processes()) //because ram contains all processes
                 {
                     if(process.get_display_name().down().contains(search_text.down()) || 
process.get_cmdline().down().contains(search_text.down()))
-                        model.insert_sorted(process, sort);
+                        model.insert_sorted(process, processcmp);
                 }
             }
 
@@ -160,22 +176,5 @@ namespace Usage
                    row.set_header(separator);
                }
         }
-
-        private int sort(GLib.CompareDataFunc.G a, GLib.CompareDataFunc.G b)
-        {
-            Process p_a = (Process) a;
-            Process p_b = (Process) b;
-
-            switch(type)
-            {
-                default:
-                case ProcessListBoxType.PROCESSOR:
-                    return (int) ((uint64) (p_a.get_cpu_load() < p_b.get_cpu_load()) - (uint64) 
(p_a.get_cpu_load() > p_b.get_cpu_load()));
-                case ProcessListBoxType.MEMORY:
-                    return (int) ((uint64) (p_a.get_mem_usage() < p_b.get_mem_usage()) - (uint64) 
(p_a.get_mem_usage() > p_b.get_mem_usage()));
-                case ProcessListBoxType.NETWORK:
-                    return (int) ((uint64) (p_a.get_net_all() < p_b.get_net_all()) - (uint64) 
(p_a.get_net_all() > p_b.get_net_all()));
-            }
-        }
     }
 }
diff --git a/src/storage-item.vala b/src/storage-item.vala
index 6a5c833..dcc8e17 100644
--- a/src/storage-item.vala
+++ b/src/storage-item.vala
@@ -54,32 +54,74 @@ namespace Usage
 
         public StorageItem.directory(StorageItemType parent, string name, string path, uint64 size, double 
percentage)
         {
-            StorageItem.item(StorageItemType.DIRECTORY, parent, name, path, size, percentage);
+               this.type = StorageItemType.DIRECTORY;
+            this.parent = parent;
+            this.name = name;
+            this.path = path;
+            this.size = size;
+            this.percentage = percentage;
+            this.section = 0;
+            this.prefered_position = StorageItemPosition.ANYWHERE;
         }
 
         public StorageItem.file(StorageItemType parent, string name, string path, uint64 size, double 
percentage)
         {
-            StorageItem.item(StorageItemType.FILE, parent, name, path, size, percentage);
+            this.type = StorageItemType.FILE;
+            this.parent = parent;
+            this.name = name;
+            this.path = path;
+            this.size = size;
+            this.percentage = percentage;
+            this.section = 0;
+            this.prefered_position = StorageItemPosition.ANYWHERE;
         }
 
         public StorageItem.trash(string path, uint64 size, double percentage, int section = 0)
         {
-            StorageItem.item(StorageItemType.TRASH, StorageItemType.TRASH, _("Trash"), path, size, 
percentage, section, StorageItemPosition.PENULTIMATE);
+            this.type = StorageItemType.TRASH;
+            this.parent = StorageItemType.TRASH;
+            this.name = _("Trash");
+            this.path = path;
+            this.size = size;
+            this.percentage = percentage;
+            this.section = section;
+            this.prefered_position = StorageItemPosition.PENULTIMATE;
         }
 
         public StorageItem.storage(string name, string path, uint64 size, int section = 0)
         {
-            StorageItem.item(StorageItemType.STORAGE, StorageItemType.STORAGE, name, path, size, 0, section, 
StorageItemPosition.FIRST);
+            this.type = StorageItemType.STORAGE;
+            this.parent = StorageItemType.STORAGE;
+            this.name = name;
+            this.path = path;
+            this.size = size;
+            this.percentage = 0;
+            this.section = section;
+            this.prefered_position = StorageItemPosition.FIRST;
         }
 
         public StorageItem.system(string name, uint64 size, double percentage, int section = 0)
         {
-            StorageItem.item(StorageItemType.SYSTEM, StorageItemType.SYSTEM, name, "", size, percentage, 
section);
+            this.type = StorageItemType.SYSTEM;
+            this.parent = StorageItemType.SYSTEM;
+            this.name = name;
+            this.path = "";
+            this.size = size;
+            this.percentage = percentage;
+            this.section = section;
+            this.prefered_position = StorageItemPosition.ANYWHERE;
         }
 
         public StorageItem.available(uint64 size, double percentage, int section = 0)
         {
-            StorageItem.item(StorageItemType.AVAILABLE, StorageItemType.AVAILABLE, _("Available"), "", size, 
percentage, section, StorageItemPosition.LAST);
+            this.type = StorageItemType.AVAILABLE;
+            this.parent = StorageItemType.AVAILABLE;
+            this.name = _("Available");
+            this.path = "";
+            this.size = size;
+            this.percentage = percentage;
+            this.section = section;
+            this.prefered_position = StorageItemPosition.LAST;
         }
 
         public StorageItemPosition get_prefered_position()
@@ -132,4 +174,4 @@ namespace Usage
             return path;
         }
     }
-}
\ No newline at end of file
+}
diff --git a/src/sub-process-list-box.vala b/src/sub-process-list-box.vala
index 156e122..722e0a7 100644
--- a/src/sub-process-list-box.vala
+++ b/src/sub-process-list-box.vala
@@ -31,11 +31,27 @@ namespace Usage
 
         private void update()
         {
+               CompareDataFunc<Process> processcmp = (a, b) => {
+               Process p_a = (Process) a;
+               Process p_b = (Process) b;
+
+               switch(type)
+               {
+                       default:
+                       case ProcessListBoxType.PROCESSOR:
+                               return (int) ((uint64) (p_a.get_cpu_load() < p_b.get_cpu_load()) - (uint64) 
(p_a.get_cpu_load() > p_b.get_cpu_load()));
+                   case ProcessListBoxType.MEMORY:
+                       return (int) ((uint64) (p_a.get_mem_usage() < p_b.get_mem_usage()) - (uint64) 
(p_a.get_mem_usage() > p_b.get_mem_usage()));
+                   case ProcessListBoxType.NETWORK:
+                       return (int) ((uint64) (p_a.get_net_all() < p_b.get_net_all()) - (uint64) 
(p_a.get_net_all() > p_b.get_net_all()));
+               }
+            };
+
            if(parent_process.get_sub_processes() != null)
            {
                foreach(unowned Process process in parent_process.get_sub_processes().get_values())
                {
-                   model.insert_sorted(process, sort);
+                   model.insert_sorted(process, processcmp);
                }
            }
         }
@@ -59,22 +75,5 @@ namespace Usage
                    row.set_header(separator);
                }
         }
-
-        private int sort(GLib.CompareDataFunc.G a, GLib.CompareDataFunc.G b)
-        {
-            Process p_a = (Process) a;
-            Process p_b = (Process) b;
-
-            switch(type)
-            {
-                default:
-                case ProcessListBoxType.PROCESSOR:
-                    return (int) ((uint64) (p_a.get_cpu_load() < p_b.get_cpu_load()) - (uint64) 
(p_a.get_cpu_load() > p_b.get_cpu_load()));
-                case ProcessListBoxType.MEMORY:
-                    return (int) ((uint64) (p_a.get_mem_usage() < p_b.get_mem_usage()) - (uint64) 
(p_a.get_mem_usage() > p_b.get_mem_usage()));
-                case ProcessListBoxType.NETWORK:
-                    return (int) ((uint64) (p_a.get_net_all() < p_b.get_net_all()) - (uint64) 
(p_a.get_net_all() > p_b.get_net_all()));
-            }
-        }
     }
 }


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