File indexing completed on 2024-04-21 16:35:04
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 QApplication app {argc, argv}; 0025 auto aboutData = KAboutData {QStringLiteral("symmy"), i18nc("display name for 'symmy' binary", "GPG Symmetric Encryption Frontend"), QStringLiteral(SYMMY_VERSION_STRING), 0026 i18n("Encrypt/decrypt one ore more files using GPG symmetric encryption."), KAboutLicense::GPL, i18n("(c) 2017 Elvis Angelaccio")}; 0027 aboutData.addAuthor(i18n("Elvis Angelaccio"), {}, QStringLiteral("elvis.angelaccio@kde.org")); 0028 KAboutData::setApplicationData(aboutData); 0029 0030 QCommandLineParser parser; 0031 parser.addPositionalArgument(QStringLiteral("files"), i18n("List of files to encrypt or decrypt.")); 0032 parser.addOption(QCommandLineOption {QStringList {QStringLiteral("e"), QStringLiteral("encrypt")}, 0033 i18n("Encrypt the given list of files (this is the default if there are no other options).")}); 0034 parser.addOption(QCommandLineOption {QStringList {QStringLiteral("d"), QStringLiteral("decrypt")}, 0035 i18n("Decrypt the given list of files.")}); 0036 0037 app.setQuitOnLastWindowClosed(false); 0038 0039 aboutData.setupCommandLine(&parser); 0040 parser.process(app); 0041 aboutData.processCommandLine(&parser); 0042 0043 if (parser.isSet(QStringLiteral("encrypt")) and parser.isSet(QStringLiteral("decrypt"))) { 0044 std::cerr << qPrintable(i18nc("--encrypt and --decrypt are CLI args, don't translate them", "Error: either --encrypt or --decrypt, not both.")) << '\n'; 0045 parser.showHelp(-1); 0046 } 0047 0048 if (parser.positionalArguments().isEmpty()) { 0049 parser.showHelp(-1); 0050 } 0051 0052 const auto files = parser.positionalArguments(); 0053 0054 if (parser.isSet(QStringLiteral("encrypt")) or not parser.isSet(QStringLiteral("decrypt"))) { 0055 qCDebug(SYMMY) << "Going to encrypt:" << files; 0056 auto job = new Symmy::CompositeJob {files, Symmy::CompositeJob::Task::Encryption}; 0057 QObject::connect(job, &KJob::result, &app, &QCoreApplication::quit, Qt::QueuedConnection); 0058 job->start(); 0059 } else { 0060 qCDebug(SYMMY) << "Going to decrypt:" << files; 0061 auto job = new Symmy::CompositeJob {files, Symmy::CompositeJob::Task::Decryption}; 0062 QObject::connect(job, &KJob::result, &app, &QCoreApplication::quit, Qt::QueuedConnection); 0063 job->start(); 0064 } 0065 0066 qCDebug(SYMMY) << "Starting event loop..."; 0067 return app.exec(); 0068 }