# Maintainer: Luke Shumaker <lukeshu@sbcglobal.net>
# Maintainer (AUR): speps <speps dot aur dot archlinux dot org>

pkgbase=pumpa
pkgname=(pumpa-qt4 pumpa-qt5 pumpa-l10n)
pkgver=0.8.2
pkgdesc="A simple pump.io client"
url="http://sjoberg.fi/software/pumpa.html"
license=('GPL3')

pkgrel=1
arch=('i686' 'x86_64')
makedepends=('aspell' 'qjson' 'qt5-base')
source=("http://gitorious.org/pumpa/pumpa/archive/v$pkgver.tar.gz")
md5sums=('cb1a75b1365063198bd02b76e3fce2c5')

prepare() {
  cd $pkgbase-$pkgbase

  # icon path fix
  sed -i 's|/.*/||' $pkgbase.desktop
}

build() {
  cd "$srcdir"/$pkgbase-$pkgbase
  mkdir build-pumpa-qt4
  cd build-pumpa-qt4
  qmake-qt4 ..
  make

  cd "$srcdir"/$pkgbase-$pkgbase
  mkdir build-pumpa-qt5
  cd build-pumpa-qt5
  qmake ..
  make
}

package_pumpa-qt4() {
  pkgdesc+=" (Qt4)"
  depends+=('pumpa-l10n' 'aspell' 'qjson')
  install="$pkgbase.install"
  _package_common Qt4
}

package_pumpa-qt5() {
  pkgdesc+=" (Qt5)"
  depends=('pumpa-l10n' 'aspell' 'qt5-base')
  install="$pkgbase.install"
  _package_common Qt5
}

package_pumpa-l10n() {
  pkgdesc+=" (localizations)"

  cd $pkgbase-$pkgbase
  install -d "$pkgdir/usr/share/locale"
  install -Dm644 translations/*.qm \
    "$pkgdir/usr/share/locale"
}

_package_common() {
  local toolkit=$1
  cd $pkgbase-$pkgbase

  # bin
  install -Dm755 build-$pkgname/$pkgbase \
    "$pkgdir/usr/bin/$pkgname"

  # icon
  install -Dm644 images/$pkgbase.png \
    "$pkgdir/usr/share/pixmaps/$pkgname.png"

  # desktop file
  install -d "$pkgdir/usr/share/applications"
  sed -e "s|$pkgbase|$pkgname|" -e "s|Pumpa|& ($toolkit)|" \
    < $pkgbase.desktop \
    > "$pkgdir/usr/share/applications/$pkgname.desktop"

  # man page
  install -d "$pkgdir/usr/share/man/man1"
  sed -e "s|$pkgbase|$pkgname|" -e "s|${pkgbase^^}|${pkgname^^}|" \
    < docs/$pkgbase.1 \
    > "$pkgdir/usr/share/man/man1/$pkgname.1"
}