Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 15 additions & 26 deletions src/Core/ChangeInformation.vala
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,6 @@ public class AppCenterCore.ChangeInformation : Object {
FINISHED
}

/**
* This signal is likely to be fired from a non-main thread. Ensure any UI
* logic driven from this runs on the GTK thread
*/
public signal void status_changed ();

/**
* This signal is likely to be fired from a non-main thread. Ensure any UI
* logic driven from this runs on the GTK thread
*/
public signal void progress_changed ();

public Gee.ArrayList<string> updatable_packages { get; private set; }

public ActionGroup action_group { get; private set; }
Expand Down Expand Up @@ -75,15 +63,12 @@ public class AppCenterCore.ChangeInformation : Object {
progress = 0.0f;
status = Status.WAITING;
status_description = _("Waiting");
status_changed ();
progress_changed ();
}

public void complete () {
cancel_action.set_enabled (false);
status = Status.FINISHED;
status_description = _("Finished");
status_changed ();
reset_progress ();
}

Expand All @@ -92,7 +77,6 @@ public class AppCenterCore.ChangeInformation : Object {
cancel_action.set_enabled (false);
status = Status.CANCELLED;
status_description = _("Cancelling");
status_changed ();
}

public void clear_update_info () {
Expand All @@ -106,16 +90,21 @@ public class AppCenterCore.ChangeInformation : Object {
progress = 0.0f;
}

/**
* This method is thread safe. It will queue any updates on the main thread.
*/
public void callback (string status_description, double progress, Status status) {
if (this.status_description != status_description || this.status != status) {
this.status_description = status_description;
this.status = status;
status_changed ();
}

if (this.progress != progress) {
this.progress = progress;
progress_changed ();
}
Idle.add (() => {
if (this.status_description != status_description || this.status != status) {
this.status_description = status_description;
this.status = status;
}

if (this.progress != progress) {
this.progress = progress;
}

return Source.REMOVE;
});
}
}
10 changes: 0 additions & 10 deletions src/Core/Package.vala
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,6 @@ public class AppCenterCore.Package : Object {
}
}

public bool changes_finished {
get {
return change_information.status == ChangeInformation.Status.FINISHED;
}
}

public bool is_runtime_updates {
get {
return component.id == RUNTIME_UPDATES_ID;
Expand Down Expand Up @@ -601,10 +595,6 @@ public class AppCenterCore.Package : Object {
return summary;
}

public string get_progress_description () {
return change_information.status_description;
}

public GLib.Icon get_icon (uint size, uint scale_factor) {
GLib.Icon? icon = null;
uint current_size = 0;
Expand Down
26 changes: 2 additions & 24 deletions src/Widgets/ProgressButton.vala
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,14 @@ public class AppCenter.ProgressButton : Gtk.Button {
add_css_class ("progress");
add_css_class ("text-button");

package.change_information.progress_changed.connect (update_progress);
package.change_information.status_changed.connect (update_progress_status);

update_progress_status ();
update_progress ();
package.change_information.bind_property ("status-description", this, "tooltip-text", SYNC_CREATE);

var cancel_label = new Gtk.Label (_("Cancel")) {
mnemonic_widget = this
};

progressbar = new Gtk.ProgressBar ();
package.change_information.bind_property ("progress", progressbar, "fraction", SYNC_CREATE);

var box = new Gtk.Box (VERTICAL, 0);
box.append (cancel_label);
Expand All @@ -39,23 +36,4 @@ public class AppCenter.ProgressButton : Gtk.Button {
action_name = ACTION_PREFIX + AppCenterCore.ChangeInformation.CANCEL_ACTION_NAME;
insert_action_group (ACTION_GROUP_PREFIX, package.change_information.action_group);
}

private void update_progress () {
Idle.add (() => {
progressbar.fraction = package.progress;
return GLib.Source.REMOVE;
});
}

private void update_progress_status () {
Idle.add (() => {
tooltip_text = package.get_progress_description ();
/* Ensure progress bar shows complete to match status (lp:1606902) */
if (package.changes_finished) {
progressbar.fraction = 1.0f;
}

return GLib.Source.REMOVE;
});
}
}