Add flatstore-users
[moonshot-ui.git] / src / moonshot-utils.vala
index da075b4..25af1e4 100644 (file)
@@ -14,12 +14,20 @@ public Gdk.Pixbuf? find_icon_sized (string name, Gtk.IconSize icon_size)
  * load them manually.
  */
 
+public bool gtk_available = false;
+
+public Gdk.Pixbuf? get_pixbuf(IdCard id)
+{
+    return find_icon("avatar-default", 48);
+}
+
 public Gdk.Pixbuf? find_icon (string name, int size)
 {
+    if (!gtk_available)
+        return null;
     try
     {
 #if OS_WIN32
-print("Windows\n");
         string? base_path = g_win32_get_package_installation_directory_of_module (null);
 
         // Hack to allow running within the source tree
@@ -29,18 +37,8 @@ print("Windows\n");
 
         string? filename = Path.build_filename (base_path, "share", "icons", "%s.png".printf (name));
         return new Gdk.Pixbuf.from_file_at_size (filename, size, size);
-//#elif OS_MACOS
-/*
-print("MacOS\n");
-        string? base_path = " /Users/pete/moonshot-ui";
-         string? filename = Filename.display_name(Path.build_filename (base_path, "share", "icons", "%s.png".printf (name)));
-print("%s\n".printf(filename));
-size_t x, y;
-        return new Gdk.Pixbuf.from_file (filename);
-//        return new Gdk.Pixbuf.from_file_at_size (filename, -1, -1);
-*/
+
 #else
-print("Linux\n");
         var icon_theme = Gtk.IconTheme.get_default ();
         return icon_theme.load_icon (name, size, Gtk.IconLookupFlags.FORCE_SIZE);
 #endif
@@ -51,3 +49,23 @@ print("Linux\n");
         return null;
     }
 }
+
+public extern unowned string GetUserName();
+public extern unowned string GetFlatStoreUsersFilePath();
+
+public bool UserForcesFlatFileStore()
+{
+    string username = GetUserName();
+    string flatstore_users_filename = GetFlatStoreUsersFilePath();
+    FileStream flatstore_users = FileStream.open(flatstore_users_filename, "r");
+    if (flatstore_users == null) {
+        return false;
+    }
+    string? flatstore_username = null;
+    while ((flatstore_username = flatstore_users.read_line()) != null) {
+        if (username == flatstore_username) {
+            return true;
+        }
+    }
+    return false;
+}