[gnome-usage] storage-view-item: Make "custom_item" property an enum
- From: Felipe Borges <felipeborges src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-usage] storage-view-item: Make "custom_item" property an enum
- Date: Tue, 30 Apr 2019 14:48:55 +0000 (UTC)
commit 7d39394f1dca43ffa0a60a4d29b54523f302b54c
Author: Felipe Borges <felipeborges gnome org>
Date: Fri Apr 5 10:57:15 2019 +0200
storage-view-item: Make "custom_item" property an enum
Instead of doing string comparisons, we should use enums for
readability and efficiency.
src/storage/storage-actionbar.vala | 4 ++--
src/storage/storage-graph.vala | 4 ++--
src/storage/storage-row-popover.vala | 4 ++--
src/storage/storage-view-item.vala | 24 ++++++++++++++++--------
src/storage/storage-view-row.vala | 4 ++--
src/storage/storage-view.vala | 14 +++++++-------
src/storage/tracker-controller.vala | 4 ++--
7 files changed, 33 insertions(+), 25 deletions(-)
---
diff --git a/src/storage/storage-actionbar.vala b/src/storage/storage-actionbar.vala
index 8b738eb..1626662 100644
--- a/src/storage/storage-actionbar.vala
+++ b/src/storage/storage-actionbar.vala
@@ -50,7 +50,7 @@ namespace Usage
if(dialog.run() == Gtk.ResponseType.OK) {
foreach(var item in selected_items) {
- if(item.type == FileType.DIRECTORY && item.custom_type == "root_item")
+ if(item.type == FileType.DIRECTORY && item.custom_type == StorageViewType.ROOT_ITEM)
delete_file(item.uri, false);
else
delete_file(item.uri, true);
@@ -83,4 +83,4 @@ namespace Usage
}
}
}
-}
\ No newline at end of file
+}
diff --git a/src/storage/storage-graph.vala b/src/storage/storage-graph.vala
index e147df4..3ba067b 100644
--- a/src/storage/storage-graph.vala
+++ b/src/storage/storage-graph.vala
@@ -39,7 +39,7 @@ namespace Usage
for(int i = 0; i < value.get_n_items(); i++)
{
var item = model.get_item(i) as StorageViewItem;
- if(item.custom_type == "os") {
+ if(item.custom_type == StorageViewType.OS) {
root = true;
break;
}
@@ -102,7 +102,7 @@ namespace Usage
{
var item = model.get_item(i) as StorageViewItem;
var item_radius = radius;
- if(item.custom_type == "up-folder" || item.size == 0)
+ if(item.custom_type == StorageViewType.UP_FOLDER || item.size == 0)
continue;
var style_context = get_style_context();
diff --git a/src/storage/storage-row-popover.vala b/src/storage/storage-row-popover.vala
index 1d58e9a..8a7e7c3 100644
--- a/src/storage/storage-row-popover.vala
+++ b/src/storage/storage-row-popover.vala
@@ -28,11 +28,11 @@ public class Usage.StorageRowPopover : Gtk.Popover {
relative_to = row;
switch(row.item.custom_type) {
- case "os":
+ case StorageViewType.OS:
label.label = _("Operating system files are an essential part of your system and cannot be
removed.");
break;
}
popup();
}
-}
\ No newline at end of file
+}
diff --git a/src/storage/storage-view-item.vala b/src/storage/storage-view-item.vala
index e7dfe21..22eaeb1 100644
--- a/src/storage/storage-view-item.vala
+++ b/src/storage/storage-view-item.vala
@@ -19,6 +19,14 @@
* Petr Štětka <pstetka redhat com>
*/
+public enum StorageViewType {
+ NONE,
+ OS,
+ UP_FOLDER,
+ AVAILABLE_GRAPH,
+ ROOT_ITEM
+}
+
public class Usage.StorageViewItem : GLib.Object {
public double percentage { set; get; }
public bool loaded { get; set; default = false; }
@@ -31,7 +39,7 @@ public class Usage.StorageViewItem : GLib.Object {
public FileType type;
public UserDirectory? dir;
public string ontology;
- public string? custom_type;
+ public StorageViewType custom_type = StorageViewType.NONE;
private string _style_class = null;
public string style_class {
@@ -114,12 +122,12 @@ public class Usage.StorageViewItem : GLib.Object {
break;
}
- if(custom_type != null) {
+ if(custom_type != StorageViewType.NONE) {
switch(custom_type) {
- case "os":
+ case StorageViewType.OS:
style_class = "os-tag";
break;
- case "available-graph":
+ case StorageViewType.AVAILABLE_GRAPH:
style_class = "available-tag";
break;
}
@@ -130,11 +138,11 @@ public class Usage.StorageViewItem : GLib.Object {
}
private bool _show_check_button () {
- if(custom_type != null) {
+ if(custom_type != StorageViewType.NONE) {
switch(custom_type) {
- case "os":
- case "available-graph":
- case "up-folder":
+ case StorageViewType.OS:
+ case StorageViewType.AVAILABLE_GRAPH:
+ case StorageViewType.UP_FOLDER:
return false;
}
}
diff --git a/src/storage/storage-view-row.vala b/src/storage/storage-view-row.vala
index 8c3974c..4541e5f 100644
--- a/src/storage/storage-view-row.vala
+++ b/src/storage/storage-view-row.vala
@@ -84,10 +84,10 @@ public class Usage.StorageViewRow : Gtk.ListBoxRow {
});
set_up();
- if (item.type == FileType.DIRECTORY || item.custom_type != null)
+ if (item.type == FileType.DIRECTORY || item.custom_type != StorageViewType.NONE)
tag.width_request = tag.height_request = 20;
- if(item.custom_type == "up-folder") {
+ if(item.custom_type == StorageViewType.UP_FOLDER) {
get_style_context().add_class("up-folder");
if(!item.loaded) {
diff --git a/src/storage/storage-view.vala b/src/storage/storage-view.vala
index 95f1fb8..0687d53 100644
--- a/src/storage/storage-view.vala
+++ b/src/storage/storage-view.vala
@@ -116,14 +116,14 @@ public class Usage.NewStorageView : Usage.View {
cancellable.cancel();
cancellable = new Cancellable();
- if(storage_row.item.custom_type == "up-folder") {
+ if(storage_row.item.custom_type == StorageViewType.UP_FOLDER) {
stack_listbox_up();
} else if (storage_row.item.type == FileType.DIRECTORY) {
selected_items_stack.push_head((owned) selected_items);
actual_item.push_head(storage_row.item);
clear_selected_items();
present_dir.begin (storage_row.item.uri, storage_row.item.dir, cancellable);
- } else if (storage_row.item.custom_type != null) {
+ } else if (storage_row.item.custom_type != StorageViewType.NONE) {
row_popover.present(storage_row);
} else {
try {
@@ -184,7 +184,7 @@ public class Usage.NewStorageView : Usage.View {
refresh_actionbar();
});
- if(item.custom_type == "available-graph")
+ if(item.custom_type == StorageViewType.AVAILABLE_GRAPH)
return new Gtk.ListBoxRow();
graph.model = (ListStore) listbox.get_model();
@@ -198,7 +198,7 @@ public class Usage.NewStorageView : Usage.View {
var model = new GLib.ListStore (typeof (StorageViewItem));
var file = File.new_for_uri (uri);
var item = StorageViewItem.from_file (file);
- item.custom_type = "up-folder";
+ item.custom_type = StorageViewType.UP_FOLDER;
item.dir = dir;
model.insert(0, item);
@@ -241,7 +241,7 @@ public class Usage.NewStorageView : Usage.View {
if (dir == "/") {
os_item.name = _("Operating System");
os_item.size = used;
- os_item.custom_type = "os";
+ os_item.custom_type = StorageViewType.OS;
}
total_used_size += used;
@@ -280,7 +280,7 @@ public class Usage.NewStorageView : Usage.View {
try {
item.size = controller.get_file_size.end (res);
item.percentage = item.size * 100 / (double) total_size;
- item.custom_type = "root_item";
+ item.custom_type = StorageViewType.ROOT_ITEM;
model.insert (1, item);
} catch (GLib.Error error) {
warning (error.message);
@@ -292,7 +292,7 @@ public class Usage.NewStorageView : Usage.View {
var available_graph_item = new StorageViewItem ();
available_graph_item.size = total_free_size;
- available_graph_item.custom_type = "available-graph";
+ available_graph_item.custom_type = StorageViewType.AVAILABLE_GRAPH;
available_graph_item.percentage = available_graph_item.size * 100 / (double) total_size;
model.append(available_graph_item);
graph.model = model;
diff --git a/src/storage/tracker-controller.vala b/src/storage/tracker-controller.vala
index bbc13ec..89697c4 100644
--- a/src/storage/tracker-controller.vala
+++ b/src/storage/tracker-controller.vala
@@ -74,11 +74,11 @@ public class Usage.TrackerController : GLib.Object {
var item_a = a as StorageViewItem;
var item_b = b as StorageViewItem;
- if (item_a.custom_type == "up-folder" || item_a.size > item_b.size) {
+ if (item_a.custom_type == StorageViewType.UP_FOLDER || item_a.size > item_b.size) {
return -1;
}
- if (item_b.custom_type == "up-folder" || item_b.size > item_a.size) {
+ if (item_b.custom_type == StorageViewType.UP_FOLDER || item_b.size > item_a.size) {
return 1;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]