# Maintainer: Sergej Pupykin <arch+pub@sergej.pp.ru>

pkgname=('psi' 'psi-nowebengine')
pkgver=1.4
pkgrel=2
pkgdesc="Powerful XMPP (Jabber) client (Qt, C++) designed for power users"
url="https://psi-im.org"
license=('GPL2')
arch=('x86_64')
depends=('hunspell' 'qca-qt5' 'qt5-svg' 'qt5-webengine' 'qt5-x11extras' 'libidn')
makedepends=('cmake' 'qt5-multimedia')
source=("https://download.sourceforge.net/${pkgname}/${pkgname}-${pkgver}.tar.xz"
        "no-qca-qt4.patch"
        "qt-5.11.patch")
sha256sums=('761934c1c62daf69215f085ba24d7f9cd4db05ef0ad735383d68fb03d21571ad'
            'a6ea9a62100b6990b8a6c8590a6d0e9df095b99b6527bb5490a7fd3f6929ac23'
            'e56ec1a250488b2cf9d42887aac432ff2e0ef482eb7cc8500f3d52cb53949119')

prepare() {
  cd $pkgname-$pkgver
  patch -p1 <"$srcdir"/no-qca-qt4.patch
  patch -p1 <"$srcdir"/qt-5.11.patch
}

build() {
  cd $pkgname-$pkgver
  mkdir -p build
  cd build
  cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Release ..
  make
  cd ..

  mkdir -p build-nowebengine
  cd build-nowebengine
  cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Release -DENABLE_WEBKIT=OFF ..
  make
}

package_psi() {
  cd "$srcdir"/psi-$pkgver/build
  make DESTDIR="$pkgdir" install
  install -dm755 "$pkgdir/usr/include/psi/plugins"
  install -m644 ../src/plugins/include/*.h "$pkgdir/usr/include/psi/plugins"
}

package_psi-nowebengine() {
  pkgdesc+=" without WebEngine support"
  depends=('hunspell' 'minizip' 'qca-qt5' 'qt5-svg' 'qt5-x11extras' 'libidn')
  provides=("$pkgbase=$pkgver")
  conflicts=("$pkgbase")
  replaces=('psi-nowebkit')

  cd "$srcdir"/psi-$pkgver/build-nowebengine
  make DESTDIR="$pkgdir" install
  install -dm755 "$pkgdir/usr/include/psi/plugins"
  install -m644 ../src/plugins/include/*.h "$pkgdir/usr/include/psi/plugins"
}
