# uncomment to enable bootstrap mode
%global bootstrap 1

%if !0%{?bootstrap}
%global tests 1
%endif

%global  base_name konsole

Name:          konsole5
Summary:       KDE Terminal emulator
Version:       22.08.0
Release:       1
License:       GPLv2 and GFDL-1.2-or-later
URL:           http://www.kde.org/applications/system/konsole/

%global revision %(echo %{version} | cut -d. -f3)
%if %{revision} >= 50
%global stable unstable
%else
%global stable stable
%endif
Source0:       http://download.kde.org/%{stable}/release-service/%{version}/src/%{base_name}-%{version}.tar.xz

Patch200:      konsole-history_location_default.patch
Source10:      konsolerc

Obsoletes:     konsole < 14.12
Provides:      konsole = %{version}-%{release}

%global maj_ver %(echo %{version} | cut -d. -f1)

BuildRequires: make
BuildRequires: desktop-file-utils
BuildRequires: gettext
BuildRequires: pkgconfig(x11)

BuildRequires: extra-cmake-modules
BuildRequires: kf5-rpm-macros
BuildRequires: cmake(KF5Bookmarks)
BuildRequires: cmake(KF5Completion)
BuildRequires: cmake(KF5Config)
BuildRequires: cmake(KF5ConfigWidgets)
BuildRequires: cmake(KF5CoreAddons)
BuildRequires: cmake(KF5Crash)
BuildRequires: cmake(KF5DBusAddons)
BuildRequires: cmake(KF5DBusAddons)
BuildRequires: cmake(KF5DocTools)
BuildRequires: cmake(KF5GlobalAccel)
BuildRequires: cmake(KF5GuiAddons)
BuildRequires: cmake(KF5I18n)
BuildRequires: cmake(KF5IconThemes)
BuildRequires: cmake(KF5KIO)
BuildRequires: cmake(KF5NewStuff)
BuildRequires: cmake(KF5NewStuffCore)
BuildRequires: cmake(KF5Notifications)
BuildRequires: cmake(KF5NotifyConfig)
BuildRequires: cmake(KF5Parts)
BuildRequires: cmake(KF5Pty)
BuildRequires: cmake(KF5Service)
BuildRequires: cmake(KF5TextWidgets)
BuildRequires: cmake(KF5WidgetsAddons)
BuildRequires: cmake(KF5WindowSystem)
BuildRequires: cmake(KF5XmlGui)

BuildRequires: libappstream-glib
BuildRequires: qt5-qtbase-devel

%if 0%{?tests}
BuildRequires: appstream
BuildRequires: xorg-x11-server-Xvfb dbus-x11
%endif
Conflicts:     kde-l10n < 17.03

Requires:      %{name}-part%{?_isa} = %{version}-%{release}
Requires:      keditbookmarks

%description
%{summary}.

%package part
Summary:       Konsole5 kpart plugin

%description part
%{summary}.


%prep
%autosetup -n %{base_name}-%{version} -p1


%build
mkdir %{_target_platform}
pushd %{_target_platform}
%{cmake_kf5} .. \
  %{?tests:-DBUILD_TESTING:BOOL=ON}
popd
%make_build  -C %{_target_platform}


%install
make install/fast DESTDIR=%{buildroot}  -C %{_target_platform}

install -m644 -p -b -D %{SOURCE10} %{buildroot}%{_kf5_sysconfdir}/xdg/konsolerc

%find_lang konsole --with-html

grep 'StartupWMClass=' %{buildroot}%{_kf5_datadir}/applications/org.kde.konsole.desktop >& /dev/null || \
desktop-file-edit --set-key=StartupWMClass --set-value=konsole %{buildroot}%{_kf5_datadir}/applications/org.kde.konsole.desktop


%check
appstream-util validate-relax --nonet %{buildroot}%{_kf5_metainfodir}/org.kde.konsole.appdata.xml ||:
desktop-file-validate %{buildroot}%{_kf5_datadir}/applications/org.kde.konsole.desktop
%if 0%{?tests}
test "$(xvfb-run -a %{_target_platform}/src/konsole --version)" = "konsole %{version}" ||:
export CTEST_OUTPUT_ON_FAILURE=1
DBUS_SESSION_BUS_ADDRESS=
xvfb-run -a \
make test -C %{_target_platform} ARGS="--output-on-failure --timeout 30" ||:
%endif


%files -f konsole.lang
%dir %{_kf5_datadir}/knsrcfiles/
%doc README*
%{_kf5_bindir}/konsole
%{_kf5_bindir}/konsoleprofile
%{_kf5_datadir}/applications/org.kde.konsole.desktop
%{_kf5_datadir}/kconf_update/konsole_globalaccel.upd
%{_kf5_datadir}/kio/servicemenus/konsolerun.desktop
%{_kf5_datadir}/knotifications5/konsole.notifyrc
%{_kf5_datadir}/knsrcfiles/konsole.knsrc
%{_kf5_datadir}/kservicetypes5/terminalemulator.desktop
%{_kf5_datadir}/qlogging-categories5/konsole.*
%{_kf5_libdir}/kconf_update_bin/konsole_globalaccel
%{_kf5_metainfodir}/org.kde.konsole.appdata.xml

%ldconfig_scriptlets part

%files part
%license COPYING*
%config(noreplace) %{_kf5_sysconfdir}/xdg/konsolerc
%{_kf5_datadir}/konsole/
%{_kf5_libdir}/libkonsoleapp.so.*
%{_kf5_libdir}/libkonsoleprivate.so.*
%{_kf5_qtplugindir}/konsolepart.so
%{_kf5_qtplugindir}/konsoleplugins/
%{_kf5_datadir}/kservices5/konsolepart.desktop


%changelog
* Thu Jul 14 2022 misaka00251 <misaka00251@misakanet.cn> - 22.08.0-1
- Init package
