34
34
* Does not show Uninstall Button **/
35
35
public class AppListUpdateView : AbstractAppList {
36
36
private bool updates_on_top;
37
private Widgets.UpdateHeaderRow updates_header;
38
private Widgets.UpdateHeaderRow updated_header;
39
private Widgets.AppActionButton update_all_button;
37
private Widgets.AppActionButton? update_all_button;
40
38
private bool updating_all_apps = false;
41
39
private bool apps_remaining_started = false;
42
40
private GLib.Mutex update_mutex;
62
60
updates_on_top = true;
64
update_all_button = new Widgets.AppActionButton (_("Update All"));
65
update_all_button.set_suggested_action_header ();
66
update_all_button.clicked.connect (on_update_all);
67
update_all_button.no_show_all = true;
68
action_button_group.add_widget (update_all_button);
70
updates_header = new Widgets.UpdateHeaderRow.updates ();
71
updates_header.add_widget (update_all_button);
73
updated_header = new Widgets.UpdateHeaderRow.updated ();
75
list_box.add (updates_header);
76
list_box.add (updated_header);
62
list_box.set_header_func ((Gtk.ListBoxUpdateHeaderFunc) row_update_header);
78
64
update_mutex = GLib.Mutex ();
79
65
apps_to_update = new Gee.LinkedList<AppCenterCore.Package> ();
85
71
_updating_cache = true;
88
protected override void after_add_remove_change_row () {update_headers ();}
74
protected override void after_add_remove_change_row () { list_box.invalidate_headers ();}
90
76
protected override Widgets.AppListRow make_row (AppCenterCore.Package package) {
91
77
return (Widgets.AppListRow)(new Widgets.PackageRow.installed (package, action_button_group, false));
94
80
protected override void on_package_changing (AppCenterCore.Package package, bool is_changing) {
95
81
base.on_package_changing (package, is_changing);
96
update_all_button.sensitive = packages_changing == 0;
83
if (update_all_button != null) {
84
update_all_button.sensitive = packages_changing == 0;
99
88
[CCode (instance_pos = -1)]
100
89
protected override int package_row_compare (Widgets.AppListRow row1, Widgets.AppListRow row2) {
101
90
bool a_is_header = !row1.has_package ();
102
91
bool b_is_header = !row2.has_package ();
103
93
bool a_has_updates = row1.get_update_available ();
104
94
bool b_has_updates = row2.get_update_available ();
115
105
if (a_is_os || b_is_os) { /* OS update row sorts ahead of other update rows */
116
106
return a_is_os ? -1 : 1;
117
} else if ((a_has_updates && !b_has_updates) || (!a_has_updates && b_has_updates)) { /* Updates rows sort ahead of updated rows */
109
if ((a_has_updates && !b_has_updates) || (!a_has_updates && b_has_updates)) { /* Updates rows sort ahead of updated rows */
118
110
return a_has_updates ? -1 : 1;
113
bool a_is_driver = row1.get_is_os_driver ();
114
bool b_is_driver = row2.get_is_os_driver ();
116
if ((a_is_driver && !b_is_driver) || (!a_is_driver && b_is_driver)) {
117
return a_is_driver ? -1 : 1;
121
120
return row1.get_name_label ().collate (row2.get_name_label ()); /* Else sort in name order */
123
[CCode (instance_pos = -1)]
124
private void row_update_header (Widgets.AppListRow row, Widgets.AppListRow? before) {
125
bool update_available = row.get_update_available ();
126
bool is_driver = row.get_is_os_driver ();
127
bool different = before != null && (update_available != before.get_update_available () || is_driver != before.get_is_os_driver ());
129
if (update_available) {
130
if (before == null || different) {
131
var header = new Widgets.UpdateHeaderRow.updates ();
133
uint update_numbers = 0U;
134
uint64 update_real_size = 0ULL;
135
foreach (var package in get_packages ()) {
136
if (package.update_available) {
138
update_real_size += package.change_information.get_size ();
142
header.update (update_numbers, update_real_size, updating_cache);
144
if (!updating_cache && update_numbers > 0) {
145
update_all_button = new Widgets.AppActionButton (_("Update All"));
146
update_all_button.set_suggested_action_header ();
147
update_all_button.clicked.connect (on_update_all);
148
update_all_button.no_show_all = true;
149
update_all_button.visible = !updating_cache && update_numbers > 0;
150
action_button_group.add_widget (update_all_button);
152
header.add_widget (update_all_button);
156
row.set_header (header);
158
row.set_header (null);
160
} else if (is_driver) {
161
if (before == null || different) {
162
var header = new Widgets.DriversHeaderRow ();
164
row.set_header (header);
166
row.set_header (null);
168
} else if ((before == null && !update_available) || different) {
169
var header = new Widgets.UpdateHeaderRow.updated ();
170
header.update (0, 0, updating_cache);
172
row.set_header (header);
174
row.set_header (null);
124
178
private void on_update_all () {
125
179
perform_all_updates.begin ();
226
280
return GLib.Source.REMOVE;
230
private void update_headers () {
231
/* Do not repeatedly update headers while rapidly adding packages to list */
232
schedule_header_update ();
235
uint grid_timeout_id = 0;
236
private void schedule_header_update () {
237
if (grid_timeout_id > 0) {
241
grid_timeout_id = GLib.Timeout.add (20, () => {
242
update_updates_grid ();
243
update_updated_grid ();
249
private void update_updates_grid () {
250
uint update_numbers = 0U;
251
uint64 update_real_size = 0ULL;
252
foreach (var package in get_packages ()) {
253
if (package.update_available) {
255
update_real_size += package.change_information.get_size ();
259
updates_header.update (update_numbers, update_real_size, updating_cache);
260
update_all_button.visible = !updating_cache && update_numbers > 0;
263
private void update_updated_grid () {
264
updated_header.update (0, 0, updating_cache);