File indexing completed on 2024-12-08 04:34:26

0001 /*
0002   SPDX-FileCopyrightText: 2023-2024 Laurent Montel <montel.org>
0003 
0004   SPDX-License-Identifier: GPL-2.0-or-later
0005   code based on kdenlive
0006 */
0007 
0008 #include "needupdateversionwidget.h"
0009 #include "ruqolawidgets_debug.h"
0010 #include <KLocalizedString>
0011 #include <QAction>
0012 
0013 NeedUpdateVersionWidget::NeedUpdateVersionWidget(QWidget *parent)
0014     : KMessageWidget(parent)
0015 {
0016     setVisible(false);
0017     setPosition(KMessageWidget::Header);
0018     setCloseButtonVisible(true);
0019     auto action = new QAction(i18n("Disable version check"), this);
0020     addAction(action);
0021     connect(action, &QAction::triggered, this, &NeedUpdateVersionWidget::slotDisableVersionCheck);
0022 }
0023 
0024 NeedUpdateVersionWidget::~NeedUpdateVersionWidget() = default;
0025 
0026 void NeedUpdateVersionWidget::setObsoleteVersion(NeedUpdateVersionUtils::ObsoleteVersion obsolete)
0027 {
0028     switch (obsolete) {
0029     case NeedUpdateVersionUtils::ObsoleteVersion::Unknown:
0030         qCWarning(RUQOLAWIDGETS_LOG) << "Unknown value: seems to be a bug";
0031         break;
0032     case NeedUpdateVersionUtils::ObsoleteVersion::OlderThan6Months:
0033         setMessageType(KMessageWidget::Information);
0034         setText(i18n("Your version is older than 6 months, we encourage you to upgrade."));
0035         animatedShow();
0036         break;
0037     case NeedUpdateVersionUtils::ObsoleteVersion::OlderThan12Months:
0038         setMessageType(KMessageWidget::Warning);
0039         setText(i18n("Your version is older than 1 year, we strongly encourage you to upgrade."));
0040         animatedShow();
0041         break;
0042     case NeedUpdateVersionUtils::ObsoleteVersion::NotObsoleteYet:
0043         // It's ok
0044         break;
0045     }
0046 }
0047 
0048 void NeedUpdateVersionWidget::slotDisableVersionCheck()
0049 {
0050     NeedUpdateVersionUtils::disableCheckVersion();
0051     animatedHide();
0052 }
0053 
0054 #include "moc_needupdateversionwidget.cpp"