();
construct {
button_vote.set_label (_("Vote"));
- button_vote.clicked.connect ((button) =>{
- Request voting = API.Poll.vote (accounts.active, poll.options, selected_index, poll.id);
- voting.then ((sess, mess, in_stream) => {
- var parser = Network.get_parser_from_inputstream (in_stream);
- status_parent.poll = API.Poll.from_json (typeof (API.Poll), network.parse_node (parser));
- })
- .on_error ((code, reason) => {}).exec ();
- });
+ button_vote.clicked.connect (on_vote_button_clicked);
notify["poll"].connect (update);
button_vote.sensitive = false;
}
+ private void on_vote_button_clicked (Gtk.Button button) {
+ button.sensitive = false;
+ API.Poll.vote (accounts.active, poll.options, selected_index, poll.id)
+ .then ((sess, mess, in_stream) => {
+ var parser = Network.get_parser_from_inputstream (in_stream);
+ poll = API.Poll.from_json (typeof (API.Poll), network.parse_node (parser));
+
+ button.sensitive = true;
+ })
+ .on_error ((code, reason) => {
+ var dlg = app.inform (_("Error"), reason);
+ dlg.present ();
+ button.sensitive = true;
+ })
+ .exec ();
+ }
+
public string generate_css_style (int percentage) {
return @".ttl-poll-$(percentage).ttl-poll-winner { background: linear-gradient(to right, alpha(@accent_bg_color, .5) $(percentage)%, transparent 0%); } .ttl-poll-$(percentage) { background: linear-gradient(to right, alpha(@view_fg_color, .1) $(percentage)%, transparent 0%); }"; // vala-lint=line-length
}
@@ -36,21 +41,16 @@ public class Tuba.Widgets.VoteBox: Box {
int64 winner_p = 0;
Widgets.VoteCheckButton group_radio_option = null;
- //clear all existing entries
- Widget entry = poll_box.get_first_child ();
+ // Clear all existing entries
+ Gtk.Widget entry = poll_box.get_first_child ();
while (entry != null) {
poll_box.remove (entry);
entry = poll_box.get_first_child ();
}
- //Reset button visibility
- button_vote.set_visible (false);
- if (!poll.expired && !poll.voted) {
- button_vote.set_visible (true);
- }
- // if (poll.expired) {
- // poll_box.sensitive = false;
- // }
+ // Reset button visibility
+ button_vote.visible = !poll.expired && !poll.voted;
+
if (poll.expired || poll.voted) {
foreach (API.PollOption p in poll.options) {
if (p.votes_count > winner_p) {
@@ -59,20 +59,20 @@ public class Tuba.Widgets.VoteBox: Box {
}
}
- //creates the entries of poll
+ // Create the entries of poll
foreach (API.PollOption p in poll.options) {
var row = new Adw.ActionRow () {
css_classes = { "ttl-poll-row" },
- use_markup = false
+ use_markup = false,
+ title = p.title
};
- //if it is own poll
+ // If it is own poll
if (poll.expired || poll.voted) {
// If multiple, Checkbox else radioButton
var percentage = poll.votes_count > 0 ? ((double)p.votes_count / poll.votes_count) * 100 : 0.0;
var provider = new Gtk.CssProvider ();
-
#if GTK_4_12
provider.load_from_string (generate_css_style ((int) percentage));
#else
@@ -92,15 +92,15 @@ public class Tuba.Widgets.VoteBox: Box {
foreach (int own_vote in poll.own_votes) {
if (own_vote == row_number) {
- row.add_suffix (new Image.from_icon_name ("tuba-check-round-outline-symbolic"));
+ row.add_suffix (new Gtk.Image.from_icon_name ("tuba-check-round-outline-symbolic") {
+ tooltip_text = _("Voted")
+ });
}
}
row.subtitle = "%.1f%%".printf (percentage);
- row.title = p.title;
poll_box.append (row);
} else {
- row.title = p.title;
var check_option = new Widgets.VoteCheckButton ();
if (!poll.multiple) {
@@ -112,20 +112,15 @@ public class Tuba.Widgets.VoteBox: Box {
}
check_option.poll_title = p.title;
- check_option.toggled.connect ((radio) => {
- var radio_votebutton = radio as Widgets.VoteCheckButton;
- if (selected_index.contains (radio_votebutton.poll_title)) {
- selected_index.remove (radio_votebutton.poll_title);
- } else {
- selected_index.add (radio_votebutton.poll_title);
- }
- button_vote.sensitive = selected_index.size > 0;
- });
+ check_option.toggled.connect (on_check_option_toggeled);
foreach (int own_vote in poll.own_votes) {
if (own_vote == row_number) {
- check_option.set_active (true);
- row.add_suffix (new Image.from_icon_name ("tuba-check-round-outline-symbolic"));
+ check_option.active = true;
+ row.add_suffix (new Gtk.Image.from_icon_name ("tuba-check-round-outline-symbolic") {
+ tooltip_text = _("Voted")
+ });
+
if (!selected_index.contains (p.title)) {
selected_index.add (p.title);
}
@@ -133,7 +128,7 @@ public class Tuba.Widgets.VoteBox: Box {
}
if (poll.expired || poll.voted) {
- check_option.set_sensitive (false);
+ check_option.sensitive = false;
}
row.add_prefix (check_option);
@@ -141,6 +136,7 @@ public class Tuba.Widgets.VoteBox: Box {
poll_box.append (row);
}
+
row_number++;
}
@@ -150,4 +146,15 @@ public class Tuba.Widgets.VoteBox: Box {
? DateTime.humanize_ago (poll.expires_at)
: DateTime.humanize_left (poll.expires_at);
}
+
+ private void on_check_option_toggeled (Gtk.CheckButton radio) {
+ var radio_votebutton = radio as Widgets.VoteCheckButton;
+ if (selected_index.contains (radio_votebutton.poll_title)) {
+ selected_index.remove (radio_votebutton.poll_title);
+ } else {
+ selected_index.add (radio_votebutton.poll_title);
+ }
+
+ button_vote.sensitive = selected_index.size > 0;
+ }
}
diff --git a/src/Widgets/VoteCheckButton.vala b/src/Widgets/VoteCheckButton.vala
index 120dd6ef6..cca13122f 100644
--- a/src/Widgets/VoteCheckButton.vala
+++ b/src/Widgets/VoteCheckButton.vala
@@ -1,11 +1,8 @@
-using Gtk;
-using Gdk;
-
-public class Tuba.Widgets.VoteCheckButton : CheckButton {
+public class Tuba.Widgets.VoteCheckButton : Gtk.CheckButton {
public string poll_title { get; set;}
construct {
- valign = Align.CENTER;
+ valign = Gtk.Align.CENTER;
css_classes = { "selection-mode" };
}
}
diff --git a/src/Widgets/Widgetizable.vala b/src/Widgets/Widgetizable.vala
index af8fbd6ff..36a9b1f1d 100644
--- a/src/Widgets/Widgetizable.vala
+++ b/src/Widgets/Widgetizable.vala
@@ -1,5 +1,4 @@
public interface Tuba.Widgetizable : GLib.Object {
-
public virtual Gtk.Widget to_widget () throws Oopsie {
throw new Tuba.Oopsie.INTERNAL ("Widgetizable didn't provide a Widget!");
}
@@ -7,8 +6,8 @@ public interface Tuba.Widgetizable : GLib.Object {
public virtual void open () {
warning ("Widgetizable didn't provide a way to open it!");
}
+
public virtual void resolve_open (InstanceAccount account) {
this.open ();
}
-
}
diff --git a/src/Widgets/meson.build b/src/Widgets/meson.build
index 2a3f48389..4adfe3e6c 100644
--- a/src/Widgets/meson.build
+++ b/src/Widgets/meson.build
@@ -8,7 +8,6 @@ sources += files(
'Emoji.vala',
'EmojiLabel.vala',
'LabelWithWidgets.vala',
- 'LockableToggleButton.vala',
'MarkupView.vala',
'Notification.vala',
'PreviewCard.vala',
@@ -22,3 +21,4 @@ sources += files(
)
subdir('Attachment')
+subdir('Status')
diff --git a/tests/Celebrate.test.vala b/tests/Celebrate.test.vala
index caa5745b0..093ec0a0d 100644
--- a/tests/Celebrate.test.vala
+++ b/tests/Celebrate.test.vala
@@ -1,5 +1,3 @@
-using GLib;
-
struct TestCelebrate {
public DateTime date;
public string[] css_classes;
diff --git a/tests/DateTime.test.vala b/tests/DateTime.test.vala
index 5ec573cdc..4be993cf9 100644
--- a/tests/DateTime.test.vala
+++ b/tests/DateTime.test.vala
@@ -1,5 +1,3 @@
-using GLib;
-
struct TestDate {
public string iso8601;
public string left;
diff --git a/tests/Html.test.vala b/tests/Html.test.vala
index 6fe4e46b3..f6be5bc02 100644
--- a/tests/Html.test.vala
+++ b/tests/Html.test.vala
@@ -1,5 +1,3 @@
-using GLib;
-
struct TestContent {
public string original;
public string sanitized;
@@ -16,13 +14,28 @@ const TestContent[] RESTORE_TESTS = {
};
const TestContent[] SIMPLIFY_TESTS = {
+ {
+ "Tuba\n",
+ "Tuba"
+ },
+ {
+ "Everything is going to be
okay
🐱
",
+ "Everything is going to be\nokay\n\n🐱"
+ }
+};
+
+const TestContent[] REMOVE_TAGS_TESTS = {
{
"Tuba\n",
- "Tuba"
+ "Tuba\n"
},
{
"Everything is going to be
okay
",
- "Everything is going to be\nokay\n\n"
+ "Everything is going to be\nokay\n🐱"
+ },
+ {
+ "Documentanother multi nested
end",
+ "DocumentI am an\nexampleanother multi nested one\nend"
}
};
@@ -50,11 +63,20 @@ public void test_simplify () {
}
}
+public void test_remove_tags () {
+ foreach (var test_remove_tag in REMOVE_TAGS_TESTS) {
+ var res = Tuba.HtmlUtils.remove_tags (test_remove_tag.original);
+
+ assert_cmpstr (res, CompareOperator.EQ, test_remove_tag.sanitized);
+ }
+}
+
public int main (string[] args) {
Test.init (ref args);
Test.add_func ("/test_pango", test_pango);
Test.add_func ("/test_restore", test_restore);
Test.add_func ("/test_simplify", test_simplify);
+ Test.add_func ("/test_remove_tags", test_remove_tags);
return Test.run ();
}
diff --git a/tests/Tracking.test.vala b/tests/Tracking.test.vala
index b11e3c8f2..64b66abe0 100644
--- a/tests/Tracking.test.vala
+++ b/tests/Tracking.test.vala
@@ -1,5 +1,3 @@
-using GLib;
-
struct TestUrl {
public string original;
public string result;
diff --git a/tests/Units.test.vala b/tests/Units.test.vala
index f8309b461..bb7b61703 100644
--- a/tests/Units.test.vala
+++ b/tests/Units.test.vala
@@ -1,5 +1,3 @@
-using GLib;
-
struct TestUnits {
public int64 original;
public string result;