%if 0%{?fedora} || 0%{?rhel} >= 10
%global QTVERSION 6
%else
%global QTVERSION 5
%endif

# %global file_version 0.0.1_2025-02-22
# %global version %(echo %file_version | sed -e 's/_\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}\\)/^\\1/; s/\\([0-9]\\{4\\}\\)-\\([0-9]\\{2\\}\\)-\\([0-9]\\{2\\}\\)/\\1\\2\\3/')
%global file_version 0.0.1-5
%global file_release %(echo %file_version | sed -e 's/\\(.*\\)\\(-\\)\\([0-9]\\{1,\\}\\)/\\3/')
%global file_autorelease %autorelease
%global version %(echo %file_version | sed -e 's/\\(.*\\)\\(-\\)\\([0-9]\\{1,\\}\\)/\\1/')
%global release %(echo %file_autorelease | sed -e 's/\\(.*\\)\\(\\.\\)\\(.*\\)/%file_release\\2\\3/')

Name:           ksensors5
Version:        %version
# Release:        %autorelease
Release:        %release
Summary:        Front-end for lm-sensors and hddtemp

Group:          System
License:        GPL-2.0-or-later
URL:            https://sourceforge.net/p/ksensors5
Source:         https://downloads.sourceforge.net/%{name}/%{name}-%{file_version}.tar.bz2

BuildRequires:  appstream
BuildRequires:  cmake
BuildRequires:  cmake(KF%{QTVERSION}CoreAddons)
BuildRequires:  cmake(KF%{QTVERSION}DBusAddons)
BuildRequires:  cmake(KF%{QTVERSION}I18n)
BuildRequires:  cmake(KF%{QTVERSION}WidgetsAddons)
BuildRequires:  cmake(KF%{QTVERSION}WindowSystem)
BuildRequires:  cmake(KF%{QTVERSION}XmlGui)
BuildRequires:  cmake(Qt%{QTVERSION}Charts)
BuildRequires:  cmake(Qt%{QTVERSION}Core)
BuildRequires:  cmake(Qt%{QTVERSION}Gui)
BuildRequires:  cmake(Qt%{QTVERSION}Multimedia)
BuildRequires:  cmake(Qt%{QTVERSION}Widgets)
%if 0%{?QTVERSION} == 6
BuildRequires:  cmake(KF6StatusNotifierItem)
%else
BuildRequires:  cmake(KF5Notifications)
BuildRequires:  cmake(Qt5X11Extras)
%endif
BuildRequires:  desktop-file-utils
BuildRequires:  extra-cmake-modules
BuildRequires:  gcc
BuildRequires:  gettext
BuildRequires:  hddtemp
BuildRequires:  lm_sensors-devel
Requires:       hicolor-icon-theme
Requires:       kde-filesystem

%if 0%{?QTVERSION} == 6
%description
ksensors5 is a lmsensors and hddtemp frontend for Qt6.

It is a fork of ksensors and several customizations.
%else
%description
ksensors5 is a lmsensors and hddtemp frontend for Qt5.

It is a fork of ksensors and several customizations.
%endif

%prep
%autosetup -p1 -n %{name}

%build
%cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo \
       -DKS_QTVERSION=%{QTVERSION}
%cmake_build

%install
%cmake_install
%find_lang %{name} --with-qt

%check
%if 0%{?QTVERSION} == 6
desktop-file-validate %{buildroot}%{_kf6_datadir}/applications/%{name}.desktop
%else
desktop-file-validate %{buildroot}%{_kf5_datadir}/applications/%{name}.desktop
%endif

%files -f %{name}.lang
%license COPYING
%doc AUTHORS README 
%{_bindir}/ksensors5
%{_docdir}/HTML/en/%{name}/index.docbook
%if 0%{?QTVERSION} == 6
%{_kf6_datadir}/%{name}/
%{_kf6_datadir}/applications/%{name}.desktop
%{_kf6_datadir}/kxmlgui5/%{name}/
%{_kf6_datadir}/icons/hicolor/*/apps/%{name}.png
%{_kf6_datadir}/icons/locolor/*/apps/%{name}.png
%{_kf6_sysconfdir}/xdg/autostart/%{name}.desktop
%else
%{_kf5_datadir}/%{name}/
%{_kf5_datadir}/applications/%{name}.desktop
%{_kf5_datadir}/kxmlgui5/%{name}/
%{_kf5_datadir}/icons/hicolor/*/apps/%{name}.png
%{_kf5_datadir}/icons/locolor/*/apps/%{name}.png
%{_kf5_sysconfdir}/xdg/autostart/%{name}.desktop
%endif

%changelog
%autochangelog