Skip to content

Commit

Permalink
1.0.1 - Add a pomodoro switch that runs in Neralie time
Browse files Browse the repository at this point in the history
  • Loading branch information
Lains committed Jul 23, 2019
1 parent 871d01e commit 7d6f694
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 63 deletions.
1 change: 0 additions & 1 deletion src/DBusServer.vala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ public class Niu.DBusServer : Object {
public signal void indicator_state (bool state);
public signal void update (Utils.Resources data);
public signal void quit ();
public signal void pomodore (bool state);
public signal void show ();

construct {
Expand Down
1 change: 0 additions & 1 deletion src/Indicator/DBusClient.vala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
public interface Niu.DBusClientInterface : Object {
public abstract void quit_niu () throws GLib.IOError, GLib.DBusError;
public abstract void show_niu () throws GLib.IOError, GLib.DBusError;
public signal void start_pomodore (bool state);
public signal void update (Utils.Resources data);
public signal void indicator_state (bool state);
}
Expand Down
14 changes: 3 additions & 11 deletions src/Indicator/Indicator.vala
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,21 @@ public class Niu.Indicator : Wingpanel.Indicator {
popover_widget = new Widgets.PopoverWidget ();

dbusclient = DBusClient.get_default ();

dbusclient.niu_vanished.connect (() => this.visible = false);
dbusclient.niu_appeared.connect (() => this.visible = settings.indicator_state);

dbusclient.interface.indicator_state.connect((state) => this.visible = state);
dbusclient.interface.start_pomodore.connect((state) => {
state = settings.pomodoro;
});

dbusclient.interface.update.connect((res) => {
display_widget.time.time_str = res.ne;
popover_widget.cal.cal_str = res.ar;
if (res.po) {
popover_widget.online = res.po;
}
});

popover_widget.quit_niu.connect (() => {
dbusclient.interface.quit_niu ();
this.visible = false;
});

popover_widget.start_pomodore.connect (() => {
dbusclient.interface.start_pomodore.connect((state) => state = settings.pomodoro);
});

popover_widget.show_niu.connect (() => {
close ();
dbusclient.interface.show_niu ();
Expand Down
9 changes: 4 additions & 5 deletions src/Indicator/Widgets/PopoverWidget.vala
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ public class Niu.Widgets.PopoverWidget : Gtk.Grid {
private Gtk.ModelButton quit_niu_button;

public signal void quit_niu ();
public signal void start_pomodore ();
public signal void show_niu ();
public bool online;

public CalWidget cal;

Expand All @@ -20,11 +20,10 @@ public class Niu.Widgets.PopoverWidget : Gtk.Grid {
show_niu_button.clicked.connect (() => show_niu ());

var settings = AppSettings.get_default ();
start_pomodore_button = new Wingpanel.Widgets.Switch (_("Start Pomodoro…"), settings.pomodoro);
start_pomodore_button.get_style_context ().add_class (Granite.STYLE_CLASS_H4_LABEL);
start_pomodore_button = new Wingpanel.Widgets.Switch (_("Start Pomodoro…"), online);
start_pomodore_button.get_switch ().notify["active"].connect (() => {
start_pomodore ();
settings.pomodoro = start_pomodore_button.get_switch ().active;
online = start_pomodore_button.get_switch ().active;
settings.pomodoro = online;
});

quit_niu_button = new Gtk.ModelButton ();
Expand Down
3 changes: 2 additions & 1 deletion src/Indicator/Widgets/Time.vala
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ public class Niu.Widgets.TimeWidget : Gtk.Box {

construct {
Gtk.IconTheme.get_default().add_resource_path("/com/github/lainsce/niu/icons");
var settings = AppSettings.get_default ();

var icon = new Gtk.Image ();
var settings = AppSettings.get_default ();
if (settings.pomodoro) {
icon.set_from_icon_name ("pomodoro-symbolic", (Gtk.IconSize)3);
} else {
Expand Down
50 changes: 16 additions & 34 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -45,49 +45,28 @@ namespace Niu {
updater.update.connect ((res) => {
dbusserver.update (res);
dbusserver.indicator_state (settings.indicator_state);
dbusserver.pomodore (settings.pomodoro);
});

dbusserver.quit.connect (() => application.quit());
dbusserver.show.connect (() => {
this.deiconify();
this.present();
this.show_all ();
});

if (settings.pomodoro) {
Timeout.add_seconds (777, () => {
pomodore_rest_notification ();
return true;
});
Timeout.add_seconds (1555, () => {
pomodore_drink_notification ();
return true;
});
Timeout.add_seconds (2332, () => {
pomodore_stand_notification ();
return true;
});
}
settings.changed.connect (() => {
if (settings.pomodoro) {
if (res.po) {
Timeout.add_seconds (777, () => {
pomodore_rest_notification ();
return true;
return false;
});
Timeout.add_seconds (1555, () => {
pomodore_drink_notification ();
return true;
return false;
});
Timeout.add_seconds (2332, () => {
pomodore_stand_notification ();
return true;
return false;
});
}
});

dbusserver.quit.connect (() => application.quit());
dbusserver.show.connect (() => {
this.deiconify();
this.present();
this.show_all ();
});
dbusserver.indicator_state (settings.indicator_state);
dbusserver.pomodore (settings.pomodoro);
}

construct {
Expand Down Expand Up @@ -241,29 +220,32 @@ namespace Niu {
});
}

public void pomodore_stand_notification () {
public bool pomodore_stand_notification () {
var notification = new GLib.Notification ("Time's up!");
notification.set_body (_("Go stand and stretch for a while before continuing."));
var icon = new GLib.ThemedIcon ("appointment");
notification.set_icon (icon);

application.send_notification ("com.github.lainsce.niu", notification);
return true;
}
public void pomodore_drink_notification () {
public bool pomodore_drink_notification () {
var notification = new GLib.Notification ("Time's up!");
notification.set_body (_("Go drink something before continuing."));
var icon = new GLib.ThemedIcon ("appointment");
notification.set_icon (icon);

application.send_notification ("com.github.lainsce.niu", notification);
return true;
}
public void pomodore_rest_notification () {
public bool pomodore_rest_notification () {
var notification = new GLib.Notification ("Time's up!");
notification.set_body (_("Go rest for a while before continuing."));
var icon = new GLib.ThemedIcon ("appointment");
notification.set_icon (icon);

application.send_notification ("com.github.lainsce.niu", notification);
return true;
}

public bool set_labels () {
Expand Down
8 changes: 6 additions & 2 deletions src/Updater.vala
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,17 @@ namespace Niu {
private bool update_resources () {
res = Utils.Resources () {
ar = ar (),
ne = ne ()
ne = ne (),
po = po ()
};
update (res);
return true;
}

public bool po () {
return res.get_pomodoro_state ();
}

public string ne () {
var date = new GLib.DateTime.now ();
return res.get_neralie_time_str (date);
Expand All @@ -37,4 +42,3 @@ namespace Niu {
}
}
}

24 changes: 16 additions & 8 deletions src/Utils.vala
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
namespace Niu.Utils {
public string arvelie;
public string neralie;
public double val;

public struct Resources {
public string ar;
public string ne;
public double va;
public bool po;

public bool get_pomodoro_state () {
var settings = AppSettings.get_default ();
if (settings.pomodoro) {
po = true;
} else {
po = false;
}
return po;
}

public string get_arvelie_calendar_str (GLib.DateTime date) {
string resm = "";
Expand Down Expand Up @@ -35,17 +43,17 @@ namespace Niu.Utils {
d = resd.to_string ();
}
}
arvelie = "%s%s%s".printf (y, m, d);
var arvelie = "%s%s%s".printf (y, m, d);
return arvelie;
}

public string get_neralie_time_str (GLib.DateTime date) {
double e = date.to_unix ();
double d = new DateTime.local (date.get_year (), date.get_month (), date.get_day_of_month (), 0, 0, 0).to_unix ();
val = ((e - d) / 8640 / 10000) / 10000;
string val_fmt = (val * 10000000).to_string ();
va = ((e - d) / 8640 / 10000) / 10000;
string val_fmt = (va * 10000000).to_string ();

neralie = "%s:%s".printf(val_fmt.substring(2, 3), val_fmt.substring(5, 3));
var neralie = "%s:%s".printf(val_fmt.substring(2, 3), val_fmt.substring(5, 3));
return neralie;
}
}
Expand Down

0 comments on commit 7d6f694

Please sign in to comment.