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

Replace Confirmations #206

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
45 changes: 35 additions & 10 deletions src/Confirmation.vala
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,57 @@
*/

public class Notifications.Confirmation : AbstractBubble {
public string confirmation_type { get; construct set; }
public new string icon_name { get; construct set; }
public double progress { get; construct set; }

public Confirmation (string icon_name, double progress) {
private Gtk.Image image;
private Gtk.ProgressBar progressbar;

public Confirmation (string confirmation_type, string icon_name, double progress) {
Object (
confirmation_type: confirmation_type,
icon_name: icon_name,
progress: progress,
timeout: 2000
);
}

construct {
var image = new Gtk.Image.from_icon_name (icon_name, Gtk.IconSize.DIALOG) {
var contents = create_contents ();
content_area.add (contents);

get_style_context ().add_class ("confirmation");
lenemter marked this conversation as resolved.
Show resolved Hide resolved
}

public void replace (string confirmation_type, string icon_name, double progress) {
if (this.confirmation_type == confirmation_type) {
image.icon_name = icon_name;
progressbar.fraction = progress;
return;
}

this.confirmation_type = confirmation_type;
this.icon_name = icon_name;
this.progress = progress;

var contents = create_contents ();
content_area.add (contents);
content_area.visible_child = contents;
}
Marukesu marked this conversation as resolved.
Show resolved Hide resolved

private Gtk.Widget create_contents () {
image = new Gtk.Image.from_icon_name (icon_name, Gtk.IconSize.DIALOG) {
valign = Gtk.Align.START,
pixel_size = 48
};

var progressbar = new Gtk.ProgressBar () {
progressbar = new Gtk.ProgressBar () {
hexpand = true,
valign = Gtk.Align.CENTER,
margin_end = 6,
width_request = 258
width_request = 258,
fraction = progress
};
progressbar.get_style_context ().add_class (Gtk.STYLE_CLASS_FLAT);

Expand All @@ -49,12 +78,8 @@ public class Notifications.Confirmation : AbstractBubble {
};
contents.attach (image, 0, 0);
contents.attach (progressbar, 1, 0);
contents.show_all ();

content_area.add (contents);

get_style_context ().add_class ("confirmation");

bind_property ("icon-name", image, "icon-name");
bind_property ("progress", progressbar, "fraction");
return contents;
}
}
8 changes: 6 additions & 2 deletions src/DBus.vala
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,19 @@ public class Notifications.Server : Object {

if (confirmation == null) {
confirmation = new Notifications.Confirmation (
confirmation_type,
icon_name,
progress_value
);
confirmation.destroy.connect (() => {
confirmation = null;
});
} else {
confirmation.icon_name = icon_name;
confirmation.progress = progress_value;
confirmation.replace (
confirmation_type,
icon_name,
progress_value
);
}

confirmation.present ();
Expand Down