SUMMARY="A powerful BitTorrent client"
DESCRIPTION="This package contains KTorrent, a BitTorrent peer-to-peer \
network client, that is based on the KDE platform. Obviously, KTorrent \
supports such basic features as downloading, uploading and seeding files \
on the BitTorrent network. However, lots of other additional features and \
intuitive GUI should make KTorrent a good choice for everyone. Some features \
are available as plugins hence you should make sure you have the ones you \
need enabled.

  - Support for HTTP and UDP trackers, trackerless DHT (mainline) and webseeds.
  - Alternative UI support including Web interface and Plasma widget.
  - Torrent grouping, speed capping, various download prioritization
    capabilities on both torrent and file level as well as bandwidth
    scheduling.
  - Support for fetching torrent files from many sources including any local
    file or remote URL, RSS feeds (with filtering) or actively monitored
    directory etc.
  - Integrated and customizable torrent search on the Web.
  - Various security features like IP blocking and protocol encryption.
  - Disk space preallocation to reduce fragmentation.
  - uTorrent compatible peer exchange.
  - Autoconfiguration for LANs like Zeroconf extension and port forwarding via
    uPnP.
  - Scripting support via Kross and interprocess control via DBus interface.
  - SOCKSv4 and SOCKSv5 proxy, IPv6 support.
  - Lots of other useful built-in features and plugins."
HOMEPAGE="https://www.kde.org/applications/internet/ktorrent/"
COPYRIGHT="2010-2019 KDE Organisation"
LICENSE="GNU LGPL v2"
REVISION="1"
SOURCE_URI="https://github.com/KDE/ktorrent/archive/v$portVersion.tar.gz"
CHECKSUM_SHA256="f3634d3761ee3905b5258cf6675cba8267d6871ca5c61c41691a36d35bf0419f"
SOURCE_DIR="ktorrent-$portVersion"
PATCHES="ktorrent-$portVersion.patchset"
ADDITIONAL_FILES="ktorrent.rdef.in"

ARCHITECTURES="all !x86_gcc2"
SECONDARY_ARCHITECTURES="!x86_gcc2 x86"

PROVIDES="
	ktorrent$secondaryArchSuffix = $portVersion
	app:KTorrent$secondaryArchSuffix = $portVersion
	cmd:ktmagnetdownloader$secondaryArchSuffix = $portVersion
	cmd:ktupnptest$secondaryArchSuffix = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	cmd:dbus_launch
	lib:libgcrypt$secondaryArchSuffix
	lib:libgmp$secondaryArchSuffix
	lib:libKF5Archive$secondaryArchSuffix
	lib:libKF5Auth$secondaryArchSuffix
	lib:libKF5Bookmarks$secondaryArchSuffix
	lib:libKF5Codecs$secondaryArchSuffix
	lib:libKF5Completion$secondaryArchSuffix
	lib:libKF5ConfigCore$secondaryArchSuffix
	lib:libKF5ConfigGui$secondaryArchSuffix
	lib:libKF5ConfigWidgets$secondaryArchSuffix
	lib:libKF5CoreAddons$secondaryArchSuffix
	lib:libKF5Crash$secondaryArchSuffix
	lib:libKF5DBusAddons$secondaryArchSuffix
	lib:libKF5I18n$secondaryArchSuffix
	lib:libKF5IconThemes$secondaryArchSuffix
	lib:libKF5ItemViews$secondaryArchSuffix
	lib:libKF5JobWidgets$secondaryArchSuffix
	lib:libKF5KCMUtils$secondaryArchSuffix
	lib:libKF5KIOCore$secondaryArchSuffix
	lib:libKF5KIOFileWidgets$secondaryArchSuffix
	lib:libKF5KIOWidgets$secondaryArchSuffix
	lib:libKF5KrossCore$secondaryArchSuffix
	lib:libKF5KrossUi$secondaryArchSuffix
	lib:libKF5Notifications$secondaryArchSuffix
	lib:libKF5NotifyConfig$secondaryArchSuffix
	lib:libKF5Parts$secondaryArchSuffix
	lib:libKF5Plotting$secondaryArchSuffix
	lib:libKF5Service$secondaryArchSuffix
	lib:libKF5Solid$secondaryArchSuffix
	lib:libKF5SonnetUi$secondaryArchSuffix
	lib:libKF5TextWidgets$secondaryArchSuffix
	lib:libKF5Torrent$secondaryArchSuffix
	lib:libKF5WidgetsAddons$secondaryArchSuffix
	lib:libKF5WindowSystem$secondaryArchSuffix
	lib:libKF5XmlGui$secondaryArchSuffix
	lib:libphonon4qt5$secondaryArchSuffix
	lib:libQt5Core$secondaryArchSuffix
	lib:libQt5DBus$secondaryArchSuffix
	lib:libQt5Gui$secondaryArchSuffix
	lib:libQt5Network$secondaryArchSuffix
	lib:libQt5Widgets$secondaryArchSuffix
	lib:libQt5Xml$secondaryArchSuffix
	lib:libtag$secondaryArchSuffix
	lib:libtag_c$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	extra_cmake_modules$secondaryArchSuffix >= 5.65
	devel:libboost_system$secondaryArchSuffix
	devel:libgcrypt$secondaryArchSuffix
	devel:libgmp$secondaryArchSuffix
	devel:libKF5Archive$secondaryArchSuffix
	devel:libKF5Auth$secondaryArchSuffix
	devel:libKF5Bookmarks$secondaryArchSuffix
	devel:libKF5Codecs$secondaryArchSuffix
	devel:libKF5Completion$secondaryArchSuffix
	devel:libKF5ConfigCore$secondaryArchSuffix
	devel:libKF5ConfigWidgets$secondaryArchSuffix
	devel:libKF5CoreAddons$secondaryArchSuffix
	devel:libKF5Crash$secondaryArchSuffix
	devel:libKF5DBusAddons$secondaryArchSuffix
	devel:libKF5I18n$secondaryArchSuffix
	devel:libKF5IconThemes$secondaryArchSuffix
	devel:libKF5ItemViews$secondaryArchSuffix
	devel:libKF5JobWidgets$secondaryArchSuffix
	devel:libKF5KCMUtils$secondaryArchSuffix
	devel:libKF5KIOCore$secondaryArchSuffix
	devel:libKF5KrossCore$secondaryArchSuffix
	devel:libKF5Notifications$secondaryArchSuffix
	devel:libKF5NotifyConfig$secondaryArchSuffix
	devel:libKF5Parts$secondaryArchSuffix
	devel:libKF5Plotting$secondaryArchSuffix
	devel:libKF5Service$secondaryArchSuffix
	devel:libKF5Solid$secondaryArchSuffix
	devel:libKF5SonnetUi$secondaryArchSuffix
	devel:libKF5TextWidgets$secondaryArchSuffix
	devel:libKF5Torrent$secondaryArchSuffix
	devel:libKF5WidgetsAddons$secondaryArchSuffix
	devel:libKF5WindowSystem$secondaryArchSuffix
	devel:libKF5XmlGui$secondaryArchSuffix
	devel:libphonon4qt5$secondaryArchSuffix
	devel:libqca$secondaryArchSuffix
	devel:libQt5Core$secondaryArchSuffix >= 5.14
	devel:libtag$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:lrelease$secondaryArchSuffix >= 5
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	cmd:python2
	"

BUILD()
{
	# disable docs generation until libxml package is fixed
	sed -i s/kdoctools/#kdoctool/g CMakeLists.txt

	mkdir -p build
	cd build
	cmake .. \
		-DCMAKE_INSTALL_PREFIX=$prefix \
		-DSHARE_INSTALL_PREFIX=$dataDir \
		-DCMAKE_INSTALL_PREFIX=$appsDir/KTorrent \
		-DCMAKE_INSTALL_DATAROOTDIR=$dataDir \
		-DKDE_INSTALL_PLUGINDIR=$addOnsDir/Qt5 \
		-DECM_DIR=/system/data/cmake/Modules/ECM/cmake \
		-DENABLE_INFOWIDGET_PLUGIN=OFF
	make $jobArgs
}

INSTALL()
{
	cd build
	make install
	mv $appsDir/KTorrent/bin/* $appsDir/KTorrent
	mv $appsDir/KTorrent/ktorrent $appsDir/KTorrent/KTorrent
	rm -rf $appsDir/KTorrent/bin

	APP_SIGNATURE="application/x-vnd.ktorrent"
	local MAJOR="`echo "$portVersion" | cut -d. -f1`"
	local MIDDLE="`echo "$portVersion" | cut -d. -f2`"
	local MINOR="`echo "$portVersion" | cut -d. -f3`"
	local LONG_INFO="$SUMMARY"
	sed \
		-e "s|@APP_SIGNATURE@|$APP_SIGNATURE|" \
		-e "s|@MAJOR@|$MAJOR|" \
		-e "s|@MIDDLE@|$MIDDLE|" \
		-e "s|@MINOR@|$MINOR|" \
		-e "s|@LONG_INFO@|$LONG_INFO|" \
		$portDir/additional-files/ktorrent.rdef.in > ktorrent.rdef

	addResourcesToBinaries ktorrent.rdef $appsDir/KTorrent/KTorrent
	addAppDeskbarSymlink $appsDir/KTorrent/KTorrent
}
