~donadigo/appcenter/fix-app-installation

« back to all changes in this revision

Viewing changes to src/Widgets/PackageRow.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:
40
40
        package_summary.ellipsize = Pango.EllipsizeMode.END;
41
41
        image.gicon = package.get_icon ();
42
42
 
43
 
        if (package.update_available) {
44
 
            action_button.label = _("Update");
45
 
        } else if (package.installed) {
46
 
            action_stack.no_show_all = true;
47
 
            action_stack.hide ();
48
 
        }
49
 
 
50
 
        package.notify["installed"].connect (() => update_buttons ());
51
 
        package.notify["update-available"].connect (() => update_buttons ());
 
43
        package.notify["state"].connect (update_state);
52
44
 
53
45
        package.change_information.bind_property ("can-cancel", cancel_button, "sensitive", GLib.BindingFlags.SYNC_CREATE);
54
 
        package.change_information.progress_changed.connect (() => update_progress ());
55
 
        package.change_information.status_changed.connect (() => update_status ());
 
46
        package.change_information.progress_changed.connect (update_progress);
 
47
        package.change_information.status_changed.connect (update_progress_status);
 
48
 
 
49
        update_progress_status (); 
56
50
        update_progress ();
57
 
        update_status ();
 
51
        update_state ();
58
52
    }
59
53
 
60
54
    construct {
115
109
        add (grid);
116
110
    }
117
111
 
118
 
    private void update_status () {
 
112
    private void update_progress_status () {
119
113
        progress_bar.text = package.change_information.get_status ();
120
 
        if (package.change_information.status == Pk.Status.FINISHED) {
121
 
            action_stack.set_visible_child_name ("buttons");
122
 
        } else {
123
 
            action_stack.set_visible_child_name ("progress");   
124
 
            action_stack.no_show_all = false;
125
 
            action_stack.show_all ();   
126
 
        }        
127
114
    }
128
115
 
129
116
    private void update_progress () {
130
 
        var progress = package.change_information.get_progress ();
 
117
        double progress = package.change_information.get_progress ();
131
118
        if (progress < 1.0f) {
132
 
            action_stack.set_visible_child_name ("progress");
133
119
            progress_bar.fraction = progress;
134
 
            action_stack.no_show_all = false;
135
 
            action_stack.show_all ();               
136
 
        } else {
137
 
            action_stack.set_visible_child_name ("buttons");
138
120
        }
139
121
    }
140
122
 
141
 
    private void update_buttons () {
142
 
        if (package.installed) {
143
 
            if (package.update_available) {
 
123
    private void update_state () {
 
124
        switch (package.state) {
 
125
            case Package.State.NOT_INSTALLED:
 
126
                action_button.label = _("Install");
 
127
                action_button.no_show_all = false;
 
128
                action_button.show_all ();
 
129
 
 
130
                action_stack.no_show_all = false;
 
131
                action_stack.show_all ();
 
132
 
 
133
                action_stack.set_visible_child_name ("buttons");
 
134
                break;
 
135
            case Package.State.INSTALLED:
 
136
                action_stack.no_show_all = true;
 
137
                action_stack.hide ();                
 
138
 
 
139
                action_stack.set_visible_child_name ("buttons");
 
140
                break;
 
141
            case Package.State.UPDATE_AVAILABLE:
144
142
                action_button.label = _("Update");
145
143
                action_button.no_show_all = false;
146
144
                action_button.show_all ();    
147
145
 
148
146
                action_stack.no_show_all = false;
149
147
                action_stack.show_all ();
150
 
            } else {
151
 
                action_stack.no_show_all = true;
152
 
                action_stack.hide ();
153
 
            }
154
 
        } else {
155
 
            action_button.label = _("Install");
156
 
            action_button.no_show_all = false;
157
 
            action_button.show_all ();
158
 
 
159
 
            action_stack.no_show_all = false;
160
 
            action_stack.show_all ();                
161
 
        }
162
 
 
163
 
        changed ();        
 
148
 
 
149
                action_stack.set_visible_child_name ("buttons");
 
150
                break;
 
151
            case Package.State.INSTALLING:
 
152
            case Package.State.UPDATING:
 
153
            case Package.State.REMOVING:
 
154
                action_stack.no_show_all = false;
 
155
                action_stack.show_all ();
 
156
 
 
157
                action_stack.set_visible_child_name ("progress");
 
158
                break;
 
159
        }  
 
160
 
 
161
        changed ();
164
162
    }
165
163
 
166
164
    private void action_cancelled () {
173
171
                yield package.update ();
174
172
            } else {
175
173
                yield package.install ();
 
174
 
 
175
                // Add this app to the Installed Apps View
 
176
                MainWindow.installed_view.add_app.begin (package);
176
177
            }
177
 
            action_stack.no_show_all = true;
178
 
            action_stack.hide ();
179
178
        } catch (Error e) {
180
179
            critical (e.message);
181
 
            action_stack.set_visible_child_name ("buttons");
182
180
        }
183
181
    }
184
182
}