## START: Set by rpmautospec
## (rpmautospec version 0.3.5)
## RPMAUTOSPEC: autorelease, autochangelog
%define autorelease(e:s:pb:n) %{?-p:0.}%{lua:
    release_number = 3;
    base_release_number = tonumber(rpm.expand("%{?-b*}%{!?-b:1}"));
    print(release_number + base_release_number - 1);
}%{?-e:.%{-e*}}%{?-s:.%{-s*}}%{!?-n:%{?dist}}
## END: Set by rpmautospec

%global srcname qutebrowser

Name:		%{srcname}
Version:	3.1.0
Release:	%autorelease
Summary:	A keyboard-driven, vim-like browser based on PyQt5 and QtWebEngine
License:	GPLv3
URL:		http://www.qutebrowser.org
Source0:	https://github.com/%{srcname}/%{srcname}/releases/download/v%{version}/%{srcname}-%{version}.tar.gz
BuildArch:	noarch
BuildRequires:	asciidoc
BuildRequires:	desktop-file-utils
BuildRequires:	libappstream-glib
BuildRequires:	python%{python3_pkgversion}-devel
BuildRequires:	python%{python3_pkgversion}dist(setuptools)
BuildRequires:	python%{python3_pkgversion}dist(pyqt6)
BuildRequires:	python%{python3_pkgversion}dist(pyqt6-sip)
BuildRequires:	python%{python3_pkgversion}dist(pyqt6-webengine)
BuildRequires:	python%{python3_pkgversion}dist(markupsafe)
BuildRequires:	python%{python3_pkgversion}dist(jinja2)
BuildRequires:	python%{python3_pkgversion}dist(pyopengl)
BuildRequires:	python%{python3_pkgversion}dist(colorama)
BuildRequires:	sip6
Requires:	qt6-qtbase
Requires:	qt6-qtdeclarative
Requires:	qt6-qtwebengine
Requires:	python%{python3_pkgversion}-pyqt6-base
Requires:	python%{python3_pkgversion}-jinja2
Requires:	python%{python3_pkgversion}-PyYAML
Requires:	python%{python3_pkgversion}-markupsafe
Requires:	python%{python3_pkgversion}-pyopengl
Requires:   python%{python3_pkgversion}-pyqt6-webengine
Recommends:	qt6-qtwebengine-devtools
Recommends:	python%{python3_pkgversion}-pygments
Recommends:	python%{python3_pkgversion}-adblock

%description
qutebrowser is a keyboard-focused browser with a minimal GUI. It’s based on
Python, PyQt5 and QtWebEngine and free software, licensed under the GPL.
It was inspired by other browsers/addons like dwb and Vimperator/Pentadactyl.


%prep
%autosetup -p 1 -n %{srcname}-%{version}


%build
# Compile the man page
a2x -f manpage doc/qutebrowser.1.asciidoc

# Find all *.py files and if their first line is exactly '#!/usr/bin/env python3'
# then replace it with '#!/usr/bin/python3' (if it's the 1st line).
find . -type f -iname "*.py" -exec sed -i '1s_^#!/usr/bin/env python3$_#!/usr/bin/python3_' {} +

%py3_build


%install
%py3_install

# Install desktop and appdata files
desktop-file-install \
	--add-category="Network" \
	--delete-original \
	--dir=%{buildroot}%{_datadir}/applications \
	misc/org.%{srcname}.%{srcname}.desktop

install -Dm644 misc/org.qutebrowser.qutebrowser.appdata.xml -t %{buildroot}%{_datadir}/metainfo

# Install man page
install -Dm644 doc/%{srcname}.1 -t %{buildroot}%{_mandir}/man1

# Install icons
install -Dm644 qutebrowser/icons/qutebrowser.svg \
	-t "%{buildroot}%{_datadir}/icons/hicolor/scalable/apps"
for i in 16 24 32 48 64 128 256 512; do
	install -Dm644 "qutebrowser/icons/qutebrowser-${i}x${i}.png" \
		"%{buildroot}%{_datadir}/icons/hicolor/${i}x${i}/apps/qutebrowser.png"
done

# Set __main__.py as executable
chmod 755 %{buildroot}%{python3_sitelib}/%{srcname}/__main__.py

# Remove zero-length files:
# https://fedoraproject.org/wiki/Packaging_tricks#Zero_length_files
find %{buildroot} -size 0 -delete

%check
appstream-util validate-relax --nonet %{buildroot}%{_datadir}/metainfo/*.appdata.xml

%files
%license LICENSE
%doc README.asciidoc doc/changelog.asciidoc qutebrowser/html/doc
%{python3_sitelib}/%{srcname}-%{version}-py%{python3_version}.egg-info
%{python3_sitelib}/%{srcname}
%{_bindir}/%{srcname}
%{_datadir}/applications/org.%{srcname}.%{srcname}.desktop
%{_mandir}/man1/%{srcname}.1*
%{_datadir}/icons/hicolor/scalable/apps/%{srcname}.svg
%{_datadir}/icons/hicolor/16x16/apps/%{srcname}.png
%{_datadir}/icons/hicolor/24x24/apps/%{srcname}.png
%{_datadir}/icons/hicolor/32x32/apps/%{srcname}.png
%{_datadir}/icons/hicolor/48x48/apps/%{srcname}.png
%{_datadir}/icons/hicolor/64x64/apps/%{srcname}.png
%{_datadir}/icons/hicolor/128x128/apps/%{srcname}.png
%{_datadir}/icons/hicolor/256x256/apps/%{srcname}.png
%{_datadir}/icons/hicolor/512x512/apps/%{srcname}.png
%{_datadir}/metainfo/org.qutebrowser.qutebrowser.appdata.xml

%changelog
* Thu Aug 31 2023 Raven <raven@sysadmins.ws> - 3.0.0-1
- initial release