Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AppInfoView: move uninstall button here #1855

Merged
merged 4 commits into from
May 25, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 55 additions & 10 deletions src/Views/AppInfoView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ namespace AppCenter.Views {
private ArrowButton screenshot_previous;
private Gtk.FlowBox oars_flowbox;
private Gtk.Revealer oars_flowbox_revealer;
private Gtk.Revealer uninstall_button_revealer;

private bool is_runtime_warning_shown = false;

Expand Down Expand Up @@ -88,10 +89,6 @@ namespace AppCenter.Views {
cancel_button_context.add_class (Gtk.STYLE_CLASS_SUGGESTED_ACTION);
cancel_button_context.add_provider (banner_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);

unowned var uninstall_button_context = uninstall_button.get_style_context ();
uninstall_button_context.add_class (Gtk.STYLE_CLASS_SUGGESTED_ACTION);
uninstall_button_context.add_provider (banner_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);

var package_component = package.component;

var drugs = new ContentType (
Expand Down Expand Up @@ -595,9 +592,28 @@ namespace AppCenter.Views {
origin_combo.pack_start (renderer, true);
origin_combo.add_attribute (renderer, "text", 1);

action_stack.valign = Gtk.Align.END;
action_stack.halign = Gtk.Align.END;
action_stack.hexpand = true;
var uninstall_button = new Gtk.Button.with_label (_("Uninstall")) {
margin_end = 12
};

unowned var uninstall_button_context = uninstall_button.get_style_context ();
uninstall_button_context.add_class (Gtk.STYLE_CLASS_SUGGESTED_ACTION);
uninstall_button_context.add_provider (banner_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);

uninstall_button_revealer = new Gtk.Revealer () {
transition_type = Gtk.RevealerTransitionType.SLIDE_LEFT
};
uninstall_button_revealer.add (uninstall_button);

action_button_group.add_widget (uninstall_button);

var button_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0) {
halign = Gtk.Align.END,
valign = Gtk.Align.END,
hexpand = true
};
button_box.add (uninstall_button_revealer);
button_box.add (action_stack);

var header_grid = new Gtk.Grid () {
column_spacing = 12,
Expand All @@ -608,7 +624,7 @@ namespace AppCenter.Views {
header_grid.attach (package_name, 1, 0);
header_grid.attach (author_label, 1, 1);
header_grid.attach (origin_combo_revealer, 1, 2, 3);
header_grid.attach (action_stack, 3, 0);
header_grid.attach (button_box, 3, 0);

if (!package.is_local) {
size_label = new Widgets.SizeLabel () {
Expand Down Expand Up @@ -719,6 +735,8 @@ namespace AppCenter.Views {
}
});

uninstall_button.clicked.connect (() => uninstall_clicked.begin ());

realize.connect (load_more_content);
}

Expand All @@ -727,8 +745,19 @@ namespace AppCenter.Views {
size_label.update ();
}

if (package.state == AppCenterCore.Package.State.NOT_INSTALLED) {
get_app_download_size.begin ();
switch (package.state) {
case AppCenterCore.Package.State.NOT_INSTALLED:
get_app_download_size.begin ();
uninstall_button_revealer.reveal_child = false;
break;
case AppCenterCore.Package.State.INSTALLED:
uninstall_button_revealer.reveal_child = !package.is_os_updates && !package.is_compulsory;
break;
case AppCenterCore.Package.State.UPDATE_AVAILABLE:
uninstall_button_revealer.reveal_child = !package.is_os_updates && !package.is_compulsory;
break;
default:
break;
}

update_action ();
Expand Down Expand Up @@ -1077,6 +1106,22 @@ namespace AppCenter.Views {
}
}

private async void uninstall_clicked () {
package.uninstall.begin ((obj, res) => {
try {
if (package.uninstall.end (res)) {
MainWindow.installed_view.remove_app.begin (package);
}
} catch (Error e) {
// Disable error dialog for if user clicks cancel. Reason: Failed to obtain authentication
// Pk ErrorEnums are mapped to the error code at an offset of 0xFF (see packagekit-glib2/pk-client.h)
if (!(e is Pk.ClientError) || e.code != Pk.ErrorEnum.NOT_AUTHORIZED + 0xFF) {
new UninstallFailDialog (package, e).present ();
}
}
});
}

class UrlButton : Gtk.Grid {
public UrlButton (string label, string? uri, string icon_name) {
get_style_context ().add_class (Gtk.STYLE_CLASS_DIM_LABEL);
Expand Down
35 changes: 0 additions & 35 deletions src/Widgets/AppContainers/AbstractAppContainer.vala
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,17 @@
namespace AppCenter {
public abstract class AbstractAppContainer : Gtk.Bin {
public AppCenterCore.Package package { get; construct set; }
protected bool show_uninstall { get; set; default = true; }
protected bool show_open { get; set; default = true; }

protected Widgets.HumbleButton action_button;
protected Gtk.Button open_button;
protected Gtk.Button uninstall_button { get; private set; }

protected Gtk.Grid button_grid;
protected ProgressButton cancel_button;
protected Gtk.SizeGroup action_button_group;
protected Gtk.Stack action_stack;

private Gtk.Revealer action_button_revealer;
private Gtk.Revealer open_button_revealer;
private Gtk.Revealer uninstall_button_revealer;

private uint state_source = 0U;

Expand All @@ -57,16 +53,6 @@ namespace AppCenter {
action_clicked.begin ();
});

uninstall_button = new Gtk.Button.with_label (_("Uninstall")) {
margin_end = 12
};

uninstall_button_revealer = new Gtk.Revealer ();
uninstall_button_revealer.transition_type = Gtk.RevealerTransitionType.SLIDE_LEFT;
uninstall_button_revealer.add (uninstall_button);

uninstall_button.clicked.connect (() => uninstall_clicked.begin ());

open_button = new Gtk.Button.with_label (_("Open"));

open_button_revealer = new Gtk.Revealer ();
Expand All @@ -76,7 +62,6 @@ namespace AppCenter {
open_button.clicked.connect (launch_package_app);

button_grid = new Gtk.Grid ();
button_grid.add (uninstall_button_revealer);
button_grid.add (action_button_revealer);
button_grid.add (open_button_revealer);

Expand All @@ -87,7 +72,6 @@ namespace AppCenter {

action_button_group = new Gtk.SizeGroup (Gtk.SizeGroupMode.HORIZONTAL);
action_button_group.add_widget (action_button);
action_button_group.add_widget (uninstall_button);
action_button_group.add_widget (cancel_button);
action_button_group.add_widget (open_button);

Expand Down Expand Up @@ -206,13 +190,11 @@ namespace AppCenter {
action_button.amount = 0;
}

uninstall_button_revealer.reveal_child = false;
action_button_revealer.reveal_child = !package.is_os_updates;
open_button_revealer.reveal_child = false;

break;
case AppCenterCore.Package.State.INSTALLED:
uninstall_button_revealer.reveal_child = show_uninstall && !package.is_os_updates && !package.is_compulsory;
action_button_revealer.reveal_child = package.should_pay && updates_view;
open_button_revealer.reveal_child = show_open && package.get_can_launch ();

Expand All @@ -225,7 +207,6 @@ namespace AppCenter {
action_button.amount = 0;
}

uninstall_button_revealer.reveal_child = show_uninstall && !package.is_os_updates && !package.is_compulsory;
action_button_revealer.reveal_child = true;
open_button_revealer.reveal_child = false;

Expand Down Expand Up @@ -293,21 +274,5 @@ namespace AppCenter {
}
}
}

private async void uninstall_clicked () {
package.uninstall.begin ((obj, res) => {
try {
if (package.uninstall.end (res)) {
MainWindow.installed_view.remove_app.begin (package);
}
} catch (Error e) {
// Disable error dialog for if user clicks cancel. Reason: Failed to obtain authentication
// Pk ErrorEnums are mapped to the error code at an offset of 0xFF (see packagekit-glib2/pk-client.h)
if (!(e is Pk.ClientError) || e.code != Pk.ErrorEnum.NOT_AUTHORIZED + 0xFF) {
new UninstallFailDialog (package, e).present ();
}
}
});
}
}
}
1 change: 0 additions & 1 deletion src/Widgets/AppContainers/AbstractPackageRowGrid.vala
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ public abstract class AppCenter.Widgets.AbstractPackageRowGrid : AbstractAppCont
margin_start = 12;
margin_end = 12;

show_uninstall = false;
show_open = false;
}
}