File indexing completed on 2024-04-28 17:00:51

0001 // clang-format off
0002 /*
0003  * KDiff3 - Text Diff And Merge Tool
0004  *
0005  * SPDX-FileCopyrightText: 2023 Michael Reeves reeves.87@gmail.com
0006  * SPDX-License-Identifier: GPL-2.0-or-later
0007  */
0008 // clang-format on
0009 
0010 #ifndef COMPAT_H
0011 #define COMPAT_H
0012 
0013 /*
0014     KF5I18n rightfully complains if included in the auto-test builds as they aren't actually setup
0015     for translations.
0016 */
0017 #ifndef AUTOTEST
0018 
0019 #include <KLocalizedString>
0020 #include <KMessageBox>
0021 #else
0022 #define i18n(expr, ...) expr
0023 #define i18nc(c, expr, ...) expr
0024 #endif
0025 #define KF_VERSION_CHECK(major, minor, patch) ((major << 16) | (minor << 8) | (patch))
0026 #define KF_VERSION KF_VERSION_CHECK(KF_VERSION_MAJOR, KF_VERSION_MINOR, KF_VERSION_PATCH)
0027 
0028 #ifndef AUTOTEST
0029 namespace Compat {
0030 
0031 inline KMessageBox::ButtonCode warningTwoActionsCancel(QWidget *parent,
0032                                                        const QString &text,
0033                                                        const QString &title,
0034                                                        const KGuiItem &primaryAction,
0035                                                        const KGuiItem &secondaryAction,
0036                                                        const KGuiItem &cancelAction = KStandardGuiItem::cancel(),
0037                                                        const QString &dontAskAgainName = QString(),
0038                                                        KMessageBox::Options options = KMessageBox::Options(KMessageBox::Notify | KMessageBox::Dangerous))
0039 {
0040 #if KF_VERSION < KF_VERSION_CHECK(5, 100, 0)
0041     return KMessageBox::warningYesNoCancel(parent,
0042                                            text,
0043                                            title,
0044                                            primaryAction,
0045                                            secondaryAction,
0046                                            cancelAction,
0047                                            dontAskAgainName,
0048                                            options);
0049 #else
0050     return KMessageBox::warningTwoActionsCancel(parent,
0051                                                 text,
0052                                                 title,
0053                                                 primaryAction,
0054                                                 secondaryAction,
0055                                                 cancelAction,
0056                                                 dontAskAgainName,
0057                                                 options);
0058 #endif
0059 }
0060 
0061 inline KMessageBox::ButtonCode warningTwoActions(QWidget *parent,
0062                                                  const QString &text,
0063                                                  const QString &title,
0064                                                  const KGuiItem &primaryAction,
0065                                                  const KGuiItem &secondaryAction,
0066                                                  const QString &dontAskAgainName = QString(),
0067                                                  KMessageBox::Options options = KMessageBox::Options(KMessageBox::Notify | KMessageBox::Dangerous))
0068 {
0069 #if KF_VERSION < KF_VERSION_CHECK(5, 100, 0)
0070     return KMessageBox::warningYesNo(parent,
0071                                      text,
0072                                      title,
0073                                      primaryAction,
0074                                      secondaryAction,
0075                                      dontAskAgainName,
0076                                      options);
0077 #else
0078     return KMessageBox::warningTwoActions(parent,
0079                                           text,
0080                                           title,
0081                                           primaryAction,
0082                                           secondaryAction,
0083                                           dontAskAgainName,
0084                                           options);
0085 #endif
0086 }
0087 
0088 #if KF_VERSION < KF_VERSION_CHECK(5, 100, 0)
0089 constexpr KMessageBox::ButtonCode PrimaryAction = KMessageBox::Yes;
0090 constexpr KMessageBox::ButtonCode SecondaryAction = KMessageBox::No;
0091 #else
0092 constexpr KMessageBox::ButtonCode PrimaryAction = KMessageBox::PrimaryAction;
0093 constexpr KMessageBox::ButtonCode SecondaryAction = KMessageBox::SecondaryAction;
0094 #endif
0095 
0096 } //namespace Compat
0097 #endif // ndef AUTOTEST
0098 
0099 #endif /* COMPAT_H */