Adding gui prompt to List command. (#643)

This commit is contained in:
louib 2017-06-18 14:43:02 -04:00 committed by GitHub
parent f817eaa5c8
commit b75b9fb7d6

View File

@ -20,11 +20,13 @@
#include "List.h" #include "List.h"
#include <QApplication>
#include <QCommandLineParser> #include <QCommandLineParser>
#include <QCoreApplication> #include <QCoreApplication>
#include <QStringList> #include <QStringList>
#include <QTextStream> #include <QTextStream>
#include "gui/UnlockDatabaseDialog.h"
#include "core/Database.h" #include "core/Database.h"
#include "core/Entry.h" #include "core/Entry.h"
#include "core/Group.h" #include "core/Group.h"
@ -33,7 +35,10 @@
int List::execute(int argc, char** argv) int List::execute(int argc, char** argv)
{ {
QCoreApplication app(argc, argv); QStringList arguments;
for (int i = 0; i < argc; ++i) {
arguments << QString(argv[i]);
}
QTextStream out(stdout); QTextStream out(stdout);
QCommandLineParser parser; QCommandLineParser parser;
@ -44,22 +49,29 @@ int List::execute(int argc, char** argv)
<< "print-uuids", << "print-uuids",
QCoreApplication::translate("main", "Print the UUIDs of the entries and groups.")); QCoreApplication::translate("main", "Print the UUIDs of the entries and groups."));
parser.addOption(printUuidsOption); parser.addOption(printUuidsOption);
parser.process(app); QCommandLineOption guiPrompt(
QStringList() << "g"
<< "gui-prompt",
QCoreApplication::translate("main", "Use a GUI prompt unlocking the database."));
parser.addOption(guiPrompt);
parser.process(arguments);
const QStringList args = parser.positionalArguments(); const QStringList args = parser.positionalArguments();
if (args.size() != 1) { if (args.size() != 1) {
QCoreApplication app(argc, argv);
parser.showHelp(); parser.showHelp();
return EXIT_FAILURE; return EXIT_FAILURE;
} }
out << "Insert the database password\n> "; Database* db = nullptr;
out.flush(); if (parser.isSet("gui-prompt")) {
QApplication app(argc, argv);
db = UnlockDatabaseDialog::openDatabasePrompt(args.at(0));
} else {
QCoreApplication app(argc, argv);
db = Database::unlockFromStdin(args.at(0));
}
static QTextStream inputTextStream(stdin, QIODevice::ReadOnly);
QString line = inputTextStream.readLine();
CompositeKey key = CompositeKey::readFromLine(line);
Database* db = Database::openDatabaseFile(args.at(0), key);
if (db == nullptr) { if (db == nullptr) {
return EXIT_FAILURE; return EXIT_FAILURE;
} }