Add refresh menu item
This commit is contained in:
parent
2d62596a21
commit
cb7590f341
|
@ -25,6 +25,7 @@ executable(
|
||||||
'src/NetManager.vala',
|
'src/NetManager.vala',
|
||||||
'src/CacheManager.vala',
|
'src/CacheManager.vala',
|
||||||
'src/Utils.vala',
|
'src/Utils.vala',
|
||||||
|
'src/CmdRunner.vala',
|
||||||
'src/API/Account.vala',
|
'src/API/Account.vala',
|
||||||
'src/API/Relationship.vala',
|
'src/API/Relationship.vala',
|
||||||
'src/API/Mention.vala',
|
'src/API/Mention.vala',
|
||||||
|
|
|
@ -31,7 +31,7 @@ public class Tootle.Status{
|
||||||
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);
|
||||||
|
|
||||||
status.account = Account.parse(obj.get_object_member ("account"));
|
status.account = Account.parse (obj.get_object_member ("account"));
|
||||||
status.uri = obj.get_string_member ("uri");
|
status.uri = obj.get_string_member ("uri");
|
||||||
status.url = obj.get_string_member ("url");
|
status.url = obj.get_string_member ("url");
|
||||||
status.created_at = obj.get_string_member ("created_at");
|
status.created_at = obj.get_string_member ("created_at");
|
||||||
|
|
|
@ -0,0 +1,91 @@
|
||||||
|
public class Tootle.CmdRunner : GLib.Object{
|
||||||
|
|
||||||
|
public signal void done(int exit);
|
||||||
|
public signal void output_changed(string text);
|
||||||
|
public signal void standard_changed(string text);
|
||||||
|
public signal void error_changed(string text);
|
||||||
|
|
||||||
|
public string standard_output_str = "";
|
||||||
|
public string error_output_str = "";
|
||||||
|
public string output_str = "";
|
||||||
|
|
||||||
|
GLib.IOChannel out_make;
|
||||||
|
GLib.IOChannel error_out;
|
||||||
|
string dir;
|
||||||
|
string command;
|
||||||
|
Pid pid;
|
||||||
|
|
||||||
|
public CmdRunner(string dir, string command){
|
||||||
|
this.dir = dir;
|
||||||
|
this.command = command;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run(){
|
||||||
|
int standard_output = 0;
|
||||||
|
int standard_error = 0;
|
||||||
|
try{
|
||||||
|
Process.spawn_async_with_pipes(dir,
|
||||||
|
command.split(" "),
|
||||||
|
null,
|
||||||
|
SpawnFlags.DO_NOT_REAP_CHILD,
|
||||||
|
null,
|
||||||
|
out pid,
|
||||||
|
null,
|
||||||
|
out standard_output,
|
||||||
|
out standard_error);
|
||||||
|
}
|
||||||
|
catch(Error e){
|
||||||
|
critical("Couldn't launch command %s in the directory %s: %s", command, dir, e.message);
|
||||||
|
}
|
||||||
|
|
||||||
|
ChildWatch.add(pid, (pid, exit) => {
|
||||||
|
Process.close_pid (pid);
|
||||||
|
error_out.shutdown (false);
|
||||||
|
out_make.shutdown (false);
|
||||||
|
done(exit);
|
||||||
|
});
|
||||||
|
|
||||||
|
out_make = new GLib.IOChannel.unix_new(standard_output);
|
||||||
|
out_make.add_watch(IOCondition.IN | IOCondition.HUP, (source, condition) => {
|
||||||
|
if(condition == IOCondition.HUP){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
string output = null;
|
||||||
|
|
||||||
|
try{
|
||||||
|
out_make.read_line(out output, null, null);
|
||||||
|
}
|
||||||
|
catch(Error e){
|
||||||
|
critical("Error in the output retrieving of %s: %s", command, e.message);
|
||||||
|
}
|
||||||
|
|
||||||
|
standard_output_str += output;
|
||||||
|
output_str += output;
|
||||||
|
standard_changed(output);
|
||||||
|
output_changed(output);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
error_out = new GLib.IOChannel.unix_new(standard_error);
|
||||||
|
error_out.add_watch(IOCondition.IN | IOCondition.HUP, (source, condition) => {
|
||||||
|
if(condition == IOCondition.HUP){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
string output = null;
|
||||||
|
try{
|
||||||
|
error_out.read_line(out output, null, null);
|
||||||
|
}
|
||||||
|
catch(Error e){
|
||||||
|
critical("Error in the output retrieving of %s: %s", command, e.message);
|
||||||
|
}
|
||||||
|
|
||||||
|
error_output_str += output;
|
||||||
|
output_str += output;
|
||||||
|
error_changed(output);
|
||||||
|
output_changed(output);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,6 +6,7 @@ public class Tootle.NetManager : GLib.Object{
|
||||||
|
|
||||||
public abstract signal void started();
|
public abstract signal void started();
|
||||||
public abstract signal void finished();
|
public abstract signal void finished();
|
||||||
|
public abstract signal void refresh();
|
||||||
|
|
||||||
private int requests_processing = 0;
|
private int requests_processing = 0;
|
||||||
private Soup.Session session;
|
private Soup.Session session;
|
||||||
|
|
|
@ -35,7 +35,7 @@ public abstract class Tootle.AbstractView : Gtk.ScrolledWindow {
|
||||||
|
|
||||||
public void clear (){
|
public void clear (){
|
||||||
max_id = -1;
|
max_id = -1;
|
||||||
view.forall (widget => view.remove (widget));
|
view.forall (widget => widget.destroy ());
|
||||||
|
|
||||||
pre_construct ();
|
pre_construct ();
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ public class Tootle.HomeView : Tootle.AbstractView {
|
||||||
|
|
||||||
view.remove.connect (on_remove);
|
view.remove.connect (on_remove);
|
||||||
Tootle.accounts.switched.connect(on_account_changed);
|
Tootle.accounts.switched.connect(on_account_changed);
|
||||||
|
Tootle.network.refresh.connect(on_refresh);
|
||||||
|
|
||||||
// var s = new Status(1);
|
// var s = new Status(1);
|
||||||
// s.content = "Test content, wow!";
|
// s.content = "Test content, wow!";
|
||||||
|
@ -81,10 +82,14 @@ public class Tootle.HomeView : Tootle.AbstractView {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual void on_refresh (){
|
||||||
|
clear ();
|
||||||
|
request ();
|
||||||
|
}
|
||||||
|
|
||||||
public virtual void on_account_changed (Account? account){
|
public virtual void on_account_changed (Account? account){
|
||||||
if(account == null)
|
if(account == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
clear ();
|
clear ();
|
||||||
request ();
|
request ();
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ public class Tootle.NotificationsView : Tootle.AbstractView {
|
||||||
|
|
||||||
view.remove.connect (on_remove);
|
view.remove.connect (on_remove);
|
||||||
Tootle.accounts.switched.connect(on_account_changed);
|
Tootle.accounts.switched.connect(on_account_changed);
|
||||||
|
Tootle.network.refresh.connect(on_refresh);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string get_icon () {
|
public override string get_icon () {
|
||||||
|
@ -36,11 +37,21 @@ public class Tootle.NotificationsView : Tootle.AbstractView {
|
||||||
if (view.get_children ().length () <= 1)
|
if (view.get_children ().length () <= 1)
|
||||||
image.icon_name = get_icon ();
|
image.icon_name = get_icon ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual void on_refresh (){
|
||||||
|
clear ();
|
||||||
|
request ();
|
||||||
|
}
|
||||||
|
|
||||||
public virtual void on_account_changed (Account? account){
|
public virtual void on_account_changed (Account? account){
|
||||||
if(account == null)
|
if(account == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
clear ();
|
||||||
|
request ();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void request (){
|
||||||
var url = Tootle.settings.instance_url;
|
var url = Tootle.settings.instance_url;
|
||||||
url += "/api/v1/notifications";
|
url += "/api/v1/notifications";
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ public class Tootle.AccountsButton : Gtk.MenuButton{
|
||||||
Gtk.Popover menu;
|
Gtk.Popover menu;
|
||||||
AccountView default_account;
|
AccountView default_account;
|
||||||
Gtk.ModelButton item_settings;
|
Gtk.ModelButton item_settings;
|
||||||
|
Gtk.ModelButton item_refresh;
|
||||||
Gtk.ModelButton item_favs;
|
Gtk.ModelButton item_favs;
|
||||||
|
|
||||||
private class AccountView : Gtk.Grid{
|
private class AccountView : Gtk.Grid{
|
||||||
|
@ -51,6 +52,10 @@ public class Tootle.AccountsButton : Gtk.MenuButton{
|
||||||
var item_separator = new Gtk.Separator (Gtk.Orientation.HORIZONTAL);
|
var item_separator = new Gtk.Separator (Gtk.Orientation.HORIZONTAL);
|
||||||
item_separator.hexpand = true;
|
item_separator.hexpand = true;
|
||||||
|
|
||||||
|
item_refresh = new Gtk.ModelButton ();
|
||||||
|
item_refresh.text = _("Refresh");
|
||||||
|
item_refresh.clicked.connect (() => Tootle.network.refresh ());
|
||||||
|
|
||||||
item_favs = new Gtk.ModelButton ();
|
item_favs = new Gtk.ModelButton ();
|
||||||
item_favs.text = _("Favorites");
|
item_favs.text = _("Favorites");
|
||||||
item_favs.clicked.connect (() => Tootle.window.open_secondary_view (new FavoritesView ()));
|
item_favs.clicked.connect (() => Tootle.window.open_secondary_view (new FavoritesView ()));
|
||||||
|
@ -63,8 +68,10 @@ public class Tootle.AccountsButton : Gtk.MenuButton{
|
||||||
grid.width_request = 200;
|
grid.width_request = 200;
|
||||||
grid.attach(default_account, 0, 1, 1, 1);
|
grid.attach(default_account, 0, 1, 1, 1);
|
||||||
grid.attach(item_separator, 0, 2, 1, 1);
|
grid.attach(item_separator, 0, 2, 1, 1);
|
||||||
grid.attach(item_favs, 0, 3, 1, 1);
|
grid.attach(item_favs, 0, 4, 1, 1);
|
||||||
//grid.attach(item_settings, 0, 4, 1, 1);
|
grid.attach(new Gtk.Separator (Gtk.Orientation.HORIZONTAL), 0, 5, 1, 1);
|
||||||
|
grid.attach(item_refresh, 0, 6, 1, 1);
|
||||||
|
grid.attach(item_settings, 0, 7, 1, 1);
|
||||||
grid.show_all ();
|
grid.show_all ();
|
||||||
|
|
||||||
menu = new Gtk.Popover (null);
|
menu = new Gtk.Popover (null);
|
||||||
|
|
|
@ -7,13 +7,13 @@ public class Tootle.StatusWidget : Gtk.EventBox {
|
||||||
public int64? date_utc;
|
public int64? date_utc;
|
||||||
|
|
||||||
public int avatar_size;
|
public int avatar_size;
|
||||||
|
public Gtk.Separator? separator;
|
||||||
public Granite.Widgets.Avatar avatar;
|
public Granite.Widgets.Avatar avatar;
|
||||||
public Gtk.Label title_user;
|
public Gtk.Label title_user;
|
||||||
public Gtk.Label title_date;
|
public Gtk.Label title_date;
|
||||||
public Gtk.Label title_acct;
|
public Gtk.Label title_acct;
|
||||||
public Gtk.Revealer revealer;
|
public Gtk.Revealer revealer;
|
||||||
public Tootle.RichLabel content;
|
public Tootle.RichLabel content;
|
||||||
public Gtk.Separator? separator;
|
|
||||||
public Gtk.Label? spoiler_content;
|
public Gtk.Label? spoiler_content;
|
||||||
Gtk.Box title_box;
|
Gtk.Box title_box;
|
||||||
Gtk.Grid grid;
|
Gtk.Grid grid;
|
||||||
|
@ -178,7 +178,7 @@ public class Tootle.StatusWidget : Gtk.EventBox {
|
||||||
// Version >=2.56 provides DateTime.from_iso8601
|
// Version >=2.56 provides DateTime.from_iso8601
|
||||||
public void parse_date_iso8601 (string date){
|
public void parse_date_iso8601 (string date){
|
||||||
var cmd = "date -d " + date + " +%s";
|
var cmd = "date -d " + date + " +%s";
|
||||||
var runner = new Granite.Services.SimpleCommand ("/bin/", cmd);
|
var runner = new CmdRunner ("/bin/", cmd); //Workaround for Granite SimpleCommand pipes bug
|
||||||
runner.done.connect (exit => {
|
runner.done.connect (exit => {
|
||||||
date_utc = int64.parse (runner.standard_output_str);
|
date_utc = int64.parse (runner.standard_output_str);
|
||||||
var date_obj = new GLib.DateTime.from_unix_local (date_utc);
|
var date_obj = new GLib.DateTime.from_unix_local (date_utc);
|
||||||
|
|
Loading…
Reference in New Issue