File indexing completed on 2022-09-27 16:37:28

0001 /*
0002  * SPDX-FileCopyrightText: 2017 Elvis Angelaccio <elvis.angelaccio@kde.org>
0003  *
0004  * SPDX-License-Identifier: GPL-2.0-or-later
0005  *
0006  */
0007 
0008 #include "compositejob.h"
0009 #include "symmydebug.h"
0010 #include "symmyversion.h"
0011 
0012 #include <KAboutData>
0013 #include <KLocalizedString>
0014 
0015 #include <QApplication>
0016 #include <QCommandLineParser>
0017 
0018 #include <iostream>
0019 
0020 int main(int argc, char **argv)
0021 {
0022     KLocalizedString::setApplicationDomain("symmy");
0023 
0024     QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps, true);
0025     QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling, true);
0026     QApplication app {argc, argv};
0027     auto aboutData = KAboutData {QStringLiteral("symmy"), i18nc("display name for 'symmy' binary", "GPG Symmetric Encryption Frontend"), QStringLiteral(SYMMY_VERSION_STRING),
0028                                  i18n("Encrypt/decrypt one ore more files using GPG symmetric encryption."), KAboutLicense::GPL, i18n("(c) 2017 Elvis Angelaccio")};
0029     aboutData.addAuthor(i18n("Elvis Angelaccio"), {}, QStringLiteral("elvis.angelaccio@kde.org"));
0030     KAboutData::setApplicationData(aboutData);
0031 
0032     QCommandLineParser parser;
0033     parser.addPositionalArgument(QStringLiteral("files"), i18n("List of files to encrypt or decrypt."));
0034     parser.addOption(QCommandLineOption {QStringList {QStringLiteral("e"), QStringLiteral("encrypt")},
0035                                          i18n("Encrypt the given list of files (this is the default if there are no other options).")});
0036     parser.addOption(QCommandLineOption {QStringList {QStringLiteral("d"), QStringLiteral("decrypt")},
0037                                          i18n("Decrypt the given list of files.")});
0038 
0039     app.setQuitOnLastWindowClosed(false);
0040 
0041     aboutData.setupCommandLine(&parser);
0042     parser.process(app);
0043     aboutData.processCommandLine(&parser);
0044 
0045     if (parser.isSet(QStringLiteral("encrypt")) and parser.isSet(QStringLiteral("decrypt"))) {
0046         std::cerr << qPrintable(i18nc("--encrypt and --decrypt are CLI args, don't translate them", "Error: either --encrypt or --decrypt, not both.")) << '\n';
0047         parser.showHelp(-1);
0048     }
0049 
0050     if (parser.positionalArguments().isEmpty()) {
0051         parser.showHelp(-1);
0052     }
0053 
0054     const auto files = parser.positionalArguments();
0055 
0056     if (parser.isSet(QStringLiteral("encrypt")) or not parser.isSet(QStringLiteral("decrypt"))) {
0057         qCDebug(SYMMY) << "Going to encrypt:" << files;
0058         auto job = new Symmy::CompositeJob {files, Symmy::CompositeJob::Task::Encryption};
0059         QObject::connect(job, &KJob::result, &app, &QCoreApplication::quit, Qt::QueuedConnection);
0060         job->start();
0061     } else {
0062         qCDebug(SYMMY) << "Going to decrypt:" << files;
0063         auto job = new Symmy::CompositeJob {files, Symmy::CompositeJob::Task::Decryption};
0064         QObject::connect(job, &KJob::result, &app, &QCoreApplication::quit, Qt::QueuedConnection);
0065         job->start();
0066     }
0067 
0068     qCDebug(SYMMY) << "Starting event loop...";
0069     return app.exec();
0070 }