Clean up things

This commit is contained in:
bleakgrey 2018-10-24 13:50:40 +03:00
parent 275436b779
commit adb44697bf
6 changed files with 107 additions and 105 deletions

View File

@ -8,6 +8,7 @@ public class Tootle.Status {
public string url;
public string? spoiler_text;
public string content;
public int64 replies_count;
public int64 reblogs_count;
public int64 favourites_count;
public string created_at;
@ -36,6 +37,7 @@ public class Tootle.Status {
status.account = Account.parse (obj.get_object_member ("account"));
status.uri = obj.get_string_member ("uri");
status.created_at = obj.get_string_member ("created_at");
status.replies_count = obj.get_int_member ("replies_count");
status.reblogs_count = obj.get_int_member ("reblogs_count");
status.favourites_count = obj.get_int_member ("favourites_count");
status.content = Html.simplify ( obj.get_string_member ("content"));
@ -171,7 +173,7 @@ public class Tootle.Status {
msg.priority = Soup.MessagePriority.HIGH;
msg.finished.connect (() => {
app.toast (_("Poof!"));
network.status_removed (this.id);
network.status_removed (id);
});
network.queue (msg);
}

View File

@ -74,6 +74,7 @@ public class Tootle.Notificator : GLib.Object {
}
private void on_error (Error e) {
if (!closing)
warning ("Error in %s: %s", get_name (), e.message);
}

View File

@ -5,21 +5,13 @@ public abstract class Tootle.AbstractView : ScrolledWindow {
public int stack_pos = -1;
public Image? image;
public Box view;
protected Grid grid;
protected Box? empty;
protected Gtk.Grid? header;
construct {
view = new Box (Orientation.VERTICAL, 0);
view.valign = Align.START;
grid = new Grid ();
grid.hexpand = true;
grid.vexpand = true;
grid.attach (view, 0, 2);
add (view);
hscrollbar_policy = PolicyType.NEVER;
add (grid);
edge_reached.connect(pos => {
if (pos == PositionType.BOTTOM)
bottom_reached ();
@ -39,7 +31,10 @@ public abstract class Tootle.AbstractView : ScrolledWindow {
}
public virtual void clear (){
view.forall (widget => widget.destroy ());
view.forall (widget => {
if (widget != header)
widget.destroy ();
});
}
public virtual void bottom_reached (){}

View File

@ -4,44 +4,43 @@ using Granite;
public class Tootle.AccountView : TimelineView {
const int AVATAR_SIZE = 128;
Account account;
protected Account account;
Gtk.Grid header;
Gtk.Grid header_image;
Gtk.Box header_info;
Granite.Widgets.Avatar avatar;
RichLabel display_name;
Gtk.Label username;
Gtk.Label relationship;
RichLabel note;
Gtk.Grid counters;
Gtk.Box actions;
Gtk.Button button_follow;
protected Grid header_image;
protected Box header_info;
protected Granite.Widgets.Avatar avatar;
protected RichLabel display_name;
protected Label username;
protected Label relationship;
protected RichLabel note;
protected Grid counters;
protected Box actions;
protected Button button_follow;
protected Gtk.Menu menu;
protected Gtk.MenuItem menu_edit;
protected Gtk.MenuItem menu_mention;
protected Gtk.MenuItem menu_mute;
protected Gtk.MenuItem menu_block;
protected Gtk.MenuItem menu_report;
protected Gtk.MenuButton button_menu;
Gtk.Menu menu;
Gtk.MenuItem menu_edit;
Gtk.MenuItem menu_mention;
Gtk.MenuItem menu_mute;
Gtk.MenuItem menu_block;
Gtk.MenuItem menu_report;
Gtk.MenuButton button_menu;
//public override void pre_construct () {
construct {
header = new Gtk.Grid ();
header_info = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
header = new Grid ();
header_info = new Box (Orientation.VERTICAL, 0);
header_info.margin = 12;
actions = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
actions = new Box (Orientation.HORIZONTAL, 0);
actions.hexpand = false;
actions.halign = Gtk.Align.END;
actions.halign = Align.END;
actions.vexpand = false;
actions.valign = Gtk.Align.START;
actions.valign = Align.START;
actions.margin = 12;
relationship = new Gtk.Label ("");
relationship = new Label ("");
relationship.get_style_context ().add_class ("relationship");
relationship.halign = Gtk.Align.START;
relationship.valign = Gtk.Align.START;
relationship.halign = Align.START;
relationship.valign = Align.START;
relationship.margin = 12;
header.attach (relationship, 0, 0, 1, 1);
@ -62,17 +61,17 @@ public class Tootle.AccountView : TimelineView {
note.selectable = true;
note.margin_top = 12;
note.can_focus = false;
note.justify = Gtk.Justification.CENTER;
note.justify = Justification.CENTER;
header_info.pack_start (note, false, false, 0);
header_info.show_all ();
header.attach (header_info, 0, 0, 1, 1);
counters = new Gtk.Grid ();
counters = new Grid ();
counters.column_homogeneous = true;
counters.get_style_context ().add_class ("header-counters");
header.attach (counters, 0, 1, 1, 1);
header_image = new Gtk.Grid ();
header_image = new Grid ();
header_image.get_style_context ().add_class ("header");
header.attach (header_image, 0, 0, 2, 2);
@ -92,10 +91,10 @@ public class Tootle.AccountView : TimelineView {
button_follow = add_counter ("contact-new-symbolic");
button_menu = new Gtk.MenuButton ();
button_menu.image = new Gtk.Image.from_icon_name ("view-more-symbolic", Gtk.IconSize.LARGE_TOOLBAR);
button_menu.image = new Image.from_icon_name ("view-more-symbolic", IconSize.LARGE_TOOLBAR);
button_menu.tooltip_text = _("More Actions");
button_menu.get_style_context ().add_class (Gtk.STYLE_CLASS_FLAT);
(button_menu as Gtk.Widget).set_focus_on_click (false);
(button_menu as Widget).set_focus_on_click (false);
button_menu.can_default = false;
button_menu.can_focus = false;
button_menu.popup = menu;
@ -105,8 +104,7 @@ public class Tootle.AccountView : TimelineView {
button_follow.hide ();
header.attach (actions, 0, 0, 2, 2);
grid.attach (header, 0, 1);
//view.pack_start (header, false, false, 0);
view.pack_start (header, false, false, 0);
}
public AccountView (Account acc) {
@ -155,11 +153,11 @@ public class Tootle.AccountView : TimelineView {
button_follow.show ();
if (account.rs.following) {
button_follow.tooltip_text = _("Unfollow");
(button_follow.get_image () as Gtk.Image).icon_name = "close-symbolic";
(button_follow.get_image () as Image).icon_name = "close-symbolic";
}
else{
button_follow.tooltip_text = _("Follow");
(button_follow.get_image () as Gtk.Image).icon_name = "contact-new-symbolic";
(button_follow.get_image () as Image).icon_name = "contact-new-symbolic";
}
}
@ -186,20 +184,20 @@ public class Tootle.AccountView : TimelineView {
}
private Gtk.Button add_counter (string name, int? i = null, int64? val = null) {
Gtk.Button btn;
Button btn;
if (val != null){
btn = new Gtk.Button ();
var label = new Gtk.Label ("<b>%s</b>\n%s".printf (name.up (), val.to_string ()));
label.justify = Gtk.Justification.CENTER;
btn = new Button ();
var label = new Label ("<b>%s</b>\n%s".printf (name.up (), val.to_string ()));
label.justify = Justification.CENTER;
label.use_markup = true;
label.margin = 8;
btn.add (label);
}
else
btn = new Gtk.Button.from_icon_name (name, Gtk.IconSize.LARGE_TOOLBAR);
btn = new Button.from_icon_name (name, IconSize.LARGE_TOOLBAR);
btn.get_style_context ().add_class (Gtk.STYLE_CLASS_FLAT);
(btn as Gtk.Widget).set_focus_on_click (false);
(btn as Widget).set_focus_on_click (false);
btn.can_default = false;
btn.can_focus = false;

View File

@ -64,8 +64,9 @@ public class Tootle.TimelineView : AbstractView {
view.pack_start (widget, false, false, 0);
if (first || status.pinned) {
view.reorder_child (widget, 0);
view.reorder_child (separator, 0);
var new_index = header == null ? 1 : 0;
view.reorder_child (widget, new_index);
view.reorder_child (separator, new_index);
}
}

View File

@ -8,36 +8,38 @@ public class Tootle.StatusWidget : Gtk.EventBox {
public bool is_notification = false;
public const int AVATAR_SIZE = 32;
public Gtk.Separator? separator;
public Gtk.Grid grid;
public Separator? separator;
public Granite.Widgets.Avatar avatar;
public RichLabel title_user;
public Gtk.Label title_date;
public Gtk.Label title_acct;
public Gtk.Revealer revealer;
public RichLabel content_label;
public RichLabel? content_spoiler;
public Gtk.Button? spoiler_button;
public Gtk.Box title_box;
public AttachmentBox attachments;
public Gtk.Box counters;
public Gtk.Label reblogs;
public Gtk.Label favorites;
private Image pin_indicator;
public ImageToggleButton reblog;
public ImageToggleButton favorite;
public ImageToggleButton reply;
protected Grid grid;
protected RichLabel title_user;
protected Label title_date;
protected Label title_acct;
protected Revealer revealer;
protected RichLabel content_label;
protected RichLabel? content_spoiler;
protected Button? spoiler_button;
protected Box title_box;
protected AttachmentBox attachments;
protected Image pin_indicator;
protected Box counters;
protected Label replies;
protected Label reblogs;
protected Label favorites;
protected ImageToggleButton reblog;
protected ImageToggleButton favorite;
protected ImageToggleButton reply;
construct {
grid = new Gtk.Grid ();
grid = new Grid ();
avatar = new Granite.Widgets.Avatar.with_default_icon (AVATAR_SIZE);
avatar.valign = Gtk.Align.START;
avatar.valign = Align.START;
avatar.margin_top = 6;
avatar.margin_start = 6;
avatar.margin_end = 6;
title_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 6);
title_box = new Box (Gtk.Orientation.HORIZONTAL, 6);
title_box.hexpand = true;
title_box.margin_end = 12;
title_box.margin_top = 6;
@ -65,7 +67,7 @@ public class Tootle.StatusWidget : Gtk.EventBox {
attachments = new AttachmentBox ();
var revealer_box = new Gtk.Box (Gtk.Orientation.VERTICAL, 6);
var revealer_box = new Box (Orientation.VERTICAL, 6);
revealer_box.margin_end = 12;
revealer_box.add (content_label);
revealer_box.add (attachments);
@ -73,8 +75,9 @@ public class Tootle.StatusWidget : Gtk.EventBox {
revealer.reveal_child = true;
revealer.add (revealer_box);
reblogs = new Gtk.Label ("0");
favorites = new Gtk.Label ("0");
reblogs = new Label ("0");
favorites = new Label ("0");
replies = new Label ("0");
reblog = new ImageToggleButton ("media-playlist-repeat-symbolic");
reblog.set_action ();
@ -98,7 +101,7 @@ public class Tootle.StatusWidget : Gtk.EventBox {
PostDialog.open_reply (status.get_formal ());
});
counters = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 6);
counters = new Box (Orientation.HORIZONTAL, 6);
counters.margin_top = 6;
counters.margin_bottom = 6;
counters.add (reblog);
@ -106,6 +109,7 @@ public class Tootle.StatusWidget : Gtk.EventBox {
counters.add (favorite);
counters.add (favorites);
counters.add (reply);
counters.add (replies);
counters.show_all ();
add (grid);
@ -123,15 +127,15 @@ public class Tootle.StatusWidget : Gtk.EventBox {
this.status.updated.connect (rebind);
if (this.status.reblog != null) {
var image = new Gtk.Image.from_icon_name("media-playlist-repeat-symbolic", Gtk.IconSize.BUTTON);
image.halign = Gtk.Align.END;
var image = new Image.from_icon_name("media-playlist-repeat-symbolic", IconSize.BUTTON);
image.halign = Align.END;
image.margin_end = 6;
image.margin_top = 6;
image.show ();
var label_text = _("<a href=\"%s\"><b>%s</b></a> boosted").printf (this.status.account.url, this.status.account.display_name);
var label = new RichLabel (label_text);
label.halign = Gtk.Align.START;
label.halign = Align.START;
label.margin_top = 6;
label.show ();
@ -141,7 +145,7 @@ public class Tootle.StatusWidget : Gtk.EventBox {
if (is_spoiler ()) {
revealer.reveal_child = false;
var spoiler_box = new Box (Gtk.Orientation.HORIZONTAL, 6);
var spoiler_box = new Box (Orientation.HORIZONTAL, 6);
spoiler_box.margin_end = 12;
var spoiler_button_text = _("Toggle content");
@ -155,7 +159,7 @@ public class Tootle.StatusWidget : Gtk.EventBox {
spoiler_button = new Button.with_label (spoiler_button_text);
}
spoiler_button.hexpand = true;
spoiler_button.halign = Gtk.Align.END;
spoiler_button.halign = Align.END;
spoiler_button.clicked.connect (() => revealer.set_reveal_child (!revealer.child_revealed));
var spoiler_text = _("[ This post contains sensitive content ]");
@ -215,6 +219,7 @@ public class Tootle.StatusWidget : Gtk.EventBox {
reblogs.label = formal.reblogs_count.to_string ();
favorites.label = formal.favourites_count.to_string ();
replies.label = formal.replies_count.to_string ();
reblog.sensitive = false;
reblog.active = formal.reblogged;