~donadigo/appcenter/drivers-2

« back to all changes in this revision

Viewing changes to src/Views/AppListView.vala

  • Committer: Adam Bieńkowski
  • Date: 2017-02-15 22:11:52 UTC
  • Revision ID: donadigos159@gmail.com-20170215221152-5c99h6nuf2f5rjha
Show drivers in the installed page

Show diffs side-by-side

added added

removed removed

Lines of Context:
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;
53
51
            set {
54
52
                if (_updating_cache != value) {
55
53
                    _updating_cache = value;
56
 
                    update_headers ();
 
54
                    list_box.invalidate_headers ();
57
55
                }
58
56
            }
59
57
        }
61
59
        construct {
62
60
            updates_on_top = true;
63
61
 
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);
69
 
 
70
 
            updates_header = new Widgets.UpdateHeaderRow.updates ();
71
 
            updates_header.add_widget (update_all_button);
72
 
 
73
 
            updated_header = new Widgets.UpdateHeaderRow.updated ();
74
 
 
75
 
            list_box.add (updates_header);
76
 
            list_box.add (updated_header);
 
62
            list_box.set_header_func ((Gtk.ListBoxUpdateHeaderFunc) row_update_header);
77
63
 
78
64
            update_mutex = GLib.Mutex ();
79
65
            apps_to_update = new Gee.LinkedList<AppCenterCore.Package> ();
85
71
            _updating_cache = true;
86
72
        }
87
73
 
88
 
        protected override void after_add_remove_change_row () {update_headers ();}
 
74
        protected override void after_add_remove_change_row () { list_box.invalidate_headers ();}
89
75
 
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));
93
79
 
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;
 
82
 
 
83
            if (update_all_button != null) {
 
84
                update_all_button.sensitive = packages_changing == 0;
 
85
            }
97
86
        }
98
87
 
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 ();
 
92
 
103
93
            bool a_has_updates = row1.get_update_available ();
104
94
            bool b_has_updates = row2.get_update_available ();
105
95
 
114
104
 
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 */
 
107
            }
 
108
 
 
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;
119
111
            }
120
112
 
 
113
            bool a_is_driver = row1.get_is_os_driver ();
 
114
            bool b_is_driver = row2.get_is_os_driver ();
 
115
 
 
116
            if ((a_is_driver && !b_is_driver) || (!a_is_driver && b_is_driver)) {
 
117
                return a_is_driver ? -1 : 1;
 
118
            }
 
119
 
121
120
            return row1.get_name_label ().collate (row2.get_name_label ()); /* Else sort in name order */
122
121
        }
123
122
 
 
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 ());
 
128
 
 
129
            if (update_available) {
 
130
                if (before == null || different) {
 
131
                    var header = new Widgets.UpdateHeaderRow.updates ();
 
132
 
 
133
                    uint update_numbers = 0U;
 
134
                    uint64 update_real_size = 0ULL;
 
135
                    foreach (var package in get_packages ()) {
 
136
                        if (package.update_available) {
 
137
                            update_numbers++;
 
138
                            update_real_size += package.change_information.get_size ();
 
139
                        }
 
140
                    }
 
141
 
 
142
                    header.update (update_numbers, update_real_size, updating_cache);
 
143
 
 
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);
 
151
 
 
152
                        header.add_widget (update_all_button);   
 
153
                    }
 
154
 
 
155
                    header.show_all ();
 
156
                    row.set_header (header);                
 
157
                } else {
 
158
                    row.set_header (null);
 
159
                }
 
160
            } else if (is_driver) {
 
161
                if (before == null || different) {
 
162
                    var header = new Widgets.DriversHeaderRow ();
 
163
                    header.show_all ();
 
164
                    row.set_header (header);
 
165
                } else {
 
166
                    row.set_header (null);
 
167
                }
 
168
            } else if ((before == null && !update_available) || different) {
 
169
                var header = new Widgets.UpdateHeaderRow.updated ();
 
170
                header.update (0, 0, updating_cache);
 
171
                header.show_all ();
 
172
                row.set_header (header);              
 
173
            } else {
 
174
                row.set_header (null);
 
175
            }
 
176
        }
 
177
 
124
178
        private void on_update_all () {
125
179
            perform_all_updates.begin ();
126
180
        }
226
280
                return GLib.Source.REMOVE;
227
281
            });
228
282
        }
229
 
 
230
 
        private void update_headers () {
231
 
            /* Do not repeatedly update headers while rapidly adding packages to list */
232
 
            schedule_header_update ();
233
 
        }
234
 
 
235
 
        uint grid_timeout_id = 0;
236
 
        private void schedule_header_update () {
237
 
            if (grid_timeout_id > 0) {
238
 
                return;
239
 
            }
240
 
 
241
 
            grid_timeout_id = GLib.Timeout.add (20, () => {
242
 
                update_updates_grid ();
243
 
                update_updated_grid ();
244
 
                grid_timeout_id = 0;
245
 
                return false;
246
 
            });
247
 
        }
248
 
 
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) {
254
 
                    update_numbers++;
255
 
                    update_real_size += package.change_information.get_size ();
256
 
                }
257
 
            }
258
 
 
259
 
            updates_header.update (update_numbers, update_real_size, updating_cache);
260
 
            update_all_button.visible = !updating_cache && update_numbers > 0;
261
 
        }
262
 
 
263
 
        private void update_updated_grid () {
264
 
            updated_header.update (0, 0, updating_cache);
265
 
        }
266
283
    }
267
284
}