From f6b37d9dd669c4b3c8234a141b03e4a32a09fa23 Mon Sep 17 00:00:00 2001 From: bleakgrey Date: Sun, 15 Apr 2018 14:29:55 +0300 Subject: [PATCH] Add toot visibility button --- meson.build | 1 + src/API/Status.vala | 22 ------------ src/API/StatusVisibility.vala | 52 ++++++++++++++++++++++++++++ src/Dialogs/DialogToot.vala | 61 +++++++++++++++++++++++++++++---- src/Widgets/AccountsButton.vala | 14 ++++---- 5 files changed, 114 insertions(+), 36 deletions(-) create mode 100644 src/API/StatusVisibility.vala diff --git a/meson.build b/meson.build index 1194c4b..d033882 100644 --- a/meson.build +++ b/meson.build @@ -26,6 +26,7 @@ executable( 'src/CacheManager.vala', 'src/API/Account.vala', 'src/API/Status.vala', + 'src/API/StatusVisibility.vala', 'src/Widgets/AlignedLabel.vala', 'src/Widgets/AccountsButton.vala', 'src/Widgets/StatusWidget.vala', diff --git a/src/API/Status.vala b/src/API/Status.vala index 1f1e1af..abcbd18 100644 --- a/src/API/Status.vala +++ b/src/API/Status.vala @@ -10,28 +10,6 @@ public class Tootle.Status{ public string avatar; public string acct; - enum Visibility { - PUBLIC, - UNLISTED, - PRIVATE, - DIRECT; - - public string to_string() { - switch (this) { - case PUBLIC: - return "public"; - case UNLISTED: - return "unlisted"; - case PRIVATE: - return "private"; - case DIRECT: - return "direct"; - default: - assert_not_reached(); - } - } - } - public Status(int64 id) { this.id = id; } diff --git a/src/API/StatusVisibility.vala b/src/API/StatusVisibility.vala new file mode 100644 index 0000000..1e9e199 --- /dev/null +++ b/src/API/StatusVisibility.vala @@ -0,0 +1,52 @@ +public enum Tootle.StatusVisibility { + PUBLIC, + UNLISTED, + PRIVATE, + DIRECT; + + public string to_string() { + switch (this) { + case PUBLIC: + return "public"; + case UNLISTED: + return "unlisted"; + case PRIVATE: + return "private"; + case DIRECT: + return "direct"; + default: + assert_not_reached(); + } + } + + public string get_desc() { + switch (this) { + case PUBLIC: + return _("Post to public timelines"); + case UNLISTED: + return _("Don\'t post to public timelines"); + case PRIVATE: + return _("Post to followers only"); + case DIRECT: + return _("Post to mentioned users only"); + default: + assert_not_reached(); + } + } + + public string get_icon() { + switch (this) { + case PUBLIC: + return "network-workgroup-symbolic"; + case UNLISTED: + return "security-medium-symbolic"; + case PRIVATE: + return "security-high-symbolic"; + case DIRECT: + return "user-available-symbolic"; + default: + assert_not_reached(); + } + } + +} diff --git a/src/Dialogs/DialogToot.vala b/src/Dialogs/DialogToot.vala index a977f80..303e4e9 100644 --- a/src/Dialogs/DialogToot.vala +++ b/src/Dialogs/DialogToot.vala @@ -1,10 +1,14 @@ using Gtk; +using Tootle; public class Tootle.TootDialog : Gtk.Dialog { private static TootDialog dialog; private Gtk.TextView text; private Gtk.Label counter; + private Gtk.MenuButton visibility; + + private StatusVisibility visibility_opt; public TootDialog (Gtk.Window? parent) { Object ( @@ -14,39 +18,82 @@ public class Tootle.TootDialog : Gtk.Dialog { title: _("Toot"), transient_for: parent ); - var actions = get_action_area().get_parent() as Gtk.Box; - var content = get_content_area(); + visibility_opt = StatusVisibility.PUBLIC; + var actions = get_action_area ().get_parent () as Gtk.Box; + var content = get_content_area (); + + visibility = get_visibility_btn (); var close = add_button(_("Cancel"), 5) as Gtk.Button; close.clicked.connect(() => { this.destroy (); }); - var publish = add_button(_("Toot!"), 5) as Gtk.Button; publish.get_style_context ().add_class (Gtk.STYLE_CLASS_SUGGESTED_ACTION); + publish.clicked.connect (() => { + this.destroy (); //TODO: actually publish toots + }); - text = new Gtk.TextView(); + text = new Gtk.TextView (); text.margin_start = 6; text.margin_end = 6; text.get_style_context ().add_class ("toot-text"); text.hexpand = true; text.wrap_mode = Gtk.WrapMode.WORD; - text.buffer.changed.connect(update_counter); + text.buffer.changed.connect (update_counter); counter = new Gtk.Label ("500"); + actions.pack_start (visibility, false, false, 6); actions.pack_start (counter, false, false, 6); content.pack_start (text, false, false, 0); content.set_size_request (300, 100); } - private void update_counter(){ + private Gtk.MenuButton get_visibility_btn (){ + var button = new Gtk.MenuButton (); + var icon = new Gtk.Image.from_icon_name (visibility_opt.get_icon (), Gtk.IconSize.SMALL_TOOLBAR); + var menu = new Gtk.Popover (null); + var box = new Gtk.Box (Gtk.Orientation.VERTICAL, 6); + box.margin = 6; + menu.add (box); + button.direction = Gtk.ArrowType.DOWN; + + StatusVisibility[] opts = {StatusVisibility.PUBLIC, StatusVisibility.UNLISTED, StatusVisibility.PRIVATE, StatusVisibility.DIRECT}; + + Gtk.RadioButton* first = null; + foreach (StatusVisibility opt in opts){ + var item = new Gtk.RadioButton.with_label_from_widget (first, opt.get_desc ()); + if(first == null) + first = item; + + item.toggled.connect (() => { + visibility_opt = opt; + button.remove (icon); + icon = new Gtk.Image.from_icon_name (opt.get_icon (), Gtk.IconSize.SMALL_TOOLBAR); + icon.show (); + button.add (icon); + }); + box.pack_start (item, false, false, 0); + } + + box.show_all (); + button.use_popover = true; + button.popover = menu; + button.valign = Gtk.Align.CENTER; + button.add (icon); + button.show (); + + return button; + } + + private void update_counter (){ var len = text.buffer.text.length; counter.label = (500 - len).to_string (); } - public static void open(Gtk.Window? parent){ + public static void open (Gtk.Window? parent){ if(dialog == null){ dialog = new TootDialog (parent); dialog.destroy.connect (() => { diff --git a/src/Widgets/AccountsButton.vala b/src/Widgets/AccountsButton.vala index 1ec5719..42b49ab 100644 --- a/src/Widgets/AccountsButton.vala +++ b/src/Widgets/AccountsButton.vala @@ -9,7 +9,7 @@ public class Tootle.AccountsButton : Gtk.MenuButton{ private class AccountView : Gtk.Grid{ - public Gtk.Label name; + public Gtk.Label display_name; public Gtk.Label user; public Gtk.Button logout; @@ -17,10 +17,10 @@ public class Tootle.AccountsButton : Gtk.MenuButton{ margin = 6; margin_start = 14; - name = new Gtk.Label ("Anonymous"); - name.hexpand = true; - name.halign = Gtk.Align.START; - name.use_markup = true; + display_name = new Gtk.Label ("Anonymous"); + display_name.hexpand = true; + display_name.halign = Gtk.Align.START; + display_name.use_markup = true; user = new Gtk.Label ("@error"); user.halign = Gtk.Align.START; logout = new Gtk.Button.from_icon_name ("pane-hide-symbolic", Gtk.IconSize.SMALL_TOOLBAR); @@ -29,7 +29,7 @@ public class Tootle.AccountsButton : Gtk.MenuButton{ logout.clicked.connect (() => AccountManager.instance.logout ()); show_all (); - attach(name, 1, 0, 1, 1); + attach(display_name, 1, 0, 1, 1); attach(user, 1, 1, 1, 1); attach(logout, 2, 0, 2, 2); } @@ -71,7 +71,7 @@ public class Tootle.AccountsButton : Gtk.MenuButton{ AccountManager.instance.changed_current.connect (account => { if (account != null){ CacheManager.instance.load_avatar (account.avatar, avatar, 24); - default_account.name.label = ""+account.display_name+""; + default_account.display_name.label = ""+account.display_name+""; default_account.user.label = "@"+account.username; } });