SUMMARY="CHM viewer for KDE"
DESCRIPTION="Kchmviewer is a free, open-source CHM (aka MS HTML help) and EPUB \
viewer written in C++ for Unix, Mac and Windows systems. Unlike most existing \
CHM viewers for Unix, it uses Trolltech Qt widget library, and could optionally \
be compiled for better KDE integration. It does not require KDE, but may be \
compiled with KDE widget support. Since version 5.0 it uses the Webkit API to \
show the content.

The main advantage of kchmviewer is the best support for non-English languages. \
Unlike other viewers, kchmviewer in most cases is able to correctly detect the \
chm file encoding and show it. It correctly shows the index and table of context \
in Russian, Spanish, Romanian, Korean, Chinese and Arabic help files, and with \
new search engine is able to search in any chm file no matter what language \
it is written."
HOMEPAGE="http://www.ulduzsoft.com/linux/kchmviewer/"
COPYRIGHT="George Yunaev"
LICENSE="GNU GPL v3"
REVISION="3"
SOURCE_URI="https://sourceforge.net/projects/kchmviewer/files/kchmviewer/$portVersion/kchmviewer-$portVersion.tar.gz"
CHECKSUM_SHA256="27cbac45c786b1718550a87e6f86010e161302b426c6396ff2a3091b913b17dd"
SOURCE_DIR="kchmviewer-$portVersion"
PATCHES="kchmviewer-$portVersion.patchset"
ADDITIONAL_FILES="
	kchmviewer.rdef.in
	haikuicons.zip
	"

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

PROVIDES="
	kchmviewer$secondaryArchSuffix = $portVersion
	app:kchmviewer$secondaryArchSuffix = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libchm$secondaryArchSuffix
	lib:libfontconfig$secondaryArchSuffix
	lib:libfreetype$secondaryArchSuffix
	lib:libGL$secondaryArchSuffix
	lib:libintl$secondaryArchSuffix
	lib:libjpeg$secondaryArchSuffix
	lib:libpng16$secondaryArchSuffix
	lib:libQt5Core$secondaryArchSuffix
	lib:libQt5Gui$secondaryArchSuffix
	lib:libQt5Network$secondaryArchSuffix
	lib:libQt5PrintSupport$secondaryArchSuffix
	lib:libQt5Svg$secondaryArchSuffix
	lib:libQt5WebKit$secondaryArchSuffix
	lib:libQt5WebKitWidgets$secondaryArchSuffix
	lib:libQt5Widgets$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	lib:libzip$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libchm$secondaryArchSuffix
	devel:libfontconfig$secondaryArchSuffix
	devel:libfreetype$secondaryArchSuffix
	devel:libGL$secondaryArchSuffix
	devel:libjpeg$secondaryArchSuffix
	devel:libpng16$secondaryArchSuffix
	devel:libQt5Core$secondaryArchSuffix
	devel:libQt5Gui$secondaryArchSuffix
	devel:libQt5Network$secondaryArchSuffix
	devel:libQt5PrintSupport$secondaryArchSuffix
	devel:libQt5Svg$secondaryArchSuffix
	devel:libQt5WebKit$secondaryArchSuffix
	devel:libQt5WebKitWidgets$secondaryArchSuffix
	devel:libQt5Widgets$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	devel:libzip$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:lrelease$secondaryArchSuffix >= 5
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	cmd:qmake$secondaryArchSuffix >= 5
	cmd:unzip
	"

PATCH()
{
	unzip -o $sourceDir/../../additional-files/haikuicons.zip -d $sourceDir/src/resources
}

BUILD()
{
	qmake
	make $jobArgs
}

INSTALL()
{
	mkdir -p $appsDir
	cp -f $sourceDir/bin/kchmviewer $appsDir/Kchmviewer

	local APP_SIGNATURE="application/x-vnd.kde.kchmviewer"
	local MAJOR="`echo "$portVersion" | cut -d. -f1`"
	local MIDDLE="`echo "$portVersion" | cut -d. -f2`"
	local LONG_INFO="$SUMMARY"

	sed \
		-e "s|@APP_SIGNATURE@|$APP_SIGNATURE|" \
		-e "s|@MAJOR@|$MAJOR|" \
		-e "s|@MIDDLE@|$MIDDLE|" \
		-e "s|@LONG_INFO@|$LONG_INFO|" \
		$portDir/additional-files/kchmviewer.rdef.in > kchmviewer.rdef

	addResourcesToBinaries kchmviewer.rdef $appsDir/Kchmviewer
	addAppDeskbarSymlink $appsDir/Kchmviewer Kchmviewer
}
