public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-dev] enhancement for doicon/newicon in eutils.eclass
@ 2012-05-20 23:24 hasufell
  2012-05-20 23:36 ` Alexis Ballier
                   ` (3 more replies)
  0 siblings, 4 replies; 22+ messages in thread
From: hasufell @ 2012-05-20 23:24 UTC (permalink / raw
  To: gentoo-dev

[-- Attachment #1: Type: text/plain, Size: 233 bytes --]

I want support for installing icons into the appropriate directories
which are under /usr/share/icons/... and not just pixmaps.

proposal attached + diff

This should not break existing ebuilds. Tested a bit and open for review
now.

[-- Attachment #2: eutils-doicon-newicon.eclass --]
[-- Type: text/plain, Size: 3127 bytes --]

# @FUNCTION: doicon
# @USAGE: doicon [options] <icons>
# @DESCRIPTION:
# Install icon into the icon directory /usr/share/icons or into
# /usr/share/pixmaps if "--size" is not set.
# This is useful in conjunction with creating desktop/menu files.
#
# @CODE
#  options:
#  -s, --size
#    !!! must specify to install into /usr/share/icons/... !!!
#    size of the icon, like 48 or 48x48
#    supported icon sizes are:
#    16 22 24 32 36 48 64 72 96 128 192 256 scalable
# -c, --context
#    defaults to "apps"
# -t, --theme
#    defaults to "hicolor"
#
# icons: list of icons
# @CODE
#
# example 1:
#    doicon foobar.png fuqbar.svg
#    results in: insinto /usr/share/pixmaps ; doins foobar.png fuqbar.svg
#
# example 2:
#    doicon -s 48 foobar.png fuqbar.svg
#    results in: insinto /usr/share/icons/hicolor/48x48/apps ; doins foobar.png fuqbar.svg
#    
doicon() {
	(
	# wrap the env here so that the 'insinto' call
	# doesn't corrupt the env of the caller
	local size dir i ret
	local context=apps
	local theme=hicolor

	while [[ $# -gt 0 ]] ; do
		case ${1} in
		-s|--size)
			case ${2} in
			16|22|24|32|36|48|64|72|96|128|192|256)
				size=${2}x${2};;
			16x16|22x22|24x24|32x32|36x36|48x48|64x64|72x72|96x96|128x128|192x192|256x256)
				size=${2};;
			scalable)
				size=scalable;;
			*)
				eqawarn "${2} is an unsupported icon size!"
				((++ret));;
			esac
			shift 2;;
		-t|--theme)
			theme=${2}
			shift 2;;
		-c|--context)
			context=${2}
			shift 2;;
		*)
			if [[ -z ${size} ]] ; then
				dir=/usr/share/pixmaps
			else
				dir=/usr/share/icons/${theme}/${size}/${context}
			fi
			
			insinto "${dir}"

			if [[ -f ${1} ]] ; then
				doins "${1}"
				((ret+=$?))
			elif [[ -d ${1} ]] ; then
				for i in "${1}"/*.{png,svg} ; do
					doins "${i}"
					((ret+=$?))
				done
			else
				eqawarn "${1} is not a valid file/directory!"
				((++ret))
			fi
			shift 1 ;;
		esac
	done
	exit ${ret}
	)
}

# @FUNCTION: newicon
# @USAGE: newicon [options] <icon> <newname>
# @DESCRIPTION:
# Like doicon, install the specified icon as newname.
#
# example 1:
#    newicon foobar.png NEWNAME.png
#    results in: insinto /usr/share/pixmaps ; newins foobar.png NEWNAME.png
#
# example 2:
#    newicon -s 48 foobar.png NEWNAME.png 
#    results in: insinto /usr/share/icons/hicolor/48x48/apps ; newins foobar.png NEWNAME.png
#
newicon() {
	(
	# wrap the env here so that the 'insinto' call
	# doesn't corrupt the env of the caller
	local size dir ret
	local context=apps
	local theme=hicolor

	while [[ $# -gt 0 ]] ; do
	case ${1} in
	-s|--size)
		case ${2} in
		16|22|24|32|36|48|64|72|96|128|192|256)
			size=${2}x${2};;
		16x16|22x22|24x24|32x32|36x36|48x48|64x64|72x72|96x96|128x128|192x192|256x256)
			size=${2};;
		scalable)
			size=scalable;;
		*)
			eqawarn "${2} is an unsupported icon size!"
			((++ret));;
		esac
		shift 2;;
	-t|--theme)
		theme=${2}
		shift 2;;
	-c|--context)
		context=${2}
		shift 2;;
	*)
		break ;;
	esac
	done

	if [[ -z ${size} ]] ; then
		dir=/usr/share/pixmaps
	else
		dir=/usr/share/icons/${theme}/${size}/${context}
	fi

	insinto "${dir}"
	newins "$@"
	((ret+=$?))

	exit ${ret}
	)
}

[-- Attachment #3: eutils.eclass.diff --]
[-- Type: text/x-patch, Size: 3827 bytes --]

--- eclass/eutils.eclass
+++ eclass/eutils.eclass
@@ -945,43 +945,150 @@
 }
 
 # @FUNCTION: doicon
-# @USAGE: <list of icons>
+# @USAGE: doicon [options] <icons>
 # @DESCRIPTION:
-# Install the list of icons into the icon directory (/usr/share/pixmaps).
+# Install icon into the icon directory /usr/share/icons or into
+# /usr/share/pixmaps if "--size" is not set.
 # This is useful in conjunction with creating desktop/menu files.
+#
+# @CODE
+#  options:
+#  -s, --size
+#    !!! must specify to install into /usr/share/icons/... !!!
+#    size of the icon, like 48 or 48x48
+#    supported icon sizes are:
+#    16 22 24 32 36 48 64 72 96 128 192 256 scalable
+# -c, --context
+#    defaults to "apps"
+# -t, --theme
+#    defaults to "hicolor"
+#
+# icons: list of icons
+# @CODE
+#
+# example 1:
+#    doicon foobar.png fuqbar.svg
+#    results in: insinto /usr/share/pixmaps ; doins foobar.png fuqbar.svg
+#
+# example 2:
+#    doicon -s 48 foobar.png fuqbar.svg
+#    results in: insinto /usr/share/icons/hicolor/48x48/apps ; doins foobar.png fuqbar.svg
+#    
 doicon() {
 	(
 	# wrap the env here so that the 'insinto' call
 	# doesn't corrupt the env of the caller
-	local i j ret
-	insinto /usr/share/pixmaps
-	for i in "$@" ; do
-		if [[ -f ${i} ]] ; then
-			doins "${i}"
-			((ret+=$?))
-		elif [[ -d ${i} ]] ; then
-			for j in "${i}"/*.png ; do
-				doins "${j}"
+	local size dir i ret
+	local context=apps
+	local theme=hicolor
+
+	while [[ $# -gt 0 ]] ; do
+		case ${1} in
+		-s|--size)
+			case ${2} in
+			16|22|24|32|36|48|64|72|96|128|192|256)
+				size=${2}x${2};;
+			16x16|22x22|24x24|32x32|36x36|48x48|64x64|72x72|96x96|128x128|192x192|256x256)
+				size=${2};;
+			scalable)
+				size=scalable;;
+			*)
+				eqawarn "${2} is an unsupported icon size!"
+				((++ret));;
+			esac
+			shift 2;;
+		-t|--theme)
+			theme=${2}
+			shift 2;;
+		-c|--context)
+			context=${2}
+			shift 2;;
+		*)
+			if [[ -z ${size} ]] ; then
+				dir=/usr/share/pixmaps
+			else
+				dir=/usr/share/icons/${theme}/${size}/${context}
+			fi
+			
+			insinto "${dir}"
+
+			if [[ -f ${1} ]] ; then
+				doins "${1}"
 				((ret+=$?))
-			done
-		else
-			((++ret))
-		fi
+			elif [[ -d ${1} ]] ; then
+				for i in "${1}"/*.{png,svg} ; do
+					doins "${i}"
+					((ret+=$?))
+				done
+			else
+				eqawarn "${1} is not a valid file/directory!"
+				((++ret))
+			fi
+			shift 1 ;;
+		esac
 	done
 	exit ${ret}
 	)
 }
 
 # @FUNCTION: newicon
-# @USAGE: <icon> <newname>
+# @USAGE: newicon [options] <icon> <newname>
 # @DESCRIPTION:
-# Like all other new* functions, install the specified icon as newname.
+# Like doicon, install the specified icon as newname.
+#
+# example 1:
+#    newicon foobar.png NEWNAME.png
+#    results in: insinto /usr/share/pixmaps ; newins foobar.png NEWNAME.png
+#
+# example 2:
+#    newicon -s 48 foobar.png NEWNAME.png 
+#    results in: insinto /usr/share/icons/hicolor/48x48/apps ; newins foobar.png NEWNAME.png
+#
 newicon() {
 	(
 	# wrap the env here so that the 'insinto' call
 	# doesn't corrupt the env of the caller
-	insinto /usr/share/pixmaps
+	local size dir ret
+	local context=apps
+	local theme=hicolor
+
+	while [[ $# -gt 0 ]] ; do
+	case ${1} in
+	-s|--size)
+		case ${2} in
+		16|22|24|32|36|48|64|72|96|128|192|256)
+			size=${2}x${2};;
+		16x16|22x22|24x24|32x32|36x36|48x48|64x64|72x72|96x96|128x128|192x192|256x256)
+			size=${2};;
+		scalable)
+			size=scalable;;
+		*)
+			eqawarn "${2} is an unsupported icon size!"
+			((++ret));;
+		esac
+		shift 2;;
+	-t|--theme)
+		theme=${2}
+		shift 2;;
+	-c|--context)
+		context=${2}
+		shift 2;;
+	*)
+		break ;;
+	esac
+	done
+
+	if [[ -z ${size} ]] ; then
+		dir=/usr/share/pixmaps
+	else
+		dir=/usr/share/icons/${theme}/${size}/${context}
+	fi
+
+	insinto "${dir}"
 	newins "$@"
+	((ret+=$?))
+
+	exit ${ret}
 	)
 }
 

^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2012-06-02 14:57 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-20 23:24 [gentoo-dev] enhancement for doicon/newicon in eutils.eclass hasufell
2012-05-20 23:36 ` Alexis Ballier
2012-05-20 23:49   ` hasufell
2012-05-21  0:01     ` [gentoo-dev] " Jonathan Callen
2012-05-21  5:30       ` hasufell
2012-05-21 14:41         ` Mike Gilbert
2012-05-21 17:14 ` [gentoo-dev] " Michał Górny
2012-05-21 17:32   ` Samuli Suominen
2012-05-21 19:58   ` hasufell
2012-05-22  2:35     ` Mike Frysinger
2012-05-22  2:49 ` Mike Frysinger
2012-05-24  0:16   ` hasufell
2012-05-24  0:30     ` Mike Frysinger
2012-05-24  0:39       ` hasufell
2012-05-24  0:43       ` hasufell
2012-05-24  5:53         ` Michał Górny
2012-05-24  1:04 ` [gentoo-dev] " hasufell
2012-06-01 22:49   ` Mike Frysinger
2012-06-02  2:50     ` hasufell
2012-06-02  2:58       ` hasufell
2012-06-02  4:48       ` Mike Frysinger
2012-06-02 14:54         ` hasufell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox