Tinkering with configure.ac to allow different versions of GTK+
[moonshot-ui.git] / src / moonshot-utils.vala
1 #if OS_WIN32
2 extern string? g_win32_get_package_installation_directory_of_module (void *module);
3 #endif
4
5 public Gdk.Pixbuf? find_icon_sized (string name, Gtk.IconSize icon_size)
6 {
7     int width, height;
8     Gtk.icon_size_lookup (icon_size, out width, out height);
9     return find_icon (name, width);
10 }
11
12 /* Portability hack: making Gtk icon themes work on Windows is
13  * difficult; let's just bundle the icons that are necessary and
14  * load them manually.
15  */
16
17 public Gdk.Pixbuf? find_icon (string name, int size)
18 {
19     try
20     {
21 #if OS_WIN32
22 print("Windows\n");
23         string? base_path = g_win32_get_package_installation_directory_of_module (null);
24
25         // Hack to allow running within the source tree
26         int last_dir_index = base_path.last_index_of_char ('\\');
27         if (base_path.substring (last_dir_index) == "\\.libs" || base_path.substring (last_dir_index) == "src")
28             base_path = base_path.slice(0, last_dir_index);
29
30         string? filename = Path.build_filename (base_path, "share", "icons", "%s.png".printf (name));
31         return new Gdk.Pixbuf.from_file_at_size (filename, size, size);
32 //#elif OS_MACOS
33 /*
34 print("MacOS\n");
35         string? base_path = " /Users/pete/moonshot-ui";
36          string? filename = Filename.display_name(Path.build_filename (base_path, "share", "icons", "%s.png".printf (name)));
37 print("%s\n".printf(filename));
38         return new Gdk.Pixbuf.from_file (filename);
39 //        return new Gdk.Pixbuf.from_file_at_size (filename, -1, -1);
40 */
41 #else
42 print("Linux\n");
43         var icon_theme = Gtk.IconTheme.get_default ();
44         return icon_theme.load_icon (name, size, Gtk.IconLookupFlags.FORCE_SIZE);
45 #endif
46     }
47     catch (Error e)
48     {
49         stdout.printf("Error loading icon '%s': %s\n", name, e.message);
50         return null;
51     }
52 }