Skip to content

Commit

Permalink
audgui: Use scalable+themable icons for the preferences window.
Browse files Browse the repository at this point in the history
  • Loading branch information
jlindgren90 committed Jan 20, 2018
1 parent b43e5cf commit 9a6dae9
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 12 deletions.
9 changes: 8 additions & 1 deletion Makefile
Expand Up @@ -13,7 +13,14 @@ DATA = AUTHORS \
images/connectivity.png \
images/info.png \
images/playlist.png \
images/plugins.png
images/plugins.png \
images/applications-graphics.svg \
images/applications-internet.svg \
images/applications-system.svg \
images/audio-volume-medium.svg \
images/audio-x-generic.svg \
images/dialog-information.svg \
images/preferences-system.svg

include buildsys.mk
include extra.mk
Expand Down
1 change: 1 addition & 0 deletions images/applications-graphics.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions images/applications-internet.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions images/applications-system.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions images/audio-volume-medium.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions images/audio-x-generic.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions images/dialog-information.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions images/preferences-system.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 39 additions & 0 deletions src/libaudgui/init.cc
Expand Up @@ -127,6 +127,38 @@ void audgui_hide_unique_window (int id)
gtk_widget_destroy (windows[id]);
}

static void load_fallback_icon (const char * icon, int size)
{
const char * data_dir = aud_get_path (AudPath::DataDir);
StringBuf svg_name = str_concat ({icon, ".svg"});
StringBuf path = filename_build ({data_dir, "images", svg_name});
auto pixbuf = gdk_pixbuf_new_from_file_at_size (path, size, size, nullptr);

if (pixbuf)
{
gtk_icon_theme_add_builtin_icon (icon, size, pixbuf);
g_object_unref (pixbuf);
}
}

static void load_fallback_icons ()
{
/* keep this in sync with the list in prefs-window.cc */
static const char * const categories[] = {
"applications-graphics",
"applications-internet",
"applications-system",
"audio-volume-medium",
"audio-x-generic",
"dialog-information",
"preferences-system"
};

int category_size = audgui_to_native_dpi (48);
for (const char * icon : categories)
load_fallback_icon (icon, category_size);
}

static void playlist_set_playing_cb (void *, void *)
{
audgui_pixbuf_uncache ();
Expand All @@ -140,13 +172,20 @@ static void playlist_position_cb (void * list, void *)

EXPORT void audgui_init ()
{
static bool icons_loaded = false;
assert (aud_get_mainloop_type () == MainloopType::GLib);

if (init_count ++)
return;

gtk_init (nullptr, nullptr);

if (! icons_loaded)
{
load_fallback_icons ();
icons_loaded = true;
}

aud_config_set_defaults ("audgui", audgui_defaults);

status_init ();
Expand Down
24 changes: 13 additions & 11 deletions src/libaudgui/prefs-window.cc
Expand Up @@ -46,7 +46,7 @@ enum CategoryViewCols {
};

struct Category {
const char * icon_path;
const char * icon;
const char * name;
};

Expand Down Expand Up @@ -77,14 +77,15 @@ enum {
CATEGORY_ADVANCED
};

/* keep this in sync with the list in load_fallback_icons (init.cc) */
static const Category categories[] = {
{ "appearance.png", N_("Appearance") },
{ "audio.png", N_("Audio") },
{ "connectivity.png", N_("Network") },
{ "playlist.png", N_("Playlist")} ,
{ "info.png", N_("Song Info") },
{ "plugins.png", N_("Plugins") },
{ "advanced.png", N_("Advanced") }
{ "applications-graphics", N_("Appearance") },
{ "audio-volume-medium", N_("Audio") },
{ "applications-internet", N_("Network") },
{ "audio-x-generic", N_("Playlist")} ,
{ "dialog-information", N_("Song Info") },
{ "applications-system", N_("Plugins") },
{ "preferences-system", N_("Advanced") }
};

static const PluginCategory plugin_categories[] = {
Expand Down Expand Up @@ -480,7 +481,8 @@ static void fill_category_list (GtkTreeView * treeview, GtkNotebook * notebook)
GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_INT);
gtk_tree_view_set_model (treeview, (GtkTreeModel *) store);

const char * data_dir = aud_get_path (AudPath::DataDir);
GtkIconTheme * icon_theme = gtk_icon_theme_get_default ();
int icon_size = audgui_to_native_dpi (48);

for (const Category & category : categories)
{
Expand All @@ -492,8 +494,8 @@ static void fill_category_list (GtkTreeView * treeview, GtkNotebook * notebook)
gtk_list_store_set (store, & iter, CATEGORY_VIEW_COL_NAME,
gettext (category.name), -1);

StringBuf path = filename_build ({data_dir, "images", category.icon_path});
AudguiPixbuf img (gdk_pixbuf_new_from_file (path, nullptr));
AudguiPixbuf img (gtk_icon_theme_load_icon (icon_theme,
category.icon, icon_size, (GtkIconLookupFlags) 0, nullptr));

if (img)
gtk_list_store_set (store, & iter, CATEGORY_VIEW_COL_ICON, img.get (), -1);
Expand Down

0 comments on commit 9a6dae9

Please sign in to comment.