passwordmanager/main.cpp

125 lines
4.0 KiB
C++
Raw Normal View History

2016-08-29 20:21:24 +02:00
#include "./cli/cli.h"
#ifdef PASSWORD_MANAGER_GUI_QTWIDGETS
2017-05-01 03:26:04 +02:00
#include "./gui/initiategui.h"
2016-08-29 20:21:24 +02:00
#endif
#ifdef PASSWORD_MANAGER_GUI_QTQUICK
2017-05-01 03:26:04 +02:00
#include "./quickgui/initiatequick.h"
2016-08-29 20:21:24 +02:00
#endif
#include "resources/config.h"
2019-03-13 19:09:31 +01:00
#include "resources/qtconfig.h"
2016-08-29 20:21:24 +02:00
#include <passwordfile/util/openssl.h>
#include <c++utilities/application/argumentparser.h>
#include <c++utilities/application/commandlineutils.h>
2017-05-01 03:26:04 +02:00
#include <c++utilities/application/failure.h>
2016-08-29 20:21:24 +02:00
#if defined(PASSWORD_MANAGER_GUI_QTWIDGETS) || defined(PASSWORD_MANAGER_GUI_QTQUICK)
2017-05-01 03:26:04 +02:00
#include <QString>
#include <qtutilities/resources/qtconfigarguments.h>
ENABLE_QT_RESOURCES_OF_STATIC_DEPENDENCIES
2016-08-29 20:21:24 +02:00
#else
2017-05-01 03:26:04 +02:00
#include <c++utilities/application/fakeqtconfigarguments.h>
2016-08-29 20:21:24 +02:00
#endif
#include <iostream>
2018-08-31 19:54:05 +02:00
// force (preferably Qt Quick) GUI under Android
#ifdef Q_OS_ANDROID
#if defined(PASSWORD_MANAGER_GUI_QTWIDGETS) || defined(PASSWORD_MANAGER_GUI_QTQUICK)
#define PASSWORD_MANAGER_FORCE_GUI
#else
#error "Must build at least one kind of GUI under Android."
#endif
#endif
2016-08-29 20:21:24 +02:00
using namespace std;
using namespace ApplicationUtilities;
using namespace Util;
int main(int argc, char *argv[])
{
CMD_UTILS_CONVERT_ARGS_TO_UTF8;
2016-08-29 20:21:24 +02:00
SET_APPLICATION_INFO;
2018-08-31 19:54:05 +02:00
QT_CONFIG_ARGUMENTS qtConfigArgs;
int returnCode = 0;
#ifndef PASSWORD_MANAGER_FORCE_GUI
// setup argument parser
2016-08-29 20:21:24 +02:00
ArgumentParser parser;
// file argument
Argument fileArg("file", 'f', "specifies the file to be opened (or created when using --modify)");
2017-05-01 03:26:04 +02:00
fileArg.setValueNames({ "path" });
2016-08-29 20:21:24 +02:00
fileArg.setRequiredValueCount(1);
fileArg.setCombinable(true);
fileArg.setRequired(false);
fileArg.setImplicit(true);
qtConfigArgs.qtWidgetsGuiArg().addSubArgument(&fileArg);
qtConfigArgs.qtQuickGuiArg().addSubArgument(&fileArg);
2016-08-29 20:21:24 +02:00
// cli argument
Argument cliArg("interactive-cli", 'i', "starts the interactive command line interface");
2017-06-10 22:26:12 +02:00
cliArg.setDenotesOperation(true);
2017-05-01 03:26:04 +02:00
cliArg.setSubArguments({ &fileArg });
2016-08-29 20:21:24 +02:00
// help argument
HelpArgument helpArg(parser);
2017-05-01 03:26:04 +02:00
parser.setMainArguments({ &qtConfigArgs.qtWidgetsGuiArg(), &qtConfigArgs.qtQuickGuiArg(), &cliArg, &helpArg });
2016-08-29 20:21:24 +02:00
// parse the specified arguments
2017-09-29 17:16:44 +02:00
parser.parseArgsOrExit(argc, argv);
2018-08-31 19:54:05 +02:00
#endif
// init OpenSSL
2017-09-29 17:16:44 +02:00
OpenSsl::init();
2018-08-31 19:54:05 +02:00
#ifndef PASSWORD_MANAGER_FORCE_GUI
2017-09-29 17:16:44 +02:00
// start either interactive CLI or GUI
if (cliArg.isPresent()) {
Cli::InteractiveCli cli;
if (fileArg.isPresent()) {
cli.run(fileArg.firstValue());
2017-09-29 17:16:44 +02:00
} else {
cli.run();
}
} else if (qtConfigArgs.areQtGuiArgsPresent()) {
#if defined(PASSWORD_MANAGER_GUI_QTWIDGETS) || defined(PASSWORD_MANAGER_GUI_QTQUICK)
const auto file(fileArg.isPresent() ? QString::fromLocal8Bit(fileArg.firstValue()) : QString());
2016-08-29 20:21:24 +02:00
#endif
2017-09-29 17:16:44 +02:00
if (qtConfigArgs.qtWidgetsGuiArg().isPresent()) {
#ifdef PASSWORD_MANAGER_GUI_QTWIDGETS
2018-08-31 19:54:05 +02:00
returnCode = QtGui::runWidgetsGui(argc, argv, qtConfigArgs, file);
2016-08-29 20:21:24 +02:00
#else
2017-09-29 17:16:44 +02:00
CMD_UTILS_START_CONSOLE;
cerr << "The application has not been built with Qt widgets support." << endl;
2016-08-29 20:21:24 +02:00
#endif
2017-09-29 17:16:44 +02:00
} else if (qtConfigArgs.qtQuickGuiArg().isPresent()) {
#ifdef PASSWORD_MANAGER_GUI_QTQUICK
2018-08-31 19:54:05 +02:00
returnCode = QtGui::runQuickGui(argc, argv, qtConfigArgs, file);
2016-08-29 20:21:24 +02:00
#else
2017-09-29 17:16:44 +02:00
CMD_UTILS_START_CONSOLE;
cerr << "The application has not been built with Qt quick support." << endl;
2016-08-29 20:21:24 +02:00
#endif
2017-09-29 17:16:44 +02:00
} else {
#if defined(PASSWORD_MANAGER_GUI_QTQUICK)
2018-08-31 19:54:05 +02:00
returnCode = QtGui::runQuickGui(argc, argv, qtConfigArgs, file);
#elif defined(PASSWORD_MANAGER_GUI_QTWIDGETS)
2018-08-31 19:54:05 +02:00
returnCode = QtGui::runWidgetsGui(argc, argv, qtConfigArgs, file);
2016-08-29 20:21:24 +02:00
#else
2017-09-29 17:16:44 +02:00
CMD_UTILS_START_CONSOLE;
cerr << "See --help for usage." << endl;
2016-08-29 20:21:24 +02:00
#endif
}
}
2018-12-08 19:55:41 +01:00
#else // PASSWORD_MANAGER_FORCE_GUI
2018-08-31 19:54:05 +02:00
#ifdef PASSWORD_MANAGER_GUI_QTQUICK
returnCode = QtGui::runQuickGui(argc, argv, qtConfigArgs, QString());
#else
returnCode = QtGui::runWidgetsGui(argc, argv, qtConfigArgs, QString());
#endif
#endif
2017-09-29 17:16:44 +02:00
2018-08-31 19:54:05 +02:00
// clean OpenSSL
2016-08-29 20:21:24 +02:00
OpenSsl::clean();
2018-08-31 19:54:05 +02:00
return returnCode;
2016-08-29 20:21:24 +02:00
}