diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2011-10-11 15:58:38 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2011-10-11 20:29:06 -0700 |
commit | 7df7518625b5a80aa1ff35c8c6e49e6e257672d9 (patch) | |
tree | 02d7b54df83f0d0e01cc6c7b87f61775e01260a5 | |
parent | 089ab5e97c50de9e0f566bda9e881e0e3c7cb0bf (diff) | |
download | subsurface-7df7518625b5a80aa1ff35c8c6e49e6e257672d9.tar.gz |
Have "make install" act more as expected for a desktop application
I'm trying to get subsurface to get closer to becoming a "regular desktop
application"; so far this is based on the recommendations and guidelines
on OpenSUSE and Fedora.
The icon is now named subsurface.svg and make install installs it in the
correct location. At runtime subsurface first checks if an icon is
installed and if it is it uses that - otherwise it falls back to the old
code that tries to read the svg file from the current directory.
We also install a subsurface.desktop file
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | Makefile | 16 | ||||
-rw-r--r-- | gtk-gui.c | 30 | ||||
-rw-r--r-- | subsurface.desktop | 10 | ||||
-rw-r--r-- | subsurface.svg (renamed from icon.svg) | 0 |
4 files changed, 50 insertions, 6 deletions
@@ -4,9 +4,18 @@ CC=gcc CFLAGS=-Wall -Wno-pointer-sign -g INSTALL=install -prefix = $(HOME) +# these locations seem to work for SuSE and Fedora +# prefix = $(HOME) +prefix = /usr DESTDIR = $(prefix)/bin +DESKTOPDIR = $(prefix)/share/applications +ICONPATH = $(prefix)/share/icons/hicolor +ICONDIR = $(ICONPATH)/scalable/apps +gtk_update_icon_cache = gtk-update-icon-cache -f -t $(ICONPATH) + NAME = subsurface +ICONFILE = $(NAME).svg +DESKTOPFILE = $(NAME).desktop # find libdivecomputer; we don't trust pkg-config here given how young # libdivecomputer still is - so we check /usr/local and /usr and then we @@ -49,6 +58,11 @@ $(NAME): $(OBJS) install: $(NAME) $(INSTALL) -d -m 755 $(DESTDIR) $(INSTALL) $(NAME) $(DESTDIR) + $(INSTALL) -d -m 755 $(DESKTOPDIR) + $(INSTALL) $(DESKTOPFILE) $(DESKTOPDIR) + $(INSTALL) -d -m 755 $(ICONDIR) + $(INSTALL) $(ICONFILE) $(ICONDIR) + $(gtk_update_icon_cache) parse-xml.o: parse-xml.c dive.h $(CC) $(CFLAGS) `pkg-config --cflags glib-2.0` -c `xml2-config --cflags` parse-xml.c @@ -43,6 +43,7 @@ void repaint_dive(void) } static char *existing_filename; +static gboolean need_icon = TRUE; static void on_info_bar_response(GtkWidget *widget, gint response, gpointer data) @@ -428,11 +429,14 @@ static void about_dialog(GtkWidget *w, gpointer data) { const char *logo_property = NULL; GdkPixbuf *logo = NULL; - GtkWidget *image = gtk_image_new_from_file("icon.svg"); - if (image) { - logo = gtk_image_get_pixbuf(GTK_IMAGE(image)); - logo_property = "logo"; + if (need_icon) { + GtkWidget *image = gtk_image_new_from_file("subsurface.svg"); + + if (image) { + logo = gtk_image_get_pixbuf(GTK_IMAGE(image)); + logo_property = "logo"; + } } gtk_show_about_dialog(NULL, @@ -441,6 +445,7 @@ static void about_dialog(GtkWidget *w, gpointer data) "license", "GPLv2", "version", VERSION_STRING, "copyright", "Linus Torvalds 2011", + "logo-icon-name", "subsurface", /* Must be last: */ logo_property, logo, NULL); @@ -596,6 +601,8 @@ void init_ui(int argc, char **argv) GtkWidget *equipment; GtkWidget *menubar; GtkWidget *vbox; + GdkScreen *screen; + GtkIconTheme *icon_theme=NULL; GtkSettings *settings; static const GtkTargetEntry notebook_target = { "GTK_NOTEBOOK_TAB", GTK_TARGET_SAME_APP, 0 @@ -627,7 +634,20 @@ void init_ui(int argc, char **argv) error_info_bar = NULL; win = gtk_window_new(GTK_WINDOW_TOPLEVEL); - gtk_window_set_icon_from_file(GTK_WINDOW(win), "icon.svg", NULL); + g_set_application_name ("subsurface"); + /* Let's check if the subsurface icon has been installed or if + * we need to try to load it from the current directory */ + screen = gdk_screen_get_default(); + if (screen) + icon_theme = gtk_icon_theme_get_for_screen(screen); + if (icon_theme) { + if (gtk_icon_theme_has_icon(icon_theme, "subsurface")) { + need_icon = FALSE; + gtk_window_set_default_icon_name ("subsurface"); + } + } + if (need_icon) + gtk_window_set_icon_from_file(GTK_WINDOW(win), "subsurface.svg", NULL); g_signal_connect(G_OBJECT(win), "delete-event", G_CALLBACK(on_delete), NULL); g_signal_connect(G_OBJECT(win), "destroy", G_CALLBACK(on_destroy), NULL); main_window = win; diff --git a/subsurface.desktop b/subsurface.desktop new file mode 100644 index 000000000..6fdec1053 --- /dev/null +++ b/subsurface.desktop @@ -0,0 +1,10 @@ +[Desktop Entry] +Type=Application +Name=subsurface +GenericName=dive log program +Comment=manage and display dive computer data +Icon=subsurface +Exec=subsurface +Terminal=false +Categories=Accessories; + diff --git a/icon.svg b/subsurface.svg index 29410c8ee..29410c8ee 100644 --- a/icon.svg +++ b/subsurface.svg |