From b2b902d9a1ef08ab66f17f57fb7faa99abffc339 Mon Sep 17 00:00:00 2001 From: lenemter Date: Thu, 6 Jul 2023 01:45:46 +0900 Subject: [PATCH 1/7] Replace Confirmations --- src/Confirmation.vala | 42 +++++++++++++++++++++++++++++++++--------- src/DBus.vala | 21 +++++++++++++++++++-- 2 files changed, 52 insertions(+), 11 deletions(-) diff --git a/src/Confirmation.vala b/src/Confirmation.vala index e0b25a54..6023ec3b 100644 --- a/src/Confirmation.vala +++ b/src/Confirmation.vala @@ -22,6 +22,8 @@ public class Notifications.Confirmation : AbstractBubble { public new string icon_name { get; construct set; } public double progress { get; construct set; } + private Gtk.ProgressBar progressbar; + public Confirmation (string icon_name, double progress) { Object ( icon_name: icon_name, @@ -31,16 +33,42 @@ public class Notifications.Confirmation : AbstractBubble { } construct { + var contents = create_contents (); + content_area.add (contents); + + get_style_context ().add_class ("confirmation"); + } + + public void replace (string icon_name, double progress) { + warning ("Replacing"); + if (this.icon_name == icon_name) { + warning ("Same icon name"); + progressbar.fraction = progress; + return; + } + + this.icon_name = icon_name; + this.progress = progress; + + warning ("Creating components"); + var contents = create_contents (); + content_area.add (contents); + content_area.visible_child = contents; + } + + private Gtk.Widget create_contents () { var image = new Gtk.Image.from_icon_name (icon_name, Gtk.IconSize.DIALOG) { valign = Gtk.Align.START, - pixel_size = 48 + pixel_size = 48, + icon_name = icon_name }; - 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); @@ -49,12 +77,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; } } diff --git a/src/DBus.vala b/src/DBus.vala index 1dc2296a..9fa41675 100644 --- a/src/DBus.vala +++ b/src/DBus.vala @@ -155,6 +155,24 @@ public class Notifications.Server : Object { send_sound ("audio-volume-change"); } + // if (app_settings.get_boolean ("bubbles")) { + // if (bubbles.has_key (id) && bubbles[id] != null) { + // bubbles[id].notification = notification; + // } else { + // bubbles[id] = new Bubble (notification); + + // bubbles[id].action_invoked.connect ((action_key) => { + // action_invoked (id, action_key); + // }); + + // bubbles[id].closed.connect ((reason) => { + // closed_callback (id, reason); + // }); + // } + + // bubbles[id].present (); + // } + if (confirmation == null) { confirmation = new Notifications.Confirmation ( icon_name, @@ -164,8 +182,7 @@ public class Notifications.Server : Object { confirmation = null; }); } else { - confirmation.icon_name = icon_name; - confirmation.progress = progress_value; + confirmation.replace (icon_name, progress_value); } confirmation.present (); From b6b496f3d834c919b7fa22f06c8804668d1f54ed Mon Sep 17 00:00:00 2001 From: lenemter Date: Thu, 6 Jul 2023 01:46:43 +0900 Subject: [PATCH 2/7] Remove debug --- src/Confirmation.vala | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Confirmation.vala b/src/Confirmation.vala index 6023ec3b..6bb1193a 100644 --- a/src/Confirmation.vala +++ b/src/Confirmation.vala @@ -40,9 +40,7 @@ public class Notifications.Confirmation : AbstractBubble { } public void replace (string icon_name, double progress) { - warning ("Replacing"); if (this.icon_name == icon_name) { - warning ("Same icon name"); progressbar.fraction = progress; return; } @@ -50,7 +48,6 @@ public class Notifications.Confirmation : AbstractBubble { this.icon_name = icon_name; this.progress = progress; - warning ("Creating components"); var contents = create_contents (); content_area.add (contents); content_area.visible_child = contents; From 8371faf7ad0796babe1ae6a294c67c158d0d43bb Mon Sep 17 00:00:00 2001 From: lenemter Date: Thu, 6 Jul 2023 01:48:21 +0900 Subject: [PATCH 3/7] Remove comments --- src/DBus.vala | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/src/DBus.vala b/src/DBus.vala index 7e4c07f0..d6e917a2 100644 --- a/src/DBus.vala +++ b/src/DBus.vala @@ -152,24 +152,6 @@ public class Notifications.Server : Object { send_sound ("audio-volume-change"); } - // if (app_settings.get_boolean ("bubbles")) { - // if (bubbles.has_key (id) && bubbles[id] != null) { - // bubbles[id].notification = notification; - // } else { - // bubbles[id] = new Bubble (notification); - - // bubbles[id].action_invoked.connect ((action_key) => { - // action_invoked (id, action_key); - // }); - - // bubbles[id].closed.connect ((reason) => { - // closed_callback (id, reason); - // }); - // } - - // bubbles[id].present (); - // } - if (confirmation == null) { confirmation = new Notifications.Confirmation ( icon_name, From 5da313062c7540ff2b4e895b2d1fc75eb9fda644 Mon Sep 17 00:00:00 2001 From: lenemter Date: Thu, 6 Jul 2023 01:59:53 +0900 Subject: [PATCH 4/7] Use `confirmation_type` to distinguish confirmations --- src/Confirmation.vala | 16 ++++++++++------ src/DBus.vala | 7 ++++++- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/Confirmation.vala b/src/Confirmation.vala index 6bb1193a..e0ce8385 100644 --- a/src/Confirmation.vala +++ b/src/Confirmation.vala @@ -19,12 +19,14 @@ */ public class Notifications.Confirmation : AbstractBubble { - public new string icon_name { get; construct set; } - public double progress { get; construct set; } + public string confirmation_type { get; private construct set; } + public new string icon_name { get; private construct set; } + public double progress { get; private construct set; } + private Gtk.Image image; private Gtk.ProgressBar progressbar; - public Confirmation (string icon_name, double progress) { + public Confirmation (string confirmation_type, string icon_name, double progress) { Object ( icon_name: icon_name, progress: progress, @@ -39,12 +41,14 @@ public class Notifications.Confirmation : AbstractBubble { get_style_context ().add_class ("confirmation"); } - public void replace (string icon_name, double progress) { - if (this.icon_name == icon_name) { + 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; @@ -54,7 +58,7 @@ public class Notifications.Confirmation : AbstractBubble { } private Gtk.Widget create_contents () { - var image = new Gtk.Image.from_icon_name (icon_name, Gtk.IconSize.DIALOG) { + image = new Gtk.Image.from_icon_name (icon_name, Gtk.IconSize.DIALOG) { valign = Gtk.Align.START, pixel_size = 48, icon_name = icon_name diff --git a/src/DBus.vala b/src/DBus.vala index d6e917a2..3405760d 100644 --- a/src/DBus.vala +++ b/src/DBus.vala @@ -154,6 +154,7 @@ public class Notifications.Server : Object { if (confirmation == null) { confirmation = new Notifications.Confirmation ( + confirmation_type, icon_name, progress_value ); @@ -161,7 +162,11 @@ public class Notifications.Server : Object { confirmation = null; }); } else { - confirmation.replace (icon_name, progress_value); + confirmation.replace ( + confirmation_type, + icon_name, + progress_value + ); } confirmation.present (); From 066790db312c85eb5fed7b02145a8fb2ac288def Mon Sep 17 00:00:00 2001 From: lenemter Date: Thu, 6 Jul 2023 02:02:31 +0900 Subject: [PATCH 5/7] Fix --- src/Confirmation.vala | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Confirmation.vala b/src/Confirmation.vala index e0ce8385..c25b3eed 100644 --- a/src/Confirmation.vala +++ b/src/Confirmation.vala @@ -19,15 +19,16 @@ */ public class Notifications.Confirmation : AbstractBubble { - public string confirmation_type { get; private construct set; } - public new string icon_name { get; private construct set; } - public double progress { get; private construct set; } + public string confirmation_type { get; construct set; } + public new string icon_name { get; construct set; } + public double progress { get; construct set; } 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 @@ -60,8 +61,7 @@ public class Notifications.Confirmation : AbstractBubble { private Gtk.Widget create_contents () { image = new Gtk.Image.from_icon_name (icon_name, Gtk.IconSize.DIALOG) { valign = Gtk.Align.START, - pixel_size = 48, - icon_name = icon_name + pixel_size = 48 }; progressbar = new Gtk.ProgressBar () { From 3cb80e7e90f9885aca0c4d969b4b9a74657e3f01 Mon Sep 17 00:00:00 2001 From: lenemter Date: Sat, 8 Jul 2023 02:57:02 +0900 Subject: [PATCH 6/7] Try to use setter --- src/Confirmation.vala | 56 ++++++++++++++++++++++++------------------- src/DBus.vala | 8 +++---- 2 files changed, 35 insertions(+), 29 deletions(-) diff --git a/src/Confirmation.vala b/src/Confirmation.vala index c25b3eed..207b1585 100644 --- a/src/Confirmation.vala +++ b/src/Confirmation.vala @@ -19,12 +19,36 @@ */ public class Notifications.Confirmation : AbstractBubble { - public string confirmation_type { get; construct set; } + private string _confirmation_type; + public string confirmation_type { + get { + return _confirmation_type; + } + set { + if (value == _confirmation_type) { + return; + } + + _confirmation_type = value; + + if (icon_name_binding != null) { + icon_name_binding.unbind (); + } + if (progress_binding != null) { + progress_binding.unbind (); + } + + var contents = create_contents (); + content_area.add (contents); + content_area.visible_child = contents; + } + } + public new string icon_name { get; construct set; } public double progress { get; construct set; } - private Gtk.Image image; - private Gtk.ProgressBar progressbar; + private Binding? icon_name_binding; + private Binding? progress_binding; public Confirmation (string confirmation_type, string icon_name, double progress) { Object ( @@ -36,35 +60,16 @@ public class Notifications.Confirmation : AbstractBubble { } construct { - var contents = create_contents (); - content_area.add (contents); - get_style_context ().add_class ("confirmation"); } - 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; - } - private Gtk.Widget create_contents () { - image = new Gtk.Image.from_icon_name (icon_name, Gtk.IconSize.DIALOG) { + var image = new Gtk.Image.from_icon_name (icon_name, Gtk.IconSize.DIALOG) { valign = Gtk.Align.START, pixel_size = 48 }; - progressbar = new Gtk.ProgressBar () { + var progressbar = new Gtk.ProgressBar () { hexpand = true, valign = Gtk.Align.CENTER, margin_end = 6, @@ -80,6 +85,9 @@ public class Notifications.Confirmation : AbstractBubble { contents.attach (progressbar, 1, 0); contents.show_all (); + icon_name_binding = bind_property ("icon-name", image, "icon-name"); + progress_binding = bind_property ("progress", progressbar, "fraction"); + return contents; } } diff --git a/src/DBus.vala b/src/DBus.vala index 242e96c7..09f9de20 100644 --- a/src/DBus.vala +++ b/src/DBus.vala @@ -162,11 +162,9 @@ public class Notifications.Server : Object { confirmation = null; }); } else { - confirmation.replace ( - confirmation_type, - icon_name, - progress_value - ); + confirmation.confirmation_type = confirmation_type; + confirmation.icon_name = icon_name; + confirmation.progress = progress_value; } confirmation.present (); From ba377945a707f0d749e4c7d78fd01d5baa3bc3f4 Mon Sep 17 00:00:00 2001 From: lenemter Date: Sun, 9 Jul 2023 14:05:11 +0900 Subject: [PATCH 7/7] Review comments --- src/Confirmation.vala | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/Confirmation.vala b/src/Confirmation.vala index 207b1585..a811bcc1 100644 --- a/src/Confirmation.vala +++ b/src/Confirmation.vala @@ -19,7 +19,8 @@ */ public class Notifications.Confirmation : AbstractBubble { - private string _confirmation_type; + public new string icon_name { get; construct set; } + public double progress { get; construct set; } public string confirmation_type { get { return _confirmation_type; @@ -44,9 +45,7 @@ public class Notifications.Confirmation : AbstractBubble { } } - public new string icon_name { get; construct set; } - public double progress { get; construct set; } - + private string _confirmation_type; private Binding? icon_name_binding; private Binding? progress_binding; @@ -57,9 +56,7 @@ public class Notifications.Confirmation : AbstractBubble { progress: progress, timeout: 2000 ); - } - construct { get_style_context ().add_class ("confirmation"); }