~donadigo/appcenter/fix-app-installation

« back to all changes in this revision

Viewing changes to src/Views/AppInfoView.vala

  • Committer: RabbitBot
  • Author(s): donadigos159 at gmail
  • Date: 2016-07-12 15:49:07 UTC
  • mfrom: (235.1.7 appcenter)
  • Revision ID: rabbitbot-20160712154907-frltbdvkx4gp9rnw
- Rework action buttons frontend.
- Fix incorrect action label on update page.
- Remove unneded code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
using AppCenterCore;
22
22
 
23
23
public class AppCenter.Views.AppInfoView : Gtk.Grid {
24
 
    AppCenterCore.Package package;
 
24
    Package package;
25
25
 
26
26
    Gtk.Image app_icon;
27
27
    Gtk.Image app_screenshot;
41
41
    Gtk.Button cancel_button;
42
42
    Gtk.Stack action_stack;
43
43
 
44
 
    public AppInfoView (AppCenterCore.Package package) {
 
44
    bool is_os_updates = false;
 
45
 
 
46
    public AppInfoView (Package package) {
45
47
        this.package = package;
46
48
        app_name.label = package.get_name ();
47
49
        app_summary.label = package.get_summary ();
48
50
        parse_description (package.component.get_description ());
49
51
        app_icon.gicon = package.get_icon (128);
 
52
        is_os_updates = package.component.id == "xxx-os-updates";
50
53
 
51
54
        if (package.component.get_extensions ().length > 0) {
52
55
            extension_box = new Gtk.ListBox ();
63
66
            load_extensions.begin ();
64
67
        }
65
68
 
66
 
        if (package.update_available) {
67
 
            action_button.label = _("Update");
68
 
        } else if (package.installed) {
69
 
            action_button.no_show_all = true;
70
 
            action_button.hide ();
71
 
        } else {
72
 
            uninstall_button.no_show_all = true;
73
 
            uninstall_button.hide ();
74
 
        }
75
 
 
76
 
        if (package.component.id == "xxx-os-updates") {
77
 
            uninstall_button.no_show_all = true;
78
 
            uninstall_button.hide ();
79
 
        }
80
 
 
81
 
        package.notify["installed"].connect (() => update_buttons ());
82
 
        package.notify["update-available"].connect (() => update_buttons ());
 
69
        package.notify["state"].connect (update_state);
83
70
 
84
71
        package.change_information.bind_property ("can-cancel", cancel_button, "sensitive", GLib.BindingFlags.SYNC_CREATE);
85
 
        package.change_information.progress_changed.connect (() => update_progress ());
86
 
        package.change_information.status_changed.connect (() => update_status ());
 
72
        package.change_information.progress_changed.connect (update_progress);
 
73
        package.change_information.status_changed.connect (update_progress_status);
 
74
 
 
75
        update_progress_status (); 
87
76
        update_progress ();
88
 
        update_status ();
 
77
        update_state ();
89
78
    }
90
79
 
91
80
    construct {
234
223
    }
235
224
 
236
225
    public void load_more_content () {
237
 
        new Thread<void*> ("content loading", () => {
 
226
        new Thread<void*> ("content-loading", () => {
238
227
            string url = null;
239
228
            uint max_size = 0U;
240
229
            package.component.get_screenshots ().foreach ((screenshot) => {
256
245
        });
257
246
    }
258
247
 
259
 
    private void update_status () {
260
 
        progress_bar.text = package.change_information.get_status ();
261
 
        if (package.change_information.status == Pk.Status.FINISHED) {
262
 
            action_stack.set_visible_child_name ("buttons");
263
 
        } else {
264
 
            action_stack.set_visible_child_name ("progress");
265
 
        }         
 
248
    private void update_progress_status () {
 
249
        progress_bar.text = package.change_information.get_status ();      
266
250
    }
267
251
 
268
252
    private void update_progress () {
269
 
        var progress = package.change_information.get_progress ();
 
253
        double progress = package.change_information.get_progress ();
270
254
        if (progress < 1.0f) {
271
 
            action_stack.set_visible_child_name ("progress");
272
255
            progress_bar.fraction = progress;
 
256
        }
 
257
    }
 
258
 
 
259
    private void update_state () {
 
260
        if (package.state != Package.State.NOT_INSTALLED && !is_os_updates) {
 
261
            uninstall_button.no_show_all = false;
 
262
            uninstall_button.show_all ();               
273
263
        } else {
274
 
            action_stack.set_visible_child_name ("buttons");
 
264
            uninstall_button.no_show_all = true;
 
265
            uninstall_button.hide ();
275
266
        }
276
 
    }
277
 
 
278
 
    private void update_buttons () {
279
 
        if (package.installed) {
280
 
            if (package.update_available) {
 
267
 
 
268
        switch (package.state) {
 
269
            case Package.State.NOT_INSTALLED:
 
270
                action_button.label = _("Install");
 
271
                action_button.no_show_all = false;
 
272
                action_button.show_all ();
 
273
 
 
274
                action_stack.set_visible_child_name ("buttons");
 
275
                break;
 
276
            case Package.State.INSTALLED:
 
277
                action_button.no_show_all = true;
 
278
                action_button.hide ();
 
279
 
 
280
                action_stack.set_visible_child_name ("buttons");
 
281
                break;
 
282
            case Package.State.UPDATE_AVAILABLE:
281
283
                action_button.label = _("Update");
282
284
                action_button.no_show_all = false;
283
 
                action_button.show_all ();                
284
 
            } else {
285
 
                action_button.no_show_all = true;
286
 
                action_button.hide ();                   
287
 
                uninstall_button.no_show_all = false;
288
 
                uninstall_button.show_all ();                
289
 
            }
290
 
        } else {
291
 
            action_button.label = _("Install");
292
 
            action_button.no_show_all = false;
293
 
            action_button.show_all ();
294
 
        }
 
285
                action_button.show_all ();    
 
286
 
 
287
                action_stack.set_visible_child_name ("buttons");
 
288
                break;
 
289
            case Package.State.INSTALLING:
 
290
            case Package.State.UPDATING:
 
291
            case Package.State.REMOVING:
 
292
                action_stack.set_visible_child_name ("progress");
 
293
                break;
 
294
        }        
295
295
    }
296
296
 
297
297
    private void action_cancelled () {
302
302
        try {
303
303
            if (package.update_available) {
304
304
                yield package.update ();
305
 
                action_button.no_show_all = true;
306
 
                action_button.hide ();
307
305
            } else {
308
306
                yield package.install ();
309
 
                action_button.no_show_all = true;
310
 
                action_button.hide ();
311
 
                if (package.component.id != "xxx-os-updates") {
312
 
                    uninstall_button.no_show_all = false;
313
 
                    uninstall_button.show_all ();
314
 
                }
315
 
                
 
307
 
316
308
                // Add this app to the Installed Apps View
317
309
                MainWindow.installed_view.add_app.begin (package);
318
310
            }
319
311
        } catch (Error e) {
320
312
            critical (e.message);
321
 
            action_stack.set_visible_child_name ("buttons");
322
313
        }
323
314
    }
324
315
 
325
316
    private async void uninstall_clicked () {
326
317
        try {
327
318
            yield package.uninstall ();
328
 
            action_button.label = _("Install");
329
 
            uninstall_button.no_show_all = true;
330
 
            uninstall_button.hide ();
331
319
 
332
320
            // Remove this app from the Installed Apps View
333
321
            MainWindow.installed_view.remove_app.begin (package);
334
322
        } catch (Error e) {
335
323
            critical (e.message);
336
 
            action_stack.set_visible_child_name ("buttons");
337
324
        }
338
325
    }
339
326
 
382
369
    }
383
370
 
384
371
    private void parse_description (string? description) {
385
 
        if (description != null)
 
372
        if (description != null) {
386
373
            app_description.buffer.text = AppStream.description_markup_convert_simple (description);
 
374
        }
387
375
    }
388
376
}