passwordmanager/main.cpp

106 lines
3.6 KiB
C++
Raw Normal View History

2015-09-06 20:33:09 +02:00
#include "./cli/cli.h"
2015-04-22 19:30:09 +02:00
#ifdef GUI_QTWIDGETS
2015-09-06 20:33:09 +02:00
# include "./gui/initiategui.h"
2015-04-22 19:30:09 +02:00
#endif
#ifdef GUI_QTQUICK
2015-09-06 20:33:09 +02:00
# include "./quickgui/initiatequick.h"
2015-04-22 19:30:09 +02:00
#endif
2015-12-08 08:37:18 +01:00
#include "resources/config.h"
2015-12-05 22:52:00 +01:00
2015-04-22 19:30:09 +02:00
#include <passwordfile/util/openssl.h>
#include <c++utilities/application/argumentparser.h>
#include <c++utilities/application/failure.h>
2015-09-01 20:18:13 +02:00
#include <c++utilities/application/commandlineutils.h>
2015-04-22 19:30:09 +02:00
#if defined(GUI_QTWIDGETS) || defined(GUI_QTQUICK)
# include <qtutilities/resources/qtconfigarguments.h>
2016-07-27 18:29:00 +02:00
# include <QString>
2015-04-22 19:30:09 +02:00
#else
# include <c++utilities/application/fakeqtconfigarguments.h>
#endif
#include <iostream>
using namespace std;
using namespace ApplicationUtilities;
using namespace Util;
int main(int argc, char *argv[])
{
// init open ssl
OpenSsl::init();
// setup argument parser
2015-08-25 19:14:49 +02:00
SET_APPLICATION_INFO;
2015-04-22 19:30:09 +02:00
ArgumentParser parser;
// file argument
2016-06-14 00:49:29 +02:00
Argument fileArg("file", 'f', "specifies the file to be opened (or created when using --modify)");
2015-04-22 19:30:09 +02:00
fileArg.setValueNames({"path"});
fileArg.setRequiredValueCount(1);
fileArg.setCombinable(true);
fileArg.setRequired(false);
fileArg.setImplicit(true);
2016-06-14 00:49:29 +02:00
// Qt configuration arguments
QT_CONFIG_ARGUMENTS qtConfigArgs;
qtConfigArgs.qtWidgetsGuiArg().addSubArgument(&fileArg);
2015-04-22 19:30:09 +02:00
// cli argument
2016-06-14 00:49:29 +02:00
Argument cliArg("interactive-cli", 'i', "starts the interactive command line interface");
cliArg.setSubArguments({&fileArg});
2015-04-22 19:30:09 +02:00
// help argument
HelpArgument helpArg(parser);
2016-06-14 00:49:29 +02:00
parser.setMainArguments({&qtConfigArgs.qtWidgetsGuiArg(), &qtConfigArgs.qtQuickGuiArg(), &cliArg, &helpArg});
2015-04-22 19:30:09 +02:00
// holds the application's return code
int res = 0;
// parse the specified arguments
try {
parser.parseArgs(argc, argv);
if(cliArg.isPresent()) {
Cli::InteractiveCli cli;
2016-06-14 00:49:29 +02:00
if(fileArg.isPresent()) {
cli.run(fileArg.values().front());
2015-04-22 19:30:09 +02:00
} else {
cli.run();
}
} else if(qtConfigArgs.areQtGuiArgsPresent()) {
// run Qt gui if no arguments, --qt-gui or --qt-quick-gui specified, a file might be specified
2016-07-27 18:29:00 +02:00
#if defined(GUI_QTWIDGETS) || defined(GUI_QTQUICK)
2015-04-22 19:30:09 +02:00
QString file;
2016-06-14 00:49:29 +02:00
if(fileArg.isPresent()) {
file = QString::fromLocal8Bit(fileArg.values().front());
2015-04-22 19:30:09 +02:00
}
2016-07-27 18:29:00 +02:00
#endif
2015-04-22 19:30:09 +02:00
if(qtConfigArgs.qtWidgetsGuiArg().isPresent()) {
#ifdef GUI_QTWIDGETS
2015-09-01 20:18:13 +02:00
res = QtGui::runWidgetsGui(argc, argv, qtConfigArgs, file);
2015-04-22 19:30:09 +02:00
#else
2015-09-01 20:18:13 +02:00
CMD_UTILS_START_CONSOLE;
2015-04-22 19:30:09 +02:00
cout << "The application has not been built with Qt widgets support." << endl;
#endif
} else if(qtConfigArgs.qtQuickGuiArg().isPresent()) {
#ifdef GUI_QTQUICK
2015-09-01 20:18:13 +02:00
res = QtGui::runQuickGui(argc, argv, qtConfigArgs);
2015-04-22 19:30:09 +02:00
#else
2015-09-01 20:18:13 +02:00
CMD_UTILS_START_CONSOLE;
2015-04-22 19:30:09 +02:00
cout << "The application has not been built with Qt quick support." << endl;
#endif
} else {
#if defined(GUI_QTQUICK)
2015-09-01 20:18:13 +02:00
res = QtGui::runQuickGui(argc, argv, qtConfigArgs);
2015-04-22 19:30:09 +02:00
#elif defined(GUI_QTWIDGETS)
2015-09-01 20:18:13 +02:00
res = QtGui::runWidgetsGui(argc, argv, qtConfigArgs, file);
2015-04-22 19:30:09 +02:00
#else
2015-09-01 20:18:13 +02:00
CMD_UTILS_START_CONSOLE;
2015-04-22 19:30:09 +02:00
cout << "See --help for usage." << endl;
#endif
}
}
2016-06-14 00:49:29 +02:00
} catch(const Failure &ex) {
2015-09-01 20:18:13 +02:00
CMD_UTILS_START_CONSOLE;
2015-04-22 19:30:09 +02:00
cout << "Unable to parse arguments. " << ex.what() << "\nSee --help for available commands." << endl;
}
// clean open ssl
OpenSsl::clean();
return res;
}