Close #81
This commit is contained in:
parent
2364a26d2c
commit
03a3895b4d
|
@ -83,7 +83,7 @@ public class Tootle.Accounts : Object {
|
|||
switch_account (settings.current_account);
|
||||
}
|
||||
|
||||
private void save (bool overwrite = true) {
|
||||
public void save (bool overwrite = true) {
|
||||
try {
|
||||
var dir = File.new_for_path (dir_path);
|
||||
if (!dir.query_exists ())
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
public class Tootle.InstanceAccount : GLib.Object {
|
||||
using GLib;
|
||||
|
||||
public class Tootle.InstanceAccount : Object {
|
||||
|
||||
public string username {get; set;}
|
||||
public string instance {get; set;}
|
||||
public string client_id {get; set;}
|
||||
public string client_secret {get; set;}
|
||||
public string token {get; set;}
|
||||
public bool has_unread {get; set;}
|
||||
|
||||
private Notificator? notificator;
|
||||
|
||||
|
@ -52,6 +55,8 @@ public class Tootle.InstanceAccount : GLib.Object {
|
|||
builder.add_string_value (client_secret);
|
||||
builder.set_member_name ("token");
|
||||
builder.add_string_value (token);
|
||||
builder.set_member_name ("has_unread");
|
||||
builder.add_boolean_value (has_unread);
|
||||
builder.end_object ();
|
||||
return builder.get_root ();
|
||||
}
|
||||
|
@ -63,6 +68,7 @@ public class Tootle.InstanceAccount : GLib.Object {
|
|||
acc.client_id = obj.get_string_member ("id");
|
||||
acc.client_secret = obj.get_string_member ("secret");
|
||||
acc.token = obj.get_string_member ("token");
|
||||
acc.has_unread = obj.get_boolean_member ("has_unread");
|
||||
return acc;
|
||||
}
|
||||
|
||||
|
|
|
@ -50,22 +50,20 @@ public class Tootle.MainWindow: Gtk.Window {
|
|||
|
||||
button_toot = new Button ();
|
||||
button_toot.tooltip_text = _("Toot");
|
||||
button_toot.image = new Gtk.Image.from_icon_name ("document-edit-symbolic", Gtk.IconSize.LARGE_TOOLBAR);
|
||||
button_toot.image = new Image.from_icon_name ("document-edit-symbolic", IconSize.LARGE_TOOLBAR);
|
||||
button_toot.clicked.connect (() => PostDialog.open ());
|
||||
|
||||
button_mode = new Granite.Widgets.ModeButton ();
|
||||
button_mode.get_style_context ().add_class ("mode");
|
||||
button_mode.vexpand = true;
|
||||
button_mode.valign = Gtk.Align.FILL;
|
||||
button_mode.mode_changed.connect (widget => {
|
||||
secondary_stack.set_visible_child_name (widget.tooltip_text);
|
||||
});
|
||||
button_mode.valign = Align.FILL;
|
||||
button_mode.mode_changed.connect (on_mode_changed);
|
||||
button_mode.show ();
|
||||
|
||||
header = new Gtk.HeaderBar ();
|
||||
header = new HeaderBar ();
|
||||
header.get_style_context ().add_class ("compact");
|
||||
header.show_close_button = true;
|
||||
header.title = "Tootle";
|
||||
header.title = _("Tootle");
|
||||
header.custom_title = button_mode;
|
||||
header.pack_start (button_back);
|
||||
header.pack_start (button_toot);
|
||||
|
@ -73,7 +71,7 @@ public class Tootle.MainWindow: Gtk.Window {
|
|||
header.pack_end (spinner);
|
||||
header.show_all ();
|
||||
|
||||
grid = new Gtk.Grid ();
|
||||
grid = new Grid ();
|
||||
grid.attach (primary_stack, 0, 0, 1, 1);
|
||||
|
||||
add_header_view (home);
|
||||
|
@ -83,7 +81,7 @@ public class Tootle.MainWindow: Gtk.Window {
|
|||
button_mode.set_active (0);
|
||||
|
||||
toast = new Granite.Widgets.Toast ("");
|
||||
overlay = new Gtk.Overlay ();
|
||||
overlay = new Overlay ();
|
||||
overlay.add_overlay (grid);
|
||||
overlay.add_overlay (toast);
|
||||
overlay.set_size_request (450, 600);
|
||||
|
@ -113,7 +111,7 @@ public class Tootle.MainWindow: Gtk.Window {
|
|||
}
|
||||
|
||||
private void add_header_view (AbstractView view) {
|
||||
var img = new Gtk.Image.from_icon_name (view.get_icon (), Gtk.IconSize.LARGE_TOOLBAR);
|
||||
var img = new Image.from_icon_name (view.get_icon (), IconSize.LARGE_TOOLBAR);
|
||||
img.tooltip_text = view.get_name ();
|
||||
button_mode.append (img);
|
||||
view.image = img;
|
||||
|
@ -156,11 +154,6 @@ public class Tootle.MainWindow: Gtk.Window {
|
|||
}
|
||||
}
|
||||
|
||||
private void on_toast (string msg){
|
||||
toast.title = msg;
|
||||
toast.send_notification ();
|
||||
}
|
||||
|
||||
public override bool delete_event (Gdk.EventAny event) {
|
||||
this.destroy.connect (() => {
|
||||
if (!settings.always_online || accounts.is_empty ())
|
||||
|
@ -170,6 +163,10 @@ public class Tootle.MainWindow: Gtk.Window {
|
|||
return false;
|
||||
}
|
||||
|
||||
public void switch_timeline (int32 timeline_no) {
|
||||
button_mode.set_active (timeline_no);
|
||||
}
|
||||
|
||||
private void update_theme () {
|
||||
var provider = new Gtk.CssProvider ();
|
||||
var is_dark = settings.dark_theme;
|
||||
|
@ -188,7 +185,20 @@ public class Tootle.MainWindow: Gtk.Window {
|
|||
button_accounts.set_visible (true);
|
||||
}
|
||||
|
||||
public void switch_timeline (int32 timeline_no) {
|
||||
button_mode.set_active (timeline_no);
|
||||
private void on_toast (string msg){
|
||||
toast.title = msg;
|
||||
toast.send_notification ();
|
||||
}
|
||||
|
||||
private void on_mode_changed (Widget widget) {
|
||||
var visible = secondary_stack.get_visible_child () as AbstractView;
|
||||
visible.current = false;
|
||||
|
||||
secondary_stack.set_visible_child_name (widget.tooltip_text);
|
||||
|
||||
visible = secondary_stack.get_visible_child () as AbstractView;
|
||||
visible.current = true;
|
||||
visible.on_set_current ();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,11 +2,12 @@ using Gtk;
|
|||
|
||||
public abstract class Tootle.AbstractView : ScrolledWindow {
|
||||
|
||||
public bool current = false;
|
||||
public int stack_pos = -1;
|
||||
public Image? image;
|
||||
public Box view;
|
||||
protected Box? empty;
|
||||
protected Gtk.Grid? header;
|
||||
protected Grid? header;
|
||||
|
||||
construct {
|
||||
view = new Box (Orientation.VERTICAL, 0);
|
||||
|
@ -14,9 +15,9 @@ public abstract class Tootle.AbstractView : ScrolledWindow {
|
|||
add (view);
|
||||
|
||||
hscrollbar_policy = PolicyType.NEVER;
|
||||
edge_reached.connect(pos => {
|
||||
edge_reached.connect (pos => {
|
||||
if (pos == PositionType.BOTTOM)
|
||||
bottom_reached ();
|
||||
on_bottom_reached ();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -39,7 +40,8 @@ public abstract class Tootle.AbstractView : ScrolledWindow {
|
|||
});
|
||||
}
|
||||
|
||||
public virtual void bottom_reached (){}
|
||||
public virtual void on_bottom_reached () {}
|
||||
public virtual void on_set_current () {}
|
||||
|
||||
public virtual bool is_empty () {
|
||||
return view.get_children ().length () <= 1;
|
||||
|
|
|
@ -14,7 +14,10 @@ public class Tootle.NotificationsView : AbstractView {
|
|||
}
|
||||
|
||||
public override string get_icon () {
|
||||
return Desktop.fallback_icon ("notification-symbolic", "user-invisible-symbolic");
|
||||
if (accounts.formal == null || !accounts.formal.has_unread)
|
||||
return Desktop.fallback_icon ("notification-symbolic", "user-invisible-symbolic");
|
||||
else
|
||||
return Desktop.fallback_icon ("notification-new-symbolic", "user-available-symbolic");
|
||||
}
|
||||
|
||||
public override string get_name () {
|
||||
|
@ -34,7 +37,6 @@ public class Tootle.NotificationsView : AbstractView {
|
|||
|
||||
var widget = new NotificationWidget (notification);
|
||||
widget.separator = separator;
|
||||
image.icon_name = Desktop.fallback_icon ("notification-new-symbolic", "user-available-symbolic");
|
||||
view.pack_start (separator, false, false, 0);
|
||||
view.pack_start (widget, false, false, 0);
|
||||
|
||||
|
@ -42,6 +44,21 @@ public class Tootle.NotificationsView : AbstractView {
|
|||
view.reorder_child (widget, 0);
|
||||
view.reorder_child (separator, 0);
|
||||
}
|
||||
|
||||
if (!current && reverse) {
|
||||
accounts.formal.has_unread = true;
|
||||
accounts.save ();
|
||||
}
|
||||
image.icon_name = get_icon ();
|
||||
}
|
||||
|
||||
public override void on_set_current () {
|
||||
var account = accounts.formal;
|
||||
if (account != null && account.has_unread) {
|
||||
account.has_unread = false;
|
||||
accounts.save ();
|
||||
}
|
||||
image.icon_name = get_icon ();
|
||||
}
|
||||
|
||||
public virtual void on_remove (Widget widget) {
|
||||
|
|
|
@ -187,7 +187,7 @@ public class Tootle.TimelineView : AbstractView {
|
|||
return settings.live_updates && allowed_public;
|
||||
}
|
||||
|
||||
protected override void bottom_reached (){
|
||||
protected override void on_bottom_reached () {
|
||||
if (is_last_page) {
|
||||
debug ("Last page reached");
|
||||
return;
|
||||
|
|
Loading…
Reference in New Issue