- Install mimeedit script pulled from svn to support mime edit menu (bug

458667)
i9cf
Mamoru Tasaka 16 years ago
parent 5e25e9b084
commit 34beb74c75

@ -0,0 +1,4 @@
#!/bin/bash
export PATH=/usr/libexec/gnome-commander:$PATH
exec gnome-commander $@

@ -4,14 +4,19 @@
# mv trunk %%{name}-%%{version}-%%{extratag} # mv trunk %%{name}-%%{version}-%%{extratag}
# tar cjf %%{name}-%%{version}-%%{extratag}.tar.bz2 %%{name}-%%{version}-%%{extratag} # tar cjf %%{name}-%%{version}-%%{extratag}.tar.bz2 %%{name}-%%{version}-%%{extratag}
# Source10 is created by:
# svn co http://svn.gnome.org/svn/gnome-commander/branches/gcmd-1-3/tools/mimeedit/
# cp -p mimeedit/mimeedit.sh mimeedit-rev%%{mimeedit_rev}.sh
%define EXIV2_REQ 0.14 %define EXIV2_REQ 0.14
%define TAGLIB_REQ 1.4 %define TAGLIB_REQ 1.4
%define LIBGSF_REQ 1.12.0 %define LIBGSF_REQ 1.12.0
%define use_autotool 0 %define use_autotool 0
%define if_pre 0 %define if_pre 0
%define main_release 2 %define main_release 3
#%%define extratag svn1901_trunk #%%define extratag svn1901_trunk
%define mimeedit_rev 1958
%if 0%{?if_pre} > 0 %if 0%{?if_pre} > 0
%define use_autotool 1 %define use_autotool 1
@ -30,7 +35,10 @@ Group: Applications/File
License: GPLv2+ License: GPLv2+
URL: http://www.nongnu.org/gcmd/ URL: http://www.nongnu.org/gcmd/
Source0: ftp://ftp.gnome.org/pub/GNOME/sources/%{name}/1.2/%{name}-%{version}%{?extratag:-%extratag}.tar.bz2 Source0: ftp://ftp.gnome.org/pub/GNOME/sources/%{name}/1.2/%{name}-%{version}%{?extratag:-%extratag}.tar.bz2
Source1: gnome-commander.sh
Source10: mimeedit-svn%{mimeedit_rev}.sh
#Patch0: gnome-commander-rev1874-hexmode-display.patch #Patch0: gnome-commander-rev1874-hexmode-display.patch
Patch10: mimeedit-svn1958.diff
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildRequires: desktop-file-utils BuildRequires: desktop-file-utils
@ -99,6 +107,9 @@ ansluta till FTP-servrar och SMB-nätverk.
sh autogen.sh sh autogen.sh
%endif %endif
cp -p %SOURCE10 mimeedit.sh
%patch10 -p0
%{__sed} -i.pylib \ %{__sed} -i.pylib \
-e 's|\$PY_EXEC_PREFIX/lib|%{_libdir}|' \ -e 's|\$PY_EXEC_PREFIX/lib|%{_libdir}|' \
configure configure
@ -109,6 +120,9 @@ function replace_icon(){
xargs %{__sed} -i -e "s|\"$1\"|\"$2\"|" xargs %{__sed} -i -e "s|\"$1\"|\"$2\"|"
} }
# Replace icon name due to gnome-icon-theme 2.23.x change
# (many icons are removed)
replace_icon gnome-fs-directory gtk-directory replace_icon gnome-fs-directory gtk-directory
replace_icon gnome-fs-ftp folder-remote replace_icon gnome-fs-ftp folder-remote
replace_icon gnome-fs-home user-home replace_icon gnome-fs-home user-home
@ -120,7 +134,11 @@ replace_icon gnome-fs-web folder-remote
%endif %endif
%build %build
# Install wrapper script, and move binaries to
# %%{_libexecdir}/%%{name}
%configure \ %configure \
--bindir=%{_libexecdir}/%{name} \
--disable-scrollkeeper \ --disable-scrollkeeper \
--enable-python --enable-python
%{__make} %{?_smp_mflags} %{__make} %{?_smp_mflags}
@ -132,6 +150,7 @@ replace_icon gnome-fs-web folder-remote
DESTDIR=%{buildroot} \ DESTDIR=%{buildroot} \
install install
# Desktop file
desktop-file-install \ desktop-file-install \
--delete-original \ --delete-original \
--vendor '' \ --vendor '' \
@ -139,6 +158,14 @@ desktop-file-install \
--dir %{buildroot}%{_datadir}/applications \ --dir %{buildroot}%{_datadir}/applications \
%{buildroot}%{_datadir}/applications/%{name}.desktop %{buildroot}%{_datadir}/applications/%{name}.desktop
# Install wrapper
%{__mkdir_p} %{buildroot}%{_bindir}
%{__install} -cpm 0755 %SOURCE1 %{buildroot}%{_bindir}/%{name}
# install gnome-file-types-properties (bug 458667)
%{__install} -cpm 0755 mimeedit.sh \
%{buildroot}%{_libexecdir}/%{name}/gnome-file-types-properties
%{__rm} -f %{buildroot}%{_libdir}/%{name}/*.{a,la} %{__rm} -f %{buildroot}%{_libdir}/%{name}/*.{a,la}
%{__rm} -f %{buildroot}%{_libdir}/%{name}/*/*.{a,la} %{__rm} -f %{buildroot}%{_libdir}/%{name}/*/*.{a,la}
@ -165,6 +192,7 @@ scrollkeeper-update -q || :
%doc doc/*.txt %doc doc/*.txt
%{_bindir}/* %{_bindir}/*
%{_libexecdir}/%{name}/
%{_libdir}/%{name}/ %{_libdir}/%{name}/
%{_mandir}/man1/%{name}.1* %{_mandir}/man1/%{name}.1*
@ -177,6 +205,10 @@ scrollkeeper-update -q || :
%{_datadir}/pixmaps/%{name}/ %{_datadir}/pixmaps/%{name}/
%changelog %changelog
* Tue Aug 12 2008 Mamoru Tasaka <mtasaka@ioa.s.u-tokyo.ac.jp> - 1.2.7-3
- Install mimeedit script pulled from svn to support mime edit
menu (bug 458667)
* Wed Jul 30 2008 Mamoru Tasaka <mtasaka@ioa.s.u-tokyo.ac.jp> - 1.2.7-2 * Wed Jul 30 2008 Mamoru Tasaka <mtasaka@ioa.s.u-tokyo.ac.jp> - 1.2.7-2
- F-10+: Fix icon name due to gnome-icon-theme 2.23.x change - F-10+: Fix icon name due to gnome-icon-theme 2.23.x change

@ -0,0 +1,40 @@
Index: mimeedit.sh
===================================================================
--- mimeedit.sh (revision 1958)
+++ mimeedit.sh (working copy)
@@ -342,6 +342,7 @@
# The .desktop file editor
#
function dtfedit (){
+ TMPFILE=`mktemp /tmp/gnome-commander.XXXXXX`
USER_DTF="$DT_FILE-$EXT"
if [ -n "$DT_FILE" ]
then
@@ -350,15 +351,22 @@
then
TO_EDIT="$DATA_DIR/$USER_DTF"
else
- TO_EDIT="$GDATA_DIR/$DT_FILE.desktop"
+ DT_FILE_PREFIX=$(echo $DT_FILE | sed -e 's|-[0-9][0-9]*||')
+ DT_FILE_SUFFIX=$(echo $DT_FILE | sed -n -e 's|^.*-\([0-9][0-9]*\)$|\1|p')
+ if [ -e $DATA_DIR/${DT_FILE_PREFIX}-usercreated-$DT_FILE_SUFFIX.desktop ]
+ then
+ TO_EDIT="$DATA_DIR/${DT_FILE_PREFIX}-usercreated-$DT_FILE_SUFFIX.desktop"
+ else
+ TO_EDIT="$GDATA_DIR/$DT_FILE.desktop"
+ fi
fi
cat "$TO_EDIT" | zenity --height="350" --width="550" --text-info --editable \
- --title "Edititng the file: $USER_DTF" > $UTMP.$USER_DTF
- if [ -s $UTMP.$USER_DTF ]
+ --title "Edititng the file: $USER_DTF" > $TMPFILE
+ if [ -s $TMPFILE ]
then
- mv $UTMP.$USER_DTF $DATA_DIR/$USER_DTF
+ mv $TMPFILE $DATA_DIR/$USER_DTF
else
- rm -f $UTMP.$USER_DTF
+ rm -f $TMPFILE
DT_FILE=""
fi
fi

@ -0,0 +1,376 @@
#!/bin/bash
#
# gnome-file-types-properties -
# A zenity-script for chosing preferred applications.
# Written by Magnus Stålnacke (jemamo at telia.com)
# Version 0.8.4 Nov. 30 2007
#
export LANG=en_US.utf8
ARGU="$1"
UTMP="/tmp/$(whoami)"
DATA_DIR="$HOME/.local/share/applications"
GDATA_DIR="/usr/share/applications"
G_CACHE="$GDATA_DIR/mimeinfo.cache"
U_CACHE="$DATA_DIR/mimeinfo.cache"
SUBC="/usr/share/mime/subclasses"
U_DEF="$DATA_DIR/defaults.list"
EXT="usercreated.desktop"
NONEW=1
#
# Create dirs in users home if missing.
#
if [ -e "$DATA_DIR" ]; then :; else mkdir $DATA_DIR;fi
if [ -e "$U_DEF" ]
then :;
else
echo "[Default Applications]" > $DATA_DIR/defaults.list
fi
#
# Check how we got started.
#
function checkarg (){
if [ -n "$ARGU" ]
then
if [ -e "$ARGU" ]
then
chkmtpe
deflist
else
showhelp
fi
else
selfile
dtfedit
if [ -n "$DT_FILE" ]
then
update
fi
fi
}
#
# Mimetype check.
#
function chkmtpe (){
MTPE=$(gnomevfs-info -s "$ARGU" | grep "MIME type" | sed 's/.*: //')
echo "The mimetype is: $MTPE"
}
#
# Build a list with registered apps for this mimetype.
#
function deflist (){
if [ -e "$UTMP.avail" ]; then cleanup;fi
# Create the list in "$UTMP.avail" to be used by the zenity list-box
if [ "$NONEW" == 1 ]
then
echo "FALSE Add_New_App New" > "$UTMP.avail"
fi
# Get all sub-mimetypes, one per row.
SUB="$(grep -hs "^$MTPE" $SUBC $G_CACHE $U_CACHE | awk -F= '{print $1}' | sed 's/ /\n/g')"
# Get all .desktopfiles for the above mimetypes
MTPEs=$(grep -hs "$SUB" $U_CACHE $G_CACHE | sed 's/.*=//g;s/;$//g;s/;/\n/g;')
if [ -n "$SUB" ]
then
for i in $(echo "$MTPEs" | sort -u); do
echo "FALSE $i $(grep -hs "^Name=" $GDATA_DIR/$i $DATA_DIR/$i | \
sed 's/Name=//;s/ /_/g')" >> "$UTMP.avail"
done
fi
# Change FALSE to TRUE for the default app.
if grep -q "desktop" "$UTMP.avail"
then
DEF_APP=$(gnomevfs-info -s "$ARGU" | grep "Default app" | sed 's/.*: //')
sed -i "s|FALSE $DEF_APP|TRUE $DEF_APP|" "$UTMP.avail"
fi
# Show the list
zenity --height="350" --width="550" --list --radiolist --text \
"The list below show applications that already have an entry for the mimetype:
$MTPE on your system, meaning they are registered to be able
to deal with this mimetype. You can choose your preferred default application
by checking the radiobutton. The script will adjust the mimetype settings in
your local home directory, thus not changing anything systemwide.
If you wish you can add an application that is not in the list by checking the first
option in list named Add_New_App
Please select" \
--column "Pick" --column ".desktop file" --column "Application" \
$(cat "$UTMP.avail") > "$UTMP.chosen"
retval=$?
choice=$(cat "$UTMP.chosen")
if grep -q "$MTPE=$choice" $U_DEF
then
retval=2
fi
case $retval in
0)
DEF_CH=$(grep -s "$choice" "$UTMP.avail" | awk '{print $2}')
DEF_NME=$(grep -s "$choice" "$UTMP.avail" | awk '{print $3}')
if [ "$DEF_CH" = Add_New_App ]
then
newmime
fi
if [ -z "$NOCH" ]
then
if grep -q "$MTPE" $U_DEF
then
# Set the users chosen default app for the existing mime.
sed -i "s|$MTPE=.*|$MTPE=$DEF_CH|" $U_DEF
else
# If no user default for this mimetype, add it.
echo "$MTPE=$DEF_CH" >> $U_DEF
fi
update
zenity --info --text "Default application to handle $MTPE is set to $DEF_NME"
fi;;
1)
echo "Cancel pressed.";;
-1)
echo "ESC pressed.";;
2)
zenity --info --text "Default was not changed.";;
esac
cleanup
}
#
# Show an input box for new app to handle the mimetype.
#
function newmime (){
NEWAPP=$(zenity --entry --text \
"Fill in the Name and command for the application you want to handle the
mimetype: $MTPE separate them with a colon (:)
Separate Name and Command with a colon. If you omit the command, or
type something that is not in your path, you will get the chance to
provide the command with full path by a file chooser dialog.")
case $? in
0)
if echo "$NEWAPP" | grep -q ":"
then
NAME=$(echo "$NEWAPP" | awk -F: '{print $1}')
CMD=$(echo "$NEWAPP" | awk -F: '{print $2}')
if [ -n "$NAME" ]
then
check
usercreate
else
zenity --error --text "Application name is missing"
newmime
fi
else
zenity --error --text "Separator missing"
newmime
fi
;;
1)
deflist
;;
-1)
deflist
;;
esac
NOCH=yes
}
#
# Check if the command exists in path, if not give the
# user a filechooser.
#
function check (){
if which $CMD >&/dev/null
then
CMD=`which $CMD`
else
CMD=$(zenity --file-selection --filename=/ --title="Chose application")
if [ -z $CMD ]
then
newmime
fi
fi
}
#
# Create a new *.desktop file for the added app that can handle
# the mimetype in question.
#
function usercreate(){
APP=$(basename "$CMD")
USER_APP="$DATA_DIR/$APP-$EXT"
if cat $G_CACHE $U_CACHE | grep "$MTPE" | grep -q "$APP"
then
zenity --error --text "The mime type: $MTPE is alredy assigned to: $APP"
NOCH=yes
else
if [ -e "$USER_APP" ]
then
sed -i "s|MimeType=|MimeType=$MTPE;|g" $USER_APP
update
zenity --info --text \
"The mime type: $MTPE is now registered to be handled by: $APP"
else
cat <<EOF >$USER_APP
[Desktop Entry]
Encoding=UTF-8
Name=$NAME
Exec=$CMD
Type=Application
Terminal=false
NoDisplay=true
MimeType=$MTPE;
EOF
fi
fi
if [ -z "$NOCH" ]
then
zenity --question --text \
"The created $(basename "$USER_APP") can now be edited manually, to add, remove or change options, do you want to do this now?
This file should work as is, so you can safely cancel this operation, but advanced users may want to edit options to their liking. But due to a bug this editor cannot handle '%' charachters and replaces them with garbage."
VAL=$?
if [ "$VAL" == 0 ]
then
DT_FILE="$APP"
dtfedit
update
else
update
fi
zenity --info --text "$APP is now registered to handle: $MTPE"
fi
NONEW=2
deflist
}
#
# Update the users mime chache and set the defaults
# first from the defaults.list file
#
function update (){
update-desktop-database $DATA_DIR
for i in $(sed '/\[.*\]/d' $U_DEF); do
MTYPE=$(echo "$i" | awk -F= '{print $1}')
M_FIL=$(echo "$i" | awk -F= '{print $2}')
if grep -q "$MTYPE" $U_CACHE
then
sed -i "\|$MTYPE|s|$M_FIL||;s|$MTYPE=|$i;|;s|;;|;|" $U_CACHE
else
echo "$i" >> $U_CACHE
fi
done
# If there are rows with empty mimetypes, delete them.
sed -i '/.*=$/d' $U_CACHE
}
#
# Give the user a helping hand.
#
function showhelp (){
echo
echo "Usage: $(basename $0) [ARGUMENT]"
echo '''
-h, -?, --help Show this help and exit.
DESCRIPTION
This script is dependent on zenity for creating its GUI. It is
to be used as a tool for choosing the default application or to
run for different type of files (mimetypes). It modifies or add
files in "$HOME/.local/share/applications"
When passed a valid filename it checks its mimetype as interpreted
by gnomevfs, it will show a list of already registered applications
able to handle the mimetype in question, the user can change default
application in this list. The list also contains an option to add
the Name and command of a program that is not registered to be able
to open files of the mimetype. After any changes this script will
run the update-desktop-database to update the users mime cache.
When executed without any argument, the script will list all
applications associated with a mimetype. When selecting an item from
this list, the user will be able to edit the options for the selected
application. The edited file will be saved in the above path and the
update-desktop-database is executed.
When given an invalid argument or any of the options -h -? --help,
this text is shown.
'''
}
#
# Remove tempfiles.
#
function cleanup (){
rm -f "$UTMP.avail"
rm -f "$UTMP.chosen"
}
#
# The .desktop file selector
#
function selfile (){
DT_FILE=$(for i in $GDATA_DIR/*.desktop $DATA_DIR/*.desktop; do
if grep -q "MimeType" $i
then
BNME=$(basename $i | sed 's/\.desktop//;s/-usercreated//')
if [ -e $DATA_DIR/$BNME-$EXT ]
then
i="$DATA_DIR/$BNME-$EXT"
fi
CMD=$(grep -m 1 "^Exec" $i | sed "s/^Exec=//")
NME=$(grep -m 1 "^Name=" $i | sed 's/^Name=//')
echo "$BNME---$NME---\"$CMD\""
fi
done | sort -u | sed 's/---/\n/g' | zenity --list --width="550" --height="400" \
--column="Base name" --column="Program name" --column="Program command" \
--print-column="1" --text "Select item below.
By selecting an item in this list and klick OK, you will get another window where
you can edit the file that contains the options of the selected application. The
edited file will end up in your: $DATA_DIR
Pressing "Esc", click Cancel or use the window close (X) button will close without
any changes in this or the following editor window. Be aware that the editor do
have problems with the (%)percent charachter and may replace it by garbage.")
}
#
# The .desktop file editor
#
function dtfedit (){
USER_DTF="$DT_FILE-$EXT"
if [ -n "$DT_FILE" ]
then
# Chose to edit users own file if exist
if [ -e $DATA_DIR/$USER_DTF ]
then
TO_EDIT="$DATA_DIR/$USER_DTF"
else
TO_EDIT="$GDATA_DIR/$DT_FILE.desktop"
fi
cat "$TO_EDIT" | zenity --height="350" --width="550" --text-info --editable \
--title "Edititng the file: $USER_DTF" > $UTMP.$USER_DTF
if [ -s $UTMP.$USER_DTF ]
then
mv $UTMP.$USER_DTF $DATA_DIR/$USER_DTF
else
rm -f $UTMP.$USER_DTF
DT_FILE=""
fi
fi
}
#
# Check if we have zenity installed then start this mess.
#
if which zenity >&/dev/null
then
checkarg
else
echo "Error: zenity not found!"
fi
Loading…
Cancel
Save