# $Id: PKGBUILD 150188 2015-12-08 07:49:06Z fyan $
# Maintainer (Arch): speps <speps at aur dot archlinux dot org>
# Maintainer: André Silva <emulatorman@parabola.nu>

pkgbase=qupzilla
pkgname=(qupzilla qupzilla-qt4)
pkgver=1.8.9
pkgrel=2.parabola1
arch=(i686 x86_64)
url="http://www.qupzilla.com/"
license=('GPL3')
makedepends=('qtwebkit' 'qt5-webkit' 'qt5-script' 'qt5-tools' 'hunspell' 'kdelibs' 'kwallet' 'libgnome-keyring')
optdepends=('bash-completion: bash completion support')
install="$pkgbase.install"
source=("$pkgbase-$pkgver.tar.gz::https://github.com/QupZilla/qupzilla/archive/v$pkgver.tar.gz"
         'searchenginesmanager.cpp.sed'
         'speeddial.cpp.sed'
         'start.html.sed')
noextract=("$pkgbase-$pkgver.tar.gz")
md5sums=('a39767aa92b482863ea4851935e26dd2'
         '1d926e97a5b287d40fb695f6516f2a06'
         '0f166fa102af975b3b8ac030d477e9b8'
         '77120a0c39ba8254e5b2c273910f029a')

prepare() {
  # extract
  mkdir -p qt{4,5}
  bsdtar --strip-components 1 -zxf $pkgbase-$pkgver.tar.gz -C qt4
  bsdtar --strip-components 1 -zxf $pkgbase-$pkgver.tar.gz -C qt5

  # configure
  export USE_WEBGL=true \
         QUPZILLA_PREFIX=/usr/ \
         KDE_INTEGRATION=true \
         GNOME_INTEGRATION=true

  # remove Google and Youtube support, replaces it to DDG HTML
  cd qt4
  sed -i -f $srcdir/searchenginesmanager.cpp.sed src/lib/opensearch/searchenginesmanager.cpp
  sed -i -f $srcdir/speeddial.cpp.sed src/lib/plugins/speeddial.cpp
  sed -i -f $srcdir/start.html.sed src/lib/data/html/start.html

  cd ../qt5
  sed -i -f $srcdir/searchenginesmanager.cpp.sed src/lib/opensearch/searchenginesmanager.cpp
  sed -i -f $srcdir/speeddial.cpp.sed src/lib/plugins/speeddial.cpp
  sed -i -f $srcdir/start.html.sed src/lib/data/html/start.html
}

build() {
  cd qt4
  qmake-qt4
  make

  cd ../qt5
  qmake
  make
}

package_qupzilla() {
  pkgdesc="Cross-platform QtWebKit browser (Qt5), without non-privacy search engines"
  depends=('qt5-webkit' 'qt5-script' 'qt5-x11extras' 'hunspell' 'desktop-file-utils' 'hicolor-icon-theme')
  optdepends=('kwallet: kf5 kwallet integration'
              'libgnome-keyring: gnome keyring integration')
  provides=('qupzilla-qt5')
  conflicts=('qupzilla-qt5' 'qupzilla-libre')
  replaces=('qupzilla-qt5' 'qupzilla-libre')

  cd qt5
  make INSTALL_ROOT="$pkgdir/" install

  # zsh completion
  install -Dm644 linux/completion/_$pkgbase \
    "$pkgdir/usr/share/zsh/site-functions/_$pkgbase"
}

package_qupzilla-qt4() {
  pkgdesc="Cross-platform QtWebKit browser (Qt4), without non-privacy search engines"
  depends=('qtwebkit' 'hunspell')
  optdepends=('kdelibs: kwallet integration'
              'libgnome-keyring: gnome keyring integration')
  provides=('qupzilla')
  conflicts=('qupzilla' 'qupzilla-libre-qt4')
  replaces=('qupzilla-libre-qt4')

  cd qt4
  make INSTALL_ROOT="$pkgdir/" install

  # zsh completion
  install -Dm644 linux/completion/_$pkgbase \
    "$pkgdir/usr/share/zsh/site-functions/_$pkgbase"
}

# vim:set ts=2 sw=2 et: