# Maintainer (Arch): Felix Yan <felixonmars@archlinux.org>
# Maintainer (Arch): Antonio Rojas <arojas@archlinux.org>
# Contributor (Arch): Andrea Scarpino <andrea@archlinux.org>
# Contributor: André Silva <emulatorman@hyperbola.info>

# rationale for inclusion in nonprism:
#   removed support for possible privacy critical protocals

pkgname=kopete
pkgver=18.12.2
pkgrel=1
pkgrel+=.parabola1.nonprism1
url='https://kde.org/applications/internet/kopete/'
arch=(x86_64)
arch+=(i686 armv7h)
license=(GPL LGPL FDL)
groups=(kde-applications kdenetwork)
depends=(knotifyconfig kcmutils ktexteditor kcontacts kidentitymanagement libkleo qca kdelibs4support khtml
         libidn libotr)
depends+=(kio)
makedepends=(extra-cmake-modules mediastreamer libgadu jsoncpp kdoctools kdesignerplugin kdnssd libkleo ktexteditor)
optdepends=('mediastreamer: jingle support' 'libgadu: Gadu-Gadu protocol' 'kdnssd: bonjour protocol')
conflicts=(kdenetwork-kopete)
replaces=(kdenetwork-kopete)
source=("https://download.kde.org/stable/applications/$pkgver/src/$pkgname-$pkgver.tar.xz"{,.sig} 
        kopete-mediastreamer2.14.patch kopete-srtp2.patch kopete-openssl-1.1.patch kopete-glibc-2.28.patch)
source+=(libre-nonprism.patch)
sha256sums=('48dad416ead50ac69afe822932abccca82cabc2d512c93ca3b7d5d653e38f363'
            'SKIP'
            '8b8e7a5d9f17fafdddb402fab22b0b8d9963039ea8ea9fa749cad67aeeb879ac'
            'ceed663f7007654d186d918cf7a0742972ed5bd319879021e9ba80e395177700'
            'a12ea422e5162ef11274a98fd53658d6e780cafbe2e0fac70c8bc7d3291fef8b'
            'ba1b830bbd74c3dde8de99d887bd20205b4bbb1e466a41aa2b230404f1959c83'
            '32553b785ef603c3e8160f0f1ef423095a0c9b8bbdc6c01e4d2c81740adb9db3')
validpgpkeys=(CA262C6C83DE4D2FB28A332A3A6A4DB839EAA6D7  # Albert Astals Cid <aacid@kde.org>
              F23275E4BF10AFC1DF6914A6DBD2CE893E2D1C87) # Christoph Feck <cfeck@kde.org>

prepare() {
  mkdir -p build

  cd $pkgname-$pkgver
# fix build with mediastreamer 2.14 https://phabricator.kde.org/D15956
  patch -p1 -i ../kopete-mediastreamer2.14.patch
# fix build with OpenSSL 1.1 (Fedora patch)
  patch -p1 -i ../kopete-openssl-1.1.patch
# support SRTP2
  patch -p1 -i ../kopete-srtp2.patch
# fix build with glibc 2.28
  patch -p1 -i ../kopete-glibc-2.28.patch

  # based on https://devel.trisquel.info/trisquel/package-helpers/blob/belenos/helpers/make-kopete
  sed -i 's/Skype protocol" ON/Skype protocol" OFF/g' protocols/CMakeLists.txt
  rm -rf protocols/skype
  sed 's/, Skype//' -i ./doc/index.docbook

  # Remove unsafe/dangerous services
  rm -rfv protocols/oscar
  rm -rfv protocols/yahoo
  rm -rfv protocols/qq
  rm -rfv protocols/groupwise
  rm -rfv protocols/gadu
  rm -rfv protocols/wlm
  rm -rfv protocols/meanwhile
  patch -p1 -i "${srcdir}"/libre-nonprism.patch
}

build() {
  cd build
  cmake ../$pkgname-$pkgver \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DCMAKE_INSTALL_LIBDIR=lib \
    -DBUILD_TESTING=OFF \
    -DWITH_Libmsn=OFF \
    -DWITH_Libgadu=OFF \
    -DWITH_skype=OFF \
    -DWITH_oscar=OFF \
    -DWITH_yahoo=OFF \
    -DWITH_qq=OFF \
    -DWITH_groupwise=OFF \
    -DWITH_gadu=OFF \
    -DWITH_GOOGLETALK=OFF \
    -DWITH_wlm=OFF \
    -DWITH_WLM_MEDIASTREAMER=OFF \
    -DWITH_meanwhile=OFF
  make
}

package() {
  cd build
  make DESTDIR="$pkgdir" install
}
