Skip to content

Commit 6a0fb55

Browse files
Barak A. Pearlmutterbarak
Barak A. Pearlmutter
authored andcommitted
scalable icon and desktop file support
Convert xpm bitmap icon into a scalable svg icon (carefully sized to 64x64 and saved as plain SVG instead of inkscape-extended SVG) Add a .desktop file. Have Makefile.am install the desktop file and icons, including bitmap icons at various resolutions. This is controlled by configuration-time option ./configure --enable-icons for conditional installation of icons and desktop file. Inkscape is used to convert graphics when available as it does a better job than ImageMagick convert, which is used as a fallback. The icon compiled into the executable is also generated from the scalable icon. Add usbview.desktop to distribution tarball.
1 parent 5a99b76 commit 6a0fb55

6 files changed

+154
-188
lines changed

Makefile.am

+68-5
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,72 @@ usbview_SOURCES = \
1414
usbtree.c usbtree.h \
1515
usbparse.c usbparse.h \
1616
configure-dialog.c \
17-
usbview_logo.xpm \
18-
usbview_logo.xcf \
19-
usb_icon.xpm \
20-
usbview.spec
17+
usbview_logo.xpm
2118

22-
EXTRA_DIST = $(man_MANS)
19+
interface.o: $(icon_bitmaps_xpm)
20+
21+
EXTRA_DIST = $(man_MANS) usbview_icon.svg usbview.desktop usbview.spec usbview_logo.xcf
22+
23+
desktopdir = $(datadir)/applications
24+
if DESKTOP
25+
desktop_DATA = usbview.desktop
26+
endif
27+
28+
icondir = $(datadir)/icons
29+
30+
icon_bitmaps_png = \
31+
hicolor/16x16/apps/usbview.png \
32+
hicolor/22x22/apps/usbview.png \
33+
hicolor/32x32/apps/usbview.png \
34+
hicolor/48x48/apps/usbview.png \
35+
hicolor/64x64/apps/usbview.png \
36+
hicolor/256x256/apps/usbview.png
37+
38+
icon_bitmaps_xpm = hicolor/64x64/apps/usbview_icon.xpm
39+
40+
if ICONS
41+
nobase_icon_DATA = $(icon_scalable) $(icon_bitmaps_png)
42+
endif
43+
44+
$(icon_bitmaps_png): usbview_icon.svg
45+
mkdir -p $$(dirname $@)
46+
if USE_INKSCAPE
47+
$(INKSCAPE) --export-png=$@ --export-width=$$(basename $$(dirname $$(dirname $@))) $<
48+
else
49+
if USE_CONVERT
50+
$(CONVERT) -geometry $$(basename $$(dirname $$(dirname $@))) $< $@
51+
else
52+
echo "error: unable to generate $@ from $<"
53+
exit 1
54+
endif
55+
endif
56+
57+
$(icon_bitmaps_xpm): usbview_icon.svg
58+
mkdir -p $$(dirname $@)
59+
if HAVE_CONVERT
60+
$(CONVERT) -geometry $$(basename $$(dirname $$(dirname $@))) $< $@
61+
else
62+
echo "error: unable to generate $@ from $<"
63+
exit 1
64+
endif
65+
66+
icon_scalable = hicolor/scalable/apps/usbview.svg
67+
68+
$(icon_scalable): usbview_icon.svg
69+
mkdir -p $$(dirname $@)
70+
cp $< $@
71+
72+
CLEANFILES = $(icon_scalable) $(icon_bitmaps_png) $(icon_bitmaps_xpm)
73+
74+
# gtk_update_icon_cache = gtk-update-icon-cache -f -t $(datadir)/icons/hicolor; gtk-update-icon-cache -f -t $(datadir)/icons/HighContrast
75+
#
76+
# install-data-hook: update-icon-cache
77+
# uninstall-hook: update-icon-cache
78+
# update-icon-cache:
79+
# @-if test -z "$(DESTDIR)"; then \
80+
# echo "Updating Gtk icon cache."; \
81+
# $(gtk_update_icon_cache); \
82+
# else \
83+
# echo "*** Icon cache not updated. After (un)install, run this:"; \
84+
# echo "*** $(gtk_update_icon_cache)"; \
85+
# fi

configure.ac

+34
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,43 @@ AC_CONFIG_SRCDIR([usbtree.c])
88
AC_CONFIG_HEADERS([config.h])
99
AM_INIT_AUTOMAKE([foreign subdir-objects -Wall])
1010

11+
# Process options.
12+
13+
AC_MSG_CHECKING([whether to try to install icons])
14+
AC_ARG_ENABLE(icons,
15+
[AS_HELP_STRING([--enable-icons],[try to install icons (default=yes)])],
16+
[icons=$enableval],
17+
[icons=yes])
18+
AC_MSG_RESULT([$icons])
19+
20+
AC_MSG_CHECKING([whether to try to install desktop file])
21+
AC_ARG_ENABLE(desktop,
22+
[AS_HELP_STRING([--enable-desktop],[try to install desktop file (default=yes)])],
23+
[desktop=$enableval],
24+
[desktop=yes])
25+
AC_MSG_RESULT([$desktop])
26+
1127
# Checks for programs.
1228

1329
AC_PROG_CC
30+
AC_CHECK_PROG([have_inkscape],[inkscape],[yes],[no])
31+
AC_CHECK_PROG([have_convert],[convert],[yes],[no])
32+
33+
# Set automake conditionals.
34+
35+
AC_SUBST(INKSCAPE,[inkscape])
36+
AC_SUBST(CONVERT,[convert])
37+
AM_CONDITIONAL(USE_INKSCAPE,[test "$have_inkscape" = "yes"])
38+
AM_CONDITIONAL(USE_CONVERT, [test "$have_inkscape" = "no" && test "$have_convert" = "yes"])
39+
AM_CONDITIONAL(HAVE_INKSCAPE,[test "$have_inkscape" = "yes"])
40+
AM_CONDITIONAL(HAVE_CONVERT, [test "$have_convert" = "yes"])
41+
42+
AS_IF([test "$have_inkscape" = "no" && test "$have_convert" = "no"],
43+
[AC_MSG_WARN([no bitmap conversion utility, disabling icon installation])
44+
icons=no])
45+
46+
AM_CONDITIONAL(DESKTOP,[test x${desktop} = xyes])
47+
AM_CONDITIONAL(ICONS,[test x${icons} = xyes])
1448

1549
# Checks for libraries.
1650

interface.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include <gtk/gtk.h>
2626

2727
#include "usbtree.h"
28-
#include "usb_icon.xpm"
28+
#include "hicolor/64x64/apps/usbview_icon.xpm"
2929

3030
GtkWidget *treeUSB;
3131
GtkTreeStore *treeStore;
@@ -55,7 +55,7 @@ create_windowMain ()
5555
gtk_window_set_title (GTK_WINDOW (windowMain), "USB Viewer");
5656
gtk_window_set_default_size (GTK_WINDOW (windowMain), 600, 300);
5757

58-
icon = gdk_pixbuf_new_from_xpm_data((const char **)usb_icon_xpm);
58+
icon = gdk_pixbuf_new_from_xpm_data((const char **)usbview_icon);
5959
gtk_window_set_icon(GTK_WINDOW(windowMain), icon);
6060

6161
vbox1 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);

usb_icon.xpm

-181
This file was deleted.

usbview.desktop

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[Desktop Entry]
2+
Name=USBView
3+
Comment=View USB devices attached to system
4+
Exec=su-to-root -X -c /usr/bin/usbview
5+
Icon=usbview
6+
Terminal=false
7+
Type=Application
8+
Keywords=USB;devices;connected;removable;
9+
Categories=GTK;HardwareSettings;Settings;

usbview_icon.svg

+41
Loading

0 commit comments

Comments
 (0)