From e25db9343935a42df633aa66b7367d262ced8248 Mon Sep 17 00:00:00 2001 From: Sam Thursfield Date: Fri, 20 May 2011 14:52:54 +0100 Subject: [PATCH] Load icons manually on Windows Icon themes don't really make sense (or work) when the app is running in an independent sandbox prefix. Instead, the icons we need will be put in share/icons and loaded directly using GdkPixbuf. --- Makefile.am | 3 ++- src/moonshot-identities-manager.vala | 14 +----------- src/moonshot-utils.vala | 41 ++++++++++++++++++++++++++++++++++++ src/moonshot-window.vala | 29 +++++++------------------ windows/app.wxs | 22 ++++++------------- 5 files changed, 58 insertions(+), 51 deletions(-) create mode 100644 src/moonshot-utils.vala diff --git a/Makefile.am b/Makefile.am index 4df40bb..d877b2a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -21,7 +21,8 @@ src_moonshot_SOURCES = \ src/moonshot-idcard-widget.vala \ src/moonshot-custom-vbox.vala \ src/moonshot-identities-manager.vala \ - src/moonshot-window.vala + src/moonshot-window.vala \ + src/moonshot-utils.vala src_moonshot_LDADD = \ $(moonshot_LIBS) diff --git a/src/moonshot-identities-manager.vala b/src/moonshot-identities-manager.vala index 7095197..8d5d0c5 100644 --- a/src/moonshot-identities-manager.vala +++ b/src/moonshot-identities-manager.vala @@ -108,19 +108,7 @@ class IdentitiesManager : Object { id_card.issuer = id_card_data[1]; id_card.services = {"email","jabber","irc"}; id_card.nai = id_card.username + "@" + id_card.issuer; - - var icon_theme = Gtk.IconTheme.get_default (); - try - { - id_card.pixbuf = icon_theme.load_icon ("avatar-default", - 48, - Gtk.IconLookupFlags.FORCE_SIZE); - } - catch (Error e) - { - id_card.pixbuf = null; - stdout.printf("Error: %s\n", e.message); - } + id_card.pixbuf = find_icon ("avatar-default", 48); return id_card; } diff --git a/src/moonshot-utils.vala b/src/moonshot-utils.vala new file mode 100644 index 0000000..87c5ff8 --- /dev/null +++ b/src/moonshot-utils.vala @@ -0,0 +1,41 @@ +#if OS_WIN32 +extern string? g_win32_get_package_installation_directory_of_module (void *module); +#endif + +public Gdk.Pixbuf? find_icon_sized (string name, Gtk.IconSize icon_size) +{ + int width, height; + Gtk.icon_size_lookup (icon_size, out width, out height); + return find_icon (name, width); +} + +/* Portability hack: making Gtk icon themes work on Windows is + * difficult; let's just bundle the icons that are necessary and + * load them manually. + */ + +public Gdk.Pixbuf? find_icon (string name, int size) +{ + try + { +#if OS_WIN32 + string? base_path = g_win32_get_package_installation_directory_of_module (null); + + // Hack to allow running within the source tree + int last_dir_index = base_path.last_index_of_char ('\\'); + if (base_path.substring (last_dir_index) == "\\src") + base_path = base_path.slice(0, last_dir_index); + + string? filename = Path.build_filename (base_path, "share", "icons", "%s.png".printf (name)); + return new Gdk.Pixbuf.from_file_at_size (filename, size, size); +#else + var icon_theme = Gtk.IconTheme.get_default (); + return icon_theme.load_icon (name, icon_size, Gtk.IconLookupFlags.FORCE_SIZE); +#endif + } + catch (Error e) + { + stdout.printf("Error loading icon '%s': %s\n", name, e.message); + return null; + } +} diff --git a/src/moonshot-window.vala b/src/moonshot-window.vala index 7ade76a..5fb5d83 100644 --- a/src/moonshot-window.vala +++ b/src/moonshot-window.vala @@ -197,20 +197,7 @@ class MainWindow : Window id_card.username = dialog.username; id_card.password = dialog.password; id_card.nai = id_card.username + "@" + id_card.issuer; - - var icon_theme = IconTheme.get_default (); - try - { - id_card.pixbuf = icon_theme.load_icon ("avatar-default", - 48, - IconLookupFlags.FORCE_SIZE); - } - catch (Error e) - { - id_card.pixbuf = null; - stdout.printf("Error: %s\n", e.message); - } - + id_card.pixbuf = find_icon ("avatar-default", 48); id_card.services = {"email","jabber","irc"}; return id_card; @@ -515,17 +502,18 @@ class MainWindow : Window this.search_entry = new Entry(); set_atk_name_description (search_entry, _("Search entry"), _("Search for a specific ID Card")); - this.search_entry.set_icon_from_icon_name (EntryIconPosition.PRIMARY, - "edit-find-symbolic"); - this.search_entry.set_icon_sensitive (EntryIconPosition.PRIMARY, false); + this.search_entry.set_icon_from_pixbuf (EntryIconPosition.PRIMARY, + find_icon_sized ("edit-find-symbolic", Gtk.IconSize.MENU)); this.search_entry.set_icon_tooltip_text (EntryIconPosition.PRIMARY, _("Search identity or service")); + this.search_entry.set_icon_sensitive (EntryIconPosition.PRIMARY, false); - this.search_entry.set_icon_from_icon_name (EntryIconPosition.SECONDARY, - "edit-clear-symbolic"); - this.search_entry.set_icon_sensitive (EntryIconPosition.SECONDARY, false); + this.search_entry.set_icon_from_pixbuf (EntryIconPosition.SECONDARY, + find_icon_sized ("edit-clear-symbolic", Gtk.IconSize.MENU)); this.search_entry.set_icon_tooltip_text (EntryIconPosition.SECONDARY, _("Clear the current search")); + this.search_entry.set_icon_sensitive (EntryIconPosition.SECONDARY, false); + this.search_entry.icon_press.connect (search_entry_icon_press_cb); this.search_entry.notify["text"].connect (search_entry_text_changed_cb); @@ -655,7 +643,6 @@ class MainWindow : Window // Force specific theme settings on Windows without requiring a gtkrc file Gtk.Settings settings = Gtk.Settings.get_default (); settings.set_string_property ("gtk-theme-name", "ms-windows", "moonshot"); - settings.set_string_property ("gtk-icon-theme-name", "Gnome", "moonshot"); settings.set_long_property ("gtk-menu-images", 0, "moonshot"); #endif diff --git a/windows/app.wxs b/windows/app.wxs index 6daf1d1..c1f098e 100644 --- a/windows/app.wxs +++ b/windows/app.wxs @@ -109,21 +109,12 @@ - - - - - - - - - - - - - - + + + + + @@ -147,8 +138,7 @@ - - + -- 2.1.4