diff --git a/meson.build b/meson.build
index 79f9acc..e7a5f08 100644
--- a/meson.build
+++ b/meson.build
@@ -24,6 +24,7 @@ executable(
'src/AccountManager.vala',
'src/NetManager.vala',
'src/CacheManager.vala',
+ 'src/Utils.vala',
'src/API/Account.vala',
'src/API/Status.vala',
'src/API/StatusVisibility.vala',
@@ -42,6 +43,7 @@ executable(
'src/Views/FederatedView.vala',
'src/Views/NotificationsView.vala',
'src/Views/StatusView.vala',
+ 'src/Views/AccountView.vala',
dependencies: [
dependency('gtk+-3.0'),
dependency('glib-2.0', version: '>=2.30.0'),
diff --git a/src/API/Status.vala b/src/API/Status.vala
index f044e37..34710cb 100644
--- a/src/API/Status.vala
+++ b/src/API/Status.vala
@@ -21,24 +21,6 @@ public class Tootle.Status{
this.favorited = false;
}
- public static string escape_html(string content){
- return content
- .replace("
", "\n")
- .replace("", "")
- .replace("
", "\n")
- .replace("rel=\"tag\"", "")
- .replace("rel=\"nofollow noopener\"", "")
- .replace("class=\"mention hashtag\"", "")
- .replace("class=\"h-card\"", "")
- .replace("class=\"invisible\"", "")
- .replace("class=\"ellipsis\"", "")
- .replace("class=\"u-url mention\"", "")
- .replace("class=\"\"", "")
- .replace("
", "") - .replace("
", " ") - .replace("target=\"_blank\"", ""); - } - public static Status parse(Json.Object obj) { var id = int64.parse (obj.get_string_member ("id")); var status = new Status (id); @@ -48,10 +30,10 @@ public class Tootle.Status{ status.url = obj.get_string_member ("url"); status.reblogs_count = obj.get_int_member ("reblogs_count"); status.favourites_count = obj.get_int_member ("favourites_count"); - status.content = escape_html ( obj.get_string_member ("content")); + status.content = Utils.escape_html ( obj.get_string_member ("content")); var spoiler = obj.get_string_member ("spoiler_text"); if (spoiler != "") - status.spoiler_text = escape_html (spoiler); + status.spoiler_text = Utils.escape_html (spoiler); if(obj.has_member ("reblogged")) status.reblogged = obj.get_boolean_member ("reblogged"); diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 9c9471f..ae8a54a 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -23,7 +23,7 @@ public class Tootle.MainWindow: Gtk.Window { primary_stack = new Stack(); primary_stack.transition_type = Gtk.StackTransitionType.SLIDE_LEFT_RIGHT; primary_stack.show (); - primary_stack.add_named (secondary_stack, "modes"); + primary_stack.add_named (secondary_stack, "0"); header = new Tootle.HeaderBar (); @@ -83,8 +83,10 @@ public class Tootle.MainWindow: Gtk.Window { public void open_secondary_view (Widget widget) { widget.show (); - primary_stack.add_named (widget, "details"); - primary_stack.set_visible_child_name ("details"); + var i = int.parse (primary_stack.get_visible_child_name ()); + i++; + primary_stack.add_named (widget, i.to_string ()); + primary_stack.set_visible_child_name (i.to_string ()); header.update (false); } diff --git a/src/Utils.vala b/src/Utils.vala new file mode 100644 index 0000000..992c226 --- /dev/null +++ b/src/Utils.vala @@ -0,0 +1,26 @@ +public class Tootle.Utils{ + + public static string escape_html(string content){ + var str = content + .replace("", "") + .replace("
", "\n\n") + .replace("target=\"_blank\"", ""); + + while (str.has_suffix ("\n")) + str = str.slice (0, str.last_index_of ("\n")); + + return str; + } + +} diff --git a/src/Views/AbstractView.vala b/src/Views/AbstractView.vala index 822eb57..54ef6a9 100644 --- a/src/Views/AbstractView.vala +++ b/src/Views/AbstractView.vala @@ -1,12 +1,20 @@ using Gtk; -public abstract class Tootle.AbstractView : Gtk.Box { +public abstract class Tootle.AbstractView : Gtk.ScrolledWindow { public bool show_in_header; public Gtk.Image image; + public Gtk.Box view; - public AbstractView (bool show_in_header) { - this.show_in_header = show_in_header; + construct { + view = new Gtk.Box (Gtk.Orientation.VERTICAL, 0); + hscrollbar_policy = Gtk.PolicyType.NEVER; + add (view); + } + + public AbstractView (bool show) { + show_in_header = show; + show_all (); } public virtual string get_icon () { diff --git a/src/Views/AccountView.vala b/src/Views/AccountView.vala new file mode 100644 index 0000000..111388f --- /dev/null +++ b/src/Views/AccountView.vala @@ -0,0 +1,47 @@ +using Gtk; +using Granite; + +public class Tootle.AccountView : Tootle.AbstractView { + + Account account; + + Gtk.Box header; + Granite.Widgets.Avatar avatar; + Gtk.Label display_name; + Gtk.Label username; + Gtk.Label note; + + construct { + header = new Gtk.Box (Gtk.Orientation.VERTICAL, 0); + header.margin = 16; + + avatar = new Granite.Widgets.Avatar.with_default_icon (128); + header.pack_start (avatar, false, false, 0); + + display_name = new Gtk.Label (""); + display_name.get_style_context ().add_class (Granite.STYLE_CLASS_H2_LABEL); + header.pack_start (display_name, false, false, 0); + username = new Gtk.Label (""); + username.get_style_context ().add_class (Granite.STYLE_CLASS_H3_LABEL); + header.pack_start (username, false, false, 0); + note = new Gtk.Label (""); + note.set_use_markup (true); + note.set_line_wrap (true); + note.get_style_context ().add_class (Granite.STYLE_CLASS_H3_LABEL); + note.justify = Gtk.Justification.CENTER; + header.pack_start (note, false, false, 0); + + view.pack_start (header, false, false, 0); + } + + public AccountView (Account acc){ + base (false); + account = acc; + + display_name.label = account.display_name; + username.label = "@" + account.acct; + note.label = Utils.escape_html (account.note); + CacheManager.instance.load_avatar (account.avatar, avatar, 128); + } + +} diff --git a/src/Views/HomeView.vala b/src/Views/HomeView.vala index af3f677..c76419d 100644 --- a/src/Views/HomeView.vala +++ b/src/Views/HomeView.vala @@ -2,31 +2,14 @@ using Gtk; using Gdk; public class Tootle.HomeView : Tootle.AbstractView { - - Gtk.Box view; - Gtk.ScrolledWindow scroll; private string timeline; private string pars; - construct { - view = new Gtk.Box (Gtk.Orientation.VERTICAL, 0); - view.hexpand = true; - view.valign = Gtk.Align.START; - - scroll = new Gtk.ScrolledWindow (null, null); - scroll.hexpand = true; - scroll.vexpand = true; - scroll.hscrollbar_policy = Gtk.PolicyType.NEVER; - scroll.add (view); - add (scroll); - } - public HomeView (string timeline = "home", string pars = "") { base (true); this.timeline = timeline; this.pars = pars; - show_all(); view.remove.connect (on_remove); AccountManager.instance.switched.connect(on_account_changed); diff --git a/src/Views/NotificationsView.vala b/src/Views/NotificationsView.vala index dfcb19a..147ae2b 100644 --- a/src/Views/NotificationsView.vala +++ b/src/Views/NotificationsView.vala @@ -3,25 +3,8 @@ using Gdk; public class Tootle.NotificationsView : Tootle.AbstractView { - Gtk.Box view; - Gtk.ScrolledWindow scroll; - - construct { - view = new Gtk.Box (Gtk.Orientation.VERTICAL, 0); - view.hexpand = true; - view.valign = Gtk.Align.START; - - scroll = new Gtk.ScrolledWindow (null, null); - scroll.hexpand = true; - scroll.vexpand = true; - scroll.hscrollbar_policy = Gtk.PolicyType.NEVER; - scroll.add (view); - add (scroll); - } - public NotificationsView () { base (true); - show_all(); view.remove.connect (on_remove); AccountManager.instance.switched.connect(on_account_changed); diff --git a/src/Views/StatusView.vala b/src/Views/StatusView.vala index 933b30f..336c0fa 100644 --- a/src/Views/StatusView.vala +++ b/src/Views/StatusView.vala @@ -3,23 +3,6 @@ using Gtk; public class Tootle.StatusView : Tootle.AbstractView { Status root_status; - Gtk.Box view; - Gtk.ScrolledWindow scroll; - - construct { - view = new Gtk.Box (Gtk.Orientation.VERTICAL, 0); - view.hexpand = true; - view.valign = Gtk.Align.START; - - scroll = new Gtk.ScrolledWindow (null, null); - scroll.hexpand = true; - scroll.vexpand = true; - scroll.hscrollbar_policy = Gtk.PolicyType.NEVER; - scroll.add (view); - add (scroll); - - show_all (); - } public StatusView (Status status) { base (false); diff --git a/src/Widgets/HeaderBar.vala b/src/Widgets/HeaderBar.vala index 7d08560..d29e5f1 100644 --- a/src/Widgets/HeaderBar.vala +++ b/src/Widgets/HeaderBar.vala @@ -19,10 +19,14 @@ public class Tootle.HeaderBar : Gtk.HeaderBar{ button_back.get_style_context ().add_class (Granite.STYLE_CLASS_BACK_BUTTON); button_back.clicked.connect (() => { var primary_stack = Tootle.window.primary_stack; - primary_stack.set_visible_child_name ("modes"); - var child = primary_stack.get_child_by_name ("details"); + var i = int.parse (primary_stack.get_visible_child_name ()); + primary_stack.set_visible_child_name ((i-1).to_string ()); + + var child = primary_stack.get_child_by_name (i.to_string ()); child.destroy (); - update (true); + + var is_root = primary_stack.get_visible_child_name () == "0"; + update (is_root); }); button_toot = new Button (); diff --git a/src/Widgets/StatusWidget.vala b/src/Widgets/StatusWidget.vala index 7be15a6..f8ce71c 100644 --- a/src/Widgets/StatusWidget.vala +++ b/src/Widgets/StatusWidget.vala @@ -146,6 +146,15 @@ public class Tootle.StatusWidget : Gtk.EventBox { var avatar_url = status.reblog != null ? status.reblog.account.avatar : status.account.avatar; CacheManager.instance.load_avatar (avatar_url, this.avatar, this.avatar_size); + + avatar.button_press_event.connect(on_avatar_clicked); + } + + private bool on_avatar_clicked (){ + var account = status.reblog != null ? status.reblog.account : status.account; + var view = new AccountView (account); + Tootle.window.open_secondary_view (view); + return true; } private Gtk.ToggleButton get_action_button (string icon_path){