After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 680826 - Order by most recently used
Order by most recently used
Status: RESOLVED FIXED
Product: gnome-boxes
Classification: Applications
Component: general
unspecified
Other Linux
: Normal trivial
: --
Assigned To: GNOME Boxes maintainer(s)
GNOME Boxes maintainer(s)
Depends on:
Blocks:
 
 
Reported: 2012-07-30 13:03 UTC by Marc-Andre Lureau
Modified: 2016-03-31 13:57 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Move the properties sync code to DisplayConfig (8.80 KB, patch)
2012-10-24 21:15 UTC, Marc-Andre Lureau
committed Details | Review
Move access information to DisplayConfig (8.94 KB, patch)
2012-10-24 21:15 UTC, Marc-Andre Lureau
committed Details | Review
Rename s/DisplayConfig/BoxConfig (8.59 KB, patch)
2012-10-24 21:15 UTC, Marc-Andre Lureau
committed Details | Review
Get rid of DisplayProperties (3.49 KB, patch)
2012-10-24 21:15 UTC, Marc-Andre Lureau
committed Details | Review
Order by most recently used (1.57 KB, patch)
2012-10-24 21:16 UTC, Marc-Andre Lureau
reviewed Details | Review
box-config: make {load,save}_property() private (1.37 KB, patch)
2012-10-24 21:23 UTC, Marc-Andre Lureau
committed Details | Review
Order by most recently used (3.99 KB, patch)
2012-10-26 10:24 UTC, Marc-Andre Lureau
reviewed Details | Review
Order by most recently used (4.75 KB, patch)
2013-03-01 14:19 UTC, Zeeshan Ali
needs-work Details | Review
collection: Order machines by last access time (4.93 KB, patch)
2013-03-02 21:10 UTC, Zeeshan Ali
committed Details | Review
Boxes without latest patch (170.47 KB, image/png)
2013-03-02 21:16 UTC, Zeeshan Ali
  Details
Boxes with latest patch (171.81 KB, image/png)
2013-03-02 21:16 UTC, Zeeshan Ali
  Details

Description Marc-Andre Lureau 2012-07-30 13:03:08 UTC
Boxes collection is currently alphabetically ordered.

It is more sensible and more consistant with the rest of GNOME application design to order the machines by most recently used.
Comment 1 Marc-Andre Lureau 2012-10-24 21:15:48 UTC
Created attachment 227198 [details] [review]
Move the properties sync code to DisplayConfig
Comment 2 Marc-Andre Lureau 2012-10-24 21:15:51 UTC
Created attachment 227199 [details] [review]
Move access information to DisplayConfig
Comment 3 Marc-Andre Lureau 2012-10-24 21:15:55 UTC
Created attachment 227200 [details] [review]
Rename s/DisplayConfig/BoxConfig
Comment 4 Marc-Andre Lureau 2012-10-24 21:15:59 UTC
Created attachment 227201 [details] [review]
Get rid of DisplayProperties
Comment 5 Marc-Andre Lureau 2012-10-24 21:16:03 UTC
Created attachment 227202 [details] [review]
Order by most recently used
Comment 6 Marc-Andre Lureau 2012-10-24 21:20:45 UTC
this is mostly refactoring, for which I hope I don't have to justify myself too much, since I wrote it, and I was not so happy about it in the first place. 

The problem with the current code is that it started to show it's age, and some of the early design turned to be not flexible enough. Now we have a BoxConfig class that can sync properties from various objects, and we don't need to instantiate a Display object to get/set some settings, such as access time. Also we get rid of an extra weird class DisplayProperties, and we make some method part of a Display instance and protected, such as access_start () and access_finish (), which is better since only the Display should update access information.
Comment 7 Marc-Andre Lureau 2012-10-24 21:23:55 UTC
Created attachment 227205 [details] [review]
box-config: make {load,save}_property() private
Comment 8 Zeeshan Ali 2012-10-25 21:59:01 UTC
Review of attachment 227198 [details] [review]:

1. Looking at this patch, I wonder if we really need so many indirections: DisplayProperties keeps a list of all saved props and then saving/loading code in display-config is given a name for which it tries to find a gobject prop, checks its type and then call the appropriate method on keyfile. Can't this saving/loading methods be virtual methods in DisplayProperties hierarchy, where each implementation simply calls the appropriate method on the keyfile as they know the type of the property being saved and which ones to save?

2. I think SavedProperty is more descriptive. SyncedProperty is not bad either.
Comment 9 Zeeshan Ali 2012-10-25 22:15:18 UTC
Review of attachment 227199 [details] [review]:

Seems like a simple move from class A to B (though I don't know if these classes really should be separate) so ACK, depending on outcome of review or parent commit.
Comment 10 Zeeshan Ali 2012-10-25 22:18:23 UTC
Review of attachment 227199 [details] [review]:

scratch what i said about these classes being separate, next patch explains what i keep on missing. :)
Comment 11 Zeeshan Ali 2012-10-26 00:10:01 UTC
Review of attachment 227201 [details] [review]:

Good stuff
Comment 12 Zeeshan Ali 2012-10-26 00:11:08 UTC
Review of attachment 227200 [details] [review]:

Yup, another good simplification of code. Keep 'em coming :)
Comment 13 Zeeshan Ali 2012-10-26 00:30:55 UTC
Review of attachment 227202 [details] [review]:

::: src/collection-view.vala
@@ +361,3 @@
+                if (machine_a.config.access_last_time >
+                    machine_b.config.access_last_time)
+                    return -1;

shouldn't there be:
  else
       return 1;

here?

@@ -357,1 +357,17 @@
-            return item_a.name.collate (item_b.name);
+            var machine_a = item_a as Machine;
+            var machine_b = item_b as Machine;
+            if (machine_a != null && machine_b != null) {
... 14 more ...

shouldn't this one return "1" and not "-1"?
Comment 14 Zeeshan Ali 2012-10-26 00:45:34 UTC
Review of attachment 227198 [details] [review]:

After looking at the rest of the patches, I think the complexity/indirections is much reduced but I still wonder if the code can be further simplified by IPropertiesProvider implementors saving/loading props themselves. Am I making any sense here? :) If not, ignore me on this one and just address #2 in previous comment.
Comment 15 Zeeshan Ali 2012-10-26 00:48:51 UTC
Review of attachment 227205 [details] [review]:

Looks good as per the previous patches.
Comment 16 Marc-Andre Lureau 2012-10-26 01:19:39 UTC
Review of attachment 227198 [details] [review]:

regarding #1, we can always improve later, this it is beyond the point of this refactoring

for #2, Sync is more appropriate than Saved. I don't see why Synced would be better than Sync, no more than Binded or Bound would be better than Bind ..
Comment 17 Marc-Andre Lureau 2012-10-26 01:22:39 UTC
Review of attachment 227202 [details] [review]:

::: src/collection-view.vala
@@ +361,3 @@
+                if (machine_a.config.access_last_time >
+                    machine_b.config.access_last_time)
+                    return -1;

not here, as we order them by alphabetical order next (if they really have same access_last_time (probably 0)

@@ -357,1 +357,17 @@
-            return item_a.name.collate (item_b.name);
+            var machine_a = item_a as Machine;
+            var machine_b = item_b as Machine;
+            if (machine_a != null && machine_b != null) {
... 14 more ...

we want empty name to be last, so b come after a, so return should be negative (a < b).
Comment 18 Zeeshan Ali 2012-10-26 01:43:05 UTC
Review of attachment 227202 [details] [review]:

::: src/collection-view.vala
@@ +361,3 @@
+                if (machine_a.config.access_last_time >
+                    machine_b.config.access_last_time)
+                    return -1;

but we are preceding to comparison by alphabetical order also in case access_time_a < access_time_b, not only if they are equal.

@@ -357,1 +357,17 @@
-            return item_a.name.collate (item_b.name);
+            var machine_a = item_a as Machine;
+            var machine_b = item_b as Machine;
+            if (machine_a != null && machine_b != null) {
... 14 more ...

ah ok, i think its just a bit confusing with both ifs returning the same value.
Comment 19 Zeeshan Ali 2012-10-26 01:45:05 UTC
Review of attachment 227198 [details] [review]:

Depending on the context, bound/binded might actually be better than bind. :) present tense of verb is usually a good choice for function names as they are actions. Anways, nitpicks. :)
Comment 20 Marc-Andre Lureau 2012-10-26 01:59:27 UTC
Review of attachment 227202 [details] [review]:

::: src/collection-view.vala
@@ +361,3 @@
+                if (machine_a.config.access_last_time >
+                    machine_b.config.access_last_time)
+                    return -1;

hmm.. right, I need to update that.. it's late

@@ -357,1 +357,17 @@
-            return item_a.name.collate (item_b.name);
+            var machine_a = item_a as Machine;
+            var machine_b = item_b as Machine;
+            if (machine_a != null && machine_b != null) {
... 14 more ...

hey, I think you are right, if this condition is reached, a is not set, and b is, so b < a, and we should return 1.
Comment 21 Marc-Andre Lureau 2012-10-26 10:08:20 UTC
Attachment 227198 [details] pushed as 887316a - Move the properties sync code to DisplayConfig
Attachment 227199 [details] pushed as c4a9eb8 - Move access information to DisplayConfig
Attachment 227200 [details] pushed as 720086b - Rename s/DisplayConfig/BoxConfig
Attachment 227201 [details] pushed as f4568fb - Get rid of DisplayProperties
Attachment 227205 [details] pushed as 7893ba8 - box-config: make {load,save}_property() private
Comment 22 Marc-Andre Lureau 2012-10-26 10:24:12 UTC
Created attachment 227346 [details] [review]
Order by most recently used
Comment 23 Zeeshan Ali 2012-11-19 02:54:27 UTC
Review of attachment 227346 [details] [review]:

Looks good otherwise.

::: src/box-config.vala
@@ -184,0 +184,5 @@
+
+    public int compare (BoxConfig other) {
+        // sort first by last time used
... 2 more ...

don't see the need for diffing and keeping the diff:

If (access_last_time > other.access_last_time)
   return -1;
else if (access_last_time < other.access_last_time)
   return 1;

::: src/collection-view.vala
@@ +360,3 @@
+                return machine_a.config.compare (machine_b.config);
+
+            // then by name

* this 'then' seems misplaced here, i'm guessing c&p mistake..
* Do we need this code here? We don't have any other kinds of items than Machine?
Comment 24 Marc-Andre Lureau 2012-11-19 10:26:18 UTC
Review of attachment 227346 [details] [review]:

::: src/box-config.vala
@@ -184,0 +184,5 @@
+
+    public int compare (BoxConfig other) {
+        // sort first by last time used
... 2 more ...

I beg to differ, using access_diff help readin the code.

::: src/collection-view.vala
@@ +360,3 @@
+                return machine_a.config.compare (machine_b.config);
+
+            // then by name

* "then by name", because we first order by machine.config.compare.

* other kind of items: directories / groups, whatever else we may want to put there
Comment 25 Zeeshan Ali 2012-11-19 15:10:03 UTC
Review of attachment 227346 [details] [review]:

::: src/box-config.vala
@@ -184,0 +184,5 @@
+
+    public int compare (BoxConfig other) {
+        // sort first by last time used
... 2 more ...

Never seen anyone doing a diff and comparing the diff against 0 for readability and i dont see any readability improvement but if you prefer it this way...

::: src/collection-view.vala
@@ +360,3 @@
+                return machine_a.config.compare (machine_b.config);
+
+            // then by name

* You want to also put a "First by..." comment above to make the conversation more complete. :)

* Yeah i thought of containers while thinking more about this. Why not have a 'compare' method in Item then and have Machine override it? Machines' implementation would just be:

return config.compare (other_machine.config);
Comment 26 Zeeshan Ali 2013-03-01 14:19:15 UTC
Created attachment 237711 [details] [review]
Order by most recently used

In this version I acted on my own review comments:

* CollectionItem provides a virtual 'compare' method that Machine overrides.
* Compare values directly rather than comparing the diff against 0.
Comment 27 Alexander Larsson 2013-03-01 14:27:48 UTC
Review of attachment 237711 [details] [review]:

::: src/machine.vala
@@ +513,3 @@
+            return config.compare ((other as Machine).config);
+        else
+            return base.compare (other);

I don't think this is a valid comparison. It doesn't seem to define a total order, more like a partial order. I.e. the order of the result depends in what order the machine and non-machine items appears in during the sort. For instance, if a non-machine item appears between two machines the order only depends on the basic stuff (name) whereas if the two machines happened to be next to each other it depends on the use date.
Comment 28 Zeeshan Ali 2013-03-02 21:10:47 UTC
Created attachment 237853 [details] [review]
collection: Order machines by last access time

This version should take care of listing machines before non-machines.
Comment 29 Zeeshan Ali 2013-03-02 21:14:05 UTC
I was able to test with this hack: http://paste.fedoraproject.org/4121 that adds dummy items after each machine. Will attach screenshots of this hack with and without the latest patch.
Comment 30 Zeeshan Ali 2013-03-02 21:16:01 UTC
Created attachment 237854 [details]
Boxes without latest patch
Comment 31 Zeeshan Ali 2013-03-02 21:16:46 UTC
Created attachment 237855 [details]
Boxes with latest patch
Comment 32 Alexander Larsson 2013-03-04 12:59:53 UTC
Review of attachment 237853 [details] [review]:

otherwise it looks good

::: src/box-config.vala
@@ +189,3 @@
+                return -1;
+            else if (access_last_time < other.access_last_time)
+                return 1;

Isn't this supposed to fall back to name if the access times are equal?
Comment 33 Zeeshan Ali 2013-03-04 13:20:01 UTC
Review of attachment 237853 [details] [review]:

::: src/box-config.vala
@@ +189,3 @@
+                return -1;
+            else if (access_last_time < other.access_last_time)
+                return 1;

And it does, doesn't it?

if (access times are set) {
  if (a.access > b.access)
    return..
  else if (a.access < b.access)
    return..
}

The above code won't return if access times are not set or they are equal so the following code will be executed, which compares names.
Comment 34 Alexander Larsson 2013-03-04 13:37:44 UTC
Review of attachment 237853 [details] [review]:

::: src/box-config.vala
@@ +189,3 @@
+                return -1;
+            else if (access_last_time < other.access_last_time)
+                return 1;

ah, true. I just misread the second else. sorry. Ack then
Comment 35 Zeeshan Ali 2013-03-04 13:49:02 UTC
Attachment 237853 [details] pushed as 563bf0d - collection: Order machines by last access time