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 688473 - Clean up ui_state_changed
Clean up ui_state_changed
Status: RESOLVED FIXED
Product: gnome-boxes
Classification: Applications
Component: general
unspecified
Other Linux
: Normal normal
: --
Assigned To: GNOME Boxes maintainer(s)
GNOME Boxes maintainer(s)
Depends on:
Blocks:
 
 
Reported: 2012-11-16 15:53 UTC by Alexander Larsson
Modified: 2016-03-31 13:57 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Properties: Avoid connecting to stats multiple times (2.10 KB, patch)
2012-11-16 15:54 UTC, Alexander Larsson
committed Details | Review
Simplify status tracking (3.20 KB, patch)
2012-11-16 15:54 UTC, Alexander Larsson
committed Details | Review
App: minor ui_state_changed cleanup (1.24 KB, patch)
2012-11-16 15:54 UTC, Alexander Larsson
committed Details | Review
App.ui_state_changed: move searchbar hiding out of switch (1.05 KB, patch)
2012-11-16 15:54 UTC, Alexander Larsson
accepted-commit_now Details | Review
Move most App.current_item.actor stuff to App from CollectionView (5.64 KB, patch)
2012-11-16 15:54 UTC, Alexander Larsson
accepted-commit_now Details | Review
Simplify actor fading in ui_state_changed implementation (2.95 KB, patch)
2012-11-16 15:54 UTC, Alexander Larsson
accepted-commit_now Details | Review
CollectionView.ui_state_changed remove switch (1.12 KB, patch)
2012-11-16 15:54 UTC, Alexander Larsson
accepted-commit_now Details | Review
Add allocate_actor_noanim herlper (2.64 KB, patch)
2012-11-16 15:54 UTC, Alexander Larsson
reviewed Details | Review
App: Move shared code into position_item_actor_at_icon helper (2.91 KB, patch)
2012-11-16 15:54 UTC, Alexander Larsson
reviewed Details | Review
Cleanup ui_state_changed implementations (4.75 KB, patch)
2012-11-16 15:54 UTC, Alexander Larsson
accepted-commit_now Details | Review
App.ui_state_changed: move searchbar hiding out of switch (1.15 KB, patch)
2012-11-19 08:37 UTC, Alexander Larsson
committed Details | Review
Move most App.current_item.actor stuff to App from CollectionView (5.64 KB, patch)
2012-11-19 08:37 UTC, Alexander Larsson
committed Details | Review
Simplify actor fading in ui_state_changed implementation (2.95 KB, patch)
2012-11-19 08:37 UTC, Alexander Larsson
committed Details | Review
CollectionView.ui_state_changed remove switch (1.12 KB, patch)
2012-11-19 08:38 UTC, Alexander Larsson
committed Details | Review
Add allocate_actor_noanim herlper (2.70 KB, patch)
2012-11-19 08:38 UTC, Alexander Larsson
committed Details | Review
App: Move shared code into position_item_actor_at_icon helper (2.91 KB, patch)
2012-11-19 08:38 UTC, Alexander Larsson
committed Details | Review
Cleanup ui_state_changed implementations (4.75 KB, patch)
2012-11-19 08:38 UTC, Alexander Larsson
committed Details | Review

Description Alexander Larsson 2012-11-16 15:53:45 UTC
I really dislike how tangled our control flow is due to the various ui_state_changed handlers spread all over the place. This series tries
to clean this up by grouping related code in the same class, and making the ui_state_changed implementations smaller and have more "local" behaviour.
Comment 1 Alexander Larsson 2012-11-16 15:54:17 UTC
Created attachment 229145 [details] [review]
Properties: Avoid connecting to stats multiple times

populate() can now be called multiple times, via the refresh_properties
signal. This moves the stats_updated call to ui_state_changed
so that it only happens once.
Comment 2 Alexander Larsson 2012-11-16 15:54:20 UTC
Created attachment 229146 [details] [review]
Simplify status tracking

Instead of signal connections we just bind properties. This also
centralizes the status handling to App.vala.
Comment 3 Alexander Larsson 2012-11-16 15:54:23 UTC
Created attachment 229147 [details] [review]
App: minor ui_state_changed cleanup

Move the set_main_ui_state() call out of the switch as its
really only depending on != DISPLAY, and duplicating it in
all cases is not very nice.
Comment 4 Alexander Larsson 2012-11-16 15:54:26 UTC
Created attachment 229148 [details] [review]
App.ui_state_changed: move searchbar hiding out of switch
Comment 5 Alexander Larsson 2012-11-16 15:54:28 UTC
Created attachment 229149 [details] [review]
Move most App.current_item.actor stuff to App from CollectionView

Its really confusion how this actor is modified from multiple files.
current_item is a member of App, lets manage it from there.

This just copied the code over and minimally modifies it to work.
Further commits will clean up the code.
Comment 6 Alexander Larsson 2012-11-16 15:54:31 UTC
Created attachment 229150 [details] [review]
Simplify actor fading in ui_state_changed implementation

These are all of the form if in the right state, fade in, otherwise
fade out. No need to use the switches for this.
Comment 7 Alexander Larsson 2012-11-16 15:54:35 UTC
Created attachment 229151 [details] [review]
CollectionView.ui_state_changed remove switch

No need for the big switch anymore.
Comment 8 Alexander Larsson 2012-11-16 15:54:38 UTC
Created attachment 229152 [details] [review]
Add allocate_actor_noanim herlper
Comment 9 Alexander Larsson 2012-11-16 15:54:41 UTC
Created attachment 229153 [details] [review]
App: Move shared code into position_item_actor_at_icon helper
Comment 10 Alexander Larsson 2012-11-16 15:54:44 UTC
Created attachment 229154 [details] [review]
Cleanup ui_state_changed implementations

Now that many of these are pretty small we can simplify them a bit.
For instance, most of them don't really need full switches on the
state as they just have one or two cases that are handled, which
is an excellent usecase for "if".
Comment 11 Zeeshan Ali 2012-11-16 16:15:38 UTC
Review of attachment 229145 [details] [review]:

Looks good otherwise.

::: src/properties.vala
@@ -304,2 +298,4 @@
         switch (ui_state) {
         case UIState.PROPERTIES:
+            var libvirt_machine = App.app.current_item as LibvirtMachine;
+            if (libvirt_machine != null) {

don't remember what was the agreement last we discussed this but I prefer more explicit:

if (App.app.current_item is LibvirtMachine) {
    var libvirt_machine = App.app.current_item as LibvirtMachine;
....
}

I know is more verbose but not so much as it makes things more clear/readable.
Comment 12 Zeeshan Ali 2012-11-16 16:40:30 UTC
Review of attachment 229146 [details] [review]:

Looks good
Comment 13 Zeeshan Ali 2012-11-16 16:42:02 UTC
Review of attachment 229147 [details] [review]:

ACK
Comment 14 Zeeshan Ali 2012-11-16 16:54:15 UTC
Review of attachment 229148 [details] [review]:

ACK

::: src/app.vala
@@ +560,3 @@
             set_main_ui_state ();
 
+        if (ui_state != UIState.COLLECTION)

this means that we do this now also for DISPLAY state. I guess that intentional but you might want to mention this in the commit log.
Comment 15 Zeeshan Ali 2012-11-16 17:13:10 UTC
Review of attachment 229149 [details] [review]:

ACK, though App seems to be getting very bloated. Hopefully we can clean it later.
Comment 16 Zeeshan Ali 2012-11-16 18:15:16 UTC
Review of attachment 229150 [details] [review]:

ACK
Comment 17 Zeeshan Ali 2012-11-16 18:15:57 UTC
Review of attachment 229151 [details] [review]:

ACK
Comment 18 Zeeshan Ali 2012-11-16 18:27:48 UTC
Review of attachment 229152 [details] [review]:

herlper -> helper in the commit log

Looks good otherwise.

::: src/app.vala
@@ +771,3 @@
+            allocate_actor_noanim (actor, x, y,
+                                   Machine.SCREENSHOT_WIDTH,
+                                   Machine.SCREENSHOT_WIDTH * 2);

I guess its a c&p mistake and last 2 arguments were supposed to be:

x + Machine.SCREENSHOT_WIDTH,
y + Machine.SCREENSHOT_HEIGHT * 2

?

::: src/util-app.vala
@@ +100,3 @@
 
+    // This can be used to ensure a specific initial allocation for a previously unallocated actor
+    public void allocate_actor_noanim (Clutter.Actor actor,

dont see the need to shorten "no_animation" in the name but no strong feelings.

@@ -100,1 +100,5 @@
 
+    // This can be used to ensure a specific initial allocation for a previously unallocated actor
+    public void allocate_actor_noanim (Clutter.Actor actor,
+                                       float x, float y,
+                                       float w, float h) {

w -> width, h -> height
Comment 19 Zeeshan Ali 2012-11-16 19:19:31 UTC
Review of attachment 229153 [details] [review]:

Looks like nice refactoing otherwise..

::: src/app.vala
@@ +554,3 @@
+        // We temporarily set the duration to 0 because we don't want to animate
+        // fixed_x/y, but rather immidiately set it to the target value and then
+        // animate actor.allocation which is set based on these.

where do we 'animate actor.allocation' ?
Comment 20 Zeeshan Ali 2012-11-16 19:23:05 UTC
Review of attachment 229154 [details] [review]:

what did switches ever do to you. :)
Comment 21 Alexander Larsson 2012-11-19 08:31:50 UTC
Review of attachment 229153 [details] [review]:

::: src/app.vala
@@ +554,3 @@
+        // We temporarily set the duration to 0 because we don't want to animate
+        // fixed_x/y, but rather immidiately set it to the target value and then
+        // animate actor.allocation which is set based on these.

During the layout phase the thing affecting size and position (like min_width, fixed_x/y, etc) will be used to calculate a final allocation of the actor which will be applied to the actor, just like say GtkWidget.size_allocate(). It is this rectangle we want to interpolate from the initial state to the destination state, not the individual input components of they layout system. The later will not result in a correct animation.
Comment 22 Alexander Larsson 2012-11-19 08:37:52 UTC
Created attachment 229347 [details] [review]
App.ui_state_changed: move searchbar hiding out of switch

This also sets searchbar state for the DISPLAY case, which should
not cause any change in behaviour.
Comment 23 Alexander Larsson 2012-11-19 08:37:54 UTC
Created attachment 229348 [details] [review]
Move most App.current_item.actor stuff to App from CollectionView

Its really confusion how this actor is modified from multiple files.
current_item is a member of App, lets manage it from there.

This just copied the code over and minimally modifies it to work.
Further commits will clean up the code.
Comment 24 Alexander Larsson 2012-11-19 08:37:57 UTC
Created attachment 229349 [details] [review]
Simplify actor fading in ui_state_changed implementation

These are all of the form if in the right state, fade in, otherwise
fade out. No need to use the switches for this.
Comment 25 Alexander Larsson 2012-11-19 08:38:00 UTC
Created attachment 229350 [details] [review]
CollectionView.ui_state_changed remove switch

No need for the big switch anymore.
Comment 26 Alexander Larsson 2012-11-19 08:38:03 UTC
Created attachment 229351 [details] [review]
Add allocate_actor_noanim herlper
Comment 27 Alexander Larsson 2012-11-19 08:38:06 UTC
Created attachment 229352 [details] [review]
App: Move shared code into position_item_actor_at_icon helper
Comment 28 Alexander Larsson 2012-11-19 08:38:09 UTC
Created attachment 229353 [details] [review]
Cleanup ui_state_changed implementations

Now that many of these are pretty small we can simplify them a bit.
For instance, most of them don't really need full switches on the
state as they just have one or two cases that are handled, which
is an excellent usecase for "if".
Comment 29 Alexander Larsson 2012-11-19 08:41:49 UTC
I updated all the patches wrt to the reviews except comment 11. I don't
think the verboser version is more readable. I'm perfectly willing to change it, but i don't want to do so on a "random" choice based on who is reviewing. Seems we need to either:
a) not really care which way it is
or
b) agree in the group which way we want and add it to the styleguide
Comment 30 Alexander Larsson 2012-11-19 09:57:06 UTC
Teuf also agreed (on irc) that the more explicit version is better. Thats at least 50% for the explict version, so I think we should always use that even if elmarco also agrees with me, since it seems to be the least likely to surprise people. I'll fix this patch and come up with a CodingStyle.txt patch.
Comment 31 Alexander Larsson 2012-11-19 10:02:15 UTC
Attachment 229145 [details] pushed as eb9eed6 - Properties: Avoid connecting to stats multiple times
Attachment 229146 [details] pushed as 1d003ef - Simplify status tracking
Attachment 229147 [details] pushed as 180a3f1 - App: minor ui_state_changed cleanup
Attachment 229347 [details] pushed as f5c802f - App.ui_state_changed: move searchbar hiding out of switch
Attachment 229348 [details] pushed as 102a826 - Move most App.current_item.actor stuff to App from CollectionView
Attachment 229349 [details] pushed as 6281117 - Simplify actor fading in ui_state_changed implementation
Attachment 229350 [details] pushed as b53aa59 - CollectionView.ui_state_changed remove switch
Attachment 229351 [details] pushed as ef50d47 - Add allocate_actor_noanim herlper
Attachment 229352 [details] pushed as 804c502 - App: Move shared code into position_item_actor_at_icon helper
Comment 32 Alexander Larsson 2012-11-19 10:03:29 UTC
Ugh, when i commited this i accidentally squashed the last 2 patches together. Sorry about that.