Revamp stuff

This commit is contained in:
bleakgrey 2018-04-25 16:16:57 +03:00
parent 1851188711
commit b27b836ed4
11 changed files with 109 additions and 80 deletions

View File

@ -24,6 +24,7 @@ executable(
'src/AccountManager.vala', 'src/AccountManager.vala',
'src/NetManager.vala', 'src/NetManager.vala',
'src/CacheManager.vala', 'src/CacheManager.vala',
'src/Utils.vala',
'src/API/Account.vala', 'src/API/Account.vala',
'src/API/Status.vala', 'src/API/Status.vala',
'src/API/StatusVisibility.vala', 'src/API/StatusVisibility.vala',
@ -42,6 +43,7 @@ executable(
'src/Views/FederatedView.vala', 'src/Views/FederatedView.vala',
'src/Views/NotificationsView.vala', 'src/Views/NotificationsView.vala',
'src/Views/StatusView.vala', 'src/Views/StatusView.vala',
'src/Views/AccountView.vala',
dependencies: [ dependencies: [
dependency('gtk+-3.0'), dependency('gtk+-3.0'),
dependency('glib-2.0', version: '>=2.30.0'), dependency('glib-2.0', version: '>=2.30.0'),

View File

@ -21,24 +21,6 @@ public class Tootle.Status{
this.favorited = false; this.favorited = false;
} }
public static string escape_html(string content){
return content
.replace("<br>", "\n")
.replace("</br>", "")
.replace("<br />", "\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("<p>", "")
.replace("</p>", " ")
.replace("target=\"_blank\"", "");
}
public static Status parse(Json.Object obj) { public static Status parse(Json.Object obj) {
var id = int64.parse (obj.get_string_member ("id")); var id = int64.parse (obj.get_string_member ("id"));
var status = new Status (id); var status = new Status (id);
@ -48,10 +30,10 @@ public class Tootle.Status{
status.url = obj.get_string_member ("url"); status.url = obj.get_string_member ("url");
status.reblogs_count = obj.get_int_member ("reblogs_count"); status.reblogs_count = obj.get_int_member ("reblogs_count");
status.favourites_count = obj.get_int_member ("favourites_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"); var spoiler = obj.get_string_member ("spoiler_text");
if (spoiler != "") if (spoiler != "")
status.spoiler_text = escape_html (spoiler); status.spoiler_text = Utils.escape_html (spoiler);
if(obj.has_member ("reblogged")) if(obj.has_member ("reblogged"))
status.reblogged = obj.get_boolean_member ("reblogged"); status.reblogged = obj.get_boolean_member ("reblogged");

View File

@ -23,7 +23,7 @@ public class Tootle.MainWindow: Gtk.Window {
primary_stack = new Stack(); primary_stack = new Stack();
primary_stack.transition_type = Gtk.StackTransitionType.SLIDE_LEFT_RIGHT; primary_stack.transition_type = Gtk.StackTransitionType.SLIDE_LEFT_RIGHT;
primary_stack.show (); primary_stack.show ();
primary_stack.add_named (secondary_stack, "modes"); primary_stack.add_named (secondary_stack, "0");
header = new Tootle.HeaderBar (); header = new Tootle.HeaderBar ();
@ -83,8 +83,10 @@ public class Tootle.MainWindow: Gtk.Window {
public void open_secondary_view (Widget widget) { public void open_secondary_view (Widget widget) {
widget.show (); widget.show ();
primary_stack.add_named (widget, "details"); var i = int.parse (primary_stack.get_visible_child_name ());
primary_stack.set_visible_child_name ("details"); i++;
primary_stack.add_named (widget, i.to_string ());
primary_stack.set_visible_child_name (i.to_string ());
header.update (false); header.update (false);
} }

26
src/Utils.vala Normal file
View File

@ -0,0 +1,26 @@
public class Tootle.Utils{
public static string escape_html(string content){
var str = content
.replace("<br>", "\n")
.replace("</br>", "")
.replace("<br />", "\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("<p>", "")
.replace("</p>", "\n\n")
.replace("target=\"_blank\"", "");
while (str.has_suffix ("\n"))
str = str.slice (0, str.last_index_of ("\n"));
return str;
}
}

View File

@ -1,12 +1,20 @@
using Gtk; using Gtk;
public abstract class Tootle.AbstractView : Gtk.Box { public abstract class Tootle.AbstractView : Gtk.ScrolledWindow {
public bool show_in_header; public bool show_in_header;
public Gtk.Image image; public Gtk.Image image;
public Gtk.Box view;
public AbstractView (bool show_in_header) { construct {
this.show_in_header = show_in_header; 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 () { public virtual string get_icon () {

View File

@ -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);
}
}

View File

@ -3,30 +3,13 @@ using Gdk;
public class Tootle.HomeView : Tootle.AbstractView { public class Tootle.HomeView : Tootle.AbstractView {
Gtk.Box view;
Gtk.ScrolledWindow scroll;
private string timeline; private string timeline;
private string pars; 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 = "") { public HomeView (string timeline = "home", string pars = "") {
base (true); base (true);
this.timeline = timeline; this.timeline = timeline;
this.pars = pars; this.pars = pars;
show_all();
view.remove.connect (on_remove); view.remove.connect (on_remove);
AccountManager.instance.switched.connect(on_account_changed); AccountManager.instance.switched.connect(on_account_changed);

View File

@ -3,25 +3,8 @@ using Gdk;
public class Tootle.NotificationsView : Tootle.AbstractView { 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 () { public NotificationsView () {
base (true); base (true);
show_all();
view.remove.connect (on_remove); view.remove.connect (on_remove);
AccountManager.instance.switched.connect(on_account_changed); AccountManager.instance.switched.connect(on_account_changed);

View File

@ -3,23 +3,6 @@ using Gtk;
public class Tootle.StatusView : Tootle.AbstractView { public class Tootle.StatusView : Tootle.AbstractView {
Status root_status; 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) { public StatusView (Status status) {
base (false); base (false);

View File

@ -19,10 +19,14 @@ public class Tootle.HeaderBar : Gtk.HeaderBar{
button_back.get_style_context ().add_class (Granite.STYLE_CLASS_BACK_BUTTON); button_back.get_style_context ().add_class (Granite.STYLE_CLASS_BACK_BUTTON);
button_back.clicked.connect (() => { button_back.clicked.connect (() => {
var primary_stack = Tootle.window.primary_stack; var primary_stack = Tootle.window.primary_stack;
primary_stack.set_visible_child_name ("modes"); var i = int.parse (primary_stack.get_visible_child_name ());
var child = primary_stack.get_child_by_name ("details"); primary_stack.set_visible_child_name ((i-1).to_string ());
var child = primary_stack.get_child_by_name (i.to_string ());
child.destroy (); child.destroy ();
update (true);
var is_root = primary_stack.get_visible_child_name () == "0";
update (is_root);
}); });
button_toot = new Button (); button_toot = new Button ();

View File

@ -146,6 +146,15 @@ public class Tootle.StatusWidget : Gtk.EventBox {
var avatar_url = status.reblog != null ? status.reblog.account.avatar : status.account.avatar; var avatar_url = status.reblog != null ? status.reblog.account.avatar : status.account.avatar;
CacheManager.instance.load_avatar (avatar_url, this.avatar, this.avatar_size); 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){ private Gtk.ToggleButton get_action_button (string icon_path){