Uniform line endings (dos2unix)

This commit is contained in:
Martchus 2016-08-29 20:21:24 +02:00
parent 56907b6d4c
commit 648d482766
6 changed files with 1688 additions and 1692 deletions

View File

@ -3,12 +3,10 @@
#include <passwordfile/io/passwordfile.h> #include <passwordfile/io/passwordfile.h>
#include <c++utilities/application/global.h>
#if defined(PLATFORM_UNIX) #if defined(PLATFORM_UNIX)
#include <termios.h> # include <termios.h>
#elif defined(PLATFORM_WINDOWS) #elif defined(PLATFORM_WINDOWS)
#include <windows.h> # include <windows.h>
#endif #endif
#include <string> #include <string>
@ -17,9 +15,7 @@
#include <ostream> #include <ostream>
namespace ApplicationUtilities { namespace ApplicationUtilities {
typedef std::vector<std::string> StringVector; typedef std::vector<std::string> StringVector;
} }
namespace Io { namespace Io {

File diff suppressed because it is too large Load Diff

View File

@ -1,138 +1,138 @@
#ifndef MAINWINDOW_H #ifndef MAINWINDOW_H
#define MAINWINDOW_H #define MAINWINDOW_H
#include "./passwordgeneratordialog.h" #include "./passwordgeneratordialog.h"
#include <passwordfile/io/passwordfile.h> #include <passwordfile/io/passwordfile.h>
#include <c++utilities/io/binaryreader.h> #include <c++utilities/io/binaryreader.h>
#include <c++utilities/io/binarywriter.h> #include <c++utilities/io/binarywriter.h>
#include <QMainWindow> #include <QMainWindow>
#include <QMap> #include <QMap>
#include <memory> #include <memory>
QT_FORWARD_DECLARE_CLASS(QCloseEvent) QT_FORWARD_DECLARE_CLASS(QCloseEvent)
QT_FORWARD_DECLARE_CLASS(QTreeWidgetItem) QT_FORWARD_DECLARE_CLASS(QTreeWidgetItem)
QT_FORWARD_DECLARE_CLASS(QUndoStack) QT_FORWARD_DECLARE_CLASS(QUndoStack)
QT_FORWARD_DECLARE_CLASS(QUndoView) QT_FORWARD_DECLARE_CLASS(QUndoView)
QT_FORWARD_DECLARE_CLASS(QSettings) QT_FORWARD_DECLARE_CLASS(QSettings)
namespace Io { namespace Io {
DECLARE_ENUM_CLASS(EntryType, int); DECLARE_ENUM_CLASS(EntryType, int);
DECLARE_ENUM_CLASS(FieldType, int); DECLARE_ENUM_CLASS(FieldType, int);
} }
namespace MiscUtils { namespace MiscUtils {
class RecentMenuManager; class RecentMenuManager;
} }
namespace Dialogs { namespace Dialogs {
class AboutDialog; class AboutDialog;
class SettingsDialog; class SettingsDialog;
class QtSettings; class QtSettings;
} }
namespace QtGui { namespace QtGui {
class FieldModel; class FieldModel;
class EntryModel; class EntryModel;
class EntryFilterModel; class EntryFilterModel;
namespace Ui { namespace Ui {
class MainWindow; class MainWindow;
} }
class MainWindow : public QMainWindow class MainWindow : public QMainWindow
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit MainWindow(QSettings &settings, Dialogs::QtSettings *qtSettings = nullptr, QWidget *parent = nullptr); explicit MainWindow(QSettings &settings, Dialogs::QtSettings *qtSettings = nullptr, QWidget *parent = nullptr);
~MainWindow(); ~MainWindow();
public slots: public slots:
// file management // file management
bool openFile(const QString &path); bool openFile(const QString &path);
void createFile(const QString &path, const QString &password); void createFile(const QString &path, const QString &password);
void createFile(const QString &path); void createFile(const QString &path);
bool createFile(); bool createFile();
void changePassword(); void changePassword();
bool saveFile(); bool saveFile();
void exportFile(); void exportFile();
bool closeFile(); bool closeFile();
// show dialogs // show dialogs
void showOpenFileDialog(); void showOpenFileDialog();
void showSaveFileDialog(); void showSaveFileDialog();
void showSettingsDialog(); void showSettingsDialog();
void showAboutDialog(); void showAboutDialog();
void showPassowrdGeneratorDialog(); void showPassowrdGeneratorDialog();
void showUndoView(); void showUndoView();
protected: protected:
bool eventFilter(QObject *obj, QEvent *event); bool eventFilter(QObject *obj, QEvent *event);
void closeEvent(QCloseEvent *event); void closeEvent(QCloseEvent *event);
void timerEvent(QTimerEvent *event); void timerEvent(QTimerEvent *event);
private slots: private slots:
// file management // file management
bool showFile(); bool showFile();
// account/categories management // account/categories management
void addAccount(); void addAccount();
void addCategory(); void addCategory();
void addEntry(Io::EntryType type); void addEntry(Io::EntryType type);
void removeEntry(); void removeEntry();
void applyFilter(const QString &filterText); void applyFilter(const QString &filterText);
// row management // row management
void accountSelected(const QModelIndex &selected, const QModelIndex &); void accountSelected(const QModelIndex &selected, const QModelIndex &);
void insertRow(); void insertRow();
void removeRows(); void removeRows();
void markAsPasswordField(); void markAsPasswordField();
void markAsNormalField(); void markAsNormalField();
void setFieldType(Io::FieldType fieldType); void setFieldType(Io::FieldType fieldType);
void setPasswordVisibility(QAction *selectedAction); void setPasswordVisibility(QAction *selectedAction);
QString selectedFieldsString() const; QString selectedFieldsString() const;
void insertFields(const QString &fieldsString); void insertFields(const QString &fieldsString);
void copyFieldsForXMilliSeconds(int x = 5000); void copyFieldsForXMilliSeconds(int x = 5000);
void copyFields(); void copyFields();
void insertFieldsFromClipboard(); void insertFieldsFromClipboard();
// showing context menus // showing context menus
void showTreeViewContextMenu(); void showTreeViewContextMenu();
void showTableViewContextMenu(); void showTableViewContextMenu();
// other // other
void showContainingDirectory(); void showContainingDirectory();
void clearClipboard(); void clearClipboard();
void setSomethingChanged(); void setSomethingChanged();
void setSomethingChanged(bool somethingChanged); void setSomethingChanged(bool somethingChanged);
private: private:
// showing conditional messages/prompts // showing conditional messages/prompts
bool askForCreatingFile(); bool askForCreatingFile();
bool showNoFileOpened(); bool showNoFileOpened();
bool showNoAccount(); bool showNoAccount();
// other // other
void updateUiStatus(); void updateUiStatus();
void updateWindowTitle(); void updateWindowTitle();
void applyDefaultExpanding(const QModelIndex &parent); void applyDefaultExpanding(const QModelIndex &parent);
std::unique_ptr<Ui::MainWindow> m_ui; std::unique_ptr<Ui::MainWindow> m_ui;
Io::PasswordFile m_file; Io::PasswordFile m_file;
FieldModel *m_fieldModel; FieldModel *m_fieldModel;
EntryModel *m_entryModel; EntryModel *m_entryModel;
EntryFilterModel *m_entryFilterModel; EntryFilterModel *m_entryFilterModel;
QUndoStack *m_undoStack; QUndoStack *m_undoStack;
QUndoView *m_undoView; QUndoView *m_undoView;
bool m_somethingChanged; bool m_somethingChanged;
bool m_dontUpdateSelection; bool m_dontUpdateSelection;
int m_clearClipboardTimer; int m_clearClipboardTimer;
MiscUtils::RecentMenuManager *m_recentMgr; MiscUtils::RecentMenuManager *m_recentMgr;
Dialogs::AboutDialog *m_aboutDlg; Dialogs::AboutDialog *m_aboutDlg;
QSettings &m_settings; QSettings &m_settings;
Dialogs::QtSettings *m_qtSettings; Dialogs::QtSettings *m_qtSettings;
Dialogs::SettingsDialog *m_settingsDlg; Dialogs::SettingsDialog *m_settingsDlg;
}; };
} }
#endif // MAINWINDOW_H #endif // MAINWINDOW_H

View File

@ -1,172 +1,172 @@
#include "./passwordgeneratordialog.h" #include "./passwordgeneratordialog.h"
#include "ui_passwordgeneratordialog.h" #include "ui_passwordgeneratordialog.h"
#include <passwordfile/io/cryptoexception.h> #include <passwordfile/io/cryptoexception.h>
#include <qtutilities/misc/dialogutils.h> #include <qtutilities/misc/dialogutils.h>
#include <c++utilities/conversion/binaryconversion.h> #include <c++utilities/conversion/binaryconversion.h>
#include <openssl/rand.h> #include <openssl/rand.h>
#include <QMessageBox> #include <QMessageBox>
#include <QClipboard> #include <QClipboard>
#include <string> #include <string>
#include <sstream> #include <sstream>
#include <algorithm> #include <algorithm>
#include <random> #include <random>
using namespace std; using namespace std;
using namespace Io; using namespace Io;
using namespace Util; using namespace Util;
using namespace Dialogs; using namespace Dialogs;
namespace QtGui { namespace QtGui {
const char smallLetters[] = {'a','b','c','d','e','f', const char smallLetters[] = {'a','b','c','d','e','f',
'g','h','i','j','k', 'g','h','i','j','k',
'l','m','n','o','p', 'l','m','n','o','p',
'q','r','s','t','u', 'q','r','s','t','u',
'v','w','x','y','z'}; 'v','w','x','y','z'};
const char capitalLetters[] = {'A','B','C','D','E','F', const char capitalLetters[] = {'A','B','C','D','E','F',
'G','H','I','J','K', 'G','H','I','J','K',
'L','M','N','O','P', 'L','M','N','O','P',
'Q','R','S','T','U', 'Q','R','S','T','U',
'V','W','X','Y','Z'}; 'V','W','X','Y','Z'};
const char digits[] = {'0','1','2','3','4', const char digits[] = {'0','1','2','3','4',
'5','6','7','8','9'}; '5','6','7','8','9'};
/*! /*!
* \class PasswordGeneratorDialog * \class PasswordGeneratorDialog
* \brief The PasswordGeneratorDialog class provides a password generation dialog. * \brief The PasswordGeneratorDialog class provides a password generation dialog.
*/ */
/*! /*!
* \brief Constructs a new password generator dialog. * \brief Constructs a new password generator dialog.
*/ */
PasswordGeneratorDialog::PasswordGeneratorDialog(QWidget *parent) : PasswordGeneratorDialog::PasswordGeneratorDialog(QWidget *parent) :
QDialog(parent), QDialog(parent),
m_ui(new Ui::PasswordGeneratorDialog) m_ui(new Ui::PasswordGeneratorDialog)
{ {
m_ui->setupUi(this); m_ui->setupUi(this);
#ifdef Q_OS_WIN32 #ifdef Q_OS_WIN32
setStyleSheet(QStringLiteral("%1 QCommandLinkButton { font-size: 12pt; color: %2; font-weight: normal; }").arg(dialogStyle(), instructionTextColor().name())); setStyleSheet(QStringLiteral("%1 QCommandLinkButton { font-size: 12pt; color: %2; font-weight: normal; }").arg(dialogStyle(), instructionTextColor().name()));
#endif #endif
setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint); setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint);
connect(m_ui->copyPasswordCommandLinkButton, &QCommandLinkButton::clicked, this, &PasswordGeneratorDialog::copyPassword); connect(m_ui->copyPasswordCommandLinkButton, &QCommandLinkButton::clicked, this, &PasswordGeneratorDialog::copyPassword);
connect(m_ui->generatePassowordCommandLinkButton, &QCommandLinkButton::clicked, this, &PasswordGeneratorDialog::generateNewPassword); connect(m_ui->generatePassowordCommandLinkButton, &QCommandLinkButton::clicked, this, &PasswordGeneratorDialog::generateNewPassword);
connect(m_ui->useCapitalLettersCheckBox, &QCheckBox::stateChanged, this, &PasswordGeneratorDialog::handleCheckedCategoriesChanged); connect(m_ui->useCapitalLettersCheckBox, &QCheckBox::stateChanged, this, &PasswordGeneratorDialog::handleCheckedCategoriesChanged);
connect(m_ui->useCapitalLettersCheckBox, &QCheckBox::stateChanged, this, &PasswordGeneratorDialog::handleCheckedCategoriesChanged); connect(m_ui->useCapitalLettersCheckBox, &QCheckBox::stateChanged, this, &PasswordGeneratorDialog::handleCheckedCategoriesChanged);
connect(m_ui->useSmallLettersCheckBox, &QCheckBox::stateChanged, this, &PasswordGeneratorDialog::handleCheckedCategoriesChanged); connect(m_ui->useSmallLettersCheckBox, &QCheckBox::stateChanged, this, &PasswordGeneratorDialog::handleCheckedCategoriesChanged);
connect(m_ui->useDigitsCheckBox, &QCheckBox::stateChanged, this, &PasswordGeneratorDialog::handleCheckedCategoriesChanged); connect(m_ui->useDigitsCheckBox, &QCheckBox::stateChanged, this, &PasswordGeneratorDialog::handleCheckedCategoriesChanged);
connect(m_ui->otherCharsLineEdit, &QLineEdit::textChanged, this, &PasswordGeneratorDialog::handleCheckedCategoriesChanged); connect(m_ui->otherCharsLineEdit, &QLineEdit::textChanged, this, &PasswordGeneratorDialog::handleCheckedCategoriesChanged);
connect(m_ui->passwordLineEdit, &QLineEdit::textChanged, this, &PasswordGeneratorDialog::handlePasswordChanged); connect(m_ui->passwordLineEdit, &QLineEdit::textChanged, this, &PasswordGeneratorDialog::handlePasswordChanged);
connect(m_ui->closePushButton, &QPushButton::clicked, this, &PasswordGeneratorDialog::close); connect(m_ui->closePushButton, &QPushButton::clicked, this, &PasswordGeneratorDialog::close);
handlePasswordChanged(); handlePasswordChanged();
} }
/*! /*!
* \brief Destroys the dialog. * \brief Destroys the dialog.
*/ */
PasswordGeneratorDialog::~PasswordGeneratorDialog() PasswordGeneratorDialog::~PasswordGeneratorDialog()
{ {
delete m_ui; delete m_ui;
} }
/*! /*!
* \brief Generates and shows a new password. * \brief Generates and shows a new password.
*/ */
void PasswordGeneratorDialog::generateNewPassword() void PasswordGeneratorDialog::generateNewPassword()
{ {
int length = m_ui->LengthSpinBox->value(); int length = m_ui->LengthSpinBox->value();
if(length > 0) { if(length > 0) {
if(m_charset.empty()) { if(m_charset.empty()) {
bool useSmallLetters = m_ui->useSmallLettersCheckBox->isChecked(); bool useSmallLetters = m_ui->useSmallLettersCheckBox->isChecked();
bool useCapitalLetters = m_ui->useCapitalLettersCheckBox->isChecked(); bool useCapitalLetters = m_ui->useCapitalLettersCheckBox->isChecked();
bool useDigits = m_ui->useDigitsCheckBox->isChecked(); bool useDigits = m_ui->useDigitsCheckBox->isChecked();
QString otherChars = m_ui->otherCharsLineEdit->text(); QString otherChars = m_ui->otherCharsLineEdit->text();
int charsetSize = otherChars.length(); int charsetSize = otherChars.length();
if(useSmallLetters) { if(useSmallLetters) {
charsetSize += sizeof(smallLetters); charsetSize += sizeof(smallLetters);
} }
if(useCapitalLetters) { if(useCapitalLetters) {
charsetSize += sizeof(capitalLetters); charsetSize += sizeof(capitalLetters);
} }
if(useDigits) { if(useDigits) {
charsetSize += sizeof(digits); charsetSize += sizeof(digits);
} }
m_charset.reserve(charsetSize); m_charset.reserve(charsetSize);
if(useSmallLetters) { if(useSmallLetters) {
m_charset.insert(m_charset.end(), std::begin(smallLetters), std::end(smallLetters)); m_charset.insert(m_charset.end(), std::begin(smallLetters), std::end(smallLetters));
} }
if(useCapitalLetters) { if(useCapitalLetters) {
m_charset.insert(m_charset.end(), std::begin(capitalLetters), std::end(capitalLetters)); m_charset.insert(m_charset.end(), std::begin(capitalLetters), std::end(capitalLetters));
} }
if(useDigits) { if(useDigits) {
m_charset.insert(m_charset.end(), std::begin(digits), std::end(digits)); m_charset.insert(m_charset.end(), std::begin(digits), std::end(digits));
} }
char charval; char charval;
foreach(QChar qchar, otherChars) { foreach(QChar qchar, otherChars) {
charval = qchar.toLatin1(); charval = qchar.toLatin1();
if(charval != '\x00' && charval != ' ' && std::find(m_charset.begin(), m_charset.end(), charval) == m_charset.end()) { if(charval != '\x00' && charval != ' ' && std::find(m_charset.begin(), m_charset.end(), charval) == m_charset.end()) {
m_charset.push_back(charval); m_charset.push_back(charval);
} }
} }
} }
if(!m_charset.empty()) { if(!m_charset.empty()) {
try { try {
default_random_engine rng(m_random()); default_random_engine rng(m_random());
uniform_int_distribution<> dist(0, m_charset.size() - 1); uniform_int_distribution<> dist(0, m_charset.size() - 1);
auto randchar = [this, &dist, &rng]() { auto randchar = [this, &dist, &rng]() {
return m_charset[dist(rng)]; return m_charset[dist(rng)];
}; };
string res(length, 0); string res(length, 0);
generate_n(res.begin(), length, randchar); generate_n(res.begin(), length, randchar);
m_ui->passwordLineEdit->setText(QString::fromLatin1(res.c_str())); m_ui->passwordLineEdit->setText(QString::fromLatin1(res.c_str()));
} catch(const CryptoException &ex) { } catch(const CryptoException &ex) {
QMessageBox::warning(this, QApplication::applicationName(), tr("Failed to generate password.\nOpenSSL error: %1").arg(QString::fromLocal8Bit(ex.what()))); QMessageBox::warning(this, QApplication::applicationName(), tr("Failed to generate password.\nOpenSSL error: %1").arg(QString::fromLocal8Bit(ex.what())));
} }
} else { } else {
QMessageBox::warning(this, QApplication::applicationName(), tr("You have to select at least one checkbox.")); QMessageBox::warning(this, QApplication::applicationName(), tr("You have to select at least one checkbox."));
} }
} else { } else {
QMessageBox::warning(this, QApplication::applicationName(), tr("The length has to be at least one.")); QMessageBox::warning(this, QApplication::applicationName(), tr("The length has to be at least one."));
} }
} }
/*! /*!
* \brief Handles when the user checked or unchecked a category. * \brief Handles when the user checked or unchecked a category.
*/ */
void PasswordGeneratorDialog::handleCheckedCategoriesChanged() void PasswordGeneratorDialog::handleCheckedCategoriesChanged()
{ {
m_ui->generatePassowordCommandLinkButton->setEnabled(m_ui->useCapitalLettersCheckBox->isChecked() m_ui->generatePassowordCommandLinkButton->setEnabled(m_ui->useCapitalLettersCheckBox->isChecked()
|| m_ui->useDigitsCheckBox->isChecked() || m_ui->useDigitsCheckBox->isChecked()
|| m_ui->useSmallLettersCheckBox->isChecked() || m_ui->useSmallLettersCheckBox->isChecked()
|| !m_ui->otherCharsLineEdit->text().isEmpty()); || !m_ui->otherCharsLineEdit->text().isEmpty());
m_charset.clear(); m_charset.clear();
} }
/*! /*!
* \brief Handles when the password changed. * \brief Handles when the password changed.
*/ */
void PasswordGeneratorDialog::handlePasswordChanged() void PasswordGeneratorDialog::handlePasswordChanged()
{ {
m_ui->copyPasswordCommandLinkButton->setEnabled(m_ui->passwordLineEdit->text().count() > 0); m_ui->copyPasswordCommandLinkButton->setEnabled(m_ui->passwordLineEdit->text().count() > 0);
} }
/*! /*!
* \brief Copies the current password to the clipboard. * \brief Copies the current password to the clipboard.
*/ */
void PasswordGeneratorDialog::copyPassword() void PasswordGeneratorDialog::copyPassword()
{ {
QClipboard *cb = QApplication::clipboard(); QClipboard *cb = QApplication::clipboard();
cb->setText(m_ui->passwordLineEdit->text()); cb->setText(m_ui->passwordLineEdit->text());
} }
} }

View File

@ -1,38 +1,38 @@
#ifndef PASSWORDGENERATORDIALOG_H #ifndef PASSWORDGENERATORDIALOG_H
#define PASSWORDGENERATORDIALOG_H #define PASSWORDGENERATORDIALOG_H
#include <passwordfile/util/opensslrandomdevice.h> #include <passwordfile/util/opensslrandomdevice.h>
#include <QDialog> #include <QDialog>
#include <vector> #include <vector>
namespace QtGui { namespace QtGui {
namespace Ui { namespace Ui {
class PasswordGeneratorDialog; class PasswordGeneratorDialog;
} }
class PasswordGeneratorDialog : public QDialog class PasswordGeneratorDialog : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit PasswordGeneratorDialog(QWidget *parent = 0); explicit PasswordGeneratorDialog(QWidget *parent = 0);
~PasswordGeneratorDialog(); ~PasswordGeneratorDialog();
private Q_SLOTS: private Q_SLOTS:
void generateNewPassword(); void generateNewPassword();
void handleCheckedCategoriesChanged(); void handleCheckedCategoriesChanged();
void handlePasswordChanged(); void handlePasswordChanged();
void copyPassword(); void copyPassword();
private: private:
Ui::PasswordGeneratorDialog *m_ui; Ui::PasswordGeneratorDialog *m_ui;
std::vector<char> m_charset; std::vector<char> m_charset;
Util::OpenSslRandomDevice m_random; Util::OpenSslRandomDevice m_random;
}; };
} }
#endif // PASSWORDGENERATORDIALOG_H #endif // PASSWORDGENERATORDIALOG_H

210
main.cpp
View File

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