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
36 extern string? g_win32_get_package_installation_directory_of_module(void *module);
39 public Gdk.Pixbuf? find_icon_sized(string name, Gtk.IconSize icon_size)
42 Gtk.icon_size_lookup(icon_size, out width, out height);
43 return find_icon(name, width);
46 /* Portability hack: making Gtk icon themes work on Windows is
47 * difficult; let's just bundle the icons that are necessary and
51 public bool gtk_available = false;
53 public Gdk.Pixbuf? get_pixbuf(IdCard id)
55 return find_icon("avatar-default", 48);
58 public Gdk.Pixbuf? find_icon(string name, int size)
65 string? base_path = g_win32_get_package_installation_directory_of_module(null);
67 // Hack to allow running within the source tree
68 int last_dir_index = base_path.last_index_of_char('\\');
69 if (base_path.substring(last_dir_index) == "\\.libs" || base_path.substring(last_dir_index) == "src")
70 base_path = base_path.slice(0, last_dir_index);
72 string? filename = Path.build_filename(base_path, "share", "icons", "%s.png".printf(name));
73 return new Gdk.Pixbuf.from_file_at_size(filename, size, size);
76 var icon_theme = Gtk.IconTheme.get_default();
77 return icon_theme.load_icon(name, size, Gtk.IconLookupFlags.FORCE_SIZE);
82 stdout.printf("Error loading icon '%s': %s\n", name, e.message);
87 public extern unowned string GetUserName();
88 public extern unowned string GetFlatStoreUsersFilePath();
90 public bool UserForcesFlatFileStore()
92 string username = GetUserName();
93 string flatstore_users_filename = GetFlatStoreUsersFilePath();
94 FileStream flatstore_users = FileStream.open(flatstore_users_filename, "r");
95 if (flatstore_users == null) {
98 string? flatstore_username = null;
99 while ((flatstore_username = flatstore_users.read_line()) != null) {
100 if (username == flatstore_username) {
107 internal Gdk.Color make_color(uint16 red, uint16 green, uint16 blue)
109 Gdk.Color color = Gdk.Color();
117 internal void set_atk_relation(Widget widget, Widget target_widget, Atk.RelationType relationship)
119 var atk_widget = widget.get_accessible();
120 var atk_target_widget = target_widget.get_accessible();
122 atk_widget.add_relationship(relationship, atk_target_widget);
126 internal Widget make_ta_fingerprint_widget(TrustAnchor trust_anchor)
128 var fingerprint_label = new Label(_("SHA-256 fingerprint:"));
129 fingerprint_label.set_alignment(0, 0.5f);
131 var fingerprint = new TextView();
132 fingerprint.set_editable(false);
133 var buffer = fingerprint.get_buffer();
134 buffer.set_text(colonize(trust_anchor.server_cert), -1);
135 fingerprint.wrap_mode = WrapMode.WORD_CHAR;
137 set_atk_relation(fingerprint_label, fingerprint, Atk.RelationType.LABEL_FOR);
139 var fingerprint_width_constraint = new ScrolledWindow(null, null);
140 fingerprint_width_constraint.set_policy(PolicyType.NEVER, PolicyType.NEVER);
141 fingerprint_width_constraint.set_shadow_type(ShadowType.IN);
142 fingerprint_width_constraint.set_size_request(400, 60);
143 fingerprint_width_constraint.add_with_viewport(fingerprint);
145 var vbox = new VBox(false, 0);
146 vbox.pack_start(fingerprint_label, true, true, 2);
147 vbox.pack_start(fingerprint_width_constraint, true, true, 2);
151 // Yeah, it doesn't mean "colonize" the way you might think... :-)
152 internal static string colonize(string input) {
153 return_if_fail(input.length % 2 == 0);
157 while (i < input.length) {
161 result += input[i : i + 2];