~benwaffle/appcenter/buttons

« back to all changes in this revision

Viewing changes to src/Widgets/PackageRow.vala

  • Committer: ben
  • Date: 2016-06-21 18:06:26 UTC
  • Revision ID: iofelben@gmail.com-20160621180626-8l4ccsfni54jv1gv
Fix only update buttons showing up in search results

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
    Gtk.Label package_name;
28
28
    Gtk.Label package_summary;
29
29
 
30
 
    public Gtk.Button update_button;
 
30
    // The action button covers Install and Update
 
31
    public Gtk.Button action_button;
 
32
    public Gtk.Button uninstall_button;
 
33
    Gtk.ProgressBar progress_bar;
 
34
    Gtk.Label progress_label;
31
35
    public Gtk.Button cancel_button;
32
 
    public Gtk.Stack action_stack;
33
 
    Gtk.Grid update_grid;
34
 
    Gtk.ProgressBar update_progressbar;
35
 
    Gtk.Label update_label;
 
36
    Gtk.Stack action_stack;
36
37
 
37
38
    public PackageRow (Package package) {
38
39
        this.package = package;
62
63
            image.gicon = new ThemedIcon (icon_name);
63
64
        }
64
65
 
 
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
 
65
76
        package.notify["installed"].connect (() => {
 
77
            if (package.installed && package.update_available) {
 
78
                action_button.label = _("Update");
 
79
                action_button.no_show_all = false;
 
80
            } else if (package.installed) {
 
81
                action_button.hide ();
 
82
                action_button.no_show_all = true;
 
83
            } else {
 
84
                action_button.label = _("Install");
 
85
                action_button.no_show_all = false;
 
86
                uninstall_button.no_show_all = true;
 
87
                uninstall_button.hide ();
 
88
            }
66
89
            changed ();
67
90
        });
68
91
 
69
92
        package.notify["update-available"].connect (() => {
 
93
            if (package.update_available) {
 
94
                action_button.label = _("Update");
 
95
                action_button.no_show_all = false;
 
96
                action_button.show ();
 
97
            } else {
 
98
                action_button.no_show_all = true;
 
99
                action_button.hide ();
 
100
            }
70
101
            changed ();
71
102
        });
72
103
 
100
131
        ((Gtk.Misc) package_summary).xalign = 0;
101
132
 
102
133
        action_stack = new Gtk.Stack ();
103
 
 
104
 
        update_button = new Gtk.Button.with_label (_("Update"));
105
 
        update_button.halign = Gtk.Align.END;
106
 
        update_button.valign = Gtk.Align.CENTER;
107
 
        update_button.margin_end = 6;
108
 
        update_button.clicked.connect (() => update_package.begin ());
109
 
 
110
 
        update_label = new Gtk.Label (null);
111
 
        update_progressbar = new Gtk.ProgressBar ();
112
 
        update_progressbar.margin_end = 12;
113
 
 
114
 
        cancel_button = new Gtk.Button.with_label (_("Cancel"));
 
134
        action_stack.transition_type = Gtk.StackTransitionType.CROSSFADE;
 
135
        action_stack.margin_end = 6;
 
136
 
 
137
        progress_bar = new Gtk.ProgressBar ();
 
138
 
 
139
        progress_label = new Gtk.Label (null);
 
140
 
 
141
        cancel_button = new Gtk.Button.from_icon_name ("process-stop-symbolic", Gtk.IconSize.MENU);
 
142
        cancel_button.get_style_context ().add_class (Gtk.STYLE_CLASS_FLAT);
115
143
        cancel_button.valign = Gtk.Align.CENTER;
116
 
        cancel_button.margin_end = 6;
117
 
 
118
 
        update_grid = new Gtk.Grid ();
119
 
        update_grid.attach (update_label, 0, 0, 1, 1);
120
 
        update_grid.attach (update_progressbar, 0, 1, 1, 1);
121
 
        update_grid.attach (cancel_button, 1, 0, 1, 2);
122
 
 
123
 
        action_stack.add (update_button);
124
 
        action_stack.add (update_grid);
 
144
 
 
145
        action_button = new Gtk.Button.with_label (_("Install"));
 
146
        action_button.get_style_context ().add_class (Gtk.STYLE_CLASS_SUGGESTED_ACTION);
 
147
        action_button.get_style_context ().add_class ("h3");
 
148
        action_button.clicked.connect (() => action_clicked.begin ());
 
149
 
 
150
        uninstall_button = new Gtk.Button.with_label (_("Uninstall"));
 
151
        uninstall_button.get_style_context ().add_class (Gtk.STYLE_CLASS_DESTRUCTIVE_ACTION);
 
152
        uninstall_button.get_style_context ().add_class ("h3");
 
153
        uninstall_button.clicked.connect (() => uninstall_clicked.begin ());
 
154
 
 
155
        var button_grid = new Gtk.Grid ();
 
156
        button_grid.halign = Gtk.Align.END;
 
157
        button_grid.valign = Gtk.Align.CENTER;
 
158
        button_grid.column_spacing = 12;
 
159
        button_grid.orientation = Gtk.Orientation.HORIZONTAL;
 
160
        button_grid.add (uninstall_button);
 
161
        button_grid.add (action_button);
 
162
 
 
163
        var progress_grid = new Gtk.Grid ();
 
164
        progress_grid.valign = Gtk.Align.CENTER;
 
165
        progress_grid.row_spacing = 6;
 
166
        progress_grid.attach (progress_label, 0, 0, 1, 1);
 
167
        progress_grid.attach (progress_bar, 0, 1, 1, 1);
 
168
        progress_grid.attach (cancel_button, 1, 0, 1, 2);
 
169
 
 
170
        action_stack.add_named (button_grid, "buttons");
 
171
        action_stack.add_named (progress_grid, "progress");
125
172
 
126
173
        grid.attach (image, 0, 0, 1, 2);
127
174
        grid.attach (package_name, 1, 0, 1, 1);
134
181
        });
135
182
    }
136
183
 
137
 
    private async void update_package () {
138
 
        try {
139
 
            update_button.sensitive = false;
140
 
            yield package.update ();
141
 
        } catch (Error e) {
142
 
            critical (e.message);
143
 
        }
144
 
 
145
 
        update_button.sensitive = true;
146
 
    }
147
 
 
148
184
    private void update_status () {
149
 
        update_label.label = package.change_information.get_status ();
 
185
        progress_label.label = package.change_information.get_status ();
150
186
    }
151
187
 
152
188
    private void update_progress () {
153
189
        var progress = package.change_information.get_progress ();
154
190
        if (progress < 1.0f) {
155
 
            action_stack.set_visible_child (update_grid);
156
 
            update_progressbar.fraction = progress;
 
191
            action_stack.set_visible_child_name ("progress");
 
192
            progress_bar.fraction = progress;
157
193
        } else {
158
 
            action_stack.set_visible_child (update_button);
 
194
            action_stack.set_visible_child_name ("buttons");
 
195
        }
 
196
    }
 
197
 
 
198
    private async void action_clicked () {
 
199
        try {
 
200
            if (package.update_available) {
 
201
                yield package.update ();
 
202
                action_button.no_show_all = true;
 
203
                action_button.hide ();
 
204
            } else {
 
205
                yield package.install ();
 
206
                action_button.no_show_all = true;
 
207
                action_button.hide ();
 
208
                if (package.component.id != "xxx-os-updates") {
 
209
                    uninstall_button.no_show_all = false;
 
210
                    uninstall_button.show ();
 
211
                }
 
212
            }
 
213
        } catch (Error e) {
 
214
            critical (e.message);
 
215
            action_stack.set_visible_child_name ("buttons");
 
216
        }
 
217
    }
 
218
 
 
219
    private async void uninstall_clicked () {
 
220
        try {
 
221
            yield package.uninstall ();
 
222
            action_button.label = _("Install");
 
223
            uninstall_button.no_show_all = true;
 
224
            uninstall_button.hide ();
 
225
            action_button.no_show_all = false;
 
226
            action_button.show ();
 
227
        } catch (Error e) {
 
228
            critical (e.message);
 
229
            action_stack.set_visible_child_name ("buttons");
159
230
        }
160
231
    }
161
232
}