[gnome-break-timer] Add UserActivity.to_string
- From: Dylan McCall <dylanmccall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-break-timer] Add UserActivity.to_string
- Date: Mon, 16 Nov 2020 17:43:13 +0000 (UTC)
commit 6416238faaf2d9af00f5def38b7c2520a8fd3003
Author: Dylan McCall <dylan dylanmccall ca>
Date: Mon Nov 16 09:42:59 2020 -0800
Add UserActivity.to_string
src/daemon/activity/ActivityMonitor.vala | 5 +---
src/daemon/activity/UserActivity.vala | 48 ++++++++++++++++++++++++++------
2 files changed, 41 insertions(+), 12 deletions(-)
---
diff --git a/src/daemon/activity/ActivityMonitor.vala b/src/daemon/activity/ActivityMonitor.vala
index 61dae10..e0959eb 100644
--- a/src/daemon/activity/ActivityMonitor.vala
+++ b/src/daemon/activity/ActivityMonitor.vala
@@ -64,6 +64,7 @@ public class ActivityMonitor : GLib.Object {
public void poll_activity () {
UserActivity activity = this.collect_activity ();
+ GLib.debug ("Detected activity: %s", activity.to_string ());
this.add_activity (activity);
}
@@ -114,28 +115,24 @@ public class ActivityMonitor : GLib.Object {
idle_time = 0,
time_correction = sleep_time
};
- GLib.debug ("Detected system sleep (time_correction: " + int64.FORMAT + " seconds)", sleep_time);
} else if (this.session_status.is_locked ()) {
activity = UserActivity () {
type = ActivityType.LOCKED,
idle_time = idle_time,
time_correction = 0
};
- GLib.debug ("Detected session locked (idle_time: " + int64.FORMAT + " seconds)", idle_time);
} else if (idle_time == 0 || idle_time < this.last_activity.idle_time) {
activity = UserActivity () {
type = ActivityType.INPUT,
idle_time = idle_time,
time_correction = 0
};
- GLib.debug ("Detected user input (idle_time: " + int64.FORMAT + " seconds)", idle_time);
} else {
activity = UserActivity () {
type = ActivityType.NONE,
idle_time = idle_time,
time_correction = 0
};
- GLib.debug ("Detected no activity (idle_time: " + int64.FORMAT + " seconds)", idle_time);
}
activity.time_since_active = time_since_active;
diff --git a/src/daemon/activity/UserActivity.vala b/src/daemon/activity/UserActivity.vala
index 3aa6446..0a7e37c 100644
--- a/src/daemon/activity/UserActivity.vala
+++ b/src/daemon/activity/UserActivity.vala
@@ -17,14 +17,6 @@
namespace BreakTimer.Daemon.Activity {
-public enum ActivityType {
- SLEEP,
- LOCKED,
- NONE,
- INPUT,
- UNLOCK
-}
-
public struct UserActivity {
public ActivityType type;
public int64 idle_time;
@@ -52,6 +44,46 @@ public struct UserActivity {
public bool is_active () {
return this.type > ActivityType.NONE;
}
+
+ public string to_string () {
+ const string format =
+ "%s (" +
+ "idle_time: %" + int64.FORMAT + ", " +
+ "time_since_active %" + int64.FORMAT + ", " +
+ "time_correction: %" + int64.FORMAT +
+ ")";
+ return format.printf (
+ this.type.to_string (),
+ this.idle_time,
+ this.time_since_active,
+ this.time_correction
+ );
+ }
+}
+
+public enum ActivityType {
+ SLEEP,
+ LOCKED,
+ NONE,
+ INPUT,
+ UNLOCK;
+
+ public string to_string() {
+ switch (this) {
+ case SLEEP:
+ return "Sleep";
+ case LOCKED:
+ return "Locked";
+ case NONE:
+ return "None";
+ case INPUT:
+ return "Input";
+ case UNLOCK:
+ return "Unlock";
+ default:
+ assert_not_reached();
+ }
+ }
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]