SUMMARY="A Markdown editor with no distractions"
DESCRIPTION="Ghostwriter is a text editor for Markdown that tries to stay out of your way.
Main features:

* Optional live HTML preview
* Drag and drop of images
* Copy as HTML to clipboard
* Export HTML
* Auto-save
* A 'distraction-free mode' to focus on the current sentence/paragraph
* Customizable color themes
* Custom style sheets
* Outline window to quickly jump to headings
* Markdown cheat sheet
* Document and session statistics"
HOMEPAGE="https://wereturtle.github.io/ghostwriter/"
COPYRIGHT="wereturtle et al."
LICENSE="GNU GPL v3"
REVISION="3"
SOURCE_URI="https://github.com/wereturtle/ghostwriter/archive/v$portVersion.tar.gz"
CHECKSUM_SHA256="4987126e71a37556e575fbce2002c5504cf15a04c11bcce604a278f59ec9c11a"
SOURCE_FILENAME="ghostwriter-$portVersion.tar.gz"
ADDITIONAL_FILES="ghostwriter.rdef.in"
PATCHES="ghostwriter-$portVersion.patchset"

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

PROVIDES="
	ghostwriter$secondaryArchSuffix = $portVersion
	app:Ghostwriter$secondaryArchSuffix = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	cmd:hunspell$secondaryArchSuffix
	lib:libGL$secondaryArchSuffix
	lib:libQt5Concurrent$secondaryArchSuffix
	lib:libQt5Core$secondaryArchSuffix
	lib:libQt5Gui$secondaryArchSuffix
	lib:libQt5PrintSupport$secondaryArchSuffix
	lib:libQt5WebKit$secondaryArchSuffix
	lib:libQt5WebKitWidgets$secondaryArchSuffix
	lib:libQt5Widgets$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	hunspell${secondaryArchSuffix}_devel
	devel:libGL$secondaryArchSuffix
	devel:libQt5Concurrent$secondaryArchSuffix
	devel:libQt5Core$secondaryArchSuffix
	devel:libQt5Gui$secondaryArchSuffix
	devel:libQt5PrintSupport$secondaryArchSuffix
	devel:libQt5WebKit$secondaryArchSuffix
	devel:libQt5WebKitWidgets$secondaryArchSuffix
	devel:libQt5Widgets$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:g++$secondaryArchSuffix
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:lrelease$secondaryArchSuffix >= 5
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	cmd:qmake$secondaryArchSuffix >= 5
	"

PATCH()
{
	sed -i \
		-e "/translationPaths.append/ \
			s|appDir + \"/translations\"|\"$dataDir/ghostwriter/translations\"|;" \
		src/AppSettings.cpp
}

BUILD()
{
	lrelease ghostwriter.pro
	qmake BINDIR=$appsDir DATADIR=$dataDir
	make $jobArgs
}

INSTALL()
{
	make install
	mv $appsDir/ghostwriter $appsDir/Ghostwriter
	rm -rf $dataDir/{appdata,applications,icons,pixmaps}

	local APP_SIGNATURE="application/x-vnd.ghostwriter"
	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/ghostwriter.rdef.in > ghostwriter.rdef

	addResourcesToBinaries ghostwriter.rdef $appsDir/Ghostwriter
	mimeset -f $appsDir/Ghostwriter
	addAppDeskbarSymlink $appsDir/Ghostwriter
}
