File indexing completed on 2024-07-21 04:35:15

0001 /*
0002     SPDX-FileCopyrightText: 2024 Ralf Habacker ralf.habacker @freenet.de
0003 
0004     This file is part of libalkimia.
0005 
0006     SPDX-License-Identifier: LGPL-2.1-or-later
0007 */
0008 
0009 #include "alkapplication.h"
0010 
0011 #include <KAboutData>
0012 
0013 #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
0014     #include <QApplication>
0015     #include <KLocalizedString>
0016 #else
0017     #include <KApplication>
0018     #include <KCmdLineArgs>
0019 #endif
0020 
0021 class Private
0022 {
0023 public:
0024     int _argc{0};
0025     char **_argv{nullptr};
0026     QStringList _args;
0027     KAboutData *_aboutData{nullptr};
0028 #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
0029     QApplication *_app{nullptr};
0030 #else
0031     KApplication *_app{nullptr};
0032 #endif
0033     ~Private()
0034     {
0035         delete _aboutData;
0036     }
0037 };
0038 
0039 Q_GLOBAL_STATIC(Private, d)
0040 
0041 #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
0042 AlkAboutData::AlkAboutData(const QString &componentName, const QString &displayName, const QString &version,
0043                            const QString &shortDescription, AlkAboutData::License license, const QString &copyrightStatement)
0044 {
0045     KLocalizedString::setApplicationDomain(componentName.toStdString().c_str());
0046     d->_aboutData = new KAboutData(componentName, displayName, version, shortDescription, static_cast<KAboutLicense::LicenseKey>(license), copyrightStatement);
0047     d->_app = new QApplication(d->_argc, d->_argv);
0048 }
0049 
0050 AlkAboutData &AlkAboutData::setOrganizationDomain(const QByteArray &domain)
0051 {
0052     d->_aboutData->setOrganizationDomain(domain);
0053     return *this;
0054 }
0055 
0056 void AlkAboutData::setApplicationData(AlkAboutData &aboutData)
0057 {
0058     Q_UNUSED(aboutData);
0059 
0060     KAboutData::setApplicationData(*d->_aboutData);
0061 }
0062 
0063 QString AlkAboutData::displayName()
0064 {
0065     return d()->_aboutData->displayName();
0066 }
0067 #else
0068 AlkAboutData::AlkAboutData(const QString &componentName, const QString &displayName, const QString &version,
0069                            const QString &shortDescription, AlkAboutData::License license, const QString &copyrightStatement)
0070 {
0071     d()->_aboutData = new KAboutData(componentName.toLatin1(), componentName.toLatin1(), ki18n(displayName.toStdString().c_str()),
0072                                      version.toStdString().c_str(), ki18n(shortDescription.toStdString().c_str()),
0073                                      static_cast<KAboutData::LicenseKey>(license), ki18n(copyrightStatement.toStdString().c_str()));
0074     KCmdLineArgs::init(d()->_aboutData);
0075     d()->_app = new KApplication(true);
0076 }
0077 
0078 AlkAboutData &AlkAboutData::setOrganizationDomain(const QByteArray &domain)
0079 {
0080     return *this;
0081 }
0082 
0083 void AlkAboutData::setApplicationData(AlkAboutData &aboutData)
0084 {
0085 }
0086 
0087 QString AlkAboutData::displayName()
0088 {
0089     return d()->_aboutData->programName();
0090 }
0091 #endif
0092 
0093 QString AlkAboutData::shortDescription() const
0094 {
0095     return d()->_aboutData->shortDescription();
0096 }
0097 
0098 AlkApplication::AlkApplication(int argc, char** argv)
0099 {
0100     d()->_argc = argc;
0101     d()->_argv = argv;
0102     for (int i = 0; i < argc; i++)
0103         d()->_args.append(argv[i]);
0104 }
0105 
0106 QStringList AlkApplication::arguments()
0107 {
0108     return d()->_args;
0109 }
0110 
0111 int AlkApplication::exec()
0112 {
0113     return d()->_app->exec();
0114 }