2 * Copyright (c) 2011-2014, JANET(UK)
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of JANET(UK) nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 extern string? g_win32_get_package_installation_directory_of_module(void *module);
36 public Gdk.Pixbuf? find_icon_sized(string name, Gtk.IconSize icon_size)
39 Gtk.icon_size_lookup(icon_size, out width, out height);
40 return find_icon(name, width);
43 /* Portability hack: making Gtk icon themes work on Windows is
44 * difficult; let's just bundle the icons that are necessary and
48 public bool gtk_available = false;
50 public Gdk.Pixbuf? get_pixbuf(IdCard id)
52 return find_icon("avatar-default", 48);
55 public Gdk.Pixbuf? find_icon(string name, int size)
62 string? base_path = g_win32_get_package_installation_directory_of_module(null);
64 // Hack to allow running within the source tree
65 int last_dir_index = base_path.last_index_of_char('\\');
66 if (base_path.substring(last_dir_index) == "\\.libs" || base_path.substring(last_dir_index) == "src")
67 base_path = base_path.slice(0, last_dir_index);
69 string? filename = Path.build_filename(base_path, "share", "icons", "%s.png".printf(name));
70 return new Gdk.Pixbuf.from_file_at_size(filename, size, size);
73 var icon_theme = Gtk.IconTheme.get_default();
74 return icon_theme.load_icon(name, size, Gtk.IconLookupFlags.FORCE_SIZE);
79 stdout.printf("Error loading icon '%s': %s\n", name, e.message);
84 public extern unowned string GetUserName();
85 public extern unowned string GetFlatStoreUsersFilePath();
87 public bool UserForcesFlatFileStore()
89 string username = GetUserName();
90 string flatstore_users_filename = GetFlatStoreUsersFilePath();
91 FileStream flatstore_users = FileStream.open(flatstore_users_filename, "r");
92 if (flatstore_users == null) {
95 string? flatstore_username = null;
96 while ((flatstore_username = flatstore_users.read_line()) != null) {
97 if (username == flatstore_username) {