[gnome-commander] Set XDG_DATA_DIRS and override png mimetype priority
- From: Uwe Scholz <uwescholz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-commander] Set XDG_DATA_DIRS and override png mimetype priority
- Date: Sat, 30 May 2015 15:16:39 +0000 (UTC)
commit 610eb4ff42a85b513585064bd2141a280873dcd5
Author: Mamoru TASAKA <mtasaka fedoraproject org>
Date: Sat May 30 22:16:05 2015 +0900
Set XDG_DATA_DIRS and override png mimetype priority
https://bugzilla.gnome.org/show_bug.cgi?id=734032
http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
sets XDG_DATA_DIRS can override where shared-mime-info
files are to be searched.
Set XDG_DATA_DIRS and install gnome-commander specific
mime xml file to override png mimetype priority.
configure.ac | 6 ++++++
data/Makefile.am | 17 +++++++++++++++++
data/gnome-commander-mime.xml | 12 ++++++++++++
src/Makefile.am | 4 +++-
src/gnome-cmd-mime-config.cc | 32 ++++++++++++++++++++++++++++++++
src/gnome-cmd-mime-config.h | 24 ++++++++++++++++++++++++
src/main.cc | 3 +++
7 files changed, 97 insertions(+), 1 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 5070efb..df4cb68 100644
--- a/configure.ac
+++ b/configure.ac
@@ -419,6 +419,12 @@ AC_DEFINE_UNQUOTED(HELP_DIR, "${PREFIX}/share/gnome/help/${PACKAGE}", "")
PLUGIN_LIBTOOL_FLAGS="-module -avoid-version"
AC_SUBST(PLUGIN_LIBTOOL_FLAGS)
+dnl =====================
+dnl Check for binary
+dnl =====================
+AC_CHECK_PROG(HAVE_UPDATE_MIME_DATABASE, update-mime-database, "yes", "no")
+AC_SUBST(HAVE_UPDATE_MIME_DATABASE)
+
dnl =====================
dnl Write some output
diff --git a/data/Makefile.am b/data/Makefile.am
index b3bb327..93995c9 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -10,6 +10,11 @@ desktop_DATA = $(desktop_in_files:.desktop.in=.desktop)
appdatadir = $(datadir)/appdata
appdata_in_files = @PACKAGE appdata xml in
appdata_DATA = $(appdata_in_files:.xml.in=.xml)
+
+mimetopdir = $(datadir)/@PACKAGE@/mime
+mimexmldir = $(mimetopdir)/packages
+mimexml_DATA = gnome-commander-mime.xml
+
@INTLTOOL_XML_RULE@
#BUILT_SOURCES = @PACKAGE -@VERSION ebuild
@@ -21,7 +26,19 @@ ebuild_DATA_NOINST = @PACKAGE -@VERSION ebuild
ln -sf @PACKAGE ebuild @PACKAGE -@VERSION ebuild
EXTRA_DIST = $(appdata_in_files) $(desktop_in_files) @PACKAGE spec $(ebuild_files) $(ebuild_DATA_NOINST)
+EXTRA_DIST += $(mimexml_DATA)
DISTCLEANFILES = $(appdata_DATA) $(desktop_DATA)
+HAVE_UPDATE_MIME_DATABASE = @HAVE_UPDATE_MIME_DATABASE@
+
+install-data-hook:
+ test "x$(HAVE_UPDATE_MIME_DATABASE)" == "xyes" && \
+ update-mime-database -V $(DESTDIR)/$(mimetopdir)
+
+uninstall-hook:
+ for target in $(DESTDIR)/$(mimetopdir)/* ; \
+ do test "x$${target}" != "x$(DESTDIR)/$(mimexmldir)" && rm -rf $${target} ; done
+
+
-include $(top_srcdir)/git.mk
diff --git a/data/gnome-commander-mime.xml b/data/gnome-commander-mime.xml
new file mode 100644
index 0000000..0ebcae5
--- /dev/null
+++ b/data/gnome-commander-mime.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
+ <mime-type type="image/png">
+ <comment>PNG image</comment>
+ <magic priority="90">
+ <match type="string" value="\x89PNG" offset="0">
+ <match value="CgBI" type="string" offset="12"/>
+ </match>
+ </magic>
+ <glob weight="10" pattern="*.png"/>
+ </mime-type>
+</mime-info>
diff --git a/src/Makefile.am b/src/Makefile.am
index 2ffcb65..fbce0e7 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -11,7 +11,8 @@ AM_CPPFLAGS = \
$(UNIQUE_CFLAGS) \
$(PYTHON_CFLAGS) \
-DDATADIR=\""$(datadir)"\"\
- -DPLUGIN_DIR=\""$(libdir)/$(PACKAGE)/plugins"\"
+ -DPLUGIN_DIR=\""$(libdir)/$(PACKAGE)/plugins"\" \
+ -DMIMETOP_DIR=\""$(datadir)/@PACKAGE@/"\"
bin_PROGRAMS = gnome-commander gcmd-block
@@ -51,6 +52,7 @@ gnome_commander_SOURCES = \
gnome-cmd-main-menu.h gnome-cmd-main-menu.cc \
gnome-cmd-main-win.h gnome-cmd-main-win.cc \
gnome-cmd-menu-button.h gnome-cmd-menu-button.cc \
+ gnome-cmd-mime-config.h gnome-cmd-mime-config.cc \
gnome-cmd-notebook.h gnome-cmd-notebook.cc \
gnome-cmd-path.h \
gnome-cmd-pixmap.h gnome-cmd-pixmap.cc \
diff --git a/src/gnome-cmd-mime-config.cc b/src/gnome-cmd-mime-config.cc
new file mode 100644
index 0000000..118a24e
--- /dev/null
+++ b/src/gnome-cmd-mime-config.cc
@@ -0,0 +1,32 @@
+/*
+ GNOME Commander - A GNOME based file manager
+ Copyright (C) 2015 Mamoru TASAKA
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <glib.h>
+
+void gnome_cmd_mime_config(void)
+{
+ const gchar *old_xdg_data_dirs = g_getenv("XDG_DATA_DIRS");
+ gchar *new_xdg_data_dirs =
+ g_strdup_printf(
+ "%s:%s",
+ MIMETOP_DIR,
+ (old_xdg_data_dirs ? old_xdg_data_dirs : "/usr/share/:/usr/share/local/")
+ );
+ g_setenv("XDG_DATA_DIRS", new_xdg_data_dirs, 1);
+ g_free(new_xdg_data_dirs);
+}
diff --git a/src/gnome-cmd-mime-config.h b/src/gnome-cmd-mime-config.h
new file mode 100644
index 0000000..d74581f
--- /dev/null
+++ b/src/gnome-cmd-mime-config.h
@@ -0,0 +1,24 @@
+/*
+ GNOME Commander - A GNOME based file manager
+ Copyright (C) 2015 Mamoru TASAKA
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GNOME_CMD_MIME_CONFIG_H__
+#define __GNOME_CMD_MIME_CONFIG_H__
+
+void gnome_cmd_mime_config(void);
+
+#endif
diff --git a/src/main.cc b/src/main.cc
index 09ddf5f..51bce7e 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -31,6 +31,7 @@ extern "C"
#include "gnome-cmd-includes.h"
#include "gnome-cmd-main-win.h"
+#include "gnome-cmd-mime-config.h"
#include "gnome-cmd-data.h"
#include "gnome-cmd-user-actions.h"
#include "owner.h"
@@ -118,6 +119,8 @@ int main (int argc, char *argv[])
locale_information = localeconv();
#endif
+ gnome_cmd_mime_config();
+
option_context = g_option_context_new (PACKAGE);
g_option_context_add_main_entries (option_context, options, NULL);
program = gnome_program_init (PACKAGE, VERSION, LIBGNOMEUI_MODULE,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]