[gnome-usage/accountsservice-via-dbus: 2/3] process-row: Consume AccountsService data over DBus
- From: Felipe Borges <felipeborges src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-usage/accountsservice-via-dbus: 2/3] process-row: Consume AccountsService data over DBus
- Date: Fri, 9 Mar 2018 14:16:00 +0000 (UTC)
commit b4260643c2995562df5c8dd7653528bdf8848537
Author: Felipe Borges <felipeborges gnome org>
Date: Wed Mar 7 13:00:34 2018 +0100
process-row: Consume AccountsService data over DBus
So we don't need to depend on the accountsservice library AND we
can query user data from within a sandbox (flatpak), since Usage
is plumbed to DBus.
src/process-row.vala | 67 ++++++++++++++++++++++------------------------------
src/utils.vala | 20 ++++++++++++++++
2 files changed, 48 insertions(+), 39 deletions(-)
---
diff --git a/src/process-row.vala b/src/process-row.vala
index 70f3c71..f657c12 100644
--- a/src/process-row.vala
+++ b/src/process-row.vala
@@ -40,7 +40,7 @@ namespace Usage
[GtkChild]
private Gtk.Label load_label;
- private Act.User user;
+ private Fdo.AccountsUser user;
public Process process { get; private set; }
public bool max_usage { get; private set; }
@@ -61,14 +61,26 @@ namespace Usage
{
this.type = type;
this.process = process;
- this.user = Act.UserManager.get_default().get_user_by_id(process.uid);
load_icon(process.display_name);
update();
- this.user.notify["is-loaded"].connect(() => {
- update_user_tag();
- });
+ load_user_account();
+ }
+
+ private async void load_user_account() {
+ try {
+ Fdo.Accounts accounts = yield Bus.get_proxy (BusType.SYSTEM,
+ "org.freedesktop.Accounts",
+ "/org/freedesktop/Accounts");
+ var user_account_path = yield accounts.FindUserById ((int64)process.uid);
+ this.user = yield Bus.get_proxy (BusType.SYSTEM,
+ "org.freedesktop.Accounts",
+ user_account_path);
+ update_user_tag();
+ } catch (Error e) {
+ warning ("Unable to obtain user account: %s", e.message);
+ }
}
private void load_icon(string display_name)
@@ -114,11 +126,11 @@ namespace Usage
private void update_user_tag()
{
+ if (user == null)
+ return;
+
remove_user_tag();
- if(user.is_loaded)
- {
- create_user_tag();
- }
+ create_user_tag();
}
private void remove_user_tag()
@@ -131,50 +143,27 @@ namespace Usage
private void create_user_tag()
{
- user_tag_box.visible = true;
-
- var tag_label = user.real_name.split(" ");
- if (user.real_name.contains("User for") ||
- user.real_name.contains("Default user for"))
- user_tag_label.label = tag_label[tag_label.length - 1];
- else
- user_tag_label.label = user.real_name;
-
string class_name = "";
- if(is_regular_user())
+ if(user.LocalAccount)
{
class_name = CSS_TAG_USER;
}
- else if(is_root_user())
+ else if(user.AccountType == UserAccountType.ADMINISTRATOR)
{
class_name = CSS_TAG_ROOT;
}
- else if(is_system_user())
+ else if(user.SystemAccount)
{
class_name = CSS_TAG_SYSTEM;
}
- user_tag_box.get_style_context().add_class(class_name);
-
- if(is_logged_in())
- {
- user_tag_box.visible = false;
- }
- }
- private bool is_regular_user(){
- return user.is_local_account();
- }
-
- private bool is_root_user(){
- return user.uid == 0;
- }
-
- private bool is_system_user(){
- return !is_regular_user() && !is_root_user();
+ user_tag_box.get_style_context().add_class(class_name);
+ user_tag_label.label = user.UserName;
+ user_tag_box.visible = !is_logged_in();
}
private bool is_logged_in(){
- return user.user_name == GLib.Environment.get_user_name();
+ return user.UserName == GLib.Environment.get_user_name();
}
private void check_max_usage()
diff --git a/src/utils.vala b/src/utils.vala
index 7432648..21c0f83 100644
--- a/src/utils.vala
+++ b/src/utils.vala
@@ -80,4 +80,24 @@ namespace Usage
return (field + (((255 - field) / 100) * percentage)) / 255;
}
}
+
+ public enum UserAccountType {
+ STANDARD,
+ ADMINISTRATOR,
+ }
+
+ [DBus (name = "org.freedesktop.Accounts")]
+ public interface Fdo.Accounts : Object {
+ public abstract async string FindUserById (int64 id) throws IOError;
+ }
+
+ [DBus (name = "org.freedesktop.Accounts.User")]
+ public interface Fdo.AccountsUser : Object {
+ public abstract bool SystemAccount { get; }
+ public abstract bool LocalAccount { get; }
+ public abstract int32 AccountType { get; }
+ public abstract string RealName { owned get; }
+ public abstract string UserName { owned get; }
+ public abstract uint64 Uid { get; }
+ }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]