#Maintainer: Dimitris Jemos <djemos~at~slackel~dot~gr>

pkgname=last.fm
pkgver=1.5.4.27091
pkgrel=1dj
orgver=1.5.4.27091
source=("http://ftp.de.debian.org/debian/pool/main/l/lastfm/lastfm_${orgver}+dfsg1.orig.tar.gz"
        "http://www.mehercule.net/lastfm/build-fixes.diff" \
        "http://www.mehercule.net/lastfm/gcc41.diff" \
        "http://www.mehercule.net/lastfm/reduce-linkage.diff" \
        "http://www.mehercule.net/lastfm/no-fingerprint-lib.diff" \
        "http://www.mehercule.net/lastfm/alsa-uses-qdebug.diff" \
        "http://www.mehercule.net/lastfm/check-soundcard-errors.diff" \
        "http://www.mehercule.net/lastfm/tray-icon-size.diff" \
        "http://www.mehercule.net/lastfm/hide-scrobbledir-option.diff" \
        "http://www.mehercule.net/lastfm/tray-volume.diff" \
        "http://www.mehercule.net/lastfm/set-locale.diff" \
        "http://www.mehercule.net/lastfm/set-firstrun-status.diff" \
        "http://www.mehercule.net/lastfm/qt45.diff" \
        "http://www.mehercule.net/lastfm/qt46.diff" \
        "http://www.mehercule.net/lastfm/qt47.diff" \
        "http://www.mehercule.net/lastfm/hide-loved-radio.diff" \
        "http://www.mehercule.net/lastfm/ipod-scrobble-fix.diff" \
        "http://www.mehercule.net/lastfm/sidebar-crash-fix.diff" \
        "http://www.mehercule.net/lastfm/dirpaths.diff" \
        "http://www.mehercule.net/lastfm/icons.tar.gz" \
        "http://www.mehercule.net/lastfm/trayicons22.tar.gz" \
        "http://www.mehercule.net/lastfm/multi-sound.diff" \
        "http://www.mehercule.net/lastfm/dbus.diff" \
        "http://www.mehercule.net/lastfm/tag-cloud.diff" \
        "http://www.mehercule.net/lastfm/browser-select.diff" \
        "http://www.mehercule.net/lastfm/no-cruft.diff" \
        "http://www.mehercule.net/lastfm/gcc47.patch" \
        "last.fm.desktop" "last.fm.script" "last.fm.1" "last.fm.protocol")
sourcetemplate=http://people.salixos.org/djemos/salix/$pkgname

docs=("readme" "copying" "changelog")
url=http://www.last.fm


slackdesc=\
(
 #|-----handy-ruler------------------------------------------------------|
 "last.fm (Standalone Player for last.fm)"
 "With Last.fm on your computer you can scrobble your tracks,"
 "share your music tastes, listen to personalized radio streams,"
 "and discover new music and people."
 "Last.fm is open source software and contains no spyware or adware."
)

build() {
        
 cd ${SRC}/lastfm-1.5.4.27091+dfsg1

   patch -p1 <../build-fixes.diff
   patch -p1 <../gcc41.diff
   patch -p1 <../gcc47.patch
# patch -p1 <../reduce-linkage.diff // BROKEN
# patch -p1 <../link-to-needed.diff // BROKEN
   patch -p1 <../no-fingerprint-lib.diff
   patch -p1 <../alsa-uses-qdebug.diff
   patch -p1 <../check-soundcard-errors.diff
   patch -p1 <../tray-icon-size.diff
   patch -p1 <../hide-scrobbledir-option.diff
   patch -p1 <../tray-volume.diff
   patch -p1 <../set-locale.diff
   patch -p1 <../set-firstrun-status.diff
   patch -p1 <../qt45.diff
   patch -p1 <../qt46.diff
   patch -p1 <../qt47.diff
   patch -p1 <../hide-loved-radio.diff
   patch -p1 <../ipod-scrobble-fix.diff
   patch -p1 <../sidebar-crash-fix.diff
   patch -p1 <../dirpaths.diff
   
# patch -p1 <../multi-sound.diff //BROKEN
   patch -p1 <../dbus.diff
   patch -p1 <../tag-cloud.diff
   patch -p1 <../browser-select.diff
   patch -p1 <../no-cruft.diff
   sed -i 's|glib/glist.h|glib.h|' src/mediadevices/ipod/IpodDevice.cpp

  qmake -config release LIBS+=-lX11
   
  lrelease i18n/*.ts || return 1
                  
  make || return 1
  make install DESTDIR=$startdir/pkg || return 1
  # create icons
  if [ -e "$PKG/usr/share/icons/hicolor/48x48/apps" ]; then
    echo "perhaps icons already exists?"
    return 1
  fi

  mkdir -p $PKG/usr/share/icons/hicolor/48x48/apps || return 1

  #Last.fm doesn't have a nice installer, so we need to package it manually.
  mkdir -p $PKG/usr/bin $PKG/usr/man/man1 \
  $PKG/usr/share/applications $PKG/usr/share/pixmaps || return 1

  install -d ${PKG}/usr/{bin,share/applications,share/pixmaps,lib${LIBDIRSUFFIX}} || return 1
  install -d ${PKG}/usr/share/last.fm/{icons,buttons,i18n,services} || return 1
  install -d ${PKG}/usr/share/kde4/services || return 1
 
  install -m644 i18n/*.qm ${PKG}/usr/share/last.fm/i18n || return 1

  install -m644 ${SRC}/last.fm.protocol ${PKG}/usr/share/kde4/services || return 1
  install -m644 ${SRC}/last.fm.desktop ${PKG}/usr/share/applications || return 1
   
  cd bin

  install -m755 last.fm ${PKG}/usr/share/last.fm || return 1
  echo -e '#!/bin/sh\nexec /usr/share/last.fm/last.fm\n' > last.fm || return 1
  install -m755 last.fm ${PKG}/usr/bin || return 1

  install -m644 {libLastFmTools.so.1.0.0,libMoose.so.1.0.0} ${PKG}/usr/lib${LIBDIRSUFFIX} || return 1
  cp -a libLastFmTools.so libLastFmTools.so.1 libLastFmTools.so.1.0 \
         libMoose.so libMoose.so.1 libMoose.so.1.0 ${PKG}/usr/lib${LIBDIRSUFFIX} || return 1

  install -m644 services/* ${PKG}/usr/share/last.fm/services || return 1
 
  cd data
  install -m644 about_generic.png app_55.png logo.png no*.gif \
                 progress.mng progress_active.mng slider*.png \
                 speaker*.png watermark.png wizard_generic.png \
                 ${PKG}/usr/share/last.fm || return 1
   
  install -m644 buttons/*.png ${PKG}/usr/share/last.fm/buttons || return 1
  install -m644 icons/*.png ${PKG}/usr/share/last.fm/icons || return 1
  rm -f ${PKG}/usr/share/last.fm/icons/*profile24.png || return 1
  install -m644 ${SRC}/user_*22.png ${PKG}/usr/share/last.fm/icons || return 1
   
  install -m644 icons/as.png ${PKG}/usr/share/pixmaps/lastfm.png || return 1
  install -m644 icons/as.png $PKG/usr/share/icons/hicolor/48x48/apps/lastfm.png  || return 1
  cp -a ${SRC}/icons ${PKG}/usr/share/ || return 1

  gzip -9c $startdir/src/$pkgname.1 > $PKG/usr/man/man1/$pkgname.1.gz || return 1

  sed -i "s/.png//" $PKG/usr/share/applications/$pkgname.desktop || return 1  

  # copy patches to src 
  COPYFILES="build-fixes.diff gcc41.diff reduce-linkage.diff no-fingerprint-lib.diff alsa-uses-qdebug.diff check-soundcard-errors.diff tray-icon-size.diff 
  hide-scrobbledir-option.diff tray-volume.diff set-locale.diff set-firstrun-status.diff qt45.diff qt46.diff qt47.diff hide-loved-radio.diff 
  ipod-scrobble-fix.diff sidebar-crash-fix.diff dirpaths.diff icons.tar.gz trayicons22.tar.gz multi-sound.diff dbus.diff tag-cloud.diff 
  browser-select.diff no-cruft.diff gcc47.patch"

  for i in $COPYFILES; do
    mv $startdir/$i $PKG/usr/src/$pkgname-$pkgver/ || return 1
  done;
                
}

  # Doinst
  doinst() {
  if [ -x /usr/bin/update-desktop-database ]; then
    /usr/bin/update-desktop-database -q usr/share/applications >/dev/null 2>&1
  fi
}
