mirror of
https://gitlab.gnome.org/World/tootle
synced 2025-02-17 03:51:11 +01:00
Tweaks
This commit is contained in:
parent
fbdfb5ea27
commit
7323bc6836
@ -2,9 +2,11 @@ using Gtk;
|
||||
|
||||
public class Tootle.MainWindow: Gtk.Window {
|
||||
|
||||
weak SettingsManager settings;
|
||||
Gtk.Overlay overlay;
|
||||
Granite.Widgets.Toast toast;
|
||||
private weak SettingsManager settings;
|
||||
|
||||
private Gtk.Overlay overlay;
|
||||
private Granite.Widgets.Toast toast;
|
||||
private Gtk.Grid grid;
|
||||
public Tootle.HeaderBar header;
|
||||
public Stack primary_stack;
|
||||
public Stack secondary_stack;
|
||||
@ -30,7 +32,7 @@ public class Tootle.MainWindow: Gtk.Window {
|
||||
primary_stack.vexpand = true;
|
||||
header = new Tootle.HeaderBar ();
|
||||
|
||||
var grid = new Gtk.Grid ();
|
||||
grid = new Gtk.Grid ();
|
||||
grid.set_size_request (400, 500);
|
||||
grid.attach (primary_stack, 0, 0, 1, 1);
|
||||
grid.attach (overlay, 0, 0, 1, 1);
|
||||
|
@ -22,7 +22,7 @@ public class Tootle.NetManager : GLib.Object {
|
||||
construct {
|
||||
cache_path = "%s/%s".printf (GLib.Environment.get_user_cache_dir (), "tootle");
|
||||
cache = new Soup.Cache (cache_path, Soup.CacheType.SINGLE_USER);
|
||||
cache.set_max_size (1024 * 1024 * 16);
|
||||
cache.set_max_size (1024 * 1024 * 64); // 64 mb
|
||||
|
||||
session = new Soup.Session ();
|
||||
session.ssl_strict = true;
|
||||
@ -92,6 +92,11 @@ public class Tootle.NetManager : GLib.Object {
|
||||
|
||||
if (cb != null)
|
||||
cb (sess, mess);
|
||||
|
||||
msg.request_body.free ();
|
||||
msg.response_body.free ();
|
||||
msg.request_headers.free ();
|
||||
msg.response_headers.free ();
|
||||
});
|
||||
return msg;
|
||||
}
|
||||
@ -116,14 +121,13 @@ public class Tootle.NetManager : GLib.Object {
|
||||
return parser.get_root ().get_array ();
|
||||
}
|
||||
|
||||
public void load_avatar (string url, Granite.Widgets.Avatar avatar, int size){
|
||||
public void load_avatar (string url, Granite.Widgets.Avatar avatar, int size = 32){
|
||||
var msg = new Soup.Message("GET", url);
|
||||
msg.finished.connect(() => {
|
||||
var loader = new PixbufLoader ();
|
||||
loader.set_size (size, size);
|
||||
loader.write (msg.response_body.data);
|
||||
loader.close ();
|
||||
avatar.pixbuf = loader.get_pixbuf ();
|
||||
var data = msg.response_body.flatten ().data;
|
||||
var stream = new MemoryInputStream.from_data (data);
|
||||
var pixbuf = new Gdk.Pixbuf.from_stream_at_scale (stream, size, size, true);
|
||||
avatar.pixbuf = pixbuf;
|
||||
});
|
||||
Tootle.network.queue (msg);
|
||||
}
|
||||
@ -131,10 +135,10 @@ public class Tootle.NetManager : GLib.Object {
|
||||
public void load_image (string url, Gtk.Image image) {
|
||||
var msg = new Soup.Message("GET", url);
|
||||
msg.finished.connect(() => {
|
||||
var loader = new PixbufLoader ();
|
||||
loader.write (msg.response_body.data);
|
||||
loader.close ();
|
||||
image.set_from_pixbuf (loader.get_pixbuf ());
|
||||
var data = msg.response_body.flatten ().data;
|
||||
var stream = new MemoryInputStream.from_data (data);
|
||||
var pixbuf = new Gdk.Pixbuf.from_stream (stream);
|
||||
image.set_from_pixbuf (pixbuf);
|
||||
});
|
||||
Tootle.network.queue (msg);
|
||||
}
|
||||
@ -142,7 +146,8 @@ public class Tootle.NetManager : GLib.Object {
|
||||
public void load_scaled_image (string url, Gtk.Image image, int size = 64) {
|
||||
var msg = new Soup.Message("GET", url);
|
||||
msg.finished.connect(() => {
|
||||
var stream = new MemoryInputStream.from_data(msg.response_body.data, GLib.g_free);
|
||||
var data = msg.response_body.flatten ().data;
|
||||
var stream = new MemoryInputStream.from_data (data);
|
||||
var pixbuf = new Gdk.Pixbuf.from_stream_at_scale (stream, size, size, true);
|
||||
image.set_from_pixbuf (pixbuf);
|
||||
});
|
||||
|
@ -32,7 +32,7 @@ public abstract class Tootle.AbstractView : Gtk.ScrolledWindow {
|
||||
return "unnamed";
|
||||
}
|
||||
|
||||
public void clear (){
|
||||
public virtual void clear (){
|
||||
max_id = -1;
|
||||
view.forall (widget => widget.destroy ());
|
||||
|
||||
|
@ -13,13 +13,18 @@ public class Tootle.HomeView : Tootle.AbstractView {
|
||||
Tootle.accounts.switched.connect(on_account_changed);
|
||||
Tootle.app.refresh.connect(on_refresh);
|
||||
|
||||
// var s = new Status(1);
|
||||
// s.content = "Test content, wow!";
|
||||
// prepend (s);
|
||||
|
||||
request ();
|
||||
}
|
||||
|
||||
public override void clear (){
|
||||
max_id = -1;
|
||||
view.forall (widget => {
|
||||
widget.destroy ();
|
||||
});
|
||||
|
||||
pre_construct ();
|
||||
}
|
||||
|
||||
public override string get_icon () {
|
||||
return "user-home-symbolic";
|
||||
}
|
||||
@ -32,11 +37,11 @@ public class Tootle.HomeView : Tootle.AbstractView {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void prepend(Status status){
|
||||
public void prepend (ref Status status){
|
||||
var separator = new Gtk.Separator (Gtk.Orientation.HORIZONTAL);
|
||||
separator.show ();
|
||||
|
||||
var widget = new StatusWidget(status);
|
||||
|
||||
var widget = new StatusWidget (ref status);
|
||||
widget.separator = separator;
|
||||
widget.button_press_event.connect(widget.open);
|
||||
if (!is_status_owned (status))
|
||||
@ -69,7 +74,7 @@ public class Tootle.HomeView : Tootle.AbstractView {
|
||||
if (object != null){
|
||||
var status = Status.parse(object);
|
||||
max_id = status.id;
|
||||
prepend (status);
|
||||
prepend (ref status);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -23,12 +23,12 @@ public class Tootle.SearchView : AbstractView {
|
||||
entry.grab_focus_without_selecting ();
|
||||
}
|
||||
|
||||
private void append_account (Account acc) {
|
||||
private void append_account (ref Account acc) {
|
||||
var _status = new Status (-1);
|
||||
_status.account = acc;
|
||||
_status.content = "<a href=\"%s\">@%s</a>".printf (acc.url, acc.acct);
|
||||
_status.created_at = acc.created_at;
|
||||
var widget = new StatusWidget (_status);
|
||||
var widget = new StatusWidget (ref _status);
|
||||
widget.counters.visible = false;
|
||||
widget.title_acct.visible = false;
|
||||
widget.button_press_event.connect(() => {
|
||||
@ -38,8 +38,8 @@ public class Tootle.SearchView : AbstractView {
|
||||
view.pack_start (widget, false, false, 0);
|
||||
}
|
||||
|
||||
private void append_status (Status status) {
|
||||
var widget = new StatusWidget (status);
|
||||
private void append_status (ref Status status) {
|
||||
var widget = new StatusWidget (ref status);
|
||||
widget.button_press_event.connect(widget.open);
|
||||
view.pack_start (widget, false, false, 0);
|
||||
}
|
||||
@ -99,7 +99,7 @@ public class Tootle.SearchView : AbstractView {
|
||||
accounts.foreach_element ((array, i, node) => {
|
||||
var obj = node.get_object ();
|
||||
var acc = Account.parse (obj);
|
||||
append_account (acc);
|
||||
append_account (ref acc);
|
||||
});
|
||||
}
|
||||
|
||||
@ -108,7 +108,7 @@ public class Tootle.SearchView : AbstractView {
|
||||
statuses.foreach_element ((array, i, node) => {
|
||||
var obj = node.get_object ();
|
||||
var status = Status.parse (obj);
|
||||
append_status (status);
|
||||
append_status (ref status);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -2,19 +2,19 @@ using Gtk;
|
||||
|
||||
public class Tootle.StatusView : Tootle.AbstractView {
|
||||
|
||||
Status root_status;
|
||||
private Status root_status;
|
||||
bool last_was_a_root = false;
|
||||
|
||||
public StatusView (Status status) {
|
||||
public StatusView (ref Status status) {
|
||||
base ();
|
||||
root_status = status;
|
||||
request_context ();
|
||||
}
|
||||
|
||||
private void prepend (Status status, bool is_root = false){
|
||||
private void prepend (ref Status status, bool is_root = false){
|
||||
var separator = new Gtk.Separator (Gtk.Orientation.HORIZONTAL);
|
||||
separator.show ();
|
||||
var widget = new StatusWidget(status);
|
||||
var widget = new StatusWidget (ref status);
|
||||
if (is_root)
|
||||
widget.highlight ();
|
||||
|
||||
@ -40,17 +40,21 @@ public class Tootle.StatusView : Tootle.AbstractView {
|
||||
var ancestors = root.get_array_member ("ancestors");
|
||||
ancestors.foreach_element ((array, i, node) => {
|
||||
var object = node.get_object ();
|
||||
if (object != null)
|
||||
prepend (Status.parse(object));
|
||||
if (object != null) {
|
||||
var status = Status.parse (object);
|
||||
prepend (ref status);
|
||||
}
|
||||
});
|
||||
|
||||
prepend (root_status, true);
|
||||
prepend (ref root_status, true);
|
||||
|
||||
var descendants = root.get_array_member ("descendants");
|
||||
descendants.foreach_element ((array, i, node) => {
|
||||
var object = node.get_object ();
|
||||
if (object != null)
|
||||
prepend (Status.parse(object));
|
||||
if (object != null) {
|
||||
var status = Status.parse (object);
|
||||
prepend (ref status);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (GLib.Error e) {
|
||||
|
@ -3,7 +3,7 @@ using Granite;
|
||||
|
||||
public class Tootle.NotificationWidget : Gtk.Grid {
|
||||
|
||||
public Notification notification;
|
||||
private Notification notification;
|
||||
|
||||
public Gtk.Separator? separator;
|
||||
private Gtk.Image image;
|
||||
@ -53,7 +53,7 @@ public class Tootle.NotificationWidget : Gtk.Grid {
|
||||
});
|
||||
|
||||
if (notification.status != null){
|
||||
status_widget = new StatusWidget (notification.status);
|
||||
status_widget = new StatusWidget (ref notification.status);
|
||||
status_widget.button_press_event.connect(status_widget.open);
|
||||
status_widget.avatar.button_press_event.connect(status_widget.on_avatar_clicked);
|
||||
attach(status_widget, 1, 3, 3, 1);
|
||||
|
@ -4,12 +4,10 @@ public class Tootle.RichLabel : Gtk.Label {
|
||||
|
||||
public weak Mention[]? mentions;
|
||||
|
||||
public RichLabel (string text, bool override_links = true) {
|
||||
public RichLabel (string text) {
|
||||
label = text;
|
||||
set_use_markup (true);
|
||||
|
||||
if (override_links)
|
||||
activate_link.connect (open_link);
|
||||
activate_link.connect (open_link);
|
||||
}
|
||||
|
||||
public void wrap_words () {
|
||||
|
@ -4,10 +4,9 @@ using Granite;
|
||||
public class Tootle.StatusWidget : Gtk.EventBox {
|
||||
|
||||
public Status status;
|
||||
public int64? date_utc;
|
||||
|
||||
public Gtk.Separator? separator;
|
||||
public int avatar_size = 32;
|
||||
public Gtk.Grid grid;
|
||||
public Granite.Widgets.Avatar avatar;
|
||||
public Gtk.Label title_user;
|
||||
public Gtk.Label title_date;
|
||||
@ -18,7 +17,6 @@ public class Tootle.StatusWidget : Gtk.EventBox {
|
||||
public Gtk.Button? spoiler_button;
|
||||
public Gtk.Box title_box;
|
||||
public AttachmentBox attachments;
|
||||
public Gtk.Grid grid;
|
||||
public Gtk.Box counters;
|
||||
public Gtk.Label reblogs;
|
||||
public Gtk.Label favorites;
|
||||
@ -28,8 +26,8 @@ public class Tootle.StatusWidget : Gtk.EventBox {
|
||||
|
||||
construct {
|
||||
grid = new Gtk.Grid ();
|
||||
|
||||
avatar = new Granite.Widgets.Avatar.with_default_icon (avatar_size);
|
||||
|
||||
avatar = new Granite.Widgets.Avatar.with_default_icon (32);
|
||||
avatar.valign = Gtk.Align.START;
|
||||
avatar.margin_top = 6;
|
||||
avatar.margin_start = 6;
|
||||
@ -76,14 +74,14 @@ public class Tootle.StatusWidget : Gtk.EventBox {
|
||||
reblog.tooltip_text = _("Boost");
|
||||
reblog.toggled.connect (() => {
|
||||
if (reblog.sensitive)
|
||||
status.get_formal ().set_reblogged (reblog.get_active ());
|
||||
this.status.get_formal ().set_reblogged (reblog.get_active ());
|
||||
});
|
||||
favorite = new ImageToggleButton ("help-about-symbolic");
|
||||
favorite.set_action ();
|
||||
favorite.tooltip_text = _("Favorite");
|
||||
favorite.toggled.connect (() => {
|
||||
if (favorite.sensitive)
|
||||
status.get_formal ().set_favorited (favorite.get_active ());
|
||||
this.status.get_formal ().set_favorited (favorite.get_active ());
|
||||
});
|
||||
reply = new ImageToggleButton ("edit-undo-symbolic");
|
||||
reply.set_action ();
|
||||
@ -103,27 +101,27 @@ public class Tootle.StatusWidget : Gtk.EventBox {
|
||||
counters.add (reply);
|
||||
counters.show_all ();
|
||||
|
||||
add (grid);
|
||||
grid.attach (avatar, 1, 1, 1, 4);
|
||||
grid.attach (title_box, 2, 2, 1, 1);
|
||||
grid.attach (revealer, 2, 4, 1, 1);
|
||||
grid.attach (counters, 2, 5, 1, 1);
|
||||
add (grid);
|
||||
show_all ();
|
||||
}
|
||||
|
||||
public StatusWidget (Status status) {
|
||||
public StatusWidget (ref Status status) {
|
||||
this.status = status;
|
||||
status.updated.connect (rebind);
|
||||
this.status.updated.connect (rebind);
|
||||
get_style_context ().add_class ("status");
|
||||
|
||||
if (status.reblog != null) {
|
||||
if (this.status.reblog != null) {
|
||||
var image = new Gtk.Image.from_icon_name("go-up-symbolic", Gtk.IconSize.BUTTON);
|
||||
image.halign = Gtk.Align.END;
|
||||
image.margin_end = 6;
|
||||
image.margin_top = 6;
|
||||
image.show ();
|
||||
|
||||
var label_text = _("<a href=\"%s\"><b>%s</b></a> boosted").printf (status.account.url, status.account.display_name);
|
||||
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.margin_top = 6;
|
||||
@ -180,7 +178,7 @@ public class Tootle.StatusWidget : Gtk.EventBox {
|
||||
});
|
||||
|
||||
Tootle.network.status_removed.connect (id => {
|
||||
if (id == status.id)
|
||||
if (id == this.status.id)
|
||||
destroy ();
|
||||
});
|
||||
|
||||
@ -219,11 +217,11 @@ public class Tootle.StatusWidget : Gtk.EventBox {
|
||||
reblog.tooltip_text = _("This post can't be boosted");
|
||||
}
|
||||
|
||||
Tootle.network.load_avatar (formal.account.avatar, avatar, avatar_size);
|
||||
Tootle.network.load_avatar (formal.account.avatar, avatar);
|
||||
}
|
||||
|
||||
public bool is_spoiler () {
|
||||
return status.get_formal ().spoiler_text != null || status.get_formal ().sensitive;
|
||||
return this.status.get_formal ().spoiler_text != null || this.status.get_formal ().sensitive;
|
||||
}
|
||||
|
||||
private GLib.DateTime? parse_date_iso8601 (string date) {
|
||||
@ -241,7 +239,8 @@ public class Tootle.StatusWidget : Gtk.EventBox {
|
||||
}
|
||||
|
||||
public bool open () {
|
||||
var view = new StatusView (status.get_formal ());
|
||||
var formal = status.get_formal ();
|
||||
var view = new StatusView (ref formal);
|
||||
Tootle.window.open_view (view);
|
||||
return false;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user