#Maintainer: Maximus (maximus[at]gmail[dot]com)

pkgname=picasa
pkgver=3.0
pkgrel=1mb
arch=i486
source=("http://dl.google.com/linux/deb/pool/non-free/p/picasa/picasa_3.0-current_i386.deb")
sourcetemplate=http://people.salixos.org/maximuus/$pkgname/$pkgver
url=http://picasa.google.com/linux/
options="noautodotnew"

slackdesc=\
(
#|-----handy-ruler------------------------------------------------------|
"picasa - a photo organizer from Google"
"Picasa is a free photo software from Google. This version is Linux"
"compatible. Picasa won't delete your pictures or put them online"
"without your permission."
"This is a preview of the upcoming release of Picasa 3 for Linux."
)


build() {
# prepare directories	
	mkdir -p $startdir/pkg/usr/bin
	mkdir -p $startdir/pkg/usr/lib/mozilla/plugins
	mkdir -p $startdir/pkg/usr/share/{applications,$pkgname-$pkgver}
	mkdir -p $startdir/pkg/etc/gconf/schemas
	mkdir -p $startdir/pkg/usr/share/icons/hicolor/48x48/apps
	mkdir -p $startdir/pkg/usr/doc/$pkgname-$pkgver
	
# extract and copy source
	cd $startdir/src
    ar xv picasa_3.0-current_i386.deb
	tar xzvf data.tar.gz
	rm -rf $startdir/src/opt/google/$pkgname/$pkgver/wine/share/man
	cp -a $startdir/src/opt/google/$pkgname/$pkgver/* $startdir/pkg/usr/share/$pkgname-$pkgver
	cp $startdir/src/usr/share/gconf/schemas/picasa.schemas $startdir/pkg/etc/gconf/schemas/picasa.schemas
	
# create links to libs and binaries
	cd $startdir/pkg/usr/bin
	ln -sf ../share/picasa-3.0/bin/picasa picasa
	ln -sf ../share/picasa-3.0/bin/picasafontcfg picasafontcfg
	cd $startdir/pkg/usr/lib/mozilla/plugins
	ln -sf ../share/picasa-3.0/lib/npPicasa3.so npPicasa3.so
	
# gconf stuff
        export GCONF_CONFIG_SOURCE="xml::$startdir/pkg/etc/gconf/gconf.xml.defaults"
        if [ -d $startdir/pkg/etc/gconf/schemas ]; then
            install -v -d -m755 $startdir/pkg/etc/gconf/gconf.xml.defaults
            SCHEMAS=$startdir/pkg/etc/gconf/schemas
            for schema in $SCHEMAS/*.schemas; do
                gconftool-2 --makefile-install-rule $schema
            done
            # Reset / Verify correct permissions
            ( cd $startdir/pkg/etc/gconf ; find . -type d -exec chmod 755 {} \; )
            ( cd $startdir/pkg/etc/gconf ; find . -type f -exec chmod 644 {} \; )
        fi

# convert and copy icons
	cd $startdir/src
	convert $startdir/src/opt/google/$pkgname/$pkgver/desktop/picasa.xpm picasa.png
	convert $startdir/src/opt/google/$pkgname/$pkgver/desktop/picasa-fontcfg.xpm picasa-fontcfg.png
	cp *.png $startdir/pkg/usr/share/icons/hicolor/48x48/apps	

# copy docs
	mv $startdir/pkg/usr/share/$pkgname-$pkgver/LICENSE.FOSS $startdir/pkg/usr/doc/$pkgname-$pkgver
	mv $startdir/pkg/usr/share/$pkgname-$pkgver/README $startdir/pkg/usr/doc/$pkgname-$pkgver
	
# create desktop files	
	cat > $startdir/pkg/usr/share/applications/$pkgname.desktop <<EOF
[Desktop Entry]
Encoding=UTF-8
Name=Picasa
Comment=Photo Organizer
Exec=picasa
Terminal=false
Type=Application
Categories=Graphics
Icon=picasa
EOF

	cat > $startdir/pkg/usr/share/applications/picasafontcfg.desktop <<EOF
[Desktop Entry]
Encoding=UTF-8
Name=Picasa Font Settings
Comment=Configure fonts used by Picasa
Exec=picasafontcfg
Terminal=false
Type=Application
Categories=Settings
Icon=picasa-fontcfg
EOF

# fix some permissions problems
	cd $startdir/pkg
	find . -perm 666 -exec chmod 644 {} \;
	find . -perm 664 -exec chmod 644 {} \;
	find . -perm 600 -exec chmod 644 {} \;
	find . -perm 444 -exec chmod 644 {} \;
	find . -perm 400 -exec chmod 644 {} \;
	find . -perm 440 -exec chmod 644 {} \;
	find . -perm 777 -exec chmod 755 {} \;
	find . -perm 775 -exec chmod 755 {} \;
	find . -perm 511 -exec chmod 755 {} \;
	find . -perm 711 -exec chmod 755 {} \;
	find . -perm 555 -exec chmod 755 {} \;
	#make sure files that need to be executable are executable and files that do not, are not.
	find . -type f -name "*.dll" | xargs chmod -x
    find . -type f -name "*.exe" | xargs chmod +x
    
# find has problems with directory names containing spaces
	cd "$startdir/pkg/usr/share/picasa-3.0/wine/drive_c/Program Files"
	find . -perm 666 -exec chmod 644 {} \;
	find . -perm 664 -exec chmod 644 {} \;
	find . -perm 600 -exec chmod 644 {} \;
	find . -perm 444 -exec chmod 644 {} \;
	find . -perm 400 -exec chmod 644 {} \;
	find . -perm 440 -exec chmod 644 {} \;
	find . -perm 777 -exec chmod 755 {} \;
	find . -perm 775 -exec chmod 755 {} \;
	find . -perm 511 -exec chmod 755 {} \;
	find . -perm 711 -exec chmod 755 {} \;
	find . -perm 555 -exec chmod 755 {} \;
	#make sure files that need to be executable are executable and files that do not, are not.
	find . -type f -name "*.dll" | xargs chmod -x
    find . -type f -name "*.exe" | xargs chmod +x
}