[nautilus-actions] Migrate all I/O providers preferences



commit a91b5d4656acb49ae3ae9cd39818734b71a75d58
Author: Pierre Wieser <pwieser trychlos org>
Date:   Fri Jan 7 16:02:32 2011 +0100

    Migrate all I/O providers preferences
    
    Also make sure that GConf i/o provider is locked ad the system level, by setting it
    as locked, not readable and not writable.

 ChangeLog                    |    2 +
 src/utils/na-gconf2key.sh.in |   87 +++++++++++++++++++++++++++++++++++++-----
 2 files changed, 79 insertions(+), 10 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 086079e..534b2cf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -96,6 +96,8 @@
 
 	* src/utils/na-gconf2key.sh.in:
 	Make sure that GConf is at the end of the list of I/O providers.
+	Make sure that GConf is locked.
+	Migrate all I/O provider preferences.
 
 	* configure.ac:
 	* src/utils/Makefile.am:
diff --git a/src/utils/na-gconf2key.sh.in b/src/utils/na-gconf2key.sh.in
index b8181cb..d03eec1 100644
--- a/src/utils/na-gconf2key.sh.in
+++ b/src/utils/na-gconf2key.sh.in
@@ -204,7 +204,8 @@ opt_delete_def="no"
 na_package="/apps/@PACKAGE@"
 na_configurations="${na_package}/configurations"
 na_preferences="${na_package}/preferences"
-na_providers="${na_package}/providers"
+na_mandatory="${na_package}/mandatory"
+na_providers="${na_package}/io-providers"
 na_print_program="@bindir@/nautilus-actions-print"
 
 # loop over command line arguments
@@ -376,6 +377,16 @@ function add_pref
 	echo "${_key} = ${_newvalue}" >> ${my_tmproot}.${_group}
 }
 
+function add_pref_provider
+{
+	typeset _group="${1}"
+	typeset _key="${2}"
+	typeset _value="${3}"
+
+	typeset _groupname="$(echo "${_group}" | sed 's/ /_/g')"
+	echo "${_key} = ${value}" >> ${my_tmproot}.${_groupname}
+}
+
 function create_first_level
 {
 	typeset _newvalue="$(echo "$1" | sed -e 's/^\[//' -e 's/]$//' -e 's/,/;/g');"
@@ -424,8 +435,7 @@ command "mkdir -p ${destdir}"
 destconf=${destdir}/@PACKAGE  conf
 rm -f ${my_tmproot}.nact
 rm -f ${my_tmproot}.runtime
-rm -f ${my_tmproot}.zero
-have_level_zero=0
+rm -f ${my_tmproot}.io-provider_*
 
 gconftool-2 --all-entries ${na_preferences} | while read key x value; do
 	case ${key} in
@@ -527,7 +537,7 @@ gconftool-2 --all-entries ${na_preferences} | while read key x value; do
 			;;
 		iprefs-level-zero)
 			# for now, keep the level zero order as a runtime preference
-			#let have_level_zero+=1
+			# in nautilus-actions.conf
 			#create_first_level "${value}"
 			add_pref "runtime" "items-level-zero-order" list "${value}"
 			;;
@@ -567,21 +577,78 @@ gconftool-2 --all-entries ${na_preferences} | while read key x value; do
 	esac
 done
 
-nbprefs=$(cat ${my_tmproot}.nact ${my_tmproot}.runtime | wc -l)
+# migrate mandatory keys
+# /apps/nautilus-actions/mandatory/all/locked -> [runtime]
+# /apps/nautilus-actions/mandatory/<provider_id>/locked -> [io-provider <provider_id>]
+if [ $(id -u) -eq 0 ]; then
+	for dir in $(gconftool-2 --all-dirs ${na_mandatory}); do
+		bdir=$(basename ${dir})
+		if [ "${bdir}" != "na-gconf" ]; then
+			value=$(gconftool-2 --get ${dir}/locked 2>/dev/null)
+			if [ "${value}" != "" ]; then
+				[ "${bdir}" = "all" ] && group="runtime" || group="io-provider ${bdir}"
+				[ "${bdir}" = "all" ] && key="io-providers-all-locked" || key="locked"
+				add_pref_provider "${group}" "${key}" "${value}"
+			fi
+		fi
+	done
+	# as a security - while we are root -, we force the GConf i/o provider to be locked
+	cat <<! >${my_tmproot}.io-provider_na-gconf
+locked = true
+readable = false
+writable = false
+!
+fi
+
+# migrate io-providers keys
+# fully disabling (not reconducting its keys)
+for dir in $(gconftool-2 --all-dirs ${na_providers}); do
+	bdir=$(basename ${dir})
+	if [ "${bdir}" != "na-gconf" ]; then
+		gconftool-2 --all-entries ${dir} | while read key x value; do
+			case ${key} in
+				read-at-startup)
+					add_pref_provider "io-provider ${bdir}" "readable" "${value}"
+					;;
+				writable)
+					add_pref_provider "io-provider ${bdir}" "${key}" "${value}"
+					;;
+			esac
+		done
+	fi
+done
+
+nbprefs=$(cat ${my_tmproot}.nact ${my_tmproot}.runtime ${my_tmproot}.io-provider_* 2>/dev/null | wc -l)
 
 if [ ${nbprefs} -gt 0 ]; then
-	cat <<! >${destconf}
+	rm -f ${destconf}
+	if [ -s ${my_tmproot}.nact ]; then
+		cat <<! >>${destconf}
+
 [nact]
-$(sort < ${my_tmproot}.nact)
+$(sort < ${my_tmproot}.nact 2>/dev/null)
+!
+	fi
+	if [ -s ${my_tmproot}.runtime ]; then
+		cat <<! >>${destconf}
 
 [runtime]
-$(sort < ${my_tmproot}.runtime)
+$(sort < ${my_tmproot}.runtime 2>/dev/null)
+!
+	fi
+	for f in $(ls -1 ${my_tmproot}.io-provider_* 2>/dev/null); do
+		group="$(echo ${f} | sed -e "s,^${my_tmproot}\.,," -e 's/_/ /g')"
+		cat <<! >>${destconf}
+
+[${group}]
+$(sort < ${f})
 !
+	done
 fi
 
 msg "${nbprefs} migrated preferences"
 
-#if [ ${have_level_zero} -gt 0 ]; then
+#if [ -s ${my_tmproot}.zero ]; then
 #	cat <<! >${opt_dir}/level-zero.directory
 #[Desktop Entry]
 #$(cat ${my_tmproot}.zero)
@@ -595,7 +662,7 @@ killall gconfd-2
 if [ "${opt_delete}" = "yes" -a ${count} -gt 0 ]; then
 	if [ $(id -u) -eq 0 ]; then
 		# rather a bad hack to find where mandatory keys are stored by GConf
-		# nautilus-actions-delete directly removes our branch from the XML tree!
+		# na-delete-xmltree directly removes our branch from the XML tree!
 		xml=$(find /etc -name gconf.xml.mandatory)/%gconf-tree.xml
 		path='/gconf/dir[ name="apps"]/dir[ name="@PACKAGE@"]'
 		command "@pkglibexecdir@/na-delete-xmltree --path '${path}' --xml ${xml} > ${xml}2"



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]