Uniform line endings (dos2unix)
This commit is contained in:
parent
56907b6d4c
commit
648d482766
|
@ -3,12 +3,10 @@
|
|||
|
||||
#include <passwordfile/io/passwordfile.h>
|
||||
|
||||
#include <c++utilities/application/global.h>
|
||||
|
||||
#if defined(PLATFORM_UNIX)
|
||||
#include <termios.h>
|
||||
# include <termios.h>
|
||||
#elif defined(PLATFORM_WINDOWS)
|
||||
#include <windows.h>
|
||||
# include <windows.h>
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
|
@ -17,9 +15,7 @@
|
|||
#include <ostream>
|
||||
|
||||
namespace ApplicationUtilities {
|
||||
|
||||
typedef std::vector<std::string> StringVector;
|
||||
|
||||
}
|
||||
|
||||
namespace Io {
|
||||
|
|
2466
gui/mainwindow.cpp
2466
gui/mainwindow.cpp
File diff suppressed because it is too large
Load Diff
276
gui/mainwindow.h
276
gui/mainwindow.h
|
@ -1,138 +1,138 @@
|
|||
#ifndef MAINWINDOW_H
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#include "./passwordgeneratordialog.h"
|
||||
|
||||
#include <passwordfile/io/passwordfile.h>
|
||||
|
||||
#include <c++utilities/io/binaryreader.h>
|
||||
#include <c++utilities/io/binarywriter.h>
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QMap>
|
||||
|
||||
#include <memory>
|
||||
|
||||
QT_FORWARD_DECLARE_CLASS(QCloseEvent)
|
||||
QT_FORWARD_DECLARE_CLASS(QTreeWidgetItem)
|
||||
QT_FORWARD_DECLARE_CLASS(QUndoStack)
|
||||
QT_FORWARD_DECLARE_CLASS(QUndoView)
|
||||
QT_FORWARD_DECLARE_CLASS(QSettings)
|
||||
|
||||
namespace Io {
|
||||
DECLARE_ENUM_CLASS(EntryType, int);
|
||||
DECLARE_ENUM_CLASS(FieldType, int);
|
||||
}
|
||||
|
||||
namespace MiscUtils {
|
||||
class RecentMenuManager;
|
||||
}
|
||||
|
||||
namespace Dialogs {
|
||||
class AboutDialog;
|
||||
class SettingsDialog;
|
||||
class QtSettings;
|
||||
}
|
||||
|
||||
namespace QtGui {
|
||||
|
||||
class FieldModel;
|
||||
class EntryModel;
|
||||
class EntryFilterModel;
|
||||
|
||||
namespace Ui {
|
||||
class MainWindow;
|
||||
}
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MainWindow(QSettings &settings, Dialogs::QtSettings *qtSettings = nullptr, QWidget *parent = nullptr);
|
||||
~MainWindow();
|
||||
|
||||
public slots:
|
||||
// file management
|
||||
bool openFile(const QString &path);
|
||||
void createFile(const QString &path, const QString &password);
|
||||
void createFile(const QString &path);
|
||||
bool createFile();
|
||||
void changePassword();
|
||||
bool saveFile();
|
||||
void exportFile();
|
||||
bool closeFile();
|
||||
// show dialogs
|
||||
void showOpenFileDialog();
|
||||
void showSaveFileDialog();
|
||||
void showSettingsDialog();
|
||||
void showAboutDialog();
|
||||
void showPassowrdGeneratorDialog();
|
||||
void showUndoView();
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *obj, QEvent *event);
|
||||
void closeEvent(QCloseEvent *event);
|
||||
void timerEvent(QTimerEvent *event);
|
||||
|
||||
private slots:
|
||||
// file management
|
||||
bool showFile();
|
||||
// account/categories management
|
||||
void addAccount();
|
||||
void addCategory();
|
||||
void addEntry(Io::EntryType type);
|
||||
void removeEntry();
|
||||
void applyFilter(const QString &filterText);
|
||||
// row management
|
||||
void accountSelected(const QModelIndex &selected, const QModelIndex &);
|
||||
void insertRow();
|
||||
void removeRows();
|
||||
void markAsPasswordField();
|
||||
void markAsNormalField();
|
||||
void setFieldType(Io::FieldType fieldType);
|
||||
void setPasswordVisibility(QAction *selectedAction);
|
||||
QString selectedFieldsString() const;
|
||||
void insertFields(const QString &fieldsString);
|
||||
void copyFieldsForXMilliSeconds(int x = 5000);
|
||||
void copyFields();
|
||||
void insertFieldsFromClipboard();
|
||||
// showing context menus
|
||||
void showTreeViewContextMenu();
|
||||
void showTableViewContextMenu();
|
||||
// other
|
||||
void showContainingDirectory();
|
||||
void clearClipboard();
|
||||
void setSomethingChanged();
|
||||
void setSomethingChanged(bool somethingChanged);
|
||||
|
||||
private:
|
||||
// showing conditional messages/prompts
|
||||
bool askForCreatingFile();
|
||||
bool showNoFileOpened();
|
||||
bool showNoAccount();
|
||||
// other
|
||||
void updateUiStatus();
|
||||
void updateWindowTitle();
|
||||
void applyDefaultExpanding(const QModelIndex &parent);
|
||||
|
||||
std::unique_ptr<Ui::MainWindow> m_ui;
|
||||
Io::PasswordFile m_file;
|
||||
FieldModel *m_fieldModel;
|
||||
EntryModel *m_entryModel;
|
||||
EntryFilterModel *m_entryFilterModel;
|
||||
QUndoStack *m_undoStack;
|
||||
QUndoView *m_undoView;
|
||||
bool m_somethingChanged;
|
||||
bool m_dontUpdateSelection;
|
||||
int m_clearClipboardTimer;
|
||||
MiscUtils::RecentMenuManager *m_recentMgr;
|
||||
Dialogs::AboutDialog *m_aboutDlg;
|
||||
QSettings &m_settings;
|
||||
Dialogs::QtSettings *m_qtSettings;
|
||||
Dialogs::SettingsDialog *m_settingsDlg;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
#ifndef MAINWINDOW_H
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#include "./passwordgeneratordialog.h"
|
||||
|
||||
#include <passwordfile/io/passwordfile.h>
|
||||
|
||||
#include <c++utilities/io/binaryreader.h>
|
||||
#include <c++utilities/io/binarywriter.h>
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QMap>
|
||||
|
||||
#include <memory>
|
||||
|
||||
QT_FORWARD_DECLARE_CLASS(QCloseEvent)
|
||||
QT_FORWARD_DECLARE_CLASS(QTreeWidgetItem)
|
||||
QT_FORWARD_DECLARE_CLASS(QUndoStack)
|
||||
QT_FORWARD_DECLARE_CLASS(QUndoView)
|
||||
QT_FORWARD_DECLARE_CLASS(QSettings)
|
||||
|
||||
namespace Io {
|
||||
DECLARE_ENUM_CLASS(EntryType, int);
|
||||
DECLARE_ENUM_CLASS(FieldType, int);
|
||||
}
|
||||
|
||||
namespace MiscUtils {
|
||||
class RecentMenuManager;
|
||||
}
|
||||
|
||||
namespace Dialogs {
|
||||
class AboutDialog;
|
||||
class SettingsDialog;
|
||||
class QtSettings;
|
||||
}
|
||||
|
||||
namespace QtGui {
|
||||
|
||||
class FieldModel;
|
||||
class EntryModel;
|
||||
class EntryFilterModel;
|
||||
|
||||
namespace Ui {
|
||||
class MainWindow;
|
||||
}
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MainWindow(QSettings &settings, Dialogs::QtSettings *qtSettings = nullptr, QWidget *parent = nullptr);
|
||||
~MainWindow();
|
||||
|
||||
public slots:
|
||||
// file management
|
||||
bool openFile(const QString &path);
|
||||
void createFile(const QString &path, const QString &password);
|
||||
void createFile(const QString &path);
|
||||
bool createFile();
|
||||
void changePassword();
|
||||
bool saveFile();
|
||||
void exportFile();
|
||||
bool closeFile();
|
||||
// show dialogs
|
||||
void showOpenFileDialog();
|
||||
void showSaveFileDialog();
|
||||
void showSettingsDialog();
|
||||
void showAboutDialog();
|
||||
void showPassowrdGeneratorDialog();
|
||||
void showUndoView();
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *obj, QEvent *event);
|
||||
void closeEvent(QCloseEvent *event);
|
||||
void timerEvent(QTimerEvent *event);
|
||||
|
||||
private slots:
|
||||
// file management
|
||||
bool showFile();
|
||||
// account/categories management
|
||||
void addAccount();
|
||||
void addCategory();
|
||||
void addEntry(Io::EntryType type);
|
||||
void removeEntry();
|
||||
void applyFilter(const QString &filterText);
|
||||
// row management
|
||||
void accountSelected(const QModelIndex &selected, const QModelIndex &);
|
||||
void insertRow();
|
||||
void removeRows();
|
||||
void markAsPasswordField();
|
||||
void markAsNormalField();
|
||||
void setFieldType(Io::FieldType fieldType);
|
||||
void setPasswordVisibility(QAction *selectedAction);
|
||||
QString selectedFieldsString() const;
|
||||
void insertFields(const QString &fieldsString);
|
||||
void copyFieldsForXMilliSeconds(int x = 5000);
|
||||
void copyFields();
|
||||
void insertFieldsFromClipboard();
|
||||
// showing context menus
|
||||
void showTreeViewContextMenu();
|
||||
void showTableViewContextMenu();
|
||||
// other
|
||||
void showContainingDirectory();
|
||||
void clearClipboard();
|
||||
void setSomethingChanged();
|
||||
void setSomethingChanged(bool somethingChanged);
|
||||
|
||||
private:
|
||||
// showing conditional messages/prompts
|
||||
bool askForCreatingFile();
|
||||
bool showNoFileOpened();
|
||||
bool showNoAccount();
|
||||
// other
|
||||
void updateUiStatus();
|
||||
void updateWindowTitle();
|
||||
void applyDefaultExpanding(const QModelIndex &parent);
|
||||
|
||||
std::unique_ptr<Ui::MainWindow> m_ui;
|
||||
Io::PasswordFile m_file;
|
||||
FieldModel *m_fieldModel;
|
||||
EntryModel *m_entryModel;
|
||||
EntryFilterModel *m_entryFilterModel;
|
||||
QUndoStack *m_undoStack;
|
||||
QUndoView *m_undoView;
|
||||
bool m_somethingChanged;
|
||||
bool m_dontUpdateSelection;
|
||||
int m_clearClipboardTimer;
|
||||
MiscUtils::RecentMenuManager *m_recentMgr;
|
||||
Dialogs::AboutDialog *m_aboutDlg;
|
||||
QSettings &m_settings;
|
||||
Dialogs::QtSettings *m_qtSettings;
|
||||
Dialogs::SettingsDialog *m_settingsDlg;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
|
|
|
@ -1,172 +1,172 @@
|
|||
#include "./passwordgeneratordialog.h"
|
||||
|
||||
#include "ui_passwordgeneratordialog.h"
|
||||
|
||||
#include <passwordfile/io/cryptoexception.h>
|
||||
|
||||
#include <qtutilities/misc/dialogutils.h>
|
||||
|
||||
#include <c++utilities/conversion/binaryconversion.h>
|
||||
|
||||
#include <openssl/rand.h>
|
||||
|
||||
#include <QMessageBox>
|
||||
#include <QClipboard>
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
#include <random>
|
||||
|
||||
using namespace std;
|
||||
using namespace Io;
|
||||
using namespace Util;
|
||||
using namespace Dialogs;
|
||||
|
||||
namespace QtGui {
|
||||
|
||||
const char smallLetters[] = {'a','b','c','d','e','f',
|
||||
'g','h','i','j','k',
|
||||
'l','m','n','o','p',
|
||||
'q','r','s','t','u',
|
||||
'v','w','x','y','z'};
|
||||
|
||||
const char capitalLetters[] = {'A','B','C','D','E','F',
|
||||
'G','H','I','J','K',
|
||||
'L','M','N','O','P',
|
||||
'Q','R','S','T','U',
|
||||
'V','W','X','Y','Z'};
|
||||
|
||||
const char digits[] = {'0','1','2','3','4',
|
||||
'5','6','7','8','9'};
|
||||
|
||||
/*!
|
||||
* \class PasswordGeneratorDialog
|
||||
* \brief The PasswordGeneratorDialog class provides a password generation dialog.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \brief Constructs a new password generator dialog.
|
||||
*/
|
||||
PasswordGeneratorDialog::PasswordGeneratorDialog(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
m_ui(new Ui::PasswordGeneratorDialog)
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
#ifdef Q_OS_WIN32
|
||||
setStyleSheet(QStringLiteral("%1 QCommandLinkButton { font-size: 12pt; color: %2; font-weight: normal; }").arg(dialogStyle(), instructionTextColor().name()));
|
||||
#endif
|
||||
setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint);
|
||||
|
||||
connect(m_ui->copyPasswordCommandLinkButton, &QCommandLinkButton::clicked, this, &PasswordGeneratorDialog::copyPassword);
|
||||
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->useSmallLettersCheckBox, &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->passwordLineEdit, &QLineEdit::textChanged, this, &PasswordGeneratorDialog::handlePasswordChanged);
|
||||
connect(m_ui->closePushButton, &QPushButton::clicked, this, &PasswordGeneratorDialog::close);
|
||||
|
||||
handlePasswordChanged();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Destroys the dialog.
|
||||
*/
|
||||
PasswordGeneratorDialog::~PasswordGeneratorDialog()
|
||||
{
|
||||
delete m_ui;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Generates and shows a new password.
|
||||
*/
|
||||
void PasswordGeneratorDialog::generateNewPassword()
|
||||
{
|
||||
int length = m_ui->LengthSpinBox->value();
|
||||
if(length > 0) {
|
||||
if(m_charset.empty()) {
|
||||
bool useSmallLetters = m_ui->useSmallLettersCheckBox->isChecked();
|
||||
bool useCapitalLetters = m_ui->useCapitalLettersCheckBox->isChecked();
|
||||
bool useDigits = m_ui->useDigitsCheckBox->isChecked();
|
||||
QString otherChars = m_ui->otherCharsLineEdit->text();
|
||||
int charsetSize = otherChars.length();
|
||||
if(useSmallLetters) {
|
||||
charsetSize += sizeof(smallLetters);
|
||||
}
|
||||
if(useCapitalLetters) {
|
||||
charsetSize += sizeof(capitalLetters);
|
||||
}
|
||||
if(useDigits) {
|
||||
charsetSize += sizeof(digits);
|
||||
}
|
||||
m_charset.reserve(charsetSize);
|
||||
if(useSmallLetters) {
|
||||
m_charset.insert(m_charset.end(), std::begin(smallLetters), std::end(smallLetters));
|
||||
}
|
||||
if(useCapitalLetters) {
|
||||
m_charset.insert(m_charset.end(), std::begin(capitalLetters), std::end(capitalLetters));
|
||||
}
|
||||
if(useDigits) {
|
||||
m_charset.insert(m_charset.end(), std::begin(digits), std::end(digits));
|
||||
}
|
||||
char charval;
|
||||
foreach(QChar qchar, otherChars) {
|
||||
charval = qchar.toLatin1();
|
||||
if(charval != '\x00' && charval != ' ' && std::find(m_charset.begin(), m_charset.end(), charval) == m_charset.end()) {
|
||||
m_charset.push_back(charval);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!m_charset.empty()) {
|
||||
try {
|
||||
default_random_engine rng(m_random());
|
||||
uniform_int_distribution<> dist(0, m_charset.size() - 1);
|
||||
auto randchar = [this, &dist, &rng]() {
|
||||
return m_charset[dist(rng)];
|
||||
};
|
||||
string res(length, 0);
|
||||
generate_n(res.begin(), length, randchar);
|
||||
m_ui->passwordLineEdit->setText(QString::fromLatin1(res.c_str()));
|
||||
} catch(const CryptoException &ex) {
|
||||
QMessageBox::warning(this, QApplication::applicationName(), tr("Failed to generate password.\nOpenSSL error: %1").arg(QString::fromLocal8Bit(ex.what())));
|
||||
}
|
||||
} else {
|
||||
QMessageBox::warning(this, QApplication::applicationName(), tr("You have to select at least one checkbox."));
|
||||
}
|
||||
} else {
|
||||
QMessageBox::warning(this, QApplication::applicationName(), tr("The length has to be at least one."));
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Handles when the user checked or unchecked a category.
|
||||
*/
|
||||
void PasswordGeneratorDialog::handleCheckedCategoriesChanged()
|
||||
{
|
||||
m_ui->generatePassowordCommandLinkButton->setEnabled(m_ui->useCapitalLettersCheckBox->isChecked()
|
||||
|| m_ui->useDigitsCheckBox->isChecked()
|
||||
|| m_ui->useSmallLettersCheckBox->isChecked()
|
||||
|| !m_ui->otherCharsLineEdit->text().isEmpty());
|
||||
m_charset.clear();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Handles when the password changed.
|
||||
*/
|
||||
void PasswordGeneratorDialog::handlePasswordChanged()
|
||||
{
|
||||
m_ui->copyPasswordCommandLinkButton->setEnabled(m_ui->passwordLineEdit->text().count() > 0);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Copies the current password to the clipboard.
|
||||
*/
|
||||
void PasswordGeneratorDialog::copyPassword()
|
||||
{
|
||||
QClipboard *cb = QApplication::clipboard();
|
||||
cb->setText(m_ui->passwordLineEdit->text());
|
||||
}
|
||||
|
||||
}
|
||||
#include "./passwordgeneratordialog.h"
|
||||
|
||||
#include "ui_passwordgeneratordialog.h"
|
||||
|
||||
#include <passwordfile/io/cryptoexception.h>
|
||||
|
||||
#include <qtutilities/misc/dialogutils.h>
|
||||
|
||||
#include <c++utilities/conversion/binaryconversion.h>
|
||||
|
||||
#include <openssl/rand.h>
|
||||
|
||||
#include <QMessageBox>
|
||||
#include <QClipboard>
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
#include <random>
|
||||
|
||||
using namespace std;
|
||||
using namespace Io;
|
||||
using namespace Util;
|
||||
using namespace Dialogs;
|
||||
|
||||
namespace QtGui {
|
||||
|
||||
const char smallLetters[] = {'a','b','c','d','e','f',
|
||||
'g','h','i','j','k',
|
||||
'l','m','n','o','p',
|
||||
'q','r','s','t','u',
|
||||
'v','w','x','y','z'};
|
||||
|
||||
const char capitalLetters[] = {'A','B','C','D','E','F',
|
||||
'G','H','I','J','K',
|
||||
'L','M','N','O','P',
|
||||
'Q','R','S','T','U',
|
||||
'V','W','X','Y','Z'};
|
||||
|
||||
const char digits[] = {'0','1','2','3','4',
|
||||
'5','6','7','8','9'};
|
||||
|
||||
/*!
|
||||
* \class PasswordGeneratorDialog
|
||||
* \brief The PasswordGeneratorDialog class provides a password generation dialog.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \brief Constructs a new password generator dialog.
|
||||
*/
|
||||
PasswordGeneratorDialog::PasswordGeneratorDialog(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
m_ui(new Ui::PasswordGeneratorDialog)
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
#ifdef Q_OS_WIN32
|
||||
setStyleSheet(QStringLiteral("%1 QCommandLinkButton { font-size: 12pt; color: %2; font-weight: normal; }").arg(dialogStyle(), instructionTextColor().name()));
|
||||
#endif
|
||||
setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint);
|
||||
|
||||
connect(m_ui->copyPasswordCommandLinkButton, &QCommandLinkButton::clicked, this, &PasswordGeneratorDialog::copyPassword);
|
||||
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->useSmallLettersCheckBox, &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->passwordLineEdit, &QLineEdit::textChanged, this, &PasswordGeneratorDialog::handlePasswordChanged);
|
||||
connect(m_ui->closePushButton, &QPushButton::clicked, this, &PasswordGeneratorDialog::close);
|
||||
|
||||
handlePasswordChanged();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Destroys the dialog.
|
||||
*/
|
||||
PasswordGeneratorDialog::~PasswordGeneratorDialog()
|
||||
{
|
||||
delete m_ui;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Generates and shows a new password.
|
||||
*/
|
||||
void PasswordGeneratorDialog::generateNewPassword()
|
||||
{
|
||||
int length = m_ui->LengthSpinBox->value();
|
||||
if(length > 0) {
|
||||
if(m_charset.empty()) {
|
||||
bool useSmallLetters = m_ui->useSmallLettersCheckBox->isChecked();
|
||||
bool useCapitalLetters = m_ui->useCapitalLettersCheckBox->isChecked();
|
||||
bool useDigits = m_ui->useDigitsCheckBox->isChecked();
|
||||
QString otherChars = m_ui->otherCharsLineEdit->text();
|
||||
int charsetSize = otherChars.length();
|
||||
if(useSmallLetters) {
|
||||
charsetSize += sizeof(smallLetters);
|
||||
}
|
||||
if(useCapitalLetters) {
|
||||
charsetSize += sizeof(capitalLetters);
|
||||
}
|
||||
if(useDigits) {
|
||||
charsetSize += sizeof(digits);
|
||||
}
|
||||
m_charset.reserve(charsetSize);
|
||||
if(useSmallLetters) {
|
||||
m_charset.insert(m_charset.end(), std::begin(smallLetters), std::end(smallLetters));
|
||||
}
|
||||
if(useCapitalLetters) {
|
||||
m_charset.insert(m_charset.end(), std::begin(capitalLetters), std::end(capitalLetters));
|
||||
}
|
||||
if(useDigits) {
|
||||
m_charset.insert(m_charset.end(), std::begin(digits), std::end(digits));
|
||||
}
|
||||
char charval;
|
||||
foreach(QChar qchar, otherChars) {
|
||||
charval = qchar.toLatin1();
|
||||
if(charval != '\x00' && charval != ' ' && std::find(m_charset.begin(), m_charset.end(), charval) == m_charset.end()) {
|
||||
m_charset.push_back(charval);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!m_charset.empty()) {
|
||||
try {
|
||||
default_random_engine rng(m_random());
|
||||
uniform_int_distribution<> dist(0, m_charset.size() - 1);
|
||||
auto randchar = [this, &dist, &rng]() {
|
||||
return m_charset[dist(rng)];
|
||||
};
|
||||
string res(length, 0);
|
||||
generate_n(res.begin(), length, randchar);
|
||||
m_ui->passwordLineEdit->setText(QString::fromLatin1(res.c_str()));
|
||||
} catch(const CryptoException &ex) {
|
||||
QMessageBox::warning(this, QApplication::applicationName(), tr("Failed to generate password.\nOpenSSL error: %1").arg(QString::fromLocal8Bit(ex.what())));
|
||||
}
|
||||
} else {
|
||||
QMessageBox::warning(this, QApplication::applicationName(), tr("You have to select at least one checkbox."));
|
||||
}
|
||||
} else {
|
||||
QMessageBox::warning(this, QApplication::applicationName(), tr("The length has to be at least one."));
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Handles when the user checked or unchecked a category.
|
||||
*/
|
||||
void PasswordGeneratorDialog::handleCheckedCategoriesChanged()
|
||||
{
|
||||
m_ui->generatePassowordCommandLinkButton->setEnabled(m_ui->useCapitalLettersCheckBox->isChecked()
|
||||
|| m_ui->useDigitsCheckBox->isChecked()
|
||||
|| m_ui->useSmallLettersCheckBox->isChecked()
|
||||
|| !m_ui->otherCharsLineEdit->text().isEmpty());
|
||||
m_charset.clear();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Handles when the password changed.
|
||||
*/
|
||||
void PasswordGeneratorDialog::handlePasswordChanged()
|
||||
{
|
||||
m_ui->copyPasswordCommandLinkButton->setEnabled(m_ui->passwordLineEdit->text().count() > 0);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Copies the current password to the clipboard.
|
||||
*/
|
||||
void PasswordGeneratorDialog::copyPassword()
|
||||
{
|
||||
QClipboard *cb = QApplication::clipboard();
|
||||
cb->setText(m_ui->passwordLineEdit->text());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,38 +1,38 @@
|
|||
#ifndef PASSWORDGENERATORDIALOG_H
|
||||
#define PASSWORDGENERATORDIALOG_H
|
||||
|
||||
#include <passwordfile/util/opensslrandomdevice.h>
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace QtGui {
|
||||
|
||||
namespace Ui {
|
||||
class PasswordGeneratorDialog;
|
||||
}
|
||||
|
||||
class PasswordGeneratorDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit PasswordGeneratorDialog(QWidget *parent = 0);
|
||||
~PasswordGeneratorDialog();
|
||||
|
||||
private Q_SLOTS:
|
||||
void generateNewPassword();
|
||||
void handleCheckedCategoriesChanged();
|
||||
void handlePasswordChanged();
|
||||
void copyPassword();
|
||||
|
||||
private:
|
||||
Ui::PasswordGeneratorDialog *m_ui;
|
||||
std::vector<char> m_charset;
|
||||
Util::OpenSslRandomDevice m_random;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // PASSWORDGENERATORDIALOG_H
|
||||
#ifndef PASSWORDGENERATORDIALOG_H
|
||||
#define PASSWORDGENERATORDIALOG_H
|
||||
|
||||
#include <passwordfile/util/opensslrandomdevice.h>
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace QtGui {
|
||||
|
||||
namespace Ui {
|
||||
class PasswordGeneratorDialog;
|
||||
}
|
||||
|
||||
class PasswordGeneratorDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit PasswordGeneratorDialog(QWidget *parent = 0);
|
||||
~PasswordGeneratorDialog();
|
||||
|
||||
private Q_SLOTS:
|
||||
void generateNewPassword();
|
||||
void handleCheckedCategoriesChanged();
|
||||
void handlePasswordChanged();
|
||||
void copyPassword();
|
||||
|
||||
private:
|
||||
Ui::PasswordGeneratorDialog *m_ui;
|
||||
std::vector<char> m_charset;
|
||||
Util::OpenSslRandomDevice m_random;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // PASSWORDGENERATORDIALOG_H
|
||||
|
|
210
main.cpp
210
main.cpp
|
@ -1,105 +1,105 @@
|
|||
#include "./cli/cli.h"
|
||||
#ifdef GUI_QTWIDGETS
|
||||
# include "./gui/initiategui.h"
|
||||
#endif
|
||||
#ifdef GUI_QTQUICK
|
||||
# include "./quickgui/initiatequick.h"
|
||||
#endif
|
||||
|
||||
#include "resources/config.h"
|
||||
|
||||
#include <passwordfile/util/openssl.h>
|
||||
|
||||
#include <c++utilities/application/argumentparser.h>
|
||||
#include <c++utilities/application/failure.h>
|
||||
#include <c++utilities/application/commandlineutils.h>
|
||||
|
||||
#if defined(GUI_QTWIDGETS) || defined(GUI_QTQUICK)
|
||||
# include <qtutilities/resources/qtconfigarguments.h>
|
||||
# include <QString>
|
||||
#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
|
||||
SET_APPLICATION_INFO;
|
||||
ArgumentParser parser;
|
||||
// file argument
|
||||
Argument fileArg("file", 'f', "specifies the file to be opened (or created when using --modify)");
|
||||
fileArg.setValueNames({"path"});
|
||||
fileArg.setRequiredValueCount(1);
|
||||
fileArg.setCombinable(true);
|
||||
fileArg.setRequired(false);
|
||||
fileArg.setImplicit(true);
|
||||
// Qt configuration arguments
|
||||
QT_CONFIG_ARGUMENTS qtConfigArgs;
|
||||
qtConfigArgs.qtWidgetsGuiArg().addSubArgument(&fileArg);
|
||||
// cli argument
|
||||
Argument cliArg("interactive-cli", 'i', "starts the interactive command line interface");
|
||||
cliArg.setSubArguments({&fileArg});
|
||||
// help argument
|
||||
HelpArgument helpArg(parser);
|
||||
parser.setMainArguments({&qtConfigArgs.qtWidgetsGuiArg(), &qtConfigArgs.qtQuickGuiArg(), &cliArg, &helpArg});
|
||||
// holds the application's return code
|
||||
int res = 0;
|
||||
// parse the specified arguments
|
||||
try {
|
||||
parser.parseArgs(argc, argv);
|
||||
if(cliArg.isPresent()) {
|
||||
Cli::InteractiveCli cli;
|
||||
if(fileArg.isPresent()) {
|
||||
cli.run(fileArg.values().front());
|
||||
} 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
|
||||
#if defined(GUI_QTWIDGETS) || defined(GUI_QTQUICK)
|
||||
QString file;
|
||||
if(fileArg.isPresent()) {
|
||||
file = QString::fromLocal8Bit(fileArg.values().front());
|
||||
}
|
||||
#endif
|
||||
if(qtConfigArgs.qtWidgetsGuiArg().isPresent()) {
|
||||
#ifdef GUI_QTWIDGETS
|
||||
res = QtGui::runWidgetsGui(argc, argv, qtConfigArgs, file);
|
||||
#else
|
||||
CMD_UTILS_START_CONSOLE;
|
||||
cout << "The application has not been built with Qt widgets support." << endl;
|
||||
#endif
|
||||
} else if(qtConfigArgs.qtQuickGuiArg().isPresent()) {
|
||||
#ifdef GUI_QTQUICK
|
||||
res = QtGui::runQuickGui(argc, argv, qtConfigArgs);
|
||||
#else
|
||||
CMD_UTILS_START_CONSOLE;
|
||||
cout << "The application has not been built with Qt quick support." << endl;
|
||||
#endif
|
||||
} else {
|
||||
#if defined(GUI_QTQUICK)
|
||||
res = QtGui::runQuickGui(argc, argv, qtConfigArgs);
|
||||
#elif defined(GUI_QTWIDGETS)
|
||||
res = QtGui::runWidgetsGui(argc, argv, qtConfigArgs, file);
|
||||
#else
|
||||
CMD_UTILS_START_CONSOLE;
|
||||
cout << "See --help for usage." << endl;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
} catch(const Failure &ex) {
|
||||
CMD_UTILS_START_CONSOLE;
|
||||
cout << "Unable to parse arguments. " << ex.what() << "\nSee --help for available commands." << endl;
|
||||
}
|
||||
// clean open ssl
|
||||
OpenSsl::clean();
|
||||
return res;
|
||||
}
|
||||
#include "./cli/cli.h"
|
||||
#ifdef GUI_QTWIDGETS
|
||||
# include "./gui/initiategui.h"
|
||||
#endif
|
||||
#ifdef GUI_QTQUICK
|
||||
# include "./quickgui/initiatequick.h"
|
||||
#endif
|
||||
|
||||
#include "resources/config.h"
|
||||
|
||||
#include <passwordfile/util/openssl.h>
|
||||
|
||||
#include <c++utilities/application/argumentparser.h>
|
||||
#include <c++utilities/application/failure.h>
|
||||
#include <c++utilities/application/commandlineutils.h>
|
||||
|
||||
#if defined(GUI_QTWIDGETS) || defined(GUI_QTQUICK)
|
||||
# include <qtutilities/resources/qtconfigarguments.h>
|
||||
# include <QString>
|
||||
#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
|
||||
SET_APPLICATION_INFO;
|
||||
ArgumentParser parser;
|
||||
// file argument
|
||||
Argument fileArg("file", 'f', "specifies the file to be opened (or created when using --modify)");
|
||||
fileArg.setValueNames({"path"});
|
||||
fileArg.setRequiredValueCount(1);
|
||||
fileArg.setCombinable(true);
|
||||
fileArg.setRequired(false);
|
||||
fileArg.setImplicit(true);
|
||||
// Qt configuration arguments
|
||||
QT_CONFIG_ARGUMENTS qtConfigArgs;
|
||||
qtConfigArgs.qtWidgetsGuiArg().addSubArgument(&fileArg);
|
||||
// cli argument
|
||||
Argument cliArg("interactive-cli", 'i', "starts the interactive command line interface");
|
||||
cliArg.setSubArguments({&fileArg});
|
||||
// help argument
|
||||
HelpArgument helpArg(parser);
|
||||
parser.setMainArguments({&qtConfigArgs.qtWidgetsGuiArg(), &qtConfigArgs.qtQuickGuiArg(), &cliArg, &helpArg});
|
||||
// holds the application's return code
|
||||
int res = 0;
|
||||
// parse the specified arguments
|
||||
try {
|
||||
parser.parseArgs(argc, argv);
|
||||
if(cliArg.isPresent()) {
|
||||
Cli::InteractiveCli cli;
|
||||
if(fileArg.isPresent()) {
|
||||
cli.run(fileArg.values().front());
|
||||
} 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
|
||||
#if defined(GUI_QTWIDGETS) || defined(GUI_QTQUICK)
|
||||
QString file;
|
||||
if(fileArg.isPresent()) {
|
||||
file = QString::fromLocal8Bit(fileArg.values().front());
|
||||
}
|
||||
#endif
|
||||
if(qtConfigArgs.qtWidgetsGuiArg().isPresent()) {
|
||||
#ifdef GUI_QTWIDGETS
|
||||
res = QtGui::runWidgetsGui(argc, argv, qtConfigArgs, file);
|
||||
#else
|
||||
CMD_UTILS_START_CONSOLE;
|
||||
cout << "The application has not been built with Qt widgets support." << endl;
|
||||
#endif
|
||||
} else if(qtConfigArgs.qtQuickGuiArg().isPresent()) {
|
||||
#ifdef GUI_QTQUICK
|
||||
res = QtGui::runQuickGui(argc, argv, qtConfigArgs);
|
||||
#else
|
||||
CMD_UTILS_START_CONSOLE;
|
||||
cout << "The application has not been built with Qt quick support." << endl;
|
||||
#endif
|
||||
} else {
|
||||
#if defined(GUI_QTQUICK)
|
||||
res = QtGui::runQuickGui(argc, argv, qtConfigArgs);
|
||||
#elif defined(GUI_QTWIDGETS)
|
||||
res = QtGui::runWidgetsGui(argc, argv, qtConfigArgs, file);
|
||||
#else
|
||||
CMD_UTILS_START_CONSOLE;
|
||||
cout << "See --help for usage." << endl;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
} catch(const Failure &ex) {
|
||||
CMD_UTILS_START_CONSOLE;
|
||||
cout << "Unable to parse arguments. " << ex.what() << "\nSee --help for available commands." << endl;
|
||||
}
|
||||
// clean open ssl
|
||||
OpenSsl::clean();
|
||||
return res;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue